dwc3-pci.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 "platform_data.h"
  24. #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd
  25. #define PCI_DEVICE_ID_INTEL_BYT 0x0f37
  26. #define PCI_DEVICE_ID_INTEL_MRFLD 0x119e
  27. #define PCI_DEVICE_ID_INTEL_BSW 0x22B7
  28. #define PCI_DEVICE_ID_INTEL_SPTLP 0x9d30
  29. #define PCI_DEVICE_ID_INTEL_SPTH 0xa130
  30. static int dwc3_pci_quirks(struct pci_dev *pdev)
  31. {
  32. if (pdev->vendor == PCI_VENDOR_ID_AMD &&
  33. pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
  34. struct dwc3_platform_data pdata;
  35. memset(&pdata, 0, sizeof(pdata));
  36. pdata.has_lpm_erratum = true;
  37. pdata.lpm_nyet_threshold = 0xf;
  38. pdata.u2exit_lfps_quirk = true;
  39. pdata.u2ss_inp3_quirk = true;
  40. pdata.req_p1p2p3_quirk = true;
  41. pdata.del_p1p2p3_quirk = true;
  42. pdata.del_phy_power_chg_quirk = true;
  43. pdata.lfps_filter_quirk = true;
  44. pdata.rx_detect_poll_quirk = true;
  45. pdata.tx_de_emphasis_quirk = true;
  46. pdata.tx_de_emphasis = 1;
  47. /*
  48. * FIXME these quirks should be removed when AMD NL
  49. * taps out
  50. */
  51. pdata.disable_scramble_quirk = true;
  52. pdata.dis_u3_susphy_quirk = true;
  53. pdata.dis_u2_susphy_quirk = true;
  54. return platform_device_add_data(pci_get_drvdata(pdev), &pdata,
  55. sizeof(pdata));
  56. }
  57. return 0;
  58. }
  59. static int dwc3_pci_probe(struct pci_dev *pci,
  60. const struct pci_device_id *id)
  61. {
  62. struct resource res[2];
  63. struct platform_device *dwc3;
  64. int ret;
  65. struct device *dev = &pci->dev;
  66. ret = pcim_enable_device(pci);
  67. if (ret) {
  68. dev_err(dev, "failed to enable pci device\n");
  69. return -ENODEV;
  70. }
  71. pci_set_master(pci);
  72. dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
  73. if (!dwc3) {
  74. dev_err(dev, "couldn't allocate dwc3 device\n");
  75. return -ENOMEM;
  76. }
  77. memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
  78. res[0].start = pci_resource_start(pci, 0);
  79. res[0].end = pci_resource_end(pci, 0);
  80. res[0].name = "dwc_usb3";
  81. res[0].flags = IORESOURCE_MEM;
  82. res[1].start = pci->irq;
  83. res[1].name = "dwc_usb3";
  84. res[1].flags = IORESOURCE_IRQ;
  85. ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res));
  86. if (ret) {
  87. dev_err(dev, "couldn't add resources to dwc3 device\n");
  88. return ret;
  89. }
  90. pci_set_drvdata(pci, dwc3);
  91. ret = dwc3_pci_quirks(pci);
  92. if (ret)
  93. goto err;
  94. dwc3->dev.parent = dev;
  95. ret = platform_device_add(dwc3);
  96. if (ret) {
  97. dev_err(dev, "failed to register dwc3 device\n");
  98. goto err;
  99. }
  100. return 0;
  101. err:
  102. platform_device_put(dwc3);
  103. return ret;
  104. }
  105. static void dwc3_pci_remove(struct pci_dev *pci)
  106. {
  107. platform_device_unregister(pci_get_drvdata(pci));
  108. }
  109. static const struct pci_device_id dwc3_pci_id_table[] = {
  110. {
  111. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
  112. PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
  113. },
  114. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), },
  115. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), },
  116. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), },
  117. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTLP), },
  118. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTH), },
  119. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), },
  120. { } /* Terminating Entry */
  121. };
  122. MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
  123. static struct pci_driver dwc3_pci_driver = {
  124. .name = "dwc3-pci",
  125. .id_table = dwc3_pci_id_table,
  126. .probe = dwc3_pci_probe,
  127. .remove = dwc3_pci_remove,
  128. };
  129. MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
  130. MODULE_LICENSE("GPL v2");
  131. MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer");
  132. module_pci_driver(dwc3_pci_driver);