Skip to content

Commit 512c193

Browse files
mbriandgregkh
authored andcommitted
gpio: regmap: Allow to allocate regmap-irq device
[ Upstream commit 553b75d ] 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: 2ba5772 ("gpio: idio-16: Define fixed direction of the GPIO lines") Signed-off-by: William Breathitt Gray <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 41e98f2 commit 512c193

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

drivers/gpio/gpio-regmap.c

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

33+
#ifdef CONFIG_REGMAP_IRQ
34+
int regmap_irq_line;
35+
struct regmap_irq_chip_data *irq_chip_data;
36+
#endif
37+
3338
int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
3439
unsigned int offset, unsigned int *reg,
3540
unsigned int *mask);
@@ -203,6 +208,7 @@ EXPORT_SYMBOL_GPL(gpio_regmap_get_drvdata);
203208
*/
204209
struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config)
205210
{
211+
struct irq_domain *irq_domain;
206212
struct gpio_regmap *gpio;
207213
struct gpio_chip *chip;
208214
int ret;
@@ -278,8 +284,22 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
278284
if (ret < 0)
279285
goto err_free_gpio;
280286

281-
if (config->irq_domain) {
282-
ret = gpiochip_irqchip_add_domain(chip, config->irq_domain);
287+
#ifdef CONFIG_REGMAP_IRQ
288+
if (config->regmap_irq_chip) {
289+
gpio->regmap_irq_line = config->regmap_irq_line;
290+
ret = regmap_add_irq_chip_fwnode(dev_fwnode(config->parent), config->regmap,
291+
config->regmap_irq_line, config->regmap_irq_flags,
292+
0, config->regmap_irq_chip, &gpio->irq_chip_data);
293+
if (ret)
294+
goto err_free_gpio;
295+
296+
irq_domain = regmap_irq_get_domain(gpio->irq_chip_data);
297+
} else
298+
#endif
299+
irq_domain = config->irq_domain;
300+
301+
if (irq_domain) {
302+
ret = gpiochip_irqchip_add_domain(chip, irq_domain);
283303
if (ret)
284304
goto err_remove_gpiochip;
285305
}
@@ -300,6 +320,11 @@ EXPORT_SYMBOL_GPL(gpio_regmap_register);
300320
*/
301321
void gpio_regmap_unregister(struct gpio_regmap *gpio)
302322
{
323+
#ifdef CONFIG_REGMAP_IRQ
324+
if (gpio->irq_chip_data)
325+
regmap_del_irq_chip(gpio->regmap_irq_line, gpio->irq_chip_data);
326+
#endif
327+
303328
gpiochip_remove(&gpio->gpio_chip);
304329
kfree(gpio);
305330
}

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)