summaryrefslogtreecommitdiff
path: root/common/charger.c
Commit message (Collapse)AuthorAgeFilesLines
* zephyr: tests: Test most of remaining ocpc.c codeTristan Honscheid2023-05-051-3/+3
| | | | | | | | | | | | | | Add coverage to much of ocpc_config_secondary_charger() and ocpc_calc_resistances() BUG=b:276805061 TEST=./twister -T zephyr/test/ocpc Change-Id: I78ca222fc44c087807d1419ae1dd15e1875b1b2a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4504794 Commit-Queue: Tristan Honscheid <honscheid@google.com> Tested-by: Tristan Honscheid <honscheid@google.com> Reviewed-by: Peter Marheine <pmarheine@chromium.org>
* charger: Disambiguate charger command outputDaisuke Nojiri2023-04-201-14/+18
| | | | | | | | | | | | | | | | | | | | | | | | The values of the charger console command output are not clearly explained. This CL reformats the output as follows: Name: ISL9241 Option: (0x2830004) Man id: 0x0049 Dev id: 0x000e I_dptf: disabled Limits ( min max step) chg_voltage: 8760 mV ( 64 - 18304, 8) chg_current: 4336 mA ( 8 - 12280, 8) input_current: 4512 mA ( 8 - 12280, 8) BUG=b:278898714 BRANCH=None TEST=See above (on Vell). Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: Ide4b448d15b5066c43cec9e8aadf1ffdb1afe7f4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4447187 Reviewed-by: Eric Yilun Lin <yllin@google.com>
* frostflow: Modify charger frequence for power consumption.Logan_Liao2023-03-151-0/+15
| | | | | | | | | | | | | | | | | | To avoid charger enter CCM mode, modify isl9241 frequence to 600kHz from 1020kHz in S5. BUG=b:271704154 BRANCH=none TEST=power team test power consumption is lower than 1020kHz. Change-Id: I9906f2795582c2c8e4a63a674404c0e5a5dfbc96 Signed-off-by: Logan_Liao <Logan_Liao@compal.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4333276 Reviewed-by: SamSP Liu <samsp_liu2@compal.corp-partner.google.com> Tested-by: Logan Liao <logan_liao@compal.corp-partner.google.com> Reviewed-by: Chao Gui <chaogui@google.com> Commit-Queue: Logan Liao <logan_liao@compal.corp-partner.google.com> Reviewed-by: Logan Liao <logan_liao@compal.corp-partner.google.com>
* charger: Add prochot printing functionRobert Zieba2022-12-091-0/+9
| | | | | | | | | | | | | | | | Add `print_charger_prochot` function and corresponding entry to charger driver struct to accommodate calling this functionality in a generic way. BRANCH=none BUG=b:227768313 TEST=Builds LOW_COVERAGE_REASON=No generic CrOS EC charger emulator Change-Id: Iabc9b33de55436b2bbdd9c372738d7356536c874 Signed-off-by: Robert Zieba <robertzieba@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4087540 Reviewed-by: Diana Z <dzigterman@chromium.org>
* common/charger: read charger parameters using primary chargerDeepti Deshatty2022-11-301-1/+5
| | | | | | | | | | | | | | | | | | | when no active charger is connected to the system, retrieve charger parameters using primary charger(0). This avoids setting the 'problems_exist' flag which allows charger_task() to sleep for a period of CHARGE_POLL_PERIOD_VERY_LONG in susped scenarios. BUG=b:258613461 BRANCH=none TEST=zmake build craask, EC S0ix power is optimized Change-Id: Ic177acb74f943ec8b3eafaae7bf6b56db758d6e5 Signed-off-by: Deepti Deshatty <deepti.deshatty@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4050321 Code-Coverage: Diana Z <dzigterman@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* common: Sort header filesJeremy Bettis2022-11-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | Sort all includes in common with the clang-format rules used by the zephyr project. BRANCH=None BUG=b:247100970 TEST=zmake build -a TEST=./twister --clobber -v -i TEST=make -j72 buildall_only runtests TEST=zmake compare-builds -a Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: I70c2ed7bb2ce50c968f3e2dbdc274de3a455129a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4049889 Auto-Submit: Jeremy Bettis <jbettis@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Tomasz Michalec <tmichalec@google.com> Reviewed-by: Tom Hughes <tomhughes@chromium.org>
* charger: Bounds check chgnum in charger_enable_bypass_mode()Tristan Honscheid2022-11-101-1/+4
| | | | | | | | | | | | | | | | | | | This function is public and does not validate the chgnum parameter, which can cause out-of-bounds access to an array. Add an ASSERT to protect against this. Also convert the enable parameter to a bool. BRANCH=None BUG=None TEST=./twister Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: I54d374d53e28210af014edbe24638bbead1ef295 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4000834 Reviewed-by: Yuval Peress <peress@google.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* charger: Remove always false chgnum checksAaron Massey2022-10-251-11/+11
| | | | | | | | | | | | | | | | | | | | | In 11 charger.c functions, the variable chgnum is set to 0 and then immediately checked if it's less than 0 with no instructions in-between the variable initialization and the branch check for chg < 0. Remove all of the aforementioned checks. BRANCH=none BUG=b:255357127 TEST=twister --clobber -i -s zephyr/test/drivers/drivers.default TEST=CQ LOW_COVERAGE_REASON=Only removed dead code. Signed-off-by: Aaron Massey <aaronmassey@google.com> Change-Id: I64f8ecdde9934bfd792a7a4570346fda2db609c1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3975974 Code-Coverage: Abe Levkoy <alevkoy@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* charger: Detect the number of battery cellsKyle Lin2022-09-281-0/+11
| | | | | | | | | | | | | | | | | | | | | The charging mode of SM5803 charger is configured by sensing an external resistors. The number of battery cells can be determined from the charging mode. To support 2S and 3S batteries in one model(project), the number of battery cells should be detected at run time. BUG=b:242477985 BRANCH=none TEST='make buildall' and 'zmake build -a' Change-Id: Icb7af51ab7b3b27a6fb7ad4ac4b8fe87331108fe Signed-off-by: Kyle Lin <kylelinck@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3892078 Code-Coverage: Andrew McRae <amcrae@google.com> Tested-by: Zick Wei <zick.wei@quanta.corp-partner.google.com> Reviewed-by: Andrew McRae <amcrae@google.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Andrew McRae <amcrae@google.com> Reviewed-by: Zhuohao Lee <zhuohao@chromium.org>
* herobrine: Wait negotiated VBUS transition before enabling 5V railWai-Hong Tam2022-09-201-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previous, the PP5000 is enabled at GPIO init. In the dead battery case, enabling PP5000 overloads the battery charger at the initial 5V 500mA supply. We want to defer it until the PD negotiated VBUS transition, so the battery charger won't be overloaded. A window of PD negotiation is created. It starts from the Type-C state reaching Attached.SNK, and eneds when the PD contract is created. The VBUS may be raised anytime in this window. The current implementation is the worst case scenario. Every message the PD negotiation is received at the last moment before timeout. The extra time is added to compensate the delay internally, like the decision of the DPM. The unit tests are added. BRANCH=None BUG=b:215726554 TEST=Booted the Herobrine board with no-battery. The 5V rail got delayed. Change-Id: I5529762de3495e4cb6702e887bf6ee09d1711f14 Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3501013 Reviewed-by: Sam Hurst <shurst@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* 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>
* charger: support the charger without batteryZhuohao Lee2022-09-081-2/+4
| | | | | | | | | | | | | | | | | | | | | | In order to support the HW design with charger but doesn't include the a battery, we exclude the charge_state_v2.c if we define the CONFIG_CHARGER but not define the CONFIG_BATTERY. Besides, we also implement some default functions to avoid the link error. Note: remove the charge_prevent_power_on from the board.c of rainier/mchpevb1 and use the default function. BUG=b:242949656 BRANCH=none TEST=build pass with 1. CONFIG_CHARGER + CONFIG_BATTERY 2. CONFIG_CHARGER + no CONFIG_BATTERY 3. make buildall Change-Id: I32c9b03aaf87b641af2b337db1f3bae838464a41 Signed-off-by: Zhuohao Lee <zhuohao@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3865186 Reviewed-by: Diana Z <dzigterman@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* 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>
* tree: Remove non-standard %pb printf formatTom Hughes2022-07-121-1/+1
| | | | | | | | | | | | | | | | The binary printf format doesn't provide much over printing hex, so change existing binary prints to hex. Using standard format specifiers makes it easier to switch between the "builtin" EC standard library and the C standard library provided by the toolchain (or Zephyr). BRANCH=none BUG=b:238433667, b:234181908 TEST=make buildall Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I55153f0ea1a4864e7819cee0e0f35368baa3f682 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3756176 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* charger: Add get_vsys_voltageDaisuke Nojiri2022-06-291-2/+25
| | | | | | | | | | | | | | get_vsys_voltage returns a Vsys voltage measured by the charger if it's supported by the charger. BUG=None BRANCH=None TEST=buildall Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I49a024860504ee4c8ec172b025dbb3cdaf3ac214 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3733416 Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
* common/charger.c: Format with clang-formatJack Rosenthal2022-06-281-26/+29
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: I1ee9e677b6d2a1d562d671bfbc2c69823293bef7 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729599 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* chgstv2: Add bypass mode for ISL9241Daisuke Nojiri2022-04-211-0/+7
| | | | | | | | | | | | | | | | | | | This patch adds bypass mode support to the charger interface and implement it for ISL9241. The bypass mode routes the input current from AC directly to the system power rail for efficiency. Enabling or disabling is done by the charger task. BUG=b:214057333, b:216206104 BRANCH=None TEST=On Agah. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I951393b0e0026de795ce930e8fdeb9018d57b84e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3519879 Tested-by: Zick Wei <zick.wei@quanta.corp-partner.google.com> Reviewed-by: Zhuohao Lee <zhuohao@chromium.org>
* hooks: add HOOK_PRIO_POST_I2CKeith Short2022-03-291-1/+1
| | | | | | | | | | | | | | | | | Add the HOOK_PRIO_POST_I2C alias for (HOOK_PRIO_INIT_I2C+1). This more clearly identifies the intent of this priority level. Applied only to common code and to Zephyr boards. BUG=none BRANCH=none TEST=compare_build.sh TEST=zmake testall Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: Ia5b8c594e1f06ae1a982770f75b63bb4ba44191f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3553669 Reviewed-by: Wai-Hong Tam <waihong@google.com>
* ocpc: Do not report invalid charger if CHARGE_PORT_NONEAndrew McRae2022-01-201-1/+5
| | | | | | | | | | | | | | Do not report an invalid charger if there is no charger. BUG=b:215253447 TEST=zmake configure -b nivviks; flash and run BRANCH=none Signed-off-by: Andrew McRae <amcrae@google.com> Change-Id: I23b1d7861065c32b438e43198c2fa1cc2a515f5b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3403358 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
* charger: Enable hw ramp for active_chg_chipTommy Chung2021-11-021-8/+16
| | | | | | | | | | | | | | | There're some boards with more than one chg chips included (OCPC). We should set the "active chg chips" when we call charger_set_hw_ramp. BUG=b:196928096 BRANCH=none TEST=make sure that hw ramp enabled on the active chg chip. Signed-off-by: Tommy Chung <tommy.chung@quanta.corp-partner.google.com> Change-Id: I98c8ca3a189ed1794c06a789a5e685b5d8a8aa12 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3252564 Reviewed-by: Diana Z <dzigterman@chromium.org> Reviewed-by: Devin Lu <Devin.Lu@quantatw.com>
* cleanup: charger: consolidate charger_dump console commandsDeepti Deshatty2021-10-201-4/+25
| | | | | | | | | | | | | | | | | | | | Console command "charger_dump" is defined in multiple charger driver files, hence, build fails when more than one charger chip drivers are enabled for a platform. To avoid this "charger_dump" console command is defined in a common file, and this command handler invokes platform specific charger dump register api. BRANCH=none BUG=none TEST=Verified 'charger dump' command on brya Signed-off-by: Deepti Deshatty <deepti.deshatty@intel.corp-partner.google.com> Change-Id: Ic542af90b47880e90073c529f9183abc6a3f5af7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3211760 Commit-Queue: caveh jalali <caveh@chromium.org> Reviewed-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* chgstv2: Refactor charger_discharge_on_acDaisuke Nojiri2021-06-251-0/+3
| | | | | | | | | | | | | | | This patch makes charger_discharge_on_ac call board_discharge_on_ac. It also makes set_chg_ctrl_mode call charger_discharge_on_ac. This makes sense since when the charge control mode changes, discharge-on-ac also needs to be enabled or disabled. BUG=b:188457962 BRANCH=none TEST=make runhosttests Change-Id: I65ec09f580afc987cc86f4c60c15c1f90ead6c3c Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2986848
* charger: Add new APIs for measured charge valuesAseda Aboagye2021-03-111-0/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some of the charger ICs can provide measurements for the charge voltage and the charge current. This information is needed by the OCPC module. Previously, the charge_get_current() and charge_get_voltage() functions were modified to provide this information. However, those functions are intended to provide the set voltage and current targets for the charger IC. This commit adds a new set of APIs, charge_get_actual_current() and charge_get_actual_voltage() which provides the actual charge current and voltage if the charger IC is able to provide that information. BUG=b:182018616 BRANCH=dedede TEST=Build and flash madoo, verify that `charger` EC console command shows the set current and voltage targets instead of the measured values. Check that the `chgstate` command shows the measured values for use with the OCPC module. TEST=Verify that charging from the sub board works. TEST=Verify that resistances are still calculated and seem reasonable. Signed-off-by: Aseda Aboagye <aaboagye@google.com> Change-Id: I82565d18908d9ea0f54934787897937488e280e6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2750866 Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org>
* Avoid passing char values to ctype functionsSimon Glass2021-02-121-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With Zephyr's newlib we get a warning when trying to do this, since it includes the following note in: /opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi/include/ctype.h "These macros are intentionally written in a manner that will trigger a gcc -Wall warning if the user mistakenly passes a 'char' instead of an int containing an 'unsigned char'." Presumably this is so characters above ASCII 127 are handled correctly, even if these are seldom used. Update the few affected call sites to ensure the value is cast to an unsigned char so that it will not fall afoul of the newlib warning. Note that the ECOS version of the ctype functions does not make use of an array, so does not suffer from failure if negative values are passed. Still, it is harmless to fix it. BUG=b:180023514 BRANCH=none TEST=build zephyr volteer with CONFIG_NEWLIB_LIBC and see no warnings Signed-off-by: Simon Glass <sjg@chromium.org> Change-Id: Ieae2fab8c20b75baa46d01dd8cdb393c6bb5c2c2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2691413 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* Charger: Silent error retrieving CHARGE_PORT_NONE inputDiana Z2020-12-111-1/+5
| | | | | | | | | | | | | | | | | In OCPC, the charger_get_params() function will regularly be calling charger_get_input_current_limit() with the active charger chip. This may be CHARGE_PORT_NONE if the board is not currently charging. In these cases, silently return an invalid status. BRANCH=None BUG=None TEST=on drawcia, confirm no console spam with no active charger chip Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I9a6b85584488f9381b1e1b8d7527b7ebd68a75e0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2580838 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
* charger: Add driver method for linear chargingAseda Aboagye2020-12-101-0/+14
| | | | | | | | | | | | | | | | | | This commit adds a driver method for enabling linear charging. Some charger ICs have the ability to manipulate the BFET in the linear region. This commit just adds that method and an API for use by the rest of the system. BUG=b:174683659 BRANCH=dedede TEST=`make -j buildall` Change-Id: I1660c0598a402b1f3f82300052b7cd72b8154a31 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2570937 Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* charger: Add `charger_is_icl_reached()`Aseda Aboagye2020-12-101-0/+13
| | | | | | | | | | | | | | | | | | Some charger ICs have the capability to report whether they have reached the set input current limit. This commit simply exposes an API for use by the rest of the system to determine if the input current limit is reached. BUG=b:174167890 BRANCH=dedede TEST=`make -j buildall` Signed-off-by: Aseda Aboagye <aaboagye@google.com> Change-Id: Ic0e00a54c53c985104cf400f0ce36b7a090ca5f2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2568563 Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* charger: fail fast with EC_ERROR_UMIMPLEMENTEDEric Yilun Lin2020-12-091-113/+77
| | | | | | | | | | | | | | | This CL doesn't change the flow, just fail fast. need a refactoring. BUG=none TEST=make buildall BRANCH=none Change-Id: I896e46a67722d6e8ffc7db5dffebc60da0b7fc5c Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2578617 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* charger: replace charger_get_input_current usesEric Yilun Lin2020-12-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | Replace them with charger_get_input_current_limit which is aligned to the old usage, no funcional changes. Keep OCPC charger_get_input_current uses as was, since it is its intended use. Also, implement - isl923x_get_input_current, raa48900_get_input_current - sm5803_get_input_current_limit BUG=b:171853295 TEST=1. grep "\<charger_get_input_current\>"; only ocpc uses the function. 2. make buildall 3. test with CL:2569086 on waddledee(sm5803), waddledoo(raa489000), hayato(isl923x), pompom(isl923x), and ensure the output of `curr 0|1` equalts to the report of power meter. BRANCH=none Change-Id: I71aca33cbc88dda9b0238cb71b1609665a9c9a7f Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2569085 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* charger: add charger_get_input_current_limitEric Yilun Lin2020-12-081-0/+17
| | | | | | | | | | | | | | A pre-processing CL for the later CL which migrate API from charger_get_input_current. BUG=b:171853295 TEST=make buildall BRANCH=none Change-Id: Ia15ce47ac5d068b7125c58115e368f9dfa87958c Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2569084 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* charger: rename charger_set_input_currentEric Yilun Lin2020-12-081-5/+6
| | | | | | | | | | | | | | | charger_set_input_current was actually sets the input current limit, so renames it to charger_set_input_current_limit. BUG=b:171853295 TEST=make buildall TEST=not output from `grep -r "\<charger_set_input_current\>"` BRANCH=none Change-Id: Icf4e99f287a7d4fc2d9560e8502e46cc07bfc085 Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2569083 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* Charger: Add chgnum parameter to OTG set functionsDiana Z2020-08-271-4/+3
| | | | | | | | | | | | | | | | Add the charger number as an input for setting OTG output current and enabling it, both in the charger driver and in charge_set_output_current_limit(). Also add a clarifying note about the intent of CHARGER_SOLO. BRANCH=None BUG=b:147440290 TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I7656c19a87d8216f5efc72dcffa6d638064d3e2f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2376469 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* OCPC: Assume port == chgnum when checking OTGDiana Z2020-08-271-0/+3
| | | | | | | | | | | | | | | Since OCPC has one charger chip per port, it can be assumed in the charger_is_sourcing_otg_power() function that the port will be the same as the charger number with this config enabled. BRANCH=None BUG=b:147440290 TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Iff5130e9ac7c268d38fe75eb3eb1c9ea5864abd4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2376468 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* Charger: Call discharge on AC for all chargersDiana Z2020-08-271-7/+9
| | | | | | | | | | | | | | | This change adds a loop to the common charger driver to set discharge on AC for all chargers, since it's unlikely a caller of this API would only want this feature enabled for a single port. BRANCH=None BUG=b:164256610 TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Ib23a93259a630016cb0f1384a6fc2b19b2baafb1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2375725 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* Charger: Add dynamic charger chip countDiana Z2020-07-111-25/+35
| | | | | | | | | | | | | | | | Different DB options may cause different numbers of charger chips to be present on the system. Remove constant count for charger chips, and instead always call into the overridable function to query the count. BRANCH=None BUG=b:155963446 TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I0e65b8af351ecabe6f7b823e0e56f1932cc280a6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2277833 Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* OCPC: charger: Add support for VSYS compensationAseda Aboagye2020-06-041-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | Some charger ICs can compensate VSYS for losses across the board when charging from an auxiliary charger in an OCPC scheme. This commit adds that support to the common charger and OCPC framework such that it can be leveraged. Charger ICs which can dynamically compensate and don't need continuous adjustments should return EC_SUCCESS as the PID won't be needed. Other chargers should return EC_ERROR_UNIMPLEMENTED since they require continuous adjustments. BUG=b:147440290,b:148980016 BRANCH=None TEST=With driver changes made for RAA48900, build and flash on waddledoo, verify that charging from the sub board works on board revs 0 and 1. TEST=`make -j buildall` Signed-off-by: Aseda Aboagye <aaboagye@google.com> Change-Id: Ie6fb27260b2d6e040dbfdc0aaa5b64b52173037c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2191298 Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* Charger: Handle Vbus retrieval from secondary charger chipDiana Z2020-05-141-0/+4
| | | | | | | | | | | | | | | | | When a board is using multiple charger chips, fetch the Vbus level assuming that the port is the same as the charger number. When waddledee enables OCPC, the config can be easily changed to follow CONFIG_OCPC instead. BRANCH=None BUG=None TEST=on waddledee, "ectool usbpdpower 1" gives correct port 1 voltage Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I9226b8ffd12c515d2a638236f2e618799637296e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2191371 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* OCPC: Add concept of active charger ICAseda Aboagye2020-05-011-38/+60
| | | | | | | | | | | | | | | | | | | | | | | 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>
* charger: Add chgnum arg to charger_get_input_currentAseda Aboagye2020-04-151-5/+9
| | | | | | | | | | | | | | | | | | | | With the advent of OCPC, one charger per Type-C, it will be required to retrieve the input current per charger IC. This commit adds the chgnum argument to charger_get_input_current. For boards with a single charger IC, they should simply pass in 0 for this argument. BUG=b:147440290,b:148980034 BRANCH=None TEST=`make -j buildall` TEST=With other code, verify that queries for input current is targeted at the correct charger IC. Signed-off-by: Aseda Aboagye <aaboagye@google.com> Change-Id: Iac80255faa539a7b4cfeb495aaed2bf12e62f182 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2135961 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
* Charger: Add driver function for sourcing OTGDiana Z2020-03-211-0/+16
| | | | | | | | | | | | | Fold charger_is_sourcing_otg_power into the charger driver structure. BUG=None BRANCH=None TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I0526495fff8464539e216d2cf80c34e09af2c418 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2110530 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* Charger: Convert boards to use new driver structureDiana Z2020-02-041-57/+0
| | | | | | | | | | | | | | | This commit removes the temporary common charger chip configuration and instead puts the configuration in each board. BRANCH=none BUG=b:147672225 TEST=builds, runs on waddledoo and octopus Change-Id: If81aef31e48c65999a87e202494f286716114bbb Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2031855 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
* Charger: change get_vbus_voltage to return EC errorDiana Z2020-01-281-2/+3
| | | | | | | | | | | | | | | The other driver structure members return an ec_error_list value and fill in parameters to return data. This commit changes the get_vbus_voltage call to follow that model. BRANCH=None BUG=b:147672225 TEST=builds Change-Id: I7308502a9734274dd308b830762493c4d70d147a Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2015340 Reviewed-by: Jett Rink <jettrink@chromium.org>
* Charger: Create charger driver structureDiana Z2020-01-281-9/+434
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With upcoming boards which use multiple charger chips, the EC codebase needs to be changed to assume chargers may have different I2C ports. This commit creates the driver structure and wrapper functions, which for now are hard-coded to chip 0 for equivalent behavior with previous code. A general charger config is created for all boards in charger.c for now, which uses the build information to fill in the structure. All boards will default to defining CONFIG_CHARGER_SINGLE_CHIP, which in turn defines a CHARGER_SOLO which can be used by drivers which have code that needs to determine charger numbers. For boards which have multiple chips, they may undefine this config and should generate build errors if their driver is still using the hardcoded charger reference of CHARGER_SOLO. Older drivers may continue using CHARGER_SOLO in non-static functions until they're needed in a multiple charger board. For boards which may be supporting different I2C configurations for the charger over board versions, they may define CONFIG_CHARGER_RUNTIME_CONFIG to fill in these fields after boot. BRANCH=none BUG=b:147672225 TEST=builds, chargers on hatch and octopus work Change-Id: I390ede494226252e512595c48099fa1288ffe93e Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2008451 Reviewed-by: Jett Rink <jettrink@chromium.org>
* printf: Convert %b to %pbEvan Green2019-10-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | In order to turn on compile-time printf format checking, non-standard specifiers like %b (binary) must be removed. Convert that into %pb, which takes a pointer to a structure containing the value to print, and how many bits to print. Use the convenience macro BINARY_VALUE() to package these values up into a struct whose pointer is passed to printf(). Technically this is slightly more limited functionality than we used to support given all the possible flags, field width, and precision. However every existing instance in our codebase was using %0NNb, where NN is some number. If more variants are needed, the parameters structure can be expanded in the future. BUG=chromium:984041 TEST=make -j buildall BRANCH=None Change-Id: I8ef995dcf97af688fbca98ab6ff59b84092b69e3 Signed-off-by: Evan Green <evgreen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1733100 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* config: Merge CONFIG_CHARGER_V2 into CONFIG_CHARGERKeith Short2019-09-181-4/+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>
* 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>
* chgstv2: Fix manual control via EC console.Aseda Aboagye2018-06-011-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* 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>
* Add cprints() and ccprints()Vic Yang2014-05-211-1/+1
| | | | | | | | | | | | | | | | | | | | | 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>
* Add "debug" option to charge_state_v2.cBill Richardson2014-05-151-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | | This is useful for testing battery charge profiles. When enabled, a dump of all battery, charger, and charge state information will be printed whenever the battery charge percentage changes. BUG=none BRANCH=ToT TEST=make buildall -j On the EC console: chg debug on then watch the console while either charging or discharging the battery. Disable with chg debug off Change-Id: I6725c461461f90fcd812873f97490e980ab47bc6 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/199816 Reviewed-by: Alec Berg <alecaberg@chromium.org>