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>
48 #include <plat/vrfb.h>
49 #include <video/omapdss.h>
51 #include "omap_voutlib.h"
52 #include "omap_voutdef.h"
53 #include "omap_vout_vrfb.h"
55 MODULE_AUTHOR("Texas Instruments");
56 MODULE_DESCRIPTION("OMAP Video for Linux Video out driver");
57 MODULE_LICENSE("GPL");
59 /* Driver Configuration macros */
60 #define VOUT_NAME "omap_vout"
62 enum omap_vout_channels
{
67 static struct videobuf_queue_ops video_vbq_ops
;
68 /* Variables configurable through module params*/
69 static u32 video1_numbuffers
= 3;
70 static u32 video2_numbuffers
= 3;
71 static u32 video1_bufsize
= OMAP_VOUT_MAX_BUF_SIZE
;
72 static u32 video2_bufsize
= OMAP_VOUT_MAX_BUF_SIZE
;
73 static bool vid1_static_vrfb_alloc
;
74 static bool vid2_static_vrfb_alloc
;
77 /* Module parameters */
78 module_param(video1_numbuffers
, uint
, S_IRUGO
);
79 MODULE_PARM_DESC(video1_numbuffers
,
80 "Number of buffers to be allocated at init time for Video1 device.");
82 module_param(video2_numbuffers
, uint
, S_IRUGO
);
83 MODULE_PARM_DESC(video2_numbuffers
,
84 "Number of buffers to be allocated at init time for Video2 device.");
86 module_param(video1_bufsize
, uint
, S_IRUGO
);
87 MODULE_PARM_DESC(video1_bufsize
,
88 "Size of the buffer to be allocated for video1 device");
90 module_param(video2_bufsize
, uint
, S_IRUGO
);
91 MODULE_PARM_DESC(video2_bufsize
,
92 "Size of the buffer to be allocated for video2 device");
94 module_param(vid1_static_vrfb_alloc
, bool, S_IRUGO
);
95 MODULE_PARM_DESC(vid1_static_vrfb_alloc
,
96 "Static allocation of the VRFB buffer for video1 device");
98 module_param(vid2_static_vrfb_alloc
, bool, S_IRUGO
);
99 MODULE_PARM_DESC(vid2_static_vrfb_alloc
,
100 "Static allocation of the VRFB buffer for video2 device");
102 module_param(debug
, bool, S_IRUGO
);
103 MODULE_PARM_DESC(debug
, "Debug level (0-1)");
105 /* list of image formats supported by OMAP2 video pipelines */
106 static const struct v4l2_fmtdesc omap_formats
[] = {
108 /* Note: V4L2 defines RGB565 as:
111 * g2 g1 g0 r4 r3 r2 r1 r0 b4 b3 b2 b1 b0 g5 g4 g3
113 * We interpret RGB565 as:
116 * g2 g1 g0 b4 b3 b2 b1 b0 r4 r3 r2 r1 r0 g5 g4 g3
118 .description
= "RGB565, le",
119 .pixelformat
= V4L2_PIX_FMT_RGB565
,
122 /* Note: V4L2 defines RGB32 as: RGB-8-8-8-8 we use
123 * this for RGB24 unpack mode, the last 8 bits are ignored
125 .description
= "RGB32, le",
126 .pixelformat
= V4L2_PIX_FMT_RGB32
,
129 /* Note: V4L2 defines RGB24 as: RGB-8-8-8 we use
130 * this for RGB24 packed mode
133 .description
= "RGB24, le",
134 .pixelformat
= V4L2_PIX_FMT_RGB24
,
137 .description
= "YUYV (YUV 4:2:2), packed",
138 .pixelformat
= V4L2_PIX_FMT_YUYV
,
141 .description
= "UYVY, packed",
142 .pixelformat
= V4L2_PIX_FMT_UYVY
,
146 #define NUM_OUTPUT_FORMATS (ARRAY_SIZE(omap_formats))
151 static int omap_vout_try_format(struct v4l2_pix_format
*pix
)
155 pix
->height
= clamp(pix
->height
, (u32
)VID_MIN_HEIGHT
,
156 (u32
)VID_MAX_HEIGHT
);
157 pix
->width
= clamp(pix
->width
, (u32
)VID_MIN_WIDTH
, (u32
)VID_MAX_WIDTH
);
159 for (ifmt
= 0; ifmt
< NUM_OUTPUT_FORMATS
; ifmt
++) {
160 if (pix
->pixelformat
== omap_formats
[ifmt
].pixelformat
)
164 if (ifmt
== NUM_OUTPUT_FORMATS
)
167 pix
->pixelformat
= omap_formats
[ifmt
].pixelformat
;
168 pix
->field
= V4L2_FIELD_ANY
;
171 switch (pix
->pixelformat
) {
172 case V4L2_PIX_FMT_YUYV
:
173 case V4L2_PIX_FMT_UYVY
:
175 pix
->colorspace
= V4L2_COLORSPACE_JPEG
;
178 case V4L2_PIX_FMT_RGB565
:
179 case V4L2_PIX_FMT_RGB565X
:
180 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
183 case V4L2_PIX_FMT_RGB24
:
184 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
187 case V4L2_PIX_FMT_RGB32
:
188 case V4L2_PIX_FMT_BGR32
:
189 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
193 pix
->bytesperline
= pix
->width
* bpp
;
194 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
200 * omap_vout_uservirt_to_phys: This inline function is used to convert user
201 * space virtual address to physical address.
203 static u32
omap_vout_uservirt_to_phys(u32 virtp
)
205 unsigned long physp
= 0;
206 struct vm_area_struct
*vma
;
207 struct mm_struct
*mm
= current
->mm
;
209 vma
= find_vma(mm
, virtp
);
210 /* For kernel direct-mapped memory, take the easy way */
211 if (virtp
>= PAGE_OFFSET
) {
212 physp
= virt_to_phys((void *) virtp
);
213 } else if (vma
&& (vma
->vm_flags
& VM_IO
) && vma
->vm_pgoff
) {
214 /* this will catch, kernel-allocated, mmaped-to-usermode
216 physp
= (vma
->vm_pgoff
<< PAGE_SHIFT
) + (virtp
- vma
->vm_start
);
218 /* otherwise, use get_user_pages() for general userland pages */
219 int res
, nr_pages
= 1;
221 down_read(¤t
->mm
->mmap_sem
);
223 res
= get_user_pages(current
, current
->mm
, virtp
, nr_pages
, 1,
225 up_read(¤t
->mm
->mmap_sem
);
227 if (res
== nr_pages
) {
228 physp
= __pa(page_address(&pages
[0]) +
229 (virtp
& ~PAGE_MASK
));
231 printk(KERN_WARNING VOUT_NAME
232 "get_user_pages failed\n");
241 * Free the V4L2 buffers
243 void omap_vout_free_buffers(struct omap_vout_device
*vout
)
247 /* Allocate memory for the buffers */
248 numbuffers
= (vout
->vid
) ? video2_numbuffers
: video1_numbuffers
;
249 vout
->buffer_size
= (vout
->vid
) ? video2_bufsize
: video1_bufsize
;
251 for (i
= 0; i
< numbuffers
; i
++) {
252 omap_vout_free_buffer(vout
->buf_virt_addr
[i
],
254 vout
->buf_phy_addr
[i
] = 0;
255 vout
->buf_virt_addr
[i
] = 0;
260 * Convert V4L2 rotation to DSS rotation
261 * V4L2 understand 0, 90, 180, 270.
262 * Convert to 0, 1, 2 and 3 respectively for DSS
264 static int v4l2_rot_to_dss_rot(int v4l2_rotation
,
265 enum dss_rotation
*rotation
, bool mirror
)
269 switch (v4l2_rotation
) {
271 *rotation
= dss_rotation_90_degree
;
274 *rotation
= dss_rotation_180_degree
;
277 *rotation
= dss_rotation_270_degree
;
280 *rotation
= dss_rotation_0_degree
;
288 static int omap_vout_calculate_offset(struct omap_vout_device
*vout
)
290 struct omapvideo_info
*ovid
;
291 struct v4l2_rect
*crop
= &vout
->crop
;
292 struct v4l2_pix_format
*pix
= &vout
->pix
;
293 int *cropped_offset
= &vout
->cropped_offset
;
294 int ps
= 2, line_length
= 0;
296 ovid
= &vout
->vid_info
;
298 if (ovid
->rotation_type
== VOUT_ROT_VRFB
) {
299 omap_vout_calculate_vrfb_offset(vout
);
301 vout
->line_length
= line_length
= pix
->width
;
303 if (V4L2_PIX_FMT_YUYV
== pix
->pixelformat
||
304 V4L2_PIX_FMT_UYVY
== pix
->pixelformat
)
306 else if (V4L2_PIX_FMT_RGB32
== pix
->pixelformat
)
308 else if (V4L2_PIX_FMT_RGB24
== pix
->pixelformat
)
313 *cropped_offset
= (line_length
* ps
) *
314 crop
->top
+ crop
->left
* ps
;
317 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "%s Offset:%x\n",
318 __func__
, vout
->cropped_offset
);
324 * Convert V4L2 pixel format to DSS pixel format
326 static int video_mode_to_dss_mode(struct omap_vout_device
*vout
)
328 struct omap_overlay
*ovl
;
329 struct omapvideo_info
*ovid
;
330 struct v4l2_pix_format
*pix
= &vout
->pix
;
331 enum omap_color_mode mode
;
333 ovid
= &vout
->vid_info
;
334 ovl
= ovid
->overlays
[0];
336 switch (pix
->pixelformat
) {
339 case V4L2_PIX_FMT_YUYV
:
340 mode
= OMAP_DSS_COLOR_YUV2
;
342 case V4L2_PIX_FMT_UYVY
:
343 mode
= OMAP_DSS_COLOR_UYVY
;
345 case V4L2_PIX_FMT_RGB565
:
346 mode
= OMAP_DSS_COLOR_RGB16
;
348 case V4L2_PIX_FMT_RGB24
:
349 mode
= OMAP_DSS_COLOR_RGB24P
;
351 case V4L2_PIX_FMT_RGB32
:
352 mode
= (ovl
->id
== OMAP_DSS_VIDEO1
) ?
353 OMAP_DSS_COLOR_RGB24U
: OMAP_DSS_COLOR_ARGB32
;
355 case V4L2_PIX_FMT_BGR32
:
356 mode
= OMAP_DSS_COLOR_RGBX32
;
367 static int omapvid_setup_overlay(struct omap_vout_device
*vout
,
368 struct omap_overlay
*ovl
, int posx
, int posy
, int outw
,
372 struct omap_overlay_info info
;
373 int cropheight
, cropwidth
, pixheight
, pixwidth
;
375 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_SCALE
) == 0 &&
376 (outw
!= vout
->pix
.width
|| outh
!= vout
->pix
.height
)) {
381 vout
->dss_mode
= video_mode_to_dss_mode(vout
);
382 if (vout
->dss_mode
== -EINVAL
) {
387 /* Setup the input plane parameters according to
388 * rotation value selected.
390 if (is_rotation_90_or_270(vout
)) {
391 cropheight
= vout
->crop
.width
;
392 cropwidth
= vout
->crop
.height
;
393 pixheight
= vout
->pix
.width
;
394 pixwidth
= vout
->pix
.height
;
396 cropheight
= vout
->crop
.height
;
397 cropwidth
= vout
->crop
.width
;
398 pixheight
= vout
->pix
.height
;
399 pixwidth
= vout
->pix
.width
;
402 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 unsigned int omap_vout_poll(struct file
*file
,
838 struct poll_table_struct
*wait
)
840 struct omap_vout_device
*vout
= file
->private_data
;
841 struct videobuf_queue
*q
= &vout
->vbq
;
843 return videobuf_poll_stream(file
, q
, wait
);
846 static void omap_vout_vm_open(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_open [vma=%08lx-%08lx]\n", vma
->vm_start
, vma
->vm_end
);
855 static void omap_vout_vm_close(struct vm_area_struct
*vma
)
857 struct omap_vout_device
*vout
= vma
->vm_private_data
;
859 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
860 "vm_close [vma=%08lx-%08lx]\n", vma
->vm_start
, vma
->vm_end
);
864 static struct vm_operations_struct omap_vout_vm_ops
= {
865 .open
= omap_vout_vm_open
,
866 .close
= omap_vout_vm_close
,
869 static int omap_vout_mmap(struct file
*file
, struct vm_area_struct
*vma
)
873 unsigned long start
= vma
->vm_start
;
874 unsigned long size
= (vma
->vm_end
- vma
->vm_start
);
875 struct omap_vout_device
*vout
= file
->private_data
;
876 struct videobuf_queue
*q
= &vout
->vbq
;
878 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
879 " %s pgoff=0x%lx, start=0x%lx, end=0x%lx\n", __func__
,
880 vma
->vm_pgoff
, vma
->vm_start
, vma
->vm_end
);
882 /* look for the buffer to map */
883 for (i
= 0; i
< VIDEO_MAX_FRAME
; i
++) {
884 if (NULL
== q
->bufs
[i
])
886 if (V4L2_MEMORY_MMAP
!= q
->bufs
[i
]->memory
)
888 if (q
->bufs
[i
]->boff
== (vma
->vm_pgoff
<< PAGE_SHIFT
))
892 if (VIDEO_MAX_FRAME
== i
) {
893 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
894 "offset invalid [offset=0x%lx]\n",
895 (vma
->vm_pgoff
<< PAGE_SHIFT
));
898 /* Check the size of the buffer */
899 if (size
> vout
->buffer_size
) {
900 v4l2_err(&vout
->vid_dev
->v4l2_dev
,
901 "insufficient memory [%lu] [%u]\n",
902 size
, vout
->buffer_size
);
906 q
->bufs
[i
]->baddr
= vma
->vm_start
;
908 vma
->vm_flags
|= VM_RESERVED
;
909 vma
->vm_page_prot
= pgprot_writecombine(vma
->vm_page_prot
);
910 vma
->vm_ops
= &omap_vout_vm_ops
;
911 vma
->vm_private_data
= (void *) vout
;
912 pos
= (void *)vout
->buf_virt_addr
[i
];
913 vma
->vm_pgoff
= virt_to_phys((void *)pos
) >> PAGE_SHIFT
;
916 pfn
= virt_to_phys((void *) pos
) >> PAGE_SHIFT
;
917 if (remap_pfn_range(vma
, start
, pfn
, PAGE_SIZE
, PAGE_SHARED
))
924 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Exiting %s\n", __func__
);
929 static int omap_vout_release(struct file
*file
)
932 struct videobuf_queue
*q
;
933 struct omapvideo_info
*ovid
;
934 struct omap_vout_device
*vout
= file
->private_data
;
936 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Entering %s\n", __func__
);
937 ovid
= &vout
->vid_info
;
943 /* Disable all the overlay managers connected with this interface */
944 for (i
= 0; i
< ovid
->num_overlays
; i
++) {
945 struct omap_overlay
*ovl
= ovid
->overlays
[i
];
946 if (ovl
->manager
&& ovl
->manager
->device
) {
947 struct omap_overlay_info info
;
948 ovl
->get_overlay_info(ovl
, &info
);
950 ovl
->set_overlay_info(ovl
, &info
);
953 /* Turn off the pipeline */
954 ret
= omapvid_apply_changes(vout
);
956 v4l2_warn(&vout
->vid_dev
->v4l2_dev
,
957 "Unable to apply changes\n");
959 /* Free all buffers */
960 omap_vout_free_extra_buffers(vout
);
962 /* Free the VRFB buffers only if they are allocated
963 * during reqbufs. Don't free if init time allocated
965 if (ovid
->rotation_type
== VOUT_ROT_VRFB
) {
966 if (!vout
->vrfb_static_allocation
)
967 omap_vout_free_vrfb_buffers(vout
);
969 videobuf_mmap_free(q
);
971 /* Even if apply changes fails we should continue
972 freeing allocated memory */
973 if (vout
->streaming
) {
976 mask
= DISPC_IRQ_VSYNC
| DISPC_IRQ_EVSYNC_EVEN
|
977 DISPC_IRQ_EVSYNC_ODD
| DISPC_IRQ_VSYNC2
;
978 omap_dispc_unregister_isr(omap_vout_isr
, vout
, mask
);
981 videobuf_streamoff(q
);
982 videobuf_queue_cancel(q
);
985 if (vout
->mmap_count
!= 0)
986 vout
->mmap_count
= 0;
989 file
->private_data
= NULL
;
991 if (vout
->buffer_allocated
)
992 videobuf_mmap_free(q
);
994 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Exiting %s\n", __func__
);
998 static int omap_vout_open(struct file
*file
)
1000 struct videobuf_queue
*q
;
1001 struct omap_vout_device
*vout
= NULL
;
1003 vout
= video_drvdata(file
);
1004 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Entering %s\n", __func__
);
1009 /* for now, we only support single open */
1015 file
->private_data
= vout
;
1016 vout
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
1019 video_vbq_ops
.buf_setup
= omap_vout_buffer_setup
;
1020 video_vbq_ops
.buf_prepare
= omap_vout_buffer_prepare
;
1021 video_vbq_ops
.buf_release
= omap_vout_buffer_release
;
1022 video_vbq_ops
.buf_queue
= omap_vout_buffer_queue
;
1023 spin_lock_init(&vout
->vbq_lock
);
1025 videobuf_queue_dma_contig_init(q
, &video_vbq_ops
, q
->dev
,
1026 &vout
->vbq_lock
, vout
->type
, V4L2_FIELD_NONE
,
1027 sizeof(struct videobuf_buffer
), vout
, NULL
);
1029 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Exiting %s\n", __func__
);
1036 static int vidioc_querycap(struct file
*file
, void *fh
,
1037 struct v4l2_capability
*cap
)
1039 struct omap_vout_device
*vout
= fh
;
1041 strlcpy(cap
->driver
, VOUT_NAME
, sizeof(cap
->driver
));
1042 strlcpy(cap
->card
, vout
->vfd
->name
, sizeof(cap
->card
));
1043 cap
->bus_info
[0] = '\0';
1044 cap
->capabilities
= V4L2_CAP_STREAMING
| V4L2_CAP_VIDEO_OUTPUT
;
1049 static int vidioc_enum_fmt_vid_out(struct file
*file
, void *fh
,
1050 struct v4l2_fmtdesc
*fmt
)
1052 int index
= fmt
->index
;
1054 if (index
>= NUM_OUTPUT_FORMATS
)
1057 fmt
->flags
= omap_formats
[index
].flags
;
1058 strlcpy(fmt
->description
, omap_formats
[index
].description
,
1059 sizeof(fmt
->description
));
1060 fmt
->pixelformat
= omap_formats
[index
].pixelformat
;
1065 static int vidioc_g_fmt_vid_out(struct file
*file
, void *fh
,
1066 struct v4l2_format
*f
)
1068 struct omap_vout_device
*vout
= fh
;
1070 f
->fmt
.pix
= vout
->pix
;
1075 static int vidioc_try_fmt_vid_out(struct file
*file
, void *fh
,
1076 struct v4l2_format
*f
)
1078 struct omap_overlay
*ovl
;
1079 struct omapvideo_info
*ovid
;
1080 struct omap_video_timings
*timing
;
1081 struct omap_vout_device
*vout
= fh
;
1083 ovid
= &vout
->vid_info
;
1084 ovl
= ovid
->overlays
[0];
1086 if (!ovl
->manager
|| !ovl
->manager
->device
)
1088 /* get the display device attached to the overlay */
1089 timing
= &ovl
->manager
->device
->panel
.timings
;
1091 vout
->fbuf
.fmt
.height
= timing
->y_res
;
1092 vout
->fbuf
.fmt
.width
= timing
->x_res
;
1094 omap_vout_try_format(&f
->fmt
.pix
);
1098 static int vidioc_s_fmt_vid_out(struct file
*file
, void *fh
,
1099 struct v4l2_format
*f
)
1102 struct omap_overlay
*ovl
;
1103 struct omapvideo_info
*ovid
;
1104 struct omap_video_timings
*timing
;
1105 struct omap_vout_device
*vout
= fh
;
1107 if (vout
->streaming
)
1110 mutex_lock(&vout
->lock
);
1112 ovid
= &vout
->vid_info
;
1113 ovl
= ovid
->overlays
[0];
1115 /* get the display device attached to the overlay */
1116 if (!ovl
->manager
|| !ovl
->manager
->device
) {
1118 goto s_fmt_vid_out_exit
;
1120 timing
= &ovl
->manager
->device
->panel
.timings
;
1122 /* We dont support RGB24-packed mode if vrfb rotation
1124 if ((is_rotation_enabled(vout
)) &&
1125 f
->fmt
.pix
.pixelformat
== V4L2_PIX_FMT_RGB24
) {
1127 goto s_fmt_vid_out_exit
;
1130 /* get the framebuffer parameters */
1132 if (is_rotation_90_or_270(vout
)) {
1133 vout
->fbuf
.fmt
.height
= timing
->x_res
;
1134 vout
->fbuf
.fmt
.width
= timing
->y_res
;
1136 vout
->fbuf
.fmt
.height
= timing
->y_res
;
1137 vout
->fbuf
.fmt
.width
= timing
->x_res
;
1140 /* change to samller size is OK */
1142 bpp
= omap_vout_try_format(&f
->fmt
.pix
);
1143 f
->fmt
.pix
.sizeimage
= f
->fmt
.pix
.width
* f
->fmt
.pix
.height
* bpp
;
1145 /* try & set the new output format */
1147 vout
->pix
= f
->fmt
.pix
;
1150 /* If YUYV then vrfb bpp is 2, for others its 1 */
1151 if (V4L2_PIX_FMT_YUYV
== vout
->pix
.pixelformat
||
1152 V4L2_PIX_FMT_UYVY
== vout
->pix
.pixelformat
)
1155 /* set default crop and win */
1156 omap_vout_new_format(&vout
->pix
, &vout
->fbuf
, &vout
->crop
, &vout
->win
);
1158 /* Save the changes in the overlay strcuture */
1159 ret
= omapvid_init(vout
, 0);
1161 v4l2_err(&vout
->vid_dev
->v4l2_dev
, "failed to change mode\n");
1162 goto s_fmt_vid_out_exit
;
1168 mutex_unlock(&vout
->lock
);
1172 static int vidioc_try_fmt_vid_overlay(struct file
*file
, void *fh
,
1173 struct v4l2_format
*f
)
1176 struct omap_vout_device
*vout
= fh
;
1177 struct omap_overlay
*ovl
;
1178 struct omapvideo_info
*ovid
;
1179 struct v4l2_window
*win
= &f
->fmt
.win
;
1181 ovid
= &vout
->vid_info
;
1182 ovl
= ovid
->overlays
[0];
1184 ret
= omap_vout_try_window(&vout
->fbuf
, win
);
1187 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
) == 0)
1188 win
->global_alpha
= 255;
1190 win
->global_alpha
= f
->fmt
.win
.global_alpha
;
1196 static int vidioc_s_fmt_vid_overlay(struct file
*file
, void *fh
,
1197 struct v4l2_format
*f
)
1200 struct omap_overlay
*ovl
;
1201 struct omapvideo_info
*ovid
;
1202 struct omap_vout_device
*vout
= fh
;
1203 struct v4l2_window
*win
= &f
->fmt
.win
;
1205 mutex_lock(&vout
->lock
);
1206 ovid
= &vout
->vid_info
;
1207 ovl
= ovid
->overlays
[0];
1209 ret
= omap_vout_new_window(&vout
->crop
, &vout
->win
, &vout
->fbuf
, win
);
1211 /* Video1 plane does not support global alpha on OMAP3 */
1212 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
) == 0)
1213 vout
->win
.global_alpha
= 255;
1215 vout
->win
.global_alpha
= f
->fmt
.win
.global_alpha
;
1217 vout
->win
.chromakey
= f
->fmt
.win
.chromakey
;
1219 mutex_unlock(&vout
->lock
);
1223 static int vidioc_enum_fmt_vid_overlay(struct file
*file
, void *fh
,
1224 struct v4l2_fmtdesc
*fmt
)
1226 int index
= fmt
->index
;
1228 if (index
>= NUM_OUTPUT_FORMATS
)
1231 fmt
->flags
= omap_formats
[index
].flags
;
1232 strlcpy(fmt
->description
, omap_formats
[index
].description
,
1233 sizeof(fmt
->description
));
1234 fmt
->pixelformat
= omap_formats
[index
].pixelformat
;
1238 static int vidioc_g_fmt_vid_overlay(struct file
*file
, void *fh
,
1239 struct v4l2_format
*f
)
1242 struct omap_overlay
*ovl
;
1243 struct omapvideo_info
*ovid
;
1244 struct omap_vout_device
*vout
= fh
;
1245 struct omap_overlay_manager_info info
;
1246 struct v4l2_window
*win
= &f
->fmt
.win
;
1248 ovid
= &vout
->vid_info
;
1249 ovl
= ovid
->overlays
[0];
1251 win
->w
= vout
->win
.w
;
1252 win
->field
= vout
->win
.field
;
1253 win
->global_alpha
= vout
->win
.global_alpha
;
1255 if (ovl
->manager
&& ovl
->manager
->get_manager_info
) {
1256 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1257 key_value
= info
.trans_key
;
1259 win
->chromakey
= key_value
;
1263 static int vidioc_cropcap(struct file
*file
, void *fh
,
1264 struct v4l2_cropcap
*cropcap
)
1266 struct omap_vout_device
*vout
= fh
;
1267 struct v4l2_pix_format
*pix
= &vout
->pix
;
1269 if (cropcap
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1272 /* Width and height are always even */
1273 cropcap
->bounds
.width
= pix
->width
& ~1;
1274 cropcap
->bounds
.height
= pix
->height
& ~1;
1276 omap_vout_default_crop(&vout
->pix
, &vout
->fbuf
, &cropcap
->defrect
);
1277 cropcap
->pixelaspect
.numerator
= 1;
1278 cropcap
->pixelaspect
.denominator
= 1;
1282 static int vidioc_g_crop(struct file
*file
, void *fh
, struct v4l2_crop
*crop
)
1284 struct omap_vout_device
*vout
= fh
;
1286 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1288 crop
->c
= vout
->crop
;
1292 static int vidioc_s_crop(struct file
*file
, void *fh
, struct v4l2_crop
*crop
)
1295 struct omap_vout_device
*vout
= fh
;
1296 struct omapvideo_info
*ovid
;
1297 struct omap_overlay
*ovl
;
1298 struct omap_video_timings
*timing
;
1300 if (vout
->streaming
)
1303 mutex_lock(&vout
->lock
);
1304 ovid
= &vout
->vid_info
;
1305 ovl
= ovid
->overlays
[0];
1307 if (!ovl
->manager
|| !ovl
->manager
->device
) {
1311 /* get the display device attached to the overlay */
1312 timing
= &ovl
->manager
->device
->panel
.timings
;
1314 if (is_rotation_90_or_270(vout
)) {
1315 vout
->fbuf
.fmt
.height
= timing
->x_res
;
1316 vout
->fbuf
.fmt
.width
= timing
->y_res
;
1318 vout
->fbuf
.fmt
.height
= timing
->y_res
;
1319 vout
->fbuf
.fmt
.width
= timing
->x_res
;
1322 if (crop
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1323 ret
= omap_vout_new_crop(&vout
->pix
, &vout
->crop
, &vout
->win
,
1324 &vout
->fbuf
, &crop
->c
);
1327 mutex_unlock(&vout
->lock
);
1331 static int vidioc_queryctrl(struct file
*file
, void *fh
,
1332 struct v4l2_queryctrl
*ctrl
)
1337 case V4L2_CID_ROTATE
:
1338 ret
= v4l2_ctrl_query_fill(ctrl
, 0, 270, 90, 0);
1340 case V4L2_CID_BG_COLOR
:
1341 ret
= v4l2_ctrl_query_fill(ctrl
, 0, 0xFFFFFF, 1, 0);
1343 case V4L2_CID_VFLIP
:
1344 ret
= v4l2_ctrl_query_fill(ctrl
, 0, 1, 1, 0);
1347 ctrl
->name
[0] = '\0';
1353 static int vidioc_g_ctrl(struct file
*file
, void *fh
, struct v4l2_control
*ctrl
)
1356 struct omap_vout_device
*vout
= fh
;
1359 case V4L2_CID_ROTATE
:
1360 ctrl
->value
= vout
->control
[0].value
;
1362 case V4L2_CID_BG_COLOR
:
1364 struct omap_overlay_manager_info info
;
1365 struct omap_overlay
*ovl
;
1367 ovl
= vout
->vid_info
.overlays
[0];
1368 if (!ovl
->manager
|| !ovl
->manager
->get_manager_info
) {
1373 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1374 ctrl
->value
= info
.default_color
;
1377 case V4L2_CID_VFLIP
:
1378 ctrl
->value
= vout
->control
[2].value
;
1386 static int vidioc_s_ctrl(struct file
*file
, void *fh
, struct v4l2_control
*a
)
1389 struct omap_vout_device
*vout
= fh
;
1392 case V4L2_CID_ROTATE
:
1394 struct omapvideo_info
*ovid
;
1395 int rotation
= a
->value
;
1397 ovid
= &vout
->vid_info
;
1399 mutex_lock(&vout
->lock
);
1400 if (rotation
&& ovid
->rotation_type
== VOUT_ROT_NONE
) {
1401 mutex_unlock(&vout
->lock
);
1406 if (rotation
&& vout
->pix
.pixelformat
== V4L2_PIX_FMT_RGB24
) {
1407 mutex_unlock(&vout
->lock
);
1412 if (v4l2_rot_to_dss_rot(rotation
, &vout
->rotation
,
1414 mutex_unlock(&vout
->lock
);
1419 vout
->control
[0].value
= rotation
;
1420 mutex_unlock(&vout
->lock
);
1423 case V4L2_CID_BG_COLOR
:
1425 struct omap_overlay
*ovl
;
1426 unsigned int color
= a
->value
;
1427 struct omap_overlay_manager_info info
;
1429 ovl
= vout
->vid_info
.overlays
[0];
1431 mutex_lock(&vout
->lock
);
1432 if (!ovl
->manager
|| !ovl
->manager
->get_manager_info
) {
1433 mutex_unlock(&vout
->lock
);
1438 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1439 info
.default_color
= color
;
1440 if (ovl
->manager
->set_manager_info(ovl
->manager
, &info
)) {
1441 mutex_unlock(&vout
->lock
);
1446 vout
->control
[1].value
= color
;
1447 mutex_unlock(&vout
->lock
);
1450 case V4L2_CID_VFLIP
:
1452 struct omap_overlay
*ovl
;
1453 struct omapvideo_info
*ovid
;
1454 unsigned int mirror
= a
->value
;
1456 ovid
= &vout
->vid_info
;
1457 ovl
= ovid
->overlays
[0];
1459 mutex_lock(&vout
->lock
);
1460 if (mirror
&& ovid
->rotation_type
== VOUT_ROT_NONE
) {
1461 mutex_unlock(&vout
->lock
);
1466 if (mirror
&& vout
->pix
.pixelformat
== V4L2_PIX_FMT_RGB24
) {
1467 mutex_unlock(&vout
->lock
);
1471 vout
->mirror
= mirror
;
1472 vout
->control
[2].value
= mirror
;
1473 mutex_unlock(&vout
->lock
);
1482 static int vidioc_reqbufs(struct file
*file
, void *fh
,
1483 struct v4l2_requestbuffers
*req
)
1486 unsigned int i
, num_buffers
= 0;
1487 struct omap_vout_device
*vout
= fh
;
1488 struct videobuf_queue
*q
= &vout
->vbq
;
1490 if ((req
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
) || (req
->count
< 0))
1492 /* if memory is not mmp or userptr
1494 if ((V4L2_MEMORY_MMAP
!= req
->memory
) &&
1495 (V4L2_MEMORY_USERPTR
!= req
->memory
))
1498 mutex_lock(&vout
->lock
);
1499 /* Cannot be requested when streaming is on */
1500 if (vout
->streaming
) {
1505 /* If buffers are already allocated free them */
1506 if (q
->bufs
[0] && (V4L2_MEMORY_MMAP
== q
->bufs
[0]->memory
)) {
1507 if (vout
->mmap_count
) {
1511 num_buffers
= (vout
->vid
== OMAP_VIDEO1
) ?
1512 video1_numbuffers
: video2_numbuffers
;
1513 for (i
= num_buffers
; i
< vout
->buffer_allocated
; i
++) {
1514 omap_vout_free_buffer(vout
->buf_virt_addr
[i
],
1516 vout
->buf_virt_addr
[i
] = 0;
1517 vout
->buf_phy_addr
[i
] = 0;
1519 vout
->buffer_allocated
= num_buffers
;
1520 videobuf_mmap_free(q
);
1521 } else if (q
->bufs
[0] && (V4L2_MEMORY_USERPTR
== q
->bufs
[0]->memory
)) {
1522 if (vout
->buffer_allocated
) {
1523 videobuf_mmap_free(q
);
1524 for (i
= 0; i
< vout
->buffer_allocated
; i
++) {
1528 vout
->buffer_allocated
= 0;
1532 /*store the memory type in data structure */
1533 vout
->memory
= req
->memory
;
1535 INIT_LIST_HEAD(&vout
->dma_queue
);
1537 /* call videobuf_reqbufs api */
1538 ret
= videobuf_reqbufs(q
, req
);
1542 vout
->buffer_allocated
= req
->count
;
1545 mutex_unlock(&vout
->lock
);
1549 static int vidioc_querybuf(struct file
*file
, void *fh
,
1550 struct v4l2_buffer
*b
)
1552 struct omap_vout_device
*vout
= fh
;
1554 return videobuf_querybuf(&vout
->vbq
, b
);
1557 static int vidioc_qbuf(struct file
*file
, void *fh
,
1558 struct v4l2_buffer
*buffer
)
1560 struct omap_vout_device
*vout
= fh
;
1561 struct videobuf_queue
*q
= &vout
->vbq
;
1563 if ((V4L2_BUF_TYPE_VIDEO_OUTPUT
!= buffer
->type
) ||
1564 (buffer
->index
>= vout
->buffer_allocated
) ||
1565 (q
->bufs
[buffer
->index
]->memory
!= buffer
->memory
)) {
1568 if (V4L2_MEMORY_USERPTR
== buffer
->memory
) {
1569 if ((buffer
->length
< vout
->pix
.sizeimage
) ||
1570 (0 == buffer
->m
.userptr
)) {
1575 if ((is_rotation_enabled(vout
)) &&
1576 vout
->vrfb_dma_tx
.req_status
== DMA_CHAN_NOT_ALLOTED
) {
1577 v4l2_warn(&vout
->vid_dev
->v4l2_dev
,
1578 "DMA Channel not allocated for Rotation\n");
1582 return videobuf_qbuf(q
, buffer
);
1585 static int vidioc_dqbuf(struct file
*file
, void *fh
, struct v4l2_buffer
*b
)
1587 struct omap_vout_device
*vout
= fh
;
1588 struct videobuf_queue
*q
= &vout
->vbq
;
1593 struct videobuf_buffer
*vb
;
1595 vb
= q
->bufs
[b
->index
];
1597 if (!vout
->streaming
)
1600 if (file
->f_flags
& O_NONBLOCK
)
1601 /* Call videobuf_dqbuf for non blocking mode */
1602 ret
= videobuf_dqbuf(q
, (struct v4l2_buffer
*)b
, 1);
1604 /* Call videobuf_dqbuf for blocking mode */
1605 ret
= videobuf_dqbuf(q
, (struct v4l2_buffer
*)b
, 0);
1607 addr
= (unsigned long) vout
->buf_phy_addr
[vb
->i
];
1608 size
= (unsigned long) vb
->size
;
1609 dma_unmap_single(vout
->vid_dev
->v4l2_dev
.dev
, addr
,
1610 size
, DMA_TO_DEVICE
);
1614 static int vidioc_streamon(struct file
*file
, void *fh
, enum v4l2_buf_type i
)
1617 u32 addr
= 0, mask
= 0;
1618 struct omap_vout_device
*vout
= fh
;
1619 struct videobuf_queue
*q
= &vout
->vbq
;
1620 struct omapvideo_info
*ovid
= &vout
->vid_info
;
1622 mutex_lock(&vout
->lock
);
1624 if (vout
->streaming
) {
1629 ret
= videobuf_streamon(q
);
1633 if (list_empty(&vout
->dma_queue
)) {
1638 /* Get the next frame from the buffer queue */
1639 vout
->next_frm
= vout
->cur_frm
= list_entry(vout
->dma_queue
.next
,
1640 struct videobuf_buffer
, queue
);
1641 /* Remove buffer from the buffer queue */
1642 list_del(&vout
->cur_frm
->queue
);
1643 /* Mark state of the current frame to active */
1644 vout
->cur_frm
->state
= VIDEOBUF_ACTIVE
;
1645 /* Initialize field_id and started member */
1648 /* set flag here. Next QBUF will start DMA */
1649 vout
->streaming
= 1;
1651 vout
->first_int
= 1;
1653 if (omap_vout_calculate_offset(vout
)) {
1657 addr
= (unsigned long) vout
->queued_buf_addr
[vout
->cur_frm
->i
]
1658 + vout
->cropped_offset
;
1660 mask
= DISPC_IRQ_VSYNC
| DISPC_IRQ_EVSYNC_EVEN
| DISPC_IRQ_EVSYNC_ODD
1663 omap_dispc_register_isr(omap_vout_isr
, vout
, mask
);
1665 for (j
= 0; j
< ovid
->num_overlays
; j
++) {
1666 struct omap_overlay
*ovl
= ovid
->overlays
[j
];
1668 if (ovl
->manager
&& ovl
->manager
->device
) {
1669 struct omap_overlay_info info
;
1670 ovl
->get_overlay_info(ovl
, &info
);
1673 if (ovl
->set_overlay_info(ovl
, &info
)) {
1680 /* First save the configuration in ovelray structure */
1681 ret
= omapvid_init(vout
, addr
);
1683 v4l2_err(&vout
->vid_dev
->v4l2_dev
,
1684 "failed to set overlay info\n");
1685 /* Enable the pipeline and set the Go bit */
1686 ret
= omapvid_apply_changes(vout
);
1688 v4l2_err(&vout
->vid_dev
->v4l2_dev
, "failed to change mode\n");
1694 ret
= videobuf_streamoff(q
);
1696 mutex_unlock(&vout
->lock
);
1700 static int vidioc_streamoff(struct file
*file
, void *fh
, enum v4l2_buf_type i
)
1704 struct omap_vout_device
*vout
= fh
;
1705 struct omapvideo_info
*ovid
= &vout
->vid_info
;
1707 if (!vout
->streaming
)
1710 vout
->streaming
= 0;
1711 mask
= DISPC_IRQ_VSYNC
| DISPC_IRQ_EVSYNC_EVEN
| DISPC_IRQ_EVSYNC_ODD
1714 omap_dispc_unregister_isr(omap_vout_isr
, vout
, mask
);
1716 for (j
= 0; j
< ovid
->num_overlays
; j
++) {
1717 struct omap_overlay
*ovl
= ovid
->overlays
[j
];
1719 if (ovl
->manager
&& ovl
->manager
->device
) {
1720 struct omap_overlay_info info
;
1722 ovl
->get_overlay_info(ovl
, &info
);
1724 ret
= ovl
->set_overlay_info(ovl
, &info
);
1726 v4l2_err(&vout
->vid_dev
->v4l2_dev
,
1727 "failed to update overlay info in streamoff\n");
1731 /* Turn of the pipeline */
1732 ret
= omapvid_apply_changes(vout
);
1734 v4l2_err(&vout
->vid_dev
->v4l2_dev
, "failed to change mode in"
1737 INIT_LIST_HEAD(&vout
->dma_queue
);
1738 ret
= videobuf_streamoff(&vout
->vbq
);
1743 static int vidioc_s_fbuf(struct file
*file
, void *fh
,
1744 struct v4l2_framebuffer
*a
)
1747 struct omap_overlay
*ovl
;
1748 struct omapvideo_info
*ovid
;
1749 struct omap_vout_device
*vout
= fh
;
1750 struct omap_overlay_manager_info info
;
1751 enum omap_dss_trans_key_type key_type
= OMAP_DSS_COLOR_KEY_GFX_DST
;
1753 ovid
= &vout
->vid_info
;
1754 ovl
= ovid
->overlays
[0];
1756 /* OMAP DSS doesn't support Source and Destination color
1758 if ((a
->flags
& V4L2_FBUF_FLAG_SRC_CHROMAKEY
) &&
1759 (a
->flags
& V4L2_FBUF_FLAG_CHROMAKEY
))
1761 /* OMAP DSS Doesn't support the Destination color key
1762 and alpha blending together */
1763 if ((a
->flags
& V4L2_FBUF_FLAG_CHROMAKEY
) &&
1764 (a
->flags
& V4L2_FBUF_FLAG_LOCAL_ALPHA
))
1767 if ((a
->flags
& V4L2_FBUF_FLAG_SRC_CHROMAKEY
)) {
1768 vout
->fbuf
.flags
|= V4L2_FBUF_FLAG_SRC_CHROMAKEY
;
1769 key_type
= OMAP_DSS_COLOR_KEY_VID_SRC
;
1771 vout
->fbuf
.flags
&= ~V4L2_FBUF_FLAG_SRC_CHROMAKEY
;
1773 if ((a
->flags
& V4L2_FBUF_FLAG_CHROMAKEY
)) {
1774 vout
->fbuf
.flags
|= V4L2_FBUF_FLAG_CHROMAKEY
;
1775 key_type
= OMAP_DSS_COLOR_KEY_GFX_DST
;
1777 vout
->fbuf
.flags
&= ~V4L2_FBUF_FLAG_CHROMAKEY
;
1779 if (a
->flags
& (V4L2_FBUF_FLAG_CHROMAKEY
|
1780 V4L2_FBUF_FLAG_SRC_CHROMAKEY
))
1784 if (ovl
->manager
&& ovl
->manager
->get_manager_info
&&
1785 ovl
->manager
->set_manager_info
) {
1787 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1788 info
.trans_enabled
= enable
;
1789 info
.trans_key_type
= key_type
;
1790 info
.trans_key
= vout
->win
.chromakey
;
1792 if (ovl
->manager
->set_manager_info(ovl
->manager
, &info
))
1795 if (a
->flags
& V4L2_FBUF_FLAG_LOCAL_ALPHA
) {
1796 vout
->fbuf
.flags
|= V4L2_FBUF_FLAG_LOCAL_ALPHA
;
1799 vout
->fbuf
.flags
&= ~V4L2_FBUF_FLAG_LOCAL_ALPHA
;
1802 if (ovl
->manager
&& ovl
->manager
->get_manager_info
&&
1803 ovl
->manager
->set_manager_info
) {
1804 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1805 /* enable this only if there is no zorder cap */
1806 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_ZORDER
) == 0)
1807 info
.partial_alpha_enabled
= enable
;
1808 if (ovl
->manager
->set_manager_info(ovl
->manager
, &info
))
1815 static int vidioc_g_fbuf(struct file
*file
, void *fh
,
1816 struct v4l2_framebuffer
*a
)
1818 struct omap_overlay
*ovl
;
1819 struct omapvideo_info
*ovid
;
1820 struct omap_vout_device
*vout
= fh
;
1821 struct omap_overlay_manager_info info
;
1823 ovid
= &vout
->vid_info
;
1824 ovl
= ovid
->overlays
[0];
1827 a
->capability
= V4L2_FBUF_CAP_LOCAL_ALPHA
| V4L2_FBUF_CAP_CHROMAKEY
1828 | V4L2_FBUF_CAP_SRC_CHROMAKEY
;
1830 if (ovl
->manager
&& ovl
->manager
->get_manager_info
) {
1831 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1832 if (info
.trans_key_type
== OMAP_DSS_COLOR_KEY_VID_SRC
)
1833 a
->flags
|= V4L2_FBUF_FLAG_SRC_CHROMAKEY
;
1834 if (info
.trans_key_type
== OMAP_DSS_COLOR_KEY_GFX_DST
)
1835 a
->flags
|= V4L2_FBUF_FLAG_CHROMAKEY
;
1837 if (ovl
->manager
&& ovl
->manager
->get_manager_info
) {
1838 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1839 if (info
.partial_alpha_enabled
)
1840 a
->flags
|= V4L2_FBUF_FLAG_LOCAL_ALPHA
;
1846 static const struct v4l2_ioctl_ops vout_ioctl_ops
= {
1847 .vidioc_querycap
= vidioc_querycap
,
1848 .vidioc_enum_fmt_vid_out
= vidioc_enum_fmt_vid_out
,
1849 .vidioc_g_fmt_vid_out
= vidioc_g_fmt_vid_out
,
1850 .vidioc_try_fmt_vid_out
= vidioc_try_fmt_vid_out
,
1851 .vidioc_s_fmt_vid_out
= vidioc_s_fmt_vid_out
,
1852 .vidioc_queryctrl
= vidioc_queryctrl
,
1853 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1854 .vidioc_s_fbuf
= vidioc_s_fbuf
,
1855 .vidioc_g_fbuf
= vidioc_g_fbuf
,
1856 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1857 .vidioc_try_fmt_vid_overlay
= vidioc_try_fmt_vid_overlay
,
1858 .vidioc_s_fmt_vid_overlay
= vidioc_s_fmt_vid_overlay
,
1859 .vidioc_enum_fmt_vid_overlay
= vidioc_enum_fmt_vid_overlay
,
1860 .vidioc_g_fmt_vid_overlay
= vidioc_g_fmt_vid_overlay
,
1861 .vidioc_cropcap
= vidioc_cropcap
,
1862 .vidioc_g_crop
= vidioc_g_crop
,
1863 .vidioc_s_crop
= vidioc_s_crop
,
1864 .vidioc_reqbufs
= vidioc_reqbufs
,
1865 .vidioc_querybuf
= vidioc_querybuf
,
1866 .vidioc_qbuf
= vidioc_qbuf
,
1867 .vidioc_dqbuf
= vidioc_dqbuf
,
1868 .vidioc_streamon
= vidioc_streamon
,
1869 .vidioc_streamoff
= vidioc_streamoff
,
1872 static const struct v4l2_file_operations omap_vout_fops
= {
1873 .owner
= THIS_MODULE
,
1874 .poll
= omap_vout_poll
,
1875 .unlocked_ioctl
= video_ioctl2
,
1876 .mmap
= omap_vout_mmap
,
1877 .open
= omap_vout_open
,
1878 .release
= omap_vout_release
,
1881 /* Init functions used during driver initialization */
1882 /* Initial setup of video_data */
1883 static int __init
omap_vout_setup_video_data(struct omap_vout_device
*vout
)
1885 struct video_device
*vfd
;
1886 struct v4l2_pix_format
*pix
;
1887 struct v4l2_control
*control
;
1888 struct omap_dss_device
*display
=
1889 vout
->vid_info
.overlays
[0]->manager
->device
;
1891 /* set the default pix */
1894 /* Set the default picture of QVGA */
1895 pix
->width
= QQVGA_WIDTH
;
1896 pix
->height
= QQVGA_HEIGHT
;
1898 /* Default pixel format is RGB 5-6-5 */
1899 pix
->pixelformat
= V4L2_PIX_FMT_RGB565
;
1900 pix
->field
= V4L2_FIELD_ANY
;
1901 pix
->bytesperline
= pix
->width
* 2;
1902 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
1904 pix
->colorspace
= V4L2_COLORSPACE_JPEG
;
1906 vout
->bpp
= RGB565_BPP
;
1907 vout
->fbuf
.fmt
.width
= display
->panel
.timings
.x_res
;
1908 vout
->fbuf
.fmt
.height
= display
->panel
.timings
.y_res
;
1910 /* Set the data structures for the overlay parameters*/
1911 vout
->win
.global_alpha
= 255;
1912 vout
->fbuf
.flags
= 0;
1913 vout
->fbuf
.capability
= V4L2_FBUF_CAP_LOCAL_ALPHA
|
1914 V4L2_FBUF_CAP_SRC_CHROMAKEY
| V4L2_FBUF_CAP_CHROMAKEY
;
1915 vout
->win
.chromakey
= 0;
1917 omap_vout_new_format(pix
, &vout
->fbuf
, &vout
->crop
, &vout
->win
);
1919 /*Initialize the control variables for
1920 rotation, flipping and background color. */
1921 control
= vout
->control
;
1922 control
[0].id
= V4L2_CID_ROTATE
;
1923 control
[0].value
= 0;
1926 vout
->control
[2].id
= V4L2_CID_HFLIP
;
1927 vout
->control
[2].value
= 0;
1928 if (vout
->vid_info
.rotation_type
== VOUT_ROT_VRFB
)
1931 control
[1].id
= V4L2_CID_BG_COLOR
;
1932 control
[1].value
= 0;
1934 /* initialize the video_device struct */
1935 vfd
= vout
->vfd
= video_device_alloc();
1938 printk(KERN_ERR VOUT_NAME
": could not allocate"
1939 " video device struct\n");
1942 vfd
->release
= video_device_release
;
1943 vfd
->ioctl_ops
= &vout_ioctl_ops
;
1945 strlcpy(vfd
->name
, VOUT_NAME
, sizeof(vfd
->name
));
1947 vfd
->fops
= &omap_vout_fops
;
1948 vfd
->v4l2_dev
= &vout
->vid_dev
->v4l2_dev
;
1949 mutex_init(&vout
->lock
);
1956 /* Setup video buffers */
1957 static int __init
omap_vout_setup_video_bufs(struct platform_device
*pdev
,
1962 struct omapvideo_info
*ovid
;
1963 struct omap_vout_device
*vout
;
1964 struct v4l2_device
*v4l2_dev
= platform_get_drvdata(pdev
);
1965 struct omap2video_device
*vid_dev
=
1966 container_of(v4l2_dev
, struct omap2video_device
, v4l2_dev
);
1968 vout
= vid_dev
->vouts
[vid_num
];
1969 ovid
= &vout
->vid_info
;
1971 numbuffers
= (vid_num
== 0) ? video1_numbuffers
: video2_numbuffers
;
1972 vout
->buffer_size
= (vid_num
== 0) ? video1_bufsize
: video2_bufsize
;
1973 dev_info(&pdev
->dev
, "Buffer Size = %d\n", vout
->buffer_size
);
1975 for (i
= 0; i
< numbuffers
; i
++) {
1976 vout
->buf_virt_addr
[i
] =
1977 omap_vout_alloc_buffer(vout
->buffer_size
,
1978 (u32
*) &vout
->buf_phy_addr
[i
]);
1979 if (!vout
->buf_virt_addr
[i
]) {
1986 vout
->cropped_offset
= 0;
1988 if (ovid
->rotation_type
== VOUT_ROT_VRFB
) {
1989 int static_vrfb_allocation
= (vid_num
== 0) ?
1990 vid1_static_vrfb_alloc
: vid2_static_vrfb_alloc
;
1991 ret
= omap_vout_setup_vrfb_bufs(pdev
, vid_num
,
1992 static_vrfb_allocation
);
1998 for (i
= 0; i
< numbuffers
; i
++) {
1999 omap_vout_free_buffer(vout
->buf_virt_addr
[i
],
2001 vout
->buf_virt_addr
[i
] = 0;
2002 vout
->buf_phy_addr
[i
] = 0;
2008 /* Create video out devices */
2009 static int __init
omap_vout_create_video_devices(struct platform_device
*pdev
)
2012 struct omap_vout_device
*vout
;
2013 struct video_device
*vfd
= NULL
;
2014 struct v4l2_device
*v4l2_dev
= platform_get_drvdata(pdev
);
2015 struct omap2video_device
*vid_dev
= container_of(v4l2_dev
,
2016 struct omap2video_device
, v4l2_dev
);
2018 for (k
= 0; k
< pdev
->num_resources
; k
++) {
2020 vout
= kzalloc(sizeof(struct omap_vout_device
), GFP_KERNEL
);
2022 dev_err(&pdev
->dev
, ": could not allocate memory\n");
2027 vid_dev
->vouts
[k
] = vout
;
2028 vout
->vid_dev
= vid_dev
;
2029 /* Select video2 if only 1 overlay is controlled by V4L2 */
2030 if (pdev
->num_resources
== 1)
2031 vout
->vid_info
.overlays
[0] = vid_dev
->overlays
[k
+ 2];
2033 /* Else select video1 and video2 one by one. */
2034 vout
->vid_info
.overlays
[0] = vid_dev
->overlays
[k
+ 1];
2035 vout
->vid_info
.num_overlays
= 1;
2036 vout
->vid_info
.id
= k
+ 1;
2038 /* Set VRFB as rotation_type for omap2 and omap3 */
2039 if (cpu_is_omap24xx() || cpu_is_omap34xx())
2040 vout
->vid_info
.rotation_type
= VOUT_ROT_VRFB
;
2042 /* Setup the default configuration for the video devices
2044 if (omap_vout_setup_video_data(vout
) != 0) {
2049 /* Allocate default number of buffers for the video streaming
2050 * and reserve the VRFB space for rotation
2052 if (omap_vout_setup_video_bufs(pdev
, k
) != 0) {
2057 /* Register the Video device with V4L2
2060 if (video_register_device(vfd
, VFL_TYPE_GRABBER
, -1) < 0) {
2061 dev_err(&pdev
->dev
, ": Could not register "
2062 "Video for Linux device\n");
2067 video_set_drvdata(vfd
, vout
);
2069 /* Configure the overlay structure */
2070 ret
= omapvid_init(vid_dev
->vouts
[k
], 0);
2075 if (vout
->vid_info
.rotation_type
== VOUT_ROT_VRFB
)
2076 omap_vout_release_vrfb(vout
);
2077 omap_vout_free_buffers(vout
);
2079 video_device_release(vfd
);
2085 dev_info(&pdev
->dev
, ": registered and initialized"
2086 " video device %d\n", vfd
->minor
);
2087 if (k
== (pdev
->num_resources
- 1))
2093 /* Driver functions */
2094 static void omap_vout_cleanup_device(struct omap_vout_device
*vout
)
2096 struct video_device
*vfd
;
2097 struct omapvideo_info
*ovid
;
2103 ovid
= &vout
->vid_info
;
2105 if (!video_is_registered(vfd
)) {
2107 * The device was never registered, so release the
2108 * video_device struct directly.
2110 video_device_release(vfd
);
2113 * The unregister function will release the video_device
2114 * struct as well as unregistering it.
2116 video_unregister_device(vfd
);
2119 if (ovid
->rotation_type
== VOUT_ROT_VRFB
) {
2120 omap_vout_release_vrfb(vout
);
2121 /* Free the VRFB buffer if allocated
2124 if (vout
->vrfb_static_allocation
)
2125 omap_vout_free_vrfb_buffers(vout
);
2127 omap_vout_free_buffers(vout
);
2132 static int omap_vout_remove(struct platform_device
*pdev
)
2135 struct v4l2_device
*v4l2_dev
= platform_get_drvdata(pdev
);
2136 struct omap2video_device
*vid_dev
= container_of(v4l2_dev
, struct
2137 omap2video_device
, v4l2_dev
);
2139 v4l2_device_unregister(v4l2_dev
);
2140 for (k
= 0; k
< pdev
->num_resources
; k
++)
2141 omap_vout_cleanup_device(vid_dev
->vouts
[k
]);
2143 for (k
= 0; k
< vid_dev
->num_displays
; k
++) {
2144 if (vid_dev
->displays
[k
]->state
!= OMAP_DSS_DISPLAY_DISABLED
)
2145 vid_dev
->displays
[k
]->driver
->disable(vid_dev
->displays
[k
]);
2147 omap_dss_put_device(vid_dev
->displays
[k
]);
2153 static int __init
omap_vout_probe(struct platform_device
*pdev
)
2156 struct omap_overlay
*ovl
;
2157 struct omap_dss_device
*dssdev
= NULL
;
2158 struct omap_dss_device
*def_display
;
2159 struct omap2video_device
*vid_dev
= NULL
;
2161 if (pdev
->num_resources
== 0) {
2162 dev_err(&pdev
->dev
, "probed for an unknown device\n");
2166 vid_dev
= kzalloc(sizeof(struct omap2video_device
), GFP_KERNEL
);
2167 if (vid_dev
== NULL
)
2170 vid_dev
->num_displays
= 0;
2171 for_each_dss_dev(dssdev
) {
2172 omap_dss_get_device(dssdev
);
2174 if (!dssdev
->driver
) {
2175 dev_warn(&pdev
->dev
, "no driver for display: %s\n",
2177 omap_dss_put_device(dssdev
);
2181 vid_dev
->displays
[vid_dev
->num_displays
++] = dssdev
;
2184 if (vid_dev
->num_displays
== 0) {
2185 dev_err(&pdev
->dev
, "no displays\n");
2190 vid_dev
->num_overlays
= omap_dss_get_num_overlays();
2191 for (i
= 0; i
< vid_dev
->num_overlays
; i
++)
2192 vid_dev
->overlays
[i
] = omap_dss_get_overlay(i
);
2194 vid_dev
->num_managers
= omap_dss_get_num_overlay_managers();
2195 for (i
= 0; i
< vid_dev
->num_managers
; i
++)
2196 vid_dev
->managers
[i
] = omap_dss_get_overlay_manager(i
);
2198 /* Get the Video1 overlay and video2 overlay.
2199 * Setup the Display attached to that overlays
2201 for (i
= 1; i
< vid_dev
->num_overlays
; i
++) {
2202 ovl
= omap_dss_get_overlay(i
);
2203 if (ovl
->manager
&& ovl
->manager
->device
) {
2204 def_display
= ovl
->manager
->device
;
2206 dev_warn(&pdev
->dev
, "cannot find display\n");
2210 struct omap_dss_driver
*dssdrv
= def_display
->driver
;
2212 ret
= dssdrv
->enable(def_display
);
2214 /* Here we are not considering a error
2215 * as display may be enabled by frame
2218 dev_warn(&pdev
->dev
,
2219 "'%s' Display already enabled\n",
2225 if (v4l2_device_register(&pdev
->dev
, &vid_dev
->v4l2_dev
) < 0) {
2226 dev_err(&pdev
->dev
, "v4l2_device_register failed\n");
2231 ret
= omap_vout_create_video_devices(pdev
);
2235 for (i
= 0; i
< vid_dev
->num_displays
; i
++) {
2236 struct omap_dss_device
*display
= vid_dev
->displays
[i
];
2238 if (display
->driver
->update
)
2239 display
->driver
->update(display
, 0, 0,
2240 display
->panel
.timings
.x_res
,
2241 display
->panel
.timings
.y_res
);
2246 v4l2_device_unregister(&vid_dev
->v4l2_dev
);
2248 for (i
= 1; i
< vid_dev
->num_overlays
; i
++) {
2250 ovl
= omap_dss_get_overlay(i
);
2251 if (ovl
->manager
&& ovl
->manager
->device
)
2252 def_display
= ovl
->manager
->device
;
2254 if (def_display
&& def_display
->driver
)
2255 def_display
->driver
->disable(def_display
);
2262 static struct platform_driver omap_vout_driver
= {
2266 .probe
= omap_vout_probe
,
2267 .remove
= omap_vout_remove
,
2270 static int __init
omap_vout_init(void)
2272 if (platform_driver_register(&omap_vout_driver
) != 0) {
2273 printk(KERN_ERR VOUT_NAME
":Could not register Video driver\n");
2279 static void omap_vout_cleanup(void)
2281 platform_driver_unregister(&omap_vout_driver
);
2284 late_initcall(omap_vout_init
);
2285 module_exit(omap_vout_cleanup
);