From ae0fb762a2b0592a9734120bd14e0b7a98af9d31 Mon Sep 17 00:00:00 2001 From: Joel Kitching Date: Sun, 7 Apr 2019 00:37:14 +0800 Subject: chromeos: clean up "recovery" and "write protect" GPIOs The "write protect" GPIO's cached value is never actually read after entering depthcharge. Ensure the value from get_write_protect_state() is being transferred accurately, so that we may read this GPIO value in depthcharge without resampling. The cached value of the "recovery" GPIO is read only on certain boards which have a physical recovery switch. Correct some of the values sent to boards which presumably never read the previously incorrect value. Most of these inaccuracies are from non-inverted values on ACTIVE_LOW GPIOs. BUG=b:124141368, b:124192753, chromium:950273 TEST=make clean && make test-abuild BRANCH=none Change-Id: Ic17a98768703d7098480a9233b752fe5b201bd51 Signed-off-by: Joel Kitching Reviewed-on: https://review.coreboot.org/c/coreboot/+/32233 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- src/mainboard/google/auron/chromeos.c | 3 ++- src/mainboard/google/beltino/chromeos.c | 5 +++-- src/mainboard/google/cheza/chromeos.c | 2 +- src/mainboard/google/daisy/chromeos.c | 2 +- src/mainboard/google/foster/chromeos.c | 2 +- src/mainboard/google/gale/chromeos.c | 19 ++++++++----------- src/mainboard/google/gru/chromeos.c | 7 +++---- src/mainboard/google/jecht/chromeos.c | 4 ++-- src/mainboard/google/nyan/chromeos.c | 3 ++- src/mainboard/google/nyan_big/chromeos.c | 3 ++- src/mainboard/google/nyan_blaze/chromeos.c | 3 ++- src/mainboard/google/oak/chromeos.c | 2 +- src/mainboard/google/peach_pit/chromeos.c | 2 +- src/mainboard/google/sarien/chromeos.c | 2 +- src/mainboard/google/slippy/chromeos.c | 2 +- src/mainboard/google/smaug/chromeos.c | 2 +- src/mainboard/google/storm/chromeos.c | 14 ++++++-------- src/mainboard/google/veyron/chromeos.c | 5 +++-- src/mainboard/google/veyron_mickey/chromeos.c | 5 +++-- src/mainboard/google/veyron_rialto/chromeos.c | 3 ++- 20 files changed, 46 insertions(+), 44 deletions(-) (limited to 'src/mainboard/google') diff --git a/src/mainboard/google/auron/chromeos.c b/src/mainboard/google/auron/chromeos.c index c27ad9e164..942e9dd8db 100644 --- a/src/mainboard/google/auron/chromeos.c +++ b/src/mainboard/google/auron/chromeos.c @@ -25,7 +25,8 @@ void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { - {CROS_WP_GPIO, ACTIVE_HIGH, 0, "write protect"}, + {CROS_WP_GPIO, ACTIVE_HIGH, get_write_protect_state(), + "write protect"}, {-1, ACTIVE_HIGH, get_recovery_mode_switch(), "recovery"}, {-1, ACTIVE_HIGH, get_lid_switch(), "lid"}, {-1, ACTIVE_HIGH, 0, "power"}, diff --git a/src/mainboard/google/beltino/chromeos.c b/src/mainboard/google/beltino/chromeos.c index 1a1d0a29dc..92bb7b445a 100644 --- a/src/mainboard/google/beltino/chromeos.c +++ b/src/mainboard/google/beltino/chromeos.c @@ -33,9 +33,10 @@ void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { - {GPIO_SPI_WP, ACTIVE_HIGH, 0, "write protect"}, + {GPIO_SPI_WP, ACTIVE_HIGH, + get_write_protect_state(), "write protect"}, {GPIO_REC_MODE, ACTIVE_LOW, - get_recovery_mode_switch(), "recovery"}, + !get_recovery_mode_switch(), "recovery"}, {-1, ACTIVE_HIGH, 1, "lid"}, {-1, ACTIVE_HIGH, 0, "power"}, {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"}, diff --git a/src/mainboard/google/cheza/chromeos.c b/src/mainboard/google/cheza/chromeos.c index 1c2c4f5c5f..e84061352e 100644 --- a/src/mainboard/google/cheza/chromeos.c +++ b/src/mainboard/google/cheza/chromeos.c @@ -38,7 +38,7 @@ void fill_lb_gpios(struct lb_gpios *gpios) "EC in RW"}, {GPIO_AP_EC_INT.addr, ACTIVE_LOW, gpio_get(GPIO_AP_EC_INT), "EC interrupt"}, - {GPIO_WP_STATE.addr, ACTIVE_LOW, gpio_get(GPIO_WP_STATE), + {GPIO_WP_STATE.addr, ACTIVE_LOW, !get_write_protect_state(), "write protect"}, {GPIO_H1_AP_INT.addr, ACTIVE_LOW, gpio_get(GPIO_H1_AP_INT), "TPM interrupt"}, diff --git a/src/mainboard/google/daisy/chromeos.c b/src/mainboard/google/daisy/chromeos.c index 65139bb1ad..c06f8394eb 100644 --- a/src/mainboard/google/daisy/chromeos.c +++ b/src/mainboard/google/daisy/chromeos.c @@ -27,7 +27,7 @@ void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { /* Write Protect: active low (WP_GPIO) */ - {EXYNOS5_GPD1, ACTIVE_LOW, gpio_get_value(GPIO_D16), + {EXYNOS5_GPD1, ACTIVE_LOW, !get_write_protect_state(), "write protect"}, /* Recovery: active low */ diff --git a/src/mainboard/google/foster/chromeos.c b/src/mainboard/google/foster/chromeos.c index 024fd4ce7e..026dd3e5dd 100644 --- a/src/mainboard/google/foster/chromeos.c +++ b/src/mainboard/google/foster/chromeos.c @@ -27,7 +27,7 @@ void fill_lb_gpios(struct lb_gpios *gpios) /* TBD(twarren@nvidia.com): Any analogs for these on Foster-FFD? */ struct lb_gpio chromeos_gpios[] = { /* Write Protect: active low */ - {-1, ACTIVE_LOW, get_write_protect_state(), "write protect"}, + {-1, ACTIVE_LOW, !get_write_protect_state(), "write protect"}, /* Recovery: active high */ {-1, ACTIVE_HIGH, get_recovery_mode_switch(), "recovery"}, diff --git a/src/mainboard/google/gale/chromeos.c b/src/mainboard/google/gale/chromeos.c index 66b1a62ea4..69c3a7a3c7 100644 --- a/src/mainboard/google/gale/chromeos.c +++ b/src/mainboard/google/gale/chromeos.c @@ -25,9 +25,6 @@ #include #define PP_SW 41 -#define PP_POL ACTIVE_LOW -#define REC_POL ACTIVE_LOW -#define WP_POL ACTIVE_LOW static int get_rec_sw_gpio_pin(void) { @@ -70,11 +67,11 @@ static int read_gpio(gpio_t gpio_num) void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { - {PP_SW, PP_POL, read_gpio(PP_SW), "presence"}, - {get_rec_sw_gpio_pin(), REC_POL, + {PP_SW, ACTIVE_LOW, read_gpio(PP_SW), "presence"}, + {get_rec_sw_gpio_pin(), ACTIVE_LOW, read_gpio(get_rec_sw_gpio_pin()), "recovery"}, - {get_wp_status_gpio_pin(), WP_POL, - read_gpio(get_wp_status_gpio_pin()), "write protect"}, + {get_wp_status_gpio_pin(), ACTIVE_LOW, + !get_write_protect_state(), "write protect"}, {-1, ACTIVE_LOW, 1, "power"}, {-1, ACTIVE_LOW, 0, "lid"}, }; @@ -119,7 +116,7 @@ static enum switch_state get_switch_state(void) return saved_state; rec_sw = get_rec_sw_gpio_pin(); - sampled_value = read_gpio(rec_sw) ^ !REC_POL; + sampled_value = !read_gpio(rec_sw); if (!sampled_value) { saved_state = no_req; @@ -133,7 +130,7 @@ static enum switch_state get_switch_state(void) stopwatch_init_msecs_expire(&sw, WIPEOUT_MODE_DELAY_MS); do { - sampled_value = read_gpio(rec_sw) ^ !REC_POL; + sampled_value = !read_gpio(rec_sw); if (!sampled_value) break; } while (!stopwatch_expired(&sw)); @@ -143,7 +140,7 @@ static enum switch_state get_switch_state(void) printk(BIOS_INFO, "wipeout requested, checking recovery\n"); stopwatch_init_msecs_expire(&sw, RECOVERY_MODE_EXTRA_DELAY_MS); do { - sampled_value = read_gpio(rec_sw) ^ !REC_POL; + sampled_value = !read_gpio(rec_sw); if (!sampled_value) break; } while (!stopwatch_expired(&sw)); @@ -175,5 +172,5 @@ int get_wipeout_mode_switch(void) int get_write_protect_state(void) { - return read_gpio(get_wp_status_gpio_pin()) ^ !WP_POL; + return !read_gpio(get_wp_status_gpio_pin()); } diff --git a/src/mainboard/google/gru/chromeos.c b/src/mainboard/google/gru/chromeos.c index a856e45089..53d00fb188 100644 --- a/src/mainboard/google/gru/chromeos.c +++ b/src/mainboard/google/gru/chromeos.c @@ -26,15 +26,14 @@ static const uint32_t wp_polarity = CONFIG(GRU_BASEBOARD_SCARLET) ? int get_write_protect_state(void) { - int raw = gpio_get(GPIO_WP); - return wp_polarity == ACTIVE_HIGH ? raw : !raw; + return gpio_get(GPIO_WP) ^ !wp_polarity; } void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { - {GPIO_WP.raw, wp_polarity, gpio_get(GPIO_WP), - "write protect"}, + {GPIO_WP.raw, wp_polarity, + get_write_protect_state() ^ !wp_polarity, "write protect"}, {-1, ACTIVE_HIGH, get_recovery_mode_switch(), "recovery"}, #if CONFIG(GRU_BASEBOARD_SCARLET) {GPIO_BACKLIGHT.raw, ACTIVE_HIGH, -1, "backlight"}, diff --git a/src/mainboard/google/jecht/chromeos.c b/src/mainboard/google/jecht/chromeos.c index c0b14f3d87..b3215a0ec6 100644 --- a/src/mainboard/google/jecht/chromeos.c +++ b/src/mainboard/google/jecht/chromeos.c @@ -35,9 +35,9 @@ void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { {GPIO_SPI_WP, ACTIVE_HIGH, - get_gpio(GPIO_SPI_WP), "write protect"}, + get_write_protect_state(), "write protect"}, {GPIO_REC_MODE, ACTIVE_LOW, - get_recovery_mode_switch(), "recovery"}, + !get_recovery_mode_switch(), "recovery"}, {-1, ACTIVE_HIGH, 1, "lid"}, {-1, ACTIVE_HIGH, 0, "power"}, {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"}, diff --git a/src/mainboard/google/nyan/chromeos.c b/src/mainboard/google/nyan/chromeos.c index be1b98d3ce..ba851c76c3 100644 --- a/src/mainboard/google/nyan/chromeos.c +++ b/src/mainboard/google/nyan/chromeos.c @@ -20,7 +20,8 @@ void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { - {GPIO(R1), ACTIVE_LOW, gpio_get(GPIO(R1)), "write protect"}, + {GPIO(R1), ACTIVE_LOW, !get_write_protect_state(), + "write protect"}, {-1, ACTIVE_HIGH, get_recovery_mode_switch(), "recovery"}, {GPIO(R4), ACTIVE_HIGH, -1, "lid"}, {GPIO(Q0), ACTIVE_LOW, -1, "power"}, diff --git a/src/mainboard/google/nyan_big/chromeos.c b/src/mainboard/google/nyan_big/chromeos.c index 945a0e743c..f2979989fa 100644 --- a/src/mainboard/google/nyan_big/chromeos.c +++ b/src/mainboard/google/nyan_big/chromeos.c @@ -20,7 +20,8 @@ void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { - {GPIO(R1), ACTIVE_LOW, gpio_get(GPIO(R1)), "write protect"}, + {GPIO(R1), ACTIVE_LOW, + !get_write_protect_state(), "write protect"}, {-1, ACTIVE_HIGH, get_recovery_mode_switch(), "recovery"}, {GPIO(R4), ACTIVE_HIGH, -1, "lid"}, {GPIO(Q0), ACTIVE_LOW, -1, "power"}, diff --git a/src/mainboard/google/nyan_blaze/chromeos.c b/src/mainboard/google/nyan_blaze/chromeos.c index 945a0e743c..dbbd91f1dd 100644 --- a/src/mainboard/google/nyan_blaze/chromeos.c +++ b/src/mainboard/google/nyan_blaze/chromeos.c @@ -20,7 +20,8 @@ void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { - {GPIO(R1), ACTIVE_LOW, gpio_get(GPIO(R1)), "write protect"}, + {GPIO(R1), ACTIVE_LOW, !get_write_protect_state(), + "write protect"}, {-1, ACTIVE_HIGH, get_recovery_mode_switch(), "recovery"}, {GPIO(R4), ACTIVE_HIGH, -1, "lid"}, {GPIO(Q0), ACTIVE_LOW, -1, "power"}, diff --git a/src/mainboard/google/oak/chromeos.c b/src/mainboard/google/oak/chromeos.c index b5d70238a1..4e07236b4c 100644 --- a/src/mainboard/google/oak/chromeos.c +++ b/src/mainboard/google/oak/chromeos.c @@ -35,7 +35,7 @@ void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { {WRITE_PROTECT.id, ACTIVE_LOW, - gpio_get(WRITE_PROTECT), "write protect"}, + !get_write_protect_state(), "write protect"}, {-1, ACTIVE_HIGH, get_recovery_mode_switch(), "recovery"}, {LID.id, ACTIVE_HIGH, -1, "lid"}, {POWER_BUTTON.id, ACTIVE_HIGH, -1, "power"}, diff --git a/src/mainboard/google/peach_pit/chromeos.c b/src/mainboard/google/peach_pit/chromeos.c index f507bd8d6b..00dd1f3987 100644 --- a/src/mainboard/google/peach_pit/chromeos.c +++ b/src/mainboard/google/peach_pit/chromeos.c @@ -27,7 +27,7 @@ void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { /* Write Protect: active low (WP_GPIO) */ - {EXYNOS5_GPX3, ACTIVE_LOW, gpio_get_value(GPIO_X30), + {EXYNOS5_GPX3, ACTIVE_LOW, !get_write_protect_state(), "write protect"}, /* Recovery: active low */ diff --git a/src/mainboard/google/sarien/chromeos.c b/src/mainboard/google/sarien/chromeos.c index 2bef829f83..15670d0d8e 100644 --- a/src/mainboard/google/sarien/chromeos.c +++ b/src/mainboard/google/sarien/chromeos.c @@ -36,7 +36,7 @@ void fill_lb_gpios(struct lb_gpios *gpios) struct lb_gpio chromeos_gpios[] = { {GPIO_PCH_WP, ACTIVE_HIGH, get_write_protect_state(), "write protect"}, - {GPIO_REC_MODE, ACTIVE_LOW, get_recovery_mode_switch(), + {GPIO_REC_MODE, ACTIVE_LOW, !get_recovery_mode_switch(), "recovery"}, {-1, ACTIVE_HIGH, get_lid_switch(), "lid"}, {-1, ACTIVE_HIGH, 0, "power"}, diff --git a/src/mainboard/google/slippy/chromeos.c b/src/mainboard/google/slippy/chromeos.c index 6cae38d442..15779ee965 100644 --- a/src/mainboard/google/slippy/chromeos.c +++ b/src/mainboard/google/slippy/chromeos.c @@ -24,7 +24,7 @@ void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { - {58, ACTIVE_HIGH, 0, "write protect"}, + {58, ACTIVE_HIGH, get_write_protect_state(), "write protect"}, {-1, ACTIVE_HIGH, get_recovery_mode_switch(), "recovery"}, {-1, ACTIVE_HIGH, get_lid_switch(), "lid"}, {-1, ACTIVE_HIGH, 0, "power"}, diff --git a/src/mainboard/google/smaug/chromeos.c b/src/mainboard/google/smaug/chromeos.c index 86e8cb2edb..567a3ae253 100644 --- a/src/mainboard/google/smaug/chromeos.c +++ b/src/mainboard/google/smaug/chromeos.c @@ -22,7 +22,7 @@ void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { {WRITE_PROTECT_L, ACTIVE_LOW, - gpio_get(WRITE_PROTECT_L), "write protect"}, + !get_write_protect_state(), "write protect"}, {-1, ACTIVE_HIGH, get_recovery_mode_switch(), "recovery"}, {POWER_BUTTON, ACTIVE_LOW, -1, "power"}, {EC_IN_RW, ACTIVE_HIGH, -1, "EC in RW"}, diff --git a/src/mainboard/google/storm/chromeos.c b/src/mainboard/google/storm/chromeos.c index b829457890..ccc0b53e02 100644 --- a/src/mainboard/google/storm/chromeos.c +++ b/src/mainboard/google/storm/chromeos.c @@ -25,11 +25,8 @@ #include #define DEV_SW 15 -#define DEV_POL ACTIVE_LOW #define REC_SW 16 -#define REC_POL ACTIVE_LOW #define WP_SW 17 -#define WP_POL ACTIVE_LOW static int read_gpio(gpio_t gpio_num) { @@ -43,7 +40,8 @@ void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { {REC_SW, ACTIVE_LOW, read_gpio(REC_SW), "recovery"}, - {WP_SW, ACTIVE_LOW, read_gpio(WP_SW), "write protect"}, + {WP_SW, ACTIVE_LOW, !get_write_protect_state(), + "write protect"}, {-1, ACTIVE_LOW, 1, "power"}, {-1, ACTIVE_LOW, 0, "lid"}, }; @@ -87,7 +85,7 @@ static enum switch_state get_switch_state(void) if (saved_state != not_probed) return saved_state; - sampled_value = read_gpio(REC_SW) ^ !REC_POL; + sampled_value = !read_gpio(REC_SW); if (!sampled_value) { saved_state = no_req; @@ -101,7 +99,7 @@ static enum switch_state get_switch_state(void) stopwatch_init_msecs_expire(&sw, WIPEOUT_MODE_DELAY_MS); do { - sampled_value = read_gpio(REC_SW) ^ !REC_POL; + sampled_value = !read_gpio(REC_SW); if (!sampled_value) break; } while (!stopwatch_expired(&sw)); @@ -111,7 +109,7 @@ static enum switch_state get_switch_state(void) printk(BIOS_INFO, "wipeout requested, checking recovery\n"); stopwatch_init_msecs_expire(&sw, RECOVERY_MODE_EXTRA_DELAY_MS); do { - sampled_value = read_gpio(REC_SW) ^ !REC_POL; + sampled_value = !read_gpio(REC_SW); if (!sampled_value) break; } while (!stopwatch_expired(&sw)); @@ -143,5 +141,5 @@ int get_wipeout_mode_switch(void) int get_write_protect_state(void) { - return read_gpio(WP_SW) ^ !WP_POL; + return !read_gpio(WP_SW); } diff --git a/src/mainboard/google/veyron/chromeos.c b/src/mainboard/google/veyron/chromeos.c index ac14e37886..357a7fc468 100644 --- a/src/mainboard/google/veyron/chromeos.c +++ b/src/mainboard/google/veyron/chromeos.c @@ -40,9 +40,10 @@ void setup_chromeos_gpios(void) void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { - {GPIO_WP.raw, ACTIVE_LOW, gpio_get(GPIO_WP), "write protect"}, + {GPIO_WP.raw, ACTIVE_LOW, !get_write_protect_state(), + "write protect"}, {GPIO_RECOVERY.raw, ACTIVE_LOW, - get_recovery_mode_switch(), "recovery"}, + !get_recovery_mode_switch(), "recovery"}, {GPIO_LID.raw, ACTIVE_HIGH, -1, "lid"}, {GPIO_POWER.raw, ACTIVE_LOW, -1, "power"}, {GPIO_ECINRW.raw, ACTIVE_HIGH, -1, "EC in RW"}, diff --git a/src/mainboard/google/veyron_mickey/chromeos.c b/src/mainboard/google/veyron_mickey/chromeos.c index c775e48133..46a6738b93 100644 --- a/src/mainboard/google/veyron_mickey/chromeos.c +++ b/src/mainboard/google/veyron_mickey/chromeos.c @@ -31,9 +31,10 @@ void setup_chromeos_gpios(void) void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { - {GPIO_WP.raw, ACTIVE_LOW, gpio_get(GPIO_WP), "write protect"}, + {GPIO_WP.raw, ACTIVE_LOW, + !get_write_protect_state(), "write protect"}, {GPIO_RECOVERY.raw, ACTIVE_LOW, - gpio_get(GPIO_RECOVERY), "recovery"}, + !get_recovery_mode_switch(), "recovery"}, {GPIO_RESET.raw, ACTIVE_HIGH, -1, "reset"}, }; lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios)); diff --git a/src/mainboard/google/veyron_rialto/chromeos.c b/src/mainboard/google/veyron_rialto/chromeos.c index a0ac77edbc..e86d86305f 100644 --- a/src/mainboard/google/veyron_rialto/chromeos.c +++ b/src/mainboard/google/veyron_rialto/chromeos.c @@ -36,7 +36,8 @@ void setup_chromeos_gpios(void) void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { - {GPIO_WP.raw, ACTIVE_LOW, gpio_get(GPIO_WP), "write protect"}, + {GPIO_WP.raw, ACTIVE_LOW, + !get_write_protect_state(), "write protect"}, /* Note for early development, we want to support both servo * and pushkey recovery buttons in firmware boot stages. */ {GPIO_RECOVERY_PUSHKEY.raw, ACTIVE_LOW, -- cgit v1.2.3