pci.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
  2. /*
  3. * pci.c - DesignWare HS OTG Controller PCI driver
  4. *
  5. * Copyright (C) 2004-2013 Synopsys, Inc.
  6. */
  7. /*
  8. * Provides the initialization and cleanup entry points for the DWC_otg PCI
  9. * driver
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/moduleparam.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/io.h>
  17. #include <linux/slab.h>
  18. #include <linux/pci.h>
  19. #include <linux/usb.h>
  20. #include <linux/usb/hcd.h>
  21. #include <linux/usb/ch11.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/usb/usb_phy_generic.h>
  24. #define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0
  25. static const char dwc2_driver_name[] = "dwc2-pci";
  26. struct dwc2_pci_glue {
  27. struct platform_device *dwc2;
  28. struct platform_device *phy;
  29. };
  30. /**
  31. * dwc2_pci_remove() - Provides the cleanup entry points for the DWC_otg PCI
  32. * driver
  33. *
  34. * @pci: The programming view of DWC_otg PCI
  35. */
  36. static void dwc2_pci_remove(struct pci_dev *pci)
  37. {
  38. struct dwc2_pci_glue *glue = pci_get_drvdata(pci);
  39. platform_device_unregister(glue->dwc2);
  40. usb_phy_generic_unregister(glue->phy);
  41. pci_set_drvdata(pci, NULL);
  42. }
  43. static int dwc2_pci_probe(struct pci_dev *pci,
  44. const struct pci_device_id *id)
  45. {
  46. struct resource res[2];
  47. struct platform_device *dwc2;
  48. struct platform_device *phy;
  49. int ret;
  50. struct device *dev = &pci->dev;
  51. struct dwc2_pci_glue *glue;
  52. ret = pcim_enable_device(pci);
  53. if (ret) {
  54. dev_err(dev, "failed to enable pci device\n");
  55. return -ENODEV;
  56. }
  57. pci_set_master(pci);
  58. phy = usb_phy_generic_register();
  59. if (IS_ERR(phy)) {
  60. dev_err(dev, "error registering generic PHY (%ld)\n",
  61. PTR_ERR(phy));
  62. return PTR_ERR(phy);
  63. }
  64. dwc2 = platform_device_alloc("dwc2", PLATFORM_DEVID_AUTO);
  65. if (!dwc2) {
  66. dev_err(dev, "couldn't allocate dwc2 device\n");
  67. ret = -ENOMEM;
  68. goto err;
  69. }
  70. memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
  71. res[0].start = pci_resource_start(pci, 0);
  72. res[0].end = pci_resource_end(pci, 0);
  73. res[0].name = "dwc2";
  74. res[0].flags = IORESOURCE_MEM;
  75. res[1].start = pci->irq;
  76. res[1].name = "dwc2";
  77. res[1].flags = IORESOURCE_IRQ;
  78. ret = platform_device_add_resources(dwc2, res, ARRAY_SIZE(res));
  79. if (ret) {
  80. dev_err(dev, "couldn't add resources to dwc2 device\n");
  81. goto err;
  82. }
  83. dwc2->dev.parent = dev;
  84. glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL);
  85. if (!glue) {
  86. ret = -ENOMEM;
  87. goto err;
  88. }
  89. ret = platform_device_add(dwc2);
  90. if (ret) {
  91. dev_err(dev, "failed to register dwc2 device\n");
  92. goto err;
  93. }
  94. glue->phy = phy;
  95. glue->dwc2 = dwc2;
  96. pci_set_drvdata(pci, glue);
  97. return 0;
  98. err:
  99. usb_phy_generic_unregister(phy);
  100. platform_device_put(dwc2);
  101. return ret;
  102. }
  103. static const struct pci_device_id dwc2_pci_ids[] = {
  104. {
  105. PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG),
  106. },
  107. {
  108. PCI_DEVICE(PCI_VENDOR_ID_STMICRO,
  109. PCI_DEVICE_ID_STMICRO_USB_OTG),
  110. },
  111. { /* end: all zeroes */ }
  112. };
  113. MODULE_DEVICE_TABLE(pci, dwc2_pci_ids);
  114. static struct pci_driver dwc2_pci_driver = {
  115. .name = dwc2_driver_name,
  116. .id_table = dwc2_pci_ids,
  117. .probe = dwc2_pci_probe,
  118. .remove = dwc2_pci_remove,
  119. };
  120. module_pci_driver(dwc2_pci_driver);
  121. MODULE_DESCRIPTION("DESIGNWARE HS OTG PCI Bus Glue");
  122. MODULE_AUTHOR("Synopsys, Inc.");
  123. MODULE_LICENSE("Dual BSD/GPL");