Skip to content

Commit dcea54b

Browse files
author
Linus Walleij
committed
pinctrl: npcm7xx: Convert to immutable irq_chip
Convert the driver to immutable irq-chip with a bit of intuition. I refactored the way the state container was accessed in the irq_chip callbacks to all look the same and switch to use irqd_to_hwirq() while we are at it. Cc: Marc Zyngier <maz@kernel.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Link: https://lore.kernel.org/r/20230403-immutable-irqchips-v1-4-503788a7f6e6@linaro.org
1 parent dccdc09 commit dcea54b

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ struct npcm7xx_gpio {
8282
struct gpio_chip gc;
8383
int irqbase;
8484
int irq;
85-
struct irq_chip irq_chip;
8685
u32 pinctrl_id;
8786
int (*direction_input)(struct gpio_chip *chip, unsigned int offset);
8887
int (*direction_output)(struct gpio_chip *chip, unsigned int offset,
@@ -240,9 +239,9 @@ static void npcmgpio_irq_handler(struct irq_desc *desc)
240239

241240
static int npcmgpio_set_irq_type(struct irq_data *d, unsigned int type)
242241
{
243-
struct npcm7xx_gpio *bank =
244-
gpiochip_get_data(irq_data_get_irq_chip_data(d));
245-
unsigned int gpio = BIT(d->hwirq);
242+
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
243+
struct npcm7xx_gpio *bank = gpiochip_get_data(gc);
244+
unsigned int gpio = BIT(irqd_to_hwirq(d));
246245

247246
dev_dbg(bank->gc.parent, "setirqtype: %u.%u = %u\n", gpio,
248247
d->irq, type);
@@ -288,9 +287,9 @@ static int npcmgpio_set_irq_type(struct irq_data *d, unsigned int type)
288287

289288
static void npcmgpio_irq_ack(struct irq_data *d)
290289
{
291-
struct npcm7xx_gpio *bank =
292-
gpiochip_get_data(irq_data_get_irq_chip_data(d));
293-
unsigned int gpio = d->hwirq;
290+
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
291+
struct npcm7xx_gpio *bank = gpiochip_get_data(gc);
292+
unsigned int gpio = irqd_to_hwirq(d);
294293

295294
dev_dbg(bank->gc.parent, "irq_ack: %u.%u\n", gpio, d->irq);
296295
iowrite32(BIT(gpio), bank->base + NPCM7XX_GP_N_EVST);
@@ -299,31 +298,33 @@ static void npcmgpio_irq_ack(struct irq_data *d)
299298
/* Disable GPIO interrupt */
300299
static void npcmgpio_irq_mask(struct irq_data *d)
301300
{
302-
struct npcm7xx_gpio *bank =
303-
gpiochip_get_data(irq_data_get_irq_chip_data(d));
304-
unsigned int gpio = d->hwirq;
301+
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
302+
struct npcm7xx_gpio *bank = gpiochip_get_data(gc);
303+
unsigned int gpio = irqd_to_hwirq(d);
305304

306305
/* Clear events */
307306
dev_dbg(bank->gc.parent, "irq_mask: %u.%u\n", gpio, d->irq);
308307
iowrite32(BIT(gpio), bank->base + NPCM7XX_GP_N_EVENC);
308+
gpiochip_disable_irq(gc, gpio);
309309
}
310310

311311
/* Enable GPIO interrupt */
312312
static void npcmgpio_irq_unmask(struct irq_data *d)
313313
{
314-
struct npcm7xx_gpio *bank =
315-
gpiochip_get_data(irq_data_get_irq_chip_data(d));
316-
unsigned int gpio = d->hwirq;
314+
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
315+
struct npcm7xx_gpio *bank = gpiochip_get_data(gc);
316+
unsigned int gpio = irqd_to_hwirq(d);
317317

318318
/* Enable events */
319+
gpiochip_enable_irq(gc, gpio);
319320
dev_dbg(bank->gc.parent, "irq_unmask: %u.%u\n", gpio, d->irq);
320321
iowrite32(BIT(gpio), bank->base + NPCM7XX_GP_N_EVENS);
321322
}
322323

323324
static unsigned int npcmgpio_irq_startup(struct irq_data *d)
324325
{
325326
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
326-
unsigned int gpio = d->hwirq;
327+
unsigned int gpio = irqd_to_hwirq(d);
327328

328329
/* active-high, input, clear interrupt, enable interrupt */
329330
dev_dbg(gc->parent, "startup: %u.%u\n", gpio, d->irq);
@@ -341,6 +342,8 @@ static const struct irq_chip npcmgpio_irqchip = {
341342
.irq_mask = npcmgpio_irq_mask,
342343
.irq_set_type = npcmgpio_set_irq_type,
343344
.irq_startup = npcmgpio_irq_startup,
345+
.flags = IRQCHIP_IMMUTABLE,
346+
GPIOCHIP_IRQ_RESOURCE_HELPERS,
344347
};
345348

346349
/* pinmux handing in the pinctrl driver*/
@@ -1906,7 +1909,6 @@ static int npcm7xx_gpio_of(struct npcm7xx_pinctrl *pctrl)
19061909
return -EINVAL;
19071910
}
19081911
pctrl->gpio_bank[id].irq = ret;
1909-
pctrl->gpio_bank[id].irq_chip = npcmgpio_irqchip;
19101912
pctrl->gpio_bank[id].irqbase = id * NPCM7XX_GPIO_PER_BANK;
19111913
pctrl->gpio_bank[id].pinctrl_id = args.args[0];
19121914
pctrl->gpio_bank[id].gc.base = args.args[1];
@@ -1941,7 +1943,7 @@ static int npcm7xx_gpio_register(struct npcm7xx_pinctrl *pctrl)
19411943
struct gpio_irq_chip *girq;
19421944

19431945
girq = &pctrl->gpio_bank[id].gc.irq;
1944-
girq->chip = &pctrl->gpio_bank[id].irq_chip;
1946+
gpio_irq_chip_set_chip(girq, &npcmgpio_irqchip);
19451947
girq->parent_handler = npcmgpio_irq_handler;
19461948
girq->num_parents = 1;
19471949
girq->parents = devm_kcalloc(pctrl->dev, 1,

0 commit comments

Comments
 (0)