1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright 2015-2017 Google, Inc
6 #ifndef __LINUX_USB_PD_VDO_H
7 #define __LINUX_USB_PD_VDO_H
12 * VDO : Vendor Defined Message Object
13 * VDM object is minimum of VDM header + 6 additional data objects.
16 #define VDO_MAX_OBJECTS 6
17 #define VDO_MAX_SIZE (VDO_MAX_OBJECTS + 1)
23 * <15> :: VDM type ( 1b == structured, 0b == unstructured )
24 * <14:13> :: Structured VDM version (can only be 00 == 1.0 currently)
26 * <10:8> :: object position (1-7 valid ... used for enter/exit mode only)
27 * <7:6> :: command type (SVDM only?)
28 * <5> :: reserved (SVDM), command type (UVDM)
31 #define VDO(vid, type, custom) \
36 #define VDO_SVDM_TYPE (1 << 15)
37 #define VDO_SVDM_VERS(x) ((x) << 13)
38 #define VDO_OPOS(x) ((x) << 8)
39 #define VDO_CMDT(x) ((x) << 6)
40 #define VDO_OPOS_MASK VDO_OPOS(0x7)
41 #define VDO_CMDT_MASK VDO_CMDT(0x3)
44 #define CMDT_RSP_ACK 1
45 #define CMDT_RSP_NAK 2
46 #define CMDT_RSP_BUSY 3
48 /* reserved for SVDM ... for Google UVDM */
49 #define VDO_SRC_INITIATOR (0 << 5)
50 #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
59 #define VDO_CMD_VENDOR(x) (((0x10 + (x)) & 0x1f))
61 /* ChromeOS specific commands */
62 #define VDO_CMD_VERSION VDO_CMD_VENDOR(0)
63 #define VDO_CMD_SEND_INFO VDO_CMD_VENDOR(1)
64 #define VDO_CMD_READ_INFO VDO_CMD_VENDOR(2)
65 #define VDO_CMD_REBOOT VDO_CMD_VENDOR(5)
66 #define VDO_CMD_FLASH_ERASE VDO_CMD_VENDOR(6)
67 #define VDO_CMD_FLASH_WRITE VDO_CMD_VENDOR(7)
68 #define VDO_CMD_ERASE_SIG VDO_CMD_VENDOR(8)
69 #define VDO_CMD_PING_ENABLE VDO_CMD_VENDOR(10)
70 #define VDO_CMD_CURRENT VDO_CMD_VENDOR(11)
71 #define VDO_CMD_FLIP VDO_CMD_VENDOR(12)
72 #define VDO_CMD_GET_LOG VDO_CMD_VENDOR(13)
73 #define VDO_CMD_CCD_EN VDO_CMD_VENDOR(14)
75 #define PD_VDO_VID(vdo) ((vdo) >> 16)
76 #define PD_VDO_SVDM(vdo) (((vdo) >> 15) & 1)
77 #define PD_VDO_OPOS(vdo) (((vdo) >> 8) & 0x7)
78 #define PD_VDO_CMD(vdo) ((vdo) & 0x1f)
79 #define PD_VDO_CMDT(vdo) (((vdo) >> 6) & 0x3)
82 * SVDM Identity request -> response
84 * Request is simply properly formatted SVDM header
86 * Response is 4 data objects:
88 * [1] :: Identitiy header
89 * [2] :: Cert Stat VDO
90 * [3] :: (Product | Cable) VDO
94 #define VDO_INDEX_HDR 0
95 #define VDO_INDEX_IDH 1
96 #define VDO_INDEX_CSTAT 2
97 #define VDO_INDEX_CABLE 3
98 #define VDO_INDEX_PRODUCT 3
99 #define VDO_INDEX_AMA 4
102 * SVDM Identity Header
103 * --------------------
104 * <31> :: data capable as a USB host
105 * <30> :: data capable as a USB device
106 * <29:27> :: product type
107 * <26> :: modal operation supported (1b == yes)
108 * <25:16> :: Reserved, Shall be set to zero
109 * <15:0> :: USB-IF assigned VID for this cable vendor
111 #define IDH_PTYPE_UNDEF 0
112 #define IDH_PTYPE_HUB 1
113 #define IDH_PTYPE_PERIPH 2
114 #define IDH_PTYPE_PCABLE 3
115 #define IDH_PTYPE_ACABLE 4
116 #define IDH_PTYPE_AMA 5
118 #define VDO_IDH(usbh, usbd, ptype, is_modal, vid) \
119 ((usbh) << 31 | (usbd) << 30 | ((ptype) & 0x7) << 27 \
120 | (is_modal) << 26 | ((vid) & 0xffff))
122 #define PD_IDH_PTYPE(vdo) (((vdo) >> 27) & 0x7)
123 #define PD_IDH_VID(vdo) ((vdo) & 0xffff)
124 #define PD_IDH_MODAL_SUPP(vdo) ((vdo) & (1 << 26))
129 * <31:0> : USB-IF assigned XID for this cable
131 #define PD_CSTAT_XID(vdo) (vdo)
136 * <31:16> : USB Product ID
137 * <15:0> : USB bcdDevice
139 #define VDO_PRODUCT(pid, bcd) (((pid) & 0xffff) << 16 | ((bcd) & 0xffff))
140 #define PD_PRODUCT_PID(vdo) (((vdo) >> 16) & 0xffff)
145 * <31:29> :: UFP VDO version
147 * <27:24> :: Device capability
149 * <5:3> :: Alternate modes
150 * <2:0> :: USB highest speed
152 #define PD_VDO1_UFP_DEVCAP(vdo) (((vdo) & GENMASK(27, 24)) >> 24)
154 #define DEV_USB2_CAPABLE BIT(0)
155 #define DEV_USB2_BILLBOARD BIT(1)
156 #define DEV_USB3_CAPABLE BIT(2)
157 #define DEV_USB4_CAPABLE BIT(3)
162 * <31:29> :: DFP VDO version
163 * <28:27> :: Reserved
164 * <26:24> :: Host capability
166 * <4:0> :: Port number
168 #define PD_VDO_DFP_HOSTCAP(vdo) (((vdo) & GENMASK(26, 24)) >> 24)
170 #define HOST_USB2_CAPABLE BIT(0)
171 #define HOST_USB3_CAPABLE BIT(1)
172 #define HOST_USB4_CAPABLE BIT(2)
177 * <31:28> :: Cable HW version
178 * <27:24> :: Cable FW version
179 * <23:20> :: Reserved, Shall be set to zero
180 * <19:18> :: type-C to Type-A/B/C (00b == A, 01 == B, 10 == C)
181 * <17> :: Type-C to Plug/Receptacle (0b == plug, 1b == receptacle)
182 * <16:13> :: cable latency (0001 == <10ns(~1m length))
183 * <12:11> :: cable termination type (11b == both ends active VCONN req)
184 * <10> :: SSTX1 Directionality support (0b == fixed, 1b == cfgable)
185 * <9> :: SSTX2 Directionality support
186 * <8> :: SSRX1 Directionality support
187 * <7> :: SSRX2 Directionality support
188 * <6:5> :: Vbus current handling capability
189 * <4> :: Vbus through cable (0b == no, 1b == yes)
190 * <3> :: SOP" controller present? (0b == no, 1b == yes)
191 * <2:0> :: USB SS Signaling support
193 #define CABLE_ATYPE 0
194 #define CABLE_BTYPE 1
195 #define CABLE_CTYPE 2
197 #define CABLE_RECEPTACLE 1
198 #define CABLE_CURR_1A5 0
199 #define CABLE_CURR_3A 1
200 #define CABLE_CURR_5A 2
201 #define CABLE_USBSS_U2_ONLY 0
202 #define CABLE_USBSS_U31_GEN1 1
203 #define CABLE_USBSS_U31_GEN2 2
204 #define VDO_CABLE(hw, fw, cbl, gdr, lat, term, tx1d, tx2d, rx1d, rx2d, cur,\
206 (((hw) & 0x7) << 28 | ((fw) & 0x7) << 24 | ((cbl) & 0x3) << 18 \
207 | (gdr) << 17 | ((lat) & 0x7) << 13 | ((term) & 0x3) << 11 \
208 | (tx1d) << 10 | (tx2d) << 9 | (rx1d) << 8 | (rx2d) << 7 \
209 | ((cur) & 0x3) << 5 | (vps) << 4 | (sopp) << 3 \
215 * <31:28> :: Cable HW version
216 * <27:24> :: Cable FW version
217 * <23:12> :: Reserved, Shall be set to zero
218 * <11> :: SSTX1 Directionality support (0b == fixed, 1b == cfgable)
219 * <10> :: SSTX2 Directionality support
220 * <9> :: SSRX1 Directionality support
221 * <8> :: SSRX2 Directionality support
222 * <7:5> :: Vconn power
223 * <4> :: Vconn power required
224 * <3> :: Vbus power required
225 * <2:0> :: USB SS Signaling support
227 #define VDO_AMA(hw, fw, tx1d, tx2d, rx1d, rx2d, vcpwr, vcr, vbr, usbss) \
228 (((hw) & 0x7) << 28 | ((fw) & 0x7) << 24 \
229 | (tx1d) << 11 | (tx2d) << 10 | (rx1d) << 9 | (rx2d) << 8 \
230 | ((vcpwr) & 0x7) << 5 | (vcr) << 4 | (vbr) << 3 \
233 #define PD_VDO_AMA_VCONN_REQ(vdo) (((vdo) >> 4) & 1)
234 #define PD_VDO_AMA_VBUS_REQ(vdo) (((vdo) >> 3) & 1)
236 #define AMA_VCONN_PWR_1W 0
237 #define AMA_VCONN_PWR_1W5 1
238 #define AMA_VCONN_PWR_2W 2
239 #define AMA_VCONN_PWR_3W 3
240 #define AMA_VCONN_PWR_4W 4
241 #define AMA_VCONN_PWR_5W 5
242 #define AMA_VCONN_PWR_6W 6
243 #define AMA_USBSS_U2_ONLY 0
244 #define AMA_USBSS_U31_GEN1 1
245 #define AMA_USBSS_U31_GEN2 2
246 #define AMA_USBSS_BBONLY 3
249 * SVDM Discover SVIDs request -> response
251 * Request is properly formatted VDM Header with discover SVIDs command.
252 * Response is a set of SVIDs of all supported SVIDs with all zero's to
253 * mark the end of SVIDs. If more than 12 SVIDs are supported command SHOULD be
256 #define VDO_SVID(svid0, svid1) (((svid0) & 0xffff) << 16 | ((svid1) & 0xffff))
257 #define PD_VDO_SVID_SVID0(vdo) ((vdo) >> 16)
258 #define PD_VDO_SVID_SVID1(vdo) ((vdo) & 0xffff)
261 #define USB_SID_PD 0xff00 /* power delivery */
262 #define USB_SID_DISPLAYPORT 0xff01
263 #define USB_SID_MHL 0xff02 /* Mobile High-Definition Link */
265 /* VDM command timeouts (in ms) */
267 #define PD_T_VDM_UNSTRUCTURED 500
268 #define PD_T_VDM_BUSY 100
269 #define PD_T_VDM_WAIT_MODE_E 100
270 #define PD_T_VDM_SNDR_RSP 30
271 #define PD_T_VDM_E_MODE 25
272 #define PD_T_VDM_RCVR_RSP 15
274 #endif /* __LINUX_USB_PD_VDO_H */