Commit Graph

526 Commits

Author SHA1 Message Date
Eric Yilun Lin 0172656723 Revert "zephyr: Add battery and smart battery options"
This reverts commit ac4f512e60.

Reason for revert: This CL stops chipset_task forever, revert this to boot AP.

Original change's description:
> zephyr: Add battery and smart battery options
>
> Shim in battery and smart battery support.
>
> BUG=b:175248556
> BRANCH=none
> TEST=boot on volteer, run 'battery' command.
> TEST=run 'ninja menuconfig' and check KConfig help text.
> 20-12-10 20:08:12.778 battery
> 20-12-10 20:08:13.509   Status:    0x02c0 DCHG INIT RC
> 20-12-10 20:08:13.529   Param flags:00000003
> 20-12-10 20:08:13.541   Temp:      0x0b63 = %.1d K (%.1d C)
> 20-12-10 20:08:13.541   V:         0x2a1e = 10782 mV
> 20-12-10 20:08:13.541   V-desired: 0x3390 = 13200 mV
> 20-12-10 20:08:13.541   I:         0x0000 = 0 mA
> 20-12-10 20:08:13.550   I-desired: 0x0a19 = 2585 mA
> 20-12-10 20:08:13.550   Charging:  Allowed
> 20-12-10 20:08:13.550   Charge:    0 %
> 20-12-10 20:08:13.550   Manuf:     LG
> 20-12-10 20:08:13.555   Device:    AC17A8
> 20-12-10 20:08:13.573   Chem:      LIO
> 20-12-10 20:08:13.573   Serial:    0xb754
> 20-12-10 20:08:13.573   V-design:  0x2d1e = 11550 mV
> 20-12-10 20:08:13.573   Mode:      0x6001
> 20-12-10 20:08:13.573   Abs charge:0 %
> 20-12-10 20:08:13.573   Remaining: 0 mAh
> 20-12-10 20:08:13.577   Cap-full:  4932 mAh (4833 mAh with 98 % compensation)
> 20-12-10 20:08:13.585     Design:  5360 mAh
> 20-12-10 20:08:13.594   Time-full: 0h:0
> 20-12-10 20:08:13.594     Empty:   0h:0
>
> Change-Id: Ie782e75ee4027ab2a5c6a0ae7f4ad81e9c360711
> Signed-off-by: Simon Glass <sjg@chromium.org>
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2575199

Bug: b:175248556
Change-Id: I66086d8fee46d5fd02d26938468a7d76dab71c6e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2589140
Reviewed-by: Eric Yilun Lin <yllin@chromium.org>
Commit-Queue: Eric Yilun Lin <yllin@chromium.org>
Tested-by: Eric Yilun Lin <yllin@chromium.org>
2020-12-14 05:11:24 +00:00
Keith Short ac4f512e60 zephyr: Add battery and smart battery options
Shim in battery and smart battery support.

BUG=b:175248556
BRANCH=none
TEST=boot on volteer, run 'battery' command.
TEST=run 'ninja menuconfig' and check KConfig help text.
20-12-10 20:08:12.778 battery
20-12-10 20:08:13.509   Status:    0x02c0 DCHG INIT RC
20-12-10 20:08:13.529   Param flags:00000003
20-12-10 20:08:13.541   Temp:      0x0b63 = %.1d K (%.1d C)
20-12-10 20:08:13.541   V:         0x2a1e = 10782 mV
20-12-10 20:08:13.541   V-desired: 0x3390 = 13200 mV
20-12-10 20:08:13.541   I:         0x0000 = 0 mA
20-12-10 20:08:13.550   I-desired: 0x0a19 = 2585 mA
20-12-10 20:08:13.550   Charging:  Allowed
20-12-10 20:08:13.550   Charge:    0 %
20-12-10 20:08:13.550   Manuf:     LG
20-12-10 20:08:13.555   Device:    AC17A8
20-12-10 20:08:13.573   Chem:      LIO
20-12-10 20:08:13.573   Serial:    0xb754
20-12-10 20:08:13.573   V-design:  0x2d1e = 11550 mV
20-12-10 20:08:13.573   Mode:      0x6001
20-12-10 20:08:13.573   Abs charge:0 %
20-12-10 20:08:13.573   Remaining: 0 mAh
20-12-10 20:08:13.577   Cap-full:  4932 mAh (4833 mAh with 98 % compensation)
20-12-10 20:08:13.585     Design:  5360 mAh
20-12-10 20:08:13.594   Time-full: 0h:0
20-12-10 20:08:13.594     Empty:   0h:0

Change-Id: Ie782e75ee4027ab2a5c6a0ae7f4ad81e9c360711
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2575199
2020-12-11 23:53:17 +00:00
Patryk Duda f03d488b98 power/host_sleep: Fix notifying about power state transitions
CL:2321874 moves sleep_set_notify() and sleep_notify_transition()
under CONFIG_POWER_SLEEP_FAILURE_DETECTION ifdef and introduces their
no-op counterparts if CONFIG_POWER_SLEEP_FAILURE_DETECTION is not
defined. Before that CL aforementioned functions were outside ifdef.
Commit message also mentions that CL is only moving code, not performing
any logical changes.

Therefore this CL is moving sleep_set_notify() and sleep_notify_transition()
outside ifdef and removes their no-on counterparts to eliminate logical
changes introduced in CL:2321874

Issue was found when running EC ToT on octopus (casta). When AP was
going to S0ix EC reported that fact, but PD was not changing DRP
state to 'toggle off'.

BUG=b:162083524, b:161775827
BRANCH=none
TEST=Compile and flash firmware on octopus (tested on casta).
     Go to ChromeOS Developer Console and issue 'powerd_dbus_suspend'
     Check EC console if PD stack is reporting state transition and make
     sure that DRP is set to 'toggling off'

