gpucc-sc7280.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/clk-provider.h>
  7. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/regmap.h>
  10. #include <dt-bindings/clock/qcom,gpucc-sc7280.h>
  11. #include "clk-alpha-pll.h"
  12. #include "clk-branch.h"
  13. #include "clk-rcg.h"
  14. #include "clk-regmap-divider.h"
  15. #include "common.h"
  16. #include "reset.h"
  17. #include "gdsc.h"
  18. enum {
  19. P_BI_TCXO,
  20. P_GCC_GPU_GPLL0_CLK_SRC,
  21. P_GCC_GPU_GPLL0_DIV_CLK_SRC,
  22. P_GPU_CC_PLL0_OUT_MAIN,
  23. P_GPU_CC_PLL1_OUT_MAIN,
  24. };
  25. static const struct pll_vco lucid_vco[] = {
  26. { 249600000, 2000000000, 0 },
  27. };
  28. static struct clk_alpha_pll gpu_cc_pll0 = {
  29. .offset = 0x0,
  30. .vco_table = lucid_vco,
  31. .num_vco = ARRAY_SIZE(lucid_vco),
  32. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
  33. .clkr = {
  34. .hw.init = &(struct clk_init_data){
  35. .name = "gpu_cc_pll0",
  36. .parent_data = &(const struct clk_parent_data){
  37. .fw_name = "bi_tcxo",
  38. },
  39. .num_parents = 1,
  40. .ops = &clk_alpha_pll_lucid_ops,
  41. },
  42. },
  43. };
  44. /* 500MHz Configuration */
  45. static const struct alpha_pll_config gpu_cc_pll1_config = {
  46. .l = 0x1A,
  47. .alpha = 0xAAA,
  48. .config_ctl_val = 0x20485699,
  49. .config_ctl_hi_val = 0x00002261,
  50. .config_ctl_hi1_val = 0x329A299C,
  51. .user_ctl_val = 0x00000001,
  52. .user_ctl_hi_val = 0x00000805,
  53. .user_ctl_hi1_val = 0x00000000,
  54. };
  55. static struct clk_alpha_pll gpu_cc_pll1 = {
  56. .offset = 0x100,
  57. .vco_table = lucid_vco,
  58. .num_vco = ARRAY_SIZE(lucid_vco),
  59. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
  60. .clkr = {
  61. .hw.init = &(struct clk_init_data){
  62. .name = "gpu_cc_pll1",
  63. .parent_data = &(const struct clk_parent_data){
  64. .fw_name = "bi_tcxo",
  65. },
  66. .num_parents = 1,
  67. .ops = &clk_alpha_pll_lucid_ops,
  68. },
  69. },
  70. };
  71. static const struct parent_map gpu_cc_parent_map_0[] = {
  72. { P_BI_TCXO, 0 },
  73. { P_GPU_CC_PLL0_OUT_MAIN, 1 },
  74. { P_GPU_CC_PLL1_OUT_MAIN, 3 },
  75. { P_GCC_GPU_GPLL0_CLK_SRC, 5 },
  76. { P_GCC_GPU_GPLL0_DIV_CLK_SRC, 6 },
  77. };
  78. static const struct clk_parent_data gpu_cc_parent_data_0[] = {
  79. { .fw_name = "bi_tcxo" },
  80. { .hw = &gpu_cc_pll0.clkr.hw },
  81. { .hw = &gpu_cc_pll1.clkr.hw },
  82. { .fw_name = "gcc_gpu_gpll0_clk_src" },
  83. { .fw_name = "gcc_gpu_gpll0_div_clk_src" },
  84. };
  85. static const struct parent_map gpu_cc_parent_map_1[] = {
  86. { P_BI_TCXO, 0 },
  87. { P_GPU_CC_PLL1_OUT_MAIN, 3 },
  88. { P_GCC_GPU_GPLL0_CLK_SRC, 5 },
  89. { P_GCC_GPU_GPLL0_DIV_CLK_SRC, 6 },
  90. };
  91. static const struct clk_parent_data gpu_cc_parent_data_1[] = {
  92. { .fw_name = "bi_tcxo", },
  93. { .hw = &gpu_cc_pll1.clkr.hw },
  94. { .fw_name = "gcc_gpu_gpll0_clk_src", },
  95. { .fw_name = "gcc_gpu_gpll0_div_clk_src", },
  96. };
  97. static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src[] = {
  98. F(19200000, P_BI_TCXO, 1, 0, 0),
  99. F(200000000, P_GCC_GPU_GPLL0_DIV_CLK_SRC, 1.5, 0, 0),
  100. F(500000000, P_GPU_CC_PLL1_OUT_MAIN, 1, 0, 0),
  101. { }
  102. };
  103. static struct clk_rcg2 gpu_cc_gmu_clk_src = {
  104. .cmd_rcgr = 0x1120,
  105. .mnd_width = 0,
  106. .hid_width = 5,
  107. .parent_map = gpu_cc_parent_map_0,
  108. .freq_tbl = ftbl_gpu_cc_gmu_clk_src,
  109. .clkr.hw.init = &(struct clk_init_data){
  110. .name = "gpu_cc_gmu_clk_src",
  111. .parent_data = gpu_cc_parent_data_0,
  112. .num_parents = ARRAY_SIZE(gpu_cc_parent_data_0),
  113. .ops = &clk_rcg2_shared_ops,
  114. },
  115. };
  116. static const struct freq_tbl ftbl_gpu_cc_hub_clk_src[] = {
  117. F(150000000, P_GCC_GPU_GPLL0_DIV_CLK_SRC, 2, 0, 0),
  118. F(240000000, P_GCC_GPU_GPLL0_CLK_SRC, 2.5, 0, 0),
  119. F(300000000, P_GCC_GPU_GPLL0_CLK_SRC, 2, 0, 0),
  120. { }
  121. };
  122. static struct clk_rcg2 gpu_cc_hub_clk_src = {
  123. .cmd_rcgr = 0x117c,
  124. .mnd_width = 0,
  125. .hid_width = 5,
  126. .parent_map = gpu_cc_parent_map_1,
  127. .freq_tbl = ftbl_gpu_cc_hub_clk_src,
  128. .clkr.hw.init = &(struct clk_init_data){
  129. .name = "gpu_cc_hub_clk_src",
  130. .parent_data = gpu_cc_parent_data_1,
  131. .num_parents = ARRAY_SIZE(gpu_cc_parent_data_1),
  132. .ops = &clk_rcg2_shared_ops,
  133. },
  134. };
  135. static struct clk_regmap_div gpu_cc_hub_ahb_div_clk_src = {
  136. .reg = 0x11c0,
  137. .shift = 0,
  138. .width = 4,
  139. .clkr.hw.init = &(struct clk_init_data) {
  140. .name = "gpu_cc_hub_ahb_div_clk_src",
  141. .parent_hws = (const struct clk_hw*[]){
  142. &gpu_cc_hub_clk_src.clkr.hw,
  143. },
  144. .num_parents = 1,
  145. .flags = CLK_SET_RATE_PARENT,
  146. .ops = &clk_regmap_div_ro_ops,
  147. },
  148. };
  149. static struct clk_regmap_div gpu_cc_hub_cx_int_div_clk_src = {
  150. .reg = 0x11bc,
  151. .shift = 0,
  152. .width = 4,
  153. .clkr.hw.init = &(struct clk_init_data) {
  154. .name = "gpu_cc_hub_cx_int_div_clk_src",
  155. .parent_hws = (const struct clk_hw*[]){
  156. &gpu_cc_hub_clk_src.clkr.hw,
  157. },
  158. .num_parents = 1,
  159. .flags = CLK_SET_RATE_PARENT,
  160. .ops = &clk_regmap_div_ro_ops,
  161. },
  162. };
  163. static struct clk_branch gpu_cc_ahb_clk = {
  164. .halt_reg = 0x1078,
  165. .halt_check = BRANCH_HALT_DELAY,
  166. .clkr = {
  167. .enable_reg = 0x1078,
  168. .enable_mask = BIT(0),
  169. .hw.init = &(struct clk_init_data){
  170. .name = "gpu_cc_ahb_clk",
  171. .parent_hws = (const struct clk_hw*[]){
  172. &gpu_cc_hub_ahb_div_clk_src.clkr.hw,
  173. },
  174. .num_parents = 1,
  175. .flags = CLK_SET_RATE_PARENT,
  176. .ops = &clk_branch2_ops,
  177. },
  178. },
  179. };
  180. static struct clk_branch gpu_cc_crc_ahb_clk = {
  181. .halt_reg = 0x107c,
  182. .halt_check = BRANCH_HALT_VOTED,
  183. .clkr = {
  184. .enable_reg = 0x107c,
  185. .enable_mask = BIT(0),
  186. .hw.init = &(struct clk_init_data){
  187. .name = "gpu_cc_crc_ahb_clk",
  188. .parent_hws = (const struct clk_hw*[]){
  189. &gpu_cc_hub_ahb_div_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 gpu_cc_cx_gmu_clk = {
  198. .halt_reg = 0x1098,
  199. .halt_check = BRANCH_HALT,
  200. .clkr = {
  201. .enable_reg = 0x1098,
  202. .enable_mask = BIT(0),
  203. .hw.init = &(struct clk_init_data){
  204. .name = "gpu_cc_cx_gmu_clk",
  205. .parent_hws = (const struct clk_hw*[]){
  206. &gpu_cc_gmu_clk_src.clkr.hw,
  207. },
  208. .num_parents = 1,
  209. .flags = CLK_SET_RATE_PARENT,
  210. .ops = &clk_branch2_aon_ops,
  211. },
  212. },
  213. };
  214. static struct clk_branch gpu_cc_cx_snoc_dvm_clk = {
  215. .halt_reg = 0x108c,
  216. .halt_check = BRANCH_HALT_VOTED,
  217. .clkr = {
  218. .enable_reg = 0x108c,
  219. .enable_mask = BIT(0),
  220. .hw.init = &(struct clk_init_data){
  221. .name = "gpu_cc_cx_snoc_dvm_clk",
  222. .ops = &clk_branch2_ops,
  223. },
  224. },
  225. };
  226. static struct clk_branch gpu_cc_cxo_aon_clk = {
  227. .halt_reg = 0x1004,
  228. .halt_check = BRANCH_HALT_VOTED,
  229. .clkr = {
  230. .enable_reg = 0x1004,
  231. .enable_mask = BIT(0),
  232. .hw.init = &(struct clk_init_data){
  233. .name = "gpu_cc_cxo_aon_clk",
  234. .ops = &clk_branch2_ops,
  235. },
  236. },
  237. };
  238. static struct clk_branch gpu_cc_cxo_clk = {
  239. .halt_reg = 0x109c,
  240. .halt_check = BRANCH_HALT,
  241. .clkr = {
  242. .enable_reg = 0x109c,
  243. .enable_mask = BIT(0),
  244. .hw.init = &(struct clk_init_data){
  245. .name = "gpu_cc_cxo_clk",
  246. .ops = &clk_branch2_aon_ops,
  247. },
  248. },
  249. };
  250. static struct clk_branch gpu_cc_gx_gmu_clk = {
  251. .halt_reg = 0x1064,
  252. .halt_check = BRANCH_HALT,
  253. .clkr = {
  254. .enable_reg = 0x1064,
  255. .enable_mask = BIT(0),
  256. .hw.init = &(struct clk_init_data){
  257. .name = "gpu_cc_gx_gmu_clk",
  258. .parent_hws = (const struct clk_hw*[]){
  259. &gpu_cc_gmu_clk_src.clkr.hw,
  260. },
  261. .num_parents = 1,
  262. .flags = CLK_SET_RATE_PARENT,
  263. .ops = &clk_branch2_ops,
  264. },
  265. },
  266. };
  267. static struct clk_branch gpu_cc_hlos1_vote_gpu_smmu_clk = {
  268. .halt_reg = 0x5000,
  269. .halt_check = BRANCH_VOTED,
  270. .clkr = {
  271. .enable_reg = 0x5000,
  272. .enable_mask = BIT(0),
  273. .hw.init = &(struct clk_init_data){
  274. .name = "gpu_cc_hlos1_vote_gpu_smmu_clk",
  275. .ops = &clk_branch2_ops,
  276. },
  277. },
  278. };
  279. static struct clk_branch gpu_cc_hub_aon_clk = {
  280. .halt_reg = 0x1178,
  281. .halt_check = BRANCH_HALT,
  282. .clkr = {
  283. .enable_reg = 0x1178,
  284. .enable_mask = BIT(0),
  285. .hw.init = &(struct clk_init_data){
  286. .name = "gpu_cc_hub_aon_clk",
  287. .parent_hws = (const struct clk_hw*[]){
  288. &gpu_cc_hub_clk_src.clkr.hw,
  289. },
  290. .num_parents = 1,
  291. .flags = CLK_SET_RATE_PARENT,
  292. .ops = &clk_branch2_aon_ops,
  293. },
  294. },
  295. };
  296. static struct clk_branch gpu_cc_hub_cx_int_clk = {
  297. .halt_reg = 0x1204,
  298. .halt_check = BRANCH_HALT,
  299. .clkr = {
  300. .enable_reg = 0x1204,
  301. .enable_mask = BIT(0),
  302. .hw.init = &(struct clk_init_data){
  303. .name = "gpu_cc_hub_cx_int_clk",
  304. .parent_hws = (const struct clk_hw*[]){
  305. &gpu_cc_hub_cx_int_div_clk_src.clkr.hw,
  306. },
  307. .num_parents = 1,
  308. .flags = CLK_SET_RATE_PARENT,
  309. .ops = &clk_branch2_aon_ops,
  310. },
  311. },
  312. };
  313. static struct clk_branch gpu_cc_mnd1x_0_gfx3d_clk = {
  314. .halt_reg = 0x802c,
  315. .halt_check = BRANCH_HALT_SKIP,
  316. .clkr = {
  317. .enable_reg = 0x802c,
  318. .enable_mask = BIT(0),
  319. .hw.init = &(struct clk_init_data){
  320. .name = "gpu_cc_mnd1x_0_gfx3d_clk",
  321. .ops = &clk_branch2_ops,
  322. },
  323. },
  324. };
  325. static struct clk_branch gpu_cc_mnd1x_1_gfx3d_clk = {
  326. .halt_reg = 0x8030,
  327. .halt_check = BRANCH_HALT_SKIP,
  328. .clkr = {
  329. .enable_reg = 0x8030,
  330. .enable_mask = BIT(0),
  331. .hw.init = &(struct clk_init_data){
  332. .name = "gpu_cc_mnd1x_1_gfx3d_clk",
  333. .ops = &clk_branch2_ops,
  334. },
  335. },
  336. };
  337. static struct clk_branch gpu_cc_sleep_clk = {
  338. .halt_reg = 0x1090,
  339. .halt_check = BRANCH_HALT_VOTED,
  340. .clkr = {
  341. .enable_reg = 0x1090,
  342. .enable_mask = BIT(0),
  343. .hw.init = &(struct clk_init_data){
  344. .name = "gpu_cc_sleep_clk",
  345. .ops = &clk_branch2_ops,
  346. },
  347. },
  348. };
  349. static struct gdsc cx_gdsc = {
  350. .gdscr = 0x106c,
  351. .en_rest_wait_val = 0x2,
  352. .en_few_wait_val = 0x2,
  353. .clk_dis_wait_val = 0x2,
  354. .gds_hw_ctrl = 0x1540,
  355. .pd = {
  356. .name = "cx_gdsc",
  357. },
  358. .pwrsts = PWRSTS_OFF_ON,
  359. .flags = VOTABLE | RETAIN_FF_ENABLE,
  360. };
  361. static struct gdsc gx_gdsc = {
  362. .gdscr = 0x100c,
  363. .en_rest_wait_val = 0x2,
  364. .en_few_wait_val = 0x2,
  365. .clk_dis_wait_val = 0x2,
  366. .clamp_io_ctrl = 0x1508,
  367. .pd = {
  368. .name = "gx_gdsc",
  369. .power_on = gdsc_gx_do_nothing_enable,
  370. },
  371. .pwrsts = PWRSTS_OFF_ON,
  372. .flags = CLAMP_IO | RETAIN_FF_ENABLE,
  373. };
  374. static struct gdsc *gpu_cc_sc7180_gdscs[] = {
  375. [GPU_CC_CX_GDSC] = &cx_gdsc,
  376. [GPU_CC_GX_GDSC] = &gx_gdsc,
  377. };
  378. static struct clk_regmap *gpu_cc_sc7280_clocks[] = {
  379. [GPU_CC_AHB_CLK] = &gpu_cc_ahb_clk.clkr,
  380. [GPU_CC_CRC_AHB_CLK] = &gpu_cc_crc_ahb_clk.clkr,
  381. [GPU_CC_CX_GMU_CLK] = &gpu_cc_cx_gmu_clk.clkr,
  382. [GPU_CC_CX_SNOC_DVM_CLK] = &gpu_cc_cx_snoc_dvm_clk.clkr,
  383. [GPU_CC_CXO_AON_CLK] = &gpu_cc_cxo_aon_clk.clkr,
  384. [GPU_CC_CXO_CLK] = &gpu_cc_cxo_clk.clkr,
  385. [GPU_CC_GMU_CLK_SRC] = &gpu_cc_gmu_clk_src.clkr,
  386. [GPU_CC_GX_GMU_CLK] = &gpu_cc_gx_gmu_clk.clkr,
  387. [GPU_CC_HLOS1_VOTE_GPU_SMMU_CLK] = &gpu_cc_hlos1_vote_gpu_smmu_clk.clkr,
  388. [GPU_CC_HUB_AHB_DIV_CLK_SRC] = &gpu_cc_hub_ahb_div_clk_src.clkr,
  389. [GPU_CC_HUB_AON_CLK] = &gpu_cc_hub_aon_clk.clkr,
  390. [GPU_CC_HUB_CLK_SRC] = &gpu_cc_hub_clk_src.clkr,
  391. [GPU_CC_HUB_CX_INT_CLK] = &gpu_cc_hub_cx_int_clk.clkr,
  392. [GPU_CC_HUB_CX_INT_DIV_CLK_SRC] = &gpu_cc_hub_cx_int_div_clk_src.clkr,
  393. [GPU_CC_MND1X_0_GFX3D_CLK] = &gpu_cc_mnd1x_0_gfx3d_clk.clkr,
  394. [GPU_CC_MND1X_1_GFX3D_CLK] = &gpu_cc_mnd1x_1_gfx3d_clk.clkr,
  395. [GPU_CC_PLL0] = &gpu_cc_pll0.clkr,
  396. [GPU_CC_PLL1] = &gpu_cc_pll1.clkr,
  397. [GPU_CC_SLEEP_CLK] = &gpu_cc_sleep_clk.clkr,
  398. };
  399. static const struct regmap_config gpu_cc_sc7280_regmap_config = {
  400. .reg_bits = 32,
  401. .reg_stride = 4,
  402. .val_bits = 32,
  403. .max_register = 0x8030,
  404. .fast_io = true,
  405. };
  406. static const struct qcom_cc_desc gpu_cc_sc7280_desc = {
  407. .config = &gpu_cc_sc7280_regmap_config,
  408. .clks = gpu_cc_sc7280_clocks,
  409. .num_clks = ARRAY_SIZE(gpu_cc_sc7280_clocks),
  410. .gdscs = gpu_cc_sc7180_gdscs,
  411. .num_gdscs = ARRAY_SIZE(gpu_cc_sc7180_gdscs),
  412. };
  413. static const struct of_device_id gpu_cc_sc7280_match_table[] = {
  414. { .compatible = "qcom,sc7280-gpucc" },
  415. { }
  416. };
  417. MODULE_DEVICE_TABLE(of, gpu_cc_sc7280_match_table);
  418. static int gpu_cc_sc7280_probe(struct platform_device *pdev)
  419. {
  420. struct regmap *regmap;
  421. regmap = qcom_cc_map(pdev, &gpu_cc_sc7280_desc);
  422. if (IS_ERR(regmap))
  423. return PTR_ERR(regmap);
  424. clk_lucid_pll_configure(&gpu_cc_pll1, regmap, &gpu_cc_pll1_config);
  425. /* Keep some clocks always-on */
  426. qcom_branch_set_clk_en(regmap, 0x1170); /* GPU_CC_CB_CLK */
  427. qcom_branch_set_clk_en(regmap, 0x1098); /* GPUCC_CX_GMU_CLK */
  428. regmap_update_bits(regmap, 0x1098, BIT(13), BIT(13));
  429. return qcom_cc_really_probe(&pdev->dev, &gpu_cc_sc7280_desc, regmap);
  430. }
  431. static struct platform_driver gpu_cc_sc7280_driver = {
  432. .probe = gpu_cc_sc7280_probe,
  433. .driver = {
  434. .name = "gpu_cc-sc7280",
  435. .of_match_table = gpu_cc_sc7280_match_table,
  436. },
  437. };
  438. module_platform_driver(gpu_cc_sc7280_driver);
  439. MODULE_DESCRIPTION("QTI GPU_CC SC7280 Driver");
  440. MODULE_LICENSE("GPL v2");