pci.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 "core.h"
  52. #include "hcd.h"
  53. #define PCI_VENDOR_ID_SYNOPSYS 0x16c3
  54. #define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0
  55. static const char dwc2_driver_name[] = "dwc2";
  56. static const struct dwc2_core_params dwc2_module_params = {
  57. .otg_cap = -1,
  58. .otg_ver = -1,
  59. .dma_enable = -1,
  60. .dma_desc_enable = 0,
  61. .speed = -1,
  62. .enable_dynamic_fifo = -1,
  63. .en_multiple_tx_fifo = -1,
  64. .host_rx_fifo_size = 1024,
  65. .host_nperio_tx_fifo_size = 256,
  66. .host_perio_tx_fifo_size = 1024,
  67. .max_transfer_size = 65535,
  68. .max_packet_count = 511,
  69. .host_channels = -1,
  70. .phy_type = -1,
  71. .phy_utmi_width = -1,
  72. .phy_ulpi_ddr = -1,
  73. .phy_ulpi_ext_vbus = -1,
  74. .i2c_enable = -1,
  75. .ulpi_fs_ls = -1,
  76. .host_support_fs_ls_low_power = -1,
  77. .host_ls_low_power_phy_clk = -1,
  78. .ts_dline = -1,
  79. .reload_ctl = -1,
  80. .ahbcfg = -1,
  81. .uframe_sched = -1,
  82. };
  83. /**
  84. * dwc2_driver_remove() - Called when the DWC_otg core is unregistered with the
  85. * DWC_otg driver
  86. *
  87. * @dev: Bus device
  88. *
  89. * This routine is called, for example, when the rmmod command is executed. The
  90. * device may or may not be electrically present. If it is present, the driver
  91. * stops device processing. Any resources used on behalf of this device are
  92. * freed.
  93. */
  94. static void dwc2_driver_remove(struct pci_dev *dev)
  95. {
  96. struct dwc2_hsotg *hsotg = pci_get_drvdata(dev);
  97. dwc2_hcd_remove(hsotg);
  98. pci_disable_device(dev);
  99. }
  100. /**
  101. * dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg
  102. * driver
  103. *
  104. * @dev: Bus device
  105. *
  106. * This routine creates the driver components required to control the device
  107. * (core, HCD, and PCD) and initializes the device. The driver components are
  108. * stored in a dwc2_hsotg structure. A reference to the dwc2_hsotg is saved
  109. * in the device private data. This allows the driver to access the dwc2_hsotg
  110. * structure on subsequent calls to driver methods for this device.
  111. */
  112. static int dwc2_driver_probe(struct pci_dev *dev,
  113. const struct pci_device_id *id)
  114. {
  115. struct dwc2_hsotg *hsotg;
  116. int retval;
  117. hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL);
  118. if (!hsotg)
  119. return -ENOMEM;
  120. hsotg->dev = &dev->dev;
  121. hsotg->regs = devm_ioremap_resource(&dev->dev, &dev->resource[0]);
  122. if (IS_ERR(hsotg->regs))
  123. return PTR_ERR(hsotg->regs);
  124. dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n",
  125. (unsigned long)pci_resource_start(dev, 0), hsotg->regs);
  126. if (pci_enable_device(dev) < 0)
  127. return -ENODEV;
  128. pci_set_master(dev);
  129. retval = devm_request_irq(hsotg->dev, dev->irq,
  130. dwc2_handle_common_intr, IRQF_SHARED,
  131. dev_name(hsotg->dev), hsotg);
  132. if (retval)
  133. return retval;
  134. spin_lock_init(&hsotg->lock);
  135. retval = dwc2_hcd_init(hsotg, dev->irq, &dwc2_module_params);
  136. if (retval) {
  137. pci_disable_device(dev);
  138. return retval;
  139. }
  140. pci_set_drvdata(dev, hsotg);
  141. return retval;
  142. }
  143. static const struct pci_device_id dwc2_pci_ids[] = {
  144. {
  145. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG),
  146. },
  147. {
  148. PCI_DEVICE(PCI_VENDOR_ID_STMICRO,
  149. PCI_DEVICE_ID_STMICRO_USB_OTG),
  150. },
  151. { /* end: all zeroes */ }
  152. };
  153. MODULE_DEVICE_TABLE(pci, dwc2_pci_ids);
  154. static struct pci_driver dwc2_pci_driver = {
  155. .name = dwc2_driver_name,
  156. .id_table = dwc2_pci_ids,
  157. .probe = dwc2_driver_probe,
  158. .remove = dwc2_driver_remove,
  159. };
  160. module_pci_driver(dwc2_pci_driver);
  161. MODULE_DESCRIPTION("DESIGNWARE HS OTG PCI Bus Glue");
  162. MODULE_AUTHOR("Synopsys, Inc.");
  163. MODULE_LICENSE("Dual BSD/GPL");