xref: /openbmc/linux/drivers/media/platform/ti/omap/omap_vout.c (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
1012e3ca3SMauro Carvalho Chehab /*
2012e3ca3SMauro Carvalho Chehab  * omap_vout.c
3012e3ca3SMauro Carvalho Chehab  *
4012e3ca3SMauro Carvalho Chehab  * Copyright (C) 2005-2010 Texas Instruments.
5012e3ca3SMauro Carvalho Chehab  *
6012e3ca3SMauro Carvalho Chehab  * This file is licensed under the terms of the GNU General Public License
7012e3ca3SMauro Carvalho Chehab  * version 2. This program is licensed "as is" without any warranty of any
8012e3ca3SMauro Carvalho Chehab  * kind, whether express or implied.
9012e3ca3SMauro Carvalho Chehab  *
10012e3ca3SMauro Carvalho Chehab  * Leveraged code from the OMAP2 camera driver
11012e3ca3SMauro Carvalho Chehab  * Video-for-Linux (Version 2) camera capture driver for
12012e3ca3SMauro Carvalho Chehab  * the OMAP24xx camera controller.
13012e3ca3SMauro Carvalho Chehab  *
14012e3ca3SMauro Carvalho Chehab  * Author: Andy Lowe (source@mvista.com)
15012e3ca3SMauro Carvalho Chehab  *
16012e3ca3SMauro Carvalho Chehab  * Copyright (C) 2004 MontaVista Software, Inc.
17012e3ca3SMauro Carvalho Chehab  * Copyright (C) 2010 Texas Instruments.
18012e3ca3SMauro Carvalho Chehab  *
19012e3ca3SMauro Carvalho Chehab  * History:
20012e3ca3SMauro Carvalho Chehab  * 20-APR-2006 Khasim		Modified VRFB based Rotation,
21012e3ca3SMauro Carvalho Chehab  *				The image data is always read from 0 degree
22012e3ca3SMauro Carvalho Chehab  *				view and written
23012e3ca3SMauro Carvalho Chehab  *				to the virtual space of desired rotation angle
24012e3ca3SMauro Carvalho Chehab  * 4-DEC-2006  Jian		Changed to support better memory management
25012e3ca3SMauro Carvalho Chehab  *
26012e3ca3SMauro Carvalho Chehab  * 17-Nov-2008 Hardik		Changed driver to use video_ioctl2
27012e3ca3SMauro Carvalho Chehab  *
28012e3ca3SMauro Carvalho Chehab  * 23-Feb-2010 Vaibhav H	Modified to use new DSS2 interface
29012e3ca3SMauro Carvalho Chehab  *
30012e3ca3SMauro Carvalho Chehab  */
31012e3ca3SMauro Carvalho Chehab 
32012e3ca3SMauro Carvalho Chehab #include <linux/init.h>
33012e3ca3SMauro Carvalho Chehab #include <linux/module.h>
34012e3ca3SMauro Carvalho Chehab #include <linux/vmalloc.h>
35012e3ca3SMauro Carvalho Chehab #include <linux/sched.h>
36012e3ca3SMauro Carvalho Chehab #include <linux/types.h>
37012e3ca3SMauro Carvalho Chehab #include <linux/platform_device.h>
38012e3ca3SMauro Carvalho Chehab #include <linux/irq.h>
39012e3ca3SMauro Carvalho Chehab #include <linux/videodev2.h>
40012e3ca3SMauro Carvalho Chehab #include <linux/dma-mapping.h>
41012e3ca3SMauro Carvalho Chehab #include <linux/slab.h>
42012e3ca3SMauro Carvalho Chehab 
43012e3ca3SMauro Carvalho Chehab #include <media/v4l2-device.h>
44012e3ca3SMauro Carvalho Chehab #include <media/v4l2-ioctl.h>
45012e3ca3SMauro Carvalho Chehab #include <media/v4l2-event.h>
46012e3ca3SMauro Carvalho Chehab 
47012e3ca3SMauro Carvalho Chehab #include <video/omapvrfb.h>
48012e3ca3SMauro Carvalho Chehab #include <video/omapfb_dss.h>
49012e3ca3SMauro Carvalho Chehab 
50012e3ca3SMauro Carvalho Chehab #include "omap_voutlib.h"
51012e3ca3SMauro Carvalho Chehab #include "omap_voutdef.h"
52012e3ca3SMauro Carvalho Chehab #include "omap_vout_vrfb.h"
53012e3ca3SMauro Carvalho Chehab 
54012e3ca3SMauro Carvalho Chehab MODULE_AUTHOR("Texas Instruments");
55012e3ca3SMauro Carvalho Chehab MODULE_DESCRIPTION("OMAP Video for Linux Video out driver");
56012e3ca3SMauro Carvalho Chehab MODULE_LICENSE("GPL");
57012e3ca3SMauro Carvalho Chehab 
58012e3ca3SMauro Carvalho Chehab /* Driver Configuration macros */
59012e3ca3SMauro Carvalho Chehab #define VOUT_NAME		"omap_vout"
60012e3ca3SMauro Carvalho Chehab 
61012e3ca3SMauro Carvalho Chehab enum omap_vout_channels {
62012e3ca3SMauro Carvalho Chehab 	OMAP_VIDEO1,
63012e3ca3SMauro Carvalho Chehab 	OMAP_VIDEO2,
64012e3ca3SMauro Carvalho Chehab };
65012e3ca3SMauro Carvalho Chehab 
66012e3ca3SMauro Carvalho Chehab /* Variables configurable through module params*/
67012e3ca3SMauro Carvalho Chehab static bool vid1_static_vrfb_alloc;
68012e3ca3SMauro Carvalho Chehab static bool vid2_static_vrfb_alloc;
69012e3ca3SMauro Carvalho Chehab static bool debug;
70012e3ca3SMauro Carvalho Chehab 
71012e3ca3SMauro Carvalho Chehab /* Module parameters */
72012e3ca3SMauro Carvalho Chehab module_param(vid1_static_vrfb_alloc, bool, S_IRUGO);
73012e3ca3SMauro Carvalho Chehab MODULE_PARM_DESC(vid1_static_vrfb_alloc,
74012e3ca3SMauro Carvalho Chehab 	"Static allocation of the VRFB buffer for video1 device");
75012e3ca3SMauro Carvalho Chehab 
76012e3ca3SMauro Carvalho Chehab module_param(vid2_static_vrfb_alloc, bool, S_IRUGO);
77012e3ca3SMauro Carvalho Chehab MODULE_PARM_DESC(vid2_static_vrfb_alloc,
78012e3ca3SMauro Carvalho Chehab 	"Static allocation of the VRFB buffer for video2 device");
79012e3ca3SMauro Carvalho Chehab 
80012e3ca3SMauro Carvalho Chehab module_param(debug, bool, S_IRUGO);
81012e3ca3SMauro Carvalho Chehab MODULE_PARM_DESC(debug, "Debug level (0-1)");
82012e3ca3SMauro Carvalho Chehab 
83012e3ca3SMauro Carvalho Chehab /* list of image formats supported by OMAP2 video pipelines */
84012e3ca3SMauro Carvalho Chehab static const struct v4l2_fmtdesc omap_formats[] = {
85012e3ca3SMauro Carvalho Chehab 	{
86012e3ca3SMauro Carvalho Chehab 		/* Note:  V4L2 defines RGB565 as:
87012e3ca3SMauro Carvalho Chehab 		 *
88012e3ca3SMauro Carvalho Chehab 		 *      Byte 0                    Byte 1
89012e3ca3SMauro Carvalho Chehab 		 *      g2 g1 g0 r4 r3 r2 r1 r0   b4 b3 b2 b1 b0 g5 g4 g3
90012e3ca3SMauro Carvalho Chehab 		 *
91012e3ca3SMauro Carvalho Chehab 		 * We interpret RGB565 as:
92012e3ca3SMauro Carvalho Chehab 		 *
93012e3ca3SMauro Carvalho Chehab 		 *      Byte 0                    Byte 1
94012e3ca3SMauro Carvalho Chehab 		 *      g2 g1 g0 b4 b3 b2 b1 b0   r4 r3 r2 r1 r0 g5 g4 g3
95012e3ca3SMauro Carvalho Chehab 		 */
96012e3ca3SMauro Carvalho Chehab 		.pixelformat = V4L2_PIX_FMT_RGB565,
97012e3ca3SMauro Carvalho Chehab 	},
98012e3ca3SMauro Carvalho Chehab 	{
99012e3ca3SMauro Carvalho Chehab 		/* Note:  V4L2 defines RGB32 as: RGB-8-8-8-8  we use
100012e3ca3SMauro Carvalho Chehab 		 *  this for RGB24 unpack mode, the last 8 bits are ignored
101012e3ca3SMauro Carvalho Chehab 		 * */
102012e3ca3SMauro Carvalho Chehab 		.pixelformat = V4L2_PIX_FMT_RGB32,
103012e3ca3SMauro Carvalho Chehab 	},
104012e3ca3SMauro Carvalho Chehab 	{
105012e3ca3SMauro Carvalho Chehab 		/* Note:  V4L2 defines RGB24 as: RGB-8-8-8  we use
106012e3ca3SMauro Carvalho Chehab 		 *        this for RGB24 packed mode
107012e3ca3SMauro Carvalho Chehab 		 *
108012e3ca3SMauro Carvalho Chehab 		 */
109012e3ca3SMauro Carvalho Chehab 		.pixelformat = V4L2_PIX_FMT_RGB24,
110012e3ca3SMauro Carvalho Chehab 	},
111012e3ca3SMauro Carvalho Chehab 	{
112012e3ca3SMauro Carvalho Chehab 		.pixelformat = V4L2_PIX_FMT_YUYV,
113012e3ca3SMauro Carvalho Chehab 	},
114012e3ca3SMauro Carvalho Chehab 	{
115012e3ca3SMauro Carvalho Chehab 		.pixelformat = V4L2_PIX_FMT_UYVY,
116012e3ca3SMauro Carvalho Chehab 	},
117012e3ca3SMauro Carvalho Chehab };
118012e3ca3SMauro Carvalho Chehab 
119012e3ca3SMauro Carvalho Chehab #define NUM_OUTPUT_FORMATS (ARRAY_SIZE(omap_formats))
120012e3ca3SMauro Carvalho Chehab 
121012e3ca3SMauro Carvalho Chehab /*
122012e3ca3SMauro Carvalho Chehab  * Try format
123012e3ca3SMauro Carvalho Chehab  */
omap_vout_try_format(struct v4l2_pix_format * pix)124012e3ca3SMauro Carvalho Chehab static int omap_vout_try_format(struct v4l2_pix_format *pix)
125012e3ca3SMauro Carvalho Chehab {
126012e3ca3SMauro Carvalho Chehab 	int ifmt, bpp = 0;
127012e3ca3SMauro Carvalho Chehab 
128012e3ca3SMauro Carvalho Chehab 	pix->height = clamp(pix->height, (u32)VID_MIN_HEIGHT,
129012e3ca3SMauro Carvalho Chehab 						(u32)VID_MAX_HEIGHT);
130012e3ca3SMauro Carvalho Chehab 	pix->width = clamp(pix->width, (u32)VID_MIN_WIDTH, (u32)VID_MAX_WIDTH);
131012e3ca3SMauro Carvalho Chehab 
132012e3ca3SMauro Carvalho Chehab 	for (ifmt = 0; ifmt < NUM_OUTPUT_FORMATS; ifmt++) {
133012e3ca3SMauro Carvalho Chehab 		if (pix->pixelformat == omap_formats[ifmt].pixelformat)
134012e3ca3SMauro Carvalho Chehab 			break;
135012e3ca3SMauro Carvalho Chehab 	}
136012e3ca3SMauro Carvalho Chehab 
137012e3ca3SMauro Carvalho Chehab 	if (ifmt == NUM_OUTPUT_FORMATS)
138012e3ca3SMauro Carvalho Chehab 		ifmt = 0;
139012e3ca3SMauro Carvalho Chehab 
140012e3ca3SMauro Carvalho Chehab 	pix->pixelformat = omap_formats[ifmt].pixelformat;
141012e3ca3SMauro Carvalho Chehab 	pix->field = V4L2_FIELD_NONE;
142012e3ca3SMauro Carvalho Chehab 
143012e3ca3SMauro Carvalho Chehab 	switch (pix->pixelformat) {
144012e3ca3SMauro Carvalho Chehab 	case V4L2_PIX_FMT_YUYV:
145012e3ca3SMauro Carvalho Chehab 	case V4L2_PIX_FMT_UYVY:
146012e3ca3SMauro Carvalho Chehab 	default:
147012e3ca3SMauro Carvalho Chehab 		pix->colorspace = V4L2_COLORSPACE_SRGB;
148012e3ca3SMauro Carvalho Chehab 		bpp = YUYV_BPP;
149012e3ca3SMauro Carvalho Chehab 		break;
150012e3ca3SMauro Carvalho Chehab 	case V4L2_PIX_FMT_RGB565:
151012e3ca3SMauro Carvalho Chehab 	case V4L2_PIX_FMT_RGB565X:
152012e3ca3SMauro Carvalho Chehab 		pix->colorspace = V4L2_COLORSPACE_SRGB;
153012e3ca3SMauro Carvalho Chehab 		bpp = RGB565_BPP;
154012e3ca3SMauro Carvalho Chehab 		break;
155012e3ca3SMauro Carvalho Chehab 	case V4L2_PIX_FMT_RGB24:
156012e3ca3SMauro Carvalho Chehab 		pix->colorspace = V4L2_COLORSPACE_SRGB;
157012e3ca3SMauro Carvalho Chehab 		bpp = RGB24_BPP;
158012e3ca3SMauro Carvalho Chehab 		break;
159012e3ca3SMauro Carvalho Chehab 	case V4L2_PIX_FMT_RGB32:
160012e3ca3SMauro Carvalho Chehab 	case V4L2_PIX_FMT_BGR32:
161012e3ca3SMauro Carvalho Chehab 		pix->colorspace = V4L2_COLORSPACE_SRGB;
162012e3ca3SMauro Carvalho Chehab 		bpp = RGB32_BPP;
163012e3ca3SMauro Carvalho Chehab 		break;
164012e3ca3SMauro Carvalho Chehab 	}
165012e3ca3SMauro Carvalho Chehab 	pix->bytesperline = pix->width * bpp;
166012e3ca3SMauro Carvalho Chehab 	pix->sizeimage = pix->bytesperline * pix->height;
167012e3ca3SMauro Carvalho Chehab 
168012e3ca3SMauro Carvalho Chehab 	return bpp;
169012e3ca3SMauro Carvalho Chehab }
170012e3ca3SMauro Carvalho Chehab 
171012e3ca3SMauro Carvalho Chehab /*
172012e3ca3SMauro Carvalho Chehab  * Convert V4L2 rotation to DSS rotation
173012e3ca3SMauro Carvalho Chehab  *	V4L2 understand 0, 90, 180, 270.
174012e3ca3SMauro Carvalho Chehab  *	Convert to 0, 1, 2 and 3 respectively for DSS
175012e3ca3SMauro Carvalho Chehab  */
v4l2_rot_to_dss_rot(int v4l2_rotation,enum dss_rotation * rotation,bool mirror)176012e3ca3SMauro Carvalho Chehab static int v4l2_rot_to_dss_rot(int v4l2_rotation,
177012e3ca3SMauro Carvalho Chehab 			enum dss_rotation *rotation, bool mirror)
178012e3ca3SMauro Carvalho Chehab {
179012e3ca3SMauro Carvalho Chehab 	int ret = 0;
180012e3ca3SMauro Carvalho Chehab 
181012e3ca3SMauro Carvalho Chehab 	switch (v4l2_rotation) {
182012e3ca3SMauro Carvalho Chehab 	case 90:
183012e3ca3SMauro Carvalho Chehab 		*rotation = dss_rotation_90_degree;
184012e3ca3SMauro Carvalho Chehab 		break;
185012e3ca3SMauro Carvalho Chehab 	case 180:
186012e3ca3SMauro Carvalho Chehab 		*rotation = dss_rotation_180_degree;
187012e3ca3SMauro Carvalho Chehab 		break;
188012e3ca3SMauro Carvalho Chehab 	case 270:
189012e3ca3SMauro Carvalho Chehab 		*rotation = dss_rotation_270_degree;
190012e3ca3SMauro Carvalho Chehab 		break;
191012e3ca3SMauro Carvalho Chehab 	case 0:
192012e3ca3SMauro Carvalho Chehab 		*rotation = dss_rotation_0_degree;
193012e3ca3SMauro Carvalho Chehab 		break;
194012e3ca3SMauro Carvalho Chehab 	default:
195012e3ca3SMauro Carvalho Chehab 		ret = -EINVAL;
196012e3ca3SMauro Carvalho Chehab 	}
197012e3ca3SMauro Carvalho Chehab 	return ret;
198012e3ca3SMauro Carvalho Chehab }
199012e3ca3SMauro Carvalho Chehab 
omap_vout_calculate_offset(struct omap_vout_device * vout)200012e3ca3SMauro Carvalho Chehab static int omap_vout_calculate_offset(struct omap_vout_device *vout)
201012e3ca3SMauro Carvalho Chehab {
202012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid;
203012e3ca3SMauro Carvalho Chehab 	struct v4l2_rect *crop = &vout->crop;
204012e3ca3SMauro Carvalho Chehab 	struct v4l2_pix_format *pix = &vout->pix;
205012e3ca3SMauro Carvalho Chehab 	int *cropped_offset = &vout->cropped_offset;
206012e3ca3SMauro Carvalho Chehab 	int ps = 2, line_length = 0;
207012e3ca3SMauro Carvalho Chehab 
208012e3ca3SMauro Carvalho Chehab 	ovid = &vout->vid_info;
209012e3ca3SMauro Carvalho Chehab 
210012e3ca3SMauro Carvalho Chehab 	if (ovid->rotation_type == VOUT_ROT_VRFB) {
211012e3ca3SMauro Carvalho Chehab 		omap_vout_calculate_vrfb_offset(vout);
212012e3ca3SMauro Carvalho Chehab 	} else {
213012e3ca3SMauro Carvalho Chehab 		vout->line_length = line_length = pix->width;
214012e3ca3SMauro Carvalho Chehab 
215012e3ca3SMauro Carvalho Chehab 		if (V4L2_PIX_FMT_YUYV == pix->pixelformat ||
216012e3ca3SMauro Carvalho Chehab 			V4L2_PIX_FMT_UYVY == pix->pixelformat)
217012e3ca3SMauro Carvalho Chehab 			ps = 2;
218012e3ca3SMauro Carvalho Chehab 		else if (V4L2_PIX_FMT_RGB32 == pix->pixelformat)
219012e3ca3SMauro Carvalho Chehab 			ps = 4;
220012e3ca3SMauro Carvalho Chehab 		else if (V4L2_PIX_FMT_RGB24 == pix->pixelformat)
221012e3ca3SMauro Carvalho Chehab 			ps = 3;
222012e3ca3SMauro Carvalho Chehab 
223012e3ca3SMauro Carvalho Chehab 		vout->ps = ps;
224012e3ca3SMauro Carvalho Chehab 
225012e3ca3SMauro Carvalho Chehab 		*cropped_offset = (line_length * ps) *
226012e3ca3SMauro Carvalho Chehab 			crop->top + crop->left * ps;
227012e3ca3SMauro Carvalho Chehab 	}
228012e3ca3SMauro Carvalho Chehab 
229012e3ca3SMauro Carvalho Chehab 	v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "%s Offset:%x\n",
230012e3ca3SMauro Carvalho Chehab 			__func__, vout->cropped_offset);
231012e3ca3SMauro Carvalho Chehab 
232012e3ca3SMauro Carvalho Chehab 	return 0;
233012e3ca3SMauro Carvalho Chehab }
234012e3ca3SMauro Carvalho Chehab 
235012e3ca3SMauro Carvalho Chehab /*
236012e3ca3SMauro Carvalho Chehab  * Convert V4L2 pixel format to DSS pixel format
237012e3ca3SMauro Carvalho Chehab  */
video_mode_to_dss_mode(struct omap_vout_device * vout)238012e3ca3SMauro Carvalho Chehab static int video_mode_to_dss_mode(struct omap_vout_device *vout)
239012e3ca3SMauro Carvalho Chehab {
240012e3ca3SMauro Carvalho Chehab 	struct omap_overlay *ovl;
241012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid;
242012e3ca3SMauro Carvalho Chehab 	struct v4l2_pix_format *pix = &vout->pix;
243012e3ca3SMauro Carvalho Chehab 	enum omap_color_mode mode;
244012e3ca3SMauro Carvalho Chehab 
245012e3ca3SMauro Carvalho Chehab 	ovid = &vout->vid_info;
246012e3ca3SMauro Carvalho Chehab 	ovl = ovid->overlays[0];
247012e3ca3SMauro Carvalho Chehab 
248012e3ca3SMauro Carvalho Chehab 	switch (pix->pixelformat) {
249012e3ca3SMauro Carvalho Chehab 	case V4L2_PIX_FMT_YUYV:
250012e3ca3SMauro Carvalho Chehab 		mode = OMAP_DSS_COLOR_YUV2;
251012e3ca3SMauro Carvalho Chehab 		break;
252012e3ca3SMauro Carvalho Chehab 	case V4L2_PIX_FMT_UYVY:
253012e3ca3SMauro Carvalho Chehab 		mode = OMAP_DSS_COLOR_UYVY;
254012e3ca3SMauro Carvalho Chehab 		break;
255012e3ca3SMauro Carvalho Chehab 	case V4L2_PIX_FMT_RGB565:
256012e3ca3SMauro Carvalho Chehab 		mode = OMAP_DSS_COLOR_RGB16;
257012e3ca3SMauro Carvalho Chehab 		break;
258012e3ca3SMauro Carvalho Chehab 	case V4L2_PIX_FMT_RGB24:
259012e3ca3SMauro Carvalho Chehab 		mode = OMAP_DSS_COLOR_RGB24P;
260012e3ca3SMauro Carvalho Chehab 		break;
261012e3ca3SMauro Carvalho Chehab 	case V4L2_PIX_FMT_RGB32:
262012e3ca3SMauro Carvalho Chehab 		mode = (ovl->id == OMAP_DSS_VIDEO1) ?
263012e3ca3SMauro Carvalho Chehab 			OMAP_DSS_COLOR_RGB24U : OMAP_DSS_COLOR_ARGB32;
264012e3ca3SMauro Carvalho Chehab 		break;
265012e3ca3SMauro Carvalho Chehab 	case V4L2_PIX_FMT_BGR32:
266012e3ca3SMauro Carvalho Chehab 		mode = OMAP_DSS_COLOR_RGBX32;
267012e3ca3SMauro Carvalho Chehab 		break;
268012e3ca3SMauro Carvalho Chehab 	default:
269012e3ca3SMauro Carvalho Chehab 		mode = -EINVAL;
270012e3ca3SMauro Carvalho Chehab 		break;
271012e3ca3SMauro Carvalho Chehab 	}
272012e3ca3SMauro Carvalho Chehab 	return mode;
273012e3ca3SMauro Carvalho Chehab }
274012e3ca3SMauro Carvalho Chehab 
275012e3ca3SMauro Carvalho Chehab /*
276012e3ca3SMauro Carvalho Chehab  * Setup the overlay
277012e3ca3SMauro Carvalho Chehab  */
omapvid_setup_overlay(struct omap_vout_device * vout,struct omap_overlay * ovl,int posx,int posy,int outw,int outh,dma_addr_t addr)278012e3ca3SMauro Carvalho Chehab static int omapvid_setup_overlay(struct omap_vout_device *vout,
279012e3ca3SMauro Carvalho Chehab 		struct omap_overlay *ovl, int posx, int posy, int outw,
280012e3ca3SMauro Carvalho Chehab 		int outh, dma_addr_t addr)
281012e3ca3SMauro Carvalho Chehab {
282012e3ca3SMauro Carvalho Chehab 	int ret = 0;
283012e3ca3SMauro Carvalho Chehab 	struct omap_overlay_info info;
284012e3ca3SMauro Carvalho Chehab 	int cropheight, cropwidth, pixwidth;
285012e3ca3SMauro Carvalho Chehab 
286012e3ca3SMauro Carvalho Chehab 	if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0 &&
287012e3ca3SMauro Carvalho Chehab 			(outw != vout->pix.width || outh != vout->pix.height)) {
288012e3ca3SMauro Carvalho Chehab 		ret = -EINVAL;
289012e3ca3SMauro Carvalho Chehab 		goto setup_ovl_err;
290012e3ca3SMauro Carvalho Chehab 	}
291012e3ca3SMauro Carvalho Chehab 
292012e3ca3SMauro Carvalho Chehab 	vout->dss_mode = video_mode_to_dss_mode(vout);
293012e3ca3SMauro Carvalho Chehab 	if (vout->dss_mode == -EINVAL) {
294012e3ca3SMauro Carvalho Chehab 		ret = -EINVAL;
295012e3ca3SMauro Carvalho Chehab 		goto setup_ovl_err;
296012e3ca3SMauro Carvalho Chehab 	}
297012e3ca3SMauro Carvalho Chehab 
298012e3ca3SMauro Carvalho Chehab 	/* Setup the input plane parameters according to
299012e3ca3SMauro Carvalho Chehab 	 * rotation value selected.
300012e3ca3SMauro Carvalho Chehab 	 */
301012e3ca3SMauro Carvalho Chehab 	if (is_rotation_90_or_270(vout)) {
302012e3ca3SMauro Carvalho Chehab 		cropheight = vout->crop.width;
303012e3ca3SMauro Carvalho Chehab 		cropwidth = vout->crop.height;
304012e3ca3SMauro Carvalho Chehab 		pixwidth = vout->pix.height;
305012e3ca3SMauro Carvalho Chehab 	} else {
306012e3ca3SMauro Carvalho Chehab 		cropheight = vout->crop.height;
307012e3ca3SMauro Carvalho Chehab 		cropwidth = vout->crop.width;
308012e3ca3SMauro Carvalho Chehab 		pixwidth = vout->pix.width;
309012e3ca3SMauro Carvalho Chehab 	}
310012e3ca3SMauro Carvalho Chehab 
311012e3ca3SMauro Carvalho Chehab 	ovl->get_overlay_info(ovl, &info);
312012e3ca3SMauro Carvalho Chehab 	info.paddr = addr;
313012e3ca3SMauro Carvalho Chehab 	info.width = cropwidth;
314012e3ca3SMauro Carvalho Chehab 	info.height = cropheight;
315012e3ca3SMauro Carvalho Chehab 	info.color_mode = vout->dss_mode;
316012e3ca3SMauro Carvalho Chehab 	info.mirror = vout->mirror;
317012e3ca3SMauro Carvalho Chehab 	info.pos_x = posx;
318012e3ca3SMauro Carvalho Chehab 	info.pos_y = posy;
319012e3ca3SMauro Carvalho Chehab 	info.out_width = outw;
320012e3ca3SMauro Carvalho Chehab 	info.out_height = outh;
321012e3ca3SMauro Carvalho Chehab 	info.global_alpha = vout->win.global_alpha;
322012e3ca3SMauro Carvalho Chehab 	if (!is_rotation_enabled(vout)) {
323012e3ca3SMauro Carvalho Chehab 		info.rotation = 0;
324012e3ca3SMauro Carvalho Chehab 		info.rotation_type = OMAP_DSS_ROT_DMA;
325012e3ca3SMauro Carvalho Chehab 		info.screen_width = pixwidth;
326012e3ca3SMauro Carvalho Chehab 	} else {
327012e3ca3SMauro Carvalho Chehab 		info.rotation = vout->rotation;
328012e3ca3SMauro Carvalho Chehab 		info.rotation_type = OMAP_DSS_ROT_VRFB;
329012e3ca3SMauro Carvalho Chehab 		info.screen_width = 2048;
330012e3ca3SMauro Carvalho Chehab 	}
331012e3ca3SMauro Carvalho Chehab 
332012e3ca3SMauro Carvalho Chehab 	v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev,
333012e3ca3SMauro Carvalho Chehab 		"%s enable=%d addr=%pad width=%d\n height=%d color_mode=%d\n"
334012e3ca3SMauro Carvalho Chehab 		"rotation=%d mirror=%d posx=%d posy=%d out_width = %d \n"
335012e3ca3SMauro Carvalho Chehab 		"out_height=%d rotation_type=%d screen_width=%d\n", __func__,
336012e3ca3SMauro Carvalho Chehab 		ovl->is_enabled(ovl), &info.paddr, info.width, info.height,
337012e3ca3SMauro Carvalho Chehab 		info.color_mode, info.rotation, info.mirror, info.pos_x,
338012e3ca3SMauro Carvalho Chehab 		info.pos_y, info.out_width, info.out_height, info.rotation_type,
339012e3ca3SMauro Carvalho Chehab 		info.screen_width);
340012e3ca3SMauro Carvalho Chehab 
341012e3ca3SMauro Carvalho Chehab 	ret = ovl->set_overlay_info(ovl, &info);
342012e3ca3SMauro Carvalho Chehab 	if (ret)
343012e3ca3SMauro Carvalho Chehab 		goto setup_ovl_err;
344012e3ca3SMauro Carvalho Chehab 
345012e3ca3SMauro Carvalho Chehab 	return 0;
346012e3ca3SMauro Carvalho Chehab 
347012e3ca3SMauro Carvalho Chehab setup_ovl_err:
348012e3ca3SMauro Carvalho Chehab 	v4l2_warn(&vout->vid_dev->v4l2_dev, "setup_overlay failed\n");
349012e3ca3SMauro Carvalho Chehab 	return ret;
350012e3ca3SMauro Carvalho Chehab }
351012e3ca3SMauro Carvalho Chehab 
352012e3ca3SMauro Carvalho Chehab /*
353012e3ca3SMauro Carvalho Chehab  * Initialize the overlay structure
354012e3ca3SMauro Carvalho Chehab  */
omapvid_init(struct omap_vout_device * vout,dma_addr_t addr)355012e3ca3SMauro Carvalho Chehab static int omapvid_init(struct omap_vout_device *vout, dma_addr_t addr)
356012e3ca3SMauro Carvalho Chehab {
357012e3ca3SMauro Carvalho Chehab 	int ret = 0, i;
358012e3ca3SMauro Carvalho Chehab 	struct v4l2_window *win;
359012e3ca3SMauro Carvalho Chehab 	struct omap_overlay *ovl;
360012e3ca3SMauro Carvalho Chehab 	int posx, posy, outw, outh;
361012e3ca3SMauro Carvalho Chehab 	struct omap_video_timings *timing;
362012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid = &vout->vid_info;
363012e3ca3SMauro Carvalho Chehab 
364012e3ca3SMauro Carvalho Chehab 	win = &vout->win;
365012e3ca3SMauro Carvalho Chehab 	for (i = 0; i < ovid->num_overlays; i++) {
366012e3ca3SMauro Carvalho Chehab 		struct omap_dss_device *dssdev;
367012e3ca3SMauro Carvalho Chehab 
368012e3ca3SMauro Carvalho Chehab 		ovl = ovid->overlays[i];
369012e3ca3SMauro Carvalho Chehab 		dssdev = ovl->get_device(ovl);
370012e3ca3SMauro Carvalho Chehab 
371012e3ca3SMauro Carvalho Chehab 		if (!dssdev)
372012e3ca3SMauro Carvalho Chehab 			return -EINVAL;
373012e3ca3SMauro Carvalho Chehab 
374012e3ca3SMauro Carvalho Chehab 		timing = &dssdev->panel.timings;
375012e3ca3SMauro Carvalho Chehab 
376012e3ca3SMauro Carvalho Chehab 		outw = win->w.width;
377012e3ca3SMauro Carvalho Chehab 		outh = win->w.height;
378012e3ca3SMauro Carvalho Chehab 		switch (vout->rotation) {
379012e3ca3SMauro Carvalho Chehab 		case dss_rotation_90_degree:
380012e3ca3SMauro Carvalho Chehab 			/* Invert the height and width for 90
381012e3ca3SMauro Carvalho Chehab 			 * and 270 degree rotation
382012e3ca3SMauro Carvalho Chehab 			 */
383012e3ca3SMauro Carvalho Chehab 			swap(outw, outh);
384012e3ca3SMauro Carvalho Chehab 			posy = (timing->y_res - win->w.width) - win->w.left;
385012e3ca3SMauro Carvalho Chehab 			posx = win->w.top;
386012e3ca3SMauro Carvalho Chehab 			break;
387012e3ca3SMauro Carvalho Chehab 
388012e3ca3SMauro Carvalho Chehab 		case dss_rotation_180_degree:
389012e3ca3SMauro Carvalho Chehab 			posx = (timing->x_res - win->w.width) - win->w.left;
390012e3ca3SMauro Carvalho Chehab 			posy = (timing->y_res - win->w.height) - win->w.top;
391012e3ca3SMauro Carvalho Chehab 			break;
392012e3ca3SMauro Carvalho Chehab 
393012e3ca3SMauro Carvalho Chehab 		case dss_rotation_270_degree:
394012e3ca3SMauro Carvalho Chehab 			swap(outw, outh);
395012e3ca3SMauro Carvalho Chehab 			posy = win->w.left;
396012e3ca3SMauro Carvalho Chehab 			posx = (timing->x_res - win->w.height) - win->w.top;
397012e3ca3SMauro Carvalho Chehab 			break;
398012e3ca3SMauro Carvalho Chehab 
399012e3ca3SMauro Carvalho Chehab 		default:
400012e3ca3SMauro Carvalho Chehab 			posx = win->w.left;
401012e3ca3SMauro Carvalho Chehab 			posy = win->w.top;
402012e3ca3SMauro Carvalho Chehab 			break;
403012e3ca3SMauro Carvalho Chehab 		}
404012e3ca3SMauro Carvalho Chehab 
405012e3ca3SMauro Carvalho Chehab 		ret = omapvid_setup_overlay(vout, ovl, posx, posy,
406012e3ca3SMauro Carvalho Chehab 				outw, outh, addr);
407012e3ca3SMauro Carvalho Chehab 		if (ret)
408012e3ca3SMauro Carvalho Chehab 			goto omapvid_init_err;
409012e3ca3SMauro Carvalho Chehab 	}
410012e3ca3SMauro Carvalho Chehab 	return 0;
411012e3ca3SMauro Carvalho Chehab 
412012e3ca3SMauro Carvalho Chehab omapvid_init_err:
413012e3ca3SMauro Carvalho Chehab 	v4l2_warn(&vout->vid_dev->v4l2_dev, "apply_changes failed\n");
414012e3ca3SMauro Carvalho Chehab 	return ret;
415012e3ca3SMauro Carvalho Chehab }
416012e3ca3SMauro Carvalho Chehab 
417012e3ca3SMauro Carvalho Chehab /*
418012e3ca3SMauro Carvalho Chehab  * Apply the changes set the go bit of DSS
419012e3ca3SMauro Carvalho Chehab  */
omapvid_apply_changes(struct omap_vout_device * vout)420012e3ca3SMauro Carvalho Chehab static int omapvid_apply_changes(struct omap_vout_device *vout)
421012e3ca3SMauro Carvalho Chehab {
422012e3ca3SMauro Carvalho Chehab 	int i;
423012e3ca3SMauro Carvalho Chehab 	struct omap_overlay *ovl;
424012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid = &vout->vid_info;
425012e3ca3SMauro Carvalho Chehab 
426012e3ca3SMauro Carvalho Chehab 	for (i = 0; i < ovid->num_overlays; i++) {
427012e3ca3SMauro Carvalho Chehab 		struct omap_dss_device *dssdev;
428012e3ca3SMauro Carvalho Chehab 
429012e3ca3SMauro Carvalho Chehab 		ovl = ovid->overlays[i];
430012e3ca3SMauro Carvalho Chehab 		dssdev = ovl->get_device(ovl);
431012e3ca3SMauro Carvalho Chehab 		if (!dssdev)
432012e3ca3SMauro Carvalho Chehab 			return -EINVAL;
433012e3ca3SMauro Carvalho Chehab 		ovl->manager->apply(ovl->manager);
434012e3ca3SMauro Carvalho Chehab 	}
435012e3ca3SMauro Carvalho Chehab 
436012e3ca3SMauro Carvalho Chehab 	return 0;
437012e3ca3SMauro Carvalho Chehab }
438012e3ca3SMauro Carvalho Chehab 
omapvid_handle_interlace_display(struct omap_vout_device * vout,unsigned int irqstatus,u64 ts)439012e3ca3SMauro Carvalho Chehab static int omapvid_handle_interlace_display(struct omap_vout_device *vout,
440012e3ca3SMauro Carvalho Chehab 		unsigned int irqstatus, u64 ts)
441012e3ca3SMauro Carvalho Chehab {
442012e3ca3SMauro Carvalho Chehab 	u32 fid;
443012e3ca3SMauro Carvalho Chehab 
444012e3ca3SMauro Carvalho Chehab 	if (vout->first_int) {
445012e3ca3SMauro Carvalho Chehab 		vout->first_int = 0;
446012e3ca3SMauro Carvalho Chehab 		goto err;
447012e3ca3SMauro Carvalho Chehab 	}
448012e3ca3SMauro Carvalho Chehab 
449012e3ca3SMauro Carvalho Chehab 	if (irqstatus & DISPC_IRQ_EVSYNC_ODD)
450012e3ca3SMauro Carvalho Chehab 		fid = 1;
451012e3ca3SMauro Carvalho Chehab 	else if (irqstatus & DISPC_IRQ_EVSYNC_EVEN)
452012e3ca3SMauro Carvalho Chehab 		fid = 0;
453012e3ca3SMauro Carvalho Chehab 	else
454012e3ca3SMauro Carvalho Chehab 		goto err;
455012e3ca3SMauro Carvalho Chehab 
456012e3ca3SMauro Carvalho Chehab 	vout->field_id ^= 1;
457012e3ca3SMauro Carvalho Chehab 	if (fid != vout->field_id) {
458012e3ca3SMauro Carvalho Chehab 		if (fid == 0)
459012e3ca3SMauro Carvalho Chehab 			vout->field_id = fid;
460012e3ca3SMauro Carvalho Chehab 	} else if (0 == fid) {
461012e3ca3SMauro Carvalho Chehab 		if (vout->cur_frm == vout->next_frm)
462012e3ca3SMauro Carvalho Chehab 			goto err;
463012e3ca3SMauro Carvalho Chehab 
464012e3ca3SMauro Carvalho Chehab 		vout->cur_frm->vbuf.vb2_buf.timestamp = ts;
465012e3ca3SMauro Carvalho Chehab 		vout->cur_frm->vbuf.sequence = vout->sequence++;
466012e3ca3SMauro Carvalho Chehab 		vb2_buffer_done(&vout->cur_frm->vbuf.vb2_buf, VB2_BUF_STATE_DONE);
467012e3ca3SMauro Carvalho Chehab 		vout->cur_frm = vout->next_frm;
468012e3ca3SMauro Carvalho Chehab 	} else {
469012e3ca3SMauro Carvalho Chehab 		if (list_empty(&vout->dma_queue) ||
470012e3ca3SMauro Carvalho Chehab 				(vout->cur_frm != vout->next_frm))
471012e3ca3SMauro Carvalho Chehab 			goto err;
472012e3ca3SMauro Carvalho Chehab 	}
473012e3ca3SMauro Carvalho Chehab 
474012e3ca3SMauro Carvalho Chehab 	return vout->field_id;
475012e3ca3SMauro Carvalho Chehab err:
476012e3ca3SMauro Carvalho Chehab 	return 0;
477012e3ca3SMauro Carvalho Chehab }
478012e3ca3SMauro Carvalho Chehab 
omap_vout_isr(void * arg,unsigned int irqstatus)479012e3ca3SMauro Carvalho Chehab static void omap_vout_isr(void *arg, unsigned int irqstatus)
480012e3ca3SMauro Carvalho Chehab {
481012e3ca3SMauro Carvalho Chehab 	int ret, fid, mgr_id;
482012e3ca3SMauro Carvalho Chehab 	dma_addr_t addr;
483012e3ca3SMauro Carvalho Chehab 	u32 irq;
484012e3ca3SMauro Carvalho Chehab 	struct omap_overlay *ovl;
485012e3ca3SMauro Carvalho Chehab 	u64 ts;
486012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid;
487012e3ca3SMauro Carvalho Chehab 	struct omap_dss_device *cur_display;
488012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = (struct omap_vout_device *)arg;
489012e3ca3SMauro Carvalho Chehab 
490012e3ca3SMauro Carvalho Chehab 	ovid = &vout->vid_info;
491012e3ca3SMauro Carvalho Chehab 	ovl = ovid->overlays[0];
492012e3ca3SMauro Carvalho Chehab 
493012e3ca3SMauro Carvalho Chehab 	mgr_id = ovl->manager->id;
494012e3ca3SMauro Carvalho Chehab 
495012e3ca3SMauro Carvalho Chehab 	/* get the display device attached to the overlay */
496012e3ca3SMauro Carvalho Chehab 	cur_display = ovl->get_device(ovl);
497012e3ca3SMauro Carvalho Chehab 
498012e3ca3SMauro Carvalho Chehab 	if (!cur_display)
499012e3ca3SMauro Carvalho Chehab 		return;
500012e3ca3SMauro Carvalho Chehab 
501012e3ca3SMauro Carvalho Chehab 	spin_lock(&vout->vbq_lock);
502012e3ca3SMauro Carvalho Chehab 	ts = ktime_get_ns();
503012e3ca3SMauro Carvalho Chehab 
504012e3ca3SMauro Carvalho Chehab 	switch (cur_display->type) {
505012e3ca3SMauro Carvalho Chehab 	case OMAP_DISPLAY_TYPE_DSI:
506012e3ca3SMauro Carvalho Chehab 	case OMAP_DISPLAY_TYPE_DPI:
507012e3ca3SMauro Carvalho Chehab 	case OMAP_DISPLAY_TYPE_DVI:
508012e3ca3SMauro Carvalho Chehab 		if (mgr_id == OMAP_DSS_CHANNEL_LCD)
509012e3ca3SMauro Carvalho Chehab 			irq = DISPC_IRQ_VSYNC;
510012e3ca3SMauro Carvalho Chehab 		else if (mgr_id == OMAP_DSS_CHANNEL_LCD2)
511012e3ca3SMauro Carvalho Chehab 			irq = DISPC_IRQ_VSYNC2;
512012e3ca3SMauro Carvalho Chehab 		else
513012e3ca3SMauro Carvalho Chehab 			goto vout_isr_err;
514012e3ca3SMauro Carvalho Chehab 
515012e3ca3SMauro Carvalho Chehab 		if (!(irqstatus & irq))
516012e3ca3SMauro Carvalho Chehab 			goto vout_isr_err;
517012e3ca3SMauro Carvalho Chehab 		break;
518012e3ca3SMauro Carvalho Chehab 	case OMAP_DISPLAY_TYPE_VENC:
519012e3ca3SMauro Carvalho Chehab 		fid = omapvid_handle_interlace_display(vout, irqstatus,
520012e3ca3SMauro Carvalho Chehab 				ts);
521012e3ca3SMauro Carvalho Chehab 		if (!fid)
522012e3ca3SMauro Carvalho Chehab 			goto vout_isr_err;
523012e3ca3SMauro Carvalho Chehab 		break;
524012e3ca3SMauro Carvalho Chehab 	case OMAP_DISPLAY_TYPE_HDMI:
525012e3ca3SMauro Carvalho Chehab 		if (!(irqstatus & DISPC_IRQ_EVSYNC_EVEN))
526012e3ca3SMauro Carvalho Chehab 			goto vout_isr_err;
527012e3ca3SMauro Carvalho Chehab 		break;
528012e3ca3SMauro Carvalho Chehab 	default:
529012e3ca3SMauro Carvalho Chehab 		goto vout_isr_err;
530012e3ca3SMauro Carvalho Chehab 	}
531012e3ca3SMauro Carvalho Chehab 
532012e3ca3SMauro Carvalho Chehab 	if (!vout->first_int && (vout->cur_frm != vout->next_frm)) {
533012e3ca3SMauro Carvalho Chehab 		vout->cur_frm->vbuf.vb2_buf.timestamp = ts;
534012e3ca3SMauro Carvalho Chehab 		vout->cur_frm->vbuf.sequence = vout->sequence++;
535012e3ca3SMauro Carvalho Chehab 		vb2_buffer_done(&vout->cur_frm->vbuf.vb2_buf, VB2_BUF_STATE_DONE);
536012e3ca3SMauro Carvalho Chehab 		vout->cur_frm = vout->next_frm;
537012e3ca3SMauro Carvalho Chehab 	}
538012e3ca3SMauro Carvalho Chehab 
539012e3ca3SMauro Carvalho Chehab 	vout->first_int = 0;
540012e3ca3SMauro Carvalho Chehab 	if (list_empty(&vout->dma_queue))
541012e3ca3SMauro Carvalho Chehab 		goto vout_isr_err;
542012e3ca3SMauro Carvalho Chehab 
543012e3ca3SMauro Carvalho Chehab 	vout->next_frm = list_entry(vout->dma_queue.next,
544012e3ca3SMauro Carvalho Chehab 			struct omap_vout_buffer, queue);
545012e3ca3SMauro Carvalho Chehab 	list_del(&vout->next_frm->queue);
546012e3ca3SMauro Carvalho Chehab 
547012e3ca3SMauro Carvalho Chehab 	addr = vout->queued_buf_addr[vout->next_frm->vbuf.vb2_buf.index]
548012e3ca3SMauro Carvalho Chehab 		+ vout->cropped_offset;
549012e3ca3SMauro Carvalho Chehab 
550012e3ca3SMauro Carvalho Chehab 	/* First save the configuration in ovelray structure */
551012e3ca3SMauro Carvalho Chehab 	ret = omapvid_init(vout, addr);
552012e3ca3SMauro Carvalho Chehab 	if (ret) {
553012e3ca3SMauro Carvalho Chehab 		printk(KERN_ERR VOUT_NAME
554012e3ca3SMauro Carvalho Chehab 			"failed to set overlay info\n");
555012e3ca3SMauro Carvalho Chehab 		goto vout_isr_err;
556012e3ca3SMauro Carvalho Chehab 	}
557012e3ca3SMauro Carvalho Chehab 
558012e3ca3SMauro Carvalho Chehab 	/* Enable the pipeline and set the Go bit */
559012e3ca3SMauro Carvalho Chehab 	ret = omapvid_apply_changes(vout);
560012e3ca3SMauro Carvalho Chehab 	if (ret)
561012e3ca3SMauro Carvalho Chehab 		printk(KERN_ERR VOUT_NAME "failed to change mode\n");
562012e3ca3SMauro Carvalho Chehab 
563012e3ca3SMauro Carvalho Chehab vout_isr_err:
564012e3ca3SMauro Carvalho Chehab 	spin_unlock(&vout->vbq_lock);
565012e3ca3SMauro Carvalho Chehab }
566012e3ca3SMauro Carvalho Chehab 
567012e3ca3SMauro Carvalho Chehab 
568012e3ca3SMauro Carvalho Chehab /*
569012e3ca3SMauro Carvalho Chehab  * V4L2 ioctls
570012e3ca3SMauro Carvalho Chehab  */
vidioc_querycap(struct file * file,void * fh,struct v4l2_capability * cap)571012e3ca3SMauro Carvalho Chehab static int vidioc_querycap(struct file *file, void *fh,
572012e3ca3SMauro Carvalho Chehab 		struct v4l2_capability *cap)
573012e3ca3SMauro Carvalho Chehab {
574012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = video_drvdata(file);
575012e3ca3SMauro Carvalho Chehab 
576012e3ca3SMauro Carvalho Chehab 	strscpy(cap->driver, VOUT_NAME, sizeof(cap->driver));
577012e3ca3SMauro Carvalho Chehab 	strscpy(cap->card, vout->vfd->name, sizeof(cap->card));
578012e3ca3SMauro Carvalho Chehab 	snprintf(cap->bus_info, sizeof(cap->bus_info),
579012e3ca3SMauro Carvalho Chehab 		 "platform:%s.%d", VOUT_NAME, vout->vid);
580012e3ca3SMauro Carvalho Chehab 	return 0;
581012e3ca3SMauro Carvalho Chehab }
582012e3ca3SMauro Carvalho Chehab 
vidioc_enum_fmt_vid_out(struct file * file,void * fh,struct v4l2_fmtdesc * fmt)583012e3ca3SMauro Carvalho Chehab static int vidioc_enum_fmt_vid_out(struct file *file, void *fh,
584012e3ca3SMauro Carvalho Chehab 			struct v4l2_fmtdesc *fmt)
585012e3ca3SMauro Carvalho Chehab {
586012e3ca3SMauro Carvalho Chehab 	int index = fmt->index;
587012e3ca3SMauro Carvalho Chehab 
588012e3ca3SMauro Carvalho Chehab 	if (index >= NUM_OUTPUT_FORMATS)
589012e3ca3SMauro Carvalho Chehab 		return -EINVAL;
590012e3ca3SMauro Carvalho Chehab 
591012e3ca3SMauro Carvalho Chehab 	fmt->flags = omap_formats[index].flags;
592012e3ca3SMauro Carvalho Chehab 	fmt->pixelformat = omap_formats[index].pixelformat;
593012e3ca3SMauro Carvalho Chehab 
594012e3ca3SMauro Carvalho Chehab 	return 0;
595012e3ca3SMauro Carvalho Chehab }
596012e3ca3SMauro Carvalho Chehab 
vidioc_g_fmt_vid_out(struct file * file,void * fh,struct v4l2_format * f)597012e3ca3SMauro Carvalho Chehab static int vidioc_g_fmt_vid_out(struct file *file, void *fh,
598012e3ca3SMauro Carvalho Chehab 			struct v4l2_format *f)
599012e3ca3SMauro Carvalho Chehab {
600012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = video_drvdata(file);
601012e3ca3SMauro Carvalho Chehab 
602012e3ca3SMauro Carvalho Chehab 	f->fmt.pix = vout->pix;
603012e3ca3SMauro Carvalho Chehab 	return 0;
604012e3ca3SMauro Carvalho Chehab 
605012e3ca3SMauro Carvalho Chehab }
606012e3ca3SMauro Carvalho Chehab 
vidioc_try_fmt_vid_out(struct file * file,void * fh,struct v4l2_format * f)607012e3ca3SMauro Carvalho Chehab static int vidioc_try_fmt_vid_out(struct file *file, void *fh,
608012e3ca3SMauro Carvalho Chehab 			struct v4l2_format *f)
609012e3ca3SMauro Carvalho Chehab {
610012e3ca3SMauro Carvalho Chehab 	struct omap_overlay *ovl;
611012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid;
612012e3ca3SMauro Carvalho Chehab 	struct omap_video_timings *timing;
613012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = video_drvdata(file);
614012e3ca3SMauro Carvalho Chehab 	struct omap_dss_device *dssdev;
615012e3ca3SMauro Carvalho Chehab 
616012e3ca3SMauro Carvalho Chehab 	ovid = &vout->vid_info;
617012e3ca3SMauro Carvalho Chehab 	ovl = ovid->overlays[0];
618012e3ca3SMauro Carvalho Chehab 	/* get the display device attached to the overlay */
619012e3ca3SMauro Carvalho Chehab 	dssdev = ovl->get_device(ovl);
620012e3ca3SMauro Carvalho Chehab 
621012e3ca3SMauro Carvalho Chehab 	if (!dssdev)
622012e3ca3SMauro Carvalho Chehab 		return -EINVAL;
623012e3ca3SMauro Carvalho Chehab 
624012e3ca3SMauro Carvalho Chehab 	timing = &dssdev->panel.timings;
625012e3ca3SMauro Carvalho Chehab 
626012e3ca3SMauro Carvalho Chehab 	vout->fbuf.fmt.height = timing->y_res;
627012e3ca3SMauro Carvalho Chehab 	vout->fbuf.fmt.width = timing->x_res;
628012e3ca3SMauro Carvalho Chehab 
629012e3ca3SMauro Carvalho Chehab 	omap_vout_try_format(&f->fmt.pix);
630012e3ca3SMauro Carvalho Chehab 	return 0;
631012e3ca3SMauro Carvalho Chehab }
632012e3ca3SMauro Carvalho Chehab 
vidioc_s_fmt_vid_out(struct file * file,void * fh,struct v4l2_format * f)633012e3ca3SMauro Carvalho Chehab static int vidioc_s_fmt_vid_out(struct file *file, void *fh,
634012e3ca3SMauro Carvalho Chehab 			struct v4l2_format *f)
635012e3ca3SMauro Carvalho Chehab {
636012e3ca3SMauro Carvalho Chehab 	int ret, bpp;
637012e3ca3SMauro Carvalho Chehab 	struct omap_overlay *ovl;
638012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid;
639012e3ca3SMauro Carvalho Chehab 	struct omap_video_timings *timing;
640012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = video_drvdata(file);
641012e3ca3SMauro Carvalho Chehab 	struct omap_dss_device *dssdev;
642012e3ca3SMauro Carvalho Chehab 
643012e3ca3SMauro Carvalho Chehab 	if (vb2_is_busy(&vout->vq))
644012e3ca3SMauro Carvalho Chehab 		return -EBUSY;
645012e3ca3SMauro Carvalho Chehab 
646012e3ca3SMauro Carvalho Chehab 	ovid = &vout->vid_info;
647012e3ca3SMauro Carvalho Chehab 	ovl = ovid->overlays[0];
648012e3ca3SMauro Carvalho Chehab 	dssdev = ovl->get_device(ovl);
649012e3ca3SMauro Carvalho Chehab 
650012e3ca3SMauro Carvalho Chehab 	/* get the display device attached to the overlay */
651012e3ca3SMauro Carvalho Chehab 	if (!dssdev) {
652012e3ca3SMauro Carvalho Chehab 		ret = -EINVAL;
653012e3ca3SMauro Carvalho Chehab 		goto s_fmt_vid_out_exit;
654012e3ca3SMauro Carvalho Chehab 	}
655012e3ca3SMauro Carvalho Chehab 	timing = &dssdev->panel.timings;
656012e3ca3SMauro Carvalho Chehab 
657012e3ca3SMauro Carvalho Chehab 	/* We don't support RGB24-packed mode if vrfb rotation
658012e3ca3SMauro Carvalho Chehab 	 * is enabled*/
659012e3ca3SMauro Carvalho Chehab 	if ((is_rotation_enabled(vout)) &&
660012e3ca3SMauro Carvalho Chehab 			f->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB24) {
661012e3ca3SMauro Carvalho Chehab 		ret = -EINVAL;
662012e3ca3SMauro Carvalho Chehab 		goto s_fmt_vid_out_exit;
663012e3ca3SMauro Carvalho Chehab 	}
664012e3ca3SMauro Carvalho Chehab 
665012e3ca3SMauro Carvalho Chehab 	/* get the framebuffer parameters */
666012e3ca3SMauro Carvalho Chehab 
667012e3ca3SMauro Carvalho Chehab 	if (is_rotation_90_or_270(vout)) {
668012e3ca3SMauro Carvalho Chehab 		vout->fbuf.fmt.height = timing->x_res;
669012e3ca3SMauro Carvalho Chehab 		vout->fbuf.fmt.width = timing->y_res;
670012e3ca3SMauro Carvalho Chehab 	} else {
671012e3ca3SMauro Carvalho Chehab 		vout->fbuf.fmt.height = timing->y_res;
672012e3ca3SMauro Carvalho Chehab 		vout->fbuf.fmt.width = timing->x_res;
673012e3ca3SMauro Carvalho Chehab 	}
674012e3ca3SMauro Carvalho Chehab 
675012e3ca3SMauro Carvalho Chehab 	/* change to smaller size is OK */
676012e3ca3SMauro Carvalho Chehab 
677012e3ca3SMauro Carvalho Chehab 	bpp = omap_vout_try_format(&f->fmt.pix);
678012e3ca3SMauro Carvalho Chehab 	f->fmt.pix.sizeimage = f->fmt.pix.width * f->fmt.pix.height * bpp;
679012e3ca3SMauro Carvalho Chehab 
680012e3ca3SMauro Carvalho Chehab 	/* try & set the new output format */
681012e3ca3SMauro Carvalho Chehab 	vout->bpp = bpp;
682012e3ca3SMauro Carvalho Chehab 	vout->pix = f->fmt.pix;
683012e3ca3SMauro Carvalho Chehab 	vout->vrfb_bpp = 1;
684012e3ca3SMauro Carvalho Chehab 
685012e3ca3SMauro Carvalho Chehab 	/* If YUYV then vrfb bpp is 2, for  others its 1 */
686012e3ca3SMauro Carvalho Chehab 	if (V4L2_PIX_FMT_YUYV == vout->pix.pixelformat ||
687012e3ca3SMauro Carvalho Chehab 			V4L2_PIX_FMT_UYVY == vout->pix.pixelformat)
688012e3ca3SMauro Carvalho Chehab 		vout->vrfb_bpp = 2;
689012e3ca3SMauro Carvalho Chehab 
690012e3ca3SMauro Carvalho Chehab 	/* set default crop and win */
691012e3ca3SMauro Carvalho Chehab 	omap_vout_new_format(&vout->pix, &vout->fbuf, &vout->crop, &vout->win);
692012e3ca3SMauro Carvalho Chehab 
693012e3ca3SMauro Carvalho Chehab 	ret = 0;
694012e3ca3SMauro Carvalho Chehab 
695012e3ca3SMauro Carvalho Chehab s_fmt_vid_out_exit:
696012e3ca3SMauro Carvalho Chehab 	return ret;
697012e3ca3SMauro Carvalho Chehab }
698012e3ca3SMauro Carvalho Chehab 
vidioc_try_fmt_vid_overlay(struct file * file,void * fh,struct v4l2_format * f)699012e3ca3SMauro Carvalho Chehab static int vidioc_try_fmt_vid_overlay(struct file *file, void *fh,
700012e3ca3SMauro Carvalho Chehab 			struct v4l2_format *f)
701012e3ca3SMauro Carvalho Chehab {
702012e3ca3SMauro Carvalho Chehab 	int ret = 0;
703012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = video_drvdata(file);
704012e3ca3SMauro Carvalho Chehab 	struct omap_overlay *ovl;
705012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid;
706012e3ca3SMauro Carvalho Chehab 	struct v4l2_window *win = &f->fmt.win;
707012e3ca3SMauro Carvalho Chehab 
708012e3ca3SMauro Carvalho Chehab 	ovid = &vout->vid_info;
709012e3ca3SMauro Carvalho Chehab 	ovl = ovid->overlays[0];
710012e3ca3SMauro Carvalho Chehab 
711012e3ca3SMauro Carvalho Chehab 	ret = omap_vout_try_window(&vout->fbuf, win);
712012e3ca3SMauro Carvalho Chehab 
713012e3ca3SMauro Carvalho Chehab 	if (!ret && !(ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA))
714012e3ca3SMauro Carvalho Chehab 		win->global_alpha = 0;
715012e3ca3SMauro Carvalho Chehab 
716012e3ca3SMauro Carvalho Chehab 	return ret;
717012e3ca3SMauro Carvalho Chehab }
718012e3ca3SMauro Carvalho Chehab 
vidioc_s_fmt_vid_overlay(struct file * file,void * fh,struct v4l2_format * f)719012e3ca3SMauro Carvalho Chehab static int vidioc_s_fmt_vid_overlay(struct file *file, void *fh,
720012e3ca3SMauro Carvalho Chehab 			struct v4l2_format *f)
721012e3ca3SMauro Carvalho Chehab {
722012e3ca3SMauro Carvalho Chehab 	int ret = 0;
723012e3ca3SMauro Carvalho Chehab 	struct omap_overlay *ovl;
724012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid;
725012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = video_drvdata(file);
726012e3ca3SMauro Carvalho Chehab 	struct v4l2_window *win = &f->fmt.win;
727012e3ca3SMauro Carvalho Chehab 
728012e3ca3SMauro Carvalho Chehab 	ovid = &vout->vid_info;
729012e3ca3SMauro Carvalho Chehab 	ovl = ovid->overlays[0];
730012e3ca3SMauro Carvalho Chehab 
731012e3ca3SMauro Carvalho Chehab 	ret = omap_vout_new_window(&vout->crop, &vout->win, &vout->fbuf, win);
732012e3ca3SMauro Carvalho Chehab 	if (!ret) {
733012e3ca3SMauro Carvalho Chehab 		enum omap_dss_trans_key_type key_type =
734012e3ca3SMauro Carvalho Chehab 			OMAP_DSS_COLOR_KEY_GFX_DST;
735012e3ca3SMauro Carvalho Chehab 		int enable;
736012e3ca3SMauro Carvalho Chehab 
737012e3ca3SMauro Carvalho Chehab 		/* Video1 plane does not support global alpha on OMAP3 */
738012e3ca3SMauro Carvalho Chehab 		if (ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA)
739012e3ca3SMauro Carvalho Chehab 			vout->win.global_alpha = win->global_alpha;
740012e3ca3SMauro Carvalho Chehab 		else
741012e3ca3SMauro Carvalho Chehab 			win->global_alpha = 0;
742012e3ca3SMauro Carvalho Chehab 		if (vout->fbuf.flags & (V4L2_FBUF_FLAG_CHROMAKEY |
743012e3ca3SMauro Carvalho Chehab 					V4L2_FBUF_FLAG_SRC_CHROMAKEY))
744012e3ca3SMauro Carvalho Chehab 			enable = 1;
745012e3ca3SMauro Carvalho Chehab 		else
746012e3ca3SMauro Carvalho Chehab 			enable = 0;
747012e3ca3SMauro Carvalho Chehab 		if (vout->fbuf.flags & V4L2_FBUF_FLAG_SRC_CHROMAKEY)
748012e3ca3SMauro Carvalho Chehab 			key_type = OMAP_DSS_COLOR_KEY_VID_SRC;
749012e3ca3SMauro Carvalho Chehab 
750012e3ca3SMauro Carvalho Chehab 		if (ovl->manager && ovl->manager->get_manager_info &&
751012e3ca3SMauro Carvalho Chehab 		    ovl->manager->set_manager_info) {
752012e3ca3SMauro Carvalho Chehab 			struct omap_overlay_manager_info info;
753012e3ca3SMauro Carvalho Chehab 
754012e3ca3SMauro Carvalho Chehab 			ovl->manager->get_manager_info(ovl->manager, &info);
755012e3ca3SMauro Carvalho Chehab 			info.trans_enabled = enable;
756012e3ca3SMauro Carvalho Chehab 			info.trans_key_type = key_type;
757012e3ca3SMauro Carvalho Chehab 			info.trans_key = vout->win.chromakey;
758012e3ca3SMauro Carvalho Chehab 
759012e3ca3SMauro Carvalho Chehab 			if (ovl->manager->set_manager_info(ovl->manager, &info))
760012e3ca3SMauro Carvalho Chehab 				return -EINVAL;
761012e3ca3SMauro Carvalho Chehab 		}
762012e3ca3SMauro Carvalho Chehab 	}
763012e3ca3SMauro Carvalho Chehab 	return ret;
764012e3ca3SMauro Carvalho Chehab }
765012e3ca3SMauro Carvalho Chehab 
vidioc_g_fmt_vid_overlay(struct file * file,void * fh,struct v4l2_format * f)766012e3ca3SMauro Carvalho Chehab static int vidioc_g_fmt_vid_overlay(struct file *file, void *fh,
767012e3ca3SMauro Carvalho Chehab 			struct v4l2_format *f)
768012e3ca3SMauro Carvalho Chehab {
769012e3ca3SMauro Carvalho Chehab 	struct omap_overlay *ovl;
770012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid;
771012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = video_drvdata(file);
772012e3ca3SMauro Carvalho Chehab 	struct v4l2_window *win = &f->fmt.win;
773012e3ca3SMauro Carvalho Chehab 
774012e3ca3SMauro Carvalho Chehab 	ovid = &vout->vid_info;
775012e3ca3SMauro Carvalho Chehab 	ovl = ovid->overlays[0];
776012e3ca3SMauro Carvalho Chehab 
777012e3ca3SMauro Carvalho Chehab 	win->w = vout->win.w;
778012e3ca3SMauro Carvalho Chehab 	win->field = vout->win.field;
779012e3ca3SMauro Carvalho Chehab 	win->chromakey = vout->win.chromakey;
780012e3ca3SMauro Carvalho Chehab 	if (ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA)
781012e3ca3SMauro Carvalho Chehab 		win->global_alpha = vout->win.global_alpha;
782012e3ca3SMauro Carvalho Chehab 	else
783012e3ca3SMauro Carvalho Chehab 		win->global_alpha = 0;
784012e3ca3SMauro Carvalho Chehab 	win->clips = NULL;
785012e3ca3SMauro Carvalho Chehab 	win->clipcount = 0;
786012e3ca3SMauro Carvalho Chehab 	win->bitmap = NULL;
787012e3ca3SMauro Carvalho Chehab 	return 0;
788012e3ca3SMauro Carvalho Chehab }
789012e3ca3SMauro Carvalho Chehab 
vidioc_g_selection(struct file * file,void * fh,struct v4l2_selection * sel)790012e3ca3SMauro Carvalho Chehab static int vidioc_g_selection(struct file *file, void *fh, struct v4l2_selection *sel)
791012e3ca3SMauro Carvalho Chehab {
792012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = video_drvdata(file);
793012e3ca3SMauro Carvalho Chehab 	struct v4l2_pix_format *pix = &vout->pix;
794012e3ca3SMauro Carvalho Chehab 
795012e3ca3SMauro Carvalho Chehab 	if (sel->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
796012e3ca3SMauro Carvalho Chehab 		return -EINVAL;
797012e3ca3SMauro Carvalho Chehab 
798012e3ca3SMauro Carvalho Chehab 	switch (sel->target) {
799012e3ca3SMauro Carvalho Chehab 	case V4L2_SEL_TGT_CROP:
800012e3ca3SMauro Carvalho Chehab 		sel->r = vout->crop;
801012e3ca3SMauro Carvalho Chehab 		break;
802012e3ca3SMauro Carvalho Chehab 	case V4L2_SEL_TGT_CROP_DEFAULT:
803012e3ca3SMauro Carvalho Chehab 		omap_vout_default_crop(&vout->pix, &vout->fbuf, &sel->r);
804012e3ca3SMauro Carvalho Chehab 		break;
805012e3ca3SMauro Carvalho Chehab 	case V4L2_SEL_TGT_CROP_BOUNDS:
806012e3ca3SMauro Carvalho Chehab 		/* Width and height are always even */
807012e3ca3SMauro Carvalho Chehab 		sel->r.width = pix->width & ~1;
808012e3ca3SMauro Carvalho Chehab 		sel->r.height = pix->height & ~1;
809012e3ca3SMauro Carvalho Chehab 		break;
810012e3ca3SMauro Carvalho Chehab 	default:
811012e3ca3SMauro Carvalho Chehab 		return -EINVAL;
812012e3ca3SMauro Carvalho Chehab 	}
813012e3ca3SMauro Carvalho Chehab 	return 0;
814012e3ca3SMauro Carvalho Chehab }
815012e3ca3SMauro Carvalho Chehab 
vidioc_s_selection(struct file * file,void * fh,struct v4l2_selection * sel)816012e3ca3SMauro Carvalho Chehab static int vidioc_s_selection(struct file *file, void *fh, struct v4l2_selection *sel)
817012e3ca3SMauro Carvalho Chehab {
818012e3ca3SMauro Carvalho Chehab 	int ret = -EINVAL;
819012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = video_drvdata(file);
820012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid;
821012e3ca3SMauro Carvalho Chehab 	struct omap_overlay *ovl;
822012e3ca3SMauro Carvalho Chehab 	struct omap_video_timings *timing;
823012e3ca3SMauro Carvalho Chehab 	struct omap_dss_device *dssdev;
824012e3ca3SMauro Carvalho Chehab 
825012e3ca3SMauro Carvalho Chehab 	if (sel->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
826012e3ca3SMauro Carvalho Chehab 		return -EINVAL;
827012e3ca3SMauro Carvalho Chehab 
828012e3ca3SMauro Carvalho Chehab 	if (sel->target != V4L2_SEL_TGT_CROP)
829012e3ca3SMauro Carvalho Chehab 		return -EINVAL;
830012e3ca3SMauro Carvalho Chehab 
831012e3ca3SMauro Carvalho Chehab 	if (vb2_is_busy(&vout->vq))
832012e3ca3SMauro Carvalho Chehab 		return -EBUSY;
833012e3ca3SMauro Carvalho Chehab 
834012e3ca3SMauro Carvalho Chehab 	ovid = &vout->vid_info;
835012e3ca3SMauro Carvalho Chehab 	ovl = ovid->overlays[0];
836012e3ca3SMauro Carvalho Chehab 	/* get the display device attached to the overlay */
837012e3ca3SMauro Carvalho Chehab 	dssdev = ovl->get_device(ovl);
838012e3ca3SMauro Carvalho Chehab 
839012e3ca3SMauro Carvalho Chehab 	if (!dssdev) {
840012e3ca3SMauro Carvalho Chehab 		ret = -EINVAL;
841012e3ca3SMauro Carvalho Chehab 		goto s_crop_err;
842012e3ca3SMauro Carvalho Chehab 	}
843012e3ca3SMauro Carvalho Chehab 
844012e3ca3SMauro Carvalho Chehab 	timing = &dssdev->panel.timings;
845012e3ca3SMauro Carvalho Chehab 
846012e3ca3SMauro Carvalho Chehab 	if (is_rotation_90_or_270(vout)) {
847012e3ca3SMauro Carvalho Chehab 		vout->fbuf.fmt.height = timing->x_res;
848012e3ca3SMauro Carvalho Chehab 		vout->fbuf.fmt.width = timing->y_res;
849012e3ca3SMauro Carvalho Chehab 	} else {
850012e3ca3SMauro Carvalho Chehab 		vout->fbuf.fmt.height = timing->y_res;
851012e3ca3SMauro Carvalho Chehab 		vout->fbuf.fmt.width = timing->x_res;
852012e3ca3SMauro Carvalho Chehab 	}
853012e3ca3SMauro Carvalho Chehab 
854012e3ca3SMauro Carvalho Chehab 	ret = omap_vout_new_crop(&vout->pix, &vout->crop, &vout->win,
855012e3ca3SMauro Carvalho Chehab 				 &vout->fbuf, &sel->r);
856012e3ca3SMauro Carvalho Chehab 
857012e3ca3SMauro Carvalho Chehab s_crop_err:
858012e3ca3SMauro Carvalho Chehab 	return ret;
859012e3ca3SMauro Carvalho Chehab }
860012e3ca3SMauro Carvalho Chehab 
omap_vout_s_ctrl(struct v4l2_ctrl * ctrl)861012e3ca3SMauro Carvalho Chehab static int omap_vout_s_ctrl(struct v4l2_ctrl *ctrl)
862012e3ca3SMauro Carvalho Chehab {
863012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout =
864012e3ca3SMauro Carvalho Chehab 		container_of(ctrl->handler, struct omap_vout_device, ctrl_handler);
865012e3ca3SMauro Carvalho Chehab 	int ret = 0;
866012e3ca3SMauro Carvalho Chehab 
867012e3ca3SMauro Carvalho Chehab 	switch (ctrl->id) {
868012e3ca3SMauro Carvalho Chehab 	case V4L2_CID_ROTATE: {
869012e3ca3SMauro Carvalho Chehab 		struct omapvideo_info *ovid;
870012e3ca3SMauro Carvalho Chehab 		int rotation = ctrl->val;
871012e3ca3SMauro Carvalho Chehab 
872012e3ca3SMauro Carvalho Chehab 		ovid = &vout->vid_info;
873012e3ca3SMauro Carvalho Chehab 
874012e3ca3SMauro Carvalho Chehab 		if (rotation && ovid->rotation_type == VOUT_ROT_NONE) {
875012e3ca3SMauro Carvalho Chehab 			ret = -ERANGE;
876012e3ca3SMauro Carvalho Chehab 			break;
877012e3ca3SMauro Carvalho Chehab 		}
878012e3ca3SMauro Carvalho Chehab 
879012e3ca3SMauro Carvalho Chehab 		if (rotation && vout->pix.pixelformat == V4L2_PIX_FMT_RGB24) {
880012e3ca3SMauro Carvalho Chehab 			ret = -EINVAL;
881012e3ca3SMauro Carvalho Chehab 			break;
882012e3ca3SMauro Carvalho Chehab 		}
883012e3ca3SMauro Carvalho Chehab 
884012e3ca3SMauro Carvalho Chehab 		if (v4l2_rot_to_dss_rot(rotation, &vout->rotation,
885012e3ca3SMauro Carvalho Chehab 							vout->mirror)) {
886012e3ca3SMauro Carvalho Chehab 			ret = -EINVAL;
887012e3ca3SMauro Carvalho Chehab 			break;
888012e3ca3SMauro Carvalho Chehab 		}
889012e3ca3SMauro Carvalho Chehab 		break;
890012e3ca3SMauro Carvalho Chehab 	}
891012e3ca3SMauro Carvalho Chehab 	case V4L2_CID_BG_COLOR:
892012e3ca3SMauro Carvalho Chehab 	{
893012e3ca3SMauro Carvalho Chehab 		struct omap_overlay *ovl;
894012e3ca3SMauro Carvalho Chehab 		unsigned int color = ctrl->val;
895012e3ca3SMauro Carvalho Chehab 		struct omap_overlay_manager_info info;
896012e3ca3SMauro Carvalho Chehab 
897012e3ca3SMauro Carvalho Chehab 		ovl = vout->vid_info.overlays[0];
898012e3ca3SMauro Carvalho Chehab 
899012e3ca3SMauro Carvalho Chehab 		if (!ovl->manager || !ovl->manager->get_manager_info) {
900012e3ca3SMauro Carvalho Chehab 			ret = -EINVAL;
901012e3ca3SMauro Carvalho Chehab 			break;
902012e3ca3SMauro Carvalho Chehab 		}
903012e3ca3SMauro Carvalho Chehab 
904012e3ca3SMauro Carvalho Chehab 		ovl->manager->get_manager_info(ovl->manager, &info);
905012e3ca3SMauro Carvalho Chehab 		info.default_color = color;
906012e3ca3SMauro Carvalho Chehab 		if (ovl->manager->set_manager_info(ovl->manager, &info)) {
907012e3ca3SMauro Carvalho Chehab 			ret = -EINVAL;
908012e3ca3SMauro Carvalho Chehab 			break;
909012e3ca3SMauro Carvalho Chehab 		}
910012e3ca3SMauro Carvalho Chehab 		break;
911012e3ca3SMauro Carvalho Chehab 	}
912012e3ca3SMauro Carvalho Chehab 	case V4L2_CID_VFLIP:
913012e3ca3SMauro Carvalho Chehab 	{
914012e3ca3SMauro Carvalho Chehab 		struct omapvideo_info *ovid;
915012e3ca3SMauro Carvalho Chehab 		unsigned int mirror = ctrl->val;
916012e3ca3SMauro Carvalho Chehab 
917012e3ca3SMauro Carvalho Chehab 		ovid = &vout->vid_info;
918012e3ca3SMauro Carvalho Chehab 
919012e3ca3SMauro Carvalho Chehab 		if (mirror && ovid->rotation_type == VOUT_ROT_NONE) {
920012e3ca3SMauro Carvalho Chehab 			ret = -ERANGE;
921012e3ca3SMauro Carvalho Chehab 			break;
922012e3ca3SMauro Carvalho Chehab 		}
923012e3ca3SMauro Carvalho Chehab 
924012e3ca3SMauro Carvalho Chehab 		if (mirror  && vout->pix.pixelformat == V4L2_PIX_FMT_RGB24) {
925012e3ca3SMauro Carvalho Chehab 			ret = -EINVAL;
926012e3ca3SMauro Carvalho Chehab 			break;
927012e3ca3SMauro Carvalho Chehab 		}
928012e3ca3SMauro Carvalho Chehab 		vout->mirror = mirror;
929012e3ca3SMauro Carvalho Chehab 		break;
930012e3ca3SMauro Carvalho Chehab 	}
931012e3ca3SMauro Carvalho Chehab 	default:
932012e3ca3SMauro Carvalho Chehab 		return -EINVAL;
933012e3ca3SMauro Carvalho Chehab 	}
934012e3ca3SMauro Carvalho Chehab 	return ret;
935012e3ca3SMauro Carvalho Chehab }
936012e3ca3SMauro Carvalho Chehab 
937012e3ca3SMauro Carvalho Chehab static const struct v4l2_ctrl_ops omap_vout_ctrl_ops = {
938012e3ca3SMauro Carvalho Chehab 	.s_ctrl = omap_vout_s_ctrl,
939012e3ca3SMauro Carvalho Chehab };
940012e3ca3SMauro Carvalho Chehab 
omap_vout_vb2_queue_setup(struct vb2_queue * vq,unsigned int * nbufs,unsigned int * num_planes,unsigned int sizes[],struct device * alloc_devs[])941012e3ca3SMauro Carvalho Chehab static int omap_vout_vb2_queue_setup(struct vb2_queue *vq,
942012e3ca3SMauro Carvalho Chehab 				     unsigned int *nbufs,
943012e3ca3SMauro Carvalho Chehab 				     unsigned int *num_planes, unsigned int sizes[],
944012e3ca3SMauro Carvalho Chehab 				     struct device *alloc_devs[])
945012e3ca3SMauro Carvalho Chehab {
946012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = vb2_get_drv_priv(vq);
947012e3ca3SMauro Carvalho Chehab 	int size = vout->pix.sizeimage;
948012e3ca3SMauro Carvalho Chehab 
949012e3ca3SMauro Carvalho Chehab 	if (is_rotation_enabled(vout) && vq->num_buffers + *nbufs > VRFB_NUM_BUFS) {
950012e3ca3SMauro Carvalho Chehab 		*nbufs = VRFB_NUM_BUFS - vq->num_buffers;
951012e3ca3SMauro Carvalho Chehab 		if (*nbufs == 0)
952012e3ca3SMauro Carvalho Chehab 			return -EINVAL;
953012e3ca3SMauro Carvalho Chehab 	}
954012e3ca3SMauro Carvalho Chehab 
955012e3ca3SMauro Carvalho Chehab 	if (*num_planes)
956012e3ca3SMauro Carvalho Chehab 		return sizes[0] < size ? -EINVAL : 0;
957012e3ca3SMauro Carvalho Chehab 
958012e3ca3SMauro Carvalho Chehab 	*num_planes = 1;
959012e3ca3SMauro Carvalho Chehab 	sizes[0] = size;
960012e3ca3SMauro Carvalho Chehab 	return 0;
961012e3ca3SMauro Carvalho Chehab }
962012e3ca3SMauro Carvalho Chehab 
omap_vout_vb2_prepare(struct vb2_buffer * vb)963012e3ca3SMauro Carvalho Chehab static int omap_vout_vb2_prepare(struct vb2_buffer *vb)
964012e3ca3SMauro Carvalho Chehab {
965012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = vb2_get_drv_priv(vb->vb2_queue);
966012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid = &vout->vid_info;
967012e3ca3SMauro Carvalho Chehab 	struct omap_vout_buffer *voutbuf = vb2_to_omap_vout_buffer(vb);
968012e3ca3SMauro Carvalho Chehab 	dma_addr_t buf_phy_addr = vb2_dma_contig_plane_dma_addr(vb, 0);
969012e3ca3SMauro Carvalho Chehab 
970012e3ca3SMauro Carvalho Chehab 	if (vb2_plane_size(vb, 0) < vout->pix.sizeimage) {
971012e3ca3SMauro Carvalho Chehab 		v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev,
972012e3ca3SMauro Carvalho Chehab 			 "%s data will not fit into plane (%lu < %u)\n",
973012e3ca3SMauro Carvalho Chehab 			__func__, vb2_plane_size(vb, 0), vout->pix.sizeimage);
974012e3ca3SMauro Carvalho Chehab 		return -EINVAL;
975012e3ca3SMauro Carvalho Chehab 	}
976012e3ca3SMauro Carvalho Chehab 
977012e3ca3SMauro Carvalho Chehab 	vb2_set_plane_payload(vb, 0, vout->pix.sizeimage);
978012e3ca3SMauro Carvalho Chehab 	voutbuf->vbuf.field = V4L2_FIELD_NONE;
979012e3ca3SMauro Carvalho Chehab 
980012e3ca3SMauro Carvalho Chehab 	vout->queued_buf_addr[vb->index] = buf_phy_addr;
981012e3ca3SMauro Carvalho Chehab 	if (ovid->rotation_type == VOUT_ROT_VRFB)
982012e3ca3SMauro Carvalho Chehab 		return omap_vout_prepare_vrfb(vout, vb);
983012e3ca3SMauro Carvalho Chehab 	return 0;
984012e3ca3SMauro Carvalho Chehab }
985012e3ca3SMauro Carvalho Chehab 
omap_vout_vb2_queue(struct vb2_buffer * vb)986012e3ca3SMauro Carvalho Chehab static void omap_vout_vb2_queue(struct vb2_buffer *vb)
987012e3ca3SMauro Carvalho Chehab {
988012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = vb2_get_drv_priv(vb->vb2_queue);
989012e3ca3SMauro Carvalho Chehab 	struct omap_vout_buffer *voutbuf = vb2_to_omap_vout_buffer(vb);
990012e3ca3SMauro Carvalho Chehab 
991012e3ca3SMauro Carvalho Chehab 	list_add_tail(&voutbuf->queue, &vout->dma_queue);
992012e3ca3SMauro Carvalho Chehab }
993012e3ca3SMauro Carvalho Chehab 
omap_vout_vb2_start_streaming(struct vb2_queue * vq,unsigned int count)994012e3ca3SMauro Carvalho Chehab static int omap_vout_vb2_start_streaming(struct vb2_queue *vq, unsigned int count)
995012e3ca3SMauro Carvalho Chehab {
996012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = vb2_get_drv_priv(vq);
997012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid = &vout->vid_info;
998012e3ca3SMauro Carvalho Chehab 	struct omap_vout_buffer *buf, *tmp;
999012e3ca3SMauro Carvalho Chehab 	dma_addr_t addr = 0;
1000012e3ca3SMauro Carvalho Chehab 	u32 mask = 0;
1001012e3ca3SMauro Carvalho Chehab 	int ret, j;
1002012e3ca3SMauro Carvalho Chehab 
1003012e3ca3SMauro Carvalho Chehab 	/* Get the next frame from the buffer queue */
1004012e3ca3SMauro Carvalho Chehab 	vout->next_frm = vout->cur_frm = list_entry(vout->dma_queue.next,
1005012e3ca3SMauro Carvalho Chehab 			struct omap_vout_buffer, queue);
1006012e3ca3SMauro Carvalho Chehab 	/* Remove buffer from the buffer queue */
1007012e3ca3SMauro Carvalho Chehab 	list_del(&vout->cur_frm->queue);
1008012e3ca3SMauro Carvalho Chehab 	/* Initialize field_id and started member */
1009012e3ca3SMauro Carvalho Chehab 	vout->field_id = 0;
1010012e3ca3SMauro Carvalho Chehab 	vout->first_int = 1;
1011012e3ca3SMauro Carvalho Chehab 	vout->sequence = 0;
1012012e3ca3SMauro Carvalho Chehab 
1013012e3ca3SMauro Carvalho Chehab 	if (omap_vout_calculate_offset(vout)) {
1014012e3ca3SMauro Carvalho Chehab 		ret = -EINVAL;
1015012e3ca3SMauro Carvalho Chehab 		goto out;
1016012e3ca3SMauro Carvalho Chehab 	}
1017012e3ca3SMauro Carvalho Chehab 	if (ovid->rotation_type == VOUT_ROT_VRFB)
1018012e3ca3SMauro Carvalho Chehab 		if (omap_vout_vrfb_buffer_setup(vout, &count, 0)) {
1019012e3ca3SMauro Carvalho Chehab 			ret = -ENOMEM;
1020012e3ca3SMauro Carvalho Chehab 			goto out;
1021012e3ca3SMauro Carvalho Chehab 		}
1022012e3ca3SMauro Carvalho Chehab 
1023012e3ca3SMauro Carvalho Chehab 	addr = vout->queued_buf_addr[vout->cur_frm->vbuf.vb2_buf.index]
1024012e3ca3SMauro Carvalho Chehab 		+ vout->cropped_offset;
1025012e3ca3SMauro Carvalho Chehab 
1026012e3ca3SMauro Carvalho Chehab 	mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD
1027012e3ca3SMauro Carvalho Chehab 		| DISPC_IRQ_VSYNC2;
1028012e3ca3SMauro Carvalho Chehab 
1029012e3ca3SMauro Carvalho Chehab 	/* First save the configuration in overlay structure */
1030012e3ca3SMauro Carvalho Chehab 	ret = omapvid_init(vout, addr);
1031012e3ca3SMauro Carvalho Chehab 	if (ret) {
1032012e3ca3SMauro Carvalho Chehab 		v4l2_err(&vout->vid_dev->v4l2_dev,
1033012e3ca3SMauro Carvalho Chehab 				"failed to set overlay info\n");
1034012e3ca3SMauro Carvalho Chehab 		goto streamon_err1;
1035012e3ca3SMauro Carvalho Chehab 	}
1036012e3ca3SMauro Carvalho Chehab 
1037012e3ca3SMauro Carvalho Chehab 	omap_dispc_register_isr(omap_vout_isr, vout, mask);
1038012e3ca3SMauro Carvalho Chehab 
1039012e3ca3SMauro Carvalho Chehab 	/* Enable the pipeline and set the Go bit */
1040012e3ca3SMauro Carvalho Chehab 	ret = omapvid_apply_changes(vout);
1041012e3ca3SMauro Carvalho Chehab 	if (ret)
1042012e3ca3SMauro Carvalho Chehab 		v4l2_err(&vout->vid_dev->v4l2_dev, "failed to change mode\n");
1043012e3ca3SMauro Carvalho Chehab 
1044012e3ca3SMauro Carvalho Chehab 	for (j = 0; j < ovid->num_overlays; j++) {
1045012e3ca3SMauro Carvalho Chehab 		struct omap_overlay *ovl = ovid->overlays[j];
1046012e3ca3SMauro Carvalho Chehab 		struct omap_dss_device *dssdev = ovl->get_device(ovl);
1047012e3ca3SMauro Carvalho Chehab 
1048012e3ca3SMauro Carvalho Chehab 		if (dssdev) {
1049012e3ca3SMauro Carvalho Chehab 			ret = ovl->enable(ovl);
1050012e3ca3SMauro Carvalho Chehab 			if (ret)
1051012e3ca3SMauro Carvalho Chehab 				goto streamon_err1;
1052012e3ca3SMauro Carvalho Chehab 		}
1053012e3ca3SMauro Carvalho Chehab 	}
1054012e3ca3SMauro Carvalho Chehab 	return 0;
1055012e3ca3SMauro Carvalho Chehab 
1056012e3ca3SMauro Carvalho Chehab streamon_err1:
1057012e3ca3SMauro Carvalho Chehab 	mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD
1058012e3ca3SMauro Carvalho Chehab 		| DISPC_IRQ_VSYNC2;
1059012e3ca3SMauro Carvalho Chehab 
1060012e3ca3SMauro Carvalho Chehab 	omap_dispc_unregister_isr(omap_vout_isr, vout, mask);
1061012e3ca3SMauro Carvalho Chehab 
1062012e3ca3SMauro Carvalho Chehab 	for (j = 0; j < ovid->num_overlays; j++) {
1063012e3ca3SMauro Carvalho Chehab 		struct omap_overlay *ovl = ovid->overlays[j];
1064012e3ca3SMauro Carvalho Chehab 		struct omap_dss_device *dssdev = ovl->get_device(ovl);
1065012e3ca3SMauro Carvalho Chehab 
1066012e3ca3SMauro Carvalho Chehab 		if (dssdev)
1067012e3ca3SMauro Carvalho Chehab 			ovl->disable(ovl);
1068012e3ca3SMauro Carvalho Chehab 	}
1069012e3ca3SMauro Carvalho Chehab 	/* Turn of the pipeline */
1070012e3ca3SMauro Carvalho Chehab 	if (omapvid_apply_changes(vout))
1071012e3ca3SMauro Carvalho Chehab 		v4l2_err(&vout->vid_dev->v4l2_dev,
1072012e3ca3SMauro Carvalho Chehab 			 "failed to change mode in streamoff\n");
1073012e3ca3SMauro Carvalho Chehab 
1074012e3ca3SMauro Carvalho Chehab out:
1075012e3ca3SMauro Carvalho Chehab 	vb2_buffer_done(&vout->cur_frm->vbuf.vb2_buf, VB2_BUF_STATE_QUEUED);
1076012e3ca3SMauro Carvalho Chehab 	list_for_each_entry_safe(buf, tmp, &vout->dma_queue, queue) {
1077012e3ca3SMauro Carvalho Chehab 		list_del(&buf->queue);
1078012e3ca3SMauro Carvalho Chehab 		vb2_buffer_done(&buf->vbuf.vb2_buf, VB2_BUF_STATE_QUEUED);
1079012e3ca3SMauro Carvalho Chehab 	}
1080012e3ca3SMauro Carvalho Chehab 	return ret;
1081012e3ca3SMauro Carvalho Chehab }
1082012e3ca3SMauro Carvalho Chehab 
omap_vout_vb2_stop_streaming(struct vb2_queue * vq)1083012e3ca3SMauro Carvalho Chehab static void omap_vout_vb2_stop_streaming(struct vb2_queue *vq)
1084012e3ca3SMauro Carvalho Chehab {
1085012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = vb2_get_drv_priv(vq);
1086012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid = &vout->vid_info;
1087012e3ca3SMauro Carvalho Chehab 	struct omap_vout_buffer *buf, *tmp;
1088012e3ca3SMauro Carvalho Chehab 	u32 mask = 0;
1089012e3ca3SMauro Carvalho Chehab 	int j;
1090012e3ca3SMauro Carvalho Chehab 
1091012e3ca3SMauro Carvalho Chehab 	mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD
1092012e3ca3SMauro Carvalho Chehab 		| DISPC_IRQ_VSYNC2;
1093012e3ca3SMauro Carvalho Chehab 
1094012e3ca3SMauro Carvalho Chehab 	omap_dispc_unregister_isr(omap_vout_isr, vout, mask);
1095012e3ca3SMauro Carvalho Chehab 
1096012e3ca3SMauro Carvalho Chehab 	for (j = 0; j < ovid->num_overlays; j++) {
1097012e3ca3SMauro Carvalho Chehab 		struct omap_overlay *ovl = ovid->overlays[j];
1098012e3ca3SMauro Carvalho Chehab 		struct omap_dss_device *dssdev = ovl->get_device(ovl);
1099012e3ca3SMauro Carvalho Chehab 
1100012e3ca3SMauro Carvalho Chehab 		if (dssdev)
1101012e3ca3SMauro Carvalho Chehab 			ovl->disable(ovl);
1102012e3ca3SMauro Carvalho Chehab 	}
1103012e3ca3SMauro Carvalho Chehab 	/* Turn of the pipeline */
1104012e3ca3SMauro Carvalho Chehab 	if (omapvid_apply_changes(vout))
1105012e3ca3SMauro Carvalho Chehab 		v4l2_err(&vout->vid_dev->v4l2_dev,
1106012e3ca3SMauro Carvalho Chehab 			 "failed to change mode in streamoff\n");
1107012e3ca3SMauro Carvalho Chehab 
1108012e3ca3SMauro Carvalho Chehab 	if (vout->next_frm != vout->cur_frm)
1109012e3ca3SMauro Carvalho Chehab 		vb2_buffer_done(&vout->next_frm->vbuf.vb2_buf, VB2_BUF_STATE_ERROR);
1110012e3ca3SMauro Carvalho Chehab 	vb2_buffer_done(&vout->cur_frm->vbuf.vb2_buf, VB2_BUF_STATE_ERROR);
1111012e3ca3SMauro Carvalho Chehab 	list_for_each_entry_safe(buf, tmp, &vout->dma_queue, queue) {
1112012e3ca3SMauro Carvalho Chehab 		list_del(&buf->queue);
1113012e3ca3SMauro Carvalho Chehab 		vb2_buffer_done(&buf->vbuf.vb2_buf, VB2_BUF_STATE_ERROR);
1114012e3ca3SMauro Carvalho Chehab 	}
1115012e3ca3SMauro Carvalho Chehab }
1116012e3ca3SMauro Carvalho Chehab 
vidioc_s_fbuf(struct file * file,void * fh,const struct v4l2_framebuffer * a)1117012e3ca3SMauro Carvalho Chehab static int vidioc_s_fbuf(struct file *file, void *fh,
1118012e3ca3SMauro Carvalho Chehab 				const struct v4l2_framebuffer *a)
1119012e3ca3SMauro Carvalho Chehab {
1120012e3ca3SMauro Carvalho Chehab 	int enable = 0;
1121012e3ca3SMauro Carvalho Chehab 	struct omap_overlay *ovl;
1122012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid;
1123012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = video_drvdata(file);
1124012e3ca3SMauro Carvalho Chehab 	struct omap_overlay_manager_info info;
1125012e3ca3SMauro Carvalho Chehab 	enum omap_dss_trans_key_type key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
1126012e3ca3SMauro Carvalho Chehab 
1127012e3ca3SMauro Carvalho Chehab 	ovid = &vout->vid_info;
1128012e3ca3SMauro Carvalho Chehab 	ovl = ovid->overlays[0];
1129012e3ca3SMauro Carvalho Chehab 
1130012e3ca3SMauro Carvalho Chehab 	/* OMAP DSS doesn't support Source and Destination color
1131012e3ca3SMauro Carvalho Chehab 	   key together */
1132012e3ca3SMauro Carvalho Chehab 	if ((a->flags & V4L2_FBUF_FLAG_SRC_CHROMAKEY) &&
1133012e3ca3SMauro Carvalho Chehab 			(a->flags & V4L2_FBUF_FLAG_CHROMAKEY))
1134012e3ca3SMauro Carvalho Chehab 		return -EINVAL;
1135012e3ca3SMauro Carvalho Chehab 	/* OMAP DSS Doesn't support the Destination color key
1136012e3ca3SMauro Carvalho Chehab 	   and alpha blending together */
1137012e3ca3SMauro Carvalho Chehab 	if ((a->flags & V4L2_FBUF_FLAG_CHROMAKEY) &&
1138012e3ca3SMauro Carvalho Chehab 			(a->flags & V4L2_FBUF_FLAG_LOCAL_ALPHA))
1139012e3ca3SMauro Carvalho Chehab 		return -EINVAL;
1140012e3ca3SMauro Carvalho Chehab 
1141012e3ca3SMauro Carvalho Chehab 	if ((a->flags & V4L2_FBUF_FLAG_SRC_CHROMAKEY)) {
1142012e3ca3SMauro Carvalho Chehab 		vout->fbuf.flags |= V4L2_FBUF_FLAG_SRC_CHROMAKEY;
1143012e3ca3SMauro Carvalho Chehab 		key_type =  OMAP_DSS_COLOR_KEY_VID_SRC;
1144012e3ca3SMauro Carvalho Chehab 	} else
1145012e3ca3SMauro Carvalho Chehab 		vout->fbuf.flags &= ~V4L2_FBUF_FLAG_SRC_CHROMAKEY;
1146012e3ca3SMauro Carvalho Chehab 
1147012e3ca3SMauro Carvalho Chehab 	if ((a->flags & V4L2_FBUF_FLAG_CHROMAKEY)) {
1148012e3ca3SMauro Carvalho Chehab 		vout->fbuf.flags |= V4L2_FBUF_FLAG_CHROMAKEY;
1149012e3ca3SMauro Carvalho Chehab 		key_type =  OMAP_DSS_COLOR_KEY_GFX_DST;
1150012e3ca3SMauro Carvalho Chehab 	} else
1151012e3ca3SMauro Carvalho Chehab 		vout->fbuf.flags &=  ~V4L2_FBUF_FLAG_CHROMAKEY;
1152012e3ca3SMauro Carvalho Chehab 
1153012e3ca3SMauro Carvalho Chehab 	if (a->flags & (V4L2_FBUF_FLAG_CHROMAKEY |
1154012e3ca3SMauro Carvalho Chehab 				V4L2_FBUF_FLAG_SRC_CHROMAKEY))
1155012e3ca3SMauro Carvalho Chehab 		enable = 1;
1156012e3ca3SMauro Carvalho Chehab 	else
1157012e3ca3SMauro Carvalho Chehab 		enable = 0;
1158012e3ca3SMauro Carvalho Chehab 	if (ovl->manager && ovl->manager->get_manager_info &&
1159012e3ca3SMauro Carvalho Chehab 			ovl->manager->set_manager_info) {
1160012e3ca3SMauro Carvalho Chehab 
1161012e3ca3SMauro Carvalho Chehab 		ovl->manager->get_manager_info(ovl->manager, &info);
1162012e3ca3SMauro Carvalho Chehab 		info.trans_enabled = enable;
1163012e3ca3SMauro Carvalho Chehab 		info.trans_key_type = key_type;
1164012e3ca3SMauro Carvalho Chehab 		info.trans_key = vout->win.chromakey;
1165012e3ca3SMauro Carvalho Chehab 
1166012e3ca3SMauro Carvalho Chehab 		if (ovl->manager->set_manager_info(ovl->manager, &info))
1167012e3ca3SMauro Carvalho Chehab 			return -EINVAL;
1168012e3ca3SMauro Carvalho Chehab 	}
1169012e3ca3SMauro Carvalho Chehab 	if (a->flags & V4L2_FBUF_FLAG_LOCAL_ALPHA) {
1170012e3ca3SMauro Carvalho Chehab 		vout->fbuf.flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA;
1171012e3ca3SMauro Carvalho Chehab 		enable = 1;
1172012e3ca3SMauro Carvalho Chehab 	} else {
1173012e3ca3SMauro Carvalho Chehab 		vout->fbuf.flags &= ~V4L2_FBUF_FLAG_LOCAL_ALPHA;
1174012e3ca3SMauro Carvalho Chehab 		enable = 0;
1175012e3ca3SMauro Carvalho Chehab 	}
1176012e3ca3SMauro Carvalho Chehab 	if (ovl->manager && ovl->manager->get_manager_info &&
1177012e3ca3SMauro Carvalho Chehab 			ovl->manager->set_manager_info) {
1178012e3ca3SMauro Carvalho Chehab 		ovl->manager->get_manager_info(ovl->manager, &info);
1179012e3ca3SMauro Carvalho Chehab 		/* enable this only if there is no zorder cap */
1180012e3ca3SMauro Carvalho Chehab 		if ((ovl->caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
1181012e3ca3SMauro Carvalho Chehab 			info.partial_alpha_enabled = enable;
1182012e3ca3SMauro Carvalho Chehab 		if (ovl->manager->set_manager_info(ovl->manager, &info))
1183012e3ca3SMauro Carvalho Chehab 			return -EINVAL;
1184012e3ca3SMauro Carvalho Chehab 	}
1185012e3ca3SMauro Carvalho Chehab 
1186012e3ca3SMauro Carvalho Chehab 	return 0;
1187012e3ca3SMauro Carvalho Chehab }
1188012e3ca3SMauro Carvalho Chehab 
vidioc_g_fbuf(struct file * file,void * fh,struct v4l2_framebuffer * a)1189012e3ca3SMauro Carvalho Chehab static int vidioc_g_fbuf(struct file *file, void *fh,
1190012e3ca3SMauro Carvalho Chehab 		struct v4l2_framebuffer *a)
1191012e3ca3SMauro Carvalho Chehab {
1192012e3ca3SMauro Carvalho Chehab 	struct omap_overlay *ovl;
1193012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid;
1194012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout = video_drvdata(file);
1195012e3ca3SMauro Carvalho Chehab 	struct omap_overlay_manager_info info;
1196012e3ca3SMauro Carvalho Chehab 	struct omap_video_timings *timing;
1197012e3ca3SMauro Carvalho Chehab 	struct omap_dss_device *dssdev;
1198012e3ca3SMauro Carvalho Chehab 
1199012e3ca3SMauro Carvalho Chehab 	ovid = &vout->vid_info;
1200012e3ca3SMauro Carvalho Chehab 	ovl = ovid->overlays[0];
1201012e3ca3SMauro Carvalho Chehab 	/* get the display device attached to the overlay */
1202012e3ca3SMauro Carvalho Chehab 	dssdev = ovl->get_device(ovl);
1203012e3ca3SMauro Carvalho Chehab 
1204012e3ca3SMauro Carvalho Chehab 	if (!dssdev)
1205012e3ca3SMauro Carvalho Chehab 		return -EINVAL;
1206012e3ca3SMauro Carvalho Chehab 
1207012e3ca3SMauro Carvalho Chehab 	timing = &dssdev->panel.timings;
1208012e3ca3SMauro Carvalho Chehab 
1209012e3ca3SMauro Carvalho Chehab 	vout->fbuf.fmt.height = timing->y_res;
1210012e3ca3SMauro Carvalho Chehab 	vout->fbuf.fmt.width = timing->x_res;
1211012e3ca3SMauro Carvalho Chehab 	a->fmt.field = V4L2_FIELD_NONE;
1212012e3ca3SMauro Carvalho Chehab 	a->fmt.colorspace = V4L2_COLORSPACE_SRGB;
1213012e3ca3SMauro Carvalho Chehab 	a->fmt.pixelformat = V4L2_PIX_FMT_RGBA32;
1214012e3ca3SMauro Carvalho Chehab 	a->fmt.height = vout->fbuf.fmt.height;
1215012e3ca3SMauro Carvalho Chehab 	a->fmt.width = vout->fbuf.fmt.width;
1216012e3ca3SMauro Carvalho Chehab 	a->fmt.bytesperline = vout->fbuf.fmt.width * 4;
1217012e3ca3SMauro Carvalho Chehab 	a->fmt.sizeimage = a->fmt.height * a->fmt.bytesperline;
1218012e3ca3SMauro Carvalho Chehab 	a->base = vout->fbuf.base;
1219012e3ca3SMauro Carvalho Chehab 
1220012e3ca3SMauro Carvalho Chehab 	a->flags = vout->fbuf.flags;
1221012e3ca3SMauro Carvalho Chehab 	a->capability = vout->fbuf.capability;
1222012e3ca3SMauro Carvalho Chehab 	a->flags &= ~(V4L2_FBUF_FLAG_SRC_CHROMAKEY | V4L2_FBUF_FLAG_CHROMAKEY |
1223012e3ca3SMauro Carvalho Chehab 		      V4L2_FBUF_FLAG_LOCAL_ALPHA);
1224012e3ca3SMauro Carvalho Chehab 
1225012e3ca3SMauro Carvalho Chehab 	if (ovl->manager && ovl->manager->get_manager_info) {
1226012e3ca3SMauro Carvalho Chehab 		ovl->manager->get_manager_info(ovl->manager, &info);
1227012e3ca3SMauro Carvalho Chehab 		if (info.trans_key_type == OMAP_DSS_COLOR_KEY_VID_SRC)
1228012e3ca3SMauro Carvalho Chehab 			a->flags |= V4L2_FBUF_FLAG_SRC_CHROMAKEY;
1229012e3ca3SMauro Carvalho Chehab 		if (info.trans_key_type == OMAP_DSS_COLOR_KEY_GFX_DST)
1230012e3ca3SMauro Carvalho Chehab 			a->flags |= V4L2_FBUF_FLAG_CHROMAKEY;
1231012e3ca3SMauro Carvalho Chehab 		if (info.partial_alpha_enabled)
1232012e3ca3SMauro Carvalho Chehab 			a->flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA;
1233012e3ca3SMauro Carvalho Chehab 	}
1234012e3ca3SMauro Carvalho Chehab 
1235012e3ca3SMauro Carvalho Chehab 	return 0;
1236012e3ca3SMauro Carvalho Chehab }
1237012e3ca3SMauro Carvalho Chehab 
vidioc_enum_output(struct file * file,void * priv_fh,struct v4l2_output * out)1238012e3ca3SMauro Carvalho Chehab static int vidioc_enum_output(struct file *file, void *priv_fh,
1239012e3ca3SMauro Carvalho Chehab 			      struct v4l2_output *out)
1240012e3ca3SMauro Carvalho Chehab {
1241012e3ca3SMauro Carvalho Chehab 	if (out->index)
1242012e3ca3SMauro Carvalho Chehab 		return -EINVAL;
1243012e3ca3SMauro Carvalho Chehab 	snprintf(out->name, sizeof(out->name), "Overlay");
1244012e3ca3SMauro Carvalho Chehab 	out->type = V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY;
1245012e3ca3SMauro Carvalho Chehab 	return 0;
1246012e3ca3SMauro Carvalho Chehab }
1247012e3ca3SMauro Carvalho Chehab 
vidioc_g_output(struct file * file,void * priv_fh,unsigned int * i)1248012e3ca3SMauro Carvalho Chehab static int vidioc_g_output(struct file *file, void *priv_fh, unsigned int *i)
1249012e3ca3SMauro Carvalho Chehab {
1250012e3ca3SMauro Carvalho Chehab 	*i = 0;
1251012e3ca3SMauro Carvalho Chehab 	return 0;
1252012e3ca3SMauro Carvalho Chehab }
1253012e3ca3SMauro Carvalho Chehab 
vidioc_s_output(struct file * file,void * priv_fh,unsigned int i)1254012e3ca3SMauro Carvalho Chehab static int vidioc_s_output(struct file *file, void *priv_fh, unsigned int i)
1255012e3ca3SMauro Carvalho Chehab {
1256012e3ca3SMauro Carvalho Chehab 	return i ? -EINVAL : 0;
1257012e3ca3SMauro Carvalho Chehab }
1258012e3ca3SMauro Carvalho Chehab 
1259012e3ca3SMauro Carvalho Chehab static const struct v4l2_ioctl_ops vout_ioctl_ops = {
1260012e3ca3SMauro Carvalho Chehab 	.vidioc_querycap			= vidioc_querycap,
1261012e3ca3SMauro Carvalho Chehab 	.vidioc_enum_fmt_vid_out		= vidioc_enum_fmt_vid_out,
1262012e3ca3SMauro Carvalho Chehab 	.vidioc_g_fmt_vid_out			= vidioc_g_fmt_vid_out,
1263012e3ca3SMauro Carvalho Chehab 	.vidioc_try_fmt_vid_out			= vidioc_try_fmt_vid_out,
1264012e3ca3SMauro Carvalho Chehab 	.vidioc_s_fmt_vid_out			= vidioc_s_fmt_vid_out,
1265012e3ca3SMauro Carvalho Chehab 	.vidioc_s_fbuf				= vidioc_s_fbuf,
1266012e3ca3SMauro Carvalho Chehab 	.vidioc_g_fbuf				= vidioc_g_fbuf,
1267012e3ca3SMauro Carvalho Chehab 	.vidioc_try_fmt_vid_out_overlay		= vidioc_try_fmt_vid_overlay,
1268012e3ca3SMauro Carvalho Chehab 	.vidioc_s_fmt_vid_out_overlay		= vidioc_s_fmt_vid_overlay,
1269012e3ca3SMauro Carvalho Chehab 	.vidioc_g_fmt_vid_out_overlay		= vidioc_g_fmt_vid_overlay,
1270012e3ca3SMauro Carvalho Chehab 	.vidioc_g_selection			= vidioc_g_selection,
1271012e3ca3SMauro Carvalho Chehab 	.vidioc_s_selection			= vidioc_s_selection,
1272012e3ca3SMauro Carvalho Chehab 	.vidioc_enum_output			= vidioc_enum_output,
1273012e3ca3SMauro Carvalho Chehab 	.vidioc_g_output			= vidioc_g_output,
1274012e3ca3SMauro Carvalho Chehab 	.vidioc_s_output			= vidioc_s_output,
1275012e3ca3SMauro Carvalho Chehab 	.vidioc_reqbufs				= vb2_ioctl_reqbufs,
1276012e3ca3SMauro Carvalho Chehab 	.vidioc_create_bufs			= vb2_ioctl_create_bufs,
1277012e3ca3SMauro Carvalho Chehab 	.vidioc_querybuf			= vb2_ioctl_querybuf,
1278012e3ca3SMauro Carvalho Chehab 	.vidioc_qbuf				= vb2_ioctl_qbuf,
1279012e3ca3SMauro Carvalho Chehab 	.vidioc_dqbuf				= vb2_ioctl_dqbuf,
1280012e3ca3SMauro Carvalho Chehab 	.vidioc_expbuf				= vb2_ioctl_expbuf,
1281012e3ca3SMauro Carvalho Chehab 	.vidioc_streamon			= vb2_ioctl_streamon,
1282012e3ca3SMauro Carvalho Chehab 	.vidioc_streamoff			= vb2_ioctl_streamoff,
1283012e3ca3SMauro Carvalho Chehab 	.vidioc_subscribe_event			= v4l2_ctrl_subscribe_event,
1284012e3ca3SMauro Carvalho Chehab 	.vidioc_unsubscribe_event		= v4l2_event_unsubscribe,
1285012e3ca3SMauro Carvalho Chehab };
1286012e3ca3SMauro Carvalho Chehab 
1287012e3ca3SMauro Carvalho Chehab static const struct v4l2_file_operations omap_vout_fops = {
1288012e3ca3SMauro Carvalho Chehab 	.owner		= THIS_MODULE,
1289012e3ca3SMauro Carvalho Chehab 	.unlocked_ioctl	= video_ioctl2,
1290012e3ca3SMauro Carvalho Chehab 	.poll		= vb2_fop_poll,
1291012e3ca3SMauro Carvalho Chehab 	.mmap		= vb2_fop_mmap,
1292012e3ca3SMauro Carvalho Chehab 	.open		= v4l2_fh_open,
1293012e3ca3SMauro Carvalho Chehab 	.release	= vb2_fop_release,
1294012e3ca3SMauro Carvalho Chehab };
1295012e3ca3SMauro Carvalho Chehab 
1296012e3ca3SMauro Carvalho Chehab static const struct vb2_ops omap_vout_vb2_ops = {
1297012e3ca3SMauro Carvalho Chehab 	.queue_setup		= omap_vout_vb2_queue_setup,
1298012e3ca3SMauro Carvalho Chehab 	.buf_queue		= omap_vout_vb2_queue,
1299012e3ca3SMauro Carvalho Chehab 	.buf_prepare		= omap_vout_vb2_prepare,
1300012e3ca3SMauro Carvalho Chehab 	.start_streaming	= omap_vout_vb2_start_streaming,
1301012e3ca3SMauro Carvalho Chehab 	.stop_streaming		= omap_vout_vb2_stop_streaming,
1302012e3ca3SMauro Carvalho Chehab 	.wait_prepare		= vb2_ops_wait_prepare,
1303012e3ca3SMauro Carvalho Chehab 	.wait_finish		= vb2_ops_wait_finish,
1304012e3ca3SMauro Carvalho Chehab };
1305012e3ca3SMauro Carvalho Chehab 
1306012e3ca3SMauro Carvalho Chehab /* Init functions used during driver initialization */
1307012e3ca3SMauro Carvalho Chehab /* Initial setup of video_data */
omap_vout_setup_video_data(struct omap_vout_device * vout)1308012e3ca3SMauro Carvalho Chehab static int __init omap_vout_setup_video_data(struct omap_vout_device *vout)
1309012e3ca3SMauro Carvalho Chehab {
1310012e3ca3SMauro Carvalho Chehab 	struct video_device *vfd;
1311012e3ca3SMauro Carvalho Chehab 	struct v4l2_pix_format *pix;
1312012e3ca3SMauro Carvalho Chehab 	struct omap_overlay *ovl = vout->vid_info.overlays[0];
1313012e3ca3SMauro Carvalho Chehab 	struct omap_dss_device *display = ovl->get_device(ovl);
1314012e3ca3SMauro Carvalho Chehab 	struct v4l2_ctrl_handler *hdl;
1315012e3ca3SMauro Carvalho Chehab 	struct vb2_queue *vq;
1316012e3ca3SMauro Carvalho Chehab 	int ret;
1317012e3ca3SMauro Carvalho Chehab 
1318012e3ca3SMauro Carvalho Chehab 	/* set the default pix */
1319012e3ca3SMauro Carvalho Chehab 	pix = &vout->pix;
1320012e3ca3SMauro Carvalho Chehab 
1321012e3ca3SMauro Carvalho Chehab 	/* Set the default picture of QVGA  */
1322012e3ca3SMauro Carvalho Chehab 	pix->width = QQVGA_WIDTH;
1323012e3ca3SMauro Carvalho Chehab 	pix->height = QQVGA_HEIGHT;
1324012e3ca3SMauro Carvalho Chehab 
1325012e3ca3SMauro Carvalho Chehab 	/* Default pixel format is RGB 5-6-5 */
1326012e3ca3SMauro Carvalho Chehab 	pix->pixelformat = V4L2_PIX_FMT_RGB565;
1327012e3ca3SMauro Carvalho Chehab 	pix->field = V4L2_FIELD_NONE;
1328012e3ca3SMauro Carvalho Chehab 	pix->bytesperline = pix->width * 2;
1329012e3ca3SMauro Carvalho Chehab 	pix->sizeimage = pix->bytesperline * pix->height;
1330012e3ca3SMauro Carvalho Chehab 	pix->colorspace = V4L2_COLORSPACE_SRGB;
1331012e3ca3SMauro Carvalho Chehab 
1332012e3ca3SMauro Carvalho Chehab 	vout->bpp = RGB565_BPP;
1333012e3ca3SMauro Carvalho Chehab 	vout->fbuf.fmt.width  =  display->panel.timings.x_res;
1334012e3ca3SMauro Carvalho Chehab 	vout->fbuf.fmt.height =  display->panel.timings.y_res;
1335012e3ca3SMauro Carvalho Chehab 	vout->cropped_offset = 0;
1336012e3ca3SMauro Carvalho Chehab 
1337012e3ca3SMauro Carvalho Chehab 	/* Set the data structures for the overlay parameters*/
1338012e3ca3SMauro Carvalho Chehab 	vout->fbuf.flags = V4L2_FBUF_FLAG_OVERLAY;
1339012e3ca3SMauro Carvalho Chehab 	vout->fbuf.capability = V4L2_FBUF_CAP_LOCAL_ALPHA |
1340012e3ca3SMauro Carvalho Chehab 		V4L2_FBUF_CAP_SRC_CHROMAKEY | V4L2_FBUF_CAP_CHROMAKEY |
1341012e3ca3SMauro Carvalho Chehab 		V4L2_FBUF_CAP_EXTERNOVERLAY;
1342012e3ca3SMauro Carvalho Chehab 	if (ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) {
1343012e3ca3SMauro Carvalho Chehab 		vout->win.global_alpha = 255;
1344012e3ca3SMauro Carvalho Chehab 		vout->fbuf.capability |= V4L2_FBUF_CAP_GLOBAL_ALPHA;
1345012e3ca3SMauro Carvalho Chehab 		vout->fbuf.flags |= V4L2_FBUF_FLAG_GLOBAL_ALPHA;
1346012e3ca3SMauro Carvalho Chehab 	} else {
1347012e3ca3SMauro Carvalho Chehab 		vout->win.global_alpha = 0;
1348012e3ca3SMauro Carvalho Chehab 	}
1349012e3ca3SMauro Carvalho Chehab 	vout->win.field = V4L2_FIELD_NONE;
1350012e3ca3SMauro Carvalho Chehab 
1351012e3ca3SMauro Carvalho Chehab 	omap_vout_new_format(pix, &vout->fbuf, &vout->crop, &vout->win);
1352012e3ca3SMauro Carvalho Chehab 
1353012e3ca3SMauro Carvalho Chehab 	hdl = &vout->ctrl_handler;
1354012e3ca3SMauro Carvalho Chehab 	v4l2_ctrl_handler_init(hdl, 3);
1355012e3ca3SMauro Carvalho Chehab 	if (vout->vid_info.rotation_type == VOUT_ROT_VRFB) {
1356012e3ca3SMauro Carvalho Chehab 		v4l2_ctrl_new_std(hdl, &omap_vout_ctrl_ops,
1357012e3ca3SMauro Carvalho Chehab 				  V4L2_CID_ROTATE, 0, 270, 90, 0);
1358012e3ca3SMauro Carvalho Chehab 		v4l2_ctrl_new_std(hdl, &omap_vout_ctrl_ops,
1359012e3ca3SMauro Carvalho Chehab 				  V4L2_CID_VFLIP, 0, 1, 1, 0);
1360012e3ca3SMauro Carvalho Chehab 	}
1361012e3ca3SMauro Carvalho Chehab 	v4l2_ctrl_new_std(hdl, &omap_vout_ctrl_ops,
1362012e3ca3SMauro Carvalho Chehab 			  V4L2_CID_BG_COLOR, 0, 0xffffff, 1, 0);
1363012e3ca3SMauro Carvalho Chehab 	if (hdl->error)
1364012e3ca3SMauro Carvalho Chehab 		return hdl->error;
1365012e3ca3SMauro Carvalho Chehab 
1366012e3ca3SMauro Carvalho Chehab 	vout->rotation = 0;
1367012e3ca3SMauro Carvalho Chehab 	vout->mirror = false;
1368012e3ca3SMauro Carvalho Chehab 	INIT_LIST_HEAD(&vout->dma_queue);
1369012e3ca3SMauro Carvalho Chehab 	if (vout->vid_info.rotation_type == VOUT_ROT_VRFB)
1370012e3ca3SMauro Carvalho Chehab 		vout->vrfb_bpp = 2;
1371012e3ca3SMauro Carvalho Chehab 
1372012e3ca3SMauro Carvalho Chehab 	/* initialize the video_device struct */
1373012e3ca3SMauro Carvalho Chehab 	vfd = vout->vfd = video_device_alloc();
1374012e3ca3SMauro Carvalho Chehab 
1375012e3ca3SMauro Carvalho Chehab 	if (!vfd) {
1376012e3ca3SMauro Carvalho Chehab 		printk(KERN_ERR VOUT_NAME
1377012e3ca3SMauro Carvalho Chehab 		       ": could not allocate video device struct\n");
1378012e3ca3SMauro Carvalho Chehab 		v4l2_ctrl_handler_free(hdl);
1379012e3ca3SMauro Carvalho Chehab 		return -ENOMEM;
1380012e3ca3SMauro Carvalho Chehab 	}
1381012e3ca3SMauro Carvalho Chehab 	vfd->ctrl_handler = hdl;
1382012e3ca3SMauro Carvalho Chehab 	vfd->release = video_device_release;
1383012e3ca3SMauro Carvalho Chehab 	vfd->ioctl_ops = &vout_ioctl_ops;
1384012e3ca3SMauro Carvalho Chehab 
1385012e3ca3SMauro Carvalho Chehab 	strscpy(vfd->name, VOUT_NAME, sizeof(vfd->name));
1386012e3ca3SMauro Carvalho Chehab 
1387012e3ca3SMauro Carvalho Chehab 	vfd->fops = &omap_vout_fops;
1388012e3ca3SMauro Carvalho Chehab 	vfd->v4l2_dev = &vout->vid_dev->v4l2_dev;
1389012e3ca3SMauro Carvalho Chehab 	vfd->vfl_dir = VFL_DIR_TX;
1390012e3ca3SMauro Carvalho Chehab 	vfd->minor = -1;
1391012e3ca3SMauro Carvalho Chehab 	vfd->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_OUTPUT |
1392012e3ca3SMauro Carvalho Chehab 			   V4L2_CAP_VIDEO_OUTPUT_OVERLAY;
1393012e3ca3SMauro Carvalho Chehab 	mutex_init(&vout->lock);
1394012e3ca3SMauro Carvalho Chehab 
1395012e3ca3SMauro Carvalho Chehab 	vq = &vout->vq;
1396012e3ca3SMauro Carvalho Chehab 	vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
1397012e3ca3SMauro Carvalho Chehab 	vq->io_modes = VB2_MMAP | VB2_DMABUF;
1398012e3ca3SMauro Carvalho Chehab 	vq->drv_priv = vout;
1399012e3ca3SMauro Carvalho Chehab 	vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1400012e3ca3SMauro Carvalho Chehab 	vq->buf_struct_size = sizeof(struct omap_vout_buffer);
1401012e3ca3SMauro Carvalho Chehab 	vq->dev = vfd->v4l2_dev->dev;
1402012e3ca3SMauro Carvalho Chehab 
1403012e3ca3SMauro Carvalho Chehab 	vq->ops = &omap_vout_vb2_ops;
1404012e3ca3SMauro Carvalho Chehab 	vq->mem_ops = &vb2_dma_contig_memops;
1405012e3ca3SMauro Carvalho Chehab 	vq->lock = &vout->lock;
1406012e3ca3SMauro Carvalho Chehab 	vq->min_buffers_needed = 1;
1407012e3ca3SMauro Carvalho Chehab 	vfd->queue = vq;
1408012e3ca3SMauro Carvalho Chehab 
1409012e3ca3SMauro Carvalho Chehab 	ret = vb2_queue_init(vq);
1410012e3ca3SMauro Carvalho Chehab 	if (ret) {
1411012e3ca3SMauro Carvalho Chehab 		v4l2_ctrl_handler_free(hdl);
1412012e3ca3SMauro Carvalho Chehab 		video_device_release(vfd);
1413012e3ca3SMauro Carvalho Chehab 	}
1414012e3ca3SMauro Carvalho Chehab 	return ret;
1415012e3ca3SMauro Carvalho Chehab }
1416012e3ca3SMauro Carvalho Chehab 
1417012e3ca3SMauro Carvalho Chehab /* Setup video buffers */
omap_vout_setup_video_bufs(struct platform_device * pdev,int vid_num)1418012e3ca3SMauro Carvalho Chehab static int __init omap_vout_setup_video_bufs(struct platform_device *pdev,
1419012e3ca3SMauro Carvalho Chehab 		int vid_num)
1420012e3ca3SMauro Carvalho Chehab {
1421012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid;
1422012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout;
1423012e3ca3SMauro Carvalho Chehab 	struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
1424012e3ca3SMauro Carvalho Chehab 	struct omap2video_device *vid_dev =
1425012e3ca3SMauro Carvalho Chehab 		container_of(v4l2_dev, struct omap2video_device, v4l2_dev);
1426012e3ca3SMauro Carvalho Chehab 	int ret = 0;
1427012e3ca3SMauro Carvalho Chehab 
1428012e3ca3SMauro Carvalho Chehab 	vout = vid_dev->vouts[vid_num];
1429012e3ca3SMauro Carvalho Chehab 	ovid = &vout->vid_info;
1430012e3ca3SMauro Carvalho Chehab 
1431012e3ca3SMauro Carvalho Chehab 	if (ovid->rotation_type == VOUT_ROT_VRFB) {
1432012e3ca3SMauro Carvalho Chehab 		bool static_vrfb_allocation = (vid_num == 0) ?
1433012e3ca3SMauro Carvalho Chehab 			vid1_static_vrfb_alloc : vid2_static_vrfb_alloc;
1434012e3ca3SMauro Carvalho Chehab 		ret = omap_vout_setup_vrfb_bufs(pdev, vid_num,
1435012e3ca3SMauro Carvalho Chehab 				static_vrfb_allocation);
1436012e3ca3SMauro Carvalho Chehab 	}
1437012e3ca3SMauro Carvalho Chehab 	return ret;
1438012e3ca3SMauro Carvalho Chehab }
1439012e3ca3SMauro Carvalho Chehab 
1440012e3ca3SMauro Carvalho Chehab /* Create video out devices */
omap_vout_create_video_devices(struct platform_device * pdev)1441012e3ca3SMauro Carvalho Chehab static int __init omap_vout_create_video_devices(struct platform_device *pdev)
1442012e3ca3SMauro Carvalho Chehab {
1443012e3ca3SMauro Carvalho Chehab 	int ret = 0, k;
1444012e3ca3SMauro Carvalho Chehab 	struct omap_vout_device *vout;
1445012e3ca3SMauro Carvalho Chehab 	struct video_device *vfd = NULL;
1446012e3ca3SMauro Carvalho Chehab 	struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
1447012e3ca3SMauro Carvalho Chehab 	struct omap2video_device *vid_dev = container_of(v4l2_dev,
1448012e3ca3SMauro Carvalho Chehab 			struct omap2video_device, v4l2_dev);
1449012e3ca3SMauro Carvalho Chehab 	struct omap_overlay *ovl = vid_dev->overlays[0];
1450012e3ca3SMauro Carvalho Chehab 	struct omap_overlay_info info;
1451012e3ca3SMauro Carvalho Chehab 
1452012e3ca3SMauro Carvalho Chehab 	ovl->get_overlay_info(ovl, &info);
1453012e3ca3SMauro Carvalho Chehab 
1454012e3ca3SMauro Carvalho Chehab 	for (k = 0; k < pdev->num_resources; k++) {
1455012e3ca3SMauro Carvalho Chehab 
1456012e3ca3SMauro Carvalho Chehab 		vout = kzalloc(sizeof(struct omap_vout_device), GFP_KERNEL);
1457012e3ca3SMauro Carvalho Chehab 		if (!vout) {
1458012e3ca3SMauro Carvalho Chehab 			dev_err(&pdev->dev, ": could not allocate memory\n");
1459012e3ca3SMauro Carvalho Chehab 			return -ENOMEM;
1460012e3ca3SMauro Carvalho Chehab 		}
1461012e3ca3SMauro Carvalho Chehab 
1462012e3ca3SMauro Carvalho Chehab 		vout->vid = k;
1463012e3ca3SMauro Carvalho Chehab 		vid_dev->vouts[k] = vout;
1464012e3ca3SMauro Carvalho Chehab 		vout->vid_dev = vid_dev;
1465012e3ca3SMauro Carvalho Chehab 		/* Select video2 if only 1 overlay is controlled by V4L2 */
1466012e3ca3SMauro Carvalho Chehab 		if (pdev->num_resources == 1)
1467012e3ca3SMauro Carvalho Chehab 			vout->vid_info.overlays[0] = vid_dev->overlays[k + 2];
1468012e3ca3SMauro Carvalho Chehab 		else
1469012e3ca3SMauro Carvalho Chehab 			/* Else select video1 and video2 one by one. */
1470012e3ca3SMauro Carvalho Chehab 			vout->vid_info.overlays[0] = vid_dev->overlays[k + 1];
1471012e3ca3SMauro Carvalho Chehab 		vout->vid_info.num_overlays = 1;
1472012e3ca3SMauro Carvalho Chehab 		vout->vid_info.id = k + 1;
1473012e3ca3SMauro Carvalho Chehab 		spin_lock_init(&vout->vbq_lock);
1474012e3ca3SMauro Carvalho Chehab 		/*
1475012e3ca3SMauro Carvalho Chehab 		 * Set the framebuffer base, this allows applications to find
1476012e3ca3SMauro Carvalho Chehab 		 * the fb corresponding to this overlay.
1477012e3ca3SMauro Carvalho Chehab 		 *
1478012e3ca3SMauro Carvalho Chehab 		 * To be precise: fbuf.base should match smem_start of
1479012e3ca3SMauro Carvalho Chehab 		 * struct fb_fix_screeninfo.
1480012e3ca3SMauro Carvalho Chehab 		 */
1481012e3ca3SMauro Carvalho Chehab 		vout->fbuf.base = (void *)(uintptr_t)info.paddr;
1482012e3ca3SMauro Carvalho Chehab 
1483012e3ca3SMauro Carvalho Chehab 		/* Set VRFB as rotation_type for omap2 and omap3 */
1484012e3ca3SMauro Carvalho Chehab 		if (omap_vout_dss_omap24xx() || omap_vout_dss_omap34xx())
1485012e3ca3SMauro Carvalho Chehab 			vout->vid_info.rotation_type = VOUT_ROT_VRFB;
1486012e3ca3SMauro Carvalho Chehab 
1487012e3ca3SMauro Carvalho Chehab 		/* Setup the default configuration for the video devices
1488012e3ca3SMauro Carvalho Chehab 		 */
1489012e3ca3SMauro Carvalho Chehab 		if (omap_vout_setup_video_data(vout) != 0) {
1490012e3ca3SMauro Carvalho Chehab 			ret = -ENOMEM;
1491012e3ca3SMauro Carvalho Chehab 			goto error;
1492012e3ca3SMauro Carvalho Chehab 		}
1493012e3ca3SMauro Carvalho Chehab 
1494012e3ca3SMauro Carvalho Chehab 		/* Allocate default number of buffers for the video streaming
1495012e3ca3SMauro Carvalho Chehab 		 * and reserve the VRFB space for rotation
1496012e3ca3SMauro Carvalho Chehab 		 */
1497012e3ca3SMauro Carvalho Chehab 		if (omap_vout_setup_video_bufs(pdev, k) != 0) {
1498012e3ca3SMauro Carvalho Chehab 			ret = -ENOMEM;
1499012e3ca3SMauro Carvalho Chehab 			goto error1;
1500012e3ca3SMauro Carvalho Chehab 		}
1501012e3ca3SMauro Carvalho Chehab 
1502012e3ca3SMauro Carvalho Chehab 		/* Register the Video device with V4L2
1503012e3ca3SMauro Carvalho Chehab 		 */
1504012e3ca3SMauro Carvalho Chehab 		vfd = vout->vfd;
1505012e3ca3SMauro Carvalho Chehab 		if (video_register_device(vfd, VFL_TYPE_VIDEO, -1) < 0) {
1506012e3ca3SMauro Carvalho Chehab 			dev_err(&pdev->dev,
1507012e3ca3SMauro Carvalho Chehab 				": Could not register Video for Linux device\n");
1508012e3ca3SMauro Carvalho Chehab 			vfd->minor = -1;
1509012e3ca3SMauro Carvalho Chehab 			ret = -ENODEV;
1510012e3ca3SMauro Carvalho Chehab 			goto error2;
1511012e3ca3SMauro Carvalho Chehab 		}
1512012e3ca3SMauro Carvalho Chehab 		video_set_drvdata(vfd, vout);
1513012e3ca3SMauro Carvalho Chehab 
1514012e3ca3SMauro Carvalho Chehab 		dev_info(&pdev->dev,
1515012e3ca3SMauro Carvalho Chehab 			 ": registered and initialized video device %d\n",
1516012e3ca3SMauro Carvalho Chehab 			 vfd->minor);
1517012e3ca3SMauro Carvalho Chehab 		if (k == (pdev->num_resources - 1))
1518012e3ca3SMauro Carvalho Chehab 			return 0;
1519012e3ca3SMauro Carvalho Chehab 
1520012e3ca3SMauro Carvalho Chehab 		continue;
1521012e3ca3SMauro Carvalho Chehab error2:
1522012e3ca3SMauro Carvalho Chehab 		if (vout->vid_info.rotation_type == VOUT_ROT_VRFB)
1523012e3ca3SMauro Carvalho Chehab 			omap_vout_release_vrfb(vout);
1524012e3ca3SMauro Carvalho Chehab error1:
1525012e3ca3SMauro Carvalho Chehab 		video_device_release(vfd);
1526012e3ca3SMauro Carvalho Chehab error:
1527012e3ca3SMauro Carvalho Chehab 		kfree(vout);
1528012e3ca3SMauro Carvalho Chehab 		return ret;
1529012e3ca3SMauro Carvalho Chehab 	}
1530012e3ca3SMauro Carvalho Chehab 
1531012e3ca3SMauro Carvalho Chehab 	return -ENODEV;
1532012e3ca3SMauro Carvalho Chehab }
1533012e3ca3SMauro Carvalho Chehab /* Driver functions */
omap_vout_cleanup_device(struct omap_vout_device * vout)1534012e3ca3SMauro Carvalho Chehab static void omap_vout_cleanup_device(struct omap_vout_device *vout)
1535012e3ca3SMauro Carvalho Chehab {
1536012e3ca3SMauro Carvalho Chehab 	struct video_device *vfd;
1537012e3ca3SMauro Carvalho Chehab 	struct omapvideo_info *ovid;
1538012e3ca3SMauro Carvalho Chehab 
1539012e3ca3SMauro Carvalho Chehab 	if (!vout)
1540012e3ca3SMauro Carvalho Chehab 		return;
1541012e3ca3SMauro Carvalho Chehab 
1542012e3ca3SMauro Carvalho Chehab 	vfd = vout->vfd;
1543012e3ca3SMauro Carvalho Chehab 	ovid = &vout->vid_info;
1544012e3ca3SMauro Carvalho Chehab 	if (vfd) {
1545012e3ca3SMauro Carvalho Chehab 		if (!video_is_registered(vfd)) {
1546012e3ca3SMauro Carvalho Chehab 			/*
1547012e3ca3SMauro Carvalho Chehab 			 * The device was never registered, so release the
1548012e3ca3SMauro Carvalho Chehab 			 * video_device struct directly.
1549012e3ca3SMauro Carvalho Chehab 			 */
1550012e3ca3SMauro Carvalho Chehab 			video_device_release(vfd);
1551012e3ca3SMauro Carvalho Chehab 		} else {
1552012e3ca3SMauro Carvalho Chehab 			/*
1553012e3ca3SMauro Carvalho Chehab 			 * The unregister function will release the video_device
1554012e3ca3SMauro Carvalho Chehab 			 * struct as well as unregistering it.
1555012e3ca3SMauro Carvalho Chehab 			 */
1556012e3ca3SMauro Carvalho Chehab 			video_unregister_device(vfd);
1557012e3ca3SMauro Carvalho Chehab 		}
1558012e3ca3SMauro Carvalho Chehab 	}
1559012e3ca3SMauro Carvalho Chehab 	v4l2_ctrl_handler_free(&vout->ctrl_handler);
1560012e3ca3SMauro Carvalho Chehab 	if (ovid->rotation_type == VOUT_ROT_VRFB) {
1561012e3ca3SMauro Carvalho Chehab 		omap_vout_release_vrfb(vout);
1562012e3ca3SMauro Carvalho Chehab 		/* Free the VRFB buffer if allocated
1563012e3ca3SMauro Carvalho Chehab 		 * init time
1564012e3ca3SMauro Carvalho Chehab 		 */
1565012e3ca3SMauro Carvalho Chehab 		if (vout->vrfb_static_allocation)
1566012e3ca3SMauro Carvalho Chehab 			omap_vout_free_vrfb_buffers(vout);
1567012e3ca3SMauro Carvalho Chehab 	}
1568012e3ca3SMauro Carvalho Chehab 
1569012e3ca3SMauro Carvalho Chehab 	kfree(vout);
1570012e3ca3SMauro Carvalho Chehab }
1571012e3ca3SMauro Carvalho Chehab 
omap_vout_remove(struct platform_device * pdev)1572*0a44e5f6SUwe Kleine-König static void omap_vout_remove(struct platform_device *pdev)
1573012e3ca3SMauro Carvalho Chehab {
1574012e3ca3SMauro Carvalho Chehab 	int k;
1575012e3ca3SMauro Carvalho Chehab 	struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
1576012e3ca3SMauro Carvalho Chehab 	struct omap2video_device *vid_dev = container_of(v4l2_dev, struct
1577012e3ca3SMauro Carvalho Chehab 			omap2video_device, v4l2_dev);
1578012e3ca3SMauro Carvalho Chehab 
1579012e3ca3SMauro Carvalho Chehab 	v4l2_device_unregister(v4l2_dev);
1580012e3ca3SMauro Carvalho Chehab 	for (k = 0; k < pdev->num_resources; k++)
1581012e3ca3SMauro Carvalho Chehab 		omap_vout_cleanup_device(vid_dev->vouts[k]);
1582012e3ca3SMauro Carvalho Chehab 
1583012e3ca3SMauro Carvalho Chehab 	for (k = 0; k < vid_dev->num_displays; k++) {
1584012e3ca3SMauro Carvalho Chehab 		if (vid_dev->displays[k]->state != OMAP_DSS_DISPLAY_DISABLED)
1585012e3ca3SMauro Carvalho Chehab 			vid_dev->displays[k]->driver->disable(vid_dev->displays[k]);
1586012e3ca3SMauro Carvalho Chehab 
1587012e3ca3SMauro Carvalho Chehab 		omap_dss_put_device(vid_dev->displays[k]);
1588012e3ca3SMauro Carvalho Chehab 	}
1589012e3ca3SMauro Carvalho Chehab 	kfree(vid_dev);
1590012e3ca3SMauro Carvalho Chehab }
1591012e3ca3SMauro Carvalho Chehab 
omap_vout_probe(struct platform_device * pdev)1592012e3ca3SMauro Carvalho Chehab static int __init omap_vout_probe(struct platform_device *pdev)
1593012e3ca3SMauro Carvalho Chehab {
1594012e3ca3SMauro Carvalho Chehab 	int ret = 0, i;
1595012e3ca3SMauro Carvalho Chehab 	struct omap_overlay *ovl;
1596012e3ca3SMauro Carvalho Chehab 	struct omap_dss_device *dssdev = NULL;
1597012e3ca3SMauro Carvalho Chehab 	struct omap_dss_device *def_display;
1598012e3ca3SMauro Carvalho Chehab 	struct omap2video_device *vid_dev = NULL;
1599012e3ca3SMauro Carvalho Chehab 
1600012e3ca3SMauro Carvalho Chehab 	if (omapdss_is_initialized() == false)
1601012e3ca3SMauro Carvalho Chehab 		return -EPROBE_DEFER;
1602012e3ca3SMauro Carvalho Chehab 
1603012e3ca3SMauro Carvalho Chehab 	ret = omapdss_compat_init();
1604012e3ca3SMauro Carvalho Chehab 	if (ret) {
1605012e3ca3SMauro Carvalho Chehab 		dev_err(&pdev->dev, "failed to init dss\n");
1606012e3ca3SMauro Carvalho Chehab 		return ret;
1607012e3ca3SMauro Carvalho Chehab 	}
1608012e3ca3SMauro Carvalho Chehab 
1609012e3ca3SMauro Carvalho Chehab 	if (pdev->num_resources == 0) {
1610012e3ca3SMauro Carvalho Chehab 		dev_err(&pdev->dev, "probed for an unknown device\n");
1611012e3ca3SMauro Carvalho Chehab 		ret = -ENODEV;
1612012e3ca3SMauro Carvalho Chehab 		goto err_dss_init;
1613012e3ca3SMauro Carvalho Chehab 	}
1614012e3ca3SMauro Carvalho Chehab 
1615012e3ca3SMauro Carvalho Chehab 	vid_dev = kzalloc(sizeof(struct omap2video_device), GFP_KERNEL);
1616012e3ca3SMauro Carvalho Chehab 	if (vid_dev == NULL) {
1617012e3ca3SMauro Carvalho Chehab 		ret = -ENOMEM;
1618012e3ca3SMauro Carvalho Chehab 		goto err_dss_init;
1619012e3ca3SMauro Carvalho Chehab 	}
1620012e3ca3SMauro Carvalho Chehab 
1621012e3ca3SMauro Carvalho Chehab 	vid_dev->num_displays = 0;
1622012e3ca3SMauro Carvalho Chehab 	for_each_dss_dev(dssdev) {
1623012e3ca3SMauro Carvalho Chehab 		omap_dss_get_device(dssdev);
1624012e3ca3SMauro Carvalho Chehab 
1625012e3ca3SMauro Carvalho Chehab 		if (!dssdev->driver) {
1626012e3ca3SMauro Carvalho Chehab 			dev_warn(&pdev->dev, "no driver for display: %s\n",
1627012e3ca3SMauro Carvalho Chehab 					dssdev->name);
1628012e3ca3SMauro Carvalho Chehab 			omap_dss_put_device(dssdev);
1629012e3ca3SMauro Carvalho Chehab 			continue;
1630012e3ca3SMauro Carvalho Chehab 		}
1631012e3ca3SMauro Carvalho Chehab 
1632012e3ca3SMauro Carvalho Chehab 		vid_dev->displays[vid_dev->num_displays++] = dssdev;
1633012e3ca3SMauro Carvalho Chehab 	}
1634012e3ca3SMauro Carvalho Chehab 
1635012e3ca3SMauro Carvalho Chehab 	if (vid_dev->num_displays == 0) {
1636012e3ca3SMauro Carvalho Chehab 		dev_err(&pdev->dev, "no displays\n");
1637012e3ca3SMauro Carvalho Chehab 		ret = -EINVAL;
1638012e3ca3SMauro Carvalho Chehab 		goto probe_err0;
1639012e3ca3SMauro Carvalho Chehab 	}
1640012e3ca3SMauro Carvalho Chehab 
1641012e3ca3SMauro Carvalho Chehab 	vid_dev->num_overlays = omap_dss_get_num_overlays();
1642012e3ca3SMauro Carvalho Chehab 	for (i = 0; i < vid_dev->num_overlays; i++)
1643012e3ca3SMauro Carvalho Chehab 		vid_dev->overlays[i] = omap_dss_get_overlay(i);
1644012e3ca3SMauro Carvalho Chehab 
1645012e3ca3SMauro Carvalho Chehab 	vid_dev->num_managers = omap_dss_get_num_overlay_managers();
1646012e3ca3SMauro Carvalho Chehab 	for (i = 0; i < vid_dev->num_managers; i++)
1647012e3ca3SMauro Carvalho Chehab 		vid_dev->managers[i] = omap_dss_get_overlay_manager(i);
1648012e3ca3SMauro Carvalho Chehab 
1649012e3ca3SMauro Carvalho Chehab 	/* Get the Video1 overlay and video2 overlay.
1650012e3ca3SMauro Carvalho Chehab 	 * Setup the Display attached to that overlays
1651012e3ca3SMauro Carvalho Chehab 	 */
1652012e3ca3SMauro Carvalho Chehab 	for (i = 1; i < vid_dev->num_overlays; i++) {
1653012e3ca3SMauro Carvalho Chehab 		ovl = omap_dss_get_overlay(i);
1654012e3ca3SMauro Carvalho Chehab 		dssdev = ovl->get_device(ovl);
1655012e3ca3SMauro Carvalho Chehab 
1656012e3ca3SMauro Carvalho Chehab 		if (dssdev) {
1657012e3ca3SMauro Carvalho Chehab 			def_display = dssdev;
1658012e3ca3SMauro Carvalho Chehab 		} else {
1659012e3ca3SMauro Carvalho Chehab 			dev_warn(&pdev->dev, "cannot find display\n");
1660012e3ca3SMauro Carvalho Chehab 			def_display = NULL;
1661012e3ca3SMauro Carvalho Chehab 		}
1662012e3ca3SMauro Carvalho Chehab 		if (def_display) {
1663012e3ca3SMauro Carvalho Chehab 			struct omap_dss_driver *dssdrv = def_display->driver;
1664012e3ca3SMauro Carvalho Chehab 
1665012e3ca3SMauro Carvalho Chehab 			ret = dssdrv->enable(def_display);
1666012e3ca3SMauro Carvalho Chehab 			if (ret) {
1667012e3ca3SMauro Carvalho Chehab 				/* Here we are not considering a error
1668012e3ca3SMauro Carvalho Chehab 				 *  as display may be enabled by frame
1669012e3ca3SMauro Carvalho Chehab 				 *  buffer driver
1670012e3ca3SMauro Carvalho Chehab 				 */
1671012e3ca3SMauro Carvalho Chehab 				dev_warn(&pdev->dev,
1672012e3ca3SMauro Carvalho Chehab 					"'%s' Display already enabled\n",
1673012e3ca3SMauro Carvalho Chehab 					def_display->name);
1674012e3ca3SMauro Carvalho Chehab 			}
1675012e3ca3SMauro Carvalho Chehab 		}
1676012e3ca3SMauro Carvalho Chehab 	}
1677012e3ca3SMauro Carvalho Chehab 
1678012e3ca3SMauro Carvalho Chehab 	if (v4l2_device_register(&pdev->dev, &vid_dev->v4l2_dev) < 0) {
1679012e3ca3SMauro Carvalho Chehab 		dev_err(&pdev->dev, "v4l2_device_register failed\n");
1680012e3ca3SMauro Carvalho Chehab 		ret = -ENODEV;
1681012e3ca3SMauro Carvalho Chehab 		goto probe_err1;
1682012e3ca3SMauro Carvalho Chehab 	}
1683012e3ca3SMauro Carvalho Chehab 
1684012e3ca3SMauro Carvalho Chehab 	ret = omap_vout_create_video_devices(pdev);
1685012e3ca3SMauro Carvalho Chehab 	if (ret)
1686012e3ca3SMauro Carvalho Chehab 		goto probe_err2;
1687012e3ca3SMauro Carvalho Chehab 
1688012e3ca3SMauro Carvalho Chehab 	for (i = 0; i < vid_dev->num_displays; i++) {
1689012e3ca3SMauro Carvalho Chehab 		struct omap_dss_device *display = vid_dev->displays[i];
1690012e3ca3SMauro Carvalho Chehab 
1691012e3ca3SMauro Carvalho Chehab 		if (display->driver->update)
1692012e3ca3SMauro Carvalho Chehab 			display->driver->update(display, 0, 0,
1693012e3ca3SMauro Carvalho Chehab 					display->panel.timings.x_res,
1694012e3ca3SMauro Carvalho Chehab 					display->panel.timings.y_res);
1695012e3ca3SMauro Carvalho Chehab 	}
1696012e3ca3SMauro Carvalho Chehab 	return 0;
1697012e3ca3SMauro Carvalho Chehab 
1698012e3ca3SMauro Carvalho Chehab probe_err2:
1699012e3ca3SMauro Carvalho Chehab 	v4l2_device_unregister(&vid_dev->v4l2_dev);
1700012e3ca3SMauro Carvalho Chehab probe_err1:
1701012e3ca3SMauro Carvalho Chehab 	for (i = 1; i < vid_dev->num_overlays; i++) {
1702012e3ca3SMauro Carvalho Chehab 		def_display = NULL;
1703012e3ca3SMauro Carvalho Chehab 		ovl = omap_dss_get_overlay(i);
1704012e3ca3SMauro Carvalho Chehab 		dssdev = ovl->get_device(ovl);
1705012e3ca3SMauro Carvalho Chehab 
1706012e3ca3SMauro Carvalho Chehab 		if (dssdev)
1707012e3ca3SMauro Carvalho Chehab 			def_display = dssdev;
1708012e3ca3SMauro Carvalho Chehab 
1709012e3ca3SMauro Carvalho Chehab 		if (def_display && def_display->driver)
1710012e3ca3SMauro Carvalho Chehab 			def_display->driver->disable(def_display);
1711012e3ca3SMauro Carvalho Chehab 	}
1712012e3ca3SMauro Carvalho Chehab probe_err0:
1713012e3ca3SMauro Carvalho Chehab 	kfree(vid_dev);
1714012e3ca3SMauro Carvalho Chehab err_dss_init:
1715012e3ca3SMauro Carvalho Chehab 	omapdss_compat_uninit();
1716012e3ca3SMauro Carvalho Chehab 	return ret;
1717012e3ca3SMauro Carvalho Chehab }
1718012e3ca3SMauro Carvalho Chehab 
1719012e3ca3SMauro Carvalho Chehab static struct platform_driver omap_vout_driver = {
1720012e3ca3SMauro Carvalho Chehab 	.driver = {
1721012e3ca3SMauro Carvalho Chehab 		.name = VOUT_NAME,
1722012e3ca3SMauro Carvalho Chehab 	},
1723*0a44e5f6SUwe Kleine-König 	.remove_new = omap_vout_remove,
1724012e3ca3SMauro Carvalho Chehab };
1725012e3ca3SMauro Carvalho Chehab 
omap_vout_init(void)1726012e3ca3SMauro Carvalho Chehab static int __init omap_vout_init(void)
1727012e3ca3SMauro Carvalho Chehab {
1728012e3ca3SMauro Carvalho Chehab 	if (platform_driver_probe(&omap_vout_driver, omap_vout_probe) != 0) {
1729012e3ca3SMauro Carvalho Chehab 		printk(KERN_ERR VOUT_NAME ":Could not register Video driver\n");
1730012e3ca3SMauro Carvalho Chehab 		return -EINVAL;
1731012e3ca3SMauro Carvalho Chehab 	}
1732012e3ca3SMauro Carvalho Chehab 	return 0;
1733012e3ca3SMauro Carvalho Chehab }
1734012e3ca3SMauro Carvalho Chehab 
omap_vout_cleanup(void)1735012e3ca3SMauro Carvalho Chehab static void omap_vout_cleanup(void)
1736012e3ca3SMauro Carvalho Chehab {
1737012e3ca3SMauro Carvalho Chehab 	platform_driver_unregister(&omap_vout_driver);
1738012e3ca3SMauro Carvalho Chehab }
1739012e3ca3SMauro Carvalho Chehab 
1740012e3ca3SMauro Carvalho Chehab late_initcall(omap_vout_init);
1741012e3ca3SMauro Carvalho Chehab module_exit(omap_vout_cleanup);
1742