Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (c) 2020, The Linux Foundation. All rights reserved.
0004  * Copyright (c) 2020, AngeloGioacchino Del Regno
0005  *                     <angelogioacchino.delregno@somainline.org>
0006  */
0007 
0008 #include <linux/bitops.h>
0009 #include <linux/clk.h>
0010 #include <linux/clk-provider.h>
0011 #include <linux/err.h>
0012 #include <linux/kernel.h>
0013 #include <linux/module.h>
0014 #include <linux/platform_device.h>
0015 #include <linux/of.h>
0016 #include <linux/of_device.h>
0017 #include <linux/regmap.h>
0018 #include <linux/reset-controller.h>
0019 #include <dt-bindings/clock/qcom,gpucc-sdm660.h>
0020 
0021 #include "clk-alpha-pll.h"
0022 #include "common.h"
0023 #include "clk-regmap.h"
0024 #include "clk-pll.h"
0025 #include "clk-rcg.h"
0026 #include "clk-branch.h"
0027 #include "gdsc.h"
0028 #include "reset.h"
0029 
0030 enum {
0031     P_GPU_XO,
0032     P_GPLL0_OUT_MAIN,
0033     P_GPLL0_OUT_MAIN_DIV,
0034     P_GPU_PLL0_PLL_OUT_MAIN,
0035     P_GPU_PLL1_PLL_OUT_MAIN,
0036 };
0037 
0038 static struct clk_branch gpucc_cxo_clk = {
0039     .halt_reg = 0x1020,
0040     .clkr = {
0041         .enable_reg = 0x1020,
0042         .enable_mask = BIT(0),
0043         .hw.init = &(struct clk_init_data){
0044             .name = "gpucc_cxo_clk",
0045             .parent_data = &(const struct clk_parent_data){
0046                 .fw_name = "xo"
0047             },
0048             .num_parents = 1,
0049             .ops = &clk_branch2_ops,
0050             .flags = CLK_IS_CRITICAL,
0051         },
0052     },
0053 };
0054 
0055 static struct pll_vco gpu_vco[] = {
0056     { 1000000000, 2000000000, 0 },
0057     { 500000000,  1000000000, 2 },
0058     { 250000000,   500000000, 3 },
0059 };
0060 
0061 static struct clk_alpha_pll gpu_pll0_pll_out_main = {
0062     .offset = 0x0,
0063     .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
0064     .vco_table = gpu_vco,
0065     .num_vco = ARRAY_SIZE(gpu_vco),
0066     .clkr.hw.init = &(struct clk_init_data){
0067         .name = "gpu_pll0_pll_out_main",
0068         .parent_hws = (const struct clk_hw*[]){
0069             &gpucc_cxo_clk.clkr.hw,
0070         },
0071         .num_parents = 1,
0072         .ops = &clk_alpha_pll_ops,
0073     },
0074 };
0075 
0076 static struct clk_alpha_pll gpu_pll1_pll_out_main = {
0077     .offset = 0x40,
0078     .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
0079     .vco_table = gpu_vco,
0080     .num_vco = ARRAY_SIZE(gpu_vco),
0081     .clkr.hw.init = &(struct clk_init_data){
0082         .name = "gpu_pll1_pll_out_main",
0083         .parent_hws = (const struct clk_hw*[]){
0084             &gpucc_cxo_clk.clkr.hw,
0085         },
0086         .num_parents = 1,
0087         .ops = &clk_alpha_pll_ops,
0088     },
0089 };
0090 
0091 static const struct parent_map gpucc_parent_map_1[] = {
0092     { P_GPU_XO, 0 },
0093     { P_GPU_PLL0_PLL_OUT_MAIN, 1 },
0094     { P_GPU_PLL1_PLL_OUT_MAIN, 3 },
0095     { P_GPLL0_OUT_MAIN, 5 },
0096 };
0097 
0098 static const struct clk_parent_data gpucc_parent_data_1[] = {
0099     { .hw = &gpucc_cxo_clk.clkr.hw },
0100     { .hw = &gpu_pll0_pll_out_main.clkr.hw },
0101     { .hw = &gpu_pll1_pll_out_main.clkr.hw },
0102     { .fw_name = "gcc_gpu_gpll0_clk" },
0103 };
0104 
0105 static struct clk_rcg2_gfx3d gfx3d_clk_src = {
0106     .div = 2,
0107     .rcg = {
0108         .cmd_rcgr = 0x1070,
0109         .mnd_width = 0,
0110         .hid_width = 5,
0111         .parent_map = gpucc_parent_map_1,
0112         .clkr.hw.init = &(struct clk_init_data){
0113             .name = "gfx3d_clk_src",
0114             .parent_data = gpucc_parent_data_1,
0115             .num_parents = ARRAY_SIZE(gpucc_parent_data_1),
0116             .ops = &clk_gfx3d_ops,
0117             .flags = CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
0118         },
0119     },
0120     .hws = (struct clk_hw*[]){
0121         &gpucc_cxo_clk.clkr.hw,
0122         &gpu_pll0_pll_out_main.clkr.hw,
0123         &gpu_pll1_pll_out_main.clkr.hw,
0124     }
0125 };
0126 
0127 static struct clk_branch gpucc_gfx3d_clk = {
0128     .halt_reg = 0x1098,
0129     .halt_check = BRANCH_HALT,
0130     .hwcg_reg = 0x1098,
0131     .hwcg_bit = 1,
0132     .clkr = {
0133         .enable_reg = 0x1098,
0134         .enable_mask = BIT(0),
0135         .hw.init = &(struct clk_init_data){
0136             .name = "gpucc_gfx3d_clk",
0137             .parent_hws = (const struct clk_hw*[]){
0138                 &gfx3d_clk_src.rcg.clkr.hw,
0139             },
0140             .num_parents = 1,
0141             .ops = &clk_branch2_ops,
0142             .flags = CLK_SET_RATE_PARENT,
0143         },
0144     },
0145 };
0146 
0147 static const struct parent_map gpucc_parent_map_0[] = {
0148     { P_GPU_XO, 0 },
0149     { P_GPLL0_OUT_MAIN, 5 },
0150     { P_GPLL0_OUT_MAIN_DIV, 6 },
0151 };
0152 
0153 static const struct clk_parent_data gpucc_parent_data_0[] = {
0154     { .hw = &gpucc_cxo_clk.clkr.hw },
0155     { .fw_name = "gcc_gpu_gpll0_clk" },
0156     { .fw_name = "gcc_gpu_gpll0_div_clk" },
0157 };
0158 
0159 static const struct freq_tbl ftbl_rbbmtimer_clk_src[] = {
0160     F(19200000, P_GPU_XO, 1, 0, 0),
0161     { }
0162 };
0163 
0164 static struct clk_rcg2 rbbmtimer_clk_src = {
0165     .cmd_rcgr = 0x10b0,
0166     .mnd_width = 0,
0167     .hid_width = 5,
0168     .parent_map = gpucc_parent_map_0,
0169     .freq_tbl = ftbl_rbbmtimer_clk_src,
0170     .clkr.hw.init = &(struct clk_init_data){
0171         .name = "rbbmtimer_clk_src",
0172         .parent_data = gpucc_parent_data_0,
0173         .num_parents = ARRAY_SIZE(gpucc_parent_data_0),
0174         .ops = &clk_rcg2_ops,
0175     },
0176 };
0177 
0178 static const struct freq_tbl ftbl_rbcpr_clk_src[] = {
0179     F(19200000, P_GPU_XO, 1, 0, 0),
0180     F(50000000, P_GPLL0_OUT_MAIN_DIV, 6, 0, 0),
0181     { }
0182 };
0183 
0184 static struct clk_rcg2 rbcpr_clk_src = {
0185     .cmd_rcgr = 0x1030,
0186     .mnd_width = 0,
0187     .hid_width = 5,
0188     .parent_map = gpucc_parent_map_0,
0189     .freq_tbl = ftbl_rbcpr_clk_src,
0190     .clkr.hw.init = &(struct clk_init_data){
0191         .name = "rbcpr_clk_src",
0192         .parent_data = gpucc_parent_data_0,
0193         .num_parents = ARRAY_SIZE(gpucc_parent_data_0),
0194         .ops = &clk_rcg2_ops,
0195     },
0196 };
0197 
0198 static struct clk_branch gpucc_rbbmtimer_clk = {
0199     .halt_reg = 0x10d0,
0200     .halt_check = BRANCH_HALT,
0201     .clkr = {
0202         .enable_reg = 0x10d0,
0203         .enable_mask = BIT(0),
0204         .hw.init = &(struct clk_init_data){
0205             .name = "gpucc_rbbmtimer_clk",
0206             .parent_hws = (const struct clk_hw*[]){
0207                 &rbbmtimer_clk_src.clkr.hw,
0208             },
0209             .num_parents = 1,
0210             .flags = CLK_SET_RATE_PARENT,
0211             .ops = &clk_branch2_ops,
0212         },
0213     },
0214 };
0215 
0216 static struct clk_branch gpucc_rbcpr_clk = {
0217     .halt_reg = 0x1054,
0218     .halt_check = BRANCH_HALT,
0219     .clkr = {
0220         .enable_reg = 0x1054,
0221         .enable_mask = BIT(0),
0222         .hw.init = &(struct clk_init_data){
0223             .name = "gpucc_rbcpr_clk",
0224             .parent_hws = (const struct clk_hw*[]){
0225                 &rbcpr_clk_src.clkr.hw,
0226             },
0227             .num_parents = 1,
0228             .flags = CLK_SET_RATE_PARENT,
0229             .ops = &clk_branch2_ops,
0230         },
0231     },
0232 };
0233 
0234 static struct gdsc gpu_cx_gdsc = {
0235     .gdscr = 0x1004,
0236     .gds_hw_ctrl = 0x1008,
0237     .pd = {
0238         .name = "gpu_cx",
0239     },
0240     .pwrsts = PWRSTS_OFF_ON,
0241     .flags = VOTABLE,
0242 };
0243 
0244 static struct gdsc gpu_gx_gdsc = {
0245     .gdscr = 0x1094,
0246     .clamp_io_ctrl = 0x130,
0247     .resets = (unsigned int []){ GPU_GX_BCR },
0248     .reset_count = 1,
0249     .cxcs = (unsigned int []){ 0x1098 },
0250     .cxc_count = 1,
0251     .pd = {
0252         .name = "gpu_gx",
0253     },
0254     .parent = &gpu_cx_gdsc.pd,
0255     .pwrsts = PWRSTS_OFF | PWRSTS_ON | PWRSTS_RET,
0256     .flags = CLAMP_IO | SW_RESET | AON_RESET | NO_RET_PERIPH,
0257 };
0258 
0259 static struct gdsc *gpucc_sdm660_gdscs[] = {
0260     [GPU_CX_GDSC] = &gpu_cx_gdsc,
0261     [GPU_GX_GDSC] = &gpu_gx_gdsc,
0262 };
0263 
0264 static const struct qcom_reset_map gpucc_sdm660_resets[] = {
0265     [GPU_CX_BCR] = { 0x1000 },
0266     [RBCPR_BCR] = { 0x1050 },
0267     [GPU_GX_BCR] = { 0x1090 },
0268     [SPDM_BCR] = { 0x10E0 },
0269 };
0270 
0271 static struct clk_regmap *gpucc_sdm660_clocks[] = {
0272     [GPUCC_CXO_CLK] = &gpucc_cxo_clk.clkr,
0273     [GPU_PLL0_PLL] = &gpu_pll0_pll_out_main.clkr,
0274     [GPU_PLL1_PLL] = &gpu_pll1_pll_out_main.clkr,
0275     [GFX3D_CLK_SRC] = &gfx3d_clk_src.rcg.clkr,
0276     [RBCPR_CLK_SRC] = &rbcpr_clk_src.clkr,
0277     [RBBMTIMER_CLK_SRC] = &rbbmtimer_clk_src.clkr,
0278     [GPUCC_RBCPR_CLK] = &gpucc_rbcpr_clk.clkr,
0279     [GPUCC_GFX3D_CLK] = &gpucc_gfx3d_clk.clkr,
0280     [GPUCC_RBBMTIMER_CLK] = &gpucc_rbbmtimer_clk.clkr,
0281 };
0282 
0283 static const struct regmap_config gpucc_660_regmap_config = {
0284     .reg_bits   = 32,
0285     .reg_stride = 4,
0286     .val_bits   = 32,
0287     .max_register   = 0x9034,
0288     .fast_io    = true,
0289 };
0290 
0291 static const struct qcom_cc_desc gpucc_sdm660_desc = {
0292     .config = &gpucc_660_regmap_config,
0293     .clks = gpucc_sdm660_clocks,
0294     .num_clks = ARRAY_SIZE(gpucc_sdm660_clocks),
0295     .resets = gpucc_sdm660_resets,
0296     .num_resets = ARRAY_SIZE(gpucc_sdm660_resets),
0297     .gdscs = gpucc_sdm660_gdscs,
0298     .num_gdscs = ARRAY_SIZE(gpucc_sdm660_gdscs),
0299 };
0300 
0301 static const struct of_device_id gpucc_sdm660_match_table[] = {
0302     { .compatible = "qcom,gpucc-sdm660" },
0303     { .compatible = "qcom,gpucc-sdm630" },
0304     { }
0305 };
0306 MODULE_DEVICE_TABLE(of, gpucc_sdm660_match_table);
0307 
0308 static int gpucc_sdm660_probe(struct platform_device *pdev)
0309 {
0310     struct regmap *regmap;
0311     struct alpha_pll_config gpu_pll_config = {
0312         .config_ctl_val = 0x4001055b,
0313         .alpha = 0xaaaaab00,
0314         .alpha_en_mask = BIT(24),
0315         .vco_val = 0x2 << 20,
0316         .vco_mask = 0x3 << 20,
0317         .main_output_mask = 0x1,
0318     };
0319 
0320     regmap = qcom_cc_map(pdev, &gpucc_sdm660_desc);
0321     if (IS_ERR(regmap))
0322         return PTR_ERR(regmap);
0323 
0324     /* 800MHz configuration for GPU PLL0 */
0325     gpu_pll_config.l = 0x29;
0326     gpu_pll_config.alpha_hi = 0xaa;
0327     clk_alpha_pll_configure(&gpu_pll0_pll_out_main, regmap, &gpu_pll_config);
0328 
0329     /* 740MHz configuration for GPU PLL1 */
0330     gpu_pll_config.l = 0x26;
0331     gpu_pll_config.alpha_hi = 0x8a;
0332     clk_alpha_pll_configure(&gpu_pll1_pll_out_main, regmap, &gpu_pll_config);
0333 
0334     return qcom_cc_really_probe(pdev, &gpucc_sdm660_desc, regmap);
0335 }
0336 
0337 static struct platform_driver gpucc_sdm660_driver = {
0338     .probe      = gpucc_sdm660_probe,
0339     .driver     = {
0340         .name   = "gpucc-sdm660",
0341         .of_match_table = gpucc_sdm660_match_table,
0342     },
0343 };
0344 module_platform_driver(gpucc_sdm660_driver);
0345 
0346 MODULE_DESCRIPTION("Qualcomm SDM630/SDM660 GPUCC Driver");
0347 MODULE_LICENSE("GPL v2");