usb-fs.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*
  2. * Platform level USB initialization for FS USB OTG controller on omap1 and 24xx
  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. #include <linux/module.h>
  21. #include <linux/kernel.h>
  22. #include <linux/types.h>
  23. #include <linux/errno.h>
  24. #include <linux/init.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/clk.h>
  27. #include <linux/err.h>
  28. #include <asm/irq.h>
  29. #include <plat/control.h>
  30. #include <plat/usb.h>
  31. #include <plat/board.h>
  32. #define INT_USB_IRQ_GEN INT_24XX_USB_IRQ_GEN
  33. #define INT_USB_IRQ_NISO INT_24XX_USB_IRQ_NISO
  34. #define INT_USB_IRQ_ISO INT_24XX_USB_IRQ_ISO
  35. #define INT_USB_IRQ_HGEN INT_24XX_USB_IRQ_HGEN
  36. #define INT_USB_IRQ_OTG INT_24XX_USB_IRQ_OTG
  37. #include "mux.h"
  38. #if defined(CONFIG_ARCH_OMAP2)
  39. #ifdef CONFIG_USB_GADGET_OMAP
  40. static struct resource udc_resources[] = {
  41. /* order is significant! */
  42. { /* registers */
  43. .start = UDC_BASE,
  44. .end = UDC_BASE + 0xff,
  45. .flags = IORESOURCE_MEM,
  46. }, { /* general IRQ */
  47. .start = INT_USB_IRQ_GEN,
  48. .flags = IORESOURCE_IRQ,
  49. }, { /* PIO IRQ */
  50. .start = INT_USB_IRQ_NISO,
  51. .flags = IORESOURCE_IRQ,
  52. }, { /* SOF IRQ */
  53. .start = INT_USB_IRQ_ISO,
  54. .flags = IORESOURCE_IRQ,
  55. },
  56. };
  57. static u64 udc_dmamask = ~(u32)0;
  58. static struct platform_device udc_device = {
  59. .name = "omap_udc",
  60. .id = -1,
  61. .dev = {
  62. .dma_mask = &udc_dmamask,
  63. .coherent_dma_mask = 0xffffffff,
  64. },
  65. .num_resources = ARRAY_SIZE(udc_resources),
  66. .resource = udc_resources,
  67. };
  68. static inline void udc_device_init(struct omap_usb_config *pdata)
  69. {
  70. pdata->udc_device = &udc_device;
  71. }
  72. #else
  73. static inline void udc_device_init(struct omap_usb_config *pdata)
  74. {
  75. }
  76. #endif
  77. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  78. /* The dmamask must be set for OHCI to work */
  79. static u64 ohci_dmamask = ~(u32)0;
  80. static struct resource ohci_resources[] = {
  81. {
  82. .start = OMAP_OHCI_BASE,
  83. .end = OMAP_OHCI_BASE + 0xff,
  84. .flags = IORESOURCE_MEM,
  85. },
  86. {
  87. .start = INT_USB_IRQ_HGEN,
  88. .flags = IORESOURCE_IRQ,
  89. },
  90. };
  91. static struct platform_device ohci_device = {
  92. .name = "ohci",
  93. .id = -1,
  94. .dev = {
  95. .dma_mask = &ohci_dmamask,
  96. .coherent_dma_mask = 0xffffffff,
  97. },
  98. .num_resources = ARRAY_SIZE(ohci_resources),
  99. .resource = ohci_resources,
  100. };
  101. static inline void ohci_device_init(struct omap_usb_config *pdata)
  102. {
  103. pdata->ohci_device = &ohci_device;
  104. }
  105. #else
  106. static inline void ohci_device_init(struct omap_usb_config *pdata)
  107. {
  108. }
  109. #endif
  110. #if defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)
  111. static struct resource otg_resources[] = {
  112. /* order is significant! */
  113. {
  114. .start = OTG_BASE,
  115. .end = OTG_BASE + 0xff,
  116. .flags = IORESOURCE_MEM,
  117. }, {
  118. .start = INT_USB_IRQ_OTG,
  119. .flags = IORESOURCE_IRQ,
  120. },
  121. };
  122. static struct platform_device otg_device = {
  123. .name = "omap_otg",
  124. .id = -1,
  125. .num_resources = ARRAY_SIZE(otg_resources),
  126. .resource = otg_resources,
  127. };
  128. static inline void otg_device_init(struct omap_usb_config *pdata)
  129. {
  130. pdata->otg_device = &otg_device;
  131. }
  132. #else
  133. static inline void otg_device_init(struct omap_usb_config *pdata)
  134. {
  135. }
  136. #endif
  137. static void omap2_usb_devconf_clear(u8 port, u32 mask)
  138. {
  139. u32 r;
  140. r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
  141. r &= ~USBTXWRMODEI(port, mask);
  142. omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
  143. }
  144. static void omap2_usb_devconf_set(u8 port, u32 mask)
  145. {
  146. u32 r;
  147. r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
  148. r |= USBTXWRMODEI(port, mask);
  149. omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
  150. }
  151. static void omap2_usb2_disable_5pinbitll(void)
  152. {
  153. u32 r;
  154. r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
  155. r &= ~(USBTXWRMODEI(2, USB_BIDIR_TLL) | USBT2TLL5PI);
  156. omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
  157. }
  158. static void omap2_usb2_enable_5pinunitll(void)
  159. {
  160. u32 r;
  161. r = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
  162. r |= USBTXWRMODEI(2, USB_UNIDIR_TLL) | USBT2TLL5PI;
  163. omap_ctrl_writel(r, OMAP2_CONTROL_DEVCONF0);
  164. }
  165. static u32 __init omap2_usb0_init(unsigned nwires, unsigned is_device)
  166. {
  167. u32 syscon1 = 0;
  168. omap2_usb_devconf_clear(0, USB_BIDIR_TLL);
  169. if (nwires == 0)
  170. return 0;
  171. if (is_device)
  172. omap_mux_init_signal("usb0_puen", 0);
  173. omap_mux_init_signal("usb0_dat", 0);
  174. omap_mux_init_signal("usb0_txen", 0);
  175. omap_mux_init_signal("usb0_se0", 0);
  176. if (nwires != 3)
  177. omap_mux_init_signal("usb0_rcv", 0);
  178. switch (nwires) {
  179. case 3:
  180. syscon1 = 2;
  181. omap2_usb_devconf_set(0, USB_BIDIR);
  182. break;
  183. case 4:
  184. syscon1 = 1;
  185. omap2_usb_devconf_set(0, USB_BIDIR);
  186. break;
  187. case 6:
  188. syscon1 = 3;
  189. omap_mux_init_signal("usb0_vp", 0);
  190. omap_mux_init_signal("usb0_vm", 0);
  191. omap2_usb_devconf_set(0, USB_UNIDIR);
  192. break;
  193. default:
  194. printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
  195. 0, nwires);
  196. }
  197. return syscon1 << 16;
  198. }
  199. static u32 __init omap2_usb1_init(unsigned nwires)
  200. {
  201. u32 syscon1 = 0;
  202. omap2_usb_devconf_clear(1, USB_BIDIR_TLL);
  203. if (nwires == 0)
  204. return 0;
  205. /* NOTE: board-specific code must set up pin muxing for usb1,
  206. * since each signal could come out on either of two balls.
  207. */
  208. switch (nwires) {
  209. case 2:
  210. /* NOTE: board-specific code must override this setting if
  211. * this TLL link is not using DP/DM
  212. */
  213. syscon1 = 1;
  214. omap2_usb_devconf_set(1, USB_BIDIR_TLL);
  215. break;
  216. case 3:
  217. syscon1 = 2;
  218. omap2_usb_devconf_set(1, USB_BIDIR);
  219. break;
  220. case 4:
  221. syscon1 = 1;
  222. omap2_usb_devconf_set(1, USB_BIDIR);
  223. break;
  224. case 6:
  225. default:
  226. printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
  227. 1, nwires);
  228. }
  229. return syscon1 << 20;
  230. }
  231. static u32 __init omap2_usb2_init(unsigned nwires, unsigned alt_pingroup)
  232. {
  233. u32 syscon1 = 0;
  234. omap2_usb2_disable_5pinbitll();
  235. alt_pingroup = 0;
  236. /* NOTE omap1 erratum: must leave USB2_UNI_R set if usb0 in use */
  237. if (alt_pingroup || nwires == 0)
  238. return 0;
  239. omap_mux_init_signal("usb2_dat", 0);
  240. omap_mux_init_signal("usb2_se0", 0);
  241. if (nwires > 2)
  242. omap_mux_init_signal("usb2_txen", 0);
  243. if (nwires > 3)
  244. omap_mux_init_signal("usb2_rcv", 0);
  245. switch (nwires) {
  246. case 2:
  247. /* NOTE: board-specific code must override this setting if
  248. * this TLL link is not using DP/DM
  249. */
  250. syscon1 = 1;
  251. omap2_usb_devconf_set(2, USB_BIDIR_TLL);
  252. break;
  253. case 3:
  254. syscon1 = 2;
  255. omap2_usb_devconf_set(2, USB_BIDIR);
  256. break;
  257. case 4:
  258. syscon1 = 1;
  259. omap2_usb_devconf_set(2, USB_BIDIR);
  260. break;
  261. case 5:
  262. /* NOTE: board-specific code must mux this setting depending
  263. * on TLL link using DP/DM. Something must also
  264. * set up OTG_SYSCON2.HMC_TLL{ATTACH,SPEED}
  265. * 2420: hdq_sio.usb2_tllse0 or vlynq_rx0.usb2_tllse0
  266. * 2430: hdq_sio.usb2_tllse0 or sdmmc2_dat0.usb2_tllse0
  267. */
  268. syscon1 = 3;
  269. omap2_usb2_enable_5pinunitll();
  270. break;
  271. case 6:
  272. default:
  273. printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",
  274. 2, nwires);
  275. }
  276. return syscon1 << 24;
  277. }
  278. void __init omap2_usbfs_init(struct omap_usb_config *pdata)
  279. {
  280. struct clk *ick;
  281. if (!cpu_is_omap24xx())
  282. return;
  283. ick = clk_get(NULL, "usb_l4_ick");
  284. if (IS_ERR(ick))
  285. return;
  286. clk_enable(ick);
  287. pdata->usb0_init = omap2_usb0_init;
  288. pdata->usb1_init = omap2_usb1_init;
  289. pdata->usb2_init = omap2_usb2_init;
  290. udc_device_init(pdata);
  291. ohci_device_init(pdata);
  292. otg_device_init(pdata);
  293. omap_otg_init(pdata);
  294. clk_disable(ick);
  295. clk_put(ick);
  296. }
  297. #endif