xhci-mtk-driver.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. #include <xhci.h>
  2. #include "xhci-mtk-driver.h"
  3. #include "xhci-mtk-power.h"
  4. #include <linux/kernel.h> /* printk() */
  5. #include <linux/slab.h>
  6. #include <linux/delay.h>
  7. #include <linux/uaccess.h>
  8. #include <linux/dma-mapping.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/wakelock.h>
  11. #ifdef CONFIG_USB_MTK_DUALMODE
  12. /*#include <mt-plat/eint.h>*/
  13. #include <linux/irq.h>
  14. #include <linux/switch.h>
  15. #include <linux/sched.h>
  16. #include <linux/module.h>
  17. #undef DRV_Reg32
  18. #undef DRV_WriteReg32
  19. #include <mt-plat/battery_meter.h>
  20. #undef DRV_Reg32
  21. #undef DRV_WriteReg32
  22. #include <mt-plat/mt_gpio.h>
  23. #include <linux/of.h>
  24. #include <linux/of_address.h>
  25. #include <linux/of_irq.h>
  26. #ifdef CONFIG_PROJECT_PHY
  27. #include <mtk-phy-asic.h>
  28. #endif
  29. #endif
  30. #include <hub.h>
  31. #include <linux/jiffies.h>
  32. #include <linux/list.h>
  33. #include <linux/atomic.h>
  34. #include <linux/usb/hcd.h>
  35. /*#include <mach/mt_chip.h>*/
  36. #ifdef CONFIG_USB_C_SWITCH
  37. #include <typec.h>
  38. #endif
  39. #ifdef CONFIG_MTK_FPGA
  40. #include <linux/mu3phy/mtk-phy.h>
  41. #endif
  42. #ifdef CONFIG_USB_MTK_DUALMODE
  43. #ifdef CONFIG_MTK_OTG_PMIC_BOOST_5V
  44. #ifdef CONFIG_MTK_OTG_OC_DETECTOR
  45. #include <linux/kobject.h>
  46. #include <linux/miscdevice.h>
  47. #endif
  48. #endif
  49. #endif
  50. #define mtk_xhci_mtk_log(fmt, args...) \
  51. pr_notice("%s(%d): " fmt, __func__, __LINE__, ##args)
  52. #define RET_SUCCESS 0
  53. #define RET_FAIL 1
  54. struct xhci_hcd *mtk_xhci;
  55. static int vbus_on;
  56. static struct wake_lock mtk_xhci_wakelock;
  57. #ifdef CONFIG_MTK_FPGA
  58. #ifndef CONFIG_USB_MTK_DUALMODE
  59. void __iomem *u3_base;
  60. void __iomem *u3_sif_base;
  61. void __iomem *u3_sif2_base;
  62. void __iomem *i2c1_base;
  63. #endif
  64. #endif
  65. /* struct u3phy_info *u3phy; */
  66. /* struct u3phy_operator *u3phy_ops; */
  67. #ifdef CONFIG_USB_MTK_DUALMODE
  68. enum idpin_state {
  69. IDPIN_OUT,
  70. IDPIN_IN_HOST,
  71. IDPIN_IN_DEVICE,
  72. };
  73. static int mtk_idpin_irqnum;
  74. static enum idpin_state mtk_idpin_cur_stat = IDPIN_OUT;
  75. static struct switch_dev mtk_otg_state;
  76. static struct delayed_work mtk_xhci_delaywork;
  77. int mtk_iddig_debounce = 10;
  78. module_param(mtk_iddig_debounce, int, 0644);
  79. void switch_int_to_host_and_mask(void)
  80. {
  81. irq_set_irq_type(mtk_idpin_irqnum, IRQF_TRIGGER_LOW);
  82. disable_irq(mtk_idpin_irqnum);
  83. }
  84. void switch_int_to_host(void)
  85. {
  86. irq_set_irq_type(mtk_idpin_irqnum, IRQF_TRIGGER_LOW);
  87. enable_irq(mtk_idpin_irqnum);
  88. }
  89. static void mtk_set_iddig_out_detect(void)
  90. {
  91. irq_set_irq_type(mtk_idpin_irqnum, IRQF_TRIGGER_HIGH);
  92. enable_irq(mtk_idpin_irqnum);
  93. }
  94. static void mtk_set_iddig_in_detect(void)
  95. {
  96. irq_set_irq_type(mtk_idpin_irqnum, IRQF_TRIGGER_LOW);
  97. enable_irq(mtk_idpin_irqnum);
  98. }
  99. static bool mtk_is_charger_4_vol(void)
  100. {
  101. int vol = battery_meter_get_charger_voltage();
  102. mtk_xhci_mtk_log("voltage(%d)\n", vol);
  103. #if defined(CONFIG_USBIF_COMPLIANCE) || defined(CONFIG_POWER_EXT)
  104. return false;
  105. #else
  106. return (vol > 4000) ? true : false;
  107. #endif
  108. }
  109. bool mtk_is_usb_id_pin_short_gnd(void)
  110. {
  111. return (mtk_idpin_cur_stat != IDPIN_OUT) ? true : false;
  112. }
  113. #ifdef CONFIG_MTK_OTG_PMIC_BOOST_5V
  114. #define PMIC_REG_BAK_NUM (10)
  115. #ifdef CONFIG_MTK_OTG_OC_DETECTOR
  116. #define OC_DETECTOR_TIMER (2000)
  117. static struct delayed_work mtk_xhci_oc_delaywork;
  118. static struct miscdevice xhci_misc_uevent = {
  119. .minor = MISC_DYNAMIC_MINOR,
  120. .name = "xhci_misc_uevent",
  121. .fops = NULL,
  122. };
  123. #endif
  124. U32 pmic_bak_regs[PMIC_REG_BAK_NUM][2] = {
  125. {0x8D22, 0}, {0x8D14, 0}, {0x803C, 0}, {0x8036, 0}, {0x8D24, 0},
  126. {0x8D16, 0}, {0x803A, 0}, {0x8046, 0}, {0x803E, 0}, {0x8044, 0}
  127. };
  128. static void pmic_save_regs(void)
  129. {
  130. int i;
  131. for (i = 0; i < PMIC_REG_BAK_NUM; i++)
  132. pmic_read_interface(pmic_bak_regs[i][0], &pmic_bak_regs[i][1], 0xffffffff, 0);
  133. }
  134. static void pmic_restore_regs(void)
  135. {
  136. int i;
  137. for (i = 0; i < PMIC_REG_BAK_NUM; i++)
  138. pmic_config_interface(pmic_bak_regs[i][0], pmic_bak_regs[i][1], 0xffffffff, 0);
  139. }
  140. void mtk_enable_pmic_otg_mode(void)
  141. {
  142. int val = 0;
  143. int cnt = 0;
  144. vbus_on++;
  145. /* / vbus_on =1; */
  146. mtk_xhci_mtk_log("set pmic power on, %d\n", vbus_on);
  147. #if 1
  148. if (vbus_on > 1)
  149. return;
  150. #endif
  151. /* save PMIC related registers */
  152. pmic_save_regs();
  153. pmic_config_interface(0x8D22, 0x1, 0x1, 12);
  154. pmic_config_interface(0x8D14, 0x1, 0x1, 12);
  155. pmic_config_interface(0x803C, 0x3, 0x3, 0);
  156. pmic_config_interface(0x803C, 0x2, 0x3, 2);
  157. pmic_config_interface(0x803C, 0x1, 0x1, 14);
  158. pmic_config_interface(0x8036, 0x0, 0x0, 0);
  159. pmic_config_interface(0x8D24, 0xf, 0xf, 12);
  160. pmic_config_interface(0x8D16, 0x1, 0x1, 15);
  161. pmic_config_interface(0x803A, 0x1, 0x1, 6);
  162. pmic_config_interface(0x8046, 0x00A0, 0xffff, 0);
  163. pmic_config_interface(0x803E, 0x1, 0x1, 2);
  164. pmic_config_interface(0x803E, 0x1, 0x1, 3);
  165. pmic_config_interface(0x803E, 0x3, 0x3, 8);
  166. #ifdef CONFIG_MTK_OTG_OC_DETECTOR
  167. /* Current limit is on */
  168. pmic_config_interface(0x803E, 0x1, 0x1, 10);
  169. #else
  170. pmic_config_interface(0x803E, 0x0, 0x1, 10);
  171. #endif
  172. pmic_config_interface(0x8044, 0x3, 0x3, 0);
  173. pmic_config_interface(0x8044, 0x3, 0x7, 8);
  174. pmic_config_interface(0x8044, 0x1, 0x1, 11);
  175. pmic_config_interface(0x809C, 0x8000, 0xFFFF, 0);
  176. val = 0;
  177. while (val == 0)
  178. pmic_read_interface(0x809A, &val, 0x1, 15);
  179. pmic_config_interface(0x8084, 0x1, 0x1, 0);
  180. mdelay(50);
  181. val = 0;
  182. while (val == 0 && cnt < 20) {
  183. pmic_read_interface(0x8060, &val, 0x1, 14);
  184. cnt++;
  185. mdelay(2);
  186. }
  187. #ifdef CONFIG_MTK_OTG_OC_DETECTOR
  188. schedule_delayed_work_on(0, &mtk_xhci_oc_delaywork, msecs_to_jiffies(OC_DETECTOR_TIMER));
  189. #endif
  190. mtk_xhci_mtk_log("set pmic power on(cnt:%d), done\n", cnt);
  191. }
  192. void mtk_disable_pmic_otg_mode(void)
  193. {
  194. int val = 0;
  195. int cnt = 0;
  196. /* /vbus_on = 0; */
  197. vbus_on--;
  198. mtk_xhci_mtk_log("set pmic power off %d\n", vbus_on);
  199. if (vbus_on < 0 || vbus_on > 0) {
  200. if (vbus_on < 0)
  201. vbus_on = 0;
  202. return;
  203. }
  204. pmic_config_interface(0x8068, 0x0, 0x1, 0);
  205. pmic_config_interface(0x8084, 0x0, 0x1, 0);
  206. mdelay(50);
  207. pmic_config_interface(0x8068, 0x0, 0x1, 1);
  208. val = 1;
  209. while (val == 1 && cnt < 20) {
  210. pmic_read_interface(0x805E, &val, 0x1, 4);
  211. cnt++;
  212. mdelay(2);
  213. }
  214. #if 0
  215. pmic_config_interface(0x809E, 0x8000, 0xFFFF, 0);
  216. val = 1;
  217. while (val == 1)
  218. pmic_read_interface(0x809A, &val, 0x1, 15);
  219. #endif
  220. /* restore PMIC registers */
  221. pmic_restore_regs();
  222. #ifdef CONFIG_MTK_OTG_OC_DETECTOR
  223. cancel_delayed_work(&mtk_xhci_oc_delaywork);
  224. #endif
  225. mtk_xhci_mtk_log("set pmic power off(cnt:%d), done\n", cnt);
  226. }
  227. #ifdef CONFIG_MTK_OTG_OC_DETECTOR
  228. void xhci_send_event(char *event)
  229. {
  230. char udev_event[128];
  231. char *envp[2] = { udev_event, NULL };
  232. int ret;
  233. snprintf(udev_event, 128, "XHCI_MISC_UEVENT=%s", event);
  234. mtk_xhci_mtk_log("send %s in %s\n", udev_event,
  235. kobject_get_path(&xhci_misc_uevent.this_device->kobj, GFP_KERNEL));
  236. ret = kobject_uevent_env(&xhci_misc_uevent.this_device->kobj, KOBJ_CHANGE, envp);
  237. if (ret < 0)
  238. mtk_xhci_mtk_log("fail, ret(%d)\n", ret);
  239. }
  240. static bool mtk_is_over_current(void)
  241. {
  242. int vol = battery_meter_get_charger_voltage();
  243. if (vol < 4200) {
  244. mtk_xhci_mtk_log("over current occurs, voltage(%d)\n", vol);
  245. return true;
  246. }
  247. return false;
  248. }
  249. static void mtk_xhci_oc_detector(struct work_struct *work)
  250. {
  251. int ret;
  252. if (mtk_is_over_current()) {
  253. xhci_send_event("OVER_CURRENT");
  254. mtk_disable_pmic_otg_mode();
  255. } else {
  256. ret =
  257. schedule_delayed_work_on(0, &mtk_xhci_oc_delaywork,
  258. msecs_to_jiffies(OC_DETECTOR_TIMER));
  259. }
  260. }
  261. #endif
  262. #endif
  263. #if 0
  264. void mtk_hub_event_steal(spinlock_t *lock, struct list_head *list)
  265. {
  266. mtk_hub_event_lock = lock;
  267. mtk_hub_event_list = list;
  268. }
  269. void mtk_ep_count_inc(void)
  270. {
  271. mtk_ep_count++;
  272. }
  273. void mtk_ep_count_dec(void)
  274. {
  275. mtk_ep_count--;
  276. }
  277. #endif
  278. #if 0
  279. int mtk_is_hub_active(void)
  280. {
  281. struct usb_hcd *hcd = xhci_to_hcd(mtk_xhci);
  282. struct usb_device *rhdev = hcd->self.root_hub;
  283. struct usb_hub *hub = usb_hub_to_struct_hub(rhdev);
  284. bool ret = true;
  285. spin_lock_irq(mtk_hub_event_lock);
  286. if ((mtk_ep_count == 0) && (list_empty(&hub->event_list) == 1)
  287. && (atomic_read(&(hub->kref.refcount)) == 1)) {
  288. ret = false;
  289. }
  290. spin_unlock_irq(mtk_hub_event_lock);
  291. return ret;
  292. }
  293. #endif
  294. static void mtk_enable_otg_mode(void)
  295. {
  296. #if defined(CONFIG_MTK_BQ25896_SUPPORT)
  297. bq25890_otg_en(0x01);
  298. bq25890_set_boost_ilim(0x03); /* 1.3A */
  299. #elif defined(CONFIG_MTK_OTG_PMIC_BOOST_5V)
  300. mtk_enable_pmic_otg_mode();
  301. #endif
  302. }
  303. static void mtk_disable_otg_mode(void)
  304. {
  305. #if defined(CONFIG_MTK_BQ25896_SUPPORT)
  306. bq25890_otg_en(0x0);
  307. #elif defined(CONFIG_MTK_OTG_PMIC_BOOST_5V)
  308. mtk_disable_pmic_otg_mode();
  309. #endif
  310. }
  311. static int mtk_xhci_hcd_init(void)
  312. {
  313. int retval;
  314. retval = xhci_register_plat();
  315. if (retval < 0) {
  316. pr_err("Problem registering platform driver.\n");
  317. return retval;
  318. }
  319. retval = xhci_attrs_init();
  320. if (retval < 0) {
  321. pr_err("Problem creating xhci attributes.\n");
  322. goto unreg_plat;
  323. }
  324. #ifdef CONFIG_MTK_OTG_PMIC_BOOST_5V
  325. #ifdef CONFIG_MTK_OTG_OC_DETECTOR
  326. retval = misc_register(&xhci_misc_uevent);
  327. if (retval) {
  328. pr_err("create the xhci_uevent_device fail, ret(%d)\n", retval);
  329. goto unreg_attrs;
  330. }
  331. #endif
  332. #endif
  333. /*
  334. * Check the compiler generated sizes of structures that must be laid
  335. * out in specific ways for hardware access.
  336. */
  337. BUILD_BUG_ON(sizeof(struct xhci_doorbell_array) != 256 * 32 / 8);
  338. BUILD_BUG_ON(sizeof(struct xhci_slot_ctx) != 8 * 32 / 8);
  339. BUILD_BUG_ON(sizeof(struct xhci_ep_ctx) != 8 * 32 / 8);
  340. /* xhci_device_control has eight fields, and also
  341. * embeds one xhci_slot_ctx and 31 xhci_ep_ctx
  342. */
  343. BUILD_BUG_ON(sizeof(struct xhci_stream_ctx) != 4 * 32 / 8);
  344. BUILD_BUG_ON(sizeof(union xhci_trb) != 4 * 32 / 8);
  345. BUILD_BUG_ON(sizeof(struct xhci_erst_entry) != 4 * 32 / 8);
  346. BUILD_BUG_ON(sizeof(struct xhci_cap_regs) != 7 * 32 / 8);
  347. BUILD_BUG_ON(sizeof(struct xhci_intr_reg) != 8 * 32 / 8);
  348. /* xhci_run_regs has eight fields and embeds 128 xhci_intr_regs */
  349. BUILD_BUG_ON(sizeof(struct xhci_run_regs) != (8 + 8 * 128) * 32 / 8);
  350. return 0;
  351. #ifdef CONFIG_MTK_OTG_PMIC_BOOST_5V
  352. #ifdef CONFIG_MTK_OTG_OC_DETECTOR
  353. unreg_attrs:
  354. xhci_attrs_exit();
  355. #endif
  356. #endif
  357. unreg_plat:
  358. xhci_unregister_plat();
  359. return retval;
  360. }
  361. static void mtk_xhci_hcd_cleanup(void)
  362. {
  363. #ifdef CONFIG_MTK_OTG_PMIC_BOOST_5V
  364. #ifdef CONFIG_MTK_OTG_OC_DETECTOR
  365. misc_deregister(&xhci_misc_uevent);
  366. #endif
  367. #endif
  368. xhci_attrs_exit();
  369. xhci_unregister_plat();
  370. }
  371. static void mtk_xhci_imod_set(u32 imod)
  372. {
  373. u32 temp;
  374. temp = readl(&mtk_xhci->ir_set->irq_control);
  375. temp &= ~0xFFFF;
  376. temp |= imod;
  377. writel(temp, &mtk_xhci->ir_set->irq_control);
  378. }
  379. static int mtk_xhci_driver_load(void)
  380. {
  381. int ret = 0;
  382. /* recover clock/power setting and deassert reset bit of mac */
  383. #ifdef CONFIG_PROJECT_PHY
  384. usb_phy_recover(0);
  385. usb20_pll_settings(true, true);
  386. #endif
  387. ret = mtk_xhci_hcd_init();
  388. if (ret || !mtk_xhci) {
  389. ret = -ENXIO;
  390. goto _err;
  391. }
  392. /* for performance, fixed the interrupt moderation from 0xA0(default) to 0x30 */
  393. mtk_xhci_imod_set(0x30);
  394. mtk_enable_otg_mode();
  395. enableXhciAllPortPower(mtk_xhci);
  396. return 0;
  397. _err:
  398. mtk_xhci_mtk_log("ret(%d), mtk_xhci(0x%p)\n", ret, mtk_xhci);
  399. #ifdef CONFIG_PROJECT_PHY
  400. usb_phy_savecurrent(1);
  401. #endif
  402. return ret;
  403. }
  404. static void mtk_xhci_disPortPower(void)
  405. {
  406. mtk_disable_otg_mode();
  407. disableXhciAllPortPower(mtk_xhci);
  408. }
  409. static void mtk_xhci_driver_unload(void)
  410. {
  411. mtk_xhci_hcd_cleanup();
  412. /* close clock/power setting and assert reset bit of mac */
  413. #ifdef CONFIG_PROJECT_PHY
  414. usb_phy_savecurrent(1);
  415. #endif
  416. }
  417. void mtk_xhci_switch_init(void)
  418. {
  419. mtk_otg_state.name = "otg_state";
  420. mtk_otg_state.index = 0;
  421. mtk_otg_state.state = 0;
  422. #ifndef CONFIG_USBIF_COMPLIANCE
  423. if (switch_dev_register(&mtk_otg_state))
  424. mtk_xhci_mtk_log("switch_dev_register fail\n");
  425. else
  426. mtk_xhci_mtk_log("switch_dev register success\n");
  427. #endif
  428. }
  429. void mtk_xhci_mode_switch(struct work_struct *work)
  430. {
  431. static bool is_load;
  432. static bool is_pwoff;
  433. int ret = 0;
  434. mtk_xhci_mtk_log("mtk_xhci_mode_switch\n");
  435. if (musb_check_ipo_state() == true) {
  436. enable_irq(mtk_idpin_irqnum); /* prevent from disable irq twice*/
  437. return;
  438. }
  439. if (mtk_idpin_cur_stat == IDPIN_OUT) {
  440. is_load = false;
  441. /* expect next isr is for id-pin out action */
  442. mtk_idpin_cur_stat = (mtk_is_charger_4_vol()) ? IDPIN_IN_DEVICE : IDPIN_IN_HOST;
  443. /* make id pin to detect the plug-out */
  444. mtk_set_iddig_out_detect();
  445. if (mtk_idpin_cur_stat == IDPIN_IN_DEVICE)
  446. goto done;
  447. ret = mtk_xhci_driver_load();
  448. if (!ret) {
  449. is_load = true;
  450. mtk_xhci_wakelock_lock();
  451. #ifndef CONFIG_USBIF_COMPLIANCE
  452. switch_set_state(&mtk_otg_state, 1);
  453. #endif
  454. }
  455. } else { /* IDPIN_OUT */
  456. if (is_load) {
  457. if (!is_pwoff)
  458. mtk_xhci_disPortPower();
  459. /* prevent hang here */
  460. /* if(mtk_is_hub_active()){
  461. is_pwoff = true;
  462. schedule_delayed_work_on(0, &mtk_xhci_delaywork, msecs_to_jiffies(mtk_iddig_debounce));
  463. mtk_xhci_mtk_log("wait, hub is still active, ep cnt %d !!!\n", mtk_ep_count);
  464. return;
  465. } */
  466. /* USB PLL Force settings */
  467. #ifdef CONFIG_PROJECT_PHY
  468. usb20_pll_settings(true, false);
  469. #endif
  470. mtk_xhci_driver_unload();
  471. is_pwoff = false;
  472. is_load = false;
  473. #ifndef CONFIG_USBIF_COMPLIANCE
  474. switch_set_state(&mtk_otg_state, 0);
  475. #endif
  476. mtk_xhci_wakelock_unlock();
  477. }
  478. /* expect next isr is for id-pin in action */
  479. mtk_idpin_cur_stat = IDPIN_OUT;
  480. /* make id pin to detect the plug-in */
  481. mtk_set_iddig_in_detect();
  482. }
  483. done:
  484. mtk_xhci_mtk_log("current mode is %s, ret(%d), switch(%d)\n",
  485. (mtk_idpin_cur_stat == IDPIN_IN_HOST) ? "host" :
  486. (mtk_idpin_cur_stat == IDPIN_IN_DEVICE) ? "id_device" : "device",
  487. ret, mtk_otg_state.state);
  488. }
  489. static irqreturn_t xhci_eint_iddig_isr(int irqnum, void *data)
  490. {
  491. schedule_delayed_work(&mtk_xhci_delaywork, msecs_to_jiffies(mtk_iddig_debounce));
  492. /* microseconds */
  493. /*
  494. ret =
  495. schedule_delayed_work_on(0, &mtk_xhci_delaywork, msecs_to_jiffies(mtk_iddig_debounce));
  496. */
  497. mtk_xhci_mtk_log("xhci_eint_iddig_isr\n");
  498. disable_irq_nosync(irqnum);
  499. return IRQ_HANDLED;
  500. }
  501. int mtk_xhci_eint_iddig_init(void)
  502. {
  503. int retval;
  504. struct device_node *node;
  505. int iddig_gpio, iddig_debounce;
  506. u32 ints[2] = {0, 0};
  507. node = of_find_compatible_node(NULL, NULL, "mediatek,usb3_xhci");
  508. if (node) {
  509. node = of_find_compatible_node(NULL, NULL, "mediatek,usb_iddig_bi_eint");
  510. if (node) {
  511. retval = of_property_read_u32_array(node, "debounce", ints, ARRAY_SIZE(ints));
  512. if (!retval) {
  513. iddig_gpio = ints[0];
  514. iddig_debounce = ints[1];
  515. mtk_idpin_irqnum = irq_of_parse_and_map(node, 0);
  516. mtk_xhci_mtk_log("iddig gpio num = %d\n", mtk_idpin_irqnum);
  517. }
  518. }
  519. } else {
  520. mtk_xhci_mtk_log("cannot get the node\n");
  521. return -ENODEV;
  522. }
  523. INIT_DELAYED_WORK(&mtk_xhci_delaywork, mtk_xhci_mode_switch);
  524. #ifdef CONFIG_MTK_OTG_PMIC_BOOST_5V
  525. #ifdef CONFIG_MTK_OTG_OC_DETECTOR
  526. INIT_DELAYED_WORK(&mtk_xhci_oc_delaywork, mtk_xhci_oc_detector);
  527. #endif
  528. #endif
  529. /* microseconds */
  530. /* mt_gpio_set_debounce(iddig_gpio, iddig_debounce);*/
  531. retval =
  532. request_irq(mtk_idpin_irqnum, xhci_eint_iddig_isr, IRQF_TRIGGER_LOW, "iddig_eint",
  533. NULL);
  534. if (retval != 0) {
  535. mtk_xhci_mtk_log("request_irq fail, ret %d, irqnum %d!!!\n", retval,
  536. mtk_idpin_irqnum);
  537. return retval;
  538. }
  539. /* set in-detect and umask the iddig interrupt */
  540. /* enable_irq(mtk_idpin_irqnum); */
  541. return retval;
  542. }
  543. void mtk_xhci_eint_iddig_deinit(void)
  544. {
  545. /* mt_eint_registration(IDDIG_EINT_PIN, EINTF_TRIGGER_LOW, NULL, false); */
  546. disable_irq_nosync(mtk_idpin_irqnum);
  547. free_irq(mtk_idpin_irqnum, NULL);
  548. cancel_delayed_work(&mtk_xhci_delaywork);
  549. #ifdef CONFIG_MTK_OTG_PMIC_BOOST_5V
  550. #ifdef CONFIG_MTK_OTG_OC_DETECTOR
  551. cancel_delayed_work(&mtk_xhci_oc_delaywork);
  552. #endif
  553. #endif
  554. mtk_idpin_cur_stat = IDPIN_OUT;
  555. mtk_xhci_mtk_log("external iddig unregister done.\n");
  556. }
  557. void mtk_set_host_mode_in_host(void)
  558. {
  559. mtk_idpin_cur_stat = IDPIN_IN_HOST;
  560. }
  561. void mtk_set_host_mode_out(void)
  562. {
  563. mtk_idpin_cur_stat = IDPIN_OUT;
  564. }
  565. bool mtk_is_host_mode(void)
  566. {
  567. return (vbus_on > 0 || mtk_idpin_cur_stat == IDPIN_IN_HOST) ? true : false;
  568. }
  569. void mtk_unload_xhci_on_ipo(void)
  570. {
  571. mtk_xhci_disPortPower();
  572. /* USB PLL Force settings */
  573. usb20_pll_settings(true, false);
  574. mtk_xhci_driver_unload();
  575. switch_set_state(&mtk_otg_state, 0);
  576. mtk_xhci_wakelock_unlock();
  577. mtk_idpin_cur_stat = IDPIN_OUT;
  578. }
  579. #endif
  580. #ifdef CONFIG_USB_C_SWITCH
  581. static void typec_otg_enable(void)
  582. {
  583. mtk_idpin_cur_stat = IDPIN_IN_HOST;
  584. int ret = 0;
  585. ret = mtk_xhci_driver_load();
  586. if (!ret) {
  587. mtk_xhci_wakelock_lock();
  588. switch_set_state(&mtk_otg_state, 1);
  589. }
  590. }
  591. static void typec_otg_disable(void)
  592. {
  593. mtk_xhci_disPortPower();
  594. /* USB PLL Force settings */
  595. usb20_pll_settings(true, false);
  596. mtk_xhci_driver_unload();
  597. switch_set_state(&mtk_otg_state, 0);
  598. mtk_xhci_wakelock_unlock();
  599. mtk_idpin_cur_stat = IDPIN_OUT;
  600. }
  601. static struct typec_switch_data typec_host_driver = {
  602. .name = "xhci-mtk",
  603. .type = HOST_TYPE,
  604. .enable = typec_otg_enable,
  605. .disable = typec_otg_disable,
  606. };
  607. #endif
  608. void mtk_xhci_wakelock_init(void)
  609. {
  610. wake_lock_init(&mtk_xhci_wakelock, WAKE_LOCK_SUSPEND, "xhci.wakelock");
  611. #ifdef CONFIG_USB_C_SWITCH
  612. typec_host_driver.priv_data = NULL;
  613. register_typec_switch_callback(&typec_host_driver);
  614. #endif
  615. }
  616. void mtk_xhci_wakelock_lock(void)
  617. {
  618. if (!wake_lock_active(&mtk_xhci_wakelock))
  619. wake_lock(&mtk_xhci_wakelock);
  620. mtk_xhci_mtk_log("done\n");
  621. }
  622. void mtk_xhci_wakelock_unlock(void)
  623. {
  624. if (wake_lock_active(&mtk_xhci_wakelock))
  625. wake_unlock(&mtk_xhci_wakelock);
  626. mtk_xhci_mtk_log("done\n");
  627. }
  628. void mtk_xhci_set(struct usb_hcd *hcd, struct xhci_hcd *xhci)
  629. {
  630. struct platform_device *pdev = to_platform_device(hcd->self.controller);
  631. struct resource *sif_res, *sif2_res;
  632. xhci->base_regs = (unsigned long)hcd->regs;
  633. sif_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, XHCI_SIF_REGS_ADDR_RES_NAME);
  634. if (!sif_res)
  635. pr_err("%s(%d): cannot get sif resources\n", __func__, __LINE__);
  636. xhci->sif_regs = (unsigned long)ioremap(sif_res->start, resource_size(sif_res));
  637. mtk_xhci_mtk_log("%s(%d): sif_base, logic 0x%p, phys 0x%p\n", __func__, __LINE__,
  638. (void *)(unsigned long)sif_res->start, (void *)xhci->sif_regs);
  639. sif2_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, XHCI_SIF2_REGS_ADDR_RES_NAME);
  640. if (!sif2_res)
  641. pr_err("%s(%d): cannot get sif2 resources\n", __func__, __LINE__);
  642. xhci->sif2_regs = (unsigned long)ioremap(sif2_res->start, resource_size(sif2_res));
  643. mtk_xhci_mtk_log("%s(%d): sif2_base, logic 0x%p, phys 0x%p\n", __func__, __LINE__,
  644. (void *)(unsigned long)sif2_res->start, (void *)xhci->sif2_regs);
  645. mtk_xhci_mtk_log("mtk_xhci = 0x%p\n", xhci);
  646. mtk_xhci = xhci;
  647. }
  648. void mtk_xhci_reset(struct xhci_hcd *xhci)
  649. {
  650. iounmap((void __iomem *)xhci->sif_regs);
  651. mtk_xhci_mtk_log("iounmap, sif_reg, 0x%p\n", (void *)xhci->sif_regs);
  652. iounmap((void __iomem *)xhci->sif2_regs);
  653. mtk_xhci_mtk_log("iounmap, sif2_reg, 0x%p\n", (void *)xhci->sif2_regs);
  654. mtk_xhci = NULL;
  655. }
  656. void mtk_xhci_ck_timer_init(struct xhci_hcd *xhci)
  657. {
  658. #if 0
  659. void __iomem *addr;
  660. u32 temp = 0;
  661. int num_u3_port;
  662. unsigned int hw_code = mt_get_chip_hw_code();
  663. CHIP_SW_VER sw_code = mt_get_chip_sw_ver();
  664. mtk_xhci_mtk_log("hw code(0x%x), sw_code(0x%x)\n", hw_code, sw_code);
  665. if (0x6595 == hw_code) {
  666. /* The sys125_ck = 1/2 sys_ck = 62.5MHz */
  667. addr = (void __iomem *)_SSUSB_SYS_CK_CTRL(xhci->sif_regs);
  668. temp = readl(addr);
  669. temp |= SSUSB_SYS_CK_DIV2_EN;
  670. writel(temp, addr);
  671. mtk_xhci_mtk_log("mu3d sys_clk, addr 0x%p, value 0x%x\n",
  672. (void *)_SSUSB_SYS_CK_CTRL(xhci->sif_regs),
  673. readl((__u32 __iomem *) _SSUSB_SYS_CK_CTRL(xhci->sif_regs)));
  674. num_u3_port =
  675. SSUSB_U3_PORT_NUM(readl((void __iomem *)_SSUSB_IP_CAP(xhci->sif_regs)));
  676. if (num_u3_port) {
  677. #if 0
  678. /* set MAC reference clock speed */
  679. addr =
  680. (void __iomem *)(_SSUSB_U3_MAC_BASE(xhci->base_regs) +
  681. U3_UX_EXIT_LFPS_TIMING_PAR);
  682. temp = readl(addr);
  683. temp &= ~(0xff << U3_RX_UX_EXIT_LFPS_REF_OFFSET);
  684. temp |= (U3_RX_UX_EXIT_LFPS_REF << U3_RX_UX_EXIT_LFPS_REF_OFFSET);
  685. writel(temp, addr);
  686. addr =
  687. (void __iomem *)(_SSUSB_U3_MAC_BASE(xhci->base_regs) + U3_REF_CK_PAR);
  688. temp = readl(addr);
  689. temp &= ~(0xff);
  690. temp |= U3_REF_CK_VAL;
  691. writel(temp, addr);
  692. #endif
  693. /* set U3 MAC SYS_CK */
  694. addr =
  695. (void __iomem *)(_SSUSB_U3_SYS_BASE(xhci->base_regs) +
  696. U3_TIMING_PULSE_CTRL);
  697. temp = readl(addr);
  698. temp &= ~(0xff);
  699. temp |= MTK_CNT_1US_VALUE;
  700. writel(temp, addr);
  701. }
  702. /* set U2 MAC SYS_CK */
  703. addr =
  704. (void __iomem *)(_SSUSB_U2_SYS_BASE(xhci->base_regs) + USB20_TIMING_PARAMETER);
  705. temp &= ~(0xff);
  706. temp |= MTK_TIME_VALUE_1US;
  707. writel(temp, addr);
  708. mtk_xhci_mtk_log("mu3d u2 mac sys_clk, addr 0x%p, value 0x%x\n",
  709. (void *)(_SSUSB_U2_SYS_BASE(xhci->base_regs) +
  710. USB20_TIMING_PARAMETER),
  711. readl((void __iomem *)(_SSUSB_U2_SYS_BASE(xhci->base_regs) +
  712. (unsigned long)USB20_TIMING_PARAMETER)));
  713. #if 0
  714. if (num_u3_port) {
  715. /* set LINK_PM_TIMER=3 */
  716. addr =
  717. (void __iomem *)(_SSUSB_U3_SYS_BASE(xhci->base_regs) + LINK_PM_TIMER);
  718. temp = readl(addr);
  719. temp &= ~(0xf);
  720. temp |= MTK_PM_LC_TIMEOUT_VALUE;
  721. writel(temp, addr);
  722. }
  723. #endif
  724. }
  725. #endif
  726. }
  727. static void setLatchSel(struct xhci_hcd *xhci)
  728. {
  729. void __iomem *latch_sel_addr;
  730. u32 latch_sel_value;
  731. int num_u3_port;
  732. num_u3_port = SSUSB_U3_PORT_NUM(readl((void __iomem *)_SSUSB_IP_CAP(xhci->sif_regs)));
  733. if (num_u3_port <= 0)
  734. return;
  735. latch_sel_addr = (void __iomem *)_U3_PIPE_LATCH_SEL_ADD(xhci->base_regs);
  736. latch_sel_value = ((U3_PIPE_LATCH_TX) << 2) | (U3_PIPE_LATCH_RX);
  737. writel(latch_sel_value, latch_sel_addr);
  738. }
  739. #ifndef CONFIG_USB_MTK_DUALMODE
  740. static int mtk_xhci_phy_init(int argc, char **argv)
  741. {
  742. /* initialize PHY related data structure */
  743. if (!u3phy_ops)
  744. u3phy_init();
  745. /* USB 2.0 slew rate calibration */
  746. if (u3phy_ops->u2_slew_rate_calibration)
  747. u3phy_ops->u2_slew_rate_calibration(u3phy);
  748. else
  749. mtk_xhci_mtk_log("WARN: PHY doesn't implement u2 slew rate calibration function\n");
  750. /* phy initialization */
  751. if (u3phy_ops->init(u3phy) != PHY_TRUE)
  752. return RET_FAIL;
  753. mtk_xhci_mtk_log("phy registers and operations initial done\n");
  754. return RET_SUCCESS;
  755. }
  756. #endif
  757. int mtk_xhci_ip_init(struct usb_hcd *hcd, struct xhci_hcd *xhci)
  758. {
  759. mtk_xhci_set(hcd, xhci);
  760. #ifdef CONFIG_MTK_FPGA
  761. u3_base = (void __iomem *)xhci->base_regs;
  762. u3_sif_base = (void __iomem *)xhci->sif_regs;
  763. u3_sif2_base = (void __iomem *)xhci->sif2_regs;
  764. i2c1_base = ioremap(0x11008000, 0x1000);
  765. if (!(i2c1_base))
  766. pr_err("Can't remap I2C1 BASE\n");
  767. mtk_xhci_mtk_log("%s(%d): i2c1_base, logic x%x, phys 0x%p\n", __func__, __LINE__, 0x11008000,
  768. (void *)i2c1_base);
  769. #endif
  770. /* phy initialization is done by device, if target runs on dual mode */
  771. #ifndef CONFIG_USB_MTK_DUALMODE
  772. mtk_xhci_phy_init(0, NULL);
  773. enableAllClockPower(xhci, 1); /* host do reset ip */
  774. #else
  775. enableAllClockPower(xhci, 1); /* device do reset ip */
  776. #endif
  777. setLatchSel(xhci);
  778. mtk_xhci_ck_timer_init(xhci);
  779. return 0;
  780. }
  781. #if 0
  782. int mtk_xhci_get_port_num(void)
  783. {
  784. return SSUSB_U3_PORT_NUM(readl((void __iomem *)SSUSB_IP_CAP))
  785. + SSUSB_U2_PORT_NUM(readl((void __iomem *)SSUSB_IP_CAP));
  786. }
  787. #endif
  788. #ifdef CONFIG_USBIF_COMPLIANCE
  789. #ifndef CONFIG_USB_MTK_DUALMODE
  790. static int xhci_hcd_driver_init(void)
  791. {
  792. int retval;
  793. retval = xhci_register_pci();
  794. if (retval < 0) {
  795. mtk_xhci_mtk_log(KERN_DEBUG "Problem registering PCI driver.");
  796. return retval;
  797. }
  798. #ifdef CONFIG_USB_XHCI_MTK
  799. mtk_xhci_ip_init();
  800. #endif
  801. retval = xhci_register_plat();
  802. if (retval < 0) {
  803. mtk_xhci_mtk_log(KERN_DEBUG "Problem registering platform driver.");
  804. goto unreg_pci;
  805. }
  806. #ifdef CONFIG_USB_XHCI_MTK
  807. retval = xhci_attrs_init();
  808. if (retval < 0) {
  809. mtk_xhci_mtk_log(KERN_DEBUG "Problem creating xhci attributes.");
  810. goto unreg_plat;
  811. }
  812. mtk_xhci_wakelock_init();
  813. #endif
  814. /*
  815. * Check the compiler generated sizes of structures that must be laid
  816. * out in specific ways for hardware access.
  817. */
  818. BUILD_BUG_ON(sizeof(struct xhci_doorbell_array) != 256*32/8);
  819. BUILD_BUG_ON(sizeof(struct xhci_slot_ctx) != 8*32/8);
  820. BUILD_BUG_ON(sizeof(struct xhci_ep_ctx) != 8*32/8);
  821. /* xhci_device_control has eight fields, and also
  822. * embeds one xhci_slot_ctx and 31 xhci_ep_ctx
  823. */
  824. BUILD_BUG_ON(sizeof(struct xhci_stream_ctx) != 4*32/8);
  825. BUILD_BUG_ON(sizeof(union xhci_trb) != 4*32/8);
  826. BUILD_BUG_ON(sizeof(struct xhci_erst_entry) != 4*32/8);
  827. BUILD_BUG_ON(sizeof(struct xhci_cap_regs) != 7*32/8);
  828. BUILD_BUG_ON(sizeof(struct xhci_intr_reg) != 8*32/8);
  829. /* xhci_run_regs has eight fields and embeds 128 xhci_intr_regs */
  830. BUILD_BUG_ON(sizeof(struct xhci_run_regs) != (8+8*128)*32/8);
  831. return 0;
  832. #ifdef CONFIG_USB_XHCI_MTK
  833. unreg_plat:
  834. xhci_unregister_plat();
  835. #endif
  836. unreg_pci:
  837. xhci_unregister_pci();
  838. return retval;
  839. }
  840. static void xhci_hcd_driver_cleanup(void)
  841. {
  842. xhci_unregister_pci();
  843. xhci_unregister_plat();
  844. xhci_attrs_exit();
  845. }
  846. #else
  847. static int xhci_hcd_driver_init(void)
  848. {
  849. /* init in mt_devs.c*/
  850. mtk_xhci_eint_iddig_init();
  851. mtk_xhci_switch_init();
  852. /*mtk_xhci_wakelock_init();*/
  853. return 0;
  854. }
  855. static void xhci_hcd_driver_cleanup(void)
  856. {
  857. mtk_xhci_eint_iddig_deinit();
  858. }
  859. #endif
  860. static int mu3h_normal_driver_on;
  861. static int xhci_mu3h_proc_show(struct seq_file *seq, void *v)
  862. {
  863. seq_printf(seq, "xhci_mu3h_proc_show, mu3h is %d (on:1, off:0)\n", mu3h_normal_driver_on);
  864. return 0;
  865. }
  866. static int xhci_mu3h_proc_open(struct inode *inode, struct file *file)
  867. {
  868. return single_open(file, xhci_mu3h_proc_show, inode->i_private);
  869. }
  870. static ssize_t xhci_mu3h_proc_write(struct file *file, const char __user *buf, size_t length, loff_t *ppos)
  871. {
  872. int ret;
  873. char msg[32];
  874. int result;
  875. if (length >= sizeof(msg)) {
  876. mtk_xhci_mtk_log("xhci_mu3h_proc_write length error, the error len is %d\n", (unsigned int)length);
  877. return -EINVAL;
  878. }
  879. if (copy_from_user(msg, buf, length))
  880. return -EFAULT;
  881. msg[length] = 0;
  882. mtk_xhci_mtk_log("xhci_mu3h_proc_write: %s, current driver on/off: %d\n", msg, mu3h_normal_driver_on);
  883. if ((msg[0] == '1') && (mu3h_normal_driver_on == 0)) {
  884. xhci_hcd_driver_init();
  885. mu3h_normal_driver_on = 1;
  886. mtk_xhci_mtk_log("registe mu3h driver : m3h xhci driver\n");
  887. } else if ((msg[0] == '0') && (mu3h_normal_driver_on == 1)) {
  888. xhci_hcd_driver_cleanup();
  889. mu3h_normal_driver_on = 0;
  890. mtk_xhci_mtk_log("unregiste m3h xhci driver.\n");
  891. else
  892. mtk_xhci_mtk_log("xhci_mu3h_proc_write write faile !\n");
  893. return length;
  894. }
  895. static const struct file_operations mu3h_proc_fops = {
  896. .owner = THIS_MODULE,
  897. .open = xhci_mu3h_proc_open,
  898. .write = xhci_mu3h_proc_write,
  899. .read = seq_read,
  900. .llseek = seq_lseek,
  901. };
  902. static int __init xhci_hcd_init(void)
  903. {
  904. struct proc_dir_entry *prEntry;
  905. mtk_xhci_mtk_log(KERN_DEBUG "xhci_hcd_init");
  906. /* set xhci up at boot up*/
  907. xhci_hcd_driver_init();
  908. mtk_xhci_wakelock_init();
  909. mu3h_normal_driver_on = 1;
  910. /* USBIF */
  911. prEntry = proc_create("mu3h_driver_init", 0666, NULL, &mu3h_proc_fops);
  912. if (prEntry) {
  913. mtk_xhci_mtk_log("create the mu3h init proc OK!\n");
  914. else
  915. mtk_xhci_mtk_log("[ERROR] create the mu3h init proc FAIL\n");
  916. #ifdef CONFIG_USB_XHCI_MTK
  917. if (!misc_register(&mu3h_uevent_device))
  918. mtk_xhci_mtk_log("create the mu3h_uevent_device uevent device OK!\n");
  919. else
  920. mtk_xhci_mtk_log("[ERROR] create the mu3h_uevent_device uevent device fail\n");
  921. #endif
  922. return 0;
  923. }
  924. module_init(xhci_hcd_init);
  925. static void __exit xhci_hcd_cleanup(void)
  926. {
  927. #ifdef CONFIG_USB_XHCI_MTK
  928. misc_deregister(&mu3h_uevent_device);
  929. #endif
  930. mtk_xhci_mtk_log(KERN_DEBUG "xhci_hcd_cleanup");
  931. }
  932. module_exit(xhci_hcd_cleanup);
  933. #else
  934. #ifndef CONFIG_USB_MTK_DUALMODE
  935. static int __init xhci_hcd_init(void)
  936. {
  937. int retval;
  938. retval = xhci_register_pci();
  939. if (retval < 0) {
  940. mtk_xhci_mtk_log("Problem registering PCI driver.");
  941. return retval;
  942. }
  943. retval = xhci_register_plat();
  944. if (retval < 0) {
  945. mtk_xhci_mtk_log("Problem registering platform driver.");
  946. goto unreg_pci;
  947. }
  948. retval = xhci_attrs_init();
  949. if (retval < 0) {
  950. mtk_xhci_mtk_log("Problem creating xhci attributes.");
  951. goto unreg_plat;
  952. }
  953. mtk_xhci_wakelock_init();
  954. /*
  955. * Check the compiler generated sizes of structures that must be laid
  956. * out in specific ways for hardware access.
  957. */
  958. BUILD_BUG_ON(sizeof(struct xhci_doorbell_array) != 256*32/8);
  959. BUILD_BUG_ON(sizeof(struct xhci_slot_ctx) != 8*32/8);
  960. BUILD_BUG_ON(sizeof(struct xhci_ep_ctx) != 8*32/8);
  961. /* xhci_device_control has eight fields, and also
  962. * embeds one xhci_slot_ctx and 31 xhci_ep_ctx
  963. */
  964. BUILD_BUG_ON(sizeof(struct xhci_stream_ctx) != 4*32/8);
  965. BUILD_BUG_ON(sizeof(union xhci_trb) != 4*32/8);
  966. BUILD_BUG_ON(sizeof(struct xhci_erst_entry) != 4*32/8);
  967. BUILD_BUG_ON(sizeof(struct xhci_cap_regs) != 7*32/8);
  968. BUILD_BUG_ON(sizeof(struct xhci_intr_reg) != 8*32/8);
  969. /* xhci_run_regs has eight fields and embeds 128 xhci_intr_regs */
  970. BUILD_BUG_ON(sizeof(struct xhci_run_regs) != (8+8*128)*32/8);
  971. return 0;
  972. #ifdef CONFIG_USB_XHCI_MTK
  973. unreg_plat:
  974. xhci_unregister_plat();
  975. #endif
  976. unreg_pci:
  977. xhci_unregister_pci();
  978. return retval;
  979. }
  980. module_init(xhci_hcd_init);
  981. static void __exit xhci_hcd_cleanup(void)
  982. {
  983. xhci_unregister_pci();
  984. xhci_unregister_plat();
  985. xhci_attrs_exit();
  986. }
  987. module_exit(xhci_hcd_cleanup);
  988. #else /*CONFIG_USB_MTK_DUALMODE*/
  989. static int __init xhci_hcd_init(void)
  990. {
  991. mtk_xhci_eint_iddig_init();
  992. mtk_xhci_switch_init();
  993. mtk_xhci_wakelock_init();
  994. return 0;
  995. }
  996. late_initcall(xhci_hcd_init);
  997. static void __exit xhci_hcd_cleanup(void)
  998. {
  999. }
  1000. module_exit(xhci_hcd_cleanup);
  1001. #endif
  1002. #endif