summaryrefslogtreecommitdiff
path: root/include/usb_sm.h
Commit message (Collapse)AuthorAgeFilesLines
* zephyr: Add initial USB-C supportSimon Glass2020-12-241-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This includes a variety of things to get volteer to build with some amount of USB-C support. It seems to charge the battery and prevent booting when the battery is too low. Much work remains. In particular: - check the Kconfig help and add missing help - possibly add a TCPM Kconfig option for grouping - BCI1.2 event handler - TCPMv2 event generator BUG=b:175434113, b:176171475 BRANCH=none TEST=build and run on volteer: 20-12-11 17:43:12.344 uart:~$ tcpci_dump 0 20-12-11 17:44:45.493 VENDOR_ID (0x00) = 0x0451 20-12-11 17:44:45.493 PRODUCT_ID (0x02) = 0x0422 20-12-11 17:44:45.493 BCD_DEV (0x04) = 0x0100 20-12-11 17:44:45.504 TC_REV (0x06) = 0x0011 20-12-11 17:44:45.504 PD_REV (0x08) = 0x2011 20-12-11 17:44:45.504 PD_INT_REV (0x0a) = 0x1010 20-12-11 17:44:45.515 ALERT (0x10) = 0x000f 20-12-11 17:44:45.515 ALERT_MASK (0x12) = 0x007f 20-12-11 17:44:45.526 POWER_STATUS_MASK (0x14) = 0x04 20-12-11 17:44:45.526 FAULT_STATUS_MASK (0x15) = 0x7f 20-12-11 17:44:45.526 EXT_STATUS_MASK (0x16) = 0x00 20-12-11 17:44:45.536 ALERT_EXTENDED_MASK (0x17) = 0x00 20-12-11 17:44:45.536 CONFIG_STD_OUTPUT (0x18) = 0x60 20-12-11 17:44:45.536 TCPC_CTRL (0x19) = 0x11 20-12-11 17:44:45.547 ROLE_CTRL (0x1a) = 0x1a 20-12-11 17:44:45.547 FAULT_CTRL (0x1b) = 0x06 20-12-11 17:44:45.558 POWER_CTRL (0x1c) = 0x70 20-12-11 17:44:45.558 CC_STATUS (0x1d) = 0x13 20-12-11 17:44:45.558 POWER_STATUS (0x1e) = 0x8c 20-12-11 17:44:45.569 FAULT_STATUS (0x1f) = 0x00 20-12-11 17:44:45.569 EXT_STATUS (0x20) = 0x00 20-12-11 17:44:45.580 ALERT_EXT (0x21) = 0x00 20-12-11 17:44:45.580 DEV_CAP_1 (0x24) = 0x1e98 20-12-11 17:44:45.580 DEV_CAP_2 (0x26) = 0x00c5 20-12-11 17:44:45.592 STD_INPUT_CAP (0x28) = 0x00 20-12-11 17:44:45.592 STD_OUTPUT_CAP (0x29) = 0x00 20-12-11 17:44:45.592 CONFIG_EXT_1 (0x2a) = 0x00 20-12-11 17:44:45.602 MSG_HDR_INFO (0x2e) = 0x02 20-12-11 17:44:45.602 RX_DETECT (0x2f) = 0x00 20-12-11 17:44:45.613 RX_BYTE_CNT (0x30) = 0x00 20-12-11 17:44:45.613 RX_BUF_FRAME_TYPE (0x31) = 0x00 20-12-11 17:44:45.613 TRANSMIT (0x50) = 0x00 20-12-11 17:44:45.624 VBUS_VOLTAGE (0x70) = 0x0000 20-12-11 17:44:45.624 VBUS_SINK_DISCONNECT_THRESH (0x72) = 0x0000 20-12-11 17:44:45.633 VBUS_STOP_DISCHARGE_THRESH (0x74) = 0x0000 20-12-11 17:44:45.633 VBUS_VOLTAGE_ALARM_HI_CFG (0x76) = 0x0000 20-12-11 17:44:45.633 VBUS_VOLTAGE_ALARM_LO_CFG (0x78) = 0x0000 20-12-11 17:44:49.544 uart:~$ ppc_dump 0 20-12-11 17:45:09.838 FUNC_SET1 [50h] = 0x0b 20-12-11 17:45:09.838 FUNC_SET2 [51h] = 0x18 20-12-11 17:45:09.838 FUNC_SET3 [52h] = 0x6a 20-12-11 17:45:09.838 FUNC_SET4 [53h] = 0xfe 20-12-11 17:45:09.838 FUNC_SET5 [54h] = 0x37 20-12-11 17:45:09.838 FUNC_SET6 [55h] = 0xc1 20-12-11 17:45:09.847 FUNC_SET7 [56h] = 0x70 20-12-11 17:45:09.847 FUNC_SET8 [57h] = 0xbd 20-12-11 17:45:09.847 FUNC_SET9 [58h] = 0x34 20-12-11 17:45:09.847 FUNC_SET10 [59h] = 0x70 20-12-11 17:45:09.847 FUNC_SET11 [5ah] = 0x24 20-12-11 17:45:09.858 FUNC_SET12 [5bh] = 0x70 20-12-11 17:45:09.858 INT_STATUS_REG1 [2fh] = 0x00 20-12-11 17:45:09.858 INT_STATUS_REG2 [30h] = 0x80 20-12-11 17:45:09.858 INT_STATUS_REG3 [31h] = 0x09 20-12-11 17:45:09.858 INT_STATUS_REG4 [32h] = 0x08 20-12-11 17:45:09.862 INT_TRIP_RISE_REG1 [20h] = 0x80 20-12-11 17:45:09.862 INT_TRIP_RISE_REG2 [21h] = 0x00 20-12-11 17:45:09.874 INT_TRIP_RISE_REG3 [22h] = 0x05 20-12-11 17:45:09.874 INT_TRIP_FALL_REG1 [23h] = 0x80 20-12-11 17:45:09.874 INT_TRIP_FALL_REG2 [24h] = 0x00 20-12-11 17:45:09.879 INT_TRIP_FALL_REG3 [25h] = 0x05 20-12-11 17:45:09.879 INT_MASK_RISE_REG1 [26h] = 0xef 20-12-11 17:45:09.879 INT_MASK_RISE_REG2 [27h] = 0xe1 20-12-11 17:45:09.892 INT_MASK_RISE_REG3 [28h] = 0xff 20-12-11 17:45:09.892 INT_MASK_FALL_REG1 [29h] = 0xff 20-12-11 17:45:09.892 INT_MASK_FALL_REG2 [2ah] = 0xef 20-12-11 17:45:09.892 INT_MASK_FALL_REG3 [2bh] = 0x8f ... 20-12-11 18:21:17.576 battery 20-12-11 18:21:17.933 Status: 0x0080 INIT 20-12-11 18:21:17.933 Param flags:00000003 20-12-11 18:21:17.933 Temp: 0x0b64 = %.1d K (%.1d C) 20-12-11 18:21:17.933 V: 0x2aa8 = 10920 mV 20-12-11 18:21:17.933 V-desired: 0x3390 = 13200 mV 20-12-11 18:21:17.944 I: 0x00bd = 189 mA(CHG) 20-12-11 18:21:17.944 I-desired: 0x0a19 = 2585 mA 20-12-11 18:21:17.944 Charging: Allowed 20-12-11 18:21:17.944 Charge: 3 % 20-12-11 18:21:17.948 Manuf: LG 20-12-11 18:21:17.948 Device: AC17A8 20-12-11 18:21:17.953 Chem: LIO 20-12-11 18:21:17.960 Serial: 0xb754 20-12-11 18:21:17.960 V-design: 0x2d1e = 11550 mV 20-12-11 18:21:17.965 Mode: 0x6001 20-12-11 18:21:17.965 Abs charge:3 % 20-12-11 18:21:17.974 Remaining: 139 mAh 20-12-11 18:21:17.974 Cap-full: 5093 mAh (4991 mAh with 98 % compensation) 20-12-11 18:21:17.983 Display: 0.0 % 20-12-11 18:21:17.983 Design: 5360 mAh 20-12-11 18:21:17.993 Time-full: 26h:21 20-12-11 18:21:17.993 Empty: 0h:0 Cq-Depend: chromium:2585918 Change-Id: I0d852169c9cbbc70603944b70f4708111abd5b42 Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2587225 Reviewed-by: Keith Short <keithshort@chromium.org>
* usbc: add GEN_NOT_SUPPORTED macro for unsupported statesJett Rink2020-08-131-0/+3
| | | | | | | | | | | | | | | | | | | To enabled use of the IS_ENABLE macro we need to define some of the usb state machine states as extern variables that will never be linked. This allows the compiler to know about a state but will still fail the linking phase if the config option is not defined properly. This is just adding a convenience macro for this paradigm, not creating the paradigm itself. BRANCH=none BUG=none TEST=builds Signed-off-by: Jett Rink <jettrink@chromium.org> Change-Id: Ia19b5babd43d536f043745314481475cf25f6e01 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2353369 Reviewed-by: Edward Hill <ecgh@chromium.org>
* TCPMv2: Correct state control flow descriptionAbe Levkoy2020-07-071-3/+7
| | | | | | | | | | | | | | Child run functions execute before parent fun functions, not after. Make additional minor corrections and clarifications. BUG=none TEST=make buildall BRANCH=none Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Change-Id: Ic1b345e42269c9086f77bb6d9fe54d3f91b1002e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2277210 Reviewed-by: Jett Rink <jettrink@chromium.org>
* tcpmv2: add debug level for TC state machineDenis Brockus2020-05-041-0/+7
| | | | | | | | | | | | | | BUG=none BRANCH=none TEST=verify default and changing debug level works Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I9e1b6485166641e2dd8e9680b0ae0125d84ec3e3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2175377 Tested-by: Denis Brockus <dbrockus@chromium.org> Commit-Queue: Jett Rink <jettrink@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Auto-Submit: Denis Brockus <dbrockus@chromium.org>
* TCPMv2: Add dump pd command needed by PD_FAFTSam Hurst2020-04-291-0/+12
| | | | | | | | | | | | | | | | | | Add dump pd command that sets the debug level of the Policy Engine Layer and Protocol layer. BUG=b:151481791 BRANCH=none TEST=make -j buildall manual: pd dump 0 - verified PRL layer didn't print packet info and PE layer didn't print state names pd dump 1 - verified PRL layer printed packet info and PE layer printed state names Change-Id: I49430573278a4c51f52698c1528ace2c639cc30f Signed-off-by: Sam Hurst <shurst@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2162190 Reviewed-by: Wai-Hong Tam <waihong@google.com>
* usbc: rename exe_state to run_stateEdward Hill2019-10-151-1/+1
| | | | | | | | | | | | | | | | | Just a simple rename. run_state() seems more readable to me, and "run" is used in many of the related functions and comments. exe_state used to be called sm_run_state_machine before the great refactoring of CL:1733744. BRANCH=none BUG=none TEST=build Change-Id: I5fe9e5b98042d7a5b9b9e9bde48ebecbda420458 Signed-off-by: Edward Hill <ecgh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1848970 Reviewed-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
* test: add sanity check for existing state machinesJett Rink2019-08-201-0/+17
| | | | | | | | | | | | | | | | | | | | We want to ensure that our usb state machines - do not have any cycles - do not have any completely empty states - have names for every print statement if called These new unit tests allow us to have build-times checks for the above. BRANCH=none BUG=none TEST=tests pass. Made each test fail locally to ensure that tests were actually working. Change-Id: Idd2c4d69e83cf38c97278edd1727d86b52a85db9 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1744657 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* usb: update state machine frameworkJett Rink2019-08-201-118/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - OBJ is renamed to context (CTX) for current and last state - State definition now includes its parent (no need for the boiler plate function that takes in a signal) - The init_state, set_state, and exe_state have been re-written to take advantages of new state machine definition. I had to add more logic to handle hierarchical states fully. - Explicitly create the USB states at the bottom of the file with all of the statics. Don't need to use macros (even though I did suggest them) - Use NULL when we do_nothing instead of calling into a function - Created a "private" enum in the C file that lists all of the states in the file, that we can use to refer to a state (it is also the index into the states array for that state). - Changed prototype of state function to return void, since we aren't really using the return value and it cleans up a lot of return 0 that aren't needed. - Add const to int port since we can and should - Moves struct definition to implementation file only to keep implementation details private. We can access data through accessor if needed. BRANCH=none BUG=none TEST=all unit tests passes Change-Id: I482a63e08f7d63022d5102b891a2fac0b0faa46f Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1733744 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* type-c: USB Type-C State Machine based on Release 1.4 of the spec.Sam Hurst2019-07-301-41/+51
| | | | | | | | | | | | | | | | | | | | | | | | | Implements DRP with Accessory, and Try.SRC as detailed in Release 1.4 of the USB Type-C specification. BUG=b:130895206 BRANCH=none TEST=manual Used Atlas device to verify that it could be charged from PD and none PD charges at 5V/3A. Attached USB dock and verifed access to USB Thumb drive. Performed same tests on Hatch 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. Change-Id: Ic4869e20e5b4c2ba6c827d92e40c70f3140f2518 Signed-off-by: Sam Hurst <shurst@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1574667 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Sam Hurst <shurst@google.com> Commit-Queue: Sam Hurst <shurst@google.com>
* chocodile_vpdmcu: Firmware refactoringSam Hurst2019-06-051-0/+72
| | | | | | | | | | | | | | | | | Move code in header files into c source files. BUG=b:133341676 BRANCH=none TEST=manual Charge-Through was tested on an Atlas running a DRP USB-C/PD state machine with CTUnattached.SNK and CTAttached.SNK states. Change-Id: Ib1b51a778b937e02908f0bc8866bc91a39831163 Signed-off-by: Sam Hurst <shurst@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1626036 Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Sam Hurst <shurst@google.com> Tested-by: Sam Hurst <shurst@google.com>
* chocodile_vpdmcu: Firmware for chocodile mcuSam Hurst2019-04-081-0/+67
Implement Chocodile Charge-Through Vconn Powered firmware for mcu using new Type-C/PD State machine stack. BUG=b:115626873 BRANCH=none TEST=manual Charge-Through was tested on an Atlas running a DRP USB-C/PD state machine with CTUnattached.SNK and CTAttached.SNK states. Signed-off-by: Sam Hurst <shurst@chromium.org> Change-Id: I847f1bcd2fc3ce41e66edd133a10c943d5e8c819 Reviewed-on: https://chromium-review.googlesource.com/1225250 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Sam Hurst <shurst@google.com> Reviewed-by: Stefan Reinauer <reinauer@google.com>