usb.c 19 KB

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