ehci-vt8500.c 3.5 KB

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