summaryrefslogtreecommitdiff
path: root/driver/battery
Commit message (Collapse)AuthorAgeFilesLines
...
* battery/max17055: Use macros to clean up duplicate codePhilip Chen2017-11-021-25/+25
| | | | | | | | | | | | | | BUG=none BRANCH=none TEST=manually test on Scarlet rev2 and confirm max17055 still initializes and works by 'battery' command Change-Id: I3f553a1392cc1c4364ac605111564501bd706ec2 Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/737712 Commit-Ready: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Philip Chen <philipchen@chromium.org>
* battery/max17055: Measure temperature using external thermistorPhilip Chen2017-10-241-0/+13
| | | | | | | | | | | | | | | | By default max17055 measures from internal temperature sensor. BUG=b:68170538 BRANCH=none TEST=place a heat source on top of the battery pack and see temperature rise from 'battery' command Change-Id: I1c0bb981e366a8a73d2e14e6c1fc92327069e8f1 Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/735080 Commit-Ready: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* battery/max17055: update battery remaining capacity message dynamicLin Huang2017-09-131-1/+9
| | | | | | | | | | | | | | kernel will get the battery info through command "ectool battery", so we need to get the remaining capacity dynamic. BUG=b:65494883 BRANCH=none TEST=run "ectool battery" in kernel, and get the battery info. Change-Id: Idf824f6dc1e72acd17156c03d81c0ca87adc109f Signed-off-by: Lin Huang <hl@rock-chips.com> Reviewed-on: https://chromium-review.googlesource.com/658160 Reviewed-by: Philip Chen <philipchen@chromium.org>
* battery/max17055: Specify desired charging voltage/currentPhilip Chen2017-08-211-2/+2
| | | | | | | | | | | | | | BUG=b:64821815, b:63870414 CQ-DEPEND=CL:621777 BRANCH=none TEST=plug in AC, and check 'charger' command on ec console Change-Id: Ic60bcab7fd0ccc2ea73471ac46e9b0b887f251d9 Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/621776 Commit-Ready: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* battery/max17055: Wait longer for initial configPhilip Chen2017-08-181-2/+2
| | | | | | | | | | | | | | | | | max17055 sometimes fails to finish configuration due to timeout. Let's wait longer. BUG=b:63870414 BRANCH=none TEST=boot scarlet rev1 10 times and ensure MODELCFG.REFRESH bit is cleared when retries value > 10. Change-Id: I62984c19014a244a378180bab6683e2e6f842cd1 Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/617653 Commit-Ready: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* battery/max17055: Process negative current/temperature rightPhilip Chen2017-08-181-2/+2
| | | | | | | | | | | | | | | | | | | | On max17055, current/temperature register values are in 2's complement format. Therefore we need to consider the case of negative values before doing bitwise operation. BUG=b:63870414 BRANCH=none TEST=run 'battery' command and confirm the reported discharge current looks reasonable. Change-Id: Iea0c554aecf2b410fc27b547e01ee7a583a0dd00 Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/617654 Commit-Ready: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* battery/max17055: Add max17055 fuel gauge driverPhilip Chen2017-07-271-0/+375
| | | | | | | | | | | | | | | | | BUG=chromium:736603 BRANCH=none TEST=Follow the steps below 1) add MAX17055 config to Scarlet and build the code 2) hook up max17055 eval board and a single cell battery 3) battery command from ec console shows reasonable numbers for temperature, voltage, and charge percentage Change-Id: I3f838ff92c591665e9f1d0a7ba636ff83d9b7612 Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/578300 Commit-Ready: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* cleanup: Remove charge_state_v1Sam Hurst2017-02-061-1/+1
| | | | | | | | | | | | | | | | 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>
* smart_battery: Cleanup smart battery & SB users codeVijay Hiremath2017-01-021-27/+41
| | | | | | | | | | | | | BUG=chrome-os-partner:61173 BRANCH=none TEST=Manually tested on Reef. Battery info works. Change-Id: I6e867eee38885186f8e63a934f52e826f0cf72fd Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/422998 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>
* smart_battery: Add console command to read ManufacturerAccess() dataVijay Hiremath2016-11-121-0/+57
| | | | | | | | | | | | | | | | | Added console command to read ManufacturerAccess() data on a given register block. BUG=chrome-os-partner:59660 BRANCH=none TEST=Enabled config on Reef. Successfully able to read ManufacturerAccess() data Change-Id: Ic86ae1b44ca8016634c48b54b1130d30fdd2d3fa Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/409638 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>
* smart_battery: Remove smart charger unreachable codeVijay Hiremath2016-10-111-10/+0
| | | | | | | | | | | | | | | | Smart battery code has I2C read/write code for smart chargers which is an unreachable code for few boards hence removed it. BUG=none BRANCH=none TEST=make buildall -j Change-Id: I79933f61893c66447c686a81073c92f6a16e2d48 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/396279 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: Add i2ctest console commandVijay Hiremath2016-09-231-0/+33
| | | | | | | | | | | | | | | | | | Added i2ctest console command to test the reliability of the I2C. By reading/writing to the known registers this tests provides the number of successful read and writes. BUG=chrome-os-partner:57487 TEST=Enabled the i2ctest config on Reef and tested the i2c read/writes. BRANCH=none Change-Id: I9e27ff96f2b85422933bc590d112a083990e2dfb Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/290427 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>
* cleanup: DECLARE_CONSOLE_COMMAND only needs 4 argsBill Richardson2016-08-243-18/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | Since pretty much always, we've declared console commands to take a "longhelp" argument with detailed explanations of what the command does. But since almost as long, we've never actually used that argument for anything - we just silently throw it away in the macro. There's only one command (usbchargemode) that even thinks it defines that argument. We're never going to use this, let's just get rid of it. BUG=none BRANCH=none CQ-DEPEND=CL:*279060 CQ-DEPEND=CL:*279158 CQ-DEPEND=CL:*279037 TEST=make buildall; tested on Cr50 hardware Everything builds. Since we never used this arg anyway, there had better not be any difference in the result. Change-Id: Id3f71a53d02e3dc625cfcc12aa71ecb50e35eb9f Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/374163 Reviewed-by: Myles Watson <mylesgw@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Standard locations for board specific battery codeVictor Prupis2016-08-192-536/+0
| | | | | | | | | | | | | Moved battery code for samus and ryu from driver tree to board tree. BUG=chrome-os-partner:42486 BRANCH=master TEST=none Change-Id: Iaad1456323f85e5852d8aa8e3e2d453b26e2d452 Signed-off-by: Victor Prupis <vprupis@google.com> Reviewed-on: https://chromium-review.googlesource.com/371402 Reviewed-by: Stefan Reinauer <reinauer@google.com>
* Deferred: Use deferred_data instead of function pointerAnton Staaf2016-04-181-1/+1
| | | | | | | | | | | | | | | | | | | | | Previously calls to hook_call_deferred were passed the function to call, which was then looked up in the .rodata.deferred section with a linear search. This linear search can be replaced with a subtract by passing the pointer to the deferred_data object created when DECLARE_DEFERRED was invoked. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None CQ-DEPEND=CL:*255812 TEST=make buildall -j Change-Id: I951dd1541302875b102dd086154cf05591694440 Reviewed-on: https://chromium-review.googlesource.com/334315 Commit-Ready: Bill Richardson <wfrichar@chromium.org> Tested-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* Kunimitsu: remove console commands for code sizeKyoung Kim2016-04-141-1/+1
| | | | | | | | | | | | | | | | | | | | | Remove following EC console commands to reduce code size: - battfake - apthrottle And none of commands above are used in 'auto test'. This is a squash of - https://chromium-review.googlesource.com/337657 - https://chromium-review.googlesource.com/338018 BUG=none BRANCH=firmware-glados-7820.B TEST=make -j buildall Change-Id: I11d2c5514f2714f0a46416feec2b2c47666fb462 Signed-off-by: Kyoung Kim <kyoung.il.kim@intel.com> Signed-off-by: Kevin K Wong <kevin.k.wong@intel.com> Reviewed-on: https://chromium-review.googlesource.com/338893 Reviewed-by: Shawn N <shawnn@chromium.org>
* Smart battery: wait for any battery responseMary Ruthven2015-12-031-21/+7
| | | | | | | | | | | | | | | | | | | | | | Currently the EC waits until it reads a battery status with the flag STATUS_INITIALIZED set, but the EC does not use this flag for charging or any other battery operation. If this flag is not set, it does not mean that the battery is unusable, it just means that its values may not be trustworthy. This change will remove the check for STATUS_INITIALIZED and just check that the battery responds. The battery response shows that the battery is connected and can be used by the EC. BRANCH=none BUG=chromium:564893 TEST=see that device without STATUS_INITIALIZED set will exit battery_wait_for_stable() without timing out. Change-Id: I07778e8570b6d9400b61beec6b2e222984a40692 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/315200 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* i2c: get battery information from charge stateMary Ruthven2015-10-271-0/+3
| | | | | | | | | | | | | | | | | | 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>
* charge_state_v2: fix battfake command race conditionAlec Berg2015-10-062-2/+64
| | | | | | | | | | | | | | | | | | | | | | | This moves battfake console command to the battery driver. This fixes a race condition with using the 'battfake' command where charge_state_v2 could return the real battery percentage even when a faked percentage is specified, if a higher priority task uses the battery state of charge in between when the battery is read, and when the fake state of charge overwrites the battery parameter. BUG=chrome-os-partner:45878 BRANCH=none TEST=use tap for battery with a faked state of charge. the tap for battery queries the battery percentage a lot, so without this CL, the tap sequence often temporarily jumps to different percentages and colors. with this CL, the tap sequence works great. Change-Id: I3ae0866d1ff7bb8d0c51355cd6b958310766f19e Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/302711 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* ryu: update charging temperature upper limitVincent Palatin2015-10-021-2/+2
| | | | | | | | | | | | | | | | | | | | | Do not charge above 48 C. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=smaug BUG=chrome-os-partner:45631 TEST=none Change-Id: I43260ab6079732ab3779d77ed64e3d872c5da4bd Reviewed-on: https://chromium-review.googlesource.com/302442 Reviewed-by: Furquan Shaikh <furquan@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org> Commit-Queue: Vincent Palatin <vpalatin@chromium.org> (cherry picked from commit 071b068816722958cebf326857b68b4bb06ecb5b) Reviewed-on: https://chromium-review.googlesource.com/302475 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Todd Broch <tbroch@chromium.org>
* ryu: change charging temperature limitsVincent Palatin2015-09-241-5/+5
| | | | | | | | | | | | | | | | | Do not charge below 5 C or above 50 C. Still charge at 0.1C between 5 C and 10 C. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=smaug BUG=chrome-os-partner:45631 TEST=none Change-Id: I6788088054ef4a5eb176eb2185b5e1c576128e09 Reviewed-on: https://chromium-review.googlesource.com/302232 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org>
* ryu: put additional temperature checks for battery chargingVincent Palatin2015-09-151-2/+11
| | | | | | | | | | | | | | | | | | | | | | Whatever the battery gas gauge returns, ensure we never charge below 0 C and above 60 C. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=smaug BUG=chrome-os-partner:44820 TEST=charge a Smaug DVT, use a cold spray on the battery and see the charge stop. Change-Id: I8670fbe1713b35aa079bebc9c5bb70e9f28cf8ac Reviewed-on: https://chromium-review.googlesource.com/299945 Trybot-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org> Commit-Queue: Vincent Palatin <vpalatin@chromium.org> (cherry picked from commit 1d19259be3b0721667835ce01bfe719fb547785e) Reviewed-on: https://chromium-review.googlesource.com/299906 Commit-Ready: Vincent Palatin <vpalatin@chromium.org>
* Driver: Add macros to conditionally compile the console commandsVijay Hiremath2015-07-292-0/+4
| | | | | | | | | | | | | | Added macros to conditionally compile the console commands to save the memory. These macros can be enabled/disabled in the board specific files. BUG=none TEST=make buildall -j BRANCH=none Change-Id: I108a072c333762cd24ea973612202c9cc4d40914 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/288950 Reviewed-by: Shawn N <shawnn@chromium.org>
* cleanup: fix all the header guardsBill Richardson2015-06-181-2/+2
| | | | | | | | | | | | | | | This unifies all the EC header files to use __CROS_EC_FILENAME_H as the include guard. Well, except for test/ util/ and extra/ which use __TEST_ __UTIL_ and __EXTRA_ prefixes respectively. BUG=chromium:496895 BRANCH=none TEST=make buildall -j Signed-off-by: Bill Richardson <wfrichar@chromium.org> Change-Id: Iea71b3a08bdec94a11239de810a2b2e152b15029 Reviewed-on: https://chromium-review.googlesource.com/278121 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Remove obsolete board-specific codeRandall Spangler2015-06-101-140/+0
| | | | | | | | | | | | | | | | | Now that we've removed boards from ToT, also delete board-specific code used only by the removed boards. There are still more things to remove (unused charging chips, LED drivers, COMx support). More CLs coming. BUG=chromium:493866 BRANCH=none TEST=make buildall -j Change-Id: Ie6bdeaf96e61cadd77e3f6336c73b9b54ff4eabb Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/276524 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* Skip the battery device name reading on BQ27742Vincent Palatin2015-03-261-0/+6
| | | | | | | | | | | | | | | | | | | | Contrary to the BQ2751 and BQ27741 it is sharing code with, BQ27742 does not have a "device name" register. So we need to skip the I2C reads else the battery_device_name() function returns an I2C error and the charge code retries until the end-of-time to read it hogging the CPU. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=none BUG=chrome-os-partner:38401 TEST=run on Ryu P4 and verify that we are no longer seeing 20ms of I2C transactions every 100ms on the battery I2C bus. Change-Id: I961af54017f661ee928058b346a42b7206ad8217 Reviewed-on: https://chromium-review.googlesource.com/262449 Reviewed-by: Alec Berg <alecaberg@chromium.org> Commit-Queue: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org>
* ryu: Implement charging profileVic Yang2015-01-291-0/+215
| | | | | | | | | | | | | | | This allows us to charge at a faster rate. BRANCH=Ryu BUG=None TEST=Charge Ryu P3 in S5 and check charging current. Change-Id: If8fbaa42d34df45f3d4db35ba50031c511b0c7af Signed-off-by: Vic Yang <victoryang@google.com> Reviewed-on: https://chromium-review.googlesource.com/242666 Tested-by: Vic Yang <victoryang@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org> Commit-Queue: Vic Yang <victoryang@chromium.org>
* samus: modify fast charging profile to avoid charge problemsAlec Berg2015-01-261-29/+91
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Several modifications to samus fast charging to fix bug where charging circuit stops charging the battery. - Fix bug: if we have a bad temperature reading, fast charging should ignore it. - Change the fast charging high temperature profile to set a charging voltage equal to the maximum of 8.3V and the current battery voltage. - Divide the normal temperature profile into two phases, low voltage charging and high voltage charging. Once we transition to second phase, don't allow it to go back to phase 1 unless AC is removed. On samus, we have to make sure we never command the BQ to a charging voltage that is below the present battery voltage or else the INA will lose power and we will not be able to charge the battery until AC is disconnected. This also changes charge_state_v2 so that the fast charging profile override is called even when AC is disconnected to avoid jumps in temperature as seen by the fast charging code. Also changes the voltage threshold for transitioning from phase 1 to phase 2 of normal temp charging so that the transition is taken a little earlier to match the desired profile slightly better. BUG=chrome-os-partner:35491 BRANCH=samus TEST=Added custom console command to be able to directly control the battery temperature that charger_profile_override() uses: static int command_chgtemp(int argc, char **argv) { char *e; if (argc < 2) return EC_ERROR_PARAM_COUNT; chg_temp = strtoi(argv[1], &e, 10); if (*e) return EC_ERROR_PARAM1; return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(chgtemp, command_chgtemp, "", "", NULL); Using this command, I jumped back and forth between all three temperature fast charging regions and made sure that (1) we never set a charging voltage below the present battery voltage and (2) we never stop charging the battery. I ran this test at low battery and high battery percentage and with low load (G3) and high load (S0 with webgl aquarium). Change-Id: I035603a4ab48a156ab43f8c93f21200c4b664aab Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/243143 Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
* samus: add battery cutoffAlec Berg2015-01-241-0/+24
| | | | | | | | | | | | | | Add battery cutoff to samus. BUG=chrome-os-partner:35744 BRANCH=samus TEST=tested "cutoff" console command cuts off battery and "ectool batterycutoff" from host cuts off battery Change-Id: I88194c9c601594dee144933cabef5b1dc536ab0d Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/242830 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* bq27541: report battery present stateVic Yang2015-01-241-2/+12
| | | | | | | | | | | | | | | | The battery driver is not reporting battery present state, and as a result, is_present flag always remain NOT_SURE. Fix it. BRANCH=Ryu BUG=None TEST=On Ryu, 'chgstate' and see 'is_present = YES'. Change-Id: I84bedc390158797bf1e67e612d0bb3f526292dfa Signed-off-by: Vic Yang <victoryang@google.com> Reviewed-on: https://chromium-review.googlesource.com/242970 Reviewed-by: Alec Berg <alecaberg@chromium.org> Commit-Queue: Vic Yang <victoryang@chromium.org> Tested-by: Vic Yang <victoryang@chromium.org>
* driver: BQ27621 scaling bug fixMyles Watson2015-01-241-2/+2
| | | | | | | | | | | | | | Design capacity and Design Energy need to be multiplied by the scaling factor. BUG=None TEST=Manual test with hadoken without charging enabled. Observed the battery level decreasing. BRANCH=NONE Change-Id: Icb5f74766c2416128277df4fe1bb00fc7307f5e5 Signed-off-by: Myles Watson <mylesgw@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/242890 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* battery: Add support for TI's BQ27621_g1 fuel gauge.Myles Watson2014-12-311-0/+754
| | | | | | | | | | | | | | | | | | | | | define CONFIG_CMD_BATDEBUG to enable console commands. If the battery is larger than 6Ah or smaller than 150mAh, scale the parameters transparently to the user using macros. BUG=chrome-os-partner:34477 BRANCH=none TEST=Custom console commands for the fuel gauge I also used a Logic16 from Saleae and the fuel gauge on hadoken. Signed-off-by: Myles Watson <mylesgw@chromium.org> Change-Id: I959d51c3188336e4ad0983528ad7e53a2955a764 Reviewed-on: https://chromium-review.googlesource.com/234285 Reviewed-by: Randall Spangler <rspangler@chromium.org> Tested-by: Myles Watson <mylesgw@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org> Commit-Queue: Myles Watson <mylesgw@chromium.org>
* samus: set BQ voltage to battery voltage when AC disconnectedAlec Berg2014-12-231-1/+1
| | | | | | | | | | | | | | | | | | | | Set charge state machine voltage to just above the battery voltage when AC is disconnected. Also send new current before sending new voltage to charger when there is a change. These changes reduce input current spikes caused by current inrush into the battery and thereby decrease chance of overcurrenting power supply on connect. BUG=chrome-os-partner:33862 BRANCH=samus TEST=load onto samus instrumented with input current probe. when AC is attached note that initial current spike is much lower with this change. Change-Id: I7760cd2b709c6b3536cf2a9449bb1f46800ce10a Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/237245 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
* samus: enabled fast charging for EVT ATL cellsAlec Berg2014-09-231-19/+51
| | | | | | | | | | | | | | | | | Enable fast charging with profile designed for ATL cells that will be used in EVT. BUG=chrome-os-partner:23776 BRANCH=none TEST=Took detailed charging/discharging data and verified that the actual profile matches the desired profile and that the fast charging profile is actually faster than the standard. See bug report for more info and data collected. Change-Id: Ic11ab89e48afb73987b8013abf8b0564e1138156 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/212980 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* Add support for BQ27742 battery gauge chipVic Yang2014-09-171-5/+24
| | | | | | | | | | | | | | | | This reuses most of the existing BQ27541 driver, but changed necessary parts to make it work. BUG=none TEST=Boot on Ryu. See battery charging. BRANCH=factory-ryu-6212.B Change-Id: I3a7325a821c81f84396bcc328036b6a5e7749a2e Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/217198 Reviewed-by: Alec Berg <alecaberg@chromium.org> (cherry picked from commit f44593e20bf61a2243d7baaae901c912ca798d75) Reviewed-on: https://chromium-review.googlesource.com/218413
* EC: smart battery using smbus APISheng-Liang Song2014-09-031-2/+21
| | | | | | | | | | | | | | | | Ref: Common Smart Battery System Inferface Specification v8.0. Ref: http://smbus.org/specs/smbus20.pdf - Enable smbus read/write APIs with compile options BUG=chrome-os-partner:30930 BRANCH=ToT,glimmer TEST=Verified with LGC & Simplo firmware update. Change-Id: I3f4bb23147f22365adb378c2e39c40d5ba100889 Signed-off-by: Sheng-Liang Song <ssl@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/209906 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* EC: Add smart battery firmware update driverSheng-Liang Song2014-09-032-0/+382
| | | | | | | | | | | | | | | | | | | | Ref: Common Smart Battery System Inferface Specification v8.0. - Added 2 new AP->EC Command APIs EC_CMD_SB_FW_UPDATE, EC_CMD_ENTERING_MODE - Implemented common smart battery update drivers. BUG=chrome-os-partner:24741 CQ-DEPEND=CL:210032 CQ-DEPEND=CL:210033 CQ-DEPEND=CL:215720 BRANCH=ToT,glimmer TEST=Verified on LGC & Simplo smart battery Change-Id: Ice6e60b1b04762217ae7613356d6925777c06abf Signed-off-by: Sheng-Liang Song <ssl@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/205323 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* EC: clean up i2c_read_stringSheng-Liang Song2014-08-291-1/+1
| | | | | | | | | | | | | | | | - Removed duplicate (similar) i2c_read_string functions. - Kept one generic (weak) copy in common/i2c.c. - TBD: Need support start/stop flags for STM32 family devices BUG=chrome-os-partner:23569 BRANCH=ToT TEST=Verified with smart battery firmware update application on glimmer. Passed LGC & Simplo Battery. Change-Id: I6d9446c60b6a36aef9a6179242c081084199c8e2 Signed-off-by: Sheng-Liang Song <ssl@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/209866 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* pd: Print warning before flash erase if on PD powerVic Yang2014-08-141-0/+8
| | | | | | | | | | | | | | | | | During flash erase operation, read is stalled and thus interrupt might be serviced later. This can cause PD communication to fail and thus the board reboots if there is no battery. Print a warning message in this case. BUG=chrome-os-partner:31127,chrome-os-partner:31207,chrome-os-partner:31362 TEST=Boot Ryu, on software sync, see warning message before board reboots. BRANCH=None Change-Id: If327a4f533fd2dfa83f92531148bd52ace927e03 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/212264 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* samus: ryu: set input current limit based on PD negotiationAlec Berg2014-08-091-26/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Set input current limit based on the max current from the PD negotiation. For samus, this information is passed to the EC as a host command. For ryu, the max current is set directly following a negotiation. CONFIG_CHARGER_INPUT_CURRENT is now just the default limit, but after a successful PD negotiation, the limit can be raised. Note, for now the input current limit for samus is set to 2/3 of the value negotiated for. This is due to hardware problems measuring input current on p2b boards. BUG=chrome-os-partner:28532, chrome-os-partner:24461 BRANCH=none TEST=tested on a samus. Verified input current limit using "charger" console command from EC. Input current limit after a reboot is 512. When zinger is plugged in, it jumps to the appropriate value (currently 1280mA), and when the negotiation is changed using the "pd 0 dev 5" command on the PD console, the input current limit is adjusted to match (2000mA). Change-Id: Iab9186a0f9814655e3240217a9baf4a38f15f84d Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/211023 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* battery: fix BQ27541/BQ27741 gas gauge driverVincent Palatin2014-07-291-6/+21
| | | | | | | | | | | | | | | | | | | | | | Update the code to be compatible with charge v2 expectations : never return EC_ERROR_UNIMPLEMENTED for battery information else the charge code continuously tries to read them again. Fix the State Of Charge reading : on BQ27741 the gas gauge gets confused if we do a 16-bit I2C read while a 8-bit read works perfectly. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=none BUG=none TEST=run a Ryu connected to a Kirby battery and check the output of the "battery" command. Change-Id: Ic1d6128dc02efa47662fa5ca5b9e5de62420ebe8 Reviewed-on: https://chromium-review.googlesource.com/207273 Reviewed-by: Vic Yang <victoryang@chromium.org> Tested-by: Vic Yang <victoryang@chromium.org> Commit-Queue: Vic Yang <victoryang@chromium.org>
* ryu: Kick battery out of disconnect state when AC is attachedstabilize-6092.BVic Yang2014-07-251-0/+49
| | | | | | | | | | | | | | | | Like Samus, the battery can be placed into a disconnect state. This CL implements the necessary function to determine if it is so and kick it out of this state when possible. BUG=chrome-os-partner:30633 TEST=Put a battery in this state. Plug in AC. Verify the battery is revived. BRANCH=None Change-Id: I074a72a2efe3844cbdfb0eda16a25fd8d1755a9b Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/209634 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* samus: Kick battery out of disconnect state when AC is attachedShawn Nematbakhsh2014-07-231-0/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The Samus battery can be placed into a disconnect state by asserting a disconnect input signal. In this state, the battery will not function until a charging current is applied. This patch adds detection of the disconnect state. If a battery in disconnect state is found, a current is force-applied to the battery to kick it out of disconnect. BRANCH=None TEST=Manual on Samus. 1. Put battery into disconnect state 2. Pull AC, then reattach AC 3. Verify "found battery in disconnect state" is seen on the EC console. 4. Pull AC and verify that EC console is still accessable Also verify that battery gets out of reset state: 1. Pull AC 2. Issue "i2cxfer w16 0 0x16 0x0 0x12" command on EC console 3. Re-attach AC 4. Pull AC and verify that EC console is still accessable BUG=chrome-os-partner:29465 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: Ib4268887fb483094ac4e641749200268160d3014 Reviewed-on: https://chromium-review.googlesource.com/209013 Reviewed-by: Alec Berg <alecaberg@chromium.org> Commit-Queue: Alec Berg <alecaberg@chromium.org> Tested-by: Alec Berg <alecaberg@chromium.org>
* samus: fix input current to 2048Duncan Laurie2014-06-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | This changes the input current limit to 2048mA with no ramp up. Problem is that the bq24773 is doing a really poor job of measuring input current, so even though the zinger side can support 3A, the samus side can cause over currents down to 2300mA. This is set consertavily to avoid over current errors and will need to be updated when the hardware allows. BUG=chrome-os-partner:24461 BRANCH=none TEST=Used bench top power supply to power multiple samus 2A proto boards and gathered data on max current samus was drawing based on input current setting. Samus was often underestimating current by 300-700mA. Change-Id: Iabeb0d026f2b72a9ee539d92579ee6d11aeaa56b Signed-off-by: Duncan Laurie <dlaurie@chromium.org> Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/205143 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* samus: allow charging of dead battery requesting nilAlec Berg2014-06-071-0/+13
| | | | | | | | | | | | | | | | | | | | | | | On samus battery, when the battery is dead it reports 0 for desired voltage, current, and state of charge. In this case we should allow charging. Added a CONFIG option for this that should be removed as soon as the battery side is fixed. With this CL, when a dead samus battery is used and a charger is connected, we attempt to charge it. BUG=chrome-os-partner:29465 BRANCH=none TEST=test on a samus with a dead battery. w/o this CL, the battery never charges because the charging not allowed flag is set. With this CL, the battery charges. Change-Id: Ic61f27a27237166d33cb9ea5f024d3ef6360ce82 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/202603 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* samus: limit input current to 2.5A to prevent over currenting zingerAlec Berg2014-05-231-1/+1
| | | | | | | | | | | | | | | | | Set maximum input current limit to ~2.5A to prevent over current faults on zinger. Note, we still get over current faults sometimes but it always clears in < 10seconds. BUG=chrome-os-partner:28611 BRANCH=none TEST=Test with a samus 1.9 and a zinger. Plug and unplug charger many times and make sure that we are eventually able to successfully negotiate for power and start charging. Change-Id: I5a7adf9fc7f5ed7a0c7dfdb620e0c1474f72a878 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/201154 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Add cprints() and ccprints()Vic Yang2014-05-211-5/+5
| | | | | | | | | | | | | | | | | | | | | Our code base contains a lot of debug messages in this pattern: CPRINTF("[%T xxx]\n") or ccprintf("[%T xxx]\n") The strings are taking up spaces in the EC binaries, so let's refactor this by adding cprints() and ccprints(). cprints() is just like cprintf(), except that it adds the brackets and the timestamp. ccprints() is equivalent to cprints(CC_CONSOLE, ...) This saves us hundreds of bytes in EC binaries. BUG=chromium:374575 TEST=Build and check flash size BRANCH=None Change-Id: Ifafe8dc1b80e698b28ed42b70518c7917b49ee51 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/200490 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Samus: Update configuration for proto1.9Bill Richardson2014-05-121-0/+1
| | | | | | | | | | | | | Start of changes to Samus' board.h and board.c to support proto1.9 BUG=chrome-os-partner:28721 BRANCH=ToT TEST=make buildall Change-Id: I70590c1f9845430801a6c2939ac92be289750ca3 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/199242 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* Adding waiting function when battery boot-upWonjoon Lee2014-05-071-0/+42
| | | | | | | | | | | | | | | | | | | | | Some battery uses clock stretching feature, and this could disturb PMU communication before battery going stable. AP does not know and will attempt PMU setting, and could get fail For various battery indicates usually 1s for stable (even if it is much less in real world 200ms~700ms) Let's checking 'battery is ready' when first pump-up power. BRANCH=ToT BUG=chrome-os-partner:28289 TEST=Going battery shipmode and plug-in AC, See booting and EC log Disconnect battery, and plug-in and see booting and EC log Change-Id: Idd8ae2ab4ec164b11fe67413bbf647cad18bc481 Signed-off-by: Wonjoon Lee <woojoo.lee@samsung.com> Reviewed-on: https://chromium-review.googlesource.com/197990 Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Doug Anderson <dianders@chromium.org> Tested-by: Doug Anderson <dianders@chromium.org>
* Rename battery_vendor_params() to battery_override_params()Dave Parker2014-04-291-3/+3
| | | | | | | | | | | | | | | | | | | | Charger V1 only. This is a clearer name for the intent of the function to override the charging parameters requested by the battery. This also disabmiguates this function with a new host command to get and set arbitrary vendor parameters in the battery. BUG=chrome-os-partner:25145 BRANCH=ToT TEST=`make buildall -j`. Change-Id: I1e8762d359c0e91c5b2a539553d22c12c9850c03 Signed-off-by: Dave Parker <dparker@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/195823 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/197164 Reviewed-by: Yung-chieh Lo <yjlou@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org>