summaryrefslogtreecommitdiff
path: root/common/usb_pd_protocol.c
Commit message (Collapse)AuthorAgeFilesLines
* usb: Remove invalid data role from enumJett Rink2019-10-231-3/+4
| | | | | | | | | | | | | | | | The data role as defined in the USB spec is 1 bit. Disconnected does not fit and no one is using it properly. All users of Disconnected value alias the value to DFP anyway. Just use DFP explicitly BRANCH=none BUG=none TEST=builds and runs new stack on hatch Change-Id: I5c7dddea8f34c8e3c524da8701913c87c23b42b2 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1865984
* pd: Extend READY_HOLD_OFF_US timer value for SRCScott Collyer2019-10-171-4/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | The READY_HOLD_OFF_US was set to 200 msec for both SNK and SRC connections. However, in the case of SRC, there can be a race condition with charge through hubs that initiate a power swap request and the SRC port sending the VDM discover idenity message. This CL makes the holdoff timer delay longer for SRC connections and prefixes READY_HOLD_OFF_US with SNK/SRC to differentiate the two timer values. BUG=b:140092163 BRANCH=None TEST=Tested with the AA-AM1N95W charge through hub. Verfied that this can be attached to Kohaku with external power already connected and successfully power role swap into source to charge the kohaku port. Tested 20-25 connections with no failures. Prior to this change the failure rate was 1 out of 3 attempts. Change-Id: I375415fec96baf44ecd4592033e8b44ed4616011 Signed-off-by: Scott Collyer <scollyer@google.com> Signed-off-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1776844 Tested-by: Scott Collyer <scollyer@chromium.org> Tested-by: Jongpil Jung <jongpil19.jung@samsung.corp-partner.google.com>
* pd: Prevent trasmitting messages if rx messages are pendingScott Collyer2019-10-171-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | This CL adds a check in pd_transmit to prevent sending tx messages if there are pending rx messages to be processed. This fixes an issue where a power role swap request is received, but before the accept reply can be sent a VDM discover identity message is sent which confuses the other side of the connection. BUG=b:140092163 BRANCH=None TEST=Tested with the AA-AM1N95W charge through hub. Verfied that this can be attached to Kohaku with external power already connected and successfully power role swap into source to charge the kohaku port. Tested 20-25 connections with no failures. Prior to this change the failure rate was 1 out of 3 attempts. Change-Id: Iebe53e0fc52bf817b709d58ef3e0ee7b226b0aa9 Signed-off-by: Scott Collyer <scollyer@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1799288 Reviewed-by: Jett Rink <jettrink@chromium.org> Tested-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Commit-Queue: Scott Collyer <scollyer@chromium.org>
* usb_pd: drop duplicate func get_max_request_mv()Yilun Lin2019-10-091-1/+1
| | | | | | | | | | | | | | The function is added by chromium:1737899 and is duplicate of pd_get_max_voltage(). TEST=make buildall -j BUG=None BRANCH=firmware-kukui-12573.B Change-Id: Ida1f56d108573a1776dcec8460dd48439427d10d Signed-off-by: Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1847513 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* builtin: Introduce and use inttypes.hEvan Green2019-10-051-1/+2
| | | | | | | | | | | | | | | | | | | | | In order to pass the right printf format specifiers for certain types that are compiled both in 32-bit EC and 64-bit host environments, standard macros PRIx64 and PRId64 must be introduced. These specify the correct printf format specifier in the given compilation environment for printing a 64-bit value. On the host, inttypes.h already exists. Add an inttypes.h for the EC codebase so that these macros can be used where they're needed. BUG=chromium:984041 TEST=make -j buildall BRANCH=none Change-Id: I76e3bdc88aef7da6e5234d5b86b595f7138ea9a1 Signed-off-by: Evan Green <evgreen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1819642 Reviewed-by: caveh jalali <caveh@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* host_command: Change host command return value to enum ec_statusTom Hughes2019-10-021-8/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the host command handler callback function returns an int, it's easy to accidentally mix up the enum ec_error_list and enum ec_status types. The host commands always expect an enum ec_status type, so we change the return value to be of that explicit type. Compilation will then fail if you accidentally try to return an enum ec_error_list value. Ran the following commands and then manually fixed up a few remaining instances that were not caught: git grep --name-only 'static int .*(struct host_cmd_handler_args \*args)' |\ xargs sed -i 's#static int \(.*\)(struct host_cmd_handler_args \*args)#\ static enum ec_status \1(struct host_cmd_handler_args \*args)##' git grep --name-only 'int .*(struct host_cmd_handler_args \*args)' |\ xargs sed -i 's#int \(.*\)(struct host_cmd_handler_args \*args)#\ enum ec_status \1(struct host_cmd_handler_args \*args)##' BRANCH=none BUG=chromium:1004831 TEST=make buildall -j Cq-Depend: chrome-internal:1872675 Change-Id: Id93df9387ac53d016a1594dba86c6642babbfd1e Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1816865 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* cleanup: fix byte access and ifdefs for BBRAM_PD2Jett Rink2019-09-301-3/+0
| | | | | | | | | | | | | | Ensure that PD2 is accessed as a single byte instead of 4 bytes and remove unnecessary ifdef guards in all chip implementations. BRANCH=none BUG=none TEST=builds Change-Id: I319d8d6a8456662235ab4d8dcda6bda7e8ed7c15 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1809938 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* usb_pd_protocol: add missing CPRINTF argumentCaveh Jalali2019-09-261-1/+1
| | | | | | | | | | | | | This adds the missing "port" argument to a printf. BUG=none BRANCH=none TEST=buildall passed, boots on atlas Change-Id: Ia0e27b323bf6f274efbd3498c8e7e5c7d7b81a1a Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1825875 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* cleanup: remove copy of pd_cc_state enumJett Rink2019-09-261-9/+10
| | | | | | | | | | | | | | | | | | | | | The EC command interface created a separate copy of the enum pd_cc_state. Remove the EC command version and move the pd_cc_state definition to the command interface. Also remove PD_CC_NO_UFP option as there is no difference between that value and PD_CC_NONE. Split PD_CC_DEBUG_ACC into separate UFP and DFP values for clarity. BRANCH=none BUG=none TEST=builds Change-Id: Ic8c4c5ac4dd340b1e605100e35acb147c226a455 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1825503 Reviewed-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Sam Hurst <shurst@google.com>
* USB-PD: SOP'/SOP" packet header fieldRuibin Chang2019-09-231-8/+20
| | | | | | | | | | | | | | | | | | | | SOP'/SOP" message header bit field: bit5:should reserved bit8:0b Message originated from a DFP or UFP 1b Message originated from a Cable Plug. reference: PD3.0 v2.0 spec table 6-1 message header. BUG=None BRANCH=None TEST=test on baord: reef_it8320 SRC connects to SNK via E-mark cable, sources Vconn successfully, check SOP' header bit field by Lecroy analyzer. Change-Id: Ie9b9d8507d84d5b4c694cc906eb7da8715b88a5f Signed-off-by: Ruibin Chang <Ruibin.Chang@ite.com.tw> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1725379 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* pd: Exit DP mode on sysjumpSam Hurst2019-09-171-15/+3
| | | | | | | | | | | | | | | Exits all USB PD Alternate Modes after a system jump BUG=b:140807930 BRANCH=none TEST=manual Change-Id: Ie0843e0c9f1dcacecc2109cd0565a90cfafed306 Signed-off-by: Sam Hurst <shurst@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1797661 Tested-by: Sam Hurst <shurst@google.com> Reviewed-by: Denis Brockus <dbrockus@chromium.org> Commit-Queue: Denis Brockus <dbrockus@chromium.org>
* tcpm: Hold tPSHardReset after receiving hard reset from sink deviceYilun Lin2019-09-101-4/+6
| | | | | | | | | | | | | | | | USB-PD3.0 ver1.2 "7.3.13 Sink Initiated Hard Reset" Policy Engine should wait tPSHardReset after receiving Hard Reset. TEST=Pass the USB-PD Compliance Test TDA.2.3.1.1: POW-SRC-LOAD-P-PC TDA.2.3.1.2: POW-SRC-LOAD-CP-ACC BUG=b:139914412 BRANCH=none Change-Id: I2595d9f8618de7ec85e834195d77cd9928d198f6 Signed-off-by: Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1770331 Reviewed-by: Jett Rink <jettrink@chromium.org>
* pd: USB Power Delivery State Machine based on Revision 3.0 of the spec.Sam Hurst2019-09-101-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adds Power Delivery to the TypeC state machine as detailed in Revision 3.0, Version 1.2 of the specification. This CL passes the PD2.0 compliance tests and has been tested on several devices. Some areas such as handling Electronically Marked Cable information, creation of PIDs, and Host commands will be addressed in later CLs. BUG=b:130895206 BRANCH=none TEST=manual Port 0 on Hatch was used to run this CL, merged with PD functionality, on the PD2.0 Compliance tester. All tests pass except for a few physical layer tests. The test report has been added to the bug. Atlas was verified to work with Apple, Amazon, StarTech, MKDGO and several other generic docks. Atlas was verified to work with Google's and Apple's CTVPD. Signed-off-by: Sam Hurst <shurst@chromium.org> Change-Id: Ia5e1988b0d81ec4cf9a7175e273197bd5a0865e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1737899 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org> Tested-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Denis Brockus <dbrockus@chromium.org>
* include: Move RESET_FLAG_* into ec_commands.h as EC_RESET_FLAG_*You-Cheng Syu2019-08-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | RESET_FLAGS_* are used when setting/reading the field ec_reset_flags of struct ec_response_uptime_info, which is defined in ec_commands.h. So it might be better to put those macros there. To be consistent with the other macros in the file, add "EC_" prefixes to them. BUG=b:109900671,b:118654976 BRANCH=none TEST=make buildall -j Cq-Depend: chrome-internal:1054910, chrome-internal:1054911, chrome-internal:1045539 Change-Id: If72ec25f1b34d8d46b74479fb4cd09252102aafa Signed-off-by: You-Cheng Syu <youcheng@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1520574 Tested-by: Yu-Ping Wu <yupingso@chromium.org> Commit-Ready: Yu-Ping Wu <yupingso@chromium.org> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Yilun Lin <yllin@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* tcpm: ignore repeated MessageIDYilun Lin2019-08-251-14/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Ignore repeated MessageID in TCPM rather than TCPC[1]. https://crrev.com/c/1513033 implemented the logic in TCPC, but according to spec[2], TCPC should pass repeated messages to TCPM. This CL simply moves the logic from TCPC to TCPM. [1] USB PD spec rev3.0 6.7.1.2 MessageID Counter Receiver Usage [2] USB Port Controller spec rev2.0 3.3 USB-PD Message Delivery * MessageID is not checked in the TCPC when a non-GoodCRC message is received. Retried messages that are received are passed to the TCPM via I2C BUG=b:134556286, b:129337537 BRANCH=None TEST=make buildall -j; See Krane boots; See servo_v4 boots. Ensure repeat request message triggered artificially are dropped without any side-effects. Cq-Depend: chromium:1763895 Change-Id: I362056d973a71f0940b1287511ffe9180f566fac Signed-off-by: Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1757596 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* usb: de-dup common code from old and new PD stackJett Rink2019-08-191-70/+11
| | | | | | | | | | | | | | We still need to pull out more common code between the two stacks, but this is scaffolding with a few examples. BRANCH=none BUG=b:137493121 TEST=unit tests pass Change-Id: Ibd9dda1e544e06f02aa3dde48ca7de1539700cfa Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1744655 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* usb_pd: Get USB-C cable type informationAyushee2019-08-161-0/+1
| | | | | | | | | | | | | | | Added logic to share the USB-C cable type information in host command to configure the virtual mux of Intel SOC. BUG=b:129990370 BRANCH=None TEST=Verified on Intelrvp, able to get correct USB-C cable type information Change-Id: Iee7c274d318f59a482d21b8faa56610509fbdf8e Signed-off-by: Ayushee <ayushee.shah@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1749560 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* usb_pd: Adding USB-C cable detectionAyushee2019-08-161-3/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a discover identity command is sent with a SOP prime packet, the cable plug of an emark cable responds with the cable attribute. Added a structure pd_cable that stores the cable type and and resetting it when the cable is disconnected. Also added console command that gives the type of cable connected. Host(DFP) Cable Port-Partner(UFP) -------------------------EXPLICIT CONTRACT------------------------ Discover Identity SOP -----------------------------> request | <------------------------- Discover Identity response Discover Identity SOP' ---------> request | (If Emark Cable) <------------ Discover Identity SOP' | response Store cable type | (If Non-Emark Cable) <-------------- No response | Discover SVID SOP request ------------------------------------> (Rest of the PD flow) BUG=b:129990370 BRANCH=none TEST=Verified on dragonegg, able to get cable response Change-Id: I2536cf24d58f7ee5ff462b34fc32f69d7a200d41 Signed-off-by: Ayushee <ayushee.shah@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1707851 Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* cleanup: change initializer for storm_trackerJett Rink2019-08-131-1/+1
| | | | | | | | | | | | | | | The octopus firmware branch cannot build with the { 0 } format, but it can build with {}. Since they mean the same thing, use {} everywhere. BRANCH=octopus BUG=none TEST=build on ToT and octopus branch Change-Id: I621dd89c40b8c7297db72a3093631f9aba8dd9b6 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1749551 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* usb: convert cc1 from int to enumJett Rink2019-08-091-9/+9
| | | | | | | | | | | | | | Refactor code to use proper type for cc1 and cc2 lines. BRANCH=none BUG=none TEST=builds. No functional change. Change-Id: Id292db8480920e2b191bac9d9ecc2685f61e4ea9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1744654 Tested-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org> Commit-Queue: Jett Rink <jettrink@chromium.org>
* pd: Don't request LPM in DRP_TOGGLE if cc is not openScott Collyer2019-08-081-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, LPM_REQUESTED flag is always set in the DRP_AUTO_TOGGLE state. This is true even when the next state will be SNK_DISCONNECTED or SRC_DISCONNECTED. This setting makes sense for SNK_DISCONNECTED as when the AP is not in S0, then auto toggling will be disabled so the PD state machine should remain in SNK_DISCONNECTED until something is attached. But for the transition from DRP_TOGGLE to SRC_DISCONNECTED should only happen when either an adapter gets attached while the AP is in S0, or the chipset enters S0 with an adapter already attached. This 2nd case is problematic as if LPM_REQUESTED is set and there is no CC event pending, the PD task will get suspended (wait = -1) and therefore remain in SRC_DISCONNECTED. This CL modifies the existing logic to not set LPM_REQUESTED when something is attached as given by the CC1 and CC2 values. BUG=b:137697655 BRANCH=none TEST=Tested both EC reboot and resume from suspend with a USB stick connected via a type C->A adapter and verified that the PD state machine advances to PD_STATE_SRC_DISCOVERY as expected and the USB stick enumerates. Change-Id: I6afbd642ce38134ddabd20f7dc5e15f937b9810a Signed-off-by: Scott Collyer <scollyer@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1730967 Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Furquan Shaikh <furquan@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Scott Collyer <scollyer@chromium.org>
* ec_commands: Rename 'renew' to 'live' in EC_CMD_USB_PD_CHIP_INFOKarthikeyan Ramasubramanian2019-07-201-2/+3
| | | | | | | | | | | | | | | | | | | | | | Semantics of renew field in EC_CMD_USB_PD_CHIP_INFO is changing as follows: 0 -> Return hard-coded info for Vendor ID/Product ID and cached info for the Firmware Version 1 -> Return the live chip info for Vendor ID/Product ID/Firmware Version Also rename the 'renew' field to 'live' to match the new semantics. BUG=b:128820536,b:119046668 BRANCH=None TEST=make -j buildall; Boot to ChromeOS. Change-Id: Ie3dd022336b0be5c9728bb0ebabef32b7a6b5d57 Signed-off-by: Karthikeyan Ramasubramanian <kramasub@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1617893 Tested-by: Karthikeyan Ramasubramanian <kramasub@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Karthikeyan Ramasubramanian <kramasub@chromium.org> Auto-Submit: Karthikeyan Ramasubramanian <kramasub@chromium.org>
* USB PD: Refrain from resets if battery is lowDiana Z2019-07-021-10/+95
| | | | | | | | | | | | | | | | | | | | | | This change introduces a new clause to the SNK_DISCOVERY state to prevent reset timers from starting when a battery is reporting below a configured level, which indicates the point at which the battery is capable of withstanding the potential loss of Vbus. Once the battery has charged enough, a timer for soft reset will begin to trigger PD negotiation to start over if it hasn't been able to complete. BUG=b:128935567 BRANCH=octopus TEST=verified hard reset doesn't occur on grabbiter when system is locked and coming back from battery cutoff without enough battery, verified soft followed by hard resets after the battery had charged Change-Id: Ib885d2b55acacad7ef1375572b0e6d243e639bdf Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1565147 Reviewed-by: Jett Rink <jettrink@chromium.org>
* USB PD: disable port if TCPC interrupt storm detectedJett Rink2019-06-281-2/+41
| | | | | | | | | | | | | | | | | If we get too many interrupts too fast, then we will starve the rest of the EC. Disable an overactive port for 5 seconds. BRANCH=none BUG=b:134702480,b:128701054 TEST=7-magic hub no longer watch dog resets phaser port 0, HDMI dongle plugged into port 1 still able to function while port 0 is periodically suspending Change-Id: Ic2d13ecc64990994ffc8e3fb68537aa909657745 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1650484 Tested-by: Diana Z <dzigterman@chromium.org> Reviewed-by: Edward Hill <ecgh@chromium.org>
* pd_protocol: Don't DRP toggle lower than S0.Aseda Aboagye2019-06-211-23/+99
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently our USB PD protocol stack has "low power mode" tightly coupled with PD_STATE_DRP_AUTO_TOGGLE. In addition, it has the side effect of us dual role toggling (and resolving as sources) even though we have no intention of being a source. (e.g. DRP toggle in S0, once we suspend we're still toggling, even after shutting down to S5, we're still toggling.) This commit makes it such that we not dual role toggle in those lower power states, but instead behave properly as a sink and present only the Rd's. It also fixes a bug where if a port was previously sourcing in S0 and remained sourcing in suspend, if the sink was unplugged the port would be stuck presenting Rp's until a sink was plugged and unplugged again. BUG=chromium:902437 BUG=b:119055792 BRANCH=firmware-nocturne-10984.B TEST=Flash nocturne, use twinkie verify port does not dual role toggle in suspend or off. TEST=Verify that TCPC goes into low power mode in SNK_DISCONNECTED. TEST=Verify that charging works in suspend and off. Signed-off-by: Aseda Aboagye <aaboagye@google.com> Signed-off-by: Scott Collyer <scollyer@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/1320909 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Change-Id: Ie44581a1a1a82cf29a786b57a71ce70760862ca2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1667940 Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Scott Collyer <scollyer@chromium.org> Auto-Submit: Scott Collyer <scollyer@chromium.org>
* LICENSE: remove unnecessary (c) after CopyrightTom Hughes2019-06-191-1/+1
| | | | | | | | | | | | | | | | Ran the following command: git grep -l 'Copyright (c)' | \ xargs sed -i 's/Copyright (c)/Copyright/g' BRANCH=none BUG=none TEST=make buildall -j Change-Id: I6cc4a0f7e8b30d5b5f97d53c031c299f3e164ca7 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1663262 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* USB PD: Only maintain contracts over sysjump when sinkingDiana Z2019-06-041-9/+18
| | | | | | | | | | | | | | | | | | | | | | Currently, the pd_task will attempt to maintain both source and sink contracts after an unlocked sysjump or unlocked EC reset. However, the pd_task will disable Vbus to any partners it was sourcing, causing the soft reset process to lead to a hard reset and disconnection. Since the port partner will be without Vbus and unable to respond, treat the contract as terminated and the port as the default state. BUG=b:132110509 BRANCH=octopus TEST=unlocked sysjumps with a display port dongle and hoho to ensure they were treated as disconnected, unlocked sysjumps with charger to ensure it was soft reset Change-Id: Ie477f393ea828a4e880c8e8ccbe72539e8be721a Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1639212 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* USB PD: Disable Vconn as well as Vbus on initDiana Z2019-06-041-1/+7
| | | | | | | | | | | | | | | | | | | | | | Currently, the pd_task will call a power supply reset during init which cuts Vbus to the port partner. However, on a sysjump we may still be sourcing Vconn to a partner which will leave it in an inconsistent state of having Vconn but no Vbus. Depending on the port partner's power topology, they may even feedback some amount of voltage on Vbus, causing them to be detected as a charger. After disabling Vbus to the port partner, disable Vconn as well. BUG=b:132110509 BRANCH=octopus TEST=unlocked EC resets and sysjumps with a display port dongle and hoho, ensuring neither was detected as a low power charger after Change-Id: Ica9b72167bc981faeaebac18bac476ca9b7bfe7f Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1639211 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* common: Remove duplicate error checkJacob Garber2019-05-281-3/+1
| | | | | | | | | | | | | | | | This argument count check is already performed at the beginning of the function and is useless anyway since we've already accessed argv[1]. BUG=none BRANCH=none TEST=none Change-Id: I9f1de3c5e67bb0db5564d8a1161b2ae646e8dfe9 Signed-off-by: Jacob Garber <jgarber1@ualberta.ca> Found-by: Coverity CID 141743 Reviewed-on: https://chromium-review.googlesource.com/1629277 Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* usb/mux: Do not connect MUX when PD disconnectedstabilize-12222.BRuibin Chang2019-05-231-10/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When chipset power up to S5->S3 state set PD_EVENT_POWER_STATE_CHANGE, pd task set mux usb mode whether c-port is attached or not. If c-port is nothing attached at the setting moment, then mux detects nothing and goes to low power state. Plug-in type-c usb device, after debounce pass, we set mux usb mode and mux responds i2C NAK (due to in low power mode). This CL changes that do not connect MUX when PD disconnected. For example ps8751 is used for mux case. When power up(S5->S3), we should set mux none mode whether c-port is attached or not. Once type-c usb device plug-in, after cc debounce pass, we will set mux usb mode in X_DEBOUNCE_DISCONNECT state. BRANCH=None BUG=b:133196882 TEST=After console cmd reboot and reboot hard, type-c usb device plug-in on ampton and get type-c port status by "ectool usbpdmuxinfo". Change-Id: Ia538af48c450e12af1438a6aa9a6e4e426e2f616 Signed-off-by: Ruibin Chang <Ruibin.Chang@ite.com.tw> Reviewed-on: https://chromium-review.googlesource.com/1609262 Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* USB PD: Don't attempt to exit mode on a suspended portDiana Z2019-05-171-11/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | Since suspended ports run a very tight while loop which does not include the pd_task's event processing, sysjumping an unlocked system with a suspended port hangs forever. A suspended port cannot be in an alternate mode, so this change skips setting PD_EVENT_SYSJUMP for such ports (which, currently, is only used to trigger the exit mode sequence). In the unlikely event that processing a PD interrupt causes the port to suspend after this check and before PD_EVENT_SYSJUMP is set, the sysjump loop will also send the reply event to the caller. BUG=b:131855159 BRANCH=None TEST=set a phaser port to fail TCPC initialization, verified that "sysjump RW" can still succeed with suspended port Change-Id: I948dd419718d0eb2e5ade58970ed36a8bd51b272 Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1613640 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org> Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Reviewed-by: Furquan Shaikh <furquan@chromium.org>
* pd_protocol: Add ready_state_holdoff_timer.Aseda Aboagye2019-05-171-17/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Recently a sink holdoff timer was added to the PD stack which allowed the state machine to prevent initiating any messages for 200ms after entering the SNK_READY state. This was to give time for some chatty sources to send messages to avoid a collision. Apparently, the same thing can happen when we are a source (collision with chatty sink). This commit reuses the holdoff timer for resolution as a source as well, which starts after an explicit contract is established. In order to prevent any potential new collisions, some jitter based off of the system timestamp is added to the holdoff timer. BUG=b:132202148, chromium:925618 BRANCH=firmware-atlas-11827.B TEST=Flash atlas, plug in a fully featured C-C cable between atlas and the LG 27UK850-W, verify that no conflict occurs and external display always works. TEST=Verify that no messages are initiated by the source within 200ms of sending PS_RDY. TEST=Flash nocturne, verify Dell U3818DW still works over C-C cable. TEST=Flash nocturne, verify CableMatters MST DP hub still works with charge through. TEST=Verify with Twinkie that messages are sent at varied timestamps between 200-300ms in the SNK/SRC_READY state. Change-Id: I195199de271950ae09c2b26194ddc5f271b296a0 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/1600510 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* retimer: Add driver support for Intel Burnside Bridge retimerVijay Hiremath2019-05-141-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Burnside Bridge is a Type-C multi-protocol retimer to be used in on-board applications. Burnside Bridge offers the ability to latch protocol signals into on-chip memory before retransmitting them onwards. It can be used to extend the physical length of the system without increasing high frequency jitter. Burnside Bridge supports spec compliant retimer of following protocols: 1. Display Port: four unidirectional DP lanes 2. USB3.1 Gen1/2: one bi-directional USB lane 3. Thunderbolt: two bi-directional CIO lanes 4. Multifunction Display (MFD): two unidirectional lanes of DP and one bi-directional lane of USB3.1 Gen1/2 Note: Only item 1, 2 & 4 are supported in this CL. Item 3 support will be added in follow on CLs. BUG=b:127623438 BRANCH=none TEST=Manually verified on ICLRVP, able to configure the registers Change-Id: I2d60dbcaf8fe7a1503f09a2f16007409f059f54e Signed-off-by: Ayushee <ayushee.shah@intel.com> Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/1594170 Commit-Ready: Jett Rink <jettrink@chromium.org> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Divya S Sasidharan <divya.s.sasidharan@intel.com>
* common/usb_pd_protocol: Avoid unitialized use of port flagsNicolas Boichat2019-05-121-11/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On reset, when pd_partner_port_reset is called, if, for any reason pd_get_saved_port_flags fails to get the saved port status, we would risk using unitialized flags from the stack. The function logic was a little complicated, and can be simplified quite a bit by returning early if no contract is in place (or if we fail to read flags from BBRAM). This should not be a problem on real boards, as the stored value should be readable from BBRAM. In any case, the first time we used the flag if (explicit_contract_in_place && pd_comm_is_enabled(port)) only applies to unlocked RO images, so this never happens in production (where RO images are locked). The second case is a little tricker, and we may end up (not) applying Rp where we should (not): /* If we just lost power, don't apply Rp. */ if (!explicit_contract_in_place || system_get_reset_flags() & (RESET_FLAG_BROWNOUT | RESET_FLAG_POWER_ON)) return; Presumably, the worst case here is that a charger may not work after a brownout/power on. BRANCH=none BUG=chromium:958510 TEST=setup_board --board=amd64-generic --profile=msan-fuzzer cros_fuzz --board=amd64-generic reproduce --fuzzer \ chromeos_ec_usb_pd_fuzzer --testcase \ ./clusterfuzz-testcase-minimized-ec_usb_pd_fuzzer-5086219896225792 \ --package chromeos-ec --build-type msan => No more MemorySanitizer error. Change-Id: I40fb87b68dbe5244e8a2ae136508b431db7f96a8 Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1600935 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* USB-PD: Add hook for PD connect eventDaisuke Nojiri2019-05-081-0/+5
| | | | | | | | | | | | | | | | This patch adds a hook for USB PD connect event. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=b/127228934 BRANCH=none TEST=buildall. Verify a hook is called on BC12 charger connection. Change-Id: I88fcd65d1afce07b6275398c5d0b902ecd7a44a3 Reviewed-on: https://chromium-review.googlesource.com/1597794 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* usb_pd_protocol.c: exiting from try.src to attach.srcRuibin Chang2019-05-071-10/+34
| | | | | | | | | | | | | | | | | | | | The port shall transition to Attached.SRC when the SRC.Rd state is detected on exactly "one of the CC1 or CC2 pins" for at least tTryCCDebounce. See TypeC v1.4 spec 4.5.2.2.10.2 Exiting from Try.SRC State. BRANCH=None BUG=b:130615676 TEST=1.Ampton with apple type-c adapter 2.Ellisys USB-PD test Change-Id: I461c53e2b8d9189f290956964754ae5b1a11a950 Signed-off-by: Ruibin Chang <Ruibin.Chang@ite.com.tw> Reviewed-on: https://chromium-review.googlesource.com/1564499 Commit-Ready: Diana Z <dzigterman@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* pd_protocol: Don't clear PD flags while debouncing.Aseda Aboagye2019-05-041-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The PD_FLAGS_TRY_SRC flag was being cleared every time we entered the *_DISCONNECTED state. However, this would lead to a case where if the state machine was debouncing the CC lines and decided to re-enter the SRC_DISCONNECTED state, the Try.Src flag would be cleared and the state machine would not transition to the TryWait.SNK state after timing out. We shouldn't clear any flags when transitioning back to the disconnected state from the debounce state as the two states here are really the same states in the state diagram. This commit simply only clears the PD flags when we're transitioning to the disconnected state but not from a debounce state. This also keeps the Try.Src flag set if the previous state was a debounce as it means the state machine decided it didn't meet the condition to exit and should continue waiting before transitioning to TryWait.SNK. BUG=b:115452695 BRANCH=master TEST=Flash nocturne; boot to S0, plug in Apple 87W USB-C charger with eMarked cable, verify we form an explicit 45W contract. Change-Id: I6d8f5d69b8bd0d25ac7af008bbbe91f2658cdfe2 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/1286299 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> (cherry picked from commit 1f30c7483fa5621e9d67c5977709dce73f31a66d) Reviewed-on: https://chromium-review.googlesource.com/1591483 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
* usb: add inline helper method for CC linesJett Rink2019-05-021-32/+12
| | | | | | | | | | | | | | | | Expressing logic for CC lines can get very verbose. Add helper inline methods that logical describe the condition we are testing to clean up call sites. BRANCH=none BUG=none TEST=Builds, no functional change. Change-Id: I48c117437bc14f3c55473df7f7c778b55af2706d Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1589906 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Sam Hurst <shurst@google.com>
* Flapjack: Disable charging from BC 1.2 charger as USB-C chargerDaisuke Nojiri2019-04-301-1/+2
| | | | | | | | | | | | | | | | | | | | | Currently, if a charger shows Rp=USB on USB-C port, the charge manager chooses it and sets the max current to 500 mA even if it can provide higher power as a BC 1.2 charger. This patch introduces CONFIG_USBC_DISABLE_CHARGE_FROM_RP_DEF. When it's defined, a BC 1.2 charger won't be recognized as a USB-C charger. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=b/131353444 BRANCH=none TEST=Charge Flapjack from BC 1.2 charger on USB-C port. Change-Id: I50969973026185dd2aecdb768985cd116c1d32f7 Reviewed-on: https://chromium-review.googlesource.com/1586580 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* USB PD: Re-discover port partner when a contract was in placeDiana Z2019-04-181-1/+48
| | | | | | | | | | | | | | | | | | | | | | When the pd_task starts up with an explicit contract previously in place, re-check the partner's identity. This will happen automatically when we EC reset into RO since pd_chipset_startup sets the flag, but for a RO->RW jump the flag needs to be set again. Additionally, exit DP modes before sysjumping, in order to not confuse the port partner with a second enter mode when it had previously been in that mode. BUG=b:125552060 BRANCH=octopus TEST=on unlocked octopus board, plugged in powered HDMI dongle from hibernate state and confirmed display worked after RO->RW jump. Also turned off software sync and confirmed console "sysjump" worked. Change-Id: Idcde6f04deeb8f409a9b4d0a4b3fc924bdb644c7 Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1506434 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* pd_protocol: Allow charging @ 500mA from Rp-USB.Aseda Aboagye2019-04-171-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | A USB Type-C ECN "Title: Default Current Clarification for non-USB Devices", allows a sink to draw 500mA based off of a Default USB Rp advertisement. This is especially important for devices which lack the hardware to detect legacy sources via BC 1.2. This commit will now allow those devices to charge at 5V/500mA. BUG=b:117805314,b:124138725 BRANCH=firmware-nocturne-10984.B,master TEST=Flash nocturne, plug in USB-A to USB-C cable, verify cable is detected as a charger and that we charge from it. Change-Id: I1f40cca7246c6d671c7775869da64cf30f649dc4 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/1431252 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Benson Leung <bleung@chromium.org> (cherry picked from commit 9509f9aa3322fb180f51064309875589c8b90973) Reviewed-on: https://chromium-review.googlesource.com/1565463 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Matthew Blecker <matthewb@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Matthew Blecker <matthewb@chromium.org>
* kukui: remove flashpd/rwhashpd host command from ROTing Shen2019-04-171-1/+4
| | | | | | | | | | | | | | | | | | | | | Kukui is running out of RO space. In order to save more space, we found that these two functions takes ~500 bytes, so it's especially worth removing. RO size before and after: 122056 Apr 11 17:01 build/kukui/RO/ec.RO.flat 121544 Apr 11 18:14 build/kukui/RO/ec.RO.flat BUG=b:120588396 TEST=make buildall -j BRANCH=None Change-Id: I2e08d45093d5ef88516950e8289e559d4421d126 Signed-off-by: Ting Shen <phoenixshen@google.com> Reviewed-on: https://chromium-review.googlesource.com/1564490 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Ting Shen <phoenixshen@chromium.org> Reviewed-by: Yilun Lin <yllin@chromium.org>
* pd: Apply Rd prior to sending PS_RDY in PRSWAP.Aseda Aboagye2019-04-091-5/+19
| | | | | | | | | | | | | | | | | | | | | | | | | According to the PD spec, in a Power Role swap, the initial source must change its termination from Rp to Rd prior to sending the PS_RDY control message. This commit fixes a bug where we were changing our termination *after* sending the PS_RDY control message. BUG=b:113207208, b:116340006 BRANCH=firmware-nocturne-10984.B,master TEST=Plug in charge thru hub with charger plugged into nocturne, verify PR swap succeeds and the CC lines don't float to vOpen. TEST=Plug in Pixel phone into nocturne, do a PR swap, verify that the CC lines don't float to vOpen. Change-Id: If041595baa77d2494c4caff3660151329bfd4926 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/1381633 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> (cherry picked from commit 31dfe0b1a6b43b01bc89f45e6d3a4ac78b823959) Reviewed-on: https://chromium-review.googlesource.com/1388845 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* common/usb_pd_tcpc: Ignore repeat messagesKarthikeyan Ramasubramanian2019-03-281-2/+21
| | | | | | | | | | | | | | | | | | | | | | | Sometimes messages with the same ID are retransmitted at the physical layer. Under such scenario do not handle the repeat messages. BUG=b:129337537 BRANCH=None TEST=make -j buildall; Ensure that the DUT boots to ChromeOS. Ensure that the servo_v4 boots fine. Ensure that the DUT boots fine in normal mode and recovery mode with and without battery. Ensure that the repeat request messages triggered aritificially are dropped without any side-effects. Ensure that the DUT is detected in CCD with pass-through connected after multiple EC reboots, servo_v4 reboots and USB-C unplug/replug procedure. Change-Id: I850cd3536ff5e62c34f9dabcc0f8f53bb196ce4c Signed-off-by: Karthikeyan Ramasubramanian <kramasub@google.com> Reviewed-on: https://chromium-review.googlesource.com/1513033 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Karthikeyan Ramasubramanian <kramasub@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* USB PD: Save Vconn state in BBRAMDiana Z2019-03-281-6/+29
| | | | | | | | | | | | | | | | | | | | | Currently, unlocked systems can maintain a contract over a reset or sysjump by referencing BBRAM flags for the data and power state. An additional flag is needed to track Vconn state though, particularly in scenarios with hubs which prefer to swap Vconn when they source power. Otherwise, both port partners have a different perspective of which one is sourcing Vconn and this can lead to hard resets when the hub attempts another Vconn swap. BUG=None BRANCH=None TEST=Ran EC resets on unlocked octopus board with a hub which prefers to not source Vconn, ensured that there were no strange Vconn_swap sequences after reset Change-Id: I4ccae72bef1a2df8cda4b32fb6e0a15c0cf176b1 Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1536078 Reviewed-by: Jett Rink <jettrink@chromium.org>
* usb_pd: Get current DP pin modeAyushee2019-03-281-0/+6
| | | | | | | | | | | | | | | | | | | | | DP pin mode is needed to configure the Intel virtual muxes hence, added a board level function that returns the current DP pin mode. Also added a variable to return the DP pin mode in USB_PD_CONTROL host command. BUG=b:112311321 BRANCH=None TEST=Verified on Dragonegg, able to get correct pin mode USB:0x0 (No DP) DP cable:0x4 (Mode:C) USBC dock:0x8 (Mode:D) Change-Id: I997de80d0963e8ac45e97e5da0064694d5572942 Signed-off-by: Ayushee <ayushee.shah@intel.com> Reviewed-on: https://chromium-review.googlesource.com/1512134 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Jett Rink <jettrink@chromium.org>
* common: bit change 1 << constants with BIT(constants)Gwendal Grignou2019-03-261-4/+4
| | | | | | | | | | | | | | | | | Mechanical replacement of bit operation where operand is a constant. More bit operation exist, but prone to errors. Reveal a bug in npcx: chip/npcx/system-npcx7.c:114:54: error: conversion from 'long unsigned int' to 'uint8_t' {aka 'volatile unsigned char'} changes value from '16777215' to '255' [-Werror=overflow] BUG=None BRANCH=None TEST=None Change-Id: I006614026143fa180702ac0d1cc2ceb1b3c6eeb0 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1518660 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* common: replace 1 << digits, with BIT(digits)Gwendal Grignou2019-03-261-1/+1
| | | | | | | | | | | | | | | | Requested for linux integration, use BIT instead of 1 << First step replace bit operation with operand containing only digits. Fix an error in motion_lid try to set bit 31 of a signed integer. BUG=None BRANCH=None TEST=compile Change-Id: Ie843611f2f68e241f0f40d4067f7ade726951d29 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1518659 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* usbpd: Remove pd_state_names if not usedDaisuke Nojiri2019-03-141-20/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, pd_state_names is included in all builds. This change makes it included only in such builds as: - CONFIG_USB_PD_DEBUG_LEVEL is defined to 1+ OR - CONFIG_USB_PD_DEBUG_LEVEL is not defined The 'pd dump' console command will continue to print & change debug level in a normal build. If CONFIG_USB_PD_DEBUG_LEVEL is explicitly defined, the command will only print the current debug level (as expected). Enum pd_state doesn't have to be different between different configurations (DRP, no-DRP, etc.). Actually, we should just stick to a single definition (and append more to the tail to grow) so that the consumers can translate the numbers to the names. After the change with CONFIG_USB_PD_DEBUG_LEVEL = 0, 93520 Mar 11 12:53 build/flapjack/RO/ec.RO.flat 104836 Mar 11 12:54 build/flapjack/RW/ec.RW.flat After the change with CONFIG_USB_PD_DEBUG_LEVEL = 2, 94672 Mar 11 12:54 build/flapjack/RO/ec.RO.flat 106004 Mar 11 12:55 build/flapjack/RW/ec.RW.flat Whatever script, test, daemon, etc. is relying on the text representation of the PD state needs to be fixed as well. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=chromium:937427 BRANCH=none TEST=buildall. Verify 'pd dump' works like bofore in a normal build. Change-Id: Id66634240050103253d69f257ee6f717252fc417 Reviewed-on: https://chromium-review.googlesource.com/1496770 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* usb_chg: Add USB_CHG events for data role set and CC openScott Collyer2019-03-121-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | The pi3usb9201 bc1.2 chip has both client and host mode support. Other bc1.2 detection chips support client mode and are triggered by VBUS detection events. To have better control of the pi3usb9201 and to prevent d+/d- data interruption, it's preferable to trigger bc1.2 mode on data role updates as the data role setting is what's most relevant to legacy bc1.2 modes. This CL adds 3 new USB_CHG events that can be set in the USB PD protocol layer when the data role is being set to sink or source and when a detach event occurs. BUG=b:124612788 BRANCH=none TEST=Tested both external chargers, adapters, and charge through hubs. Verfied that bc1.2 detection is triggered as expected when chargers are connected and verified that when the type C port is in source mode, then the pi3usb9201 is in host CDP mode. Change-Id: I9dbb441c6e226a7836220fc6abcf723a46b1a349 Signed-off-by: Scott Collyer <scollyer@google.com> Reviewed-on: https://chromium-review.googlesource.com/1503953 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Furquan Shaikh <furquan@chromium.org>