1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2019, Jeffrey Hugo
6 #include <linux/kernel.h>
7 #include <linux/bitops.h>
9 #include <linux/platform_device.h>
10 #include <linux/module.h>
12 #include <linux/of_device.h>
13 #include <linux/clk-provider.h>
14 #include <linux/regmap.h>
15 #include <linux/reset-controller.h>
17 #include <dt-bindings/clock/qcom,gpucc-msm8998.h>
20 #include "clk-regmap.h"
21 #include "clk-regmap-divider.h"
22 #include "clk-alpha-pll.h"
24 #include "clk-branch.h"
34 /* Instead of going directly to the block, XO is routed through this branch */
35 static struct clk_branch gpucc_cxo_clk = {
39 .enable_mask = BIT(0),
40 .hw.init = &(struct clk_init_data){
41 .name = "gpucc_cxo_clk",
42 .parent_data = &(const struct clk_parent_data){
46 .ops = &clk_branch2_ops,
47 .flags = CLK_IS_CRITICAL,
52 static struct pll_vco fabia_vco[] = {
53 { 249600000, 2000000000, 0 },
54 { 125000000, 1000000000, 1 },
57 static const struct clk_div_table post_div_table_fabia_even[] = {
65 static struct clk_alpha_pll gpupll0 = {
67 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA],
68 .vco_table = fabia_vco,
69 .num_vco = ARRAY_SIZE(fabia_vco),
70 .clkr.hw.init = &(struct clk_init_data){
72 .parent_hws = (const struct clk_hw *[]){ &gpucc_cxo_clk.clkr.hw },
74 .ops = &clk_alpha_pll_fabia_ops,
78 static struct clk_alpha_pll_postdiv gpupll0_out_even = {
81 .post_div_table = post_div_table_fabia_even,
82 .num_post_div = ARRAY_SIZE(post_div_table_fabia_even),
84 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA],
85 .clkr.hw.init = &(struct clk_init_data){
86 .name = "gpupll0_out_even",
87 .parent_hws = (const struct clk_hw *[]){ &gpupll0.clkr.hw },
89 .flags = CLK_SET_RATE_PARENT,
90 .ops = &clk_alpha_pll_postdiv_fabia_ops,
94 static const struct parent_map gpu_xo_gpll0_map[] = {
99 static const struct clk_parent_data gpu_xo_gpll0[] = {
100 { .hw = &gpucc_cxo_clk.clkr.hw },
101 { .fw_name = "gpll0" },
104 static const struct parent_map gpu_xo_gpupll0_map[] = {
106 { P_GPUPLL0_OUT_EVEN, 1 },
109 static const struct clk_parent_data gpu_xo_gpupll0[] = {
110 { .hw = &gpucc_cxo_clk.clkr.hw },
111 { .hw = &gpupll0_out_even.clkr.hw },
114 static const struct freq_tbl ftbl_rbcpr_clk_src[] = {
115 F(19200000, P_XO, 1, 0, 0),
116 F(50000000, P_GPLL0, 12, 0, 0),
120 static struct clk_rcg2 rbcpr_clk_src = {
123 .parent_map = gpu_xo_gpll0_map,
124 .freq_tbl = ftbl_rbcpr_clk_src,
125 .clkr.hw.init = &(struct clk_init_data){
126 .name = "rbcpr_clk_src",
127 .parent_data = gpu_xo_gpll0,
128 .num_parents = ARRAY_SIZE(gpu_xo_gpll0),
129 .ops = &clk_rcg2_ops,
133 static const struct freq_tbl ftbl_gfx3d_clk_src[] = {
134 { .src = P_GPUPLL0_OUT_EVEN, .pre_div = 3 },
138 static struct clk_rcg2 gfx3d_clk_src = {
141 .parent_map = gpu_xo_gpupll0_map,
142 .freq_tbl = ftbl_gfx3d_clk_src,
143 .clkr.hw.init = &(struct clk_init_data){
144 .name = "gfx3d_clk_src",
145 .parent_data = gpu_xo_gpupll0,
146 .num_parents = ARRAY_SIZE(gpu_xo_gpupll0),
147 .ops = &clk_rcg2_ops,
148 .flags = CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
152 static const struct freq_tbl ftbl_rbbmtimer_clk_src[] = {
153 F(19200000, P_XO, 1, 0, 0),
157 static struct clk_rcg2 rbbmtimer_clk_src = {
160 .parent_map = gpu_xo_gpll0_map,
161 .freq_tbl = ftbl_rbbmtimer_clk_src,
162 .clkr.hw.init = &(struct clk_init_data){
163 .name = "rbbmtimer_clk_src",
164 .parent_data = gpu_xo_gpll0,
165 .num_parents = ARRAY_SIZE(gpu_xo_gpll0),
166 .ops = &clk_rcg2_ops,
170 static const struct freq_tbl ftbl_gfx3d_isense_clk_src[] = {
171 F(19200000, P_XO, 1, 0, 0),
172 F(40000000, P_GPLL0, 15, 0, 0),
173 F(200000000, P_GPLL0, 3, 0, 0),
174 F(300000000, P_GPLL0, 2, 0, 0),
178 static struct clk_rcg2 gfx3d_isense_clk_src = {
181 .parent_map = gpu_xo_gpll0_map,
182 .freq_tbl = ftbl_gfx3d_isense_clk_src,
183 .clkr.hw.init = &(struct clk_init_data){
184 .name = "gfx3d_isense_clk_src",
185 .parent_data = gpu_xo_gpll0,
186 .num_parents = ARRAY_SIZE(gpu_xo_gpll0),
187 .ops = &clk_rcg2_ops,
191 static struct clk_branch rbcpr_clk = {
194 .enable_reg = 0x1054,
195 .enable_mask = BIT(0),
196 .hw.init = &(struct clk_init_data){
198 .parent_hws = (const struct clk_hw *[]){ &rbcpr_clk_src.clkr.hw },
200 .ops = &clk_branch2_ops,
201 .flags = CLK_SET_RATE_PARENT,
206 static struct clk_branch gfx3d_clk = {
209 .enable_reg = 0x1098,
210 .enable_mask = BIT(0),
211 .hw.init = &(struct clk_init_data){
213 .parent_hws = (const struct clk_hw *[]){ &gfx3d_clk_src.clkr.hw },
215 .ops = &clk_branch2_ops,
216 .flags = CLK_SET_RATE_PARENT,
221 static struct clk_branch rbbmtimer_clk = {
224 .enable_reg = 0x10d0,
225 .enable_mask = BIT(0),
226 .hw.init = &(struct clk_init_data){
227 .name = "rbbmtimer_clk",
228 .parent_hws = (const struct clk_hw *[]){ &rbbmtimer_clk_src.clkr.hw },
230 .ops = &clk_branch2_ops,
231 .flags = CLK_SET_RATE_PARENT,
236 static struct clk_branch gfx3d_isense_clk = {
239 .enable_reg = 0x1124,
240 .enable_mask = BIT(0),
241 .hw.init = &(struct clk_init_data){
242 .name = "gfx3d_isense_clk",
243 .parent_hws = (const struct clk_hw *[]){ &gfx3d_isense_clk_src.clkr.hw },
245 .ops = &clk_branch2_ops,
250 static struct gdsc gpu_cx_gdsc = {
252 .gds_hw_ctrl = 0x1008,
256 .pwrsts = PWRSTS_OFF_ON,
260 static struct gdsc gpu_gx_gdsc = {
262 .clamp_io_ctrl = 0x130,
263 .resets = (unsigned int []){ GPU_GX_BCR },
265 .cxcs = (unsigned int []){ 0x1098 },
270 .parent = &gpu_cx_gdsc.pd,
271 .pwrsts = PWRSTS_OFF_ON | PWRSTS_RET,
272 .flags = CLAMP_IO | SW_RESET | AON_RESET | NO_RET_PERIPH,
275 static struct clk_regmap *gpucc_msm8998_clocks[] = {
276 [GPUPLL0] = &gpupll0.clkr,
277 [GPUPLL0_OUT_EVEN] = &gpupll0_out_even.clkr,
278 [RBCPR_CLK_SRC] = &rbcpr_clk_src.clkr,
279 [GFX3D_CLK_SRC] = &gfx3d_clk_src.clkr,
280 [RBBMTIMER_CLK_SRC] = &rbbmtimer_clk_src.clkr,
281 [GFX3D_ISENSE_CLK_SRC] = &gfx3d_isense_clk_src.clkr,
282 [RBCPR_CLK] = &rbcpr_clk.clkr,
283 [GFX3D_CLK] = &gfx3d_clk.clkr,
284 [RBBMTIMER_CLK] = &rbbmtimer_clk.clkr,
285 [GFX3D_ISENSE_CLK] = &gfx3d_isense_clk.clkr,
286 [GPUCC_CXO_CLK] = &gpucc_cxo_clk.clkr,
289 static struct gdsc *gpucc_msm8998_gdscs[] = {
290 [GPU_CX_GDSC] = &gpu_cx_gdsc,
291 [GPU_GX_GDSC] = &gpu_gx_gdsc,
294 static const struct qcom_reset_map gpucc_msm8998_resets[] = {
295 [GPU_CX_BCR] = { 0x1000 },
296 [RBCPR_BCR] = { 0x1050 },
297 [GPU_GX_BCR] = { 0x1090 },
298 [GPU_ISENSE_BCR] = { 0x1120 },
301 static const struct regmap_config gpucc_msm8998_regmap_config = {
305 .max_register = 0x9000,
309 static const struct qcom_cc_desc gpucc_msm8998_desc = {
310 .config = &gpucc_msm8998_regmap_config,
311 .clks = gpucc_msm8998_clocks,
312 .num_clks = ARRAY_SIZE(gpucc_msm8998_clocks),
313 .resets = gpucc_msm8998_resets,
314 .num_resets = ARRAY_SIZE(gpucc_msm8998_resets),
315 .gdscs = gpucc_msm8998_gdscs,
316 .num_gdscs = ARRAY_SIZE(gpucc_msm8998_gdscs),
319 static const struct of_device_id gpucc_msm8998_match_table[] = {
320 { .compatible = "qcom,msm8998-gpucc" },
323 MODULE_DEVICE_TABLE(of, gpucc_msm8998_match_table);
325 static int gpucc_msm8998_probe(struct platform_device *pdev)
327 struct regmap *regmap;
329 regmap = qcom_cc_map(pdev, &gpucc_msm8998_desc);
331 return PTR_ERR(regmap);
333 /* force periph logic on to avoid perf counter corruption */
334 regmap_write_bits(regmap, gfx3d_clk.clkr.enable_reg, BIT(13), BIT(13));
335 /* tweak droop detector (GPUCC_GPU_DD_WRAP_CTRL) to reduce leakage */
336 regmap_write_bits(regmap, gfx3d_clk.clkr.enable_reg, BIT(0), BIT(0));
338 return qcom_cc_really_probe(pdev, &gpucc_msm8998_desc, regmap);
341 static struct platform_driver gpucc_msm8998_driver = {
342 .probe = gpucc_msm8998_probe,
344 .name = "gpucc-msm8998",
345 .of_match_table = gpucc_msm8998_match_table,
348 module_platform_driver(gpucc_msm8998_driver);
350 MODULE_DESCRIPTION("QCOM GPUCC MSM8998 Driver");
351 MODULE_LICENSE("GPL v2");