usb.c 18 KB

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