ehci-vt8500.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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/of.h>
  19. #include <linux/platform_device.h>
  20. static int ehci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
  21. {
  22. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  23. int rc = 0;
  24. if (!udev->parent) /* udev is root hub itself, impossible */
  25. rc = -1;
  26. /* we only support lpm device connected to root hub yet */
  27. if (ehci->has_lpm && !udev->parent->parent) {
  28. rc = ehci_lpm_set_da(ehci, udev->devnum, udev->portnum);
  29. if (!rc)
  30. rc = ehci_lpm_check(ehci, udev->portnum);
  31. }
  32. return rc;
  33. }
  34. static const struct hc_driver vt8500_ehci_hc_driver = {
  35. .description = hcd_name,
  36. .product_desc = "VT8500 EHCI",
  37. .hcd_priv_size = sizeof(struct ehci_hcd),
  38. /*
  39. * generic hardware linkage
  40. */
  41. .irq = ehci_irq,
  42. .flags = HCD_MEMORY | HCD_USB2,
  43. /*
  44. * basic lifecycle operations
  45. */
  46. .reset = ehci_setup,
  47. .start = ehci_run,
  48. .stop = ehci_stop,
  49. .shutdown = ehci_shutdown,
  50. /*
  51. * managing i/o requests and associated device resources
  52. */
  53. .urb_enqueue = ehci_urb_enqueue,
  54. .urb_dequeue = ehci_urb_dequeue,
  55. .endpoint_disable = ehci_endpoint_disable,
  56. .endpoint_reset = ehci_endpoint_reset,
  57. /*
  58. * scheduling support
  59. */
  60. .get_frame_number = ehci_get_frame,
  61. /*
  62. * root hub support
  63. */
  64. .hub_status_data = ehci_hub_status_data,
  65. .hub_control = ehci_hub_control,
  66. .bus_suspend = ehci_bus_suspend,
  67. .bus_resume = ehci_bus_resume,
  68. .relinquish_port = ehci_relinquish_port,
  69. .port_handed_over = ehci_port_handed_over,
  70. /*
  71. * call back when device connected and addressed
  72. */
  73. .update_device = ehci_update_device,
  74. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  75. };
  76. static int vt8500_ehci_drv_probe(struct platform_device *pdev)
  77. {
  78. struct usb_hcd *hcd;
  79. struct ehci_hcd *ehci;
  80. struct resource *res;
  81. int ret;
  82. if (usb_disabled())
  83. return -ENODEV;
  84. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  85. pr_debug("resource[1] is not IORESOURCE_IRQ");
  86. return -ENOMEM;
  87. }
  88. hcd = usb_create_hcd(&vt8500_ehci_hc_driver, &pdev->dev, "VT8500");
  89. if (!hcd)
  90. return -ENOMEM;
  91. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  92. hcd->rsrc_start = res->start;
  93. hcd->rsrc_len = resource_size(res);
  94. hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
  95. if (!hcd->regs) {
  96. pr_debug("ioremap failed");
  97. ret = -ENOMEM;
  98. goto err1;
  99. }
  100. ehci = hcd_to_ehci(hcd);
  101. ehci->caps = hcd->regs;
  102. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  103. IRQF_SHARED);
  104. if (ret == 0) {
  105. platform_set_drvdata(pdev, hcd);
  106. return ret;
  107. }
  108. err1:
  109. usb_put_hcd(hcd);
  110. return ret;
  111. }
  112. static int vt8500_ehci_drv_remove(struct platform_device *pdev)
  113. {
  114. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  115. usb_remove_hcd(hcd);
  116. usb_put_hcd(hcd);
  117. platform_set_drvdata(pdev, NULL);
  118. return 0;
  119. }
  120. static const struct of_device_id vt8500_ehci_ids[] = {
  121. { .compatible = "via,vt8500-ehci", },
  122. { .compatible = "wm,prizm-ehci", },
  123. {}
  124. };
  125. static struct platform_driver vt8500_ehci_driver = {
  126. .probe = vt8500_ehci_drv_probe,
  127. .remove = vt8500_ehci_drv_remove,
  128. .shutdown = usb_hcd_platform_shutdown,
  129. .driver = {
  130. .name = "vt8500-ehci",
  131. .owner = THIS_MODULE,
  132. .of_match_table = of_match_ptr(vt8500_ehci_ids),
  133. }
  134. };
  135. MODULE_ALIAS("platform:vt8500-ehci");
  136. MODULE_DEVICE_TABLE(of, vt8500_ehci_ids);