1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef __LINUX_USB_TCPM_H
16#define __LINUX_USB_TCPM_H
17
18#include <linux/bitops.h>
19#include <linux/usb/typec.h>
20#include "pd.h"
21
22enum typec_cc_status {
23 TYPEC_CC_OPEN,
24 TYPEC_CC_RA,
25 TYPEC_CC_RD,
26 TYPEC_CC_RP_DEF,
27 TYPEC_CC_RP_1_5,
28 TYPEC_CC_RP_3_0,
29};
30
31enum typec_cc_polarity {
32 TYPEC_POLARITY_CC1,
33 TYPEC_POLARITY_CC2,
34};
35
36
37#define PD_T_TCPC_TX_TIMEOUT 100
38#define PD_ROLE_SWAP_TIMEOUT (MSEC_PER_SEC * 10)
39
40enum tcpm_transmit_status {
41 TCPC_TX_SUCCESS = 0,
42 TCPC_TX_DISCARDED = 1,
43 TCPC_TX_FAILED = 2,
44};
45
46enum tcpm_transmit_type {
47 TCPC_TX_SOP = 0,
48 TCPC_TX_SOP_PRIME = 1,
49 TCPC_TX_SOP_PRIME_PRIME = 2,
50 TCPC_TX_SOP_DEBUG_PRIME = 3,
51 TCPC_TX_SOP_DEBUG_PRIME_PRIME = 4,
52 TCPC_TX_HARD_RESET = 5,
53 TCPC_TX_CABLE_RESET = 6,
54 TCPC_TX_BIST_MODE_2 = 7
55};
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78struct tcpc_config {
79 const u32 *src_pdo;
80 unsigned int nr_src_pdo;
81
82 const u32 *snk_pdo;
83 unsigned int nr_snk_pdo;
84
85 const u32 *snk_vdo;
86 unsigned int nr_snk_vdo;
87
88 unsigned int max_snk_mv;
89 unsigned int max_snk_ma;
90 unsigned int max_snk_mw;
91 unsigned int operating_snk_mw;
92
93 enum typec_port_type type;
94 enum typec_role default_role;
95 bool try_role_hw;
96
97 const struct typec_altmode_desc *alt_modes;
98};
99
100enum tcpc_usb_switch {
101 TCPC_USB_SWITCH_CONNECT,
102 TCPC_USB_SWITCH_DISCONNECT,
103};
104
105
106#define TCPC_MUX_USB_ENABLED BIT(0)
107#define TCPC_MUX_DP_ENABLED BIT(1)
108#define TCPC_MUX_POLARITY_INVERTED BIT(2)
109
110
111enum tcpc_mux_mode {
112 TYPEC_MUX_NONE = 0,
113 TYPEC_MUX_USB = TCPC_MUX_USB_ENABLED,
114 TYPEC_MUX_DP = TCPC_MUX_DP_ENABLED,
115 TYPEC_MUX_DOCK = TCPC_MUX_USB_ENABLED |
116 TCPC_MUX_DP_ENABLED,
117};
118
119struct tcpc_mux_dev {
120 int (*set)(struct tcpc_mux_dev *dev, enum tcpc_mux_mode mux_mode,
121 enum tcpc_usb_switch usb_config,
122 enum typec_cc_polarity polarity);
123 bool dfp_only;
124 void *priv_data;
125};
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156struct tcpc_dev {
157 const struct tcpc_config *config;
158
159 int (*init)(struct tcpc_dev *dev);
160 int (*get_vbus)(struct tcpc_dev *dev);
161 int (*get_current_limit)(struct tcpc_dev *dev);
162 int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc);
163 int (*get_cc)(struct tcpc_dev *dev, enum typec_cc_status *cc1,
164 enum typec_cc_status *cc2);
165 int (*set_polarity)(struct tcpc_dev *dev,
166 enum typec_cc_polarity polarity);
167 int (*set_vconn)(struct tcpc_dev *dev, bool on);
168 int (*set_vbus)(struct tcpc_dev *dev, bool on, bool charge);
169 int (*set_current_limit)(struct tcpc_dev *dev, u32 max_ma, u32 mv);
170 int (*set_pd_rx)(struct tcpc_dev *dev, bool on);
171 int (*set_roles)(struct tcpc_dev *dev, bool attached,
172 enum typec_role role, enum typec_data_role data);
173 int (*start_drp_toggling)(struct tcpc_dev *dev,
174 enum typec_cc_status cc);
175 int (*try_role)(struct tcpc_dev *dev, int role);
176 int (*pd_transmit)(struct tcpc_dev *dev, enum tcpm_transmit_type type,
177 const struct pd_message *msg);
178 struct tcpc_mux_dev *mux;
179};
180
181struct tcpm_port;
182
183struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc);
184void tcpm_unregister_port(struct tcpm_port *port);
185
186int tcpm_update_source_capabilities(struct tcpm_port *port, const u32 *pdo,
187 unsigned int nr_pdo);
188int tcpm_update_sink_capabilities(struct tcpm_port *port, const u32 *pdo,
189 unsigned int nr_pdo,
190 unsigned int max_snk_mv,
191 unsigned int max_snk_ma,
192 unsigned int max_snk_mw,
193 unsigned int operating_snk_mw);
194
195void tcpm_vbus_change(struct tcpm_port *port);
196void tcpm_cc_change(struct tcpm_port *port);
197void tcpm_pd_receive(struct tcpm_port *port,
198 const struct pd_message *msg);
199void tcpm_pd_transmit_complete(struct tcpm_port *port,
200 enum tcpm_transmit_status status);
201void tcpm_pd_hard_reset(struct tcpm_port *port);
202void tcpm_tcpc_reset(struct tcpm_port *port);
203
204#endif
205