pd_vdo.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * Copyright 2015-2017 Google, Inc
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef __LINUX_USB_PD_VDO_H
  15. #define __LINUX_USB_PD_VDO_H
  16. #include "pd.h"
  17. /*
  18. * VDO : Vendor Defined Message Object
  19. * VDM object is minimum of VDM header + 6 additional data objects.
  20. */
  21. #define VDO_MAX_OBJECTS 6
  22. #define VDO_MAX_SIZE (VDO_MAX_OBJECTS + 1)
  23. /*
  24. * VDM header
  25. * ----------
  26. * <31:16> :: SVID
  27. * <15> :: VDM type ( 1b == structured, 0b == unstructured )
  28. * <14:13> :: Structured VDM version (can only be 00 == 1.0 currently)
  29. * <12:11> :: reserved
  30. * <10:8> :: object position (1-7 valid ... used for enter/exit mode only)
  31. * <7:6> :: command type (SVDM only?)
  32. * <5> :: reserved (SVDM), command type (UVDM)
  33. * <4:0> :: command
  34. */
  35. #define VDO(vid, type, custom) \
  36. (((vid) << 16) | \
  37. ((type) << 15) | \
  38. ((custom) & 0x7FFF))
  39. #define VDO_SVDM_TYPE (1 << 15)
  40. #define VDO_SVDM_VERS(x) ((x) << 13)
  41. #define VDO_OPOS(x) ((x) << 8)
  42. #define VDO_CMDT(x) ((x) << 6)
  43. #define VDO_OPOS_MASK VDO_OPOS(0x7)
  44. #define VDO_CMDT_MASK VDO_CMDT(0x3)
  45. #define CMDT_INIT 0
  46. #define CMDT_RSP_ACK 1
  47. #define CMDT_RSP_NAK 2
  48. #define CMDT_RSP_BUSY 3
  49. /* reserved for SVDM ... for Google UVDM */
  50. #define VDO_SRC_INITIATOR (0 << 5)
  51. #define VDO_SRC_RESPONDER (1 << 5)
  52. #define CMD_DISCOVER_IDENT 1
  53. #define CMD_DISCOVER_SVID 2
  54. #define CMD_DISCOVER_MODES 3
  55. #define CMD_ENTER_MODE 4
  56. #define CMD_EXIT_MODE 5
  57. #define CMD_ATTENTION 6
  58. #define VDO_CMD_VENDOR(x) (((0x10 + (x)) & 0x1f))
  59. /* ChromeOS specific commands */
  60. #define VDO_CMD_VERSION VDO_CMD_VENDOR(0)
  61. #define VDO_CMD_SEND_INFO VDO_CMD_VENDOR(1)
  62. #define VDO_CMD_READ_INFO VDO_CMD_VENDOR(2)
  63. #define VDO_CMD_REBOOT VDO_CMD_VENDOR(5)
  64. #define VDO_CMD_FLASH_ERASE VDO_CMD_VENDOR(6)
  65. #define VDO_CMD_FLASH_WRITE VDO_CMD_VENDOR(7)
  66. #define VDO_CMD_ERASE_SIG VDO_CMD_VENDOR(8)
  67. #define VDO_CMD_PING_ENABLE VDO_CMD_VENDOR(10)
  68. #define VDO_CMD_CURRENT VDO_CMD_VENDOR(11)
  69. #define VDO_CMD_FLIP VDO_CMD_VENDOR(12)
  70. #define VDO_CMD_GET_LOG VDO_CMD_VENDOR(13)
  71. #define VDO_CMD_CCD_EN VDO_CMD_VENDOR(14)
  72. #define PD_VDO_VID(vdo) ((vdo) >> 16)
  73. #define PD_VDO_SVDM(vdo) (((vdo) >> 15) & 1)
  74. #define PD_VDO_OPOS(vdo) (((vdo) >> 8) & 0x7)
  75. #define PD_VDO_CMD(vdo) ((vdo) & 0x1f)
  76. #define PD_VDO_CMDT(vdo) (((vdo) >> 6) & 0x3)
  77. /*
  78. * SVDM Identity request -> response
  79. *
  80. * Request is simply properly formatted SVDM header
  81. *
  82. * Response is 4 data objects:
  83. * [0] :: SVDM header
  84. * [1] :: Identitiy header
  85. * [2] :: Cert Stat VDO
  86. * [3] :: (Product | Cable) VDO
  87. * [4] :: AMA VDO
  88. *
  89. */
  90. #define VDO_INDEX_HDR 0
  91. #define VDO_INDEX_IDH 1
  92. #define VDO_INDEX_CSTAT 2
  93. #define VDO_INDEX_CABLE 3
  94. #define VDO_INDEX_PRODUCT 3
  95. #define VDO_INDEX_AMA 4
  96. /*
  97. * SVDM Identity Header
  98. * --------------------
  99. * <31> :: data capable as a USB host
  100. * <30> :: data capable as a USB device
  101. * <29:27> :: product type
  102. * <26> :: modal operation supported (1b == yes)
  103. * <25:16> :: Reserved, Shall be set to zero
  104. * <15:0> :: USB-IF assigned VID for this cable vendor
  105. */
  106. #define IDH_PTYPE_UNDEF 0
  107. #define IDH_PTYPE_HUB 1
  108. #define IDH_PTYPE_PERIPH 2
  109. #define IDH_PTYPE_PCABLE 3
  110. #define IDH_PTYPE_ACABLE 4
  111. #define IDH_PTYPE_AMA 5
  112. #define VDO_IDH(usbh, usbd, ptype, is_modal, vid) \
  113. ((usbh) << 31 | (usbd) << 30 | ((ptype) & 0x7) << 27 \
  114. | (is_modal) << 26 | ((vid) & 0xffff))
  115. #define PD_IDH_PTYPE(vdo) (((vdo) >> 27) & 0x7)
  116. #define PD_IDH_VID(vdo) ((vdo) & 0xffff)
  117. #define PD_IDH_MODAL_SUPP(vdo) ((vdo) & (1 << 26))
  118. /*
  119. * Cert Stat VDO
  120. * -------------
  121. * <31:0> : USB-IF assigned XID for this cable
  122. */
  123. #define PD_CSTAT_XID(vdo) (vdo)
  124. /*
  125. * Product VDO
  126. * -----------
  127. * <31:16> : USB Product ID
  128. * <15:0> : USB bcdDevice
  129. */
  130. #define VDO_PRODUCT(pid, bcd) (((pid) & 0xffff) << 16 | ((bcd) & 0xffff))
  131. #define PD_PRODUCT_PID(vdo) (((vdo) >> 16) & 0xffff)
  132. /*
  133. * Cable VDO
  134. * ---------
  135. * <31:28> :: Cable HW version
  136. * <27:24> :: Cable FW version
  137. * <23:20> :: Reserved, Shall be set to zero
  138. * <19:18> :: type-C to Type-A/B/C (00b == A, 01 == B, 10 == C)
  139. * <17> :: Type-C to Plug/Receptacle (0b == plug, 1b == receptacle)
  140. * <16:13> :: cable latency (0001 == <10ns(~1m length))
  141. * <12:11> :: cable termination type (11b == both ends active VCONN req)
  142. * <10> :: SSTX1 Directionality support (0b == fixed, 1b == cfgable)
  143. * <9> :: SSTX2 Directionality support
  144. * <8> :: SSRX1 Directionality support
  145. * <7> :: SSRX2 Directionality support
  146. * <6:5> :: Vbus current handling capability
  147. * <4> :: Vbus through cable (0b == no, 1b == yes)
  148. * <3> :: SOP" controller present? (0b == no, 1b == yes)
  149. * <2:0> :: USB SS Signaling support
  150. */
  151. #define CABLE_ATYPE 0
  152. #define CABLE_BTYPE 1
  153. #define CABLE_CTYPE 2
  154. #define CABLE_PLUG 0
  155. #define CABLE_RECEPTACLE 1
  156. #define CABLE_CURR_1A5 0
  157. #define CABLE_CURR_3A 1
  158. #define CABLE_CURR_5A 2
  159. #define CABLE_USBSS_U2_ONLY 0
  160. #define CABLE_USBSS_U31_GEN1 1
  161. #define CABLE_USBSS_U31_GEN2 2
  162. #define VDO_CABLE(hw, fw, cbl, gdr, lat, term, tx1d, tx2d, rx1d, rx2d, cur,\
  163. vps, sopp, usbss) \
  164. (((hw) & 0x7) << 28 | ((fw) & 0x7) << 24 | ((cbl) & 0x3) << 18 \
  165. | (gdr) << 17 | ((lat) & 0x7) << 13 | ((term) & 0x3) << 11 \
  166. | (tx1d) << 10 | (tx2d) << 9 | (rx1d) << 8 | (rx2d) << 7 \
  167. | ((cur) & 0x3) << 5 | (vps) << 4 | (sopp) << 3 \
  168. | ((usbss) & 0x7))
  169. /*
  170. * AMA VDO
  171. * ---------
  172. * <31:28> :: Cable HW version
  173. * <27:24> :: Cable FW version
  174. * <23:12> :: Reserved, Shall be set to zero
  175. * <11> :: SSTX1 Directionality support (0b == fixed, 1b == cfgable)
  176. * <10> :: SSTX2 Directionality support
  177. * <9> :: SSRX1 Directionality support
  178. * <8> :: SSRX2 Directionality support
  179. * <7:5> :: Vconn power
  180. * <4> :: Vconn power required
  181. * <3> :: Vbus power required
  182. * <2:0> :: USB SS Signaling support
  183. */
  184. #define VDO_AMA(hw, fw, tx1d, tx2d, rx1d, rx2d, vcpwr, vcr, vbr, usbss) \
  185. (((hw) & 0x7) << 28 | ((fw) & 0x7) << 24 \
  186. | (tx1d) << 11 | (tx2d) << 10 | (rx1d) << 9 | (rx2d) << 8 \
  187. | ((vcpwr) & 0x7) << 5 | (vcr) << 4 | (vbr) << 3 \
  188. | ((usbss) & 0x7))
  189. #define PD_VDO_AMA_VCONN_REQ(vdo) (((vdo) >> 4) & 1)
  190. #define PD_VDO_AMA_VBUS_REQ(vdo) (((vdo) >> 3) & 1)
  191. #define AMA_VCONN_PWR_1W 0
  192. #define AMA_VCONN_PWR_1W5 1
  193. #define AMA_VCONN_PWR_2W 2
  194. #define AMA_VCONN_PWR_3W 3
  195. #define AMA_VCONN_PWR_4W 4
  196. #define AMA_VCONN_PWR_5W 5
  197. #define AMA_VCONN_PWR_6W 6
  198. #define AMA_USBSS_U2_ONLY 0
  199. #define AMA_USBSS_U31_GEN1 1
  200. #define AMA_USBSS_U31_GEN2 2
  201. #define AMA_USBSS_BBONLY 3
  202. /*
  203. * SVDM Discover SVIDs request -> response
  204. *
  205. * Request is properly formatted VDM Header with discover SVIDs command.
  206. * Response is a set of SVIDs of all all supported SVIDs with all zero's to
  207. * mark the end of SVIDs. If more than 12 SVIDs are supported command SHOULD be
  208. * repeated.
  209. */
  210. #define VDO_SVID(svid0, svid1) (((svid0) & 0xffff) << 16 | ((svid1) & 0xffff))
  211. #define PD_VDO_SVID_SVID0(vdo) ((vdo) >> 16)
  212. #define PD_VDO_SVID_SVID1(vdo) ((vdo) & 0xffff)
  213. /* USB-IF SIDs */
  214. #define USB_SID_PD 0xff00 /* power delivery */
  215. #define USB_SID_DISPLAYPORT 0xff01
  216. #define USB_SID_MHL 0xff02 /* Mobile High-Definition Link */
  217. /* VDM command timeouts (in ms) */
  218. #define PD_T_VDM_UNSTRUCTURED 500
  219. #define PD_T_VDM_BUSY 100
  220. #define PD_T_VDM_WAIT_MODE_E 100
  221. #define PD_T_VDM_SNDR_RSP 30
  222. #define PD_T_VDM_E_MODE 25
  223. #define PD_T_VDM_RCVR_RSP 15
  224. #endif /* __LINUX_USB_PD_VDO_H */