ehci-sh.c 4.0 KB

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