Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 
0003 #ifndef __USB_TYPEC_CLASS__
0004 #define __USB_TYPEC_CLASS__
0005 
0006 #include <linux/device.h>
0007 #include <linux/usb/typec.h>
0008 
0009 struct typec_mux;
0010 struct typec_switch;
0011 
0012 struct typec_plug {
0013     struct device           dev;
0014     enum typec_plug_index       index;
0015     struct ida          mode_ids;
0016     int             num_altmodes;
0017 };
0018 
0019 struct typec_cable {
0020     struct device           dev;
0021     enum typec_plug_type        type;
0022     struct usb_pd_identity      *identity;
0023     unsigned int            active:1;
0024     u16             pd_revision; /* 0300H = "3.0" */
0025 };
0026 
0027 struct typec_partner {
0028     struct device           dev;
0029     unsigned int            usb_pd:1;
0030     struct usb_pd_identity      *identity;
0031     enum typec_accessory        accessory;
0032     struct ida          mode_ids;
0033     int             num_altmodes;
0034     u16             pd_revision; /* 0300H = "3.0" */
0035     enum usb_pd_svdm_ver        svdm_version;
0036 
0037     struct usb_power_delivery   *pd;
0038 };
0039 
0040 struct typec_port {
0041     unsigned int            id;
0042     struct device           dev;
0043     struct ida          mode_ids;
0044 
0045     struct usb_power_delivery   *pd;
0046 
0047     int             prefer_role;
0048     enum typec_data_role        data_role;
0049     enum typec_role         pwr_role;
0050     enum typec_role         vconn_role;
0051     enum typec_pwr_opmode       pwr_opmode;
0052     enum typec_port_type        port_type;
0053     struct mutex            port_type_lock;
0054 
0055     enum typec_orientation      orientation;
0056     struct typec_switch     *sw;
0057     struct typec_mux        *mux;
0058     struct typec_retimer        *retimer;
0059 
0060     const struct typec_capability   *cap;
0061     const struct typec_operations   *ops;
0062 };
0063 
0064 #define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev)
0065 #define to_typec_plug(_dev_) container_of(_dev_, struct typec_plug, dev)
0066 #define to_typec_cable(_dev_) container_of(_dev_, struct typec_cable, dev)
0067 #define to_typec_partner(_dev_) container_of(_dev_, struct typec_partner, dev)
0068 
0069 extern const struct device_type typec_partner_dev_type;
0070 extern const struct device_type typec_cable_dev_type;
0071 extern const struct device_type typec_plug_dev_type;
0072 extern const struct device_type typec_port_dev_type;
0073 
0074 #define is_typec_partner(dev) ((dev)->type == &typec_partner_dev_type)
0075 #define is_typec_cable(dev) ((dev)->type == &typec_cable_dev_type)
0076 #define is_typec_plug(dev) ((dev)->type == &typec_plug_dev_type)
0077 #define is_typec_port(dev) ((dev)->type == &typec_port_dev_type)
0078 
0079 extern struct class typec_mux_class;
0080 extern struct class retimer_class;
0081 extern struct class typec_class;
0082 
0083 #if defined(CONFIG_ACPI)
0084 int typec_link_ports(struct typec_port *connector);
0085 void typec_unlink_ports(struct typec_port *connector);
0086 #else
0087 static inline int typec_link_ports(struct typec_port *connector) { return 0; }
0088 static inline void typec_unlink_ports(struct typec_port *connector) { }
0089 #endif
0090 
0091 #endif /* __USB_TYPEC_CLASS__ */