msp_usb.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * The setup file for USB related hardware on PMC-Sierra MSP processors.
  3. *
  4. * Copyright 2006-2007 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. #include <linux/dma-mapping.h>
  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. #if defined(CONFIG_USB_EHCI_HCD)
  35. static struct resource msp_usbhost_resources [] = {
  36. [0] = {
  37. .start = MSP_USB_BASE_START,
  38. .end = MSP_USB_BASE_END,
  39. .flags = IORESOURCE_MEM,
  40. },
  41. [1] = {
  42. .start = MSP_INT_USB,
  43. .end = MSP_INT_USB,
  44. .flags = IORESOURCE_IRQ,
  45. },
  46. };
  47. static u64 msp_usbhost_dma_mask = DMA_32BIT_MASK;
  48. static struct platform_device msp_usbhost_device = {
  49. .name = "pmcmsp-ehci",
  50. .id = 0,
  51. .dev = {
  52. .dma_mask = &msp_usbhost_dma_mask,
  53. .coherent_dma_mask = DMA_32BIT_MASK,
  54. },
  55. .num_resources = ARRAY_SIZE(msp_usbhost_resources),
  56. .resource = msp_usbhost_resources,
  57. };
  58. #endif /* CONFIG_USB_EHCI_HCD */
  59. #if defined(CONFIG_USB_GADGET)
  60. static struct resource msp_usbdev_resources [] = {
  61. [0] = {
  62. .start = MSP_USB_BASE,
  63. .end = MSP_USB_BASE_END,
  64. .flags = IORESOURCE_MEM,
  65. },
  66. [1] = {
  67. .start = MSP_INT_USB,
  68. .end = MSP_INT_USB,
  69. .flags = IORESOURCE_IRQ,
  70. },
  71. };
  72. static u64 msp_usbdev_dma_mask = DMA_32BIT_MASK;
  73. static struct platform_device msp_usbdev_device = {
  74. .name = "msp71xx_udc",
  75. .id = 0,
  76. .dev = {
  77. .dma_mask = &msp_usbdev_dma_mask,
  78. .coherent_dma_mask = DMA_32BIT_MASK,
  79. },
  80. .num_resources = ARRAY_SIZE(msp_usbdev_resources),
  81. .resource = msp_usbdev_resources,
  82. };
  83. #endif /* CONFIG_USB_GADGET */
  84. #if defined(CONFIG_USB_EHCI_HCD) || defined(CONFIG_USB_GADGET)
  85. static struct platform_device *msp_devs[1];
  86. #endif
  87. static int __init msp_usb_setup(void)
  88. {
  89. #if defined(CONFIG_USB_EHCI_HCD) || defined(CONFIG_USB_GADGET)
  90. char *strp;
  91. char envstr[32];
  92. unsigned int val = 0;
  93. int result = 0;
  94. /*
  95. * construct environment name usbmode
  96. * set usbmode <host/device> as pmon environment var
  97. */
  98. snprintf((char *)&envstr[0], sizeof(envstr), "usbmode");
  99. #if defined(CONFIG_USB_EHCI_HCD)
  100. /* default to host mode */
  101. val = 1;
  102. #endif
  103. /* get environment string */
  104. strp = prom_getenv((char *)&envstr[0]);
  105. if (strp) {
  106. if (!strcmp(strp, "device"))
  107. val = 0;
  108. }
  109. if (val) {
  110. #if defined(CONFIG_USB_EHCI_HCD)
  111. /* get host mode device */
  112. msp_devs[0] = &msp_usbhost_device;
  113. ppfinit("platform add USB HOST done %s.\n",
  114. msp_devs[0]->name);
  115. result = platform_add_devices(msp_devs, ARRAY_SIZE(msp_devs));
  116. #endif /* CONFIG_USB_EHCI_HCD */
  117. }
  118. #if defined(CONFIG_USB_GADGET)
  119. else {
  120. /* get device mode structure */
  121. msp_devs[0] = &msp_usbdev_device;
  122. ppfinit("platform add USB DEVICE done %s.\n",
  123. msp_devs[0]->name);
  124. result = platform_add_devices(msp_devs, ARRAY_SIZE(msp_devs));
  125. }
  126. #endif /* CONFIG_USB_GADGET */
  127. #endif /* CONFIG_USB_EHCI_HCD || CONFIG_USB_GADGET */
  128. return result;
  129. }
  130. subsys_initcall(msp_usb_setup);