1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
4 * Copyright (c) 2023, Linaro Limited
7 #include <linux/clk-provider.h>
8 #include <linux/module.h>
9 #include <linux/of_device.h>
10 #include <linux/regmap.h>
12 #include <dt-bindings/clock/qcom,sm6115-gpucc.h>
14 #include "clk-alpha-pll.h"
15 #include "clk-branch.h"
17 #include "clk-regmap.h"
18 #include "clk-regmap-divider.h"
19 #include "clk-regmap-mux.h"
20 #include "clk-regmap-phy-mux.h"
26 DT_GCC_GPU_GPLL0_CLK_SRC,
27 DT_GCC_GPU_GPLL0_DIV_CLK_SRC,
34 P_GPU_CC_PLL0_OUT_AUX2,
35 P_GPU_CC_PLL0_OUT_MAIN,
36 P_GPU_CC_PLL1_OUT_AUX,
37 P_GPU_CC_PLL1_OUT_MAIN,
40 static struct pll_vco default_vco[] = {
41 { 1000000000, 2000000000, 0 },
44 static struct pll_vco pll1_vco[] = {
45 { 500000000, 1000000000, 2 },
48 static const struct alpha_pll_config gpu_cc_pll0_config = {
53 .vco_mask = GENMASK(21, 20),
54 .alpha_en_mask = BIT(24),
55 .main_output_mask = BIT(0),
56 .aux_output_mask = BIT(1),
57 .aux2_output_mask = BIT(2),
58 .config_ctl_val = 0x4001055b,
59 .test_ctl_hi1_val = 0x1,
62 /* 1200MHz configuration */
63 static struct clk_alpha_pll gpu_cc_pll0 = {
65 .vco_table = default_vco,
66 .num_vco = ARRAY_SIZE(default_vco),
67 .flags = SUPPORTS_DYNAMIC_UPDATE,
68 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
70 .hw.init = &(struct clk_init_data){
71 .name = "gpu_cc_pll0",
72 .parent_data = &(const struct clk_parent_data){
76 .ops = &clk_alpha_pll_ops,
81 static const struct clk_div_table post_div_table_gpu_cc_pll0_out_aux2[] = {
86 static struct clk_alpha_pll_postdiv gpu_cc_pll0_out_aux2 = {
89 .post_div_table = post_div_table_gpu_cc_pll0_out_aux2,
90 .num_post_div = ARRAY_SIZE(post_div_table_gpu_cc_pll0_out_aux2),
92 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
93 .clkr.hw.init = &(struct clk_init_data){
94 .name = "gpu_cc_pll0_out_aux2",
95 .parent_hws = (const struct clk_hw*[]) {
99 .flags = CLK_SET_RATE_PARENT,
100 .ops = &clk_alpha_pll_postdiv_ops,
104 /* 640MHz configuration */
105 static const struct alpha_pll_config gpu_cc_pll1_config = {
109 .alpha_en_mask = BIT(24),
110 .vco_val = 0x2 << 20,
111 .vco_mask = GENMASK(21, 20),
112 .main_output_mask = BIT(0),
113 .aux_output_mask = BIT(1),
114 .config_ctl_val = 0x4001055b,
115 .test_ctl_hi1_val = 0x1,
118 static struct clk_alpha_pll gpu_cc_pll1 = {
120 .vco_table = pll1_vco,
121 .num_vco = ARRAY_SIZE(pll1_vco),
122 .flags = SUPPORTS_DYNAMIC_UPDATE,
123 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
125 .hw.init = &(struct clk_init_data){
126 .name = "gpu_cc_pll1",
127 .parent_data = &(const struct clk_parent_data){
131 .ops = &clk_alpha_pll_ops,
136 static const struct clk_div_table post_div_table_gpu_cc_pll1_out_aux[] = {
141 static struct clk_alpha_pll_postdiv gpu_cc_pll1_out_aux = {
143 .post_div_shift = 15,
144 .post_div_table = post_div_table_gpu_cc_pll1_out_aux,
145 .num_post_div = ARRAY_SIZE(post_div_table_gpu_cc_pll1_out_aux),
147 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
148 .clkr.hw.init = &(struct clk_init_data){
149 .name = "gpu_cc_pll1_out_aux",
150 .parent_hws = (const struct clk_hw*[]) {
151 &gpu_cc_pll1.clkr.hw,
154 .flags = CLK_SET_RATE_PARENT,
155 .ops = &clk_alpha_pll_postdiv_ops,
159 static const struct parent_map gpu_cc_parent_map_0[] = {
161 { P_GPU_CC_PLL0_OUT_MAIN, 1 },
162 { P_GPU_CC_PLL1_OUT_MAIN, 3 },
163 { P_GPLL0_OUT_MAIN, 5 },
164 { P_GPLL0_OUT_MAIN_DIV, 6 },
167 static const struct clk_parent_data gpu_cc_parent_data_0[] = {
168 { .index = P_BI_TCXO },
169 { .hw = &gpu_cc_pll0.clkr.hw },
170 { .hw = &gpu_cc_pll1.clkr.hw },
171 { .index = DT_GCC_GPU_GPLL0_CLK_SRC },
172 { .index = DT_GCC_GPU_GPLL0_DIV_CLK_SRC },
175 static const struct parent_map gpu_cc_parent_map_1[] = {
177 { P_GPU_CC_PLL0_OUT_AUX2, 2 },
178 { P_GPU_CC_PLL1_OUT_AUX, 3 },
179 { P_GPLL0_OUT_MAIN, 5 },
182 static const struct clk_parent_data gpu_cc_parent_data_1[] = {
183 { .index = P_BI_TCXO },
184 { .hw = &gpu_cc_pll0_out_aux2.clkr.hw },
185 { .hw = &gpu_cc_pll1_out_aux.clkr.hw },
186 { .index = DT_GCC_GPU_GPLL0_CLK_SRC },
189 static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src[] = {
190 F(200000000, P_GPLL0_OUT_MAIN, 3, 0, 0),
194 static struct clk_rcg2 gpu_cc_gmu_clk_src = {
198 .parent_map = gpu_cc_parent_map_0,
199 .freq_tbl = ftbl_gpu_cc_gmu_clk_src,
200 .clkr.hw.init = &(struct clk_init_data){
201 .name = "gpu_cc_gmu_clk_src",
202 .parent_data = gpu_cc_parent_data_0,
203 .num_parents = ARRAY_SIZE(gpu_cc_parent_data_0),
204 .flags = CLK_SET_RATE_PARENT,
205 .ops = &clk_rcg2_shared_ops,
209 static const struct freq_tbl ftbl_gpu_cc_gx_gfx3d_clk_src[] = {
210 F(320000000, P_GPU_CC_PLL1_OUT_AUX, 2, 0, 0),
211 F(465000000, P_GPU_CC_PLL1_OUT_AUX, 2, 0, 0),
212 F(600000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
213 F(745000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
214 F(820000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
215 F(900000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
216 F(950000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
217 F(980000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
221 static struct clk_rcg2 gpu_cc_gx_gfx3d_clk_src = {
225 .parent_map = gpu_cc_parent_map_1,
226 .freq_tbl = ftbl_gpu_cc_gx_gfx3d_clk_src,
227 .clkr.hw.init = &(struct clk_init_data){
228 .name = "gpu_cc_gx_gfx3d_clk_src",
229 .parent_data = gpu_cc_parent_data_1,
230 .num_parents = ARRAY_SIZE(gpu_cc_parent_data_1),
231 .flags = CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
232 .ops = &clk_rcg2_ops,
236 static struct clk_branch gpu_cc_ahb_clk = {
238 .halt_check = BRANCH_HALT_DELAY,
240 .enable_reg = 0x1078,
241 .enable_mask = BIT(0),
242 .hw.init = &(struct clk_init_data){
243 .name = "gpu_cc_ahb_clk",
244 .flags = CLK_IS_CRITICAL,
245 .ops = &clk_branch2_ops,
250 static struct clk_branch gpu_cc_crc_ahb_clk = {
252 .halt_check = BRANCH_HALT_DELAY,
254 .enable_reg = 0x107c,
255 .enable_mask = BIT(0),
256 .hw.init = &(struct clk_init_data){
257 .name = "gpu_cc_crc_ahb_clk",
258 .ops = &clk_branch2_ops,
263 static struct clk_branch gpu_cc_cx_gfx3d_clk = {
265 .halt_check = BRANCH_HALT_DELAY,
267 .enable_reg = 0x10a4,
268 .enable_mask = BIT(0),
269 .hw.init = &(struct clk_init_data){
270 .name = "gpu_cc_cx_gfx3d_clk",
271 .parent_data = &(const struct clk_parent_data){
272 .hw = &gpu_cc_gx_gfx3d_clk_src.clkr.hw,
275 .flags = CLK_SET_RATE_PARENT,
276 .ops = &clk_branch2_ops,
281 static struct clk_branch gpu_cc_cx_gmu_clk = {
283 .halt_check = BRANCH_HALT,
285 .enable_reg = 0x1098,
286 .enable_mask = BIT(0),
287 .hw.init = &(struct clk_init_data){
288 .name = "gpu_cc_cx_gmu_clk",
289 .parent_data = &(const struct clk_parent_data){
290 .hw = &gpu_cc_gmu_clk_src.clkr.hw,
293 .flags = CLK_SET_RATE_PARENT,
294 .ops = &clk_branch2_ops,
299 static struct clk_branch gpu_cc_cx_snoc_dvm_clk = {
301 .halt_check = BRANCH_HALT_DELAY,
303 .enable_reg = 0x108c,
304 .enable_mask = BIT(0),
305 .hw.init = &(struct clk_init_data){
306 .name = "gpu_cc_cx_snoc_dvm_clk",
307 .ops = &clk_branch2_ops,
312 static struct clk_branch gpu_cc_cxo_aon_clk = {
314 .halt_check = BRANCH_HALT_DELAY,
316 .enable_reg = 0x1004,
317 .enable_mask = BIT(0),
318 .hw.init = &(struct clk_init_data){
319 .name = "gpu_cc_cxo_aon_clk",
320 .ops = &clk_branch2_ops,
325 static struct clk_branch gpu_cc_cxo_clk = {
327 .halt_check = BRANCH_HALT,
329 .enable_reg = 0x109c,
330 .enable_mask = BIT(0),
331 .hw.init = &(struct clk_init_data){
332 .name = "gpu_cc_cxo_clk",
333 .ops = &clk_branch2_ops,
338 static struct clk_branch gpu_cc_gx_cxo_clk = {
340 .halt_check = BRANCH_HALT_DELAY,
342 .enable_reg = 0x1060,
343 .enable_mask = BIT(0),
344 .hw.init = &(struct clk_init_data){
345 .name = "gpu_cc_gx_cxo_clk",
346 .flags = CLK_IS_CRITICAL,
347 .ops = &clk_branch2_ops,
352 static struct clk_branch gpu_cc_gx_gfx3d_clk = {
354 .halt_check = BRANCH_HALT_SKIP,
356 .enable_reg = 0x1054,
357 .enable_mask = BIT(0),
358 .hw.init = &(struct clk_init_data){
359 .name = "gpu_cc_gx_gfx3d_clk",
360 .parent_data = &(const struct clk_parent_data){
361 .hw = &gpu_cc_gx_gfx3d_clk_src.clkr.hw,
364 .flags = CLK_SET_RATE_PARENT,
365 .ops = &clk_branch2_ops,
370 static struct clk_branch gpu_cc_sleep_clk = {
372 .halt_check = BRANCH_HALT_DELAY,
374 .enable_reg = 0x1090,
375 .enable_mask = BIT(0),
376 .hw.init = &(struct clk_init_data){
377 .name = "gpu_cc_sleep_clk",
378 .ops = &clk_branch2_ops,
383 static struct clk_branch gpu_cc_hlos1_vote_gpu_smmu_clk = {
385 .halt_check = BRANCH_VOTED,
387 .enable_reg = 0x5000,
388 .enable_mask = BIT(0),
389 .hw.init = &(struct clk_init_data){
390 .name = "gpu_cc_hlos1_vote_gpu_smmu_clk",
391 .ops = &clk_branch2_ops,
396 static struct gdsc gpu_cx_gdsc = {
398 .gds_hw_ctrl = 0x1540,
400 .name = "gpu_cx_gdsc",
402 .pwrsts = PWRSTS_OFF_ON,
406 static struct gdsc gpu_gx_gdsc = {
408 .clamp_io_ctrl = 0x1508,
409 .resets = (unsigned int []){ GPU_GX_BCR },
412 .name = "gpu_gx_gdsc",
414 .parent = &gpu_cx_gdsc.pd,
415 .pwrsts = PWRSTS_OFF_ON,
416 .flags = CLAMP_IO | SW_RESET | VOTABLE,
419 static struct clk_regmap *gpu_cc_sm6115_clocks[] = {
420 [GPU_CC_AHB_CLK] = &gpu_cc_ahb_clk.clkr,
421 [GPU_CC_CRC_AHB_CLK] = &gpu_cc_crc_ahb_clk.clkr,
422 [GPU_CC_CX_GFX3D_CLK] = &gpu_cc_cx_gfx3d_clk.clkr,
423 [GPU_CC_CX_GMU_CLK] = &gpu_cc_cx_gmu_clk.clkr,
424 [GPU_CC_CX_SNOC_DVM_CLK] = &gpu_cc_cx_snoc_dvm_clk.clkr,
425 [GPU_CC_CXO_AON_CLK] = &gpu_cc_cxo_aon_clk.clkr,
426 [GPU_CC_CXO_CLK] = &gpu_cc_cxo_clk.clkr,
427 [GPU_CC_GMU_CLK_SRC] = &gpu_cc_gmu_clk_src.clkr,
428 [GPU_CC_GX_CXO_CLK] = &gpu_cc_gx_cxo_clk.clkr,
429 [GPU_CC_GX_GFX3D_CLK] = &gpu_cc_gx_gfx3d_clk.clkr,
430 [GPU_CC_GX_GFX3D_CLK_SRC] = &gpu_cc_gx_gfx3d_clk_src.clkr,
431 [GPU_CC_PLL0] = &gpu_cc_pll0.clkr,
432 [GPU_CC_PLL0_OUT_AUX2] = &gpu_cc_pll0_out_aux2.clkr,
433 [GPU_CC_PLL1] = &gpu_cc_pll1.clkr,
434 [GPU_CC_PLL1_OUT_AUX] = &gpu_cc_pll1_out_aux.clkr,
435 [GPU_CC_SLEEP_CLK] = &gpu_cc_sleep_clk.clkr,
436 [GPU_CC_HLOS1_VOTE_GPU_SMMU_CLK] = &gpu_cc_hlos1_vote_gpu_smmu_clk.clkr,
439 static const struct qcom_reset_map gpu_cc_sm6115_resets[] = {
440 [GPU_GX_BCR] = { 0x1008 },
443 static struct gdsc *gpu_cc_sm6115_gdscs[] = {
444 [GPU_CX_GDSC] = &gpu_cx_gdsc,
445 [GPU_GX_GDSC] = &gpu_gx_gdsc,
448 static const struct regmap_config gpu_cc_sm6115_regmap_config = {
452 .max_register = 0x9000,
456 static const struct qcom_cc_desc gpu_cc_sm6115_desc = {
457 .config = &gpu_cc_sm6115_regmap_config,
458 .clks = gpu_cc_sm6115_clocks,
459 .num_clks = ARRAY_SIZE(gpu_cc_sm6115_clocks),
460 .resets = gpu_cc_sm6115_resets,
461 .num_resets = ARRAY_SIZE(gpu_cc_sm6115_resets),
462 .gdscs = gpu_cc_sm6115_gdscs,
463 .num_gdscs = ARRAY_SIZE(gpu_cc_sm6115_gdscs),
466 static const struct of_device_id gpu_cc_sm6115_match_table[] = {
467 { .compatible = "qcom,sm6115-gpucc" },
470 MODULE_DEVICE_TABLE(of, gpu_cc_sm6115_match_table);
472 static int gpu_cc_sm6115_probe(struct platform_device *pdev)
474 struct regmap *regmap;
476 regmap = qcom_cc_map(pdev, &gpu_cc_sm6115_desc);
478 return PTR_ERR(regmap);
480 clk_alpha_pll_configure(&gpu_cc_pll0, regmap, &gpu_cc_pll0_config);
481 clk_alpha_pll_configure(&gpu_cc_pll1, regmap, &gpu_cc_pll1_config);
483 /* Set recommended WAKEUP/SLEEP settings for the gpu_cc_cx_gmu_clk */
484 qcom_branch_set_wakeup(regmap, gpu_cc_cx_gmu_clk, 0xf);
485 qcom_branch_set_sleep(regmap, gpu_cc_cx_gmu_clk, 0xf);
487 qcom_branch_set_force_mem_core(regmap, gpu_cc_gx_gfx3d_clk, true);
488 qcom_branch_set_force_periph_on(regmap, gpu_cc_gx_gfx3d_clk, true);
490 return qcom_cc_really_probe(pdev, &gpu_cc_sm6115_desc, regmap);
493 static struct platform_driver gpu_cc_sm6115_driver = {
494 .probe = gpu_cc_sm6115_probe,
496 .name = "sm6115-gpucc",
497 .of_match_table = gpu_cc_sm6115_match_table,
500 module_platform_driver(gpu_cc_sm6115_driver);
502 MODULE_DESCRIPTION("QTI GPU_CC SM6115 Driver");
503 MODULE_LICENSE("GPL");