Patrick Georgi (pgeorgi@google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/9411
-gerrit
commit 80eb57750cec0777eaa33aac76a95b603d057f39 Author: David Hendricks dhendrix@chromium.org Date: Thu Nov 6 15:09:27 2014 -0800
gpio: cosmetic changes to tristate_gpios.c
This patch makes a few cosmetic changes: - Rename tristate_gpios.c to gpio.c since it will soon be used for binary GPIOs as well. - Rename gpio_get_tristates() to gpio_base3_value() - The binary version will be called gpio_base2_value(). - Updates call sites. - Change the variable name "id" to something more generic.
BUG=none BRANCH=none TEST=compiled for veyron_pinky and storm
Change-Id: Iab7e32f4e9d70853f782695cfe6842accff1df64 Signed-off-by: Patrick Georgi pgeorgi@chromium.org Original-Commit-Id: c47d0f33ea1a6e9515211b834009cf47a171953f Original-Change-Id: I36d88c67cb118efd1730278691dc3e4ecb6055ee Original-Signed-off-by: David Hendricks dhendrix@chromium.org Original-Reviewed-on: https://chromium-review.googlesource.com/228324 --- src/include/gpio.h | 4 +- src/lib/Makefile.inc | 2 +- src/lib/gpio.c | 82 +++++++++++++++++++++++++++++++ src/lib/tristate_gpios.c | 82 ------------------------------- src/mainboard/google/nyan_big/boardid.c | 2 +- src/mainboard/google/nyan_blaze/boardid.c | 2 +- src/mainboard/google/rush_ryu/boardid.c | 2 +- src/mainboard/google/storm/boardid.c | 6 +-- 8 files changed, 91 insertions(+), 91 deletions(-)
diff --git a/src/include/gpio.h b/src/include/gpio.h index b2a341d..e54b156 100644 --- a/src/include/gpio.h +++ b/src/include/gpio.h @@ -37,12 +37,12 @@ void gpio_output(gpio_t gpio, int value); /* * 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_get_tristates({GPIO(X1), GPIO(X2)}) = 5 + * 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. * * gpio[]: pin positions to read. gpio[0] is less significant than gpio[1]. * num_gpio: number of pins to read. */ -int gpio_get_tristates(gpio_t gpio[], int num_gpio); +int gpio_base3_value(gpio_t gpio[], int num_gpio);
#endif /* __SRC_INCLUDE_GPIO_H__ */ diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc index e01d347..f0f73f2 100644 --- a/src/lib/Makefile.inc +++ b/src/lib/Makefile.inc @@ -88,7 +88,7 @@ ramstage-$(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT) += edid.c ramstage-y += memrange.c ramstage-$(CONFIG_COOP_MULTITASKING) += thread.c ramstage-$(CONFIG_TIMER_QUEUE) += timer_queue.c -ramstage-$(CONFIG_TERTIARY_BOARD_ID) += tristate_gpios.c +ramstage-$(CONFIG_TERTIARY_BOARD_ID) += gpio.c
romstage-y += cbmem_common.c dynamic_cbmem.c ramstage-y += cbmem_common.c dynamic_cbmem.c diff --git a/src/lib/gpio.c b/src/lib/gpio.c new file mode 100644 index 0000000..3a646e0 --- /dev/null +++ b/src/lib/gpio.c @@ -0,0 +1,82 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2014 Google Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <base3.h> +#include <console/console.h> +#include <delay.h> +#include <gpio.h> + +int gpio_base3_value(gpio_t gpio[], int num_gpio) +{ + /* + * GPIOs which are tied to stronger external pull up or pull down + * will stay there regardless of the internal pull up or pull + * down setting. + * + * GPIOs which are floating will go to whatever level they're + * internally pulled to. + */ + + static const char tristate_char[] = {[0] = '0', [1] = '1', [Z] = 'Z'}; + int temp; + int index; + int result = 0; + char value[num_gpio]; + + /* Enable internal pull up */ + for (index = 0; index < num_gpio; ++index) + gpio_input_pullup(gpio[index]); + + /* Wait until signals become stable */ + udelay(10); + + /* Get gpio values at internal pull up */ + for (index = 0; index < num_gpio; ++index) + value[index] = gpio_get(gpio[index]); + + /* Enable internal pull down */ + for (index = 0; index < num_gpio; ++index) + gpio_input_pulldown(gpio[index]); + + /* Wait until signals become stable */ + udelay(10); + + /* + * Get gpio values at internal pull down. + * Compare with gpio pull up value and then + * determine a gpio final value/state: + * 0: pull down + * 1: pull up + * 2: floating + */ + printk(BIOS_DEBUG, "Reading tristate GPIOs: "); + for (index = num_gpio - 1; index >= 0; --index) { + temp = gpio_get(gpio[index]); + temp |= ((value[index] ^ temp) << 1); + printk(BIOS_DEBUG, "%c ", tristate_char[temp]); + result = (result * 3) + temp; + } + printk(BIOS_DEBUG, "= %d\n", result); + + /* Disable pull up / pull down to conserve power */ + for (index = 0; index < num_gpio; ++index) + gpio_input(gpio[index]); + + return result; +} diff --git a/src/lib/tristate_gpios.c b/src/lib/tristate_gpios.c deleted file mode 100644 index 0967a8f..0000000 --- a/src/lib/tristate_gpios.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This file is part of the coreboot project. - * - * Copyright 2014 Google Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <base3.h> -#include <console/console.h> -#include <delay.h> -#include <gpio.h> - -int gpio_get_tristates(gpio_t gpio[], int num_gpio) -{ - /* - * GPIOs which are tied to stronger external pull up or pull down - * will stay there regardless of the internal pull up or pull - * down setting. - * - * GPIOs which are floating will go to whatever level they're - * internally pulled to. - */ - - static const char tristate_char[] = {[0] = '0', [1] = '1', [Z] = 'Z'}; - int temp; - int index; - int id = 0; - char value[num_gpio]; - - /* Enable internal pull up */ - for (index = 0; index < num_gpio; ++index) - gpio_input_pullup(gpio[index]); - - /* Wait until signals become stable */ - udelay(10); - - /* Get gpio values at internal pull up */ - for (index = 0; index < num_gpio; ++index) - value[index] = gpio_get(gpio[index]); - - /* Enable internal pull down */ - for (index = 0; index < num_gpio; ++index) - gpio_input_pulldown(gpio[index]); - - /* Wait until signals become stable */ - udelay(10); - - /* - * Get gpio values at internal pull down. - * Compare with gpio pull up value and then - * determine a gpio final value/state: - * 0: pull down - * 1: pull up - * 2: floating - */ - printk(BIOS_DEBUG, "Reading tristate GPIOs: "); - for (index = num_gpio - 1; index >= 0; --index) { - temp = gpio_get(gpio[index]); - temp |= ((value[index] ^ temp) << 1); - printk(BIOS_DEBUG, "%c ", tristate_char[temp]); - id = (id * 3) + temp; - } - printk(BIOS_DEBUG, "= %d\n", id); - - /* Disable pull up / pull down to conserve power */ - for (index = 0; index < num_gpio; ++index) - gpio_input(gpio[index]); - - return id; -} diff --git a/src/mainboard/google/nyan_big/boardid.c b/src/mainboard/google/nyan_big/boardid.c index b420f5a..1905c79 100644 --- a/src/mainboard/google/nyan_big/boardid.c +++ b/src/mainboard/google/nyan_big/boardid.c @@ -29,7 +29,7 @@ uint8_t board_id(void) [1] = GPIO(T1), [0] = GPIO(Q3),}; /* Q3 is LSB */
if (id < 0) { - id = gpio_get_tristates(gpio, ARRAY_SIZE(gpio)); + id = gpio_base3_value(gpio, ARRAY_SIZE(gpio));
printk(BIOS_SPEW, "Board TRISTATE ID: %d.\n", id); } diff --git a/src/mainboard/google/nyan_blaze/boardid.c b/src/mainboard/google/nyan_blaze/boardid.c index b420f5a..1905c79 100644 --- a/src/mainboard/google/nyan_blaze/boardid.c +++ b/src/mainboard/google/nyan_blaze/boardid.c @@ -29,7 +29,7 @@ uint8_t board_id(void) [1] = GPIO(T1), [0] = GPIO(Q3),}; /* Q3 is LSB */
if (id < 0) { - id = gpio_get_tristates(gpio, ARRAY_SIZE(gpio)); + id = gpio_base3_value(gpio, ARRAY_SIZE(gpio));
printk(BIOS_SPEW, "Board TRISTATE ID: %d.\n", id); } diff --git a/src/mainboard/google/rush_ryu/boardid.c b/src/mainboard/google/rush_ryu/boardid.c index 37f6292..9c4d184 100644 --- a/src/mainboard/google/rush_ryu/boardid.c +++ b/src/mainboard/google/rush_ryu/boardid.c @@ -30,7 +30,7 @@ uint8_t board_id(void) if (id < 0) { gpio_t gpio[] = {[1] = BD_ID1, [0] = BD_ID0}; /* ID0 is LSB */
- id = gpio_get_tristates(gpio, ARRAY_SIZE(gpio)); + id = gpio_base3_value(gpio, ARRAY_SIZE(gpio)); }
return id; diff --git a/src/mainboard/google/storm/boardid.c b/src/mainboard/google/storm/boardid.c index c32567e..c4f54a5 100644 --- a/src/mainboard/google/storm/boardid.c +++ b/src/mainboard/google/storm/boardid.c @@ -25,8 +25,8 @@ /* * Storm boards dedicate to the board ID three GPIOs in tertiary mode: 29, 30 * and 68. On proto0 GPIO68 is used and tied low, so it reads as 'zero' by - * gpio_get_tristates(), whereas the other two pins are not connected - * and read as 'two'. This results in gpio_get_tristates() returning + * gpio_base3_value(), whereas the other two pins are not connected + * and read as 'two'. This results in gpio_base3_value() returning * 8 on proto0. * * Three tertitiary signals could represent 27 different values. To make @@ -45,7 +45,7 @@ static uint8_t get_board_id(void) gpio_t hw_rev_gpios[] = {[2] = 68, [1] = 30, [0] = 29}; /* 29 is LSB */ int offset = 19;
- bid = gpio_get_tristates(hw_rev_gpios, ARRAY_SIZE(hw_rev_gpios)); + bid = gpio_base3_value(hw_rev_gpios, ARRAY_SIZE(hw_rev_gpios)); bid = (bid + offset) % 27; printk(BIOS_INFO, "Board ID %d\n", bid);