ehci-ixp4xx.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * IXP4XX EHCI Host Controller Driver
  3. *
  4. * Author: Vladimir Barinov <vbarinov@embeddedalley.com>
  5. *
  6. * Based on "ehci-fsl.c" by Randy Vinson <rvinson@mvista.com>
  7. *
  8. * 2007 (c) MontaVista Software, Inc. This file is licensed under
  9. * the terms of the GNU General Public License version 2. This program
  10. * is licensed "as is" without any warranty of any kind, whether express
  11. * or implied.
  12. */
  13. #include <linux/platform_device.h>
  14. static int ixp4xx_ehci_init(struct usb_hcd *hcd)
  15. {
  16. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  17. int retval = 0;
  18. ehci->big_endian_desc = 1;
  19. ehci->big_endian_mmio = 1;
  20. ehci->caps = hcd->regs + 0x100;
  21. hcd->has_tt = 1;
  22. retval = ehci_setup(hcd);
  23. if (retval)
  24. return retval;
  25. ehci_port_power(ehci, 0);
  26. return retval;
  27. }
  28. static const struct hc_driver ixp4xx_ehci_hc_driver = {
  29. .description = hcd_name,
  30. .product_desc = "IXP4XX EHCI Host Controller",
  31. .hcd_priv_size = sizeof(struct ehci_hcd),
  32. .irq = ehci_irq,
  33. .flags = HCD_MEMORY | HCD_USB2,
  34. .reset = ixp4xx_ehci_init,
  35. .start = ehci_run,
  36. .stop = ehci_stop,
  37. .shutdown = ehci_shutdown,
  38. .urb_enqueue = ehci_urb_enqueue,
  39. .urb_dequeue = ehci_urb_dequeue,
  40. .endpoint_disable = ehci_endpoint_disable,
  41. .endpoint_reset = ehci_endpoint_reset,
  42. .get_frame_number = ehci_get_frame,
  43. .hub_status_data = ehci_hub_status_data,
  44. .hub_control = ehci_hub_control,
  45. #if defined(CONFIG_PM)
  46. .bus_suspend = ehci_bus_suspend,
  47. .bus_resume = ehci_bus_resume,
  48. #endif
  49. .relinquish_port = ehci_relinquish_port,
  50. .port_handed_over = ehci_port_handed_over,
  51. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  52. };
  53. static int ixp4xx_ehci_probe(struct platform_device *pdev)
  54. {
  55. struct usb_hcd *hcd;
  56. const struct hc_driver *driver = &ixp4xx_ehci_hc_driver;
  57. struct resource *res;
  58. int irq;
  59. int retval;
  60. if (usb_disabled())
  61. return -ENODEV;
  62. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  63. if (!res) {
  64. dev_err(&pdev->dev,
  65. "Found HC with no IRQ. Check %s setup!\n",
  66. dev_name(&pdev->dev));
  67. return -ENODEV;
  68. }
  69. irq = res->start;
  70. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  71. if (!hcd) {
  72. retval = -ENOMEM;
  73. goto fail_create_hcd;
  74. }
  75. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  76. if (!res) {
  77. dev_err(&pdev->dev,
  78. "Found HC with no register addr. Check %s setup!\n",
  79. dev_name(&pdev->dev));
  80. retval = -ENODEV;
  81. goto fail_request_resource;
  82. }
  83. hcd->rsrc_start = res->start;
  84. hcd->rsrc_len = resource_size(res);
  85. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  86. driver->description)) {
  87. dev_dbg(&pdev->dev, "controller already in use\n");
  88. retval = -EBUSY;
  89. goto fail_request_resource;
  90. }
  91. hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
  92. if (hcd->regs == NULL) {
  93. dev_dbg(&pdev->dev, "error mapping memory\n");
  94. retval = -EFAULT;
  95. goto fail_ioremap;
  96. }
  97. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  98. if (retval)
  99. goto fail_add_hcd;
  100. return retval;
  101. fail_add_hcd:
  102. iounmap(hcd->regs);
  103. fail_ioremap:
  104. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  105. fail_request_resource:
  106. usb_put_hcd(hcd);
  107. fail_create_hcd:
  108. dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval);
  109. return retval;
  110. }
  111. static int ixp4xx_ehci_remove(struct platform_device *pdev)
  112. {
  113. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  114. usb_remove_hcd(hcd);
  115. iounmap(hcd->regs);
  116. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  117. usb_put_hcd(hcd);
  118. return 0;
  119. }
  120. MODULE_ALIAS("platform:ixp4xx-ehci");
  121. static struct platform_driver ixp4xx_ehci_driver = {
  122. .probe = ixp4xx_ehci_probe,
  123. .remove = ixp4xx_ehci_remove,
  124. .driver = {
  125. .name = "ixp4xx-ehci",
  126. },
  127. };