Signed-off-by: Patryk Duda <pdk@semihalf.com>
Change-Id: I6ba4187c8549ee6d9e3b19543d67c49520927cb8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2575064
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: Wai-Hong Tam <waihong@google.com>
2020-12-08 08:51:58 +00:00
Ting Shen 898d76ff51 power/mt8192: back to S5 when PMIC failed to shutdown
`apshutdown` sometimes fails to shutdown PMIC, when this happens,
powerstate will bounce between G3 and S5G3 until watchdog kicks in.

To fix this, we should detect PMIC status in S5G3, go back to S5 to
retry shutdown if PMIC is still alive.

BUG=b:174546890
TEST=Run the reproduce steps in b/174546890#comment13,
     verify EC enters G3.
BRANCH=main

Signed-off-by: Ting Shen <phoenixshen@google.com>
Change-Id: I1f0544e16d818074378f58f1208bd586031a5ebb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2573895
Reviewed-by: Eric Yilun Lin <yllin@chromium.org>
Commit-Queue: Ting Shen <phoenixshen@chromium.org>
Tested-by: Ting Shen <phoenixshen@chromium.org>
2020-12-04 09:04:04 +00:00
Jack Rosenthal 5103f885bb power: move headers to include/power
This makes the headers visible to the Zephyr build.

BUG=b:173798264
BRANCH=none
TEST=buildall

Signed-off-by: Jack Rosenthal <jrosenth@chromium.org>
Change-Id: I3b6d27c1234b3924ee8902a86eec5fdb2ccd9998
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2571897
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: Keith Short <keithshort@chromium.org>
2020-12-03 19:09:21 +00:00
Wai-Hong Tam 2f7eec59e7 sc7180: Increase delays between enabling switchcap and enabling PMIC
According to some experiments, the current delays are not enough on
some boards. Add larger margin to the value. Also do the same on the
power-off sequence delay.

BRANCH=Trogdor
BUG=b:163613549
TEST=Made DUT transit to DEV mode and the next auto-boot worked fine.

Change-Id: Ia72c725fe1e8ff795e637e1b4b99b097478bcc1a
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2565635
Commit-Queue: Stephen Boyd <swboyd@chromium.org>
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
2020-12-02 18:25:55 +00:00
ravindr1 5e3ff7b30e Ectool: support reboot AP from G3 state with configurable delay.
On using Ectool command - reboot_ap_on_g3 [<delay>] && shutdown -h now,
AP must perform a reboot from G3 state to S0 state with configurable
delay in seconds on it's next corresponding shutdown cycle.

BUG=b:172885634
BRANCH=none
TEST=Run Ectool command - reboot_ap_on_g3 50 && shutdown -h now.

Change-Id: I2c5eb304d27a9647f0adc220d91de2d0b4061460
Signed-off-by: ravindr1 <ravindra@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2528731
Reviewed-by: Keith Short <keithshort@chromium.org>
2020-11-23 09:31:45 +00:00
Jack Rosenthal 24afe7306b zephyr: shim in power sequencing
Enable shimming of power sequencing code.

BUG=b:171312361
BRANCH=none
TEST=With zephyr-chrome CL...
     https://screenshot.googleplex.com/4m6N6vd2Nx5FpiD.png

Signed-off-by: Jack Rosenthal <jrosenth@chromium.org>
Change-Id: I8fb96019c8c636010d2cd136c0116df41fc9f148
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2548308
2020-11-20 23:57:56 +00:00
Jack Rosenthal 16511b74ee power: allow eSPI virtual wires without eSPI host commands for zephyr
For Zephyr OS, we want to get eSPI up and going for power sequencing
without having to bring in all of the host command dependencies.
Right now the power sequencing code assumes that if we are using eSPI
for host commands, that means we might have eSPI virtual wires too.
Instead, use the separate option CONFIG_HOST_ESPI_VW_POWER_SIGNAL,
which is what we actually want, and allow that to be defined without
CONFIG_HOSTCMD_ESPI.

BUG=b:171312361
BRANCH=none
TEST=buildall

Signed-off-by: Jack Rosenthal <jrosenth@chromium.org>
Change-Id: I2f56ef3ab9cc566f5e0e3926fea96484daa93236
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2548302
Reviewed-by: Yuval Peress <peress@chromium.org>
2020-11-19 03:08:28 +00:00
Wai-Hong Tam 27c170587f sc7180: Fix forever loop if not enough power to boot AP
When the power supply is not enough (<10W adapter and no battery)
to boot AP, should clear the boot_from_off flag and go back to S5;
otherwise, the boot_from_off flag will trigger the power-on again.
Also do the same on power_on() sequence failed.

Increase the delay of checking power, such that the messages are
not too noisy.

BRANCH=None
BUG=b:167155164
TEST=Unplugged the battery, plugged a <10W adapter, checked the
"Not enough power to boot (-1 %, 7500 mW)" message just showed 10x.

Change-Id: Id7c5e66dab62bc71d3e2e00b3be172e13a146ed5
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2536554
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
2020-11-14 02:51:41 +00:00
wen zhang 1172759baa Kukui: initial a new models kakadu of ec.
Copy from krane, which is a model from Kukui.
Modified for building pass.
It will need to be revised later.

BUG=b:171763111
BRANCH=master
TEST=make -j BOARD=kakadu

Change-Id: I87fcf8c8e3bd4fa669e0bcb7fbb9d125a9926cdb
Signed-off-by: wen zhang <zhangwen6@huaqin.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2501801
Reviewed-by: Chen-Tsung Hsieh <chentsung@chromium.org>
2020-11-02 11:24:50 +00:00
Wai-Hong Tam a5c40c2ee2 Trogdor: Deprecate PMIC_FAULT_L signal
This signal is no longer connected to PMIC on recent hardware
revisions. It is unused. Deprecate it.

