dwc3-pci.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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_APL 0x5aaa
  36. #define PCI_DEVICE_ID_INTEL_KBP 0xa2b0
  37. #define PCI_DEVICE_ID_INTEL_GLK 0x31aa
  38. static const struct acpi_gpio_params reset_gpios = { 0, 0, false };
  39. static const struct acpi_gpio_params cs_gpios = { 1, 0, false };
  40. static const struct acpi_gpio_mapping acpi_dwc3_byt_gpios[] = {
  41. { "reset-gpios", &reset_gpios, 1 },
  42. { "cs-gpios", &cs_gpios, 1 },
  43. { },
  44. };
  45. static int dwc3_pci_quirks(struct pci_dev *pdev)
  46. {
  47. if (pdev->vendor == PCI_VENDOR_ID_AMD &&
  48. pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
  49. struct dwc3_platform_data pdata;
  50. memset(&pdata, 0, sizeof(pdata));
  51. pdata.has_lpm_erratum = true;
  52. pdata.lpm_nyet_threshold = 0xf;
  53. pdata.u2exit_lfps_quirk = true;
  54. pdata.u2ss_inp3_quirk = true;
  55. pdata.req_p1p2p3_quirk = true;
  56. pdata.del_p1p2p3_quirk = true;
  57. pdata.del_phy_power_chg_quirk = true;
  58. pdata.lfps_filter_quirk = true;
  59. pdata.rx_detect_poll_quirk = true;
  60. pdata.tx_de_emphasis_quirk = true;
  61. pdata.tx_de_emphasis = 1;
  62. /*
  63. * FIXME these quirks should be removed when AMD NL
  64. * taps out
  65. */
  66. pdata.disable_scramble_quirk = true;
  67. pdata.dis_u3_susphy_quirk = true;
  68. pdata.dis_u2_susphy_quirk = true;
  69. return platform_device_add_data(pci_get_drvdata(pdev), &pdata,
  70. sizeof(pdata));
  71. }
  72. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  73. pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
  74. struct gpio_desc *gpio;
  75. acpi_dev_add_driver_gpios(ACPI_COMPANION(&pdev->dev),
  76. acpi_dwc3_byt_gpios);
  77. /*
  78. * These GPIOs will turn on the USB2 PHY. Note that we have to
  79. * put the gpio descriptors again here because the phy driver
  80. * might want to grab them, too.
  81. */
  82. gpio = gpiod_get_optional(&pdev->dev, "cs", GPIOD_OUT_LOW);
  83. if (IS_ERR(gpio))
  84. return PTR_ERR(gpio);
  85. gpiod_set_value_cansleep(gpio, 1);
  86. gpiod_put(gpio);
  87. gpio = gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW);
  88. if (IS_ERR(gpio))
  89. return PTR_ERR(gpio);
  90. if (gpio) {
  91. gpiod_set_value_cansleep(gpio, 1);
  92. gpiod_put(gpio);
  93. usleep_range(10000, 11000);
  94. }
  95. }
  96. if (pdev->vendor == PCI_VENDOR_ID_SYNOPSYS &&
  97. (pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 ||
  98. pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI ||
  99. pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31)) {
  100. struct dwc3_platform_data pdata;
  101. memset(&pdata, 0, sizeof(pdata));
  102. pdata.usb3_lpm_capable = true;
  103. pdata.has_lpm_erratum = true;
  104. pdata.dis_enblslpm_quirk = true;
  105. return platform_device_add_data(pci_get_drvdata(pdev), &pdata,
  106. sizeof(pdata));
  107. }
  108. return 0;
  109. }
  110. static int dwc3_pci_probe(struct pci_dev *pci,
  111. const struct pci_device_id *id)
  112. {
  113. struct resource res[2];
  114. struct platform_device *dwc3;
  115. int ret;
  116. struct device *dev = &pci->dev;
  117. ret = pcim_enable_device(pci);
  118. if (ret) {
  119. dev_err(dev, "failed to enable pci device\n");
  120. return -ENODEV;
  121. }
  122. pci_set_master(pci);
  123. dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
  124. if (!dwc3) {
  125. dev_err(dev, "couldn't allocate dwc3 device\n");
  126. return -ENOMEM;
  127. }
  128. memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
  129. res[0].start = pci_resource_start(pci, 0);
  130. res[0].end = pci_resource_end(pci, 0);
  131. res[0].name = "dwc_usb3";
  132. res[0].flags = IORESOURCE_MEM;
  133. res[1].start = pci->irq;
  134. res[1].name = "dwc_usb3";
  135. res[1].flags = IORESOURCE_IRQ;
  136. ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res));
  137. if (ret) {
  138. dev_err(dev, "couldn't add resources to dwc3 device\n");
  139. goto err;
  140. }
  141. pci_set_drvdata(pci, dwc3);
  142. ret = dwc3_pci_quirks(pci);
  143. if (ret)
  144. goto err;
  145. dwc3->dev.parent = dev;
  146. ACPI_COMPANION_SET(&dwc3->dev, ACPI_COMPANION(dev));
  147. ret = platform_device_add(dwc3);
  148. if (ret) {
  149. dev_err(dev, "failed to register dwc3 device\n");
  150. goto err;
  151. }
  152. return 0;
  153. err:
  154. platform_device_put(dwc3);
  155. return ret;
  156. }
  157. static void dwc3_pci_remove(struct pci_dev *pci)
  158. {
  159. acpi_dev_remove_driver_gpios(ACPI_COMPANION(&pci->dev));
  160. platform_device_unregister(pci_get_drvdata(pci));
  161. }
  162. static const struct pci_device_id dwc3_pci_id_table[] = {
  163. {
  164. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
  165. PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
  166. },
  167. {
  168. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
  169. PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI),
  170. },
  171. {
  172. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
  173. PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31),
  174. },
  175. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), },
  176. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), },
  177. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), },
  178. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTLP), },
  179. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTH), },
  180. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT), },
  181. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), },
  182. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBP), },
  183. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_GLK), },
  184. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), },
  185. { } /* Terminating Entry */
  186. };
  187. MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
  188. static struct pci_driver dwc3_pci_driver = {
  189. .name = "dwc3-pci",
  190. .id_table = dwc3_pci_id_table,
  191. .probe = dwc3_pci_probe,
  192. .remove = dwc3_pci_remove,
  193. };
  194. MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
  195. MODULE_LICENSE("GPL v2");
  196. MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer");
  197. module_pci_driver(dwc3_pci_driver);