aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/gpio
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2014-04-25 11:10:06 -0400
committerLinus Walleij <linus.walleij@linaro.org>2014-05-09 07:48:30 -0400
commit29a1f2333e07bbbecb920cc78fd035fe8f53207a (patch)
treeb2cb50d4c41ff4d1337cca888da3840f6f0d4d84 /include/linux/gpio
parent91329132c909bbeb27699556b98b7f745ddb2ed9 (diff)
gpio: Add helpers for optional GPIOs
Introduce gpiod_get_optional() and gpiod_get_index_optional() helpers that make it easier for drivers to handle optional GPIOs. Currently in order to handle optional GPIOs, a driver needs to special case error handling for -ENOENT, such as this: gpio = gpiod_get(dev, "foo"); if (IS_ERR(gpio)) { if (PTR_ERR(gpio) != -ENOENT) return PTR_ERR(gpio); gpio = NULL; } if (gpio) { /* set up GPIO */ } With these new helpers the above is reduced to: gpio = gpiod_get_optional(dev, "foo"); if (IS_ERR(gpio)) return PTR_ERR(gpio); if (gpio) { /* set up GPIO */ } While at it, device-managed variants of these functions are also provided. Signed-off-by: Thierry Reding <treding@nvidia.com> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'include/linux/gpio')
-rw-r--r--include/linux/gpio/consumer.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index bed128e8f4b1..6a37ef0dc59c 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -23,6 +23,12 @@ struct gpio_desc *__must_check gpiod_get(struct device *dev,
23struct gpio_desc *__must_check gpiod_get_index(struct device *dev, 23struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
24 const char *con_id, 24 const char *con_id,
25 unsigned int idx); 25 unsigned int idx);
26struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
27 const char *con_id);
28struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
29 const char *con_id,
30 unsigned int index);
31
26void gpiod_put(struct gpio_desc *desc); 32void gpiod_put(struct gpio_desc *desc);
27 33
28struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, 34struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
@@ -30,6 +36,12 @@ struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
30struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, 36struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
31 const char *con_id, 37 const char *con_id,
32 unsigned int idx); 38 unsigned int idx);
39struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
40 const char *con_id);
41struct gpio_desc *__must_check
42devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
43 unsigned int index);
44
33void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); 45void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
34 46
35int gpiod_get_direction(const struct gpio_desc *desc); 47int gpiod_get_direction(const struct gpio_desc *desc);
@@ -73,6 +85,20 @@ static inline struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
73{ 85{
74 return ERR_PTR(-ENOSYS); 86 return ERR_PTR(-ENOSYS);
75} 87}
88
89static inline struct gpio_desc *__must_check
90gpiod_get_optional(struct device *dev, const char *con_id)
91{
92 return ERR_PTR(-ENOSYS);
93}
94
95static inline struct gpio_desc *__must_check
96gpiod_get_index_optional(struct device *dev, const char *con_id,
97 unsigned int index)
98{
99 return ERR_PTR(-ENOSYS);
100}
101
76static inline void gpiod_put(struct gpio_desc *desc) 102static inline void gpiod_put(struct gpio_desc *desc)
77{ 103{
78 might_sleep(); 104 might_sleep();
@@ -93,6 +119,20 @@ struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
93{ 119{
94 return ERR_PTR(-ENOSYS); 120 return ERR_PTR(-ENOSYS);
95} 121}
122
123static inline struct gpio_desc *__must_check
124devm_gpiod_get_optional(struct device *dev, const char *con_id)
125{
126 return ERR_PTR(-ENOSYS);
127}
128
129static inline struct gpio_desc *__must_check
130devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
131 unsigned int index)
132{
133 return ERR_PTR(-ENOSYS);
134}
135
96static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) 136static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
97{ 137{
98 might_sleep(); 138 might_sleep();