18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2018, The Linux Foundation. All rights reserved. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include <linux/clk-provider.h> 78c2ecf20Sopenharmony_ci#include <linux/module.h> 88c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 98c2ecf20Sopenharmony_ci#include <linux/regmap.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <dt-bindings/clock/qcom,gpucc-sdm845.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include "common.h" 148c2ecf20Sopenharmony_ci#include "clk-alpha-pll.h" 158c2ecf20Sopenharmony_ci#include "clk-branch.h" 168c2ecf20Sopenharmony_ci#include "clk-pll.h" 178c2ecf20Sopenharmony_ci#include "clk-rcg.h" 188c2ecf20Sopenharmony_ci#include "clk-regmap.h" 198c2ecf20Sopenharmony_ci#include "gdsc.h" 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#define CX_GMU_CBCR_SLEEP_MASK 0xf 228c2ecf20Sopenharmony_ci#define CX_GMU_CBCR_SLEEP_SHIFT 4 238c2ecf20Sopenharmony_ci#define CX_GMU_CBCR_WAKE_MASK 0xf 248c2ecf20Sopenharmony_ci#define CX_GMU_CBCR_WAKE_SHIFT 8 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cienum { 278c2ecf20Sopenharmony_ci P_BI_TCXO, 288c2ecf20Sopenharmony_ci P_CORE_BI_PLL_TEST_SE, 298c2ecf20Sopenharmony_ci P_GPLL0_OUT_MAIN, 308c2ecf20Sopenharmony_ci P_GPLL0_OUT_MAIN_DIV, 318c2ecf20Sopenharmony_ci P_GPU_CC_PLL1_OUT_EVEN, 328c2ecf20Sopenharmony_ci P_GPU_CC_PLL1_OUT_MAIN, 338c2ecf20Sopenharmony_ci P_GPU_CC_PLL1_OUT_ODD, 348c2ecf20Sopenharmony_ci}; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cistatic const struct parent_map gpu_cc_parent_map_0[] = { 378c2ecf20Sopenharmony_ci { P_BI_TCXO, 0 }, 388c2ecf20Sopenharmony_ci { P_GPU_CC_PLL1_OUT_MAIN, 3 }, 398c2ecf20Sopenharmony_ci { P_GPLL0_OUT_MAIN, 5 }, 408c2ecf20Sopenharmony_ci { P_GPLL0_OUT_MAIN_DIV, 6 }, 418c2ecf20Sopenharmony_ci { P_CORE_BI_PLL_TEST_SE, 7 }, 428c2ecf20Sopenharmony_ci}; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic const char * const gpu_cc_parent_names_0[] = { 458c2ecf20Sopenharmony_ci "bi_tcxo", 468c2ecf20Sopenharmony_ci "gpu_cc_pll1", 478c2ecf20Sopenharmony_ci "gcc_gpu_gpll0_clk_src", 488c2ecf20Sopenharmony_ci "gcc_gpu_gpll0_div_clk_src", 498c2ecf20Sopenharmony_ci "core_bi_pll_test_se", 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic const struct alpha_pll_config gpu_cc_pll1_config = { 538c2ecf20Sopenharmony_ci .l = 0x1a, 548c2ecf20Sopenharmony_ci .alpha = 0xaab, 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cistatic struct clk_alpha_pll gpu_cc_pll1 = { 588c2ecf20Sopenharmony_ci .offset = 0x100, 598c2ecf20Sopenharmony_ci .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA], 608c2ecf20Sopenharmony_ci .clkr = { 618c2ecf20Sopenharmony_ci .hw.init = &(struct clk_init_data){ 628c2ecf20Sopenharmony_ci .name = "gpu_cc_pll1", 638c2ecf20Sopenharmony_ci .parent_names = (const char *[]){ "bi_tcxo" }, 648c2ecf20Sopenharmony_ci .num_parents = 1, 658c2ecf20Sopenharmony_ci .ops = &clk_alpha_pll_fabia_ops, 668c2ecf20Sopenharmony_ci }, 678c2ecf20Sopenharmony_ci }, 688c2ecf20Sopenharmony_ci}; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistatic const struct freq_tbl ftbl_gpu_cc_gmu_clk_src[] = { 718c2ecf20Sopenharmony_ci F(19200000, P_BI_TCXO, 1, 0, 0), 728c2ecf20Sopenharmony_ci F(200000000, P_GPLL0_OUT_MAIN_DIV, 1.5, 0, 0), 738c2ecf20Sopenharmony_ci F(500000000, P_GPU_CC_PLL1_OUT_MAIN, 1, 0, 0), 748c2ecf20Sopenharmony_ci { } 758c2ecf20Sopenharmony_ci}; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistatic struct clk_rcg2 gpu_cc_gmu_clk_src = { 788c2ecf20Sopenharmony_ci .cmd_rcgr = 0x1120, 798c2ecf20Sopenharmony_ci .mnd_width = 0, 808c2ecf20Sopenharmony_ci .hid_width = 5, 818c2ecf20Sopenharmony_ci .parent_map = gpu_cc_parent_map_0, 828c2ecf20Sopenharmony_ci .freq_tbl = ftbl_gpu_cc_gmu_clk_src, 838c2ecf20Sopenharmony_ci .clkr.hw.init = &(struct clk_init_data){ 848c2ecf20Sopenharmony_ci .name = "gpu_cc_gmu_clk_src", 858c2ecf20Sopenharmony_ci .parent_names = gpu_cc_parent_names_0, 868c2ecf20Sopenharmony_ci .num_parents = 5, 878c2ecf20Sopenharmony_ci .ops = &clk_rcg2_shared_ops, 888c2ecf20Sopenharmony_ci }, 898c2ecf20Sopenharmony_ci}; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistatic struct clk_branch gpu_cc_cx_gmu_clk = { 928c2ecf20Sopenharmony_ci .halt_reg = 0x1098, 938c2ecf20Sopenharmony_ci .halt_check = BRANCH_HALT, 948c2ecf20Sopenharmony_ci .clkr = { 958c2ecf20Sopenharmony_ci .enable_reg = 0x1098, 968c2ecf20Sopenharmony_ci .enable_mask = BIT(0), 978c2ecf20Sopenharmony_ci .hw.init = &(struct clk_init_data){ 988c2ecf20Sopenharmony_ci .name = "gpu_cc_cx_gmu_clk", 998c2ecf20Sopenharmony_ci .parent_names = (const char *[]){ 1008c2ecf20Sopenharmony_ci "gpu_cc_gmu_clk_src", 1018c2ecf20Sopenharmony_ci }, 1028c2ecf20Sopenharmony_ci .num_parents = 1, 1038c2ecf20Sopenharmony_ci .flags = CLK_SET_RATE_PARENT, 1048c2ecf20Sopenharmony_ci .ops = &clk_branch2_ops, 1058c2ecf20Sopenharmony_ci }, 1068c2ecf20Sopenharmony_ci }, 1078c2ecf20Sopenharmony_ci}; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistatic struct clk_branch gpu_cc_cxo_clk = { 1108c2ecf20Sopenharmony_ci .halt_reg = 0x109c, 1118c2ecf20Sopenharmony_ci .halt_check = BRANCH_HALT, 1128c2ecf20Sopenharmony_ci .clkr = { 1138c2ecf20Sopenharmony_ci .enable_reg = 0x109c, 1148c2ecf20Sopenharmony_ci .enable_mask = BIT(0), 1158c2ecf20Sopenharmony_ci .hw.init = &(struct clk_init_data){ 1168c2ecf20Sopenharmony_ci .name = "gpu_cc_cxo_clk", 1178c2ecf20Sopenharmony_ci .ops = &clk_branch2_ops, 1188c2ecf20Sopenharmony_ci }, 1198c2ecf20Sopenharmony_ci }, 1208c2ecf20Sopenharmony_ci}; 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_cistatic struct gdsc gpu_cx_gdsc = { 1238c2ecf20Sopenharmony_ci .gdscr = 0x106c, 1248c2ecf20Sopenharmony_ci .gds_hw_ctrl = 0x1540, 1258c2ecf20Sopenharmony_ci .clk_dis_wait_val = 0x8, 1268c2ecf20Sopenharmony_ci .pd = { 1278c2ecf20Sopenharmony_ci .name = "gpu_cx_gdsc", 1288c2ecf20Sopenharmony_ci }, 1298c2ecf20Sopenharmony_ci .pwrsts = PWRSTS_OFF_ON, 1308c2ecf20Sopenharmony_ci .flags = VOTABLE, 1318c2ecf20Sopenharmony_ci}; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_cistatic struct gdsc gpu_gx_gdsc = { 1348c2ecf20Sopenharmony_ci .gdscr = 0x100c, 1358c2ecf20Sopenharmony_ci .clamp_io_ctrl = 0x1508, 1368c2ecf20Sopenharmony_ci .pd = { 1378c2ecf20Sopenharmony_ci .name = "gpu_gx_gdsc", 1388c2ecf20Sopenharmony_ci .power_on = gdsc_gx_do_nothing_enable, 1398c2ecf20Sopenharmony_ci }, 1408c2ecf20Sopenharmony_ci .pwrsts = PWRSTS_OFF_ON, 1418c2ecf20Sopenharmony_ci .flags = CLAMP_IO | AON_RESET | POLL_CFG_GDSCR, 1428c2ecf20Sopenharmony_ci}; 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_cistatic struct clk_regmap *gpu_cc_sdm845_clocks[] = { 1458c2ecf20Sopenharmony_ci [GPU_CC_CXO_CLK] = &gpu_cc_cxo_clk.clkr, 1468c2ecf20Sopenharmony_ci [GPU_CC_CX_GMU_CLK] = &gpu_cc_cx_gmu_clk.clkr, 1478c2ecf20Sopenharmony_ci [GPU_CC_GMU_CLK_SRC] = &gpu_cc_gmu_clk_src.clkr, 1488c2ecf20Sopenharmony_ci [GPU_CC_PLL1] = &gpu_cc_pll1.clkr, 1498c2ecf20Sopenharmony_ci}; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_cistatic struct gdsc *gpu_cc_sdm845_gdscs[] = { 1528c2ecf20Sopenharmony_ci [GPU_CX_GDSC] = &gpu_cx_gdsc, 1538c2ecf20Sopenharmony_ci [GPU_GX_GDSC] = &gpu_gx_gdsc, 1548c2ecf20Sopenharmony_ci}; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_cistatic const struct regmap_config gpu_cc_sdm845_regmap_config = { 1578c2ecf20Sopenharmony_ci .reg_bits = 32, 1588c2ecf20Sopenharmony_ci .reg_stride = 4, 1598c2ecf20Sopenharmony_ci .val_bits = 32, 1608c2ecf20Sopenharmony_ci .max_register = 0x8008, 1618c2ecf20Sopenharmony_ci .fast_io = true, 1628c2ecf20Sopenharmony_ci}; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_cistatic const struct qcom_cc_desc gpu_cc_sdm845_desc = { 1658c2ecf20Sopenharmony_ci .config = &gpu_cc_sdm845_regmap_config, 1668c2ecf20Sopenharmony_ci .clks = gpu_cc_sdm845_clocks, 1678c2ecf20Sopenharmony_ci .num_clks = ARRAY_SIZE(gpu_cc_sdm845_clocks), 1688c2ecf20Sopenharmony_ci .gdscs = gpu_cc_sdm845_gdscs, 1698c2ecf20Sopenharmony_ci .num_gdscs = ARRAY_SIZE(gpu_cc_sdm845_gdscs), 1708c2ecf20Sopenharmony_ci}; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_cistatic const struct of_device_id gpu_cc_sdm845_match_table[] = { 1738c2ecf20Sopenharmony_ci { .compatible = "qcom,sdm845-gpucc" }, 1748c2ecf20Sopenharmony_ci { } 1758c2ecf20Sopenharmony_ci}; 1768c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, gpu_cc_sdm845_match_table); 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_cistatic int gpu_cc_sdm845_probe(struct platform_device *pdev) 1798c2ecf20Sopenharmony_ci{ 1808c2ecf20Sopenharmony_ci struct regmap *regmap; 1818c2ecf20Sopenharmony_ci unsigned int value, mask; 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci regmap = qcom_cc_map(pdev, &gpu_cc_sdm845_desc); 1848c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) 1858c2ecf20Sopenharmony_ci return PTR_ERR(regmap); 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci clk_fabia_pll_configure(&gpu_cc_pll1, regmap, &gpu_cc_pll1_config); 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci /* 1908c2ecf20Sopenharmony_ci * Configure gpu_cc_cx_gmu_clk with recommended 1918c2ecf20Sopenharmony_ci * wakeup/sleep settings 1928c2ecf20Sopenharmony_ci */ 1938c2ecf20Sopenharmony_ci mask = CX_GMU_CBCR_WAKE_MASK << CX_GMU_CBCR_WAKE_SHIFT; 1948c2ecf20Sopenharmony_ci mask |= CX_GMU_CBCR_SLEEP_MASK << CX_GMU_CBCR_SLEEP_SHIFT; 1958c2ecf20Sopenharmony_ci value = 0xf << CX_GMU_CBCR_WAKE_SHIFT | 0xf << CX_GMU_CBCR_SLEEP_SHIFT; 1968c2ecf20Sopenharmony_ci regmap_update_bits(regmap, 0x1098, mask, value); 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci return qcom_cc_really_probe(pdev, &gpu_cc_sdm845_desc, regmap); 1998c2ecf20Sopenharmony_ci} 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_cistatic struct platform_driver gpu_cc_sdm845_driver = { 2028c2ecf20Sopenharmony_ci .probe = gpu_cc_sdm845_probe, 2038c2ecf20Sopenharmony_ci .driver = { 2048c2ecf20Sopenharmony_ci .name = "sdm845-gpucc", 2058c2ecf20Sopenharmony_ci .of_match_table = gpu_cc_sdm845_match_table, 2068c2ecf20Sopenharmony_ci }, 2078c2ecf20Sopenharmony_ci}; 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_cistatic int __init gpu_cc_sdm845_init(void) 2108c2ecf20Sopenharmony_ci{ 2118c2ecf20Sopenharmony_ci return platform_driver_register(&gpu_cc_sdm845_driver); 2128c2ecf20Sopenharmony_ci} 2138c2ecf20Sopenharmony_cisubsys_initcall(gpu_cc_sdm845_init); 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_cistatic void __exit gpu_cc_sdm845_exit(void) 2168c2ecf20Sopenharmony_ci{ 2178c2ecf20Sopenharmony_ci platform_driver_unregister(&gpu_cc_sdm845_driver); 2188c2ecf20Sopenharmony_ci} 2198c2ecf20Sopenharmony_cimodule_exit(gpu_cc_sdm845_exit); 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("QTI GPUCC SDM845 Driver"); 2228c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 223