1
2
3
4
5
6 #ifndef __LINUX_USB_TCPM_H
7 #define __LINUX_USB_TCPM_H
8
9 #include <linux/bitops.h>
10 #include <linux/usb/typec.h>
11 #include "pd.h"
12
13 enum typec_cc_status {
14 TYPEC_CC_OPEN,
15 TYPEC_CC_RA,
16 TYPEC_CC_RD,
17 TYPEC_CC_RP_DEF,
18 TYPEC_CC_RP_1_5,
19 TYPEC_CC_RP_3_0,
20 };
21
22 enum typec_cc_polarity {
23 TYPEC_POLARITY_CC1,
24 TYPEC_POLARITY_CC2,
25 };
26
27
28 #define PD_T_TCPC_TX_TIMEOUT 100
29 #define PD_ROLE_SWAP_TIMEOUT (MSEC_PER_SEC * 10)
30 #define PD_PPS_CTRL_TIMEOUT (MSEC_PER_SEC * 10)
31
32 enum tcpm_transmit_status {
33 TCPC_TX_SUCCESS = 0,
34 TCPC_TX_DISCARDED = 1,
35 TCPC_TX_FAILED = 2,
36 };
37
38 enum tcpm_transmit_type {
39 TCPC_TX_SOP = 0,
40 TCPC_TX_SOP_PRIME = 1,
41 TCPC_TX_SOP_PRIME_PRIME = 2,
42 TCPC_TX_SOP_DEBUG_PRIME = 3,
43 TCPC_TX_SOP_DEBUG_PRIME_PRIME = 4,
44 TCPC_TX_HARD_RESET = 5,
45 TCPC_TX_CABLE_RESET = 6,
46 TCPC_TX_BIST_MODE_2 = 7
47 };
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 struct tcpc_config {
68 const u32 *src_pdo;
69 unsigned int nr_src_pdo;
70
71 const u32 *snk_pdo;
72 unsigned int nr_snk_pdo;
73
74 const u32 *snk_vdo;
75 unsigned int nr_snk_vdo;
76
77 unsigned int operating_snk_mw;
78
79 enum typec_port_type type;
80 enum typec_port_data data;
81 enum typec_role default_role;
82 bool try_role_hw;
83 bool self_powered;
84
85 const struct typec_altmode_desc *alt_modes;
86 };
87
88
89 #define TCPC_MUX_USB_ENABLED BIT(0)
90 #define TCPC_MUX_DP_ENABLED BIT(1)
91 #define TCPC_MUX_POLARITY_INVERTED BIT(2)
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 struct tcpc_dev {
124 const struct tcpc_config *config;
125 struct fwnode_handle *fwnode;
126
127 int (*init)(struct tcpc_dev *dev);
128 int (*get_vbus)(struct tcpc_dev *dev);
129 int (*get_current_limit)(struct tcpc_dev *dev);
130 int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc);
131 int (*get_cc)(struct tcpc_dev *dev, enum typec_cc_status *cc1,
132 enum typec_cc_status *cc2);
133 int (*set_polarity)(struct tcpc_dev *dev,
134 enum typec_cc_polarity polarity);
135 int (*set_vconn)(struct tcpc_dev *dev, bool on);
136 int (*set_vbus)(struct tcpc_dev *dev, bool on, bool charge);
137 int (*set_current_limit)(struct tcpc_dev *dev, u32 max_ma, u32 mv);
138 int (*set_pd_rx)(struct tcpc_dev *dev, bool on);
139 int (*set_roles)(struct tcpc_dev *dev, bool attached,
140 enum typec_role role, enum typec_data_role data);
141 int (*start_toggling)(struct tcpc_dev *dev,
142 enum typec_port_type port_type,
143 enum typec_cc_status cc);
144 int (*try_role)(struct tcpc_dev *dev, int role);
145 int (*pd_transmit)(struct tcpc_dev *dev, enum tcpm_transmit_type type,
146 const struct pd_message *msg);
147 };
148
149 struct tcpm_port;
150
151 struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc);
152 void tcpm_unregister_port(struct tcpm_port *port);
153
154 void tcpm_vbus_change(struct tcpm_port *port);
155 void tcpm_cc_change(struct tcpm_port *port);
156 void tcpm_pd_receive(struct tcpm_port *port,
157 const struct pd_message *msg);
158 void tcpm_pd_transmit_complete(struct tcpm_port *port,
159 enum tcpm_transmit_status status);
160 void tcpm_pd_hard_reset(struct tcpm_port *port);
161 void tcpm_tcpc_reset(struct tcpm_port *port);
162
163 #endif