videocc-sdm845.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2018, 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-sdm845.h>
  10. #include "common.h"
  11. #include "clk-alpha-pll.h"
  12. #include "clk-branch.h"
  13. #include "clk-rcg.h"
  14. #include "clk-regmap.h"
  15. #include "clk-pll.h"
  16. #include "gdsc.h"
  17. enum {
  18. P_BI_TCXO,
  19. P_CORE_BI_PLL_TEST_SE,
  20. P_VIDEO_PLL0_OUT_EVEN,
  21. P_VIDEO_PLL0_OUT_MAIN,
  22. P_VIDEO_PLL0_OUT_ODD,
  23. };
  24. static const struct parent_map video_cc_parent_map_0[] = {
  25. { P_BI_TCXO, 0 },
  26. { P_VIDEO_PLL0_OUT_MAIN, 1 },
  27. { P_VIDEO_PLL0_OUT_EVEN, 2 },
  28. { P_VIDEO_PLL0_OUT_ODD, 3 },
  29. { P_CORE_BI_PLL_TEST_SE, 4 },
  30. };
  31. static const char * const video_cc_parent_names_0[] = {
  32. "bi_tcxo",
  33. "video_pll0",
  34. "video_pll0_out_even",
  35. "video_pll0_out_odd",
  36. "core_bi_pll_test_se",
  37. };
  38. static const struct alpha_pll_config video_pll0_config = {
  39. .l = 0x10,
  40. .alpha = 0xaaab,
  41. };
  42. static struct clk_alpha_pll video_pll0 = {
  43. .offset = 0x42c,
  44. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA],
  45. .clkr = {
  46. .hw.init = &(struct clk_init_data){
  47. .name = "video_pll0",
  48. .parent_names = (const char *[]){ "bi_tcxo" },
  49. .num_parents = 1,
  50. .ops = &clk_alpha_pll_fabia_ops,
  51. },
  52. },
  53. };
  54. static const struct freq_tbl ftbl_video_cc_venus_clk_src[] = {
  55. F(100000000, P_VIDEO_PLL0_OUT_MAIN, 4, 0, 0),
  56. F(200000000, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
  57. F(330000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
  58. F(404000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
  59. F(444000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
  60. F(533000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
  61. { }
  62. };
  63. static struct clk_rcg2 video_cc_venus_clk_src = {
  64. .cmd_rcgr = 0x7f0,
  65. .mnd_width = 0,
  66. .hid_width = 5,
  67. .parent_map = video_cc_parent_map_0,
  68. .freq_tbl = ftbl_video_cc_venus_clk_src,
  69. .clkr.hw.init = &(struct clk_init_data){
  70. .name = "video_cc_venus_clk_src",
  71. .parent_names = video_cc_parent_names_0,
  72. .num_parents = 5,
  73. .flags = CLK_SET_RATE_PARENT,
  74. .ops = &clk_rcg2_shared_ops,
  75. },
  76. };
  77. static struct clk_branch video_cc_apb_clk = {
  78. .halt_reg = 0x990,
  79. .halt_check = BRANCH_HALT,
  80. .clkr = {
  81. .enable_reg = 0x990,
  82. .enable_mask = BIT(0),
  83. .hw.init = &(struct clk_init_data){
  84. .name = "video_cc_apb_clk",
  85. .ops = &clk_branch2_ops,
  86. },
  87. },
  88. };
  89. static struct clk_branch video_cc_at_clk = {
  90. .halt_reg = 0x9f0,
  91. .halt_check = BRANCH_HALT,
  92. .clkr = {
  93. .enable_reg = 0x9f0,
  94. .enable_mask = BIT(0),
  95. .hw.init = &(struct clk_init_data){
  96. .name = "video_cc_at_clk",
  97. .ops = &clk_branch2_ops,
  98. },
  99. },
  100. };
  101. static struct clk_branch video_cc_qdss_trig_clk = {
  102. .halt_reg = 0x970,
  103. .halt_check = BRANCH_HALT,
  104. .clkr = {
  105. .enable_reg = 0x970,
  106. .enable_mask = BIT(0),
  107. .hw.init = &(struct clk_init_data){
  108. .name = "video_cc_qdss_trig_clk",
  109. .ops = &clk_branch2_ops,
  110. },
  111. },
  112. };
  113. static struct clk_branch video_cc_qdss_tsctr_div8_clk = {
  114. .halt_reg = 0x9d0,
  115. .halt_check = BRANCH_HALT,
  116. .clkr = {
  117. .enable_reg = 0x9d0,
  118. .enable_mask = BIT(0),
  119. .hw.init = &(struct clk_init_data){
  120. .name = "video_cc_qdss_tsctr_div8_clk",
  121. .ops = &clk_branch2_ops,
  122. },
  123. },
  124. };
  125. static struct clk_branch video_cc_vcodec0_axi_clk = {
  126. .halt_reg = 0x930,
  127. .halt_check = BRANCH_HALT,
  128. .clkr = {
  129. .enable_reg = 0x930,
  130. .enable_mask = BIT(0),
  131. .hw.init = &(struct clk_init_data){
  132. .name = "video_cc_vcodec0_axi_clk",
  133. .ops = &clk_branch2_ops,
  134. },
  135. },
  136. };
  137. static struct clk_branch video_cc_vcodec0_core_clk = {
  138. .halt_reg = 0x890,
  139. .halt_check = BRANCH_VOTED,
  140. .clkr = {
  141. .enable_reg = 0x890,
  142. .enable_mask = BIT(0),
  143. .hw.init = &(struct clk_init_data){
  144. .name = "video_cc_vcodec0_core_clk",
  145. .parent_names = (const char *[]){
  146. "video_cc_venus_clk_src",
  147. },
  148. .num_parents = 1,
  149. .flags = CLK_SET_RATE_PARENT,
  150. .ops = &clk_branch2_ops,
  151. },
  152. },
  153. };
  154. static struct clk_branch video_cc_vcodec1_axi_clk = {
  155. .halt_reg = 0x950,
  156. .halt_check = BRANCH_HALT,
  157. .clkr = {
  158. .enable_reg = 0x950,
  159. .enable_mask = BIT(0),
  160. .hw.init = &(struct clk_init_data){
  161. .name = "video_cc_vcodec1_axi_clk",
  162. .ops = &clk_branch2_ops,
  163. },
  164. },
  165. };
  166. static struct clk_branch video_cc_vcodec1_core_clk = {
  167. .halt_reg = 0x8d0,
  168. .halt_check = BRANCH_VOTED,
  169. .clkr = {
  170. .enable_reg = 0x8d0,
  171. .enable_mask = BIT(0),
  172. .hw.init = &(struct clk_init_data){
  173. .name = "video_cc_vcodec1_core_clk",
  174. .parent_names = (const char *[]){
  175. "video_cc_venus_clk_src",
  176. },
  177. .num_parents = 1,
  178. .flags = CLK_SET_RATE_PARENT,
  179. .ops = &clk_branch2_ops,
  180. },
  181. },
  182. };
  183. static struct clk_branch video_cc_venus_ahb_clk = {
  184. .halt_reg = 0x9b0,
  185. .halt_check = BRANCH_HALT,
  186. .clkr = {
  187. .enable_reg = 0x9b0,
  188. .enable_mask = BIT(0),
  189. .hw.init = &(struct clk_init_data){
  190. .name = "video_cc_venus_ahb_clk",
  191. .ops = &clk_branch2_ops,
  192. },
  193. },
  194. };
  195. static struct clk_branch video_cc_venus_ctl_axi_clk = {
  196. .halt_reg = 0x910,
  197. .halt_check = BRANCH_HALT,
  198. .clkr = {
  199. .enable_reg = 0x910,
  200. .enable_mask = BIT(0),
  201. .hw.init = &(struct clk_init_data){
  202. .name = "video_cc_venus_ctl_axi_clk",
  203. .ops = &clk_branch2_ops,
  204. },
  205. },
  206. };
  207. static struct clk_branch video_cc_venus_ctl_core_clk = {
  208. .halt_reg = 0x850,
  209. .halt_check = BRANCH_HALT,
  210. .clkr = {
  211. .enable_reg = 0x850,
  212. .enable_mask = BIT(0),
  213. .hw.init = &(struct clk_init_data){
  214. .name = "video_cc_venus_ctl_core_clk",
  215. .parent_names = (const char *[]){
  216. "video_cc_venus_clk_src",
  217. },
  218. .num_parents = 1,
  219. .flags = CLK_SET_RATE_PARENT,
  220. .ops = &clk_branch2_ops,
  221. },
  222. },
  223. };
  224. static struct gdsc venus_gdsc = {
  225. .gdscr = 0x814,
  226. .pd = {
  227. .name = "venus_gdsc",
  228. },
  229. .cxcs = (unsigned int []){ 0x850, 0x910 },
  230. .cxc_count = 2,
  231. .pwrsts = PWRSTS_OFF_ON,
  232. .flags = POLL_CFG_GDSCR,
  233. };
  234. static struct gdsc vcodec0_gdsc = {
  235. .gdscr = 0x874,
  236. .pd = {
  237. .name = "vcodec0_gdsc",
  238. },
  239. .cxcs = (unsigned int []){ 0x890, 0x930 },
  240. .cxc_count = 2,
  241. .flags = HW_CTRL | POLL_CFG_GDSCR,
  242. .pwrsts = PWRSTS_OFF_ON,
  243. };
  244. static struct gdsc vcodec1_gdsc = {
  245. .gdscr = 0x8b4,
  246. .pd = {
  247. .name = "vcodec1_gdsc",
  248. },
  249. .cxcs = (unsigned int []){ 0x8d0, 0x950 },
  250. .cxc_count = 2,
  251. .flags = HW_CTRL | POLL_CFG_GDSCR,
  252. .pwrsts = PWRSTS_OFF_ON,
  253. };
  254. static struct clk_regmap *video_cc_sdm845_clocks[] = {
  255. [VIDEO_CC_APB_CLK] = &video_cc_apb_clk.clkr,
  256. [VIDEO_CC_AT_CLK] = &video_cc_at_clk.clkr,
  257. [VIDEO_CC_QDSS_TRIG_CLK] = &video_cc_qdss_trig_clk.clkr,
  258. [VIDEO_CC_QDSS_TSCTR_DIV8_CLK] = &video_cc_qdss_tsctr_div8_clk.clkr,
  259. [VIDEO_CC_VCODEC0_AXI_CLK] = &video_cc_vcodec0_axi_clk.clkr,
  260. [VIDEO_CC_VCODEC0_CORE_CLK] = &video_cc_vcodec0_core_clk.clkr,
  261. [VIDEO_CC_VCODEC1_AXI_CLK] = &video_cc_vcodec1_axi_clk.clkr,
  262. [VIDEO_CC_VCODEC1_CORE_CLK] = &video_cc_vcodec1_core_clk.clkr,
  263. [VIDEO_CC_VENUS_AHB_CLK] = &video_cc_venus_ahb_clk.clkr,
  264. [VIDEO_CC_VENUS_CLK_SRC] = &video_cc_venus_clk_src.clkr,
  265. [VIDEO_CC_VENUS_CTL_AXI_CLK] = &video_cc_venus_ctl_axi_clk.clkr,
  266. [VIDEO_CC_VENUS_CTL_CORE_CLK] = &video_cc_venus_ctl_core_clk.clkr,
  267. [VIDEO_PLL0] = &video_pll0.clkr,
  268. };
  269. static struct gdsc *video_cc_sdm845_gdscs[] = {
  270. [VENUS_GDSC] = &venus_gdsc,
  271. [VCODEC0_GDSC] = &vcodec0_gdsc,
  272. [VCODEC1_GDSC] = &vcodec1_gdsc,
  273. };
  274. static const struct regmap_config video_cc_sdm845_regmap_config = {
  275. .reg_bits = 32,
  276. .reg_stride = 4,
  277. .val_bits = 32,
  278. .max_register = 0xb90,
  279. .fast_io = true,
  280. };
  281. static const struct qcom_cc_desc video_cc_sdm845_desc = {
  282. .config = &video_cc_sdm845_regmap_config,
  283. .clks = video_cc_sdm845_clocks,
  284. .num_clks = ARRAY_SIZE(video_cc_sdm845_clocks),
  285. .gdscs = video_cc_sdm845_gdscs,
  286. .num_gdscs = ARRAY_SIZE(video_cc_sdm845_gdscs),
  287. };
  288. static const struct of_device_id video_cc_sdm845_match_table[] = {
  289. { .compatible = "qcom,sdm845-videocc" },
  290. { }
  291. };
  292. MODULE_DEVICE_TABLE(of, video_cc_sdm845_match_table);
  293. static int video_cc_sdm845_probe(struct platform_device *pdev)
  294. {
  295. struct regmap *regmap;
  296. regmap = qcom_cc_map(pdev, &video_cc_sdm845_desc);
  297. if (IS_ERR(regmap))
  298. return PTR_ERR(regmap);
  299. clk_fabia_pll_configure(&video_pll0, regmap, &video_pll0_config);
  300. return qcom_cc_really_probe(pdev, &video_cc_sdm845_desc, regmap);
  301. }
  302. static struct platform_driver video_cc_sdm845_driver = {
  303. .probe = video_cc_sdm845_probe,
  304. .driver = {
  305. .name = "sdm845-videocc",
  306. .of_match_table = video_cc_sdm845_match_table,
  307. },
  308. };
  309. static int __init video_cc_sdm845_init(void)
  310. {
  311. return platform_driver_register(&video_cc_sdm845_driver);
  312. }
  313. subsys_initcall(video_cc_sdm845_init);
  314. static void __exit video_cc_sdm845_exit(void)
  315. {
  316. platform_driver_unregister(&video_cc_sdm845_driver);
  317. }
  318. module_exit(video_cc_sdm845_exit);
  319. MODULE_LICENSE("GPL v2");