usb.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /*
  2. * arch/arm/plat-omap/usb.c -- platform level USB initialization
  3. *
  4. * Copyright (C) 2004 Texas Instruments, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #undef DEBUG
  21. #include <linux/module.h>
  22. #include <linux/kernel.h>
  23. #include <linux/types.h>
  24. #include <linux/errno.h>
  25. #include <linux/init.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/usb/otg.h>
  28. #include <asm/io.h>
  29. #include <asm/irq.h>
  30. #include <asm/system.h>
  31. #include <asm/hardware.h>
  32. #include <asm/arch/mux.h>
  33. #include <asm/arch/usb.h>
  34. #include <asm/arch/board.h>
  35. #ifdef CONFIG_ARCH_OMAP1
  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. #else
  42. #define INT_USB_IRQ_GEN INT_24XX_USB_IRQ_GEN
  43. #define INT_USB_IRQ_NISO INT_24XX_USB_IRQ_NISO
  44. #define INT_USB_IRQ_ISO INT_24XX_USB_IRQ_ISO
  45. #define INT_USB_IRQ_HGEN INT_24XX_USB_IRQ_HGEN
  46. #define INT_USB_IRQ_OTG INT_24XX_USB_IRQ_OTG
  47. #endif
  48. /* These routines should handle the standard chip-specific modes
  49. * for usb0/1/2 ports, covering basic mux and transceiver setup.
  50. *
  51. * Some board-*.c files will need to set up additional mux options,
  52. * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup.
  53. */
  54. /* TESTED ON:
  55. * - 1611B H2 (with usb1 mini-AB) using standard Mini-B or OTG cables
  56. * - 5912 OSK OHCI (with usb0 standard-A), standard A-to-B cables
  57. * - 5912 OSK UDC, with *nonstandard* A-to-A cable
  58. * - 1510 Innovator UDC with bundled usb0 cable
  59. * - 1510 Innovator OHCI with bundled usb1/usb2 cable
  60. * - 1510 Innovator OHCI with custom usb0 cable, feeding 5V VBUS
  61. * - 1710 custom development board using alternate pin group
  62. * - 1710 H3 (with usb1 mini-AB) using standard Mini-B or OTG cables
  63. */
  64. /*-------------------------------------------------------------------------*/
  65. #ifdef CONFIG_ARCH_OMAP_OTG
  66. static struct otg_transceiver *xceiv;
  67. /**
  68. * otg_get_transceiver - find the (single) OTG transceiver driver
  69. *
  70. * Returns the transceiver driver, after getting a refcount to it; or
  71. * null if there is no such transceiver. The caller is responsible for
  72. * releasing that count.
  73. */
  74. struct otg_transceiver *otg_get_transceiver(void)
  75. {
  76. if (xceiv)
  77. get_device(xceiv->dev);
  78. return xceiv;
  79. }
  80. EXPORT_SYMBOL(otg_get_transceiver);
  81. int otg_set_transceiver(struct otg_transceiver *x)
  82. {
  83. if (xceiv && x)
  84. return -EBUSY;
  85. xceiv = x;
  86. return 0;
  87. }
  88. EXPORT_SYMBOL(otg_set_transceiver);
  89. #endif
  90. /*-------------------------------------------------------------------------*/
  91. #if defined(CONFIG_ARCH_OMAP_OTG) || defined(CONFIG_ARCH_OMAP15XX)
  92. static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
  93. {
  94. u32 syscon1 = 0;
  95. if (cpu_is_omap24xx())
  96. CONTROL_DEVCONF_REG &= ~USBT0WRMODEI(USB_BIDIR_TLL);
  97. if (nwires == 0) {
  98. if (cpu_class_is_omap1() && !cpu_is_omap15xx()) {
  99. /* pulldown D+/D- */
  100. USB_TRANSCEIVER_CTRL_REG &= ~(3 << 1);
  101. }
  102. return 0;
  103. }
  104. if (is_device) {
  105. if (cpu_is_omap24xx())
  106. omap_cfg_reg(J20_24XX_USB0_PUEN);
  107. else
  108. omap_cfg_reg(W4_USB_PUEN);
  109. }
  110. /* internal transceiver (unavailable on 17xx, 24xx) */
  111. if (!cpu_class_is_omap2() && nwires == 2) {
  112. // omap_cfg_reg(P9_USB_DP);
  113. // omap_cfg_reg(R8_USB_DM);
  114. if (cpu_is_omap15xx()) {
  115. /* This works on 1510-Innovator */
  116. return 0;
  117. }
  118. /* NOTES:
  119. * - peripheral should configure VBUS detection!
  120. * - only peripherals may use the internal D+/D- pulldowns
  121. * - OTG support on this port not yet written
  122. */
  123. USB_TRANSCEIVER_CTRL_REG &= ~(7 << 4);
  124. if (!is_device)
  125. USB_TRANSCEIVER_CTRL_REG |= (3 << 1);
  126. return 3 << 16;
  127. }
  128. /* alternate pin config, external transceiver */
  129. if (cpu_is_omap15xx()) {
  130. printk(KERN_ERR "no usb0 alt pin config on 15xx\n");
  131. return 0;
  132. }
  133. if (cpu_is_omap24xx()) {
  134. omap_cfg_reg(K18_24XX_USB0_DAT);
  135. omap_cfg_reg(K19_24XX_USB0_TXEN);
  136. omap_cfg_reg(J14_24XX_USB0_SE0);
  137. if (nwires != 3)
  138. omap_cfg_reg(J18_24XX_USB0_RCV);
  139. } else {
  140. omap_cfg_reg(V6_USB0_TXD);
  141. omap_cfg_reg(W9_USB0_TXEN);
  142. omap_cfg_reg(W5_USB0_SE0);
  143. if (nwires != 3)
  144. omap_cfg_reg(Y5_USB0_RCV);
  145. }
  146. /* NOTE: SPEED and SUSP aren't configured here. OTG hosts
  147. * may be able to use I2C requests to set those bits along
  148. * with VBUS switching and overcurrent detection.
  149. */
  150. if (cpu_class_is_omap1() && nwires != 6)
  151. USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
  152. switch (nwires) {
  153. case 3:
  154. syscon1 = 2;
  155. if (cpu_is_omap24xx())
  156. CONTROL_DEVCONF_REG |= USBT0WRMODEI(USB_BIDIR);
  157. break;
  158. case 4:
  159. syscon1 = 1;
  160. if (cpu_is_omap24xx())
  161. CONTROL_DEVCONF_REG |= USBT0WRMODEI(USB_BIDIR);
  162. break;
  163. case 6:
  164. syscon1 = 3;
  165. if (cpu_is_omap24xx()) {
  166. omap_cfg_reg(J19_24XX_USB0_VP);
  167. omap_cfg_reg(K20_24XX_USB0_VM);
  168. CONTROL_DEVCONF_REG |= USBT0WRMODEI(USB_UNIDIR);
  169. } else {
  170. omap_cfg_reg(AA9_USB0_VP);
  171. omap_cfg_reg(R9_USB0_VM);
  172. USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
  173. }
  174. break;
  175. default:
  176. printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
  177. 0, nwires);
  178. }
  179. return syscon1 << 16;
  180. }
  181. static u32 __init omap_usb1_init(unsigned nwires)
  182. {
  183. u32 syscon1 = 0;
  184. if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6)
  185. USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB1_UNI_R;
  186. if (cpu_is_omap24xx())
  187. CONTROL_DEVCONF_REG &= ~USBT1WRMODEI(USB_BIDIR_TLL);
  188. if (nwires == 0)
  189. return 0;
  190. /* external transceiver */
  191. if (cpu_class_is_omap1()) {
  192. omap_cfg_reg(USB1_TXD);
  193. omap_cfg_reg(USB1_TXEN);
  194. if (nwires != 3)
  195. omap_cfg_reg(USB1_RCV);
  196. }
  197. if (cpu_is_omap15xx()) {
  198. omap_cfg_reg(USB1_SEO);
  199. omap_cfg_reg(USB1_SPEED);
  200. // SUSP
  201. } else if (cpu_is_omap1610() || cpu_is_omap5912()) {
  202. omap_cfg_reg(W13_1610_USB1_SE0);
  203. omap_cfg_reg(R13_1610_USB1_SPEED);
  204. // SUSP
  205. } else if (cpu_is_omap1710()) {
  206. omap_cfg_reg(R13_1710_USB1_SE0);
  207. // SUSP
  208. } else if (cpu_is_omap24xx()) {
  209. /* NOTE: board-specific code must set up pin muxing for usb1,
  210. * since each signal could come out on either of two balls.
  211. */
  212. } else {
  213. pr_debug("usb%d cpu unrecognized\n", 1);
  214. return 0;
  215. }
  216. switch (nwires) {
  217. case 2:
  218. if (!cpu_is_omap24xx())
  219. goto bad;
  220. /* NOTE: board-specific code must override this setting if
  221. * this TLL link is not using DP/DM
  222. */
  223. syscon1 = 1;
  224. CONTROL_DEVCONF_REG |= USBT1WRMODEI(USB_BIDIR_TLL);
  225. break;
  226. case 3:
  227. syscon1 = 2;
  228. if (cpu_is_omap24xx())
  229. CONTROL_DEVCONF_REG |= USBT1WRMODEI(USB_BIDIR);
  230. break;
  231. case 4:
  232. syscon1 = 1;
  233. if (cpu_is_omap24xx())
  234. CONTROL_DEVCONF_REG |= USBT1WRMODEI(USB_BIDIR);
  235. break;
  236. case 6:
  237. if (cpu_is_omap24xx())
  238. goto bad;
  239. syscon1 = 3;
  240. omap_cfg_reg(USB1_VP);
  241. omap_cfg_reg(USB1_VM);
  242. if (!cpu_is_omap15xx())
  243. USB_TRANSCEIVER_CTRL_REG |= CONF_USB1_UNI_R;
  244. break;
  245. default:
  246. bad:
  247. printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
  248. 1, nwires);
  249. }
  250. return syscon1 << 20;
  251. }
  252. static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup)
  253. {
  254. u32 syscon1 = 0;
  255. if (cpu_is_omap24xx()) {
  256. CONTROL_DEVCONF_REG &= ~(USBT2WRMODEI(USB_BIDIR_TLL)
  257. | USBT2TLL5PI);
  258. alt_pingroup = 0;
  259. }
  260. /* NOTE omap1 erratum: must leave USB2_UNI_R set if usb0 in use */
  261. if (alt_pingroup || nwires == 0)
  262. return 0;
  263. if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6)
  264. USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
  265. /* external transceiver */
  266. if (cpu_is_omap15xx()) {
  267. omap_cfg_reg(USB2_TXD);
  268. omap_cfg_reg(USB2_TXEN);
  269. omap_cfg_reg(USB2_SEO);
  270. if (nwires != 3)
  271. omap_cfg_reg(USB2_RCV);
  272. /* there is no USB2_SPEED */
  273. } else if (cpu_is_omap16xx()) {
  274. omap_cfg_reg(V6_USB2_TXD);
  275. omap_cfg_reg(W9_USB2_TXEN);
  276. omap_cfg_reg(W5_USB2_SE0);
  277. if (nwires != 3)
  278. omap_cfg_reg(Y5_USB2_RCV);
  279. // FIXME omap_cfg_reg(USB2_SPEED);
  280. } else if (cpu_is_omap24xx()) {
  281. omap_cfg_reg(Y11_24XX_USB2_DAT);
  282. omap_cfg_reg(AA10_24XX_USB2_SE0);
  283. if (nwires > 2)
  284. omap_cfg_reg(AA12_24XX_USB2_TXEN);
  285. if (nwires > 3)
  286. omap_cfg_reg(AA6_24XX_USB2_RCV);
  287. } else {
  288. pr_debug("usb%d cpu unrecognized\n", 1);
  289. return 0;
  290. }
  291. // if (cpu_class_is_omap1()) omap_cfg_reg(USB2_SUSP);
  292. switch (nwires) {
  293. case 2:
  294. if (!cpu_is_omap24xx())
  295. goto bad;
  296. /* NOTE: board-specific code must override this setting if
  297. * this TLL link is not using DP/DM
  298. */
  299. syscon1 = 1;
  300. CONTROL_DEVCONF_REG |= USBT2WRMODEI(USB_BIDIR_TLL);
  301. break;
  302. case 3:
  303. syscon1 = 2;
  304. if (cpu_is_omap24xx())
  305. CONTROL_DEVCONF_REG |= USBT2WRMODEI(USB_BIDIR);
  306. break;
  307. case 4:
  308. syscon1 = 1;
  309. if (cpu_is_omap24xx())
  310. CONTROL_DEVCONF_REG |= USBT2WRMODEI(USB_BIDIR);
  311. break;
  312. case 5:
  313. if (!cpu_is_omap24xx())
  314. goto bad;
  315. omap_cfg_reg(AA4_24XX_USB2_TLLSE0);
  316. /* NOTE: board-specific code must override this setting if
  317. * this TLL link is not using DP/DM. Something must also
  318. * set up OTG_SYSCON2.HMC_TLL{ATTACH,SPEED}
  319. */
  320. syscon1 = 3;
  321. CONTROL_DEVCONF_REG |= USBT2WRMODEI(USB_UNIDIR_TLL)
  322. | USBT2TLL5PI;
  323. break;
  324. case 6:
  325. if (cpu_is_omap24xx())
  326. goto bad;
  327. syscon1 = 3;
  328. if (cpu_is_omap15xx()) {
  329. omap_cfg_reg(USB2_VP);
  330. omap_cfg_reg(USB2_VM);
  331. } else {
  332. omap_cfg_reg(AA9_USB2_VP);
  333. omap_cfg_reg(R9_USB2_VM);
  334. USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
  335. }
  336. break;
  337. default:
  338. bad:
  339. printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
  340. 2, nwires);
  341. }
  342. return syscon1 << 24;
  343. }
  344. #endif
  345. /*-------------------------------------------------------------------------*/
  346. #if defined(CONFIG_USB_GADGET_OMAP) || \
  347. defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) || \
  348. (defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG))
  349. static void usb_release(struct device *dev)
  350. {
  351. /* normally not freed */
  352. }
  353. #endif
  354. #ifdef CONFIG_USB_GADGET_OMAP
  355. static struct resource udc_resources[] = {
  356. /* order is significant! */
  357. { /* registers */
  358. .start = UDC_BASE,
  359. .end = UDC_BASE + 0xff,
  360. .flags = IORESOURCE_MEM,
  361. }, { /* general IRQ */
  362. .start = INT_USB_IRQ_GEN,
  363. .flags = IORESOURCE_IRQ,
  364. }, { /* PIO IRQ */
  365. .start = INT_USB_IRQ_NISO,
  366. .flags = IORESOURCE_IRQ,
  367. }, { /* SOF IRQ */
  368. .start = INT_USB_IRQ_ISO,
  369. .flags = IORESOURCE_IRQ,
  370. },
  371. };
  372. static u64 udc_dmamask = ~(u32)0;
  373. static struct platform_device udc_device = {
  374. .name = "omap_udc",
  375. .id = -1,
  376. .dev = {
  377. .release = usb_release,
  378. .dma_mask = &udc_dmamask,
  379. .coherent_dma_mask = 0xffffffff,
  380. },
  381. .num_resources = ARRAY_SIZE(udc_resources),
  382. .resource = udc_resources,
  383. };
  384. #endif
  385. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  386. /* The dmamask must be set for OHCI to work */
  387. static u64 ohci_dmamask = ~(u32)0;
  388. static struct resource ohci_resources[] = {
  389. {
  390. .start = OMAP_OHCI_BASE,
  391. .end = OMAP_OHCI_BASE + 0xff,
  392. .flags = IORESOURCE_MEM,
  393. },
  394. {
  395. .start = INT_USB_IRQ_HGEN,
  396. .flags = IORESOURCE_IRQ,
  397. },
  398. };
  399. static struct platform_device ohci_device = {
  400. .name = "ohci",
  401. .id = -1,
  402. .dev = {
  403. .release = usb_release,
  404. .dma_mask = &ohci_dmamask,
  405. .coherent_dma_mask = 0xffffffff,
  406. },
  407. .num_resources = ARRAY_SIZE(ohci_resources),
  408. .resource = ohci_resources,
  409. };
  410. #endif
  411. #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
  412. static struct resource otg_resources[] = {
  413. /* order is significant! */
  414. {
  415. .start = OTG_BASE,
  416. .end = OTG_BASE + 0xff,
  417. .flags = IORESOURCE_MEM,
  418. }, {
  419. .start = INT_USB_IRQ_OTG,
  420. .flags = IORESOURCE_IRQ,
  421. },
  422. };
  423. static struct platform_device otg_device = {
  424. .name = "omap_otg",
  425. .id = -1,
  426. .dev = {
  427. .release = usb_release,
  428. },
  429. .num_resources = ARRAY_SIZE(otg_resources),
  430. .resource = otg_resources,
  431. };
  432. #endif
  433. /*-------------------------------------------------------------------------*/
  434. #define ULPD_CLOCK_CTRL_REG __REG16(ULPD_CLOCK_CTRL)
  435. #define ULPD_SOFT_REQ_REG __REG16(ULPD_SOFT_REQ)
  436. // FIXME correct answer depends on hmc_mode,
  437. // as does (on omap1) any nonzero value for config->otg port number
  438. #ifdef CONFIG_USB_GADGET_OMAP
  439. #define is_usb0_device(config) 1
  440. #else
  441. #define is_usb0_device(config) 0
  442. #endif
  443. /*-------------------------------------------------------------------------*/
  444. #ifdef CONFIG_ARCH_OMAP_OTG
  445. void __init
  446. omap_otg_init(struct omap_usb_config *config)
  447. {
  448. u32 syscon = OTG_SYSCON_1_REG & 0xffff;
  449. int status;
  450. int alt_pingroup = 0;
  451. /* NOTE: no bus or clock setup (yet?) */
  452. syscon = OTG_SYSCON_1_REG & 0xffff;
  453. if (!(syscon & OTG_RESET_DONE))
  454. pr_debug("USB resets not complete?\n");
  455. // OTG_IRQ_EN_REG = 0;
  456. /* pin muxing and transceiver pinouts */
  457. if (config->pins[0] > 2) /* alt pingroup 2 */
  458. alt_pingroup = 1;
  459. syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));
  460. syscon |= omap_usb1_init(config->pins[1]);
  461. syscon |= omap_usb2_init(config->pins[2], alt_pingroup);
  462. pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
  463. OTG_SYSCON_1_REG = syscon;
  464. syscon = config->hmc_mode;
  465. syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
  466. #ifdef CONFIG_USB_OTG
  467. if (config->otg)
  468. syscon |= OTG_EN;
  469. #endif
  470. if (cpu_class_is_omap1())
  471. pr_debug("USB_TRANSCEIVER_CTRL_REG = %03x\n", USB_TRANSCEIVER_CTRL_REG);
  472. pr_debug("OTG_SYSCON_2_REG = %08x\n", syscon);
  473. OTG_SYSCON_2_REG = syscon;
  474. printk("USB: hmc %d", config->hmc_mode);
  475. if (!alt_pingroup)
  476. printk(", usb2 alt %d wires", config->pins[2]);
  477. else if (config->pins[0])
  478. printk(", usb0 %d wires%s", config->pins[0],
  479. is_usb0_device(config) ? " (dev)" : "");
  480. if (config->pins[1])
  481. printk(", usb1 %d wires", config->pins[1]);
  482. if (!alt_pingroup && config->pins[2])
  483. printk(", usb2 %d wires", config->pins[2]);
  484. if (config->otg)
  485. printk(", Mini-AB on usb%d", config->otg - 1);
  486. printk("\n");
  487. if (cpu_class_is_omap1()) {
  488. /* leave USB clocks/controllers off until needed */
  489. ULPD_SOFT_REQ_REG &= ~SOFT_USB_CLK_REQ;
  490. ULPD_CLOCK_CTRL_REG &= ~USB_MCLK_EN;
  491. ULPD_CLOCK_CTRL_REG |= DIS_USB_PVCI_CLK;
  492. }
  493. syscon = OTG_SYSCON_1_REG;
  494. syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
  495. #ifdef CONFIG_USB_GADGET_OMAP
  496. if (config->otg || config->register_dev) {
  497. syscon &= ~DEV_IDLE_EN;
  498. udc_device.dev.platform_data = config;
  499. /* FIXME patch IRQ numbers for omap730 */
  500. status = platform_device_register(&udc_device);
  501. if (status)
  502. pr_debug("can't register UDC device, %d\n", status);
  503. }
  504. #endif
  505. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  506. if (config->otg || config->register_host) {
  507. syscon &= ~HST_IDLE_EN;
  508. ohci_device.dev.platform_data = config;
  509. if (cpu_is_omap730())
  510. ohci_resources[1].start = INT_730_USB_HHC_1;
  511. status = platform_device_register(&ohci_device);
  512. if (status)
  513. pr_debug("can't register OHCI device, %d\n", status);
  514. }
  515. #endif
  516. #ifdef CONFIG_USB_OTG
  517. if (config->otg) {
  518. syscon &= ~OTG_IDLE_EN;
  519. otg_device.dev.platform_data = config;
  520. if (cpu_is_omap730())
  521. otg_resources[1].start = INT_730_USB_OTG;
  522. status = platform_device_register(&otg_device);
  523. if (status)
  524. pr_debug("can't register OTG device, %d\n", status);
  525. }
  526. #endif
  527. pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
  528. OTG_SYSCON_1_REG = syscon;
  529. status = 0;
  530. }
  531. #else
  532. static inline void omap_otg_init(struct omap_usb_config *config) {}
  533. #endif
  534. /*-------------------------------------------------------------------------*/
  535. #ifdef CONFIG_ARCH_OMAP15XX
  536. #define ULPD_DPLL_CTRL_REG __REG16(ULPD_DPLL_CTRL)
  537. #define DPLL_IOB (1 << 13)
  538. #define DPLL_PLL_ENABLE (1 << 4)
  539. #define DPLL_LOCK (1 << 0)
  540. #define ULPD_APLL_CTRL_REG __REG16(ULPD_APLL_CTRL)
  541. #define APLL_NDPLL_SWITCH (1 << 0)
  542. static void __init omap_1510_usb_init(struct omap_usb_config *config)
  543. {
  544. unsigned int val;
  545. omap_usb0_init(config->pins[0], is_usb0_device(config));
  546. omap_usb1_init(config->pins[1]);
  547. omap_usb2_init(config->pins[2], 0);
  548. val = omap_readl(MOD_CONF_CTRL_0) & ~(0x3f << 1);
  549. val |= (config->hmc_mode << 1);
  550. omap_writel(val, MOD_CONF_CTRL_0);
  551. printk("USB: hmc %d", config->hmc_mode);
  552. if (config->pins[0])
  553. printk(", usb0 %d wires%s", config->pins[0],
  554. is_usb0_device(config) ? " (dev)" : "");
  555. if (config->pins[1])
  556. printk(", usb1 %d wires", config->pins[1]);
  557. if (config->pins[2])
  558. printk(", usb2 %d wires", config->pins[2]);
  559. printk("\n");
  560. /* use DPLL for 48 MHz function clock */
  561. pr_debug("APLL %04x DPLL %04x REQ %04x\n", ULPD_APLL_CTRL_REG,
  562. ULPD_DPLL_CTRL_REG, ULPD_SOFT_REQ_REG);
  563. ULPD_APLL_CTRL_REG &= ~APLL_NDPLL_SWITCH;
  564. ULPD_DPLL_CTRL_REG |= DPLL_IOB | DPLL_PLL_ENABLE;
  565. ULPD_SOFT_REQ_REG |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
  566. while (!(ULPD_DPLL_CTRL_REG & DPLL_LOCK))
  567. cpu_relax();
  568. #ifdef CONFIG_USB_GADGET_OMAP
  569. if (config->register_dev) {
  570. int status;
  571. udc_device.dev.platform_data = config;
  572. status = platform_device_register(&udc_device);
  573. if (status)
  574. pr_debug("can't register UDC device, %d\n", status);
  575. /* udc driver gates 48MHz by D+ pullup */
  576. }
  577. #endif
  578. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  579. if (config->register_host) {
  580. int status;
  581. ohci_device.dev.platform_data = config;
  582. status = platform_device_register(&ohci_device);
  583. if (status)
  584. pr_debug("can't register OHCI device, %d\n", status);
  585. /* hcd explicitly gates 48MHz */
  586. }
  587. #endif
  588. }
  589. #else
  590. static inline void omap_1510_usb_init(struct omap_usb_config *config) {}
  591. #endif
  592. /*-------------------------------------------------------------------------*/
  593. static struct omap_usb_config platform_data;
  594. static int __init
  595. omap_usb_init(void)
  596. {
  597. const struct omap_usb_config *config;
  598. config = omap_get_config(OMAP_TAG_USB, struct omap_usb_config);
  599. if (config == NULL) {
  600. printk(KERN_ERR "USB: No board-specific "
  601. "platform config found\n");
  602. return -ENODEV;
  603. }
  604. platform_data = *config;
  605. if (cpu_is_omap730() || cpu_is_omap16xx() || cpu_is_omap24xx())
  606. omap_otg_init(&platform_data);
  607. else if (cpu_is_omap15xx())
  608. omap_1510_usb_init(&platform_data);
  609. else {
  610. printk(KERN_ERR "USB: No init for your chip yet\n");
  611. return -ENODEV;
  612. }
  613. return 0;
  614. }
  615. subsys_initcall(omap_usb_init);