gpucc-sc7280.c 12 KB

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