1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2019, 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,sm6125-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,
33 P_GPU_CC_PLL0_OUT_AUX2,
34 P_GPU_CC_PLL1_OUT_AUX,
35 P_GPU_CC_PLL1_OUT_AUX2,
38 static struct pll_vco gpu_cc_pll_vco[] = {
39 { 1000000000, 2000000000, 0 },
40 { 500000000, 1000000000, 2 },
43 /* 1020MHz configuration */
44 static const struct alpha_pll_config gpu_pll0_config = {
46 .config_ctl_val = 0x4001055b,
49 .alpha_en_mask = BIT(24),
51 .vco_mask = 0x3 << 20,
52 .aux2_output_mask = BIT(2),
55 /* 930MHz configuration */
56 static const struct alpha_pll_config gpu_pll1_config = {
58 .config_ctl_val = 0x4001055b,
61 .alpha_en_mask = BIT(24),
63 .vco_mask = 0x3 << 20,
64 .aux2_output_mask = BIT(2),
67 static struct clk_alpha_pll gpu_cc_pll0_out_aux2 = {
69 .vco_table = gpu_cc_pll_vco,
70 .num_vco = ARRAY_SIZE(gpu_cc_pll_vco),
71 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
72 .flags = SUPPORTS_DYNAMIC_UPDATE,
74 .hw.init = &(struct clk_init_data){
75 .name = "gpu_cc_pll0_out_aux2",
76 .parent_data = &(const struct clk_parent_data) {
80 .ops = &clk_alpha_pll_ops,
85 static struct clk_alpha_pll gpu_cc_pll1_out_aux2 = {
87 .vco_table = gpu_cc_pll_vco,
88 .num_vco = ARRAY_SIZE(gpu_cc_pll_vco),
89 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
90 .flags = SUPPORTS_DYNAMIC_UPDATE,
92 .hw.init = &(struct clk_init_data){
93 .name = "gpu_cc_pll1_out_aux2",
94 .parent_data = &(const struct clk_parent_data) {
98 .ops = &clk_alpha_pll_ops,
103 static const struct parent_map gpu_cc_parent_map_0[] = {
105 { P_GPLL0_OUT_MAIN, 5 },
108 static const struct clk_parent_data gpu_cc_parent_data_0[] = {
109 { .index = DT_BI_TCXO },
110 { .index = DT_GCC_GPU_GPLL0_CLK_SRC },
113 static const struct parent_map gpu_cc_parent_map_1[] = {
115 { P_GPU_CC_PLL0_OUT_AUX2, 2 },
116 { P_GPU_CC_PLL1_OUT_AUX2, 4 },
119 static const struct clk_parent_data gpu_cc_parent_data_1[] = {
120 { .index = DT_BI_TCXO },
121 { .hw = &gpu_cc_pll0_out_aux2.clkr.hw },
122 { .hw = &gpu_cc_pll1_out_aux2.clkr.hw },
125 static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src[] = {
126 F(200000000, P_GPLL0_OUT_MAIN, 3, 0, 0),
130 static struct clk_rcg2 gpu_cc_gmu_clk_src = {
134 .parent_map = gpu_cc_parent_map_0,
135 .freq_tbl = ftbl_gpu_cc_gmu_clk_src,
136 .clkr.hw.init = &(struct clk_init_data){
137 .name = "gpu_cc_gmu_clk_src",
138 .parent_data = gpu_cc_parent_data_0,
139 .num_parents = ARRAY_SIZE(gpu_cc_parent_data_0),
140 .ops = &clk_rcg2_shared_ops,
144 static const struct freq_tbl ftbl_gpu_cc_gx_gfx3d_clk_src[] = {
145 F(320000000, P_GPU_CC_PLL1_OUT_AUX2, 2, 0, 0),
146 F(465000000, P_GPU_CC_PLL1_OUT_AUX2, 2, 0, 0),
147 F(600000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
148 F(745000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
149 F(820000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
150 F(900000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
151 F(950000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
155 static struct clk_rcg2 gpu_cc_gx_gfx3d_clk_src = {
159 .parent_map = gpu_cc_parent_map_1,
160 .freq_tbl = ftbl_gpu_cc_gx_gfx3d_clk_src,
161 .clkr.hw.init = &(struct clk_init_data){
162 .name = "gpu_cc_gx_gfx3d_clk_src",
163 .parent_data = gpu_cc_parent_data_1,
164 .num_parents = ARRAY_SIZE(gpu_cc_parent_data_1),
165 .flags = CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
166 .ops = &clk_rcg2_ops,
170 static struct clk_branch gpu_cc_crc_ahb_clk = {
172 .halt_check = BRANCH_HALT_DELAY,
174 .enable_reg = 0x107c,
175 .enable_mask = BIT(0),
176 .hw.init = &(struct clk_init_data){
177 .name = "gpu_cc_crc_ahb_clk",
178 .ops = &clk_branch2_ops,
183 static struct clk_branch gpu_cc_cx_apb_clk = {
185 .halt_check = BRANCH_HALT_DELAY,
187 .enable_reg = 0x1088,
188 .enable_mask = BIT(0),
189 .hw.init = &(struct clk_init_data){
190 .name = "gpu_cc_cx_apb_clk",
191 .ops = &clk_branch2_ops,
196 static struct clk_branch gpu_cc_gx_gfx3d_clk = {
198 .halt_check = BRANCH_HALT_SKIP,
200 .enable_reg = 0x1054,
201 .enable_mask = BIT(0),
202 .hw.init = &(struct clk_init_data){
203 .name = "gpu_cc_gx_gfx3d_clk",
204 .parent_hws = (const struct clk_hw*[]) {
205 &gpu_cc_gx_gfx3d_clk_src.clkr.hw,
208 .flags = CLK_SET_RATE_PARENT,
209 .ops = &clk_branch2_ops,
214 static struct clk_branch gpu_cc_cx_gfx3d_clk = {
216 .halt_check = BRANCH_HALT_DELAY,
218 .enable_reg = 0x10a4,
219 .enable_mask = BIT(0),
220 .hw.init = &(struct clk_init_data){
221 .name = "gpu_cc_cx_gfx3d_clk",
222 .parent_hws = (const struct clk_hw*[]) {
223 &gpu_cc_gx_gfx3d_clk.clkr.hw,
226 .flags = CLK_SET_RATE_PARENT,
227 .ops = &clk_branch2_ops,
232 static struct clk_branch gpu_cc_cx_gmu_clk = {
234 .halt_check = BRANCH_HALT,
236 .enable_reg = 0x1098,
237 .enable_mask = BIT(0),
238 .hw.init = &(struct clk_init_data){
239 .name = "gpu_cc_cx_gmu_clk",
240 .parent_hws = (const struct clk_hw*[]) {
241 &gpu_cc_gmu_clk_src.clkr.hw,
244 .flags = CLK_SET_RATE_PARENT,
245 .ops = &clk_branch2_ops,
250 static struct clk_branch gpu_cc_cx_snoc_dvm_clk = {
252 .halt_check = BRANCH_HALT_DELAY,
254 .enable_reg = 0x108c,
255 .enable_mask = BIT(0),
256 .hw.init = &(struct clk_init_data){
257 .name = "gpu_cc_cx_snoc_dvm_clk",
258 .ops = &clk_branch2_ops,
263 static struct clk_branch gpu_cc_cxo_aon_clk = {
265 .halt_check = BRANCH_HALT_DELAY,
267 .enable_reg = 0x1004,
268 .enable_mask = BIT(0),
269 .hw.init = &(struct clk_init_data){
270 .name = "gpu_cc_cxo_aon_clk",
271 .ops = &clk_branch2_ops,
276 static struct clk_branch gpu_cc_cxo_clk = {
278 .halt_check = BRANCH_HALT,
280 .enable_reg = 0x109c,
281 .enable_mask = BIT(0),
282 .hw.init = &(struct clk_init_data){
283 .name = "gpu_cc_cxo_clk",
284 .ops = &clk_branch2_ops,
289 static struct clk_branch gpu_cc_sleep_clk = {
291 .halt_check = BRANCH_HALT_DELAY,
293 .enable_reg = 0x1090,
294 .enable_mask = BIT(0),
295 .hw.init = &(struct clk_init_data){
296 .name = "gpu_cc_sleep_clk",
297 .ops = &clk_branch2_ops,
302 static struct clk_branch gpu_cc_ahb_clk = {
304 .halt_check = BRANCH_HALT_DELAY,
306 .enable_reg = 0x1078,
307 .enable_mask = BIT(0),
308 .hw.init = &(struct clk_init_data){
309 .name = "gpu_cc_ahb_clk",
310 .flags = CLK_IS_CRITICAL,
311 .ops = &clk_branch2_ops,
316 static struct clk_branch gpu_cc_hlos1_vote_gpu_smmu_clk = {
318 .halt_check = BRANCH_VOTED,
320 .enable_reg = 0x5000,
321 .enable_mask = BIT(0),
322 .hw.init = &(struct clk_init_data){
323 .name = "gpu_cc_hlos1_vote_gpu_smmu_clk",
324 .ops = &clk_branch2_ops,
329 static struct gdsc gpu_cx_gdsc = {
331 .gds_hw_ctrl = 0x1540,
333 .name = "gpu_cx_gdsc",
335 .pwrsts = PWRSTS_OFF_ON,
339 static struct gdsc gpu_gx_gdsc = {
342 .name = "gpu_gx_gdsc",
344 .pwrsts = PWRSTS_OFF_ON,
348 static struct clk_regmap *gpu_cc_sm6125_clocks[] = {
349 [GPU_CC_CRC_AHB_CLK] = &gpu_cc_crc_ahb_clk.clkr,
350 [GPU_CC_CX_APB_CLK] = &gpu_cc_cx_apb_clk.clkr,
351 [GPU_CC_CX_GFX3D_CLK] = &gpu_cc_cx_gfx3d_clk.clkr,
352 [GPU_CC_CX_GMU_CLK] = &gpu_cc_cx_gmu_clk.clkr,
353 [GPU_CC_CX_SNOC_DVM_CLK] = &gpu_cc_cx_snoc_dvm_clk.clkr,
354 [GPU_CC_CXO_AON_CLK] = &gpu_cc_cxo_aon_clk.clkr,
355 [GPU_CC_CXO_CLK] = &gpu_cc_cxo_clk.clkr,
356 [GPU_CC_GMU_CLK_SRC] = &gpu_cc_gmu_clk_src.clkr,
357 [GPU_CC_PLL0_OUT_AUX2] = &gpu_cc_pll0_out_aux2.clkr,
358 [GPU_CC_PLL1_OUT_AUX2] = &gpu_cc_pll1_out_aux2.clkr,
359 [GPU_CC_SLEEP_CLK] = &gpu_cc_sleep_clk.clkr,
360 [GPU_CC_GX_GFX3D_CLK] = &gpu_cc_gx_gfx3d_clk.clkr,
361 [GPU_CC_GX_GFX3D_CLK_SRC] = &gpu_cc_gx_gfx3d_clk_src.clkr,
362 [GPU_CC_AHB_CLK] = &gpu_cc_ahb_clk.clkr,
363 [GPU_CC_HLOS1_VOTE_GPU_SMMU_CLK] = &gpu_cc_hlos1_vote_gpu_smmu_clk.clkr,
366 static struct gdsc *gpucc_sm6125_gdscs[] = {
367 [GPU_CX_GDSC] = &gpu_cx_gdsc,
368 [GPU_GX_GDSC] = &gpu_gx_gdsc,
371 static const struct regmap_config gpu_cc_sm6125_regmap_config = {
375 .max_register = 0x9000,
379 static const struct qcom_cc_desc gpu_cc_sm6125_desc = {
380 .config = &gpu_cc_sm6125_regmap_config,
381 .clks = gpu_cc_sm6125_clocks,
382 .num_clks = ARRAY_SIZE(gpu_cc_sm6125_clocks),
383 .gdscs = gpucc_sm6125_gdscs,
384 .num_gdscs = ARRAY_SIZE(gpucc_sm6125_gdscs),
387 static const struct of_device_id gpu_cc_sm6125_match_table[] = {
388 { .compatible = "qcom,sm6125-gpucc" },
391 MODULE_DEVICE_TABLE(of, gpu_cc_sm6125_match_table);
393 static int gpu_cc_sm6125_probe(struct platform_device *pdev)
395 struct regmap *regmap;
397 regmap = qcom_cc_map(pdev, &gpu_cc_sm6125_desc);
399 return PTR_ERR(regmap);
401 clk_alpha_pll_configure(&gpu_cc_pll0_out_aux2, regmap, &gpu_pll0_config);
402 clk_alpha_pll_configure(&gpu_cc_pll1_out_aux2, regmap, &gpu_pll1_config);
404 /* Set recommended WAKEUP/SLEEP settings for the gpu_cc_cx_gmu_clk */
405 qcom_branch_set_wakeup(regmap, gpu_cc_cx_gmu_clk, 0xf);
406 qcom_branch_set_sleep(regmap, gpu_cc_cx_gmu_clk, 0xf);
408 qcom_branch_set_force_mem_core(regmap, gpu_cc_gx_gfx3d_clk, true);
409 qcom_branch_set_force_periph_on(regmap, gpu_cc_gx_gfx3d_clk, true);
411 return qcom_cc_really_probe(pdev, &gpu_cc_sm6125_desc, regmap);
414 static struct platform_driver gpu_cc_sm6125_driver = {
415 .probe = gpu_cc_sm6125_probe,
417 .name = "gpucc-sm6125",
418 .of_match_table = gpu_cc_sm6125_match_table,
421 module_platform_driver(gpu_cc_sm6125_driver);
423 MODULE_DESCRIPTION("QTI GPUCC SM6125 Driver");
424 MODULE_LICENSE("GPL");