ehci-sh.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * SuperH EHCI host controller driver
  3. *
  4. * Copyright (C) 2010 Paul Mundt
  5. *
  6. * Based on ohci-sh.c and ehci-atmel.c.
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/platform_device.h>
  13. #include <linux/clk.h>
  14. #include <linux/platform_data/ehci-sh.h>
  15. struct ehci_sh_priv {
  16. struct clk *iclk, *fclk;
  17. struct usb_hcd *hcd;
  18. };
  19. static int ehci_sh_reset(struct usb_hcd *hcd)
  20. {
  21. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  22. ehci->caps = hcd->regs;
  23. return ehci_setup(hcd);
  24. }
  25. static const struct hc_driver ehci_sh_hc_driver = {
  26. .description = hcd_name,
  27. .product_desc = "SuperH EHCI",
  28. .hcd_priv_size = sizeof(struct ehci_hcd),
  29. /*
  30. * generic hardware linkage
  31. */
  32. .irq = ehci_irq,
  33. .flags = HCD_USB2 | HCD_MEMORY,
  34. /*
  35. * basic lifecycle operations
  36. */
  37. .reset = ehci_sh_reset,
  38. .start = ehci_run,
  39. .stop = ehci_stop,
  40. .shutdown = ehci_shutdown,
  41. /*
  42. * managing i/o requests and associated device resources
  43. */
  44. .urb_enqueue = ehci_urb_enqueue,
  45. .urb_dequeue = ehci_urb_dequeue,
  46. .endpoint_disable = ehci_endpoint_disable,
  47. .endpoint_reset = ehci_endpoint_reset,
  48. /*
  49. * scheduling support
  50. */
  51. .get_frame_number = ehci_get_frame,
  52. /*
  53. * root hub support
  54. */
  55. .hub_status_data = ehci_hub_status_data,
  56. .hub_control = ehci_hub_control,
  57. #ifdef CONFIG_PM
  58. .bus_suspend = ehci_bus_suspend,
  59. .bus_resume = ehci_bus_resume,
  60. #endif
  61. .relinquish_port = ehci_relinquish_port,
  62. .port_handed_over = ehci_port_handed_over,
  63. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  64. };
  65. static int ehci_hcd_sh_probe(struct platform_device *pdev)
  66. {
  67. struct resource *res;
  68. struct ehci_sh_priv *priv;
  69. struct ehci_sh_platdata *pdata;
  70. struct usb_hcd *hcd;
  71. int irq, ret;
  72. if (usb_disabled())
  73. return -ENODEV;
  74. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  75. if (!res) {
  76. dev_err(&pdev->dev,
  77. "Found HC with no register addr. Check %s setup!\n",
  78. dev_name(&pdev->dev));
  79. ret = -ENODEV;
  80. goto fail_create_hcd;
  81. }
  82. irq = platform_get_irq(pdev, 0);
  83. if (irq <= 0) {
  84. dev_err(&pdev->dev,
  85. "Found HC with no IRQ. Check %s setup!\n",
  86. dev_name(&pdev->dev));
  87. ret = -ENODEV;
  88. goto fail_create_hcd;
  89. }
  90. pdata = pdev->dev.platform_data;
  91. /* initialize hcd */
  92. hcd = usb_create_hcd(&ehci_sh_hc_driver, &pdev->dev,
  93. dev_name(&pdev->dev));
  94. if (!hcd) {
  95. ret = -ENOMEM;
  96. goto fail_create_hcd;
  97. }
  98. hcd->rsrc_start = res->start;
  99. hcd->rsrc_len = resource_size(res);
  100. hcd->regs = devm_ioremap_resource(&pdev->dev, res);
  101. if (IS_ERR(hcd->regs)) {
  102. ret = PTR_ERR(hcd->regs);
  103. goto fail_request_resource;
  104. }
  105. priv = devm_kzalloc(&pdev->dev, sizeof(struct ehci_sh_priv),
  106. GFP_KERNEL);
  107. if (!priv) {
  108. dev_dbg(&pdev->dev, "error allocating priv data\n");
  109. ret = -ENOMEM;
  110. goto fail_request_resource;
  111. }
  112. /* These are optional, we don't care if they fail */
  113. priv->fclk = devm_clk_get(&pdev->dev, "usb_fck");
  114. if (IS_ERR(priv->fclk))
  115. priv->fclk = NULL;
  116. priv->iclk = devm_clk_get(&pdev->dev, "usb_ick");
  117. if (IS_ERR(priv->iclk))
  118. priv->iclk = NULL;
  119. clk_enable(priv->fclk);
  120. clk_enable(priv->iclk);
  121. if (pdata && pdata->phy_init)
  122. pdata->phy_init();
  123. ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
  124. if (ret != 0) {
  125. dev_err(&pdev->dev, "Failed to add hcd");
  126. goto fail_add_hcd;
  127. }
  128. priv->hcd = hcd;
  129. platform_set_drvdata(pdev, priv);
  130. return ret;
  131. fail_add_hcd:
  132. clk_disable(priv->iclk);
  133. clk_disable(priv->fclk);
  134. fail_request_resource:
  135. usb_put_hcd(hcd);
  136. fail_create_hcd:
  137. dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret);
  138. return ret;
  139. }
  140. static int ehci_hcd_sh_remove(struct platform_device *pdev)
  141. {
  142. struct ehci_sh_priv *priv = platform_get_drvdata(pdev);
  143. struct usb_hcd *hcd = priv->hcd;
  144. usb_remove_hcd(hcd);
  145. usb_put_hcd(hcd);
  146. clk_disable(priv->fclk);
  147. clk_disable(priv->iclk);
  148. return 0;
  149. }
  150. static void ehci_hcd_sh_shutdown(struct platform_device *pdev)
  151. {
  152. struct ehci_sh_priv *priv = platform_get_drvdata(pdev);
  153. struct usb_hcd *hcd = priv->hcd;
  154. if (hcd->driver->shutdown)
  155. hcd->driver->shutdown(hcd);
  156. }
  157. static struct platform_driver ehci_hcd_sh_driver = {
  158. .probe = ehci_hcd_sh_probe,
  159. .remove = ehci_hcd_sh_remove,
  160. .shutdown = ehci_hcd_sh_shutdown,
  161. .driver = {
  162. .name = "sh_ehci",
  163. .owner = THIS_MODULE,
  164. },
  165. };
  166. MODULE_ALIAS("platform:sh_ehci");