summaryrefslogtreecommitdiff
path: root/common
Commit message (Collapse)AuthorAgeFilesLines
* switch: cleanup lid_is_open logicJack Rosenthal2021-03-251-6/+1
| | | | | | | | | | | | | | | Cleanup an ifdef here for systems without a lid switch, so that "lid looks open" is just a consequence of !IS_ENABLED(CONFIG_LID_SWITCH). BUG=none BRANCH=none TEST=buildall Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: I1bbc145a0ffb49a127cb5a4e3986ed0955381353 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2787588 Commit-Queue: Paul Fagerburg <pfagerburg@chromium.org> Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
* PCHG: Notify host of new SOC and all other events in S0Daisuke Nojiri2021-03-251-4/+4
| | | | | | | | | | | | | | Currently, the EC notifies the host of a new SOC and errors. This change makes the EC additionally notify the host of all other events. BUG=b:182973695, b:173235954 BRANCH=trogdor TEST=Stylus battery indicator changes timely when stylus is attached. TEST=Suspend is entered quickly with a stylus attached. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: Id74d809f9838fa36b25d710ed64b6f1ba236cad8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2785512
* ctn730: Print firmware versionDaisuke Nojiri2021-03-241-5/+7
| | | | | | | | | | | | | | | | | | This patch makes ctn730 driver print the firmware version. EC_CMD_PCHG is updated to version 1 and returns firmware version of a charger chip. Version 0 of EC_CMD_PCHG is deprecated. BUG=b:182600604, b:173235954, b:183151376 BRANCH=Trogdor TEST=Verify firmware version is printed on EC console. TEST=ectool pchg 0 (for version 1) TEST=cat /sys/class/power_supply/PCHG0/* (for version 0) "ERR kernel: [ 33.394847] cros-ec-pchg cros-ec-pchg.13.auto: Unable to get port.0 status (err:-524)" Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: Ib7bb9a7225fe914bc6c8d600d0f4766dbf75ace8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2757098
* TCPMv2: Do not apply CC Open when running without batteryPatryk Duda2021-03-241-2/+25
| | | | | | | | | | | | | | | | | | | | | | | | This patch prevents applying CC Open when there is no battery. On some boards EC RO doesn't save power-on reset flag in BBRAM when EC reboot by Cr50 is expected. This behaviour was implemented in CL:2255830. Brown-out reset flag is implemented only for LM4 chips. Also we don't have access to information stored by TCPMv1 in BBRAM. This functionality was removed from TCPMv2 in CL:2271002, so we can't really determine if we should apply CC Open and from that time we are applying CC Open always, except power-on and brown-out reset flags. This patch adds missing battery to list of exceptions. BUG=b:161775827 BRANCH=none TEST=Flash EC ToT on Fleex. Disconnect battery physically and plug charger. Check if ChromeOS boots successfully. Signed-off-by: Patryk Duda <pdk@semihalf.com> Change-Id: Icc22fcce595693c744e1a55b905cdd58b5e7bfbd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2767638 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* keyboard_mkbp: use K_MUTEX_DEFINE to define FIFO mutexesWai-Hong Tam2021-03-241-2/+2
| | | | | | | | | | | | | | Use K_MUTEX_DEFINE to define FIFO mutexes. It supports both Zephyr and CrOS EC implementations. BRANCH=None BUG=b:183445211 TEST=Build the CrOS EC image for Lazor. Change-Id: Ie8ef54970774c5ec27329a8b2913e015577e8113 Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2782364 Reviewed-by: Simon Glass <sjg@chromium.org>
* usbc: change max_current_claimed_lock to use K_MUTEX_DEFINEJack Rosenthal2021-03-231-12/+1
| | | | | | | | | | | | | | Convert max_current_claimed_lock to use K_MUTEX_DEFINE(), removing the requirement for runtime initialization on Zephyr. BUG=b:177677037 BRANCH=none TEST=zmake testall && make buildall Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: I4ffbde25f66bf33f33b4432e2c71871697d71023 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2782236 Reviewed-by: Simon Glass <sjg@chromium.org>
* chipset: convert reset_log_mutex to use K_MUTEX_DEFINEJack Rosenthal2021-03-231-4/+1
| | | | | | | | | | | | | | Using K_MUTEX_DEFINE() initializes the mutex automatically, thus removing the requirement to use k_mutex_init(). BUG=b:177677037 BRANCH=none TEST=zmake testall && make buildall Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: Icd52129fe6a3edd497a6663b3ffea10c5b7b9dce Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2782233 Reviewed-by: Simon Glass <sjg@chromium.org>
* throttle_ap: convert throttle_mutex to use K_MUTEX_DEFINEJack Rosenthal2021-03-231-6/+1
| | | | | | | | | | | | | | | | | | | | | K_MUTEX_DEFINE creates a statically-initialized mutex, and is now available for both Zephyr and CrOS EC OS. The previous way of initializing this mutex required a boolean variable, which could potentially be the cause of a race condition if the mutex had been initialized in two threads (this condition has not been observed, though). Change to K_MUTEX_DEFINE to demonstrate the new way to do this. BUG=b:177677037 BRANCH=none TEST=compile for zephyr and CrOS EC OS Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: Id27e6bff975809a2ea51bb5e9ddb0e9e6971f066 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2782232 Reviewed-by: Simon Glass <sjg@chromium.org>
* TCPMv2: Increment Vconn swap counter after sendDiana Z2021-03-231-1/+3
| | | | | | | | | | | | | | | | During initial connection, Vconn swaps may be discarded without sending. Only count a Vconn swap for the purposes of the counter when the swap was successfully sent. BRANCH=Volteer BUG=b:182885623 TEST=verify two Voxels connected together are reliably able to enter TBT mode Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Ia76f03ee4c517d297061bda9dc9b5bfbf5990485 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2776213 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* CBI: Add CBI set to console commandDiana Z2021-03-231-12/+113
| | | | | | | | | | | | | | | | | Add the ability to set and remove tags to the CBI in the EC console. This will allow boards which are not yet booting to the OS to set their CBI fields from the EC directly. It provides similar field size checks to the ectool command version, though strings are more limited than with ectool (less than 80 characters, versus over 200 possible with ectool). BRANCH=None BUG=b:183029344 TEST=on galith, use cbi to set and remove various fields Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Ie7395e12467eeac4732cd17e923ee4a78a461b36 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2776223 Reviewed-by: Rob Barnes <robbarnes@google.com>
* TCPMv2: PE: Add mechanism to request source power roleScott Collyer2021-03-201-3/+13
| | | | | | | | | | | | | | | | | | | | | This CL makes the function pd_can_source_from_device() overridable. This default implementation is used in deciding whether to request a power role swap. By making this overridable, boards have the option of implementing custom per port policy for requesting power role swaps. BUG=b:182441965 BRANCH=None TEST=verfied that on quiche when attaching as a sink that a power role swap request is generated. Previously, quiche relied on the host requesting a power role swap. Signed-off-by: Scott Collyer <scollyer@google.com> Change-Id: I9c5bdb77405a6075de9c5b4269213f810a20cc6c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2722989 Commit-Queue: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* zephyr: implement task timersJack Rosenthal2021-03-201-0/+3
| | | | | | | | | | | | | | | | | | | | | CrOS EC OS provides one implicit timer associated with every task (see docs/core_runtime.md). As luck has it, we never needed these implicit timers for volteer, but ARM power sequencing code uses it. This implements the timer_arm and timer_cancel functions, which function equivalently to how they would in CrOS EC OS. (Note: we previously were compiling timer_arm and timer_cancel from CrOS EC, but these definitions were non-functional as we never call process_timers from Zephyr). BUG=b:183058135 BRANCH=none TEST=provided unit tests pass Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: Ibad20002c489a8149efde713d8273adae835f653 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2774362 Reviewed-by: Simon Glass <sjg@chromium.org>
* TCPMv2: Compliance Unit Test - allow PROC.PD.E3 flexibilityDenis Brockus2021-03-191-4/+9
| | | | | | | | | | | | | | | | | Allow the startup messages to be optional and don't require a specific ordering. Also add PR_Swap when PD_ROLE_UFP. BUG=none BRANCH=none TEST=make run-usb_tcpmv2_compliance Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: Ifef6fa558a789c2ce34a9f9fbf38529dc90d5e6f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2774580 Tested-by: Denis Brockus <dbrockus@chromium.org> Auto-Submit: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Diana Z <dzigterman@chromium.org>
* TCPMv2: PRL: Don't report ERR_RCH_CHUNKED to PE for timeoutScott Collyer2021-03-192-4/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | This CL adds a new RCH error type used for the case when there was a sender response timeout waiting for the next chunk of a chunked message to be received. This particular error should not result in the PE triggering a soft reset. This new error type allows the PE function to do nothing for this error case. All other RCH error states remain the same. This change is required to pass the TD.PD.SRC3.E32 compliance test where the tester purposely stops sending after the 4th chunk and expects to be able to resend that message without an protocol error being reported. BUG=b:181333342,b:179443762 BRANCH=None TEST=Verified that quiche can now pass TD.PD.SRC3.E32 Signed-off-by: Scott Collyer <scollyer@google.com> Change-Id: I0142ca8d23cd23ef7b347d5c07155cdb17f44b88 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2734158 Reviewed-by: Denis Brockus <dbrockus@chromium.org> Tested-by: Denis Brockus <dbrockus@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Commit-Queue: Scott Collyer <scollyer@chromium.org>
* Hooks: Add HOOK_CHIPSET_HARD_OFFDiana Z2021-03-181-0/+1
| | | | | | | | | | | | | | | Add a new hook called HOOK_CHIPSET_HARD_OFF which is called upon entry to the G3 power state. BRANCH=None BUG=b:166787955,b:167996216,chromium:1045209 TEST=make -j buildall, runs on waddledee with no linking errors Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: If260207910d882d17aeb766c9e99a7a6099006c7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2415171 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* PCHG: Don't notify host when there is no soc changeDaisuke Nojiri2021-03-181-10/+17
| | | | | | | | | | | | | | | | | | | Currently, the host is notified every time a charging info message is received from a charger chip. This slows down the host entring suspend state. This patch makes the pchg state machine skip notifying the host when there is no battery level change. BUG=b:182973695, b:173235954 BRANCH=trogdor TEST=Stylus connect, disconnect, charge events are triggered as expected. TEST=Suspend is entered quickly with a stylus attached. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: If27397a56f8cc636637c0872a00496fee3ca7aa5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2770504
* PCHG: Support reset to firmware update modeDaisuke Nojiri2021-03-181-94/+73
| | | | | | | | | | | | | | | | | | | | | | | This patch allows a charger chip to reset to firmware update mode (a.k.a. download mode). Actual firmware update will be added in a separate patch. Currently, a reset event causes the state machine to unconditionally transition to normal mode. This patch makes the state machine check 'mode' field in the context to decide whether it transitions to normal mode or not. This patch also makes ctn730 driver explicitly return PCHG_EVENT_*_ERROR while PCHG_EVENT_NONE was returned previously. BUG=b:173235954 BRANCH=trogdor TEST=Stylus connect, disconnect, charge events are triggered as expected. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I10dbd25d0b3d5284952e57d4ade2949e9594c8d1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2770503
* PCHG: Count number of dropped events per portDaisuke Nojiri2021-03-181-3/+3
| | | | | | | | | | | | | Currently, dropped events are counted for all ports combined. This patch makes them counted for each port separately. BUG=b:173235954 BRANCH=trogdor TEST=Verify 'pchg 0' prints dropped event count. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I09380927613defe34bef0fece022fc9d47ebb8a1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2770502
* PCHG: Check array sizes for state and event textsDaisuke Nojiri2021-03-181-0/+2
| | | | | | | | | | | | | | This patch makes a compiler check array sizes used to stringify PCHG states and events. BUG=b:173235954 BRANCH=trogdor TEST=make Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I13dc399dc973d8a661492236668c22b323e7c1c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2765423 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* crc32: Add crc32_hash and crc32_ctx_hashDaisuke Nojiri2021-03-181-4/+14
| | | | | | | | | | | | | | | This patch adds crc32_hash and crc32_ctx_hash, which compute CRC32 of data in arbitrary length using an internal context and an external context, respectively. BUG=None BRANCH=None TEST=make run-crc Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I08729528fba6b1350bbb8387c048025f72496b2d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2757097 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* TCPMv2: PE/DPM: Don't preemptively set modal flagScott Collyer2021-03-173-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | Currently we are setting the modal flag as a DFP when the ENTER command is being sent, without confirmation of the ACK reply from the UFP. This CL keeps this behavior for TCPMv1, but moves the setting of the modal flag into the alt mode specific state machine. Currently, we only support DP and Thunderbolt alt modes. When the modal flag is set pre-emptively, we will fail the TDA.2.2.3: BMC-PROT-SEQ-DRSWAP compliance test. This is because we trigger a hard reset if the modal flag is set and we receive a data role swap request. BUG=b:180764800,b:159946351,b:181386294 BRANCH=None TEST=Verifed that TDA.2.2.3: BMC-PROT-SEQ-DRSWAP passes on quiche Signed-off-by: Scott Collyer <scollyer@google.com> Change-Id: I4ae527903859e8ffdb01f355606c5d0f7d177def Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2751329 Commit-Queue: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* TCPMv2: Don't reply to SVDMs in rev2.0 as a DFPScott Collyer2021-03-171-1/+7
| | | | | | | | | | | | | | | | | | | | When are connected to a rev2.0 port partner and in a DFP data role, the only SVDM command that is allowed is the Attention message. All other SVDM commands should be NAK'd. This CL adds a change to the svdm_response function in PE to check for this case. This change fixes TD.PD.VDMD.E4 compliance test. BUG=b:182495985 BRANCH=None TEST=Verified that TD.PD.VDMD.E4 compliance test passes on quiche Signed-off-by: Scott Collyer <scollyer@google.com> Change-Id: I05bb639b81f634239b6db948ebb760c08b748c08 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2751330 Commit-Queue: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: Don't enter Tx BIST mode when VBUS > VSafe5VScott Collyer2021-03-171-0/+19
| | | | | | | | | | | | | | | | | | | | | | By spec we are only allowed to enter BIST mode when VBUS is at vSafe5V. This CL adds a check in pe_bist_tx_entry to make sure that BIST test mode is only entered if VBUS is at the correct level. We compared to the expected nominal VBUS level and not the actual measured level as not all boards will have accurate enough VBUS measurements. BUG=b:180957710 BRANCH=None TEST=Verfied that quiche can pass the TDA.2.2.7 compliance test. Signed-off-by: Scott Collyer <scollyer@google.com> Change-Id: Icc2e5ff6c32374c89490e5bea79af2c4517ea295 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2738397 Commit-Queue: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: Fix check for svdm response w/ AttentionScott Collyer2021-03-171-22/+25
| | | | | | | | | | | | | | | | | | | | Attention messages do not require a response message. A previous CL had a check for this message in a helper function. That method was not correct because the the vdm message buffer in the PE object does not get cleared and so this buffer should only be checked in a state where the vdm buffer contents are known to be current. 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: Id9908fd4bd3db574fb6f769ab0d2e1db0be5aecd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2718270 Commit-Queue: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: TC: Check drp_state upon exit of tc_disabledScott Collyer2021-03-171-4/+6
| | | | | | | | | | | | | | | | | | This CL fixes a remaining issue for starting in the correct state when the drp_state is set to FORCE_SOURCE. BUG=b:175512794 BRANCH=None TEST=verfied that following disabling of a port that when the port is enabled again, it will start in the unattached_src state instead of unattached_snk. Signed-off-by: Scott Collyer <scollyer@google.com> Change-Id: I86e2ca3a3231a727660fbdd328115ed506fcdd5d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2718267 Tested-by: Scott Collyer <scollyer@chromium.org> Commit-Queue: Scott Collyer <scollyer@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMV2: Remove unused TypeC State Machine FlagSam Hurst2021-03-171-26/+10
| | | | | | | | | | | | | | The TC_FLAGS_DISC_IDENT_IN_PROGRESS TypeC State Machine flag is unused, so it has been removed. BUG=b:165934405 BRANCH=none TEST=make runtests Signed-off-by: Sam Hurst <shurst@google.com> Change-Id: I888c53a90a68e0d3690f47ca54e6e765601e7c3c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2765156 Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMV2: Add support for (CT) Vconn Powered DevicesSam Hurst2021-03-173-7/+107
| | | | | | | | | | | | | | | | | | | | | Add support for Charge Through Vconn Powered Devices BUG=b:165934405 BRANCH=none TEST=make runtests 1) Verified that Apple VPD audio device worked. 2) With charger plugged into Chocodile_Vpdmcu, verified that a Voxel could be charged. 3) FAILED: Plugging Chocodile_Vpdmcu into Voxel first and then plugging in charger to Chocodile_Vpdmcu, Chocodile is detected as a Debug Accessory (CC1 = Rd and CC2 = Rd) and VCONN is never applied. Signed-off-by: Sam Hurst <shurst@google.com> Change-Id: I977b316dc531aa33bb6a236523c8ddbbb23014d0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2748429 Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: Preserve selected source current in FRSDiana Z2021-03-174-5/+23
| | | | | | | | | | | | | | | | | | | | When executing a fast role swap, ensure that any 3.0 A selected current is preserved through the select_current_limit_rp in the TC layer. Additionally, use this selected current to set our current limit when first attaching as a source. If FRS is disabled on a port, restore the default Rp value for the board. BRANCH=None BUG=b:180434465 TEST=Check that a 3A FRS device loaded over 1.5 A is able to successfully complete FRS Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I6e6b2f95066a3f8972664c6ac62b450e179e408d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2757096 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* TCPMv2: Debounce Vbus loss when FRS is enabledDiana Z2021-03-161-6/+43
| | | | | | | | | | | | | | | | | A hub may send a Fast Role Swap signal when Vbus is less than vSafe5V, so allow a 5ms debounce after Vbus loss for the signal to come in before we declare the connection detached. BRANCH=None BUG=b:180453483 TEST=on voxel, confirm FRS behaves normally Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: If56106660c0a2bf82e28b91129bc9dd367ebc8fe Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2718838 Tested-by: Eric Herrmann <eherrmann@chromium.org> Reviewed-by: Eric Herrmann <eherrmann@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* USB4: Reset mux, retimer and USB4 SM on exit mode requestAyushee Shah2021-03-162-0/+12
| | | | | | | | | | | | | | | | When exiting out of USB4 mode, reset the USB4 state machine and set the retimer and the mux to disconnect state followed by USB mode. BUG=b:181286325 BRANCH=None TEST=Able to re-enter into USB4 mode on warm reboot Signed-off-by: Ayushee Shah <ayushee.shah@intel.com> Change-Id: Icdc520aa221a9276466fafb885a6d86e893b7284 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2727628 Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
* zephyr: Disable duplicate line endingsKeith Short2021-03-161-2/+6
| | | | | | | | | | | | | | | | | | The Zephyr UART shell already converts '\n' line endings to '\r\n', and does not provide an API to override this behavior. Disable the legacy Chromium EC printf output from also converting '\n' to '\r\n'. BUG=b:182839302 BRANCH=none TEST=firmware_FAFTSetup detects that a Chrome EC is present Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: I0347e35c5237d7deb475aee1780978d719d218a1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2762531 Commit-Queue: Simon Glass <sjg@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
* zephyr: Fix recovery modeKeith Short2021-03-161-1/+1
| | | | | | | | | | | | | | | | | | | The Zephyr initialization was missing a call to lpc_int_mask(), which caused the detected recovery event to be ignored. Add this call before keyboard_scan_init() to match Chromium EC initialization. Note - this requires CL:2731180 for recovery mode be detected correctly. BUG=b:182808955 BRANCH=none TEST=zmake testall TEST=Press recovery combo, verify depthcharge starts recovery mode. Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: If03a837208d6fc025aef1359e72c09fcf39b5656 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2760805 Commit-Queue: Simon Glass <sjg@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
* virtual_battery: bug fix in reading SB_AVERAGE_CURRENTIkjoon Jang2021-03-151-3/+3
| | | | | | | | | | | | | | | Fix a bug from CL:2747559, virtual battery returns an error for SB_AVERAGE_CURRENT. virtual battery handler should call battery_get_avg_current(), not battery_get_avg_voltage(). BRANCH=none BUG=b:170921599 TEST=read current_avg knob in kukui Signed-off-by: Ikjoon Jang <ikjn@chromium.org> Change-Id: I90c26a8e1d4fa6faccc0166b9f7b63fca9baef51 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2751320 Reviewed-by: Ting Shen <phoenixshen@chromium.org>
* ocpc: Use desired current from charger taskAseda Aboagye2021-03-121-5/+5
| | | | | | | | | | | | | | | | | | | | | OCPC was directly querying the desired battery current instead of honoring the request from the charger task by mistake. This commit fixes that and makes sure that we don't set our current target from the desired battery current directly. BUG=b:180710082 BRANCH=dedede TEST=Build and flash sasuke, charge from C1, verify that desired charge profile is adhered to. Signed-off-by: Aseda Aboagye <aaboagye@google.com> Change-Id: I6d59babcad891fd09ab9a4fc5641e6d152223b74 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2740572 Tested-by: YongBeum.Ha <ybha@samsung.corp-partner.google.com> Reviewed-by: YongBeum.Ha <ybha@samsung.corp-partner.google.com> Reviewed-by: Diana Z <dzigterman@chromium.org> Auto-Submit: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Diana Z <dzigterman@chromium.org>
* TCPMV2: Add explicit setting of VPD VDO CT CurrentSam Hurst2021-03-121-2/+8
| | | | | | | | | | | | | | | | | | Add the capablility to explicity set a CTVPDs VDO current. BUG=b:165934405 BRANCH=none TEST=make runtests Verified that returned VDO from chocodile_vpdmcu was correct. Signed-off-by: Sam Hurst <shurst@google.com> Change-Id: I2292024986fa89b228b56678d61d1aef2866c817 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2748427 Tested-by: Sam Hurst <shurst@google.com> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Sam Hurst <shurst@google.com>
* zephyr: add DPTF supportKeith Short2021-03-122-0/+5
| | | | | | | | | | | | | | | | | | | | | | Add a Kconfig option to enable DPTF support. Adds support for the following ACPI entries: EC_ACPI_MEM_FAN_DUTY (0x04) EC_ACPI_MEM_TEMP_ID (0x05) EC_ACPI_MEM_TEMP_THRESHOLD (0x06) EC_ACPI_MEM_TEMP_COMMIT (0x07) BUG=b:179886912 BRANCH=none TEST=zmake testall TEST=Boot zephyr-ec on Volteer, observe that ACPI warnings for ignored read/writes for DPTF commands are fixed. Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: I40cbe79e57c3d4687d828ec46fe0d51034e96bfc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2757028 Reviewed-by: Simon Glass <sjg@chromium.org> Commit-Queue: Simon Glass <sjg@chromium.org>
* TCPMv2: Add support for disabling type-2 BIST modeScott Collyer2021-03-121-0/+6
| | | | | | | | | | | | | | | | | | | | | | This CL adds a TCPCI method to disable BIST mode for the case where the TCPC does not handle the duration automatically. This is required for the ucpd driver as once type-2 BIST mode is started, the ucpd peripheral needs to be reset to stop. This CL also reduces the timer value from 60 msec to 55 msec to ensure that there is enough time for BIST to be stopped and still be in spec. BUG=b:182436876 BRANCH=None TEST=verifed on Quiche that when type-2 BIST is started then it stops when the timer in PE expires. This fixes TDA.2.1.1.1: BMC-PHY-TX-EYE Signed-off-by: Scott Collyer <scollyer@google.com> Change-Id: I59ee7ac0dead09ac3a1b5783cfa3fe9db238eb7e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2660803 Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Scott Collyer <scollyer@chromium.org>
* TCPMv2: Detach before disabling PDAbe Levkoy2021-03-121-0/+1
| | | | | | | | | | | | | | | | Set TC state as if it were entering an Unattached state when entering an open state, so that accesses to TC state during open states return coherent results. BUG=b:182401047 TEST=Run ectool typecstatus with PD suspended; events are cleared BRANCH=firmware-volteer-13672.B-main Change-Id: I17d64459452c2671dddd8f4b6ff11124c09ace72 Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2752798 Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Diana Z <dzigterman@chromium.org>
* charger: Add new APIs for measured charge valuesAseda Aboagye2021-03-112-3/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some of the charger ICs can provide measurements for the charge voltage and the charge current. This information is needed by the OCPC module. Previously, the charge_get_current() and charge_get_voltage() functions were modified to provide this information. However, those functions are intended to provide the set voltage and current targets for the charger IC. This commit adds a new set of APIs, charge_get_actual_current() and charge_get_actual_voltage() which provides the actual charge current and voltage if the charger IC is able to provide that information. BUG=b:182018616 BRANCH=dedede TEST=Build and flash madoo, verify that `charger` EC console command shows the set current and voltage targets instead of the measured values. Check that the `chgstate` command shows the measured values for use with the OCPC module. TEST=Verify that charging from the sub board works. TEST=Verify that resistances are still calculated and seem reasonable. Signed-off-by: Aseda Aboagye <aaboagye@google.com> Change-Id: I82565d18908d9ea0f54934787897937488e280e6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2750866 Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org>
* virtual_battery: add a few more propertiesIkjoon Jang2021-03-111-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | Recent version of kernel sbs-battery driver has properties currently unsupported by EC.This patch adds 4 more properties to remove annoying error messages from console: "power_supply sbs-12-000b: driver failed to report xxx" in kernel, "[3927380.033752 Unhandled VB reg 1b" in EC console. New properties added : - SB_AVERAGE_CURRENT(0xb): involves i2c transaction - SB_MAX_ERROR(0xc): returns a constant 3% - SB_CHARGING_CURRENT(0x14), SB_CHARGING_VOLTAGE(0x15): returns existing battery params BRANCH=none BUG=b:170921599 TEST=read properties from sbs sysfs knobs (current_avg capacity_error_margin constant_charge_current_max constant_charge_voltage_max) Change-Id: I681006899969da8466730eda155df935af22994f Signed-off-by: Ikjoon Jang <ikjn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2747559 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* charge_state_v2: Guard system_hibernate call with CONFIG_HIBERNATEFurquan Shaikh2021-03-101-2/+4
| | | | | | | | | | | | | | | | | | | | | This change guards the call to `system_hibernate` with IS_ENABLED(CONFIG_HIBERNATE). This is to ensure that boards are not forced to provide the implementation of `system_hiberate` if CONFIG_HIBERNATE is not selected. It allows early bring up boards to enable charger functionality without enabling hibernation at the same time. BUG=b:173575131 BRANCH=None TEST=make -j buildall Signed-off-by: Furquan Shaikh <furquan@google.com> Change-Id: Idcccd3904e9b25f6aa4e06dc90a4845a1a87b2c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2748034 Auto-Submit: Furquan Shaikh <furquan@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Furquan Shaikh <furquan@chromium.org> Tested-by: Furquan Shaikh <furquan@chromium.org>
* battery: add default battery_get_avg_xxx()Ikjoon Jang2021-03-101-0/+10
| | | | | | | | | | | | | | | | | | To add new SB_AVERAGE_CURRENT property to virtual battery, it needs to use battery_get_avg_current() to get average current values. This patch adds default functions returning error for platforms without battery_avg_xxx() implementations. BRANCH=none BUG=b:170921599 TEST=read properties from sbs sysfs knobs (current_avg capacity_error_margin constant_charge_current_max constant_charge_voltage_max) Signed-off-by: Ikjoon Jang <ikjn@chromium.org> Change-Id: I2dcad27e0c5148de9cacb003c343be4c75609c42 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2748195 Reviewed-by: Ting Shen <phoenixshen@chromium.org>
* zephyr: npcx: add read & write reset flag functionWealian Liao2021-03-101-12/+0
| | | | | | | | | | | | | | This CL adds chip_save_reset_flags() & chip_read_reset_flags(). Also, fulfill the system_reset() BUG=b:176523207 BRANCH=None. TEST=check 'reboot wait-ext' will wait 10s Signed-off-by: Wealian Liao <whliao@nuvoton.corp-partner.google.com> Change-Id: Idb9c2e90e8ad5e8a989f33ac904c3b778b8f48e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2731179 Reviewed-by: Keith Short <keithshort@chromium.org>
* USB4: For AP mode entry, add support for active cablesAyushee Shah2021-03-102-18/+37
| | | | | | | | | | | | | | | | | | For AP mode entry, request to enter Thunderbolt cable mode entry prior to entering USB4 mode if - 1. Thunderbolt Mode SOP' VDO active/passive bit (B25) is TBT_CABLE_ACTIVE or 2. It's an active cable with VDM version < 2.0 or VDO version < 1.3 BUG=b:181286325 BRANCH=None TEST=Able to enter USB4 mode with LRD cable Signed-off-by: Ayushee Shah <ayushee.shah@intel.com> Change-Id: Ie223fa3d95c2357a0e50aeea93444e6f7639cc3f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2724653 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* USB charger: Ensure BC 1.2 suppliers are cleared on PR swapDiana Z2021-03-101-0/+4
| | | | | | | | | | | | | | | | | | | | When a type-c port swaps to become the source, it is no longer valid to consider charging from any BC 1.2 based suppliers on that port. Clear out these chargers so the charge manager won't select them from an overridden port. BRANCH=None BUG=b:174334068 TEST=on galtic, connect to another chromebook and ensure galtic is the UFP. Run swaps back and forth, ensuring that "ectool usbpdpower" correctly reflects our charging state. Also connect a USB-A to C cable and ensure charging occurs. Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Iaaa72b715909d1b653dde6d06b6ba026b768fe3c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2733454 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
* TCPMv2: Start Error Recovery when errant FRS signal comes inDiana Z2021-03-091-1/+8
| | | | | | | | | | | | | | | | If the PE layer is not currently running when a FRS signal is received, generate USB Type-C Error Recovery on the port to try getting back into a known good state. BRANCH=None BUG=b:180453483 TEST=on voxel, ensure that Vbus turned is off when FRS signals after TC detach from a device Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I185df235a5e9667db73869b07d0c89afaf0d9b67 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2718837 Reviewed-by: Scott Collyer <scollyer@chromium.org>
* TCPMv2: Add PD interface to asynchronously request TC Error RecoveryDiana Z2021-03-092-0/+21
| | | | | | | | | | | | | | | | | If a condition is reached outside the PD task which requires USB Type-C Error Recovery, it can now use pd_set_error_recovery() to request that the PD task execute this. Note that this will return before the error recovery has completed, which is in contrast to the suspend port behavior. BRANCH=None BUG=b:180453483 TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I487e0da3ef65c201ff406500f0c95244b460afcb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2718836 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* TBT/USB4: Add support for non-Thunderbolt typec cablesAyushee Shah2021-03-091-9/+35
| | | | | | | | | | | | | | | | | | | | Passive cables that don't support Intel SVID should enter into Thunderbolt/USB4 mode at speed from Discover Identity SOP', USB Highest Speed field and and active cables that don't support Intel SVID shouldn't enter into Thunderbolt mode. Ref: TBT4 PD Discovery Flow Application Notes Revision 0.9, Figure 2 BUG=b:180950931 BRANCH=None TEST=1. With USB4 Gen3 cables not supporting Intel SVID, able to enter into USB4/TBT mode at 40Gbps. 2. With USB4 Gen 2 cables not supporting Intel SVID, able to enter into USB/TBT mode at 20Gbps. Change-Id: I2c94cf84706dc345306a038b15f49b70aa13515a Signed-off-by: Ayushee Shah <ayushee.shah@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2733450 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* vboot_hash: Add watchdog reloadsKeith Short2021-03-091-0/+17
| | | | | | | | | | | | | | | | | | | | When neither CONFIG_SHA256_HW_ACCELERATE nor CONFIG_SHA256_UNROLLED are enabled, calculating the hash can trip the watchdog. Add watchdog reloads at a rate of 1/2 the watchdog period when both these options are disabled. BUG=b:182208446 BRANCH=none TEST=zmake testall TEST=Boot zephyr-ec on Volteer, powerdown AP and observe watchdog timeouts are fixed Signed-off-by: Keith Short <keithshort@chromium.org> Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: I6170b457c91f3247adf9ad47cd7e93b128a1d13b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2744356 Reviewed-by: Yuval Peress <peress@chromium.org>
* PCHG: Handle reset eventDaisuke Nojiri2021-03-091-9/+39
| | | | | | | | | | | | | | | | | | | | Currently, PCHG assumes PCHG chips are reset only on POR and ignores reset events. This can cause the state machine to be in an unexpected state when a reset happens asynchronously. This patch allows PCHG to handle chip reset events. It also makes the task explicitly reset PCHG chips at start-up so that everything will start in known & clean states. BUG=b:181745891,b:181036152,b:173235954 BRANCH=trogdor TEST=Verify PCHG behaves expectedly across cold reset, warm reset, suspend & resume. Repeat the test with and without stylus. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: Ia3dd1fe7ebc8dd6f4ee8149a4c25918922143fc3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2741282 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>