summaryrefslogtreecommitdiff
path: root/include/charge_state_v2.h
Commit message (Collapse)AuthorAgeFilesLines
* charge_state_v2: remove duplicated VIRTUAL_BATTERY_ADDR_FLAGSTing Shen2020-05-271-3/+0
| | | | | | | | | | | | | | | | | | | | | The macro VIRTUAL_BATTERY_ADDR_FLAGS is defined in both charge_state_v2.h and virtual_battery.h. Although identical macro definition will not cause any problem during compile, it's better to remove one if them. Clean up by remove the charge_state_v2.h one. BUG=None TEST=make buildall BRANCH=None Signed-off-by: Ting Shen <phoenixshen@google.com> Change-Id: Ife6a260091caf74b25f5ef21a5cd6e04f0f17bae Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2211606 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Ting Shen <phoenixshen@chromium.org> Tested-by: Ting Shen <phoenixshen@chromium.org> Auto-Submit: Ting Shen <phoenixshen@chromium.org>
* OCPC: Add concept of active charger ICAseda Aboagye2020-05-011-0/+17
| | | | | | | | | | | | | | | | | | | | | | | With OCPC, one charger IC per Type-C port, there are now multiple charger ICs present in the system. This commit adds the beginning of OCPC support by adding the notion of an active charger IC. Charge Manager will select the active charger IC based upon the charge port. Boards must define this mapping in a board specific function. Additionally, this commit adds chgnum as a parameter to charger_set_input_current_limit(). BUG=b:148981052 BRANCH=None TEST=With other patches, verify that the active charger IC is able to be saved and retrieved. Change-Id: Iba4a8958171ad6e1630b0ca3d07d128bc1f2c4dd Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2135963 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
* usb_pd: request preferred voltage PDOYilun Lin2019-12-091-0/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add CONFIG_USB_PD_PREFER_MV to support PD will request preferred voltage. One should define pd_pref_config, including preferd voltage, e.g. 5000, and PD_PREFER_BOOST or PD_PREFER_BUCK based on the board charging efficiency. Also, system PLT power is needed for evaluating board's desired power. The option will try to find a most fit PDO: 1. Pick the PDO which fulfills the system desired power. If a preferred voltage PDO doesn't provide enough power, it will be skipped. 2. If none of the PDO meets the preferred voltage, it will pick the closest voltage PDO based on prefer boost or prefer bulk. 3. The system desired power will be constantly updated when system in constant voltage stage (battery percent > 70%). This is done by monitoring the battery charging current. 4. If the system desired power changes, it will re-evaluate the PDO and send request if has a better fit. TEST=Set prefer_mv to 5000 and ensure PD voltage could pick 9V/12V when desired voltage > 15W (5V/3A) and pick 5V when desired voltage <= 15W BUG=b:141170279 b:141903096 b:144073892 BRANCH=kukui Change-Id: I94646cb1c74c10cf8db889f19c3df6339844042c Signed-off-by: Yilun Lin <yllin@chromium.org> Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1871499
* Remove __7b, __8b and __7bfDenis Brockus2019-07-201-1/+1
| | | | | | | | | | | | | | | | | | | The extentions were added to make the compiler perform most of the verification that the conversion was being done correctly to remove 8bit addressing as the standard I2C/SPI address type. Now that the compiler has verified the code, the extra extentions are being removed BUG=chromium:971296 BRANCH=none TEST=make buildall -j TEST=verify sensor functionality on arcada_ish Change-Id: I36894f8bb9daefb5b31b5e91577708f6f9af2a4f Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1704792 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* Use 7bit I2C/SPI slave addresses in ECDenis Brockus2019-07-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Opt for 7bit slave addresses in EC code. If 8bit is expected by a driver, make it local and show this in the naming. Use __7b, __7bf and __8b as name extensions for i2c/spi addresses used in the EC codebase. __7b indicates a 7bit address by itself. __7bf indicates a 7bit address with optional flags attached. __8b indicates a 8bit address by itself. Allow space for 10bit addresses, even though this is not currently being used by any of our attached devices. These extensions are for verification purposes only and will be removed in the last pass of this ticket. I want to make sure the variable names reflect the type to help eliminate future 7/8/7-flags confusion. BUG=chromium:971296 BRANCH=none TEST=make buildall -j Change-Id: I2fc3d1b52ce76184492b2aaff3060f486ca45f45 Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1699893 Reviewed-by: Jack Rosenthal <jrosenth@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>
* power: Allow board to take custom action on G3 timer expirationDaisuke Nojiri2019-03-281-5/+1
| | | | | | | | | | | | | | | | | | | | | This patch introduces board_system_is_idle callback function. It's called when system is in G3. A board can customize its action taken when system is idle in G3 using battery thresholds, expiration timer, etc. determined at runtime. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=none BRANCH=nami,strago,coral TEST=Verify Vayne cut off battery on G3 idle expiration while other Nami's hibernate. Change-Id: I6118a074ac7d844b99d9c0f3eb638b72d5894008 Reviewed-on: https://chromium-review.googlesource.com/1512623 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* chgstv2: Allow board to set charge level for shutdownDaisuke Nojiri2019-03-121-0/+8
| | | | | | | | | | | | | | | | | Currently, BATTERY_LEVEL_SHUTDOWN is statically determined. This patch allows it to be set at runtime. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=b/123727148 BRANCH=nami,strago,coral TEST=Verify Vayne shuts down when soc <= 4 in s0 and s5. Change-Id: I535c451e97ebf6bc735c46d7789d4b56ed82914b Reviewed-on: https://chromium-review.googlesource.com/1512619 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* chgstv2: Make board_critical_shutdown_check specify action on critical socDaisuke Nojiri2019-03-061-4/+15
| | | | | | | | | | | | | | | | | | | | | | | | | Currently, board_critical_shutdown_check is used only in the context of CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF. It returns true to cutoff the battery or false to take no action. This patch extends board_critical_shutdown_check to allow it to control what actions to take on critical battery condition. With this change, each board can also customize critical battery actions with more granularity (per OEM, BOARD_VERSION, etc.). Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=b/123727148 BRANCH=nami TEST=Verify a battery is cutoff at critical low charge on Scarlet and DUT wakes up by AC plugin on cros/firmware-scarlet-10388.B. Change-Id: Id49e860b05e21c3bfa4d75f27c48b55c2a3ad95f Reviewed-on: https://chromium-review.googlesource.com/1487113 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* scarlet: Cut off battery in a custom battery conditionPhilip Chen2018-08-021-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We want to shut down AP when the battery charge drops below BATTERY_LEVEL_SHUTDOWN. Then we want to cut off the battery to protect the battery from over-discharging. But we don't want to cut off the battery right after the battery charge drops below BATTERY_LEVEL_SHUTDOWN so that we can retain the RTC timestamp for functionality reasons. So let's add a custom check before we move on to cut off the battery in shutdown_on_critical_battery(). BUG=b:68723854 BRANCH=scarlet TEST=make buildall -j TEST=keep the battery discharging, see AP shut down when battery charge hits 2% and later EC cut off battery when battery voltage hits 3.2V Change-Id: I9950cf32558c11a2f55ee6ca64c157146d449110 Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/1121593 Reviewed-by: Alexandru M Stan <amstan@chromium.org> Commit-Queue: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Trybot-Ready: Philip Chen <philipchen@chromium.org> (cherry picked from commit 91171747b4ca01ac929186c96d4d6aa3489c60ab) Reviewed-on: https://chromium-review.googlesource.com/1140795 Commit-Ready: Philip Chen <philipchen@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
* chgstv2: Fix manual control via EC console.Aseda Aboagye2018-06-011-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | There was a recent change to save the manual setting of charge current and voltage, however it was done so assuming that the parameters were set via the host command interface. (CL:922069) However, there are times where the charge voltage/current would like to be manipulated without booting the AP. This commit simply makes the EC console command work again. BUG=None BRANCH=None TEST=make -j buildall TEST=Flash nocturne, `chgstate idle on; charger current 256; charger voltage 7400`; verify that the charge voltage and current is actually changed. Change-Id: Id250d9704f8509162518495556603950248fb267 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/1081120 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Scott Collyer <scollyer@chromium.org>
* charge_state_v2: Hibernate base in S5 with no ACNicolas Boichat2018-03-281-0/+6
| | | | | | | | | | | | | | | | | | Tell the base to hibernate when we are in S5, and no AC is connected. Also, wake the base when AC status changes (S5), and when the system transistions out of S5. BRANCH=none BUG=b:71874971 TEST=1. Lid EC console: apshutdown => Check that Base EC hibernates 2.a. Lid EC console: powerb; => Check that base reconnects 2.b. Connect/disconnect adapter: check that base disconnects and reconnects Change-Id: I5e9a4afc64a07ad92f37d171a78a914d26f07c8e Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/958814 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* charge_state_v2: Basic dual-battery charging algorithmNicolas Boichat2018-01-261-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | First version of the algorithm, some TODOs are left in the code but this, generally, works reasonably well. When charging, we allocate input current in this general order: - Base system (fixed, low, number) - Lid system (based on PSYS) - Lid battery (estimating how much current the battery actually requires) - Base battery (similar estimation) - Provide everything else to lid When discharging, we generally: - First discharge the base battery - Then discharge the lid battery BRANCH=none BUG=b:71881017 TEST=Flash lux and wand, EC-EC communication works, adapter power is split in a sensible way, and discharging works fine. Change-Id: I8a4f87963962fc5466b2fedf1347eb4dadd35740 Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/659460 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* charge_state_v2: Add charge_set_output_current_limit functionNicolas Boichat2018-01-041-0/+13
| | | | | | | | | | | | | | | | | | | | | | This function sets up and enables "OTG" mode on the charger chip (i.e. use the charger to provide power from the battery). It also records the output current in curr.output_current, to make sure that the charger loop is aware that current is provided externally. We also add a CONFIG_CHARGER_OTG to remove these functions on boards that do not require it. BRANCH=none BUG=b:65697962 TEST=On wand, when discharging, battery status is updated every 5 seconds (and not every 60 seconds). Change-Id: Ibf93933436f3eb24552a8e1eb9d97522fca2ce79 Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/842743 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* charger: Add CONFIG_CHARGE_STATE_DEBUGRyan Zhang2017-09-111-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | Servo / Suzy-Q related debugging methods is a big challenge in factory especially after servo debug header is removed. Expose some information to OS from EC will do a great help for massive production. + expose charge/battery related state to ectool 1. chg_ctl_mode 2. manual_mode 3. battery_seems_to_be_dead 4. battery_seems_to_be_disconnected 5. battery_was_removed 6. disch_on_ac (learn mode state) BUG=b:65265543 BRANCH=master TEST=`ectool chargestate param 0x20000~0x20006 get correct state` Change-Id: Ic2ed38e2eb9def01be29729fa1fe1959eb73fe43 Signed-off-by: Ryan Zhang <ryan.zhang@quanta.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/646412 Reviewed-by: Shawn N <shawnn@chromium.org>
* charger_profile: Add common code for charger profile overrideVijay Hiremath2017-01-021-23/+0
| | | | | | | | | | | | | | | | | | | Added common code for charger profile override for fast charging. Fast charging configs can be defined in the respective board battery file and use the common code for imposing the custom data. BUG=chrome-os-partner:59393 BRANCH=none TEST=Enabled the config on Reef. Manually overrode the temperature and voltage. Observed correct charge profile config is selected for each tests. Change-Id: I075d271258470b98d38e4d5395d749469d3fd469 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/407928 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
* i2c_passthru: fix virtual battery operationphilipchen2016-12-141-11/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | In some cases, the virtual battery code creates transactions that violate SB spec. One example: If the host command is structured as two messages - a write to 0x03 (reg addr), followed by two bytes of write data, the first byte of the second message (write data) will be sent to virtual_battery_read(), as if it were a reg read request. Let's do the following change for virtual battery: 1. Parse the command more carefully with state machines. 2. Support write caching for some critical registers. 3. Cache more attributes (0x03 and 0x0f). BUG=chrome-os-partner:59239, chromium:659819 BRANCH=none TEST='power_supply_info' works on kevin Change-Id: Icdeb12b21f0dc3c329f29b206b7b9395ca4c9998 Reviewed-on: https://chromium-review.googlesource.com/407987 Commit-Ready: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* charge_state_v2: Limit i/p current to meet allowed MAX i/p system powerVijay Hiremath2016-12-051-1/+2
| | | | | | | | | | | | | | | | | | | | | If battery is not present, input current is set to PD_MAX_CURRENT_MA. If the input power set is greater than the maximum allowed system power, system might get damaged. Hence, limit the input current to meet maximum allowed input system power. BUG=chrome-os-partner:58498 BRANCH=none TEST=Manually tested on Reef. Removed the battery & using 'charger' console command observed the following. With Zinger charger at 20V - Input current is set to 2.25A With Type-C & other chargers - Input current is set to 3A Change-Id: Ife8686f322e095aa74b740a7c469bfe87107fb9a Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/397865 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Shawn N <shawnn@chromium.org>
* i2c: get battery information from charge stateMary Ruthven2015-10-271-0/+15
| | | | | | | | | | | | | | | | | | ARM systems currently use SBS kernel driver which talks to the battery through I2C passthu in the EC. Instead when asking for battery information try getting it from the charge state machine first, and then try the battery if charge state does not have the information. This reduces latency by cutting out the battery response time. BUG=chromium:484841 BRANCH=none TEST=check that power_supply_info works properly on Jerry Change-Id: If4da15ccabe412adc31fc94b189089ebb3e9265c Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/307905 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org>
* samus: fix charge state machine's handling of low power chargersAlec Berg2014-12-151-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | On samus it is possible to have AC plugged in but have the battery discharging. So, add a new variable to charge state machine for battery charging status and use that where necessary. For example, the low battery shutdown code should now be based on whether or not battery is charging rather than if AC is present. This also changes the hibernate behavior when battery is low. The change is to wait 30 seconds in G3 of low battery with no charging before hibernating because for some chargers, like a USB PD charger, the charger may increase it's current limit after a little bit of time. BUG=chrome-os-partner:34485 BRANCH=samus TEST=test on samus. use low power charger and make sure that ectool battery shows the "DISCHARGING" flag. use zinger and see "CHARGING" flag. also use power_supply_info to make sure that the battery state accurately reflects reality. Change-Id: I8ac0267dd393071c4ca1fa24fbc9a13bf27848a9 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/235491 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* samus: ryu: fix charge state machine init of input currentstabilize-6146.BAlec Berg2014-08-121-0/+10
| | | | | | | | | | | | | | | | | | | | | | Currently charge state machine resets input current limit to default every time AC is connected. Problem is by the time charge state machine gets around to setting input current, it could have already been set by successful PD negotiation, and this ends up overriding that value. This fix has the state machine store desired input current limit, as determined from PD negotation or any other place, and send last desired input current limit on AC connect. BUG=chrome-os-partner:24461 BRANCH=none TEST=load on samus, test toggling between "pd 0 dev 5" and "pd 0 dev 20", and test plugging and unplugging zinger numerous times, and verify charger command always gives the expected input current limit based on PD negotiation. Change-Id: I18d8acc9e2085739e783c9c70c682d46bcce7fdb Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/211639 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* Add host command to control charge state v2Bill Richardson2014-04-051-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This replaces the obsolete and temporary (ha!) EC_CMD_CHARGE_DUMP host command with EC_CMD_CHARGE_STATE. This is used to monitor and adjust the new charge state implementation, including any board-specific customizations. This command is a single catch-all command with multiple subcommands (similar to EC_CMD_LIGHTBAR_CMD) so that we don't have to keep adding new top-level host commands just to support incremental changes. BUG=chrome-os-partner:23776 BRANCH=ToT TEST=manual From the AP, try these commands: ectool chargestate show ectool chargestate param ectool chargestate param <NUM> ectool chargestate param <NUM> <VALUE> Watch the EC console and use its "chg" command to verify the effects of setting various params. Note: the Samus-specific fast-charging profile override is param 0x10000. You can check it with the EC console "fastcharge" command. Change-Id: Iad2f773a085bc25c05073b3eed9866f122ae9d78 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/193305 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Add charge_state_v2 algorithm for use by SamusBill Richardson2014-04-011-0/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a complete rewrite of the charge_state task used by x86 platforms. Rather than having a bunch of state-specific functions, each with their own error handling and special cases, this is organized like so: Forever: 1. Read everything we can from the battery and charger. 2. Figure out what we'd like to do (including error handling). 3. Allow for customization to override that. 4. Do it. Things I need to file bugs for are marked with "TODO(wfrichar)". I'll file the bugs after this CL goes in, so that they'll have something relevant to refer to. BUG=chrome-os-partner:20881 BRANCH=ToT TEST=manual make buildall -j Try it on Samus, watch it charge from nearly empty to full, both with and without fastcharge enabled. Also undefine CONFIG_BATTERY_PRESENT_CUSTOM, plug and unplug the battery to be sure the trickle charging logic is correct when it can't tell if the battery is present. Change-Id: I3935cd3b87f322eb52178f8a675a886c16b75d58 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/191767 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Create stub files for charge_state_v2.cBill Richardson2014-03-201-0/+14
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>