* [PATCH RFC 0/2] pinctrl: Add support gpiod_to_irq
@ 2026-06-11 7:54 Xianwei Zhao via B4 Relay
2026-06-11 7:54 ` [PATCH RFC 1/2] dt-bindings: pinctl: amlogic,pinctrl-a4: Add gpio irq property Xianwei Zhao via B4 Relay
2026-06-11 7:54 ` [PATCH RFC 2/2] pinctrl: meson: amlogic-a4: support gpiod_to_irq Xianwei Zhao via B4 Relay
0 siblings, 2 replies; 5+ messages in thread
From: Xianwei Zhao via B4 Relay @ 2026-06-11 7:54 UTC (permalink / raw)
To: Linus Walleij, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Neil Armstrong, Kevin Hilman, Jerome Brunet, Martin Blumenstingl
Cc: linux-amlogic, linux-gpio, devicetree, linux-kernel,
linux-arm-kernel, Xianwei Zhao
Some users need to obtain an IRQ directly from a GPIO descriptor through gpiod_to_irq().
Add the required DT binding and implementation to support this use case.
Since this introduces a new DT property, the property is kept optional to
maintain compatibility with existing SoCs and DTS files.
Signed-off-by: Xianwei Zhao <xianwei.zhao@amlogic.com>
---
Xianwei Zhao (2):
dt-bindings: pinctl: amlogic,pinctrl-a4: Add gpio irq property
pinctrl: meson: amlogic-a4: support gpiod_to_irq
.../bindings/pinctrl/amlogic,pinctrl-a4.yaml | 5 ++
drivers/pinctrl/meson/pinctrl-amlogic-a4.c | 54 ++++++++++++++++++++++
2 files changed, 59 insertions(+)
---
base-commit: 4ca496f6285e16d91751e5c84c6010e03285528c
change-id: 20260520-gpio-to-irq-be4797d2a23f
Best regards,
--
Xianwei Zhao <xianwei.zhao@amlogic.com>
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH RFC 1/2] dt-bindings: pinctl: amlogic,pinctrl-a4: Add gpio irq property 2026-06-11 7:54 [PATCH RFC 0/2] pinctrl: Add support gpiod_to_irq Xianwei Zhao via B4 Relay @ 2026-06-11 7:54 ` Xianwei Zhao via B4 Relay 2026-06-11 8:06 ` sashiko-bot 2026-06-11 7:54 ` [PATCH RFC 2/2] pinctrl: meson: amlogic-a4: support gpiod_to_irq Xianwei Zhao via B4 Relay 1 sibling, 1 reply; 5+ messages in thread From: Xianwei Zhao via B4 Relay @ 2026-06-11 7:54 UTC (permalink / raw) To: Linus Walleij, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Neil Armstrong, Kevin Hilman, Jerome Brunet, Martin Blumenstingl Cc: linux-amlogic, linux-gpio, devicetree, linux-kernel, linux-arm-kernel, Xianwei Zhao From: Xianwei Zhao <xianwei.zhao@amlogic.com> Add the hw-irq property for each GPIO bank and enable interrupt-parent for pinctrl so that gpiod_to_irq() can translate GPIO lines to IRQs. Signed-off-by: Xianwei Zhao <xianwei.zhao@amlogic.com> --- Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml b/Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml index b69db1b95345..65ec9121300e 100644 --- a/Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml +++ b/Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml @@ -37,6 +37,8 @@ properties: ranges: true + interrupt-parent: true + patternProperties: "^gpio@[0-9a-f]+$": type: object @@ -65,6 +67,9 @@ patternProperties: gpio-ranges: maxItems: 1 + hw-irq: + $ref: /schemas/types.yaml#/definitions/uint32 + required: - reg - reg-names -- 2.52.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH RFC 1/2] dt-bindings: pinctl: amlogic,pinctrl-a4: Add gpio irq property 2026-06-11 7:54 ` [PATCH RFC 1/2] dt-bindings: pinctl: amlogic,pinctrl-a4: Add gpio irq property Xianwei Zhao via B4 Relay @ 2026-06-11 8:06 ` sashiko-bot 0 siblings, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-06-11 8:06 UTC (permalink / raw) To: Xianwei Zhao via B4 Relay Cc: robh, conor+dt, linux-amlogic, neil.armstrong, devicetree Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] The newly added `hw-irq` property is not marked as required for the GPIO banks, and the example is not updated. - [Medium] The custom device tree property `hw-irq` lacks a vendor prefix. - [Low] The newly added `hw-irq` property lacks a description field. -- commit 779e29b8c4c1e37224d568880fcfcc77220c1d72 Author: Xianwei Zhao <xianwei.zhao@amlogic.com> dt-bindings: pinctl: amlogic,pinctrl-a4: Add gpio irq property Add the hw-irq property for each GPIO bank and enable interrupt-parent for pinctrl so that gpiod_to_irq() can translate GPIO lines to IRQs. > diff --git a/Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml b/Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml > --- a/Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml > +++ b/Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml [ ... ] > @@ -65,6 +67,9 @@ patternProperties: > gpio-ranges: > maxItems: 1 > > + hw-irq: > + $ref: /schemas/types.yaml#/definitions/uint32 [Severity: Medium] Should this custom property have a vendor prefix to prevent namespace collisions, such as amlogic,hw-irq? [Severity: Low] Would it be helpful to include a description field here to document the purpose and semantic usage of this new property? > + > required: > - reg > - reg-names [Severity: Medium] The commit message indicates this property is added for each GPIO bank. Should hw-irq be included in this required list under the patternProperties:^gpio@[0-9a-f]+$ node to ensure incomplete configurations fail schema validation? Additionally, the example at the bottom of the file doesn't seem to include this new property: examples: ... gpio@4240 { reg = <0 0x4240 0 0x40>, <0 0x4000 0 0x8>; reg-names = "gpio", "mux"; gpio-controller; #gpio-cells = <2>; gpio-ranges = <&periphs_pinctrl 0 8 10>; }; Does the example section need to be updated to demonstrate the usage of the newly added property? -- Sashiko AI review · https://sashiko.dev/#/patchset/20260611-gpio-to-irq-v1-0-12201716f23f@amlogic.com?part=1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH RFC 2/2] pinctrl: meson: amlogic-a4: support gpiod_to_irq 2026-06-11 7:54 [PATCH RFC 0/2] pinctrl: Add support gpiod_to_irq Xianwei Zhao via B4 Relay 2026-06-11 7:54 ` [PATCH RFC 1/2] dt-bindings: pinctl: amlogic,pinctrl-a4: Add gpio irq property Xianwei Zhao via B4 Relay @ 2026-06-11 7:54 ` Xianwei Zhao via B4 Relay 2026-06-11 8:02 ` sashiko-bot 1 sibling, 1 reply; 5+ messages in thread From: Xianwei Zhao via B4 Relay @ 2026-06-11 7:54 UTC (permalink / raw) To: Linus Walleij, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Neil Armstrong, Kevin Hilman, Jerome Brunet, Martin Blumenstingl Cc: linux-amlogic, linux-gpio, devicetree, linux-kernel, linux-arm-kernel, Xianwei Zhao From: Xianwei Zhao <xianwei.zhao@amlogic.com> Add the to_irq() callback implementation so that gpiod_to_irq() can map GPIO lines to IRQs correctly. Signed-off-by: Xianwei Zhao <xianwei.zhao@amlogic.com> --- drivers/pinctrl/meson/pinctrl-amlogic-a4.c | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/pinctrl/meson/pinctrl-amlogic-a4.c b/drivers/pinctrl/meson/pinctrl-amlogic-a4.c index 5ae0c19d007d..663681887f35 100644 --- a/drivers/pinctrl/meson/pinctrl-amlogic-a4.c +++ b/drivers/pinctrl/meson/pinctrl-amlogic-a4.c @@ -10,6 +10,7 @@ #include <linux/io.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/of_irq.h> #include <linux/of_address.h> #include <linux/platform_device.h> #include <linux/regmap.h> @@ -97,6 +98,8 @@ struct aml_gpio_bank { struct regmap *reg_gpio; struct regmap *reg_ds; const struct multi_mux *p_mux; + struct device_node *of_irq; + u32 irq_start; }; struct aml_pinctrl { @@ -836,6 +839,32 @@ static int aml_pctl_parse_functions(struct device_node *np, return 0; } +static struct device_node *aml_get_of_irq(struct device_node *np) +{ + struct device_node *of_irq; + + of_irq = of_irq_find_parent(np); + if (of_irq && of_device_is_compatible(of_irq, "amlogic,meson-gpio-intc")) { + of_node_put(of_irq); + return of_irq; + } + + if (of_irq) + of_node_put(of_irq); + + return NULL; +} + +static u32 aml_bank_irq(struct device_node *np) +{ + u32 hw_irq; + + if (of_property_read_u32(np, "hw-irq", &hw_irq)) + return U32_MAX; + + return hw_irq; +} + static u32 aml_bank_pins(struct device_node *np) { struct of_phandle_args of_args; @@ -1003,6 +1032,27 @@ static int aml_gpio_get(struct gpio_chip *chip, unsigned int gpio) return !!(val & BIT(bit)); } +static int aml_gpio_to_irq(struct gpio_chip *chip, unsigned int gpio) +{ + struct aml_gpio_bank *bank = gpiochip_get_data(chip); + struct irq_fwspec fwspec; + int hwirq; + + if (bank->irq_start == U32_MAX) + return -EINVAL; + if (!bank->of_irq) + return -EINVAL; + + hwirq = gpio + bank->irq_start; + + fwspec.fwnode = of_fwnode_handle(bank->of_irq); + fwspec.param_count = 2; + fwspec.param[0] = hwirq; + fwspec.param[1] = IRQ_TYPE_NONE; + + return irq_create_fwspec_mapping(&fwspec); +} + static const struct gpio_chip aml_gpio_template = { .request = gpiochip_generic_request, .free = gpiochip_generic_free, @@ -1012,6 +1062,7 @@ static const struct gpio_chip aml_gpio_template = { .direction_input = aml_gpio_direction_input, .direction_output = aml_gpio_direction_output, .get_direction = aml_gpio_get_direction, + .to_irq = aml_gpio_to_irq, .can_sleep = true, }; @@ -1079,6 +1130,7 @@ static int aml_gpiolib_register_bank(struct aml_pinctrl *info, bank->reg_ds = bank->reg_gpio; } + bank->irq_start = aml_bank_irq(np); bank->gpio_chip = aml_gpio_template; bank->gpio_chip.base = -1; bank->gpio_chip.ngpio = aml_bank_pins(np); @@ -1154,6 +1206,8 @@ static int aml_pctl_probe_dt(struct platform_device *pdev, pdesc->name = pin_names[j]; pdesc++; } + + info->banks[bank].of_irq = aml_get_of_irq(np); bank++; } else { ret = aml_pctl_parse_functions(child, info, -- 2.52.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH RFC 2/2] pinctrl: meson: amlogic-a4: support gpiod_to_irq 2026-06-11 7:54 ` [PATCH RFC 2/2] pinctrl: meson: amlogic-a4: support gpiod_to_irq Xianwei Zhao via B4 Relay @ 2026-06-11 8:02 ` sashiko-bot 0 siblings, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-06-11 8:02 UTC (permalink / raw) To: Xianwei Zhao via B4 Relay Cc: linux-amlogic, conor+dt, robh, devicetree, neil.armstrong Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Premature `of_node_put()` in `aml_get_of_irq()` creates a dangling pointer, leading to a Use-After-Free. -- commit 682e8ff8b51a310ddf41177d04828ab2fd8a5670 Author: Xianwei Zhao <xianwei.zhao@amlogic.com> pinctrl: meson: amlogic-a4: support gpiod_to_irq This patch adds the to_irq() callback implementation so that gpiod_to_irq() can map GPIO lines to IRQs correctly. > diff --git a/drivers/pinctrl/meson/pinctrl-amlogic-a4.c b/drivers/pinctrl/meson/pinctrl-amlogic-a4.c > index 5ae0c19d007d7..663681887f35c 100644 > --- a/drivers/pinctrl/meson/pinctrl-amlogic-a4.c > +++ b/drivers/pinctrl/meson/pinctrl-amlogic-a4.c [ ... ] > @@ -836,6 +839,32 @@ static int aml_pctl_parse_functions(struct device_node *np, > return 0; > } > > +static struct device_node *aml_get_of_irq(struct device_node *np) > +{ > + struct device_node *of_irq; > + > + of_irq = of_irq_find_parent(np); > + if (of_irq && of_device_is_compatible(of_irq, "amlogic,meson-gpio-intc")) { > + of_node_put(of_irq); > + return of_irq; [Severity: High] Does this premature of_node_put() call create a use-after-free risk? of_irq_find_parent() returns a device node with an incremented reference count. By calling of_node_put() before returning the pointer, the reference is dropped while the pointer is still passed back and cached in bank->of_irq. Later, aml_gpio_to_irq() dereferences this pointer: fwspec.fwnode = of_fwnode_handle(bank->of_irq); If the device node is dynamically freed (for example, during Device Tree overlay removal) between caching and use, this would lead to a use-after-free. Should we retain the reference here until driver teardown instead? > + } > + > + if (of_irq) > + of_node_put(of_irq); > + > + return NULL; > +} -- Sashiko AI review · https://sashiko.dev/#/patchset/20260611-gpio-to-irq-v1-0-12201716f23f@amlogic.com?part=2 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-06-11 8:06 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-06-11 7:54 [PATCH RFC 0/2] pinctrl: Add support gpiod_to_irq Xianwei Zhao via B4 Relay 2026-06-11 7:54 ` [PATCH RFC 1/2] dt-bindings: pinctl: amlogic,pinctrl-a4: Add gpio irq property Xianwei Zhao via B4 Relay 2026-06-11 8:06 ` sashiko-bot 2026-06-11 7:54 ` [PATCH RFC 2/2] pinctrl: meson: amlogic-a4: support gpiod_to_irq Xianwei Zhao via B4 Relay 2026-06-11 8:02 ` sashiko-bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox