ehci-ls1x.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Bus Glue for Loongson LS1X built-in EHCI controller.
  3. *
  4. * Copyright (c) 2012 Zhang, Keguang <keguang.zhang@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation.
  9. */
  10. #include <linux/platform_device.h>
  11. static int ehci_ls1x_reset(struct usb_hcd *hcd)
  12. {
  13. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  14. int ret;
  15. ehci->caps = hcd->regs;
  16. ret = ehci_setup(hcd);
  17. if (ret)
  18. return ret;
  19. ehci_port_power(ehci, 0);
  20. return 0;
  21. }
  22. static const struct hc_driver ehci_ls1x_hc_driver = {
  23. .description = hcd_name,
  24. .product_desc = "LOONGSON1 EHCI",
  25. .hcd_priv_size = sizeof(struct ehci_hcd),
  26. /*
  27. * generic hardware linkage
  28. */
  29. .irq = ehci_irq,
  30. .flags = HCD_MEMORY | HCD_USB2,
  31. /*
  32. * basic lifecycle operations
  33. */
  34. .reset = ehci_ls1x_reset,
  35. .start = ehci_run,
  36. .stop = ehci_stop,
  37. .shutdown = ehci_shutdown,
  38. /*
  39. * managing i/o requests and associated device resources
  40. */
  41. .urb_enqueue = ehci_urb_enqueue,
  42. .urb_dequeue = ehci_urb_dequeue,
  43. .endpoint_disable = ehci_endpoint_disable,
  44. .endpoint_reset = ehci_endpoint_reset,
  45. /*
  46. * scheduling support
  47. */
  48. .get_frame_number = ehci_get_frame,
  49. /*
  50. * root hub support
  51. */
  52. .hub_status_data = ehci_hub_status_data,
  53. .hub_control = ehci_hub_control,
  54. .relinquish_port = ehci_relinquish_port,
  55. .port_handed_over = ehci_port_handed_over,
  56. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  57. };
  58. static int ehci_hcd_ls1x_probe(struct platform_device *pdev)
  59. {
  60. struct usb_hcd *hcd;
  61. struct resource *res;
  62. int irq;
  63. int ret;
  64. pr_debug("initializing loongson1 ehci USB Controller\n");
  65. if (usb_disabled())
  66. return -ENODEV;
  67. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  68. if (!res) {
  69. dev_err(&pdev->dev,
  70. "Found HC with no IRQ. Check %s setup!\n",
  71. dev_name(&pdev->dev));
  72. return -ENODEV;
  73. }
  74. irq = res->start;
  75. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  76. if (!res) {
  77. dev_err(&pdev->dev,
  78. "Found HC with no register addr. Check %s setup!\n",
  79. dev_name(&pdev->dev));
  80. return -ENODEV;
  81. }
  82. hcd = usb_create_hcd(&ehci_ls1x_hc_driver, &pdev->dev,
  83. dev_name(&pdev->dev));
  84. if (!hcd)
  85. return -ENOMEM;
  86. hcd->rsrc_start = res->start;
  87. hcd->rsrc_len = resource_size(res);
  88. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  89. dev_dbg(&pdev->dev, "controller already in use\n");
  90. ret = -EBUSY;
  91. goto err_put_hcd;
  92. }
  93. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  94. if (hcd->regs == NULL) {
  95. dev_dbg(&pdev->dev, "error mapping memory\n");
  96. ret = -EFAULT;
  97. goto err_release_region;
  98. }
  99. ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
  100. if (ret)
  101. goto err_iounmap;
  102. return ret;
  103. err_iounmap:
  104. iounmap(hcd->regs);
  105. err_release_region:
  106. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  107. err_put_hcd:
  108. usb_put_hcd(hcd);
  109. return ret;
  110. }
  111. static int ehci_hcd_ls1x_remove(struct platform_device *pdev)
  112. {
  113. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  114. usb_remove_hcd(hcd);
  115. iounmap(hcd->regs);
  116. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  117. usb_put_hcd(hcd);
  118. return 0;
  119. }
  120. static struct platform_driver ehci_ls1x_driver = {
  121. .probe = ehci_hcd_ls1x_probe,
  122. .remove = ehci_hcd_ls1x_remove,
  123. .shutdown = usb_hcd_platform_shutdown,
  124. .driver = {
  125. .name = "ls1x-ehci",
  126. .owner = THIS_MODULE,
  127. },
  128. };
  129. MODULE_ALIAS(PLATFORM_MODULE_PREFIX "ls1x-ehci");