[coreboot-gerrit] Patch set updated for coreboot: gpio: Add support for extended binary number system
David Hendricks (dhendrix@chromium.org)
gerrit at coreboot.org
Fri Mar 25 21:11:18 CET 2016
David Hendricks (dhendrix at chromium.org) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/14143
-gerrit
commit c499cad619bfdc7e0b9dc1bacef23b83f5132f38
Author: David Hendricks <dhendrix at chromium.org>
Date: Fri Mar 18 20:23:05 2016 -0700
gpio: Add support for extended binary number system
This adds yet another number system. In it, binary representation is
extended to allow floating/high-Z values to count in the result. A
'Z' value at position N will yield a value of 0 at position N and a
value of 1 at position (1 << N << num_gpio).
For example:
000Z => 0b1_0000
100Z => 0b1_1000
The advantage is that the value is simple to compute and translate
to/from hex. The drawback is that the number space is not contiguous.
BRANCH=none
BUG=none
TEST=stubbed out and tested for a 3-wide raw value, see comments
in gerrit for the full table.
Change-Id: I121e0cac9fa84fcbb261d1d84dcb20cfd49e5518
Signed-off-by: David Hendricks <dhendrix at chromium.org>
---
src/include/gpio.h | 13 +++++++++++++
src/lib/gpio.c | 18 ++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/src/include/gpio.h b/src/include/gpio.h
index 4627e44..0acd5b0 100644
--- a/src/include/gpio.h
+++ b/src/include/gpio.h
@@ -42,6 +42,19 @@ int gpio_base2_value(gpio_t gpio[], int num_gpio);
/*
* Read the value presented by the set of GPIOs, when each pin is interpreted
+ * as a base-2 digit (LOW = 0, HIGH = 1). If a pin is in its Z/floating state
+ * the value becomes (1 << pin_num << num_gpio).
+ *
+ * Caveat: This scheme makes the number space discontinuous. The advantage is
+ * that it's simple to compute and translate to/from hex.
+ *
+ * gpio[]: pin positions to read. gpio[0] is less significant than gpio[1].
+ * num_gpio: number of pins to read.
+ */
+int gpio_base2_ext_value(gpio_t gpio[], int num_gpio);
+
+/*
+ * Read the value presented by the set of GPIOs, when each pin is interpreted
* as a base-3 digit (LOW = 0, HIGH = 1, Z/floating = 2).
* Example: X1 = Z, X2 = 1 -> gpio_base3_value({GPIO(X1), GPIO(X2)}) = 5
* BASE3() from <base3.h> can generate numbers to compare the result to.
diff --git a/src/lib/gpio.c b/src/lib/gpio.c
index 2e34595..78a383a 100644
--- a/src/lib/gpio.c
+++ b/src/lib/gpio.c
@@ -35,6 +35,24 @@ int gpio_base2_value(gpio_t gpio[], int num_gpio)
return result;
}
+int gpio_base2_ext_value(gpio_t gpio[], int num_gpio)
+{
+ int temp, index, result = 0;
+
+ for (index = num_gpio - 1; index >= 0; --index) {
+ temp = gpio_get(gpio[index]);
+ printk(BIOS_DEBUG, "%c ", temp == Z ? 'Z' : temp + 0x30);
+
+ if (temp == Z)
+ result += (1 << index << num_gpio);
+ else
+ result += temp * (1 << index);
+ }
+
+ printk(BIOS_DEBUG, "= 0x%x (extended binary number system)\n", result);
+ return result;
+}
+
int _gpio_base3_value(gpio_t gpio[], int num_gpio, int binary_first)
{
/*
More information about the coreboot-gerrit
mailing list