ehci-ls1x.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
  89. if (hcd->regs == NULL) {
  90. dev_dbg(&pdev->dev, "error mapping memory\n");
  91. ret = -EFAULT;
  92. goto err_put_hcd;
  93. }
  94. ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
  95. if (ret)
  96. goto err_put_hcd;
  97. return ret;
  98. err_put_hcd:
  99. usb_put_hcd(hcd);
  100. return ret;
  101. }
  102. static int ehci_hcd_ls1x_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. return 0;
  108. }
  109. static struct platform_driver ehci_ls1x_driver = {
  110. .probe = ehci_hcd_ls1x_probe,
  111. .remove = ehci_hcd_ls1x_remove,
  112. .shutdown = usb_hcd_platform_shutdown,
  113. .driver = {
  114. .name = "ls1x-ehci",
  115. .owner = THIS_MODULE,
  116. },
  117. };
  118. MODULE_ALIAS(PLATFORM_MODULE_PREFIX "ls1x-ehci");