From patchwork Mon Jan 13 10:35:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Delaunay X-Patchwork-Id: 239556 List-Id: U-Boot discussion From: patrick.delaunay at st.com (Patrick Delaunay) Date: Mon, 13 Jan 2020 11:35:03 +0100 Subject: [PATCH v3 09/21] gpio: add function _dm_gpio_set_dir_flags In-Reply-To: <20200113103515.20879-1-patrick.delaunay@st.com> References: <20200113103515.20879-1-patrick.delaunay@st.com> Message-ID: <20200113103515.20879-10-patrick.delaunay@st.com> Introduce the function _dm_gpio_set_dir_flags to set dir flags without check if the GPIO is reserved. Separate the reserved check for "set_dir" and "set_dir_flags". This patch is a preliminary step to add new ops. Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- This patch was part of v2 08/14 = gpio: add ops for configuration with dir flags Changes in v3: - Split the previous patch [PATCH v2 08/14] to help review Changes in v2: None drivers/gpio/gpio-uclass.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index bdf7f5bb4e..94e90cb8ac 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -510,15 +510,11 @@ int dm_gpio_set_value(const struct gpio_desc *desc, int value) return 0; } -int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags) +static int _dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags) { struct udevice *dev = desc->dev; struct dm_gpio_ops *ops = gpio_get_ops(dev); - int ret; - - ret = check_reserved(desc, "set_dir"); - if (ret) - return ret; + int ret = 0; if (flags & GPIOD_IS_OUT) { int value = flags & GPIOD_IS_OUT_ACTIVE ? 1 : 0; @@ -529,20 +525,36 @@ int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags) } else if (flags & GPIOD_IS_IN) { ret = ops->direction_input(dev, desc->offset); } + + return ret; +} + +int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags) +{ + int ret; + + ret = check_reserved(desc, "set_dir_flags"); if (ret) return ret; - /* - * Update desc->flags here, so that GPIO_ACTIVE_LOW is honoured in - * futures - */ - desc->flags = flags; - return 0; + ret = _dm_gpio_set_dir_flags(desc, flags); + + /* update the descriptor flags */ + if (ret) + desc->flags = flags; + + return ret; } int dm_gpio_set_dir(struct gpio_desc *desc) { - return dm_gpio_set_dir_flags(desc, desc->flags); + int ret; + + ret = check_reserved(desc, "set_dir"); + if (ret) + return ret; + + return _dm_gpio_set_dir_flags(desc, desc->flags); } /**