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_venc.h"
25 #include "meson_vpp.h"
26 #include "meson_vclk.h"
27 #include "meson_registers.h"
32 * VENC Handle the pixels encoding to the output formats.
33 * We handle the following encodings :
35 * - CVBS Encoding via the ENCI encoder and VDAC digital to analog converter
36 * - TMDS/HDMI Encoding via ENCI_DIV and ENCP
37 * - Setup of more clock rates for HDMI modes
41 * - LCD Panel encoding via ENCL
42 * - TV Panel encoding via ENCT
48 * _____ _____ ____________________
49 * vd1---| |-| | | VENC /---------|----VDAC
50 * vd2---| VIU |-| VPP |-|-----ENCI/-ENCI_DVI-|-|
51 * osd1--| |-| | | \ | X--HDMI-TX
52 * osd2--|_____|-|_____| | |\-ENCP--ENCP_DVI-|-|
54 * | \--ENCL-----------|----LVDS
55 * |____________________|
57 * The ENCI is designed for PAl or NTSC encoding and can go through the VDAC
58 * directly for CVBS encoding or through the ENCI_DVI encoder for HDMI.
59 * The ENCP is designed for Progressive encoding but can also generate
60 * 1080i interlaced pixels, and was initialy desined to encode pixels for
61 * VDAC to output RGB ou YUV analog outputs.
62 * It's output is only used through the ENCP_DVI encoder for HDMI.
63 * The ENCL LVDS encoder is not implemented.
65 * The ENCI and ENCP encoders needs specially defined parameters for each
66 * supported mode and thus cannot be determined from standard video timings.
68 * The ENCI end ENCP DVI encoders are more generic and can generate any timings
69 * from the pixel data generated by ENCI or ENCP, so can use the standard video
70 * timings are source for HW parameters.
74 #define HHI_GCLK_MPEG2 0x148 /* 0x52 offset in data sheet */
75 #define HHI_VDAC_CNTL0 0x2F4 /* 0xbd offset in data sheet */
76 #define HHI_VDAC_CNTL1 0x2F8 /* 0xbe offset in data sheet */
77 #define HHI_HDMI_PHY_CNTL0 0x3a0 /* 0xe8 offset in data sheet */
79 struct meson_cvbs_enci_mode meson_cvbs_enci_pal = {
80 .mode_tag = MESON_VENC_MODE_CVBS_PAL,
86 .video_prog_mode = 0xff,
92 .top_field_line_start = 22,
93 .top_field_line_end = 310,
94 .bottom_field_line_start = 23,
95 .bottom_field_line_end = 311,
96 .video_saturation = 9,
98 .video_brightness = 0,
100 .analog_sync_adj = 0x8080,
103 struct meson_cvbs_enci_mode meson_cvbs_enci_ntsc = {
104 .mode_tag = MESON_VENC_MODE_CVBS_NTSC,
110 .video_prog_mode = 0xf0,
116 .top_field_line_start = 18,
117 .top_field_line_end = 258,
118 .bottom_field_line_start = 19,
119 .bottom_field_line_end = 259,
120 .video_saturation = 18,
122 .video_brightness = 0,
124 .analog_sync_adj = 0x9c00,
127 union meson_hdmi_venc_mode {
129 unsigned int mode_tag;
130 unsigned int hso_begin;
131 unsigned int hso_end;
132 unsigned int vso_even;
133 unsigned int vso_odd;
134 unsigned int macv_max_amp;
135 unsigned int video_prog_mode;
136 unsigned int video_mode;
137 unsigned int sch_adjust;
138 unsigned int yc_delay;
139 unsigned int pixel_start;
140 unsigned int pixel_end;
141 unsigned int top_field_line_start;
142 unsigned int top_field_line_end;
143 unsigned int bottom_field_line_start;
144 unsigned int bottom_field_line_end;
147 unsigned int dvi_settings;
148 unsigned int video_mode;
149 unsigned int video_mode_adv;
150 unsigned int video_prog_mode;
151 bool video_prog_mode_present;
152 unsigned int video_sync_mode;
153 bool video_sync_mode_present;
154 unsigned int video_yc_dly;
155 bool video_yc_dly_present;
156 unsigned int video_rgb_ctrl;
157 bool video_rgb_ctrl_present;
158 unsigned int video_filt_ctrl;
159 bool video_filt_ctrl_present;
160 unsigned int video_ofld_voav_ofst;
161 bool video_ofld_voav_ofst_present;
162 unsigned int yfp1_htime;
163 unsigned int yfp2_htime;
164 unsigned int max_pxcnt;
165 unsigned int hspuls_begin;
166 unsigned int hspuls_end;
167 unsigned int hspuls_switch;
168 unsigned int vspuls_begin;
169 unsigned int vspuls_end;
170 unsigned int vspuls_bline;
171 unsigned int vspuls_eline;
172 unsigned int eqpuls_begin;
173 bool eqpuls_begin_present;
174 unsigned int eqpuls_end;
175 bool eqpuls_end_present;
176 unsigned int eqpuls_bline;
177 bool eqpuls_bline_present;
178 unsigned int eqpuls_eline;
179 bool eqpuls_eline_present;
180 unsigned int havon_begin;
181 unsigned int havon_end;
182 unsigned int vavon_bline;
183 unsigned int vavon_eline;
184 unsigned int hso_begin;
185 unsigned int hso_end;
186 unsigned int vso_begin;
187 unsigned int vso_end;
188 unsigned int vso_bline;
189 unsigned int vso_eline;
190 bool vso_eline_present;
193 unsigned int sy2_val;
194 bool sy2_val_present;
195 unsigned int max_lncnt;
199 union meson_hdmi_venc_mode meson_hdmi_enci_mode_480i = {
205 .macv_max_amp = 0x810b,
206 .video_prog_mode = 0xf0,
212 .top_field_line_start = 18,
213 .top_field_line_end = 258,
214 .bottom_field_line_start = 19,
215 .bottom_field_line_end = 259,
219 union meson_hdmi_venc_mode meson_hdmi_enci_mode_576i = {
225 .macv_max_amp = 8107,
226 .video_prog_mode = 0xff,
232 .top_field_line_start = 22,
233 .top_field_line_end = 310,
234 .bottom_field_line_start = 23,
235 .bottom_field_line_end = 311,
239 union meson_hdmi_venc_mode meson_hdmi_encp_mode_480p = {
241 .dvi_settings = 0x21,
242 .video_mode = 0x4000,
243 .video_mode_adv = 0x9,
244 .video_prog_mode = 0,
245 .video_prog_mode_present = true,
246 .video_sync_mode = 7,
247 .video_sync_mode_present = true,
250 .video_filt_ctrl = 0x2052,
251 .video_filt_ctrl_present = true,
252 /* video_ofld_voav_ofst */
256 .hspuls_begin = 0x22,
278 .sy_val_present = true,
280 .sy2_val_present = true,
285 union meson_hdmi_venc_mode meson_hdmi_encp_mode_576p = {
287 .dvi_settings = 0x21,
288 .video_mode = 0x4000,
289 .video_mode_adv = 0x9,
290 .video_prog_mode = 0,
291 .video_prog_mode_present = true,
292 .video_sync_mode = 7,
293 .video_sync_mode_present = true,
296 .video_filt_ctrl = 0x52,
297 .video_filt_ctrl_present = true,
298 /* video_ofld_voav_ofst */
324 .sy_val_present = true,
326 .sy2_val_present = true,
331 union meson_hdmi_venc_mode meson_hdmi_encp_mode_720p60 = {
333 .dvi_settings = 0x2029,
334 .video_mode = 0x4040,
335 .video_mode_adv = 0x19,
336 /* video_prog_mode */
337 /* video_sync_mode */
340 /* video_filt_ctrl */
341 /* video_ofld_voav_ofst */
366 .vso_eline_present = true,
373 union meson_hdmi_venc_mode meson_hdmi_encp_mode_720p50 = {
375 .dvi_settings = 0x202d,
376 .video_mode = 0x4040,
377 .video_mode_adv = 0x19,
378 .video_prog_mode = 0x100,
379 .video_prog_mode_present = true,
380 .video_sync_mode = 0x407,
381 .video_sync_mode_present = true,
383 .video_yc_dly_present = true,
385 /* video_filt_ctrl */
386 /* video_ofld_voav_ofst */
411 .vso_eline_present = true,
418 union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080i60 = {
420 .dvi_settings = 0x2029,
421 .video_mode = 0x5ffc,
422 .video_mode_adv = 0x19,
423 .video_prog_mode = 0x100,
424 .video_prog_mode_present = true,
425 .video_sync_mode = 0x207,
426 .video_sync_mode_present = true,
429 /* video_filt_ctrl */
430 .video_ofld_voav_ofst = 0x11,
431 .video_ofld_voav_ofst_present = true,
446 .eqpuls_begin = 2288,
447 .eqpuls_begin_present = true,
449 .eqpuls_end_present = true,
451 .eqpuls_bline_present = true,
453 .eqpuls_eline_present = true,
460 .vso_eline_present = true,
467 union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080i50 = {
469 .dvi_settings = 0x202d,
470 .video_mode = 0x5ffc,
471 .video_mode_adv = 0x19,
472 .video_prog_mode = 0x100,
473 .video_prog_mode_present = true,
474 .video_sync_mode = 0x7,
475 .video_sync_mode_present = true,
478 /* video_filt_ctrl */
479 .video_ofld_voav_ofst = 0x11,
480 .video_ofld_voav_ofst_present = true,
495 .eqpuls_begin = 2288,
496 .eqpuls_begin_present = true,
498 .eqpuls_end_present = true,
500 .eqpuls_bline_present = true,
502 .eqpuls_eline_present = true,
509 .vso_eline_present = true,
516 union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080p24 = {
519 .video_mode = 0x4040,
520 .video_mode_adv = 0x18,
521 .video_prog_mode = 0x100,
522 .video_prog_mode_present = true,
523 .video_sync_mode = 0x7,
524 .video_sync_mode_present = true,
526 .video_yc_dly_present = true,
528 .video_rgb_ctrl_present = true,
529 .video_filt_ctrl = 0x1052,
530 .video_filt_ctrl_present = true,
531 /* video_ofld_voav_ofst */
549 .eqpuls_bline_present = true,
551 .eqpuls_eline_present = true,
558 .vso_eline_present = true,
565 union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080p30 = {
568 .video_mode = 0x4040,
569 .video_mode_adv = 0x18,
570 .video_prog_mode = 0x100,
571 .video_prog_mode_present = true,
572 /* video_sync_mode */
575 .video_filt_ctrl = 0x1052,
576 .video_filt_ctrl_present = true,
577 /* video_ofld_voav_ofst */
581 .hspuls_begin = 2156,
602 .vso_eline_present = true,
609 union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080p50 = {
612 .video_mode = 0x4040,
613 .video_mode_adv = 0x18,
614 .video_prog_mode = 0x100,
615 .video_prog_mode_present = true,
616 .video_sync_mode = 0x7,
617 .video_sync_mode_present = true,
619 .video_yc_dly_present = true,
621 .video_rgb_ctrl_present = true,
622 /* video_filt_ctrl */
623 /* video_ofld_voav_ofst */
641 .eqpuls_bline_present = true,
643 .eqpuls_eline_present = true,
650 .vso_eline_present = true,
657 union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080p60 = {
660 .video_mode = 0x4040,
661 .video_mode_adv = 0x18,
662 .video_prog_mode = 0x100,
663 .video_prog_mode_present = true,
664 /* video_sync_mode */
667 .video_filt_ctrl = 0x1052,
668 .video_filt_ctrl_present = true,
669 /* video_ofld_voav_ofst */
673 .hspuls_begin = 2156,
694 .vso_eline_present = true,
701 union meson_hdmi_venc_mode meson_hdmi_encp_mode_2160p24 = {
704 .video_mode = 0x4040,
705 .video_mode_adv = 0x8,
706 /* video_sync_mode */
709 .video_filt_ctrl = 0x1000,
710 .video_filt_ctrl_present = true,
711 /* video_ofld_voav_ofst */
713 .yfp2_htime = 140+3840,
714 .max_pxcnt = 3840+1660-1,
715 .hspuls_begin = 2156+1920,
719 .vspuls_end = 2059+1920,
731 .hso_end = 2156+1920,
732 .vso_begin = 2100+1920,
733 .vso_end = 2164+1920,
736 .vso_eline_present = true,
743 union meson_hdmi_venc_mode meson_hdmi_encp_mode_2160p25 = {
746 .video_mode = 0x4040,
747 .video_mode_adv = 0x8,
748 /* video_sync_mode */
751 .video_filt_ctrl = 0x1000,
752 .video_filt_ctrl_present = true,
753 /* video_ofld_voav_ofst */
755 .yfp2_htime = 140+3840,
756 .max_pxcnt = 3840+1440-1,
757 .hspuls_begin = 2156+1920,
761 .vspuls_end = 2059+1920,
773 .hso_end = 2156+1920,
774 .vso_begin = 2100+1920,
775 .vso_end = 2164+1920,
778 .vso_eline_present = true,
785 union meson_hdmi_venc_mode meson_hdmi_encp_mode_2160p30 = {
788 .video_mode = 0x4040,
789 .video_mode_adv = 0x8,
790 /* video_sync_mode */
793 .video_filt_ctrl = 0x1000,
794 .video_filt_ctrl_present = true,
795 /* video_ofld_voav_ofst */
797 .yfp2_htime = 140+3840,
798 .max_pxcnt = 3840+560-1,
799 .hspuls_begin = 2156+1920,
803 .vspuls_end = 2059+1920,
815 .hso_end = 2156+1920,
816 .vso_begin = 2100+1920,
817 .vso_end = 2164+1920,
820 .vso_eline_present = true,
827 struct meson_hdmi_venc_vic_mode {
829 union meson_hdmi_venc_mode *mode;
830 } meson_hdmi_venc_vic_modes[] = {
831 { 6, &meson_hdmi_enci_mode_480i },
832 { 7, &meson_hdmi_enci_mode_480i },
833 { 21, &meson_hdmi_enci_mode_576i },
834 { 22, &meson_hdmi_enci_mode_576i },
835 { 2, &meson_hdmi_encp_mode_480p },
836 { 3, &meson_hdmi_encp_mode_480p },
837 { 17, &meson_hdmi_encp_mode_576p },
838 { 18, &meson_hdmi_encp_mode_576p },
839 { 4, &meson_hdmi_encp_mode_720p60 },
840 { 19, &meson_hdmi_encp_mode_720p50 },
841 { 5, &meson_hdmi_encp_mode_1080i60 },
842 { 20, &meson_hdmi_encp_mode_1080i50 },
843 { 32, &meson_hdmi_encp_mode_1080p24 },
844 { 33, &meson_hdmi_encp_mode_1080p50 },
845 { 34, &meson_hdmi_encp_mode_1080p30 },
846 { 31, &meson_hdmi_encp_mode_1080p50 },
847 { 16, &meson_hdmi_encp_mode_1080p60 },
848 { 93, &meson_hdmi_encp_mode_2160p24 },
849 { 94, &meson_hdmi_encp_mode_2160p25 },
850 { 95, &meson_hdmi_encp_mode_2160p30 },
851 { 0, NULL}, /* sentinel */
854 static signed int to_signed(unsigned int a)
862 static unsigned long modulo(unsigned long a, unsigned long b)
871 meson_venc_hdmi_supported_mode(const struct drm_display_mode *mode)
873 if (mode->flags & ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC |
874 DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))
877 if (mode->hdisplay < 640 || mode->hdisplay > 1920)
878 return MODE_BAD_HVALUE;
880 if (mode->vdisplay < 480 || mode->vdisplay > 1200)
881 return MODE_BAD_VVALUE;
885 EXPORT_SYMBOL_GPL(meson_venc_hdmi_supported_mode);
887 bool meson_venc_hdmi_supported_vic(int vic)
889 struct meson_hdmi_venc_vic_mode *vmode = meson_hdmi_venc_vic_modes;
891 while (vmode->vic && vmode->mode) {
892 if (vmode->vic == vic)
899 EXPORT_SYMBOL_GPL(meson_venc_hdmi_supported_vic);
901 void meson_venc_hdmi_get_dmt_vmode(const struct drm_display_mode *mode,
902 union meson_hdmi_venc_mode *dmt_mode)
904 memset(dmt_mode, 0, sizeof(*dmt_mode));
906 dmt_mode->encp.dvi_settings = 0x21;
907 dmt_mode->encp.video_mode = 0x4040;
908 dmt_mode->encp.video_mode_adv = 0x18;
909 dmt_mode->encp.max_pxcnt = mode->htotal - 1;
910 dmt_mode->encp.havon_begin = mode->htotal - mode->hsync_start;
911 dmt_mode->encp.havon_end = dmt_mode->encp.havon_begin +
913 dmt_mode->encp.vavon_bline = mode->vtotal - mode->vsync_start;
914 dmt_mode->encp.vavon_eline = dmt_mode->encp.vavon_bline +
916 dmt_mode->encp.hso_begin = 0;
917 dmt_mode->encp.hso_end = mode->hsync_end - mode->hsync_start;
918 dmt_mode->encp.vso_begin = 30;
919 dmt_mode->encp.vso_end = 50;
920 dmt_mode->encp.vso_bline = 0;
921 dmt_mode->encp.vso_eline = mode->vsync_end - mode->vsync_start;
922 dmt_mode->encp.vso_eline_present = true;
923 dmt_mode->encp.max_lncnt = mode->vtotal - 1;
926 static union meson_hdmi_venc_mode *meson_venc_hdmi_get_vic_vmode(int vic)
928 struct meson_hdmi_venc_vic_mode *vmode = meson_hdmi_venc_vic_modes;
930 while (vmode->vic && vmode->mode) {
931 if (vmode->vic == vic)
939 bool meson_venc_hdmi_venc_repeat(int vic)
941 /* Repeat VENC pixels for 480/576i/p, 720p50/60 and 1080p50/60 */
942 if (vic == 6 || vic == 7 || /* 480i */
943 vic == 21 || vic == 22 || /* 576i */
944 vic == 17 || vic == 18 || /* 576p */
945 vic == 2 || vic == 3 || /* 480p */
946 vic == 4 || /* 720p60 */
947 vic == 19 || /* 720p50 */
948 vic == 5 || /* 1080i60 */
949 vic == 20) /* 1080i50 */
954 EXPORT_SYMBOL_GPL(meson_venc_hdmi_venc_repeat);
956 void meson_venc_hdmi_mode_set(struct meson_drm *priv, int vic,
957 struct drm_display_mode *mode)
959 union meson_hdmi_venc_mode *vmode = NULL;
960 union meson_hdmi_venc_mode vmode_dmt;
961 bool use_enci = false;
962 bool venc_repeat = false;
963 bool hdmi_repeat = false;
964 unsigned int venc_hdmi_latency = 2;
965 unsigned long total_pixels_venc = 0;
966 unsigned long active_pixels_venc = 0;
967 unsigned long front_porch_venc = 0;
968 unsigned long hsync_pixels_venc = 0;
969 unsigned long de_h_begin = 0;
970 unsigned long de_h_end = 0;
971 unsigned long de_v_begin_even = 0;
972 unsigned long de_v_end_even = 0;
973 unsigned long de_v_begin_odd = 0;
974 unsigned long de_v_end_odd = 0;
975 unsigned long hs_begin = 0;
976 unsigned long hs_end = 0;
977 unsigned long vs_adjust = 0;
978 unsigned long vs_bline_evn = 0;
979 unsigned long vs_eline_evn = 0;
980 unsigned long vs_bline_odd = 0;
981 unsigned long vs_eline_odd = 0;
982 unsigned long vso_begin_evn = 0;
983 unsigned long vso_begin_odd = 0;
984 unsigned int eof_lines;
985 unsigned int sof_lines;
986 unsigned int vsync_lines;
988 /* Use VENCI for 480i and 576i and double HDMI pixels */
989 if (mode->flags & DRM_MODE_FLAG_DBLCLK) {
992 venc_hdmi_latency = 1;
995 if (meson_venc_hdmi_supported_vic(vic)) {
996 vmode = meson_venc_hdmi_get_vic_vmode(vic);
998 dev_err(priv->dev, "%s: Fatal Error, unsupported mode "
999 DRM_MODE_FMT "\n", __func__,
1000 DRM_MODE_ARG(mode));
1004 meson_venc_hdmi_get_dmt_vmode(mode, &vmode_dmt);
1009 /* Repeat VENC pixels for 480/576i/p, 720p50/60 and 1080p50/60 */
1010 if (meson_venc_hdmi_venc_repeat(vic))
1013 eof_lines = mode->vsync_start - mode->vdisplay;
1014 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1016 sof_lines = mode->vtotal - mode->vsync_end;
1017 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1019 vsync_lines = mode->vsync_end - mode->vsync_start;
1020 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1023 total_pixels_venc = mode->htotal;
1025 total_pixels_venc /= 2;
1027 total_pixels_venc *= 2;
1029 active_pixels_venc = mode->hdisplay;
1031 active_pixels_venc /= 2;
1033 active_pixels_venc *= 2;
1035 front_porch_venc = (mode->hsync_start - mode->hdisplay);
1037 front_porch_venc /= 2;
1039 front_porch_venc *= 2;
1041 hsync_pixels_venc = (mode->hsync_end - mode->hsync_start);
1043 hsync_pixels_venc /= 2;
1045 hsync_pixels_venc *= 2;
1048 writel_bits_relaxed(0xff, 0xff,
1049 priv->io_base + _REG(VENC_VDAC_SETTING));
1051 writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_EN));
1052 writel_relaxed(0, priv->io_base + _REG(ENCP_VIDEO_EN));
1055 unsigned int lines_f0;
1056 unsigned int lines_f1;
1058 /* CVBS Filter settings */
1059 writel_relaxed(0x12, priv->io_base + _REG(ENCI_CFILT_CTRL));
1060 writel_relaxed(0x12, priv->io_base + _REG(ENCI_CFILT_CTRL2));
1062 /* Digital Video Select : Interlace, clk27 clk, external */
1063 writel_relaxed(0, priv->io_base + _REG(VENC_DVI_SETTING));
1065 /* Reset Video Mode */
1066 writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_MODE));
1067 writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_MODE_ADV));
1069 /* Horizontal sync signal output */
1070 writel_relaxed(vmode->enci.hso_begin,
1071 priv->io_base + _REG(ENCI_SYNC_HSO_BEGIN));
1072 writel_relaxed(vmode->enci.hso_end,
1073 priv->io_base + _REG(ENCI_SYNC_HSO_END));
1075 /* Vertical Sync lines */
1076 writel_relaxed(vmode->enci.vso_even,
1077 priv->io_base + _REG(ENCI_SYNC_VSO_EVNLN));
1078 writel_relaxed(vmode->enci.vso_odd,
1079 priv->io_base + _REG(ENCI_SYNC_VSO_ODDLN));
1081 /* Macrovision max amplitude change */
1082 writel_relaxed(vmode->enci.macv_max_amp,
1083 priv->io_base + _REG(ENCI_MACV_MAX_AMP));
1086 writel_relaxed(vmode->enci.video_prog_mode,
1087 priv->io_base + _REG(VENC_VIDEO_PROG_MODE));
1088 writel_relaxed(vmode->enci.video_mode,
1089 priv->io_base + _REG(ENCI_VIDEO_MODE));
1091 /* Advanced Video Mode :
1092 * Demux shifting 0x2
1093 * Blank line end at line17/22
1094 * High bandwidth Luma Filter
1095 * Low bandwidth Chroma Filter
1096 * Bypass luma low pass filter
1097 * No macrovision on CSYNC
1099 writel_relaxed(0x26, priv->io_base + _REG(ENCI_VIDEO_MODE_ADV));
1101 writel(vmode->enci.sch_adjust,
1102 priv->io_base + _REG(ENCI_VIDEO_SCH));
1104 /* Sync mode : MASTER Master mode, free run, send HSO/VSO out */
1105 writel_relaxed(0x07, priv->io_base + _REG(ENCI_SYNC_MODE));
1107 if (vmode->enci.yc_delay)
1108 writel_relaxed(vmode->enci.yc_delay,
1109 priv->io_base + _REG(ENCI_YC_DELAY));
1112 /* UNreset Interlaced TV Encoder */
1113 writel_relaxed(0, priv->io_base + _REG(ENCI_DBG_PX_RST));
1115 /* Enable Vfifo2vd, Y_Cb_Y_Cr select */
1116 writel_relaxed(0x4e01, priv->io_base + _REG(ENCI_VFIFO2VD_CTL));
1119 writel_relaxed(vmode->enci.pixel_start,
1120 priv->io_base + _REG(ENCI_VFIFO2VD_PIXEL_START));
1121 writel_relaxed(vmode->enci.pixel_end,
1122 priv->io_base + _REG(ENCI_VFIFO2VD_PIXEL_END));
1124 writel_relaxed(vmode->enci.top_field_line_start,
1125 priv->io_base + _REG(ENCI_VFIFO2VD_LINE_TOP_START));
1126 writel_relaxed(vmode->enci.top_field_line_end,
1127 priv->io_base + _REG(ENCI_VFIFO2VD_LINE_TOP_END));
1129 writel_relaxed(vmode->enci.bottom_field_line_start,
1130 priv->io_base + _REG(ENCI_VFIFO2VD_LINE_BOT_START));
1131 writel_relaxed(vmode->enci.bottom_field_line_end,
1132 priv->io_base + _REG(ENCI_VFIFO2VD_LINE_BOT_END));
1134 /* Select ENCI for VIU */
1135 meson_vpp_setup_mux(priv, MESON_VIU_VPP_MUX_ENCI);
1137 /* Interlace video enable */
1138 writel_relaxed(1, priv->io_base + _REG(ENCI_VIDEO_EN));
1140 lines_f0 = mode->vtotal >> 1;
1141 lines_f1 = lines_f0 + 1;
1143 de_h_begin = modulo(readl_relaxed(priv->io_base +
1144 _REG(ENCI_VFIFO2VD_PIXEL_START))
1145 + venc_hdmi_latency,
1147 de_h_end = modulo(de_h_begin + active_pixels_venc,
1150 writel_relaxed(de_h_begin,
1151 priv->io_base + _REG(ENCI_DE_H_BEGIN));
1152 writel_relaxed(de_h_end,
1153 priv->io_base + _REG(ENCI_DE_H_END));
1155 de_v_begin_even = readl_relaxed(priv->io_base +
1156 _REG(ENCI_VFIFO2VD_LINE_TOP_START));
1157 de_v_end_even = de_v_begin_even + mode->vdisplay;
1158 de_v_begin_odd = readl_relaxed(priv->io_base +
1159 _REG(ENCI_VFIFO2VD_LINE_BOT_START));
1160 de_v_end_odd = de_v_begin_odd + mode->vdisplay;
1162 writel_relaxed(de_v_begin_even,
1163 priv->io_base + _REG(ENCI_DE_V_BEGIN_EVEN));
1164 writel_relaxed(de_v_end_even,
1165 priv->io_base + _REG(ENCI_DE_V_END_EVEN));
1166 writel_relaxed(de_v_begin_odd,
1167 priv->io_base + _REG(ENCI_DE_V_BEGIN_ODD));
1168 writel_relaxed(de_v_end_odd,
1169 priv->io_base + _REG(ENCI_DE_V_END_ODD));
1171 /* Program Hsync timing */
1172 hs_begin = de_h_end + front_porch_venc;
1173 if (de_h_end + front_porch_venc >= total_pixels_venc) {
1174 hs_begin -= total_pixels_venc;
1177 hs_begin = de_h_end + front_porch_venc;
1181 hs_end = modulo(hs_begin + hsync_pixels_venc,
1183 writel_relaxed(hs_begin,
1184 priv->io_base + _REG(ENCI_DVI_HSO_BEGIN));
1185 writel_relaxed(hs_end,
1186 priv->io_base + _REG(ENCI_DVI_HSO_END));
1188 /* Program Vsync timing for even field */
1189 if (((de_v_end_odd - 1) + eof_lines + vs_adjust) >= lines_f1) {
1190 vs_bline_evn = (de_v_end_odd - 1)
1194 vs_eline_evn = vs_bline_evn + vsync_lines;
1196 writel_relaxed(vs_bline_evn,
1197 priv->io_base + _REG(ENCI_DVI_VSO_BLINE_EVN));
1199 writel_relaxed(vs_eline_evn,
1200 priv->io_base + _REG(ENCI_DVI_VSO_ELINE_EVN));
1202 writel_relaxed(hs_begin,
1203 priv->io_base + _REG(ENCI_DVI_VSO_BEGIN_EVN));
1204 writel_relaxed(hs_begin,
1205 priv->io_base + _REG(ENCI_DVI_VSO_END_EVN));
1207 vs_bline_odd = (de_v_end_odd - 1)
1211 writel_relaxed(vs_bline_odd,
1212 priv->io_base + _REG(ENCI_DVI_VSO_BLINE_ODD));
1214 writel_relaxed(hs_begin,
1215 priv->io_base + _REG(ENCI_DVI_VSO_BEGIN_ODD));
1217 if ((vs_bline_odd + vsync_lines) >= lines_f1) {
1218 vs_eline_evn = vs_bline_odd
1222 writel_relaxed(vs_eline_evn, priv->io_base
1223 + _REG(ENCI_DVI_VSO_ELINE_EVN));
1225 writel_relaxed(hs_begin, priv->io_base
1226 + _REG(ENCI_DVI_VSO_END_EVN));
1228 vs_eline_odd = vs_bline_odd
1231 writel_relaxed(vs_eline_odd, priv->io_base
1232 + _REG(ENCI_DVI_VSO_ELINE_ODD));
1234 writel_relaxed(hs_begin, priv->io_base
1235 + _REG(ENCI_DVI_VSO_END_ODD));
1239 /* Program Vsync timing for odd field */
1240 if (((de_v_end_even - 1) + (eof_lines + 1)) >= lines_f0) {
1241 vs_bline_odd = (de_v_end_even - 1)
1244 vs_eline_odd = vs_bline_odd + vsync_lines;
1246 writel_relaxed(vs_bline_odd,
1247 priv->io_base + _REG(ENCI_DVI_VSO_BLINE_ODD));
1249 writel_relaxed(vs_eline_odd,
1250 priv->io_base + _REG(ENCI_DVI_VSO_ELINE_ODD));
1252 vso_begin_odd = modulo(hs_begin
1253 + (total_pixels_venc >> 1),
1256 writel_relaxed(vso_begin_odd,
1257 priv->io_base + _REG(ENCI_DVI_VSO_BEGIN_ODD));
1258 writel_relaxed(vso_begin_odd,
1259 priv->io_base + _REG(ENCI_DVI_VSO_END_ODD));
1261 vs_bline_evn = (de_v_end_even - 1)
1264 writel_relaxed(vs_bline_evn,
1265 priv->io_base + _REG(ENCI_DVI_VSO_BLINE_EVN));
1267 vso_begin_evn = modulo(hs_begin
1268 + (total_pixels_venc >> 1),
1271 writel_relaxed(vso_begin_evn, priv->io_base
1272 + _REG(ENCI_DVI_VSO_BEGIN_EVN));
1274 if (vs_bline_evn + vsync_lines >= lines_f0) {
1275 vs_eline_odd = vs_bline_evn
1279 writel_relaxed(vs_eline_odd, priv->io_base
1280 + _REG(ENCI_DVI_VSO_ELINE_ODD));
1282 writel_relaxed(vso_begin_evn, priv->io_base
1283 + _REG(ENCI_DVI_VSO_END_ODD));
1285 vs_eline_evn = vs_bline_evn + vsync_lines;
1287 writel_relaxed(vs_eline_evn, priv->io_base
1288 + _REG(ENCI_DVI_VSO_ELINE_EVN));
1290 writel_relaxed(vso_begin_evn, priv->io_base
1291 + _REG(ENCI_DVI_VSO_END_EVN));
1295 writel_relaxed(vmode->encp.dvi_settings,
1296 priv->io_base + _REG(VENC_DVI_SETTING));
1297 writel_relaxed(vmode->encp.video_mode,
1298 priv->io_base + _REG(ENCP_VIDEO_MODE));
1299 writel_relaxed(vmode->encp.video_mode_adv,
1300 priv->io_base + _REG(ENCP_VIDEO_MODE_ADV));
1301 if (vmode->encp.video_prog_mode_present)
1302 writel_relaxed(vmode->encp.video_prog_mode,
1303 priv->io_base + _REG(VENC_VIDEO_PROG_MODE));
1304 if (vmode->encp.video_sync_mode_present)
1305 writel_relaxed(vmode->encp.video_sync_mode,
1306 priv->io_base + _REG(ENCP_VIDEO_SYNC_MODE));
1307 if (vmode->encp.video_yc_dly_present)
1308 writel_relaxed(vmode->encp.video_yc_dly,
1309 priv->io_base + _REG(ENCP_VIDEO_YC_DLY));
1310 if (vmode->encp.video_rgb_ctrl_present)
1311 writel_relaxed(vmode->encp.video_rgb_ctrl,
1312 priv->io_base + _REG(ENCP_VIDEO_RGB_CTRL));
1313 if (vmode->encp.video_filt_ctrl_present)
1314 writel_relaxed(vmode->encp.video_filt_ctrl,
1315 priv->io_base + _REG(ENCP_VIDEO_FILT_CTRL));
1316 if (vmode->encp.video_ofld_voav_ofst_present)
1317 writel_relaxed(vmode->encp.video_ofld_voav_ofst,
1319 + _REG(ENCP_VIDEO_OFLD_VOAV_OFST));
1320 writel_relaxed(vmode->encp.yfp1_htime,
1321 priv->io_base + _REG(ENCP_VIDEO_YFP1_HTIME));
1322 writel_relaxed(vmode->encp.yfp2_htime,
1323 priv->io_base + _REG(ENCP_VIDEO_YFP2_HTIME));
1324 writel_relaxed(vmode->encp.max_pxcnt,
1325 priv->io_base + _REG(ENCP_VIDEO_MAX_PXCNT));
1326 writel_relaxed(vmode->encp.hspuls_begin,
1327 priv->io_base + _REG(ENCP_VIDEO_HSPULS_BEGIN));
1328 writel_relaxed(vmode->encp.hspuls_end,
1329 priv->io_base + _REG(ENCP_VIDEO_HSPULS_END));
1330 writel_relaxed(vmode->encp.hspuls_switch,
1331 priv->io_base + _REG(ENCP_VIDEO_HSPULS_SWITCH));
1332 writel_relaxed(vmode->encp.vspuls_begin,
1333 priv->io_base + _REG(ENCP_VIDEO_VSPULS_BEGIN));
1334 writel_relaxed(vmode->encp.vspuls_end,
1335 priv->io_base + _REG(ENCP_VIDEO_VSPULS_END));
1336 writel_relaxed(vmode->encp.vspuls_bline,
1337 priv->io_base + _REG(ENCP_VIDEO_VSPULS_BLINE));
1338 writel_relaxed(vmode->encp.vspuls_eline,
1339 priv->io_base + _REG(ENCP_VIDEO_VSPULS_ELINE));
1340 if (vmode->encp.eqpuls_begin_present)
1341 writel_relaxed(vmode->encp.eqpuls_begin,
1342 priv->io_base + _REG(ENCP_VIDEO_EQPULS_BEGIN));
1343 if (vmode->encp.eqpuls_end_present)
1344 writel_relaxed(vmode->encp.eqpuls_end,
1345 priv->io_base + _REG(ENCP_VIDEO_EQPULS_END));
1346 if (vmode->encp.eqpuls_bline_present)
1347 writel_relaxed(vmode->encp.eqpuls_bline,
1348 priv->io_base + _REG(ENCP_VIDEO_EQPULS_BLINE));
1349 if (vmode->encp.eqpuls_eline_present)
1350 writel_relaxed(vmode->encp.eqpuls_eline,
1351 priv->io_base + _REG(ENCP_VIDEO_EQPULS_ELINE));
1352 writel_relaxed(vmode->encp.havon_begin,
1353 priv->io_base + _REG(ENCP_VIDEO_HAVON_BEGIN));
1354 writel_relaxed(vmode->encp.havon_end,
1355 priv->io_base + _REG(ENCP_VIDEO_HAVON_END));
1356 writel_relaxed(vmode->encp.vavon_bline,
1357 priv->io_base + _REG(ENCP_VIDEO_VAVON_BLINE));
1358 writel_relaxed(vmode->encp.vavon_eline,
1359 priv->io_base + _REG(ENCP_VIDEO_VAVON_ELINE));
1360 writel_relaxed(vmode->encp.hso_begin,
1361 priv->io_base + _REG(ENCP_VIDEO_HSO_BEGIN));
1362 writel_relaxed(vmode->encp.hso_end,
1363 priv->io_base + _REG(ENCP_VIDEO_HSO_END));
1364 writel_relaxed(vmode->encp.vso_begin,
1365 priv->io_base + _REG(ENCP_VIDEO_VSO_BEGIN));
1366 writel_relaxed(vmode->encp.vso_end,
1367 priv->io_base + _REG(ENCP_VIDEO_VSO_END));
1368 writel_relaxed(vmode->encp.vso_bline,
1369 priv->io_base + _REG(ENCP_VIDEO_VSO_BLINE));
1370 if (vmode->encp.vso_eline_present)
1371 writel_relaxed(vmode->encp.vso_eline,
1372 priv->io_base + _REG(ENCP_VIDEO_VSO_ELINE));
1373 if (vmode->encp.sy_val_present)
1374 writel_relaxed(vmode->encp.sy_val,
1375 priv->io_base + _REG(ENCP_VIDEO_SY_VAL));
1376 if (vmode->encp.sy2_val_present)
1377 writel_relaxed(vmode->encp.sy2_val,
1378 priv->io_base + _REG(ENCP_VIDEO_SY2_VAL));
1379 writel_relaxed(vmode->encp.max_lncnt,
1380 priv->io_base + _REG(ENCP_VIDEO_MAX_LNCNT));
1382 writel_relaxed(1, priv->io_base + _REG(ENCP_VIDEO_EN));
1384 /* Set DE signal’s polarity is active high */
1385 writel_bits_relaxed(BIT(14), BIT(14),
1386 priv->io_base + _REG(ENCP_VIDEO_MODE));
1388 /* Program DE timing */
1389 de_h_begin = modulo(readl_relaxed(priv->io_base +
1390 _REG(ENCP_VIDEO_HAVON_BEGIN))
1391 + venc_hdmi_latency,
1393 de_h_end = modulo(de_h_begin + active_pixels_venc,
1396 writel_relaxed(de_h_begin,
1397 priv->io_base + _REG(ENCP_DE_H_BEGIN));
1398 writel_relaxed(de_h_end,
1399 priv->io_base + _REG(ENCP_DE_H_END));
1401 /* Program DE timing for even field */
1402 de_v_begin_even = readl_relaxed(priv->io_base
1403 + _REG(ENCP_VIDEO_VAVON_BLINE));
1404 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1405 de_v_end_even = de_v_begin_even +
1406 (mode->vdisplay / 2);
1408 de_v_end_even = de_v_begin_even + mode->vdisplay;
1410 writel_relaxed(de_v_begin_even,
1411 priv->io_base + _REG(ENCP_DE_V_BEGIN_EVEN));
1412 writel_relaxed(de_v_end_even,
1413 priv->io_base + _REG(ENCP_DE_V_END_EVEN));
1415 /* Program DE timing for odd field if needed */
1416 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
1417 unsigned int ofld_voav_ofst =
1418 readl_relaxed(priv->io_base +
1419 _REG(ENCP_VIDEO_OFLD_VOAV_OFST));
1420 de_v_begin_odd = to_signed((ofld_voav_ofst & 0xf0) >> 4)
1422 + ((mode->vtotal - 1) / 2);
1423 de_v_end_odd = de_v_begin_odd + (mode->vdisplay / 2);
1425 writel_relaxed(de_v_begin_odd,
1426 priv->io_base + _REG(ENCP_DE_V_BEGIN_ODD));
1427 writel_relaxed(de_v_end_odd,
1428 priv->io_base + _REG(ENCP_DE_V_END_ODD));
1431 /* Program Hsync timing */
1432 if ((de_h_end + front_porch_venc) >= total_pixels_venc) {
1435 - total_pixels_venc;
1443 hs_end = modulo(hs_begin + hsync_pixels_venc,
1446 writel_relaxed(hs_begin,
1447 priv->io_base + _REG(ENCP_DVI_HSO_BEGIN));
1448 writel_relaxed(hs_end,
1449 priv->io_base + _REG(ENCP_DVI_HSO_END));
1451 /* Program Vsync timing for even field */
1452 if (de_v_begin_even >=
1453 (sof_lines + vsync_lines + (1 - vs_adjust)))
1454 vs_bline_evn = de_v_begin_even
1459 vs_bline_evn = mode->vtotal
1465 vs_eline_evn = modulo(vs_bline_evn + vsync_lines,
1468 writel_relaxed(vs_bline_evn,
1469 priv->io_base + _REG(ENCP_DVI_VSO_BLINE_EVN));
1470 writel_relaxed(vs_eline_evn,
1471 priv->io_base + _REG(ENCP_DVI_VSO_ELINE_EVN));
1473 vso_begin_evn = hs_begin;
1474 writel_relaxed(vso_begin_evn,
1475 priv->io_base + _REG(ENCP_DVI_VSO_BEGIN_EVN));
1476 writel_relaxed(vso_begin_evn,
1477 priv->io_base + _REG(ENCP_DVI_VSO_END_EVN));
1479 /* Program Vsync timing for odd field if needed */
1480 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
1481 vs_bline_odd = (de_v_begin_odd - 1)
1484 vs_eline_odd = (de_v_begin_odd - 1)
1486 vso_begin_odd = modulo(hs_begin
1487 + (total_pixels_venc >> 1),
1490 writel_relaxed(vs_bline_odd,
1491 priv->io_base + _REG(ENCP_DVI_VSO_BLINE_ODD));
1492 writel_relaxed(vs_eline_odd,
1493 priv->io_base + _REG(ENCP_DVI_VSO_ELINE_ODD));
1494 writel_relaxed(vso_begin_odd,
1495 priv->io_base + _REG(ENCP_DVI_VSO_BEGIN_ODD));
1496 writel_relaxed(vso_begin_odd,
1497 priv->io_base + _REG(ENCP_DVI_VSO_END_ODD));
1500 /* Select ENCP for VIU */
1501 meson_vpp_setup_mux(priv, MESON_VIU_VPP_MUX_ENCP);
1504 writel_relaxed((use_enci ? 1 : 2) |
1505 (mode->flags & DRM_MODE_FLAG_PHSYNC ? 1 << 2 : 0) |
1506 (mode->flags & DRM_MODE_FLAG_PVSYNC ? 1 << 3 : 0) |
1508 (venc_repeat ? 1 << 8 : 0) |
1509 (hdmi_repeat ? 1 << 12 : 0),
1510 priv->io_base + _REG(VPU_HDMI_SETTING));
1512 priv->venc.hdmi_repeat = hdmi_repeat;
1513 priv->venc.venc_repeat = venc_repeat;
1514 priv->venc.hdmi_use_enci = use_enci;
1516 priv->venc.current_mode = MESON_VENC_MODE_HDMI;
1518 EXPORT_SYMBOL_GPL(meson_venc_hdmi_mode_set);
1520 void meson_venci_cvbs_mode_set(struct meson_drm *priv,
1521 struct meson_cvbs_enci_mode *mode)
1523 if (mode->mode_tag == priv->venc.current_mode)
1526 /* CVBS Filter settings */
1527 writel_relaxed(0x12, priv->io_base + _REG(ENCI_CFILT_CTRL));
1528 writel_relaxed(0x12, priv->io_base + _REG(ENCI_CFILT_CTRL2));
1530 /* Digital Video Select : Interlace, clk27 clk, external */
1531 writel_relaxed(0, priv->io_base + _REG(VENC_DVI_SETTING));
1533 /* Reset Video Mode */
1534 writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_MODE));
1535 writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_MODE_ADV));
1537 /* Horizontal sync signal output */
1538 writel_relaxed(mode->hso_begin,
1539 priv->io_base + _REG(ENCI_SYNC_HSO_BEGIN));
1540 writel_relaxed(mode->hso_end,
1541 priv->io_base + _REG(ENCI_SYNC_HSO_END));
1543 /* Vertical Sync lines */
1544 writel_relaxed(mode->vso_even,
1545 priv->io_base + _REG(ENCI_SYNC_VSO_EVNLN));
1546 writel_relaxed(mode->vso_odd,
1547 priv->io_base + _REG(ENCI_SYNC_VSO_ODDLN));
1549 /* Macrovision max amplitude change */
1550 writel_relaxed(0x8100 + mode->macv_max_amp,
1551 priv->io_base + _REG(ENCI_MACV_MAX_AMP));
1554 writel_relaxed(mode->video_prog_mode,
1555 priv->io_base + _REG(VENC_VIDEO_PROG_MODE));
1556 writel_relaxed(mode->video_mode,
1557 priv->io_base + _REG(ENCI_VIDEO_MODE));
1559 /* Advanced Video Mode :
1560 * Demux shifting 0x2
1561 * Blank line end at line17/22
1562 * High bandwidth Luma Filter
1563 * Low bandwidth Chroma Filter
1564 * Bypass luma low pass filter
1565 * No macrovision on CSYNC
1567 writel_relaxed(0x26, priv->io_base + _REG(ENCI_VIDEO_MODE_ADV));
1569 writel(mode->sch_adjust, priv->io_base + _REG(ENCI_VIDEO_SCH));
1571 /* Sync mode : MASTER Master mode, free run, send HSO/VSO out */
1572 writel_relaxed(0x07, priv->io_base + _REG(ENCI_SYNC_MODE));
1574 /* 0x3 Y, C, and Component Y delay */
1575 writel_relaxed(mode->yc_delay, priv->io_base + _REG(ENCI_YC_DELAY));
1578 writel_relaxed(mode->pixel_start,
1579 priv->io_base + _REG(ENCI_VFIFO2VD_PIXEL_START));
1580 writel_relaxed(mode->pixel_end,
1581 priv->io_base + _REG(ENCI_VFIFO2VD_PIXEL_END));
1583 writel_relaxed(mode->top_field_line_start,
1584 priv->io_base + _REG(ENCI_VFIFO2VD_LINE_TOP_START));
1585 writel_relaxed(mode->top_field_line_end,
1586 priv->io_base + _REG(ENCI_VFIFO2VD_LINE_TOP_END));
1588 writel_relaxed(mode->bottom_field_line_start,
1589 priv->io_base + _REG(ENCI_VFIFO2VD_LINE_BOT_START));
1590 writel_relaxed(mode->bottom_field_line_end,
1591 priv->io_base + _REG(ENCI_VFIFO2VD_LINE_BOT_END));
1593 /* Internal Venc, Internal VIU Sync, Internal Vencoder */
1594 writel_relaxed(0, priv->io_base + _REG(VENC_SYNC_ROUTE));
1596 /* UNreset Interlaced TV Encoder */
1597 writel_relaxed(0, priv->io_base + _REG(ENCI_DBG_PX_RST));
1599 /* Enable Vfifo2vd, Y_Cb_Y_Cr select */
1600 writel_relaxed(0x4e01, priv->io_base + _REG(ENCI_VFIFO2VD_CTL));
1603 writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_SETTING));
1605 /* Video Upsampling */
1606 writel_relaxed(0x0061, priv->io_base + _REG(VENC_UPSAMPLE_CTRL0));
1607 writel_relaxed(0x4061, priv->io_base + _REG(VENC_UPSAMPLE_CTRL1));
1608 writel_relaxed(0x5061, priv->io_base + _REG(VENC_UPSAMPLE_CTRL2));
1610 /* Select Interlace Y DACs */
1611 writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL0));
1612 writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL1));
1613 writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL2));
1614 writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL3));
1615 writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL4));
1616 writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL5));
1618 /* Select ENCI for VIU */
1619 meson_vpp_setup_mux(priv, MESON_VIU_VPP_MUX_ENCI);
1621 /* Enable ENCI FIFO */
1622 writel_relaxed(0x2000, priv->io_base + _REG(VENC_VDAC_FIFO_CTRL));
1624 /* Select ENCI DACs 0, 1, 4, and 5 */
1625 writel_relaxed(0x11, priv->io_base + _REG(ENCI_DACSEL_0));
1626 writel_relaxed(0x11, priv->io_base + _REG(ENCI_DACSEL_1));
1628 /* Interlace video enable */
1629 writel_relaxed(1, priv->io_base + _REG(ENCI_VIDEO_EN));
1631 /* Configure Video Saturation / Contrast / Brightness / Hue */
1632 writel_relaxed(mode->video_saturation,
1633 priv->io_base + _REG(ENCI_VIDEO_SAT));
1634 writel_relaxed(mode->video_contrast,
1635 priv->io_base + _REG(ENCI_VIDEO_CONT));
1636 writel_relaxed(mode->video_brightness,
1637 priv->io_base + _REG(ENCI_VIDEO_BRIGHT));
1638 writel_relaxed(mode->video_hue,
1639 priv->io_base + _REG(ENCI_VIDEO_HUE));
1641 /* Enable DAC0 Filter */
1642 writel_relaxed(0x1, priv->io_base + _REG(VENC_VDAC_DAC0_FILT_CTRL0));
1643 writel_relaxed(0xfc48, priv->io_base + _REG(VENC_VDAC_DAC0_FILT_CTRL1));
1645 /* 0 in Macrovision register 0 */
1646 writel_relaxed(0, priv->io_base + _REG(ENCI_MACV_N0));
1648 /* Analog Synchronization and color burst value adjust */
1649 writel_relaxed(mode->analog_sync_adj,
1650 priv->io_base + _REG(ENCI_SYNC_ADJ));
1652 priv->venc.current_mode = mode->mode_tag;
1655 /* Returns the current ENCI field polarity */
1656 unsigned int meson_venci_get_field(struct meson_drm *priv)
1658 return readl_relaxed(priv->io_base + _REG(ENCI_INFO_READ)) & BIT(29);
1661 void meson_venc_enable_vsync(struct meson_drm *priv)
1663 writel_relaxed(2, priv->io_base + _REG(VENC_INTCTRL));
1664 regmap_update_bits(priv->hhi, HHI_GCLK_MPEG2, BIT(25), BIT(25));
1667 void meson_venc_disable_vsync(struct meson_drm *priv)
1669 regmap_update_bits(priv->hhi, HHI_GCLK_MPEG2, BIT(25), 0);
1670 writel_relaxed(0, priv->io_base + _REG(VENC_INTCTRL));
1673 void meson_venc_init(struct meson_drm *priv)
1675 /* Disable CVBS VDAC */
1676 regmap_write(priv->hhi, HHI_VDAC_CNTL0, 0);
1677 regmap_write(priv->hhi, HHI_VDAC_CNTL1, 8);
1679 /* Power Down Dacs */
1680 writel_relaxed(0xff, priv->io_base + _REG(VENC_VDAC_SETTING));
1682 /* Disable HDMI PHY */
1683 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, 0);
1686 writel_bits_relaxed(0x3, 0,
1687 priv->io_base + _REG(VPU_HDMI_SETTING));
1689 /* Disable all encoders */
1690 writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_EN));
1691 writel_relaxed(0, priv->io_base + _REG(ENCP_VIDEO_EN));
1692 writel_relaxed(0, priv->io_base + _REG(ENCL_VIDEO_EN));
1694 /* Disable VSync IRQ */
1695 meson_venc_disable_vsync(priv);
1697 priv->venc.current_mode = MESON_VENC_MODE_NONE;