dwc3-exynos.c 7.1 KB

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