ehci-sh.c 5.3 KB

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