summaryrefslogtreecommitdiff
path: root/driver/charger
Commit message (Collapse)AuthorAgeFilesLines
* charger/rt946x: add Richtek rt946x charger driverPhilip Chen2017-07-132-0/+955
| | | | | | | | | | | | | | | | | BUG=chromium:736821 BRANCH=none TEST= 1) add RT9467 config to Scarlet and build the code 2) hook up rt9467 eval board with dummy load 3) verify the i2c traffic: set voltage, set current, and get device id Change-Id: Ie0dc2650711465b89eb4a5fbf69a326d6277b583 Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/565055 Commit-Ready: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* BD9995X: Disable input current limiting for VBAT < VSYSREG_SETVijay Hiremath2017-06-032-1/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The initial value for input current limit is set to CONFIG_CHARGER_INPUT_CURRENT which is typically 512 mA. In deeply discharged battery cases (Vbat < 5.8V), the 512 mA input current limit can cause VSYS to collapse which in turn causes the EC to reset. Depending on how discharged the battery is, the EC may remain off until the external charger is disconnected and reconnected again, or it may undergo a number of reset cycles, each time charging the battery just a little, until Vbat becomes > ~5.8V and the charger is able to stabilize. When the charger type is determined, either from BCD detection, or Type C/USB PD, the input current limit is set to the appropriate level. In order to avoid the issue described above, this CL sets a bit in the VIN_CTRL_SET register which will disable the input current limit in cases Where the VBAT is less than the VSYSREG_SET value. BUG=b:35648317 BRANCH=none TEST=Manually tested on Electro. a. With Zinger attached DUT boots without the battery after plugging in AC b. DUT boots from cut-off battery c. With Zinger attached DUT boots from cold-reset without the battery d. With no battery & DCP charger, anti-collapse occurs, input current is limited to 512mA & the DUT is power-up inhibited. Tested also on Eve with signal wires attached to both PPVAR_VSYS, PP3300_DSW, and Vbat. Verified that on certain boards (some board to board variation) that PPVAT_VSYS would collapse when the input current limit was set to CONFIG_CHARGER_INPUT_CURRENT. Then after adding this CL, verifed on the scope that the collapse of PPVAR_VSYS no longer occurred. Change-Id: Ief9960550f988e69ab4637db85450e91c70d3b51 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/456049 Commit-Ready: Vijay Hiremath <vijay.p.hiremath@intel.corp-partner.google.com> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Vijay Hiremath <vijay.p.hiremath@intel.corp-partner.google.com>
* bd9995x: BD9995X_PMON_IOUT_ADC_READ_COUNT is a power of twoDino Li2017-05-091-1/+1
| | | | | | | | | | | | | | | | With the change, compiler won't use 64-bit division for bd9995x_psys_charger_adc() function. BRANCH=none BUG=none TEST=To replace "reg" variable and checking the return value if it is expected for both "bd9995x_psys_charger_adc()" and "bd9995x_amon_bmon_chg_adc()" functions. Change-Id: Ifc461e5a54ce583ff59281ad13421c640ec9e21e Signed-off-by: Dino Li <Dino.Li@ite.com.tw> Reviewed-on: https://chromium-review.googlesource.com/485083 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* driver: bd9995x: Modify USB_CHG task so interrupts can be handledScott Collyer2017-05-031-35/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The function bc12_detect was using a msleep(312) to allow for enough time for the bd9995 to determine the charger type. Putting the USB_CHG task to sleep for this period of time means that the USB_CHG task is not able to process interrupts from the bd9995 during that time. This is a particular problem when Try.SRC is enabled and a charger is connected. VBUS will only remain present for ~40-50 msec, and when it goes away, the discharge circuit should be engaged. However, the USB_CHG task is still in the 312 mSec sleep from when VBUS was detected. The result is that discharge circuit is not engaged. It was observed that processing of charger interrupts could be delayed upwards of 500 msec. On Eve with the EVT charger, VBUS was not discharging without the discharge circuit being enabled. This resulted in excessive connect time as the Try.SRC cycle repeated many times until a case where the discharge circuit was not disabled when VBUS detect occurred and this finally allowed the charger to attach. This CL modifies the USB_CHG task main loop so that a wait timer is used when bc12_type needs to be read from the charger. There is a wait timer mark per port. If the mark value is 0, then a wait timer is not required and the task is put to sleep with -1. Each time the task is woken, either from the interrupt or wait event timer, the current time is checked against the timer mark for each port. The function that reads the bc12_type will return a 1 if the type is still not available and will return 0 if either VBUS is no longer present, or the bc12_type was successfully determined. With this change in place the discharge circuit is reliably enabled/disabled within ~5-10 mSec of VBUS changes. BUG=b:37292010 BRANCH=reef,gru TEST=Manual Added signal probe wires to VBUS, discharge control, and charger interrupt signals. Connected eve EVT charger and verified that the discharge circuit is consitently enabled when VBUS is removed following the initial attach in Try.SRC. Verifed that the EVT charger always connects on the first attempt. Also tested with various different chargers on both Eve and Reef platforms. In addition, temporarily changed the initial deferred time to 100 mSec and validated the path where vbus_provided is not true and that additional deferred calls were initiated until bc12_type is valid. Change-Id: Idd066b5461ec4cbb77bb023519fed90c9e9f71db Signed-off-by: Scott Collyer <scollyer@google.com> Reviewed-on: https://chromium-review.googlesource.com/487028 Commit-Ready: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* BD9995X: Enable/Disable charger depending on charging currentJames Chao2017-04-301-19/+39
| | | | | | | | | | | | | | | | | | | | | | If charging current is set to 0mA during charging, reference of charge current feedback amp (VREF_CHG) is set to 0V. Hence the DCDC stops switching (because of the EA offset). To eliminate this issue, disable/enable charger depending on the charging current is zero or non-zero respectively. BUG=b:37413065 BRANCH=reef TEST=test 'ectool chargecontrol normal/idle/discharge' are working Change-Id: Id31876afe365a476fb906e059ab519b7a0c9a7c6 Signed-off-by: james_chao <james_chao@asus.com> Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/486101 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> (cherry picked from commit 6da9ed8786e90ee91b39934180fe84e01ac30260) Reviewed-on: https://chromium-review.googlesource.com/489812 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
* bd9995x: Disable IADPDaisuke Nojiri2017-03-231-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch disables IADP immediately after the EC boots. We observed noise on IADP/RESET pin causing SEL_ILIM_VAL to randomly change. This seems the cause of b:35648317. We enabled IADP to fix b:35647661 initially and also followed the vendor's recommendation. However, the issue is only reproducible on the particular board which was used for power measurement and we did not see the issue on other boards with IADP disabled. Also the vendor assumed our EC doesn't control IBUS_LIM_SET and ICC_LIM_SET. (I think they assumed like other thier customers our EC controls ILIM by DAC connected to IADP/RESET pin.) If ILIM is not set by EC and IADP is disabled, the system would brownout because ILIM stays at 128mA. Therefore, it was (mistakenly) recommended that our EC should keep IADP enabled. Cros EC configures IBUS_LIM_SET and ICC_LIM_SET dynamically thus the above concern does not apply. We also found that we have too much noise on IADP/RESET pin. The noise is not big enough to cause the chip to reset but it's big enough to cause ILIM to fall in 128mA zone. We think this is why the boards fail to boot from battery cutoff or no battery. (Contrary to the vendor's explanation, it seems IADP/RESET pin continusouly affects ILIM not only in the early chip power-up period.) BUG=b:35648317 BRANCH=none TEST=Booted two Electro and two Snappy from 1) dead battery 2) no battery 3) battery cutoff. Change-Id: Ic675f1354b9ef222ceec8ce112b19713812d2752 Reviewed-on: https://chromium-review.googlesource.com/458676 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
* BD9995X: Do not overwrite the charging current in idle modeVijay Hiremath2017-03-161-1/+3
| | | | | | | | | | | | | | | | | | | If the charging current is less than the BD9995X's minimum charging current it is overwritten to BD9995X's minimum charging current. However in idle mode we write the charging current which is known to the charger during that time, which can be less than the BD9995X's charging current. Hence, do not overwrite the charging current in idle mode. BUG=b:35984679 BRANCH=none TEST=Manually tested on Electro. In idle mode charge current is 0mA. Change-Id: I2e605b63c8519383c6a62d76718bc52660e7270e Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/453999 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>
* bd9995x: Do not set IADP monitoring enable bitDaisuke Nojiri2017-03-131-8/+0
| | | | | | | | | | | | | | | | | | IADP monitoring bit was set to the default value for the devices with an RO image which clears the bit (and causes the issue). This patch removes the code so that we do not touch the IADP monitoring bit since transitioning from 0->1 may cause other issues. BUG=b:35647661 BRANCH=reef TEST=none Change-Id: I4413e0bd2de3f4e3912cbe6e73b8cad641ee9245 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/453400 Reviewed-by: Shawn N <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/453798
* charge_ramp: Specify port number in board_is_vbus_too_low()Shawn Nematbakhsh2017-02-022-13/+10
| | | | | | | | | | | | | | | | | | | charge_ramp needs to make a decision based upon the VBUS level on one specific port - the port that is ramping. The VBUS level on any other charge ports (if present) is not relevant. BUG=chrome-os-partner:54099 BRANCH=reef, gru TEST=With subsequent patches, verify charge_ramp success with a variety of BC1.2 chargers. Change-Id: Ie0a51a577e2b7491222560cd08dd5321ff3b7975 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/435561 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Shawn N <shawnn@chromium.org>
* BD9995X: Set VSYSREG_SET register as per Charger State MachineVijay Hiremath2017-02-012-54/+85
| | | | | | | | | | | | | | | | | | | | | | | Setting the VSYSREG_SET register as per Charge State Machine of the BD9995X datasheet. 1. Set VSYSREG_SET <= VBAT so that the charger is in Fast-Charge state when charging. 2. Set VSYSREG_SET > VBAT so that the charger is in Pre-Charge state when not charging or discharging. BUG=chrome-os-partner:55220 BRANCH=none TEST=Manually tested on Reef. Observed 'Charger State Machine Status' register value when charging it is in Fast-Charge state and when not charging/discharging it is in Pre-Charge state. Change-Id: I5cd5afa92384acb4fd9d69128a2a03ae6992dc5b Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/430880 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> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* bd9995x: more delay time between chg_en and vsys_setWonjoon Lee2017-01-281-11/+23
| | | | | | | | | | | | | | | | | | | | The nvdc voltage has a kind of deep, so that rarely observed NVDC down at this point because of back-boosting. Our sequence to enable charger bit and setting vsysreg is correct but rohm introduce charger may need some more time to be stable when between chg_en and vsys_set to start charge BUG=chrome-os-partner:60380 BRANCH=gru TEST=Manual on kevin, trigger battery disconnect, re-attach AC, verify system boots cleanly. and see voltage probing on c54@60380 Change-Id: Ic05091379322ffaac16fe827a47345c76c85f3e5 Signed-off-by: Wonjoon Lee <woojoo.lee@samsung.com> Reviewed-on: https://chromium-review.googlesource.com/434252 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* Reef: Reduce max battery charge voltage for 0.5% marginDaisuke Nojiri2017-01-251-4/+7
| | | | | | | | | | | | | | | | | | (From CL 431233) Limit battery charge voltage to prevent battery over-charge, due to regulation inaccuracy. Since RO FW may charge > 8656 mV, ensure the battery is not full before charging. BUG=chrome-os-partner:61906 BRANCH=none TEST=Manual on Electro, sysjump with battery @ 99%, verify battery discharges, then re-charges to 100%, before discharging once again. Change-Id: I28212c83057a442fd75e39f8ad51927a7a1f2817 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/432857 Reviewed-by: Aaron Durbin <adurbin@chromium.org>
* isl9238: Add support for battery discharging BMON current monitorNicolas Boichat2017-01-242-32/+81
| | | | | | | | | | | | | | | | | | | | ISL9238 is able to measure currents when battery is discharging (like ISL9237), and charging (new feature). Reverse AMON (OTG output current) is also supported by ISL9238, but isn't very interesting on our boards. BRANCH=none BUG=chrome-os-partner:61166 TEST=Plug charger, "amon" in EC console, check that values match current meter + "battery" information. Unplug charger, values match "battery" information. Change-Id: I9ecae6bec9e2049d17ef1a4596dbd4e3ff59919e Reviewed-on: https://chromium-review.googlesource.com/430474 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* charger: isl923x: Add support for ISL9238Nicolas Boichat2017-01-053-299/+327
| | | | | | | | | | | | | | | ISL9237 and ISL9238 are almost identical, with few register changes, let's make the driver generic, to support both chargers. BRANCH=none BUG=chrome-os-partner:61166 TEST=make buildall -j Change-Id: I029894dd62ab7e45897d877289707ee8c1ff1d09 Reviewed-on: https://chromium-review.googlesource.com/422197 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
* BD9995X: Disable input current limitation for all types of chargersVijay Hiremath2016-12-082-2/+9
| | | | | | | | | | | | | | | | | | | | Charger Operation Control Setting 1 (CHGOP_SET1) has separate bits to disable input current limitation for DCP, SDP, others. If it is not disabled, input current is automatically selected, which results in hard resets on weak chargers hence disable the input current limitation for all types of chargers. BUG=chrome-os-partner:60722 BRANCH=none TEST=Tested on Reef. Input current is not automatically set to all types of chargers. Change-Id: Ideb16ac2a40b403c94c28e85f254043ead7415e0 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/417234 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>
* reef: BD9995X: Suspend DC-DC converter when discharging on ACVijay Hiremath2016-11-281-2/+10
| | | | | | | | | | | | | | | | | | When the battery is fully charged or not charging, upon removal of the AC, discharge takes long time. To overcome this issue suspend the DC-DC converter when discharging on AC. BUG=chrome-os-partner:58969 BRANCH=none TEST=Manually tested on reef. Discharge is in the permissible range. 'chgstate' console command prints correct values. Change-Id: I64afa992e50b6e18daf43edf237fde8cf658a8a2 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/413153 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>
* BD9995X/reef/snappy/pyro: Boot from the shipmode batteryVijay Hiremath2016-11-182-0/+23
| | | | | | | | | | | | | | | | | | | | | Charger BGATE is off on POR hence the voltage to the battery pack is not applied immediately from the VBUS. To overcome this issue, BGATE is turned on (CHG_EN) at charger initialization. If the voltage across VBATT is high but I2C is still failing, battery is booting from ship mode hence overwrite the battery as not present till I2C on battery is success and INIT bit is set. BUG=chrome-os-partner:59308 BRANCH=none TEST=Reef can boot to OS from shipmode battery. Change-Id: If1b212612e27fd65a822675a9609f0a8c03d8add Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Signed-off-by: Divya Sasidharan <divya.s.sasidharan@intel.com> Reviewed-on: https://chromium-review.googlesource.com/411360 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>
* Fix various misspellings in commentsMartin Roth2016-11-153-3/+3
| | | | | | | | | | | | | No functional changes. BUG=none BRANCH=none TEST=make buildall passes Change-Id: Ie852feb8e3951975d99dce5a49c17f5f0e8bc791 Signed-off-by: Martin Roth <martinroth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/403417 Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
* bd9995x: Battery charging profile settingsVijay Hiremath2016-11-121-34/+69
| | | | | | | | | | | | | | | | | Added battery charging profile settings as given in the datasheet. BUG=chrome-os-partner:58553 BRANCH=none TEST=Manually verified on reef. VBAT is equal to battery voltage. Previous/current Charge status is equal to the conditions given in the datasheet. Change-Id: Ie04619a122fe52d6768c03ff5156b368e3f2d340 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/398080 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: David Hendricks <dhendrix@chromium.org>
* bd9995*: maintain VBAT voltage as battery maximumWonjoon Lee2016-11-081-1/+2
| | | | | | | | | | | | | | | | BUG=chrome-os-partner:54248 BRANCH=gru TEST=Manual on kevin, high temperature chamber(60C), battery will require 0 voltage because of high temp, then check 'chgstate' vbat maintained at 8688 mV. Change-Id: I3b5835701c42a0cd861400ba921b3d3797152bbd Signed-off-by: Wonjoon Lee <woojoo.lee@samsung.com> Reviewed-on: https://chromium-review.googlesource.com/400088 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* BD9995X: Fix disable case in bd9995x_select_input_portScott2016-11-011-1/+1
| | | | | | | | | | | | | | | | | | | | The 'else' was missing in the for the check of port == BD9995X_CHARGE_PORT_BOTH. So if it wasn't this port type then it would always hit the panic. BUG=chrome-os-partner:59189 BRANCH=none TEST=Manual Verfied the failure case using a type C to type A adapter. After applying the fix verified that it no longer panics. Change-Id: Ia5a16c39e226d5e648c20d0c8675d6433d083f22 Signed-off-by: Scott <scollyer@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/405747 Commit-Ready: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* reef: Enable BD9995X power save mode when hibernatedVijay Hiremath2016-10-282-12/+16
| | | | | | | | | | | | | | | | | | | | | Turn off the charger BGATE when the system is hibernated to save maximum power. BUG=chrome-os-partner:59001 BRANCH=none TEST=Manually verified on the Reef. System can boot from hibernate wake sources. Following are the power measurement values at Battery voltage = 8.3V & temperature = 23 deg C. a. Normal operation 540uA, 3.500mW b. BGATE OFF 80uA, 0.592mW Change-Id: Ia30655ccefbf0dded623246150d53b2a815df2de Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/404685 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>
* BD9995X: Disable input to port when sourcingVijay Hiremath2016-10-272-19/+27
| | | | | | | | | | | | | | | | | | POR has both VCC & VBUS enabled. If the port is sourcing VBUS it will also act as sync and AC_OK pin gets enabled. Hence disable the input to the port when sourcing. BUG=chrome-os-partner:59020 BRANCH=none TEST=Manually verified on Reef. Connected HoHo and AC_OK is not enabled. Change-Id: Ic51b81f45759d7dddb2c9744d1c24dbafd1e1293 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/404168 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Shawn N <shawnn@chromium.org>
* smart_battery: Remove smart charger unreachable codeVijay Hiremath2016-10-113-0/+33
| | | | | | | | | | | | | | | | Smart battery code has I2C read/write code for smart chargers which is an unreachable code for few boards hence removed it. BUG=none BRANCH=none TEST=make buildall -j Change-Id: I79933f61893c66447c686a81073c92f6a16e2d48 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/396279 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Shawn N <shawnn@chromium.org>
* charger: bd9995x: Reset map command set on failed set operationShawn Nematbakhsh2016-09-281-4/+6
| | | | | | | | | | | | | | | | | | | If BD9995X_CMD_MAP_SET fails, the charger's internal map command set may be the old set (if the charger failed to process the command) or the new set (if the EC failed to receive the response). Therefore, reset the EC's known map command state on failure, so that it will always be re-set on the next transaction. BUG=None TEST=Build + boot kevin. BRANCH=Kevin Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: Id16273ccf2e39b5aae7776d626aae8863e713df5 Reviewed-on: https://chromium-review.googlesource.com/390318 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* bd9995x: Disable fast/pre-charging watchdog timerphilipchen2016-09-261-2/+2
| | | | | | | | | | | | | BUG=chrome-os-partner:55771 BRANCH=none TEST=make -j buildall TEST=bd9995x r 0x0f 1; verify 0x00. Change-Id: Ibfca44599b8a6d631215b2c9a50e810312559f3a Reviewed-on: https://chromium-review.googlesource.com/388819 Commit-Ready: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* i2c: Add i2ctest console commandVijay Hiremath2016-09-232-0/+26
| | | | | | | | | | | | | | | | | | Added i2ctest console command to test the reliability of the I2C. By reading/writing to the known registers this tests provides the number of successful read and writes. BUG=chrome-os-partner:57487 TEST=Enabled the i2ctest config on Reef and tested the i2c read/writes. BRANCH=none Change-Id: I9e27ff96f2b85422933bc590d112a083990e2dfb Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/290427 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Shawn N <shawnn@chromium.org>
* BD9995X: Rename common code of BD99955 and BD99956 as BD9995XVijay Hiremath2016-09-213-686/+694
| | | | | | | | | | | | | | | | | | Except the CHIP_ID and charger name code is common between BD99955 and BD99956. Hence renamed the code to BD9995X so that valid output is printed from console commands. BUG=chrome-os-partner:57519 BRANCH=none TEST=Manually tested on Reef. 'charger' console command prints charger name as 'bd99956' Change-Id: I3c995757941bcc5a6a8026dd807d76a7a47c9911 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/387119 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>
* charger: bd99955: Adjust charger params at initShawn Nematbakhsh2016-09-162-5/+25
| | | | | | | | | | | | | | | | | - Use 1200KHz DCDC clock. - Set reverse current threshold to -50mV. - Set internal gain to 2x. BUG=chrome-os-partner:57118,chrome-os-partner:56255 TEST=Manual on kevin and reef, verify charging w/ zinger. BRANCH=None Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: Ib7188764206743543fb873f303acb7b62977dc3d Reviewed-on: https://chromium-review.googlesource.com/382451 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
* BD99955: Support Pull-up port non-standard BC1.2 chargersVijay Hiremath2016-09-162-16/+23
| | | | | | | | | | | | | | | | | | | | Some chargers with valid VBUS advertise as Pull-up ports. Hence, added code to support these kind of chargers as non-standard BC1.2 chargers. BUG=chrome-os-partner:57163 BRANCH=none TEST=Manually tested on reef. Used a Pull-up port non-standard BC1.2 charger and observed it can ramp to its maximum current ratings. Change-Id: I33c4c3a64e9c7176c909a48f6fbc49e04d529541 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/385239 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Rachel Nancollas <rachelsn@google.com> Reviewed-by: Shawn N <shawnn@chromium.org>
* bd99955: enable power-save mode only when we have no USB dataVincent Palatin2016-09-151-0/+11
| | | | | | | | | | | | | | | | | | | | | | | When we source VBUS, the BD99955 does not disable its power saving mode and messes up our USB2.0 data connection (DP/DN). Let's disable the BD99955 power-save mode whenever a USB data connection is present on one of the ports. For configurations without power saving enabled, let's still write the power-save mode register to ensure it is in the proper (disabled) state whatever happened before (bad RW ...) Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=gru BUG=chrome-os-partner:57310 TEST=On Kevin, connect a USB-Ethernet dongle and see it enumerating properly (while BD99955 power-save mode is enabled). Change-Id: I379f94ecd294f045f353bd50eafd2035636837b1 Reviewed-on: https://chromium-review.googlesource.com/384851 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* tcpc: Enable vbus discharge using PD discharge registersKevin K Wong2016-09-131-2/+2
| | | | | | | | | | | | | | | BUG=chrome-os-partner:56040 BRANCH=none TEST=Manually tested on Reef. Used scope to monitor VBUS & it dropped to 0.8V within 650ms. Change-Id: Icaea1dc11a7342a5cc1493d6d3c2ec3408d6d37b Signed-off-by: Kevin K Wong <kevin.k.wong@intel.com> Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/367482 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>
* charger: bd99955: Enable VBUS discharge when appropriateShawn Nematbakhsh2016-09-132-6/+53
| | | | | | | | | | | | | | | | | | | Use a custom VBUS threshold of 3.9V for enable / disable of our VBUS discharge circuit. BUG=chrome-os-partner:55584 BRANCH=None TEST=Plug Apple charge-thru accessory into kevin, plug zinger into accessory, verify charging occurs at PD-negotiated current / voltage. Change-Id: I25f6f68cfe55e8bae2071cda39618b2bfadcb355 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/379475 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* bd99955: Add support for power save mode.Aseda Aboagye2016-09-092-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The BD99956 charger has a power save mode that it can enter once VBUS or VCC is removed. This commit adds an optional config option that can be used to select the power save mode: CONFIG_BD99955_POWER_SAVE_MODE By default, no power save mode will be enabled. However, a board can device what level of power savings they wish to use. The levels are the following: BD99955_PWR_SAVE_LOW /* BGATE ON w/ PROCHOT# monitored only system * voltage. */ BD99955_PWR_SAVE_MED /* BGATE ON w/ PROCHOT# monitored only system * voltage every 1ms. */ BD99955_PWR_SAVE_HIGH /* BGATE ON w/o PROCHOT# monitoring. */ BD99955_PWR_SAVE_MAX /* BGATE OFF */ BUG=chrome-os-partner:55631 BRANCH=kevin TEST=make -j buildall Change-Id: Ibab7ad30d5f1ae9917b46b40d6f2800ef19e52dd Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/382877 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* Driver: BD99955: Enable trickle chargingVijay Hiremath2016-09-062-12/+20
| | | | | | | | | | | | | | | | | | | | | | | Enabled the trickle charging mode by setting the VPRECHG_TH_SET register[0x18H] to board specific battery voltage minimum value. When the battery voltage drops below the battery voltage minimum value, trickle charging is enabled. BUG=chrome-os-partner:56684 BRANCH=none TEST=Manually verified on Reef. Drained the battery below battery voltage minimum value. On plugging in the charger, State Machine Status register CHGSTM_STATUS [0x00h] is 0x01 which indicates, current state of the charger state-machine is in Trickle-Charge condition. Change-Id: Ic4b985c71ff68ea4f5ab22e18feab03d776ec134 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/376939 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* bd99955: usb_charger: Don't do BC1.2 detection on source portsShawn Nematbakhsh2016-09-051-3/+4
| | | | | | | | | | | | | | | | | | | | | If we're sourcing 5V to the port, consider the port as not providing power, for the purpose of VBUS / BC1.2 detection. BUG=chrome-os-partner:55432 BRANCH=None TEST=Manual on kevin, attach legacy peripheral in one port, zinger in the other, run "reboot" on EC console, and verify zinger port is selected as charge port. Also attach Apple charge-thru accessory w/o charger plugged, verify that charge manager is not informed of a BC1.2 / VBUS supplier. Change-Id: Ifbe587215f28756760e7106e1a00dd96319438e3 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/380324 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Amenia/Reef: Add software charge ramp for BC1.2 & nonstandard BC1.2Vijay Hiremath2016-08-292-25/+34
| | | | | | | | | | | | | | | | | | | | | | Setting the higher limit of input current for BC1.2 & nonstandard BC1.2 devices than their maximum current rating results in an anti-collapse. BD99955 does not have a way to do hardware charge ramp or to detect the anti-collapse for these chargers. Hence added code to support software charge ramp for BC1.2 & nonstandard BC1.2 so that the input current is set to maximum of the respective charger. BUG=chrome-os-partner:54990, chrome-os-partner:55517 BRANCH=none TEST=Manually tested on Amenia & Reef. BC1.2 & nonstandard BC12 devices can negotiate their respective maximum current rating. Change-Id: I0033b3662362bd7822ad01cf4360d18caabd5249 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/358106 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>
* charger: Send host event after charge info is updated.Sam Hurst2016-08-241-6/+0
| | | | | | | | | | | | | | | | When the charger is detached, the host event would sometimes be sent before the charge info was updated, resulting in the host thinking that the charger was still connected. BUG=chrome-os-partner:55584 BRANCH=none TEST=Connected charger to kevin 15 times and verified that the icon was removed in 2-seconds or less. Change-Id: I1a4e4e0f7cc23010210570fc261da8308d8e8070 Reviewed-on: https://chromium-review.googlesource.com/367809 Commit-Ready: Wonjoon Lee <woojoo.lee@samsung.com> Tested-by: Sam Hurst <shurst@google.com> Reviewed-by: Shawn N <shawnn@chromium.org>
* cleanup: DECLARE_CONSOLE_COMMAND only needs 4 argsBill Richardson2016-08-244-14/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* charger/bd99955: only print data if read was successfulMartin Roth2016-08-231-1/+2
| | | | | | | | | | | | | | | In console_command_bd99955(), because the return value wasn't being checked before displaying the data variable, it could be printed without being initialized. TEST=Build BUG=None BRANCH=None Change-Id: I03e0aae6fee33e32f648d952d6f2906e71f67ea2 Signed-off-by: Martin Roth <martinroth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/371398 Reviewed-by: David Hendricks <dhendrix@chromium.org>
* BD99955: Map PD port number to charge port numberVijay Hiremath2016-08-222-2/+12
| | | | | | | | | | | | | | | | Charger port number may differ from PD port number hence added a macro to select appropriate port numbers during compilation. BUG=chrome-os-partner:54970 BRANCH=none TEST=Reef can negotiate on both the ports. Change-Id: Id3b4b639a5f8698c27341be037bb09370910cac5 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/357836 Commit-Ready: Martin Roth <martinroth@chromium.org> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Shawn N <shawnn@chromium.org>
* charger: bd99955: Prevent truncated console command outputShawn Nematbakhsh2016-08-221-1/+3
| | | | | | | | | | | | | | | | | "bd99955_dump" output may be larger than our UART output buffer, so flush our buffer in between prints. BUG=None TEST=Run 'bd99955_dump' on kevin, verify full output is seen. BRANCH=None Change-Id: I5816e0ce0c000bf63bc09502888e5acc9c4728ae Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/373660 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* charger/bd99955.c: Simplify flow in console_command_bd99955Martin Roth2016-08-121-5/+3
| | | | | | | | | | | | | | | | It looks to static analyzers as if the variable val could be used without being initialized. That isn't actually the case because of all the checks that are being done, but the flow can be simplified to only get the value to write when we're on the write path. BRANCH=None TEST=Build and boot Reef BUG=None Change-Id: I9f6ce3c9dcbab74f3c6de18dbd1f2e07bc1c4a13 Signed-off-by: Martin Roth <martinroth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/368302 Reviewed-by: David Hendricks <dhendrix@chromium.org>
* reef: Add code to read battery temperatureVijay Hiremath2016-08-032-2/+4
| | | | | | | | | | | | | | | | | | Reef doesn't have the battery temperature sense pin connected to the charger, hence reading the battery temperature from the battery registers. BUG=chrome-os-partner:55834 BRANCH=none TEST=Using 'battery' & 'temps' console command verified, temperature readings are same from both the commands. Change-Id: I897e453296151f31344f3e0434202baa67c7025d Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/365970 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: David Hendricks <dhendrix@chromium.org>
* Revert "charger: bd99955: Adjust VSYS based on fast vs precharge state"Shawn Nematbakhsh2016-07-292-109/+10
| | | | | | | | | | | | | | | | This reverts commit 7369f0a68912dbd749271b79606c569071db0a13. Keep VSYS constant throughout precharge / fastcharge. BUG=chrome-os-partner:55524 BRANCH=None TEST=Build only. Change-Id: I35cda81b42833af2c860f35dd492ecb4f1e49025 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/364625 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* charger: bd99955: Remove incorrect VSYSVAL_THL / THH settingsShawn Nematbakhsh2016-07-251-7/+1
| | | | | | | | | | | | | | | | | | | VSYSVAL_THL / THH are high / low hysteresis values below which dead battery condition is triggered, which doesn't match our register configuration. Leave these regs at default for now until we better understand the effect of dead battery detection. BUG=chrome-os-partner:55626 BRANCH=None TEST=Manual on kevin with other pending changes, verify dead battery successfully charges. Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I35a44dd0005f165f17073e8b0f2fd5dca1eda856 Reviewed-on: https://chromium-review.googlesource.com/363030 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* charger: bd99955: Adjust VSYS based on fast vs precharge stateShawn Nematbakhsh2016-07-252-10/+109
| | | | | | | | | | | | | | | | | | | | | Rohm suggests setting VSYS to the higher value during precharge and only setting it to the lower voltage after we have crossed the lower voltage. Note that the VSYS register also controls the pre vs fastcharge threshold, so setting VSYS to the lower voltage essentially enables fastcharge. BUG=chrome-os-partner:55524 BRANCH=None TEST=Manual on kevin, verify dead battery is able to charge through precharge to fastcharge. Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: Ia5b953c8dfbb25970ab329d5487a317ad37ba609 Reviewed-on: https://chromium-review.googlesource.com/362442 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: David Schneider <dnschneid@chromium.org> Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* bd99955: Add function for reading temperatureDavid Hendricks2016-07-222-0/+16
| | | | | | | | | | | BUG=chrome-os-partner:54818 BRANCH=none TEST=needs testing Change-Id: I3a33f79e7d57e6f94731a7d929dbcd083e0f1ca1 Signed-off-by: David Hendricks <dhendrix@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/360721 Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
* charger: bd99955: Set pre-charge current in addition to fast chargeShawn Nematbakhsh2016-07-202-2/+13
| | | | | | | | | | | | | | | | | | | | | Pre-charge vs fast-charge mode depends on battery voltage relative to VSYS. Rather than checking battery voltage (which may change), set pre-charge and fast-charge currents whenever charger_set_current() is called. BUG=chrome-os-partner:55416 BRANCH=None TEST=Manual on kevin. Verify system continues to boot with no battery. Attach depleted battery, run "battery" and verify charger current is ~200 mA. Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I68c06108c6d85ceede396294bedd1a017ddddd52 Reviewed-on: https://chromium-review.googlesource.com/361993 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* charger: bd99955: Allow charge limits < 512 mAShawn Nematbakhsh2016-07-202-2/+8
| | | | | | | | | | | | | | | | | | | | During pre-charge, batteries may request < 512 mA. Allow battery charging at this low current, and only apply the 512 mA floor when no battery is present. BUG=chrome-os-partner:54821 BRANCH=None TEST=Manual on kevin. Verify system continues to boot with no battery. Attach depleted battery, run "battery" and verify charger current is ~200 mA. Change-Id: Ia10e732a6b21587917ffa5e34035507f5be74dd3 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/361589 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>