gpio: rockchip: Update the GPIO driver
Subsystems (2)
v4 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'.
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 | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-)
Signature · 1 line
2.34.1
PATCH v4 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
@@ -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] - SVN 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
Re: [PATCH v4 1/4] gpio: rockchip: explan the format of the GPIO version ID
Quoted 2 lines · Ye Zhang
Remove redundant comments and provide a detailed explanation of the GPIO version ID.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v4 1/4] gpio: rockchip: explan the format of the GPIO version ID
In reply to Ye ZhangHi,
Quoted 5 lines · Ye Zhang
Remove redundant comments and provide a detailed explanation of the GPIO version ID.
Signed-off-by Ye Zhang <[email protected]>---
-- Sebastian
Quoted 29 lines
drivers/gpio/gpio-rockchip.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/gpio/gpio-rockchip.c +8
-2@@ -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] - SVN 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 · 1 line
2.34.1
Re: [PATCH v4 1/4] gpio: rockchip: explan the format of the GPIO version ID
In reply to Ye ZhangQuoted 4 lines · Ye Zhang
Remove redundant comments and provide a detailed explanation of the GPIO version ID.
Signed-off-by Ye Zhang <[email protected]>
Yours,
Linus Walleij
PATCH v4 2/4 gpio: rockchip: change the GPIO version judgment logic
In reply to Ye ZhangHave a list of valid IDs and default to -ENODEV.
--- drivers/gpio/gpio-rockchip.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/gpio/gpio-rockchip.c +11 -5
@@ -667,8 +667,13 @@ 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_V1 : + bank->gpio_regs = &gpio_regs_v1; + bank->gpio_type =GPIO_TYPE_V1 ; +break ; +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 +682,10 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)clk_disable_unprepare (bank->clk);return -EINVAL ; } - }else { - bank->gpio_regs = &gpio_regs_v1; - bank->gpio_type =GPIO_TYPE_V1 ; +break ; +default : +dev_err (bank->dev,"cannot get the version ID\n" ); +return -ENODEV ; }return 0 ;
Signature · 1 line
2.34.1
Re: [PATCH v4 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.
...
drivers/gpio/gpio-rockchip.c static int rockchip_get_bank_data(struct rockchip_pin_bank *bank) · line 671
Quoted 4 lines
drivers/gpio/gpio-rockchip.c +2
-2-/* If not gpio v2, that is default to v1. */ -if (id ==GPIO_TYPE_V2 || id ==GPIO_TYPE_V2_1 ) { +switch (id) { +case GPIO_TYPE_V1 :
If you leave the V2 case first...
drivers/gpio/gpio-rockchip.c static int rockchip_get_bank_data(struct rockchip_pin_bank *bank) · line 676
Quoted 5 lines
drivers/gpio/gpio-rockchip.c +5
-0+ bank->gpio_regs = &gpio_regs_v1; + bank->gpio_type =GPIO_TYPE_V1 ; +break ; +case GPIO_TYPE_V2 : +case GPIO_TYPE_V2_1 :
...and the v1 case last, the whole diff will be much more understandable and reviewable.
Quoted 15 lines
drivers/gpio/gpio-rockchip.c +4
-3bank->gpio_regs = &gpio_regs_v2; bank->gpio_type =GPIO_TYPE_V2 ; bank->db_clk =of_clk_get (bank->of_node,1 );@@ -677,9 +682,10 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)clk_disable_unprepare (bank->clk);return -EINVAL ; } - }else { - bank->gpio_regs = &gpio_regs_v1; - bank->gpio_type =GPIO_TYPE_V1 ; +break ; +default : +dev_err (bank->dev,"cannot get the version ID\n" ); +return -ENODEV ; }
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v4 2/4] gpio: rockchip: change the GPIO version judgment logic
In reply to Ye ZhangHi,
Quoted 28 lines · Ye Zhang
Have a list of valid IDs and default to
-ENODEV.Signed-off-by Ye Zhang <[email protected]>--- drivers/gpio/gpio-rockchip.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)drivers/gpio/gpio-rockchip.c +7
-2@@ -667,8 +667,13 @@ 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_V1 : + bank->gpio_regs = &gpio_regs_v1; + bank->gpio_type =GPIO_TYPE_V1 ; +break ; +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 );
drivers/gpio/gpio-rockchip.c static int rockchip_get_bank_data(struct rockchip_pin_bank *bank) · line 687
Quoted 9 lines
drivers/gpio/gpio-rockchip.c +3
-3@@ -677,9 +682,10 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)clk_disable_unprepare (bank->clk);return -EINVAL ; } - }else { - bank->gpio_regs = &gpio_regs_v1; - bank->gpio_type =GPIO_TYPE_V1 ; +break ; +default : +dev_err (bank->dev,"cannot get the version ID\n" );
I think this would be a better error message:
dev_err(bank->dev, "unsupported version ID: 0x%08x\n", id);
But it can be improved later on. Just like the next patch I think this should go into the 6.13 kernel as soon as possible to fix handling of the Rockchip RK3576, which currently initializes its GPIO controller using the v1 register layer instead of the v2 register layout.
-- Sebastian
Quoted 8 lines
drivers/gpio/gpio-rockchip.c +1
-0+return -ENODEV ; }return 0 ;Signature · 1 line
2.34.1
PATCH v4 3/4 gpio: rockchip: support new version GPIO
In reply to Ye ZhangSupport 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
@@ -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 ,
@@ -674,6 +675,7 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)break ;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 · 1 line
2.34.1
Re: [PATCH v4 3/4] gpio: rockchip: support new version GPIO
Quoted 1 line · Ye Zhang
Support the next version GPIO controller on SoCs like rk3576.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v4 3/4] gpio: rockchip: support new version GPIO
In reply to Ye ZhangHi,
Quoted 4 lines · Ye Zhang
Support the next version GPIO controller on SoCs like rk3576.
Signed-off-by Ye Zhang <[email protected]>---
This is needed for 6.13, which introduces RK3576 support and currently (linux-next) tries to use the GPIO controller in V1 mode.
-- Sebastian
Quoted 27 lines
drivers/gpio/gpio-rockchip.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpio/gpio-rockchip.c +2
-0@@ -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 ,@@ -674,6 +675,7 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)break ;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 · 1 line
2.34.1
Re: [PATCH v4 3/4] gpio: rockchip: support new version GPIO
In reply to Ye ZhangQuoted 3 lines · Ye Zhang
Support the next version GPIO controller on SoCs like rk3576.
Signed-off-by Ye Zhang <[email protected]>
Yours,
Linus Walleij
PATCH v4 4/4 gpio: rockchip: Set input direction when request irq
In reply to Ye ZhangSince 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
@@ -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 · 1 line
2.34.1
Re: [PATCH v4 4/4] gpio: rockchip: Set input direction when request irq
Hi,
Quoted 5 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.
Signed-off-by Ye Zhang <[email protected]>---
-- Sebastian
Quoted 24 lines
drivers/gpio/gpio-rockchip.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpio/gpio-rockchip.c +4
-1@@ -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 · 1 line
2.34.1
Re: [PATCH v4 4/4] gpio: rockchip: Set input direction when request irq
In reply to Ye ZhangQuoted 4 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.
Signed-off-by Ye Zhang <[email protected]>
Yours,
Linus Walleij