xref: /openbmc/linux/drivers/gpu/drm/meson/meson_venc.c (revision 1ccea77e)
11ccea77eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2bbbe775eSNeil Armstrong /*
3bbbe775eSNeil Armstrong  * Copyright (C) 2016 BayLibre, SAS
4bbbe775eSNeil Armstrong  * Author: Neil Armstrong <narmstrong@baylibre.com>
5bbbe775eSNeil Armstrong  * Copyright (C) 2015 Amlogic, Inc. All rights reserved.
6bbbe775eSNeil Armstrong  */
7bbbe775eSNeil Armstrong 
8bbbe775eSNeil Armstrong #include <linux/kernel.h>
9bbbe775eSNeil Armstrong #include <linux/module.h>
10bbbe775eSNeil Armstrong #include <drm/drmP.h>
11bbbe775eSNeil Armstrong #include "meson_drv.h"
12bbbe775eSNeil Armstrong #include "meson_venc.h"
13bbbe775eSNeil Armstrong #include "meson_vpp.h"
14bbbe775eSNeil Armstrong #include "meson_vclk.h"
15bbbe775eSNeil Armstrong #include "meson_registers.h"
16bbbe775eSNeil Armstrong 
172021d5b7SNeil Armstrong /**
182021d5b7SNeil Armstrong  * DOC: Video Encoder
192021d5b7SNeil Armstrong  *
20bbbe775eSNeil Armstrong  * VENC Handle the pixels encoding to the output formats.
21bbbe775eSNeil Armstrong  * We handle the following encodings :
222021d5b7SNeil Armstrong  *
23bbbe775eSNeil Armstrong  * - CVBS Encoding via the ENCI encoder and VDAC digital to analog converter
24bbbe775eSNeil Armstrong  * - TMDS/HDMI Encoding via ENCI_DIV and ENCP
25bbbe775eSNeil Armstrong  * - Setup of more clock rates for HDMI modes
26335e3713SNeil Armstrong  *
27335e3713SNeil Armstrong  * What is missing :
282021d5b7SNeil Armstrong  *
29bbbe775eSNeil Armstrong  * - LCD Panel encoding via ENCL
30bbbe775eSNeil Armstrong  * - TV Panel encoding via ENCT
31335e3713SNeil Armstrong  *
32335e3713SNeil Armstrong  * VENC paths :
332021d5b7SNeil Armstrong  *
342021d5b7SNeil Armstrong  * .. code::
352021d5b7SNeil Armstrong  *
36335e3713SNeil Armstrong  *          _____   _____   ____________________
37335e3713SNeil Armstrong  *   vd1---|     |-|     | | VENC     /---------|----VDAC
382021d5b7SNeil Armstrong  *   vd2---| VIU |-| VPP |-|-----ENCI/-ENCI_DVI-|-|
39335e3713SNeil Armstrong  *   osd1--|     |-|     | | \                  | X--HDMI-TX
402021d5b7SNeil Armstrong  *   osd2--|_____|-|_____| |  |\-ENCP--ENCP_DVI-|-|
41335e3713SNeil Armstrong  *                         |  |                 |
42335e3713SNeil Armstrong  *                         |  \--ENCL-----------|----LVDS
43335e3713SNeil Armstrong  *                         |____________________|
44335e3713SNeil Armstrong  *
45335e3713SNeil Armstrong  * The ENCI is designed for PAl or NTSC encoding and can go through the VDAC
46335e3713SNeil Armstrong  * directly for CVBS encoding or through the ENCI_DVI encoder for HDMI.
47335e3713SNeil Armstrong  * The ENCP is designed for Progressive encoding but can also generate
48335e3713SNeil Armstrong  * 1080i interlaced pixels, and was initialy desined to encode pixels for
49335e3713SNeil Armstrong  * VDAC to output RGB ou YUV analog outputs.
50335e3713SNeil Armstrong  * It's output is only used through the ENCP_DVI encoder for HDMI.
51335e3713SNeil Armstrong  * The ENCL LVDS encoder is not implemented.
52335e3713SNeil Armstrong  *
53335e3713SNeil Armstrong  * The ENCI and ENCP encoders needs specially defined parameters for each
54335e3713SNeil Armstrong  * supported mode and thus cannot be determined from standard video timings.
55335e3713SNeil Armstrong  *
56335e3713SNeil Armstrong  * The ENCI end ENCP DVI encoders are more generic and can generate any timings
57335e3713SNeil Armstrong  * from the pixel data generated by ENCI or ENCP, so can use the standard video
58335e3713SNeil Armstrong  * timings are source for HW parameters.
59bbbe775eSNeil Armstrong  */
60bbbe775eSNeil Armstrong 
610c931a29SNeil Armstrong /* HHI Registers */
622bcd3ecaSNeil Armstrong #define HHI_GCLK_MPEG2		0x148 /* 0x52 offset in data sheet */
630c931a29SNeil Armstrong #define HHI_VDAC_CNTL0		0x2F4 /* 0xbd offset in data sheet */
6464d598a1SNeil Armstrong #define HHI_VDAC_CNTL0_G12A	0x2EC /* 0xbd offset in data sheet */
650c931a29SNeil Armstrong #define HHI_VDAC_CNTL1		0x2F8 /* 0xbe offset in data sheet */
6664d598a1SNeil Armstrong #define HHI_VDAC_CNTL1_G12A	0x2F0 /* 0xbe offset in data sheet */
670c931a29SNeil Armstrong #define HHI_HDMI_PHY_CNTL0	0x3a0 /* 0xe8 offset in data sheet */
680c931a29SNeil Armstrong 
69bbbe775eSNeil Armstrong struct meson_cvbs_enci_mode meson_cvbs_enci_pal = {
70bbbe775eSNeil Armstrong 	.mode_tag = MESON_VENC_MODE_CVBS_PAL,
71bbbe775eSNeil Armstrong 	.hso_begin = 3,
72bbbe775eSNeil Armstrong 	.hso_end = 129,
73bbbe775eSNeil Armstrong 	.vso_even = 3,
74bbbe775eSNeil Armstrong 	.vso_odd = 260,
75bbbe775eSNeil Armstrong 	.macv_max_amp = 7,
76bbbe775eSNeil Armstrong 	.video_prog_mode = 0xff,
77bbbe775eSNeil Armstrong 	.video_mode = 0x13,
78bbbe775eSNeil Armstrong 	.sch_adjust = 0x28,
79bbbe775eSNeil Armstrong 	.yc_delay = 0x343,
80bbbe775eSNeil Armstrong 	.pixel_start = 251,
81bbbe775eSNeil Armstrong 	.pixel_end = 1691,
82bbbe775eSNeil Armstrong 	.top_field_line_start = 22,
83bbbe775eSNeil Armstrong 	.top_field_line_end = 310,
84bbbe775eSNeil Armstrong 	.bottom_field_line_start = 23,
85bbbe775eSNeil Armstrong 	.bottom_field_line_end = 311,
86bbbe775eSNeil Armstrong 	.video_saturation = 9,
87bbbe775eSNeil Armstrong 	.video_contrast = 0,
88bbbe775eSNeil Armstrong 	.video_brightness = 0,
89bbbe775eSNeil Armstrong 	.video_hue = 0,
90bbbe775eSNeil Armstrong 	.analog_sync_adj = 0x8080,
91bbbe775eSNeil Armstrong };
92bbbe775eSNeil Armstrong 
93bbbe775eSNeil Armstrong struct meson_cvbs_enci_mode meson_cvbs_enci_ntsc = {
94bbbe775eSNeil Armstrong 	.mode_tag = MESON_VENC_MODE_CVBS_NTSC,
95bbbe775eSNeil Armstrong 	.hso_begin = 5,
96bbbe775eSNeil Armstrong 	.hso_end = 129,
97bbbe775eSNeil Armstrong 	.vso_even = 3,
98bbbe775eSNeil Armstrong 	.vso_odd = 260,
99bbbe775eSNeil Armstrong 	.macv_max_amp = 0xb,
100bbbe775eSNeil Armstrong 	.video_prog_mode = 0xf0,
101bbbe775eSNeil Armstrong 	.video_mode = 0x8,
102bbbe775eSNeil Armstrong 	.sch_adjust = 0x20,
103bbbe775eSNeil Armstrong 	.yc_delay = 0x333,
104bbbe775eSNeil Armstrong 	.pixel_start = 227,
105bbbe775eSNeil Armstrong 	.pixel_end = 1667,
106bbbe775eSNeil Armstrong 	.top_field_line_start = 18,
107bbbe775eSNeil Armstrong 	.top_field_line_end = 258,
108bbbe775eSNeil Armstrong 	.bottom_field_line_start = 19,
109bbbe775eSNeil Armstrong 	.bottom_field_line_end = 259,
110bbbe775eSNeil Armstrong 	.video_saturation = 18,
111bbbe775eSNeil Armstrong 	.video_contrast = 3,
112bbbe775eSNeil Armstrong 	.video_brightness = 0,
113bbbe775eSNeil Armstrong 	.video_hue = 0,
114bbbe775eSNeil Armstrong 	.analog_sync_adj = 0x9c00,
115bbbe775eSNeil Armstrong };
116bbbe775eSNeil Armstrong 
117335e3713SNeil Armstrong union meson_hdmi_venc_mode {
118335e3713SNeil Armstrong 	struct {
119335e3713SNeil Armstrong 		unsigned int mode_tag;
120335e3713SNeil Armstrong 		unsigned int hso_begin;
121335e3713SNeil Armstrong 		unsigned int hso_end;
122335e3713SNeil Armstrong 		unsigned int vso_even;
123335e3713SNeil Armstrong 		unsigned int vso_odd;
124335e3713SNeil Armstrong 		unsigned int macv_max_amp;
125335e3713SNeil Armstrong 		unsigned int video_prog_mode;
126335e3713SNeil Armstrong 		unsigned int video_mode;
127335e3713SNeil Armstrong 		unsigned int sch_adjust;
128335e3713SNeil Armstrong 		unsigned int yc_delay;
129335e3713SNeil Armstrong 		unsigned int pixel_start;
130335e3713SNeil Armstrong 		unsigned int pixel_end;
131335e3713SNeil Armstrong 		unsigned int top_field_line_start;
132335e3713SNeil Armstrong 		unsigned int top_field_line_end;
133335e3713SNeil Armstrong 		unsigned int bottom_field_line_start;
134335e3713SNeil Armstrong 		unsigned int bottom_field_line_end;
135335e3713SNeil Armstrong 	} enci;
136335e3713SNeil Armstrong 	struct {
137335e3713SNeil Armstrong 		unsigned int dvi_settings;
138335e3713SNeil Armstrong 		unsigned int video_mode;
139335e3713SNeil Armstrong 		unsigned int video_mode_adv;
140335e3713SNeil Armstrong 		unsigned int video_prog_mode;
141335e3713SNeil Armstrong 		bool video_prog_mode_present;
142335e3713SNeil Armstrong 		unsigned int video_sync_mode;
143335e3713SNeil Armstrong 		bool video_sync_mode_present;
144335e3713SNeil Armstrong 		unsigned int video_yc_dly;
145335e3713SNeil Armstrong 		bool video_yc_dly_present;
146335e3713SNeil Armstrong 		unsigned int video_rgb_ctrl;
147335e3713SNeil Armstrong 		bool video_rgb_ctrl_present;
148335e3713SNeil Armstrong 		unsigned int video_filt_ctrl;
149335e3713SNeil Armstrong 		bool video_filt_ctrl_present;
150335e3713SNeil Armstrong 		unsigned int video_ofld_voav_ofst;
151335e3713SNeil Armstrong 		bool video_ofld_voav_ofst_present;
152335e3713SNeil Armstrong 		unsigned int yfp1_htime;
153335e3713SNeil Armstrong 		unsigned int yfp2_htime;
154335e3713SNeil Armstrong 		unsigned int max_pxcnt;
155335e3713SNeil Armstrong 		unsigned int hspuls_begin;
156335e3713SNeil Armstrong 		unsigned int hspuls_end;
157335e3713SNeil Armstrong 		unsigned int hspuls_switch;
158335e3713SNeil Armstrong 		unsigned int vspuls_begin;
159335e3713SNeil Armstrong 		unsigned int vspuls_end;
160335e3713SNeil Armstrong 		unsigned int vspuls_bline;
161335e3713SNeil Armstrong 		unsigned int vspuls_eline;
162335e3713SNeil Armstrong 		unsigned int eqpuls_begin;
163335e3713SNeil Armstrong 		bool eqpuls_begin_present;
164335e3713SNeil Armstrong 		unsigned int eqpuls_end;
165335e3713SNeil Armstrong 		bool eqpuls_end_present;
166335e3713SNeil Armstrong 		unsigned int eqpuls_bline;
167335e3713SNeil Armstrong 		bool eqpuls_bline_present;
168335e3713SNeil Armstrong 		unsigned int eqpuls_eline;
169335e3713SNeil Armstrong 		bool eqpuls_eline_present;
170335e3713SNeil Armstrong 		unsigned int havon_begin;
171335e3713SNeil Armstrong 		unsigned int havon_end;
172335e3713SNeil Armstrong 		unsigned int vavon_bline;
173335e3713SNeil Armstrong 		unsigned int vavon_eline;
174335e3713SNeil Armstrong 		unsigned int hso_begin;
175335e3713SNeil Armstrong 		unsigned int hso_end;
176335e3713SNeil Armstrong 		unsigned int vso_begin;
177335e3713SNeil Armstrong 		unsigned int vso_end;
178335e3713SNeil Armstrong 		unsigned int vso_bline;
179335e3713SNeil Armstrong 		unsigned int vso_eline;
180335e3713SNeil Armstrong 		bool vso_eline_present;
181335e3713SNeil Armstrong 		unsigned int sy_val;
182335e3713SNeil Armstrong 		bool sy_val_present;
183335e3713SNeil Armstrong 		unsigned int sy2_val;
184335e3713SNeil Armstrong 		bool sy2_val_present;
185335e3713SNeil Armstrong 		unsigned int max_lncnt;
186335e3713SNeil Armstrong 	} encp;
187335e3713SNeil Armstrong };
188335e3713SNeil Armstrong 
189335e3713SNeil Armstrong union meson_hdmi_venc_mode meson_hdmi_enci_mode_480i = {
190335e3713SNeil Armstrong 	.enci = {
191335e3713SNeil Armstrong 		.hso_begin = 5,
192335e3713SNeil Armstrong 		.hso_end = 129,
193335e3713SNeil Armstrong 		.vso_even = 3,
194335e3713SNeil Armstrong 		.vso_odd = 260,
195335e3713SNeil Armstrong 		.macv_max_amp = 0x810b,
196335e3713SNeil Armstrong 		.video_prog_mode = 0xf0,
197335e3713SNeil Armstrong 		.video_mode = 0x8,
198335e3713SNeil Armstrong 		.sch_adjust = 0x20,
199335e3713SNeil Armstrong 		.yc_delay = 0,
200335e3713SNeil Armstrong 		.pixel_start = 227,
201335e3713SNeil Armstrong 		.pixel_end = 1667,
202335e3713SNeil Armstrong 		.top_field_line_start = 18,
203335e3713SNeil Armstrong 		.top_field_line_end = 258,
204335e3713SNeil Armstrong 		.bottom_field_line_start = 19,
205335e3713SNeil Armstrong 		.bottom_field_line_end = 259,
206335e3713SNeil Armstrong 	},
207335e3713SNeil Armstrong };
208335e3713SNeil Armstrong 
209335e3713SNeil Armstrong union meson_hdmi_venc_mode meson_hdmi_enci_mode_576i = {
210335e3713SNeil Armstrong 	.enci = {
211335e3713SNeil Armstrong 		.hso_begin = 3,
212335e3713SNeil Armstrong 		.hso_end = 129,
213335e3713SNeil Armstrong 		.vso_even = 3,
214335e3713SNeil Armstrong 		.vso_odd = 260,
215335e3713SNeil Armstrong 		.macv_max_amp = 8107,
216335e3713SNeil Armstrong 		.video_prog_mode = 0xff,
217335e3713SNeil Armstrong 		.video_mode = 0x13,
218335e3713SNeil Armstrong 		.sch_adjust = 0x28,
219335e3713SNeil Armstrong 		.yc_delay = 0x333,
220335e3713SNeil Armstrong 		.pixel_start = 251,
221335e3713SNeil Armstrong 		.pixel_end = 1691,
222335e3713SNeil Armstrong 		.top_field_line_start = 22,
223335e3713SNeil Armstrong 		.top_field_line_end = 310,
224335e3713SNeil Armstrong 		.bottom_field_line_start = 23,
225335e3713SNeil Armstrong 		.bottom_field_line_end = 311,
226335e3713SNeil Armstrong 	},
227335e3713SNeil Armstrong };
228335e3713SNeil Armstrong 
229335e3713SNeil Armstrong union meson_hdmi_venc_mode meson_hdmi_encp_mode_480p = {
230335e3713SNeil Armstrong 	.encp = {
231335e3713SNeil Armstrong 		.dvi_settings = 0x21,
232335e3713SNeil Armstrong 		.video_mode = 0x4000,
233335e3713SNeil Armstrong 		.video_mode_adv = 0x9,
234335e3713SNeil Armstrong 		.video_prog_mode = 0,
235335e3713SNeil Armstrong 		.video_prog_mode_present = true,
236335e3713SNeil Armstrong 		.video_sync_mode = 7,
237335e3713SNeil Armstrong 		.video_sync_mode_present = true,
238335e3713SNeil Armstrong 		/* video_yc_dly */
239335e3713SNeil Armstrong 		/* video_rgb_ctrl */
240335e3713SNeil Armstrong 		.video_filt_ctrl = 0x2052,
241335e3713SNeil Armstrong 		.video_filt_ctrl_present = true,
242335e3713SNeil Armstrong 		/* video_ofld_voav_ofst */
243335e3713SNeil Armstrong 		.yfp1_htime = 244,
244335e3713SNeil Armstrong 		.yfp2_htime = 1630,
245335e3713SNeil Armstrong 		.max_pxcnt = 1715,
246335e3713SNeil Armstrong 		.hspuls_begin = 0x22,
247335e3713SNeil Armstrong 		.hspuls_end = 0xa0,
248335e3713SNeil Armstrong 		.hspuls_switch = 88,
249335e3713SNeil Armstrong 		.vspuls_begin = 0,
250335e3713SNeil Armstrong 		.vspuls_end = 1589,
251335e3713SNeil Armstrong 		.vspuls_bline = 0,
252335e3713SNeil Armstrong 		.vspuls_eline = 5,
253335e3713SNeil Armstrong 		.havon_begin = 249,
254335e3713SNeil Armstrong 		.havon_end = 1689,
255335e3713SNeil Armstrong 		.vavon_bline = 42,
256335e3713SNeil Armstrong 		.vavon_eline = 521,
257335e3713SNeil Armstrong 		/* eqpuls_begin */
258335e3713SNeil Armstrong 		/* eqpuls_end */
259335e3713SNeil Armstrong 		/* eqpuls_bline */
260335e3713SNeil Armstrong 		/* eqpuls_eline */
261335e3713SNeil Armstrong 		.hso_begin = 3,
262335e3713SNeil Armstrong 		.hso_end = 5,
263335e3713SNeil Armstrong 		.vso_begin = 3,
264335e3713SNeil Armstrong 		.vso_end = 5,
265335e3713SNeil Armstrong 		.vso_bline = 0,
266335e3713SNeil Armstrong 		/* vso_eline */
267335e3713SNeil Armstrong 		.sy_val	= 8,
268335e3713SNeil Armstrong 		.sy_val_present = true,
269335e3713SNeil Armstrong 		.sy2_val = 0x1d8,
270335e3713SNeil Armstrong 		.sy2_val_present = true,
271335e3713SNeil Armstrong 		.max_lncnt = 524,
272335e3713SNeil Armstrong 	},
273335e3713SNeil Armstrong };
274335e3713SNeil Armstrong 
275335e3713SNeil Armstrong union meson_hdmi_venc_mode meson_hdmi_encp_mode_576p = {
276335e3713SNeil Armstrong 	.encp = {
277335e3713SNeil Armstrong 		.dvi_settings = 0x21,
278335e3713SNeil Armstrong 		.video_mode = 0x4000,
279335e3713SNeil Armstrong 		.video_mode_adv = 0x9,
280335e3713SNeil Armstrong 		.video_prog_mode = 0,
281335e3713SNeil Armstrong 		.video_prog_mode_present = true,
282335e3713SNeil Armstrong 		.video_sync_mode = 7,
283335e3713SNeil Armstrong 		.video_sync_mode_present = true,
284335e3713SNeil Armstrong 		/* video_yc_dly */
285335e3713SNeil Armstrong 		/* video_rgb_ctrl */
286335e3713SNeil Armstrong 		.video_filt_ctrl = 0x52,
287335e3713SNeil Armstrong 		.video_filt_ctrl_present = true,
288335e3713SNeil Armstrong 		/* video_ofld_voav_ofst */
289335e3713SNeil Armstrong 		.yfp1_htime = 235,
290335e3713SNeil Armstrong 		.yfp2_htime = 1674,
291335e3713SNeil Armstrong 		.max_pxcnt = 1727,
292335e3713SNeil Armstrong 		.hspuls_begin = 0,
293335e3713SNeil Armstrong 		.hspuls_end = 0x80,
294335e3713SNeil Armstrong 		.hspuls_switch = 88,
295335e3713SNeil Armstrong 		.vspuls_begin = 0,
296335e3713SNeil Armstrong 		.vspuls_end = 1599,
297335e3713SNeil Armstrong 		.vspuls_bline = 0,
298335e3713SNeil Armstrong 		.vspuls_eline = 4,
299335e3713SNeil Armstrong 		.havon_begin = 235,
300335e3713SNeil Armstrong 		.havon_end = 1674,
301335e3713SNeil Armstrong 		.vavon_bline = 44,
302335e3713SNeil Armstrong 		.vavon_eline = 619,
303335e3713SNeil Armstrong 		/* eqpuls_begin */
304335e3713SNeil Armstrong 		/* eqpuls_end */
305335e3713SNeil Armstrong 		/* eqpuls_bline */
306335e3713SNeil Armstrong 		/* eqpuls_eline */
307335e3713SNeil Armstrong 		.hso_begin = 0x80,
308335e3713SNeil Armstrong 		.hso_end = 0,
309335e3713SNeil Armstrong 		.vso_begin = 0,
310335e3713SNeil Armstrong 		.vso_end = 5,
311335e3713SNeil Armstrong 		.vso_bline = 0,
312335e3713SNeil Armstrong 		/* vso_eline */
313335e3713SNeil Armstrong 		.sy_val	= 8,
314335e3713SNeil Armstrong 		.sy_val_present = true,
315335e3713SNeil Armstrong 		.sy2_val = 0x1d8,
316335e3713SNeil Armstrong 		.sy2_val_present = true,
317335e3713SNeil Armstrong 		.max_lncnt = 624,
318335e3713SNeil Armstrong 	},
319335e3713SNeil Armstrong };
320335e3713SNeil Armstrong 
321335e3713SNeil Armstrong union meson_hdmi_venc_mode meson_hdmi_encp_mode_720p60 = {
322335e3713SNeil Armstrong 	.encp = {
323335e3713SNeil Armstrong 		.dvi_settings = 0x2029,
324335e3713SNeil Armstrong 		.video_mode = 0x4040,
325335e3713SNeil Armstrong 		.video_mode_adv = 0x19,
326335e3713SNeil Armstrong 		/* video_prog_mode */
327335e3713SNeil Armstrong 		/* video_sync_mode */
328335e3713SNeil Armstrong 		/* video_yc_dly */
329335e3713SNeil Armstrong 		/* video_rgb_ctrl */
330335e3713SNeil Armstrong 		/* video_filt_ctrl */
331335e3713SNeil Armstrong 		/* video_ofld_voav_ofst */
332335e3713SNeil Armstrong 		.yfp1_htime = 648,
333335e3713SNeil Armstrong 		.yfp2_htime = 3207,
334335e3713SNeil Armstrong 		.max_pxcnt = 3299,
335335e3713SNeil Armstrong 		.hspuls_begin = 80,
336335e3713SNeil Armstrong 		.hspuls_end = 240,
337335e3713SNeil Armstrong 		.hspuls_switch = 80,
338335e3713SNeil Armstrong 		.vspuls_begin = 688,
339335e3713SNeil Armstrong 		.vspuls_end = 3248,
340335e3713SNeil Armstrong 		.vspuls_bline = 4,
341335e3713SNeil Armstrong 		.vspuls_eline = 8,
342335e3713SNeil Armstrong 		.havon_begin = 648,
343335e3713SNeil Armstrong 		.havon_end = 3207,
344335e3713SNeil Armstrong 		.vavon_bline = 29,
345335e3713SNeil Armstrong 		.vavon_eline = 748,
346335e3713SNeil Armstrong 		/* eqpuls_begin */
347335e3713SNeil Armstrong 		/* eqpuls_end */
348335e3713SNeil Armstrong 		/* eqpuls_bline */
349335e3713SNeil Armstrong 		/* eqpuls_eline */
350335e3713SNeil Armstrong 		.hso_begin = 256,
351335e3713SNeil Armstrong 		.hso_end = 168,
352335e3713SNeil Armstrong 		.vso_begin = 168,
353335e3713SNeil Armstrong 		.vso_end = 256,
354335e3713SNeil Armstrong 		.vso_bline = 0,
355335e3713SNeil Armstrong 		.vso_eline = 5,
356335e3713SNeil Armstrong 		.vso_eline_present = true,
357335e3713SNeil Armstrong 		/* sy_val */
358335e3713SNeil Armstrong 		/* sy2_val */
359335e3713SNeil Armstrong 		.max_lncnt = 749,
360335e3713SNeil Armstrong 	},
361335e3713SNeil Armstrong };
362335e3713SNeil Armstrong 
363335e3713SNeil Armstrong union meson_hdmi_venc_mode meson_hdmi_encp_mode_720p50 = {
364335e3713SNeil Armstrong 	.encp = {
365335e3713SNeil Armstrong 		.dvi_settings = 0x202d,
366335e3713SNeil Armstrong 		.video_mode = 0x4040,
367335e3713SNeil Armstrong 		.video_mode_adv = 0x19,
368335e3713SNeil Armstrong 		.video_prog_mode = 0x100,
369335e3713SNeil Armstrong 		.video_prog_mode_present = true,
370335e3713SNeil Armstrong 		.video_sync_mode = 0x407,
371335e3713SNeil Armstrong 		.video_sync_mode_present = true,
372335e3713SNeil Armstrong 		.video_yc_dly = 0,
373335e3713SNeil Armstrong 		.video_yc_dly_present = true,
374335e3713SNeil Armstrong 		/* video_rgb_ctrl */
375335e3713SNeil Armstrong 		/* video_filt_ctrl */
376335e3713SNeil Armstrong 		/* video_ofld_voav_ofst */
377335e3713SNeil Armstrong 		.yfp1_htime = 648,
378335e3713SNeil Armstrong 		.yfp2_htime = 3207,
379335e3713SNeil Armstrong 		.max_pxcnt = 3959,
380335e3713SNeil Armstrong 		.hspuls_begin = 80,
381335e3713SNeil Armstrong 		.hspuls_end = 240,
382335e3713SNeil Armstrong 		.hspuls_switch = 80,
383335e3713SNeil Armstrong 		.vspuls_begin = 688,
384335e3713SNeil Armstrong 		.vspuls_end = 3248,
385335e3713SNeil Armstrong 		.vspuls_bline = 4,
386335e3713SNeil Armstrong 		.vspuls_eline = 8,
387335e3713SNeil Armstrong 		.havon_begin = 648,
388335e3713SNeil Armstrong 		.havon_end = 3207,
389335e3713SNeil Armstrong 		.vavon_bline = 29,
390335e3713SNeil Armstrong 		.vavon_eline = 748,
391335e3713SNeil Armstrong 		/* eqpuls_begin */
392335e3713SNeil Armstrong 		/* eqpuls_end */
393335e3713SNeil Armstrong 		/* eqpuls_bline */
394335e3713SNeil Armstrong 		/* eqpuls_eline */
395335e3713SNeil Armstrong 		.hso_begin = 128,
396335e3713SNeil Armstrong 		.hso_end = 208,
397335e3713SNeil Armstrong 		.vso_begin = 128,
398335e3713SNeil Armstrong 		.vso_end = 128,
399335e3713SNeil Armstrong 		.vso_bline = 0,
400335e3713SNeil Armstrong 		.vso_eline = 5,
401335e3713SNeil Armstrong 		.vso_eline_present = true,
402335e3713SNeil Armstrong 		/* sy_val */
403335e3713SNeil Armstrong 		/* sy2_val */
404335e3713SNeil Armstrong 		.max_lncnt = 749,
405335e3713SNeil Armstrong 	},
406335e3713SNeil Armstrong };
407335e3713SNeil Armstrong 
408335e3713SNeil Armstrong union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080i60 = {
409335e3713SNeil Armstrong 	.encp = {
410335e3713SNeil Armstrong 		.dvi_settings = 0x2029,
411335e3713SNeil Armstrong 		.video_mode = 0x5ffc,
412335e3713SNeil Armstrong 		.video_mode_adv = 0x19,
413335e3713SNeil Armstrong 		.video_prog_mode = 0x100,
414335e3713SNeil Armstrong 		.video_prog_mode_present = true,
415335e3713SNeil Armstrong 		.video_sync_mode = 0x207,
416335e3713SNeil Armstrong 		.video_sync_mode_present = true,
417335e3713SNeil Armstrong 		/* video_yc_dly */
418335e3713SNeil Armstrong 		/* video_rgb_ctrl */
419335e3713SNeil Armstrong 		/* video_filt_ctrl */
420335e3713SNeil Armstrong 		.video_ofld_voav_ofst = 0x11,
421335e3713SNeil Armstrong 		.video_ofld_voav_ofst_present = true,
422335e3713SNeil Armstrong 		.yfp1_htime = 516,
423335e3713SNeil Armstrong 		.yfp2_htime = 4355,
424335e3713SNeil Armstrong 		.max_pxcnt = 4399,
425335e3713SNeil Armstrong 		.hspuls_begin = 88,
426335e3713SNeil Armstrong 		.hspuls_end = 264,
427335e3713SNeil Armstrong 		.hspuls_switch = 88,
428335e3713SNeil Armstrong 		.vspuls_begin = 440,
429335e3713SNeil Armstrong 		.vspuls_end = 2200,
430335e3713SNeil Armstrong 		.vspuls_bline = 0,
431335e3713SNeil Armstrong 		.vspuls_eline = 4,
432335e3713SNeil Armstrong 		.havon_begin = 516,
433335e3713SNeil Armstrong 		.havon_end = 4355,
434335e3713SNeil Armstrong 		.vavon_bline = 20,
435335e3713SNeil Armstrong 		.vavon_eline = 559,
436335e3713SNeil Armstrong 		.eqpuls_begin = 2288,
437335e3713SNeil Armstrong 		.eqpuls_begin_present = true,
438335e3713SNeil Armstrong 		.eqpuls_end = 2464,
439335e3713SNeil Armstrong 		.eqpuls_end_present = true,
440335e3713SNeil Armstrong 		.eqpuls_bline = 0,
441335e3713SNeil Armstrong 		.eqpuls_bline_present = true,
442335e3713SNeil Armstrong 		.eqpuls_eline = 4,
443335e3713SNeil Armstrong 		.eqpuls_eline_present = true,
444335e3713SNeil Armstrong 		.hso_begin = 264,
445335e3713SNeil Armstrong 		.hso_end = 176,
446335e3713SNeil Armstrong 		.vso_begin = 88,
447335e3713SNeil Armstrong 		.vso_end = 88,
448335e3713SNeil Armstrong 		.vso_bline = 0,
449335e3713SNeil Armstrong 		.vso_eline = 5,
450335e3713SNeil Armstrong 		.vso_eline_present = true,
451335e3713SNeil Armstrong 		/* sy_val */
452335e3713SNeil Armstrong 		/* sy2_val */
453335e3713SNeil Armstrong 		.max_lncnt = 1124,
454335e3713SNeil Armstrong 	},
455335e3713SNeil Armstrong };
456335e3713SNeil Armstrong 
457335e3713SNeil Armstrong union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080i50 = {
458335e3713SNeil Armstrong 	.encp = {
459335e3713SNeil Armstrong 		.dvi_settings = 0x202d,
460335e3713SNeil Armstrong 		.video_mode = 0x5ffc,
461335e3713SNeil Armstrong 		.video_mode_adv = 0x19,
462335e3713SNeil Armstrong 		.video_prog_mode = 0x100,
463335e3713SNeil Armstrong 		.video_prog_mode_present = true,
464335e3713SNeil Armstrong 		.video_sync_mode = 0x7,
465335e3713SNeil Armstrong 		.video_sync_mode_present = true,
466335e3713SNeil Armstrong 		/* video_yc_dly */
467335e3713SNeil Armstrong 		/* video_rgb_ctrl */
468335e3713SNeil Armstrong 		/* video_filt_ctrl */
469335e3713SNeil Armstrong 		.video_ofld_voav_ofst = 0x11,
470335e3713SNeil Armstrong 		.video_ofld_voav_ofst_present = true,
471335e3713SNeil Armstrong 		.yfp1_htime = 526,
472335e3713SNeil Armstrong 		.yfp2_htime = 4365,
473335e3713SNeil Armstrong 		.max_pxcnt = 5279,
474335e3713SNeil Armstrong 		.hspuls_begin = 88,
475335e3713SNeil Armstrong 		.hspuls_end = 264,
476335e3713SNeil Armstrong 		.hspuls_switch = 88,
477335e3713SNeil Armstrong 		.vspuls_begin = 440,
478335e3713SNeil Armstrong 		.vspuls_end = 2200,
479335e3713SNeil Armstrong 		.vspuls_bline = 0,
480335e3713SNeil Armstrong 		.vspuls_eline = 4,
481335e3713SNeil Armstrong 		.havon_begin = 526,
482335e3713SNeil Armstrong 		.havon_end = 4365,
483335e3713SNeil Armstrong 		.vavon_bline = 20,
484335e3713SNeil Armstrong 		.vavon_eline = 559,
485335e3713SNeil Armstrong 		.eqpuls_begin = 2288,
486335e3713SNeil Armstrong 		.eqpuls_begin_present = true,
487335e3713SNeil Armstrong 		.eqpuls_end = 2464,
488335e3713SNeil Armstrong 		.eqpuls_end_present = true,
489335e3713SNeil Armstrong 		.eqpuls_bline = 0,
490335e3713SNeil Armstrong 		.eqpuls_bline_present = true,
491335e3713SNeil Armstrong 		.eqpuls_eline = 4,
492335e3713SNeil Armstrong 		.eqpuls_eline_present = true,
493335e3713SNeil Armstrong 		.hso_begin = 142,
494335e3713SNeil Armstrong 		.hso_end = 230,
495335e3713SNeil Armstrong 		.vso_begin = 142,
496335e3713SNeil Armstrong 		.vso_end = 142,
497335e3713SNeil Armstrong 		.vso_bline = 0,
498335e3713SNeil Armstrong 		.vso_eline = 5,
499335e3713SNeil Armstrong 		.vso_eline_present = true,
500335e3713SNeil Armstrong 		/* sy_val */
501335e3713SNeil Armstrong 		/* sy2_val */
502335e3713SNeil Armstrong 		.max_lncnt = 1124,
503335e3713SNeil Armstrong 	},
504335e3713SNeil Armstrong };
505335e3713SNeil Armstrong 
506335e3713SNeil Armstrong union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080p24 = {
507335e3713SNeil Armstrong 	.encp = {
508335e3713SNeil Armstrong 		.dvi_settings = 0xd,
509335e3713SNeil Armstrong 		.video_mode = 0x4040,
510335e3713SNeil Armstrong 		.video_mode_adv = 0x18,
511335e3713SNeil Armstrong 		.video_prog_mode = 0x100,
512335e3713SNeil Armstrong 		.video_prog_mode_present = true,
513335e3713SNeil Armstrong 		.video_sync_mode = 0x7,
514335e3713SNeil Armstrong 		.video_sync_mode_present = true,
515335e3713SNeil Armstrong 		.video_yc_dly = 0,
516335e3713SNeil Armstrong 		.video_yc_dly_present = true,
517335e3713SNeil Armstrong 		.video_rgb_ctrl = 2,
518335e3713SNeil Armstrong 		.video_rgb_ctrl_present = true,
519335e3713SNeil Armstrong 		.video_filt_ctrl = 0x1052,
520335e3713SNeil Armstrong 		.video_filt_ctrl_present = true,
521335e3713SNeil Armstrong 		/* video_ofld_voav_ofst */
522335e3713SNeil Armstrong 		.yfp1_htime = 271,
523335e3713SNeil Armstrong 		.yfp2_htime = 2190,
524335e3713SNeil Armstrong 		.max_pxcnt = 2749,
525335e3713SNeil Armstrong 		.hspuls_begin = 44,
526335e3713SNeil Armstrong 		.hspuls_end = 132,
527335e3713SNeil Armstrong 		.hspuls_switch = 44,
528335e3713SNeil Armstrong 		.vspuls_begin = 220,
529335e3713SNeil Armstrong 		.vspuls_end = 2140,
530335e3713SNeil Armstrong 		.vspuls_bline = 0,
531335e3713SNeil Armstrong 		.vspuls_eline = 4,
532335e3713SNeil Armstrong 		.havon_begin = 271,
533335e3713SNeil Armstrong 		.havon_end = 2190,
534335e3713SNeil Armstrong 		.vavon_bline = 41,
535335e3713SNeil Armstrong 		.vavon_eline = 1120,
536335e3713SNeil Armstrong 		/* eqpuls_begin */
537335e3713SNeil Armstrong 		/* eqpuls_end */
538335e3713SNeil Armstrong 		.eqpuls_bline = 0,
539335e3713SNeil Armstrong 		.eqpuls_bline_present = true,
540335e3713SNeil Armstrong 		.eqpuls_eline = 4,
541335e3713SNeil Armstrong 		.eqpuls_eline_present = true,
542335e3713SNeil Armstrong 		.hso_begin = 79,
543335e3713SNeil Armstrong 		.hso_end = 123,
544335e3713SNeil Armstrong 		.vso_begin = 79,
545335e3713SNeil Armstrong 		.vso_end = 79,
546335e3713SNeil Armstrong 		.vso_bline = 0,
547335e3713SNeil Armstrong 		.vso_eline = 5,
548335e3713SNeil Armstrong 		.vso_eline_present = true,
549335e3713SNeil Armstrong 		/* sy_val */
550335e3713SNeil Armstrong 		/* sy2_val */
551335e3713SNeil Armstrong 		.max_lncnt = 1124,
552335e3713SNeil Armstrong 	},
553335e3713SNeil Armstrong };
554335e3713SNeil Armstrong 
555335e3713SNeil Armstrong union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080p30 = {
556335e3713SNeil Armstrong 	.encp = {
557335e3713SNeil Armstrong 		.dvi_settings = 0x1,
558335e3713SNeil Armstrong 		.video_mode = 0x4040,
559335e3713SNeil Armstrong 		.video_mode_adv = 0x18,
560335e3713SNeil Armstrong 		.video_prog_mode = 0x100,
561335e3713SNeil Armstrong 		.video_prog_mode_present = true,
562335e3713SNeil Armstrong 		/* video_sync_mode */
563335e3713SNeil Armstrong 		/* video_yc_dly */
564335e3713SNeil Armstrong 		/* video_rgb_ctrl */
565335e3713SNeil Armstrong 		.video_filt_ctrl = 0x1052,
566335e3713SNeil Armstrong 		.video_filt_ctrl_present = true,
567335e3713SNeil Armstrong 		/* video_ofld_voav_ofst */
568335e3713SNeil Armstrong 		.yfp1_htime = 140,
569335e3713SNeil Armstrong 		.yfp2_htime = 2060,
570335e3713SNeil Armstrong 		.max_pxcnt = 2199,
571335e3713SNeil Armstrong 		.hspuls_begin = 2156,
572335e3713SNeil Armstrong 		.hspuls_end = 44,
573335e3713SNeil Armstrong 		.hspuls_switch = 44,
574335e3713SNeil Armstrong 		.vspuls_begin = 140,
575335e3713SNeil Armstrong 		.vspuls_end = 2059,
576335e3713SNeil Armstrong 		.vspuls_bline = 0,
577335e3713SNeil Armstrong 		.vspuls_eline = 4,
578335e3713SNeil Armstrong 		.havon_begin = 148,
579335e3713SNeil Armstrong 		.havon_end = 2067,
580335e3713SNeil Armstrong 		.vavon_bline = 41,
581335e3713SNeil Armstrong 		.vavon_eline = 1120,
582335e3713SNeil Armstrong 		/* eqpuls_begin */
583335e3713SNeil Armstrong 		/* eqpuls_end */
584335e3713SNeil Armstrong 		/* eqpuls_bline */
585335e3713SNeil Armstrong 		/* eqpuls_eline */
586335e3713SNeil Armstrong 		.hso_begin = 44,
587335e3713SNeil Armstrong 		.hso_end = 2156,
588335e3713SNeil Armstrong 		.vso_begin = 2100,
589335e3713SNeil Armstrong 		.vso_end = 2164,
590335e3713SNeil Armstrong 		.vso_bline = 0,
591335e3713SNeil Armstrong 		.vso_eline = 5,
592335e3713SNeil Armstrong 		.vso_eline_present = true,
593335e3713SNeil Armstrong 		/* sy_val */
594335e3713SNeil Armstrong 		/* sy2_val */
595335e3713SNeil Armstrong 		.max_lncnt = 1124,
596335e3713SNeil Armstrong 	},
597335e3713SNeil Armstrong };
598335e3713SNeil Armstrong 
599335e3713SNeil Armstrong union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080p50 = {
600335e3713SNeil Armstrong 	.encp = {
601335e3713SNeil Armstrong 		.dvi_settings = 0xd,
602335e3713SNeil Armstrong 		.video_mode = 0x4040,
603335e3713SNeil Armstrong 		.video_mode_adv = 0x18,
604335e3713SNeil Armstrong 		.video_prog_mode = 0x100,
605335e3713SNeil Armstrong 		.video_prog_mode_present = true,
606335e3713SNeil Armstrong 		.video_sync_mode = 0x7,
607335e3713SNeil Armstrong 		.video_sync_mode_present = true,
608335e3713SNeil Armstrong 		.video_yc_dly = 0,
609335e3713SNeil Armstrong 		.video_yc_dly_present = true,
610335e3713SNeil Armstrong 		.video_rgb_ctrl = 2,
611335e3713SNeil Armstrong 		.video_rgb_ctrl_present = true,
612335e3713SNeil Armstrong 		/* video_filt_ctrl */
613335e3713SNeil Armstrong 		/* video_ofld_voav_ofst */
614335e3713SNeil Armstrong 		.yfp1_htime = 271,
615335e3713SNeil Armstrong 		.yfp2_htime = 2190,
616335e3713SNeil Armstrong 		.max_pxcnt = 2639,
617335e3713SNeil Armstrong 		.hspuls_begin = 44,
618335e3713SNeil Armstrong 		.hspuls_end = 132,
619335e3713SNeil Armstrong 		.hspuls_switch = 44,
620335e3713SNeil Armstrong 		.vspuls_begin = 220,
621335e3713SNeil Armstrong 		.vspuls_end = 2140,
622335e3713SNeil Armstrong 		.vspuls_bline = 0,
623335e3713SNeil Armstrong 		.vspuls_eline = 4,
624335e3713SNeil Armstrong 		.havon_begin = 271,
625335e3713SNeil Armstrong 		.havon_end = 2190,
626335e3713SNeil Armstrong 		.vavon_bline = 41,
627335e3713SNeil Armstrong 		.vavon_eline = 1120,
628335e3713SNeil Armstrong 		/* eqpuls_begin */
629335e3713SNeil Armstrong 		/* eqpuls_end */
630335e3713SNeil Armstrong 		.eqpuls_bline = 0,
631335e3713SNeil Armstrong 		.eqpuls_bline_present = true,
632335e3713SNeil Armstrong 		.eqpuls_eline = 4,
633335e3713SNeil Armstrong 		.eqpuls_eline_present = true,
634335e3713SNeil Armstrong 		.hso_begin = 79,
635335e3713SNeil Armstrong 		.hso_end = 123,
636335e3713SNeil Armstrong 		.vso_begin = 79,
637335e3713SNeil Armstrong 		.vso_end = 79,
638335e3713SNeil Armstrong 		.vso_bline = 0,
639335e3713SNeil Armstrong 		.vso_eline = 5,
640335e3713SNeil Armstrong 		.vso_eline_present = true,
641335e3713SNeil Armstrong 		/* sy_val */
642335e3713SNeil Armstrong 		/* sy2_val */
643335e3713SNeil Armstrong 		.max_lncnt = 1124,
644335e3713SNeil Armstrong 	},
645335e3713SNeil Armstrong };
646335e3713SNeil Armstrong 
647335e3713SNeil Armstrong union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080p60 = {
648335e3713SNeil Armstrong 	.encp = {
649335e3713SNeil Armstrong 		.dvi_settings = 0x1,
650335e3713SNeil Armstrong 		.video_mode = 0x4040,
651335e3713SNeil Armstrong 		.video_mode_adv = 0x18,
652335e3713SNeil Armstrong 		.video_prog_mode = 0x100,
653335e3713SNeil Armstrong 		.video_prog_mode_present = true,
654335e3713SNeil Armstrong 		/* video_sync_mode */
655335e3713SNeil Armstrong 		/* video_yc_dly */
656335e3713SNeil Armstrong 		/* video_rgb_ctrl */
657335e3713SNeil Armstrong 		.video_filt_ctrl = 0x1052,
658335e3713SNeil Armstrong 		.video_filt_ctrl_present = true,
659335e3713SNeil Armstrong 		/* video_ofld_voav_ofst */
660335e3713SNeil Armstrong 		.yfp1_htime = 140,
661335e3713SNeil Armstrong 		.yfp2_htime = 2060,
662335e3713SNeil Armstrong 		.max_pxcnt = 2199,
663335e3713SNeil Armstrong 		.hspuls_begin = 2156,
664335e3713SNeil Armstrong 		.hspuls_end = 44,
665335e3713SNeil Armstrong 		.hspuls_switch = 44,
666335e3713SNeil Armstrong 		.vspuls_begin = 140,
667335e3713SNeil Armstrong 		.vspuls_end = 2059,
668335e3713SNeil Armstrong 		.vspuls_bline = 0,
669335e3713SNeil Armstrong 		.vspuls_eline = 4,
670335e3713SNeil Armstrong 		.havon_begin = 148,
671335e3713SNeil Armstrong 		.havon_end = 2067,
672335e3713SNeil Armstrong 		.vavon_bline = 41,
673335e3713SNeil Armstrong 		.vavon_eline = 1120,
674335e3713SNeil Armstrong 		/* eqpuls_begin */
675335e3713SNeil Armstrong 		/* eqpuls_end */
676335e3713SNeil Armstrong 		/* eqpuls_bline */
677335e3713SNeil Armstrong 		/* eqpuls_eline */
678335e3713SNeil Armstrong 		.hso_begin = 44,
679335e3713SNeil Armstrong 		.hso_end = 2156,
680335e3713SNeil Armstrong 		.vso_begin = 2100,
681335e3713SNeil Armstrong 		.vso_end = 2164,
682335e3713SNeil Armstrong 		.vso_bline = 0,
683335e3713SNeil Armstrong 		.vso_eline = 5,
684335e3713SNeil Armstrong 		.vso_eline_present = true,
685335e3713SNeil Armstrong 		/* sy_val */
686335e3713SNeil Armstrong 		/* sy2_val */
687335e3713SNeil Armstrong 		.max_lncnt = 1124,
688335e3713SNeil Armstrong 	},
689335e3713SNeil Armstrong };
690335e3713SNeil Armstrong 
6915d0bfe44SNeil Armstrong union meson_hdmi_venc_mode meson_hdmi_encp_mode_2160p24 = {
6925d0bfe44SNeil Armstrong 	.encp = {
6935d0bfe44SNeil Armstrong 		.dvi_settings = 0x1,
6945d0bfe44SNeil Armstrong 		.video_mode = 0x4040,
6955d0bfe44SNeil Armstrong 		.video_mode_adv = 0x8,
6965d0bfe44SNeil Armstrong 		/* video_sync_mode */
6975d0bfe44SNeil Armstrong 		/* video_yc_dly */
6985d0bfe44SNeil Armstrong 		/* video_rgb_ctrl */
6995d0bfe44SNeil Armstrong 		.video_filt_ctrl = 0x1000,
7005d0bfe44SNeil Armstrong 		.video_filt_ctrl_present = true,
7015d0bfe44SNeil Armstrong 		/* video_ofld_voav_ofst */
7025d0bfe44SNeil Armstrong 		.yfp1_htime = 140,
7035d0bfe44SNeil Armstrong 		.yfp2_htime = 140+3840,
7045d0bfe44SNeil Armstrong 		.max_pxcnt = 3840+1660-1,
7055d0bfe44SNeil Armstrong 		.hspuls_begin = 2156+1920,
7065d0bfe44SNeil Armstrong 		.hspuls_end = 44,
7075d0bfe44SNeil Armstrong 		.hspuls_switch = 44,
7085d0bfe44SNeil Armstrong 		.vspuls_begin = 140,
7095d0bfe44SNeil Armstrong 		.vspuls_end = 2059+1920,
7105d0bfe44SNeil Armstrong 		.vspuls_bline = 0,
7115d0bfe44SNeil Armstrong 		.vspuls_eline = 4,
7125d0bfe44SNeil Armstrong 		.havon_begin = 148,
7135d0bfe44SNeil Armstrong 		.havon_end = 3987,
7145d0bfe44SNeil Armstrong 		.vavon_bline = 89,
7155d0bfe44SNeil Armstrong 		.vavon_eline = 2248,
7165d0bfe44SNeil Armstrong 		/* eqpuls_begin */
7175d0bfe44SNeil Armstrong 		/* eqpuls_end */
7185d0bfe44SNeil Armstrong 		/* eqpuls_bline */
7195d0bfe44SNeil Armstrong 		/* eqpuls_eline */
7205d0bfe44SNeil Armstrong 		.hso_begin = 44,
7215d0bfe44SNeil Armstrong 		.hso_end = 2156+1920,
7225d0bfe44SNeil Armstrong 		.vso_begin = 2100+1920,
7235d0bfe44SNeil Armstrong 		.vso_end = 2164+1920,
7245d0bfe44SNeil Armstrong 		.vso_bline = 51,
7255d0bfe44SNeil Armstrong 		.vso_eline = 53,
7265d0bfe44SNeil Armstrong 		.vso_eline_present = true,
7275d0bfe44SNeil Armstrong 		/* sy_val */
7285d0bfe44SNeil Armstrong 		/* sy2_val */
7295d0bfe44SNeil Armstrong 		.max_lncnt = 2249,
7305d0bfe44SNeil Armstrong 	},
7315d0bfe44SNeil Armstrong };
7325d0bfe44SNeil Armstrong 
7335d0bfe44SNeil Armstrong union meson_hdmi_venc_mode meson_hdmi_encp_mode_2160p25 = {
7345d0bfe44SNeil Armstrong 	.encp = {
7355d0bfe44SNeil Armstrong 		.dvi_settings = 0x1,
7365d0bfe44SNeil Armstrong 		.video_mode = 0x4040,
7375d0bfe44SNeil Armstrong 		.video_mode_adv = 0x8,
7385d0bfe44SNeil Armstrong 		/* video_sync_mode */
7395d0bfe44SNeil Armstrong 		/* video_yc_dly */
7405d0bfe44SNeil Armstrong 		/* video_rgb_ctrl */
7415d0bfe44SNeil Armstrong 		.video_filt_ctrl = 0x1000,
7425d0bfe44SNeil Armstrong 		.video_filt_ctrl_present = true,
7435d0bfe44SNeil Armstrong 		/* video_ofld_voav_ofst */
7445d0bfe44SNeil Armstrong 		.yfp1_htime = 140,
7455d0bfe44SNeil Armstrong 		.yfp2_htime = 140+3840,
7465d0bfe44SNeil Armstrong 		.max_pxcnt = 3840+1440-1,
7475d0bfe44SNeil Armstrong 		.hspuls_begin = 2156+1920,
7485d0bfe44SNeil Armstrong 		.hspuls_end = 44,
7495d0bfe44SNeil Armstrong 		.hspuls_switch = 44,
7505d0bfe44SNeil Armstrong 		.vspuls_begin = 140,
7515d0bfe44SNeil Armstrong 		.vspuls_end = 2059+1920,
7525d0bfe44SNeil Armstrong 		.vspuls_bline = 0,
7535d0bfe44SNeil Armstrong 		.vspuls_eline = 4,
7545d0bfe44SNeil Armstrong 		.havon_begin = 148,
7555d0bfe44SNeil Armstrong 		.havon_end = 3987,
7565d0bfe44SNeil Armstrong 		.vavon_bline = 89,
7575d0bfe44SNeil Armstrong 		.vavon_eline = 2248,
7585d0bfe44SNeil Armstrong 		/* eqpuls_begin */
7595d0bfe44SNeil Armstrong 		/* eqpuls_end */
7605d0bfe44SNeil Armstrong 		/* eqpuls_bline */
7615d0bfe44SNeil Armstrong 		/* eqpuls_eline */
7625d0bfe44SNeil Armstrong 		.hso_begin = 44,
7635d0bfe44SNeil Armstrong 		.hso_end = 2156+1920,
7645d0bfe44SNeil Armstrong 		.vso_begin = 2100+1920,
7655d0bfe44SNeil Armstrong 		.vso_end = 2164+1920,
7665d0bfe44SNeil Armstrong 		.vso_bline = 51,
7675d0bfe44SNeil Armstrong 		.vso_eline = 53,
7685d0bfe44SNeil Armstrong 		.vso_eline_present = true,
7695d0bfe44SNeil Armstrong 		/* sy_val */
7705d0bfe44SNeil Armstrong 		/* sy2_val */
7715d0bfe44SNeil Armstrong 		.max_lncnt = 2249,
7725d0bfe44SNeil Armstrong 	},
7735d0bfe44SNeil Armstrong };
7745d0bfe44SNeil Armstrong 
7755d0bfe44SNeil Armstrong union meson_hdmi_venc_mode meson_hdmi_encp_mode_2160p30 = {
7765d0bfe44SNeil Armstrong 	.encp = {
7775d0bfe44SNeil Armstrong 		.dvi_settings = 0x1,
7785d0bfe44SNeil Armstrong 		.video_mode = 0x4040,
7795d0bfe44SNeil Armstrong 		.video_mode_adv = 0x8,
7805d0bfe44SNeil Armstrong 		/* video_sync_mode */
7815d0bfe44SNeil Armstrong 		/* video_yc_dly */
7825d0bfe44SNeil Armstrong 		/* video_rgb_ctrl */
7835d0bfe44SNeil Armstrong 		.video_filt_ctrl = 0x1000,
7845d0bfe44SNeil Armstrong 		.video_filt_ctrl_present = true,
7855d0bfe44SNeil Armstrong 		/* video_ofld_voav_ofst */
7865d0bfe44SNeil Armstrong 		.yfp1_htime = 140,
7875d0bfe44SNeil Armstrong 		.yfp2_htime = 140+3840,
7885d0bfe44SNeil Armstrong 		.max_pxcnt = 3840+560-1,
7895d0bfe44SNeil Armstrong 		.hspuls_begin = 2156+1920,
7905d0bfe44SNeil Armstrong 		.hspuls_end = 44,
7915d0bfe44SNeil Armstrong 		.hspuls_switch = 44,
7925d0bfe44SNeil Armstrong 		.vspuls_begin = 140,
7935d0bfe44SNeil Armstrong 		.vspuls_end = 2059+1920,
7945d0bfe44SNeil Armstrong 		.vspuls_bline = 0,
7955d0bfe44SNeil Armstrong 		.vspuls_eline = 4,
7965d0bfe44SNeil Armstrong 		.havon_begin = 148,
7975d0bfe44SNeil Armstrong 		.havon_end = 3987,
7985d0bfe44SNeil Armstrong 		.vavon_bline = 89,
7995d0bfe44SNeil Armstrong 		.vavon_eline = 2248,
8005d0bfe44SNeil Armstrong 		/* eqpuls_begin */
8015d0bfe44SNeil Armstrong 		/* eqpuls_end */
8025d0bfe44SNeil Armstrong 		/* eqpuls_bline */
8035d0bfe44SNeil Armstrong 		/* eqpuls_eline */
8045d0bfe44SNeil Armstrong 		.hso_begin = 44,
8055d0bfe44SNeil Armstrong 		.hso_end = 2156+1920,
8065d0bfe44SNeil Armstrong 		.vso_begin = 2100+1920,
8075d0bfe44SNeil Armstrong 		.vso_end = 2164+1920,
8085d0bfe44SNeil Armstrong 		.vso_bline = 51,
8095d0bfe44SNeil Armstrong 		.vso_eline = 53,
8105d0bfe44SNeil Armstrong 		.vso_eline_present = true,
8115d0bfe44SNeil Armstrong 		/* sy_val */
8125d0bfe44SNeil Armstrong 		/* sy2_val */
8135d0bfe44SNeil Armstrong 		.max_lncnt = 2249,
8145d0bfe44SNeil Armstrong 	},
8155d0bfe44SNeil Armstrong };
8165d0bfe44SNeil Armstrong 
817335e3713SNeil Armstrong struct meson_hdmi_venc_vic_mode {
818335e3713SNeil Armstrong 	unsigned int vic;
819335e3713SNeil Armstrong 	union meson_hdmi_venc_mode *mode;
820335e3713SNeil Armstrong } meson_hdmi_venc_vic_modes[] = {
821335e3713SNeil Armstrong 	{ 6, &meson_hdmi_enci_mode_480i },
822335e3713SNeil Armstrong 	{ 7, &meson_hdmi_enci_mode_480i },
823335e3713SNeil Armstrong 	{ 21, &meson_hdmi_enci_mode_576i },
824335e3713SNeil Armstrong 	{ 22, &meson_hdmi_enci_mode_576i },
825335e3713SNeil Armstrong 	{ 2, &meson_hdmi_encp_mode_480p },
826335e3713SNeil Armstrong 	{ 3, &meson_hdmi_encp_mode_480p },
827335e3713SNeil Armstrong 	{ 17, &meson_hdmi_encp_mode_576p },
828335e3713SNeil Armstrong 	{ 18, &meson_hdmi_encp_mode_576p },
829335e3713SNeil Armstrong 	{ 4, &meson_hdmi_encp_mode_720p60 },
830335e3713SNeil Armstrong 	{ 19, &meson_hdmi_encp_mode_720p50 },
831335e3713SNeil Armstrong 	{ 5, &meson_hdmi_encp_mode_1080i60 },
832335e3713SNeil Armstrong 	{ 20, &meson_hdmi_encp_mode_1080i50 },
833335e3713SNeil Armstrong 	{ 32, &meson_hdmi_encp_mode_1080p24 },
83431e1ab49SChristian Hewitt 	{ 33, &meson_hdmi_encp_mode_1080p50 },
835335e3713SNeil Armstrong 	{ 34, &meson_hdmi_encp_mode_1080p30 },
836335e3713SNeil Armstrong 	{ 31, &meson_hdmi_encp_mode_1080p50 },
837335e3713SNeil Armstrong 	{ 16, &meson_hdmi_encp_mode_1080p60 },
8385d0bfe44SNeil Armstrong 	{ 93, &meson_hdmi_encp_mode_2160p24 },
8395d0bfe44SNeil Armstrong 	{ 94, &meson_hdmi_encp_mode_2160p25 },
8405d0bfe44SNeil Armstrong 	{ 95, &meson_hdmi_encp_mode_2160p30 },
84174f6d1e1SNeil Armstrong 	{ 96, &meson_hdmi_encp_mode_2160p25 },
84274f6d1e1SNeil Armstrong 	{ 97, &meson_hdmi_encp_mode_2160p30 },
843335e3713SNeil Armstrong 	{ 0, NULL}, /* sentinel */
844335e3713SNeil Armstrong };
845335e3713SNeil Armstrong 
846335e3713SNeil Armstrong static signed int to_signed(unsigned int a)
847335e3713SNeil Armstrong {
848335e3713SNeil Armstrong 	if (a <= 7)
849335e3713SNeil Armstrong 		return a;
850335e3713SNeil Armstrong 	else
851335e3713SNeil Armstrong 		return a - 16;
852335e3713SNeil Armstrong }
853335e3713SNeil Armstrong 
854335e3713SNeil Armstrong static unsigned long modulo(unsigned long a, unsigned long b)
855335e3713SNeil Armstrong {
856335e3713SNeil Armstrong 	if (a >= b)
857335e3713SNeil Armstrong 		return a - b;
858335e3713SNeil Armstrong 	else
859335e3713SNeil Armstrong 		return a;
860335e3713SNeil Armstrong }
861335e3713SNeil Armstrong 
8623273fc63SNeil Armstrong enum drm_mode_status
8633273fc63SNeil Armstrong meson_venc_hdmi_supported_mode(const struct drm_display_mode *mode)
8649c936b12SNeil Armstrong {
8653273fc63SNeil Armstrong 	if (mode->flags & ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC |
8663273fc63SNeil Armstrong 			    DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))
8673273fc63SNeil Armstrong 		return MODE_BAD;
8689c936b12SNeil Armstrong 
8693273fc63SNeil Armstrong 	if (mode->hdisplay < 640 || mode->hdisplay > 1920)
8703273fc63SNeil Armstrong 		return MODE_BAD_HVALUE;
8719c936b12SNeil Armstrong 
8723273fc63SNeil Armstrong 	if (mode->vdisplay < 480 || mode->vdisplay > 1200)
8733273fc63SNeil Armstrong 		return MODE_BAD_VVALUE;
8743273fc63SNeil Armstrong 
8753273fc63SNeil Armstrong 	return MODE_OK;
8769c936b12SNeil Armstrong }
8779c936b12SNeil Armstrong EXPORT_SYMBOL_GPL(meson_venc_hdmi_supported_mode);
8789c936b12SNeil Armstrong 
879335e3713SNeil Armstrong bool meson_venc_hdmi_supported_vic(int vic)
880335e3713SNeil Armstrong {
881335e3713SNeil Armstrong 	struct meson_hdmi_venc_vic_mode *vmode = meson_hdmi_venc_vic_modes;
882335e3713SNeil Armstrong 
883335e3713SNeil Armstrong 	while (vmode->vic && vmode->mode) {
884335e3713SNeil Armstrong 		if (vmode->vic == vic)
885335e3713SNeil Armstrong 			return true;
886335e3713SNeil Armstrong 		vmode++;
887335e3713SNeil Armstrong 	}
888335e3713SNeil Armstrong 
889335e3713SNeil Armstrong 	return false;
890335e3713SNeil Armstrong }
891335e3713SNeil Armstrong EXPORT_SYMBOL_GPL(meson_venc_hdmi_supported_vic);
892335e3713SNeil Armstrong 
8933273fc63SNeil Armstrong void meson_venc_hdmi_get_dmt_vmode(const struct drm_display_mode *mode,
8943273fc63SNeil Armstrong 				   union meson_hdmi_venc_mode *dmt_mode)
8959c936b12SNeil Armstrong {
8963273fc63SNeil Armstrong 	memset(dmt_mode, 0, sizeof(*dmt_mode));
8979c936b12SNeil Armstrong 
8983273fc63SNeil Armstrong 	dmt_mode->encp.dvi_settings = 0x21;
8993273fc63SNeil Armstrong 	dmt_mode->encp.video_mode = 0x4040;
9003273fc63SNeil Armstrong 	dmt_mode->encp.video_mode_adv = 0x18;
9013273fc63SNeil Armstrong 	dmt_mode->encp.max_pxcnt = mode->htotal - 1;
9023273fc63SNeil Armstrong 	dmt_mode->encp.havon_begin = mode->htotal - mode->hsync_start;
9033273fc63SNeil Armstrong 	dmt_mode->encp.havon_end = dmt_mode->encp.havon_begin +
9043273fc63SNeil Armstrong 				   mode->hdisplay - 1;
9053273fc63SNeil Armstrong 	dmt_mode->encp.vavon_bline = mode->vtotal - mode->vsync_start;
9063273fc63SNeil Armstrong 	dmt_mode->encp.vavon_eline = dmt_mode->encp.vavon_bline +
9073273fc63SNeil Armstrong 				     mode->vdisplay - 1;
9083273fc63SNeil Armstrong 	dmt_mode->encp.hso_begin = 0;
9093273fc63SNeil Armstrong 	dmt_mode->encp.hso_end = mode->hsync_end - mode->hsync_start;
9103273fc63SNeil Armstrong 	dmt_mode->encp.vso_begin = 30;
9113273fc63SNeil Armstrong 	dmt_mode->encp.vso_end = 50;
9123273fc63SNeil Armstrong 	dmt_mode->encp.vso_bline = 0;
9133273fc63SNeil Armstrong 	dmt_mode->encp.vso_eline = mode->vsync_end - mode->vsync_start;
9143273fc63SNeil Armstrong 	dmt_mode->encp.vso_eline_present = true;
9153273fc63SNeil Armstrong 	dmt_mode->encp.max_lncnt = mode->vtotal - 1;
9169c936b12SNeil Armstrong }
9179c936b12SNeil Armstrong 
918335e3713SNeil Armstrong static union meson_hdmi_venc_mode *meson_venc_hdmi_get_vic_vmode(int vic)
919335e3713SNeil Armstrong {
920335e3713SNeil Armstrong 	struct meson_hdmi_venc_vic_mode *vmode = meson_hdmi_venc_vic_modes;
921335e3713SNeil Armstrong 
922335e3713SNeil Armstrong 	while (vmode->vic && vmode->mode) {
923335e3713SNeil Armstrong 		if (vmode->vic == vic)
924335e3713SNeil Armstrong 			return vmode->mode;
925335e3713SNeil Armstrong 		vmode++;
926335e3713SNeil Armstrong 	}
927335e3713SNeil Armstrong 
928335e3713SNeil Armstrong 	return NULL;
929335e3713SNeil Armstrong }
930335e3713SNeil Armstrong 
931335e3713SNeil Armstrong bool meson_venc_hdmi_venc_repeat(int vic)
932335e3713SNeil Armstrong {
933335e3713SNeil Armstrong 	/* Repeat VENC pixels for 480/576i/p, 720p50/60 and 1080p50/60 */
934335e3713SNeil Armstrong 	if (vic == 6 || vic == 7 || /* 480i */
935335e3713SNeil Armstrong 	    vic == 21 || vic == 22 || /* 576i */
936335e3713SNeil Armstrong 	    vic == 17 || vic == 18 || /* 576p */
937335e3713SNeil Armstrong 	    vic == 2 || vic == 3 || /* 480p */
938335e3713SNeil Armstrong 	    vic == 4 || /* 720p60 */
939335e3713SNeil Armstrong 	    vic == 19 || /* 720p50 */
940335e3713SNeil Armstrong 	    vic == 5 || /* 1080i60 */
941335e3713SNeil Armstrong 	    vic == 20)	/* 1080i50 */
942335e3713SNeil Armstrong 		return true;
943335e3713SNeil Armstrong 
944335e3713SNeil Armstrong 	return false;
945335e3713SNeil Armstrong }
946335e3713SNeil Armstrong EXPORT_SYMBOL_GPL(meson_venc_hdmi_venc_repeat);
947335e3713SNeil Armstrong 
948335e3713SNeil Armstrong void meson_venc_hdmi_mode_set(struct meson_drm *priv, int vic,
949335e3713SNeil Armstrong 			      struct drm_display_mode *mode)
950335e3713SNeil Armstrong {
951335e3713SNeil Armstrong 	union meson_hdmi_venc_mode *vmode = NULL;
9523273fc63SNeil Armstrong 	union meson_hdmi_venc_mode vmode_dmt;
953335e3713SNeil Armstrong 	bool use_enci = false;
954335e3713SNeil Armstrong 	bool venc_repeat = false;
955335e3713SNeil Armstrong 	bool hdmi_repeat = false;
956335e3713SNeil Armstrong 	unsigned int venc_hdmi_latency = 2;
957335e3713SNeil Armstrong 	unsigned long total_pixels_venc = 0;
958335e3713SNeil Armstrong 	unsigned long active_pixels_venc = 0;
959335e3713SNeil Armstrong 	unsigned long front_porch_venc = 0;
960335e3713SNeil Armstrong 	unsigned long hsync_pixels_venc = 0;
961335e3713SNeil Armstrong 	unsigned long de_h_begin = 0;
962335e3713SNeil Armstrong 	unsigned long de_h_end = 0;
963335e3713SNeil Armstrong 	unsigned long de_v_begin_even = 0;
964335e3713SNeil Armstrong 	unsigned long de_v_end_even = 0;
965335e3713SNeil Armstrong 	unsigned long de_v_begin_odd = 0;
966335e3713SNeil Armstrong 	unsigned long de_v_end_odd = 0;
967335e3713SNeil Armstrong 	unsigned long hs_begin = 0;
968335e3713SNeil Armstrong 	unsigned long hs_end = 0;
969335e3713SNeil Armstrong 	unsigned long vs_adjust = 0;
970335e3713SNeil Armstrong 	unsigned long vs_bline_evn = 0;
971335e3713SNeil Armstrong 	unsigned long vs_eline_evn = 0;
972335e3713SNeil Armstrong 	unsigned long vs_bline_odd = 0;
973335e3713SNeil Armstrong 	unsigned long vs_eline_odd = 0;
974335e3713SNeil Armstrong 	unsigned long vso_begin_evn = 0;
975335e3713SNeil Armstrong 	unsigned long vso_begin_odd = 0;
976335e3713SNeil Armstrong 	unsigned int eof_lines;
977335e3713SNeil Armstrong 	unsigned int sof_lines;
978335e3713SNeil Armstrong 	unsigned int vsync_lines;
979335e3713SNeil Armstrong 
980adf59dd2SJorge Ramirez-Ortiz 	/* Use VENCI for 480i and 576i and double HDMI pixels */
981adf59dd2SJorge Ramirez-Ortiz 	if (mode->flags & DRM_MODE_FLAG_DBLCLK) {
982adf59dd2SJorge Ramirez-Ortiz 		hdmi_repeat = true;
983adf59dd2SJorge Ramirez-Ortiz 		use_enci = true;
984adf59dd2SJorge Ramirez-Ortiz 		venc_hdmi_latency = 1;
985adf59dd2SJorge Ramirez-Ortiz 	}
986adf59dd2SJorge Ramirez-Ortiz 
9873273fc63SNeil Armstrong 	if (meson_venc_hdmi_supported_vic(vic)) {
988335e3713SNeil Armstrong 		vmode = meson_venc_hdmi_get_vic_vmode(vic);
989335e3713SNeil Armstrong 		if (!vmode) {
9909c936b12SNeil Armstrong 			dev_err(priv->dev, "%s: Fatal Error, unsupported mode "
9913273fc63SNeil Armstrong 				DRM_MODE_FMT "\n", __func__,
9923273fc63SNeil Armstrong 				DRM_MODE_ARG(mode));
993335e3713SNeil Armstrong 			return;
994335e3713SNeil Armstrong 		}
9953273fc63SNeil Armstrong 	} else {
9963273fc63SNeil Armstrong 		meson_venc_hdmi_get_dmt_vmode(mode, &vmode_dmt);
9973273fc63SNeil Armstrong 		vmode = &vmode_dmt;
998adf59dd2SJorge Ramirez-Ortiz 		use_enci = false;
999335e3713SNeil Armstrong 	}
1000335e3713SNeil Armstrong 
1001335e3713SNeil Armstrong 	/* Repeat VENC pixels for 480/576i/p, 720p50/60 and 1080p50/60 */
1002335e3713SNeil Armstrong 	if (meson_venc_hdmi_venc_repeat(vic))
1003335e3713SNeil Armstrong 		venc_repeat = true;
1004335e3713SNeil Armstrong 
1005335e3713SNeil Armstrong 	eof_lines = mode->vsync_start - mode->vdisplay;
1006335e3713SNeil Armstrong 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1007335e3713SNeil Armstrong 		eof_lines /= 2;
1008335e3713SNeil Armstrong 	sof_lines = mode->vtotal - mode->vsync_end;
1009335e3713SNeil Armstrong 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1010335e3713SNeil Armstrong 		sof_lines /= 2;
1011335e3713SNeil Armstrong 	vsync_lines = mode->vsync_end - mode->vsync_start;
1012335e3713SNeil Armstrong 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1013335e3713SNeil Armstrong 		vsync_lines /= 2;
1014335e3713SNeil Armstrong 
1015335e3713SNeil Armstrong 	total_pixels_venc = mode->htotal;
1016335e3713SNeil Armstrong 	if (hdmi_repeat)
1017335e3713SNeil Armstrong 		total_pixels_venc /= 2;
1018335e3713SNeil Armstrong 	if (venc_repeat)
1019335e3713SNeil Armstrong 		total_pixels_venc *= 2;
1020335e3713SNeil Armstrong 
1021335e3713SNeil Armstrong 	active_pixels_venc = mode->hdisplay;
1022335e3713SNeil Armstrong 	if (hdmi_repeat)
1023335e3713SNeil Armstrong 		active_pixels_venc /= 2;
1024335e3713SNeil Armstrong 	if (venc_repeat)
1025335e3713SNeil Armstrong 		active_pixels_venc *= 2;
1026335e3713SNeil Armstrong 
1027335e3713SNeil Armstrong 	front_porch_venc = (mode->hsync_start - mode->hdisplay);
1028335e3713SNeil Armstrong 	if (hdmi_repeat)
1029335e3713SNeil Armstrong 		front_porch_venc /= 2;
1030335e3713SNeil Armstrong 	if (venc_repeat)
1031335e3713SNeil Armstrong 		front_porch_venc *= 2;
1032335e3713SNeil Armstrong 
1033335e3713SNeil Armstrong 	hsync_pixels_venc = (mode->hsync_end - mode->hsync_start);
1034335e3713SNeil Armstrong 	if (hdmi_repeat)
1035335e3713SNeil Armstrong 		hsync_pixels_venc /= 2;
1036335e3713SNeil Armstrong 	if (venc_repeat)
1037335e3713SNeil Armstrong 		hsync_pixels_venc *= 2;
1038335e3713SNeil Armstrong 
1039335e3713SNeil Armstrong 	/* Disable VDACs */
10409c936b12SNeil Armstrong 	writel_bits_relaxed(0xff, 0xff,
1041335e3713SNeil Armstrong 			priv->io_base + _REG(VENC_VDAC_SETTING));
1042335e3713SNeil Armstrong 
1043335e3713SNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_EN));
1044335e3713SNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(ENCP_VIDEO_EN));
1045335e3713SNeil Armstrong 
1046335e3713SNeil Armstrong 	if (use_enci) {
1047335e3713SNeil Armstrong 		unsigned int lines_f0;
1048335e3713SNeil Armstrong 		unsigned int lines_f1;
1049335e3713SNeil Armstrong 
1050335e3713SNeil Armstrong 		/* CVBS Filter settings */
1051335e3713SNeil Armstrong 		writel_relaxed(0x12, priv->io_base + _REG(ENCI_CFILT_CTRL));
1052335e3713SNeil Armstrong 		writel_relaxed(0x12, priv->io_base + _REG(ENCI_CFILT_CTRL2));
1053335e3713SNeil Armstrong 
1054335e3713SNeil Armstrong 		/* Digital Video Select : Interlace, clk27 clk, external */
1055335e3713SNeil Armstrong 		writel_relaxed(0, priv->io_base + _REG(VENC_DVI_SETTING));
1056335e3713SNeil Armstrong 
1057335e3713SNeil Armstrong 		/* Reset Video Mode */
1058335e3713SNeil Armstrong 		writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_MODE));
1059335e3713SNeil Armstrong 		writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_MODE_ADV));
1060335e3713SNeil Armstrong 
1061335e3713SNeil Armstrong 		/* Horizontal sync signal output */
1062335e3713SNeil Armstrong 		writel_relaxed(vmode->enci.hso_begin,
1063335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_SYNC_HSO_BEGIN));
1064335e3713SNeil Armstrong 		writel_relaxed(vmode->enci.hso_end,
1065335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_SYNC_HSO_END));
1066335e3713SNeil Armstrong 
1067335e3713SNeil Armstrong 		/* Vertical Sync lines */
1068335e3713SNeil Armstrong 		writel_relaxed(vmode->enci.vso_even,
1069335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_SYNC_VSO_EVNLN));
1070335e3713SNeil Armstrong 		writel_relaxed(vmode->enci.vso_odd,
1071335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_SYNC_VSO_ODDLN));
1072335e3713SNeil Armstrong 
1073335e3713SNeil Armstrong 		/* Macrovision max amplitude change */
1074335e3713SNeil Armstrong 		writel_relaxed(vmode->enci.macv_max_amp,
1075335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_MACV_MAX_AMP));
1076335e3713SNeil Armstrong 
1077335e3713SNeil Armstrong 		/* Video mode */
1078335e3713SNeil Armstrong 		writel_relaxed(vmode->enci.video_prog_mode,
1079335e3713SNeil Armstrong 				priv->io_base + _REG(VENC_VIDEO_PROG_MODE));
1080335e3713SNeil Armstrong 		writel_relaxed(vmode->enci.video_mode,
1081335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_VIDEO_MODE));
1082335e3713SNeil Armstrong 
1083335e3713SNeil Armstrong 		/* Advanced Video Mode :
1084335e3713SNeil Armstrong 		 * Demux shifting 0x2
1085335e3713SNeil Armstrong 		 * Blank line end at line17/22
1086335e3713SNeil Armstrong 		 * High bandwidth Luma Filter
1087335e3713SNeil Armstrong 		 * Low bandwidth Chroma Filter
1088335e3713SNeil Armstrong 		 * Bypass luma low pass filter
1089335e3713SNeil Armstrong 		 * No macrovision on CSYNC
1090335e3713SNeil Armstrong 		 */
1091335e3713SNeil Armstrong 		writel_relaxed(0x26, priv->io_base + _REG(ENCI_VIDEO_MODE_ADV));
1092335e3713SNeil Armstrong 
1093335e3713SNeil Armstrong 		writel(vmode->enci.sch_adjust,
1094335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_VIDEO_SCH));
1095335e3713SNeil Armstrong 
1096335e3713SNeil Armstrong 		/* Sync mode : MASTER Master mode, free run, send HSO/VSO out */
1097335e3713SNeil Armstrong 		writel_relaxed(0x07, priv->io_base + _REG(ENCI_SYNC_MODE));
1098335e3713SNeil Armstrong 
1099335e3713SNeil Armstrong 		if (vmode->enci.yc_delay)
1100335e3713SNeil Armstrong 			writel_relaxed(vmode->enci.yc_delay,
1101335e3713SNeil Armstrong 					priv->io_base + _REG(ENCI_YC_DELAY));
1102335e3713SNeil Armstrong 
1103335e3713SNeil Armstrong 
1104335e3713SNeil Armstrong 		/* UNreset Interlaced TV Encoder */
1105335e3713SNeil Armstrong 		writel_relaxed(0, priv->io_base + _REG(ENCI_DBG_PX_RST));
1106335e3713SNeil Armstrong 
1107335e3713SNeil Armstrong 		/* Enable Vfifo2vd, Y_Cb_Y_Cr select */
1108335e3713SNeil Armstrong 		writel_relaxed(0x4e01, priv->io_base + _REG(ENCI_VFIFO2VD_CTL));
1109335e3713SNeil Armstrong 
1110335e3713SNeil Armstrong 		/* Timings */
1111335e3713SNeil Armstrong 		writel_relaxed(vmode->enci.pixel_start,
1112335e3713SNeil Armstrong 			priv->io_base + _REG(ENCI_VFIFO2VD_PIXEL_START));
1113335e3713SNeil Armstrong 		writel_relaxed(vmode->enci.pixel_end,
1114335e3713SNeil Armstrong 			priv->io_base + _REG(ENCI_VFIFO2VD_PIXEL_END));
1115335e3713SNeil Armstrong 
1116335e3713SNeil Armstrong 		writel_relaxed(vmode->enci.top_field_line_start,
1117335e3713SNeil Armstrong 			priv->io_base + _REG(ENCI_VFIFO2VD_LINE_TOP_START));
1118335e3713SNeil Armstrong 		writel_relaxed(vmode->enci.top_field_line_end,
1119335e3713SNeil Armstrong 			priv->io_base + _REG(ENCI_VFIFO2VD_LINE_TOP_END));
1120335e3713SNeil Armstrong 
1121335e3713SNeil Armstrong 		writel_relaxed(vmode->enci.bottom_field_line_start,
1122335e3713SNeil Armstrong 			priv->io_base + _REG(ENCI_VFIFO2VD_LINE_BOT_START));
1123335e3713SNeil Armstrong 		writel_relaxed(vmode->enci.bottom_field_line_end,
1124335e3713SNeil Armstrong 			priv->io_base + _REG(ENCI_VFIFO2VD_LINE_BOT_END));
1125335e3713SNeil Armstrong 
1126335e3713SNeil Armstrong 		/* Select ENCI for VIU */
1127335e3713SNeil Armstrong 		meson_vpp_setup_mux(priv, MESON_VIU_VPP_MUX_ENCI);
1128335e3713SNeil Armstrong 
1129335e3713SNeil Armstrong 		/* Interlace video enable */
1130335e3713SNeil Armstrong 		writel_relaxed(1, priv->io_base + _REG(ENCI_VIDEO_EN));
1131335e3713SNeil Armstrong 
1132335e3713SNeil Armstrong 		lines_f0 = mode->vtotal >> 1;
1133335e3713SNeil Armstrong 		lines_f1 = lines_f0 + 1;
1134335e3713SNeil Armstrong 
1135335e3713SNeil Armstrong 		de_h_begin = modulo(readl_relaxed(priv->io_base +
1136335e3713SNeil Armstrong 					_REG(ENCI_VFIFO2VD_PIXEL_START))
1137335e3713SNeil Armstrong 					+ venc_hdmi_latency,
1138335e3713SNeil Armstrong 				    total_pixels_venc);
1139335e3713SNeil Armstrong 		de_h_end  = modulo(de_h_begin + active_pixels_venc,
1140335e3713SNeil Armstrong 				   total_pixels_venc);
1141335e3713SNeil Armstrong 
1142335e3713SNeil Armstrong 		writel_relaxed(de_h_begin,
1143335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DE_H_BEGIN));
1144335e3713SNeil Armstrong 		writel_relaxed(de_h_end,
1145335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DE_H_END));
1146335e3713SNeil Armstrong 
1147335e3713SNeil Armstrong 		de_v_begin_even = readl_relaxed(priv->io_base +
1148335e3713SNeil Armstrong 					_REG(ENCI_VFIFO2VD_LINE_TOP_START));
1149335e3713SNeil Armstrong 		de_v_end_even  = de_v_begin_even + mode->vdisplay;
1150335e3713SNeil Armstrong 		de_v_begin_odd = readl_relaxed(priv->io_base +
1151335e3713SNeil Armstrong 					_REG(ENCI_VFIFO2VD_LINE_BOT_START));
1152335e3713SNeil Armstrong 		de_v_end_odd = de_v_begin_odd + mode->vdisplay;
1153335e3713SNeil Armstrong 
1154335e3713SNeil Armstrong 		writel_relaxed(de_v_begin_even,
1155335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DE_V_BEGIN_EVEN));
1156335e3713SNeil Armstrong 		writel_relaxed(de_v_end_even,
1157335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DE_V_END_EVEN));
1158335e3713SNeil Armstrong 		writel_relaxed(de_v_begin_odd,
1159335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DE_V_BEGIN_ODD));
1160335e3713SNeil Armstrong 		writel_relaxed(de_v_end_odd,
1161335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DE_V_END_ODD));
1162335e3713SNeil Armstrong 
1163335e3713SNeil Armstrong 		/* Program Hsync timing */
1164335e3713SNeil Armstrong 		hs_begin = de_h_end + front_porch_venc;
1165335e3713SNeil Armstrong 		if (de_h_end + front_porch_venc >= total_pixels_venc) {
1166335e3713SNeil Armstrong 			hs_begin -= total_pixels_venc;
1167335e3713SNeil Armstrong 			vs_adjust  = 1;
1168335e3713SNeil Armstrong 		} else {
1169335e3713SNeil Armstrong 			hs_begin = de_h_end + front_porch_venc;
1170335e3713SNeil Armstrong 			vs_adjust  = 0;
1171335e3713SNeil Armstrong 		}
1172335e3713SNeil Armstrong 
1173335e3713SNeil Armstrong 		hs_end = modulo(hs_begin + hsync_pixels_venc,
1174335e3713SNeil Armstrong 				total_pixels_venc);
1175335e3713SNeil Armstrong 		writel_relaxed(hs_begin,
1176335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DVI_HSO_BEGIN));
1177335e3713SNeil Armstrong 		writel_relaxed(hs_end,
1178335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DVI_HSO_END));
1179335e3713SNeil Armstrong 
1180335e3713SNeil Armstrong 		/* Program Vsync timing for even field */
1181335e3713SNeil Armstrong 		if (((de_v_end_odd - 1) + eof_lines + vs_adjust) >= lines_f1) {
1182335e3713SNeil Armstrong 			vs_bline_evn = (de_v_end_odd - 1)
1183335e3713SNeil Armstrong 					+ eof_lines
1184335e3713SNeil Armstrong 					+ vs_adjust
1185335e3713SNeil Armstrong 					- lines_f1;
1186335e3713SNeil Armstrong 			vs_eline_evn = vs_bline_evn + vsync_lines;
1187335e3713SNeil Armstrong 
1188335e3713SNeil Armstrong 			writel_relaxed(vs_bline_evn,
1189335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DVI_VSO_BLINE_EVN));
1190335e3713SNeil Armstrong 
1191335e3713SNeil Armstrong 			writel_relaxed(vs_eline_evn,
1192335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DVI_VSO_ELINE_EVN));
1193335e3713SNeil Armstrong 
1194335e3713SNeil Armstrong 			writel_relaxed(hs_begin,
1195335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DVI_VSO_BEGIN_EVN));
1196335e3713SNeil Armstrong 			writel_relaxed(hs_begin,
1197335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DVI_VSO_END_EVN));
1198335e3713SNeil Armstrong 		} else {
1199335e3713SNeil Armstrong 			vs_bline_odd = (de_v_end_odd - 1)
1200335e3713SNeil Armstrong 					+ eof_lines
1201335e3713SNeil Armstrong 					+ vs_adjust;
1202335e3713SNeil Armstrong 
1203335e3713SNeil Armstrong 			writel_relaxed(vs_bline_odd,
1204335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DVI_VSO_BLINE_ODD));
1205335e3713SNeil Armstrong 
1206335e3713SNeil Armstrong 			writel_relaxed(hs_begin,
1207335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DVI_VSO_BEGIN_ODD));
1208335e3713SNeil Armstrong 
1209335e3713SNeil Armstrong 			if ((vs_bline_odd + vsync_lines) >= lines_f1) {
1210335e3713SNeil Armstrong 				vs_eline_evn = vs_bline_odd
1211335e3713SNeil Armstrong 						+ vsync_lines
1212335e3713SNeil Armstrong 						- lines_f1;
1213335e3713SNeil Armstrong 
1214335e3713SNeil Armstrong 				writel_relaxed(vs_eline_evn, priv->io_base
1215335e3713SNeil Armstrong 						+ _REG(ENCI_DVI_VSO_ELINE_EVN));
1216335e3713SNeil Armstrong 
1217335e3713SNeil Armstrong 				writel_relaxed(hs_begin, priv->io_base
1218335e3713SNeil Armstrong 						+ _REG(ENCI_DVI_VSO_END_EVN));
1219335e3713SNeil Armstrong 			} else {
1220335e3713SNeil Armstrong 				vs_eline_odd = vs_bline_odd
1221335e3713SNeil Armstrong 						+ vsync_lines;
1222335e3713SNeil Armstrong 
1223335e3713SNeil Armstrong 				writel_relaxed(vs_eline_odd, priv->io_base
1224335e3713SNeil Armstrong 						+ _REG(ENCI_DVI_VSO_ELINE_ODD));
1225335e3713SNeil Armstrong 
1226335e3713SNeil Armstrong 				writel_relaxed(hs_begin, priv->io_base
1227335e3713SNeil Armstrong 						+ _REG(ENCI_DVI_VSO_END_ODD));
1228335e3713SNeil Armstrong 			}
1229335e3713SNeil Armstrong 		}
1230335e3713SNeil Armstrong 
1231335e3713SNeil Armstrong 		/* Program Vsync timing for odd field */
1232335e3713SNeil Armstrong 		if (((de_v_end_even - 1) + (eof_lines + 1)) >= lines_f0) {
1233335e3713SNeil Armstrong 			vs_bline_odd = (de_v_end_even - 1)
1234335e3713SNeil Armstrong 					+ (eof_lines + 1)
1235335e3713SNeil Armstrong 					- lines_f0;
1236335e3713SNeil Armstrong 			vs_eline_odd = vs_bline_odd + vsync_lines;
1237335e3713SNeil Armstrong 
1238335e3713SNeil Armstrong 			writel_relaxed(vs_bline_odd,
1239335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DVI_VSO_BLINE_ODD));
1240335e3713SNeil Armstrong 
1241335e3713SNeil Armstrong 			writel_relaxed(vs_eline_odd,
1242335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DVI_VSO_ELINE_ODD));
1243335e3713SNeil Armstrong 
1244335e3713SNeil Armstrong 			vso_begin_odd  = modulo(hs_begin
1245335e3713SNeil Armstrong 						+ (total_pixels_venc >> 1),
1246335e3713SNeil Armstrong 						total_pixels_venc);
1247335e3713SNeil Armstrong 
1248335e3713SNeil Armstrong 			writel_relaxed(vso_begin_odd,
1249335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DVI_VSO_BEGIN_ODD));
1250335e3713SNeil Armstrong 			writel_relaxed(vso_begin_odd,
1251335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DVI_VSO_END_ODD));
1252335e3713SNeil Armstrong 		} else {
1253335e3713SNeil Armstrong 			vs_bline_evn = (de_v_end_even - 1)
1254335e3713SNeil Armstrong 					+ (eof_lines + 1);
1255335e3713SNeil Armstrong 
1256335e3713SNeil Armstrong 			writel_relaxed(vs_bline_evn,
1257335e3713SNeil Armstrong 				priv->io_base + _REG(ENCI_DVI_VSO_BLINE_EVN));
1258335e3713SNeil Armstrong 
1259335e3713SNeil Armstrong 			vso_begin_evn  = modulo(hs_begin
1260335e3713SNeil Armstrong 						+ (total_pixels_venc >> 1),
1261335e3713SNeil Armstrong 						total_pixels_venc);
1262335e3713SNeil Armstrong 
1263335e3713SNeil Armstrong 			writel_relaxed(vso_begin_evn, priv->io_base
1264335e3713SNeil Armstrong 					+ _REG(ENCI_DVI_VSO_BEGIN_EVN));
1265335e3713SNeil Armstrong 
1266335e3713SNeil Armstrong 			if (vs_bline_evn + vsync_lines >= lines_f0) {
1267335e3713SNeil Armstrong 				vs_eline_odd = vs_bline_evn
1268335e3713SNeil Armstrong 						+ vsync_lines
1269335e3713SNeil Armstrong 						- lines_f0;
1270335e3713SNeil Armstrong 
1271335e3713SNeil Armstrong 				writel_relaxed(vs_eline_odd, priv->io_base
1272335e3713SNeil Armstrong 						+ _REG(ENCI_DVI_VSO_ELINE_ODD));
1273335e3713SNeil Armstrong 
1274335e3713SNeil Armstrong 				writel_relaxed(vso_begin_evn, priv->io_base
1275335e3713SNeil Armstrong 						+ _REG(ENCI_DVI_VSO_END_ODD));
1276335e3713SNeil Armstrong 			} else {
1277335e3713SNeil Armstrong 				vs_eline_evn = vs_bline_evn + vsync_lines;
1278335e3713SNeil Armstrong 
1279335e3713SNeil Armstrong 				writel_relaxed(vs_eline_evn, priv->io_base
1280335e3713SNeil Armstrong 						+ _REG(ENCI_DVI_VSO_ELINE_EVN));
1281335e3713SNeil Armstrong 
1282335e3713SNeil Armstrong 				writel_relaxed(vso_begin_evn, priv->io_base
1283335e3713SNeil Armstrong 						+ _REG(ENCI_DVI_VSO_END_EVN));
1284335e3713SNeil Armstrong 			}
1285335e3713SNeil Armstrong 		}
1286335e3713SNeil Armstrong 	} else {
1287335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.dvi_settings,
1288335e3713SNeil Armstrong 				priv->io_base + _REG(VENC_DVI_SETTING));
1289335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.video_mode,
1290335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_MODE));
1291335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.video_mode_adv,
1292335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_MODE_ADV));
1293335e3713SNeil Armstrong 		if (vmode->encp.video_prog_mode_present)
1294335e3713SNeil Armstrong 			writel_relaxed(vmode->encp.video_prog_mode,
1295335e3713SNeil Armstrong 				priv->io_base + _REG(VENC_VIDEO_PROG_MODE));
1296335e3713SNeil Armstrong 		if (vmode->encp.video_sync_mode_present)
1297335e3713SNeil Armstrong 			writel_relaxed(vmode->encp.video_sync_mode,
1298335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_SYNC_MODE));
1299335e3713SNeil Armstrong 		if (vmode->encp.video_yc_dly_present)
1300335e3713SNeil Armstrong 			writel_relaxed(vmode->encp.video_yc_dly,
1301335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_YC_DLY));
1302335e3713SNeil Armstrong 		if (vmode->encp.video_rgb_ctrl_present)
1303335e3713SNeil Armstrong 			writel_relaxed(vmode->encp.video_rgb_ctrl,
1304335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_RGB_CTRL));
1305335e3713SNeil Armstrong 		if (vmode->encp.video_filt_ctrl_present)
1306335e3713SNeil Armstrong 			writel_relaxed(vmode->encp.video_filt_ctrl,
1307335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_FILT_CTRL));
1308335e3713SNeil Armstrong 		if (vmode->encp.video_ofld_voav_ofst_present)
1309335e3713SNeil Armstrong 			writel_relaxed(vmode->encp.video_ofld_voav_ofst,
1310335e3713SNeil Armstrong 				priv->io_base
1311335e3713SNeil Armstrong 				+ _REG(ENCP_VIDEO_OFLD_VOAV_OFST));
1312335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.yfp1_htime,
1313335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_YFP1_HTIME));
1314335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.yfp2_htime,
1315335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_YFP2_HTIME));
1316335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.max_pxcnt,
1317335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_MAX_PXCNT));
1318335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.hspuls_begin,
1319335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_HSPULS_BEGIN));
1320335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.hspuls_end,
1321335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_HSPULS_END));
1322335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.hspuls_switch,
1323335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_HSPULS_SWITCH));
1324335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.vspuls_begin,
1325335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_VSPULS_BEGIN));
1326335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.vspuls_end,
1327335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_VSPULS_END));
1328335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.vspuls_bline,
1329335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_VSPULS_BLINE));
1330335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.vspuls_eline,
1331335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_VSPULS_ELINE));
1332335e3713SNeil Armstrong 		if (vmode->encp.eqpuls_begin_present)
1333335e3713SNeil Armstrong 			writel_relaxed(vmode->encp.eqpuls_begin,
1334335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_EQPULS_BEGIN));
1335335e3713SNeil Armstrong 		if (vmode->encp.eqpuls_end_present)
1336335e3713SNeil Armstrong 			writel_relaxed(vmode->encp.eqpuls_end,
1337335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_EQPULS_END));
1338335e3713SNeil Armstrong 		if (vmode->encp.eqpuls_bline_present)
1339335e3713SNeil Armstrong 			writel_relaxed(vmode->encp.eqpuls_bline,
1340335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_EQPULS_BLINE));
1341335e3713SNeil Armstrong 		if (vmode->encp.eqpuls_eline_present)
1342335e3713SNeil Armstrong 			writel_relaxed(vmode->encp.eqpuls_eline,
1343335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_EQPULS_ELINE));
1344335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.havon_begin,
1345335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_HAVON_BEGIN));
1346335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.havon_end,
1347335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_HAVON_END));
1348335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.vavon_bline,
1349335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_VAVON_BLINE));
1350335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.vavon_eline,
1351335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_VAVON_ELINE));
1352335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.hso_begin,
1353335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_HSO_BEGIN));
1354335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.hso_end,
1355335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_HSO_END));
1356335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.vso_begin,
1357335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_VSO_BEGIN));
1358335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.vso_end,
1359335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_VSO_END));
1360335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.vso_bline,
1361335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_VSO_BLINE));
1362335e3713SNeil Armstrong 		if (vmode->encp.vso_eline_present)
1363335e3713SNeil Armstrong 			writel_relaxed(vmode->encp.vso_eline,
1364335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_VSO_ELINE));
1365335e3713SNeil Armstrong 		if (vmode->encp.sy_val_present)
1366335e3713SNeil Armstrong 			writel_relaxed(vmode->encp.sy_val,
1367335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_SY_VAL));
1368335e3713SNeil Armstrong 		if (vmode->encp.sy2_val_present)
1369335e3713SNeil Armstrong 			writel_relaxed(vmode->encp.sy2_val,
1370335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_SY2_VAL));
1371335e3713SNeil Armstrong 		writel_relaxed(vmode->encp.max_lncnt,
1372335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_VIDEO_MAX_LNCNT));
1373335e3713SNeil Armstrong 
1374335e3713SNeil Armstrong 		writel_relaxed(1, priv->io_base + _REG(ENCP_VIDEO_EN));
1375335e3713SNeil Armstrong 
1376335e3713SNeil Armstrong 		/* Set DE signal’s polarity is active high */
1377335e3713SNeil Armstrong 		writel_bits_relaxed(BIT(14), BIT(14),
1378335e3713SNeil Armstrong 				    priv->io_base + _REG(ENCP_VIDEO_MODE));
1379335e3713SNeil Armstrong 
1380335e3713SNeil Armstrong 		/* Program DE timing */
1381335e3713SNeil Armstrong 		de_h_begin = modulo(readl_relaxed(priv->io_base +
1382335e3713SNeil Armstrong 					_REG(ENCP_VIDEO_HAVON_BEGIN))
1383335e3713SNeil Armstrong 					+ venc_hdmi_latency,
1384335e3713SNeil Armstrong 				    total_pixels_venc);
1385335e3713SNeil Armstrong 		de_h_end = modulo(de_h_begin + active_pixels_venc,
1386335e3713SNeil Armstrong 				  total_pixels_venc);
1387335e3713SNeil Armstrong 
1388335e3713SNeil Armstrong 		writel_relaxed(de_h_begin,
1389335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_DE_H_BEGIN));
1390335e3713SNeil Armstrong 		writel_relaxed(de_h_end,
1391335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_DE_H_END));
1392335e3713SNeil Armstrong 
1393335e3713SNeil Armstrong 		/* Program DE timing for even field */
1394335e3713SNeil Armstrong 		de_v_begin_even = readl_relaxed(priv->io_base
1395335e3713SNeil Armstrong 						+ _REG(ENCP_VIDEO_VAVON_BLINE));
1396335e3713SNeil Armstrong 		if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1397335e3713SNeil Armstrong 			de_v_end_even = de_v_begin_even +
1398335e3713SNeil Armstrong 					(mode->vdisplay / 2);
1399335e3713SNeil Armstrong 		else
1400335e3713SNeil Armstrong 			de_v_end_even = de_v_begin_even + mode->vdisplay;
1401335e3713SNeil Armstrong 
1402335e3713SNeil Armstrong 		writel_relaxed(de_v_begin_even,
1403335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_DE_V_BEGIN_EVEN));
1404335e3713SNeil Armstrong 		writel_relaxed(de_v_end_even,
1405335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_DE_V_END_EVEN));
1406335e3713SNeil Armstrong 
1407335e3713SNeil Armstrong 		/* Program DE timing for odd field if needed */
1408335e3713SNeil Armstrong 		if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
1409335e3713SNeil Armstrong 			unsigned int ofld_voav_ofst =
1410335e3713SNeil Armstrong 				readl_relaxed(priv->io_base +
1411335e3713SNeil Armstrong 					_REG(ENCP_VIDEO_OFLD_VOAV_OFST));
1412335e3713SNeil Armstrong 			de_v_begin_odd = to_signed((ofld_voav_ofst & 0xf0) >> 4)
1413335e3713SNeil Armstrong 						+ de_v_begin_even
1414335e3713SNeil Armstrong 						+ ((mode->vtotal - 1) / 2);
1415335e3713SNeil Armstrong 			de_v_end_odd = de_v_begin_odd + (mode->vdisplay / 2);
1416335e3713SNeil Armstrong 
1417335e3713SNeil Armstrong 			writel_relaxed(de_v_begin_odd,
1418335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_DE_V_BEGIN_ODD));
1419335e3713SNeil Armstrong 			writel_relaxed(de_v_end_odd,
1420335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_DE_V_END_ODD));
1421335e3713SNeil Armstrong 		}
1422335e3713SNeil Armstrong 
1423335e3713SNeil Armstrong 		/* Program Hsync timing */
1424335e3713SNeil Armstrong 		if ((de_h_end + front_porch_venc) >= total_pixels_venc) {
1425335e3713SNeil Armstrong 			hs_begin = de_h_end
1426335e3713SNeil Armstrong 				   + front_porch_venc
1427335e3713SNeil Armstrong 				   - total_pixels_venc;
1428335e3713SNeil Armstrong 			vs_adjust  = 1;
1429335e3713SNeil Armstrong 		} else {
1430335e3713SNeil Armstrong 			hs_begin = de_h_end
1431335e3713SNeil Armstrong 				   + front_porch_venc;
1432335e3713SNeil Armstrong 			vs_adjust  = 0;
1433335e3713SNeil Armstrong 		}
1434335e3713SNeil Armstrong 
1435335e3713SNeil Armstrong 		hs_end = modulo(hs_begin + hsync_pixels_venc,
1436335e3713SNeil Armstrong 				total_pixels_venc);
1437335e3713SNeil Armstrong 
1438335e3713SNeil Armstrong 		writel_relaxed(hs_begin,
1439335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_DVI_HSO_BEGIN));
1440335e3713SNeil Armstrong 		writel_relaxed(hs_end,
1441335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_DVI_HSO_END));
1442335e3713SNeil Armstrong 
1443335e3713SNeil Armstrong 		/* Program Vsync timing for even field */
1444335e3713SNeil Armstrong 		if (de_v_begin_even >=
1445335e3713SNeil Armstrong 				(sof_lines + vsync_lines + (1 - vs_adjust)))
1446335e3713SNeil Armstrong 			vs_bline_evn = de_v_begin_even
1447335e3713SNeil Armstrong 					- sof_lines
1448335e3713SNeil Armstrong 					- vsync_lines
1449335e3713SNeil Armstrong 					- (1 - vs_adjust);
1450335e3713SNeil Armstrong 		else
1451335e3713SNeil Armstrong 			vs_bline_evn = mode->vtotal
1452335e3713SNeil Armstrong 					+ de_v_begin_even
1453335e3713SNeil Armstrong 					- sof_lines
1454335e3713SNeil Armstrong 					- vsync_lines
1455335e3713SNeil Armstrong 					- (1 - vs_adjust);
1456335e3713SNeil Armstrong 
1457335e3713SNeil Armstrong 		vs_eline_evn = modulo(vs_bline_evn + vsync_lines,
1458335e3713SNeil Armstrong 					mode->vtotal);
1459335e3713SNeil Armstrong 
1460335e3713SNeil Armstrong 		writel_relaxed(vs_bline_evn,
1461335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_DVI_VSO_BLINE_EVN));
1462335e3713SNeil Armstrong 		writel_relaxed(vs_eline_evn,
1463335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_DVI_VSO_ELINE_EVN));
1464335e3713SNeil Armstrong 
1465335e3713SNeil Armstrong 		vso_begin_evn = hs_begin;
1466335e3713SNeil Armstrong 		writel_relaxed(vso_begin_evn,
1467335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_DVI_VSO_BEGIN_EVN));
1468335e3713SNeil Armstrong 		writel_relaxed(vso_begin_evn,
1469335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_DVI_VSO_END_EVN));
1470335e3713SNeil Armstrong 
1471335e3713SNeil Armstrong 		/* Program Vsync timing for odd field if needed */
1472335e3713SNeil Armstrong 		if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
1473335e3713SNeil Armstrong 			vs_bline_odd = (de_v_begin_odd - 1)
1474335e3713SNeil Armstrong 					- sof_lines
1475335e3713SNeil Armstrong 					- vsync_lines;
1476335e3713SNeil Armstrong 			vs_eline_odd = (de_v_begin_odd - 1)
1477335e3713SNeil Armstrong 					- vsync_lines;
1478335e3713SNeil Armstrong 			vso_begin_odd  = modulo(hs_begin
1479335e3713SNeil Armstrong 						+ (total_pixels_venc >> 1),
1480335e3713SNeil Armstrong 						total_pixels_venc);
1481335e3713SNeil Armstrong 
1482335e3713SNeil Armstrong 			writel_relaxed(vs_bline_odd,
1483335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_DVI_VSO_BLINE_ODD));
1484335e3713SNeil Armstrong 			writel_relaxed(vs_eline_odd,
1485335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_DVI_VSO_ELINE_ODD));
1486335e3713SNeil Armstrong 			writel_relaxed(vso_begin_odd,
1487335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_DVI_VSO_BEGIN_ODD));
1488335e3713SNeil Armstrong 			writel_relaxed(vso_begin_odd,
1489335e3713SNeil Armstrong 				priv->io_base + _REG(ENCP_DVI_VSO_END_ODD));
1490335e3713SNeil Armstrong 		}
1491335e3713SNeil Armstrong 
1492335e3713SNeil Armstrong 		/* Select ENCP for VIU */
1493335e3713SNeil Armstrong 		meson_vpp_setup_mux(priv, MESON_VIU_VPP_MUX_ENCP);
1494335e3713SNeil Armstrong 	}
1495335e3713SNeil Armstrong 
1496335e3713SNeil Armstrong 	writel_relaxed((use_enci ? 1 : 2) |
1497335e3713SNeil Armstrong 		       (mode->flags & DRM_MODE_FLAG_PHSYNC ? 1 << 2 : 0) |
1498335e3713SNeil Armstrong 		       (mode->flags & DRM_MODE_FLAG_PVSYNC ? 1 << 3 : 0) |
1499335e3713SNeil Armstrong 		       4 << 5 |
1500335e3713SNeil Armstrong 		       (venc_repeat ? 1 << 8 : 0) |
1501335e3713SNeil Armstrong 		       (hdmi_repeat ? 1 << 12 : 0),
1502335e3713SNeil Armstrong 		       priv->io_base + _REG(VPU_HDMI_SETTING));
1503335e3713SNeil Armstrong 
1504335e3713SNeil Armstrong 	priv->venc.hdmi_repeat = hdmi_repeat;
1505335e3713SNeil Armstrong 	priv->venc.venc_repeat = venc_repeat;
1506335e3713SNeil Armstrong 	priv->venc.hdmi_use_enci = use_enci;
1507335e3713SNeil Armstrong 
1508335e3713SNeil Armstrong 	priv->venc.current_mode = MESON_VENC_MODE_HDMI;
1509335e3713SNeil Armstrong }
1510335e3713SNeil Armstrong EXPORT_SYMBOL_GPL(meson_venc_hdmi_mode_set);
1511335e3713SNeil Armstrong 
1512bbbe775eSNeil Armstrong void meson_venci_cvbs_mode_set(struct meson_drm *priv,
1513bbbe775eSNeil Armstrong 			       struct meson_cvbs_enci_mode *mode)
1514bbbe775eSNeil Armstrong {
1515bbbe775eSNeil Armstrong 	if (mode->mode_tag == priv->venc.current_mode)
1516bbbe775eSNeil Armstrong 		return;
1517bbbe775eSNeil Armstrong 
1518bbbe775eSNeil Armstrong 	/* CVBS Filter settings */
1519bbbe775eSNeil Armstrong 	writel_relaxed(0x12, priv->io_base + _REG(ENCI_CFILT_CTRL));
1520bbbe775eSNeil Armstrong 	writel_relaxed(0x12, priv->io_base + _REG(ENCI_CFILT_CTRL2));
1521bbbe775eSNeil Armstrong 
1522bbbe775eSNeil Armstrong 	/* Digital Video Select : Interlace, clk27 clk, external */
1523bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(VENC_DVI_SETTING));
1524bbbe775eSNeil Armstrong 
1525bbbe775eSNeil Armstrong 	/* Reset Video Mode */
1526bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_MODE));
1527bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_MODE_ADV));
1528bbbe775eSNeil Armstrong 
1529bbbe775eSNeil Armstrong 	/* Horizontal sync signal output */
1530bbbe775eSNeil Armstrong 	writel_relaxed(mode->hso_begin,
1531bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_SYNC_HSO_BEGIN));
1532bbbe775eSNeil Armstrong 	writel_relaxed(mode->hso_end,
1533bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_SYNC_HSO_END));
1534bbbe775eSNeil Armstrong 
1535bbbe775eSNeil Armstrong 	/* Vertical Sync lines */
1536bbbe775eSNeil Armstrong 	writel_relaxed(mode->vso_even,
1537bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_SYNC_VSO_EVNLN));
1538bbbe775eSNeil Armstrong 	writel_relaxed(mode->vso_odd,
1539bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_SYNC_VSO_ODDLN));
1540bbbe775eSNeil Armstrong 
1541bbbe775eSNeil Armstrong 	/* Macrovision max amplitude change */
1542bbbe775eSNeil Armstrong 	writel_relaxed(0x8100 + mode->macv_max_amp,
1543bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_MACV_MAX_AMP));
1544bbbe775eSNeil Armstrong 
1545bbbe775eSNeil Armstrong 	/* Video mode */
1546bbbe775eSNeil Armstrong 	writel_relaxed(mode->video_prog_mode,
1547bbbe775eSNeil Armstrong 			priv->io_base + _REG(VENC_VIDEO_PROG_MODE));
1548bbbe775eSNeil Armstrong 	writel_relaxed(mode->video_mode,
1549bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_VIDEO_MODE));
1550bbbe775eSNeil Armstrong 
1551bbbe775eSNeil Armstrong 	/* Advanced Video Mode :
1552bbbe775eSNeil Armstrong 	 * Demux shifting 0x2
1553bbbe775eSNeil Armstrong 	 * Blank line end at line17/22
1554bbbe775eSNeil Armstrong 	 * High bandwidth Luma Filter
1555bbbe775eSNeil Armstrong 	 * Low bandwidth Chroma Filter
1556bbbe775eSNeil Armstrong 	 * Bypass luma low pass filter
1557bbbe775eSNeil Armstrong 	 * No macrovision on CSYNC
1558bbbe775eSNeil Armstrong 	 */
1559bbbe775eSNeil Armstrong 	writel_relaxed(0x26, priv->io_base + _REG(ENCI_VIDEO_MODE_ADV));
1560bbbe775eSNeil Armstrong 
1561bbbe775eSNeil Armstrong 	writel(mode->sch_adjust, priv->io_base + _REG(ENCI_VIDEO_SCH));
1562bbbe775eSNeil Armstrong 
1563bbbe775eSNeil Armstrong 	/* Sync mode : MASTER Master mode, free run, send HSO/VSO out */
1564bbbe775eSNeil Armstrong 	writel_relaxed(0x07, priv->io_base + _REG(ENCI_SYNC_MODE));
1565bbbe775eSNeil Armstrong 
1566bbbe775eSNeil Armstrong 	/* 0x3 Y, C, and Component Y delay */
1567bbbe775eSNeil Armstrong 	writel_relaxed(mode->yc_delay, priv->io_base + _REG(ENCI_YC_DELAY));
1568bbbe775eSNeil Armstrong 
1569bbbe775eSNeil Armstrong 	/* Timings */
1570bbbe775eSNeil Armstrong 	writel_relaxed(mode->pixel_start,
1571bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_VFIFO2VD_PIXEL_START));
1572bbbe775eSNeil Armstrong 	writel_relaxed(mode->pixel_end,
1573bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_VFIFO2VD_PIXEL_END));
1574bbbe775eSNeil Armstrong 
1575bbbe775eSNeil Armstrong 	writel_relaxed(mode->top_field_line_start,
1576bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_VFIFO2VD_LINE_TOP_START));
1577bbbe775eSNeil Armstrong 	writel_relaxed(mode->top_field_line_end,
1578bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_VFIFO2VD_LINE_TOP_END));
1579bbbe775eSNeil Armstrong 
1580bbbe775eSNeil Armstrong 	writel_relaxed(mode->bottom_field_line_start,
1581bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_VFIFO2VD_LINE_BOT_START));
1582bbbe775eSNeil Armstrong 	writel_relaxed(mode->bottom_field_line_end,
1583bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_VFIFO2VD_LINE_BOT_END));
1584bbbe775eSNeil Armstrong 
1585bbbe775eSNeil Armstrong 	/* Internal Venc, Internal VIU Sync, Internal Vencoder */
1586bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(VENC_SYNC_ROUTE));
1587bbbe775eSNeil Armstrong 
1588bbbe775eSNeil Armstrong 	/* UNreset Interlaced TV Encoder */
1589bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(ENCI_DBG_PX_RST));
1590bbbe775eSNeil Armstrong 
1591bbbe775eSNeil Armstrong 	/* Enable Vfifo2vd, Y_Cb_Y_Cr select */
1592bbbe775eSNeil Armstrong 	writel_relaxed(0x4e01, priv->io_base + _REG(ENCI_VFIFO2VD_CTL));
1593bbbe775eSNeil Armstrong 
1594bbbe775eSNeil Armstrong 	/* Power UP Dacs */
1595bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_SETTING));
1596bbbe775eSNeil Armstrong 
1597bbbe775eSNeil Armstrong 	/* Video Upsampling */
1598bbbe775eSNeil Armstrong 	writel_relaxed(0x0061, priv->io_base + _REG(VENC_UPSAMPLE_CTRL0));
1599bbbe775eSNeil Armstrong 	writel_relaxed(0x4061, priv->io_base + _REG(VENC_UPSAMPLE_CTRL1));
1600bbbe775eSNeil Armstrong 	writel_relaxed(0x5061, priv->io_base + _REG(VENC_UPSAMPLE_CTRL2));
1601bbbe775eSNeil Armstrong 
1602bbbe775eSNeil Armstrong 	/* Select Interlace Y DACs */
1603bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL0));
1604bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL1));
1605bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL2));
1606bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL3));
1607bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL4));
1608bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL5));
1609bbbe775eSNeil Armstrong 
1610bbbe775eSNeil Armstrong 	/* Select ENCI for VIU */
1611bbbe775eSNeil Armstrong 	meson_vpp_setup_mux(priv, MESON_VIU_VPP_MUX_ENCI);
1612bbbe775eSNeil Armstrong 
1613bbbe775eSNeil Armstrong 	/* Enable ENCI FIFO */
1614bbbe775eSNeil Armstrong 	writel_relaxed(0x2000, priv->io_base + _REG(VENC_VDAC_FIFO_CTRL));
1615bbbe775eSNeil Armstrong 
1616bbbe775eSNeil Armstrong 	/* Select ENCI DACs 0, 1, 4, and 5 */
1617bbbe775eSNeil Armstrong 	writel_relaxed(0x11, priv->io_base + _REG(ENCI_DACSEL_0));
1618bbbe775eSNeil Armstrong 	writel_relaxed(0x11, priv->io_base + _REG(ENCI_DACSEL_1));
1619bbbe775eSNeil Armstrong 
1620bbbe775eSNeil Armstrong 	/* Interlace video enable */
1621bbbe775eSNeil Armstrong 	writel_relaxed(1, priv->io_base + _REG(ENCI_VIDEO_EN));
1622bbbe775eSNeil Armstrong 
1623bbbe775eSNeil Armstrong 	/* Configure Video Saturation / Contrast / Brightness / Hue */
1624bbbe775eSNeil Armstrong 	writel_relaxed(mode->video_saturation,
1625bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_VIDEO_SAT));
1626bbbe775eSNeil Armstrong 	writel_relaxed(mode->video_contrast,
1627bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_VIDEO_CONT));
1628bbbe775eSNeil Armstrong 	writel_relaxed(mode->video_brightness,
1629bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_VIDEO_BRIGHT));
1630bbbe775eSNeil Armstrong 	writel_relaxed(mode->video_hue,
1631bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_VIDEO_HUE));
1632bbbe775eSNeil Armstrong 
1633bbbe775eSNeil Armstrong 	/* Enable DAC0 Filter */
1634bbbe775eSNeil Armstrong 	writel_relaxed(0x1, priv->io_base + _REG(VENC_VDAC_DAC0_FILT_CTRL0));
1635bbbe775eSNeil Armstrong 	writel_relaxed(0xfc48, priv->io_base + _REG(VENC_VDAC_DAC0_FILT_CTRL1));
1636bbbe775eSNeil Armstrong 
1637bbbe775eSNeil Armstrong 	/* 0 in Macrovision register 0 */
1638bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(ENCI_MACV_N0));
1639bbbe775eSNeil Armstrong 
1640bbbe775eSNeil Armstrong 	/* Analog Synchronization and color burst value adjust */
1641bbbe775eSNeil Armstrong 	writel_relaxed(mode->analog_sync_adj,
1642bbbe775eSNeil Armstrong 			priv->io_base + _REG(ENCI_SYNC_ADJ));
1643bbbe775eSNeil Armstrong 
1644bbbe775eSNeil Armstrong 	priv->venc.current_mode = mode->mode_tag;
1645bbbe775eSNeil Armstrong }
1646bbbe775eSNeil Armstrong 
1647bbbe775eSNeil Armstrong /* Returns the current ENCI field polarity */
1648bbbe775eSNeil Armstrong unsigned int meson_venci_get_field(struct meson_drm *priv)
1649bbbe775eSNeil Armstrong {
1650bbbe775eSNeil Armstrong 	return readl_relaxed(priv->io_base + _REG(ENCI_INFO_READ)) & BIT(29);
1651bbbe775eSNeil Armstrong }
1652bbbe775eSNeil Armstrong 
1653bbbe775eSNeil Armstrong void meson_venc_enable_vsync(struct meson_drm *priv)
1654bbbe775eSNeil Armstrong {
1655bbbe775eSNeil Armstrong 	writel_relaxed(2, priv->io_base + _REG(VENC_INTCTRL));
16562bcd3ecaSNeil Armstrong 	regmap_update_bits(priv->hhi, HHI_GCLK_MPEG2, BIT(25), BIT(25));
1657bbbe775eSNeil Armstrong }
1658bbbe775eSNeil Armstrong 
1659bbbe775eSNeil Armstrong void meson_venc_disable_vsync(struct meson_drm *priv)
1660bbbe775eSNeil Armstrong {
16612bcd3ecaSNeil Armstrong 	regmap_update_bits(priv->hhi, HHI_GCLK_MPEG2, BIT(25), 0);
1662bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(VENC_INTCTRL));
1663bbbe775eSNeil Armstrong }
1664bbbe775eSNeil Armstrong 
1665bbbe775eSNeil Armstrong void meson_venc_init(struct meson_drm *priv)
1666bbbe775eSNeil Armstrong {
16670c931a29SNeil Armstrong 	/* Disable CVBS VDAC */
166864d598a1SNeil Armstrong 	if (meson_vpu_is_compatible(priv, "amlogic,meson-g12a-vpu")) {
166964d598a1SNeil Armstrong 		regmap_write(priv->hhi, HHI_VDAC_CNTL0_G12A, 0);
167064d598a1SNeil Armstrong 		regmap_write(priv->hhi, HHI_VDAC_CNTL1_G12A, 8);
167164d598a1SNeil Armstrong 	} else {
16720c931a29SNeil Armstrong 		regmap_write(priv->hhi, HHI_VDAC_CNTL0, 0);
16730c931a29SNeil Armstrong 		regmap_write(priv->hhi, HHI_VDAC_CNTL1, 8);
167464d598a1SNeil Armstrong 	}
16750c931a29SNeil Armstrong 
16760c931a29SNeil Armstrong 	/* Power Down Dacs */
16770c931a29SNeil Armstrong 	writel_relaxed(0xff, priv->io_base + _REG(VENC_VDAC_SETTING));
16780c931a29SNeil Armstrong 
16790c931a29SNeil Armstrong 	/* Disable HDMI PHY */
16800c931a29SNeil Armstrong 	regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, 0);
16810c931a29SNeil Armstrong 
16820c931a29SNeil Armstrong 	/* Disable HDMI */
16830c931a29SNeil Armstrong 	writel_bits_relaxed(0x3, 0,
16840c931a29SNeil Armstrong 			    priv->io_base + _REG(VPU_HDMI_SETTING));
16850c931a29SNeil Armstrong 
1686bbbe775eSNeil Armstrong 	/* Disable all encoders */
1687bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_EN));
1688bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(ENCP_VIDEO_EN));
1689bbbe775eSNeil Armstrong 	writel_relaxed(0, priv->io_base + _REG(ENCL_VIDEO_EN));
1690bbbe775eSNeil Armstrong 
1691bbbe775eSNeil Armstrong 	/* Disable VSync IRQ */
1692bbbe775eSNeil Armstrong 	meson_venc_disable_vsync(priv);
1693bbbe775eSNeil Armstrong 
1694bbbe775eSNeil Armstrong 	priv->venc.current_mode = MESON_VENC_MODE_NONE;
1695bbbe775eSNeil Armstrong }
1696