1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2021, The Linux Foundation. All rights reserved.
6 #include <linux/clk-provider.h>
7 #include <linux/kernel.h>
8 #include <linux/module.h>
9 #include <linux/platform_device.h>
10 #include <linux/regmap.h>
12 #include <dt-bindings/clock/qcom,gpucc-sc8280xp.h>
14 #include "clk-alpha-pll.h"
15 #include "clk-branch.h"
17 #include "clk-regmap-divider.h"
22 /* Need to match the order of clocks in DT binding */
25 DT_GCC_GPU_GPLL0_CLK_SRC,
26 DT_GCC_GPU_GPLL0_DIV_CLK_SRC,
31 P_GCC_GPU_GPLL0_CLK_SRC,
32 P_GCC_GPU_GPLL0_DIV_CLK_SRC,
33 P_GPU_CC_PLL0_OUT_MAIN,
34 P_GPU_CC_PLL1_OUT_MAIN,
37 static const struct clk_parent_data parent_data_tcxo = { .index = DT_BI_TCXO };
39 static const struct pll_vco lucid_5lpe_vco[] = {
40 { 249600000, 1800000000, 0 },
43 static struct alpha_pll_config gpu_cc_pll0_config = {
46 .config_ctl_val = 0x20485699,
47 .config_ctl_hi_val = 0x00002261,
48 .config_ctl_hi1_val = 0x2a9a699c,
49 .test_ctl_val = 0x00000000,
50 .test_ctl_hi_val = 0x00000000,
51 .test_ctl_hi1_val = 0x01800000,
52 .user_ctl_val = 0x00000000,
53 .user_ctl_hi_val = 0x00000805,
54 .user_ctl_hi1_val = 0x00000000,
57 static struct clk_alpha_pll gpu_cc_pll0 = {
59 .vco_table = lucid_5lpe_vco,
60 .num_vco = ARRAY_SIZE(lucid_5lpe_vco),
61 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
63 .hw.init = &(const struct clk_init_data){
64 .name = "gpu_cc_pll0",
65 .parent_data = &parent_data_tcxo,
67 .ops = &clk_alpha_pll_lucid_5lpe_ops,
72 static struct alpha_pll_config gpu_cc_pll1_config = {
75 .config_ctl_val = 0x20485699,
76 .config_ctl_hi_val = 0x00002261,
77 .config_ctl_hi1_val = 0x2a9a699c,
78 .test_ctl_val = 0x00000000,
79 .test_ctl_hi_val = 0x00000000,
80 .test_ctl_hi1_val = 0x01800000,
81 .user_ctl_val = 0x00000000,
82 .user_ctl_hi_val = 0x00000805,
83 .user_ctl_hi1_val = 0x00000000,
86 static struct clk_alpha_pll gpu_cc_pll1 = {
88 .vco_table = lucid_5lpe_vco,
89 .num_vco = ARRAY_SIZE(lucid_5lpe_vco),
90 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
92 .hw.init = &(const struct clk_init_data){
93 .name = "gpu_cc_pll1",
94 .parent_data = &parent_data_tcxo,
96 .ops = &clk_alpha_pll_lucid_5lpe_ops,
101 static const struct parent_map gpu_cc_parent_map_0[] = {
103 { P_GPU_CC_PLL0_OUT_MAIN, 1 },
104 { P_GPU_CC_PLL1_OUT_MAIN, 3 },
105 { P_GCC_GPU_GPLL0_CLK_SRC, 5 },
106 { P_GCC_GPU_GPLL0_DIV_CLK_SRC, 6 },
109 static const struct clk_parent_data gpu_cc_parent_data_0[] = {
110 { .index = DT_BI_TCXO },
111 { .hw = &gpu_cc_pll0.clkr.hw },
112 { .hw = &gpu_cc_pll1.clkr.hw },
113 { .index = DT_GCC_GPU_GPLL0_CLK_SRC },
114 { .index = DT_GCC_GPU_GPLL0_DIV_CLK_SRC },
117 static const struct parent_map gpu_cc_parent_map_1[] = {
119 { P_GPU_CC_PLL1_OUT_MAIN, 3 },
120 { P_GCC_GPU_GPLL0_CLK_SRC, 5 },
121 { P_GCC_GPU_GPLL0_DIV_CLK_SRC, 6 },
124 static const struct clk_parent_data gpu_cc_parent_data_1[] = {
125 { .index = DT_BI_TCXO },
126 { .hw = &gpu_cc_pll1.clkr.hw },
127 { .index = DT_GCC_GPU_GPLL0_CLK_SRC },
128 { .index = DT_GCC_GPU_GPLL0_DIV_CLK_SRC },
131 static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src[] = {
132 F(19200000, P_BI_TCXO, 1, 0, 0),
133 F(200000000, P_GCC_GPU_GPLL0_DIV_CLK_SRC, 1.5, 0, 0),
134 F(500000000, P_GPU_CC_PLL1_OUT_MAIN, 1, 0, 0),
138 static struct clk_rcg2 gpu_cc_gmu_clk_src = {
142 .parent_map = gpu_cc_parent_map_0,
143 .freq_tbl = ftbl_gpu_cc_gmu_clk_src,
144 .clkr.hw.init = &(const struct clk_init_data){
145 .name = "gpu_cc_gmu_clk_src",
146 .parent_data = gpu_cc_parent_data_0,
147 .num_parents = ARRAY_SIZE(gpu_cc_parent_data_0),
148 .ops = &clk_rcg2_shared_ops,
152 static const struct freq_tbl ftbl_gpu_cc_hub_clk_src[] = {
153 F(200000000, P_GCC_GPU_GPLL0_CLK_SRC, 3, 0, 0),
154 F(300000000, P_GCC_GPU_GPLL0_CLK_SRC, 2, 0, 0),
155 F(400000000, P_GCC_GPU_GPLL0_CLK_SRC, 1.5, 0, 0),
159 static struct clk_rcg2 gpu_cc_hub_clk_src = {
163 .parent_map = gpu_cc_parent_map_1,
164 .freq_tbl = ftbl_gpu_cc_hub_clk_src,
165 .clkr.hw.init = &(const struct clk_init_data){
166 .name = "gpu_cc_hub_clk_src",
167 .parent_data = gpu_cc_parent_data_1,
168 .num_parents = ARRAY_SIZE(gpu_cc_parent_data_1),
169 .ops = &clk_rcg2_shared_ops,
173 static struct clk_regmap_div gpu_cc_hub_ahb_div_clk_src = {
177 .clkr.hw.init = &(const struct clk_init_data) {
178 .name = "gpu_cc_hub_ahb_div_clk_src",
179 .parent_hws = (const struct clk_hw*[]){
180 &gpu_cc_hub_clk_src.clkr.hw,
183 .flags = CLK_SET_RATE_PARENT,
184 .ops = &clk_regmap_div_ro_ops,
188 static struct clk_regmap_div gpu_cc_hub_cx_int_div_clk_src = {
192 .clkr.hw.init = &(const struct clk_init_data) {
193 .name = "gpu_cc_hub_cx_int_div_clk_src",
194 .parent_hws = (const struct clk_hw*[]){
195 &gpu_cc_hub_clk_src.clkr.hw,
198 .flags = CLK_SET_RATE_PARENT,
199 .ops = &clk_regmap_div_ro_ops,
203 static struct clk_branch gpu_cc_ahb_clk = {
205 .halt_check = BRANCH_HALT_DELAY,
207 .enable_reg = 0x1078,
208 .enable_mask = BIT(0),
209 .hw.init = &(const struct clk_init_data){
210 .name = "gpu_cc_ahb_clk",
211 .parent_hws = (const struct clk_hw*[]){
212 &gpu_cc_hub_ahb_div_clk_src.clkr.hw,
215 .flags = CLK_SET_RATE_PARENT,
216 .ops = &clk_branch2_ops,
221 static struct clk_branch gpu_cc_crc_ahb_clk = {
223 .halt_check = BRANCH_HALT_VOTED,
225 .enable_reg = 0x107c,
226 .enable_mask = BIT(0),
227 .hw.init = &(const struct clk_init_data){
228 .name = "gpu_cc_crc_ahb_clk",
229 .parent_hws = (const struct clk_hw*[]){
230 &gpu_cc_hub_ahb_div_clk_src.clkr.hw,
233 .flags = CLK_SET_RATE_PARENT,
234 .ops = &clk_branch2_ops,
239 static struct clk_branch gpu_cc_cx_gmu_clk = {
241 .halt_check = BRANCH_HALT,
243 .enable_reg = 0x1098,
244 .enable_mask = BIT(0),
245 .hw.init = &(const struct clk_init_data){
246 .name = "gpu_cc_cx_gmu_clk",
247 .parent_hws = (const struct clk_hw*[]){
248 &gpu_cc_gmu_clk_src.clkr.hw,
251 .flags = CLK_SET_RATE_PARENT,
252 .ops = &clk_branch2_aon_ops,
257 static struct clk_branch gpu_cc_cx_snoc_dvm_clk = {
259 .halt_check = BRANCH_HALT_VOTED,
261 .enable_reg = 0x108c,
262 .enable_mask = BIT(0),
263 .hw.init = &(const struct clk_init_data){
264 .name = "gpu_cc_cx_snoc_dvm_clk",
265 .ops = &clk_branch2_ops,
270 static struct clk_branch gpu_cc_cxo_aon_clk = {
272 .halt_check = BRANCH_HALT_VOTED,
274 .enable_reg = 0x1004,
275 .enable_mask = BIT(0),
276 .hw.init = &(const struct clk_init_data){
277 .name = "gpu_cc_cxo_aon_clk",
278 .ops = &clk_branch2_ops,
283 static struct clk_branch gpu_cc_gx_gmu_clk = {
285 .halt_check = BRANCH_HALT,
287 .enable_reg = 0x1064,
288 .enable_mask = BIT(0),
289 .hw.init = &(const struct clk_init_data){
290 .name = "gpu_cc_gx_gmu_clk",
291 .parent_hws = (const struct clk_hw*[]){
292 &gpu_cc_gmu_clk_src.clkr.hw,
295 .flags = CLK_SET_RATE_PARENT,
296 .ops = &clk_branch2_ops,
301 static struct clk_branch gpu_cc_hlos1_vote_gpu_smmu_clk = {
303 .halt_check = BRANCH_HALT_VOTED,
305 .enable_reg = 0x5000,
306 .enable_mask = BIT(0),
307 .hw.init = &(const struct clk_init_data){
308 .name = "gpu_cc_hlos1_vote_gpu_smmu_clk",
309 .ops = &clk_branch2_ops,
314 static struct clk_branch gpu_cc_hub_aon_clk = {
316 .halt_check = BRANCH_HALT,
318 .enable_reg = 0x1178,
319 .enable_mask = BIT(0),
320 .hw.init = &(const struct clk_init_data){
321 .name = "gpu_cc_hub_aon_clk",
322 .parent_hws = (const struct clk_hw*[]){
323 &gpu_cc_hub_clk_src.clkr.hw,
326 .flags = CLK_SET_RATE_PARENT,
327 .ops = &clk_branch2_aon_ops,
332 static struct clk_branch gpu_cc_hub_cx_int_clk = {
334 .halt_check = BRANCH_HALT,
336 .enable_reg = 0x1204,
337 .enable_mask = BIT(0),
338 .hw.init = &(const struct clk_init_data){
339 .name = "gpu_cc_hub_cx_int_clk",
340 .parent_hws = (const struct clk_hw*[]){
341 &gpu_cc_hub_cx_int_div_clk_src.clkr.hw,
344 .flags = CLK_SET_RATE_PARENT,
345 .ops = &clk_branch2_aon_ops,
350 static struct clk_branch gpu_cc_sleep_clk = {
352 .halt_check = BRANCH_HALT_VOTED,
354 .enable_reg = 0x1090,
355 .enable_mask = BIT(0),
356 .hw.init = &(const struct clk_init_data){
357 .name = "gpu_cc_sleep_clk",
358 .ops = &clk_branch2_ops,
363 static struct clk_regmap *gpu_cc_sc8280xp_clocks[] = {
364 [GPU_CC_AHB_CLK] = &gpu_cc_ahb_clk.clkr,
365 [GPU_CC_CRC_AHB_CLK] = &gpu_cc_crc_ahb_clk.clkr,
366 [GPU_CC_CX_GMU_CLK] = &gpu_cc_cx_gmu_clk.clkr,
367 [GPU_CC_CX_SNOC_DVM_CLK] = &gpu_cc_cx_snoc_dvm_clk.clkr,
368 [GPU_CC_CXO_AON_CLK] = &gpu_cc_cxo_aon_clk.clkr,
369 [GPU_CC_GMU_CLK_SRC] = &gpu_cc_gmu_clk_src.clkr,
370 [GPU_CC_GX_GMU_CLK] = &gpu_cc_gx_gmu_clk.clkr,
371 [GPU_CC_HLOS1_VOTE_GPU_SMMU_CLK] = &gpu_cc_hlos1_vote_gpu_smmu_clk.clkr,
372 [GPU_CC_HUB_AHB_DIV_CLK_SRC] = &gpu_cc_hub_ahb_div_clk_src.clkr,
373 [GPU_CC_HUB_AON_CLK] = &gpu_cc_hub_aon_clk.clkr,
374 [GPU_CC_HUB_CLK_SRC] = &gpu_cc_hub_clk_src.clkr,
375 [GPU_CC_HUB_CX_INT_CLK] = &gpu_cc_hub_cx_int_clk.clkr,
376 [GPU_CC_HUB_CX_INT_DIV_CLK_SRC] = &gpu_cc_hub_cx_int_div_clk_src.clkr,
377 [GPU_CC_PLL0] = &gpu_cc_pll0.clkr,
378 [GPU_CC_PLL1] = &gpu_cc_pll1.clkr,
379 [GPU_CC_SLEEP_CLK] = &gpu_cc_sleep_clk.clkr,
382 static struct gdsc cx_gdsc = {
384 .gds_hw_ctrl = 0x1540,
388 .pwrsts = PWRSTS_OFF_ON,
389 .flags = VOTABLE | RETAIN_FF_ENABLE,
392 static struct gdsc gx_gdsc = {
394 .clamp_io_ctrl = 0x1508,
397 .power_on = gdsc_gx_do_nothing_enable,
399 .pwrsts = PWRSTS_OFF_ON,
400 .flags = CLAMP_IO | RETAIN_FF_ENABLE,
403 static struct gdsc *gpu_cc_sc8280xp_gdscs[] = {
404 [GPU_CC_CX_GDSC] = &cx_gdsc,
405 [GPU_CC_GX_GDSC] = &gx_gdsc,
408 static const struct regmap_config gpu_cc_sc8280xp_regmap_config = {
412 .max_register = 0x8030,
416 static struct qcom_cc_desc gpu_cc_sc8280xp_desc = {
417 .config = &gpu_cc_sc8280xp_regmap_config,
418 .clks = gpu_cc_sc8280xp_clocks,
419 .num_clks = ARRAY_SIZE(gpu_cc_sc8280xp_clocks),
420 .gdscs = gpu_cc_sc8280xp_gdscs,
421 .num_gdscs = ARRAY_SIZE(gpu_cc_sc8280xp_gdscs),
424 static int gpu_cc_sc8280xp_probe(struct platform_device *pdev)
426 struct regmap *regmap;
428 regmap = qcom_cc_map(pdev, &gpu_cc_sc8280xp_desc);
430 return PTR_ERR(regmap);
432 clk_lucid_pll_configure(&gpu_cc_pll0, regmap, &gpu_cc_pll0_config);
433 clk_lucid_pll_configure(&gpu_cc_pll1, regmap, &gpu_cc_pll1_config);
436 * Keep the clocks always-ON
437 * GPU_CC_CB_CLK, GPU_CC_CXO_CLK
439 regmap_update_bits(regmap, 0x1170, BIT(0), BIT(0));
440 regmap_update_bits(regmap, 0x109c, BIT(0), BIT(0));
442 return qcom_cc_really_probe(pdev, &gpu_cc_sc8280xp_desc, regmap);
445 static const struct of_device_id gpu_cc_sc8280xp_match_table[] = {
446 { .compatible = "qcom,sc8280xp-gpucc" },
449 MODULE_DEVICE_TABLE(of, gpu_cc_sc8280xp_match_table);
451 static struct platform_driver gpu_cc_sc8280xp_driver = {
452 .probe = gpu_cc_sc8280xp_probe,
454 .name = "gpu_cc-sc8280xp",
455 .of_match_table = gpu_cc_sc8280xp_match_table,
458 module_platform_driver(gpu_cc_sc8280xp_driver);
460 MODULE_DESCRIPTION("Qualcomm SC8280XP GPU clock controller");
461 MODULE_LICENSE("GPL");