Skip to content

Commit 0e3cb6e

Browse files
Russell Kinglinusw
authored andcommitted
gpio: gpio-reg: add irq mapping for gpio-reg users
Add support for mapping gpio-reg gpios to interrupts. This may be a non-linear mapping - some gpios in the register may not even have corresponding interrupts associated with them, so we need to pass an array. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 380639c commit 0e3cb6e

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

drivers/gpio/gpio-reg.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ struct gpio_reg {
1919
u32 direction;
2020
u32 out;
2121
void __iomem *reg;
22+
struct irq_domain *irqdomain;
23+
const int *irqs;
2224
};
2325

2426
#define to_gpio_reg(x) container_of(x, struct gpio_reg, gc)
@@ -96,6 +98,17 @@ static void gpio_reg_set_multiple(struct gpio_chip *gc, unsigned long *mask,
9698
spin_unlock_irqrestore(&r->lock, flags);
9799
}
98100

101+
static int gpio_reg_to_irq(struct gpio_chip *gc, unsigned offset)
102+
{
103+
struct gpio_reg *r = to_gpio_reg(gc);
104+
int irq = r->irqs[offset];
105+
106+
if (irq >= 0 && r->irqdomain)
107+
irq = irq_find_mapping(r->irqdomain, irq);
108+
109+
return irq;
110+
}
111+
99112
/**
100113
* gpio_reg_init - add a fixed in/out register as gpio
101114
* @dev: optional struct device associated with this register
@@ -104,7 +117,12 @@ static void gpio_reg_set_multiple(struct gpio_chip *gc, unsigned long *mask,
104117
* @label: GPIO chip label
105118
* @direction: bitmask of fixed direction, one per GPIO signal, 1 = in
106119
* @def_out: initial GPIO output value
107-
* @names: array of %num strings describing each GPIO signal
120+
* @names: array of %num strings describing each GPIO signal or %NULL
121+
* @irqdom: irq domain or %NULL
122+
* @irqs: array of %num ints describing the interrupt mapping for each
123+
* GPIO signal, or %NULL. If @irqdom is %NULL, then this
124+
* describes the Linux interrupt number, otherwise it describes
125+
* the hardware interrupt number in the specified irq domain.
108126
*
109127
* Add a single-register GPIO device containing up to 32 GPIO signals,
110128
* where each GPIO has a fixed input or output configuration. Only
@@ -114,7 +132,7 @@ static void gpio_reg_set_multiple(struct gpio_chip *gc, unsigned long *mask,
114132
*/
115133
struct gpio_chip *gpio_reg_init(struct device *dev, void __iomem *reg,
116134
int base, int num, const char *label, u32 direction, u32 def_out,
117-
const char *const *names)
135+
const char *const *names, struct irq_domain *irqdom, const int *irqs)
118136
{
119137
struct gpio_reg *r;
120138
int ret;
@@ -136,12 +154,15 @@ struct gpio_chip *gpio_reg_init(struct device *dev, void __iomem *reg,
136154
r->gc.set = gpio_reg_set;
137155
r->gc.get = gpio_reg_get;
138156
r->gc.set_multiple = gpio_reg_set_multiple;
157+
if (irqs)
158+
r->gc.to_irq = gpio_reg_to_irq;
139159
r->gc.base = base;
140160
r->gc.ngpio = num;
141161
r->gc.names = names;
142162
r->direction = direction;
143163
r->out = def_out;
144164
r->reg = reg;
165+
r->irqs = irqs;
145166

146167
if (dev)
147168
ret = devm_gpiochip_add_data(dev, &r->gc, r);

include/linux/gpio/gpio-reg.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
#define GPIO_REG_H
33

44
struct device;
5+
struct irq_domain;
56

67
struct gpio_chip *gpio_reg_init(struct device *dev, void __iomem *reg,
78
int base, int num, const char *label, u32 direction, u32 def_out,
8-
const char *const *names);
9+
const char *const *names, struct irq_domain *irqdom, const int *irqs);
910

1011
int gpio_reg_resume(struct gpio_chip *gc);
1112

0 commit comments

Comments
 (0)