ehci-vt8500.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * drivers/usb/host/ehci-vt8500.c
  3. *
  4. * Copyright (C) 2010 Alexey Charkov <alchark@gmail.com>
  5. *
  6. * Based on ehci-au1xxx.c
  7. *
  8. * This software is licensed under the terms of the GNU General Public
  9. * License version 2, as published by the Free Software Foundation, and
  10. * may be copied, distributed, and modified under those terms.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. */
  18. #include <linux/platform_device.h>
  19. static int ehci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
  20. {
  21. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  22. int rc = 0;
  23. if (!udev->parent) /* udev is root hub itself, impossible */
  24. rc = -1;
  25. /* we only support lpm device connected to root hub yet */
  26. if (ehci->has_lpm && !udev->parent->parent) {
  27. rc = ehci_lpm_set_da(ehci, udev->devnum, udev->portnum);
  28. if (!rc)
  29. rc = ehci_lpm_check(ehci, udev->portnum);
  30. }
  31. return rc;
  32. }
  33. static const struct hc_driver vt8500_ehci_hc_driver = {
  34. .description = hcd_name,
  35. .product_desc = "VT8500 EHCI",
  36. .hcd_priv_size = sizeof(struct ehci_hcd),
  37. /*
  38. * generic hardware linkage
  39. */
  40. .irq = ehci_irq,
  41. .flags = HCD_MEMORY | HCD_USB2,
  42. /*
  43. * basic lifecycle operations
  44. */
  45. .reset = ehci_init,
  46. .start = ehci_run,
  47. .stop = ehci_stop,
  48. .shutdown = ehci_shutdown,
  49. /*
  50. * managing i/o requests and associated device resources
  51. */
  52. .urb_enqueue = ehci_urb_enqueue,
  53. .urb_dequeue = ehci_urb_dequeue,
  54. .endpoint_disable = ehci_endpoint_disable,
  55. .endpoint_reset = ehci_endpoint_reset,
  56. /*
  57. * scheduling support
  58. */
  59. .get_frame_number = ehci_get_frame,
  60. /*
  61. * root hub support
  62. */
  63. .hub_status_data = ehci_hub_status_data,
  64. .hub_control = ehci_hub_control,
  65. .bus_suspend = ehci_bus_suspend,
  66. .bus_resume = ehci_bus_resume,
  67. .relinquish_port = ehci_relinquish_port,
  68. .port_handed_over = ehci_port_handed_over,
  69. /*
  70. * call back when device connected and addressed
  71. */
  72. .update_device = ehci_update_device,
  73. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  74. };
  75. static int vt8500_ehci_drv_probe(struct platform_device *pdev)
  76. {
  77. struct usb_hcd *hcd;
  78. struct ehci_hcd *ehci;
  79. struct resource *res;
  80. int ret;
  81. if (usb_disabled())
  82. return -ENODEV;
  83. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  84. pr_debug("resource[1] is not IORESOURCE_IRQ");
  85. return -ENOMEM;
  86. }
  87. hcd = usb_create_hcd(&vt8500_ehci_hc_driver, &pdev->dev, "VT8500");
  88. if (!hcd)
  89. return -ENOMEM;
  90. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  91. hcd->rsrc_start = res->start;
  92. hcd->rsrc_len = resource_size(res);
  93. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  94. pr_debug("request_mem_region failed");
  95. ret = -EBUSY;
  96. goto err1;
  97. }
  98. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  99. if (!hcd->regs) {
  100. pr_debug("ioremap failed");
  101. ret = -ENOMEM;
  102. goto err2;
  103. }
  104. ehci = hcd_to_ehci(hcd);
  105. ehci->caps = hcd->regs;
  106. ehci->regs = hcd->regs +
  107. HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
  108. dbg_hcs_params(ehci, "reset");
  109. dbg_hcc_params(ehci, "reset");
  110. /* cache this readonly data; minimize chip reads */
  111. ehci->hcs_params = readl(&ehci->caps->hcs_params);
  112. ehci_port_power(ehci, 1);
  113. ehci_reset(ehci);
  114. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  115. IRQF_SHARED);
  116. if (ret == 0) {
  117. platform_set_drvdata(pdev, hcd);
  118. return ret;
  119. }
  120. iounmap(hcd->regs);
  121. err2:
  122. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  123. err1:
  124. usb_put_hcd(hcd);
  125. return ret;
  126. }
  127. static int vt8500_ehci_drv_remove(struct platform_device *pdev)
  128. {
  129. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  130. usb_remove_hcd(hcd);
  131. iounmap(hcd->regs);
  132. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  133. usb_put_hcd(hcd);
  134. platform_set_drvdata(pdev, NULL);
  135. return 0;
  136. }
  137. static struct platform_driver vt8500_ehci_driver = {
  138. .probe = vt8500_ehci_drv_probe,
  139. .remove = vt8500_ehci_drv_remove,
  140. .shutdown = usb_hcd_platform_shutdown,
  141. .driver = {
  142. .name = "vt8500-ehci",
  143. .owner = THIS_MODULE,
  144. }
  145. };
  146. MODULE_ALIAS("platform:vt8500-ehci");