1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
6 #include <linux/clk-provider.h>
7 #include <linux/module.h>
8 #include <linux/platform_device.h>
9 #include <linux/regmap.h>
11 #include <dt-bindings/clock/qcom,gpucc-sdm845.h>
14 #include "clk-alpha-pll.h"
15 #include "clk-branch.h"
18 #include "clk-regmap.h"
21 #define CX_GMU_CBCR_SLEEP_MASK 0xf
22 #define CX_GMU_CBCR_SLEEP_SHIFT 4
23 #define CX_GMU_CBCR_WAKE_MASK 0xf
24 #define CX_GMU_CBCR_WAKE_SHIFT 8
28 P_CORE_BI_PLL_TEST_SE,
31 P_GPU_CC_PLL1_OUT_EVEN,
32 P_GPU_CC_PLL1_OUT_MAIN,
33 P_GPU_CC_PLL1_OUT_ODD,
36 static const struct parent_map gpu_cc_parent_map_0[] = {
38 { P_GPU_CC_PLL1_OUT_MAIN, 3 },
39 { P_GPLL0_OUT_MAIN, 5 },
40 { P_GPLL0_OUT_MAIN_DIV, 6 },
41 { P_CORE_BI_PLL_TEST_SE, 7 },
44 static const char * const gpu_cc_parent_names_0[] = {
47 "gcc_gpu_gpll0_clk_src",
48 "gcc_gpu_gpll0_div_clk_src",
49 "core_bi_pll_test_se",
52 static const struct alpha_pll_config gpu_cc_pll1_config = {
57 static struct clk_alpha_pll gpu_cc_pll1 = {
59 .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA],
61 .hw.init = &(struct clk_init_data){
62 .name = "gpu_cc_pll1",
63 .parent_names = (const char *[]){ "bi_tcxo" },
65 .ops = &clk_alpha_pll_fabia_ops,
70 static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src[] = {
71 F(19200000, P_BI_TCXO, 1, 0, 0),
72 F(200000000, P_GPLL0_OUT_MAIN_DIV, 1.5, 0, 0),
73 F(500000000, P_GPU_CC_PLL1_OUT_MAIN, 1, 0, 0),
77 static struct clk_rcg2 gpu_cc_gmu_clk_src = {
81 .parent_map = gpu_cc_parent_map_0,
82 .freq_tbl = ftbl_gpu_cc_gmu_clk_src,
83 .clkr.hw.init = &(struct clk_init_data){
84 .name = "gpu_cc_gmu_clk_src",
85 .parent_names = gpu_cc_parent_names_0,
87 .ops = &clk_rcg2_shared_ops,
91 static struct clk_branch gpu_cc_cx_gmu_clk = {
93 .halt_check = BRANCH_HALT,
96 .enable_mask = BIT(0),
97 .hw.init = &(struct clk_init_data){
98 .name = "gpu_cc_cx_gmu_clk",
99 .parent_names = (const char *[]){
100 "gpu_cc_gmu_clk_src",
103 .flags = CLK_SET_RATE_PARENT,
104 .ops = &clk_branch2_ops,
109 static struct clk_branch gpu_cc_cxo_clk = {
111 .halt_check = BRANCH_HALT,
113 .enable_reg = 0x109c,
114 .enable_mask = BIT(0),
115 .hw.init = &(struct clk_init_data){
116 .name = "gpu_cc_cxo_clk",
117 .ops = &clk_branch2_ops,
122 static struct gdsc gpu_cx_gdsc = {
124 .gds_hw_ctrl = 0x1540,
125 .clk_dis_wait_val = 0x8,
127 .name = "gpu_cx_gdsc",
129 .pwrsts = PWRSTS_OFF_ON,
133 static struct gdsc gpu_gx_gdsc = {
135 .clamp_io_ctrl = 0x1508,
137 .name = "gpu_gx_gdsc",
138 .power_on = gdsc_gx_do_nothing_enable,
140 .pwrsts = PWRSTS_OFF_ON,
141 .flags = CLAMP_IO | AON_RESET | POLL_CFG_GDSCR,
144 static struct clk_regmap *gpu_cc_sdm845_clocks[] = {
145 [GPU_CC_CXO_CLK] = &gpu_cc_cxo_clk.clkr,
146 [GPU_CC_CX_GMU_CLK] = &gpu_cc_cx_gmu_clk.clkr,
147 [GPU_CC_GMU_CLK_SRC] = &gpu_cc_gmu_clk_src.clkr,
148 [GPU_CC_PLL1] = &gpu_cc_pll1.clkr,
151 static struct gdsc *gpu_cc_sdm845_gdscs[] = {
152 [GPU_CX_GDSC] = &gpu_cx_gdsc,
153 [GPU_GX_GDSC] = &gpu_gx_gdsc,
156 static const struct regmap_config gpu_cc_sdm845_regmap_config = {
160 .max_register = 0x8008,
164 static const struct qcom_cc_desc gpu_cc_sdm845_desc = {
165 .config = &gpu_cc_sdm845_regmap_config,
166 .clks = gpu_cc_sdm845_clocks,
167 .num_clks = ARRAY_SIZE(gpu_cc_sdm845_clocks),
168 .gdscs = gpu_cc_sdm845_gdscs,
169 .num_gdscs = ARRAY_SIZE(gpu_cc_sdm845_gdscs),
172 static const struct of_device_id gpu_cc_sdm845_match_table[] = {
173 { .compatible = "qcom,sdm845-gpucc" },
176 MODULE_DEVICE_TABLE(of, gpu_cc_sdm845_match_table);
178 static int gpu_cc_sdm845_probe(struct platform_device *pdev)
180 struct regmap *regmap;
181 unsigned int value, mask;
183 regmap = qcom_cc_map(pdev, &gpu_cc_sdm845_desc);
185 return PTR_ERR(regmap);
187 clk_fabia_pll_configure(&gpu_cc_pll1, regmap, &gpu_cc_pll1_config);
190 * Configure gpu_cc_cx_gmu_clk with recommended
191 * wakeup/sleep settings
193 mask = CX_GMU_CBCR_WAKE_MASK << CX_GMU_CBCR_WAKE_SHIFT;
194 mask |= CX_GMU_CBCR_SLEEP_MASK << CX_GMU_CBCR_SLEEP_SHIFT;
195 value = 0xf << CX_GMU_CBCR_WAKE_SHIFT | 0xf << CX_GMU_CBCR_SLEEP_SHIFT;
196 regmap_update_bits(regmap, 0x1098, mask, value);
198 return qcom_cc_really_probe(pdev, &gpu_cc_sdm845_desc, regmap);
201 static struct platform_driver gpu_cc_sdm845_driver = {
202 .probe = gpu_cc_sdm845_probe,
204 .name = "sdm845-gpucc",
205 .of_match_table = gpu_cc_sdm845_match_table,
209 static int __init gpu_cc_sdm845_init(void)
211 return platform_driver_register(&gpu_cc_sdm845_driver);
213 subsys_initcall(gpu_cc_sdm845_init);
215 static void __exit gpu_cc_sdm845_exit(void)
217 platform_driver_unregister(&gpu_cc_sdm845_driver);
219 module_exit(gpu_cc_sdm845_exit);
221 MODULE_DESCRIPTION("QTI GPUCC SDM845 Driver");
222 MODULE_LICENSE("GPL v2");