diff options
author | Simon Glass <sjg@chromium.org> | 2014-11-10 18:00:21 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2014-11-21 07:24:11 +0100 |
commit | e5901c94e32b3533c35511d1acfb7f1587e324ee (patch) | |
tree | 6dc5d86c7f55b0ac45e60bb3b019ceec02db59ec /drivers | |
parent | 469a579df2907a421afec06e37d50e61b7d80227 (diff) | |
download | u-boot-imx-e5901c94e32b3533c35511d1acfb7f1587e324ee.zip u-boot-imx-e5901c94e32b3533c35511d1acfb7f1587e324ee.tar.gz u-boot-imx-e5901c94e32b3533c35511d1acfb7f1587e324ee.tar.bz2 |
dm: gpio: Add a function to read an ID from a list of GPIOs
For board IDs a common approach is to set aside several GPIOs for use in
determining the board ID. This can provide information about board features
and the revision.
Add a function that turns a list of GPIOs into an integer by assigning
each GPIO to a single bit.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gpio/gpio-uclass.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index 45e9a5a..255700a 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -390,6 +390,25 @@ int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize) return 0; } +/* + * get a number comprised of multiple GPIO values. gpio_num_array points to + * the array of gpio pin numbers to scan, terminated by -1. + */ +unsigned gpio_get_values_as_int(const int *gpio_num_array) +{ + int gpio; + unsigned bitmask = 1; + unsigned vector = 0; + + while (bitmask && + ((gpio = *gpio_num_array++) != -1)) { + if (gpio_get_value(gpio)) + vector |= bitmask; + bitmask <<= 1; + } + return vector; +} + /* We need to renumber the GPIOs when any driver is probed/removed */ static int gpio_renumber(struct udevice *removed_dev) { |