ohci-exynos.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 = devm_kzalloc(&pdev->dev, sizeof(struct exynos_ohci_hcd),
  75. GFP_KERNEL);
  76. if (!exynos_ohci)
  77. return -ENOMEM;
  78. exynos_ohci->dev = &pdev->dev;
  79. hcd = usb_create_hcd(&exynos_ohci_hc_driver, &pdev->dev,
  80. dev_name(&pdev->dev));
  81. if (!hcd) {
  82. dev_err(&pdev->dev, "Unable to create HCD\n");
  83. return -ENOMEM;
  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 = devm_ioremap(&pdev->dev, res->start, hcd->rsrc_len);
  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_io;
  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_io;
  123. }
  124. platform_set_drvdata(pdev, exynos_ohci);
  125. return 0;
  126. fail_io:
  127. clk_disable(exynos_ohci->clk);
  128. fail_clken:
  129. clk_put(exynos_ohci->clk);
  130. fail_clk:
  131. usb_put_hcd(hcd);
  132. return err;
  133. }
  134. static int __devexit exynos_ohci_remove(struct platform_device *pdev)
  135. {
  136. struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data;
  137. struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev);
  138. struct usb_hcd *hcd = exynos_ohci->hcd;
  139. usb_remove_hcd(hcd);
  140. if (pdata && pdata->phy_exit)
  141. pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
  142. clk_disable(exynos_ohci->clk);
  143. clk_put(exynos_ohci->clk);
  144. usb_put_hcd(hcd);
  145. return 0;
  146. }
  147. static void exynos_ohci_shutdown(struct platform_device *pdev)
  148. {
  149. struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev);
  150. struct usb_hcd *hcd = exynos_ohci->hcd;
  151. if (hcd->driver->shutdown)
  152. hcd->driver->shutdown(hcd);
  153. }
  154. #ifdef CONFIG_PM
  155. static int exynos_ohci_suspend(struct device *dev)
  156. {
  157. struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev);
  158. struct usb_hcd *hcd = exynos_ohci->hcd;
  159. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  160. struct platform_device *pdev = to_platform_device(dev);
  161. struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data;
  162. unsigned long flags;
  163. int rc = 0;
  164. /*
  165. * Root hub was already suspended. Disable irq emission and
  166. * mark HW unaccessible, bail out if RH has been resumed. Use
  167. * the spinlock to properly synchronize with possible pending
  168. * RH suspend or resume activity.
  169. */
  170. spin_lock_irqsave(&ohci->lock, flags);
  171. if (ohci->rh_state != OHCI_RH_SUSPENDED &&
  172. ohci->rh_state != OHCI_RH_HALTED) {
  173. rc = -EINVAL;
  174. goto fail;
  175. }
  176. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  177. if (pdata && pdata->phy_exit)
  178. pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
  179. clk_disable(exynos_ohci->clk);
  180. fail:
  181. spin_unlock_irqrestore(&ohci->lock, flags);
  182. return rc;
  183. }
  184. static int exynos_ohci_resume(struct device *dev)
  185. {
  186. struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev);
  187. struct usb_hcd *hcd = exynos_ohci->hcd;
  188. struct platform_device *pdev = to_platform_device(dev);
  189. struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data;
  190. clk_enable(exynos_ohci->clk);
  191. if (pdata && pdata->phy_init)
  192. pdata->phy_init(pdev, S5P_USB_PHY_HOST);
  193. /* Mark hardware accessible again as we are out of D3 state by now */
  194. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  195. ohci_finish_controller_resume(hcd);
  196. return 0;
  197. }
  198. #else
  199. #define exynos_ohci_suspend NULL
  200. #define exynos_ohci_resume NULL
  201. #endif
  202. static const struct dev_pm_ops exynos_ohci_pm_ops = {
  203. .suspend = exynos_ohci_suspend,
  204. .resume = exynos_ohci_resume,
  205. };
  206. static struct platform_driver exynos_ohci_driver = {
  207. .probe = exynos_ohci_probe,
  208. .remove = __devexit_p(exynos_ohci_remove),
  209. .shutdown = exynos_ohci_shutdown,
  210. .driver = {
  211. .name = "exynos-ohci",
  212. .owner = THIS_MODULE,
  213. .pm = &exynos_ohci_pm_ops,
  214. }
  215. };
  216. MODULE_ALIAS("platform:exynos-ohci");
  217. MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");