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>
This commit is contained in:
@@ -497,6 +497,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
|
||||
*
|
||||
@@ -725,6 +750,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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user