ehci-vt8500.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_setup,
  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. hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
  94. if (!hcd->regs) {
  95. pr_debug("ioremap failed");
  96. ret = -ENOMEM;
  97. goto err1;
  98. }
  99. ehci = hcd_to_ehci(hcd);
  100. ehci->caps = hcd->regs;
  101. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  102. IRQF_SHARED);
  103. if (ret == 0) {
  104. platform_set_drvdata(pdev, hcd);
  105. return ret;
  106. }
  107. err1:
  108. usb_put_hcd(hcd);
  109. return ret;
  110. }
  111. static int vt8500_ehci_drv_remove(struct platform_device *pdev)
  112. {
  113. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  114. usb_remove_hcd(hcd);
  115. usb_put_hcd(hcd);
  116. platform_set_drvdata(pdev, NULL);
  117. return 0;
  118. }
  119. static struct platform_driver vt8500_ehci_driver = {
  120. .probe = vt8500_ehci_drv_probe,
  121. .remove = vt8500_ehci_drv_remove,
  122. .shutdown = usb_hcd_platform_shutdown,
  123. .driver = {
  124. .name = "vt8500-ehci",
  125. .owner = THIS_MODULE,
  126. }
  127. };
  128. MODULE_ALIAS("platform:vt8500-ehci");