ehci-sh.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * SuperH EHCI host controller driver
  4. *
  5. * Copyright (C) 2010 Paul Mundt
  6. *
  7. * Based on ohci-sh.c and ehci-atmel.c.
  8. */
  9. #include <linux/platform_device.h>
  10. #include <linux/clk.h>
  11. struct ehci_sh_priv {
  12. struct clk *iclk, *fclk;
  13. struct usb_hcd *hcd;
  14. };
  15. static int ehci_sh_reset(struct usb_hcd *hcd)
  16. {
  17. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  18. ehci->caps = hcd->regs;
  19. return ehci_setup(hcd);
  20. }
  21. static const struct hc_driver ehci_sh_hc_driver = {
  22. .description = hcd_name,
  23. .product_desc = "SuperH EHCI",
  24. .hcd_priv_size = sizeof(struct ehci_hcd),
  25. /*
  26. * generic hardware linkage
  27. */
  28. .irq = ehci_irq,
  29. .flags = HCD_USB2 | HCD_DMA | HCD_MEMORY | HCD_BH,
  30. /*
  31. * basic lifecycle operations
  32. */
  33. .reset = ehci_sh_reset,
  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. #ifdef CONFIG_PM
  54. .bus_suspend = ehci_bus_suspend,
  55. .bus_resume = ehci_bus_resume,
  56. #endif
  57. .relinquish_port = ehci_relinquish_port,
  58. .port_handed_over = ehci_port_handed_over,
  59. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  60. };
  61. static int ehci_hcd_sh_probe(struct platform_device *pdev)
  62. {
  63. struct resource *res;
  64. struct ehci_sh_priv *priv;
  65. struct usb_hcd *hcd;
  66. int irq, ret;
  67. if (usb_disabled())
  68. return -ENODEV;
  69. irq = platform_get_irq(pdev, 0);
  70. if (irq <= 0) {
  71. ret = -ENODEV;
  72. goto fail_create_hcd;
  73. }
  74. /* initialize hcd */
  75. hcd = usb_create_hcd(&ehci_sh_hc_driver, &pdev->dev,
  76. dev_name(&pdev->dev));
  77. if (!hcd) {
  78. ret = -ENOMEM;
  79. goto fail_create_hcd;
  80. }
  81. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  82. hcd->regs = devm_ioremap_resource(&pdev->dev, res);
  83. if (IS_ERR(hcd->regs)) {
  84. ret = PTR_ERR(hcd->regs);
  85. goto fail_request_resource;
  86. }
  87. hcd->rsrc_start = res->start;
  88. hcd->rsrc_len = resource_size(res);
  89. priv = devm_kzalloc(&pdev->dev, sizeof(struct ehci_sh_priv),
  90. GFP_KERNEL);
  91. if (!priv) {
  92. ret = -ENOMEM;
  93. goto fail_request_resource;
  94. }
  95. /* These are optional, we don't care if they fail */
  96. priv->fclk = devm_clk_get(&pdev->dev, "usb_fck");
  97. if (IS_ERR(priv->fclk))
  98. priv->fclk = NULL;
  99. priv->iclk = devm_clk_get(&pdev->dev, "usb_ick");
  100. if (IS_ERR(priv->iclk))
  101. priv->iclk = NULL;
  102. clk_enable(priv->fclk);
  103. clk_enable(priv->iclk);
  104. ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
  105. if (ret != 0) {
  106. dev_err(&pdev->dev, "Failed to add hcd");
  107. goto fail_add_hcd;
  108. }
  109. device_wakeup_enable(hcd->self.controller);
  110. priv->hcd = hcd;
  111. platform_set_drvdata(pdev, priv);
  112. return ret;
  113. fail_add_hcd:
  114. clk_disable(priv->iclk);
  115. clk_disable(priv->fclk);
  116. fail_request_resource:
  117. usb_put_hcd(hcd);
  118. fail_create_hcd:
  119. dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret);
  120. return ret;
  121. }
  122. static int ehci_hcd_sh_remove(struct platform_device *pdev)
  123. {
  124. struct ehci_sh_priv *priv = platform_get_drvdata(pdev);
  125. struct usb_hcd *hcd = priv->hcd;
  126. usb_remove_hcd(hcd);
  127. usb_put_hcd(hcd);
  128. clk_disable(priv->fclk);
  129. clk_disable(priv->iclk);
  130. return 0;
  131. }
  132. static void ehci_hcd_sh_shutdown(struct platform_device *pdev)
  133. {
  134. struct ehci_sh_priv *priv = platform_get_drvdata(pdev);
  135. struct usb_hcd *hcd = priv->hcd;
  136. if (hcd->driver->shutdown)
  137. hcd->driver->shutdown(hcd);
  138. }
  139. static struct platform_driver ehci_hcd_sh_driver = {
  140. .probe = ehci_hcd_sh_probe,
  141. .remove = ehci_hcd_sh_remove,
  142. .shutdown = ehci_hcd_sh_shutdown,
  143. .driver = {
  144. .name = "sh_ehci",
  145. },
  146. };
  147. MODULE_ALIAS("platform:sh_ehci");