aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/sandbox.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-02-04 21:22:09 -0700
committerTom Rini <trini@konsulko.com>2021-03-03 15:40:47 -0500
commit8a45b2205749252f61d26508d5de9dcce020b2ef (patch)
treefac56f635fb7a10236dd41868a0b1629184ab39c /drivers/gpio/sandbox.c
parentbe04f1ab4291c724a65d86a743b8b7938f15a54c (diff)
downloadu-boot-8a45b2205749252f61d26508d5de9dcce020b2ef.tar.gz
gpio: Add a way to read 3-way strapping pins
Using the internal vs. external pull resistors it is possible to get 27 different combinations from 3 strapping pins. Add an implementation of this. This involves updating the sandbox GPIO driver to model external and (weaker) internal pull resistors. The get_value() method now takes account of what is driving a pin: sandbox: GPIOD_EXT_DRIVEN - in which case GPIO_EXT_HIGH provides the value outside source - in which case GPIO_EXT_PULL_UP/DOWN indicates the external state and we work the final state using those flags and the internal GPIOD_PULL_UP/DOWN flags Of course the outside source does not really exist in sandbox. We are just modelling it for test purpose. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/gpio/sandbox.c')
-rw-r--r--drivers/gpio/sandbox.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c
index 700098446b5..d008fdd2224 100644
--- a/drivers/gpio/sandbox.c
+++ b/drivers/gpio/sandbox.c
@@ -19,7 +19,6 @@
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/gpio/sandbox-gpio.h>
-
struct gpio_state {
const char *label; /* label given by requester */
ulong flags; /* flags (GPIOD_...) */
@@ -81,10 +80,16 @@ int sandbox_gpio_get_value(struct udevice *dev, unsigned offset)
if (get_gpio_flag(dev, offset, GPIOD_IS_OUT))
debug("sandbox_gpio: get_value on output gpio %u\n", offset);
- if (state->flags & GPIOD_EXT_DRIVEN)
+ if (state->flags & GPIOD_EXT_DRIVEN) {
val = state->flags & GPIOD_EXT_HIGH;
- else
- val = false;
+ } else {
+ if (state->flags & GPIOD_EXT_PULL_UP)
+ val = true;
+ else if (state->flags & GPIOD_EXT_PULL_DOWN)
+ val = false;
+ else
+ val = state->flags & GPIOD_PULL_UP;
+ }
return val;
}