0001
0002
0003
0004
0005
0006 #include <linux/clk-provider.h>
0007 #include <linux/module.h>
0008 #include <linux/platform_device.h>
0009 #include <linux/regmap.h>
0010
0011 #include <dt-bindings/clock/qcom,videocc-sdm845.h>
0012
0013 #include "common.h"
0014 #include "clk-alpha-pll.h"
0015 #include "clk-branch.h"
0016 #include "clk-rcg.h"
0017 #include "clk-regmap.h"
0018 #include "clk-pll.h"
0019 #include "gdsc.h"
0020
0021 enum {
0022 P_BI_TCXO,
0023 P_VIDEO_PLL0_OUT_MAIN,
0024
0025
0026 };
0027
0028 static const struct alpha_pll_config video_pll0_config = {
0029 .l = 0x10,
0030 .alpha = 0xaaab,
0031 };
0032
0033 static struct clk_alpha_pll video_pll0 = {
0034 .offset = 0x42c,
0035 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA],
0036 .clkr = {
0037 .hw.init = &(struct clk_init_data){
0038 .name = "video_pll0",
0039 .parent_data = &(const struct clk_parent_data){
0040 .fw_name = "bi_tcxo", .name = "bi_tcxo",
0041 },
0042 .num_parents = 1,
0043 .ops = &clk_alpha_pll_fabia_ops,
0044 },
0045 },
0046 };
0047
0048 static const struct parent_map video_cc_parent_map_0[] = {
0049 { P_BI_TCXO, 0 },
0050 { P_VIDEO_PLL0_OUT_MAIN, 1 },
0051
0052
0053 };
0054
0055 static const struct clk_parent_data video_cc_parent_data_0[] = {
0056 { .fw_name = "bi_tcxo", .name = "bi_tcxo" },
0057 { .hw = &video_pll0.clkr.hw },
0058
0059
0060 };
0061
0062 static const struct freq_tbl ftbl_video_cc_venus_clk_src[] = {
0063 F(100000000, P_VIDEO_PLL0_OUT_MAIN, 4, 0, 0),
0064 F(200000000, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
0065 F(330000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
0066 F(404000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
0067 F(444000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
0068 F(533000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
0069 { }
0070 };
0071
0072 static struct clk_rcg2 video_cc_venus_clk_src = {
0073 .cmd_rcgr = 0x7f0,
0074 .mnd_width = 0,
0075 .hid_width = 5,
0076 .parent_map = video_cc_parent_map_0,
0077 .freq_tbl = ftbl_video_cc_venus_clk_src,
0078 .clkr.hw.init = &(struct clk_init_data){
0079 .name = "video_cc_venus_clk_src",
0080 .parent_data = video_cc_parent_data_0,
0081 .num_parents = ARRAY_SIZE(video_cc_parent_data_0),
0082 .flags = CLK_SET_RATE_PARENT,
0083 .ops = &clk_rcg2_shared_ops,
0084 },
0085 };
0086
0087 static struct clk_branch video_cc_apb_clk = {
0088 .halt_reg = 0x990,
0089 .halt_check = BRANCH_HALT,
0090 .clkr = {
0091 .enable_reg = 0x990,
0092 .enable_mask = BIT(0),
0093 .hw.init = &(struct clk_init_data){
0094 .name = "video_cc_apb_clk",
0095 .ops = &clk_branch2_ops,
0096 },
0097 },
0098 };
0099
0100 static struct clk_branch video_cc_at_clk = {
0101 .halt_reg = 0x9f0,
0102 .halt_check = BRANCH_HALT,
0103 .clkr = {
0104 .enable_reg = 0x9f0,
0105 .enable_mask = BIT(0),
0106 .hw.init = &(struct clk_init_data){
0107 .name = "video_cc_at_clk",
0108 .ops = &clk_branch2_ops,
0109 },
0110 },
0111 };
0112
0113 static struct clk_branch video_cc_qdss_trig_clk = {
0114 .halt_reg = 0x970,
0115 .halt_check = BRANCH_HALT,
0116 .clkr = {
0117 .enable_reg = 0x970,
0118 .enable_mask = BIT(0),
0119 .hw.init = &(struct clk_init_data){
0120 .name = "video_cc_qdss_trig_clk",
0121 .ops = &clk_branch2_ops,
0122 },
0123 },
0124 };
0125
0126 static struct clk_branch video_cc_qdss_tsctr_div8_clk = {
0127 .halt_reg = 0x9d0,
0128 .halt_check = BRANCH_HALT,
0129 .clkr = {
0130 .enable_reg = 0x9d0,
0131 .enable_mask = BIT(0),
0132 .hw.init = &(struct clk_init_data){
0133 .name = "video_cc_qdss_tsctr_div8_clk",
0134 .ops = &clk_branch2_ops,
0135 },
0136 },
0137 };
0138
0139 static struct clk_branch video_cc_vcodec0_axi_clk = {
0140 .halt_reg = 0x930,
0141 .halt_check = BRANCH_HALT,
0142 .clkr = {
0143 .enable_reg = 0x930,
0144 .enable_mask = BIT(0),
0145 .hw.init = &(struct clk_init_data){
0146 .name = "video_cc_vcodec0_axi_clk",
0147 .ops = &clk_branch2_ops,
0148 },
0149 },
0150 };
0151
0152 static struct clk_branch video_cc_vcodec0_core_clk = {
0153 .halt_reg = 0x890,
0154 .halt_check = BRANCH_VOTED,
0155 .clkr = {
0156 .enable_reg = 0x890,
0157 .enable_mask = BIT(0),
0158 .hw.init = &(struct clk_init_data){
0159 .name = "video_cc_vcodec0_core_clk",
0160 .parent_hws = (const struct clk_hw*[]){
0161 &video_cc_venus_clk_src.clkr.hw,
0162 },
0163 .num_parents = 1,
0164 .flags = CLK_SET_RATE_PARENT,
0165 .ops = &clk_branch2_ops,
0166 },
0167 },
0168 };
0169
0170 static struct clk_branch video_cc_vcodec1_axi_clk = {
0171 .halt_reg = 0x950,
0172 .halt_check = BRANCH_HALT,
0173 .clkr = {
0174 .enable_reg = 0x950,
0175 .enable_mask = BIT(0),
0176 .hw.init = &(struct clk_init_data){
0177 .name = "video_cc_vcodec1_axi_clk",
0178 .ops = &clk_branch2_ops,
0179 },
0180 },
0181 };
0182
0183 static struct clk_branch video_cc_vcodec1_core_clk = {
0184 .halt_reg = 0x8d0,
0185 .halt_check = BRANCH_VOTED,
0186 .clkr = {
0187 .enable_reg = 0x8d0,
0188 .enable_mask = BIT(0),
0189 .hw.init = &(struct clk_init_data){
0190 .name = "video_cc_vcodec1_core_clk",
0191 .parent_hws = (const struct clk_hw*[]){
0192 &video_cc_venus_clk_src.clkr.hw,
0193 },
0194 .num_parents = 1,
0195 .flags = CLK_SET_RATE_PARENT,
0196 .ops = &clk_branch2_ops,
0197 },
0198 },
0199 };
0200
0201 static struct clk_branch video_cc_venus_ahb_clk = {
0202 .halt_reg = 0x9b0,
0203 .halt_check = BRANCH_HALT,
0204 .clkr = {
0205 .enable_reg = 0x9b0,
0206 .enable_mask = BIT(0),
0207 .hw.init = &(struct clk_init_data){
0208 .name = "video_cc_venus_ahb_clk",
0209 .ops = &clk_branch2_ops,
0210 },
0211 },
0212 };
0213
0214 static struct clk_branch video_cc_venus_ctl_axi_clk = {
0215 .halt_reg = 0x910,
0216 .halt_check = BRANCH_HALT,
0217 .clkr = {
0218 .enable_reg = 0x910,
0219 .enable_mask = BIT(0),
0220 .hw.init = &(struct clk_init_data){
0221 .name = "video_cc_venus_ctl_axi_clk",
0222 .ops = &clk_branch2_ops,
0223 },
0224 },
0225 };
0226
0227 static struct clk_branch video_cc_venus_ctl_core_clk = {
0228 .halt_reg = 0x850,
0229 .halt_check = BRANCH_HALT,
0230 .clkr = {
0231 .enable_reg = 0x850,
0232 .enable_mask = BIT(0),
0233 .hw.init = &(struct clk_init_data){
0234 .name = "video_cc_venus_ctl_core_clk",
0235 .parent_hws = (const struct clk_hw*[]){
0236 &video_cc_venus_clk_src.clkr.hw,
0237 },
0238 .num_parents = 1,
0239 .flags = CLK_SET_RATE_PARENT,
0240 .ops = &clk_branch2_ops,
0241 },
0242 },
0243 };
0244
0245 static struct gdsc venus_gdsc = {
0246 .gdscr = 0x814,
0247 .pd = {
0248 .name = "venus_gdsc",
0249 },
0250 .cxcs = (unsigned int []){ 0x850, 0x910 },
0251 .cxc_count = 2,
0252 .pwrsts = PWRSTS_OFF_ON,
0253 .flags = POLL_CFG_GDSCR,
0254 };
0255
0256 static struct gdsc vcodec0_gdsc = {
0257 .gdscr = 0x874,
0258 .pd = {
0259 .name = "vcodec0_gdsc",
0260 },
0261 .cxcs = (unsigned int []){ 0x890, 0x930 },
0262 .cxc_count = 2,
0263 .flags = HW_CTRL | POLL_CFG_GDSCR,
0264 .pwrsts = PWRSTS_OFF_ON,
0265 };
0266
0267 static struct gdsc vcodec1_gdsc = {
0268 .gdscr = 0x8b4,
0269 .pd = {
0270 .name = "vcodec1_gdsc",
0271 },
0272 .cxcs = (unsigned int []){ 0x8d0, 0x950 },
0273 .cxc_count = 2,
0274 .flags = HW_CTRL | POLL_CFG_GDSCR,
0275 .pwrsts = PWRSTS_OFF_ON,
0276 };
0277
0278 static struct clk_regmap *video_cc_sdm845_clocks[] = {
0279 [VIDEO_CC_APB_CLK] = &video_cc_apb_clk.clkr,
0280 [VIDEO_CC_AT_CLK] = &video_cc_at_clk.clkr,
0281 [VIDEO_CC_QDSS_TRIG_CLK] = &video_cc_qdss_trig_clk.clkr,
0282 [VIDEO_CC_QDSS_TSCTR_DIV8_CLK] = &video_cc_qdss_tsctr_div8_clk.clkr,
0283 [VIDEO_CC_VCODEC0_AXI_CLK] = &video_cc_vcodec0_axi_clk.clkr,
0284 [VIDEO_CC_VCODEC0_CORE_CLK] = &video_cc_vcodec0_core_clk.clkr,
0285 [VIDEO_CC_VCODEC1_AXI_CLK] = &video_cc_vcodec1_axi_clk.clkr,
0286 [VIDEO_CC_VCODEC1_CORE_CLK] = &video_cc_vcodec1_core_clk.clkr,
0287 [VIDEO_CC_VENUS_AHB_CLK] = &video_cc_venus_ahb_clk.clkr,
0288 [VIDEO_CC_VENUS_CLK_SRC] = &video_cc_venus_clk_src.clkr,
0289 [VIDEO_CC_VENUS_CTL_AXI_CLK] = &video_cc_venus_ctl_axi_clk.clkr,
0290 [VIDEO_CC_VENUS_CTL_CORE_CLK] = &video_cc_venus_ctl_core_clk.clkr,
0291 [VIDEO_PLL0] = &video_pll0.clkr,
0292 };
0293
0294 static struct gdsc *video_cc_sdm845_gdscs[] = {
0295 [VENUS_GDSC] = &venus_gdsc,
0296 [VCODEC0_GDSC] = &vcodec0_gdsc,
0297 [VCODEC1_GDSC] = &vcodec1_gdsc,
0298 };
0299
0300 static const struct regmap_config video_cc_sdm845_regmap_config = {
0301 .reg_bits = 32,
0302 .reg_stride = 4,
0303 .val_bits = 32,
0304 .max_register = 0xb90,
0305 .fast_io = true,
0306 };
0307
0308 static const struct qcom_cc_desc video_cc_sdm845_desc = {
0309 .config = &video_cc_sdm845_regmap_config,
0310 .clks = video_cc_sdm845_clocks,
0311 .num_clks = ARRAY_SIZE(video_cc_sdm845_clocks),
0312 .gdscs = video_cc_sdm845_gdscs,
0313 .num_gdscs = ARRAY_SIZE(video_cc_sdm845_gdscs),
0314 };
0315
0316 static const struct of_device_id video_cc_sdm845_match_table[] = {
0317 { .compatible = "qcom,sdm845-videocc" },
0318 { }
0319 };
0320 MODULE_DEVICE_TABLE(of, video_cc_sdm845_match_table);
0321
0322 static int video_cc_sdm845_probe(struct platform_device *pdev)
0323 {
0324 struct regmap *regmap;
0325
0326 regmap = qcom_cc_map(pdev, &video_cc_sdm845_desc);
0327 if (IS_ERR(regmap))
0328 return PTR_ERR(regmap);
0329
0330 clk_fabia_pll_configure(&video_pll0, regmap, &video_pll0_config);
0331
0332 return qcom_cc_really_probe(pdev, &video_cc_sdm845_desc, regmap);
0333 }
0334
0335 static struct platform_driver video_cc_sdm845_driver = {
0336 .probe = video_cc_sdm845_probe,
0337 .driver = {
0338 .name = "sdm845-videocc",
0339 .of_match_table = video_cc_sdm845_match_table,
0340 },
0341 };
0342
0343 static int __init video_cc_sdm845_init(void)
0344 {
0345 return platform_driver_register(&video_cc_sdm845_driver);
0346 }
0347 subsys_initcall(video_cc_sdm845_init);
0348
0349 static void __exit video_cc_sdm845_exit(void)
0350 {
0351 platform_driver_unregister(&video_cc_sdm845_driver);
0352 }
0353 module_exit(video_cc_sdm845_exit);
0354
0355 MODULE_LICENSE("GPL v2");