1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 3 #ifndef __CROS_EC_TYPEC__ 4 #define __CROS_EC_TYPEC__ 5 6 #include <linux/list.h> 7 #include <linux/notifier.h> 8 #include <linux/platform_data/cros_ec_proto.h> 9 #include <linux/usb/pd.h> 10 #include <linux/usb/role.h> 11 #include <linux/usb/typec.h> 12 #include <linux/usb/typec_altmode.h> 13 #include <linux/usb/typec_mux.h> 14 #include <linux/usb/typec_retimer.h> 15 #include <linux/workqueue.h> 16 17 /* Supported alt modes. */ 18 enum { 19 CROS_EC_ALTMODE_DP = 0, 20 CROS_EC_ALTMODE_TBT, 21 CROS_EC_ALTMODE_MAX, 22 }; 23 24 /* Container for altmode pointer nodes. */ 25 struct cros_typec_altmode_node { 26 struct typec_altmode *amode; 27 struct list_head list; 28 }; 29 30 /* Platform-specific data for the Chrome OS EC Type C controller. */ 31 struct cros_typec_data { 32 struct device *dev; 33 struct cros_ec_device *ec; 34 int num_ports; 35 unsigned int pd_ctrl_ver; 36 /* Array of ports, indexed by port number. */ 37 struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS]; 38 struct notifier_block nb; 39 struct work_struct port_work; 40 bool typec_cmd_supported; 41 bool needs_mux_ack; 42 bool ap_driven_altmode; 43 }; 44 45 /* Per port data. */ 46 struct cros_typec_port { 47 struct typec_port *port; 48 int port_num; 49 /* Initial capabilities for the port. */ 50 struct typec_capability caps; 51 struct typec_partner *partner; 52 struct typec_cable *cable; 53 /* SOP' plug. */ 54 struct typec_plug *plug; 55 /* Port partner PD identity info. */ 56 struct usb_pd_identity p_identity; 57 /* Port cable PD identity info. */ 58 struct usb_pd_identity c_identity; 59 struct typec_switch *ori_sw; 60 struct typec_mux *mux; 61 struct typec_retimer *retimer; 62 struct usb_role_switch *role_sw; 63 64 /* Variables keeping track of switch state. */ 65 struct typec_mux_state state; 66 uint8_t mux_flags; 67 uint8_t role; 68 69 struct typec_altmode *port_altmode[CROS_EC_ALTMODE_MAX]; 70 71 /* Flag indicating that PD partner discovery data parsing is completed. */ 72 bool sop_disc_done; 73 bool sop_prime_disc_done; 74 struct ec_response_typec_discovery *disc_data; 75 struct list_head partner_mode_list; 76 struct list_head plug_mode_list; 77 78 /* PDO-related structs */ 79 struct usb_power_delivery *partner_pd; 80 struct usb_power_delivery_capabilities *partner_src_caps; 81 struct usb_power_delivery_capabilities *partner_sink_caps; 82 83 struct cros_typec_data *typec_data; 84 }; 85 86 #endif /* __CROS_EC_TYPEC__ */ 87