ehci-sh.c 5.3 KB

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