forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/usb/chipidea/ci.h
....@@ -1,4 +1,4 @@
1
-// SPDX-License-Identifier: GPL-2.0
1
+/* SPDX-License-Identifier: GPL-2.0 */
22 /*
33 * ci.h - common structures, functions, and macros of the ChipIdea driver
44 *
....@@ -16,6 +16,7 @@
1616 #include <linux/usb/gadget.h>
1717 #include <linux/usb/otg-fsm.h>
1818 #include <linux/usb/otg.h>
19
+#include <linux/usb/role.h>
1920 #include <linux/ulpi/interface.h>
2021
2122 /******************************************************************************
....@@ -24,6 +25,7 @@
2425 #define TD_PAGE_COUNT 5
2526 #define CI_HDRC_PAGE_SIZE 4096ul /* page size for TD's */
2627 #define ENDPT_MAX 32
28
+#define CI_MAX_BUF_SIZE (TD_PAGE_COUNT * CI_HDRC_PAGE_SIZE)
2729
2830 /******************************************************************************
2931 * REGISTERS
....@@ -202,6 +204,7 @@
202204 * @in_lpm: if the core in low power mode
203205 * @wakeup_int: if wakeup interrupt occur
204206 * @rev: The revision number for controller
207
+ * @mutex: protect code from concorrent running when doing role switch
205208 */
206209 struct ci_hdrc {
207210 struct device *dev;
....@@ -217,6 +220,7 @@
217220 ktime_t hr_timeouts[NUM_OTG_FSM_TIMERS];
218221 unsigned enabled_otg_timer_bits;
219222 enum otg_fsm_timer next_otg_timer;
223
+ struct usb_role_switch *role_switch;
220224 struct work_struct work;
221225 struct workqueue_struct *wq;
222226
....@@ -254,6 +258,7 @@
254258 bool in_lpm;
255259 bool wakeup_int;
256260 enum ci_revision rev;
261
+ struct mutex mutex;
257262 };
258263
259264 static inline struct ci_role_driver *ci_role(struct ci_hdrc *ci)
....@@ -290,6 +295,26 @@
290295 ci->roles[role]->stop(ci);
291296 }
292297
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
+
293318 /**
294319 * hw_read_id_reg: reads from a identification register
295320 * @ci: the controller