linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] fix gpio-sysfs/libgpiod for rockchip
@ 2022-09-23 14:51 Quentin Schulz
  2022-09-23 14:51 ` [PATCH 1/2] pinctrl: rockchip: add pinmux_ops.gpio_set_direction callback Quentin Schulz
  2022-09-23 14:51 ` [PATCH 2/2] gpio: rockchip: request GPIO mux to pinctrl when setting direction Quentin Schulz
  0 siblings, 2 replies; 5+ messages in thread
From: Quentin Schulz @ 2022-09-23 14:51 UTC (permalink / raw)
  Cc: linus.walleij, brgl, heiko, jay.xu, linux-gpio, linux-arm-kernel,
	linux-rockchip, linux-kernel, foss+kernel, Quentin Schulz

From: Quentin Schulz <quentin.schulz@theobroma-systems.com>

Since the split of gpio and pinctrl in their own driver, gpio-sysfs and
libgpiod userspace GPIO handling has been broken because the pins aren't
put into their GPIO function anymore since pinctrl subsystem is
"bypassed" when requesting GPIOs from userspace.

This fixes it by making the gpio driver actually request from the
pinctrl subsystem to put the pin in its GPIO function when the GPIO
direction is set in userspace.

I discovered the issue because we have a GPIO the user needs to control
from userspace to flash FW on an on-board STM32 that is actually on the
same pin as one used by the flash controller. Considering the storage
medium tried by the BOOTROM is emmc->nor->nand->sdmmc, booting from emmc
didn't show the issue because the default function for pins is GPIO and
the flash controller pins didn't need to be muxed by the BOOTROM.
However, if there's nothing on emmc, the BOOTROM does the pinmux for SPI
controller and puts the pins in their flash mode and therefore the
handling of that pin as a GPIO from userspace was not possible, but only
when booting on something else than eMMC.

This restores the behavior as seen in v5.14 and earlier.

Cheers,
Quentin

Quentin Schulz (2):
  pinctrl: rockchip: add pinmux_ops.gpio_set_direction callback
  gpio: rockchip: request GPIO mux to pinctrl when setting direction

 drivers/gpio/gpio-rockchip.c       |  6 ++++++
 drivers/pinctrl/pinctrl-rockchip.c | 13 +++++++++++++
 2 files changed, 19 insertions(+)

-- 
2.37.3


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] pinctrl: rockchip: add pinmux_ops.gpio_set_direction callback
  2022-09-23 14:51 [PATCH 0/2] fix gpio-sysfs/libgpiod for rockchip Quentin Schulz
