videocc-milos.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2025, Luca Weiss <luca.weiss@fairphone.com>
  5. */
  6. #include <linux/clk-provider.h>
  7. #include <linux/mod_devicetable.h>
  8. #include <linux/module.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/regmap.h>
  11. #include <dt-bindings/clock/qcom,milos-videocc.h>
  12. #include "clk-alpha-pll.h"
  13. #include "clk-branch.h"
  14. #include "clk-rcg.h"
  15. #include "clk-regmap.h"
  16. #include "clk-regmap-divider.h"
  17. #include "common.h"
  18. #include "gdsc.h"
  19. #include "reset.h"
  20. /* Need to match the order of clocks in DT binding */
  21. enum {
  22. DT_BI_TCXO,
  23. DT_BI_TCXO_AO,
  24. DT_SLEEP_CLK,
  25. DT_IFACE,
  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 lucid_ole_vco[] = {
  33. { 249600000, 2300000000, 0 },
  34. };
  35. /* 604.8 MHz Configuration */
  36. static const struct alpha_pll_config video_cc_pll0_config = {
  37. .l = 0x1f,
  38. .alpha = 0x8000,
  39. .config_ctl_val = 0x20485699,
  40. .config_ctl_hi_val = 0x00182261,
  41. .config_ctl_hi1_val = 0x82aa299c,
  42. .test_ctl_val = 0x00000000,
  43. .test_ctl_hi_val = 0x00000003,
  44. .test_ctl_hi1_val = 0x00009000,
  45. .test_ctl_hi2_val = 0x00000034,
  46. .user_ctl_val = 0x00000000,
  47. .user_ctl_hi_val = 0x00000005,
  48. };
  49. static struct clk_alpha_pll video_cc_pll0 = {
  50. .offset = 0x0,
  51. .config = &video_cc_pll0_config,
  52. .vco_table = lucid_ole_vco,
  53. .num_vco = ARRAY_SIZE(lucid_ole_vco),
  54. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_OLE],
  55. .clkr = {
  56. .hw.init = &(const struct clk_init_data) {
  57. .name = "video_cc_pll0",
  58. .parent_data = &(const struct clk_parent_data) {
  59. .index = DT_BI_TCXO,
  60. },
  61. .num_parents = 1,
  62. .ops = &clk_alpha_pll_lucid_evo_ops,
  63. },
  64. },
  65. };
  66. static const struct parent_map video_cc_parent_map_0[] = {
  67. { P_BI_TCXO, 0 },
  68. };
  69. static const struct clk_parent_data video_cc_parent_data_0[] = {
  70. { .index = DT_BI_TCXO },
  71. };
  72. static const struct clk_parent_data video_cc_parent_data_0_ao[] = {
  73. { .index = DT_BI_TCXO_AO },
  74. };
  75. static const struct parent_map video_cc_parent_map_1[] = {
  76. { P_BI_TCXO, 0 },
  77. { P_VIDEO_CC_PLL0_OUT_MAIN, 1 },
  78. };
  79. static const struct clk_parent_data video_cc_parent_data_1[] = {
  80. { .index = DT_BI_TCXO },
  81. { .hw = &video_cc_pll0.clkr.hw },
  82. };
  83. static const struct parent_map video_cc_parent_map_2[] = {
  84. { P_SLEEP_CLK, 0 },
  85. };
  86. static const struct clk_parent_data video_cc_parent_data_2_ao[] = {
  87. { .index = DT_SLEEP_CLK },
  88. };
  89. static const struct freq_tbl ftbl_video_cc_ahb_clk_src[] = {
  90. F(19200000, P_BI_TCXO, 1, 0, 0),
  91. { }
  92. };
  93. static struct clk_rcg2 video_cc_ahb_clk_src = {
  94. .cmd_rcgr = 0x8030,
  95. .mnd_width = 0,
  96. .hid_width = 5,
  97. .parent_map = video_cc_parent_map_0,
  98. .freq_tbl = ftbl_video_cc_ahb_clk_src,
  99. .clkr.hw.init = &(const struct clk_init_data) {
  100. .name = "video_cc_ahb_clk_src",
  101. .parent_data = video_cc_parent_data_0_ao,
  102. .num_parents = ARRAY_SIZE(video_cc_parent_data_0_ao),
  103. .flags = CLK_SET_RATE_PARENT,
  104. .ops = &clk_rcg2_shared_ops,
  105. },
  106. };
  107. static const struct freq_tbl ftbl_video_cc_mvs0_clk_src[] = {
  108. F(604800000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  109. F(720000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  110. F(1014000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  111. F(1098000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  112. F(1332000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  113. F(1656000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  114. { }
  115. };
  116. static struct clk_rcg2 video_cc_mvs0_clk_src = {
  117. .cmd_rcgr = 0x8000,
  118. .mnd_width = 0,
  119. .hid_width = 5,
  120. .parent_map = video_cc_parent_map_1,
  121. .freq_tbl = ftbl_video_cc_mvs0_clk_src,
  122. .clkr.hw.init = &(const struct clk_init_data) {
  123. .name = "video_cc_mvs0_clk_src",
  124. .parent_data = video_cc_parent_data_1,
  125. .num_parents = ARRAY_SIZE(video_cc_parent_data_1),
  126. .flags = CLK_SET_RATE_PARENT,
  127. .ops = &clk_rcg2_shared_ops,
  128. },
  129. };
  130. static const struct freq_tbl ftbl_video_cc_sleep_clk_src[] = {
  131. F(32000, P_SLEEP_CLK, 1, 0, 0),
  132. { }
  133. };
  134. static struct clk_rcg2 video_cc_sleep_clk_src = {
  135. .cmd_rcgr = 0x8128,
  136. .mnd_width = 0,
  137. .hid_width = 5,
  138. .parent_map = video_cc_parent_map_2,
  139. .freq_tbl = ftbl_video_cc_sleep_clk_src,
  140. .clkr.hw.init = &(const struct clk_init_data) {
  141. .name = "video_cc_sleep_clk_src",
  142. .parent_data = video_cc_parent_data_2_ao,
  143. .num_parents = ARRAY_SIZE(video_cc_parent_data_2_ao),
  144. .flags = CLK_SET_RATE_PARENT,
  145. .ops = &clk_rcg2_ops,
  146. },
  147. };
  148. static struct clk_rcg2 video_cc_xo_clk_src = {
  149. .cmd_rcgr = 0x810c,
  150. .mnd_width = 0,
  151. .hid_width = 5,
  152. .parent_map = video_cc_parent_map_0,
  153. .freq_tbl = ftbl_video_cc_ahb_clk_src,
  154. .clkr.hw.init = &(const struct clk_init_data) {
  155. .name = "video_cc_xo_clk_src",
  156. .parent_data = video_cc_parent_data_0,
  157. .num_parents = ARRAY_SIZE(video_cc_parent_data_0),
  158. .flags = CLK_SET_RATE_PARENT,
  159. .ops = &clk_rcg2_ops,
  160. },
  161. };
  162. static struct clk_regmap_div video_cc_mvs0_div_clk_src = {
  163. .reg = 0x80c4,
  164. .shift = 0,
  165. .width = 4,
  166. .clkr.hw.init = &(const struct clk_init_data) {
  167. .name = "video_cc_mvs0_div_clk_src",
  168. .parent_hws = (const struct clk_hw*[]) {
  169. &video_cc_mvs0_clk_src.clkr.hw,
  170. },
  171. .num_parents = 1,
  172. .flags = CLK_SET_RATE_PARENT,
  173. .ops = &clk_regmap_div_ro_ops,
  174. },
  175. };
  176. static struct clk_regmap_div video_cc_mvs0c_div2_div_clk_src = {
  177. .reg = 0x8070,
  178. .shift = 0,
  179. .width = 4,
  180. .clkr.hw.init = &(const struct clk_init_data) {
  181. .name = "video_cc_mvs0c_div2_div_clk_src",
  182. .parent_hws = (const struct clk_hw*[]) {
  183. &video_cc_mvs0_clk_src.clkr.hw,
  184. },
  185. .num_parents = 1,
  186. .flags = CLK_SET_RATE_PARENT,
  187. .ops = &clk_regmap_div_ro_ops,
  188. },
  189. };
  190. static struct clk_branch video_cc_mvs0_clk = {
  191. .halt_reg = 0x80b8,
  192. .halt_check = BRANCH_HALT_VOTED,
  193. .hwcg_reg = 0x80b8,
  194. .hwcg_bit = 1,
  195. .clkr = {
  196. .enable_reg = 0x80b8,
  197. .enable_mask = BIT(0),
  198. .hw.init = &(const struct clk_init_data) {
  199. .name = "video_cc_mvs0_clk",
  200. .parent_hws = (const struct clk_hw*[]) {
  201. &video_cc_mvs0_div_clk_src.clkr.hw,
  202. },
  203. .num_parents = 1,
  204. .flags = CLK_SET_RATE_PARENT,
  205. .ops = &clk_branch2_ops,
  206. },
  207. },
  208. };
  209. static struct clk_branch video_cc_mvs0_shift_clk = {
  210. .halt_reg = 0x8144,
  211. .halt_check = BRANCH_HALT_VOTED,
  212. .hwcg_reg = 0x8144,
  213. .hwcg_bit = 1,
  214. .clkr = {
  215. .enable_reg = 0x8144,
  216. .enable_mask = BIT(0),
  217. .hw.init = &(const struct clk_init_data) {
  218. .name = "video_cc_mvs0_shift_clk",
  219. .parent_hws = (const struct clk_hw*[]) {
  220. &video_cc_xo_clk_src.clkr.hw,
  221. },
  222. .num_parents = 1,
  223. .flags = CLK_SET_RATE_PARENT,
  224. .ops = &clk_branch2_ops,
  225. },
  226. },
  227. };
  228. static struct clk_branch video_cc_mvs0c_clk = {
  229. .halt_reg = 0x8064,
  230. .halt_check = BRANCH_HALT,
  231. .clkr = {
  232. .enable_reg = 0x8064,
  233. .enable_mask = BIT(0),
  234. .hw.init = &(const struct clk_init_data) {
  235. .name = "video_cc_mvs0c_clk",
  236. .parent_hws = (const struct clk_hw*[]) {
  237. &video_cc_mvs0c_div2_div_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_shift_clk = {
  246. .halt_reg = 0x8148,
  247. .halt_check = BRANCH_HALT_VOTED,
  248. .hwcg_reg = 0x8148,
  249. .hwcg_bit = 1,
  250. .clkr = {
  251. .enable_reg = 0x8148,
  252. .enable_mask = BIT(0),
  253. .hw.init = &(const struct clk_init_data) {
  254. .name = "video_cc_mvs0c_shift_clk",
  255. .parent_hws = (const struct clk_hw*[]) {
  256. &video_cc_xo_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 gdsc video_cc_mvs0c_gdsc = {
  265. .gdscr = 0x804c,
  266. .en_rest_wait_val = 0x2,
  267. .en_few_wait_val = 0x2,
  268. .clk_dis_wait_val = 0x6,
  269. .pd = {
  270. .name = "video_cc_mvs0c_gdsc",
  271. },
  272. .pwrsts = PWRSTS_OFF_ON,
  273. .flags = POLL_CFG_GDSCR | RETAIN_FF_ENABLE,
  274. };
  275. static struct gdsc video_cc_mvs0_gdsc = {
  276. .gdscr = 0x80a4,
  277. .en_rest_wait_val = 0x2,
  278. .en_few_wait_val = 0x2,
  279. .clk_dis_wait_val = 0x6,
  280. .pd = {
  281. .name = "video_cc_mvs0_gdsc",
  282. },
  283. .pwrsts = PWRSTS_OFF_ON,
  284. .parent = &video_cc_mvs0c_gdsc.pd,
  285. .flags = POLL_CFG_GDSCR | RETAIN_FF_ENABLE | HW_CTRL_TRIGGER,
  286. };
  287. static struct clk_regmap *video_cc_milos_clocks[] = {
  288. [VIDEO_CC_AHB_CLK_SRC] = &video_cc_ahb_clk_src.clkr,
  289. [VIDEO_CC_MVS0_CLK] = &video_cc_mvs0_clk.clkr,
  290. [VIDEO_CC_MVS0_CLK_SRC] = &video_cc_mvs0_clk_src.clkr,
  291. [VIDEO_CC_MVS0_DIV_CLK_SRC] = &video_cc_mvs0_div_clk_src.clkr,
  292. [VIDEO_CC_MVS0_SHIFT_CLK] = &video_cc_mvs0_shift_clk.clkr,
  293. [VIDEO_CC_MVS0C_CLK] = &video_cc_mvs0c_clk.clkr,
  294. [VIDEO_CC_MVS0C_DIV2_DIV_CLK_SRC] = &video_cc_mvs0c_div2_div_clk_src.clkr,
  295. [VIDEO_CC_MVS0C_SHIFT_CLK] = &video_cc_mvs0c_shift_clk.clkr,
  296. [VIDEO_CC_PLL0] = &video_cc_pll0.clkr,
  297. [VIDEO_CC_SLEEP_CLK_SRC] = &video_cc_sleep_clk_src.clkr,
  298. [VIDEO_CC_XO_CLK_SRC] = &video_cc_xo_clk_src.clkr,
  299. };
  300. static struct gdsc *video_cc_milos_gdscs[] = {
  301. [VIDEO_CC_MVS0C_GDSC] = &video_cc_mvs0c_gdsc,
  302. [VIDEO_CC_MVS0_GDSC] = &video_cc_mvs0_gdsc,
  303. };
  304. static const struct qcom_reset_map video_cc_milos_resets[] = {
  305. [VIDEO_CC_INTERFACE_BCR] = { 0x80f0 },
  306. [VIDEO_CC_MVS0_BCR] = { 0x80a0 },
  307. [VIDEO_CC_MVS0C_CLK_ARES] = { 0x8064, 2 },
  308. [VIDEO_CC_MVS0C_BCR] = { 0x8048 },
  309. };
  310. static struct clk_alpha_pll *video_cc_milos_plls[] = {
  311. &video_cc_pll0,
  312. };
  313. static u32 video_cc_milos_critical_cbcrs[] = {
  314. 0x80f4, /* VIDEO_CC_AHB_CLK */
  315. 0x8140, /* VIDEO_CC_SLEEP_CLK */
  316. 0x8124, /* VIDEO_CC_XO_CLK */
  317. };
  318. static const struct regmap_config video_cc_milos_regmap_config = {
  319. .reg_bits = 32,
  320. .reg_stride = 4,
  321. .val_bits = 32,
  322. .max_register = 0x9f50,
  323. .fast_io = true,
  324. };
  325. static struct qcom_cc_driver_data video_cc_milos_driver_data = {
  326. .alpha_plls = video_cc_milos_plls,
  327. .num_alpha_plls = ARRAY_SIZE(video_cc_milos_plls),
  328. .clk_cbcrs = video_cc_milos_critical_cbcrs,
  329. .num_clk_cbcrs = ARRAY_SIZE(video_cc_milos_critical_cbcrs),
  330. };
  331. static const struct qcom_cc_desc video_cc_milos_desc = {
  332. .config = &video_cc_milos_regmap_config,
  333. .clks = video_cc_milos_clocks,
  334. .num_clks = ARRAY_SIZE(video_cc_milos_clocks),
  335. .resets = video_cc_milos_resets,
  336. .num_resets = ARRAY_SIZE(video_cc_milos_resets),
  337. .gdscs = video_cc_milos_gdscs,
  338. .num_gdscs = ARRAY_SIZE(video_cc_milos_gdscs),
  339. .use_rpm = true,
  340. .driver_data = &video_cc_milos_driver_data,
  341. };
  342. static const struct of_device_id video_cc_milos_match_table[] = {
  343. { .compatible = "qcom,milos-videocc" },
  344. { }
  345. };
  346. MODULE_DEVICE_TABLE(of, video_cc_milos_match_table);
  347. static int video_cc_milos_probe(struct platform_device *pdev)
  348. {
  349. return qcom_cc_probe(pdev, &video_cc_milos_desc);
  350. }
  351. static struct platform_driver video_cc_milos_driver = {
  352. .probe = video_cc_milos_probe,
  353. .driver = {
  354. .name = "video_cc-milos",
  355. .of_match_table = video_cc_milos_match_table,
  356. },
  357. };
  358. module_platform_driver(video_cc_milos_driver);
  359. MODULE_DESCRIPTION("QTI VIDEO_CC Milos Driver");
  360. MODULE_LICENSE("GPL");