gpucc-sm6375.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023, 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_runtime.h>
  11. #include <linux/regmap.h>
  12. #include <dt-bindings/clock/qcom,sm6375-gpucc.h>
  13. #include "clk-alpha-pll.h"
  14. #include "clk-branch.h"
  15. #include "clk-rcg.h"
  16. #include "clk-regmap.h"
  17. #include "clk-regmap-divider.h"
  18. #include "clk-regmap-mux.h"
  19. #include "clk-regmap-phy-mux.h"
  20. #include "gdsc.h"
  21. #include "reset.h"
  22. enum {
  23. DT_BI_TCXO,
  24. DT_GCC_GPU_GPLL0_CLK_SRC,
  25. DT_GCC_GPU_GPLL0_DIV_CLK_SRC,
  26. DT_GCC_GPU_SNOC_DVM_GFX_CLK,
  27. };
  28. enum {
  29. P_BI_TCXO,
  30. P_GCC_GPU_GPLL0_CLK_SRC,
  31. P_GCC_GPU_GPLL0_DIV_CLK_SRC,
  32. P_GPU_CC_PLL0_OUT_EVEN,
  33. P_GPU_CC_PLL0_OUT_MAIN,
  34. P_GPU_CC_PLL0_OUT_ODD,
  35. P_GPU_CC_PLL1_OUT_EVEN,
  36. P_GPU_CC_PLL1_OUT_MAIN,
  37. P_GPU_CC_PLL1_OUT_ODD,
  38. };
  39. static const struct pll_vco lucid_vco[] = {
  40. { 249600000, 2000000000, 0 },
  41. };
  42. /* 532MHz Configuration */
  43. static const struct alpha_pll_config gpucc_pll0_config = {
  44. .l = 0x1b,
  45. .alpha = 0xb555,
  46. .config_ctl_val = 0x20485699,
  47. .config_ctl_hi_val = 0x00002261,
  48. .config_ctl_hi1_val = 0x329a299c,
  49. .user_ctl_val = 0x00000001,
  50. .user_ctl_hi_val = 0x00000805,
  51. .user_ctl_hi1_val = 0x00000000,
  52. };
  53. static struct clk_alpha_pll gpucc_pll0 = {
  54. .offset = 0x0,
  55. .vco_table = lucid_vco,
  56. .num_vco = ARRAY_SIZE(lucid_vco),
  57. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
  58. .clkr = {
  59. .hw.init = &(struct clk_init_data){
  60. .name = "gpucc_pll0",
  61. .parent_data = &(const struct clk_parent_data){
  62. .index = P_BI_TCXO,
  63. },
  64. .num_parents = 1,
  65. .ops = &clk_alpha_pll_lucid_ops,
  66. },
  67. },
  68. };
  69. /* 514MHz Configuration */
  70. static const struct alpha_pll_config gpucc_pll1_config = {
  71. .l = 0x1a,
  72. .alpha = 0xc555,
  73. .config_ctl_val = 0x20485699,
  74. .config_ctl_hi_val = 0x00002261,
  75. .config_ctl_hi1_val = 0x329a299c,
  76. .user_ctl_val = 0x00000001,
  77. .user_ctl_hi_val = 0x00000805,
  78. .user_ctl_hi1_val = 0x00000000,
  79. };
  80. static struct clk_alpha_pll gpucc_pll1 = {
  81. .offset = 0x100,
  82. .vco_table = lucid_vco,
  83. .num_vco = ARRAY_SIZE(lucid_vco),
  84. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
  85. .clkr = {
  86. .hw.init = &(struct clk_init_data){
  87. .name = "gpucc_pll1",
  88. .parent_data = &(const struct clk_parent_data){
  89. .index = P_BI_TCXO,
  90. },
  91. .num_parents = 1,
  92. .ops = &clk_alpha_pll_lucid_ops,
  93. },
  94. },
  95. };
  96. static const struct parent_map gpucc_parent_map_0[] = {
  97. { P_BI_TCXO, 0 },
  98. { P_GPU_CC_PLL0_OUT_MAIN, 1 },
  99. { P_GPU_CC_PLL1_OUT_MAIN, 3 },
  100. { P_GCC_GPU_GPLL0_CLK_SRC, 5 },
  101. { P_GCC_GPU_GPLL0_DIV_CLK_SRC, 6 },
  102. };
  103. static const struct clk_parent_data gpucc_parent_data_0[] = {
  104. { .index = P_BI_TCXO },
  105. { .hw = &gpucc_pll0.clkr.hw },
  106. { .hw = &gpucc_pll1.clkr.hw },
  107. { .index = DT_GCC_GPU_GPLL0_CLK_SRC },
  108. { .index = DT_GCC_GPU_GPLL0_DIV_CLK_SRC },
  109. };
  110. static const struct parent_map gpucc_parent_map_1[] = {
  111. { P_BI_TCXO, 0 },
  112. { P_GPU_CC_PLL0_OUT_EVEN, 1 },
  113. { P_GPU_CC_PLL0_OUT_ODD, 2 },
  114. { P_GPU_CC_PLL1_OUT_EVEN, 3 },
  115. { P_GPU_CC_PLL1_OUT_ODD, 4 },
  116. { P_GCC_GPU_GPLL0_CLK_SRC, 5 },
  117. };
  118. static const struct clk_parent_data gpucc_parent_data_1[] = {
  119. { .index = P_BI_TCXO },
  120. { .hw = &gpucc_pll0.clkr.hw },
  121. { .hw = &gpucc_pll0.clkr.hw },
  122. { .hw = &gpucc_pll1.clkr.hw },
  123. { .hw = &gpucc_pll1.clkr.hw },
  124. { .index = DT_GCC_GPU_GPLL0_CLK_SRC },
  125. };
  126. static const struct freq_tbl ftbl_gpucc_gmu_clk_src[] = {
  127. F(200000000, P_GCC_GPU_GPLL0_DIV_CLK_SRC, 1.5, 0, 0),
  128. { }
  129. };
  130. static struct clk_rcg2 gpucc_gmu_clk_src = {
  131. .cmd_rcgr = 0x1120,
  132. .mnd_width = 0,
  133. .hid_width = 5,
  134. .parent_map = gpucc_parent_map_0,
  135. .freq_tbl = ftbl_gpucc_gmu_clk_src,
  136. .clkr.hw.init = &(struct clk_init_data){
  137. .name = "gpucc_gmu_clk_src",
  138. .parent_data = gpucc_parent_data_0,
  139. .num_parents = ARRAY_SIZE(gpucc_parent_data_0),
  140. .ops = &clk_rcg2_shared_ops,
  141. },
  142. };
  143. static const struct freq_tbl ftbl_gpucc_gx_gfx3d_clk_src[] = {
  144. F(266000000, P_GPU_CC_PLL0_OUT_EVEN, 2, 0, 0),
  145. F(390000000, P_GPU_CC_PLL0_OUT_EVEN, 2, 0, 0),
  146. F(490000000, P_GPU_CC_PLL0_OUT_EVEN, 2, 0, 0),
  147. F(650000000, P_GPU_CC_PLL0_OUT_EVEN, 2, 0, 0),
  148. F(770000000, P_GPU_CC_PLL0_OUT_EVEN, 2, 0, 0),
  149. F(840000000, P_GPU_CC_PLL0_OUT_EVEN, 2, 0, 0),
  150. F(900000000, P_GPU_CC_PLL0_OUT_EVEN, 2, 0, 0),
  151. { }
  152. };
  153. static struct clk_rcg2 gpucc_gx_gfx3d_clk_src = {
  154. .cmd_rcgr = 0x101c,
  155. .mnd_width = 0,
  156. .hid_width = 5,
  157. .parent_map = gpucc_parent_map_1,
  158. .freq_tbl = ftbl_gpucc_gx_gfx3d_clk_src,
  159. .clkr.hw.init = &(struct clk_init_data){
  160. .name = "gpucc_gx_gfx3d_clk_src",
  161. .parent_data = gpucc_parent_data_1,
  162. .num_parents = ARRAY_SIZE(gpucc_parent_data_1),
  163. .flags = CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
  164. .ops = &clk_rcg2_ops,
  165. },
  166. };
  167. static struct clk_branch gpucc_ahb_clk = {
  168. .halt_reg = 0x1078,
  169. .halt_check = BRANCH_HALT_DELAY,
  170. .clkr = {
  171. .enable_reg = 0x1078,
  172. .enable_mask = BIT(0),
  173. .hw.init = &(struct clk_init_data){
  174. .name = "gpucc_ahb_clk",
  175. .flags = CLK_IS_CRITICAL,
  176. .ops = &clk_branch2_ops,
  177. },
  178. },
  179. };
  180. static struct clk_branch gpucc_cx_gfx3d_clk = {
  181. .halt_reg = 0x10a4,
  182. .halt_check = BRANCH_HALT_DELAY,
  183. .clkr = {
  184. .enable_reg = 0x10a4,
  185. .enable_mask = BIT(0),
  186. .hw.init = &(struct clk_init_data){
  187. .name = "gpucc_cx_gfx3d_clk",
  188. .parent_hws = (const struct clk_hw*[]) {
  189. &gpucc_gx_gfx3d_clk_src.clkr.hw,
  190. },
  191. .num_parents = 1,
  192. .flags = CLK_SET_RATE_PARENT,
  193. .ops = &clk_branch2_ops,
  194. },
  195. },
  196. };
  197. static struct clk_branch gpucc_cx_gfx3d_slv_clk = {
  198. .halt_reg = 0x10a8,
  199. .halt_check = BRANCH_HALT_DELAY,
  200. .clkr = {
  201. .enable_reg = 0x10a8,
  202. .enable_mask = BIT(0),
  203. .hw.init = &(struct clk_init_data){
  204. .name = "gpucc_cx_gfx3d_slv_clk",
  205. .parent_hws = (const struct clk_hw*[]) {
  206. &gpucc_gx_gfx3d_clk_src.clkr.hw,
  207. },
  208. .num_parents = 1,
  209. .flags = CLK_SET_RATE_PARENT,
  210. .ops = &clk_branch2_ops,
  211. },
  212. },
  213. };
  214. static struct clk_branch gpucc_cx_gmu_clk = {
  215. .halt_reg = 0x1098,
  216. .halt_check = BRANCH_HALT,
  217. .clkr = {
  218. .enable_reg = 0x1098,
  219. .enable_mask = BIT(0),
  220. .hw.init = &(struct clk_init_data){
  221. .name = "gpucc_cx_gmu_clk",
  222. .parent_hws = (const struct clk_hw*[]) {
  223. &gpucc_gmu_clk_src.clkr.hw,
  224. },
  225. .num_parents = 1,
  226. .flags = CLK_SET_RATE_PARENT,
  227. .ops = &clk_branch2_ops,
  228. },
  229. },
  230. };
  231. static struct clk_branch gpucc_cx_snoc_dvm_clk = {
  232. .halt_reg = 0x108c,
  233. .halt_check = BRANCH_HALT_DELAY,
  234. .clkr = {
  235. .enable_reg = 0x108c,
  236. .enable_mask = BIT(0),
  237. .hw.init = &(struct clk_init_data){
  238. .name = "gpucc_cx_snoc_dvm_clk",
  239. .parent_data = &(const struct clk_parent_data){
  240. .index = DT_GCC_GPU_SNOC_DVM_GFX_CLK,
  241. },
  242. .num_parents = 1,
  243. .ops = &clk_branch2_ops,
  244. },
  245. },
  246. };
  247. static struct clk_branch gpucc_cxo_aon_clk = {
  248. .halt_reg = 0x1004,
  249. .halt_check = BRANCH_HALT_DELAY,
  250. .clkr = {
  251. .enable_reg = 0x1004,
  252. .enable_mask = BIT(0),
  253. .hw.init = &(struct clk_init_data){
  254. .name = "gpucc_cxo_aon_clk",
  255. .ops = &clk_branch2_ops,
  256. },
  257. },
  258. };
  259. static struct clk_branch gpucc_cxo_clk = {
  260. .halt_reg = 0x109c,
  261. .halt_check = BRANCH_HALT,
  262. .clkr = {
  263. .enable_reg = 0x109c,
  264. .enable_mask = BIT(0),
  265. .hw.init = &(struct clk_init_data){
  266. .name = "gpucc_cxo_clk",
  267. .ops = &clk_branch2_ops,
  268. },
  269. },
  270. };
  271. static struct clk_branch gpucc_gx_cxo_clk = {
  272. .halt_reg = 0x1060,
  273. .halt_check = BRANCH_HALT_DELAY,
  274. .clkr = {
  275. .enable_reg = 0x1060,
  276. .enable_mask = BIT(0),
  277. .hw.init = &(struct clk_init_data){
  278. .name = "gpucc_gx_cxo_clk",
  279. .flags = CLK_IS_CRITICAL,
  280. .ops = &clk_branch2_ops,
  281. },
  282. },
  283. };
  284. static struct clk_branch gpucc_gx_gfx3d_clk = {
  285. .halt_reg = 0x1054,
  286. .halt_check = BRANCH_HALT_DELAY,
  287. .clkr = {
  288. .enable_reg = 0x1054,
  289. .enable_mask = BIT(0),
  290. .hw.init = &(struct clk_init_data){
  291. .name = "gpucc_gx_gfx3d_clk",
  292. .parent_hws = (const struct clk_hw*[]) {
  293. &gpucc_gx_gfx3d_clk_src.clkr.hw,
  294. },
  295. .num_parents = 1,
  296. .flags = CLK_SET_RATE_PARENT,
  297. .ops = &clk_branch2_ops,
  298. },
  299. },
  300. };
  301. static struct clk_branch gpucc_gx_gmu_clk = {
  302. .halt_reg = 0x1064,
  303. .halt_check = BRANCH_HALT,
  304. .clkr = {
  305. .enable_reg = 0x1064,
  306. .enable_mask = BIT(0),
  307. .hw.init = &(struct clk_init_data){
  308. .name = "gpucc_gx_gmu_clk",
  309. .parent_hws = (const struct clk_hw*[]) {
  310. &gpucc_gmu_clk_src.clkr.hw,
  311. },
  312. .num_parents = 1,
  313. .flags = CLK_SET_RATE_PARENT,
  314. .ops = &clk_branch2_ops,
  315. },
  316. },
  317. };
  318. static struct clk_branch gpucc_sleep_clk = {
  319. .halt_reg = 0x1090,
  320. .halt_check = BRANCH_HALT_VOTED,
  321. .clkr = {
  322. .enable_reg = 0x1090,
  323. .enable_mask = BIT(0),
  324. .hw.init = &(struct clk_init_data){
  325. .name = "gpucc_sleep_clk",
  326. .ops = &clk_branch2_ops,
  327. },
  328. },
  329. };
  330. static struct gdsc gpu_cx_gdsc = {
  331. .gdscr = 0x106c,
  332. .gds_hw_ctrl = 0x1540,
  333. .clk_dis_wait_val = 8,
  334. .pd = {
  335. .name = "gpu_cx_gdsc",
  336. },
  337. .pwrsts = PWRSTS_OFF_ON,
  338. .flags = VOTABLE,
  339. };
  340. static struct gdsc gpu_gx_gdsc = {
  341. .gdscr = 0x100c,
  342. .clamp_io_ctrl = 0x1508,
  343. .resets = (unsigned int []){ GPU_GX_BCR, GPU_ACD_BCR, GPU_GX_ACD_MISC_BCR },
  344. .reset_count = 3,
  345. .pd = {
  346. .name = "gpu_gx_gdsc",
  347. },
  348. .pwrsts = PWRSTS_OFF_ON,
  349. .flags = CLAMP_IO | SW_RESET | AON_RESET,
  350. };
  351. static struct clk_regmap *gpucc_sm6375_clocks[] = {
  352. [GPU_CC_AHB_CLK] = &gpucc_ahb_clk.clkr,
  353. [GPU_CC_CX_GFX3D_CLK] = &gpucc_cx_gfx3d_clk.clkr,
  354. [GPU_CC_CX_GFX3D_SLV_CLK] = &gpucc_cx_gfx3d_slv_clk.clkr,
  355. [GPU_CC_CX_GMU_CLK] = &gpucc_cx_gmu_clk.clkr,
  356. [GPU_CC_CX_SNOC_DVM_CLK] = &gpucc_cx_snoc_dvm_clk.clkr,
  357. [GPU_CC_CXO_AON_CLK] = &gpucc_cxo_aon_clk.clkr,
  358. [GPU_CC_CXO_CLK] = &gpucc_cxo_clk.clkr,
  359. [GPU_CC_GMU_CLK_SRC] = &gpucc_gmu_clk_src.clkr,
  360. [GPU_CC_GX_CXO_CLK] = &gpucc_gx_cxo_clk.clkr,
  361. [GPU_CC_GX_GFX3D_CLK] = &gpucc_gx_gfx3d_clk.clkr,
  362. [GPU_CC_GX_GFX3D_CLK_SRC] = &gpucc_gx_gfx3d_clk_src.clkr,
  363. [GPU_CC_GX_GMU_CLK] = &gpucc_gx_gmu_clk.clkr,
  364. [GPU_CC_PLL0] = &gpucc_pll0.clkr,
  365. [GPU_CC_PLL1] = &gpucc_pll1.clkr,
  366. [GPU_CC_SLEEP_CLK] = &gpucc_sleep_clk.clkr,
  367. };
  368. static const struct qcom_reset_map gpucc_sm6375_resets[] = {
  369. [GPU_GX_BCR] = { 0x1008 },
  370. [GPU_ACD_BCR] = { 0x1160 },
  371. [GPU_GX_ACD_MISC_BCR] = { 0x8004 },
  372. };
  373. static struct gdsc *gpucc_sm6375_gdscs[] = {
  374. [GPU_CX_GDSC] = &gpu_cx_gdsc,
  375. [GPU_GX_GDSC] = &gpu_gx_gdsc,
  376. };
  377. static const struct regmap_config gpucc_sm6375_regmap_config = {
  378. .reg_bits = 32,
  379. .reg_stride = 4,
  380. .val_bits = 32,
  381. .max_register = 0x9000,
  382. .fast_io = true,
  383. };
  384. static const struct qcom_cc_desc gpucc_sm6375_desc = {
  385. .config = &gpucc_sm6375_regmap_config,
  386. .clks = gpucc_sm6375_clocks,
  387. .num_clks = ARRAY_SIZE(gpucc_sm6375_clocks),
  388. .resets = gpucc_sm6375_resets,
  389. .num_resets = ARRAY_SIZE(gpucc_sm6375_resets),
  390. .gdscs = gpucc_sm6375_gdscs,
  391. .num_gdscs = ARRAY_SIZE(gpucc_sm6375_gdscs),
  392. };
  393. static const struct of_device_id gpucc_sm6375_match_table[] = {
  394. { .compatible = "qcom,sm6375-gpucc" },
  395. { }
  396. };
  397. MODULE_DEVICE_TABLE(of, gpucc_sm6375_match_table);
  398. static int gpucc_sm6375_probe(struct platform_device *pdev)
  399. {
  400. struct regmap *regmap;
  401. int ret;
  402. ret = devm_pm_runtime_enable(&pdev->dev);
  403. if (ret)
  404. return ret;
  405. ret = pm_runtime_resume_and_get(&pdev->dev);
  406. if (ret)
  407. return ret;
  408. regmap = qcom_cc_map(pdev, &gpucc_sm6375_desc);
  409. if (IS_ERR(regmap)) {
  410. pm_runtime_put(&pdev->dev);
  411. return PTR_ERR(regmap);
  412. }
  413. clk_lucid_pll_configure(&gpucc_pll0, regmap, &gpucc_pll0_config);
  414. clk_lucid_pll_configure(&gpucc_pll1, regmap, &gpucc_pll1_config);
  415. ret = qcom_cc_really_probe(&pdev->dev, &gpucc_sm6375_desc, regmap);
  416. pm_runtime_put(&pdev->dev);
  417. return ret;
  418. }
  419. static struct platform_driver gpucc_sm6375_driver = {
  420. .probe = gpucc_sm6375_probe,
  421. .driver = {
  422. .name = "gpucc-sm6375",
  423. .of_match_table = gpucc_sm6375_match_table,
  424. },
  425. };
  426. module_platform_driver(gpucc_sm6375_driver);
  427. MODULE_DESCRIPTION("QTI GPUCC SM6375 Driver");
  428. MODULE_LICENSE("GPL");