videocc-volcano.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #include <linux/clk.h>
  6. #include <linux/clk-provider.h>
  7. #include <linux/err.h>
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/of_device.h>
  11. #include <linux/of.h>
  12. #include <linux/regmap.h>
  13. #include <linux/pm_runtime.h>
  14. #include <dt-bindings/clock/qcom,videocc-volcano.h>
  15. #include "clk-alpha-pll.h"
  16. #include "clk-branch.h"
  17. #include "clk-pll.h"
  18. #include "clk-rcg.h"
  19. #include "clk-regmap.h"
  20. #include "clk-regmap-divider.h"
  21. #include "clk-regmap-mux.h"
  22. #include "common.h"
  23. #include "reset.h"
  24. #include "vdd-level.h"
  25. static DEFINE_VDD_REGULATORS(vdd_cx, VDD_HIGH + 1, 1, vdd_corner);
  26. static DEFINE_VDD_REGULATORS(vdd_mx, VDD_HIGH + 1, 1, vdd_corner);
  27. static struct clk_vdd_class *video_cc_volcano_regulators[] = {
  28. &vdd_cx,
  29. &vdd_mx,
  30. };
  31. enum {
  32. P_BI_TCXO,
  33. P_SLEEP_CLK,
  34. P_VIDEO_CC_PLL0_OUT_MAIN,
  35. };
  36. static const struct pll_vco lucid_ole_vco[] = {
  37. { 249600000, 2300000000, 0 },
  38. };
  39. /* 604.8 MHz Configuration */
  40. static const struct alpha_pll_config video_cc_pll0_config = {
  41. .l = 0x1f,
  42. .cal_l = 0x44,
  43. .cal_l_ringosc = 0x44,
  44. .alpha = 0x8000,
  45. .config_ctl_val = 0x20485699,
  46. .config_ctl_hi_val = 0x00182261,
  47. .config_ctl_hi1_val = 0x82aa299c,
  48. .test_ctl_val = 0x00000000,
  49. .test_ctl_hi_val = 0x00000003,
  50. .test_ctl_hi1_val = 0x00009000,
  51. .test_ctl_hi2_val = 0x00000034,
  52. .user_ctl_val = 0x00000000,
  53. .user_ctl_hi_val = 0x00000005,
  54. };
  55. static struct clk_alpha_pll video_cc_pll0 = {
  56. .offset = 0x0,
  57. .vco_table = lucid_ole_vco,
  58. .num_vco = ARRAY_SIZE(lucid_ole_vco),
  59. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_OLE],
  60. .clkr = {
  61. .hw.init = &(const struct clk_init_data) {
  62. .name = "video_cc_pll0",
  63. .parent_data = &(const struct clk_parent_data) {
  64. .fw_name = "bi_tcxo",
  65. },
  66. .num_parents = 1,
  67. .ops = &clk_alpha_pll_lucid_ole_ops,
  68. },
  69. .vdd_data = {
  70. .vdd_class = &vdd_mx,
  71. .num_rate_max = VDD_NUM,
  72. .rate_max = (unsigned long[VDD_NUM]) {
  73. [VDD_LOWER_D1] = 615000000,
  74. [VDD_LOW] = 1100000000,
  75. [VDD_LOW_L1] = 1600000000,
  76. [VDD_NOMINAL] = 2000000000,
  77. [VDD_HIGH_L1] = 2300000000},
  78. },
  79. },
  80. };
  81. static const struct parent_map video_cc_parent_map_0[] = {
  82. { P_BI_TCXO, 0 },
  83. };
  84. static const struct clk_parent_data video_cc_parent_data_0[] = {
  85. { .fw_name = "bi_tcxo" },
  86. };
  87. static const struct clk_parent_data video_cc_parent_data_0_ao[] = {
  88. { .fw_name = "bi_tcxo_ao" },
  89. };
  90. static const struct parent_map video_cc_parent_map_1[] = {
  91. { P_BI_TCXO, 0 },
  92. { P_VIDEO_CC_PLL0_OUT_MAIN, 1 },
  93. };
  94. static const struct clk_parent_data video_cc_parent_data_1[] = {
  95. { .fw_name = "bi_tcxo" },
  96. { .hw = &video_cc_pll0.clkr.hw },
  97. };
  98. static const struct parent_map video_cc_parent_map_2[] = {
  99. { P_SLEEP_CLK, 0 },
  100. };
  101. static const struct clk_parent_data video_cc_parent_data_2_ao[] = {
  102. { .fw_name = "sleep_clk" },
  103. };
  104. static const struct freq_tbl ftbl_video_cc_ahb_clk_src[] = {
  105. F(19200000, P_BI_TCXO, 1, 0, 0),
  106. { }
  107. };
  108. static struct clk_rcg2 video_cc_ahb_clk_src = {
  109. .cmd_rcgr = 0x8030,
  110. .mnd_width = 0,
  111. .hid_width = 5,
  112. .parent_map = video_cc_parent_map_0,
  113. .freq_tbl = ftbl_video_cc_ahb_clk_src,
  114. .enable_safe_config = true,
  115. .flags = HW_CLK_CTRL_MODE,
  116. .clkr.hw.init = &(const struct clk_init_data) {
  117. .name = "video_cc_ahb_clk_src",
  118. .parent_data = video_cc_parent_data_0_ao,
  119. .num_parents = ARRAY_SIZE(video_cc_parent_data_0_ao),
  120. .flags = CLK_SET_RATE_PARENT,
  121. .ops = &clk_rcg2_ops,
  122. },
  123. };
  124. static const struct freq_tbl ftbl_video_cc_mvs0_clk_src[] = {
  125. F(604800000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  126. F(720000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  127. F(1014000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  128. F(1098000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  129. F(1332000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  130. F(1656000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  131. { }
  132. };
  133. static struct clk_rcg2 video_cc_mvs0_clk_src = {
  134. .cmd_rcgr = 0x8000,
  135. .mnd_width = 0,
  136. .hid_width = 5,
  137. .parent_map = video_cc_parent_map_1,
  138. .freq_tbl = ftbl_video_cc_mvs0_clk_src,
  139. .enable_safe_config = true,
  140. .flags = HW_CLK_CTRL_MODE,
  141. .clkr.hw.init = &(const struct clk_init_data) {
  142. .name = "video_cc_mvs0_clk_src",
  143. .parent_data = video_cc_parent_data_1,
  144. .num_parents = ARRAY_SIZE(video_cc_parent_data_1),
  145. .flags = CLK_SET_RATE_PARENT,
  146. .ops = &clk_rcg2_ops,
  147. },
  148. .clkr.vdd_data = {
  149. .vdd_classes = video_cc_volcano_regulators,
  150. .num_vdd_classes = ARRAY_SIZE(video_cc_volcano_regulators),
  151. .num_rate_max = VDD_NUM,
  152. .rate_max = (unsigned long[VDD_NUM]) {
  153. [VDD_LOWER] = 720000000,
  154. [VDD_LOW] = 1014000000,
  155. [VDD_LOW_L1] = 1098000000,
  156. [VDD_NOMINAL] = 1332000000,
  157. [VDD_HIGH] = 1656000000},
  158. },
  159. };
  160. static const struct freq_tbl ftbl_video_cc_sleep_clk_src[] = {
  161. F(32000, P_SLEEP_CLK, 1, 0, 0),
  162. { }
  163. };
  164. static struct clk_rcg2 video_cc_sleep_clk_src = {
  165. .cmd_rcgr = 0x8128,
  166. .mnd_width = 0,
  167. .hid_width = 5,
  168. .parent_map = video_cc_parent_map_2,
  169. .freq_tbl = ftbl_video_cc_sleep_clk_src,
  170. .clkr.hw.init = &(const struct clk_init_data) {
  171. .name = "video_cc_sleep_clk_src",
  172. .parent_data = video_cc_parent_data_2_ao,
  173. .num_parents = ARRAY_SIZE(video_cc_parent_data_2_ao),
  174. .flags = CLK_SET_RATE_PARENT,
  175. .ops = &clk_rcg2_ops,
  176. },
  177. };
  178. static struct clk_rcg2 video_cc_xo_clk_src = {
  179. .cmd_rcgr = 0x810c,
  180. .mnd_width = 0,
  181. .hid_width = 5,
  182. .parent_map = video_cc_parent_map_0,
  183. .freq_tbl = ftbl_video_cc_ahb_clk_src,
  184. .clkr.hw.init = &(const struct clk_init_data) {
  185. .name = "video_cc_xo_clk_src",
  186. .parent_data = video_cc_parent_data_0,
  187. .num_parents = ARRAY_SIZE(video_cc_parent_data_0),
  188. .flags = CLK_SET_RATE_PARENT,
  189. .ops = &clk_rcg2_ops,
  190. },
  191. .clkr.vdd_data = {
  192. .vdd_class = &vdd_cx,
  193. .num_rate_max = VDD_NUM,
  194. .rate_max = (unsigned long[VDD_NUM]) {
  195. [VDD_LOWER] = 19200000},
  196. },
  197. };
  198. static struct clk_regmap_div video_cc_mvs0_div_clk_src = {
  199. .reg = 0x80c4,
  200. .shift = 0,
  201. .width = 4,
  202. .clkr.hw.init = &(const struct clk_init_data) {
  203. .name = "video_cc_mvs0_div_clk_src",
  204. .parent_hws = (const struct clk_hw*[]) {
  205. &video_cc_mvs0_clk_src.clkr.hw,
  206. },
  207. .num_parents = 1,
  208. .flags = CLK_SET_RATE_PARENT,
  209. .ops = &clk_regmap_div_ro_ops,
  210. },
  211. };
  212. static struct clk_regmap_div video_cc_mvs0c_div2_div_clk_src = {
  213. .reg = 0x8070,
  214. .shift = 0,
  215. .width = 4,
  216. .clkr.hw.init = &(const struct clk_init_data) {
  217. .name = "video_cc_mvs0c_div2_div_clk_src",
  218. .parent_hws = (const struct clk_hw*[]) {
  219. &video_cc_mvs0_clk_src.clkr.hw,
  220. },
  221. .num_parents = 1,
  222. .flags = CLK_SET_RATE_PARENT,
  223. .ops = &clk_regmap_div_ro_ops,
  224. },
  225. };
  226. static struct clk_branch video_cc_mvs0_clk = {
  227. .halt_reg = 0x80b8,
  228. .halt_check = BRANCH_HALT_VOTED,
  229. .hwcg_reg = 0x80b8,
  230. .hwcg_bit = 1,
  231. .clkr = {
  232. .enable_reg = 0x80b8,
  233. .enable_mask = BIT(0),
  234. .hw.init = &(const struct clk_init_data) {
  235. .name = "video_cc_mvs0_clk",
  236. .parent_hws = (const struct clk_hw*[]) {
  237. &video_cc_mvs0_div_clk_src.clkr.hw,
  238. },
  239. .num_parents = 1,
  240. .flags = CLK_SET_RATE_PARENT,
  241. .ops = &clk_branch2_ops,
  242. },
  243. },
  244. };
  245. static struct clk_branch video_cc_mvs0_shift_clk = {
  246. .halt_reg = 0x8144,
  247. .halt_check = BRANCH_HALT_VOTED,
  248. .hwcg_reg = 0x8144,
  249. .hwcg_bit = 1,
  250. .clkr = {
  251. .enable_reg = 0x8144,
  252. .enable_mask = BIT(0),
  253. .hw.init = &(const struct clk_init_data) {
  254. .name = "video_cc_mvs0_shift_clk",
  255. .parent_hws = (const struct clk_hw*[]) {
  256. &video_cc_xo_clk_src.clkr.hw,
  257. },
  258. .num_parents = 1,
  259. .flags = CLK_SET_RATE_PARENT,
  260. .ops = &clk_branch2_ops,
  261. },
  262. },
  263. };
  264. static struct clk_branch video_cc_mvs0c_clk = {
  265. .halt_reg = 0x8064,
  266. .halt_check = BRANCH_HALT,
  267. .clkr = {
  268. .enable_reg = 0x8064,
  269. .enable_mask = BIT(0),
  270. .hw.init = &(const struct clk_init_data) {
  271. .name = "video_cc_mvs0c_clk",
  272. .parent_hws = (const struct clk_hw*[]) {
  273. &video_cc_mvs0c_div2_div_clk_src.clkr.hw,
  274. },
  275. .num_parents = 1,
  276. .flags = CLK_SET_RATE_PARENT,
  277. .ops = &clk_branch2_ops,
  278. },
  279. },
  280. };
  281. static struct clk_branch video_cc_mvs0c_shift_clk = {
  282. .halt_reg = 0x8148,
  283. .halt_check = BRANCH_HALT_VOTED,
  284. .hwcg_reg = 0x8148,
  285. .hwcg_bit = 1,
  286. .clkr = {
  287. .enable_reg = 0x8148,
  288. .enable_mask = BIT(0),
  289. .hw.init = &(const struct clk_init_data) {
  290. .name = "video_cc_mvs0c_shift_clk",
  291. .parent_hws = (const struct clk_hw*[]) {
  292. &video_cc_xo_clk_src.clkr.hw,
  293. },
  294. .num_parents = 1,
  295. .flags = CLK_SET_RATE_PARENT,
  296. .ops = &clk_branch2_ops,
  297. },
  298. },
  299. };
  300. static struct clk_regmap *video_cc_volcano_clocks[] = {
  301. [VIDEO_CC_AHB_CLK_SRC] = &video_cc_ahb_clk_src.clkr,
  302. [VIDEO_CC_MVS0_CLK] = &video_cc_mvs0_clk.clkr,
  303. [VIDEO_CC_MVS0_CLK_SRC] = &video_cc_mvs0_clk_src.clkr,
  304. [VIDEO_CC_MVS0_DIV_CLK_SRC] = &video_cc_mvs0_div_clk_src.clkr,
  305. [VIDEO_CC_MVS0_SHIFT_CLK] = &video_cc_mvs0_shift_clk.clkr,
  306. [VIDEO_CC_MVS0C_CLK] = &video_cc_mvs0c_clk.clkr,
  307. [VIDEO_CC_MVS0C_DIV2_DIV_CLK_SRC] = &video_cc_mvs0c_div2_div_clk_src.clkr,
  308. [VIDEO_CC_MVS0C_SHIFT_CLK] = &video_cc_mvs0c_shift_clk.clkr,
  309. [VIDEO_CC_PLL0] = &video_cc_pll0.clkr,
  310. [VIDEO_CC_SLEEP_CLK_SRC] = &video_cc_sleep_clk_src.clkr,
  311. [VIDEO_CC_XO_CLK_SRC] = &video_cc_xo_clk_src.clkr,
  312. };
  313. static const struct qcom_reset_map video_cc_volcano_resets[] = {
  314. [VIDEO_CC_INTERFACE_BCR] = { 0x80f0 },
  315. [VIDEO_CC_MVS0_BCR] = { 0x80a0 },
  316. [VIDEO_CC_MVS0C_CLK_ARES] = { 0x8064, 2 },
  317. [VIDEO_CC_MVS0C_BCR] = { 0x8048 },
  318. };
  319. static const struct regmap_config video_cc_volcano_regmap_config = {
  320. .reg_bits = 32,
  321. .reg_stride = 4,
  322. .val_bits = 32,
  323. .max_register = 0x9f50,
  324. .fast_io = true,
  325. };
  326. static struct qcom_cc_desc video_cc_volcano_desc = {
  327. .config = &video_cc_volcano_regmap_config,
  328. .clks = video_cc_volcano_clocks,
  329. .num_clks = ARRAY_SIZE(video_cc_volcano_clocks),
  330. .resets = video_cc_volcano_resets,
  331. .num_resets = ARRAY_SIZE(video_cc_volcano_resets),
  332. .clk_regulators = video_cc_volcano_regulators,
  333. .num_clk_regulators = ARRAY_SIZE(video_cc_volcano_regulators),
  334. };
  335. static const struct of_device_id video_cc_volcano_match_table[] = {
  336. { .compatible = "qcom,volcano-videocc" },
  337. { }
  338. };
  339. MODULE_DEVICE_TABLE(of, video_cc_volcano_match_table);
  340. static int video_cc_volcano_probe(struct platform_device *pdev)
  341. {
  342. struct regmap *regmap;
  343. int ret;
  344. regmap = qcom_cc_map(pdev, &video_cc_volcano_desc);
  345. if (IS_ERR(regmap))
  346. return PTR_ERR(regmap);
  347. ret = qcom_cc_runtime_init(pdev, &video_cc_volcano_desc);
  348. if (ret)
  349. return ret;
  350. ret = pm_runtime_get_sync(&pdev->dev);
  351. if (ret)
  352. return ret;
  353. clk_lucid_ole_pll_configure(&video_cc_pll0, regmap, &video_cc_pll0_config);
  354. /*
  355. * Keep clocks always enabled:
  356. * video_cc_ahb_clk
  357. * video_cc_sleep_clk
  358. * video_cc_xo_clk
  359. */
  360. regmap_update_bits(regmap, 0x80f4, BIT(0), BIT(0));
  361. regmap_update_bits(regmap, 0x8140, BIT(0), BIT(0));
  362. regmap_update_bits(regmap, 0x8124, BIT(0), BIT(0));
  363. ret = qcom_cc_really_probe(pdev, &video_cc_volcano_desc, regmap);
  364. if (ret) {
  365. dev_err(&pdev->dev, "Failed to register VIDEO CC clocks\n");
  366. return ret;
  367. }
  368. pm_runtime_put_sync(&pdev->dev);
  369. dev_info(&pdev->dev, "Registered VIDEO CC clocks\n");
  370. return ret;
  371. }
  372. static void video_cc_volcano_sync_state(struct device *dev)
  373. {
  374. qcom_cc_sync_state(dev, &video_cc_volcano_desc);
  375. }
  376. static const struct dev_pm_ops video_cc_volcano_pm_ops = {
  377. SET_RUNTIME_PM_OPS(qcom_cc_runtime_suspend, qcom_cc_runtime_resume, NULL)
  378. SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
  379. pm_runtime_force_resume)
  380. };
  381. static struct platform_driver video_cc_volcano_driver = {
  382. .probe = video_cc_volcano_probe,
  383. .driver = {
  384. .name = "video_cc-volcano",
  385. .of_match_table = video_cc_volcano_match_table,
  386. .sync_state = video_cc_volcano_sync_state,
  387. .pm = &video_cc_volcano_pm_ops,
  388. },
  389. };
  390. static int __init video_cc_volcano_init(void)
  391. {
  392. return platform_driver_register(&video_cc_volcano_driver);
  393. }
  394. subsys_initcall(video_cc_volcano_init);
  395. static void __exit video_cc_volcano_exit(void)
  396. {
  397. platform_driver_unregister(&video_cc_volcano_driver);
  398. }
  399. module_exit(video_cc_volcano_exit);
  400. MODULE_DESCRIPTION("QTI VIDEO_CC VOLCANO Driver");
  401. MODULE_LICENSE("GPL");