]> git.ipfire.org Git - thirdparty/kernel/stable.git/blob - include/linux/usb/pd_vdo.h
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157
[thirdparty/kernel/stable.git] / include / linux / usb / pd_vdo.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Copyright 2015-2017 Google, Inc
4 */
5
6 #ifndef __LINUX_USB_PD_VDO_H
7 #define __LINUX_USB_PD_VDO_H
8
9 #include "pd.h"
10
11 /*
12 * VDO : Vendor Defined Message Object
13 * VDM object is minimum of VDM header + 6 additional data objects.
14 */
15
16 #define VDO_MAX_OBJECTS 6
17 #define VDO_MAX_SIZE (VDO_MAX_OBJECTS + 1)
18
19 /*
20 * VDM header
21 * ----------
22 * <31:16> :: SVID
23 * <15> :: VDM type ( 1b == structured, 0b == unstructured )
24 * <14:13> :: Structured VDM version (can only be 00 == 1.0 currently)
25 * <12:11> :: reserved
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)
29 * <4:0> :: command
30 */
31 #define VDO(vid, type, custom) \
32 (((vid) << 16) | \
33 ((type) << 15) | \
34 ((custom) & 0x7FFF))
35
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)
42
43 #define CMDT_INIT 0
44 #define CMDT_RSP_ACK 1
45 #define CMDT_RSP_NAK 2
46 #define CMDT_RSP_BUSY 3
47
48 /* reserved for SVDM ... for Google UVDM */
49 #define VDO_SRC_INITIATOR (0 << 5)
50 #define VDO_SRC_RESPONDER (1 << 5)
51
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
59 #define VDO_CMD_VENDOR(x) (((0x10 + (x)) & 0x1f))
60
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)
74
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)
80
81 /*
82 * SVDM Identity request -> response
83 *
84 * Request is simply properly formatted SVDM header
85 *
86 * Response is 4 data objects:
87 * [0] :: SVDM header
88 * [1] :: Identitiy header
89 * [2] :: Cert Stat VDO
90 * [3] :: (Product | Cable) VDO
91 * [4] :: AMA VDO
92 *
93 */
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
100
101 /*
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
110 */
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
117
118 #define VDO_IDH(usbh, usbd, ptype, is_modal, vid) \
119 ((usbh) << 31 | (usbd) << 30 | ((ptype) & 0x7) << 27 \
120 | (is_modal) << 26 | ((vid) & 0xffff))
121
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))
125
126 /*
127 * Cert Stat VDO
128 * -------------
129 * <31:0> : USB-IF assigned XID for this cable
130 */
131 #define PD_CSTAT_XID(vdo) (vdo)
132
133 /*
134 * Product VDO
135 * -----------
136 * <31:16> : USB Product ID
137 * <15:0> : USB bcdDevice
138 */
139 #define VDO_PRODUCT(pid, bcd) (((pid) & 0xffff) << 16 | ((bcd) & 0xffff))
140 #define PD_PRODUCT_PID(vdo) (((vdo) >> 16) & 0xffff)
141
142 /*
143 * Cable VDO
144 * ---------
145 * <31:28> :: Cable HW version
146 * <27:24> :: Cable FW version
147 * <23:20> :: Reserved, Shall be set to zero
148 * <19:18> :: type-C to Type-A/B/C (00b == A, 01 == B, 10 == C)
149 * <17> :: Type-C to Plug/Receptacle (0b == plug, 1b == receptacle)
150 * <16:13> :: cable latency (0001 == <10ns(~1m length))
151 * <12:11> :: cable termination type (11b == both ends active VCONN req)
152 * <10> :: SSTX1 Directionality support (0b == fixed, 1b == cfgable)
153 * <9> :: SSTX2 Directionality support
154 * <8> :: SSRX1 Directionality support
155 * <7> :: SSRX2 Directionality support
156 * <6:5> :: Vbus current handling capability
157 * <4> :: Vbus through cable (0b == no, 1b == yes)
158 * <3> :: SOP" controller present? (0b == no, 1b == yes)
159 * <2:0> :: USB SS Signaling support
160 */
161 #define CABLE_ATYPE 0
162 #define CABLE_BTYPE 1
163 #define CABLE_CTYPE 2
164 #define CABLE_PLUG 0
165 #define CABLE_RECEPTACLE 1
166 #define CABLE_CURR_1A5 0
167 #define CABLE_CURR_3A 1
168 #define CABLE_CURR_5A 2
169 #define CABLE_USBSS_U2_ONLY 0
170 #define CABLE_USBSS_U31_GEN1 1
171 #define CABLE_USBSS_U31_GEN2 2
172 #define VDO_CABLE(hw, fw, cbl, gdr, lat, term, tx1d, tx2d, rx1d, rx2d, cur,\
173 vps, sopp, usbss) \
174 (((hw) & 0x7) << 28 | ((fw) & 0x7) << 24 | ((cbl) & 0x3) << 18 \
175 | (gdr) << 17 | ((lat) & 0x7) << 13 | ((term) & 0x3) << 11 \
176 | (tx1d) << 10 | (tx2d) << 9 | (rx1d) << 8 | (rx2d) << 7 \
177 | ((cur) & 0x3) << 5 | (vps) << 4 | (sopp) << 3 \
178 | ((usbss) & 0x7))
179
180 /*
181 * AMA VDO
182 * ---------
183 * <31:28> :: Cable HW version
184 * <27:24> :: Cable FW version
185 * <23:12> :: Reserved, Shall be set to zero
186 * <11> :: SSTX1 Directionality support (0b == fixed, 1b == cfgable)
187 * <10> :: SSTX2 Directionality support
188 * <9> :: SSRX1 Directionality support
189 * <8> :: SSRX2 Directionality support
190 * <7:5> :: Vconn power
191 * <4> :: Vconn power required
192 * <3> :: Vbus power required
193 * <2:0> :: USB SS Signaling support
194 */
195 #define VDO_AMA(hw, fw, tx1d, tx2d, rx1d, rx2d, vcpwr, vcr, vbr, usbss) \
196 (((hw) & 0x7) << 28 | ((fw) & 0x7) << 24 \
197 | (tx1d) << 11 | (tx2d) << 10 | (rx1d) << 9 | (rx2d) << 8 \
198 | ((vcpwr) & 0x7) << 5 | (vcr) << 4 | (vbr) << 3 \
199 | ((usbss) & 0x7))
200
201 #define PD_VDO_AMA_VCONN_REQ(vdo) (((vdo) >> 4) & 1)
202 #define PD_VDO_AMA_VBUS_REQ(vdo) (((vdo) >> 3) & 1)
203
204 #define AMA_VCONN_PWR_1W 0
205 #define AMA_VCONN_PWR_1W5 1
206 #define AMA_VCONN_PWR_2W 2
207 #define AMA_VCONN_PWR_3W 3
208 #define AMA_VCONN_PWR_4W 4
209 #define AMA_VCONN_PWR_5W 5
210 #define AMA_VCONN_PWR_6W 6
211 #define AMA_USBSS_U2_ONLY 0
212 #define AMA_USBSS_U31_GEN1 1
213 #define AMA_USBSS_U31_GEN2 2
214 #define AMA_USBSS_BBONLY 3
215
216 /*
217 * SVDM Discover SVIDs request -> response
218 *
219 * Request is properly formatted VDM Header with discover SVIDs command.
220 * Response is a set of SVIDs of all all supported SVIDs with all zero's to
221 * mark the end of SVIDs. If more than 12 SVIDs are supported command SHOULD be
222 * repeated.
223 */
224 #define VDO_SVID(svid0, svid1) (((svid0) & 0xffff) << 16 | ((svid1) & 0xffff))
225 #define PD_VDO_SVID_SVID0(vdo) ((vdo) >> 16)
226 #define PD_VDO_SVID_SVID1(vdo) ((vdo) & 0xffff)
227
228 /* USB-IF SIDs */
229 #define USB_SID_PD 0xff00 /* power delivery */
230 #define USB_SID_DISPLAYPORT 0xff01
231 #define USB_SID_MHL 0xff02 /* Mobile High-Definition Link */
232
233 /* VDM command timeouts (in ms) */
234
235 #define PD_T_VDM_UNSTRUCTURED 500
236 #define PD_T_VDM_BUSY 100
237 #define PD_T_VDM_WAIT_MODE_E 100
238 #define PD_T_VDM_SNDR_RSP 30
239 #define PD_T_VDM_E_MODE 25
240 #define PD_T_VDM_RCVR_RSP 15
241
242 #endif /* __LINUX_USB_PD_VDO_H */