ehci-vt8500.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 const struct hc_driver vt8500_ehci_hc_driver = {
  21. .description = hcd_name,
  22. .product_desc = "VT8500 EHCI",
  23. .hcd_priv_size = sizeof(struct ehci_hcd),
  24. /*
  25. * generic hardware linkage
  26. */
  27. .irq = ehci_irq,
  28. .flags = HCD_MEMORY | HCD_USB2,
  29. /*
  30. * basic lifecycle operations
  31. */
  32. .reset = ehci_setup,
  33. .start = ehci_run,
  34. .stop = ehci_stop,
  35. .shutdown = ehci_shutdown,
  36. /*
  37. * managing i/o requests and associated device resources
  38. */
  39. .urb_enqueue = ehci_urb_enqueue,
  40. .urb_dequeue = ehci_urb_dequeue,
  41. .endpoint_disable = ehci_endpoint_disable,
  42. .endpoint_reset = ehci_endpoint_reset,
  43. /*
  44. * scheduling support
  45. */
  46. .get_frame_number = ehci_get_frame,
  47. /*
  48. * root hub support
  49. */
  50. .hub_status_data = ehci_hub_status_data,
  51. .hub_control = ehci_hub_control,
  52. .bus_suspend = ehci_bus_suspend,
  53. .bus_resume = ehci_bus_resume,
  54. .relinquish_port = ehci_relinquish_port,
  55. .port_handed_over = ehci_port_handed_over,
  56. /*
  57. * call back when device connected and addressed
  58. */
  59. .update_device = ehci_update_device,
  60. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  61. };
  62. static u64 vt8500_ehci_dma_mask = DMA_BIT_MASK(32);
  63. static int vt8500_ehci_drv_probe(struct platform_device *pdev)
  64. {
  65. struct usb_hcd *hcd;
  66. struct ehci_hcd *ehci;
  67. struct resource *res;
  68. int ret;
  69. if (usb_disabled())
  70. return -ENODEV;
  71. /*
  72. * Right now device-tree probed devices don't get dma_mask set.
  73. * Since shared usb code relies on it, set it here for now.
  74. * Once we have dma capability bindings this can go away.
  75. */
  76. if (!pdev->dev.dma_mask)
  77. pdev->dev.dma_mask = &vt8500_ehci_dma_mask;
  78. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  79. pr_debug("resource[1] is not IORESOURCE_IRQ");
  80. return -ENOMEM;
  81. }
  82. hcd = usb_create_hcd(&vt8500_ehci_hc_driver, &pdev->dev, "VT8500");
  83. if (!hcd)
  84. return -ENOMEM;
  85. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  86. hcd->rsrc_start = res->start;
  87. hcd->rsrc_len = resource_size(res);
  88. hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
  89. if (!hcd->regs) {
  90. pr_debug("ioremap failed");
  91. ret = -ENOMEM;
  92. goto err1;
  93. }
  94. ehci = hcd_to_ehci(hcd);
  95. ehci->caps = hcd->regs;
  96. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  97. IRQF_SHARED);
  98. if (ret == 0) {
  99. platform_set_drvdata(pdev, hcd);
  100. return ret;
  101. }
  102. err1:
  103. usb_put_hcd(hcd);
  104. return ret;
  105. }
  106. static int vt8500_ehci_drv_remove(struct platform_device *pdev)
  107. {
  108. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  109. usb_remove_hcd(hcd);
  110. usb_put_hcd(hcd);
  111. platform_set_drvdata(pdev, NULL);
  112. return 0;
  113. }
  114. static const struct of_device_id vt8500_ehci_ids[] = {
  115. { .compatible = "via,vt8500-ehci", },
  116. { .compatible = "wm,prizm-ehci", },
  117. {}
  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. .of_match_table = of_match_ptr(vt8500_ehci_ids),
  127. }
  128. };
  129. MODULE_ALIAS("platform:vt8500-ehci");
  130. MODULE_DEVICE_TABLE(of, vt8500_ehci_ids);