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"
34 P_GPU_PLL0_PLL_OUT_MAIN,
35 P_GPU_PLL1_PLL_OUT_MAIN,
38 static struct clk_branch gpucc_cxo_clk = {
42 .enable_mask = BIT(0),
43 .hw.init = &(struct clk_init_data){
44 .name = "gpucc_cxo_clk",
45 .parent_data = &(const struct clk_parent_data){
49 .ops = &clk_branch2_ops,
50 .flags = CLK_IS_CRITICAL,
55 static struct pll_vco gpu_vco[] = {
56 { 1000000000, 2000000000, 0 },
57 { 500000000, 1000000000, 2 },
58 { 250000000, 500000000, 3 },
61 static struct clk_alpha_pll gpu_pll0_pll_out_main = {
63 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
65 .num_vco = ARRAY_SIZE(gpu_vco),
66 .clkr.hw.init = &(struct clk_init_data){
67 .name = "gpu_pll0_pll_out_main",
68 .parent_hws = (const struct clk_hw*[]){
69 &gpucc_cxo_clk.clkr.hw,
72 .ops = &clk_alpha_pll_ops,
76 static struct clk_alpha_pll gpu_pll1_pll_out_main = {
78 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
80 .num_vco = ARRAY_SIZE(gpu_vco),
81 .clkr.hw.init = &(struct clk_init_data){
82 .name = "gpu_pll1_pll_out_main",
83 .parent_hws = (const struct clk_hw*[]){
84 &gpucc_cxo_clk.clkr.hw,
87 .ops = &clk_alpha_pll_ops,
91 static const struct parent_map gpucc_parent_map_1[] = {
93 { P_GPU_PLL0_PLL_OUT_MAIN, 1 },
94 { P_GPU_PLL1_PLL_OUT_MAIN, 3 },
95 { P_GPLL0_OUT_MAIN, 5 },
98 static const struct clk_parent_data gpucc_parent_data_1[] = {
99 { .hw = &gpucc_cxo_clk.clkr.hw },
100 { .hw = &gpu_pll0_pll_out_main.clkr.hw },
101 { .hw = &gpu_pll1_pll_out_main.clkr.hw },
102 { .fw_name = "gcc_gpu_gpll0_clk" },
105 static struct clk_rcg2_gfx3d gfx3d_clk_src = {
111 .parent_map = gpucc_parent_map_1,
112 .clkr.hw.init = &(struct clk_init_data){
113 .name = "gfx3d_clk_src",
114 .parent_data = gpucc_parent_data_1,
115 .num_parents = ARRAY_SIZE(gpucc_parent_data_1),
116 .ops = &clk_gfx3d_ops,
117 .flags = CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
120 .hws = (struct clk_hw*[]){
121 &gpucc_cxo_clk.clkr.hw,
122 &gpu_pll0_pll_out_main.clkr.hw,
123 &gpu_pll1_pll_out_main.clkr.hw,
127 static struct clk_branch gpucc_gfx3d_clk = {
129 .halt_check = BRANCH_HALT,
133 .enable_reg = 0x1098,
134 .enable_mask = BIT(0),
135 .hw.init = &(struct clk_init_data){
136 .name = "gpucc_gfx3d_clk",
137 .parent_hws = (const struct clk_hw*[]){
138 &gfx3d_clk_src.rcg.clkr.hw,
141 .ops = &clk_branch2_ops,
142 .flags = CLK_SET_RATE_PARENT,
147 static const struct parent_map gpucc_parent_map_0[] = {
149 { P_GPLL0_OUT_MAIN, 5 },
150 { P_GPLL0_OUT_MAIN_DIV, 6 },
153 static const struct clk_parent_data gpucc_parent_data_0[] = {
154 { .hw = &gpucc_cxo_clk.clkr.hw },
155 { .fw_name = "gcc_gpu_gpll0_clk" },
156 { .fw_name = "gcc_gpu_gpll0_div_clk" },
159 static const struct freq_tbl ftbl_rbbmtimer_clk_src[] = {
160 F(19200000, P_GPU_XO, 1, 0, 0),
164 static struct clk_rcg2 rbbmtimer_clk_src = {
168 .parent_map = gpucc_parent_map_0,
169 .freq_tbl = ftbl_rbbmtimer_clk_src,
170 .clkr.hw.init = &(struct clk_init_data){
171 .name = "rbbmtimer_clk_src",
172 .parent_data = gpucc_parent_data_0,
173 .num_parents = ARRAY_SIZE(gpucc_parent_data_0),
174 .ops = &clk_rcg2_ops,
178 static const struct freq_tbl ftbl_rbcpr_clk_src[] = {
179 F(19200000, P_GPU_XO, 1, 0, 0),
180 F(50000000, P_GPLL0_OUT_MAIN_DIV, 6, 0, 0),
184 static struct clk_rcg2 rbcpr_clk_src = {
188 .parent_map = gpucc_parent_map_0,
189 .freq_tbl = ftbl_rbcpr_clk_src,
190 .clkr.hw.init = &(struct clk_init_data){
191 .name = "rbcpr_clk_src",
192 .parent_data = gpucc_parent_data_0,
193 .num_parents = ARRAY_SIZE(gpucc_parent_data_0),
194 .ops = &clk_rcg2_ops,
198 static struct clk_branch gpucc_rbbmtimer_clk = {
200 .halt_check = BRANCH_HALT,
202 .enable_reg = 0x10d0,
203 .enable_mask = BIT(0),
204 .hw.init = &(struct clk_init_data){
205 .name = "gpucc_rbbmtimer_clk",
206 .parent_hws = (const struct clk_hw*[]){
207 &rbbmtimer_clk_src.clkr.hw,
210 .flags = CLK_SET_RATE_PARENT,
211 .ops = &clk_branch2_ops,
216 static struct clk_branch gpucc_rbcpr_clk = {
218 .halt_check = BRANCH_HALT,
220 .enable_reg = 0x1054,
221 .enable_mask = BIT(0),
222 .hw.init = &(struct clk_init_data){
223 .name = "gpucc_rbcpr_clk",
224 .parent_hws = (const struct clk_hw*[]){
225 &rbcpr_clk_src.clkr.hw,
228 .flags = CLK_SET_RATE_PARENT,
229 .ops = &clk_branch2_ops,
234 static struct gdsc gpu_cx_gdsc = {
236 .gds_hw_ctrl = 0x1008,
240 .pwrsts = PWRSTS_OFF_ON,
244 static struct gdsc gpu_gx_gdsc = {
246 .clamp_io_ctrl = 0x130,
247 .resets = (unsigned int []){ GPU_GX_BCR },
249 .cxcs = (unsigned int []){ 0x1098 },
254 .parent = &gpu_cx_gdsc.pd,
255 .pwrsts = PWRSTS_OFF | PWRSTS_ON | PWRSTS_RET,
256 .flags = CLAMP_IO | SW_RESET | AON_RESET | NO_RET_PERIPH,
259 static struct gdsc *gpucc_sdm660_gdscs[] = {
260 [GPU_CX_GDSC] = &gpu_cx_gdsc,
261 [GPU_GX_GDSC] = &gpu_gx_gdsc,
264 static const struct qcom_reset_map gpucc_sdm660_resets[] = {
265 [GPU_CX_BCR] = { 0x1000 },
266 [RBCPR_BCR] = { 0x1050 },
267 [GPU_GX_BCR] = { 0x1090 },
268 [SPDM_BCR] = { 0x10E0 },
271 static struct clk_regmap *gpucc_sdm660_clocks[] = {
272 [GPUCC_CXO_CLK] = &gpucc_cxo_clk.clkr,
273 [GPU_PLL0_PLL] = &gpu_pll0_pll_out_main.clkr,
274 [GPU_PLL1_PLL] = &gpu_pll1_pll_out_main.clkr,
275 [GFX3D_CLK_SRC] = &gfx3d_clk_src.rcg.clkr,
276 [RBCPR_CLK_SRC] = &rbcpr_clk_src.clkr,
277 [RBBMTIMER_CLK_SRC] = &rbbmtimer_clk_src.clkr,
278 [GPUCC_RBCPR_CLK] = &gpucc_rbcpr_clk.clkr,
279 [GPUCC_GFX3D_CLK] = &gpucc_gfx3d_clk.clkr,
280 [GPUCC_RBBMTIMER_CLK] = &gpucc_rbbmtimer_clk.clkr,
283 static const struct regmap_config gpucc_660_regmap_config = {
287 .max_register = 0x9034,
291 static const struct qcom_cc_desc gpucc_sdm660_desc = {
292 .config = &gpucc_660_regmap_config,
293 .clks = gpucc_sdm660_clocks,
294 .num_clks = ARRAY_SIZE(gpucc_sdm660_clocks),
295 .resets = gpucc_sdm660_resets,
296 .num_resets = ARRAY_SIZE(gpucc_sdm660_resets),
297 .gdscs = gpucc_sdm660_gdscs,
298 .num_gdscs = ARRAY_SIZE(gpucc_sdm660_gdscs),
301 static const struct of_device_id gpucc_sdm660_match_table[] = {
302 { .compatible = "qcom,gpucc-sdm660" },
303 { .compatible = "qcom,gpucc-sdm630" },
306 MODULE_DEVICE_TABLE(of, gpucc_sdm660_match_table);
308 static int gpucc_sdm660_probe(struct platform_device *pdev)
310 struct regmap *regmap;
311 struct alpha_pll_config gpu_pll_config = {
312 .config_ctl_val = 0x4001055b,
314 .alpha_en_mask = BIT(24),
315 .vco_val = 0x2 << 20,
316 .vco_mask = 0x3 << 20,
317 .main_output_mask = 0x1,
320 regmap = qcom_cc_map(pdev, &gpucc_sdm660_desc);
322 return PTR_ERR(regmap);
324 /* 800MHz configuration for GPU PLL0 */
325 gpu_pll_config.l = 0x29;
326 gpu_pll_config.alpha_hi = 0xaa;
327 clk_alpha_pll_configure(&gpu_pll0_pll_out_main, regmap, &gpu_pll_config);
329 /* 740MHz configuration for GPU PLL1 */
330 gpu_pll_config.l = 0x26;
331 gpu_pll_config.alpha_hi = 0x8a;
332 clk_alpha_pll_configure(&gpu_pll1_pll_out_main, regmap, &gpu_pll_config);
334 return qcom_cc_really_probe(pdev, &gpucc_sdm660_desc, regmap);
337 static struct platform_driver gpucc_sdm660_driver = {
338 .probe = gpucc_sdm660_probe,
340 .name = "gpucc-sdm660",
341 .of_match_table = gpucc_sdm660_match_table,
344 module_platform_driver(gpucc_sdm660_driver);
346 MODULE_DESCRIPTION("Qualcomm SDM630/SDM660 GPUCC Driver");
347 MODULE_LICENSE("GPL v2");