ehci-s5p.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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/platform_device.h>
  16. #include <plat/ehci.h>
  17. #include <plat/usb-phy.h>
  18. #define EHCI_INSNREG00(base) (base + 0x90)
  19. #define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25)
  20. #define EHCI_INSNREG00_ENA_INCR8 (0x1 << 24)
  21. #define EHCI_INSNREG00_ENA_INCR4 (0x1 << 23)
  22. #define EHCI_INSNREG00_ENA_INCRX_ALIGN (0x1 << 22)
  23. #define EHCI_INSNREG00_ENABLE_DMA_BURST \
  24. (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \
  25. EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN)
  26. struct s5p_ehci_hcd {
  27. struct device *dev;
  28. struct usb_hcd *hcd;
  29. struct clk *clk;
  30. };
  31. static const struct hc_driver s5p_ehci_hc_driver = {
  32. .description = hcd_name,
  33. .product_desc = "S5P EHCI Host Controller",
  34. .hcd_priv_size = sizeof(struct ehci_hcd),
  35. .irq = ehci_irq,
  36. .flags = HCD_MEMORY | HCD_USB2,
  37. .reset = ehci_setup,
  38. .start = ehci_run,
  39. .stop = ehci_stop,
  40. .shutdown = ehci_shutdown,
  41. .get_frame_number = ehci_get_frame,
  42. .urb_enqueue = ehci_urb_enqueue,
  43. .urb_dequeue = ehci_urb_dequeue,
  44. .endpoint_disable = ehci_endpoint_disable,
  45. .endpoint_reset = ehci_endpoint_reset,
  46. .hub_status_data = ehci_hub_status_data,
  47. .hub_control = ehci_hub_control,
  48. .bus_suspend = ehci_bus_suspend,
  49. .bus_resume = ehci_bus_resume,
  50. .relinquish_port = ehci_relinquish_port,
  51. .port_handed_over = ehci_port_handed_over,
  52. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  53. };
  54. static int __devinit s5p_ehci_probe(struct platform_device *pdev)
  55. {
  56. struct s5p_ehci_platdata *pdata;
  57. struct s5p_ehci_hcd *s5p_ehci;
  58. struct usb_hcd *hcd;
  59. struct ehci_hcd *ehci;
  60. struct resource *res;
  61. int irq;
  62. int err;
  63. pdata = pdev->dev.platform_data;
  64. if (!pdata) {
  65. dev_err(&pdev->dev, "No platform data defined\n");
  66. return -EINVAL;
  67. }
  68. s5p_ehci = devm_kzalloc(&pdev->dev, sizeof(struct s5p_ehci_hcd),
  69. GFP_KERNEL);
  70. if (!s5p_ehci)
  71. return -ENOMEM;
  72. s5p_ehci->dev = &pdev->dev;
  73. hcd = usb_create_hcd(&s5p_ehci_hc_driver, &pdev->dev,
  74. dev_name(&pdev->dev));
  75. if (!hcd) {
  76. dev_err(&pdev->dev, "Unable to create HCD\n");
  77. return -ENOMEM;
  78. }
  79. s5p_ehci->hcd = hcd;
  80. s5p_ehci->clk = clk_get(&pdev->dev, "usbhost");
  81. if (IS_ERR(s5p_ehci->clk)) {
  82. dev_err(&pdev->dev, "Failed to get usbhost clock\n");
  83. err = PTR_ERR(s5p_ehci->clk);
  84. goto fail_clk;
  85. }
  86. err = clk_enable(s5p_ehci->clk);
  87. if (err)
  88. goto fail_clken;
  89. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  90. if (!res) {
  91. dev_err(&pdev->dev, "Failed to get I/O memory\n");
  92. err = -ENXIO;
  93. goto fail_io;
  94. }
  95. hcd->rsrc_start = res->start;
  96. hcd->rsrc_len = resource_size(res);
  97. hcd->regs = devm_ioremap(&pdev->dev, res->start, hcd->rsrc_len);
  98. if (!hcd->regs) {
  99. dev_err(&pdev->dev, "Failed to remap I/O memory\n");
  100. err = -ENOMEM;
  101. goto fail_io;
  102. }
  103. irq = platform_get_irq(pdev, 0);
  104. if (!irq) {
  105. dev_err(&pdev->dev, "Failed to get IRQ\n");
  106. err = -ENODEV;
  107. goto fail_io;
  108. }
  109. if (pdata->phy_init)
  110. pdata->phy_init(pdev, S5P_USB_PHY_HOST);
  111. ehci = hcd_to_ehci(hcd);
  112. ehci->caps = hcd->regs;
  113. /* DMA burst Enable */
  114. writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
  115. err = usb_add_hcd(hcd, irq, IRQF_SHARED);
  116. if (err) {
  117. dev_err(&pdev->dev, "Failed to add USB HCD\n");
  118. goto fail_io;
  119. }
  120. platform_set_drvdata(pdev, s5p_ehci);
  121. return 0;
  122. fail_io:
  123. clk_disable(s5p_ehci->clk);
  124. fail_clken:
  125. clk_put(s5p_ehci->clk);
  126. fail_clk:
  127. usb_put_hcd(hcd);
  128. return err;
  129. }
  130. static int __devexit s5p_ehci_remove(struct platform_device *pdev)
  131. {
  132. struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
  133. struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
  134. struct usb_hcd *hcd = s5p_ehci->hcd;
  135. usb_remove_hcd(hcd);
  136. if (pdata && pdata->phy_exit)
  137. pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
  138. clk_disable(s5p_ehci->clk);
  139. clk_put(s5p_ehci->clk);
  140. usb_put_hcd(hcd);
  141. return 0;
  142. }
  143. static void s5p_ehci_shutdown(struct platform_device *pdev)
  144. {
  145. struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
  146. struct usb_hcd *hcd = s5p_ehci->hcd;
  147. if (hcd->driver->shutdown)
  148. hcd->driver->shutdown(hcd);
  149. }
  150. #ifdef CONFIG_PM
  151. static int s5p_ehci_suspend(struct device *dev)
  152. {
  153. struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
  154. struct usb_hcd *hcd = s5p_ehci->hcd;
  155. bool do_wakeup = device_may_wakeup(dev);
  156. struct platform_device *pdev = to_platform_device(dev);
  157. struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
  158. int rc;
  159. rc = ehci_suspend(hcd, do_wakeup);
  160. if (pdata && pdata->phy_exit)
  161. pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
  162. clk_disable(s5p_ehci->clk);
  163. return rc;
  164. }
  165. static int s5p_ehci_resume(struct device *dev)
  166. {
  167. struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
  168. struct usb_hcd *hcd = s5p_ehci->hcd;
  169. struct platform_device *pdev = to_platform_device(dev);
  170. struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
  171. clk_enable(s5p_ehci->clk);
  172. if (pdata && pdata->phy_init)
  173. pdata->phy_init(pdev, S5P_USB_PHY_HOST);
  174. /* DMA burst Enable */
  175. writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
  176. ehci_resume(hcd, false);
  177. return 0;
  178. }
  179. #else
  180. #define s5p_ehci_suspend NULL
  181. #define s5p_ehci_resume NULL
  182. #endif
  183. static const struct dev_pm_ops s5p_ehci_pm_ops = {
  184. .suspend = s5p_ehci_suspend,
  185. .resume = s5p_ehci_resume,
  186. };
  187. static struct platform_driver s5p_ehci_driver = {
  188. .probe = s5p_ehci_probe,
  189. .remove = __devexit_p(s5p_ehci_remove),
  190. .shutdown = s5p_ehci_shutdown,
  191. .driver = {
  192. .name = "s5p-ehci",
  193. .owner = THIS_MODULE,
  194. .pm = &s5p_ehci_pm_ops,
  195. }
  196. };
  197. MODULE_ALIAS("platform:s5p-ehci");