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#define PD_PPS_CTRL_TIMEOUT (MSEC_PER_SEC * 10)
40
41enum tcpm_transmit_status {
42 TCPC_TX_SUCCESS = 0,
43 TCPC_TX_DISCARDED = 1,
44 TCPC_TX_FAILED = 2,
45};
46
47enum tcpm_transmit_type {
48 TCPC_TX_SOP = 0,
49 TCPC_TX_SOP_PRIME = 1,
50 TCPC_TX_SOP_PRIME_PRIME = 2,
51 TCPC_TX_SOP_DEBUG_PRIME = 3,
52 TCPC_TX_SOP_DEBUG_PRIME_PRIME = 4,
53 TCPC_TX_HARD_RESET = 5,
54 TCPC_TX_CABLE_RESET = 6,
55 TCPC_TX_BIST_MODE_2 = 7
56};
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76struct tcpc_config {
77 const u32 *src_pdo;
78 unsigned int nr_src_pdo;
79
80 const u32 *snk_pdo;
81 unsigned int nr_snk_pdo;
82
83 const u32 *snk_vdo;
84 unsigned int nr_snk_vdo;
85
86 unsigned int operating_snk_mw;
87
88 enum typec_port_type type;
89 enum typec_port_data data;
90 enum typec_role default_role;
91 bool try_role_hw;
92 bool self_powered;
93
94 const struct typec_altmode_desc *alt_modes;
95};
96
97
98#define TCPC_MUX_USB_ENABLED BIT(0)
99#define TCPC_MUX_DP_ENABLED BIT(1)
100#define TCPC_MUX_POLARITY_INVERTED BIT(2)
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132struct tcpc_dev {
133 const struct tcpc_config *config;
134 struct fwnode_handle *fwnode;
135
136 int (*init)(struct tcpc_dev *dev);
137 int (*get_vbus)(struct tcpc_dev *dev);
138 int (*get_current_limit)(struct tcpc_dev *dev);
139 int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc);
140 int (*get_cc)(struct tcpc_dev *dev, enum typec_cc_status *cc1,
141 enum typec_cc_status *cc2);
142 int (*set_polarity)(struct tcpc_dev *dev,
143 enum typec_cc_polarity polarity);
144 int (*set_vconn)(struct tcpc_dev *dev, bool on);
145 int (*set_vbus)(struct tcpc_dev *dev, bool on, bool charge);
146 int (*set_current_limit)(struct tcpc_dev *dev, u32 max_ma, u32 mv);
147 int (*set_pd_rx)(struct tcpc_dev *dev, bool on);
148 int (*set_roles)(struct tcpc_dev *dev, bool attached,
149 enum typec_role role, enum typec_data_role data);
150 int (*start_drp_toggling)(struct tcpc_dev *dev,
151 enum typec_cc_status cc);
152 int (*try_role)(struct tcpc_dev *dev, int role);
153 int (*pd_transmit)(struct tcpc_dev *dev, enum tcpm_transmit_type type,
154 const struct pd_message *msg);
155};
156
157struct tcpm_port;
158
159struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc);
160void tcpm_unregister_port(struct tcpm_port *port);
161
162int tcpm_update_source_capabilities(struct tcpm_port *port, const u32 *pdo,
163 unsigned int nr_pdo);
164int tcpm_update_sink_capabilities(struct tcpm_port *port, const u32 *pdo,
165 unsigned int nr_pdo,
166 unsigned int operating_snk_mw);
167
168void tcpm_vbus_change(struct tcpm_port *port);
169void tcpm_cc_change(struct tcpm_port *port);
170void tcpm_pd_receive(struct tcpm_port *port,
171 const struct pd_message *msg);
172void tcpm_pd_transmit_complete(struct tcpm_port *port,
173 enum tcpm_transmit_status status);
174void tcpm_pd_hard_reset(struct tcpm_port *port);
175void tcpm_tcpc_reset(struct tcpm_port *port);
176
177#endif
178