Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
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,gpucc-sm8150.h>
0012 
0013 #include "common.h"
0014 #include "clk-alpha-pll.h"
0015 #include "clk-branch.h"
0016 #include "clk-pll.h"
0017 #include "clk-rcg.h"
0018 #include "clk-regmap.h"
0019 #include "reset.h"
0020 #include "gdsc.h"
0021 
0022 enum {
0023     P_BI_TCXO,
0024     P_GPLL0_OUT_MAIN,
0025     P_GPLL0_OUT_MAIN_DIV,
0026     P_GPU_CC_PLL1_OUT_MAIN,
0027 };
0028 
0029 static const struct pll_vco trion_vco[] = {
0030     { 249600000, 2000000000, 0 },
0031 };
0032 
0033 static struct alpha_pll_config gpu_cc_pll1_config = {
0034     .l = 0x1a,
0035     .alpha = 0xaaa,
0036     .config_ctl_val = 0x20485699,
0037     .config_ctl_hi_val = 0x00002267,
0038     .config_ctl_hi1_val = 0x00000024,
0039     .test_ctl_val = 0x00000000,
0040     .test_ctl_hi_val = 0x00000002,
0041     .test_ctl_hi1_val = 0x00000000,
0042     .user_ctl_val = 0x00000000,
0043     .user_ctl_hi_val = 0x00000805,
0044     .user_ctl_hi1_val = 0x000000d0,
0045 };
0046 
0047 static struct clk_alpha_pll gpu_cc_pll1 = {
0048     .offset = 0x100,
0049     .vco_table = trion_vco,
0050     .num_vco = ARRAY_SIZE(trion_vco),
0051     .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_TRION],
0052     .clkr = {
0053         .hw.init = &(struct clk_init_data){
0054             .name = "gpu_cc_pll1",
0055             .parent_data =  &(const struct clk_parent_data){
0056                 .fw_name = "bi_tcxo",
0057             },
0058             .num_parents = 1,
0059             .ops = &clk_alpha_pll_trion_ops,
0060         },
0061     },
0062 };
0063 
0064 static const struct parent_map gpu_cc_parent_map_0[] = {
0065     { P_BI_TCXO, 0 },
0066     { P_GPU_CC_PLL1_OUT_MAIN, 3 },
0067     { P_GPLL0_OUT_MAIN, 5 },
0068     { P_GPLL0_OUT_MAIN_DIV, 6 },
0069 };
0070 
0071 static const struct clk_parent_data gpu_cc_parent_data_0[] = {
0072     { .fw_name = "bi_tcxo" },
0073     { .hw = &gpu_cc_pll1.clkr.hw },
0074     { .fw_name = "gcc_gpu_gpll0_clk_src" },
0075     { .fw_name = "gcc_gpu_gpll0_div_clk_src" },
0076 };
0077 
0078 static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src[] = {
0079     F(19200000, P_BI_TCXO, 1, 0, 0),
0080     F(200000000, P_GPLL0_OUT_MAIN_DIV, 1.5, 0, 0),
0081     F(500000000, P_GPU_CC_PLL1_OUT_MAIN, 1, 0, 0),
0082     { }
0083 };
0084 
0085 static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src_sc8180x[] = {
0086     F(19200000, P_BI_TCXO, 1, 0, 0),
0087     F(200000000, P_GPLL0_OUT_MAIN_DIV, 1.5, 0, 0),
0088     F(400000000, P_GPLL0_OUT_MAIN, 1.5, 0, 0),
0089     F(500000000, P_GPU_CC_PLL1_OUT_MAIN, 1, 0, 0),
0090     { }
0091 };
0092 
0093 static struct clk_rcg2 gpu_cc_gmu_clk_src = {
0094     .cmd_rcgr = 0x1120,
0095     .mnd_width = 0,
0096     .hid_width = 5,
0097     .parent_map = gpu_cc_parent_map_0,
0098     .freq_tbl = ftbl_gpu_cc_gmu_clk_src,
0099     .clkr.hw.init = &(struct clk_init_data){
0100         .name = "gpu_cc_gmu_clk_src",
0101         .parent_data = gpu_cc_parent_data_0,
0102         .num_parents = ARRAY_SIZE(gpu_cc_parent_data_0),
0103         .flags = CLK_SET_RATE_PARENT,
0104         .ops = &clk_rcg2_ops,
0105     },
0106 };
0107 
0108 static struct clk_branch gpu_cc_ahb_clk = {
0109     .halt_reg = 0x1078,
0110     .halt_check = BRANCH_HALT_DELAY,
0111     .clkr = {
0112         .enable_reg = 0x1078,
0113         .enable_mask = BIT(0),
0114         .hw.init = &(struct clk_init_data){
0115             .name = "gpu_cc_ahb_clk",
0116             .ops = &clk_branch2_ops,
0117         },
0118     },
0119 };
0120 
0121 static struct clk_branch gpu_cc_crc_ahb_clk = {
0122     .halt_reg = 0x107c,
0123     .halt_check = BRANCH_HALT,
0124     .clkr = {
0125         .enable_reg = 0x107c,
0126         .enable_mask = BIT(0),
0127         .hw.init = &(struct clk_init_data){
0128             .name = "gpu_cc_crc_ahb_clk",
0129             .ops = &clk_branch2_ops,
0130         },
0131     },
0132 };
0133 
0134 static struct clk_branch gpu_cc_cx_apb_clk = {
0135     .halt_reg = 0x1088,
0136     .halt_check = BRANCH_HALT,
0137     .clkr = {
0138         .enable_reg = 0x1088,
0139         .enable_mask = BIT(0),
0140         .hw.init = &(struct clk_init_data){
0141             .name = "gpu_cc_cx_apb_clk",
0142             .ops = &clk_branch2_ops,
0143         },
0144     },
0145 };
0146 
0147 static struct clk_branch gpu_cc_cx_gmu_clk = {
0148     .halt_reg = 0x1098,
0149     .halt_check = BRANCH_HALT,
0150     .clkr = {
0151         .enable_reg = 0x1098,
0152         .enable_mask = BIT(0),
0153         .hw.init = &(struct clk_init_data){
0154             .name = "gpu_cc_cx_gmu_clk",
0155             .parent_hws = (const struct clk_hw*[]){
0156                 &gpu_cc_gmu_clk_src.clkr.hw,
0157             },
0158             .num_parents = 1,
0159             .flags = CLK_SET_RATE_PARENT,
0160             .ops = &clk_branch2_ops,
0161         },
0162     },
0163 };
0164 
0165 static struct clk_branch gpu_cc_cx_snoc_dvm_clk = {
0166     .halt_reg = 0x108c,
0167     .halt_check = BRANCH_HALT,
0168     .clkr = {
0169         .enable_reg = 0x108c,
0170         .enable_mask = BIT(0),
0171         .hw.init = &(struct clk_init_data){
0172             .name = "gpu_cc_cx_snoc_dvm_clk",
0173             .ops = &clk_branch2_ops,
0174         },
0175     },
0176 };
0177 
0178 static struct clk_branch gpu_cc_cxo_aon_clk = {
0179     .halt_reg = 0x1004,
0180     .halt_check = BRANCH_HALT,
0181     .clkr = {
0182         .enable_reg = 0x1004,
0183         .enable_mask = BIT(0),
0184         .hw.init = &(struct clk_init_data){
0185             .name = "gpu_cc_cxo_aon_clk",
0186             .ops = &clk_branch2_ops,
0187         },
0188     },
0189 };
0190 
0191 static struct clk_branch gpu_cc_cxo_clk = {
0192     .halt_reg = 0x109c,
0193     .halt_check = BRANCH_HALT,
0194     .clkr = {
0195         .enable_reg = 0x109c,
0196         .enable_mask = BIT(0),
0197         .hw.init = &(struct clk_init_data){
0198             .name = "gpu_cc_cxo_clk",
0199             .ops = &clk_branch2_ops,
0200         },
0201     },
0202 };
0203 
0204 static struct clk_branch gpu_cc_gx_gmu_clk = {
0205     .halt_reg = 0x1064,
0206     .halt_check = BRANCH_HALT,
0207     .clkr = {
0208         .enable_reg = 0x1064,
0209         .enable_mask = BIT(0),
0210         .hw.init = &(struct clk_init_data){
0211             .name = "gpu_cc_gx_gmu_clk",
0212             .parent_hws = (const struct clk_hw*[]){
0213                 &gpu_cc_gmu_clk_src.clkr.hw,
0214             },
0215             .num_parents = 1,
0216             .flags = CLK_SET_RATE_PARENT,
0217             .ops = &clk_branch2_ops,
0218         },
0219     },
0220 };
0221 
0222 static struct gdsc gpu_cx_gdsc = {
0223     .gdscr = 0x106c,
0224     .gds_hw_ctrl = 0x1540,
0225     .pd = {
0226         .name = "gpu_cx_gdsc",
0227     },
0228     .pwrsts = PWRSTS_OFF_ON,
0229     .flags = VOTABLE,
0230 };
0231 
0232 static struct gdsc gpu_gx_gdsc = {
0233     .gdscr = 0x100c,
0234     .clamp_io_ctrl = 0x1508,
0235     .pd = {
0236         .name = "gpu_gx_gdsc",
0237         .power_on = gdsc_gx_do_nothing_enable,
0238     },
0239     .pwrsts = PWRSTS_OFF_ON,
0240     .flags = CLAMP_IO | AON_RESET | POLL_CFG_GDSCR,
0241 };
0242 
0243 static struct clk_regmap *gpu_cc_sm8150_clocks[] = {
0244     [GPU_CC_AHB_CLK] = &gpu_cc_ahb_clk.clkr,
0245     [GPU_CC_CRC_AHB_CLK] = &gpu_cc_crc_ahb_clk.clkr,
0246     [GPU_CC_CX_APB_CLK] = &gpu_cc_cx_apb_clk.clkr,
0247     [GPU_CC_CX_GMU_CLK] = &gpu_cc_cx_gmu_clk.clkr,
0248     [GPU_CC_CX_SNOC_DVM_CLK] = &gpu_cc_cx_snoc_dvm_clk.clkr,
0249     [GPU_CC_CXO_AON_CLK] = &gpu_cc_cxo_aon_clk.clkr,
0250     [GPU_CC_CXO_CLK] = &gpu_cc_cxo_clk.clkr,
0251     [GPU_CC_GMU_CLK_SRC] = &gpu_cc_gmu_clk_src.clkr,
0252     [GPU_CC_GX_GMU_CLK] = &gpu_cc_gx_gmu_clk.clkr,
0253     [GPU_CC_PLL1] = &gpu_cc_pll1.clkr,
0254 };
0255 
0256 static const struct qcom_reset_map gpu_cc_sm8150_resets[] = {
0257     [GPUCC_GPU_CC_CX_BCR] = { 0x1068 },
0258     [GPUCC_GPU_CC_GMU_BCR] = { 0x111c },
0259     [GPUCC_GPU_CC_GX_BCR] = { 0x1008 },
0260     [GPUCC_GPU_CC_SPDM_BCR] = { 0x1110 },
0261     [GPUCC_GPU_CC_XO_BCR] = { 0x1000 },
0262 };
0263 
0264 static struct gdsc *gpu_cc_sm8150_gdscs[] = {
0265     [GPU_CX_GDSC] = &gpu_cx_gdsc,
0266     [GPU_GX_GDSC] = &gpu_gx_gdsc,
0267 };
0268 
0269 static const struct regmap_config gpu_cc_sm8150_regmap_config = {
0270     .reg_bits   = 32,
0271     .reg_stride = 4,
0272     .val_bits   = 32,
0273     .max_register   = 0x8008,
0274     .fast_io    = true,
0275 };
0276 
0277 static const struct qcom_cc_desc gpu_cc_sm8150_desc = {
0278     .config = &gpu_cc_sm8150_regmap_config,
0279     .clks = gpu_cc_sm8150_clocks,
0280     .num_clks = ARRAY_SIZE(gpu_cc_sm8150_clocks),
0281     .resets = gpu_cc_sm8150_resets,
0282     .num_resets = ARRAY_SIZE(gpu_cc_sm8150_resets),
0283     .gdscs = gpu_cc_sm8150_gdscs,
0284     .num_gdscs = ARRAY_SIZE(gpu_cc_sm8150_gdscs),
0285 };
0286 
0287 static const struct of_device_id gpu_cc_sm8150_match_table[] = {
0288     { .compatible = "qcom,sc8180x-gpucc" },
0289     { .compatible = "qcom,sm8150-gpucc" },
0290     { }
0291 };
0292 MODULE_DEVICE_TABLE(of, gpu_cc_sm8150_match_table);
0293 
0294 static int gpu_cc_sm8150_probe(struct platform_device *pdev)
0295 {
0296     struct regmap *regmap;
0297 
0298     regmap = qcom_cc_map(pdev, &gpu_cc_sm8150_desc);
0299     if (IS_ERR(regmap))
0300         return PTR_ERR(regmap);
0301 
0302     if (of_device_is_compatible(pdev->dev.of_node, "qcom,sc8180x-gpucc"))
0303         gpu_cc_gmu_clk_src.freq_tbl = ftbl_gpu_cc_gmu_clk_src_sc8180x;
0304 
0305     clk_trion_pll_configure(&gpu_cc_pll1, regmap, &gpu_cc_pll1_config);
0306 
0307     return qcom_cc_really_probe(pdev, &gpu_cc_sm8150_desc, regmap);
0308 }
0309 
0310 static struct platform_driver gpu_cc_sm8150_driver = {
0311     .probe = gpu_cc_sm8150_probe,
0312     .driver = {
0313         .name = "sm8150-gpucc",
0314         .of_match_table = gpu_cc_sm8150_match_table,
0315     },
0316 };
0317 
0318 static int __init gpu_cc_sm8150_init(void)
0319 {
0320     return platform_driver_register(&gpu_cc_sm8150_driver);
0321 }
0322 subsys_initcall(gpu_cc_sm8150_init);
0323 
0324 static void __exit gpu_cc_sm8150_exit(void)
0325 {
0326     platform_driver_unregister(&gpu_cc_sm8150_driver);
0327 }
0328 module_exit(gpu_cc_sm8150_exit);
0329 
0330 MODULE_DESCRIPTION("QTI GPUCC SM8150 Driver");
0331 MODULE_LICENSE("GPL v2");