diff options
-rw-r--r-- | board/cr50/rdd.c | 32 | ||||
-rw-r--r-- | chip/g/rbox.c | 29 | ||||
-rw-r--r-- | chip/g/rbox.h | 21 |
3 files changed, 66 insertions, 16 deletions
diff --git a/board/cr50/rdd.c b/board/cr50/rdd.c index 4c67b5f1d2..49bb0297d0 100644 --- a/board/cr50/rdd.c +++ b/board/cr50/rdd.c @@ -333,16 +333,34 @@ static int command_powerbtn(int argc, char **argv) char *e; int ms = 200; - if (argc == 2) { - ms = strtoi(argv[1], &e, 0); - if (*e) + if (argc > 1) { + if (!strcasecmp("pulse", argv[1])) { + if (argc == 3) { + ms = strtoi(argv[2], &e, 0); + if (*e) + return EC_ERROR_PARAM2; + } + + ccprintf("Force %dms power button press\n", ms); + + rbox_powerbtn_press(); + msleep(ms); + rbox_powerbtn_release(); + } else if (!strcasecmp("press", argv[1])) { + rbox_powerbtn_press(); + } else if (!strcasecmp("release", argv[1])) { + rbox_powerbtn_release(); + } else return EC_ERROR_PARAM1; } - ccprintf("Simulating %dms power button press\n", ms); - rbox_press_power_btn(ms); + ccprintf("powerbtn: %s\n", + rbox_powerbtn_override_is_enabled() ? "forced press" : + rbox_powerbtn_is_pressed() ? "pressed\n" : "released\n"); return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(powerbtn, command_powerbtn, - "ms", - "Simulate a power button press"); + "[pulse [ms] | press | release]", + "get/set the state of the power button"); + + diff --git a/chip/g/rbox.c b/chip/g/rbox.c index 9813123a84..dba2438fa9 100644 --- a/chip/g/rbox.c +++ b/chip/g/rbox.c @@ -10,21 +10,36 @@ #define POWER_BUTTON 2 -void rbox_press_power_btn(int ms) -{ - uint8_t val = GREAD_FIELD(RBOX, OVERRIDE_OUTPUT, VAL); +static uint8_t val; - GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, VAL, ~(1 << POWER_BUTTON) & val); - GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, OEN, 1 << POWER_BUTTON); - GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, EN, 1 << POWER_BUTTON); +int rbox_powerbtn_is_pressed(void) +{ + return !GREAD_FIELD(RBOX, CHECK_OUTPUT, PWRB_OUT); +} - msleep(ms); +int rbox_powerbtn_override_is_enabled(void) +{ + return GREAD_FIELD(RBOX, OVERRIDE_OUTPUT, EN) & (1 << POWER_BUTTON); +} +void rbox_powerbtn_release(void) +{ GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, EN, 0); GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, OEN, 0); GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, VAL, val); } +void rbox_powerbtn_press(void) +{ + if (rbox_powerbtn_override_is_enabled()) + return; + + val = GREAD_FIELD(RBOX, OVERRIDE_OUTPUT, VAL); + GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, VAL, ~(1 << POWER_BUTTON) & val); + GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, OEN, 1 << POWER_BUTTON); + GWRITE_FIELD(RBOX, OVERRIDE_OUTPUT, EN, 1 << POWER_BUTTON); +} + static void rbox_release_ec_reset(void) { /* Let the EC go (the RO bootloader asserts it ASAP after POR) */ diff --git a/chip/g/rbox.h b/chip/g/rbox.h index 0d90b2ce25..e327faaf8e 100644 --- a/chip/g/rbox.h +++ b/chip/g/rbox.h @@ -6,6 +6,23 @@ #ifndef __CROS_RBOX_H #define __CROS_RBOX_H -/* Simultate a power button press */ -void rbox_press_power_btn(int ms); +/** + * Return true if the power button output shows it is pressed + */ +int rbox_powerbtn_is_pressed(void); + +/** + * Return true if power button rbox output override is enabled + */ +int rbox_powerbtn_override_is_enabled(void); + +/** + * Disable the output override + */ +void rbox_powerbtn_release(void); + +/** + * Override power button output to force a power button press + */ +void rbox_powerbtn_press(void); #endif /* __CROS_RBOX_H */ |