gpio: add Ambarella CV75 PL061 support
Subsystems (6)
v15 cover gpio: add Ambarella CV75 PL061 support
Please take this series through the GPIO tree. The quirk, the PL061 conversion and the Ambarella layout belong together.
These patches convert the ARM PL061 data path to regmap, then add the CV75 layout. They also request ACPI GPIO events for an external irq domain, and remove the gpiochip before tearing down its irqchip.
The data path uses gpio-regmap with two layouts, ARM PrimeCell and Ambarella. ARM PL061 sets GPIO_REGMAP_QUIRK_SET_AFTER_DIR. IRQ stays a custom PL061 irqchip, attached through gpio-regmap. regmap-irq is not used.
Tested with lockdep enabled on the CV75 EVK. The board boots. gpio-hammer toggles gpiochip0 line 26 ten times, and gpio-event-mon on line 27 records alternating rising and falling edges. unbind and bind work; the chip re-registers and both tools work again after the rebind. Holding line 27 as an edge IRQ and unbinding, without blocking in read, no longer warns from remove_proc_entry().
The registration error-path leak fix is already applied in the GPIO tree as 80415a6ff295 ("gpio: regmap: free the irqchip if adding the irq domain fails"). Apply this series on top of that commit.
Changes in v15:
- gpio: pl061: call gpiolib irq helpers on the immutable chip. (Sashiko)
- lib/string_choices: collect Andy's Reviewed-by on the helper. (Andy)
- gpio: pl061: collect Andy's Reviewed-by on the string_choices use. (Andy)
- Link to v14: https://patch.msgid.link/[email protected]
Changes in v14:
- lib/string_choices: add str_rising_falling() and use it in pl061. (Andy)
- gpio: regmap: keep removing the gpiochip before the irqchip. (Sashiko)
- gpio: regmap: rename the SET_AFTER_DIR subject from gpiolib:. (Michael)
- gpiolib: collect Mika's Acked-by and move linux-acpi below ---. (Mika)
- gpio: pl061: collect Andy's Reviewed-by on the IRQ logging patch. (Andy)
- gpio: pl061: collect Linus's Reviewed-by on the parent local. (Linus)
- Link to v13: https://patch.msgid.link/[email protected]
To: Bartosz Golaszewski <[email protected]>
To: [email protected]
Cc: Linus Walleij <[email protected]>
Cc: Michael Walle <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Conor Dooley <[email protected]>
Cc: Mika Westerberg <[email protected]>
Cc: [email protected]
Cc: Long Zhao <[email protected]>
Cc: Long Zhao <[email protected]>
Cc: [email protected]
---
Long Zhao (14):
dt-bindings: gpio: pl061: add Ambarella CV75 variant
gpio: regmap: add GPIO_REGMAP_QUIRK_SET_AFTER_DIR
gpio: regmap: remove gpiochip before tearing down irqchip
gpio: pl061: drop redundant pending check in the IRQ handler
gpio: pl061: convert register access to regmap
gpio: pl061: use IRQ_TYPE_LEVEL_MASK and IRQ_TYPE_EDGE_BOTH
gpio: pl061: use cleanup helpers for locks
gpio: pl061: keep the parent device in a local
gpiolib: request ACPI GPIO events for external IRQ domains
gpio: pl061: switch data path to gpio-regmap
gpio: pl061: add Ambarella register-layout variant
gpio: pl061: tidy up IRQ trigger logging lib/string_choices: add str_rising_falling()
gpio: pl061: use string_choices helpers for IRQ trigger logging
.../devicetree/bindings/gpio/pl061-gpio.yaml | 25 +- drivers/gpio/Kconfig | 2 + drivers/gpio/gpio-pl061.c | 592 ++++++++++++++------- drivers/gpio/gpio-regmap.c | 24 +- drivers/gpio/gpiolib.c | 9 +- include/linux/amba/bus.h | 1 + include/linux/gpio/regmap.h | 14 + include/linux/string_choices.h | 6 + 8 files changed, 475 insertions(+), 198 deletions(-)
---
base-commit: 34cf6dafc47441dfb6b356a095b89c3585a93714
change-id: 20261007-cv75-gpio-333d7c1dfe11
Best regards,
Signature · 1 line
Long Zhao <[email protected]>
PATCH v15 1/14 dt-bindings: gpio: pl061: add Ambarella CV75 variant
The CV75 GPIO is a modified PL061. The basic registers have the same names and roles (DAT/DIR/IS/IBE/IEV/IE/MIS/IC). Each bank is 32-bit and 32 lines and adds MASK and ENABLE, so it is not register-compatible with the ARM PL061 and arm,pl061 must not be used as a fallback.
The AMBA core matches the PL061 driver by PrimeCell ID, not by the DT compatible string. These blocks do not implement the standard PL061 ID (0x00041061) in the ID registers, so arm,primecell-periphid is required and is fixed to 0x000e8061; the driver uses that ID to select the Ambarella layout. gpio-ranges is required because each bank is a slice of the SoC pinctrl pin space.
--- .../devicetree/bindings/gpio/pl061-gpio.yaml | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/gpio/pl061-gpio.yaml +22 -3
@@ -15,7 +15,9 @@ select: properties: compatible: contains: - const: arm,pl061 + enum: + - arm,pl061 + - ambarella,cv75-gpio required: - compatible
@@ -25,7 +27,9 @@ properties: compatible: items: - - const: arm,pl061 + - enum: + - ambarella,cv75-gpio + - arm,pl061 - const: arm,primecell reg:
@@ -64,6 +68,21 @@ required: - "#gpio-cells" - gpio-controller -additionalProperties: false +allOf: + - $ref: /schemas/arm/primecell.yaml# + - if: + properties: + compatible: + contains: + const: ambarella,cv75-gpio + then: + properties: + arm,primecell-periphid: + const: 0x000e8061 + required: + - arm,primecell-periphid + - gpio-ranges + +unevaluatedProperties: false ...
Signature · 1 line
2.34.1
PATCH v15 2/14 gpio: regmap: add GPIO_REGMAP_QUIRK_SET_AFTER_DIR
In reply to Long ZhaoSome controllers ignore output writes while a line is still an input. Add a behaviour flag so the output value is written after the direction change. This is a legacy quirk. New hardware must not use it.
--- drivers/gpio/gpio-regmap.c | 15 +++++++++++++-- include/linux/gpio/regmap.h | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-)
drivers/gpio/gpio-regmap.c +13 -2
@@ -33,6 +33,7 @@ struct gpio_regmap {unsigned int reg_dir_out_base;unsigned long *fixed_direction_mask;unsigned long *fixed_direction_output; +unsigned long quirks;#ifdef CONFIG_REGMAP_IRQ int regmap_irq_line;
@@ -271,9 +272,17 @@ static int gpio_regmap_direction_output(struct gpio_chip *chip,return ret; } -gpio_regmap_set (chip, offset, value); +if (!(gpio->quirks &GPIO_REGMAP_QUIRK_SET_AFTER_DIR )) +gpio_regmap_set (chip, offset, value); -return gpio_regmap_set_direction (chip, offset, true); + ret =gpio_regmap_set_direction (chip, offset, true); +if (ret) +return ret; + +if (gpio->quirks &GPIO_REGMAP_QUIRK_SET_AFTER_DIR ) +gpio_regmap_set (chip, offset, value); + +return 0 ; }void *gpio_regmap_get_drvdata (struct gpio_regmap *gpio)
@@ -376,6 +385,8 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config config->fixed_direction_output, chip->ngpio); } + gpio->quirks = config->quirks; +/* if not set, assume there is only one register */ gpio->ngpio_per_reg = config->ngpio_per_reg;if (!gpio->ngpio_per_reg)
include/linux/gpio/regmap.h +14 -0
@@ -3,6 +3,8 @@#ifndef _LINUX_GPIO_REGMAP_H#define _LINUX_GPIO_REGMAP_H +#include <linux/bits.h> +struct device ;struct fwnode_handle ;struct gpio_regmap ;
@@ -13,6 +15,14 @@ struct regmap;#define GPIO_REGMAP_ADDR_ZERO ((unsigned int)(-1))#define GPIO_REGMAP_ADDR (addr) ((addr) ? : GPIO_REGMAP_ADDR_ZERO) +/* +* Write the output value after the line is switched to output. +* Needed when hardware ignores output writes while the line is an input. +* This is a legacy quirk; new hardware must not use it. Direction changes +* will glitch. +*/ +#define GPIO_REGMAP_QUIRK_SET_AFTER_DIR BIT(0) +/** * struct gpio_regmap_config - Description of a generic regmap gpio_chip. * @parent: The parent device
@@ -48,6 +58,7 @@ struct regmap;* (Optional) Bitmap representing the fixed direction of * the GPIO lines. Useful when there are GPIO lines with a * fixed direction mixed together in the same register. +* @quirks: (Optional) Behaviour flags, OR of GPIO_REGMAP_QUIRK_*. * @drvdata: (Optional) Pointer to driver specific data which is * not used by gpio-remap but is provided "as is" to the * driver callback(s).
@@ -98,6 +109,9 @@ struct gpio_regmap_config {unsigned long *fixed_direction_mask;unsigned long *fixed_direction_output; +/* Regmap GPIO behaviour flags */ +unsigned long quirks; +#ifdef CONFIG_REGMAP_IRQ struct regmap_irq_chip *regmap_irq_chip;int regmap_irq_line;
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v15 02/14] gpio: regmap: add GPIO_REGMAP_QUIRK_SET_AFTER_DIR
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] gpio: regmap: unchecked gpio_regmap_set() in gpio_regmap_direction_output() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] gpio: regmap: unchecked gpio_regmap_set() in gpio_regmap_direction_output()
--
commit a28b7f775ac99e04969880f3336f27205468ad0c
Author: Long Zhao <[email protected]>
gpio: regmap: add GPIO_REGMAP_QUIRK_SET_AFTER_DIR
This commit adds the GPIO_REGMAP_QUIRK_SET_AFTER_DIR flag to allow gpio-regmap controllers to write the output value after configuring the line direction as output.
Quoted 4 lines
drivers/gpio/gpio-regmap.c +0
-0
[ ... ]
Quoted 8 lines
drivers/gpio/gpio-regmap.c +2
-1@@ -271,9 +272,17 @@ static int gpio_regmap_direction_output(struct gpio_chip *chip,return ret; } -gpio_regmap_set (chip, offset, value); +if (!(gpio->quirks &GPIO_REGMAP_QUIRK_SET_AFTER_DIR )) +gpio_regmap_set (chip, offset, value);
drivers/gpio/gpio-regmap.c static int gpio_regmap_direction_output(struct gpio_chip *chip, · line 286
Quoted 10 lines
drivers/gpio/gpio-regmap.c +8
-1-return gpio_regmap_set_direction (chip, offset, true); + ret =gpio_regmap_set_direction (chip, offset, true); +if (ret) +return ret; + +if (gpio->quirks &GPIO_REGMAP_QUIRK_SET_AFTER_DIR ) +gpio_regmap_set (chip, offset, value); + +return 0 ; }
[Severity: Medium]
Should gpio_regmap_direction_output() check and return the error code from gpio_regmap_set()?
gpio_regmap_set() returns a negative errno when gpio->reg_mask_xlate() or the underlying regmap write fails. Ignoring it lets the non-quirk path switch the pin to output while driving a stale hardware value, and lets the GPIO_REGMAP_QUIRK_SET_AFTER_DIR path return 0 after switching the direction even though setting the output level failed.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v15 3/14 gpio: regmap: remove gpiochip before tearing down irqchip
In reply to Long Zhaogpiochip_remove() calls acpi_gpiochip_free_interrupts() and gpiod_free_irqs(). Both still need the irq domain. regmap_del_irq_chip() removes that domain, so remove the gpiochip first.
--- drivers/gpio/gpio-regmap.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/gpio/gpio-regmap.c +8 -1
@@ -445,12 +445,19 @@ EXPORT_SYMBOL_GPL(gpio_regmap_register);*/ void gpio_regmap_unregister (struct gpio_regmap *gpio) { +/* +* gpiochip_remove() runs acpi_gpiochip_free_interrupts() and +* gpiod_free_irqs(). Both still need the irq domain. +* regmap_del_irq_chip() removes that domain, so remove the +* gpiochip first. +*/ +gpiochip_remove (&gpio->gpio_chip); +#ifdef CONFIG_REGMAP_IRQ if (gpio->irq_chip_data)regmap_del_irq_chip (gpio->regmap_irq_line, gpio->irq_chip_data);#endif -gpiochip_remove (&gpio->gpio_chip);bitmap_free (gpio->fixed_direction_output);bitmap_free (gpio->fixed_direction_mask);kfree (gpio);
Signature · 1 line
2.34.1
Re: [PATCH v15 03/14] gpio: regmap: remove gpiochip before tearing down irqchip
Quoted 5 lines · On Wed, Nov 18, 2026 at 03:42:20PM +0800, Long Zhao via B4 Relay wrote:
gpiochip_remove()callsacpi_gpiochip_free_interrupts()andgpiod_free_irqs(). Both still need the irq domain.regmap_del_irq_chip()removes that domain, so remove the gpiochip first.
So, AFAIR Michael rose the question that this patch makes the unregister flow not reverse symmetrical to the register one. I took a look at this and I can say that this is a bit twisted. The pure creation part is independent, but to function it requires GPIO chip to be instantiated. So, yeah, this patch is a bit controversial. Let me see what we can do here.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v15 4/14 gpio: pl061: drop redundant pending check in the IRQ handler
In reply to Long Zhaofor_each_set_bit() does nothing when the mask is zero, so the if (pending) wrapper around it is redundant.
--- drivers/gpio/gpio-pl061.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpio/gpio-pl061.c +2 -5
@@ -219,11 +219,8 @@ static void pl061_irq_handler(struct irq_desc *desc)chained_irq_enter (irqchip, desc); pending =readb (pl061->base +GPIOMIS ); -if (pending) { -for_each_set_bit (offset, &pending,PL061_GPIO_NR ) -generic_handle_domain_irq (gc->irq.domain, - offset); - } +for_each_set_bit (offset, &pending,PL061_GPIO_NR ) +generic_handle_domain_irq (gc->irq.domain, offset);chained_irq_exit (irqchip, desc); }
Signature · 1 line
2.34.1
PATCH v15 5/14 gpio: pl061: convert register access to regmap
In reply to Long ZhaoReplace readb()/writeb() with a MMIO regmap while keeping the existing gpio_chip and girq irqchip. Use a raw spinlock so irq_ack() can run under the irq descriptor lock.
--- drivers/gpio/Kconfig | 1 + drivers/gpio/gpio-pl061.c | 144 ++++++++++++++++++++++++++++++---------------- 2 files changed, 94 insertions(+), 51 deletions(-)
drivers/gpio/Kconfig +1 -0
@@ -583,6 +583,7 @@ config GPIO_PL061 depends on ARM_AMBA || COMPILE_TEST select IRQ_DOMAIN select GPIOLIB_IRQCHIP + select REGMAP_MMIO help Say yes here to support the PrimeCell PL061 GPIO device.
drivers/gpio/gpio-pl061.c +93 -51
297 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v15 6/14 gpio: pl061: use IRQ_TYPE_LEVEL_MASK and IRQ_TYPE_EDGE_BOTH
In reply to Long ZhaoUse the standard IRQ_TYPE_LEVEL_MASK and IRQ_TYPE_EDGE_BOTH helpers instead of open-coded edge and level comparisons.
--- drivers/gpio/gpio-pl061.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpio/gpio-pl061.c +2 -4
@@ -167,9 +167,7 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger)if (offset <0 || offset >=PL061_GPIO_NR )return -EINVAL ; -if ((trigger & (IRQ_TYPE_LEVEL_HIGH |IRQ_TYPE_LEVEL_LOW )) && - (trigger & (IRQ_TYPE_EDGE_RISING |IRQ_TYPE_EDGE_FALLING ))) - { +if ((trigger &IRQ_TYPE_LEVEL_MASK ) && (trigger &IRQ_TYPE_EDGE_BOTH )) { dev_err(gc->parent, "trying to configure line %d for both level and edge " "detection, choose one!\n",
@@ -184,7 +182,7 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger)regmap_read (pl061->regmap,GPIOIS , &gpiois);regmap_read (pl061->regmap,GPIOIBE , &gpioibe); -if (trigger & (IRQ_TYPE_LEVEL_HIGH |IRQ_TYPE_LEVEL_LOW )) { +if (trigger &IRQ_TYPE_LEVEL_MASK ) {bool polarity = trigger &IRQ_TYPE_LEVEL_HIGH ;/* Disable edge detection */
Signature · 1 line
2.34.1
PATCH v15 7/14 gpio: pl061: use cleanup helpers for locks
In reply to Long ZhaoConvert raw_spinlock critical sections to guard()() from cleanup.h.
--- drivers/gpio/gpio-pl061.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-)
drivers/gpio/gpio-pl061.c +10 -17
@@ -10,6 +10,7 @@*/ #include <linux/amba/bus.h> #include <linux/bitops.h> +#include <linux/cleanup.h> #include <linux/device.h> #include <linux/errno.h> #include <linux/gpio/driver.h>
@@ -105,11 +106,10 @@ static int pl061_get_direction(struct gpio_chip *gc, unsigned offset)static int pl061_direction_input (struct gpio_chip *gc,unsigned offset) {struct pl061 *pl061 =gpiochip_get_data (gc); -unsigned long flags; -raw_spin_lock_irqsave (&pl061->lock, flags); +guard (raw_spinlock_irqsave)(&pl061->lock); +regmap_clear_bits (pl061->regmap,GPIODIR ,BIT (offset)); -raw_spin_unlock_irqrestore (&pl061->lock, flags);return 0 ; }
@@ -119,9 +119,9 @@ static int pl061_direction_output(struct gpio_chip *gc, unsigned offset, {struct pl061 *pl061 =gpiochip_get_data (gc);unsigned int mask =BIT (offset); -unsigned long flags; -raw_spin_lock_irqsave (&pl061->lock, flags); +guard (raw_spinlock_irqsave)(&pl061->lock); +regmap_assign_bits (pl061->regmap,BIT (offset +PL061_DATA_OFFSET ),BIT (offset), value);regmap_set_bits (pl061->regmap,GPIODIR , mask);
@@ -132,7 +132,6 @@ static int pl061_direction_output(struct gpio_chip *gc, unsigned offset,*/ regmap_assign_bits (pl061->regmap,BIT (offset +PL061_DATA_OFFSET ),BIT (offset), value); -raw_spin_unlock_irqrestore (&pl061->lock, flags);return 0 ; }
@@ -162,7 +161,6 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger)unsigned int gpioiev =0 ;unsigned int gpioibe =0 ;unsigned int gpiois =0 ; -unsigned long flags;if (offset <0 || offset >=PL061_GPIO_NR )return -EINVAL ;
@@ -175,8 +173,7 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger)return -EINVAL ; } - -raw_spin_lock_irqsave (&pl061->lock, flags); +guard (raw_spinlock_irqsave)(&pl061->lock);regmap_read (pl061->regmap,GPIOIEV , &gpioiev);regmap_read (pl061->regmap,GPIOIS , &gpiois);
@@ -236,8 +233,6 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger)regmap_write (pl061->regmap,GPIOIBE , gpioibe);regmap_write (pl061->regmap,GPIOIEV , gpioiev); -raw_spin_unlock_irqrestore (&pl061->lock, flags); -return 0 ; }
@@ -266,9 +261,8 @@ static void pl061_irq_mask(struct irq_data *d)struct pl061 *pl061 =gpiochip_get_data (gc);u8 mask =BIT (irqd_to_hwirq (d) %PL061_GPIO_NR ); -raw_spin_lock (&pl061->lock); -regmap_clear_bits (pl061->regmap,GPIOIE , mask); -raw_spin_unlock (&pl061->lock); + scoped_guard(raw_spinlock, &pl061->lock) +regmap_clear_bits (pl061->regmap,GPIOIE , mask);gpiochip_disable_irq (gc, d->hwirq); }
@@ -281,9 +275,8 @@ static void pl061_irq_unmask(struct irq_data *d)gpiochip_enable_irq (gc, d->hwirq); -raw_spin_lock (&pl061->lock); -regmap_set_bits (pl061->regmap,GPIOIE , mask); -raw_spin_unlock (&pl061->lock); + scoped_guard(raw_spinlock, &pl061->lock) +regmap_set_bits (pl061->regmap,GPIOIE , mask); }/**
Signature · 1 line
2.34.1
PATCH v15 8/14 gpio: pl061: keep the parent device in a local
In reply to Long ZhaoIRQ logging uses gc->parent. Keep that device in a local so the gpio-regmap switch can change where it comes from without rewriting every log line.
--- drivers/gpio/gpio-pl061.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/gpio/gpio-pl061.c +8 -7
@@ -156,6 +156,7 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger) {struct gpio_chip *gc =irq_data_get_irq_chip_data (d);struct pl061 *pl061 =gpiochip_get_data (gc); +struct device *parent = gc->parent;int offset =irqd_to_hwirq (d);unsigned int bit =BIT (offset);unsigned int gpioiev =0 ;
@@ -166,7 +167,7 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger)return -EINVAL ;if ((trigger &IRQ_TYPE_LEVEL_MASK ) && (trigger &IRQ_TYPE_EDGE_BOTH )) { -dev_err (gc->parent, +dev_err (parent,"trying to configure line %d for both level and edge " "detection, choose one!\n" , offset);
@@ -192,7 +193,7 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger)else gpioiev &= ~bit;irq_set_handler_locked (d, handle_level_irq); -dev_dbg (gc->parent,"line %d: IRQ on %s level\n" , +dev_dbg (parent,"line %d: IRQ on %s level\n" , offset, polarity ?"HIGH" :"LOW" ); }else if ((trigger &IRQ_TYPE_EDGE_BOTH ) ==IRQ_TYPE_EDGE_BOTH ) {
@@ -201,7 +202,7 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger)/* Select both edges, setting this makes GPIOEV be ignored */ gpioibe |= bit;irq_set_handler_locked (d, handle_edge_irq); -dev_dbg (gc->parent,"line %d: IRQ on both edges\n" , offset); +dev_dbg (parent,"line %d: IRQ on both edges\n" , offset); }else if ((trigger &IRQ_TYPE_EDGE_RISING ) || (trigger &IRQ_TYPE_EDGE_FALLING )) {bool rising = trigger &IRQ_TYPE_EDGE_RISING ;
@@ -216,7 +217,7 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger)else gpioiev &= ~bit;irq_set_handler_locked (d, handle_edge_irq); -dev_dbg (gc->parent,"line %d: IRQ on %s edge\n" , +dev_dbg (parent,"line %d: IRQ on %s edge\n" , offset, rising ?"RISING" :"FALLING" ); }else {
@@ -225,8 +226,7 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger) gpioibe &= ~bit; gpioiev &= ~bit;irq_set_handler_locked (d, handle_bad_irq); -dev_warn (gc->parent,"no trigger selected for line %d\n" , - offset); +dev_warn (parent,"no trigger selected for line %d\n" , offset); }regmap_write (pl061->regmap,GPIOIS , gpiois);
@@ -307,8 +307,9 @@ static int pl061_irq_set_wake(struct irq_data *d, unsigned int state)static void pl061_irq_print_chip (struct irq_data *data,struct seq_file *p) {struct gpio_chip *gc =irq_data_get_irq_chip_data (data); +struct device *parent = gc->parent; -seq_puts (p,dev_name (gc->parent)); +seq_puts (p,dev_name (parent)); }static const struct irq_chip pl061_irq_chip = {
Signature · 1 line
2.34.1
PATCH v15 9/14 gpiolib: request ACPI GPIO events for external IRQ domains
In reply to Long Zhaogpiochip_add_irqchip() requests GPIO-signaled ACPI events after installing the irqchip. A gpiochip that gets its IRQ domain through gpiochip_irqchip_add_domain() never goes through that path, so _AEI events, such as the power button on ARM64 ACPI platforms, are not requested.
Request them here as well. gpiochip_remove() already calls acpi_gpiochip_free_interrupts().
---
Cc: [email protected]
--- drivers/gpio/gpiolib.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/gpio/gpiolib.c +8 -1
@@ -2353,7 +2353,14 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gc)int gpiochip_irqchip_add_domain (struct gpio_chip *gc,struct irq_domain *domain) { -return gpiochip_irqchip_add_allocated_domain (gc, domain, true); +int ret; + + ret =gpiochip_irqchip_add_allocated_domain (gc, domain, true); +if (ret) +return ret; + +acpi_gpiochip_request_interrupts (gc); +return 0 ; }EXPORT_SYMBOL_GPL (gpiochip_irqchip_add_domain);
Signature · 1 line
2.34.1
Re: [PATCH v15 09/14] gpiolib: request ACPI GPIO events for external IRQ domains
Quoted 9 lines · On Wed, Nov 18, 2026 at 03:42:26PM +0800, Long Zhao via B4 Relay wrote:
gpiochip_add_irqchip()requests GPIO-signaled ACPI events after installing the irqchip. A gpiochip that gets its IRQ domain throughgpiochip_irqchip_add_domain()never goes through that path, so_AEIevents, such as the power button on ARM64 ACPI platforms, are not requested.Request them here as well.
gpiochip_remove()already callsacpi_gpiochip_free_interrupts().
This is part of the bigger issue with IRQ domain registration AFAIU. (See patch 3/14).
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v15 10/14 gpio: pl061: switch data path to gpio-regmap
In reply to Long ZhaoMove get, set and direction onto gpio-regmap. ARM PL061 sets GPIO_REGMAP_QUIRK_SET_AFTER_DIR so the output value is written after the direction change.
Keep a custom irqchip and irq domain. Create the domain with the PL061 private data and let gpio-regmap attach it.
Leave the chained handler's regmap_read() unchecked. mis stays 0 on failure, so the pending loop does nothing, and chained_irq_exit() still runs. irq_type still ignores MMIO write returns.
The irqchip uses its own child IRQ lockdep class. Split teardown into two devm actions: dispose mappings while the domain is still alive, and clear the chained handler only after it was installed. Checked with lockdep on the CV75 board. irq_set_parent() nests the GPIO irq_desc under the AMBA parent for irq_set_wake().
The irqchip is immutable and stores struct pl061 as its chip data, so the GPIOCHIP_IRQ_RESOURCE_HELPERS macro does not apply. Look up the gpio_chip while mapping the IRQ, then call gpiochip_reqres_irq(), gpiochip_relres_irq(), gpiochip_enable_irq() and gpiochip_disable_irq() from the irqchip.
--- drivers/gpio/Kconfig | 1 + drivers/gpio/gpio-pl061.c | 463 +++++++++++++++++++++++++++++----------------- 2 files changed, 294 insertions(+), 170 deletions(-)
drivers/gpio/Kconfig +1 -0
@@ -583,6 +583,7 @@ config GPIO_PL061 depends on ARM_AMBA || COMPILE_TEST select IRQ_DOMAIN select GPIOLIB_IRQCHIP + select GPIO_REGMAP select REGMAP_MMIO help Say yes here to support the PrimeCell PL061 GPIO device.
drivers/gpio/gpio-pl061.c +293 -170
636 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v15 10/14] gpio: pl061: switch data path to gpio-regmap
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] gpio: pl061: premature IRQ domain publish breaks pl061_irq_domain_map() - [Low] gpio: pl061…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] gpio: pl061: premature IRQ domain publish breaks pl061_irq_domain_map()
- [Low] gpio: pl061: incomplete changelog and inaccurate irq_set_parent() description
--
commit 0b93363ac72443e24d6e5779edcb0ca7954b6b53
Author: Long Zhao <[email protected]>
Quoted 19 lines
gpio: pl061: switch data path to gpio-regmap
Move get, set and direction onto gpio-regmap. ARM PL061 sets
GPIO_REGMAP_QUIRK_SET_AFTER_DIRso the output value is written after the direction change.Keep a custom irqchip and irq domain. Create the domain with the PL061 private data and let gpio-regmap attach it.
Leave the chained handler's
regmap_read()unchecked. mis stays 0 on failure, so the pending loop does nothing, andchained_irq_exit()still runs.irq_typestill ignores MMIO write returns.The irqchip uses its own child IRQ lockdep class. Split teardown into two devm actions: dispose mappings while the domain is still alive, and clear the chained handler only after it was installed. Checked with lockdep on the CV75 board.
irq_set_parent()nests the GPIOirq_descunder the AMBA parent forirq_set_wake().
Quoted 7 lines
The irqchip is immutable and stores struct pl061 as its chip data, so the
GPIOCHIP_IRQ_RESOURCE_HELPERSmacro does not apply. Look up thegpio_chipwhile mapping the IRQ, then callgpiochip_reqres_irq(),gpiochip_relres_irq(),gpiochip_enable_irq()andgpiochip_disable_irq()from the irqchip.Signed-off-by Long Zhao <[email protected]>
[Severity: Low]
This isn't a bug, but the commit message says irq_set_parent() nests the GPIO irq_desc under the AMBA parent for irq_set_wake(). irq_set_parent() only records desc->parent_irq under CONFIG_HARDIRQS_SW_RESEND for software interrupt resending; irq_set_lockdep_class() is what puts the child irq_desc in a separate lockdep class so irq_set_irq_wake() on parent_irq does not trigger a lockdep recursion warning.
The changelog also omits the addition of struct pl061_regs and struct pl061_drvdata and the rewrite of pl061_suspend() and pl061_resume() to use regcache syncing instead of struct pl061_context_save_regs.
Quoted 4 lines
drivers/gpio/gpio-pl061.c +0
-0
[ ... ]
Quoted 1 line
drivers/gpio/gpio-pl061.c +0
-0@@ -289,29 +255,64 @@ static void pl061_irq_unmask(struct irq_data *d)
[ ... ]
Quoted 22 lines
drivers/gpio/gpio-pl061.c +22
-0+static int pl061_gc_from_domain (struct gpio_chip *gc,const void *data) +{ +const struct pl061 *pl061 = data; + +return gc->irq.domain == pl061->irq_domain; +} + +static struct gpio_chip *pl061_lookup_gc (struct pl061 *pl061) +{ +struct gpio_device *gdev; + +if (pl061->gc) +return pl061->gc; + + gdev =gpio_device_find (pl061, pl061_gc_from_domain); +if (!gdev) +return NULL ; + + pl061->gc =gpio_device_get_chip (gdev); +gpio_device_put (gdev); +return pl061->gc; +}
[ ... ]
Quoted 1 line
drivers/gpio/gpio-pl061.c +0
-0@@ -319,68 +320,175 @@ static const struct irq_chip pl061_irq_chip = {
[ ... ]
drivers/gpio/gpio-pl061.c static const struct irq_chip pl061_irq_chip = { · line 337
Quoted 7 lines
drivers/gpio/gpio-pl061.c +7
-0+static int pl061_irq_domain_map (struct irq_domain *d,unsigned int virq, +irq_hw_number_t hwirq) +{ +struct pl061 *pl061 = d->host_data; + +if (!pl061_lookup_gc (pl061)) +return -ENODEV ;
[Severity: Medium]
Can pl061_irq_domain_map() fail with -ENODEV if a consumer maps an IRQ before devm_gpio_regmap_register() finishes?
devm_irq_domain_instantiate() publishes pl061->irq_domain on irq_domain_list before devm_gpio_regmap_register() runs, and inside gpio_regmap_register(), gpiochip_add_data() registers the gpio_device before gpiochip_irqchip_add_domain() sets gc->irq.domain:
CPU0 CPU1pl061_probe()
devm_irq_domain_instantiate()
...
__irq_domain_publish()
irq_create_fwspec_mapping()
irq_find_matching_fwspec()
irq_domain_associate_locked()
pl061_irq_domain_map()
pl061_lookup_gc()
--> NULL (-ENODEV)
devm_gpio_regmap_register()
gpio_regmap_register()
gpiochip_add_data()
gpiochip_irqchip_add_domain()
gc->irq.domain = irq_domainBecause the domain is already published, a concurrent consumer does not get -EPROBE_DEFER from irq_find_host(); instead pl061_irq_domain_map() fails with -ENODEV and irq_create_fwspec_mapping() returns 0, failing the consumer's probe.
Since pl061_irq_domain_map() does not use pl061->gc itself, could pl061_lookup_gc() be deferred to pl061_irq_request_resources(), or could pl061->gc be populated before publishing the IRQ domain?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
PATCH v15 11/14 gpio: pl061: add Ambarella register-layout variant
In reply to Long ZhaoAdd a 32-bit, 32-line layout with DAT/DIR/IS/IBE/IEV/IE/MIS/IC plus MASK and ENABLE. Probe unmasks the bank and enables the controller. IRQ type changes also clear the pending bit. This derivative does not need write-after-direction or system suspend save/restore.
Cache DAT (REGCACHE_FLAT_S, not volatile) so gpio_set() updates one bit from the output shadow instead of read-modify-writing the pin level across the bank.
Match the part with designer AMBA_VENDOR_AMBARELLA (JEP106 identity 0x68, bit 7 set) and part number 0x061.
--- drivers/gpio/gpio-pl061.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/amba/bus.h | 1 + 2 files changed, 59 insertions(+)
drivers/gpio/gpio-pl061.c +58 -0
@@ -40,6 +40,18 @@#define PL061_GPIO_NR 8#define PL061_DATA_OFFSET 2 +#define AMBARELLA_GPIO_NR 32 +#define AMBARELLA_DAT 0x00 +#define AMBARELLA_DIR 0x04 +#define AMBARELLA_IS 0x08 +#define AMBARELLA_IBE 0x0c +#define AMBARELLA_IEV 0x10 +#define AMBARELLA_IE 0x14 +#define AMBARELLA_MIS 0x20 +#define AMBARELLA_IC 0x24 +#define AMBARELLA_MASK 0x28 +#define AMBARELLA_ENABLE 0x2c +struct pl061_regs {unsigned int dat;unsigned int dir;
@@ -95,6 +107,17 @@ static bool pl061_arm_volatile_reg(struct device *dev, unsigned int reg) } } +static bool pl061_ambarella_volatile_reg (struct device *dev,unsigned int reg) +{ +switch (reg) { +case AMBARELLA_MIS : +case AMBARELLA_IC : +return true; +default : +return false; + } +} +static const struct regmap_config pl061_arm_regmap_config = { .reg_bits =16 , .val_bits =8 ,
@@ -105,6 +128,16 @@ static const struct regmap_config pl061_arm_regmap_config = { .use_raw_spinlock = true, }; +static const struct regmap_config pl061_ambarella_regmap_config = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , + .max_register =AMBARELLA_ENABLE , + .volatile_reg = pl061_ambarella_volatile_reg, + .cache_type =REGCACHE_FLAT_S , + .use_raw_spinlock = true, +}; +static unsigned int pl061_line_mask (struct pl061 *pl061,irq_hw_number_t hwirq) {return BIT (hwirq % pl061->data->ngpio);
@@ -382,6 +415,19 @@ static const struct pl061_regs pl061_arm_regs = { .ic = GPIOIC, }; +static const struct pl061_regs pl061_ambarella_regs = { + .dat =AMBARELLA_DAT , + .dir =AMBARELLA_DIR , + .is =AMBARELLA_IS , + .ibe =AMBARELLA_IBE , + .iev =AMBARELLA_IEV , + .ie =AMBARELLA_IE , + .mis =AMBARELLA_MIS , + .ic =AMBARELLA_IC , + .mask =AMBARELLA_MASK , + .enable =AMBARELLA_ENABLE , +}; +static const struct pl061_drvdata pl061_arm = { .regmap_config = &pl061_arm_regmap_config, .regs = &pl061_arm_regs,
@@ -391,6 +437,13 @@ static const struct pl061_drvdata pl061_arm = { .reg_mask_xlate = pl061_arm_reg_mask_xlate, }; +static const struct pl061_drvdata pl061_ambarella = { + .regmap_config = &pl061_ambarella_regmap_config, + .regs = &pl061_ambarella_regs, + .ngpio =AMBARELLA_GPIO_NR , + .clear_irq_on_type = true, +}; +static int pl061_probe (struct amba_device *adev,const struct amba_id *id) {struct gpio_regmap_config config = {};
@@ -567,6 +620,11 @@ static const struct amba_id pl061_ids[] = { .mask = 0x000fffff, .data = (void *)&pl061_arm, }, + { + .id = (AMBA_VENDOR_AMBARELLA << 12) | 0x061, + .mask = 0x000fffff, + .data = (void *)&pl061_ambarella, + }, { 0, 0 }, }; MODULE_DEVICE_TABLE(amba, pl061_ids);
include/linux/amba/bus.h +1 -0
@@ -98,6 +98,7 @@ enum amba_vendor {AMBA_VENDOR_ST =0x80 ,AMBA_VENDOR_QCOM =0x51 ,AMBA_VENDOR_LSI =0xb6 , + AMBA_VENDOR_AMBARELLA = 0xe8, };extern const struct bus_type amba_bustype;
Signature · 1 line
2.34.1
PATCH v15 12/14 gpio: pl061: tidy up IRQ trigger logging
In reply to Long ZhaoJoin the level-and-edge dev_err() into one string literal so a grep for "edge detection" finds it.
--- drivers/gpio/gpio-pl061.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpio/gpio-pl061.c +1 -2
@@ -172,8 +172,7 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger)if ((trigger &IRQ_TYPE_LEVEL_MASK ) && (trigger &IRQ_TYPE_EDGE_BOTH )) {dev_err (parent, -"trying to configure line %d for both level and edge " -"detection, choose one!\n" , +"trying to configure line %d for both level and edge detection, choose one!\n" , offset);return -EINVAL ; }
Signature · 1 line
2.34.1
PATCH v15 13/14 lib/string_choices: add str_rising_falling()
In reply to Long ZhaoAdd str_rising_falling() and str_falling_rising() for code that prints an IRQ trigger edge.
---
Cc: Kees Cook <[email protected]>
Cc: [email protected]
--- include/linux/string_choices.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/linux/string_choices.h +6 -0
@@ -65,6 +65,12 @@ static inline const char *str_read_write(bool v) }#define str_write_read (v) str_read_write(!(v)) +static inline const char *str_rising_falling (bool v) +{ +return v ?"rising" :"falling" ; +} +#define str_falling_rising (v) str_rising_falling(!(v)) +static inline const char *str_true_false (bool v) {return v ?"true" :"false" ;
Signature · 1 line
2.34.1
PATCH v15 14/14 gpio: pl061: use string_choices helpers for IRQ trigger logging
In reply to Long ZhaoUse str_high_low() and str_rising_falling() for the level and edge debug lines.
--- drivers/gpio/gpio-pl061.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpio/gpio-pl061.c +3 -4
@@ -27,6 +27,7 @@#include <linux/regmap.h> #include <linux/seq_file.h> #include <linux/spinlock.h> +#include <linux/string_choices.h> #define GPIODIR 0x400#define GPIOIS 0x404
@@ -197,8 +198,7 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger) gpioiev &= ~bit;irq_set_handler_locked (d, handle_level_irq);dev_dbg (parent,"line %d: IRQ on %s level\n" , - offset, - polarity ?"HIGH" :"LOW" ); + offset,str_high_low (polarity)); }else if ((trigger &IRQ_TYPE_EDGE_BOTH ) ==IRQ_TYPE_EDGE_BOTH ) {/* Disable level detection */ gpiois &= ~bit;
@@ -221,8 +221,7 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger) gpioiev &= ~bit;irq_set_handler_locked (d, handle_edge_irq);dev_dbg (parent,"line %d: IRQ on %s edge\n" , - offset, - rising ?"RISING" :"FALLING" ); + offset,str_rising_falling (rising)); }else {/* No trigger: disable everything */ gpiois &= ~bit;
Signature · 1 line
2.34.1