usb-musb.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * linux/arch/arm/mach-omap2/usb-musb.c
  3. *
  4. * This file will contain the board specific details for the
  5. * MENTOR USB OTG controller on OMAP3430
  6. *
  7. * Copyright (C) 2007-2008 Texas Instruments
  8. * Copyright (C) 2008 Nokia Corporation
  9. * Author: Vikram Pandita
  10. *
  11. * Generalization by:
  12. * Felipe Balbi <felipe.balbi@nokia.com>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License version 2 as
  16. * published by the Free Software Foundation.
  17. */
  18. #include <linux/types.h>
  19. #include <linux/errno.h>
  20. #include <linux/delay.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/clk.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/io.h>
  25. #include <linux/usb/musb.h>
  26. #include <mach/hardware.h>
  27. #include <mach/irqs.h>
  28. #include <mach/mux.h>
  29. #include <mach/usb.h>
  30. #define OTG_SYSCONFIG (OMAP34XX_HSUSB_OTG_BASE + 0x404)
  31. static void __init usb_musb_pm_init(void)
  32. {
  33. /* Ensure force-idle mode for OTG controller */
  34. if (cpu_is_omap34xx())
  35. omap_writel(0, OTG_SYSCONFIG);
  36. }
  37. #ifdef CONFIG_USB_MUSB_SOC
  38. static struct resource musb_resources[] = {
  39. [0] = { /* start and end set dynamically */
  40. .flags = IORESOURCE_MEM,
  41. },
  42. [1] = { /* general IRQ */
  43. .start = INT_243X_HS_USB_MC,
  44. .flags = IORESOURCE_IRQ,
  45. },
  46. [2] = { /* DMA IRQ */
  47. .start = INT_243X_HS_USB_DMA,
  48. .flags = IORESOURCE_IRQ,
  49. },
  50. };
  51. static int clk_on;
  52. static int musb_set_clock(struct clk *clk, int state)
  53. {
  54. if (state) {
  55. if (clk_on > 0)
  56. return -ENODEV;
  57. clk_enable(clk);
  58. clk_on = 1;
  59. } else {
  60. if (clk_on == 0)
  61. return -ENODEV;
  62. clk_disable(clk);
  63. clk_on = 0;
  64. }
  65. return 0;
  66. }
  67. static struct musb_hdrc_eps_bits musb_eps[] = {
  68. { "ep1_tx", 10, },
  69. { "ep1_rx", 10, },
  70. { "ep2_tx", 9, },
  71. { "ep2_rx", 9, },
  72. { "ep3_tx", 3, },
  73. { "ep3_rx", 3, },
  74. { "ep4_tx", 3, },
  75. { "ep4_rx", 3, },
  76. { "ep5_tx", 3, },
  77. { "ep5_rx", 3, },
  78. { "ep6_tx", 3, },
  79. { "ep6_rx", 3, },
  80. { "ep7_tx", 3, },
  81. { "ep7_rx", 3, },
  82. { "ep8_tx", 2, },
  83. { "ep8_rx", 2, },
  84. { "ep9_tx", 2, },
  85. { "ep9_rx", 2, },
  86. { "ep10_tx", 2, },
  87. { "ep10_rx", 2, },
  88. { "ep11_tx", 2, },
  89. { "ep11_rx", 2, },
  90. { "ep12_tx", 2, },
  91. { "ep12_rx", 2, },
  92. { "ep13_tx", 2, },
  93. { "ep13_rx", 2, },
  94. { "ep14_tx", 2, },
  95. { "ep14_rx", 2, },
  96. { "ep15_tx", 2, },
  97. { "ep15_rx", 2, },
  98. };
  99. static struct musb_hdrc_config musb_config = {
  100. .multipoint = 1,
  101. .dyn_fifo = 1,
  102. .soft_con = 1,
  103. .dma = 1,
  104. .num_eps = 16,
  105. .dma_channels = 7,
  106. .dma_req_chan = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3),
  107. .ram_bits = 12,
  108. .eps_bits = musb_eps,
  109. };
  110. static struct musb_hdrc_platform_data musb_plat = {
  111. #ifdef CONFIG_USB_MUSB_OTG
  112. .mode = MUSB_OTG,
  113. #elif defined(CONFIG_USB_MUSB_HDRC_HCD)
  114. .mode = MUSB_HOST,
  115. #elif defined(CONFIG_USB_GADGET_MUSB_HDRC)
  116. .mode = MUSB_PERIPHERAL,
  117. #endif
  118. /* .clock is set dynamically */
  119. .set_clock = musb_set_clock,
  120. .config = &musb_config,
  121. /* REVISIT charge pump on TWL4030 can supply up to
  122. * 100 mA ... but this value is board-specific, like
  123. * "mode", and should be passed to usb_musb_init().
  124. */
  125. .power = 50, /* up to 100 mA */
  126. };
  127. static u64 musb_dmamask = DMA_BIT_MASK(32);
  128. static struct platform_device musb_device = {
  129. .name = "musb_hdrc",
  130. .id = -1,
  131. .dev = {
  132. .dma_mask = &musb_dmamask,
  133. .coherent_dma_mask = DMA_BIT_MASK(32),
  134. .platform_data = &musb_plat,
  135. },
  136. .num_resources = ARRAY_SIZE(musb_resources),
  137. .resource = musb_resources,
  138. };
  139. #ifdef CONFIG_NOP_USB_XCEIV
  140. static u64 nop_xceiv_dmamask = DMA_BIT_MASK(32);
  141. static struct platform_device nop_xceiv_device = {
  142. .name = "nop_usb_xceiv",
  143. .id = -1,
  144. .dev = {
  145. .dma_mask = &nop_xceiv_dmamask,
  146. .coherent_dma_mask = DMA_BIT_MASK(32),
  147. .platform_data = NULL,
  148. },
  149. };
  150. #endif
  151. void __init usb_musb_init(void)
  152. {
  153. if (cpu_is_omap243x())
  154. musb_resources[0].start = OMAP243X_HS_BASE;
  155. else
  156. musb_resources[0].start = OMAP34XX_HSUSB_OTG_BASE;
  157. musb_resources[0].end = musb_resources[0].start + SZ_8K - 1;
  158. /*
  159. * REVISIT: This line can be removed once all the platforms using
  160. * musb_core.c have been converted to use use clkdev.
  161. */
  162. musb_plat.clock = "ick";
  163. #ifdef CONFIG_NOP_USB_XCEIV
  164. if (platform_device_register(&nop_xceiv_device) < 0) {
  165. printk(KERN_ERR "Unable to register NOP-XCEIV device\n");
  166. return;
  167. }
  168. #endif
  169. if (platform_device_register(&musb_device) < 0) {
  170. printk(KERN_ERR "Unable to register HS-USB (MUSB) device\n");
  171. return;
  172. }
  173. usb_musb_pm_init();
  174. }
  175. #else
  176. void __init usb_musb_init(void)
  177. {
  178. usb_musb_pm_init();
  179. }
  180. #endif /* CONFIG_USB_MUSB_SOC */