videocc-sm8450.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #include <linux/clk-provider.h>
  6. #include <linux/mod_devicetable.h>
  7. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/regmap.h>
  10. #include <dt-bindings/clock/qcom,sm8450-videocc.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 "gdsc.h"
  18. #include "reset.h"
  19. enum {
  20. DT_BI_TCXO,
  21. };
  22. enum {
  23. P_BI_TCXO,
  24. P_VIDEO_CC_PLL0_OUT_MAIN,
  25. P_VIDEO_CC_PLL1_OUT_MAIN,
  26. };
  27. static const struct pll_vco lucid_evo_vco[] = {
  28. { 249600000, 2020000000, 0 },
  29. };
  30. static const struct alpha_pll_config video_cc_pll0_config = {
  31. /* .l includes CAL_L_VAL, L_VAL fields */
  32. .l = 0x0044001e,
  33. .alpha = 0x0,
  34. .config_ctl_val = 0x20485699,
  35. .config_ctl_hi_val = 0x00182261,
  36. .config_ctl_hi1_val = 0x32aa299c,
  37. .user_ctl_val = 0x00000000,
  38. .user_ctl_hi_val = 0x00000805,
  39. };
  40. static const struct alpha_pll_config sm8475_video_cc_pll0_config = {
  41. /* .l includes CAL_L_VAL, L_VAL fields */
  42. .l = 0x1e,
  43. .alpha = 0x0,
  44. .config_ctl_val = 0x20485699,
  45. .config_ctl_hi_val = 0x00182261,
  46. .config_ctl_hi1_val = 0x82aa299c,
  47. .test_ctl_val = 0x00000000,
  48. .test_ctl_hi_val = 0x00000003,
  49. .test_ctl_hi1_val = 0x00009000,
  50. .test_ctl_hi2_val = 0x00000034,
  51. .user_ctl_val = 0x00000000,
  52. .user_ctl_hi_val = 0x00000005,
  53. };
  54. static struct clk_alpha_pll video_cc_pll0 = {
  55. .offset = 0x0,
  56. .config = &video_cc_pll0_config,
  57. .vco_table = lucid_evo_vco,
  58. .num_vco = ARRAY_SIZE(lucid_evo_vco),
  59. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_EVO],
  60. .clkr = {
  61. .hw.init = &(const struct clk_init_data) {
  62. .name = "video_cc_pll0",
  63. .parent_data = &(const struct clk_parent_data) {
  64. .index = DT_BI_TCXO,
  65. },
  66. .num_parents = 1,
  67. .ops = &clk_alpha_pll_lucid_evo_ops,
  68. },
  69. },
  70. };
  71. static const struct alpha_pll_config video_cc_pll1_config = {
  72. /* .l includes CAL_L_VAL, L_VAL fields */
  73. .l = 0x0044002b,
  74. .alpha = 0xc000,
  75. .config_ctl_val = 0x20485699,
  76. .config_ctl_hi_val = 0x00182261,
  77. .config_ctl_hi1_val = 0x32aa299c,
  78. .user_ctl_val = 0x00000000,
  79. .user_ctl_hi_val = 0x00000805,
  80. };
  81. static const struct alpha_pll_config sm8475_video_cc_pll1_config = {
  82. /* .l includes CAL_L_VAL, L_VAL fields */
  83. .l = 0x2b,
  84. .alpha = 0xc000,
  85. .config_ctl_val = 0x20485699,
  86. .config_ctl_hi_val = 0x00182261,
  87. .config_ctl_hi1_val = 0x82aa299c,
  88. .test_ctl_val = 0x00000000,
  89. .test_ctl_hi_val = 0x00000003,
  90. .test_ctl_hi1_val = 0x00009000,
  91. .test_ctl_hi2_val = 0x00000034,
  92. .user_ctl_val = 0x00000000,
  93. .user_ctl_hi_val = 0x00000005,
  94. };
  95. static struct clk_alpha_pll video_cc_pll1 = {
  96. .offset = 0x1000,
  97. .config = &video_cc_pll1_config,
  98. .vco_table = lucid_evo_vco,
  99. .num_vco = ARRAY_SIZE(lucid_evo_vco),
  100. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_EVO],
  101. .clkr = {
  102. .hw.init = &(const struct clk_init_data) {
  103. .name = "video_cc_pll1",
  104. .parent_data = &(const struct clk_parent_data) {
  105. .index = DT_BI_TCXO,
  106. },
  107. .num_parents = 1,
  108. .ops = &clk_alpha_pll_lucid_evo_ops,
  109. },
  110. },
  111. };
  112. static const struct parent_map video_cc_parent_map_0[] = {
  113. { P_BI_TCXO, 0 },
  114. { P_VIDEO_CC_PLL0_OUT_MAIN, 1 },
  115. };
  116. static const struct clk_parent_data video_cc_parent_data_0[] = {
  117. { .index = DT_BI_TCXO },
  118. { .hw = &video_cc_pll0.clkr.hw },
  119. };
  120. static const struct parent_map video_cc_parent_map_1[] = {
  121. { P_BI_TCXO, 0 },
  122. { P_VIDEO_CC_PLL1_OUT_MAIN, 1 },
  123. };
  124. static const struct clk_parent_data video_cc_parent_data_1[] = {
  125. { .index = DT_BI_TCXO },
  126. { .hw = &video_cc_pll1.clkr.hw },
  127. };
  128. static const struct freq_tbl ftbl_video_cc_mvs0_clk_src[] = {
  129. F(576000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  130. F(720000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  131. F(1014000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  132. F(1098000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  133. F(1332000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  134. { }
  135. };
  136. static struct clk_rcg2 video_cc_mvs0_clk_src = {
  137. .cmd_rcgr = 0x8000,
  138. .mnd_width = 0,
  139. .hid_width = 5,
  140. .parent_map = video_cc_parent_map_0,
  141. .freq_tbl = ftbl_video_cc_mvs0_clk_src,
  142. .clkr.hw.init = &(const struct clk_init_data) {
  143. .name = "video_cc_mvs0_clk_src",
  144. .parent_data = video_cc_parent_data_0,
  145. .num_parents = ARRAY_SIZE(video_cc_parent_data_0),
  146. .flags = CLK_SET_RATE_PARENT,
  147. .ops = &clk_rcg2_shared_ops,
  148. },
  149. };
  150. static const struct freq_tbl ftbl_video_cc_mvs1_clk_src[] = {
  151. F(840000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
  152. F(1050000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
  153. F(1350000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
  154. F(1500000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
  155. F(1650000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
  156. { }
  157. };
  158. static struct clk_rcg2 video_cc_mvs1_clk_src = {
  159. .cmd_rcgr = 0x8018,
  160. .mnd_width = 0,
  161. .hid_width = 5,
  162. .parent_map = video_cc_parent_map_1,
  163. .freq_tbl = ftbl_video_cc_mvs1_clk_src,
  164. .clkr.hw.init = &(const struct clk_init_data) {
  165. .name = "video_cc_mvs1_clk_src",
  166. .parent_data = video_cc_parent_data_1,
  167. .num_parents = ARRAY_SIZE(video_cc_parent_data_1),
  168. .flags = CLK_SET_RATE_PARENT,
  169. .ops = &clk_rcg2_shared_ops,
  170. },
  171. };
  172. static struct clk_regmap_div video_cc_mvs0_div_clk_src = {
  173. .reg = 0x80b8,
  174. .shift = 0,
  175. .width = 4,
  176. .clkr.hw.init = &(const struct clk_init_data) {
  177. .name = "video_cc_mvs0_div_clk_src",
  178. .parent_hws = (const struct clk_hw*[]) {
  179. &video_cc_mvs0_clk_src.clkr.hw,
  180. },
  181. .num_parents = 1,
  182. .flags = CLK_SET_RATE_PARENT,
  183. .ops = &clk_regmap_div_ro_ops,
  184. },
  185. };
  186. static struct clk_regmap_div video_cc_mvs0c_div2_div_clk_src = {
  187. .reg = 0x806c,
  188. .shift = 0,
  189. .width = 4,
  190. .clkr.hw.init = &(const struct clk_init_data) {
  191. .name = "video_cc_mvs0c_div2_div_clk_src",
  192. .parent_hws = (const struct clk_hw*[]) {
  193. &video_cc_mvs0_clk_src.clkr.hw,
  194. },
  195. .num_parents = 1,
  196. .flags = CLK_SET_RATE_PARENT,
  197. .ops = &clk_regmap_div_ro_ops,
  198. },
  199. };
  200. static struct clk_regmap_div video_cc_mvs1_div_clk_src = {
  201. .reg = 0x80dc,
  202. .shift = 0,
  203. .width = 4,
  204. .clkr.hw.init = &(const struct clk_init_data) {
  205. .name = "video_cc_mvs1_div_clk_src",
  206. .parent_hws = (const struct clk_hw*[]) {
  207. &video_cc_mvs1_clk_src.clkr.hw,
  208. },
  209. .num_parents = 1,
  210. .flags = CLK_SET_RATE_PARENT,
  211. .ops = &clk_regmap_div_ro_ops,
  212. },
  213. };
  214. static struct clk_regmap_div video_cc_mvs1c_div2_div_clk_src = {
  215. .reg = 0x8094,
  216. .shift = 0,
  217. .width = 4,
  218. .clkr.hw.init = &(const struct clk_init_data) {
  219. .name = "video_cc_mvs1c_div2_div_clk_src",
  220. .parent_hws = (const struct clk_hw*[]) {
  221. &video_cc_mvs1_clk_src.clkr.hw,
  222. },
  223. .num_parents = 1,
  224. .flags = CLK_SET_RATE_PARENT,
  225. .ops = &clk_regmap_div_ro_ops,
  226. },
  227. };
  228. static struct clk_branch video_cc_mvs0_clk = {
  229. .halt_reg = 0x80b0,
  230. .halt_check = BRANCH_HALT_SKIP,
  231. .hwcg_reg = 0x80b0,
  232. .hwcg_bit = 1,
  233. .clkr = {
  234. .enable_reg = 0x80b0,
  235. .enable_mask = BIT(0),
  236. .hw.init = &(const struct clk_init_data) {
  237. .name = "video_cc_mvs0_clk",
  238. .parent_hws = (const struct clk_hw*[]) {
  239. &video_cc_mvs0_div_clk_src.clkr.hw,
  240. },
  241. .num_parents = 1,
  242. .flags = CLK_SET_RATE_PARENT,
  243. .ops = &clk_branch2_ops,
  244. },
  245. },
  246. };
  247. static struct clk_branch video_cc_mvs0c_clk = {
  248. .halt_reg = 0x8064,
  249. .halt_check = BRANCH_HALT,
  250. .clkr = {
  251. .enable_reg = 0x8064,
  252. .enable_mask = BIT(0),
  253. .hw.init = &(const struct clk_init_data) {
  254. .name = "video_cc_mvs0c_clk",
  255. .parent_hws = (const struct clk_hw*[]) {
  256. &video_cc_mvs0c_div2_div_clk_src.clkr.hw,
  257. },
  258. .num_parents = 1,
  259. .flags = CLK_SET_RATE_PARENT,
  260. .ops = &clk_branch2_ops,
  261. },
  262. },
  263. };
  264. static struct clk_branch video_cc_mvs1_clk = {
  265. .halt_reg = 0x80d4,
  266. .halt_check = BRANCH_HALT_SKIP,
  267. .hwcg_reg = 0x80d4,
  268. .hwcg_bit = 1,
  269. .clkr = {
  270. .enable_reg = 0x80d4,
  271. .enable_mask = BIT(0),
  272. .hw.init = &(const struct clk_init_data) {
  273. .name = "video_cc_mvs1_clk",
  274. .parent_hws = (const struct clk_hw*[]) {
  275. &video_cc_mvs1_div_clk_src.clkr.hw,
  276. },
  277. .num_parents = 1,
  278. .flags = CLK_SET_RATE_PARENT,
  279. .ops = &clk_branch2_ops,
  280. },
  281. },
  282. };
  283. static struct clk_branch video_cc_mvs1c_clk = {
  284. .halt_reg = 0x808c,
  285. .halt_check = BRANCH_HALT,
  286. .clkr = {
  287. .enable_reg = 0x808c,
  288. .enable_mask = BIT(0),
  289. .hw.init = &(const struct clk_init_data) {
  290. .name = "video_cc_mvs1c_clk",
  291. .parent_hws = (const struct clk_hw*[]) {
  292. &video_cc_mvs1c_div2_div_clk_src.clkr.hw,
  293. },
  294. .num_parents = 1,
  295. .flags = CLK_SET_RATE_PARENT,
  296. .ops = &clk_branch2_ops,
  297. },
  298. },
  299. };
  300. static struct gdsc video_cc_mvs0c_gdsc = {
  301. .gdscr = 0x804c,
  302. .en_rest_wait_val = 0x2,
  303. .en_few_wait_val = 0x2,
  304. .clk_dis_wait_val = 0x6,
  305. .pd = {
  306. .name = "video_cc_mvs0c_gdsc",
  307. },
  308. .pwrsts = PWRSTS_OFF_ON,
  309. .flags = RETAIN_FF_ENABLE,
  310. };
  311. static struct gdsc video_cc_mvs0_gdsc = {
  312. .gdscr = 0x809c,
  313. .en_rest_wait_val = 0x2,
  314. .en_few_wait_val = 0x2,
  315. .clk_dis_wait_val = 0x6,
  316. .pd = {
  317. .name = "video_cc_mvs0_gdsc",
  318. },
  319. .pwrsts = PWRSTS_OFF_ON,
  320. .parent = &video_cc_mvs0c_gdsc.pd,
  321. .flags = HW_CTRL_TRIGGER | RETAIN_FF_ENABLE,
  322. };
  323. static struct gdsc video_cc_mvs1c_gdsc = {
  324. .gdscr = 0x8074,
  325. .en_rest_wait_val = 0x2,
  326. .en_few_wait_val = 0x2,
  327. .clk_dis_wait_val = 0x6,
  328. .pd = {
  329. .name = "video_cc_mvs1c_gdsc",
  330. },
  331. .pwrsts = PWRSTS_OFF_ON,
  332. .flags = RETAIN_FF_ENABLE,
  333. };
  334. static struct gdsc video_cc_mvs1_gdsc = {
  335. .gdscr = 0x80c0,
  336. .en_rest_wait_val = 0x2,
  337. .en_few_wait_val = 0x2,
  338. .clk_dis_wait_val = 0x6,
  339. .pd = {
  340. .name = "video_cc_mvs1_gdsc",
  341. },
  342. .pwrsts = PWRSTS_OFF_ON,
  343. .parent = &video_cc_mvs1c_gdsc.pd,
  344. .flags = HW_CTRL_TRIGGER | RETAIN_FF_ENABLE,
  345. };
  346. static struct clk_regmap *video_cc_sm8450_clocks[] = {
  347. [VIDEO_CC_MVS0_CLK] = &video_cc_mvs0_clk.clkr,
  348. [VIDEO_CC_MVS0_CLK_SRC] = &video_cc_mvs0_clk_src.clkr,
  349. [VIDEO_CC_MVS0_DIV_CLK_SRC] = &video_cc_mvs0_div_clk_src.clkr,
  350. [VIDEO_CC_MVS0C_CLK] = &video_cc_mvs0c_clk.clkr,
  351. [VIDEO_CC_MVS0C_DIV2_DIV_CLK_SRC] = &video_cc_mvs0c_div2_div_clk_src.clkr,
  352. [VIDEO_CC_MVS1_CLK] = &video_cc_mvs1_clk.clkr,
  353. [VIDEO_CC_MVS1_CLK_SRC] = &video_cc_mvs1_clk_src.clkr,
  354. [VIDEO_CC_MVS1_DIV_CLK_SRC] = &video_cc_mvs1_div_clk_src.clkr,
  355. [VIDEO_CC_MVS1C_CLK] = &video_cc_mvs1c_clk.clkr,
  356. [VIDEO_CC_MVS1C_DIV2_DIV_CLK_SRC] = &video_cc_mvs1c_div2_div_clk_src.clkr,
  357. [VIDEO_CC_PLL0] = &video_cc_pll0.clkr,
  358. [VIDEO_CC_PLL1] = &video_cc_pll1.clkr,
  359. };
  360. static struct gdsc *video_cc_sm8450_gdscs[] = {
  361. [VIDEO_CC_MVS0C_GDSC] = &video_cc_mvs0c_gdsc,
  362. [VIDEO_CC_MVS0_GDSC] = &video_cc_mvs0_gdsc,
  363. [VIDEO_CC_MVS1C_GDSC] = &video_cc_mvs1c_gdsc,
  364. [VIDEO_CC_MVS1_GDSC] = &video_cc_mvs1_gdsc,
  365. };
  366. static const struct qcom_reset_map video_cc_sm8450_resets[] = {
  367. [CVP_VIDEO_CC_INTERFACE_BCR] = { 0x80e0 },
  368. [CVP_VIDEO_CC_MVS0_BCR] = { 0x8098 },
  369. [CVP_VIDEO_CC_MVS0C_BCR] = { 0x8048 },
  370. [CVP_VIDEO_CC_MVS1_BCR] = { 0x80bc },
  371. [CVP_VIDEO_CC_MVS1C_BCR] = { 0x8070 },
  372. [VIDEO_CC_MVS0C_CLK_ARES] = { .reg = 0x8064, .bit = 2, .udelay = 1000 },
  373. [VIDEO_CC_MVS1C_CLK_ARES] = { .reg = 0x808c, .bit = 2, .udelay = 1000 },
  374. };
  375. static struct clk_alpha_pll *video_cc_sm8450_plls[] = {
  376. &video_cc_pll0,
  377. &video_cc_pll1,
  378. };
  379. static u32 video_cc_sm8450_critical_cbcrs[] = {
  380. 0x80e4, /* VIDEO_CC_AHB_CLK */
  381. 0x8114, /* VIDEO_CC_XO_CLK */
  382. 0x8130, /* VIDEO_CC_SLEEP_CLK */
  383. };
  384. static const struct regmap_config video_cc_sm8450_regmap_config = {
  385. .reg_bits = 32,
  386. .reg_stride = 4,
  387. .val_bits = 32,
  388. .max_register = 0x9f4c,
  389. .fast_io = true,
  390. };
  391. static struct qcom_cc_driver_data video_cc_sm8450_driver_data = {
  392. .alpha_plls = video_cc_sm8450_plls,
  393. .num_alpha_plls = ARRAY_SIZE(video_cc_sm8450_plls),
  394. .clk_cbcrs = video_cc_sm8450_critical_cbcrs,
  395. .num_clk_cbcrs = ARRAY_SIZE(video_cc_sm8450_critical_cbcrs),
  396. };
  397. static const struct qcom_cc_desc video_cc_sm8450_desc = {
  398. .config = &video_cc_sm8450_regmap_config,
  399. .clks = video_cc_sm8450_clocks,
  400. .num_clks = ARRAY_SIZE(video_cc_sm8450_clocks),
  401. .resets = video_cc_sm8450_resets,
  402. .num_resets = ARRAY_SIZE(video_cc_sm8450_resets),
  403. .gdscs = video_cc_sm8450_gdscs,
  404. .num_gdscs = ARRAY_SIZE(video_cc_sm8450_gdscs),
  405. .use_rpm = true,
  406. .driver_data = &video_cc_sm8450_driver_data,
  407. };
  408. static const struct of_device_id video_cc_sm8450_match_table[] = {
  409. { .compatible = "qcom,sm8450-videocc" },
  410. { .compatible = "qcom,sm8475-videocc" },
  411. { }
  412. };
  413. MODULE_DEVICE_TABLE(of, video_cc_sm8450_match_table);
  414. static int video_cc_sm8450_probe(struct platform_device *pdev)
  415. {
  416. if (of_device_is_compatible(pdev->dev.of_node, "qcom,sm8475-videocc")) {
  417. /* Update VideoCC PLL0 */
  418. video_cc_pll0.regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_OLE];
  419. /* Update VideoCC PLL1 */
  420. video_cc_pll1.regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_OLE];
  421. video_cc_pll0.config = &sm8475_video_cc_pll0_config;
  422. video_cc_pll1.config = &sm8475_video_cc_pll1_config;
  423. }
  424. return qcom_cc_probe(pdev, &video_cc_sm8450_desc);
  425. }
  426. static struct platform_driver video_cc_sm8450_driver = {
  427. .probe = video_cc_sm8450_probe,
  428. .driver = {
  429. .name = "video_cc-sm8450",
  430. .of_match_table = video_cc_sm8450_match_table,
  431. },
  432. };
  433. module_platform_driver(video_cc_sm8450_driver);
  434. MODULE_DESCRIPTION("QTI VIDEOCC SM8450 / SM8475 Driver");
  435. MODULE_LICENSE("GPL");