BRANCH=None
BUG=b:171245607
TEST=Built the affected Trogdor images.

Change-Id: I75562f1aa9e411df38afd321ab63b51e91e7d4f7
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2488660
Reviewed-by: Alexandru M Stan <amstan@chromium.org>
2020-10-22 20:02:00 +00:00
Wai-Hong Tam bf8bda5901 sc7180: Correct the order of suspend hooks
Call the SUSPEND hooks before the SUSPEND_COMPLETE hooks. This matches
the resume hooks, that the RESUME_INIT hooks are called before the RESUME
hooks.

BRANCH=None
BUG=b:148149387, b:170604357
TEST=Checked the power off sequence and suspend.

Change-Id: Ie51ac808cc142ebd14496056042c7f65be73ffa3
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2468656
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
2020-10-14 00:22:52 +00:00
Wai-Hong Tam 307b4d213e sc7180: Notify SUSPEND hooks in S0S3 if shutdown from on
This CL pairs with the previous CL:2391202, which notifies the RESUME
hook in S3S0 if boot from off. This CL does the counter part, which
notifies the SUSPEND hooks in S0S3 if shutdown from on.

BRANCH=None
BUG=b:148149387, b:170604357
TEST=Verified the SUSPEND hooks are called when shutdown from S0.
For example, all the PWM channels are disabled after power off AP.

Change-Id: Ib420d5d0e560f30f9c03b5e31788a145279a9c75
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2468476
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
2020-10-14 00:22:51 +00:00
Ting Shen cc39b716fb power/mt8192: don't boot AP when wake from AC insert
Implement the wakeup behavior defined in our spec:
  AC insert -> wake EC
  Lid open / Power button -> wake EC + AP

BUG=b:163963220
TEST=Verify boot behavior matches the spec
BRANCH=none

Signed-off-by: Ting Shen <phoenixshen@google.com>
Change-Id: Ifc225c07d9a9faf25cf99578d535e63f63fc9bff
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2437238
Reviewed-by: Eric Yilun Lin <yllin@chromium.org>
Commit-Queue: Ting Shen <phoenixshen@chromium.org>
Tested-by: Ting Shen <phoenixshen@chromium.org>
2020-10-05 08:43:29 +00:00
Wai-Hong Tam a72f9b006f sc7180: Notify RESUME hooks in S3S0 if boot from off
After enabling the suspend hang detection, the RESUME hooks are deferred
to S0. When the kernel sets the host sleep event to flag the resume
completion, EC notifies the RESUME hooks. However, when it boots from an
off state, G3 or S5, the kernel won't set this host sleep event. Should
explicitly notify the RESUME hooks in the S3S0 state.

The change also renames the flag boot_from_g3 to boot_from_off and
carries it forward to S3S0; and renames the flag shutdown_from_s0 to
shutdown_from_on and carries it forward to S3S5.

BRANCH=None
BUG=b:148149387, b:167155164
TEST=Verified the RESUME hooks are called when boot from S5.

Change-Id: I48ee09ad66e53363e7a20d9602b37571177ac300
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2391202
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
2020-09-03 05:14:13 +00:00
Wai-Hong Tam 60dc637cf3 sc7180: Decouple the switchcap control from the power sequence
Currently, SC7180 power sequence is tightly coupled with a single
switchcap part, i.e. DA9313. Should decouple the switchcap control
from the power sequence, such that more different switchcap parts
can be supported.

BRANCH=None
BUG=b:163867792
TEST=Built the affect images and booted into kernel.

Change-Id: I7f63cd22bbc308672c40a734be4f6dfc80e07158
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2386480
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
Reviewed-by: Philip Chen <philipchen@chromium.org>
2020-09-02 01:45:15 +00:00
Ting Shen 723b0f9adc asurada: keep PP5000_A on at G3
In current EC implementation, EC turns off PP5000_A in G3. Since
PPC is powered by PP5000_A, it needs special logic to handle the
re-power and re-initialization.

See b:154775121 for more discussion.

To simplify the logic, change the behavior to turn PP5000_A off
only when hibernate, so we won't need to worry about re-initialize
PPC anymore (resume from hibernate is a reboot, so it's also
covered here).

BUG=b:154775121
TEST=1) Run the test script in CL:2169443
     2) Verify PD is functional whenever EC is awake.
BRANCH=none

Signed-off-by: Ting Shen <phoenixshen@google.com>
Change-Id: I07c03f9a8c0b77012d1284a283ce489e54b1a058
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2378940
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Commit-Queue: Ting Shen <phoenixshen@chromium.org>
Tested-by: Ting Shen <phoenixshen@chromium.org>
2020-08-28 10:46:55 +00:00
Daisuke Nojiri bc932aea92 Revert "power: Don't boot after waking up from hibernation"
This reverts commit 8db6eb8954.

Reason for revert: See chromium:1073960

Original change's description:
> power: Don't boot after waking up from hibernation
>
> When a device shuts down and is idle for 60 mins (configurable), EC
> enters hibernation. When an AC adapter is plugged, the system boots.
> This is not expected behavior and not consistent with the behavior
> that the system stays off on AC plug-in before hibernation.
>
> This patch fixes the above inconsistency by storing AP_OFF flag before
> entering hibernation after 60 mins idle in S5.
>
> Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
>
> BUG=chromium:1073960
> BRANCH=none
> TEST=Verified Bloog stays off after waking up from hibernation on
>      AC plug-in.
>
> Change-Id: I097bee97164284dd4c35f8bf9389c76319fd676a
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2176555
> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
> Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org>

Bug: chromium:1073960
Change-Id: I2792dd6d868118ffcba533a3cdb5195cc7d71b76
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2363099
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org>
2020-08-18 21:47:04 +00:00
Daisuke Nojiri d75d74f27e Revert "system: Clear AP_IDLE when waking up from hibernation by AC"
This reverts commit 4aacf83506.

Reason for revert: See chromium:1073960

Original change's description:
> system: Clear AP_IDLE when waking up from hibernation by AC
>
> Currently, AP_IDLE is set when EC is left idle in G3. This makes the AP
> stay off after EC wakes up from hibernation (for any wake-up source).
> This makes a board require another power button press to boot the
> system from hibernation.
>
> This change makes RO clear AP_IDLE unless AC is present. When AC is
> present, EC doesn't hibernate. So, AC presence infers the EC woke
> up from hibernation by AC. That is, if the system wakes up by a power
> button press, AP_IDLE is cleared and AP will be turned on (unless it's
> overwritten by AP_OFF).
>
> Tested as follows on Trembyle:
> 1. Put DUT in hibernation.
> 2. Wake up DUT and observe:
>   a. When waking up by power button, AP is turned on.
>   b. When waking up by lid open, AP is turned on.
>   c. When waking up by AC, AP is left idle.
>
> BUG=b:157077589, chromium:1073960
> BRANCH=none
> TEST=See above.
>
> Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
> Change-Id: Ie5020bbe50ad489f4e3010820681cc57ff51b941
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2236589

Bug: b:157077589
Bug: chromium:1073960
Change-Id: Id92d0d3657a622338581cb111d3925cbc11bf168
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2363080
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org>
2020-08-18 21:47:02 +00:00
Wai-Hong Tam 5cf6b55666 sc7180: Increase the timeout of waiting enough power
In a device without battery plugged, EC has to wait PD to negotiate to
at least 7.5W. Some charger takes a bit longer to negotiate a PD
contract and misses the timeout. AP won't autoboot. This CL increases
the timeout.

BRANCH=None
BUG=b:165027088, b:150240129
TEST=Unplugged the battery, plugged a PD charger, and AP booted up.

Change-Id: I775f87c2a7c25a3c160bd97d09bbbc1d617095b4
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2360435
Reviewed-by: Alexandru M Stan <amstan@chromium.org>
2020-08-18 18:07:21 +00:00
Edward Hill 55554e281b task: Change mutex_lock() assert
Instead of asserting that task_start() has not been called,
just return without doing any locking.

This avoids the need to fix every caller of mutex_lock() to check
task_start_called().

BUG=b:164461158
BRANCH=none
TEST=Esc+F3+Power enters recovery, does not assert.

Signed-off-by: Edward Hill <ecgh@chromium.org>
Change-Id: Ic157d7e7041185a67f257f0f5710fd02e45cd77f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2357496
Reviewed-by: Wai-Hong Tam <waihong@google.com>
Tested-by: Wai-Hong Tam <waihong@google.com>
Commit-Queue: Wai-Hong Tam <waihong@google.com>
2020-08-15 01:47:31 +00:00
Wai-Hong Tam 4b39e18c51 sc7180: Don't neglect the delay in a forced shutdown
In a forced shutdown, it just waits the POWER_GOOD drop to low, but not
wait the SYSTEM_POWER_ON_DELAY. If AP requests EC reboot at shutdown,
EC reboots immediately right after turns off the switchcap. Better to
delay a bit.

BRANCH=None
BUG=b:156981868, b:163613549
TEST=After switching from normal to dev mode, AP boots normally.

Change-Id: Iae300aa03dd0a991f62742159613377fe2388760
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2352440
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
2020-08-13 07:42:18 +00:00
Edward Hill e695620911 task: Fix mutex_lock() assert (reland)
mutex_lock() must not be used in interrupt context. Add an assert
to catch this.

Also assert task_start_called() since task ID is not valid
before this.

Also remove an old assert since comparing id with TASK_ID_INVALID
doesn't make sense.

Add check for task_start_called() for NPCX flash_lock, I2C port_mutex,
pwr_5v_ctl_mtx, STM32 bkpdata_write_mutex.

This was submitted CL:2309057, reverted CL:2323704, submitted
CL:2335738, reverted CL:2341706.

BUG=b:160975910
BRANCH=none
TEST=boot AP, jump to RW

Signed-off-by: Edward Hill <ecgh@chromium.org>
Change-Id: I0aadf29d073f0d3d798432099bd024a058332412
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2343450
Reviewed-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
2020-08-12 03:13:01 +00:00
Wai-Hong Tam 1c3aacb46b sc7180: Cancel the power button timer during the power state transition
A timer is created in the check_for_power_off_event(), which waits for
the power button long press. Should cancel the timer during the power
state transition; otherwise, EC will crash.

The S3 state calls the check_for_power_off_event() too. So cancel the
timer during S3->S0 and S3->S5.

BRANCH=None
BUG=b:163367454
TEST=Checked the bug scenario:
 * In VT2, run powerd_dbus_suspend and EC transits the state to S3.
 * Press power button
 * EC transits the state to S0; no crash.
TEST=Tested the normal shutdown case:
 * Hold the power button
 * After 8s, EC transits to S3 and then S5 after the power button is
   released.
TEST=Tested the change in check_for_power_off_event():
 * Hold the power button
 * In VT2, run "shutdown -H now" which makes POWER_GOOD drop
 * EC transits to S3 and then S5 after the power button is released

Change-Id: Ia279e890954cf77f94ae8907a2782f94265c849a
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2346600
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
2020-08-11 04:35:34 +00:00
Wai-Hong Tam 76d37a8137 sc7180: Fix the S3 state check
Should use the CHIPSET_STATE_SUSPEND to check if it is in S3, instead of
CHIPSET_STATE_STANDBY, which is actually the S0ix state.

BRANCH=None
BUG=b:148149387
TEST=Hached to make EC in S3 and then trigger AP warm reset.
Noticed the the CHIPSET_RESET_HOOK triggered and entered the if clause.
> [90.811712 power state 2 = S3, in 0x001c]
[90.812383 power state 2 = S3, in 0x001d]
[90.867572 power state 2 = S3, in 0x001e]
[90.944061 power state 2 = S3, in 0x001c]
[90.944957 power state 2 = S3, in 0x001d]
[91.000530 power state 2 = S3, in 0x001e]
[91.101117 power state 2 = S3, in 0x001c]
[91.101785 power state 2 = S3, in 0x001d]
[91.156711 power state 2 = S3, in 0x001e]
[91.157318 Chipset reset: exit s3]
[91.157659 Handle sleep: 0]
12 signal changes:
  90.811621  +0.000000  PS_HOLD => 0
  90.812012  +0.000391  AP_RST_L => 0
  90.867371  +0.055359  AP_RST_L => 1
  90.867483  +0.000112  PS_HOLD => 1
  90.943970  +0.076487  PS_HOLD => 0
  90.944357  +0.000387  AP_RST_L => 0
  91.000328  +0.055971  AP_RST_L => 1
  91.000441  +0.000113  PS_HOLD => 1
  91.100809  +0.100368  PS_HOLD => 0
  91.101183  +0.000374  AP_RST_L => 0
  91.156510  +0.055327  AP_RST_L => 1
  91.156623  +0.000113  PS_HOLD => 1

Change-Id: I8a3f2fec7e7c0ca784d5d742e5e9352fa019b18e
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2346601
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
2020-08-11 04:25:57 +00:00
Wai-Hong Tam 1a182fd225 sc7180: Monitor AP_RST_L from PMIC to notify HOOK_CHIPSET_RESET
The HOOK_CHIPSET_RESET should be notified when the AP resets.

In x86 platforms, EC monitors the LPC LRESET pin. This LRESET pin is
asserted when the chipset resets. However, ARM platforms don't use
LPC. We need another way to monitor AP reset.

This CL modifies the SC7180 power sequence, to monitor the AP_RST_L
signal from PMIC. PMIC uses the AP_RST_L to notify AP reset. A
complete warm reset sequence will toggle the AP_RST_L signal 3 times.
EC monitors the AP_RST_L signal and wait it transition 3 times to
notify the HOOK_CHIPSET_RESET. In case, the AP_RST_L is not toggled
3 times, still notifies the hook but prints a warning message.

BRANCH=None
BUG=b:163078082
TEST=Checked the HOOK_CHIPSET_RESET is notified after AP warm reset.

Change-Id: I4e7b0f0d266e01526deaf54afcdfd2ac1037b8f6
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2343753
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
2020-08-08 01:48:32 +00:00
Wai-Hong Tam 67944274aa sc7180: Support the sleep failure detection to SC7180 power sequence
This only adds the sleep failure detection support to SC7180 power
sequence but not enable it yet. The board has to explicitly define
the following CONFIG to enable this feature:
 * CONFIG_CHIPSET_RESUME_INIT_HOOK
 * CONFIG_POWER_SLEEP_FAILURE_DETECTION

Without defining the CONFIGs, the only change is to disable/enable
the AP_SUSPEND signal interrupt; the suspend/resume hooks are
unchanged, i.e. not wait for the host sleep event.

With defining the CONFIGs, the suspend failure detection is enabled.

When AP_SUSPEND is deasserted, only the RESUME_INIT hook is triggered
to initialize the SPI interface, such that EC can receive the host
sleep event. The RESUME hook is delayed to be triggered until AP
sends the resume event.

If AP_SUSPEND becomes asserted before receiving the host event, will
back to S3 and the SUSPEND_COMPLETE hook is triggered to disable the
SPI interface.

If no host event is received and no AP_SUSPEND assertion, a timeout
happens and wake the AP with a HANG_DETECT event.

BRANCH=None
BUG=b:148149387
TEST=Tried the following scenaiors (the CONFIGs not defined):
(1) On AP_SUSPEND assertion, SUSPEND hook triggered, go to S3;
(2) On AP_SUSPEND deassertion, RESUME hook triggered, go to S0.
Checked the follower CL for the configs defined.

Change-Id: I28301921a4c85aab092cdc8af9d6ff4b1da7ec61
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2321876
Reviewed-by: Ting Shen <phoenixshen@chromium.org>
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
2020-08-08 01:47:11 +00:00
Wai-Hong Tam 099a6bc377 power: Move the sleep failure detection to a common library
Move the sleep failure detection logic from intel_x86 power sequence to
a common library, i.e. host_sleep.

This CL simply moves the code, without any logic change.

BRANCH=None
BUG=b:162083524
TEST=Build the hatch board.

Change-Id: Ia3f70804ded8d80c4a079a36fbf1819c05a2090b
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2321874
Reviewed-by: Ting Shen <phoenixshen@chromium.org>
2020-08-07 19:04:25 +00:00
Wai-Hong Tam 530c9c7127 power/intel_x86: Abstract the chipset specific functions
This CL abstracts the chipset specific functions, that makes the hang
detection logic clearer. The changes are like:
 * Set the sleep_notify variable through the call sleep_set_notify()
 * The chipset specific timeout handle is moved to a callback function.
   This callback is passed to sleep_start_suspend().

BRANCH=None
BUG=b:162083524
TEST=Build the hatch board.

Change-Id: Ib9462f1fecbd39d63607bb9f10d1994e54c9ac64
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2327837
Reviewed-by: Ting Shen <phoenixshen@chromium.org>
2020-08-07 19:04:24 +00:00
Wai-Hong Tam 82e39fbcb5 power/intel_x86: Decouple LPC logic from sleep detection
Move the LPC handling logic out of the sleep failure detection
functions. For example, move the lpc_s0ix_suspend_clear_masks()
to the first SUSPEND hook, move power_update_wake_mask() out of
sleep_complete_resume().

BRANCH=None
BUG=b:162083524
TEST=Build the hatch board.

Change-Id: I16c4ed88e7cf40aabb9ce2d9ec95f7994dfe7efc
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2321873
Reviewed-by: Eric Yilun Lin <yllin@chromium.org>
2020-08-05 23:50:59 +00:00
Sam Hurst dede4e01ae ec: change usage of dummy
Google is working to change its source code to use more inclusive
language. To that end, replace the term "dummy" with inclusive
alternatives.

BUG=b:162781382
BRANCH=None
TEST=make -j buildall
     `grep -ir dummy *`
      The only results are in "private/nordic_keyboard/sdk8.0.0"
      which is not our code.

Signed-off-by: Sam Hurst <shurst@google.com>
Change-Id: I6a42183d998e4db4bb61625f962867fda10722e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2335737
Reviewed-by: Tom Hughes <tomhughes@chromium.org>
2020-08-05 18:41:25 +00:00
Wai-Hong Tam 119a7701d5 power/intel_x86: Generalize the sleep failure detection, not bound to S0ix
This change prepares to separate the sleep failure detection out of
intel_x86, such that other chipset power sequence can reuse the code.

It only touches the naming. No logic changes.
 * Rename to CONFIG_POWER_SLEEP_FAILURE_DETECTION
 * Modify the function and variable names, to avoid S0ix
 * Modify the comment to more neutral

BRANCH=None
BUG=b:162083524
TEST=make buildall -j

Change-Id: I6a61c3b0a63af60913ee89e0ca343085fbd22308
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2321872
Reviewed-by: Eric Yilun Lin <yllin@chromium.org>
2020-08-04 06:38:09 +00:00
Daisuke Nojiri 744a611d80 Revert "power: Clear AP_IDLE when waking up by PB or LID"
This reverts commit 27ee378bb7.

Reason for revert: b/162508724

A wake-up source from hibernation needs to be determined only by RO.  Reverting back to the original implementation: CL:2236589.

Original change's description:
> power: Clear AP_IDLE when waking up by PB or LID
>
> Currently, AP_IDLE is cleared when EC wakes up by the power button or
> the lid open.
>
> This patch extends the logic from CONFIG_EXTPOWER_GPIO to
> CONFIG_EXTPOWER so that the bug (chromium:1073960) can be also fixed
> on the boards using non-GPIO method for extpower_is_present.
>
> Tested as follows on Trembyle:
> 1. Put DUT in hibernation.
> 2. Wake up DUT and observe:
>   a. When waking up by power button, AP is turned on.
>   b. When waking up by lid open, AP is turned on.
>   c. When waking up by AC, AP is left idle.
>
> BUG=b:157077589, chromium:1073960, b:159350276
> BRANCH=none
> TEST=See above.
>
> Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
> Change-Id: I944aaac036ce58659e81b7021e52a3291f31e951
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2283946
> Reviewed-by: Jett Rink <jettrink@chromium.org>

Bug: b:157077589
Bug: chromium:1073960
Bug: b:159350276
Bug: b:162508724
Change-Id: Iaf9d0af2ca8c48bbf2529c4ba05493837dd76287
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2333106
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
2020-08-01 00:12:19 +00:00
Wai-Hong Tam 8ff1717409 sc7180: Enable the load switch during AP power-on
The QSIP_ON GPIO controls the load switch enable. The load switch is
redundant and used for experiments. But leaving it off consumes power.
Should enable it during AP power-on and disable it during AP power-off,
such that it doesn't waste power.

Add the QSIP_ON GPIO to the trogdor board. It was added since rev-1
(rev-0 is NC).

BRANCH=None
BUG=b:159999589
TEST=Checked AP power-on and power-off.

Change-Id: Ia1ef6a0c2285b5adcc53b717f7f310b15eb1d941
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2327632
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
Reviewed-by: Jim Guerin <jguerin@google.com>
2020-07-30 04:42:14 +00:00
Wai-Hong Tam b40786b4b8 sc7180: Add debug command to fake AP_SUSPEND signal to enter/exit S3
The AP_SUSPEND signal doesn't work on ToT kernel. It needs more work.
Introduce a way to fake the signal for testing.

BRANCH=None
BUG=b:148149387
TEST=Typing "fakesuspend on" in S0, transit into S3;
then typing "fakesuspend off" in S3, transit into S0;
then typing "fakesuspend reset", back to using AP_SUSPEND signal.

Change-Id: I706b576a848f9875e8ce6bed4c71ea7e33dfc315
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2324988
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
2020-07-30 04:32:28 +00:00
Wai-Hong Tam e89e106687 power/intel_x86: Add a config check for S0ix
The S0ix requires the CONFIG_POWER_TRACK_HOST_SLEEP_STATE enabled;
otherwise, a compilation error happens. Add a config check for it
and simplify some #ifdef clauses.

BRANCH=None
BUG=b:162083524
TEST=make buildall -j
TEST=Removing the CONFIG_POWER_TRACK_HOST_SLEEP_STATE on hatch caused
a fail.

Change-Id: Ic685d1ca5d05d705fcf6bb43717fc05f6526274e
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2321871
Reviewed-by: Evan Green <evgreen@chromium.org>
Reviewed-by: Eric Yilun Lin <yllin@chromium.org>
2020-07-29 07:22:12 +00:00
Wai-Hong Tam 73fe6226b6 sc7180: Allow the idle task to go into deep sleep in S3 or lower
Move the enable_sleep(SLEEP_MASK_AP_RUN) call from S5S3 to S3S0,
such that the idle task can go into deep sleep in S3.

BRANCH=None
BUG=b:148149387
TEST=Tried to trigger different states on the power sequence.

Change-Id: I9f7ea0186547ea460b3a07d4e98cef0fa6c16b08
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2321878
Reviewed-by: Alexandru M Stan <amstan@chromium.org>
2020-07-29 07:22:07 +00:00
Eric Yilun Lin d434d51ab0 power/mt8183: reset EC if EC has jumped and AP reboots
Resets EC if EC has jumped before and we want to boot AP.

In the normal flow, EC should stay at RW and reset itself
and AP should request EC for bootblock when start booting.

On some testing scenario, we might want to boot AP after RO->RW->RO
transition, and in such case, AP won't be able to boot due to
AP_SYS_RST_ODL been pulled down by the SLG, and SLG latches output
until the next EC_RST_ODL. So in such test cases, we should
reset the EC.

BUG=b:161584167
TEST=boot AP; sysjump RO; apshutdown; powerbtn 1200; ensure AP boots
BRANCH=kukui

Change-Id: Ia4066f1764b83acf6835f344393dcad8c125d0e3
Signed-off-by: Eric Yilun Lin <yllin@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2319494
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2020-07-29 06:44:16 +00:00
Paul Fagerburg 514923bc59 ec: change usage of "sane" per inclusive language
Google is working to change its source code to use more inclusive
language. To that end, replace the terms "sane", "sanity check", and
similar with inclusive/non-stigmatizing alternatives.

BUG=b:161832469
BRANCH=None
TEST=`make buildall -j` succeeds. `grep -Eir "sane|sanity" .` shows
results only in third-party code or documentation.

Signed-off-by: Paul Fagerburg <pfagerburg@chromium.org>
Change-Id: I29e78ab27f84f17b1ded75cfa10868fa4e5ae88c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2311169
Reviewed-by: Jett Rink <jettrink@chromium.org>
2020-07-22 22:49:46 +00:00
Wai-Hong Tam 05d9a30c9d sc7180: Support staying and leaving S3
In the previous power state machine, S3 was just a transitional state
between S0 <-> S5. This change supports staying and leaving S3, by
checking the AP_SUSPEND signal.

BRANCH=none
BUG=b:148149387
TEST=Powered DUT on and off; verified transition to S0 and S5.
TEST=Modified the AP_SUSPEND signal; verified transition to S3 and S0.

Change-Id: I7978be31d05546c814d2588eaf1f4e1ac47638ce
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2220833
Reviewed-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
Commit-Queue: Alexandru M Stan <amstan@chromium.org>
2020-07-22 03:33:40 +00:00
Daisuke Nojiri 27ee378bb7 power: Clear AP_IDLE when waking up by PB or LID
Currently, AP_IDLE is cleared when EC wakes up by the power button or
the lid open.

This patch extends the logic from CONFIG_EXTPOWER_GPIO to
CONFIG_EXTPOWER so that the bug (chromium:1073960) can be also fixed
on the boards using non-GPIO method for extpower_is_present.

Tested as follows on Trembyle:
1. Put DUT in hibernation.
2. Wake up DUT and observe:
  a. When waking up by power button, AP is turned on.
  b. When waking up by lid open, AP is turned on.
  c. When waking up by AC, AP is left idle.

BUG=b:157077589, chromium:1073960, b:159350276
BRANCH=none
TEST=See above.

Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Change-Id: I944aaac036ce58659e81b7021e52a3291f31e951
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2283946
Reviewed-by: Jett Rink <jettrink@chromium.org>
2020-07-22 00:24:41 +00:00
Wai-Hong Tam 395e6112a9 power: Use a general name for PMIC_RESIN_L signal on sc7180 and sdm845
Don't bound to the PMIC part name.

BRANCH=None
BUG=b:148113568
TEST=Built the affected images.

Change-Id: I3c2e8851294b957aa133c6a8528de3960a3e468c
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2303815
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
2020-07-20 23:20:08 +00:00
Wai-Hong Tam 7465442b16 sc7180: Add debug message for the switchcap no power case
On some board, we saw the behavior that the switchcap asserts its GPIO
to report the output rail in a good range but actually the rail has no
voltage.

This CL adds a debug message for it by checking the PMIC_KPD_PWR_ODL
GPIO value. This open-drain GPIO should be pulled by the PMIC. For the
switchcap no power case, the message prints out and cancel the power on
sequence.

BRANCH=None
BUG=b:159776965
TEST=Manually overrode the PMIC_KPD_PWR_ODL to low. Triggered the power
on sequence and checked it cancelled:
[28.365326 power state 1 = S5, in 0x0005]
[28.365757 power on 4]
RTC: 0x5eb941ba (1589199290.00 s)
[28.366407 power state 5 = S5->S3, in 0x0005]
[28.366862 power button released in time]
[28.369017 set_system_power(1)]
[28.495140 set_pmic_pwron(1)]
[28.495614 PMIC_KPD_PWR_ODL not pulled up by PMIC; cancel pwron]
[28.496110 POWER_GOOD not seen in time]
[28.496487 set_system_power(0)]
RTC: 0x5eb941ba (1589199290.00 s)
[28.507645 power state 1 = S5, in 0x0005]

Change-Id: Id2362a8c87746cc756192aae0b0489cf3d95d133
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2277344
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
2020-07-01 19:45:14 +00:00
Daisuke Nojiri 6218ae9887 Battery: Implement smart discharge system
Currently, CrOS EC chooses only one of the two powre-saving states
when the system is left idle. One is to hibernate and the other is
to cut off the battery. And these are determined at compile time.

If the system hibernates, EC will not have a chance to cut off the
battery before the state of charge reaches critical low. If the
system is in cutoff, it requires an AC adapter to wake up. So, neither
behavior is ideal.

This patch introduces the smart discharge system. Given the number
of hours to zero capacity as a target, it tries to choose the better
state for idling.

For example, if the state of charge is high, it will hibernate the
system because the target can be met before the battery completely
drains. If the state of charge is low, it will keep the EC up so
that it can cutoff the battery.

Tests are done on Bloog as follows:

Verify EC selects not to hibernate when the remaining capacity is
below the stay-up threshold.

The ectool smartdischarge command is tested as follows:

localhost ~ # ectool smartdischarge
Hours to zero capacity:         0 h
Stay-up threshold:              0 mAh
Cutoff threshold:               0 mAh
Hibernate discharge rate:       0 uA
Cutoff discharge rate:          0 uA

localhost ~ # ectool smartdischarge 2160
Hours to zero capacity:      2160 h
Stay-up threshold:              0 mAh
Cutoff threshold:               0 mAh
Hibernate discharge rate:       0 uA
Cutoff discharge rate:          0 uA

localhost ~ # ectool smartdischarge 2160 200 1500
EC result 3 (INVALID_PARAM)

localhost ~ # ectool smartdischarge 2160 1500 200
Hours to zero capacity:      2160 h
Stay-up threshold:           3240 mAh
Cutoff threshold:             432 mAh
Hibernate discharge rate:    1500 uA
Cutoff discharge rate:        200 uA

localhost ~ # ectool smartdischarge 2160 1500 0
EC result 3 (INVALID_PARAM)

localhost ~ # ectool smartdischarge 0
Hours to zero capacity:         0 h
Stay-up threshold:              0 mAh
Cutoff threshold:               0 mAh
Hibernate discharge rate:    1500 uA
Cutoff discharge rate:        200 uA

Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>

BUG=b:152431365, b:157602162
BRANCH=none
TEST=See above

Change-Id: I1470b13203f3653ae0e495cd5ec8ed05f3c5102f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2216392
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org>
2020-06-20 02:17:16 +00:00
Wai-Hong Tam 3bb7d7b0e6 sc7180: Handle the exception cases of power on
Make the switchcap and PMIC functions return a success or error
code. In the power on sequence, an error happening in the middle
will make it skip the remaining steps, and then calls the power
off sequence to restore back S5. The power off sequence don't
care about any error and perform the entire procedure.

BRANCH=None
BUG=b:159101052
TEST=Manually trigger power on and power off.
TEST=Forced to a switchcap error, it went back to S5.
> gpioset DA9313_GPIO0 0
> power on
Requesting power on
> RTC: 0x5ed1d4a7 (1590809767.00 s)
[7177.018477 power state 4 = G3->S5, in 0x0005]
RTC: 0x5ed1d4a7 (1590809767.00 s)
[7177.019409 power state 1 = S5, in 0x0005]
[7177.019918 power on 4]
RTC: 0x5ed1d4a7 (1590809767.00 s)
[7177.021168 power state 5 = S5->S3, in 0x0005]
[7177.021700 power button released in time]
[7177.024143 set_system_power(1)]
[7177.076708 SWITCHCAP NO POWER GOOD!]
[7177.187407 set_system_power(0)]
RTC: 0x5ed1d4a7 (1590809767.00 s)
[7177.188564 power state 1 = S5, in 0x0005]

Change-Id: Iaf2676d84513056b3a1deb4f4c554c607e588c37
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2250668
Reviewed-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
2020-06-18 05:19:07 +00:00
Wai-Hong Tam 9397f93579 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>
2020-06-18 05:19:06 +00:00
Tony Lin 76f2c33a42 asurada rev0: Remove control of PP3300_U and PP1800_U.
Those power rails are controlled by PMIC (MT6359)

BUG=none
TEST=Boot asurada with PP3300_U and PP1800_U
BRANCH=none

Signed-off-by: Ting Shen <phoenixshen@google.com>
Change-Id: I52d93e0ce77b3cd9b5c58e7289ef56293cde3ada
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2222383
Tested-by: Ting Shen <phoenixshen@chromium.org>
Reviewed-by: Eric Yilun Lin <yllin@chromium.org>
Commit-Queue: Ting Shen <phoenixshen@chromium.org>
2020-06-11 11:37:20 +00:00
Daisuke Nojiri 4aacf83506 system: Clear AP_IDLE when waking up from hibernation by AC
Currently, AP_IDLE is set when EC is left idle in G3. This makes the AP
stay off after EC wakes up from hibernation (for any wake-up source).
This makes a board require another power button press to boot the
system from hibernation.

This change makes RO clear AP_IDLE unless AC is present. When AC is
present, EC doesn't hibernate. So, AC presence infers the EC woke
up from hibernation by AC. That is, if the system wakes up by a power
button press, AP_IDLE is cleared and AP will be turned on (unless it's
overwritten by AP_OFF).

Tested as follows on Trembyle:
1. Put DUT in hibernation.
2. Wake up DUT and observe:
  a. When waking up by power button, AP is turned on.
  b. When waking up by lid open, AP is turned on.
  c. When waking up by AC, AP is left idle.

BUG=b:157077589, chromium:1073960
BRANCH=none
TEST=See above.

Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Change-Id: Ie5020bbe50ad489f4e3010820681cc57ff51b941
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2236589
2020-06-11 03:19:46 +00:00
Aseda Aboagye 8a3de00ee2 JSL: Wait 60ms to turn off PP5000_U after PP3300_A
For Jasperlake, we need to wait 60ms after PP3300_A goes down before
turning off PP5000_U.  This time is needed to allow VCCIN AUX to
discharge properly.

BUG=b:157784504
BRANCH=None
TEST=Build and flash waddledoo, verify that a 60ms delay is added when
PP3300_A turns off when shutting down.

Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Change-Id: I0fc08bfd597c0e0264f4ff52ccec3a1504f9fb8e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2229605
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Auto-Submit: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Diana Z <dzigterman@chromium.org>
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
2020-06-09 23:35:15 +00:00