gpucc-sm6115.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023, Linaro Limited
  5. */
  6. #include <linux/clk-provider.h>
  7. #include <linux/mod_devicetable.h>
  8. #include <linux/module.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/regmap.h>
  11. #include <dt-bindings/clock/qcom,sm6115-gpucc.h>
  12. #include "clk-alpha-pll.h"
  13. #include "clk-branch.h"
  14. #include "clk-rcg.h"
  15. #include "clk-regmap.h"
  16. #include "clk-regmap-divider.h"
  17. #include "clk-regmap-mux.h"
  18. #include "clk-regmap-phy-mux.h"
  19. #include "gdsc.h"
  20. #include "reset.h"
  21. enum {
  22. DT_BI_TCXO,
  23. DT_GCC_GPU_GPLL0_CLK_SRC,
  24. DT_GCC_GPU_GPLL0_DIV_CLK_SRC,
  25. };
  26. enum {
  27. P_BI_TCXO,
  28. P_GPLL0_OUT_MAIN,
  29. P_GPLL0_OUT_MAIN_DIV,
  30. P_GPU_CC_PLL0_OUT_AUX2,
  31. P_GPU_CC_PLL0_OUT_MAIN,
  32. P_GPU_CC_PLL1_OUT_AUX,
  33. P_GPU_CC_PLL1_OUT_MAIN,
  34. };
  35. static const struct pll_vco default_vco[] = {
  36. { 1000000000, 2000000000, 0 },
  37. };
  38. static const struct pll_vco pll1_vco[] = {
  39. { 500000000, 1000000000, 2 },
  40. };
  41. static const struct alpha_pll_config gpu_cc_pll0_config = {
  42. .l = 0x3e,
  43. .alpha = 0,
  44. .alpha_hi = 0x80,
  45. .vco_val = 0x0 << 20,
  46. .vco_mask = GENMASK(21, 20),
  47. .alpha_en_mask = BIT(24),
  48. .main_output_mask = BIT(0),
  49. .aux_output_mask = BIT(1),
  50. .aux2_output_mask = BIT(2),
  51. .config_ctl_val = 0x4001055b,
  52. .test_ctl_hi1_val = 0x1,
  53. };
  54. /* 1200MHz configuration */
  55. static struct clk_alpha_pll gpu_cc_pll0 = {
  56. .offset = 0x0,
  57. .vco_table = default_vco,
  58. .num_vco = ARRAY_SIZE(default_vco),
  59. .flags = SUPPORTS_DYNAMIC_UPDATE,
  60. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
  61. .clkr = {
  62. .hw.init = &(struct clk_init_data){
  63. .name = "gpu_cc_pll0",
  64. .parent_data = &(const struct clk_parent_data){
  65. .index = DT_BI_TCXO,
  66. },
  67. .num_parents = 1,
  68. .ops = &clk_alpha_pll_ops,
  69. },
  70. },
  71. };
  72. static const struct clk_div_table post_div_table_gpu_cc_pll0_out_aux2[] = {
  73. { 0x0, 1 },
  74. { }
  75. };
  76. static struct clk_alpha_pll_postdiv gpu_cc_pll0_out_aux2 = {
  77. .offset = 0x0,
  78. .post_div_shift = 8,
  79. .post_div_table = post_div_table_gpu_cc_pll0_out_aux2,
  80. .num_post_div = ARRAY_SIZE(post_div_table_gpu_cc_pll0_out_aux2),
  81. .width = 4,
  82. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
  83. .clkr.hw.init = &(struct clk_init_data){
  84. .name = "gpu_cc_pll0_out_aux2",
  85. .parent_hws = (const struct clk_hw*[]) {
  86. &gpu_cc_pll0.clkr.hw,
  87. },
  88. .num_parents = 1,
  89. .flags = CLK_SET_RATE_PARENT,
  90. .ops = &clk_alpha_pll_postdiv_ops,
  91. },
  92. };
  93. /* 640MHz configuration */
  94. static const struct alpha_pll_config gpu_cc_pll1_config = {
  95. .l = 0x21,
  96. .alpha = 0x55555555,
  97. .alpha_hi = 0x55,
  98. .alpha_en_mask = BIT(24),
  99. .vco_val = 0x2 << 20,
  100. .vco_mask = GENMASK(21, 20),
  101. .main_output_mask = BIT(0),
  102. .aux_output_mask = BIT(1),
  103. .config_ctl_val = 0x4001055b,
  104. .test_ctl_hi1_val = 0x1,
  105. };
  106. static struct clk_alpha_pll gpu_cc_pll1 = {
  107. .offset = 0x100,
  108. .vco_table = pll1_vco,
  109. .num_vco = ARRAY_SIZE(pll1_vco),
  110. .flags = SUPPORTS_DYNAMIC_UPDATE,
  111. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
  112. .clkr = {
  113. .hw.init = &(struct clk_init_data){
  114. .name = "gpu_cc_pll1",
  115. .parent_data = &(const struct clk_parent_data){
  116. .index = DT_BI_TCXO,
  117. },
  118. .num_parents = 1,
  119. .ops = &clk_alpha_pll_ops,
  120. },
  121. },
  122. };
  123. static const struct clk_div_table post_div_table_gpu_cc_pll1_out_aux[] = {
  124. { 0x0, 1 },
  125. { }
  126. };
  127. static struct clk_alpha_pll_postdiv gpu_cc_pll1_out_aux = {
  128. .offset = 0x100,
  129. .post_div_shift = 15,
  130. .post_div_table = post_div_table_gpu_cc_pll1_out_aux,
  131. .num_post_div = ARRAY_SIZE(post_div_table_gpu_cc_pll1_out_aux),
  132. .width = 3,
  133. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
  134. .clkr.hw.init = &(struct clk_init_data){
  135. .name = "gpu_cc_pll1_out_aux",
  136. .parent_hws = (const struct clk_hw*[]) {
  137. &gpu_cc_pll1.clkr.hw,
  138. },
  139. .num_parents = 1,
  140. .flags = CLK_SET_RATE_PARENT,
  141. .ops = &clk_alpha_pll_postdiv_ops,
  142. },
  143. };
  144. static const struct parent_map gpu_cc_parent_map_0[] = {
  145. { P_BI_TCXO, 0 },
  146. { P_GPU_CC_PLL0_OUT_MAIN, 1 },
  147. { P_GPU_CC_PLL1_OUT_MAIN, 3 },
  148. { P_GPLL0_OUT_MAIN, 5 },
  149. { P_GPLL0_OUT_MAIN_DIV, 6 },
  150. };
  151. static const struct clk_parent_data gpu_cc_parent_data_0[] = {
  152. { .index = P_BI_TCXO },
  153. { .hw = &gpu_cc_pll0.clkr.hw },
  154. { .hw = &gpu_cc_pll1.clkr.hw },
  155. { .index = DT_GCC_GPU_GPLL0_CLK_SRC },
  156. { .index = DT_GCC_GPU_GPLL0_DIV_CLK_SRC },
  157. };
  158. static const struct parent_map gpu_cc_parent_map_1[] = {
  159. { P_BI_TCXO, 0 },
  160. { P_GPU_CC_PLL0_OUT_AUX2, 2 },
  161. { P_GPU_CC_PLL1_OUT_AUX, 3 },
  162. { P_GPLL0_OUT_MAIN, 5 },
  163. };
  164. static const struct clk_parent_data gpu_cc_parent_data_1[] = {
  165. { .index = P_BI_TCXO },
  166. { .hw = &gpu_cc_pll0_out_aux2.clkr.hw },
  167. { .hw = &gpu_cc_pll1_out_aux.clkr.hw },
  168. { .index = DT_GCC_GPU_GPLL0_CLK_SRC },
  169. };
  170. static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src[] = {
  171. F(200000000, P_GPLL0_OUT_MAIN, 3, 0, 0),
  172. { }
  173. };
  174. static struct clk_rcg2 gpu_cc_gmu_clk_src = {
  175. .cmd_rcgr = 0x1120,
  176. .mnd_width = 0,
  177. .hid_width = 5,
  178. .parent_map = gpu_cc_parent_map_0,
  179. .freq_tbl = ftbl_gpu_cc_gmu_clk_src,
  180. .clkr.hw.init = &(struct clk_init_data){
  181. .name = "gpu_cc_gmu_clk_src",
  182. .parent_data = gpu_cc_parent_data_0,
  183. .num_parents = ARRAY_SIZE(gpu_cc_parent_data_0),
  184. .flags = CLK_SET_RATE_PARENT,
  185. .ops = &clk_rcg2_shared_ops,
  186. },
  187. };
  188. static const struct freq_tbl ftbl_gpu_cc_gx_gfx3d_clk_src[] = {
  189. F(320000000, P_GPU_CC_PLL1_OUT_AUX, 2, 0, 0),
  190. F(465000000, P_GPU_CC_PLL1_OUT_AUX, 2, 0, 0),
  191. F(600000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  192. F(745000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  193. F(820000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  194. F(900000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  195. F(950000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  196. F(980000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  197. { }
  198. };
  199. static struct clk_rcg2 gpu_cc_gx_gfx3d_clk_src = {
  200. .cmd_rcgr = 0x101c,
  201. .mnd_width = 0,
  202. .hid_width = 5,
  203. .parent_map = gpu_cc_parent_map_1,
  204. .freq_tbl = ftbl_gpu_cc_gx_gfx3d_clk_src,
  205. .clkr.hw.init = &(struct clk_init_data){
  206. .name = "gpu_cc_gx_gfx3d_clk_src",
  207. .parent_data = gpu_cc_parent_data_1,
  208. .num_parents = ARRAY_SIZE(gpu_cc_parent_data_1),
  209. .flags = CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
  210. .ops = &clk_rcg2_ops,
  211. },
  212. };
  213. static struct clk_branch gpu_cc_ahb_clk = {
  214. .halt_reg = 0x1078,
  215. .halt_check = BRANCH_HALT_DELAY,
  216. .clkr = {
  217. .enable_reg = 0x1078,
  218. .enable_mask = BIT(0),
  219. .hw.init = &(struct clk_init_data){
  220. .name = "gpu_cc_ahb_clk",
  221. .flags = CLK_IS_CRITICAL,
  222. .ops = &clk_branch2_ops,
  223. },
  224. },
  225. };
  226. static struct clk_branch gpu_cc_crc_ahb_clk = {
  227. .halt_reg = 0x107c,
  228. .halt_check = BRANCH_HALT_DELAY,
  229. .clkr = {
  230. .enable_reg = 0x107c,
  231. .enable_mask = BIT(0),
  232. .hw.init = &(struct clk_init_data){
  233. .name = "gpu_cc_crc_ahb_clk",
  234. .ops = &clk_branch2_ops,
  235. },
  236. },
  237. };
  238. static struct clk_branch gpu_cc_cx_gfx3d_clk = {
  239. .halt_reg = 0x10a4,
  240. .halt_check = BRANCH_HALT_DELAY,
  241. .clkr = {
  242. .enable_reg = 0x10a4,
  243. .enable_mask = BIT(0),
  244. .hw.init = &(struct clk_init_data){
  245. .name = "gpu_cc_cx_gfx3d_clk",
  246. .parent_data = &(const struct clk_parent_data){
  247. .hw = &gpu_cc_gx_gfx3d_clk_src.clkr.hw,
  248. },
  249. .num_parents = 1,
  250. .flags = CLK_SET_RATE_PARENT,
  251. .ops = &clk_branch2_ops,
  252. },
  253. },
  254. };
  255. static struct clk_branch gpu_cc_cx_gmu_clk = {
  256. .halt_reg = 0x1098,
  257. .halt_check = BRANCH_HALT,
  258. .clkr = {
  259. .enable_reg = 0x1098,
  260. .enable_mask = BIT(0),
  261. .hw.init = &(struct clk_init_data){
  262. .name = "gpu_cc_cx_gmu_clk",
  263. .parent_data = &(const struct clk_parent_data){
  264. .hw = &gpu_cc_gmu_clk_src.clkr.hw,
  265. },
  266. .num_parents = 1,
  267. .flags = CLK_SET_RATE_PARENT,
  268. .ops = &clk_branch2_ops,
  269. },
  270. },
  271. };
  272. static struct clk_branch gpu_cc_cx_snoc_dvm_clk = {
  273. .halt_reg = 0x108c,
  274. .halt_check = BRANCH_HALT_DELAY,
  275. .clkr = {
  276. .enable_reg = 0x108c,
  277. .enable_mask = BIT(0),
  278. .hw.init = &(struct clk_init_data){
  279. .name = "gpu_cc_cx_snoc_dvm_clk",
  280. .ops = &clk_branch2_ops,
  281. },
  282. },
  283. };
  284. static struct clk_branch gpu_cc_cxo_aon_clk = {
  285. .halt_reg = 0x1004,
  286. .halt_check = BRANCH_HALT_DELAY,
  287. .clkr = {
  288. .enable_reg = 0x1004,
  289. .enable_mask = BIT(0),
  290. .hw.init = &(struct clk_init_data){
  291. .name = "gpu_cc_cxo_aon_clk",
  292. .ops = &clk_branch2_ops,
  293. },
  294. },
  295. };
  296. static struct clk_branch gpu_cc_cxo_clk = {
  297. .halt_reg = 0x109c,
  298. .halt_check = BRANCH_HALT,
  299. .clkr = {
  300. .enable_reg = 0x109c,
  301. .enable_mask = BIT(0),
  302. .hw.init = &(struct clk_init_data){
  303. .name = "gpu_cc_cxo_clk",
  304. .ops = &clk_branch2_ops,
  305. },
  306. },
  307. };
  308. static struct clk_branch gpu_cc_gx_cxo_clk = {
  309. .halt_reg = 0x1060,
  310. .halt_check = BRANCH_HALT_DELAY,
  311. .clkr = {
  312. .enable_reg = 0x1060,
  313. .enable_mask = BIT(0),
  314. .hw.init = &(struct clk_init_data){
  315. .name = "gpu_cc_gx_cxo_clk",
  316. .flags = CLK_IS_CRITICAL,
  317. .ops = &clk_branch2_ops,
  318. },
  319. },
  320. };
  321. static struct clk_branch gpu_cc_gx_gfx3d_clk = {
  322. .halt_reg = 0x1054,
  323. .halt_check = BRANCH_HALT_SKIP,
  324. .clkr = {
  325. .enable_reg = 0x1054,
  326. .enable_mask = BIT(0),
  327. .hw.init = &(struct clk_init_data){
  328. .name = "gpu_cc_gx_gfx3d_clk",
  329. .parent_data = &(const struct clk_parent_data){
  330. .hw = &gpu_cc_gx_gfx3d_clk_src.clkr.hw,
  331. },
  332. .num_parents = 1,
  333. .flags = CLK_SET_RATE_PARENT,
  334. .ops = &clk_branch2_ops,
  335. },
  336. },
  337. };
  338. static struct clk_branch gpu_cc_sleep_clk = {
  339. .halt_reg = 0x1090,
  340. .halt_check = BRANCH_HALT_DELAY,
  341. .clkr = {
  342. .enable_reg = 0x1090,
  343. .enable_mask = BIT(0),
  344. .hw.init = &(struct clk_init_data){
  345. .name = "gpu_cc_sleep_clk",
  346. .ops = &clk_branch2_ops,
  347. },
  348. },
  349. };
  350. static struct clk_branch gpu_cc_hlos1_vote_gpu_smmu_clk = {
  351. .halt_reg = 0x5000,
  352. .halt_check = BRANCH_VOTED,
  353. .clkr = {
  354. .enable_reg = 0x5000,
  355. .enable_mask = BIT(0),
  356. .hw.init = &(struct clk_init_data){
  357. .name = "gpu_cc_hlos1_vote_gpu_smmu_clk",
  358. .ops = &clk_branch2_ops,
  359. },
  360. },
  361. };
  362. static struct gdsc gpu_cx_gdsc = {
  363. .gdscr = 0x106c,
  364. .gds_hw_ctrl = 0x1540,
  365. .pd = {
  366. .name = "gpu_cx_gdsc",
  367. },
  368. .pwrsts = PWRSTS_OFF_ON,
  369. .flags = VOTABLE,
  370. };
  371. static struct gdsc gpu_gx_gdsc = {
  372. .gdscr = 0x100c,
  373. .clamp_io_ctrl = 0x1508,
  374. .resets = (unsigned int []){ GPU_GX_BCR },
  375. .reset_count = 1,
  376. .pd = {
  377. .name = "gpu_gx_gdsc",
  378. },
  379. .parent = &gpu_cx_gdsc.pd,
  380. .pwrsts = PWRSTS_OFF_ON,
  381. .flags = CLAMP_IO | SW_RESET | VOTABLE,
  382. };
  383. static struct clk_regmap *gpu_cc_sm6115_clocks[] = {
  384. [GPU_CC_AHB_CLK] = &gpu_cc_ahb_clk.clkr,
  385. [GPU_CC_CRC_AHB_CLK] = &gpu_cc_crc_ahb_clk.clkr,
  386. [GPU_CC_CX_GFX3D_CLK] = &gpu_cc_cx_gfx3d_clk.clkr,
  387. [GPU_CC_CX_GMU_CLK] = &gpu_cc_cx_gmu_clk.clkr,
  388. [GPU_CC_CX_SNOC_DVM_CLK] = &gpu_cc_cx_snoc_dvm_clk.clkr,
  389. [GPU_CC_CXO_AON_CLK] = &gpu_cc_cxo_aon_clk.clkr,
  390. [GPU_CC_CXO_CLK] = &gpu_cc_cxo_clk.clkr,
  391. [GPU_CC_GMU_CLK_SRC] = &gpu_cc_gmu_clk_src.clkr,
  392. [GPU_CC_GX_CXO_CLK] = &gpu_cc_gx_cxo_clk.clkr,
  393. [GPU_CC_GX_GFX3D_CLK] = &gpu_cc_gx_gfx3d_clk.clkr,
  394. [GPU_CC_GX_GFX3D_CLK_SRC] = &gpu_cc_gx_gfx3d_clk_src.clkr,
  395. [GPU_CC_PLL0] = &gpu_cc_pll0.clkr,
  396. [GPU_CC_PLL0_OUT_AUX2] = &gpu_cc_pll0_out_aux2.clkr,
  397. [GPU_CC_PLL1] = &gpu_cc_pll1.clkr,
  398. [GPU_CC_PLL1_OUT_AUX] = &gpu_cc_pll1_out_aux.clkr,
  399. [GPU_CC_SLEEP_CLK] = &gpu_cc_sleep_clk.clkr,
  400. [GPU_CC_HLOS1_VOTE_GPU_SMMU_CLK] = &gpu_cc_hlos1_vote_gpu_smmu_clk.clkr,
  401. };
  402. static const struct qcom_reset_map gpu_cc_sm6115_resets[] = {
  403. [GPU_GX_BCR] = { 0x1008 },
  404. };
  405. static struct gdsc *gpu_cc_sm6115_gdscs[] = {
  406. [GPU_CX_GDSC] = &gpu_cx_gdsc,
  407. [GPU_GX_GDSC] = &gpu_gx_gdsc,
  408. };
  409. static const struct regmap_config gpu_cc_sm6115_regmap_config = {
  410. .reg_bits = 32,
  411. .reg_stride = 4,
  412. .val_bits = 32,
  413. .max_register = 0x9000,
  414. .fast_io = true,
  415. };
  416. static const struct qcom_cc_desc gpu_cc_sm6115_desc = {
  417. .config = &gpu_cc_sm6115_regmap_config,
  418. .clks = gpu_cc_sm6115_clocks,
  419. .num_clks = ARRAY_SIZE(gpu_cc_sm6115_clocks),
  420. .resets = gpu_cc_sm6115_resets,
  421. .num_resets = ARRAY_SIZE(gpu_cc_sm6115_resets),
  422. .gdscs = gpu_cc_sm6115_gdscs,
  423. .num_gdscs = ARRAY_SIZE(gpu_cc_sm6115_gdscs),
  424. };
  425. static const struct of_device_id gpu_cc_sm6115_match_table[] = {
  426. { .compatible = "qcom,sm6115-gpucc" },
  427. { }
  428. };
  429. MODULE_DEVICE_TABLE(of, gpu_cc_sm6115_match_table);
  430. static int gpu_cc_sm6115_probe(struct platform_device *pdev)
  431. {
  432. struct regmap *regmap;
  433. regmap = qcom_cc_map(pdev, &gpu_cc_sm6115_desc);
  434. if (IS_ERR(regmap))
  435. return PTR_ERR(regmap);
  436. clk_alpha_pll_configure(&gpu_cc_pll0, regmap, &gpu_cc_pll0_config);
  437. clk_alpha_pll_configure(&gpu_cc_pll1, regmap, &gpu_cc_pll1_config);
  438. /* Set recommended WAKEUP/SLEEP settings for the gpu_cc_cx_gmu_clk */
  439. qcom_branch_set_wakeup(regmap, gpu_cc_cx_gmu_clk, 0xf);
  440. qcom_branch_set_sleep(regmap, gpu_cc_cx_gmu_clk, 0xf);
  441. qcom_branch_set_force_mem_core(regmap, gpu_cc_gx_gfx3d_clk, true);
  442. qcom_branch_set_force_periph_on(regmap, gpu_cc_gx_gfx3d_clk, true);
  443. return qcom_cc_really_probe(&pdev->dev, &gpu_cc_sm6115_desc, regmap);
  444. }
  445. static struct platform_driver gpu_cc_sm6115_driver = {
  446. .probe = gpu_cc_sm6115_probe,
  447. .driver = {
  448. .name = "sm6115-gpucc",
  449. .of_match_table = gpu_cc_sm6115_match_table,
  450. },
  451. };
  452. module_platform_driver(gpu_cc_sm6115_driver);
  453. MODULE_DESCRIPTION("QTI GPU_CC SM6115 Driver");
  454. MODULE_LICENSE("GPL");