videocc-sm6150.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  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 <dt-bindings/clock/qcom,videocc-sm6150.h>
  14. #include "clk-alpha-pll.h"
  15. #include "clk-branch.h"
  16. #include "clk-pm.h"
  17. #include "clk-rcg.h"
  18. #include "clk-regmap.h"
  19. #include "common.h"
  20. #include "vdd-level-sm6150.h"
  21. static DEFINE_VDD_REGULATORS(vdd_cx, VDD_NUM, 1, vdd_corner);
  22. enum {
  23. P_BI_TCXO,
  24. P_SLEEP_CLK,
  25. P_VIDEO_PLL0_OUT_AUX,
  26. P_VIDEO_PLL0_OUT_AUX2,
  27. P_VIDEO_PLL0_OUT_MAIN,
  28. };
  29. static struct pll_vco spark_vco[] = {
  30. { 500000000, 1000000000, 2 },
  31. };
  32. /* 600MHz configuration */
  33. static struct alpha_pll_config video_pll0_config = {
  34. .l = 0x1F,
  35. .alpha_hi = 0x40,
  36. .alpha = 0x00,
  37. .alpha_en_mask = BIT(24),
  38. .vco_val = 0x2 << 20,
  39. .vco_mask = 0x3 << 20,
  40. .main_output_mask = BIT(0),
  41. .config_ctl_val = 0x4001055b,
  42. .test_ctl_hi_val = 0x1,
  43. .test_ctl_hi_mask = 0x1,
  44. };
  45. static struct clk_init_data video_pll0_sa6155 = {
  46. .name = "video_pll0",
  47. .parent_data = &(const struct clk_parent_data){
  48. .fw_name = "bi_tcxo",
  49. },
  50. .num_parents = 1,
  51. .ops = &clk_alpha_pll_slew_ops,
  52. };
  53. static struct clk_alpha_pll video_pll0 = {
  54. .offset = 0x42c,
  55. .vco_table = spark_vco,
  56. .num_vco = ARRAY_SIZE(spark_vco),
  57. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT],
  58. .flags = SUPPORTS_DYNAMIC_UPDATE,
  59. .config = &video_pll0_config,
  60. .clkr = {
  61. .hw.init = &(struct clk_init_data){
  62. .name = "video_pll0",
  63. .parent_data = &(const struct clk_parent_data){
  64. .fw_name = "bi_tcxo",
  65. },
  66. .num_parents = 1,
  67. .ops = &clk_alpha_pll_ops,
  68. },
  69. .vdd_data = {
  70. .vdd_class = &vdd_cx,
  71. .num_rate_max = VDD_NUM,
  72. .rate_max = (unsigned long[VDD_NUM]) {
  73. [VDD_MIN] = 1100000000,
  74. [VDD_NOMINAL] = 2000000000},
  75. },
  76. },
  77. };
  78. static const struct parent_map video_cc_parent_map_0[] = {
  79. { P_SLEEP_CLK, 0 },
  80. };
  81. static const struct clk_parent_data video_cc_parent_data_0[] = {
  82. { .fw_name = "sleep_clk"},
  83. };
  84. static const struct parent_map video_cc_parent_map_1[] = {
  85. { P_BI_TCXO, 0 },
  86. { P_VIDEO_PLL0_OUT_MAIN, 1 },
  87. { P_VIDEO_PLL0_OUT_AUX, 2 },
  88. { P_VIDEO_PLL0_OUT_AUX2, 3 },
  89. };
  90. static const struct clk_parent_data video_cc_parent_data_1[] = {
  91. { .fw_name = "bi_tcxo"},
  92. { .hw = &video_pll0.clkr.hw },
  93. { .hw = &video_pll0.clkr.hw },
  94. { .hw = &video_pll0.clkr.hw },
  95. };
  96. static const struct freq_tbl ftbl_video_cc_sleep_clk_src[] = {
  97. F(32000, P_SLEEP_CLK, 1, 0, 0),
  98. { }
  99. };
  100. static struct clk_rcg2 video_cc_sleep_clk_src = {
  101. .cmd_rcgr = 0xaf8,
  102. .mnd_width = 0,
  103. .hid_width = 5,
  104. .parent_map = video_cc_parent_map_0,
  105. .freq_tbl = ftbl_video_cc_sleep_clk_src,
  106. .clkr.hw.init = &(struct clk_init_data){
  107. .name = "video_cc_sleep_clk_src",
  108. .parent_data = video_cc_parent_data_0,
  109. .num_parents = ARRAY_SIZE(video_cc_parent_data_0),
  110. .ops = &clk_rcg2_ops,
  111. },
  112. .clkr.vdd_data = {
  113. .vdd_class = &vdd_cx,
  114. .num_rate_max = VDD_NUM,
  115. .rate_max = (unsigned long[VDD_NUM]) {
  116. [VDD_LOWER] = 32000},
  117. },
  118. };
  119. static const struct freq_tbl ftbl_video_cc_venus_clk_src[] = {
  120. F(19200000, P_BI_TCXO, 1, 0, 0),
  121. F(133333333, P_VIDEO_PLL0_OUT_MAIN, 4.5, 0, 0),
  122. F(240000000, P_VIDEO_PLL0_OUT_MAIN, 2.5, 0, 0),
  123. F(300000000, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
  124. F(380000000, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
  125. F(410000000, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
  126. F(460000000, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
  127. { }
  128. };
  129. static struct clk_rcg2 video_cc_venus_clk_src = {
  130. .cmd_rcgr = 0x7f0,
  131. .mnd_width = 0,
  132. .hid_width = 5,
  133. .parent_map = video_cc_parent_map_1,
  134. .freq_tbl = ftbl_video_cc_venus_clk_src,
  135. .enable_safe_config = true,
  136. .clkr.hw.init = &(struct clk_init_data){
  137. .name = "video_cc_venus_clk_src",
  138. .parent_data = video_cc_parent_data_1,
  139. .num_parents = ARRAY_SIZE(video_cc_parent_data_1),
  140. .flags = CLK_SET_RATE_PARENT,
  141. .ops = &clk_rcg2_ops,
  142. },
  143. .clkr.vdd_data = {
  144. .vdd_class = &vdd_cx,
  145. .num_rate_max = VDD_NUM,
  146. .rate_max = (unsigned long[VDD_NUM]) {
  147. [VDD_LOWER] = 133333333,
  148. [VDD_LOW] = 240000000,
  149. [VDD_LOW_L1] = 300000000,
  150. [VDD_NOMINAL] = 380000000,
  151. [VDD_NOMINAL_L1] = 410000000,
  152. [VDD_HIGH] = 460000000},
  153. },
  154. };
  155. static struct clk_branch video_cc_sleep_clk = {
  156. .halt_reg = 0xb18,
  157. .halt_check = BRANCH_HALT,
  158. .clkr = {
  159. .enable_reg = 0xb18,
  160. .enable_mask = BIT(0),
  161. .hw.init = &(struct clk_init_data){
  162. .name = "video_cc_sleep_clk",
  163. .parent_data = &(const struct clk_parent_data){
  164. .hw = &video_cc_sleep_clk_src.clkr.hw,
  165. },
  166. .num_parents = 1,
  167. .flags = CLK_SET_RATE_PARENT,
  168. .ops = &clk_branch2_ops,
  169. },
  170. },
  171. };
  172. static struct clk_branch video_cc_vcodec0_axi_clk = {
  173. .halt_reg = 0x8f0,
  174. .halt_check = BRANCH_HALT,
  175. .clkr = {
  176. .enable_reg = 0x8f0,
  177. .enable_mask = BIT(0),
  178. .hw.init = &(struct clk_init_data){
  179. .name = "video_cc_vcodec0_axi_clk",
  180. .ops = &clk_branch2_ops,
  181. },
  182. },
  183. };
  184. static struct clk_branch video_cc_vcodec0_core_clk = {
  185. .halt_reg = 0x890,
  186. .halt_check = BRANCH_HALT_VOTED,
  187. .clkr = {
  188. .enable_reg = 0x890,
  189. .enable_mask = BIT(0),
  190. .hw.init = &(struct clk_init_data){
  191. .name = "video_cc_vcodec0_core_clk",
  192. .parent_data = &(const struct clk_parent_data){
  193. .hw = &video_cc_venus_clk_src.clkr.hw,
  194. },
  195. .num_parents = 1,
  196. .flags = CLK_SET_RATE_PARENT,
  197. .ops = &clk_branch2_ops,
  198. },
  199. },
  200. };
  201. static struct clk_branch video_cc_venus_ahb_clk = {
  202. .halt_reg = 0x9b0,
  203. .halt_check = BRANCH_HALT,
  204. .clkr = {
  205. .enable_reg = 0x9b0,
  206. .enable_mask = BIT(0),
  207. .hw.init = &(struct clk_init_data){
  208. .name = "video_cc_venus_ahb_clk",
  209. .ops = &clk_branch2_ops,
  210. },
  211. },
  212. };
  213. static struct clk_branch video_cc_venus_ctl_axi_clk = {
  214. .halt_reg = 0x8d0,
  215. .halt_check = BRANCH_HALT,
  216. .clkr = {
  217. .enable_reg = 0x8d0,
  218. .enable_mask = BIT(0),
  219. .hw.init = &(struct clk_init_data){
  220. .name = "video_cc_venus_ctl_axi_clk",
  221. .ops = &clk_branch2_ops,
  222. },
  223. },
  224. };
  225. static struct clk_branch video_cc_venus_ctl_core_clk = {
  226. .halt_reg = 0x850,
  227. .halt_check = BRANCH_HALT,
  228. .clkr = {
  229. .enable_reg = 0x850,
  230. .enable_mask = BIT(0),
  231. .hw.init = &(struct clk_init_data){
  232. .name = "video_cc_venus_ctl_core_clk",
  233. .parent_data = &(const struct clk_parent_data){
  234. .hw = &video_cc_venus_clk_src.clkr.hw,
  235. },
  236. .num_parents = 1,
  237. .flags = CLK_SET_RATE_PARENT,
  238. .ops = &clk_branch2_ops,
  239. },
  240. },
  241. };
  242. static struct clk_regmap *video_cc_sm6150_clocks[] = {
  243. [VIDEO_CC_SLEEP_CLK] = &video_cc_sleep_clk.clkr,
  244. [VIDEO_CC_SLEEP_CLK_SRC] = &video_cc_sleep_clk_src.clkr,
  245. [VIDEO_CC_VCODEC0_AXI_CLK] = &video_cc_vcodec0_axi_clk.clkr,
  246. [VIDEO_CC_VCODEC0_CORE_CLK] = &video_cc_vcodec0_core_clk.clkr,
  247. [VIDEO_CC_VENUS_AHB_CLK] = &video_cc_venus_ahb_clk.clkr,
  248. [VIDEO_CC_VENUS_CLK_SRC] = &video_cc_venus_clk_src.clkr,
  249. [VIDEO_CC_VENUS_CTL_AXI_CLK] = &video_cc_venus_ctl_axi_clk.clkr,
  250. [VIDEO_CC_VENUS_CTL_CORE_CLK] = &video_cc_venus_ctl_core_clk.clkr,
  251. [VIDEO_PLL0] = &video_pll0.clkr,
  252. };
  253. static const struct regmap_config video_cc_sm6150_regmap_config = {
  254. .reg_bits = 32,
  255. .reg_stride = 4,
  256. .val_bits = 32,
  257. .max_register = 0xb94,
  258. .fast_io = true,
  259. };
  260. static struct critical_clk_offset critical_clk_list[] = {
  261. { .offset = 0xab8, .mask = BIT(0) },
  262. };
  263. static struct qcom_cc_desc video_cc_sm6150_desc = {
  264. .config = &video_cc_sm6150_regmap_config,
  265. .clks = video_cc_sm6150_clocks,
  266. .num_clks = ARRAY_SIZE(video_cc_sm6150_clocks),
  267. .critical_clk_en = critical_clk_list,
  268. .num_critical_clk = ARRAY_SIZE(critical_clk_list),
  269. };
  270. static const struct of_device_id video_cc_sm6150_match_table[] = {
  271. { .compatible = "qcom,sm6150-videocc" },
  272. { .compatible = "qcom,sa6155-videocc" },
  273. { }
  274. };
  275. MODULE_DEVICE_TABLE(of, video_cc_sm6150_match_table);
  276. static void videocc_sm6150_fixup_sa6155(struct platform_device *pdev)
  277. {
  278. vdd_cx.num_levels = VDD_NUM_SA6155;
  279. vdd_cx.cur_level = VDD_NUM_SA6155;
  280. video_pll0.clkr.hw.init = &video_pll0_sa6155;
  281. }
  282. static int video_cc_sm6150_probe(struct platform_device *pdev)
  283. {
  284. struct regmap *regmap;
  285. int ret, is_sa6155;
  286. vdd_cx.regulator[0] = devm_regulator_get(&pdev->dev, "vdd_cx");
  287. if (IS_ERR(vdd_cx.regulator[0])) {
  288. if (!(PTR_ERR(vdd_cx.regulator[0]) == -EPROBE_DEFER))
  289. dev_err(&pdev->dev,
  290. "Unable to get vdd_cx regulator\n");
  291. return PTR_ERR(vdd_cx.regulator[0]);
  292. }
  293. is_sa6155 = of_device_is_compatible(pdev->dev.of_node,
  294. "qcom,sa6155-videocc");
  295. if (is_sa6155)
  296. videocc_sm6150_fixup_sa6155(pdev);
  297. regmap = qcom_cc_map(pdev, &video_cc_sm6150_desc);
  298. if (IS_ERR(regmap)) {
  299. pr_err("Failed to map the video_cc registers\n");
  300. return PTR_ERR(regmap);
  301. }
  302. clk_alpha_pll_configure(&video_pll0, regmap, video_pll0.config);
  303. /*
  304. * Keep clocks always enabled:
  305. * video_cc_xo_clk
  306. */
  307. regmap_update_bits(regmap, 0xab8, BIT(0), BIT(0));
  308. ret = qcom_cc_really_probe(pdev, &video_cc_sm6150_desc, regmap);
  309. if (ret) {
  310. dev_err(&pdev->dev, "Failed to register VIDEO CC clocks\n");
  311. return ret;
  312. }
  313. ret = register_qcom_clks_pm(pdev, false, &video_cc_sm6150_desc);
  314. if (ret)
  315. dev_err(&pdev->dev, "VIDEO CC failed to register for pm ops\n");
  316. dev_info(&pdev->dev, "Registered VIDEO CC clocks\n");
  317. return ret;
  318. }
  319. static void video_cc_sm6150_sync_state(struct device *dev)
  320. {
  321. qcom_cc_sync_state(dev, &video_cc_sm6150_desc);
  322. }
  323. static struct platform_driver video_cc_sm6150_driver = {
  324. .probe = video_cc_sm6150_probe,
  325. .driver = {
  326. .name = "video_cc-sm6150",
  327. .of_match_table = video_cc_sm6150_match_table,
  328. .sync_state = video_cc_sm6150_sync_state,
  329. },
  330. };
  331. static int __init video_cc_sm6150_init(void)
  332. {
  333. return platform_driver_register(&video_cc_sm6150_driver);
  334. }
  335. subsys_initcall(video_cc_sm6150_init);
  336. static void __exit video_cc_sm6150_exit(void)
  337. {
  338. platform_driver_unregister(&video_cc_sm6150_driver);
  339. }
  340. module_exit(video_cc_sm6150_exit);
  341. MODULE_DESCRIPTION("QTI VIDEO_CC SM6150 Driver");
  342. MODULE_LICENSE("GPL");