lpasscorecc-sc7280.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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/err.h>
  7. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/pm_clock.h>
  10. #include <linux/pm_runtime.h>
  11. #include <linux/regmap.h>
  12. #include <dt-bindings/clock/qcom,lpasscorecc-sc7280.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 "common.h"
  19. #include "gdsc.h"
  20. enum {
  21. P_BI_TCXO,
  22. P_LPASS_CORE_CC_DIG_PLL_OUT_MAIN,
  23. P_LPASS_CORE_CC_DIG_PLL_OUT_MAIN_DIV_CLK_SRC,
  24. P_LPASS_CORE_CC_DIG_PLL_OUT_ODD,
  25. };
  26. static const struct pll_vco lucid_vco[] = {
  27. { 249600000, 2000000000, 0 },
  28. };
  29. /* 614.4MHz configuration */
  30. static const struct alpha_pll_config lpass_core_cc_dig_pll_config = {
  31. .l = 0x20,
  32. .alpha = 0x0,
  33. .config_ctl_val = 0x20485699,
  34. .config_ctl_hi_val = 0x00002261,
  35. .config_ctl_hi1_val = 0xB2923BBC,
  36. .user_ctl_val = 0x00005100,
  37. .user_ctl_hi_val = 0x00050805,
  38. .user_ctl_hi1_val = 0x00000000,
  39. };
  40. static struct clk_alpha_pll lpass_core_cc_dig_pll = {
  41. .offset = 0x1000,
  42. .vco_table = lucid_vco,
  43. .num_vco = ARRAY_SIZE(lucid_vco),
  44. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
  45. .clkr = {
  46. .hw.init = &(struct clk_init_data){
  47. .name = "lpass_core_cc_dig_pll",
  48. .parent_data = &(const struct clk_parent_data){
  49. .index = 0,
  50. },
  51. .num_parents = 1,
  52. .ops = &clk_alpha_pll_lucid_ops,
  53. },
  54. },
  55. };
  56. static const struct clk_div_table post_div_table_lpass_core_cc_dig_pll_out_odd[] = {
  57. { 0x5, 5 },
  58. { }
  59. };
  60. static struct clk_alpha_pll_postdiv lpass_core_cc_dig_pll_out_odd = {
  61. .offset = 0x1000,
  62. .post_div_shift = 12,
  63. .post_div_table = post_div_table_lpass_core_cc_dig_pll_out_odd,
  64. .num_post_div = ARRAY_SIZE(post_div_table_lpass_core_cc_dig_pll_out_odd),
  65. .width = 4,
  66. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
  67. .clkr.hw.init = &(struct clk_init_data){
  68. .name = "lpass_core_cc_dig_pll_out_odd",
  69. .parent_hws = (const struct clk_hw*[]){
  70. &lpass_core_cc_dig_pll.clkr.hw,
  71. },
  72. .num_parents = 1,
  73. .flags = CLK_SET_RATE_PARENT,
  74. .ops = &clk_alpha_pll_postdiv_lucid_ops,
  75. },
  76. };
  77. static struct clk_regmap_div lpass_core_cc_dig_pll_out_main_div_clk_src = {
  78. .reg = 0x1054,
  79. .shift = 0,
  80. .width = 4,
  81. .clkr.hw.init = &(struct clk_init_data) {
  82. .name = "lpass_core_cc_dig_pll_out_main_div_clk_src",
  83. .parent_hws = (const struct clk_hw*[]){
  84. &lpass_core_cc_dig_pll.clkr.hw,
  85. },
  86. .num_parents = 1,
  87. .flags = CLK_SET_RATE_PARENT,
  88. .ops = &clk_regmap_div_ro_ops,
  89. },
  90. };
  91. static const struct parent_map lpass_core_cc_parent_map_0[] = {
  92. { P_BI_TCXO, 0 },
  93. { P_LPASS_CORE_CC_DIG_PLL_OUT_ODD, 5 },
  94. };
  95. static const struct clk_parent_data lpass_core_cc_parent_data_0[] = {
  96. { .index = 0 },
  97. { .hw = &lpass_core_cc_dig_pll_out_odd.clkr.hw },
  98. };
  99. static const struct parent_map lpass_core_cc_parent_map_2[] = {
  100. { P_BI_TCXO, 0 },
  101. { P_LPASS_CORE_CC_DIG_PLL_OUT_MAIN, 1 },
  102. { P_LPASS_CORE_CC_DIG_PLL_OUT_MAIN_DIV_CLK_SRC, 2 },
  103. };
  104. static const struct clk_parent_data lpass_core_cc_parent_data_ao_2[] = {
  105. { .index = 1 },
  106. { .hw = &lpass_core_cc_dig_pll.clkr.hw },
  107. { .hw = &lpass_core_cc_dig_pll_out_main_div_clk_src.clkr.hw },
  108. };
  109. static const struct freq_tbl ftbl_lpass_core_cc_core_clk_src[] = {
  110. F(19200000, P_BI_TCXO, 1, 0, 0),
  111. F(51200000, P_LPASS_CORE_CC_DIG_PLL_OUT_MAIN_DIV_CLK_SRC, 6, 0, 0),
  112. F(102400000, P_LPASS_CORE_CC_DIG_PLL_OUT_MAIN_DIV_CLK_SRC, 3, 0, 0),
  113. F(204800000, P_LPASS_CORE_CC_DIG_PLL_OUT_MAIN, 3, 0, 0),
  114. { }
  115. };
  116. static struct clk_rcg2 lpass_core_cc_core_clk_src = {
  117. .cmd_rcgr = 0x1d000,
  118. .mnd_width = 8,
  119. .hid_width = 5,
  120. .parent_map = lpass_core_cc_parent_map_2,
  121. .freq_tbl = ftbl_lpass_core_cc_core_clk_src,
  122. .clkr.hw.init = &(const struct clk_init_data){
  123. .name = "lpass_core_cc_core_clk_src",
  124. .parent_data = lpass_core_cc_parent_data_ao_2,
  125. .num_parents = ARRAY_SIZE(lpass_core_cc_parent_data_ao_2),
  126. .ops = &clk_rcg2_shared_ops,
  127. },
  128. };
  129. static const struct freq_tbl ftbl_lpass_core_cc_ext_if0_clk_src[] = {
  130. F(256000, P_LPASS_CORE_CC_DIG_PLL_OUT_ODD, 15, 1, 32),
  131. F(512000, P_LPASS_CORE_CC_DIG_PLL_OUT_ODD, 15, 1, 16),
  132. F(768000, P_LPASS_CORE_CC_DIG_PLL_OUT_ODD, 10, 1, 16),
  133. F(1024000, P_LPASS_CORE_CC_DIG_PLL_OUT_ODD, 15, 1, 8),
  134. F(1536000, P_LPASS_CORE_CC_DIG_PLL_OUT_ODD, 10, 1, 8),
  135. F(2048000, P_LPASS_CORE_CC_DIG_PLL_OUT_ODD, 15, 1, 4),
  136. F(3072000, P_LPASS_CORE_CC_DIG_PLL_OUT_ODD, 10, 1, 4),
  137. F(4096000, P_LPASS_CORE_CC_DIG_PLL_OUT_ODD, 15, 1, 2),
  138. F(6144000, P_LPASS_CORE_CC_DIG_PLL_OUT_ODD, 10, 1, 2),
  139. F(8192000, P_LPASS_CORE_CC_DIG_PLL_OUT_ODD, 15, 0, 0),
  140. F(9600000, P_BI_TCXO, 2, 0, 0),
  141. F(12288000, P_LPASS_CORE_CC_DIG_PLL_OUT_ODD, 10, 0, 0),
  142. F(19200000, P_BI_TCXO, 1, 0, 0),
  143. F(24576000, P_LPASS_CORE_CC_DIG_PLL_OUT_ODD, 5, 0, 0),
  144. { }
  145. };
  146. static struct clk_rcg2 lpass_core_cc_ext_if0_clk_src = {
  147. .cmd_rcgr = 0x10000,
  148. .mnd_width = 16,
  149. .hid_width = 5,
  150. .parent_map = lpass_core_cc_parent_map_0,
  151. .freq_tbl = ftbl_lpass_core_cc_ext_if0_clk_src,
  152. .clkr.hw.init = &(const struct clk_init_data){
  153. .name = "lpass_core_cc_ext_if0_clk_src",
  154. .parent_data = lpass_core_cc_parent_data_0,
  155. .num_parents = ARRAY_SIZE(lpass_core_cc_parent_data_0),
  156. .ops = &clk_rcg2_ops,
  157. },
  158. };
  159. static struct clk_rcg2 lpass_core_cc_ext_if1_clk_src = {
  160. .cmd_rcgr = 0x11000,
  161. .mnd_width = 16,
  162. .hid_width = 5,
  163. .parent_map = lpass_core_cc_parent_map_0,
  164. .freq_tbl = ftbl_lpass_core_cc_ext_if0_clk_src,
  165. .clkr.hw.init = &(const struct clk_init_data){
  166. .name = "lpass_core_cc_ext_if1_clk_src",
  167. .parent_data = lpass_core_cc_parent_data_0,
  168. .num_parents = ARRAY_SIZE(lpass_core_cc_parent_data_0),
  169. .ops = &clk_rcg2_ops,
  170. },
  171. };
  172. static struct clk_rcg2 lpass_core_cc_ext_mclk0_clk_src = {
  173. .cmd_rcgr = 0x20000,
  174. .mnd_width = 8,
  175. .hid_width = 5,
  176. .parent_map = lpass_core_cc_parent_map_0,
  177. .freq_tbl = ftbl_lpass_core_cc_ext_if0_clk_src,
  178. .clkr.hw.init = &(const struct clk_init_data){
  179. .name = "lpass_core_cc_ext_mclk0_clk_src",
  180. .parent_data = lpass_core_cc_parent_data_0,
  181. .num_parents = ARRAY_SIZE(lpass_core_cc_parent_data_0),
  182. .ops = &clk_rcg2_ops,
  183. },
  184. };
  185. static struct clk_branch lpass_core_cc_core_clk = {
  186. .halt_reg = 0x1f000,
  187. .halt_check = BRANCH_HALT_VOTED,
  188. .hwcg_reg = 0x1f000,
  189. .hwcg_bit = 1,
  190. .clkr = {
  191. .enable_reg = 0x1f000,
  192. .enable_mask = BIT(0),
  193. .hw.init = &(const struct clk_init_data){
  194. .name = "lpass_core_cc_core_clk",
  195. .parent_hws = (const struct clk_hw*[]){
  196. &lpass_core_cc_core_clk_src.clkr.hw,
  197. },
  198. .num_parents = 1,
  199. .flags = CLK_SET_RATE_PARENT,
  200. .ops = &clk_branch2_aon_ops,
  201. },
  202. },
  203. };
  204. static struct clk_branch lpass_core_cc_ext_if0_ibit_clk = {
  205. .halt_reg = 0x10018,
  206. .halt_check = BRANCH_HALT,
  207. .clkr = {
  208. .enable_reg = 0x10018,
  209. .enable_mask = BIT(0),
  210. .hw.init = &(const struct clk_init_data){
  211. .name = "lpass_core_cc_ext_if0_ibit_clk",
  212. .parent_hws = (const struct clk_hw*[]){
  213. &lpass_core_cc_ext_if0_clk_src.clkr.hw,
  214. },
  215. .num_parents = 1,
  216. .flags = CLK_SET_RATE_PARENT,
  217. .ops = &clk_branch2_ops,
  218. },
  219. },
  220. };
  221. static struct clk_branch lpass_core_cc_ext_if1_ibit_clk = {
  222. .halt_reg = 0x11018,
  223. .halt_check = BRANCH_HALT,
  224. .clkr = {
  225. .enable_reg = 0x11018,
  226. .enable_mask = BIT(0),
  227. .hw.init = &(const struct clk_init_data){
  228. .name = "lpass_core_cc_ext_if1_ibit_clk",
  229. .parent_hws = (const struct clk_hw*[]){
  230. &lpass_core_cc_ext_if1_clk_src.clkr.hw,
  231. },
  232. .num_parents = 1,
  233. .flags = CLK_SET_RATE_PARENT,
  234. .ops = &clk_branch2_ops,
  235. },
  236. },
  237. };
  238. static struct clk_branch lpass_core_cc_lpm_core_clk = {
  239. .halt_reg = 0x1e000,
  240. .halt_check = BRANCH_HALT,
  241. .clkr = {
  242. .enable_reg = 0x1e000,
  243. .enable_mask = BIT(0),
  244. .hw.init = &(const struct clk_init_data){
  245. .name = "lpass_core_cc_lpm_core_clk",
  246. .parent_hws = (const struct clk_hw*[]){
  247. &lpass_core_cc_core_clk_src.clkr.hw,
  248. },
  249. .num_parents = 1,
  250. .flags = CLK_SET_RATE_PARENT,
  251. .ops = &clk_branch2_ops,
  252. },
  253. },
  254. };
  255. static struct clk_branch lpass_core_cc_lpm_mem0_core_clk = {
  256. .halt_reg = 0x1e004,
  257. .halt_check = BRANCH_HALT,
  258. .clkr = {
  259. .enable_reg = 0x1e004,
  260. .enable_mask = BIT(0),
  261. .hw.init = &(const struct clk_init_data){
  262. .name = "lpass_core_cc_lpm_mem0_core_clk",
  263. .parent_hws = (const struct clk_hw*[]){
  264. &lpass_core_cc_core_clk_src.clkr.hw,
  265. },
  266. .num_parents = 1,
  267. .flags = CLK_SET_RATE_PARENT,
  268. .ops = &clk_branch2_ops,
  269. },
  270. },
  271. };
  272. static struct clk_branch lpass_core_cc_ext_mclk0_clk = {
  273. .halt_reg = 0x20014,
  274. .halt_check = BRANCH_HALT,
  275. .clkr = {
  276. .enable_reg = 0x20014,
  277. .enable_mask = BIT(0),
  278. .hw.init = &(const struct clk_init_data){
  279. .name = "lpass_core_cc_ext_mclk0_clk",
  280. .parent_hws = (const struct clk_hw*[]){
  281. &lpass_core_cc_ext_mclk0_clk_src.clkr.hw,
  282. },
  283. .num_parents = 1,
  284. .flags = CLK_SET_RATE_PARENT,
  285. .ops = &clk_branch2_ops,
  286. },
  287. },
  288. };
  289. static struct clk_branch lpass_core_cc_sysnoc_mport_core_clk = {
  290. .halt_reg = 0x23000,
  291. .halt_check = BRANCH_HALT_VOTED,
  292. .hwcg_reg = 0x23000,
  293. .hwcg_bit = 1,
  294. .clkr = {
  295. .enable_reg = 0x23000,
  296. .enable_mask = BIT(0),
  297. .hw.init = &(const struct clk_init_data){
  298. .name = "lpass_core_cc_sysnoc_mport_core_clk",
  299. .parent_hws = (const struct clk_hw*[]){
  300. &lpass_core_cc_core_clk_src.clkr.hw,
  301. },
  302. .num_parents = 1,
  303. .flags = CLK_SET_RATE_PARENT,
  304. .ops = &clk_branch2_ops,
  305. },
  306. },
  307. };
  308. static struct gdsc lpass_core_cc_lpass_core_hm_gdsc = {
  309. .gdscr = 0x0,
  310. .pd = {
  311. .name = "lpass_core_cc_lpass_core_hm_gdsc",
  312. },
  313. .pwrsts = PWRSTS_OFF_ON,
  314. .flags = RETAIN_FF_ENABLE,
  315. };
  316. static struct clk_regmap *lpass_core_cc_sc7280_clocks[] = {
  317. [LPASS_CORE_CC_CORE_CLK] = &lpass_core_cc_core_clk.clkr,
  318. [LPASS_CORE_CC_CORE_CLK_SRC] = &lpass_core_cc_core_clk_src.clkr,
  319. [LPASS_CORE_CC_DIG_PLL] = &lpass_core_cc_dig_pll.clkr,
  320. [LPASS_CORE_CC_DIG_PLL_OUT_MAIN_DIV_CLK_SRC] =
  321. &lpass_core_cc_dig_pll_out_main_div_clk_src.clkr,
  322. [LPASS_CORE_CC_DIG_PLL_OUT_ODD] = &lpass_core_cc_dig_pll_out_odd.clkr,
  323. [LPASS_CORE_CC_EXT_IF0_CLK_SRC] = &lpass_core_cc_ext_if0_clk_src.clkr,
  324. [LPASS_CORE_CC_EXT_IF0_IBIT_CLK] = &lpass_core_cc_ext_if0_ibit_clk.clkr,
  325. [LPASS_CORE_CC_EXT_IF1_CLK_SRC] = &lpass_core_cc_ext_if1_clk_src.clkr,
  326. [LPASS_CORE_CC_EXT_IF1_IBIT_CLK] = &lpass_core_cc_ext_if1_ibit_clk.clkr,
  327. [LPASS_CORE_CC_LPM_CORE_CLK] = &lpass_core_cc_lpm_core_clk.clkr,
  328. [LPASS_CORE_CC_LPM_MEM0_CORE_CLK] = &lpass_core_cc_lpm_mem0_core_clk.clkr,
  329. [LPASS_CORE_CC_SYSNOC_MPORT_CORE_CLK] = &lpass_core_cc_sysnoc_mport_core_clk.clkr,
  330. [LPASS_CORE_CC_EXT_MCLK0_CLK] = &lpass_core_cc_ext_mclk0_clk.clkr,
  331. [LPASS_CORE_CC_EXT_MCLK0_CLK_SRC] = &lpass_core_cc_ext_mclk0_clk_src.clkr,
  332. };
  333. static struct regmap_config lpass_core_cc_sc7280_regmap_config = {
  334. .reg_bits = 32,
  335. .reg_stride = 4,
  336. .val_bits = 32,
  337. .fast_io = true,
  338. };
  339. static const struct qcom_cc_desc lpass_core_cc_sc7280_desc = {
  340. .config = &lpass_core_cc_sc7280_regmap_config,
  341. .clks = lpass_core_cc_sc7280_clocks,
  342. .num_clks = ARRAY_SIZE(lpass_core_cc_sc7280_clocks),
  343. };
  344. static const struct of_device_id lpass_core_cc_sc7280_match_table[] = {
  345. { .compatible = "qcom,sc7280-lpasscorecc" },
  346. { }
  347. };
  348. MODULE_DEVICE_TABLE(of, lpass_core_cc_sc7280_match_table);
  349. static struct gdsc *lpass_core_hm_sc7280_gdscs[] = {
  350. [LPASS_CORE_CC_LPASS_CORE_HM_GDSC] = &lpass_core_cc_lpass_core_hm_gdsc,
  351. };
  352. static const struct qcom_cc_desc lpass_core_hm_sc7280_desc = {
  353. .config = &lpass_core_cc_sc7280_regmap_config,
  354. .gdscs = lpass_core_hm_sc7280_gdscs,
  355. .num_gdscs = ARRAY_SIZE(lpass_core_hm_sc7280_gdscs),
  356. };
  357. static int lpass_core_cc_sc7280_probe(struct platform_device *pdev)
  358. {
  359. const struct qcom_cc_desc *desc;
  360. struct regmap *regmap;
  361. lpass_core_cc_sc7280_regmap_config.name = "lpass_core_cc";
  362. lpass_core_cc_sc7280_regmap_config.max_register = 0x4f004;
  363. desc = &lpass_core_cc_sc7280_desc;
  364. regmap = qcom_cc_map(pdev, desc);
  365. if (IS_ERR(regmap))
  366. return PTR_ERR(regmap);
  367. clk_lucid_pll_configure(&lpass_core_cc_dig_pll, regmap, &lpass_core_cc_dig_pll_config);
  368. return qcom_cc_really_probe(&pdev->dev, &lpass_core_cc_sc7280_desc, regmap);
  369. }
  370. static struct platform_driver lpass_core_cc_sc7280_driver = {
  371. .probe = lpass_core_cc_sc7280_probe,
  372. .driver = {
  373. .name = "lpass_core_cc-sc7280",
  374. .of_match_table = lpass_core_cc_sc7280_match_table,
  375. },
  376. };
  377. static int lpass_hm_core_probe(struct platform_device *pdev)
  378. {
  379. const struct qcom_cc_desc *desc;
  380. lpass_core_cc_sc7280_regmap_config.name = "lpass_hm_core";
  381. lpass_core_cc_sc7280_regmap_config.max_register = 0x24;
  382. desc = &lpass_core_hm_sc7280_desc;
  383. return qcom_cc_probe_by_index(pdev, 0, desc);
  384. }
  385. static const struct of_device_id lpass_hm_sc7280_match_table[] = {
  386. { .compatible = "qcom,sc7280-lpasshm" },
  387. { }
  388. };
  389. MODULE_DEVICE_TABLE(of, lpass_hm_sc7280_match_table);
  390. static struct platform_driver lpass_hm_sc7280_driver = {
  391. .probe = lpass_hm_core_probe,
  392. .driver = {
  393. .name = "lpass_hm-sc7280",
  394. .of_match_table = lpass_hm_sc7280_match_table,
  395. },
  396. };
  397. static int __init lpass_core_cc_sc7280_init(void)
  398. {
  399. int ret;
  400. ret = platform_driver_register(&lpass_hm_sc7280_driver);
  401. if (ret)
  402. return ret;
  403. return platform_driver_register(&lpass_core_cc_sc7280_driver);
  404. }
  405. subsys_initcall(lpass_core_cc_sc7280_init);
  406. static void __exit lpass_core_cc_sc7280_exit(void)
  407. {
  408. platform_driver_unregister(&lpass_core_cc_sc7280_driver);
  409. platform_driver_unregister(&lpass_hm_sc7280_driver);
  410. }
  411. module_exit(lpass_core_cc_sc7280_exit);
  412. MODULE_DESCRIPTION("QTI LPASS_CORE_CC SC7280 Driver");
  413. MODULE_LICENSE("GPL v2");