mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-29 10:00:51 +00:00
cr50: add press and release options to powerbtn command
This change adds options to the powerbtn console command to press and release the power button. BUG=chrome-os-partner:58123 BRANCH=none TEST=manual 'powerbtn press' force a power button press 'powerbtn release' release the power button. This will not override the signal if the button is physically pressed. Change-Id: I52631d30dbae874ba6637f728cb6e435cb626e12 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/396207 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
This commit is contained in:
@@ -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");
|
||||
|
||||
|
||||
|
||||
@@ -10,21 +10,36 @@
|
||||
|
||||
#define POWER_BUTTON 2
|
||||
|
||||
void rbox_press_power_btn(int ms)
|
||||
static uint8_t val;
|
||||
|
||||
int rbox_powerbtn_is_pressed(void)
|
||||
{
|
||||
uint8_t val = GREAD_FIELD(RBOX, OVERRIDE_OUTPUT, VAL);
|
||||
return !GREAD_FIELD(RBOX, CHECK_OUTPUT, PWRB_OUT);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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) */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user