1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
4 * Copyright (c) 2023, Linaro Limited
7 #include <linux/clk-provider.h>
8 #include <linux/module.h>
9 #include <linux/platform_device.h>
10 #include <linux/pm_clock.h>
11 #include <linux/pm_runtime.h>
12 #include <linux/regmap.h>
14 #include <dt-bindings/clock/qcom,sm8350-videocc.h>
15 #include <dt-bindings/reset/qcom,sm8350-videocc.h>
17 #include "clk-alpha-pll.h"
18 #include "clk-branch.h"
20 #include "clk-regmap.h"
21 #include "clk-regmap-divider.h"
36 P_VIDEO_PLL0_OUT_MAIN,
37 P_VIDEO_PLL1_OUT_MAIN,
40 static const struct pll_vco lucid_5lpe_vco[] = {
41 { 249600000, 1750000000, 0 },
44 static const struct alpha_pll_config video_pll0_config = {
47 .config_ctl_val = 0x20485699,
48 .config_ctl_hi_val = 0x00002261,
49 .config_ctl_hi1_val = 0x2a9a699c,
50 .test_ctl_val = 0x00000000,
51 .test_ctl_hi_val = 0x00000000,
52 .test_ctl_hi1_val = 0x01800000,
53 .user_ctl_val = 0x00000000,
54 .user_ctl_hi_val = 0x00000805,
55 .user_ctl_hi1_val = 0x00000000,
58 static struct clk_alpha_pll video_pll0 = {
60 .vco_table = lucid_5lpe_vco,
61 .num_vco = ARRAY_SIZE(lucid_5lpe_vco),
62 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
64 .hw.init = &(const struct clk_init_data) {
66 .parent_data = &(const struct clk_parent_data){
70 .ops = &clk_alpha_pll_lucid_5lpe_ops,
75 static const struct alpha_pll_config video_pll1_config = {
78 .config_ctl_val = 0x20485699,
79 .config_ctl_hi_val = 0x00002261,
80 .config_ctl_hi1_val = 0x2a9a699c,
81 .test_ctl_val = 0x00000000,
82 .test_ctl_hi_val = 0x00000000,
83 .test_ctl_hi1_val = 0x01800000,
84 .user_ctl_val = 0x00000000,
85 .user_ctl_hi_val = 0x00000805,
86 .user_ctl_hi1_val = 0x00000000,
89 static struct clk_alpha_pll video_pll1 = {
91 .vco_table = lucid_5lpe_vco,
92 .num_vco = ARRAY_SIZE(lucid_5lpe_vco),
93 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
95 .hw.init = &(const struct clk_init_data) {
97 .parent_data = &(const struct clk_parent_data){
101 .ops = &clk_alpha_pll_lucid_5lpe_ops,
106 static const struct parent_map video_cc_parent_map_0[] = {
110 static const struct clk_parent_data video_cc_parent_data_0[] = {
111 { .index = DT_BI_TCXO_AO },
114 static const struct parent_map video_cc_parent_map_1[] = {
116 { P_VIDEO_PLL0_OUT_MAIN, 1 },
119 static const struct clk_parent_data video_cc_parent_data_1[] = {
120 { .index = DT_BI_TCXO },
121 { .hw = &video_pll0.clkr.hw },
124 static const struct parent_map video_cc_parent_map_2[] = {
126 { P_VIDEO_PLL1_OUT_MAIN, 1 },
129 static const struct clk_parent_data video_cc_parent_data_2[] = {
130 { .index = DT_BI_TCXO },
131 { .hw = &video_pll1.clkr.hw },
134 static const struct freq_tbl ftbl_video_cc_ahb_clk_src[] = {
135 F(19200000, P_BI_TCXO, 1, 0, 0),
139 static struct clk_rcg2 video_cc_ahb_clk_src = {
143 .parent_map = video_cc_parent_map_0,
144 .freq_tbl = ftbl_video_cc_ahb_clk_src,
145 .clkr.hw.init = &(const struct clk_init_data) {
146 .name = "video_cc_ahb_clk_src",
147 .parent_data = video_cc_parent_data_0,
148 .num_parents = ARRAY_SIZE(video_cc_parent_data_0),
149 .flags = CLK_SET_RATE_PARENT,
150 .ops = &clk_rcg2_shared_ops,
154 static const struct freq_tbl ftbl_video_cc_mvs0_clk_src[] = {
155 F(720000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
156 F(1014000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
157 F(1098000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
158 F(1332000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
162 static struct clk_rcg2 video_cc_mvs0_clk_src = {
166 .parent_map = video_cc_parent_map_1,
167 .freq_tbl = ftbl_video_cc_mvs0_clk_src,
168 .clkr.hw.init = &(const struct clk_init_data) {
169 .name = "video_cc_mvs0_clk_src",
170 .parent_data = video_cc_parent_data_1,
171 .num_parents = ARRAY_SIZE(video_cc_parent_data_1),
172 .flags = CLK_SET_RATE_PARENT,
173 .ops = &clk_rcg2_shared_ops,
177 static const struct freq_tbl ftbl_video_cc_mvs1_clk_src[] = {
178 F(840000000, P_VIDEO_PLL1_OUT_MAIN, 1, 0, 0),
179 F(1098000000, P_VIDEO_PLL1_OUT_MAIN, 1, 0, 0),
180 F(1332000000, P_VIDEO_PLL1_OUT_MAIN, 1, 0, 0),
184 static struct clk_rcg2 video_cc_mvs1_clk_src = {
188 .parent_map = video_cc_parent_map_2,
189 .freq_tbl = ftbl_video_cc_mvs1_clk_src,
190 .clkr.hw.init = &(const struct clk_init_data) {
191 .name = "video_cc_mvs1_clk_src",
192 .parent_data = video_cc_parent_data_2,
193 .num_parents = ARRAY_SIZE(video_cc_parent_data_2),
194 .flags = CLK_SET_RATE_PARENT,
195 .ops = &clk_rcg2_shared_ops,
199 static const struct freq_tbl ftbl_video_cc_sleep_clk_src[] = {
200 F(32000, P_SLEEP_CLK, 1, 0, 0),
204 static struct clk_rcg2 video_cc_sleep_clk_src = {
208 .freq_tbl = ftbl_video_cc_sleep_clk_src,
209 .clkr.hw.init = &(const struct clk_init_data) {
210 .name = "video_cc_sleep_clk_src",
211 .parent_data = &(const struct clk_parent_data){
212 .index = DT_SLEEP_CLK,
215 .flags = CLK_SET_RATE_PARENT,
216 .ops = &clk_rcg2_ops,
220 static struct clk_rcg2 video_cc_xo_clk_src = {
224 .parent_map = video_cc_parent_map_0,
225 .freq_tbl = ftbl_video_cc_ahb_clk_src,
226 .clkr.hw.init = &(const struct clk_init_data) {
227 .name = "video_cc_xo_clk_src",
228 .parent_data = video_cc_parent_data_0,
229 .num_parents = ARRAY_SIZE(video_cc_parent_data_0),
230 .flags = CLK_SET_RATE_PARENT,
231 .ops = &clk_rcg2_ops,
235 static struct clk_regmap_div video_cc_mvs0_div_clk_src = {
239 .clkr.hw.init = &(const struct clk_init_data) {
240 .name = "video_cc_mvs0_div_clk_src",
241 .parent_hws = (const struct clk_hw*[]){
242 &video_cc_mvs0_clk_src.clkr.hw,
245 .flags = CLK_SET_RATE_PARENT,
246 .ops = &clk_regmap_div_ro_ops,
250 static struct clk_regmap_div video_cc_mvs0c_div2_div_clk_src = {
254 .clkr.hw.init = &(const struct clk_init_data) {
255 .name = "video_cc_mvs0c_div2_div_clk_src",
256 .parent_hws = (const struct clk_hw*[]){
257 &video_cc_mvs0_clk_src.clkr.hw,
260 .flags = CLK_SET_RATE_PARENT,
261 .ops = &clk_regmap_div_ro_ops,
265 static struct clk_regmap_div video_cc_mvs1_div_clk_src = {
269 .clkr.hw.init = &(const struct clk_init_data) {
270 .name = "video_cc_mvs1_div_clk_src",
271 .parent_hws = (const struct clk_hw*[]){
272 &video_cc_mvs1_clk_src.clkr.hw,
275 .flags = CLK_SET_RATE_PARENT,
276 .ops = &clk_regmap_div_ro_ops,
280 static struct clk_regmap_div video_cc_mvs1c_div2_div_clk_src = {
284 .clkr.hw.init = &(const struct clk_init_data) {
285 .name = "video_cc_mvs1c_div2_div_clk_src",
286 .parent_hws = (const struct clk_hw*[]){
287 &video_cc_mvs1_clk_src.clkr.hw,
290 .flags = CLK_SET_RATE_PARENT,
291 .ops = &clk_regmap_div_ro_ops,
295 static struct clk_branch video_cc_mvs0_clk = {
297 .halt_check = BRANCH_HALT_VOTED,
302 .enable_mask = BIT(0),
303 .hw.init = &(const struct clk_init_data) {
304 .name = "video_cc_mvs0_clk",
305 .parent_hws = (const struct clk_hw*[]){
306 &video_cc_mvs0_div_clk_src.clkr.hw,
309 .flags = CLK_SET_RATE_PARENT,
310 .ops = &clk_branch2_ops,
315 static struct clk_branch video_cc_mvs0c_clk = {
317 .halt_check = BRANCH_HALT,
320 .enable_mask = BIT(0),
321 .hw.init = &(const struct clk_init_data) {
322 .name = "video_cc_mvs0c_clk",
323 .parent_hws = (const struct clk_hw*[]){
324 &video_cc_mvs0c_div2_div_clk_src.clkr.hw,
327 .flags = CLK_SET_RATE_PARENT,
328 .ops = &clk_branch2_ops,
333 static struct clk_branch video_cc_mvs1_clk = {
335 .halt_check = BRANCH_HALT_VOTED,
340 .enable_mask = BIT(0),
341 .hw.init = &(const struct clk_init_data) {
342 .name = "video_cc_mvs1_clk",
343 .parent_hws = (const struct clk_hw*[]){
344 &video_cc_mvs1_div_clk_src.clkr.hw,
347 .flags = CLK_SET_RATE_PARENT,
348 .ops = &clk_branch2_ops,
353 static struct clk_branch video_cc_mvs1_div2_clk = {
355 .halt_check = BRANCH_HALT_VOTED,
360 .enable_mask = BIT(0),
361 .hw.init = &(const struct clk_init_data) {
362 .name = "video_cc_mvs1_div2_clk",
363 .parent_hws = (const struct clk_hw*[]){
364 &video_cc_mvs1c_div2_div_clk_src.clkr.hw,
367 .flags = CLK_SET_RATE_PARENT,
368 .ops = &clk_branch2_ops,
373 static struct clk_branch video_cc_mvs1c_clk = {
375 .halt_check = BRANCH_HALT,
378 .enable_mask = BIT(0),
379 .hw.init = &(const struct clk_init_data) {
380 .name = "video_cc_mvs1c_clk",
381 .parent_hws = (const struct clk_hw*[]){
382 &video_cc_mvs1c_div2_div_clk_src.clkr.hw,
385 .flags = CLK_SET_RATE_PARENT,
386 .ops = &clk_branch2_ops,
391 static struct clk_branch video_cc_sleep_clk = {
393 .halt_check = BRANCH_HALT,
396 .enable_mask = BIT(0),
397 .hw.init = &(const struct clk_init_data) {
398 .name = "video_cc_sleep_clk",
399 .parent_hws = (const struct clk_hw*[]){
400 &video_cc_sleep_clk_src.clkr.hw,
403 .flags = CLK_SET_RATE_PARENT,
404 .ops = &clk_branch2_ops,
409 static struct gdsc mvs0c_gdsc = {
412 .name = "mvs0c_gdsc",
414 .flags = RETAIN_FF_ENABLE,
415 .pwrsts = PWRSTS_OFF_ON,
418 static struct gdsc mvs1c_gdsc = {
421 .name = "mvs1c_gdsc",
423 .flags = RETAIN_FF_ENABLE,
424 .pwrsts = PWRSTS_OFF_ON,
427 static struct gdsc mvs0_gdsc = {
432 .flags = HW_CTRL | RETAIN_FF_ENABLE,
433 .pwrsts = PWRSTS_OFF_ON,
436 static struct gdsc mvs1_gdsc = {
441 .flags = HW_CTRL | RETAIN_FF_ENABLE,
442 .pwrsts = PWRSTS_OFF_ON,
445 static struct clk_regmap *video_cc_sm8350_clocks[] = {
446 [VIDEO_CC_AHB_CLK_SRC] = &video_cc_ahb_clk_src.clkr,
447 [VIDEO_CC_MVS0_CLK] = &video_cc_mvs0_clk.clkr,
448 [VIDEO_CC_MVS0_CLK_SRC] = &video_cc_mvs0_clk_src.clkr,
449 [VIDEO_CC_MVS0_DIV_CLK_SRC] = &video_cc_mvs0_div_clk_src.clkr,
450 [VIDEO_CC_MVS0C_CLK] = &video_cc_mvs0c_clk.clkr,
451 [VIDEO_CC_MVS0C_DIV2_DIV_CLK_SRC] = &video_cc_mvs0c_div2_div_clk_src.clkr,
452 [VIDEO_CC_MVS1_CLK] = &video_cc_mvs1_clk.clkr,
453 [VIDEO_CC_MVS1_CLK_SRC] = &video_cc_mvs1_clk_src.clkr,
454 [VIDEO_CC_MVS1_DIV2_CLK] = &video_cc_mvs1_div2_clk.clkr,
455 [VIDEO_CC_MVS1_DIV_CLK_SRC] = &video_cc_mvs1_div_clk_src.clkr,
456 [VIDEO_CC_MVS1C_CLK] = &video_cc_mvs1c_clk.clkr,
457 [VIDEO_CC_MVS1C_DIV2_DIV_CLK_SRC] = &video_cc_mvs1c_div2_div_clk_src.clkr,
458 [VIDEO_CC_SLEEP_CLK] = &video_cc_sleep_clk.clkr,
459 [VIDEO_CC_SLEEP_CLK_SRC] = &video_cc_sleep_clk_src.clkr,
460 [VIDEO_CC_XO_CLK_SRC] = &video_cc_xo_clk_src.clkr,
461 [VIDEO_PLL0] = &video_pll0.clkr,
462 [VIDEO_PLL1] = &video_pll1.clkr,
465 static const struct qcom_reset_map video_cc_sm8350_resets[] = {
466 [VIDEO_CC_CVP_INTERFACE_BCR] = { 0xe54 },
467 [VIDEO_CC_CVP_MVS0_BCR] = { 0xd14 },
468 [VIDEO_CC_MVS0C_CLK_ARES] = { 0xc34, 2 },
469 [VIDEO_CC_CVP_MVS0C_BCR] = { 0xbf4 },
470 [VIDEO_CC_CVP_MVS1_BCR] = { 0xd94 },
471 [VIDEO_CC_MVS1C_CLK_ARES] = { 0xcd4, 2 },
472 [VIDEO_CC_CVP_MVS1C_BCR] = { 0xc94 },
475 static struct gdsc *video_cc_sm8350_gdscs[] = {
476 [MVS0C_GDSC] = &mvs0c_gdsc,
477 [MVS1C_GDSC] = &mvs1c_gdsc,
478 [MVS0_GDSC] = &mvs0_gdsc,
479 [MVS1_GDSC] = &mvs1_gdsc,
482 static const struct regmap_config video_cc_sm8350_regmap_config = {
486 .max_register = 0x10000,
490 static struct qcom_cc_desc video_cc_sm8350_desc = {
491 .config = &video_cc_sm8350_regmap_config,
492 .clks = video_cc_sm8350_clocks,
493 .num_clks = ARRAY_SIZE(video_cc_sm8350_clocks),
494 .resets = video_cc_sm8350_resets,
495 .num_resets = ARRAY_SIZE(video_cc_sm8350_resets),
496 .gdscs = video_cc_sm8350_gdscs,
497 .num_gdscs = ARRAY_SIZE(video_cc_sm8350_gdscs),
500 static int video_cc_sm8350_probe(struct platform_device *pdev)
502 struct regmap *regmap;
505 ret = devm_pm_runtime_enable(&pdev->dev);
509 ret = pm_runtime_resume_and_get(&pdev->dev);
513 regmap = qcom_cc_map(pdev, &video_cc_sm8350_desc);
514 if (IS_ERR(regmap)) {
515 pm_runtime_put(&pdev->dev);
516 return PTR_ERR(regmap);
519 clk_lucid_pll_configure(&video_pll0, regmap, &video_pll0_config);
520 clk_lucid_pll_configure(&video_pll1, regmap, &video_pll1_config);
523 * Keep clocks always enabled:
527 regmap_update_bits(regmap, 0xe58, BIT(0), BIT(0));
528 regmap_update_bits(regmap, 0xeec, BIT(0), BIT(0));
530 ret = qcom_cc_really_probe(pdev, &video_cc_sm8350_desc, regmap);
531 pm_runtime_put(&pdev->dev);
536 static const struct of_device_id video_cc_sm8350_match_table[] = {
537 { .compatible = "qcom,sm8350-videocc" },
540 MODULE_DEVICE_TABLE(of, video_cc_sm8350_match_table);
542 static struct platform_driver video_cc_sm8350_driver = {
543 .probe = video_cc_sm8350_probe,
545 .name = "sm8350-videocc",
546 .of_match_table = video_cc_sm8350_match_table,
549 module_platform_driver(video_cc_sm8350_driver);
551 MODULE_DESCRIPTION("QTI SM8350 VIDEOCC Driver");
552 MODULE_LICENSE("GPL");