ohci-exynos.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * SAMSUNG EXYNOS USB HOST OHCI Controller
  3. *
  4. * Copyright (C) 2011 Samsung Electronics Co.Ltd
  5. * Author: Jingoo Han <jg1.han@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/platform_device.h>
  15. #include <mach/ohci.h>
  16. #include <plat/usb-phy.h>
  17. struct exynos_ohci_hcd {
  18. struct device *dev;
  19. struct usb_hcd *hcd;
  20. struct clk *clk;
  21. };
  22. static int ohci_exynos_start(struct usb_hcd *hcd)
  23. {
  24. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  25. int ret;
  26. ohci_dbg(ohci, "ohci_exynos_start, ohci:%p", ohci);
  27. ret = ohci_init(ohci);
  28. if (ret < 0)
  29. return ret;
  30. ret = ohci_run(ohci);
  31. if (ret < 0) {
  32. dev_err(hcd->self.controller, "can't start %s\n",
  33. hcd->self.bus_name);
  34. ohci_stop(hcd);
  35. return ret;
  36. }
  37. return 0;
  38. }
  39. static const struct hc_driver exynos_ohci_hc_driver = {
  40. .description = hcd_name,
  41. .product_desc = "EXYNOS OHCI Host Controller",
  42. .hcd_priv_size = sizeof(struct ohci_hcd),
  43. .irq = ohci_irq,
  44. .flags = HCD_MEMORY|HCD_USB11,
  45. .start = ohci_exynos_start,
  46. .stop = ohci_stop,
  47. .shutdown = ohci_shutdown,
  48. .get_frame_number = ohci_get_frame,
  49. .urb_enqueue = ohci_urb_enqueue,
  50. .urb_dequeue = ohci_urb_dequeue,
  51. .endpoint_disable = ohci_endpoint_disable,
  52. .hub_status_data = ohci_hub_status_data,
  53. .hub_control = ohci_hub_control,
  54. #ifdef CONFIG_PM
  55. .bus_suspend = ohci_bus_suspend,
  56. .bus_resume = ohci_bus_resume,
  57. #endif
  58. .start_port_reset = ohci_start_port_reset,
  59. };
  60. static int __devinit exynos_ohci_probe(struct platform_device *pdev)
  61. {
  62. struct exynos4_ohci_platdata *pdata;
  63. struct exynos_ohci_hcd *exynos_ohci;
  64. struct usb_hcd *hcd;
  65. struct ohci_hcd *ohci;
  66. struct resource *res;
  67. int irq;
  68. int err;
  69. pdata = pdev->dev.platform_data;
  70. if (!pdata) {
  71. dev_err(&pdev->dev, "No platform data defined\n");
  72. return -EINVAL;
  73. }
  74. exynos_ohci = kzalloc(sizeof(struct exynos_ohci_hcd), GFP_KERNEL);
  75. if (!exynos_ohci)
  76. return -ENOMEM;
  77. exynos_ohci->dev = &pdev->dev;
  78. hcd = usb_create_hcd(&exynos_ohci_hc_driver, &pdev->dev,
  79. dev_name(&pdev->dev));
  80. if (!hcd) {
  81. dev_err(&pdev->dev, "Unable to create HCD\n");
  82. err = -ENOMEM;
  83. goto fail_hcd;
  84. }
  85. exynos_ohci->hcd = hcd;
  86. exynos_ohci->clk = clk_get(&pdev->dev, "usbhost");
  87. if (IS_ERR(exynos_ohci->clk)) {
  88. dev_err(&pdev->dev, "Failed to get usbhost clock\n");
  89. err = PTR_ERR(exynos_ohci->clk);
  90. goto fail_clk;
  91. }
  92. err = clk_enable(exynos_ohci->clk);
  93. if (err)
  94. goto fail_clken;
  95. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  96. if (!res) {
  97. dev_err(&pdev->dev, "Failed to get I/O memory\n");
  98. err = -ENXIO;
  99. goto fail_io;
  100. }
  101. hcd->rsrc_start = res->start;
  102. hcd->rsrc_len = resource_size(res);
  103. hcd->regs = ioremap(res->start, resource_size(res));
  104. if (!hcd->regs) {
  105. dev_err(&pdev->dev, "Failed to remap I/O memory\n");
  106. err = -ENOMEM;
  107. goto fail_io;
  108. }
  109. irq = platform_get_irq(pdev, 0);
  110. if (!irq) {
  111. dev_err(&pdev->dev, "Failed to get IRQ\n");
  112. err = -ENODEV;
  113. goto fail;
  114. }
  115. if (pdata->phy_init)
  116. pdata->phy_init(pdev, S5P_USB_PHY_HOST);
  117. ohci = hcd_to_ohci(hcd);
  118. ohci_hcd_init(ohci);
  119. err = usb_add_hcd(hcd, irq, IRQF_SHARED);
  120. if (err) {
  121. dev_err(&pdev->dev, "Failed to add USB HCD\n");
  122. goto fail;
  123. }
  124. platform_set_drvdata(pdev, exynos_ohci);
  125. return 0;
  126. fail:
  127. iounmap(hcd->regs);
  128. fail_io:
  129. clk_disable(exynos_ohci->clk);
  130. fail_clken:
  131. clk_put(exynos_ohci->clk);
  132. fail_clk:
  133. usb_put_hcd(hcd);
  134. fail_hcd:
  135. kfree(exynos_ohci);
  136. return err;
  137. }
  138. static int __devexit exynos_ohci_remove(struct platform_device *pdev)
  139. {
  140. struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data;
  141. struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev);
  142. struct usb_hcd *hcd = exynos_ohci->hcd;
  143. usb_remove_hcd(hcd);
  144. if (pdata && pdata->phy_exit)
  145. pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
  146. iounmap(hcd->regs);
  147. clk_disable(exynos_ohci->clk);
  148. clk_put(exynos_ohci->clk);
  149. usb_put_hcd(hcd);
  150. kfree(exynos_ohci);
  151. return 0;
  152. }
  153. static void exynos_ohci_shutdown(struct platform_device *pdev)
  154. {
  155. struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev);
  156. struct usb_hcd *hcd = exynos_ohci->hcd;
  157. if (hcd->driver->shutdown)
  158. hcd->driver->shutdown(hcd);
  159. }
  160. #ifdef CONFIG_PM
  161. static int exynos_ohci_suspend(struct device *dev)
  162. {
  163. struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev);
  164. struct usb_hcd *hcd = exynos_ohci->hcd;
  165. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  166. struct platform_device *pdev = to_platform_device(dev);
  167. struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data;
  168. unsigned long flags;
  169. int rc = 0;
  170. /*
  171. * Root hub was already suspended. Disable irq emission and
  172. * mark HW unaccessible, bail out if RH has been resumed. Use
  173. * the spinlock to properly synchronize with possible pending
  174. * RH suspend or resume activity.
  175. */
  176. spin_lock_irqsave(&ohci->lock, flags);
  177. if (ohci->rh_state != OHCI_RH_SUSPENDED &&
  178. ohci->rh_state != OHCI_RH_HALTED) {
  179. rc = -EINVAL;
  180. goto fail;
  181. }
  182. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  183. if (pdata && pdata->phy_exit)
  184. pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
  185. fail:
  186. spin_unlock_irqrestore(&ohci->lock, flags);
  187. return rc;
  188. }
  189. static int exynos_ohci_resume(struct device *dev)
  190. {
  191. struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev);
  192. struct usb_hcd *hcd = exynos_ohci->hcd;
  193. struct platform_device *pdev = to_platform_device(dev);
  194. struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data;
  195. if (pdata && pdata->phy_init)
  196. pdata->phy_init(pdev, S5P_USB_PHY_HOST);
  197. /* Mark hardware accessible again as we are out of D3 state by now */
  198. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  199. ohci_finish_controller_resume(hcd);
  200. return 0;
  201. }
  202. #else
  203. #define exynos_ohci_suspend NULL
  204. #define exynos_ohci_resume NULL
  205. #endif
  206. static const struct dev_pm_ops exynos_ohci_pm_ops = {
  207. .suspend = exynos_ohci_suspend,
  208. .resume = exynos_ohci_resume,
  209. };
  210. static struct platform_driver exynos_ohci_driver = {
  211. .probe = exynos_ohci_probe,
  212. .remove = __devexit_p(exynos_ohci_remove),
  213. .shutdown = exynos_ohci_shutdown,
  214. .driver = {
  215. .name = "exynos-ohci",
  216. .owner = THIS_MODULE,
  217. .pm = &exynos_ohci_pm_ops,
  218. }
  219. };
  220. MODULE_ALIAS("platform:exynos-ohci");
  221. MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");