mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-21 06:31:31 +00:00
gpio: Add a function to obtain a GPIO vector value
We can use GPIOs as binary digits for reading 'strapping' values. Each GPIO is assigned a single bit and can be set high or low on the circuit board. We already have a legacy function for reading these values. Add one that supports driver model. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
This commit is contained in:
parent
740d5d34b1
commit
bbf2478026
2 changed files with 30 additions and 0 deletions
|
@ -577,6 +577,24 @@ int gpio_get_values_as_int(const int *gpio_list)
|
||||||
return vector;
|
return vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int dm_gpio_get_values_as_int(struct gpio_desc *desc_list, int count)
|
||||||
|
{
|
||||||
|
unsigned bitmask = 1;
|
||||||
|
unsigned vector = 0;
|
||||||
|
int ret, i;
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
ret = dm_gpio_get_value(&desc_list[i]);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
else if (ret)
|
||||||
|
vector |= bitmask;
|
||||||
|
bitmask <<= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return vector;
|
||||||
|
}
|
||||||
|
|
||||||
static int _gpio_request_by_name_nodev(const void *blob, int node,
|
static int _gpio_request_by_name_nodev(const void *blob, int node,
|
||||||
const char *list_name, int index,
|
const char *list_name, int index,
|
||||||
struct gpio_desc *desc, int flags,
|
struct gpio_desc *desc, int flags,
|
||||||
|
|
|
@ -359,6 +359,18 @@ int gpio_lookup_name(const char *name, struct udevice **devp,
|
||||||
*/
|
*/
|
||||||
int gpio_get_values_as_int(const int *gpio_list);
|
int gpio_get_values_as_int(const int *gpio_list);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dm_gpio_get_values_as_int() - Turn the values of a list of GPIOs into an int
|
||||||
|
*
|
||||||
|
* This puts the value of the first GPIO into bit 0, the second into bit 1,
|
||||||
|
* etc. then returns the resulting integer.
|
||||||
|
*
|
||||||
|
* @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(struct gpio_desc *desc_list, int count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gpio_claim_vector() - claim a number of GPIOs for input
|
* gpio_claim_vector() - claim a number of GPIOs for input
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue