summaryrefslogtreecommitdiff
path: root/include/charge_state.h
Commit message (Collapse)AuthorAgeFilesLines
* rename power_state* to charge_state*Louis Yung-Chieh Lo2014-01-071-12/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Add battery_get_params()Randall Spangler2013-12-021-9/+6
| | | | | | | | | | | | | | | | | | | | | | | | 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
* cleanup: charge state headerRandall Spangler2013-10-251-9/+1
| | | | | | | | | | | | | 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>
* cleanup: Battery header files and filenamesRandall Spangler2013-10-071-1/+1
| | | | | | | | | | | | | | | | | | | | 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>
* Track the duration of each charge/discharge state.Dave Parker2013-08-021-0/+1
| | | | | | | | | | 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
* Move TPSChrome charging temperature range to battery packRong Chang2013-07-241-1/+1
| | | | | | | | | | | | | | | | | 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>
* Peppy: Detect physical presence of battery before waking itDave Parker2013-07-191-2/+5
| | | | | | | | | | | | | | 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>
* Replace generated CONFIG_TASK_ macros with HAS_TASK_Bill Richardson2013-04-241-1/+1
| | | | | | | | | | | | | | | 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>
* Allow building without battery chargingBill Richardson2013-04-241-1/+4
| | | | | | | | | | | | | | 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>
* Add external power present flag to charge_get_flags()Randall Spangler2013-03-151-0/+2
| | | | | | | | | | | | | | | | | | 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>
* Clean up power LED state machine on linkRandall Spangler2013-03-141-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Give the AP 30 sec warning before shutting down due to low batteryRandall Spangler2013-03-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Add reinit state to charge_state module to distinguish it from at-ec-boot initRandall Spangler2013-02-281-3/+6
| | | | | | | | | | | | | | | | | | | | | 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>
* Add console command to fake battery state of chargetoolchain-3701.42.Bstabilize-3701.81.Bstabilize-3701.46.Bstabilize-3701.30.0bstabilize-3701.30.0release-R26-3701.BRandall Spangler2013-02-121-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Use SECOND and MSEC constantsRandall Spangler2012-10-291-6/+0
| | | | | | | | | | | | | | | | | | 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
* link: Revive under voltage protection battery packRong Chang2012-10-081-0/+1
| | | | | | | | | | | | | | | | | | | | 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>
* link: Add charge_near_full stateRandall Spangler2012-10-021-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* link: Don't set power LED green until second idleRandall Spangler2012-10-011-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* link: If discharging and system is off, only poll battery once a minuteRandall Spangler2012-09-251-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Revert "Set power LED to green when we are trickle charging nearly full"Vic Yang2012-08-031-2/+0
| | | | | | | | | | | | | | | | This reverts commit f322e1b96a5a7400d283b2a6397e020e6200522c. 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>
* Add interface to charge_state for lightbarRandall Spangler2012-07-191-0/+10
| | | | | | | | | | | | 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
* Set power LED to green when we are trickle charging nearly fullVic Yang2012-07-181-0/+2
| | | | | | | | | | | | | | | | | | | 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>
* Debounce charging voltage when cross 8.0VRong Chang2012-07-151-1/+2
| | | | | | | | | | | | | | | | | | | | | 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>
* Cleanup - includes go in include dirRandall Spangler2012-05-251-0/+113
Signed-off-by: Randall Spangler <rspangler@chromium.org> BUG=none TEST=if it builds, it works Change-Id: I2064f3eed4790051312a5a53ef742dcf79c4ee9d