ci_hdrc_pci.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * ci_hdrc_pci.c - MIPS USB IP core family device controller
  4. *
  5. * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved.
  6. *
  7. * Author: David Lopo
  8. */
  9. #include <linux/platform_device.h>
  10. #include <linux/module.h>
  11. #include <linux/pci.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/usb/gadget.h>
  14. #include <linux/usb/chipidea.h>
  15. #include <linux/usb/usb_phy_generic.h>
  16. /* driver name */
  17. #define UDC_DRIVER_NAME "ci_hdrc_pci"
  18. struct ci_hdrc_pci {
  19. struct platform_device *ci;
  20. struct platform_device *phy;
  21. };
  22. /******************************************************************************
  23. * PCI block
  24. *****************************************************************************/
  25. static struct ci_hdrc_platform_data pci_platdata = {
  26. .name = UDC_DRIVER_NAME,
  27. .capoffset = DEF_CAPOFFSET,
  28. };
  29. static struct ci_hdrc_platform_data langwell_pci_platdata = {
  30. .name = UDC_DRIVER_NAME,
  31. .capoffset = 0,
  32. };
  33. static struct ci_hdrc_platform_data penwell_pci_platdata = {
  34. .name = UDC_DRIVER_NAME,
  35. .capoffset = 0,
  36. .power_budget = 200,
  37. };
  38. /**
  39. * ci_hdrc_pci_probe: PCI probe
  40. * @pdev: USB device controller being probed
  41. * @id: PCI hotplug ID connecting controller to UDC framework
  42. *
  43. * This function returns an error code
  44. * Allocates basic PCI resources for this USB device controller, and then
  45. * invokes the udc_probe() method to start the UDC associated with it
  46. */
  47. static int ci_hdrc_pci_probe(struct pci_dev *pdev,
  48. const struct pci_device_id *id)
  49. {
  50. struct ci_hdrc_platform_data *platdata = (void *)id->driver_data;
  51. struct ci_hdrc_pci *ci;
  52. struct resource res[3];
  53. int retval = 0, nres = 2;
  54. if (!platdata) {
  55. dev_err(&pdev->dev, "device doesn't provide driver data\n");
  56. return -ENODEV;
  57. }
  58. ci = devm_kzalloc(&pdev->dev, sizeof(*ci), GFP_KERNEL);
  59. if (!ci)
  60. return -ENOMEM;
  61. retval = pcim_enable_device(pdev);
  62. if (retval)
  63. return retval;
  64. if (!pdev->irq) {
  65. dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!");
  66. return -ENODEV;
  67. }
  68. pci_set_master(pdev);
  69. pci_try_set_mwi(pdev);
  70. /* register a nop PHY */
  71. ci->phy = usb_phy_generic_register();
  72. if (IS_ERR(ci->phy))
  73. return PTR_ERR(ci->phy);
  74. memset(res, 0, sizeof(res));
  75. res[0].start = pci_resource_start(pdev, 0);
  76. res[0].end = pci_resource_end(pdev, 0);
  77. res[0].flags = IORESOURCE_MEM;
  78. res[1].start = pdev->irq;
  79. res[1].flags = IORESOURCE_IRQ;
  80. ci->ci = ci_hdrc_add_device(&pdev->dev, res, nres, platdata);
  81. if (IS_ERR(ci->ci)) {
  82. dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n");
  83. usb_phy_generic_unregister(ci->phy);
  84. return PTR_ERR(ci->ci);
  85. }
  86. pci_set_drvdata(pdev, ci);
  87. return 0;
  88. }
  89. /**
  90. * ci_hdrc_pci_remove: PCI remove
  91. * @pdev: USB Device Controller being removed
  92. *
  93. * Reverses the effect of ci_hdrc_pci_probe(),
  94. * first invoking the udc_remove() and then releases
  95. * all PCI resources allocated for this USB device controller
  96. */
  97. static void ci_hdrc_pci_remove(struct pci_dev *pdev)
  98. {
  99. struct ci_hdrc_pci *ci = pci_get_drvdata(pdev);
  100. ci_hdrc_remove_device(ci->ci);
  101. usb_phy_generic_unregister(ci->phy);
  102. }
  103. /**
  104. * PCI device table
  105. * PCI device structure
  106. *
  107. * Check "pci.h" for details
  108. *
  109. * Note: ehci-pci driver may try to probe the device first. You have to add an
  110. * ID to the bypass_pci_id_table in ehci-pci driver to prevent this.
  111. */
  112. static const struct pci_device_id ci_hdrc_pci_id_table[] = {
  113. {
  114. PCI_DEVICE(0x153F, 0x1004),
  115. .driver_data = (kernel_ulong_t)&pci_platdata,
  116. },
  117. {
  118. PCI_DEVICE(0x153F, 0x1006),
  119. .driver_data = (kernel_ulong_t)&pci_platdata,
  120. },
  121. {
  122. PCI_VDEVICE(INTEL, 0x0811),
  123. .driver_data = (kernel_ulong_t)&langwell_pci_platdata,
  124. },
  125. {
  126. PCI_VDEVICE(INTEL, 0x0829),
  127. .driver_data = (kernel_ulong_t)&penwell_pci_platdata,
  128. },
  129. {
  130. /* Intel Clovertrail */
  131. PCI_VDEVICE(INTEL, 0xe006),
  132. .driver_data = (kernel_ulong_t)&penwell_pci_platdata,
  133. },
  134. { 0 } /* end: all zeroes */
  135. };
  136. MODULE_DEVICE_TABLE(pci, ci_hdrc_pci_id_table);
  137. static struct pci_driver ci_hdrc_pci_driver = {
  138. .name = UDC_DRIVER_NAME,
  139. .id_table = ci_hdrc_pci_id_table,
  140. .probe = ci_hdrc_pci_probe,
  141. .remove = ci_hdrc_pci_remove,
  142. };
  143. module_pci_driver(ci_hdrc_pci_driver);
  144. MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>");
  145. MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller");
  146. MODULE_LICENSE("GPL");
  147. MODULE_ALIAS("platform:ci13xxx_pci");