1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
6 #include <linux/clk-provider.h>
7 #include <linux/mod_devicetable.h>
8 #include <linux/module.h>
9 #include <linux/platform_device.h>
10 #include <linux/pm_runtime.h>
11 #include <linux/regmap.h>
13 #include <dt-bindings/clock/qcom,sm8450-videocc.h>
15 #include "clk-alpha-pll.h"
16 #include "clk-branch.h"
18 #include "clk-regmap.h"
19 #include "clk-regmap-divider.h"
30 P_VIDEO_CC_PLL0_OUT_MAIN,
31 P_VIDEO_CC_PLL1_OUT_MAIN,
34 static const struct pll_vco lucid_evo_vco[] = {
35 { 249600000, 2020000000, 0 },
38 static const struct alpha_pll_config video_cc_pll0_config = {
39 /* .l includes CAL_L_VAL, L_VAL fields */
42 .config_ctl_val = 0x20485699,
43 .config_ctl_hi_val = 0x00182261,
44 .config_ctl_hi1_val = 0x32aa299c,
45 .user_ctl_val = 0x00000000,
46 .user_ctl_hi_val = 0x00000805,
49 static struct clk_alpha_pll video_cc_pll0 = {
51 .vco_table = lucid_evo_vco,
52 .num_vco = ARRAY_SIZE(lucid_evo_vco),
53 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_EVO],
55 .hw.init = &(const struct clk_init_data) {
56 .name = "video_cc_pll0",
57 .parent_data = &(const struct clk_parent_data) {
61 .ops = &clk_alpha_pll_lucid_evo_ops,
66 static const struct alpha_pll_config video_cc_pll1_config = {
67 /* .l includes CAL_L_VAL, L_VAL fields */
70 .config_ctl_val = 0x20485699,
71 .config_ctl_hi_val = 0x00182261,
72 .config_ctl_hi1_val = 0x32aa299c,
73 .user_ctl_val = 0x00000000,
74 .user_ctl_hi_val = 0x00000805,
77 static struct clk_alpha_pll video_cc_pll1 = {
79 .vco_table = lucid_evo_vco,
80 .num_vco = ARRAY_SIZE(lucid_evo_vco),
81 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_EVO],
83 .hw.init = &(const struct clk_init_data) {
84 .name = "video_cc_pll1",
85 .parent_data = &(const struct clk_parent_data) {
89 .ops = &clk_alpha_pll_lucid_evo_ops,
94 static const struct parent_map video_cc_parent_map_0[] = {
96 { P_VIDEO_CC_PLL0_OUT_MAIN, 1 },
99 static const struct clk_parent_data video_cc_parent_data_0[] = {
100 { .index = DT_BI_TCXO },
101 { .hw = &video_cc_pll0.clkr.hw },
104 static const struct parent_map video_cc_parent_map_1[] = {
106 { P_VIDEO_CC_PLL1_OUT_MAIN, 1 },
109 static const struct clk_parent_data video_cc_parent_data_1[] = {
110 { .index = DT_BI_TCXO },
111 { .hw = &video_cc_pll1.clkr.hw },
114 static const struct freq_tbl ftbl_video_cc_mvs0_clk_src[] = {
115 F(576000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
116 F(720000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
117 F(1014000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
118 F(1098000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
119 F(1332000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
123 static struct clk_rcg2 video_cc_mvs0_clk_src = {
127 .parent_map = video_cc_parent_map_0,
128 .freq_tbl = ftbl_video_cc_mvs0_clk_src,
129 .clkr.hw.init = &(const struct clk_init_data) {
130 .name = "video_cc_mvs0_clk_src",
131 .parent_data = video_cc_parent_data_0,
132 .num_parents = ARRAY_SIZE(video_cc_parent_data_0),
133 .flags = CLK_SET_RATE_PARENT,
134 .ops = &clk_rcg2_shared_ops,
138 static const struct freq_tbl ftbl_video_cc_mvs1_clk_src[] = {
139 F(840000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
140 F(1050000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
141 F(1350000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
142 F(1500000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
143 F(1650000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
147 static struct clk_rcg2 video_cc_mvs1_clk_src = {
151 .parent_map = video_cc_parent_map_1,
152 .freq_tbl = ftbl_video_cc_mvs1_clk_src,
153 .clkr.hw.init = &(const struct clk_init_data) {
154 .name = "video_cc_mvs1_clk_src",
155 .parent_data = video_cc_parent_data_1,
156 .num_parents = ARRAY_SIZE(video_cc_parent_data_1),
157 .flags = CLK_SET_RATE_PARENT,
158 .ops = &clk_rcg2_shared_ops,
162 static struct clk_regmap_div video_cc_mvs0_div_clk_src = {
166 .clkr.hw.init = &(const struct clk_init_data) {
167 .name = "video_cc_mvs0_div_clk_src",
168 .parent_hws = (const struct clk_hw*[]) {
169 &video_cc_mvs0_clk_src.clkr.hw,
172 .flags = CLK_SET_RATE_PARENT,
173 .ops = &clk_regmap_div_ro_ops,
177 static struct clk_regmap_div video_cc_mvs0c_div2_div_clk_src = {
181 .clkr.hw.init = &(const struct clk_init_data) {
182 .name = "video_cc_mvs0c_div2_div_clk_src",
183 .parent_hws = (const struct clk_hw*[]) {
184 &video_cc_mvs0_clk_src.clkr.hw,
187 .flags = CLK_SET_RATE_PARENT,
188 .ops = &clk_regmap_div_ro_ops,
192 static struct clk_regmap_div video_cc_mvs1_div_clk_src = {
196 .clkr.hw.init = &(const struct clk_init_data) {
197 .name = "video_cc_mvs1_div_clk_src",
198 .parent_hws = (const struct clk_hw*[]) {
199 &video_cc_mvs1_clk_src.clkr.hw,
202 .flags = CLK_SET_RATE_PARENT,
203 .ops = &clk_regmap_div_ro_ops,
207 static struct clk_regmap_div video_cc_mvs1c_div2_div_clk_src = {
211 .clkr.hw.init = &(const struct clk_init_data) {
212 .name = "video_cc_mvs1c_div2_div_clk_src",
213 .parent_hws = (const struct clk_hw*[]) {
214 &video_cc_mvs1_clk_src.clkr.hw,
217 .flags = CLK_SET_RATE_PARENT,
218 .ops = &clk_regmap_div_ro_ops,
222 static struct clk_branch video_cc_mvs0_clk = {
224 .halt_check = BRANCH_HALT_SKIP,
228 .enable_reg = 0x80b0,
229 .enable_mask = BIT(0),
230 .hw.init = &(const struct clk_init_data) {
231 .name = "video_cc_mvs0_clk",
232 .parent_hws = (const struct clk_hw*[]) {
233 &video_cc_mvs0_div_clk_src.clkr.hw,
236 .flags = CLK_SET_RATE_PARENT,
237 .ops = &clk_branch2_ops,
242 static struct clk_branch video_cc_mvs0c_clk = {
244 .halt_check = BRANCH_HALT,
246 .enable_reg = 0x8064,
247 .enable_mask = BIT(0),
248 .hw.init = &(const struct clk_init_data) {
249 .name = "video_cc_mvs0c_clk",
250 .parent_hws = (const struct clk_hw*[]) {
251 &video_cc_mvs0c_div2_div_clk_src.clkr.hw,
254 .flags = CLK_SET_RATE_PARENT,
255 .ops = &clk_branch2_ops,
260 static struct clk_branch video_cc_mvs1_clk = {
262 .halt_check = BRANCH_HALT_SKIP,
266 .enable_reg = 0x80d4,
267 .enable_mask = BIT(0),
268 .hw.init = &(const struct clk_init_data) {
269 .name = "video_cc_mvs1_clk",
270 .parent_hws = (const struct clk_hw*[]) {
271 &video_cc_mvs1_div_clk_src.clkr.hw,
274 .flags = CLK_SET_RATE_PARENT,
275 .ops = &clk_branch2_ops,
280 static struct clk_branch video_cc_mvs1c_clk = {
282 .halt_check = BRANCH_HALT,
284 .enable_reg = 0x808c,
285 .enable_mask = BIT(0),
286 .hw.init = &(const struct clk_init_data) {
287 .name = "video_cc_mvs1c_clk",
288 .parent_hws = (const struct clk_hw*[]) {
289 &video_cc_mvs1c_div2_div_clk_src.clkr.hw,
292 .flags = CLK_SET_RATE_PARENT,
293 .ops = &clk_branch2_ops,
298 static struct gdsc video_cc_mvs0c_gdsc = {
300 .en_rest_wait_val = 0x2,
301 .en_few_wait_val = 0x2,
302 .clk_dis_wait_val = 0x6,
304 .name = "video_cc_mvs0c_gdsc",
306 .pwrsts = PWRSTS_OFF_ON,
307 .flags = RETAIN_FF_ENABLE,
310 static struct gdsc video_cc_mvs0_gdsc = {
312 .en_rest_wait_val = 0x2,
313 .en_few_wait_val = 0x2,
314 .clk_dis_wait_val = 0x6,
316 .name = "video_cc_mvs0_gdsc",
318 .pwrsts = PWRSTS_OFF_ON,
319 .parent = &video_cc_mvs0c_gdsc.pd,
320 .flags = RETAIN_FF_ENABLE | HW_CTRL,
323 static struct gdsc video_cc_mvs1c_gdsc = {
325 .en_rest_wait_val = 0x2,
326 .en_few_wait_val = 0x2,
327 .clk_dis_wait_val = 0x6,
329 .name = "video_cc_mvs1c_gdsc",
331 .pwrsts = PWRSTS_OFF_ON,
332 .flags = RETAIN_FF_ENABLE,
335 static struct gdsc video_cc_mvs1_gdsc = {
337 .en_rest_wait_val = 0x2,
338 .en_few_wait_val = 0x2,
339 .clk_dis_wait_val = 0x6,
341 .name = "video_cc_mvs1_gdsc",
343 .pwrsts = PWRSTS_OFF_ON,
344 .parent = &video_cc_mvs1c_gdsc.pd,
345 .flags = RETAIN_FF_ENABLE | HW_CTRL,
348 static struct clk_regmap *video_cc_sm8450_clocks[] = {
349 [VIDEO_CC_MVS0_CLK] = &video_cc_mvs0_clk.clkr,
350 [VIDEO_CC_MVS0_CLK_SRC] = &video_cc_mvs0_clk_src.clkr,
351 [VIDEO_CC_MVS0_DIV_CLK_SRC] = &video_cc_mvs0_div_clk_src.clkr,
352 [VIDEO_CC_MVS0C_CLK] = &video_cc_mvs0c_clk.clkr,
353 [VIDEO_CC_MVS0C_DIV2_DIV_CLK_SRC] = &video_cc_mvs0c_div2_div_clk_src.clkr,
354 [VIDEO_CC_MVS1_CLK] = &video_cc_mvs1_clk.clkr,
355 [VIDEO_CC_MVS1_CLK_SRC] = &video_cc_mvs1_clk_src.clkr,
356 [VIDEO_CC_MVS1_DIV_CLK_SRC] = &video_cc_mvs1_div_clk_src.clkr,
357 [VIDEO_CC_MVS1C_CLK] = &video_cc_mvs1c_clk.clkr,
358 [VIDEO_CC_MVS1C_DIV2_DIV_CLK_SRC] = &video_cc_mvs1c_div2_div_clk_src.clkr,
359 [VIDEO_CC_PLL0] = &video_cc_pll0.clkr,
360 [VIDEO_CC_PLL1] = &video_cc_pll1.clkr,
363 static struct gdsc *video_cc_sm8450_gdscs[] = {
364 [VIDEO_CC_MVS0C_GDSC] = &video_cc_mvs0c_gdsc,
365 [VIDEO_CC_MVS0_GDSC] = &video_cc_mvs0_gdsc,
366 [VIDEO_CC_MVS1C_GDSC] = &video_cc_mvs1c_gdsc,
367 [VIDEO_CC_MVS1_GDSC] = &video_cc_mvs1_gdsc,
370 static const struct qcom_reset_map video_cc_sm8450_resets[] = {
371 [CVP_VIDEO_CC_INTERFACE_BCR] = { 0x80e0 },
372 [CVP_VIDEO_CC_MVS0_BCR] = { 0x8098 },
373 [CVP_VIDEO_CC_MVS0C_BCR] = { 0x8048 },
374 [CVP_VIDEO_CC_MVS1_BCR] = { 0x80bc },
375 [CVP_VIDEO_CC_MVS1C_BCR] = { 0x8070 },
376 [VIDEO_CC_MVS0C_CLK_ARES] = { 0x8064, 2 },
377 [VIDEO_CC_MVS1C_CLK_ARES] = { 0x808c, 2 },
380 static const struct regmap_config video_cc_sm8450_regmap_config = {
384 .max_register = 0x9f4c,
388 static struct qcom_cc_desc video_cc_sm8450_desc = {
389 .config = &video_cc_sm8450_regmap_config,
390 .clks = video_cc_sm8450_clocks,
391 .num_clks = ARRAY_SIZE(video_cc_sm8450_clocks),
392 .resets = video_cc_sm8450_resets,
393 .num_resets = ARRAY_SIZE(video_cc_sm8450_resets),
394 .gdscs = video_cc_sm8450_gdscs,
395 .num_gdscs = ARRAY_SIZE(video_cc_sm8450_gdscs),
398 static const struct of_device_id video_cc_sm8450_match_table[] = {
399 { .compatible = "qcom,sm8450-videocc" },
402 MODULE_DEVICE_TABLE(of, video_cc_sm8450_match_table);
404 static int video_cc_sm8450_probe(struct platform_device *pdev)
406 struct regmap *regmap;
409 ret = devm_pm_runtime_enable(&pdev->dev);
413 ret = pm_runtime_resume_and_get(&pdev->dev);
417 regmap = qcom_cc_map(pdev, &video_cc_sm8450_desc);
418 if (IS_ERR(regmap)) {
419 pm_runtime_put(&pdev->dev);
420 return PTR_ERR(regmap);
423 clk_lucid_evo_pll_configure(&video_cc_pll0, regmap, &video_cc_pll0_config);
424 clk_lucid_evo_pll_configure(&video_cc_pll1, regmap, &video_cc_pll1_config);
427 * Keep clocks always enabled:
432 regmap_update_bits(regmap, 0x80e4, BIT(0), BIT(0));
433 regmap_update_bits(regmap, 0x8130, BIT(0), BIT(0));
434 regmap_update_bits(regmap, 0x8114, BIT(0), BIT(0));
436 ret = qcom_cc_really_probe(pdev, &video_cc_sm8450_desc, regmap);
438 pm_runtime_put(&pdev->dev);
443 static struct platform_driver video_cc_sm8450_driver = {
444 .probe = video_cc_sm8450_probe,
446 .name = "video_cc-sm8450",
447 .of_match_table = video_cc_sm8450_match_table,
451 static int __init video_cc_sm8450_init(void)
453 return platform_driver_register(&video_cc_sm8450_driver);
455 subsys_initcall(video_cc_sm8450_init);
457 static void __exit video_cc_sm8450_exit(void)
459 platform_driver_unregister(&video_cc_sm8450_driver);
461 module_exit(video_cc_sm8450_exit);
463 MODULE_DESCRIPTION("QTI VIDEOCC SM8450 Driver");
464 MODULE_LICENSE("GPL");