dwc3-exynos.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /**
  2. * dwc3-exynos.c - Samsung EXYNOS DWC3 Specific Glue layer
  3. *
  4. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com
  6. *
  7. * Author: Anton Tikhomirov <av.tikhomirov@samsung.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/slab.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/platform_data/dwc3-exynos.h>
  19. #include <linux/dma-mapping.h>
  20. #include <linux/clk.h>
  21. #include <linux/usb/otg.h>
  22. #include <linux/usb/nop-usb-xceiv.h>
  23. #include <linux/of.h>
  24. #include <linux/of_platform.h>
  25. struct dwc3_exynos {
  26. struct platform_device *usb2_phy;
  27. struct platform_device *usb3_phy;
  28. struct device *dev;
  29. struct clk *clk;
  30. };
  31. static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
  32. {
  33. struct nop_usb_xceiv_platform_data pdata;
  34. struct platform_device *pdev;
  35. int ret;
  36. memset(&pdata, 0x00, sizeof(pdata));
  37. pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
  38. if (!pdev)
  39. return -ENOMEM;
  40. exynos->usb2_phy = pdev;
  41. pdata.type = USB_PHY_TYPE_USB2;
  42. ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata));
  43. if (ret)
  44. goto err1;
  45. pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
  46. if (!pdev) {
  47. ret = -ENOMEM;
  48. goto err1;
  49. }
  50. exynos->usb3_phy = pdev;
  51. pdata.type = USB_PHY_TYPE_USB3;
  52. ret = platform_device_add_data(exynos->usb3_phy, &pdata, sizeof(pdata));
  53. if (ret)
  54. goto err2;
  55. ret = platform_device_add(exynos->usb2_phy);
  56. if (ret)
  57. goto err2;
  58. ret = platform_device_add(exynos->usb3_phy);
  59. if (ret)
  60. goto err3;
  61. return 0;
  62. err3:
  63. platform_device_del(exynos->usb2_phy);
  64. err2:
  65. platform_device_put(exynos->usb3_phy);
  66. err1:
  67. platform_device_put(exynos->usb2_phy);
  68. return ret;
  69. }
  70. static int dwc3_exynos_remove_child(struct device *dev, void *unused)
  71. {
  72. struct platform_device *pdev = to_platform_device(dev);
  73. platform_device_unregister(pdev);
  74. return 0;
  75. }
  76. static int dwc3_exynos_probe(struct platform_device *pdev)
  77. {
  78. struct dwc3_exynos *exynos;
  79. struct clk *clk;
  80. struct device *dev = &pdev->dev;
  81. struct device_node *node = dev->of_node;
  82. int ret = -ENOMEM;
  83. exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
  84. if (!exynos) {
  85. dev_err(dev, "not enough memory\n");
  86. goto err1;
  87. }
  88. /*
  89. * Right now device-tree probed devices don't get dma_mask set.
  90. * Since shared usb code relies on it, set it here for now.
  91. * Once we move to full device tree support this will vanish off.
  92. */
  93. if (!dev->dma_mask)
  94. dev->dma_mask = &dev->coherent_dma_mask;
  95. if (!dev->coherent_dma_mask)
  96. dev->coherent_dma_mask = DMA_BIT_MASK(32);
  97. platform_set_drvdata(pdev, exynos);
  98. ret = dwc3_exynos_register_phys(exynos);
  99. if (ret) {
  100. dev_err(dev, "couldn't register PHYs\n");
  101. goto err1;
  102. }
  103. clk = devm_clk_get(dev, "usbdrd30");
  104. if (IS_ERR(clk)) {
  105. dev_err(dev, "couldn't get clock\n");
  106. ret = -EINVAL;
  107. goto err1;
  108. }
  109. exynos->dev = dev;
  110. exynos->clk = clk;
  111. clk_prepare_enable(exynos->clk);
  112. if (node) {
  113. ret = of_platform_populate(node, NULL, NULL, dev);
  114. if (ret) {
  115. dev_err(dev, "failed to add dwc3 core\n");
  116. goto err2;
  117. }
  118. } else {
  119. dev_err(dev, "no device node, failed to add dwc3 core\n");
  120. ret = -ENODEV;
  121. goto err2;
  122. }
  123. return 0;
  124. err2:
  125. clk_disable_unprepare(clk);
  126. err1:
  127. return ret;
  128. }
  129. static int dwc3_exynos_remove(struct platform_device *pdev)
  130. {
  131. struct dwc3_exynos *exynos = platform_get_drvdata(pdev);
  132. device_for_each_child(&pdev->dev, NULL, dwc3_exynos_remove_child);
  133. platform_device_unregister(exynos->usb2_phy);
  134. platform_device_unregister(exynos->usb3_phy);
  135. clk_disable_unprepare(exynos->clk);
  136. return 0;
  137. }
  138. #ifdef CONFIG_OF
  139. static const struct of_device_id exynos_dwc3_match[] = {
  140. { .compatible = "samsung,exynos5250-dwusb3" },
  141. {},
  142. };
  143. MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
  144. #endif
  145. #ifdef CONFIG_PM_SLEEP
  146. static int dwc3_exynos_suspend(struct device *dev)
  147. {
  148. struct dwc3_exynos *exynos = dev_get_drvdata(dev);
  149. clk_disable(exynos->clk);
  150. return 0;
  151. }
  152. static int dwc3_exynos_resume(struct device *dev)
  153. {
  154. struct dwc3_exynos *exynos = dev_get_drvdata(dev);
  155. clk_enable(exynos->clk);
  156. /* runtime set active to reflect active state. */
  157. pm_runtime_disable(dev);
  158. pm_runtime_set_active(dev);
  159. pm_runtime_enable(dev);
  160. return 0;
  161. }
  162. static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = {
  163. SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume)
  164. };
  165. #define DEV_PM_OPS (&dwc3_exynos_dev_pm_ops)
  166. #else
  167. #define DEV_PM_OPS NULL
  168. #endif /* CONFIG_PM_SLEEP */
  169. static struct platform_driver dwc3_exynos_driver = {
  170. .probe = dwc3_exynos_probe,
  171. .remove = dwc3_exynos_remove,
  172. .driver = {
  173. .name = "exynos-dwc3",
  174. .of_match_table = of_match_ptr(exynos_dwc3_match),
  175. .pm = DEV_PM_OPS,
  176. },
  177. };
  178. module_platform_driver(dwc3_exynos_driver);
  179. MODULE_ALIAS("platform:exynos-dwc3");
  180. MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
  181. MODULE_LICENSE("GPL");
  182. MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");