at v5.7 7.4 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2 3#ifndef __LINUX_USB_TYPEC_H 4#define __LINUX_USB_TYPEC_H 5 6#include <linux/types.h> 7 8/* USB Type-C Specification releases */ 9#define USB_TYPEC_REV_1_0 0x100 /* 1.0 */ 10#define USB_TYPEC_REV_1_1 0x110 /* 1.1 */ 11#define USB_TYPEC_REV_1_2 0x120 /* 1.2 */ 12#define USB_TYPEC_REV_1_3 0x130 /* 1.3 */ 13#define USB_TYPEC_REV_1_4 0x140 /* 1.4 */ 14#define USB_TYPEC_REV_2_0 0x200 /* 2.0 */ 15 16struct typec_partner; 17struct typec_cable; 18struct typec_plug; 19struct typec_port; 20 21struct fwnode_handle; 22struct device; 23 24enum typec_port_type { 25 TYPEC_PORT_SRC, 26 TYPEC_PORT_SNK, 27 TYPEC_PORT_DRP, 28}; 29 30enum typec_port_data { 31 TYPEC_PORT_DFP, 32 TYPEC_PORT_UFP, 33 TYPEC_PORT_DRD, 34}; 35 36enum typec_plug_type { 37 USB_PLUG_NONE, 38 USB_PLUG_TYPE_A, 39 USB_PLUG_TYPE_B, 40 USB_PLUG_TYPE_C, 41 USB_PLUG_CAPTIVE, 42}; 43 44enum typec_data_role { 45 TYPEC_DEVICE, 46 TYPEC_HOST, 47}; 48 49enum typec_role { 50 TYPEC_SINK, 51 TYPEC_SOURCE, 52}; 53 54enum typec_pwr_opmode { 55 TYPEC_PWR_MODE_USB, 56 TYPEC_PWR_MODE_1_5A, 57 TYPEC_PWR_MODE_3_0A, 58 TYPEC_PWR_MODE_PD, 59}; 60 61enum typec_accessory { 62 TYPEC_ACCESSORY_NONE, 63 TYPEC_ACCESSORY_AUDIO, 64 TYPEC_ACCESSORY_DEBUG, 65}; 66 67#define TYPEC_MAX_ACCESSORY 3 68 69enum typec_orientation { 70 TYPEC_ORIENTATION_NONE, 71 TYPEC_ORIENTATION_NORMAL, 72 TYPEC_ORIENTATION_REVERSE, 73}; 74 75/* 76 * struct usb_pd_identity - USB Power Delivery identity data 77 * @id_header: ID Header VDO 78 * @cert_stat: Cert Stat VDO 79 * @product: Product VDO 80 * @vdo: Product Type Specific VDOs 81 * 82 * USB power delivery Discover Identity command response data. 83 * 84 * REVISIT: This is USB Power Delivery specific information, so this structure 85 * probable belongs to USB Power Delivery header file once we have them. 86 */ 87struct usb_pd_identity { 88 u32 id_header; 89 u32 cert_stat; 90 u32 product; 91 u32 vdo[3]; 92}; 93 94int typec_partner_set_identity(struct typec_partner *partner); 95int typec_cable_set_identity(struct typec_cable *cable); 96 97/* 98 * struct typec_altmode_desc - USB Type-C Alternate Mode Descriptor 99 * @svid: Standard or Vendor ID 100 * @mode: Index of the Mode 101 * @vdo: VDO returned by Discover Modes USB PD command 102 * @roles: Only for ports. DRP if the mode is available in both roles 103 * 104 * Description of an Alternate Mode which a connector, cable plug or partner 105 * supports. 106 */ 107struct typec_altmode_desc { 108 u16 svid; 109 u8 mode; 110 u32 vdo; 111 /* Only used with ports */ 112 enum typec_port_data roles; 113}; 114 115struct typec_altmode 116*typec_partner_register_altmode(struct typec_partner *partner, 117 const struct typec_altmode_desc *desc); 118struct typec_altmode 119*typec_plug_register_altmode(struct typec_plug *plug, 120 const struct typec_altmode_desc *desc); 121struct typec_altmode 122*typec_port_register_altmode(struct typec_port *port, 123 const struct typec_altmode_desc *desc); 124void typec_unregister_altmode(struct typec_altmode *altmode); 125 126struct typec_port *typec_altmode2port(struct typec_altmode *alt); 127 128void typec_altmode_update_active(struct typec_altmode *alt, bool active); 129 130enum typec_plug_index { 131 TYPEC_PLUG_SOP_P, 132 TYPEC_PLUG_SOP_PP, 133}; 134 135/* 136 * struct typec_plug_desc - USB Type-C Cable Plug Descriptor 137 * @index: SOP Prime for the plug connected to DFP and SOP Double Prime for the 138 * plug connected to UFP 139 * 140 * Represents USB Type-C Cable Plug. 141 */ 142struct typec_plug_desc { 143 enum typec_plug_index index; 144}; 145 146/* 147 * struct typec_cable_desc - USB Type-C Cable Descriptor 148 * @type: The plug type from USB PD Cable VDO 149 * @active: Is the cable active or passive 150 * @identity: Result of Discover Identity command 151 * 152 * Represents USB Type-C Cable attached to USB Type-C port. 153 */ 154struct typec_cable_desc { 155 enum typec_plug_type type; 156 unsigned int active:1; 157 struct usb_pd_identity *identity; 158}; 159 160/* 161 * struct typec_partner_desc - USB Type-C Partner Descriptor 162 * @usb_pd: USB Power Delivery support 163 * @accessory: Audio, Debug or none. 164 * @identity: Discover Identity command data 165 * 166 * Details about a partner that is attached to USB Type-C port. If @identity 167 * member exists when partner is registered, a directory named "identity" is 168 * created to sysfs for the partner device. 169 */ 170struct typec_partner_desc { 171 unsigned int usb_pd:1; 172 enum typec_accessory accessory; 173 struct usb_pd_identity *identity; 174}; 175 176/** 177 * struct typec_operations - USB Type-C Port Operations 178 * @try_role: Set data role preference for DRP port 179 * @dr_set: Set Data Role 180 * @pr_set: Set Power Role 181 * @vconn_set: Source VCONN 182 * @port_type_set: Set port type 183 */ 184struct typec_operations { 185 int (*try_role)(struct typec_port *port, int role); 186 int (*dr_set)(struct typec_port *port, enum typec_data_role role); 187 int (*pr_set)(struct typec_port *port, enum typec_role role); 188 int (*vconn_set)(struct typec_port *port, enum typec_role role); 189 int (*port_type_set)(struct typec_port *port, 190 enum typec_port_type type); 191}; 192 193/* 194 * struct typec_capability - USB Type-C Port Capabilities 195 * @type: Supported power role of the port 196 * @data: Supported data role of the port 197 * @revision: USB Type-C Specification release. Binary coded decimal 198 * @pd_revision: USB Power Delivery Specification revision if supported 199 * @prefer_role: Initial role preference (DRP ports). 200 * @accessory: Supported Accessory Modes 201 * @fwnode: Optional fwnode of the port 202 * @driver_data: Private pointer for driver specific info 203 * @ops: Port operations vector 204 * 205 * Static capabilities of a single USB Type-C port. 206 */ 207struct typec_capability { 208 enum typec_port_type type; 209 enum typec_port_data data; 210 u16 revision; /* 0120H = "1.2" */ 211 u16 pd_revision; /* 0300H = "3.0" */ 212 int prefer_role; 213 enum typec_accessory accessory[TYPEC_MAX_ACCESSORY]; 214 unsigned int orientation_aware:1; 215 216 struct fwnode_handle *fwnode; 217 void *driver_data; 218 219 const struct typec_operations *ops; 220}; 221 222/* Specific to try_role(). Indicates the user want's to clear the preference. */ 223#define TYPEC_NO_PREFERRED_ROLE (-1) 224 225struct typec_port *typec_register_port(struct device *parent, 226 const struct typec_capability *cap); 227void typec_unregister_port(struct typec_port *port); 228 229struct typec_partner *typec_register_partner(struct typec_port *port, 230 struct typec_partner_desc *desc); 231void typec_unregister_partner(struct typec_partner *partner); 232 233struct typec_cable *typec_register_cable(struct typec_port *port, 234 struct typec_cable_desc *desc); 235void typec_unregister_cable(struct typec_cable *cable); 236 237struct typec_cable *typec_cable_get(struct typec_port *port); 238void typec_cable_put(struct typec_cable *cable); 239int typec_cable_is_active(struct typec_cable *cable); 240 241struct typec_plug *typec_register_plug(struct typec_cable *cable, 242 struct typec_plug_desc *desc); 243void typec_unregister_plug(struct typec_plug *plug); 244 245void typec_set_data_role(struct typec_port *port, enum typec_data_role role); 246void typec_set_pwr_role(struct typec_port *port, enum typec_role role); 247void typec_set_vconn_role(struct typec_port *port, enum typec_role role); 248void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode); 249 250int typec_set_orientation(struct typec_port *port, 251 enum typec_orientation orientation); 252enum typec_orientation typec_get_orientation(struct typec_port *port); 253int typec_set_mode(struct typec_port *port, int mode); 254 255void *typec_get_drvdata(struct typec_port *port); 256 257int typec_find_port_power_role(const char *name); 258int typec_find_power_role(const char *name); 259int typec_find_port_data_role(const char *name); 260#endif /* __LINUX_USB_TYPEC_H */