gpucc-msm8998.c 8.5 KB

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