Edward O'Callaghan has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/38740 )
Change subject: mainboard/google/{hatch,fizz}: Fix gpio common code TODO ......................................................................
mainboard/google/{hatch,fizz}: Fix gpio common code TODO
This is common gpio code that can come up in other cases as as well. See to fixing the TODO and not let it rot.
BUG=b:147992492 BRANCH=none TEST=none
Change-Id: I6c67f04ae458a0e47f4bb022d744dd8b8a0789ee Signed-off-by: Edward O'Callaghan quasisec@google.com --- M src/include/gpio.h M src/lib/gpio.c M src/mainboard/google/fizz/mainboard.c M src/mainboard/google/hatch/variants/puff/mainboard.c 4 files changed, 34 insertions(+), 46 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/40/38740/1
diff --git a/src/include/gpio.h b/src/include/gpio.h index 0a37ee7..3736f95 100644 --- a/src/include/gpio.h +++ b/src/include/gpio.h @@ -19,6 +19,8 @@ #include <soc/gpio.h> #include <types.h>
+long wait_for_gpio(gpio_t gpio, long timeout); + /* <soc/gpio.h> must typedef a gpio_t that fits in 32 bits. */ _Static_assert(sizeof(gpio_t) <= sizeof(u32), "gpio_t doesn't fit in lb_gpio");
diff --git a/src/lib/gpio.c b/src/lib/gpio.c index 8ea3b5e..578d583 100644 --- a/src/lib/gpio.c +++ b/src/lib/gpio.c @@ -16,6 +16,7 @@ #include <base3.h> #include <console/console.h> #include <delay.h> +#include <timer.h> #include <gpio.h>
static void _check_num(const char *name, int num) @@ -179,6 +180,19 @@ return result; }
+long wait_for_gpio(gpio_t gpio, long timeout) +{ + struct stopwatch sw; + stopwatch_init_msecs_expire(&sw, timeout); + while (!gpio_get(gpio)) { + if (stopwatch_expired(&sw)) { + return -1; + } + mdelay(200); + } + return stopwatch_duration_msecs(&sw); +} + /* Default handler for ACPI path is to return NULL */ __weak const char *gpio_acpi_path(gpio_t gpio) { diff --git a/src/mainboard/google/fizz/mainboard.c b/src/mainboard/google/fizz/mainboard.c index 9397786..527d5b2 100644 --- a/src/mainboard/google/fizz/mainboard.c +++ b/src/mainboard/google/fizz/mainboard.c @@ -238,27 +238,6 @@ #define GPIO_HDMI_HPD GPP_E13 #define GPIO_DP_HPD GPP_E14
-/* TODO: This can be moved to common directory */ -static void wait_for_hpd(gpio_t gpio, long timeout) -{ - struct stopwatch sw; - - printk(BIOS_INFO, "Waiting for HPD\n"); - gpio_input(gpio); - - stopwatch_init_msecs_expire(&sw, timeout); - while (!gpio_get(gpio)) { - if (stopwatch_expired(&sw)) { - printk(BIOS_WARNING, - "HPD not ready after %ldms. Abort.\n", timeout); - return; - } - mdelay(200); - } - printk(BIOS_INFO, "HPD ready after %lu ms\n", - stopwatch_duration_msecs(&sw)); -} - static void mainboard_chip_init(void *chip_info) { const struct pad_config *pads; @@ -270,8 +249,15 @@ gpio_input(GPIO_HDMI_HPD); if (display_init_required() && !gpio_get(GPIO_HDMI_HPD)) { /* This has to be done before FSP-S runs. */ - if (google_chromeec_wait_for_displayport(display_timeout_ms)) - wait_for_hpd(GPIO_DP_HPD, display_timeout_ms); + if (google_chromeec_wait_for_displayport(display_timeout_ms)) { + printk(BIOS_INFO, "Waiting for HPD\n"); + long t = wait_for_gpio(GPIO_DP_HPD, display_timeout_ms); + if (t >= 0) + printk(BIOS_INFO, "HPD ready after %lu ms\n", t); + else + printk(BIOS_WARNING, + "HPD not ready after %ldms. Abort.\n", timeout); + } }
pads = variant_gpio_table(&num); diff --git a/src/mainboard/google/hatch/variants/puff/mainboard.c b/src/mainboard/google/hatch/variants/puff/mainboard.c index 7354ce9..a245f6e 100644 --- a/src/mainboard/google/hatch/variants/puff/mainboard.c +++ b/src/mainboard/google/hatch/variants/puff/mainboard.c @@ -15,34 +15,13 @@
#include <baseboard/variants.h> #include <chip.h> -#include <delay.h> #include <device/device.h> #include <ec/google/chromeec/ec.h> #include <gpio.h> -#include <timer.h>
#define GPIO_HDMI_HPD GPP_E13 #define GPIO_DP_HPD GPP_E14
-/* TODO: This can be moved to common directory */ -static void wait_for_hpd(gpio_t gpio, long timeout) -{ - struct stopwatch sw; - - printk(BIOS_INFO, "Waiting for HPD\n"); - stopwatch_init_msecs_expire(&sw, timeout); - while (!gpio_get(gpio)) { - if (stopwatch_expired(&sw)) { - printk(BIOS_WARNING, - "HPD not ready after %ldms. Abort.\n", timeout); - return; - } - mdelay(200); - } - printk(BIOS_INFO, "HPD ready after %lu ms\n", - stopwatch_duration_msecs(&sw)); -} - void variant_ramstage_init(void) { static const long display_timeout_ms = 3000; @@ -55,8 +34,15 @@ && !gpio_get(GPIO_HDMI_HPD) && !gpio_get(GPIO_DP_HPD)) { /* This has to be done before FSP-S runs. */ - if (google_chromeec_wait_for_displayport(display_timeout_ms)) - wait_for_hpd(GPIO_DP_HPD, display_timeout_ms); + if (google_chromeec_wait_for_displayport(display_timeout_ms)) { + printk(BIOS_INFO, "Waiting for HPD\n"); + long t = wait_for_gpio(GPIO_DP_HPD, display_timeout_ms); + if (t >= 0) + printk(BIOS_INFO, "HPD ready after %lu ms\n", t); + else + printk(BIOS_WARNING, + "HPD not ready after %ldms. Abort.\n", timeout); + } } }