ehci-sh.c 5.1 KB

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