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