usb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Platform level USB initialization for FS USB OTG controller on omap1
  4. *
  5. * Copyright (C) 2004 Texas Instruments, Inc.
  6. */
  7. #include <linux/module.h>
  8. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/dma-map-ops.h>
  12. #include <linux/io.h>
  13. #include <linux/delay.h>
  14. #include <linux/soc/ti/omap1-io.h>
  15. #include <asm/irq.h>
  16. #include "hardware.h"
  17. #include "mux.h"
  18. #include "usb.h"
  19. #include "common.h"
  20. /* These routines should handle the standard chip-specific modes
  21. * for usb0/1/2 ports, covering basic mux and transceiver setup.
  22. *
  23. * Some board-*.c files will need to set up additional mux options,
  24. * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup.
  25. */
  26. /* TESTED ON:
  27. * - 1611B H2 (with usb1 mini-AB) using standard Mini-B or OTG cables
  28. * - 5912 OSK OHCI (with usb0 standard-A), standard A-to-B cables
  29. * - 5912 OSK UDC, with *nonstandard* A-to-A cable
  30. * - 1510 Innovator UDC with bundled usb0 cable
  31. * - 1510 Innovator OHCI with bundled usb1/usb2 cable
  32. * - 1510 Innovator OHCI with custom usb0 cable, feeding 5V VBUS
  33. * - 1710 custom development board using alternate pin group
  34. * - 1710 H3 (with usb1 mini-AB) using standard Mini-B or OTG cables
  35. */
  36. #define INT_USB_IRQ_GEN IH2_BASE + 20
  37. #define INT_USB_IRQ_NISO IH2_BASE + 30
  38. #define INT_USB_IRQ_ISO IH2_BASE + 29
  39. #define INT_USB_IRQ_HGEN INT_USB_HHC_1
  40. #define INT_USB_IRQ_OTG IH2_BASE + 8
  41. #ifdef CONFIG_ARCH_OMAP_OTG
  42. static void __init
  43. omap_otg_init(struct omap_usb_config *config)
  44. {
  45. u32 syscon;
  46. int alt_pingroup = 0;
  47. u16 w;
  48. /* NOTE: no bus or clock setup (yet?) */
  49. syscon = omap_readl(OTG_SYSCON_1) & 0xffff;
  50. if (!(syscon & OTG_RESET_DONE))
  51. pr_debug("USB resets not complete?\n");
  52. //omap_writew(0, OTG_IRQ_EN);
  53. /* pin muxing and transceiver pinouts */
  54. if (config->pins[0] > 2) /* alt pingroup 2 */
  55. alt_pingroup = 1;
  56. syscon |= config->usb0_init(config->pins[0], is_usb0_device(config));
  57. syscon |= config->usb1_init(config->pins[1]);
  58. syscon |= config->usb2_init(config->pins[2], alt_pingroup);
  59. pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
  60. omap_writel(syscon, OTG_SYSCON_1);
  61. syscon = config->hmc_mode;
  62. syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
  63. #ifdef CONFIG_USB_OTG
  64. if (config->otg)
  65. syscon |= OTG_EN;
  66. #endif
  67. pr_debug("USB_TRANSCEIVER_CTRL = %03x\n",
  68. omap_readl(USB_TRANSCEIVER_CTRL));
  69. pr_debug("OTG_SYSCON_2 = %08x\n", omap_readl(OTG_SYSCON_2));
  70. omap_writel(syscon, OTG_SYSCON_2);
  71. printk("USB: hmc %d", config->hmc_mode);
  72. if (!alt_pingroup)
  73. pr_cont(", usb2 alt %d wires", config->pins[2]);
  74. else if (config->pins[0])
  75. pr_cont(", usb0 %d wires%s", config->pins[0],
  76. is_usb0_device(config) ? " (dev)" : "");
  77. if (config->pins[1])
  78. pr_cont(", usb1 %d wires", config->pins[1]);
  79. if (!alt_pingroup && config->pins[2])
  80. pr_cont(", usb2 %d wires", config->pins[2]);
  81. if (config->otg)
  82. pr_cont(", Mini-AB on usb%d", config->otg - 1);
  83. pr_cont("\n");
  84. /* leave USB clocks/controllers off until needed */
  85. w = omap_readw(ULPD_SOFT_REQ);
  86. w &= ~SOFT_USB_CLK_REQ;
  87. omap_writew(w, ULPD_SOFT_REQ);
  88. w = omap_readw(ULPD_CLOCK_CTRL);
  89. w &= ~USB_MCLK_EN;
  90. w |= DIS_USB_PVCI_CLK;
  91. omap_writew(w, ULPD_CLOCK_CTRL);
  92. syscon = omap_readl(OTG_SYSCON_1);
  93. syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
  94. #if IS_ENABLED(CONFIG_USB_OMAP)
  95. if (config->otg || config->register_dev) {
  96. struct platform_device *udc_device = config->udc_device;
  97. int status;
  98. syscon &= ~DEV_IDLE_EN;
  99. udc_device->dev.platform_data = config;
  100. status = platform_device_register(udc_device);
  101. if (status)
  102. pr_debug("can't register UDC device, %d\n", status);
  103. }
  104. #endif
  105. #if IS_ENABLED(CONFIG_USB_OHCI_HCD)
  106. if (config->otg || config->register_host) {
  107. struct platform_device *ohci_device = config->ohci_device;
  108. int status;
  109. syscon &= ~HST_IDLE_EN;
  110. ohci_device->dev.platform_data = config;
  111. status = platform_device_register(ohci_device);
  112. if (status)
  113. pr_debug("can't register OHCI device, %d\n", status);
  114. }
  115. #endif
  116. #ifdef CONFIG_USB_OTG
  117. if (config->otg) {
  118. struct platform_device *otg_device = config->otg_device;
  119. int status;
  120. syscon &= ~OTG_IDLE_EN;
  121. otg_device->dev.platform_data = config;
  122. status = platform_device_register(otg_device);
  123. if (status)
  124. pr_debug("can't register OTG device, %d\n", status);
  125. }
  126. #endif
  127. pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
  128. omap_writel(syscon, OTG_SYSCON_1);
  129. }
  130. #else
  131. static void omap_otg_init(struct omap_usb_config *config) {}
  132. #endif
  133. #if IS_ENABLED(CONFIG_USB_OMAP)
  134. static struct resource udc_resources[] = {
  135. /* order is significant! */
  136. { /* registers */
  137. .start = UDC_BASE,
  138. .end = UDC_BASE + 0xff,
  139. .flags = IORESOURCE_MEM,
  140. }, { /* general IRQ */
  141. .start = INT_USB_IRQ_GEN,
  142. .flags = IORESOURCE_IRQ,
  143. }, { /* PIO IRQ */
  144. .start = INT_USB_IRQ_NISO,
  145. .flags = IORESOURCE_IRQ,
  146. }, { /* SOF IRQ */
  147. .start = INT_USB_IRQ_ISO,
  148. .flags = IORESOURCE_IRQ,
  149. },
  150. };
  151. static u64 udc_dmamask = ~(u32)0;
  152. static struct platform_device udc_device = {
  153. .name = "omap_udc",
  154. .id = -1,
  155. .dev = {
  156. .dma_mask = &udc_dmamask,
  157. .coherent_dma_mask = 0xffffffff,
  158. },
  159. .num_resources = ARRAY_SIZE(udc_resources),
  160. .resource = udc_resources,
  161. };
  162. static inline void udc_device_init(struct omap_usb_config *pdata)
  163. {
  164. pdata->udc_device = &udc_device;
  165. }
  166. #else
  167. static inline void udc_device_init(struct omap_usb_config *pdata)
  168. {
  169. }
  170. #endif
  171. /* The dmamask must be set for OHCI to work */
  172. static u64 ohci_dmamask = ~(u32)0;
  173. static struct resource ohci_resources[] = {
  174. {
  175. .start = OMAP_OHCI_BASE,
  176. .end = OMAP_OHCI_BASE + 0xff,
  177. .flags = IORESOURCE_MEM,
  178. },
  179. {
  180. .start = INT_USB_IRQ_HGEN,
  181. .flags = IORESOURCE_IRQ,
  182. },
  183. };
  184. static struct platform_device ohci_device = {
  185. .name = "ohci",
  186. .id = -1,
  187. .dev = {
  188. .dma_mask = &ohci_dmamask,
  189. .coherent_dma_mask = 0xffffffff,
  190. },
  191. .num_resources = ARRAY_SIZE(ohci_resources),
  192. .resource = ohci_resources,
  193. };
  194. static inline void ohci_device_init(struct omap_usb_config *pdata)
  195. {
  196. if (!IS_ENABLED(CONFIG_USB_OHCI_HCD))
  197. return;
  198. pdata->ohci_device = &ohci_device;
  199. pdata->ocpi_enable = &ocpi_enable;
  200. }
  201. #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
  202. static struct resource otg_resources[] = {
  203. /* order is significant! */
  204. {
  205. .start = OTG_BASE,
  206. .end = OTG_BASE + 0xff,
  207. .flags = IORESOURCE_MEM,
  208. }, {
  209. .start = INT_USB_IRQ_OTG,
  210. .flags = IORESOURCE_IRQ,
  211. },
  212. };
  213. static struct platform_device otg_device = {
  214. .name = "omap_otg",
  215. .id = -1,
  216. .num_resources = ARRAY_SIZE(otg_resources),
  217. .resource = otg_resources,
  218. };
  219. static inline void otg_device_init(struct omap_usb_config *pdata)
  220. {
  221. pdata->otg_device = &otg_device;
  222. }
  223. #else
  224. static inline void otg_device_init(struct omap_usb_config *pdata)
  225. {
  226. }
  227. #endif
  228. static u32 __init omap1_usb0_init(unsigned nwires, unsigned is_device)
  229. {
  230. u32 syscon1 = 0;
  231. if (nwires == 0) {
  232. if (!cpu_is_omap15xx()) {
  233. u32 l;
  234. /* pulldown D+/D- */
  235. l = omap_readl(USB_TRANSCEIVER_CTRL);
  236. l &= ~(3 << 1);
  237. omap_writel(l, USB_TRANSCEIVER_CTRL);
  238. }
  239. return 0;
  240. }
  241. if (is_device) {
  242. omap_cfg_reg(W4_USB_PUEN);
  243. }
  244. if (nwires == 2) {
  245. u32 l;
  246. // omap_cfg_reg(P9_USB_DP);
  247. // omap_cfg_reg(R8_USB_DM);
  248. if (cpu_is_omap15xx()) {
  249. /* This works on 1510-Innovator */
  250. return 0;
  251. }
  252. /* NOTES:
  253. * - peripheral should configure VBUS detection!
  254. * - only peripherals may use the internal D+/D- pulldowns
  255. * - OTG support on this port not yet written
  256. */
  257. l = omap_readl(USB_TRANSCEIVER_CTRL);
  258. l &= ~(7 << 4);
  259. if (!is_device)
  260. l |= (3 << 1);
  261. omap_writel(l, USB_TRANSCEIVER_CTRL);
  262. return 3 << 16;
  263. }
  264. /* alternate pin config, external transceiver */
  265. if (cpu_is_omap15xx()) {
  266. printk(KERN_ERR "no usb0 alt pin config on 15xx\n");
  267. return 0;
  268. }
  269. omap_cfg_reg(V6_USB0_TXD);
  270. omap_cfg_reg(W9_USB0_TXEN);
  271. omap_cfg_reg(W5_USB0_SE0);
  272. if (nwires != 3)
  273. omap_cfg_reg(Y5_USB0_RCV);
  274. /* NOTE: SPEED and SUSP aren't configured here. OTG hosts
  275. * may be able to use I2C requests to set those bits along
  276. * with VBUS switching and overcurrent detection.
  277. */
  278. if (nwires != 6) {
  279. u32 l;
  280. l = omap_readl(USB_TRANSCEIVER_CTRL);
  281. l &= ~CONF_USB2_UNI_R;
  282. omap_writel(l, USB_TRANSCEIVER_CTRL);
  283. }
  284. switch (nwires) {
  285. case 3:
  286. syscon1 = 2;
  287. break;
  288. case 4:
  289. syscon1 = 1;
  290. break;
  291. case 6:
  292. syscon1 = 3;
  293. {
  294. u32 l;
  295. omap_cfg_reg(AA9_USB0_VP);
  296. omap_cfg_reg(R9_USB0_VM);
  297. l = omap_readl(USB_TRANSCEIVER_CTRL);
  298. l |= CONF_USB2_UNI_R;
  299. omap_writel(l, USB_TRANSCEIVER_CTRL);
  300. }
  301. break;
  302. default:
  303. printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
  304. 0, nwires);
  305. }
  306. return syscon1 << 16;
  307. }
  308. static u32 __init omap1_usb1_init(unsigned nwires)
  309. {
  310. u32 syscon1 = 0;
  311. if (!cpu_is_omap15xx() && nwires != 6) {
  312. u32 l;
  313. l = omap_readl(USB_TRANSCEIVER_CTRL);
  314. l &= ~CONF_USB1_UNI_R;
  315. omap_writel(l, USB_TRANSCEIVER_CTRL);
  316. }
  317. if (nwires == 0)
  318. return 0;
  319. /* external transceiver */
  320. omap_cfg_reg(USB1_TXD);
  321. omap_cfg_reg(USB1_TXEN);
  322. if (nwires != 3)
  323. omap_cfg_reg(USB1_RCV);
  324. if (cpu_is_omap15xx()) {
  325. omap_cfg_reg(USB1_SEO);
  326. omap_cfg_reg(USB1_SPEED);
  327. // SUSP
  328. } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
  329. omap_cfg_reg(W13_1610_USB1_SE0);
  330. omap_cfg_reg(R13_1610_USB1_SPEED);
  331. // SUSP
  332. } else if (cpu_is_omap1710()) {
  333. omap_cfg_reg(R13_1710_USB1_SE0);
  334. // SUSP
  335. } else {
  336. pr_debug("usb%d cpu unrecognized\n", 1);
  337. return 0;
  338. }
  339. switch (nwires) {
  340. case 2:
  341. goto bad;
  342. case 3:
  343. syscon1 = 2;
  344. break;
  345. case 4:
  346. syscon1 = 1;
  347. break;
  348. case 6:
  349. syscon1 = 3;
  350. omap_cfg_reg(USB1_VP);
  351. omap_cfg_reg(USB1_VM);
  352. if (!cpu_is_omap15xx()) {
  353. u32 l;
  354. l = omap_readl(USB_TRANSCEIVER_CTRL);
  355. l |= CONF_USB1_UNI_R;
  356. omap_writel(l, USB_TRANSCEIVER_CTRL);
  357. }
  358. break;
  359. default:
  360. bad:
  361. printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
  362. 1, nwires);
  363. }
  364. return syscon1 << 20;
  365. }
  366. static u32 __init omap1_usb2_init(unsigned nwires, unsigned alt_pingroup)
  367. {
  368. u32 syscon1 = 0;
  369. /* NOTE omap1 erratum: must leave USB2_UNI_R set if usb0 in use */
  370. if (alt_pingroup || nwires == 0)
  371. return 0;
  372. if (!cpu_is_omap15xx() && nwires != 6) {
  373. u32 l;
  374. l = omap_readl(USB_TRANSCEIVER_CTRL);
  375. l &= ~CONF_USB2_UNI_R;
  376. omap_writel(l, USB_TRANSCEIVER_CTRL);
  377. }
  378. /* external transceiver */
  379. if (cpu_is_omap15xx()) {
  380. omap_cfg_reg(USB2_TXD);
  381. omap_cfg_reg(USB2_TXEN);
  382. omap_cfg_reg(USB2_SEO);
  383. if (nwires != 3)
  384. omap_cfg_reg(USB2_RCV);
  385. /* there is no USB2_SPEED */
  386. } else if (cpu_is_omap16xx()) {
  387. omap_cfg_reg(V6_USB2_TXD);
  388. omap_cfg_reg(W9_USB2_TXEN);
  389. omap_cfg_reg(W5_USB2_SE0);
  390. if (nwires != 3)
  391. omap_cfg_reg(Y5_USB2_RCV);
  392. // FIXME omap_cfg_reg(USB2_SPEED);
  393. } else {
  394. pr_debug("usb%d cpu unrecognized\n", 1);
  395. return 0;
  396. }
  397. // omap_cfg_reg(USB2_SUSP);
  398. switch (nwires) {
  399. case 2:
  400. goto bad;
  401. case 3:
  402. syscon1 = 2;
  403. break;
  404. case 4:
  405. syscon1 = 1;
  406. break;
  407. case 5:
  408. goto bad;
  409. case 6:
  410. syscon1 = 3;
  411. if (cpu_is_omap15xx()) {
  412. omap_cfg_reg(USB2_VP);
  413. omap_cfg_reg(USB2_VM);
  414. } else {
  415. u32 l;
  416. omap_cfg_reg(AA9_USB2_VP);
  417. omap_cfg_reg(R9_USB2_VM);
  418. l = omap_readl(USB_TRANSCEIVER_CTRL);
  419. l |= CONF_USB2_UNI_R;
  420. omap_writel(l, USB_TRANSCEIVER_CTRL);
  421. }
  422. break;
  423. default:
  424. bad:
  425. printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
  426. 2, nwires);
  427. }
  428. return syscon1 << 24;
  429. }
  430. #ifdef CONFIG_ARCH_OMAP15XX
  431. /* OMAP-1510 OHCI has its own MMU for DMA */
  432. #define OMAP1510_LB_MEMSIZE 32 /* Should be same as SDRAM size */
  433. #define OMAP1510_LB_CLOCK_DIV 0xfffec10c
  434. #define OMAP1510_LB_MMU_CTL 0xfffec208
  435. #define OMAP1510_LB_MMU_LCK 0xfffec224
  436. #define OMAP1510_LB_MMU_LD_TLB 0xfffec228
  437. #define OMAP1510_LB_MMU_CAM_H 0xfffec22c
  438. #define OMAP1510_LB_MMU_CAM_L 0xfffec230
  439. #define OMAP1510_LB_MMU_RAM_H 0xfffec234
  440. #define OMAP1510_LB_MMU_RAM_L 0xfffec238
  441. /*
  442. * Bus address is physical address, except for OMAP-1510 Local Bus.
  443. * OMAP-1510 bus address is translated into a Local Bus address if the
  444. * OMAP bus type is lbus.
  445. */
  446. #define OMAP1510_LB_OFFSET UL(0x30000000)
  447. /*
  448. * OMAP-1510 specific Local Bus clock on/off
  449. */
  450. static int omap_1510_local_bus_power(int on)
  451. {
  452. if (on) {
  453. omap_writel((1 << 1) | (1 << 0), OMAP1510_LB_MMU_CTL);
  454. udelay(200);
  455. } else {
  456. omap_writel(0, OMAP1510_LB_MMU_CTL);
  457. }
  458. return 0;
  459. }
  460. /*
  461. * OMAP-1510 specific Local Bus initialization
  462. * NOTE: This assumes 32MB memory size in OMAP1510LB_MEMSIZE.
  463. * See also arch/mach-omap/memory.h for __virt_to_dma() and
  464. * __dma_to_virt() which need to match with the physical
  465. * Local Bus address below.
  466. */
  467. static int omap_1510_local_bus_init(void)
  468. {
  469. unsigned int tlb;
  470. unsigned long lbaddr, physaddr;
  471. omap_writel((omap_readl(OMAP1510_LB_CLOCK_DIV) & 0xfffffff8) | 0x4,
  472. OMAP1510_LB_CLOCK_DIV);
  473. /* Configure the Local Bus MMU table */
  474. for (tlb = 0; tlb < OMAP1510_LB_MEMSIZE; tlb++) {
  475. lbaddr = tlb * 0x00100000 + OMAP1510_LB_OFFSET;
  476. physaddr = tlb * 0x00100000 + PHYS_OFFSET;
  477. omap_writel((lbaddr & 0x0fffffff) >> 22, OMAP1510_LB_MMU_CAM_H);
  478. omap_writel(((lbaddr & 0x003ffc00) >> 6) | 0xc,
  479. OMAP1510_LB_MMU_CAM_L);
  480. omap_writel(physaddr >> 16, OMAP1510_LB_MMU_RAM_H);
  481. omap_writel((physaddr & 0x0000fc00) | 0x300, OMAP1510_LB_MMU_RAM_L);
  482. omap_writel(tlb << 4, OMAP1510_LB_MMU_LCK);
  483. omap_writel(0x1, OMAP1510_LB_MMU_LD_TLB);
  484. }
  485. /* Enable the walking table */
  486. omap_writel(omap_readl(OMAP1510_LB_MMU_CTL) | (1 << 3), OMAP1510_LB_MMU_CTL);
  487. udelay(200);
  488. return 0;
  489. }
  490. static void omap_1510_local_bus_reset(void)
  491. {
  492. omap_1510_local_bus_power(1);
  493. omap_1510_local_bus_init();
  494. }
  495. /* ULPD_DPLL_CTRL */
  496. #define DPLL_IOB (1 << 13)
  497. #define DPLL_PLL_ENABLE (1 << 4)
  498. #define DPLL_LOCK (1 << 0)
  499. /* ULPD_APLL_CTRL */
  500. #define APLL_NDPLL_SWITCH (1 << 0)
  501. static void __init omap_1510_usb_init(struct omap_usb_config *config)
  502. {
  503. unsigned int val;
  504. u16 w;
  505. config->usb0_init(config->pins[0], is_usb0_device(config));
  506. config->usb1_init(config->pins[1]);
  507. config->usb2_init(config->pins[2], 0);
  508. val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
  509. val |= (config->hmc_mode << 1);
  510. omap_writel(val, MOD_CONF_CTRL_0);
  511. printk("USB: hmc %d", config->hmc_mode);
  512. if (config->pins[0])
  513. pr_cont(", usb0 %d wires%s", config->pins[0],
  514. is_usb0_device(config) ? " (dev)" : "");
  515. if (config->pins[1])
  516. pr_cont(", usb1 %d wires", config->pins[1]);
  517. if (config->pins[2])
  518. pr_cont(", usb2 %d wires", config->pins[2]);
  519. pr_cont("\n");
  520. /* use DPLL for 48 MHz function clock */
  521. pr_debug("APLL %04x DPLL %04x REQ %04x\n", omap_readw(ULPD_APLL_CTRL),
  522. omap_readw(ULPD_DPLL_CTRL), omap_readw(ULPD_SOFT_REQ));
  523. w = omap_readw(ULPD_APLL_CTRL);
  524. w &= ~APLL_NDPLL_SWITCH;
  525. omap_writew(w, ULPD_APLL_CTRL);
  526. w = omap_readw(ULPD_DPLL_CTRL);
  527. w |= DPLL_IOB | DPLL_PLL_ENABLE;
  528. omap_writew(w, ULPD_DPLL_CTRL);
  529. w = omap_readw(ULPD_SOFT_REQ);
  530. w |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
  531. omap_writew(w, ULPD_SOFT_REQ);
  532. while (!(omap_readw(ULPD_DPLL_CTRL) & DPLL_LOCK))
  533. cpu_relax();
  534. #if IS_ENABLED(CONFIG_USB_OMAP)
  535. if (config->register_dev) {
  536. int status;
  537. udc_device.dev.platform_data = config;
  538. status = platform_device_register(&udc_device);
  539. if (status)
  540. pr_debug("can't register UDC device, %d\n", status);
  541. /* udc driver gates 48MHz by D+ pullup */
  542. }
  543. #endif
  544. if (IS_ENABLED(CONFIG_USB_OHCI_HCD) && config->register_host) {
  545. int status;
  546. ohci_device.dev.platform_data = config;
  547. dma_direct_set_offset(&ohci_device.dev, PHYS_OFFSET,
  548. OMAP1510_LB_OFFSET, (u64)-1);
  549. status = platform_device_register(&ohci_device);
  550. if (status)
  551. pr_debug("can't register OHCI device, %d\n", status);
  552. /* hcd explicitly gates 48MHz */
  553. config->lb_reset = omap_1510_local_bus_reset;
  554. }
  555. }
  556. #else
  557. static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
  558. #endif
  559. void __init omap1_usb_init(struct omap_usb_config *_pdata)
  560. {
  561. struct omap_usb_config *pdata;
  562. pdata = kmemdup(_pdata, sizeof(*pdata), GFP_KERNEL);
  563. if (!pdata)
  564. return;
  565. pdata->usb0_init = omap1_usb0_init;
  566. pdata->usb1_init = omap1_usb1_init;
  567. pdata->usb2_init = omap1_usb2_init;
  568. udc_device_init(pdata);
  569. ohci_device_init(pdata);
  570. otg_device_init(pdata);
  571. if (cpu_is_omap16xx())
  572. omap_otg_init(pdata);
  573. else if (cpu_is_omap15xx())
  574. omap_1510_usb_init(pdata);
  575. else
  576. printk(KERN_ERR "USB: No init for your chip yet\n");
  577. }