Skip to content

Commit df60325

Browse files
author
Linus Walleij
committed
pinctrl: sx150x: Convert to immutable irq_chip
Convert the driver to immutable irq-chip with a bit of intuition. I switched to consistently using irqd_to_hwirq() consistently while we are at it. As the driver now needs to get the gpio_chip in the .irq_mask and .irq_unmask callbacks, I switched to a pattern where we first fetch the gpio_chip and then the state container from that in two steps. The compiler will do the same thing anyway. 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-9-503788a7f6e6@linaro.org
1 parent 7341944 commit df60325

1 file changed

Lines changed: 37 additions & 27 deletions

File tree

drivers/pinctrl/pinctrl-sx150x.c

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ struct sx150x_pinctrl {
9999
struct pinctrl_dev *pctldev;
100100
struct pinctrl_desc pinctrl_desc;
101101
struct gpio_chip gpio;
102-
struct irq_chip irq_chip;
103102
struct regmap *regmap;
104103
struct {
105104
u32 sense;
@@ -487,19 +486,21 @@ static int sx150x_gpio_direction_output(struct gpio_chip *chip,
487486

488487
static void sx150x_irq_mask(struct irq_data *d)
489488
{
490-
struct sx150x_pinctrl *pctl =
491-
gpiochip_get_data(irq_data_get_irq_chip_data(d));
492-
unsigned int n = d->hwirq;
489+
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
490+
struct sx150x_pinctrl *pctl = gpiochip_get_data(gc);
491+
unsigned int n = irqd_to_hwirq(d);
493492

494493
pctl->irq.masked |= BIT(n);
494+
gpiochip_disable_irq(gc, n);
495495
}
496496

497497
static void sx150x_irq_unmask(struct irq_data *d)
498498
{
499-
struct sx150x_pinctrl *pctl =
500-
gpiochip_get_data(irq_data_get_irq_chip_data(d));
501-
unsigned int n = d->hwirq;
499+
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
500+
struct sx150x_pinctrl *pctl = gpiochip_get_data(gc);
501+
unsigned int n = irqd_to_hwirq(d);
502502

503+
gpiochip_enable_irq(gc, n);
503504
pctl->irq.masked &= ~BIT(n);
504505
}
505506

@@ -520,14 +521,14 @@ static void sx150x_irq_set_sense(struct sx150x_pinctrl *pctl,
520521

521522
static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type)
522523
{
523-
struct sx150x_pinctrl *pctl =
524-
gpiochip_get_data(irq_data_get_irq_chip_data(d));
524+
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
525+
struct sx150x_pinctrl *pctl = gpiochip_get_data(gc);
525526
unsigned int n, val = 0;
526527

527528
if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW))
528529
return -EINVAL;
529530

530-
n = d->hwirq;
531+
n = irqd_to_hwirq(d);
531532

532533
if (flow_type & IRQ_TYPE_EDGE_RISING)
533534
val |= SX150X_IRQ_TYPE_EDGE_RISING;
@@ -562,22 +563,42 @@ static irqreturn_t sx150x_irq_thread_fn(int irq, void *dev_id)
562563

563564
static void sx150x_irq_bus_lock(struct irq_data *d)
564565
{
565-
struct sx150x_pinctrl *pctl =
566-
gpiochip_get_data(irq_data_get_irq_chip_data(d));
566+
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
567+
struct sx150x_pinctrl *pctl = gpiochip_get_data(gc);
567568

568569
mutex_lock(&pctl->lock);
569570
}
570571

571572
static void sx150x_irq_bus_sync_unlock(struct irq_data *d)
572573
{
573-
struct sx150x_pinctrl *pctl =
574-
gpiochip_get_data(irq_data_get_irq_chip_data(d));
574+
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
575+
struct sx150x_pinctrl *pctl = gpiochip_get_data(gc);
575576

576577
regmap_write(pctl->regmap, pctl->data->reg_irq_mask, pctl->irq.masked);
577578
regmap_write(pctl->regmap, pctl->data->reg_sense, pctl->irq.sense);
578579
mutex_unlock(&pctl->lock);
579580
}
580581

582+
583+
static void sx150x_irq_print_chip(struct irq_data *d, struct seq_file *p)
584+
{
585+
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
586+
struct sx150x_pinctrl *pctl = gpiochip_get_data(gc);
587+
588+
seq_printf(p, pctl->client->name);
589+
}
590+
591+
static const struct irq_chip sx150x_irq_chip = {
592+
.irq_mask = sx150x_irq_mask,
593+
.irq_unmask = sx150x_irq_unmask,
594+
.irq_set_type = sx150x_irq_set_type,
595+
.irq_bus_lock = sx150x_irq_bus_lock,
596+
.irq_bus_sync_unlock = sx150x_irq_bus_sync_unlock,
597+
.irq_print_chip = sx150x_irq_print_chip,
598+
.flags = IRQCHIP_IMMUTABLE,
599+
GPIOCHIP_IRQ_RESOURCE_HELPERS,
600+
};
601+
581602
static int sx150x_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
582603
unsigned long *config)
583604
{
@@ -1181,19 +1202,8 @@ static int sx150x_probe(struct i2c_client *client)
11811202
if (client->irq > 0) {
11821203
struct gpio_irq_chip *girq;
11831204

1184-
pctl->irq_chip.irq_mask = sx150x_irq_mask;
1185-
pctl->irq_chip.irq_unmask = sx150x_irq_unmask;
1186-
pctl->irq_chip.irq_set_type = sx150x_irq_set_type;
1187-
pctl->irq_chip.irq_bus_lock = sx150x_irq_bus_lock;
1188-
pctl->irq_chip.irq_bus_sync_unlock = sx150x_irq_bus_sync_unlock;
1189-
pctl->irq_chip.name = devm_kstrdup(dev, client->name,
1190-
GFP_KERNEL);
1191-
if (!pctl->irq_chip.name)
1192-
return -ENOMEM;
1193-
11941205
pctl->irq.masked = ~0;
11951206
pctl->irq.sense = 0;
1196-
11971207
/*
11981208
* Because sx150x_irq_threaded_fn invokes all of the
11991209
* nested interrupt handlers via handle_nested_irq,
@@ -1206,7 +1216,7 @@ static int sx150x_probe(struct i2c_client *client)
12061216
* called (should not happen)
12071217
*/
12081218
girq = &pctl->gpio.irq;
1209-
girq->chip = &pctl->irq_chip;
1219+
gpio_irq_chip_set_chip(girq, &sx150x_irq_chip);
12101220
/* This will let us handle the parent IRQ in the driver */
12111221
girq->parent_handler = NULL;
12121222
girq->num_parents = 0;
@@ -1219,7 +1229,7 @@ static int sx150x_probe(struct i2c_client *client)
12191229
sx150x_irq_thread_fn,
12201230
IRQF_ONESHOT | IRQF_SHARED |
12211231
IRQF_TRIGGER_FALLING,
1222-
pctl->irq_chip.name, pctl);
1232+
client->name, pctl);
12231233
if (ret < 0)
12241234
return ret;
12251235
}

0 commit comments

Comments
 (0)