summaryrefslogtreecommitdiff
path: root/include/charge_manager.h
Commit message (Collapse)AuthorAgeFilesLines
* tree: remove unused P9221 wireless chargerTom Hughes2022-07-121-12/+0
| | | | | | | | | | | | | | BRANCH=none BUG=none TEST=Add 20 blank lines to common/charge_manager.c and 5 blank lines to common/usb_charger.c ./util/compare_build.sh -b all -j 120 = MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I0e1364f64fa9f749830cbaa4833fc856eed9abef Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3756173 Reviewed-by: Keith Short <keithshort@chromium.org>
* GPU: Add Nvidia GPU D-Notify driverDaisuke Nojiri2022-06-291-1/+1
| | | | | | | | | | | | | | | | | (Based on the driver written by Tim Wawrzynczak.) This patch adds Nvidia GPU D-Notify driver. It asserts a GPIO, sends a host event, and sets D-Notify level in shared memory when power availability changes (i.e. AC plug/unplug, battery charge/discharge). BUG=b:216485035 BRANCH=None TEST=make run-nvidia_gpu && make buildall Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I231619157fe03fb357882540ffa34b4d48fba253 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3716794 Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
* charge_manager: Export is_pd_portDaisuke Nojiri2022-06-291-0/+3
| | | | | | | | | | | | | | is_pd_port tells whether a port is a PD port or not. This patch makes it available to other compilation units. BUG=b:216206104 BRANCH=None TEST=buildall Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I12dde5032b9e6422eed504591d1d005895b1daac Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3733414 Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
* include/charge_manager.h: Format with clang-formatJack Rosenthal2022-06-281-26/+21
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: Ib8c102aac348d4bab2e4385d8b4add49f9ddbba2 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3730220 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* charge_manager: Make chgsup print moreDaisuke Nojiri2022-06-191-1/+39
| | | | | | | | | | | | | | | | | | | | | | | | | This patch makes chgsup command print all available charge port information. > chgsup Port --Supplier-- Prio -Avalable Power- P0 PD 1 3000mA 15000mV USBC_1_5A 4 500mA 5000mV VBUS 4 500mA 5000mV *P2 DEDICATED 0 7700mA 19500mV Left safe mode Override port = -1 BUG=None BRANCH=None TEST=See above Change-Id: I3531b445f8d79c910150db643363aa84b74aee94 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3710279 Reviewed-by: Keith Short <keithshort@chromium.org>
* zephyr: shim: add single charge task supportFabio Baltieri2022-06-031-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | Add an option to run the charger code in a single task. This is enabled by default in Zephyr builds, but explicitly disabled for a couple of platforms that currently have task dependent board code. Should be enough to start testing the configuration, will work on handling the remaining boards (corsola and nissa) later. BRANCH=none BUG=b:226411332 TEST=make buildall TEST=zmake testall TEST=cq dry run TEST=run on Brya, connect/disconnect usb devices Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com> Change-Id: I75a63f7b0a9545e6c824114de7f81b71924e0789 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3663748 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Reviewed-by: Aaron Massey <aaronmassey@google.com>
* charge: respect PDO current maximum limitEric Yilun Lin2021-10-151-0/+9
| | | | | | | | | | | | | | | | | | | | | | The current input limit setting doesn't respect the PDO's current limit (e.g. when the current limit is less than CONFIG_INPUT_CURRENT_LIMIT) and this might cause the over-draining the charger. BUG=b:172878439 TEST=1) make buildall 2) modified servo-v4 which only broadcast PDOs with 250mA current limit and ensure the goroh won't sink more than 250mA. (while the CONFIG_INPUT_CURRENT_LIMIT is 512mA) BRANCH=main Change-Id: I09f8e6fb39a072ee38ea09a5c9898984f4122513 Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3220037 Commit-Queue: Eric Yilun Lin <yllin@google.com> Tested-by: Eric Yilun Lin <yllin@google.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* charge_manager: board specific callback to get vbus voltageSue Chen2021-08-271-0/+6
| | | | | | | | | | | | | | | | Add board_get_vbus_voltage to get vbus voltage by board, for ADC_VBUS maybe is only for one typec port when the DUT supports multiple typec. BUG=b:196001868 BRANCH=none TEST=show correct C1 vbus voltage on tomato Signed-off-by: Sue Chen <sue.chen@quanta.corp-partner.google.com> Change-Id: Ia567ec3bddf4f62a08c9902b4f0721783f2c07ff Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3084403 Reviewed-by: Ting Shen <phoenixshen@chromium.org> Commit-Queue: Ting Shen <phoenixshen@chromium.org>
* charge_manager: Expose get_vbus_voltage functionAbe Levkoy2021-01-221-0/+8
| | | | | | | | | | | | | Allow other modules to get the current VBUS voltage. BUG=b:169385081 TEST=make buildall BRANCH=none Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Change-Id: I1c4a22fff0d7e44ef47c2d8a3ff6e25e1a6ded1e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2639583 Reviewed-by: Diana Z <dzigterman@chromium.org>
* charge_manager: two charger DUT does not choose correct portDenis Brockus2020-09-081-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | The active charge_port is selected in a delayed call to charge_manager_refresh. This leaves a big window allowing a better charger to be detected but not acted upon as the soon to be active charge_port. This leads to the PD Policy Engine deciding this better port is not the current active charge_port and down grading the current limit for the port to no longer be the best choice. So when the charge_manager_refresh is called, it starts changing ports and then later checks for the best port and then swaps back to a lesser charger. BUG=b:166228326 BRANCH=none TEST=USB-C0 45W then attach USB-C1 65W charger Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I23dad1e4690285b3867bd046d9416db9522002e8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2393863 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Commit-Queue: Edward Hill <ecgh@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Edward Hill <ecgh@chromium.org>
* usb_pd: request preferred voltage PDOYilun Lin2019-12-091-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add CONFIG_USB_PD_PREFER_MV to support PD will request preferred voltage. One should define pd_pref_config, including preferd voltage, e.g. 5000, and PD_PREFER_BOOST or PD_PREFER_BUCK based on the board charging efficiency. Also, system PLT power is needed for evaluating board's desired power. The option will try to find a most fit PDO: 1. Pick the PDO which fulfills the system desired power. If a preferred voltage PDO doesn't provide enough power, it will be skipped. 2. If none of the PDO meets the preferred voltage, it will pick the closest voltage PDO based on prefer boost or prefer bulk. 3. The system desired power will be constantly updated when system in constant voltage stage (battery percent > 70%). This is done by monitoring the battery charging current. 4. If the system desired power changes, it will re-evaluate the PDO and send request if has a better fit. TEST=Set prefer_mv to 5000 and ensure PD voltage could pick 9V/12V when desired voltage > 15W (5V/3A) and pick 5V when desired voltage <= 15W BUG=b:141170279 b:141903096 b:144073892 BRANCH=kukui Change-Id: I94646cb1c74c10cf8db889f19c3df6339844042c Signed-off-by: Yilun Lin <yllin@chromium.org> Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1871499
* Rename CONFIG_USB_PD_PORT_COUNT as CONFIG_USB_PD_PORT_MAX_COUNTKarthikeyan Ramasubramanian2019-11-011-3/+3
| | | | | | | | | | | | | | | | | Certain SKUs of certain boards have lesser number of USB PD ports than defined by CONFIG_USB_PD_PORT_COUNT. Hence rename CONFIG_USB_PD_PORT_COUNT as CONFIG_USB_PD_PORT_MAX_COUNT. BUG=b:140816510, b:143196487 BRANCH=octopus TEST=make -j buildall; Boot to ChromeOS Change-Id: I7c33b27150730a1a3b5813b7b4a72fd24ab73c6a Signed-off-by: Karthikeyan Ramasubramanian <kramasub@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1879337 Tested-by: Karthikeyan Ramasubramanian <kramasub@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Jett Rink <jettrink@chromium.org>
* charge_manager: Mark functions overridableDaisuke Nojiri2019-08-141-2/+3
| | | | | | | | | | | | | | | | | | | Functions such as board_fill_source_power_info are overridable. This patch annotates them properly using override macros, and removes their declarations from board.h. These functions are declared in both charge_manager.h and {kukui,krane,kodama}/board.h. The latter causes comm-dev.c to fail to be compiled in chrome-base/diagnostics. BUG=none BRANCH=none TEST=buildall Change-Id: I27d6dfe2fa9299550ac5205c34095a4fe02dabdb Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1752597 Tested-by: Yu-Ping Wu <yupingso@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>
* charge_manager: customize dedicated port propertiesTing Shen2019-06-051-2/+49
| | | | | | | | | | | | | | | | | | | Kukui's pogo charger breaks the basic assumption of a dedicated charger. Add board specific functions to customize them. Also add a check to make sure the value of DEDICATED_CHARGE_PORT is good. BUG=b:128386458 TEST=combine with CL:1535087, verify that `ectool usbpdpower 1` correctly reports its status. BRANCH=None Change-Id: I6c698ea6a6fb4ab765f87c6fea0b35d5a757295a Signed-off-by: Ting Shen <phoenixshen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1569090 Reviewed-by: Yilun Lin <yllin@chromium.org> Tested-by: Ting Shen <phoenixshen@chromium.org> Commit-Queue: Ting Shen <phoenixshen@chromium.org>
* chgmgr: Allow boards to customize supplier_priorityDaisuke Nojiri2019-05-291-0/+6
| | | | | | | | | | | | | | | | | | | Currently, supplier_priority is shared across boards. This patch makes it weakly defined so that boards can customize it. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=none BRANCH=none TEST=Verify BC12, PD work on Flapjack. buildall. Change-Id: Ie1e73758c611414512425121164bf7d56cf02697 Reviewed-on: https://chromium-review.googlesource.com/1622889 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* charge_manager: Revisit charge supplier priority.stabilize-12206.BYilun Lin2019-05-141-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | According to USB-C spec 1.3 Table 4-17 "Precedence of power source usage", the supplier's priority should be: USB-C 3.0A/1.5A > BC1.2 > USB-C under 1.5A. This CL propose to raise the BC1.2 priority to fix that charge_manager won't choose BC1.2 when the port reports it can supply both TYPEC 500ma and BC1.2 supplier. According to the spec mentioned aboved, we should prefer BC1.2 rather than TYPEC. Besdies, charge_manager is able to pick the supplier which provides the higheste power. The CL simplifies the supplier priority a bit by taking advantage of the feature. TEST=Charge kukui with 5V/2A charger and see it can drain 1.34A (DCP current bound of mt6370 is 1.5A) rather than 0.5A. TEST=Charge kukui with Type-C 5V3A/CDP/DCP/SDP/PD charger randomly and see that the current it drains is reasonable. TEST=Charge soraka with 'A', and plug another port with 'B', and see it can transist the sinking port from A to B. Here (A, B) are: 1. (SDP 5V0.5A, Type-C 5V3A) 2. (CDP 5V1.5A, PD) 3. (SDP 5V0.5A, CDP 5V1.5A) 4. (CDP 5V1.5A, Type-C 5V3A) 5. (Type-C 5V3A, PD) BUG=b:131126720 BRANCH=None Change-Id: I46384e09d764aa926129358657d0593fca4923c2 Signed-off-by: Yilun Lin <yllin@google.com> Reviewed-on: https://chromium-review.googlesource.com/1581859 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Yilun Lin <yllin@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* P9221: Add P9221 driverTony Zou2019-04-221-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds P9221 driver and enable it for Flapjack. The driver originates from https://android.googlesource.com/kernel /msm/+/android-msm-bluecross-4.9-pie-qpr1/drivers/power/supply/qcom /p9221_charger.c CQ-DEPEND=CL:1445133 CL:1551583 BRANCH=none BUG=b:126162615 TEST=Verify charging from PD and WPC as follows: 1. Charge with PD charger. Place DUT on WPC charger. -> PD charger continues to charge. 2. Unplug PD charger. -> WPC starts charging as GPP. 3. Plug PD charger. -> PD charger starts charging at 2A@9V TEST=Verify OTG and WPC functionality as follows: 1. Plug fan to USB port: -> Fan spins 2. Place DUT on WPC charger: -> WPC starts charging as GPP. Fan continues to spin. 3. Remove DUT from WPC charger: -> Fan continues to spin. 4. Do 1 and 2 then unplug USB fan: -> WPC starts charging. TEST=/sys/class/power_supply/CROS_USBPD_CHARGER0/usb_type is BrickID /sys/class/power_supply/sbs-12-000b/status is ok Change-Id: I5fbd0237cedd8095f98582c39973d432e733f2cd Signed-off-by: Tony Zou <zoutao@huaqin.corp-partner.google.com> Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1448193 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
* chgmgr: Allow charge_manager_update_charge to accept NULLDaisuke Nojiri2018-09-201-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | Currently, charge_manager_update_charge does not handle NULL pointer for struct charge_port_info any differently. It's not sanity-checked either (thus memory access violation can occur). This patch will make charge_manager_update_charge accept NULL pointer and set available current and voltage to zero. This also helps callers' intentions be clear because callers can explicitly specify NULL (instead of passing a pointer to chg = {0}, which is initialized somewhere else). Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=none BRANCH=none TEST=buildall Change-Id: I518662ab6a3a07f93da5d34cf62a6f856884f67d Reviewed-on: https://chromium-review.googlesource.com/1226125 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* charge_manager: Use enum for CHARGE_SUPPLIER_NONEDaisuke Nojiri2018-09-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | Currently, CHARGE_SUPPLIER_NONE is defined as a macro. This causes the compiler to allocate uint8_t to enum charge_supplier. When -1 passed to or returned from a function, it's cast to 0xff. This patch defines CHARGE_SUPPLIER_NONE in enum charge_supplier. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=none BRANCH=none TEST=Verify ectool usbpdpower 1 return 'Port 1: Disconnected' and 'Port 1: SNK (not charging)' without and with a BJ adapter connected respectively on Fizz. Change-Id: I31bfa33efa91f60c6667f3b0de9cbdf9c6b3e8bf Reviewed-on: https://chromium-review.googlesource.com/1217605 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
* charge_manager: Pass struct charge_port_info as constDaisuke Nojiri2018-06-071-1/+1
| | | | | | | | | | | | | | | | | This patch changes the prototype of charge_manager_update_charge to mark 'struct charge_port_info *' as const. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=none BRANCH=none TEST=buildall Change-Id: I36211e75a51009d7f507897be85745f4ffbe797e Reviewed-on: https://chromium-review.googlesource.com/1089570 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* usbc: add config support for multiple (and no) vbus adc channelsJett Rink2018-03-091-0/+10
| | | | | | | | | | | | | | yorp measures each port's vbus separately on a deticated ADC. Also, add config to take care of ADV_VBUS -1 case too. BRANCH=none BUG=b:74127309 TEST=none Change-Id: I6f4df96caffc3b527b69e67358631dd448172cde Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/956555 Reviewed-by: Edward Hill <ecgh@chromium.org>
* charge_manager: Add EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMITDaisuke Nojiri2017-11-281-0/+4
| | | | | | | | | | | | | | | | | | Usually, the max current and supply voltage of dedicated chargers are not known to the EC. This patch adds EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT, which allows the host to change the max current and supply voltage of the dedicated charge port. BUG=b:64442692 BRANCH=none TEST=make runtests && buildall. Boot Fizz and let coreboot set the adapter current and voltage. Change-Id: I29b3f5762f8b316ca363c23e230530cdf4ca207a Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/769152
* Fizz: Switch power source to BJ at G3/S5Daisuke Nojiri2017-11-131-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | This patch allows Fizz to switch the power source from a type-c charger to a barrel jack adapter if the system is in S5. BUG=b:38321259 BRANCH=none TEST=Verify the following with 45W and 60W type-c chargers: 1. Boot Fizz with a type-c charger 2. Go to S5 if not already. 3. Plug in a BJ adapter. Fizz boots to S0 using BJ power. Also verified other boot modes are not affected: 1. Auto boot on BJ insert 2. Auto boot on Type-C insert 3. Recovery boot on BJ 4. Recovery boot on Type-C 5. Stay off if it's previously S5 Change-Id: I86aa0fe6e403bcbacfe396997d897111ffcf8e74 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/706251 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* charge_manager: Enter safe mode at bootShawn Nematbakhsh2017-11-021-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | Charge port / current selection often needs to be significantly altered when a battery cannot provide sufficient charge, so have charge_manager initially enter safe mode. After a battery with sufficient capacity has been identified, charge manager will leave safe mode, and port / current selection will return to standard rules. BUG=chromium:777596 BRANCH=None TEST=Pass charge_manager unit tests. On kevin, remove battery, attach Apple PD charger, verify safe mode is not exited and device does not brown out. Hot-plug battery and verify safe mode is exited. Next, remove battery, attach to Samus, verify safe mode is not exited and device doesn't brown out. Hot-plug battery, verify that safe mode is exited and no active charge port, due to dual-role exclusion. Change-Id: I7784865750087a037aad8dbbac058b22c77ba6d4 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/733954 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* charge_ramp: Ramp USB-C DTS sourcesShawn Nematbakhsh2017-10-191-0/+1
| | | | | | | | | | | | | | | | | | | | suzy-qable advertises 1.5A, but its actual capability depends on the host USB port it is attached to. Since suzy-qable is ubiquitous and other DTS sources may behave in the same way, ramp the input current limit in order to find a reasonable maximum. BUG=chromium:770296 BRANCH=None TEST=Attach suzy-qable to kevin and reef, verify that neither OCs and EC console via cr50 is available on reef. Also verify donette chargers kevin at 3A and does not ramp. Change-Id: Idd0683ede3a44111a01da6b4faab52f388ee82fd Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/693295 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* charge_manager: Support no-BC1.2 configurationShawn Nematbakhsh2017-09-281-0/+8
| | | | | | | | | | | | | | | | If BC1.2 isn't supported, don't waste space + time checking for inputs that don't exist. BUG=chromium:759880 BRANCH=None TEST=`make buildall -j` Change-Id: I47e81451abd79a67a666d1859faf2610ee5c941a Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/663838 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* Fizz: Give highest priority to dedicated chargersDaisuke Nojiri2017-09-121-0/+3
| | | | | | | | | | | | | | | | | This patch gives the highest priority to dedicated chargers. It means if a dedicated power supply is being connected, other power supplies such as USB-C adapters will not be recognized as a new charger. BUG=b:65059574 BRANCH=none TEST=Boot Fizz on BJ adapter. Verify plugging in Type-C adapter doesn't shut down the system. Change-Id: Ie49b128ae64f917a227f9081148565a3f5356212 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/655638 Reviewed-by: Shawn N <shawnn@chromium.org>
* charge_manager: Consider port in source PDO.Aseda Aboagye2017-08-111-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | When CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT is defined for a board, as its name implies, the board can source a higher current if there is only one port acting as a source. This commit fixes an issue with selecting the right source capability message to advertise. charge_manager_get_source_pdo() was simply checking if there was more than one sink connected, instead of checking if there were any *other* sinks connected. In the event that a sink was connected to a different port, we would advertise the max source PDO. BUG=b:64037926, b:35577509 BRANCH=gru,eve,reef TEST=Connect sink to port 1. Connect a AMA to port 0 that claims that VBUS isn't necessary. Start sending source caps, verify that the max PDO is not being advertised in the source caps. Change-Id: Ie4145ecaf98d5b9070ad3e8b139e5653685fa801 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/610479 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* charger: Add dedicated (non-type-c) chargerDaisuke Nojiri2017-05-111-0/+3
| | | | | | | | | | | | | | | | This patch adds a dedicated charge port. The number of such ports is specified by CONFIG_DEDICATED_CHARGE_PORT_COUNT. It works as a sink only. The total number of charge ports is represented by CHARGE_PORT_COUNT. BUG=chromium:721383 BRANCH=none TEST=make buildall. Boot Fizz off of barrel jack. Change-Id: Ibbb11f3e1c66e35b5abe190e49161eeaa2009994 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/501468 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Revert "charge_ramp: Adjust minimum ramp current"Vijay Hiremath2017-01-181-9/+0
| | | | | | | | | | | | | | | | | | | | From the USBC spec 1.2 "Table 4-14 Precedence of power source usage" USB Type-C 3.0 A & 1.5 A takes precedence over BC1.2. Hence reverting this patch. This reverts commit 6a7e4a7b353c53d33d44662c71763490ffd1fdc4. BUG=chrome-os-partner:61420 BRANCH=none TEST=make buildall -j Change-Id: I2ed3f767973ff9c47fa7d2a2cca1aca15d13aa65 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/430152 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> Reviewed-by: Benson Leung <bleung@chromium.org>
* charge_ramp: Adjust minimum ramp currentVijay Hiremath2017-01-131-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | A valid charge port is always detected as VBUS supplier type, 'USB charger' can detect the same port as BC1.2 DCP supplier type & also 'TCPC' can detect the same port as TYPEC supplier type. Thus a valid port is detected as 2 or 3 supplier types. Depending on the supplier's priority and the power that the supplier can provide, charge manager choses the charge supplier type of the port. If the USB charger detected supplier is BC1.2 DCP and the TCPC detected supplier is TYPEC then the supplier can provide stable current from TYPEC supplier's advertised current hence start ramping from TYPEC supplier's advertised current. BUG=chrome-os-partner:61420 BRANCH=none TEST=Manually tested on reef. Donette bottom port can switch from 1.5A to 3A upon high load. Change-Id: I871eca3ae4041f00bb3fd50e6aa939643f30a1f2 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/427961 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>
* charge_manager: cleanup and documentphilipchen2016-12-061-16/+70
| | | | | | | | | | | | | | | Remove some runtime assert to reduce code size. Improve the documentation. BUG=chromium:670886 BRANCH=none TEST=make buildall -j Change-Id: I60bd787fad94779cd978aefa26e0581fb5f6ebef Reviewed-on: https://chromium-review.googlesource.com/416392 Commit-Ready: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* charge_state_v2: Limit i/p current to meet allowed MAX i/p system powerVijay Hiremath2016-12-051-1/+3
| | | | | | | | | | | | | | | | | | | | | If battery is not present, input current is set to PD_MAX_CURRENT_MA. If the input power set is greater than the maximum allowed system power, system might get damaged. Hence, limit the input current to meet maximum allowed input system power. BUG=chrome-os-partner:58498 BRANCH=none TEST=Manually tested on Reef. Removed the battery & using 'charger' console command observed the following. With Zinger charger at 20V - Input current is set to 2.25A With Type-C & other chargers - Input current is set to 3A Change-Id: Ife8686f322e095aa74b740a7c469bfe87107fb9a Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/397865 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Shawn N <shawnn@chromium.org>
* pd: Limit input current to 500mA on PD voltage transitionShawn Nematbakhsh2016-12-051-0/+10
| | | | | | | | | | | | | | | | | | | Upon requesting a PD power contract at a new voltage, keep the input current limit at 500mA until PD_RDY is received. BUG=b:30744563,chrome-os-partner:59311,chrome-os-partner:44340 BRANCH=ryu, gru, glados TEST=Manual on kevin, set ilim to 5V through `chglim` console command, attach zinger. Set ilim to 20V through `chglim`, verify that ilim goes from 3A to 500mA to 3A. Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I452f183cfb958780e336a9f99dc6398356de17a0 Reviewed-on: https://chromium-review.googlesource.com/399918 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Todd Broch <tbroch@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* kevin: set accurate current limit on USB load switchVincent Palatin2016-10-311-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | When sourcing current on the type-C port, set the OCP limit on the VBUS load switch according to current dynamic capability. (3.0A when only one port is a power source, 1.5A else) Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=gru BUG=chrome-os-partner:56110 TEST=manual: connect Caroline to Kevin with Twinkie in between, ask Caroline to sink current through the UI. without anything else connected on Kevin, see 3A flowing when measuring with Twinkie ('tw vbus'), plug a dangling C-to-A receptacle dongle on the other Kevin port and see 1.5A flowing through Twinkie. Force the input current limit on Caroline to 3.0A and see Kevin cutting VBUS. Change-Id: Ib879b1ed720b20aa702c5f3643948ba0575d1193 Reviewed-on: https://chromium-review.googlesource.com/403869 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* charger v2: Don't set charger current limit if capability is unknownShawn Nematbakhsh2016-09-211-1/+1
| | | | | | | | | | | | | | | | | | If charge_manager has not decided on a current limit, don't set a minimum current limit, since we may brown-out in the no / low-battery case. BUG=chrome-os-partner:56139 BRANCH=None TEST=Manual on kevin, attach cut-off battery, attach OEM charger, verify system doesn't brown-out due to OC. Change-Id: Id53eb32c4a8ac9c6d9a0d3f1d700f089a50fcb0f Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/386793 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* charge_manager: Pass uncapped / max current to current limit callbackShawn Nematbakhsh2016-09-131-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | charge_manager may request a charge current limit less than the capability of the supply in certain cases (eg. during PD voltage transition, to make an effort to comply with reduced load spec). Depending on the battery / system state, setting a reduced charge current limit may result in brownout. Pass the uncapped / max negotiated current to board_set_charge_limit() so that boards may use it instead of the requested limit in such circumstances. BUG=chrome-os-partner:56139 BRANCH=gru TEST=Manual on kevin with subsequent commit, boot system with zinger + low-charge battery, verify devices powers up to OS without brownout. Change-Id: I2b8e0d44edcf57ffe4ee0fdec1a1ed35c6becbbd Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/383732 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* pd: manage total source current availableVincent Palatin2016-09-011-0/+11
| | | | | | | | | | | | | | | | | | | Add a policy to handle the case where the device can source the `CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT` over one of its type-C port if there is no sink connected on the other ones. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=none BUG=chrome-os-partner:56110 TEST=manual: on Kevin, plug and unplug various devices on the 2 ports, while measuring the type-C pull-up with Twinkie. Change-Id: Id5961f04d0a1b1073f5ab340068efd9079918209 Reviewed-on: https://chromium-review.googlesource.com/373818 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* Driver: BD99955: Enable BC1.2 supportVijay Hiremath2016-05-241-1/+1
| | | | | | | | | | | | | | | | | BUG=none BRANCH=none TEST=Manually tested on Amenia. Connected Zinger, Type-C, DCP & CDP chargers. Device can negotiate to desired current & voltage and the battery can charge. USB2.0 sync device is detected by Kernel. Change-Id: I58cb69289eef9a966e06bef8fe31d35beaec5e27 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/341030 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Kevin K Wong <kevin.k.wong@intel.com> Reviewed-by: Shawn N <shawnn@chromium.org>
* charge_manager: Report UNKNOWN USB charger for 2 seconds after changeShawn Nematbakhsh2016-04-031-0/+6
| | | | | | | | | | | | | | | | | | | After a charger is attached, we may set a charge limit based upon BC1.2 or USB-C Rp before PD negotiation completes. Therefore, allow 2 seconds for all negotiation to complete. Previously this behavior was implicit when using SW charge ramp. BUG=chrome-os-partner:51280 BRANCH=glados TEST=Manual on chell. Insert stock charger, verify that it is detected as TYPE_UNKNOWN until timeout. Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I52f02de46fa92b66a9fbaddb94a062310688f028 Reviewed-on: https://chromium-review.googlesource.com/334312 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* charger/Kunimitsu: Fix for boot from cut-off batteryVijay Hiremath2016-02-021-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Battery in cut-off mode wakes when voltage is applied to the PACK and takes approximately 2 to 3 seconds to initialize before capable of providing the power. Hence made the battery present status to BP_NO in case of cut-off mode. Once the battery is ready new status is updated as BP_YES. When the battery status changes from BP_NO to BP_YES, charger input current is set to board specific charger input current which is not sufficient to boot the AP hence the system reboots. To avoid this issue, added code to write charger manager negotiated current to charger input current when the battery status changes from BP_NO to BP_YES. BRANCH=none BUG=chrome-os-partner:49224 TEST=Manually tested on Kunimitsu. Used console command 'cutoff' to put the battery in cut-off mode. Inserted the adopter to wake the system, system doesn't reboot & the battery charges. Change-Id: Ia5a1457506b4bef0b3dd27993e4b60ae64c8f746 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/322430 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* charger: Add LIMIT_POWER charger param for low bat + weak chargerShawn Nematbakhsh2015-10-271-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for two new configs to specify critical energy battery percentage and critical external charger power. When we are under both thresholds, set the LIMIT_POWER charger parameter to inform the AP that it should conserve power to avoid brownout, and consider jumping to EC RW to negotiate PD. In addition, modify the existing CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON to allow power-up regardless of power level if a 15W+ charger is attached, since there is a reasonable chance it may speak PD and provide sufficient power to boot the AP. BUG=chromium:537269 TEST=Manual on Glados. Set CHG_MW thresh to 20000, BAT_PCT to 50. Verify that LIMIT_POWER charger param is set until Zinger negotiates to 20V. Also veify that system can boot with Donette. BRANCH=None Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: Ic963c82fea4ad10e8a5d7e476c5ce3e5ae525dad Reviewed-on: https://chromium-review.googlesource.com/306774 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org>
* charge_manager: Support multiple independent charge ceilingsShawn Nematbakhsh2015-08-191-2/+15
| | | | | | | | | | | | | | | | We will soon have a need to independently set a charge ceiling from both the PD state machine and from incoming host commands. Store these ceilings separately, and have the minimum take effect. BUG=chrome-os-partner:43285 TEST=Pass unit tests. Also, host command current limit takes effect with subsequent commit. BRANCH=None Change-Id: I0ecfe888a7df0d5da5a68999c164c7c841da348b Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/293818 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* cleanup: remove board function callback on charge override timeoutrelease-R45-7262.BAlec Berg2015-07-131-3/+0
| | | | | | | | | | | | | | | | | Remove board function callback on charge override timeout, since the implementation should be common to all boards: send host event. This function is called when a power swap fails during an issued charge override and notifies the host so that it is aware that the power swap did not succeed. BUG=none BRANCH=smaug TEST=make -j buildall Change-Id: Ia2a078a17aef6b302fd2b9fd21a5a92c628fd7db Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/284923 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* cleanup: define one set of USB charger voltage and min currentAlec Berg2015-07-131-2/+0
| | | | | | | | | | | | | | | Remove duplicate definitions of USB charger min current across boards and make one set of defines for standard USB charger voltage and minimum USB charger current. BUG=none BRANCH=smaug TEST=make -j buildall Change-Id: Ib842fafb317417c8de9a67d314fdde4c1e47ad9d Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/284956 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* cleanup: fix all the header guardsBill Richardson2015-06-181-3/+3
| | | | | | | | | | | | | | | 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>
* charger: Move USB charger / BC1.2 task to common codeShawn Nematbakhsh2015-06-101-0/+15
| | | | | | | | | | | | | | | | Move the task responsible for detection of USB chargers to common code to reduce code duplication. BUG=chrome-os-partner:40920 TEST=Manual on samus_pd. Plug USB charger, verify detection is correct on both charge ports. BRANCH=None Change-Id: I362f8b5b51741509e459c66928131f1f6d2a3b1d Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/276210 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org>
* pd_log: Add command to request PD MCU to write a logShawn Nematbakhsh2015-02-121-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | When we find that charging is in a wedged state, we may wish to write a PD log entry, but the PD MCU cannot detect such a state on its own. Therefore, add a new command to ask the PD MCU to write a log of a given type, and add a new board-specific custom log event. BUG=chrome-os-partner:36668 TEST=Manual on samus: ./ectool --dev=1 pdwritelog charge 0 ./ectool --dev=1 pdwritelog charge 1 ./ectool --dev=1 pdwritelog 1 0 ./ectool --dev=1 pdwritelog 2 0 ./ectool --dev=1 pdlog Verify log output matches expectation: 2015-02-12 11:12:49.290 P0 SRC 2015-02-12 11:12:49.296 P1 SNK Charger PD 20286mV max 20000mV / 3000mA 2015-02-12 11:12:49.303 P0 New connection 2015-02-12 11:12:49.310 P0 Board-custom event --- END OF LOG -- Also, verify kernel logging of wedged event: [ 181.378420] PDLOG 2015/02/12 19:13:44.019 P0 Event 02 (0000) [] Also, trigger wedged state on Samus and verify log entry is written. BRANCH=Samus Change-Id: I55c7c839cf8300fcd3931dccdaaf16c1065e31a8 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/248981 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* charge_manager: Minimize log spewShawn Nematbakhsh2015-02-111-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | Previously, we tried to minimize log spew by keeping track of previous log entries and not writing new entries in some cases. Instead, we can write a log on the following events only: 1. A port becomes active or 2. A port becomes inactive or 3. The active charge port power limit changes or 4. Any supplier change on an inactive port Also, make charge_manager_save_log a non-static charge manager API function, so that other modules can record a log, if they have reason to believe a port has changed outside of a charge manager change. BUG=chrome-os-partner:33248 TEST=Manual on Samus. Make various power actions and observe logging. BRANCH=Samus Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I5d5d3e186e85fdb1c59797ffbfb2f5a6ec04d94d Reviewed-on: https://chromium-review.googlesource.com/247891 Reviewed-by: Alec Berg <alecaberg@chromium.org>