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
13enum 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
23#define SINK_TX_NG TYPEC_CC_RP_1_5
24#define SINK_TX_OK TYPEC_CC_RP_3_0
25
26enum typec_cc_polarity {
27 TYPEC_POLARITY_CC1,
28 TYPEC_POLARITY_CC2,
29};
30
31
32#define PD_T_TCPC_TX_TIMEOUT 100
33#define PD_ROLE_SWAP_TIMEOUT (MSEC_PER_SEC * 10)
34#define PD_PPS_CTRL_TIMEOUT (MSEC_PER_SEC * 10)
35
36enum tcpm_transmit_status {
37 TCPC_TX_SUCCESS = 0,
38 TCPC_TX_DISCARDED = 1,
39 TCPC_TX_FAILED = 2,
40};
41
42enum tcpm_transmit_type {
43 TCPC_TX_SOP = 0,
44 TCPC_TX_SOP_PRIME = 1,
45 TCPC_TX_SOP_PRIME_PRIME = 2,
46 TCPC_TX_SOP_DEBUG_PRIME = 3,
47 TCPC_TX_SOP_DEBUG_PRIME_PRIME = 4,
48 TCPC_TX_HARD_RESET = 5,
49 TCPC_TX_CABLE_RESET = 6,
50 TCPC_TX_BIST_MODE_2 = 7
51};
52
53
54#define TCPC_MUX_USB_ENABLED BIT(0)
55#define TCPC_MUX_DP_ENABLED BIT(1)
56#define TCPC_MUX_POLARITY_INVERTED BIT(2)
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
118struct tcpc_dev {
119 struct fwnode_handle *fwnode;
120
121 int (*init)(struct tcpc_dev *dev);
122 int (*get_vbus)(struct tcpc_dev *dev);
123 int (*get_current_limit)(struct tcpc_dev *dev);
124 int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc);
125 int (*apply_rc)(struct tcpc_dev *dev, enum typec_cc_status cc,
126 enum typec_cc_polarity polarity);
127 int (*get_cc)(struct tcpc_dev *dev, enum typec_cc_status *cc1,
128 enum typec_cc_status *cc2);
129 int (*set_polarity)(struct tcpc_dev *dev,
130 enum typec_cc_polarity polarity);
131 int (*set_vconn)(struct tcpc_dev *dev, bool on);
132 int (*set_vbus)(struct tcpc_dev *dev, bool on, bool charge);
133 int (*set_current_limit)(struct tcpc_dev *dev, u32 max_ma, u32 mv);
134 int (*set_pd_rx)(struct tcpc_dev *dev, bool on);
135 int (*set_roles)(struct tcpc_dev *dev, bool attached,
136 enum typec_role role, enum typec_data_role data);
137 int (*start_toggling)(struct tcpc_dev *dev,
138 enum typec_port_type port_type,
139 enum typec_cc_status cc);
140 int (*try_role)(struct tcpc_dev *dev, int role);
141 int (*pd_transmit)(struct tcpc_dev *dev, enum tcpm_transmit_type type,
142 const struct pd_message *msg, unsigned int negotiated_rev);
143 int (*set_bist_data)(struct tcpc_dev *dev, bool on);
144 int (*enable_frs)(struct tcpc_dev *dev, bool enable);
145 void (*frs_sourcing_vbus)(struct tcpc_dev *dev);
146 int (*enable_auto_vbus_discharge)(struct tcpc_dev *dev, bool enable);
147 int (*set_auto_vbus_discharge_threshold)(struct tcpc_dev *dev, enum typec_pwr_opmode mode,
148 bool pps_active, u32 requested_vbus_voltage);
149 bool (*is_vbus_vsafe0v)(struct tcpc_dev *dev);
150 void (*set_partner_usb_comm_capable)(struct tcpc_dev *dev, bool enable);
151};
152
153struct tcpm_port;
154
155struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc);
156void tcpm_unregister_port(struct tcpm_port *port);
157
158void tcpm_vbus_change(struct tcpm_port *port);
159void tcpm_cc_change(struct tcpm_port *port);
160void tcpm_sink_frs(struct tcpm_port *port);
161void tcpm_sourcing_vbus(struct tcpm_port *port);
162void tcpm_pd_receive(struct tcpm_port *port,
163 const struct pd_message *msg);
164void tcpm_pd_transmit_complete(struct tcpm_port *port,
165 enum tcpm_transmit_status status);
166void tcpm_pd_hard_reset(struct tcpm_port *port);
167void tcpm_tcpc_reset(struct tcpm_port *port);
168
169#endif
170