dwc3-haps.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * dwc3-haps.c - Synopsys HAPS PCI Specific glue layer
  4. *
  5. * Copyright (C) 2018 Synopsys, Inc.
  6. *
  7. * Authors: Thinh Nguyen <[email protected]>,
  8. * John Youn <[email protected]>
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/slab.h>
  13. #include <linux/pci.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/property.h>
  16. /**
  17. * struct dwc3_haps - Driver private structure
  18. * @dwc3: child dwc3 platform_device
  19. * @pci: our link to PCI bus
  20. */
  21. struct dwc3_haps {
  22. struct platform_device *dwc3;
  23. struct pci_dev *pci;
  24. };
  25. static const struct property_entry initial_properties[] = {
  26. PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"),
  27. PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"),
  28. PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"),
  29. PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
  30. { },
  31. };
  32. static const struct software_node dwc3_haps_swnode = {
  33. .properties = initial_properties,
  34. };
  35. static int dwc3_haps_probe(struct pci_dev *pci,
  36. const struct pci_device_id *id)
  37. {
  38. struct dwc3_haps *dwc;
  39. struct device *dev = &pci->dev;
  40. struct resource res[2];
  41. int ret;
  42. ret = pcim_enable_device(pci);
  43. if (ret) {
  44. dev_err(dev, "failed to enable pci device\n");
  45. return -ENODEV;
  46. }
  47. pci_set_master(pci);
  48. dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
  49. if (!dwc)
  50. return -ENOMEM;
  51. dwc->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
  52. if (!dwc->dwc3)
  53. return -ENOMEM;
  54. memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
  55. res[0].start = pci_resource_start(pci, 0);
  56. res[0].end = pci_resource_end(pci, 0);
  57. res[0].name = "dwc_usb3";
  58. res[0].flags = IORESOURCE_MEM;
  59. res[1].start = pci->irq;
  60. res[1].name = "dwc_usb3";
  61. res[1].flags = IORESOURCE_IRQ;
  62. ret = platform_device_add_resources(dwc->dwc3, res, ARRAY_SIZE(res));
  63. if (ret) {
  64. dev_err(dev, "couldn't add resources to dwc3 device\n");
  65. goto err;
  66. }
  67. dwc->pci = pci;
  68. dwc->dwc3->dev.parent = dev;
  69. ret = device_add_software_node(&dwc->dwc3->dev, &dwc3_haps_swnode);
  70. if (ret)
  71. goto err;
  72. ret = platform_device_add(dwc->dwc3);
  73. if (ret) {
  74. dev_err(dev, "failed to register dwc3 device\n");
  75. goto err;
  76. }
  77. pci_set_drvdata(pci, dwc);
  78. return 0;
  79. err:
  80. device_remove_software_node(&dwc->dwc3->dev);
  81. platform_device_put(dwc->dwc3);
  82. return ret;
  83. }
  84. static void dwc3_haps_remove(struct pci_dev *pci)
  85. {
  86. struct dwc3_haps *dwc = pci_get_drvdata(pci);
  87. device_remove_software_node(&dwc->dwc3->dev);
  88. platform_device_unregister(dwc->dwc3);
  89. }
  90. static const struct pci_device_id dwc3_haps_id_table[] = {
  91. {
  92. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
  93. PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
  94. /*
  95. * i.MX6QP and i.MX7D platform use a PCIe controller with the
  96. * same VID and PID as this USB controller. The system may
  97. * incorrectly match this driver to that PCIe controller. To
  98. * workaround this, specifically use class type USB to prevent
  99. * incorrect driver matching.
  100. */
  101. .class = (PCI_CLASS_SERIAL_USB << 8),
  102. .class_mask = 0xffff00,
  103. },
  104. {
  105. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
  106. PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI),
  107. },
  108. {
  109. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
  110. PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31),
  111. },
  112. { } /* Terminating Entry */
  113. };
  114. MODULE_DEVICE_TABLE(pci, dwc3_haps_id_table);
  115. static struct pci_driver dwc3_haps_driver = {
  116. .name = "dwc3-haps",
  117. .id_table = dwc3_haps_id_table,
  118. .probe = dwc3_haps_probe,
  119. .remove = dwc3_haps_remove,
  120. };
  121. MODULE_AUTHOR("Thinh Nguyen <[email protected]>");
  122. MODULE_LICENSE("GPL v2");
  123. MODULE_DESCRIPTION("Synopsys HAPS PCI Glue Layer");
  124. module_pci_driver(dwc3_haps_driver);