1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
6 #include <linux/clk-provider.h>
7 #include <linux/module.h>
8 #include <linux/platform_device.h>
9 #include <linux/regmap.h>
11 #include <dt-bindings/clock/qcom,videocc-sm8250.h>
13 #include "clk-alpha-pll.h"
14 #include "clk-branch.h"
16 #include "clk-regmap.h"
17 #include "clk-regmap-divider.h"
25 P_CORE_BI_PLL_TEST_SE,
26 P_VIDEO_PLL0_OUT_MAIN,
27 P_VIDEO_PLL1_OUT_MAIN,
30 static struct pll_vco lucid_vco[] = {
31 { 249600000, 2000000000, 0 },
34 static const struct alpha_pll_config video_pll0_config = {
37 .config_ctl_val = 0x20485699,
38 .config_ctl_hi_val = 0x00002261,
39 .config_ctl_hi1_val = 0x329A699C,
40 .user_ctl_val = 0x00000000,
41 .user_ctl_hi_val = 0x00000805,
42 .user_ctl_hi1_val = 0x00000000,
45 static struct clk_alpha_pll video_pll0 = {
47 .vco_table = lucid_vco,
48 .num_vco = ARRAY_SIZE(lucid_vco),
49 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
51 .hw.init = &(struct clk_init_data){
53 .parent_data = &(const struct clk_parent_data){
57 .ops = &clk_alpha_pll_lucid_ops,
62 static const struct alpha_pll_config video_pll1_config = {
65 .config_ctl_val = 0x20485699,
66 .config_ctl_hi_val = 0x00002261,
67 .config_ctl_hi1_val = 0x329A699C,
68 .user_ctl_val = 0x00000000,
69 .user_ctl_hi_val = 0x00000805,
70 .user_ctl_hi1_val = 0x00000000,
73 static struct clk_alpha_pll video_pll1 = {
75 .vco_table = lucid_vco,
76 .num_vco = ARRAY_SIZE(lucid_vco),
77 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
79 .hw.init = &(struct clk_init_data){
81 .parent_data = &(const struct clk_parent_data){
85 .ops = &clk_alpha_pll_lucid_ops,
90 static const struct parent_map video_cc_parent_map_1[] = {
92 { P_VIDEO_PLL0_OUT_MAIN, 1 },
95 static const struct clk_parent_data video_cc_parent_data_1[] = {
96 { .fw_name = "bi_tcxo" },
97 { .hw = &video_pll0.clkr.hw },
100 static const struct parent_map video_cc_parent_map_2[] = {
102 { P_VIDEO_PLL1_OUT_MAIN, 1 },
105 static const struct clk_parent_data video_cc_parent_data_2[] = {
106 { .fw_name = "bi_tcxo" },
107 { .hw = &video_pll1.clkr.hw },
110 static const struct freq_tbl ftbl_video_cc_mvs0_clk_src[] = {
111 F(19200000, P_BI_TCXO, 1, 0, 0),
112 F(720000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
113 F(1014000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
114 F(1098000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
115 F(1332000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
119 static struct clk_rcg2 video_cc_mvs0_clk_src = {
123 .parent_map = video_cc_parent_map_1,
124 .freq_tbl = ftbl_video_cc_mvs0_clk_src,
125 .clkr.hw.init = &(struct clk_init_data){
126 .name = "video_cc_mvs0_clk_src",
127 .parent_data = video_cc_parent_data_1,
128 .num_parents = ARRAY_SIZE(video_cc_parent_data_1),
129 .flags = CLK_SET_RATE_PARENT,
130 .ops = &clk_rcg2_shared_ops,
134 static const struct freq_tbl ftbl_video_cc_mvs1_clk_src[] = {
135 F(19200000, P_BI_TCXO, 1, 0, 0),
136 F(840000000, P_VIDEO_PLL1_OUT_MAIN, 1, 0, 0),
137 F(1098000000, P_VIDEO_PLL1_OUT_MAIN, 1, 0, 0),
138 F(1332000000, P_VIDEO_PLL1_OUT_MAIN, 1, 0, 0),
142 static struct clk_rcg2 video_cc_mvs1_clk_src = {
146 .parent_map = video_cc_parent_map_2,
147 .freq_tbl = ftbl_video_cc_mvs1_clk_src,
148 .clkr.hw.init = &(struct clk_init_data){
149 .name = "video_cc_mvs1_clk_src",
150 .parent_data = video_cc_parent_data_2,
151 .num_parents = ARRAY_SIZE(video_cc_parent_data_2),
152 .flags = CLK_SET_RATE_PARENT,
153 .ops = &clk_rcg2_shared_ops,
157 static struct clk_regmap_div video_cc_mvs0c_div2_div_clk_src = {
161 .clkr.hw.init = &(struct clk_init_data) {
162 .name = "video_cc_mvs0c_div2_div_clk_src",
163 .parent_data = &(const struct clk_parent_data){
164 .hw = &video_cc_mvs0_clk_src.clkr.hw,
167 .flags = CLK_SET_RATE_PARENT,
168 .ops = &clk_regmap_div_ro_ops,
172 static struct clk_regmap_div video_cc_mvs0_div_clk_src = {
176 .clkr.hw.init = &(struct clk_init_data) {
177 .name = "video_cc_mvs0_div_clk_src",
178 .parent_data = &(const struct clk_parent_data){
179 .hw = &video_cc_mvs0_clk_src.clkr.hw,
182 .flags = CLK_SET_RATE_PARENT,
183 .ops = &clk_regmap_div_ro_ops,
187 static struct clk_regmap_div video_cc_mvs1c_div2_div_clk_src = {
191 .clkr.hw.init = &(struct clk_init_data) {
192 .name = "video_cc_mvs1c_div2_div_clk_src",
193 .parent_data = &(const struct clk_parent_data){
194 .hw = &video_cc_mvs1_clk_src.clkr.hw,
197 .flags = CLK_SET_RATE_PARENT,
198 .ops = &clk_regmap_div_ro_ops,
202 static struct clk_branch video_cc_mvs0c_clk = {
204 .halt_check = BRANCH_HALT,
207 .enable_mask = BIT(0),
208 .hw.init = &(struct clk_init_data){
209 .name = "video_cc_mvs0c_clk",
210 .parent_data = &(const struct clk_parent_data){
211 .hw = &video_cc_mvs0c_div2_div_clk_src.clkr.hw,
214 .flags = CLK_SET_RATE_PARENT,
215 .ops = &clk_branch2_ops,
220 static struct clk_branch video_cc_mvs0_clk = {
222 .halt_check = BRANCH_HALT_VOTED,
225 .enable_mask = BIT(0),
226 .hw.init = &(struct clk_init_data){
227 .name = "video_cc_mvs0_clk",
228 .parent_data = &(const struct clk_parent_data){
229 .hw = &video_cc_mvs0_div_clk_src.clkr.hw,
232 .flags = CLK_SET_RATE_PARENT,
233 .ops = &clk_branch2_ops,
238 static struct clk_branch video_cc_mvs1_div2_clk = {
240 .halt_check = BRANCH_HALT_VOTED,
243 .enable_mask = BIT(0),
244 .hw.init = &(struct clk_init_data){
245 .name = "video_cc_mvs1_div2_clk",
246 .parent_data = &(const struct clk_parent_data){
247 .hw = &video_cc_mvs1c_div2_div_clk_src.clkr.hw,
250 .flags = CLK_SET_RATE_PARENT,
251 .ops = &clk_branch2_ops,
256 static struct clk_branch video_cc_mvs1c_clk = {
258 .halt_check = BRANCH_HALT_VOTED,
261 .enable_mask = BIT(0),
262 .hw.init = &(struct clk_init_data){
263 .name = "video_cc_mvs1c_clk",
264 .parent_data = &(const struct clk_parent_data){
265 .hw = &video_cc_mvs1c_div2_div_clk_src.clkr.hw,
268 .flags = CLK_SET_RATE_PARENT,
269 .ops = &clk_branch2_ops,
274 static struct gdsc mvs0c_gdsc = {
277 .name = "mvs0c_gdsc",
280 .pwrsts = PWRSTS_OFF_ON,
284 static struct gdsc mvs1c_gdsc = {
287 .name = "mvs1c_gdsc",
290 .pwrsts = PWRSTS_OFF_ON,
294 static struct gdsc mvs0_gdsc = {
300 .pwrsts = PWRSTS_OFF_ON,
304 static struct gdsc mvs1_gdsc = {
310 .pwrsts = PWRSTS_OFF_ON,
314 static struct clk_regmap *video_cc_sm8250_clocks[] = {
315 [VIDEO_CC_MVS0_CLK] = &video_cc_mvs0_clk.clkr,
316 [VIDEO_CC_MVS0_CLK_SRC] = &video_cc_mvs0_clk_src.clkr,
317 [VIDEO_CC_MVS0_DIV_CLK_SRC] = &video_cc_mvs0_div_clk_src.clkr,
318 [VIDEO_CC_MVS0C_CLK] = &video_cc_mvs0c_clk.clkr,
319 [VIDEO_CC_MVS0C_DIV2_DIV_CLK_SRC] = &video_cc_mvs0c_div2_div_clk_src.clkr,
320 [VIDEO_CC_MVS1_CLK_SRC] = &video_cc_mvs1_clk_src.clkr,
321 [VIDEO_CC_MVS1_DIV2_CLK] = &video_cc_mvs1_div2_clk.clkr,
322 [VIDEO_CC_MVS1C_CLK] = &video_cc_mvs1c_clk.clkr,
323 [VIDEO_CC_MVS1C_DIV2_DIV_CLK_SRC] = &video_cc_mvs1c_div2_div_clk_src.clkr,
324 [VIDEO_CC_PLL0] = &video_pll0.clkr,
325 [VIDEO_CC_PLL1] = &video_pll1.clkr,
328 static const struct qcom_reset_map video_cc_sm8250_resets[] = {
329 [VIDEO_CC_CVP_INTERFACE_BCR] = { 0xe54 },
330 [VIDEO_CC_CVP_MVS0_BCR] = { 0xd14 },
331 [VIDEO_CC_MVS0C_CLK_ARES] = { 0xc34, 2 },
332 [VIDEO_CC_CVP_MVS0C_BCR] = { 0xbf4 },
333 [VIDEO_CC_CVP_MVS1_BCR] = { 0xd94 },
334 [VIDEO_CC_MVS1C_CLK_ARES] = { 0xcd4, 2 },
335 [VIDEO_CC_CVP_MVS1C_BCR] = { 0xc94 },
338 static struct gdsc *video_cc_sm8250_gdscs[] = {
339 [MVS0C_GDSC] = &mvs0c_gdsc,
340 [MVS1C_GDSC] = &mvs1c_gdsc,
341 [MVS0_GDSC] = &mvs0_gdsc,
342 [MVS1_GDSC] = &mvs1_gdsc,
345 static const struct regmap_config video_cc_sm8250_regmap_config = {
349 .max_register = 0xf4c,
353 static const struct qcom_cc_desc video_cc_sm8250_desc = {
354 .config = &video_cc_sm8250_regmap_config,
355 .clks = video_cc_sm8250_clocks,
356 .num_clks = ARRAY_SIZE(video_cc_sm8250_clocks),
357 .resets = video_cc_sm8250_resets,
358 .num_resets = ARRAY_SIZE(video_cc_sm8250_resets),
359 .gdscs = video_cc_sm8250_gdscs,
360 .num_gdscs = ARRAY_SIZE(video_cc_sm8250_gdscs),
363 static const struct of_device_id video_cc_sm8250_match_table[] = {
364 { .compatible = "qcom,sm8250-videocc" },
367 MODULE_DEVICE_TABLE(of, video_cc_sm8250_match_table);
369 static int video_cc_sm8250_probe(struct platform_device *pdev)
371 struct regmap *regmap;
373 regmap = qcom_cc_map(pdev, &video_cc_sm8250_desc);
375 return PTR_ERR(regmap);
377 clk_lucid_pll_configure(&video_pll0, regmap, &video_pll0_config);
378 clk_lucid_pll_configure(&video_pll1, regmap, &video_pll1_config);
380 /* Keep VIDEO_CC_AHB_CLK and VIDEO_CC_XO_CLK ALWAYS-ON */
381 regmap_update_bits(regmap, 0xe58, BIT(0), BIT(0));
382 regmap_update_bits(regmap, 0xeec, BIT(0), BIT(0));
384 return qcom_cc_really_probe(pdev, &video_cc_sm8250_desc, regmap);
387 static struct platform_driver video_cc_sm8250_driver = {
388 .probe = video_cc_sm8250_probe,
390 .name = "sm8250-videocc",
391 .of_match_table = video_cc_sm8250_match_table,
395 static int __init video_cc_sm8250_init(void)
397 return platform_driver_register(&video_cc_sm8250_driver);
399 subsys_initcall(video_cc_sm8250_init);
401 static void __exit video_cc_sm8250_exit(void)
403 platform_driver_unregister(&video_cc_sm8250_driver);
405 module_exit(video_cc_sm8250_exit);
407 MODULE_LICENSE("GPL v2");
408 MODULE_DESCRIPTION("QTI VIDEOCC SM8250 Driver");