videocc-sm6350.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021, Konrad Dybcio <konrad.dybcio@somainline.org>
  5. * Copyright (c) 2025, Luca Weiss <luca.weiss@fairphone.com>
  6. */
  7. #include <linux/clk-provider.h>
  8. #include <linux/module.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/regmap.h>
  11. #include <dt-bindings/clock/qcom,sm6350-videocc.h>
  12. #include "clk-alpha-pll.h"
  13. #include "clk-branch.h"
  14. #include "clk-rcg.h"
  15. #include "clk-regmap.h"
  16. #include "common.h"
  17. #include "gdsc.h"
  18. enum {
  19. DT_IFACE,
  20. DT_BI_TCXO,
  21. DT_SLEEP_CLK,
  22. };
  23. enum {
  24. P_BI_TCXO,
  25. P_CHIP_SLEEP_CLK,
  26. P_VIDEO_PLL0_OUT_EVEN,
  27. };
  28. static const struct pll_vco fabia_vco[] = {
  29. { 125000000, 1000000000, 1 },
  30. };
  31. /* 600 MHz */
  32. static const struct alpha_pll_config video_pll0_config = {
  33. .l = 0x1f,
  34. .alpha = 0x4000,
  35. .config_ctl_val = 0x20485699,
  36. .config_ctl_hi_val = 0x00002067,
  37. .test_ctl_val = 0x40000000,
  38. .test_ctl_hi_val = 0x00000002,
  39. .user_ctl_val = 0x00000101,
  40. .user_ctl_hi_val = 0x00004005,
  41. };
  42. static struct clk_alpha_pll video_pll0 = {
  43. .offset = 0x0,
  44. .vco_table = fabia_vco,
  45. .num_vco = ARRAY_SIZE(fabia_vco),
  46. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA],
  47. .clkr = {
  48. .hw.init = &(const struct clk_init_data) {
  49. .name = "video_pll0",
  50. .parent_data = &(const struct clk_parent_data) {
  51. .index = DT_BI_TCXO,
  52. },
  53. .num_parents = 1,
  54. .ops = &clk_alpha_pll_fabia_ops,
  55. },
  56. },
  57. };
  58. static const struct clk_div_table post_div_table_video_pll0_out_even[] = {
  59. { 0x1, 2 },
  60. { }
  61. };
  62. static struct clk_alpha_pll_postdiv video_pll0_out_even = {
  63. .offset = 0x0,
  64. .post_div_shift = 8,
  65. .post_div_table = post_div_table_video_pll0_out_even,
  66. .num_post_div = ARRAY_SIZE(post_div_table_video_pll0_out_even),
  67. .width = 4,
  68. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA],
  69. .clkr.hw.init = &(const struct clk_init_data) {
  70. .name = "video_pll0_out_even",
  71. .parent_hws = (const struct clk_hw*[]) {
  72. &video_pll0.clkr.hw,
  73. },
  74. .num_parents = 1,
  75. .flags = CLK_SET_RATE_PARENT,
  76. .ops = &clk_alpha_pll_postdiv_fabia_ops,
  77. },
  78. };
  79. static const struct parent_map video_cc_parent_map_0[] = {
  80. { P_BI_TCXO, 0 },
  81. { P_VIDEO_PLL0_OUT_EVEN, 3 },
  82. };
  83. static const struct clk_parent_data video_cc_parent_data_0[] = {
  84. { .index = DT_BI_TCXO },
  85. { .hw = &video_pll0_out_even.clkr.hw },
  86. };
  87. static const struct parent_map video_cc_parent_map_1[] = {
  88. { P_CHIP_SLEEP_CLK, 0 },
  89. };
  90. static const struct clk_parent_data video_cc_parent_data_1[] = {
  91. { .index = DT_SLEEP_CLK },
  92. };
  93. static const struct freq_tbl ftbl_video_cc_iris_clk_src[] = {
  94. F(133250000, P_VIDEO_PLL0_OUT_EVEN, 2, 0, 0),
  95. F(240000000, P_VIDEO_PLL0_OUT_EVEN, 1.5, 0, 0),
  96. F(300000000, P_VIDEO_PLL0_OUT_EVEN, 1, 0, 0),
  97. F(380000000, P_VIDEO_PLL0_OUT_EVEN, 1, 0, 0),
  98. F(460000000, P_VIDEO_PLL0_OUT_EVEN, 1, 0, 0),
  99. { }
  100. };
  101. static struct clk_rcg2 video_cc_iris_clk_src = {
  102. .cmd_rcgr = 0x1000,
  103. .mnd_width = 0,
  104. .hid_width = 5,
  105. .parent_map = video_cc_parent_map_0,
  106. .freq_tbl = ftbl_video_cc_iris_clk_src,
  107. .clkr.hw.init = &(const struct clk_init_data) {
  108. .name = "video_cc_iris_clk_src",
  109. .parent_data = video_cc_parent_data_0,
  110. .num_parents = ARRAY_SIZE(video_cc_parent_data_0),
  111. .flags = CLK_SET_RATE_PARENT,
  112. .ops = &clk_rcg2_shared_ops,
  113. },
  114. };
  115. static const struct freq_tbl ftbl_video_cc_sleep_clk_src[] = {
  116. F(32764, P_CHIP_SLEEP_CLK, 1, 0, 0),
  117. { }
  118. };
  119. static struct clk_rcg2 video_cc_sleep_clk_src = {
  120. .cmd_rcgr = 0x701c,
  121. .mnd_width = 0,
  122. .hid_width = 5,
  123. .parent_map = video_cc_parent_map_1,
  124. .freq_tbl = ftbl_video_cc_sleep_clk_src,
  125. .clkr.hw.init = &(const struct clk_init_data) {
  126. .name = "video_cc_sleep_clk_src",
  127. .parent_data = video_cc_parent_data_1,
  128. .num_parents = ARRAY_SIZE(video_cc_parent_data_1),
  129. .ops = &clk_rcg2_ops,
  130. },
  131. };
  132. static struct clk_branch video_cc_iris_ahb_clk = {
  133. .halt_reg = 0x5004,
  134. .halt_check = BRANCH_VOTED,
  135. .clkr = {
  136. .enable_reg = 0x5004,
  137. .enable_mask = BIT(0),
  138. .hw.init = &(const struct clk_init_data) {
  139. .name = "video_cc_iris_ahb_clk",
  140. .parent_hws = (const struct clk_hw*[]) {
  141. &video_cc_iris_clk_src.clkr.hw,
  142. },
  143. .num_parents = 1,
  144. .flags = CLK_SET_RATE_PARENT,
  145. .ops = &clk_branch2_ops,
  146. },
  147. },
  148. };
  149. static struct clk_branch video_cc_mvs0_axi_clk = {
  150. .halt_reg = 0x800c,
  151. .halt_check = BRANCH_HALT,
  152. .clkr = {
  153. .enable_reg = 0x800c,
  154. .enable_mask = BIT(0),
  155. .hw.init = &(const struct clk_init_data) {
  156. .name = "video_cc_mvs0_axi_clk",
  157. .ops = &clk_branch2_ops,
  158. },
  159. },
  160. };
  161. static struct clk_branch video_cc_mvs0_core_clk = {
  162. .halt_reg = 0x3010,
  163. .halt_check = BRANCH_VOTED,
  164. .hwcg_reg = 0x3010,
  165. .hwcg_bit = 1,
  166. .clkr = {
  167. .enable_reg = 0x3010,
  168. .enable_mask = BIT(0),
  169. .hw.init = &(const struct clk_init_data) {
  170. .name = "video_cc_mvs0_core_clk",
  171. .parent_hws = (const struct clk_hw*[]) {
  172. &video_cc_iris_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 video_cc_mvsc_core_clk = {
  181. .halt_reg = 0x2014,
  182. .halt_check = BRANCH_HALT,
  183. .clkr = {
  184. .enable_reg = 0x2014,
  185. .enable_mask = BIT(0),
  186. .hw.init = &(const struct clk_init_data) {
  187. .name = "video_cc_mvsc_core_clk",
  188. .parent_hws = (const struct clk_hw*[]) {
  189. &video_cc_iris_clk_src.clkr.hw,
  190. },
  191. .num_parents = 1,
  192. .flags = CLK_SET_RATE_PARENT,
  193. .ops = &clk_branch2_ops,
  194. },
  195. },
  196. };
  197. static struct clk_branch video_cc_mvsc_ctl_axi_clk = {
  198. .halt_reg = 0x8004,
  199. .halt_check = BRANCH_HALT,
  200. .clkr = {
  201. .enable_reg = 0x8004,
  202. .enable_mask = BIT(0),
  203. .hw.init = &(const struct clk_init_data) {
  204. .name = "video_cc_mvsc_ctl_axi_clk",
  205. .ops = &clk_branch2_ops,
  206. },
  207. },
  208. };
  209. static struct clk_branch video_cc_sleep_clk = {
  210. .halt_reg = 0x7034,
  211. .halt_check = BRANCH_HALT,
  212. .clkr = {
  213. .enable_reg = 0x7034,
  214. .enable_mask = BIT(0),
  215. .hw.init = &(const struct clk_init_data) {
  216. .name = "video_cc_sleep_clk",
  217. .parent_hws = (const struct clk_hw*[]) {
  218. &video_cc_sleep_clk_src.clkr.hw,
  219. },
  220. .num_parents = 1,
  221. .flags = CLK_SET_RATE_PARENT,
  222. .ops = &clk_branch2_ops,
  223. },
  224. },
  225. };
  226. static struct clk_branch video_cc_venus_ahb_clk = {
  227. .halt_reg = 0x801c,
  228. .halt_check = BRANCH_HALT,
  229. .clkr = {
  230. .enable_reg = 0x801c,
  231. .enable_mask = BIT(0),
  232. .hw.init = &(const struct clk_init_data) {
  233. .name = "video_cc_venus_ahb_clk",
  234. .ops = &clk_branch2_ops,
  235. },
  236. },
  237. };
  238. static struct gdsc mvsc_gdsc = {
  239. .gdscr = 0x2004,
  240. .en_rest_wait_val = 0x2,
  241. .en_few_wait_val = 0x2,
  242. .clk_dis_wait_val = 0x6,
  243. .pd = {
  244. .name = "mvsc_gdsc",
  245. },
  246. .pwrsts = PWRSTS_OFF_ON,
  247. };
  248. static struct gdsc mvs0_gdsc = {
  249. .gdscr = 0x3004,
  250. .en_rest_wait_val = 0x2,
  251. .en_few_wait_val = 0x2,
  252. .clk_dis_wait_val = 0x6,
  253. .pd = {
  254. .name = "mvs0_gdsc",
  255. },
  256. .pwrsts = PWRSTS_OFF_ON,
  257. .flags = HW_CTRL_TRIGGER,
  258. };
  259. static struct gdsc *video_cc_sm6350_gdscs[] = {
  260. [MVSC_GDSC] = &mvsc_gdsc,
  261. [MVS0_GDSC] = &mvs0_gdsc,
  262. };
  263. static struct clk_regmap *video_cc_sm6350_clocks[] = {
  264. [VIDEO_CC_IRIS_AHB_CLK] = &video_cc_iris_ahb_clk.clkr,
  265. [VIDEO_CC_IRIS_CLK_SRC] = &video_cc_iris_clk_src.clkr,
  266. [VIDEO_CC_MVS0_AXI_CLK] = &video_cc_mvs0_axi_clk.clkr,
  267. [VIDEO_CC_MVS0_CORE_CLK] = &video_cc_mvs0_core_clk.clkr,
  268. [VIDEO_CC_MVSC_CORE_CLK] = &video_cc_mvsc_core_clk.clkr,
  269. [VIDEO_CC_MVSC_CTL_AXI_CLK] = &video_cc_mvsc_ctl_axi_clk.clkr,
  270. [VIDEO_CC_SLEEP_CLK] = &video_cc_sleep_clk.clkr,
  271. [VIDEO_CC_SLEEP_CLK_SRC] = &video_cc_sleep_clk_src.clkr,
  272. [VIDEO_CC_VENUS_AHB_CLK] = &video_cc_venus_ahb_clk.clkr,
  273. [VIDEO_PLL0] = &video_pll0.clkr,
  274. [VIDEO_PLL0_OUT_EVEN] = &video_pll0_out_even.clkr,
  275. };
  276. static const struct regmap_config video_cc_sm6350_regmap_config = {
  277. .reg_bits = 32,
  278. .reg_stride = 4,
  279. .val_bits = 32,
  280. .max_register = 0xb000,
  281. .fast_io = true,
  282. };
  283. static const struct qcom_cc_desc video_cc_sm6350_desc = {
  284. .config = &video_cc_sm6350_regmap_config,
  285. .clks = video_cc_sm6350_clocks,
  286. .num_clks = ARRAY_SIZE(video_cc_sm6350_clocks),
  287. .gdscs = video_cc_sm6350_gdscs,
  288. .num_gdscs = ARRAY_SIZE(video_cc_sm6350_gdscs),
  289. };
  290. static const struct of_device_id video_cc_sm6350_match_table[] = {
  291. { .compatible = "qcom,sm6350-videocc" },
  292. { }
  293. };
  294. MODULE_DEVICE_TABLE(of, video_cc_sm6350_match_table);
  295. static int video_cc_sm6350_probe(struct platform_device *pdev)
  296. {
  297. struct regmap *regmap;
  298. regmap = qcom_cc_map(pdev, &video_cc_sm6350_desc);
  299. if (IS_ERR(regmap))
  300. return PTR_ERR(regmap);
  301. clk_fabia_pll_configure(&video_pll0, regmap, &video_pll0_config);
  302. /* Keep some clocks always-on */
  303. qcom_branch_set_clk_en(regmap, 0x7018); /* VIDEO_CC_XO_CLK */
  304. return qcom_cc_really_probe(&pdev->dev, &video_cc_sm6350_desc, regmap);
  305. }
  306. static struct platform_driver video_cc_sm6350_driver = {
  307. .probe = video_cc_sm6350_probe,
  308. .driver = {
  309. .name = "video_cc-sm6350",
  310. .of_match_table = video_cc_sm6350_match_table,
  311. },
  312. };
  313. module_platform_driver(video_cc_sm6350_driver);
  314. MODULE_DESCRIPTION("QTI VIDEO_CC SM6350 Driver");
  315. MODULE_LICENSE("GPL");