ehci-sh.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  107. driver->description)) {
  108. dev_dbg(&pdev->dev, "controller already in use\n");
  109. ret = -EBUSY;
  110. goto fail_request_resource;
  111. }
  112. hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
  113. if (hcd->regs == NULL) {
  114. dev_dbg(&pdev->dev, "error mapping memory\n");
  115. ret = -ENXIO;
  116. goto fail_ioremap;
  117. }
  118. priv = kmalloc(sizeof(struct ehci_sh_priv), GFP_KERNEL);
  119. if (!priv) {
  120. dev_dbg(&pdev->dev, "error allocating priv data\n");
  121. ret = -ENOMEM;
  122. goto fail_alloc;
  123. }
  124. /* These are optional, we don't care if they fail */
  125. priv->fclk = clk_get(&pdev->dev, "usb_fck");
  126. if (IS_ERR(priv->fclk))
  127. priv->fclk = NULL;
  128. priv->iclk = clk_get(&pdev->dev, "usb_ick");
  129. if (IS_ERR(priv->iclk))
  130. priv->iclk = NULL;
  131. clk_enable(priv->fclk);
  132. clk_enable(priv->iclk);
  133. if (pdata && pdata->phy_init)
  134. pdata->phy_init();
  135. ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
  136. if (ret != 0) {
  137. dev_err(&pdev->dev, "Failed to add hcd");
  138. goto fail_add_hcd;
  139. }
  140. priv->hcd = hcd;
  141. platform_set_drvdata(pdev, priv);
  142. return ret;
  143. fail_add_hcd:
  144. clk_disable(priv->iclk);
  145. clk_disable(priv->fclk);
  146. clk_put(priv->iclk);
  147. clk_put(priv->fclk);
  148. kfree(priv);
  149. fail_alloc:
  150. iounmap(hcd->regs);
  151. fail_ioremap:
  152. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  153. fail_request_resource:
  154. usb_put_hcd(hcd);
  155. fail_create_hcd:
  156. dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret);
  157. return ret;
  158. }
  159. static int __exit ehci_hcd_sh_remove(struct platform_device *pdev)
  160. {
  161. struct ehci_sh_priv *priv = platform_get_drvdata(pdev);
  162. struct usb_hcd *hcd = priv->hcd;
  163. usb_remove_hcd(hcd);
  164. iounmap(hcd->regs);
  165. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  166. usb_put_hcd(hcd);
  167. platform_set_drvdata(pdev, NULL);
  168. clk_disable(priv->fclk);
  169. clk_disable(priv->iclk);
  170. clk_put(priv->fclk);
  171. clk_put(priv->iclk);
  172. kfree(priv);
  173. return 0;
  174. }
  175. static void ehci_hcd_sh_shutdown(struct platform_device *pdev)
  176. {
  177. struct ehci_sh_priv *priv = platform_get_drvdata(pdev);
  178. struct usb_hcd *hcd = priv->hcd;
  179. if (hcd->driver->shutdown)
  180. hcd->driver->shutdown(hcd);
  181. }
  182. static struct platform_driver ehci_hcd_sh_driver = {
  183. .probe = ehci_hcd_sh_probe,
  184. .remove = __exit_p(ehci_hcd_sh_remove),
  185. .shutdown = ehci_hcd_sh_shutdown,
  186. .driver = {
  187. .name = "sh_ehci",
  188. .owner = THIS_MODULE,
  189. },
  190. };
  191. MODULE_ALIAS("platform:sh_ehci");