gpucc-sm8250.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2018-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-sm8250.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. #define CX_GMU_CBCR_SLEEP_MASK 0xf
  19. #define CX_GMU_CBCR_SLEEP_SHIFT 4
  20. #define CX_GMU_CBCR_WAKE_MASK 0xf
  21. #define CX_GMU_CBCR_WAKE_SHIFT 8
  22. enum {
  23. P_BI_TCXO,
  24. P_GPLL0_OUT_MAIN,
  25. P_GPLL0_OUT_MAIN_DIV,
  26. P_GPU_CC_PLL0_OUT_MAIN,
  27. P_GPU_CC_PLL1_OUT_MAIN,
  28. };
  29. static struct pll_vco lucid_vco[] = {
  30. { 249600000, 2000000000, 0 },
  31. };
  32. static const struct alpha_pll_config gpu_cc_pll1_config = {
  33. .l = 0x1a,
  34. .alpha = 0xaaa,
  35. .config_ctl_val = 0x20485699,
  36. .config_ctl_hi_val = 0x00002261,
  37. .config_ctl_hi1_val = 0x029a699c,
  38. .user_ctl_val = 0x00000000,
  39. .user_ctl_hi_val = 0x00000805,
  40. .user_ctl_hi1_val = 0x00000000,
  41. };
  42. static struct clk_alpha_pll gpu_cc_pll1 = {
  43. .offset = 0x100,
  44. .vco_table = lucid_vco,
  45. .num_vco = ARRAY_SIZE(lucid_vco),
  46. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
  47. .clkr = {
  48. .hw.init = &(struct clk_init_data){
  49. .name = "gpu_cc_pll1",
  50. .parent_data = &(const struct clk_parent_data){
  51. .fw_name = "bi_tcxo",
  52. },
  53. .num_parents = 1,
  54. .ops = &clk_alpha_pll_lucid_ops,
  55. },
  56. },
  57. };
  58. static const struct parent_map gpu_cc_parent_map_0[] = {
  59. { P_BI_TCXO, 0 },
  60. { P_GPU_CC_PLL1_OUT_MAIN, 3 },
  61. { P_GPLL0_OUT_MAIN, 5 },
  62. { P_GPLL0_OUT_MAIN_DIV, 6 },
  63. };
  64. static const struct clk_parent_data gpu_cc_parent_data_0[] = {
  65. { .fw_name = "bi_tcxo" },
  66. { .hw = &gpu_cc_pll1.clkr.hw },
  67. { .fw_name = "gcc_gpu_gpll0_clk_src" },
  68. { .fw_name = "gcc_gpu_gpll0_div_clk_src" },
  69. };
  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),
  74. { }
  75. };
  76. static struct clk_rcg2 gpu_cc_gmu_clk_src = {
  77. .cmd_rcgr = 0x1120,
  78. .mnd_width = 0,
  79. .hid_width = 5,
  80. .parent_map = gpu_cc_parent_map_0,
  81. .freq_tbl = ftbl_gpu_cc_gmu_clk_src,
  82. .clkr.hw.init = &(struct clk_init_data){
  83. .name = "gpu_cc_gmu_clk_src",
  84. .parent_data = gpu_cc_parent_data_0,
  85. .num_parents = ARRAY_SIZE(gpu_cc_parent_data_0),
  86. .flags = CLK_SET_RATE_PARENT,
  87. .ops = &clk_rcg2_ops,
  88. },
  89. };
  90. static struct clk_branch gpu_cc_ahb_clk = {
  91. .halt_reg = 0x1078,
  92. .halt_check = BRANCH_HALT_DELAY,
  93. .clkr = {
  94. .enable_reg = 0x1078,
  95. .enable_mask = BIT(0),
  96. .hw.init = &(struct clk_init_data){
  97. .name = "gpu_cc_ahb_clk",
  98. .ops = &clk_branch2_ops,
  99. },
  100. },
  101. };
  102. static struct clk_branch gpu_cc_crc_ahb_clk = {
  103. .halt_reg = 0x107c,
  104. .halt_check = BRANCH_HALT_VOTED,
  105. .clkr = {
  106. .enable_reg = 0x107c,
  107. .enable_mask = BIT(0),
  108. .hw.init = &(struct clk_init_data){
  109. .name = "gpu_cc_crc_ahb_clk",
  110. .ops = &clk_branch2_ops,
  111. },
  112. },
  113. };
  114. static struct clk_branch gpu_cc_cx_apb_clk = {
  115. .halt_reg = 0x1088,
  116. .halt_check = BRANCH_HALT_VOTED,
  117. .clkr = {
  118. .enable_reg = 0x1088,
  119. .enable_mask = BIT(0),
  120. .hw.init = &(struct clk_init_data){
  121. .name = "gpu_cc_cx_apb_clk",
  122. .ops = &clk_branch2_ops,
  123. },
  124. },
  125. };
  126. static struct clk_branch gpu_cc_cx_gmu_clk = {
  127. .halt_reg = 0x1098,
  128. .halt_check = BRANCH_HALT,
  129. .clkr = {
  130. .enable_reg = 0x1098,
  131. .enable_mask = BIT(0),
  132. .hw.init = &(struct clk_init_data){
  133. .name = "gpu_cc_cx_gmu_clk",
  134. .parent_hws = (const struct clk_hw*[]){
  135. &gpu_cc_gmu_clk_src.clkr.hw,
  136. },
  137. .num_parents = 1,
  138. .flags = CLK_SET_RATE_PARENT,
  139. .ops = &clk_branch2_ops,
  140. },
  141. },
  142. };
  143. static struct clk_branch gpu_cc_cx_snoc_dvm_clk = {
  144. .halt_reg = 0x108c,
  145. .halt_check = BRANCH_HALT_VOTED,
  146. .clkr = {
  147. .enable_reg = 0x108c,
  148. .enable_mask = BIT(0),
  149. .hw.init = &(struct clk_init_data){
  150. .name = "gpu_cc_cx_snoc_dvm_clk",
  151. .ops = &clk_branch2_ops,
  152. },
  153. },
  154. };
  155. static struct clk_branch gpu_cc_cxo_aon_clk = {
  156. .halt_reg = 0x1004,
  157. .halt_check = BRANCH_HALT_VOTED,
  158. .clkr = {
  159. .enable_reg = 0x1004,
  160. .enable_mask = BIT(0),
  161. .hw.init = &(struct clk_init_data){
  162. .name = "gpu_cc_cxo_aon_clk",
  163. .ops = &clk_branch2_ops,
  164. },
  165. },
  166. };
  167. static struct clk_branch gpu_cc_cxo_clk = {
  168. .halt_reg = 0x109c,
  169. .halt_check = BRANCH_HALT,
  170. .clkr = {
  171. .enable_reg = 0x109c,
  172. .enable_mask = BIT(0),
  173. .hw.init = &(struct clk_init_data){
  174. .name = "gpu_cc_cxo_clk",
  175. .ops = &clk_branch2_ops,
  176. },
  177. },
  178. };
  179. static struct clk_branch gpu_cc_gx_gmu_clk = {
  180. .halt_reg = 0x1064,
  181. .halt_check = BRANCH_HALT,
  182. .clkr = {
  183. .enable_reg = 0x1064,
  184. .enable_mask = BIT(0),
  185. .hw.init = &(struct clk_init_data){
  186. .name = "gpu_cc_gx_gmu_clk",
  187. .parent_hws = (const struct clk_hw*[]){
  188. &gpu_cc_gmu_clk_src.clkr.hw,
  189. },
  190. .num_parents = 1,
  191. .flags = CLK_SET_RATE_PARENT,
  192. .ops = &clk_branch2_ops,
  193. },
  194. },
  195. };
  196. static struct clk_branch gpu_cc_hlos1_vote_gpu_smmu_clk = {
  197. .halt_reg = 0x5000,
  198. .halt_check = BRANCH_VOTED,
  199. .clkr = {
  200. .enable_reg = 0x5000,
  201. .enable_mask = BIT(0),
  202. .hw.init = &(struct clk_init_data){
  203. .name = "gpu_cc_hlos1_vote_gpu_smmu_clk",
  204. .ops = &clk_branch2_ops,
  205. },
  206. },
  207. };
  208. static struct gdsc gpu_cx_gdsc = {
  209. .gdscr = 0x106c,
  210. .gds_hw_ctrl = 0x1540,
  211. .pd = {
  212. .name = "gpu_cx_gdsc",
  213. },
  214. .pwrsts = PWRSTS_OFF_ON,
  215. .flags = VOTABLE,
  216. };
  217. static struct gdsc gpu_gx_gdsc = {
  218. .gdscr = 0x100c,
  219. .clamp_io_ctrl = 0x1508,
  220. .pd = {
  221. .name = "gpu_gx_gdsc",
  222. .power_on = gdsc_gx_do_nothing_enable,
  223. },
  224. .pwrsts = PWRSTS_OFF_ON,
  225. .flags = CLAMP_IO | AON_RESET | POLL_CFG_GDSCR,
  226. };
  227. static struct clk_regmap *gpu_cc_sm8250_clocks[] = {
  228. [GPU_CC_AHB_CLK] = &gpu_cc_ahb_clk.clkr,
  229. [GPU_CC_CRC_AHB_CLK] = &gpu_cc_crc_ahb_clk.clkr,
  230. [GPU_CC_CX_APB_CLK] = &gpu_cc_cx_apb_clk.clkr,
  231. [GPU_CC_CX_GMU_CLK] = &gpu_cc_cx_gmu_clk.clkr,
  232. [GPU_CC_CX_SNOC_DVM_CLK] = &gpu_cc_cx_snoc_dvm_clk.clkr,
  233. [GPU_CC_CXO_AON_CLK] = &gpu_cc_cxo_aon_clk.clkr,
  234. [GPU_CC_CXO_CLK] = &gpu_cc_cxo_clk.clkr,
  235. [GPU_CC_GMU_CLK_SRC] = &gpu_cc_gmu_clk_src.clkr,
  236. [GPU_CC_GX_GMU_CLK] = &gpu_cc_gx_gmu_clk.clkr,
  237. [GPU_CC_PLL1] = &gpu_cc_pll1.clkr,
  238. [GPU_CC_HLOS1_VOTE_GPU_SMMU_CLK] = &gpu_cc_hlos1_vote_gpu_smmu_clk.clkr,
  239. };
  240. static const struct qcom_reset_map gpu_cc_sm8250_resets[] = {
  241. [GPUCC_GPU_CC_ACD_BCR] = { 0x1160 },
  242. [GPUCC_GPU_CC_CX_BCR] = { 0x1068 },
  243. [GPUCC_GPU_CC_GFX3D_AON_BCR] = { 0x10a0 },
  244. [GPUCC_GPU_CC_GMU_BCR] = { 0x111c },
  245. [GPUCC_GPU_CC_GX_BCR] = { 0x1008 },
  246. [GPUCC_GPU_CC_XO_BCR] = { 0x1000 },
  247. };
  248. static struct gdsc *gpu_cc_sm8250_gdscs[] = {
  249. [GPU_CX_GDSC] = &gpu_cx_gdsc,
  250. [GPU_GX_GDSC] = &gpu_gx_gdsc,
  251. };
  252. static const struct regmap_config gpu_cc_sm8250_regmap_config = {
  253. .reg_bits = 32,
  254. .reg_stride = 4,
  255. .val_bits = 32,
  256. .max_register = 0x8008,
  257. .fast_io = true,
  258. };
  259. static const struct qcom_cc_desc gpu_cc_sm8250_desc = {
  260. .config = &gpu_cc_sm8250_regmap_config,
  261. .clks = gpu_cc_sm8250_clocks,
  262. .num_clks = ARRAY_SIZE(gpu_cc_sm8250_clocks),
  263. .resets = gpu_cc_sm8250_resets,
  264. .num_resets = ARRAY_SIZE(gpu_cc_sm8250_resets),
  265. .gdscs = gpu_cc_sm8250_gdscs,
  266. .num_gdscs = ARRAY_SIZE(gpu_cc_sm8250_gdscs),
  267. };
  268. static const struct of_device_id gpu_cc_sm8250_match_table[] = {
  269. { .compatible = "qcom,sm8250-gpucc" },
  270. { }
  271. };
  272. MODULE_DEVICE_TABLE(of, gpu_cc_sm8250_match_table);
  273. static int gpu_cc_sm8250_probe(struct platform_device *pdev)
  274. {
  275. struct regmap *regmap;
  276. unsigned int value, mask;
  277. regmap = qcom_cc_map(pdev, &gpu_cc_sm8250_desc);
  278. if (IS_ERR(regmap))
  279. return PTR_ERR(regmap);
  280. clk_lucid_pll_configure(&gpu_cc_pll1, regmap, &gpu_cc_pll1_config);
  281. /*
  282. * Configure gpu_cc_cx_gmu_clk with recommended
  283. * wakeup/sleep settings
  284. */
  285. mask = CX_GMU_CBCR_WAKE_MASK << CX_GMU_CBCR_WAKE_SHIFT;
  286. mask |= CX_GMU_CBCR_SLEEP_MASK << CX_GMU_CBCR_SLEEP_SHIFT;
  287. value = 0xf << CX_GMU_CBCR_WAKE_SHIFT | 0xf << CX_GMU_CBCR_SLEEP_SHIFT;
  288. regmap_update_bits(regmap, 0x1098, mask, value);
  289. return qcom_cc_really_probe(pdev, &gpu_cc_sm8250_desc, regmap);
  290. }
  291. static struct platform_driver gpu_cc_sm8250_driver = {
  292. .probe = gpu_cc_sm8250_probe,
  293. .driver = {
  294. .name = "sm8250-gpucc",
  295. .of_match_table = gpu_cc_sm8250_match_table,
  296. },
  297. };
  298. static int __init gpu_cc_sm8250_init(void)
  299. {
  300. return platform_driver_register(&gpu_cc_sm8250_driver);
  301. }
  302. subsys_initcall(gpu_cc_sm8250_init);
  303. static void __exit gpu_cc_sm8250_exit(void)
  304. {
  305. platform_driver_unregister(&gpu_cc_sm8250_driver);
  306. }
  307. module_exit(gpu_cc_sm8250_exit);
  308. MODULE_DESCRIPTION("QTI GPU_CC SM8250 Driver");
  309. MODULE_LICENSE("GPL v2");