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 (UFP / Cable) 107 * <26> :: modal operation supported (1b == yes) 108 * <25:16> :: product type (DFP) 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_PSD 3 115 #define IDH_PTYPE_AMA 5 116 117 #define IDH_PTYPE_PCABLE 3 118 #define IDH_PTYPE_ACABLE 4 119 120 #define IDH_PTYPE_DFP_UNDEF 0 121 #define IDH_PTYPE_DFP_HUB 1 122 #define IDH_PTYPE_DFP_HOST 2 123 #define IDH_PTYPE_DFP_PB 3 124 #define IDH_PTYPE_DFP_AMC 4 125 126 #define VDO_IDH(usbh, usbd, ptype, is_modal, vid) \ 127 ((usbh) << 31 | (usbd) << 30 | ((ptype) & 0x7) << 27 \ 128 | (is_modal) << 26 | ((vid) & 0xffff)) 129 130 #define PD_IDH_PTYPE(vdo) (((vdo) >> 27) & 0x7) 131 #define PD_IDH_VID(vdo) ((vdo) & 0xffff) 132 #define PD_IDH_MODAL_SUPP(vdo) ((vdo) & (1 << 26)) 133 #define PD_IDH_DFP_PTYPE(vdo) (((vdo) >> 23) & 0x7) 134 135 /* 136 * Cert Stat VDO 137 * ------------- 138 * <31:0> : USB-IF assigned XID for this cable 139 */ 140 #define PD_CSTAT_XID(vdo) (vdo) 141 142 /* 143 * Product VDO 144 * ----------- 145 * <31:16> : USB Product ID 146 * <15:0> : USB bcdDevice 147 */ 148 #define VDO_PRODUCT(pid, bcd) (((pid) & 0xffff) << 16 | ((bcd) & 0xffff)) 149 #define PD_PRODUCT_PID(vdo) (((vdo) >> 16) & 0xffff) 150 151 /* 152 * UFP VDO1 153 * -------- 154 * <31:29> :: UFP VDO version 155 * <28> :: Reserved 156 * <27:24> :: Device capability 157 * <23:6> :: Reserved 158 * <5:3> :: Alternate modes 159 * <2:0> :: USB highest speed 160 */ 161 #define PD_VDO1_UFP_DEVCAP(vdo) (((vdo) & GENMASK(27, 24)) >> 24) 162 163 #define DEV_USB2_CAPABLE BIT(0) 164 #define DEV_USB2_BILLBOARD BIT(1) 165 #define DEV_USB3_CAPABLE BIT(2) 166 #define DEV_USB4_CAPABLE BIT(3) 167 168 /* 169 * DFP VDO 170 * -------- 171 * <31:29> :: DFP VDO version 172 * <28:27> :: Reserved 173 * <26:24> :: Host capability 174 * <23:5> :: Reserved 175 * <4:0> :: Port number 176 */ 177 #define PD_VDO_DFP_HOSTCAP(vdo) (((vdo) & GENMASK(26, 24)) >> 24) 178 179 #define HOST_USB2_CAPABLE BIT(0) 180 #define HOST_USB3_CAPABLE BIT(1) 181 #define HOST_USB4_CAPABLE BIT(2) 182 183 /* 184 * Cable VDO 185 * --------- 186 * <31:28> :: Cable HW version 187 * <27:24> :: Cable FW version 188 * <23:20> :: Reserved, Shall be set to zero 189 * <19:18> :: type-C to Type-A/B/C/Captive (00b == A, 01 == B, 10 == C, 11 == Captive) 190 * <17> :: Type-C to Plug/Receptacle (0b == plug, 1b == receptacle) 191 * <16:13> :: cable latency (0001 == <10ns(~1m length)) 192 * <12:11> :: cable termination type (11b == both ends active VCONN req) 193 * <10> :: SSTX1 Directionality support (0b == fixed, 1b == cfgable) 194 * <9> :: SSTX2 Directionality support 195 * <8> :: SSRX1 Directionality support 196 * <7> :: SSRX2 Directionality support 197 * <6:5> :: Vbus current handling capability 198 * <4> :: Vbus through cable (0b == no, 1b == yes) 199 * <3> :: SOP" controller present? (0b == no, 1b == yes) 200 * <2:0> :: USB SS Signaling support 201 */ 202 #define CABLE_ATYPE 0 203 #define CABLE_BTYPE 1 204 #define CABLE_CTYPE 2 205 #define CABLE_CAPTIVE 3 206 #define CABLE_PLUG 0 207 #define CABLE_RECEPTACLE 1 208 #define CABLE_CURR_1A5 0 209 #define CABLE_CURR_3A 1 210 #define CABLE_CURR_5A 2 211 #define CABLE_USBSS_U2_ONLY 0 212 #define CABLE_USBSS_U31_GEN1 1 213 #define CABLE_USBSS_U31_GEN2 2 214 #define VDO_CABLE(hw, fw, cbl, gdr, lat, term, tx1d, tx2d, rx1d, rx2d, cur,\ 215 vps, sopp, usbss) \ 216 (((hw) & 0x7) << 28 | ((fw) & 0x7) << 24 | ((cbl) & 0x3) << 18 \ 217 | (gdr) << 17 | ((lat) & 0x7) << 13 | ((term) & 0x3) << 11 \ 218 | (tx1d) << 10 | (tx2d) << 9 | (rx1d) << 8 | (rx2d) << 7 \ 219 | ((cur) & 0x3) << 5 | (vps) << 4 | (sopp) << 3 \ 220 | ((usbss) & 0x7)) 221 #define VDO_TYPEC_CABLE_TYPE(vdo) (((vdo) >> 18) & 0x3) 222 223 /* 224 * AMA VDO 225 * --------- 226 * <31:28> :: Cable HW version 227 * <27:24> :: Cable FW version 228 * <23:12> :: Reserved, Shall be set to zero 229 * <11> :: SSTX1 Directionality support (0b == fixed, 1b == cfgable) 230 * <10> :: SSTX2 Directionality support 231 * <9> :: SSRX1 Directionality support 232 * <8> :: SSRX2 Directionality support 233 * <7:5> :: Vconn power 234 * <4> :: Vconn power required 235 * <3> :: Vbus power required 236 * <2:0> :: USB SS Signaling support 237 */ 238 #define VDO_AMA(hw, fw, tx1d, tx2d, rx1d, rx2d, vcpwr, vcr, vbr, usbss) \ 239 (((hw) & 0x7) << 28 | ((fw) & 0x7) << 24 \ 240 | (tx1d) << 11 | (tx2d) << 10 | (rx1d) << 9 | (rx2d) << 8 \ 241 | ((vcpwr) & 0x7) << 5 | (vcr) << 4 | (vbr) << 3 \ 242 | ((usbss) & 0x7)) 243 244 #define PD_VDO_AMA_VCONN_REQ(vdo) (((vdo) >> 4) & 1) 245 #define PD_VDO_AMA_VBUS_REQ(vdo) (((vdo) >> 3) & 1) 246 247 #define AMA_VCONN_PWR_1W 0 248 #define AMA_VCONN_PWR_1W5 1 249 #define AMA_VCONN_PWR_2W 2 250 #define AMA_VCONN_PWR_3W 3 251 #define AMA_VCONN_PWR_4W 4 252 #define AMA_VCONN_PWR_5W 5 253 #define AMA_VCONN_PWR_6W 6 254 #define AMA_USBSS_U2_ONLY 0 255 #define AMA_USBSS_U31_GEN1 1 256 #define AMA_USBSS_U31_GEN2 2 257 #define AMA_USBSS_BBONLY 3 258 259 /* 260 * SVDM Discover SVIDs request -> response 261 * 262 * Request is properly formatted VDM Header with discover SVIDs command. 263 * Response is a set of SVIDs of all supported SVIDs with all zero's to 264 * mark the end of SVIDs. If more than 12 SVIDs are supported command SHOULD be 265 * repeated. 266 */ 267 #define VDO_SVID(svid0, svid1) (((svid0) & 0xffff) << 16 | ((svid1) & 0xffff)) 268 #define PD_VDO_SVID_SVID0(vdo) ((vdo) >> 16) 269 #define PD_VDO_SVID_SVID1(vdo) ((vdo) & 0xffff) 270 271 /* USB-IF SIDs */ 272 #define USB_SID_PD 0xff00 /* power delivery */ 273 #define USB_SID_DISPLAYPORT 0xff01 274 #define USB_SID_MHL 0xff02 /* Mobile High-Definition Link */ 275 276 /* VDM command timeouts (in ms) */ 277 278 #define PD_T_VDM_UNSTRUCTURED 500 279 #define PD_T_VDM_BUSY 100 280 #define PD_T_VDM_WAIT_MODE_E 100 281 #define PD_T_VDM_SNDR_RSP 30 282 #define PD_T_VDM_E_MODE 25 283 #define PD_T_VDM_RCVR_RSP 15 284 285 #endif /* __LINUX_USB_PD_VDO_H */ 286