dwc3-haps.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. /**
  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 int dwc3_haps_probe(struct pci_dev *pci,
  33. const struct pci_device_id *id)
  34. {
  35. struct dwc3_haps *dwc;
  36. struct device *dev = &pci->dev;
  37. struct resource res[2];
  38. int ret;
  39. ret = pcim_enable_device(pci);
  40. if (ret) {
  41. dev_err(dev, "failed to enable pci device\n");
  42. return -ENODEV;
  43. }
  44. pci_set_master(pci);
  45. dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
  46. if (!dwc)
  47. return -ENOMEM;
  48. dwc->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
  49. if (!dwc->dwc3)
  50. return -ENOMEM;
  51. memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
  52. res[0].start = pci_resource_start(pci, 0);
  53. res[0].end = pci_resource_end(pci, 0);
  54. res[0].name = "dwc_usb3";
  55. res[0].flags = IORESOURCE_MEM;
  56. res[1].start = pci->irq;
  57. res[1].name = "dwc_usb3";
  58. res[1].flags = IORESOURCE_IRQ;
  59. ret = platform_device_add_resources(dwc->dwc3, res, ARRAY_SIZE(res));
  60. if (ret) {
  61. dev_err(dev, "couldn't add resources to dwc3 device\n");
  62. goto err;
  63. }
  64. dwc->pci = pci;
  65. dwc->dwc3->dev.parent = dev;
  66. ret = platform_device_add_properties(dwc->dwc3, initial_properties);
  67. if (ret)
  68. goto err;
  69. ret = platform_device_add(dwc->dwc3);
  70. if (ret) {
  71. dev_err(dev, "failed to register dwc3 device\n");
  72. goto err;
  73. }
  74. pci_set_drvdata(pci, dwc);
  75. return 0;
  76. err:
  77. platform_device_put(dwc->dwc3);
  78. return ret;
  79. }
  80. static void dwc3_haps_remove(struct pci_dev *pci)
  81. {
  82. struct dwc3_haps *dwc = pci_get_drvdata(pci);
  83. platform_device_unregister(dwc->dwc3);
  84. }
  85. static const struct pci_device_id dwc3_haps_id_table[] = {
  86. {
  87. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
  88. PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
  89. },
  90. {
  91. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
  92. PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI),
  93. },
  94. {
  95. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
  96. PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31),
  97. },
  98. { } /* Terminating Entry */
  99. };
  100. MODULE_DEVICE_TABLE(pci, dwc3_haps_id_table);
  101. static struct pci_driver dwc3_haps_driver = {
  102. .name = "dwc3-haps",
  103. .id_table = dwc3_haps_id_table,
  104. .probe = dwc3_haps_probe,
  105. .remove = dwc3_haps_remove,
  106. };
  107. MODULE_AUTHOR("Thinh Nguyen <thinhn@synopsys.com>");
  108. MODULE_LICENSE("GPL v2");
  109. MODULE_DESCRIPTION("Synopsys HAPS PCI Glue Layer");
  110. module_pci_driver(dwc3_haps_driver);