.. | .. |
---|
1 | | -// SPDX-License-Identifier: GPL-2.0 |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0 */ |
---|
2 | 2 | /* |
---|
3 | 3 | * ci.h - common structures, functions, and macros of the ChipIdea driver |
---|
4 | 4 | * |
---|
.. | .. |
---|
16 | 16 | #include <linux/usb/gadget.h> |
---|
17 | 17 | #include <linux/usb/otg-fsm.h> |
---|
18 | 18 | #include <linux/usb/otg.h> |
---|
| 19 | +#include <linux/usb/role.h> |
---|
19 | 20 | #include <linux/ulpi/interface.h> |
---|
20 | 21 | |
---|
21 | 22 | /****************************************************************************** |
---|
.. | .. |
---|
24 | 25 | #define TD_PAGE_COUNT 5 |
---|
25 | 26 | #define CI_HDRC_PAGE_SIZE 4096ul /* page size for TD's */ |
---|
26 | 27 | #define ENDPT_MAX 32 |
---|
| 28 | +#define CI_MAX_BUF_SIZE (TD_PAGE_COUNT * CI_HDRC_PAGE_SIZE) |
---|
27 | 29 | |
---|
28 | 30 | /****************************************************************************** |
---|
29 | 31 | * REGISTERS |
---|
.. | .. |
---|
202 | 204 | * @in_lpm: if the core in low power mode |
---|
203 | 205 | * @wakeup_int: if wakeup interrupt occur |
---|
204 | 206 | * @rev: The revision number for controller |
---|
| 207 | + * @mutex: protect code from concorrent running when doing role switch |
---|
205 | 208 | */ |
---|
206 | 209 | struct ci_hdrc { |
---|
207 | 210 | struct device *dev; |
---|
.. | .. |
---|
217 | 220 | ktime_t hr_timeouts[NUM_OTG_FSM_TIMERS]; |
---|
218 | 221 | unsigned enabled_otg_timer_bits; |
---|
219 | 222 | enum otg_fsm_timer next_otg_timer; |
---|
| 223 | + struct usb_role_switch *role_switch; |
---|
220 | 224 | struct work_struct work; |
---|
221 | 225 | struct workqueue_struct *wq; |
---|
222 | 226 | |
---|
.. | .. |
---|
254 | 258 | bool in_lpm; |
---|
255 | 259 | bool wakeup_int; |
---|
256 | 260 | enum ci_revision rev; |
---|
| 261 | + struct mutex mutex; |
---|
257 | 262 | }; |
---|
258 | 263 | |
---|
259 | 264 | static inline struct ci_role_driver *ci_role(struct ci_hdrc *ci) |
---|
.. | .. |
---|
290 | 295 | ci->roles[role]->stop(ci); |
---|
291 | 296 | } |
---|
292 | 297 | |
---|
| 298 | +static inline enum usb_role ci_role_to_usb_role(struct ci_hdrc *ci) |
---|
| 299 | +{ |
---|
| 300 | + if (ci->role == CI_ROLE_HOST) |
---|
| 301 | + return USB_ROLE_HOST; |
---|
| 302 | + else if (ci->role == CI_ROLE_GADGET && ci->vbus_active) |
---|
| 303 | + return USB_ROLE_DEVICE; |
---|
| 304 | + else |
---|
| 305 | + return USB_ROLE_NONE; |
---|
| 306 | +} |
---|
| 307 | + |
---|
| 308 | +static inline enum ci_role usb_role_to_ci_role(enum usb_role role) |
---|
| 309 | +{ |
---|
| 310 | + if (role == USB_ROLE_HOST) |
---|
| 311 | + return CI_ROLE_HOST; |
---|
| 312 | + else if (role == USB_ROLE_DEVICE) |
---|
| 313 | + return CI_ROLE_GADGET; |
---|
| 314 | + else |
---|
| 315 | + return CI_ROLE_END; |
---|
| 316 | +} |
---|
| 317 | + |
---|
293 | 318 | /** |
---|
294 | 319 | * hw_read_id_reg: reads from a identification register |
---|
295 | 320 | * @ci: the controller |
---|