lpasscc-sc7280.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/clk-provider.h>
  6. #include <linux/platform_device.h>
  7. #include <linux/pm_clock.h>
  8. #include <linux/pm_runtime.h>
  9. #include <linux/module.h>
  10. #include <linux/of_address.h>
  11. #include <linux/regmap.h>
  12. #include <dt-bindings/clock/qcom,lpass-sc7280.h>
  13. #include "clk-regmap.h"
  14. #include "clk-branch.h"
  15. #include "common.h"
  16. static struct clk_branch lpass_top_cc_lpi_q6_axim_hs_clk = {
  17. .halt_reg = 0x0,
  18. .halt_check = BRANCH_HALT,
  19. .clkr = {
  20. .enable_reg = 0x0,
  21. .enable_mask = BIT(0),
  22. .hw.init = &(struct clk_init_data){
  23. .name = "lpass_top_cc_lpi_q6_axim_hs_clk",
  24. .ops = &clk_branch2_ops,
  25. },
  26. },
  27. };
  28. static struct clk_branch lpass_qdsp6ss_core_clk = {
  29. .halt_reg = 0x20,
  30. /* CLK_OFF would not toggle until LPASS is out of reset */
  31. .halt_check = BRANCH_HALT_SKIP,
  32. .clkr = {
  33. .enable_reg = 0x20,
  34. .enable_mask = BIT(0),
  35. .hw.init = &(struct clk_init_data){
  36. .name = "lpass_qdsp6ss_core_clk",
  37. .ops = &clk_branch2_ops,
  38. },
  39. },
  40. };
  41. static struct clk_branch lpass_qdsp6ss_xo_clk = {
  42. .halt_reg = 0x38,
  43. /* CLK_OFF would not toggle until LPASS is out of reset */
  44. .halt_check = BRANCH_HALT_SKIP,
  45. .clkr = {
  46. .enable_reg = 0x38,
  47. .enable_mask = BIT(0),
  48. .hw.init = &(struct clk_init_data){
  49. .name = "lpass_qdsp6ss_xo_clk",
  50. .ops = &clk_branch2_ops,
  51. },
  52. },
  53. };
  54. static struct clk_branch lpass_qdsp6ss_sleep_clk = {
  55. .halt_reg = 0x3c,
  56. /* CLK_OFF would not toggle until LPASS is out of reset */
  57. .halt_check = BRANCH_HALT_SKIP,
  58. .clkr = {
  59. .enable_reg = 0x3c,
  60. .enable_mask = BIT(0),
  61. .hw.init = &(struct clk_init_data){
  62. .name = "lpass_qdsp6ss_sleep_clk",
  63. .ops = &clk_branch2_ops,
  64. },
  65. },
  66. };
  67. static struct regmap_config lpass_regmap_config = {
  68. .reg_bits = 32,
  69. .reg_stride = 4,
  70. .val_bits = 32,
  71. .fast_io = true,
  72. };
  73. static struct clk_regmap *lpass_cc_top_sc7280_clocks[] = {
  74. [LPASS_TOP_CC_LPI_Q6_AXIM_HS_CLK] =
  75. &lpass_top_cc_lpi_q6_axim_hs_clk.clkr,
  76. };
  77. static const struct qcom_cc_desc lpass_cc_top_sc7280_desc = {
  78. .config = &lpass_regmap_config,
  79. .clks = lpass_cc_top_sc7280_clocks,
  80. .num_clks = ARRAY_SIZE(lpass_cc_top_sc7280_clocks),
  81. };
  82. static struct clk_regmap *lpass_qdsp6ss_sc7280_clocks[] = {
  83. [LPASS_QDSP6SS_XO_CLK] = &lpass_qdsp6ss_xo_clk.clkr,
  84. [LPASS_QDSP6SS_SLEEP_CLK] = &lpass_qdsp6ss_sleep_clk.clkr,
  85. [LPASS_QDSP6SS_CORE_CLK] = &lpass_qdsp6ss_core_clk.clkr,
  86. };
  87. static const struct qcom_cc_desc lpass_qdsp6ss_sc7280_desc = {
  88. .config = &lpass_regmap_config,
  89. .clks = lpass_qdsp6ss_sc7280_clocks,
  90. .num_clks = ARRAY_SIZE(lpass_qdsp6ss_sc7280_clocks),
  91. };
  92. static int lpass_cc_sc7280_probe(struct platform_device *pdev)
  93. {
  94. const struct qcom_cc_desc *desc;
  95. int ret;
  96. pm_runtime_enable(&pdev->dev);
  97. ret = pm_clk_create(&pdev->dev);
  98. if (ret)
  99. goto disable_pm_runtime;
  100. ret = pm_clk_add(&pdev->dev, "iface");
  101. if (ret < 0) {
  102. dev_err(&pdev->dev, "failed to acquire iface clock\n");
  103. goto err_destroy_pm_clk;
  104. }
  105. ret = pm_runtime_resume_and_get(&pdev->dev);
  106. if (ret)
  107. goto err_destroy_pm_clk;
  108. if (!of_property_read_bool(pdev->dev.of_node, "qcom,adsp-pil-mode")) {
  109. lpass_regmap_config.name = "qdsp6ss";
  110. lpass_regmap_config.max_register = 0x3f;
  111. desc = &lpass_qdsp6ss_sc7280_desc;
  112. ret = qcom_cc_probe_by_index(pdev, 0, desc);
  113. if (ret)
  114. goto err_put_rpm;
  115. }
  116. lpass_regmap_config.name = "top_cc";
  117. lpass_regmap_config.max_register = 0x4;
  118. desc = &lpass_cc_top_sc7280_desc;
  119. ret = qcom_cc_probe_by_index(pdev, 1, desc);
  120. if (ret)
  121. goto err_put_rpm;
  122. pm_runtime_put(&pdev->dev);
  123. return 0;
  124. err_put_rpm:
  125. pm_runtime_put_sync(&pdev->dev);
  126. err_destroy_pm_clk:
  127. pm_clk_destroy(&pdev->dev);
  128. disable_pm_runtime:
  129. pm_runtime_disable(&pdev->dev);
  130. return ret;
  131. }
  132. static const struct of_device_id lpass_cc_sc7280_match_table[] = {
  133. { .compatible = "qcom,sc7280-lpasscc" },
  134. { }
  135. };
  136. MODULE_DEVICE_TABLE(of, lpass_cc_sc7280_match_table);
  137. static struct platform_driver lpass_cc_sc7280_driver = {
  138. .probe = lpass_cc_sc7280_probe,
  139. .driver = {
  140. .name = "sc7280-lpasscc",
  141. .of_match_table = lpass_cc_sc7280_match_table,
  142. },
  143. };
  144. static int __init lpass_cc_sc7280_init(void)
  145. {
  146. return platform_driver_register(&lpass_cc_sc7280_driver);
  147. }
  148. subsys_initcall(lpass_cc_sc7280_init);
  149. static void __exit lpass_cc_sc7280_exit(void)
  150. {
  151. platform_driver_unregister(&lpass_cc_sc7280_driver);
  152. }
  153. module_exit(lpass_cc_sc7280_exit);
  154. MODULE_DESCRIPTION("QTI LPASS_CC SC7280 Driver");
  155. MODULE_LICENSE("GPL v2");