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>
41 #include <media/videobuf-dma-contig.h>
42 #include <media/v4l2-device.h>
43 #include <media/v4l2-ioctl.h>
46 #include <plat/vrfb.h>
47 #include <video/omapdss.h>
49 #include "omap_voutlib.h"
50 #include "omap_voutdef.h"
52 MODULE_AUTHOR("Texas Instruments");
53 MODULE_DESCRIPTION("OMAP Video for Linux Video out driver");
54 MODULE_LICENSE("GPL");
56 /* Driver Configuration macros */
57 #define VOUT_NAME "omap_vout"
59 enum omap_vout_channels {
64 static struct videobuf_queue_ops video_vbq_ops;
65 /* Variables configurable through module params*/
66 static u32 video1_numbuffers = 3;
67 static u32 video2_numbuffers = 3;
68 static u32 video1_bufsize = OMAP_VOUT_MAX_BUF_SIZE;
69 static u32 video2_bufsize = OMAP_VOUT_MAX_BUF_SIZE;
70 static u32 vid1_static_vrfb_alloc;
71 static u32 vid2_static_vrfb_alloc;
74 /* Module parameters */
75 module_param(video1_numbuffers, uint, S_IRUGO);
76 MODULE_PARM_DESC(video1_numbuffers,
77 "Number of buffers to be allocated at init time for Video1 device.");
79 module_param(video2_numbuffers, uint, S_IRUGO);
80 MODULE_PARM_DESC(video2_numbuffers,
81 "Number of buffers to be allocated at init time for Video2 device.");
83 module_param(video1_bufsize, uint, S_IRUGO);
84 MODULE_PARM_DESC(video1_bufsize,
85 "Size of the buffer to be allocated for video1 device");
87 module_param(video2_bufsize, uint, S_IRUGO);
88 MODULE_PARM_DESC(video2_bufsize,
89 "Size of the buffer to be allocated for video2 device");
91 module_param(vid1_static_vrfb_alloc, bool, S_IRUGO);
92 MODULE_PARM_DESC(vid1_static_vrfb_alloc,
93 "Static allocation of the VRFB buffer for video1 device");
95 module_param(vid2_static_vrfb_alloc, bool, S_IRUGO);
96 MODULE_PARM_DESC(vid2_static_vrfb_alloc,
97 "Static allocation of the VRFB buffer for video2 device");
99 module_param(debug, bool, S_IRUGO);
100 MODULE_PARM_DESC(debug, "Debug level (0-1)");
102 /* list of image formats supported by OMAP2 video pipelines */
103 static const struct v4l2_fmtdesc omap_formats[] = {
105 /* Note: V4L2 defines RGB565 as:
108 * g2 g1 g0 r4 r3 r2 r1 r0 b4 b3 b2 b1 b0 g5 g4 g3
110 * We interpret RGB565 as:
113 * g2 g1 g0 b4 b3 b2 b1 b0 r4 r3 r2 r1 r0 g5 g4 g3
115 .description = "RGB565, le",
116 .pixelformat = V4L2_PIX_FMT_RGB565,
119 /* Note: V4L2 defines RGB32 as: RGB-8-8-8-8 we use
120 * this for RGB24 unpack mode, the last 8 bits are ignored
122 .description = "RGB32, le",
123 .pixelformat = V4L2_PIX_FMT_RGB32,
126 /* Note: V4L2 defines RGB24 as: RGB-8-8-8 we use
127 * this for RGB24 packed mode
130 .description = "RGB24, le",
131 .pixelformat = V4L2_PIX_FMT_RGB24,
134 .description = "YUYV (YUV 4:2:2), packed",
135 .pixelformat = V4L2_PIX_FMT_YUYV,
138 .description = "UYVY, packed",
139 .pixelformat = V4L2_PIX_FMT_UYVY,
143 #define NUM_OUTPUT_FORMATS (ARRAY_SIZE(omap_formats))
146 * Function for allocating video buffers
148 static int omap_vout_allocate_vrfb_buffers(struct omap_vout_device *vout,
149 unsigned int *count, int startindex)
153 for (i = 0; i < *count; i++) {
154 if (!vout->smsshado_virt_addr[i]) {
155 vout->smsshado_virt_addr[i] =
156 omap_vout_alloc_buffer(vout->smsshado_size,
157 &vout->smsshado_phy_addr[i]);
159 if (!vout->smsshado_virt_addr[i] && startindex != -1) {
160 if (V4L2_MEMORY_MMAP == vout->memory && i >= startindex)
163 if (!vout->smsshado_virt_addr[i]) {
164 for (j = 0; j < i; j++) {
165 omap_vout_free_buffer(
166 vout->smsshado_virt_addr[j],
167 vout->smsshado_size);
168 vout->smsshado_virt_addr[j] = 0;
169 vout->smsshado_phy_addr[j] = 0;
174 memset((void *) vout->smsshado_virt_addr[i], 0,
175 vout->smsshado_size);
183 static int omap_vout_try_format(struct v4l2_pix_format *pix)
187 pix->height = clamp(pix->height, (u32)VID_MIN_HEIGHT,
188 (u32)VID_MAX_HEIGHT);
189 pix->width = clamp(pix->width, (u32)VID_MIN_WIDTH, (u32)VID_MAX_WIDTH);
191 for (ifmt = 0; ifmt < NUM_OUTPUT_FORMATS; ifmt++) {
192 if (pix->pixelformat == omap_formats[ifmt].pixelformat)
196 if (ifmt == NUM_OUTPUT_FORMATS)
199 pix->pixelformat = omap_formats[ifmt].pixelformat;
200 pix->field = V4L2_FIELD_ANY;
203 switch (pix->pixelformat) {
204 case V4L2_PIX_FMT_YUYV:
205 case V4L2_PIX_FMT_UYVY:
207 pix->colorspace = V4L2_COLORSPACE_JPEG;
210 case V4L2_PIX_FMT_RGB565:
211 case V4L2_PIX_FMT_RGB565X:
212 pix->colorspace = V4L2_COLORSPACE_SRGB;
215 case V4L2_PIX_FMT_RGB24:
216 pix->colorspace = V4L2_COLORSPACE_SRGB;
219 case V4L2_PIX_FMT_RGB32:
220 case V4L2_PIX_FMT_BGR32:
221 pix->colorspace = V4L2_COLORSPACE_SRGB;
225 pix->bytesperline = pix->width * bpp;
226 pix->sizeimage = pix->bytesperline * pix->height;
232 * omap_vout_uservirt_to_phys: This inline function is used to convert user
233 * space virtual address to physical address.
235 static u32 omap_vout_uservirt_to_phys(u32 virtp)
237 unsigned long physp = 0;
238 struct vm_area_struct *vma;
239 struct mm_struct *mm = current->mm;
241 vma = find_vma(mm, virtp);
242 /* For kernel direct-mapped memory, take the easy way */
243 if (virtp >= PAGE_OFFSET) {
244 physp = virt_to_phys((void *) virtp);
245 } else if (vma && (vma->vm_flags & VM_IO) && vma->vm_pgoff) {
246 /* this will catch, kernel-allocated, mmaped-to-usermode
248 physp = (vma->vm_pgoff << PAGE_SHIFT) + (virtp - vma->vm_start);
250 /* otherwise, use get_user_pages() for general userland pages */
251 int res, nr_pages = 1;
253 down_read(¤t->mm->mmap_sem);
255 res = get_user_pages(current, current->mm, virtp, nr_pages, 1,
257 up_read(¤t->mm->mmap_sem);
259 if (res == nr_pages) {
260 physp = __pa(page_address(&pages[0]) +
261 (virtp & ~PAGE_MASK));
263 printk(KERN_WARNING VOUT_NAME
264 "get_user_pages failed\n");
273 * Wakes up the application once the DMA transfer to VRFB space is completed.
275 static void omap_vout_vrfb_dma_tx_callback(int lch, u16 ch_status, void *data)
277 struct vid_vrfb_dma *t = (struct vid_vrfb_dma *) data;
280 wake_up_interruptible(&t->wait);
284 * Release the VRFB context once the module exits
286 static void omap_vout_release_vrfb(struct omap_vout_device *vout)
290 for (i = 0; i < VRFB_NUM_BUFS; i++)
291 omap_vrfb_release_ctx(&vout->vrfb_context[i]);
293 if (vout->vrfb_dma_tx.req_status == DMA_CHAN_ALLOTED) {
294 vout->vrfb_dma_tx.req_status = DMA_CHAN_NOT_ALLOTED;
295 omap_free_dma(vout->vrfb_dma_tx.dma_ch);
300 * Free the V4L2 buffers
302 static void omap_vout_free_buffers(struct omap_vout_device *vout)
306 /* Allocate memory for the buffers */
307 numbuffers = (vout->vid) ? video2_numbuffers : video1_numbuffers;
308 vout->buffer_size = (vout->vid) ? video2_bufsize : video1_bufsize;
310 for (i = 0; i < numbuffers; i++) {
311 omap_vout_free_buffer(vout->buf_virt_addr[i],
313 vout->buf_phy_addr[i] = 0;
314 vout->buf_virt_addr[i] = 0;
321 static void omap_vout_free_vrfb_buffers(struct omap_vout_device *vout)
325 for (j = 0; j < VRFB_NUM_BUFS; j++) {
326 omap_vout_free_buffer(vout->smsshado_virt_addr[j],
327 vout->smsshado_size);
328 vout->smsshado_virt_addr[j] = 0;
329 vout->smsshado_phy_addr[j] = 0;
334 * Allocate the buffers for the VRFB space. Data is copied from V4L2
335 * buffers to the VRFB buffers using the DMA engine.
337 static int omap_vout_vrfb_buffer_setup(struct omap_vout_device *vout,
338 unsigned int *count, unsigned int startindex)
343 /* Allocate the VRFB buffers only if the buffers are not
344 * allocated during init time.
346 if ((rotation_enabled(vout)) && !vout->vrfb_static_allocation)
347 if (omap_vout_allocate_vrfb_buffers(vout, count, startindex))
350 if (vout->dss_mode == OMAP_DSS_COLOR_YUV2 ||
351 vout->dss_mode == OMAP_DSS_COLOR_UYVY)
356 for (i = 0; i < *count; i++)
357 omap_vrfb_setup(&vout->vrfb_context[i],
358 vout->smsshado_phy_addr[i], vout->pix.width,
359 vout->pix.height, vout->bpp, yuv_mode);
365 * Convert V4L2 rotation to DSS rotation
366 * V4L2 understand 0, 90, 180, 270.
367 * Convert to 0, 1, 2 and 3 respectively for DSS
369 static int v4l2_rot_to_dss_rot(int v4l2_rotation,
370 enum dss_rotation *rotation, bool mirror)
374 switch (v4l2_rotation) {
376 *rotation = dss_rotation_90_degree;
379 *rotation = dss_rotation_180_degree;
382 *rotation = dss_rotation_270_degree;
385 *rotation = dss_rotation_0_degree;
394 * Calculate the buffer offsets from which the streaming should
395 * start. This offset calculation is mainly required because of
396 * the VRFB 32 pixels alignment with rotation.
398 static int omap_vout_calculate_offset(struct omap_vout_device *vout)
400 struct omap_overlay *ovl;
401 enum dss_rotation rotation;
402 struct omapvideo_info *ovid;
403 bool mirroring = vout->mirror;
404 struct omap_dss_device *cur_display;
405 struct v4l2_rect *crop = &vout->crop;
406 struct v4l2_pix_format *pix = &vout->pix;
407 int *cropped_offset = &vout->cropped_offset;
408 int vr_ps = 1, ps = 2, temp_ps = 2;
409 int offset = 0, ctop = 0, cleft = 0, line_length = 0;
411 ovid = &vout->vid_info;
412 ovl = ovid->overlays[0];
413 /* get the display device attached to the overlay */
414 if (!ovl->manager || !ovl->manager->device)
417 cur_display = ovl->manager->device;
418 rotation = calc_rotation(vout);
420 if (V4L2_PIX_FMT_YUYV == pix->pixelformat ||
421 V4L2_PIX_FMT_UYVY == pix->pixelformat) {
422 if (rotation_enabled(vout)) {
424 * ps - Actual pixel size for YUYV/UYVY for
425 * VRFB/Mirroring is 4 bytes
426 * vr_ps - Virtually pixel size for YUYV/UYVY is
432 ps = 2; /* otherwise the pixel size is 2 byte */
434 } else if (V4L2_PIX_FMT_RGB32 == pix->pixelformat) {
436 } else if (V4L2_PIX_FMT_RGB24 == pix->pixelformat) {
442 if (rotation_enabled(vout)) {
443 line_length = MAX_PIXELS_PER_LINE;
444 ctop = (pix->height - crop->height) - crop->top;
445 cleft = (pix->width - crop->width) - crop->left;
447 line_length = pix->width;
449 vout->line_length = line_length;
451 case dss_rotation_90_degree:
452 offset = vout->vrfb_context[0].yoffset *
453 vout->vrfb_context[0].bytespp;
454 temp_ps = ps / vr_ps;
455 if (mirroring == 0) {
456 *cropped_offset = offset + line_length *
457 temp_ps * cleft + crop->top * temp_ps;
459 *cropped_offset = offset + line_length * temp_ps *
460 cleft + crop->top * temp_ps + (line_length *
461 ((crop->width / (vr_ps)) - 1) * ps);
464 case dss_rotation_180_degree:
465 offset = ((MAX_PIXELS_PER_LINE * vout->vrfb_context[0].yoffset *
466 vout->vrfb_context[0].bytespp) +
467 (vout->vrfb_context[0].xoffset *
468 vout->vrfb_context[0].bytespp));
469 if (mirroring == 0) {
470 *cropped_offset = offset + (line_length * ps * ctop) +
471 (cleft / vr_ps) * ps;
474 *cropped_offset = offset + (line_length * ps * ctop) +
475 (cleft / vr_ps) * ps + (line_length *
476 (crop->height - 1) * ps);
479 case dss_rotation_270_degree:
480 offset = MAX_PIXELS_PER_LINE * vout->vrfb_context[0].xoffset *
481 vout->vrfb_context[0].bytespp;
482 temp_ps = ps / vr_ps;
483 if (mirroring == 0) {
484 *cropped_offset = offset + line_length *
485 temp_ps * crop->left + ctop * ps;
487 *cropped_offset = offset + line_length *
488 temp_ps * crop->left + ctop * ps +
489 (line_length * ((crop->width / vr_ps) - 1) *
493 case dss_rotation_0_degree:
494 if (mirroring == 0) {
495 *cropped_offset = (line_length * ps) *
496 crop->top + (crop->left / vr_ps) * ps;
498 *cropped_offset = (line_length * ps) *
499 crop->top + (crop->left / vr_ps) * ps +
500 (line_length * (crop->height - 1) * ps);
504 *cropped_offset = (line_length * ps * crop->top) /
505 vr_ps + (crop->left * ps) / vr_ps +
506 ((crop->width / vr_ps) - 1) * ps;
509 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "%s Offset:%x\n",
510 __func__, *cropped_offset);
515 * Convert V4L2 pixel format to DSS pixel format
517 static int video_mode_to_dss_mode(struct omap_vout_device *vout)
519 struct omap_overlay *ovl;
520 struct omapvideo_info *ovid;
521 struct v4l2_pix_format *pix = &vout->pix;
522 enum omap_color_mode mode;
524 ovid = &vout->vid_info;
525 ovl = ovid->overlays[0];
527 switch (pix->pixelformat) {
530 case V4L2_PIX_FMT_YUYV:
531 mode = OMAP_DSS_COLOR_YUV2;
533 case V4L2_PIX_FMT_UYVY:
534 mode = OMAP_DSS_COLOR_UYVY;
536 case V4L2_PIX_FMT_RGB565:
537 mode = OMAP_DSS_COLOR_RGB16;
539 case V4L2_PIX_FMT_RGB24:
540 mode = OMAP_DSS_COLOR_RGB24P;
542 case V4L2_PIX_FMT_RGB32:
543 mode = (ovl->id == OMAP_DSS_VIDEO1) ?
544 OMAP_DSS_COLOR_RGB24U : OMAP_DSS_COLOR_ARGB32;
546 case V4L2_PIX_FMT_BGR32:
547 mode = OMAP_DSS_COLOR_RGBX32;
558 static int omapvid_setup_overlay(struct omap_vout_device *vout,
559 struct omap_overlay *ovl, int posx, int posy, int outw,
563 struct omap_overlay_info info;
564 int cropheight, cropwidth, pixheight, pixwidth;
566 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0 &&
567 (outw != vout->pix.width || outh != vout->pix.height)) {
572 vout->dss_mode = video_mode_to_dss_mode(vout);
573 if (vout->dss_mode == -EINVAL) {
578 /* Setup the input plane parameters according to
579 * rotation value selected.
581 if (rotate_90_or_270(vout)) {
582 cropheight = vout->crop.width;
583 cropwidth = vout->crop.height;
584 pixheight = vout->pix.width;
585 pixwidth = vout->pix.height;
587 cropheight = vout->crop.height;
588 cropwidth = vout->crop.width;
589 pixheight = vout->pix.height;
590 pixwidth = vout->pix.width;
593 ovl->get_overlay_info(ovl, &info);
596 info.width = cropwidth;
597 info.height = cropheight;
598 info.color_mode = vout->dss_mode;
599 info.mirror = vout->mirror;
602 info.out_width = outw;
603 info.out_height = outh;
604 info.global_alpha = vout->win.global_alpha;
605 if (!rotation_enabled(vout)) {
607 info.rotation_type = OMAP_DSS_ROT_DMA;
608 info.screen_width = pixwidth;
610 info.rotation = vout->rotation;
611 info.rotation_type = OMAP_DSS_ROT_VRFB;
612 info.screen_width = 2048;
615 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev,
616 "%s enable=%d addr=%x width=%d\n height=%d color_mode=%d\n"
617 "rotation=%d mirror=%d posx=%d posy=%d out_width = %d \n"
618 "out_height=%d rotation_type=%d screen_width=%d\n",
619 __func__, info.enabled, info.paddr, info.width, info.height,
620 info.color_mode, info.rotation, info.mirror, info.pos_x,
621 info.pos_y, info.out_width, info.out_height, info.rotation_type,
624 ret = ovl->set_overlay_info(ovl, &info);
631 v4l2_warn(&vout->vid_dev->v4l2_dev, "setup_overlay failed\n");
636 * Initialize the overlay structure
638 static int omapvid_init(struct omap_vout_device *vout, u32 addr)
641 struct v4l2_window *win;
642 struct omap_overlay *ovl;
643 int posx, posy, outw, outh, temp;
644 struct omap_video_timings *timing;
645 struct omapvideo_info *ovid = &vout->vid_info;
648 for (i = 0; i < ovid->num_overlays; i++) {
649 ovl = ovid->overlays[i];
650 if (!ovl->manager || !ovl->manager->device)
653 timing = &ovl->manager->device->panel.timings;
656 outh = win->w.height;
657 switch (vout->rotation) {
658 case dss_rotation_90_degree:
659 /* Invert the height and width for 90
660 * and 270 degree rotation
665 posy = (timing->y_res - win->w.width) - win->w.left;
669 case dss_rotation_180_degree:
670 posx = (timing->x_res - win->w.width) - win->w.left;
671 posy = (timing->y_res - win->w.height) - win->w.top;
674 case dss_rotation_270_degree:
679 posx = (timing->x_res - win->w.height) - win->w.top;
688 ret = omapvid_setup_overlay(vout, ovl, posx, posy,
691 goto omapvid_init_err;
696 v4l2_warn(&vout->vid_dev->v4l2_dev, "apply_changes failed\n");
701 * Apply the changes set the go bit of DSS
703 static int omapvid_apply_changes(struct omap_vout_device *vout)
706 struct omap_overlay *ovl;
707 struct omapvideo_info *ovid = &vout->vid_info;
709 for (i = 0; i < ovid->num_overlays; i++) {
710 ovl = ovid->overlays[i];
711 if (!ovl->manager || !ovl->manager->device)
713 ovl->manager->apply(ovl->manager);
719 static void omap_vout_isr(void *arg, unsigned int irqstatus)
723 struct omap_overlay *ovl;
724 struct timeval timevalue;
725 struct omapvideo_info *ovid;
726 struct omap_dss_device *cur_display;
727 struct omap_vout_device *vout = (struct omap_vout_device *)arg;
729 if (!vout->streaming)
732 ovid = &vout->vid_info;
733 ovl = ovid->overlays[0];
734 /* get the display device attached to the overlay */
735 if (!ovl->manager || !ovl->manager->device)
738 cur_display = ovl->manager->device;
740 spin_lock(&vout->vbq_lock);
741 do_gettimeofday(&timevalue);
742 if (cur_display->type == OMAP_DISPLAY_TYPE_DPI) {
743 if (!(irqstatus & DISPC_IRQ_VSYNC))
746 if (!vout->first_int && (vout->cur_frm != vout->next_frm)) {
747 vout->cur_frm->ts = timevalue;
748 vout->cur_frm->state = VIDEOBUF_DONE;
749 wake_up_interruptible(&vout->cur_frm->done);
750 vout->cur_frm = vout->next_frm;
753 if (list_empty(&vout->dma_queue))
756 vout->next_frm = list_entry(vout->dma_queue.next,
757 struct videobuf_buffer, queue);
758 list_del(&vout->next_frm->queue);
760 vout->next_frm->state = VIDEOBUF_ACTIVE;
762 addr = (unsigned long) vout->queued_buf_addr[vout->next_frm->i]
763 + vout->cropped_offset;
765 /* First save the configuration in ovelray structure */
766 ret = omapvid_init(vout, addr);
768 printk(KERN_ERR VOUT_NAME
769 "failed to set overlay info\n");
770 /* Enable the pipeline and set the Go bit */
771 ret = omapvid_apply_changes(vout);
773 printk(KERN_ERR VOUT_NAME "failed to change mode\n");
776 if (vout->first_int) {
780 if (irqstatus & DISPC_IRQ_EVSYNC_ODD)
782 else if (irqstatus & DISPC_IRQ_EVSYNC_EVEN)
788 if (fid != vout->field_id) {
790 vout->field_id = fid;
795 if (vout->cur_frm == vout->next_frm)
798 vout->cur_frm->ts = timevalue;
799 vout->cur_frm->state = VIDEOBUF_DONE;
800 wake_up_interruptible(&vout->cur_frm->done);
801 vout->cur_frm = vout->next_frm;
802 } else if (1 == fid) {
803 if (list_empty(&vout->dma_queue) ||
804 (vout->cur_frm != vout->next_frm))
807 vout->next_frm = list_entry(vout->dma_queue.next,
808 struct videobuf_buffer, queue);
809 list_del(&vout->next_frm->queue);
811 vout->next_frm->state = VIDEOBUF_ACTIVE;
812 addr = (unsigned long)
813 vout->queued_buf_addr[vout->next_frm->i] +
814 vout->cropped_offset;
815 /* First save the configuration in ovelray structure */
816 ret = omapvid_init(vout, addr);
818 printk(KERN_ERR VOUT_NAME
819 "failed to set overlay info\n");
820 /* Enable the pipeline and set the Go bit */
821 ret = omapvid_apply_changes(vout);
823 printk(KERN_ERR VOUT_NAME
824 "failed to change mode\n");
830 spin_unlock(&vout->vbq_lock);
834 /* Video buffer call backs */
837 * Buffer setup function is called by videobuf layer when REQBUF ioctl is
838 * called. This is used to setup buffers and return size and count of
839 * buffers allocated. After the call to this buffer, videobuf layer will
840 * setup buffer queue depending on the size and count of buffers
842 static int omap_vout_buffer_setup(struct videobuf_queue *q, unsigned int *count,
845 int startindex = 0, i, j;
846 u32 phy_addr = 0, virt_addr = 0;
847 struct omap_vout_device *vout = q->priv_data;
852 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != q->type)
855 startindex = (vout->vid == OMAP_VIDEO1) ?
856 video1_numbuffers : video2_numbuffers;
857 if (V4L2_MEMORY_MMAP == vout->memory && *count < startindex)
860 if ((rotation_enabled(vout)) && *count > VRFB_NUM_BUFS)
861 *count = VRFB_NUM_BUFS;
863 /* If rotation is enabled, allocate memory for VRFB space also */
864 if (rotation_enabled(vout))
865 if (omap_vout_vrfb_buffer_setup(vout, count, startindex))
868 if (V4L2_MEMORY_MMAP != vout->memory)
871 /* Now allocated the V4L2 buffers */
872 *size = PAGE_ALIGN(vout->pix.width * vout->pix.height * vout->bpp);
873 startindex = (vout->vid == OMAP_VIDEO1) ?
874 video1_numbuffers : video2_numbuffers;
876 /* Check the size of the buffer */
877 if (*size > vout->buffer_size) {
878 v4l2_err(&vout->vid_dev->v4l2_dev,
879 "buffer allocation mismatch [%u] [%u]\n",
880 *size, vout->buffer_size);
884 for (i = startindex; i < *count; i++) {
885 vout->buffer_size = *size;
887 virt_addr = omap_vout_alloc_buffer(vout->buffer_size,
890 if (!rotation_enabled(vout))
892 /* Free the VRFB buffers if no space for V4L2 buffers */
893 for (j = i; j < *count; j++) {
894 omap_vout_free_buffer(
895 vout->smsshado_virt_addr[j],
896 vout->smsshado_size);
897 vout->smsshado_virt_addr[j] = 0;
898 vout->smsshado_phy_addr[j] = 0;
901 vout->buf_virt_addr[i] = virt_addr;
902 vout->buf_phy_addr[i] = phy_addr;
904 *count = vout->buffer_allocated = i;
910 * Free the V4L2 buffers additionally allocated than default
911 * number of buffers and free all the VRFB buffers
913 static void omap_vout_free_allbuffers(struct omap_vout_device *vout)
915 int num_buffers = 0, i;
917 num_buffers = (vout->vid == OMAP_VIDEO1) ?
918 video1_numbuffers : video2_numbuffers;
920 for (i = num_buffers; i < vout->buffer_allocated; i++) {
921 if (vout->buf_virt_addr[i])
922 omap_vout_free_buffer(vout->buf_virt_addr[i],
925 vout->buf_virt_addr[i] = 0;
926 vout->buf_phy_addr[i] = 0;
928 /* Free the VRFB buffers only if they are allocated
929 * during reqbufs. Don't free if init time allocated
931 if (!vout->vrfb_static_allocation) {
932 for (i = 0; i < VRFB_NUM_BUFS; i++) {
933 if (vout->smsshado_virt_addr[i]) {
934 omap_vout_free_buffer(
935 vout->smsshado_virt_addr[i],
936 vout->smsshado_size);
937 vout->smsshado_virt_addr[i] = 0;
938 vout->smsshado_phy_addr[i] = 0;
942 vout->buffer_allocated = num_buffers;
946 * This function will be called when VIDIOC_QBUF ioctl is called.
947 * It prepare buffers before give out for the display. This function
948 * converts user space virtual address into physical address if userptr memory
949 * exchange mechanism is used. If rotation is enabled, it copies entire
950 * buffer into VRFB memory space before giving it to the DSS.
952 static int omap_vout_buffer_prepare(struct videobuf_queue *q,
953 struct videobuf_buffer *vb,
954 enum v4l2_field field)
957 struct vid_vrfb_dma *tx;
958 enum dss_rotation rotation;
959 struct omap_vout_device *vout = q->priv_data;
960 u32 dest_frame_index = 0, src_element_index = 0;
961 u32 dest_element_index = 0, src_frame_index = 0;
962 u32 elem_count = 0, frame_count = 0, pixsize = 2;
964 if (VIDEOBUF_NEEDS_INIT == vb->state) {
965 vb->width = vout->pix.width;
966 vb->height = vout->pix.height;
967 vb->size = vb->width * vb->height * vout->bpp;
970 vb->state = VIDEOBUF_PREPARED;
971 /* if user pointer memory mechanism is used, get the physical
972 * address of the buffer
974 if (V4L2_MEMORY_USERPTR == vb->memory) {
977 /* Physical address */
978 vout->queued_buf_addr[vb->i] = (u8 *)
979 omap_vout_uservirt_to_phys(vb->baddr);
981 vout->queued_buf_addr[vb->i] = (u8 *)vout->buf_phy_addr[vb->i];
984 if (!rotation_enabled(vout))
987 dmabuf = vout->buf_phy_addr[vb->i];
988 /* If rotation is enabled, copy input buffer into VRFB
989 * memory space using DMA. We are copying input buffer
990 * into VRFB memory space of desired angle and DSS will
991 * read image VRFB memory for 0 degree angle
993 pixsize = vout->bpp * vout->vrfb_bpp;
995 * DMA transfer in double index mode
999 dest_frame_index = ((MAX_PIXELS_PER_LINE * pixsize) -
1000 (vout->pix.width * vout->bpp)) + 1;
1002 /* Source and destination parameters */
1003 src_element_index = 0;
1004 src_frame_index = 0;
1005 dest_element_index = 1;
1006 /* Number of elements per frame */
1007 elem_count = vout->pix.width * vout->bpp;
1008 frame_count = vout->pix.height;
1009 tx = &vout->vrfb_dma_tx;
1011 omap_set_dma_transfer_params(tx->dma_ch, OMAP_DMA_DATA_TYPE_S32,
1012 (elem_count / 4), frame_count, OMAP_DMA_SYNC_ELEMENT,
1014 /* src_port required only for OMAP1 */
1015 omap_set_dma_src_params(tx->dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
1016 dmabuf, src_element_index, src_frame_index);
1017 /*set dma source burst mode for VRFB */
1018 omap_set_dma_src_burst_mode(tx->dma_ch, OMAP_DMA_DATA_BURST_16);
1019 rotation = calc_rotation(vout);
1021 /* dest_port required only for OMAP1 */
1022 omap_set_dma_dest_params(tx->dma_ch, 0, OMAP_DMA_AMODE_DOUBLE_IDX,
1023 vout->vrfb_context[vb->i].paddr[0], dest_element_index,
1025 /*set dma dest burst mode for VRFB */
1026 omap_set_dma_dest_burst_mode(tx->dma_ch, OMAP_DMA_DATA_BURST_16);
1027 omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE, 0x20, 0);
1029 omap_start_dma(tx->dma_ch);
1030 interruptible_sleep_on_timeout(&tx->wait, VRFB_TX_TIMEOUT);
1032 if (tx->tx_status == 0) {
1033 omap_stop_dma(tx->dma_ch);
1036 /* Store buffers physical address into an array. Addresses
1037 * from this array will be used to configure DSS */
1038 vout->queued_buf_addr[vb->i] = (u8 *)
1039 vout->vrfb_context[vb->i].paddr[rotation];
1044 * Buffer queue function will be called from the videobuf layer when _QBUF
1045 * ioctl is called. It is used to enqueue buffer, which is ready to be
1048 static void omap_vout_buffer_queue(struct videobuf_queue *q,
1049 struct videobuf_buffer *vb)
1051 struct omap_vout_device *vout = q->priv_data;
1053 /* Driver is also maintainig a queue. So enqueue buffer in the driver
1055 list_add_tail(&vb->queue, &vout->dma_queue);
1057 vb->state = VIDEOBUF_QUEUED;
1061 * Buffer release function is called from videobuf layer to release buffer
1062 * which are already allocated
1064 static void omap_vout_buffer_release(struct videobuf_queue *q,
1065 struct videobuf_buffer *vb)
1067 struct omap_vout_device *vout = q->priv_data;
1069 vb->state = VIDEOBUF_NEEDS_INIT;
1071 if (V4L2_MEMORY_MMAP != vout->memory)
1078 static void omap_vout_vm_open(struct vm_area_struct *vma)
1080 struct omap_vout_device *vout = vma->vm_private_data;
1082 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev,
1083 "vm_open [vma=%08lx-%08lx]\n", vma->vm_start, vma->vm_end);
1087 static void omap_vout_vm_close(struct vm_area_struct *vma)
1089 struct omap_vout_device *vout = vma->vm_private_data;
1091 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev,
1092 "vm_close [vma=%08lx-%08lx]\n", vma->vm_start, vma->vm_end);
1096 static struct vm_operations_struct omap_vout_vm_ops = {
1097 .open = omap_vout_vm_open,
1098 .close = omap_vout_vm_close,
1101 static int omap_vout_mmap(struct file *file, struct vm_area_struct *vma)
1105 unsigned long start = vma->vm_start;
1106 unsigned long size = (vma->vm_end - vma->vm_start);
1107 struct omap_vout_device *vout = file->private_data;
1108 struct videobuf_queue *q = &vout->vbq;
1110 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev,
1111 " %s pgoff=0x%lx, start=0x%lx, end=0x%lx\n", __func__,
1112 vma->vm_pgoff, vma->vm_start, vma->vm_end);
1114 /* look for the buffer to map */
1115 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
1116 if (NULL == q->bufs[i])
1118 if (V4L2_MEMORY_MMAP != q->bufs[i]->memory)
1120 if (q->bufs[i]->boff == (vma->vm_pgoff << PAGE_SHIFT))
1124 if (VIDEO_MAX_FRAME == i) {
1125 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev,
1126 "offset invalid [offset=0x%lx]\n",
1127 (vma->vm_pgoff << PAGE_SHIFT));
1130 /* Check the size of the buffer */
1131 if (size > vout->buffer_size) {
1132 v4l2_err(&vout->vid_dev->v4l2_dev,
1133 "insufficient memory [%lu] [%u]\n",
1134 size, vout->buffer_size);
1138 q->bufs[i]->baddr = vma->vm_start;
1140 vma->vm_flags |= VM_RESERVED;
1141 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
1142 vma->vm_ops = &omap_vout_vm_ops;
1143 vma->vm_private_data = (void *) vout;
1144 pos = (void *)vout->buf_virt_addr[i];
1145 vma->vm_pgoff = virt_to_phys((void *)pos) >> PAGE_SHIFT;
1148 pfn = virt_to_phys((void *) pos) >> PAGE_SHIFT;
1149 if (remap_pfn_range(vma, start, pfn, PAGE_SIZE, PAGE_SHARED))
1156 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Exiting %s\n", __func__);
1161 static int omap_vout_release(struct file *file)
1163 unsigned int ret, i;
1164 struct videobuf_queue *q;
1165 struct omapvideo_info *ovid;
1166 struct omap_vout_device *vout = file->private_data;
1168 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
1169 ovid = &vout->vid_info;
1175 /* Disable all the overlay managers connected with this interface */
1176 for (i = 0; i < ovid->num_overlays; i++) {
1177 struct omap_overlay *ovl = ovid->overlays[i];
1178 if (ovl->manager && ovl->manager->device) {
1179 struct omap_overlay_info info;
1180 ovl->get_overlay_info(ovl, &info);
1182 ovl->set_overlay_info(ovl, &info);
1185 /* Turn off the pipeline */
1186 ret = omapvid_apply_changes(vout);
1188 v4l2_warn(&vout->vid_dev->v4l2_dev,
1189 "Unable to apply changes\n");
1191 /* Free all buffers */
1192 omap_vout_free_allbuffers(vout);
1193 videobuf_mmap_free(q);
1195 /* Even if apply changes fails we should continue
1196 freeing allocated memory */
1197 if (vout->streaming) {
1200 mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_EVEN |
1201 DISPC_IRQ_EVSYNC_ODD;
1202 omap_dispc_unregister_isr(omap_vout_isr, vout, mask);
1203 vout->streaming = 0;
1205 videobuf_streamoff(q);
1206 videobuf_queue_cancel(q);
1209 if (vout->mmap_count != 0)
1210 vout->mmap_count = 0;
1213 file->private_data = NULL;
1215 if (vout->buffer_allocated)
1216 videobuf_mmap_free(q);
1218 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Exiting %s\n", __func__);
1222 static int omap_vout_open(struct file *file)
1224 struct videobuf_queue *q;
1225 struct omap_vout_device *vout = NULL;
1227 vout = video_drvdata(file);
1228 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
1233 /* for now, we only support single open */
1239 file->private_data = vout;
1240 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
1243 video_vbq_ops.buf_setup = omap_vout_buffer_setup;
1244 video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
1245 video_vbq_ops.buf_release = omap_vout_buffer_release;
1246 video_vbq_ops.buf_queue = omap_vout_buffer_queue;
1247 spin_lock_init(&vout->vbq_lock);
1249 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
1250 &vout->vbq_lock, vout->type, V4L2_FIELD_NONE,
1251 sizeof(struct videobuf_buffer), vout, NULL);
1253 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Exiting %s\n", __func__);
1260 static int vidioc_querycap(struct file *file, void *fh,
1261 struct v4l2_capability *cap)
1263 struct omap_vout_device *vout = fh;
1265 strlcpy(cap->driver, VOUT_NAME, sizeof(cap->driver));
1266 strlcpy(cap->card, vout->vfd->name, sizeof(cap->card));
1267 cap->bus_info[0] = '\0';
1268 cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_OUTPUT;
1273 static int vidioc_enum_fmt_vid_out(struct file *file, void *fh,
1274 struct v4l2_fmtdesc *fmt)
1276 int index = fmt->index;
1277 enum v4l2_buf_type type = fmt->type;
1281 if (index >= NUM_OUTPUT_FORMATS)
1284 fmt->flags = omap_formats[index].flags;
1285 strlcpy(fmt->description, omap_formats[index].description,
1286 sizeof(fmt->description));
1287 fmt->pixelformat = omap_formats[index].pixelformat;
1292 static int vidioc_g_fmt_vid_out(struct file *file, void *fh,
1293 struct v4l2_format *f)
1295 struct omap_vout_device *vout = fh;
1297 f->fmt.pix = vout->pix;
1302 static int vidioc_try_fmt_vid_out(struct file *file, void *fh,
1303 struct v4l2_format *f)
1305 struct omap_overlay *ovl;
1306 struct omapvideo_info *ovid;
1307 struct omap_video_timings *timing;
1308 struct omap_vout_device *vout = fh;
1310 ovid = &vout->vid_info;
1311 ovl = ovid->overlays[0];
1313 if (!ovl->manager || !ovl->manager->device)
1315 /* get the display device attached to the overlay */
1316 timing = &ovl->manager->device->panel.timings;
1318 vout->fbuf.fmt.height = timing->y_res;
1319 vout->fbuf.fmt.width = timing->x_res;
1321 omap_vout_try_format(&f->fmt.pix);
1325 static int vidioc_s_fmt_vid_out(struct file *file, void *fh,
1326 struct v4l2_format *f)
1329 struct omap_overlay *ovl;
1330 struct omapvideo_info *ovid;
1331 struct omap_video_timings *timing;
1332 struct omap_vout_device *vout = fh;
1334 if (vout->streaming)
1337 mutex_lock(&vout->lock);
1339 ovid = &vout->vid_info;
1340 ovl = ovid->overlays[0];
1342 /* get the display device attached to the overlay */
1343 if (!ovl->manager || !ovl->manager->device) {
1345 goto s_fmt_vid_out_exit;
1347 timing = &ovl->manager->device->panel.timings;
1349 /* We dont support RGB24-packed mode if vrfb rotation
1351 if ((rotation_enabled(vout)) &&
1352 f->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB24) {
1354 goto s_fmt_vid_out_exit;
1357 /* get the framebuffer parameters */
1359 if (rotate_90_or_270(vout)) {
1360 vout->fbuf.fmt.height = timing->x_res;
1361 vout->fbuf.fmt.width = timing->y_res;
1363 vout->fbuf.fmt.height = timing->y_res;
1364 vout->fbuf.fmt.width = timing->x_res;
1367 /* change to samller size is OK */
1369 bpp = omap_vout_try_format(&f->fmt.pix);
1370 f->fmt.pix.sizeimage = f->fmt.pix.width * f->fmt.pix.height * bpp;
1372 /* try & set the new output format */
1374 vout->pix = f->fmt.pix;
1377 /* If YUYV then vrfb bpp is 2, for others its 1 */
1378 if (V4L2_PIX_FMT_YUYV == vout->pix.pixelformat ||
1379 V4L2_PIX_FMT_UYVY == vout->pix.pixelformat)
1382 /* set default crop and win */
1383 omap_vout_new_format(&vout->pix, &vout->fbuf, &vout->crop, &vout->win);
1385 /* Save the changes in the overlay strcuture */
1386 ret = omapvid_init(vout, 0);
1388 v4l2_err(&vout->vid_dev->v4l2_dev, "failed to change mode\n");
1389 goto s_fmt_vid_out_exit;
1395 mutex_unlock(&vout->lock);
1399 static int vidioc_try_fmt_vid_overlay(struct file *file, void *fh,
1400 struct v4l2_format *f)
1403 struct omap_vout_device *vout = fh;
1404 struct v4l2_window *win = &f->fmt.win;
1406 ret = omap_vout_try_window(&vout->fbuf, win);
1409 if (vout->vid == OMAP_VIDEO1)
1410 win->global_alpha = 255;
1412 win->global_alpha = f->fmt.win.global_alpha;
1418 static int vidioc_s_fmt_vid_overlay(struct file *file, void *fh,
1419 struct v4l2_format *f)
1422 struct omap_overlay *ovl;
1423 struct omapvideo_info *ovid;
1424 struct omap_vout_device *vout = fh;
1425 struct v4l2_window *win = &f->fmt.win;
1427 mutex_lock(&vout->lock);
1428 ovid = &vout->vid_info;
1429 ovl = ovid->overlays[0];
1431 ret = omap_vout_new_window(&vout->crop, &vout->win, &vout->fbuf, win);
1433 /* Video1 plane does not support global alpha */
1434 if (ovl->id == OMAP_DSS_VIDEO1)
1435 vout->win.global_alpha = 255;
1437 vout->win.global_alpha = f->fmt.win.global_alpha;
1439 vout->win.chromakey = f->fmt.win.chromakey;
1441 mutex_unlock(&vout->lock);
1445 static int vidioc_enum_fmt_vid_overlay(struct file *file, void *fh,
1446 struct v4l2_fmtdesc *fmt)
1448 int index = fmt->index;
1449 enum v4l2_buf_type type = fmt->type;
1453 if (index >= NUM_OUTPUT_FORMATS)
1456 fmt->flags = omap_formats[index].flags;
1457 strlcpy(fmt->description, omap_formats[index].description,
1458 sizeof(fmt->description));
1459 fmt->pixelformat = omap_formats[index].pixelformat;
1463 static int vidioc_g_fmt_vid_overlay(struct file *file, void *fh,
1464 struct v4l2_format *f)
1467 struct omap_overlay *ovl;
1468 struct omapvideo_info *ovid;
1469 struct omap_vout_device *vout = fh;
1470 struct omap_overlay_manager_info info;
1471 struct v4l2_window *win = &f->fmt.win;
1473 ovid = &vout->vid_info;
1474 ovl = ovid->overlays[0];
1476 win->w = vout->win.w;
1477 win->field = vout->win.field;
1478 win->global_alpha = vout->win.global_alpha;
1480 if (ovl->manager && ovl->manager->get_manager_info) {
1481 ovl->manager->get_manager_info(ovl->manager, &info);
1482 key_value = info.trans_key;
1484 win->chromakey = key_value;
1488 static int vidioc_cropcap(struct file *file, void *fh,
1489 struct v4l2_cropcap *cropcap)
1491 struct omap_vout_device *vout = fh;
1492 struct v4l2_pix_format *pix = &vout->pix;
1494 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
1497 /* Width and height are always even */
1498 cropcap->bounds.width = pix->width & ~1;
1499 cropcap->bounds.height = pix->height & ~1;
1501 omap_vout_default_crop(&vout->pix, &vout->fbuf, &cropcap->defrect);
1502 cropcap->pixelaspect.numerator = 1;
1503 cropcap->pixelaspect.denominator = 1;
1507 static int vidioc_g_crop(struct file *file, void *fh, struct v4l2_crop *crop)
1509 struct omap_vout_device *vout = fh;
1511 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
1513 crop->c = vout->crop;
1517 static int vidioc_s_crop(struct file *file, void *fh, struct v4l2_crop *crop)
1520 struct omap_vout_device *vout = fh;
1521 struct omapvideo_info *ovid;
1522 struct omap_overlay *ovl;
1523 struct omap_video_timings *timing;
1525 if (vout->streaming)
1528 mutex_lock(&vout->lock);
1529 ovid = &vout->vid_info;
1530 ovl = ovid->overlays[0];
1532 if (!ovl->manager || !ovl->manager->device) {
1536 /* get the display device attached to the overlay */
1537 timing = &ovl->manager->device->panel.timings;
1539 if (rotate_90_or_270(vout)) {
1540 vout->fbuf.fmt.height = timing->x_res;
1541 vout->fbuf.fmt.width = timing->y_res;
1543 vout->fbuf.fmt.height = timing->y_res;
1544 vout->fbuf.fmt.width = timing->x_res;
1547 if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
1548 ret = omap_vout_new_crop(&vout->pix, &vout->crop, &vout->win,
1549 &vout->fbuf, &crop->c);
1552 mutex_unlock(&vout->lock);
1556 static int vidioc_queryctrl(struct file *file, void *fh,
1557 struct v4l2_queryctrl *ctrl)
1562 case V4L2_CID_ROTATE:
1563 ret = v4l2_ctrl_query_fill(ctrl, 0, 270, 90, 0);
1565 case V4L2_CID_BG_COLOR:
1566 ret = v4l2_ctrl_query_fill(ctrl, 0, 0xFFFFFF, 1, 0);
1568 case V4L2_CID_VFLIP:
1569 ret = v4l2_ctrl_query_fill(ctrl, 0, 1, 1, 0);
1572 ctrl->name[0] = '\0';
1578 static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *ctrl)
1581 struct omap_vout_device *vout = fh;
1584 case V4L2_CID_ROTATE:
1585 ctrl->value = vout->control[0].value;
1587 case V4L2_CID_BG_COLOR:
1589 struct omap_overlay_manager_info info;
1590 struct omap_overlay *ovl;
1592 ovl = vout->vid_info.overlays[0];
1593 if (!ovl->manager || !ovl->manager->get_manager_info) {
1598 ovl->manager->get_manager_info(ovl->manager, &info);
1599 ctrl->value = info.default_color;
1602 case V4L2_CID_VFLIP:
1603 ctrl->value = vout->control[2].value;
1611 static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *a)
1614 struct omap_vout_device *vout = fh;
1617 case V4L2_CID_ROTATE:
1619 int rotation = a->value;
1621 mutex_lock(&vout->lock);
1623 if (rotation && vout->pix.pixelformat == V4L2_PIX_FMT_RGB24) {
1624 mutex_unlock(&vout->lock);
1629 if (v4l2_rot_to_dss_rot(rotation, &vout->rotation,
1631 mutex_unlock(&vout->lock);
1636 vout->control[0].value = rotation;
1637 mutex_unlock(&vout->lock);
1640 case V4L2_CID_BG_COLOR:
1642 struct omap_overlay *ovl;
1643 unsigned int color = a->value;
1644 struct omap_overlay_manager_info info;
1646 ovl = vout->vid_info.overlays[0];
1648 mutex_lock(&vout->lock);
1649 if (!ovl->manager || !ovl->manager->get_manager_info) {
1650 mutex_unlock(&vout->lock);
1655 ovl->manager->get_manager_info(ovl->manager, &info);
1656 info.default_color = color;
1657 if (ovl->manager->set_manager_info(ovl->manager, &info)) {
1658 mutex_unlock(&vout->lock);
1663 vout->control[1].value = color;
1664 mutex_unlock(&vout->lock);
1667 case V4L2_CID_VFLIP:
1669 struct omap_overlay *ovl;
1670 struct omapvideo_info *ovid;
1671 unsigned int mirror = a->value;
1673 ovid = &vout->vid_info;
1674 ovl = ovid->overlays[0];
1676 mutex_lock(&vout->lock);
1678 if (mirror && vout->pix.pixelformat == V4L2_PIX_FMT_RGB24) {
1679 mutex_unlock(&vout->lock);
1683 vout->mirror = mirror;
1684 vout->control[2].value = mirror;
1685 mutex_unlock(&vout->lock);
1694 static int vidioc_reqbufs(struct file *file, void *fh,
1695 struct v4l2_requestbuffers *req)
1698 unsigned int i, num_buffers = 0;
1699 struct omap_vout_device *vout = fh;
1700 struct videobuf_queue *q = &vout->vbq;
1702 if ((req->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) || (req->count < 0))
1704 /* if memory is not mmp or userptr
1706 if ((V4L2_MEMORY_MMAP != req->memory) &&
1707 (V4L2_MEMORY_USERPTR != req->memory))
1710 mutex_lock(&vout->lock);
1711 /* Cannot be requested when streaming is on */
1712 if (vout->streaming) {
1717 /* If buffers are already allocated free them */
1718 if (q->bufs[0] && (V4L2_MEMORY_MMAP == q->bufs[0]->memory)) {
1719 if (vout->mmap_count) {
1723 num_buffers = (vout->vid == OMAP_VIDEO1) ?
1724 video1_numbuffers : video2_numbuffers;
1725 for (i = num_buffers; i < vout->buffer_allocated; i++) {
1726 omap_vout_free_buffer(vout->buf_virt_addr[i],
1728 vout->buf_virt_addr[i] = 0;
1729 vout->buf_phy_addr[i] = 0;
1731 vout->buffer_allocated = num_buffers;
1732 videobuf_mmap_free(q);
1733 } else if (q->bufs[0] && (V4L2_MEMORY_USERPTR == q->bufs[0]->memory)) {
1734 if (vout->buffer_allocated) {
1735 videobuf_mmap_free(q);
1736 for (i = 0; i < vout->buffer_allocated; i++) {
1740 vout->buffer_allocated = 0;
1744 /*store the memory type in data structure */
1745 vout->memory = req->memory;
1747 INIT_LIST_HEAD(&vout->dma_queue);
1749 /* call videobuf_reqbufs api */
1750 ret = videobuf_reqbufs(q, req);
1754 vout->buffer_allocated = req->count;
1757 mutex_unlock(&vout->lock);
1761 static int vidioc_querybuf(struct file *file, void *fh,
1762 struct v4l2_buffer *b)
1764 struct omap_vout_device *vout = fh;
1766 return videobuf_querybuf(&vout->vbq, b);
1769 static int vidioc_qbuf(struct file *file, void *fh,
1770 struct v4l2_buffer *buffer)
1772 struct omap_vout_device *vout = fh;
1773 struct videobuf_queue *q = &vout->vbq;
1775 if ((V4L2_BUF_TYPE_VIDEO_OUTPUT != buffer->type) ||
1776 (buffer->index >= vout->buffer_allocated) ||
1777 (q->bufs[buffer->index]->memory != buffer->memory)) {
1780 if (V4L2_MEMORY_USERPTR == buffer->memory) {
1781 if ((buffer->length < vout->pix.sizeimage) ||
1782 (0 == buffer->m.userptr)) {
1787 if ((rotation_enabled(vout)) &&
1788 vout->vrfb_dma_tx.req_status == DMA_CHAN_NOT_ALLOTED) {
1789 v4l2_warn(&vout->vid_dev->v4l2_dev,
1790 "DMA Channel not allocated for Rotation\n");
1794 return videobuf_qbuf(q, buffer);
1797 static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b)
1799 struct omap_vout_device *vout = fh;
1800 struct videobuf_queue *q = &vout->vbq;
1802 if (!vout->streaming)
1805 if (file->f_flags & O_NONBLOCK)
1806 /* Call videobuf_dqbuf for non blocking mode */
1807 return videobuf_dqbuf(q, (struct v4l2_buffer *)b, 1);
1809 /* Call videobuf_dqbuf for blocking mode */
1810 return videobuf_dqbuf(q, (struct v4l2_buffer *)b, 0);
1813 static int vidioc_streamon(struct file *file, void *fh, enum v4l2_buf_type i)
1816 u32 addr = 0, mask = 0;
1817 struct omap_vout_device *vout = fh;
1818 struct videobuf_queue *q = &vout->vbq;
1819 struct omapvideo_info *ovid = &vout->vid_info;
1821 mutex_lock(&vout->lock);
1823 if (vout->streaming) {
1828 ret = videobuf_streamon(q);
1832 if (list_empty(&vout->dma_queue)) {
1837 /* Get the next frame from the buffer queue */
1838 vout->next_frm = vout->cur_frm = list_entry(vout->dma_queue.next,
1839 struct videobuf_buffer, queue);
1840 /* Remove buffer from the buffer queue */
1841 list_del(&vout->cur_frm->queue);
1842 /* Mark state of the current frame to active */
1843 vout->cur_frm->state = VIDEOBUF_ACTIVE;
1844 /* Initialize field_id and started member */
1847 /* set flag here. Next QBUF will start DMA */
1848 vout->streaming = 1;
1850 vout->first_int = 1;
1852 if (omap_vout_calculate_offset(vout)) {
1856 addr = (unsigned long) vout->queued_buf_addr[vout->cur_frm->i]
1857 + vout->cropped_offset;
1859 mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
1861 omap_dispc_register_isr(omap_vout_isr, vout, mask);
1863 for (j = 0; j < ovid->num_overlays; j++) {
1864 struct omap_overlay *ovl = ovid->overlays[j];
1866 if (ovl->manager && ovl->manager->device) {
1867 struct omap_overlay_info info;
1868 ovl->get_overlay_info(ovl, &info);
1871 if (ovl->set_overlay_info(ovl, &info)) {
1878 /* First save the configuration in ovelray structure */
1879 ret = omapvid_init(vout, addr);
1881 v4l2_err(&vout->vid_dev->v4l2_dev,
1882 "failed to set overlay info\n");
1883 /* Enable the pipeline and set the Go bit */
1884 ret = omapvid_apply_changes(vout);
1886 v4l2_err(&vout->vid_dev->v4l2_dev, "failed to change mode\n");
1892 ret = videobuf_streamoff(q);
1894 mutex_unlock(&vout->lock);
1898 static int vidioc_streamoff(struct file *file, void *fh, enum v4l2_buf_type i)
1902 struct omap_vout_device *vout = fh;
1903 struct omapvideo_info *ovid = &vout->vid_info;
1905 if (!vout->streaming)
1908 vout->streaming = 0;
1909 mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
1911 omap_dispc_unregister_isr(omap_vout_isr, vout, mask);
1913 for (j = 0; j < ovid->num_overlays; j++) {
1914 struct omap_overlay *ovl = ovid->overlays[j];
1916 if (ovl->manager && ovl->manager->device) {
1917 struct omap_overlay_info info;
1919 ovl->get_overlay_info(ovl, &info);
1921 ret = ovl->set_overlay_info(ovl, &info);
1923 v4l2_err(&vout->vid_dev->v4l2_dev,
1924 "failed to update overlay info in streamoff\n");
1928 /* Turn of the pipeline */
1929 ret = omapvid_apply_changes(vout);
1931 v4l2_err(&vout->vid_dev->v4l2_dev, "failed to change mode in"
1934 INIT_LIST_HEAD(&vout->dma_queue);
1935 ret = videobuf_streamoff(&vout->vbq);
1940 static int vidioc_s_fbuf(struct file *file, void *fh,
1941 struct v4l2_framebuffer *a)
1944 struct omap_overlay *ovl;
1945 struct omapvideo_info *ovid;
1946 struct omap_vout_device *vout = fh;
1947 struct omap_overlay_manager_info info;
1948 enum omap_dss_trans_key_type key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
1950 ovid = &vout->vid_info;
1951 ovl = ovid->overlays[0];
1953 /* OMAP DSS doesn't support Source and Destination color
1955 if ((a->flags & V4L2_FBUF_FLAG_SRC_CHROMAKEY) &&
1956 (a->flags & V4L2_FBUF_FLAG_CHROMAKEY))
1958 /* OMAP DSS Doesn't support the Destination color key
1959 and alpha blending together */
1960 if ((a->flags & V4L2_FBUF_FLAG_CHROMAKEY) &&
1961 (a->flags & V4L2_FBUF_FLAG_LOCAL_ALPHA))
1964 if ((a->flags & V4L2_FBUF_FLAG_SRC_CHROMAKEY)) {
1965 vout->fbuf.flags |= V4L2_FBUF_FLAG_SRC_CHROMAKEY;
1966 key_type = OMAP_DSS_COLOR_KEY_VID_SRC;
1968 vout->fbuf.flags &= ~V4L2_FBUF_FLAG_SRC_CHROMAKEY;
1970 if ((a->flags & V4L2_FBUF_FLAG_CHROMAKEY)) {
1971 vout->fbuf.flags |= V4L2_FBUF_FLAG_CHROMAKEY;
1972 key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
1974 vout->fbuf.flags &= ~V4L2_FBUF_FLAG_CHROMAKEY;
1976 if (a->flags & (V4L2_FBUF_FLAG_CHROMAKEY |
1977 V4L2_FBUF_FLAG_SRC_CHROMAKEY))
1981 if (ovl->manager && ovl->manager->get_manager_info &&
1982 ovl->manager->set_manager_info) {
1984 ovl->manager->get_manager_info(ovl->manager, &info);
1985 info.trans_enabled = enable;
1986 info.trans_key_type = key_type;
1987 info.trans_key = vout->win.chromakey;
1989 if (ovl->manager->set_manager_info(ovl->manager, &info))
1992 if (a->flags & V4L2_FBUF_FLAG_LOCAL_ALPHA) {
1993 vout->fbuf.flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA;
1996 vout->fbuf.flags &= ~V4L2_FBUF_FLAG_LOCAL_ALPHA;
1999 if (ovl->manager && ovl->manager->get_manager_info &&
2000 ovl->manager->set_manager_info) {
2001 ovl->manager->get_manager_info(ovl->manager, &info);
2002 info.alpha_enabled = enable;
2003 if (ovl->manager->set_manager_info(ovl->manager, &info))
2010 static int vidioc_g_fbuf(struct file *file, void *fh,
2011 struct v4l2_framebuffer *a)
2013 struct omap_overlay *ovl;
2014 struct omapvideo_info *ovid;
2015 struct omap_vout_device *vout = fh;
2016 struct omap_overlay_manager_info info;
2018 ovid = &vout->vid_info;
2019 ovl = ovid->overlays[0];
2022 a->capability = V4L2_FBUF_CAP_LOCAL_ALPHA | V4L2_FBUF_CAP_CHROMAKEY
2023 | V4L2_FBUF_CAP_SRC_CHROMAKEY;
2025 if (ovl->manager && ovl->manager->get_manager_info) {
2026 ovl->manager->get_manager_info(ovl->manager, &info);
2027 if (info.trans_key_type == OMAP_DSS_COLOR_KEY_VID_SRC)
2028 a->flags |= V4L2_FBUF_FLAG_SRC_CHROMAKEY;
2029 if (info.trans_key_type == OMAP_DSS_COLOR_KEY_GFX_DST)
2030 a->flags |= V4L2_FBUF_FLAG_CHROMAKEY;
2032 if (ovl->manager && ovl->manager->get_manager_info) {
2033 ovl->manager->get_manager_info(ovl->manager, &info);
2034 if (info.alpha_enabled)
2035 a->flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA;
2041 static const struct v4l2_ioctl_ops vout_ioctl_ops = {
2042 .vidioc_querycap = vidioc_querycap,
2043 .vidioc_enum_fmt_vid_out = vidioc_enum_fmt_vid_out,
2044 .vidioc_g_fmt_vid_out = vidioc_g_fmt_vid_out,
2045 .vidioc_try_fmt_vid_out = vidioc_try_fmt_vid_out,
2046 .vidioc_s_fmt_vid_out = vidioc_s_fmt_vid_out,
2047 .vidioc_queryctrl = vidioc_queryctrl,
2048 .vidioc_g_ctrl = vidioc_g_ctrl,
2049 .vidioc_s_fbuf = vidioc_s_fbuf,
2050 .vidioc_g_fbuf = vidioc_g_fbuf,
2051 .vidioc_s_ctrl = vidioc_s_ctrl,
2052 .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
2053 .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
2054 .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
2055 .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
2056 .vidioc_cropcap = vidioc_cropcap,
2057 .vidioc_g_crop = vidioc_g_crop,
2058 .vidioc_s_crop = vidioc_s_crop,
2059 .vidioc_reqbufs = vidioc_reqbufs,
2060 .vidioc_querybuf = vidioc_querybuf,
2061 .vidioc_qbuf = vidioc_qbuf,
2062 .vidioc_dqbuf = vidioc_dqbuf,
2063 .vidioc_streamon = vidioc_streamon,
2064 .vidioc_streamoff = vidioc_streamoff,
2067 static const struct v4l2_file_operations omap_vout_fops = {
2068 .owner = THIS_MODULE,
2069 .unlocked_ioctl = video_ioctl2,
2070 .mmap = omap_vout_mmap,
2071 .open = omap_vout_open,
2072 .release = omap_vout_release,
2075 /* Init functions used during driver initialization */
2076 /* Initial setup of video_data */
2077 static int __init omap_vout_setup_video_data(struct omap_vout_device *vout)
2079 struct video_device *vfd;
2080 struct v4l2_pix_format *pix;
2081 struct v4l2_control *control;
2082 struct omap_dss_device *display =
2083 vout->vid_info.overlays[0]->manager->device;
2085 /* set the default pix */
2088 /* Set the default picture of QVGA */
2089 pix->width = QQVGA_WIDTH;
2090 pix->height = QQVGA_HEIGHT;
2092 /* Default pixel format is RGB 5-6-5 */
2093 pix->pixelformat = V4L2_PIX_FMT_RGB565;
2094 pix->field = V4L2_FIELD_ANY;
2095 pix->bytesperline = pix->width * 2;
2096 pix->sizeimage = pix->bytesperline * pix->height;
2098 pix->colorspace = V4L2_COLORSPACE_JPEG;
2100 vout->bpp = RGB565_BPP;
2101 vout->fbuf.fmt.width = display->panel.timings.x_res;
2102 vout->fbuf.fmt.height = display->panel.timings.y_res;
2104 /* Set the data structures for the overlay parameters*/
2105 vout->win.global_alpha = 255;
2106 vout->fbuf.flags = 0;
2107 vout->fbuf.capability = V4L2_FBUF_CAP_LOCAL_ALPHA |
2108 V4L2_FBUF_CAP_SRC_CHROMAKEY | V4L2_FBUF_CAP_CHROMAKEY;
2109 vout->win.chromakey = 0;
2111 omap_vout_new_format(pix, &vout->fbuf, &vout->crop, &vout->win);
2113 /*Initialize the control variables for
2114 rotation, flipping and background color. */
2115 control = vout->control;
2116 control[0].id = V4L2_CID_ROTATE;
2117 control[0].value = 0;
2120 vout->control[2].id = V4L2_CID_HFLIP;
2121 vout->control[2].value = 0;
2124 control[1].id = V4L2_CID_BG_COLOR;
2125 control[1].value = 0;
2127 /* initialize the video_device struct */
2128 vfd = vout->vfd = video_device_alloc();
2131 printk(KERN_ERR VOUT_NAME ": could not allocate"
2132 " video device struct\n");
2135 vfd->release = video_device_release;
2136 vfd->ioctl_ops = &vout_ioctl_ops;
2138 strlcpy(vfd->name, VOUT_NAME, sizeof(vfd->name));
2140 vfd->fops = &omap_vout_fops;
2141 vfd->v4l2_dev = &vout->vid_dev->v4l2_dev;
2142 mutex_init(&vout->lock);
2149 /* Setup video buffers */
2150 static int __init omap_vout_setup_video_bufs(struct platform_device *pdev,
2155 int image_width, image_height;
2156 struct video_device *vfd;
2157 struct omap_vout_device *vout;
2158 int static_vrfb_allocation = 0, vrfb_num_bufs = VRFB_NUM_BUFS;
2159 struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
2160 struct omap2video_device *vid_dev =
2161 container_of(v4l2_dev, struct omap2video_device, v4l2_dev);
2163 vout = vid_dev->vouts[vid_num];
2166 numbuffers = (vid_num == 0) ? video1_numbuffers : video2_numbuffers;
2167 vout->buffer_size = (vid_num == 0) ? video1_bufsize : video2_bufsize;
2168 dev_info(&pdev->dev, "Buffer Size = %d\n", vout->buffer_size);
2170 for (i = 0; i < numbuffers; i++) {
2171 vout->buf_virt_addr[i] =
2172 omap_vout_alloc_buffer(vout->buffer_size,
2173 (u32 *) &vout->buf_phy_addr[i]);
2174 if (!vout->buf_virt_addr[i]) {
2181 for (i = 0; i < VRFB_NUM_BUFS; i++) {
2182 if (omap_vrfb_request_ctx(&vout->vrfb_context[i])) {
2183 dev_info(&pdev->dev, ": VRFB allocation failed\n");
2184 for (j = 0; j < i; j++)
2185 omap_vrfb_release_ctx(&vout->vrfb_context[j]);
2190 vout->cropped_offset = 0;
2192 /* Calculate VRFB memory size */
2193 /* allocate for worst case size */
2194 image_width = VID_MAX_WIDTH / TILE_SIZE;
2195 if (VID_MAX_WIDTH % TILE_SIZE)
2198 image_width = image_width * TILE_SIZE;
2199 image_height = VID_MAX_HEIGHT / TILE_SIZE;
2201 if (VID_MAX_HEIGHT % TILE_SIZE)
2204 image_height = image_height * TILE_SIZE;
2205 vout->smsshado_size = PAGE_ALIGN(image_width * image_height * 2 * 2);
2208 * Request and Initialize DMA, for DMA based VRFB transfer
2210 vout->vrfb_dma_tx.dev_id = OMAP_DMA_NO_DEVICE;
2211 vout->vrfb_dma_tx.dma_ch = -1;
2212 vout->vrfb_dma_tx.req_status = DMA_CHAN_ALLOTED;
2213 ret = omap_request_dma(vout->vrfb_dma_tx.dev_id, "VRFB DMA TX",
2214 omap_vout_vrfb_dma_tx_callback,
2215 (void *) &vout->vrfb_dma_tx, &vout->vrfb_dma_tx.dma_ch);
2217 vout->vrfb_dma_tx.req_status = DMA_CHAN_NOT_ALLOTED;
2218 dev_info(&pdev->dev, ": failed to allocate DMA Channel for"
2219 " video%d\n", vfd->minor);
2221 init_waitqueue_head(&vout->vrfb_dma_tx.wait);
2223 /* Allocate VRFB buffers if selected through bootargs */
2224 static_vrfb_allocation = (vid_num == 0) ?
2225 vid1_static_vrfb_alloc : vid2_static_vrfb_alloc;
2227 /* statically allocated the VRFB buffer is done through
2228 commands line aruments */
2229 if (static_vrfb_allocation) {
2230 if (omap_vout_allocate_vrfb_buffers(vout, &vrfb_num_bufs, -1)) {
2232 goto release_vrfb_ctx;
2234 vout->vrfb_static_allocation = 1;
2239 for (j = 0; j < VRFB_NUM_BUFS; j++)
2240 omap_vrfb_release_ctx(&vout->vrfb_context[j]);
2243 for (i = 0; i < numbuffers; i++) {
2244 omap_vout_free_buffer(vout->buf_virt_addr[i],
2246 vout->buf_virt_addr[i] = 0;
2247 vout->buf_phy_addr[i] = 0;
2253 /* Create video out devices */
2254 static int __init omap_vout_create_video_devices(struct platform_device *pdev)
2257 struct omap_vout_device *vout;
2258 struct video_device *vfd = NULL;
2259 struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
2260 struct omap2video_device *vid_dev = container_of(v4l2_dev,
2261 struct omap2video_device, v4l2_dev);
2263 for (k = 0; k < pdev->num_resources; k++) {
2265 vout = kzalloc(sizeof(struct omap_vout_device), GFP_KERNEL);
2267 dev_err(&pdev->dev, ": could not allocate memory\n");
2272 vid_dev->vouts[k] = vout;
2273 vout->vid_dev = vid_dev;
2274 /* Select video2 if only 1 overlay is controlled by V4L2 */
2275 if (pdev->num_resources == 1)
2276 vout->vid_info.overlays[0] = vid_dev->overlays[k + 2];
2278 /* Else select video1 and video2 one by one. */
2279 vout->vid_info.overlays[0] = vid_dev->overlays[k + 1];
2280 vout->vid_info.num_overlays = 1;
2281 vout->vid_info.id = k + 1;
2283 /* Setup the default configuration for the video devices
2285 if (omap_vout_setup_video_data(vout) != 0) {
2290 /* Allocate default number of buffers for the video streaming
2291 * and reserve the VRFB space for rotation
2293 if (omap_vout_setup_video_bufs(pdev, k) != 0) {
2298 /* Register the Video device with V4L2
2301 if (video_register_device(vfd, VFL_TYPE_GRABBER, -1) < 0) {
2302 dev_err(&pdev->dev, ": Could not register "
2303 "Video for Linux device\n");
2308 video_set_drvdata(vfd, vout);
2310 /* Configure the overlay structure */
2311 ret = omapvid_init(vid_dev->vouts[k], 0);
2316 omap_vout_release_vrfb(vout);
2317 omap_vout_free_buffers(vout);
2319 video_device_release(vfd);
2325 dev_info(&pdev->dev, ": registered and initialized"
2326 " video device %d\n", vfd->minor);
2327 if (k == (pdev->num_resources - 1))
2333 /* Driver functions */
2334 static void omap_vout_cleanup_device(struct omap_vout_device *vout)
2336 struct video_device *vfd;
2343 if (!video_is_registered(vfd)) {
2345 * The device was never registered, so release the
2346 * video_device struct directly.
2348 video_device_release(vfd);
2351 * The unregister function will release the video_device
2352 * struct as well as unregistering it.
2354 video_unregister_device(vfd);
2358 omap_vout_release_vrfb(vout);
2359 omap_vout_free_buffers(vout);
2360 /* Free the VRFB buffer if allocated
2363 if (vout->vrfb_static_allocation)
2364 omap_vout_free_vrfb_buffers(vout);
2369 static int omap_vout_remove(struct platform_device *pdev)
2372 struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
2373 struct omap2video_device *vid_dev = container_of(v4l2_dev, struct
2374 omap2video_device, v4l2_dev);
2376 v4l2_device_unregister(v4l2_dev);
2377 for (k = 0; k < pdev->num_resources; k++)
2378 omap_vout_cleanup_device(vid_dev->vouts[k]);
2380 for (k = 0; k < vid_dev->num_displays; k++) {
2381 if (vid_dev->displays[k]->state != OMAP_DSS_DISPLAY_DISABLED)
2382 vid_dev->displays[k]->driver->disable(vid_dev->displays[k]);
2384 omap_dss_put_device(vid_dev->displays[k]);
2390 static int __init omap_vout_probe(struct platform_device *pdev)
2393 struct omap_overlay *ovl;
2394 struct omap_dss_device *dssdev = NULL;
2395 struct omap_dss_device *def_display;
2396 struct omap2video_device *vid_dev = NULL;
2398 if (pdev->num_resources == 0) {
2399 dev_err(&pdev->dev, "probed for an unknown device\n");
2403 vid_dev = kzalloc(sizeof(struct omap2video_device), GFP_KERNEL);
2404 if (vid_dev == NULL)
2407 vid_dev->num_displays = 0;
2408 for_each_dss_dev(dssdev) {
2409 omap_dss_get_device(dssdev);
2410 vid_dev->displays[vid_dev->num_displays++] = dssdev;
2413 if (vid_dev->num_displays == 0) {
2414 dev_err(&pdev->dev, "no displays\n");
2419 vid_dev->num_overlays = omap_dss_get_num_overlays();
2420 for (i = 0; i < vid_dev->num_overlays; i++)
2421 vid_dev->overlays[i] = omap_dss_get_overlay(i);
2423 vid_dev->num_managers = omap_dss_get_num_overlay_managers();
2424 for (i = 0; i < vid_dev->num_managers; i++)
2425 vid_dev->managers[i] = omap_dss_get_overlay_manager(i);
2427 /* Get the Video1 overlay and video2 overlay.
2428 * Setup the Display attached to that overlays
2430 for (i = 1; i < vid_dev->num_overlays; i++) {
2431 ovl = omap_dss_get_overlay(i);
2432 if (ovl->manager && ovl->manager->device) {
2433 def_display = ovl->manager->device;
2435 dev_warn(&pdev->dev, "cannot find display\n");
2439 struct omap_dss_driver *dssdrv = def_display->driver;
2441 ret = dssdrv->enable(def_display);
2443 /* Here we are not considering a error
2444 * as display may be enabled by frame
2447 dev_warn(&pdev->dev,
2448 "'%s' Display already enabled\n",
2451 /* set the update mode */
2452 if (def_display->caps &
2453 OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
2454 if (dssdrv->enable_te)
2455 dssdrv->enable_te(def_display, 0);
2456 if (dssdrv->set_update_mode)
2457 dssdrv->set_update_mode(def_display,
2458 OMAP_DSS_UPDATE_MANUAL);
2460 if (dssdrv->set_update_mode)
2461 dssdrv->set_update_mode(def_display,
2462 OMAP_DSS_UPDATE_AUTO);
2467 if (v4l2_device_register(&pdev->dev, &vid_dev->v4l2_dev) < 0) {
2468 dev_err(&pdev->dev, "v4l2_device_register failed\n");
2473 ret = omap_vout_create_video_devices(pdev);
2477 for (i = 0; i < vid_dev->num_displays; i++) {
2478 struct omap_dss_device *display = vid_dev->displays[i];
2480 if (display->driver->update)
2481 display->driver->update(display, 0, 0,
2482 display->panel.timings.x_res,
2483 display->panel.timings.y_res);
2488 v4l2_device_unregister(&vid_dev->v4l2_dev);
2490 for (i = 1; i < vid_dev->num_overlays; i++) {
2492 ovl = omap_dss_get_overlay(i);
2493 if (ovl->manager && ovl->manager->device)
2494 def_display = ovl->manager->device;
2496 if (def_display && def_display->driver)
2497 def_display->driver->disable(def_display);
2504 static struct platform_driver omap_vout_driver = {
2508 .probe = omap_vout_probe,
2509 .remove = omap_vout_remove,
2512 static int __init omap_vout_init(void)
2514 if (platform_driver_register(&omap_vout_driver) != 0) {
2515 printk(KERN_ERR VOUT_NAME ":Could not register Video driver\n");
2521 static void omap_vout_cleanup(void)
2523 platform_driver_unregister(&omap_vout_driver);
2526 late_initcall(omap_vout_init);
2527 module_exit(omap_vout_cleanup);