dwc3-pci.c 4.2 KB

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