aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/gpio.txt5
-rw-r--r--drivers/gpio/gpiolib.c18
-rw-r--r--include/asm-generic/gpio.h7
3 files changed, 28 insertions, 2 deletions
diff --git a/Documentation/gpio.txt b/Documentation/gpio.txt
index 18022e249c53..8a7c45956d24 100644
--- a/Documentation/gpio.txt
+++ b/Documentation/gpio.txt
@@ -264,7 +264,7 @@ map between them using calls like:
264 /* map GPIO numbers to IRQ numbers */ 264 /* map GPIO numbers to IRQ numbers */
265 int gpio_to_irq(unsigned gpio); 265 int gpio_to_irq(unsigned gpio);
266 266
267 /* map IRQ numbers to GPIO numbers */ 267 /* map IRQ numbers to GPIO numbers (avoid using this) */
268 int irq_to_gpio(unsigned irq); 268 int irq_to_gpio(unsigned irq);
269 269
270Those return either the corresponding number in the other namespace, or 270Those return either the corresponding number in the other namespace, or
@@ -284,7 +284,8 @@ system wakeup capabilities.
284 284
285Non-error values returned from irq_to_gpio() would most commonly be used 285Non-error values returned from irq_to_gpio() would most commonly be used
286with gpio_get_value(), for example to initialize or update driver state 286with gpio_get_value(), for example to initialize or update driver state
287when the IRQ is edge-triggered. 287when the IRQ is edge-triggered. Note that some platforms don't support
288this reverse mapping, so you should avoid using it.
288 289
289 290
290Emulating Open Drain Signals 291Emulating Open Drain Signals
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 317004fd94fb..29a7e6b1be5d 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1010,6 +1010,24 @@ int __gpio_cansleep(unsigned gpio)
1010} 1010}
1011EXPORT_SYMBOL_GPL(__gpio_cansleep); 1011EXPORT_SYMBOL_GPL(__gpio_cansleep);
1012 1012
1013/**
1014 * __gpio_to_irq() - return the IRQ corresponding to a GPIO
1015 * @gpio: gpio whose IRQ will be returned (already requested)
1016 * Context: any
1017 *
1018 * This is used directly or indirectly to implement gpio_to_irq().
1019 * It returns the number of the IRQ signaled by this (input) GPIO,
1020 * or a negative errno.
1021 */
1022int __gpio_to_irq(unsigned gpio)
1023{
1024 struct gpio_chip *chip;
1025
1026 chip = gpio_to_chip(gpio);
1027 return chip->to_irq ? chip->to_irq(chip, gpio - chip->base) : -ENXIO;
1028}
1029EXPORT_SYMBOL_GPL(__gpio_to_irq);
1030
1013 1031
1014 1032
1015/* There's no value in making it easy to inline GPIO calls that may sleep. 1033/* There's no value in making it easy to inline GPIO calls that may sleep.
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 2c5744b66dec..04cb1d175df1 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -40,6 +40,8 @@ struct module;
40 * returns either the value actually sensed, or zero 40 * returns either the value actually sensed, or zero
41 * @direction_output: configures signal "offset" as output, or returns error 41 * @direction_output: configures signal "offset" as output, or returns error
42 * @set: assigns output value for signal "offset" 42 * @set: assigns output value for signal "offset"
43 * @to_irq: optional hook supporting non-static gpio_to_irq() mappings;
44 * implementation may not sleep
43 * @dbg_show: optional routine to show contents in debugfs; default code 45 * @dbg_show: optional routine to show contents in debugfs; default code
44 * will be used when this is omitted, but custom code can show extra 46 * will be used when this is omitted, but custom code can show extra
45 * state (such as pullup/pulldown configuration). 47 * state (such as pullup/pulldown configuration).
@@ -73,6 +75,10 @@ struct gpio_chip {
73 unsigned offset, int value); 75 unsigned offset, int value);
74 void (*set)(struct gpio_chip *chip, 76 void (*set)(struct gpio_chip *chip,
75 unsigned offset, int value); 77 unsigned offset, int value);
78
79 int (*to_irq)(struct gpio_chip *chip,
80 unsigned offset);
81
76 void (*dbg_show)(struct seq_file *s, 82 void (*dbg_show)(struct seq_file *s,
77 struct gpio_chip *chip); 83 struct gpio_chip *chip);
78 int base; 84 int base;
@@ -112,6 +118,7 @@ extern void __gpio_set_value(unsigned gpio, int value);
112 118
113extern int __gpio_cansleep(unsigned gpio); 119extern int __gpio_cansleep(unsigned gpio);
114 120
121extern int __gpio_to_irq(unsigned gpio);
115 122
116#ifdef CONFIG_GPIO_SYSFS 123#ifdef CONFIG_GPIO_SYSFS
117 124