gpucc-msm8998.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2019, Jeffrey Hugo
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/bitops.h>
  7. #include <linux/err.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/module.h>
  10. #include <linux/of.h>
  11. #include <linux/clk-provider.h>
  12. #include <linux/regmap.h>
  13. #include <linux/reset-controller.h>
  14. #include <dt-bindings/clock/qcom,gpucc-msm8998.h>
  15. #include "common.h"
  16. #include "clk-regmap.h"
  17. #include "clk-regmap-divider.h"
  18. #include "clk-alpha-pll.h"
  19. #include "clk-rcg.h"
  20. #include "clk-branch.h"
  21. #include "reset.h"
  22. #include "gdsc.h"
  23. enum {
  24. P_XO,
  25. P_GPLL0,
  26. P_GPUPLL0_OUT_EVEN,
  27. };
  28. /* Instead of going directly to the block, XO is routed through this branch */
  29. static struct clk_branch gpucc_cxo_clk = {
  30. .halt_reg = 0x1020,
  31. .clkr = {
  32. .enable_reg = 0x1020,
  33. .enable_mask = BIT(0),
  34. .hw.init = &(struct clk_init_data){
  35. .name = "gpucc_cxo_clk",
  36. .parent_data = &(const struct clk_parent_data){
  37. .fw_name = "xo"
  38. },
  39. .num_parents = 1,
  40. .ops = &clk_branch2_ops,
  41. .flags = CLK_IS_CRITICAL,
  42. },
  43. },
  44. };
  45. static const struct pll_vco fabia_vco[] = {
  46. { 249600000, 2000000000, 0 },
  47. { 125000000, 1000000000, 1 },
  48. };
  49. static const struct clk_div_table post_div_table_fabia_even[] = {
  50. { 0x0, 1 },
  51. { 0x1, 2 },
  52. { 0x3, 4 },
  53. { 0x7, 8 },
  54. { }
  55. };
  56. static struct clk_alpha_pll gpupll0 = {
  57. .offset = 0x0,
  58. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA],
  59. .vco_table = fabia_vco,
  60. .num_vco = ARRAY_SIZE(fabia_vco),
  61. .clkr.hw.init = &(struct clk_init_data){
  62. .name = "gpupll0",
  63. .parent_hws = (const struct clk_hw *[]){ &gpucc_cxo_clk.clkr.hw },
  64. .num_parents = 1,
  65. .ops = &clk_alpha_pll_fabia_ops,
  66. },
  67. };
  68. static struct clk_alpha_pll_postdiv gpupll0_out_even = {
  69. .offset = 0x0,
  70. .post_div_shift = 8,
  71. .post_div_table = post_div_table_fabia_even,
  72. .num_post_div = ARRAY_SIZE(post_div_table_fabia_even),
  73. .width = 4,
  74. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA],
  75. .clkr.hw.init = &(struct clk_init_data){
  76. .name = "gpupll0_out_even",
  77. .parent_hws = (const struct clk_hw *[]){ &gpupll0.clkr.hw },
  78. .num_parents = 1,
  79. .flags = CLK_SET_RATE_PARENT,
  80. .ops = &clk_alpha_pll_postdiv_fabia_ops,
  81. },
  82. };
  83. static const struct parent_map gpu_xo_gpll0_map[] = {
  84. { P_XO, 0 },
  85. { P_GPLL0, 5 },
  86. };
  87. static const struct clk_parent_data gpu_xo_gpll0[] = {
  88. { .hw = &gpucc_cxo_clk.clkr.hw },
  89. { .fw_name = "gpll0", .name = "gcc_gpu_gpll0_clk" },
  90. };
  91. static const struct parent_map gpu_xo_gpupll0_map[] = {
  92. { P_XO, 0 },
  93. { P_GPUPLL0_OUT_EVEN, 1 },
  94. };
  95. static const struct clk_hw *gpu_xo_gpupll0[] = {
  96. &gpucc_cxo_clk.clkr.hw,
  97. &gpupll0_out_even.clkr.hw,
  98. };
  99. static const struct freq_tbl ftbl_rbcpr_clk_src[] = {
  100. F(19200000, P_XO, 1, 0, 0),
  101. F(50000000, P_GPLL0, 12, 0, 0),
  102. { }
  103. };
  104. static struct clk_rcg2 rbcpr_clk_src = {
  105. .cmd_rcgr = 0x1030,
  106. .hid_width = 5,
  107. .parent_map = gpu_xo_gpll0_map,
  108. .freq_tbl = ftbl_rbcpr_clk_src,
  109. .clkr.hw.init = &(struct clk_init_data){
  110. .name = "rbcpr_clk_src",
  111. .parent_data = gpu_xo_gpll0,
  112. .num_parents = ARRAY_SIZE(gpu_xo_gpll0),
  113. .ops = &clk_rcg2_ops,
  114. },
  115. };
  116. static const struct freq_tbl ftbl_gfx3d_clk_src[] = {
  117. { .src = P_GPUPLL0_OUT_EVEN, .pre_div = 3 },
  118. { }
  119. };
  120. static struct clk_rcg2 gfx3d_clk_src = {
  121. .cmd_rcgr = 0x1070,
  122. .hid_width = 5,
  123. .parent_map = gpu_xo_gpupll0_map,
  124. .freq_tbl = ftbl_gfx3d_clk_src,
  125. .clkr.hw.init = &(struct clk_init_data){
  126. .name = "gfx3d_clk_src",
  127. .parent_hws = gpu_xo_gpupll0,
  128. .num_parents = ARRAY_SIZE(gpu_xo_gpupll0),
  129. .ops = &clk_rcg2_ops,
  130. .flags = CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
  131. },
  132. };
  133. static const struct freq_tbl ftbl_rbbmtimer_clk_src[] = {
  134. F(19200000, P_XO, 1, 0, 0),
  135. { }
  136. };
  137. static struct clk_rcg2 rbbmtimer_clk_src = {
  138. .cmd_rcgr = 0x10b0,
  139. .hid_width = 5,
  140. .parent_map = gpu_xo_gpll0_map,
  141. .freq_tbl = ftbl_rbbmtimer_clk_src,
  142. .clkr.hw.init = &(struct clk_init_data){
  143. .name = "rbbmtimer_clk_src",
  144. .parent_data = gpu_xo_gpll0,
  145. .num_parents = ARRAY_SIZE(gpu_xo_gpll0),
  146. .ops = &clk_rcg2_ops,
  147. },
  148. };
  149. static const struct freq_tbl ftbl_gfx3d_isense_clk_src[] = {
  150. F(19200000, P_XO, 1, 0, 0),
  151. F(40000000, P_GPLL0, 15, 0, 0),
  152. F(200000000, P_GPLL0, 3, 0, 0),
  153. F(300000000, P_GPLL0, 2, 0, 0),
  154. { }
  155. };
  156. static struct clk_rcg2 gfx3d_isense_clk_src = {
  157. .cmd_rcgr = 0x1100,
  158. .hid_width = 5,
  159. .parent_map = gpu_xo_gpll0_map,
  160. .freq_tbl = ftbl_gfx3d_isense_clk_src,
  161. .clkr.hw.init = &(struct clk_init_data){
  162. .name = "gfx3d_isense_clk_src",
  163. .parent_data = gpu_xo_gpll0,
  164. .num_parents = ARRAY_SIZE(gpu_xo_gpll0),
  165. .ops = &clk_rcg2_ops,
  166. },
  167. };
  168. static struct clk_branch rbcpr_clk = {
  169. .halt_reg = 0x1054,
  170. .clkr = {
  171. .enable_reg = 0x1054,
  172. .enable_mask = BIT(0),
  173. .hw.init = &(struct clk_init_data){
  174. .name = "rbcpr_clk",
  175. .parent_hws = (const struct clk_hw *[]){ &rbcpr_clk_src.clkr.hw },
  176. .num_parents = 1,
  177. .ops = &clk_branch2_ops,
  178. .flags = CLK_SET_RATE_PARENT,
  179. },
  180. },
  181. };
  182. static struct clk_branch gfx3d_clk = {
  183. .halt_reg = 0x1098,
  184. .clkr = {
  185. .enable_reg = 0x1098,
  186. .enable_mask = BIT(0),
  187. .hw.init = &(struct clk_init_data){
  188. .name = "gfx3d_clk",
  189. .parent_hws = (const struct clk_hw *[]){ &gfx3d_clk_src.clkr.hw },
  190. .num_parents = 1,
  191. .ops = &clk_branch2_ops,
  192. .flags = CLK_SET_RATE_PARENT,
  193. },
  194. },
  195. };
  196. static struct clk_branch rbbmtimer_clk = {
  197. .halt_reg = 0x10d0,
  198. .clkr = {
  199. .enable_reg = 0x10d0,
  200. .enable_mask = BIT(0),
  201. .hw.init = &(struct clk_init_data){
  202. .name = "rbbmtimer_clk",
  203. .parent_hws = (const struct clk_hw *[]){ &rbbmtimer_clk_src.clkr.hw },
  204. .num_parents = 1,
  205. .ops = &clk_branch2_ops,
  206. .flags = CLK_SET_RATE_PARENT,
  207. },
  208. },
  209. };
  210. static struct clk_branch gfx3d_isense_clk = {
  211. .halt_reg = 0x1124,
  212. .clkr = {
  213. .enable_reg = 0x1124,
  214. .enable_mask = BIT(0),
  215. .hw.init = &(struct clk_init_data){
  216. .name = "gfx3d_isense_clk",
  217. .parent_hws = (const struct clk_hw *[]){ &gfx3d_isense_clk_src.clkr.hw },
  218. .num_parents = 1,
  219. .ops = &clk_branch2_ops,
  220. },
  221. },
  222. };
  223. static struct gdsc gpu_cx_gdsc = {
  224. .gdscr = 0x1004,
  225. .gds_hw_ctrl = 0x1008,
  226. .pd = {
  227. .name = "gpu_cx",
  228. },
  229. .pwrsts = PWRSTS_OFF_ON,
  230. .flags = VOTABLE,
  231. };
  232. static struct gdsc gpu_gx_gdsc = {
  233. .gdscr = 0x1094,
  234. .clamp_io_ctrl = 0x130,
  235. .resets = (unsigned int []){ GPU_GX_BCR },
  236. .reset_count = 1,
  237. .cxcs = (unsigned int []){ 0x1098 },
  238. .cxc_count = 1,
  239. .pd = {
  240. .name = "gpu_gx",
  241. },
  242. .parent = &gpu_cx_gdsc.pd,
  243. .pwrsts = PWRSTS_OFF_ON | PWRSTS_RET,
  244. .flags = CLAMP_IO | SW_RESET | AON_RESET | NO_RET_PERIPH,
  245. };
  246. static struct clk_regmap *gpucc_msm8998_clocks[] = {
  247. [GPUPLL0] = &gpupll0.clkr,
  248. [GPUPLL0_OUT_EVEN] = &gpupll0_out_even.clkr,
  249. [RBCPR_CLK_SRC] = &rbcpr_clk_src.clkr,
  250. [GFX3D_CLK_SRC] = &gfx3d_clk_src.clkr,
  251. [RBBMTIMER_CLK_SRC] = &rbbmtimer_clk_src.clkr,
  252. [GFX3D_ISENSE_CLK_SRC] = &gfx3d_isense_clk_src.clkr,
  253. [RBCPR_CLK] = &rbcpr_clk.clkr,
  254. [GFX3D_CLK] = &gfx3d_clk.clkr,
  255. [RBBMTIMER_CLK] = &rbbmtimer_clk.clkr,
  256. [GFX3D_ISENSE_CLK] = &gfx3d_isense_clk.clkr,
  257. [GPUCC_CXO_CLK] = &gpucc_cxo_clk.clkr,
  258. };
  259. static struct gdsc *gpucc_msm8998_gdscs[] = {
  260. [GPU_CX_GDSC] = &gpu_cx_gdsc,
  261. [GPU_GX_GDSC] = &gpu_gx_gdsc,
  262. };
  263. static const struct qcom_reset_map gpucc_msm8998_resets[] = {
  264. [GPU_CX_BCR] = { 0x1000 },
  265. [RBCPR_BCR] = { 0x1050 },
  266. [GPU_GX_BCR] = { 0x1090 },
  267. [GPU_ISENSE_BCR] = { 0x1120 },
  268. };
  269. static const struct regmap_config gpucc_msm8998_regmap_config = {
  270. .reg_bits = 32,
  271. .reg_stride = 4,
  272. .val_bits = 32,
  273. .max_register = 0x9000,
  274. .fast_io = true,
  275. };
  276. static const struct qcom_cc_desc gpucc_msm8998_desc = {
  277. .config = &gpucc_msm8998_regmap_config,
  278. .clks = gpucc_msm8998_clocks,
  279. .num_clks = ARRAY_SIZE(gpucc_msm8998_clocks),
  280. .resets = gpucc_msm8998_resets,
  281. .num_resets = ARRAY_SIZE(gpucc_msm8998_resets),
  282. .gdscs = gpucc_msm8998_gdscs,
  283. .num_gdscs = ARRAY_SIZE(gpucc_msm8998_gdscs),
  284. };
  285. static const struct of_device_id gpucc_msm8998_match_table[] = {
  286. { .compatible = "qcom,msm8998-gpucc" },
  287. { }
  288. };
  289. MODULE_DEVICE_TABLE(of, gpucc_msm8998_match_table);
  290. static int gpucc_msm8998_probe(struct platform_device *pdev)
  291. {
  292. struct regmap *regmap;
  293. regmap = qcom_cc_map(pdev, &gpucc_msm8998_desc);
  294. if (IS_ERR(regmap))
  295. return PTR_ERR(regmap);
  296. /* force periph logic on to avoid perf counter corruption */
  297. regmap_write_bits(regmap, gfx3d_clk.clkr.enable_reg, BIT(13), BIT(13));
  298. /* tweak droop detector (GPUCC_GPU_DD_WRAP_CTRL) to reduce leakage */
  299. regmap_write_bits(regmap, gfx3d_clk.clkr.enable_reg, BIT(0), BIT(0));
  300. return qcom_cc_really_probe(&pdev->dev, &gpucc_msm8998_desc, regmap);
  301. }
  302. static struct platform_driver gpucc_msm8998_driver = {
  303. .probe = gpucc_msm8998_probe,
  304. .driver = {
  305. .name = "gpucc-msm8998",
  306. .of_match_table = gpucc_msm8998_match_table,
  307. },
  308. };
  309. module_platform_driver(gpucc_msm8998_driver);
  310. MODULE_DESCRIPTION("QCOM GPUCC MSM8998 Driver");
  311. MODULE_LICENSE("GPL v2");