ehci-vt8500.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 u64 vt8500_ehci_dma_mask = DMA_BIT_MASK(32);
  77. static int vt8500_ehci_drv_probe(struct platform_device *pdev)
  78. {
  79. struct usb_hcd *hcd;
  80. struct ehci_hcd *ehci;
  81. struct resource *res;
  82. int ret;
  83. if (usb_disabled())
  84. return -ENODEV;
  85. /*
  86. * Right now device-tree probed devices don't get dma_mask set.
  87. * Since shared usb code relies on it, set it here for now.
  88. * Once we have dma capability bindings this can go away.
  89. */
  90. if (!pdev->dev.dma_mask)
  91. pdev->dev.dma_mask = &vt8500_ehci_dma_mask;
  92. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  93. pr_debug("resource[1] is not IORESOURCE_IRQ");
  94. return -ENOMEM;
  95. }
  96. hcd = usb_create_hcd(&vt8500_ehci_hc_driver, &pdev->dev, "VT8500");
  97. if (!hcd)
  98. return -ENOMEM;
  99. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  100. hcd->rsrc_start = res->start;
  101. hcd->rsrc_len = resource_size(res);
  102. hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
  103. if (!hcd->regs) {
  104. pr_debug("ioremap failed");
  105. ret = -ENOMEM;
  106. goto err1;
  107. }
  108. ehci = hcd_to_ehci(hcd);
  109. ehci->caps = hcd->regs;
  110. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  111. IRQF_SHARED);
  112. if (ret == 0) {
  113. platform_set_drvdata(pdev, hcd);
  114. return ret;
  115. }
  116. err1:
  117. usb_put_hcd(hcd);
  118. return ret;
  119. }
  120. static int vt8500_ehci_drv_remove(struct platform_device *pdev)
  121. {
  122. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  123. usb_remove_hcd(hcd);
  124. usb_put_hcd(hcd);
  125. platform_set_drvdata(pdev, NULL);
  126. return 0;
  127. }
  128. static const struct of_device_id vt8500_ehci_ids[] = {
  129. { .compatible = "via,vt8500-ehci", },
  130. { .compatible = "wm,prizm-ehci", },
  131. {}
  132. };
  133. static struct platform_driver vt8500_ehci_driver = {
  134. .probe = vt8500_ehci_drv_probe,
  135. .remove = vt8500_ehci_drv_remove,
  136. .shutdown = usb_hcd_platform_shutdown,
  137. .driver = {
  138. .name = "vt8500-ehci",
  139. .owner = THIS_MODULE,
  140. .of_match_table = of_match_ptr(vt8500_ehci_ids),
  141. }
  142. };
  143. MODULE_ALIAS("platform:vt8500-ehci");
  144. MODULE_DEVICE_TABLE(of, vt8500_ehci_ids);