1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 4 */ 5 6 #include <linux/clk-provider.h> 7 #include <linux/module.h> 8 #include <linux/platform_device.h> 9 #include <linux/regmap.h> 10 11 #include <dt-bindings/clock/qcom,hawi-gpucc.h> 12 13 #include "clk-alpha-pll.h" 14 #include "clk-branch.h" 15 #include "clk-rcg.h" 16 #include "clk-regmap.h" 17 #include "clk-regmap-divider.h" 18 #include "common.h" 19 #include "gdsc.h" 20 #include "reset.h" 21 22 enum { 23 DT_BI_TCXO, 24 DT_GPLL0_OUT_MAIN, 25 DT_GPLL0_OUT_MAIN_DIV, 26 }; 27 28 enum { 29 P_BI_TCXO, 30 P_GPLL0_OUT_MAIN, 31 P_GPLL0_OUT_MAIN_DIV, 32 P_GPU_CC_PLL0_OUT_EVEN, 33 P_GPU_CC_PLL0_OUT_MAIN, 34 P_GPU_CC_PLL0_OUT_ODD, 35 }; 36 37 static const struct pll_vco taycan_eha_t_vco[] = { 38 { 249600000, 2500000000, 0 }, 39 }; 40 41 /* 788.0 MHz Configuration */ 42 static const struct alpha_pll_config gpu_cc_pll0_config = { 43 .l = 0x29, 44 .alpha = 0xaaa, 45 .config_ctl_val = 0xa5c400e7, 46 .config_ctl_hi_val = 0x0a8060e0, 47 .config_ctl_hi1_val = 0xf51dea20, 48 .user_ctl_val = 0x00000000, 49 .user_ctl_hi_val = 0x00000002, 50 }; 51 52 /* 788.0 MHz Configuration */ 53 static const struct alpha_pll_config gpu_cc_pll0_config_maili = { 54 .l = 0x29, 55 .cal_l = 0x42, 56 .alpha = 0xaaa, 57 .config_ctl_val = 0xa5c400e7, 58 .config_ctl_hi_val = 0x0a806160, 59 .config_ctl_hi1_val = 0xf51dea20, 60 .user_ctl_val = 0x00000000, 61 .user_ctl_hi_val = 0x00000002, 62 }; 63 64 static struct clk_alpha_pll gpu_cc_pll0 = { 65 .offset = 0x0, 66 .config = &gpu_cc_pll0_config, 67 .vco_table = taycan_eha_t_vco, 68 .num_vco = ARRAY_SIZE(taycan_eha_t_vco), 69 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_TAYCAN_EHA_T], 70 .clkr = { 71 .hw.init = &(const struct clk_init_data) { 72 .name = "gpu_cc_pll0", 73 .parent_data = &(const struct clk_parent_data) { 74 .index = DT_BI_TCXO, 75 }, 76 .num_parents = 1, 77 .ops = &clk_alpha_pll_taycan_eha_t_ops, 78 }, 79 }, 80 }; 81 82 static const struct parent_map gpu_cc_parent_map_1[] = { 83 { P_BI_TCXO, 0 }, 84 { P_GPU_CC_PLL0_OUT_MAIN, 1 }, 85 { P_GPU_CC_PLL0_OUT_EVEN, 2 }, 86 { P_GPU_CC_PLL0_OUT_ODD, 3 }, 87 { P_GPLL0_OUT_MAIN, 5 }, 88 { P_GPLL0_OUT_MAIN_DIV, 6 }, 89 }; 90 91 static const struct clk_parent_data gpu_cc_parent_data_1[] = { 92 { .index = DT_BI_TCXO }, 93 { .hw = &gpu_cc_pll0.clkr.hw }, 94 { .hw = &gpu_cc_pll0.clkr.hw }, 95 { .hw = &gpu_cc_pll0.clkr.hw }, 96 { .index = DT_GPLL0_OUT_MAIN }, 97 { .index = DT_GPLL0_OUT_MAIN_DIV }, 98 }; 99 100 static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src[] = { 101 F(19200000, P_BI_TCXO, 1, 0, 0), 102 F(788000000, P_GPU_CC_PLL0_OUT_MAIN, 1, 0, 0), 103 F(825000000, P_GPU_CC_PLL0_OUT_MAIN, 1, 0, 0), 104 F(880000000, P_GPU_CC_PLL0_OUT_MAIN, 1, 0, 0), 105 F(917000000, P_GPU_CC_PLL0_OUT_MAIN, 1, 0, 0), 106 { } 107 }; 108 109 static struct clk_rcg2 gpu_cc_gmu_clk_src = { 110 .cmd_rcgr = 0x9318, 111 .mnd_width = 0, 112 .hid_width = 5, 113 .parent_map = gpu_cc_parent_map_1, 114 .freq_tbl = ftbl_gpu_cc_gmu_clk_src, 115 .hw_clk_ctrl = true, 116 .clkr.hw.init = &(const struct clk_init_data) { 117 .name = "gpu_cc_gmu_clk_src", 118 .parent_data = gpu_cc_parent_data_1, 119 .num_parents = ARRAY_SIZE(gpu_cc_parent_data_1), 120 .flags = CLK_SET_RATE_PARENT, 121 .ops = &clk_rcg2_shared_ops, 122 }, 123 }; 124 125 static const struct freq_tbl ftbl_gpu_cc_hub_clk_src[] = { 126 F(150000000, P_GPLL0_OUT_MAIN_DIV, 2, 0, 0), 127 F(200000000, P_GPLL0_OUT_MAIN, 3, 0, 0), 128 F(300000000, P_GPLL0_OUT_MAIN, 2, 0, 0), 129 F(400000000, P_GPLL0_OUT_MAIN, 1.5, 0, 0), 130 { } 131 }; 132 133 static struct clk_rcg2 gpu_cc_hub_clk_src = { 134 .cmd_rcgr = 0x93f0, 135 .mnd_width = 0, 136 .hid_width = 5, 137 .parent_map = gpu_cc_parent_map_1, 138 .freq_tbl = ftbl_gpu_cc_hub_clk_src, 139 .hw_clk_ctrl = true, 140 .clkr.hw.init = &(const struct clk_init_data) { 141 .name = "gpu_cc_hub_clk_src", 142 .parent_data = gpu_cc_parent_data_1, 143 .num_parents = ARRAY_SIZE(gpu_cc_parent_data_1), 144 .flags = CLK_SET_RATE_PARENT, 145 .ops = &clk_rcg2_shared_ops, 146 }, 147 }; 148 149 static struct clk_regmap_div gpu_cc_hub_div_clk_src = { 150 .reg = 0x9430, 151 .shift = 0, 152 .width = 4, 153 .clkr.hw.init = &(const struct clk_init_data) { 154 .name = "gpu_cc_hub_div_clk_src", 155 .parent_hws = (const struct clk_hw *[]) { 156 &gpu_cc_hub_clk_src.clkr.hw, 157 }, 158 .num_parents = 1, 159 .flags = CLK_SET_RATE_PARENT, 160 .ops = &clk_regmap_div_ro_ops, 161 }, 162 }; 163 164 static struct clk_branch gpu_cc_ahb_clk = { 165 .halt_reg = 0x90bc, 166 .halt_check = BRANCH_HALT_DELAY, 167 .clkr = { 168 .enable_reg = 0x90bc, 169 .enable_mask = BIT(0), 170 .hw.init = &(const struct clk_init_data) { 171 .name = "gpu_cc_ahb_clk", 172 .parent_hws = (const struct clk_hw *[]) { 173 &gpu_cc_hub_div_clk_src.clkr.hw, 174 }, 175 .num_parents = 1, 176 .flags = CLK_SET_RATE_PARENT, 177 .ops = &clk_branch2_ops, 178 }, 179 }, 180 }; 181 182 static struct clk_branch gpu_cc_cx_accu_shift_clk = { 183 .halt_reg = 0x9104, 184 .halt_check = BRANCH_HALT_VOTED, 185 .clkr = { 186 .enable_reg = 0x9104, 187 .enable_mask = BIT(0), 188 .hw.init = &(const struct clk_init_data) { 189 .name = "gpu_cc_cx_accu_shift_clk", 190 .ops = &clk_branch2_ops, 191 }, 192 }, 193 }; 194 195 static struct clk_branch gpu_cc_cx_gmu_clk = { 196 .halt_reg = 0x90d4, 197 .halt_check = BRANCH_HALT_VOTED, 198 .hwcg_reg = 0x90d4, 199 .hwcg_bit = 1, 200 .clkr = { 201 .enable_reg = 0x90d4, 202 .enable_mask = BIT(0), 203 .hw.init = &(const struct clk_init_data) { 204 .name = "gpu_cc_cx_gmu_clk", 205 .parent_hws = (const struct clk_hw *[]) { 206 &gpu_cc_gmu_clk_src.clkr.hw, 207 }, 208 .num_parents = 1, 209 .flags = CLK_SET_RATE_PARENT, 210 .ops = &clk_branch2_aon_ops, 211 }, 212 }, 213 }; 214 215 static struct clk_branch gpu_cc_demet_clk = { 216 .halt_reg = 0x9010, 217 .halt_check = BRANCH_HALT_VOTED, 218 .clkr = { 219 .enable_reg = 0x9010, 220 .enable_mask = BIT(0), 221 .hw.init = &(const struct clk_init_data) { 222 .name = "gpu_cc_demet_clk", 223 .ops = &clk_branch2_ops, 224 }, 225 }, 226 }; 227 228 static struct clk_branch gpu_cc_dpm_clk = { 229 .halt_reg = 0x9108, 230 .halt_check = BRANCH_HALT, 231 .clkr = { 232 .enable_reg = 0x9108, 233 .enable_mask = BIT(0), 234 .hw.init = &(const struct clk_init_data) { 235 .name = "gpu_cc_dpm_clk", 236 .ops = &clk_branch2_ops, 237 }, 238 }, 239 }; 240 241 static struct clk_branch gpu_cc_freq_measure_clk = { 242 .halt_reg = 0x900c, 243 .halt_check = BRANCH_HALT, 244 .clkr = { 245 .enable_reg = 0x900c, 246 .enable_mask = BIT(0), 247 .hw.init = &(const struct clk_init_data) { 248 .name = "gpu_cc_freq_measure_clk", 249 .ops = &clk_branch2_ops, 250 }, 251 }, 252 }; 253 254 static struct clk_branch gpu_cc_gpu_smmu_vote_clk = { 255 .halt_reg = 0x7000, 256 .halt_check = BRANCH_HALT_VOTED, 257 .clkr = { 258 .enable_reg = 0x7000, 259 .enable_mask = BIT(0), 260 .hw.init = &(const struct clk_init_data) { 261 .name = "gpu_cc_gpu_smmu_vote_clk", 262 .ops = &clk_branch2_ops, 263 }, 264 }, 265 }; 266 267 static struct clk_branch gpu_cc_gx_accu_shift_clk = { 268 .halt_reg = 0x9070, 269 .halt_check = BRANCH_HALT_VOTED, 270 .clkr = { 271 .enable_reg = 0x9070, 272 .enable_mask = BIT(0), 273 .hw.init = &(const struct clk_init_data) { 274 .name = "gpu_cc_gx_accu_shift_clk", 275 .ops = &clk_branch2_ops, 276 }, 277 }, 278 }; 279 280 static struct clk_branch gpu_cc_hub_aon_clk = { 281 .halt_reg = 0x93ec, 282 .halt_check = BRANCH_HALT_VOTED, 283 .clkr = { 284 .enable_reg = 0x93ec, 285 .enable_mask = BIT(0), 286 .hw.init = &(const struct clk_init_data) { 287 .name = "gpu_cc_hub_aon_clk", 288 .parent_hws = (const struct clk_hw *[]) { 289 &gpu_cc_hub_clk_src.clkr.hw, 290 }, 291 .num_parents = 1, 292 .flags = CLK_SET_RATE_PARENT, 293 .ops = &clk_branch2_aon_ops, 294 }, 295 }, 296 }; 297 298 static struct clk_branch gpu_cc_hub_cx_int_clk = { 299 .halt_reg = 0x90e8, 300 .halt_check = BRANCH_HALT_VOTED, 301 .hwcg_reg = 0x90e8, 302 .hwcg_bit = 1, 303 .clkr = { 304 .enable_reg = 0x90e8, 305 .enable_mask = BIT(0), 306 .hw.init = &(const struct clk_init_data) { 307 .name = "gpu_cc_hub_cx_int_clk", 308 .parent_hws = (const struct clk_hw *[]) { 309 &gpu_cc_hub_clk_src.clkr.hw, 310 }, 311 .num_parents = 1, 312 .flags = CLK_SET_RATE_PARENT, 313 .ops = &clk_branch2_aon_ops, 314 }, 315 }, 316 }; 317 318 static struct clk_branch gpu_cc_memnoc_gfx_clk = { 319 .halt_reg = 0x90ec, 320 .halt_check = BRANCH_HALT_VOTED, 321 .hwcg_reg = 0x90ec, 322 .hwcg_bit = 1, 323 .clkr = { 324 .enable_reg = 0x90ec, 325 .enable_mask = BIT(0), 326 .hw.init = &(const struct clk_init_data) { 327 .name = "gpu_cc_memnoc_gfx_clk", 328 .ops = &clk_branch2_ops, 329 }, 330 }, 331 }; 332 333 static struct clk_branch gpu_cc_mxg_ahb_clk = { 334 .halt_reg = 0x9744, 335 .halt_check = BRANCH_HALT_VOTED, 336 .clkr = { 337 .enable_reg = 0x9744, 338 .enable_mask = BIT(0), 339 .hw.init = &(const struct clk_init_data) { 340 .name = "gpu_cc_mxg_ahb_clk", 341 .parent_hws = (const struct clk_hw *[]) { 342 &gpu_cc_hub_div_clk_src.clkr.hw, 343 }, 344 .num_parents = 1, 345 .flags = CLK_SET_RATE_PARENT, 346 .ops = &clk_branch2_ops, 347 }, 348 }, 349 }; 350 351 static struct gdsc gpu_cc_cx_gdsc = { 352 .gdscr = 0x9080, 353 .gds_hw_ctrl = 0x9094, 354 .en_rest_wait_val = 0x2, 355 .en_few_wait_val = 0x2, 356 .clk_dis_wait_val = 0xf, 357 .pd = { 358 .name = "gpu_cc_cx_gdsc", 359 }, 360 .pwrsts = PWRSTS_OFF_ON, 361 .flags = VOTABLE | POLL_CFG_GDSCR | RETAIN_FF_ENABLE, 362 }; 363 364 static struct gdsc gpu_cc_mxg_gdsc = { 365 .gdscr = 0x961c, 366 .en_rest_wait_val = 0x2, 367 .en_few_wait_val = 0x2, 368 .clk_dis_wait_val = 0xf, 369 .pd = { 370 .name = "gpu_cc_mxg_gdsc", 371 }, 372 .pwrsts = PWRSTS_OFF_ON, 373 .flags = POLL_CFG_GDSCR | RETAIN_FF_ENABLE, 374 }; 375 376 static struct clk_regmap *gpu_cc_hawi_clocks[] = { 377 [GPU_CC_AHB_CLK] = &gpu_cc_ahb_clk.clkr, 378 [GPU_CC_CX_ACCU_SHIFT_CLK] = &gpu_cc_cx_accu_shift_clk.clkr, 379 [GPU_CC_CX_GMU_CLK] = &gpu_cc_cx_gmu_clk.clkr, 380 [GPU_CC_DEMET_CLK] = &gpu_cc_demet_clk.clkr, 381 [GPU_CC_DPM_CLK] = &gpu_cc_dpm_clk.clkr, 382 [GPU_CC_FREQ_MEASURE_CLK] = &gpu_cc_freq_measure_clk.clkr, 383 [GPU_CC_GMU_CLK_SRC] = &gpu_cc_gmu_clk_src.clkr, 384 [GPU_CC_GPU_SMMU_VOTE_CLK] = &gpu_cc_gpu_smmu_vote_clk.clkr, 385 [GPU_CC_GX_ACCU_SHIFT_CLK] = &gpu_cc_gx_accu_shift_clk.clkr, 386 [GPU_CC_HUB_AON_CLK] = &gpu_cc_hub_aon_clk.clkr, 387 [GPU_CC_HUB_CLK_SRC] = &gpu_cc_hub_clk_src.clkr, 388 [GPU_CC_HUB_CX_INT_CLK] = &gpu_cc_hub_cx_int_clk.clkr, 389 [GPU_CC_HUB_DIV_CLK_SRC] = &gpu_cc_hub_div_clk_src.clkr, 390 [GPU_CC_MEMNOC_GFX_CLK] = &gpu_cc_memnoc_gfx_clk.clkr, 391 [GPU_CC_MXG_AHB_CLK] = &gpu_cc_mxg_ahb_clk.clkr, 392 [GPU_CC_PLL0] = &gpu_cc_pll0.clkr, 393 }; 394 395 static struct gdsc *gpu_cc_hawi_gdscs[] = { 396 [GPU_CC_CX_GDSC] = &gpu_cc_cx_gdsc, 397 [GPU_CC_MXG_GDSC] = &gpu_cc_mxg_gdsc, 398 }; 399 400 static const struct qcom_reset_map gpu_cc_hawi_resets[] = { 401 [GPU_CC_CB_BCR] = { 0x93a0 }, 402 [GPU_CC_CX_BCR] = { 0x907c }, 403 [GPU_CC_FAST_HUB_BCR] = { 0x93e4 }, 404 [GPU_CC_GMU_BCR] = { 0x9314 }, 405 [GPU_CC_GX_BCR] = { 0x905c }, 406 [GPU_CC_MXG_BCR] = { 0x9618 }, 407 [GPU_CC_XO_BCR] = { 0x9000 }, 408 }; 409 410 static struct clk_alpha_pll *gpu_cc_hawi_plls[] = { 411 &gpu_cc_pll0, 412 }; 413 414 static u32 gpu_cc_hawi_critical_cbcrs[] = { 415 0x93a4, /* GPU_CC_CB_CLK */ 416 0x9704, /* GPU_CC_MXG_XO_CLK */ 417 0x90e4, /* GPU_CC_CXO_CLK */ 418 0x9008, /* GPU_CC_CXO_AON_CLK */ 419 0x93e8, /* GPU_CC_RSCC_HUB_AON_CLK */ 420 0x9004, /* GPU_CC_RSCC_XO_AON_CLK */ 421 0x90cc, /* GPU_CC_SLEEP_CLK */ 422 }; 423 424 static const struct regmap_config gpu_cc_hawi_regmap_config = { 425 .reg_bits = 32, 426 .reg_stride = 4, 427 .val_bits = 32, 428 .max_register = 0x9744, 429 .fast_io = true, 430 }; 431 432 static struct qcom_cc_driver_data gpu_cc_hawi_driver_data = { 433 .alpha_plls = gpu_cc_hawi_plls, 434 .num_alpha_plls = ARRAY_SIZE(gpu_cc_hawi_plls), 435 .clk_cbcrs = gpu_cc_hawi_critical_cbcrs, 436 .num_clk_cbcrs = ARRAY_SIZE(gpu_cc_hawi_critical_cbcrs), 437 }; 438 439 static const struct qcom_cc_desc gpu_cc_hawi_desc = { 440 .config = &gpu_cc_hawi_regmap_config, 441 .clks = gpu_cc_hawi_clocks, 442 .num_clks = ARRAY_SIZE(gpu_cc_hawi_clocks), 443 .resets = gpu_cc_hawi_resets, 444 .num_resets = ARRAY_SIZE(gpu_cc_hawi_resets), 445 .gdscs = gpu_cc_hawi_gdscs, 446 .num_gdscs = ARRAY_SIZE(gpu_cc_hawi_gdscs), 447 .use_rpm = true, 448 .driver_data = &gpu_cc_hawi_driver_data, 449 }; 450 451 static const struct of_device_id gpu_cc_hawi_match_table[] = { 452 { .compatible = "qcom,hawi-gpucc" }, 453 { .compatible = "qcom,maili-gpucc" }, 454 { } 455 }; 456 MODULE_DEVICE_TABLE(of, gpu_cc_hawi_match_table); 457 458 static int gpu_cc_hawi_probe(struct platform_device *pdev) 459 { 460 if (device_is_compatible(&pdev->dev, "qcom,maili-gpucc")) 461 gpu_cc_pll0.config = &gpu_cc_pll0_config_maili; 462 463 return qcom_cc_probe(pdev, &gpu_cc_hawi_desc); 464 } 465 466 static struct platform_driver gpu_cc_hawi_driver = { 467 .probe = gpu_cc_hawi_probe, 468 .driver = { 469 .name = "gpucc-hawi", 470 .of_match_table = gpu_cc_hawi_match_table, 471 }, 472 }; 473 474 module_platform_driver(gpu_cc_hawi_driver); 475 476 MODULE_DESCRIPTION("QTI GPUCC HAWI Driver"); 477 MODULE_LICENSE("GPL"); 478