diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2022-02-02 23:30:20 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-02-07 08:55:32 +0100 |
commit | 3d8cc9f822224ca3af3055b921cb278950f29228 (patch) | |
tree | 486b1268e492b5fcdab87154b0dc68f572bc3e0f | |
parent | bfa76583c12407d9ef8cf59e02b95297ec19f845 (diff) | |
download | barebox-3d8cc9f822224ca3af3055b921cb278950f29228.tar.gz barebox-3d8cc9f822224ca3af3055b921cb278950f29228.tar.xz |
gpiolib: implement gpiod_set_value
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@pengutronix.de>
Link: https://lore.barebox.org/20220202223023.341817-2-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | include/gpiod.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/include/gpiod.h b/include/gpiod.h index c8b2cd47a3..adac50b4c3 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 |