blob: 3b5b73b7c3beed44068419cd3e3d1c300e365ec1 [file] [log] [blame]
Neil Armstrong3bed4222018-07-24 17:45:28 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Amlogic Meson Video Processing Unit driver
4 *
5 * Copyright (c) 2018 BayLibre, SAS.
6 * Author: Neil Armstrong <narmstrong@baylibre.com>
7 */
8
Simon Glassb9dea622019-10-27 09:54:03 -06009#include <common.h>
10#include <dm.h>
Neil Armstrong3bed4222018-07-24 17:45:28 +020011#include <edid.h>
12#include "meson_vpu.h"
Simon Glassf7ae49f2020-05-10 11:40:05 -060013#include <log.h>
Neil Armstrong3bed4222018-07-24 17:45:28 +020014#include <linux/iopoll.h>
15#include <linux/math64.h>
16
17#define writel_bits(mask, val, addr) \
18 writel((readl(addr) & ~(mask)) | (val), addr)
19
20enum {
21 MESON_VCLK_TARGET_CVBS = 0,
22 MESON_VCLK_TARGET_HDMI = 1,
23 MESON_VCLK_TARGET_DMT = 2,
24};
25
26/* HHI Registers */
27#define HHI_VID_PLL_CLK_DIV 0x1a0 /* 0x68 offset in data sheet */
28#define VID_PLL_EN BIT(19)
29#define VID_PLL_BYPASS BIT(18)
30#define VID_PLL_PRESET BIT(15)
31#define HHI_VIID_CLK_DIV 0x128 /* 0x4a offset in data sheet */
32#define VCLK2_DIV_MASK 0xff
33#define VCLK2_DIV_EN BIT(16)
34#define VCLK2_DIV_RESET BIT(17)
35#define CTS_VDAC_SEL_MASK (0xf << 28)
36#define CTS_VDAC_SEL_SHIFT 28
37#define HHI_VIID_CLK_CNTL 0x12c /* 0x4b offset in data sheet */
38#define VCLK2_EN BIT(19)
39#define VCLK2_SEL_MASK (0x7 << 16)
40#define VCLK2_SEL_SHIFT 16
41#define VCLK2_SOFT_RESET BIT(15)
42#define VCLK2_DIV1_EN BIT(0)
43#define HHI_VID_CLK_DIV 0x164 /* 0x59 offset in data sheet */
44#define VCLK_DIV_MASK 0xff
45#define VCLK_DIV_EN BIT(16)
46#define VCLK_DIV_RESET BIT(17)
47#define CTS_ENCP_SEL_MASK (0xf << 24)
48#define CTS_ENCP_SEL_SHIFT 24
49#define CTS_ENCI_SEL_MASK (0xf << 28)
50#define CTS_ENCI_SEL_SHIFT 28
51#define HHI_VID_CLK_CNTL 0x17c /* 0x5f offset in data sheet */
52#define VCLK_EN BIT(19)
53#define VCLK_SEL_MASK (0x7 << 16)
54#define VCLK_SEL_SHIFT 16
55#define VCLK_SOFT_RESET BIT(15)
56#define VCLK_DIV1_EN BIT(0)
57#define VCLK_DIV2_EN BIT(1)
58#define VCLK_DIV4_EN BIT(2)
59#define VCLK_DIV6_EN BIT(3)
60#define VCLK_DIV12_EN BIT(4)
61#define HHI_VID_CLK_CNTL2 0x194 /* 0x65 offset in data sheet */
62#define CTS_ENCI_EN BIT(0)
63#define CTS_ENCP_EN BIT(2)
64#define CTS_VDAC_EN BIT(4)
65#define HDMI_TX_PIXEL_EN BIT(5)
66#define HHI_HDMI_CLK_CNTL 0x1cc /* 0x73 offset in data sheet */
67#define HDMI_TX_PIXEL_SEL_MASK (0xf << 16)
68#define HDMI_TX_PIXEL_SEL_SHIFT 16
69#define CTS_HDMI_SYS_SEL_MASK (0x7 << 9)
70#define CTS_HDMI_SYS_DIV_MASK (0x7f)
71#define CTS_HDMI_SYS_EN BIT(8)
72
73#define HHI_HDMI_PLL_CNTL 0x320 /* 0xc8 offset in data sheet */
Neil Armstrong573687c2019-08-30 14:09:24 +020074#define HHI_HDMI_PLL_CNTL_EN BIT(30)
Neil Armstrong3bed4222018-07-24 17:45:28 +020075#define HHI_HDMI_PLL_CNTL2 0x324 /* 0xc9 offset in data sheet */
76#define HHI_HDMI_PLL_CNTL3 0x328 /* 0xca offset in data sheet */
77#define HHI_HDMI_PLL_CNTL4 0x32C /* 0xcb offset in data sheet */
78#define HHI_HDMI_PLL_CNTL5 0x330 /* 0xcc offset in data sheet */
79#define HHI_HDMI_PLL_CNTL6 0x334 /* 0xcd offset in data sheet */
Neil Armstrong573687c2019-08-30 14:09:24 +020080#define HHI_HDMI_PLL_CNTL7 0x338 /* 0xce offset in data sheet */
Neil Armstrong3bed4222018-07-24 17:45:28 +020081
82#define HDMI_PLL_RESET BIT(28)
Neil Armstrong573687c2019-08-30 14:09:24 +020083#define HDMI_PLL_RESET_G12A BIT(29)
Neil Armstrong3bed4222018-07-24 17:45:28 +020084#define HDMI_PLL_LOCK BIT(31)
Neil Armstrong573687c2019-08-30 14:09:24 +020085#define HDMI_PLL_LOCK_G12A (3 << 30)
86
87#define FREQ_1000_1001(_freq) DIV_ROUND_CLOSEST(_freq * 1000, 1001)
Neil Armstrong3bed4222018-07-24 17:45:28 +020088
89/* VID PLL Dividers */
90enum {
91 VID_PLL_DIV_1 = 0,
92 VID_PLL_DIV_2,
93 VID_PLL_DIV_2p5,
94 VID_PLL_DIV_3,
95 VID_PLL_DIV_3p5,
96 VID_PLL_DIV_3p75,
97 VID_PLL_DIV_4,
98 VID_PLL_DIV_5,
99 VID_PLL_DIV_6,
100 VID_PLL_DIV_6p25,
101 VID_PLL_DIV_7,
102 VID_PLL_DIV_7p5,
103 VID_PLL_DIV_12,
104 VID_PLL_DIV_14,
105 VID_PLL_DIV_15,
106};
107
108void meson_vid_pll_set(struct meson_vpu_priv *priv, unsigned int div)
109{
110 unsigned int shift_val = 0;
111 unsigned int shift_sel = 0;
112
113 /* Disable vid_pll output clock */
114 hhi_update_bits(HHI_VID_PLL_CLK_DIV, VID_PLL_EN, 0);
115 hhi_update_bits(HHI_VID_PLL_CLK_DIV, VID_PLL_PRESET, 0);
116
117 switch (div) {
118 case VID_PLL_DIV_2:
119 shift_val = 0x0aaa;
120 shift_sel = 0;
121 break;
122 case VID_PLL_DIV_2p5:
123 shift_val = 0x5294;
124 shift_sel = 2;
125 break;
126 case VID_PLL_DIV_3:
127 shift_val = 0x0db6;
128 shift_sel = 0;
129 break;
130 case VID_PLL_DIV_3p5:
131 shift_val = 0x36cc;
132 shift_sel = 1;
133 break;
134 case VID_PLL_DIV_3p75:
135 shift_val = 0x6666;
136 shift_sel = 2;
137 break;
138 case VID_PLL_DIV_4:
139 shift_val = 0x0ccc;
140 shift_sel = 0;
141 break;
142 case VID_PLL_DIV_5:
143 shift_val = 0x739c;
144 shift_sel = 2;
145 break;
146 case VID_PLL_DIV_6:
147 shift_val = 0x0e38;
148 shift_sel = 0;
149 break;
150 case VID_PLL_DIV_6p25:
151 shift_val = 0x0000;
152 shift_sel = 3;
153 break;
154 case VID_PLL_DIV_7:
155 shift_val = 0x3c78;
156 shift_sel = 1;
157 break;
158 case VID_PLL_DIV_7p5:
159 shift_val = 0x78f0;
160 shift_sel = 2;
161 break;
162 case VID_PLL_DIV_12:
163 shift_val = 0x0fc0;
164 shift_sel = 0;
165 break;
166 case VID_PLL_DIV_14:
167 shift_val = 0x3f80;
168 shift_sel = 1;
169 break;
170 case VID_PLL_DIV_15:
171 shift_val = 0x7f80;
172 shift_sel = 2;
173 break;
174 }
175
176 if (div == VID_PLL_DIV_1) {
177 /* Enable vid_pll bypass to HDMI pll */
178 hhi_update_bits(HHI_VID_PLL_CLK_DIV,
179 VID_PLL_BYPASS, VID_PLL_BYPASS);
180 } else {
181 /* Disable Bypass */
182 hhi_update_bits(HHI_VID_PLL_CLK_DIV,
183 VID_PLL_BYPASS, 0);
184 /* Clear sel */
185 hhi_update_bits(HHI_VID_PLL_CLK_DIV,
186 3 << 16, 0);
187 hhi_update_bits(HHI_VID_PLL_CLK_DIV,
188 VID_PLL_PRESET, 0);
189 hhi_update_bits(HHI_VID_PLL_CLK_DIV,
190 0x7fff, 0);
191
192 /* Setup sel and val */
193 hhi_update_bits(HHI_VID_PLL_CLK_DIV,
194 3 << 16, shift_sel << 16);
195 hhi_update_bits(HHI_VID_PLL_CLK_DIV,
196 VID_PLL_PRESET, VID_PLL_PRESET);
197 hhi_update_bits(HHI_VID_PLL_CLK_DIV,
198 0x7fff, shift_val);
199
200 hhi_update_bits(HHI_VID_PLL_CLK_DIV,
201 VID_PLL_PRESET, 0);
202 }
203
204 /* Enable the vid_pll output clock */
205 hhi_update_bits(HHI_VID_PLL_CLK_DIV,
206 VID_PLL_EN, VID_PLL_EN);
207}
208
209/*
210 * Setup VCLK2 for 27MHz, and enable clocks for ENCI and VDAC
211 *
212 * TOFIX: Refactor into table to also handle HDMI frequency and paths
213 */
214static void meson_venci_cvbs_clock_config(struct meson_vpu_priv *priv)
215{
216 unsigned int val;
217
Neil Armstrong3bed4222018-07-24 17:45:28 +0200218 /* Setup PLL to output 1.485GHz */
219 if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXBB)) {
220 hhi_write(HHI_HDMI_PLL_CNTL, 0x5800023d);
221 hhi_write(HHI_HDMI_PLL_CNTL2, 0x00404e00);
222 hhi_write(HHI_HDMI_PLL_CNTL3, 0x0d5c5091);
223 hhi_write(HHI_HDMI_PLL_CNTL4, 0x801da72c);
224 hhi_write(HHI_HDMI_PLL_CNTL5, 0x71486980);
225 hhi_write(HHI_HDMI_PLL_CNTL6, 0x00000e55);
226 hhi_write(HHI_HDMI_PLL_CNTL, 0x4800023d);
Neil Armstrong573687c2019-08-30 14:09:24 +0200227
228 /* Poll for lock bit */
229 readl_poll_timeout(priv->hhi_base + HHI_HDMI_PLL_CNTL, val,
230 (val & HDMI_PLL_LOCK), 10);
Neil Armstrong3bed4222018-07-24 17:45:28 +0200231 } else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) ||
232 meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXL)) {
233 hhi_write(HHI_HDMI_PLL_CNTL, 0x4000027b);
234 hhi_write(HHI_HDMI_PLL_CNTL2, 0x800cb300);
235 hhi_write(HHI_HDMI_PLL_CNTL3, 0xa6212844);
236 hhi_write(HHI_HDMI_PLL_CNTL4, 0x0c4d000c);
237 hhi_write(HHI_HDMI_PLL_CNTL5, 0x001fa729);
238 hhi_write(HHI_HDMI_PLL_CNTL6, 0x01a31500);
239
240 /* Reset PLL */
241 hhi_update_bits(HHI_HDMI_PLL_CNTL,
242 HDMI_PLL_RESET, HDMI_PLL_RESET);
243 hhi_update_bits(HHI_HDMI_PLL_CNTL,
244 HDMI_PLL_RESET, 0);
Neil Armstrong573687c2019-08-30 14:09:24 +0200245
246 /* Poll for lock bit */
247 readl_poll_timeout(priv->hhi_base + HHI_HDMI_PLL_CNTL, val,
248 (val & HDMI_PLL_LOCK), 10);
249 } else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
250 hhi_write(HHI_HDMI_PLL_CNTL, 0x1a0504f7);
251 hhi_write(HHI_HDMI_PLL_CNTL2, 0x00010000);
252 hhi_write(HHI_HDMI_PLL_CNTL3, 0x00000000);
253 hhi_write(HHI_HDMI_PLL_CNTL4, 0x6a28dc00);
254 hhi_write(HHI_HDMI_PLL_CNTL5, 0x65771290);
255 hhi_write(HHI_HDMI_PLL_CNTL6, 0x39272000);
256 hhi_write(HHI_HDMI_PLL_CNTL7, 0x56540000);
257 hhi_write(HHI_HDMI_PLL_CNTL, 0x3a0504f7);
258 hhi_write(HHI_HDMI_PLL_CNTL, 0x1a0504f7);
259
260 /* Poll for lock bit */
261 readl_poll_timeout(priv->hhi_base + HHI_HDMI_PLL_CNTL, val,
262 ((val & HDMI_PLL_LOCK_G12A) == HDMI_PLL_LOCK_G12A),
263 10);
Neil Armstrong3bed4222018-07-24 17:45:28 +0200264 }
265
Neil Armstrong3bed4222018-07-24 17:45:28 +0200266 /* Disable VCLK2 */
267 hhi_update_bits(HHI_VIID_CLK_CNTL, VCLK2_EN, 0);
268
269 /* Setup vid_pll to /1 */
270 meson_vid_pll_set(priv, VID_PLL_DIV_1);
271
272 /* Setup the VCLK2 divider value to achieve 27MHz */
273 hhi_update_bits(HHI_VIID_CLK_DIV,
274 VCLK2_DIV_MASK, (55 - 1));
275
276 /* select vid_pll for vclk2 */
Neil Armstrong573687c2019-08-30 14:09:24 +0200277 if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
278 hhi_update_bits(HHI_VIID_CLK_CNTL,
279 VCLK2_SEL_MASK, (0 << VCLK2_SEL_SHIFT));
280 else
281 hhi_update_bits(HHI_VIID_CLK_CNTL,
282 VCLK2_SEL_MASK, (4 << VCLK2_SEL_SHIFT));
283
Neil Armstrong3bed4222018-07-24 17:45:28 +0200284 /* enable vclk2 gate */
285 hhi_update_bits(HHI_VIID_CLK_CNTL, VCLK2_EN, VCLK2_EN);
286
287 /* select vclk_div1 for enci */
288 hhi_update_bits(HHI_VID_CLK_DIV,
289 CTS_ENCI_SEL_MASK, (8 << CTS_ENCI_SEL_SHIFT));
290 /* select vclk_div1 for vdac */
291 hhi_update_bits(HHI_VIID_CLK_DIV,
292 CTS_VDAC_SEL_MASK, (8 << CTS_VDAC_SEL_SHIFT));
293
294 /* release vclk2_div_reset and enable vclk2_div */
295 hhi_update_bits(HHI_VIID_CLK_DIV,
296 VCLK2_DIV_EN | VCLK2_DIV_RESET, VCLK2_DIV_EN);
297
298 /* enable vclk2_div1 gate */
299 hhi_update_bits(HHI_VIID_CLK_CNTL,
300 VCLK2_DIV1_EN, VCLK2_DIV1_EN);
301
302 /* reset vclk2 */
303 hhi_update_bits(HHI_VIID_CLK_CNTL,
304 VCLK2_SOFT_RESET, VCLK2_SOFT_RESET);
305 hhi_update_bits(HHI_VIID_CLK_CNTL,
306 VCLK2_SOFT_RESET, 0);
307
308 /* enable enci_clk */
309 hhi_update_bits(HHI_VID_CLK_CNTL2,
310 CTS_ENCI_EN, CTS_ENCI_EN);
311 /* enable vdac_clk */
312 hhi_update_bits(HHI_VID_CLK_CNTL2,
313 CTS_VDAC_EN, CTS_VDAC_EN);
Neil Armstrong3bed4222018-07-24 17:45:28 +0200314}
315
316enum {
317/* PLL O1 O2 O3 VP DV EN TX */
318/* 4320 /4 /4 /1 /5 /1 => /2 /2 */
Neil Armstrong573687c2019-08-30 14:09:24 +0200319 MESON_VCLK_HDMI_ENCI_54000 = 0,
Neil Armstrong3bed4222018-07-24 17:45:28 +0200320/* 4320 /4 /4 /1 /5 /1 => /1 /2 */
321 MESON_VCLK_HDMI_DDR_54000,
322/* 2970 /4 /1 /1 /5 /1 => /1 /2 */
323 MESON_VCLK_HDMI_DDR_148500,
324/* 2970 /2 /2 /2 /5 /1 => /1 /1 */
325 MESON_VCLK_HDMI_74250,
326/* 2970 /1 /2 /2 /5 /1 => /1 /1 */
327 MESON_VCLK_HDMI_148500,
328/* 2970 /1 /1 /1 /5 /2 => /1 /1 */
329 MESON_VCLK_HDMI_297000,
330/* 5940 /1 /1 /2 /5 /1 => /1 /1 */
331 MESON_VCLK_HDMI_594000
332};
333
334struct meson_vclk_params {
Neil Armstrong573687c2019-08-30 14:09:24 +0200335 unsigned int pixel_freq;
Neil Armstrong3bed4222018-07-24 17:45:28 +0200336 unsigned int pll_base_freq;
337 unsigned int pll_od1;
338 unsigned int pll_od2;
339 unsigned int pll_od3;
340 unsigned int vid_pll_div;
341 unsigned int vclk_div;
342} params[] = {
343 [MESON_VCLK_HDMI_ENCI_54000] = {
Neil Armstrong573687c2019-08-30 14:09:24 +0200344 .pixel_freq = 54000,
Neil Armstrong3bed4222018-07-24 17:45:28 +0200345 .pll_base_freq = 4320000,
346 .pll_od1 = 4,
347 .pll_od2 = 4,
348 .pll_od3 = 1,
349 .vid_pll_div = VID_PLL_DIV_5,
350 .vclk_div = 1,
351 },
352 [MESON_VCLK_HDMI_DDR_54000] = {
Neil Armstrong573687c2019-08-30 14:09:24 +0200353 .pixel_freq = 54000,
Neil Armstrong3bed4222018-07-24 17:45:28 +0200354 .pll_base_freq = 4320000,
355 .pll_od1 = 4,
356 .pll_od2 = 4,
357 .pll_od3 = 1,
358 .vid_pll_div = VID_PLL_DIV_5,
359 .vclk_div = 1,
360 },
361 [MESON_VCLK_HDMI_DDR_148500] = {
Neil Armstrong573687c2019-08-30 14:09:24 +0200362 .pixel_freq = 148500,
Neil Armstrong3bed4222018-07-24 17:45:28 +0200363 .pll_base_freq = 2970000,
364 .pll_od1 = 4,
365 .pll_od2 = 1,
366 .pll_od3 = 1,
367 .vid_pll_div = VID_PLL_DIV_5,
368 .vclk_div = 1,
369 },
370 [MESON_VCLK_HDMI_74250] = {
Neil Armstrong573687c2019-08-30 14:09:24 +0200371 .pixel_freq = 74250,
Neil Armstrong3bed4222018-07-24 17:45:28 +0200372 .pll_base_freq = 2970000,
373 .pll_od1 = 2,
374 .pll_od2 = 2,
375 .pll_od3 = 2,
376 .vid_pll_div = VID_PLL_DIV_5,
377 .vclk_div = 1,
378 },
379 [MESON_VCLK_HDMI_148500] = {
Neil Armstrong573687c2019-08-30 14:09:24 +0200380 .pixel_freq = 148500,
Neil Armstrong3bed4222018-07-24 17:45:28 +0200381 .pll_base_freq = 2970000,
382 .pll_od1 = 1,
383 .pll_od2 = 2,
384 .pll_od3 = 2,
385 .vid_pll_div = VID_PLL_DIV_5,
386 .vclk_div = 1,
387 },
388 [MESON_VCLK_HDMI_297000] = {
Neil Armstrong573687c2019-08-30 14:09:24 +0200389 .pixel_freq = 297000,
390 .pll_base_freq = 5940000,
391 .pll_od1 = 2,
Neil Armstrong3bed4222018-07-24 17:45:28 +0200392 .pll_od2 = 1,
393 .pll_od3 = 1,
394 .vid_pll_div = VID_PLL_DIV_5,
395 .vclk_div = 2,
396 },
397 [MESON_VCLK_HDMI_594000] = {
Neil Armstrong573687c2019-08-30 14:09:24 +0200398 .pixel_freq = 594000,
Neil Armstrong3bed4222018-07-24 17:45:28 +0200399 .pll_base_freq = 5940000,
400 .pll_od1 = 1,
401 .pll_od2 = 1,
402 .pll_od3 = 2,
403 .vid_pll_div = VID_PLL_DIV_5,
404 .vclk_div = 1,
405 },
Neil Armstrong573687c2019-08-30 14:09:24 +0200406 { /* sentinel */ },
Neil Armstrong3bed4222018-07-24 17:45:28 +0200407};
408
409static inline unsigned int pll_od_to_reg(unsigned int od)
410{
411 switch (od) {
412 case 1:
413 return 0;
414 case 2:
415 return 1;
416 case 4:
417 return 2;
418 case 8:
419 return 3;
420 }
421
422 /* Invalid */
423 return 0;
424}
425
426void meson_hdmi_pll_set_params(struct meson_vpu_priv *priv, unsigned int m,
427 unsigned int frac, unsigned int od1,
428 unsigned int od2, unsigned int od3)
429{
430 unsigned int val;
431
432 if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXBB)) {
433 hhi_write(HHI_HDMI_PLL_CNTL, 0x58000200 | m);
434 if (frac)
435 hhi_write(HHI_HDMI_PLL_CNTL2,
436 0x00004000 | frac);
437 else
438 hhi_write(HHI_HDMI_PLL_CNTL2,
439 0x00000000);
440 hhi_write(HHI_HDMI_PLL_CNTL3, 0x0d5c5091);
441 hhi_write(HHI_HDMI_PLL_CNTL4, 0x801da72c);
442 hhi_write(HHI_HDMI_PLL_CNTL5, 0x71486980);
443 hhi_write(HHI_HDMI_PLL_CNTL6, 0x00000e55);
444
445 /* Enable and unreset */
446 hhi_update_bits(HHI_HDMI_PLL_CNTL,
447 0x7 << 28, 0x4 << 28);
448
449 /* Poll for lock bit */
450 readl_poll_timeout(priv->hhi_base + HHI_HDMI_PLL_CNTL, val,
451 (val & HDMI_PLL_LOCK), 10);
452 } else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) ||
453 meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXL)) {
454 hhi_write(HHI_HDMI_PLL_CNTL, 0x40000200 | m);
455 hhi_write(HHI_HDMI_PLL_CNTL2, 0x800cb000 | frac);
456 hhi_write(HHI_HDMI_PLL_CNTL3, 0x860f30c4);
457 hhi_write(HHI_HDMI_PLL_CNTL4, 0x0c8e0000);
458 hhi_write(HHI_HDMI_PLL_CNTL5, 0x001fa729);
459 hhi_write(HHI_HDMI_PLL_CNTL6, 0x01a31500);
460
461 /* Reset PLL */
462 hhi_update_bits(HHI_HDMI_PLL_CNTL,
463 HDMI_PLL_RESET, HDMI_PLL_RESET);
464 hhi_update_bits(HHI_HDMI_PLL_CNTL,
465 HDMI_PLL_RESET, 0);
466
467 /* Poll for lock bit */
468 readl_poll_timeout(priv->hhi_base + HHI_HDMI_PLL_CNTL, val,
469 (val & HDMI_PLL_LOCK), 10);
Neil Armstrong573687c2019-08-30 14:09:24 +0200470 } else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
471 hhi_write(HHI_HDMI_PLL_CNTL, 0x0b3a0400 | m);
472
473 /* Enable and reset */
474 hhi_update_bits(HHI_HDMI_PLL_CNTL, 0x3 << 28, 0x3 << 28);
475
476 hhi_write(HHI_HDMI_PLL_CNTL2, frac);
477 hhi_write(HHI_HDMI_PLL_CNTL3, 0x00000000);
478
479 /* G12A HDMI PLL Needs specific parameters for 5.4GHz */
480 if (m >= 0xf7) {
481 if (frac < 0x10000) {
482 hhi_write(HHI_HDMI_PLL_CNTL4, 0x6a685c00);
483 hhi_write(HHI_HDMI_PLL_CNTL5, 0x11551293);
484 } else {
485 hhi_write(HHI_HDMI_PLL_CNTL4, 0xea68dc00);
486 hhi_write(HHI_HDMI_PLL_CNTL5, 0x65771290);
487 }
488 hhi_write(HHI_HDMI_PLL_CNTL6, 0x39272000);
489 hhi_write(HHI_HDMI_PLL_CNTL7, 0x55540000);
490 } else {
491 hhi_write(HHI_HDMI_PLL_CNTL4, 0x0a691c00);
492 hhi_write(HHI_HDMI_PLL_CNTL5, 0x33771290);
493 hhi_write(HHI_HDMI_PLL_CNTL6, 0x39270000);
494 hhi_write(HHI_HDMI_PLL_CNTL7, 0x50540000);
495 }
496
497 do {
498 /* Reset PLL */
499 hhi_update_bits(HHI_HDMI_PLL_CNTL,
500 HDMI_PLL_RESET_G12A,
501 HDMI_PLL_RESET_G12A);
502
503 /* UN-Reset PLL */
504 hhi_update_bits(HHI_HDMI_PLL_CNTL,
505 HDMI_PLL_RESET_G12A, 0);
506
507 /* Poll for lock bits */
508 if (!readl_poll_timeout(
509 priv->hhi_base + HHI_HDMI_PLL_CNTL, val,
510 ((val & HDMI_PLL_LOCK_G12A)
511 == HDMI_PLL_LOCK_G12A), 100))
512 break;
513 } while (1);
Neil Armstrong3bed4222018-07-24 17:45:28 +0200514 }
515
516 if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXBB))
517 hhi_update_bits(HHI_HDMI_PLL_CNTL2,
518 3 << 16, pll_od_to_reg(od1) << 16);
519 else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) ||
520 meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXL))
521 hhi_update_bits(HHI_HDMI_PLL_CNTL3,
522 3 << 21, pll_od_to_reg(od1) << 21);
Neil Armstrong573687c2019-08-30 14:09:24 +0200523 else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
524 hhi_update_bits(HHI_HDMI_PLL_CNTL,
525 3 << 16, pll_od_to_reg(od1) << 16);
Neil Armstrong3bed4222018-07-24 17:45:28 +0200526
527 if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXBB))
528 hhi_update_bits(HHI_HDMI_PLL_CNTL2,
529 3 << 22, pll_od_to_reg(od2) << 22);
530 else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) ||
531 meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXL))
532 hhi_update_bits(HHI_HDMI_PLL_CNTL3,
533 3 << 23, pll_od_to_reg(od2) << 23);
Neil Armstrong573687c2019-08-30 14:09:24 +0200534 else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
535 hhi_update_bits(HHI_HDMI_PLL_CNTL,
536 3 << 18, pll_od_to_reg(od2) << 18);
Neil Armstrong3bed4222018-07-24 17:45:28 +0200537
538 if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXBB))
539 hhi_update_bits(HHI_HDMI_PLL_CNTL2,
540 3 << 18, pll_od_to_reg(od3) << 18);
541 else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) ||
542 meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXL))
543 hhi_update_bits(HHI_HDMI_PLL_CNTL3,
544 3 << 19, pll_od_to_reg(od3) << 19);
Neil Armstrong573687c2019-08-30 14:09:24 +0200545 else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
546 hhi_update_bits(HHI_HDMI_PLL_CNTL,
547 3 << 20, pll_od_to_reg(od3) << 20);
Neil Armstrong3bed4222018-07-24 17:45:28 +0200548}
549
550#define XTAL_FREQ 24000
551
552static unsigned int meson_hdmi_pll_get_m(struct meson_vpu_priv *priv,
553 unsigned int pll_freq)
554{
555 /* The GXBB PLL has a /2 pre-multiplier */
556 if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXBB))
557 pll_freq /= 2;
558
559 return pll_freq / XTAL_FREQ;
560}
561
562#define HDMI_FRAC_MAX_GXBB 4096
563#define HDMI_FRAC_MAX_GXL 1024
Neil Armstrong573687c2019-08-30 14:09:24 +0200564#define HDMI_FRAC_MAX_G12A 131072
Neil Armstrong3bed4222018-07-24 17:45:28 +0200565
566static unsigned int meson_hdmi_pll_get_frac(struct meson_vpu_priv *priv,
567 unsigned int m,
568 unsigned int pll_freq)
569{
570 unsigned int parent_freq = XTAL_FREQ;
571 unsigned int frac_max = HDMI_FRAC_MAX_GXL;
572 unsigned int frac_m;
573 unsigned int frac;
574
575 /* The GXBB PLL has a /2 pre-multiplier and a larger FRAC width */
576 if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXBB)) {
577 frac_max = HDMI_FRAC_MAX_GXBB;
578 parent_freq *= 2;
579 }
580
Neil Armstrong573687c2019-08-30 14:09:24 +0200581 if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
582 frac_max = HDMI_FRAC_MAX_G12A;
583
Neil Armstrong3bed4222018-07-24 17:45:28 +0200584 /* We can have a perfect match !*/
585 if (pll_freq / m == parent_freq &&
586 pll_freq % m == 0)
587 return 0;
588
589 frac = div_u64((u64)pll_freq * (u64)frac_max, parent_freq);
590 frac_m = m * frac_max;
591 if (frac_m > frac)
592 return frac_max;
593 frac -= frac_m;
594
595 return min((u16)frac, (u16)(frac_max - 1));
596}
597
598static bool meson_hdmi_pll_validate_params(struct meson_vpu_priv *priv,
599 unsigned int m,
600 unsigned int frac)
601{
602 if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXBB)) {
603 /* Empiric supported min/max dividers */
604 if (m < 53 || m > 123)
605 return false;
606 if (frac >= HDMI_FRAC_MAX_GXBB)
607 return false;
608 } else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) ||
609 meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXL)) {
610 /* Empiric supported min/max dividers */
611 if (m < 106 || m > 247)
612 return false;
613 if (frac >= HDMI_FRAC_MAX_GXL)
614 return false;
Neil Armstrong573687c2019-08-30 14:09:24 +0200615 } else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
616 /* Empiric supported min/max dividers */
617 if (m < 106 || m > 247)
618 return false;
619 if (frac >= HDMI_FRAC_MAX_G12A)
620 return false;
Neil Armstrong3bed4222018-07-24 17:45:28 +0200621 }
622
623 return true;
624}
625
626static bool meson_hdmi_pll_find_params(struct meson_vpu_priv *priv,
627 unsigned int freq,
628 unsigned int *m,
629 unsigned int *frac,
630 unsigned int *od)
631{
632 /* Cycle from /16 to /2 */
633 for (*od = 16 ; *od > 1 ; *od >>= 1) {
634 *m = meson_hdmi_pll_get_m(priv, freq * *od);
635 if (!*m)
636 continue;
637 *frac = meson_hdmi_pll_get_frac(priv, *m, freq * *od);
638
639 debug("PLL params for %dkHz: m=%x frac=%x od=%d\n",
640 freq, *m, *frac, *od);
641
642 if (meson_hdmi_pll_validate_params(priv, *m, *frac))
643 return true;
644 }
645
646 return false;
647}
648
649/* pll_freq is the frequency after the OD dividers */
650bool meson_vclk_dmt_supported_freq(struct meson_vpu_priv *priv,
651 unsigned int freq)
652{
653 unsigned int od, m, frac;
654
655 /* In DMT mode, path after PLL is always /10 */
656 freq *= 10;
657
658 if (meson_hdmi_pll_find_params(priv, freq, &m, &frac, &od))
659 return true;
660
661 return false;
662}
663
664/* pll_freq is the frequency after the OD dividers */
665static void meson_hdmi_pll_generic_set(struct meson_vpu_priv *priv,
666 unsigned int pll_freq)
667{
668 unsigned int od, m, frac, od1, od2, od3;
669
670 if (meson_hdmi_pll_find_params(priv, pll_freq, &m, &frac, &od)) {
671 od3 = 1;
672 if (od < 4) {
673 od1 = 2;
674 od2 = 1;
675 } else {
676 od2 = od / 4;
677 od1 = od / od2;
678 }
679
680 debug("PLL params for %dkHz: m=%x frac=%x od=%d/%d/%d\n",
681 pll_freq, m, frac, od1, od2, od3);
682
683 meson_hdmi_pll_set_params(priv, m, frac, od1, od2, od3);
684
685 return;
686 }
687
688 printf("Fatal, unable to find parameters for PLL freq %d\n",
689 pll_freq);
690}
691
692static void
693meson_vclk_set(struct meson_vpu_priv *priv, unsigned int pll_base_freq,
694 unsigned int od1, unsigned int od2, unsigned int od3,
695 unsigned int vid_pll_div, unsigned int vclk_div,
696 unsigned int hdmi_tx_div, unsigned int venc_div,
Neil Armstrong573687c2019-08-30 14:09:24 +0200697 bool hdmi_use_enci, bool vic_alternate_clock)
Neil Armstrong3bed4222018-07-24 17:45:28 +0200698{
Neil Armstrong573687c2019-08-30 14:09:24 +0200699 unsigned int m = 0, frac = 0;
700
Neil Armstrong3bed4222018-07-24 17:45:28 +0200701 /* Set HDMI-TX sys clock */
702 hhi_update_bits(HHI_HDMI_CLK_CNTL,
703 CTS_HDMI_SYS_SEL_MASK, 0);
704 hhi_update_bits(HHI_HDMI_CLK_CNTL,
705 CTS_HDMI_SYS_DIV_MASK, 0);
706 hhi_update_bits(HHI_HDMI_CLK_CNTL,
707 CTS_HDMI_SYS_EN, CTS_HDMI_SYS_EN);
708
709 /* Set HDMI PLL rate */
710 if (!od1 && !od2 && !od3) {
711 meson_hdmi_pll_generic_set(priv, pll_base_freq);
712 } else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXBB)) {
713 switch (pll_base_freq) {
714 case 2970000:
Neil Armstrong573687c2019-08-30 14:09:24 +0200715 m = 0x3d;
716 frac = vic_alternate_clock ? 0xd02 : 0xe00;
Neil Armstrong3bed4222018-07-24 17:45:28 +0200717 break;
718 case 4320000:
Neil Armstrong573687c2019-08-30 14:09:24 +0200719 m = vic_alternate_clock ? 0x59 : 0x5a;
720 frac = vic_alternate_clock ? 0xe8f : 0;
Neil Armstrong3bed4222018-07-24 17:45:28 +0200721 break;
722 case 5940000:
Neil Armstrong573687c2019-08-30 14:09:24 +0200723 m = 0x7b;
724 frac = vic_alternate_clock ? 0xa05 : 0xc00;
Neil Armstrong3bed4222018-07-24 17:45:28 +0200725 break;
726 }
Neil Armstrong573687c2019-08-30 14:09:24 +0200727
728 meson_hdmi_pll_set_params(priv, m, frac, od1, od2, od3);
Neil Armstrong3bed4222018-07-24 17:45:28 +0200729 } else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) ||
730 meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXL)) {
731 switch (pll_base_freq) {
732 case 2970000:
Neil Armstrong573687c2019-08-30 14:09:24 +0200733 m = 0x7b;
734 frac = vic_alternate_clock ? 0x281 : 0x300;
Neil Armstrong3bed4222018-07-24 17:45:28 +0200735 break;
736 case 4320000:
Neil Armstrong573687c2019-08-30 14:09:24 +0200737 m = vic_alternate_clock ? 0xb3 : 0xb4;
738 frac = vic_alternate_clock ? 0x347 : 0;
Neil Armstrong3bed4222018-07-24 17:45:28 +0200739 break;
740 case 5940000:
Neil Armstrong573687c2019-08-30 14:09:24 +0200741 m = 0xf7;
742 frac = vic_alternate_clock ? 0x102 : 0x200;
Neil Armstrong3bed4222018-07-24 17:45:28 +0200743 break;
744 }
Neil Armstrong573687c2019-08-30 14:09:24 +0200745
746 meson_hdmi_pll_set_params(priv, m, frac, od1, od2, od3);
747 } else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
748 switch (pll_base_freq) {
749 case 2970000:
750 m = 0x7b;
751 frac = vic_alternate_clock ? 0x140b4 : 0x18000;
752 break;
753 case 4320000:
754 m = vic_alternate_clock ? 0xb3 : 0xb4;
755 frac = vic_alternate_clock ? 0x1a3ee : 0;
756 break;
757 case 5940000:
758 m = 0xf7;
759 frac = vic_alternate_clock ? 0x8148 : 0x10000;
760 break;
761 }
762
763 meson_hdmi_pll_set_params(priv, m, frac, od1, od2, od3);
Neil Armstrong3bed4222018-07-24 17:45:28 +0200764 }
765
766 /* Setup vid_pll divider */
767 meson_vid_pll_set(priv, vid_pll_div);
768
769 /* Set VCLK div */
770 hhi_update_bits(HHI_VID_CLK_CNTL,
771 VCLK_SEL_MASK, 0);
772 hhi_update_bits(HHI_VID_CLK_DIV,
773 VCLK_DIV_MASK, vclk_div - 1);
774
775 /* Set HDMI-TX source */
776 switch (hdmi_tx_div) {
777 case 1:
778 /* enable vclk_div1 gate */
779 hhi_update_bits(HHI_VID_CLK_CNTL,
780 VCLK_DIV1_EN, VCLK_DIV1_EN);
781
782 /* select vclk_div1 for HDMI-TX */
783 hhi_update_bits(HHI_HDMI_CLK_CNTL,
784 HDMI_TX_PIXEL_SEL_MASK, 0);
785 break;
786 case 2:
787 /* enable vclk_div2 gate */
788 hhi_update_bits(HHI_VID_CLK_CNTL,
789 VCLK_DIV2_EN, VCLK_DIV2_EN);
790
791 /* select vclk_div2 for HDMI-TX */
792 hhi_update_bits(HHI_HDMI_CLK_CNTL,
793 HDMI_TX_PIXEL_SEL_MASK,
794 1 << HDMI_TX_PIXEL_SEL_SHIFT);
795 break;
796 case 4:
797 /* enable vclk_div4 gate */
798 hhi_update_bits(HHI_VID_CLK_CNTL,
799 VCLK_DIV4_EN, VCLK_DIV4_EN);
800
801 /* select vclk_div4 for HDMI-TX */
802 hhi_update_bits(HHI_HDMI_CLK_CNTL,
803 HDMI_TX_PIXEL_SEL_MASK,
804 2 << HDMI_TX_PIXEL_SEL_SHIFT);
805 break;
806 case 6:
807 /* enable vclk_div6 gate */
808 hhi_update_bits(HHI_VID_CLK_CNTL,
809 VCLK_DIV6_EN, VCLK_DIV6_EN);
810
811 /* select vclk_div6 for HDMI-TX */
812 hhi_update_bits(HHI_HDMI_CLK_CNTL,
813 HDMI_TX_PIXEL_SEL_MASK,
814 3 << HDMI_TX_PIXEL_SEL_SHIFT);
815 break;
816 case 12:
817 /* enable vclk_div12 gate */
818 hhi_update_bits(HHI_VID_CLK_CNTL,
819 VCLK_DIV12_EN, VCLK_DIV12_EN);
820
821 /* select vclk_div12 for HDMI-TX */
822 hhi_update_bits(HHI_HDMI_CLK_CNTL,
823 HDMI_TX_PIXEL_SEL_MASK,
824 4 << HDMI_TX_PIXEL_SEL_SHIFT);
825 break;
826 }
827 hhi_update_bits(HHI_VID_CLK_CNTL2,
828 HDMI_TX_PIXEL_EN, HDMI_TX_PIXEL_EN);
829
830 /* Set ENCI/ENCP Source */
831 switch (venc_div) {
832 case 1:
833 /* enable vclk_div1 gate */
834 hhi_update_bits(HHI_VID_CLK_CNTL,
835 VCLK_DIV1_EN, VCLK_DIV1_EN);
836
837 if (hdmi_use_enci)
838 /* select vclk_div1 for enci */
839 hhi_update_bits(HHI_VID_CLK_DIV,
840 CTS_ENCI_SEL_MASK, 0);
841 else
842 /* select vclk_div1 for encp */
843 hhi_update_bits(HHI_VID_CLK_DIV,
844 CTS_ENCP_SEL_MASK, 0);
845 break;
846 case 2:
847 /* enable vclk_div2 gate */
848 hhi_update_bits(HHI_VID_CLK_CNTL,
849 VCLK_DIV2_EN, VCLK_DIV2_EN);
850
851 if (hdmi_use_enci)
852 /* select vclk_div2 for enci */
853 hhi_update_bits(HHI_VID_CLK_DIV,
854 CTS_ENCI_SEL_MASK,
855 1 << CTS_ENCI_SEL_SHIFT);
856 else
857 /* select vclk_div2 for encp */
858 hhi_update_bits(HHI_VID_CLK_DIV,
859 CTS_ENCP_SEL_MASK,
860 1 << CTS_ENCP_SEL_SHIFT);
861 break;
862 case 4:
863 /* enable vclk_div4 gate */
864 hhi_update_bits(HHI_VID_CLK_CNTL,
865 VCLK_DIV4_EN, VCLK_DIV4_EN);
866
867 if (hdmi_use_enci)
868 /* select vclk_div4 for enci */
869 hhi_update_bits(HHI_VID_CLK_DIV,
870 CTS_ENCI_SEL_MASK,
871 2 << CTS_ENCI_SEL_SHIFT);
872 else
873 /* select vclk_div4 for encp */
874 hhi_update_bits(HHI_VID_CLK_DIV,
875 CTS_ENCP_SEL_MASK,
876 2 << CTS_ENCP_SEL_SHIFT);
877 break;
878 case 6:
879 /* enable vclk_div6 gate */
880 hhi_update_bits(HHI_VID_CLK_CNTL,
881 VCLK_DIV6_EN, VCLK_DIV6_EN);
882
883 if (hdmi_use_enci)
884 /* select vclk_div6 for enci */
885 hhi_update_bits(HHI_VID_CLK_DIV,
886 CTS_ENCI_SEL_MASK,
887 3 << CTS_ENCI_SEL_SHIFT);
888 else
889 /* select vclk_div6 for encp */
890 hhi_update_bits(HHI_VID_CLK_DIV,
891 CTS_ENCP_SEL_MASK,
892 3 << CTS_ENCP_SEL_SHIFT);
893 break;
894 case 12:
895 /* enable vclk_div12 gate */
896 hhi_update_bits(HHI_VID_CLK_CNTL,
897 VCLK_DIV12_EN, VCLK_DIV12_EN);
898
899 if (hdmi_use_enci)
900 /* select vclk_div12 for enci */
901 hhi_update_bits(HHI_VID_CLK_DIV,
902 CTS_ENCI_SEL_MASK,
903 4 << CTS_ENCI_SEL_SHIFT);
904 else
905 /* select vclk_div12 for encp */
906 hhi_update_bits(HHI_VID_CLK_DIV,
907 CTS_ENCP_SEL_MASK,
908 4 << CTS_ENCP_SEL_SHIFT);
909 break;
910 }
911
912 if (hdmi_use_enci)
913 /* Enable ENCI clock gate */
914 hhi_update_bits(HHI_VID_CLK_CNTL2,
915 CTS_ENCI_EN, CTS_ENCI_EN);
916 else
917 /* Enable ENCP clock gate */
918 hhi_update_bits(HHI_VID_CLK_CNTL2,
919 CTS_ENCP_EN, CTS_ENCP_EN);
920
921 hhi_update_bits(HHI_VID_CLK_CNTL, VCLK_EN, VCLK_EN);
922}
923
924static void meson_vclk_setup(struct meson_vpu_priv *priv, unsigned int target,
925 unsigned int vclk_freq, unsigned int venc_freq,
926 unsigned int dac_freq, bool hdmi_use_enci)
927{
Neil Armstrong573687c2019-08-30 14:09:24 +0200928 bool vic_alternate_clock = false;
Neil Armstrong3bed4222018-07-24 17:45:28 +0200929 unsigned int freq;
930 unsigned int hdmi_tx_div;
931 unsigned int venc_div;
932
933 if (target == MESON_VCLK_TARGET_CVBS) {
934 meson_venci_cvbs_clock_config(priv);
935 return;
936 } else if (target == MESON_VCLK_TARGET_DMT) {
937 /* The DMT clock path is fixed after the PLL:
938 * - automatic PLL freq + OD management
939 * - vid_pll_div = VID_PLL_DIV_5
940 * - vclk_div = 2
941 * - hdmi_tx_div = 1
942 * - venc_div = 1
943 * - encp encoder
944 */
945 meson_vclk_set(priv, vclk_freq * 10, 0, 0, 0,
Neil Armstrong573687c2019-08-30 14:09:24 +0200946 VID_PLL_DIV_5, 2, 1, 1, false, false);
Neil Armstrong3bed4222018-07-24 17:45:28 +0200947 return;
948 }
949
950 hdmi_tx_div = vclk_freq / dac_freq;
951
952 if (hdmi_tx_div == 0) {
953 printf("Fatal Error, invalid HDMI-TX freq %d\n",
954 dac_freq);
955 return;
956 }
957
958 venc_div = vclk_freq / venc_freq;
959
960 if (venc_div == 0) {
961 printf("Fatal Error, invalid HDMI venc freq %d\n",
962 venc_freq);
963 return;
964 }
965
Neil Armstrong573687c2019-08-30 14:09:24 +0200966 for (freq = 0 ; params[freq].pixel_freq ; ++freq) {
967 if (vclk_freq == params[freq].pixel_freq ||
968 vclk_freq == FREQ_1000_1001(params[freq].pixel_freq)) {
969 if (vclk_freq != params[freq].pixel_freq)
970 vic_alternate_clock = true;
971 else
972 vic_alternate_clock = false;
973
974 if (freq == MESON_VCLK_HDMI_ENCI_54000 &&
975 !hdmi_use_enci)
976 continue;
977
978 if (freq == MESON_VCLK_HDMI_DDR_54000 &&
979 hdmi_use_enci)
980 continue;
981
982 if (freq == MESON_VCLK_HDMI_DDR_148500 &&
983 dac_freq == vclk_freq)
984 continue;
985
986 if (freq == MESON_VCLK_HDMI_148500 &&
987 dac_freq != vclk_freq)
988 continue;
989 break;
990 }
991 }
992
993 if (!params[freq].pixel_freq) {
994 pr_err("Fatal Error, invalid HDMI vclk freq %d\n", vclk_freq);
Neil Armstrong3bed4222018-07-24 17:45:28 +0200995 return;
996 }
997
998 meson_vclk_set(priv, params[freq].pll_base_freq,
999 params[freq].pll_od1, params[freq].pll_od2,
1000 params[freq].pll_od3, params[freq].vid_pll_div,
1001 params[freq].vclk_div, hdmi_tx_div, venc_div,
Neil Armstrong573687c2019-08-30 14:09:24 +02001002 hdmi_use_enci, vic_alternate_clock);
Neil Armstrong3bed4222018-07-24 17:45:28 +02001003}
1004
1005void meson_vpu_setup_vclk(struct udevice *dev,
1006 const struct display_timing *mode, bool is_cvbs)
1007{
1008 struct meson_vpu_priv *priv = dev_get_priv(dev);
1009 unsigned int vclk_freq;
1010
1011 if (is_cvbs)
1012 return meson_vclk_setup(priv, MESON_VCLK_TARGET_CVBS,
1013 0, 0, 0, false);
1014
1015 vclk_freq = mode->pixelclock.typ / 1000;
1016
1017 return meson_vclk_setup(priv, MESON_VCLK_TARGET_DMT,
1018 vclk_freq, vclk_freq, vclk_freq, false);
1019}