gpucc-sc8280xp.c 11 KB

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