0001
0002
0003
0004
0005
0006
0007 #include <linux/clk-provider.h>
0008 #include <linux/module.h>
0009 #include <linux/platform_device.h>
0010 #include <linux/regmap.h>
0011
0012 #include <dt-bindings/clock/qcom,gpucc-sm6350.h>
0013
0014 #include "common.h"
0015 #include "clk-alpha-pll.h"
0016 #include "clk-branch.h"
0017 #include "clk-rcg.h"
0018 #include "clk-regmap.h"
0019 #include "reset.h"
0020 #include "gdsc.h"
0021
0022 #define CX_GMU_CBCR_SLEEP_MASK 0xF
0023 #define CX_GMU_CBCR_SLEEP_SHIFT 4
0024 #define CX_GMU_CBCR_WAKE_MASK 0xF
0025 #define CX_GMU_CBCR_WAKE_SHIFT 8
0026
0027 enum {
0028 P_BI_TCXO,
0029 P_GPLL0_OUT_MAIN,
0030 P_GPLL0_OUT_MAIN_DIV,
0031 P_GPU_CC_PLL0_OUT_MAIN,
0032 P_GPU_CC_PLL0_OUT_ODD,
0033 P_GPU_CC_PLL1_OUT_EVEN,
0034 P_GPU_CC_PLL1_OUT_MAIN,
0035 P_GPU_CC_PLL1_OUT_ODD,
0036 P_CRC_DIV,
0037 };
0038
0039 static const struct pll_vco fabia_vco[] = {
0040 { 249600000, 2000000000, 0 },
0041 };
0042
0043
0044 static const struct alpha_pll_config gpu_cc_pll0_config = {
0045 .l = 0x1A,
0046 .alpha = 0x5AAA,
0047 .config_ctl_val = 0x20485699,
0048 .config_ctl_hi_val = 0x00002067,
0049 .test_ctl_val = 0x40000000,
0050 .test_ctl_hi_val = 0x00000002,
0051 .user_ctl_val = 0x00000001,
0052 .user_ctl_hi_val = 0x00004805,
0053 };
0054
0055 static struct clk_alpha_pll gpu_cc_pll0 = {
0056 .offset = 0x0,
0057 .vco_table = fabia_vco,
0058 .num_vco = ARRAY_SIZE(fabia_vco),
0059 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA],
0060 .clkr = {
0061 .hw.init = &(struct clk_init_data){
0062 .name = "gpu_cc_pll0",
0063 .parent_data = &(const struct clk_parent_data){
0064 .fw_name = "bi_tcxo",
0065 },
0066 .num_parents = 1,
0067 .ops = &clk_alpha_pll_fabia_ops,
0068 },
0069 },
0070 };
0071
0072 static struct clk_fixed_factor crc_div = {
0073 .mult = 1,
0074 .div = 2,
0075 .hw.init = &(struct clk_init_data){
0076 .name = "crc_div",
0077 .parent_hws = (const struct clk_hw*[]){
0078 &gpu_cc_pll0.clkr.hw,
0079 },
0080 .num_parents = 1,
0081 .flags = CLK_SET_RATE_PARENT,
0082 .ops = &clk_fixed_factor_ops,
0083 },
0084 };
0085
0086
0087 static const struct alpha_pll_config gpu_cc_pll1_config = {
0088 .l = 0x1A,
0089 .alpha = 0xC555,
0090 .config_ctl_val = 0x20485699,
0091 .config_ctl_hi_val = 0x00002067,
0092 .test_ctl_val = 0x40000000,
0093 .test_ctl_hi_val = 0x00000002,
0094 .user_ctl_val = 0x00000001,
0095 .user_ctl_hi_val = 0x00004805,
0096 };
0097
0098 static struct clk_alpha_pll gpu_cc_pll1 = {
0099 .offset = 0x100,
0100 .vco_table = fabia_vco,
0101 .num_vco = ARRAY_SIZE(fabia_vco),
0102 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA],
0103 .clkr = {
0104 .hw.init = &(struct clk_init_data){
0105 .name = "gpu_cc_pll1",
0106 .parent_data = &(const struct clk_parent_data){
0107 .fw_name = "bi_tcxo",
0108 },
0109 .num_parents = 1,
0110 .ops = &clk_alpha_pll_fabia_ops,
0111 },
0112 },
0113 };
0114
0115 static const struct parent_map gpu_cc_parent_map_0[] = {
0116 { P_BI_TCXO, 0 },
0117 { P_GPU_CC_PLL0_OUT_MAIN, 1 },
0118 { P_GPU_CC_PLL1_OUT_MAIN, 3 },
0119 { P_GPLL0_OUT_MAIN, 5 },
0120 { P_GPLL0_OUT_MAIN_DIV, 6 },
0121 };
0122
0123 static const struct clk_parent_data gpu_cc_parent_data_0[] = {
0124 { .fw_name = "bi_tcxo" },
0125 { .hw = &gpu_cc_pll0.clkr.hw },
0126 { .hw = &gpu_cc_pll1.clkr.hw },
0127 { .fw_name = "gcc_gpu_gpll0_clk" },
0128 { .fw_name = "gcc_gpu_gpll0_div_clk" },
0129 };
0130
0131 static const struct parent_map gpu_cc_parent_map_1[] = {
0132 { P_BI_TCXO, 0 },
0133 { P_CRC_DIV, 1 },
0134 { P_GPU_CC_PLL0_OUT_ODD, 2 },
0135 { P_GPU_CC_PLL1_OUT_EVEN, 3 },
0136 { P_GPU_CC_PLL1_OUT_ODD, 4 },
0137 { P_GPLL0_OUT_MAIN, 5 },
0138 };
0139
0140 static const struct clk_parent_data gpu_cc_parent_data_1[] = {
0141 { .fw_name = "bi_tcxo" },
0142 { .hw = &crc_div.hw },
0143 { .hw = &gpu_cc_pll0.clkr.hw },
0144 { .hw = &gpu_cc_pll1.clkr.hw },
0145 { .hw = &gpu_cc_pll1.clkr.hw },
0146 { .fw_name = "gcc_gpu_gpll0_clk" },
0147 };
0148
0149 static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src[] = {
0150 F(200000000, P_GPLL0_OUT_MAIN_DIV, 1.5, 0, 0),
0151 { }
0152 };
0153
0154 static struct clk_rcg2 gpu_cc_gmu_clk_src = {
0155 .cmd_rcgr = 0x1120,
0156 .mnd_width = 0,
0157 .hid_width = 5,
0158 .parent_map = gpu_cc_parent_map_0,
0159 .freq_tbl = ftbl_gpu_cc_gmu_clk_src,
0160 .clkr.hw.init = &(struct clk_init_data){
0161 .name = "gpu_cc_gmu_clk_src",
0162 .parent_data = gpu_cc_parent_data_0,
0163 .num_parents = ARRAY_SIZE(gpu_cc_parent_data_0),
0164 .flags = CLK_SET_RATE_PARENT,
0165 .ops = &clk_rcg2_ops,
0166 },
0167 };
0168
0169 static const struct freq_tbl ftbl_gpu_cc_gx_gfx3d_clk_src[] = {
0170 F(253000000, P_CRC_DIV, 1, 0, 0),
0171 F(355000000, P_CRC_DIV, 1, 0, 0),
0172 F(430000000, P_CRC_DIV, 1, 0, 0),
0173 F(565000000, P_CRC_DIV, 1, 0, 0),
0174 F(650000000, P_CRC_DIV, 1, 0, 0),
0175 F(800000000, P_CRC_DIV, 1, 0, 0),
0176 F(825000000, P_CRC_DIV, 1, 0, 0),
0177 F(850000000, P_CRC_DIV, 1, 0, 0),
0178 { }
0179 };
0180
0181 static struct clk_rcg2 gpu_cc_gx_gfx3d_clk_src = {
0182 .cmd_rcgr = 0x101c,
0183 .mnd_width = 0,
0184 .hid_width = 5,
0185 .parent_map = gpu_cc_parent_map_1,
0186 .freq_tbl = ftbl_gpu_cc_gx_gfx3d_clk_src,
0187 .clkr.hw.init = &(struct clk_init_data){
0188 .name = "gpu_cc_gx_gfx3d_clk_src",
0189 .parent_data = gpu_cc_parent_data_1,
0190 .num_parents = ARRAY_SIZE(gpu_cc_parent_data_1),
0191 .flags = CLK_SET_RATE_PARENT,
0192 .ops = &clk_rcg2_ops,
0193 },
0194 };
0195
0196 static struct clk_branch gpu_cc_acd_ahb_clk = {
0197 .halt_reg = 0x1168,
0198 .halt_check = BRANCH_HALT,
0199 .clkr = {
0200 .enable_reg = 0x1168,
0201 .enable_mask = BIT(0),
0202 .hw.init = &(struct clk_init_data){
0203 .name = "gpu_cc_acd_ahb_clk",
0204 .ops = &clk_branch2_ops,
0205 },
0206 },
0207 };
0208
0209 static struct clk_branch gpu_cc_acd_cxo_clk = {
0210 .halt_reg = 0x1164,
0211 .halt_check = BRANCH_HALT,
0212 .clkr = {
0213 .enable_reg = 0x1164,
0214 .enable_mask = BIT(0),
0215 .hw.init = &(struct clk_init_data){
0216 .name = "gpu_cc_acd_cxo_clk",
0217 .ops = &clk_branch2_ops,
0218 },
0219 },
0220 };
0221
0222 static struct clk_branch gpu_cc_ahb_clk = {
0223 .halt_reg = 0x1078,
0224 .halt_check = BRANCH_HALT_DELAY,
0225 .clkr = {
0226 .enable_reg = 0x1078,
0227 .enable_mask = BIT(0),
0228 .hw.init = &(struct clk_init_data){
0229 .name = "gpu_cc_ahb_clk",
0230 .flags = CLK_IS_CRITICAL,
0231 .ops = &clk_branch2_ops,
0232 },
0233 },
0234 };
0235
0236 static struct clk_branch gpu_cc_crc_ahb_clk = {
0237 .halt_reg = 0x107c,
0238 .halt_check = BRANCH_HALT_DELAY,
0239 .clkr = {
0240 .enable_reg = 0x107c,
0241 .enable_mask = BIT(0),
0242 .hw.init = &(struct clk_init_data){
0243 .name = "gpu_cc_crc_ahb_clk",
0244 .ops = &clk_branch2_ops,
0245 },
0246 },
0247 };
0248
0249 static struct clk_branch gpu_cc_cx_gfx3d_clk = {
0250 .halt_reg = 0x10a4,
0251 .halt_check = BRANCH_HALT_DELAY,
0252 .clkr = {
0253 .enable_reg = 0x10a4,
0254 .enable_mask = BIT(0),
0255 .hw.init = &(struct clk_init_data){
0256 .name = "gpu_cc_cx_gfx3d_clk",
0257 .parent_hws = (const struct clk_hw*[]){
0258 &gpu_cc_gx_gfx3d_clk_src.clkr.hw,
0259 },
0260 .num_parents = 1,
0261 .flags = CLK_SET_RATE_PARENT,
0262 .ops = &clk_branch2_ops,
0263 },
0264 },
0265 };
0266
0267 static struct clk_branch gpu_cc_cx_gfx3d_slv_clk = {
0268 .halt_reg = 0x10a8,
0269 .halt_check = BRANCH_HALT_DELAY,
0270 .clkr = {
0271 .enable_reg = 0x10a8,
0272 .enable_mask = BIT(0),
0273 .hw.init = &(struct clk_init_data){
0274 .name = "gpu_cc_cx_gfx3d_slv_clk",
0275 .parent_hws = (const struct clk_hw*[]){
0276 &gpu_cc_gx_gfx3d_clk_src.clkr.hw,
0277 },
0278 .num_parents = 1,
0279 .flags = CLK_SET_RATE_PARENT,
0280 .ops = &clk_branch2_ops,
0281 },
0282 },
0283 };
0284
0285 static struct clk_branch gpu_cc_cx_gmu_clk = {
0286 .halt_reg = 0x1098,
0287 .halt_check = BRANCH_HALT,
0288 .clkr = {
0289 .enable_reg = 0x1098,
0290 .enable_mask = BIT(0),
0291 .hw.init = &(struct clk_init_data){
0292 .name = "gpu_cc_cx_gmu_clk",
0293 .parent_hws = (const struct clk_hw*[]){
0294 &gpu_cc_gmu_clk_src.clkr.hw,
0295 },
0296 .num_parents = 1,
0297 .flags = CLK_SET_RATE_PARENT,
0298 .ops = &clk_branch2_ops,
0299 },
0300 },
0301 };
0302
0303 static struct clk_branch gpu_cc_cx_snoc_dvm_clk = {
0304 .halt_reg = 0x108c,
0305 .halt_check = BRANCH_HALT_DELAY,
0306 .clkr = {
0307 .enable_reg = 0x108c,
0308 .enable_mask = BIT(0),
0309 .hw.init = &(struct clk_init_data){
0310 .name = "gpu_cc_cx_snoc_dvm_clk",
0311 .ops = &clk_branch2_ops,
0312 },
0313 },
0314 };
0315
0316 static struct clk_branch gpu_cc_cxo_aon_clk = {
0317 .halt_reg = 0x1004,
0318 .halt_check = BRANCH_HALT_DELAY,
0319 .clkr = {
0320 .enable_reg = 0x1004,
0321 .enable_mask = BIT(0),
0322 .hw.init = &(struct clk_init_data){
0323 .name = "gpu_cc_cxo_aon_clk",
0324 .ops = &clk_branch2_ops,
0325 },
0326 },
0327 };
0328
0329 static struct clk_branch gpu_cc_cxo_clk = {
0330 .halt_reg = 0x109c,
0331 .halt_check = BRANCH_HALT,
0332 .clkr = {
0333 .enable_reg = 0x109c,
0334 .enable_mask = BIT(0),
0335 .hw.init = &(struct clk_init_data){
0336 .name = "gpu_cc_cxo_clk",
0337 .ops = &clk_branch2_ops,
0338 },
0339 },
0340 };
0341
0342 static struct clk_branch gpu_cc_gx_cxo_clk = {
0343 .halt_reg = 0x1060,
0344 .halt_check = BRANCH_HALT,
0345 .clkr = {
0346 .enable_reg = 0x1060,
0347 .enable_mask = BIT(0),
0348 .hw.init = &(struct clk_init_data){
0349 .name = "gpu_cc_gx_cxo_clk",
0350 .ops = &clk_branch2_ops,
0351 },
0352 },
0353 };
0354
0355 static struct clk_branch gpu_cc_gx_gfx3d_clk = {
0356 .halt_reg = 0x1054,
0357 .halt_check = BRANCH_HALT_SKIP,
0358 .clkr = {
0359 .enable_reg = 0x1054,
0360 .enable_mask = BIT(0),
0361 .hw.init = &(struct clk_init_data){
0362 .name = "gpu_cc_gx_gfx3d_clk",
0363 .parent_hws = (const struct clk_hw*[]){
0364 &gpu_cc_gx_gfx3d_clk_src.clkr.hw,
0365 },
0366 .num_parents = 1,
0367 .flags = CLK_SET_RATE_PARENT,
0368 .ops = &clk_branch2_ops,
0369 },
0370 },
0371 };
0372
0373 static struct clk_branch gpu_cc_gx_gmu_clk = {
0374 .halt_reg = 0x1064,
0375 .halt_check = BRANCH_HALT,
0376 .clkr = {
0377 .enable_reg = 0x1064,
0378 .enable_mask = BIT(0),
0379 .hw.init = &(struct clk_init_data){
0380 .name = "gpu_cc_gx_gmu_clk",
0381 .parent_hws = (const struct clk_hw*[]){
0382 &gpu_cc_gmu_clk_src.clkr.hw,
0383 },
0384 .num_parents = 1,
0385 .flags = CLK_SET_RATE_PARENT,
0386 .ops = &clk_branch2_ops,
0387 },
0388 },
0389 };
0390
0391 static struct clk_branch gpu_cc_gx_vsense_clk = {
0392 .halt_reg = 0x1058,
0393 .halt_check = BRANCH_HALT_DELAY,
0394 .clkr = {
0395 .enable_reg = 0x1058,
0396 .enable_mask = BIT(0),
0397 .hw.init = &(struct clk_init_data){
0398 .name = "gpu_cc_gx_vsense_clk",
0399 .ops = &clk_branch2_ops,
0400 },
0401 },
0402 };
0403
0404 static struct gdsc gpu_cx_gdsc = {
0405 .gdscr = 0x106c,
0406 .gds_hw_ctrl = 0x1540,
0407 .pd = {
0408 .name = "gpu_cx_gdsc",
0409 },
0410 .pwrsts = PWRSTS_OFF_ON,
0411 .flags = VOTABLE,
0412 };
0413
0414 static struct gdsc gpu_gx_gdsc = {
0415 .gdscr = 0x100c,
0416 .clamp_io_ctrl = 0x1508,
0417 .pd = {
0418 .name = "gpu_gx_gdsc",
0419 .power_on = gdsc_gx_do_nothing_enable,
0420 },
0421 .pwrsts = PWRSTS_OFF_ON,
0422 .flags = CLAMP_IO | POLL_CFG_GDSCR,
0423 };
0424
0425 static struct clk_hw *gpu_cc_sm6350_hws[] = {
0426 [GPU_CC_CRC_DIV] = &crc_div.hw,
0427 };
0428
0429 static struct clk_regmap *gpu_cc_sm6350_clocks[] = {
0430 [GPU_CC_ACD_AHB_CLK] = &gpu_cc_acd_ahb_clk.clkr,
0431 [GPU_CC_ACD_CXO_CLK] = &gpu_cc_acd_cxo_clk.clkr,
0432 [GPU_CC_AHB_CLK] = &gpu_cc_ahb_clk.clkr,
0433 [GPU_CC_CRC_AHB_CLK] = &gpu_cc_crc_ahb_clk.clkr,
0434 [GPU_CC_CX_GFX3D_CLK] = &gpu_cc_cx_gfx3d_clk.clkr,
0435 [GPU_CC_CX_GFX3D_SLV_CLK] = &gpu_cc_cx_gfx3d_slv_clk.clkr,
0436 [GPU_CC_CX_GMU_CLK] = &gpu_cc_cx_gmu_clk.clkr,
0437 [GPU_CC_CX_SNOC_DVM_CLK] = &gpu_cc_cx_snoc_dvm_clk.clkr,
0438 [GPU_CC_CXO_AON_CLK] = &gpu_cc_cxo_aon_clk.clkr,
0439 [GPU_CC_CXO_CLK] = &gpu_cc_cxo_clk.clkr,
0440 [GPU_CC_GMU_CLK_SRC] = &gpu_cc_gmu_clk_src.clkr,
0441 [GPU_CC_GX_CXO_CLK] = &gpu_cc_gx_cxo_clk.clkr,
0442 [GPU_CC_GX_GFX3D_CLK] = &gpu_cc_gx_gfx3d_clk.clkr,
0443 [GPU_CC_GX_GFX3D_CLK_SRC] = &gpu_cc_gx_gfx3d_clk_src.clkr,
0444 [GPU_CC_GX_GMU_CLK] = &gpu_cc_gx_gmu_clk.clkr,
0445 [GPU_CC_GX_VSENSE_CLK] = &gpu_cc_gx_vsense_clk.clkr,
0446 [GPU_CC_PLL0] = &gpu_cc_pll0.clkr,
0447 [GPU_CC_PLL1] = &gpu_cc_pll1.clkr,
0448 };
0449
0450 static struct gdsc *gpu_cc_sm6350_gdscs[] = {
0451 [GPU_CX_GDSC] = &gpu_cx_gdsc,
0452 [GPU_GX_GDSC] = &gpu_gx_gdsc,
0453 };
0454
0455 static const struct regmap_config gpu_cc_sm6350_regmap_config = {
0456 .reg_bits = 32,
0457 .reg_stride = 4,
0458 .val_bits = 32,
0459 .max_register = 0x8008,
0460 .fast_io = true,
0461 };
0462
0463 static const struct qcom_cc_desc gpu_cc_sm6350_desc = {
0464 .config = &gpu_cc_sm6350_regmap_config,
0465 .clk_hws = gpu_cc_sm6350_hws,
0466 .num_clk_hws = ARRAY_SIZE(gpu_cc_sm6350_hws),
0467 .clks = gpu_cc_sm6350_clocks,
0468 .num_clks = ARRAY_SIZE(gpu_cc_sm6350_clocks),
0469 .gdscs = gpu_cc_sm6350_gdscs,
0470 .num_gdscs = ARRAY_SIZE(gpu_cc_sm6350_gdscs),
0471 };
0472
0473 static const struct of_device_id gpu_cc_sm6350_match_table[] = {
0474 { .compatible = "qcom,sm6350-gpucc" },
0475 { }
0476 };
0477 MODULE_DEVICE_TABLE(of, gpu_cc_sm6350_match_table);
0478
0479 static int gpu_cc_sm6350_probe(struct platform_device *pdev)
0480 {
0481 struct regmap *regmap;
0482 unsigned int value, mask;
0483
0484 regmap = qcom_cc_map(pdev, &gpu_cc_sm6350_desc);
0485 if (IS_ERR(regmap))
0486 return PTR_ERR(regmap);
0487
0488 clk_fabia_pll_configure(&gpu_cc_pll0, regmap, &gpu_cc_pll0_config);
0489 clk_fabia_pll_configure(&gpu_cc_pll1, regmap, &gpu_cc_pll1_config);
0490
0491
0492 mask = CX_GMU_CBCR_WAKE_MASK << CX_GMU_CBCR_WAKE_SHIFT;
0493 mask |= CX_GMU_CBCR_SLEEP_MASK << CX_GMU_CBCR_SLEEP_SHIFT;
0494 value = 0xF << CX_GMU_CBCR_WAKE_SHIFT | 0xF << CX_GMU_CBCR_SLEEP_SHIFT;
0495 regmap_update_bits(regmap, 0x1098, mask, value);
0496
0497 return qcom_cc_really_probe(pdev, &gpu_cc_sm6350_desc, regmap);
0498 }
0499
0500 static struct platform_driver gpu_cc_sm6350_driver = {
0501 .probe = gpu_cc_sm6350_probe,
0502 .driver = {
0503 .name = "sm6350-gpucc",
0504 .of_match_table = gpu_cc_sm6350_match_table,
0505 },
0506 };
0507
0508 static int __init gpu_cc_sm6350_init(void)
0509 {
0510 return platform_driver_register(&gpu_cc_sm6350_driver);
0511 }
0512 core_initcall(gpu_cc_sm6350_init);
0513
0514 static void __exit gpu_cc_sm6350_exit(void)
0515 {
0516 platform_driver_unregister(&gpu_cc_sm6350_driver);
0517 }
0518 module_exit(gpu_cc_sm6350_exit);
0519
0520 MODULE_DESCRIPTION("QTI GPU_CC LAGOON Driver");
0521 MODULE_LICENSE("GPL v2");