Re: [RFC/RFT PATCH] pinctrl: bcm2835: don't -EINVAL on alternate funcs from get_direction()

From: Marek Szyprowski
Date: Wed Feb 19 2025 - 06:17:42 EST


On 19.02.2025 11:27, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
>
> Since commit 9d846b1aebbe ("gpiolib: check the return value of
> gpio_chip::get_direction()") we check the return value of the
> get_direction() callback as per its API contract. This driver returns
> -EINVAL if the pin in question is set to one of the alternative
> (non-GPIO) functions. This isn't really an error that should be
> communicated to GPIOLIB so default to returning the "safe" value of
> INPUT in this case. The GPIO subsystem does not have the notion of
> "unknown" direction.
>
> Fixes: 9d846b1aebbe ("gpiolib: check the return value of gpio_chip::get_direction()")
> Reported-by: Mark Brown <broonie@xxxxxxxxxx>
> Closes: https://lore.kernel.org/all/Z7VFB1nST6lbmBIo@xxxxxxxxxxxxxxxxxxxxxxxx/
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
Closes:
https://lore.kernel.org/all/dfe03f88-407e-4ef1-ad30-42db53bbd4e4@xxxxxxxxxxx/
Tested-by: Marek Szyprowski <m.szyprowski@xxxxxxxxxxx>
> ---
> drivers/pinctrl/bcm/pinctrl-bcm2835.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
> index cc1fe0555e19..eaeec096bc9a 100644
> --- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
> +++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
> @@ -346,14 +346,14 @@ static int bcm2835_gpio_get_direction(struct gpio_chip *chip, unsigned int offse
> struct bcm2835_pinctrl *pc = gpiochip_get_data(chip);
> enum bcm2835_fsel fsel = bcm2835_pinctrl_fsel_get(pc, offset);
>
> - /* Alternative function doesn't clearly provide a direction */
> - if (fsel > BCM2835_FSEL_GPIO_OUT)
> - return -EINVAL;
> + if (fsel == BCM2835_FSEL_GPIO_OUT)
> + return GPIO_LINE_DIRECTION_OUT;
>
> - if (fsel == BCM2835_FSEL_GPIO_IN)
> - return GPIO_LINE_DIRECTION_IN;
> -
> - return GPIO_LINE_DIRECTION_OUT;
> + /*
> + * Alternative function doesn't clearly provide a direction. Default
> + * to INPUT.
> + */
> + return GPIO_LINE_DIRECTION_IN;
> }
>
> static void bcm2835_gpio_set(struct gpio_chip *chip, unsigned offset, int value)

Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland