gpucc-kaanapali.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
  4. */
  5. #include <linux/clk-provider.h>
  6. #include <linux/mod_devicetable.h>
  7. #include <linux/module.h>
  8. #include <linux/of.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/regmap.h>
  11. #include <dt-bindings/clock/qcom,kaanapali-gpucc.h>
  12. #include "clk-alpha-pll.h"
  13. #include "clk-branch.h"
  14. #include "clk-pll.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 "common.h"
  20. #include "gdsc.h"
  21. #include "reset.h"
  22. enum {
  23. DT_BI_TCXO,
  24. DT_GPLL0_OUT_MAIN,
  25. DT_GPLL0_OUT_MAIN_DIV,
  26. };
  27. enum {
  28. P_BI_TCXO,
  29. P_GPLL0_OUT_MAIN,
  30. P_GPLL0_OUT_MAIN_DIV,
  31. P_GPU_CC_PLL0_OUT_EVEN,
  32. P_GPU_CC_PLL0_OUT_MAIN,
  33. P_GPU_CC_PLL0_OUT_ODD,
  34. };
  35. static const struct pll_vco taycan_eko_t_vco[] = {
  36. { 249600000, 2500000000, 0 },
  37. };
  38. /* 950.0 MHz Configuration */
  39. static const struct alpha_pll_config gpu_cc_pll0_config = {
  40. .l = 0x31,
  41. .cal_l = 0x48,
  42. .alpha = 0x7aaa,
  43. .config_ctl_val = 0x25c400e7,
  44. .config_ctl_hi_val = 0x0a8062e0,
  45. .config_ctl_hi1_val = 0xf51dea20,
  46. .user_ctl_val = 0x00000408,
  47. .user_ctl_hi_val = 0x00000002,
  48. };
  49. static struct clk_alpha_pll gpu_cc_pll0 = {
  50. .offset = 0x0,
  51. .config = &gpu_cc_pll0_config,
  52. .vco_table = taycan_eko_t_vco,
  53. .num_vco = ARRAY_SIZE(taycan_eko_t_vco),
  54. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_TAYCAN_EKO_T],
  55. .clkr = {
  56. .hw.init = &(const 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_taycan_eko_t_ops,
  63. },
  64. },
  65. };
  66. static const struct clk_div_table post_div_table_gpu_cc_pll0_out_even[] = {
  67. { 0x1, 2 },
  68. { }
  69. };
  70. static struct clk_alpha_pll_postdiv gpu_cc_pll0_out_even = {
  71. .offset = 0x0,
  72. .post_div_shift = 10,
  73. .post_div_table = post_div_table_gpu_cc_pll0_out_even,
  74. .num_post_div = ARRAY_SIZE(post_div_table_gpu_cc_pll0_out_even),
  75. .width = 4,
  76. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_TAYCAN_EKO_T],
  77. .clkr.hw.init = &(const struct clk_init_data) {
  78. .name = "gpu_cc_pll0_out_even",
  79. .parent_hws = (const struct clk_hw*[]) {
  80. &gpu_cc_pll0.clkr.hw,
  81. },
  82. .num_parents = 1,
  83. .flags = CLK_SET_RATE_PARENT,
  84. .ops = &clk_alpha_pll_postdiv_taycan_eko_t_ops,
  85. },
  86. };
  87. static const struct parent_map gpu_cc_parent_map_0[] = {
  88. { P_BI_TCXO, 0 },
  89. { P_GPU_CC_PLL0_OUT_MAIN, 1 },
  90. { P_GPU_CC_PLL0_OUT_EVEN, 2 },
  91. { P_GPU_CC_PLL0_OUT_ODD, 3 },
  92. { P_GPLL0_OUT_MAIN, 5 },
  93. { P_GPLL0_OUT_MAIN_DIV, 6 },
  94. };
  95. static const struct clk_parent_data gpu_cc_parent_data_0[] = {
  96. { .index = DT_BI_TCXO },
  97. { .hw = &gpu_cc_pll0.clkr.hw },
  98. { .hw = &gpu_cc_pll0_out_even.clkr.hw },
  99. { .hw = &gpu_cc_pll0.clkr.hw },
  100. { .index = DT_GPLL0_OUT_MAIN },
  101. { .index = DT_GPLL0_OUT_MAIN_DIV },
  102. };
  103. static const struct freq_tbl ftbl_gpu_cc_gmu_clk_src[] = {
  104. F(19200000, P_BI_TCXO, 1, 0, 0),
  105. F(475000000, P_GPU_CC_PLL0_OUT_EVEN, 1, 0, 0),
  106. F(575000000, P_GPU_CC_PLL0_OUT_EVEN, 1, 0, 0),
  107. F(700000000, P_GPU_CC_PLL0_OUT_EVEN, 1, 0, 0),
  108. F(725000000, P_GPU_CC_PLL0_OUT_EVEN, 1, 0, 0),
  109. F(750000000, P_GPU_CC_PLL0_OUT_EVEN, 1, 0, 0),
  110. { }
  111. };
  112. static struct clk_rcg2 gpu_cc_gmu_clk_src = {
  113. .cmd_rcgr = 0x9318,
  114. .mnd_width = 0,
  115. .hid_width = 5,
  116. .parent_map = gpu_cc_parent_map_0,
  117. .hw_clk_ctrl = true,
  118. .freq_tbl = ftbl_gpu_cc_gmu_clk_src,
  119. .clkr.hw.init = &(const struct clk_init_data) {
  120. .name = "gpu_cc_gmu_clk_src",
  121. .parent_data = gpu_cc_parent_data_0,
  122. .num_parents = ARRAY_SIZE(gpu_cc_parent_data_0),
  123. .flags = CLK_SET_RATE_PARENT,
  124. .ops = &clk_rcg2_shared_ops,
  125. },
  126. };
  127. static const struct freq_tbl ftbl_gpu_cc_hub_clk_src[] = {
  128. F(150000000, P_GPLL0_OUT_MAIN_DIV, 2, 0, 0),
  129. F(200000000, P_GPLL0_OUT_MAIN, 3, 0, 0),
  130. F(300000000, P_GPLL0_OUT_MAIN, 2, 0, 0),
  131. F(400000000, P_GPLL0_OUT_MAIN, 1.5, 0, 0),
  132. { }
  133. };
  134. static struct clk_rcg2 gpu_cc_hub_clk_src = {
  135. .cmd_rcgr = 0x93f0,
  136. .mnd_width = 0,
  137. .hid_width = 5,
  138. .parent_map = gpu_cc_parent_map_0,
  139. .hw_clk_ctrl = true,
  140. .freq_tbl = ftbl_gpu_cc_hub_clk_src,
  141. .clkr.hw.init = &(const struct clk_init_data) {
  142. .name = "gpu_cc_hub_clk_src",
  143. .parent_data = gpu_cc_parent_data_0,
  144. .num_parents = ARRAY_SIZE(gpu_cc_parent_data_0),
  145. .flags = CLK_SET_RATE_PARENT,
  146. .ops = &clk_rcg2_shared_ops,
  147. },
  148. };
  149. static struct clk_regmap_div gpu_cc_hub_div_clk_src = {
  150. .reg = 0x9430,
  151. .shift = 0,
  152. .width = 4,
  153. .clkr.hw.init = &(const struct clk_init_data) {
  154. .name = "gpu_cc_hub_div_clk_src",
  155. .parent_hws = (const struct clk_hw*[]) {
  156. &gpu_cc_hub_clk_src.clkr.hw,
  157. },
  158. .num_parents = 1,
  159. .flags = CLK_SET_RATE_PARENT,
  160. .ops = &clk_regmap_div_ro_ops,
  161. },
  162. };
  163. static struct clk_branch gpu_cc_ahb_clk = {
  164. .halt_reg = 0x90bc,
  165. .halt_check = BRANCH_HALT_DELAY,
  166. .clkr = {
  167. .enable_reg = 0x90bc,
  168. .enable_mask = BIT(0),
  169. .hw.init = &(const struct clk_init_data) {
  170. .name = "gpu_cc_ahb_clk",
  171. .parent_hws = (const struct clk_hw*[]) {
  172. &gpu_cc_hub_div_clk_src.clkr.hw,
  173. },
  174. .num_parents = 1,
  175. .flags = CLK_SET_RATE_PARENT,
  176. .ops = &clk_branch2_ops,
  177. },
  178. },
  179. };
  180. static struct clk_branch gpu_cc_cx_accu_shift_clk = {
  181. .halt_reg = 0x9104,
  182. .halt_check = BRANCH_HALT_VOTED,
  183. .clkr = {
  184. .enable_reg = 0x9104,
  185. .enable_mask = BIT(0),
  186. .hw.init = &(const struct clk_init_data) {
  187. .name = "gpu_cc_cx_accu_shift_clk",
  188. .ops = &clk_branch2_ops,
  189. },
  190. },
  191. };
  192. static struct clk_branch gpu_cc_cx_gmu_clk = {
  193. .halt_reg = 0x90d4,
  194. .halt_check = BRANCH_HALT_VOTED,
  195. .clkr = {
  196. .enable_reg = 0x90d4,
  197. .enable_mask = BIT(0),
  198. .hw.init = &(const struct clk_init_data) {
  199. .name = "gpu_cc_cx_gmu_clk",
  200. .parent_hws = (const struct clk_hw*[]) {
  201. &gpu_cc_gmu_clk_src.clkr.hw,
  202. },
  203. .num_parents = 1,
  204. .flags = CLK_SET_RATE_PARENT,
  205. .ops = &clk_branch2_aon_ops,
  206. },
  207. },
  208. };
  209. static struct clk_branch gpu_cc_cxo_clk = {
  210. .halt_reg = 0x90e4,
  211. .halt_check = BRANCH_HALT,
  212. .clkr = {
  213. .enable_reg = 0x90e4,
  214. .enable_mask = BIT(0),
  215. .hw.init = &(const struct clk_init_data) {
  216. .name = "gpu_cc_cxo_clk",
  217. .ops = &clk_branch2_aon_ops,
  218. },
  219. },
  220. };
  221. static struct clk_branch gpu_cc_demet_clk = {
  222. .halt_reg = 0x9010,
  223. .halt_check = BRANCH_HALT_VOTED,
  224. .clkr = {
  225. .enable_reg = 0x9010,
  226. .enable_mask = BIT(0),
  227. .hw.init = &(const struct clk_init_data) {
  228. .name = "gpu_cc_demet_clk",
  229. .ops = &clk_branch2_ops,
  230. },
  231. },
  232. };
  233. static struct clk_branch gpu_cc_dpm_clk = {
  234. .halt_reg = 0x9108,
  235. .halt_check = BRANCH_HALT,
  236. .clkr = {
  237. .enable_reg = 0x9108,
  238. .enable_mask = BIT(0),
  239. .hw.init = &(const struct clk_init_data) {
  240. .name = "gpu_cc_dpm_clk",
  241. .ops = &clk_branch2_ops,
  242. },
  243. },
  244. };
  245. static struct clk_branch gpu_cc_freq_measure_clk = {
  246. .halt_reg = 0x900c,
  247. .halt_check = BRANCH_HALT,
  248. .clkr = {
  249. .enable_reg = 0x900c,
  250. .enable_mask = BIT(0),
  251. .hw.init = &(const struct clk_init_data) {
  252. .name = "gpu_cc_freq_measure_clk",
  253. .ops = &clk_branch2_ops,
  254. },
  255. },
  256. };
  257. static struct clk_branch gpu_cc_gpu_smmu_vote_clk = {
  258. .halt_reg = 0x7000,
  259. .halt_check = BRANCH_HALT_VOTED,
  260. .clkr = {
  261. .enable_reg = 0x7000,
  262. .enable_mask = BIT(0),
  263. .hw.init = &(const struct clk_init_data) {
  264. .name = "gpu_cc_gpu_smmu_vote_clk",
  265. .ops = &clk_branch2_ops,
  266. },
  267. },
  268. };
  269. static struct clk_branch gpu_cc_gx_accu_shift_clk = {
  270. .halt_reg = 0x9070,
  271. .halt_check = BRANCH_HALT_VOTED,
  272. .clkr = {
  273. .enable_reg = 0x9070,
  274. .enable_mask = BIT(0),
  275. .hw.init = &(const struct clk_init_data) {
  276. .name = "gpu_cc_gx_accu_shift_clk",
  277. .ops = &clk_branch2_ops,
  278. },
  279. },
  280. };
  281. static struct clk_branch gpu_cc_gx_gmu_clk = {
  282. .halt_reg = 0x9060,
  283. .halt_check = BRANCH_HALT,
  284. .clkr = {
  285. .enable_reg = 0x9060,
  286. .enable_mask = BIT(0),
  287. .hw.init = &(const struct clk_init_data) {
  288. .name = "gpu_cc_gx_gmu_clk",
  289. .parent_hws = (const struct clk_hw*[]) {
  290. &gpu_cc_gmu_clk_src.clkr.hw,
  291. },
  292. .num_parents = 1,
  293. .flags = CLK_SET_RATE_PARENT,
  294. .ops = &clk_branch2_ops,
  295. },
  296. },
  297. };
  298. static struct clk_branch gpu_cc_hub_aon_clk = {
  299. .halt_reg = 0x93ec,
  300. .halt_check = BRANCH_HALT_VOTED,
  301. .clkr = {
  302. .enable_reg = 0x93ec,
  303. .enable_mask = BIT(0),
  304. .hw.init = &(const struct clk_init_data) {
  305. .name = "gpu_cc_hub_aon_clk",
  306. .parent_hws = (const struct clk_hw*[]) {
  307. &gpu_cc_hub_clk_src.clkr.hw,
  308. },
  309. .num_parents = 1,
  310. .flags = CLK_SET_RATE_PARENT,
  311. .ops = &clk_branch2_aon_ops,
  312. },
  313. },
  314. };
  315. static struct clk_branch gpu_cc_hub_cx_int_clk = {
  316. .halt_reg = 0x90e8,
  317. .halt_check = BRANCH_HALT_VOTED,
  318. .clkr = {
  319. .enable_reg = 0x90e8,
  320. .enable_mask = BIT(0),
  321. .hw.init = &(const struct clk_init_data) {
  322. .name = "gpu_cc_hub_cx_int_clk",
  323. .parent_hws = (const struct clk_hw*[]) {
  324. &gpu_cc_hub_clk_src.clkr.hw,
  325. },
  326. .num_parents = 1,
  327. .flags = CLK_SET_RATE_PARENT,
  328. .ops = &clk_branch2_aon_ops,
  329. },
  330. },
  331. };
  332. static struct clk_branch gpu_cc_memnoc_gfx_clk = {
  333. .halt_reg = 0x90ec,
  334. .halt_check = BRANCH_HALT_VOTED,
  335. .clkr = {
  336. .enable_reg = 0x90ec,
  337. .enable_mask = BIT(0),
  338. .hw.init = &(const struct clk_init_data) {
  339. .name = "gpu_cc_memnoc_gfx_clk",
  340. .ops = &clk_branch2_ops,
  341. },
  342. },
  343. };
  344. static struct gdsc gpu_cc_cx_gdsc = {
  345. .gdscr = 0x9080,
  346. .gds_hw_ctrl = 0x9094,
  347. .en_rest_wait_val = 0x2,
  348. .en_few_wait_val = 0x2,
  349. .clk_dis_wait_val = 0x8,
  350. .pd = {
  351. .name = "gpu_cc_cx_gdsc",
  352. },
  353. .pwrsts = PWRSTS_OFF_ON,
  354. .flags = POLL_CFG_GDSCR | RETAIN_FF_ENABLE,
  355. };
  356. static struct clk_regmap *gpu_cc_kaanapali_clocks[] = {
  357. [GPU_CC_AHB_CLK] = &gpu_cc_ahb_clk.clkr,
  358. [GPU_CC_CX_ACCU_SHIFT_CLK] = &gpu_cc_cx_accu_shift_clk.clkr,
  359. [GPU_CC_CX_GMU_CLK] = &gpu_cc_cx_gmu_clk.clkr,
  360. [GPU_CC_CXO_CLK] = &gpu_cc_cxo_clk.clkr,
  361. [GPU_CC_DEMET_CLK] = &gpu_cc_demet_clk.clkr,
  362. [GPU_CC_DPM_CLK] = &gpu_cc_dpm_clk.clkr,
  363. [GPU_CC_FREQ_MEASURE_CLK] = &gpu_cc_freq_measure_clk.clkr,
  364. [GPU_CC_GMU_CLK_SRC] = &gpu_cc_gmu_clk_src.clkr,
  365. [GPU_CC_GPU_SMMU_VOTE_CLK] = &gpu_cc_gpu_smmu_vote_clk.clkr,
  366. [GPU_CC_GX_ACCU_SHIFT_CLK] = &gpu_cc_gx_accu_shift_clk.clkr,
  367. [GPU_CC_GX_GMU_CLK] = &gpu_cc_gx_gmu_clk.clkr,
  368. [GPU_CC_HUB_AON_CLK] = &gpu_cc_hub_aon_clk.clkr,
  369. [GPU_CC_HUB_CLK_SRC] = &gpu_cc_hub_clk_src.clkr,
  370. [GPU_CC_HUB_CX_INT_CLK] = &gpu_cc_hub_cx_int_clk.clkr,
  371. [GPU_CC_HUB_DIV_CLK_SRC] = &gpu_cc_hub_div_clk_src.clkr,
  372. [GPU_CC_MEMNOC_GFX_CLK] = &gpu_cc_memnoc_gfx_clk.clkr,
  373. [GPU_CC_PLL0] = &gpu_cc_pll0.clkr,
  374. [GPU_CC_PLL0_OUT_EVEN] = &gpu_cc_pll0_out_even.clkr,
  375. };
  376. static struct gdsc *gpu_cc_kaanapali_gdscs[] = {
  377. [GPU_CC_CX_GDSC] = &gpu_cc_cx_gdsc,
  378. };
  379. static const struct qcom_reset_map gpu_cc_kaanapali_resets[] = {
  380. [GPU_CC_CB_BCR] = { 0x93a0 },
  381. [GPU_CC_CX_BCR] = { 0x907c },
  382. [GPU_CC_FAST_HUB_BCR] = { 0x93e4 },
  383. [GPU_CC_FF_BCR] = { 0x9470 },
  384. [GPU_CC_GMU_BCR] = { 0x9314 },
  385. [GPU_CC_GX_BCR] = { 0x905c },
  386. [GPU_CC_XO_BCR] = { 0x9000 },
  387. };
  388. static struct clk_alpha_pll *gpu_cc_kaanapali_plls[] = {
  389. &gpu_cc_pll0,
  390. };
  391. static u32 gpu_cc_kaanapali_critical_cbcrs[] = {
  392. 0x9008, /* GPU_CC_CXO_AON_CLK */
  393. 0x93e8, /* GPU_CC_RSCC_HUB_AON_CLK */
  394. 0x9004, /* GPU_CC_RSCC_XO_AON_CLK */
  395. };
  396. static const struct regmap_config gpu_cc_kaanapali_regmap_config = {
  397. .reg_bits = 32,
  398. .reg_stride = 4,
  399. .val_bits = 32,
  400. .max_register = 0x95e8,
  401. .fast_io = true,
  402. };
  403. static struct qcom_cc_driver_data gpu_cc_kaanapali_driver_data = {
  404. .alpha_plls = gpu_cc_kaanapali_plls,
  405. .num_alpha_plls = ARRAY_SIZE(gpu_cc_kaanapali_plls),
  406. .clk_cbcrs = gpu_cc_kaanapali_critical_cbcrs,
  407. .num_clk_cbcrs = ARRAY_SIZE(gpu_cc_kaanapali_critical_cbcrs),
  408. };
  409. static const struct qcom_cc_desc gpu_cc_kaanapali_desc = {
  410. .config = &gpu_cc_kaanapali_regmap_config,
  411. .clks = gpu_cc_kaanapali_clocks,
  412. .num_clks = ARRAY_SIZE(gpu_cc_kaanapali_clocks),
  413. .resets = gpu_cc_kaanapali_resets,
  414. .num_resets = ARRAY_SIZE(gpu_cc_kaanapali_resets),
  415. .gdscs = gpu_cc_kaanapali_gdscs,
  416. .num_gdscs = ARRAY_SIZE(gpu_cc_kaanapali_gdscs),
  417. .use_rpm = true,
  418. .driver_data = &gpu_cc_kaanapali_driver_data,
  419. };
  420. static const struct of_device_id gpu_cc_kaanapali_match_table[] = {
  421. { .compatible = "qcom,kaanapali-gpucc" },
  422. { }
  423. };
  424. MODULE_DEVICE_TABLE(of, gpu_cc_kaanapali_match_table);
  425. static int gpu_cc_kaanapali_probe(struct platform_device *pdev)
  426. {
  427. return qcom_cc_probe(pdev, &gpu_cc_kaanapali_desc);
  428. }
  429. static struct platform_driver gpu_cc_kaanapali_driver = {
  430. .probe = gpu_cc_kaanapali_probe,
  431. .driver = {
  432. .name = "gpucc-kaanapali",
  433. .of_match_table = gpu_cc_kaanapali_match_table,
  434. },
  435. };
  436. module_platform_driver(gpu_cc_kaanapali_driver);
  437. MODULE_DESCRIPTION("QTI GPUCC Kaanapali Driver");
  438. MODULE_LICENSE("GPL");