summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWai-Hong Tam <waihong@google.com>2020-06-17 12:21:01 -0700
committerCommit Bot <commit-bot@chromium.org>2020-06-18 05:19:06 +0000
commit9397f9357992b8719eb42054d0bf1e75a96cfd12 (patch)
tree077eb73e11aa4e57d1b562d7b2f23a4234f21f96
parentc687adf9e953e771bc0ccac1115066fd5fafdfb7 (diff)
downloadchrome-ec-9397f9357992b8719eb42054d0bf1e75a96cfd12.tar.gz
sc7180: Move the hook notifications out of power_on and power_off
Make the functions power_on and power_off just contain the power rail control. Move the hook notifications out of them. So they can be reused in the follow-up change. Also move the battery level check out of the power_off. BRANCH=None BUG=b:153594300 TEST=Manually trigger power on and power off. TEST=For the low battery case, no misleading messages: > power on Requesting power on > RTC: 0x5ecf416f (1590641007.00 s) [14.208200 power state 4 = G3->S5, in 0x0005] RTC: 0x5ecf416f (1590641007.00 s) [14.211855 power state 1 = S5, in 0x0005] [14.213840 power on 4] RTC: 0x5ecf416f (1590641007.00 s) [14.214463 power state 5 = S5->S3, in 0x0005] [14.214898 power button released in time] [14.220408 Not enough power to boot (2 %, 0 mW)] [14.323917 Not enough power to boot (2 %, 0 mW)] [14.425590 Not enough power to boot (2 %, 0 mW)] [14.530575 Not enough power to boot (2 %, 0 mW)] [14.635587 Not enough power to boot (2 %, 0 mW)] [14.740618 Not enough power to boot (2 %, 0 mW)] [14.744386 Not enough power to boot (2 %, 0 mW)] RTC: 0x5ecf4170 (1590641008.00 s) [14.747297 power state 1 = S5, in 0x0005] Change-Id: Ic368b28ba045dfced7979deca545d2393d3453b7 Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2250667 Reviewed-by: Stephen Boyd <swboyd@chromium.org> Reviewed-by: Alexandru M Stan <amstan@chromium.org>
-rw-r--r--power/sc7180.c39
1 files changed, 17 insertions, 22 deletions
diff --git a/power/sc7180.c b/power/sc7180.c
index be2ee90f8b..dfd9b192fd 100644
--- a/power/sc7180.c
+++ b/power/sc7180.c
@@ -471,9 +471,6 @@ static void power_off(void)
if (!is_system_powered())
return;
- /* Call hooks before we drop power rails */
- hook_notify(HOOK_CHIPSET_SHUTDOWN);
-
/* Do a graceful way to shutdown PMIC/AP first */
set_pmic_pwron(0);
usleep(PMIC_POWER_OFF_DELAY);
@@ -495,10 +492,6 @@ static void power_off(void)
lid_opened = 0;
enable_sleep(SLEEP_MASK_AP_RUN);
- CPRINTS("power shutdown complete");
-
- /* Call hooks after we drop power rails */
- hook_notify(HOOK_CHIPSET_SHUTDOWN_COMPLETE);
}
/**
@@ -529,19 +522,6 @@ static int power_is_enough(void)
*/
static void power_on(void)
{
- /*
- * If no enough power, return and the state machine will transition
- * back to S5.
- */
- if (!power_is_enough())
- return;
-
- /*
- * When power_on() is called, we are at S5S3. Initialize components
- * to ready state before AP is up.
- */
- hook_notify(HOOK_CHIPSET_PRE_INIT);
-
/* Enable the 3.3V and 5V rail. */
gpio_set_level(GPIO_EN_PP3300_A, 1);
#ifdef CONFIG_POWER_PP5000_CONTROL
@@ -559,8 +539,6 @@ static void power_on(void)
set_pmic_pwron(1);
disable_sleep(SLEEP_MASK_AP_RUN);
-
- CPRINTS("AP running ...");
}
/**
@@ -757,7 +735,16 @@ enum power_state power_handle_state(enum power_state state)
*/
power_button_wait_for_release(-1);
+ /* If no enough power, return back to S5. */
+ if (!power_is_enough())
+ return POWER_S5;
+
+ /* Initialize components to ready state before AP is up. */
+ hook_notify(HOOK_CHIPSET_PRE_INIT);
+
power_on();
+ CPRINTS("AP running ...");
+
if (power_wait_signals(IN_POWER_GOOD) != EC_SUCCESS) {
CPRINTS("POWER_GOOD not seen in time");
set_system_power(0);
@@ -807,7 +794,15 @@ enum power_state power_handle_state(enum power_state state)
return POWER_S3;
case POWER_S3S5:
+ /* Call hooks before we drop power rails */
+ hook_notify(HOOK_CHIPSET_SHUTDOWN);
+
power_off();
+ CPRINTS("power shutdown complete");
+
+ /* Call hooks after we drop power rails */
+ hook_notify(HOOK_CHIPSET_SHUTDOWN_COMPLETE);
+
/*
* Wait forever for the release of the power button; otherwise,
* this power button press will then trigger a power-on in S5.