aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/gpio
diff options
context:
space:
mode:
authorAlexandre Courbot <acourbot@nvidia.com>2014-02-09 03:43:54 -0500
committerLinus Walleij <linus.walleij@linaro.org>2014-02-12 11:11:35 -0500
commitbb1e88ccb771492ac908ac295ec135efa1d53093 (patch)
treeb8848e3943167f59db95516a0626020f4efbbe71 /include/linux/gpio
parent90df4fe07f9794984bd2dafd1d28acd45318d37f (diff)
gpiolib: add gpiochip_get_desc() driver function
Some drivers dealing with a gpio_chip might need to act on its descriptors directly; one example is pinctrl drivers that need to lock a GPIO for being used as IRQ using gpiod_lock_as_irq(). This patch exports a gpiochip_get_desc() function that returns the GPIO descriptor at the requested index. It also sweeps the gpio_to_chip() function out of the consumer interface since any holder of a gpio_chip reference can manipulate its GPIOs way beyond what a consumer should be allowed to do. As a result, gpio_chip is not visible anymore to simple GPIO consumers. Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com> Reviewed-by: Jean-Jacques Hiblot <jjhiblot@traphandler.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'include/linux/gpio')
-rw-r--r--include/linux/gpio/consumer.h8
-rw-r--r--include/linux/gpio/driver.h18
2 files changed, 18 insertions, 8 deletions
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index 387994325122..dccda505ba7c 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -7,7 +7,6 @@
7#ifdef CONFIG_GPIOLIB 7#ifdef CONFIG_GPIOLIB
8 8
9struct device; 9struct device;
10struct gpio_chip;
11 10
12/** 11/**
13 * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are 12 * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are
@@ -60,7 +59,6 @@ int gpiod_to_irq(const struct gpio_desc *desc);
60/* Convert between the old gpio_ and new gpiod_ interfaces */ 59/* Convert between the old gpio_ and new gpiod_ interfaces */
61struct gpio_desc *gpio_to_desc(unsigned gpio); 60struct gpio_desc *gpio_to_desc(unsigned gpio);
62int desc_to_gpio(const struct gpio_desc *desc); 61int desc_to_gpio(const struct gpio_desc *desc);
63struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc);
64 62
65#else /* CONFIG_GPIOLIB */ 63#else /* CONFIG_GPIOLIB */
66 64
@@ -214,12 +212,6 @@ static inline int desc_to_gpio(const struct gpio_desc *desc)
214 WARN_ON(1); 212 WARN_ON(1);
215 return -EINVAL; 213 return -EINVAL;
216} 214}
217static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc)
218{
219 /* GPIO can never have been requested */
220 WARN_ON(1);
221 return ERR_PTR(-ENODEV);
222}
223 215
224 216
225#endif /* CONFIG_GPIOLIB */ 217#endif /* CONFIG_GPIOLIB */
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index a3e181e09636..9fe283642253 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -10,6 +10,8 @@ struct of_phandle_args;
10struct device_node; 10struct device_node;
11struct seq_file; 11struct seq_file;
12 12
13#ifdef CONFIG_GPIOLIB
14
13/** 15/**
14 * struct gpio_chip - abstract a GPIO controller 16 * struct gpio_chip - abstract a GPIO controller
15 * @label: for diagnostics 17 * @label: for diagnostics
@@ -129,6 +131,11 @@ extern struct gpio_chip *gpiochip_find(void *data,
129int gpiod_lock_as_irq(struct gpio_desc *desc); 131int gpiod_lock_as_irq(struct gpio_desc *desc);
130void gpiod_unlock_as_irq(struct gpio_desc *desc); 132void gpiod_unlock_as_irq(struct gpio_desc *desc);
131 133
134struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc);
135
136struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip,
137 u16 hwnum);
138
132enum gpio_lookup_flags { 139enum gpio_lookup_flags {
133 GPIO_ACTIVE_HIGH = (0 << 0), 140 GPIO_ACTIVE_HIGH = (0 << 0),
134 GPIO_ACTIVE_LOW = (1 << 0), 141 GPIO_ACTIVE_LOW = (1 << 0),
@@ -183,4 +190,15 @@ struct gpiod_lookup_table {
183 190
184void gpiod_add_lookup_table(struct gpiod_lookup_table *table); 191void gpiod_add_lookup_table(struct gpiod_lookup_table *table);
185 192
193#else /* CONFIG_GPIOLIB */
194
195static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc)
196{
197 /* GPIO can never have been requested */
198 WARN_ON(1);
199 return ERR_PTR(-ENODEV);
200}
201
202#endif /* CONFIG_GPIOLIB */
203
186#endif 204#endif