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 #include <linux/android_kabi.h> 9 10 struct typec_mux; 11 struct typec_switch; 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 ANDROID_KABI_RESERVE(1); 19 }; 20 21 struct typec_cable { 22 struct device dev; 23 enum typec_plug_type type; 24 struct usb_pd_identity *identity; 25 unsigned int active:1; 26 u16 pd_revision; /* 0300H = "3.0" */ 27 ANDROID_KABI_RESERVE(1); 28 }; 29 30 struct typec_partner { 31 struct device dev; 32 unsigned int usb_pd:1; 33 struct usb_pd_identity *identity; 34 enum typec_accessory accessory; 35 struct ida mode_ids; 36 int num_altmodes; 37 u16 pd_revision; /* 0300H = "3.0" */ 38 enum usb_pd_svdm_ver svdm_version; 39 40 struct usb_power_delivery *pd; 41 ANDROID_KABI_RESERVE(1); 42 }; 43 44 struct typec_port { 45 unsigned int id; 46 struct device dev; 47 struct ida mode_ids; 48 49 struct usb_power_delivery *pd; 50 51 int prefer_role; 52 enum typec_data_role data_role; 53 enum typec_role pwr_role; 54 enum typec_role vconn_role; 55 enum typec_pwr_opmode pwr_opmode; 56 enum typec_port_type port_type; 57 struct mutex port_type_lock; 58 59 enum typec_orientation orientation; 60 struct typec_switch *sw; 61 struct typec_mux *mux; 62 struct typec_retimer *retimer; 63 64 const struct typec_capability *cap; 65 const struct typec_operations *ops; 66 ANDROID_KABI_RESERVE(1); 67 }; 68 69 #define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev) 70 #define to_typec_plug(_dev_) container_of(_dev_, struct typec_plug, dev) 71 #define to_typec_cable(_dev_) container_of(_dev_, struct typec_cable, dev) 72 #define to_typec_partner(_dev_) container_of(_dev_, struct typec_partner, dev) 73 74 extern const struct device_type typec_partner_dev_type; 75 extern const struct device_type typec_cable_dev_type; 76 extern const struct device_type typec_plug_dev_type; 77 extern const struct device_type typec_port_dev_type; 78 79 #define is_typec_partner(dev) ((dev)->type == &typec_partner_dev_type) 80 #define is_typec_cable(dev) ((dev)->type == &typec_cable_dev_type) 81 #define is_typec_plug(dev) ((dev)->type == &typec_plug_dev_type) 82 #define is_typec_port(dev) ((dev)->type == &typec_port_dev_type) 83 84 extern struct class typec_mux_class; 85 extern struct class retimer_class; 86 extern struct class typec_class; 87 88 #if defined(CONFIG_ACPI) 89 int typec_link_ports(struct typec_port *connector); 90 void typec_unlink_ports(struct typec_port *connector); 91 #else typec_link_ports(struct typec_port * connector)92static inline int typec_link_ports(struct typec_port *connector) { return 0; } typec_unlink_ports(struct typec_port * connector)93static inline void typec_unlink_ports(struct typec_port *connector) { } 94 #endif 95 96 #endif /* __USB_TYPEC_CLASS__ */ 97