summaryrefslogtreecommitdiff
path: root/common/usb_pd_policy.c
Commit message (Collapse)AuthorAgeFilesLines
* Add a board specific helper to return USB PD port countKarthikeyan Ramasubramanian2019-11-091-4/+4
| | | | | | | | | | | | | | | | | | | | | Certain SKUs of certain boards have less number of USB PD ports than configured in CONFIG_USB_PD_PORT_MAX_COUNT. Hence define an overrideable board specific helper to return the number of USB PD ports. This helps to avoid initiating a PD firmware update in SKUs where there are less number of USB PD ports. Also update charge manager to ensure that absent/ invalid PD ports are skipped during port initialization and management. BUG=b:140816510, b:143196487 BRANCH=octopus TEST=make -j buildall; Boot to ChromeOS in bobba(2A + 2C config) and garg(2A + 1C + 1HDMI config). Change-Id: Ie345cef470ad878ec443ddf4797e5d17cfe1f61e Signed-off-by: Karthikeyan Ramasubramanian <kramasub@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1879338 Tested-by: Karthikeyan Ramasubramanian <kramasub@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Karthikeyan Ramasubramanian <kramasub@chromium.org>
* Rename CONFIG_USB_PD_PORT_COUNT as CONFIG_USB_PD_PORT_MAX_COUNTKarthikeyan Ramasubramanian2019-11-011-13/+13
| | | | | | | | | | | | | | | | | Certain SKUs of certain boards have lesser number of USB PD ports than defined by CONFIG_USB_PD_PORT_COUNT. Hence rename CONFIG_USB_PD_PORT_COUNT as CONFIG_USB_PD_PORT_MAX_COUNT. BUG=b:140816510, b:143196487 BRANCH=octopus TEST=make -j buildall; Boot to ChromeOS Change-Id: I7c33b27150730a1a3b5813b7b4a72fd24ab73c6a Signed-off-by: Karthikeyan Ramasubramanian <kramasub@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1879337 Tested-by: Karthikeyan Ramasubramanian <kramasub@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Jett Rink <jettrink@chromium.org>
* usbc: Get current DP pin mode and CC stateAyushee2019-11-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | To configure Intel virtual mux and burnside bridge retimer, current DP pin mode, cc state and the type of the cable is required. Hence, implemented a board level function that returns the current DP pin mode and added a function that returns the type of cable inaccordance to the cable vdo response. Also added a new version to USB_PD_CONTROL host command, to return the DP mode, cc_state and the cable type BUG=b:141971044 BRANCH=None TEST=Verifed with ectool usbpd command on CPU console, able to get correct CC state, pin mode and cable type Pin mode: USB:0x0 (No DP) DP cable:0x4 (Mode:C) USBC dock:0x8 (Mode:D) Change-Id: If87ae6b77e5fa2ceaa22319dfa2d2c802460edfa Signed-off-by: Ayushee <ayushee.shah@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1835030 Reviewed-by: Keith Short <keithshort@chromium.org>
* usb_pd: fix an unit in log message.Pi-Hsun Shih2019-10-291-1/+1
| | | | | | | | | | | | | | From USB PD spec, the voltages encoded in PDO is in 50mV units, not 50V units. BUG=None TEST=None BRANCH=none Change-Id: I20ea308c954fc407b313dd3923ab0112b520108c Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1880777 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* usb_pd: drop duplicate func get_max_request_mv()Yilun Lin2019-10-091-5/+0
| | | | | | | | | | | | | | 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>
* host_command: Change host command return value to enum ec_statusTom Hughes2019-10-021-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* usb_pd: Send SOP' DiscIdent messages on SOP NAKsPrashant Malani2019-09-231-3/+19
| | | | | | | | | | | | | | | | | | | | | | Currently, the only scenario where an SOP' message is sent is when we receive a SOP DiscIdentity Response from the UFP. However, we should be able to query the cable characteristics even if the UFP responds with a NAK. So, add handling to send a SOP' DiscIdentity even if we receive a NAK. This will not otherwise disrupt the PD connection flow. Note that there may be other situations where SOP' messages can be sent, but aren't currently being sent. BUG=chromium:1005941 BRANCH=None TEST=make -j buildall; Test on a hatch with a Pixel 2 DUT. Cable correctly responds with Cable information even after the EC receives a UFP DiscIdentity NAK. Change-Id: Ia856f2eb1547f09ae1dc0318021ad9f2458fc25a Signed-off-by: Prashant Malani <pmalani@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1808057 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* version: Make ver_get_num_commits work for on-flash imagesDaisuke Nojiri2019-09-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | EFS needs to check whether a RW version on flash is equal to or newer for rollback protection before jumping to a RW copy. Currently, ver_get_numcommits works only for the running image. This makes it work for images on flash as well. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=chromium:998135 BRANCH=none TEST=Boot Nami. Verify version numbers are read from RAM and flash. Change-Id: I94475e40f89dc4c3173d83cb1d9d4ad38d6fab79 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1450816 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
* usb_pd: Remove unused port argument from functionsPrashant Malani2019-09-171-5/+5
| | | | | | | | | | | | | | | dfp_discover_identity() and dfp_discover_svids() don't seem to be using the "port" argument. So, remove it. BUG=None BRANCH=None TEST=make -j tests; make -j buildall Change-Id: Ica8c8b96512932c8a905a49c6594dc79ca04fea0 Signed-off-by: Prashant Malani <pmalani@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1806363 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Benson Leung <bleung@google.com>
* pd: USB Power Delivery State Machine based on Revision 3.0 of the spec.Sam Hurst2019-09-101-130/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* usb_pd: Get USB-C cable type informationAyushee2019-08-161-0/+5
| | | | | | | | | | | | | | | 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: Storing USB-C cable attributesAyushee2019-08-161-1/+125
| | | | | | | | | | | | | | | | | | | | | | Cable response VDO after a discovery Identity command with SOP' is being stored and also added a console command which print the information on the console according the cable revision. Since USB PD rev2.0, USB PD rev 3.0 for active cable and USB PD rev 3.0 for passive cable have different cable vdos, different decodings are added for each according to their respective specifications. BUG=b:129990370 BRANCH=none TEST=Verified on dragonegg, able to store the cable attributes. Change-Id: I59e60fe9c820d3d08138875092849345db603776 Signed-off-by: Ayushee <ayushee.shah@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1553898 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
* usb_pd: Adding USB-C cable detectionAyushee2019-08-161-2/+79
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* pd_policy: Change DP AltMode event from host event to MKBP.Aseda Aboagye2019-07-171-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | Previously, the EC could notify the AP that it had entered into DisplayPort Alternate mode by sending a MODE_CHANGE host event. However, there was no mechanism to disable that functionality if desired without effecting the other MODE_CHANGE events (i.e. - base attach/detach). By changing the DisplayPort Alternate mode entry to an MKBP event, we can have more granularity and only affect this single event. - This commit adds a new MKBP event, EC_MKBP_EVENT_DP_ALT_MODE_ENTERED. - The commit also changes the DP AltMode entry notification from sending a MODE_CHANGE host event to this new MKBP event. BUG=chromium:786721 BRANCH=None TEST=Build and flash nocturne, verify that system still wakes up on DisplayPort Alternate Mode entry. Change-Id: Ia5f294b26701c3c98c9b7f948fc693d26234c835 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1685787 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Alexandru M Stan <amstan@chromium.org>
* common: pd_policy: Add notification for DP AltModeAseda Aboagye2019-06-241-0/+17
| | | | | | | | | | | | | | | | | | | | | This commit simply adds a notification that can be called when the device enters DisplayPort Alternate mode or a DP attention VDM is received. Calling the notification will send a MODE_CHANGE host event which may wake the AP. BUG=chromium:786721 BRANCH=firmware-nocturne-10984.B TEST=With other patches, flash nocturne; suspend DUT, plug in powered charge through hub, verify DUT wakes up. Change-Id: Iaa221e69060a7d1015f7c1e2f6f053e6810a674a Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1666366 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Reviewed-by: Furquan Shaikh <furquan@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Auto-Submit: Aseda Aboagye <aaboagye@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>
* common: Remove unnecessary null checkJacob Garber2019-05-281-3/+0
| | | | | | | | | | | | | | | | supported_modes is an array of structs, and addresses of array elements cannot be null. BUG=none BRANCH=none TEST=none Change-Id: I1268e024ba8b2469d1bc70be27b3e98044a7ac04 Signed-off-by: Jacob Garber <jgarber1@ualberta.ca> Found-by: Coverity CID 141742 Reviewed-on: https://chromium-review.googlesource.com/1629279 Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* USB-PD: Fix null-pointer dereference for svdm_rsp.amodeDaisuke Nojiri2019-05-121-2/+4
| | | | | | | | | | | | | | | | | | | This patch fixes null-pointer dereference for svdm_rsp.amode. Some boards set svdm_rsp.amode to NULL. This patch will make TCPM on those boards return NACK instead of crash. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=none BRANCH=none TEST=buildall Change-Id: Ifdeacbe4e164c5f1f7679ed4bb19a91053936ac6 Reviewed-on: https://chromium-review.googlesource.com/1599729 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Patrick Georgi <pgeorgi@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* USB-PD: Fix scope of variable ma in pd_find_pdo_indexDaisuke Nojiri2019-02-121-2/+2
| | | | | | | | | | | | | | | | | | This variable, ma, in pd_find_pdo_index is used only in an internal section but its scope is leaking to the entire function. This patch fixes the scope for better readability. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=none BRANCH=none TEST=buildall Change-Id: Ice903fc830e9d95cc4f2ecbdb6fe8e606f56cf2d Reviewed-on: https://chromium-review.googlesource.com/1459825 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
* USB-PD: Make pd_build_request return voidDaisuke Nojiri2019-02-121-3/+2
| | | | | | | | | | | | | | | | pd_build_request always returns EC_SUCCESS. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=none BRANCH=none TEST=buildall Change-Id: Iae826382134a97ba05f930245d4bfd85ebd76528 Reviewed-on: https://chromium-review.googlesource.com/1459823 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
* PD: Ensure SVID parsing doesn't exceed packet boundariesDiana Z2018-12-031-2/+10
| | | | | | | | | | | | | | | | | | | | | When responding to DiscSVID requests, most port partners will include an SVID value of 0 to indicate the end of the SVIDs. However, not all dongles follow this rule and their packet may end with a VDO containing two non-zero SVIDs. In this scenario, we should stop parsing when we reach the end of the valid packet region to avoid finding junk SVIDs. BRANCH=coral,eve,fizz,glados,gru,grunt,nami,nocturne,oak,octopus,poppy, reef,samus,scarlet,smaug BUG=b:116764439 TEST=on bobba360, verified there were no regressions in SVID parsing with well-behaving dongles (hoho - 2 VDOs, apple - 2 VDOs, DA200 - 1VDO, 7magic - 1 VDO) Change-Id: Id2b40ba918439aeb214efb43837dd995ff0b9d86 Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1355364 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Todd Broch <tbroch@chromium.org>
* ec: Make it possible to build tests using clangNicolas Boichat2018-06-281-3/+1
| | | | | | | | | | | | | | | | | | We might want to try out address sanitizer/fuzzer on some host tests: make it possible to build host tests using clang. Board builds are broken, and there is no intention to fix them, at least for now. BRANCH=none BUG=chromium:854924 TEST=make buildall -j TEST=make CC=clang runtests -j Change-Id: Id49a1b8537bc403d53437a2245f4fab6ceae89ac Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1107522 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* PD: Leave Vbus ON if Vconn and Vbus Requested is set to 0 in the AMA VDOSam Hurst2018-04-251-6/+6
| | | | | | | | | | | | | | | | | | | | While troubleshooting why a generic $19.99 Multiport (USB, HDMI, Type-C) Type-C dongle didn't work on Scarlet, I noticed that Vconn Req and Vbus Req were both set to zero in the AMA VDO. For a better user experience, default to Vbus ON if both Vconn and Vbus Req are both zero. BUG=b:78286905 BRANCH=NONE TEST=manual Tested the generic dongle with USB-Keyboard, TypeC power adapter, and HP monitor. Change-Id: I170eef1372c3621334de2c457bd4533eea744cc0 Signed-off-by: Sam Hurst <shurst@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1019611 Commit-Ready: Sam Hurst <shurst@google.com> Tested-by: Sam Hurst <shurst@google.com> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* cleanup: CONFIG_USB_PD_CUSTOM_VDM is not usedDivya Sasidharan2018-04-091-7/+0
| | | | | | | | | | | | | | | | | | | The pd_custom_vdm is called in common/usb_pd_protocol no matter you have this defined or not. No where else I see pd_vdm being used. So we should not have to deal with this CONFIG_USB_PD_CUSTOM_VDM. BUG=None BRANCH=None TEST=make buildall -j Change-Id: I4e8b710240ee27b12625d797e7824f29044e6462 Signed-off-by: Divya Sasidharan <divya.s.sasidharan@intel.com> Reviewed-on: https://chromium-review.googlesource.com/998520 Commit-Ready: Divya S Sasidharan <divya.s.sasidharan@intel.com> Tested-by: Divya S Sasidharan <divya.s.sasidharan@intel.com> Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Jett Rink <jettrink@chromium.org>
* usb pd: Adding PPC vbus discharge pathJett Rink2018-01-311-0/+3
| | | | | | | | | | | | | | Boards with a PPC will use the PPC to discharge the VBUS line instead of the TCPC or GPIO discharge path. BRANCH=none BUG=b:72179253 TEST=Fall time after device removal on grunt within spec now Change-Id: I822923a1cedb32a20efc3610cce4437ade3387f0 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/886563 Reviewed-by: Edward Hill <ecgh@chromium.org>
* PD: Make current USB PD Stack REV 3 compliantSam Hurst2017-10-241-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implement the following required features in the USB PD Rev. 3.0 specification. Not_supported control message: Inform a port partner that a particular message is not supported. Battery capabilities extended message: Report battery design capacity and last full charge capacity. Battery status data message: Report battery state of charge Collision avoidance: New scheme to avoid collisions caused when both source and sink want to send messages. Cable communication: Only the VCONN source can communicate with the cable plug. This is NOT implemented because although the drivers have the capability of communicating with a cable plug, the PD stack doesn't currently need to talk to a cable plug. This is okay since the current PD design doesn't source or sink more than 3 amps and all Type-C cables are required to be 3 amp capable. BUG=b:64411727 BRANCH=None TEST=`make -j buildall` Passed relevant PD Rev 2.0 compliance tests Successful PD negotiation with PD Rev 2.0 and 3.0 chargers Tested with low power none PD charger. Modified a Kevin to operate as a PD 3.0 charger and sent all required messages and verified the return messages. Also tested collision avoidance by verifying that a sink only transmits when the source indicates it's okay. Used Twinkie to verify that PD was operating as v3.0. Signed-off-by: Sam Hurst <shurst@chromium.org> Change-Id: Ifd77e92ec4e9106236f9221393d2bfb97263d979 Reviewed-on: https://chromium-review.googlesource.com/603003 Commit-Ready: Sam Hurst <shurst@google.com> Tested-by: Sam Hurst <shurst@google.com> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* cleanup: pd: Make PDO find / extract functions non-staticShawn Nematbakhsh2017-10-191-37/+34
| | | | | | | | | | | | | | | | Allow other modules to call pd_find_pdo_index() / pd_extract_pdo_power() in order to get information about current PDOs. BUG=chromium:775542 TEST=Manual on kevin, verify 20V negotiation with zinger still works. BRANCH=servo Change-Id: I1861a0226501bda13e7d576d0971d841da9d2b74 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/724682 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* charge_manager: Consider port in source PDO.Aseda Aboagye2017-08-111-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | When CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT is defined for a board, as its name implies, the board can source a higher current if there is only one port acting as a source. This commit fixes an issue with selecting the right source capability message to advertise. charge_manager_get_source_pdo() was simply checking if there was more than one sink connected, instead of checking if there were any *other* sinks connected. In the event that a sink was connected to a different port, we would advertise the max source PDO. BUG=b:64037926, b:35577509 BRANCH=gru,eve,reef TEST=Connect sink to port 1. Connect a AMA to port 0 that claims that VBUS isn't necessary. Start sending source caps, verify that the max PDO is not being advertised in the source caps. Change-Id: Ie4145ecaf98d5b9070ad3e8b139e5653685fa801 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/610479 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* pd: Ignore Augmented PDOs when choosing PDO to request.Todd Broch2017-05-021-0/+4
| | | | | | | | | | | | | | | | | | | Augmented PDOs are part of the PD3.0 specification. As present USB PD sinks can't support these PDO types we need to ignore them. BRANCH=samus,glados,oak,gru,reef BUG=b:37476637 TEST=manual, On samus, plug-in blackcat (EVT) charger and see it ignore these Augmented PDOs when making its PDO request. Change-Id: I28a0377e1486368f25f37cad640af71244a4c30b Reviewed-on: https://chromium-review.googlesource.com/484687 Commit-Ready: Todd Broch <tbroch@chromium.org> Tested-by: Todd Broch <tbroch@chromium.org> Reviewed-by: Benson Leung <bleung@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* pd: prefer CD pin assignments over EF for USBC->USBC case.Todd Broch2017-04-061-5/+8
| | | | | | | | | | | | | BRANCH=samus,glados,oak,gru,reef BUG=chromium:694597 TEST=manual, connect samus to USB-C monitor via cable and see it select pin assigmnent 'C' Change-Id: Iddad5b654715bd30ba081c62f8fb53e07816498c Reviewed-on: https://chromium-review.googlesource.com/465379 Commit-Ready: Todd Broch <tbroch@chromium.org> Tested-by: Todd Broch <tbroch@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* version: Store image size data in version structShawn Nematbakhsh2017-03-161-1/+1
| | | | | | | | | | | | | | | | | | | | | Store our image size (known at build time) in our version struct (now renamed to image_data). This will allow us to more efficiently determine the size of an image in a follow-up CL. Note that compatibility is broken for old ROs that do not include this CL. BUG=chromium:577915 TEST=Verify on kevin + lars + lars_pd that stored image size matches output of system_get_image_used() for both RO and RW images. BRANCH=None Change-Id: I7b8dc3ac8cf2df3184d0701a0e0ec8032de8d81b Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/450858 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* usb_pd_policy: make pd_set_vbus_discharge work with devices with one USB PD portphilipchen2017-02-021-2/+6
| | | | | | | | | | | | | | | | | | We see compile error in case that pd_set_vbus_discharge is called when GPIO_USB_C1_DISCHARGE is not defined. BUG=chrome-os-partner:62207 BRANCH=gru TEST=make buildall -j Change-Id: I17c324d26ee6bf94c13ec7e0f92b7352de602329 Reviewed-on: https://chromium-review.googlesource.com/435458 Reviewed-by: Shawn N <shawnn@chromium.org> Commit-Queue: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/435540 Commit-Ready: Philip Chen <philipchen@chromium.org> Reviewed-by: Philip Chen <philipchen@chromium.org>
* Revert "version: Store image size data in version struct"Vadim Bendebury2017-02-011-1/+1
| | | | | | | | | | | | | This is a dependency of the uderlyaing patch which breaks header composition of g chip based boards. This reverts commit 7cbb815732d7434f5985d3b50a869aa71ba5c507. Change-Id: I4d94647cf5cb09fd338e5a581c956df6b5d83081 Reviewed-on: https://chromium-review.googlesource.com/435551 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Commit-Queue: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Bendebury <vbendeb@chromium.org>
* version: Store image size data in version structShawn Nematbakhsh2017-01-301-1/+1
| | | | | | | | | | | | | | | | | | | | | Store our image size (known at build time) in our version struct (now renamed to image_data). This will allow us to more efficiently determine the size of an image in a follow-up CL. Note that compatibility is broken for old ROs that do not include this CL. BUG=chromium:577915 TEST=Verify on kevin + lars + lars_pd that stored image size matches output of system_get_image_used() for both RO and RW images. BRANCH=None Change-Id: I49ea5fc27a7f11f66daba485a87d0dfe7d0c770f Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/427408 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* pd: support gotoMin and giveBackSam Hurst2017-01-261-2/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Sink mode, on the receipt of a GotoMin message, reduce the current consumption to some minimum level. BUG=chrome-os-partner:33688 TEST=Manual testing Used a Kevin, with test routine, to test GotoMin feature on another Kevin unit. Test routine: if (!strcasecmp(argv[2], "gm")) { ccprintf("send goto min\n"); send_control(port, PD_CTRL_GOTO_MIN); send_control(port, PD_CTRL_PS_RDY); } Kevin with GotoMin feature: # ectool usbpdpower 0 Port 0: SNK DRP PD 4277mV / 3000mA, max 5000mV / 3000mA / 15000mW Port 1: Disconnected After Test routine is executed: # ectool usbpdpower 0 Port 0: SNK DRP PD 4906mV / 500mA, max 5000mV / 500mA / 2500mW Port 1: Disconnected BRANCH=none Change-Id: Iaac6e19706ceb10ccaff4d602d63fc086c808c8f Reviewed-on: https://chromium-review.googlesource.com/425728 Commit-Ready: Sam Hurst <shurst@google.com> Tested-by: Sam Hurst <shurst@google.com> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* usb_pd_policy: Automatically swap vconn if adapter requests itNicolas Boichat2016-12-141-1/+6
| | | | | | | | | | | | | | | | | | | | | | During discovery, if adapter requests vconn power in the AMA flags, make sure that we provide vconn. This, for example, is necessary for the Apple HDMI adapter to work on boot, when connected in S5. In that case, adapter does request vconn swap, but we reject that as the system is off, and, therefore 5V supply is off. On boot, we send another discovery request, which will detect this case and swap the power. BRANCH=none BUG=chromium:644663 TEST=On elm, S5. Plug adapter with power+HDMI. Switch on elm, type "pd 0 vdm ident" in console, display works. Change-Id: I55b6658c2bc0574b8427ae086f61daf03730a725 Reviewed-on: https://chromium-review.googlesource.com/415697 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* usb_pd_policy: pd_extract_pdo_power: Check that mv != 0Nicolas Boichat2016-12-061-0/+9
| | | | | | | | | | | | | | | | | | | | | | It's preferable to print an error when mv = 0, rather than crashing. Also, do not even select invalid PDO in pd_find_pdo_index. This was seen on elm, where ANX7688 appears to send the EC a corrupted packet during hard reset when connected to j5create adapter. BRANCH=none BUG=chrome-os-partner:60575 TEST=Plug in j5create adapter, then HDMI adapter, then power, elm does not crash (note that the HDMI output still does not work, but at least elm charges). Change-Id: I2150ad6f13465a005444804ec44ec3bdc0ded361 Reviewed-on: https://chromium-review.googlesource.com/416700 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* pd: Whitelist port after receiving IDENT responseShawn Nematbakhsh2016-12-011-0/+6
| | | | | | | | | | | | | | | | | | | | Making dual-role determination after receiving source caps is not sufficient, since we may not yet have identified the partner port. BUG=chrome-os-partner:56966 BRANCH=gru TEST=Attach 'old' Apple USB-C accessory to kevin, attach OEM charger to accessory, run 'pd X hard', verify device charges from port. Change-Id: I7333dd2c723e7245d30cf8a6cb1344e60073c063 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/403118 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org> (cherry picked from commit 09691a0e8dd93383fa76b74332d89707bfe16001) Reviewed-on: https://chromium-review.googlesource.com/415492 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org>
* pd: add PDO selection for choosing highest voltageDevin Lu2016-11-181-13/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | pyro board is using 3S1P battery, it is near 13V. To avoid the charger entering buck-boost mode, sinking as higher voltage to get the higher power efficiency. BRANCH=none BUG=chrome-os-partner:59276 TEST=plug in pyro's charger (offering 20V@2.25A, 15V@3A, 9V@3A and 5V@3A), see it selecting 20V as below: C1 st2 C1 st3 C1 st15 C1 st3 C1 st6 Req C1 [1] 5000mV 3000mA [6391.078044 New chg p1] [6391.081020 Ramp reset: st1] [6391.081664 CL: p1 s0 i500 v20000] C1 st7 C1 st8 C1 st9 [6391.192437 Ramp reset: st1] [6391.193339 CL: p1 s0 i3000 v5000] Req C1 [4] 20000mV 2250mA C1 st7 C1 st8 C1 st9 [6391.457545 Ramp reset: st1] [6391.458340 CL: p1 s0 i2250 v20000] C1 st27 C1 st9 [6392.081252 AC on] [6392.113477 charge_request(0mV, 0mA)] [6393.116998 Ramp p1 st5 2250mA 2250mA] plug in other charger (offering 15V@3A, 12V@3A and 5V@3A), see it selecting 15V as below: C1 st2 C1 st3 C1 st15 C1 st3 C1 st6 Req C1 [1] 5000mV 3000mA [6636.084963 New chg p1] [6636.087117 Ramp reset: st1] [6636.087786 CL: p1 s0 i500 v15000] C1 st7 C1 st8 C1 st9 [6636.165409 Ramp reset: st1] [6636.166314 CL: p1 s0 i3000 v5000] Req C1 [3] 15000mV 3000mA C1 st7 C1 st8 C1 st9 C1 st27 C1 st9 [6637.092559 AC on] [6637.125043 charge_request(0mV, 0mA)] [6638.091158 Ramp p1 st5 3000mA 3000mA] [6639.374815 charge_request(13040mV, 3712mA)] Change-Id: I74fe4cbd6b9d1b416a94eec3fe944a9b725f0ced Signed-off-by: Devin Lu <Devin.Lu@quantatw.com> Reviewed-on: https://chromium-review.googlesource.com/411621 Commit-Ready: Shawn N <shawnn@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* kevin: set accurate current limit on USB load switchVincent Palatin2016-10-311-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | When sourcing current on the type-C port, set the OCP limit on the VBUS load switch according to current dynamic capability. (3.0A when only one port is a power source, 1.5A else) Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=gru BUG=chrome-os-partner:56110 TEST=manual: connect Caroline to Kevin with Twinkie in between, ask Caroline to sink current through the UI. without anything else connected on Kevin, see 3A flowing when measuring with Twinkie ('tw vbus'), plug a dangling C-to-A receptacle dongle on the other Kevin port and see 1.5A flowing through Twinkie. Force the input current limit on Caroline to 3.0A and see Kevin cutting VBUS. Change-Id: Ib879b1ed720b20aa702c5f3643948ba0575d1193 Reviewed-on: https://chromium-review.googlesource.com/403869 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* pd: fix contract negotiation with dynamic PDOsVincent Palatin2016-10-261-5/+13
| | | | | | | | | | | | | | | | | | | | | When the board is using dynamic source PDOs, we need to ensure that we are checking the incoming sink power request against the right set of PDOs else we might reject a valid request (e.g. with high-power source, we need to check against the 3.0A limit if we only have one port connected). Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=gru BUG=chrome-os-partner:56110 TEST=Connect Kevin to Caroline, ask Caroline to charge from the other side and see it negotiating successfully a 5V/3A contract. Change-Id: Ie1aa5746776be5946422bf07c08ae0f22faddd8c Reviewed-on: https://chromium-review.googlesource.com/403088 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* tcpc: Enable vbus discharge using PD discharge registersKevin K Wong2016-09-131-3/+4
| | | | | | | | | | | | | | | BUG=chrome-os-partner:56040 BRANCH=none TEST=Manually tested on Reef. Used scope to monitor VBUS & it dropped to 0.8V within 650ms. Change-Id: Icaea1dc11a7342a5cc1493d6d3c2ec3408d6d37b Signed-off-by: Kevin K Wong <kevin.k.wong@intel.com> Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/367482 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Shawn N <shawnn@chromium.org>
* charger: bd99955: Enable VBUS discharge when appropriateShawn Nematbakhsh2016-09-131-0/+20
| | | | | | | | | | | | | | | | | | | Use a custom VBUS threshold of 3.9V for enable / disable of our VBUS discharge circuit. BUG=chrome-os-partner:55584 BRANCH=None TEST=Plug Apple charge-thru accessory into kevin, plug zinger into accessory, verify charging occurs at PD-negotiated current / voltage. Change-Id: I25f6f68cfe55e8bae2071cda39618b2bfadcb355 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/379475 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* cleanup: DECLARE_CONSOLE_COMMAND only needs 4 argsBill Richardson2016-08-241-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Since pretty much always, we've declared console commands to take a "longhelp" argument with detailed explanations of what the command does. But since almost as long, we've never actually used that argument for anything - we just silently throw it away in the macro. There's only one command (usbchargemode) that even thinks it defines that argument. We're never going to use this, let's just get rid of it. BUG=none BRANCH=none CQ-DEPEND=CL:*279060 CQ-DEPEND=CL:*279158 CQ-DEPEND=CL:*279037 TEST=make buildall; tested on Cr50 hardware Everything builds. Since we never used this arg anyway, there had better not be any difference in the result. Change-Id: Id3f71a53d02e3dc625cfcc12aa71ecb50e35eb9f Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/374163 Reviewed-by: Myles Watson <mylesgw@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Deferred: Use deferred_data instead of function pointerAnton Staaf2016-04-181-1/+1
| | | | | | | | | | | | | | | | | | | | | Previously calls to hook_call_deferred were passed the function to call, which was then looked up in the .rodata.deferred section with a linear search. This linear search can be replaced with a subtract by passing the pointer to the deferred_data object created when DECLARE_DEFERRED was invoked. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None CQ-DEPEND=CL:*255812 TEST=make buildall -j Change-Id: I951dd1541302875b102dd086154cf05591694440 Reviewed-on: https://chromium-review.googlesource.com/334315 Commit-Ready: Bill Richardson <wfrichar@chromium.org> Tested-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* pd: Add common EC_HOST_EVENT_PD_MCU implementationShawn Nematbakhsh2016-01-071-6/+0
| | | | | | | | | | | | | | | | | | | | | For TCPMs with an off chip TCPC, PD MCU host event status can be handled in a common way. When a status flag is updated (ex. from charge_manager), notify the AP through the host event, and save the status flag for later retrieval. BUG=chrome-os-partner:49124 BRANCH=None TEST=Verify `cat /sys/class/power_supply/CROS_USB_PD_CHARGER1/online` on chell reflects the actual online status of the charger. Also verify UI charge icon tracks the online status correctly. Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I63bc70205627474590e38ffd282faedaea3bcc66 Reviewed-on: https://chromium-review.googlesource.com/320796 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Benson Leung <bleung@chromium.org> Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
* cleanup: Fix gcc 5.2.1 compile errorsShawn Nematbakhsh2015-11-111-1/+1
| | | | | | | | | | | | | | | BUG=chromium:552006 BRANCH=None TEST=`make buildall -j` and also verify panic reporting works on glados_pd. Change-Id: Ic9f1ec6b5297389df0d46bb38a67c156901ed956 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/311253 Commit-Ready: Shawn N <shawnn@gmail.com> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* pd: allow request message over max current if mismatch bit setAlec Berg2015-10-131-1/+1
| | | | | | | | | | | | | | | | Allow a request message over our max current if the mismatch bit is set as per the PD spec. BUG=chromium:542832 BRANCH=samus,ryu TEST=load onto samus and connect to a ryu that is requesting 1A max with mismatch bit set, and verify that we accept the request Change-Id: I486495422c972a43927bb2ebffc64c2b9f9ac445 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/305375 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Todd Broch <tbroch@chromium.org>
* cleanup: pd: remove duplicate code for checking request msgAlec Berg2015-10-131-0/+39
| | | | | | | | | | | | | | | | Remove duplicate code for checking request message, but keep a board specific check of the request message for custom checks needed on zinger and plankton. BUG=chrome-os-partner:42490 BRANCH=none TEST=make -j buildall. run on samus and connect a hoho, make sure we successfully negotiate a contract. Change-Id: I7398953a158d340e3e113f5a816b55445a857711 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/305374 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* cleanup: Change meaning of storage offset CONFIGsShawn Nematbakhsh2015-09-161-4/+8
| | | | | | | | | | | | | | | | | | | | | | | In order to support architectures with non-contiguous writable and protected regions, change storage offsets to be relative to writable and protected regions, rather than relative to "the start of the region of storage belonging to the EC". Spec doc available at https://goo.gl/fnzTvr. BRANCH=None BUG=chrome-os-partner:23796 TEST=With entire patch series, on both Samus and Glados: - Verify 'version' EC console command is correct - Verify 'flashrom -p ec -r read.bin' reads back EC image - Verify software sync correctly flashes both EC and PD RW images Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I796f8e7305a6336495bd256a78774595cb16a2e4 Reviewed-on: https://chromium-review.googlesource.com/297823 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>