[PATCH RFC 8/9] gpio: timberdale: Make irq_chip immutable

Peng Fan (OSS) posted 9 patches 9 months ago
[PATCH RFC 8/9] gpio: timberdale: Make irq_chip immutable
Posted by Peng Fan (OSS) 9 months ago
From: Peng Fan <peng.fan@nxp.com>

Kernel warns about mutable irq_chips:
"not an immutable chip, please consider fixing!"

Constify timbgpio_irqchip, flag the irq_chip as IRQCHIP_IMMUTABLE,
add the new helper functions, and call the appropriate gpiolib functions.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/gpio/gpio-timberdale.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-timberdale.c b/drivers/gpio/gpio-timberdale.c
index fad979797486534d3cc6a1437fdca765baeb7b47..cb303a26f4d3cd77368b5bdac42aa42821b39345 100644
--- a/drivers/gpio/gpio-timberdale.c
+++ b/drivers/gpio/gpio-timberdale.c
@@ -103,20 +103,26 @@ static void timbgpio_irq_disable(struct irq_data *d)
 {
 	struct timbgpio *tgpio = irq_data_get_irq_chip_data(d);
 	int offset = d->irq - tgpio->irq_base;
+	irq_hw_number_t hwirq = irqd_to_hwirq(d);
 	unsigned long flags;
 
 	spin_lock_irqsave(&tgpio->lock, flags);
 	tgpio->last_ier &= ~(1UL << offset);
 	iowrite32(tgpio->last_ier, tgpio->membase + TGPIO_IER);
 	spin_unlock_irqrestore(&tgpio->lock, flags);
+
+	gpiochip_disable_irq(&tgpio->gpio, hwirq);
 }
 
 static void timbgpio_irq_enable(struct irq_data *d)
 {
 	struct timbgpio *tgpio = irq_data_get_irq_chip_data(d);
 	int offset = d->irq - tgpio->irq_base;
+	irq_hw_number_t hwirq = irqd_to_hwirq(d);
 	unsigned long flags;
 
+	gpiochip_enable_irq(&tgpio->gpio, hwirq);
+
 	spin_lock_irqsave(&tgpio->lock, flags);
 	tgpio->last_ier |= 1UL << offset;
 	iowrite32(tgpio->last_ier, tgpio->membase + TGPIO_IER);
@@ -205,11 +211,13 @@ static void timbgpio_irq(struct irq_desc *desc)
 	iowrite32(tgpio->last_ier, tgpio->membase + TGPIO_IER);
 }
 
-static struct irq_chip timbgpio_irqchip = {
+static const struct irq_chip timbgpio_irqchip = {
 	.name		= "GPIO",
 	.irq_enable	= timbgpio_irq_enable,
 	.irq_disable	= timbgpio_irq_disable,
 	.irq_set_type	= timbgpio_irq_type,
+	.flags = IRQCHIP_IMMUTABLE,
+	GPIOCHIP_IRQ_RESOURCE_HELPERS,
 };
 
 static int timbgpio_probe(struct platform_device *pdev)

-- 
2.37.1
Re: [PATCH RFC 8/9] gpio: timberdale: Make irq_chip immutable
Posted by Andy Shevchenko 9 months ago
Fri, May 09, 2025 at 12:45:39PM +0800, Peng Fan (OSS) kirjoitti:
> From: Peng Fan <peng.fan@nxp.com>
> 
> Kernel warns about mutable irq_chips:
> "not an immutable chip, please consider fixing!"
> 
> Constify timbgpio_irqchip, flag the irq_chip as IRQCHIP_IMMUTABLE,
> add the new helper functions, and call the appropriate gpiolib functions.

...

>  	struct timbgpio *tgpio = irq_data_get_irq_chip_data(d);
>  	int offset = d->irq - tgpio->irq_base;
> +	irq_hw_number_t hwirq = irqd_to_hwirq(d);
>  	unsigned long flags;

While at it, replace direct accesses to IRQ data `irq` member.

  	int offset = hwirq - tgpio->irq_base;

...

>  static void timbgpio_irq_enable(struct irq_data *d)
>  {
>  	struct timbgpio *tgpio = irq_data_get_irq_chip_data(d);
>  	int offset = d->irq - tgpio->irq_base;
> +	irq_hw_number_t hwirq = irqd_to_hwirq(d);
>  	unsigned long flags;

Ditto.

> +	gpiochip_enable_irq(&tgpio->gpio, hwirq);
> +
>  	spin_lock_irqsave(&tgpio->lock, flags);
>  	tgpio->last_ier |= 1UL << offset;
>  	iowrite32(tgpio->last_ier, tgpio->membase + TGPIO_IER);

>  }

-- 
With Best Regards,
Andy Shevchenko