lpasscorecc-sc7280.c 13 KB

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