summaryrefslogtreecommitdiff
path: root/common
Commit message (Collapse)AuthorAgeFilesLines
* usb_pe_drp: new unit test with mocksPaul Fagerburg2020-08-316-8/+288
| | | | | | | | | | | | | | | | | | | Add a new unit test for usb_pe_drp with mocks for the various subsystems that it will use. The fake_prl module is already essentially a mock for the PRL layer, so just move it into the mocks directory and make it available as mock to other tests. BUG=b:163421994 BRANCH=None TEST=`make runhosttests` succeeds Signed-off-by: Paul Fagerburg <pfagerburg@google.com> Change-Id: I2aea3fa0694e8d9e6bae1f47516cb4d5d2a1e714 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2364050 Tested-by: Paul Fagerburg <pfagerburg@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Paul Fagerburg <pfagerburg@chromium.org>
* eve: Move board level TCPC init to happen in pd_task initDuncan Laurie2020-08-311-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When the board level TCPC run as an init hook it will frequently lead to an EC reset when we are trying to recovery a disconnected battery, potentially even a reboot loop with the most unlucky timing. If we instead call it from the pd_task before tcpc_init is called then the board init hook can stall the pd_task init until the battery is out of disconnect mode, or giving up after 2 seconds in case the battery never seems to recover. This accomplishes two goals: ensure the PD chips are not reset until the battery is out of disconnect and delay start of the pd_task (and PD negotiation) until the battery is out of disconnect state. With this change I never see an EC reset when recovering from a disconnected battery state. BUG=b:63957122 BRANCH=eve TEST=manual testing on Eve with 50+ battery disconnect and battery cutoff cycles to ensure it never triggers an unexpected EC reset. Change-Id: Ie1604e82916ea203a32cbdde98f6697e344bba4c Signed-off-by: Duncan Laurie <dlaurie@google.com> Reviewed-on: https://chromium-review.googlesource.com/592716 Reviewed-by: Furquan Shaikh <furquan@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2320248 Commit-Queue: Patryk Duda <pdk@semihalf.com> Tested-by: Patryk Duda <pdk@semihalf.com> Reviewed-by: Jett Rink <jettrink@chromium.org>
* fpsensor: Run maintenance when in maintenance modeTom Hughes2020-08-312-0/+8
| | | | | | | | | | | | BRANCH=none BUG=b:76037094 TEST=make buildall -j Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Ibe8649c3cf77ef4542b5fc46d7df5eee03293b56 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2364755 Commit-Queue: Craig Hesling <hesling@chromium.org> Reviewed-by: Craig Hesling <hesling@chromium.org>
* power_button: Add CONFIG_POWER_BUTTON_TO_PCH_CUSTOMEdward Hill2020-08-291-1/+4
| | | | | | | | | | | | | | | Allow board to provide board_pwrbtn_to_pch function to override the default behavior of gpio_set_level(GPIO_PCH_PWRBTN_L, level) as the means for asserting power button signal to PCH. BUG=b:164921478 BRANCH=zork TEST=power button timing Signed-off-by: Edward Hill <ecgh@chromium.org> Change-Id: I8f5ffb2759318fdc941155b60be8bf4aa7dd4771 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2378557 Reviewed-by: Furquan Shaikh <furquan@chromium.org>
* driver: add ICM-426xx driver supportJean-Baptiste Maneyrol2020-08-291-0/+1
| | | | | | | | | | | | | | | Add ICM-426xx accel/gyro driver code. BUG=chromium:1117541 BRANCH=None TEST=ectool motionsense fifo_read && tast run hardware.SensorRing Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Change-Id: I83fe48abc6aa9cde86576a777ac4272d90fac597 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2317888 Reviewed-by: Gwendal Grignou <gwendal@chromium.org> Commit-Queue: Gwendal Grignou <gwendal@chromium.org> Tested-by: Gwendal Grignou <gwendal@chromium.org>
* TCPMv2: Send SOP'/SOP'' VDM only when the port is VCONN srcAyushee2020-08-282-1/+77
| | | | | | | | | | | | | | | | | | | | | | According to USB PD spec, section 2.5.4, only VCONN source can communicate with the cable plug. This CL checks if the port is the VCONN before sending SOP'/SOP'' messages. If there is a VCONN source failure, port retries swapping the VCONN times before marking the VDM as failed/naked. The CL also enables falling back to DP mode in case enter mode thunderbolt fails. BUG=b:148528713 BRANCH=None TEST=Tested on volteer, the port sends SOP'/SOP'' VDMs to the cable only if it's the VCONN source Signed-off-by: Ayushee <ayushee.shah@intel.com> Change-Id: I5880104a7a42b3e7de9e472affd41e937d36f9a5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2368066 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* TCPMv2: set VDM response buffer and lengthli feng2020-08-281-13/+30
| | | | | | | | | | | | | | | | | | | Pass tx_emsg[port].buf to VDM response implementation functions Convert data objects count to bytes VDM header in VDM response message should not use USB_VID_GOOGLE as SVID to respond to all requests. Save SVID from received request and compose response VDM header with this SVID. BUG=b:148528713,b:157163664 BRANCH=none TEST=Connect volteer to Gatkex DFP port, with CL:2370045, check VDM response messages from Volteer have correct contents. Signed-off-by: li feng <li1.feng@intel.com> Change-Id: I7403af1449abfa4ebf6b43ded457e3654396aadb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2368067 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* TCPMv2: handle un- and supported auto toggle TCPCRuibin Chang2020-08-281-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | This CL changes for both unsupported and supported auto toggle TCPC on a board: 1.board level enable CONFIG_USB_PD_TCPC_LOW_POWER: Exit LPM state for unsupported auto toggle TCPC port, when drp state is TOGGLE_ON in S0. 2.board level enable CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE: Don't transit to TC_DRP_AUTO_TOGGLE state for unsupported auto toggle TCPC port. BUG=none BRANCH=none TEST=on board drawcia, check unsupported auto toggle TCPC port: 1.connect with adapter/dongle, pd state to SNK/SRC_Ready during G3 -> S0. 2.shut down to G3, connect with adapter and pd state to SNK_Ready. Signed-off-by: Ruibin Chang <ruibin.chang@ite.com.tw> Change-Id: Ic6afc84df1564b2cb19a9032bba0752091cbf7a0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2362371 Tested-by: Ruibin Chang <Ruibin.Chang@ite.com.tw> Reviewed-by: Diana Z <dzigterman@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Ruibin Chang <Ruibin.Chang@ite.com.tw>
* Charger: Add chgnum parameter to OTG set functionsDiana Z2020-08-273-11/+11
| | | | | | | | | | | | | | | | Add the charger number as an input for setting OTG output current and enabling it, both in the charger driver and in charge_set_output_current_limit(). Also add a clarifying note about the intent of CHARGER_SOLO. BRANCH=None BUG=b:147440290 TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I7656c19a87d8216f5efc72dcffa6d638064d3e2f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2376469 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* OCPC: Assume port == chgnum when checking OTGDiana Z2020-08-271-0/+3
| | | | | | | | | | | | | | | Since OCPC has one charger chip per port, it can be assumed in the charger_is_sourcing_otg_power() function that the port will be the same as the charger number with this config enabled. BRANCH=None BUG=b:147440290 TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Iff5130e9ac7c268d38fe75eb3eb1c9ea5864abd4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2376468 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* system_is_locked: Use static variable to track stateDuncan Laurie2020-08-271-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | When CONFIG_SYSTEM_UNLOCKED is not defined the function to check if flash is write protected (flash_get_protect()) can take up to 7ms to execute, and this function is called up to 18 times when booting from RO. Use a static variable to track the status so we do not spend so long executing this one function. Without this change I would regularly see a PD hard reset when booting without a battery and the system would fail to boot. BUG=b:63957122 BRANCH=eve TEST=manual testing to reliably boot without a battery on Eve Change-Id: I806a215b5745b41ce0d99aeb6853ebfecb0cb7d1 Signed-off-by: Duncan Laurie <dlaurie@google.com> Reviewed-on: https://chromium-review.googlesource.com/582542 Reviewed-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Furquan Shaikh <furquan@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2320002 Tested-by: Patryk Duda <pdk@semihalf.com> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Patryk Duda <pdk@semihalf.com>
* hack: temporarily work around TX_COMPLETE failureJett Rink2020-08-271-2/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After we removed the retry logic in the PRL layer, we uncovered an issue that was being masked. On Delbin, the state machine is not receiving that the PD messages (namely Request) is being sent successfully. We get neither success or failure within 100ms. We still need to figure out and fix this the root cause. This change just assumes that any sent PD traffic is successful after 100ms (instead of a failure) for Delbin boards only. There is an upcoming build for Delbin that we will have power on issues if we don't add some kind of power work around. This patch will not allow the USB PD stack on Delbin to work properly in all scenarios; this patch only aims to ensure that we can get power to the device to test other non-PD functionality. This CL should be reverted within a two week time frame. BRANCH=none BUG=b:164154200 TEST=Delbin can power on Signed-off-by: Jett Rink <jettrink@chromium.org> Change-Id: If6dce35dfd78ee3a70e6216a7b6bf62d3ded5646 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2376477 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Anson Tseng <ansontseng@google.com> Tested-by: Michael5 Chen <michael5_chen1@pegatron.corp-partner.google.com>
* CBI: Validate data size of input from hostDaisuke Nojiri2020-08-271-0/+4
| | | | | | | | | | | | | | | | | | | | Currently, the size of input data is not verified. This can cause read overflow in cbi_set_data. This patch makes the host command handler validate the input data size. BUG=chromium:1114458 BRANCH=none TEST=cros_fuzz --board=amd64-generic reproduce \ --fuzzer ec_host_command_fuzzer \ --testcase ...ec_host_command_fuzzer-5111452783935488 \ --package chromeos-ec --build-type asan Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: Ia3e03cd6bb857e0fa594de9d8cc66d8788d6dcd8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2378203 Reviewed-by: Jett Rink <jettrink@chromium.org>
* Charger: Call discharge on AC for all chargersDiana Z2020-08-271-7/+9
| | | | | | | | | | | | | | | This change adds a loop to the common charger driver to set discharge on AC for all chargers, since it's unlikely a caller of this API would only want this feature enabled for a single port. BRANCH=None BUG=b:164256610 TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Ib23a93259a630016cb0f1384a6fc2b19b2baafb1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2375725 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* TCPMv2: re-enable GetSnkCap call for allDenis Brockus2020-08-271-67/+99
| | | | | | | | | | | | | | | | | | | | | | | | | | The problem was a discarded SendSrcCap message that happened around the same time as the GetSnkCap. GetSnkCap timedout and did what it was supposed to do but the SendSrcCap locked up waiting for the message to transfer before it started the timer to allow it to time out. Never would happen. Built in a framework to track the current DPM request to make discard redirections easier to determine. Also good for re-queuing DPM requests that are discarded. BUG=b:165822172 BRANCH=none TEST=DUT-DUT PR_Swap Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I8854ac745d4489125c84b7e617d5fa1a94e70e51 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2370747 Tested-by: Denis Brockus <dbrockus@chromium.org> Auto-Submit: Denis Brockus <dbrockus@chromium.org> Commit-Queue: Jett Rink <jettrink@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
* TCPMv2: Modal Operations should clear in dfp_discovery_initDenis Brockus2020-08-261-0/+2
| | | | | | | | | | | | | BUG=b:165983983 BRANCH=none TEST=dock specified in bug should be able to PR_Swap Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: Ifaccba2d741ed066e6bafc95c7e604b8f8dcfb17 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2373322 Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Denis Brockus <dbrockus@chromium.org>
* ocpc: Check CFET status before changing VSYSAseda Aboagye2020-08-261-0/+29
| | | | | | | | | | | | | | | | | | | | | | | | If the CFET is disabled, then the charging feedback loop is broken and any further adjustments of VSYS will have no effect on the charging current. Therefore, the system should not try to make any VSYS adjustments while this is occurring. This commit causes the the OCPC loop to check if the CFET is disabled before deciding to adjust VSYS or not. BUG=b:160918663 BRANCH=None TEST=Build and flash waddledee, charge DUT thru sub board until battery toggles the CFET, wait until the toggling ceases, verify that VSYS was not changed during that time. Signed-off-by: Aseda Aboagye <aaboagye@google.com> Change-Id: I7c0e5dce277118600b8f3120a6637938645db6ec Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2370044 Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Auto-Submit: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* battery_fuel_gauge: Add check for CFET statusAseda Aboagye2020-08-261-14/+54
| | | | | | | | | | | | | | | | | | | This commit adds a function that allows the system to check the if the charge FET (CFET) is disabled or not. BUG=b:160918663 BRANCH=None TEST=Build and flash waddledee; cutoff battery, revive system, verify that "found batt in disconnect" statements are still found. TEST=Add other code, verify that CFET status is able to be retrieved. Signed-off-by: Aseda Aboagye <aaboagye@google.com> Change-Id: I899070e50a38499708a367bba6b5f502b0232672 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2368071 Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Auto-Submit: Aseda Aboagye <aaboagye@chromium.org>
* usb_mux: move usb_mux_set_safe_mode()Keith Short2020-08-243-19/+15
| | | | | | | | | | | | | | Move usb_mux_set_safe_mode() definition into usb_common.c so it's available to the test framework. BUG=none BRANCH=none TEST=make buildall Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: I789a470468ae441e366afbf94ce3c29db526dfd8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2370409 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* TCPMv2: Don't interrupt RX/TX Extended Chunked Msg sequenceSam Hurst2020-08-222-2/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Delay sending a new message during the reception or transmitting of Chunked messages. BRANCH=none BUG=b:161836223 TEST=make -j buildall manual: Transmitted an extended message and verified that the sequence was not interrupted by attempting to send a VDM message. Without patch Chunked message request that was interrupted. 20-08-14 10:46:13.473 C1: RECV 9a9f/1 [0]00008c00 20-08-14 10:46:13.494 C1: RECV 9c9f/1 [0]00009400 20-08-14 10:46:13.516 C1: RECV 9e9f/1 [0]00009c00 20-08-14 10:46:13.535 C1: RECV 909f/1 [0]0000a400 Try to send VDM. MSG_TYPE is corrupted, was 0x1f, now 0x0f 20-08-14 10:46:13.563 C1: RECV 928f/1 [0]0000ac00 20-08-14 10:46:13.591 C1: RECV 948f/1 [0]0000b400 20-08-14 10:46:13.618 C1: RECV 968f/1 [0]0000bc00 20-08-14 10:46:13.645 C1: RECV 988f/1 [0]0000c400 20-08-14 10:46:13.674 C1: RECV 9a8f/1 [0]0000cc00 With patch. Chunked message request was not interrupted. 20-08-14 10:50:56.052 C1: RECV 9a9f/1 [0]00008c00 20-08-14 10:50:56.075 C1: RECV 9c9f/1 [0]00009400 20-08-14 10:50:56.093 C1: RECV 9e9f/1 [0]00009c00 20-08-14 10:50:56.114 C1: RECV 909f/1 [0]0000a400 Try to send VDM. Message delayed 20-08-14 10:50:56.134 C1: RECV 929f/1 [0]0000ac00 20-08-14 10:50:56.155 C1: RECV 949f/1 [0]0000b400 20-08-14 10:50:56.175 C1: RECV 969f/1 [0]0000bc00 20-08-14 10:50:56.195 C1: RECV 989f/1 [0]0000c400 20-08-14 10:50:56.216 C1: RECV 9a9f/1 [0]0000cc00 20-08-14 10:50:56.242 C1: RECV 0c90/0 Try to send VDM. Signed-off-by: Sam Hurst <shurst@google.com>wq Change-Id: I5475792ee9f272fe4964e27839e55e3409a6a799 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2357414
* usbc: remove PD_EVENT_SM in favor of task_wakeJett Rink2020-08-213-14/+13
| | | | | | | | | | | | | | | | We have used both methods of waking up the PD tasks to process the next state: PD_EVENT_SM and TASK_EVENT_WAKE. They effectively do the same thing and it is more straightforward to only have one way to wake the task up with the sole purpose of re-evaluating the current state. BRANCH=none BUG=none TEST=No regressions on GRL testing. Signed-off-by: Jett Rink <jettrink@chromium.org> Change-Id: I0fa79b82223e6b97eede4130480156949d79f365 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2363466 Reviewed-by: Edward Hill <ecgh@chromium.org>
* gpio: add a gpio_or_ioex_get_level function to match the setterPeter Marheine2020-08-211-0/+8
| | | | | | | | | | | | | | Code that wants to work with either regular or IO expander GPIOs may also wish to read the current value; this function permits it. BUG=b:159051013,b:165622386 TEST=buildall BRANCH=None Signed-off-by: Peter Marheine <pmarheine@chromium.org> Change-Id: I677617621ae4964f568ad87512b372ce8a9830a1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2366455 Reviewed-by: Edward Hill <ecgh@chromium.org>
* TCPMv2: SRC->SNK PR Swap enable AutoDischarge after VbusDenis Brockus2020-08-211-15/+37
| | | | | | | | | | | | | | | | | | | A debounce was added to allow for the TCPC to get a valid Vbus but AutoDischargeDisconnect was enabled as soon as we set for the debounce. Since Vbus had a good chance of not being valid, we would get a FAULT from the TCPC indicating an Auto Discharge Disconnect failure. BUG=b:165797061 BRANCH=none TEST=DUT-DUT PR_Swap Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I897d682e405d7f2fcda4b4a36a3c1b333e8f7913 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2365253 Tested-by: Denis Brockus <dbrockus@chromium.org> Commit-Queue: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* TCPMv2: PR_Swap SRC->SNK should send PS_RDY in current AMSDenis Brockus2020-08-211-6/+16
| | | | | | | | | | | | | | | | | | The SRC->SNK PR_Swap is currently starting a new AMS for the SNK PS_RDY and this causes the partner to disconnect from the bus instead of continuing with the swap. BUG=b:165794652 BRANCH=none TEST=DUT-DUT PR_Swap Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: Id953a9b6f78057777617d06f518eb17b061b6f92 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2365057 Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Denis Brockus <dbrockus@chromium.org>
* TCPMv2: Do not send GetSnkCap if FRS is not enabledDenis Brockus2020-08-211-1/+10
| | | | | | | | | | | | | | | GetSnkCap is only needed for FastRoleSwap BUG=none BRANCH=none TEST=PR_Swap DUT-DUT testing Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I51973dfbfbfe855d1027c3b1cec35a2ba06a7b65 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2367283 Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Denis Brockus <dbrockus@chromium.org>
* usbc: wake task on every state transitionJett Rink2020-08-193-1/+11
| | | | | | | | | | | | | | | | | | Whenever we change state, we should continue to wake the USB statemachine task up until is settles into a steady state were it is waiting/polling on a timer or event. BRANCH=none BUG=b:163152687 TEST=Ran GRL PD3.0 test on Trembyle and did not see any regressions. It did make a few tests pass that were failing before due to timing issues. Signed-off-by: Jett Rink <jettrink@chromium.org> Change-Id: Idc3c1ae8d92a0f6a5cd4b82f9db6d7138d143f77 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2356954 Reviewed-by: Edward Hill <ecgh@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Diana Z <dzigterman@chromium.org>
* cleanup: update formatting for clarityJett Rink2020-08-191-11/+10
| | | | | | | | | | | | | | | Make it clear that there are multiple function calls happening instead of a single statement with multiple parameters. BRANCH=none BUG=none TEST=builds. No actual code change Signed-off-by: Jett Rink <jettrink@chromium.org> Change-Id: I1c01a40794e0c2dc08be205ac953f42bdc9298be Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2363465 Commit-Queue: Edward Hill <ecgh@chromium.org> Reviewed-by: Edward Hill <ecgh@chromium.org>
* TCPM common: Store number of Identity VDOsDiana Z2020-08-191-0/+1
| | | | | | | | | | | | | | Store the number of valid identity VDOs that were received for use later. BRANCH=None BUG=b:165264379 TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I54f991c862c4b6589edff2476a79b5c3a8b69b4b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2363416 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* common: gyro_cal: Implement gyroscope calibrationYuval Peress2020-08-184-18/+1012
| | | | | | | | | | | | | | Implement the calibration code for the gyroscope which is ported over from AOSP's https://android.googlesource.com/device/google/contexthub/+/refs/heads/master/firmware/os/algos/calibration/gyroscope/ BUG=b:138303429,b:137204366,chromium:1023858 TEST=Added unit tests BRANCH=None Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: Ic1ab2efb66565cda0a96c9c06722136fb184df77 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2244934 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* Revert "system: Clear AP_IDLE when waking up from hibernation by AC"Daisuke Nojiri2020-08-181-12/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 4aacf83506fd959d1341e29b664f6e4fe97824cb. Reason for revert: See chromium:1073960 Original change's description: > system: Clear AP_IDLE when waking up from hibernation by AC > > Currently, AP_IDLE is set when EC is left idle in G3. This makes the AP > stay off after EC wakes up from hibernation (for any wake-up source). > This makes a board require another power button press to boot the > system from hibernation. > > This change makes RO clear AP_IDLE unless AC is present. When AC is > present, EC doesn't hibernate. So, AC presence infers the EC woke > up from hibernation by AC. That is, if the system wakes up by a power > button press, AP_IDLE is cleared and AP will be turned on (unless it's > overwritten by AP_OFF). > > Tested as follows on Trembyle: > 1. Put DUT in hibernation. > 2. Wake up DUT and observe: > a. When waking up by power button, AP is turned on. > b. When waking up by lid open, AP is turned on. > c. When waking up by AC, AP is left idle. > > BUG=b:157077589, chromium:1073960 > BRANCH=none > TEST=See above. > > Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> > Change-Id: Ie5020bbe50ad489f4e3010820681cc57ff51b941 > Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2236589 Bug: b:157077589 Bug: chromium:1073960 Change-Id: Id92d0d3657a622338581cb111d3925cbc11bf168 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2363080 Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org>
* TCPMv2: Debounce VBUS on SRC to SNK swapKeith Short2020-08-181-2/+21
| | | | | | | | | | | | | | | | | Copying TCPMv1 behavior, debounce VBUS at the completion of a SRC to SNK swap to allow the TCPC/PPC to update the VBUS state following receipt of the PS_RDY message from the partner. BUG=b:162347811 BRANCH=none TEST=make buildall TEST=Force power role swaps and observe no false disconnects. Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: Ia0644cde64d14044b7e291bf582b68ac4278af0a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2363411 Reviewed-by: Denis Brockus <dbrockus@chromium.org> Commit-Queue: Denis Brockus <dbrockus@chromium.org>
* config: Require battery >5% to enable PD Try.SRCWai-Hong Tam2020-08-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Align the CONFIG_USB_PD_TRY_SRC_MIN_BATT_SOC to the value of BATTERY_LEVEL_CRITICAL, which is 5%. The BATTERY_LEVEL_CRITICAL is 5% that means EC will send battery- critical host event when the battery level <= 5%. CrOS PD policies state that the system doesn't source power to any external USB devices when AP is shutdown. So the current CONFIG_USB_PD_TRY_SRC_MIN_BATT_SOC 1% default has no point. When the battery level is <= 5%, AP should be shutdown soon and the system should not be a source, so should not enable Try.SRC. Also change the comparison from soc >= CONFIG_USB_PD_TRY_SRC_MIN_BATT_SOC to soc > CONFIG_USB_PD_TRY_SRC_MIN_BATT_SOC as the battery critical check is soc <= BATTERY_LEVEL_CRITICAL. BRANCH=None BUG=b:165057418 TEST=Plugging a PD charger to a board with the battery level very low, the system boots up (was failed), Change-Id: If6b11feacd62fd003e13b1756eb5c33d2f9bbce4 Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2360543 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* task: Change mutex_lock() assertEdward Hill2020-08-151-4/+0
| | | | | | | | | | | | | | | | | | | Instead of asserting that task_start() has not been called, just return without doing any locking. This avoids the need to fix every caller of mutex_lock() to check task_start_called(). BUG=b:164461158 BRANCH=none TEST=Esc+F3+Power enters recovery, does not assert. Signed-off-by: Edward Hill <ecgh@chromium.org> Change-Id: Ic157d7e7041185a67f257f0f5710fd02e45cd77f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2357496 Reviewed-by: Wai-Hong Tam <waihong@google.com> Tested-by: Wai-Hong Tam <waihong@google.com> Commit-Queue: Wai-Hong Tam <waihong@google.com>
* fingerprint: Stopgap to repair public buildsCraig Hesling2020-08-151-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This repairs building bloonchipper and dartmonkey builds when private lib is unavailable. There are two issues this remedies: 1) Redefinition of sensor info macros, like FP_SENSOR_RES_X 2) Undefined reference to fp_sensor_maintenance when building bloonchipper/dartmonkey non-private image. All of these issues stem from the way we handle code when HAVE_FP_PRIVATE_DRIVER is set or faked by a test. This is a fundamental issues that needs some thought and refactoring. BRANCH=none BUG=b:164174822,b:163109916, b:163411883 TEST=# With private time make buildall -j TEST=# Without private time make buildall -j TEST=# With private libs # Cherry-pick https://crrev.com/c/2357870 first, then # this patch. ./util/compare_build.sh -b all -o # This confirms that the all output binaries with private-lib # did not change at all Signed-off-by: Craig Hesling <hesling@chromium.org> Change-Id: If71e3376fb7a904b77f2fc9fc56c8e0daf54db3b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2357430 Reviewed-by: Andrew de los Reyes <adlr@chromium.org> Reviewed-by: YH Lin <yueherngl@chromium.org>
* System: Set stay-in-RO reset flag for sysjump and host commandDiana Z2020-08-141-3/+14
| | | | | | | | | | | | | | | | | | With EFS2, the EC can jump itself straight from RO to RW without AP intervention. However, sometimes the AP or a developer may want the EC to remain on RO to perform operations there. In these cases, set the reset flag to say in RO. BRANCH=None BUG=b:161887378 TEST=on waddledee, run "sysjump ro/rw" while the AP is on and confirm the AP remains on. Run "flashrom -p ec -w /tmp/ec.bin" and confirm the operation completes successfully. Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I036bd04514858a55e4e52abfc05eb67896436505 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2354742 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* sysrq: Ignore H1_EC_RECOVERY_BTN_ODLDaisuke Nojiri2020-08-141-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | On Puff, there are two signals from the recovery button. One is from the button and the other is from H1. The signal from H1 is masked by the power button and it looks asserted only after the power button is released. This makes the EC start the warm reset timer. If the user doesn't release the recovery button (as instructed) to enter the recovery mode for four seconds, the AP resets and entry to the recovery mode fails. This patch makes the EC ignore H1's signal as sysrq signal. BUG=b:163443447 BRANCH=Puff TEST=Recovery mode can be entered by keeping recovery button pressed on Duffy. TEST=Recovery button triggers sysrq. TEST=Holding recovery button for 4 seconds triggers AP reset. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I8631d5dc0da8c95eed1d740b0683aa5de7848335 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2353890 Reviewed-by: Andrew McRae <amcrae@chromium.org> Reviewed-by: Sam McNally <sammc@chromium.org>
* cleanup/usbc: organize all super states togetherJett Rink2020-08-131-27/+30
| | | | | | | | | | | | | | Like other state machine declarations, put all of the super states together to make it more clear when reading states. BRANCH=none BUG=none TEST=build and unit tests Signed-off-by: Jett Rink <jettrink@chromium.org> Change-Id: I1bb776434911d3acdb34abc64e7e8fa5f87154de Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2354193 Reviewed-by: Edward Hill <ecgh@chromium.org>
* usbc: add GEN_NOT_SUPPORTED macro for unsupported statesJett Rink2020-08-133-61/+35
| | | | | | | | | | | | | | | | | | | To enabled use of the IS_ENABLE macro we need to define some of the usb state machine states as extern variables that will never be linked. This allows the compiler to know about a state but will still fail the linking phase if the config option is not defined properly. This is just adding a convenience macro for this paradigm, not creating the paradigm itself. BRANCH=none BUG=none TEST=builds Signed-off-by: Jett Rink <jettrink@chromium.org> Change-Id: Ia19b5babd43d536f043745314481475cf25f6e01 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2353369 Reviewed-by: Edward Hill <ecgh@chromium.org>
* tcpmv2: wait before enabling HW auto toggleJett Rink2020-08-132-5/+31
| | | | | | | | | | | | | | | We need to ensure that the previous Rd or Rp has been held long enough before we transition into hardware auto toggle otherwise the first toggle might be too short and violate the DRP timing spec BRANCH=none BUG=b:163095971 TEST=Verify on scope Signed-off-by: Jett Rink <jettrink@chromium.org> Change-Id: I92e9f5ca7dbca2b347e438d774551cc11476195b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2343176 Reviewed-by: Edward Hill <ecgh@chromium.org>
* cbi: add Second Source Factory Cache (SSFC) CBI fieldMarco Chen2020-08-131-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | SSFC field will be leveraged to record what second source is used in the DUT by probing components in the factory or RMA. Firmware code should refer to this field to judge what driver should be configured for a specific component. For example, the board code can arrange what sensor driver should be set into motion_sensors array if there are multiple sources of base or lid sensor. As the definition of FW_CONFIG, it describe which "features" the firmware code should enable or disable. For example, whether lid / base sensors should be enabled or not but not care about what second source is in this DUT. BRANCH=none BUG=b:163285687 TEST=call `cbi-util` to create the cbi image with SSFC and show created content. TEST=`make buildall -j` TEST=`make runhosttests -j` Change-Id: Icb4aa00ae47ab025198e7fd5edd6aab96a4bf53e Signed-off-by: Marco Chen <marcochen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2344268 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Jett Rink <jettrink@chromium.org>
* init_rom: Add init_rom layerKeith Short2020-08-132-1/+70
| | | | | | | | | | | | | | | | | | | Create a thin init_rom layer for accessing data objects linked into the .init_rom section with the CONFIG_CHIP_INIT_ROM_REGION opton and __init_rom attribute. BUG=b:160330682 BRANCH=none TEST=make buildall TEST=Using the next CL, verify BMI260 config data can be read using both memory mapped and indirect access. Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: I6cd311637e87cd10ac394ff75c4bfc16bbade3b0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2335739 Reviewed-by: caveh jalali <caveh@chromium.org> Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Commit-Queue: caveh jalali <caveh@chromium.org>
* flash: allow programming larger EC imagesKeith Short2020-08-131-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For some ECs, the EC image size is limited by the amount of code RAM instead of 1/2 the total flash size. In this instance, there is unused flash that can be used for single use data objects. To support linking data objects into the unused flash area, increase the region size that can be programmed for RW images. Analysis of chips that are impacted by this change: Chip EC image limit New RW size limit mec1701h 188 KiB 256 KiB mec17xx_2E00 188 KiB 256 KiB npcx5m5g 96 KiB 128 KiB npcx5m6g 224 KiB 256 KiB npcx7m6f 192 KiB 256 KiB npcx7m6fb 192 KiB 256 KiB npcx7m6fc 192 KiB 256 KiB npcx7m6g 192 KiB 256 KiB npcx7m7wb 256 KiB 512 KiB npcx7m7wc 252 KiB 256 KiB Boards using other chips verified that CONFIG_RW_SIZE is the same as CONFIG_EC_WRITABLE_STORAGE_SIZE. EC_FLASH_REGION_RO isn't used by depthcharge, only EC_FLASH_REGION_WP_RO which is already set to the correct size. BUG=b:160330682 BRANCH=none TEST=make buildall Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: I84b9dc84568273e1ab1473e301d27ffd2b07ba7f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2325764 Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Reviewed-by: caveh jalali <caveh@chromium.org> Commit-Queue: caveh jalali <caveh@chromium.org>
* TCPMv2: Check discard flag before processing received messagesDiana Z2020-08-131-5/+17
| | | | | | | | | | | | | | | | | | | | | | | | When an outgoing message is discarded due to receiving an incoming message, the new message will arrive the same state machine cycle as the discard notification (if chunking is disabled). Child states of the sender response and VDM send parent should verify their message wasn't discarded before reading the received message. The parent will continue to handle the discard flag after the child run state. BRANCH=None BUG=b:162753650 TEST=on Volteer with chunking disabled, Gatkex creek is able to continue correctly after message discard Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I9c6343c7713351b38639668a721291eba31519bc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2350502 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Tested-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
* tcpmv2: use IS_ENABLED style codeJett Rink2020-08-121-36/+44
| | | | | | | | | | | | | | | | Make the state machine states always defined. This also makes the state number stable regardless of which config options are defined. This matches the style in other USBC state machines (e.g. PE layer) Also remove unused evt_timer BRANCH=none BUG=none TEST=builds Signed-off-by: Jett Rink <jettrink@chromium.org> Change-Id: Ifcbc6a723db07f0c1c69ecebe6a2942f5d46bafb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2343175
* mock/usb_pd_mock: remove tc functionsPaul Fagerburg2020-08-121-8/+0
| | | | | | | | | | | | | Remove tc_set_data_role and tc_set_power_role from usb_pd_mock. BUG=b:163421165 BRANCH=None TEST=`make runhosttests`, all unit tests pass Signed-off-by: Paul Fagerburg <pfagerburg@chromium.org> Change-Id: Ib380d2f04f833b58e23a16d0c6421316b72329fe Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2349282 Reviewed-by: Jett Rink <jettrink@chromium.org>
* test: Soft_Reset sent regardless of Rp valueEdward Hill2020-08-122-39/+45
| | | | | | | | | | | | | | | Add test for TD.PD.SRC3.E26.Soft_Reset sent regardless of Rp value. BUG=b:161835483 BRANCH=none TEST=make -j run-usb_tcpmv2_tcpci Signed-off-by: Edward Hill <ecgh@chromium.org> Change-Id: I972bffcb1c7a330aef4ebdff98fcd33af9a667be Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2340486 Reviewed-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Denis Brockus <dbrockus@chromium.org>
* task: Fix mutex_lock() assert (reland)Edward Hill2020-08-121-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | mutex_lock() must not be used in interrupt context. Add an assert to catch this. Also assert task_start_called() since task ID is not valid before this. Also remove an old assert since comparing id with TASK_ID_INVALID doesn't make sense. Add check for task_start_called() for NPCX flash_lock, I2C port_mutex, pwr_5v_ctl_mtx, STM32 bkpdata_write_mutex. This was submitted CL:2309057, reverted CL:2323704, submitted CL:2335738, reverted CL:2341706. BUG=b:160975910 BRANCH=none TEST=boot AP, jump to RW Signed-off-by: Edward Hill <ecgh@chromium.org> Change-Id: I0aadf29d073f0d3d798432099bd024a058332412 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2343450 Reviewed-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* ocpc: Incorporate charge IstepAseda Aboagye2020-08-121-1/+6
| | | | | | | | | | | | | | | | | | | | | Charger ICs differ in their ability to regulate down to a certain mA, therefore, the OCPC code should take this ability into account and not count it as an error if it's within the bounds of what the charger IC is capable of regulating it to. BUG=b:147440290 BRANCH=None TEST=Enable on waddledee, flash, verify that once target current is within an error bar of what the charger IC is capable of regulating to, no error is reported. Signed-off-by: Aseda Aboagye <aaboagye@google.com> Change-Id: If94a9173e27d35be81b86589c530766bfe6431a2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2336174 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Auto-Submit: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Diana Z <dzigterman@chromium.org>
* TCPMv2: handle SVIDs time out for INIT_VDM_SVIDs_RequestDenis Brockus2020-08-101-0/+18
| | | | | | | | | | | | | | | | | | | | The charger does not look like it is responding correctly to our request and a NAK should have come back. Adding in an exit routine to check for timeout to stop the spamming and allow the connection flow to continue. BUG=b:163114771 BRANCH=none TEST=Plug in the charger into a berknip Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I0ce761df7c7c6f4cdbb420f3964c7593e740d803 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2346782 Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Denis Brockus <dbrockus@chromium.org> Auto-Submit: Denis Brockus <dbrockus@chromium.org>
* TCPMv2: Downgrade cable to PD 2.0 halfway through discovery attemptsDiana Z2020-08-101-0/+17
| | | | | | | | | | | | | | | | | Since some PD 2.0 cables will GoodCRC PD 3.0 requests without replying, also assume there may be some PD 2.0 cables which may not GoodCRC PD 3.0 requests at all. Downgrade the cable revision to PD 2.0 halfway through the allowed number of discovery attempts. BRANCH=None BUG=b:154653135 TEST=on drawlat, verify cable discovery attempts with HooToo downgrade to PD 2.0 halfway through Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Ifc9128d1b8cef03235cfe7662e1f016d15f7878e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2346593 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>