videocc-sc7180.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2019, 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-sc7180.h>
  10. #include "clk-alpha-pll.h"
  11. #include "clk-branch.h"
  12. #include "clk-rcg.h"
  13. #include "clk-regmap.h"
  14. #include "common.h"
  15. #include "gdsc.h"
  16. enum {
  17. P_BI_TCXO,
  18. P_VIDEO_PLL0_OUT_MAIN,
  19. };
  20. static const struct pll_vco fabia_vco[] = {
  21. { 249600000, 2000000000, 0 },
  22. };
  23. static struct clk_alpha_pll video_pll0 = {
  24. .offset = 0x42c,
  25. .vco_table = fabia_vco,
  26. .num_vco = ARRAY_SIZE(fabia_vco),
  27. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_FABIA],
  28. .clkr = {
  29. .hw.init = &(struct clk_init_data){
  30. .name = "video_pll0",
  31. .parent_data = &(const struct clk_parent_data){
  32. .fw_name = "bi_tcxo",
  33. },
  34. .num_parents = 1,
  35. .ops = &clk_alpha_pll_fabia_ops,
  36. },
  37. },
  38. };
  39. static const struct parent_map video_cc_parent_map_1[] = {
  40. { P_BI_TCXO, 0 },
  41. { P_VIDEO_PLL0_OUT_MAIN, 1 },
  42. };
  43. static const struct clk_parent_data video_cc_parent_data_1[] = {
  44. { .fw_name = "bi_tcxo" },
  45. { .hw = &video_pll0.clkr.hw },
  46. };
  47. static const struct freq_tbl ftbl_video_cc_venus_clk_src[] = {
  48. F(19200000, P_BI_TCXO, 1, 0, 0),
  49. F(150000000, P_VIDEO_PLL0_OUT_MAIN, 4, 0, 0),
  50. F(270000000, P_VIDEO_PLL0_OUT_MAIN, 2.5, 0, 0),
  51. F(340000000, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
  52. F(434000000, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
  53. F(500000000, P_VIDEO_PLL0_OUT_MAIN, 2, 0, 0),
  54. { }
  55. };
  56. static struct clk_rcg2 video_cc_venus_clk_src = {
  57. .cmd_rcgr = 0x7f0,
  58. .mnd_width = 0,
  59. .hid_width = 5,
  60. .parent_map = video_cc_parent_map_1,
  61. .freq_tbl = ftbl_video_cc_venus_clk_src,
  62. .clkr.hw.init = &(struct clk_init_data){
  63. .name = "video_cc_venus_clk_src",
  64. .parent_data = video_cc_parent_data_1,
  65. .num_parents = ARRAY_SIZE(video_cc_parent_data_1),
  66. .flags = CLK_SET_RATE_PARENT,
  67. .ops = &clk_rcg2_shared_ops,
  68. },
  69. };
  70. static struct clk_branch video_cc_vcodec0_axi_clk = {
  71. .halt_reg = 0x9ec,
  72. .halt_check = BRANCH_HALT,
  73. .clkr = {
  74. .enable_reg = 0x9ec,
  75. .enable_mask = BIT(0),
  76. .hw.init = &(struct clk_init_data){
  77. .name = "video_cc_vcodec0_axi_clk",
  78. .ops = &clk_branch2_ops,
  79. },
  80. },
  81. };
  82. static struct clk_branch video_cc_vcodec0_core_clk = {
  83. .halt_reg = 0x890,
  84. .halt_check = BRANCH_HALT_VOTED,
  85. .clkr = {
  86. .enable_reg = 0x890,
  87. .enable_mask = BIT(0),
  88. .hw.init = &(struct clk_init_data){
  89. .name = "video_cc_vcodec0_core_clk",
  90. .parent_hws = (const struct clk_hw*[]){
  91. &video_cc_venus_clk_src.clkr.hw,
  92. },
  93. .num_parents = 1,
  94. .flags = CLK_SET_RATE_PARENT,
  95. .ops = &clk_branch2_ops,
  96. },
  97. },
  98. };
  99. static struct clk_branch video_cc_venus_ahb_clk = {
  100. .halt_reg = 0xa4c,
  101. .halt_check = BRANCH_HALT,
  102. .clkr = {
  103. .enable_reg = 0xa4c,
  104. .enable_mask = BIT(0),
  105. .hw.init = &(struct clk_init_data){
  106. .name = "video_cc_venus_ahb_clk",
  107. .ops = &clk_branch2_ops,
  108. },
  109. },
  110. };
  111. static struct clk_branch video_cc_venus_ctl_axi_clk = {
  112. .halt_reg = 0x9cc,
  113. .halt_check = BRANCH_HALT,
  114. .clkr = {
  115. .enable_reg = 0x9cc,
  116. .enable_mask = BIT(0),
  117. .hw.init = &(struct clk_init_data){
  118. .name = "video_cc_venus_ctl_axi_clk",
  119. .ops = &clk_branch2_ops,
  120. },
  121. },
  122. };
  123. static struct clk_branch video_cc_venus_ctl_core_clk = {
  124. .halt_reg = 0x850,
  125. .halt_check = BRANCH_HALT,
  126. .clkr = {
  127. .enable_reg = 0x850,
  128. .enable_mask = BIT(0),
  129. .hw.init = &(struct clk_init_data){
  130. .name = "video_cc_venus_ctl_core_clk",
  131. .parent_hws = (const struct clk_hw*[]){
  132. &video_cc_venus_clk_src.clkr.hw,
  133. },
  134. .num_parents = 1,
  135. .flags = CLK_SET_RATE_PARENT,
  136. .ops = &clk_branch2_ops,
  137. },
  138. },
  139. };
  140. static struct gdsc venus_gdsc = {
  141. .gdscr = 0x814,
  142. .pd = {
  143. .name = "venus_gdsc",
  144. },
  145. .pwrsts = PWRSTS_OFF_ON,
  146. };
  147. static struct gdsc vcodec0_gdsc = {
  148. .gdscr = 0x874,
  149. .pd = {
  150. .name = "vcodec0_gdsc",
  151. },
  152. .flags = HW_CTRL,
  153. .pwrsts = PWRSTS_OFF_ON,
  154. };
  155. static struct clk_regmap *video_cc_sc7180_clocks[] = {
  156. [VIDEO_CC_VCODEC0_AXI_CLK] = &video_cc_vcodec0_axi_clk.clkr,
  157. [VIDEO_CC_VCODEC0_CORE_CLK] = &video_cc_vcodec0_core_clk.clkr,
  158. [VIDEO_CC_VENUS_AHB_CLK] = &video_cc_venus_ahb_clk.clkr,
  159. [VIDEO_CC_VENUS_CLK_SRC] = &video_cc_venus_clk_src.clkr,
  160. [VIDEO_CC_VENUS_CTL_AXI_CLK] = &video_cc_venus_ctl_axi_clk.clkr,
  161. [VIDEO_CC_VENUS_CTL_CORE_CLK] = &video_cc_venus_ctl_core_clk.clkr,
  162. [VIDEO_PLL0] = &video_pll0.clkr,
  163. };
  164. static struct gdsc *video_cc_sc7180_gdscs[] = {
  165. [VENUS_GDSC] = &venus_gdsc,
  166. [VCODEC0_GDSC] = &vcodec0_gdsc,
  167. };
  168. static const struct regmap_config video_cc_sc7180_regmap_config = {
  169. .reg_bits = 32,
  170. .reg_stride = 4,
  171. .val_bits = 32,
  172. .max_register = 0xb94,
  173. .fast_io = true,
  174. };
  175. static const struct qcom_cc_desc video_cc_sc7180_desc = {
  176. .config = &video_cc_sc7180_regmap_config,
  177. .clks = video_cc_sc7180_clocks,
  178. .num_clks = ARRAY_SIZE(video_cc_sc7180_clocks),
  179. .gdscs = video_cc_sc7180_gdscs,
  180. .num_gdscs = ARRAY_SIZE(video_cc_sc7180_gdscs),
  181. };
  182. static const struct of_device_id video_cc_sc7180_match_table[] = {
  183. { .compatible = "qcom,sc7180-videocc" },
  184. { }
  185. };
  186. MODULE_DEVICE_TABLE(of, video_cc_sc7180_match_table);
  187. static int video_cc_sc7180_probe(struct platform_device *pdev)
  188. {
  189. struct regmap *regmap;
  190. struct alpha_pll_config video_pll0_config = {};
  191. regmap = qcom_cc_map(pdev, &video_cc_sc7180_desc);
  192. if (IS_ERR(regmap))
  193. return PTR_ERR(regmap);
  194. video_pll0_config.l = 0x1f;
  195. video_pll0_config.alpha = 0x4000;
  196. video_pll0_config.user_ctl_val = 0x00000001;
  197. video_pll0_config.user_ctl_hi_val = 0x00004805;
  198. clk_fabia_pll_configure(&video_pll0, regmap, &video_pll0_config);
  199. /* Keep VIDEO_CC_XO_CLK ALWAYS-ON */
  200. regmap_update_bits(regmap, 0x984, 0x1, 0x1);
  201. return qcom_cc_really_probe(pdev, &video_cc_sc7180_desc, regmap);
  202. }
  203. static struct platform_driver video_cc_sc7180_driver = {
  204. .probe = video_cc_sc7180_probe,
  205. .driver = {
  206. .name = "sc7180-videocc",
  207. .of_match_table = video_cc_sc7180_match_table,
  208. },
  209. };
  210. static int __init video_cc_sc7180_init(void)
  211. {
  212. return platform_driver_register(&video_cc_sc7180_driver);
  213. }
  214. subsys_initcall(video_cc_sc7180_init);
  215. static void __exit video_cc_sc7180_exit(void)
  216. {
  217. platform_driver_unregister(&video_cc_sc7180_driver);
  218. }
  219. module_exit(video_cc_sc7180_exit);
  220. MODULE_LICENSE("GPL v2");
  221. MODULE_DESCRIPTION("QTI VIDEOCC SC7180 Driver");