mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: maud_spierings@hotmail.com, Sascha Hauer <s.hauer@pengutronix.de>,
	BAREBOX <barebox@lists.infradead.org>
Subject: Re: [PATCH 1/2] gpio: i.MX: make _get_value() able to read output pin state
Date: Thu, 16 Oct 2025 14:53:28 +0200	[thread overview]
Message-ID: <67c3de1a-31c9-43a1-aa34-2be6a53f5396@pengutronix.de> (raw)
In-Reply-To: <20251015-imx_gpio-v1-1-e57925f906bb@hotmail.com>



On 10/15/25 8:03 PM, Maud Spierings via B4 Relay wrote:
> From: Maud Spierings <maud_spierings@hotmail.com>
> 
> Make _get_value() read back the dr register instead of the psr register
> when the direction is set to output. Now _get_value() can actually read
> the state of an output gpio instead of being always low.
> 
> Signed-off-by: Maud Spierings <maud_spierings@hotmail.com>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> 
> ---
> inspired by similar logic being used in u-boot and Linux

That's useful info that should go into the commit message IMO, because
it explains why we think regression should be limited.

> ---
>  drivers/gpio/gpio-imx.c | 19 +++++++++++--------
>  1 file changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-imx.c b/drivers/gpio/gpio-imx.c
> index d9499c66cd..bb14c56399 100644
> --- a/drivers/gpio/gpio-imx.c
> +++ b/drivers/gpio/gpio-imx.c
> @@ -89,24 +89,27 @@ static int imx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int
>  	return 0;
>  }
>  
> -static int imx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
> +static int imx_get_direction(struct gpio_chip *chip, unsigned offset)
>  {
>  	struct imx_gpio_chip *imxgpio = container_of(chip, struct imx_gpio_chip, chip);
>  	void __iomem *base = imxgpio->base;
> -	u32 val;
> -
> -	val = readl(base + imxgpio->regs->psr);
> +	u32 val = readl(base + imxgpio->regs->gdir);
>  
> -	return val & (1 << gpio) ? 1 : 0;
> +	return (val & (1 << offset)) ? GPIOF_DIR_OUT : GPIOF_DIR_IN;
>  }
>  
> -static int imx_get_direction(struct gpio_chip *chip, unsigned offset)
> +static int imx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
>  {
>  	struct imx_gpio_chip *imxgpio = container_of(chip, struct imx_gpio_chip, chip);
>  	void __iomem *base = imxgpio->base;
> -	u32 val = readl(base + imxgpio->regs->gdir);
> +	u32 val;
>  
> -	return (val & (1 << offset)) ? GPIOF_DIR_OUT : GPIOF_DIR_IN;
> +	if (imx_get_direction(chip, gpio) == GPIOF_DIR_IN)
> +		val = readl(base + imxgpio->regs->psr);
> +	else
> +		val = readl(base + imxgpio->regs->dr);
> +
> +	return val & (1 << gpio) ? 1 : 0;
>  }
>  
>  static struct gpio_ops imx_gpio_ops = {
> 

-- 
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |




  reply	other threads:[~2025-10-16 12:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-15 18:03 [PATCH 0/2] " Maud Spierings via B4 Relay
2025-10-15 18:03 ` [PATCH 1/2] " Maud Spierings via B4 Relay
2025-10-16 12:53   ` Ahmad Fatoum [this message]
2025-10-15 18:03 ` [PATCH 2/2] Documentation: migration-2025.11.0: add new empty file Maud Spierings via B4 Relay
2025-10-16 12:58   ` Ahmad Fatoum
2025-10-17  9:15     ` Maud Spierings

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=67c3de1a-31c9-43a1-aa34-2be6a53f5396@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=maud_spierings@hotmail.com \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox