gpucc-sc7280.c 12 KB

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