diff options
author | Inochi Amaoto <inochiama@outlook.com> | 2024-05-23 13:07:45 +0800 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2024-05-23 15:42:52 +0530 |
commit | d962db280725b03a0340e05a07e4c85c93f35bc5 (patch) | |
tree | 7c7988fd57cfeccab2023d2ac84563ae055e842b | |
parent | ae5ef1848d8404e1acdaed5dc460dd1bf2d33140 (diff) | |
download | opensbi-d962db280725b03a0340e05a07e4c85c93f35bc5.zip opensbi-d962db280725b03a0340e05a07e4c85c93f35bc5.tar.gz opensbi-d962db280725b03a0340e05a07e4c85c93f35bc5.tar.bz2 |
lib: utils/gpio: respect flag GPIO_FLAG_ACTIVE_LOW
"gpio-poweroff" and "gpio-restart" always set gpio to high to
active the function, but some chips need a low signal to active.
Fortunately, it can be achieved by setting GPIO_FLAG_ACTIVE_LOW
for the gpio. Implement this flag support for the gpio library
so the gpio reset can function well.
Signed-off-by: Inochi Amaoto <inochiama@outlook.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
-rw-r--r-- | lib/utils/gpio/gpio.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/utils/gpio/gpio.c b/lib/utils/gpio/gpio.c index 3a3a6b2..6ffe929 100644 --- a/lib/utils/gpio/gpio.c +++ b/lib/utils/gpio/gpio.c @@ -73,17 +73,26 @@ int gpio_direction_output(struct gpio_pin *gp, int value) if (!gp->chip->direction_output) return SBI_ENOSYS; + if (gp->flags & GPIO_FLAG_ACTIVE_LOW) + value = value == 0 ? 1 : 0; + return gp->chip->direction_output(gp, value); } int gpio_get(struct gpio_pin *gp) { + int value; + if (!gp || !gp->chip || (gp->chip->ngpio <= gp->offset)) return SBI_EINVAL; if (!gp->chip->get) return SBI_ENOSYS; - return gp->chip->get(gp); + value = gp->chip->get(gp); + + if (gp->flags & GPIO_FLAG_ACTIVE_LOW) + value = value == 0 ? 1 : 0; + return value; } int gpio_set(struct gpio_pin *gp, int value) @@ -93,6 +102,9 @@ int gpio_set(struct gpio_pin *gp, int value) if (!gp->chip->set) return SBI_ENOSYS; + if (gp->flags & GPIO_FLAG_ACTIVE_LOW) + value = value == 0 ? 1 : 0; + gp->chip->set(gp, value); return 0; } |