usb.c 18 KB

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