@ 2022-09-23 14:51 ` Quentin Schulz
  2022-09-23 18:14   ` Heiko Stuebner
  2022-09-23 14:51 ` [PATCH 2/2] gpio: rockchip: request GPIO mux to pinctrl when setting direction Quentin Schulz
  1 sibling, 1 reply; 5+ messages in thread
From: Quentin Schulz @ 2022-09-23 14:51 UTC (permalink / raw)
  Cc: linus.walleij, brgl, heiko, jay.xu, linux-gpio, linux-arm-kernel,
	linux-rockchip, linux-kernel, foss+kernel, Quentin Schulz,
	stable

From: Quentin Schulz <quentin.schulz@theobroma-systems.com>

Before the split of gpio and pinctrl sections in their own driver,
rockchip_set_mux was called in pinmux_ops.gpio_set_direction for
configuring a pin in its GPIO function.

This is essential for cases where pinctrl is "bypassed" by gpio
consumers otherwise the GPIO function is not configured for the pin and
it does not work. Such was the case for the sysfs/libgpiod userspace
GPIO handling.

Let's re-implement the pinmux_ops.gpio_set_direction callback so that
the gpio subsystem can request from the pinctrl driver to put the pin in
its GPIO function.

Fixes: 9ce9a02039de ("pinctrl/rockchip: drop the gpio related codes")
Cc: stable@vger.kernel.org
Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
---
 drivers/pinctrl/pinctrl-rockchip.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c
index 32e41395fc768..c84bd0e1ce5a6 100644
--- a/drivers/pinctrl/pinctrl-rockchip.c
+++ b/drivers/pinctrl/pinctrl-rockchip.c
@@ -2393,11 +2393,24 @@ static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector,
 	return 0;
 }
 
+static int rockchip_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
+					   struct pinctrl_gpio_range *range,
+					   unsigned offset,
+					   bool input)
+{
+	struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
+	struct rockchip_pin_bank *bank;
+
+	bank = pin_to_bank(info, offset);
+	return rockchip_set_mux(bank, offset - bank->pin_base, RK_FUNC_GPIO);
+}
+
 static const struct pinmux_ops rockchip_pmx_ops = {
 	.get_functions_count	= rockchip_pmx_get_funcs_count,
 	.get_function_name	= rockchip_pmx_get_func_name,
 	.get_function_groups	= rockchip_pmx_get_groups,
 	.set_mux		= rockchip_pmx_set,
+	.gpio_set_direction	= rockchip_pmx_gpio_set_direction,
 };
 
 /*
-- 
2.37.3


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] gpio: rockchip: request GPIO mux to pinctrl when setting direction
  2022-09-23 14:51 [PATCH 0/2] fix gpio-sysfs/libgpiod for rockchip Quentin Schulz
  2022-09-23 14:51 ` [PATCH 1/2] pinctrl: rockchip: add pinmux_ops.gpio_set_direction callback Quentin Schulz
@ 2022-09-23 14:51 ` Quentin Schulz
  2022-09-23 18:41   ` Heiko Stuebner
  1 sibling, 1 reply; 5+ messages in thread
From: Quentin Schulz @ 2022-09-23 14:51 UTC (permalink / raw)
  Cc: linus.walleij, brgl, heiko, jay.xu, linux-gpio, linux-arm-kernel,
	linux-rockchip, linux-kernel, foss+kernel, Quentin Schulz,
	stable

From: Quentin Schulz <quentin.schulz@theobroma-systems.com>

Before the split of gpio and pinctrl sections in their own driver,
rockchip_set_mux was called in pinmux_ops.gpio_set_direction for
configuring a pin in its GPIO function.

This is essential for cases where pinctrl is "bypassed" by gpio
consumers otherwise the GPIO function is not configured for the pin and
it does not work. Such was the case for the sysfs/libgpiod userspace
GPIO handling.

Let's call pinctrl_gpio_direction_input/output when setting the
direction of a GPIO so that the pinctrl core requests from the rockchip
pinctrl driver to put the pin in its GPIO function.

Fixes: 9ce9a02039de ("pinctrl/rockchip: drop the gpio related codes")
Fixes: 936ee2675eee ("gpio/rockchip: add driver for rockchip gpio")
Cc: stable@vger.kernel.org
Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
---
 drivers/gpio/gpio-rockchip.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index bb50335239ac8..b83913e1ee49e 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -156,6 +156,12 @@ static int rockchip_gpio_set_direction(struct gpio_chip *chip,
 	unsigned long flags;
 	u32 data = input ? 0 : 1;
 
+
+	if (input)
+		pinctrl_gpio_direction_input(bank->pin_base + offset);
+	else
+		pinctrl_gpio_direction_output(bank->pin_base + offset);
+
 	raw_spin_lock_irqsave(&bank->slock, flags);
 	rockchip_gpio_writel_bit(bank, offset, data, bank->gpio_regs->port_ddr);
 	raw_spin_unlock_irqrestore(&bank->slock, flags);
-- 
2.37.3


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] pinctrl: rockchip: add pinmux_ops.gpio_set_direction callback
  2022-09-23 14:51 ` [PATCH 1/2] pinctrl: rockchip: add pinmux_ops.gpio_set_direction callback Quentin Schulz
@ 2022-09-23 18:14   ` Heiko Stuebner
  0 siblings, 0 replies; 5+ messages in thread
