diff mbox series

[v2,07/10] gpio: dw: Return output value when direction is out

Message ID 20200608012651.1525906-8-seanga2@gmail.com
State New
Headers show
Series riscv: Add FPIOA and GPIO support for Kendryte K210 | expand

Commit Message

Sean Anderson June 8, 2020, 1:26 a.m. UTC
dm_gpio_ops.get_value can be called when the gpio is either input or
output. The current dw code always returns the input value, which is
invalid if the direction is set to out.

Signed-off-by: Sean Anderson <seanga2 at gmail.com>
---
This patch was previously submitted as part of
https://patchwork.ozlabs.org/project/uboot/list/?series=161576

Changes in v2:
- Reorder changes to minimize diff

 drivers/gpio/dwapb_gpio.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Tan, Ley Foon June 9, 2020, 1:20 a.m. UTC | #1
> -----Original Message-----
> From: Sean Anderson <seanga2 at gmail.com>
> Sent: Monday, June 8, 2020 9:27 AM
> To: u-boot at lists.denx.de
> Cc: Tom Rini <trini at konsulko.com>; Bin Meng <bmeng.cn at gmail.com>;
> Rick Chen <rickchen36 at gmail.com>; Simon Glass <sjg at chromium.org>;
> Sean Anderson <seanga2 at gmail.com>; Anatolij Gustschin <agust at denx.de>;
> Tan, Ley Foon <ley.foon.tan at intel.com>; Marek Vasut <marex at denx.de>;
> Simon Goldschmidt <simon.k.r.goldschmidt at gmail.com>
> Subject: [PATCH v2 07/10] gpio: dw: Return output value when direction is
> out
> 
> dm_gpio_ops.get_value can be called when the gpio is either input or output.
> The current dw code always returns the input value, which is invalid if the
> direction is set to out.
> 
> Signed-off-by: Sean Anderson <seanga2 at gmail.com>
> ---
> This patch was previously submitted as part of
> https://patchwork.ozlabs.org/project/uboot/list/?series=161576
> 
> Changes in v2:
> - Reorder changes to minimize diff
> 
>  drivers/gpio/dwapb_gpio.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
Reviewed-by: Ley Foon Tan <ley.foon.tan at intel.com>
Sean Anderson June 9, 2020, 5:26 a.m. UTC | #2
On 6/7/20 9:26 PM, Sean Anderson wrote:
> dm_gpio_ops.get_value can be called when the gpio is either input or
> output. The current dw code always returns the input value, which is
> invalid if the direction is set to out.
> 
> Signed-off-by: Sean Anderson <seanga2 at gmail.com>
> ---
> This patch was previously submitted as part of
> https://patchwork.ozlabs.org/project/uboot/list/?series=161576
> 
> Changes in v2:
> - Reorder changes to minimize diff

...and I just noticed that this breaks the build since
dwapb_gpio_get_function is not declared yet. Will revert to the previous
version of this patch in the next revision.

> 
>  drivers/gpio/dwapb_gpio.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c
> index a52c9e18e3..e2970a83a8 100644
> --- a/drivers/gpio/dwapb_gpio.c
> +++ b/drivers/gpio/dwapb_gpio.c
> @@ -69,9 +69,14 @@ static int dwapb_gpio_direction_output(struct udevice *dev, unsigned pin,
>  static int dwapb_gpio_get_value(struct udevice *dev, unsigned pin)
>  {
>  	struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
> -	return !!(readl(plat->base + GPIO_EXT_PORT(plat->bank)) & (1 << pin));
> -}
> +	u32 value;
>  
> +	if (dwapb_gpio_get_function(dev, pin) == GPIOF_OUTPUT)
> +		value = readl(plat->base + GPIO_SWPORT_DR(plat->bank));
> +	else
> +		value = readl(plat->base + GPIO_EXT_PORT(plat->bank));
> +	return !!(value & BIT(pin));
> +}
>  
>  static int dwapb_gpio_set_value(struct udevice *dev, unsigned pin, int val)
>  {
> 

--Sean
diff mbox series

Patch

diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c
index a52c9e18e3..e2970a83a8 100644
--- a/drivers/gpio/dwapb_gpio.c
+++ b/drivers/gpio/dwapb_gpio.c
@@ -69,9 +69,14 @@  static int dwapb_gpio_direction_output(struct udevice *dev, unsigned pin,
 static int dwapb_gpio_get_value(struct udevice *dev, unsigned pin)
 {
 	struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
-	return !!(readl(plat->base + GPIO_EXT_PORT(plat->bank)) & (1 << pin));
-}
+	u32 value;
 
+	if (dwapb_gpio_get_function(dev, pin) == GPIOF_OUTPUT)
+		value = readl(plat->base + GPIO_SWPORT_DR(plat->bank));
+	else
+		value = readl(plat->base + GPIO_EXT_PORT(plat->bank));
+	return !!(value & BIT(pin));
+}
 
 static int dwapb_gpio_set_value(struct udevice *dev, unsigned pin, int val)
 {