videocc-sm8750.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
  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/pm_runtime.h>
  10. #include <linux/regmap.h>
  11. #include <dt-bindings/clock/qcom,sm8750-videocc.h>
  12. #include "clk-alpha-pll.h"
  13. #include "clk-branch.h"
  14. #include "clk-pll.h"
  15. #include "clk-rcg.h"
  16. #include "clk-regmap.h"
  17. #include "clk-regmap-divider.h"
  18. #include "clk-regmap-mux.h"
  19. #include "common.h"
  20. #include "gdsc.h"
  21. #include "reset.h"
  22. enum {
  23. DT_BI_TCXO,
  24. DT_BI_TCXO_AO,
  25. DT_SLEEP_CLK,
  26. };
  27. enum {
  28. P_BI_TCXO,
  29. P_SLEEP_CLK,
  30. P_VIDEO_CC_PLL0_OUT_MAIN,
  31. };
  32. static const struct pll_vco taycan_elu_vco[] = {
  33. { 249600000, 2500000000, 0 },
  34. };
  35. static const struct alpha_pll_config video_cc_pll0_config = {
  36. .l = 0x25,
  37. .alpha = 0x8000,
  38. .config_ctl_val = 0x19660387,
  39. .config_ctl_hi_val = 0x098060a0,
  40. .config_ctl_hi1_val = 0xb416cb20,
  41. .user_ctl_val = 0x00000000,
  42. .user_ctl_hi_val = 0x00000002,
  43. };
  44. static struct clk_alpha_pll video_cc_pll0 = {
  45. .offset = 0x0,
  46. .config = &video_cc_pll0_config,
  47. .vco_table = taycan_elu_vco,
  48. .num_vco = ARRAY_SIZE(taycan_elu_vco),
  49. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_TAYCAN_ELU],
  50. .clkr = {
  51. .hw.init = &(const struct clk_init_data) {
  52. .name = "video_cc_pll0",
  53. .parent_data = &(const struct clk_parent_data) {
  54. .index = DT_BI_TCXO,
  55. },
  56. .num_parents = 1,
  57. .ops = &clk_alpha_pll_taycan_elu_ops,
  58. },
  59. },
  60. };
  61. static const struct parent_map video_cc_parent_map_0[] = {
  62. { P_BI_TCXO, 0 },
  63. };
  64. static const struct clk_parent_data video_cc_parent_data_0_ao[] = {
  65. { .index = DT_BI_TCXO_AO },
  66. };
  67. static const struct parent_map video_cc_parent_map_1[] = {
  68. { P_BI_TCXO, 0 },
  69. { P_VIDEO_CC_PLL0_OUT_MAIN, 1 },
  70. };
  71. static const struct clk_parent_data video_cc_parent_data_1[] = {
  72. { .index = DT_BI_TCXO },
  73. { .hw = &video_cc_pll0.clkr.hw },
  74. };
  75. static const struct parent_map video_cc_parent_map_2[] = {
  76. { P_SLEEP_CLK, 0 },
  77. };
  78. static const struct clk_parent_data video_cc_parent_data_2_ao[] = {
  79. { .index = DT_SLEEP_CLK },
  80. };
  81. static const struct freq_tbl ftbl_video_cc_ahb_clk_src[] = {
  82. F(19200000, P_BI_TCXO, 1, 0, 0),
  83. { }
  84. };
  85. static struct clk_rcg2 video_cc_ahb_clk_src = {
  86. .cmd_rcgr = 0x8018,
  87. .mnd_width = 0,
  88. .hid_width = 5,
  89. .parent_map = video_cc_parent_map_0,
  90. .freq_tbl = ftbl_video_cc_ahb_clk_src,
  91. .clkr.hw.init = &(const struct clk_init_data) {
  92. .name = "video_cc_ahb_clk_src",
  93. .parent_data = video_cc_parent_data_0_ao,
  94. .num_parents = ARRAY_SIZE(video_cc_parent_data_0_ao),
  95. .flags = CLK_SET_RATE_PARENT,
  96. .ops = &clk_rcg2_ops,
  97. },
  98. };
  99. static const struct freq_tbl ftbl_video_cc_mvs0_clk_src[] = {
  100. F(720000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  101. F(1014000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  102. F(1260000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  103. F(1332000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  104. F(1600000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  105. F(1710000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  106. F(1890000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  107. { }
  108. };
  109. static struct clk_rcg2 video_cc_mvs0_clk_src = {
  110. .cmd_rcgr = 0x8000,
  111. .mnd_width = 0,
  112. .hid_width = 5,
  113. .parent_map = video_cc_parent_map_1,
  114. .freq_tbl = ftbl_video_cc_mvs0_clk_src,
  115. .clkr.hw.init = &(const struct clk_init_data) {
  116. .name = "video_cc_mvs0_clk_src",
  117. .parent_data = video_cc_parent_data_1,
  118. .num_parents = ARRAY_SIZE(video_cc_parent_data_1),
  119. .flags = CLK_SET_RATE_PARENT,
  120. .ops = &clk_rcg2_shared_ops,
  121. },
  122. };
  123. static const struct freq_tbl ftbl_video_cc_sleep_clk_src[] = {
  124. F(32000, P_SLEEP_CLK, 1, 0, 0),
  125. { }
  126. };
  127. static struct clk_rcg2 video_cc_sleep_clk_src = {
  128. .cmd_rcgr = 0x80e0,
  129. .mnd_width = 0,
  130. .hid_width = 5,
  131. .parent_map = video_cc_parent_map_2,
  132. .freq_tbl = ftbl_video_cc_sleep_clk_src,
  133. .clkr.hw.init = &(const struct clk_init_data) {
  134. .name = "video_cc_sleep_clk_src",
  135. .parent_data = video_cc_parent_data_2_ao,
  136. .num_parents = ARRAY_SIZE(video_cc_parent_data_2_ao),
  137. .flags = CLK_SET_RATE_PARENT,
  138. .ops = &clk_rcg2_ops,
  139. },
  140. };
  141. static struct clk_rcg2 video_cc_xo_clk_src = {
  142. .cmd_rcgr = 0x80bc,
  143. .mnd_width = 0,
  144. .hid_width = 5,
  145. .parent_map = video_cc_parent_map_0,
  146. .freq_tbl = ftbl_video_cc_ahb_clk_src,
  147. .clkr.hw.init = &(const struct clk_init_data) {
  148. .name = "video_cc_xo_clk_src",
  149. .parent_data = video_cc_parent_data_0_ao,
  150. .num_parents = ARRAY_SIZE(video_cc_parent_data_0_ao),
  151. .flags = CLK_SET_RATE_PARENT,
  152. .ops = &clk_rcg2_ops,
  153. },
  154. };
  155. static struct clk_regmap_div video_cc_mvs0_div_clk_src = {
  156. .reg = 0x809c,
  157. .shift = 0,
  158. .width = 4,
  159. .clkr.hw.init = &(const struct clk_init_data) {
  160. .name = "video_cc_mvs0_div_clk_src",
  161. .parent_hws = (const struct clk_hw*[]) {
  162. &video_cc_mvs0_clk_src.clkr.hw,
  163. },
  164. .num_parents = 1,
  165. .flags = CLK_SET_RATE_PARENT,
  166. .ops = &clk_regmap_div_ro_ops,
  167. },
  168. };
  169. static struct clk_regmap_div video_cc_mvs0c_div2_div_clk_src = {
  170. .reg = 0x8060,
  171. .shift = 0,
  172. .width = 4,
  173. .clkr.hw.init = &(const struct clk_init_data) {
  174. .name = "video_cc_mvs0c_div2_div_clk_src",
  175. .parent_hws = (const struct clk_hw*[]) {
  176. &video_cc_mvs0_clk_src.clkr.hw,
  177. },
  178. .num_parents = 1,
  179. .flags = CLK_SET_RATE_PARENT,
  180. .ops = &clk_regmap_div_ro_ops,
  181. },
  182. };
  183. static struct clk_branch video_cc_mvs0_clk = {
  184. .halt_reg = 0x807c,
  185. .halt_check = BRANCH_HALT_VOTED,
  186. .hwcg_reg = 0x807c,
  187. .hwcg_bit = 1,
  188. .clkr = {
  189. .enable_reg = 0x807c,
  190. .enable_mask = BIT(0),
  191. .hw.init = &(const struct clk_init_data) {
  192. .name = "video_cc_mvs0_clk",
  193. .parent_hws = (const struct clk_hw*[]) {
  194. &video_cc_mvs0_div_clk_src.clkr.hw,
  195. },
  196. .num_parents = 1,
  197. .flags = CLK_SET_RATE_PARENT,
  198. .ops = &clk_branch2_ops,
  199. },
  200. },
  201. };
  202. static struct clk_mem_branch video_cc_mvs0_freerun_clk = {
  203. .mem_enable_reg = 0x8090,
  204. .mem_ack_reg = 0x8090,
  205. .mem_enable_mask = BIT(3),
  206. .mem_enable_ack_mask = GENMASK(11, 10),
  207. .mem_enable_invert = true,
  208. .branch = {
  209. .halt_reg = 0x808c,
  210. .halt_check = BRANCH_HALT,
  211. .clkr = {
  212. .enable_reg = 0x808c,
  213. .enable_mask = BIT(0),
  214. .hw.init = &(const struct clk_init_data) {
  215. .name = "video_cc_mvs0_freerun_clk",
  216. .parent_hws = (const struct clk_hw*[]) {
  217. &video_cc_mvs0_div_clk_src.clkr.hw,
  218. },
  219. .num_parents = 1,
  220. .flags = CLK_SET_RATE_PARENT,
  221. .ops = &clk_branch2_mem_ops,
  222. },
  223. },
  224. },
  225. };
  226. static struct clk_branch video_cc_mvs0_shift_clk = {
  227. .halt_reg = 0x80d8,
  228. .halt_check = BRANCH_HALT_VOTED,
  229. .hwcg_reg = 0x80d8,
  230. .hwcg_bit = 1,
  231. .clkr = {
  232. .enable_reg = 0x80d8,
  233. .enable_mask = BIT(0),
  234. .hw.init = &(const struct clk_init_data) {
  235. .name = "video_cc_mvs0_shift_clk",
  236. .parent_hws = (const struct clk_hw*[]) {
  237. &video_cc_xo_clk_src.clkr.hw,
  238. },
  239. .num_parents = 1,
  240. .flags = CLK_SET_RATE_PARENT,
  241. .ops = &clk_branch2_ops,
  242. },
  243. },
  244. };
  245. static struct clk_branch video_cc_mvs0c_clk = {
  246. .halt_reg = 0x804c,
  247. .halt_check = BRANCH_HALT,
  248. .clkr = {
  249. .enable_reg = 0x804c,
  250. .enable_mask = BIT(0),
  251. .hw.init = &(const struct clk_init_data) {
  252. .name = "video_cc_mvs0c_clk",
  253. .parent_hws = (const struct clk_hw*[]) {
  254. &video_cc_mvs0c_div2_div_clk_src.clkr.hw,
  255. },
  256. .num_parents = 1,
  257. .flags = CLK_SET_RATE_PARENT,
  258. .ops = &clk_branch2_ops,
  259. },
  260. },
  261. };
  262. static struct clk_branch video_cc_mvs0c_freerun_clk = {
  263. .halt_reg = 0x805c,
  264. .halt_check = BRANCH_HALT,
  265. .clkr = {
  266. .enable_reg = 0x805c,
  267. .enable_mask = BIT(0),
  268. .hw.init = &(const struct clk_init_data) {
  269. .name = "video_cc_mvs0c_freerun_clk",
  270. .parent_hws = (const struct clk_hw*[]) {
  271. &video_cc_mvs0c_div2_div_clk_src.clkr.hw,
  272. },
  273. .num_parents = 1,
  274. .flags = CLK_SET_RATE_PARENT,
  275. .ops = &clk_branch2_ops,
  276. },
  277. },
  278. };
  279. static struct clk_branch video_cc_mvs0c_shift_clk = {
  280. .halt_reg = 0x80dc,
  281. .halt_check = BRANCH_HALT_VOTED,
  282. .hwcg_reg = 0x80dc,
  283. .hwcg_bit = 1,
  284. .clkr = {
  285. .enable_reg = 0x80dc,
  286. .enable_mask = BIT(0),
  287. .hw.init = &(const struct clk_init_data) {
  288. .name = "video_cc_mvs0c_shift_clk",
  289. .parent_hws = (const struct clk_hw*[]) {
  290. &video_cc_xo_clk_src.clkr.hw,
  291. },
  292. .num_parents = 1,
  293. .flags = CLK_SET_RATE_PARENT,
  294. .ops = &clk_branch2_ops,
  295. },
  296. },
  297. };
  298. static struct gdsc video_cc_mvs0c_gdsc = {
  299. .gdscr = 0x8034,
  300. .en_rest_wait_val = 0x2,
  301. .en_few_wait_val = 0x2,
  302. .clk_dis_wait_val = 0x6,
  303. .pd = {
  304. .name = "video_cc_mvs0c_gdsc",
  305. },
  306. .pwrsts = PWRSTS_OFF_ON,
  307. .flags = POLL_CFG_GDSCR | RETAIN_FF_ENABLE,
  308. };
  309. static struct gdsc video_cc_mvs0_gdsc = {
  310. .gdscr = 0x8068,
  311. .en_rest_wait_val = 0x2,
  312. .en_few_wait_val = 0x2,
  313. .clk_dis_wait_val = 0x6,
  314. .pd = {
  315. .name = "video_cc_mvs0_gdsc",
  316. },
  317. .pwrsts = PWRSTS_OFF_ON,
  318. .parent = &video_cc_mvs0c_gdsc.pd,
  319. .flags = POLL_CFG_GDSCR | RETAIN_FF_ENABLE | HW_CTRL_TRIGGER,
  320. };
  321. static struct clk_regmap *video_cc_sm8750_clocks[] = {
  322. [VIDEO_CC_AHB_CLK_SRC] = &video_cc_ahb_clk_src.clkr,
  323. [VIDEO_CC_MVS0_CLK] = &video_cc_mvs0_clk.clkr,
  324. [VIDEO_CC_MVS0_CLK_SRC] = &video_cc_mvs0_clk_src.clkr,
  325. [VIDEO_CC_MVS0_DIV_CLK_SRC] = &video_cc_mvs0_div_clk_src.clkr,
  326. [VIDEO_CC_MVS0_FREERUN_CLK] = &video_cc_mvs0_freerun_clk.branch.clkr,
  327. [VIDEO_CC_MVS0_SHIFT_CLK] = &video_cc_mvs0_shift_clk.clkr,
  328. [VIDEO_CC_MVS0C_CLK] = &video_cc_mvs0c_clk.clkr,
  329. [VIDEO_CC_MVS0C_DIV2_DIV_CLK_SRC] = &video_cc_mvs0c_div2_div_clk_src.clkr,
  330. [VIDEO_CC_MVS0C_FREERUN_CLK] = &video_cc_mvs0c_freerun_clk.clkr,
  331. [VIDEO_CC_MVS0C_SHIFT_CLK] = &video_cc_mvs0c_shift_clk.clkr,
  332. [VIDEO_CC_PLL0] = &video_cc_pll0.clkr,
  333. [VIDEO_CC_SLEEP_CLK_SRC] = &video_cc_sleep_clk_src.clkr,
  334. [VIDEO_CC_XO_CLK_SRC] = &video_cc_xo_clk_src.clkr,
  335. };
  336. static struct gdsc *video_cc_sm8750_gdscs[] = {
  337. [VIDEO_CC_MVS0_GDSC] = &video_cc_mvs0_gdsc,
  338. [VIDEO_CC_MVS0C_GDSC] = &video_cc_mvs0c_gdsc,
  339. };
  340. static const struct qcom_reset_map video_cc_sm8750_resets[] = {
  341. [VIDEO_CC_INTERFACE_BCR] = { 0x80a0 },
  342. [VIDEO_CC_MVS0_BCR] = { 0x8064 },
  343. [VIDEO_CC_MVS0C_CLK_ARES] = { 0x804c, 2 },
  344. [VIDEO_CC_MVS0C_BCR] = { 0x8030 },
  345. [VIDEO_CC_MVS0_FREERUN_CLK_ARES] = { 0x808c, 2 },
  346. [VIDEO_CC_MVS0C_FREERUN_CLK_ARES] = { 0x805c, 2 },
  347. [VIDEO_CC_XO_CLK_ARES] = { 0x80d4, 2 },
  348. };
  349. static const struct regmap_config video_cc_sm8750_regmap_config = {
  350. .reg_bits = 32,
  351. .reg_stride = 4,
  352. .val_bits = 32,
  353. .max_register = 0x9f4c,
  354. .fast_io = true,
  355. };
  356. static struct clk_alpha_pll *video_cc_sm8750_plls[] = {
  357. &video_cc_pll0,
  358. };
  359. static u32 video_cc_sm8750_critical_cbcrs[] = {
  360. 0x80a4, /* VIDEO_CC_AHB_CLK */
  361. 0x80f8, /* VIDEO_CC_SLEEP_CLK */
  362. 0x80d4, /* VIDEO_CC_XO_CLK */
  363. };
  364. static void clk_sm8750_regs_configure(struct device *dev, struct regmap *regmap)
  365. {
  366. /* Update DLY_ACCU_RED_SHIFTER_DONE to 0xF for mvs0, mvs0c */
  367. regmap_update_bits(regmap, 0x8074, GENMASK(25, 21), GENMASK(25, 21));
  368. regmap_update_bits(regmap, 0x8040, GENMASK(25, 21), GENMASK(25, 21));
  369. regmap_update_bits(regmap, 0x9f24, BIT(0), BIT(0));
  370. }
  371. static struct qcom_cc_driver_data video_cc_sm8750_driver_data = {
  372. .alpha_plls = video_cc_sm8750_plls,
  373. .num_alpha_plls = ARRAY_SIZE(video_cc_sm8750_plls),
  374. .clk_cbcrs = video_cc_sm8750_critical_cbcrs,
  375. .num_clk_cbcrs = ARRAY_SIZE(video_cc_sm8750_critical_cbcrs),
  376. .clk_regs_configure = clk_sm8750_regs_configure,
  377. };
  378. static const struct qcom_cc_desc video_cc_sm8750_desc = {
  379. .config = &video_cc_sm8750_regmap_config,
  380. .clks = video_cc_sm8750_clocks,
  381. .num_clks = ARRAY_SIZE(video_cc_sm8750_clocks),
  382. .resets = video_cc_sm8750_resets,
  383. .num_resets = ARRAY_SIZE(video_cc_sm8750_resets),
  384. .gdscs = video_cc_sm8750_gdscs,
  385. .num_gdscs = ARRAY_SIZE(video_cc_sm8750_gdscs),
  386. .use_rpm = true,
  387. .driver_data = &video_cc_sm8750_driver_data,
  388. };
  389. static const struct of_device_id video_cc_sm8750_match_table[] = {
  390. { .compatible = "qcom,sm8750-videocc" },
  391. { }
  392. };
  393. MODULE_DEVICE_TABLE(of, video_cc_sm8750_match_table);
  394. static int video_cc_sm8750_probe(struct platform_device *pdev)
  395. {
  396. return qcom_cc_probe(pdev, &video_cc_sm8750_desc);
  397. }
  398. static struct platform_driver video_cc_sm8750_driver = {
  399. .probe = video_cc_sm8750_probe,
  400. .driver = {
  401. .name = "video_cc-sm8750",
  402. .of_match_table = video_cc_sm8750_match_table,
  403. },
  404. };
  405. static int __init video_cc_sm8750_init(void)
  406. {
  407. return platform_driver_register(&video_cc_sm8750_driver);
  408. }
  409. subsys_initcall(video_cc_sm8750_init);
  410. static void __exit video_cc_sm8750_exit(void)
  411. {
  412. platform_driver_unregister(&video_cc_sm8750_driver);
  413. }
  414. module_exit(video_cc_sm8750_exit);
  415. MODULE_DESCRIPTION("QTI VIDEO_CC SM8750 Driver");
  416. MODULE_LICENSE("GPL");