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