summaryrefslogtreecommitdiff
path: root/common/usbc/usb_pe_drp_sm.c
Commit message (Collapse)AuthorAgeFilesLines
...
* TCPMv2: PD Timers - Add PE NoResponse to frameworkDenis Brockus2021-03-021-14/+7
| | | | | | | | | | | | | BUG=b:178029034 BRANCH=none TEST=make runtests Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: If5487b71106a02d9273bd0e99bf4809c45c734f5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2707909 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: PD Timers - Use NextExpiration for high priorityDenis Brockus2021-03-021-2/+1
| | | | | | | | | | | | | | | | Use outstanding PD Timer expiration times to adjust to faster state machine ticks. BUG=b:178029034 BRANCH=none TEST=make runtests Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: Iee7f75baf29e70f5fd7ef31de5c53d5824b52871 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2707908 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: PD Timers - Add PE generic Timeout to frameworkDenis Brockus2021-03-021-16/+30
| | | | | | | | | | | | | BUG=b:178029034 BRANCH=none TEST=make runtests Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: If7b81f9b19e8898be12df8fb25b13d1c90d17db4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2707907 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: PD Timers - Add PE SinkRequest to frameworkDenis Brockus2021-03-021-13/+10
| | | | | | | | | | | | | BUG=b:178029034 BRANCH=none TEST=make runtests Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I437efe7b10a7de09a483bfaea3c53ca29f73a771 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2707906 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: PD Timers - Add PE SwapSourceStart to frameworkDenis Brockus2021-03-021-12/+10
| | | | | | | | | | | | | BUG=b:178029034 BRANCH=none TEST=make runtests Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I7d6e5e12e735029d0efb183f0ba6a1abc8f61e6d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2707905 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: PD Timers - Add PE HardReset to frameworkDenis Brockus2021-03-021-11/+16
| | | | | | | | | | | | | BUG=b:178029034 BRANCH=none TEST=make runtests Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: Id00a8bdd9b2c7967e6080211c35144af46def800 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2707904 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: PD Timers - Add PE PSSourceTimer to frameworkDenis Brockus2021-03-021-31/+29
| | | | | | | | | | | | | BUG=b:178029034 BRANCH=none TEST=make runtests Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: Ie7b6dfb64fb419c43f71493f5de44a6e90b8542a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2707903 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: PD Timers - Add PE SrcTransition to frameworkDenis Brockus2021-03-021-15/+10
| | | | | | | | | | | | | BUG=b:178029034 BRANCH=none TEST=make runtests Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I66f35864109e11b53f8211c18e0ae0e0889d1853 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2707822 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: PD Timers - Add PE VConnOn to frameworkDenis Brockus2021-03-021-7/+8
| | | | | | | | | | | | | BUG=b:178029034 BRANCH=none TEST=make runtests Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: Ie77f8a7b9087985e78377b2a0414d8457d9a8300 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2707821 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: PD Timers - Add PE VDMResponse to frameworkDenis Brockus2021-03-021-15/+7
| | | | | | | | | | | | | BUG=b:178029034 BRANCH=none TEST=make runtests Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I6f7a5c79a79d5938c13514a3cea935491a443c3f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2707820 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: PD Timers - Add PE WaitAndAddJitter to frameworkDenis Brockus2021-03-021-16/+25
| | | | | | | | | | | | | BUG=b:178029034 BRANCH=none TEST=make runtests Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I6809f24f30521ff5939127c58b2e2be03f87194e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2707819 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: PD Timers - Add PE ChunkingNotSupported to frameworkDenis Brockus2021-03-021-14/+10
| | | | | | | | | | | | | BUG=b:178029034 BRANCH=none TEST=make runtests Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I3018528667273ddbe9b97ec0ad1db55cfba934b5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2707818 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: PD Timers - Add PE BistContMode to frameworkDenis Brockus2021-03-021-13/+9
| | | | | | | | | | | | | BUG=b:178029034 BRANCH=none TEST=make runtests Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: Id956787b7f3cfc07bb1bb333936a4595f841646e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2707817 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: PD Timers - Add PE SenderResponse to frameworkDenis Brockus2021-03-021-31/+100
| | | | | | | | | | | | | BUG=b:178029034 BRANCH=none TEST=make runtests Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: Ifba1403f5edd6ae56b7c2d25a3b06a1f39ed697e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2707816 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: PD Timers - Add PE PSTransition to frameworkDenis Brockus2021-03-021-16/+12
| | | | | | | | | | | | | BUG=b:178029034 BRANCH=none TEST=make runtests Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I74ad19364fa8d73fbac685097611347de2a9e537 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2707815 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: Reset discovery events on AP resetDiana Z2021-02-261-8/+5
| | | | | | | | | | | | | | | | | | | | When the AP resets, reset the SOP and SOP' discovery events so it knows there is completed discovery information to consume. Additionally, remove the requirement that events only be set from the port's PD task. Since this is just an atomic or of events and the setting of a host event, it should be safe to do from other tasks. BRANCH=None BUG=b:179505381 TEST=on galtic, verify events are reset after reboot with: - Apple 3-in-1 (SOP identity, no SOP') - TBT dock (both SOP and SOP' identity) - Active cable tied to another chromebook (SOP' identity, no SOP) Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Ib2c49854fd4269c65e771565210fe88222c6e848 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2708785 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* TCPMv2: Get SNK Caps after PR_Swap in SNK startupEric Herrmann2021-02-251-3/+9
| | | | | | | | | | | | | | | | | | | | If we support FRS, we should query the SRC sink_capabilities on entry to SNK_Ready. Currently we queue up this when we enter snk_startup, but only when it isn't due to a power role swap. Some devices will change their sink capabilities depending on what their current status is, so we should check again following a power role swap. BUG=b:181156774 TEST=make buildall TEST=Check that get_sink_capabilities message is sent following a SRC->SNK power role swap BRANCH=none Signed-off-by: Eric Herrmann <eherrmann@chromium.org> Change-Id: I5f1cbe2b300e8c29bef16336bd7ddfa8f7a8b2c7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2718495 Reviewed-by: Nathan Kolluru <nkolluru@google.com> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: Don't check VBUS when entering BIST modeAbe Levkoy2021-02-231-15/+0
| | | | | | | | | | | | | | | | | Temporarily remove check for VBUS = vSafe5V when entering BIST mode. It does this by measuring VBUS, but this facility is inadequate to the purpose on Volteer. Since this even more of an edge case than actually running BIST tests, remove the check for now, pending a more general solution. BUG=b:180957710,b:173023378 TEST=make buildall; pass TDA.2.1.2.2 BMC PHY RX INT REJ on voxel BRANCH=firmware-volteer-13672.B-main Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Change-Id: I172c1bcc10731c2e405344cdc6ad2b5a1ed80ced Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2714203 Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: PE: Improvements for SVDM response handlerScott Collyer2021-02-201-73/+112
| | | | | | | | | | | | | | | | | | | | | | | | | | This CL fixes/improves the follow areas: - Refactors the svdm_response entry state, including logic to set/clear the modal operation flag upon enter/exit mode. - Adds a check for tx message discarded flag in the response run state which allows a VDM command sequence to be proplerly interrupted. - Adds logic in the vdm common parser helper function to check for DP attention messages so the state doesn't wait for a reply. BUG=b:175660576,b:173027965 BRANCH=None TEST=Verified on quiche that can enter ALT-DP mode as a UFP-D and that display is extended properly via display port or hdmi connector. Signed-off-by: Scott Collyer <scollyer@google.com> Change-Id: I723f09ced39a3cd7c3d434102fad51c4c31f8d9f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2677703 Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org>
* TCPMv2: Source out 3.0 A to non-PD portsDiana Z2021-02-191-0/+3
| | | | | | | | | | | | | | | | | | | | | | | When no PD sinks require 3.0 A and no FRS ports require it, offer this current level to non-PD sinking devices. The non-PD devices will be downgraded whenever a higher-priority type of port is connected. BRANCH=None BUG=b:141690755 TEST=on madoo, verify: - plugging in a flash drive, it is offered 3.0 A - plugging in a 3.0 A PD sink, flash drive CC resistor is downgraded - unplugging 3.0 A PD sink, flash drive CC resistor is back to 3.0 A - connect power to 3.0 A PD sink, flash drive CC resistor is back to 3.0 A With FRS config check commented out, verify: - flash drive is downgraded and FRS enabled on powered hub plug in - flash drive is back to 3.0 A on FRS hub detach Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Iaa5c3f0a6a4f41db83978bb1e1d0b54f2519abb2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2692030 Reviewed-by: Keith Short <keithshort@chromium.org>
* TCPMv2: Refactor PD 3.0 check into FRS enableDiana Z2021-02-161-31/+24
| | | | | | | | | | | | | | | To reduce code indenting, add the check for CONFIG_USB_PD_REV30 into the pe_set_frs_enable function. Also move typec current limit setting into the FRS enable function. BRANCH=None BUG=None TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Id272c40c447c799f299fb59294c77a1603ccc1c3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2692028 Reviewed-by: Keith Short <keithshort@chromium.org>
* TCPMv2: Allocate FRS ports 3.0 A when neededDiana Z2021-02-161-87/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When there are no PD sinks requiring 3.0 A, any FRS ports which require that much current will have FRS detection enabled. If a PD sink requiring 3.0 A is attached, then FRS detection will be disabled on that port again. FRS port partners which require only USB or 1.5 A of current will always have FRS detection enabled. BRANCH=None BUG=b:141690755 TEST=on volteer-based system, verify: - FRS source partners requiring 1.5 A or less always have FRS detection enabled - FRS detection is disabled on detach - FRS source partner requiring 3.0 A has FRS detection enabled if no PD sink needing 3.0 A is present - Plugging in a 3.0 A PD sink disables FRS detection for the 3.0 A FRS partner - Unplugging a 3.0 A PD sink enables FRS detection for the 3.0 A FRS partner - When FRS occurs on 3.0 A port with detection enabled, partner is offered appropriate starting current in first source caps Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Ib067ac7c1c2f4a6e64f36aeffd1b8dde5cb93760 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2676084 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Eric Herrmann <eherrmann@chromium.org> Tested-by: Eric Herrmann <eherrmann@chromium.org>
* tcpmv2: Only issue SOP' soft reset following PR swapKeith Short2021-02-161-14/+26
| | | | | | | | | | | | | | | | | | | | | | | | Entry to the PE_SNK_Startup and PE_SRC_Startup states resets the protocol layer, and clears the message IDs for all SOP types. These states are entered during initial connect, hard reset, and after a power role swap. The cable should automatically clear it's message IDs on the initial connect (because it didn't have power) and on a hard reset, so modify the PE policy to only send SOP' soft reset after power role swaps. BUG=b:179325862 BRANCH=volteer TEST=Connect TBT loopback device, verify no SOP' soft reset is sent and that TBT entry is successful. TEST=Connect USB+DP monitor when EC starts as SRC/DFP and VCONN source. Verify EC sends SOP' soft reset is sent after power role swap. Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: I2c133eec0e76c1ecb7b79cea94a541fdb55ee9c1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2691423 Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Commit-Queue: Abe Levkoy <alevkoy@chromium.org>
* TCPMv2: Don't reset Vconn swap counter on AcceptDiana Z2021-02-091-1/+0
| | | | | | | | | | | | | | | | | Currently, when a DUT is connected to another DUT they can enter into an infinite loop of Vconn swapping. Remove the vconn swap counter re-set on Accept, and only re-set the counter on new connections. BRANCH=None BUG=b:174334068,b:179334214 TEST=with two DUTs connected, connection is able to settle into a stable state after swap attempts are exhuasted Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Ib2eec57812465efbec63220142912978c6655ba2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2678659 Tested-by: Keith Short <keithshort@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org>
* TCPMv2: tc: Fix FORCE_SOURCE and add drp initial stateScott Collyer2021-02-081-6/+11
| | | | | | | | | | | | | | | | | | | | | This CL fixes a few issues with using drp_state = FORCE_SOURCE. There were some instances where the the state was always returning to snk_unattached without checking drp_state. In addition, this CL allows for a board to specify a starting drp_state when the chipset task is not defined. BUG=b:175512794 BRANCH=None TEST=Set drp_state as FORCE_SOURCE and verified that it attaches and can detach, then attach in source power role. Signed-off-by: Scott Collyer <scollyer@google.com> Change-Id: I4c46b9aa4dfdbb073bd0bbebe8449c135034721b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2589895 Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Scott Collyer <scollyer@chromium.org>
* TCPMv2: Remove pe_prl_execute_hard_resetAbe Levkoy2021-02-081-6/+1
| | | | | | | | | | | | | Just call prl_execute_hard_reset. BUG=b:173725284,b:179198412 TEST=make buildall BRANCH=none Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Change-Id: Ib801c72e5082918c4449efed2d0fcdaa58d7e029 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2679991 Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: Reset stored PD revs at appropriate timesAbe Levkoy2021-02-081-2/+2
| | | | | | | | | | | | | | | | | | | | Stored PD revs for partners should only be reset upon Detach, Hard Reset, or Error Recovery. Don't do it when the PE enters a Startup state, e.g. after a Power Role Swap. BUG=b:173725284,b:179198412 TEST=make buildall TEST=PR Swap after SOP' Discover Identity with PD 2.0 cable; subsequent SOP' messages still PD 2.0; subsequent Enter_USB message has correct cable speed BRANCH=none Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Change-Id: I2c12287c99154fba96e4f04a76ebc48273b0bb2e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2676265 Reviewed-by: Diana Z <dzigterman@chromium.org> Tested-by: Divya Sasidharan <divya.s.sasidharan@intel.corp-partner.google.com> Tested-by: Ayushee Shah <ayushee.shah@intel.com>
* TCPMv2: Add DPM controls for FRS detectionDiana Z2021-02-081-4/+33
| | | | | | | | | | | | | | | Add a DPM request to control FRS detection enable and disable on a task. This allows the FRS detection to be safely toggled from other tasks when 3A port balancing occurs. BRANCH=None BUG=b:141690755 TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I41d4f4a77f536c95a8119fef0de0474f0726fbab Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2676083 Reviewed-by: Keith Short <keithshort@chromium.org>
* TCPMv2: Move source and sink DPM handling to helpersDiana Z2021-02-081-105/+143
| | | | | | | | | | | | | | | | | Move DPM handling for source run and sink run into helper functions to reduce the level of nesting for their clauses. Additionally, allow the run state to continue when an unhandled DPM request is received as there's no reason to exit early in that case. BRANCH=None BUG=None TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I4d42d9417e155df8cff7f86016d3a6c8365675b5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2680938 Reviewed-by: Keith Short <keithshort@chromium.org>
* usb: Correct comments for CONFIG_USB_PD_EXTENDED_MESSAGESSimon Glass2021-02-051-1/+1
| | | | | | | | | | | | | | | Some of the comments are out-of-sync or incorrect for this option. Fix them along with an extra blank line at end-of-file. BUG=none BRANCH=none TEST=build for volteer Signed-off-by: Simon Glass <sjg@chromium.org> Change-Id: I68bc96907b61b16244e114f594adb31ed1438c50 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2677181 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* TCPMv2: Check for discard in cable reset stateDiana Z2021-02-051-8/+7
| | | | | | | | | | | | | | | Check for message discard and restore DPM request if cable soft reset doesn't send, then return to Ready to handle the incoming message. BRANCH=None BUG=None TEST=connect Magolor and Madoo together repeatedly and observe the connection is able to stabilize Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I28787f802a8279d318170a304e5aeac6abb03b75 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2676925 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* TCPMv2: Check charge port when bootingDiana Z2021-02-051-3/+6
| | | | | | | | | | | | | | | | | | When booting into S0, take the current charge port into account when deciding whether to power role swap. If the port has been selected from the UI as a charge port, then refrain from swapping and continue to charge from it. BRANCH=None BUG=b:179334214,b:179095748,b:178070314 TEST=on madoo, connect to magolor and select charging from magolor on the UI. Go through suspend and shutdown iterations and confirm that madoo continues to charge from magolor Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I40ef73309f75372b0a34a7542282244ff30868ed Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2676924 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* TCPMv2: Consult board before setting power role swap requestDiana Z2021-02-051-0/+4
| | | | | | | | | | | | | | | | | If a board does not want to power role swap (ex. because it is in S5), then do not allow the DPM request for the power role swap to be set. This is equivalent to the logic done when a PR_SWAP message is received by the system. BRANCH=None BUG=b:174726240 TEST=on madoo, plug in phone and shutdown. Verify DUT does not swap to sourcing when in S5 Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Ia6684006d0de6d9f23bac8bd792c34191fabab14 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2676931 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* TCPMv2: Store the cable's PD revision after soft reset SOP'Ayushee Shah2021-02-031-0/+11
| | | | | | | | | | | | | | | | | On soft reset SOP', the cable's PD revision is lost causing Thunderbolt and USB4 devices to downgrade. Hence, this patch retains the cable revision by storing it again after a soft reset SOP'. BUG=b:173725284 BRANCH=None TEST=No downgrade seen with USB4 with 100 continuous hotplugs Signed-off-by: Ayushee Shah <ayushee.shah@intel.com> Change-Id: I4498c6b397503058e5c4c2bce91e7d31960f6395 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2669418 Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Commit-Queue: Abe Levkoy <alevkoy@chromium.org>
* TCPMv2: Adjust sink hard reset behaviorDiana Z2021-02-011-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | Adjust the timing and behavior of our sink hard resets. This allows us to reply to partners faster after a hard reset if they take very little time to reach vSafe0V, and also only reduces our input current limit if Vbus actually drops. Since we may still be drawing current from a non-PD port partner on startup, compare Vbus against the vSinkDisconnect level rather than vSafe5V. Additionally, this clears flags in the sink hard reset path, similar to the source hard reset path, and removes an incorrect comment. BRANCH=None BUG=b:172867393,b:178615293 TEST=on drawcia, confirm hard resets as sink go well with: - Suzy-q - servo_v4 with charger - BenQ monitor - Apple 3-in-1 dongle - Powered Dock Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I4c5633705da4716536316255834455da2b383a5b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2541883 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* TCPMv2: Check message discard sending Vconn swap PS_RDYDiana Z2021-01-291-0/+3
| | | | | | | | | | | | | | | Incoming messages may cause the PS_RDY message from a Vconn swap to be discarded. Check for this condition and soft reset using the SOP* of the incoming message. BRANCH=None BUG=b:157228506,b:174726240 TEST=on galtic, verify after reboot phone is able to charge Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Ic74d490ab2c1450851b795249f2e57322461ad2b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2653794 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* common: Add attribute to store const data in .dataKeith Short2021-01-271-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On EC chips that support CONFIG_CHIP_DATA_IN_INIT_ROM, the code execution RAM is smaller than flash, leaving some flash unused. The CONFIG_CHIP_DATA_IN_INIT_ROM moves the .data section into the unused flash area, where it is copied directly into data RAM at startup. Add a new attribute __const_data that allows constant data objects to link into the .data section instead of .rodata. This saves 1600 bytes of RO and RW flash space on boards that enable CONFIG_CHIP_DATA_IN_INIT_ROM. delbin_npcx796fc eldrid_npcx796fc halvor lindar lingcod magolor_legacy malefor metaknight_legacy terrador todor trondo voema volteer_apmodeentry volteer waddledoo BUG=none BRANCH=none TEST=make buildall TEST=boot Volteer and verify USB-PD operation Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: Ibb97a499442bbab8185b1d07f8867a7af1e793f4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2651208 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* TCPMv2: Wait for tSrcTransition after AcceptAbe Levkoy2021-01-261-5/+20
| | | | | | | | | | | | | | | | | During power contract negotiation, after sending Accept, wait for tSrcTransition before transitioning the supply and sending PS_RDY. See PD r3.0, v2.0, Table 7-22. BUG=b:173023378 TEST=Pass TDA.2.1.2.2 using MQP compliance tester (or at least don't fail due to sending PS_RDY too early). BRANCH=none Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Change-Id: I76e31ff5df6bfd71f78642bda25e1e8f9f590f9c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2644179 Reviewed-by: Diana Z <dzigterman@chromium.org> Tested-by: JC Huang <j.c.huang@quanta.corp-partner.google.com>
* tcpmv2: Re-discover cable if the port parter is PD 2.0Ayushee Shah2021-01-251-12/+23
| | | | | | | | | | | | | | | If the cables has been queried with PD 3.0, but the port partner supports PD 2.0, re-discover the cable capabilities. BUG=b:178077239 BRANCH=None TEST=Tested with PD2.0 dock and PD3.0 cable, able to enter Thunderbolt mode. Signed-off-by: Ayushee Shah <ayushee.shah@intel.com> Change-Id: I559f57a64a525a7ee0ae8744f88ec347688fe880 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2643580 Reviewed-by: Keith Short <keithshort@chromium.org>
* TCPMv1/TCPMv2: Add functions providing requested voltage and currentPatryk Duda2021-01-221-0/+10
| | | | | | | | | | | | | | | | | This patch adds functions responsible for providing voltage and current requested from charger. This patch doesn't introduce any logical changes. BUG=b:161775827 BRANCH=none TEST=make -j buildall Signed-off-by: Patryk Duda <pdk@semihalf.com> Change-Id: Ib86285e4c4e6f2da3f922a8a4389e78706f1de96 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2592497 Reviewed-by: Wai-Hong Tam <waihong@google.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* config: Make VCONN Swap delay a documented optionAbe Levkoy2021-01-221-2/+4
| | | | | | | | | | | | | | | | | | | | | Replace PD_VCONN_SWAP_DELAY with CONFIG_USBC_VCONN_SWAP_DELAY_US. This is the approximate result of the following command, run from platform/ec: find . -type f -\( -name '*.c' -o -name '*.h' -\) | \ xargs sed -iE 's/PD_VCONN_SWAP_DELAY/CONFIG_USBC_VCONN_SWAP_DELAY/g' Fix some latent formatting errors in usb_pd_protocol.c, because they were preventing pre-upload hooks from passing. BUG=b:144165680 TEST=make buildall BRANCH=none Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Change-Id: Icaf3b309c08fdcd162e960cf5dc88185016b5d2d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2628131 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
* TCPMv2: Support BIST Test ModeAbe Levkoy2021-01-221-0/+8
| | | | | | | | | | | | | | | | | | After the first BIST Test Data packet, enable BIST Test Mode if the TCPC supports it (currently just TCPCI). While in BIST Test Mode, mask ALERT.ReceivedSOP*MessageStatus. Unmask it when the test ends, due to Hard Reset or to detach. BUG=b:173023378,b:169385081,b:172709198,b:173028832,b:173028791 BUG=b:173141941,b:173142113 TEST=Complete TDA.2.1.2.2 BMC PHY RX INT REJ on volteer without running out of Rx buffer space or watchdog timeout (still fail though) BRANCH=firmware-volteer-13521.B-master Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Change-Id: I03bbc4cfacceebd0334aa814e11a16e09177a322 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2545667 Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: Ignore BIST messages when appropriateAbe Levkoy2021-01-221-0/+21
| | | | | | | | | | | | | | Ignore BIST messages when not operating at vSafe5V. Ignore unsupported BIST modes. BUG=b:169385081 TEST=make buildall BRANCH=firmware-volteer-13672.B-main Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Change-Id: Ia7504cf0f7cf16273aa641edb364eef7e666a3ff Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2602720 Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: TD.PD.SRC.E5 Compliance failure - service event loop as high priorityDenis Brockus2021-01-211-0/+7
| | | | | | | | | | | | | | | | | | | | Increased the event loop while waiting for the response in PE_SRC_Send_Capabilities in order to respond with the HardReset in the correct window of time. BUG=b:173025780 BRANCH=zork TEST=make run-usb_tcpmv2_compliance Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: Ia108b3d4d4f18b76da6550f406011d1ee79c2757 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2639663 Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Edward Hill <ecgh@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Denis Brockus <dbrockus@chromium.org> Auto-Submit: Denis Brockus <dbrockus@chromium.org>
* TCPMv2: Do not check for SinkTxOk in FRS-ModeEric Herrmann2021-01-201-10/+14
| | | | | | | | | | | | | | | | | | | | | | | After an FRS signal, the initial sink will attempt to initiate the FR Swap AMS, and the initial source should apply SinkTxOk. If the initial source is removed entirely, FRS will be triggered butSinkTxOk will never be applied and this will get the initial sink state machine stuck. So, in the case of an FRS ignore the CC voltage. After an FRS signal, the source isn't allowed to initiate an AMS. BUG=b:171740860 TEST=On Volteer with the PS8815, enable FRS and remove the FRS device. Make sure we enter ErrorRecovery instead of hanging in PE_PRS_SNK_SRC_Send_Swap TEST=make buildall BRANCH=none Change-Id: I8373a76c0c19feeb909b0623a1ae2d6b0ad5fa60 Signed-off-by: Eric Herrmann <eherrmann@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2633654 Commit-Queue: Diana Z <dzigterman@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: Process DPMs before discoveryDiana Z2021-01-141-26/+22
| | | | | | | | | | | | | | | | | | | | | | Some devices may reply to discovery differently if they're not yet being offered sufficient current. Process DPM requests before running discovery in order to get these devices into the best state for discovery probing. This also moves the cable soft reset DPM request up to the common DPM request function. Otherwise, it will be considered an unhandled request and dropped before attempting discovery. BRANCH=volteer BUG=b:177303467,b:177001425 TEST=verify we can reliably receive DiscoverSVIDs ACK from LaCie SSD Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I0917476c2aeb0cb9551edde3df14ddd1fd47fcab Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2627805 Tested-by: Utkarsh H Patel <utkarsh.h.patel@intel.com> Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org>
* TCPMv2: Do not perform hard reset when battery is lowPatryk Duda2021-01-121-0/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change adds checking for enough battery level before sending hard reset in PE_SNK_Hard_Reset state. There are a lot of reasons causing Policy Engine to send hard reset. One of them is timeout in PE_SNK_Wait_For_Capabilities, which can cause brown out if battery doesn't have enough charge New flag PE_FLAGS_SNK_WAITING_BATT was added. This flag is set on PE_SNK_Hard_Reset entry, and can be cleared when battery reaches minimal charge (see pe_update_waiting_batt_flag()). Original fix implemented for TCPMv1 stack: https://chromium-review.googlesource.com/1565147 https://chromium-review.googlesource.com/1980406 BUG=b:160243307, b:161775827 BRANCH=none TEST=Get board with bad battery (eg. bobba). Flash ToT EC. Discharge battery to cutoff. Plug charger. Make sure that PD goes to PE_SRC_Disabled after PE_SNK_Wait_For_Capabilities tries to send hard reset (switches to PE_SNK_Hard_Reset). PD should remain in PE_SRC_Disabled state until battery reaches minimal charge. It might be necessary to limit PD_CAPS_COUNT (in my case to 10) in ServoV4 (used as charger) to actually trigger timeout. During test EC RO have to report that PD comm is disabled, in other words system must be locked. When battery charges quickly, it is allowed to do 'sysjump RW'. Signed-off-by: Patryk Duda <pdk@semihalf.com> Change-Id: I63ac93a093d921f41bea2af93de8325783056962 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2600985 Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: Send Hard Reset from any state on DPM requestPatryk Duda2021-01-121-18/+22
| | | | | | | | | | | | | | | | | | | | | | | | | USB PD specification states that we can send Hard Reset on DPM request regardless of state we are currently in (see USB PD Specification 8.3.3.3.8). This patch implements changing state to PE_SNK_Hard_Reset or PE_SRC_Hard_Reset depending on current power role when requested by DPM. Currently, requests can come only from PD console. BUG=b:160243307 BRANCH=none TEST=Connect DUT to ServoV4. Configure ServoV4 as source using 'cc src' or 'cc srcdts'. Issue Hard Reset from DUT EC console using 'pd 0 hard'. Check if transition PE_SNK_Ready -> PE_SNK_Hard_Reset occurs. Configure ServoV4 as sink using 'cc pdsnk' or 'cc pdsnkdts'. Issue Hard Reset from DUT EC console using 'pd 0 hard'. Check if transition PE_SRC_Ready -> PE_SRC_Hard_Reset occurs. Signed-off-by: Patryk Duda <pdk@semihalf.com> Change-Id: I46a0446ff9dd417bab19fd13d71aa11e8aa83d04 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2618002 Reviewed-by: Diana Z <dzigterman@chromium.org>
* tcpmv2: Use cable soft reset state during VCSKeith Short2021-01-091-82/+17
| | | | | | | | | | | | | BUG=b:152058087 BRANCH=volteer TEST=Connect to monitor as SRC, verify SOP' soft reset sent after VCONN swap and before SOP' DiscoveryIdentity. Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: If8b52ed033b1ee78d61958d6c9bf5d7ff01bc8dc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2601143 Reviewed-by: Diana Z <dzigterman@chromium.org> Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* tcpmv2: always issue SOP' soft resetKeith Short2021-01-091-0/+114
| | | | | | | | | | | | | | | | | | | After entering a PD contract, always issue an SOP' soft reset before sending any discovery VDMs to the cable. BUG=b:172364575 BRANCH=volteer TEST=connect monitor with emarked cable, verify SOP' soft reset is sent when EC starts as SNK/DFP. TEST=Connect monitor with non-emark cable. Verify SOP' soft reset is sent once regardless of starting role. TEST=Connect USB4 dock, verify USB4 entry. Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: Id5026a2c8c9877b860e1356dd33763bad3e51841 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2596838 Reviewed-by: Diana Z <dzigterman@chromium.org> Reviewed-by: Abe Levkoy <alevkoy@chromium.org>