1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 #ifndef __USB_TYPEC_CLASS__ 4 #define __USB_TYPEC_CLASS__ 5 6 #include <linux/device.h> 7 #include <linux/usb/typec.h> 8 9 struct typec_mux; 10 struct typec_switch; 11 struct usb_device; 12 13 struct typec_plug { 14 struct device dev; 15 enum typec_plug_index index; 16 struct ida mode_ids; 17 int num_altmodes; 18 }; 19 20 struct typec_cable { 21 struct device dev; 22 enum typec_plug_type type; 23 struct usb_pd_identity *identity; 24 unsigned int active:1; 25 u16 pd_revision; /* 0300H = "3.0" */ 26 enum usb_pd_svdm_ver svdm_version; 27 }; 28 29 struct typec_partner { 30 struct device dev; 31 unsigned int usb_pd:1; 32 struct usb_pd_identity *identity; 33 enum typec_accessory accessory; 34 struct ida mode_ids; 35 int num_altmodes; 36 u16 pd_revision; /* 0300H = "3.0" */ 37 enum usb_pd_svdm_ver svdm_version; 38 enum usb_mode usb_mode; 39 u8 usb_capability; 40 41 struct usb_power_delivery *pd; 42 43 void (*attach)(struct typec_partner *partner, struct device *dev); 44 void (*deattach)(struct typec_partner *partner, struct device *dev); 45 }; 46 47 struct typec_port { 48 unsigned int id; 49 struct device dev; 50 struct ida mode_ids; 51 52 struct usb_power_delivery *pd; 53 54 int prefer_role; 55 enum typec_data_role data_role; 56 enum typec_role pwr_role; 57 enum typec_role vconn_role; 58 enum typec_pwr_opmode pwr_opmode; 59 enum typec_port_type port_type; 60 enum usb_mode usb_mode; 61 struct mutex port_type_lock; 62 struct mutex partner_link_lock; 63 64 enum typec_orientation orientation; 65 struct typec_switch *sw; 66 struct typec_mux *mux; 67 struct typec_retimer *retimer; 68 69 const struct typec_capability *cap; 70 const struct typec_operations *ops; 71 72 struct typec_connector con; 73 74 /* 75 * REVISIT: Only USB devices for now. If there are others, these need to 76 * be converted into a list. 77 * 78 * NOTE: These may be registered first before the typec_partner, so they 79 * will always have to be kept here instead of struct typec_partner. 80 */ 81 struct device *usb2_dev; 82 struct device *usb3_dev; 83 }; 84 85 #define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev) 86 #define to_typec_plug(_dev_) container_of(_dev_, struct typec_plug, dev) 87 #define to_typec_cable(_dev_) container_of(_dev_, struct typec_cable, dev) 88 #define to_typec_partner(_dev_) container_of(_dev_, struct typec_partner, dev) 89 90 extern const struct device_type typec_partner_dev_type; 91 extern const struct device_type typec_cable_dev_type; 92 extern const struct device_type typec_plug_dev_type; 93 extern const struct device_type typec_port_dev_type; 94 95 #define is_typec_partner(dev) ((dev)->type == &typec_partner_dev_type) 96 #define is_typec_cable(dev) ((dev)->type == &typec_cable_dev_type) 97 #define is_typec_plug(dev) ((dev)->type == &typec_plug_dev_type) 98 #define is_typec_port(dev) ((dev)->type == &typec_port_dev_type) 99 100 extern const struct class typec_mux_class; 101 extern const struct class retimer_class; 102 extern const struct class typec_class; 103 104 #if defined(CONFIG_ACPI) 105 int typec_link_ports(struct typec_port *connector); 106 void typec_unlink_ports(struct typec_port *connector); 107 #else 108 static inline int typec_link_ports(struct typec_port *connector) { return 0; } 109 static inline void typec_unlink_ports(struct typec_port *connector) { } 110 #endif 111 112 #endif /* __USB_TYPEC_CLASS__ */ 113