1 // SPDX-License-Identifier: GPL-2.0
3 * Amlogic Meson Video Processing Unit driver
5 * Copyright (c) 2018 BayLibre, SAS.
6 * Author: Neil Armstrong <narmstrong@baylibre.com>
15 #include "meson_vpu.h"
18 MESON_VENC_MODE_NONE = 0,
19 MESON_VENC_MODE_CVBS_PAL,
20 MESON_VENC_MODE_CVBS_NTSC,
24 enum meson_venc_source {
25 MESON_VENC_SOURCE_NONE = 0,
26 MESON_VENC_SOURCE_ENCI = 1,
27 MESON_VENC_SOURCE_ENCP = 2,
30 #define HHI_VDAC_CNTL0 0x2F4 /* 0xbd offset in data sheet */
31 #define HHI_VDAC_CNTL0_G12A 0x2EC /* 0xbb offset in data sheet */
32 #define HHI_VDAC_CNTL1 0x2F8 /* 0xbe offset in data sheet */
33 #define HHI_VDAC_CNTL1_G12A 0x2F0 /* 0xbc offset in data sheet */
35 struct meson_cvbs_enci_mode {
36 unsigned int mode_tag;
37 unsigned int hso_begin; /* HSO begin position */
38 unsigned int hso_end; /* HSO end position */
39 unsigned int vso_even; /* VSO even line */
40 unsigned int vso_odd; /* VSO odd line */
41 unsigned int macv_max_amp; /* Macrovision max amplitude */
42 unsigned int video_prog_mode;
43 unsigned int video_mode;
44 unsigned int sch_adjust;
45 unsigned int yc_delay;
46 unsigned int pixel_start;
47 unsigned int pixel_end;
48 unsigned int top_field_line_start;
49 unsigned int top_field_line_end;
50 unsigned int bottom_field_line_start;
51 unsigned int bottom_field_line_end;
52 unsigned int video_saturation;
53 unsigned int video_contrast;
54 unsigned int video_brightness;
55 unsigned int video_hue;
56 unsigned int analog_sync_adj;
59 struct meson_cvbs_enci_mode meson_cvbs_enci_pal = {
60 .mode_tag = MESON_VENC_MODE_CVBS_PAL,
66 .video_prog_mode = 0xff,
72 .top_field_line_start = 22,
73 .top_field_line_end = 310,
74 .bottom_field_line_start = 23,
75 .bottom_field_line_end = 311,
76 .video_saturation = 9,
78 .video_brightness = 0,
80 .analog_sync_adj = 0x8080,
83 struct meson_cvbs_enci_mode meson_cvbs_enci_ntsc = {
84 .mode_tag = MESON_VENC_MODE_CVBS_NTSC,
90 .video_prog_mode = 0xf0,
96 .top_field_line_start = 18,
97 .top_field_line_end = 258,
98 .bottom_field_line_start = 19,
99 .bottom_field_line_end = 259,
100 .video_saturation = 18,
102 .video_brightness = 0,
104 .analog_sync_adj = 0x9c00,
107 union meson_hdmi_venc_mode {
109 unsigned int mode_tag;
110 unsigned int hso_begin;
111 unsigned int hso_end;
112 unsigned int vso_even;
113 unsigned int vso_odd;
114 unsigned int macv_max_amp;
115 unsigned int video_prog_mode;
116 unsigned int video_mode;
117 unsigned int sch_adjust;
118 unsigned int yc_delay;
119 unsigned int pixel_start;
120 unsigned int pixel_end;
121 unsigned int top_field_line_start;
122 unsigned int top_field_line_end;
123 unsigned int bottom_field_line_start;
124 unsigned int bottom_field_line_end;
127 unsigned int dvi_settings;
128 unsigned int video_mode;
129 unsigned int video_mode_adv;
130 unsigned int video_prog_mode;
131 bool video_prog_mode_present;
132 unsigned int video_sync_mode;
133 bool video_sync_mode_present;
134 unsigned int video_yc_dly;
135 bool video_yc_dly_present;
136 unsigned int video_rgb_ctrl;
137 bool video_rgb_ctrl_present;
138 unsigned int video_filt_ctrl;
139 bool video_filt_ctrl_present;
140 unsigned int video_ofld_voav_ofst;
141 bool video_ofld_voav_ofst_present;
142 unsigned int yfp1_htime;
143 unsigned int yfp2_htime;
144 unsigned int max_pxcnt;
145 unsigned int hspuls_begin;
146 unsigned int hspuls_end;
147 unsigned int hspuls_switch;
148 unsigned int vspuls_begin;
149 unsigned int vspuls_end;
150 unsigned int vspuls_bline;
151 unsigned int vspuls_eline;
152 unsigned int eqpuls_begin;
153 bool eqpuls_begin_present;
154 unsigned int eqpuls_end;
155 bool eqpuls_end_present;
156 unsigned int eqpuls_bline;
157 bool eqpuls_bline_present;
158 unsigned int eqpuls_eline;
159 bool eqpuls_eline_present;
160 unsigned int havon_begin;
161 unsigned int havon_end;
162 unsigned int vavon_bline;
163 unsigned int vavon_eline;
164 unsigned int hso_begin;
165 unsigned int hso_end;
166 unsigned int vso_begin;
167 unsigned int vso_end;
168 unsigned int vso_bline;
169 unsigned int vso_eline;
170 bool vso_eline_present;
173 unsigned int sy2_val;
174 bool sy2_val_present;
175 unsigned int max_lncnt;
179 union meson_hdmi_venc_mode meson_hdmi_enci_mode_480i = {
186 .video_prog_mode = 0xf0,
192 .top_field_line_start = 18,
193 .top_field_line_end = 258,
194 .bottom_field_line_start = 19,
195 .bottom_field_line_end = 259,
199 union meson_hdmi_venc_mode meson_hdmi_enci_mode_576i = {
206 .video_prog_mode = 0xff,
212 .top_field_line_start = 22,
213 .top_field_line_end = 310,
214 .bottom_field_line_start = 23,
215 .bottom_field_line_end = 311,
219 union meson_hdmi_venc_mode meson_hdmi_encp_mode_480p = {
221 .dvi_settings = 0x21,
222 .video_mode = 0x4000,
223 .video_mode_adv = 0x9,
224 .video_prog_mode = 0,
225 .video_prog_mode_present = true,
226 .video_sync_mode = 7,
227 .video_sync_mode_present = true,
230 .video_filt_ctrl = 0x2052,
231 .video_filt_ctrl_present = true,
232 /* video_ofld_voav_ofst */
236 .hspuls_begin = 0x22,
258 .sy_val_present = true,
260 .sy2_val_present = true,
265 union meson_hdmi_venc_mode meson_hdmi_encp_mode_576p = {
267 .dvi_settings = 0x21,
268 .video_mode = 0x4000,
269 .video_mode_adv = 0x9,
270 .video_prog_mode = 0,
271 .video_prog_mode_present = true,
272 .video_sync_mode = 7,
273 .video_sync_mode_present = true,
276 .video_filt_ctrl = 0x52,
277 .video_filt_ctrl_present = true,
278 /* video_ofld_voav_ofst */
304 .sy_val_present = true,
306 .sy2_val_present = true,
311 union meson_hdmi_venc_mode meson_hdmi_encp_mode_720p60 = {
313 .dvi_settings = 0x2029,
314 .video_mode = 0x4040,
315 .video_mode_adv = 0x19,
316 /* video_prog_mode */
317 /* video_sync_mode */
320 /* video_filt_ctrl */
321 /* video_ofld_voav_ofst */
346 .vso_eline_present = true,
353 union meson_hdmi_venc_mode meson_hdmi_encp_mode_720p50 = {
355 .dvi_settings = 0x202d,
356 .video_mode = 0x4040,
357 .video_mode_adv = 0x19,
358 .video_prog_mode = 0x100,
359 .video_prog_mode_present = true,
360 .video_sync_mode = 0x407,
361 .video_sync_mode_present = true,
363 .video_yc_dly_present = true,
365 /* video_filt_ctrl */
366 /* video_ofld_voav_ofst */
391 .vso_eline_present = true,
398 union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080i60 = {
400 .dvi_settings = 0x2029,
401 .video_mode = 0x5ffc,
402 .video_mode_adv = 0x19,
403 .video_prog_mode = 0x100,
404 .video_prog_mode_present = true,
405 .video_sync_mode = 0x207,
406 .video_sync_mode_present = true,
409 /* video_filt_ctrl */
410 .video_ofld_voav_ofst = 0x11,
411 .video_ofld_voav_ofst_present = true,
426 .eqpuls_begin = 2288,
427 .eqpuls_begin_present = true,
429 .eqpuls_end_present = true,
431 .eqpuls_bline_present = true,
433 .eqpuls_eline_present = true,
440 .vso_eline_present = true,
447 union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080i50 = {
449 .dvi_settings = 0x202d,
450 .video_mode = 0x5ffc,
451 .video_mode_adv = 0x19,
452 .video_prog_mode = 0x100,
453 .video_prog_mode_present = true,
454 .video_sync_mode = 0x7,
455 .video_sync_mode_present = true,
458 /* video_filt_ctrl */
459 .video_ofld_voav_ofst = 0x11,
460 .video_ofld_voav_ofst_present = true,
475 .eqpuls_begin = 2288,
476 .eqpuls_begin_present = true,
478 .eqpuls_end_present = true,
480 .eqpuls_bline_present = true,
482 .eqpuls_eline_present = true,
489 .vso_eline_present = true,
496 union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080p24 = {
499 .video_mode = 0x4040,
500 .video_mode_adv = 0x18,
501 .video_prog_mode = 0x100,
502 .video_prog_mode_present = true,
503 .video_sync_mode = 0x7,
504 .video_sync_mode_present = true,
506 .video_yc_dly_present = true,
508 .video_rgb_ctrl_present = true,
509 .video_filt_ctrl = 0x1052,
510 .video_filt_ctrl_present = true,
511 /* video_ofld_voav_ofst */
529 .eqpuls_bline_present = true,
531 .eqpuls_eline_present = true,
538 .vso_eline_present = true,
545 union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080p30 = {
548 .video_mode = 0x4040,
549 .video_mode_adv = 0x18,
550 .video_prog_mode = 0x100,
551 .video_prog_mode_present = true,
552 /* video_sync_mode */
555 .video_filt_ctrl = 0x1052,
556 .video_filt_ctrl_present = true,
557 /* video_ofld_voav_ofst */
561 .hspuls_begin = 2156,
582 .vso_eline_present = true,
589 union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080p50 = {
592 .video_mode = 0x4040,
593 .video_mode_adv = 0x18,
594 .video_prog_mode = 0x100,
595 .video_prog_mode_present = true,
596 .video_sync_mode = 0x7,
597 .video_sync_mode_present = true,
599 .video_yc_dly_present = true,
601 .video_rgb_ctrl_present = true,
602 /* video_filt_ctrl */
603 /* video_ofld_voav_ofst */
621 .eqpuls_bline_present = true,
623 .eqpuls_eline_present = true,
630 .vso_eline_present = true,
637 union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080p60 = {
640 .video_mode = 0x4040,
641 .video_mode_adv = 0x18,
642 .video_prog_mode = 0x100,
643 .video_prog_mode_present = true,
644 /* video_sync_mode */
647 .video_filt_ctrl = 0x1052,
648 .video_filt_ctrl_present = true,
649 /* video_ofld_voav_ofst */
653 .hspuls_begin = 2156,
674 .vso_eline_present = true,
681 static signed int to_signed(unsigned int a)
689 static unsigned long modulo(unsigned long a, unsigned long b)
697 bool meson_venc_hdmi_supported_mode(const struct display_timing *mode)
699 if (mode->flags & ~(DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_HSYNC_HIGH |
700 DISPLAY_FLAGS_VSYNC_LOW | DISPLAY_FLAGS_VSYNC_HIGH))
703 if (mode->hactive.typ < 640 || mode->hactive.typ > 1920)
706 if (mode->vactive.typ < 480 || mode->vactive.typ > 1200)
712 static void meson_venc_hdmi_get_dmt_vmode(const struct display_timing *mode,
713 union meson_hdmi_venc_mode *dmt_mode)
715 memset(dmt_mode, 0, sizeof(*dmt_mode));
717 dmt_mode->encp.dvi_settings = 0x21;
718 dmt_mode->encp.video_mode = 0x4040;
719 dmt_mode->encp.video_mode_adv = 0x18;
721 dmt_mode->encp.max_pxcnt = mode->hactive.typ +
722 mode->hfront_porch.typ +
723 mode->hback_porch.typ +
724 mode->hsync_len.typ - 1;
726 dmt_mode->encp.havon_begin = mode->hback_porch.typ +
729 dmt_mode->encp.havon_end = dmt_mode->encp.havon_begin +
730 mode->hactive.typ - 1;
732 dmt_mode->encp.vavon_bline = mode->vback_porch.typ +
734 dmt_mode->encp.vavon_eline = dmt_mode->encp.vavon_bline +
735 mode->vactive.typ - 1;
738 dmt_mode->encp.hso_begin = 0;
739 dmt_mode->encp.hso_end = mode->hsync_len.typ;
740 dmt_mode->encp.vso_begin = 30;
741 dmt_mode->encp.vso_end = 50;
743 dmt_mode->encp.vso_bline = 0;
744 dmt_mode->encp.vso_eline = mode->vsync_len.typ;
745 dmt_mode->encp.vso_eline_present = true;
747 dmt_mode->encp.max_lncnt = mode->vactive.typ +
748 mode->vfront_porch.typ +
749 mode->vback_porch.typ +
750 mode->vsync_len.typ - 1;
753 static void meson_venc_hdmi_mode_set(struct meson_vpu_priv *priv,
754 const struct display_timing *mode)
756 union meson_hdmi_venc_mode *vmode = NULL;
757 union meson_hdmi_venc_mode vmode_dmt;
758 bool use_enci = false;
759 bool venc_repeat = false;
760 bool hdmi_repeat = false;
761 unsigned int venc_hdmi_latency = 2;
762 unsigned long total_pixels_venc = 0;
763 unsigned long active_pixels_venc = 0;
764 unsigned long front_porch_venc = 0;
765 unsigned long hsync_pixels_venc = 0;
766 unsigned long de_h_begin = 0;
767 unsigned long de_h_end = 0;
768 unsigned long de_v_begin_even = 0;
769 unsigned long de_v_end_even = 0;
770 unsigned long de_v_begin_odd = 0;
771 unsigned long de_v_end_odd = 0;
772 unsigned long hs_begin = 0;
773 unsigned long hs_end = 0;
774 unsigned long vs_adjust = 0;
775 unsigned long vs_bline_evn = 0;
776 unsigned long vs_eline_evn = 0;
777 unsigned long vs_bline_odd = 0;
778 unsigned long vs_eline_odd = 0;
779 unsigned long vso_begin_evn = 0;
780 unsigned long vso_begin_odd = 0;
781 unsigned int eof_lines;
782 unsigned int sof_lines;
783 unsigned int vsync_lines;
786 /* Use VENCI for 480i and 576i and double HDMI pixels */
787 if (mode->flags & DISPLAY_FLAGS_DOUBLECLK) {
790 venc_hdmi_latency = 1;
793 meson_venc_hdmi_get_dmt_vmode(mode, &vmode_dmt);
797 debug(" max_pxcnt %04d, max_lncnt %04d\n"
798 " havon_begin %04d, havon_end %04d\n"
799 " vavon_bline %04d, vavon_eline %04d\n"
800 " hso_begin %04d, hso_end %04d\n"
801 " vso_begin %04d, vso_end %04d\n"
802 " vso_bline %04d, vso_eline %04d\n",
803 vmode->encp.max_pxcnt, vmode->encp.max_lncnt,
804 vmode->encp.havon_begin, vmode->encp.havon_end,
805 vmode->encp.vavon_bline, vmode->encp.vavon_eline,
806 vmode->encp.hso_begin, vmode->encp.hso_end,
807 vmode->encp.vso_begin, vmode->encp.vso_end,
808 vmode->encp.vso_bline, vmode->encp.vso_eline);
810 eof_lines = mode->vfront_porch.typ;
811 if (mode->flags & DISPLAY_FLAGS_INTERLACED)
814 sof_lines = mode->vback_porch.typ;
815 if (mode->flags & DISPLAY_FLAGS_INTERLACED)
818 vsync_lines = mode->vsync_len.typ;
819 if (mode->flags & DISPLAY_FLAGS_INTERLACED)
822 total_pixels_venc = mode->hback_porch.typ + mode->hactive.typ +
823 mode->hfront_porch.typ + mode->hsync_len.typ;
825 total_pixels_venc /= 2;
827 total_pixels_venc *= 2;
829 active_pixels_venc = mode->hactive.typ;
831 active_pixels_venc /= 2;
833 active_pixels_venc *= 2;
835 front_porch_venc = mode->hfront_porch.typ;
837 front_porch_venc /= 2;
839 front_porch_venc *= 2;
841 hsync_pixels_venc = mode->hsync_len.typ;
843 hsync_pixels_venc /= 2;
845 hsync_pixels_venc *= 2;
848 writel_bits(0xff, 0xff,
849 priv->io_base + _REG(VENC_VDAC_SETTING));
851 writel(0, priv->io_base + _REG(ENCI_VIDEO_EN));
852 writel(0, priv->io_base + _REG(ENCP_VIDEO_EN));
854 debug("use_enci: %d, hdmi_repeat: %d\n", use_enci, hdmi_repeat);
857 unsigned int lines_f0;
858 unsigned int lines_f1;
860 /* CVBS Filter settings */
861 writel(ENCI_CFILT_CMPT_SEL_HIGH | 0x10,
862 priv->io_base + _REG(ENCI_CFILT_CTRL));
863 writel(ENCI_CFILT_CMPT_CR_DLY(2) |
864 ENCI_CFILT_CMPT_CB_DLY(1),
865 priv->io_base + _REG(ENCI_CFILT_CTRL2));
867 /* Digital Video Select : Interlace, clk27 clk, external */
868 writel(0, priv->io_base + _REG(VENC_DVI_SETTING));
870 /* Reset Video Mode */
871 writel(0, priv->io_base + _REG(ENCI_VIDEO_MODE));
872 writel(0, priv->io_base + _REG(ENCI_VIDEO_MODE_ADV));
874 /* Horizontal sync signal output */
875 writel(vmode->enci.hso_begin,
876 priv->io_base + _REG(ENCI_SYNC_HSO_BEGIN));
877 writel(vmode->enci.hso_end,
878 priv->io_base + _REG(ENCI_SYNC_HSO_END));
880 /* Vertical Sync lines */
881 writel(vmode->enci.vso_even,
882 priv->io_base + _REG(ENCI_SYNC_VSO_EVNLN));
883 writel(vmode->enci.vso_odd,
884 priv->io_base + _REG(ENCI_SYNC_VSO_ODDLN));
886 /* Macrovision max amplitude change */
887 writel(ENCI_MACV_MAX_AMP_ENABLE_CHANGE |
888 ENCI_MACV_MAX_AMP_VAL(vmode->enci.macv_max_amp),
889 priv->io_base + _REG(ENCI_MACV_MAX_AMP));
892 writel(vmode->enci.video_prog_mode,
893 priv->io_base + _REG(VENC_VIDEO_PROG_MODE));
894 writel(vmode->enci.video_mode,
895 priv->io_base + _REG(ENCI_VIDEO_MODE));
898 * Advanced Video Mode :
900 * Blank line end at line17/22
901 * High bandwidth Luma Filter
902 * Low bandwidth Chroma Filter
903 * Bypass luma low pass filter
904 * No macrovision on CSYNC
906 writel(ENCI_VIDEO_MODE_ADV_DMXMD(2) |
907 ENCI_VIDEO_MODE_ADV_VBICTL_LINE_17_22 |
908 ENCI_VIDEO_MODE_ADV_YBW_HIGH,
909 priv->io_base + _REG(ENCI_VIDEO_MODE_ADV));
911 writel(vmode->enci.sch_adjust,
912 priv->io_base + _REG(ENCI_VIDEO_SCH));
914 /* Sync mode : MASTER Master mode, free run, send HSO/VSO out */
915 writel(0x07, priv->io_base + _REG(ENCI_SYNC_MODE));
917 if (vmode->enci.yc_delay)
918 writel(vmode->enci.yc_delay,
919 priv->io_base + _REG(ENCI_YC_DELAY));
921 /* UNreset Interlaced TV Encoder */
922 writel(0, priv->io_base + _REG(ENCI_DBG_PX_RST));
925 * Enable Vfifo2vd and set Y_Cb_Y_Cr:
926 * Corresponding value:
930 * Ex: 0x4e => 01001110 would mean Cb/Y/Cr/Y
932 writel(ENCI_VFIFO2VD_CTL_ENABLE |
933 ENCI_VFIFO2VD_CTL_VD_SEL(0x4e),
934 priv->io_base + _REG(ENCI_VFIFO2VD_CTL));
937 writel(vmode->enci.pixel_start,
938 priv->io_base + _REG(ENCI_VFIFO2VD_PIXEL_START));
939 writel(vmode->enci.pixel_end,
940 priv->io_base + _REG(ENCI_VFIFO2VD_PIXEL_END));
942 writel(vmode->enci.top_field_line_start,
943 priv->io_base + _REG(ENCI_VFIFO2VD_LINE_TOP_START));
944 writel(vmode->enci.top_field_line_end,
945 priv->io_base + _REG(ENCI_VFIFO2VD_LINE_TOP_END));
947 writel(vmode->enci.bottom_field_line_start,
948 priv->io_base + _REG(ENCI_VFIFO2VD_LINE_BOT_START));
949 writel(vmode->enci.bottom_field_line_end,
950 priv->io_base + _REG(ENCI_VFIFO2VD_LINE_BOT_END));
952 /* Select ENCI for VIU */
953 meson_vpp_setup_mux(priv, MESON_VIU_VPP_MUX_ENCI);
955 /* Interlace video enable */
956 writel(ENCI_VIDEO_EN_ENABLE,
957 priv->io_base + _REG(ENCI_VIDEO_EN));
959 lines_f0 = mode->vback_porch.typ + mode->vactive.typ +
960 mode->vback_porch.typ + mode->vsync_len.typ;
961 lines_f0 = lines_f0 >> 1;
962 lines_f1 = lines_f0 + 1;
964 de_h_begin = modulo(readl(priv->io_base +
965 _REG(ENCI_VFIFO2VD_PIXEL_START))
968 de_h_end = modulo(de_h_begin + active_pixels_venc,
972 priv->io_base + _REG(ENCI_DE_H_BEGIN));
974 priv->io_base + _REG(ENCI_DE_H_END));
976 de_v_begin_even = readl(priv->io_base +
977 _REG(ENCI_VFIFO2VD_LINE_TOP_START));
978 de_v_end_even = de_v_begin_even + mode->vactive.typ;
979 de_v_begin_odd = readl(priv->io_base +
980 _REG(ENCI_VFIFO2VD_LINE_BOT_START));
981 de_v_end_odd = de_v_begin_odd + mode->vactive.typ;
983 writel(de_v_begin_even,
984 priv->io_base + _REG(ENCI_DE_V_BEGIN_EVEN));
985 writel(de_v_end_even,
986 priv->io_base + _REG(ENCI_DE_V_END_EVEN));
987 writel(de_v_begin_odd,
988 priv->io_base + _REG(ENCI_DE_V_BEGIN_ODD));
990 priv->io_base + _REG(ENCI_DE_V_END_ODD));
992 /* Program Hsync timing */
993 hs_begin = de_h_end + front_porch_venc;
994 if (de_h_end + front_porch_venc >= total_pixels_venc) {
995 hs_begin -= total_pixels_venc;
998 hs_begin = de_h_end + front_porch_venc;
1002 hs_end = modulo(hs_begin + hsync_pixels_venc,
1005 priv->io_base + _REG(ENCI_DVI_HSO_BEGIN));
1007 priv->io_base + _REG(ENCI_DVI_HSO_END));
1009 /* Program Vsync timing for even field */
1010 if (((de_v_end_odd - 1) + eof_lines + vs_adjust) >= lines_f1) {
1011 vs_bline_evn = (de_v_end_odd - 1)
1015 vs_eline_evn = vs_bline_evn + vsync_lines;
1017 writel(vs_bline_evn,
1018 priv->io_base + _REG(ENCI_DVI_VSO_BLINE_EVN));
1020 writel(vs_eline_evn,
1021 priv->io_base + _REG(ENCI_DVI_VSO_ELINE_EVN));
1024 priv->io_base + _REG(ENCI_DVI_VSO_BEGIN_EVN));
1026 priv->io_base + _REG(ENCI_DVI_VSO_END_EVN));
1028 vs_bline_odd = (de_v_end_odd - 1)
1032 writel(vs_bline_odd,
1033 priv->io_base + _REG(ENCI_DVI_VSO_BLINE_ODD));
1036 priv->io_base + _REG(ENCI_DVI_VSO_BEGIN_ODD));
1038 if ((vs_bline_odd + vsync_lines) >= lines_f1) {
1039 vs_eline_evn = vs_bline_odd
1043 writel(vs_eline_evn, priv->io_base
1044 + _REG(ENCI_DVI_VSO_ELINE_EVN));
1046 writel(hs_begin, priv->io_base
1047 + _REG(ENCI_DVI_VSO_END_EVN));
1049 vs_eline_odd = vs_bline_odd
1052 writel(vs_eline_odd, priv->io_base
1053 + _REG(ENCI_DVI_VSO_ELINE_ODD));
1055 writel(hs_begin, priv->io_base
1056 + _REG(ENCI_DVI_VSO_END_ODD));
1060 /* Program Vsync timing for odd field */
1061 if (((de_v_end_even - 1) + (eof_lines + 1)) >= lines_f0) {
1062 vs_bline_odd = (de_v_end_even - 1)
1065 vs_eline_odd = vs_bline_odd + vsync_lines;
1067 writel(vs_bline_odd,
1068 priv->io_base + _REG(ENCI_DVI_VSO_BLINE_ODD));
1070 writel(vs_eline_odd,
1071 priv->io_base + _REG(ENCI_DVI_VSO_ELINE_ODD));
1073 vso_begin_odd = modulo(hs_begin
1074 + (total_pixels_venc >> 1),
1077 writel(vso_begin_odd,
1078 priv->io_base + _REG(ENCI_DVI_VSO_BEGIN_ODD));
1079 writel(vso_begin_odd,
1080 priv->io_base + _REG(ENCI_DVI_VSO_END_ODD));
1082 vs_bline_evn = (de_v_end_even - 1)
1085 writel(vs_bline_evn,
1086 priv->io_base + _REG(ENCI_DVI_VSO_BLINE_EVN));
1088 vso_begin_evn = modulo(hs_begin
1089 + (total_pixels_venc >> 1),
1092 writel(vso_begin_evn, priv->io_base
1093 + _REG(ENCI_DVI_VSO_BEGIN_EVN));
1095 if (vs_bline_evn + vsync_lines >= lines_f0) {
1096 vs_eline_odd = vs_bline_evn
1100 writel(vs_eline_odd, priv->io_base
1101 + _REG(ENCI_DVI_VSO_ELINE_ODD));
1103 writel(vso_begin_evn, priv->io_base
1104 + _REG(ENCI_DVI_VSO_END_ODD));
1106 vs_eline_evn = vs_bline_evn + vsync_lines;
1108 writel(vs_eline_evn, priv->io_base
1109 + _REG(ENCI_DVI_VSO_ELINE_EVN));
1111 writel(vso_begin_evn, priv->io_base
1112 + _REG(ENCI_DVI_VSO_END_EVN));
1116 writel(vmode->encp.dvi_settings,
1117 priv->io_base + _REG(VENC_DVI_SETTING));
1118 writel(vmode->encp.video_mode,
1119 priv->io_base + _REG(ENCP_VIDEO_MODE));
1120 writel(vmode->encp.video_mode_adv,
1121 priv->io_base + _REG(ENCP_VIDEO_MODE_ADV));
1122 if (vmode->encp.video_prog_mode_present)
1123 writel(vmode->encp.video_prog_mode,
1124 priv->io_base + _REG(VENC_VIDEO_PROG_MODE));
1125 if (vmode->encp.video_sync_mode_present)
1126 writel(vmode->encp.video_sync_mode,
1127 priv->io_base + _REG(ENCP_VIDEO_SYNC_MODE));
1128 if (vmode->encp.video_yc_dly_present)
1129 writel(vmode->encp.video_yc_dly,
1130 priv->io_base + _REG(ENCP_VIDEO_YC_DLY));
1131 if (vmode->encp.video_rgb_ctrl_present)
1132 writel(vmode->encp.video_rgb_ctrl,
1133 priv->io_base + _REG(ENCP_VIDEO_RGB_CTRL));
1134 if (vmode->encp.video_filt_ctrl_present)
1135 writel(vmode->encp.video_filt_ctrl,
1136 priv->io_base + _REG(ENCP_VIDEO_FILT_CTRL));
1137 if (vmode->encp.video_ofld_voav_ofst_present)
1138 writel(vmode->encp.video_ofld_voav_ofst,
1140 + _REG(ENCP_VIDEO_OFLD_VOAV_OFST));
1141 writel(vmode->encp.yfp1_htime,
1142 priv->io_base + _REG(ENCP_VIDEO_YFP1_HTIME));
1143 writel(vmode->encp.yfp2_htime,
1144 priv->io_base + _REG(ENCP_VIDEO_YFP2_HTIME));
1145 writel(vmode->encp.max_pxcnt,
1146 priv->io_base + _REG(ENCP_VIDEO_MAX_PXCNT));
1147 writel(vmode->encp.hspuls_begin,
1148 priv->io_base + _REG(ENCP_VIDEO_HSPULS_BEGIN));
1149 writel(vmode->encp.hspuls_end,
1150 priv->io_base + _REG(ENCP_VIDEO_HSPULS_END));
1151 writel(vmode->encp.hspuls_switch,
1152 priv->io_base + _REG(ENCP_VIDEO_HSPULS_SWITCH));
1153 writel(vmode->encp.vspuls_begin,
1154 priv->io_base + _REG(ENCP_VIDEO_VSPULS_BEGIN));
1155 writel(vmode->encp.vspuls_end,
1156 priv->io_base + _REG(ENCP_VIDEO_VSPULS_END));
1157 writel(vmode->encp.vspuls_bline,
1158 priv->io_base + _REG(ENCP_VIDEO_VSPULS_BLINE));
1159 writel(vmode->encp.vspuls_eline,
1160 priv->io_base + _REG(ENCP_VIDEO_VSPULS_ELINE));
1161 if (vmode->encp.eqpuls_begin_present)
1162 writel(vmode->encp.eqpuls_begin,
1163 priv->io_base + _REG(ENCP_VIDEO_EQPULS_BEGIN));
1164 if (vmode->encp.eqpuls_end_present)
1165 writel(vmode->encp.eqpuls_end,
1166 priv->io_base + _REG(ENCP_VIDEO_EQPULS_END));
1167 if (vmode->encp.eqpuls_bline_present)
1168 writel(vmode->encp.eqpuls_bline,
1169 priv->io_base + _REG(ENCP_VIDEO_EQPULS_BLINE));
1170 if (vmode->encp.eqpuls_eline_present)
1171 writel(vmode->encp.eqpuls_eline,
1172 priv->io_base + _REG(ENCP_VIDEO_EQPULS_ELINE));
1173 writel(vmode->encp.havon_begin,
1174 priv->io_base + _REG(ENCP_VIDEO_HAVON_BEGIN));
1175 writel(vmode->encp.havon_end,
1176 priv->io_base + _REG(ENCP_VIDEO_HAVON_END));
1177 writel(vmode->encp.vavon_bline,
1178 priv->io_base + _REG(ENCP_VIDEO_VAVON_BLINE));
1179 writel(vmode->encp.vavon_eline,
1180 priv->io_base + _REG(ENCP_VIDEO_VAVON_ELINE));
1181 writel(vmode->encp.hso_begin,
1182 priv->io_base + _REG(ENCP_VIDEO_HSO_BEGIN));
1183 writel(vmode->encp.hso_end,
1184 priv->io_base + _REG(ENCP_VIDEO_HSO_END));
1185 writel(vmode->encp.vso_begin,
1186 priv->io_base + _REG(ENCP_VIDEO_VSO_BEGIN));
1187 writel(vmode->encp.vso_end,
1188 priv->io_base + _REG(ENCP_VIDEO_VSO_END));
1189 writel(vmode->encp.vso_bline,
1190 priv->io_base + _REG(ENCP_VIDEO_VSO_BLINE));
1191 if (vmode->encp.vso_eline_present)
1192 writel(vmode->encp.vso_eline,
1193 priv->io_base + _REG(ENCP_VIDEO_VSO_ELINE));
1194 if (vmode->encp.sy_val_present)
1195 writel(vmode->encp.sy_val,
1196 priv->io_base + _REG(ENCP_VIDEO_SY_VAL));
1197 if (vmode->encp.sy2_val_present)
1198 writel(vmode->encp.sy2_val,
1199 priv->io_base + _REG(ENCP_VIDEO_SY2_VAL));
1200 writel(vmode->encp.max_lncnt,
1201 priv->io_base + _REG(ENCP_VIDEO_MAX_LNCNT));
1203 writel(1, priv->io_base + _REG(ENCP_VIDEO_EN));
1205 /* Set DE signal's polarity is active high */
1206 writel_bits(ENCP_VIDEO_MODE_DE_V_HIGH,
1207 ENCP_VIDEO_MODE_DE_V_HIGH,
1208 priv->io_base + _REG(ENCP_VIDEO_MODE));
1210 /* Program DE timing */
1211 de_h_begin = modulo(readl(priv->io_base +
1212 _REG(ENCP_VIDEO_HAVON_BEGIN))
1213 + venc_hdmi_latency,
1215 de_h_end = modulo(de_h_begin + active_pixels_venc,
1219 priv->io_base + _REG(ENCP_DE_H_BEGIN));
1221 priv->io_base + _REG(ENCP_DE_H_END));
1223 /* Program DE timing for even field */
1224 de_v_begin_even = readl(priv->io_base
1225 + _REG(ENCP_VIDEO_VAVON_BLINE));
1226 if (mode->flags & DISPLAY_FLAGS_INTERLACED)
1227 de_v_end_even = de_v_begin_even +
1228 (mode->vactive.typ / 2);
1230 de_v_end_even = de_v_begin_even + mode->vactive.typ;
1232 writel(de_v_begin_even,
1233 priv->io_base + _REG(ENCP_DE_V_BEGIN_EVEN));
1234 writel(de_v_end_even,
1235 priv->io_base + _REG(ENCP_DE_V_END_EVEN));
1237 /* Program DE timing for odd field if needed */
1238 if (mode->flags & DISPLAY_FLAGS_INTERLACED) {
1239 unsigned int ofld_voav_ofst =
1240 readl(priv->io_base +
1241 _REG(ENCP_VIDEO_OFLD_VOAV_OFST));
1242 de_v_begin_odd = to_signed((ofld_voav_ofst & 0xf0) >> 4)
1244 + ((mode->vfront_porch.typ +
1246 mode->vsync_len.typ - 1) / 2);
1247 de_v_end_odd = de_v_begin_odd + (mode->vactive.typ / 2);
1249 writel(de_v_begin_odd,
1250 priv->io_base + _REG(ENCP_DE_V_BEGIN_ODD));
1251 writel(de_v_end_odd,
1252 priv->io_base + _REG(ENCP_DE_V_END_ODD));
1255 /* Program Hsync timing */
1256 if ((de_h_end + front_porch_venc) >= total_pixels_venc) {
1259 - total_pixels_venc;
1267 hs_end = modulo(hs_begin + hsync_pixels_venc,
1271 priv->io_base + _REG(ENCP_DVI_HSO_BEGIN));
1273 priv->io_base + _REG(ENCP_DVI_HSO_END));
1275 /* Program Vsync timing for even field */
1276 if (de_v_begin_even >=
1277 (sof_lines + vsync_lines + (1 - vs_adjust)))
1278 vs_bline_evn = de_v_begin_even
1283 vs_bline_evn = (mode->vfront_porch.typ +
1285 mode->vsync_len.typ) +
1291 vs_eline_evn = modulo(vs_bline_evn + vsync_lines,
1292 mode->hfront_porch.typ +
1294 mode->hsync_len.typ);
1296 writel(vs_bline_evn,
1297 priv->io_base + _REG(ENCP_DVI_VSO_BLINE_EVN));
1298 writel(vs_eline_evn,
1299 priv->io_base + _REG(ENCP_DVI_VSO_ELINE_EVN));
1301 vso_begin_evn = hs_begin;
1302 writel(vso_begin_evn,
1303 priv->io_base + _REG(ENCP_DVI_VSO_BEGIN_EVN));
1304 writel(vso_begin_evn,
1305 priv->io_base + _REG(ENCP_DVI_VSO_END_EVN));
1307 /* Program Vsync timing for odd field if needed */
1308 if (mode->flags & DISPLAY_FLAGS_INTERLACED) {
1309 vs_bline_odd = (de_v_begin_odd - 1)
1312 vs_eline_odd = (de_v_begin_odd - 1)
1314 vso_begin_odd = modulo(hs_begin
1315 + (total_pixels_venc >> 1),
1318 writel(vs_bline_odd,
1319 priv->io_base + _REG(ENCP_DVI_VSO_BLINE_ODD));
1320 writel(vs_eline_odd,
1321 priv->io_base + _REG(ENCP_DVI_VSO_ELINE_ODD));
1322 writel(vso_begin_odd,
1323 priv->io_base + _REG(ENCP_DVI_VSO_BEGIN_ODD));
1324 writel(vso_begin_odd,
1325 priv->io_base + _REG(ENCP_DVI_VSO_END_ODD));
1328 /* Select ENCP for VIU */
1329 meson_vpp_setup_mux(priv, MESON_VIU_VPP_MUX_ENCP);
1332 /* Set VPU HDMI setting */
1333 /* Select ENCP or ENCI data to HDMI */
1335 reg = VPU_HDMI_ENCI_DATA_TO_HDMI;
1337 reg = VPU_HDMI_ENCP_DATA_TO_HDMI;
1339 /* Invert polarity of HSYNC from VENC */
1340 if (mode->flags & DISPLAY_FLAGS_HSYNC_HIGH)
1341 reg |= VPU_HDMI_INV_HSYNC;
1343 /* Invert polarity of VSYNC from VENC */
1344 if (mode->flags & DISPLAY_FLAGS_VSYNC_HIGH)
1345 reg |= VPU_HDMI_INV_VSYNC;
1347 /* Output data format: CbYCr */
1348 reg |= VPU_HDMI_OUTPUT_CBYCR;
1351 * Write rate to the async FIFO between VENC and HDMI.
1352 * One write every 2 wr_clk.
1355 reg |= VPU_HDMI_WR_RATE(2);
1358 * Read rate to the async FIFO between VENC and HDMI.
1359 * One read every 2 wr_clk.
1362 reg |= VPU_HDMI_RD_RATE(2);
1364 writel(reg, priv->io_base + _REG(VPU_HDMI_SETTING));
1367 static void meson_venci_cvbs_mode_set(struct meson_vpu_priv *priv,
1368 struct meson_cvbs_enci_mode *mode)
1372 /* CVBS Filter settings */
1373 writel(ENCI_CFILT_CMPT_SEL_HIGH | 0x10,
1374 priv->io_base + _REG(ENCI_CFILT_CTRL));
1375 writel(ENCI_CFILT_CMPT_CR_DLY(2) |
1376 ENCI_CFILT_CMPT_CB_DLY(1),
1377 priv->io_base + _REG(ENCI_CFILT_CTRL2));
1379 /* Digital Video Select : Interlace, clk27 clk, external */
1380 writel(0, priv->io_base + _REG(VENC_DVI_SETTING));
1382 /* Reset Video Mode */
1383 writel(0, priv->io_base + _REG(ENCI_VIDEO_MODE));
1384 writel(0, priv->io_base + _REG(ENCI_VIDEO_MODE_ADV));
1386 /* Horizontal sync signal output */
1387 writel(mode->hso_begin,
1388 priv->io_base + _REG(ENCI_SYNC_HSO_BEGIN));
1389 writel(mode->hso_end,
1390 priv->io_base + _REG(ENCI_SYNC_HSO_END));
1392 /* Vertical Sync lines */
1393 writel(mode->vso_even,
1394 priv->io_base + _REG(ENCI_SYNC_VSO_EVNLN));
1395 writel(mode->vso_odd,
1396 priv->io_base + _REG(ENCI_SYNC_VSO_ODDLN));
1398 /* Macrovision max amplitude change */
1399 writel(ENCI_MACV_MAX_AMP_ENABLE_CHANGE |
1400 ENCI_MACV_MAX_AMP_VAL(mode->macv_max_amp),
1401 priv->io_base + _REG(ENCI_MACV_MAX_AMP));
1404 writel(mode->video_prog_mode,
1405 priv->io_base + _REG(VENC_VIDEO_PROG_MODE));
1406 writel(mode->video_mode,
1407 priv->io_base + _REG(ENCI_VIDEO_MODE));
1410 * Advanced Video Mode :
1411 * Demux shifting 0x2
1412 * Blank line end at line17/22
1413 * High bandwidth Luma Filter
1414 * Low bandwidth Chroma Filter
1415 * Bypass luma low pass filter
1416 * No macrovision on CSYNC
1418 writel(ENCI_VIDEO_MODE_ADV_DMXMD(2) |
1419 ENCI_VIDEO_MODE_ADV_VBICTL_LINE_17_22 |
1420 ENCI_VIDEO_MODE_ADV_YBW_HIGH,
1421 priv->io_base + _REG(ENCI_VIDEO_MODE_ADV));
1423 writel(mode->sch_adjust, priv->io_base + _REG(ENCI_VIDEO_SCH));
1425 /* Sync mode : MASTER Master mode, free run, send HSO/VSO out */
1426 writel(0x07, priv->io_base + _REG(ENCI_SYNC_MODE));
1428 /* 0x3 Y, C, and Component Y delay */
1429 writel(mode->yc_delay, priv->io_base + _REG(ENCI_YC_DELAY));
1432 writel(mode->pixel_start,
1433 priv->io_base + _REG(ENCI_VFIFO2VD_PIXEL_START));
1434 writel(mode->pixel_end,
1435 priv->io_base + _REG(ENCI_VFIFO2VD_PIXEL_END));
1437 writel(mode->top_field_line_start,
1438 priv->io_base + _REG(ENCI_VFIFO2VD_LINE_TOP_START));
1439 writel(mode->top_field_line_end,
1440 priv->io_base + _REG(ENCI_VFIFO2VD_LINE_TOP_END));
1442 writel(mode->bottom_field_line_start,
1443 priv->io_base + _REG(ENCI_VFIFO2VD_LINE_BOT_START));
1444 writel(mode->bottom_field_line_end,
1445 priv->io_base + _REG(ENCI_VFIFO2VD_LINE_BOT_END));
1447 /* Internal Venc, Internal VIU Sync, Internal Vencoder */
1448 writel(0, priv->io_base + _REG(VENC_SYNC_ROUTE));
1450 /* UNreset Interlaced TV Encoder */
1451 writel(0, priv->io_base + _REG(ENCI_DBG_PX_RST));
1454 * Enable Vfifo2vd and set Y_Cb_Y_Cr:
1455 * Corresponding value:
1459 * Ex: 0x4e => 01001110 would mean Cb/Y/Cr/Y
1461 writel(ENCI_VFIFO2VD_CTL_ENABLE |
1462 ENCI_VFIFO2VD_CTL_VD_SEL(0x4e),
1463 priv->io_base + _REG(ENCI_VFIFO2VD_CTL));
1466 writel(0, priv->io_base + _REG(VENC_VDAC_SETTING));
1468 /* Video Upsampling */
1470 * CTRL0, CTRL1 and CTRL2:
1471 * Filter0: input data sample every 2 cloks
1472 * Filter1: filtering and upsample enable
1474 reg = VENC_UPSAMPLE_CTRL_F0_2_CLK_RATIO | VENC_UPSAMPLE_CTRL_F1_EN |
1475 VENC_UPSAMPLE_CTRL_F1_UPSAMPLE_EN;
1479 * Interlace High Bandwidth Luma
1481 writel(VENC_UPSAMPLE_CTRL_INTERLACE_HIGH_LUMA | reg,
1482 priv->io_base + _REG(VENC_UPSAMPLE_CTRL0));
1488 writel(VENC_UPSAMPLE_CTRL_INTERLACE_PB | reg,
1489 priv->io_base + _REG(VENC_UPSAMPLE_CTRL1));
1495 writel(VENC_UPSAMPLE_CTRL_INTERLACE_PR | reg,
1496 priv->io_base + _REG(VENC_UPSAMPLE_CTRL2));
1498 /* Select Interlace Y DACs */
1499 writel(0, priv->io_base + _REG(VENC_VDAC_DACSEL0));
1500 writel(0, priv->io_base + _REG(VENC_VDAC_DACSEL1));
1501 writel(0, priv->io_base + _REG(VENC_VDAC_DACSEL2));
1502 writel(0, priv->io_base + _REG(VENC_VDAC_DACSEL3));
1503 writel(0, priv->io_base + _REG(VENC_VDAC_DACSEL4));
1504 writel(0, priv->io_base + _REG(VENC_VDAC_DACSEL5));
1506 /* Select ENCI for VIU */
1507 meson_vpp_setup_mux(priv, MESON_VIU_VPP_MUX_ENCI);
1509 /* Enable ENCI FIFO */
1510 writel(VENC_VDAC_FIFO_EN_ENCI_ENABLE,
1511 priv->io_base + _REG(VENC_VDAC_FIFO_CTRL));
1513 /* Select ENCI DACs 0, 1, 4, and 5 */
1514 writel(0x11, priv->io_base + _REG(ENCI_DACSEL_0));
1515 writel(0x11, priv->io_base + _REG(ENCI_DACSEL_1));
1517 /* Interlace video enable */
1518 writel(ENCI_VIDEO_EN_ENABLE,
1519 priv->io_base + _REG(ENCI_VIDEO_EN));
1521 /* Configure Video Saturation / Contrast / Brightness / Hue */
1522 writel(mode->video_saturation,
1523 priv->io_base + _REG(ENCI_VIDEO_SAT));
1524 writel(mode->video_contrast,
1525 priv->io_base + _REG(ENCI_VIDEO_CONT));
1526 writel(mode->video_brightness,
1527 priv->io_base + _REG(ENCI_VIDEO_BRIGHT));
1528 writel(mode->video_hue,
1529 priv->io_base + _REG(ENCI_VIDEO_HUE));
1531 /* Enable DAC0 Filter */
1532 writel(VENC_VDAC_DAC0_FILT_CTRL0_EN,
1533 priv->io_base + _REG(VENC_VDAC_DAC0_FILT_CTRL0));
1534 writel(0xfc48, priv->io_base + _REG(VENC_VDAC_DAC0_FILT_CTRL1));
1536 /* 0 in Macrovision register 0 */
1537 writel(0, priv->io_base + _REG(ENCI_MACV_N0));
1539 /* Analog Synchronization and color burst value adjust */
1540 writel(mode->analog_sync_adj,
1541 priv->io_base + _REG(ENCI_SYNC_ADJ));
1544 writel_bits(VENC_VDAC_SEL_ATV_DMD, 0,
1545 priv->io_base + _REG(VENC_VDAC_DACSEL0));
1547 if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXBB))
1548 hhi_write(HHI_VDAC_CNTL0, 1);
1549 else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXL) ||
1550 meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM))
1551 hhi_write(HHI_VDAC_CNTL0, 0xf0001);
1552 else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
1553 hhi_write(HHI_VDAC_CNTL0_G12A, 0x906001);
1555 if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
1556 hhi_write(HHI_VDAC_CNTL1_G12A, 0);
1558 hhi_write(HHI_VDAC_CNTL1, 0);
1561 void meson_vpu_setup_venc(struct udevice *dev,
1562 const struct display_timing *mode, bool is_cvbs)
1564 struct meson_vpu_priv *priv = dev_get_priv(dev);
1567 return meson_venci_cvbs_mode_set(priv, &meson_cvbs_enci_pal);
1569 meson_venc_hdmi_mode_set(priv, mode);