usb.c 19 KB

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