gpucc-sm6125.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2019, 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/regmap.h>
  11. #include <dt-bindings/clock/qcom,sm6125-gpucc.h>
  12. #include "clk-alpha-pll.h"
  13. #include "clk-branch.h"
  14. #include "clk-rcg.h"
  15. #include "clk-regmap.h"
  16. #include "clk-regmap-divider.h"
  17. #include "clk-regmap-mux.h"
  18. #include "clk-regmap-phy-mux.h"
  19. #include "gdsc.h"
  20. #include "reset.h"
  21. enum {
  22. DT_BI_TCXO,
  23. DT_GCC_GPU_GPLL0_CLK_SRC,
  24. };
  25. enum {
  26. P_BI_TCXO,
  27. P_GPLL0_OUT_MAIN,
  28. P_GPU_CC_PLL0_2X_CLK,
  29. P_GPU_CC_PLL0_OUT_AUX2,
  30. P_GPU_CC_PLL1_OUT_AUX,
  31. P_GPU_CC_PLL1_OUT_AUX2,
  32. };
  33. static const struct pll_vco gpu_cc_pll_vco[] = {
  34. { 1000000000, 2000000000, 0 },
  35. { 500000000, 1000000000, 2 },
  36. };
  37. /* 1020MHz configuration */
  38. static const struct alpha_pll_config gpu_pll0_config = {
  39. .l = 0x35,
  40. .config_ctl_val = 0x4001055b,
  41. .alpha_hi = 0x20,
  42. .alpha = 0x00,
  43. .alpha_en_mask = BIT(24),
  44. .vco_val = 0x0 << 20,
  45. .vco_mask = 0x3 << 20,
  46. .aux2_output_mask = BIT(2),
  47. };
  48. /* 930MHz configuration */
  49. static const struct alpha_pll_config gpu_pll1_config = {
  50. .l = 0x30,
  51. .config_ctl_val = 0x4001055b,
  52. .alpha_hi = 0x70,
  53. .alpha = 0x00,
  54. .alpha_en_mask = BIT(24),
  55. .vco_val = 0x2 << 20,
  56. .vco_mask = 0x3 << 20,
  57. .aux2_output_mask = BIT(2),
  58. };
  59. static struct clk_alpha_pll gpu_cc_pll0_out_aux2 = {
  60. .offset = 0x0,
  61. .vco_table = gpu_cc_pll_vco,
  62. .num_vco = ARRAY_SIZE(gpu_cc_pll_vco),
  63. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
  64. .flags = SUPPORTS_DYNAMIC_UPDATE,
  65. .clkr = {
  66. .hw.init = &(struct clk_init_data){
  67. .name = "gpu_cc_pll0_out_aux2",
  68. .parent_data = &(const struct clk_parent_data) {
  69. .index = DT_BI_TCXO,
  70. },
  71. .num_parents = 1,
  72. .ops = &clk_alpha_pll_ops,
  73. },
  74. },
  75. };
  76. static struct clk_alpha_pll gpu_cc_pll1_out_aux2 = {
  77. .offset = 0x100,
  78. .vco_table = gpu_cc_pll_vco,
  79. .num_vco = ARRAY_SIZE(gpu_cc_pll_vco),
  80. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
  81. .flags = SUPPORTS_DYNAMIC_UPDATE,
  82. .clkr = {
  83. .hw.init = &(struct clk_init_data){
  84. .name = "gpu_cc_pll1_out_aux2",
  85. .parent_data = &(const struct clk_parent_data) {
  86. .index = DT_BI_TCXO,
  87. },
  88. .num_parents = 1,
  89. .ops = &clk_alpha_pll_ops,
  90. },
  91. },
  92. };
  93. static const struct parent_map gpu_cc_parent_map_0[] = {
  94. { P_BI_TCXO, 0 },
  95. { P_GPLL0_OUT_MAIN, 5 },
  96. };
  97. static const struct clk_parent_data gpu_cc_parent_data_0[] = {
  98. { .index = DT_BI_TCXO },
  99. { .index = DT_GCC_GPU_GPLL0_CLK_SRC },
  100. };
  101. static const struct parent_map gpu_cc_parent_map_1[] = {
  102. { P_BI_TCXO, 0 },
  103. { P_GPU_CC_PLL0_OUT_AUX2, 2 },
  104. { P_GPU_CC_PLL1_OUT_AUX2, 4 },
  105. };
  106. static const struct clk_parent_data gpu_cc_parent_data_1[] = {
  107. { .index = DT_BI_TCXO },
  108. { .hw = &gpu_cc_pll0_out_aux2.clkr.hw },
  109. { .hw = &gpu_cc_pll1_out_aux2.clkr.hw },
  110. };
  111. static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src[] = {
  112. F(200000000, P_GPLL0_OUT_MAIN, 3, 0, 0),
  113. { }
  114. };
  115. static struct clk_rcg2 gpu_cc_gmu_clk_src = {
  116. .cmd_rcgr = 0x1120,
  117. .mnd_width = 0,
  118. .hid_width = 5,
  119. .parent_map = gpu_cc_parent_map_0,
  120. .freq_tbl = ftbl_gpu_cc_gmu_clk_src,
  121. .clkr.hw.init = &(struct clk_init_data){
  122. .name = "gpu_cc_gmu_clk_src",
  123. .parent_data = gpu_cc_parent_data_0,
  124. .num_parents = ARRAY_SIZE(gpu_cc_parent_data_0),
  125. .ops = &clk_rcg2_shared_ops,
  126. },
  127. };
  128. static const struct freq_tbl ftbl_gpu_cc_gx_gfx3d_clk_src[] = {
  129. F(320000000, P_GPU_CC_PLL1_OUT_AUX2, 2, 0, 0),
  130. F(465000000, P_GPU_CC_PLL1_OUT_AUX2, 2, 0, 0),
  131. F(600000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  132. F(745000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  133. F(820000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  134. F(900000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  135. F(950000000, P_GPU_CC_PLL0_OUT_AUX2, 2, 0, 0),
  136. { }
  137. };
  138. static struct clk_rcg2 gpu_cc_gx_gfx3d_clk_src = {
  139. .cmd_rcgr = 0x101c,
  140. .mnd_width = 0,
  141. .hid_width = 5,
  142. .parent_map = gpu_cc_parent_map_1,
  143. .freq_tbl = ftbl_gpu_cc_gx_gfx3d_clk_src,
  144. .clkr.hw.init = &(struct clk_init_data){
  145. .name = "gpu_cc_gx_gfx3d_clk_src",
  146. .parent_data = gpu_cc_parent_data_1,
  147. .num_parents = ARRAY_SIZE(gpu_cc_parent_data_1),
  148. .flags = CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE,
  149. .ops = &clk_rcg2_ops,
  150. },
  151. };
  152. static struct clk_branch gpu_cc_crc_ahb_clk = {
  153. .halt_reg = 0x107c,
  154. .halt_check = BRANCH_HALT_DELAY,
  155. .clkr = {
  156. .enable_reg = 0x107c,
  157. .enable_mask = BIT(0),
  158. .hw.init = &(struct clk_init_data){
  159. .name = "gpu_cc_crc_ahb_clk",
  160. .ops = &clk_branch2_ops,
  161. },
  162. },
  163. };
  164. static struct clk_branch gpu_cc_cx_apb_clk = {
  165. .halt_reg = 0x1088,
  166. .halt_check = BRANCH_HALT_DELAY,
  167. .clkr = {
  168. .enable_reg = 0x1088,
  169. .enable_mask = BIT(0),
  170. .hw.init = &(struct clk_init_data){
  171. .name = "gpu_cc_cx_apb_clk",
  172. .ops = &clk_branch2_ops,
  173. },
  174. },
  175. };
  176. static struct clk_branch gpu_cc_gx_gfx3d_clk = {
  177. .halt_reg = 0x1054,
  178. .halt_check = BRANCH_HALT_SKIP,
  179. .clkr = {
  180. .enable_reg = 0x1054,
  181. .enable_mask = BIT(0),
  182. .hw.init = &(struct clk_init_data){
  183. .name = "gpu_cc_gx_gfx3d_clk",
  184. .parent_hws = (const struct clk_hw*[]) {
  185. &gpu_cc_gx_gfx3d_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_gfx3d_clk = {
  194. .halt_reg = 0x10a4,
  195. .halt_check = BRANCH_HALT_DELAY,
  196. .clkr = {
  197. .enable_reg = 0x10a4,
  198. .enable_mask = BIT(0),
  199. .hw.init = &(struct clk_init_data){
  200. .name = "gpu_cc_cx_gfx3d_clk",
  201. .parent_hws = (const struct clk_hw*[]) {
  202. &gpu_cc_gx_gfx3d_clk.clkr.hw,
  203. },
  204. .num_parents = 1,
  205. .flags = CLK_SET_RATE_PARENT,
  206. .ops = &clk_branch2_ops,
  207. },
  208. },
  209. };
  210. static struct clk_branch gpu_cc_cx_gmu_clk = {
  211. .halt_reg = 0x1098,
  212. .halt_check = BRANCH_HALT,
  213. .clkr = {
  214. .enable_reg = 0x1098,
  215. .enable_mask = BIT(0),
  216. .hw.init = &(struct clk_init_data){
  217. .name = "gpu_cc_cx_gmu_clk",
  218. .parent_hws = (const struct clk_hw*[]) {
  219. &gpu_cc_gmu_clk_src.clkr.hw,
  220. },
  221. .num_parents = 1,
  222. .flags = CLK_SET_RATE_PARENT,
  223. .ops = &clk_branch2_ops,
  224. },
  225. },
  226. };
  227. static struct clk_branch gpu_cc_cx_snoc_dvm_clk = {
  228. .halt_reg = 0x108c,
  229. .halt_check = BRANCH_HALT_DELAY,
  230. .clkr = {
  231. .enable_reg = 0x108c,
  232. .enable_mask = BIT(0),
  233. .hw.init = &(struct clk_init_data){
  234. .name = "gpu_cc_cx_snoc_dvm_clk",
  235. .ops = &clk_branch2_ops,
  236. },
  237. },
  238. };
  239. static struct clk_branch gpu_cc_cxo_aon_clk = {
  240. .halt_reg = 0x1004,
  241. .halt_check = BRANCH_HALT_DELAY,
  242. .clkr = {
  243. .enable_reg = 0x1004,
  244. .enable_mask = BIT(0),
  245. .hw.init = &(struct clk_init_data){
  246. .name = "gpu_cc_cxo_aon_clk",
  247. .ops = &clk_branch2_ops,
  248. },
  249. },
  250. };
  251. static struct clk_branch gpu_cc_cxo_clk = {
  252. .halt_reg = 0x109c,
  253. .halt_check = BRANCH_HALT,
  254. .clkr = {
  255. .enable_reg = 0x109c,
  256. .enable_mask = BIT(0),
  257. .hw.init = &(struct clk_init_data){
  258. .name = "gpu_cc_cxo_clk",
  259. .ops = &clk_branch2_ops,
  260. },
  261. },
  262. };
  263. static struct clk_branch gpu_cc_sleep_clk = {
  264. .halt_reg = 0x1090,
  265. .halt_check = BRANCH_HALT_DELAY,
  266. .clkr = {
  267. .enable_reg = 0x1090,
  268. .enable_mask = BIT(0),
  269. .hw.init = &(struct clk_init_data){
  270. .name = "gpu_cc_sleep_clk",
  271. .ops = &clk_branch2_ops,
  272. },
  273. },
  274. };
  275. static struct clk_branch gpu_cc_ahb_clk = {
  276. .halt_reg = 0x1078,
  277. .halt_check = BRANCH_HALT_DELAY,
  278. .clkr = {
  279. .enable_reg = 0x1078,
  280. .enable_mask = BIT(0),
  281. .hw.init = &(struct clk_init_data){
  282. .name = "gpu_cc_ahb_clk",
  283. .flags = CLK_IS_CRITICAL,
  284. .ops = &clk_branch2_ops,
  285. },
  286. },
  287. };
  288. static struct clk_branch gpu_cc_hlos1_vote_gpu_smmu_clk = {
  289. .halt_reg = 0x5000,
  290. .halt_check = BRANCH_VOTED,
  291. .clkr = {
  292. .enable_reg = 0x5000,
  293. .enable_mask = BIT(0),
  294. .hw.init = &(struct clk_init_data){
  295. .name = "gpu_cc_hlos1_vote_gpu_smmu_clk",
  296. .ops = &clk_branch2_ops,
  297. },
  298. },
  299. };
  300. static struct gdsc gpu_cx_gdsc = {
  301. .gdscr = 0x106c,
  302. .gds_hw_ctrl = 0x1540,
  303. .pd = {
  304. .name = "gpu_cx_gdsc",
  305. },
  306. .pwrsts = PWRSTS_OFF_ON,
  307. .flags = VOTABLE,
  308. };
  309. static struct gdsc gpu_gx_gdsc = {
  310. .gdscr = 0x100c,
  311. .pd = {
  312. .name = "gpu_gx_gdsc",
  313. },
  314. .pwrsts = PWRSTS_OFF_ON,
  315. .flags = VOTABLE,
  316. };
  317. static struct clk_regmap *gpu_cc_sm6125_clocks[] = {
  318. [GPU_CC_CRC_AHB_CLK] = &gpu_cc_crc_ahb_clk.clkr,
  319. [GPU_CC_CX_APB_CLK] = &gpu_cc_cx_apb_clk.clkr,
  320. [GPU_CC_CX_GFX3D_CLK] = &gpu_cc_cx_gfx3d_clk.clkr,
  321. [GPU_CC_CX_GMU_CLK] = &gpu_cc_cx_gmu_clk.clkr,
  322. [GPU_CC_CX_SNOC_DVM_CLK] = &gpu_cc_cx_snoc_dvm_clk.clkr,
  323. [GPU_CC_CXO_AON_CLK] = &gpu_cc_cxo_aon_clk.clkr,
  324. [GPU_CC_CXO_CLK] = &gpu_cc_cxo_clk.clkr,
  325. [GPU_CC_GMU_CLK_SRC] = &gpu_cc_gmu_clk_src.clkr,
  326. [GPU_CC_PLL0_OUT_AUX2] = &gpu_cc_pll0_out_aux2.clkr,
  327. [GPU_CC_PLL1_OUT_AUX2] = &gpu_cc_pll1_out_aux2.clkr,
  328. [GPU_CC_SLEEP_CLK] = &gpu_cc_sleep_clk.clkr,
  329. [GPU_CC_GX_GFX3D_CLK] = &gpu_cc_gx_gfx3d_clk.clkr,
  330. [GPU_CC_GX_GFX3D_CLK_SRC] = &gpu_cc_gx_gfx3d_clk_src.clkr,
  331. [GPU_CC_AHB_CLK] = &gpu_cc_ahb_clk.clkr,
  332. [GPU_CC_HLOS1_VOTE_GPU_SMMU_CLK] = &gpu_cc_hlos1_vote_gpu_smmu_clk.clkr,
  333. };
  334. static struct gdsc *gpucc_sm6125_gdscs[] = {
  335. [GPU_CX_GDSC] = &gpu_cx_gdsc,
  336. [GPU_GX_GDSC] = &gpu_gx_gdsc,
  337. };
  338. static const struct regmap_config gpu_cc_sm6125_regmap_config = {
  339. .reg_bits = 32,
  340. .reg_stride = 4,
  341. .val_bits = 32,
  342. .max_register = 0x9000,
  343. .fast_io = true,
  344. };
  345. static const struct qcom_cc_desc gpu_cc_sm6125_desc = {
  346. .config = &gpu_cc_sm6125_regmap_config,
  347. .clks = gpu_cc_sm6125_clocks,
  348. .num_clks = ARRAY_SIZE(gpu_cc_sm6125_clocks),
  349. .gdscs = gpucc_sm6125_gdscs,
  350. .num_gdscs = ARRAY_SIZE(gpucc_sm6125_gdscs),
  351. };
  352. static const struct of_device_id gpu_cc_sm6125_match_table[] = {
  353. { .compatible = "qcom,sm6125-gpucc" },
  354. { }
  355. };
  356. MODULE_DEVICE_TABLE(of, gpu_cc_sm6125_match_table);
  357. static int gpu_cc_sm6125_probe(struct platform_device *pdev)
  358. {
  359. struct regmap *regmap;
  360. regmap = qcom_cc_map(pdev, &gpu_cc_sm6125_desc);
  361. if (IS_ERR(regmap))
  362. return PTR_ERR(regmap);
  363. clk_alpha_pll_configure(&gpu_cc_pll0_out_aux2, regmap, &gpu_pll0_config);
  364. clk_alpha_pll_configure(&gpu_cc_pll1_out_aux2, regmap, &gpu_pll1_config);
  365. /* Set recommended WAKEUP/SLEEP settings for the gpu_cc_cx_gmu_clk */
  366. qcom_branch_set_wakeup(regmap, gpu_cc_cx_gmu_clk, 0xf);
  367. qcom_branch_set_sleep(regmap, gpu_cc_cx_gmu_clk, 0xf);
  368. qcom_branch_set_force_mem_core(regmap, gpu_cc_gx_gfx3d_clk, true);
  369. qcom_branch_set_force_periph_on(regmap, gpu_cc_gx_gfx3d_clk, true);
  370. return qcom_cc_really_probe(&pdev->dev, &gpu_cc_sm6125_desc, regmap);
  371. }
  372. static struct platform_driver gpu_cc_sm6125_driver = {
  373. .probe = gpu_cc_sm6125_probe,
  374. .driver = {
  375. .name = "gpucc-sm6125",
  376. .of_match_table = gpu_cc_sm6125_match_table,
  377. },
  378. };
  379. module_platform_driver(gpu_cc_sm6125_driver);
  380. MODULE_DESCRIPTION("QTI GPUCC SM6125 Driver");
  381. MODULE_LICENSE("GPL");