Commit 22c40367 authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Linus Walleij

gpio: return NULL from gpiod_get_optional when GPIOLIB is disabled

Given the intent behind gpiod_get_optional() and friends it does not make
sense to return -ENOSYS when GPIOLIB is disabled: the driver is expected to
work just fine without gpio so let's behave as if gpio was not found.
Otherwise we have to special-case -ENOSYS in drivers.

Note that there was objection that someone might forget to enable GPIOLIB
when dealing with a platform that has device that actually specifies
optional gpio and we'll break it. I find this unconvincing as that would
have to be the *only GPIO* in the system, which is extremely unlikely.
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 85c73d50
...@@ -70,6 +70,12 @@ instead of -ENOENT if no GPIO has been assigned to the requested function: ...@@ -70,6 +70,12 @@ instead of -ENOENT if no GPIO has been assigned to the requested function:
unsigned int index, unsigned int index,
enum gpiod_flags flags) enum gpiod_flags flags)
Note that gpio_get*_optional() functions (and their managed variants), unlike
the rest of gpiolib API, also return NULL when gpiolib support is disabled.
This is helpful to driver authors, since they do not need to special case
-ENOSYS return codes. System integrators should however be careful to enable
gpiolib on systems that need it.
For a function using multiple GPIOs all of those can be obtained with one call: For a function using multiple GPIOs all of those can be obtained with one call:
struct gpio_descs *gpiod_get_array(struct device *dev, struct gpio_descs *gpiod_get_array(struct device *dev,
......
...@@ -179,14 +179,14 @@ static inline struct gpio_desc *__must_check ...@@ -179,14 +179,14 @@ static inline struct gpio_desc *__must_check
gpiod_get_optional(struct device *dev, const char *con_id, gpiod_get_optional(struct device *dev, const char *con_id,
enum gpiod_flags flags) enum gpiod_flags flags)
{ {
return ERR_PTR(-ENOSYS); return NULL;
} }
static inline struct gpio_desc *__must_check static inline struct gpio_desc *__must_check
gpiod_get_index_optional(struct device *dev, const char *con_id, gpiod_get_index_optional(struct device *dev, const char *con_id,
unsigned int index, enum gpiod_flags flags) unsigned int index, enum gpiod_flags flags)
{ {
return ERR_PTR(-ENOSYS); return NULL;
} }
static inline struct gpio_descs *__must_check static inline struct gpio_descs *__must_check
...@@ -200,7 +200,7 @@ static inline struct gpio_descs *__must_check ...@@ -200,7 +200,7 @@ static inline struct gpio_descs *__must_check
gpiod_get_array_optional(struct device *dev, const char *con_id, gpiod_get_array_optional(struct device *dev, const char *con_id,
enum gpiod_flags flags) enum gpiod_flags flags)
{ {
return ERR_PTR(-ENOSYS); return NULL;
} }
static inline void gpiod_put(struct gpio_desc *desc) static inline void gpiod_put(struct gpio_desc *desc)
...@@ -240,14 +240,14 @@ static inline struct gpio_desc *__must_check ...@@ -240,14 +240,14 @@ static inline struct gpio_desc *__must_check
devm_gpiod_get_optional(struct device *dev, const char *con_id, devm_gpiod_get_optional(struct device *dev, const char *con_id,
enum gpiod_flags flags) enum gpiod_flags flags)
{ {
return ERR_PTR(-ENOSYS); return NULL;
} }
static inline struct gpio_desc *__must_check static inline struct gpio_desc *__must_check
devm_gpiod_get_index_optional(struct device *dev, const char *con_id, devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
unsigned int index, enum gpiod_flags flags) unsigned int index, enum gpiod_flags flags)
{ {
return ERR_PTR(-ENOSYS); return NULL;
} }
static inline struct gpio_descs *__must_check static inline struct gpio_descs *__must_check
...@@ -261,7 +261,7 @@ static inline struct gpio_descs *__must_check ...@@ -261,7 +261,7 @@ static inline struct gpio_descs *__must_check
devm_gpiod_get_array_optional(struct device *dev, const char *con_id, devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
enum gpiod_flags flags) enum gpiod_flags flags)
{ {
return ERR_PTR(-ENOSYS); return NULL;
} }
static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment