mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master] gpio: rockchip: fix support for RK3588/RK3566
@ 2024-04-15  5:31 Ahmad Fatoum
  2024-04-16 10:24 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-04-15  5:31 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The GPIO controller on newer Rockchip SoCs isn't compatible with the
older ones. Back when GPIOv2 support was added, RK3568 was the only
SoC supported using it, but since then support for the very similar
RK3566 as well as the newer RK3588 has followed, but the driver wasn't
extended to support them.

As GPIOv2 controllers have an identification register, start checking it
like Linux does and use that to detect whether we have a GPIOv2 or GPIOv1.

This issue was found trying to read GPIO inputs of the RK3566.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/gpio/gpio-rockchip.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index 7c67512ee380..2c13e97b9774 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -10,6 +10,10 @@
 #include <linux/basic_mmio_gpio.h>
 #include <mach/rockchip/rockchip.h>
 
+#define GPIO_TYPE_V1		(0)           /* GPIO Version ID reserved */
+#define GPIO_TYPE_V2		(0x01000C2B)  /* GPIO Version ID 0x01000C2B */
+#define GPIO_TYPE_V2_1		(0x0101157C)  /* GPIO Version ID 0x0101157C */
+
 struct rockchip_gpiochip {
 	struct device			*dev;
 	void __iomem			*reg_base;
@@ -131,6 +135,7 @@ static int rockchip_gpio_probe(struct device *dev)
 	struct gpio_chip *gpio;
 	struct resource *res;
 	void __iomem *reg_base;
+	u32 id, gpio_type;
 	int ret;
 
 	rgc = xzalloc(sizeof(*rgc));
@@ -153,7 +158,13 @@ static int rockchip_gpio_probe(struct device *dev)
 
 	reg_base = rgc->reg_base;
 
-	if (rockchip_soc() == 3568) {
+	id = readl(reg_base + 0x78);
+	if (id == GPIO_TYPE_V2 || id == GPIO_TYPE_V2_1)
+		gpio_type = GPIO_TYPE_V2;
+	else
+		gpio_type = GPIO_TYPE_V1;
+
+	if (gpio_type >= GPIO_TYPE_V2) {
 		gpio->ngpio = 32;
 		gpio->dev = dev;
 		gpio->ops = &rockchip_gpio_ops;
@@ -176,6 +187,9 @@ static int rockchip_gpio_probe(struct device *dev)
 		return ret;
 	}
 
+	dev_dbg(dev, "registered GPIOv%d-compatible bank\n",
+		gpio_type == GPIO_TYPE_V1 ? 1 : 2);
+
 	return 0;
 }
 
-- 
2.39.2




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

* Re: [PATCH master] gpio: rockchip: fix support for RK3588/RK3566
  2024-04-15  5:31 [PATCH master] gpio: rockchip: fix support for RK3588/RK3566 Ahmad Fatoum
@ 2024-04-16 10:24 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2024-04-16 10:24 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 15 Apr 2024 07:31:37 +0200, Ahmad Fatoum wrote:
> The GPIO controller on newer Rockchip SoCs isn't compatible with the
> older ones. Back when GPIOv2 support was added, RK3568 was the only
> SoC supported using it, but since then support for the very similar
> RK3566 as well as the newer RK3588 has followed, but the driver wasn't
> extended to support them.
> 
> As GPIOv2 controllers have an identification register, start checking it
> like Linux does and use that to detect whether we have a GPIOv2 or GPIOv1.
> 
> [...]

Applied, thanks!

[1/1] gpio: rockchip: fix support for RK3588/RK3566
      https://git.pengutronix.de/cgit/barebox/commit/?id=ff8547d924aa (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

end of thread, other threads:[~2024-04-16 10:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-15  5:31 [PATCH master] gpio: rockchip: fix support for RK3588/RK3566 Ahmad Fatoum
2024-04-16 10:24 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox