Commit Graph

41 Commits

Author SHA1 Message Date
Daisuke Nojiri
7757a8e872 charger: Add state for discharge + full
When battery is fully charged, Reef starts discharging to protect
battery and starts charging again when charge level goes down
around 95%. To prevent the battery LED from showing blue with the
charger plugged in, this patch adds a new state for discharge +
nearly full. Reef shows a color indicating battery is full if
an external charger is present.

BUG=b:35775017
BRANCH=none
TEST=Fully charge Electro. Plug in OEM charger. LED lights blue.

Change-Id: I4c7c62f2c51c1d39188d1b271331984e89d5d7a3
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/448961
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2017-03-03 17:11:30 -08:00
Sam Hurst
edf46467b9 cleanup: Remove charge_state_v1
All boards have been transitioned to charge_state_v2.c
So charge_state_v1.c, HOOK_CHARGE_STATE_CHANGE, and
CONFIG_CHARGER_TIMEOUT_HOURS can be removed

BUG=chrome-os-partner:36272
TEST=make -j buildall
BRANCH=none

Change-Id: I3f20c5198ea75185f9894deb792575a1be31432a
Reviewed-on: https://chromium-review.googlesource.com/435467
Commit-Ready: Sam Hurst <shurst@google.com>
Tested-by: Sam Hurst <shurst@google.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
2017-02-06 14:50:32 -08:00
Vijay Hiremath
6f5489e18e cleanup: Rename charge_temp_sensor_get_val() to charge_get_battery_temp()
charge_temp_sensor_get_val() is used to get the battery temperature value
hence renamed it to charge_get_battery_temp().

BUG=none
BRANCH=none
TEST=make buildall -j

Change-Id: I2b52cac57dcde12a6b7405e7d712240e278954e2
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/397962
Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2016-10-14 18:49:36 -07:00
Ryan Zhang
f6a53e9917 COMMON: move precharge time to config.h
move PRECHARGE_TIMEOUT to config.h so that we can customize precharge time to
meet client's spec.

BUG=none
BRANCH=master
TEST=`make -j buildall`, precharge time is set to 300s in elm.

Change-Id: I5c3bf0d5c5240b9c087e6cdb7c6e97301efa9f84
Signed-off-by: Ryan Zhang <Ryan.Zhang@quantatw.com>
Reviewed-on: https://chromium-review.googlesource.com/348151
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-06-01 20:37:08 -07:00
Shawn Nematbakhsh
0af6e77a3a charger: Change unlocked battery level ignore conditions
x86 systems will auto-power-on when power is applied to the EC. When
the battery level is critically low, power-on is prevented, except when
the system is unlocked. So, when unlocked, some systems will
auto-power-on regardless of battery level, overcurrent the charger /
battery, and then repeat forever.

Prevent this reboot loop by ignoring auto-power-up when the battery is
critically low, regardless of system unlocked status.

BUG=chrome-os-partner:48339
TEST=Verify power-up is prevented on no-battery chell w/ donette. Then,
run 'powerbtn' on EC console and verify system powers on (and
overcurrents).
BRANCH=None

Change-Id: Ia631b5a8c45b42ec805e4a0c3f827929a0efd236
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/319187
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
2016-01-06 18:48:11 -08:00
Shawn Nematbakhsh
88ccbe9323 charger: Make critical battery shutdown timeout a config option
Certain platforms may wish to have a longer shutdown timeout, so make
the timeout a config option.

BUG=chrome-os-partner:35188
TEST=Manual on Samus with subsequent CL. Set config option to increase
timeout, verify that timeout is extended.
BRANCH=Samus

Change-Id: I69feb0d31fdc53e533671dec1e88ba96cc4553c2
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/240815
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-01-15 05:13:14 +00:00
Shawn Nematbakhsh
ed4d13fde2 charger v2: Combine prevent_*_discharge functions
prevent_hot_discharge and prevent_deep_discharge are near-identical
copies of one another, and can be combined without the loss of any
useful functionality.

BUG=chrome-os-partner:35188
TEST=Manual on Samus. Charge to 2% and boot system with 5V power supply.
Verify that warnings print to console and AP powers down after 30s. Also
pass unit tests.
BRANCH=Samus

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I0f1da5248825a3884f7910babc742dfa7eadf5a3
Reviewed-on: https://chromium-review.googlesource.com/240033
2015-01-13 18:48:18 +00:00
Shawn Nematbakhsh
a7bae3588c power_button_x86: Inhibit AP power-on if battery level is too low
Allow CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON to be defined at the board
level to be the minimum battery percentage required for power-on. If the
battery level is below the threshold, or if the battery is missing,
power button presses will be ignored.

BUG=chrome-os-partner:31127
TEST=Manual on Samus with subsequent commit. Verify that AP continues
to boot normally when charge level exceeds
CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON. Verify that power button
presses are ignored when the charge level is below the threshold, and
we return to G3.
BRANCH=Samus

Change-Id: I0ff3f7ddabf38080332470e172c8b2e307bf1655
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/236021
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-12-17 18:07:10 +00:00
Alec Berg
fca4977983 samus: add high battery temp warning to charge state machine
Add high (and low) battery temperature warning which sends host
event to AP. After 30 seconds of out of range temp readings force
shut off AP and hibernate the EC.

BUG=chrome-os-partner:27641, chrome-os-partner:33111
BRANCH=samus
TEST=make buildall, and write unit tests to test this condition.

Change-Id: I95b7d9d753c17e4b76218a9845aa63dd1b96a500
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/235645
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-12-15 22:44:28 +00:00
Alec Berg
72357cd1ed samus: Allow samus to charge w/o battery or with dead battery
Use a EC to PD host command to notify the PD MCU when a battery
is present and charged enough that it is ok to negotiate for a
higher power. The PD MCU will not negotiate until the host command
is received, which allows the system to be powered without a
battery or with a dead battery with 5V.

BUG=chrome-os-partner:28611
BRANCH=none
TEST=Tested on a samus:

1) Tested the normal case of battery charged and plugged in. When
charger is plugged in, the device immediately starts negotiating
for 20V and starts charging.
2) Tested with no battery. Plug in a charger, samus boots and stays
alive. VBUS measured at 5V. When a battery is plugged in, device
negotiates for 20V and starts charging.
3) Tested dead battery by taking a battery with no charge, and
plugging in zinger. Everything boots, but PD does not negotiate
for power. Then when battery reaches 1%, PD negotiates and zinger
switches to 20V without causing a reboot.

Change-Id: Iaa451403674e86cddbd3fe80e9503584910be576
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/201958
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-06-09 22:20:48 +00:00
Louis Yung-Chieh Lo
58878e79e0 Fixed the stack overflow bug in 'battery' console command.
On the Nyan EC, we almost run out of the stack of console task.
Instead of making that struct static or global, we print the cached data.
Read the issue tracker for more detailed discussion.

BUG=chrome-os-partner:28027
BRANCH=tot
TEST=verified on nyan with/without battery.
The "battery" console command doesn't crash the system.

Change-Id: Id5246724760aed4cf1df827baf115007b2ffb48e
Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/194875
Reviewed-by: Dave Parker <dparker@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-04-21 20:58:32 +00:00
Bill Richardson
5019551e1d Move common charge_state time constants to a common header
We had duplicate values in both v1 and v2 headers. Let's consolidate them in
one place, and prefix the constants with "CHARGE_", so people don't use them
randomly.

BUG=chrome-os-partner:20881
BRANCH=ToT
TEST=make buildall -j

No functionality changes, refactor/rename only.

Change-Id: I0ee599a2e3bf0835c2c0a7e57872ad9015701a4b
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/193876
2014-04-11 15:37:38 +00:00
Bill Richardson
defaf5cdb5 Create stub files for charge_state_v2.c
Remove copied code from V1 implementation, reduce to bare minimum needed to
satisfy external dependencies.

Don't actually enable it for any platforms, though.

BRANCH=ToT
BUG=chrome-os-partner:23776
TEST=make buildall -j

It's used by anything and doesn't do anything if it was, but test
compilation of the changed sources by defining CONFIG_CHARGER_V2.

Change-Id: Iea37d0b4fc48c8ebf7f7088cd1674d6e275d03d4
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/190853
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-03-20 23:51:03 +00:00
Bill Richardson
a025f18673 Rename charge_state.[ch] to charge_state_v1.[ch]
Making room for a new charge_state implementation.

BRANCH=ToT
BUG=chrome-os-partner:23776
TEST=make buildall -j

No new functionality, just renaming some files.

Change-Id: I80ce861f09129a518e180cac20d32e867a93cd46
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/190852
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-03-20 23:51:00 +00:00
Bill Richardson
0a35a979d4 Remove conditional declaration of charge_want_shutdown()
This is only used in power_button_x86.c, which always defines
CONFIG_CHARGER, so there's no need to make it conditional.

BRANCH=ToT
BUG=chrome-os-partner:23776
TEST=make buildall -j

Change-Id: I415572e691cc5bd6b189f9d3dd737b4209c33669
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/190851
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-03-20 23:50:57 +00:00
Louis Yung-Chieh Lo
e43074ebcf cleanup: nyan: remove unnecessary dependence to pmu_tpschrome.h
Nyan uses common/charge_state instead. So, fix the dependence.
Since snow/spring/pit are using common/pmu_tps65090_charger, keep them.

BUG=None
BRANCH=Nyan
TEST=build and works fine on Nyan 3.2

Change-Id: I985f7980578ac22602b1fbffa51edf039078bc05
Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/186337
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-02-14 17:46:34 +00:00
Randall Spangler
3192264679 Include battery fuel gauge temp sensor in temperature sensors
This gives the AP a way to see that temperature for DPTF.  Alarm
thresholds were defined on a per-sensor basis, so they come along for
free.

BUG=chrome-os-partner:25585
BRANCH=rambi
TEST=temps command shows same temp for battery as battery command (other
     than rounding error; battery command shows with 0.1C accuracy).
     'ectool temps all' shows the battery temp as the last temperature.

     Unplug battery and temps command shows error for the battery temp,
     as does 'ectool temps all'.

Change-Id: I1bce72f164d9fb1be631e7241a4ea24ddf409d7a
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/185444
Reviewed-by: Dave Parker <dparker@chromium.org>
2014-02-08 04:21:26 +00:00
Louis Yung-Chieh Lo
5a4b239981 rename power_state* to charge_state*
Those are actually charge state, not power state. Rename the misleading
names.

BUG=chrome-os-partner:24832
BRANCH=link,falco,samus,rambi,peppy,spring,pit,snow
TEST=build only because no name conflicts.
make clean BOARD=link && make -j32 BOARD=link && \
make clean BOARD=falco && make -j 32 BOARD=falco && \
make clean BOARD=samus && make -j 32 BOARD=samus && \
make clean BOARD=rambi && make -j 32 BOARD=rambi && \
make clean BOARD=peppy && make -j 32 BOARD=peppy && \
make clean BOARD=snow && make -j 32 BOARD=snow && \
make clean BOARD=spring && make -j 32 BOARD=spring && \
make clean BOARD=pit && make -j 32 BOARD=pit && \
make clean BOARD=nyan && make -j 32 BOARD=nyan && \
make runtests -j 32 && make tests -j 32 BOARD=link && \
make tests -j 32 BOARD=falco && make tests -j 32 BOARD=samus && \
make tests -j 32 BOARD=rambi && make tests -j 32 BOARD=peppy && \
make tests -j 32 BOARD=snow && make tests -j 32 BOARD=spring && \
make tests -j 32 BOARD=pit && make tests -j 32 BOARD=nyan

Change-Id: Ie15052d5a7dbd97d519303d37260945346a27779
Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/181505
Reviewed-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-01-07 04:53:20 +00:00
Randall Spangler
c0ec787ba1 Add battery_get_params()
The charge state machine asks for all of this stuff at the same time
anyway.  Bundling it into a single function removes a number of
redundant (and painfully slow) I2C reads.

Also refactor the battery debug command so it doesn't have so many
local variables all in one function; it was consuming considerably
more stack space than any other debug command.

Spring still needs low-level access to the smart battery, so move the
two functions it needs directly into the Spring implementation.

BUG=chrome-os-partner:20881
BRANCH=none
TEST=charge/discharge rambi, pit and spring; watch debug messages and
     LED and output of 'battery' debug command.  All should behave the
     same as before.  Then run 'taskinfo' and see that the console task
     has at least 20 bytes unused.

Change-Id: I951b569542e28bbbb58853d62b57b0aaaf183e3f
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/177797
2013-12-02 22:03:51 +00:00
Randall Spangler
870b7ebb78 cleanup: charge state header
Remove old TODO and function which no longer exists.

BUG=none
BRANCH=none
TEST=compile all platforms

Change-Id: I81c5ddb3d0e156d455be1af82f12d8d4f30e1bc8
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/174393
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2013-10-25 01:32:21 +00:00
Randall Spangler
99157c265c cleanup: Battery header files and filenames
battery.h is the high-level interface.  battery_smart.h is the
low-level interface.  Most things don't need the low-level interface,
but were including smart_battery.h solely to get at battery.h.  Fixed
this.  Also merged battery_pack.h into battery.h, since it was odd to
split that data across multiple header files.  Tidied the function
comments in battery.h as well.

No functional changes, just renaming files and adding comments.

BUG=chrome-os-partner:18343
BRANCH=none
TEST=build all boards; pass unit tests

Change-Id: I5ef372f0a5f8f5f36e09a3a1ce24008685c1fd0d
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/171967
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2013-10-07 18:30:50 +00:00
Dave Parker
33f8086c90 Track the duration of each charge/discharge state.
BUG=chromium:267146
BRANCH=falco,peppy
TEST=Manual. Observe charge state messages on the ec console.

Change-Id: I25f04db56bf62394b5bb2e0d56edbda3a0bb5e25
Signed-off-by: Dave Parker <dparker@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/64280
2013-08-02 12:16:43 -07:00
Rong Chang
6c280b1b32 Move TPSChrome charging temperature range to battery pack
This change moves vendor specific temperature ranges to battery pack
files or board setup files. And added a host test case to verify that
does not change x86 smart battery charging state machine behavior.

BUG=chrome-os-partner:21181
BRANCH=None
TEST=manual
  build test: util/ecmakeall.sh
  hosttests: make hosttests && make runtests

Change-Id: I48e76826b5555f64b78e3c063ce5f02416c72aa2
Signed-off-by: Rong Chang <rongchang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/62978
Reviewed-by: Vic Yang <victoryang@chromium.org>
2013-07-24 13:07:13 -07:00
Dave Parker
50ebe05652 Peppy: Detect physical presence of battery before waking it
BUG=chrome-os-partner:20889
BRANCH=peppy
TEST=Power device without battery. It should boot with no 30
second delay. The battery LED blinks orange indicating a
battery error.

Change-Id: Iea4f5644ae223b60dc8058dc52e06405e275c001
Signed-off-by: Dave Parker <dparker@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/61820
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: Marc Jones <marc.jones@se-eng.com>
2013-07-19 17:02:18 -07:00
Bill Richardson
0bfb7ddd07 Replace generated CONFIG_TASK_ macros with HAS_TASK_
CONFIG_ macros should be set directly. Expanding the task names in the same
way made it difficult to tell what was a configuration choice and what was
due to changes in ec.tasklist

BUG=chrome-os-partner:18343
TEST=build all, run link
BRANCH=none

Change-Id: Ib82e34f974238ee2dd216f33b701b6f4c6a4f1f1
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/49098
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-04-24 16:32:58 -07:00
Bill Richardson
c747652e49 Allow building without battery charging
Some experimental boards may want to build without a battery charging task
to make bringup easier.

BUG=chrome-os-partner:18343
TEST=build all boards
BRANCH=none

Change-Id: I4269fea4046325241ad7720ec3457b0534aadda3
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/48974
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-04-24 00:05:52 -07:00
Randall Spangler
05f496759f Add external power present flag to charge_get_flags()
Modules that need to find out about charge/power state no longer need
to use the lower-level switch API.

(This will matter more in future CLs which handle conditions like
"external power present, but at low power so we're doing battery
assist" - that can simply be state=discharging,flags=external_power_present.

BUG=chrome-os-partner:18256
BRANCH=none
TEST=add AC power, UI shows charging indicator; remove AC, indicator goes away

Change-Id: I62130a4e089297fa47ab03f6a76082593c936761
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/45515
Reviewed-by: Vic Yang <victoryang@chromium.org>
2013-03-15 09:07:58 -07:00
Randall Spangler
75acd4065a Clean up power LED state machine on link
The power LED now has its own tick-based handler which knows how to
blink the LED and resend the desired LED state to work around the
flaky 1-wire connection.

Removes a bunch of LED state code from charge_state.c.

No user-visible impact.  Does not need to go into link branch.

BUG=chromium-os:18256
BRANCH=none
TEST=manual

1) Discharge battery to <97%
2) Plug in AC.  LED=yellow
3) 'ectool chargeforceidle 1' from root shell.  LED=blinking green/off.
4) 'ectool chargeforceidle 0' from root shell.  LED=yellow.
5) Wait for battery >= 97% (or 'battfake 98' from EC console).  LED=green.
6) Unplug battery.  LED=red (may take 10 sec).
7) Replug battery.  LED=green.

Change-Id: I999ee3e1abe269bb3f737bbc75e0b872316605ce
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/45469
Reviewed-by: Vic Yang <victoryang@chromium.org>
2013-03-14 15:44:14 -07:00
Randall Spangler
e60f1ab224 Give the AP 30 sec warning before shutting down due to low battery
This allows the AP to shut down cleanly.  If it doesn't shut down in
that time period, the EC will forcibly shut it down.

BUG=chrome-os-partner:17124
BRANCH=link
TEST=manual

1. With system off,
  - battfake 2 -> EC hibernates immediately

2. With system on,
  - battfake 2 -> battery shutdown event posted to AP
  - power off system manually within 30 sec -> EC hibernates

3. With system on,
  - battfake 2 -> battery shutdown event posted to AP
  - do not power off AP
  - after 30 sec, EC shuts down AP then hibernates

4. With system on,
  - battfake 2 -> battery shutdown event posted to AP
  - after 15 sec, apply AC power
  - system does NOT shut down
  - remove AC power -> battery shutdown event posted to AP
    (because battfake 2 is still faking 2% battery left)
  - after 30 sec, EC shuts down AP then hibernates
    (check to make sure the full 30 sec elapses; the timer
     should have been restarted when AC power was removed;
     if the EC shuts down the AP immediately this is a
     failure indicating the timer is still running from
     the first shutdown event)

Change-Id: I1a13765f501d705d3a580b2acbbb173d47e020ff
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/44413
2013-03-05 10:26:21 -08:00
Randall Spangler
d86df6c388 Add reinit state to charge_state module to distinguish it from at-ec-boot init
This is a precursor to changing the switch state machine to delay
powering on the AP until the charge_state module knows if there's
enough power to do so (which it will know when it leaves the INIT
state).

BUG=chrome-os-partner:17124
BRANCH=link
TEST=manual

1. Reboot EC on battery power.  See charge state init->discharging
2. Plug in AC.  See charge state discharging->reinit
(charge state will then transition to some other charging or idle state
based on battery level)

Change-Id: Ia02cc8b37e9b5e8d6dd8c2fbfdf14e385694b1bf
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/44291
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2013-02-28 16:12:05 -08:00
Randall Spangler
695289cfe6 Add console command to fake battery state of charge
The new 'battfake' command is really handy for testing low-battery
shutdown logic.

BUG=chrome-os-partner:17124
BRANCH=link
TEST=from EC console:
	  reboot
	  battfake -> using real battery level
	  power on system -> lightbar should be blue
	  battfake 5
	  lightbar turns red after a few seconds
	  UI shows battery is very low
	     (shows <5% due to different kernel math)
	  'ectool battery' from root shell shows present capacity ~5% of
	  	  design capacity
	  remove AC power
	  battfake 4
	  UI shows low-battery screen and shuts down (may take a minute)
	  battfake 50
	  power on system
	  UI shows battery at 45-55%
	  battfake 2 -> system shuts down immediately
	  battfake -1
	  power on system
	  UI shows actual battery level

Change-Id: I3180e321241c0f586f3baad2150fb6a2b2d2e242
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/43151
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2013-02-12 18:10:14 -08:00
Randall Spangler
1d916d7c6b Use SECOND and MSEC constants
We'd defined them in a number of different files.  This moves
definitions to timer.h, and uses them everywhere we have large delays
(since 10*SECOND is less typo-prone than 10000000).

Also add msleep() and sleep() inline functions.  No need for mdelay()
or delay(), since any delays that long should use sleep funcs instead
of spin-waiting.

BUG=chrome-os-partner:15579
BRANCH=none
TEST=boot system; taskinfo displays similar numbers to before

Change-Id: I2a92a9f10f46b6b7b6571759b1f8ab4ecfbf8259
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/36726
2012-10-29 16:52:49 -07:00
Rong Chang
e679d8504d link: Revive under voltage protection battery pack
Experiments showed that some UVP batteries took ~30 seconds to restart
its gas gauge IC. This change adds 30 seconds polling check to determine
the condition.

Signed-off-by: Rong Chang <rongchang@chromium.org>
BRANCH=link
BUG=chrome-os-partner:13923
BUG=chrome-os-partner:14094
TEST=manual
  Disconnect battery and plug in charger. The charging LED should turn
  red after 30 seconds.

Change-Id: I425e63c428aeeaf1468bc2f9886457de1145cada
Reviewed-on: https://gerrit.chromium.org/gerrit/34886
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Ready: Rong Chang <rongchang@chromium.org>
Tested-by: Rong Chang <rongchang@chromium.org>
2012-10-08 23:05:45 -07:00
Randall Spangler
3c06f602b6 link: Add charge_near_full state
Tell the host the battery is no longer charging when it hits 97%, and
set the power adapter LED to green.

This solves several problems:

1) The last 3% of charge takes a looong time.  Kernel/ACPI/UI already
have a hack to show the battery as charged when it's about 3% from
full, but the EC still showed a yellow LED.

2) If the system is charged and you briefly unplug the adapter, the
LED turned yellow for a long time as it slowly trickle-charged.  Now
it goes right to green.

3) A fully-charged battery will drop below 100% charge as it settles,
but won't accept more current at that time.  This caused the LED to
turn yellow and stay there until the battery finally settled down to
~96%, at which point it'd accept more current and top itself off.  The
whole time it did this, the kernel/ACPI/UI hack from (1) would keep
reporting "battery full".  Now the LED stays green too.

BUG=chrome-os-partner:11248
BRANCH=link
TEST=manual

