msp_usb.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. #endif /* CONFIG_USB_EHCI_HCD */
  72. #if defined(CONFIG_USB_GADGET)
  73. static struct resource msp_usbdev0_resources[] = {
  74. [0] = { /* EHCI-HS operational and capabilities registers */
  75. .start = MSP_USB0_HS_START,
  76. .end = MSP_USB0_HS_END,
  77. .flags = IORESOURCE_MEM,
  78. },
  79. [1] = {
  80. .start = MSP_INT_USB,
  81. .end = MSP_INT_USB,
  82. .flags = IORESOURCE_IRQ,
  83. },
  84. [2] = { /* MSBus-to-AMBA bridge register space */
  85. .start = MSP_USB0_MAB_START,
  86. .end = MSP_USB0_MAB_END,
  87. .flags = IORESOURCE_MEM,
  88. },
  89. [3] = { /* Identification and general hardware parameters */
  90. .start = MSP_USB0_ID_START,
  91. .end = MSP_USB0_ID_END,
  92. .flags = IORESOURCE_MEM,
  93. },
  94. };
  95. static u64 msp_usbdev_dma_mask = 0xffffffffUL;
  96. /* This may need to be converted to a mspusb_device, too. */
  97. static struct mspusb_device msp_usbdev0_device = {
  98. .dev = {
  99. .name = "msp71xx_udc",
  100. .id = 0,
  101. .dev = {
  102. .dma_mask = &msp_usbdev_dma_mask,
  103. .coherent_dma_mask = 0xffffffffUL,
  104. },
  105. .num_resources = ARRAY_SIZE(msp_usbdev0_resources),
  106. .resource = msp_usbdev0_resources,
  107. },
  108. };
  109. #endif /* CONFIG_USB_GADGET */
  110. static int __init msp_usb_setup(void)
  111. {
  112. char *strp;
  113. char envstr[32];
  114. struct platform_device *msp_devs[NUM_USB_DEVS];
  115. unsigned int val;
  116. /* construct environment name usbmode */
  117. /* set usbmode <host/device> as pmon environment var */
  118. /*
  119. * Could this perhaps be integrated into the "features" env var?
  120. * Use the features key "U", and follow with "H" for host-mode,
  121. * "D" for device-mode. If it works for Ethernet, why not USB...
  122. * -- hammtrev, 2007/03/22
  123. */
  124. snprintf((char *)&envstr[0], sizeof(envstr), "usbmode");
  125. /* set default host mode */
  126. val = 1;
  127. /* get environment string */
  128. strp = prom_getenv((char *)&envstr[0]);
  129. if (strp) {
  130. /* compare string */
  131. if (!strcmp(strp, "device"))
  132. val = 0;
  133. }
  134. if (val) {
  135. #if defined(CONFIG_USB_EHCI_HCD)
  136. msp_devs[0] = &msp_usbhost0_device.dev;
  137. ppfinit("platform add USB HOST done %s.\n", msp_devs[0]->name);
  138. #else
  139. ppfinit("%s: echi_hcd not supported\n", __FILE__);
  140. #endif /* CONFIG_USB_EHCI_HCD */
  141. } else {
  142. #if defined(CONFIG_USB_GADGET)
  143. /* get device mode structure */
  144. msp_devs[0] = &msp_usbdev0_device.dev;
  145. ppfinit("platform add USB DEVICE done %s.\n"
  146. , msp_devs[0]->name);
  147. #else
  148. ppfinit("%s: usb_gadget not supported\n", __FILE__);
  149. #endif /* CONFIG_USB_GADGET */
  150. }
  151. /* add device */
  152. platform_add_devices(msp_devs, ARRAY_SIZE(msp_devs));
  153. return 0;
  154. }
  155. subsys_initcall(msp_usb_setup);
  156. #endif /* CONFIG_USB_EHCI_HCD || CONFIG_USB_GADGET */