summaryrefslogtreecommitdiff
path: root/common/dps.c
Commit message (Collapse)AuthorAgeFilesLines
* dps: Init zephyr mutexAndrew McRae2022-12-161-1/+1
| | | | | | | | | | | | | | | | Explicitly initialize the dps_lock mutex when running on Zephyr. BUG=b:262703463 TEST=./twister -T zephyr/test BRANCH=none Change-Id: Ib0b311cd868fc314476afaa522365aba1278a1dc Signed-off-by: Andrew McRae <amcrae@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4111620 Commit-Queue: Peter Marheine <pmarheine@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Peter Marheine <pmarheine@chromium.org>
* dps: add PDO selection testsEric Yilun Lin2022-12-021-6/+12
| | | | | | | | | | | | | | | | | | | | | | It tests when the selected PDO is aligned to the system power and the efficient PDO. 1. renames dps.c to dps_config.c 2. adds dps_selection.c BUG=b:257200275 b:243840939 TEST=./twister -T test BRANCH=none Change-Id: Ie4f5e7171a922e63cbb276177a98024e11351245 Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4060443 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Tested-by: Eric Yilun Lin <yllin@google.com> Commit-Queue: Eric Yilun Lin <yllin@google.com> Auto-Submit: Eric Yilun Lin <yllin@google.com> Reviewed-by: Sung-Chi Li <lschyi@chromium.org> Reviewed-by: Ting Shen <phoenixshen@chromium.org>
* common: Sort header filesJeremy Bettis2022-11-291-6/+6
| | | | | | | | | | | | | | | | | | | | | | Sort all includes in common with the clang-format rules used by the zephyr project. BRANCH=None BUG=b:247100970 TEST=zmake build -a TEST=./twister --clobber -v -i TEST=make -j72 buildall_only runtests TEST=zmake compare-builds -a Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: I70c2ed7bb2ce50c968f3e2dbdc274de3a455129a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4049889 Auto-Submit: Jeremy Bettis <jbettis@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Tomasz Michalec <tmichalec@google.com> Reviewed-by: Tom Hughes <tomhughes@chromium.org>
* dps: Declare get_efficient_voltage() as staticAaron Massey2022-11-021-1/+1
| | | | | | | | | | | | | | | | | | | The get_efficient_voltage() function is only used locally to its source. Declare the function static. BRANCH=none BUG=none TEST=twister -i -s zephyr/test/drivers/drivers.default TEST=CQ LOW_COVERAGE_REASON=Zoss sometimes mismarks adding of static Signed-off-by: Aaron Massey <aaronmassey@google.com> Change-Id: I406e92d16c9d9e539d1891bad1e87a96a4d4db2b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3995818 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Keith Short <keithshort@chromium.org>
* dps: limit the minimum operating power when AC onlyWill Tsai2022-10-191-23/+40
| | | | | | | | | | | | | | | | | | | We found that the system will fail to boot without battery if PDO 5V/3A is selected. To prevent boot failed, limit the minimum operating power to the larger PDO when the system is booting up without battery. BUG=b:240533589 TEST=On Joxer, confirm the selected power is equal to 9V when system booting, and the system boot up successfully. TEST=./twister -v -i --coverage -p native_posix -p unit_testing BRANCH=none Signed-off-by: Will Tsai <will_tsai@wistron.corp-partner.google.com> Change-Id: I5d9655b09eead6791c5a3bf161e574f26f6beb02 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3878627 Reviewed-by: Diana Z <dzigterman@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Aaron Massey <aaronmassey@google.com>
* Update license boilerplate text in source code filesMike Frysinger2022-09-121-1/+1
| | | | | | | | | | | | | | | Normally we don't do this, but enough changes have accumulated that we're doing a tree-wide one-off update of the name & style. BRANCH=none BUG=chromium:1098010 TEST=`repo upload` works Change-Id: Icd3a1723c20595356af83d190b2c6a9078b3013b Signed-off-by: Mike Frysinger <vapier@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3891203 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* tree-wide: const-ify argv for console commandsCaveh Jalali2022-09-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | This updates the API for console commands from "int cmd(int argc, char **argv)" to "int cmd(int argc, const char **argv)" which is more accurate and in line with common convention. BRANCH=none BUG=b:244387210 TEST="make buildall" passes TEST="zmake build -a" passes TEST="util/compare_build.sh -b all" passes TEST="./twister -v -T zephyr/test" passes Cq-Depend: chrome-internal:4960125 Cq-Depend: chrome-internal:4959932 Change-Id: I57de9f35b85b8f3c7119df36aefb2abf25d2625f Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3863941 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org>
* zephyr: test: Test `dps` console command in `common/dps.c`Tristan Honscheid2022-09-011-0/+19
| | | | | | | | | | | | | Test the `dps` console command BRANCH=None BUG=None TEST=./twister Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: I89cbbf8658a6fbb25782e37048a3fa75d77e4fee Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3867045 Reviewed-by: Al Semjonovs <asemjonovs@google.com>
* zephyr: test: add dps test casesEric Yilun Lin2022-08-251-9/+25
| | | | | | | | | | | | | | | | | Setup DPS test environment and add test cases for config and enablement. BUG=b:243105887 TEST=./twister -T zephyr/test/drivers/ --sub-test drivers.dps BRANCH=none Change-Id: I33d5a0c11ff58296c0faa953775220034fb13d92 Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3841536 Commit-Queue: Eric Yilun Lin <yllin@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Tested-by: Eric Yilun Lin <yllin@google.com> Reviewed-by: Yuval Peress <peress@google.com> Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* dps: header cleanupEric Yilun Lin2022-08-231-3/+0
| | | | | | | | | | | | | | | | | Drop unneeded headers. BUG=none TEST=zmake build -a BRANCH=none Change-Id: I180d319f8ea86e8d2a6fc53eeeecf3d30950bfb3 Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3841537 Tested-by: Eric Yilun Lin <yllin@google.com> Auto-Submit: Eric Yilun Lin <yllin@google.com> Commit-Queue: Ting Shen <phoenixshen@chromium.org> Reviewed-by: Ting Shen <phoenixshen@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* dps: use active charger idx for getting voltageEric Yilun Lin2022-07-271-3/+3
| | | | | | | | | | | | | | | | | | It should use active charger index, rather than the USB-C port index. BUG=b:239777910 TEST=charger kingler at C1 port, and ensure the dps command doesn't complain. BRANCH=none Change-Id: I981257314048f4e7aa1da384c1c895df998f70b8 Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3788025 Auto-Submit: Eric Yilun Lin <yllin@google.com> Commit-Queue: Ting Shen <phoenixshen@chromium.org> Reviewed-by: Ting Shen <phoenixshen@chromium.org> Tested-by: Eric Yilun Lin <yllin@google.com>
* dps: respect PD_MAX_CURRENT_MA when evaluating PDOEric Yilun Lin2022-07-271-1/+1
| | | | | | | | | | | | | | | | PD_MAX_CURRENT_MA should be used when evaluating the PDO's maximum power it can request. BUG=b:169532537 TEST=none BRANCH=cherry Change-Id: Ia514e921b012b326fc314f33c2257f8082b42443 Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3529601 Tested-by: Eric Yilun Lin <yllin@google.com> Commit-Queue: Eric Yilun Lin <yllin@google.com> Reviewed-by: Sam Hurst <shurst@google.com>
* dps: use charger target voltage instead of battery design voltagePeter Marheine2022-07-271-3/+23
| | | | | | | | | | | | | | | | | | | | | | On systems where charger voltage can be queried, the target voltage as returned from charger_get_voltage() should be a more accurate representation of the converter's output than the battery design voltage. On Nereid, the battery design voltage is 11520 mV with actual voltage at full charge being approximately 12600 mV and VSYS set to 13200 mV. Using the design voltage as target for DPS causes 9V VBUS to be selected, even though 15V should be more efficient when VSYS is at 13.2V. BUG=b:239777910 TEST=DPS target voltage now follows charger VSYS setting on Nereid and 15V VBUS is selected as expected. BRANCH=none Signed-off-by: Peter Marheine <pmarheine@chromium.org> Change-Id: Ibe97c5888aacffd0f376f7d9d0d33b5ab80b955c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3781948 Reviewed-by: Eric Yilun Lin <yllin@google.com>
* common/dps.c: Format with clang-formatJack Rosenthal2022-06-301-31/+23
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: Iebab9e7635dd66ad3af68be2dce5fd69fec6b7dd Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729604 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* dps: ensure DPS task waited for enough timeEric Yilun Lin2022-03-161-0/+1
| | | | | | | | | | | | | | | | | | DPS task will be waken up if new srccaps received, but the DPS should wait enough time and then start the next evaluation, or we might measure the starting up current and power and the value will be underestimated. BUG=b:169532537 TEST=enable DPS, and it won't sample starting up current and power BRANCH=cherry Change-Id: I995639b4d9f88ef4eaae02ad07b49fb9b6ffee0a Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3527895 Reviewed-by: Ting Shen <phoenixshen@chromium.org> Commit-Queue: Eric Yilun Lin <yllin@google.com> Tested-by: Eric Yilun Lin <yllin@google.com>
* ectool: support dps enable/disable commandEric Yilun Lin2022-03-151-0/+12
| | | | | | | | | | | | | | | | Support dps host command for factory test. BUG=b:223937130 TEST=ectool usbpddps disable|enable BRANCH=cherry Change-Id: I050c724b5caab41644248a6f72704edbc76554a0 Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3522247 Tested-by: Eric Yilun Lin <yllin@google.com> Auto-Submit: Eric Yilun Lin <yllin@google.com> Reviewed-by: Rong Chang <rongchang@chromium.org> Commit-Queue: Rong Chang <rongchang@chromium.org>
* dps: move disable process to dps_enable()Eric Yilun Lin2022-03-151-3/+6
| | | | | | | | | | | | | | | | Move the code to an appropriate place. BUG=none TEST=dps dis, and DUT issue a new power request BRANCH=none Change-Id: Ice41f0b77c1867c0742fc9f517089c2da879e118 Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3522246 Tested-by: Eric Yilun Lin <yllin@google.com> Auto-Submit: Eric Yilun Lin <yllin@google.com> Reviewed-by: Rong Chang <rongchang@chromium.org> Commit-Queue: Rong Chang <rongchang@chromium.org>
* dps: do not evaluate a SRC portEric Yilun Lin2022-03-041-0/+4
| | | | | | | | | | | | | | | | | If the port is connected to a DRP device, and we are sourcing the device, do not evaluate it as a power source or we might sink from the port. BUG=b:206601685 TEST=Ensure the PDO is not evaluated if the power role is SRC BRANCH=cherry Change-Id: Ia70b39d88467b2835f1903ae1c8b0af168688cd8 Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3448056 Reviewed-by: Ting Shen <phoenixshen@chromium.org> Tested-by: Eric Yilun Lin <yllin@google.com> Commit-Queue: Eric Yilun Lin <yllin@google.com>
* dps: reset PD voltage when dps disabled.Eric Yilun Lin2021-10-191-0/+3
| | | | | | | | | | | | | | | | To enforce the PD voltage back to the default value, we have to force a new request. BUG=b:169532537 TEST=dps dis, and a new PD request is issued BRANCH=asurada Change-Id: I4c7d1d6019a9095099dc992411890e394c71b820 Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3229048 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Eric Yilun Lin <yllin@google.com> Tested-by: Eric Yilun Lin <yllin@google.com>
* usbpd: support dynamic PDO selectionEric Yilun Lin2021-09-011-0/+639
Support dynamic PDO selection CONFIG_USB_PD_DPS. This config controls the charging voltage and power according to the input power and battery configuration. DPS would continuously evaluate the system load and current charging voltage, and decide a new one by below: 1. If the PDO can fulfill system desired power. 2. If the PDO is efficient for the battery configuration. To detect if the system load cannot be fulfilled by the current PDO, it checks: 1. if the input current closes to the PDO current limit. 2. if the input power closes to the PDO maximum power. To detect if the system load can be fulfilled by a more efficient PDO, it checks: - if the voltage of a new PDO is closer to the battery voltage than the current PDO, and the power is able fulfill the system load. BUG=b:169532537 TEST=1. tested on asurada, the charging voltage is able to switch to different PDOs under different system loads 2. tested that the DPS is able to switch charge port (e.g. C1 12V -> C0 9V) based on the provided PDOs. BRANCH=asurada Change-Id: I7c7706b331dc0d4f8ac68569dc7ed852fc9308e3 Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2897064 Tested-by: Eric Yilun Lin <yllin@google.com> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Eric Yilun Lin <yllin@google.com>