Skip to content

Commit 2325e44

Browse files
mbriandgregkh
authored andcommitted
gpio: regmap: Allow to allocate regmap-irq device
[ Upstream commit 553b75d4bfe9264f631d459fe9996744e0672b0e ] GPIO controller often have support for IRQ: allow to easily allocate both gpio-regmap and regmap-irq in one operation. Reviewed-by: Andy Shevchenko <[email protected]> Acked-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Mathieu Dubois-Briand <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]> Stable-dep-of: 2ba5772e530f ("gpio: idio-16: Define fixed direction of the GPIO lines") Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c21c27e commit 2325e44

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

drivers/gpio/gpio-regmap.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ struct gpio_regmap {
3232
unsigned int reg_dir_in_base;
3333
unsigned int reg_dir_out_base;
3434

35+
#ifdef CONFIG_REGMAP_IRQ
36+
int regmap_irq_line;
37+
struct regmap_irq_chip_data *irq_chip_data;
38+
#endif
39+
3540
int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
3641
unsigned int offset, unsigned int *reg,
3742
unsigned int *mask);
@@ -215,6 +220,7 @@ EXPORT_SYMBOL_GPL(gpio_regmap_get_drvdata);
215220
*/
216221
struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config)
217222
{
223+
struct irq_domain *irq_domain;
218224
struct gpio_regmap *gpio;
219225
struct gpio_chip *chip;
220226
int ret;
@@ -295,8 +301,22 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
295301
if (ret < 0)
296302
goto err_free_gpio;
297303

298-
if (config->irq_domain) {
299-
ret = gpiochip_irqchip_add_domain(chip, config->irq_domain);
304+
#ifdef CONFIG_REGMAP_IRQ
305+
if (config->regmap_irq_chip) {
306+
gpio->regmap_irq_line = config->regmap_irq_line;
307+
ret = regmap_add_irq_chip_fwnode(dev_fwnode(config->parent), config->regmap,
308+
config->regmap_irq_line, config->regmap_irq_flags,
309+
0, config->regmap_irq_chip, &gpio->irq_chip_data);
310+
if (ret)
311+
goto err_free_gpio;
312+
313+
irq_domain = regmap_irq_get_domain(gpio->irq_chip_data);
314+
} else
315+
#endif
316+
irq_domain = config->irq_domain;
317+
318+
if (irq_domain) {
319+
ret = gpiochip_irqchip_add_domain(chip, irq_domain);
300320
if (ret)
301321
goto err_remove_gpiochip;
302322
}
@@ -317,6 +337,11 @@ EXPORT_SYMBOL_GPL(gpio_regmap_register);
317337
*/
318338
void gpio_regmap_unregister(struct gpio_regmap *gpio)
319339
{
340+
#ifdef CONFIG_REGMAP_IRQ
341+
if (gpio->irq_chip_data)
342+
regmap_del_irq_chip(gpio->regmap_irq_line, gpio->irq_chip_data);
343+
#endif
344+
320345
gpiochip_remove(&gpio->gpio_chip);
321346
kfree(gpio);
322347
}

include/linux/gpio/regmap.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ struct regmap;
4040
* @drvdata: (Optional) Pointer to driver specific data which is
4141
* not used by gpio-remap but is provided "as is" to the
4242
* driver callback(s).
43+
* @regmap_irq_chip: (Optional) Pointer on an regmap_irq_chip structure. If
44+
* set, a regmap-irq device will be created and the IRQ
45+
* domain will be set accordingly.
46+
* @regmap_irq_line (Optional) The IRQ the device uses to signal interrupts.
47+
* @regmap_irq_flags (Optional) The IRQF_ flags to use for the interrupt.
4348
*
4449
* The ->reg_mask_xlate translates a given base address and GPIO offset to
4550
* register and mask pair. The base address is one of the given register
@@ -78,6 +83,12 @@ struct gpio_regmap_config {
7883
int ngpio_per_reg;
7984
struct irq_domain *irq_domain;
8085

86+
#ifdef CONFIG_REGMAP_IRQ
87+
struct regmap_irq_chip *regmap_irq_chip;
88+
int regmap_irq_line;
89+
unsigned long regmap_irq_flags;
90+
#endif
91+
8192
int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
8293
unsigned int offset, unsigned int *reg,
8394
unsigned int *mask);

0 commit comments

Comments
 (0)