videocc-sm8150.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2020, 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/pm_runtime.h>
  9. #include <linux/regmap.h>
  10. #include <dt-bindings/clock/qcom,videocc-sm8150.h>
  11. #include "common.h"
  12. #include "clk-alpha-pll.h"
  13. #include "clk-branch.h"
  14. #include "clk-rcg.h"
  15. #include "clk-regmap.h"
  16. #include "reset.h"
  17. #include "gdsc.h"
  18. enum {
  19. P_BI_TCXO,
  20. P_VIDEO_PLL0_OUT_MAIN,
  21. };
  22. static const struct pll_vco trion_vco[] = {
  23. { 249600000, 2000000000, 0 },
  24. };
  25. static struct alpha_pll_config video_pll0_config = {
  26. .l = 0x14,
  27. .alpha = 0xD555,
  28. .config_ctl_val = 0x20485699,
  29. .config_ctl_hi_val = 0x00002267,
  30. .config_ctl_hi1_val = 0x00000024,
  31. .test_ctl_hi1_val = 0x00000020,
  32. .user_ctl_val = 0x00000000,
  33. .user_ctl_hi_val = 0x00000805,
  34. .user_ctl_hi1_val = 0x000000D0,
  35. };
  36. static struct clk_alpha_pll video_pll0 = {
  37. .offset = 0x42c,
  38. .vco_table = trion_vco,
  39. .num_vco = ARRAY_SIZE(trion_vco),
  40. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_TRION],
  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_trion_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_MAIN, 1 },
  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 freq_tbl ftbl_video_cc_iris_clk_src[] = {
  61. F(19200000, P_BI_TCXO, 1, 0, 0),
  62. F(200000000, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
  63. F(240000000, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
  64. F(338000000, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
  65. F(365000000, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
  66. F(444000000, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
  67. F(533000000, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
  68. { }
  69. };
  70. static struct clk_rcg2 video_cc_iris_clk_src = {
  71. .cmd_rcgr = 0x7f0,
  72. .mnd_width = 0,
  73. .hid_width = 5,
  74. .parent_map = video_cc_parent_map_0,
  75. .freq_tbl = ftbl_video_cc_iris_clk_src,
  76. .clkr.hw.init = &(struct clk_init_data){
  77. .name = "video_cc_iris_clk_src",
  78. .parent_data = video_cc_parent_data_0,
  79. .num_parents = ARRAY_SIZE(video_cc_parent_data_0),
  80. .flags = CLK_SET_RATE_PARENT,
  81. .ops = &clk_rcg2_shared_ops,
  82. },
  83. };
  84. static struct clk_branch video_cc_iris_ahb_clk = {
  85. .halt_reg = 0x8f4,
  86. .halt_check = BRANCH_VOTED,
  87. .clkr = {
  88. .enable_reg = 0x8f4,
  89. .enable_mask = BIT(0),
  90. .hw.init = &(struct clk_init_data){
  91. .name = "video_cc_iris_ahb_clk",
  92. .parent_hws = (const struct clk_hw*[]){
  93. &video_cc_iris_clk_src.clkr.hw,
  94. },
  95. .num_parents = 1,
  96. .flags = CLK_SET_RATE_PARENT,
  97. .ops = &clk_branch2_ops,
  98. },
  99. },
  100. };
  101. static struct clk_branch video_cc_mvs0_core_clk = {
  102. .halt_reg = 0x890,
  103. .halt_check = BRANCH_VOTED,
  104. .clkr = {
  105. .enable_reg = 0x890,
  106. .enable_mask = BIT(0),
  107. .hw.init = &(struct clk_init_data){
  108. .name = "video_cc_mvs0_core_clk",
  109. .parent_hws = (const struct clk_hw*[]){
  110. &video_cc_iris_clk_src.clkr.hw,
  111. },
  112. .num_parents = 1,
  113. .flags = CLK_SET_RATE_PARENT,
  114. .ops = &clk_branch2_ops,
  115. },
  116. },
  117. };
  118. static struct clk_branch video_cc_mvs1_core_clk = {
  119. .halt_reg = 0x8d0,
  120. .halt_check = BRANCH_VOTED,
  121. .clkr = {
  122. .enable_reg = 0x8d0,
  123. .enable_mask = BIT(0),
  124. .hw.init = &(struct clk_init_data){
  125. .name = "video_cc_mvs1_core_clk",
  126. .parent_hws = (const struct clk_hw*[]){
  127. &video_cc_iris_clk_src.clkr.hw,
  128. },
  129. .num_parents = 1,
  130. .flags = CLK_SET_RATE_PARENT,
  131. .ops = &clk_branch2_ops,
  132. },
  133. },
  134. };
  135. static struct clk_branch video_cc_mvsc_core_clk = {
  136. .halt_reg = 0x850,
  137. .halt_check = BRANCH_HALT,
  138. .clkr = {
  139. .enable_reg = 0x850,
  140. .enable_mask = BIT(0),
  141. .hw.init = &(struct clk_init_data){
  142. .name = "video_cc_mvsc_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 gdsc venus_gdsc = {
  153. .gdscr = 0x814,
  154. .pd = {
  155. .name = "venus_gdsc",
  156. },
  157. .flags = 0,
  158. .pwrsts = PWRSTS_OFF_ON,
  159. };
  160. static struct gdsc vcodec0_gdsc = {
  161. .gdscr = 0x874,
  162. .pd = {
  163. .name = "vcodec0_gdsc",
  164. },
  165. .flags = HW_CTRL_TRIGGER,
  166. .pwrsts = PWRSTS_OFF_ON,
  167. };
  168. static struct gdsc vcodec1_gdsc = {
  169. .gdscr = 0x8b4,
  170. .pd = {
  171. .name = "vcodec1_gdsc",
  172. },
  173. .flags = HW_CTRL_TRIGGER,
  174. .pwrsts = PWRSTS_OFF_ON,
  175. };
  176. static struct clk_regmap *video_cc_sm8150_clocks[] = {
  177. [VIDEO_CC_IRIS_AHB_CLK] = &video_cc_iris_ahb_clk.clkr,
  178. [VIDEO_CC_IRIS_CLK_SRC] = &video_cc_iris_clk_src.clkr,
  179. [VIDEO_CC_MVS0_CORE_CLK] = &video_cc_mvs0_core_clk.clkr,
  180. [VIDEO_CC_MVS1_CORE_CLK] = &video_cc_mvs1_core_clk.clkr,
  181. [VIDEO_CC_MVSC_CORE_CLK] = &video_cc_mvsc_core_clk.clkr,
  182. [VIDEO_CC_PLL0] = &video_pll0.clkr,
  183. };
  184. static struct gdsc *video_cc_sm8150_gdscs[] = {
  185. [VENUS_GDSC] = &venus_gdsc,
  186. [VCODEC0_GDSC] = &vcodec0_gdsc,
  187. [VCODEC1_GDSC] = &vcodec1_gdsc,
  188. };
  189. static const struct regmap_config video_cc_sm8150_regmap_config = {
  190. .reg_bits = 32,
  191. .reg_stride = 4,
  192. .val_bits = 32,
  193. .max_register = 0xb94,
  194. .fast_io = true,
  195. };
  196. static const struct qcom_reset_map video_cc_sm8150_resets[] = {
  197. [VIDEO_CC_MVSC_CORE_CLK_BCR] = { .reg = 0x850, .bit = 2, .udelay = 150 },
  198. [VIDEO_CC_INTERFACE_BCR] = { 0x8f0 },
  199. [VIDEO_CC_MVS0_BCR] = { 0x870 },
  200. [VIDEO_CC_MVS1_BCR] = { 0x8b0 },
  201. [VIDEO_CC_MVSC_BCR] = { 0x810 },
  202. };
  203. static const struct qcom_cc_desc video_cc_sm8150_desc = {
  204. .config = &video_cc_sm8150_regmap_config,
  205. .clks = video_cc_sm8150_clocks,
  206. .num_clks = ARRAY_SIZE(video_cc_sm8150_clocks),
  207. .resets = video_cc_sm8150_resets,
  208. .num_resets = ARRAY_SIZE(video_cc_sm8150_resets),
  209. .gdscs = video_cc_sm8150_gdscs,
  210. .num_gdscs = ARRAY_SIZE(video_cc_sm8150_gdscs),
  211. };
  212. static const struct of_device_id video_cc_sm8150_match_table[] = {
  213. { .compatible = "qcom,sm8150-videocc" },
  214. { }
  215. };
  216. MODULE_DEVICE_TABLE(of, video_cc_sm8150_match_table);
  217. static int video_cc_sm8150_probe(struct platform_device *pdev)
  218. {
  219. struct regmap *regmap;
  220. int ret;
  221. ret = devm_pm_runtime_enable(&pdev->dev);
  222. if (ret)
  223. return ret;
  224. ret = pm_runtime_resume_and_get(&pdev->dev);
  225. if (ret)
  226. return ret;
  227. regmap = qcom_cc_map(pdev, &video_cc_sm8150_desc);
  228. if (IS_ERR(regmap)) {
  229. pm_runtime_put_sync(&pdev->dev);
  230. return PTR_ERR(regmap);
  231. }
  232. clk_trion_pll_configure(&video_pll0, regmap, &video_pll0_config);
  233. /* Keep VIDEO_CC_XO_CLK ALWAYS-ON */
  234. regmap_update_bits(regmap, 0x984, 0x1, 0x1);
  235. ret = qcom_cc_really_probe(&pdev->dev, &video_cc_sm8150_desc, regmap);
  236. pm_runtime_put_sync(&pdev->dev);
  237. return ret;
  238. }
  239. static struct platform_driver video_cc_sm8150_driver = {
  240. .probe = video_cc_sm8150_probe,
  241. .driver = {
  242. .name = "video_cc-sm8150",
  243. .of_match_table = video_cc_sm8150_match_table,
  244. },
  245. };
  246. module_platform_driver(video_cc_sm8150_driver);
  247. MODULE_LICENSE("GPL v2");
  248. MODULE_DESCRIPTION("QTI VIDEOCC SM8150 Driver");