ci_hdrc_pci.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. /* driver name */
  19. #define UDC_DRIVER_NAME "ci_hdrc_pci"
  20. /******************************************************************************
  21. * PCI block
  22. *****************************************************************************/
  23. static struct ci_hdrc_platform_data pci_platdata = {
  24. .name = UDC_DRIVER_NAME,
  25. .capoffset = DEF_CAPOFFSET,
  26. };
  27. static struct ci_hdrc_platform_data langwell_pci_platdata = {
  28. .name = UDC_DRIVER_NAME,
  29. .capoffset = 0,
  30. };
  31. static struct ci_hdrc_platform_data penwell_pci_platdata = {
  32. .name = UDC_DRIVER_NAME,
  33. .capoffset = 0,
  34. .power_budget = 200,
  35. };
  36. /**
  37. * ci_hdrc_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 ci_hdrc_pci_probe(struct pci_dev *pdev,
  46. const struct pci_device_id *id)
  47. {
  48. struct ci_hdrc_platform_data *platdata = (void *)id->driver_data;
  49. struct platform_device *plat_ci;
  50. struct resource res[3];
  51. int retval = 0, nres = 2;
  52. if (!platdata) {
  53. dev_err(&pdev->dev, "device doesn't provide driver data\n");
  54. return -ENODEV;
  55. }
  56. retval = pcim_enable_device(pdev);
  57. if (retval)
  58. return retval;
  59. if (!pdev->irq) {
  60. dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!");
  61. return -ENODEV;
  62. }
  63. pci_set_master(pdev);
  64. pci_try_set_mwi(pdev);
  65. memset(res, 0, sizeof(res));
  66. res[0].start = pci_resource_start(pdev, 0);
  67. res[0].end = pci_resource_end(pdev, 0);
  68. res[0].flags = IORESOURCE_MEM;
  69. res[1].start = pdev->irq;
  70. res[1].flags = IORESOURCE_IRQ;
  71. plat_ci = ci_hdrc_add_device(&pdev->dev, res, nres, platdata);
  72. if (IS_ERR(plat_ci)) {
  73. dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n");
  74. return PTR_ERR(plat_ci);
  75. }
  76. pci_set_drvdata(pdev, plat_ci);
  77. return 0;
  78. }
  79. /**
  80. * ci_hdrc_pci_remove: PCI remove
  81. * @pdev: USB Device Controller being removed
  82. *
  83. * Reverses the effect of ci_hdrc_pci_probe(),
  84. * first invoking the udc_remove() and then releases
  85. * all PCI resources allocated for this USB device controller
  86. */
  87. static void ci_hdrc_pci_remove(struct pci_dev *pdev)
  88. {
  89. struct platform_device *plat_ci = pci_get_drvdata(pdev);
  90. ci_hdrc_remove_device(plat_ci);
  91. }
  92. /**
  93. * PCI device table
  94. * PCI device structure
  95. *
  96. * Check "pci.h" for details
  97. */
  98. static DEFINE_PCI_DEVICE_TABLE(ci_hdrc_pci_id_table) = {
  99. {
  100. PCI_DEVICE(0x153F, 0x1004),
  101. .driver_data = (kernel_ulong_t)&pci_platdata,
  102. },
  103. {
  104. PCI_DEVICE(0x153F, 0x1006),
  105. .driver_data = (kernel_ulong_t)&pci_platdata,
  106. },
  107. {
  108. PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0811),
  109. .driver_data = (kernel_ulong_t)&langwell_pci_platdata,
  110. },
  111. {
  112. PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0829),
  113. .driver_data = (kernel_ulong_t)&penwell_pci_platdata,
  114. },
  115. { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ }
  116. };
  117. MODULE_DEVICE_TABLE(pci, ci_hdrc_pci_id_table);
  118. static struct pci_driver ci_hdrc_pci_driver = {
  119. .name = UDC_DRIVER_NAME,
  120. .id_table = ci_hdrc_pci_id_table,
  121. .probe = ci_hdrc_pci_probe,
  122. .remove = ci_hdrc_pci_remove,
  123. };
  124. module_pci_driver(ci_hdrc_pci_driver);
  125. MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>");
  126. MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller");
  127. MODULE_LICENSE("GPL");
  128. MODULE_VERSION("June 2008");
  129. MODULE_ALIAS("platform:ci13xxx_pci");