gpucc-sm8150.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/clk-provider.h>
  6. #include <linux/module.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/regmap.h>
  9. #include <dt-bindings/clock/qcom,gpucc-sm8150.h>
  10. #include "common.h"
  11. #include "clk-alpha-pll.h"
  12. #include "clk-branch.h"
  13. #include "clk-pll.h"
  14. #include "clk-rcg.h"
  15. #include "clk-regmap.h"
  16. #include "reset.h"
  17. #include "gdsc.h"
  18. enum {
  19. P_BI_TCXO,
  20. P_GPLL0_OUT_MAIN,
  21. P_GPLL0_OUT_MAIN_DIV,
  22. P_GPU_CC_PLL1_OUT_MAIN,
  23. };
  24. static const struct pll_vco trion_vco[] = {
  25. { 249600000, 2000000000, 0 },
  26. };
  27. static struct alpha_pll_config gpu_cc_pll1_config = {
  28. .l = 0x1a,
  29. .alpha = 0xaaa,
  30. .config_ctl_val = 0x20485699,
  31. .config_ctl_hi_val = 0x00002267,
  32. .config_ctl_hi1_val = 0x00000024,
  33. .test_ctl_val = 0x00000000,
  34. .test_ctl_hi_val = 0x00000000,
  35. .test_ctl_hi1_val = 0x00000020,
  36. .user_ctl_val = 0x00000000,
  37. .user_ctl_hi_val = 0x00000805,
  38. .user_ctl_hi1_val = 0x000000d0,
  39. };
  40. static struct clk_alpha_pll gpu_cc_pll1 = {
  41. .offset = 0x100,
  42. .vco_table = trion_vco,
  43. .num_vco = ARRAY_SIZE(trion_vco),
  44. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_TRION],
  45. .clkr = {
  46. .hw.init = &(struct clk_init_data){
  47. .name = "gpu_cc_pll1",
  48. .parent_data = &(const struct clk_parent_data){
  49. .fw_name = "bi_tcxo",
  50. },
  51. .num_parents = 1,
  52. .ops = &clk_alpha_pll_trion_ops,
  53. },
  54. },
  55. };
  56. static const struct parent_map gpu_cc_parent_map_0[] = {
  57. { P_BI_TCXO, 0 },
  58. { P_GPU_CC_PLL1_OUT_MAIN, 3 },
  59. { P_GPLL0_OUT_MAIN, 5 },
  60. { P_GPLL0_OUT_MAIN_DIV, 6 },
  61. };
  62. static const struct clk_parent_data gpu_cc_parent_data_0[] = {
  63. { .fw_name = "bi_tcxo" },
  64. { .hw = &gpu_cc_pll1.clkr.hw },
  65. { .fw_name = "gcc_gpu_gpll0_clk_src" },
  66. { .fw_name = "gcc_gpu_gpll0_div_clk_src" },
  67. };
  68. static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src[] = {
  69. F(19200000, P_BI_TCXO, 1, 0, 0),
  70. F(200000000, P_GPLL0_OUT_MAIN_DIV, 1.5, 0, 0),
  71. F(500000000, P_GPU_CC_PLL1_OUT_MAIN, 1, 0, 0),
  72. { }
  73. };
  74. static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src_sc8180x[] = {
  75. F(19200000, P_BI_TCXO, 1, 0, 0),
  76. F(200000000, P_GPLL0_OUT_MAIN_DIV, 1.5, 0, 0),
  77. F(400000000, P_GPLL0_OUT_MAIN, 1.5, 0, 0),
  78. F(500000000, P_GPU_CC_PLL1_OUT_MAIN, 1, 0, 0),
  79. { }
  80. };
  81. static struct clk_rcg2 gpu_cc_gmu_clk_src = {
  82. .cmd_rcgr = 0x1120,
  83. .mnd_width = 0,
  84. .hid_width = 5,
  85. .parent_map = gpu_cc_parent_map_0,
  86. .freq_tbl = ftbl_gpu_cc_gmu_clk_src,
  87. .clkr.hw.init = &(struct clk_init_data){
  88. .name = "gpu_cc_gmu_clk_src",
  89. .parent_data = gpu_cc_parent_data_0,
  90. .num_parents = ARRAY_SIZE(gpu_cc_parent_data_0),
  91. .flags = CLK_SET_RATE_PARENT,
  92. .ops = &clk_rcg2_ops,
  93. },
  94. };
  95. static struct clk_branch gpu_cc_ahb_clk = {
  96. .halt_reg = 0x1078,
  97. .halt_check = BRANCH_HALT_DELAY,
  98. .clkr = {
  99. .enable_reg = 0x1078,
  100. .enable_mask = BIT(0),
  101. .hw.init = &(struct clk_init_data){
  102. .name = "gpu_cc_ahb_clk",
  103. .ops = &clk_branch2_ops,
  104. },
  105. },
  106. };
  107. static struct clk_branch gpu_cc_crc_ahb_clk = {
  108. .halt_reg = 0x107c,
  109. .halt_check = BRANCH_HALT,
  110. .clkr = {
  111. .enable_reg = 0x107c,
  112. .enable_mask = BIT(0),
  113. .hw.init = &(struct clk_init_data){
  114. .name = "gpu_cc_crc_ahb_clk",
  115. .ops = &clk_branch2_ops,
  116. },
  117. },
  118. };
  119. static struct clk_branch gpu_cc_cx_apb_clk = {
  120. .halt_reg = 0x1088,
  121. .halt_check = BRANCH_HALT,
  122. .clkr = {
  123. .enable_reg = 0x1088,
  124. .enable_mask = BIT(0),
  125. .hw.init = &(struct clk_init_data){
  126. .name = "gpu_cc_cx_apb_clk",
  127. .ops = &clk_branch2_ops,
  128. },
  129. },
  130. };
  131. static struct clk_branch gpu_cc_cx_gmu_clk = {
  132. .halt_reg = 0x1098,
  133. .halt_check = BRANCH_HALT,
  134. .clkr = {
  135. .enable_reg = 0x1098,
  136. .enable_mask = BIT(0),
  137. .hw.init = &(struct clk_init_data){
  138. .name = "gpu_cc_cx_gmu_clk",
  139. .parent_hws = (const struct clk_hw*[]){
  140. &gpu_cc_gmu_clk_src.clkr.hw,
  141. },
  142. .num_parents = 1,
  143. .flags = CLK_SET_RATE_PARENT,
  144. .ops = &clk_branch2_ops,
  145. },
  146. },
  147. };
  148. static struct clk_branch gpu_cc_cx_snoc_dvm_clk = {
  149. .halt_reg = 0x108c,
  150. .halt_check = BRANCH_HALT,
  151. .clkr = {
  152. .enable_reg = 0x108c,
  153. .enable_mask = BIT(0),
  154. .hw.init = &(struct clk_init_data){
  155. .name = "gpu_cc_cx_snoc_dvm_clk",
  156. .ops = &clk_branch2_ops,
  157. },
  158. },
  159. };
  160. static struct clk_branch gpu_cc_cxo_aon_clk = {
  161. .halt_reg = 0x1004,
  162. .halt_check = BRANCH_HALT,
  163. .clkr = {
  164. .enable_reg = 0x1004,
  165. .enable_mask = BIT(0),
  166. .hw.init = &(struct clk_init_data){
  167. .name = "gpu_cc_cxo_aon_clk",
  168. .ops = &clk_branch2_ops,
  169. },
  170. },
  171. };
  172. static struct clk_branch gpu_cc_cxo_clk = {
  173. .halt_reg = 0x109c,
  174. .halt_check = BRANCH_HALT,
  175. .clkr = {
  176. .enable_reg = 0x109c,
  177. .enable_mask = BIT(0),
  178. .hw.init = &(struct clk_init_data){
  179. .name = "gpu_cc_cxo_clk",
  180. .ops = &clk_branch2_ops,
  181. },
  182. },
  183. };
  184. static struct clk_branch gpu_cc_gx_gmu_clk = {
  185. .halt_reg = 0x1064,
  186. .halt_check = BRANCH_HALT,
  187. .clkr = {
  188. .enable_reg = 0x1064,
  189. .enable_mask = BIT(0),
  190. .hw.init = &(struct clk_init_data){
  191. .name = "gpu_cc_gx_gmu_clk",
  192. .parent_hws = (const struct clk_hw*[]){
  193. &gpu_cc_gmu_clk_src.clkr.hw,
  194. },
  195. .num_parents = 1,
  196. .flags = CLK_SET_RATE_PARENT,
  197. .ops = &clk_branch2_ops,
  198. },
  199. },
  200. };
  201. static struct gdsc gpu_cx_gdsc = {
  202. .gdscr = 0x106c,
  203. .gds_hw_ctrl = 0x1540,
  204. .pd = {
  205. .name = "gpu_cx_gdsc",
  206. },
  207. .pwrsts = PWRSTS_OFF_ON,
  208. .flags = VOTABLE,
  209. };
  210. static struct gdsc gpu_gx_gdsc = {
  211. .gdscr = 0x100c,
  212. .clamp_io_ctrl = 0x1508,
  213. .pd = {
  214. .name = "gpu_gx_gdsc",
  215. .power_on = gdsc_gx_do_nothing_enable,
  216. },
  217. .pwrsts = PWRSTS_OFF_ON,
  218. .flags = CLAMP_IO | AON_RESET | POLL_CFG_GDSCR,
  219. };
  220. static struct clk_regmap *gpu_cc_sm8150_clocks[] = {
  221. [GPU_CC_AHB_CLK] = &gpu_cc_ahb_clk.clkr,
  222. [GPU_CC_CRC_AHB_CLK] = &gpu_cc_crc_ahb_clk.clkr,
  223. [GPU_CC_CX_APB_CLK] = &gpu_cc_cx_apb_clk.clkr,
  224. [GPU_CC_CX_GMU_CLK] = &gpu_cc_cx_gmu_clk.clkr,
  225. [GPU_CC_CX_SNOC_DVM_CLK] = &gpu_cc_cx_snoc_dvm_clk.clkr,
  226. [GPU_CC_CXO_AON_CLK] = &gpu_cc_cxo_aon_clk.clkr,
  227. [GPU_CC_CXO_CLK] = &gpu_cc_cxo_clk.clkr,
  228. [GPU_CC_GMU_CLK_SRC] = &gpu_cc_gmu_clk_src.clkr,
  229. [GPU_CC_GX_GMU_CLK] = &gpu_cc_gx_gmu_clk.clkr,
  230. [GPU_CC_PLL1] = &gpu_cc_pll1.clkr,
  231. };
  232. static const struct qcom_reset_map gpu_cc_sm8150_resets[] = {
  233. [GPUCC_GPU_CC_CX_BCR] = { 0x1068 },
  234. [GPUCC_GPU_CC_GMU_BCR] = { 0x111c },
  235. [GPUCC_GPU_CC_GX_BCR] = { 0x1008 },
  236. [GPUCC_GPU_CC_SPDM_BCR] = { 0x1110 },
  237. [GPUCC_GPU_CC_XO_BCR] = { 0x1000 },
  238. };
  239. static struct gdsc *gpu_cc_sm8150_gdscs[] = {
  240. [GPU_CX_GDSC] = &gpu_cx_gdsc,
  241. [GPU_GX_GDSC] = &gpu_gx_gdsc,
  242. };
  243. static const struct regmap_config gpu_cc_sm8150_regmap_config = {
  244. .reg_bits = 32,
  245. .reg_stride = 4,
  246. .val_bits = 32,
  247. .max_register = 0x8008,
  248. .fast_io = true,
  249. };
  250. static const struct qcom_cc_desc gpu_cc_sm8150_desc = {
  251. .config = &gpu_cc_sm8150_regmap_config,
  252. .clks = gpu_cc_sm8150_clocks,
  253. .num_clks = ARRAY_SIZE(gpu_cc_sm8150_clocks),
  254. .resets = gpu_cc_sm8150_resets,
  255. .num_resets = ARRAY_SIZE(gpu_cc_sm8150_resets),
  256. .gdscs = gpu_cc_sm8150_gdscs,
  257. .num_gdscs = ARRAY_SIZE(gpu_cc_sm8150_gdscs),
  258. };
  259. static const struct of_device_id gpu_cc_sm8150_match_table[] = {
  260. { .compatible = "qcom,sc8180x-gpucc" },
  261. { .compatible = "qcom,sm8150-gpucc" },
  262. { }
  263. };
  264. MODULE_DEVICE_TABLE(of, gpu_cc_sm8150_match_table);
  265. static int gpu_cc_sm8150_probe(struct platform_device *pdev)
  266. {
  267. struct regmap *regmap;
  268. regmap = qcom_cc_map(pdev, &gpu_cc_sm8150_desc);
  269. if (IS_ERR(regmap))
  270. return PTR_ERR(regmap);
  271. if (of_device_is_compatible(pdev->dev.of_node, "qcom,sc8180x-gpucc"))
  272. gpu_cc_gmu_clk_src.freq_tbl = ftbl_gpu_cc_gmu_clk_src_sc8180x;
  273. clk_trion_pll_configure(&gpu_cc_pll1, regmap, &gpu_cc_pll1_config);
  274. return qcom_cc_really_probe(&pdev->dev, &gpu_cc_sm8150_desc, regmap);
  275. }
  276. static struct platform_driver gpu_cc_sm8150_driver = {
  277. .probe = gpu_cc_sm8150_probe,
  278. .driver = {
  279. .name = "sm8150-gpucc",
  280. .of_match_table = gpu_cc_sm8150_match_table,
  281. },
  282. };
  283. module_platform_driver(gpu_cc_sm8150_driver);
  284. MODULE_DESCRIPTION("QTI GPUCC SM8150 Driver");
  285. MODULE_LICENSE("GPL v2");