Skip to content

Commit 565a0e9

Browse files
committed
gpio: adnp: Use irqchip template
This makes the driver use the irqchip template to assign properties to the gpio_irq_chip instead of using the explicit calls to gpiochip_irqchip_add_nested() and gpiochip_set_nested_irqchip(). The irqchip is instead added while adding the gpiochip. Signed-off-by: Linus Walleij <[email protected]> Cc: Roland Stigge <[email protected]> Cc: Lars Poeschel <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9745079 commit 565a0e9

File tree

1 file changed

+48
-47
lines changed

1 file changed

+48
-47
lines changed

drivers/gpio/gpio-adnp.c

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -238,36 +238,6 @@ static void adnp_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
238238
mutex_unlock(&adnp->i2c_lock);
239239
}
240240

241-
static int adnp_gpio_setup(struct adnp *adnp, unsigned int num_gpios)
242-
{
243-
struct gpio_chip *chip = &adnp->gpio;
244-
int err;
245-
246-
adnp->reg_shift = get_count_order(num_gpios) - 3;
247-
248-
chip->direction_input = adnp_gpio_direction_input;
249-
chip->direction_output = adnp_gpio_direction_output;
250-
chip->get = adnp_gpio_get;
251-
chip->set = adnp_gpio_set;
252-
chip->can_sleep = true;
253-
254-
if (IS_ENABLED(CONFIG_DEBUG_FS))
255-
chip->dbg_show = adnp_gpio_dbg_show;
256-
257-
chip->base = -1;
258-
chip->ngpio = num_gpios;
259-
chip->label = adnp->client->name;
260-
chip->parent = &adnp->client->dev;
261-
chip->of_node = chip->parent->of_node;
262-
chip->owner = THIS_MODULE;
263-
264-
err = devm_gpiochip_add_data(&adnp->client->dev, chip, adnp);
265-
if (err)
266-
return err;
267-
268-
return 0;
269-
}
270-
271241
static irqreturn_t adnp_irq(int irq, void *data)
272242
{
273243
struct adnp *adnp = data;
@@ -464,18 +434,54 @@ static int adnp_irq_setup(struct adnp *adnp)
464434
return err;
465435
}
466436

467-
err = gpiochip_irqchip_add_nested(chip,
468-
&adnp_irq_chip,
469-
0,
470-
handle_simple_irq,
471-
IRQ_TYPE_NONE);
472-
if (err) {
473-
dev_err(chip->parent,
474-
"could not connect irqchip to gpiochip\n");
475-
return err;
437+
return 0;
438+
}
439+
440+
static int adnp_gpio_setup(struct adnp *adnp, unsigned int num_gpios,
441+
bool is_irq_controller)
442+
{
443+
struct gpio_chip *chip = &adnp->gpio;
444+
int err;
445+
446+
adnp->reg_shift = get_count_order(num_gpios) - 3;
447+
448+
chip->direction_input = adnp_gpio_direction_input;
449+
chip->direction_output = adnp_gpio_direction_output;
450+
chip->get = adnp_gpio_get;
451+
chip->set = adnp_gpio_set;
452+
chip->can_sleep = true;
453+
454+
if (IS_ENABLED(CONFIG_DEBUG_FS))
455+
chip->dbg_show = adnp_gpio_dbg_show;
456+
457+
chip->base = -1;
458+
chip->ngpio = num_gpios;
459+
chip->label = adnp->client->name;
460+
chip->parent = &adnp->client->dev;
461+
chip->of_node = chip->parent->of_node;
462+
chip->owner = THIS_MODULE;
463+
464+
if (is_irq_controller) {
465+
struct gpio_irq_chip *girq;
466+
467+
err = adnp_irq_setup(adnp);
468+
if (err)
469+
return err;
470+
471+
girq = &chip->irq;
472+
girq->chip = &adnp_irq_chip;
473+
/* This will let us handle the parent IRQ in the driver */
474+
girq->parent_handler = NULL;
475+
girq->num_parents = 0;
476+
girq->parents = NULL;
477+
girq->default_type = IRQ_TYPE_NONE;
478+
girq->handler = handle_simple_irq;
479+
girq->threaded = true;
476480
}
477481

478-
gpiochip_set_nested_irqchip(chip, &adnp_irq_chip, adnp->client->irq);
482+
err = devm_gpiochip_add_data(&adnp->client->dev, chip, adnp);
483+
if (err)
484+
return err;
479485

480486
return 0;
481487
}
@@ -503,16 +509,11 @@ static int adnp_i2c_probe(struct i2c_client *client,
503509
mutex_init(&adnp->i2c_lock);
504510
adnp->client = client;
505511

506-
err = adnp_gpio_setup(adnp, num_gpios);
512+
err = adnp_gpio_setup(adnp, num_gpios,
513+
of_property_read_bool(np, "interrupt-controller"));
507514
if (err)
508515
return err;
509516

510-
if (of_find_property(np, "interrupt-controller", NULL)) {
511-
err = adnp_irq_setup(adnp);
512-
if (err)
513-
return err;
514-
}
515-
516517
i2c_set_clientdata(client, adnp);
517518

518519
return 0;

0 commit comments

Comments
 (0)