ehci-sh.c 4.5 KB

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