dwc3-pci.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /**
  2. * dwc3-pci.c - PCI Specific glue layer
  3. *
  4. * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
  5. *
  6. * Authors: Felipe Balbi <balbi@ti.com>,
  7. * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 of
  11. * the License as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/slab.h>
  21. #include <linux/pci.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/gpio/consumer.h>
  24. #include <linux/acpi.h>
  25. #include "platform_data.h"
  26. #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd
  27. #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI 0xabce
  28. #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31 0xabcf
  29. #define PCI_DEVICE_ID_INTEL_BYT 0x0f37
  30. #define PCI_DEVICE_ID_INTEL_MRFLD 0x119e
  31. #define PCI_DEVICE_ID_INTEL_BSW 0x22b7
  32. #define PCI_DEVICE_ID_INTEL_SPTLP 0x9d30
  33. #define PCI_DEVICE_ID_INTEL_SPTH 0xa130
  34. #define PCI_DEVICE_ID_INTEL_BXT 0x0aaa
  35. #define PCI_DEVICE_ID_INTEL_BXT_M 0x1aaa
  36. #define PCI_DEVICE_ID_INTEL_APL 0x5aaa
  37. static const struct acpi_gpio_params reset_gpios = { 0, 0, false };
  38. static const struct acpi_gpio_params cs_gpios = { 1, 0, false };
  39. static const struct acpi_gpio_mapping acpi_dwc3_byt_gpios[] = {
  40. { "reset-gpios", &reset_gpios, 1 },
  41. { "cs-gpios", &cs_gpios, 1 },
  42. { },
  43. };
  44. static int dwc3_pci_quirks(struct pci_dev *pdev)
  45. {
  46. if (pdev->vendor == PCI_VENDOR_ID_AMD &&
  47. pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
  48. struct dwc3_platform_data pdata;
  49. memset(&pdata, 0, sizeof(pdata));
  50. pdata.has_lpm_erratum = true;
  51. pdata.lpm_nyet_threshold = 0xf;
  52. pdata.u2exit_lfps_quirk = true;
  53. pdata.u2ss_inp3_quirk = true;
  54. pdata.req_p1p2p3_quirk = true;
  55. pdata.del_p1p2p3_quirk = true;
  56. pdata.del_phy_power_chg_quirk = true;
  57. pdata.lfps_filter_quirk = true;
  58. pdata.rx_detect_poll_quirk = true;
  59. pdata.tx_de_emphasis_quirk = true;
  60. pdata.tx_de_emphasis = 1;
  61. /*
  62. * FIXME these quirks should be removed when AMD NL
  63. * taps out
  64. */
  65. pdata.disable_scramble_quirk = true;
  66. pdata.dis_u3_susphy_quirk = true;
  67. pdata.dis_u2_susphy_quirk = true;
  68. return platform_device_add_data(pci_get_drvdata(pdev), &pdata,
  69. sizeof(pdata));
  70. }
  71. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  72. pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
  73. struct gpio_desc *gpio;
  74. acpi_dev_add_driver_gpios(ACPI_COMPANION(&pdev->dev),
  75. acpi_dwc3_byt_gpios);
  76. /*
  77. * These GPIOs will turn on the USB2 PHY. Note that we have to
  78. * put the gpio descriptors again here because the phy driver
  79. * might want to grab them, too.
  80. */
  81. gpio = gpiod_get_optional(&pdev->dev, "cs", GPIOD_OUT_LOW);
  82. if (IS_ERR(gpio))
  83. return PTR_ERR(gpio);
  84. gpiod_set_value_cansleep(gpio, 1);
  85. gpiod_put(gpio);
  86. gpio = gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW);
  87. if (IS_ERR(gpio))
  88. return PTR_ERR(gpio);
  89. if (gpio) {
  90. gpiod_set_value_cansleep(gpio, 1);
  91. gpiod_put(gpio);
  92. usleep_range(10000, 11000);
  93. }
  94. }
  95. if (pdev->vendor == PCI_VENDOR_ID_SYNOPSYS &&
  96. (pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 ||
  97. pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI ||
  98. pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31)) {
  99. struct dwc3_platform_data pdata;
  100. memset(&pdata, 0, sizeof(pdata));
  101. pdata.usb3_lpm_capable = true;
  102. pdata.has_lpm_erratum = true;
  103. pdata.dis_enblslpm_quirk = true;
  104. return platform_device_add_data(pci_get_drvdata(pdev), &pdata,
  105. sizeof(pdata));
  106. }
  107. return 0;
  108. }
  109. static int dwc3_pci_probe(struct pci_dev *pci,
  110. const struct pci_device_id *id)
  111. {
  112. struct resource res[2];
  113. struct platform_device *dwc3;
  114. int ret;
  115. struct device *dev = &pci->dev;
  116. ret = pcim_enable_device(pci);
  117. if (ret) {
  118. dev_err(dev, "failed to enable pci device\n");
  119. return -ENODEV;
  120. }
  121. pci_set_master(pci);
  122. dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
  123. if (!dwc3) {
  124. dev_err(dev, "couldn't allocate dwc3 device\n");
  125. return -ENOMEM;
  126. }
  127. memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
  128. res[0].start = pci_resource_start(pci, 0);
  129. res[0].end = pci_resource_end(pci, 0);
  130. res[0].name = "dwc_usb3";
  131. res[0].flags = IORESOURCE_MEM;
  132. res[1].start = pci->irq;
  133. res[1].name = "dwc_usb3";
  134. res[1].flags = IORESOURCE_IRQ;
  135. ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res));
  136. if (ret) {
  137. dev_err(dev, "couldn't add resources to dwc3 device\n");
  138. return ret;
  139. }
  140. pci_set_drvdata(pci, dwc3);
  141. ret = dwc3_pci_quirks(pci);
  142. if (ret)
  143. goto err;
  144. dwc3->dev.parent = dev;
  145. ACPI_COMPANION_SET(&dwc3->dev, ACPI_COMPANION(dev));
  146. ret = platform_device_add(dwc3);
  147. if (ret) {
  148. dev_err(dev, "failed to register dwc3 device\n");
  149. goto err;
  150. }
  151. return 0;
  152. err:
  153. platform_device_put(dwc3);
  154. return ret;
  155. }
  156. static void dwc3_pci_remove(struct pci_dev *pci)
  157. {
  158. acpi_dev_remove_driver_gpios(ACPI_COMPANION(&pci->dev));
  159. platform_device_unregister(pci_get_drvdata(pci));
  160. }
  161. static const struct pci_device_id dwc3_pci_id_table[] = {
  162. {
  163. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
  164. PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
  165. },
  166. {
  167. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
  168. PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI),
  169. },
  170. {
  171. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
  172. PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31),
  173. },
  174. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), },
  175. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), },
  176. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), },
  177. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTLP), },
  178. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTH), },
  179. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT), },
  180. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT_M), },
  181. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), },
  182. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), },
  183. { } /* Terminating Entry */
  184. };
  185. MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
  186. static struct pci_driver dwc3_pci_driver = {
  187. .name = "dwc3-pci",
  188. .id_table = dwc3_pci_id_table,
  189. .probe = dwc3_pci_probe,
  190. .remove = dwc3_pci_remove,
  191. };
  192. MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
  193. MODULE_LICENSE("GPL v2");
  194. MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer");
  195. module_pci_driver(dwc3_pci_driver);