1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2021-2022, 2024, Qualcomm Innovation Center, Inc. All rights reserved.
4 * Copyright (c) 2023, Linaro Limited
7 #include <linux/clk-provider.h>
9 #include <linux/kernel.h>
10 #include <linux/mod_devicetable.h>
11 #include <linux/module.h>
12 #include <linux/platform_device.h>
13 #include <linux/regmap.h>
15 #include <dt-bindings/clock/qcom,sa8775p-gpucc.h>
17 #include "clk-alpha-pll.h"
18 #include "clk-branch.h"
20 #include "clk-regmap.h"
21 #include "clk-regmap-divider.h"
26 /* Need to match the order of clocks in DT binding */
29 DT_GCC_GPU_GPLL0_CLK_SRC
,
30 DT_GCC_GPU_GPLL0_DIV_CLK_SRC
,
37 P_GPU_CC_PLL0_OUT_MAIN
,
38 P_GPU_CC_PLL1_OUT_MAIN
,
41 static const struct clk_parent_data parent_data_tcxo
= { .index
= DT_BI_TCXO
};
43 static const struct pll_vco lucid_evo_vco
[] = {
44 { 249600000, 2020000000, 0 },
47 /* 810MHz configuration */
48 static struct alpha_pll_config gpu_cc_pll0_config
= {
51 .config_ctl_val
= 0x20485699,
52 .config_ctl_hi_val
= 0x00182261,
53 .config_ctl_hi1_val
= 0x32aa299c,
54 .user_ctl_val
= 0x00000001,
55 .user_ctl_hi_val
= 0x00400805,
58 static struct clk_alpha_pll gpu_cc_pll0
= {
60 .vco_table
= lucid_evo_vco
,
61 .num_vco
= ARRAY_SIZE(lucid_evo_vco
),
62 .regs
= clk_alpha_pll_regs
[CLK_ALPHA_PLL_TYPE_LUCID_EVO
],
64 .hw
.init
= &(const struct clk_init_data
){
65 .name
= "gpu_cc_pll0",
66 .parent_data
= &parent_data_tcxo
,
68 .ops
= &clk_alpha_pll_lucid_evo_ops
,
73 /* 1000MHz configuration */
74 static struct alpha_pll_config gpu_cc_pll1_config
= {
77 .config_ctl_val
= 0x20485699,
78 .config_ctl_hi_val
= 0x00182261,
79 .config_ctl_hi1_val
= 0x32aa299c,
80 .user_ctl_val
= 0x00000001,
81 .user_ctl_hi_val
= 0x00400805,
84 static struct clk_alpha_pll gpu_cc_pll1
= {
86 .vco_table
= lucid_evo_vco
,
87 .num_vco
= ARRAY_SIZE(lucid_evo_vco
),
88 .regs
= clk_alpha_pll_regs
[CLK_ALPHA_PLL_TYPE_LUCID_EVO
],
90 .hw
.init
= &(const struct clk_init_data
){
91 .name
= "gpu_cc_pll1",
92 .parent_data
= &parent_data_tcxo
,
94 .ops
= &clk_alpha_pll_lucid_evo_ops
,
99 static const struct parent_map gpu_cc_parent_map_0
[] = {
101 { P_GPLL0_OUT_MAIN
, 5 },
102 { P_GPLL0_OUT_MAIN_DIV
, 6 },
105 static const struct clk_parent_data gpu_cc_parent_data_0
[] = {
106 { .index
= DT_BI_TCXO
},
107 { .index
= DT_GCC_GPU_GPLL0_CLK_SRC
},
108 { .index
= DT_GCC_GPU_GPLL0_DIV_CLK_SRC
},
111 static const struct parent_map gpu_cc_parent_map_1
[] = {
113 { P_GPU_CC_PLL0_OUT_MAIN
, 1 },
114 { P_GPU_CC_PLL1_OUT_MAIN
, 3 },
115 { P_GPLL0_OUT_MAIN
, 5 },
116 { P_GPLL0_OUT_MAIN_DIV
, 6 },
119 static const struct clk_parent_data gpu_cc_parent_data_1
[] = {
120 { .index
= DT_BI_TCXO
},
121 { .hw
= &gpu_cc_pll0
.clkr
.hw
},
122 { .hw
= &gpu_cc_pll1
.clkr
.hw
},
123 { .index
= DT_GCC_GPU_GPLL0_CLK_SRC
},
124 { .index
= DT_GCC_GPU_GPLL0_DIV_CLK_SRC
},
127 static const struct parent_map gpu_cc_parent_map_2
[] = {
129 { P_GPU_CC_PLL1_OUT_MAIN
, 3 },
130 { P_GPLL0_OUT_MAIN
, 5 },
131 { P_GPLL0_OUT_MAIN_DIV
, 6 },
134 static const struct clk_parent_data gpu_cc_parent_data_2
[] = {
135 { .index
= DT_BI_TCXO
},
136 { .hw
= &gpu_cc_pll1
.clkr
.hw
},
137 { .index
= DT_GCC_GPU_GPLL0_CLK_SRC
},
138 { .index
= DT_GCC_GPU_GPLL0_DIV_CLK_SRC
},
141 static const struct parent_map gpu_cc_parent_map_3
[] = {
145 static const struct clk_parent_data gpu_cc_parent_data_3
[] = {
146 { .index
= DT_BI_TCXO
},
149 static const struct freq_tbl ftbl_gpu_cc_ff_clk_src
[] = {
150 F(200000000, P_GPLL0_OUT_MAIN
, 3, 0, 0),
154 static struct clk_rcg2 gpu_cc_ff_clk_src
= {
158 .parent_map
= gpu_cc_parent_map_0
,
159 .freq_tbl
= ftbl_gpu_cc_ff_clk_src
,
160 .clkr
.hw
.init
= &(const struct clk_init_data
){
161 .name
= "gpu_cc_ff_clk_src",
162 .parent_data
= gpu_cc_parent_data_0
,
163 .num_parents
= ARRAY_SIZE(gpu_cc_parent_data_0
),
164 .ops
= &clk_rcg2_shared_ops
,
168 static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src
[] = {
169 F(500000000, P_GPU_CC_PLL1_OUT_MAIN
, 2, 0, 0),
173 static struct clk_rcg2 gpu_cc_gmu_clk_src
= {
177 .parent_map
= gpu_cc_parent_map_1
,
178 .freq_tbl
= ftbl_gpu_cc_gmu_clk_src
,
179 .clkr
.hw
.init
= &(const struct clk_init_data
){
180 .name
= "gpu_cc_gmu_clk_src",
181 .parent_data
= gpu_cc_parent_data_1
,
182 .num_parents
= ARRAY_SIZE(gpu_cc_parent_data_1
),
183 .flags
= CLK_SET_RATE_PARENT
,
184 .ops
= &clk_rcg2_shared_ops
,
188 static const struct freq_tbl ftbl_gpu_cc_hub_clk_src
[] = {
189 F(240000000, P_GPLL0_OUT_MAIN
, 2.5, 0, 0),
193 static struct clk_rcg2 gpu_cc_hub_clk_src
= {
197 .parent_map
= gpu_cc_parent_map_2
,
198 .freq_tbl
= ftbl_gpu_cc_hub_clk_src
,
199 .clkr
.hw
.init
= &(const struct clk_init_data
){
200 .name
= "gpu_cc_hub_clk_src",
201 .parent_data
= gpu_cc_parent_data_2
,
202 .num_parents
= ARRAY_SIZE(gpu_cc_parent_data_2
),
203 .ops
= &clk_rcg2_shared_ops
,
207 static const struct freq_tbl ftbl_gpu_cc_xo_clk_src
[] = {
208 F(19200000, P_BI_TCXO
, 1, 0, 0),
212 static struct clk_rcg2 gpu_cc_xo_clk_src
= {
216 .parent_map
= gpu_cc_parent_map_3
,
217 .freq_tbl
= ftbl_gpu_cc_xo_clk_src
,
218 .clkr
.hw
.init
= &(const struct clk_init_data
){
219 .name
= "gpu_cc_xo_clk_src",
220 .parent_data
= gpu_cc_parent_data_3
,
221 .num_parents
= ARRAY_SIZE(gpu_cc_parent_data_3
),
222 .ops
= &clk_rcg2_ops
,
226 static struct clk_regmap_div gpu_cc_demet_div_clk_src
= {
230 .clkr
.hw
.init
= &(const struct clk_init_data
) {
231 .name
= "gpu_cc_demet_div_clk_src",
232 .parent_hws
= (const struct clk_hw
*[]){
233 &gpu_cc_xo_clk_src
.clkr
.hw
,
236 .flags
= CLK_SET_RATE_PARENT
,
237 .ops
= &clk_regmap_div_ro_ops
,
241 static struct clk_regmap_div gpu_cc_hub_ahb_div_clk_src
= {
245 .clkr
.hw
.init
= &(const struct clk_init_data
) {
246 .name
= "gpu_cc_hub_ahb_div_clk_src",
247 .parent_hws
= (const struct clk_hw
*[]){
248 &gpu_cc_hub_clk_src
.clkr
.hw
,
251 .flags
= CLK_SET_RATE_PARENT
,
252 .ops
= &clk_regmap_div_ro_ops
,
256 static struct clk_regmap_div gpu_cc_hub_cx_int_div_clk_src
= {
260 .clkr
.hw
.init
= &(const struct clk_init_data
) {
261 .name
= "gpu_cc_hub_cx_int_div_clk_src",
262 .parent_hws
= (const struct clk_hw
*[]){
263 &gpu_cc_hub_clk_src
.clkr
.hw
,
266 .flags
= CLK_SET_RATE_PARENT
,
267 .ops
= &clk_regmap_div_ro_ops
,
271 static struct clk_branch gpu_cc_ahb_clk
= {
273 .halt_check
= BRANCH_HALT_DELAY
,
275 .enable_reg
= 0x911c,
276 .enable_mask
= BIT(0),
277 .hw
.init
= &(const struct clk_init_data
){
278 .name
= "gpu_cc_ahb_clk",
279 .parent_hws
= (const struct clk_hw
*[]){
280 &gpu_cc_hub_ahb_div_clk_src
.clkr
.hw
,
283 .flags
= CLK_SET_RATE_PARENT
,
284 .ops
= &clk_branch2_ops
,
289 static struct clk_branch gpu_cc_cb_clk
= {
291 .halt_check
= BRANCH_HALT
,
293 .enable_reg
= 0x93a4,
294 .enable_mask
= BIT(0),
295 .hw
.init
= &(const struct clk_init_data
){
296 .name
= "gpu_cc_cb_clk",
297 .ops
= &clk_branch2_aon_ops
,
302 static struct clk_branch gpu_cc_crc_ahb_clk
= {
304 .halt_check
= BRANCH_HALT_VOTED
,
306 .enable_reg
= 0x9120,
307 .enable_mask
= BIT(0),
308 .hw
.init
= &(const struct clk_init_data
){
309 .name
= "gpu_cc_crc_ahb_clk",
310 .parent_hws
= (const struct clk_hw
*[]){
311 &gpu_cc_hub_ahb_div_clk_src
.clkr
.hw
,
314 .flags
= CLK_SET_RATE_PARENT
,
315 .ops
= &clk_branch2_ops
,
320 static struct clk_branch gpu_cc_cx_ff_clk
= {
322 .halt_check
= BRANCH_HALT
,
324 .enable_reg
= 0x914c,
325 .enable_mask
= BIT(0),
326 .hw
.init
= &(const struct clk_init_data
){
327 .name
= "gpu_cc_cx_ff_clk",
328 .parent_hws
= (const struct clk_hw
*[]){
329 &gpu_cc_ff_clk_src
.clkr
.hw
,
332 .flags
= CLK_SET_RATE_PARENT
,
333 .ops
= &clk_branch2_ops
,
338 static struct clk_branch gpu_cc_cx_gmu_clk
= {
340 .halt_check
= BRANCH_HALT
,
342 .enable_reg
= 0x913c,
343 .enable_mask
= BIT(0),
344 .hw
.init
= &(const struct clk_init_data
){
345 .name
= "gpu_cc_cx_gmu_clk",
346 .parent_hws
= (const struct clk_hw
*[]){
347 &gpu_cc_gmu_clk_src
.clkr
.hw
,
350 .flags
= CLK_SET_RATE_PARENT
,
351 .ops
= &clk_branch2_aon_ops
,
356 static struct clk_branch gpu_cc_cx_snoc_dvm_clk
= {
358 .halt_check
= BRANCH_HALT_VOTED
,
360 .enable_reg
= 0x9130,
361 .enable_mask
= BIT(0),
362 .hw
.init
= &(const struct clk_init_data
){
363 .name
= "gpu_cc_cx_snoc_dvm_clk",
364 .ops
= &clk_branch2_ops
,
369 static struct clk_branch gpu_cc_cxo_aon_clk
= {
371 .halt_check
= BRANCH_HALT_VOTED
,
373 .enable_reg
= 0x9004,
374 .enable_mask
= BIT(0),
375 .hw
.init
= &(const struct clk_init_data
){
376 .name
= "gpu_cc_cxo_aon_clk",
377 .parent_hws
= (const struct clk_hw
*[]){
378 &gpu_cc_xo_clk_src
.clkr
.hw
,
381 .flags
= CLK_SET_RATE_PARENT
,
382 .ops
= &clk_branch2_ops
,
387 static struct clk_branch gpu_cc_cxo_clk
= {
389 .halt_check
= BRANCH_HALT
,
391 .enable_reg
= 0x9144,
392 .enable_mask
= BIT(0),
393 .hw
.init
= &(const struct clk_init_data
){
394 .name
= "gpu_cc_cxo_clk",
395 .parent_hws
= (const struct clk_hw
*[]){
396 &gpu_cc_xo_clk_src
.clkr
.hw
,
399 .flags
= CLK_SET_RATE_PARENT
,
400 .ops
= &clk_branch2_ops
,
405 static struct clk_branch gpu_cc_demet_clk
= {
407 .halt_check
= BRANCH_HALT
,
409 .enable_reg
= 0x900c,
410 .enable_mask
= BIT(0),
411 .hw
.init
= &(const struct clk_init_data
){
412 .name
= "gpu_cc_demet_clk",
413 .parent_hws
= (const struct clk_hw
*[]){
414 &gpu_cc_demet_div_clk_src
.clkr
.hw
,
417 .flags
= CLK_SET_RATE_PARENT
,
418 .ops
= &clk_branch2_aon_ops
,
423 static struct clk_branch gpu_cc_hlos1_vote_gpu_smmu_clk
= {
425 .halt_check
= BRANCH_HALT_VOTED
,
427 .enable_reg
= 0x7000,
428 .enable_mask
= BIT(0),
429 .hw
.init
= &(const struct clk_init_data
){
430 .name
= "gpu_cc_hlos1_vote_gpu_smmu_clk",
431 .ops
= &clk_branch2_ops
,
436 static struct clk_branch gpu_cc_hub_aon_clk
= {
438 .halt_check
= BRANCH_HALT
,
440 .enable_reg
= 0x93e8,
441 .enable_mask
= BIT(0),
442 .hw
.init
= &(const struct clk_init_data
){
443 .name
= "gpu_cc_hub_aon_clk",
444 .parent_hws
= (const struct clk_hw
*[]){
445 &gpu_cc_hub_clk_src
.clkr
.hw
,
448 .flags
= CLK_SET_RATE_PARENT
,
449 .ops
= &clk_branch2_aon_ops
,
454 static struct clk_branch gpu_cc_hub_cx_int_clk
= {
456 .halt_check
= BRANCH_HALT
,
458 .enable_reg
= 0x9148,
459 .enable_mask
= BIT(0),
460 .hw
.init
= &(const struct clk_init_data
){
461 .name
= "gpu_cc_hub_cx_int_clk",
462 .parent_hws
= (const struct clk_hw
*[]){
463 &gpu_cc_hub_cx_int_div_clk_src
.clkr
.hw
,
466 .flags
= CLK_SET_RATE_PARENT
,
467 .ops
= &clk_branch2_aon_ops
,
472 static struct clk_branch gpu_cc_memnoc_gfx_clk
= {
474 .halt_check
= BRANCH_HALT
,
476 .enable_reg
= 0x9150,
477 .enable_mask
= BIT(0),
478 .hw
.init
= &(const struct clk_init_data
){
479 .name
= "gpu_cc_memnoc_gfx_clk",
480 .ops
= &clk_branch2_ops
,
485 static struct clk_branch gpu_cc_sleep_clk
= {
487 .halt_check
= BRANCH_HALT_VOTED
,
489 .enable_reg
= 0x9134,
490 .enable_mask
= BIT(0),
491 .hw
.init
= &(const struct clk_init_data
){
492 .name
= "gpu_cc_sleep_clk",
493 .ops
= &clk_branch2_ops
,
498 static struct clk_regmap
*gpu_cc_sa8775p_clocks
[] = {
499 [GPU_CC_AHB_CLK
] = &gpu_cc_ahb_clk
.clkr
,
500 [GPU_CC_CB_CLK
] = &gpu_cc_cb_clk
.clkr
,
501 [GPU_CC_CRC_AHB_CLK
] = &gpu_cc_crc_ahb_clk
.clkr
,
502 [GPU_CC_CX_FF_CLK
] = &gpu_cc_cx_ff_clk
.clkr
,
503 [GPU_CC_CX_GMU_CLK
] = &gpu_cc_cx_gmu_clk
.clkr
,
504 [GPU_CC_CX_SNOC_DVM_CLK
] = &gpu_cc_cx_snoc_dvm_clk
.clkr
,
505 [GPU_CC_CXO_AON_CLK
] = &gpu_cc_cxo_aon_clk
.clkr
,
506 [GPU_CC_CXO_CLK
] = &gpu_cc_cxo_clk
.clkr
,
507 [GPU_CC_DEMET_CLK
] = &gpu_cc_demet_clk
.clkr
,
508 [GPU_CC_DEMET_DIV_CLK_SRC
] = &gpu_cc_demet_div_clk_src
.clkr
,
509 [GPU_CC_FF_CLK_SRC
] = &gpu_cc_ff_clk_src
.clkr
,
510 [GPU_CC_GMU_CLK_SRC
] = &gpu_cc_gmu_clk_src
.clkr
,
511 [GPU_CC_HLOS1_VOTE_GPU_SMMU_CLK
] = &gpu_cc_hlos1_vote_gpu_smmu_clk
.clkr
,
512 [GPU_CC_HUB_AHB_DIV_CLK_SRC
] = &gpu_cc_hub_ahb_div_clk_src
.clkr
,
513 [GPU_CC_HUB_AON_CLK
] = &gpu_cc_hub_aon_clk
.clkr
,
514 [GPU_CC_HUB_CLK_SRC
] = &gpu_cc_hub_clk_src
.clkr
,
515 [GPU_CC_HUB_CX_INT_CLK
] = &gpu_cc_hub_cx_int_clk
.clkr
,
516 [GPU_CC_HUB_CX_INT_DIV_CLK_SRC
] = &gpu_cc_hub_cx_int_div_clk_src
.clkr
,
517 [GPU_CC_MEMNOC_GFX_CLK
] = &gpu_cc_memnoc_gfx_clk
.clkr
,
518 [GPU_CC_PLL0
] = &gpu_cc_pll0
.clkr
,
519 [GPU_CC_PLL1
] = &gpu_cc_pll1
.clkr
,
520 [GPU_CC_SLEEP_CLK
] = &gpu_cc_sleep_clk
.clkr
,
521 [GPU_CC_XO_CLK_SRC
] = &gpu_cc_xo_clk_src
.clkr
,
524 static struct gdsc cx_gdsc
= {
526 .en_rest_wait_val
= 0x2,
527 .en_few_wait_val
= 0x2,
528 .clk_dis_wait_val
= 0xf,
529 .gds_hw_ctrl
= 0x953c,
533 .pwrsts
= PWRSTS_OFF_ON
,
534 .flags
= VOTABLE
| RETAIN_FF_ENABLE
,
537 static struct gdsc gx_gdsc
= {
539 .en_rest_wait_val
= 0x2,
540 .en_few_wait_val
= 0x2,
541 .clk_dis_wait_val
= 0xf,
544 .power_on
= gdsc_gx_do_nothing_enable
,
546 .pwrsts
= PWRSTS_OFF_ON
,
547 .flags
= AON_RESET
| RETAIN_FF_ENABLE
,
550 static struct gdsc
*gpu_cc_sa8775p_gdscs
[] = {
551 [GPU_CC_CX_GDSC
] = &cx_gdsc
,
552 [GPU_CC_GX_GDSC
] = &gx_gdsc
,
555 static const struct qcom_reset_map gpu_cc_sa8775p_resets
[] = {
556 [GPUCC_GPU_CC_ACD_BCR
] = { 0x9358 },
557 [GPUCC_GPU_CC_CB_BCR
] = { 0x93a0 },
558 [GPUCC_GPU_CC_CX_BCR
] = { 0x9104 },
559 [GPUCC_GPU_CC_FAST_HUB_BCR
] = { 0x93e4 },
560 [GPUCC_GPU_CC_FF_BCR
] = { 0x9470 },
561 [GPUCC_GPU_CC_GFX3D_AON_BCR
] = { 0x9198 },
562 [GPUCC_GPU_CC_GMU_BCR
] = { 0x9314 },
563 [GPUCC_GPU_CC_GX_BCR
] = { 0x9058 },
564 [GPUCC_GPU_CC_XO_BCR
] = { 0x9000 },
567 static const struct regmap_config gpu_cc_sa8775p_regmap_config
= {
571 .max_register
= 0x9988,
575 static const struct qcom_cc_desc gpu_cc_sa8775p_desc
= {
576 .config
= &gpu_cc_sa8775p_regmap_config
,
577 .clks
= gpu_cc_sa8775p_clocks
,
578 .num_clks
= ARRAY_SIZE(gpu_cc_sa8775p_clocks
),
579 .resets
= gpu_cc_sa8775p_resets
,
580 .num_resets
= ARRAY_SIZE(gpu_cc_sa8775p_resets
),
581 .gdscs
= gpu_cc_sa8775p_gdscs
,
582 .num_gdscs
= ARRAY_SIZE(gpu_cc_sa8775p_gdscs
),
585 static const struct of_device_id gpu_cc_sa8775p_match_table
[] = {
586 { .compatible
= "qcom,sa8775p-gpucc" },
589 MODULE_DEVICE_TABLE(of
, gpu_cc_sa8775p_match_table
);
591 static int gpu_cc_sa8775p_probe(struct platform_device
*pdev
)
593 struct regmap
*regmap
;
595 regmap
= qcom_cc_map(pdev
, &gpu_cc_sa8775p_desc
);
597 return PTR_ERR(regmap
);
599 clk_lucid_evo_pll_configure(&gpu_cc_pll0
, regmap
, &gpu_cc_pll0_config
);
600 clk_lucid_evo_pll_configure(&gpu_cc_pll1
, regmap
, &gpu_cc_pll1_config
);
602 return qcom_cc_really_probe(&pdev
->dev
, &gpu_cc_sa8775p_desc
, regmap
);
605 static struct platform_driver gpu_cc_sa8775p_driver
= {
606 .probe
= gpu_cc_sa8775p_probe
,
608 .name
= "gpu_cc-sa8775p",
609 .of_match_table
= gpu_cc_sa8775p_match_table
,
613 module_platform_driver(gpu_cc_sa8775p_driver
);
615 MODULE_DESCRIPTION("SA8775P GPUCC driver");
616 MODULE_LICENSE("GPL");