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,eliza-cambistmclkcc.h> 12 13 #include "clk-alpha-pll.h" 14 #include "clk-branch.h" 15 #include "clk-pll.h" 16 #include "clk-rcg.h" 17 #include "clk-regmap.h" 18 #include "clk-regmap-divider.h" 19 #include "clk-regmap-mux.h" 20 #include "common.h" 21 #include "reset.h" 22 23 enum { 24 DT_BI_TCXO, 25 DT_SLEEP_CLK, 26 DT_AHB_CLK, 27 }; 28 29 enum { 30 P_BI_TCXO, 31 P_CAM_BIST_MCLK_CC_PLL0_OUT_EVEN, 32 P_CAM_BIST_MCLK_CC_PLL0_OUT_MAIN, 33 P_SLEEP_CLK, 34 }; 35 36 static const struct pll_vco rivian_ole_vco[] = { 37 { 777000000, 1285000000, 0 }, 38 }; 39 40 /* 960.0 MHz Configuration */ 41 static const struct alpha_pll_config cam_bist_mclk_cc_pll0_config = { 42 .l = 0x32, 43 .cal_l = 0x32, 44 .alpha = 0x0, 45 .config_ctl_val = 0x10000030, 46 .config_ctl_hi_val = 0x80890263, 47 .config_ctl_hi1_val = 0x00000217, 48 .user_ctl_val = 0x00000001, 49 .user_ctl_hi_val = 0x00000000, 50 }; 51 52 static struct clk_alpha_pll cam_bist_mclk_cc_pll0 = { 53 .offset = 0x0, 54 .config = &cam_bist_mclk_cc_pll0_config, 55 .vco_table = rivian_ole_vco, 56 .num_vco = ARRAY_SIZE(rivian_ole_vco), 57 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_RIVIAN_EVO], 58 .clkr = { 59 .hw.init = &(const struct clk_init_data) { 60 .name = "cam_bist_mclk_cc_pll0", 61 .parent_data = &(const struct clk_parent_data) { 62 .index = DT_BI_TCXO, 63 }, 64 .num_parents = 1, 65 .ops = &clk_alpha_pll_rivian_evo_ops, 66 }, 67 }, 68 }; 69 70 static const struct parent_map cam_bist_mclk_cc_parent_map_0[] = { 71 { P_BI_TCXO, 0 }, 72 { P_CAM_BIST_MCLK_CC_PLL0_OUT_EVEN, 3 }, 73 { P_CAM_BIST_MCLK_CC_PLL0_OUT_MAIN, 5 }, 74 }; 75 76 static const struct clk_parent_data cam_bist_mclk_cc_parent_data_0[] = { 77 { .index = DT_BI_TCXO }, 78 { .hw = &cam_bist_mclk_cc_pll0.clkr.hw }, 79 { .hw = &cam_bist_mclk_cc_pll0.clkr.hw }, 80 }; 81 82 static const struct parent_map cam_bist_mclk_cc_parent_map_1[] = { 83 { P_SLEEP_CLK, 0 }, 84 }; 85 86 static const struct clk_parent_data cam_bist_mclk_cc_parent_data_1[] = { 87 { .index = DT_SLEEP_CLK }, 88 }; 89 90 static const struct freq_tbl ftbl_cam_bist_mclk_cc_mclk0_clk_src[] = { 91 F(19200000, P_BI_TCXO, 1, 0, 0), 92 F(24000000, P_CAM_BIST_MCLK_CC_PLL0_OUT_EVEN, 10, 1, 4), 93 F(68571429, P_CAM_BIST_MCLK_CC_PLL0_OUT_MAIN, 14, 0, 0), 94 { } 95 }; 96 97 static struct clk_rcg2 cam_bist_mclk_cc_mclk0_clk_src = { 98 .cmd_rcgr = 0x4000, 99 .mnd_width = 8, 100 .hid_width = 5, 101 .parent_map = cam_bist_mclk_cc_parent_map_0, 102 .freq_tbl = ftbl_cam_bist_mclk_cc_mclk0_clk_src, 103 .hw_clk_ctrl = true, 104 .clkr.hw.init = &(const struct clk_init_data) { 105 .name = "cam_bist_mclk_cc_mclk0_clk_src", 106 .parent_data = cam_bist_mclk_cc_parent_data_0, 107 .num_parents = ARRAY_SIZE(cam_bist_mclk_cc_parent_data_0), 108 .flags = CLK_SET_RATE_PARENT, 109 .ops = &clk_rcg2_shared_ops, 110 }, 111 }; 112 113 static struct clk_rcg2 cam_bist_mclk_cc_mclk1_clk_src = { 114 .cmd_rcgr = 0x401c, 115 .mnd_width = 8, 116 .hid_width = 5, 117 .parent_map = cam_bist_mclk_cc_parent_map_0, 118 .freq_tbl = ftbl_cam_bist_mclk_cc_mclk0_clk_src, 119 .hw_clk_ctrl = true, 120 .clkr.hw.init = &(const struct clk_init_data) { 121 .name = "cam_bist_mclk_cc_mclk1_clk_src", 122 .parent_data = cam_bist_mclk_cc_parent_data_0, 123 .num_parents = ARRAY_SIZE(cam_bist_mclk_cc_parent_data_0), 124 .flags = CLK_SET_RATE_PARENT, 125 .ops = &clk_rcg2_shared_ops, 126 }, 127 }; 128 129 static struct clk_rcg2 cam_bist_mclk_cc_mclk2_clk_src = { 130 .cmd_rcgr = 0x4038, 131 .mnd_width = 8, 132 .hid_width = 5, 133 .parent_map = cam_bist_mclk_cc_parent_map_0, 134 .freq_tbl = ftbl_cam_bist_mclk_cc_mclk0_clk_src, 135 .hw_clk_ctrl = true, 136 .clkr.hw.init = &(const struct clk_init_data) { 137 .name = "cam_bist_mclk_cc_mclk2_clk_src", 138 .parent_data = cam_bist_mclk_cc_parent_data_0, 139 .num_parents = ARRAY_SIZE(cam_bist_mclk_cc_parent_data_0), 140 .flags = CLK_SET_RATE_PARENT, 141 .ops = &clk_rcg2_shared_ops, 142 }, 143 }; 144 145 static struct clk_rcg2 cam_bist_mclk_cc_mclk3_clk_src = { 146 .cmd_rcgr = 0x4054, 147 .mnd_width = 8, 148 .hid_width = 5, 149 .parent_map = cam_bist_mclk_cc_parent_map_0, 150 .freq_tbl = ftbl_cam_bist_mclk_cc_mclk0_clk_src, 151 .hw_clk_ctrl = true, 152 .clkr.hw.init = &(const struct clk_init_data) { 153 .name = "cam_bist_mclk_cc_mclk3_clk_src", 154 .parent_data = cam_bist_mclk_cc_parent_data_0, 155 .num_parents = ARRAY_SIZE(cam_bist_mclk_cc_parent_data_0), 156 .flags = CLK_SET_RATE_PARENT, 157 .ops = &clk_rcg2_shared_ops, 158 }, 159 }; 160 161 static struct clk_rcg2 cam_bist_mclk_cc_mclk4_clk_src = { 162 .cmd_rcgr = 0x4070, 163 .mnd_width = 8, 164 .hid_width = 5, 165 .parent_map = cam_bist_mclk_cc_parent_map_0, 166 .freq_tbl = ftbl_cam_bist_mclk_cc_mclk0_clk_src, 167 .hw_clk_ctrl = true, 168 .clkr.hw.init = &(const struct clk_init_data) { 169 .name = "cam_bist_mclk_cc_mclk4_clk_src", 170 .parent_data = cam_bist_mclk_cc_parent_data_0, 171 .num_parents = ARRAY_SIZE(cam_bist_mclk_cc_parent_data_0), 172 .flags = CLK_SET_RATE_PARENT, 173 .ops = &clk_rcg2_shared_ops, 174 }, 175 }; 176 177 static struct clk_rcg2 cam_bist_mclk_cc_mclk5_clk_src = { 178 .cmd_rcgr = 0x408c, 179 .mnd_width = 8, 180 .hid_width = 5, 181 .parent_map = cam_bist_mclk_cc_parent_map_0, 182 .freq_tbl = ftbl_cam_bist_mclk_cc_mclk0_clk_src, 183 .hw_clk_ctrl = true, 184 .clkr.hw.init = &(const struct clk_init_data) { 185 .name = "cam_bist_mclk_cc_mclk5_clk_src", 186 .parent_data = cam_bist_mclk_cc_parent_data_0, 187 .num_parents = ARRAY_SIZE(cam_bist_mclk_cc_parent_data_0), 188 .flags = CLK_SET_RATE_PARENT, 189 .ops = &clk_rcg2_shared_ops, 190 }, 191 }; 192 193 static struct clk_rcg2 cam_bist_mclk_cc_mclk6_clk_src = { 194 .cmd_rcgr = 0x40a8, 195 .mnd_width = 8, 196 .hid_width = 5, 197 .parent_map = cam_bist_mclk_cc_parent_map_0, 198 .freq_tbl = ftbl_cam_bist_mclk_cc_mclk0_clk_src, 199 .hw_clk_ctrl = true, 200 .clkr.hw.init = &(const struct clk_init_data) { 201 .name = "cam_bist_mclk_cc_mclk6_clk_src", 202 .parent_data = cam_bist_mclk_cc_parent_data_0, 203 .num_parents = ARRAY_SIZE(cam_bist_mclk_cc_parent_data_0), 204 .flags = CLK_SET_RATE_PARENT, 205 .ops = &clk_rcg2_shared_ops, 206 }, 207 }; 208 209 static struct clk_rcg2 cam_bist_mclk_cc_mclk7_clk_src = { 210 .cmd_rcgr = 0x40c4, 211 .mnd_width = 8, 212 .hid_width = 5, 213 .parent_map = cam_bist_mclk_cc_parent_map_0, 214 .freq_tbl = ftbl_cam_bist_mclk_cc_mclk0_clk_src, 215 .hw_clk_ctrl = true, 216 .clkr.hw.init = &(const struct clk_init_data) { 217 .name = "cam_bist_mclk_cc_mclk7_clk_src", 218 .parent_data = cam_bist_mclk_cc_parent_data_0, 219 .num_parents = ARRAY_SIZE(cam_bist_mclk_cc_parent_data_0), 220 .flags = CLK_SET_RATE_PARENT, 221 .ops = &clk_rcg2_shared_ops, 222 }, 223 }; 224 225 static const struct freq_tbl ftbl_cam_bist_mclk_cc_sleep_clk_src[] = { 226 F(32000, P_SLEEP_CLK, 1, 0, 0), 227 { } 228 }; 229 230 static struct clk_rcg2 cam_bist_mclk_cc_sleep_clk_src = { 231 .cmd_rcgr = 0x40e0, 232 .mnd_width = 0, 233 .hid_width = 5, 234 .parent_map = cam_bist_mclk_cc_parent_map_1, 235 .freq_tbl = ftbl_cam_bist_mclk_cc_sleep_clk_src, 236 .hw_clk_ctrl = true, 237 .clkr.hw.init = &(const struct clk_init_data) { 238 .name = "cam_bist_mclk_cc_sleep_clk_src", 239 .parent_data = cam_bist_mclk_cc_parent_data_1, 240 .num_parents = ARRAY_SIZE(cam_bist_mclk_cc_parent_data_1), 241 .flags = CLK_SET_RATE_PARENT, 242 .ops = &clk_rcg2_shared_ops, 243 }, 244 }; 245 246 static struct clk_branch cam_bist_mclk_cc_mclk0_clk = { 247 .halt_reg = 0x4018, 248 .halt_check = BRANCH_HALT, 249 .clkr = { 250 .enable_reg = 0x4018, 251 .enable_mask = BIT(0), 252 .hw.init = &(const struct clk_init_data) { 253 .name = "cam_bist_mclk_cc_mclk0_clk", 254 .parent_hws = (const struct clk_hw*[]) { 255 &cam_bist_mclk_cc_mclk0_clk_src.clkr.hw, 256 }, 257 .num_parents = 1, 258 .flags = CLK_SET_RATE_PARENT, 259 .ops = &clk_branch2_ops, 260 }, 261 }, 262 }; 263 264 static struct clk_branch cam_bist_mclk_cc_mclk1_clk = { 265 .halt_reg = 0x4034, 266 .halt_check = BRANCH_HALT, 267 .clkr = { 268 .enable_reg = 0x4034, 269 .enable_mask = BIT(0), 270 .hw.init = &(const struct clk_init_data) { 271 .name = "cam_bist_mclk_cc_mclk1_clk", 272 .parent_hws = (const struct clk_hw*[]) { 273 &cam_bist_mclk_cc_mclk1_clk_src.clkr.hw, 274 }, 275 .num_parents = 1, 276 .flags = CLK_SET_RATE_PARENT, 277 .ops = &clk_branch2_ops, 278 }, 279 }, 280 }; 281 282 static struct clk_branch cam_bist_mclk_cc_mclk2_clk = { 283 .halt_reg = 0x4050, 284 .halt_check = BRANCH_HALT, 285 .clkr = { 286 .enable_reg = 0x4050, 287 .enable_mask = BIT(0), 288 .hw.init = &(const struct clk_init_data) { 289 .name = "cam_bist_mclk_cc_mclk2_clk", 290 .parent_hws = (const struct clk_hw*[]) { 291 &cam_bist_mclk_cc_mclk2_clk_src.clkr.hw, 292 }, 293 .num_parents = 1, 294 .flags = CLK_SET_RATE_PARENT, 295 .ops = &clk_branch2_ops, 296 }, 297 }, 298 }; 299 300 static struct clk_branch cam_bist_mclk_cc_mclk3_clk = { 301 .halt_reg = 0x406c, 302 .halt_check = BRANCH_HALT, 303 .clkr = { 304 .enable_reg = 0x406c, 305 .enable_mask = BIT(0), 306 .hw.init = &(const struct clk_init_data) { 307 .name = "cam_bist_mclk_cc_mclk3_clk", 308 .parent_hws = (const struct clk_hw*[]) { 309 &cam_bist_mclk_cc_mclk3_clk_src.clkr.hw, 310 }, 311 .num_parents = 1, 312 .flags = CLK_SET_RATE_PARENT, 313 .ops = &clk_branch2_ops, 314 }, 315 }, 316 }; 317 318 static struct clk_branch cam_bist_mclk_cc_mclk4_clk = { 319 .halt_reg = 0x4088, 320 .halt_check = BRANCH_HALT, 321 .clkr = { 322 .enable_reg = 0x4088, 323 .enable_mask = BIT(0), 324 .hw.init = &(const struct clk_init_data) { 325 .name = "cam_bist_mclk_cc_mclk4_clk", 326 .parent_hws = (const struct clk_hw*[]) { 327 &cam_bist_mclk_cc_mclk4_clk_src.clkr.hw, 328 }, 329 .num_parents = 1, 330 .flags = CLK_SET_RATE_PARENT, 331 .ops = &clk_branch2_ops, 332 }, 333 }, 334 }; 335 336 static struct clk_branch cam_bist_mclk_cc_mclk5_clk = { 337 .halt_reg = 0x40a4, 338 .halt_check = BRANCH_HALT, 339 .clkr = { 340 .enable_reg = 0x40a4, 341 .enable_mask = BIT(0), 342 .hw.init = &(const struct clk_init_data) { 343 .name = "cam_bist_mclk_cc_mclk5_clk", 344 .parent_hws = (const struct clk_hw*[]) { 345 &cam_bist_mclk_cc_mclk5_clk_src.clkr.hw, 346 }, 347 .num_parents = 1, 348 .flags = CLK_SET_RATE_PARENT, 349 .ops = &clk_branch2_ops, 350 }, 351 }, 352 }; 353 354 static struct clk_branch cam_bist_mclk_cc_mclk6_clk = { 355 .halt_reg = 0x40c0, 356 .halt_check = BRANCH_HALT, 357 .clkr = { 358 .enable_reg = 0x40c0, 359 .enable_mask = BIT(0), 360 .hw.init = &(const struct clk_init_data) { 361 .name = "cam_bist_mclk_cc_mclk6_clk", 362 .parent_hws = (const struct clk_hw*[]) { 363 &cam_bist_mclk_cc_mclk6_clk_src.clkr.hw, 364 }, 365 .num_parents = 1, 366 .flags = CLK_SET_RATE_PARENT, 367 .ops = &clk_branch2_ops, 368 }, 369 }, 370 }; 371 372 static struct clk_branch cam_bist_mclk_cc_mclk7_clk = { 373 .halt_reg = 0x40dc, 374 .halt_check = BRANCH_HALT, 375 .clkr = { 376 .enable_reg = 0x40dc, 377 .enable_mask = BIT(0), 378 .hw.init = &(const struct clk_init_data) { 379 .name = "cam_bist_mclk_cc_mclk7_clk", 380 .parent_hws = (const struct clk_hw*[]) { 381 &cam_bist_mclk_cc_mclk7_clk_src.clkr.hw, 382 }, 383 .num_parents = 1, 384 .flags = CLK_SET_RATE_PARENT, 385 .ops = &clk_branch2_ops, 386 }, 387 }, 388 }; 389 390 static struct clk_regmap *cam_bist_mclk_cc_eliza_clocks[] = { 391 [CAM_BIST_MCLK_CC_MCLK0_CLK] = &cam_bist_mclk_cc_mclk0_clk.clkr, 392 [CAM_BIST_MCLK_CC_MCLK0_CLK_SRC] = &cam_bist_mclk_cc_mclk0_clk_src.clkr, 393 [CAM_BIST_MCLK_CC_MCLK1_CLK] = &cam_bist_mclk_cc_mclk1_clk.clkr, 394 [CAM_BIST_MCLK_CC_MCLK1_CLK_SRC] = &cam_bist_mclk_cc_mclk1_clk_src.clkr, 395 [CAM_BIST_MCLK_CC_MCLK2_CLK] = &cam_bist_mclk_cc_mclk2_clk.clkr, 396 [CAM_BIST_MCLK_CC_MCLK2_CLK_SRC] = &cam_bist_mclk_cc_mclk2_clk_src.clkr, 397 [CAM_BIST_MCLK_CC_MCLK3_CLK] = &cam_bist_mclk_cc_mclk3_clk.clkr, 398 [CAM_BIST_MCLK_CC_MCLK3_CLK_SRC] = &cam_bist_mclk_cc_mclk3_clk_src.clkr, 399 [CAM_BIST_MCLK_CC_MCLK4_CLK] = &cam_bist_mclk_cc_mclk4_clk.clkr, 400 [CAM_BIST_MCLK_CC_MCLK4_CLK_SRC] = &cam_bist_mclk_cc_mclk4_clk_src.clkr, 401 [CAM_BIST_MCLK_CC_MCLK5_CLK] = &cam_bist_mclk_cc_mclk5_clk.clkr, 402 [CAM_BIST_MCLK_CC_MCLK5_CLK_SRC] = &cam_bist_mclk_cc_mclk5_clk_src.clkr, 403 [CAM_BIST_MCLK_CC_MCLK6_CLK] = &cam_bist_mclk_cc_mclk6_clk.clkr, 404 [CAM_BIST_MCLK_CC_MCLK6_CLK_SRC] = &cam_bist_mclk_cc_mclk6_clk_src.clkr, 405 [CAM_BIST_MCLK_CC_MCLK7_CLK] = &cam_bist_mclk_cc_mclk7_clk.clkr, 406 [CAM_BIST_MCLK_CC_MCLK7_CLK_SRC] = &cam_bist_mclk_cc_mclk7_clk_src.clkr, 407 [CAM_BIST_MCLK_CC_PLL0] = &cam_bist_mclk_cc_pll0.clkr, 408 [CAM_BIST_MCLK_CC_SLEEP_CLK_SRC] = &cam_bist_mclk_cc_sleep_clk_src.clkr, 409 }; 410 411 static struct clk_alpha_pll *cam_bist_mclk_cc_eliza_plls[] = { 412 &cam_bist_mclk_cc_pll0, 413 }; 414 415 static const u32 cam_bist_mclk_cc_eliza_critical_cbcrs[] = { 416 0x40f8, /* CAM_BIST_MCLK_CC_SLEEP_CLK */ 417 }; 418 419 static const struct regmap_config cam_bist_mclk_cc_eliza_regmap_config = { 420 .reg_bits = 32, 421 .reg_stride = 4, 422 .val_bits = 32, 423 .max_register = 0x5010, 424 .fast_io = true, 425 }; 426 427 static const struct qcom_cc_driver_data cam_bist_mclk_cc_eliza_driver_data = { 428 .alpha_plls = cam_bist_mclk_cc_eliza_plls, 429 .num_alpha_plls = ARRAY_SIZE(cam_bist_mclk_cc_eliza_plls), 430 .clk_cbcrs = cam_bist_mclk_cc_eliza_critical_cbcrs, 431 .num_clk_cbcrs = ARRAY_SIZE(cam_bist_mclk_cc_eliza_critical_cbcrs), 432 }; 433 434 static const struct qcom_cc_desc cam_bist_mclk_cc_eliza_desc = { 435 .config = &cam_bist_mclk_cc_eliza_regmap_config, 436 .clks = cam_bist_mclk_cc_eliza_clocks, 437 .num_clks = ARRAY_SIZE(cam_bist_mclk_cc_eliza_clocks), 438 .use_rpm = true, 439 .driver_data = &cam_bist_mclk_cc_eliza_driver_data, 440 }; 441 442 static const struct of_device_id cam_bist_mclk_cc_eliza_match_table[] = { 443 { .compatible = "qcom,eliza-cambistmclkcc" }, 444 { } 445 }; 446 MODULE_DEVICE_TABLE(of, cam_bist_mclk_cc_eliza_match_table); 447 448 static int cam_bist_mclk_cc_eliza_probe(struct platform_device *pdev) 449 { 450 return qcom_cc_probe(pdev, &cam_bist_mclk_cc_eliza_desc); 451 } 452 453 static struct platform_driver cam_bist_mclk_cc_eliza_driver = { 454 .probe = cam_bist_mclk_cc_eliza_probe, 455 .driver = { 456 .name = "cambistmclkcc-eliza", 457 .of_match_table = cam_bist_mclk_cc_eliza_match_table, 458 }, 459 }; 460 461 module_platform_driver(cam_bist_mclk_cc_eliza_driver); 462 463 MODULE_DESCRIPTION("QTI CAMBISTMCLKCC Eliza Driver"); 464 MODULE_LICENSE("GPL"); 465