apss-ipq5424.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2025, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/clk.h>
  7. #include <linux/clk-provider.h>
  8. #include <linux/err.h>
  9. #include <linux/interconnect-provider.h>
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/regmap.h>
  14. #include <dt-bindings/arm/qcom,ids.h>
  15. #include <dt-bindings/clock/qcom,apss-ipq.h>
  16. #include <dt-bindings/interconnect/qcom,ipq5424.h>
  17. #include "clk-alpha-pll.h"
  18. #include "clk-branch.h"
  19. #include "clk-rcg.h"
  20. #include "clk-regmap.h"
  21. #include "common.h"
  22. enum {
  23. DT_XO,
  24. DT_CLK_REF,
  25. };
  26. enum {
  27. P_XO,
  28. P_GPLL0,
  29. P_APSS_PLL_EARLY,
  30. P_L3_PLL,
  31. };
  32. static const struct alpha_pll_config apss_pll_config = {
  33. .l = 0x3b,
  34. .config_ctl_val = 0x08200920,
  35. .config_ctl_hi_val = 0x05008001,
  36. .config_ctl_hi1_val = 0x04000000,
  37. .user_ctl_val = 0xf,
  38. };
  39. static struct clk_alpha_pll ipq5424_apss_pll = {
  40. .offset = 0x0,
  41. .config = &apss_pll_config,
  42. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_HUAYRA_2290],
  43. .flags = SUPPORTS_DYNAMIC_UPDATE,
  44. .clkr = {
  45. .enable_reg = 0x0,
  46. .enable_mask = BIT(0),
  47. .hw.init = &(struct clk_init_data){
  48. .name = "apss_pll",
  49. .parent_data = &(const struct clk_parent_data) {
  50. .index = DT_XO,
  51. },
  52. .num_parents = 1,
  53. .ops = &clk_alpha_pll_huayra_ops,
  54. },
  55. },
  56. };
  57. static const struct clk_parent_data parents_apss_silver_clk_src[] = {
  58. { .index = DT_XO },
  59. { .index = DT_CLK_REF },
  60. { .hw = &ipq5424_apss_pll.clkr.hw },
  61. };
  62. static const struct parent_map parents_apss_silver_clk_src_map[] = {
  63. { P_XO, 0 },
  64. { P_GPLL0, 4 },
  65. { P_APSS_PLL_EARLY, 5 },
  66. };
  67. static const struct freq_tbl ftbl_apss_clk_src[] = {
  68. F(816000000, P_APSS_PLL_EARLY, 1, 0, 0),
  69. F(1416000000, P_APSS_PLL_EARLY, 1, 0, 0),
  70. F(1800000000, P_APSS_PLL_EARLY, 1, 0, 0),
  71. { }
  72. };
  73. static struct clk_rcg2 apss_silver_clk_src = {
  74. .cmd_rcgr = 0x0080,
  75. .freq_tbl = ftbl_apss_clk_src,
  76. .hid_width = 5,
  77. .parent_map = parents_apss_silver_clk_src_map,
  78. .clkr.hw.init = &(struct clk_init_data) {
  79. .name = "apss_silver_clk_src",
  80. .parent_data = parents_apss_silver_clk_src,
  81. .num_parents = ARRAY_SIZE(parents_apss_silver_clk_src),
  82. .ops = &clk_rcg2_ops,
  83. .flags = CLK_SET_RATE_PARENT,
  84. },
  85. };
  86. static struct clk_branch apss_silver_core_clk = {
  87. .halt_reg = 0x008c,
  88. .clkr = {
  89. .enable_reg = 0x008c,
  90. .enable_mask = BIT(0),
  91. .hw.init = &(struct clk_init_data) {
  92. .name = "apss_silver_core_clk",
  93. .parent_hws = (const struct clk_hw *[]) {
  94. &apss_silver_clk_src.clkr.hw
  95. },
  96. .num_parents = 1,
  97. .flags = CLK_SET_RATE_PARENT | CLK_IS_CRITICAL,
  98. .ops = &clk_branch2_ops,
  99. },
  100. },
  101. };
  102. static const struct alpha_pll_config l3_pll_config = {
  103. .l = 0x29,
  104. .config_ctl_val = 0x08200920,
  105. .config_ctl_hi_val = 0x05008001,
  106. .config_ctl_hi1_val = 0x04000000,
  107. .user_ctl_val = 0xf,
  108. };
  109. static struct clk_alpha_pll ipq5424_l3_pll = {
  110. .offset = 0x10000,
  111. .config = &l3_pll_config,
  112. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_HUAYRA_2290],
  113. .flags = SUPPORTS_DYNAMIC_UPDATE,
  114. .clkr = {
  115. .enable_reg = 0x0,
  116. .enable_mask = BIT(0),
  117. .hw.init = &(struct clk_init_data) {
  118. .name = "l3_pll",
  119. .parent_data = &(const struct clk_parent_data) {
  120. .index = DT_XO,
  121. },
  122. .num_parents = 1,
  123. .ops = &clk_alpha_pll_huayra_ops,
  124. },
  125. },
  126. };
  127. static const struct clk_parent_data parents_l3_clk_src[] = {
  128. { .index = DT_XO },
  129. { .index = DT_CLK_REF },
  130. { .hw = &ipq5424_l3_pll.clkr.hw },
  131. };
  132. static const struct parent_map parents_l3_clk_src_map[] = {
  133. { P_XO, 0 },
  134. { P_GPLL0, 4 },
  135. { P_L3_PLL, 5 },
  136. };
  137. static const struct freq_tbl ftbl_l3_clk_src[] = {
  138. F(816000000, P_L3_PLL, 1, 0, 0),
  139. F(984000000, P_L3_PLL, 1, 0, 0),
  140. F(1272000000, P_L3_PLL, 1, 0, 0),
  141. { }
  142. };
  143. static struct clk_rcg2 l3_clk_src = {
  144. .cmd_rcgr = 0x10080,
  145. .freq_tbl = ftbl_l3_clk_src,
  146. .hid_width = 5,
  147. .parent_map = parents_l3_clk_src_map,
  148. .clkr.hw.init = &(struct clk_init_data) {
  149. .name = "l3_clk_src",
  150. .parent_data = parents_l3_clk_src,
  151. .num_parents = ARRAY_SIZE(parents_l3_clk_src),
  152. .ops = &clk_rcg2_ops,
  153. .flags = CLK_SET_RATE_PARENT,
  154. },
  155. };
  156. static struct clk_branch l3_core_clk = {
  157. .halt_reg = 0x1008c,
  158. .clkr = {
  159. .enable_reg = 0x1008c,
  160. .enable_mask = BIT(0),
  161. .hw.init = &(struct clk_init_data) {
  162. .name = "l3_clk",
  163. .parent_hws = (const struct clk_hw *[]) {
  164. &l3_clk_src.clkr.hw
  165. },
  166. .num_parents = 1,
  167. .flags = CLK_SET_RATE_PARENT | CLK_IS_CRITICAL,
  168. .ops = &clk_branch2_ops,
  169. },
  170. },
  171. };
  172. static const struct regmap_config apss_ipq5424_regmap_config = {
  173. .reg_bits = 32,
  174. .reg_stride = 4,
  175. .val_bits = 32,
  176. .max_register = 0x20000,
  177. .fast_io = true,
  178. };
  179. static struct clk_regmap *apss_ipq5424_clks[] = {
  180. [APSS_PLL_EARLY] = &ipq5424_apss_pll.clkr,
  181. [APSS_SILVER_CLK_SRC] = &apss_silver_clk_src.clkr,
  182. [APSS_SILVER_CORE_CLK] = &apss_silver_core_clk.clkr,
  183. [L3_PLL] = &ipq5424_l3_pll.clkr,
  184. [L3_CLK_SRC] = &l3_clk_src.clkr,
  185. [L3_CORE_CLK] = &l3_core_clk.clkr,
  186. };
  187. static struct clk_alpha_pll *ipa5424_apss_plls[] = {
  188. &ipq5424_l3_pll,
  189. &ipq5424_apss_pll,
  190. };
  191. static struct qcom_cc_driver_data ipa5424_apss_driver_data = {
  192. .alpha_plls = ipa5424_apss_plls,
  193. .num_alpha_plls = ARRAY_SIZE(ipa5424_apss_plls),
  194. };
  195. #define IPQ_APPS_PLL_ID (5424 * 3) /* some unique value */
  196. static const struct qcom_icc_hws_data icc_ipq5424_cpu_l3[] = {
  197. { MASTER_CPU, SLAVE_L3, L3_CORE_CLK },
  198. };
  199. static const struct qcom_cc_desc apss_ipq5424_desc = {
  200. .config = &apss_ipq5424_regmap_config,
  201. .clks = apss_ipq5424_clks,
  202. .num_clks = ARRAY_SIZE(apss_ipq5424_clks),
  203. .icc_hws = icc_ipq5424_cpu_l3,
  204. .num_icc_hws = ARRAY_SIZE(icc_ipq5424_cpu_l3),
  205. .icc_first_node_id = IPQ_APPS_PLL_ID,
  206. .driver_data = &ipa5424_apss_driver_data,
  207. };
  208. static int apss_ipq5424_probe(struct platform_device *pdev)
  209. {
  210. return qcom_cc_probe(pdev, &apss_ipq5424_desc);
  211. }
  212. static const struct of_device_id apss_ipq5424_match_table[] = {
  213. { .compatible = "qcom,ipq5424-apss-clk" },
  214. { }
  215. };
  216. MODULE_DEVICE_TABLE(of, apss_ipq5424_match_table);
  217. static struct platform_driver apss_ipq5424_driver = {
  218. .probe = apss_ipq5424_probe,
  219. .driver = {
  220. .name = "apss-ipq5424-clk",
  221. .of_match_table = apss_ipq5424_match_table,
  222. .sync_state = icc_sync_state,
  223. },
  224. };
  225. module_platform_driver(apss_ipq5424_driver);
  226. MODULE_DESCRIPTION("QCOM APSS IPQ5424 CLK Driver");
  227. MODULE_LICENSE("GPL");