diff options
author | Ahmad Fatoum <ahmad@a3f.at> | 2021-04-10 12:35:07 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-04-13 07:35:16 +0200 |
commit | 72254b8658dce0efdb1750b315876e78be5d6f07 (patch) | |
tree | 665fbcacaa5b1ed0a080271b7b90a7eaf3b36f12 /include/gpiod.h | |
parent | 45804d9208d786f3efe60403761a13e308d0b989 (diff) | |
download | barebox-72254b8658dce0efdb1750b315876e78be5d6f07.tar.gz |
gpiolib: add Linux-like gpiod_get() helper
Many Linux drivers use [devm_]gpiod_get to get appropriately configured
GPIO descriptors out with little code. Make porting such Linux code
easier by providing a semi-compatible gpiod_get function. Main
differences:
- It returns a gpio index, so it can be passed to any gpio_ function
- It's device-tree only, so it should only be used from drivers
that themselves probe from device tree.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
Link: https://lore.pengutronix.de/20210410103511.2073504-1-ahmad@a3f.at
Diffstat (limited to 'include/gpiod.h')
-rw-r--r-- | include/gpiod.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/include/gpiod.h b/include/gpiod.h new file mode 100644 index 0000000000..c8b2cd47a3 --- /dev/null +++ b/include/gpiod.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __GPIOD_H_ +#define __GPIOD_H_ + +#include <gpio.h> +#include <of_gpio.h> + +/** + * Optional flags that can be passed to one of gpiod_* to configure direction + * and output value. These values cannot be OR'd. + */ +enum gpiod_flags { + GPIOD_ASIS = 0, + GPIOD_IN = GPIOF_IN, + /* + * To change this later to a different logic level (i.e. taking + * active low into account), use gpio_direction_active() + */ + GPIOD_OUT_LOW = GPIOF_OUT_INIT_INACTIVE, + GPIOD_OUT_HIGH = GPIOF_OUT_INIT_ACTIVE, +}; + +/* 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); + +#endif |