summaryrefslogtreecommitdiff
path: root/driver/battery/bq27541.c
Commit message (Collapse)AuthorAgeFilesLines
* Update license boilerplate text in source code filesMike Frysinger2022-09-121-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: Icd3a1723c20595356af83d190b2c6a9078b3013b Signed-off-by: Mike Frysinger <vapier@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3891203 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* tree-wide: const-ify argv for console commandsCaveh Jalali2022-09-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | This updates the API for console commands from "int cmd(int argc, char **argv)" to "int cmd(int argc, const char **argv)" which is more accurate and in line with common convention. BRANCH=none BUG=b:244387210 TEST="make buildall" passes TEST="zmake build -a" passes TEST="util/compare_build.sh -b all" passes TEST="./twister -v -T zephyr/test" passes Cq-Depend: chrome-internal:4960125 Cq-Depend: chrome-internal:4959932 Change-Id: I57de9f35b85b8f3c7119df36aefb2abf25d2625f Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3863941 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org>
* driver/battery/bq27541.c: Format with clang-formatJack Rosenthal2022-06-301-49/+46
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: I1372ed33eb509682cec59af9663642edf6e8dd10 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729929 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* tree: Files should end with single newlineTom Hughes2021-10-181-1/+0
| | | | | | | | | | | | | | | | | | | | | | | One of the checks that runs as part of "repo upload" looks for a single newline at the end of each file. I'm getting warnings about this when I touch files that do not follow this, even though I didn't add the extra newlines. This commit fixes all files by running the following: for f in $(find . -name '*.[ch]'); do printf '%s\n' "$(cat ${f})" > ${f}; done BRANCH=none BUG=b:172020503 TEST=./util/compare_build.sh -b all -j 120 => MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Ia3ece5b64b549d21ca11708791368002bb6e9b0e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3229797 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* Kakadu: Fix battery charging status for bq27542wen zhang2020-12-081-0/+4
| | | | | | | | | | | | | | | | Fix the battery charging status for gauge bq27542. BUG=b:174725434 BRANCH=master TEST=1.make -j BOARD=kakadu 2.verified the battery charging status and the result is OK. Change-Id: Ie3a926dd96b967679d2c51856afc3d1c157835f5 Signed-off-by: wen zhang <zhangwen6@huaqin.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2576196 Reviewed-by: Chen-Tsung Hsieh <chentsung@chromium.org> Reviewed-by: Ting Shen <phoenixshen@chromium.org> Commit-Queue: Ting Shen <phoenixshen@chromium.org>
* Kakadu: Fix battery is_present status for bq27542wen zhang2020-12-041-2/+4
| | | | | | | | | | | | | | Fix the battery is_present status for gauge bq27542. BUG=b:174802149 BRANCH=master TEST=1.make -j BOARD=kakadu 2.verified the battery present status and the result is OK. Change-Id: Ic8d9d503bc2f7d9648df56c150018f304aacfb18 Signed-off-by: wen zhang <zhangwen6@huaqin.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2571145 Reviewed-by: Ting Shen <phoenixshen@chromium.org>
* Kakadu: Add new battery support for gauge bq27542wen zhang2020-11-121-4/+75
| | | | | | | | | | | | | | Configure battery parameter and driver for gauge bq27542 on kakadu. BUG=b:172197008, b:171456201 BRANCH=master TEST=1.make -j BOARD=kakadu 2.verified the battery parameter and the result is OK. Change-Id: I4c2cc11df1e13cb7313280afca717a7f1e2461ff Signed-off-by: wen zhang <zhangwen6@huaqin.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2531765 Reviewed-by: Ting Shen <phoenixshen@chromium.org>
* battery: Expose battery_manufacture_date() as APIWai-Hong Tam2020-07-211-0/+5
| | | | | | | | | | | | | | | | | | | | | | | The newer kernels request this data. Add the battery_manufacture_date() as a new API. Checked the TRMs of the following batteries. They don't have any way to query the manufacture date, so return EC_ERROR_UNIMPLEMENTED. * bq27541 * bq27621_g1 * max17055 * mm8013 BRANCH=None BUG=b:160784792 TEST=Hacked to print the manufacture date, on both battery present and not. Change-Id: I1deefb64f6cc594828d6c10c42fa7107dadd7559 Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2300689 Commit-Queue: Douglas Anderson <dianders@chromium.org> Reviewed-by: Douglas Anderson <dianders@chromium.org>
* 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>
* battery: Consolidate battery_manufacturer_nameDaisuke Nojiri2019-05-011-7/+0
| | | | | | | | | | | | | | | | | | | | | Currently, the battery_manufacturer_name API is implemented individually by each chip. This patch consolidate the definitions. It also allows a board to return custom manufacturer names. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=b/129599895 BRANCH=none TEST=buildall Change-Id: Ib0f60c9be71fea31658ab284a915d73341b9145e Reviewed-on: https://chromium-review.googlesource.com/1590039 Commit-Ready: YH Lin <yueherngl@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: YH Lin <yueherngl@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* common: replace 1 << digits, with BIT(digits)Gwendal Grignou2019-03-261-1/+1
| | | | | | | | | | | | | | | | 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>
* cleanup: DECLARE_CONSOLE_COMMAND only needs 4 argsBill Richardson2016-08-241-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* charge_state_v2: fix battfake command race conditionAlec Berg2015-10-061-1/+30
| | | | | | | | | | | | | | | | | | | | | | | 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>
* 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>
* 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>
* 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
* 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>
* 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>
* Add more fields and error flags to struct batt_paramsBill Richardson2014-03-281-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds two battery parameters that need to be monitored constantly: remaining_capacity and full_capacity (that one only changes occasionally, but we have to notify the AP when it does). It also adds the is_present field to indicate whether the battery is physically present or not (when we can tell), so we know whether to try to wake up a deep-discharged battery. Along with that, we clean up the error flags to provide indication of which fields were unable to be read, and replace the manual logical-or of all errors as they were set with a bitmask (BATT_FLAG_BAD_ANY). No functionality is changed, only new & better information is provided for use in the upcoming cleanup of the charge state machine. BUG=chrome-os-partner:20881 BRANCH=ToT TEST=make buildall -j All targets build; all tests pass. Change-Id: I4312c2fdd3cf2dd9570718e90571eff796b269db Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/191917 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Cleanly force battery to mAh mode when reading capacityRandall Spangler2013-12-021-13/+0
| | | | | | | | | | | | | | | | | Smart batteries can report capacity in mAh or 10mW units. We forced the units to mAh in charge_state.c's main loop, but that doesn't guarantee that they're actually set before the capacity is read. It's cleaner to check the capacity reporting mode when actually reading the capacity. BUG=chrome-os-partner:20881 BRANCH=none TEST=battery command reports the same capacity data before/after change (on rambi, design=2940 mAh) Change-Id: I4a4c80eaade72bb09627d5d65693c097e264a992 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/176154
* Add battery_get_params()Randall Spangler2013-12-021-39/+50
| | | | | | | | | | | | | | | | | | | | | | | | 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
* Show smart battery status with 'battery' commandBill Richardson2013-11-051-0/+5
| | | | | | | | | | | | | | | | | | | | | | | The smart battery status register holds some useful info. This displays it along with all the other stuff. This decodes the alarm and status bits, but not the error code, since that field is only valid immediately after a failed i2c transaction (that's how the battery indicates error). Since we do all sorts of automatic battery probing in other threads, that value will never be reliable when we run the "battery" console command. BUG=none BRANCH=none TEST=manual Run "battery". You should see a new line amongst the output: Status: 0x00c0 DCHG INIT Change-Id: I5e684198af2cf7767f89786c91a7d946ad95d4c2 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/175659
* cleanup: rename I2C_PORT_HOST to I2C_PORT_MASTERRandall Spangler2013-10-251-3/+3
| | | | | | | | | | | | | | | | | Previously, it was really confusing whether I2C_PORT_HOST meant the port where the EC was the master, or the port used to talk to the AP. No functional changes, just a global find/replace and some tidying of unused comments. BUG=chrome-os-partner:18343 BRANCH=none TEST=build all platforms; pass unit tests Change-Id: Ia591ba4577d3399729556e0234ba0db3a0e3c5ea Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/174546 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* Move source files to driver/ and power/ subdirsRandall Spangler2013-10-231-0/+219
The common/ subdir was getting cluttered. Move drivers for external components to a new driver/ tree, and move what used to be called chipset_*.c to a new power/ directory. This does not move/rename header files or CONFIG options. That will be done in subsequent steps, since moving and modifying .c files in the same CL is harder to review. BUG=chrome-os-partner:18343 BRANCH=none TEST=build all boards; pass unit tests Change-Id: I67a3003dc8564783a320335cf0e9620a21982d5e Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/173601 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Vic Yang <victoryang@chromium.org>