Add gpio driver support for Realtek DHC SoCs
Subsystems (2)
v3 cover Add gpio driver support for Realtek DHC SoCs
These patches add the bindings and the gpio driver for Realtek DHC(Digital Home Center) RTD SoCs, including RTD1295, RTD1395, RTD1619, RTD1319, RTD1619B, RTD1319D and RTD1315E.
Change log:v2->v3:
1. Remove generic compatible and use SoC-specific compatible instead.
2. Add the missing descriptions for the rtd_gpio_info structure members.
3. Assign gpio_chip fwnode.v1->v2:
1. Add description for DHC RTD SoCs in the bindings.
2. Revise the compatible names in the bindings.
3. Transitioned from OF API to platform_device API.
4. Use u8 for the offset array within the rtd_gpio_info structure.
5. Record the size of each array within the rtd_gpio_info structure and implement checks to prevent out-of-bounds access.
6. Use GPIOLIB_IRQCHIP helpers to register interrupts.
7. Use dynamic allocation for GPIO base.
Tzuyi Chang (2):
dt-bindings: gpio: realtek: Add realtek,rtd-gpio
Add GPIO support for Realtek DHC(Digital Home Center) RTD SoCs.
.../bindings/gpio/realtek,rtd-gpio.yaml | 69 ++ drivers/gpio/Kconfig | 9 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-rtd.c | 748 ++++++++++++++++++ 4 files changed, 827 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/realtek,rtd-gpio.yaml create mode 100644 drivers/gpio/gpio-rtd.c
Signature · 1 line
2.43.0
PATCH v3 1/2 dt-bindings: gpio: realtek: Add realtek,rtd-gpio
From: Tzuyi Chang <[email protected]>
Add the device tree bindings for the Realtek DHC(Digital Home Center) RTD SoCs GPIO controllers.
---
v2 to v3 change:
1. Remove generic compatible and use SoC-specific compatible instead.
v1 to v2 change:
1. Add description for DHC RTD SoCs.
2. Revise the compatible names.
3. Add descriptions for reg and interrupts properties.
--- .../bindings/gpio/realtek,rtd-gpio.yaml | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/realtek,rtd-gpio.yaml
Documentation/devicetree/bindings/gpio/realtek,rtd-gpio.yaml new file +69 -0
@@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright 2023 Realtek Semiconductor Corporation +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/gpio/realtek,rtd-gpio.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Realtek DHC GPIO controller + +maintainers: + - Tzuyi Chang <[email protected]> + +description: + The GPIO controller is designed for the Realtek DHC (Digital Home Center) + RTD series SoC family, which are high-definition media processor SoCs. + +properties: + compatible: + enum: + - realtek,rtd1295-misc-gpio + - realtek,rtd1295-iso-gpio + - realtek,rtd1395-iso-gpio + - realtek,rtd1619-iso-gpio + - realtek,rtd1319-iso-gpio + - realtek,rtd1619b-iso-gpio + - realtek,rtd1319d-iso-gpio + - realtek,rtd1315e-iso-gpio + + reg: + items: + - description: GPIO controller registers + - description: GPIO interrupt registers + + interrupts: + items: + - description: Interrupt number of the assert GPIO interrupt, which is + triggered when there is a rising edge. + - description: Interrupt number of the deassert GPIO interrupt, which is + triggered when there is a falling edge. + + gpio-ranges: true + + gpio-controller: true + + "#gpio-cells": + const: 2 + +required: + - compatible + - reg + - interrupts + - gpio-ranges + - gpio-controller + - "#gpio-cells" + +additionalProperties: false + +examples: + - | + gpio@100 { + compatible = "realtek,rtd1319d-iso-gpio"; + reg = <0x100 0x100>, + <0x000 0x0b0>; + interrupt-parent = <&iso_irq_mux>; + interrupts = <19>, <20>; + gpio-ranges = <&pinctrl 0 0 82>; + gpio-controller; + #gpio-cells = <2>; + };
Signature · 1 line
2.43.0
Re: [PATCH v3 1/2] dt-bindings: gpio: realtek: Add realtek,rtd-gpio
Quoted 41 lines · TY Chang
From: Tzuyi Chang <[email protected]>
Add the device tree bindings for the Realtek DHC(Digital Home Center) RTD SoCs GPIO controllers.
Signed-off-by Tzuyi Chang <[email protected]>---
v2 to v3 change:
1. Remove generic compatible and use SoC-specific compatible instead.
v1 to v2 change:
1. Add description for DHC RTD SoCs.
2. Revise the compatible names.
3. Add descriptions for reg and interrupts properties.--- .../bindings/gpio/realtek,rtd-gpio.yaml | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/realtek,rtd-gpio.yamlDocumentation/devicetree/bindings/gpio/realtek,rtd-gpio.yaml new file +17
-0@@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright 2023 Realtek Semiconductor Corporation +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/gpio/realtek,rtd-gpio.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Realtek DHC GPIO controller + +maintainers: + - Tzuyi Chang <[email protected]> + +description: + The GPIO controller is designed for the Realtek DHC (Digital Home Center) + RTD series SoC family, which are high-definition media processor SoCs. + +properties:
Documentation/devicetree/bindings/gpio/realtek,rtd-gpio.yaml line 27
Quoted 10 lines
Documentation/devicetree/bindings/gpio/realtek,rtd-gpio.yaml new file +10
-0+ compatible: + enum: + - realtek,rtd1295-misc-gpio + - realtek,rtd1295-iso-gpio + - realtek,rtd1395-iso-gpio + - realtek,rtd1619-iso-gpio + - realtek,rtd1319-iso-gpio + - realtek,rtd1619b-iso-gpio + - realtek,rtd1319d-iso-gpio + - realtek,rtd1315e-iso-gpio
If there is going to be resend, please order this list alphanumerically.
Quoted 6 lines
Documentation/devicetree/bindings/gpio/realtek,rtd-gpio.yaml new file +6
-0+ + reg: + items: + - description: GPIO controller registers + - description: GPIO interrupt registers +
...
Documentation/devicetree/bindings/gpio/realtek,rtd-gpio.yaml line 63
Quoted 9 lines
Documentation/devicetree/bindings/gpio/realtek,rtd-gpio.yaml new file +9
-0+ +additionalProperties: false + +examples: + - | + gpio@100 { + compatible = "realtek,rtd1319d-iso-gpio"; + reg = <0x100 0x100>, + <0x000 0x0b0>;
That's odd. Why order is decreasing? Isn't 0x0 the address of the SoC (soc@0)?
It is, btw, 0x0, not 0x000. The same for 0x0b0 -> 0xb0, unless you want to pad to full word.
Best regards,
Krzysztof
RE: [PATCH v3 1/2] dt-bindings: gpio: realtek: Add realtek,rtd-gpio
Hi Krzysztof,
Quoted 29 lines
Quoted 29 lines
diff --git
a/Documentation/devicetree/bindings/gpio/realtek,rtd-gpio.yamlb/Documentation/devicetree/bindings/gpio/realtek,rtd-gpio.yamlnew file mode 100644
index 000000000000..984e7dbd322eDocumentation/devicetree/bindings/gpio/realtek,rtd-gpio.yaml new file +21
-0@@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) # Copyright 2023 +Realtek Semiconductor Corporation %YAML 1.2 +--- +$id: http://devicetree.org/schemas/gpio/realtek,rtd-gpio.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Realtek DHC GPIO controller + +maintainers: + - Tzuyi Chang <[email protected]> + +description: + The GPIO controller is designed for the Realtek DHC (Digital Home +Center) + RTD series SoC family, which are high-definition media processor SoCs. + +properties: + compatible: + enum: + - realtek,rtd1295-misc-gpio + - realtek,rtd1295-iso-gpio
Quoted 9 lines
Documentation/devicetree/bindings/gpio/realtek,rtd-gpio.yaml line 27
Quoted 6 lines
Documentation/devicetree/bindings/gpio/realtek,rtd-gpio.yaml new file +6
-0+ - realtek,rtd1395-iso-gpio + - realtek,rtd1619-iso-gpio + - realtek,rtd1319-iso-gpio + - realtek,rtd1619b-iso-gpio + - realtek,rtd1319d-iso-gpio + - realtek,rtd1315e-iso-gpioIf there is going to be resend, please order this list alphanumerically.
I will revise it in the next version
Quoted 9 lines
Quoted 6 lines
Documentation/devicetree/bindings/gpio/realtek,rtd-gpio.yaml new file +6
-0+ + reg: + items: + - description: GPIO controller registers + - description: GPIO interrupt registers +...
Quoted 12 lines
Documentation/devicetree/bindings/gpio/realtek,rtd-gpio.yaml line 63
Quoted 9 lines
Documentation/devicetree/bindings/gpio/realtek,rtd-gpio.yaml new file +9
-0+ +additionalProperties: false + +examples: + - | + gpio@100 { + compatible = "realtek,rtd1319d-iso-gpio"; + reg = <0x100 0x100>, + <0x000 0x0b0>;That's odd. Why order is decreasing? Isn't
0x0the address of the SoC (soc@0)?
The DTS use in our platform follows this structure:
soc@0 {
rbus: rbus@98000000 {
...
iso: syscon@7000 {
...
gpio: gpio@100 {
compatible = "realtek,rtd1319d-iso-gpio";
reg = <0x100 0x100>,
<0x000 0x0b0>;
interrupt-parent = <&iso_irq_mux>;
interrupts = <19>, <20>;
gpio-ranges = <&pinctrl 0 0 82>;
gpio-controller;
#gpio-cells = <2>;
};
};
};
};The base address for the GPIO controller is 0x98007100. The second line of 'reg' refers to the GPIO interrupt status registers, which are distributed within the range of 0x98007000 to 0x980070AF. Would it be advisable to fetch the syscon from parent node(iso: syscon@7000) to handle the GPIO interrupt status registers?
Quoted 3 lines
It is, btw,
0x0, not0x000. The same for0x0b0->0xb0, unless you want to pad to full word.
I will revise it in the next version.
Thanks,
Tzuyi Chang
Re: [PATCH v3 1/2] dt-bindings: gpio: realtek: Add realtek,rtd-gpio
Quoted 22 lines · TY_Chang[張子逸]
The DTS use in our platform follows this structure:
soc@0 { rbus: rbus@98000000 { ... iso: syscon@7000 { ... gpio: gpio@100 { compatible = "realtek,rtd1319d-iso-gpio"; reg = <0x100 0x100>, <0x000 0x0b0>; interrupt-parent = <&iso_irq_mux>; interrupts = <19>, <20>; gpio-ranges = <&pinctrl 0 0 82>; gpio-controller; #gpio-cells = <2>; }; }; }; };
Quoted 3 lines
The base address for the GPIO controller is
0x98007100. The second line of 'reg' refers to the GPIO interrupt status registers, which are distributed within the range of0x98007000to0x980070AF.
Ah, ok.
Quoted 3 lines
Would it be advisable to fetch the
syscon from parent node(iso: syscon@7000) to handle the GPIO interrupt status registers?
If these are GPIO interrupts then current description is fine.
Quoted 4 lines
Quoted 4 lines
It is, btw,
0x0, not0x000. The same for0x0b0->0xb0, unless you want to pad to full word.
Best regards,
Krzysztof
PATCH v3 2/2 Add GPIO support for Realtek DHC(Digital Home Center) RTD SoCs.
In reply to TY ChangFrom: Tzuyi Chang <[email protected]>
This driver enables configuration of GPIO direction, GPIO values, GPIO debounce settings and handles GPIO interrupts.
---
v2 to v3 change:
1. Remove generic compatible and use SoC-specific compatible instead.
2. Add the missing descriptions for the rtd_gpio_info structure members.
3. Assign gpio_chip fwnode.
v1 to v2 change:
1. Remove legacy headers.
2. Transitioned from OF API to platform_device API.
3. Use u8 for the offset member within the rtd_gpio_info structure.
4. Record the size of each array within the rtd_gpio_info structure and implement checks to prevent out-of-bounds access.
5. Use GPIOLIB_IRQCHIP helpers to register interrupts.
6. Use dynamic allocation for GPIO base.
--- drivers/gpio/Kconfig | 9 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-rtd.c | 748 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 758 insertions(+) create mode 100644 drivers/gpio/gpio-rtd.c
drivers/gpio/Kconfig +9 -0
@@ -553,6 +553,15 @@ config GPIO_ROCKCHIP help Say yes here to support GPIO on Rockchip SoCs. +config GPIO_RTD + tristate "Realtek DHC GPIO support" + depends on ARCH_REALTEK + default y + select GPIOLIB_IRQCHIP + help + Say yes here to support GPIO on Realtek DHC(Digital Home Center) + SoCs. + config GPIO_SAMA5D2_PIOBU tristate "SAMA5D2 PIOBU GPIO support" depends on MFD_SYSCON
drivers/gpio/Makefile +1 -0
@@ -137,6 +137,7 @@ obj-$(CONFIG_GPIO_RDC321X) += gpio-rdc321x.o obj-$(CONFIG_GPIO_REALTEK_OTTO) += gpio-realtek-otto.o obj-$(CONFIG_GPIO_REG) += gpio-reg.o obj-$(CONFIG_GPIO_ROCKCHIP) += gpio-rockchip.o +obj-$(CONFIG_GPIO_RTD) += gpio-rtd.o obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o obj-$(CONFIG_GPIO_SAMA5D2_PIOBU) += gpio-sama5d2-piobu.o obj-$(CONFIG_GPIO_SCH311X) += gpio-sch311x.o
drivers/gpio/gpio-rtd.c new file +748 -0
748 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v3 2/2] Add GPIO support for Realtek DHC(Digital Home Center) RTD SoCs.
Quoted 4 lines · TY Chang
From: Tzuyi Chang <[email protected]>
This driver enables configuration of GPIO direction, GPIO values, GPIO debounce settings and handles GPIO interrupts.
Why gpio-regmap can't be used?
...
Quoted 8 lines
drivers/gpio/gpio-rtd.c new file +7
-0+struct rtd_gpio_info { +u8 *dir_offset; +u8 num_dir; +u8 *dato_offset; +u8 num_dato; +u8 *dati_offset; +u8 num_dati;
drivers/gpio/gpio-rtd.c line 78
Quoted 10 lines
drivers/gpio/gpio-rtd.c new file +10
-0+u8 *ie_offset; +u8 num_ie; +u8 *dp_offset; +u8 num_dp; +u8 *gpa_offset; +u8 num_gpa; +u8 *gpda_offset; +u8 num_gpda; +u8 *deb_offset; +u8 num_deb;
A lot of wasted space. Can you group pointers followed by u8 members? Note, use pahole tool to check the struct layout in C.
Quoted 1 line
+};
...
drivers/gpio/gpio-rtd.c line 82
Quoted 2 lines
drivers/gpio/gpio-rtd.c new file +2
-0+struct rtd_gpio { +struct platform_device *pdev;
Why
struct device *dev;
is not suffice?
drivers/gpio/gpio-rtd.c line 86
Quoted 5 lines
drivers/gpio/gpio-rtd.c new file +4
-0+const struct rtd_gpio_info *info; +void __iomem *base; +void __iomem *irq_base; +struct gpio_chip gpio_chip;
Make this to be the first member, it might reduce some code (due to pointer arithmetics).
drivers/gpio/gpio-rtd.c line 91
Quoted 5 lines
drivers/gpio/gpio-rtd.c new file +5
-0+unsigned int irqs[2 ]; +spinlock_t lock; +}; + +
One blank line is enough.
...
Quoted 12 lines
drivers/gpio/gpio-rtd.c new file +12
-0+static const struct rtd_gpio_info rtd_iso_gpio_info = { + .name ="rtd_iso_gpio" , + .type =RTD_ISO_GPIO , + .gpio_base =0 , + .num_gpios =82 , + .dir_offset = (u8 []){0x0 ,0x18 ,0x2c }, + .num_dir =3 , + .dato_offset = (u8 []){0x4 ,0x1c ,0x30 }, + .num_dato =3 , + .dati_offset = (u8 []){0x8 ,0x20 ,0x34 }, + .num_dati =3 , + .ie_offset = (u8 []){0xc ,0x24 ,0x38 },
drivers/gpio/gpio-rtd.c line 113
Quoted 10 lines
drivers/gpio/gpio-rtd.c new file +10
-0+ .num_ie = 3, + .dp_offset = (u8 []){ 0x10, 0x28, 0x3c }, + .num_dp = 3, + .gpa_offset = (u8 []){ 0x8, 0xe0, 0x90 }, + .num_gpa = 3, + .gpda_offset = (u8 []){ 0xc, 0xe4, 0x94 }, + .num_gpda = 3, + .deb_offset = (u8 []){0x44 ,0x48 ,0x4c ,0x50 ,0x54 ,0x58 ,0x5c , + 0x60, 0x64, 0x68, 0x6c }, + .num_deb = 11,
Use ARRAY_SIZE() from array_size.h for all num_* assignments.
Quoted 1 line
+};
...
Quoted 1 line
+static const struct
rtd_gpio_infortd1619_iso_gpio_info= {
Ditto.
Quoted 1 line
+};
...
Quoted 1 line
+static const struct
rtd_gpio_infortd1395_iso_gpio_info= {
Ditto.
drivers/gpio/gpio-rtd.c line 163
Quoted 3 lines
drivers/gpio/gpio-rtd.c new file +3
-0+}; + +static const struct rtd_gpio_info rtd1295_misc_gpio_info = {
Ditto.
drivers/gpio/gpio-rtd.c line 186
Quoted 3 lines
drivers/gpio/gpio-rtd.c new file +3
-0+}; + +static const struct rtd_gpio_info rtd1295_iso_gpio_info = {
Ditto.
Quoted 1 line
+};
...
drivers/gpio/gpio-rtd.c line 214
Quoted 6 lines
drivers/gpio/gpio-rtd.c new file +5
-0+static int rtd_gpio_dir_offset (struct rtd_gpio *data,unsigned int offset) +{ +int index = offset /32 ; +if (index > data->info->num_dir) +return -EINVAL ;
When this conditional can be true?
Same Q to the similar checks over the code.
Quoted 2 lines
(quoted diff) +2
-0+ return data->info->dir_offset[index]; +}
...
Quoted 11 lines
drivers/gpio/gpio-rtd.c new file +11
-0+if (data->info->type ==RTD1295_ISO_GPIO ) { + reg_offset =rtd_gpio_deb_offset (data,0 ); +if (reg_offset <0 ) +return reg_offset; + shift =0 ; + deb_val +=1 ; + write_en =BIT (shift +3 ); + }else if (data->info->type ==RTD1295_MISC_GPIO ) { + reg_offset =rtd_gpio_deb_offset (data,0 ); +if (reg_offset <0 ) +return reg_offset;
drivers/gpio/gpio-rtd.c line 346
Quoted 10 lines
drivers/gpio/gpio-rtd.c new file +10
-0+ shift = (offset >>4 ) *4 ; + deb_val +=1 ; + write_en =BIT (shift +3 ); + }else { + reg_offset =rtd_gpio_deb_offset (data, offset); +if (reg_offset <0 ) +return reg_offset; + shift = (offset %8 ) *4 ; + write_en =BIT (shift +3 ); + }
You should probably have kind of chip_info constant structure that goes via driver_data and will have a callback, so, here you will call one and get all three at once:
- register offset;
- shift
- updated debounce value
...
drivers/gpio/gpio-rtd.c line 385
Quoted 12 lines
drivers/gpio/gpio-rtd.c new file +11
-0+static int rtd_gpio_get_direction (struct gpio_chip *chip,unsigned int offset) +{ +struct rtd_gpio *data =gpiochip_get_data (chip); +unsigned long flags; +int reg_offset; +u32 val; + + reg_offset =rtd_gpio_dir_offset (data, offset); +if (reg_offset <0 ) +return reg_offset; +spin_lock_irqsave (&data->lock, flags);
So, is your IRQ chip going to work with CONFIG_PREEMT_RT?
drivers/gpio/gpio-rtd.c line 388
Quoted 3 lines
drivers/gpio/gpio-rtd.c new file +2
-0+ val =readl_relaxed (data->base + reg_offset); + val &=BIT (offset %32 );
Why this is is under lock?
Quoted 4 lines
drivers/gpio/gpio-rtd.c new file +4
-0+spin_unlock_irqrestore (&data->lock, flags); + +return val ?GPIO_LINE_DIRECTION_OUT :GPIO_LINE_DIRECTION_IN ; +}
...
drivers/gpio/gpio-rtd.c line 416
Quoted 10 lines
drivers/gpio/gpio-rtd.c new file +5
-0+static int rtd_gpio_set_direction (struct gpio_chip *chip,unsigned int offset,bool out) +{ +unsigned long flags; +spin_lock_irqsave (&data->lock, flags); +spin_unlock_irqrestore (&data->lock, flags);
Consider to utilise guard() / scoped_guard() from cleanup.h.
Quoted 1 line
+}
...
drivers/gpio/gpio-rtd.c line 428
Quoted 4 lines
drivers/gpio/gpio-rtd.c new file +3
-0+static int rtd_gpio_direction_output (struct gpio_chip *chip,unsigned int offset,int value) +{ + chip->set (chip, offset, value);
Why? Can't you call the function by its name directly?
Quoted 3 lines
drivers/gpio/gpio-rtd.c new file +3
-0+ +return rtd_gpio_set_direction (chip, offset, true); +}
...
Quoted 8 lines
drivers/gpio/gpio-rtd.c new file +8
-0+static int rtd_gpio_get (struct gpio_chip *chip,unsigned int offset) +{ +struct rtd_gpio *data =gpiochip_get_data (chip); +int dir_reg_offset, dat_reg_offset; +unsigned long flags; +u32 val; + + dir_reg_offset =rtd_gpio_dir_offset (data, offset);
drivers/gpio/gpio-rtd.c line 473
Quoted 10 lines
drivers/gpio/gpio-rtd.c new file +9
-0+if (dir_reg_offset <0 ) +return dir_reg_offset; + +spin_lock_irqsave (&data->lock, flags); + + val =readl_relaxed (data->base + dir_reg_offset); + val &=BIT (offset %32 ); + dat_reg_offset = val ? +rtd_gpio_dato_offset (data, offset) :rtd_gpio_dati_offset (data, offset);
Can't you have the direction be cached and already know which offset to use even before the lock?
drivers/gpio/gpio-rtd.c line 477
Quoted 4 lines
drivers/gpio/gpio-rtd.c new file +3
-0+ val =readl_relaxed (data->base + dat_reg_offset); + val >>= offset %32 ; + val &=0x1 ;
Why were these operations done under the lock?
Quoted 4 lines
drivers/gpio/gpio-rtd.c new file +4
-0+spin_unlock_irqrestore (&data->lock, flags); + +return val; +}
...
drivers/gpio/gpio-rtd.c line 507
Quoted 11 lines
drivers/gpio/gpio-rtd.c new file +10
-0+static void rtd_gpio_irq_handle (struct irq_desc *desc) +{ +int (*get_reg_offset)(struct rtd_gpio *gpio,unsigned int offset); +struct rtd_gpio *data =irq_desc_get_handler_data (desc); +struct irq_domain *domain = data->gpio_chip.irq.domain; +struct irq_chip *chip =irq_desc_get_chip (desc); +unsigned int irq =irq_desc_get_irq (desc); +int reg_offset; +u32 status; +int hwirq;
Why signed?
drivers/gpio/gpio-rtd.c line 516
Quoted 9 lines
drivers/gpio/gpio-rtd.c new file +8
-0+int i; +int j; + +chained_irq_enter (chip, desc); +if (irq == data->irqs[0 ]) + get_reg_offset = &rtd_gpio_gpa_offset; +else if (irq == data->irqs[1 ]) + get_reg_offset = &rtd_gpio_gpda_offset;
Can't it be done before entering into chained IRQ handler?
drivers/gpio/gpio-rtd.c line 518
Quoted 1 line
drivers/gpio/gpio-rtd.c new file +1
-0+for (i =0 ; i < data->info->num_gpios; i = i +31 ) {
31 ?! In any case i += 31 is simply shorter.
drivers/gpio/gpio-rtd.c line 528
Quoted 10 lines
drivers/gpio/gpio-rtd.c new file +9
-0+ reg_offset =get_reg_offset (data, i); +if (reg_offset <0 ) +return ; + + status =readl_relaxed (data->irq_base + reg_offset) >>1 ; +writel_relaxed (status <<1 , data->irq_base + reg_offset); +while (status) { + j =__ffs (status); + status &= ~BIT (j);
NIH for_each_set_bit()
drivers/gpio/gpio-rtd.c line 537
Quoted 10 lines
drivers/gpio/gpio-rtd.c new file +9
-0+ hwirq = i + j; +if (rtd_gpio_check_ie (data, hwirq)) { +int girq =irq_find_mapping (domain, hwirq); +u32 irq_type =irq_get_trigger_type (girq); + +if ((irq == data->irqs[1 ]) && ((irq_type &IRQ_TYPE_SENSE_MASK ) != +IRQ_TYPE_EDGE_BOTH )) +break ; +generic_handle_irq (girq);
Why you can't use generic_handle_domain_irq()?
Quoted 6 lines
drivers/gpio/gpio-rtd.c new file +6
-0+ } + } + } + +chained_irq_exit (chip, desc); +}
...
drivers/gpio/gpio-rtd.c line 606
Quoted 1 line
drivers/gpio/gpio-rtd.c new file +1
-0+u32 mask =BIT (d->hwirq %32 );
Use proper type and getter for hwirq. It's mentioned in the Documentation.
...
drivers/gpio/gpio-rtd.c line 652
Quoted 7 lines
drivers/gpio/gpio-rtd.c new file +6
-0+static const struct irq_chip rtd_gpio_irq_chip = { + .name ="rtd-gpio" , + .irq_enable = rtd_gpio_enable_irq, + .irq_disable = rtd_gpio_disable_irq, + .irq_set_type = rtd_gpio_irq_set_type, + .flags =IRQCHIP_IMMUTABLE ,
Is it? You seems missed something to fulfill the immutability requirements. Please consult with the Documentation, it's all written there.
Quoted 1 line
+};
...
drivers/gpio/gpio-rtd.c line 664
Quoted 11 lines
drivers/gpio/gpio-rtd.c new file +10
-0+static const struct of_device_id rtd_gpio_of_matches[] = { + { .compatible ="realtek,rtd1295-misc-gpio" , .data = &rtd1295_misc_gpio_info }, + { .compatible ="realtek,rtd1295-iso-gpio" , .data = &rtd1295_iso_gpio_info }, + { .compatible ="realtek,rtd1395-iso-gpio" , .data = &rtd1395_iso_gpio_info }, + { .compatible ="realtek,rtd1619-iso-gpio" , .data = &rtd1619_iso_gpio_info }, + { .compatible ="realtek,rtd1319-iso-gpio" , .data = &rtd_iso_gpio_info }, + { .compatible ="realtek,rtd1619b-iso-gpio" , .data = &rtd_iso_gpio_info }, + { .compatible ="realtek,rtd1319d-iso-gpio" , .data = &rtd_iso_gpio_info }, + { .compatible ="realtek,rtd1315e-iso-gpio" , .data = &rtd_iso_gpio_info }, + { },
No comma in the terminator entry.
Review
Quoted 2 lines
(quoted diff) +2
-0+}; +MODULE_DEVICE_TABLE(of, rtd_gpio_of_matches);
Move all these closer to its user (struct platform_device below).
...
drivers/gpio/gpio-rtd.c line 700
Quoted 1 line
drivers/gpio/gpio-rtd.c new file +1
-0+ data->gpio_chip.label =dev_name (&pdev->dev);
dev
...
drivers/gpio/gpio-rtd.c line 711
Quoted 1 line
drivers/gpio/gpio-rtd.c new file +1
-0+ data->gpio_chip.fwnode =dev_fwnode (&pdev->dev);
dev
But why setting parent device is not suffice?
...
drivers/gpio/gpio-rtd.c line 738
Quoted 6 lines
drivers/gpio/gpio-rtd.c new file +5
-0+static int rtd_gpio_init (void ) +{ +return platform_driver_register (&rtd_gpio_platform_driver); +} +
Unneeded blank line.
Quoted 1 line
+subsys_initcall(rtd_gpio_init);
Why? Anything that is not on standard initcall must be justified.
Signature · 2 lines
With Best Regards, Andy Shevchenko
RE: [PATCH v3 2/2] Add GPIO support for Realtek DHC(Digital Home Center) RTD SoCs.
Hi Andy,
Thank you for the review.
Quoted 8 lines · TY Chang
Quoted 4 lines
From: Tzuyi Chang <[email protected]>
This driver enables configuration of GPIO direction, GPIO values, GPIO debounce settings and handles GPIO interrupts.
Why gpio-regmap can't be used?
I will try to use gpio-remap in the next version.
Quoted 21 lines
...
Quoted 8 lines
drivers/gpio/gpio-rtd.c new file +7
-0+struct rtd_gpio_info { +u8 *dir_offset; +u8 num_dir; +u8 *dato_offset; +u8 num_dato; +u8 *dati_offset; +u8 num_dati;drivers/gpio/gpio-rtd.c line 78
Quoted 10 lines
drivers/gpio/gpio-rtd.c new file +10
-0+u8 *ie_offset; +u8 num_ie; +u8 *dp_offset; +u8 num_dp; +u8 *gpa_offset; +u8 num_gpa; +u8 *gpda_offset; +u8 num_gpda; +u8 *deb_offset; +u8 num_deb;
Quoted 3 lines
A lot of wasted space. Can you group pointers followed by u8 members? Note, use
paholetool to check the struct layout in C.
I will revise it in the next version.
Quoted 4 lines
Quoted 1 line
+};
...
Quoted 9 lines
drivers/gpio/gpio-rtd.c line 82
Quoted 2 lines
drivers/gpio/gpio-rtd.c new file +2
-0+struct rtd_gpio { +struct platform_device *pdev;Why
struct device *dev;is not suffice?
I will remove the pdev.
Quoted 9 lines
drivers/gpio/gpio-rtd.c line 86
Quoted 5 lines
drivers/gpio/gpio-rtd.c new file +4
-0+const struct rtd_gpio_info *info; +void __iomem *base; +void __iomem *irq_base; +struct gpio_chip gpio_chip;Make this to be the first member, it might reduce some code (due to pointer arithmetics).
I will move the gpio_chip to the first member.
Quoted 8 lines
drivers/gpio/gpio-rtd.c line 91
Quoted 5 lines
drivers/gpio/gpio-rtd.c new file +5
-0+unsigned int irqs[2 ]; +spinlock_t lock; +}; + +One blank line is enough.
I will remove it.
Quoted 25 lines
...
Quoted 12 lines
drivers/gpio/gpio-rtd.c new file +12
-0+static const struct rtd_gpio_info rtd_iso_gpio_info = { + .name ="rtd_iso_gpio" , + .type =RTD_ISO_GPIO , + .gpio_base =0 , + .num_gpios =82 , + .dir_offset = (u8 []){0x0 ,0x18 ,0x2c }, + .num_dir =3 , + .dato_offset = (u8 []){0x4 ,0x1c ,0x30 }, + .num_dato =3 , + .dati_offset = (u8 []){0x8 ,0x20 ,0x34 }, + .num_dati =3 , + .ie_offset = (u8 []){0xc ,0x24 ,0x38 },drivers/gpio/gpio-rtd.c line 113
Quoted 10 lines
drivers/gpio/gpio-rtd.c new file +10
-0+ .num_ie = 3, + .dp_offset = (u8 []){ 0x10, 0x28, 0x3c }, + .num_dp = 3, + .gpa_offset = (u8 []){ 0x8, 0xe0, 0x90 }, + .num_gpa = 3, + .gpda_offset = (u8 []){ 0xc, 0xe4, 0x94 }, + .num_gpda = 3, + .deb_offset = (u8 []){0x44 ,0x48 ,0x4c ,0x50 ,0x54 ,0x58 ,0x5c , + 0x60, 0x64, 0x68, 0x6c }, + .num_deb = 11,
Quoted 2 lines
Use
ARRAY_SIZE()fromarray_size.hfor all num_* assignments.
I will revise it.
Quoted 36 lines
Quoted 1 line
+};
...
Quoted 1 line
+static const struct
rtd_gpio_infortd1619_iso_gpio_info= {Ditto.
Quoted 1 line
+};
...
Quoted 1 line
+static const struct
rtd_gpio_infortd1395_iso_gpio_info= {Ditto.
drivers/gpio/gpio-rtd.c line 163
Quoted 3 lines
drivers/gpio/gpio-rtd.c new file +3
-0+}; + +static const struct rtd_gpio_info rtd1295_misc_gpio_info = {Ditto.
drivers/gpio/gpio-rtd.c line 186
Quoted 3 lines
drivers/gpio/gpio-rtd.c new file +3
-0+}; + +static const struct rtd_gpio_info rtd1295_iso_gpio_info = {Ditto.
Quoted 1 line
+};
...
Quoted 3 lines
(quoted diff) +3
-0+static int rtd_gpio_dir_offset(struct rtd_gpio *data, unsigned int +offset) { + int index = offset / 32;
Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (index > data->info->num_dir) + return -EINVAL;When this conditional can be true?
Same Q to the similar checks over the code.
It is only to check if the offset value is missing in the rtd_gpio_info. I'm uncertain about the necessity of these checks. If they are not necessary, I will remove the num_* members in the rtd_gpio_info structure along with these checks.
Quoted 26 lines
Quoted 1 line
+ return data->info->dir_offset[index]; }
...
Quoted 11 lines
drivers/gpio/gpio-rtd.c new file +11
-0+if (data->info->type ==RTD1295_ISO_GPIO ) { + reg_offset =rtd_gpio_deb_offset (data,0 ); +if (reg_offset <0 ) +return reg_offset; + shift =0 ; + deb_val +=1 ; + write_en =BIT (shift +3 ); + }else if (data->info->type ==RTD1295_MISC_GPIO ) { + reg_offset =rtd_gpio_deb_offset (data,0 ); +if (reg_offset <0 ) +return reg_offset;drivers/gpio/gpio-rtd.c line 346
Quoted 10 lines
drivers/gpio/gpio-rtd.c new file +10
-0+ shift = (offset >>4 ) *4 ; + deb_val +=1 ; + write_en =BIT (shift +3 ); + }else { + reg_offset =rtd_gpio_deb_offset (data, offset); +if (reg_offset <0 ) +return reg_offset; + shift = (offset %8 ) *4 ; + write_en =BIT (shift +3 ); + }
Quoted 7 lines
You should probably have kind of
chip_infoconstant structure that goes viadriver_dataand will have a callback, so, here you will call one and get all three at once:
- register offset;
- shift
- updated debounce value
I will add a callback in the struct rtd_gpio_info to get these values.
Quoted 13 lines
...
Quoted 10 lines
drivers/gpio/gpio-rtd.c new file +10
-0+static int rtd_gpio_get_direction (struct gpio_chip *chip,unsigned +int offset) { +struct rtd_gpio *data =gpiochip_get_data (chip); +unsigned long flags; +int reg_offset; +u32 val; + + reg_offset =rtd_gpio_dir_offset (data, offset); +if (reg_offset <0 ) +return reg_offset;
Quoted 4 lines
Quoted 1 line
+
spin_lock_irqsave(&data->lock, flags);So, is your IRQ chip going to work with
CONFIG_PREEMT_RT?
No, we do not enable CONFIG_PREEMT_RT. However, a custom driver might change the GPIO status in the ISR. I will utilize raw_spinlock instead and only lock the write operations.
Quoted 6 lines
drivers/gpio/gpio-rtd.c line 388
Quoted 3 lines
drivers/gpio/gpio-rtd.c new file +2
-0+ val =readl_relaxed (data->base + reg_offset); + val &=BIT (offset %32 );Why this is is under lock?
I'll move it outside of the lock.
Quoted 13 lines
drivers/gpio/gpio-rtd.c
Quoted 3 lines
drivers/gpio/gpio-rtd.c new file +3
-0+spin_unlock_irqrestore (&data->lock, flags); + + return val ? GPIO_LINE_DIRECTION_OUT :
GPIO_LINE_DIRECTION_IN; }...
Quoted 4 lines
(quoted diff) +3
-0+static int rtd_gpio_set_direction(struct gpio_chip *chip, unsigned +int offset, bool out) { + unsigned long flags;
Quoted 7 lines
drivers/gpio/gpio-rtd.c line 351
Quoted 4 lines
drivers/gpio/gpio-rtd.c new file +2
-0+spin_lock_irqsave (&data->lock, flags); +spin_unlock_irqrestore (&data->lock, flags);Consider to utilise
guard()/scoped_guard()fromcleanup.h.
I will try to use these macros.
Quoted 11 lines
Quoted 1 line
+}
...
Review
Quoted 4 lines
(quoted diff) +3
-0+static int rtd_gpio_direction_output(struct gpio_chip *chip, unsigned +int offset, int value) { + chip->set(chip, offset, value);Why? Can't you call the function by its name directly?
I will revise it.
Quoted 21 lines
Quoted 2 lines
(quoted diff) +2
-0+ + return rtd_gpio_set_direction(chip, offset, true); }...
Quoted 15 lines
drivers/gpio/gpio-rtd.c new file +15
-0+static int rtd_gpio_get (struct gpio_chip *chip,unsigned int offset) +{ +struct rtd_gpio *data =gpiochip_get_data (chip); +int dir_reg_offset, dat_reg_offset; +unsigned long flags; +u32 val; + + dir_reg_offset =rtd_gpio_dir_offset (data, offset); +if (dir_reg_offset <0 ) +return dir_reg_offset; + +spin_lock_irqsave (&data->lock, flags); + + val =readl_relaxed (data->base + dir_reg_offset); + val &=BIT (offset %32 );
Quoted 7 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ dat_reg_offset = val ? + rtd_gpio_dato_offset(data, offset) : + rtd_gpio_dati_offset(data, offset);Can't you have the direction be cached and already know which offset to use even before the lock?
I will move these codes outside of the lock.
Quoted 7 lines
drivers/gpio/gpio-rtd.c line 477
Quoted 4 lines
drivers/gpio/gpio-rtd.c new file +3
-0+ val =readl_relaxed (data->base + dat_reg_offset); + val >>= offset %32 ; + val &=0x1 ;Why were these operations done under the lock?
I will move these codes outside of the lock.
Quoted 16 lines
Quoted 4 lines
drivers/gpio/gpio-rtd.c new file +4
-0+spin_unlock_irqrestore (&data->lock, flags); + +return val; +}...
Quoted 8 lines
drivers/gpio/gpio-rtd.c new file +8
-0+static void rtd_gpio_irq_handle (struct irq_desc *desc) { +int (*get_reg_offset)(struct rtd_gpio *gpio,unsigned int offset); +struct rtd_gpio *data =irq_desc_get_handler_data (desc); +struct irq_domain *domain = data->gpio_chip.irq.domain; +struct irq_chip *chip =irq_desc_get_chip (desc); +unsigned int irq =irq_desc_get_irq (desc); +int reg_offset; +u32 status;
Quoted 4 lines
Quoted 1 line
+ int hwirq;
Why signed?
I will revised it to unsigned int.
Quoted 5 lines
Quoted 4 lines
drivers/gpio/gpio-rtd.c new file +4
-0+int i; +int j; + +chained_irq_enter (chip, desc);
Quoted 7 lines
drivers/gpio/gpio-rtd.c line 516
Quoted 4 lines
drivers/gpio/gpio-rtd.c new file +4
-0+if (irq == data->irqs[0 ]) + get_reg_offset = &rtd_gpio_gpa_offset; +else if (irq == data->irqs[1 ]) + get_reg_offset = &rtd_gpio_gpda_offset;Can't it be done before entering into chained IRQ handler?
I will revise it.
Quoted 4 lines
Quoted 1 line
+ for (i = 0; i <
data->info->num_gpios; i = i + 31) {31 ?! In any case i += 31 is simply shorter.
I will revise it.
Quoted 8 lines
Quoted 7 lines
drivers/gpio/gpio-rtd.c new file +7
-0+ reg_offset =get_reg_offset (data, i); +if (reg_offset <0 ) +return ; + + status =readl_relaxed (data->irq_base + reg_offset) >>1 ; +writel_relaxed (status <<1 , data->irq_base + + reg_offset);
Quoted 6 lines
drivers/gpio/gpio-rtd.c line 528
Quoted 3 lines
drivers/gpio/gpio-rtd.c new file +3
-0+while (status) { + j =__ffs (status); + status &= ~BIT (j);NIH
for_each_set_bit()
I will revise it.
Quoted 8 lines
drivers/gpio/gpio-rtd.c
Quoted 3 lines
drivers/gpio/gpio-rtd.c new file +3
-0+ hwirq = i + j; +if (rtd_gpio_check_ie (data, hwirq)) { + int girq = irq_find_mapping(domain,hwirq);
Review
Quoted 4 lines
(quoted diff) +4
-0+ u32 irq_type = + irq_get_trigger_type(girq); + + if ((irq == data->irqs[1]) && ((irq_type &
Quoted 8 lines
IRQ_TYPE_SENSE_MASK) !=drivers/gpio/gpio-rtd.c line 537
Quoted 4 lines
drivers/gpio/gpio-rtd.c new file +3
-0+ IRQ_TYPE_EDGE_BOTH)) +break ; +generic_handle_irq (girq);Why you can't use
generic_handle_domain_irq()?
I will revise it.
Quoted 9 lines
Quoted 6 lines
drivers/gpio/gpio-rtd.c new file +6
-0+ } + } + } + +chained_irq_exit (chip, desc); +}...
Quoted 4 lines
Quoted 1 line
+ u32 mask =
BIT(d->hwirq % 32);Use proper type and getter for hwirq. It's mentioned in the Documentation.
I will use irqd_to_hwirq(d) to get hwirq.
Quoted 8 lines
...
Quoted 5 lines
drivers/gpio/gpio-rtd.c new file +5
-0+static const struct irq_chip rtd_gpio_irq_chip = { + .name ="rtd-gpio" , + .irq_enable = rtd_gpio_enable_irq, + .irq_disable = rtd_gpio_disable_irq, + .irq_set_type = rtd_gpio_irq_set_type,
Quoted 5 lines
Quoted 1 line
+ .flags =
IRQCHIP_IMMUTABLE,Is it? You seems missed something to fulfill the immutability requirements. Please consult with the Documentation, it's all written there.
I think I missed to call the gpiochip_disable_irq/gpiochip_enable_irq in the .irq_disable/.irq_enable callback function to inform the gpiolib. I will revise it.
Quoted 17 lines
Quoted 1 line
+};
...
Review
Quoted 2 lines
(quoted diff) +2
-0+static const struct of_device_id rtd_gpio_of_matches[] = { + { .compatible = "realtek,rtd1295-misc-gpio", .data =
&rtd1295_misc_gpio_info},Quoted 1 line
+ { .compatible = "realtek,rtd1295-iso-gpio", .data =
&rtd1295_iso_gpio_info},Quoted 1 line
+ { .compatible = "realtek,rtd1395-iso-gpio", .data =
&rtd1395_iso_gpio_info},Quoted 1 line
+ { .compatible = "realtek,rtd1619-iso-gpio", .data =
&rtd1619_iso_gpio_info},Quoted 1 line
+ { .compatible = "realtek,rtd1319-iso-gpio", .data =
&rtd_iso_gpio_info},Quoted 1 line
+ { .compatible = "realtek,rtd1619b-iso-gpio", .data =
&rtd_iso_gpio_info},
Quoted 9 lines
Quoted 1 line
+ { .compatible = "realtek,rtd1319d-iso-gpio", .data =
&rtd_iso_gpio_info},Review
Quoted 4 lines
(quoted diff) +3
-0+ { .compatible = "realtek,rtd1315e-iso-gpio", .data = +&rtd_iso_gpio_info }, + { },No comma in the terminator entry.
I will revise it.
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+}; +MODULE_DEVICE_TABLE(of, rtd_gpio_of_matches);Move all these closer to its user (struct
platform_devicebelow).
I will revise it.
Quoted 6 lines
...
Quoted 1 line
+
data->gpio_chip.label=dev_name(&pdev->dev);dev
Quoted 8 lines
...
Quoted 1 line
+
data->gpio_chip.fwnode=dev_fwnode(&pdev->dev);dev
But why setting parent device is not suffice?
I will revise it to data->gpio_chip.parent = dev;.
Quoted 11 lines
...
drivers/gpio/gpio-rtd.c line 738
Quoted 6 lines
drivers/gpio/gpio-rtd.c new file +5
-0+static int rtd_gpio_init (void ) +{ +return platform_driver_register (&rtd_gpio_platform_driver); +} +Unneeded blank line.
I will remove it.
Quoted 4 lines
Quoted 1 line
+subsys_initcall(rtd_gpio_init);
Why? Anything that is not on standard initcall must be justified.
I will revise it to module_init.
Quoted 3 lines
--
With Best Regards,
Andy Shevchenko
Thanks,
Tzuyi Chang
Re: [PATCH v3 2/2] Add GPIO support for Realtek DHC(Digital Home Center) RTD SoCs.
Quoted 1 line · TY_Chang[張子逸]
Quoted 1 line · TY Chang
...
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
This driver enables configuration of GPIO direction, GPIO values, GPIO debounce settings and handles GPIO interrupts.
Why gpio-regmap can't be used?
I will try to use gpio-remap in the next version.
If it appears that it makes code uglier / complicated, please add the note somewhere to answer the above question.
...
Quoted 10 lines
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (index > data->info->num_dir) + return -EINVAL;When this conditional can be true?
Same Q to the similar checks over the code.It is only to check if the offset value is missing in the
rtd_gpio_info. I'm uncertain about the necessity of these checks. If they are not necessary, I will remove the num_* members in thertd_gpio_infostructure along with these checks.
My understanding that these checks are equivalent to the
if (offset >= ngpio)
one, which is performed by GPIO library, i.o.w. you will never get an offset outside the range of supported GPIO lines.
If my understanding is wrong, these checks need a comment why.
...
Quoted 8 lines
Quoted 6 lines
drivers/gpio/gpio-rtd.c line 516
Quoted 4 lines
drivers/gpio/gpio-rtd.c new file +4
-0+if (irq == data->irqs[0 ]) + get_reg_offset = &rtd_gpio_gpa_offset; +else if (irq == data->irqs[1 ]) + get_reg_offset = &rtd_gpio_gpda_offset;Can't it be done before entering into chained IRQ handler?
I will revise it.
Thinking about this more, perhaps you can register two IRQ chips with different functions, so this won't be part of the very critical interrupt handler (as we all want to reduce overhead in it as much as possible). Anyway, think about this and try different options, choose the one you think the best.
Signature · 2 lines
With Best Regards, Andy Shevchenko
RE: [PATCH v3 2/2] Add GPIO support for Realtek DHC(Digital Home Center) RTD SoCs.
Hi Andy,
Thank you for the suggestions.
Quoted 8 lines · TY_Chang[張子逸]
Quoted 1 line
Quoted 1 line · TY Chang
...
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
This driver enables configuration of GPIO direction, GPIO values, GPIO debounce settings and handles GPIO interrupts.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Why gpio-regmap can't be used?
I will try to use gpio-remap in the next version.
If it appears that it makes code uglier / complicated, please add the note somewhere to answer the above question.
I've traced the gpio-regmap.c file. It appears that for the driver to register gpio_irq_chip, it must create the irq_domain and add it into gpio_regmap_config. Additionally, the driver needs to register the irq handler by itself. However, this process can be managed by the gpiolib if the driver fills in the struct gpio_irq_chip inside struct gpio_chip before invoking gpiochip_add_data.
Moreover, apart from managing the registers for gpio direction and value, there are several other registers that require access(interrupt enable, debounce...). The GPIO IRQ status registers are located at different base addresses and are not contiguous. It may need to create an additional regmap and assign the access table to this regmap.
With the above consideration, I tend to keep using the existing method.
Quoted 13 lines
...
Quoted 10 lines
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (index > data->info->num_dir) + return -EINVAL;When this conditional can be true?
Same Q to the similar checks over the code.It is only to check if the offset value is missing in the
rtd_gpio_info. I'm uncertain about the necessity of these checks. If they are not necessary, I will remove the num_* members in thertd_gpio_infostructure along with these checks.
Quoted 9 lines
My understanding that these checks are equivalent to the
if (offset >= ngpio)
one, which is performed by GPIO library, i.o.w. you will never get an offset outside the range of supported GPIO lines.
If my understanding is wrong, these checks need a comment why.
I agree with you. I will remove these checks.
Quoted 9 lines
...
Quoted 7 lines
Quoted 6 lines
drivers/gpio/gpio-rtd.c line 516
Quoted 4 lines
drivers/gpio/gpio-rtd.c new file +4
-0+if (irq == data->irqs[0 ]) + get_reg_offset = &rtd_gpio_gpa_offset; +else if (irq == data->irqs[1 ]) + get_reg_offset = &rtd_gpio_gpda_offset;Can't it be done before entering into chained IRQ handler?
Quoted 8 lines
Quoted 1 line
I will revise it.
Thinking about this more, perhaps you can register two IRQ chips with different functions, so this won't be part of the very critical interrupt handler (as we all want to reduce overhead in it as much as possible).
Anyway, think about this and try different options, choose the one you think the best.
In the previous patch (v1), I had registered two IRQ chips with different handlers. However, these two handlers appeared quite similar and the gpio_irq_chip only allows the registration of a single handler. Therefore, I ended up registering one handler for both IRQs and included conditional checks within the handler to differentiate between the two.
Quoted 3 lines
--
With Best Regards,
Andy Shevchenko
Thanks,
Tzuyi Chang
Re: [PATCH v3 2/2] Add GPIO support for Realtek DHC(Digital Home Center) RTD SoCs.
+Cc: Michael (GPIO regmap maintainer)
Quoted 2 lines · TY_Chang[張子逸]
Quoted 2 lines · TY_Chang[張子逸]
Quoted 1 line
Quoted 1 line · TY Chang
...
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
This driver enables configuration of GPIO direction, GPIO values, GPIO debounce settings and handles GPIO interrupts.
Why gpio-regmap can't be used?
I will try to use gpio-remap in the next version.
Quoted 8 lines
Quoted 2 lines
If it appears that it makes code uglier / complicated, please add the note somewhere to answer the above question.
I've traced the
gpio-regmap.cfile. It appears that for the driver to registergpio_irq_chip, it must create theirq_domainand add it intogpio_regmap_config. Additionally, the driver needs to register the irq handler by itself. However, this process can be managed by the gpiolib if the driver fills in the structgpio_irq_chipinside structgpio_chipbefore invokinggpiochip_add_data.
Hmm... I thought this is solvable issue.
Michael, is there a limitation in GPIO regmap that this driver can't be converted?
Quoted 5 lines
Moreover, apart from managing the registers for gpio direction and value, there are several other registers that require
access(interrupt enable, debounce...). The GPIO IRQ status registers are located at different base addresses and are not contiguous. It may need to create an additional regmap and assign the access table to this regmap.
AFAIK this is not a problem as you can provide your own xlate function that will take care about register mapping.
Quoted 1 line
With the above consideration, I tend to keep using the existing method.
I would like to hear from Michael if it's indeed a big obstacle.
...
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
drivers/gpio/gpio-rtd.c line 516
Quoted 4 lines
drivers/gpio/gpio-rtd.c new file +4
-0+if (irq == data->irqs[0 ]) + get_reg_offset = &rtd_gpio_gpa_offset; +else if (irq == data->irqs[1 ]) + get_reg_offset = &rtd_gpio_gpda_offset;Can't it be done before entering into chained IRQ handler?
Quoted 7 lines
Quoted 1 line
I will revise it.
Thinking about this more, perhaps you can register two IRQ chips with different functions, so this won't be part of the very critical interrupt handler (as we all want to reduce overhead in it as much as possible). Anyway, think about this and try different options, choose the one you think the best.
Quoted 5 lines
In the previous patch (v1), I had registered two IRQ chips with different handlers. However, these two handlers appeared quite similar and the
gpio_irq_chiponly allows the registration of a single handler. Therefore, I ended up registering one handler for both IRQs and included conditional checks within the handler to differentiate between the two.
What is the performance impact that you have that condition in the interrupt handler?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 2/2] Add GPIO support for Realtek DHC(Digital Home Center) RTD SoCs.
Hi,
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
This driver enables configuration of GPIO direction, GPIO values, GPIO debounce settings and handles GPIO interrupts.
Why gpio-regmap can't be used?
I will try to use gpio-remap in the next version.
If it appears that it makes code uglier / complicated, please add the note somewhere to answer the above question.
Quoted 8 lines
Quoted 5 lines
I've traced the
gpio-regmap.cfile. It appears that for the driver to registergpio_irq_chip, it must create theirq_domainand add it intogpio_regmap_config. Additionally, the driver needs to register the irq handler by itself. However, this process can be managed by the gpiolib if the driver fills in the structgpio_irq_chipinside structgpio_chipbefore invokinggpiochip_add_data.Hmm... I thought this is solvable issue.
Michael, is there a limitation in GPIO regmap that this driver can't be converted?
gpio-regmap is designed that regmap-irq (drivers/base/regmap/irq.c) can be used. So, if regmap-irq fit this driver, then it can be used together with gpio-regmap.
From a quick glance at the patch, it looks like the gpio portion might fit gpio-regmap.
Quoted 8 lines
Quoted 5 lines
Moreover, apart from managing the registers for gpio direction and value, there are several other registers that require
access(interrupt enable, debounce...). The GPIO IRQ status registers are located at different base addresses and are not contiguous. It may need to create an additional regmap and assign the access table to this regmap.AFAIK this is not a problem as you can provide your own xlate function that will take care about register mapping.
Just for the gpio part. IIRC regmap has it own translation (regmap fields).
Quoted 3 lines
Quoted 1 line
With the above consideration, I tend to keep using the existing method.
I would like to hear from Michael if it's indeed a big obstacle.
So, regarding the irq portion, again, it must fit the regmap-irq. For the additional requirement to set the debounce, you can add a .set_config to gpio_regmap_config and supply your own set_config callback. See also [1].
-michael
Re: [PATCH v3 2/2] Add GPIO support for Realtek DHC(Digital Home Center) RTD SoCs.
Quoted 47 lines · Michael Walle
Quoted 20 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
This driver enables configuration of GPIO direction, GPIO values, GPIO debounce settings and handles GPIO interrupts.
Why gpio-regmap can't be used?
I will try to use gpio-remap in the next version.
If it appears that it makes code uglier / complicated, please add the note somewhere to answer the above question.
Quoted 9 lines
I've traced the
gpio-regmap.cfile. It appears that for the driver to registergpio_irq_chip, it must create theirq_domainand add it intogpio_regmap_config.
Additionally, the driver needs to register the irq handler by itself. However, this process can be managed by the gpiolib if the driver fills in the structgpio_irq_chipinside structgpio_chipbefore invokinggpiochip_add_data.Quoted 3 lines
Hmm... I thought this is solvable issue.
Michael, is there a limitation in GPIO regmap that this driver can't be converted?gpio-regmap is designed that regmap-irq (
drivers/base/regmap/irq.c) can be used. So, if regmap-irq fit this driver, then it can be used together with gpio-regmap.From a quick glance at the patch, it looks like the gpio portion might fit gpio-regmap.
Quoted 10 lines
Quoted 9 lines
Moreover, apart from managing the registers for gpio direction and value, there
are several other registers that requireaccess(interrupt enable, debounce...).
The GPIO IRQ status registers are located at different base addresses and are
not contiguous. It may need to create an additional regmap and assign the access
table to this regmap.Quoted 3 lines
AFAIK this is not a problem as you can provide your own xlate function that
will take care about register mapping.Just for the gpio part. IIRC regmap has it own translation (regmap fields).
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
With the above consideration, I tend to keep using the existing method.
I would like to hear from Michael if it's indeed a big obstacle.
So, regarding the irq portion, again, it must fit the regmap-irq. For the additional requirement to set the debounce, you can add a .set_config to
gpio_regmap_configand supply your ownset_configcallback. See also [1].
Thank you, Michael, for the prompt answer. It's insightful to me, I will try to remember these aspects for the future reviews.
Quoted 2 lines
Signature · 2 lines
With Best Regards, Andy Shevchenko
RE: [PATCH v3 2/2] Add GPIO support for Realtek DHC(Digital Home Center) RTD SoCs.
Hi Andy,
Quoted 51 lines · Michael Walle
Quoted 42 lines
Quoted 19 lines
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
This driver enables configuration of GPIO direction, GPIO values, GPIO debounce settings and handles GPIO interrupts.
Why gpio-regmap can't be used?
I will try to use gpio-remap in the next version.
If it appears that it makes code uglier / complicated, please add the note somewhere to answer the above question.
Quoted 7 lines
I've traced the
gpio-regmap.cfile. It appears that for the driver to registergpio_irq_chip, it must create theirq_domainand add it intogpio_regmap_config.
Additionally, the driver needs to register the irq handler by itself. However, this process can be managed by the gpiolib if the driver fills in the structgpio_irq_chipinside structgpio_chipbefore invokinggpiochip_add_data.Quoted 3 lines
Hmm... I thought this is solvable issue.
Michael, is there a limitation in GPIO regmap that this driver can't be converted?gpio-regmap is designed that regmap-irq (
drivers/base/regmap/irq.c) can be used. So, if regmap-irq fit this driver, then it can be used together with gpio-regmap.From a quick glance at the patch, it looks like the gpio portion might fit gpio-regmap.
Quoted 9 lines
Quoted 6 lines
Moreover, apart from managing the registers for gpio direction and value, there are several other registers that require
access(interrupt enable, debounce...).
The GPIO IRQ status registers are located at different base addresses and are not contiguous. It may need to create an additional regmap and assign the access table to this regmap.AFAIK this is not a problem as you can provide your own xlate function that will take care about register mapping.
Just for the gpio part. IIRC regmap has it own translation (regmap fields).
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
With the above consideration, I tend to keep using the existing method.
I would like to hear from Michael if it's indeed a big obstacle.
So, regarding the irq portion, again, it must fit the regmap-irq. For the additional requirement to set the debounce, you can add a .set_config to
gpio_regmap_configand supply your ownset_configcallback.
Quoted 10 lines
See also [1].
Thank you, Michael, for the prompt answer. It's insightful to me, I will try to remember these aspects for the future reviews.
Quoted 2 lines
[1]
https://lore.kernel.org/linux-gpio/d4a6a640c373b6d939e147691efa596c@wa
Quoted 1 line
lle.cc/
I have looked into regmap-irq, it appears that using the default irq thread_fn(regmap_irq_thread) is required. However, due to hardware limitation, we need to inspect the IRQ_TYPE to determine whether to manage the irq within the irq handler. I think our irq portion does not perfectly fit the regmap-irq. Moreover, it seems that the gpio-regmap.c file needs to be modified if the GPIO driver requires debounce settings. I think the gpio-regmap may not be appropriate for our driver. Do you have any suggestions?
Thanks,
Tzuyi Chang
Re: [PATCH v3 2/2] Add GPIO support for Realtek DHC(Digital Home Center) RTD SoCs.
Hi,
Quoted 7 lines
I have looked into regmap-irq, it appears that using the default irq
thread_fn(regmap_irq_thread)is required. However, due to hardware limitation, we need to inspect theIRQ_TYPEto determine whether to manage the irq within the irq handler. I think our irq portion does not perfectly fit the regmap-irq. Moreover, it seems that thegpio-regmap.cfile needs to be modified if the GPIO driver requires debounce settings. I think the gpio-regmap may not be appropriate for our driver. Do you have any suggestions?
Can't say anything regarding the interrupt handling but adding literally one line to gpio-regmap shouldn't be a reason not to use it.
-michael
A message that is not in the archive (sent off-list or not yet received): [email protected]
RE: [PATCH v3 2/2] Add GPIO support for Realtek DHC(Digital Home Center) RTD SoCs.
Hi Michael,
Quoted 12 lines
Hi,
Quoted 9 lines
I have looked into regmap-irq, it appears that using the default irq
thread_fn(regmap_irq_thread)is required. However, due to hardware limitation, we need to inspect theIRQ_TYPEto determine whether to manage the irq within the irq handler. I think our irq portion does not perfectly fit the regmap-irq.
Moreover, it seems that thegpio-regmap.cfile needs to be modified if the GPIO driver requires debounce settings. I think the gpio-regmap may not be appropriate for our driver.
Do you have any suggestions?
Quoted 3 lines
Can't say anything regarding the interrupt handling but adding literally one line to gpio-regmap shouldn't be a reason not to use it.
I agree that this should not be the reason. Sorry about that. However, the interrupt handler issue may still be the limitation for our platform.
Thanks,
Tzuyi Chang
RE: [PATCH v3 2/2] Add GPIO support for Realtek DHC(Digital Home Center) RTD SoCs.
In reply to Andy ShevchenkoHi Andy,
Quoted 21 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
drivers/gpio/gpio-rtd.c new file +4
-0+if (irq == data->irqs[0 ]) + get_reg_offset = &rtd_gpio_gpa_offset; +else if (irq == data->irqs[1 ]) + get_reg_offset = &rtd_gpio_gpda_offset;Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Can't it be done before entering into chained IRQ handler?
I will revise it.
Thinking about this more, perhaps you can register two IRQ chips with different functions, so this won't be part of the very critical interrupt handler (as we all want to reduce overhead in it as much as
possible).
Quoted 8 lines
Quoted 2 lines
Anyway, think about this and try different options, choose the one you think the best.
In the previous patch (v1), I had registered two IRQ chips with different handlers. However, these two handlers appeared quite similar and the
gpio_irq_chiponly allows the registration of a single handler. Therefore, I ended up registering one handler for both IRQs and included conditional checks within the handler to differentiate between
Quoted 5 lines
the two.
What is the performance impact that you have that condition in the interrupt handler?
I believe the performance impact is minimal since this conditional check is a simple operation aimed at retrieving the corresponding offset of the interrupt status registers.
Or is there something I might not have considered?
Thanks,
Tzuyi Chang