videocc-pineapple.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2022-2024, Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #include <linux/clk.h>
  6. #include <linux/clk-provider.h>
  7. #include <linux/err.h>
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/of_device.h>
  11. #include <linux/of.h>
  12. #include <linux/regmap.h>
  13. #include <linux/pm_runtime.h>
  14. #include <dt-bindings/clock/qcom,videocc-pineapple.h>
  15. #include "clk-alpha-pll.h"
  16. #include "clk-branch.h"
  17. #include "clk-pll.h"
  18. #include "clk-rcg.h"
  19. #include "clk-regmap.h"
  20. #include "clk-regmap-divider.h"
  21. #include "clk-regmap-mux.h"
  22. #include "common.h"
  23. #include "reset.h"
  24. #include "vdd-level.h"
  25. static DEFINE_VDD_REGULATORS(vdd_mm, VDD_HIGH + 1, 1, vdd_corner);
  26. static DEFINE_VDD_REGULATORS(vdd_mxc, VDD_HIGH + 1, 1, vdd_corner);
  27. static struct clk_vdd_class *video_cc_pineapple_regulators[] = {
  28. &vdd_mm,
  29. &vdd_mxc,
  30. };
  31. enum {
  32. P_BI_TCXO,
  33. P_SLEEP_CLK,
  34. P_VIDEO_CC_PLL0_OUT_MAIN,
  35. P_VIDEO_CC_PLL1_OUT_MAIN,
  36. };
  37. static const struct pll_vco lucid_ole_vco[] = {
  38. { 249600000, 2300000000, 0 },
  39. };
  40. static const struct alpha_pll_config video_cc_pll0_config = {
  41. .l = 0x1E,
  42. .cal_l = 0x44,
  43. .cal_l_ringosc = 0x44,
  44. .alpha = 0xA000,
  45. .config_ctl_val = 0x20485699,
  46. .config_ctl_hi_val = 0x00182261,
  47. .config_ctl_hi1_val = 0x82AA299C,
  48. .test_ctl_val = 0x00000000,
  49. .test_ctl_hi_val = 0x00000003,
  50. .test_ctl_hi1_val = 0x00009000,
  51. .test_ctl_hi2_val = 0x00000034,
  52. .user_ctl_val = 0x00000000,
  53. .user_ctl_hi_val = 0x00000005,
  54. };
  55. /* 576MHz Configuration */
  56. static const struct alpha_pll_config video_cc_pll0_config_cliffs = {
  57. .l = 0x1e,
  58. .cal_l = 0x44,
  59. .cal_l_ringosc = 0x44,
  60. .alpha = 0x0,
  61. .config_ctl_val = 0x20485699,
  62. .config_ctl_hi_val = 0x00182261,
  63. .config_ctl_hi1_val = 0x82aa299c,
  64. .test_ctl_val = 0x00000000,
  65. .test_ctl_hi_val = 0x00000003,
  66. .test_ctl_hi1_val = 0x00009000,
  67. .test_ctl_hi2_val = 0x00000034,
  68. .user_ctl_val = 0x00000000,
  69. .user_ctl_hi_val = 0x00000005,
  70. };
  71. static struct clk_alpha_pll video_cc_pll0 = {
  72. .offset = 0x0,
  73. .vco_table = lucid_ole_vco,
  74. .num_vco = ARRAY_SIZE(lucid_ole_vco),
  75. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_OLE],
  76. .clkr = {
  77. .hw.init = &(const struct clk_init_data){
  78. .name = "video_cc_pll0",
  79. .parent_data = &(const struct clk_parent_data){
  80. .fw_name = "bi_tcxo",
  81. },
  82. .num_parents = 1,
  83. .ops = &clk_alpha_pll_lucid_ole_ops,
  84. },
  85. .vdd_data = {
  86. .vdd_class = &vdd_mxc,
  87. .num_rate_max = VDD_NUM,
  88. .rate_max = (unsigned long[VDD_NUM]) {
  89. [VDD_LOWER_D1] = 615000000,
  90. [VDD_LOW] = 1100000000,
  91. [VDD_LOW_L1] = 1600000000,
  92. [VDD_NOMINAL] = 2000000000,
  93. [VDD_HIGH_L1] = 2300000000},
  94. },
  95. },
  96. };
  97. static const struct alpha_pll_config video_cc_pll1_config = {
  98. .l = 0x2B,
  99. .cal_l = 0x44,
  100. .cal_l_ringosc = 0x44,
  101. .alpha = 0xC000,
  102. .config_ctl_val = 0x20485699,
  103. .config_ctl_hi_val = 0x00182261,
  104. .config_ctl_hi1_val = 0x82AA299C,
  105. .test_ctl_val = 0x00000000,
  106. .test_ctl_hi_val = 0x00000003,
  107. .test_ctl_hi1_val = 0x00009000,
  108. .test_ctl_hi2_val = 0x00000034,
  109. .user_ctl_val = 0x00000000,
  110. .user_ctl_hi_val = 0x00000005,
  111. };
  112. static struct clk_alpha_pll video_cc_pll1 = {
  113. .offset = 0x1000,
  114. .vco_table = lucid_ole_vco,
  115. .num_vco = ARRAY_SIZE(lucid_ole_vco),
  116. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_OLE],
  117. .clkr = {
  118. .hw.init = &(const struct clk_init_data){
  119. .name = "video_cc_pll1",
  120. .parent_data = &(const struct clk_parent_data){
  121. .fw_name = "bi_tcxo",
  122. },
  123. .num_parents = 1,
  124. .ops = &clk_alpha_pll_lucid_ole_ops,
  125. },
  126. .vdd_data = {
  127. .vdd_class = &vdd_mxc,
  128. .num_rate_max = VDD_NUM,
  129. .rate_max = (unsigned long[VDD_NUM]) {
  130. [VDD_LOWER_D1] = 615000000,
  131. [VDD_LOW] = 1100000000,
  132. [VDD_LOW_L1] = 1600000000,
  133. [VDD_NOMINAL] = 2000000000,
  134. [VDD_HIGH_L1] = 2300000000},
  135. },
  136. },
  137. };
  138. static const struct parent_map video_cc_parent_map_0[] = {
  139. { P_BI_TCXO, 0 },
  140. };
  141. static const struct clk_parent_data video_cc_parent_data_0_ao[] = {
  142. { .fw_name = "bi_tcxo_ao" },
  143. };
  144. static const struct parent_map video_cc_parent_map_1[] = {
  145. { P_BI_TCXO, 0 },
  146. { P_VIDEO_CC_PLL0_OUT_MAIN, 1 },
  147. };
  148. static const struct clk_parent_data video_cc_parent_data_1[] = {
  149. { .fw_name = "bi_tcxo" },
  150. { .hw = &video_cc_pll0.clkr.hw },
  151. };
  152. static const struct parent_map video_cc_parent_map_2[] = {
  153. { P_BI_TCXO, 0 },
  154. { P_VIDEO_CC_PLL1_OUT_MAIN, 1 },
  155. };
  156. static const struct clk_parent_data video_cc_parent_data_2[] = {
  157. { .fw_name = "bi_tcxo" },
  158. { .hw = &video_cc_pll1.clkr.hw },
  159. };
  160. static const struct parent_map video_cc_parent_map_3[] = {
  161. { P_SLEEP_CLK, 0 },
  162. };
  163. static const struct clk_parent_data video_cc_parent_data_3[] = {
  164. { .fw_name = "sleep_clk" },
  165. };
  166. static const struct freq_tbl ftbl_video_cc_ahb_clk_src[] = {
  167. F(19200000, P_BI_TCXO, 1, 0, 0),
  168. { }
  169. };
  170. static struct clk_rcg2 video_cc_ahb_clk_src = {
  171. .cmd_rcgr = 0x8030,
  172. .mnd_width = 0,
  173. .hid_width = 5,
  174. .parent_map = video_cc_parent_map_0,
  175. .freq_tbl = ftbl_video_cc_ahb_clk_src,
  176. .enable_safe_config = true,
  177. .flags = HW_CLK_CTRL_MODE,
  178. .clkr.hw.init = &(const struct clk_init_data){
  179. .name = "video_cc_ahb_clk_src",
  180. .parent_data = video_cc_parent_data_0_ao,
  181. .num_parents = ARRAY_SIZE(video_cc_parent_data_0_ao),
  182. .flags = CLK_SET_RATE_PARENT,
  183. .ops = &clk_rcg2_ops,
  184. },
  185. };
  186. static const struct freq_tbl ftbl_video_cc_mvs0_clk_src[] = {
  187. F(588000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  188. F(840000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  189. F(1140000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  190. F(1305000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  191. F(1440000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  192. F(1600000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  193. { }
  194. };
  195. static const struct freq_tbl ftbl_video_cc_mvs0_clk_src_pineapple_v2[] = {
  196. F(588000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  197. F(900000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  198. F(1140000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  199. F(1305000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  200. F(1440000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  201. F(1600000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  202. { }
  203. };
  204. static const struct freq_tbl ftbl_video_cc_mvs0_clk_src_cliffs[] = {
  205. F(576000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  206. F(633000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  207. F(720000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  208. F(1014000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  209. F(1098000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  210. F(1113000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  211. F(1332000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  212. F(1600000000, P_VIDEO_CC_PLL0_OUT_MAIN, 1, 0, 0),
  213. { }
  214. };
  215. static struct clk_rcg2 video_cc_mvs0_clk_src = {
  216. .cmd_rcgr = 0x8000,
  217. .mnd_width = 0,
  218. .hid_width = 5,
  219. .parent_map = video_cc_parent_map_1,
  220. .freq_tbl = ftbl_video_cc_mvs0_clk_src,
  221. .enable_safe_config = true,
  222. .flags = HW_CLK_CTRL_MODE,
  223. .clkr.hw.init = &(const struct clk_init_data){
  224. .name = "video_cc_mvs0_clk_src",
  225. .parent_data = video_cc_parent_data_1,
  226. .num_parents = ARRAY_SIZE(video_cc_parent_data_1),
  227. .flags = CLK_SET_RATE_PARENT,
  228. .ops = &clk_rcg2_ops,
  229. },
  230. .clkr.vdd_data = {
  231. .vdd_classes = video_cc_pineapple_regulators,
  232. .num_vdd_classes = ARRAY_SIZE(video_cc_pineapple_regulators),
  233. .num_rate_max = VDD_NUM,
  234. .rate_max = (unsigned long[VDD_NUM]) {
  235. [VDD_LOWER_D1] = 588000000,
  236. [VDD_LOWER] = 840000000,
  237. [VDD_LOW] = 1140000000,
  238. [VDD_LOW_L1] = 1305000000,
  239. [VDD_NOMINAL] = 1440000000,
  240. [VDD_HIGH] = 1600000000},
  241. },
  242. };
  243. static const struct freq_tbl ftbl_video_cc_mvs1_clk_src[] = {
  244. F(840000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
  245. F(1050000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
  246. F(1350000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
  247. F(1500000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
  248. F(1650000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
  249. { }
  250. };
  251. static const struct freq_tbl ftbl_video_cc_mvs1_clk_src_pineapple_v2[] = {
  252. F(840000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
  253. F(1110000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
  254. F(1350000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
  255. F(1500000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
  256. F(1650000000, P_VIDEO_CC_PLL1_OUT_MAIN, 1, 0, 0),
  257. { }
  258. };
  259. static struct clk_rcg2 video_cc_mvs1_clk_src = {
  260. .cmd_rcgr = 0x8018,
  261. .mnd_width = 0,
  262. .hid_width = 5,
  263. .parent_map = video_cc_parent_map_2,
  264. .freq_tbl = ftbl_video_cc_mvs1_clk_src,
  265. .enable_safe_config = true,
  266. .flags = HW_CLK_CTRL_MODE,
  267. .clkr.hw.init = &(const struct clk_init_data){
  268. .name = "video_cc_mvs1_clk_src",
  269. .parent_data = video_cc_parent_data_2,
  270. .num_parents = ARRAY_SIZE(video_cc_parent_data_2),
  271. .flags = CLK_SET_RATE_PARENT,
  272. .ops = &clk_rcg2_ops,
  273. },
  274. .clkr.vdd_data = {
  275. .vdd_classes = video_cc_pineapple_regulators,
  276. .num_vdd_classes = ARRAY_SIZE(video_cc_pineapple_regulators),
  277. .num_rate_max = VDD_NUM,
  278. .rate_max = (unsigned long[VDD_NUM]) {
  279. [VDD_LOWER_D1] = 840000000,
  280. [VDD_LOWER] = 1050000000,
  281. [VDD_LOW] = 1350000000,
  282. [VDD_LOW_L1] = 1500000000,
  283. [VDD_NOMINAL] = 1650000000},
  284. },
  285. };
  286. static const struct freq_tbl ftbl_video_cc_sleep_clk_src[] = {
  287. F(32000, P_SLEEP_CLK, 1, 0, 0),
  288. { }
  289. };
  290. static struct clk_rcg2 video_cc_sleep_clk_src = {
  291. .cmd_rcgr = 0x8138,
  292. .mnd_width = 0,
  293. .hid_width = 5,
  294. .parent_map = video_cc_parent_map_3,
  295. .freq_tbl = ftbl_video_cc_sleep_clk_src,
  296. .clkr.hw.init = &(const struct clk_init_data){
  297. .name = "video_cc_sleep_clk_src",
  298. .parent_data = video_cc_parent_data_3,
  299. .num_parents = ARRAY_SIZE(video_cc_parent_data_3),
  300. .flags = CLK_SET_RATE_PARENT,
  301. .ops = &clk_rcg2_ops,
  302. },
  303. .clkr.vdd_data = {
  304. .vdd_class = &vdd_mm,
  305. .num_rate_max = VDD_NUM,
  306. .rate_max = (unsigned long[VDD_NUM]) {
  307. [VDD_LOWER_D1] = 32000},
  308. },
  309. };
  310. static struct clk_rcg2 video_cc_xo_clk_src = {
  311. .cmd_rcgr = 0x810c,
  312. .mnd_width = 0,
  313. .hid_width = 5,
  314. .parent_map = video_cc_parent_map_0,
  315. .freq_tbl = ftbl_video_cc_ahb_clk_src,
  316. .clkr.hw.init = &(const struct clk_init_data){
  317. .name = "video_cc_xo_clk_src",
  318. .parent_data = video_cc_parent_data_0_ao,
  319. .num_parents = ARRAY_SIZE(video_cc_parent_data_0_ao),
  320. .flags = CLK_SET_RATE_PARENT,
  321. .ops = &clk_rcg2_ops,
  322. },
  323. };
  324. static struct clk_regmap_div video_cc_mvs0_div_clk_src = {
  325. .reg = 0x80c4,
  326. .shift = 0,
  327. .width = 4,
  328. .clkr.hw.init = &(const struct clk_init_data) {
  329. .name = "video_cc_mvs0_div_clk_src",
  330. .parent_hws = (const struct clk_hw*[]){
  331. &video_cc_mvs0_clk_src.clkr.hw,
  332. },
  333. .num_parents = 1,
  334. .flags = CLK_SET_RATE_PARENT,
  335. .ops = &clk_regmap_div_ro_ops,
  336. },
  337. };
  338. static struct clk_regmap_div video_cc_mvs0c_div2_div_clk_src = {
  339. .reg = 0x8070,
  340. .shift = 0,
  341. .width = 4,
  342. .clkr.hw.init = &(const struct clk_init_data) {
  343. .name = "video_cc_mvs0c_div2_div_clk_src",
  344. .parent_hws = (const struct clk_hw*[]){
  345. &video_cc_mvs0_clk_src.clkr.hw,
  346. },
  347. .num_parents = 1,
  348. .flags = CLK_SET_RATE_PARENT,
  349. .ops = &clk_regmap_div_ro_ops,
  350. },
  351. };
  352. static struct clk_regmap_div video_cc_mvs1_div_clk_src = {
  353. .reg = 0x80ec,
  354. .shift = 0,
  355. .width = 4,
  356. .clkr.hw.init = &(const struct clk_init_data) {
  357. .name = "video_cc_mvs1_div_clk_src",
  358. .parent_hws = (const struct clk_hw*[]){
  359. &video_cc_mvs1_clk_src.clkr.hw,
  360. },
  361. .num_parents = 1,
  362. .flags = CLK_SET_RATE_PARENT,
  363. .ops = &clk_regmap_div_ro_ops,
  364. },
  365. };
  366. static struct clk_regmap_div video_cc_mvs1c_div2_div_clk_src = {
  367. .reg = 0x809c,
  368. .shift = 0,
  369. .width = 4,
  370. .clkr.hw.init = &(const struct clk_init_data) {
  371. .name = "video_cc_mvs1c_div2_div_clk_src",
  372. .parent_hws = (const struct clk_hw*[]){
  373. &video_cc_mvs1_clk_src.clkr.hw,
  374. },
  375. .num_parents = 1,
  376. .flags = CLK_SET_RATE_PARENT,
  377. .ops = &clk_regmap_div_ro_ops,
  378. },
  379. };
  380. static struct clk_branch video_cc_mvs0_clk = {
  381. .halt_reg = 0x80b8,
  382. .halt_check = BRANCH_HALT_VOTED,
  383. .hwcg_reg = 0x80b8,
  384. .hwcg_bit = 1,
  385. .clkr = {
  386. .enable_reg = 0x80b8,
  387. .enable_mask = BIT(0),
  388. .hw.init = &(const struct clk_init_data){
  389. .name = "video_cc_mvs0_clk",
  390. .parent_hws = (const struct clk_hw*[]){
  391. &video_cc_mvs0_div_clk_src.clkr.hw,
  392. },
  393. .num_parents = 1,
  394. .flags = CLK_SET_RATE_PARENT,
  395. .ops = &clk_branch2_ops,
  396. },
  397. },
  398. };
  399. static struct clk_branch video_cc_mvs0_shift_clk = {
  400. .halt_reg = 0x8128,
  401. .halt_check = BRANCH_HALT_VOTED,
  402. .hwcg_reg = 0x8128,
  403. .hwcg_bit = 1,
  404. .clkr = {
  405. .enable_reg = 0x8128,
  406. .enable_mask = BIT(0),
  407. .hw.init = &(const struct clk_init_data){
  408. .name = "video_cc_mvs0_shift_clk",
  409. .parent_hws = (const struct clk_hw*[]){
  410. &video_cc_xo_clk_src.clkr.hw,
  411. },
  412. .num_parents = 1,
  413. .flags = CLK_SET_RATE_PARENT,
  414. .ops = &clk_branch2_ops,
  415. },
  416. },
  417. };
  418. static struct clk_branch video_cc_mvs0c_clk = {
  419. .halt_reg = 0x8064,
  420. .halt_check = BRANCH_HALT,
  421. .clkr = {
  422. .enable_reg = 0x8064,
  423. .enable_mask = BIT(0),
  424. .hw.init = &(const struct clk_init_data){
  425. .name = "video_cc_mvs0c_clk",
  426. .parent_hws = (const struct clk_hw*[]){
  427. &video_cc_mvs0c_div2_div_clk_src.clkr.hw,
  428. },
  429. .num_parents = 1,
  430. .flags = CLK_SET_RATE_PARENT,
  431. .ops = &clk_branch2_ops,
  432. },
  433. },
  434. };
  435. static struct clk_branch video_cc_mvs0c_shift_clk = {
  436. .halt_reg = 0x812c,
  437. .halt_check = BRANCH_HALT_VOTED,
  438. .hwcg_reg = 0x812c,
  439. .hwcg_bit = 1,
  440. .clkr = {
  441. .enable_reg = 0x812c,
  442. .enable_mask = BIT(0),
  443. .hw.init = &(const struct clk_init_data){
  444. .name = "video_cc_mvs0c_shift_clk",
  445. .parent_hws = (const struct clk_hw*[]){
  446. &video_cc_xo_clk_src.clkr.hw,
  447. },
  448. .num_parents = 1,
  449. .flags = CLK_SET_RATE_PARENT,
  450. .ops = &clk_branch2_ops,
  451. },
  452. },
  453. };
  454. static struct clk_branch video_cc_mvs1_clk = {
  455. .halt_reg = 0x80e0,
  456. .halt_check = BRANCH_HALT_VOTED,
  457. .hwcg_reg = 0x80e0,
  458. .hwcg_bit = 1,
  459. .clkr = {
  460. .enable_reg = 0x80e0,
  461. .enable_mask = BIT(0),
  462. .hw.init = &(const struct clk_init_data){
  463. .name = "video_cc_mvs1_clk",
  464. .parent_hws = (const struct clk_hw*[]){
  465. &video_cc_mvs1_div_clk_src.clkr.hw,
  466. },
  467. .num_parents = 1,
  468. .flags = CLK_SET_RATE_PARENT,
  469. .ops = &clk_branch2_ops,
  470. },
  471. },
  472. };
  473. static struct clk_branch video_cc_mvs1_shift_clk = {
  474. .halt_reg = 0x8130,
  475. .halt_check = BRANCH_HALT_VOTED,
  476. .hwcg_reg = 0x8130,
  477. .hwcg_bit = 1,
  478. .clkr = {
  479. .enable_reg = 0x8130,
  480. .enable_mask = BIT(0),
  481. .hw.init = &(const struct clk_init_data){
  482. .name = "video_cc_mvs1_shift_clk",
  483. .parent_hws = (const struct clk_hw*[]){
  484. &video_cc_xo_clk_src.clkr.hw,
  485. },
  486. .num_parents = 1,
  487. .flags = CLK_SET_RATE_PARENT,
  488. .ops = &clk_branch2_ops,
  489. },
  490. },
  491. };
  492. static struct clk_branch video_cc_mvs1c_clk = {
  493. .halt_reg = 0x8090,
  494. .halt_check = BRANCH_HALT,
  495. .clkr = {
  496. .enable_reg = 0x8090,
  497. .enable_mask = BIT(0),
  498. .hw.init = &(const struct clk_init_data){
  499. .name = "video_cc_mvs1c_clk",
  500. .parent_hws = (const struct clk_hw*[]){
  501. &video_cc_mvs1c_div2_div_clk_src.clkr.hw,
  502. },
  503. .num_parents = 1,
  504. .flags = CLK_SET_RATE_PARENT,
  505. .ops = &clk_branch2_ops,
  506. },
  507. },
  508. };
  509. static struct clk_branch video_cc_mvs1c_shift_clk = {
  510. .halt_reg = 0x8134,
  511. .halt_check = BRANCH_HALT_VOTED,
  512. .hwcg_reg = 0x8134,
  513. .hwcg_bit = 1,
  514. .clkr = {
  515. .enable_reg = 0x8134,
  516. .enable_mask = BIT(0),
  517. .hw.init = &(const struct clk_init_data){
  518. .name = "video_cc_mvs1c_shift_clk",
  519. .parent_hws = (const struct clk_hw*[]){
  520. &video_cc_xo_clk_src.clkr.hw,
  521. },
  522. .num_parents = 1,
  523. .flags = CLK_SET_RATE_PARENT,
  524. .ops = &clk_branch2_ops,
  525. },
  526. },
  527. };
  528. static struct clk_regmap *video_cc_pineapple_clocks[] = {
  529. [VIDEO_CC_AHB_CLK_SRC] = &video_cc_ahb_clk_src.clkr,
  530. [VIDEO_CC_MVS0_CLK] = &video_cc_mvs0_clk.clkr,
  531. [VIDEO_CC_MVS0_CLK_SRC] = &video_cc_mvs0_clk_src.clkr,
  532. [VIDEO_CC_MVS0_DIV_CLK_SRC] = &video_cc_mvs0_div_clk_src.clkr,
  533. [VIDEO_CC_MVS0_SHIFT_CLK] = &video_cc_mvs0_shift_clk.clkr,
  534. [VIDEO_CC_MVS0C_CLK] = &video_cc_mvs0c_clk.clkr,
  535. [VIDEO_CC_MVS0C_DIV2_DIV_CLK_SRC] = &video_cc_mvs0c_div2_div_clk_src.clkr,
  536. [VIDEO_CC_MVS0C_SHIFT_CLK] = &video_cc_mvs0c_shift_clk.clkr,
  537. [VIDEO_CC_MVS1_CLK] = &video_cc_mvs1_clk.clkr,
  538. [VIDEO_CC_MVS1_CLK_SRC] = &video_cc_mvs1_clk_src.clkr,
  539. [VIDEO_CC_MVS1_DIV_CLK_SRC] = &video_cc_mvs1_div_clk_src.clkr,
  540. [VIDEO_CC_MVS1_SHIFT_CLK] = &video_cc_mvs1_shift_clk.clkr,
  541. [VIDEO_CC_MVS1C_CLK] = &video_cc_mvs1c_clk.clkr,
  542. [VIDEO_CC_MVS1C_DIV2_DIV_CLK_SRC] = &video_cc_mvs1c_div2_div_clk_src.clkr,
  543. [VIDEO_CC_MVS1C_SHIFT_CLK] = &video_cc_mvs1c_shift_clk.clkr,
  544. [VIDEO_CC_PLL0] = &video_cc_pll0.clkr,
  545. [VIDEO_CC_PLL1] = &video_cc_pll1.clkr,
  546. [VIDEO_CC_SLEEP_CLK_SRC] = &video_cc_sleep_clk_src.clkr,
  547. [VIDEO_CC_XO_CLK_SRC] = &video_cc_xo_clk_src.clkr,
  548. };
  549. static const struct qcom_reset_map video_cc_pineapple_resets[] = {
  550. [VCODEC_VIDEO_CC_INTERFACE_BCR] = { 0x80f0 },
  551. [VCODEC_VIDEO_CC_MVS0_BCR] = { 0x80a0 },
  552. [VIDEO_CC_MVS0C_CLK_ARES] = { 0x8064, 2 },
  553. [VCODEC_VIDEO_CC_MVS0C_BCR] = { 0x8048 },
  554. [VCODEC_VIDEO_CC_MVS1_BCR] = { 0x80c8 },
  555. [VIDEO_CC_MVS1C_CLK_ARES] = { 0x8090, 2 },
  556. [VCODEC_VIDEO_CC_MVS1C_BCR] = { 0x8074 },
  557. [VIDEO_CC_XO_CLK_ARES] = { 0x8124, 2 },
  558. [VIDEO_CC_MVS0_CLK_ARES] = { 0x80b8, 2 },
  559. };
  560. static const struct regmap_config video_cc_pineapple_regmap_config = {
  561. .reg_bits = 32,
  562. .reg_stride = 4,
  563. .val_bits = 32,
  564. .max_register = 0x9f4c,
  565. .fast_io = true,
  566. };
  567. static struct qcom_cc_desc video_cc_pineapple_desc = {
  568. .config = &video_cc_pineapple_regmap_config,
  569. .clks = video_cc_pineapple_clocks,
  570. .num_clks = ARRAY_SIZE(video_cc_pineapple_clocks),
  571. .resets = video_cc_pineapple_resets,
  572. .num_resets = ARRAY_SIZE(video_cc_pineapple_resets),
  573. .clk_regulators = video_cc_pineapple_regulators,
  574. .num_clk_regulators = ARRAY_SIZE(video_cc_pineapple_regulators),
  575. };
  576. static const struct of_device_id video_cc_pineapple_match_table[] = {
  577. { .compatible = "qcom,pineapple-videocc" },
  578. { .compatible = "qcom,pineapple-videocc-v2" },
  579. { .compatible = "qcom,cliffs-videocc" },
  580. { }
  581. };
  582. MODULE_DEVICE_TABLE(of, video_cc_pineapple_match_table);
  583. static void video_cc_pineapple_fixup_pineapplev2(struct regmap *regmap)
  584. {
  585. video_cc_mvs0_clk_src.freq_tbl = ftbl_video_cc_mvs0_clk_src_pineapple_v2;
  586. video_cc_mvs0_clk_src.clkr.vdd_data.rate_max[VDD_LOWER] = 900000000;
  587. video_cc_mvs1_clk_src.freq_tbl = ftbl_video_cc_mvs1_clk_src_pineapple_v2;
  588. video_cc_mvs1_clk_src.clkr.vdd_data.rate_max[VDD_LOWER] = 1110000000;
  589. }
  590. static void video_cc_pineapple_fixup_cliffs(struct regmap *regmap)
  591. {
  592. clk_lucid_ole_pll_configure(&video_cc_pll0, regmap, &video_cc_pll0_config_cliffs);
  593. video_cc_mvs0_clk_src.freq_tbl = ftbl_video_cc_mvs0_clk_src_cliffs;
  594. video_cc_mvs0_clk_src.clkr.vdd_data.rate_max[VDD_LOWER_D1] = 576000000;
  595. video_cc_mvs0_clk_src.clkr.vdd_data.rate_max[VDD_LOWER] = 720000000;
  596. video_cc_mvs0_clk_src.clkr.vdd_data.rate_max[VDD_LOW] = 1014000000;
  597. video_cc_mvs0_clk_src.clkr.vdd_data.rate_max[VDD_LOW_L1] = 1098000000;
  598. video_cc_mvs0_clk_src.clkr.vdd_data.rate_max[VDD_NOMINAL] = 1332000000;
  599. video_cc_mvs0_shift_clk.halt_reg = 0x8144;
  600. video_cc_mvs0_shift_clk.hwcg_reg = 0x8144;
  601. video_cc_mvs0_shift_clk.clkr.enable_reg = 0x8144;
  602. video_cc_mvs0c_shift_clk.halt_reg = 0x8148;
  603. video_cc_mvs0c_shift_clk.hwcg_reg = 0x8148;
  604. video_cc_mvs0c_shift_clk.clkr.enable_reg = 0x8148;
  605. video_cc_mvs1_shift_clk.halt_reg = 0x814c;
  606. video_cc_mvs1_shift_clk.hwcg_reg = 0x814c;
  607. video_cc_mvs1_shift_clk.clkr.enable_reg = 0x814c;
  608. video_cc_mvs1c_shift_clk.halt_reg = 0x8150;
  609. video_cc_mvs1c_shift_clk.hwcg_reg = 0x8150;
  610. video_cc_mvs1c_shift_clk.clkr.enable_reg = 0x8150;
  611. video_cc_sleep_clk_src.cmd_rcgr = 0x8128;
  612. }
  613. static int video_cc_pineapple_fixup(struct platform_device *pdev, struct regmap *regmap)
  614. {
  615. const char *compat = NULL;
  616. u32 offset = 0x8150;
  617. int compatlen = 0;
  618. compat = of_get_property(pdev->dev.of_node, "compatible", &compatlen);
  619. if (!compat || compatlen <= 0)
  620. return -EINVAL;
  621. if (!strcmp(compat, "qcom,pineapple-videocc-v2"))
  622. video_cc_pineapple_fixup_pineapplev2(regmap);
  623. else if (!strcmp(compat, "qcom,cliffs-videocc")) {
  624. video_cc_pineapple_fixup_cliffs(regmap);
  625. offset = 0x8140;
  626. }
  627. /*
  628. * Keep clocks always enabled:
  629. * video_cc_ahb_clk
  630. * video_cc_xo_clk
  631. * video_cc_sleep_clk
  632. */
  633. regmap_update_bits(regmap, 0x80f4, BIT(0), BIT(0));
  634. regmap_update_bits(regmap, 0x8124, BIT(0), BIT(0));
  635. regmap_update_bits(regmap, offset, BIT(0), BIT(0));
  636. return 0;
  637. }
  638. static int video_cc_pineapple_probe(struct platform_device *pdev)
  639. {
  640. struct regmap *regmap;
  641. int ret;
  642. regmap = qcom_cc_map(pdev, &video_cc_pineapple_desc);
  643. if (IS_ERR(regmap))
  644. return PTR_ERR(regmap);
  645. ret = qcom_cc_runtime_init(pdev, &video_cc_pineapple_desc);
  646. if (ret)
  647. return ret;
  648. ret = pm_runtime_get_sync(&pdev->dev);
  649. if (ret)
  650. return ret;
  651. clk_lucid_ole_pll_configure(&video_cc_pll0, regmap, &video_cc_pll0_config);
  652. clk_lucid_ole_pll_configure(&video_cc_pll1, regmap, &video_cc_pll1_config);
  653. ret = video_cc_pineapple_fixup(pdev, regmap);
  654. if (ret)
  655. return ret;
  656. ret = qcom_cc_really_probe(pdev, &video_cc_pineapple_desc, regmap);
  657. if (ret) {
  658. dev_err(&pdev->dev, "Failed to register VIDEO CC clocks\n");
  659. return ret;
  660. }
  661. pm_runtime_put_sync(&pdev->dev);
  662. dev_info(&pdev->dev, "Registered VIDEO CC clocks\n");
  663. return ret;
  664. }
  665. static void video_cc_pineapple_sync_state(struct device *dev)
  666. {
  667. qcom_cc_sync_state(dev, &video_cc_pineapple_desc);
  668. }
  669. static const struct dev_pm_ops video_cc_pineapple_pm_ops = {
  670. SET_RUNTIME_PM_OPS(qcom_cc_runtime_suspend, qcom_cc_runtime_resume, NULL)
  671. SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
  672. pm_runtime_force_resume)
  673. };
  674. static struct platform_driver video_cc_pineapple_driver = {
  675. .probe = video_cc_pineapple_probe,
  676. .driver = {
  677. .name = "video_cc-pineapple",
  678. .of_match_table = video_cc_pineapple_match_table,
  679. .sync_state = video_cc_pineapple_sync_state,
  680. .pm = &video_cc_pineapple_pm_ops,
  681. },
  682. };
  683. static int __init video_cc_pineapple_init(void)
  684. {
  685. return platform_driver_register(&video_cc_pineapple_driver);
  686. }
  687. subsys_initcall(video_cc_pineapple_init);
  688. static void __exit video_cc_pineapple_exit(void)
  689. {
  690. platform_driver_unregister(&video_cc_pineapple_driver);
  691. }
  692. module_exit(video_cc_pineapple_exit);
  693. MODULE_DESCRIPTION("QTI VIDEO_CC PINEAPPLE Driver");
  694. MODULE_LICENSE("GPL");