msp_usb.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * The setup file for USB related hardware on PMC-Sierra MSP processors.
  3. *
  4. * Copyright 2006 PMC-Sierra, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  12. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  14. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  15. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  16. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  17. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  18. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  19. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  20. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. *
  22. * You should have received a copy of the GNU General Public License along
  23. * with this program; if not, write to the Free Software Foundation, Inc.,
  24. * 675 Mass Ave, Cambridge, MA 02139, USA.
  25. */
  26. #if defined(CONFIG_USB_EHCI_HCD) || defined(CONFIG_USB_GADGET)
  27. #include <linux/init.h>
  28. #include <linux/ioport.h>
  29. #include <linux/platform_device.h>
  30. #include <asm/mipsregs.h>
  31. #include <msp_regs.h>
  32. #include <msp_int.h>
  33. #include <msp_prom.h>
  34. #include <msp_usb.h>
  35. #if defined(CONFIG_USB_EHCI_HCD)
  36. static struct resource msp_usbhost0_resources[] = {
  37. [0] = { /* EHCI-HS operational and capabilities registers */
  38. .start = MSP_USB0_HS_START,
  39. .end = MSP_USB0_HS_END,
  40. .flags = IORESOURCE_MEM,
  41. },
  42. [1] = {
  43. .start = MSP_INT_USB,
  44. .end = MSP_INT_USB,
  45. .flags = IORESOURCE_IRQ,
  46. },
  47. [2] = { /* MSBus-to-AMBA bridge register space */
  48. .start = MSP_USB0_MAB_START,
  49. .end = MSP_USB0_MAB_END,
  50. .flags = IORESOURCE_MEM,
  51. },
  52. [3] = { /* Identification and general hardware parameters */
  53. .start = MSP_USB0_ID_START,
  54. .end = MSP_USB0_ID_END,
  55. .flags = IORESOURCE_MEM,
  56. },
  57. };
  58. static u64 msp_usbhost0_dma_mask = 0xffffffffUL;
  59. static struct mspusb_device msp_usbhost0_device = {
  60. .dev = {
  61. .name = "pmcmsp-ehci",
  62. .id = 0,
  63. .dev = {
  64. .dma_mask = &msp_usbhost0_dma_mask,
  65. .coherent_dma_mask = 0xffffffffUL,
  66. },
  67. .num_resources = ARRAY_SIZE(msp_usbhost0_resources),
  68. .resource = msp_usbhost0_resources,
  69. },
  70. };
  71. /* MSP7140/MSP82XX has two USB2 hosts. */
  72. #ifdef CONFIG_MSP_HAS_DUAL_USB
  73. static u64 msp_usbhost1_dma_mask = 0xffffffffUL;
  74. static struct resource msp_usbhost1_resources[] = {
  75. [0] = { /* EHCI-HS operational and capabilities registers */
  76. .start = MSP_USB1_HS_START,
  77. .end = MSP_USB1_HS_END,
  78. .flags = IORESOURCE_MEM,
  79. },
  80. [1] = {
  81. .start = MSP_INT_USB,
  82. .end = MSP_INT_USB,
  83. .flags = IORESOURCE_IRQ,
  84. },
  85. [2] = { /* MSBus-to-AMBA bridge register space */
  86. .start = MSP_USB1_MAB_START,
  87. .end = MSP_USB1_MAB_END,
  88. .flags = IORESOURCE_MEM,
  89. },
  90. [3] = { /* Identification and general hardware parameters */
  91. .start = MSP_USB1_ID_START,
  92. .end = MSP_USB1_ID_END,
  93. .flags = IORESOURCE_MEM,
  94. },
  95. };
  96. static struct mspusb_device msp_usbhost1_device = {
  97. .dev = {
  98. .name = "pmcmsp-ehci",
  99. .id = 1,
  100. .dev = {
  101. .dma_mask = &msp_usbhost1_dma_mask,
  102. .coherent_dma_mask = 0xffffffffUL,
  103. },
  104. .num_resources = ARRAY_SIZE(msp_usbhost1_resources),
  105. .resource = msp_usbhost1_resources,
  106. },
  107. };
  108. #endif /* CONFIG_MSP_HAS_DUAL_USB */
  109. #endif /* CONFIG_USB_EHCI_HCD */
  110. #if defined(CONFIG_USB_GADGET)
  111. static struct resource msp_usbdev0_resources[] = {
  112. [0] = { /* EHCI-HS operational and capabilities registers */
  113. .start = MSP_USB0_HS_START,
  114. .end = MSP_USB0_HS_END,
  115. .flags = IORESOURCE_MEM,
  116. },
  117. [1] = {
  118. .start = MSP_INT_USB,
  119. .end = MSP_INT_USB,
  120. .flags = IORESOURCE_IRQ,
  121. },
  122. [2] = { /* MSBus-to-AMBA bridge register space */
  123. .start = MSP_USB0_MAB_START,
  124. .end = MSP_USB0_MAB_END,
  125. .flags = IORESOURCE_MEM,
  126. },
  127. [3] = { /* Identification and general hardware parameters */
  128. .start = MSP_USB0_ID_START,
  129. .end = MSP_USB0_ID_END,
  130. .flags = IORESOURCE_MEM,
  131. },
  132. };
  133. static u64 msp_usbdev_dma_mask = 0xffffffffUL;
  134. /* This may need to be converted to a mspusb_device, too. */
  135. static struct mspusb_device msp_usbdev0_device = {
  136. .dev = {
  137. .name = "msp71xx_udc",
  138. .id = 0,
  139. .dev = {
  140. .dma_mask = &msp_usbdev_dma_mask,
  141. .coherent_dma_mask = 0xffffffffUL,
  142. },
  143. .num_resources = ARRAY_SIZE(msp_usbdev0_resources),
  144. .resource = msp_usbdev0_resources,
  145. },
  146. };
  147. #ifdef CONFIG_MSP_HAS_DUAL_USB
  148. static struct resource msp_usbdev1_resources[] = {
  149. [0] = { /* EHCI-HS operational and capabilities registers */
  150. .start = MSP_USB1_HS_START,
  151. .end = MSP_USB1_HS_END,
  152. .flags = IORESOURCE_MEM,
  153. },
  154. [1] = {
  155. .start = MSP_INT_USB,
  156. .end = MSP_INT_USB,
  157. .flags = IORESOURCE_IRQ,
  158. },
  159. [2] = { /* MSBus-to-AMBA bridge register space */
  160. .start = MSP_USB1_MAB_START,
  161. .end = MSP_USB1_MAB_END,
  162. .flags = IORESOURCE_MEM,
  163. },
  164. [3] = { /* Identification and general hardware parameters */
  165. .start = MSP_USB1_ID_START,
  166. .end = MSP_USB1_ID_END,
  167. .flags = IORESOURCE_MEM,
  168. },
  169. };
  170. /* This may need to be converted to a mspusb_device, too. */
  171. static struct mspusb_device msp_usbdev1_device = {
  172. .dev = {
  173. .name = "msp71xx_udc",
  174. .id = 0,
  175. .dev = {
  176. .dma_mask = &msp_usbdev_dma_mask,
  177. .coherent_dma_mask = 0xffffffffUL,
  178. },
  179. .num_resources = ARRAY_SIZE(msp_usbdev1_resources),
  180. .resource = msp_usbdev1_resources,
  181. },
  182. };
  183. #endif /* CONFIG_MSP_HAS_DUAL_USB */
  184. #endif /* CONFIG_USB_GADGET */
  185. static int __init msp_usb_setup(void)
  186. {
  187. char *strp;
  188. char envstr[32];
  189. struct platform_device *msp_devs[NUM_USB_DEVS];
  190. unsigned int val;
  191. /* construct environment name usbmode */
  192. /* set usbmode <host/device> as pmon environment var */
  193. /*
  194. * Could this perhaps be integrated into the "features" env var?
  195. * Use the features key "U", and follow with "H" for host-mode,
  196. * "D" for device-mode. If it works for Ethernet, why not USB...
  197. * -- hammtrev, 2007/03/22
  198. */
  199. snprintf((char *)&envstr[0], sizeof(envstr), "usbmode");
  200. /* set default host mode */
  201. val = 1;
  202. /* get environment string */
  203. strp = prom_getenv((char *)&envstr[0]);
  204. if (strp) {
  205. /* compare string */
  206. if (!strcmp(strp, "device"))
  207. val = 0;
  208. }
  209. if (val) {
  210. #if defined(CONFIG_USB_EHCI_HCD)
  211. msp_devs[0] = &msp_usbhost0_device.dev;
  212. ppfinit("platform add USB HOST done %s.\n", msp_devs[0]->name);
  213. #ifdef CONFIG_MSP_HAS_DUAL_USB
  214. msp_devs[1] = &msp_usbhost1_device.dev;
  215. ppfinit("platform add USB HOST done %s.\n", msp_devs[1]->name);
  216. #endif
  217. #else
  218. ppfinit("%s: echi_hcd not supported\n", __FILE__);
  219. #endif /* CONFIG_USB_EHCI_HCD */
  220. } else {
  221. #if defined(CONFIG_USB_GADGET)
  222. /* get device mode structure */
  223. msp_devs[0] = &msp_usbdev0_device.dev;
  224. ppfinit("platform add USB DEVICE done %s.\n"
  225. , msp_devs[0]->name);
  226. #ifdef CONFIG_MSP_HAS_DUAL_USB
  227. msp_devs[1] = &msp_usbdev1_device.dev;
  228. ppfinit("platform add USB DEVICE done %s.\n"
  229. , msp_devs[1]->name);
  230. #endif
  231. #else
  232. ppfinit("%s: usb_gadget not supported\n", __FILE__);
  233. #endif /* CONFIG_USB_GADGET */
  234. }
  235. /* add device */
  236. platform_add_devices(msp_devs, ARRAY_SIZE(msp_devs));
  237. return 0;
  238. }
  239. subsys_initcall(msp_usb_setup);
  240. #endif /* CONFIG_USB_EHCI_HCD || CONFIG_USB_GADGET */