videocc-sm7150.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2024, Danila Tikhonov <danila@jiaxyga.com>
  5. */
  6. #include <linux/clk-provider.h>
  7. #include <linux/mod_devicetable.h>
  8. #include <linux/module.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/regmap.h>
  11. #include <dt-bindings/clock/qcom,sm7150-videocc.h>
  12. #include "common.h"
  13. #include "clk-alpha-pll.h"
  14. #include "clk-branch.h"
  15. #include "clk-rcg.h"
  16. #include "clk-regmap.h"
  17. #include "clk-pll.h"
  18. #include "gdsc.h"
  19. enum {
  20. DT_BI_TCXO,
  21. DT_BI_TCXO_AO,
  22. };
  23. enum {
  24. P_BI_TCXO,
  25. P_VIDEOCC_PLL0_OUT_EVEN,
  26. P_VIDEOCC_PLL0_OUT_MAIN,
  27. P_VIDEOCC_PLL0_OUT_ODD,
  28. };
  29. static const struct pll_vco fabia_vco[] = {
  30. { 249600000, 2000000000, 0 },
  31. { 125000000, 1000000000, 1 },
  32. };
  33. static struct alpha_pll_config videocc_pll0_config = {
  34. .l = 0x19,
  35. .alpha = 0x0,
  36. .config_ctl_val = 0x20485699,
  37. .config_ctl_hi_val = 0x00002067,
  38. .user_ctl_val = 0x00000001,
  39. .user_ctl_hi_val = 0x00004805,
  40. .test_ctl_hi_val = 0x40000000,
  41. };
  42. static struct clk_alpha_pll videocc_pll0 = {
  43. .offset = 0x42c,
  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 = "videocc_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 parent_map videocc_parent_map_0[] = {
  59. { P_BI_TCXO, 0 },
  60. { P_VIDEOCC_PLL0_OUT_MAIN, 1 },
  61. { P_VIDEOCC_PLL0_OUT_EVEN, 2 },
  62. { P_VIDEOCC_PLL0_OUT_ODD, 3 },
  63. };
  64. static const struct clk_parent_data videocc_parent_data_0[] = {
  65. { .index = DT_BI_TCXO },
  66. { .hw = &videocc_pll0.clkr.hw },
  67. { .hw = &videocc_pll0.clkr.hw },
  68. { .hw = &videocc_pll0.clkr.hw },
  69. };
  70. static const struct parent_map videocc_parent_map_1[] = {
  71. { P_BI_TCXO, 0 },
  72. };
  73. static const struct clk_parent_data videocc_parent_data_1[] = {
  74. { .index = DT_BI_TCXO_AO },
  75. };
  76. static const struct freq_tbl ftbl_videocc_iris_clk_src[] = {
  77. F(240000000, P_VIDEOCC_PLL0_OUT_MAIN, 2, 0, 0),
  78. F(338000000, P_VIDEOCC_PLL0_OUT_MAIN, 2, 0, 0),
  79. F(365000000, P_VIDEOCC_PLL0_OUT_MAIN, 2, 0, 0),
  80. F(444000000, P_VIDEOCC_PLL0_OUT_MAIN, 2, 0, 0),
  81. F(533000000, P_VIDEOCC_PLL0_OUT_MAIN, 2, 0, 0),
  82. { }
  83. };
  84. static struct clk_rcg2 videocc_iris_clk_src = {
  85. .cmd_rcgr = 0x7f0,
  86. .mnd_width = 0,
  87. .hid_width = 5,
  88. .parent_map = videocc_parent_map_0,
  89. .freq_tbl = ftbl_videocc_iris_clk_src,
  90. .clkr.hw.init = &(const struct clk_init_data) {
  91. .name = "videocc_iris_clk_src",
  92. .parent_data = videocc_parent_data_0,
  93. .num_parents = ARRAY_SIZE(videocc_parent_data_0),
  94. .flags = CLK_SET_RATE_PARENT,
  95. .ops = &clk_rcg2_shared_ops,
  96. },
  97. };
  98. static const struct freq_tbl ftbl_videocc_xo_clk_src[] = {
  99. F(19200000, P_BI_TCXO, 1, 0, 0),
  100. { }
  101. };
  102. static struct clk_rcg2 videocc_xo_clk_src = {
  103. .cmd_rcgr = 0xa98,
  104. .mnd_width = 0,
  105. .hid_width = 5,
  106. .parent_map = videocc_parent_map_1,
  107. .freq_tbl = ftbl_videocc_xo_clk_src,
  108. .clkr.hw.init = &(const struct clk_init_data) {
  109. .name = "videocc_xo_clk_src",
  110. .parent_data = videocc_parent_data_1,
  111. .num_parents = ARRAY_SIZE(videocc_parent_data_1),
  112. .ops = &clk_rcg2_ops,
  113. },
  114. };
  115. static struct clk_branch videocc_iris_ahb_clk = {
  116. .halt_reg = 0x8f4,
  117. .halt_check = BRANCH_VOTED,
  118. .clkr = {
  119. .enable_reg = 0x8f4,
  120. .enable_mask = BIT(0),
  121. .hw.init = &(const struct clk_init_data) {
  122. .name = "videocc_iris_ahb_clk",
  123. .parent_data = &(const struct clk_parent_data) {
  124. .hw = &videocc_iris_clk_src.clkr.hw,
  125. },
  126. .num_parents = 1,
  127. .flags = CLK_SET_RATE_PARENT,
  128. .ops = &clk_branch2_ops,
  129. },
  130. },
  131. };
  132. static struct clk_branch videocc_mvs0_axi_clk = {
  133. .halt_reg = 0x9ec,
  134. .halt_check = BRANCH_HALT,
  135. .clkr = {
  136. .enable_reg = 0x9ec,
  137. .enable_mask = BIT(0),
  138. .hw.init = &(const struct clk_init_data) {
  139. .name = "videocc_mvs0_axi_clk",
  140. .ops = &clk_branch2_ops,
  141. },
  142. },
  143. };
  144. static struct clk_branch videocc_mvs0_core_clk = {
  145. .halt_reg = 0x890,
  146. .halt_check = BRANCH_VOTED,
  147. .clkr = {
  148. .enable_reg = 0x890,
  149. .enable_mask = BIT(0),
  150. .hw.init = &(const struct clk_init_data) {
  151. .name = "videocc_mvs0_core_clk",
  152. .parent_data = &(const struct clk_parent_data) {
  153. .hw = &videocc_iris_clk_src.clkr.hw,
  154. },
  155. .num_parents = 1,
  156. .flags = CLK_SET_RATE_PARENT,
  157. .ops = &clk_branch2_ops,
  158. },
  159. },
  160. };
  161. static struct clk_branch videocc_mvs1_axi_clk = {
  162. .halt_reg = 0xa0c,
  163. .halt_check = BRANCH_HALT,
  164. .clkr = {
  165. .enable_reg = 0xa0c,
  166. .enable_mask = BIT(0),
  167. .hw.init = &(const struct clk_init_data) {
  168. .name = "videocc_mvs1_axi_clk",
  169. .ops = &clk_branch2_ops,
  170. },
  171. },
  172. };
  173. static struct clk_branch videocc_mvs1_core_clk = {
  174. .halt_reg = 0x8d0,
  175. .halt_check = BRANCH_VOTED,
  176. .clkr = {
  177. .enable_reg = 0x8d0,
  178. .enable_mask = BIT(0),
  179. .hw.init = &(const struct clk_init_data) {
  180. .name = "videocc_mvs1_core_clk",
  181. .parent_data = &(const struct clk_parent_data) {
  182. .hw = &videocc_iris_clk_src.clkr.hw,
  183. },
  184. .num_parents = 1,
  185. .flags = CLK_SET_RATE_PARENT,
  186. .ops = &clk_branch2_ops,
  187. },
  188. },
  189. };
  190. static struct clk_branch videocc_mvsc_core_clk = {
  191. .halt_reg = 0x850,
  192. .halt_check = BRANCH_HALT,
  193. .clkr = {
  194. .enable_reg = 0x850,
  195. .enable_mask = BIT(0),
  196. .hw.init = &(const struct clk_init_data) {
  197. .name = "videocc_mvsc_core_clk",
  198. .parent_data = &(const struct clk_parent_data) {
  199. .hw = &videocc_iris_clk_src.clkr.hw,
  200. },
  201. .num_parents = 1,
  202. .flags = CLK_SET_RATE_PARENT,
  203. .ops = &clk_branch2_ops,
  204. },
  205. },
  206. };
  207. static struct clk_branch videocc_mvsc_ctl_axi_clk = {
  208. .halt_reg = 0x9cc,
  209. .halt_check = BRANCH_HALT,
  210. .clkr = {
  211. .enable_reg = 0x9cc,
  212. .enable_mask = BIT(0),
  213. .hw.init = &(const struct clk_init_data) {
  214. .name = "videocc_mvsc_ctl_axi_clk",
  215. .ops = &clk_branch2_ops,
  216. },
  217. },
  218. };
  219. static struct clk_branch videocc_venus_ahb_clk = {
  220. .halt_reg = 0xa6c,
  221. .halt_check = BRANCH_HALT,
  222. .clkr = {
  223. .enable_reg = 0xa6c,
  224. .enable_mask = BIT(0),
  225. .hw.init = &(const struct clk_init_data) {
  226. .name = "videocc_venus_ahb_clk",
  227. .ops = &clk_branch2_ops,
  228. },
  229. },
  230. };
  231. static struct gdsc venus_gdsc = {
  232. .gdscr = 0x814,
  233. .pd = {
  234. .name = "venus_gdsc",
  235. },
  236. .cxcs = (unsigned int []){ 0x850, 0x9cc },
  237. .cxc_count = 2,
  238. .pwrsts = PWRSTS_OFF_ON,
  239. .flags = POLL_CFG_GDSCR,
  240. };
  241. static struct gdsc vcodec0_gdsc = {
  242. .gdscr = 0x874,
  243. .pd = {
  244. .name = "vcodec0_gdsc",
  245. },
  246. .cxcs = (unsigned int []){ 0x890, 0x9ec },
  247. .cxc_count = 2,
  248. .flags = HW_CTRL_TRIGGER | POLL_CFG_GDSCR,
  249. .pwrsts = PWRSTS_OFF_ON,
  250. };
  251. static struct gdsc vcodec1_gdsc = {
  252. .gdscr = 0x8b4,
  253. .pd = {
  254. .name = "vcodec1_gdsc",
  255. },
  256. .cxcs = (unsigned int []){ 0x8d0, 0xa0c },
  257. .cxc_count = 2,
  258. .flags = HW_CTRL_TRIGGER | POLL_CFG_GDSCR,
  259. .pwrsts = PWRSTS_OFF_ON,
  260. };
  261. static struct clk_regmap *videocc_sm7150_clocks[] = {
  262. [VIDEOCC_PLL0] = &videocc_pll0.clkr,
  263. [VIDEOCC_IRIS_AHB_CLK] = &videocc_iris_ahb_clk.clkr,
  264. [VIDEOCC_IRIS_CLK_SRC] = &videocc_iris_clk_src.clkr,
  265. [VIDEOCC_MVS0_AXI_CLK] = &videocc_mvs0_axi_clk.clkr,
  266. [VIDEOCC_MVS0_CORE_CLK] = &videocc_mvs0_core_clk.clkr,
  267. [VIDEOCC_MVS1_AXI_CLK] = &videocc_mvs1_axi_clk.clkr,
  268. [VIDEOCC_MVS1_CORE_CLK] = &videocc_mvs1_core_clk.clkr,
  269. [VIDEOCC_MVSC_CORE_CLK] = &videocc_mvsc_core_clk.clkr,
  270. [VIDEOCC_MVSC_CTL_AXI_CLK] = &videocc_mvsc_ctl_axi_clk.clkr,
  271. [VIDEOCC_VENUS_AHB_CLK] = &videocc_venus_ahb_clk.clkr,
  272. [VIDEOCC_XO_CLK_SRC] = &videocc_xo_clk_src.clkr,
  273. };
  274. static struct gdsc *videocc_sm7150_gdscs[] = {
  275. [VENUS_GDSC] = &venus_gdsc,
  276. [VCODEC0_GDSC] = &vcodec0_gdsc,
  277. [VCODEC1_GDSC] = &vcodec1_gdsc,
  278. };
  279. static const struct regmap_config videocc_sm7150_regmap_config = {
  280. .reg_bits = 32,
  281. .reg_stride = 4,
  282. .val_bits = 32,
  283. .max_register = 0xb94,
  284. .fast_io = true,
  285. };
  286. static const struct qcom_cc_desc videocc_sm7150_desc = {
  287. .config = &videocc_sm7150_regmap_config,
  288. .clks = videocc_sm7150_clocks,
  289. .num_clks = ARRAY_SIZE(videocc_sm7150_clocks),
  290. .gdscs = videocc_sm7150_gdscs,
  291. .num_gdscs = ARRAY_SIZE(videocc_sm7150_gdscs),
  292. };
  293. static const struct of_device_id videocc_sm7150_match_table[] = {
  294. { .compatible = "qcom,sm7150-videocc" },
  295. { }
  296. };
  297. MODULE_DEVICE_TABLE(of, videocc_sm7150_match_table);
  298. static int videocc_sm7150_probe(struct platform_device *pdev)
  299. {
  300. struct regmap *regmap;
  301. regmap = qcom_cc_map(pdev, &videocc_sm7150_desc);
  302. if (IS_ERR(regmap))
  303. return PTR_ERR(regmap);
  304. clk_fabia_pll_configure(&videocc_pll0, regmap, &videocc_pll0_config);
  305. /* Keep some clocks always-on */
  306. qcom_branch_set_clk_en(regmap, 0x984); /* VIDEOCC_XO_CLK */
  307. return qcom_cc_really_probe(&pdev->dev, &videocc_sm7150_desc, regmap);
  308. }
  309. static struct platform_driver videocc_sm7150_driver = {
  310. .probe = videocc_sm7150_probe,
  311. .driver = {
  312. .name = "videocc-sm7150",
  313. .of_match_table = videocc_sm7150_match_table,
  314. },
  315. };
  316. module_platform_driver(videocc_sm7150_driver);
  317. MODULE_DESCRIPTION("Qualcomm SM7150 Video Clock Controller");
  318. MODULE_LICENSE("GPL");