pd_vdo.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright 2015-2017 Google, Inc
  4. */
  5. #ifndef __LINUX_USB_PD_VDO_H
  6. #define __LINUX_USB_PD_VDO_H
  7. #include "pd.h"
  8. /*
  9. * VDO : Vendor Defined Message Object
  10. * VDM object is minimum of VDM header + 6 additional data objects.
  11. */
  12. #define VDO_MAX_OBJECTS 6
  13. #define VDO_MAX_SIZE (VDO_MAX_OBJECTS + 1)
  14. /*
  15. * VDM header
  16. * ----------
  17. * <31:16> :: SVID
  18. * <15> :: VDM type ( 1b == structured, 0b == unstructured )
  19. * <14:13> :: Structured VDM version
  20. * <12:11> :: reserved
  21. * <10:8> :: object position (1-7 valid ... used for enter/exit mode only)
  22. * <7:6> :: command type (SVDM only?)
  23. * <5> :: reserved (SVDM), command type (UVDM)
  24. * <4:0> :: command
  25. */
  26. #define VDO(vid, type, ver, custom) \
  27. (((vid) << 16) | \
  28. ((type) << 15) | \
  29. ((ver) << 13) | \
  30. ((custom) & 0x7FFF))
  31. #define VDO_SVDM_TYPE (1 << 15)
  32. #define VDO_SVDM_VERS(x) ((x) << 13)
  33. #define VDO_OPOS(x) ((x) << 8)
  34. #define VDO_CMDT(x) ((x) << 6)
  35. #define VDO_SVDM_VERS_MASK VDO_SVDM_VERS(0x3)
  36. #define VDO_OPOS_MASK VDO_OPOS(0x7)
  37. #define VDO_CMDT_MASK VDO_CMDT(0x3)
  38. #define CMDT_INIT 0
  39. #define CMDT_RSP_ACK 1
  40. #define CMDT_RSP_NAK 2
  41. #define CMDT_RSP_BUSY 3
  42. /* reserved for SVDM ... for Google UVDM */
  43. #define VDO_SRC_INITIATOR (0 << 5)
  44. #define VDO_SRC_RESPONDER (1 << 5)
  45. #define CMD_DISCOVER_IDENT 1
  46. #define CMD_DISCOVER_SVID 2
  47. #define CMD_DISCOVER_MODES 3
  48. #define CMD_ENTER_MODE 4
  49. #define CMD_EXIT_MODE 5
  50. #define CMD_ATTENTION 6
  51. #define VDO_CMD_VENDOR(x) (((0x10 + (x)) & 0x1f))
  52. /* ChromeOS specific commands */
  53. #define VDO_CMD_VERSION VDO_CMD_VENDOR(0)
  54. #define VDO_CMD_SEND_INFO VDO_CMD_VENDOR(1)
  55. #define VDO_CMD_READ_INFO VDO_CMD_VENDOR(2)
  56. #define VDO_CMD_REBOOT VDO_CMD_VENDOR(5)
  57. #define VDO_CMD_FLASH_ERASE VDO_CMD_VENDOR(6)
  58. #define VDO_CMD_FLASH_WRITE VDO_CMD_VENDOR(7)
  59. #define VDO_CMD_ERASE_SIG VDO_CMD_VENDOR(8)
  60. #define VDO_CMD_PING_ENABLE VDO_CMD_VENDOR(10)
  61. #define VDO_CMD_CURRENT VDO_CMD_VENDOR(11)
  62. #define VDO_CMD_FLIP VDO_CMD_VENDOR(12)
  63. #define VDO_CMD_GET_LOG VDO_CMD_VENDOR(13)
  64. #define VDO_CMD_CCD_EN VDO_CMD_VENDOR(14)
  65. #define PD_VDO_VID(vdo) ((vdo) >> 16)
  66. #define PD_VDO_SVDM(vdo) (((vdo) >> 15) & 1)
  67. #define PD_VDO_SVDM_VER(vdo) (((vdo) >> 13) & 0x3)
  68. #define PD_VDO_OPOS(vdo) (((vdo) >> 8) & 0x7)
  69. #define PD_VDO_CMD(vdo) ((vdo) & 0x1f)
  70. #define PD_VDO_CMDT(vdo) (((vdo) >> 6) & 0x3)
  71. /*
  72. * SVDM Identity request -> response
  73. *
  74. * Request is simply properly formatted SVDM header
  75. *
  76. * Response is 4 data objects:
  77. * [0] :: SVDM header
  78. * [1] :: Identitiy header
  79. * [2] :: Cert Stat VDO
  80. * [3] :: (Product | Cable) VDO
  81. * [4] :: AMA VDO
  82. *
  83. */
  84. #define VDO_INDEX_HDR 0
  85. #define VDO_INDEX_IDH 1
  86. #define VDO_INDEX_CSTAT 2
  87. #define VDO_INDEX_CABLE 3
  88. #define VDO_INDEX_PRODUCT 3
  89. #define VDO_INDEX_AMA 4
  90. /*
  91. * SVDM Identity Header
  92. * --------------------
  93. * <31> :: data capable as a USB host
  94. * <30> :: data capable as a USB device
  95. * <29:27> :: product type (UFP / Cable / VPD)
  96. * <26> :: modal operation supported (1b == yes)
  97. * <25:23> :: product type (DFP) (SVDM version 2.0+ only; set to zero in version 1.0)
  98. * <22:21> :: connector type (SVDM version 2.0+ only; set to zero in version 1.0)
  99. * <20:16> :: Reserved, Shall be set to zero
  100. * <15:0> :: USB-IF assigned VID for this cable vendor
  101. */
  102. /* PD Rev2.0 definition */
  103. #define IDH_PTYPE_UNDEF 0
  104. /* SOP Product Type (UFP) */
  105. #define IDH_PTYPE_NOT_UFP 0
  106. #define IDH_PTYPE_HUB 1
  107. #define IDH_PTYPE_PERIPH 2
  108. #define IDH_PTYPE_PSD 3
  109. #define IDH_PTYPE_AMA 5
  110. /* SOP' Product Type (Cable Plug / VPD) */
  111. #define IDH_PTYPE_NOT_CABLE 0
  112. #define IDH_PTYPE_PCABLE 3
  113. #define IDH_PTYPE_ACABLE 4
  114. #define IDH_PTYPE_VPD 6
  115. /* SOP Product Type (DFP) */
  116. #define IDH_PTYPE_NOT_DFP 0
  117. #define IDH_PTYPE_DFP_HUB 1
  118. #define IDH_PTYPE_DFP_HOST 2
  119. #define IDH_PTYPE_DFP_PB 3
  120. /* ID Header Mask */
  121. #define IDH_DFP_MASK GENMASK(25, 23)
  122. #define IDH_CONN_MASK GENMASK(22, 21)
  123. #define VDO_IDH(usbh, usbd, ufp_cable, is_modal, dfp, conn, vid) \
  124. ((usbh) << 31 | (usbd) << 30 | ((ufp_cable) & 0x7) << 27 \
  125. | (is_modal) << 26 | ((dfp) & 0x7) << 23 | ((conn) & 0x3) << 21 \
  126. | ((vid) & 0xffff))
  127. #define PD_IDH_PTYPE(vdo) (((vdo) >> 27) & 0x7)
  128. #define PD_IDH_VID(vdo) ((vdo) & 0xffff)
  129. #define PD_IDH_MODAL_SUPP(vdo) ((vdo) & (1 << 26))
  130. #define PD_IDH_DFP_PTYPE(vdo) (((vdo) >> 23) & 0x7)
  131. #define PD_IDH_CONN_TYPE(vdo) (((vdo) >> 21) & 0x3)
  132. /*
  133. * Cert Stat VDO
  134. * -------------
  135. * <31:0> : USB-IF assigned XID for this cable
  136. */
  137. #define PD_CSTAT_XID(vdo) (vdo)
  138. #define VDO_CERT(xid) ((xid) & 0xffffffff)
  139. /*
  140. * Product VDO
  141. * -----------
  142. * <31:16> : USB Product ID
  143. * <15:0> : USB bcdDevice
  144. */
  145. #define VDO_PRODUCT(pid, bcd) (((pid) & 0xffff) << 16 | ((bcd) & 0xffff))
  146. #define PD_PRODUCT_PID(vdo) (((vdo) >> 16) & 0xffff)
  147. /*
  148. * UFP VDO (PD Revision 3.0+ only)
  149. * --------
  150. * <31:29> :: UFP VDO version
  151. * <28> :: Reserved
  152. * <27:24> :: Device capability
  153. * <23:22> :: Connector type (10b == receptacle, 11b == captive plug)
  154. * <21:11> :: Reserved
  155. * <10:8> :: Vconn power (AMA only)
  156. * <7> :: Vconn required (AMA only, 0b == no, 1b == yes)
  157. * <6> :: Vbus required (AMA only, 0b == yes, 1b == no)
  158. * <5:3> :: Alternate modes
  159. * <2:0> :: USB highest speed
  160. */
  161. #define PD_VDO_UFP_DEVCAP(vdo) (((vdo) & GENMASK(27, 24)) >> 24)
  162. /* UFP VDO Version */
  163. #define UFP_VDO_VER1_2 2
  164. /* Device Capability */
  165. #define DEV_USB2_CAPABLE BIT(0)
  166. #define DEV_USB2_BILLBOARD BIT(1)
  167. #define DEV_USB3_CAPABLE BIT(2)
  168. #define DEV_USB4_CAPABLE BIT(3)
  169. /* Connector Type */
  170. #define UFP_RECEPTACLE 2
  171. #define UFP_CAPTIVE 3
  172. /* Vconn Power (AMA only, set to AMA_VCONN_NOT_REQ if Vconn is not required) */
  173. #define AMA_VCONN_PWR_1W 0
  174. #define AMA_VCONN_PWR_1W5 1
  175. #define AMA_VCONN_PWR_2W 2
  176. #define AMA_VCONN_PWR_3W 3
  177. #define AMA_VCONN_PWR_4W 4
  178. #define AMA_VCONN_PWR_5W 5
  179. #define AMA_VCONN_PWR_6W 6
  180. /* Vconn Required (AMA only) */
  181. #define AMA_VCONN_NOT_REQ 0
  182. #define AMA_VCONN_REQ 1
  183. /* Vbus Required (AMA only) */
  184. #define AMA_VBUS_REQ 0
  185. #define AMA_VBUS_NOT_REQ 1
  186. /* Alternate Modes */
  187. #define UFP_ALTMODE_NOT_SUPP 0
  188. #define UFP_ALTMODE_TBT3 BIT(0)
  189. #define UFP_ALTMODE_RECFG BIT(1)
  190. #define UFP_ALTMODE_NO_RECFG BIT(2)
  191. /* USB Highest Speed */
  192. #define UFP_USB2_ONLY 0
  193. #define UFP_USB32_GEN1 1
  194. #define UFP_USB32_4_GEN2 2
  195. #define UFP_USB4_GEN3 3
  196. #define VDO_UFP(ver, cap, conn, vcpwr, vcr, vbr, alt, spd) \
  197. (((ver) & 0x7) << 29 | ((cap) & 0xf) << 24 | ((conn) & 0x3) << 22 \
  198. | ((vcpwr) & 0x7) << 8 | (vcr) << 7 | (vbr) << 6 | ((alt) & 0x7) << 3 \
  199. | ((spd) & 0x7))
  200. /*
  201. * DFP VDO (PD Revision 3.0+ only)
  202. * --------
  203. * <31:29> :: DFP VDO version
  204. * <28:27> :: Reserved
  205. * <26:24> :: Host capability
  206. * <23:22> :: Connector type (10b == receptacle, 11b == captive plug)
  207. * <21:5> :: Reserved
  208. * <4:0> :: Port number
  209. */
  210. #define PD_VDO_DFP_HOSTCAP(vdo) (((vdo) & GENMASK(26, 24)) >> 24)
  211. #define DFP_VDO_VER1_1 1
  212. #define HOST_USB2_CAPABLE BIT(0)
  213. #define HOST_USB3_CAPABLE BIT(1)
  214. #define HOST_USB4_CAPABLE BIT(2)
  215. #define DFP_RECEPTACLE 2
  216. #define DFP_CAPTIVE 3
  217. #define VDO_DFP(ver, cap, conn, pnum) \
  218. (((ver) & 0x7) << 29 | ((cap) & 0x7) << 24 | ((conn) & 0x3) << 22 \
  219. | ((pnum) & 0x1f))
  220. /*
  221. * Cable VDO (for both Passive and Active Cable VDO in PD Rev2.0)
  222. * ---------
  223. * <31:28> :: Cable HW version
  224. * <27:24> :: Cable FW version
  225. * <23:20> :: Reserved, Shall be set to zero
  226. * <19:18> :: type-C to Type-A/B/C/Captive (00b == A, 01 == B, 10 == C, 11 == Captive)
  227. * <17> :: Reserved, Shall be set to zero
  228. * <16:13> :: cable latency (0001 == <10ns(~1m length))
  229. * <12:11> :: cable termination type (11b == both ends active VCONN req)
  230. * <10> :: SSTX1 Directionality support (0b == fixed, 1b == cfgable)
  231. * <9> :: SSTX2 Directionality support
  232. * <8> :: SSRX1 Directionality support
  233. * <7> :: SSRX2 Directionality support
  234. * <6:5> :: Vbus current handling capability (01b == 3A, 10b == 5A)
  235. * <4> :: Vbus through cable (0b == no, 1b == yes)
  236. * <3> :: SOP" controller present? (0b == no, 1b == yes)
  237. * <2:0> :: USB SS Signaling support
  238. *
  239. * Passive Cable VDO (PD Rev3.0+)
  240. * ---------
  241. * <31:28> :: Cable HW version
  242. * <27:24> :: Cable FW version
  243. * <23:21> :: VDO version
  244. * <20> :: Reserved, Shall be set to zero
  245. * <19:18> :: Type-C to Type-C/Captive (10b == C, 11b == Captive)
  246. * <17> :: Reserved, Shall be set to zero
  247. * <16:13> :: cable latency (0001 == <10ns(~1m length))
  248. * <12:11> :: cable termination type (10b == Vconn not req, 01b == Vconn req)
  249. * <10:9> :: Maximum Vbus voltage (00b == 20V, 01b == 30V, 10b == 40V, 11b == 50V)
  250. * <8:7> :: Reserved, Shall be set to zero
  251. * <6:5> :: Vbus current handling capability (01b == 3A, 10b == 5A)
  252. * <4:3> :: Reserved, Shall be set to zero
  253. * <2:0> :: USB highest speed
  254. *
  255. * Active Cable VDO 1 (PD Rev3.0+)
  256. * ---------
  257. * <31:28> :: Cable HW version
  258. * <27:24> :: Cable FW version
  259. * <23:21> :: VDO version
  260. * <20> :: Reserved, Shall be set to zero
  261. * <19:18> :: Connector type (10b == C, 11b == Captive)
  262. * <17> :: Reserved, Shall be set to zero
  263. * <16:13> :: cable latency (0001 == <10ns(~1m length))
  264. * <12:11> :: cable termination type (10b == one end active, 11b == both ends active VCONN req)
  265. * <10:9> :: Maximum Vbus voltage (00b == 20V, 01b == 30V, 10b == 40V, 11b == 50V)
  266. * <8> :: SBU supported (0b == supported, 1b == not supported)
  267. * <7> :: SBU type (0b == passive, 1b == active)
  268. * <6:5> :: Vbus current handling capability (01b == 3A, 10b == 5A)
  269. * <4> :: Vbus through cable (0b == no, 1b == yes)
  270. * <3> :: SOP" controller present? (0b == no, 1b == yes)
  271. * <2:0> :: USB highest speed
  272. */
  273. /* Cable VDO Version */
  274. #define CABLE_VDO_VER1_0 0
  275. #define CABLE_VDO_VER1_3 3
  276. /* Connector Type (_ATYPE and _BTYPE are for PD Rev2.0 only) */
  277. #define CABLE_ATYPE 0
  278. #define CABLE_BTYPE 1
  279. #define CABLE_CTYPE 2
  280. #define CABLE_CAPTIVE 3
  281. /* Cable Latency */
  282. #define CABLE_LATENCY_1M 1
  283. #define CABLE_LATENCY_2M 2
  284. #define CABLE_LATENCY_3M 3
  285. #define CABLE_LATENCY_4M 4
  286. #define CABLE_LATENCY_5M 5
  287. #define CABLE_LATENCY_6M 6
  288. #define CABLE_LATENCY_7M 7
  289. #define CABLE_LATENCY_7M_PLUS 8
  290. /* Cable Termination Type */
  291. #define PCABLE_VCONN_NOT_REQ 0
  292. #define PCABLE_VCONN_REQ 1
  293. #define ACABLE_ONE_END 2
  294. #define ACABLE_BOTH_END 3
  295. /* Maximum Vbus Voltage */
  296. #define CABLE_MAX_VBUS_20V 0
  297. #define CABLE_MAX_VBUS_30V 1
  298. #define CABLE_MAX_VBUS_40V 2
  299. #define CABLE_MAX_VBUS_50V 3
  300. /* Active Cable SBU Supported/Type */
  301. #define ACABLE_SBU_SUPP 0
  302. #define ACABLE_SBU_NOT_SUPP 1
  303. #define ACABLE_SBU_PASSIVE 0
  304. #define ACABLE_SBU_ACTIVE 1
  305. /* Vbus Current Handling Capability */
  306. #define CABLE_CURR_DEF 0
  307. #define CABLE_CURR_3A 1
  308. #define CABLE_CURR_5A 2
  309. /* USB SuperSpeed Signaling Support (PD Rev2.0) */
  310. #define CABLE_USBSS_U2_ONLY 0
  311. #define CABLE_USBSS_U31_GEN1 1
  312. #define CABLE_USBSS_U31_GEN2 2
  313. /* USB Highest Speed */
  314. #define CABLE_USB2_ONLY 0
  315. #define CABLE_USB32_GEN1 1
  316. #define CABLE_USB32_4_GEN2 2
  317. #define CABLE_USB4_GEN3 3
  318. #define VDO_CABLE(hw, fw, cbl, lat, term, tx1d, tx2d, rx1d, rx2d, cur, vps, sopp, usbss) \
  319. (((hw) & 0x7) << 28 | ((fw) & 0x7) << 24 | ((cbl) & 0x3) << 18 \
  320. | ((lat) & 0x7) << 13 | ((term) & 0x3) << 11 | (tx1d) << 10 \
  321. | (tx2d) << 9 | (rx1d) << 8 | (rx2d) << 7 | ((cur) & 0x3) << 5 \
  322. | (vps) << 4 | (sopp) << 3 | ((usbss) & 0x7))
  323. #define VDO_PCABLE(hw, fw, ver, conn, lat, term, vbm, cur, spd) \
  324. (((hw) & 0xf) << 28 | ((fw) & 0xf) << 24 | ((ver) & 0x7) << 21 \
  325. | ((conn) & 0x3) << 18 | ((lat) & 0xf) << 13 | ((term) & 0x3) << 11 \
  326. | ((vbm) & 0x3) << 9 | ((cur) & 0x3) << 5 | ((spd) & 0x7))
  327. #define VDO_ACABLE1(hw, fw, ver, conn, lat, term, vbm, sbu, sbut, cur, vbt, sopp, spd) \
  328. (((hw) & 0xf) << 28 | ((fw) & 0xf) << 24 | ((ver) & 0x7) << 21 \
  329. | ((conn) & 0x3) << 18 | ((lat) & 0xf) << 13 | ((term) & 0x3) << 11 \
  330. | ((vbm) & 0x3) << 9 | (sbu) << 8 | (sbut) << 7 | ((cur) & 0x3) << 5 \
  331. | (vbt) << 4 | (sopp) << 3 | ((spd) & 0x7))
  332. #define VDO_TYPEC_CABLE_TYPE(vdo) (((vdo) >> 18) & 0x3)
  333. /*
  334. * Active Cable VDO 2
  335. * ---------
  336. * <31:24> :: Maximum operating temperature
  337. * <23:16> :: Shutdown temperature
  338. * <15> :: Reserved, Shall be set to zero
  339. * <14:12> :: U3/CLd power
  340. * <11> :: U3 to U0 transition mode (0b == direct, 1b == through U3S)
  341. * <10> :: Physical connection (0b == copper, 1b == optical)
  342. * <9> :: Active element (0b == redriver, 1b == retimer)
  343. * <8> :: USB4 supported (0b == yes, 1b == no)
  344. * <7:6> :: USB2 hub hops consumed
  345. * <5> :: USB2 supported (0b == yes, 1b == no)
  346. * <4> :: USB3.2 supported (0b == yes, 1b == no)
  347. * <3> :: USB lanes supported (0b == one lane, 1b == two lanes)
  348. * <2> :: Optically isolated active cable (0b == no, 1b == yes)
  349. * <1> :: Reserved, Shall be set to zero
  350. * <0> :: USB gen (0b == gen1, 1b == gen2+)
  351. */
  352. /* U3/CLd Power*/
  353. #define ACAB2_U3_CLD_10MW_PLUS 0
  354. #define ACAB2_U3_CLD_10MW 1
  355. #define ACAB2_U3_CLD_5MW 2
  356. #define ACAB2_U3_CLD_1MW 3
  357. #define ACAB2_U3_CLD_500UW 4
  358. #define ACAB2_U3_CLD_200UW 5
  359. #define ACAB2_U3_CLD_50UW 6
  360. /* Other Active Cable VDO 2 Fields */
  361. #define ACAB2_U3U0_DIRECT 0
  362. #define ACAB2_U3U0_U3S 1
  363. #define ACAB2_PHY_COPPER 0
  364. #define ACAB2_PHY_OPTICAL 1
  365. #define ACAB2_REDRIVER 0
  366. #define ACAB2_RETIMER 1
  367. #define ACAB2_USB4_SUPP 0
  368. #define ACAB2_USB4_NOT_SUPP 1
  369. #define ACAB2_USB2_SUPP 0
  370. #define ACAB2_USB2_NOT_SUPP 1
  371. #define ACAB2_USB32_SUPP 0
  372. #define ACAB2_USB32_NOT_SUPP 1
  373. #define ACAB2_LANES_ONE 0
  374. #define ACAB2_LANES_TWO 1
  375. #define ACAB2_OPT_ISO_NO 0
  376. #define ACAB2_OPT_ISO_YES 1
  377. #define ACAB2_GEN_1 0
  378. #define ACAB2_GEN_2_PLUS 1
  379. #define VDO_ACABLE2(mtemp, stemp, u3p, trans, phy, ele, u4, hops, u2, u32, lane, iso, gen) \
  380. (((mtemp) & 0xff) << 24 | ((stemp) & 0xff) << 16 | ((u3p) & 0x7) << 12 \
  381. | (trans) << 11 | (phy) << 10 | (ele) << 9 | (u4) << 8 \
  382. | ((hops) & 0x3) << 6 | (u2) << 5 | (u32) << 4 | (lane) << 3 \
  383. | (iso) << 2 | (gen))
  384. /*
  385. * AMA VDO (PD Rev2.0)
  386. * ---------
  387. * <31:28> :: Cable HW version
  388. * <27:24> :: Cable FW version
  389. * <23:12> :: Reserved, Shall be set to zero
  390. * <11> :: SSTX1 Directionality support (0b == fixed, 1b == cfgable)
  391. * <10> :: SSTX2 Directionality support
  392. * <9> :: SSRX1 Directionality support
  393. * <8> :: SSRX2 Directionality support
  394. * <7:5> :: Vconn power
  395. * <4> :: Vconn power required
  396. * <3> :: Vbus power required
  397. * <2:0> :: USB SS Signaling support
  398. */
  399. #define VDO_AMA(hw, fw, tx1d, tx2d, rx1d, rx2d, vcpwr, vcr, vbr, usbss) \
  400. (((hw) & 0x7) << 28 | ((fw) & 0x7) << 24 \
  401. | (tx1d) << 11 | (tx2d) << 10 | (rx1d) << 9 | (rx2d) << 8 \
  402. | ((vcpwr) & 0x7) << 5 | (vcr) << 4 | (vbr) << 3 \
  403. | ((usbss) & 0x7))
  404. #define PD_VDO_AMA_VCONN_REQ(vdo) (((vdo) >> 4) & 1)
  405. #define PD_VDO_AMA_VBUS_REQ(vdo) (((vdo) >> 3) & 1)
  406. #define AMA_USBSS_U2_ONLY 0
  407. #define AMA_USBSS_U31_GEN1 1
  408. #define AMA_USBSS_U31_GEN2 2
  409. #define AMA_USBSS_BBONLY 3
  410. /*
  411. * VPD VDO
  412. * ---------
  413. * <31:28> :: HW version
  414. * <27:24> :: FW version
  415. * <23:21> :: VDO version
  416. * <20:17> :: Reserved, Shall be set to zero
  417. * <16:15> :: Maximum Vbus voltage (00b == 20V, 01b == 30V, 10b == 40V, 11b == 50V)
  418. * <14> :: Charge through current support (0b == 3A, 1b == 5A)
  419. * <13> :: Reserved, Shall be set to zero
  420. * <12:7> :: Vbus impedance
  421. * <6:1> :: Ground impedance
  422. * <0> :: Charge through support (0b == no, 1b == yes)
  423. */
  424. #define VPD_VDO_VER1_0 0
  425. #define VPD_MAX_VBUS_20V 0
  426. #define VPD_MAX_VBUS_30V 1
  427. #define VPD_MAX_VBUS_40V 2
  428. #define VPD_MAX_VBUS_50V 3
  429. #define VPDCT_CURR_3A 0
  430. #define VPDCT_CURR_5A 1
  431. #define VPDCT_NOT_SUPP 0
  432. #define VPDCT_SUPP 1
  433. #define VDO_VPD(hw, fw, ver, vbm, curr, vbi, gi, ct) \
  434. (((hw) & 0xf) << 28 | ((fw) & 0xf) << 24 | ((ver) & 0x7) << 21 \
  435. | ((vbm) & 0x3) << 15 | (curr) << 14 | ((vbi) & 0x3f) << 7 \
  436. | ((gi) & 0x3f) << 1 | (ct))
  437. /*
  438. * SVDM Discover SVIDs request -> response
  439. *
  440. * Request is properly formatted VDM Header with discover SVIDs command.
  441. * Response is a set of SVIDs of all supported SVIDs with all zero's to
  442. * mark the end of SVIDs. If more than 12 SVIDs are supported command SHOULD be
  443. * repeated.
  444. */
  445. #define VDO_SVID(svid0, svid1) (((svid0) & 0xffff) << 16 | ((svid1) & 0xffff))
  446. #define PD_VDO_SVID_SVID0(vdo) ((vdo) >> 16)
  447. #define PD_VDO_SVID_SVID1(vdo) ((vdo) & 0xffff)
  448. /* USB-IF SIDs */
  449. #define USB_SID_PD 0xff00 /* power delivery */
  450. #define USB_SID_DISPLAYPORT 0xff01
  451. #define USB_SID_MHL 0xff02 /* Mobile High-Definition Link */
  452. /* VDM command timeouts (in ms) */
  453. #define PD_T_VDM_UNSTRUCTURED 500
  454. #define PD_T_VDM_BUSY 100
  455. #define PD_T_VDM_WAIT_MODE_E 100
  456. #define PD_T_VDM_SNDR_RSP 30
  457. #define PD_T_VDM_E_MODE 25
  458. #define PD_T_VDM_RCVR_RSP 15
  459. #endif /* __LINUX_USB_PD_VDO_H */