- Discharge system to <95% full.
- Plug adapter in.  LED should come on yellow.
- At around 97% full, the LED should turn green.
- Around that the UI will display "battery full".
  (Note that due to rounding, the UI may take a few minutes to display
   "battery full" after the LED goes green; that's ok)
- Unplug and replug adapter.  LED should come on green.  UI still reports
  "battery full".

Change-Id: Ie56fbf3a05239e73d2c765bb98d36aa5cfedc2ef
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/34452
2012-10-02 16:05:17 -07:00
Randall Spangler
56ce828309 link: Don't set power LED green until second idle
Currently, the charge state machine sets the power LED green the first
time it hits IDLE.  This causes the LED to briefly flash green when
the adapter is inserted, because the state machine goes
discharging->init->idle->charging.

Instead, add a new idle0 state in between init and idle which does not
set the power LED.  This allows the state machine to go
discharging->init->idle0->charging, so the LED only goes from off->yellow.

If the system is actually fully charged, it'll go init->idle0->idle
and show green.

BUG=chrome-os-partner:14630
BRANCH=link
TEST=manual

- Remove adapter and allow system to discharge a bit
- Insert adapter
- Should see LED go from off directly to yellow
- Wait for charge
- Should see LED go green

Change-Id: I9b77f01fad27c8574133211c9fe250486609f3c1
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/34387
Reviewed-by: Rong Chang <rongchang@chromium.org>
2012-10-01 23:50:16 -07:00
Randall Spangler
c51a8982ff link: If discharging and system is off, only poll battery once a minute
This reduces power consumption in S3/S5 because the EC doesn't need to
poll the battery every 500ms.

BUG=chrome-os-partner:9676
BRANCH=link
TEST=manual

As much as can be tested with the current debug information:

- Boot system with AC adapter in.  Charge state machine should go to
  charging state.
- Remove AC adapter.  Charge state -> discharging.
- Shut system down.
- Plug AC adapter in.  Charge state -> init -> charging over the course of
  a few seconds (NOT a minute).
- Remove AC adapter.  Charge state -> discharging.

Really good testing requires a source-level change.  Hack in a line of
debug output above task_wait_event(sleep_next) in
charge_state_machine_task() which prints how long the charge state
machine is sleeping.  It should sleep for ~250ms when charging, ~500ms
when discharging and the system is on, or ~60000ms when discharging
and the system is off.  (I did this when writing this change, but
removed it because it clutters up the debug console output.)

Change-Id: I7d3e291fbc40bfcc67d1fb4982d91f0e6bf2e785
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/33921
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Rong Chang <rongchang@chromium.org>
2012-09-25 10:56:43 -07:00
Vic Yang
29d478c92b Revert "Set power LED to green when we are trickle charging nearly full"
This reverts commit f322e1b96a.

Now that we notify kernel when charge_full changes, this workaround
should be abandoned.

BUG=chrome-os-partner:11248
TEST=Check power LED still works.

Change-Id: I87c269dcf4cb6b9f0da2472f139e39cced28232b
Reviewed-on: https://gerrit.chromium.org/gerrit/29147
Reviewed-by: Rong Chang <rongchang@chromium.org>
Commit-Ready: Vic Yang <victoryang@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
2012-08-03 08:04:16 -07:00
Randall Spangler
e5bdf41f39 Add interface to charge_state for lightbar
Use these functions to get charging state and battery percent.  Use
power_ac_present() from power_button.h to find out if AC adapter is present.

BUG=chrome-os-partner:8039
TEST=none

Change-Id: Ied670c297be316b0b8fa56a450a1566470099b5b
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27830
2012-07-19 11:35:21 -07:00
Vic Yang
f322e1b96a Set power LED to green when we are trickle charging nearly full
When battery is nearly full, battery sometimes demands for very low
current and we are actually trickle charging. This causes the last part
of charging process very long, but the actual charged amount is only few
mAh. Let's set power LED to green in this case so that user doesn't feel
the device is charging forever.

BUG=chrome-os-partner:11248
TEST=Charge the battery to nearly full. Disconnect and connect AC power.
     Check the power LED is green when we are trickle charging.

Change-Id: Ide108778232e9f1d3abe6b61af7518af25040d10
Reviewed-on: https://gerrit.chromium.org/gerrit/27264
Commit-Ready: Vic Yang <victoryang@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2012-07-18 09:31:27 -07:00
Rong Chang
3b0e13173d Debounce charging voltage when cross 8.0V
Link battery pack specification suggested a lower charging current
when voltage pass 8.0V. But the lowering the current in constant
current phase leads voltage drop. And the battery goes back to
high current zone, < 8.0V.

This CL adds a 10 seconds debounce time to prevent charging current
change too quickly.

Signed-off-by: Rong Chang <rongchang@chromium.org>
BUG=chrome-os-partner:9572
TEST=manual
  watch battery V+ on oscilloscope when charging voltage cross 8.0V

Change-Id: I002f941e33b029e38f813ab2e292c6b73a054352
Reviewed-on: https://gerrit.chromium.org/gerrit/27275
Commit-Ready: Rong Chang <rongchang@chromium.org>
Reviewed-by: Rong Chang <rongchang@chromium.org>
Tested-by: Rong Chang <rongchang@chromium.org>
2012-07-15 22:01:14 -07:00
Randall Spangler
4f34d3f9ef Cleanup - includes go in include dir
Signed-off-by: Randall Spangler <rspangler@chromium.org>

BUG=none
TEST=if it builds, it works

Change-Id: I2064f3eed4790051312a5a53ef742dcf79c4ee9d
2012-05-25 09:59:58 -07:00