From 7450790558f3b1f85e9a11df252dd27f1047bfeb Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Wed, 5 Aug 2020 15:27:11 -0700 Subject: gpio: Pull down HiZ pins after reading tristate GPIO strapping People who know a lot more about electrons and stuff than I do tell me that leaving a HiZ pin floating without a pull resistor may waste power. So if we find a pin to be HiZ when reading tristate strapping GPIOs, we should make sure the internal pull-down is enabled when we're done with it. (For pins that are externally pulled high or low, we should continue to leave the internal pull disabled instead.) Signed-off-by: Julius Werner Change-Id: I1669823c8a7faab536e0441cb4c6cfeb9f696189 Reviewed-on: https://review.coreboot.org/c/coreboot/+/44253 Reviewed-by: Douglas Anderson Reviewed-by: Alexandru Stan Reviewed-by: Furquan Shaikh Reviewed-by: Aaron Durbin Reviewed-by: Angel Pons Tested-by: build bot (Jenkins) --- src/lib/gpio.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/lib/gpio.c') diff --git a/src/lib/gpio.c b/src/lib/gpio.c index 3f3ae60d91..801a3b3b9c 100644 --- a/src/lib/gpio.c +++ b/src/lib/gpio.c @@ -114,6 +114,12 @@ uint32_t _gpio_base3_value(const gpio_t gpio[], int num_gpio, int binary_first) printk(BIOS_DEBUG, "%c ", tristate_char[temp]); result = (result * 3) + temp; + /* Disable pull to avoid wasting power. For HiZ we leave the + pull-down enabled, since letting them float freely back and + forth may waste power in the SoC's GPIO input logic. */ + if (temp != Z) + gpio_input(gpio[index]); + /* * For binary_first we keep track of the normal ternary result * and whether we found any pin that was a Z. We also determine @@ -159,10 +165,6 @@ uint32_t _gpio_base3_value(const gpio_t gpio[], int num_gpio, int binary_first) printk(BIOS_DEBUG, "= %d (%s base3 number system)\n", result, binary_first ? "binary_first" : "standard"); - /* Disable pull up / pull down to conserve power */ - for (index = 0; index < num_gpio; ++index) - gpio_input(gpio[index]); - return result; } -- cgit v1.2.3