ci13xxx_pci.c 4.6 KB

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