ci13xxx_pci.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * ci13xxx_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 "ci13xxx_udc.h"
  18. /* driver name */
  19. #define UDC_DRIVER_NAME "ci13xxx_pci"
  20. /******************************************************************************
  21. * PCI block
  22. *****************************************************************************/
  23. struct ci13xxx_udc_driver pci_driver = {
  24. .name = UDC_DRIVER_NAME,
  25. .capoffset = DEF_CAPOFFSET,
  26. };
  27. struct ci13xxx_udc_driver langwell_pci_driver = {
  28. .name = UDC_DRIVER_NAME,
  29. .capoffset = 0,
  30. };
  31. /**
  32. * ci13xxx_pci_probe: PCI probe
  33. * @pdev: USB device controller being probed
  34. * @id: PCI hotplug ID connecting controller to UDC framework
  35. *
  36. * This function returns an error code
  37. * Allocates basic PCI resources for this USB device controller, and then
  38. * invokes the udc_probe() method to start the UDC associated with it
  39. */
  40. static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
  41. const struct pci_device_id *id)
  42. {
  43. struct ci13xxx_udc_driver *driver = (void *)id->driver_data;
  44. struct platform_device *plat_ci;
  45. struct resource res[3];
  46. int retval = 0, nres = 2;
  47. retval = pci_enable_device(pdev);
  48. if (retval)
  49. goto done;
  50. if (!pdev->irq) {
  51. dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!");
  52. retval = -ENODEV;
  53. goto disable_device;
  54. }
  55. pci_set_power_state(pdev, PCI_D0);
  56. pci_set_master(pdev);
  57. pci_try_set_mwi(pdev);
  58. plat_ci = platform_device_alloc("ci_udc", -1);
  59. if (!plat_ci) {
  60. dev_err(&pdev->dev, "can't allocate ci_udc platform device\n");
  61. retval = -ENOMEM;
  62. goto disable_device;
  63. }
  64. memset(res, 0, sizeof(res));
  65. res[0].start = pci_resource_start(pdev, 0);
  66. res[0].end = pci_resource_end(pdev, 0);
  67. res[0].flags = IORESOURCE_MEM;
  68. res[1].start = pdev->irq;
  69. res[1].flags = IORESOURCE_IRQ;
  70. retval = platform_device_add_resources(plat_ci, res, nres);
  71. if (retval) {
  72. dev_err(&pdev->dev, "can't add resources to platform device\n");
  73. goto put_platform;
  74. }
  75. retval = platform_device_add_data(plat_ci, driver, sizeof(*driver));
  76. if (retval)
  77. goto put_platform;
  78. dma_set_coherent_mask(&plat_ci->dev, pdev->dev.coherent_dma_mask);
  79. plat_ci->dev.dma_mask = pdev->dev.dma_mask;
  80. plat_ci->dev.dma_parms = pdev->dev.dma_parms;
  81. plat_ci->dev.parent = &pdev->dev;
  82. pci_set_drvdata(pdev, plat_ci);
  83. retval = platform_device_add(plat_ci);
  84. if (retval)
  85. goto put_platform;
  86. return 0;
  87. put_platform:
  88. pci_set_drvdata(pdev, NULL);
  89. platform_device_put(plat_ci);
  90. disable_device:
  91. pci_disable_device(pdev);
  92. done:
  93. return retval;
  94. }
  95. /**
  96. * ci13xxx_pci_remove: PCI remove
  97. * @pdev: USB Device Controller being removed
  98. *
  99. * Reverses the effect of ci13xxx_pci_probe(),
  100. * first invoking the udc_remove() and then releases
  101. * all PCI resources allocated for this USB device controller
  102. */
  103. static void __devexit ci13xxx_pci_remove(struct pci_dev *pdev)
  104. {
  105. struct platform_device *plat_ci = pci_get_drvdata(pdev);
  106. platform_device_unregister(plat_ci);
  107. pci_set_drvdata(pdev, NULL);
  108. pci_disable_device(pdev);
  109. }
  110. /**
  111. * PCI device table
  112. * PCI device structure
  113. *
  114. * Check "pci.h" for details
  115. */
  116. static DEFINE_PCI_DEVICE_TABLE(ci13xxx_pci_id_table) = {
  117. {
  118. PCI_DEVICE(0x153F, 0x1004),
  119. .driver_data = (kernel_ulong_t)&pci_driver,
  120. },
  121. {
  122. PCI_DEVICE(0x153F, 0x1006),
  123. .driver_data = (kernel_ulong_t)&pci_driver,
  124. },
  125. {
  126. PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0811),
  127. .driver_data = (kernel_ulong_t)&langwell_pci_driver,
  128. },
  129. {
  130. PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0829),
  131. .driver_data = (kernel_ulong_t)&langwell_pci_driver,
  132. },
  133. { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ }
  134. };
  135. MODULE_DEVICE_TABLE(pci, ci13xxx_pci_id_table);
  136. static struct pci_driver ci13xxx_pci_driver = {
  137. .name = UDC_DRIVER_NAME,
  138. .id_table = ci13xxx_pci_id_table,
  139. .probe = ci13xxx_pci_probe,
  140. .remove = __devexit_p(ci13xxx_pci_remove),
  141. };
  142. module_pci_driver(ci13xxx_pci_driver);
  143. MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>");
  144. MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller");
  145. MODULE_LICENSE("GPL");
  146. MODULE_VERSION("June 2008");