videocc-sm8250.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2018-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-sm8250.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-regmap-divider.h"
  16. #include "common.h"
  17. #include "reset.h"
  18. #include "gdsc.h"
  19. enum {
  20. P_BI_TCXO,
  21. P_VIDEO_PLL0_OUT_MAIN,
  22. P_VIDEO_PLL1_OUT_MAIN,
  23. };
  24. static struct pll_vco lucid_vco[] = {
  25. { 249600000, 2000000000, 0 },
  26. };
  27. static const struct alpha_pll_config video_pll0_config = {
  28. .l = 0x25,
  29. .alpha = 0x8000,
  30. .config_ctl_val = 0x20485699,
  31. .config_ctl_hi_val = 0x00002261,
  32. .config_ctl_hi1_val = 0x329A699C,
  33. .user_ctl_val = 0x00000000,
  34. .user_ctl_hi_val = 0x00000805,
  35. .user_ctl_hi1_val = 0x00000000,
  36. };
  37. static struct clk_alpha_pll video_pll0 = {
  38. .offset = 0x42c,
  39. .vco_table = lucid_vco,
  40. .num_vco = ARRAY_SIZE(lucid_vco),
  41. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
  42. .clkr = {
  43. .hw.init = &(struct clk_init_data){
  44. .name = "video_pll0",
  45. .parent_data = &(const struct clk_parent_data){
  46. .fw_name = "bi_tcxo",
  47. },
  48. .num_parents = 1,
  49. .ops = &clk_alpha_pll_lucid_ops,
  50. },
  51. },
  52. };
  53. static const struct alpha_pll_config video_pll1_config = {
  54. .l = 0x2B,
  55. .alpha = 0xC000,
  56. .config_ctl_val = 0x20485699,
  57. .config_ctl_hi_val = 0x00002261,
  58. .config_ctl_hi1_val = 0x329A699C,
  59. .user_ctl_val = 0x00000000,
  60. .user_ctl_hi_val = 0x00000805,
  61. .user_ctl_hi1_val = 0x00000000,
  62. };
  63. static struct clk_alpha_pll video_pll1 = {
  64. .offset = 0x7d0,
  65. .vco_table = lucid_vco,
  66. .num_vco = ARRAY_SIZE(lucid_vco),
  67. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
  68. .clkr = {
  69. .hw.init = &(struct clk_init_data){
  70. .name = "video_pll1",
  71. .parent_data = &(const struct clk_parent_data){
  72. .fw_name = "bi_tcxo",
  73. },
  74. .num_parents = 1,
  75. .ops = &clk_alpha_pll_lucid_ops,
  76. },
  77. },
  78. };
  79. static const struct parent_map video_cc_parent_map_1[] = {
  80. { P_BI_TCXO, 0 },
  81. { P_VIDEO_PLL0_OUT_MAIN, 1 },
  82. };
  83. static const struct clk_parent_data video_cc_parent_data_1[] = {
  84. { .fw_name = "bi_tcxo" },
  85. { .hw = &video_pll0.clkr.hw },
  86. };
  87. static const struct parent_map video_cc_parent_map_2[] = {
  88. { P_BI_TCXO, 0 },
  89. { P_VIDEO_PLL1_OUT_MAIN, 1 },
  90. };
  91. static const struct clk_parent_data video_cc_parent_data_2[] = {
  92. { .fw_name = "bi_tcxo" },
  93. { .hw = &video_pll1.clkr.hw },
  94. };
  95. static const struct freq_tbl ftbl_video_cc_mvs0_clk_src[] = {
  96. F(19200000, P_BI_TCXO, 1, 0, 0),
  97. F(720000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
  98. F(1014000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
  99. F(1098000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
  100. F(1332000000, P_VIDEO_PLL0_OUT_MAIN, 1, 0, 0),
  101. { }
  102. };
  103. static struct clk_rcg2 video_cc_mvs0_clk_src = {
  104. .cmd_rcgr = 0xb94,
  105. .mnd_width = 0,
  106. .hid_width = 5,
  107. .parent_map = video_cc_parent_map_1,
  108. .freq_tbl = ftbl_video_cc_mvs0_clk_src,
  109. .clkr.hw.init = &(struct clk_init_data){
  110. .name = "video_cc_mvs0_clk_src",
  111. .parent_data = video_cc_parent_data_1,
  112. .num_parents = ARRAY_SIZE(video_cc_parent_data_1),
  113. .flags = CLK_SET_RATE_PARENT,
  114. .ops = &clk_rcg2_shared_ops,
  115. },
  116. };
  117. static const struct freq_tbl ftbl_video_cc_mvs1_clk_src[] = {
  118. F(19200000, P_BI_TCXO, 1, 0, 0),
  119. F(840000000, P_VIDEO_PLL1_OUT_MAIN, 1, 0, 0),
  120. F(1098000000, P_VIDEO_PLL1_OUT_MAIN, 1, 0, 0),
  121. F(1332000000, P_VIDEO_PLL1_OUT_MAIN, 1, 0, 0),
  122. { }
  123. };
  124. static struct clk_rcg2 video_cc_mvs1_clk_src = {
  125. .cmd_rcgr = 0xbb4,
  126. .mnd_width = 0,
  127. .hid_width = 5,
  128. .parent_map = video_cc_parent_map_2,
  129. .freq_tbl = ftbl_video_cc_mvs1_clk_src,
  130. .clkr.hw.init = &(struct clk_init_data){
  131. .name = "video_cc_mvs1_clk_src",
  132. .parent_data = video_cc_parent_data_2,
  133. .num_parents = ARRAY_SIZE(video_cc_parent_data_2),
  134. .flags = CLK_SET_RATE_PARENT,
  135. .ops = &clk_rcg2_shared_ops,
  136. },
  137. };
  138. static struct clk_regmap_div video_cc_mvs0c_div2_div_clk_src = {
  139. .reg = 0xc54,
  140. .shift = 0,
  141. .width = 2,
  142. .clkr.hw.init = &(struct clk_init_data) {
  143. .name = "video_cc_mvs0c_div2_div_clk_src",
  144. .parent_hws = (const struct clk_hw*[]){
  145. &video_cc_mvs0_clk_src.clkr.hw,
  146. },
  147. .num_parents = 1,
  148. .flags = CLK_SET_RATE_PARENT,
  149. .ops = &clk_regmap_div_ro_ops,
  150. },
  151. };
  152. static struct clk_regmap_div video_cc_mvs0_div_clk_src = {
  153. .reg = 0xd54,
  154. .shift = 0,
  155. .width = 2,
  156. .clkr.hw.init = &(struct clk_init_data) {
  157. .name = "video_cc_mvs0_div_clk_src",
  158. .parent_hws = (const struct clk_hw*[]){
  159. &video_cc_mvs0_clk_src.clkr.hw,
  160. },
  161. .num_parents = 1,
  162. .flags = CLK_SET_RATE_PARENT,
  163. .ops = &clk_regmap_div_ro_ops,
  164. },
  165. };
  166. static struct clk_regmap_div video_cc_mvs1c_div2_div_clk_src = {
  167. .reg = 0xcf4,
  168. .shift = 0,
  169. .width = 2,
  170. .clkr.hw.init = &(struct clk_init_data) {
  171. .name = "video_cc_mvs1c_div2_div_clk_src",
  172. .parent_hws = (const struct clk_hw*[]){
  173. &video_cc_mvs1_clk_src.clkr.hw,
  174. },
  175. .num_parents = 1,
  176. .flags = CLK_SET_RATE_PARENT,
  177. .ops = &clk_regmap_div_ro_ops,
  178. },
  179. };
  180. static struct clk_branch video_cc_mvs0c_clk = {
  181. .halt_reg = 0xc34,
  182. .halt_check = BRANCH_HALT,
  183. .clkr = {
  184. .enable_reg = 0xc34,
  185. .enable_mask = BIT(0),
  186. .hw.init = &(struct clk_init_data){
  187. .name = "video_cc_mvs0c_clk",
  188. .parent_hws = (const struct clk_hw*[]){
  189. &video_cc_mvs0c_div2_div_clk_src.clkr.hw,
  190. },
  191. .num_parents = 1,
  192. .flags = CLK_SET_RATE_PARENT,
  193. .ops = &clk_branch2_ops,
  194. },
  195. },
  196. };
  197. static struct clk_branch video_cc_mvs0_clk = {
  198. .halt_reg = 0xd34,
  199. .halt_check = BRANCH_HALT_VOTED,
  200. .clkr = {
  201. .enable_reg = 0xd34,
  202. .enable_mask = BIT(0),
  203. .hw.init = &(struct clk_init_data){
  204. .name = "video_cc_mvs0_clk",
  205. .parent_hws = (const struct clk_hw*[]){
  206. &video_cc_mvs0_div_clk_src.clkr.hw,
  207. },
  208. .num_parents = 1,
  209. .flags = CLK_SET_RATE_PARENT,
  210. .ops = &clk_branch2_ops,
  211. },
  212. },
  213. };
  214. static struct clk_branch video_cc_mvs1_div2_clk = {
  215. .halt_reg = 0xdf4,
  216. .halt_check = BRANCH_HALT_VOTED,
  217. .clkr = {
  218. .enable_reg = 0xdf4,
  219. .enable_mask = BIT(0),
  220. .hw.init = &(struct clk_init_data){
  221. .name = "video_cc_mvs1_div2_clk",
  222. .parent_hws = (const struct clk_hw*[]){
  223. &video_cc_mvs1c_div2_div_clk_src.clkr.hw,
  224. },
  225. .num_parents = 1,
  226. .flags = CLK_SET_RATE_PARENT,
  227. .ops = &clk_branch2_ops,
  228. },
  229. },
  230. };
  231. static struct clk_branch video_cc_mvs1c_clk = {
  232. .halt_reg = 0xcd4,
  233. .halt_check = BRANCH_HALT_VOTED,
  234. .clkr = {
  235. .enable_reg = 0xcd4,
  236. .enable_mask = BIT(0),
  237. .hw.init = &(struct clk_init_data){
  238. .name = "video_cc_mvs1c_clk",
  239. .parent_hws = (const struct clk_hw*[]){
  240. &video_cc_mvs1c_div2_div_clk_src.clkr.hw,
  241. },
  242. .num_parents = 1,
  243. .flags = CLK_SET_RATE_PARENT,
  244. .ops = &clk_branch2_ops,
  245. },
  246. },
  247. };
  248. static struct gdsc mvs0c_gdsc = {
  249. .gdscr = 0xbf8,
  250. .pd = {
  251. .name = "mvs0c_gdsc",
  252. },
  253. .flags = 0,
  254. .pwrsts = PWRSTS_OFF_ON,
  255. };
  256. static struct gdsc mvs1c_gdsc = {
  257. .gdscr = 0xc98,
  258. .pd = {
  259. .name = "mvs1c_gdsc",
  260. },
  261. .flags = 0,
  262. .pwrsts = PWRSTS_OFF_ON,
  263. };
  264. static struct gdsc mvs0_gdsc = {
  265. .gdscr = 0xd18,
  266. .pd = {
  267. .name = "mvs0_gdsc",
  268. },
  269. .flags = HW_CTRL,
  270. .pwrsts = PWRSTS_OFF_ON,
  271. };
  272. static struct gdsc mvs1_gdsc = {
  273. .gdscr = 0xd98,
  274. .pd = {
  275. .name = "mvs1_gdsc",
  276. },
  277. .flags = HW_CTRL,
  278. .pwrsts = PWRSTS_OFF_ON,
  279. };
  280. static struct clk_regmap *video_cc_sm8250_clocks[] = {
  281. [VIDEO_CC_MVS0_CLK] = &video_cc_mvs0_clk.clkr,
  282. [VIDEO_CC_MVS0_CLK_SRC] = &video_cc_mvs0_clk_src.clkr,
  283. [VIDEO_CC_MVS0_DIV_CLK_SRC] = &video_cc_mvs0_div_clk_src.clkr,
  284. [VIDEO_CC_MVS0C_CLK] = &video_cc_mvs0c_clk.clkr,
  285. [VIDEO_CC_MVS0C_DIV2_DIV_CLK_SRC] = &video_cc_mvs0c_div2_div_clk_src.clkr,
  286. [VIDEO_CC_MVS1_CLK_SRC] = &video_cc_mvs1_clk_src.clkr,
  287. [VIDEO_CC_MVS1_DIV2_CLK] = &video_cc_mvs1_div2_clk.clkr,
  288. [VIDEO_CC_MVS1C_CLK] = &video_cc_mvs1c_clk.clkr,
  289. [VIDEO_CC_MVS1C_DIV2_DIV_CLK_SRC] = &video_cc_mvs1c_div2_div_clk_src.clkr,
  290. [VIDEO_CC_PLL0] = &video_pll0.clkr,
  291. [VIDEO_CC_PLL1] = &video_pll1.clkr,
  292. };
  293. static const struct qcom_reset_map video_cc_sm8250_resets[] = {
  294. [VIDEO_CC_CVP_INTERFACE_BCR] = { 0xe54 },
  295. [VIDEO_CC_CVP_MVS0_BCR] = { 0xd14 },
  296. [VIDEO_CC_MVS0C_CLK_ARES] = { 0xc34, 2 },
  297. [VIDEO_CC_CVP_MVS0C_BCR] = { 0xbf4 },
  298. [VIDEO_CC_CVP_MVS1_BCR] = { 0xd94 },
  299. [VIDEO_CC_MVS1C_CLK_ARES] = { 0xcd4, 2 },
  300. [VIDEO_CC_CVP_MVS1C_BCR] = { 0xc94 },
  301. };
  302. static struct gdsc *video_cc_sm8250_gdscs[] = {
  303. [MVS0C_GDSC] = &mvs0c_gdsc,
  304. [MVS1C_GDSC] = &mvs1c_gdsc,
  305. [MVS0_GDSC] = &mvs0_gdsc,
  306. [MVS1_GDSC] = &mvs1_gdsc,
  307. };
  308. static const struct regmap_config video_cc_sm8250_regmap_config = {
  309. .reg_bits = 32,
  310. .reg_stride = 4,
  311. .val_bits = 32,
  312. .max_register = 0xf4c,
  313. .fast_io = true,
  314. };
  315. static const struct qcom_cc_desc video_cc_sm8250_desc = {
  316. .config = &video_cc_sm8250_regmap_config,
  317. .clks = video_cc_sm8250_clocks,
  318. .num_clks = ARRAY_SIZE(video_cc_sm8250_clocks),
  319. .resets = video_cc_sm8250_resets,
  320. .num_resets = ARRAY_SIZE(video_cc_sm8250_resets),
  321. .gdscs = video_cc_sm8250_gdscs,
  322. .num_gdscs = ARRAY_SIZE(video_cc_sm8250_gdscs),
  323. };
  324. static const struct of_device_id video_cc_sm8250_match_table[] = {
  325. { .compatible = "qcom,sm8250-videocc" },
  326. { }
  327. };
  328. MODULE_DEVICE_TABLE(of, video_cc_sm8250_match_table);
  329. static void video_cc_sm8250_pm_runtime_disable(void *data)
  330. {
  331. pm_runtime_disable(data);
  332. }
  333. static int video_cc_sm8250_probe(struct platform_device *pdev)
  334. {
  335. struct regmap *regmap;
  336. int ret;
  337. pm_runtime_enable(&pdev->dev);
  338. ret = devm_add_action_or_reset(&pdev->dev, video_cc_sm8250_pm_runtime_disable, &pdev->dev);
  339. if (ret)
  340. return ret;
  341. ret = pm_runtime_resume_and_get(&pdev->dev);
  342. if (ret)
  343. return ret;
  344. regmap = qcom_cc_map(pdev, &video_cc_sm8250_desc);
  345. if (IS_ERR(regmap)) {
  346. pm_runtime_put(&pdev->dev);
  347. return PTR_ERR(regmap);
  348. }
  349. clk_lucid_pll_configure(&video_pll0, regmap, &video_pll0_config);
  350. clk_lucid_pll_configure(&video_pll1, regmap, &video_pll1_config);
  351. /* Keep VIDEO_CC_AHB_CLK and VIDEO_CC_XO_CLK ALWAYS-ON */
  352. regmap_update_bits(regmap, 0xe58, BIT(0), BIT(0));
  353. regmap_update_bits(regmap, 0xeec, BIT(0), BIT(0));
  354. ret = qcom_cc_really_probe(pdev, &video_cc_sm8250_desc, regmap);
  355. pm_runtime_put(&pdev->dev);
  356. return ret;
  357. }
  358. static struct platform_driver video_cc_sm8250_driver = {
  359. .probe = video_cc_sm8250_probe,
  360. .driver = {
  361. .name = "sm8250-videocc",
  362. .of_match_table = video_cc_sm8250_match_table,
  363. },
  364. };
  365. static int __init video_cc_sm8250_init(void)
  366. {
  367. return platform_driver_register(&video_cc_sm8250_driver);
  368. }
  369. subsys_initcall(video_cc_sm8250_init);
  370. static void __exit video_cc_sm8250_exit(void)
  371. {
  372. platform_driver_unregister(&video_cc_sm8250_driver);
  373. }
  374. module_exit(video_cc_sm8250_exit);
  375. MODULE_LICENSE("GPL v2");
  376. MODULE_DESCRIPTION("QTI VIDEOCC SM8250 Driver");