1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2020, The Linux Foundation. All rights reserved.
4 * Copyright (c) 2020, AngeloGioacchino Del Regno
5 * <angelogioacchino.delregno@somainline.org>
8 #include <linux/bitops.h>
10 #include <linux/clk-provider.h>
11 #include <linux/err.h>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
16 #include <linux/of_device.h>
17 #include <linux/regmap.h>
18 #include <linux/reset-controller.h>
19 #include <dt-bindings/clock/qcom,gpucc-sdm660.h>
21 #include "clk-alpha-pll.h"
23 #include "clk-regmap.h"
26 #include "clk-branch.h"
32 P_CORE_BI_PLL_TEST_SE,
35 P_GPU_PLL0_PLL_OUT_MAIN,
36 P_GPU_PLL1_PLL_OUT_MAIN,
39 static struct clk_branch gpucc_cxo_clk = {
43 .enable_mask = BIT(0),
44 .hw.init = &(struct clk_init_data){
45 .name = "gpucc_cxo_clk",
46 .parent_data = &(const struct clk_parent_data){
51 .ops = &clk_branch2_ops,
52 .flags = CLK_IS_CRITICAL,
57 static struct pll_vco gpu_vco[] = {
58 { 1000000000, 2000000000, 0 },
59 { 500000000, 1000000000, 2 },
60 { 250000000, 500000000, 3 },
63 static struct clk_alpha_pll gpu_pll0_pll_out_main = {
65 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
67 .num_vco = ARRAY_SIZE(gpu_vco),
68 .clkr.hw.init = &(struct clk_init_data){
69 .name = "gpu_pll0_pll_out_main",
70 .parent_data = &(const struct clk_parent_data){
71 .hw = &gpucc_cxo_clk.clkr.hw,
74 .ops = &clk_alpha_pll_ops,
78 static struct clk_alpha_pll gpu_pll1_pll_out_main = {
80 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
82 .num_vco = ARRAY_SIZE(gpu_vco),
83 .clkr.hw.init = &(struct clk_init_data){
84 .name = "gpu_pll1_pll_out_main",
85 .parent_data = &(const struct clk_parent_data){
86 .hw = &gpucc_cxo_clk.clkr.hw,
89 .ops = &clk_alpha_pll_ops,
93 static const struct parent_map gpucc_parent_map_1[] = {
95 { P_GPU_PLL0_PLL_OUT_MAIN, 1 },
96 { P_GPU_PLL1_PLL_OUT_MAIN, 3 },
97 { P_GPLL0_OUT_MAIN, 5 },
100 static const struct clk_parent_data gpucc_parent_data_1[] = {
101 { .hw = &gpucc_cxo_clk.clkr.hw },
102 { .hw = &gpu_pll0_pll_out_main.clkr.hw },
103 { .hw = &gpu_pll1_pll_out_main.clkr.hw },
104 { .fw_name = "gcc_gpu_gpll0_clk", .name = "gcc_gpu_gpll0_clk" },
107 static struct clk_rcg2_gfx3d gfx3d_clk_src = {
113 .parent_map = gpucc_parent_map_1,
114 .clkr.hw.init = &(struct clk_init_data){
115 .name = "gfx3d_clk_src",
116 .parent_data = gpucc_parent_data_1,
118 .ops = &clk_gfx3d_ops,
119 .flags = CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
122 .hws = (struct clk_hw*[]){
123 &gpucc_cxo_clk.clkr.hw,
124 &gpu_pll0_pll_out_main.clkr.hw,
125 &gpu_pll1_pll_out_main.clkr.hw,
129 static struct clk_branch gpucc_gfx3d_clk = {
131 .halt_check = BRANCH_HALT,
135 .enable_reg = 0x1098,
136 .enable_mask = BIT(0),
137 .hw.init = &(struct clk_init_data){
138 .name = "gpucc_gfx3d_clk",
139 .parent_data = &(const struct clk_parent_data){
140 .hw = &gfx3d_clk_src.rcg.clkr.hw,
143 .ops = &clk_branch2_ops,
144 .flags = CLK_SET_RATE_PARENT,
149 static const struct parent_map gpucc_parent_map_0[] = {
151 { P_GPLL0_OUT_MAIN, 5 },
152 { P_GPLL0_OUT_MAIN_DIV, 6 },
155 static const struct clk_parent_data gpucc_parent_data_0[] = {
156 { .hw = &gpucc_cxo_clk.clkr.hw },
157 { .fw_name = "gcc_gpu_gpll0_clk", .name = "gcc_gpu_gpll0_clk" },
158 { .fw_name = "gcc_gpu_gpll0_div_clk", .name = "gcc_gpu_gpll0_div_clk" },
161 static const struct freq_tbl ftbl_rbbmtimer_clk_src[] = {
162 F(19200000, P_GPU_XO, 1, 0, 0),
166 static struct clk_rcg2 rbbmtimer_clk_src = {
170 .parent_map = gpucc_parent_map_0,
171 .freq_tbl = ftbl_rbbmtimer_clk_src,
172 .clkr.hw.init = &(struct clk_init_data){
173 .name = "rbbmtimer_clk_src",
174 .parent_data = gpucc_parent_data_0,
176 .ops = &clk_rcg2_ops,
180 static const struct freq_tbl ftbl_rbcpr_clk_src[] = {
181 F(19200000, P_GPU_XO, 1, 0, 0),
182 F(50000000, P_GPLL0_OUT_MAIN_DIV, 6, 0, 0),
186 static struct clk_rcg2 rbcpr_clk_src = {
190 .parent_map = gpucc_parent_map_0,
191 .freq_tbl = ftbl_rbcpr_clk_src,
192 .clkr.hw.init = &(struct clk_init_data){
193 .name = "rbcpr_clk_src",
194 .parent_data = gpucc_parent_data_0,
196 .ops = &clk_rcg2_ops,
200 static struct clk_branch gpucc_rbbmtimer_clk = {
202 .halt_check = BRANCH_HALT,
204 .enable_reg = 0x10d0,
205 .enable_mask = BIT(0),
206 .hw.init = &(struct clk_init_data){
207 .name = "gpucc_rbbmtimer_clk",
208 .parent_names = (const char *[]){
212 .flags = CLK_SET_RATE_PARENT,
213 .ops = &clk_branch2_ops,
218 static struct clk_branch gpucc_rbcpr_clk = {
220 .halt_check = BRANCH_HALT,
222 .enable_reg = 0x1054,
223 .enable_mask = BIT(0),
224 .hw.init = &(struct clk_init_data){
225 .name = "gpucc_rbcpr_clk",
226 .parent_names = (const char *[]){
230 .flags = CLK_SET_RATE_PARENT,
231 .ops = &clk_branch2_ops,
236 static struct gdsc gpu_cx_gdsc = {
238 .gds_hw_ctrl = 0x1008,
242 .pwrsts = PWRSTS_OFF_ON,
246 static struct gdsc gpu_gx_gdsc = {
248 .clamp_io_ctrl = 0x130,
249 .resets = (unsigned int []){ GPU_GX_BCR },
251 .cxcs = (unsigned int []){ 0x1098 },
256 .parent = &gpu_cx_gdsc.pd,
257 .pwrsts = PWRSTS_OFF | PWRSTS_ON | PWRSTS_RET,
258 .flags = CLAMP_IO | SW_RESET | AON_RESET | NO_RET_PERIPH,
261 static struct gdsc *gpucc_sdm660_gdscs[] = {
262 [GPU_CX_GDSC] = &gpu_cx_gdsc,
263 [GPU_GX_GDSC] = &gpu_gx_gdsc,
266 static const struct qcom_reset_map gpucc_sdm660_resets[] = {
267 [GPU_CX_BCR] = { 0x1000 },
268 [RBCPR_BCR] = { 0x1050 },
269 [GPU_GX_BCR] = { 0x1090 },
270 [SPDM_BCR] = { 0x10E0 },
273 static struct clk_regmap *gpucc_sdm660_clocks[] = {
274 [GPUCC_CXO_CLK] = &gpucc_cxo_clk.clkr,
275 [GPU_PLL0_PLL] = &gpu_pll0_pll_out_main.clkr,
276 [GPU_PLL1_PLL] = &gpu_pll1_pll_out_main.clkr,
277 [GFX3D_CLK_SRC] = &gfx3d_clk_src.rcg.clkr,
278 [RBCPR_CLK_SRC] = &rbcpr_clk_src.clkr,
279 [RBBMTIMER_CLK_SRC] = &rbbmtimer_clk_src.clkr,
280 [GPUCC_RBCPR_CLK] = &gpucc_rbcpr_clk.clkr,
281 [GPUCC_GFX3D_CLK] = &gpucc_gfx3d_clk.clkr,
282 [GPUCC_RBBMTIMER_CLK] = &gpucc_rbbmtimer_clk.clkr,
285 static const struct regmap_config gpucc_660_regmap_config = {
289 .max_register = 0x9034,
293 static const struct qcom_cc_desc gpucc_sdm660_desc = {
294 .config = &gpucc_660_regmap_config,
295 .clks = gpucc_sdm660_clocks,
296 .num_clks = ARRAY_SIZE(gpucc_sdm660_clocks),
297 .resets = gpucc_sdm660_resets,
298 .num_resets = ARRAY_SIZE(gpucc_sdm660_resets),
299 .gdscs = gpucc_sdm660_gdscs,
300 .num_gdscs = ARRAY_SIZE(gpucc_sdm660_gdscs),
303 static const struct of_device_id gpucc_sdm660_match_table[] = {
304 { .compatible = "qcom,gpucc-sdm660" },
305 { .compatible = "qcom,gpucc-sdm630" },
308 MODULE_DEVICE_TABLE(of, gpucc_sdm660_match_table);
310 static int gpucc_sdm660_probe(struct platform_device *pdev)
312 struct regmap *regmap;
313 struct alpha_pll_config gpu_pll_config = {
314 .config_ctl_val = 0x4001055b,
316 .alpha_en_mask = BIT(24),
317 .vco_val = 0x2 << 20,
318 .vco_mask = 0x3 << 20,
319 .main_output_mask = 0x1,
322 regmap = qcom_cc_map(pdev, &gpucc_sdm660_desc);
324 return PTR_ERR(regmap);
326 /* 800MHz configuration for GPU PLL0 */
327 gpu_pll_config.l = 0x29;
328 gpu_pll_config.alpha_hi = 0xaa;
329 clk_alpha_pll_configure(&gpu_pll0_pll_out_main, regmap, &gpu_pll_config);
331 /* 740MHz configuration for GPU PLL1 */
332 gpu_pll_config.l = 0x26;
333 gpu_pll_config.alpha_hi = 0x8a;
334 clk_alpha_pll_configure(&gpu_pll1_pll_out_main, regmap, &gpu_pll_config);
336 return qcom_cc_really_probe(pdev, &gpucc_sdm660_desc, regmap);
339 static struct platform_driver gpucc_sdm660_driver = {
340 .probe = gpucc_sdm660_probe,
342 .name = "gpucc-sdm660",
343 .of_match_table = gpucc_sdm660_match_table,
346 module_platform_driver(gpucc_sdm660_driver);
348 MODULE_DESCRIPTION("Qualcomm SDM630/SDM660 GPUCC Driver");
349 MODULE_LICENSE("GPL v2");