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>
42 #include <media/videobuf-dma-contig.h>
43 #include <media/v4l2-device.h>
44 #include <media/v4l2-ioctl.h>
47 #include <plat/vrfb.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 u32 vid1_static_vrfb_alloc
;
73 static u32 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
);
404 info
.width
= cropwidth
;
405 info
.height
= cropheight
;
406 info
.color_mode
= vout
->dss_mode
;
407 info
.mirror
= vout
->mirror
;
410 info
.out_width
= outw
;
411 info
.out_height
= outh
;
412 info
.global_alpha
= vout
->win
.global_alpha
;
413 if (!is_rotation_enabled(vout
)) {
415 info
.rotation_type
= OMAP_DSS_ROT_DMA
;
416 info
.screen_width
= pixwidth
;
418 info
.rotation
= vout
->rotation
;
419 info
.rotation_type
= OMAP_DSS_ROT_VRFB
;
420 info
.screen_width
= 2048;
423 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
424 "%s enable=%d addr=%x width=%d\n height=%d color_mode=%d\n"
425 "rotation=%d mirror=%d posx=%d posy=%d out_width = %d \n"
426 "out_height=%d rotation_type=%d screen_width=%d\n",
427 __func__
, info
.enabled
, info
.paddr
, info
.width
, info
.height
,
428 info
.color_mode
, info
.rotation
, info
.mirror
, info
.pos_x
,
429 info
.pos_y
, info
.out_width
, info
.out_height
, info
.rotation_type
,
432 ret
= ovl
->set_overlay_info(ovl
, &info
);
439 v4l2_warn(&vout
->vid_dev
->v4l2_dev
, "setup_overlay failed\n");
444 * Initialize the overlay structure
446 static int omapvid_init(struct omap_vout_device
*vout
, u32 addr
)
449 struct v4l2_window
*win
;
450 struct omap_overlay
*ovl
;
451 int posx
, posy
, outw
, outh
, temp
;
452 struct omap_video_timings
*timing
;
453 struct omapvideo_info
*ovid
= &vout
->vid_info
;
456 for (i
= 0; i
< ovid
->num_overlays
; i
++) {
457 ovl
= ovid
->overlays
[i
];
458 if (!ovl
->manager
|| !ovl
->manager
->device
)
461 timing
= &ovl
->manager
->device
->panel
.timings
;
464 outh
= win
->w
.height
;
465 switch (vout
->rotation
) {
466 case dss_rotation_90_degree
:
467 /* Invert the height and width for 90
468 * and 270 degree rotation
473 posy
= (timing
->y_res
- win
->w
.width
) - win
->w
.left
;
477 case dss_rotation_180_degree
:
478 posx
= (timing
->x_res
- win
->w
.width
) - win
->w
.left
;
479 posy
= (timing
->y_res
- win
->w
.height
) - win
->w
.top
;
482 case dss_rotation_270_degree
:
487 posx
= (timing
->x_res
- win
->w
.height
) - win
->w
.top
;
496 ret
= omapvid_setup_overlay(vout
, ovl
, posx
, posy
,
499 goto omapvid_init_err
;
504 v4l2_warn(&vout
->vid_dev
->v4l2_dev
, "apply_changes failed\n");
509 * Apply the changes set the go bit of DSS
511 static int omapvid_apply_changes(struct omap_vout_device
*vout
)
514 struct omap_overlay
*ovl
;
515 struct omapvideo_info
*ovid
= &vout
->vid_info
;
517 for (i
= 0; i
< ovid
->num_overlays
; i
++) {
518 ovl
= ovid
->overlays
[i
];
519 if (!ovl
->manager
|| !ovl
->manager
->device
)
521 ovl
->manager
->apply(ovl
->manager
);
527 static void omap_vout_isr(void *arg
, unsigned int irqstatus
)
531 struct omap_overlay
*ovl
;
532 struct timeval timevalue
;
533 struct omapvideo_info
*ovid
;
534 struct omap_dss_device
*cur_display
;
535 struct omap_vout_device
*vout
= (struct omap_vout_device
*)arg
;
537 if (!vout
->streaming
)
540 ovid
= &vout
->vid_info
;
541 ovl
= ovid
->overlays
[0];
542 /* get the display device attached to the overlay */
543 if (!ovl
->manager
|| !ovl
->manager
->device
)
546 cur_display
= ovl
->manager
->device
;
548 spin_lock(&vout
->vbq_lock
);
549 do_gettimeofday(&timevalue
);
551 if (cur_display
->type
!= OMAP_DISPLAY_TYPE_VENC
) {
552 switch (cur_display
->type
) {
553 case OMAP_DISPLAY_TYPE_DPI
:
554 if (!(irqstatus
& (DISPC_IRQ_VSYNC
| DISPC_IRQ_VSYNC2
)))
557 case OMAP_DISPLAY_TYPE_HDMI
:
558 if (!(irqstatus
& DISPC_IRQ_EVSYNC_EVEN
))
564 if (!vout
->first_int
&& (vout
->cur_frm
!= vout
->next_frm
)) {
565 vout
->cur_frm
->ts
= timevalue
;
566 vout
->cur_frm
->state
= VIDEOBUF_DONE
;
567 wake_up_interruptible(&vout
->cur_frm
->done
);
568 vout
->cur_frm
= vout
->next_frm
;
571 if (list_empty(&vout
->dma_queue
))
574 vout
->next_frm
= list_entry(vout
->dma_queue
.next
,
575 struct videobuf_buffer
, queue
);
576 list_del(&vout
->next_frm
->queue
);
578 vout
->next_frm
->state
= VIDEOBUF_ACTIVE
;
580 addr
= (unsigned long) vout
->queued_buf_addr
[vout
->next_frm
->i
]
581 + vout
->cropped_offset
;
583 /* First save the configuration in ovelray structure */
584 ret
= omapvid_init(vout
, addr
);
586 printk(KERN_ERR VOUT_NAME
587 "failed to set overlay info\n");
588 /* Enable the pipeline and set the Go bit */
589 ret
= omapvid_apply_changes(vout
);
591 printk(KERN_ERR VOUT_NAME
"failed to change mode\n");
594 if (vout
->first_int
) {
598 if (irqstatus
& DISPC_IRQ_EVSYNC_ODD
)
600 else if (irqstatus
& DISPC_IRQ_EVSYNC_EVEN
)
606 if (fid
!= vout
->field_id
) {
608 vout
->field_id
= fid
;
613 if (vout
->cur_frm
== vout
->next_frm
)
616 vout
->cur_frm
->ts
= timevalue
;
617 vout
->cur_frm
->state
= VIDEOBUF_DONE
;
618 wake_up_interruptible(&vout
->cur_frm
->done
);
619 vout
->cur_frm
= vout
->next_frm
;
620 } else if (1 == fid
) {
621 if (list_empty(&vout
->dma_queue
) ||
622 (vout
->cur_frm
!= vout
->next_frm
))
625 vout
->next_frm
= list_entry(vout
->dma_queue
.next
,
626 struct videobuf_buffer
, queue
);
627 list_del(&vout
->next_frm
->queue
);
629 vout
->next_frm
->state
= VIDEOBUF_ACTIVE
;
630 addr
= (unsigned long)
631 vout
->queued_buf_addr
[vout
->next_frm
->i
] +
632 vout
->cropped_offset
;
633 /* First save the configuration in ovelray structure */
634 ret
= omapvid_init(vout
, addr
);
636 printk(KERN_ERR VOUT_NAME
637 "failed to set overlay info\n");
638 /* Enable the pipeline and set the Go bit */
639 ret
= omapvid_apply_changes(vout
);
641 printk(KERN_ERR VOUT_NAME
642 "failed to change mode\n");
648 spin_unlock(&vout
->vbq_lock
);
652 /* Video buffer call backs */
655 * Buffer setup function is called by videobuf layer when REQBUF ioctl is
656 * called. This is used to setup buffers and return size and count of
657 * buffers allocated. After the call to this buffer, videobuf layer will
658 * setup buffer queue depending on the size and count of buffers
660 static int omap_vout_buffer_setup(struct videobuf_queue
*q
, unsigned int *count
,
663 int startindex
= 0, i
, j
;
664 u32 phy_addr
= 0, virt_addr
= 0;
665 struct omap_vout_device
*vout
= q
->priv_data
;
666 struct omapvideo_info
*ovid
= &vout
->vid_info
;
671 if (V4L2_BUF_TYPE_VIDEO_OUTPUT
!= q
->type
)
674 startindex
= (vout
->vid
== OMAP_VIDEO1
) ?
675 video1_numbuffers
: video2_numbuffers
;
676 if (V4L2_MEMORY_MMAP
== vout
->memory
&& *count
< startindex
)
679 if (ovid
->rotation_type
== VOUT_ROT_VRFB
) {
680 if (omap_vout_vrfb_buffer_setup(vout
, count
, startindex
))
684 if (V4L2_MEMORY_MMAP
!= vout
->memory
)
687 /* Now allocated the V4L2 buffers */
688 *size
= PAGE_ALIGN(vout
->pix
.width
* vout
->pix
.height
* vout
->bpp
);
689 startindex
= (vout
->vid
== OMAP_VIDEO1
) ?
690 video1_numbuffers
: video2_numbuffers
;
692 /* Check the size of the buffer */
693 if (*size
> vout
->buffer_size
) {
694 v4l2_err(&vout
->vid_dev
->v4l2_dev
,
695 "buffer allocation mismatch [%u] [%u]\n",
696 *size
, vout
->buffer_size
);
700 for (i
= startindex
; i
< *count
; i
++) {
701 vout
->buffer_size
= *size
;
703 virt_addr
= omap_vout_alloc_buffer(vout
->buffer_size
,
706 if (ovid
->rotation_type
== VOUT_ROT_NONE
) {
709 if (!is_rotation_enabled(vout
))
711 /* Free the VRFB buffers if no space for V4L2 buffers */
712 for (j
= i
; j
< *count
; j
++) {
713 omap_vout_free_buffer(
714 vout
->smsshado_virt_addr
[j
],
715 vout
->smsshado_size
);
716 vout
->smsshado_virt_addr
[j
] = 0;
717 vout
->smsshado_phy_addr
[j
] = 0;
721 vout
->buf_virt_addr
[i
] = virt_addr
;
722 vout
->buf_phy_addr
[i
] = phy_addr
;
724 *count
= vout
->buffer_allocated
= i
;
730 * Free the V4L2 buffers additionally allocated than default
733 static void omap_vout_free_extra_buffers(struct omap_vout_device
*vout
)
735 int num_buffers
= 0, i
;
737 num_buffers
= (vout
->vid
== OMAP_VIDEO1
) ?
738 video1_numbuffers
: video2_numbuffers
;
740 for (i
= num_buffers
; i
< vout
->buffer_allocated
; i
++) {
741 if (vout
->buf_virt_addr
[i
])
742 omap_vout_free_buffer(vout
->buf_virt_addr
[i
],
745 vout
->buf_virt_addr
[i
] = 0;
746 vout
->buf_phy_addr
[i
] = 0;
748 vout
->buffer_allocated
= num_buffers
;
752 * This function will be called when VIDIOC_QBUF ioctl is called.
753 * It prepare buffers before give out for the display. This function
754 * converts user space virtual address into physical address if userptr memory
755 * exchange mechanism is used. If rotation is enabled, it copies entire
756 * buffer into VRFB memory space before giving it to the DSS.
758 static int omap_vout_buffer_prepare(struct videobuf_queue
*q
,
759 struct videobuf_buffer
*vb
,
760 enum v4l2_field field
)
762 struct omap_vout_device
*vout
= q
->priv_data
;
763 struct omapvideo_info
*ovid
= &vout
->vid_info
;
765 if (VIDEOBUF_NEEDS_INIT
== vb
->state
) {
766 vb
->width
= vout
->pix
.width
;
767 vb
->height
= vout
->pix
.height
;
768 vb
->size
= vb
->width
* vb
->height
* vout
->bpp
;
771 vb
->state
= VIDEOBUF_PREPARED
;
772 /* if user pointer memory mechanism is used, get the physical
773 * address of the buffer
775 if (V4L2_MEMORY_USERPTR
== vb
->memory
) {
778 /* Physical address */
779 vout
->queued_buf_addr
[vb
->i
] = (u8
*)
780 omap_vout_uservirt_to_phys(vb
->baddr
);
785 addr
= (unsigned long) vout
->buf_virt_addr
[vb
->i
];
786 size
= (unsigned long) vb
->size
;
788 dma_addr
= dma_map_single(vout
->vid_dev
->v4l2_dev
.dev
, (void *) addr
,
789 size
, DMA_TO_DEVICE
);
790 if (dma_mapping_error(vout
->vid_dev
->v4l2_dev
.dev
, dma_addr
))
791 v4l2_err(&vout
->vid_dev
->v4l2_dev
, "dma_map_single failed\n");
793 vout
->queued_buf_addr
[vb
->i
] = (u8
*)vout
->buf_phy_addr
[vb
->i
];
796 if (ovid
->rotation_type
== VOUT_ROT_VRFB
)
797 return omap_vout_prepare_vrfb(vout
, vb
);
803 * Buffer queue function will be called from the videobuf layer when _QBUF
804 * ioctl is called. It is used to enqueue buffer, which is ready to be
807 static void omap_vout_buffer_queue(struct videobuf_queue
*q
,
808 struct videobuf_buffer
*vb
)
810 struct omap_vout_device
*vout
= q
->priv_data
;
812 /* Driver is also maintainig a queue. So enqueue buffer in the driver
814 list_add_tail(&vb
->queue
, &vout
->dma_queue
);
816 vb
->state
= VIDEOBUF_QUEUED
;
820 * Buffer release function is called from videobuf layer to release buffer
821 * which are already allocated
823 static void omap_vout_buffer_release(struct videobuf_queue
*q
,
824 struct videobuf_buffer
*vb
)
826 struct omap_vout_device
*vout
= q
->priv_data
;
828 vb
->state
= VIDEOBUF_NEEDS_INIT
;
830 if (V4L2_MEMORY_MMAP
!= vout
->memory
)
837 static void omap_vout_vm_open(struct vm_area_struct
*vma
)
839 struct omap_vout_device
*vout
= vma
->vm_private_data
;
841 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
842 "vm_open [vma=%08lx-%08lx]\n", vma
->vm_start
, vma
->vm_end
);
846 static void omap_vout_vm_close(struct vm_area_struct
*vma
)
848 struct omap_vout_device
*vout
= vma
->vm_private_data
;
850 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
851 "vm_close [vma=%08lx-%08lx]\n", vma
->vm_start
, vma
->vm_end
);
855 static struct vm_operations_struct omap_vout_vm_ops
= {
856 .open
= omap_vout_vm_open
,
857 .close
= omap_vout_vm_close
,
860 static int omap_vout_mmap(struct file
*file
, struct vm_area_struct
*vma
)
864 unsigned long start
= vma
->vm_start
;
865 unsigned long size
= (vma
->vm_end
- vma
->vm_start
);
866 struct omap_vout_device
*vout
= file
->private_data
;
867 struct videobuf_queue
*q
= &vout
->vbq
;
869 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
870 " %s pgoff=0x%lx, start=0x%lx, end=0x%lx\n", __func__
,
871 vma
->vm_pgoff
, vma
->vm_start
, vma
->vm_end
);
873 /* look for the buffer to map */
874 for (i
= 0; i
< VIDEO_MAX_FRAME
; i
++) {
875 if (NULL
== q
->bufs
[i
])
877 if (V4L2_MEMORY_MMAP
!= q
->bufs
[i
]->memory
)
879 if (q
->bufs
[i
]->boff
== (vma
->vm_pgoff
<< PAGE_SHIFT
))
883 if (VIDEO_MAX_FRAME
== i
) {
884 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
885 "offset invalid [offset=0x%lx]\n",
886 (vma
->vm_pgoff
<< PAGE_SHIFT
));
889 /* Check the size of the buffer */
890 if (size
> vout
->buffer_size
) {
891 v4l2_err(&vout
->vid_dev
->v4l2_dev
,
892 "insufficient memory [%lu] [%u]\n",
893 size
, vout
->buffer_size
);
897 q
->bufs
[i
]->baddr
= vma
->vm_start
;
899 vma
->vm_flags
|= VM_RESERVED
;
900 vma
->vm_page_prot
= pgprot_writecombine(vma
->vm_page_prot
);
901 vma
->vm_ops
= &omap_vout_vm_ops
;
902 vma
->vm_private_data
= (void *) vout
;
903 pos
= (void *)vout
->buf_virt_addr
[i
];
904 vma
->vm_pgoff
= virt_to_phys((void *)pos
) >> PAGE_SHIFT
;
907 pfn
= virt_to_phys((void *) pos
) >> PAGE_SHIFT
;
908 if (remap_pfn_range(vma
, start
, pfn
, PAGE_SIZE
, PAGE_SHARED
))
915 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Exiting %s\n", __func__
);
920 static int omap_vout_release(struct file
*file
)
923 struct videobuf_queue
*q
;
924 struct omapvideo_info
*ovid
;
925 struct omap_vout_device
*vout
= file
->private_data
;
927 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Entering %s\n", __func__
);
928 ovid
= &vout
->vid_info
;
934 /* Disable all the overlay managers connected with this interface */
935 for (i
= 0; i
< ovid
->num_overlays
; i
++) {
936 struct omap_overlay
*ovl
= ovid
->overlays
[i
];
937 if (ovl
->manager
&& ovl
->manager
->device
) {
938 struct omap_overlay_info info
;
939 ovl
->get_overlay_info(ovl
, &info
);
941 ovl
->set_overlay_info(ovl
, &info
);
944 /* Turn off the pipeline */
945 ret
= omapvid_apply_changes(vout
);
947 v4l2_warn(&vout
->vid_dev
->v4l2_dev
,
948 "Unable to apply changes\n");
950 /* Free all buffers */
951 omap_vout_free_extra_buffers(vout
);
953 /* Free the VRFB buffers only if they are allocated
954 * during reqbufs. Don't free if init time allocated
956 if (ovid
->rotation_type
== VOUT_ROT_VRFB
) {
957 if (!vout
->vrfb_static_allocation
)
958 omap_vout_free_vrfb_buffers(vout
);
960 videobuf_mmap_free(q
);
962 /* Even if apply changes fails we should continue
963 freeing allocated memory */
964 if (vout
->streaming
) {
967 mask
= DISPC_IRQ_VSYNC
| DISPC_IRQ_EVSYNC_EVEN
|
968 DISPC_IRQ_EVSYNC_ODD
| DISPC_IRQ_VSYNC2
;
969 omap_dispc_unregister_isr(omap_vout_isr
, vout
, mask
);
972 videobuf_streamoff(q
);
973 videobuf_queue_cancel(q
);
976 if (vout
->mmap_count
!= 0)
977 vout
->mmap_count
= 0;
980 file
->private_data
= NULL
;
982 if (vout
->buffer_allocated
)
983 videobuf_mmap_free(q
);
985 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Exiting %s\n", __func__
);
989 static int omap_vout_open(struct file
*file
)
991 struct videobuf_queue
*q
;
992 struct omap_vout_device
*vout
= NULL
;
994 vout
= video_drvdata(file
);
995 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Entering %s\n", __func__
);
1000 /* for now, we only support single open */
1006 file
->private_data
= vout
;
1007 vout
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
1010 video_vbq_ops
.buf_setup
= omap_vout_buffer_setup
;
1011 video_vbq_ops
.buf_prepare
= omap_vout_buffer_prepare
;
1012 video_vbq_ops
.buf_release
= omap_vout_buffer_release
;
1013 video_vbq_ops
.buf_queue
= omap_vout_buffer_queue
;
1014 spin_lock_init(&vout
->vbq_lock
);
1016 videobuf_queue_dma_contig_init(q
, &video_vbq_ops
, q
->dev
,
1017 &vout
->vbq_lock
, vout
->type
, V4L2_FIELD_NONE
,
1018 sizeof(struct videobuf_buffer
), vout
, NULL
);
1020 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Exiting %s\n", __func__
);
1027 static int vidioc_querycap(struct file
*file
, void *fh
,
1028 struct v4l2_capability
*cap
)
1030 struct omap_vout_device
*vout
= fh
;
1032 strlcpy(cap
->driver
, VOUT_NAME
, sizeof(cap
->driver
));
1033 strlcpy(cap
->card
, vout
->vfd
->name
, sizeof(cap
->card
));
1034 cap
->bus_info
[0] = '\0';
1035 cap
->capabilities
= V4L2_CAP_STREAMING
| V4L2_CAP_VIDEO_OUTPUT
;
1040 static int vidioc_enum_fmt_vid_out(struct file
*file
, void *fh
,
1041 struct v4l2_fmtdesc
*fmt
)
1043 int index
= fmt
->index
;
1045 if (index
>= NUM_OUTPUT_FORMATS
)
1048 fmt
->flags
= omap_formats
[index
].flags
;
1049 strlcpy(fmt
->description
, omap_formats
[index
].description
,
1050 sizeof(fmt
->description
));
1051 fmt
->pixelformat
= omap_formats
[index
].pixelformat
;
1056 static int vidioc_g_fmt_vid_out(struct file
*file
, void *fh
,
1057 struct v4l2_format
*f
)
1059 struct omap_vout_device
*vout
= fh
;
1061 f
->fmt
.pix
= vout
->pix
;
1066 static int vidioc_try_fmt_vid_out(struct file
*file
, void *fh
,
1067 struct v4l2_format
*f
)
1069 struct omap_overlay
*ovl
;
1070 struct omapvideo_info
*ovid
;
1071 struct omap_video_timings
*timing
;
1072 struct omap_vout_device
*vout
= fh
;
1074 ovid
= &vout
->vid_info
;
1075 ovl
= ovid
->overlays
[0];
1077 if (!ovl
->manager
|| !ovl
->manager
->device
)
1079 /* get the display device attached to the overlay */
1080 timing
= &ovl
->manager
->device
->panel
.timings
;
1082 vout
->fbuf
.fmt
.height
= timing
->y_res
;
1083 vout
->fbuf
.fmt
.width
= timing
->x_res
;
1085 omap_vout_try_format(&f
->fmt
.pix
);
1089 static int vidioc_s_fmt_vid_out(struct file
*file
, void *fh
,
1090 struct v4l2_format
*f
)
1093 struct omap_overlay
*ovl
;
1094 struct omapvideo_info
*ovid
;
1095 struct omap_video_timings
*timing
;
1096 struct omap_vout_device
*vout
= fh
;
1098 if (vout
->streaming
)
1101 mutex_lock(&vout
->lock
);
1103 ovid
= &vout
->vid_info
;
1104 ovl
= ovid
->overlays
[0];
1106 /* get the display device attached to the overlay */
1107 if (!ovl
->manager
|| !ovl
->manager
->device
) {
1109 goto s_fmt_vid_out_exit
;
1111 timing
= &ovl
->manager
->device
->panel
.timings
;
1113 /* We dont support RGB24-packed mode if vrfb rotation
1115 if ((is_rotation_enabled(vout
)) &&
1116 f
->fmt
.pix
.pixelformat
== V4L2_PIX_FMT_RGB24
) {
1118 goto s_fmt_vid_out_exit
;
1121 /* get the framebuffer parameters */
1123 if (is_rotation_90_or_270(vout
)) {
1124 vout
->fbuf
.fmt
.height
= timing
->x_res
;
1125 vout
->fbuf
.fmt
.width
= timing
->y_res
;
1127 vout
->fbuf
.fmt
.height
= timing
->y_res
;
1128 vout
->fbuf
.fmt
.width
= timing
->x_res
;
1131 /* change to samller size is OK */
1133 bpp
= omap_vout_try_format(&f
->fmt
.pix
);
1134 f
->fmt
.pix
.sizeimage
= f
->fmt
.pix
.width
* f
->fmt
.pix
.height
* bpp
;
1136 /* try & set the new output format */
1138 vout
->pix
= f
->fmt
.pix
;
1141 /* If YUYV then vrfb bpp is 2, for others its 1 */
1142 if (V4L2_PIX_FMT_YUYV
== vout
->pix
.pixelformat
||
1143 V4L2_PIX_FMT_UYVY
== vout
->pix
.pixelformat
)
1146 /* set default crop and win */
1147 omap_vout_new_format(&vout
->pix
, &vout
->fbuf
, &vout
->crop
, &vout
->win
);
1149 /* Save the changes in the overlay strcuture */
1150 ret
= omapvid_init(vout
, 0);
1152 v4l2_err(&vout
->vid_dev
->v4l2_dev
, "failed to change mode\n");
1153 goto s_fmt_vid_out_exit
;
1159 mutex_unlock(&vout
->lock
);
1163 static int vidioc_try_fmt_vid_overlay(struct file
*file
, void *fh
,
1164 struct v4l2_format
*f
)
1167 struct omap_vout_device
*vout
= fh
;
1168 struct v4l2_window
*win
= &f
->fmt
.win
;
1170 ret
= omap_vout_try_window(&vout
->fbuf
, win
);
1173 if (vout
->vid
== OMAP_VIDEO1
)
1174 win
->global_alpha
= 255;
1176 win
->global_alpha
= f
->fmt
.win
.global_alpha
;
1182 static int vidioc_s_fmt_vid_overlay(struct file
*file
, void *fh
,
1183 struct v4l2_format
*f
)
1186 struct omap_overlay
*ovl
;
1187 struct omapvideo_info
*ovid
;
1188 struct omap_vout_device
*vout
= fh
;
1189 struct v4l2_window
*win
= &f
->fmt
.win
;
1191 mutex_lock(&vout
->lock
);
1192 ovid
= &vout
->vid_info
;
1193 ovl
= ovid
->overlays
[0];
1195 ret
= omap_vout_new_window(&vout
->crop
, &vout
->win
, &vout
->fbuf
, win
);
1197 /* Video1 plane does not support global alpha */
1198 if (ovl
->id
== OMAP_DSS_VIDEO1
)
1199 vout
->win
.global_alpha
= 255;
1201 vout
->win
.global_alpha
= f
->fmt
.win
.global_alpha
;
1203 vout
->win
.chromakey
= f
->fmt
.win
.chromakey
;
1205 mutex_unlock(&vout
->lock
);
1209 static int vidioc_enum_fmt_vid_overlay(struct file
*file
, void *fh
,
1210 struct v4l2_fmtdesc
*fmt
)
1212 int index
= fmt
->index
;
1214 if (index
>= NUM_OUTPUT_FORMATS
)
1217 fmt
->flags
= omap_formats
[index
].flags
;
1218 strlcpy(fmt
->description
, omap_formats
[index
].description
,
1219 sizeof(fmt
->description
));
1220 fmt
->pixelformat
= omap_formats
[index
].pixelformat
;
1224 static int vidioc_g_fmt_vid_overlay(struct file
*file
, void *fh
,
1225 struct v4l2_format
*f
)
1228 struct omap_overlay
*ovl
;
1229 struct omapvideo_info
*ovid
;
1230 struct omap_vout_device
*vout
= fh
;
1231 struct omap_overlay_manager_info info
;
1232 struct v4l2_window
*win
= &f
->fmt
.win
;
1234 ovid
= &vout
->vid_info
;
1235 ovl
= ovid
->overlays
[0];
1237 win
->w
= vout
->win
.w
;
1238 win
->field
= vout
->win
.field
;
1239 win
->global_alpha
= vout
->win
.global_alpha
;
1241 if (ovl
->manager
&& ovl
->manager
->get_manager_info
) {
1242 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1243 key_value
= info
.trans_key
;
1245 win
->chromakey
= key_value
;
1249 static int vidioc_cropcap(struct file
*file
, void *fh
,
1250 struct v4l2_cropcap
*cropcap
)
1252 struct omap_vout_device
*vout
= fh
;
1253 struct v4l2_pix_format
*pix
= &vout
->pix
;
1255 if (cropcap
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1258 /* Width and height are always even */
1259 cropcap
->bounds
.width
= pix
->width
& ~1;
1260 cropcap
->bounds
.height
= pix
->height
& ~1;
1262 omap_vout_default_crop(&vout
->pix
, &vout
->fbuf
, &cropcap
->defrect
);
1263 cropcap
->pixelaspect
.numerator
= 1;
1264 cropcap
->pixelaspect
.denominator
= 1;
1268 static int vidioc_g_crop(struct file
*file
, void *fh
, struct v4l2_crop
*crop
)
1270 struct omap_vout_device
*vout
= fh
;
1272 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1274 crop
->c
= vout
->crop
;
1278 static int vidioc_s_crop(struct file
*file
, void *fh
, struct v4l2_crop
*crop
)
1281 struct omap_vout_device
*vout
= fh
;
1282 struct omapvideo_info
*ovid
;
1283 struct omap_overlay
*ovl
;
1284 struct omap_video_timings
*timing
;
1286 if (vout
->streaming
)
1289 mutex_lock(&vout
->lock
);
1290 ovid
= &vout
->vid_info
;
1291 ovl
= ovid
->overlays
[0];
1293 if (!ovl
->manager
|| !ovl
->manager
->device
) {
1297 /* get the display device attached to the overlay */
1298 timing
= &ovl
->manager
->device
->panel
.timings
;
1300 if (is_rotation_90_or_270(vout
)) {
1301 vout
->fbuf
.fmt
.height
= timing
->x_res
;
1302 vout
->fbuf
.fmt
.width
= timing
->y_res
;
1304 vout
->fbuf
.fmt
.height
= timing
->y_res
;
1305 vout
->fbuf
.fmt
.width
= timing
->x_res
;
1308 if (crop
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1309 ret
= omap_vout_new_crop(&vout
->pix
, &vout
->crop
, &vout
->win
,
1310 &vout
->fbuf
, &crop
->c
);
1313 mutex_unlock(&vout
->lock
);
1317 static int vidioc_queryctrl(struct file
*file
, void *fh
,
1318 struct v4l2_queryctrl
*ctrl
)
1323 case V4L2_CID_ROTATE
:
1324 ret
= v4l2_ctrl_query_fill(ctrl
, 0, 270, 90, 0);
1326 case V4L2_CID_BG_COLOR
:
1327 ret
= v4l2_ctrl_query_fill(ctrl
, 0, 0xFFFFFF, 1, 0);
1329 case V4L2_CID_VFLIP
:
1330 ret
= v4l2_ctrl_query_fill(ctrl
, 0, 1, 1, 0);
1333 ctrl
->name
[0] = '\0';
1339 static int vidioc_g_ctrl(struct file
*file
, void *fh
, struct v4l2_control
*ctrl
)
1342 struct omap_vout_device
*vout
= fh
;
1345 case V4L2_CID_ROTATE
:
1346 ctrl
->value
= vout
->control
[0].value
;
1348 case V4L2_CID_BG_COLOR
:
1350 struct omap_overlay_manager_info info
;
1351 struct omap_overlay
*ovl
;
1353 ovl
= vout
->vid_info
.overlays
[0];
1354 if (!ovl
->manager
|| !ovl
->manager
->get_manager_info
) {
1359 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1360 ctrl
->value
= info
.default_color
;
1363 case V4L2_CID_VFLIP
:
1364 ctrl
->value
= vout
->control
[2].value
;
1372 static int vidioc_s_ctrl(struct file
*file
, void *fh
, struct v4l2_control
*a
)
1375 struct omap_vout_device
*vout
= fh
;
1378 case V4L2_CID_ROTATE
:
1380 struct omapvideo_info
*ovid
;
1381 int rotation
= a
->value
;
1383 ovid
= &vout
->vid_info
;
1385 mutex_lock(&vout
->lock
);
1386 if (rotation
&& ovid
->rotation_type
== VOUT_ROT_NONE
) {
1387 mutex_unlock(&vout
->lock
);
1392 if (rotation
&& vout
->pix
.pixelformat
== V4L2_PIX_FMT_RGB24
) {
1393 mutex_unlock(&vout
->lock
);
1398 if (v4l2_rot_to_dss_rot(rotation
, &vout
->rotation
,
1400 mutex_unlock(&vout
->lock
);
1405 vout
->control
[0].value
= rotation
;
1406 mutex_unlock(&vout
->lock
);
1409 case V4L2_CID_BG_COLOR
:
1411 struct omap_overlay
*ovl
;
1412 unsigned int color
= a
->value
;
1413 struct omap_overlay_manager_info info
;
1415 ovl
= vout
->vid_info
.overlays
[0];
1417 mutex_lock(&vout
->lock
);
1418 if (!ovl
->manager
|| !ovl
->manager
->get_manager_info
) {
1419 mutex_unlock(&vout
->lock
);
1424 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1425 info
.default_color
= color
;
1426 if (ovl
->manager
->set_manager_info(ovl
->manager
, &info
)) {
1427 mutex_unlock(&vout
->lock
);
1432 vout
->control
[1].value
= color
;
1433 mutex_unlock(&vout
->lock
);
1436 case V4L2_CID_VFLIP
:
1438 struct omap_overlay
*ovl
;
1439 struct omapvideo_info
*ovid
;
1440 unsigned int mirror
= a
->value
;
1442 ovid
= &vout
->vid_info
;
1443 ovl
= ovid
->overlays
[0];
1445 mutex_lock(&vout
->lock
);
1446 if (mirror
&& ovid
->rotation_type
== VOUT_ROT_NONE
) {
1447 mutex_unlock(&vout
->lock
);
1452 if (mirror
&& vout
->pix
.pixelformat
== V4L2_PIX_FMT_RGB24
) {
1453 mutex_unlock(&vout
->lock
);
1457 vout
->mirror
= mirror
;
1458 vout
->control
[2].value
= mirror
;
1459 mutex_unlock(&vout
->lock
);
1468 static int vidioc_reqbufs(struct file
*file
, void *fh
,
1469 struct v4l2_requestbuffers
*req
)
1472 unsigned int i
, num_buffers
= 0;
1473 struct omap_vout_device
*vout
= fh
;
1474 struct videobuf_queue
*q
= &vout
->vbq
;
1476 if ((req
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
) || (req
->count
< 0))
1478 /* if memory is not mmp or userptr
1480 if ((V4L2_MEMORY_MMAP
!= req
->memory
) &&
1481 (V4L2_MEMORY_USERPTR
!= req
->memory
))
1484 mutex_lock(&vout
->lock
);
1485 /* Cannot be requested when streaming is on */
1486 if (vout
->streaming
) {
1491 /* If buffers are already allocated free them */
1492 if (q
->bufs
[0] && (V4L2_MEMORY_MMAP
== q
->bufs
[0]->memory
)) {
1493 if (vout
->mmap_count
) {
1497 num_buffers
= (vout
->vid
== OMAP_VIDEO1
) ?
1498 video1_numbuffers
: video2_numbuffers
;
1499 for (i
= num_buffers
; i
< vout
->buffer_allocated
; i
++) {
1500 omap_vout_free_buffer(vout
->buf_virt_addr
[i
],
1502 vout
->buf_virt_addr
[i
] = 0;
1503 vout
->buf_phy_addr
[i
] = 0;
1505 vout
->buffer_allocated
= num_buffers
;
1506 videobuf_mmap_free(q
);
1507 } else if (q
->bufs
[0] && (V4L2_MEMORY_USERPTR
== q
->bufs
[0]->memory
)) {
1508 if (vout
->buffer_allocated
) {
1509 videobuf_mmap_free(q
);
1510 for (i
= 0; i
< vout
->buffer_allocated
; i
++) {
1514 vout
->buffer_allocated
= 0;
1518 /*store the memory type in data structure */
1519 vout
->memory
= req
->memory
;
1521 INIT_LIST_HEAD(&vout
->dma_queue
);
1523 /* call videobuf_reqbufs api */
1524 ret
= videobuf_reqbufs(q
, req
);
1528 vout
->buffer_allocated
= req
->count
;
1531 mutex_unlock(&vout
->lock
);
1535 static int vidioc_querybuf(struct file
*file
, void *fh
,
1536 struct v4l2_buffer
*b
)
1538 struct omap_vout_device
*vout
= fh
;
1540 return videobuf_querybuf(&vout
->vbq
, b
);
1543 static int vidioc_qbuf(struct file
*file
, void *fh
,
1544 struct v4l2_buffer
*buffer
)
1546 struct omap_vout_device
*vout
= fh
;
1547 struct videobuf_queue
*q
= &vout
->vbq
;
1549 if ((V4L2_BUF_TYPE_VIDEO_OUTPUT
!= buffer
->type
) ||
1550 (buffer
->index
>= vout
->buffer_allocated
) ||
1551 (q
->bufs
[buffer
->index
]->memory
!= buffer
->memory
)) {
1554 if (V4L2_MEMORY_USERPTR
== buffer
->memory
) {
1555 if ((buffer
->length
< vout
->pix
.sizeimage
) ||
1556 (0 == buffer
->m
.userptr
)) {
1561 if ((is_rotation_enabled(vout
)) &&
1562 vout
->vrfb_dma_tx
.req_status
== DMA_CHAN_NOT_ALLOTED
) {
1563 v4l2_warn(&vout
->vid_dev
->v4l2_dev
,
1564 "DMA Channel not allocated for Rotation\n");
1568 return videobuf_qbuf(q
, buffer
);
1571 static int vidioc_dqbuf(struct file
*file
, void *fh
, struct v4l2_buffer
*b
)
1573 struct omap_vout_device
*vout
= fh
;
1574 struct videobuf_queue
*q
= &vout
->vbq
;
1579 struct videobuf_buffer
*vb
;
1581 vb
= q
->bufs
[b
->index
];
1583 if (!vout
->streaming
)
1586 if (file
->f_flags
& O_NONBLOCK
)
1587 /* Call videobuf_dqbuf for non blocking mode */
1588 ret
= videobuf_dqbuf(q
, (struct v4l2_buffer
*)b
, 1);
1590 /* Call videobuf_dqbuf for blocking mode */
1591 ret
= videobuf_dqbuf(q
, (struct v4l2_buffer
*)b
, 0);
1593 addr
= (unsigned long) vout
->buf_phy_addr
[vb
->i
];
1594 size
= (unsigned long) vb
->size
;
1595 dma_unmap_single(vout
->vid_dev
->v4l2_dev
.dev
, addr
,
1596 size
, DMA_TO_DEVICE
);
1600 static int vidioc_streamon(struct file
*file
, void *fh
, enum v4l2_buf_type i
)
1603 u32 addr
= 0, mask
= 0;
1604 struct omap_vout_device
*vout
= fh
;
1605 struct videobuf_queue
*q
= &vout
->vbq
;
1606 struct omapvideo_info
*ovid
= &vout
->vid_info
;
1608 mutex_lock(&vout
->lock
);
1610 if (vout
->streaming
) {
1615 ret
= videobuf_streamon(q
);
1619 if (list_empty(&vout
->dma_queue
)) {
1624 /* Get the next frame from the buffer queue */
1625 vout
->next_frm
= vout
->cur_frm
= list_entry(vout
->dma_queue
.next
,
1626 struct videobuf_buffer
, queue
);
1627 /* Remove buffer from the buffer queue */
1628 list_del(&vout
->cur_frm
->queue
);
1629 /* Mark state of the current frame to active */
1630 vout
->cur_frm
->state
= VIDEOBUF_ACTIVE
;
1631 /* Initialize field_id and started member */
1634 /* set flag here. Next QBUF will start DMA */
1635 vout
->streaming
= 1;
1637 vout
->first_int
= 1;
1639 if (omap_vout_calculate_offset(vout
)) {
1643 addr
= (unsigned long) vout
->queued_buf_addr
[vout
->cur_frm
->i
]
1644 + vout
->cropped_offset
;
1646 mask
= DISPC_IRQ_VSYNC
| DISPC_IRQ_EVSYNC_EVEN
| DISPC_IRQ_EVSYNC_ODD
1649 omap_dispc_register_isr(omap_vout_isr
, vout
, mask
);
1651 for (j
= 0; j
< ovid
->num_overlays
; j
++) {
1652 struct omap_overlay
*ovl
= ovid
->overlays
[j
];
1654 if (ovl
->manager
&& ovl
->manager
->device
) {
1655 struct omap_overlay_info info
;
1656 ovl
->get_overlay_info(ovl
, &info
);
1659 if (ovl
->set_overlay_info(ovl
, &info
)) {
1666 /* First save the configuration in ovelray structure */
1667 ret
= omapvid_init(vout
, addr
);
1669 v4l2_err(&vout
->vid_dev
->v4l2_dev
,
1670 "failed to set overlay info\n");
1671 /* Enable the pipeline and set the Go bit */
1672 ret
= omapvid_apply_changes(vout
);
1674 v4l2_err(&vout
->vid_dev
->v4l2_dev
, "failed to change mode\n");
1680 ret
= videobuf_streamoff(q
);
1682 mutex_unlock(&vout
->lock
);
1686 static int vidioc_streamoff(struct file
*file
, void *fh
, enum v4l2_buf_type i
)
1690 struct omap_vout_device
*vout
= fh
;
1691 struct omapvideo_info
*ovid
= &vout
->vid_info
;
1693 if (!vout
->streaming
)
1696 vout
->streaming
= 0;
1697 mask
= DISPC_IRQ_VSYNC
| DISPC_IRQ_EVSYNC_EVEN
| DISPC_IRQ_EVSYNC_ODD
1700 omap_dispc_unregister_isr(omap_vout_isr
, vout
, mask
);
1702 for (j
= 0; j
< ovid
->num_overlays
; j
++) {
1703 struct omap_overlay
*ovl
= ovid
->overlays
[j
];
1705 if (ovl
->manager
&& ovl
->manager
->device
) {
1706 struct omap_overlay_info info
;
1708 ovl
->get_overlay_info(ovl
, &info
);
1710 ret
= ovl
->set_overlay_info(ovl
, &info
);
1712 v4l2_err(&vout
->vid_dev
->v4l2_dev
,
1713 "failed to update overlay info in streamoff\n");
1717 /* Turn of the pipeline */
1718 ret
= omapvid_apply_changes(vout
);
1720 v4l2_err(&vout
->vid_dev
->v4l2_dev
, "failed to change mode in"
1723 INIT_LIST_HEAD(&vout
->dma_queue
);
1724 ret
= videobuf_streamoff(&vout
->vbq
);
1729 static int vidioc_s_fbuf(struct file
*file
, void *fh
,
1730 struct v4l2_framebuffer
*a
)
1733 struct omap_overlay
*ovl
;
1734 struct omapvideo_info
*ovid
;
1735 struct omap_vout_device
*vout
= fh
;
1736 struct omap_overlay_manager_info info
;
1737 enum omap_dss_trans_key_type key_type
= OMAP_DSS_COLOR_KEY_GFX_DST
;
1739 ovid
= &vout
->vid_info
;
1740 ovl
= ovid
->overlays
[0];
1742 /* OMAP DSS doesn't support Source and Destination color
1744 if ((a
->flags
& V4L2_FBUF_FLAG_SRC_CHROMAKEY
) &&
1745 (a
->flags
& V4L2_FBUF_FLAG_CHROMAKEY
))
1747 /* OMAP DSS Doesn't support the Destination color key
1748 and alpha blending together */
1749 if ((a
->flags
& V4L2_FBUF_FLAG_CHROMAKEY
) &&
1750 (a
->flags
& V4L2_FBUF_FLAG_LOCAL_ALPHA
))
1753 if ((a
->flags
& V4L2_FBUF_FLAG_SRC_CHROMAKEY
)) {
1754 vout
->fbuf
.flags
|= V4L2_FBUF_FLAG_SRC_CHROMAKEY
;
1755 key_type
= OMAP_DSS_COLOR_KEY_VID_SRC
;
1757 vout
->fbuf
.flags
&= ~V4L2_FBUF_FLAG_SRC_CHROMAKEY
;
1759 if ((a
->flags
& V4L2_FBUF_FLAG_CHROMAKEY
)) {
1760 vout
->fbuf
.flags
|= V4L2_FBUF_FLAG_CHROMAKEY
;
1761 key_type
= OMAP_DSS_COLOR_KEY_GFX_DST
;
1763 vout
->fbuf
.flags
&= ~V4L2_FBUF_FLAG_CHROMAKEY
;
1765 if (a
->flags
& (V4L2_FBUF_FLAG_CHROMAKEY
|
1766 V4L2_FBUF_FLAG_SRC_CHROMAKEY
))
1770 if (ovl
->manager
&& ovl
->manager
->get_manager_info
&&
1771 ovl
->manager
->set_manager_info
) {
1773 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1774 info
.trans_enabled
= enable
;
1775 info
.trans_key_type
= key_type
;
1776 info
.trans_key
= vout
->win
.chromakey
;
1778 if (ovl
->manager
->set_manager_info(ovl
->manager
, &info
))
1781 if (a
->flags
& V4L2_FBUF_FLAG_LOCAL_ALPHA
) {
1782 vout
->fbuf
.flags
|= V4L2_FBUF_FLAG_LOCAL_ALPHA
;
1785 vout
->fbuf
.flags
&= ~V4L2_FBUF_FLAG_LOCAL_ALPHA
;
1788 if (ovl
->manager
&& ovl
->manager
->get_manager_info
&&
1789 ovl
->manager
->set_manager_info
) {
1790 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1791 info
.alpha_enabled
= enable
;
1792 if (ovl
->manager
->set_manager_info(ovl
->manager
, &info
))
1799 static int vidioc_g_fbuf(struct file
*file
, void *fh
,
1800 struct v4l2_framebuffer
*a
)
1802 struct omap_overlay
*ovl
;
1803 struct omapvideo_info
*ovid
;
1804 struct omap_vout_device
*vout
= fh
;
1805 struct omap_overlay_manager_info info
;
1807 ovid
= &vout
->vid_info
;
1808 ovl
= ovid
->overlays
[0];
1811 a
->capability
= V4L2_FBUF_CAP_LOCAL_ALPHA
| V4L2_FBUF_CAP_CHROMAKEY
1812 | V4L2_FBUF_CAP_SRC_CHROMAKEY
;
1814 if (ovl
->manager
&& ovl
->manager
->get_manager_info
) {
1815 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1816 if (info
.trans_key_type
== OMAP_DSS_COLOR_KEY_VID_SRC
)
1817 a
->flags
|= V4L2_FBUF_FLAG_SRC_CHROMAKEY
;
1818 if (info
.trans_key_type
== OMAP_DSS_COLOR_KEY_GFX_DST
)
1819 a
->flags
|= V4L2_FBUF_FLAG_CHROMAKEY
;
1821 if (ovl
->manager
&& ovl
->manager
->get_manager_info
) {
1822 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1823 if (info
.alpha_enabled
)
1824 a
->flags
|= V4L2_FBUF_FLAG_LOCAL_ALPHA
;
1830 static const struct v4l2_ioctl_ops vout_ioctl_ops
= {
1831 .vidioc_querycap
= vidioc_querycap
,
1832 .vidioc_enum_fmt_vid_out
= vidioc_enum_fmt_vid_out
,
1833 .vidioc_g_fmt_vid_out
= vidioc_g_fmt_vid_out
,
1834 .vidioc_try_fmt_vid_out
= vidioc_try_fmt_vid_out
,
1835 .vidioc_s_fmt_vid_out
= vidioc_s_fmt_vid_out
,
1836 .vidioc_queryctrl
= vidioc_queryctrl
,
1837 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1838 .vidioc_s_fbuf
= vidioc_s_fbuf
,
1839 .vidioc_g_fbuf
= vidioc_g_fbuf
,
1840 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1841 .vidioc_try_fmt_vid_overlay
= vidioc_try_fmt_vid_overlay
,
1842 .vidioc_s_fmt_vid_overlay
= vidioc_s_fmt_vid_overlay
,
1843 .vidioc_enum_fmt_vid_overlay
= vidioc_enum_fmt_vid_overlay
,
1844 .vidioc_g_fmt_vid_overlay
= vidioc_g_fmt_vid_overlay
,
1845 .vidioc_cropcap
= vidioc_cropcap
,
1846 .vidioc_g_crop
= vidioc_g_crop
,
1847 .vidioc_s_crop
= vidioc_s_crop
,
1848 .vidioc_reqbufs
= vidioc_reqbufs
,
1849 .vidioc_querybuf
= vidioc_querybuf
,
1850 .vidioc_qbuf
= vidioc_qbuf
,
1851 .vidioc_dqbuf
= vidioc_dqbuf
,
1852 .vidioc_streamon
= vidioc_streamon
,
1853 .vidioc_streamoff
= vidioc_streamoff
,
1856 static const struct v4l2_file_operations omap_vout_fops
= {
1857 .owner
= THIS_MODULE
,
1858 .unlocked_ioctl
= video_ioctl2
,
1859 .mmap
= omap_vout_mmap
,
1860 .open
= omap_vout_open
,
1861 .release
= omap_vout_release
,
1864 /* Init functions used during driver initialization */
1865 /* Initial setup of video_data */
1866 static int __init
omap_vout_setup_video_data(struct omap_vout_device
*vout
)
1868 struct video_device
*vfd
;
1869 struct v4l2_pix_format
*pix
;
1870 struct v4l2_control
*control
;
1871 struct omap_dss_device
*display
=
1872 vout
->vid_info
.overlays
[0]->manager
->device
;
1874 /* set the default pix */
1877 /* Set the default picture of QVGA */
1878 pix
->width
= QQVGA_WIDTH
;
1879 pix
->height
= QQVGA_HEIGHT
;
1881 /* Default pixel format is RGB 5-6-5 */
1882 pix
->pixelformat
= V4L2_PIX_FMT_RGB565
;
1883 pix
->field
= V4L2_FIELD_ANY
;
1884 pix
->bytesperline
= pix
->width
* 2;
1885 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
1887 pix
->colorspace
= V4L2_COLORSPACE_JPEG
;
1889 vout
->bpp
= RGB565_BPP
;
1890 vout
->fbuf
.fmt
.width
= display
->panel
.timings
.x_res
;
1891 vout
->fbuf
.fmt
.height
= display
->panel
.timings
.y_res
;
1893 /* Set the data structures for the overlay parameters*/
1894 vout
->win
.global_alpha
= 255;
1895 vout
->fbuf
.flags
= 0;
1896 vout
->fbuf
.capability
= V4L2_FBUF_CAP_LOCAL_ALPHA
|
1897 V4L2_FBUF_CAP_SRC_CHROMAKEY
| V4L2_FBUF_CAP_CHROMAKEY
;
1898 vout
->win
.chromakey
= 0;
1900 omap_vout_new_format(pix
, &vout
->fbuf
, &vout
->crop
, &vout
->win
);
1902 /*Initialize the control variables for
1903 rotation, flipping and background color. */
1904 control
= vout
->control
;
1905 control
[0].id
= V4L2_CID_ROTATE
;
1906 control
[0].value
= 0;
1909 vout
->control
[2].id
= V4L2_CID_HFLIP
;
1910 vout
->control
[2].value
= 0;
1911 if (vout
->vid_info
.rotation_type
== VOUT_ROT_VRFB
)
1914 control
[1].id
= V4L2_CID_BG_COLOR
;
1915 control
[1].value
= 0;
1917 /* initialize the video_device struct */
1918 vfd
= vout
->vfd
= video_device_alloc();
1921 printk(KERN_ERR VOUT_NAME
": could not allocate"
1922 " video device struct\n");
1925 vfd
->release
= video_device_release
;
1926 vfd
->ioctl_ops
= &vout_ioctl_ops
;
1928 strlcpy(vfd
->name
, VOUT_NAME
, sizeof(vfd
->name
));
1930 vfd
->fops
= &omap_vout_fops
;
1931 vfd
->v4l2_dev
= &vout
->vid_dev
->v4l2_dev
;
1932 mutex_init(&vout
->lock
);
1939 /* Setup video buffers */
1940 static int __init
omap_vout_setup_video_bufs(struct platform_device
*pdev
,
1945 struct omapvideo_info
*ovid
;
1946 struct omap_vout_device
*vout
;
1947 struct v4l2_device
*v4l2_dev
= platform_get_drvdata(pdev
);
1948 struct omap2video_device
*vid_dev
=
1949 container_of(v4l2_dev
, struct omap2video_device
, v4l2_dev
);
1951 vout
= vid_dev
->vouts
[vid_num
];
1952 ovid
= &vout
->vid_info
;
1954 numbuffers
= (vid_num
== 0) ? video1_numbuffers
: video2_numbuffers
;
1955 vout
->buffer_size
= (vid_num
== 0) ? video1_bufsize
: video2_bufsize
;
1956 dev_info(&pdev
->dev
, "Buffer Size = %d\n", vout
->buffer_size
);
1958 for (i
= 0; i
< numbuffers
; i
++) {
1959 vout
->buf_virt_addr
[i
] =
1960 omap_vout_alloc_buffer(vout
->buffer_size
,
1961 (u32
*) &vout
->buf_phy_addr
[i
]);
1962 if (!vout
->buf_virt_addr
[i
]) {
1969 vout
->cropped_offset
= 0;
1971 if (ovid
->rotation_type
== VOUT_ROT_VRFB
) {
1972 int static_vrfb_allocation
= (vid_num
== 0) ?
1973 vid1_static_vrfb_alloc
: vid2_static_vrfb_alloc
;
1974 ret
= omap_vout_setup_vrfb_bufs(pdev
, vid_num
,
1975 static_vrfb_allocation
);
1981 for (i
= 0; i
< numbuffers
; i
++) {
1982 omap_vout_free_buffer(vout
->buf_virt_addr
[i
],
1984 vout
->buf_virt_addr
[i
] = 0;
1985 vout
->buf_phy_addr
[i
] = 0;
1991 /* Create video out devices */
1992 static int __init
omap_vout_create_video_devices(struct platform_device
*pdev
)
1995 struct omap_vout_device
*vout
;
1996 struct video_device
*vfd
= NULL
;
1997 struct v4l2_device
*v4l2_dev
= platform_get_drvdata(pdev
);
1998 struct omap2video_device
*vid_dev
= container_of(v4l2_dev
,
1999 struct omap2video_device
, v4l2_dev
);
2001 for (k
= 0; k
< pdev
->num_resources
; k
++) {
2003 vout
= kzalloc(sizeof(struct omap_vout_device
), GFP_KERNEL
);
2005 dev_err(&pdev
->dev
, ": could not allocate memory\n");
2010 vid_dev
->vouts
[k
] = vout
;
2011 vout
->vid_dev
= vid_dev
;
2012 /* Select video2 if only 1 overlay is controlled by V4L2 */
2013 if (pdev
->num_resources
== 1)
2014 vout
->vid_info
.overlays
[0] = vid_dev
->overlays
[k
+ 2];
2016 /* Else select video1 and video2 one by one. */
2017 vout
->vid_info
.overlays
[0] = vid_dev
->overlays
[k
+ 1];
2018 vout
->vid_info
.num_overlays
= 1;
2019 vout
->vid_info
.id
= k
+ 1;
2021 /* Set VRFB as rotation_type for omap2 and omap3 */
2022 if (cpu_is_omap24xx() || cpu_is_omap34xx())
2023 vout
->vid_info
.rotation_type
= VOUT_ROT_VRFB
;
2025 /* Setup the default configuration for the video devices
2027 if (omap_vout_setup_video_data(vout
) != 0) {
2032 /* Allocate default number of buffers for the video streaming
2033 * and reserve the VRFB space for rotation
2035 if (omap_vout_setup_video_bufs(pdev
, k
) != 0) {
2040 /* Register the Video device with V4L2
2043 if (video_register_device(vfd
, VFL_TYPE_GRABBER
, -1) < 0) {
2044 dev_err(&pdev
->dev
, ": Could not register "
2045 "Video for Linux device\n");
2050 video_set_drvdata(vfd
, vout
);
2052 /* Configure the overlay structure */
2053 ret
= omapvid_init(vid_dev
->vouts
[k
], 0);
2058 if (vout
->vid_info
.rotation_type
== VOUT_ROT_VRFB
)
2059 omap_vout_release_vrfb(vout
);
2060 omap_vout_free_buffers(vout
);
2062 video_device_release(vfd
);
2068 dev_info(&pdev
->dev
, ": registered and initialized"
2069 " video device %d\n", vfd
->minor
);
2070 if (k
== (pdev
->num_resources
- 1))
2076 /* Driver functions */
2077 static void omap_vout_cleanup_device(struct omap_vout_device
*vout
)
2079 struct video_device
*vfd
;
2080 struct omapvideo_info
*ovid
;
2086 ovid
= &vout
->vid_info
;
2088 if (!video_is_registered(vfd
)) {
2090 * The device was never registered, so release the
2091 * video_device struct directly.
2093 video_device_release(vfd
);
2096 * The unregister function will release the video_device
2097 * struct as well as unregistering it.
2099 video_unregister_device(vfd
);
2102 if (ovid
->rotation_type
== VOUT_ROT_VRFB
) {
2103 omap_vout_release_vrfb(vout
);
2104 /* Free the VRFB buffer if allocated
2107 if (vout
->vrfb_static_allocation
)
2108 omap_vout_free_vrfb_buffers(vout
);
2110 omap_vout_free_buffers(vout
);
2115 static int omap_vout_remove(struct platform_device
*pdev
)
2118 struct v4l2_device
*v4l2_dev
= platform_get_drvdata(pdev
);
2119 struct omap2video_device
*vid_dev
= container_of(v4l2_dev
, struct
2120 omap2video_device
, v4l2_dev
);
2122 v4l2_device_unregister(v4l2_dev
);
2123 for (k
= 0; k
< pdev
->num_resources
; k
++)
2124 omap_vout_cleanup_device(vid_dev
->vouts
[k
]);
2126 for (k
= 0; k
< vid_dev
->num_displays
; k
++) {
2127 if (vid_dev
->displays
[k
]->state
!= OMAP_DSS_DISPLAY_DISABLED
)
2128 vid_dev
->displays
[k
]->driver
->disable(vid_dev
->displays
[k
]);
2130 omap_dss_put_device(vid_dev
->displays
[k
]);
2136 static int __init
omap_vout_probe(struct platform_device
*pdev
)
2139 struct omap_overlay
*ovl
;
2140 struct omap_dss_device
*dssdev
= NULL
;
2141 struct omap_dss_device
*def_display
;
2142 struct omap2video_device
*vid_dev
= NULL
;
2144 if (pdev
->num_resources
== 0) {
2145 dev_err(&pdev
->dev
, "probed for an unknown device\n");
2149 vid_dev
= kzalloc(sizeof(struct omap2video_device
), GFP_KERNEL
);
2150 if (vid_dev
== NULL
)
2153 vid_dev
->num_displays
= 0;
2154 for_each_dss_dev(dssdev
) {
2155 omap_dss_get_device(dssdev
);
2156 vid_dev
->displays
[vid_dev
->num_displays
++] = dssdev
;
2159 if (vid_dev
->num_displays
== 0) {
2160 dev_err(&pdev
->dev
, "no displays\n");
2165 vid_dev
->num_overlays
= omap_dss_get_num_overlays();
2166 for (i
= 0; i
< vid_dev
->num_overlays
; i
++)
2167 vid_dev
->overlays
[i
] = omap_dss_get_overlay(i
);
2169 vid_dev
->num_managers
= omap_dss_get_num_overlay_managers();
2170 for (i
= 0; i
< vid_dev
->num_managers
; i
++)
2171 vid_dev
->managers
[i
] = omap_dss_get_overlay_manager(i
);
2173 /* Get the Video1 overlay and video2 overlay.
2174 * Setup the Display attached to that overlays
2176 for (i
= 1; i
< vid_dev
->num_overlays
; i
++) {
2177 ovl
= omap_dss_get_overlay(i
);
2178 if (ovl
->manager
&& ovl
->manager
->device
) {
2179 def_display
= ovl
->manager
->device
;
2181 dev_warn(&pdev
->dev
, "cannot find display\n");
2185 struct omap_dss_driver
*dssdrv
= def_display
->driver
;
2187 ret
= dssdrv
->enable(def_display
);
2189 /* Here we are not considering a error
2190 * as display may be enabled by frame
2193 dev_warn(&pdev
->dev
,
2194 "'%s' Display already enabled\n",
2197 /* set the update mode */
2198 if (def_display
->caps
&
2199 OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
) {
2200 if (dssdrv
->enable_te
)
2201 dssdrv
->enable_te(def_display
, 0);
2202 if (dssdrv
->set_update_mode
)
2203 dssdrv
->set_update_mode(def_display
,
2204 OMAP_DSS_UPDATE_MANUAL
);
2206 if (dssdrv
->set_update_mode
)
2207 dssdrv
->set_update_mode(def_display
,
2208 OMAP_DSS_UPDATE_AUTO
);
2213 if (v4l2_device_register(&pdev
->dev
, &vid_dev
->v4l2_dev
) < 0) {
2214 dev_err(&pdev
->dev
, "v4l2_device_register failed\n");
2219 ret
= omap_vout_create_video_devices(pdev
);
2223 for (i
= 0; i
< vid_dev
->num_displays
; i
++) {
2224 struct omap_dss_device
*display
= vid_dev
->displays
[i
];
2226 if (display
->driver
->update
)
2227 display
->driver
->update(display
, 0, 0,
2228 display
->panel
.timings
.x_res
,
2229 display
->panel
.timings
.y_res
);
2234 v4l2_device_unregister(&vid_dev
->v4l2_dev
);
2236 for (i
= 1; i
< vid_dev
->num_overlays
; i
++) {
2238 ovl
= omap_dss_get_overlay(i
);
2239 if (ovl
->manager
&& ovl
->manager
->device
)
2240 def_display
= ovl
->manager
->device
;
2242 if (def_display
&& def_display
->driver
)
2243 def_display
->driver
->disable(def_display
);
2250 static struct platform_driver omap_vout_driver
= {
2254 .probe
= omap_vout_probe
,
2255 .remove
= omap_vout_remove
,
2258 static int __init
omap_vout_init(void)
2260 if (platform_driver_register(&omap_vout_driver
) != 0) {
2261 printk(KERN_ERR VOUT_NAME
":Could not register Video driver\n");
2267 static void omap_vout_cleanup(void)
2269 platform_driver_unregister(&omap_vout_driver
);
2272 late_initcall(omap_vout_init
);
2273 module_exit(omap_vout_cleanup
);