diff options
author | Simon Glass <sjg@chromium.org> | 2021-02-04 21:22:09 -0700 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-03-03 15:40:47 -0500 |
commit | 8a45b2205749252f61d26508d5de9dcce020b2ef (patch) | |
tree | fac56f635fb7a10236dd41868a0b1629184ab39c /include | |
parent | be04f1ab4291c724a65d86a743b8b7938f15a54c (diff) | |
download | u-boot-8a45b2205749252f61d26508d5de9dcce020b2ef.zip u-boot-8a45b2205749252f61d26508d5de9dcce020b2ef.tar.gz u-boot-8a45b2205749252f61d26508d5de9dcce020b2ef.tar.bz2 |
gpio: Add a way to read 3-way strapping pinsWIP/2021-03-03-gpio-improvements
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 'include')
-rw-r--r-- | include/asm-generic/gpio.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h index f0c835e..2cb0500 100644 --- a/include/asm-generic/gpio.h +++ b/include/asm-generic/gpio.h @@ -498,6 +498,31 @@ int gpio_get_values_as_int(const int *gpio_list); int dm_gpio_get_values_as_int(const struct gpio_desc *desc_list, int count); /** + * dm_gpio_get_values_as_int_base3() - Create a base-3 int from a list of GPIOs + * + * This uses pull-ups/pull-downs to figure out whether a GPIO line is externally + * pulled down, pulled up or floating. This allows three different strap values + * for each pin: + * 0 : external pull-down + * 1 : external pull-up + * 2 : floating + * + * With this it is possible to obtain more combinations from the same number of + * strapping pins, when compared to dm_gpio_get_values_as_int(). The external + * pull resistors should be made stronger that the internal SoC pull resistors, + * for this to work. + * + * With 2 pins, 6 combinations are possible, compared with 4 + * With 3 pins, 27 are possible, compared with 8 + * + * @desc_list: List of GPIOs to collect + * @count: Number of GPIOs + * @return resulting integer value, or -ve on error + */ +int dm_gpio_get_values_as_int_base3(struct gpio_desc *desc_list, + int count); + +/** * gpio_claim_vector() - claim a number of GPIOs for input * * @gpio_num_array: array of gpios to claim, terminated by -1 @@ -726,6 +751,21 @@ int dm_gpio_clrset_flags(struct gpio_desc *desc, ulong clr, ulong set); int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags); /** + * dm_gpios_clrset_flags() - Sets flags for a set of GPIOs + * + * This clears and sets flags individually for each GPIO. + * + * @desc: List of GPIOs to update + * @count: Number of GPIOs in the list + * @clr: Flags to clear (GPIOD_...), e.g. GPIOD_MASK_DIR if you are + * changing the direction + * @set: Flags to set (GPIOD_...) + * @return 0 if OK, -ve on error + */ +int dm_gpios_clrset_flags(struct gpio_desc *desc, int count, ulong clr, + ulong set); + +/** * dm_gpio_get_flags() - Get flags * * Read the current flags |