pci.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * pci.c - DesignWare HS OTG Controller PCI driver
  3. *
  4. * Copyright (C) 2004-2013 Synopsys, Inc.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions, and the following disclaimer,
  11. * without modification.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. The names of the above-listed copyright holders may not be used
  16. * to endorse or promote products derived from this software without
  17. * specific prior written permission.
  18. *
  19. * ALTERNATIVELY, this software may be distributed under the terms of the
  20. * GNU General Public License ("GPL") as published by the Free Software
  21. * Foundation; either version 2 of the License, or (at your option) any
  22. * later version.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  25. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  26. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  31. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  32. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. /*
  37. * Provides the initialization and cleanup entry points for the DWC_otg PCI
  38. * driver
  39. */
  40. #include <linux/kernel.h>
  41. #include <linux/module.h>
  42. #include <linux/moduleparam.h>
  43. #include <linux/spinlock.h>
  44. #include <linux/interrupt.h>
  45. #include <linux/io.h>
  46. #include <linux/slab.h>
  47. #include <linux/pci.h>
  48. #include <linux/usb.h>
  49. #include <linux/usb/hcd.h>
  50. #include <linux/usb/ch11.h>
  51. #include <linux/platform_device.h>
  52. #include <linux/usb/usb_phy_generic.h>
  53. #define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0
  54. static const char dwc2_driver_name[] = "dwc2-pci";
  55. struct dwc2_pci_glue {
  56. struct platform_device *dwc2;
  57. struct platform_device *phy;
  58. };
  59. static int dwc2_pci_quirks(struct pci_dev *pdev, struct platform_device *dwc2)
  60. {
  61. if (pdev->vendor == PCI_VENDOR_ID_SYNOPSYS &&
  62. pdev->device == PCI_PRODUCT_ID_HAPS_HSOTG) {
  63. struct property_entry properties[] = {
  64. { },
  65. };
  66. return platform_device_add_properties(dwc2, properties);
  67. }
  68. return 0;
  69. }
  70. static void dwc2_pci_remove(struct pci_dev *pci)
  71. {
  72. struct dwc2_pci_glue *glue = pci_get_drvdata(pci);
  73. platform_device_unregister(glue->dwc2);
  74. usb_phy_generic_unregister(glue->phy);
  75. kfree(glue);
  76. pci_set_drvdata(pci, NULL);
  77. }
  78. static int dwc2_pci_probe(struct pci_dev *pci,
  79. const struct pci_device_id *id)
  80. {
  81. struct resource res[2];
  82. struct platform_device *dwc2;
  83. struct platform_device *phy;
  84. int ret;
  85. struct device *dev = &pci->dev;
  86. struct dwc2_pci_glue *glue;
  87. ret = pcim_enable_device(pci);
  88. if (ret) {
  89. dev_err(dev, "failed to enable pci device\n");
  90. return -ENODEV;
  91. }
  92. pci_set_master(pci);
  93. dwc2 = platform_device_alloc("dwc2", PLATFORM_DEVID_AUTO);
  94. if (!dwc2) {
  95. dev_err(dev, "couldn't allocate dwc2 device\n");
  96. return -ENOMEM;
  97. }
  98. memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
  99. res[0].start = pci_resource_start(pci, 0);
  100. res[0].end = pci_resource_end(pci, 0);
  101. res[0].name = "dwc2";
  102. res[0].flags = IORESOURCE_MEM;
  103. res[1].start = pci->irq;
  104. res[1].name = "dwc2";
  105. res[1].flags = IORESOURCE_IRQ;
  106. ret = platform_device_add_resources(dwc2, res, ARRAY_SIZE(res));
  107. if (ret) {
  108. dev_err(dev, "couldn't add resources to dwc2 device\n");
  109. return ret;
  110. }
  111. dwc2->dev.parent = dev;
  112. phy = usb_phy_generic_register();
  113. if (IS_ERR(phy)) {
  114. dev_err(dev, "error registering generic PHY (%ld)\n",
  115. PTR_ERR(phy));
  116. return PTR_ERR(phy);
  117. }
  118. ret = dwc2_pci_quirks(pci, dwc2);
  119. if (ret)
  120. goto err;
  121. ret = platform_device_add(dwc2);
  122. if (ret) {
  123. dev_err(dev, "failed to register dwc2 device\n");
  124. goto err;
  125. }
  126. glue = kzalloc(sizeof(*glue), GFP_KERNEL);
  127. if (!glue)
  128. return -ENOMEM;
  129. glue->phy = phy;
  130. glue->dwc2 = dwc2;
  131. pci_set_drvdata(pci, glue);
  132. return 0;
  133. err:
  134. usb_phy_generic_unregister(phy);
  135. platform_device_put(dwc2);
  136. return ret;
  137. }
  138. static const struct pci_device_id dwc2_pci_ids[] = {
  139. {
  140. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG),
  141. },
  142. {
  143. PCI_DEVICE(PCI_VENDOR_ID_STMICRO,
  144. PCI_DEVICE_ID_STMICRO_USB_OTG),
  145. },
  146. { /* end: all zeroes */ }
  147. };
  148. MODULE_DEVICE_TABLE(pci, dwc2_pci_ids);
  149. static struct pci_driver dwc2_pci_driver = {
  150. .name = dwc2_driver_name,
  151. .id_table = dwc2_pci_ids,
  152. .probe = dwc2_pci_probe,
  153. .remove = dwc2_pci_remove,
  154. };
  155. module_pci_driver(dwc2_pci_driver);
  156. MODULE_DESCRIPTION("DESIGNWARE HS OTG PCI Bus Glue");
  157. MODULE_AUTHOR("Synopsys, Inc.");
  158. MODULE_LICENSE("Dual BSD/GPL");