gpucc-sc8280xp.c 12 KB

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