summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* chgstv2: Always discharge if soc is > sustainer_soc.upperfirmware-atlas-11827.BDerek Basehore2023-05-112-7/+12
| | | | | | | | | | | | | | | | | For the Charge Limit feature, we need to discharge down to the upper limit for the battery sustainer. The Charge Limit feature requires that the system never charge above 80%, so if the feature is enabled when the system is over that, it needs to discharge down to 80%. BUG=b:222619859 TEST=run-sbs_charging_v2 Change-Id: I3f65743144de64411484dd3f2aa6c5fd681a47c9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4507759 Tested-by: Derek Basehore <dbasehore@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Derek Basehore <dbasehore@chromium.org> Auto-Submit: Derek Basehore <dbasehore@chromium.org>
* chgstv2: rework "charge_command_charge_control()"Tommy Chung2022-04-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | Condition of judging whether to enable or disable the battery sustainer should be the mode host commands give, not the current chg_ctl_mode. BUG=b:194219157, b:222620437 BRANCH=none TEST=make sure that the battery sustainer will not be incorrectly enabled when giving "ectool chargecontrol discharge" or "ectool chargecontrol idle" under CHARGE_CONTROL_NORMAL mode. Signed-off-by: Tommy Chung <tommy.chung@quanta.corp-partner.google.com> Change-Id: I8a28970164a7e80805601817f2761d6684b183cf Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3070328 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> (cherry picked from commit f60c312dcf183fdaef40d9a32f092193f8ec89db) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3573691 Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Zhuohao Lee <zhuohao@chromium.org> Commit-Queue: Zhuohao Lee <zhuohao@chromium.org>
* battery: Set EC_BATT_FLAG_INVALID_DATA correctlyDaisuke Nojiri2022-03-181-2/+2
| | | | | | | | | | | | | | | | | | | | | | | There is a typo in the logic where EC_BATT_FLAG_INVALID_DATA is set. Because of this, currently, EC_BATT_FLAG_INVALID_DATA is reported to the host only if BATT_FLAG_BAD_CURRENT is set. BATT_FLAG_BAD_CURRENT happens to be 0x20 which is equal to EC_BATT_FLAG_INVALID_DATA. (This originates from I3c428c850020a29b3f452504b60b52946a04c503.) This patch corrects the logic by changing EC_BATT_FLAG_INVALID_DATA to BATT_FLAG_BAD_ANY. BUG=b:65697962,b:65697620 BRANCH=None TEST=None Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I7504932f078ce797daf8e5c017b7835c90220a99 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3516912 Reviewed-by: caveh jalali <caveh@chromium.org> (cherry picked from commit 550f6384d82a563d85248d8a740931257b11250c) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3533722 Commit-Queue: caveh jalali <caveh@chromium.org>
* battery/smart: Don't update fields if reading failsDaisuke Nojiri2022-03-171-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | Currently, battery_get_params starts with batt_new = {0} and ends with memcpy(batt, batt_new). That is, if battery_get_params fails to read a field, we set a BATT_FLAG_BAD_* and clear the field. This behavior forces us to check the flags everywhere fields are read (to distinguish 0 v.s. invalid 0). It also makes EC forget the last known good values. Instead, we will always keep good values in the global batt_params. That is, we update fields only if reads are successful. (That's how other implementations of battery_get_params behave.) Thus, if display_soc is zero, it was computed legitimately as zero (except the very initial value). BUG=b:217401040,b:222722611 BRANCH=None TEST=Guybrush Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I5b69b708d149d1c750551d8cf957eab3fdc8aa64 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3518079 Reviewed-by: caveh jalali <caveh@chromium.org>
* Revert "battery: Do not return display_soc if data is bad"Daisuke Nojiri2022-03-162-18/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 6362dde219dd00f7fc5adcc3457f1d90cfc6c5a4. Reason for revert: Will be fixed by https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3514489, which doesn't have a side effect. Original change's description: > battery: Do not return display_soc if data is bad > > If BATT_FLAG_BAD_FULL_CAPACITY or BATT_FLAG_BAD_REMAINING_CAPACITY > flags are set, then display_charge value is also bad. > Return UNAVALIABLE error rather than 0%. > > BUG=b:217401040 > BRANCH=guybrush > TEST=Force battery glitch, do not observe 0% battery in OS > > Change-Id: Iea861582dde1f7db3d6a4c40e88169d7f74ca159 > Signed-off-by: Rob Barnes <robbarnes@google.com> > Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3496464 > Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> > Reviewed-by: Diana Z <dzigterman@chromium.org> > (cherry picked from commit b135e45447ba42f276b6f5232e2573d166320b31) > Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3514623 > Tested-by: Daisuke Nojiri <dnojiri@chromium.org> > Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org> > Reviewed-by: caveh jalali <caveh@chromium.org> > Commit-Queue: caveh jalali <caveh@chromium.org> Bug: b:217401040 Change-Id: I32d91fb223c796da9af2979d3ce1ff42ce7b2213 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3515274 Reviewed-by: Rob Barnes <robbarnes@google.com> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org>
* battery: Do not return display_soc if data is badRob Barnes2022-03-102-0/+18
| | | | | | | | | | | | | | | | | | | | | | If BATT_FLAG_BAD_FULL_CAPACITY or BATT_FLAG_BAD_REMAINING_CAPACITY flags are set, then display_charge value is also bad. Return UNAVALIABLE error rather than 0%. BUG=b:217401040 BRANCH=guybrush TEST=Force battery glitch, do not observe 0% battery in OS Change-Id: Iea861582dde1f7db3d6a4c40e88169d7f74ca159 Signed-off-by: Rob Barnes <robbarnes@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3496464 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> (cherry picked from commit b135e45447ba42f276b6f5232e2573d166320b31) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3514623 Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: caveh jalali <caveh@chromium.org> Commit-Queue: caveh jalali <caveh@chromium.org>
* battery: Set host's low battery shutdown SoC to 4%Daisuke Nojiri2021-12-151-4/+4
| | | | | | | | | | | | | | | | Currently, the host's low battery shutdown SoC is 3% by default but most boards are configured to 4%. This patch changes the default value to 4% so that we require only minority boards to customize it. BUG=b:191837893, b:189737806 BRANCH=None TEST=Storo using battfake EC command. Change-Id: I69ed5d8cc8c0d1e321d79c5eae26a9c21624a4ea Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2998509 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3340215
* Battery: Apply fake SoC to display chargeDaisuke Nojiri2021-12-152-6/+7
| | | | | | | | | | | | | | | | | This patch makes the battfake command apply the fake SoC to the display SoC as well as the raw battery SoC. This patch also cleans up battery_compensate_params. BUG=None BRANCH=None TEST=Atlas Change-Id: Ifbdaa81204d27501df8a4f5e025c19a79d62feff Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2994748 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3340214
* Battery: Apply faked state of charge to remaining capacityDaisuke Nojiri2021-12-151-6/+22
| | | | | | | | | | | | | | | | | | Currently, only the state of charge is modified by battfake command. This patch applies the faked state of charge to the remaining capacity as well. BUG=b:163721887 BRANCH=Octopus TEST=Verified Fleex wakes up host on BATTERY_LEVEL_CRITICAL. TEST=Verified powerd reports faked state of charge. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I34eb409bab129804a983abbe2a1d021298ce044e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2432865 Reviewed-by: Todd Broch <tbroch@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3340213 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* battery: Set host's low battery shutdown SoC to 3%Daisuke Nojiri2021-12-152-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | Currently, the host's low battery shutdown SoC is 2%. This is the same as EC's low battery shutdown threshold. The EC waits for 30 secs before it triggers the low battery shutdown and powerd reads the SoC every 30 secs. Thus, in most cases powerd can shut down the system gracefully but these delays can be configured differently and the system may be too busy to process all shutdown tasks within 30 secs. This patch increases the host's shutdown SoC to 3%. This will further guarantee that powerd will be given enough time to do everything for a proper shutdown. It also avoids deeply discharging the battery, which is bad for the battery health. BUG=b:191837893 BRANCH=None TEST=Altas using battfake EC command. Change-Id: I3ab23205b400a1a326a60b8f9501611c027183b2 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2994747 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3336672
* chgstv2: Unify power-on and shutdown battery thresholdsDaisuke Nojiri2021-12-1532-69/+2836
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, power-on battery SoC and shutdown battery SoC are independently configured by each board. This patch will unify the setting as follows: CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON = 2 (don't boot if soc < 2%) CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE = 2 (shutdown if soc <= 2%) BATTERY_LEVEL_SHUTDOWN = 3 (shutdown if soc < 3%) CONFIG_BATTERY_EXPORT_DISPLAY_SOC = Y (removed) CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON_WITH_AC = 1 This allows us to show the low battery alert whenever we can because EC doesn't inhibit power-on even if it knows the host would immediately shut down. With CONFIG_BATTERY_EXPORT_DISPLAY_SOC, boards will start using the CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE = 2% as the low battery threshold (and the SoC will be agreed between the EC and Powerd). Boards with CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON = 1 will keep the same threshold. This is for avoiding degrading the UX by increasing the power-on threshold (even though a question that 1% may not be enough for soft sync to finish consistently remains to be answered). Boards with CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON > 2 will have a lower threshold but we think 2% is enough to finish the software sync. A lower threshold also improves the UX by showing the low battery alert in the situation where otherwise the system would leave the user uninformed by not responding to a power button press. BUG=b:191837893 BRANCH=None TEST=buildall Change-Id: If6ff733bc181f929561a3fffb8a84e760668ce37 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2981468 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3336671
* Battery: Add command to export display SoCDaisuke Nojiri2021-12-153-13/+92
| | | | | | | | | | | | | | | | | | | | | | | Currently, CrOS EC passes the battery remaining capacity (mAh) and the full capacity (mAh) through ACPI to the AP so that the host can calculate the battery SoC. The host further manipulates the SoC to get the display SoC, which is used to determine user visible behaviors. To get consistent behaviors in all power states, this change enables the EC to send the display SoC to the host via EC_CMD_DISPLAY_SOC command. The Powerd's part is I5bd1371f2569d21d55df1b50a3d709b98bbf0325. BUG=b:174433637, b:181506409, b:80270446, b:109954565 BRANCH=dedede, trogdor, nami, hatch TEST=Storo, CoachZ Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: Idc6992625d992a73be141987d02ed220508d3b74 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2853142 Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3336670
* battery: Update the default powerd's full factor valueWai-Hong Tam2021-12-151-2/+3
| | | | | | | | | | | | | | | | | | | Use the same default value as powerd, i.e. 97% instead of 94%. The value comes from: src/platform2/power_manager/default_prefs/power_supply_full_factor BRANCH=None BUG=b:162604872 TEST=Checked EC showing the same Display percentage as the UI. Change-Id: Ia8547915251ea80bc663b5f15435060acacf9021 Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2335887 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3336669 Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
* battery: Calculate the display charge percentageWai-Hong Tam2021-12-152-11/+14
| | | | | | | | | | | | | | | | | | It doesn't require the powerd's full factory to be 100%. Also refine the comment on the powerd's equation to make it more understandable. BRANCH=None BUG=b:162604872 TEST=With the follower CL which updates the powerd's full factor value, checked EC showing the same Display percentage as the UI. Change-Id: I50ae7c38c423722188d892f91f4fc93d4d5f84e1 Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2335886 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3336668 Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
* battery: Remove redundant lfcc variable when calculate compensationWai-Hong Tam2021-12-151-8/+4
| | | | | | | | | | | | | | | | | | The value of lfcc variable, which is copied from host_get_memmap(EC_MEMMAP_BATT_LFCC), is actually the compensated full capacity. Use the value of *full directly. BRANCH=None BUG=b:162604872 TEST=Checked the battery console command result. Change-Id: Iae103dd325679333c524698ce7a86cdc96a3587e Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2335885 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3336667 Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
* battery: Simplify the compensation logic by using pointersWai-Hong Tam2021-12-151-10/+8
| | | | | | | | | | | | | | | | | Simplify the logic by using pointers, instead of copying the values from and to other variables. No behavior changes. BRANCH=None BUG=b:162604872 TEST=Checked the sysfs battery info. Change-Id: I2dafd0c774354bbf563be121a8bf9d65f1d4dfd3 Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2335884 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3336666 Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
* common/battery: Avoid negative display percentagesEvan Green2021-12-151-0/+2
| | | | | | | | | | | | | | | | | | | | Battery charges less than batt_host_shutdown_pct cause the display charge to go negative. This looks silly in EC console prints: [38.474266 Battery 2% (Display -2.-7 %) / 3h:15 to full] BUG=b:134586427 BRANCH=None TEST=Run kohaku down to low battery, observe display stays at 0. Change-Id: If8eb477b8bb21451069bac5c1474b7a408b30582 Signed-off-by: Evan Green <evgreen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1650136 Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3336665 Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
* kodama: overwrite bad battery params to known good valueTing Shen2021-12-155-0/+241
| | | | | | | | | | | | | | | | | | | | | | | | | | | Kodama's bitbang driver fails randomly, and there's no way to notify kernel side that bitbang read failed (batt->flags does not propagate into kernel). Thus, if any value in batt_params is bad, replace it with a cached good value, to make sure we never send random numbers to kernel side. BUG=b:144195782 TEST=Modify smart battery driver to make sb_read has 50% fail rate, and monitor /sys/class/power_supply/sbs*/*, make sure the bad values does not observable in kernel. BRANCH=kukui Change-Id: Idf4691eb743f1ef785593b308b8f07a34e5ea642 Signed-off-by: Ting Shen <phoenixshen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1943637 Reviewed-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Ting Shen <phoenixshen@chromium.org> Tested-by: Ting Shen <phoenixshen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3336664 Reviewed-by: Eric Yilun Lin <yllin@google.com> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
* battery: Consolidate battery_manufacturer_nameDaisuke Nojiri2021-12-157-28/+23
| | | | | | | | | | | | | | | | | | | | | | | Currently, the battery_manufacturer_name API is implemented individually by each chip. This patch consolidate the definitions. It also allows a board to return custom manufacturer names. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=b/129599895 BRANCH=none TEST=buildall Change-Id: Ib0f60c9be71fea31658ab284a915d73341b9145e Reviewed-on: https://chromium-review.googlesource.com/1590039 Commit-Ready: YH Lin <yueherngl@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: YH Lin <yueherngl@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3336663 Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
* Clear OWNERS for factory/firmware branchBrian Norris2021-09-102-9/+0
| | | | | | | | | | | | BUG=none TEST=none Change-Id: I0f03f432ada1064ffba9595be78ca7ab4d25ecd1 Signed-off-by: Brian Norris <briannorris@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3155136 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Owners-Override: Jora Jacobi <jora@google.com> Tested-by: Jack Rosenthal <jrosenth@chromium.org>
* chgstv2: call sustain_battery_soc without checking previous statesTommy Chung2021-08-211-1/+4
| | | | | | | | | | | | | | | | | | | | | When we enalbe battery sustain after battery returns that it is full, we need to add this condition for sustain_battery_soc(). Also, add this test condition for battery sustainer. BUG=b:188457962 BRANCH=none TEST=make sure the battery sustain works when enabling it after battery returns that it is full. Also, make sure that "make run-sbs_charging_v2" pass. Signed-off-by: Tommy Chung <tommy.chung@quanta.corp-partner.google.com> Change-Id: If10b9fd0264717abfb7cdbb7ddc947b370291895 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3070946 Reviewed-by: Devin Lu <Devin.Lu@quantatw.com> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3105744
* chgstv2/sustainer: Stop AC current when dischargingDaisuke Nojiri2021-08-212-7/+79
| | | | | | | | | | | | | | | | | | | | Currently, the battery sustainer discharges the battery using CHARGE_CONTROL_IDLE, which uses the AC current and stops the current from the battery. With this change, when lower < upper, the sustainer discharges using DISCHARGE. When lower == upper, the sustainer discharges using IDLE. BUG=b:188457962 BRANCH=None TEST=run-sbs_charging_v2 Change-Id: I4af31eff488bc9cfa627f84994b685488c3c9061 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3049290 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Derek Basehore <dbasehore@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3105743
* chgstv2/sustainer: Add tests for full battery and ACDaisuke Nojiri2021-08-212-16/+64
| | | | | | | | | | | | | | | | | | | Currently, unit tests do not check whether the battery sustainer can be enabled when the battery is already full or when the AC is already present. This patch adds tests which check the battery sustainer can be enabled when the battery is already full or when the AC is already present. BUG=b:188457962 BRANCH=None TEST=run-sbs_charging_v2 Change-Id: I4ec9785554d126baca0b60e889c4a2dabbfb628a Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3078401 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3105742
* test: Fix sbs_charging_v2's charge_control() cmd versionEvan Green2021-08-201-1/+1
| | | | | | | | | | | | | | | | | | | | | charge_control() was sending EC_CMD_CHARGE_CONTROL version 2, but leaving params.cmd uninitialized. Apparently we were just getting lucky. I did not get as lucky when compiling in 32-bit mode. This test is clearly sending the version 1 form of the command, so make the version number match the intent so the EC doesn't fail the command. BUG=b:179062230 BRANCH=none TEST=make -j runhosttests BOARD=host on x86_64 and i686 Signed-off-by: Evan Green <evgreen@chromium.org> Change-Id: Ie440ff825e1125bb50b4ac2477ba983e00ef303e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3059229 Reviewed-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3105741 Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
* chgstv2: Add unit test for battery sustainerDaisuke Nojiri2021-08-202-19/+106
| | | | | | | | | | | | | | | This patch adds a unit test for the battery sustainer. BUG=b:188457962 BRANCH=None TEST=make run-sbs_charging_v2 Change-Id: Ica227cf4ee3f71a746150fb6a5f4e40ab8ca0720 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2987734 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3105740 Reviewed-by: caveh jalali <caveh@chromium.org>
* Atlas: Define chg_chipsDaisuke Nojiri2021-08-201-0/+10
| | | | | | | | | | | | | | | This patch adds chg_chips[] to board.c to make Atlas compatible with the multi-charger framework (introduced by CL:2008451 in ToT). BUG=b:188457962 BRANCH=none TEST=make runhosttests Cq-Depend: chromium:3105739 Change-Id: Ifdb507de24c5d0dde55b9d8b77e1756f351c630a Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3107851 Reviewed-by: caveh jalali <caveh@chromium.org>
* chgstv2: Refactor charger_discharge_on_acDaisuke Nojiri2021-08-205-31/+96
| | | | | | | | | | | | | | | | | | This patch makes charger_discharge_on_ac call board_discharge_on_ac. It also makes set_chg_ctrl_mode call charger_discharge_on_ac. This makes sense since when the charge control mode changes, discharge-on-ac also needs to be enabled or disabled. BUG=b:188457962 BRANCH=none TEST=make runhosttests Cq-Depend: chromium:3107851 Change-Id: I65ec09f580afc987cc86f4c60c15c1f90ead6c3c Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2986848 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3105739 Reviewed-by: caveh jalali <caveh@chromium.org>
* chgstv2: Add battery sustainerDaisuke Nojiri2021-08-202-3/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds the battery sustainer. Given a target SoC by the host, the sustainer will try to keep the SoC stay close within the range near the target. The diagram below shows how the sustainer uses the charge mode to charge or discharge the battery as the SoC moves near the target: T-d% T% ----------|----------------------|----------- charge normally charge normally/slowly (mode=NORMAL) ... ----> +---------------------> | | <----------------------+ <----- ... discharge naturally discharge normally (mode=IDLE) (mode=DISCHARGE) When AC is unplugged, the sustainer is disabled. Currently, the sustainer requires CONFIG_CHARGER_DISCHARGE_ON_AC. > chgstate state_of_charge = 69% chg_ctl_mode = NORMAL manual_voltage = -1 manual_current = -1 Battery sustainer = off (-1% ~ -1%) > chgstate sustain 70 72 state_of_charge = 69% chg_ctl_mode = NORMAL manual_voltage = -1 manual_current = -1 Battery sustainer = on (70% ~ 72%) > battfake 71 > chgstate state_of_charge = 71% chg_ctl_mode = NORMAL > battfake 73 > chgstate state_of_charge = 73% chg_ctl_mode = DISCHARGE manual_voltage = -1 manual_current = -1 > battfake 71 > chgstate state_of_charge = 71% chg_ctl_mode = IDLE manual_voltage = 0 manual_current = 0 Unplug AC and EC keeps running. > chgstate state_of_charge = 73% chg_ctl_mode = DISCHARGE manual_voltage = -1 manual_current = -1 Replug AC. > chgstate state_of_charge = 73% chg_ctl_mode = DISCHARGE manual_voltage = 0 manual_current = 0 BUG=b:188457962 BRANCH=None TEST=Atlas. See the description above. Change-Id: I62b4e8bc9517900a5a32d2f35369c645fa8a60c3 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2929347 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3105738 Reviewed-by: caveh jalali <caveh@chromium.org>
* Update EC_CMD_CHARGE_CONTROL to version 2Daisuke Nojiri2021-08-208-9/+552
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Version 2 of EC_CMD_CHARGE_CONTROL can control battery sustainer. It allows the host to set the upper and lower thresholds between which the EC tries to keep the battery state of charge. Version 2 of EC_CMD_CHARGE_CONTROL also supports 'GET' request. It allows the host to query the current charge control settings. localhost ~ # ectool chargecontrol Charge mode = NORMAL (0) Battery sustainer = off (-1% ~ -1%) localhost ~ # ectool chargecontrol normal 66 66 Charge state machine is in normal mode with sustainer enabled. localhost ~ # ectool chargecontrol Charge mode = NORMAL (0) Battery sustainer = on (66% ~ 66%) localhost ~ # ectool chargecontrol normal Charge state machine is in normal mode. BUG=b:188457962 BRANCH=none TEST=Atlas. See above. Change-Id: I81ec62172b4f159c46334fc0f940a2adae3f2b8a Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2929340 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3105737 Reviewed-by: caveh jalali <caveh@chromium.org>
* util: rewrite the host test runner in Python 3, and drop pexpectJack Rosenthal2021-08-201-72/+105
| | | | | | | | | | | | | | | | | | | | This is a total-rewrite of the host test runner, in Python 3, and no longer uses the pexpect library (simply because we don't need to open a can of Pringles with a crowbar: our usage can be handled with some simple IPC and the subprocess library). BUG=chromium:1031705,chromium:1061923 BRANCH=none TEST=host tests pass, manually-created failing tests with "Fail!", premature ending, or timeout fail appropriately. Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: I4017da877d6a34c1031b261fc41f8334dae26c00 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2106862 Reviewed-by: Chris McDonald <cjmcdonald@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3105736 Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
* ectool_keyscan: add missing null terminator to kbd_plain_xlateFabio Baltieri2021-08-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | strchr relies on the source string to be null terminated. This fixes a compiler warning when building outside of the chroot: util/ectool_keyscan.c: In function ‘cmd_keyscan’: util/ectool_keyscan.c:208:9: error: ‘strchr’ argument missing terminating nul [-Werror=stringop-overflow=] 208 | pos = strchr(kbd_plain_xlate, key); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ BUG=none TEST=build only, warning is gone BRANCH=none Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com> Change-Id: Iafb8249515ffa1a5f7e04a272e54a048eef9a57c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2606228 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3105735 Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
* ec/common: Introduce IS_ENABLED to check config optionsRaul E Rangel2021-08-201-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is copied from coreboot with added support for empty defines. We should favor using this macro instead of using #ifdef. The macro will evaluate to 0 if the option is not defined. This allows all the code to be compiled and then the optimizer will remove the sections of code that won't ever run. This way we don't end up with #ifdef sections with invalid syntax because no one ever tests that specific permutation. e.g., if (IS_ENABLED(CONFIG_USBC_SS_MUX)) { ... } There are currently spots where #ifdefs are nested 3 levels deep. This makes it very hard to follow the code. BUG=none TEST=Added some code that uses the macro and verified it executes when the config value is defined, and doesn't when it's not. Change-Id: I796b899f7cbbd3067ea3a4d52527d980c68935c9 Signed-off-by: Raul E Rangel <rrangel@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1553573 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3105733 Reviewed-by: caveh jalali <caveh@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
* util/ecst: Make sure that copying back arguments doesn't exceed MAX_ARGSPatrick Georgi2021-08-201-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Newer gcc than we have in CrOS shows a non-helpful error message: util/ecst.c: In function 'main': util/ecst.c:398:7: error: 'strncpy' output may be truncated copying 100 bytes from a string of length 9999 [-Werror=stringop-truncation] 398 | strncpy(hdr_args[arg_ind++], | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ 399 | tmp_hdr_args[tmp_ind], | ~~~~~~~~~~~~~~~~~~~~~~ 400 | ARG_SIZE); | ~~~~~~~~~ In the end it's about gcc not being able to ensure that hdr_args[] doesn't overflow. BUG=none BRANCH=none TEST=gcc 9.3 as shipped with debian sid compiles ecst without error Change-Id: I2c30cdfaac0305ea4e4c19477469bcf497469caa Signed-off-by: Patrick Georgi <pgeorgi@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2273240 Tested-by: Patrick Georgi <pgeorgi@chromium.org> Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org> Commit-Queue: Patrick Georgi <pgeorgi@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3105732 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
* extra/util: replace deprecated sys_siglist with strsignalAdrian Ratiu2021-08-203-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Starting with Glibc 2.32: * The deprecated arrays sys_siglist, _sys_siglist, and sys_sigabbrev are no longer available to newly linked binaries, and their declarations have been removed from <string.h>. They are exported solely as compatibility symbols to support old binaries. All programs should use strsignal instead. https://sourceware.org/pipermail/libc-announce/2020/000029.html BUG=chromium:1171287 BRANCH=none TEST=Local builds on x86_64 / eve and arm / kevin. Sent SIGINT to iteflash and verified output. Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.corp-partner.google.com> Change-Id: I8b4deaf8743c806a9610863648b345be3b35e1b5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2698188 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org> Commit-Queue: Manoj Gupta <manojgupta@chromium.org> Tested-by: Manoj Gupta <manojgupta@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3105731 Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
* OWNER: Update OWNER listDaisuke Nojiri2021-08-201-5/+5
| | | | | | | | | | | | | | This allows anyone to approve changes as done in ToT. BUG=None BRANCH=Atlas TEST=None Change-Id: I330c16cffb03833a4aa989fb5c04cf9614c4c83c Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3107846 Reviewed-by: Bernie Thompson <bhthompson@chromium.org> Owners-Override: Bernie Thompson <bhthompson@chromium.org>
* driver/opt3100: Set min/max frequency that match the driverGwendal Grignou2020-12-012-5/+8
| | | | | | | | | | | | | | | | | | Given we set integration time at 800ms, the host must be aware to not set an ODR over 1Hz. BUG=chromium:615059 BRANCH=nocturne TEST=Check new max_frequency is indeed 1Hz on nocturne. Change-Id: I44252073f59e00cdf4d13b4fa6d88448537c168e Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1991857 Reviewed-by: Nick Vaccaro <nvaccaro@google.com> (cherry picked from commit a8ea3bfdbe928b9bcf2d3756a2fae16fe40132ae) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2567037 (cherry picked from commit c36ba0724bc7db8cdb12b66d24f4f4db60a80d65) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2567039
* usb_pd_policy: Make a lot of objects commonAseda Aboagye2020-07-1762-9816/+745
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There is a board specific usb_pd_policy.c file that contains a lot of code for handling DisplayPort Alternate mode, Google Firmware Update Alternate mode, as well as some PD policy functions such as deciding to Accept or Reject a data role swap or a power role swap. Several boards simply copy/paste this code from project to project as a lot of this functionality is not actually board specific. This commit tries to refactor this by pulling the functions that are not mainly board specific into common code. The functions are made overridable such that boards that truly do require a different implementation may do so. Additionally, this consolidation changes the policy behaviour for some boards, but they should be for the better. Some examples include that data swaps are always allowed if we are a UFP (no system image requirement), power swaps are allowed to become a sink if we are no longer dual role (e.g. - in suspend), and DisplayPort Alternate Mode is not entered if the AP is off. In order to facilitate this refactor, a couple CONFIG_* options were introduced: - CONFIG_USB_PD_DP_HPD_GPIO /* HPD is sent to the GPU from the EC via a GPIO */ - CONFIG_USB_PD_CUSTOM_VDO /* * Define this if a board needs custom SNK and/or SRC PDOs. * * The default SRC PDO is a fixed 5V/1.5A with PDO_FIXED_FLAGS indicating * Dual-Role power, USB Communication Capable, and Dual-Role data. * * The default SNK PDOs are: * - Fixed 5V/500mA with the same PDO_FIXED_FLAGS * - Variable (non-battery) min 4.75V, max PD_MAX_VOLTAGE_MV, * operational current PD_MAX_CURRENT_MA, * - Battery min 4.75V, max PD_MAX_VOLTAGE_MV, operational power * PD_OPERATING_POWER_MW */ BUG=chromium:1021724,b:141458448 BRANCH=firmware-atlas-11827.B TEST=With other PD Policies patches, flash atlas and run faft_ec&pd Change-Id: I18fd7e22dc77fe1dc6c21c38cd7f1bc53cae86cb Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1949052 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2296085 Tested-by: Dawid Niedźwiecki <dn@semihalf.com> Reviewed-by: caveh jalali <caveh@chromium.org> Commit-Queue: Dossym Nurmukhanov <dossym@chromium.org>
* usb_pd: use enum tcpc_rp_value instead of intCaveh Jalali2020-07-1720-20/+21
| | | | | | | | | | | | | | | | | | this changes the declaration and definitions of typec_set_source_current_limit() to take an enum tcpc_rp_value instead of int. BRANCH=firmware-atlas-11827.B BUG=none TEST=With other PD Policies patches, flash atlas and run faft_ec&pd Change-Id: If633641a581eeb6085b94bc727e23fb57f7cd435 Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1889117 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2296084 Tested-by: Dawid Niedźwiecki <dn@semihalf.com> Commit-Queue: Dossym Nurmukhanov <dossym@chromium.org>
* usb: de-dup common code from old and new PD stackJett Rink2020-07-1711-61/+144
| | | | | | | | | | | | | | | | | | We still need to pull out more common code between the two stacks, but this is scaffolding with a few examples. BRANCH=firmware-atlas-11827.B BUG=b:137493121 TEST=With other PD Policies patches, flash atlas and run faft_ec&pd Change-Id: Ibd9dda1e544e06f02aa3dde48ca7de1539700cfa Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1744655 Reviewed-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2296083 Tested-by: Dawid Niedźwiecki <dn@semihalf.com> Reviewed-by: caveh jalali <caveh@chromium.org> Commit-Queue: Dossym Nurmukhanov <dossym@chromium.org>
* usb_mux: Send DP safe mode info to virtual MUXVijay Hiremath2020-07-173-1/+5
| | | | | | | | | | | | | | | | | | | | Before entering into alternate mode, state of the USB-C MUX needs to be in safe mode so that the USB-C pins cab be re-purposed without getting damaged or do not damage their Port Partner. Hence, sending the DP safe mode info to virtual MUX from EC. BUG=b:139140865 BRANCH=firmware-atlas-11827.B TEST=With other PD Policies patches, flash atlas and run faft_ec&pd Change-Id: I3715b5118112b7744407ac5e652f63f6d7cd0a1b Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1745540 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2296082 Tested-by: Dawid Niedźwiecki <dn@semihalf.com> Commit-Queue: Dossym Nurmukhanov <dossym@chromium.org> Reviewed-by: caveh jalali <caveh@chromium.org>
* common: Define markers for weak symbolsDaisuke Nojiri2020-07-171-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch introduces macros to mark weak symbols. These macros are used to annotate weak definitions, declarations, and overriding definitions. __override_proto: declarations __override: definitions which take precedence __overridable: default (weak) definitions Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=chromium.org/964060 BRANCH= firmware-atlas-11827.B TEST=With other PD Policies patches, flash atlas and run faft_ec&pd Change-Id: I44cec41e0523e285db19a890d084b52337f64a9c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1633911 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Tested-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2296081 Tested-by: Dawid Niedźwiecki <dn@semihalf.com> Reviewed-by: caveh jalali <caveh@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Dossym Nurmukhanov <dossym@chromium.org>
* usb_pd: return to correct state after tcpc resetTing Shen2020-07-071-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | Currently tcpc reset always let usb pd state machine goes back to PD_DEFAULT_STATE, which is SNK_DISCONNECTED if USB_PD_DUAL_ROLE enabled, and stay at sink even if PD_DRP_FORCE_SOURCE flag turned on. We should follow the drp_state setting after reset. BUG=b:138803492 TEST=test_that --fast --board=atlas $DUT_IP firmware_PDConnect \ firmware_PDTrySrc firmware_PDDataSwap BRANCH=firmware-atlas-11827.B Change-Id: I2ef59214fc63f253488789f1dc820576497e20ad Signed-off-by: Ting Shen <phoenixshen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1873859 Reviewed-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Ting Shen <phoenixshen@chromium.org> Tested-by: Ting Shen <phoenixshen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2279821 Tested-by: Dawid Niedźwiecki <dn@semihalf.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* stm32: Fix manual interrupt clearing functionCraig Hesling2020-03-161-1/+3
| | | | | | | | | | | | | | | | | | | | | This fixes a bug in gpio_clear_pending_interrupt, where all pending interrupts are unintentionally cleared. This is not in the code path for normal gpio interrupt handlers, since the normal interrupt clearing occurs in gpio_interrupt (right below this function). BRANCH=none BUG=chromium:1059520 TEST=none Signed-off-by: Craig Hesling <hesling@chromium.org> Change-Id: I4d6fe7947f4d76cf3b57dfbf3bb926e41851c80c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2101208 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> (cherry picked from commit c2c2c083fef813e3e3c70f8c13a1418717ba682d) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2106619
* atlas: Always advertise DFP_D connectedCaveh Jalali2019-11-121-1/+5
| | | | | | | | | | | | | | | | the VESA DisplayPort Alt Mode on USB Type-C Standard section 5.2.3 requires that DP alt mode capable devices permanently set the connected status bit. BRANCH=none BUG=chromium:1022256 TEST=verified improved interop with caldigit dock Change-Id: If439186120380cdc11eb8ea69a6b3d5d3d39b0a6 Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1903646 Reviewed-by: Caveh Jalali <caveh@google.com> Commit-Queue: Caveh Jalali <caveh@google.com>
* usb_pd_protocol: disable vconn on pd_suspendCaveh Jalali2019-11-081-0/+3
| | | | | | | | | | | | | | | | | | this disables VCONN on a port before we start the TCPC firmware update. BUG=b:143330980 BRANCH=none TEST=tested TCPC firmware update on atlas Change-Id: I2b0b8d52d637acf5b7adfdc37ef4ae4871054f5b Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1899077 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> (cherry picked from commit b76871fce86d8d89e7d1d8e951bae4e9b392d150) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1904971 Reviewed-by: Caveh Jalali <caveh@google.com> Commit-Queue: Caveh Jalali <caveh@google.com> Tested-by: Caveh Jalali <caveh@google.com>
* pd: Apply Rd prior to sending PS_RDY in PRSWAP.Aseda Aboagye2019-11-051-5/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | According to the PD spec, in a Power Role swap, the initial source must change its termination from Rp to Rd prior to sending the PS_RDY control message. This commit fixes a bug where we were changing our termination *after* sending the PS_RDY control message. BUG=b:113207208, b:116340006 BRANCH=none TEST=Plug in charge thru hub with charger plugged into nocturne, verify PR swap succeeds and the CC lines don't float to vOpen. TEST=Plug in Pixel phone into nocturne, do a PR swap, verify that the CC lines don't float to vOpen. Change-Id: If041595baa77d2494c4caff3660151329bfd4926 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/1381633 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> (cherry picked from commit 31dfe0b1a6b43b01bc89f45e6d3a4ac78b823959) Reviewed-on: https://chromium-review.googlesource.com/1388845 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> (cherry picked from commit b0fc327b14d1c0a4729720e401f29b821be4e882) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1896784 Tested-by: Matthew Blecker <matthewb@chromium.org> Reviewed-by: Caveh Jalali <caveh@google.com> Commit-Queue: Matthew Blecker <matthewb@chromium.org>
* pd_protocol: add hard_reset_complete_timerCaveh Jalali2019-11-052-37/+69
| | | | | | | | | | | | | | | | | | | | | | | | | | | | certain chargers have noisy CC lines which can prevent overly sensitive TCPCs from detecting a bus idle state. this means the TCPC will not send out messages such as hard_reset. this condition may not clear which means our pd_task() will retry sending hard_resets. although we specify a "timeout" for the event loop in this state, the timeout can be ignored by the event wait when there are pending events. this gets us into a tight event processing loop that starves the watchdog! the solution is to add an explicit timeout timer when processing the PD_STATE_HARD_RESET_SEND state. BUG=b:134702480 BRANCH=none TEST=no more EC watchdog on affected systems Change-Id: I1ae871f5d8fc99f6906ddd18741bbf68dcb6e935 Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1889431 Tested-by: Nitin Kolluru <nkolluru@google.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> (cherry picked from commit b0828291b501289f4c1d3726ab545cf3efd06d13) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1899327 Reviewed-by: Caveh Jalali <caveh@google.com> Commit-Queue: Caveh Jalali <caveh@google.com>
* Revert "pd_protocol: add hard_reset_complete_timer"caveh jalali2019-11-052-73/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 11c39dba3ff1dced5c18db57116310140f2cc66d. Reason for revert: we have a newer and improved version of this change on master, so this patch will be replaced by: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1889431 Original change's description: > pd_protocol: add hard_reset_complete_timer > > certain chargers have noisy CC lines which can prevent overly > sensitive TCPCs from detecting a bus idle state. this means the TCPC > will not send out messages such as hard_reset. this condition may not > clear which means our pd_task() will retry sending hard_resets. > although we specify a "timeout" for the event loop in this state, the > timeout can be ignored by the event wait when there are pending > events. this gets us into a tight event processing loop that starves > the watchdog! > > the solution is to add an explicit timeout timer when processing the > PD_STATE_HARD_RESET_SEND state. > > BUG=b:134702480 > BRANCH=none > TEST=no more EC watchdog on affected systems > > Change-Id: I207323fd9cff06487c56e2edec5e9c30f4517ee3 > Signed-off-by: Caveh Jalali <caveh@chromium.org> > Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1654872 > Commit-Queue: Bob Moragues <moragues@chromium.org> > Reviewed-by: Bob Moragues <moragues@chromium.org> > Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Bug: b:134702480 Change-Id: I3ce6fb6b3f9ad6668e0d4305090aaa3f8a701a81 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1899326 Tested-by: caveh jalali <caveh@chromium.org> Auto-Submit: caveh jalali <caveh@chromium.org> Reviewed-by: Caveh Jalali <caveh@google.com> Commit-Queue: Caveh Jalali <caveh@google.com>
* atlas: initialize max charge currentCaveh Jalali2019-11-011-5/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | the isl923x is strapped to initialize the charge current to 3A. however, its default max charge current limit is 3.072. when the charge current exceeds the current limit, the charger asserts PROCHOT which means the AP gets throttled to 400MHz until the charge_state machine updates the current limit. on an unlocked system, we don't change the charge limit from its default, so we never apply the 5% derating needed to avoid the isl923x from over-currenting the charger. the solution is to over-ride the 3A strapping of the isl923x by appling a 5% derated current request early when we boot up. BUG=b:141533503 BRANCH=none TEST=atlas no longer boots into PROCHOT on 5v3a charger Change-Id: Idba55edf7b1c0eec36b6583aa0b276c3cb1f0c89 Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1889312 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> (cherry picked from commit 40b0cd04aeb2ac5c59b295106fb5d4cd2d2397a5) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1894803 Reviewed-by: Caveh Jalali <caveh@google.com> Commit-Queue: Caveh Jalali <caveh@google.com>
* usb_pd_protocol: set CC termination on PD resumeCaveh Jalali2019-11-011-0/+5
| | | | | | | | | | | | | | | | | | | we need to set the CC termination back to their default value on PD resume. without this, we ended up toggling between SNK_DISCONNECTED and SNK_DISCONNECTED_DEBOUNCE when there's something plugged in. this is a partial cherry-pick of https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1650484 BUG=b:143330980 BRANCH=atlas TEST="ectool pdcontrol resume 1" now works Change-Id: I41f65b5b78eeb5316556b286f1995c8776acb746 Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1894802 Reviewed-by: Caveh Jalali <caveh@google.com> Commit-Queue: Caveh Jalali <caveh@google.com>