gpucc-msm8998.c 8.5 KB

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