Merge tag 'usb-ci-v5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/peter...
[linux-block.git] / include / linux / usb / pd_vdo.h
CommitLineData
c942fddf 1/* SPDX-License-Identifier: GPL-2.0-or-later */
f0690a25
GR
2/*
3 * Copyright 2015-2017 Google, Inc
f0690a25
GR
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
193a6801
GR
16#define VDO_MAX_OBJECTS 6
17#define VDO_MAX_SIZE (VDO_MAX_OBJECTS + 1)
18
f0690a25
GR
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 */
f0690a25
GR
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
3df613ec 59#define VDO_CMD_VENDOR(x) (((0x10 + (x)) & 0x1f))
f0690a25
GR
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
d48ece0b
HK
142/*
143 * UFP VDO1
144 * --------
145 * <31:29> :: UFP VDO version
146 * <28> :: Reserved
147 * <27:24> :: Device capability
148 * <23:6> :: Reserved
149 * <5:3> :: Alternate modes
150 * <2:0> :: USB highest speed
151 */
152#define PD_VDO1_UFP_DEVCAP(vdo) (((vdo) & GENMASK(27, 24)) >> 24)
153
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)
158
159/*
160 * DFP VDO
161 * --------
162 * <31:29> :: DFP VDO version
163 * <28:27> :: Reserved
164 * <26:24> :: Host capability
165 * <23:5> :: Reserved
166 * <4:0> :: Port number
167 */
168#define PD_VDO_DFP_HOSTCAP(vdo) (((vdo) & GENMASK(26, 24)) >> 24)
169
170#define HOST_USB2_CAPABLE BIT(0)
171#define HOST_USB3_CAPABLE BIT(1)
172#define HOST_USB4_CAPABLE BIT(2)
173
f0690a25
GR
174/*
175 * Cable VDO
176 * ---------
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
192 */
193#define CABLE_ATYPE 0
194#define CABLE_BTYPE 1
195#define CABLE_CTYPE 2
196#define CABLE_PLUG 0
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,\
205 vps, sopp, usbss) \
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 \
210 | ((usbss) & 0x7))
211
212/*
213 * AMA VDO
214 * ---------
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
226 */
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 \
231 | ((usbss) & 0x7))
232
233#define PD_VDO_AMA_VCONN_REQ(vdo) (((vdo) >> 4) & 1)
234#define PD_VDO_AMA_VBUS_REQ(vdo) (((vdo) >> 3) & 1)
235
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
247
248/*
249 * SVDM Discover SVIDs request -> response
250 *
251 * Request is properly formatted VDM Header with discover SVIDs command.
c76ae34b 252 * Response is a set of SVIDs of all supported SVIDs with all zero's to
f0690a25
GR
253 * mark the end of SVIDs. If more than 12 SVIDs are supported command SHOULD be
254 * repeated.
255 */
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)
259
260/* USB-IF SIDs */
261#define USB_SID_PD 0xff00 /* power delivery */
262#define USB_SID_DISPLAYPORT 0xff01
263#define USB_SID_MHL 0xff02 /* Mobile High-Definition Link */
264
265/* VDM command timeouts (in ms) */
266
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
273
274#endif /* __LINUX_USB_PD_VDO_H */