dwc3-haps.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 <thinhn@synopsys.com>,
  8. * John Youn <johnyoun@synopsys.com>
  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. #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd
  17. #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI 0xabce
  18. #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31 0xabcf
  19. /**
  20. * struct dwc3_haps - Driver private structure
  21. * @dwc3: child dwc3 platform_device
  22. * @pci: our link to PCI bus
  23. */
  24. struct dwc3_haps {
  25. struct platform_device *dwc3;
  26. struct pci_dev *pci;
  27. };
  28. static const struct property_entry initial_properties[] = {
  29. PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"),
  30. PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"),
  31. PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"),
  32. PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
  33. { },
  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 = platform_device_add_properties(dwc->dwc3, initial_properties);
  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. platform_device_put(dwc->dwc3);
  81. return ret;
  82. }
  83. static void dwc3_haps_remove(struct pci_dev *pci)
  84. {
  85. struct dwc3_haps *dwc = pci_get_drvdata(pci);
  86. platform_device_unregister(dwc->dwc3);
  87. }
  88. static const struct pci_device_id dwc3_haps_id_table[] = {
  89. {
  90. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
  91. PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
  92. },
  93. {
  94. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
  95. PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI),
  96. },
  97. {
  98. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
  99. PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31),
  100. },
  101. { } /* Terminating Entry */
  102. };
  103. MODULE_DEVICE_TABLE(pci, dwc3_haps_id_table);
  104. static struct pci_driver dwc3_haps_driver = {
  105. .name = "dwc3-haps",
  106. .id_table = dwc3_haps_id_table,
  107. .probe = dwc3_haps_probe,
  108. .remove = dwc3_haps_remove,
  109. };
  110. MODULE_AUTHOR("Thinh Nguyen <thinhn@synopsys.com>");
  111. MODULE_LICENSE("GPL v2");
  112. MODULE_DESCRIPTION("Synopsys HAPS PCI Glue Layer");
  113. module_pci_driver(dwc3_haps_driver);