gpucc-sdm660.c 8.5 KB

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