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. */
18enum {
19 CROS_EC_ALTMODE_DP = 0,
20 CROS_EC_ALTMODE_TBT,
21 CROS_EC_ALTMODE_MAX,
22};
23
24/* Container for altmode pointer nodes. */
25struct 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. */
31struct 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};
43
44/* Per port data. */
45struct cros_typec_port {
46 struct typec_port *port;
47 int port_num;
48 /* Initial capabilities for the port. */
49 struct typec_capability caps;
50 struct typec_partner *partner;
51 struct typec_cable *cable;
52 /* SOP' plug. */
53 struct typec_plug *plug;
54 /* Port partner PD identity info. */
55 struct usb_pd_identity p_identity;
56 /* Port cable PD identity info. */
57 struct usb_pd_identity c_identity;
58 struct typec_switch *ori_sw;
59 struct typec_mux *mux;
60 struct typec_retimer *retimer;
61 struct usb_role_switch *role_sw;
62
63 /* Variables keeping track of switch state. */
64 struct typec_mux_state state;
65 uint8_t mux_flags;
66 uint8_t role;
67
68 struct typec_altmode *port_altmode[CROS_EC_ALTMODE_MAX];
69
70 /* Flag indicating that PD partner discovery data parsing is completed. */
71 bool sop_disc_done;
72 bool sop_prime_disc_done;
73 struct ec_response_typec_discovery *disc_data;
74 struct list_head partner_mode_list;
75 struct list_head plug_mode_list;
76
77 /* PDO-related structs */
78 struct usb_power_delivery *partner_pd;
79 struct usb_power_delivery_capabilities *partner_src_caps;
80 struct usb_power_delivery_capabilities *partner_sink_caps;
81
82 struct cros_typec_data *typec_data;
83};
84
85#endif /* __CROS_EC_TYPEC__ */
86

source code of linux/drivers/platform/chrome/cros_ec_typec.h