dwc3-qcom.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/clk.h>
  13. #include <linux/err.h>
  14. #include <linux/io.h>
  15. #include <linux/module.h>
  16. #include <linux/of.h>
  17. #include <linux/of_platform.h>
  18. #include <linux/platform_device.h>
  19. struct dwc3_qcom {
  20. struct device *dev;
  21. struct clk *core_clk;
  22. struct clk *iface_clk;
  23. struct clk *sleep_clk;
  24. };
  25. static int dwc3_qcom_probe(struct platform_device *pdev)
  26. {
  27. struct device_node *node = pdev->dev.of_node;
  28. struct dwc3_qcom *qdwc;
  29. int ret;
  30. qdwc = devm_kzalloc(&pdev->dev, sizeof(*qdwc), GFP_KERNEL);
  31. if (!qdwc)
  32. return -ENOMEM;
  33. platform_set_drvdata(pdev, qdwc);
  34. qdwc->dev = &pdev->dev;
  35. qdwc->core_clk = devm_clk_get(qdwc->dev, "core");
  36. if (IS_ERR(qdwc->core_clk)) {
  37. dev_err(qdwc->dev, "failed to get core clock\n");
  38. return PTR_ERR(qdwc->core_clk);
  39. }
  40. qdwc->iface_clk = devm_clk_get(qdwc->dev, "iface");
  41. if (IS_ERR(qdwc->iface_clk)) {
  42. dev_info(qdwc->dev, "failed to get optional iface clock\n");
  43. qdwc->iface_clk = NULL;
  44. }
  45. qdwc->sleep_clk = devm_clk_get(qdwc->dev, "sleep");
  46. if (IS_ERR(qdwc->sleep_clk)) {
  47. dev_info(qdwc->dev, "failed to get optional sleep clock\n");
  48. qdwc->sleep_clk = NULL;
  49. }
  50. ret = clk_prepare_enable(qdwc->core_clk);
  51. if (ret) {
  52. dev_err(qdwc->dev, "failed to enable core clock\n");
  53. goto err_core;
  54. }
  55. ret = clk_prepare_enable(qdwc->iface_clk);
  56. if (ret) {
  57. dev_err(qdwc->dev, "failed to enable optional iface clock\n");
  58. goto err_iface;
  59. }
  60. ret = clk_prepare_enable(qdwc->sleep_clk);
  61. if (ret) {
  62. dev_err(qdwc->dev, "failed to enable optional sleep clock\n");
  63. goto err_sleep;
  64. }
  65. ret = of_platform_populate(node, NULL, NULL, qdwc->dev);
  66. if (ret) {
  67. dev_err(qdwc->dev, "failed to register core - %d\n", ret);
  68. goto err_clks;
  69. }
  70. return 0;
  71. err_clks:
  72. clk_disable_unprepare(qdwc->sleep_clk);
  73. err_sleep:
  74. clk_disable_unprepare(qdwc->iface_clk);
  75. err_iface:
  76. clk_disable_unprepare(qdwc->core_clk);
  77. err_core:
  78. return ret;
  79. }
  80. static int dwc3_qcom_remove(struct platform_device *pdev)
  81. {
  82. struct dwc3_qcom *qdwc = platform_get_drvdata(pdev);
  83. of_platform_depopulate(&pdev->dev);
  84. clk_disable_unprepare(qdwc->sleep_clk);
  85. clk_disable_unprepare(qdwc->iface_clk);
  86. clk_disable_unprepare(qdwc->core_clk);
  87. return 0;
  88. }
  89. static const struct of_device_id of_dwc3_match[] = {
  90. { .compatible = "qcom,dwc3" },
  91. { /* Sentinel */ }
  92. };
  93. MODULE_DEVICE_TABLE(of, of_dwc3_match);
  94. static struct platform_driver dwc3_qcom_driver = {
  95. .probe = dwc3_qcom_probe,
  96. .remove = dwc3_qcom_remove,
  97. .driver = {
  98. .name = "qcom-dwc3",
  99. .of_match_table = of_dwc3_match,
  100. },
  101. };
  102. module_platform_driver(dwc3_qcom_driver);
  103. MODULE_ALIAS("platform:qcom-dwc3");
  104. MODULE_LICENSE("GPL v2");
  105. MODULE_DESCRIPTION("DesignWare USB3 QCOM Glue Layer");
  106. MODULE_AUTHOR("Ivan T. Ivanov <iivanov@mm-sol.com>");