videocc-sc7280.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/clk-provider.h>
  7. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/regmap.h>
  10. #include <dt-bindings/clock/qcom,videocc-sc7280.h>
  11. #include "clk-alpha-pll.h"
  12. #include "clk-branch.h"
  13. #include "clk-rcg.h"
  14. #include "common.h"
  15. #include "reset.h"
  16. #include "gdsc.h"
  17. enum {
  18. P_BI_TCXO,
  19. P_SLEEP_CLK,
  20. P_VIDEO_PLL0_OUT_EVEN,
  21. };
  22. static const struct pll_vco lucid_vco[] = {
  23. { 249600000, 2000000000, 0 },
  24. };
  25. /* 400MHz Configuration */
  26. static const struct alpha_pll_config video_pll0_config = {
  27. .l = 0x14,
  28. .alpha = 0xD555,
  29. .config_ctl_val = 0x20485699,
  30. .config_ctl_hi_val = 0x00002261,
  31. .config_ctl_hi1_val = 0x329A299C,
  32. .user_ctl_val = 0x00000001,
  33. .user_ctl_hi_val = 0x00000805,
  34. .user_ctl_hi1_val = 0x00000000,
  35. };
  36. static struct clk_alpha_pll video_pll0 = {
  37. .offset = 0x0,
  38. .vco_table = lucid_vco,
  39. .num_vco = ARRAY_SIZE(lucid_vco),
  40. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
  41. .clkr = {
  42. .hw.init = &(struct clk_init_data){
  43. .name = "video_pll0",
  44. .parent_data = &(const struct clk_parent_data){
  45. .fw_name = "bi_tcxo",
  46. },
  47. .num_parents = 1,
  48. .ops = &clk_alpha_pll_lucid_ops,
  49. },
  50. },
  51. };
  52. static const struct parent_map video_cc_parent_map_0[] = {
  53. { P_BI_TCXO, 0 },
  54. { P_VIDEO_PLL0_OUT_EVEN, 3 },
  55. };
  56. static const struct clk_parent_data video_cc_parent_data_0[] = {
  57. { .fw_name = "bi_tcxo" },
  58. { .hw = &video_pll0.clkr.hw },
  59. };
  60. static const struct parent_map video_cc_parent_map_1[] = {
  61. { P_SLEEP_CLK, 0 },
  62. };
  63. static const struct clk_parent_data video_cc_parent_data_1[] = {
  64. { .fw_name = "sleep_clk" },
  65. };
  66. static const struct freq_tbl ftbl_video_cc_iris_clk_src[] = {
  67. F(133333333, P_VIDEO_PLL0_OUT_EVEN, 3, 0, 0),
  68. F(240000000, P_VIDEO_PLL0_OUT_EVEN, 2, 0, 0),
  69. F(335000000, P_VIDEO_PLL0_OUT_EVEN, 2, 0, 0),
  70. F(424000000, P_VIDEO_PLL0_OUT_EVEN, 2, 0, 0),
  71. F(460000000, P_VIDEO_PLL0_OUT_EVEN, 2, 0, 0),
  72. { }
  73. };
  74. static struct clk_rcg2 video_cc_iris_clk_src = {
  75. .cmd_rcgr = 0x1000,
  76. .mnd_width = 0,
  77. .hid_width = 5,
  78. .parent_map = video_cc_parent_map_0,
  79. .freq_tbl = ftbl_video_cc_iris_clk_src,
  80. .clkr.hw.init = &(struct clk_init_data){
  81. .name = "video_cc_iris_clk_src",
  82. .parent_data = video_cc_parent_data_0,
  83. .num_parents = ARRAY_SIZE(video_cc_parent_data_0),
  84. .flags = CLK_SET_RATE_PARENT,
  85. .ops = &clk_rcg2_shared_ops,
  86. },
  87. };
  88. static const struct freq_tbl ftbl_video_cc_sleep_clk_src[] = {
  89. F(32000, P_SLEEP_CLK, 1, 0, 0),
  90. { }
  91. };
  92. static struct clk_rcg2 video_cc_sleep_clk_src = {
  93. .cmd_rcgr = 0x701c,
  94. .mnd_width = 0,
  95. .hid_width = 5,
  96. .parent_map = video_cc_parent_map_1,
  97. .freq_tbl = ftbl_video_cc_sleep_clk_src,
  98. .clkr.hw.init = &(struct clk_init_data){
  99. .name = "video_cc_sleep_clk_src",
  100. .parent_data = video_cc_parent_data_1,
  101. .num_parents = ARRAY_SIZE(video_cc_parent_data_1),
  102. .ops = &clk_rcg2_ops,
  103. },
  104. };
  105. static struct clk_branch video_cc_iris_ahb_clk = {
  106. .halt_reg = 0x5004,
  107. .halt_check = BRANCH_HALT_VOTED,
  108. .clkr = {
  109. .enable_reg = 0x5004,
  110. .enable_mask = BIT(0),
  111. .hw.init = &(struct clk_init_data){
  112. .name = "video_cc_iris_ahb_clk",
  113. .parent_hws = (const struct clk_hw*[]){
  114. &video_cc_iris_clk_src.clkr.hw,
  115. },
  116. .num_parents = 1,
  117. .flags = CLK_SET_RATE_PARENT,
  118. .ops = &clk_branch2_ops,
  119. },
  120. },
  121. };
  122. static struct clk_branch video_cc_mvs0_axi_clk = {
  123. .halt_reg = 0x800c,
  124. .halt_check = BRANCH_HALT,
  125. .clkr = {
  126. .enable_reg = 0x800c,
  127. .enable_mask = BIT(0),
  128. .hw.init = &(struct clk_init_data){
  129. .name = "video_cc_mvs0_axi_clk",
  130. .ops = &clk_branch2_ops,
  131. },
  132. },
  133. };
  134. static struct clk_branch video_cc_mvs0_core_clk = {
  135. .halt_reg = 0x3010,
  136. .halt_check = BRANCH_HALT_VOTED,
  137. .hwcg_reg = 0x3010,
  138. .hwcg_bit = 1,
  139. .clkr = {
  140. .enable_reg = 0x3010,
  141. .enable_mask = BIT(0),
  142. .hw.init = &(struct clk_init_data){
  143. .name = "video_cc_mvs0_core_clk",
  144. .parent_hws = (const struct clk_hw*[]){
  145. &video_cc_iris_clk_src.clkr.hw,
  146. },
  147. .num_parents = 1,
  148. .flags = CLK_SET_RATE_PARENT,
  149. .ops = &clk_branch2_ops,
  150. },
  151. },
  152. };
  153. static struct clk_branch video_cc_mvsc_core_clk = {
  154. .halt_reg = 0x2014,
  155. .halt_check = BRANCH_HALT,
  156. .clkr = {
  157. .enable_reg = 0x2014,
  158. .enable_mask = BIT(0),
  159. .hw.init = &(struct clk_init_data){
  160. .name = "video_cc_mvsc_core_clk",
  161. .parent_hws = (const struct clk_hw*[]){
  162. &video_cc_iris_clk_src.clkr.hw,
  163. },
  164. .num_parents = 1,
  165. .flags = CLK_SET_RATE_PARENT,
  166. .ops = &clk_branch2_ops,
  167. },
  168. },
  169. };
  170. static struct clk_branch video_cc_mvsc_ctl_axi_clk = {
  171. .halt_reg = 0x8004,
  172. .halt_check = BRANCH_HALT,
  173. .clkr = {
  174. .enable_reg = 0x8004,
  175. .enable_mask = BIT(0),
  176. .hw.init = &(struct clk_init_data){
  177. .name = "video_cc_mvsc_ctl_axi_clk",
  178. .ops = &clk_branch2_ops,
  179. },
  180. },
  181. };
  182. static struct clk_branch video_cc_sleep_clk = {
  183. .halt_reg = 0x7034,
  184. .halt_check = BRANCH_HALT,
  185. .clkr = {
  186. .enable_reg = 0x7034,
  187. .enable_mask = BIT(0),
  188. .hw.init = &(struct clk_init_data){
  189. .name = "video_cc_sleep_clk",
  190. .parent_hws = (const struct clk_hw*[]){
  191. &video_cc_sleep_clk_src.clkr.hw,
  192. },
  193. .num_parents = 1,
  194. .flags = CLK_SET_RATE_PARENT,
  195. .ops = &clk_branch2_ops,
  196. },
  197. },
  198. };
  199. static struct clk_branch video_cc_venus_ahb_clk = {
  200. .halt_reg = 0x801c,
  201. .halt_check = BRANCH_HALT,
  202. .clkr = {
  203. .enable_reg = 0x801c,
  204. .enable_mask = BIT(0),
  205. .hw.init = &(struct clk_init_data){
  206. .name = "video_cc_venus_ahb_clk",
  207. .ops = &clk_branch2_ops,
  208. },
  209. },
  210. };
  211. static struct gdsc mvs0_gdsc = {
  212. .gdscr = 0x3004,
  213. .en_rest_wait_val = 0x2,
  214. .en_few_wait_val = 0x2,
  215. .clk_dis_wait_val = 0x6,
  216. .pd = {
  217. .name = "mvs0_gdsc",
  218. },
  219. .pwrsts = PWRSTS_OFF_ON,
  220. .flags = HW_CTRL_TRIGGER | RETAIN_FF_ENABLE,
  221. };
  222. static struct gdsc mvsc_gdsc = {
  223. .gdscr = 0x2004,
  224. .en_rest_wait_val = 0x2,
  225. .en_few_wait_val = 0x2,
  226. .clk_dis_wait_val = 0x6,
  227. .pd = {
  228. .name = "mvsc_gdsc",
  229. },
  230. .flags = RETAIN_FF_ENABLE,
  231. .pwrsts = PWRSTS_OFF_ON,
  232. };
  233. static struct clk_regmap *video_cc_sc7280_clocks[] = {
  234. [VIDEO_CC_IRIS_AHB_CLK] = &video_cc_iris_ahb_clk.clkr,
  235. [VIDEO_CC_IRIS_CLK_SRC] = &video_cc_iris_clk_src.clkr,
  236. [VIDEO_CC_MVS0_AXI_CLK] = &video_cc_mvs0_axi_clk.clkr,
  237. [VIDEO_CC_MVS0_CORE_CLK] = &video_cc_mvs0_core_clk.clkr,
  238. [VIDEO_CC_MVSC_CORE_CLK] = &video_cc_mvsc_core_clk.clkr,
  239. [VIDEO_CC_MVSC_CTL_AXI_CLK] = &video_cc_mvsc_ctl_axi_clk.clkr,
  240. [VIDEO_CC_SLEEP_CLK] = &video_cc_sleep_clk.clkr,
  241. [VIDEO_CC_SLEEP_CLK_SRC] = &video_cc_sleep_clk_src.clkr,
  242. [VIDEO_CC_VENUS_AHB_CLK] = &video_cc_venus_ahb_clk.clkr,
  243. [VIDEO_PLL0] = &video_pll0.clkr,
  244. };
  245. static struct gdsc *video_cc_sc7280_gdscs[] = {
  246. [MVS0_GDSC] = &mvs0_gdsc,
  247. [MVSC_GDSC] = &mvsc_gdsc,
  248. };
  249. static const struct regmap_config video_cc_sc7280_regmap_config = {
  250. .reg_bits = 32,
  251. .reg_stride = 4,
  252. .val_bits = 32,
  253. .max_register = 0xb000,
  254. .fast_io = true,
  255. };
  256. static const struct qcom_cc_desc video_cc_sc7280_desc = {
  257. .config = &video_cc_sc7280_regmap_config,
  258. .clks = video_cc_sc7280_clocks,
  259. .num_clks = ARRAY_SIZE(video_cc_sc7280_clocks),
  260. .gdscs = video_cc_sc7280_gdscs,
  261. .num_gdscs = ARRAY_SIZE(video_cc_sc7280_gdscs),
  262. };
  263. static const struct of_device_id video_cc_sc7280_match_table[] = {
  264. { .compatible = "qcom,sc7280-videocc" },
  265. { }
  266. };
  267. MODULE_DEVICE_TABLE(of, video_cc_sc7280_match_table);
  268. static int video_cc_sc7280_probe(struct platform_device *pdev)
  269. {
  270. struct regmap *regmap;
  271. regmap = qcom_cc_map(pdev, &video_cc_sc7280_desc);
  272. if (IS_ERR(regmap))
  273. return PTR_ERR(regmap);
  274. clk_lucid_pll_configure(&video_pll0, regmap, &video_pll0_config);
  275. return qcom_cc_really_probe(&pdev->dev, &video_cc_sc7280_desc, regmap);
  276. }
  277. static struct platform_driver video_cc_sc7280_driver = {
  278. .probe = video_cc_sc7280_probe,
  279. .driver = {
  280. .name = "video_cc-sc7280",
  281. .of_match_table = video_cc_sc7280_match_table,
  282. },
  283. };
  284. module_platform_driver(video_cc_sc7280_driver);
  285. MODULE_DESCRIPTION("QTI VIDEO_CC sc7280 Driver");
  286. MODULE_LICENSE("GPL v2");