[PATCH 1/4] gpiolib: implement gpiod_set_value
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Jan 31 00:02:59 PST 2022
Linux gpiod_set_value is silent if the GPIO descriptor is NULL, but
barebox warns about it. Also having gpio_set_value not respect active
low/high, while Linux gpiod_set_value respects it is error-prone.
Add a new gpiod_set_value function that covers this. gpio == -ENOENT is
taken as the dummy value for optional GPIOs.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
include/gpiod.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/include/gpiod.h b/include/gpiod.h
index c8b2cd47a3cb..adac50b4c36d 100644
--- a/include/gpiod.h
+++ b/include/gpiod.h
@@ -14,7 +14,7 @@ enum gpiod_flags {
GPIOD_IN = GPIOF_IN,
/*
* To change this later to a different logic level (i.e. taking
- * active low into account), use gpio_direction_active()
+ * active low into account), use gpiod_set_value()
*/
GPIOD_OUT_LOW = GPIOF_OUT_INIT_INACTIVE,
GPIOD_OUT_HIGH = GPIOF_OUT_INIT_ACTIVE,
@@ -23,4 +23,10 @@ enum gpiod_flags {
/* returned gpio descriptor can be passed to any normal gpio_* function */
int gpiod_get(struct device_d *dev, const char *_con_id, enum gpiod_flags flags);
+static inline void gpiod_set_value(unsigned gpio, bool value)
+{
+ if (gpio != -ENOENT)
+ gpio_direction_active(gpio, value);
+}
+
#endif
--
2.30.2
More information about the barebox
mailing list