Message ID | 20250522-mdb-max7360-support-v9-6-74fc03517e41@bootlin.com |
---|---|
State | New |
Headers | show |
Series | Add support for MAX7360 | expand |
On Thu, May 22, 2025 at 2:06 PM Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> wrote: > > GPIO controller often have support for IRQ: allow to easily allocate > both gpio-regmap and regmap-irq in one operation. > > Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> > --- > drivers/gpio/gpio-regmap.c | 21 +++++++++++++++++++-- > include/linux/gpio/regmap.h | 11 +++++++++++ > 2 files changed, 30 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c > index 87c4225784cf..9cbbbaf82609 100644 > --- a/drivers/gpio/gpio-regmap.c > +++ b/drivers/gpio/gpio-regmap.c > @@ -215,6 +215,7 @@ EXPORT_SYMBOL_GPL(gpio_regmap_get_drvdata); > */ > struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config) > { > + struct irq_domain *irq_domain; > struct gpio_regmap *gpio; > struct gpio_chip *chip; > int ret; > @@ -295,8 +296,24 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config > if (ret < 0) > goto err_free_gpio; > > - if (config->irq_domain) { > - ret = gpiochip_irqchip_add_domain(chip, config->irq_domain); > +#ifdef CONFIG_REGMAP_IRQ > + if (config->regmap_irq_chip) { > + struct regmap_irq_chip_data *irq_chip_data; > + > + ret = devm_regmap_add_irq_chip_fwnode(config->parent, dev_fwnode(config->parent), > + config->regmap, config->regmap_irq_line, > + config->regmap_irq_flags, 0, > + config->regmap_irq_chip, &irq_chip_data); I don't think using devres here is a good idea. There's no guarantee that gpio_regmap_register() will be called on device attach so you must not make the release of the resource depend on an associated detach which may never happen. Please use the non-managed variant here. Bart > + if (ret) > + goto err_free_gpio; > + > + irq_domain = regmap_irq_get_domain(irq_chip_data); > + } else > +#endif > + irq_domain = config->irq_domain; > + > + if (irq_domain) { > + ret = gpiochip_irqchip_add_domain(chip, irq_domain); > if (ret) > goto err_remove_gpiochip; > } > diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h > index c722c67668c6..19b52ac03a5d 100644 > --- a/include/linux/gpio/regmap.h > +++ b/include/linux/gpio/regmap.h > @@ -40,6 +40,11 @@ struct regmap; > * @drvdata: (Optional) Pointer to driver specific data which is > * not used by gpio-remap but is provided "as is" to the > * driver callback(s). > + * @regmap_irq_chip: (Optional) Pointer on an regmap_irq_chip structure. If > + * set, a regmap-irq device will be created and the IRQ > + * domain will be set accordingly. > + * @regmap_irq_line (Optional) The IRQ the device uses to signal interrupts. > + * @regmap_irq_flags (Optional) The IRQF_ flags to use for the interrupt. > * > * The ->reg_mask_xlate translates a given base address and GPIO offset to > * register and mask pair. The base address is one of the given register > @@ -78,6 +83,12 @@ struct gpio_regmap_config { > int ngpio_per_reg; > struct irq_domain *irq_domain; > > +#ifdef CONFIG_REGMAP_IRQ > + struct regmap_irq_chip *regmap_irq_chip; > + int regmap_irq_line; > + unsigned long regmap_irq_flags; > +#endif > + > int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base, > unsigned int offset, unsigned int *reg, > unsigned int *mask); > > -- > 2.39.5 >
On Thu May 22, 2025 at 3:01 PM CEST, Bartosz Golaszewski wrote: > On Thu, May 22, 2025 at 2:06 PM Mathieu Dubois-Briand > <mathieu.dubois-briand@bootlin.com> wrote: >> >> GPIO controller often have support for IRQ: allow to easily allocate >> both gpio-regmap and regmap-irq in one operation. >> >> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> >> --- >> drivers/gpio/gpio-regmap.c | 21 +++++++++++++++++++-- >> include/linux/gpio/regmap.h | 11 +++++++++++ >> 2 files changed, 30 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c >> index 87c4225784cf..9cbbbaf82609 100644 >> --- a/drivers/gpio/gpio-regmap.c >> +++ b/drivers/gpio/gpio-regmap.c >> @@ -215,6 +215,7 @@ EXPORT_SYMBOL_GPL(gpio_regmap_get_drvdata); >> */ >> struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config) >> { >> + struct irq_domain *irq_domain; >> struct gpio_regmap *gpio; >> struct gpio_chip *chip; >> int ret; >> @@ -295,8 +296,24 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config >> if (ret < 0) >> goto err_free_gpio; >> >> - if (config->irq_domain) { >> - ret = gpiochip_irqchip_add_domain(chip, config->irq_domain); >> +#ifdef CONFIG_REGMAP_IRQ >> + if (config->regmap_irq_chip) { >> + struct regmap_irq_chip_data *irq_chip_data; >> + >> + ret = devm_regmap_add_irq_chip_fwnode(config->parent, dev_fwnode(config->parent), >> + config->regmap, config->regmap_irq_line, >> + config->regmap_irq_flags, 0, >> + config->regmap_irq_chip, &irq_chip_data); > > I don't think using devres here is a good idea. There's no guarantee > that gpio_regmap_register() will be called on device attach so you > must not make the release of the resource depend on an associated > detach which may never happen. Please use the non-managed variant > here. Right, I will make sure to use regmap_add_irq_chip_fwnode()/regmap_del_irq_chip() here. I should be able to send a new version in the coming days. > > Bart > Thanks for your review. Mathieu
diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index 87c4225784cf..9cbbbaf82609 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c @@ -215,6 +215,7 @@ EXPORT_SYMBOL_GPL(gpio_regmap_get_drvdata); */ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config) { + struct irq_domain *irq_domain; struct gpio_regmap *gpio; struct gpio_chip *chip; int ret; @@ -295,8 +296,24 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config if (ret < 0) goto err_free_gpio; - if (config->irq_domain) { - ret = gpiochip_irqchip_add_domain(chip, config->irq_domain); +#ifdef CONFIG_REGMAP_IRQ + if (config->regmap_irq_chip) { + struct regmap_irq_chip_data *irq_chip_data; + + ret = devm_regmap_add_irq_chip_fwnode(config->parent, dev_fwnode(config->parent), + config->regmap, config->regmap_irq_line, + config->regmap_irq_flags, 0, + config->regmap_irq_chip, &irq_chip_data); + if (ret) + goto err_free_gpio; + + irq_domain = regmap_irq_get_domain(irq_chip_data); + } else +#endif + irq_domain = config->irq_domain; + + if (irq_domain) { + ret = gpiochip_irqchip_add_domain(chip, irq_domain); if (ret) goto err_remove_gpiochip; } diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h index c722c67668c6..19b52ac03a5d 100644 --- a/include/linux/gpio/regmap.h +++ b/include/linux/gpio/regmap.h @@ -40,6 +40,11 @@ struct regmap; * @drvdata: (Optional) Pointer to driver specific data which is * not used by gpio-remap but is provided "as is" to the * driver callback(s). + * @regmap_irq_chip: (Optional) Pointer on an regmap_irq_chip structure. If + * set, a regmap-irq device will be created and the IRQ + * domain will be set accordingly. + * @regmap_irq_line (Optional) The IRQ the device uses to signal interrupts. + * @regmap_irq_flags (Optional) The IRQF_ flags to use for the interrupt. * * The ->reg_mask_xlate translates a given base address and GPIO offset to * register and mask pair. The base address is one of the given register @@ -78,6 +83,12 @@ struct gpio_regmap_config { int ngpio_per_reg; struct irq_domain *irq_domain; +#ifdef CONFIG_REGMAP_IRQ + struct regmap_irq_chip *regmap_irq_chip; + int regmap_irq_line; + unsigned long regmap_irq_flags; +#endif + int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base, unsigned int offset, unsigned int *reg, unsigned int *mask);
GPIO controller often have support for IRQ: allow to easily allocate both gpio-regmap and regmap-irq in one operation. Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> --- drivers/gpio/gpio-regmap.c | 21 +++++++++++++++++++-- include/linux/gpio/regmap.h | 11 +++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-)