apss-ipq6018.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/err.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/clk-provider.h>
  9. #include <linux/regmap.h>
  10. #include <linux/module.h>
  11. #include <linux/clk.h>
  12. #include <linux/soc/qcom/smem.h>
  13. #include <dt-bindings/clock/qcom,apss-ipq.h>
  14. #include <dt-bindings/arm/qcom,ids.h>
  15. #include "common.h"
  16. #include "clk-regmap.h"
  17. #include "clk-branch.h"
  18. #include "clk-alpha-pll.h"
  19. #include "clk-rcg.h"
  20. enum {
  21. P_XO,
  22. P_GPLL0,
  23. P_APSS_PLL_EARLY,
  24. };
  25. static const struct clk_parent_data parents_apcs_alias0_clk_src[] = {
  26. { .fw_name = "xo" },
  27. { .fw_name = "gpll0" },
  28. { .fw_name = "pll" },
  29. };
  30. static const struct parent_map parents_apcs_alias0_clk_src_map[] = {
  31. { P_XO, 0 },
  32. { P_GPLL0, 4 },
  33. { P_APSS_PLL_EARLY, 5 },
  34. };
  35. static struct clk_rcg2 apcs_alias0_clk_src = {
  36. .cmd_rcgr = 0x0050,
  37. .hid_width = 5,
  38. .parent_map = parents_apcs_alias0_clk_src_map,
  39. .clkr.hw.init = &(struct clk_init_data){
  40. .name = "apcs_alias0_clk_src",
  41. .parent_data = parents_apcs_alias0_clk_src,
  42. .num_parents = ARRAY_SIZE(parents_apcs_alias0_clk_src),
  43. .ops = &clk_rcg2_mux_closest_ops,
  44. .flags = CLK_SET_RATE_PARENT,
  45. },
  46. };
  47. static struct clk_branch apcs_alias0_core_clk = {
  48. .halt_reg = 0x0058,
  49. .clkr = {
  50. .enable_reg = 0x0058,
  51. .enable_mask = BIT(0),
  52. .hw.init = &(struct clk_init_data){
  53. .name = "apcs_alias0_core_clk",
  54. .parent_hws = (const struct clk_hw *[]){
  55. &apcs_alias0_clk_src.clkr.hw },
  56. .num_parents = 1,
  57. .flags = CLK_SET_RATE_PARENT | CLK_IS_CRITICAL,
  58. .ops = &clk_branch2_ops,
  59. },
  60. },
  61. };
  62. static const struct regmap_config apss_ipq6018_regmap_config = {
  63. .reg_bits = 32,
  64. .reg_stride = 4,
  65. .val_bits = 32,
  66. .max_register = 0x1000,
  67. .fast_io = true,
  68. };
  69. static struct clk_regmap *apss_ipq6018_clks[] = {
  70. [APCS_ALIAS0_CLK_SRC] = &apcs_alias0_clk_src.clkr,
  71. [APCS_ALIAS0_CORE_CLK] = &apcs_alias0_core_clk.clkr,
  72. };
  73. static const struct qcom_cc_desc apss_ipq6018_desc = {
  74. .config = &apss_ipq6018_regmap_config,
  75. .clks = apss_ipq6018_clks,
  76. .num_clks = ARRAY_SIZE(apss_ipq6018_clks),
  77. };
  78. static int cpu_clk_notifier_fn(struct notifier_block *nb, unsigned long action,
  79. void *data)
  80. {
  81. struct clk_hw *hw;
  82. u8 index;
  83. int err;
  84. if (action == PRE_RATE_CHANGE)
  85. index = P_GPLL0;
  86. else if (action == POST_RATE_CHANGE || action == ABORT_RATE_CHANGE)
  87. index = P_APSS_PLL_EARLY;
  88. else
  89. return NOTIFY_OK;
  90. hw = &apcs_alias0_clk_src.clkr.hw;
  91. err = clk_rcg2_mux_closest_ops.set_parent(hw, index);
  92. return notifier_from_errno(err);
  93. }
  94. static int apss_ipq6018_probe(struct platform_device *pdev)
  95. {
  96. struct clk_hw *hw = &apcs_alias0_clk_src.clkr.hw;
  97. struct notifier_block *cpu_clk_notifier;
  98. struct regmap *regmap;
  99. u32 soc_id;
  100. int ret;
  101. ret = qcom_smem_get_soc_id(&soc_id);
  102. if (ret)
  103. return ret;
  104. regmap = dev_get_regmap(pdev->dev.parent, NULL);
  105. if (!regmap)
  106. return -ENODEV;
  107. ret = qcom_cc_really_probe(&pdev->dev, &apss_ipq6018_desc, regmap);
  108. if (ret)
  109. return ret;
  110. switch (soc_id) {
  111. /* Only below variants of IPQ53xx support scaling */
  112. case QCOM_ID_IPQ5332:
  113. case QCOM_ID_IPQ5322:
  114. case QCOM_ID_IPQ5300:
  115. cpu_clk_notifier = devm_kzalloc(&pdev->dev,
  116. sizeof(*cpu_clk_notifier),
  117. GFP_KERNEL);
  118. if (!cpu_clk_notifier)
  119. return -ENOMEM;
  120. cpu_clk_notifier->notifier_call = cpu_clk_notifier_fn;
  121. ret = devm_clk_notifier_register(&pdev->dev, hw->clk, cpu_clk_notifier);
  122. if (ret)
  123. return ret;
  124. break;
  125. default:
  126. break;
  127. }
  128. return 0;
  129. }
  130. static struct platform_driver apss_ipq6018_driver = {
  131. .probe = apss_ipq6018_probe,
  132. .driver = {
  133. .name = "qcom,apss-ipq6018-clk",
  134. },
  135. };
  136. module_platform_driver(apss_ipq6018_driver);
  137. MODULE_DESCRIPTION("QCOM APSS IPQ 6018 CLK Driver");
  138. MODULE_LICENSE("GPL v2");