4 * Copyright (C) 2005-2010 Texas Instruments.
6 * This file is licensed under the terms of the GNU General Public License
7 * version 2. This program is licensed "as is" without any warranty of any
8 * kind, whether express or implied.
10 * Leveraged code from the OMAP2 camera driver
11 * Video-for-Linux (Version 2) camera capture driver for
12 * the OMAP24xx camera controller.
14 * Author: Andy Lowe (source@mvista.com)
16 * Copyright (C) 2004 MontaVista Software, Inc.
17 * Copyright (C) 2010 Texas Instruments.
20 * 20-APR-2006 Khasim Modified VRFB based Rotation,
21 * The image data is always read from 0 degree
23 * to the virtual space of desired rotation angle
24 * 4-DEC-2006 Jian Changed to support better memory management
26 * 17-Nov-2008 Hardik Changed driver to use video_ioctl2
28 * 23-Feb-2010 Vaibhav H Modified to use new DSS2 interface
32 #include <linux/init.h>
33 #include <linux/module.h>
34 #include <linux/vmalloc.h>
35 #include <linux/sched.h>
36 #include <linux/types.h>
37 #include <linux/platform_device.h>
38 #include <linux/irq.h>
39 #include <linux/videodev2.h>
40 #include <linux/dma-mapping.h>
41 #include <linux/slab.h>
43 #include <media/videobuf-dma-contig.h>
44 #include <media/v4l2-device.h>
45 #include <media/v4l2-ioctl.h>
47 #include <video/omapvrfb.h>
48 #include <video/omapdss.h>
50 #include "omap_voutlib.h"
51 #include "omap_voutdef.h"
52 #include "omap_vout_vrfb.h"
54 MODULE_AUTHOR("Texas Instruments");
55 MODULE_DESCRIPTION("OMAP Video for Linux Video out driver");
56 MODULE_LICENSE("GPL");
58 /* Driver Configuration macros */
59 #define VOUT_NAME "omap_vout"
61 enum omap_vout_channels
{
66 static struct videobuf_queue_ops video_vbq_ops
;
67 /* Variables configurable through module params*/
68 static u32 video1_numbuffers
= 3;
69 static u32 video2_numbuffers
= 3;
70 static u32 video1_bufsize
= OMAP_VOUT_MAX_BUF_SIZE
;
71 static u32 video2_bufsize
= OMAP_VOUT_MAX_BUF_SIZE
;
72 static bool vid1_static_vrfb_alloc
;
73 static bool vid2_static_vrfb_alloc
;
76 /* Module parameters */
77 module_param(video1_numbuffers
, uint
, S_IRUGO
);
78 MODULE_PARM_DESC(video1_numbuffers
,
79 "Number of buffers to be allocated at init time for Video1 device.");
81 module_param(video2_numbuffers
, uint
, S_IRUGO
);
82 MODULE_PARM_DESC(video2_numbuffers
,
83 "Number of buffers to be allocated at init time for Video2 device.");
85 module_param(video1_bufsize
, uint
, S_IRUGO
);
86 MODULE_PARM_DESC(video1_bufsize
,
87 "Size of the buffer to be allocated for video1 device");
89 module_param(video2_bufsize
, uint
, S_IRUGO
);
90 MODULE_PARM_DESC(video2_bufsize
,
91 "Size of the buffer to be allocated for video2 device");
93 module_param(vid1_static_vrfb_alloc
, bool, S_IRUGO
);
94 MODULE_PARM_DESC(vid1_static_vrfb_alloc
,
95 "Static allocation of the VRFB buffer for video1 device");
97 module_param(vid2_static_vrfb_alloc
, bool, S_IRUGO
);
98 MODULE_PARM_DESC(vid2_static_vrfb_alloc
,
99 "Static allocation of the VRFB buffer for video2 device");
101 module_param(debug
, bool, S_IRUGO
);
102 MODULE_PARM_DESC(debug
, "Debug level (0-1)");
104 /* list of image formats supported by OMAP2 video pipelines */
105 static const struct v4l2_fmtdesc omap_formats
[] = {
107 /* Note: V4L2 defines RGB565 as:
110 * g2 g1 g0 r4 r3 r2 r1 r0 b4 b3 b2 b1 b0 g5 g4 g3
112 * We interpret RGB565 as:
115 * g2 g1 g0 b4 b3 b2 b1 b0 r4 r3 r2 r1 r0 g5 g4 g3
117 .description
= "RGB565, le",
118 .pixelformat
= V4L2_PIX_FMT_RGB565
,
121 /* Note: V4L2 defines RGB32 as: RGB-8-8-8-8 we use
122 * this for RGB24 unpack mode, the last 8 bits are ignored
124 .description
= "RGB32, le",
125 .pixelformat
= V4L2_PIX_FMT_RGB32
,
128 /* Note: V4L2 defines RGB24 as: RGB-8-8-8 we use
129 * this for RGB24 packed mode
132 .description
= "RGB24, le",
133 .pixelformat
= V4L2_PIX_FMT_RGB24
,
136 .description
= "YUYV (YUV 4:2:2), packed",
137 .pixelformat
= V4L2_PIX_FMT_YUYV
,
140 .description
= "UYVY, packed",
141 .pixelformat
= V4L2_PIX_FMT_UYVY
,
145 #define NUM_OUTPUT_FORMATS (ARRAY_SIZE(omap_formats))
150 static int omap_vout_try_format(struct v4l2_pix_format
*pix
)
154 pix
->height
= clamp(pix
->height
, (u32
)VID_MIN_HEIGHT
,
155 (u32
)VID_MAX_HEIGHT
);
156 pix
->width
= clamp(pix
->width
, (u32
)VID_MIN_WIDTH
, (u32
)VID_MAX_WIDTH
);
158 for (ifmt
= 0; ifmt
< NUM_OUTPUT_FORMATS
; ifmt
++) {
159 if (pix
->pixelformat
== omap_formats
[ifmt
].pixelformat
)
163 if (ifmt
== NUM_OUTPUT_FORMATS
)
166 pix
->pixelformat
= omap_formats
[ifmt
].pixelformat
;
167 pix
->field
= V4L2_FIELD_ANY
;
170 switch (pix
->pixelformat
) {
171 case V4L2_PIX_FMT_YUYV
:
172 case V4L2_PIX_FMT_UYVY
:
174 pix
->colorspace
= V4L2_COLORSPACE_JPEG
;
177 case V4L2_PIX_FMT_RGB565
:
178 case V4L2_PIX_FMT_RGB565X
:
179 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
182 case V4L2_PIX_FMT_RGB24
:
183 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
186 case V4L2_PIX_FMT_RGB32
:
187 case V4L2_PIX_FMT_BGR32
:
188 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
192 pix
->bytesperline
= pix
->width
* bpp
;
193 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
199 * omap_vout_uservirt_to_phys: This inline function is used to convert user
200 * space virtual address to physical address.
202 static u32
omap_vout_uservirt_to_phys(u32 virtp
)
204 unsigned long physp
= 0;
205 struct vm_area_struct
*vma
;
206 struct mm_struct
*mm
= current
->mm
;
208 vma
= find_vma(mm
, virtp
);
209 /* For kernel direct-mapped memory, take the easy way */
210 if (virtp
>= PAGE_OFFSET
) {
211 physp
= virt_to_phys((void *) virtp
);
212 } else if (vma
&& (vma
->vm_flags
& VM_IO
) && vma
->vm_pgoff
) {
213 /* this will catch, kernel-allocated, mmaped-to-usermode
215 physp
= (vma
->vm_pgoff
<< PAGE_SHIFT
) + (virtp
- vma
->vm_start
);
217 /* otherwise, use get_user_pages() for general userland pages */
218 int res
, nr_pages
= 1;
220 down_read(¤t
->mm
->mmap_sem
);
222 res
= get_user_pages(current
, current
->mm
, virtp
, nr_pages
, 1,
224 up_read(¤t
->mm
->mmap_sem
);
226 if (res
== nr_pages
) {
227 physp
= __pa(page_address(&pages
[0]) +
228 (virtp
& ~PAGE_MASK
));
230 printk(KERN_WARNING VOUT_NAME
231 "get_user_pages failed\n");
240 * Free the V4L2 buffers
242 void omap_vout_free_buffers(struct omap_vout_device
*vout
)
246 /* Allocate memory for the buffers */
247 numbuffers
= (vout
->vid
) ? video2_numbuffers
: video1_numbuffers
;
248 vout
->buffer_size
= (vout
->vid
) ? video2_bufsize
: video1_bufsize
;
250 for (i
= 0; i
< numbuffers
; i
++) {
251 omap_vout_free_buffer(vout
->buf_virt_addr
[i
],
253 vout
->buf_phy_addr
[i
] = 0;
254 vout
->buf_virt_addr
[i
] = 0;
259 * Convert V4L2 rotation to DSS rotation
260 * V4L2 understand 0, 90, 180, 270.
261 * Convert to 0, 1, 2 and 3 respectively for DSS
263 static int v4l2_rot_to_dss_rot(int v4l2_rotation
,
264 enum dss_rotation
*rotation
, bool mirror
)
268 switch (v4l2_rotation
) {
270 *rotation
= dss_rotation_90_degree
;
273 *rotation
= dss_rotation_180_degree
;
276 *rotation
= dss_rotation_270_degree
;
279 *rotation
= dss_rotation_0_degree
;
287 static int omap_vout_calculate_offset(struct omap_vout_device
*vout
)
289 struct omapvideo_info
*ovid
;
290 struct v4l2_rect
*crop
= &vout
->crop
;
291 struct v4l2_pix_format
*pix
= &vout
->pix
;
292 int *cropped_offset
= &vout
->cropped_offset
;
293 int ps
= 2, line_length
= 0;
295 ovid
= &vout
->vid_info
;
297 if (ovid
->rotation_type
== VOUT_ROT_VRFB
) {
298 omap_vout_calculate_vrfb_offset(vout
);
300 vout
->line_length
= line_length
= pix
->width
;
302 if (V4L2_PIX_FMT_YUYV
== pix
->pixelformat
||
303 V4L2_PIX_FMT_UYVY
== pix
->pixelformat
)
305 else if (V4L2_PIX_FMT_RGB32
== pix
->pixelformat
)
307 else if (V4L2_PIX_FMT_RGB24
== pix
->pixelformat
)
312 *cropped_offset
= (line_length
* ps
) *
313 crop
->top
+ crop
->left
* ps
;
316 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "%s Offset:%x\n",
317 __func__
, vout
->cropped_offset
);
323 * Convert V4L2 pixel format to DSS pixel format
325 static int video_mode_to_dss_mode(struct omap_vout_device
*vout
)
327 struct omap_overlay
*ovl
;
328 struct omapvideo_info
*ovid
;
329 struct v4l2_pix_format
*pix
= &vout
->pix
;
330 enum omap_color_mode mode
;
332 ovid
= &vout
->vid_info
;
333 ovl
= ovid
->overlays
[0];
335 switch (pix
->pixelformat
) {
338 case V4L2_PIX_FMT_YUYV
:
339 mode
= OMAP_DSS_COLOR_YUV2
;
341 case V4L2_PIX_FMT_UYVY
:
342 mode
= OMAP_DSS_COLOR_UYVY
;
344 case V4L2_PIX_FMT_RGB565
:
345 mode
= OMAP_DSS_COLOR_RGB16
;
347 case V4L2_PIX_FMT_RGB24
:
348 mode
= OMAP_DSS_COLOR_RGB24P
;
350 case V4L2_PIX_FMT_RGB32
:
351 mode
= (ovl
->id
== OMAP_DSS_VIDEO1
) ?
352 OMAP_DSS_COLOR_RGB24U
: OMAP_DSS_COLOR_ARGB32
;
354 case V4L2_PIX_FMT_BGR32
:
355 mode
= OMAP_DSS_COLOR_RGBX32
;
366 static int omapvid_setup_overlay(struct omap_vout_device
*vout
,
367 struct omap_overlay
*ovl
, int posx
, int posy
, int outw
,
371 struct omap_overlay_info info
;
372 int cropheight
, cropwidth
, pixheight
, pixwidth
;
374 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_SCALE
) == 0 &&
375 (outw
!= vout
->pix
.width
|| outh
!= vout
->pix
.height
)) {
380 vout
->dss_mode
= video_mode_to_dss_mode(vout
);
381 if (vout
->dss_mode
== -EINVAL
) {
386 /* Setup the input plane parameters according to
387 * rotation value selected.
389 if (is_rotation_90_or_270(vout
)) {
390 cropheight
= vout
->crop
.width
;
391 cropwidth
= vout
->crop
.height
;
392 pixheight
= vout
->pix
.width
;
393 pixwidth
= vout
->pix
.height
;
395 cropheight
= vout
->crop
.height
;
396 cropwidth
= vout
->crop
.width
;
397 pixheight
= vout
->pix
.height
;
398 pixwidth
= vout
->pix
.width
;
401 ovl
->get_overlay_info(ovl
, &info
);
403 info
.width
= cropwidth
;
404 info
.height
= cropheight
;
405 info
.color_mode
= vout
->dss_mode
;
406 info
.mirror
= vout
->mirror
;
409 info
.out_width
= outw
;
410 info
.out_height
= outh
;
411 info
.global_alpha
= vout
->win
.global_alpha
;
412 if (!is_rotation_enabled(vout
)) {
414 info
.rotation_type
= OMAP_DSS_ROT_DMA
;
415 info
.screen_width
= pixwidth
;
417 info
.rotation
= vout
->rotation
;
418 info
.rotation_type
= OMAP_DSS_ROT_VRFB
;
419 info
.screen_width
= 2048;
422 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
423 "%s enable=%d addr=%x width=%d\n height=%d color_mode=%d\n"
424 "rotation=%d mirror=%d posx=%d posy=%d out_width = %d \n"
425 "out_height=%d rotation_type=%d screen_width=%d\n",
426 __func__
, ovl
->is_enabled(ovl
), info
.paddr
, info
.width
, info
.height
,
427 info
.color_mode
, info
.rotation
, info
.mirror
, info
.pos_x
,
428 info
.pos_y
, info
.out_width
, info
.out_height
, info
.rotation_type
,
431 ret
= ovl
->set_overlay_info(ovl
, &info
);
438 v4l2_warn(&vout
->vid_dev
->v4l2_dev
, "setup_overlay failed\n");
443 * Initialize the overlay structure
445 static int omapvid_init(struct omap_vout_device
*vout
, u32 addr
)
448 struct v4l2_window
*win
;
449 struct omap_overlay
*ovl
;
450 int posx
, posy
, outw
, outh
, temp
;
451 struct omap_video_timings
*timing
;
452 struct omapvideo_info
*ovid
= &vout
->vid_info
;
455 for (i
= 0; i
< ovid
->num_overlays
; i
++) {
456 struct omap_dss_device
*dssdev
;
458 ovl
= ovid
->overlays
[i
];
459 dssdev
= ovl
->get_device(ovl
);
464 timing
= &dssdev
->panel
.timings
;
467 outh
= win
->w
.height
;
468 switch (vout
->rotation
) {
469 case dss_rotation_90_degree
:
470 /* Invert the height and width for 90
471 * and 270 degree rotation
476 posy
= (timing
->y_res
- win
->w
.width
) - win
->w
.left
;
480 case dss_rotation_180_degree
:
481 posx
= (timing
->x_res
- win
->w
.width
) - win
->w
.left
;
482 posy
= (timing
->y_res
- win
->w
.height
) - win
->w
.top
;
485 case dss_rotation_270_degree
:
490 posx
= (timing
->x_res
- win
->w
.height
) - win
->w
.top
;
499 ret
= omapvid_setup_overlay(vout
, ovl
, posx
, posy
,
502 goto omapvid_init_err
;
507 v4l2_warn(&vout
->vid_dev
->v4l2_dev
, "apply_changes failed\n");
512 * Apply the changes set the go bit of DSS
514 static int omapvid_apply_changes(struct omap_vout_device
*vout
)
517 struct omap_overlay
*ovl
;
518 struct omapvideo_info
*ovid
= &vout
->vid_info
;
520 for (i
= 0; i
< ovid
->num_overlays
; i
++) {
521 struct omap_dss_device
*dssdev
;
523 ovl
= ovid
->overlays
[i
];
524 dssdev
= ovl
->get_device(ovl
);
527 ovl
->manager
->apply(ovl
->manager
);
533 static int omapvid_handle_interlace_display(struct omap_vout_device
*vout
,
534 unsigned int irqstatus
, struct timeval timevalue
)
538 if (vout
->first_int
) {
543 if (irqstatus
& DISPC_IRQ_EVSYNC_ODD
)
545 else if (irqstatus
& DISPC_IRQ_EVSYNC_EVEN
)
551 if (fid
!= vout
->field_id
) {
553 vout
->field_id
= fid
;
554 } else if (0 == fid
) {
555 if (vout
->cur_frm
== vout
->next_frm
)
558 vout
->cur_frm
->ts
= timevalue
;
559 vout
->cur_frm
->state
= VIDEOBUF_DONE
;
560 wake_up_interruptible(&vout
->cur_frm
->done
);
561 vout
->cur_frm
= vout
->next_frm
;
563 if (list_empty(&vout
->dma_queue
) ||
564 (vout
->cur_frm
!= vout
->next_frm
))
568 return vout
->field_id
;
573 static void omap_vout_isr(void *arg
, unsigned int irqstatus
)
575 int ret
, fid
, mgr_id
;
577 struct omap_overlay
*ovl
;
578 struct timeval timevalue
;
579 struct omapvideo_info
*ovid
;
580 struct omap_dss_device
*cur_display
;
581 struct omap_vout_device
*vout
= (struct omap_vout_device
*)arg
;
583 if (!vout
->streaming
)
586 ovid
= &vout
->vid_info
;
587 ovl
= ovid
->overlays
[0];
589 mgr_id
= ovl
->manager
->id
;
591 /* get the display device attached to the overlay */
592 cur_display
= ovl
->get_device(ovl
);
597 spin_lock(&vout
->vbq_lock
);
598 v4l2_get_timestamp(&timevalue
);
600 switch (cur_display
->type
) {
601 case OMAP_DISPLAY_TYPE_DSI
:
602 case OMAP_DISPLAY_TYPE_DPI
:
603 if (mgr_id
== OMAP_DSS_CHANNEL_LCD
)
604 irq
= DISPC_IRQ_VSYNC
;
605 else if (mgr_id
== OMAP_DSS_CHANNEL_LCD2
)
606 irq
= DISPC_IRQ_VSYNC2
;
610 if (!(irqstatus
& irq
))
613 case OMAP_DISPLAY_TYPE_VENC
:
614 fid
= omapvid_handle_interlace_display(vout
, irqstatus
,
619 case OMAP_DISPLAY_TYPE_HDMI
:
620 if (!(irqstatus
& DISPC_IRQ_EVSYNC_EVEN
))
627 if (!vout
->first_int
&& (vout
->cur_frm
!= vout
->next_frm
)) {
628 vout
->cur_frm
->ts
= timevalue
;
629 vout
->cur_frm
->state
= VIDEOBUF_DONE
;
630 wake_up_interruptible(&vout
->cur_frm
->done
);
631 vout
->cur_frm
= vout
->next_frm
;
635 if (list_empty(&vout
->dma_queue
))
638 vout
->next_frm
= list_entry(vout
->dma_queue
.next
,
639 struct videobuf_buffer
, queue
);
640 list_del(&vout
->next_frm
->queue
);
642 vout
->next_frm
->state
= VIDEOBUF_ACTIVE
;
644 addr
= (unsigned long) vout
->queued_buf_addr
[vout
->next_frm
->i
]
645 + vout
->cropped_offset
;
647 /* First save the configuration in ovelray structure */
648 ret
= omapvid_init(vout
, addr
);
650 printk(KERN_ERR VOUT_NAME
651 "failed to set overlay info\n");
652 /* Enable the pipeline and set the Go bit */
653 ret
= omapvid_apply_changes(vout
);
655 printk(KERN_ERR VOUT_NAME
"failed to change mode\n");
658 spin_unlock(&vout
->vbq_lock
);
661 /* Video buffer call backs */
664 * Buffer setup function is called by videobuf layer when REQBUF ioctl is
665 * called. This is used to setup buffers and return size and count of
666 * buffers allocated. After the call to this buffer, videobuf layer will
667 * setup buffer queue depending on the size and count of buffers
669 static int omap_vout_buffer_setup(struct videobuf_queue
*q
, unsigned int *count
,
672 int startindex
= 0, i
, j
;
673 u32 phy_addr
= 0, virt_addr
= 0;
674 struct omap_vout_device
*vout
= q
->priv_data
;
675 struct omapvideo_info
*ovid
= &vout
->vid_info
;
676 int vid_max_buf_size
;
681 vid_max_buf_size
= vout
->vid
== OMAP_VIDEO1
? video1_bufsize
:
684 if (V4L2_BUF_TYPE_VIDEO_OUTPUT
!= q
->type
)
687 startindex
= (vout
->vid
== OMAP_VIDEO1
) ?
688 video1_numbuffers
: video2_numbuffers
;
689 if (V4L2_MEMORY_MMAP
== vout
->memory
&& *count
< startindex
)
692 if (ovid
->rotation_type
== VOUT_ROT_VRFB
) {
693 if (omap_vout_vrfb_buffer_setup(vout
, count
, startindex
))
697 if (V4L2_MEMORY_MMAP
!= vout
->memory
)
700 /* Now allocated the V4L2 buffers */
701 *size
= PAGE_ALIGN(vout
->pix
.width
* vout
->pix
.height
* vout
->bpp
);
702 startindex
= (vout
->vid
== OMAP_VIDEO1
) ?
703 video1_numbuffers
: video2_numbuffers
;
705 /* Check the size of the buffer */
706 if (*size
> vid_max_buf_size
) {
707 v4l2_err(&vout
->vid_dev
->v4l2_dev
,
708 "buffer allocation mismatch [%u] [%u]\n",
709 *size
, vout
->buffer_size
);
713 for (i
= startindex
; i
< *count
; i
++) {
714 vout
->buffer_size
= *size
;
716 virt_addr
= omap_vout_alloc_buffer(vout
->buffer_size
,
719 if (ovid
->rotation_type
== VOUT_ROT_NONE
) {
722 if (!is_rotation_enabled(vout
))
724 /* Free the VRFB buffers if no space for V4L2 buffers */
725 for (j
= i
; j
< *count
; j
++) {
726 omap_vout_free_buffer(
727 vout
->smsshado_virt_addr
[j
],
728 vout
->smsshado_size
);
729 vout
->smsshado_virt_addr
[j
] = 0;
730 vout
->smsshado_phy_addr
[j
] = 0;
734 vout
->buf_virt_addr
[i
] = virt_addr
;
735 vout
->buf_phy_addr
[i
] = phy_addr
;
737 *count
= vout
->buffer_allocated
= i
;
743 * Free the V4L2 buffers additionally allocated than default
746 static void omap_vout_free_extra_buffers(struct omap_vout_device
*vout
)
748 int num_buffers
= 0, i
;
750 num_buffers
= (vout
->vid
== OMAP_VIDEO1
) ?
751 video1_numbuffers
: video2_numbuffers
;
753 for (i
= num_buffers
; i
< vout
->buffer_allocated
; i
++) {
754 if (vout
->buf_virt_addr
[i
])
755 omap_vout_free_buffer(vout
->buf_virt_addr
[i
],
758 vout
->buf_virt_addr
[i
] = 0;
759 vout
->buf_phy_addr
[i
] = 0;
761 vout
->buffer_allocated
= num_buffers
;
765 * This function will be called when VIDIOC_QBUF ioctl is called.
766 * It prepare buffers before give out for the display. This function
767 * converts user space virtual address into physical address if userptr memory
768 * exchange mechanism is used. If rotation is enabled, it copies entire
769 * buffer into VRFB memory space before giving it to the DSS.
771 static int omap_vout_buffer_prepare(struct videobuf_queue
*q
,
772 struct videobuf_buffer
*vb
,
773 enum v4l2_field field
)
775 struct omap_vout_device
*vout
= q
->priv_data
;
776 struct omapvideo_info
*ovid
= &vout
->vid_info
;
778 if (VIDEOBUF_NEEDS_INIT
== vb
->state
) {
779 vb
->width
= vout
->pix
.width
;
780 vb
->height
= vout
->pix
.height
;
781 vb
->size
= vb
->width
* vb
->height
* vout
->bpp
;
784 vb
->state
= VIDEOBUF_PREPARED
;
785 /* if user pointer memory mechanism is used, get the physical
786 * address of the buffer
788 if (V4L2_MEMORY_USERPTR
== vb
->memory
) {
791 /* Physical address */
792 vout
->queued_buf_addr
[vb
->i
] = (u8
*)
793 omap_vout_uservirt_to_phys(vb
->baddr
);
798 addr
= (unsigned long) vout
->buf_virt_addr
[vb
->i
];
799 size
= (unsigned long) vb
->size
;
801 dma_addr
= dma_map_single(vout
->vid_dev
->v4l2_dev
.dev
, (void *) addr
,
802 size
, DMA_TO_DEVICE
);
803 if (dma_mapping_error(vout
->vid_dev
->v4l2_dev
.dev
, dma_addr
))
804 v4l2_err(&vout
->vid_dev
->v4l2_dev
, "dma_map_single failed\n");
806 vout
->queued_buf_addr
[vb
->i
] = (u8
*)vout
->buf_phy_addr
[vb
->i
];
809 if (ovid
->rotation_type
== VOUT_ROT_VRFB
)
810 return omap_vout_prepare_vrfb(vout
, vb
);
816 * Buffer queue function will be called from the videobuf layer when _QBUF
817 * ioctl is called. It is used to enqueue buffer, which is ready to be
820 static void omap_vout_buffer_queue(struct videobuf_queue
*q
,
821 struct videobuf_buffer
*vb
)
823 struct omap_vout_device
*vout
= q
->priv_data
;
825 /* Driver is also maintainig a queue. So enqueue buffer in the driver
827 list_add_tail(&vb
->queue
, &vout
->dma_queue
);
829 vb
->state
= VIDEOBUF_QUEUED
;
833 * Buffer release function is called from videobuf layer to release buffer
834 * which are already allocated
836 static void omap_vout_buffer_release(struct videobuf_queue
*q
,
837 struct videobuf_buffer
*vb
)
839 struct omap_vout_device
*vout
= q
->priv_data
;
841 vb
->state
= VIDEOBUF_NEEDS_INIT
;
843 if (V4L2_MEMORY_MMAP
!= vout
->memory
)
850 static unsigned int omap_vout_poll(struct file
*file
,
851 struct poll_table_struct
*wait
)
853 struct omap_vout_device
*vout
= file
->private_data
;
854 struct videobuf_queue
*q
= &vout
->vbq
;
856 return videobuf_poll_stream(file
, q
, wait
);
859 static void omap_vout_vm_open(struct vm_area_struct
*vma
)
861 struct omap_vout_device
*vout
= vma
->vm_private_data
;
863 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
864 "vm_open [vma=%08lx-%08lx]\n", vma
->vm_start
, vma
->vm_end
);
868 static void omap_vout_vm_close(struct vm_area_struct
*vma
)
870 struct omap_vout_device
*vout
= vma
->vm_private_data
;
872 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
873 "vm_close [vma=%08lx-%08lx]\n", vma
->vm_start
, vma
->vm_end
);
877 static struct vm_operations_struct omap_vout_vm_ops
= {
878 .open
= omap_vout_vm_open
,
879 .close
= omap_vout_vm_close
,
882 static int omap_vout_mmap(struct file
*file
, struct vm_area_struct
*vma
)
886 unsigned long start
= vma
->vm_start
;
887 unsigned long size
= (vma
->vm_end
- vma
->vm_start
);
888 struct omap_vout_device
*vout
= file
->private_data
;
889 struct videobuf_queue
*q
= &vout
->vbq
;
891 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
892 " %s pgoff=0x%lx, start=0x%lx, end=0x%lx\n", __func__
,
893 vma
->vm_pgoff
, vma
->vm_start
, vma
->vm_end
);
895 /* look for the buffer to map */
896 for (i
= 0; i
< VIDEO_MAX_FRAME
; i
++) {
897 if (NULL
== q
->bufs
[i
])
899 if (V4L2_MEMORY_MMAP
!= q
->bufs
[i
]->memory
)
901 if (q
->bufs
[i
]->boff
== (vma
->vm_pgoff
<< PAGE_SHIFT
))
905 if (VIDEO_MAX_FRAME
== i
) {
906 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
907 "offset invalid [offset=0x%lx]\n",
908 (vma
->vm_pgoff
<< PAGE_SHIFT
));
911 /* Check the size of the buffer */
912 if (size
> vout
->buffer_size
) {
913 v4l2_err(&vout
->vid_dev
->v4l2_dev
,
914 "insufficient memory [%lu] [%u]\n",
915 size
, vout
->buffer_size
);
919 q
->bufs
[i
]->baddr
= vma
->vm_start
;
921 vma
->vm_flags
|= VM_DONTEXPAND
| VM_DONTDUMP
;
922 vma
->vm_page_prot
= pgprot_writecombine(vma
->vm_page_prot
);
923 vma
->vm_ops
= &omap_vout_vm_ops
;
924 vma
->vm_private_data
= (void *) vout
;
925 pos
= (void *)vout
->buf_virt_addr
[i
];
926 vma
->vm_pgoff
= virt_to_phys((void *)pos
) >> PAGE_SHIFT
;
929 pfn
= virt_to_phys((void *) pos
) >> PAGE_SHIFT
;
930 if (remap_pfn_range(vma
, start
, pfn
, PAGE_SIZE
, PAGE_SHARED
))
937 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Exiting %s\n", __func__
);
942 static int omap_vout_release(struct file
*file
)
945 struct videobuf_queue
*q
;
946 struct omapvideo_info
*ovid
;
947 struct omap_vout_device
*vout
= file
->private_data
;
949 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Entering %s\n", __func__
);
950 ovid
= &vout
->vid_info
;
956 /* Disable all the overlay managers connected with this interface */
957 for (i
= 0; i
< ovid
->num_overlays
; i
++) {
958 struct omap_overlay
*ovl
= ovid
->overlays
[i
];
959 struct omap_dss_device
*dssdev
= ovl
->get_device(ovl
);
964 /* Turn off the pipeline */
965 ret
= omapvid_apply_changes(vout
);
967 v4l2_warn(&vout
->vid_dev
->v4l2_dev
,
968 "Unable to apply changes\n");
970 /* Free all buffers */
971 omap_vout_free_extra_buffers(vout
);
973 /* Free the VRFB buffers only if they are allocated
974 * during reqbufs. Don't free if init time allocated
976 if (ovid
->rotation_type
== VOUT_ROT_VRFB
) {
977 if (!vout
->vrfb_static_allocation
)
978 omap_vout_free_vrfb_buffers(vout
);
980 videobuf_mmap_free(q
);
982 /* Even if apply changes fails we should continue
983 freeing allocated memory */
984 if (vout
->streaming
) {
987 mask
= DISPC_IRQ_VSYNC
| DISPC_IRQ_EVSYNC_EVEN
|
988 DISPC_IRQ_EVSYNC_ODD
| DISPC_IRQ_VSYNC2
;
989 omap_dispc_unregister_isr(omap_vout_isr
, vout
, mask
);
992 videobuf_streamoff(q
);
993 videobuf_queue_cancel(q
);
996 if (vout
->mmap_count
!= 0)
997 vout
->mmap_count
= 0;
1000 file
->private_data
= NULL
;
1002 if (vout
->buffer_allocated
)
1003 videobuf_mmap_free(q
);
1005 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Exiting %s\n", __func__
);
1009 static int omap_vout_open(struct file
*file
)
1011 struct videobuf_queue
*q
;
1012 struct omap_vout_device
*vout
= NULL
;
1014 vout
= video_drvdata(file
);
1015 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Entering %s\n", __func__
);
1020 /* for now, we only support single open */
1026 file
->private_data
= vout
;
1027 vout
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
1030 video_vbq_ops
.buf_setup
= omap_vout_buffer_setup
;
1031 video_vbq_ops
.buf_prepare
= omap_vout_buffer_prepare
;
1032 video_vbq_ops
.buf_release
= omap_vout_buffer_release
;
1033 video_vbq_ops
.buf_queue
= omap_vout_buffer_queue
;
1034 spin_lock_init(&vout
->vbq_lock
);
1036 videobuf_queue_dma_contig_init(q
, &video_vbq_ops
, q
->dev
,
1037 &vout
->vbq_lock
, vout
->type
, V4L2_FIELD_NONE
,
1038 sizeof(struct videobuf_buffer
), vout
, NULL
);
1040 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Exiting %s\n", __func__
);
1047 static int vidioc_querycap(struct file
*file
, void *fh
,
1048 struct v4l2_capability
*cap
)
1050 struct omap_vout_device
*vout
= fh
;
1052 strlcpy(cap
->driver
, VOUT_NAME
, sizeof(cap
->driver
));
1053 strlcpy(cap
->card
, vout
->vfd
->name
, sizeof(cap
->card
));
1054 cap
->bus_info
[0] = '\0';
1055 cap
->capabilities
= V4L2_CAP_STREAMING
| V4L2_CAP_VIDEO_OUTPUT
|
1056 V4L2_CAP_VIDEO_OUTPUT_OVERLAY
;
1061 static int vidioc_enum_fmt_vid_out(struct file
*file
, void *fh
,
1062 struct v4l2_fmtdesc
*fmt
)
1064 int index
= fmt
->index
;
1066 if (index
>= NUM_OUTPUT_FORMATS
)
1069 fmt
->flags
= omap_formats
[index
].flags
;
1070 strlcpy(fmt
->description
, omap_formats
[index
].description
,
1071 sizeof(fmt
->description
));
1072 fmt
->pixelformat
= omap_formats
[index
].pixelformat
;
1077 static int vidioc_g_fmt_vid_out(struct file
*file
, void *fh
,
1078 struct v4l2_format
*f
)
1080 struct omap_vout_device
*vout
= fh
;
1082 f
->fmt
.pix
= vout
->pix
;
1087 static int vidioc_try_fmt_vid_out(struct file
*file
, void *fh
,
1088 struct v4l2_format
*f
)
1090 struct omap_overlay
*ovl
;
1091 struct omapvideo_info
*ovid
;
1092 struct omap_video_timings
*timing
;
1093 struct omap_vout_device
*vout
= fh
;
1094 struct omap_dss_device
*dssdev
;
1096 ovid
= &vout
->vid_info
;
1097 ovl
= ovid
->overlays
[0];
1098 /* get the display device attached to the overlay */
1099 dssdev
= ovl
->get_device(ovl
);
1104 timing
= &dssdev
->panel
.timings
;
1106 vout
->fbuf
.fmt
.height
= timing
->y_res
;
1107 vout
->fbuf
.fmt
.width
= timing
->x_res
;
1109 omap_vout_try_format(&f
->fmt
.pix
);
1113 static int vidioc_s_fmt_vid_out(struct file
*file
, void *fh
,
1114 struct v4l2_format
*f
)
1117 struct omap_overlay
*ovl
;
1118 struct omapvideo_info
*ovid
;
1119 struct omap_video_timings
*timing
;
1120 struct omap_vout_device
*vout
= fh
;
1121 struct omap_dss_device
*dssdev
;
1123 if (vout
->streaming
)
1126 mutex_lock(&vout
->lock
);
1128 ovid
= &vout
->vid_info
;
1129 ovl
= ovid
->overlays
[0];
1130 dssdev
= ovl
->get_device(ovl
);
1132 /* get the display device attached to the overlay */
1135 goto s_fmt_vid_out_exit
;
1137 timing
= &dssdev
->panel
.timings
;
1139 /* We dont support RGB24-packed mode if vrfb rotation
1141 if ((is_rotation_enabled(vout
)) &&
1142 f
->fmt
.pix
.pixelformat
== V4L2_PIX_FMT_RGB24
) {
1144 goto s_fmt_vid_out_exit
;
1147 /* get the framebuffer parameters */
1149 if (is_rotation_90_or_270(vout
)) {
1150 vout
->fbuf
.fmt
.height
= timing
->x_res
;
1151 vout
->fbuf
.fmt
.width
= timing
->y_res
;
1153 vout
->fbuf
.fmt
.height
= timing
->y_res
;
1154 vout
->fbuf
.fmt
.width
= timing
->x_res
;
1157 /* change to samller size is OK */
1159 bpp
= omap_vout_try_format(&f
->fmt
.pix
);
1160 f
->fmt
.pix
.sizeimage
= f
->fmt
.pix
.width
* f
->fmt
.pix
.height
* bpp
;
1162 /* try & set the new output format */
1164 vout
->pix
= f
->fmt
.pix
;
1167 /* If YUYV then vrfb bpp is 2, for others its 1 */
1168 if (V4L2_PIX_FMT_YUYV
== vout
->pix
.pixelformat
||
1169 V4L2_PIX_FMT_UYVY
== vout
->pix
.pixelformat
)
1172 /* set default crop and win */
1173 omap_vout_new_format(&vout
->pix
, &vout
->fbuf
, &vout
->crop
, &vout
->win
);
1178 mutex_unlock(&vout
->lock
);
1182 static int vidioc_try_fmt_vid_overlay(struct file
*file
, void *fh
,
1183 struct v4l2_format
*f
)
1186 struct omap_vout_device
*vout
= fh
;
1187 struct omap_overlay
*ovl
;
1188 struct omapvideo_info
*ovid
;
1189 struct v4l2_window
*win
= &f
->fmt
.win
;
1191 ovid
= &vout
->vid_info
;
1192 ovl
= ovid
->overlays
[0];
1194 ret
= omap_vout_try_window(&vout
->fbuf
, win
);
1197 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
) == 0)
1198 win
->global_alpha
= 255;
1200 win
->global_alpha
= f
->fmt
.win
.global_alpha
;
1206 static int vidioc_s_fmt_vid_overlay(struct file
*file
, void *fh
,
1207 struct v4l2_format
*f
)
1210 struct omap_overlay
*ovl
;
1211 struct omapvideo_info
*ovid
;
1212 struct omap_vout_device
*vout
= fh
;
1213 struct v4l2_window
*win
= &f
->fmt
.win
;
1215 mutex_lock(&vout
->lock
);
1216 ovid
= &vout
->vid_info
;
1217 ovl
= ovid
->overlays
[0];
1219 ret
= omap_vout_new_window(&vout
->crop
, &vout
->win
, &vout
->fbuf
, win
);
1221 /* Video1 plane does not support global alpha on OMAP3 */
1222 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
) == 0)
1223 vout
->win
.global_alpha
= 255;
1225 vout
->win
.global_alpha
= f
->fmt
.win
.global_alpha
;
1227 vout
->win
.chromakey
= f
->fmt
.win
.chromakey
;
1229 mutex_unlock(&vout
->lock
);
1233 static int vidioc_g_fmt_vid_overlay(struct file
*file
, void *fh
,
1234 struct v4l2_format
*f
)
1237 struct omap_overlay
*ovl
;
1238 struct omapvideo_info
*ovid
;
1239 struct omap_vout_device
*vout
= fh
;
1240 struct omap_overlay_manager_info info
;
1241 struct v4l2_window
*win
= &f
->fmt
.win
;
1243 ovid
= &vout
->vid_info
;
1244 ovl
= ovid
->overlays
[0];
1246 win
->w
= vout
->win
.w
;
1247 win
->field
= vout
->win
.field
;
1248 win
->global_alpha
= vout
->win
.global_alpha
;
1250 if (ovl
->manager
&& ovl
->manager
->get_manager_info
) {
1251 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1252 key_value
= info
.trans_key
;
1254 win
->chromakey
= key_value
;
1258 static int vidioc_cropcap(struct file
*file
, void *fh
,
1259 struct v4l2_cropcap
*cropcap
)
1261 struct omap_vout_device
*vout
= fh
;
1262 struct v4l2_pix_format
*pix
= &vout
->pix
;
1264 if (cropcap
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1267 /* Width and height are always even */
1268 cropcap
->bounds
.width
= pix
->width
& ~1;
1269 cropcap
->bounds
.height
= pix
->height
& ~1;
1271 omap_vout_default_crop(&vout
->pix
, &vout
->fbuf
, &cropcap
->defrect
);
1272 cropcap
->pixelaspect
.numerator
= 1;
1273 cropcap
->pixelaspect
.denominator
= 1;
1277 static int vidioc_g_crop(struct file
*file
, void *fh
, struct v4l2_crop
*crop
)
1279 struct omap_vout_device
*vout
= fh
;
1281 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1283 crop
->c
= vout
->crop
;
1287 static int vidioc_s_crop(struct file
*file
, void *fh
, const struct v4l2_crop
*crop
)
1290 struct omap_vout_device
*vout
= fh
;
1291 struct omapvideo_info
*ovid
;
1292 struct omap_overlay
*ovl
;
1293 struct omap_video_timings
*timing
;
1294 struct omap_dss_device
*dssdev
;
1296 if (vout
->streaming
)
1299 mutex_lock(&vout
->lock
);
1300 ovid
= &vout
->vid_info
;
1301 ovl
= ovid
->overlays
[0];
1302 /* get the display device attached to the overlay */
1303 dssdev
= ovl
->get_device(ovl
);
1310 timing
= &dssdev
->panel
.timings
;
1312 if (is_rotation_90_or_270(vout
)) {
1313 vout
->fbuf
.fmt
.height
= timing
->x_res
;
1314 vout
->fbuf
.fmt
.width
= timing
->y_res
;
1316 vout
->fbuf
.fmt
.height
= timing
->y_res
;
1317 vout
->fbuf
.fmt
.width
= timing
->x_res
;
1320 if (crop
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1321 ret
= omap_vout_new_crop(&vout
->pix
, &vout
->crop
, &vout
->win
,
1322 &vout
->fbuf
, &crop
->c
);
1325 mutex_unlock(&vout
->lock
);
1329 static int vidioc_queryctrl(struct file
*file
, void *fh
,
1330 struct v4l2_queryctrl
*ctrl
)
1335 case V4L2_CID_ROTATE
:
1336 ret
= v4l2_ctrl_query_fill(ctrl
, 0, 270, 90, 0);
1338 case V4L2_CID_BG_COLOR
:
1339 ret
= v4l2_ctrl_query_fill(ctrl
, 0, 0xFFFFFF, 1, 0);
1341 case V4L2_CID_VFLIP
:
1342 ret
= v4l2_ctrl_query_fill(ctrl
, 0, 1, 1, 0);
1345 ctrl
->name
[0] = '\0';
1351 static int vidioc_g_ctrl(struct file
*file
, void *fh
, struct v4l2_control
*ctrl
)
1354 struct omap_vout_device
*vout
= fh
;
1357 case V4L2_CID_ROTATE
:
1358 ctrl
->value
= vout
->control
[0].value
;
1360 case V4L2_CID_BG_COLOR
:
1362 struct omap_overlay_manager_info info
;
1363 struct omap_overlay
*ovl
;
1365 ovl
= vout
->vid_info
.overlays
[0];
1366 if (!ovl
->manager
|| !ovl
->manager
->get_manager_info
) {
1371 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1372 ctrl
->value
= info
.default_color
;
1375 case V4L2_CID_VFLIP
:
1376 ctrl
->value
= vout
->control
[2].value
;
1384 static int vidioc_s_ctrl(struct file
*file
, void *fh
, struct v4l2_control
*a
)
1387 struct omap_vout_device
*vout
= fh
;
1390 case V4L2_CID_ROTATE
:
1392 struct omapvideo_info
*ovid
;
1393 int rotation
= a
->value
;
1395 ovid
= &vout
->vid_info
;
1397 mutex_lock(&vout
->lock
);
1398 if (rotation
&& ovid
->rotation_type
== VOUT_ROT_NONE
) {
1399 mutex_unlock(&vout
->lock
);
1404 if (rotation
&& vout
->pix
.pixelformat
== V4L2_PIX_FMT_RGB24
) {
1405 mutex_unlock(&vout
->lock
);
1410 if (v4l2_rot_to_dss_rot(rotation
, &vout
->rotation
,
1412 mutex_unlock(&vout
->lock
);
1417 vout
->control
[0].value
= rotation
;
1418 mutex_unlock(&vout
->lock
);
1421 case V4L2_CID_BG_COLOR
:
1423 struct omap_overlay
*ovl
;
1424 unsigned int color
= a
->value
;
1425 struct omap_overlay_manager_info info
;
1427 ovl
= vout
->vid_info
.overlays
[0];
1429 mutex_lock(&vout
->lock
);
1430 if (!ovl
->manager
|| !ovl
->manager
->get_manager_info
) {
1431 mutex_unlock(&vout
->lock
);
1436 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1437 info
.default_color
= color
;
1438 if (ovl
->manager
->set_manager_info(ovl
->manager
, &info
)) {
1439 mutex_unlock(&vout
->lock
);
1444 vout
->control
[1].value
= color
;
1445 mutex_unlock(&vout
->lock
);
1448 case V4L2_CID_VFLIP
:
1450 struct omap_overlay
*ovl
;
1451 struct omapvideo_info
*ovid
;
1452 unsigned int mirror
= a
->value
;
1454 ovid
= &vout
->vid_info
;
1455 ovl
= ovid
->overlays
[0];
1457 mutex_lock(&vout
->lock
);
1458 if (mirror
&& ovid
->rotation_type
== VOUT_ROT_NONE
) {
1459 mutex_unlock(&vout
->lock
);
1464 if (mirror
&& vout
->pix
.pixelformat
== V4L2_PIX_FMT_RGB24
) {
1465 mutex_unlock(&vout
->lock
);
1469 vout
->mirror
= mirror
;
1470 vout
->control
[2].value
= mirror
;
1471 mutex_unlock(&vout
->lock
);
1480 static int vidioc_reqbufs(struct file
*file
, void *fh
,
1481 struct v4l2_requestbuffers
*req
)
1484 unsigned int i
, num_buffers
= 0;
1485 struct omap_vout_device
*vout
= fh
;
1486 struct videobuf_queue
*q
= &vout
->vbq
;
1488 if ((req
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
) || (req
->count
< 0))
1490 /* if memory is not mmp or userptr
1492 if ((V4L2_MEMORY_MMAP
!= req
->memory
) &&
1493 (V4L2_MEMORY_USERPTR
!= req
->memory
))
1496 mutex_lock(&vout
->lock
);
1497 /* Cannot be requested when streaming is on */
1498 if (vout
->streaming
) {
1503 /* If buffers are already allocated free them */
1504 if (q
->bufs
[0] && (V4L2_MEMORY_MMAP
== q
->bufs
[0]->memory
)) {
1505 if (vout
->mmap_count
) {
1509 num_buffers
= (vout
->vid
== OMAP_VIDEO1
) ?
1510 video1_numbuffers
: video2_numbuffers
;
1511 for (i
= num_buffers
; i
< vout
->buffer_allocated
; i
++) {
1512 omap_vout_free_buffer(vout
->buf_virt_addr
[i
],
1514 vout
->buf_virt_addr
[i
] = 0;
1515 vout
->buf_phy_addr
[i
] = 0;
1517 vout
->buffer_allocated
= num_buffers
;
1518 videobuf_mmap_free(q
);
1519 } else if (q
->bufs
[0] && (V4L2_MEMORY_USERPTR
== q
->bufs
[0]->memory
)) {
1520 if (vout
->buffer_allocated
) {
1521 videobuf_mmap_free(q
);
1522 for (i
= 0; i
< vout
->buffer_allocated
; i
++) {
1526 vout
->buffer_allocated
= 0;
1530 /*store the memory type in data structure */
1531 vout
->memory
= req
->memory
;
1533 INIT_LIST_HEAD(&vout
->dma_queue
);
1535 /* call videobuf_reqbufs api */
1536 ret
= videobuf_reqbufs(q
, req
);
1540 vout
->buffer_allocated
= req
->count
;
1543 mutex_unlock(&vout
->lock
);
1547 static int vidioc_querybuf(struct file
*file
, void *fh
,
1548 struct v4l2_buffer
*b
)
1550 struct omap_vout_device
*vout
= fh
;
1552 return videobuf_querybuf(&vout
->vbq
, b
);
1555 static int vidioc_qbuf(struct file
*file
, void *fh
,
1556 struct v4l2_buffer
*buffer
)
1558 struct omap_vout_device
*vout
= fh
;
1559 struct videobuf_queue
*q
= &vout
->vbq
;
1561 if ((V4L2_BUF_TYPE_VIDEO_OUTPUT
!= buffer
->type
) ||
1562 (buffer
->index
>= vout
->buffer_allocated
) ||
1563 (q
->bufs
[buffer
->index
]->memory
!= buffer
->memory
)) {
1566 if (V4L2_MEMORY_USERPTR
== buffer
->memory
) {
1567 if ((buffer
->length
< vout
->pix
.sizeimage
) ||
1568 (0 == buffer
->m
.userptr
)) {
1573 if ((is_rotation_enabled(vout
)) &&
1574 vout
->vrfb_dma_tx
.req_status
== DMA_CHAN_NOT_ALLOTED
) {
1575 v4l2_warn(&vout
->vid_dev
->v4l2_dev
,
1576 "DMA Channel not allocated for Rotation\n");
1580 return videobuf_qbuf(q
, buffer
);
1583 static int vidioc_dqbuf(struct file
*file
, void *fh
, struct v4l2_buffer
*b
)
1585 struct omap_vout_device
*vout
= fh
;
1586 struct videobuf_queue
*q
= &vout
->vbq
;
1591 struct videobuf_buffer
*vb
;
1593 vb
= q
->bufs
[b
->index
];
1595 if (!vout
->streaming
)
1598 if (file
->f_flags
& O_NONBLOCK
)
1599 /* Call videobuf_dqbuf for non blocking mode */
1600 ret
= videobuf_dqbuf(q
, (struct v4l2_buffer
*)b
, 1);
1602 /* Call videobuf_dqbuf for blocking mode */
1603 ret
= videobuf_dqbuf(q
, (struct v4l2_buffer
*)b
, 0);
1605 addr
= (unsigned long) vout
->buf_phy_addr
[vb
->i
];
1606 size
= (unsigned long) vb
->size
;
1607 dma_unmap_single(vout
->vid_dev
->v4l2_dev
.dev
, addr
,
1608 size
, DMA_TO_DEVICE
);
1612 static int vidioc_streamon(struct file
*file
, void *fh
, enum v4l2_buf_type i
)
1615 u32 addr
= 0, mask
= 0;
1616 struct omap_vout_device
*vout
= fh
;
1617 struct videobuf_queue
*q
= &vout
->vbq
;
1618 struct omapvideo_info
*ovid
= &vout
->vid_info
;
1620 mutex_lock(&vout
->lock
);
1622 if (vout
->streaming
) {
1627 ret
= videobuf_streamon(q
);
1631 if (list_empty(&vout
->dma_queue
)) {
1636 /* Get the next frame from the buffer queue */
1637 vout
->next_frm
= vout
->cur_frm
= list_entry(vout
->dma_queue
.next
,
1638 struct videobuf_buffer
, queue
);
1639 /* Remove buffer from the buffer queue */
1640 list_del(&vout
->cur_frm
->queue
);
1641 /* Mark state of the current frame to active */
1642 vout
->cur_frm
->state
= VIDEOBUF_ACTIVE
;
1643 /* Initialize field_id and started member */
1646 /* set flag here. Next QBUF will start DMA */
1647 vout
->streaming
= 1;
1649 vout
->first_int
= 1;
1651 if (omap_vout_calculate_offset(vout
)) {
1655 addr
= (unsigned long) vout
->queued_buf_addr
[vout
->cur_frm
->i
]
1656 + vout
->cropped_offset
;
1658 mask
= DISPC_IRQ_VSYNC
| DISPC_IRQ_EVSYNC_EVEN
| DISPC_IRQ_EVSYNC_ODD
1661 omap_dispc_register_isr(omap_vout_isr
, vout
, mask
);
1663 /* First save the configuration in ovelray structure */
1664 ret
= omapvid_init(vout
, addr
);
1666 v4l2_err(&vout
->vid_dev
->v4l2_dev
,
1667 "failed to set overlay info\n");
1668 /* Enable the pipeline and set the Go bit */
1669 ret
= omapvid_apply_changes(vout
);
1671 v4l2_err(&vout
->vid_dev
->v4l2_dev
, "failed to change mode\n");
1673 for (j
= 0; j
< ovid
->num_overlays
; j
++) {
1674 struct omap_overlay
*ovl
= ovid
->overlays
[j
];
1675 struct omap_dss_device
*dssdev
= ovl
->get_device(ovl
);
1678 ret
= ovl
->enable(ovl
);
1688 ret
= videobuf_streamoff(q
);
1690 mutex_unlock(&vout
->lock
);
1694 static int vidioc_streamoff(struct file
*file
, void *fh
, enum v4l2_buf_type i
)
1698 struct omap_vout_device
*vout
= fh
;
1699 struct omapvideo_info
*ovid
= &vout
->vid_info
;
1701 if (!vout
->streaming
)
1704 vout
->streaming
= 0;
1705 mask
= DISPC_IRQ_VSYNC
| DISPC_IRQ_EVSYNC_EVEN
| DISPC_IRQ_EVSYNC_ODD
1708 omap_dispc_unregister_isr(omap_vout_isr
, vout
, mask
);
1710 for (j
= 0; j
< ovid
->num_overlays
; j
++) {
1711 struct omap_overlay
*ovl
= ovid
->overlays
[j
];
1712 struct omap_dss_device
*dssdev
= ovl
->get_device(ovl
);
1718 /* Turn of the pipeline */
1719 ret
= omapvid_apply_changes(vout
);
1721 v4l2_err(&vout
->vid_dev
->v4l2_dev
, "failed to change mode in"
1724 INIT_LIST_HEAD(&vout
->dma_queue
);
1725 ret
= videobuf_streamoff(&vout
->vbq
);
1730 static int vidioc_s_fbuf(struct file
*file
, void *fh
,
1731 const struct v4l2_framebuffer
*a
)
1734 struct omap_overlay
*ovl
;
1735 struct omapvideo_info
*ovid
;
1736 struct omap_vout_device
*vout
= fh
;
1737 struct omap_overlay_manager_info info
;
1738 enum omap_dss_trans_key_type key_type
= OMAP_DSS_COLOR_KEY_GFX_DST
;
1740 ovid
= &vout
->vid_info
;
1741 ovl
= ovid
->overlays
[0];
1743 /* OMAP DSS doesn't support Source and Destination color
1745 if ((a
->flags
& V4L2_FBUF_FLAG_SRC_CHROMAKEY
) &&
1746 (a
->flags
& V4L2_FBUF_FLAG_CHROMAKEY
))
1748 /* OMAP DSS Doesn't support the Destination color key
1749 and alpha blending together */
1750 if ((a
->flags
& V4L2_FBUF_FLAG_CHROMAKEY
) &&
1751 (a
->flags
& V4L2_FBUF_FLAG_LOCAL_ALPHA
))
1754 if ((a
->flags
& V4L2_FBUF_FLAG_SRC_CHROMAKEY
)) {
1755 vout
->fbuf
.flags
|= V4L2_FBUF_FLAG_SRC_CHROMAKEY
;
1756 key_type
= OMAP_DSS_COLOR_KEY_VID_SRC
;
1758 vout
->fbuf
.flags
&= ~V4L2_FBUF_FLAG_SRC_CHROMAKEY
;
1760 if ((a
->flags
& V4L2_FBUF_FLAG_CHROMAKEY
)) {
1761 vout
->fbuf
.flags
|= V4L2_FBUF_FLAG_CHROMAKEY
;
1762 key_type
= OMAP_DSS_COLOR_KEY_GFX_DST
;
1764 vout
->fbuf
.flags
&= ~V4L2_FBUF_FLAG_CHROMAKEY
;
1766 if (a
->flags
& (V4L2_FBUF_FLAG_CHROMAKEY
|
1767 V4L2_FBUF_FLAG_SRC_CHROMAKEY
))
1771 if (ovl
->manager
&& ovl
->manager
->get_manager_info
&&
1772 ovl
->manager
->set_manager_info
) {
1774 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1775 info
.trans_enabled
= enable
;
1776 info
.trans_key_type
= key_type
;
1777 info
.trans_key
= vout
->win
.chromakey
;
1779 if (ovl
->manager
->set_manager_info(ovl
->manager
, &info
))
1782 if (a
->flags
& V4L2_FBUF_FLAG_LOCAL_ALPHA
) {
1783 vout
->fbuf
.flags
|= V4L2_FBUF_FLAG_LOCAL_ALPHA
;
1786 vout
->fbuf
.flags
&= ~V4L2_FBUF_FLAG_LOCAL_ALPHA
;
1789 if (ovl
->manager
&& ovl
->manager
->get_manager_info
&&
1790 ovl
->manager
->set_manager_info
) {
1791 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1792 /* enable this only if there is no zorder cap */
1793 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_ZORDER
) == 0)
1794 info
.partial_alpha_enabled
= enable
;
1795 if (ovl
->manager
->set_manager_info(ovl
->manager
, &info
))
1802 static int vidioc_g_fbuf(struct file
*file
, void *fh
,
1803 struct v4l2_framebuffer
*a
)
1805 struct omap_overlay
*ovl
;
1806 struct omapvideo_info
*ovid
;
1807 struct omap_vout_device
*vout
= fh
;
1808 struct omap_overlay_manager_info info
;
1810 ovid
= &vout
->vid_info
;
1811 ovl
= ovid
->overlays
[0];
1813 /* The video overlay must stay within the framebuffer and can't be
1814 positioned independently. */
1815 a
->flags
= V4L2_FBUF_FLAG_OVERLAY
;
1816 a
->capability
= V4L2_FBUF_CAP_LOCAL_ALPHA
| V4L2_FBUF_CAP_CHROMAKEY
1817 | V4L2_FBUF_CAP_SRC_CHROMAKEY
;
1819 if (ovl
->manager
&& ovl
->manager
->get_manager_info
) {
1820 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1821 if (info
.trans_key_type
== OMAP_DSS_COLOR_KEY_VID_SRC
)
1822 a
->flags
|= V4L2_FBUF_FLAG_SRC_CHROMAKEY
;
1823 if (info
.trans_key_type
== OMAP_DSS_COLOR_KEY_GFX_DST
)
1824 a
->flags
|= V4L2_FBUF_FLAG_CHROMAKEY
;
1826 if (ovl
->manager
&& ovl
->manager
->get_manager_info
) {
1827 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1828 if (info
.partial_alpha_enabled
)
1829 a
->flags
|= V4L2_FBUF_FLAG_LOCAL_ALPHA
;
1835 static const struct v4l2_ioctl_ops vout_ioctl_ops
= {
1836 .vidioc_querycap
= vidioc_querycap
,
1837 .vidioc_enum_fmt_vid_out
= vidioc_enum_fmt_vid_out
,
1838 .vidioc_g_fmt_vid_out
= vidioc_g_fmt_vid_out
,
1839 .vidioc_try_fmt_vid_out
= vidioc_try_fmt_vid_out
,
1840 .vidioc_s_fmt_vid_out
= vidioc_s_fmt_vid_out
,
1841 .vidioc_queryctrl
= vidioc_queryctrl
,
1842 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1843 .vidioc_s_fbuf
= vidioc_s_fbuf
,
1844 .vidioc_g_fbuf
= vidioc_g_fbuf
,
1845 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1846 .vidioc_try_fmt_vid_out_overlay
= vidioc_try_fmt_vid_overlay
,
1847 .vidioc_s_fmt_vid_out_overlay
= vidioc_s_fmt_vid_overlay
,
1848 .vidioc_g_fmt_vid_out_overlay
= vidioc_g_fmt_vid_overlay
,
1849 .vidioc_cropcap
= vidioc_cropcap
,
1850 .vidioc_g_crop
= vidioc_g_crop
,
1851 .vidioc_s_crop
= vidioc_s_crop
,
1852 .vidioc_reqbufs
= vidioc_reqbufs
,
1853 .vidioc_querybuf
= vidioc_querybuf
,
1854 .vidioc_qbuf
= vidioc_qbuf
,
1855 .vidioc_dqbuf
= vidioc_dqbuf
,
1856 .vidioc_streamon
= vidioc_streamon
,
1857 .vidioc_streamoff
= vidioc_streamoff
,
1860 static const struct v4l2_file_operations omap_vout_fops
= {
1861 .owner
= THIS_MODULE
,
1862 .poll
= omap_vout_poll
,
1863 .unlocked_ioctl
= video_ioctl2
,
1864 .mmap
= omap_vout_mmap
,
1865 .open
= omap_vout_open
,
1866 .release
= omap_vout_release
,
1869 /* Init functions used during driver initialization */
1870 /* Initial setup of video_data */
1871 static int __init
omap_vout_setup_video_data(struct omap_vout_device
*vout
)
1873 struct video_device
*vfd
;
1874 struct v4l2_pix_format
*pix
;
1875 struct v4l2_control
*control
;
1876 struct omap_overlay
*ovl
= vout
->vid_info
.overlays
[0];
1877 struct omap_dss_device
*display
= ovl
->get_device(ovl
);
1879 /* set the default pix */
1882 /* Set the default picture of QVGA */
1883 pix
->width
= QQVGA_WIDTH
;
1884 pix
->height
= QQVGA_HEIGHT
;
1886 /* Default pixel format is RGB 5-6-5 */
1887 pix
->pixelformat
= V4L2_PIX_FMT_RGB565
;
1888 pix
->field
= V4L2_FIELD_ANY
;
1889 pix
->bytesperline
= pix
->width
* 2;
1890 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
1892 pix
->colorspace
= V4L2_COLORSPACE_JPEG
;
1894 vout
->bpp
= RGB565_BPP
;
1895 vout
->fbuf
.fmt
.width
= display
->panel
.timings
.x_res
;
1896 vout
->fbuf
.fmt
.height
= display
->panel
.timings
.y_res
;
1898 /* Set the data structures for the overlay parameters*/
1899 vout
->win
.global_alpha
= 255;
1900 vout
->fbuf
.flags
= 0;
1901 vout
->fbuf
.capability
= V4L2_FBUF_CAP_LOCAL_ALPHA
|
1902 V4L2_FBUF_CAP_SRC_CHROMAKEY
| V4L2_FBUF_CAP_CHROMAKEY
;
1903 vout
->win
.chromakey
= 0;
1905 omap_vout_new_format(pix
, &vout
->fbuf
, &vout
->crop
, &vout
->win
);
1907 /*Initialize the control variables for
1908 rotation, flipping and background color. */
1909 control
= vout
->control
;
1910 control
[0].id
= V4L2_CID_ROTATE
;
1911 control
[0].value
= 0;
1914 vout
->control
[2].id
= V4L2_CID_HFLIP
;
1915 vout
->control
[2].value
= 0;
1916 if (vout
->vid_info
.rotation_type
== VOUT_ROT_VRFB
)
1919 control
[1].id
= V4L2_CID_BG_COLOR
;
1920 control
[1].value
= 0;
1922 /* initialize the video_device struct */
1923 vfd
= vout
->vfd
= video_device_alloc();
1926 printk(KERN_ERR VOUT_NAME
": could not allocate"
1927 " video device struct\n");
1930 vfd
->release
= video_device_release
;
1931 vfd
->ioctl_ops
= &vout_ioctl_ops
;
1933 strlcpy(vfd
->name
, VOUT_NAME
, sizeof(vfd
->name
));
1935 vfd
->fops
= &omap_vout_fops
;
1936 vfd
->v4l2_dev
= &vout
->vid_dev
->v4l2_dev
;
1937 vfd
->vfl_dir
= VFL_DIR_TX
;
1938 mutex_init(&vout
->lock
);
1945 /* Setup video buffers */
1946 static int __init
omap_vout_setup_video_bufs(struct platform_device
*pdev
,
1951 struct omapvideo_info
*ovid
;
1952 struct omap_vout_device
*vout
;
1953 struct v4l2_device
*v4l2_dev
= platform_get_drvdata(pdev
);
1954 struct omap2video_device
*vid_dev
=
1955 container_of(v4l2_dev
, struct omap2video_device
, v4l2_dev
);
1957 vout
= vid_dev
->vouts
[vid_num
];
1958 ovid
= &vout
->vid_info
;
1960 numbuffers
= (vid_num
== 0) ? video1_numbuffers
: video2_numbuffers
;
1961 vout
->buffer_size
= (vid_num
== 0) ? video1_bufsize
: video2_bufsize
;
1962 dev_info(&pdev
->dev
, "Buffer Size = %d\n", vout
->buffer_size
);
1964 for (i
= 0; i
< numbuffers
; i
++) {
1965 vout
->buf_virt_addr
[i
] =
1966 omap_vout_alloc_buffer(vout
->buffer_size
,
1967 (u32
*) &vout
->buf_phy_addr
[i
]);
1968 if (!vout
->buf_virt_addr
[i
]) {
1975 vout
->cropped_offset
= 0;
1977 if (ovid
->rotation_type
== VOUT_ROT_VRFB
) {
1978 int static_vrfb_allocation
= (vid_num
== 0) ?
1979 vid1_static_vrfb_alloc
: vid2_static_vrfb_alloc
;
1980 ret
= omap_vout_setup_vrfb_bufs(pdev
, vid_num
,
1981 static_vrfb_allocation
);
1987 for (i
= 0; i
< numbuffers
; i
++) {
1988 omap_vout_free_buffer(vout
->buf_virt_addr
[i
],
1990 vout
->buf_virt_addr
[i
] = 0;
1991 vout
->buf_phy_addr
[i
] = 0;
1997 /* Create video out devices */
1998 static int __init
omap_vout_create_video_devices(struct platform_device
*pdev
)
2001 struct omap_vout_device
*vout
;
2002 struct video_device
*vfd
= NULL
;
2003 struct v4l2_device
*v4l2_dev
= platform_get_drvdata(pdev
);
2004 struct omap2video_device
*vid_dev
= container_of(v4l2_dev
,
2005 struct omap2video_device
, v4l2_dev
);
2007 for (k
= 0; k
< pdev
->num_resources
; k
++) {
2009 vout
= kzalloc(sizeof(struct omap_vout_device
), GFP_KERNEL
);
2011 dev_err(&pdev
->dev
, ": could not allocate memory\n");
2016 vid_dev
->vouts
[k
] = vout
;
2017 vout
->vid_dev
= vid_dev
;
2018 /* Select video2 if only 1 overlay is controlled by V4L2 */
2019 if (pdev
->num_resources
== 1)
2020 vout
->vid_info
.overlays
[0] = vid_dev
->overlays
[k
+ 2];
2022 /* Else select video1 and video2 one by one. */
2023 vout
->vid_info
.overlays
[0] = vid_dev
->overlays
[k
+ 1];
2024 vout
->vid_info
.num_overlays
= 1;
2025 vout
->vid_info
.id
= k
+ 1;
2027 /* Set VRFB as rotation_type for omap2 and omap3 */
2028 if (omap_vout_dss_omap24xx() || omap_vout_dss_omap34xx())
2029 vout
->vid_info
.rotation_type
= VOUT_ROT_VRFB
;
2031 /* Setup the default configuration for the video devices
2033 if (omap_vout_setup_video_data(vout
) != 0) {
2038 /* Allocate default number of buffers for the video streaming
2039 * and reserve the VRFB space for rotation
2041 if (omap_vout_setup_video_bufs(pdev
, k
) != 0) {
2046 /* Register the Video device with V4L2
2049 if (video_register_device(vfd
, VFL_TYPE_GRABBER
, -1) < 0) {
2050 dev_err(&pdev
->dev
, ": Could not register "
2051 "Video for Linux device\n");
2056 video_set_drvdata(vfd
, vout
);
2058 dev_info(&pdev
->dev
, ": registered and initialized"
2059 " video device %d\n", vfd
->minor
);
2060 if (k
== (pdev
->num_resources
- 1))
2065 if (vout
->vid_info
.rotation_type
== VOUT_ROT_VRFB
)
2066 omap_vout_release_vrfb(vout
);
2067 omap_vout_free_buffers(vout
);
2069 video_device_release(vfd
);
2077 /* Driver functions */
2078 static void omap_vout_cleanup_device(struct omap_vout_device
*vout
)
2080 struct video_device
*vfd
;
2081 struct omapvideo_info
*ovid
;
2087 ovid
= &vout
->vid_info
;
2089 if (!video_is_registered(vfd
)) {
2091 * The device was never registered, so release the
2092 * video_device struct directly.
2094 video_device_release(vfd
);
2097 * The unregister function will release the video_device
2098 * struct as well as unregistering it.
2100 video_unregister_device(vfd
);
2103 if (ovid
->rotation_type
== VOUT_ROT_VRFB
) {
2104 omap_vout_release_vrfb(vout
);
2105 /* Free the VRFB buffer if allocated
2108 if (vout
->vrfb_static_allocation
)
2109 omap_vout_free_vrfb_buffers(vout
);
2111 omap_vout_free_buffers(vout
);
2116 static int omap_vout_remove(struct platform_device
*pdev
)
2119 struct v4l2_device
*v4l2_dev
= platform_get_drvdata(pdev
);
2120 struct omap2video_device
*vid_dev
= container_of(v4l2_dev
, struct
2121 omap2video_device
, v4l2_dev
);
2123 v4l2_device_unregister(v4l2_dev
);
2124 for (k
= 0; k
< pdev
->num_resources
; k
++)
2125 omap_vout_cleanup_device(vid_dev
->vouts
[k
]);
2127 for (k
= 0; k
< vid_dev
->num_displays
; k
++) {
2128 if (vid_dev
->displays
[k
]->state
!= OMAP_DSS_DISPLAY_DISABLED
)
2129 vid_dev
->displays
[k
]->driver
->disable(vid_dev
->displays
[k
]);
2131 omap_dss_put_device(vid_dev
->displays
[k
]);
2137 static int __init
omap_vout_probe(struct platform_device
*pdev
)
2140 struct omap_overlay
*ovl
;
2141 struct omap_dss_device
*dssdev
= NULL
;
2142 struct omap_dss_device
*def_display
;
2143 struct omap2video_device
*vid_dev
= NULL
;
2145 ret
= omapdss_compat_init();
2147 dev_err(&pdev
->dev
, "failed to init dss\n");
2151 if (pdev
->num_resources
== 0) {
2152 dev_err(&pdev
->dev
, "probed for an unknown device\n");
2157 vid_dev
= kzalloc(sizeof(struct omap2video_device
), GFP_KERNEL
);
2158 if (vid_dev
== NULL
) {
2163 vid_dev
->num_displays
= 0;
2164 for_each_dss_dev(dssdev
) {
2165 omap_dss_get_device(dssdev
);
2167 if (!dssdev
->driver
) {
2168 dev_warn(&pdev
->dev
, "no driver for display: %s\n",
2170 omap_dss_put_device(dssdev
);
2174 vid_dev
->displays
[vid_dev
->num_displays
++] = dssdev
;
2177 if (vid_dev
->num_displays
== 0) {
2178 dev_err(&pdev
->dev
, "no displays\n");
2183 vid_dev
->num_overlays
= omap_dss_get_num_overlays();
2184 for (i
= 0; i
< vid_dev
->num_overlays
; i
++)
2185 vid_dev
->overlays
[i
] = omap_dss_get_overlay(i
);
2187 vid_dev
->num_managers
= omap_dss_get_num_overlay_managers();
2188 for (i
= 0; i
< vid_dev
->num_managers
; i
++)
2189 vid_dev
->managers
[i
] = omap_dss_get_overlay_manager(i
);
2191 /* Get the Video1 overlay and video2 overlay.
2192 * Setup the Display attached to that overlays
2194 for (i
= 1; i
< vid_dev
->num_overlays
; i
++) {
2195 ovl
= omap_dss_get_overlay(i
);
2196 dssdev
= ovl
->get_device(ovl
);
2199 def_display
= dssdev
;
2201 dev_warn(&pdev
->dev
, "cannot find display\n");
2205 struct omap_dss_driver
*dssdrv
= def_display
->driver
;
2207 ret
= dssdrv
->enable(def_display
);
2209 /* Here we are not considering a error
2210 * as display may be enabled by frame
2213 dev_warn(&pdev
->dev
,
2214 "'%s' Display already enabled\n",
2220 if (v4l2_device_register(&pdev
->dev
, &vid_dev
->v4l2_dev
) < 0) {
2221 dev_err(&pdev
->dev
, "v4l2_device_register failed\n");
2226 ret
= omap_vout_create_video_devices(pdev
);
2230 for (i
= 0; i
< vid_dev
->num_displays
; i
++) {
2231 struct omap_dss_device
*display
= vid_dev
->displays
[i
];
2233 if (display
->driver
->update
)
2234 display
->driver
->update(display
, 0, 0,
2235 display
->panel
.timings
.x_res
,
2236 display
->panel
.timings
.y_res
);
2241 v4l2_device_unregister(&vid_dev
->v4l2_dev
);
2243 for (i
= 1; i
< vid_dev
->num_overlays
; i
++) {
2245 ovl
= omap_dss_get_overlay(i
);
2246 dssdev
= ovl
->get_device(ovl
);
2249 def_display
= dssdev
;
2251 if (def_display
&& def_display
->driver
)
2252 def_display
->driver
->disable(def_display
);
2257 omapdss_compat_uninit();
2261 static struct platform_driver omap_vout_driver
= {
2265 .remove
= omap_vout_remove
,
2268 static int __init
omap_vout_init(void)
2270 if (platform_driver_probe(&omap_vout_driver
, omap_vout_probe
) != 0) {
2271 printk(KERN_ERR VOUT_NAME
":Could not register Video driver\n");
2277 static void omap_vout_cleanup(void)
2279 platform_driver_unregister(&omap_vout_driver
);
2282 late_initcall(omap_vout_init
);
2283 module_exit(omap_vout_cleanup
);