2 #ifndef __DRIVER_USB_TYPEC_UCSI_H
3 #define __DRIVER_USB_TYPEC_UCSI_H
5 #include <linux/bitops.h>
6 #include <linux/types.h>
8 /* -------------------------------------------------------------------------- */
10 /* Command Status and Connector Change Indication (CCI) data structure */
13 u8 connector_change:7;
17 u16 cancel_complete:1;
25 /* Default fields in CONTROL data structure */
32 /* ACK Command structure */
41 /* Connector Reset Command structure */
49 /* Set USB Operation Mode Command structure */
55 #define UCSI_UOR_ROLE_DFP BIT(0)
56 #define UCSI_UOR_ROLE_UFP BIT(1)
57 #define UCSI_UOR_ROLE_DRP BIT(2)
64 struct ucsi_command cmd;
65 struct ucsi_uor_cmd uor;
66 struct ucsi_ack_cmd ack;
67 struct ucsi_con_rst con_rst;
71 #define __UCSI_CMD(_ctrl_, _cmd_) \
73 (_ctrl_).raw_cmd = 0; \
74 (_ctrl_).cmd.cmd = _cmd_; \
77 /* Helper for preparing ucsi_control for CONNECTOR_RESET command. */
78 #define UCSI_CMD_CONNECTOR_RESET(_ctrl_, _con_, _hard_) \
80 __UCSI_CMD(_ctrl_, UCSI_CONNECTOR_RESET) \
81 (_ctrl_).con_rst.con_num = (_con_)->num; \
82 (_ctrl_).con_rst.hard_reset = _hard_; \
85 /* Helper for preparing ucsi_control for ACK_CC_CI command. */
86 #define UCSI_CMD_ACK(_ctrl_, _ack_) \
88 __UCSI_CMD(_ctrl_, UCSI_ACK_CC_CI) \
89 (_ctrl_).ack.cci_ack = ((_ack_) == UCSI_ACK_EVENT); \
90 (_ctrl_).ack.cmd_ack = ((_ack_) == UCSI_ACK_CMD); \
93 /* Helper for preparing ucsi_control for SET_NOTIFY_ENABLE command. */
94 #define UCSI_CMD_SET_NTFY_ENABLE(_ctrl_, _ntfys_) \
96 __UCSI_CMD(_ctrl_, UCSI_SET_NOTIFICATION_ENABLE) \
97 (_ctrl_).cmd.data = _ntfys_; \
100 /* Helper for preparing ucsi_control for GET_CAPABILITY command. */
101 #define UCSI_CMD_GET_CAPABILITY(_ctrl_) \
103 __UCSI_CMD(_ctrl_, UCSI_GET_CAPABILITY) \
106 /* Helper for preparing ucsi_control for GET_CONNECTOR_CAPABILITY command. */
107 #define UCSI_CMD_GET_CONNECTOR_CAPABILITY(_ctrl_, _con_) \
109 __UCSI_CMD(_ctrl_, UCSI_GET_CONNECTOR_CAPABILITY) \
110 (_ctrl_).cmd.data = _con_; \
113 /* Helper for preparing ucsi_control for GET_CONNECTOR_STATUS command. */
114 #define UCSI_CMD_GET_CONNECTOR_STATUS(_ctrl_, _con_) \
116 __UCSI_CMD(_ctrl_, UCSI_GET_CONNECTOR_STATUS) \
117 (_ctrl_).cmd.data = _con_; \
120 #define __UCSI_ROLE(_ctrl_, _cmd_, _con_num_) \
122 __UCSI_CMD(_ctrl_, _cmd_) \
123 (_ctrl_).uor.con_num = _con_num_; \
124 (_ctrl_).uor.role = UCSI_UOR_ROLE_DRP; \
127 /* Helper for preparing ucsi_control for SET_UOR command. */
128 #define UCSI_CMD_SET_UOR(_ctrl_, _con_, _role_) \
130 __UCSI_ROLE(_ctrl_, UCSI_SET_UOR, (_con_)->num) \
131 (_ctrl_).uor.role |= (_role_) == TYPEC_HOST ? UCSI_UOR_ROLE_DFP : \
135 /* Helper for preparing ucsi_control for SET_PDR command. */
136 #define UCSI_CMD_SET_PDR(_ctrl_, _con_, _role_) \
138 __UCSI_ROLE(_ctrl_, UCSI_SET_PDR, (_con_)->num) \
139 (_ctrl_).uor.role |= (_role_) == TYPEC_SOURCE ? UCSI_UOR_ROLE_DFP : \
144 #define UCSI_PPM_RESET 0x01
145 #define UCSI_CANCEL 0x02
146 #define UCSI_CONNECTOR_RESET 0x03
147 #define UCSI_ACK_CC_CI 0x04
148 #define UCSI_SET_NOTIFICATION_ENABLE 0x05
149 #define UCSI_GET_CAPABILITY 0x06
150 #define UCSI_GET_CONNECTOR_CAPABILITY 0x07
151 #define UCSI_SET_UOM 0x08
152 #define UCSI_SET_UOR 0x09
153 #define UCSI_SET_PDM 0x0a
154 #define UCSI_SET_PDR 0x0b
155 #define UCSI_GET_ALTERNATE_MODES 0x0c
156 #define UCSI_GET_CAM_SUPPORTED 0x0d
157 #define UCSI_GET_CURRENT_CAM 0x0e
158 #define UCSI_SET_NEW_CAM 0x0f
159 #define UCSI_GET_PDOS 0x10
160 #define UCSI_GET_CABLE_PROPERTY 0x11
161 #define UCSI_GET_CONNECTOR_STATUS 0x12
162 #define UCSI_GET_ERROR_STATUS 0x13
164 /* ACK_CC_CI commands */
165 #define UCSI_ACK_EVENT 1
166 #define UCSI_ACK_CMD 2
168 /* Bits for SET_NOTIFICATION_ENABLE command */
169 #define UCSI_ENABLE_NTFY_CMD_COMPLETE BIT(0)
170 #define UCSI_ENABLE_NTFY_EXT_PWR_SRC_CHANGE BIT(1)
171 #define UCSI_ENABLE_NTFY_PWR_OPMODE_CHANGE BIT(2)
172 #define UCSI_ENABLE_NTFY_CAP_CHANGE BIT(5)
173 #define UCSI_ENABLE_NTFY_PWR_LEVEL_CHANGE BIT(6)
174 #define UCSI_ENABLE_NTFY_PD_RESET_COMPLETE BIT(7)
175 #define UCSI_ENABLE_NTFY_CAM_CHANGE BIT(8)
176 #define UCSI_ENABLE_NTFY_BAT_STATUS_CHANGE BIT(9)
177 #define UCSI_ENABLE_NTFY_PARTNER_CHANGE BIT(11)
178 #define UCSI_ENABLE_NTFY_PWR_DIR_CHANGE BIT(12)
179 #define UCSI_ENABLE_NTFY_CONNECTOR_CHANGE BIT(14)
180 #define UCSI_ENABLE_NTFY_ERROR BIT(15)
181 #define UCSI_ENABLE_NTFY_ALL 0xdbe7
183 /* Error information returned by PPM in response to GET_ERROR_STATUS command. */
184 #define UCSI_ERROR_UNREGONIZED_CMD BIT(0)
185 #define UCSI_ERROR_INVALID_CON_NUM BIT(1)
186 #define UCSI_ERROR_INVALID_CMD_ARGUMENT BIT(2)
187 #define UCSI_ERROR_INCOMPATIBLE_PARTNER BIT(3)
188 #define UCSI_ERROR_CC_COMMUNICATION_ERR BIT(4)
189 #define UCSI_ERROR_DEAD_BATTERY BIT(5)
190 #define UCSI_ERROR_CONTRACT_NEGOTIATION_FAIL BIT(6)
192 /* Data structure filled by PPM in response to GET_CAPABILITY command. */
193 struct ucsi_capability {
195 #define UCSI_CAP_ATTR_DISABLE_STATE BIT(0)
196 #define UCSI_CAP_ATTR_BATTERY_CHARGING BIT(1)
197 #define UCSI_CAP_ATTR_USB_PD BIT(2)
198 #define UCSI_CAP_ATTR_TYPEC_CURRENT BIT(6)
199 #define UCSI_CAP_ATTR_POWER_AC_SUPPLY BIT(8)
200 #define UCSI_CAP_ATTR_POWER_OTHER BIT(10)
201 #define UCSI_CAP_ATTR_POWER_VBUS BIT(14)
202 u32 num_connectors:8;
204 #define UCSI_CAP_SET_UOM BIT(0)
205 #define UCSI_CAP_SET_PDM BIT(1)
206 #define UCSI_CAP_ALT_MODE_DETAILS BIT(2)
207 #define UCSI_CAP_ALT_MODE_OVERRIDE BIT(3)
208 #define UCSI_CAP_PDO_DETAILS BIT(4)
209 #define UCSI_CAP_CABLE_DETAILS BIT(5)
210 #define UCSI_CAP_EXT_SUPPLY_NOTIFICATIONS BIT(6)
211 #define UCSI_CAP_PD_RESET BIT(7)
219 /* Data structure filled by PPM in response to GET_CONNECTOR_CAPABILITY cmd. */
220 struct ucsi_connector_capability {
222 #define UCSI_CONCAP_OPMODE_DFP BIT(0)
223 #define UCSI_CONCAP_OPMODE_UFP BIT(1)
224 #define UCSI_CONCAP_OPMODE_DRP BIT(2)
225 #define UCSI_CONCAP_OPMODE_AUDIO_ACCESSORY BIT(3)
226 #define UCSI_CONCAP_OPMODE_DEBUG_ACCESSORY BIT(4)
227 #define UCSI_CONCAP_OPMODE_USB2 BIT(5)
228 #define UCSI_CONCAP_OPMODE_USB3 BIT(6)
229 #define UCSI_CONCAP_OPMODE_ALT_MODE BIT(7)
235 struct ucsi_altmode {
240 /* Data structure filled by PPM in response to GET_CABLE_PROPERTY command. */
241 struct ucsi_cable_property {
243 u8 current_capability;
248 #define UCSI_CABLE_PROPERTY_PLUG_TYPE_A 0
249 #define UCSI_CABLE_PROPERTY_PLUG_TYPE_B 1
250 #define UCSI_CABLE_PROPERTY_PLUG_TYPE_C 2
251 #define UCSI_CABLE_PROPERTY_PLUG_OTHER 3
258 /* Data structure filled by PPM in response to GET_CONNECTOR_STATUS command. */
259 struct ucsi_connector_status {
261 #define UCSI_CONSTAT_EXT_SUPPLY_CHANGE BIT(1)
262 #define UCSI_CONSTAT_POWER_OPMODE_CHANGE BIT(2)
263 #define UCSI_CONSTAT_PDOS_CHANGE BIT(5)
264 #define UCSI_CONSTAT_POWER_LEVEL_CHANGE BIT(6)
265 #define UCSI_CONSTAT_PD_RESET_COMPLETE BIT(7)
266 #define UCSI_CONSTAT_CAM_CHANGE BIT(8)
267 #define UCSI_CONSTAT_BC_CHANGE BIT(9)
268 #define UCSI_CONSTAT_PARTNER_CHANGE BIT(11)
269 #define UCSI_CONSTAT_POWER_DIR_CHANGE BIT(12)
270 #define UCSI_CONSTAT_CONNECT_CHANGE BIT(14)
271 #define UCSI_CONSTAT_ERROR BIT(15)
273 #define UCSI_CONSTAT_PWR_OPMODE_NONE 0
274 #define UCSI_CONSTAT_PWR_OPMODE_DEFAULT 1
275 #define UCSI_CONSTAT_PWR_OPMODE_BC 2
276 #define UCSI_CONSTAT_PWR_OPMODE_PD 3
277 #define UCSI_CONSTAT_PWR_OPMODE_TYPEC1_5 4
278 #define UCSI_CONSTAT_PWR_OPMODE_TYPEC3_0 5
282 #define UCSI_CONSTAT_PARTNER_FLAG_USB BIT(0)
283 #define UCSI_CONSTAT_PARTNER_FLAG_ALT_MODE BIT(1)
285 #define UCSI_CONSTAT_PARTNER_TYPE_DFP 1
286 #define UCSI_CONSTAT_PARTNER_TYPE_UFP 2
287 #define UCSI_CONSTAT_PARTNER_TYPE_CABLE 3 /* Powered Cable */
288 #define UCSI_CONSTAT_PARTNER_TYPE_CABLE_AND_UFP 4 /* Powered Cable */
289 #define UCSI_CONSTAT_PARTNER_TYPE_DEBUG 5
290 #define UCSI_CONSTAT_PARTNER_TYPE_AUDIO 6
291 u32 request_data_obj;
293 #define UCSI_CONSTAT_BC_NOT_CHARGING 0
294 #define UCSI_CONSTAT_BC_NOMINAL_CHARGING 1
295 #define UCSI_CONSTAT_BC_SLOW_CHARGING 2
296 #define UCSI_CONSTAT_BC_TRICKLE_CHARGING 3
297 u8 provider_cap_limit_reason:4;
298 #define UCSI_CONSTAT_CAP_PWR_LOWERED 0
299 #define UCSI_CONSTAT_CAP_PWR_BUDGET_LIMIT 1
303 /* -------------------------------------------------------------------------- */
314 struct ucsi_control ctrl;
320 * struct ucsi_ppm - Interface to UCSI Platform Policy Manager
321 * @data: memory location to the UCSI data structures
322 * @cmd: UCSI command execution routine
323 * @sync: Refresh UCSI mailbox (the data structures)
326 struct ucsi_data *data;
327 int (*cmd)(struct ucsi_ppm *, struct ucsi_control *);
328 int (*sync)(struct ucsi_ppm *);
331 struct ucsi *ucsi_register_ppm(struct device *dev, struct ucsi_ppm *ppm);
332 void ucsi_unregister_ppm(struct ucsi *ucsi);
333 void ucsi_notify(struct ucsi *ucsi);
335 #endif /* __DRIVER_USB_TYPEC_UCSI_H */