ci_hdrc_pci.c 4.4 KB

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