2 * Copyright (C) 2016 BayLibre, SAS
4 * Copyright (C) 2015 Amlogic, Inc. All rights reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include <linux/kernel.h>
21 #include <linux/module.h>
23 #include "meson_drv.h"
24 #include "meson_vclk.h"
29 * VCLK is the "Pixel Clock" frequency generator from a dedicated PLL.
30 * We handle the following encodings :
32 * - CVBS 27MHz generator via the VCLK2 to the VENCI and VDAC blocks
33 * - HDMI Pixel Clocks generation
37 * - Genenate Pixel clocks for 2K/4K 10bit formats
39 * Clock generator scheme :
43 * __________ _________ _____
45 * | HDMI PLL |-| PLL_DIV |--- VCLK--| |--ENCL
46 * |__________| |_________| \ | MUX |--ENCP
50 * Final clocks can take input for either VCLK or VCLK2, but
51 * VCLK is the preferred path for HDMI clocking and VCLK2 is the
52 * preferred path for CVBS VDAC clocking.
54 * VCLK and VCLK2 have fixed divided clocks paths for /1, /2, /4, /6 or /12.
56 * The PLL_DIV can achieve an additional fractional dividing like
57 * 1.5, 3.5, 3.75... to generate special 2K and 4K 10bit clocks.
61 #define HHI_VID_PLL_CLK_DIV 0x1a0 /* 0x68 offset in data sheet */
62 #define VID_PLL_EN BIT(19)
63 #define VID_PLL_BYPASS BIT(18)
64 #define VID_PLL_PRESET BIT(15)
65 #define HHI_VIID_CLK_DIV 0x128 /* 0x4a offset in data sheet */
66 #define VCLK2_DIV_MASK 0xff
67 #define VCLK2_DIV_EN BIT(16)
68 #define VCLK2_DIV_RESET BIT(17)
69 #define CTS_VDAC_SEL_MASK (0xf << 28)
70 #define CTS_VDAC_SEL_SHIFT 28
71 #define HHI_VIID_CLK_CNTL 0x12c /* 0x4b offset in data sheet */
72 #define VCLK2_EN BIT(19)
73 #define VCLK2_SEL_MASK (0x7 << 16)
74 #define VCLK2_SEL_SHIFT 16
75 #define VCLK2_SOFT_RESET BIT(15)
76 #define VCLK2_DIV1_EN BIT(0)
77 #define HHI_VID_CLK_DIV 0x164 /* 0x59 offset in data sheet */
78 #define VCLK_DIV_MASK 0xff
79 #define VCLK_DIV_EN BIT(16)
80 #define VCLK_DIV_RESET BIT(17)
81 #define CTS_ENCP_SEL_MASK (0xf << 24)
82 #define CTS_ENCP_SEL_SHIFT 24
83 #define CTS_ENCI_SEL_MASK (0xf << 28)
84 #define CTS_ENCI_SEL_SHIFT 28
85 #define HHI_VID_CLK_CNTL 0x17c /* 0x5f offset in data sheet */
86 #define VCLK_EN BIT(19)
87 #define VCLK_SEL_MASK (0x7 << 16)
88 #define VCLK_SEL_SHIFT 16
89 #define VCLK_SOFT_RESET BIT(15)
90 #define VCLK_DIV1_EN BIT(0)
91 #define VCLK_DIV2_EN BIT(1)
92 #define VCLK_DIV4_EN BIT(2)
93 #define VCLK_DIV6_EN BIT(3)
94 #define VCLK_DIV12_EN BIT(4)
95 #define HHI_VID_CLK_CNTL2 0x194 /* 0x65 offset in data sheet */
96 #define CTS_ENCI_EN BIT(0)
97 #define CTS_ENCP_EN BIT(2)
98 #define CTS_VDAC_EN BIT(4)
99 #define HDMI_TX_PIXEL_EN BIT(5)
100 #define HHI_HDMI_CLK_CNTL 0x1cc /* 0x73 offset in data sheet */
101 #define HDMI_TX_PIXEL_SEL_MASK (0xf << 16)
102 #define HDMI_TX_PIXEL_SEL_SHIFT 16
103 #define CTS_HDMI_SYS_SEL_MASK (0x7 << 9)
104 #define CTS_HDMI_SYS_DIV_MASK (0x7f)
105 #define CTS_HDMI_SYS_EN BIT(8)
107 #define HHI_VDAC_CNTL0 0x2F4 /* 0xbd offset in data sheet */
108 #define HHI_VDAC_CNTL1 0x2F8 /* 0xbe offset in data sheet */
110 #define HHI_HDMI_PLL_CNTL 0x320 /* 0xc8 offset in data sheet */
111 #define HHI_HDMI_PLL_CNTL2 0x324 /* 0xc9 offset in data sheet */
112 #define HHI_HDMI_PLL_CNTL3 0x328 /* 0xca offset in data sheet */
113 #define HHI_HDMI_PLL_CNTL4 0x32C /* 0xcb offset in data sheet */
114 #define HHI_HDMI_PLL_CNTL5 0x330 /* 0xcc offset in data sheet */
115 #define HHI_HDMI_PLL_CNTL6 0x334 /* 0xcd offset in data sheet */
117 #define HDMI_PLL_RESET BIT(28)
118 #define HDMI_PLL_LOCK BIT(31)
120 /* VID PLL Dividers */
139 void meson_vid_pll_set(struct meson_drm *priv, unsigned int div)
141 unsigned int shift_val = 0;
142 unsigned int shift_sel = 0;
144 /* Disable vid_pll output clock */
145 regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV, VID_PLL_EN, 0);
146 regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV, VID_PLL_PRESET, 0);
153 case VID_PLL_DIV_2p5:
161 case VID_PLL_DIV_3p5:
165 case VID_PLL_DIV_3p75:
181 case VID_PLL_DIV_6p25:
189 case VID_PLL_DIV_7p5:
207 if (div == VID_PLL_DIV_1)
208 /* Enable vid_pll bypass to HDMI pll */
209 regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV,
210 VID_PLL_BYPASS, VID_PLL_BYPASS);
213 regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV,
216 regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV,
218 regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV,
220 regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV,
223 /* Setup sel and val */
224 regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV,
225 3 << 16, shift_sel << 16);
226 regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV,
227 VID_PLL_PRESET, VID_PLL_PRESET);
228 regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV,
231 regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV,
235 /* Enable the vid_pll output clock */
236 regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV,
237 VID_PLL_EN, VID_PLL_EN);
241 * Setup VCLK2 for 27MHz, and enable clocks for ENCI and VDAC
243 * TOFIX: Refactor into table to also handle HDMI frequency and paths
245 static void meson_venci_cvbs_clock_config(struct meson_drm *priv)
249 /* Setup PLL to output 1.485GHz */
250 if (meson_vpu_is_compatible(priv, "amlogic,meson-gxbb-vpu")) {
251 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x5800023d);
252 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x00404e00);
253 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x0d5c5091);
254 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x801da72c);
255 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x71486980);
256 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x00000e55);
257 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x4800023d);
258 } else if (meson_vpu_is_compatible(priv, "amlogic,meson-gxm-vpu") ||
259 meson_vpu_is_compatible(priv, "amlogic,meson-gxl-vpu")) {
260 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x4000027b);
261 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x800cb300);
262 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0xa6212844);
263 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x0c4d000c);
264 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x001fa729);
265 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x01a31500);
268 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL,
269 HDMI_PLL_RESET, HDMI_PLL_RESET);
270 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL,
274 /* Poll for lock bit */
275 regmap_read_poll_timeout(priv->hhi, HHI_HDMI_PLL_CNTL, val,
276 (val & HDMI_PLL_LOCK), 10, 0);
279 regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL, VCLK2_EN, 0);
281 /* Setup vid_pll to /1 */
282 meson_vid_pll_set(priv, VID_PLL_DIV_1);
284 /* Setup the VCLK2 divider value to achieve 27MHz */
285 regmap_update_bits(priv->hhi, HHI_VIID_CLK_DIV,
286 VCLK2_DIV_MASK, (55 - 1));
288 /* select vid_pll for vclk2 */
289 regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL,
290 VCLK2_SEL_MASK, (4 << VCLK2_SEL_SHIFT));
291 /* enable vclk2 gate */
292 regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL, VCLK2_EN, VCLK2_EN);
294 /* select vclk_div1 for enci */
295 regmap_update_bits(priv->hhi, HHI_VID_CLK_DIV,
296 CTS_ENCI_SEL_MASK, (8 << CTS_ENCI_SEL_SHIFT));
297 /* select vclk_div1 for vdac */
298 regmap_update_bits(priv->hhi, HHI_VIID_CLK_DIV,
299 CTS_VDAC_SEL_MASK, (8 << CTS_VDAC_SEL_SHIFT));
301 /* release vclk2_div_reset and enable vclk2_div */
302 regmap_update_bits(priv->hhi, HHI_VIID_CLK_DIV,
303 VCLK2_DIV_EN | VCLK2_DIV_RESET, VCLK2_DIV_EN);
305 /* enable vclk2_div1 gate */
306 regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL,
307 VCLK2_DIV1_EN, VCLK2_DIV1_EN);
310 regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL,
311 VCLK2_SOFT_RESET, VCLK2_SOFT_RESET);
312 regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL,
313 VCLK2_SOFT_RESET, 0);
315 /* enable enci_clk */
316 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL2,
317 CTS_ENCI_EN, CTS_ENCI_EN);
318 /* enable vdac_clk */
319 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL2,
320 CTS_VDAC_EN, CTS_VDAC_EN);
324 /* PLL O1 O2 O3 VP DV EN TX */
325 /* 4320 /4 /4 /1 /5 /1 => /2 /2 */
326 #define MESON_VCLK_HDMI_ENCI_54000 1
327 /* 4320 /4 /4 /1 /5 /1 => /1 /2 */
328 #define MESON_VCLK_HDMI_DDR_54000 2
329 /* 2970 /4 /1 /1 /5 /1 => /1 /2 */
330 #define MESON_VCLK_HDMI_DDR_148500 3
331 /* 4028 /4 /4 /1 /5 /2 => /1 /1 */
332 #define MESON_VCLK_HDMI_25175 4
333 /* 3200 /4 /2 /1 /5 /2 => /1 /1 */
334 #define MESON_VCLK_HDMI_40000 5
335 /* 5200 /4 /2 /1 /5 /2 => /1 /1 */
336 #define MESON_VCLK_HDMI_65000 6
337 /* 2970 /2 /2 /2 /5 /1 => /1 /1 */
338 #define MESON_VCLK_HDMI_74250 7
339 /* 4320 /4 /1 /1 /5 /2 => /1 /1 */
340 #define MESON_VCLK_HDMI_108000 8
341 /* 2970 /1 /2 /2 /5 /1 => /1 /1 */
342 #define MESON_VCLK_HDMI_148500 9
343 /* 3240 /2 /1 /1 /5 /2 => /1 /1 */
344 #define MESON_VCLK_HDMI_162000 10
345 /* 2970 /1 /1 /1 /5 /2 => /1 /1 */
346 #define MESON_VCLK_HDMI_297000 11
347 /* 5940 /1 /1 /2 /5 /1 => /1 /1 */
348 #define MESON_VCLK_HDMI_594000 12
350 struct meson_vclk_params {
351 unsigned int pll_base_freq;
352 unsigned int pll_od1;
353 unsigned int pll_od2;
354 unsigned int pll_od3;
355 unsigned int vid_pll_div;
356 unsigned int vclk_div;
358 [MESON_VCLK_HDMI_ENCI_54000] = {
359 .pll_base_freq = 4320000,
363 .vid_pll_div = VID_PLL_DIV_5,
366 [MESON_VCLK_HDMI_DDR_54000] = {
367 .pll_base_freq = 4320000,
371 .vid_pll_div = VID_PLL_DIV_5,
374 [MESON_VCLK_HDMI_DDR_148500] = {
375 .pll_base_freq = 2970000,
379 .vid_pll_div = VID_PLL_DIV_5,
382 [MESON_VCLK_HDMI_74250] = {
383 .pll_base_freq = 2970000,
387 .vid_pll_div = VID_PLL_DIV_5,
390 [MESON_VCLK_HDMI_148500] = {
391 .pll_base_freq = 2970000,
395 .vid_pll_div = VID_PLL_DIV_5,
398 [MESON_VCLK_HDMI_297000] = {
399 .pll_base_freq = 2970000,
403 .vid_pll_div = VID_PLL_DIV_5,
406 [MESON_VCLK_HDMI_594000] = {
407 .pll_base_freq = 5940000,
411 .vid_pll_div = VID_PLL_DIV_5,
414 [MESON_VCLK_HDMI_25175] = {
415 .pll_base_freq = 4028000,
419 .vid_pll_div = VID_PLL_DIV_5,
422 [MESON_VCLK_HDMI_40000] = {
423 .pll_base_freq = 3200000,
427 .vid_pll_div = VID_PLL_DIV_5,
430 [MESON_VCLK_HDMI_65000] = {
431 .pll_base_freq = 5200000,
435 .vid_pll_div = VID_PLL_DIV_5,
438 [MESON_VCLK_HDMI_108000] = {
439 .pll_base_freq = 4320000,
443 .vid_pll_div = VID_PLL_DIV_5,
446 [MESON_VCLK_HDMI_162000] = {
447 .pll_base_freq = 3240000,
451 .vid_pll_div = VID_PLL_DIV_5,
456 static inline unsigned int pll_od_to_reg(unsigned int od)
473 void meson_hdmi_pll_set(struct meson_drm *priv,
481 if (meson_vpu_is_compatible(priv, "amlogic,meson-gxbb-vpu")) {
484 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x5800023d);
485 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x00000000);
486 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x0d5c5091);
487 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x801da72c);
488 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x71486980);
489 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x00000e55);
491 /* Enable and unreset */
492 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL,
493 0x7 << 28, 0x4 << 28);
495 /* Poll for lock bit */
496 regmap_read_poll_timeout(priv->hhi, HHI_HDMI_PLL_CNTL,
497 val, (val & HDMI_PLL_LOCK), 10, 0);
500 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL2,
505 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x58000242);
506 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x00000000);
507 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x0d5c5091);
508 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x801da72c);
509 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x71486980);
510 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x00000e55);
513 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL,
516 /* Poll for lock bit */
517 regmap_read_poll_timeout(priv->hhi, HHI_HDMI_PLL_CNTL,
518 val, (val & HDMI_PLL_LOCK), 10, 0);
521 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL2,
526 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x58000243);
527 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x00000000);
528 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x0d5c5091);
529 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x801da72c);
530 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x71486980);
531 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x00000e55);
534 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL,
537 /* Poll for lock bit */
538 regmap_read_poll_timeout(priv->hhi, HHI_HDMI_PLL_CNTL,
539 val, (val & HDMI_PLL_LOCK), 10, 0);
542 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL2,
547 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x58000250);
548 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x00000000);
549 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x0d5c5091);
550 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x801da72c);
551 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x71486980);
552 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x00000e55);
555 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL,
558 /* Poll for lock bit */
559 regmap_read_poll_timeout(priv->hhi, HHI_HDMI_PLL_CNTL,
560 val, (val & HDMI_PLL_LOCK), 10, 0);
563 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL2,
568 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x58000253);
569 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x00000000);
570 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x0d5c5091);
571 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x801da72c);
572 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x71486980);
573 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x00000e55);
576 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL,
579 /* Poll for lock bit */
580 regmap_read_poll_timeout(priv->hhi, HHI_HDMI_PLL_CNTL,
581 val, (val & HDMI_PLL_LOCK), 10, 0);
584 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL2,
589 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x5800025a);
590 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x00000000);
591 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x0d5c5091);
592 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x801da72c);
593 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x71486980);
594 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x00000e55);
597 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL,
600 /* Poll for lock bit */
601 regmap_read_poll_timeout(priv->hhi, HHI_HDMI_PLL_CNTL,
602 val, (val & HDMI_PLL_LOCK), 10, 0);
606 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x5800027b);
607 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL2,
609 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x135c5091);
610 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x801da72c);
611 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x71486980);
612 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x00000e55);
615 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL,
618 /* Poll for lock bit */
619 regmap_read_poll_timeout(priv->hhi, HHI_HDMI_PLL_CNTL,
620 val, (val & HDMI_PLL_LOCK), 10, 0);
624 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x5800026c);
625 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x00000000);
626 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x135c5091);
627 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x801da72c);
628 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x71486980);
629 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x00000e55);
632 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL,
635 /* Poll for lock bit */
636 regmap_read_poll_timeout(priv->hhi, HHI_HDMI_PLL_CNTL,
637 val, (val & HDMI_PLL_LOCK), 10, 0);
640 } else if (meson_vpu_is_compatible(priv, "amlogic,meson-gxm-vpu") ||
641 meson_vpu_is_compatible(priv, "amlogic,meson-gxl-vpu")) {
644 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x4000027b);
645 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x800cb300);
646 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x860f30c4);
647 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x0c8e0000);
648 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x001fa729);
649 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x01a31500);
653 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x40000285);
654 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x800cb155);
655 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x860f30c4);
656 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x0c8e0000);
657 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x001fa729);
658 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x01a31500);
662 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x40000287);
663 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x800cb000);
664 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x860f30c4);
665 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x0c8e0000);
666 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x001fa729);
667 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x01a31500);
671 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x400002a1);
672 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x800cb02b);
673 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x860f30c4);
674 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x0c8e0000);
675 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x001fa729);
676 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x01a31500);
680 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x400002a7);
681 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x800cb355);
682 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x860f30c4);
683 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x0c8e0000);
684 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x001fa729);
685 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x01a31500);
689 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x400002b4);
690 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x800cb000);
691 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x860f30c4);
692 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x0c8e0000);
693 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x001fa729);
694 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x01a31500);
698 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x400002f7);
699 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x800cb200);
700 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x860f30c4);
701 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x0c8e0000);
702 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x001fa729);
703 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x01a31500);
707 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x400002d8);
708 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x800cb2ab);
709 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x860f30c4);
710 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x0c8e0000);
711 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x001fa729);
712 regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x01a31500);
718 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL,
719 HDMI_PLL_RESET, HDMI_PLL_RESET);
720 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL,
723 /* Poll for lock bit */
724 regmap_read_poll_timeout(priv->hhi, HHI_HDMI_PLL_CNTL, val,
725 (val & HDMI_PLL_LOCK), 10, 0);
728 if (meson_vpu_is_compatible(priv, "amlogic,meson-gxbb-vpu"))
729 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL2,
730 3 << 16, pll_od_to_reg(od1) << 16);
731 else if (meson_vpu_is_compatible(priv, "amlogic,meson-gxm-vpu") ||
732 meson_vpu_is_compatible(priv, "amlogic,meson-gxl-vpu"))
733 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL3,
734 3 << 21, pll_od_to_reg(od1) << 21);
736 if (meson_vpu_is_compatible(priv, "amlogic,meson-gxbb-vpu"))
737 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL2,
738 3 << 22, pll_od_to_reg(od2) << 22);
739 else if (meson_vpu_is_compatible(priv, "amlogic,meson-gxm-vpu") ||
740 meson_vpu_is_compatible(priv, "amlogic,meson-gxl-vpu"))
741 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL3,
742 3 << 23, pll_od_to_reg(od2) << 23);
744 if (meson_vpu_is_compatible(priv, "amlogic,meson-gxbb-vpu"))
745 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL2,
746 3 << 18, pll_od_to_reg(od3) << 18);
747 else if (meson_vpu_is_compatible(priv, "amlogic,meson-gxm-vpu") ||
748 meson_vpu_is_compatible(priv, "amlogic,meson-gxl-vpu"))
749 regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL3,
750 3 << 19, pll_od_to_reg(od3) << 19);
753 void meson_vclk_setup(struct meson_drm *priv, unsigned int target,
754 unsigned int vclk_freq, unsigned int venc_freq,
755 unsigned int dac_freq, bool hdmi_use_enci)
758 unsigned int hdmi_tx_div;
759 unsigned int venc_div;
761 if (target == MESON_VCLK_TARGET_CVBS) {
762 meson_venci_cvbs_clock_config(priv);
766 hdmi_tx_div = vclk_freq / dac_freq;
768 if (hdmi_tx_div == 0) {
769 pr_err("Fatal Error, invalid HDMI-TX freq %d\n",
774 venc_div = vclk_freq / venc_freq;
777 pr_err("Fatal Error, invalid HDMI venc freq %d\n",
785 freq = MESON_VCLK_HDMI_ENCI_54000;
787 freq = MESON_VCLK_HDMI_DDR_54000;
790 freq = MESON_VCLK_HDMI_25175;
793 freq = MESON_VCLK_HDMI_40000;
796 freq = MESON_VCLK_HDMI_65000;
799 freq = MESON_VCLK_HDMI_74250;
802 freq = MESON_VCLK_HDMI_108000;
805 if (dac_freq != 148500)
806 freq = MESON_VCLK_HDMI_DDR_148500;
808 freq = MESON_VCLK_HDMI_148500;
811 freq = MESON_VCLK_HDMI_162000;
814 freq = MESON_VCLK_HDMI_297000;
817 freq = MESON_VCLK_HDMI_594000;
820 pr_err("Fatal Error, invalid HDMI vclk freq %d\n",
825 /* Set HDMI-TX sys clock */
826 regmap_update_bits(priv->hhi, HHI_HDMI_CLK_CNTL,
827 CTS_HDMI_SYS_SEL_MASK, 0);
828 regmap_update_bits(priv->hhi, HHI_HDMI_CLK_CNTL,
829 CTS_HDMI_SYS_DIV_MASK, 0);
830 regmap_update_bits(priv->hhi, HHI_HDMI_CLK_CNTL,
831 CTS_HDMI_SYS_EN, CTS_HDMI_SYS_EN);
833 /* Set HDMI PLL rate */
834 meson_hdmi_pll_set(priv, params[freq].pll_base_freq,
835 params[freq].pll_od1,
836 params[freq].pll_od2,
837 params[freq].pll_od3);
839 /* Setup vid_pll divider */
840 meson_vid_pll_set(priv, params[freq].vid_pll_div);
843 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL,
845 regmap_update_bits(priv->hhi, HHI_VID_CLK_DIV,
846 VCLK_DIV_MASK, params[freq].vclk_div - 1);
848 /* Set HDMI-TX source */
849 switch (hdmi_tx_div) {
851 /* enable vclk_div1 gate */
852 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL,
853 VCLK_DIV1_EN, VCLK_DIV1_EN);
855 /* select vclk_div1 for HDMI-TX */
856 regmap_update_bits(priv->hhi, HHI_HDMI_CLK_CNTL,
857 HDMI_TX_PIXEL_SEL_MASK, 0);
860 /* enable vclk_div2 gate */
861 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL,
862 VCLK_DIV2_EN, VCLK_DIV2_EN);
864 /* select vclk_div2 for HDMI-TX */
865 regmap_update_bits(priv->hhi, HHI_HDMI_CLK_CNTL,
866 HDMI_TX_PIXEL_SEL_MASK, 1 << HDMI_TX_PIXEL_SEL_SHIFT);
869 /* enable vclk_div4 gate */
870 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL,
871 VCLK_DIV4_EN, VCLK_DIV4_EN);
873 /* select vclk_div4 for HDMI-TX */
874 regmap_update_bits(priv->hhi, HHI_HDMI_CLK_CNTL,
875 HDMI_TX_PIXEL_SEL_MASK, 2 << HDMI_TX_PIXEL_SEL_SHIFT);
878 /* enable vclk_div6 gate */
879 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL,
880 VCLK_DIV6_EN, VCLK_DIV6_EN);
882 /* select vclk_div6 for HDMI-TX */
883 regmap_update_bits(priv->hhi, HHI_HDMI_CLK_CNTL,
884 HDMI_TX_PIXEL_SEL_MASK, 3 << HDMI_TX_PIXEL_SEL_SHIFT);
887 /* enable vclk_div12 gate */
888 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL,
889 VCLK_DIV12_EN, VCLK_DIV12_EN);
891 /* select vclk_div12 for HDMI-TX */
892 regmap_update_bits(priv->hhi, HHI_HDMI_CLK_CNTL,
893 HDMI_TX_PIXEL_SEL_MASK, 4 << HDMI_TX_PIXEL_SEL_SHIFT);
896 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL2,
897 HDMI_TX_PIXEL_EN, HDMI_TX_PIXEL_EN);
899 /* Set ENCI/ENCP Source */
902 /* enable vclk_div1 gate */
903 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL,
904 VCLK_DIV1_EN, VCLK_DIV1_EN);
907 /* select vclk_div1 for enci */
908 regmap_update_bits(priv->hhi, HHI_VID_CLK_DIV,
909 CTS_ENCI_SEL_MASK, 0);
911 /* select vclk_div1 for encp */
912 regmap_update_bits(priv->hhi, HHI_VID_CLK_DIV,
913 CTS_ENCP_SEL_MASK, 0);
916 /* enable vclk_div2 gate */
917 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL,
918 VCLK_DIV2_EN, VCLK_DIV2_EN);
921 /* select vclk_div2 for enci */
922 regmap_update_bits(priv->hhi, HHI_VID_CLK_DIV,
923 CTS_ENCI_SEL_MASK, 1 << CTS_ENCI_SEL_SHIFT);
925 /* select vclk_div2 for encp */
926 regmap_update_bits(priv->hhi, HHI_VID_CLK_DIV,
927 CTS_ENCP_SEL_MASK, 1 << CTS_ENCP_SEL_SHIFT);
930 /* enable vclk_div4 gate */
931 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL,
932 VCLK_DIV4_EN, VCLK_DIV4_EN);
935 /* select vclk_div4 for enci */
936 regmap_update_bits(priv->hhi, HHI_VID_CLK_DIV,
937 CTS_ENCI_SEL_MASK, 2 << CTS_ENCI_SEL_SHIFT);
939 /* select vclk_div4 for encp */
940 regmap_update_bits(priv->hhi, HHI_VID_CLK_DIV,
941 CTS_ENCP_SEL_MASK, 2 << CTS_ENCP_SEL_SHIFT);
944 /* enable vclk_div6 gate */
945 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL,
946 VCLK_DIV6_EN, VCLK_DIV6_EN);
949 /* select vclk_div6 for enci */
950 regmap_update_bits(priv->hhi, HHI_VID_CLK_DIV,
951 CTS_ENCI_SEL_MASK, 3 << CTS_ENCI_SEL_SHIFT);
953 /* select vclk_div6 for encp */
954 regmap_update_bits(priv->hhi, HHI_VID_CLK_DIV,
955 CTS_ENCP_SEL_MASK, 3 << CTS_ENCP_SEL_SHIFT);
958 /* enable vclk_div12 gate */
959 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL,
960 VCLK_DIV12_EN, VCLK_DIV12_EN);
963 /* select vclk_div12 for enci */
964 regmap_update_bits(priv->hhi, HHI_VID_CLK_DIV,
965 CTS_ENCI_SEL_MASK, 4 << CTS_ENCI_SEL_SHIFT);
967 /* select vclk_div12 for encp */
968 regmap_update_bits(priv->hhi, HHI_VID_CLK_DIV,
969 CTS_ENCP_SEL_MASK, 4 << CTS_ENCP_SEL_SHIFT);
974 /* Enable ENCI clock gate */
975 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL2,
976 CTS_ENCI_EN, CTS_ENCI_EN);
978 /* Enable ENCP clock gate */
979 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL2,
980 CTS_ENCP_EN, CTS_ENCP_EN);
982 regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL, VCLK_EN, VCLK_EN);
984 EXPORT_SYMBOL_GPL(meson_vclk_setup);