ehci-s5p.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * SAMSUNG S5P USB HOST EHCI Controller
  3. *
  4. * Copyright (C) 2011 Samsung Electronics Co.Ltd
  5. * Author: Jingoo Han <jg1.han@samsung.com>
  6. * Author: Joonyoung Shim <jy0922.shim@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. */
  14. #include <linux/clk.h>
  15. #include <linux/of.h>
  16. #include <linux/platform_device.h>
  17. #include <plat/ehci.h>
  18. #include <plat/usb-phy.h>
  19. #define EHCI_INSNREG00(base) (base + 0x90)
  20. #define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25)
  21. #define EHCI_INSNREG00_ENA_INCR8 (0x1 << 24)
  22. #define EHCI_INSNREG00_ENA_INCR4 (0x1 << 23)
  23. #define EHCI_INSNREG00_ENA_INCRX_ALIGN (0x1 << 22)
  24. #define EHCI_INSNREG00_ENABLE_DMA_BURST \
  25. (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \
  26. EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN)
  27. struct s5p_ehci_hcd {
  28. struct device *dev;
  29. struct usb_hcd *hcd;
  30. struct clk *clk;
  31. };
  32. static const struct hc_driver s5p_ehci_hc_driver = {
  33. .description = hcd_name,
  34. .product_desc = "S5P EHCI Host Controller",
  35. .hcd_priv_size = sizeof(struct ehci_hcd),
  36. .irq = ehci_irq,
  37. .flags = HCD_MEMORY | HCD_USB2,
  38. .reset = ehci_setup,
  39. .start = ehci_run,
  40. .stop = ehci_stop,
  41. .shutdown = ehci_shutdown,
  42. .get_frame_number = ehci_get_frame,
  43. .urb_enqueue = ehci_urb_enqueue,
  44. .urb_dequeue = ehci_urb_dequeue,
  45. .endpoint_disable = ehci_endpoint_disable,
  46. .endpoint_reset = ehci_endpoint_reset,
  47. .hub_status_data = ehci_hub_status_data,
  48. .hub_control = ehci_hub_control,
  49. .bus_suspend = ehci_bus_suspend,
  50. .bus_resume = ehci_bus_resume,
  51. .relinquish_port = ehci_relinquish_port,
  52. .port_handed_over = ehci_port_handed_over,
  53. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  54. };
  55. static u64 ehci_s5p_dma_mask = DMA_BIT_MASK(32);
  56. static int __devinit s5p_ehci_probe(struct platform_device *pdev)
  57. {
  58. struct s5p_ehci_platdata *pdata;
  59. struct s5p_ehci_hcd *s5p_ehci;
  60. struct usb_hcd *hcd;
  61. struct ehci_hcd *ehci;
  62. struct resource *res;
  63. int irq;
  64. int err;
  65. pdata = pdev->dev.platform_data;
  66. if (!pdata) {
  67. dev_err(&pdev->dev, "No platform data defined\n");
  68. return -EINVAL;
  69. }
  70. /*
  71. * Right now device-tree probed devices don't get dma_mask set.
  72. * Since shared usb code relies on it, set it here for now.
  73. * Once we move to full device tree support this will vanish off.
  74. */
  75. if (!pdev->dev.dma_mask)
  76. pdev->dev.dma_mask = &ehci_s5p_dma_mask;
  77. if (!pdev->dev.coherent_dma_mask)
  78. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  79. s5p_ehci = devm_kzalloc(&pdev->dev, sizeof(struct s5p_ehci_hcd),
  80. GFP_KERNEL);
  81. if (!s5p_ehci)
  82. return -ENOMEM;
  83. s5p_ehci->dev = &pdev->dev;
  84. hcd = usb_create_hcd(&s5p_ehci_hc_driver, &pdev->dev,
  85. dev_name(&pdev->dev));
  86. if (!hcd) {
  87. dev_err(&pdev->dev, "Unable to create HCD\n");
  88. return -ENOMEM;
  89. }
  90. s5p_ehci->hcd = hcd;
  91. s5p_ehci->clk = clk_get(&pdev->dev, "usbhost");
  92. if (IS_ERR(s5p_ehci->clk)) {
  93. dev_err(&pdev->dev, "Failed to get usbhost clock\n");
  94. err = PTR_ERR(s5p_ehci->clk);
  95. goto fail_clk;
  96. }
  97. err = clk_enable(s5p_ehci->clk);
  98. if (err)
  99. goto fail_clken;
  100. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  101. if (!res) {
  102. dev_err(&pdev->dev, "Failed to get I/O memory\n");
  103. err = -ENXIO;
  104. goto fail_io;
  105. }
  106. hcd->rsrc_start = res->start;
  107. hcd->rsrc_len = resource_size(res);
  108. hcd->regs = devm_ioremap(&pdev->dev, res->start, hcd->rsrc_len);
  109. if (!hcd->regs) {
  110. dev_err(&pdev->dev, "Failed to remap I/O memory\n");
  111. err = -ENOMEM;
  112. goto fail_io;
  113. }
  114. irq = platform_get_irq(pdev, 0);
  115. if (!irq) {
  116. dev_err(&pdev->dev, "Failed to get IRQ\n");
  117. err = -ENODEV;
  118. goto fail_io;
  119. }
  120. if (pdata->phy_init)
  121. pdata->phy_init(pdev, S5P_USB_PHY_HOST);
  122. ehci = hcd_to_ehci(hcd);
  123. ehci->caps = hcd->regs;
  124. /* DMA burst Enable */
  125. writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
  126. err = usb_add_hcd(hcd, irq, IRQF_SHARED);
  127. if (err) {
  128. dev_err(&pdev->dev, "Failed to add USB HCD\n");
  129. goto fail_io;
  130. }
  131. platform_set_drvdata(pdev, s5p_ehci);
  132. return 0;
  133. fail_io:
  134. clk_disable(s5p_ehci->clk);
  135. fail_clken:
  136. clk_put(s5p_ehci->clk);
  137. fail_clk:
  138. usb_put_hcd(hcd);
  139. return err;
  140. }
  141. static int __devexit s5p_ehci_remove(struct platform_device *pdev)
  142. {
  143. struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
  144. struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
  145. struct usb_hcd *hcd = s5p_ehci->hcd;
  146. usb_remove_hcd(hcd);
  147. if (pdata && pdata->phy_exit)
  148. pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
  149. clk_disable(s5p_ehci->clk);
  150. clk_put(s5p_ehci->clk);
  151. usb_put_hcd(hcd);
  152. return 0;
  153. }
  154. static void s5p_ehci_shutdown(struct platform_device *pdev)
  155. {
  156. struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
  157. struct usb_hcd *hcd = s5p_ehci->hcd;
  158. if (hcd->driver->shutdown)
  159. hcd->driver->shutdown(hcd);
  160. }
  161. #ifdef CONFIG_PM
  162. static int s5p_ehci_suspend(struct device *dev)
  163. {
  164. struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
  165. struct usb_hcd *hcd = s5p_ehci->hcd;
  166. bool do_wakeup = device_may_wakeup(dev);
  167. struct platform_device *pdev = to_platform_device(dev);
  168. struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
  169. int rc;
  170. rc = ehci_suspend(hcd, do_wakeup);
  171. if (pdata && pdata->phy_exit)
  172. pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
  173. clk_disable(s5p_ehci->clk);
  174. return rc;
  175. }
  176. static int s5p_ehci_resume(struct device *dev)
  177. {
  178. struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
  179. struct usb_hcd *hcd = s5p_ehci->hcd;
  180. struct platform_device *pdev = to_platform_device(dev);
  181. struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
  182. clk_enable(s5p_ehci->clk);
  183. if (pdata && pdata->phy_init)
  184. pdata->phy_init(pdev, S5P_USB_PHY_HOST);
  185. /* DMA burst Enable */
  186. writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
  187. ehci_resume(hcd, false);
  188. return 0;
  189. }
  190. #else
  191. #define s5p_ehci_suspend NULL
  192. #define s5p_ehci_resume NULL
  193. #endif
  194. static const struct dev_pm_ops s5p_ehci_pm_ops = {
  195. .suspend = s5p_ehci_suspend,
  196. .resume = s5p_ehci_resume,
  197. };
  198. #ifdef CONFIG_OF
  199. static const struct of_device_id exynos_ehci_match[] = {
  200. { .compatible = "samsung,exynos-ehci" },
  201. {},
  202. };
  203. MODULE_DEVICE_TABLE(of, exynos_ehci_match);
  204. #endif
  205. static struct platform_driver s5p_ehci_driver = {
  206. .probe = s5p_ehci_probe,
  207. .remove = __devexit_p(s5p_ehci_remove),
  208. .shutdown = s5p_ehci_shutdown,
  209. .driver = {
  210. .name = "s5p-ehci",
  211. .owner = THIS_MODULE,
  212. .pm = &s5p_ehci_pm_ops,
  213. .of_match_table = of_match_ptr(exynos_ehci_match),
  214. }
  215. };
  216. MODULE_ALIAS("platform:s5p-ehci");