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/mod_devicetable.h>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <linux/regmap.h>
13 #include <dt-bindings/clock/qcom,sm6125-gpucc.h>
15 #include "clk-alpha-pll.h"
16 #include "clk-branch.h"
18 #include "clk-regmap.h"
19 #include "clk-regmap-divider.h"
20 #include "clk-regmap-mux.h"
21 #include "clk-regmap-phy-mux.h"
27 DT_GCC_GPU_GPLL0_CLK_SRC,
34 P_GPU_CC_PLL0_OUT_AUX2,
35 P_GPU_CC_PLL1_OUT_AUX,
36 P_GPU_CC_PLL1_OUT_AUX2,
39 static struct pll_vco gpu_cc_pll_vco[] = {
40 { 1000000000, 2000000000, 0 },
41 { 500000000, 1000000000, 2 },
44 /* 1020MHz configuration */
45 static const struct alpha_pll_config gpu_pll0_config = {
47 .config_ctl_val = 0x4001055b,
50 .alpha_en_mask = BIT(24),
52 .vco_mask = 0x3 << 20,
53 .aux2_output_mask = BIT(2),
56 /* 930MHz configuration */
57 static const struct alpha_pll_config gpu_pll1_config = {
59 .config_ctl_val = 0x4001055b,
62 .alpha_en_mask = BIT(24),
64 .vco_mask = 0x3 << 20,
65 .aux2_output_mask = BIT(2),
68 static struct clk_alpha_pll gpu_cc_pll0_out_aux2 = {
70 .vco_table = gpu_cc_pll_vco,
71 .num_vco = ARRAY_SIZE(gpu_cc_pll_vco),
72 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
73 .flags = SUPPORTS_DYNAMIC_UPDATE,
75 .hw.init = &(struct clk_init_data){
76 .name = "gpu_cc_pll0_out_aux2",
77 .parent_data = &(const struct clk_parent_data) {
81 .ops = &clk_alpha_pll_ops,
86 static struct clk_alpha_pll gpu_cc_pll1_out_aux2 = {
88 .vco_table = gpu_cc_pll_vco,
89 .num_vco = ARRAY_SIZE(gpu_cc_pll_vco),
90 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
91 .flags = SUPPORTS_DYNAMIC_UPDATE,
93 .hw.init = &(struct clk_init_data){
94 .name = "gpu_cc_pll1_out_aux2",
95 .parent_data = &(const struct clk_parent_data) {
99 .ops = &clk_alpha_pll_ops,
104 static const struct parent_map gpu_cc_parent_map_0[] = {
106 { P_GPLL0_OUT_MAIN, 5 },
109 static const struct clk_parent_data gpu_cc_parent_data_0[] = {
110 { .index = DT_BI_TCXO },
111 { .index = DT_GCC_GPU_GPLL0_CLK_SRC },
114 static const struct parent_map gpu_cc_parent_map_1[] = {
116 { P_GPU_CC_PLL0_OUT_AUX2, 2 },
117 { P_GPU_CC_PLL1_OUT_AUX2, 4 },
120 static const struct clk_parent_data gpu_cc_parent_data_1[] = {
121 { .index = DT_BI_TCXO },
122 { .hw = &gpu_cc_pll0_out_aux2.clkr.hw },
123 { .hw = &gpu_cc_pll1_out_aux2.clkr.hw },
126 static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src[] = {
127 F(200000000, P_GPLL0_OUT_MAIN, 3, 0, 0),
131 static struct clk_rcg2 gpu_cc_gmu_clk_src = {
135 .parent_map = gpu_cc_parent_map_0,
136 .freq_tbl = ftbl_gpu_cc_gmu_clk_src,
137 .clkr.hw.init = &(struct clk_init_data){
138 .name = "gpu_cc_gmu_clk_src",
139 .parent_data = gpu_cc_parent_data_0,
140 .num_parents = ARRAY_SIZE(gpu_cc_parent_data_0),
141 .ops = &clk_rcg2_shared_ops,
145 static const struct freq_tbl ftbl_gpu_cc_gx_gfx3d_clk_src[] = {
146 F(320000000, P_GPU_CC_PLL1_OUT_AUX2, 2, 0, 0),
147 F(465000000, P_GPU_CC_PLL1_OUT_AUX2, 2, 0, 0),
148 F(600000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
149 F(745000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
150 F(820000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
151 F(900000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
152 F(950000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
156 static struct clk_rcg2 gpu_cc_gx_gfx3d_clk_src = {
160 .parent_map = gpu_cc_parent_map_1,
161 .freq_tbl = ftbl_gpu_cc_gx_gfx3d_clk_src,
162 .clkr.hw.init = &(struct clk_init_data){
163 .name = "gpu_cc_gx_gfx3d_clk_src",
164 .parent_data = gpu_cc_parent_data_1,
165 .num_parents = ARRAY_SIZE(gpu_cc_parent_data_1),
166 .flags = CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
167 .ops = &clk_rcg2_ops,
171 static struct clk_branch gpu_cc_crc_ahb_clk = {
173 .halt_check = BRANCH_HALT_DELAY,
175 .enable_reg = 0x107c,
176 .enable_mask = BIT(0),
177 .hw.init = &(struct clk_init_data){
178 .name = "gpu_cc_crc_ahb_clk",
179 .ops = &clk_branch2_ops,
184 static struct clk_branch gpu_cc_cx_apb_clk = {
186 .halt_check = BRANCH_HALT_DELAY,
188 .enable_reg = 0x1088,
189 .enable_mask = BIT(0),
190 .hw.init = &(struct clk_init_data){
191 .name = "gpu_cc_cx_apb_clk",
192 .ops = &clk_branch2_ops,
197 static struct clk_branch gpu_cc_gx_gfx3d_clk = {
199 .halt_check = BRANCH_HALT_SKIP,
201 .enable_reg = 0x1054,
202 .enable_mask = BIT(0),
203 .hw.init = &(struct clk_init_data){
204 .name = "gpu_cc_gx_gfx3d_clk",
205 .parent_hws = (const struct clk_hw*[]) {
206 &gpu_cc_gx_gfx3d_clk_src.clkr.hw,
209 .flags = CLK_SET_RATE_PARENT,
210 .ops = &clk_branch2_ops,
215 static struct clk_branch gpu_cc_cx_gfx3d_clk = {
217 .halt_check = BRANCH_HALT_DELAY,
219 .enable_reg = 0x10a4,
220 .enable_mask = BIT(0),
221 .hw.init = &(struct clk_init_data){
222 .name = "gpu_cc_cx_gfx3d_clk",
223 .parent_hws = (const struct clk_hw*[]) {
224 &gpu_cc_gx_gfx3d_clk.clkr.hw,
227 .flags = CLK_SET_RATE_PARENT,
228 .ops = &clk_branch2_ops,
233 static struct clk_branch gpu_cc_cx_gmu_clk = {
235 .halt_check = BRANCH_HALT,
237 .enable_reg = 0x1098,
238 .enable_mask = BIT(0),
239 .hw.init = &(struct clk_init_data){
240 .name = "gpu_cc_cx_gmu_clk",
241 .parent_hws = (const struct clk_hw*[]) {
242 &gpu_cc_gmu_clk_src.clkr.hw,
245 .flags = CLK_SET_RATE_PARENT,
246 .ops = &clk_branch2_ops,
251 static struct clk_branch gpu_cc_cx_snoc_dvm_clk = {
253 .halt_check = BRANCH_HALT_DELAY,
255 .enable_reg = 0x108c,
256 .enable_mask = BIT(0),
257 .hw.init = &(struct clk_init_data){
258 .name = "gpu_cc_cx_snoc_dvm_clk",
259 .ops = &clk_branch2_ops,
264 static struct clk_branch gpu_cc_cxo_aon_clk = {
266 .halt_check = BRANCH_HALT_DELAY,
268 .enable_reg = 0x1004,
269 .enable_mask = BIT(0),
270 .hw.init = &(struct clk_init_data){
271 .name = "gpu_cc_cxo_aon_clk",
272 .ops = &clk_branch2_ops,
277 static struct clk_branch gpu_cc_cxo_clk = {
279 .halt_check = BRANCH_HALT,
281 .enable_reg = 0x109c,
282 .enable_mask = BIT(0),
283 .hw.init = &(struct clk_init_data){
284 .name = "gpu_cc_cxo_clk",
285 .ops = &clk_branch2_ops,
290 static struct clk_branch gpu_cc_sleep_clk = {
292 .halt_check = BRANCH_HALT_DELAY,
294 .enable_reg = 0x1090,
295 .enable_mask = BIT(0),
296 .hw.init = &(struct clk_init_data){
297 .name = "gpu_cc_sleep_clk",
298 .ops = &clk_branch2_ops,
303 static struct clk_branch gpu_cc_ahb_clk = {
305 .halt_check = BRANCH_HALT_DELAY,
307 .enable_reg = 0x1078,
308 .enable_mask = BIT(0),
309 .hw.init = &(struct clk_init_data){
310 .name = "gpu_cc_ahb_clk",
311 .flags = CLK_IS_CRITICAL,
312 .ops = &clk_branch2_ops,
317 static struct clk_branch gpu_cc_hlos1_vote_gpu_smmu_clk = {
319 .halt_check = BRANCH_VOTED,
321 .enable_reg = 0x5000,
322 .enable_mask = BIT(0),
323 .hw.init = &(struct clk_init_data){
324 .name = "gpu_cc_hlos1_vote_gpu_smmu_clk",
325 .ops = &clk_branch2_ops,
330 static struct gdsc gpu_cx_gdsc = {
332 .gds_hw_ctrl = 0x1540,
334 .name = "gpu_cx_gdsc",
336 .pwrsts = PWRSTS_OFF_ON,
340 static struct gdsc gpu_gx_gdsc = {
343 .name = "gpu_gx_gdsc",
345 .pwrsts = PWRSTS_OFF_ON,
349 static struct clk_regmap *gpu_cc_sm6125_clocks[] = {
350 [GPU_CC_CRC_AHB_CLK] = &gpu_cc_crc_ahb_clk.clkr,
351 [GPU_CC_CX_APB_CLK] = &gpu_cc_cx_apb_clk.clkr,
352 [GPU_CC_CX_GFX3D_CLK] = &gpu_cc_cx_gfx3d_clk.clkr,
353 [GPU_CC_CX_GMU_CLK] = &gpu_cc_cx_gmu_clk.clkr,
354 [GPU_CC_CX_SNOC_DVM_CLK] = &gpu_cc_cx_snoc_dvm_clk.clkr,
355 [GPU_CC_CXO_AON_CLK] = &gpu_cc_cxo_aon_clk.clkr,
356 [GPU_CC_CXO_CLK] = &gpu_cc_cxo_clk.clkr,
357 [GPU_CC_GMU_CLK_SRC] = &gpu_cc_gmu_clk_src.clkr,
358 [GPU_CC_PLL0_OUT_AUX2] = &gpu_cc_pll0_out_aux2.clkr,
359 [GPU_CC_PLL1_OUT_AUX2] = &gpu_cc_pll1_out_aux2.clkr,
360 [GPU_CC_SLEEP_CLK] = &gpu_cc_sleep_clk.clkr,
361 [GPU_CC_GX_GFX3D_CLK] = &gpu_cc_gx_gfx3d_clk.clkr,
362 [GPU_CC_GX_GFX3D_CLK_SRC] = &gpu_cc_gx_gfx3d_clk_src.clkr,
363 [GPU_CC_AHB_CLK] = &gpu_cc_ahb_clk.clkr,
364 [GPU_CC_HLOS1_VOTE_GPU_SMMU_CLK] = &gpu_cc_hlos1_vote_gpu_smmu_clk.clkr,
367 static struct gdsc *gpucc_sm6125_gdscs[] = {
368 [GPU_CX_GDSC] = &gpu_cx_gdsc,
369 [GPU_GX_GDSC] = &gpu_gx_gdsc,
372 static const struct regmap_config gpu_cc_sm6125_regmap_config = {
376 .max_register = 0x9000,
380 static const struct qcom_cc_desc gpu_cc_sm6125_desc = {
381 .config = &gpu_cc_sm6125_regmap_config,
382 .clks = gpu_cc_sm6125_clocks,
383 .num_clks = ARRAY_SIZE(gpu_cc_sm6125_clocks),
384 .gdscs = gpucc_sm6125_gdscs,
385 .num_gdscs = ARRAY_SIZE(gpucc_sm6125_gdscs),
388 static const struct of_device_id gpu_cc_sm6125_match_table[] = {
389 { .compatible = "qcom,sm6125-gpucc" },
392 MODULE_DEVICE_TABLE(of, gpu_cc_sm6125_match_table);
394 static int gpu_cc_sm6125_probe(struct platform_device *pdev)
396 struct regmap *regmap;
398 regmap = qcom_cc_map(pdev, &gpu_cc_sm6125_desc);
400 return PTR_ERR(regmap);
402 clk_alpha_pll_configure(&gpu_cc_pll0_out_aux2, regmap, &gpu_pll0_config);
403 clk_alpha_pll_configure(&gpu_cc_pll1_out_aux2, regmap, &gpu_pll1_config);
405 /* Set recommended WAKEUP/SLEEP settings for the gpu_cc_cx_gmu_clk */
406 qcom_branch_set_wakeup(regmap, gpu_cc_cx_gmu_clk, 0xf);
407 qcom_branch_set_sleep(regmap, gpu_cc_cx_gmu_clk, 0xf);
409 qcom_branch_set_force_mem_core(regmap, gpu_cc_gx_gfx3d_clk, true);
410 qcom_branch_set_force_periph_on(regmap, gpu_cc_gx_gfx3d_clk, true);
412 return qcom_cc_really_probe(pdev, &gpu_cc_sm6125_desc, regmap);
415 static struct platform_driver gpu_cc_sm6125_driver = {
416 .probe = gpu_cc_sm6125_probe,
418 .name = "gpucc-sm6125",
419 .of_match_table = gpu_cc_sm6125_match_table,
422 module_platform_driver(gpu_cc_sm6125_driver);
424 MODULE_DESCRIPTION("QTI GPUCC SM6125 Driver");
425 MODULE_LICENSE("GPL");