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/dma-mapping.h>
39 #include <linux/irq.h>
40 #include <linux/videodev2.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/vram.h>
49 #include <plat/vrfb.h>
50 #include <video/omapdss.h>
52 #include "omap_voutlib.h"
53 #include "omap_voutdef.h"
55 MODULE_AUTHOR("Texas Instruments");
56 MODULE_DESCRIPTION("OMAP Video for Linux Video out driver");
57 MODULE_LICENSE("GPL");
60 /* Driver Configuration macros */
61 #define VOUT_NAME "omap_vout"
63 enum omap_vout_channels
{
68 enum dma_channel_state
{
73 #define QQVGA_WIDTH 160
74 #define QQVGA_HEIGHT 120
76 /* Max Resolution supported by the driver */
77 #define VID_MAX_WIDTH 1280 /* Largest width */
78 #define VID_MAX_HEIGHT 720 /* Largest height */
80 /* Mimimum requirement is 2x2 for DSS */
81 #define VID_MIN_WIDTH 2
82 #define VID_MIN_HEIGHT 2
84 /* 2048 x 2048 is max res supported by OMAP display controller */
85 #define MAX_PIXELS_PER_LINE 2048
87 #define VRFB_TX_TIMEOUT 1000
88 #define VRFB_NUM_BUFS 4
90 /* Max buffer size tobe allocated during init */
91 #define OMAP_VOUT_MAX_BUF_SIZE (VID_MAX_WIDTH*VID_MAX_HEIGHT*4)
93 static struct videobuf_queue_ops video_vbq_ops
;
94 /* Variables configurable through module params*/
95 static u32 video1_numbuffers
= 3;
96 static u32 video2_numbuffers
= 3;
97 static u32 video1_bufsize
= OMAP_VOUT_MAX_BUF_SIZE
;
98 static u32 video2_bufsize
= OMAP_VOUT_MAX_BUF_SIZE
;
99 static u32 vid1_static_vrfb_alloc
;
100 static u32 vid2_static_vrfb_alloc
;
103 /* Module parameters */
104 module_param(video1_numbuffers
, uint
, S_IRUGO
);
105 MODULE_PARM_DESC(video1_numbuffers
,
106 "Number of buffers to be allocated at init time for Video1 device.");
108 module_param(video2_numbuffers
, uint
, S_IRUGO
);
109 MODULE_PARM_DESC(video2_numbuffers
,
110 "Number of buffers to be allocated at init time for Video2 device.");
112 module_param(video1_bufsize
, uint
, S_IRUGO
);
113 MODULE_PARM_DESC(video1_bufsize
,
114 "Size of the buffer to be allocated for video1 device");
116 module_param(video2_bufsize
, uint
, S_IRUGO
);
117 MODULE_PARM_DESC(video2_bufsize
,
118 "Size of the buffer to be allocated for video2 device");
120 module_param(vid1_static_vrfb_alloc
, bool, S_IRUGO
);
121 MODULE_PARM_DESC(vid1_static_vrfb_alloc
,
122 "Static allocation of the VRFB buffer for video1 device");
124 module_param(vid2_static_vrfb_alloc
, bool, S_IRUGO
);
125 MODULE_PARM_DESC(vid2_static_vrfb_alloc
,
126 "Static allocation of the VRFB buffer for video2 device");
128 module_param(debug
, bool, S_IRUGO
);
129 MODULE_PARM_DESC(debug
, "Debug level (0-1)");
131 /* list of image formats supported by OMAP2 video pipelines */
132 static const struct v4l2_fmtdesc omap_formats
[] = {
134 /* Note: V4L2 defines RGB565 as:
137 * g2 g1 g0 r4 r3 r2 r1 r0 b4 b3 b2 b1 b0 g5 g4 g3
139 * We interpret RGB565 as:
142 * g2 g1 g0 b4 b3 b2 b1 b0 r4 r3 r2 r1 r0 g5 g4 g3
144 .description
= "RGB565, le",
145 .pixelformat
= V4L2_PIX_FMT_RGB565
,
148 /* Note: V4L2 defines RGB32 as: RGB-8-8-8-8 we use
149 * this for RGB24 unpack mode, the last 8 bits are ignored
151 .description
= "RGB32, le",
152 .pixelformat
= V4L2_PIX_FMT_RGB32
,
155 /* Note: V4L2 defines RGB24 as: RGB-8-8-8 we use
156 * this for RGB24 packed mode
159 .description
= "RGB24, le",
160 .pixelformat
= V4L2_PIX_FMT_RGB24
,
163 .description
= "YUYV (YUV 4:2:2), packed",
164 .pixelformat
= V4L2_PIX_FMT_YUYV
,
167 .description
= "UYVY, packed",
168 .pixelformat
= V4L2_PIX_FMT_UYVY
,
172 #define NUM_OUTPUT_FORMATS (ARRAY_SIZE(omap_formats))
177 static unsigned long omap_vout_alloc_buffer(u32 buf_size
, u32
*phys_addr
)
180 unsigned long virt_addr
, addr
;
182 size
= PAGE_ALIGN(buf_size
);
183 order
= get_order(size
);
184 virt_addr
= __get_free_pages(GFP_KERNEL
| GFP_DMA
, order
);
189 SetPageReserved(virt_to_page(addr
));
194 *phys_addr
= (u32
) virt_to_phys((void *) virt_addr
);
201 static void omap_vout_free_buffer(unsigned long virtaddr
, u32 buf_size
)
204 unsigned long addr
= virtaddr
;
206 size
= PAGE_ALIGN(buf_size
);
207 order
= get_order(size
);
210 ClearPageReserved(virt_to_page(addr
));
214 free_pages((unsigned long) virtaddr
, order
);
218 * Function for allocating video buffers
220 static int omap_vout_allocate_vrfb_buffers(struct omap_vout_device
*vout
,
221 unsigned int *count
, int startindex
)
225 for (i
= 0; i
< *count
; i
++) {
226 if (!vout
->smsshado_virt_addr
[i
]) {
227 vout
->smsshado_virt_addr
[i
] =
228 omap_vout_alloc_buffer(vout
->smsshado_size
,
229 &vout
->smsshado_phy_addr
[i
]);
231 if (!vout
->smsshado_virt_addr
[i
] && startindex
!= -1) {
232 if (V4L2_MEMORY_MMAP
== vout
->memory
&& i
>= startindex
)
235 if (!vout
->smsshado_virt_addr
[i
]) {
236 for (j
= 0; j
< i
; j
++) {
237 omap_vout_free_buffer(
238 vout
->smsshado_virt_addr
[j
],
239 vout
->smsshado_size
);
240 vout
->smsshado_virt_addr
[j
] = 0;
241 vout
->smsshado_phy_addr
[j
] = 0;
246 memset((void *) vout
->smsshado_virt_addr
[i
], 0,
247 vout
->smsshado_size
);
255 static int omap_vout_try_format(struct v4l2_pix_format
*pix
)
259 pix
->height
= clamp(pix
->height
, (u32
)VID_MIN_HEIGHT
,
260 (u32
)VID_MAX_HEIGHT
);
261 pix
->width
= clamp(pix
->width
, (u32
)VID_MIN_WIDTH
, (u32
)VID_MAX_WIDTH
);
263 for (ifmt
= 0; ifmt
< NUM_OUTPUT_FORMATS
; ifmt
++) {
264 if (pix
->pixelformat
== omap_formats
[ifmt
].pixelformat
)
268 if (ifmt
== NUM_OUTPUT_FORMATS
)
271 pix
->pixelformat
= omap_formats
[ifmt
].pixelformat
;
272 pix
->field
= V4L2_FIELD_ANY
;
275 switch (pix
->pixelformat
) {
276 case V4L2_PIX_FMT_YUYV
:
277 case V4L2_PIX_FMT_UYVY
:
279 pix
->colorspace
= V4L2_COLORSPACE_JPEG
;
282 case V4L2_PIX_FMT_RGB565
:
283 case V4L2_PIX_FMT_RGB565X
:
284 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
287 case V4L2_PIX_FMT_RGB24
:
288 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
291 case V4L2_PIX_FMT_RGB32
:
292 case V4L2_PIX_FMT_BGR32
:
293 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
297 pix
->bytesperline
= pix
->width
* bpp
;
298 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
304 * omap_vout_uservirt_to_phys: This inline function is used to convert user
305 * space virtual address to physical address.
307 static u32
omap_vout_uservirt_to_phys(u32 virtp
)
309 unsigned long physp
= 0;
310 struct vm_area_struct
*vma
;
311 struct mm_struct
*mm
= current
->mm
;
313 vma
= find_vma(mm
, virtp
);
314 /* For kernel direct-mapped memory, take the easy way */
315 if (virtp
>= PAGE_OFFSET
) {
316 physp
= virt_to_phys((void *) virtp
);
317 } else if (vma
&& (vma
->vm_flags
& VM_IO
) && vma
->vm_pgoff
) {
318 /* this will catch, kernel-allocated, mmaped-to-usermode
320 physp
= (vma
->vm_pgoff
<< PAGE_SHIFT
) + (virtp
- vma
->vm_start
);
322 /* otherwise, use get_user_pages() for general userland pages */
323 int res
, nr_pages
= 1;
325 down_read(¤t
->mm
->mmap_sem
);
327 res
= get_user_pages(current
, current
->mm
, virtp
, nr_pages
, 1,
329 up_read(¤t
->mm
->mmap_sem
);
331 if (res
== nr_pages
) {
332 physp
= __pa(page_address(&pages
[0]) +
333 (virtp
& ~PAGE_MASK
));
335 printk(KERN_WARNING VOUT_NAME
336 "get_user_pages failed\n");
345 * Wakes up the application once the DMA transfer to VRFB space is completed.
347 static void omap_vout_vrfb_dma_tx_callback(int lch
, u16 ch_status
, void *data
)
349 struct vid_vrfb_dma
*t
= (struct vid_vrfb_dma
*) data
;
352 wake_up_interruptible(&t
->wait
);
356 * Release the VRFB context once the module exits
358 static void omap_vout_release_vrfb(struct omap_vout_device
*vout
)
362 for (i
= 0; i
< VRFB_NUM_BUFS
; i
++)
363 omap_vrfb_release_ctx(&vout
->vrfb_context
[i
]);
365 if (vout
->vrfb_dma_tx
.req_status
== DMA_CHAN_ALLOTED
) {
366 vout
->vrfb_dma_tx
.req_status
= DMA_CHAN_NOT_ALLOTED
;
367 omap_free_dma(vout
->vrfb_dma_tx
.dma_ch
);
372 * Return true if rotation is 90 or 270
374 static inline int rotate_90_or_270(const struct omap_vout_device
*vout
)
376 return (vout
->rotation
== dss_rotation_90_degree
||
377 vout
->rotation
== dss_rotation_270_degree
);
381 * Return true if rotation is enabled
383 static inline int rotation_enabled(const struct omap_vout_device
*vout
)
385 return vout
->rotation
|| vout
->mirror
;
389 * Reverse the rotation degree if mirroring is enabled
391 static inline int calc_rotation(const struct omap_vout_device
*vout
)
394 return vout
->rotation
;
396 switch (vout
->rotation
) {
397 case dss_rotation_90_degree
:
398 return dss_rotation_270_degree
;
399 case dss_rotation_270_degree
:
400 return dss_rotation_90_degree
;
401 case dss_rotation_180_degree
:
402 return dss_rotation_0_degree
;
404 return dss_rotation_180_degree
;
409 * Free the V4L2 buffers
411 static void omap_vout_free_buffers(struct omap_vout_device
*vout
)
415 /* Allocate memory for the buffers */
416 numbuffers
= (vout
->vid
) ? video2_numbuffers
: video1_numbuffers
;
417 vout
->buffer_size
= (vout
->vid
) ? video2_bufsize
: video1_bufsize
;
419 for (i
= 0; i
< numbuffers
; i
++) {
420 omap_vout_free_buffer(vout
->buf_virt_addr
[i
],
422 vout
->buf_phy_addr
[i
] = 0;
423 vout
->buf_virt_addr
[i
] = 0;
430 static void omap_vout_free_vrfb_buffers(struct omap_vout_device
*vout
)
434 for (j
= 0; j
< VRFB_NUM_BUFS
; j
++) {
435 omap_vout_free_buffer(vout
->smsshado_virt_addr
[j
],
436 vout
->smsshado_size
);
437 vout
->smsshado_virt_addr
[j
] = 0;
438 vout
->smsshado_phy_addr
[j
] = 0;
443 * Allocate the buffers for the VRFB space. Data is copied from V4L2
444 * buffers to the VRFB buffers using the DMA engine.
446 static int omap_vout_vrfb_buffer_setup(struct omap_vout_device
*vout
,
447 unsigned int *count
, unsigned int startindex
)
452 /* Allocate the VRFB buffers only if the buffers are not
453 * allocated during init time.
455 if ((rotation_enabled(vout
)) && !vout
->vrfb_static_allocation
)
456 if (omap_vout_allocate_vrfb_buffers(vout
, count
, startindex
))
459 if (vout
->dss_mode
== OMAP_DSS_COLOR_YUV2
||
460 vout
->dss_mode
== OMAP_DSS_COLOR_UYVY
)
465 for (i
= 0; i
< *count
; i
++)
466 omap_vrfb_setup(&vout
->vrfb_context
[i
],
467 vout
->smsshado_phy_addr
[i
], vout
->pix
.width
,
468 vout
->pix
.height
, vout
->bpp
, yuv_mode
);
474 * Convert V4L2 rotation to DSS rotation
475 * V4L2 understand 0, 90, 180, 270.
476 * Convert to 0, 1, 2 and 3 respectively for DSS
478 static int v4l2_rot_to_dss_rot(int v4l2_rotation
,
479 enum dss_rotation
*rotation
, bool mirror
)
483 switch (v4l2_rotation
) {
485 *rotation
= dss_rotation_90_degree
;
488 *rotation
= dss_rotation_180_degree
;
491 *rotation
= dss_rotation_270_degree
;
494 *rotation
= dss_rotation_0_degree
;
503 * Calculate the buffer offsets from which the streaming should
504 * start. This offset calculation is mainly required because of
505 * the VRFB 32 pixels alignment with rotation.
507 static int omap_vout_calculate_offset(struct omap_vout_device
*vout
)
509 struct omap_overlay
*ovl
;
510 enum dss_rotation rotation
;
511 struct omapvideo_info
*ovid
;
512 bool mirroring
= vout
->mirror
;
513 struct omap_dss_device
*cur_display
;
514 struct v4l2_rect
*crop
= &vout
->crop
;
515 struct v4l2_pix_format
*pix
= &vout
->pix
;
516 int *cropped_offset
= &vout
->cropped_offset
;
517 int vr_ps
= 1, ps
= 2, temp_ps
= 2;
518 int offset
= 0, ctop
= 0, cleft
= 0, line_length
= 0;
520 ovid
= &vout
->vid_info
;
521 ovl
= ovid
->overlays
[0];
522 /* get the display device attached to the overlay */
523 if (!ovl
->manager
|| !ovl
->manager
->device
)
526 cur_display
= ovl
->manager
->device
;
527 rotation
= calc_rotation(vout
);
529 if (V4L2_PIX_FMT_YUYV
== pix
->pixelformat
||
530 V4L2_PIX_FMT_UYVY
== pix
->pixelformat
) {
531 if (rotation_enabled(vout
)) {
533 * ps - Actual pixel size for YUYV/UYVY for
534 * VRFB/Mirroring is 4 bytes
535 * vr_ps - Virtually pixel size for YUYV/UYVY is
541 ps
= 2; /* otherwise the pixel size is 2 byte */
543 } else if (V4L2_PIX_FMT_RGB32
== pix
->pixelformat
) {
545 } else if (V4L2_PIX_FMT_RGB24
== pix
->pixelformat
) {
551 if (rotation_enabled(vout
)) {
552 line_length
= MAX_PIXELS_PER_LINE
;
553 ctop
= (pix
->height
- crop
->height
) - crop
->top
;
554 cleft
= (pix
->width
- crop
->width
) - crop
->left
;
556 line_length
= pix
->width
;
558 vout
->line_length
= line_length
;
560 case dss_rotation_90_degree
:
561 offset
= vout
->vrfb_context
[0].yoffset
*
562 vout
->vrfb_context
[0].bytespp
;
563 temp_ps
= ps
/ vr_ps
;
564 if (mirroring
== 0) {
565 *cropped_offset
= offset
+ line_length
*
566 temp_ps
* cleft
+ crop
->top
* temp_ps
;
568 *cropped_offset
= offset
+ line_length
* temp_ps
*
569 cleft
+ crop
->top
* temp_ps
+ (line_length
*
570 ((crop
->width
/ (vr_ps
)) - 1) * ps
);
573 case dss_rotation_180_degree
:
574 offset
= ((MAX_PIXELS_PER_LINE
* vout
->vrfb_context
[0].yoffset
*
575 vout
->vrfb_context
[0].bytespp
) +
576 (vout
->vrfb_context
[0].xoffset
*
577 vout
->vrfb_context
[0].bytespp
));
578 if (mirroring
== 0) {
579 *cropped_offset
= offset
+ (line_length
* ps
* ctop
) +
580 (cleft
/ vr_ps
) * ps
;
583 *cropped_offset
= offset
+ (line_length
* ps
* ctop
) +
584 (cleft
/ vr_ps
) * ps
+ (line_length
*
585 (crop
->height
- 1) * ps
);
588 case dss_rotation_270_degree
:
589 offset
= MAX_PIXELS_PER_LINE
* vout
->vrfb_context
[0].xoffset
*
590 vout
->vrfb_context
[0].bytespp
;
591 temp_ps
= ps
/ vr_ps
;
592 if (mirroring
== 0) {
593 *cropped_offset
= offset
+ line_length
*
594 temp_ps
* crop
->left
+ ctop
* ps
;
596 *cropped_offset
= offset
+ line_length
*
597 temp_ps
* crop
->left
+ ctop
* ps
+
598 (line_length
* ((crop
->width
/ vr_ps
) - 1) *
602 case dss_rotation_0_degree
:
603 if (mirroring
== 0) {
604 *cropped_offset
= (line_length
* ps
) *
605 crop
->top
+ (crop
->left
/ vr_ps
) * ps
;
607 *cropped_offset
= (line_length
* ps
) *
608 crop
->top
+ (crop
->left
/ vr_ps
) * ps
+
609 (line_length
* (crop
->height
- 1) * ps
);
613 *cropped_offset
= (line_length
* ps
* crop
->top
) /
614 vr_ps
+ (crop
->left
* ps
) / vr_ps
+
615 ((crop
->width
/ vr_ps
) - 1) * ps
;
618 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "%s Offset:%x\n",
619 __func__
, *cropped_offset
);
624 * Convert V4L2 pixel format to DSS pixel format
626 static int video_mode_to_dss_mode(struct omap_vout_device
*vout
)
628 struct omap_overlay
*ovl
;
629 struct omapvideo_info
*ovid
;
630 struct v4l2_pix_format
*pix
= &vout
->pix
;
631 enum omap_color_mode mode
;
633 ovid
= &vout
->vid_info
;
634 ovl
= ovid
->overlays
[0];
636 switch (pix
->pixelformat
) {
639 case V4L2_PIX_FMT_YUYV
:
640 mode
= OMAP_DSS_COLOR_YUV2
;
642 case V4L2_PIX_FMT_UYVY
:
643 mode
= OMAP_DSS_COLOR_UYVY
;
645 case V4L2_PIX_FMT_RGB565
:
646 mode
= OMAP_DSS_COLOR_RGB16
;
648 case V4L2_PIX_FMT_RGB24
:
649 mode
= OMAP_DSS_COLOR_RGB24P
;
651 case V4L2_PIX_FMT_RGB32
:
652 mode
= (ovl
->id
== OMAP_DSS_VIDEO1
) ?
653 OMAP_DSS_COLOR_RGB24U
: OMAP_DSS_COLOR_ARGB32
;
655 case V4L2_PIX_FMT_BGR32
:
656 mode
= OMAP_DSS_COLOR_RGBX32
;
667 int omapvid_setup_overlay(struct omap_vout_device
*vout
,
668 struct omap_overlay
*ovl
, int posx
, int posy
, int outw
,
672 struct omap_overlay_info info
;
673 int cropheight
, cropwidth
, pixheight
, pixwidth
;
675 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_SCALE
) == 0 &&
676 (outw
!= vout
->pix
.width
|| outh
!= vout
->pix
.height
)) {
681 vout
->dss_mode
= video_mode_to_dss_mode(vout
);
682 if (vout
->dss_mode
== -EINVAL
) {
687 /* Setup the input plane parameters according to
688 * rotation value selected.
690 if (rotate_90_or_270(vout
)) {
691 cropheight
= vout
->crop
.width
;
692 cropwidth
= vout
->crop
.height
;
693 pixheight
= vout
->pix
.width
;
694 pixwidth
= vout
->pix
.height
;
696 cropheight
= vout
->crop
.height
;
697 cropwidth
= vout
->crop
.width
;
698 pixheight
= vout
->pix
.height
;
699 pixwidth
= vout
->pix
.width
;
702 ovl
->get_overlay_info(ovl
, &info
);
705 info
.width
= cropwidth
;
706 info
.height
= cropheight
;
707 info
.color_mode
= vout
->dss_mode
;
708 info
.mirror
= vout
->mirror
;
711 info
.out_width
= outw
;
712 info
.out_height
= outh
;
713 info
.global_alpha
= vout
->win
.global_alpha
;
714 if (!rotation_enabled(vout
)) {
716 info
.rotation_type
= OMAP_DSS_ROT_DMA
;
717 info
.screen_width
= pixwidth
;
719 info
.rotation
= vout
->rotation
;
720 info
.rotation_type
= OMAP_DSS_ROT_VRFB
;
721 info
.screen_width
= 2048;
724 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
725 "%s enable=%d addr=%x width=%d\n height=%d color_mode=%d\n"
726 "rotation=%d mirror=%d posx=%d posy=%d out_width = %d \n"
727 "out_height=%d rotation_type=%d screen_width=%d\n",
728 __func__
, info
.enabled
, info
.paddr
, info
.width
, info
.height
,
729 info
.color_mode
, info
.rotation
, info
.mirror
, info
.pos_x
,
730 info
.pos_y
, info
.out_width
, info
.out_height
, info
.rotation_type
,
733 ret
= ovl
->set_overlay_info(ovl
, &info
);
740 v4l2_warn(&vout
->vid_dev
->v4l2_dev
, "setup_overlay failed\n");
745 * Initialize the overlay structure
747 int omapvid_init(struct omap_vout_device
*vout
, u32 addr
)
750 struct v4l2_window
*win
;
751 struct omap_overlay
*ovl
;
752 int posx
, posy
, outw
, outh
, temp
;
753 struct omap_video_timings
*timing
;
754 struct omapvideo_info
*ovid
= &vout
->vid_info
;
757 for (i
= 0; i
< ovid
->num_overlays
; i
++) {
758 ovl
= ovid
->overlays
[i
];
759 if (!ovl
->manager
|| !ovl
->manager
->device
)
762 timing
= &ovl
->manager
->device
->panel
.timings
;
765 outh
= win
->w
.height
;
766 switch (vout
->rotation
) {
767 case dss_rotation_90_degree
:
768 /* Invert the height and width for 90
769 * and 270 degree rotation
774 posy
= (timing
->y_res
- win
->w
.width
) - win
->w
.left
;
778 case dss_rotation_180_degree
:
779 posx
= (timing
->x_res
- win
->w
.width
) - win
->w
.left
;
780 posy
= (timing
->y_res
- win
->w
.height
) - win
->w
.top
;
783 case dss_rotation_270_degree
:
788 posx
= (timing
->x_res
- win
->w
.height
) - win
->w
.top
;
797 ret
= omapvid_setup_overlay(vout
, ovl
, posx
, posy
,
800 goto omapvid_init_err
;
805 v4l2_warn(&vout
->vid_dev
->v4l2_dev
, "apply_changes failed\n");
810 * Apply the changes set the go bit of DSS
812 int omapvid_apply_changes(struct omap_vout_device
*vout
)
815 struct omap_overlay
*ovl
;
816 struct omapvideo_info
*ovid
= &vout
->vid_info
;
818 for (i
= 0; i
< ovid
->num_overlays
; i
++) {
819 ovl
= ovid
->overlays
[i
];
820 if (!ovl
->manager
|| !ovl
->manager
->device
)
822 ovl
->manager
->apply(ovl
->manager
);
828 void omap_vout_isr(void *arg
, unsigned int irqstatus
)
832 struct omap_overlay
*ovl
;
833 struct timeval timevalue
;
834 struct omapvideo_info
*ovid
;
835 struct omap_dss_device
*cur_display
;
836 struct omap_vout_device
*vout
= (struct omap_vout_device
*)arg
;
838 if (!vout
->streaming
)
841 ovid
= &vout
->vid_info
;
842 ovl
= ovid
->overlays
[0];
843 /* get the display device attached to the overlay */
844 if (!ovl
->manager
|| !ovl
->manager
->device
)
847 cur_display
= ovl
->manager
->device
;
849 spin_lock(&vout
->vbq_lock
);
850 do_gettimeofday(&timevalue
);
851 if (cur_display
->type
== OMAP_DISPLAY_TYPE_DPI
) {
852 if (!(irqstatus
& DISPC_IRQ_VSYNC
))
855 if (!vout
->first_int
&& (vout
->cur_frm
!= vout
->next_frm
)) {
856 vout
->cur_frm
->ts
= timevalue
;
857 vout
->cur_frm
->state
= VIDEOBUF_DONE
;
858 wake_up_interruptible(&vout
->cur_frm
->done
);
859 vout
->cur_frm
= vout
->next_frm
;
862 if (list_empty(&vout
->dma_queue
))
865 vout
->next_frm
= list_entry(vout
->dma_queue
.next
,
866 struct videobuf_buffer
, queue
);
867 list_del(&vout
->next_frm
->queue
);
869 vout
->next_frm
->state
= VIDEOBUF_ACTIVE
;
871 addr
= (unsigned long) vout
->queued_buf_addr
[vout
->next_frm
->i
]
872 + vout
->cropped_offset
;
874 /* First save the configuration in ovelray structure */
875 ret
= omapvid_init(vout
, addr
);
877 printk(KERN_ERR VOUT_NAME
878 "failed to set overlay info\n");
879 /* Enable the pipeline and set the Go bit */
880 ret
= omapvid_apply_changes(vout
);
882 printk(KERN_ERR VOUT_NAME
"failed to change mode\n");
885 if (vout
->first_int
) {
889 if (irqstatus
& DISPC_IRQ_EVSYNC_ODD
)
891 else if (irqstatus
& DISPC_IRQ_EVSYNC_EVEN
)
897 if (fid
!= vout
->field_id
) {
899 vout
->field_id
= fid
;
904 if (vout
->cur_frm
== vout
->next_frm
)
907 vout
->cur_frm
->ts
= timevalue
;
908 vout
->cur_frm
->state
= VIDEOBUF_DONE
;
909 wake_up_interruptible(&vout
->cur_frm
->done
);
910 vout
->cur_frm
= vout
->next_frm
;
911 } else if (1 == fid
) {
912 if (list_empty(&vout
->dma_queue
) ||
913 (vout
->cur_frm
!= vout
->next_frm
))
916 vout
->next_frm
= list_entry(vout
->dma_queue
.next
,
917 struct videobuf_buffer
, queue
);
918 list_del(&vout
->next_frm
->queue
);
920 vout
->next_frm
->state
= VIDEOBUF_ACTIVE
;
921 addr
= (unsigned long)
922 vout
->queued_buf_addr
[vout
->next_frm
->i
] +
923 vout
->cropped_offset
;
924 /* First save the configuration in ovelray structure */
925 ret
= omapvid_init(vout
, addr
);
927 printk(KERN_ERR VOUT_NAME
928 "failed to set overlay info\n");
929 /* Enable the pipeline and set the Go bit */
930 ret
= omapvid_apply_changes(vout
);
932 printk(KERN_ERR VOUT_NAME
933 "failed to change mode\n");
939 spin_unlock(&vout
->vbq_lock
);
943 /* Video buffer call backs */
946 * Buffer setup function is called by videobuf layer when REQBUF ioctl is
947 * called. This is used to setup buffers and return size and count of
948 * buffers allocated. After the call to this buffer, videobuf layer will
949 * setup buffer queue depending on the size and count of buffers
951 static int omap_vout_buffer_setup(struct videobuf_queue
*q
, unsigned int *count
,
954 int startindex
= 0, i
, j
;
955 u32 phy_addr
= 0, virt_addr
= 0;
956 struct omap_vout_device
*vout
= q
->priv_data
;
961 if (V4L2_BUF_TYPE_VIDEO_OUTPUT
!= q
->type
)
964 startindex
= (vout
->vid
== OMAP_VIDEO1
) ?
965 video1_numbuffers
: video2_numbuffers
;
966 if (V4L2_MEMORY_MMAP
== vout
->memory
&& *count
< startindex
)
969 if ((rotation_enabled(vout
)) && *count
> VRFB_NUM_BUFS
)
970 *count
= VRFB_NUM_BUFS
;
972 /* If rotation is enabled, allocate memory for VRFB space also */
973 if (rotation_enabled(vout
))
974 if (omap_vout_vrfb_buffer_setup(vout
, count
, startindex
))
977 if (V4L2_MEMORY_MMAP
!= vout
->memory
)
980 /* Now allocated the V4L2 buffers */
981 *size
= PAGE_ALIGN(vout
->pix
.width
* vout
->pix
.height
* vout
->bpp
);
982 startindex
= (vout
->vid
== OMAP_VIDEO1
) ?
983 video1_numbuffers
: video2_numbuffers
;
985 /* Check the size of the buffer */
986 if (*size
> vout
->buffer_size
) {
987 v4l2_err(&vout
->vid_dev
->v4l2_dev
,
988 "buffer allocation mismatch [%u] [%u]\n",
989 *size
, vout
->buffer_size
);
993 for (i
= startindex
; i
< *count
; i
++) {
994 vout
->buffer_size
= *size
;
996 virt_addr
= omap_vout_alloc_buffer(vout
->buffer_size
,
999 if (!rotation_enabled(vout
))
1001 /* Free the VRFB buffers if no space for V4L2 buffers */
1002 for (j
= i
; j
< *count
; j
++) {
1003 omap_vout_free_buffer(
1004 vout
->smsshado_virt_addr
[j
],
1005 vout
->smsshado_size
);
1006 vout
->smsshado_virt_addr
[j
] = 0;
1007 vout
->smsshado_phy_addr
[j
] = 0;
1010 vout
->buf_virt_addr
[i
] = virt_addr
;
1011 vout
->buf_phy_addr
[i
] = phy_addr
;
1013 *count
= vout
->buffer_allocated
= i
;
1019 * Free the V4L2 buffers additionally allocated than default
1020 * number of buffers and free all the VRFB buffers
1022 static void omap_vout_free_allbuffers(struct omap_vout_device
*vout
)
1024 int num_buffers
= 0, i
;
1026 num_buffers
= (vout
->vid
== OMAP_VIDEO1
) ?
1027 video1_numbuffers
: video2_numbuffers
;
1029 for (i
= num_buffers
; i
< vout
->buffer_allocated
; i
++) {
1030 if (vout
->buf_virt_addr
[i
])
1031 omap_vout_free_buffer(vout
->buf_virt_addr
[i
],
1034 vout
->buf_virt_addr
[i
] = 0;
1035 vout
->buf_phy_addr
[i
] = 0;
1037 /* Free the VRFB buffers only if they are allocated
1038 * during reqbufs. Don't free if init time allocated
1040 if (!vout
->vrfb_static_allocation
) {
1041 for (i
= 0; i
< VRFB_NUM_BUFS
; i
++) {
1042 if (vout
->smsshado_virt_addr
[i
]) {
1043 omap_vout_free_buffer(
1044 vout
->smsshado_virt_addr
[i
],
1045 vout
->smsshado_size
);
1046 vout
->smsshado_virt_addr
[i
] = 0;
1047 vout
->smsshado_phy_addr
[i
] = 0;
1051 vout
->buffer_allocated
= num_buffers
;
1055 * This function will be called when VIDIOC_QBUF ioctl is called.
1056 * It prepare buffers before give out for the display. This function
1057 * converts user space virtual address into physical address if userptr memory
1058 * exchange mechanism is used. If rotation is enabled, it copies entire
1059 * buffer into VRFB memory space before giving it to the DSS.
1061 static int omap_vout_buffer_prepare(struct videobuf_queue
*q
,
1062 struct videobuf_buffer
*vb
,
1063 enum v4l2_field field
)
1066 struct vid_vrfb_dma
*tx
;
1067 enum dss_rotation rotation
;
1068 struct omap_vout_device
*vout
= q
->priv_data
;
1069 u32 dest_frame_index
= 0, src_element_index
= 0;
1070 u32 dest_element_index
= 0, src_frame_index
= 0;
1071 u32 elem_count
= 0, frame_count
= 0, pixsize
= 2;
1073 if (VIDEOBUF_NEEDS_INIT
== vb
->state
) {
1074 vb
->width
= vout
->pix
.width
;
1075 vb
->height
= vout
->pix
.height
;
1076 vb
->size
= vb
->width
* vb
->height
* vout
->bpp
;
1079 vb
->state
= VIDEOBUF_PREPARED
;
1080 /* if user pointer memory mechanism is used, get the physical
1081 * address of the buffer
1083 if (V4L2_MEMORY_USERPTR
== vb
->memory
) {
1086 /* Physical address */
1087 vout
->queued_buf_addr
[vb
->i
] = (u8
*)
1088 omap_vout_uservirt_to_phys(vb
->baddr
);
1090 vout
->queued_buf_addr
[vb
->i
] = (u8
*)vout
->buf_phy_addr
[vb
->i
];
1093 if (!rotation_enabled(vout
))
1096 dmabuf
= vout
->buf_phy_addr
[vb
->i
];
1097 /* If rotation is enabled, copy input buffer into VRFB
1098 * memory space using DMA. We are copying input buffer
1099 * into VRFB memory space of desired angle and DSS will
1100 * read image VRFB memory for 0 degree angle
1102 pixsize
= vout
->bpp
* vout
->vrfb_bpp
;
1104 * DMA transfer in double index mode
1108 dest_frame_index
= ((MAX_PIXELS_PER_LINE
* pixsize
) -
1109 (vout
->pix
.width
* vout
->bpp
)) + 1;
1111 /* Source and destination parameters */
1112 src_element_index
= 0;
1113 src_frame_index
= 0;
1114 dest_element_index
= 1;
1115 /* Number of elements per frame */
1116 elem_count
= vout
->pix
.width
* vout
->bpp
;
1117 frame_count
= vout
->pix
.height
;
1118 tx
= &vout
->vrfb_dma_tx
;
1120 omap_set_dma_transfer_params(tx
->dma_ch
, OMAP_DMA_DATA_TYPE_S32
,
1121 (elem_count
/ 4), frame_count
, OMAP_DMA_SYNC_ELEMENT
,
1123 /* src_port required only for OMAP1 */
1124 omap_set_dma_src_params(tx
->dma_ch
, 0, OMAP_DMA_AMODE_POST_INC
,
1125 dmabuf
, src_element_index
, src_frame_index
);
1126 /*set dma source burst mode for VRFB */
1127 omap_set_dma_src_burst_mode(tx
->dma_ch
, OMAP_DMA_DATA_BURST_16
);
1128 rotation
= calc_rotation(vout
);
1130 /* dest_port required only for OMAP1 */
1131 omap_set_dma_dest_params(tx
->dma_ch
, 0, OMAP_DMA_AMODE_DOUBLE_IDX
,
1132 vout
->vrfb_context
[vb
->i
].paddr
[0], dest_element_index
,
1134 /*set dma dest burst mode for VRFB */
1135 omap_set_dma_dest_burst_mode(tx
->dma_ch
, OMAP_DMA_DATA_BURST_16
);
1136 omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE
, 0x20, 0);
1138 omap_start_dma(tx
->dma_ch
);
1139 interruptible_sleep_on_timeout(&tx
->wait
, VRFB_TX_TIMEOUT
);
1141 if (tx
->tx_status
== 0) {
1142 omap_stop_dma(tx
->dma_ch
);
1145 /* Store buffers physical address into an array. Addresses
1146 * from this array will be used to configure DSS */
1147 vout
->queued_buf_addr
[vb
->i
] = (u8
*)
1148 vout
->vrfb_context
[vb
->i
].paddr
[rotation
];
1153 * Buffer queue function will be called from the videobuf layer when _QBUF
1154 * ioctl is called. It is used to enqueue buffer, which is ready to be
1157 static void omap_vout_buffer_queue(struct videobuf_queue
*q
,
1158 struct videobuf_buffer
*vb
)
1160 struct omap_vout_device
*vout
= q
->priv_data
;
1162 /* Driver is also maintainig a queue. So enqueue buffer in the driver
1164 list_add_tail(&vb
->queue
, &vout
->dma_queue
);
1166 vb
->state
= VIDEOBUF_QUEUED
;
1170 * Buffer release function is called from videobuf layer to release buffer
1171 * which are already allocated
1173 static void omap_vout_buffer_release(struct videobuf_queue
*q
,
1174 struct videobuf_buffer
*vb
)
1176 struct omap_vout_device
*vout
= q
->priv_data
;
1178 vb
->state
= VIDEOBUF_NEEDS_INIT
;
1180 if (V4L2_MEMORY_MMAP
!= vout
->memory
)
1187 static void omap_vout_vm_open(struct vm_area_struct
*vma
)
1189 struct omap_vout_device
*vout
= vma
->vm_private_data
;
1191 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
1192 "vm_open [vma=%08lx-%08lx]\n", vma
->vm_start
, vma
->vm_end
);
1196 static void omap_vout_vm_close(struct vm_area_struct
*vma
)
1198 struct omap_vout_device
*vout
= vma
->vm_private_data
;
1200 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
1201 "vm_close [vma=%08lx-%08lx]\n", vma
->vm_start
, vma
->vm_end
);
1205 static struct vm_operations_struct omap_vout_vm_ops
= {
1206 .open
= omap_vout_vm_open
,
1207 .close
= omap_vout_vm_close
,
1210 static int omap_vout_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1214 unsigned long start
= vma
->vm_start
;
1215 unsigned long size
= (vma
->vm_end
- vma
->vm_start
);
1216 struct omap_vout_device
*vout
= file
->private_data
;
1217 struct videobuf_queue
*q
= &vout
->vbq
;
1219 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
1220 " %s pgoff=0x%lx, start=0x%lx, end=0x%lx\n", __func__
,
1221 vma
->vm_pgoff
, vma
->vm_start
, vma
->vm_end
);
1223 /* look for the buffer to map */
1224 for (i
= 0; i
< VIDEO_MAX_FRAME
; i
++) {
1225 if (NULL
== q
->bufs
[i
])
1227 if (V4L2_MEMORY_MMAP
!= q
->bufs
[i
]->memory
)
1229 if (q
->bufs
[i
]->boff
== (vma
->vm_pgoff
<< PAGE_SHIFT
))
1233 if (VIDEO_MAX_FRAME
== i
) {
1234 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
,
1235 "offset invalid [offset=0x%lx]\n",
1236 (vma
->vm_pgoff
<< PAGE_SHIFT
));
1239 /* Check the size of the buffer */
1240 if (size
> vout
->buffer_size
) {
1241 v4l2_err(&vout
->vid_dev
->v4l2_dev
,
1242 "insufficient memory [%lu] [%u]\n",
1243 size
, vout
->buffer_size
);
1247 q
->bufs
[i
]->baddr
= vma
->vm_start
;
1249 vma
->vm_flags
|= VM_RESERVED
;
1250 vma
->vm_page_prot
= pgprot_writecombine(vma
->vm_page_prot
);
1251 vma
->vm_ops
= &omap_vout_vm_ops
;
1252 vma
->vm_private_data
= (void *) vout
;
1253 pos
= (void *)vout
->buf_virt_addr
[i
];
1254 vma
->vm_pgoff
= virt_to_phys((void *)pos
) >> PAGE_SHIFT
;
1257 pfn
= virt_to_phys((void *) pos
) >> PAGE_SHIFT
;
1258 if (remap_pfn_range(vma
, start
, pfn
, PAGE_SIZE
, PAGE_SHARED
))
1265 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Exiting %s\n", __func__
);
1270 static int omap_vout_release(struct file
*file
)
1272 unsigned int ret
, i
;
1273 struct videobuf_queue
*q
;
1274 struct omapvideo_info
*ovid
;
1275 struct omap_vout_device
*vout
= file
->private_data
;
1277 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Entering %s\n", __func__
);
1278 ovid
= &vout
->vid_info
;
1284 /* Disable all the overlay managers connected with this interface */
1285 for (i
= 0; i
< ovid
->num_overlays
; i
++) {
1286 struct omap_overlay
*ovl
= ovid
->overlays
[i
];
1287 if (ovl
->manager
&& ovl
->manager
->device
) {
1288 struct omap_overlay_info info
;
1289 ovl
->get_overlay_info(ovl
, &info
);
1291 ovl
->set_overlay_info(ovl
, &info
);
1294 /* Turn off the pipeline */
1295 ret
= omapvid_apply_changes(vout
);
1297 v4l2_warn(&vout
->vid_dev
->v4l2_dev
,
1298 "Unable to apply changes\n");
1300 /* Free all buffers */
1301 omap_vout_free_allbuffers(vout
);
1302 videobuf_mmap_free(q
);
1304 /* Even if apply changes fails we should continue
1305 freeing allocated memory */
1306 if (vout
->streaming
) {
1309 mask
= DISPC_IRQ_VSYNC
| DISPC_IRQ_EVSYNC_EVEN
|
1310 DISPC_IRQ_EVSYNC_ODD
;
1311 omap_dispc_unregister_isr(omap_vout_isr
, vout
, mask
);
1312 vout
->streaming
= 0;
1314 videobuf_streamoff(q
);
1315 videobuf_queue_cancel(q
);
1318 if (vout
->mmap_count
!= 0)
1319 vout
->mmap_count
= 0;
1322 file
->private_data
= NULL
;
1324 if (vout
->buffer_allocated
)
1325 videobuf_mmap_free(q
);
1327 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Exiting %s\n", __func__
);
1331 static int omap_vout_open(struct file
*file
)
1333 struct videobuf_queue
*q
;
1334 struct omap_vout_device
*vout
= NULL
;
1336 vout
= video_drvdata(file
);
1337 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Entering %s\n", __func__
);
1342 /* for now, we only support single open */
1348 file
->private_data
= vout
;
1349 vout
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
1352 video_vbq_ops
.buf_setup
= omap_vout_buffer_setup
;
1353 video_vbq_ops
.buf_prepare
= omap_vout_buffer_prepare
;
1354 video_vbq_ops
.buf_release
= omap_vout_buffer_release
;
1355 video_vbq_ops
.buf_queue
= omap_vout_buffer_queue
;
1356 spin_lock_init(&vout
->vbq_lock
);
1358 videobuf_queue_dma_contig_init(q
, &video_vbq_ops
, q
->dev
,
1359 &vout
->vbq_lock
, vout
->type
, V4L2_FIELD_NONE
,
1360 sizeof(struct videobuf_buffer
), vout
, NULL
);
1362 v4l2_dbg(1, debug
, &vout
->vid_dev
->v4l2_dev
, "Exiting %s\n", __func__
);
1369 static int vidioc_querycap(struct file
*file
, void *fh
,
1370 struct v4l2_capability
*cap
)
1372 struct omap_vout_device
*vout
= fh
;
1374 strlcpy(cap
->driver
, VOUT_NAME
, sizeof(cap
->driver
));
1375 strlcpy(cap
->card
, vout
->vfd
->name
, sizeof(cap
->card
));
1376 cap
->bus_info
[0] = '\0';
1377 cap
->capabilities
= V4L2_CAP_STREAMING
| V4L2_CAP_VIDEO_OUTPUT
;
1382 static int vidioc_enum_fmt_vid_out(struct file
*file
, void *fh
,
1383 struct v4l2_fmtdesc
*fmt
)
1385 int index
= fmt
->index
;
1386 enum v4l2_buf_type type
= fmt
->type
;
1390 if (index
>= NUM_OUTPUT_FORMATS
)
1393 fmt
->flags
= omap_formats
[index
].flags
;
1394 strlcpy(fmt
->description
, omap_formats
[index
].description
,
1395 sizeof(fmt
->description
));
1396 fmt
->pixelformat
= omap_formats
[index
].pixelformat
;
1401 static int vidioc_g_fmt_vid_out(struct file
*file
, void *fh
,
1402 struct v4l2_format
*f
)
1404 struct omap_vout_device
*vout
= fh
;
1406 f
->fmt
.pix
= vout
->pix
;
1411 static int vidioc_try_fmt_vid_out(struct file
*file
, void *fh
,
1412 struct v4l2_format
*f
)
1414 struct omap_overlay
*ovl
;
1415 struct omapvideo_info
*ovid
;
1416 struct omap_video_timings
*timing
;
1417 struct omap_vout_device
*vout
= fh
;
1419 ovid
= &vout
->vid_info
;
1420 ovl
= ovid
->overlays
[0];
1422 if (!ovl
->manager
|| !ovl
->manager
->device
)
1424 /* get the display device attached to the overlay */
1425 timing
= &ovl
->manager
->device
->panel
.timings
;
1427 vout
->fbuf
.fmt
.height
= timing
->y_res
;
1428 vout
->fbuf
.fmt
.width
= timing
->x_res
;
1430 omap_vout_try_format(&f
->fmt
.pix
);
1434 static int vidioc_s_fmt_vid_out(struct file
*file
, void *fh
,
1435 struct v4l2_format
*f
)
1438 struct omap_overlay
*ovl
;
1439 struct omapvideo_info
*ovid
;
1440 struct omap_video_timings
*timing
;
1441 struct omap_vout_device
*vout
= fh
;
1443 if (vout
->streaming
)
1446 mutex_lock(&vout
->lock
);
1448 ovid
= &vout
->vid_info
;
1449 ovl
= ovid
->overlays
[0];
1451 /* get the display device attached to the overlay */
1452 if (!ovl
->manager
|| !ovl
->manager
->device
) {
1454 goto s_fmt_vid_out_exit
;
1456 timing
= &ovl
->manager
->device
->panel
.timings
;
1458 /* We dont support RGB24-packed mode if vrfb rotation
1460 if ((rotation_enabled(vout
)) &&
1461 f
->fmt
.pix
.pixelformat
== V4L2_PIX_FMT_RGB24
) {
1463 goto s_fmt_vid_out_exit
;
1466 /* get the framebuffer parameters */
1468 if (rotate_90_or_270(vout
)) {
1469 vout
->fbuf
.fmt
.height
= timing
->x_res
;
1470 vout
->fbuf
.fmt
.width
= timing
->y_res
;
1472 vout
->fbuf
.fmt
.height
= timing
->y_res
;
1473 vout
->fbuf
.fmt
.width
= timing
->x_res
;
1476 /* change to samller size is OK */
1478 bpp
= omap_vout_try_format(&f
->fmt
.pix
);
1479 f
->fmt
.pix
.sizeimage
= f
->fmt
.pix
.width
* f
->fmt
.pix
.height
* bpp
;
1481 /* try & set the new output format */
1483 vout
->pix
= f
->fmt
.pix
;
1486 /* If YUYV then vrfb bpp is 2, for others its 1 */
1487 if (V4L2_PIX_FMT_YUYV
== vout
->pix
.pixelformat
||
1488 V4L2_PIX_FMT_UYVY
== vout
->pix
.pixelformat
)
1491 /* set default crop and win */
1492 omap_vout_new_format(&vout
->pix
, &vout
->fbuf
, &vout
->crop
, &vout
->win
);
1494 /* Save the changes in the overlay strcuture */
1495 ret
= omapvid_init(vout
, 0);
1497 v4l2_err(&vout
->vid_dev
->v4l2_dev
, "failed to change mode\n");
1498 goto s_fmt_vid_out_exit
;
1504 mutex_unlock(&vout
->lock
);
1508 static int vidioc_try_fmt_vid_overlay(struct file
*file
, void *fh
,
1509 struct v4l2_format
*f
)
1512 struct omap_vout_device
*vout
= fh
;
1513 struct v4l2_window
*win
= &f
->fmt
.win
;
1515 ret
= omap_vout_try_window(&vout
->fbuf
, win
);
1518 if (vout
->vid
== OMAP_VIDEO1
)
1519 win
->global_alpha
= 255;
1521 win
->global_alpha
= f
->fmt
.win
.global_alpha
;
1527 static int vidioc_s_fmt_vid_overlay(struct file
*file
, void *fh
,
1528 struct v4l2_format
*f
)
1531 struct omap_overlay
*ovl
;
1532 struct omapvideo_info
*ovid
;
1533 struct omap_vout_device
*vout
= fh
;
1534 struct v4l2_window
*win
= &f
->fmt
.win
;
1536 mutex_lock(&vout
->lock
);
1537 ovid
= &vout
->vid_info
;
1538 ovl
= ovid
->overlays
[0];
1540 ret
= omap_vout_new_window(&vout
->crop
, &vout
->win
, &vout
->fbuf
, win
);
1542 /* Video1 plane does not support global alpha */
1543 if (ovl
->id
== OMAP_DSS_VIDEO1
)
1544 vout
->win
.global_alpha
= 255;
1546 vout
->win
.global_alpha
= f
->fmt
.win
.global_alpha
;
1548 vout
->win
.chromakey
= f
->fmt
.win
.chromakey
;
1550 mutex_unlock(&vout
->lock
);
1554 static int vidioc_enum_fmt_vid_overlay(struct file
*file
, void *fh
,
1555 struct v4l2_fmtdesc
*fmt
)
1557 int index
= fmt
->index
;
1558 enum v4l2_buf_type type
= fmt
->type
;
1562 if (index
>= NUM_OUTPUT_FORMATS
)
1565 fmt
->flags
= omap_formats
[index
].flags
;
1566 strlcpy(fmt
->description
, omap_formats
[index
].description
,
1567 sizeof(fmt
->description
));
1568 fmt
->pixelformat
= omap_formats
[index
].pixelformat
;
1572 static int vidioc_g_fmt_vid_overlay(struct file
*file
, void *fh
,
1573 struct v4l2_format
*f
)
1576 struct omap_overlay
*ovl
;
1577 struct omapvideo_info
*ovid
;
1578 struct omap_vout_device
*vout
= fh
;
1579 struct omap_overlay_manager_info info
;
1580 struct v4l2_window
*win
= &f
->fmt
.win
;
1582 ovid
= &vout
->vid_info
;
1583 ovl
= ovid
->overlays
[0];
1585 win
->w
= vout
->win
.w
;
1586 win
->field
= vout
->win
.field
;
1587 win
->global_alpha
= vout
->win
.global_alpha
;
1589 if (ovl
->manager
&& ovl
->manager
->get_manager_info
) {
1590 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1591 key_value
= info
.trans_key
;
1593 win
->chromakey
= key_value
;
1597 static int vidioc_cropcap(struct file
*file
, void *fh
,
1598 struct v4l2_cropcap
*cropcap
)
1600 struct omap_vout_device
*vout
= fh
;
1601 struct v4l2_pix_format
*pix
= &vout
->pix
;
1603 if (cropcap
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1606 /* Width and height are always even */
1607 cropcap
->bounds
.width
= pix
->width
& ~1;
1608 cropcap
->bounds
.height
= pix
->height
& ~1;
1610 omap_vout_default_crop(&vout
->pix
, &vout
->fbuf
, &cropcap
->defrect
);
1611 cropcap
->pixelaspect
.numerator
= 1;
1612 cropcap
->pixelaspect
.denominator
= 1;
1616 static int vidioc_g_crop(struct file
*file
, void *fh
, struct v4l2_crop
*crop
)
1618 struct omap_vout_device
*vout
= fh
;
1620 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1622 crop
->c
= vout
->crop
;
1626 static int vidioc_s_crop(struct file
*file
, void *fh
, struct v4l2_crop
*crop
)
1629 struct omap_vout_device
*vout
= fh
;
1630 struct omapvideo_info
*ovid
;
1631 struct omap_overlay
*ovl
;
1632 struct omap_video_timings
*timing
;
1634 if (vout
->streaming
)
1637 mutex_lock(&vout
->lock
);
1638 ovid
= &vout
->vid_info
;
1639 ovl
= ovid
->overlays
[0];
1641 if (!ovl
->manager
|| !ovl
->manager
->device
) {
1645 /* get the display device attached to the overlay */
1646 timing
= &ovl
->manager
->device
->panel
.timings
;
1648 if (rotate_90_or_270(vout
)) {
1649 vout
->fbuf
.fmt
.height
= timing
->x_res
;
1650 vout
->fbuf
.fmt
.width
= timing
->y_res
;
1652 vout
->fbuf
.fmt
.height
= timing
->y_res
;
1653 vout
->fbuf
.fmt
.width
= timing
->x_res
;
1656 if (crop
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1657 ret
= omap_vout_new_crop(&vout
->pix
, &vout
->crop
, &vout
->win
,
1658 &vout
->fbuf
, &crop
->c
);
1661 mutex_unlock(&vout
->lock
);
1665 static int vidioc_queryctrl(struct file
*file
, void *fh
,
1666 struct v4l2_queryctrl
*ctrl
)
1671 case V4L2_CID_ROTATE
:
1672 ret
= v4l2_ctrl_query_fill(ctrl
, 0, 270, 90, 0);
1674 case V4L2_CID_BG_COLOR
:
1675 ret
= v4l2_ctrl_query_fill(ctrl
, 0, 0xFFFFFF, 1, 0);
1677 case V4L2_CID_VFLIP
:
1678 ret
= v4l2_ctrl_query_fill(ctrl
, 0, 1, 1, 0);
1681 ctrl
->name
[0] = '\0';
1687 static int vidioc_g_ctrl(struct file
*file
, void *fh
, struct v4l2_control
*ctrl
)
1690 struct omap_vout_device
*vout
= fh
;
1693 case V4L2_CID_ROTATE
:
1694 ctrl
->value
= vout
->control
[0].value
;
1696 case V4L2_CID_BG_COLOR
:
1698 struct omap_overlay_manager_info info
;
1699 struct omap_overlay
*ovl
;
1701 ovl
= vout
->vid_info
.overlays
[0];
1702 if (!ovl
->manager
|| !ovl
->manager
->get_manager_info
) {
1707 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1708 ctrl
->value
= info
.default_color
;
1711 case V4L2_CID_VFLIP
:
1712 ctrl
->value
= vout
->control
[2].value
;
1720 static int vidioc_s_ctrl(struct file
*file
, void *fh
, struct v4l2_control
*a
)
1723 struct omap_vout_device
*vout
= fh
;
1726 case V4L2_CID_ROTATE
:
1728 int rotation
= a
->value
;
1730 mutex_lock(&vout
->lock
);
1732 if (rotation
&& vout
->pix
.pixelformat
== V4L2_PIX_FMT_RGB24
) {
1733 mutex_unlock(&vout
->lock
);
1738 if (v4l2_rot_to_dss_rot(rotation
, &vout
->rotation
,
1740 mutex_unlock(&vout
->lock
);
1745 vout
->control
[0].value
= rotation
;
1746 mutex_unlock(&vout
->lock
);
1749 case V4L2_CID_BG_COLOR
:
1751 struct omap_overlay
*ovl
;
1752 unsigned int color
= a
->value
;
1753 struct omap_overlay_manager_info info
;
1755 ovl
= vout
->vid_info
.overlays
[0];
1757 mutex_lock(&vout
->lock
);
1758 if (!ovl
->manager
|| !ovl
->manager
->get_manager_info
) {
1759 mutex_unlock(&vout
->lock
);
1764 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
1765 info
.default_color
= color
;
1766 if (ovl
->manager
->set_manager_info(ovl
->manager
, &info
)) {
1767 mutex_unlock(&vout
->lock
);
1772 vout
->control
[1].value
= color
;
1773 mutex_unlock(&vout
->lock
);
1776 case V4L2_CID_VFLIP
:
1778 struct omap_overlay
*ovl
;
1779 struct omapvideo_info
*ovid
;
1780 unsigned int mirror
= a
->value
;
1782 ovid
= &vout
->vid_info
;
1783 ovl
= ovid
->overlays
[0];
1785 mutex_lock(&vout
->lock
);
1787 if (mirror
&& vout
->pix
.pixelformat
== V4L2_PIX_FMT_RGB24
) {
1788 mutex_unlock(&vout
->lock
);
1792 vout
->mirror
= mirror
;
1793 vout
->control
[2].value
= mirror
;
1794 mutex_unlock(&vout
->lock
);
1803 static int vidioc_reqbufs(struct file
*file
, void *fh
,
1804 struct v4l2_requestbuffers
*req
)
1807 unsigned int i
, num_buffers
= 0;
1808 struct omap_vout_device
*vout
= fh
;
1809 struct videobuf_queue
*q
= &vout
->vbq
;
1811 if ((req
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
) || (req
->count
< 0))
1813 /* if memory is not mmp or userptr
1815 if ((V4L2_MEMORY_MMAP
!= req
->memory
) &&
1816 (V4L2_MEMORY_USERPTR
!= req
->memory
))
1819 mutex_lock(&vout
->lock
);
1820 /* Cannot be requested when streaming is on */
1821 if (vout
->streaming
) {
1826 /* If buffers are already allocated free them */
1827 if (q
->bufs
[0] && (V4L2_MEMORY_MMAP
== q
->bufs
[0]->memory
)) {
1828 if (vout
->mmap_count
) {
1832 num_buffers
= (vout
->vid
== OMAP_VIDEO1
) ?
1833 video1_numbuffers
: video2_numbuffers
;
1834 for (i
= num_buffers
; i
< vout
->buffer_allocated
; i
++) {
1835 omap_vout_free_buffer(vout
->buf_virt_addr
[i
],
1837 vout
->buf_virt_addr
[i
] = 0;
1838 vout
->buf_phy_addr
[i
] = 0;
1840 vout
->buffer_allocated
= num_buffers
;
1841 videobuf_mmap_free(q
);
1842 } else if (q
->bufs
[0] && (V4L2_MEMORY_USERPTR
== q
->bufs
[0]->memory
)) {
1843 if (vout
->buffer_allocated
) {
1844 videobuf_mmap_free(q
);
1845 for (i
= 0; i
< vout
->buffer_allocated
; i
++) {
1849 vout
->buffer_allocated
= 0;
1853 /*store the memory type in data structure */
1854 vout
->memory
= req
->memory
;
1856 INIT_LIST_HEAD(&vout
->dma_queue
);
1858 /* call videobuf_reqbufs api */
1859 ret
= videobuf_reqbufs(q
, req
);
1863 vout
->buffer_allocated
= req
->count
;
1866 mutex_unlock(&vout
->lock
);
1870 static int vidioc_querybuf(struct file
*file
, void *fh
,
1871 struct v4l2_buffer
*b
)
1873 struct omap_vout_device
*vout
= fh
;
1875 return videobuf_querybuf(&vout
->vbq
, b
);
1878 static int vidioc_qbuf(struct file
*file
, void *fh
,
1879 struct v4l2_buffer
*buffer
)
1881 struct omap_vout_device
*vout
= fh
;
1882 struct videobuf_queue
*q
= &vout
->vbq
;
1884 if ((V4L2_BUF_TYPE_VIDEO_OUTPUT
!= buffer
->type
) ||
1885 (buffer
->index
>= vout
->buffer_allocated
) ||
1886 (q
->bufs
[buffer
->index
]->memory
!= buffer
->memory
)) {
1889 if (V4L2_MEMORY_USERPTR
== buffer
->memory
) {
1890 if ((buffer
->length
< vout
->pix
.sizeimage
) ||
1891 (0 == buffer
->m
.userptr
)) {
1896 if ((rotation_enabled(vout
)) &&
1897 vout
->vrfb_dma_tx
.req_status
== DMA_CHAN_NOT_ALLOTED
) {
1898 v4l2_warn(&vout
->vid_dev
->v4l2_dev
,
1899 "DMA Channel not allocated for Rotation\n");
1903 return videobuf_qbuf(q
, buffer
);
1906 static int vidioc_dqbuf(struct file
*file
, void *fh
, struct v4l2_buffer
*b
)
1908 struct omap_vout_device
*vout
= fh
;
1909 struct videobuf_queue
*q
= &vout
->vbq
;
1911 if (!vout
->streaming
)
1914 if (file
->f_flags
& O_NONBLOCK
)
1915 /* Call videobuf_dqbuf for non blocking mode */
1916 return videobuf_dqbuf(q
, (struct v4l2_buffer
*)b
, 1);
1918 /* Call videobuf_dqbuf for blocking mode */
1919 return videobuf_dqbuf(q
, (struct v4l2_buffer
*)b
, 0);
1922 static int vidioc_streamon(struct file
*file
, void *fh
, enum v4l2_buf_type i
)
1925 u32 addr
= 0, mask
= 0;
1926 struct omap_vout_device
*vout
= fh
;
1927 struct videobuf_queue
*q
= &vout
->vbq
;
1928 struct omapvideo_info
*ovid
= &vout
->vid_info
;
1930 mutex_lock(&vout
->lock
);
1932 if (vout
->streaming
) {
1937 ret
= videobuf_streamon(q
);
1941 if (list_empty(&vout
->dma_queue
)) {
1946 /* Get the next frame from the buffer queue */
1947 vout
->next_frm
= vout
->cur_frm
= list_entry(vout
->dma_queue
.next
,
1948 struct videobuf_buffer
, queue
);
1949 /* Remove buffer from the buffer queue */
1950 list_del(&vout
->cur_frm
->queue
);
1951 /* Mark state of the current frame to active */
1952 vout
->cur_frm
->state
= VIDEOBUF_ACTIVE
;
1953 /* Initialize field_id and started member */
1956 /* set flag here. Next QBUF will start DMA */
1957 vout
->streaming
= 1;
1959 vout
->first_int
= 1;
1961 if (omap_vout_calculate_offset(vout
)) {
1965 addr
= (unsigned long) vout
->queued_buf_addr
[vout
->cur_frm
->i
]
1966 + vout
->cropped_offset
;
1968 mask
= DISPC_IRQ_VSYNC
| DISPC_IRQ_EVSYNC_EVEN
| DISPC_IRQ_EVSYNC_ODD
;
1970 omap_dispc_register_isr(omap_vout_isr
, vout
, mask
);
1972 for (j
= 0; j
< ovid
->num_overlays
; j
++) {
1973 struct omap_overlay
*ovl
= ovid
->overlays
[j
];
1975 if (ovl
->manager
&& ovl
->manager
->device
) {
1976 struct omap_overlay_info info
;
1977 ovl
->get_overlay_info(ovl
, &info
);
1980 if (ovl
->set_overlay_info(ovl
, &info
)) {
1987 /* First save the configuration in ovelray structure */
1988 ret
= omapvid_init(vout
, addr
);
1990 v4l2_err(&vout
->vid_dev
->v4l2_dev
,
1991 "failed to set overlay info\n");
1992 /* Enable the pipeline and set the Go bit */
1993 ret
= omapvid_apply_changes(vout
);
1995 v4l2_err(&vout
->vid_dev
->v4l2_dev
, "failed to change mode\n");
2001 ret
= videobuf_streamoff(q
);
2003 mutex_unlock(&vout
->lock
);
2007 static int vidioc_streamoff(struct file
*file
, void *fh
, enum v4l2_buf_type i
)
2011 struct omap_vout_device
*vout
= fh
;
2012 struct omapvideo_info
*ovid
= &vout
->vid_info
;
2014 if (!vout
->streaming
)
2017 vout
->streaming
= 0;
2018 mask
= DISPC_IRQ_VSYNC
| DISPC_IRQ_EVSYNC_EVEN
| DISPC_IRQ_EVSYNC_ODD
;
2020 omap_dispc_unregister_isr(omap_vout_isr
, vout
, mask
);
2022 for (j
= 0; j
< ovid
->num_overlays
; j
++) {
2023 struct omap_overlay
*ovl
= ovid
->overlays
[j
];
2025 if (ovl
->manager
&& ovl
->manager
->device
) {
2026 struct omap_overlay_info info
;
2028 ovl
->get_overlay_info(ovl
, &info
);
2030 ret
= ovl
->set_overlay_info(ovl
, &info
);
2032 v4l2_err(&vout
->vid_dev
->v4l2_dev
,
2033 "failed to update overlay info in streamoff\n");
2037 /* Turn of the pipeline */
2038 ret
= omapvid_apply_changes(vout
);
2040 v4l2_err(&vout
->vid_dev
->v4l2_dev
, "failed to change mode in"
2043 INIT_LIST_HEAD(&vout
->dma_queue
);
2044 ret
= videobuf_streamoff(&vout
->vbq
);
2049 static int vidioc_s_fbuf(struct file
*file
, void *fh
,
2050 struct v4l2_framebuffer
*a
)
2053 struct omap_overlay
*ovl
;
2054 struct omapvideo_info
*ovid
;
2055 struct omap_vout_device
*vout
= fh
;
2056 struct omap_overlay_manager_info info
;
2057 enum omap_dss_trans_key_type key_type
= OMAP_DSS_COLOR_KEY_GFX_DST
;
2059 ovid
= &vout
->vid_info
;
2060 ovl
= ovid
->overlays
[0];
2062 /* OMAP DSS doesn't support Source and Destination color
2064 if ((a
->flags
& V4L2_FBUF_FLAG_SRC_CHROMAKEY
) &&
2065 (a
->flags
& V4L2_FBUF_FLAG_CHROMAKEY
))
2067 /* OMAP DSS Doesn't support the Destination color key
2068 and alpha blending together */
2069 if ((a
->flags
& V4L2_FBUF_FLAG_CHROMAKEY
) &&
2070 (a
->flags
& V4L2_FBUF_FLAG_LOCAL_ALPHA
))
2073 if ((a
->flags
& V4L2_FBUF_FLAG_SRC_CHROMAKEY
)) {
2074 vout
->fbuf
.flags
|= V4L2_FBUF_FLAG_SRC_CHROMAKEY
;
2075 key_type
= OMAP_DSS_COLOR_KEY_VID_SRC
;
2077 vout
->fbuf
.flags
&= ~V4L2_FBUF_FLAG_SRC_CHROMAKEY
;
2079 if ((a
->flags
& V4L2_FBUF_FLAG_CHROMAKEY
)) {
2080 vout
->fbuf
.flags
|= V4L2_FBUF_FLAG_CHROMAKEY
;
2081 key_type
= OMAP_DSS_COLOR_KEY_GFX_DST
;
2083 vout
->fbuf
.flags
&= ~V4L2_FBUF_FLAG_CHROMAKEY
;
2085 if (a
->flags
& (V4L2_FBUF_FLAG_CHROMAKEY
|
2086 V4L2_FBUF_FLAG_SRC_CHROMAKEY
))
2090 if (ovl
->manager
&& ovl
->manager
->get_manager_info
&&
2091 ovl
->manager
->set_manager_info
) {
2093 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
2094 info
.trans_enabled
= enable
;
2095 info
.trans_key_type
= key_type
;
2096 info
.trans_key
= vout
->win
.chromakey
;
2098 if (ovl
->manager
->set_manager_info(ovl
->manager
, &info
))
2101 if (a
->flags
& V4L2_FBUF_FLAG_LOCAL_ALPHA
) {
2102 vout
->fbuf
.flags
|= V4L2_FBUF_FLAG_LOCAL_ALPHA
;
2105 vout
->fbuf
.flags
&= ~V4L2_FBUF_FLAG_LOCAL_ALPHA
;
2108 if (ovl
->manager
&& ovl
->manager
->get_manager_info
&&
2109 ovl
->manager
->set_manager_info
) {
2110 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
2111 info
.alpha_enabled
= enable
;
2112 if (ovl
->manager
->set_manager_info(ovl
->manager
, &info
))
2119 static int vidioc_g_fbuf(struct file
*file
, void *fh
,
2120 struct v4l2_framebuffer
*a
)
2122 struct omap_overlay
*ovl
;
2123 struct omapvideo_info
*ovid
;
2124 struct omap_vout_device
*vout
= fh
;
2125 struct omap_overlay_manager_info info
;
2127 ovid
= &vout
->vid_info
;
2128 ovl
= ovid
->overlays
[0];
2131 a
->capability
= V4L2_FBUF_CAP_LOCAL_ALPHA
| V4L2_FBUF_CAP_CHROMAKEY
2132 | V4L2_FBUF_CAP_SRC_CHROMAKEY
;
2134 if (ovl
->manager
&& ovl
->manager
->get_manager_info
) {
2135 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
2136 if (info
.trans_key_type
== OMAP_DSS_COLOR_KEY_VID_SRC
)
2137 a
->flags
|= V4L2_FBUF_FLAG_SRC_CHROMAKEY
;
2138 if (info
.trans_key_type
== OMAP_DSS_COLOR_KEY_GFX_DST
)
2139 a
->flags
|= V4L2_FBUF_FLAG_CHROMAKEY
;
2141 if (ovl
->manager
&& ovl
->manager
->get_manager_info
) {
2142 ovl
->manager
->get_manager_info(ovl
->manager
, &info
);
2143 if (info
.alpha_enabled
)
2144 a
->flags
|= V4L2_FBUF_FLAG_LOCAL_ALPHA
;
2150 static const struct v4l2_ioctl_ops vout_ioctl_ops
= {
2151 .vidioc_querycap
= vidioc_querycap
,
2152 .vidioc_enum_fmt_vid_out
= vidioc_enum_fmt_vid_out
,
2153 .vidioc_g_fmt_vid_out
= vidioc_g_fmt_vid_out
,
2154 .vidioc_try_fmt_vid_out
= vidioc_try_fmt_vid_out
,
2155 .vidioc_s_fmt_vid_out
= vidioc_s_fmt_vid_out
,
2156 .vidioc_queryctrl
= vidioc_queryctrl
,
2157 .vidioc_g_ctrl
= vidioc_g_ctrl
,
2158 .vidioc_s_fbuf
= vidioc_s_fbuf
,
2159 .vidioc_g_fbuf
= vidioc_g_fbuf
,
2160 .vidioc_s_ctrl
= vidioc_s_ctrl
,
2161 .vidioc_try_fmt_vid_overlay
= vidioc_try_fmt_vid_overlay
,
2162 .vidioc_s_fmt_vid_overlay
= vidioc_s_fmt_vid_overlay
,
2163 .vidioc_enum_fmt_vid_overlay
= vidioc_enum_fmt_vid_overlay
,
2164 .vidioc_g_fmt_vid_overlay
= vidioc_g_fmt_vid_overlay
,
2165 .vidioc_cropcap
= vidioc_cropcap
,
2166 .vidioc_g_crop
= vidioc_g_crop
,
2167 .vidioc_s_crop
= vidioc_s_crop
,
2168 .vidioc_reqbufs
= vidioc_reqbufs
,
2169 .vidioc_querybuf
= vidioc_querybuf
,
2170 .vidioc_qbuf
= vidioc_qbuf
,
2171 .vidioc_dqbuf
= vidioc_dqbuf
,
2172 .vidioc_streamon
= vidioc_streamon
,
2173 .vidioc_streamoff
= vidioc_streamoff
,
2176 static const struct v4l2_file_operations omap_vout_fops
= {
2177 .owner
= THIS_MODULE
,
2178 .unlocked_ioctl
= video_ioctl2
,
2179 .mmap
= omap_vout_mmap
,
2180 .open
= omap_vout_open
,
2181 .release
= omap_vout_release
,
2184 /* Init functions used during driver initialization */
2185 /* Initial setup of video_data */
2186 static int __init
omap_vout_setup_video_data(struct omap_vout_device
*vout
)
2188 struct video_device
*vfd
;
2189 struct v4l2_pix_format
*pix
;
2190 struct v4l2_control
*control
;
2191 struct omap_dss_device
*display
=
2192 vout
->vid_info
.overlays
[0]->manager
->device
;
2194 /* set the default pix */
2197 /* Set the default picture of QVGA */
2198 pix
->width
= QQVGA_WIDTH
;
2199 pix
->height
= QQVGA_HEIGHT
;
2201 /* Default pixel format is RGB 5-6-5 */
2202 pix
->pixelformat
= V4L2_PIX_FMT_RGB565
;
2203 pix
->field
= V4L2_FIELD_ANY
;
2204 pix
->bytesperline
= pix
->width
* 2;
2205 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
2207 pix
->colorspace
= V4L2_COLORSPACE_JPEG
;
2209 vout
->bpp
= RGB565_BPP
;
2210 vout
->fbuf
.fmt
.width
= display
->panel
.timings
.x_res
;
2211 vout
->fbuf
.fmt
.height
= display
->panel
.timings
.y_res
;
2213 /* Set the data structures for the overlay parameters*/
2214 vout
->win
.global_alpha
= 255;
2215 vout
->fbuf
.flags
= 0;
2216 vout
->fbuf
.capability
= V4L2_FBUF_CAP_LOCAL_ALPHA
|
2217 V4L2_FBUF_CAP_SRC_CHROMAKEY
| V4L2_FBUF_CAP_CHROMAKEY
;
2218 vout
->win
.chromakey
= 0;
2220 omap_vout_new_format(pix
, &vout
->fbuf
, &vout
->crop
, &vout
->win
);
2222 /*Initialize the control variables for
2223 rotation, flipping and background color. */
2224 control
= vout
->control
;
2225 control
[0].id
= V4L2_CID_ROTATE
;
2226 control
[0].value
= 0;
2229 vout
->control
[2].id
= V4L2_CID_HFLIP
;
2230 vout
->control
[2].value
= 0;
2233 control
[1].id
= V4L2_CID_BG_COLOR
;
2234 control
[1].value
= 0;
2236 /* initialize the video_device struct */
2237 vfd
= vout
->vfd
= video_device_alloc();
2240 printk(KERN_ERR VOUT_NAME
": could not allocate"
2241 " video device struct\n");
2244 vfd
->release
= video_device_release
;
2245 vfd
->ioctl_ops
= &vout_ioctl_ops
;
2247 strlcpy(vfd
->name
, VOUT_NAME
, sizeof(vfd
->name
));
2249 vfd
->fops
= &omap_vout_fops
;
2250 vfd
->v4l2_dev
= &vout
->vid_dev
->v4l2_dev
;
2251 mutex_init(&vout
->lock
);
2258 /* Setup video buffers */
2259 static int __init
omap_vout_setup_video_bufs(struct platform_device
*pdev
,
2264 int image_width
, image_height
;
2265 struct video_device
*vfd
;
2266 struct omap_vout_device
*vout
;
2267 int static_vrfb_allocation
= 0, vrfb_num_bufs
= VRFB_NUM_BUFS
;
2268 struct v4l2_device
*v4l2_dev
= platform_get_drvdata(pdev
);
2269 struct omap2video_device
*vid_dev
=
2270 container_of(v4l2_dev
, struct omap2video_device
, v4l2_dev
);
2272 vout
= vid_dev
->vouts
[vid_num
];
2275 numbuffers
= (vid_num
== 0) ? video1_numbuffers
: video2_numbuffers
;
2276 vout
->buffer_size
= (vid_num
== 0) ? video1_bufsize
: video2_bufsize
;
2277 dev_info(&pdev
->dev
, "Buffer Size = %d\n", vout
->buffer_size
);
2279 for (i
= 0; i
< numbuffers
; i
++) {
2280 vout
->buf_virt_addr
[i
] =
2281 omap_vout_alloc_buffer(vout
->buffer_size
,
2282 (u32
*) &vout
->buf_phy_addr
[i
]);
2283 if (!vout
->buf_virt_addr
[i
]) {
2290 for (i
= 0; i
< VRFB_NUM_BUFS
; i
++) {
2291 if (omap_vrfb_request_ctx(&vout
->vrfb_context
[i
])) {
2292 dev_info(&pdev
->dev
, ": VRFB allocation failed\n");
2293 for (j
= 0; j
< i
; j
++)
2294 omap_vrfb_release_ctx(&vout
->vrfb_context
[j
]);
2299 vout
->cropped_offset
= 0;
2301 /* Calculate VRFB memory size */
2302 /* allocate for worst case size */
2303 image_width
= VID_MAX_WIDTH
/ TILE_SIZE
;
2304 if (VID_MAX_WIDTH
% TILE_SIZE
)
2307 image_width
= image_width
* TILE_SIZE
;
2308 image_height
= VID_MAX_HEIGHT
/ TILE_SIZE
;
2310 if (VID_MAX_HEIGHT
% TILE_SIZE
)
2313 image_height
= image_height
* TILE_SIZE
;
2314 vout
->smsshado_size
= PAGE_ALIGN(image_width
* image_height
* 2 * 2);
2317 * Request and Initialize DMA, for DMA based VRFB transfer
2319 vout
->vrfb_dma_tx
.dev_id
= OMAP_DMA_NO_DEVICE
;
2320 vout
->vrfb_dma_tx
.dma_ch
= -1;
2321 vout
->vrfb_dma_tx
.req_status
= DMA_CHAN_ALLOTED
;
2322 ret
= omap_request_dma(vout
->vrfb_dma_tx
.dev_id
, "VRFB DMA TX",
2323 omap_vout_vrfb_dma_tx_callback
,
2324 (void *) &vout
->vrfb_dma_tx
, &vout
->vrfb_dma_tx
.dma_ch
);
2326 vout
->vrfb_dma_tx
.req_status
= DMA_CHAN_NOT_ALLOTED
;
2327 dev_info(&pdev
->dev
, ": failed to allocate DMA Channel for"
2328 " video%d\n", vfd
->minor
);
2330 init_waitqueue_head(&vout
->vrfb_dma_tx
.wait
);
2332 /* Allocate VRFB buffers if selected through bootargs */
2333 static_vrfb_allocation
= (vid_num
== 0) ?
2334 vid1_static_vrfb_alloc
: vid2_static_vrfb_alloc
;
2336 /* statically allocated the VRFB buffer is done through
2337 commands line aruments */
2338 if (static_vrfb_allocation
) {
2339 if (omap_vout_allocate_vrfb_buffers(vout
, &vrfb_num_bufs
, -1)) {
2341 goto release_vrfb_ctx
;
2343 vout
->vrfb_static_allocation
= 1;
2348 for (j
= 0; j
< VRFB_NUM_BUFS
; j
++)
2349 omap_vrfb_release_ctx(&vout
->vrfb_context
[j
]);
2352 for (i
= 0; i
< numbuffers
; i
++) {
2353 omap_vout_free_buffer(vout
->buf_virt_addr
[i
],
2355 vout
->buf_virt_addr
[i
] = 0;
2356 vout
->buf_phy_addr
[i
] = 0;
2362 /* Create video out devices */
2363 static int __init
omap_vout_create_video_devices(struct platform_device
*pdev
)
2366 struct omap_vout_device
*vout
;
2367 struct video_device
*vfd
= NULL
;
2368 struct v4l2_device
*v4l2_dev
= platform_get_drvdata(pdev
);
2369 struct omap2video_device
*vid_dev
= container_of(v4l2_dev
,
2370 struct omap2video_device
, v4l2_dev
);
2372 for (k
= 0; k
< pdev
->num_resources
; k
++) {
2374 vout
= kzalloc(sizeof(struct omap_vout_device
), GFP_KERNEL
);
2376 dev_err(&pdev
->dev
, ": could not allocate memory\n");
2381 vid_dev
->vouts
[k
] = vout
;
2382 vout
->vid_dev
= vid_dev
;
2383 /* Select video2 if only 1 overlay is controlled by V4L2 */
2384 if (pdev
->num_resources
== 1)
2385 vout
->vid_info
.overlays
[0] = vid_dev
->overlays
[k
+ 2];
2387 /* Else select video1 and video2 one by one. */
2388 vout
->vid_info
.overlays
[0] = vid_dev
->overlays
[k
+ 1];
2389 vout
->vid_info
.num_overlays
= 1;
2390 vout
->vid_info
.id
= k
+ 1;
2392 /* Setup the default configuration for the video devices
2394 if (omap_vout_setup_video_data(vout
) != 0) {
2399 /* Allocate default number of buffers for the video streaming
2400 * and reserve the VRFB space for rotation
2402 if (omap_vout_setup_video_bufs(pdev
, k
) != 0) {
2407 /* Register the Video device with V4L2
2410 if (video_register_device(vfd
, VFL_TYPE_GRABBER
, -1) < 0) {
2411 dev_err(&pdev
->dev
, ": Could not register "
2412 "Video for Linux device\n");
2417 video_set_drvdata(vfd
, vout
);
2419 /* Configure the overlay structure */
2420 ret
= omapvid_init(vid_dev
->vouts
[k
], 0);
2425 omap_vout_release_vrfb(vout
);
2426 omap_vout_free_buffers(vout
);
2428 video_device_release(vfd
);
2434 dev_info(&pdev
->dev
, ": registered and initialized"
2435 " video device %d\n", vfd
->minor
);
2436 if (k
== (pdev
->num_resources
- 1))
2442 /* Driver functions */
2443 static void omap_vout_cleanup_device(struct omap_vout_device
*vout
)
2445 struct video_device
*vfd
;
2452 if (!video_is_registered(vfd
)) {
2454 * The device was never registered, so release the
2455 * video_device struct directly.
2457 video_device_release(vfd
);
2460 * The unregister function will release the video_device
2461 * struct as well as unregistering it.
2463 video_unregister_device(vfd
);
2467 omap_vout_release_vrfb(vout
);
2468 omap_vout_free_buffers(vout
);
2469 /* Free the VRFB buffer if allocated
2472 if (vout
->vrfb_static_allocation
)
2473 omap_vout_free_vrfb_buffers(vout
);
2478 static int omap_vout_remove(struct platform_device
*pdev
)
2481 struct v4l2_device
*v4l2_dev
= platform_get_drvdata(pdev
);
2482 struct omap2video_device
*vid_dev
= container_of(v4l2_dev
, struct
2483 omap2video_device
, v4l2_dev
);
2485 v4l2_device_unregister(v4l2_dev
);
2486 for (k
= 0; k
< pdev
->num_resources
; k
++)
2487 omap_vout_cleanup_device(vid_dev
->vouts
[k
]);
2489 for (k
= 0; k
< vid_dev
->num_displays
; k
++) {
2490 if (vid_dev
->displays
[k
]->state
!= OMAP_DSS_DISPLAY_DISABLED
)
2491 vid_dev
->displays
[k
]->driver
->disable(vid_dev
->displays
[k
]);
2493 omap_dss_put_device(vid_dev
->displays
[k
]);
2499 static int __init
omap_vout_probe(struct platform_device
*pdev
)
2502 struct omap_overlay
*ovl
;
2503 struct omap_dss_device
*dssdev
= NULL
;
2504 struct omap_dss_device
*def_display
;
2505 struct omap2video_device
*vid_dev
= NULL
;
2507 if (pdev
->num_resources
== 0) {
2508 dev_err(&pdev
->dev
, "probed for an unknown device\n");
2512 vid_dev
= kzalloc(sizeof(struct omap2video_device
), GFP_KERNEL
);
2513 if (vid_dev
== NULL
)
2516 vid_dev
->num_displays
= 0;
2517 for_each_dss_dev(dssdev
) {
2518 omap_dss_get_device(dssdev
);
2519 vid_dev
->displays
[vid_dev
->num_displays
++] = dssdev
;
2522 if (vid_dev
->num_displays
== 0) {
2523 dev_err(&pdev
->dev
, "no displays\n");
2528 vid_dev
->num_overlays
= omap_dss_get_num_overlays();
2529 for (i
= 0; i
< vid_dev
->num_overlays
; i
++)
2530 vid_dev
->overlays
[i
] = omap_dss_get_overlay(i
);
2532 vid_dev
->num_managers
= omap_dss_get_num_overlay_managers();
2533 for (i
= 0; i
< vid_dev
->num_managers
; i
++)
2534 vid_dev
->managers
[i
] = omap_dss_get_overlay_manager(i
);
2536 /* Get the Video1 overlay and video2 overlay.
2537 * Setup the Display attached to that overlays
2539 for (i
= 1; i
< vid_dev
->num_overlays
; i
++) {
2540 ovl
= omap_dss_get_overlay(i
);
2541 if (ovl
->manager
&& ovl
->manager
->device
) {
2542 def_display
= ovl
->manager
->device
;
2544 dev_warn(&pdev
->dev
, "cannot find display\n");
2548 struct omap_dss_driver
*dssdrv
= def_display
->driver
;
2550 ret
= dssdrv
->enable(def_display
);
2552 /* Here we are not considering a error
2553 * as display may be enabled by frame
2556 dev_warn(&pdev
->dev
,
2557 "'%s' Display already enabled\n",
2560 /* set the update mode */
2561 if (def_display
->caps
&
2562 OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
) {
2563 if (dssdrv
->enable_te
)
2564 dssdrv
->enable_te(def_display
, 0);
2565 if (dssdrv
->set_update_mode
)
2566 dssdrv
->set_update_mode(def_display
,
2567 OMAP_DSS_UPDATE_MANUAL
);
2569 if (dssdrv
->set_update_mode
)
2570 dssdrv
->set_update_mode(def_display
,
2571 OMAP_DSS_UPDATE_AUTO
);
2576 if (v4l2_device_register(&pdev
->dev
, &vid_dev
->v4l2_dev
) < 0) {
2577 dev_err(&pdev
->dev
, "v4l2_device_register failed\n");
2582 ret
= omap_vout_create_video_devices(pdev
);
2586 for (i
= 0; i
< vid_dev
->num_displays
; i
++) {
2587 struct omap_dss_device
*display
= vid_dev
->displays
[i
];
2589 if (display
->driver
->update
)
2590 display
->driver
->update(display
, 0, 0,
2591 display
->panel
.timings
.x_res
,
2592 display
->panel
.timings
.y_res
);
2597 v4l2_device_unregister(&vid_dev
->v4l2_dev
);
2599 for (i
= 1; i
< vid_dev
->num_overlays
; i
++) {
2601 ovl
= omap_dss_get_overlay(i
);
2602 if (ovl
->manager
&& ovl
->manager
->device
)
2603 def_display
= ovl
->manager
->device
;
2605 if (def_display
&& def_display
->driver
)
2606 def_display
->driver
->disable(def_display
);
2613 static struct platform_driver omap_vout_driver
= {
2617 .probe
= omap_vout_probe
,
2618 .remove
= omap_vout_remove
,
2621 static int __init
omap_vout_init(void)
2623 if (platform_driver_register(&omap_vout_driver
) != 0) {
2624 printk(KERN_ERR VOUT_NAME
":Could not register Video driver\n");
2630 static void omap_vout_cleanup(void)
2632 platform_driver_unregister(&omap_vout_driver
);
2635 late_initcall(omap_vout_init
);
2636 module_exit(omap_vout_cleanup
);