ehci-sh.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. const struct hc_driver *driver = &ehci_sh_hc_driver;
  68. struct resource *res;
  69. struct ehci_sh_priv *priv;
  70. struct ehci_sh_platdata *pdata;
  71. struct usb_hcd *hcd;
  72. int irq, ret;
  73. if (usb_disabled())
  74. return -ENODEV;
  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. ret = -ENODEV;
  81. goto fail_create_hcd;
  82. }
  83. irq = platform_get_irq(pdev, 0);
  84. if (irq <= 0) {
  85. dev_err(&pdev->dev,
  86. "Found HC with no IRQ. Check %s setup!\n",
  87. dev_name(&pdev->dev));
  88. ret = -ENODEV;
  89. goto fail_create_hcd;
  90. }
  91. pdata = pdev->dev.platform_data;
  92. /* initialize hcd */
  93. hcd = usb_create_hcd(&ehci_sh_hc_driver, &pdev->dev,
  94. dev_name(&pdev->dev));
  95. if (!hcd) {
  96. ret = -ENOMEM;
  97. goto fail_create_hcd;
  98. }
  99. hcd->rsrc_start = res->start;
  100. hcd->rsrc_len = resource_size(res);
  101. hcd->regs = devm_ioremap_resource(&pdev->dev, res);
  102. if (IS_ERR(hcd->regs)) {
  103. ret = PTR_ERR(hcd->regs);
  104. goto fail_request_resource;
  105. }
  106. priv = devm_kzalloc(&pdev->dev, sizeof(struct ehci_sh_priv),
  107. GFP_KERNEL);
  108. if (!priv) {
  109. dev_dbg(&pdev->dev, "error allocating priv data\n");
  110. ret = -ENOMEM;
  111. goto fail_request_resource;
  112. }
  113. /* These are optional, we don't care if they fail */
  114. priv->fclk = devm_clk_get(&pdev->dev, "usb_fck");
  115. if (IS_ERR(priv->fclk))
  116. priv->fclk = NULL;
  117. priv->iclk = devm_clk_get(&pdev->dev, "usb_ick");
  118. if (IS_ERR(priv->iclk))
  119. priv->iclk = NULL;
  120. clk_enable(priv->fclk);
  121. clk_enable(priv->iclk);
  122. if (pdata && pdata->phy_init)
  123. pdata->phy_init();
  124. ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
  125. if (ret != 0) {
  126. dev_err(&pdev->dev, "Failed to add hcd");
  127. goto fail_add_hcd;
  128. }
  129. priv->hcd = hcd;
  130. platform_set_drvdata(pdev, priv);
  131. return ret;
  132. fail_add_hcd:
  133. clk_disable(priv->iclk);
  134. clk_disable(priv->fclk);
  135. fail_request_resource:
  136. usb_put_hcd(hcd);
  137. fail_create_hcd:
  138. dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret);
  139. return ret;
  140. }
  141. static int __exit ehci_hcd_sh_remove(struct platform_device *pdev)
  142. {
  143. struct ehci_sh_priv *priv = platform_get_drvdata(pdev);
  144. struct usb_hcd *hcd = priv->hcd;
  145. usb_remove_hcd(hcd);
  146. usb_put_hcd(hcd);
  147. platform_set_drvdata(pdev, NULL);
  148. clk_disable(priv->fclk);
  149. clk_disable(priv->iclk);
  150. return 0;
  151. }
  152. static void ehci_hcd_sh_shutdown(struct platform_device *pdev)
  153. {
  154. struct ehci_sh_priv *priv = platform_get_drvdata(pdev);
  155. struct usb_hcd *hcd = priv->hcd;
  156. if (hcd->driver->shutdown)
  157. hcd->driver->shutdown(hcd);
  158. }
  159. static struct platform_driver ehci_hcd_sh_driver = {
  160. .probe = ehci_hcd_sh_probe,
  161. .remove = __exit_p(ehci_hcd_sh_remove),
  162. .shutdown = ehci_hcd_sh_shutdown,
  163. .driver = {
  164. .name = "sh_ehci",
  165. .owner = THIS_MODULE,
  166. },
  167. };
  168. MODULE_ALIAS("platform:sh_ehci");