ehci-ixp4xx.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. ehci->regs = hcd->regs + 0x100
  22. + HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  23. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  24. hcd->has_tt = 1;
  25. ehci_reset(ehci);
  26. retval = ehci_init(hcd);
  27. if (retval)
  28. return retval;
  29. ehci_port_power(ehci, 0);
  30. return retval;
  31. }
  32. static const struct hc_driver ixp4xx_ehci_hc_driver = {
  33. .description = hcd_name,
  34. .product_desc = "IXP4XX EHCI Host Controller",
  35. .hcd_priv_size = sizeof(struct ehci_hcd),
  36. .irq = ehci_irq,
  37. .flags = HCD_MEMORY | HCD_USB2,
  38. .reset = ixp4xx_ehci_init,
  39. .start = ehci_run,
  40. .stop = ehci_stop,
  41. .shutdown = ehci_shutdown,
  42. .urb_enqueue = ehci_urb_enqueue,
  43. .urb_dequeue = ehci_urb_dequeue,
  44. .endpoint_disable = ehci_endpoint_disable,
  45. .endpoint_reset = ehci_endpoint_reset,
  46. .get_frame_number = ehci_get_frame,
  47. .hub_status_data = ehci_hub_status_data,
  48. .hub_control = ehci_hub_control,
  49. #if defined(CONFIG_PM)
  50. .bus_suspend = ehci_bus_suspend,
  51. .bus_resume = ehci_bus_resume,
  52. #endif
  53. .relinquish_port = ehci_relinquish_port,
  54. .port_handed_over = ehci_port_handed_over,
  55. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  56. };
  57. static int ixp4xx_ehci_probe(struct platform_device *pdev)
  58. {
  59. struct usb_hcd *hcd;
  60. const struct hc_driver *driver = &ixp4xx_ehci_hc_driver;
  61. struct resource *res;
  62. int irq;
  63. int retval;
  64. if (usb_disabled())
  65. return -ENODEV;
  66. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  67. if (!res) {
  68. dev_err(&pdev->dev,
  69. "Found HC with no IRQ. Check %s setup!\n",
  70. dev_name(&pdev->dev));
  71. return -ENODEV;
  72. }
  73. irq = res->start;
  74. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  75. if (!hcd) {
  76. retval = -ENOMEM;
  77. goto fail_create_hcd;
  78. }
  79. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  80. if (!res) {
  81. dev_err(&pdev->dev,
  82. "Found HC with no register addr. Check %s setup!\n",
  83. dev_name(&pdev->dev));
  84. retval = -ENODEV;
  85. goto fail_request_resource;
  86. }
  87. hcd->rsrc_start = res->start;
  88. hcd->rsrc_len = res->end - res->start + 1;
  89. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  90. driver->description)) {
  91. dev_dbg(&pdev->dev, "controller already in use\n");
  92. retval = -EBUSY;
  93. goto fail_request_resource;
  94. }
  95. hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
  96. if (hcd->regs == NULL) {
  97. dev_dbg(&pdev->dev, "error mapping memory\n");
  98. retval = -EFAULT;
  99. goto fail_ioremap;
  100. }
  101. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  102. if (retval)
  103. goto fail_add_hcd;
  104. return retval;
  105. fail_add_hcd:
  106. iounmap(hcd->regs);
  107. fail_ioremap:
  108. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  109. fail_request_resource:
  110. usb_put_hcd(hcd);
  111. fail_create_hcd:
  112. dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval);
  113. return retval;
  114. }
  115. static int ixp4xx_ehci_remove(struct platform_device *pdev)
  116. {
  117. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  118. usb_remove_hcd(hcd);
  119. iounmap(hcd->regs);
  120. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  121. usb_put_hcd(hcd);
  122. return 0;
  123. }
  124. MODULE_ALIAS("platform:ixp4xx-ehci");
  125. static struct platform_driver ixp4xx_ehci_driver = {
  126. .probe = ixp4xx_ehci_probe,
  127. .remove = ixp4xx_ehci_remove,
  128. .driver = {
  129. .name = "ixp4xx-ehci",
  130. },
  131. };