From patchwork Mon Jan 13 10:35:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Delaunay X-Patchwork-Id: 239559 List-Id: U-Boot discussion From: patrick.delaunay at st.com (Patrick Delaunay) Date: Mon, 13 Jan 2020 11:35:05 +0100 Subject: [PATCH v3 11/21] gpio: add helper GPIOD_FLAGS_OUTPUT In-Reply-To: <20200113103515.20879-1-patrick.delaunay@st.com> References: <20200113103515.20879-1-patrick.delaunay@st.com> Message-ID: <20200113103515.20879-12-patrick.delaunay@st.com> Add a macro to provide the GPIO output value according the dir flags content. 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 | 9 +++------ include/asm-generic/gpio.h | 6 ++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index 62462dffa5..1d16d4acf9 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -541,12 +541,9 @@ static int _dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags) } if (flags & GPIOD_IS_OUT) { - int value = flags & GPIOD_IS_OUT_ACTIVE ? 1 : 0; - - if (flags & GPIOD_ACTIVE_LOW) - value = !value; - ret = ops->direction_output(dev, desc->offset, value); - } else if (flags & GPIOD_IS_IN) { + ret = ops->direction_output(dev, desc->offset, + GPIOD_FLAGS_OUTPUT(flags)); + } else if (flags & GPIOD_IS_IN) { ret = ops->direction_input(dev, desc->offset); } diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h index 454578c8d2..111319f41f 100644 --- a/include/asm-generic/gpio.h +++ b/include/asm-generic/gpio.h @@ -129,6 +129,12 @@ struct gpio_desc { */ }; +/* helper to compute the value of the gpio output */ +#define GPIOD_FLAGS_OUTPUT_MASK (GPIOD_ACTIVE_LOW | GPIOD_IS_OUT_ACTIVE) +#define GPIOD_FLAGS_OUTPUT(flags) \ + (((((flags) & GPIOD_FLAGS_OUTPUT_MASK) == GPIOD_IS_OUT_ACTIVE) || \ + (((flags) & GPIOD_FLAGS_OUTPUT_MASK) == GPIOD_ACTIVE_LOW))) + /** * dm_gpio_is_valid() - Check if a GPIO is valid *