gpucc-qcm2290.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2024, Linaro Limited
  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/pm_clock.h>
  11. #include <linux/pm_runtime.h>
  12. #include <linux/regmap.h>
  13. #include <dt-bindings/clock/qcom,qcm2290-gpucc.h>
  14. #include "clk-alpha-pll.h"
  15. #include "clk-branch.h"
  16. #include "clk-rcg.h"
  17. #include "clk-regmap.h"
  18. #include "clk-regmap-divider.h"
  19. #include "clk-regmap-mux.h"
  20. #include "clk-regmap-phy-mux.h"
  21. #include "gdsc.h"
  22. #include "reset.h"
  23. enum {
  24. DT_GCC_AHB_CLK,
  25. DT_BI_TCXO,
  26. DT_GCC_GPU_GPLL0_CLK_SRC,
  27. DT_GCC_GPU_GPLL0_DIV_CLK_SRC,
  28. };
  29. enum {
  30. P_BI_TCXO,
  31. P_GPLL0_OUT_MAIN,
  32. P_GPLL0_OUT_MAIN_DIV,
  33. P_GPU_CC_PLL0_2X_DIV_CLK_SRC,
  34. P_GPU_CC_PLL0_OUT_AUX,
  35. P_GPU_CC_PLL0_OUT_AUX2,
  36. P_GPU_CC_PLL0_OUT_MAIN,
  37. };
  38. static const struct pll_vco huayra_vco[] = {
  39. { 600000000, 3300000000, 0 },
  40. { 600000000, 2200000000, 1 },
  41. };
  42. static const struct alpha_pll_config gpu_cc_pll0_config = {
  43. .l = 0x25,
  44. .config_ctl_val = 0x200d4828,
  45. .config_ctl_hi_val = 0x6,
  46. .test_ctl_val = GENMASK(28, 26),
  47. .test_ctl_hi_val = BIT(14),
  48. .user_ctl_val = 0xf,
  49. };
  50. static struct clk_alpha_pll gpu_cc_pll0 = {
  51. .offset = 0x0,
  52. .vco_table = huayra_vco,
  53. .num_vco = ARRAY_SIZE(huayra_vco),
  54. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_HUAYRA_2290],
  55. .clkr = {
  56. .hw.init = &(struct clk_init_data){
  57. .name = "gpu_cc_pll0",
  58. .parent_data = &(const struct clk_parent_data) {
  59. .index = DT_BI_TCXO,
  60. },
  61. .num_parents = 1,
  62. .ops = &clk_alpha_pll_huayra_ops,
  63. },
  64. },
  65. };
  66. static const struct parent_map gpu_cc_parent_map_0[] = {
  67. { P_BI_TCXO, 0 },
  68. { P_GPU_CC_PLL0_OUT_MAIN, 1 },
  69. { P_GPLL0_OUT_MAIN, 5 },
  70. { P_GPLL0_OUT_MAIN_DIV, 6 },
  71. };
  72. static const struct clk_parent_data gpu_cc_parent_data_0[] = {
  73. { .index = DT_BI_TCXO, },
  74. { .hw = &gpu_cc_pll0.clkr.hw, },
  75. { .index = DT_GCC_GPU_GPLL0_CLK_SRC, },
  76. { .index = DT_GCC_GPU_GPLL0_DIV_CLK_SRC, },
  77. };
  78. static const struct parent_map gpu_cc_parent_map_1[] = {
  79. { P_BI_TCXO, 0 },
  80. { P_GPU_CC_PLL0_2X_DIV_CLK_SRC, 1 },
  81. { P_GPU_CC_PLL0_OUT_AUX2, 2 },
  82. { P_GPU_CC_PLL0_OUT_AUX, 3 },
  83. { P_GPLL0_OUT_MAIN, 5 },
  84. };
  85. static const struct clk_parent_data gpu_cc_parent_data_1[] = {
  86. { .index = DT_BI_TCXO, },
  87. { .hw = &gpu_cc_pll0.clkr.hw, },
  88. { .hw = &gpu_cc_pll0.clkr.hw, },
  89. { .hw = &gpu_cc_pll0.clkr.hw, },
  90. { .index = DT_GCC_GPU_GPLL0_CLK_SRC, },
  91. };
  92. static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src[] = {
  93. F(200000000, P_GPLL0_OUT_MAIN, 3, 0, 0),
  94. { }
  95. };
  96. static struct clk_rcg2 gpu_cc_gmu_clk_src = {
  97. .cmd_rcgr = 0x1120,
  98. .mnd_width = 0,
  99. .hid_width = 5,
  100. .parent_map = gpu_cc_parent_map_0,
  101. .freq_tbl = ftbl_gpu_cc_gmu_clk_src,
  102. .clkr.hw.init = &(struct clk_init_data){
  103. .name = "gpu_cc_gmu_clk_src",
  104. .parent_data = gpu_cc_parent_data_0,
  105. .num_parents = ARRAY_SIZE(gpu_cc_parent_data_0),
  106. .flags = CLK_SET_RATE_PARENT,
  107. .ops = &clk_rcg2_shared_ops,
  108. },
  109. };
  110. static const struct freq_tbl ftbl_gpu_cc_gx_gfx3d_clk_src[] = {
  111. F(355200000, P_GPU_CC_PLL0_OUT_AUX, 2, 0, 0),
  112. F(537600000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  113. F(672000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  114. F(844800000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  115. F(921600000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  116. F(1017600000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  117. F(1123200000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  118. { }
  119. };
  120. static struct clk_rcg2 gpu_cc_gx_gfx3d_clk_src = {
  121. .cmd_rcgr = 0x101c,
  122. .mnd_width = 0,
  123. .hid_width = 5,
  124. .parent_map = gpu_cc_parent_map_1,
  125. .freq_tbl = ftbl_gpu_cc_gx_gfx3d_clk_src,
  126. .clkr.hw.init = &(struct clk_init_data){
  127. .name = "gpu_cc_gx_gfx3d_clk_src",
  128. .parent_data = gpu_cc_parent_data_1,
  129. .num_parents = ARRAY_SIZE(gpu_cc_parent_data_1),
  130. .flags = CLK_SET_RATE_PARENT,
  131. .ops = &clk_rcg2_ops,
  132. },
  133. };
  134. static struct clk_branch gpu_cc_ahb_clk = {
  135. .halt_reg = 0x1078,
  136. .halt_check = BRANCH_HALT_DELAY,
  137. .clkr = {
  138. .enable_reg = 0x1078,
  139. .enable_mask = BIT(0),
  140. .hw.init = &(struct clk_init_data){
  141. .name = "gpu_cc_ahb_clk",
  142. .flags = CLK_IS_CRITICAL,
  143. .ops = &clk_branch2_ops,
  144. },
  145. },
  146. };
  147. static struct clk_branch gpu_cc_crc_ahb_clk = {
  148. .halt_reg = 0x107c,
  149. .halt_check = BRANCH_HALT_DELAY,
  150. .clkr = {
  151. .enable_reg = 0x107c,
  152. .enable_mask = BIT(0),
  153. .hw.init = &(struct clk_init_data){
  154. .name = "gpu_cc_crc_ahb_clk",
  155. .ops = &clk_branch2_ops,
  156. },
  157. },
  158. };
  159. static struct clk_branch gpu_cc_cx_gfx3d_clk = {
  160. .halt_reg = 0x10a4,
  161. .halt_check = BRANCH_HALT_DELAY,
  162. .clkr = {
  163. .enable_reg = 0x10a4,
  164. .enable_mask = BIT(0),
  165. .hw.init = &(struct clk_init_data){
  166. .name = "gpu_cc_cx_gfx3d_clk",
  167. .parent_data = &(const struct clk_parent_data){
  168. .hw = &gpu_cc_gx_gfx3d_clk_src.clkr.hw,
  169. },
  170. .num_parents = 1,
  171. .flags = CLK_SET_RATE_PARENT,
  172. .ops = &clk_branch2_ops,
  173. },
  174. },
  175. };
  176. static struct clk_branch gpu_cc_cx_gmu_clk = {
  177. .halt_reg = 0x1098,
  178. .halt_check = BRANCH_HALT,
  179. .clkr = {
  180. .enable_reg = 0x1098,
  181. .enable_mask = BIT(0),
  182. .hw.init = &(struct clk_init_data){
  183. .name = "gpu_cc_cx_gmu_clk",
  184. .parent_data = &(const struct clk_parent_data){
  185. .hw = &gpu_cc_gmu_clk_src.clkr.hw,
  186. },
  187. .num_parents = 1,
  188. .flags = CLK_SET_RATE_PARENT,
  189. .ops = &clk_branch2_ops,
  190. },
  191. },
  192. };
  193. static struct clk_branch gpu_cc_cx_snoc_dvm_clk = {
  194. .halt_reg = 0x108c,
  195. .halt_check = BRANCH_HALT_DELAY,
  196. .clkr = {
  197. .enable_reg = 0x108c,
  198. .enable_mask = BIT(0),
  199. .hw.init = &(struct clk_init_data){
  200. .name = "gpu_cc_cx_snoc_dvm_clk",
  201. .ops = &clk_branch2_ops,
  202. },
  203. },
  204. };
  205. static struct clk_branch gpu_cc_cxo_aon_clk = {
  206. .halt_reg = 0x1004,
  207. .halt_check = BRANCH_HALT_DELAY,
  208. .clkr = {
  209. .enable_reg = 0x1004,
  210. .enable_mask = BIT(0),
  211. .hw.init = &(struct clk_init_data){
  212. .name = "gpu_cc_cxo_aon_clk",
  213. .ops = &clk_branch2_ops,
  214. },
  215. },
  216. };
  217. static struct clk_branch gpu_cc_cxo_clk = {
  218. .halt_reg = 0x109c,
  219. .halt_check = BRANCH_HALT,
  220. .clkr = {
  221. .enable_reg = 0x109c,
  222. .enable_mask = BIT(0),
  223. .hw.init = &(struct clk_init_data){
  224. .name = "gpu_cc_cxo_clk",
  225. .ops = &clk_branch2_ops,
  226. },
  227. },
  228. };
  229. static struct clk_branch gpu_cc_gx_gfx3d_clk = {
  230. .halt_reg = 0x1054,
  231. .halt_check = BRANCH_HALT_DELAY,
  232. .clkr = {
  233. .enable_reg = 0x1054,
  234. .enable_mask = BIT(0),
  235. .hw.init = &(struct clk_init_data){
  236. .name = "gpu_cc_gx_gfx3d_clk",
  237. .parent_data = &(const struct clk_parent_data){
  238. .hw = &gpu_cc_gx_gfx3d_clk_src.clkr.hw,
  239. },
  240. .num_parents = 1,
  241. .flags = CLK_SET_RATE_PARENT,
  242. .ops = &clk_branch2_ops,
  243. },
  244. },
  245. };
  246. static struct clk_branch gpu_cc_sleep_clk = {
  247. .halt_reg = 0x1090,
  248. .halt_check = BRANCH_VOTED,
  249. .clkr = {
  250. .enable_reg = 0x1090,
  251. .enable_mask = BIT(0),
  252. .hw.init = &(struct clk_init_data){
  253. .name = "gpu_cc_sleep_clk",
  254. .ops = &clk_branch2_ops,
  255. },
  256. },
  257. };
  258. static struct clk_branch gpu_cc_hlos1_vote_gpu_smmu_clk = {
  259. .halt_reg = 0x5000,
  260. .halt_check = BRANCH_VOTED,
  261. .clkr = {
  262. .enable_reg = 0x5000,
  263. .enable_mask = BIT(0),
  264. .hw.init = &(struct clk_init_data){
  265. .name = "gpu_cc_hlos1_vote_gpu_smmu_clk",
  266. .ops = &clk_branch2_ops,
  267. },
  268. },
  269. };
  270. static struct gdsc gpu_cx_gdsc = {
  271. .gdscr = 0x106c,
  272. .gds_hw_ctrl = 0x1540,
  273. .pd = {
  274. .name = "gpu_cx_gdsc",
  275. },
  276. .pwrsts = PWRSTS_OFF_ON,
  277. .flags = VOTABLE,
  278. };
  279. static struct gdsc gpu_gx_gdsc = {
  280. .gdscr = 0x100c,
  281. .clamp_io_ctrl = 0x1508,
  282. .resets = (unsigned int []){ GPU_GX_BCR },
  283. .reset_count = 1,
  284. .pd = {
  285. .name = "gpu_gx_gdsc",
  286. },
  287. .parent = &gpu_cx_gdsc.pd,
  288. .pwrsts = PWRSTS_OFF_ON,
  289. .flags = CLAMP_IO | AON_RESET | SW_RESET,
  290. };
  291. static struct clk_regmap *gpu_cc_qcm2290_clocks[] = {
  292. [GPU_CC_AHB_CLK] = &gpu_cc_ahb_clk.clkr,
  293. [GPU_CC_CRC_AHB_CLK] = &gpu_cc_crc_ahb_clk.clkr,
  294. [GPU_CC_CX_GFX3D_CLK] = &gpu_cc_cx_gfx3d_clk.clkr,
  295. [GPU_CC_CX_GMU_CLK] = &gpu_cc_cx_gmu_clk.clkr,
  296. [GPU_CC_CX_SNOC_DVM_CLK] = &gpu_cc_cx_snoc_dvm_clk.clkr,
  297. [GPU_CC_CXO_AON_CLK] = &gpu_cc_cxo_aon_clk.clkr,
  298. [GPU_CC_CXO_CLK] = &gpu_cc_cxo_clk.clkr,
  299. [GPU_CC_GMU_CLK_SRC] = &gpu_cc_gmu_clk_src.clkr,
  300. [GPU_CC_GX_GFX3D_CLK] = &gpu_cc_gx_gfx3d_clk.clkr,
  301. [GPU_CC_GX_GFX3D_CLK_SRC] = &gpu_cc_gx_gfx3d_clk_src.clkr,
  302. [GPU_CC_PLL0] = &gpu_cc_pll0.clkr,
  303. [GPU_CC_SLEEP_CLK] = &gpu_cc_sleep_clk.clkr,
  304. [GPU_CC_HLOS1_VOTE_GPU_SMMU_CLK] = &gpu_cc_hlos1_vote_gpu_smmu_clk.clkr,
  305. };
  306. static const struct qcom_reset_map gpu_cc_qcm2290_resets[] = {
  307. [GPU_GX_BCR] = { 0x1008 },
  308. };
  309. static struct gdsc *gpu_cc_qcm2290_gdscs[] = {
  310. [GPU_CX_GDSC] = &gpu_cx_gdsc,
  311. [GPU_GX_GDSC] = &gpu_gx_gdsc,
  312. };
  313. static const struct regmap_config gpu_cc_qcm2290_regmap_config = {
  314. .reg_bits = 32,
  315. .reg_stride = 4,
  316. .val_bits = 32,
  317. .max_register = 0x9000,
  318. .fast_io = true,
  319. };
  320. static const struct qcom_cc_desc gpu_cc_qcm2290_desc = {
  321. .config = &gpu_cc_qcm2290_regmap_config,
  322. .clks = gpu_cc_qcm2290_clocks,
  323. .num_clks = ARRAY_SIZE(gpu_cc_qcm2290_clocks),
  324. .resets = gpu_cc_qcm2290_resets,
  325. .num_resets = ARRAY_SIZE(gpu_cc_qcm2290_resets),
  326. .gdscs = gpu_cc_qcm2290_gdscs,
  327. .num_gdscs = ARRAY_SIZE(gpu_cc_qcm2290_gdscs),
  328. };
  329. static const struct of_device_id gpu_cc_qcm2290_match_table[] = {
  330. { .compatible = "qcom,qcm2290-gpucc" },
  331. { }
  332. };
  333. MODULE_DEVICE_TABLE(of, gpu_cc_qcm2290_match_table);
  334. static int gpu_cc_qcm2290_probe(struct platform_device *pdev)
  335. {
  336. struct regmap *regmap;
  337. int ret;
  338. regmap = qcom_cc_map(pdev, &gpu_cc_qcm2290_desc);
  339. if (IS_ERR(regmap))
  340. return PTR_ERR(regmap);
  341. ret = devm_pm_runtime_enable(&pdev->dev);
  342. if (ret)
  343. return ret;
  344. ret = devm_pm_clk_create(&pdev->dev);
  345. if (ret)
  346. return ret;
  347. ret = pm_clk_add(&pdev->dev, NULL);
  348. if (ret < 0) {
  349. dev_err(&pdev->dev, "failed to acquire ahb clock\n");
  350. return ret;
  351. }
  352. ret = pm_runtime_resume_and_get(&pdev->dev);
  353. if (ret)
  354. return ret;
  355. clk_huayra_2290_pll_configure(&gpu_cc_pll0, regmap, &gpu_cc_pll0_config);
  356. regmap_update_bits(regmap, 0x1060, BIT(0), BIT(0)); /* GPU_CC_GX_CXO_CLK */
  357. ret = qcom_cc_really_probe(&pdev->dev, &gpu_cc_qcm2290_desc, regmap);
  358. if (ret) {
  359. dev_err(&pdev->dev, "Failed to register display clock controller\n");
  360. goto out_pm_runtime_put;
  361. }
  362. out_pm_runtime_put:
  363. pm_runtime_put_sync(&pdev->dev);
  364. return 0;
  365. }
  366. static struct platform_driver gpu_cc_qcm2290_driver = {
  367. .probe = gpu_cc_qcm2290_probe,
  368. .driver = {
  369. .name = "gpucc-qcm2290",
  370. .of_match_table = gpu_cc_qcm2290_match_table,
  371. },
  372. };
  373. module_platform_driver(gpu_cc_qcm2290_driver);
  374. MODULE_DESCRIPTION("QTI QCM2290 GPU clock controller driver");
  375. MODULE_LICENSE("GPL");