gpucc-sdm660.c 8.5 KB

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