gpucc-sdm660.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2020, AngeloGioacchino Del Regno
  5. * <angelogioacchino.delregno@somainline.org>
  6. */
  7. #include <linux/bitops.h>
  8. #include <linux/clk-provider.h>
  9. #include <linux/err.h>
  10. #include <linux/kernel.h>
  11. #include <linux/mod_devicetable.h>
  12. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/regmap.h>
  15. #include <dt-bindings/clock/qcom,gpucc-sdm660.h>
  16. #include "clk-alpha-pll.h"
  17. #include "common.h"
  18. #include "clk-regmap.h"
  19. #include "clk-pll.h"
  20. #include "clk-rcg.h"
  21. #include "clk-branch.h"
  22. #include "gdsc.h"
  23. #include "reset.h"
  24. enum {
  25. P_GPU_XO,
  26. P_GPLL0_OUT_MAIN,
  27. P_GPLL0_OUT_MAIN_DIV,
  28. P_GPU_PLL0_PLL_OUT_MAIN,
  29. P_GPU_PLL1_PLL_OUT_MAIN,
  30. };
  31. static struct clk_branch gpucc_cxo_clk = {
  32. .halt_reg = 0x1020,
  33. .clkr = {
  34. .enable_reg = 0x1020,
  35. .enable_mask = BIT(0),
  36. .hw.init = &(struct clk_init_data){
  37. .name = "gpucc_cxo_clk",
  38. .parent_data = &(const struct clk_parent_data){
  39. .fw_name = "xo"
  40. },
  41. .num_parents = 1,
  42. .ops = &clk_branch2_ops,
  43. .flags = CLK_IS_CRITICAL,
  44. },
  45. },
  46. };
  47. static const struct pll_vco gpu_vco[] = {
  48. { 1000000000, 2000000000, 0 },
  49. { 500000000, 1000000000, 2 },
  50. { 250000000, 500000000, 3 },
  51. };
  52. static struct clk_alpha_pll gpu_pll0_pll_out_main = {
  53. .offset = 0x0,
  54. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
  55. .vco_table = gpu_vco,
  56. .num_vco = ARRAY_SIZE(gpu_vco),
  57. .clkr.hw.init = &(struct clk_init_data){
  58. .name = "gpu_pll0_pll_out_main",
  59. .parent_hws = (const struct clk_hw*[]){
  60. &gpucc_cxo_clk.clkr.hw,
  61. },
  62. .num_parents = 1,
  63. .ops = &clk_alpha_pll_ops,
  64. },
  65. };
  66. static struct clk_alpha_pll gpu_pll1_pll_out_main = {
  67. .offset = 0x40,
  68. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
  69. .vco_table = gpu_vco,
  70. .num_vco = ARRAY_SIZE(gpu_vco),
  71. .clkr.hw.init = &(struct clk_init_data){
  72. .name = "gpu_pll1_pll_out_main",
  73. .parent_hws = (const struct clk_hw*[]){
  74. &gpucc_cxo_clk.clkr.hw,
  75. },
  76. .num_parents = 1,
  77. .ops = &clk_alpha_pll_ops,
  78. },
  79. };
  80. static const struct parent_map gpucc_parent_map_1[] = {
  81. { P_GPU_XO, 0 },
  82. { P_GPU_PLL0_PLL_OUT_MAIN, 1 },
  83. { P_GPU_PLL1_PLL_OUT_MAIN, 3 },
  84. { P_GPLL0_OUT_MAIN, 5 },
  85. };
  86. static const struct clk_parent_data gpucc_parent_data_1[] = {
  87. { .hw = &gpucc_cxo_clk.clkr.hw },
  88. { .hw = &gpu_pll0_pll_out_main.clkr.hw },
  89. { .hw = &gpu_pll1_pll_out_main.clkr.hw },
  90. { .fw_name = "gcc_gpu_gpll0_clk" },
  91. };
  92. static struct clk_rcg2_gfx3d gfx3d_clk_src = {
  93. .div = 2,
  94. .rcg = {
  95. .cmd_rcgr = 0x1070,
  96. .mnd_width = 0,
  97. .hid_width = 5,
  98. .parent_map = gpucc_parent_map_1,
  99. .clkr.hw.init = &(struct clk_init_data){
  100. .name = "gfx3d_clk_src",
  101. .parent_data = gpucc_parent_data_1,
  102. .num_parents = ARRAY_SIZE(gpucc_parent_data_1),
  103. .ops = &clk_gfx3d_ops,
  104. .flags = CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
  105. },
  106. },
  107. .hws = (struct clk_hw*[]){
  108. &gpucc_cxo_clk.clkr.hw,
  109. &gpu_pll0_pll_out_main.clkr.hw,
  110. &gpu_pll1_pll_out_main.clkr.hw,
  111. }
  112. };
  113. static struct clk_branch gpucc_gfx3d_clk = {
  114. .halt_reg = 0x1098,
  115. .halt_check = BRANCH_HALT,
  116. .hwcg_reg = 0x1098,
  117. .hwcg_bit = 1,
  118. .clkr = {
  119. .enable_reg = 0x1098,
  120. .enable_mask = BIT(0),
  121. .hw.init = &(struct clk_init_data){
  122. .name = "gpucc_gfx3d_clk",
  123. .parent_hws = (const struct clk_hw*[]){
  124. &gfx3d_clk_src.rcg.clkr.hw,
  125. },
  126. .num_parents = 1,
  127. .ops = &clk_branch2_ops,
  128. .flags = CLK_SET_RATE_PARENT,
  129. },
  130. },
  131. };
  132. static const struct parent_map gpucc_parent_map_0[] = {
  133. { P_GPU_XO, 0 },
  134. { P_GPLL0_OUT_MAIN, 5 },
  135. { P_GPLL0_OUT_MAIN_DIV, 6 },
  136. };
  137. static const struct clk_parent_data gpucc_parent_data_0[] = {
  138. { .hw = &gpucc_cxo_clk.clkr.hw },
  139. { .fw_name = "gcc_gpu_gpll0_clk" },
  140. { .fw_name = "gcc_gpu_gpll0_div_clk" },
  141. };
  142. static const struct freq_tbl ftbl_rbbmtimer_clk_src[] = {
  143. F(19200000, P_GPU_XO, 1, 0, 0),
  144. { }
  145. };
  146. static struct clk_rcg2 rbbmtimer_clk_src = {
  147. .cmd_rcgr = 0x10b0,
  148. .mnd_width = 0,
  149. .hid_width = 5,
  150. .parent_map = gpucc_parent_map_0,
  151. .freq_tbl = ftbl_rbbmtimer_clk_src,
  152. .clkr.hw.init = &(struct clk_init_data){
  153. .name = "rbbmtimer_clk_src",
  154. .parent_data = gpucc_parent_data_0,
  155. .num_parents = ARRAY_SIZE(gpucc_parent_data_0),
  156. .ops = &clk_rcg2_ops,
  157. },
  158. };
  159. static const struct freq_tbl ftbl_rbcpr_clk_src[] = {
  160. F(19200000, P_GPU_XO, 1, 0, 0),
  161. F(50000000, P_GPLL0_OUT_MAIN_DIV, 6, 0, 0),
  162. { }
  163. };
  164. static struct clk_rcg2 rbcpr_clk_src = {
  165. .cmd_rcgr = 0x1030,
  166. .mnd_width = 0,
  167. .hid_width = 5,
  168. .parent_map = gpucc_parent_map_0,
  169. .freq_tbl = ftbl_rbcpr_clk_src,
  170. .clkr.hw.init = &(struct clk_init_data){
  171. .name = "rbcpr_clk_src",
  172. .parent_data = gpucc_parent_data_0,
  173. .num_parents = ARRAY_SIZE(gpucc_parent_data_0),
  174. .ops = &clk_rcg2_ops,
  175. },
  176. };
  177. static struct clk_branch gpucc_rbbmtimer_clk = {
  178. .halt_reg = 0x10d0,
  179. .halt_check = BRANCH_HALT,
  180. .clkr = {
  181. .enable_reg = 0x10d0,
  182. .enable_mask = BIT(0),
  183. .hw.init = &(struct clk_init_data){
  184. .name = "gpucc_rbbmtimer_clk",
  185. .parent_hws = (const struct clk_hw*[]){
  186. &rbbmtimer_clk_src.clkr.hw,
  187. },
  188. .num_parents = 1,
  189. .flags = CLK_SET_RATE_PARENT,
  190. .ops = &clk_branch2_ops,
  191. },
  192. },
  193. };
  194. static struct clk_branch gpucc_rbcpr_clk = {
  195. .halt_reg = 0x1054,
  196. .halt_check = BRANCH_HALT,
  197. .clkr = {
  198. .enable_reg = 0x1054,
  199. .enable_mask = BIT(0),
  200. .hw.init = &(struct clk_init_data){
  201. .name = "gpucc_rbcpr_clk",
  202. .parent_hws = (const struct clk_hw*[]){
  203. &rbcpr_clk_src.clkr.hw,
  204. },
  205. .num_parents = 1,
  206. .flags = CLK_SET_RATE_PARENT,
  207. .ops = &clk_branch2_ops,
  208. },
  209. },
  210. };
  211. static struct gdsc gpu_cx_gdsc = {
  212. .gdscr = 0x1004,
  213. .gds_hw_ctrl = 0x1008,
  214. .pd = {
  215. .name = "gpu_cx",
  216. },
  217. .pwrsts = PWRSTS_OFF_ON,
  218. .flags = VOTABLE,
  219. };
  220. static struct gdsc gpu_gx_gdsc = {
  221. .gdscr = 0x1094,
  222. .clamp_io_ctrl = 0x130,
  223. .resets = (unsigned int []){ GPU_GX_BCR },
  224. .reset_count = 1,
  225. .cxcs = (unsigned int []){ 0x1098 },
  226. .cxc_count = 1,
  227. .pd = {
  228. .name = "gpu_gx",
  229. },
  230. .parent = &gpu_cx_gdsc.pd,
  231. .pwrsts = PWRSTS_OFF | PWRSTS_ON | PWRSTS_RET,
  232. .flags = CLAMP_IO | SW_RESET | AON_RESET | NO_RET_PERIPH,
  233. };
  234. static struct gdsc *gpucc_sdm660_gdscs[] = {
  235. [GPU_CX_GDSC] = &gpu_cx_gdsc,
  236. [GPU_GX_GDSC] = &gpu_gx_gdsc,
  237. };
  238. static const struct qcom_reset_map gpucc_sdm660_resets[] = {
  239. [GPU_CX_BCR] = { 0x1000 },
  240. [RBCPR_BCR] = { 0x1050 },
  241. [GPU_GX_BCR] = { 0x1090 },
  242. [SPDM_BCR] = { 0x10E0 },
  243. };
  244. static struct clk_regmap *gpucc_sdm660_clocks[] = {
  245. [GPUCC_CXO_CLK] = &gpucc_cxo_clk.clkr,
  246. [GPU_PLL0_PLL] = &gpu_pll0_pll_out_main.clkr,
  247. [GPU_PLL1_PLL] = &gpu_pll1_pll_out_main.clkr,
  248. [GFX3D_CLK_SRC] = &gfx3d_clk_src.rcg.clkr,
  249. [RBCPR_CLK_SRC] = &rbcpr_clk_src.clkr,
  250. [RBBMTIMER_CLK_SRC] = &rbbmtimer_clk_src.clkr,
  251. [GPUCC_RBCPR_CLK] = &gpucc_rbcpr_clk.clkr,
  252. [GPUCC_GFX3D_CLK] = &gpucc_gfx3d_clk.clkr,
  253. [GPUCC_RBBMTIMER_CLK] = &gpucc_rbbmtimer_clk.clkr,
  254. };
  255. static const struct regmap_config gpucc_660_regmap_config = {
  256. .reg_bits = 32,
  257. .reg_stride = 4,
  258. .val_bits = 32,
  259. .max_register = 0x9034,
  260. .fast_io = true,
  261. };
  262. static const struct qcom_cc_desc gpucc_sdm660_desc = {
  263. .config = &gpucc_660_regmap_config,
  264. .clks = gpucc_sdm660_clocks,
  265. .num_clks = ARRAY_SIZE(gpucc_sdm660_clocks),
  266. .resets = gpucc_sdm660_resets,
  267. .num_resets = ARRAY_SIZE(gpucc_sdm660_resets),
  268. .gdscs = gpucc_sdm660_gdscs,
  269. .num_gdscs = ARRAY_SIZE(gpucc_sdm660_gdscs),
  270. };
  271. static const struct of_device_id gpucc_sdm660_match_table[] = {
  272. { .compatible = "qcom,gpucc-sdm660" },
  273. { .compatible = "qcom,gpucc-sdm630" },
  274. { }
  275. };
  276. MODULE_DEVICE_TABLE(of, gpucc_sdm660_match_table);
  277. static int gpucc_sdm660_probe(struct platform_device *pdev)
  278. {
  279. struct regmap *regmap;
  280. struct alpha_pll_config gpu_pll_config = {
  281. .config_ctl_val = 0x4001055b,
  282. .alpha = 0xaaaaab00,
  283. .alpha_en_mask = BIT(24),
  284. .vco_val = 0x2 << 20,
  285. .vco_mask = 0x3 << 20,
  286. .main_output_mask = 0x1,
  287. };
  288. regmap = qcom_cc_map(pdev, &gpucc_sdm660_desc);
  289. if (IS_ERR(regmap))
  290. return PTR_ERR(regmap);
  291. /* 800MHz configuration for GPU PLL0 */
  292. gpu_pll_config.l = 0x29;
  293. gpu_pll_config.alpha_hi = 0xaa;
  294. clk_alpha_pll_configure(&gpu_pll0_pll_out_main, regmap, &gpu_pll_config);
  295. /* 740MHz configuration for GPU PLL1 */
  296. gpu_pll_config.l = 0x26;
  297. gpu_pll_config.alpha_hi = 0x8a;
  298. clk_alpha_pll_configure(&gpu_pll1_pll_out_main, regmap, &gpu_pll_config);
  299. return qcom_cc_really_probe(&pdev->dev, &gpucc_sdm660_desc, regmap);
  300. }
  301. static struct platform_driver gpucc_sdm660_driver = {
  302. .probe = gpucc_sdm660_probe,
  303. .driver = {
  304. .name = "gpucc-sdm660",
  305. .of_match_table = gpucc_sdm660_match_table,
  306. },
  307. };
  308. module_platform_driver(gpucc_sdm660_driver);
  309. MODULE_DESCRIPTION("Qualcomm SDM630/SDM660 GPUCC Driver");
  310. MODULE_LICENSE("GPL v2");