diff options
| author | Heikki Krogerus <heikki.krogerus@linux.intel.com> | 2017-03-21 07:56:47 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-03-23 08:48:44 -0400 |
| commit | fab9288428ec0fbd09adb67d3a17c51d78196f9c (patch) | |
| tree | 2b6ee821f295243b37fdaa670d2fcf79286783be /include/linux | |
| parent | e1fe7b6a7b376bfb54558725ddb2a89aaaa4adcc (diff) | |
usb: USB Type-C connector class
The purpose of USB Type-C connector class is to provide
unified interface for the user space to get the status and
basic information about USB Type-C connectors on a system,
control over data role swapping, and when the port supports
USB Power Delivery, also control over power role swapping
and Alternate Modes.
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-and-Tested-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/usb/typec.h | 243 |
1 files changed, 243 insertions, 0 deletions
diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h new file mode 100644 index 000000000000..ec78204964ab --- /dev/null +++ b/include/linux/usb/typec.h | |||
| @@ -0,0 +1,243 @@ | |||
| 1 | |||
| 2 | #ifndef __LINUX_USB_TYPEC_H | ||
| 3 | #define __LINUX_USB_TYPEC_H | ||
| 4 | |||
| 5 | #include <linux/types.h> | ||
| 6 | |||
| 7 | /* XXX: Once we have a header for USB Power Delivery, this belongs there */ | ||
| 8 | #define ALTMODE_MAX_MODES 6 | ||
| 9 | |||
| 10 | /* USB Type-C Specification releases */ | ||
| 11 | #define USB_TYPEC_REV_1_0 0x100 /* 1.0 */ | ||
| 12 | #define USB_TYPEC_REV_1_1 0x110 /* 1.1 */ | ||
| 13 | #define USB_TYPEC_REV_1_2 0x120 /* 1.2 */ | ||
| 14 | |||
| 15 | struct typec_altmode; | ||
| 16 | struct typec_partner; | ||
| 17 | struct typec_cable; | ||
| 18 | struct typec_plug; | ||
| 19 | struct typec_port; | ||
| 20 | |||
| 21 | struct fwnode_handle; | ||
| 22 | |||
| 23 | enum typec_port_type { | ||
| 24 | TYPEC_PORT_DFP, | ||
| 25 | TYPEC_PORT_UFP, | ||
| 26 | TYPEC_PORT_DRP, | ||
| 27 | }; | ||
| 28 | |||
| 29 | enum typec_plug_type { | ||
| 30 | USB_PLUG_NONE, | ||
| 31 | USB_PLUG_TYPE_A, | ||
| 32 | USB_PLUG_TYPE_B, | ||
| 33 | USB_PLUG_TYPE_C, | ||
| 34 | USB_PLUG_CAPTIVE, | ||
| 35 | }; | ||
| 36 | |||
| 37 | enum typec_data_role { | ||
| 38 | TYPEC_DEVICE, | ||
| 39 | TYPEC_HOST, | ||
| 40 | }; | ||
| 41 | |||
| 42 | enum typec_role { | ||
| 43 | TYPEC_SINK, | ||
| 44 | TYPEC_SOURCE, | ||
| 45 | }; | ||
| 46 | |||
| 47 | enum typec_pwr_opmode { | ||
| 48 | TYPEC_PWR_MODE_USB, | ||
| 49 | TYPEC_PWR_MODE_1_5A, | ||
| 50 | TYPEC_PWR_MODE_3_0A, | ||
| 51 | TYPEC_PWR_MODE_PD, | ||
| 52 | }; | ||
| 53 | |||
| 54 | enum typec_accessory { | ||
| 55 | TYPEC_ACCESSORY_NONE, | ||
| 56 | TYPEC_ACCESSORY_AUDIO, | ||
| 57 | TYPEC_ACCESSORY_DEBUG, | ||
| 58 | }; | ||
| 59 | |||
| 60 | #define TYPEC_MAX_ACCESSORY 3 | ||
| 61 | |||
| 62 | /* | ||
| 63 | * struct usb_pd_identity - USB Power Delivery identity data | ||
| 64 | * @id_header: ID Header VDO | ||
| 65 | * @cert_stat: Cert Stat VDO | ||
| 66 | * @product: Product VDO | ||
| 67 | * | ||
| 68 | * USB power delivery Discover Identity command response data. | ||
| 69 | * | ||
| 70 | * REVISIT: This is USB Power Delivery specific information, so this structure | ||
| 71 | * probable belongs to USB Power Delivery header file once we have them. | ||
| 72 | */ | ||
| 73 | struct usb_pd_identity { | ||
| 74 | u32 id_header; | ||
| 75 | u32 cert_stat; | ||
| 76 | u32 product; | ||
| 77 | }; | ||
| 78 | |||
| 79 | int typec_partner_set_identity(struct typec_partner *partner); | ||
| 80 | int typec_cable_set_identity(struct typec_cable *cable); | ||
| 81 | |||
| 82 | /* | ||
| 83 | * struct typec_mode_desc - Individual Mode of an Alternate Mode | ||
| 84 | * @index: Index of the Mode within the SVID | ||
| 85 | * @vdo: VDO returned by Discover Modes USB PD command | ||
| 86 | * @desc: Optional human readable description of the mode | ||
| 87 | * @roles: Only for ports. DRP if the mode is available in both roles | ||
| 88 | * | ||
| 89 | * Description of a mode of an Alternate Mode which a connector, cable plug or | ||
| 90 | * partner supports. Every mode will have it's own sysfs group. The details are | ||
| 91 | * the VDO returned by discover modes command, description for the mode and | ||
| 92 | * active flag telling has the mode being entered or not. | ||
| 93 | */ | ||
| 94 | struct typec_mode_desc { | ||
| 95 | int index; | ||
| 96 | u32 vdo; | ||
| 97 | char *desc; | ||
| 98 | /* Only used with ports */ | ||
| 99 | enum typec_port_type roles; | ||
| 100 | }; | ||
| 101 | |||
| 102 | /* | ||
| 103 | * struct typec_altmode_desc - USB Type-C Alternate Mode Descriptor | ||
| 104 | * @svid: Standard or Vendor ID | ||
| 105 | * @n_modes: Number of modes | ||
| 106 | * @modes: Array of modes supported by the Alternate Mode | ||
| 107 | * | ||
| 108 | * Representation of an Alternate Mode that has SVID assigned by USB-IF. The | ||
| 109 | * array of modes will list the modes of a particular SVID that are supported by | ||
| 110 | * a connector, partner of a cable plug. | ||
| 111 | */ | ||
| 112 | struct typec_altmode_desc { | ||
| 113 | u16 svid; | ||
| 114 | int n_modes; | ||
| 115 | struct typec_mode_desc modes[ALTMODE_MAX_MODES]; | ||
| 116 | }; | ||
| 117 | |||
| 118 | struct typec_altmode | ||
| 119 | *typec_partner_register_altmode(struct typec_partner *partner, | ||
| 120 | struct typec_altmode_desc *desc); | ||
| 121 | struct typec_altmode | ||
| 122 | *typec_plug_register_altmode(struct typec_plug *plug, | ||
| 123 | struct typec_altmode_desc *desc); | ||
| 124 | struct typec_altmode | ||
| 125 | *typec_port_register_altmode(struct typec_port *port, | ||
| 126 | struct typec_altmode_desc *desc); | ||
| 127 | void typec_unregister_altmode(struct typec_altmode *altmode); | ||
| 128 | |||
| 129 | struct typec_port *typec_altmode2port(struct typec_altmode *alt); | ||
| 130 | |||
| 131 | void typec_altmode_update_active(struct typec_altmode *alt, int mode, | ||
| 132 | bool active); | ||
| 133 | |||
| 134 | enum typec_plug_index { | ||
| 135 | TYPEC_PLUG_SOP_P, | ||
| 136 | TYPEC_PLUG_SOP_PP, | ||
| 137 | }; | ||
| 138 | |||
| 139 | /* | ||
| 140 | * struct typec_plug_desc - USB Type-C Cable Plug Descriptor | ||
| 141 | * @index: SOP Prime for the plug connected to DFP and SOP Double Prime for the | ||
| 142 | * plug connected to UFP | ||
| 143 | * | ||
| 144 | * Represents USB Type-C Cable Plug. | ||
| 145 | */ | ||
| 146 | struct typec_plug_desc { | ||
| 147 | enum typec_plug_index index; | ||
| 148 | }; | ||
| 149 | |||
| 150 | /* | ||
| 151 | * struct typec_cable_desc - USB Type-C Cable Descriptor | ||
| 152 | * @type: The plug type from USB PD Cable VDO | ||
| 153 | * @active: Is the cable active or passive | ||
| 154 | * @identity: Result of Discover Identity command | ||
| 155 | * | ||
| 156 | * Represents USB Type-C Cable attached to USB Type-C port. | ||
| 157 | */ | ||
| 158 | struct typec_cable_desc { | ||
| 159 | enum typec_plug_type type; | ||
| 160 | unsigned int active:1; | ||
| 161 | struct usb_pd_identity *identity; | ||
| 162 | }; | ||
| 163 | |||
| 164 | /* | ||
| 165 | * struct typec_partner_desc - USB Type-C Partner Descriptor | ||
| 166 | * @usb_pd: USB Power Delivery support | ||
| 167 | * @accessory: Audio, Debug or none. | ||
| 168 | * @identity: Discover Identity command data | ||
| 169 | * | ||
| 170 | * Details about a partner that is attached to USB Type-C port. If @identity | ||
| 171 | * member exists when partner is registered, a directory named "identity" is | ||
| 172 | * created to sysfs for the partner device. | ||
| 173 | */ | ||
| 174 | struct typec_partner_desc { | ||
| 175 | unsigned int usb_pd:1; | ||
| 176 | enum typec_accessory accessory; | ||
| 177 | struct usb_pd_identity *identity; | ||
| 178 | }; | ||
| 179 | |||
| 180 | /* | ||
| 181 | * struct typec_capability - USB Type-C Port Capabilities | ||
| 182 | * @role: DFP (Host-only), UFP (Device-only) or DRP (Dual Role) | ||
| 183 | * @revision: USB Type-C Specification release. Binary coded decimal | ||
| 184 | * @pd_revision: USB Power Delivery Specification revision if supported | ||
| 185 | * @prefer_role: Initial role preference | ||
| 186 | * @accessory: Supported Accessory Modes | ||
| 187 | * @fwnode: Optional fwnode of the port | ||
| 188 | * @try_role: Set data role preference for DRP port | ||
| 189 | * @dr_set: Set Data Role | ||
| 190 | * @pr_set: Set Power Role | ||
| 191 | * @vconn_set: Set VCONN Role | ||
| 192 | * @activate_mode: Enter/exit given Alternate Mode | ||
| 193 | * | ||
| 194 | * Static capabilities of a single USB Type-C port. | ||
| 195 | */ | ||
| 196 | struct typec_capability { | ||
| 197 | enum typec_port_type type; | ||
| 198 | u16 revision; /* 0120H = "1.2" */ | ||
| 199 | u16 pd_revision; /* 0300H = "3.0" */ | ||
| 200 | int prefer_role; | ||
| 201 | enum typec_accessory accessory[TYPEC_MAX_ACCESSORY]; | ||
| 202 | |||
| 203 | struct fwnode_handle *fwnode; | ||
| 204 | |||
| 205 | int (*try_role)(const struct typec_capability *, | ||
| 206 | int role); | ||
| 207 | |||
| 208 | int (*dr_set)(const struct typec_capability *, | ||
| 209 | enum typec_data_role); | ||
| 210 | int (*pr_set)(const struct typec_capability *, | ||
| 211 | enum typec_role); | ||
| 212 | int (*vconn_set)(const struct typec_capability *, | ||
| 213 | enum typec_role); | ||
| 214 | |||
| 215 | int (*activate_mode)(const struct typec_capability *, | ||
| 216 | int mode, int activate); | ||
| 217 | }; | ||
| 218 | |||
| 219 | /* Specific to try_role(). Indicates the user want's to clear the preference. */ | ||
| 220 | #define TYPEC_NO_PREFERRED_ROLE (-1) | ||
| 221 | |||
| 222 | struct typec_port *typec_register_port(struct device *parent, | ||
| 223 | const struct typec_capability *cap); | ||
| 224 | void typec_unregister_port(struct typec_port *port); | ||
| 225 | |||
| 226 | struct typec_partner *typec_register_partner(struct typec_port *port, | ||
| 227 | struct typec_partner_desc *desc); | ||
| 228 | void typec_unregister_partner(struct typec_partner *partner); | ||
| 229 | |||
| 230 | struct typec_cable *typec_register_cable(struct typec_port *port, | ||
| 231 | struct typec_cable_desc *desc); | ||
| 232 | void typec_unregister_cable(struct typec_cable *cable); | ||
| 233 | |||
| 234 | struct typec_plug *typec_register_plug(struct typec_cable *cable, | ||
| 235 | struct typec_plug_desc *desc); | ||
| 236 | void typec_unregister_plug(struct typec_plug *plug); | ||
| 237 | |||
| 238 | void typec_set_data_role(struct typec_port *port, enum typec_data_role role); | ||
| 239 | void typec_set_pwr_role(struct typec_port *port, enum typec_role role); | ||
| 240 | void typec_set_vconn_role(struct typec_port *port, enum typec_role role); | ||
| 241 | void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode); | ||
| 242 | |||
| 243 | #endif /* __LINUX_USB_TYPEC_H */ | ||
