summaryrefslogtreecommitdiff
path: root/include/charge_manager.h
Commit message (Collapse)AuthorAgeFilesLines
* charge_manager: Wait for dualrole determination before chargingShawn Nematbakhsh2015-02-081-3/+6
| | | | | | | | | | | | | | | | | | | | | | | If a dual-role charger is plugged, we will not realize it is dual-role until after we see a type-C charge source. It can cause us to briefly charge from a dual-role charger, which has bad side effects related to charge override and the lightbar. Fix this by not charging from a port until we are fairly certain that it is a dedicated charger (based upon PD discovery timeout). BUG=chrome-os-partner:36390 TEST=Manual on Samus. Insert 1A Apple charger, verify correct detection. Run 'chgoverride -2' to prevent charging, then repeatedly insert + remove a dual-role charger on the other charge port. Verify that charging is still prevented. Finally, insert a dedicated charger and verify that the override is removed. Also, pass unit tests and verify correct detection in various scenarios with various chargers. BRANCH=Samus Change-Id: Ia4154f34dd0a850b6e72bebadbd938f034532f14 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/247130 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* samus: when battery is full, and not in S0, stop chargingAlec Berg2015-01-031-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When battery is full and system is not in S0, then stop charging and allow battery to power the system. Once battery is no longer full and requests current, allow charging again. This is to work around power consumption issues in our AC input path. The charge override port is stored upon entering S3 and restored going back to S0 so that the charge override port is not affected by this. This also fixes lightbar so lightbar checks if battery is full instead of checking raw percentage. The lightbar is also changed to use the last tap direction if no charger is plugged in. And the lightbar tap for battery threshold for turning green is lowered to 95%. This also moves some samus_pd board code out of interrupt handlers and in to deferred functions to minimize time in interrupts. BUG=chrome-os-partner:34640, chrome-os-partner:34847 BRANCH=samus TEST=load onto samus. use battfake command from pd console to set battery percentage. when system is in G3, see that batt = 100% stops charging, and when batt < 100% it starts charging again. tested that we receive host command from EC with battery information every time battery changes SOC. Change-Id: Ia8e0721508e34ee3630f5e5b0c2f431a00329caf Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/236411 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* charge_manager: Allow board to reject a selected charge portShawn Nematbakhsh2014-12-171-1/+12
| | | | | | | | | | | | | | | | | | | Modify board_set_active_charge_port to return status indicating whether the selected charge port was rejected. If rejected, zero out its available charge and attempt to select a different charge port. Also, reduce the length of related console prints. BUG=chrome-os-partner:34677 TEST=Manual on Samus. Plug C-to-Arec into port 1, verify that charge manager does not select port 1 as active and charging icon is not seen in OS. BRANCH=Samus. Change-Id: I56e3337f90c04b93ef7cc9873af6ee0f4b1ffc7d Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/236361 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* charge_manager: Add delayed port override for role swapShawn Nematbakhsh2014-12-091-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | If override charge is selected on a port currently acting as a charge source, but the attached device is also capable of acting as a source, request a charge role swap and initiate a pending delayed port override. If the role swap completes successfully and a charge source is found, the selected port will become the override port. If the role swap fails or no charge source is found within 2 seconds, the delayed port override will be lost. BUG=chrome-os-partner:28343,chrome-os-partner:31195 TEST=Manual on Samus. Connect two Samus units together through charge ports. "pd 1 swap power" - put port on test device into source role "chgoverride 1" - set charge override, verify that role swap takes effect and charge manager selects PD charge source, 900mA @ 5V Disconnect charge cable, verify that charge manager goes back to not charging. BRANCH=Samus Change-Id: Iadcc4dc98631661f254245eeff18973df517f652 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/231900 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* charge_manager: Add PD_CHARGE_PORT_OVERRIDE host commandShawn Nematbakhsh2014-11-201-7/+0
| | | | | | | | | | | | | | | | | | | Add host command to set charge port override. BUG=chrome-os-partner:32003 BRANCH=Samus TEST=Manual on Samus. Insert PD charger in port1 and BC1.2 charger in port0. ./ectool --name=cros_pd chargeoverride 0 --> Charges from port 0 ./ectool --name=cros_pd chargeoverride off --> Charges from port 1 ./ectool --name=cros_pd chargeoverride dontcharge --> No charge port ./ectool --name=cros_pd chargeoverride 1 --> Charges from port 1 ./ectool --name=cros_pd chargeoverride 2 --> Correctly returns error Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: Ib35f797a4a24e96fd2e3c008ace3fd6291b89d25 Reviewed-on: https://chromium-review.googlesource.com/230910 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* charge_manager: Add charge port override functionalityShawn Nematbakhsh2014-11-131-0/+10
| | | | | | | | | | | | | | | | | Allow a charge port to be selected as the override port, which means it will always be selected as the charge port, if any charge supplier is available. BUG=chrome-os-partner:32003 TEST=Attach PD charger and BC1.2 charger. Verify that active charge port switches to BC1.2 after running `chargeoverride [port]` from console. Also, pass unit tests. BRANCH=Samus Change-Id: Ia1b48ca89641842d51be7eed3b92d36d3eedc9ef Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/227730 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* usb_pd: Negotiate minimum power for unused portsShawn Nematbakhsh2014-11-131-0/+7
| | | | | | | | | | | | | | | | | | | | When a PD charger is detected, gets its max charge capability, but initially negotiate for its minimum charge mode. If we later determine that the port will be the one active charge port, re-negotiate for the max charge capability. BUG=chrome-os-partner:32003 TEST=Manual on Samus. Plug in Zinger, verify that current limit is initially set to 500 mA, then switches to 3000 mA shortly after. Plug in two Zingers, verify that one provides 3000 mA current while the other negotiates to 500 mA. Verify that the 500 mA charger bumps up to a high current once becoming active. BRANCH=Samus Change-Id: Ifa562b72d763642fc8bd62bc7f5aaa4eda1ef950 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/225922 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* charge_manager: Move supplier list and priority hierarchy to boardShawn Nematbakhsh2014-10-261-11/+3
| | | | | | | | | | | | | | | | Allow the list of charge suppliers and port selection priority to be specified at the board level. BUG=chrome-os-partner:32650 TEST=Manual on samus_pd. Plug + unplug PD and BC1.2 chargers, verify that PD is always preferred and higher power port / supplier is always selected. BRANCH=Samus Change-Id: Ic867a40120c809111bf76bf290ed6f204eab1168 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/225292 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* charge_manager: Add module for managing battery charge limitsShawn Nematbakhsh2014-10-151-0/+38
charge_manager is intended to manage charge limits from various tasks (typically PD charge tasks and USB / BC 1.2 charge tasks). These tasks can update the charge limit of a port by calling charge_manager_update (thread-safe function). If the charge limit has changed, charge_manager_refresh will be queued as a deferred task, which will select the "best" charge port and set the proper charge limit. In order to use charge_manager, a board needs to do the following: 1. Declare PD_PORT_COUNT in usb_pd_config.h 2. Implement board_set_charge_limit 3. Implement board_set_active_charge_port 4. Call charge_manager_update whenever the available charge on a port changes. BUG=chrome-os-partner:31361 TEST=Manual on samus_pd, with subsequent commit. Insert and remove various chargers, check console to verify PD charger always has priority and correct current limit is set based upon 'best' charger. BRANCH=samus Change-Id: Iede120b69e0b46ed329bcf9b7e07c39ba5e9f77b Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/222723 Reviewed-by: Alec Berg <alecaberg@chromium.org>