Skip to contentSkip to conversation

gpio: rockchip: Update the GPIO driver

PATCH Applied Ye Zhang 4 participants 13 messages Nov 12, 2024

Subsystems (2)
lore
Share & tools
lore

Ye Zhang

author
#0 lore raw

v5 cover gpio: rockchip: Update the GPIO driver

GPIO driver support acpi and new version, set input direction in irq_request_resources, fix division error and debounce config error.

Changes since v1:
- Split commits with multiple changes into separate commits.
- Adjust backportable fix to the forefront.
- Modify messages of some commits.

Changes since v2:
- Optimize version number comments.
- Modify the GPIO version judgment logic.
- Use devm_clk_get_enabled to simplify the code.
- Use guard instead of mutex_lock to simplify the code.
- Use irq_hw_number_t and irqd_to_hwirq() in the request irq function.
- Since list_first_entry cannot return NULL, remove the NULL check.
- Temporarily do not add support for ACPI.

Changes since v3:
- Give up modifying the debounce config because it is not actually used.
- Do not add support for retrieving clocks using 'clock-names'.

Change since v4:
- Leave the V2 case first and the V1 case last in version judgment.
- Fix the error message in version judgment.

Ye Zhang (4):
gpio: rockchip: explan the format of the GPIO version ID
gpio: rockchip: change the GPIO version judgment logic
gpio: rockchip: support new version GPIO
gpio: rockchip: Set input direction when request irq

 drivers/gpio/gpio-rockchip.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)
Signature · 7 lines
2.34.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
author
#1 lore raw

PATCH v5 1/4 gpio: rockchip: explan the format of the GPIO version ID

Remove redundant comments and provide a detailed explanation of the GPIO version ID.

---
 drivers/gpio/gpio-rockchip.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpio/gpio-rockchip.c +8 -2
index 365ab947983c..702e711f9c23 100644
@@ -26,9 +26,15 @@
 #include "../pinctrl/core.h"
 #include "../pinctrl/pinctrl-rockchip.h"
 
+/*
+ * Version ID Register
+ * Bits [31:24] - Major Version
+ * Bits [23:16] - Minor Version
+ * Bits [15:0]  - Revision Number
+ */
 #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 */
