mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-12 19:04:59 +00:00
cheza: Support confirmation of power lost
Keep the timestamp of the latest power lost. Add a handler to wake the chipset task to check if power lost stays low for a while (the time between now and the latest power lost is longer than a period). BRANCH=none BUG=b:78455067 TEST=Toggle EC GPIO SYS_RST_L for a low pulse to execute PMIC reset sequence and verified AP reset but not a transition S0 -> S5. TEST=Toggle EC GPIO PMIC_KPD_PWR_ODL and SYS_RST_L for a low pulse (see power_off function) to execute PMIC shutdown sequence and verified a power-lost transition S0 -> S5. Change-Id: I8ed789d701e834195865bfdf2d302388d42618d2 Signed-off-by: Tom Wai-Hong Tam <waihong@google.com> Signed-off-by: Alexandru M Stan <amstan@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1028831 Commit-Ready: Wai-Hong Tam <waihong@google.com> Tested-by: Wai-Hong Tam <waihong@google.com> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
committed by
chrome-bot
parent
71e966af61
commit
548e4d9708
@@ -15,7 +15,7 @@ GPIO_INT(WP_L, PIN(A, 1), GPIO_INT_BOTH, switch_interrupt) /* EC_W
|
||||
GPIO_INT(LID_OPEN, PIN(D, 2), GPIO_INT_BOTH, lid_interrupt) /* LID_OPEN_EC */
|
||||
GPIO_INT(AP_RST_REQ, PIN(C, 2), GPIO_INT_RISING | GPIO_PULL_DOWN, chipset_reset_request_interrupt) /* Reset request from AP */
|
||||
/* AP_RST_L is used for PMIC and AP negotiation. Don't change its state. */
|
||||
GPIO_INT(AP_RST_L, PIN(C, 1), GPIO_INT_BOTH, power_signal_interrupt)
|
||||
GPIO_INT(AP_RST_L, PIN(C, 1), GPIO_INT_BOTH, chipset_power_signal_interrupt)
|
||||
|
||||
/*
|
||||
* Should always make it low, to prevent AP unexpected up.
|
||||
|
||||
@@ -129,4 +129,12 @@ void chipset_handle_reboot(void);
|
||||
*/
|
||||
void chipset_reset_request_interrupt(enum gpio_signal signal);
|
||||
|
||||
/**
|
||||
* Chipset-specific power signal interrupt, overrides the default one.
|
||||
*
|
||||
* It is used in SDM845, to handle the short-low-pulse during the reset
|
||||
* sequence which we don't consider it as a power-lost.
|
||||
*/
|
||||
void chipset_power_signal_interrupt(enum gpio_signal signal);
|
||||
|
||||
#endif /* __CROS_EC_CHIPSET_H */
|
||||
|
||||
@@ -66,6 +66,9 @@
|
||||
/* Delay between power-off the system and all things (PMIC/AP) expected off */
|
||||
#define SYSTEM_POWER_OFF_DELAY (350 * MSEC)
|
||||
|
||||
/* Delay to confirm the power lost */
|
||||
#define POWER_LOST_CONFIRM_DELAY (350 * MSEC)
|
||||
|
||||
/* TODO(crosbug.com/p/25047): move to HOOK_POWER_BUTTON_CHANGE */
|
||||
/* 1 if the power button was pressed last time we checked */
|
||||
static char power_button_was_pressed;
|
||||
@@ -81,6 +84,9 @@ static char lid_opened;
|
||||
*/
|
||||
static uint8_t bypass_power_lost_trigger;
|
||||
|
||||
/* The timestamp of the latest power lost */
|
||||
static timestamp_t latest_power_lost_time;
|
||||
|
||||
/* Time where we will power off, if power button still held down */
|
||||
static timestamp_t power_off_deadline;
|
||||
|
||||
@@ -137,6 +143,49 @@ void chipset_reset_request_interrupt(enum gpio_signal signal)
|
||||
hook_call_deferred(&chipset_reset_request_handler_data, 0);
|
||||
}
|
||||
|
||||
/* Confirm power lost if the POWER_GOOD signal keeps low for a while */
|
||||
static uint32_t chipset_is_power_lost(void)
|
||||
{
|
||||
/*
|
||||
* Current POWER_GOOD signal is lost and the latest power lost trigger
|
||||
* happened before the confirmation delay.
|
||||
*/
|
||||
return (get_time().val - latest_power_lost_time.val >=
|
||||
POWER_LOST_CONFIRM_DELAY) && !power_has_signals(IN_POWER_GOOD);
|
||||
}
|
||||
|
||||
/* The deferred handler to save the power signal */
|
||||
static void deferred_power_signal_handler(void)
|
||||
{
|
||||
/* Wake the chipset task to check the power lost duration */
|
||||
task_wake(TASK_ID_CHIPSET);
|
||||
}
|
||||
DECLARE_DEFERRED(deferred_power_signal_handler);
|
||||
|
||||
/**
|
||||
* Power signal interrupt, overrides the default one.
|
||||
*
|
||||
* It handles the short-low-pulse during the reset sequence which we don't
|
||||
* consider it as a power-lost.
|
||||
*/
|
||||
void chipset_power_signal_interrupt(enum gpio_signal signal)
|
||||
{
|
||||
/* Call the default power signal interrupt */
|
||||
power_signal_interrupt(signal);
|
||||
|
||||
/*
|
||||
* It is the start of the low pulse, save the timestamp, wake the
|
||||
* chipset task after POWER_LOST_CONFIRM_DELAY in order to check if it
|
||||
* is a power-lost or a reset (short low-pulse).
|
||||
*/
|
||||
if (!(power_get_signals() & IN_POWER_GOOD)) {
|
||||
/* Keep the timestamp just at the low pulse happens. */
|
||||
latest_power_lost_time = get_time();
|
||||
hook_call_deferred(&deferred_power_signal_handler_data,
|
||||
POWER_LOST_CONFIRM_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
static void sdm845_lid_event(void)
|
||||
{
|
||||
/* Power task only cares about lid-open events */
|
||||
@@ -467,8 +516,8 @@ static int check_for_power_off_event(void)
|
||||
|
||||
power_button_was_pressed = pressed;
|
||||
|
||||
/* POWER_GOOD released by AP : shutdown immediately */
|
||||
if (!power_has_signals(IN_POWER_GOOD) && !bypass_power_lost_trigger) {
|
||||
/* Power lost: shutdown immediately */
|
||||
if (chipset_is_power_lost() && !bypass_power_lost_trigger) {
|
||||
if (power_button_was_pressed)
|
||||
timer_cancel(TASK_ID_CHIPSET);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user