From: Heiko Stuebner @ 2022-09-23 18:14 UTC (permalink / raw)
  To: Quentin Schulz
  Cc: linus.walleij, brgl, jay.xu, linux-gpio, linux-arm-kernel,
	linux-rockchip, linux-kernel, foss+kernel, Quentin Schulz,
	stable

Am Freitag, 23. September 2022, 16:51:40 CEST schrieb Quentin Schulz:
> From: Quentin Schulz <quentin.schulz@theobroma-systems.com>
> 
> Before the split of gpio and pinctrl sections in their own driver,
> rockchip_set_mux was called in pinmux_ops.gpio_set_direction for
> configuring a pin in its GPIO function.
> 
> This is essential for cases where pinctrl is "bypassed" by gpio
> consumers otherwise the GPIO function is not configured for the pin and
> it does not work. Such was the case for the sysfs/libgpiod userspace
> GPIO handling.
> 
> Let's re-implement the pinmux_ops.gpio_set_direction callback so that
> the gpio subsystem can request from the pinctrl driver to put the pin in
> its GPIO function.
> 
> Fixes: 9ce9a02039de ("pinctrl/rockchip: drop the gpio related codes")
> Cc: stable@vger.kernel.org
> Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>

Reviewed-by: Heiko Stuebner <heiko@sntech.de>




_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] gpio: rockchip: request GPIO mux to pinctrl when setting direction
  2022-09-23 14:51 ` [PATCH 2/2] gpio: rockchip: request GPIO mux to pinctrl when setting direction Quentin Schulz
@ 2022-09-23 18:41   ` Heiko Stuebner
  0 siblings, 0 replies; 5+ messages in thread
From: Heiko Stuebner @ 2022-09-23 18:41 UTC (permalink / raw)
  To: Quentin Schulz
  Cc: linus.walleij, brgl, jay.xu, linux-gpio, linux-arm-kernel,
	linux-rockchip, linux-kernel, foss+kernel, Quentin Schulz,
	stable

Am Freitag, 23. September 2022, 16:51:41 CEST schrieb Quentin Schulz:
> From: Quentin Schulz <quentin.schulz@theobroma-systems.com>
> 
> Before the split of gpio and pinctrl sections in their own driver,
> rockchip_set_mux was called in pinmux_ops.gpio_set_direction for
> configuring a pin in its GPIO function.
> 
> This is essential for cases where pinctrl is "bypassed" by gpio
> consumers otherwise the GPIO function is not configured for the pin and
> it does not work. Such was the case for the sysfs/libgpiod userspace
> GPIO handling.
> 
> Let's call pinctrl_gpio_direction_input/output when setting the
> direction of a GPIO so that the pinctrl core requests from the rockchip
> pinctrl driver to put the pin in its GPIO function.
> 
> Fixes: 9ce9a02039de ("pinctrl/rockchip: drop the gpio related codes")
> Fixes: 936ee2675eee ("gpio/rockchip: add driver for rockchip gpio")
> Cc: stable@vger.kernel.org
> Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>

cool, thanks a lot for reimplementing this

Reviewed-by: Heiko Stuebner <heiko@sntech.de>



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-23 18:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-23 14:51 [PATCH 0/2] fix gpio-sysfs/libgpiod for rockchip Quentin Schulz
2022-09-23 14:51 ` [PATCH 1/2] pinctrl: rockchip: add pinmux_ops.gpio_set_direction callback Quentin Schulz
2022-09-23 18:14   ` Heiko Stuebner
2022-09-23 14:51 ` [PATCH 2/2] gpio: rockchip: request GPIO mux to pinctrl when setting direction Quentin Schulz
2022-09-23 18:41   ` Heiko Stuebner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).