diff options
author | Michał Barnaś <mb@semihalf.com> | 2021-10-29 17:29:46 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-11-05 19:59:55 +0000 |
commit | d7bf7add1329caf0cbd9c116a54ccb62ea329cb6 (patch) | |
tree | 0f75ca6af961bd3561da84d72493803ab7685acc | |
parent | a311557a3165950a5ef3d0a36e46764ecb428f32 (diff) | |
download | chrome-ec-d7bf7add1329caf0cbd9c116a54ccb62ea329cb6.tar.gz |
zephyr: improve gpio flags conversion
Add support for more flags in functions used to convert gpio
flags between zephyr and cros.
BRANCH=main
BUG=b:173789980
TEST=check if gpios work correctly
Change-Id: I1e72cd2ac72ffe63667e0aa0a9f6e51b90b4172b
Signed-off-by: Michał Barnaś <mb@semihalf.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3262096
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
-rw-r--r-- | zephyr/shim/src/gpio.c | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/zephyr/shim/src/gpio.c b/zephyr/shim/src/gpio.c index 9440b3f3ca..8602c3c876 100644 --- a/zephyr/shim/src/gpio.c +++ b/zephyr/shim/src/gpio.c @@ -247,11 +247,23 @@ void gpio_set_level_verbose(enum console_channel channel, (GPIO_OPEN_DRAIN | GPIO_PULL_UP | GPIO_PULL_DOWN | GPIO_INPUT | \ GPIO_OUTPUT) +#define FLAGS_HANDLED_FROM_ZEPHYR \ + (GPIO_DISCONNECTED | GPIO_OPEN_DRAIN | GPIO_PULL_UP | GPIO_PULL_DOWN | \ + GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH | GPIO_INPUT | \ + GPIO_OUTPUT | GPIO_INT_ENABLE | GPIO_INT_EDGE | GPIO_INT_HIGH_1 | \ + GPIO_INT_LOW_0 | GPIO_VOLTAGE_1P8) + +#define FLAGS_HANDLED_TO_ZEPHYR \ + (GPIO_FLAG_NONE | GPIO_OPEN_DRAIN | GPIO_PULL_UP | GPIO_PULL_DOWN | \ + GPIO_LOW | GPIO_HIGH | GPIO_INPUT | GPIO_OUTPUT | GPIO_INT_F_RISING | \ + GPIO_INT_F_FALLING | GPIO_INT_F_LOW | GPIO_INT_F_HIGH | \ + GPIO_SEL_1P8V) + static int convert_from_zephyr_flags(const gpio_flags_t zephyr) { /* Start out with the bits that are the same. */ int ec_flags = zephyr & GPIO_CONVERSION_SAME_BITS; - gpio_flags_t unhandled_flags = zephyr & ~GPIO_CONVERSION_SAME_BITS; + gpio_flags_t unhandled_flags = zephyr & (~FLAGS_HANDLED_FROM_ZEPHYR); /* TODO(b/173789980): handle conversion of more bits? */ if (unhandled_flags) { @@ -259,6 +271,30 @@ static int convert_from_zephyr_flags(const gpio_flags_t zephyr) unhandled_flags); } + if (zephyr & GPIO_DISCONNECTED) + ec_flags |= GPIO_FLAG_NONE; + if (zephyr & GPIO_OUTPUT_INIT_LOW) + ec_flags |= GPIO_LOW; + if (zephyr & GPIO_OUTPUT_INIT_HIGH) + ec_flags |= GPIO_HIGH; + + if (zephyr & GPIO_INT_ENABLE) { + if (zephyr & GPIO_INT_EDGE) { + if (zephyr & GPIO_INT_HIGH_1) + ec_flags |= GPIO_INT_F_RISING; + if (zephyr & GPIO_INT_LOW_0) + ec_flags |= GPIO_INT_F_FALLING; + } else { + if (zephyr & GPIO_INT_LOW_0) + ec_flags |= GPIO_INT_F_LOW; + if (zephyr & GPIO_INT_HIGH_1) + ec_flags |= GPIO_INT_F_HIGH; + } + } + + if (zephyr & GPIO_VOLTAGE_1P8) + ec_flags |= GPIO_SEL_1P8V; + return ec_flags; } @@ -266,7 +302,7 @@ static gpio_flags_t convert_to_zephyr_flags(int ec_flags) { /* Start out with the bits that are the same. */ gpio_flags_t zephyr_flags = ec_flags & GPIO_CONVERSION_SAME_BITS; - int unhandled_flags = ec_flags & ~GPIO_CONVERSION_SAME_BITS; + int unhandled_flags = ec_flags & (~FLAGS_HANDLED_TO_ZEPHYR); /* TODO(b/173789980): handle conversion of more bits? */ if (unhandled_flags) { @@ -274,6 +310,25 @@ static gpio_flags_t convert_to_zephyr_flags(int ec_flags) unhandled_flags); } + if (ec_flags & GPIO_FLAG_NONE) + zephyr_flags |= GPIO_DISCONNECTED; + if (ec_flags & GPIO_LOW) + zephyr_flags |= GPIO_OUTPUT_INIT_LOW; + if (ec_flags & GPIO_HIGH) + zephyr_flags |= GPIO_OUTPUT_INIT_HIGH; + if (ec_flags & GPIO_INT_F_RISING) + zephyr_flags |= GPIO_INT_ENABLE + | GPIO_INT_EDGE | GPIO_INT_HIGH_1; + if (ec_flags & GPIO_INT_F_FALLING) + zephyr_flags |= GPIO_INT_ENABLE + | GPIO_INT_EDGE | GPIO_INT_LOW_0; + if (ec_flags & GPIO_INT_F_LOW) + zephyr_flags |= GPIO_INT_ENABLE | GPIO_INT_LOW_0; + if (ec_flags & GPIO_INT_F_HIGH) + zephyr_flags |= GPIO_INT_ENABLE | GPIO_INT_HIGH_1; + if (ec_flags & GPIO_SEL_1P8V) + zephyr_flags |= GPIO_VOLTAGE_1P8; + return zephyr_flags; } |