diff options
author | Nicolas Boichat <drinkcat@google.com> | 2017-06-12 08:31:56 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-06-11 23:17:19 -0700 |
commit | 3a8bba3bc3bfa5e52a368c89dd84cc25bea7fb16 (patch) | |
tree | 49569d18741887977fb042d94c375baa291347c5 | |
parent | cabd486cb297cf647458186751facae61137bbc1 (diff) | |
download | chrome-ec-3a8bba3bc3bfa5e52a368c89dd84cc25bea7fb16.tar.gz |
gpio: Move gpio_get_ternary to common gpio functions
Also, convert from usleep to udelay, as the calling site may not
necessarily be in task context.
BRANCH=none
BUG=b:62242438
TEST=make buildall -j
Change-Id: I9f36f0de4259716a92183b28324c90d974a96239
Reviewed-on: https://chromium-review.googlesource.com/530884
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
-rw-r--r-- | board/eve/board.c | 22 | ||||
-rw-r--r-- | common/gpio.c | 23 | ||||
-rw-r--r-- | include/gpio.h | 9 |
3 files changed, 32 insertions, 22 deletions
diff --git a/board/eve/board.c b/board/eve/board.c index 85f82b6932..6ebabead9c 100644 --- a/board/eve/board.c +++ b/board/eve/board.c @@ -685,28 +685,6 @@ void board_hibernate(void) ; } -static int gpio_get_ternary(enum gpio_signal gpio) -{ - int pd, pu; - int flags = gpio_get_default_flags(gpio); - - /* Read GPIO with internal pull-down */ - gpio_set_flags(gpio, GPIO_INPUT | GPIO_PULL_DOWN); - pd = gpio_get_level(gpio); - usleep(100); - - /* Read GPIO with internal pull-up */ - gpio_set_flags(gpio, GPIO_INPUT | GPIO_PULL_UP); - pu = gpio_get_level(gpio); - usleep(100); - - /* Reset GPIO flags */ - gpio_set_flags(gpio, flags); - - /* Check PU and PD readings to determine tristate */ - return pu && !pd ? 2 : pd; -} - int board_get_version(void) { static int ver; diff --git a/common/gpio.c b/common/gpio.c index f4e3cfe2b8..b0200facfd 100644 --- a/common/gpio.c +++ b/common/gpio.c @@ -8,6 +8,7 @@ #include "common.h" #include "gpio.h" #include "registers.h" +#include "timer.h" #include "util.h" /* GPIO alternate function structure */ @@ -145,4 +146,26 @@ int gpio_is_implemented(enum gpio_signal signal) return !!gpio_list[signal].mask; } +int gpio_get_ternary(enum gpio_signal signal) +{ + int pd, pu; + int flags = gpio_get_default_flags(signal); + + /* Read GPIO with internal pull-down */ + gpio_set_flags(signal, GPIO_INPUT | GPIO_PULL_DOWN); + pd = gpio_get_level(signal); + udelay(100); + + /* Read GPIO with internal pull-up */ + gpio_set_flags(signal, GPIO_INPUT | GPIO_PULL_UP); + pu = gpio_get_level(signal); + udelay(100); + + /* Reset GPIO flags */ + gpio_set_flags(signal, flags); + + /* Check PU and PD readings to determine tristate */ + return pu && !pd ? 2 : pd; +} + /*****************************************************************************/ diff --git a/include/gpio.h b/include/gpio.h index d1dad9056a..edffb73156 100644 --- a/include/gpio.h +++ b/include/gpio.h @@ -125,6 +125,15 @@ int gpio_config_pin(enum module_id id, enum gpio_signal signal, int enable); int gpio_get_level(enum gpio_signal signal); /** + * Read a ternary GPIO input, activating internal pull-down, then pull-up, + * to check if the GPIO is high, low, or Hi-Z. Useful for board strappings. + * + * @param signal Signal to get + * @return 0 if low, 1 if high, 2 if Hi-Z. + */ +int gpio_get_ternary(enum gpio_signal signal); + +/** * Return the name of a given GPIO signal. * * @param signal Signal to name |