summaryrefslogtreecommitdiff
path: root/common
Commit message (Collapse)AuthorAgeFilesLines
* chgstv2: Check string validityreno.wang2021-03-301-0/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | Battery gauge follow SMBus SPEC and SMBus SPEC define cumulative clock low extend time for both controller (master) and peripheral (slave). However, I2C doesn't. Regarding this issue, we observe EC sometimes pull I2C CLK low a while after EC start running. Actually, we are not sure the reason until now. If EC pull I2C CLK low too long, it may cause battery fw timeout because its cumulative clock extend time is over 25ms. When it happened, battery will release both its CLK and DATA and reset itself. So, EC will get 0xFF when EC keep reading data from battery. Battery static information will be unreliable and need to be updated. This change is improvement that EC should retry if battery string is unreliable. BUG=b:181639264 BRANCH=dedede TEST=make -j BOARD=boten, verify if EC retry to read battery static info. Signed-off-by: reno.wang <reno.wang@lcfc.corp-partner.google.com> Change-Id: I488fde8aae05414026e6993d7606fc02499fdf3b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2791084 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
* fpsensor: Enable -WvlaTom Hughes2021-03-301-4/+17
| | | | | | | | | | | | | | | | Ideally this should be enabled for all the EC code, but that requires making more changes. For now enable it for the fingerprint sensor code to make sure we don't accidentally introduce variable length arrays. BRANCH=none BUG=b:172020413 TEST=make buildall Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I80fe4acade2c84886142ef795e54be004d1663be Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2792699 Commit-Queue: Yicheng Li <yichengli@chromium.org> Reviewed-by: Yicheng Li <yichengli@chromium.org>
* common: body_detection: re-enable body_detection in S0Ching-Kang Yen2021-03-291-3/+16
| | | | | | | | | | | | | | | | | | | | The powerd will enable the body_detection once after rebooting, but not after resuming. Because we disable the body_detection in S3, we should re-enable the body_detection in S0. BRANCH=trogdor BUG=b:123434029 TEST=powerd_dbus_suspend; ectool motionsense list_activities; see if body_detection is enabled. TEST=make buildall; Signed-off-by: Ching-Kang Yen <chingkang@chromium.org> Change-Id: Idb06888d9b4ec0eca994201f7fbd646f37c2c371 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2752573 Commit-Queue: Ching-Kang Yen <chingkang@chromium.org> Tested-by: Ching-Kang Yen <chingkang@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* common: body_detection: using bypass_fifo flagChing-Kang Yen2021-03-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Originally, the body_detection will set MOTIONSENSE_SENSOR_FLAG_WAKEUP when changing state, which disable suspension of device. Thus, there was a commit [crrev.com/c/2631887] that just simply unset the MOTIONSENSE_SENSOR_FLAG_WAKEUP, which make body_detection not work properly. So, this commit will resolve the problem by setting the BYPASS_FIFO flag. BRANCH=None BUG=b:123434029 BUG=b:176399952 TEST=powerd_dbus_suspend # See if the device wake up after suspend TEST=make buildall; Signed-off-by: Ching-Kang Yen <chingkang@chromium.org> Change-Id: Ia911f4b27c15891d4e04eedbd524d019e0f334f0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2780862 Commit-Queue: Ching-Kang Yen <chingkang@chromium.org> Tested-by: Ching-Kang Yen <chingkang@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* Revert "common: body_detection: prevent AP from unexpected waking up"Ching-Kang Yen2021-03-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit bca7737997eecb517dbbc94fd95d034f0f5cde56. Reason for revert: This commit is just a workaround, and causes another problem. The actual fix will be in the following commit. Original change's description: > common: body_detection: prevent AP from unexpected waking up > > Current body_detection will make AP resume after enter S3. Cause the AP > wake up in a short time after suspend. > This CL will prevent this from happening. > > BRANCH=None > BUG=b:176399952 > TEST=powerd_dbus_suspend # See if the device wake up after suspend > > Signed-off-by: Ching-Kang Yen <chingkang@chromium.org> > Change-Id: Id208800a66e4e2d433a555210ece50af85c908ec > Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2631887 > Reviewed-by: Wai-Hong Tam <waihong@google.com> BRANCH=None BUG=b:176399952 TEST=None Cq-Depend: chromium:2780862 Signed-off-by: Ching-Kang Yen <chingkang@chromium.org> Change-Id: I904ff718ff41336dca3c85c99a424a69483740f5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2721328 Reviewed-by: Wai-Hong Tam <waihong@google.com> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* common: motion_sense: Prevent on/off body from waking up deviceGwendal Grignou2021-03-292-7/+25
| | | | | | | | | | | | | | | | | | | | Introduce a new flag: BYPASS_FIFO to raise an interrupt to the AP when an event is sent. It is not as strong as WAKEUP, as it does not wake up the AP. BYPASS_FIFO must be set when WAKEUP is set. It is applied to sync sensor as well as gesture/activity sensor. BUG=b:123434029 BRANCH=trogdor TEST=Compile Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Change-Id: Id5aba71e6d11ef31f7fa2c67ba2e07178d088b1b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2780834 Reviewed-by: Ching-Kang Yen <chingkang@chromium.org> Tested-by: Ching-Kang Yen <chingkang@chromium.org> Commit-Queue: Ching-Kang Yen <chingkang@chromium.org>
* common/battery: Provide function to lower input voltagePatryk Duda2021-03-291-0/+82
| | | | | | | | | | | | | | This patch introduces generic version of function that sets voltage limit when chipset is off and battery is fully charged. BUG=b:182546058 BRANCH=none TEST=make -j buildall Signed-off-by: Patryk Duda <pdk@semihalf.com> Change-Id: Ib7606c8d1ab3fe1dc650a3abcef9ebc207335ab5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2773218 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* TCPMv2: Call debug detach on toggle changesDiana Z2021-03-261-0/+7
| | | | | | | | | | | | | | | | | | | When our power state changes partway through a debug connection starting, we may end up transitioning straight from a source to a sink role without calling the debug detach routine. Ensure that dual role changes call the debug detach when forcing state changes between source and sink, where we were not previously Attached. BRANCH=None BUG=b:183619502 TEST=on galith, firmware_UserRequestRecovery can pass Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Id2214487be9be4209dbd9bece94492bc4ac9c05e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2786068 Reviewed-by: Henry Sun <henrysun@google.com> Commit-Queue: Henry Sun <henrysun@google.com> Tested-by: Henry Sun <henrysun@google.com>
* 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>