ci_hdrc_pci.c 4.4 KB

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