+#define GPIO_TYPE_V2		(0x01000C2B)
+#define GPIO_TYPE_V2_1		(0x0101157C)
 
 static const struct rockchip_gpio_regs gpio_regs_v1 = {
 	.port_dr = 0x00,
Signature · 7 lines
2.34.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
author
#2 lore raw

PATCH v5 2/4 gpio: rockchip: change the GPIO version judgment logic

In reply to Ye Zhang

Have a list of valid IDs and default to -ENODEV.

---
 drivers/gpio/gpio-rockchip.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/gpio/gpio-rockchip.c +9 -3
index 702e711f9c23..49eaefeed8fa 100644
@@ -667,8 +667,9 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
 	clk_prepare_enable(bank->clk);
 	id = readl(bank->reg_base + gpio_regs_v2.version_id);
 
-	/* If not gpio v2, that is default to v1. */
-	if (id == GPIO_TYPE_V2 || id == GPIO_TYPE_V2_1) {
+	switch (id) {
+	case GPIO_TYPE_V2:
+	case GPIO_TYPE_V2_1:
 		bank->gpio_regs = &gpio_regs_v2;
 		bank->gpio_type = GPIO_TYPE_V2;
 		bank->db_clk = of_clk_get(bank->of_node, 1);
@@ -677,9 +678,14 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
 			clk_disable_unprepare(bank->clk);
 			return -EINVAL;
 		}
-	} else {
+		break;
+	case GPIO_TYPE_V1:
 		bank->gpio_regs = &gpio_regs_v1;
 		bank->gpio_type = GPIO_TYPE_V1;
+		break;
+	default:
+		dev_err(bank->dev, "unsupported version ID: 0x%08x\n", id);
+		return -ENODEV;
 	}
 
 	return 0;
Signature · 1 line
2.34.1
Reviewed-by on v5 2/4
#3 lore raw

Re: [PATCH v5 2/4] gpio: rockchip: change the GPIO version judgment logic

Quoted 1 line · Ye Zhang

Have a list of valid IDs and default to -ENODEV.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#4 lore raw

PATCH v5 3/4 gpio: rockchip: support new version GPIO

In reply to Ye Zhang

Support the next version GPIO controller on SoCs like rk3576.

---
 drivers/gpio/gpio-rockchip.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpio/gpio-rockchip.c +2 -0
index 49eaefeed8fa..c090cac694bf 100644
@@ -35,6 +35,7 @@
 #define GPIO_TYPE_V1		(0)           /* GPIO Version ID reserved */
 #define GPIO_TYPE_V2		(0x01000C2B)
 #define GPIO_TYPE_V2_1		(0x0101157C)
+#define GPIO_TYPE_V2_2		(0x010219C8)
 
 static const struct rockchip_gpio_regs gpio_regs_v1 = {
 	.port_dr = 0x00,
@@ -670,6 +671,7 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
 	switch (id) {
 	case GPIO_TYPE_V2:
 	case GPIO_TYPE_V2_1:
+	case GPIO_TYPE_V2_2:
 		bank->gpio_regs = &gpio_regs_v2;
 		bank->gpio_type = GPIO_TYPE_V2;
 		bank->db_clk = of_clk_get(bank->of_node, 1);
Signature · 7 lines
2.34.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
author
#5 lore raw

PATCH v5 4/4 gpio: rockchip: Set input direction when request irq

In reply to Ye Zhang

Since the GPIO can only generate interrupts when its direction is set to input, it is set to input before requesting the interrupt resources.

---
 drivers/gpio/gpio-rockchip.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpio/gpio-rockchip.c +4 -1
index c090cac694bf..cdfdd5501a1e 100644
@@ -476,8 +476,11 @@ static int rockchip_irq_reqres(struct irq_data *d)
 {
 	struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
 	struct rockchip_pin_bank *bank = gc->private;
+	irq_hw_number_t hwirq = irqd_to_hwirq(d);
 
-	return gpiochip_reqres_irq(&bank->gpio_chip, d->hwirq);
+	rockchip_gpio_direction_input(&bank->gpio_chip, hwirq);
+
+	return gpiochip_reqres_irq(&bank->gpio_chip, hwirq);
 }
 
 static void rockchip_irq_relres(struct irq_data *d)
Signature · 7 lines
2.34.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
#6 lore raw

Re: [PATCH v5 4/4] gpio: rockchip: Set input direction when request irq

Quoted 28 lines · Ye Zhang

Since the GPIO can only generate interrupts when its direction is set to input, it is set to input before requesting the interrupt resources.

---
 drivers/gpio/gpio-rockchip.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpio/gpio-rockchip.c +4 -2
index c090cac694bf..cdfdd5501a1e 100644
@@ -476,8 +476,11 @@ static int rockchip_irq_reqres(struct irq_data *d)
 {
        struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
        struct rockchip_pin_bank *bank = gc->private;
+       irq_hw_number_t hwirq = irqd_to_hwirq(d);
 
-       return gpiochip_reqres_irq(&bank->gpio_chip, d->hwirq);
+       rockchip_gpio_direction_input(&bank->gpio_chip, hwirq);
+
+       return gpiochip_reqres_irq(&bank->gpio_chip, hwirq);
 }
 
 static void rockchip_irq_relres(struct irq_data *d)
--
Quoted 2 lines

2.34.1

This looks like a fix to me, do you want it sent for stable? If so, please add the Fixes tag and put it first in the series.

Bart

#7 lore raw

Re: [PATCH v5 4/4] gpio: rockchip: Set input direction when request irq

Quoted 4 lines · Bartosz Golaszewski
Quoted 3 lines · Ye Zhang

Since the GPIO can only generate interrupts when its direction is set to input, it is set to input before requesting the interrupt resources.

...

Quoted 2 lines

This looks like a fix to me, do you want it sent for stable? If so, please add the Fixes tag and put it first in the series.

Independently on the resolution on this, can the first three be applied to for-next? I think they are valuable from the documentation perspective as it adds the explanation of the version register bit fields.

The last one seems to me independent (code wise, meaning no potential conflicts) to the rest and may be applied to for-current later on.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw

Re: [PATCH v5 4/4] gpio: rockchip: Set input direction when request irq

Quoted 16 lines · Andy Shevchenko
Quoted 4 lines · Bartosz Golaszewski
Quoted 3 lines · Ye Zhang

Since the GPIO can only generate interrupts when its direction is set to input, it is set to input before requesting the interrupt resources.

...

Quoted 2 lines

This looks like a fix to me, do you want it sent for stable? If so, please add the Fixes tag and put it first in the series.

Independently on the resolution on this, can the first three be applied to for-next? I think they are valuable from the documentation perspective as it adds the explanation of the version register bit fields.

Quoted 8 lines

The last one seems to me independent (code wise, meaning no potential conflicts) to the rest and may be applied to for-current later on.

--
With Best Regards,
Andy Shevchenko

There's another issue I see with this patch. It effectively changes the pin's direction behind the back of the GPIOLIB. If a GPIO is requested, its direction set to output and another orthogonal user requests the same pin as input, we'll never update the FLAG_IS_OUT value and I don't think any subsequent behavior can be considered defined.

I applied the first 3 patches as they look alright.

Bart

#9 lore raw

Re: [PATCH v5 4/4] gpio: rockchip: Set input direction when request irq

Quoted 28 lines · Bartosz Golaszewski
Quoted 16 lines · Andy Shevchenko
Quoted 4 lines · Bartosz Golaszewski
Quoted 3 lines · Ye Zhang

Since the GPIO can only generate interrupts when its direction is set to input, it is set to input before requesting the interrupt resources.

...

Quoted 2 lines

This looks like a fix to me, do you want it sent for stable? If so, please add the Fixes tag and put it first in the series.

Independently on the resolution on this, can the first three be applied to for-next? I think they are valuable from the documentation perspective as it adds the explanation of the version register bit fields.

Quoted 8 lines

The last one seems to me independent (code wise, meaning no potential conflicts) to the rest and may be applied to for-current later on.

--
With Best Regards,
Andy Shevchenko

Quoted 4 lines

There's another issue I see with this patch. It effectively changes the pin's direction behind the back of the GPIOLIB. If a GPIO is requested, its direction set to output and another orthogonal user requests the same pin as input, we'll never update the FLAG_IS_OUT

I meant to say "same pin as interrupt". Sorry for the noise.

Bart

Quoted 6 lines

value and I don't think any subsequent behavior can be considered defined.

I applied the first 3 patches as they look alright.

Bart

#10 lore raw

Re: [PATCH v5 4/4] gpio: rockchip: Set input direction when request irq

Hi,

Quoted 27 lines · Bartosz Golaszewski
Quoted 26 lines · Bartosz Golaszewski
Quoted 23 lines · Andy Shevchenko
Quoted 4 lines · Bartosz Golaszewski
Quoted 3 lines · Ye Zhang

Since the GPIO can only generate interrupts when its direction is set to input, it is set to input before requesting the interrupt resources.

...

Quoted 2 lines

This looks like a fix to me, do you want it sent for stable? If so, please add the Fixes tag and put it first in the series.

Independently on the resolution on this, can the first three be applied to for-next? I think they are valuable from the documentation perspective as it adds the explanation of the version register bit fields.

The last one seems to me independent (code wise, meaning no potential conflicts) to the rest and may be applied to for-current later on.

--
With Best Regards,
Andy Shevchenko

Quoted 6 lines
Quoted 4 lines

There's another issue I see with this patch. It effectively changes the pin's direction behind the back of the GPIOLIB. If a GPIO is requested, its direction set to output and another orthogonal user requests the same pin as input, we'll never update the FLAG_IS_OUT

I meant to say "same pin as interrupt". Sorry for the noise.

GPIO output and interrupt at the same time looks like a misconfiguration to me. Maybe check for that situation and return -EBUSY?

-- Sebastian

Quoted 9 lines

Bart

Quoted 6 lines

value and I don't think any subsequent behavior can be considered defined.

I applied the first 3 patches as they look alright.

Bart

#11 lore raw

Re: [PATCH v5 4/4] gpio: rockchip: Set input direction when request irq

Quoted 36 lines · Sebastian Reichel

Hi,

Quoted 32 lines · Bartosz Golaszewski
Quoted 30 lines · Bartosz Golaszewski
Quoted 15 lines · Andy Shevchenko
Quoted 4 lines · Bartosz Golaszewski
Quoted 3 lines · Ye Zhang

Since the GPIO can only generate interrupts when its direction is set to input, it is set to input before requesting the interrupt resources.

...

Quoted 2 lines

This looks like a fix to me, do you want it sent for stable? If so, please add the Fixes tag and put it first in the series.

Independently on the resolution on this, can the first three be applied to for-next? I think they are valuable from the documentation perspective as it adds the explanation of the version register bit fields.

Quoted 8 lines

The last one seems to me independent (code wise, meaning no potential conflicts) to the rest and may be applied to for-current later on.

--
With Best Regards,
Andy Shevchenko

There's another issue I see with this patch. It effectively changes the pin's direction behind the back of the GPIOLIB. If a GPIO is requested, its direction set to output and another orthogonal user requests the same pin as input, we'll never update the FLAG_IS_OUT

Quoted 5 lines
Quoted 1 line

I meant to say "same pin as interrupt". Sorry for the noise.

GPIO output and interrupt at the same time looks like a misconfiguration to me. Maybe check for that situation and return -EBUSY?

Of course it is. That's why we check for it in gpiod_direction_output() and in gpiochip_lock_as_irq(): refuse to set direction to output if the GPIO is used as interrupt and refuse to use it as interrupt if direction already is output respectively.

This patch however proposes to set the direction to input implicitly which is wrong. The underlying gpiochip_reqres_irq() will check the current direction and return -EIO if it's output.

Bart

#12 lore raw

Re: (subset) [PATCH v5 0/4] gpio: rockchip: Update the GPIO driver

In reply to Ye Zhang

From: Bartosz Golaszewski <[email protected]>

Quoted 9 lines · Ye Zhang

GPIO driver support acpi and new version, set input direction in irq_request_resources, fix division error and debounce config error.

Changes since v1:
- Split commits with multiple changes into separate commits.
- Adjust backportable fix to the forefront.
- Modify messages of some commits.

[...]

Applied, thanks!

[1/4] gpio: rockchip: explan the format of the GPIO version ID

      commit: 591ae6bed250e4067db926313ff7279d23a1c7d1
[2/4] gpio: rockchip: change the GPIO version judgment logic
      commit: 41209307cad7f14c387c68375a93b50e54261a53
[3/4] gpio: rockchip: support new version GPIO
      commit: 8bcbd0379c05c66ce2e842c7e8901aa317cdf04e

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>