aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAlexandre Courbot <acourbot@nvidia.com>2013-10-17 13:21:38 -0400
committerLinus Walleij <linus.walleij@linaro.org>2013-10-19 17:24:56 -0400
commitbae48da237fcedd7ad09569025483b988635efb7 (patch)
tree51d82d78acc5e248623dd73d9e5deb2ce4f0e869 /include
parentaf8b6375a8291fe2cf77707f3edec86b98a999cc (diff)
gpiolib: add gpiod_get() and gpiod_put() functions
Add gpiod_get(), gpiod_get_index() and gpiod_put() functions that provide safer management of GPIOs. These functions put the GPIO framework in line with the conventions of other frameworks in the kernel, and help ensure every GPIO is declared properly and valid while it is used. Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/gpio/consumer.h15
-rw-r--r--include/linux/gpio/driver.h56
2 files changed, 71 insertions, 0 deletions
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index 2088eb50421c..4d34dbbbad4d 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -18,6 +18,21 @@ struct gpio_chip;
18 */ 18 */
19struct gpio_desc; 19struct gpio_desc;
20 20
21/* Acquire and dispose GPIOs */
22struct gpio_desc *__must_check gpiod_get(struct device *dev,
23 const char *con_id);
24struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
25 const char *con_id,
26 unsigned int idx);
27void gpiod_put(struct gpio_desc *desc);
28
29struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
30 const char *con_id);
31struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
32 const char *con_id,
33 unsigned int idx);
34void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
35
21int gpiod_get_direction(const struct gpio_desc *desc); 36int gpiod_get_direction(const struct gpio_desc *desc);
22int gpiod_direction_input(struct gpio_desc *desc); 37int gpiod_direction_input(struct gpio_desc *desc);
23int gpiod_direction_output(struct gpio_desc *desc, int value); 38int gpiod_direction_output(struct gpio_desc *desc, int value);
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 5dc172c72f0f..cd9da3885d79 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -124,4 +124,60 @@ extern struct gpio_chip *gpiochip_find(void *data,
124int gpiod_lock_as_irq(struct gpio_desc *desc); 124int gpiod_lock_as_irq(struct gpio_desc *desc);
125void gpiod_unlock_as_irq(struct gpio_desc *desc); 125void gpiod_unlock_as_irq(struct gpio_desc *desc);
126 126
127/**
128 * Lookup table for associating GPIOs to specific devices and functions using
129 * platform data.
130 */
131struct gpiod_lookup {
132 struct list_head list;
133 /*
134 * name of the chip the GPIO belongs to
135 */
136 const char *chip_label;
137 /*
138 * hardware number (i.e. relative to the chip) of the GPIO
139 */
140 u16 chip_hwnum;
141 /*
142 * name of device that can claim this GPIO
143 */
144 const char *dev_id;
145 /*
146 * name of the GPIO from the device's point of view
147 */
148 const char *con_id;
149 /*
150 * index of the GPIO in case several GPIOs share the same name
151 */
152 unsigned int idx;
153 /*
154 * mask of GPIOF_* values
155 */
156 unsigned long flags;
157};
158
159/*
160 * Simple definition of a single GPIO under a con_id
161 */
162#define GPIO_LOOKUP(_chip_label, _chip_hwnum, _dev_id, _con_id, _flags) \
163 GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _dev_id, _con_id, 0, _flags)
164
165/*
166 * Use this macro if you need to have several GPIOs under the same con_id.
167 * Each GPIO needs to use a different index and can be accessed using
168 * gpiod_get_index()
169 */
170#define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _dev_id, _con_id, _idx, \
171 _flags) \
172{ \
173 .chip_label = _chip_label, \
174 .chip_hwnum = _chip_hwnum, \
175 .dev_id = _dev_id, \
176 .con_id = _con_id, \
177 .idx = _idx, \
178 .flags = _flags, \
179}
180
181void gpiod_add_table(struct gpiod_lookup *table, size_t size);
182
127#endif 183#endif