From 21db62eb0e900b031cf7398149a76a3dfa6ceb5f Mon Sep 17 00:00:00 2001 From: David Hendricks Date: Thu, 6 Nov 2014 15:05:35 -0800 Subject: gpio: add a function to read GPIO array as base-2 value This adds gpio_base2_value() which reads an array of 2-state GPIOs and returns a base-2 value, where gpio[0] represents the least significant bit. BUG=none BRANCH=none TEST=tested with follow-up patches for pinky Change-Id: I0d6bfac369da0d68079a38de0988c7b59d269a97 Signed-off-by: Patrick Georgi Original-Commit-Id: 27873b7a9ea237d13f0cbafd10033a8d0f821cbe Original-Change-Id: Ia7ffc16eb60e93413c0812573b9cf0999b92828e Original-Signed-off-by: David Hendricks Original-Reviewed-on: https://chromium-review.googlesource.com/228323 Original-Reviewed-by: Julius Werner Reviewed-on: http://review.coreboot.org/9412 Tested-by: build bot (Jenkins) Reviewed-by: David Hendricks --- src/lib/gpio.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/lib') diff --git a/src/lib/gpio.c b/src/lib/gpio.c index 3a646e0d1d..0875538bae 100644 --- a/src/lib/gpio.c +++ b/src/lib/gpio.c @@ -22,6 +22,18 @@ #include #include +int gpio_base2_value(gpio_t gpio[], int num_gpio) +{ + int i, result = 0; + + for (i = 0; i < num_gpio; i++) { + gpio_input(gpio[i]); + result |= gpio_get(gpio[i]) << i; + } + + return result; +} + int gpio_base3_value(gpio_t gpio[], int num_gpio) { /* -- cgit v1.2.3