videocc-sc7280.c 7.8 KB

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