| 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_USB4, |
| 22 | CROS_EC_ALTMODE_MAX, |
| 23 | }; |
| 24 | |
| 25 | /* Container for altmode pointer nodes. */ |
| 26 | struct cros_typec_altmode_node { |
| 27 | struct typec_altmode *amode; |
| 28 | struct list_head list; |
| 29 | }; |
| 30 | |
| 31 | /* Platform-specific data for the Chrome OS EC Type C controller. */ |
| 32 | struct cros_typec_data { |
| 33 | struct device *dev; |
| 34 | struct cros_ec_device *ec; |
| 35 | int num_ports; |
| 36 | unsigned int pd_ctrl_ver; |
| 37 | /* Array of ports, indexed by port number. */ |
| 38 | struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS]; |
| 39 | struct notifier_block nb; |
| 40 | struct work_struct port_work; |
| 41 | bool typec_cmd_supported; |
| 42 | bool needs_mux_ack; |
| 43 | bool ap_driven_altmode; |
| 44 | }; |
| 45 | |
| 46 | /* Per port data. */ |
| 47 | struct cros_typec_port { |
| 48 | struct typec_port *port; |
| 49 | int port_num; |
| 50 | /* Initial capabilities for the port. */ |
| 51 | struct typec_capability caps; |
| 52 | struct typec_partner *partner; |
| 53 | struct typec_cable *cable; |
| 54 | /* SOP' plug. */ |
| 55 | struct typec_plug *plug; |
| 56 | /* Port partner PD identity info. */ |
| 57 | struct usb_pd_identity p_identity; |
| 58 | /* Port cable PD identity info. */ |
| 59 | struct usb_pd_identity c_identity; |
| 60 | struct typec_switch *ori_sw; |
| 61 | struct typec_mux *mux; |
| 62 | struct typec_retimer *retimer; |
| 63 | struct usb_role_switch *role_sw; |
| 64 | |
| 65 | /* Variables keeping track of switch state. */ |
| 66 | struct typec_mux_state state; |
| 67 | uint8_t mux_flags; |
| 68 | uint8_t role; |
| 69 | |
| 70 | struct typec_altmode *port_altmode[CROS_EC_ALTMODE_MAX]; |
| 71 | |
| 72 | /* Flag indicating that PD partner discovery data parsing is completed. */ |
| 73 | bool sop_disc_done; |
| 74 | bool sop_prime_disc_done; |
| 75 | struct ec_response_typec_discovery *disc_data; |
| 76 | struct list_head partner_mode_list; |
| 77 | struct list_head plug_mode_list; |
| 78 | |
| 79 | /* PDO-related structs */ |
| 80 | struct usb_power_delivery *partner_pd; |
| 81 | struct usb_power_delivery_capabilities *partner_src_caps; |
| 82 | struct usb_power_delivery_capabilities *partner_sink_caps; |
| 83 | |
| 84 | struct cros_typec_data *typec_data; |
| 85 | }; |
| 86 | |
| 87 | #endif /* __CROS_EC_TYPEC__ */ |
| 88 |
