summaryrefslogtreecommitdiff
path: root/include/charge_state.h
Commit message (Collapse)AuthorAgeFilesLines
* Update license boilerplate text in source code filesstabilize-quickfix-15278.72.B-ishstabilize-quickfix-15183.78.B-ishstabilize-15446.B-ishstabilize-15439.B-ishstabilize-15432.B-ishstabilize-15429.B-ishstabilize-15415.B-ishstabilize-15395.B-ishstabilize-15393.48.B-ishstabilize-15381.B-ishstabilize-15364.B-ishstabilize-15361.B-ishstabilize-15359.B-ishstabilize-15359.58.B-ishstabilize-15359.50.B-ishstabilize-15359.45.B-ishstabilize-15335.B-ishstabilize-15329.59.B-ishstabilize-15329.44.B-ishstabilize-15317.B-ishstabilize-15301.B-ishstabilize-15300.B-ishstabilize-15278.64.B-ishstabilize-15251.B-ishstabilize-15245.B-ishstabilize-15236.66.B-ishstabilize-15208.B-ishstabilize-15207.B-ishstabilize-15185.B-ishstabilize-15185.7.B-ishstabilize-15183.82.B-ishstabilize-15183.69.B-ishstabilize-15183.14.B-ishstabilize-15174.B-ishstabilize-15167.B-ishstabilize-15129.B-ishstabilize-15122.B-ishstabilize-15120.B-ishstabilize-15117.86.B-ishstabilize-15117.48.B-ishstabilize-15117.111.B-ishrelease-R114-15437.B-ishrelease-R113-15393.B-ishrelease-R112-15359.B-ishrelease-R111-15329.B-ishrelease-R110-15278.B-ishrelease-R109-15237.B-ishrelease-R109-15236.B-ishrelease-R108-15183.B-ishrelease-R107-15117.B-ishishfirmware-ti50-prepvt-15315.B-ishfirmware-skyrim-15390.B-ishfirmware-skyrim-15369.B-ishfirmware-nissa-15217.B-ishfirmware-nissa-15217.45.B-ishfirmware-nissa-15217.126.B-ishfirmware-duplo-15151.B-ishfirmware-corsola-15194.B-ishfactory-trogdor-15210.B-ishfactory-skyrim-15384.B-ishfactory-nissa-15199.B-ishfactory-corsola-15197.B-ishfactory-corsola-15196.B-ishfactory-brya-15231.B-ishMike Frysinger2022-09-141-1/+1
| | | | | | | | | | | | | | Normally we don't do this, but enough changes have accumulated that we're doing a tree-wide one-off update of the name & style. BRANCH=none BUG=chromium:1098010 TEST=`repo upload` works Change-Id: I5b357b85ae9473a192b80983871bef4ae0d4b16f Signed-off-by: Mike Frysinger <vapier@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3893394 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* charge_state: provide stub definition of charge_want_shutdownJack Rosenthal2021-03-201-0/+7
| | | | | | | | | | | | | | | | | | | | | | | Common power sequencing code (e.g., sc7180 power sequencing) calls charge_want_shutdown() to check there is enough battery. If the charger hasn't been enabled, the power sequencing code is expected to never call charge_want_shutdown (this has already been implemented for intel x86, for example). However, there's a bunch of ARM power sequencing code which does not guard the calls, and adding a bunch of ifdefs or IS_ENABLED to them would look bad. Provide a stub definition which indicates the charger never wants a shutdown if there's no charging enabled. BUG=b:183054226 BRANCH=none TEST=compile sc7180 without charger Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: I1429be4262c005752be49668aeb7274e540d8342 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2774361 Reviewed-by: Simon Glass <sjg@chromium.org>
* zork: Ignore input current and always rampEdward Hill2020-09-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | CONFIG_CHARGE_RAMP_SW is designed to stop ramping if we are not using enough current (so we are actually testing that the supplier can give the current we ramp to). But this is checked using charge_is_consuming_full_input_current(), which only tests for battery charge between 2% and 95%. This fails to accurately reflect desire for input current, because the low battery might want to charge faster, and the AP might want extra power even with full battery. For zork, change charge_is_consuming_full_input_current() to always return true. This means we will always ramp. If we are not using the full input current, and the supplier cannot deliver it when we do, then we will detect the voltage drop and re-ramp, which seems fine. BUG=b:168569046 BRANCH=zork TEST=ramp with full battery Signed-off-by: Edward Hill <ecgh@chromium.org> Change-Id: Ic7c9b93bdd3856c9b05bd3a13e8c2a78aa883755 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2426950 Reviewed-by: Denis Brockus <dbrockus@chromium.org> Commit-Queue: Denis Brockus <dbrockus@chromium.org>
* charge: allow boards to customize max battery poll timeJett Rink2019-10-161-0/+3
| | | | | | | | | | | | | | Some designs need to keep their battery from going to sleep. Allow boards to specify their max delay for polling the battery. BUG=b:133375756 BRANCH=octopus TEST=Verify access battery once per 10 seconds by ec console. Change-Id: I7e70a45fe643af567434f8187344e0e0d18d733c Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1865253
* config: Merge CONFIG_CHARGER_V2 into CONFIG_CHARGERKeith Short2019-09-181-2/+0
| | | | | | | | | | | | | | | | For all boards that defined CONFIG_CHARGER, CONFIG_CHARGER_V2 is also defined. Remove references to CONFIG_CHARGER_V2 from board header files. Replace CONFIG_CHARGER_V2 in common C modules with CONFIG_CHARGER when appropriate. BUG=b:139699769 BRANCH=none TEST=make buildall -j Change-Id: I6b54baf4ad2406bbed629b6b272dad9ea6a81280 Signed-off-by: Keith Short <keithshort@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1789420 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* usb: de-dup common code from old and new PD stackJett Rink2019-08-191-0/+7
| | | | | | | | | | | | | | We still need to pull out more common code between the two stacks, but this is scaffolding with a few examples. BRANCH=none BUG=b:137493121 TEST=unit tests pass Change-Id: Ibd9dda1e544e06f02aa3dde48ca7de1539700cfa Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1744655 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* LICENSE: remove unnecessary (c) after CopyrightTom Hughes2019-06-191-1/+1
| | | | | | | | | | | | | | | | Ran the following command: git grep -l 'Copyright (c)' | \ xargs sed -i 's/Copyright (c)/Copyright/g' BRANCH=none BUG=none TEST=make buildall -j Change-Id: I6cc4a0f7e8b30d5b5f97d53c031c299f3e164ca7 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1663262 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* common: replace 1 << digits, with BIT(digits)Gwendal Grignou2019-03-261-3/+3
| | | | | | | | | | | | | | | | Requested for linux integration, use BIT instead of 1 << First step replace bit operation with operand containing only digits. Fix an error in motion_lid try to set bit 31 of a signed integer. BUG=None BRANCH=None TEST=compile Change-Id: Ie843611f2f68e241f0f40d4067f7ade726951d29 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1518659 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* chgstv2: Notify on display percentage changeDaisuke Nojiri2018-11-081-0/+5
| | | | | | | | | | | | | | | | | | | | | This patch makes the charger task v2 notify HOOK_BATTERY_SOC_CHANGE handlers when the display charge percentage changes. This allows EC to update LEDs synchronously to the number on the display. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=b:109954565,b:80270446 BRANCH=none TEST=Verify charge LED changes to white (full) on Sona synchronously to the display percentage. TEST=Verify charge LED changes to blinking white (low) on Sona within 30 seconds synchronously to the display percentage. Change-Id: Ib2c587ad3307fe62b268a25a93344c88c6c137f3 Reviewed-on: https://chromium-review.googlesource.com/1309034 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
* charge_state: Change CHARGE_MAX_SLEEP_USEC to 1 minuteFurquan Shaikh2017-11-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | CHARGE_MAX_SLEEP_USEC was originally set to 1 minute (i.e. equal to POLL_PERIOD_VERY_LONG) in CL:191767. However, during re-factoring in CL:193876 it got changed to 1 second as charge_state_v1 used this value. Looking at the way CHARGE_MAX_SLEEP_USEC is used, value of 1 minute makes more sense because sleep_usec could be set to POLL_PERIOD_VERY_LONG when device is off or suspended. With the current logic in suspend/off state, sleep_usec is set to POLL_PERIOD_VERY_LONG and immediately gets reset to CHARGE_MAX_SLEEP_USEC in charger_task. This change fixes the above behavior by defining CHARGE_MAX_SLEEP_USEC as 1 minute. As a side-effect of this, we might not wake up early enough in case of critical battery. Thus, check if we need to shutdown on critical battery and adjust sleep time accordingly. BUG=b:69695376 BRANCH=None TEST=make -j buildall Change-Id: Ieba7279dc4b02c3d64022c3c5ac09fb869a3632d Signed-off-by: Furquan Shaikh <furquan@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/788181 Reviewed-by: Shawn N <shawnn@chromium.org>
* chg_ramp: Add charge_is_consuming_full_input_current().Aseda Aboagye2017-11-011-0/+10
| | | | | | | | | | | | | | | | | | | Most boards had an identical implementation for this function, previously known as board_is_consuming_full_charge(). To reduce copy paste, let's just move it to common code. Boards that charge ramp without a battery will have to define their own implementation, but there probably won't be any boards like that in the near future. BUG=None BRANCH=None TEST=make -j buildall Change-Id: Ic99a378ac26dfd35d7d718bf9376eacfa8609166 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/748919 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* charger: Add state for discharge + fullDaisuke Nojiri2017-03-031-0/+3
| | | | | | | | | | | | | | | | | | 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>
* cleanup: Remove charge_state_v1Sam Hurst2017-02-061-10/+2
| | | | | | | | | | | | | | | | 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>
* cleanup: Rename charge_temp_sensor_get_val() to charge_get_battery_temp()Vijay Hiremath2016-10-141-1/+1
| | | | | | | | | | | | | | | | | 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>
* COMMON: move precharge time to config.hRyan Zhang2016-06-011-1/+1
| | | | | | | | | | | | | | 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>
* charger: Change unlocked battery level ignore conditionsShawn Nematbakhsh2016-01-061-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* charger: Make critical battery shutdown timeout a config optionShawn Nematbakhsh2015-01-151-3/+0
| | | | | | | | | | | | | | | | 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>
* charger v2: Combine prevent_*_discharge functionsShawn Nematbakhsh2015-01-131-2/+1
| | | | | | | | | | | | | | | | 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
* power_button_x86: Inhibit AP power-on if battery level is too lowShawn Nematbakhsh2014-12-171-0/+6
| | | | | | | | | | | | | | | | | | | | 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>
* samus: add high battery temp warning to charge state machineAlec Berg2014-12-151-0/+2
| | | | | | | | | | | | | | | 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>
* samus: Allow samus to charge w/o battery or with dead batterystabilize-5942.BAlec Berg2014-06-091-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Fixed the stack overflow bug in 'battery' console command.stabilize-5784.0.BLouis Yung-Chieh Lo2014-04-211-0/+7
| | | | | | | | | | | | | | | | | 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>
* Move common charge_state time constants to a common headerBill Richardson2014-04-111-0/+15
| | | | | | | | | | | | | | | | 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
* Create stub files for charge_state_v2.cBill Richardson2014-03-201-0/+79
| | | | | | | | | | | | | | | | | | | 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>
* Rename charge_state.[ch] to charge_state_v1.[ch]Bill Richardson2014-03-201-149/+16
| | | | | | | | | | | | | | | 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>
* Remove conditional declaration of charge_want_shutdown()Bill Richardson2014-03-201-4/+0
| | | | | | | | | | | | | | 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>
* cleanup: nyan: remove unnecessary dependence to pmu_tpschrome.hLouis Yung-Chieh Lo2014-02-141-0/+5
| | | | | | | | | | | | | | 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>
* Include battery fuel gauge temp sensor in temperature sensorsRandall Spangler2014-02-081-0/+11
| | | | | | | | | | | | | | | | | | | | 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>
* 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>