dwc3-exynos.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 version 2 of
  11. * the License as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/module.h>
  19. #include <linux/kernel.h>
  20. #include <linux/slab.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/clk.h>
  23. #include <linux/usb/otg.h>
  24. #include <linux/usb/usb_phy_generic.h>
  25. #include <linux/of.h>
  26. #include <linux/of_platform.h>
  27. #include <linux/regulator/consumer.h>
  28. struct dwc3_exynos {
  29. struct platform_device *usb2_phy;
  30. struct platform_device *usb3_phy;
  31. struct device *dev;
  32. struct clk *clk;
  33. struct clk *susp_clk;
  34. struct clk *axius_clk;
  35. struct regulator *vdd33;
  36. struct regulator *vdd10;
  37. };
  38. static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
  39. {
  40. struct usb_phy_generic_platform_data pdata;
  41. struct platform_device *pdev;
  42. int ret;
  43. memset(&pdata, 0x00, sizeof(pdata));
  44. pdev = platform_device_alloc("usb_phy_generic", PLATFORM_DEVID_AUTO);
  45. if (!pdev)
  46. return -ENOMEM;
  47. exynos->usb2_phy = pdev;
  48. pdata.type = USB_PHY_TYPE_USB2;
  49. pdata.gpio_reset = -1;
  50. ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata));
  51. if (ret)
  52. goto err1;
  53. pdev = platform_device_alloc("usb_phy_generic", PLATFORM_DEVID_AUTO);
  54. if (!pdev) {
  55. ret = -ENOMEM;
  56. goto err1;
  57. }
  58. exynos->usb3_phy = pdev;
  59. pdata.type = USB_PHY_TYPE_USB3;
  60. ret = platform_device_add_data(exynos->usb3_phy, &pdata, sizeof(pdata));
  61. if (ret)
  62. goto err2;
  63. ret = platform_device_add(exynos->usb2_phy);
  64. if (ret)
  65. goto err2;
  66. ret = platform_device_add(exynos->usb3_phy);
  67. if (ret)
  68. goto err3;
  69. return 0;
  70. err3:
  71. platform_device_del(exynos->usb2_phy);
  72. err2:
  73. platform_device_put(exynos->usb3_phy);
  74. err1:
  75. platform_device_put(exynos->usb2_phy);
  76. return ret;
  77. }
  78. static int dwc3_exynos_remove_child(struct device *dev, void *unused)
  79. {
  80. struct platform_device *pdev = to_platform_device(dev);
  81. platform_device_unregister(pdev);
  82. return 0;
  83. }
  84. static int dwc3_exynos_probe(struct platform_device *pdev)
  85. {
  86. struct dwc3_exynos *exynos;
  87. struct device *dev = &pdev->dev;
  88. struct device_node *node = dev->of_node;
  89. int ret;
  90. exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
  91. if (!exynos)
  92. return -ENOMEM;
  93. platform_set_drvdata(pdev, exynos);
  94. exynos->dev = dev;
  95. exynos->clk = devm_clk_get(dev, "usbdrd30");
  96. if (IS_ERR(exynos->clk)) {
  97. dev_err(dev, "couldn't get clock\n");
  98. return -EINVAL;
  99. }
  100. clk_prepare_enable(exynos->clk);
  101. exynos->susp_clk = devm_clk_get(dev, "usbdrd30_susp_clk");
  102. if (IS_ERR(exynos->susp_clk)) {
  103. dev_info(dev, "no suspend clk specified\n");
  104. exynos->susp_clk = NULL;
  105. }
  106. clk_prepare_enable(exynos->susp_clk);
  107. if (of_device_is_compatible(node, "samsung,exynos7-dwusb3")) {
  108. exynos->axius_clk = devm_clk_get(dev, "usbdrd30_axius_clk");
  109. if (IS_ERR(exynos->axius_clk)) {
  110. dev_err(dev, "no AXI UpScaler clk specified\n");
  111. ret = -ENODEV;
  112. goto axius_clk_err;
  113. }
  114. clk_prepare_enable(exynos->axius_clk);
  115. } else {
  116. exynos->axius_clk = NULL;
  117. }
  118. exynos->vdd33 = devm_regulator_get(dev, "vdd33");
  119. if (IS_ERR(exynos->vdd33)) {
  120. ret = PTR_ERR(exynos->vdd33);
  121. goto err2;
  122. }
  123. ret = regulator_enable(exynos->vdd33);
  124. if (ret) {
  125. dev_err(dev, "Failed to enable VDD33 supply\n");
  126. goto err2;
  127. }
  128. exynos->vdd10 = devm_regulator_get(dev, "vdd10");
  129. if (IS_ERR(exynos->vdd10)) {
  130. ret = PTR_ERR(exynos->vdd10);
  131. goto err3;
  132. }
  133. ret = regulator_enable(exynos->vdd10);
  134. if (ret) {
  135. dev_err(dev, "Failed to enable VDD10 supply\n");
  136. goto err3;
  137. }
  138. ret = dwc3_exynos_register_phys(exynos);
  139. if (ret) {
  140. dev_err(dev, "couldn't register PHYs\n");
  141. goto err4;
  142. }
  143. if (node) {
  144. ret = of_platform_populate(node, NULL, NULL, dev);
  145. if (ret) {
  146. dev_err(dev, "failed to add dwc3 core\n");
  147. goto err5;
  148. }
  149. } else {
  150. dev_err(dev, "no device node, failed to add dwc3 core\n");
  151. ret = -ENODEV;
  152. goto err5;
  153. }
  154. return 0;
  155. err5:
  156. platform_device_unregister(exynos->usb2_phy);
  157. platform_device_unregister(exynos->usb3_phy);
  158. err4:
  159. regulator_disable(exynos->vdd10);
  160. err3:
  161. regulator_disable(exynos->vdd33);
  162. err2:
  163. clk_disable_unprepare(exynos->axius_clk);
  164. axius_clk_err:
  165. clk_disable_unprepare(exynos->susp_clk);
  166. clk_disable_unprepare(exynos->clk);
  167. return ret;
  168. }
  169. static int dwc3_exynos_remove(struct platform_device *pdev)
  170. {
  171. struct dwc3_exynos *exynos = platform_get_drvdata(pdev);
  172. device_for_each_child(&pdev->dev, NULL, dwc3_exynos_remove_child);
  173. platform_device_unregister(exynos->usb2_phy);
  174. platform_device_unregister(exynos->usb3_phy);
  175. clk_disable_unprepare(exynos->axius_clk);
  176. clk_disable_unprepare(exynos->susp_clk);
  177. clk_disable_unprepare(exynos->clk);
  178. regulator_disable(exynos->vdd33);
  179. regulator_disable(exynos->vdd10);
  180. return 0;
  181. }
  182. static const struct of_device_id exynos_dwc3_match[] = {
  183. { .compatible = "samsung,exynos5250-dwusb3" },
  184. { .compatible = "samsung,exynos7-dwusb3" },
  185. {},
  186. };
  187. MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
  188. #ifdef CONFIG_PM_SLEEP
  189. static int dwc3_exynos_suspend(struct device *dev)
  190. {
  191. struct dwc3_exynos *exynos = dev_get_drvdata(dev);
  192. clk_disable(exynos->axius_clk);
  193. clk_disable(exynos->clk);
  194. regulator_disable(exynos->vdd33);
  195. regulator_disable(exynos->vdd10);
  196. return 0;
  197. }
  198. static int dwc3_exynos_resume(struct device *dev)
  199. {
  200. struct dwc3_exynos *exynos = dev_get_drvdata(dev);
  201. int ret;
  202. ret = regulator_enable(exynos->vdd33);
  203. if (ret) {
  204. dev_err(dev, "Failed to enable VDD33 supply\n");
  205. return ret;
  206. }
  207. ret = regulator_enable(exynos->vdd10);
  208. if (ret) {
  209. dev_err(dev, "Failed to enable VDD10 supply\n");
  210. return ret;
  211. }
  212. clk_enable(exynos->clk);
  213. clk_enable(exynos->axius_clk);
  214. /* runtime set active to reflect active state. */
  215. pm_runtime_disable(dev);
  216. pm_runtime_set_active(dev);
  217. pm_runtime_enable(dev);
  218. return 0;
  219. }
  220. static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = {
  221. SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume)
  222. };
  223. #define DEV_PM_OPS (&dwc3_exynos_dev_pm_ops)
  224. #else
  225. #define DEV_PM_OPS NULL
  226. #endif /* CONFIG_PM_SLEEP */
  227. static struct platform_driver dwc3_exynos_driver = {
  228. .probe = dwc3_exynos_probe,
  229. .remove = dwc3_exynos_remove,
  230. .driver = {
  231. .name = "exynos-dwc3",
  232. .of_match_table = exynos_dwc3_match,
  233. .pm = DEV_PM_OPS,
  234. },
  235. };
  236. module_platform_driver(dwc3_exynos_driver);
  237. MODULE_ALIAS("platform:exynos-dwc3");
  238. MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
  239. MODULE_LICENSE("GPL v2");
  240. MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");