2 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
8 * This program is distributed WITHOUT ANY WARRANTY of any
9 * kind, whether express or implied; without even the implied warranty
10 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/module.h>
16 #include <linux/errno.h>
17 #include <linux/interrupt.h>
18 #include <linux/string.h>
19 #include <linux/wait.h>
20 #include <linux/time.h>
21 #include <linux/platform_device.h>
22 #include <linux/irq.h>
24 #include <linux/mutex.h>
25 #include <linux/videodev2.h>
26 #include <linux/slab.h>
28 #include <asm/pgtable.h>
29 #include <mach/cputype.h>
31 #include <media/v4l2-dev.h>
32 #include <media/v4l2-common.h>
33 #include <media/v4l2-ioctl.h>
34 #include <media/v4l2-device.h>
35 #include <media/davinci/vpbe_display.h>
36 #include <media/davinci/vpbe_types.h>
37 #include <media/davinci/vpbe.h>
38 #include <media/davinci/vpbe_venc.h>
39 #include <media/davinci/vpbe_osd.h>
40 #include "vpbe_venc_regs.h"
42 #define VPBE_DISPLAY_DRIVER "vpbe-v4l2"
46 #define VPBE_DEFAULT_NUM_BUFS 3
48 module_param(debug, int, 0644);
50 static int vpbe_set_osd_display_params(struct vpbe_display *disp_dev,
51 struct vpbe_layer *layer);
53 static int venc_is_second_field(struct vpbe_display *disp_dev)
55 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
59 ret = v4l2_subdev_call(vpbe_dev->venc,
65 v4l2_err(&vpbe_dev->v4l2_dev,
66 "Error in getting Field ID 0\n");
71 static void vpbe_isr_even_field(struct vpbe_display *disp_obj,
72 struct vpbe_layer *layer)
74 struct timespec timevalue;
76 if (layer->cur_frm == layer->next_frm)
78 ktime_get_ts(&timevalue);
79 layer->cur_frm->vb.v4l2_buf.timestamp.tv_sec =
81 layer->cur_frm->vb.v4l2_buf.timestamp.tv_usec =
82 timevalue.tv_nsec / NSEC_PER_USEC;
83 vb2_buffer_done(&layer->cur_frm->vb, VB2_BUF_STATE_DONE);
84 /* Make cur_frm pointing to next_frm */
85 layer->cur_frm = layer->next_frm;
88 static void vpbe_isr_odd_field(struct vpbe_display *disp_obj,
89 struct vpbe_layer *layer)
91 struct osd_state *osd_device = disp_obj->osd_device;
94 spin_lock(&disp_obj->dma_queue_lock);
95 if (list_empty(&layer->dma_queue) ||
96 (layer->cur_frm != layer->next_frm)) {
97 spin_unlock(&disp_obj->dma_queue_lock);
101 * one field is displayed configure
102 * the next frame if it is available
103 * otherwise hold on current frame
104 * Get next from the buffer queue
106 layer->next_frm = list_entry(layer->dma_queue.next,
107 struct vpbe_disp_buffer, list);
108 /* Remove that from the buffer queue */
109 list_del(&layer->next_frm->list);
110 spin_unlock(&disp_obj->dma_queue_lock);
111 /* Mark state of the frame to active */
112 layer->next_frm->vb.state = VB2_BUF_STATE_ACTIVE;
113 addr = vb2_dma_contig_plane_dma_addr(&layer->next_frm->vb, 0);
114 osd_device->ops.start_layer(osd_device,
115 layer->layer_info.id,
117 disp_obj->cbcr_ofst);
120 /* interrupt service routine */
121 static irqreturn_t venc_isr(int irq, void *arg)
123 struct vpbe_display *disp_dev = (struct vpbe_display *)arg;
124 struct vpbe_layer *layer;
125 static unsigned last_event;
130 if ((NULL == arg) || (NULL == disp_dev->dev[0]))
133 if (venc_is_second_field(disp_dev))
134 event |= VENC_SECOND_FIELD;
136 event |= VENC_FIRST_FIELD;
138 if (event == (last_event & ~VENC_END_OF_FRAME)) {
140 * If the display is non-interlaced, then we need to flag the
141 * end-of-frame event at every interrupt regardless of the
142 * value of the FIDST bit. We can conclude that the display is
143 * non-interlaced if the value of the FIDST bit is unchanged
144 * from the previous interrupt.
146 event |= VENC_END_OF_FRAME;
147 } else if (event == VENC_SECOND_FIELD) {
148 /* end-of-frame for interlaced display */
149 event |= VENC_END_OF_FRAME;
153 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
154 layer = disp_dev->dev[i];
155 /* If streaming is started in this layer */
159 if (layer->layer_first_int) {
160 layer->layer_first_int = 0;
163 /* Check the field format */
164 if ((V4L2_FIELD_NONE == layer->pix_fmt.field) &&
165 (event & VENC_END_OF_FRAME)) {
166 /* Progressive mode */
168 vpbe_isr_even_field(disp_dev, layer);
169 vpbe_isr_odd_field(disp_dev, layer);
171 /* Interlaced mode */
173 layer->field_id ^= 1;
174 if (event & VENC_FIRST_FIELD)
180 * If field id does not match with store
183 if (fid != layer->field_id) {
184 /* Make them in sync */
185 layer->field_id = fid;
189 * device field id and local field id are
190 * in sync. If this is even field
193 vpbe_isr_even_field(disp_dev, layer);
195 vpbe_isr_odd_field(disp_dev, layer);
203 * vpbe_buffer_prepare()
204 * This is the callback function called from vb2_qbuf() function
205 * the buffer is prepared and user space virtual address is converted into
208 static int vpbe_buffer_prepare(struct vb2_buffer *vb)
210 struct vb2_queue *q = vb->vb2_queue;
211 struct vpbe_layer *layer = vb2_get_drv_priv(q);
212 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
215 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
216 "vpbe_buffer_prepare\n");
218 vb2_set_plane_payload(vb, 0, layer->pix_fmt.sizeimage);
219 if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
222 addr = vb2_dma_contig_plane_dma_addr(vb, 0);
223 if (!IS_ALIGNED(addr, 8)) {
224 v4l2_err(&vpbe_dev->v4l2_dev,
225 "buffer_prepare:offset is not aligned to 32 bytes\n");
232 * vpbe_buffer_setup()
233 * This function allocates memory for the buffers
236 vpbe_buffer_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
237 unsigned int *nbuffers, unsigned int *nplanes,
238 unsigned int sizes[], void *alloc_ctxs[])
241 /* Get the file handle object and layer object */
242 struct vpbe_layer *layer = vb2_get_drv_priv(vq);
243 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
245 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_buffer_setup\n");
247 /* Store number of buffers allocated in numbuffer member */
248 if (*nbuffers < VPBE_DEFAULT_NUM_BUFS)
249 *nbuffers = layer->numbuffers = VPBE_DEFAULT_NUM_BUFS;
252 sizes[0] = layer->pix_fmt.sizeimage;
253 alloc_ctxs[0] = layer->alloc_ctx;
259 * vpbe_buffer_queue()
260 * This function adds the buffer to DMA queue
262 static void vpbe_buffer_queue(struct vb2_buffer *vb)
264 /* Get the file handle object and layer object */
265 struct vpbe_disp_buffer *buf = container_of(vb,
266 struct vpbe_disp_buffer, vb);
267 struct vpbe_layer *layer = vb2_get_drv_priv(vb->vb2_queue);
268 struct vpbe_display *disp = layer->disp_dev;
269 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
272 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
273 "vpbe_buffer_queue\n");
275 /* add the buffer to the DMA queue */
276 spin_lock_irqsave(&disp->dma_queue_lock, flags);
277 list_add_tail(&buf->list, &layer->dma_queue);
278 spin_unlock_irqrestore(&disp->dma_queue_lock, flags);
281 static int vpbe_start_streaming(struct vb2_queue *vq, unsigned int count)
283 struct vpbe_layer *layer = vb2_get_drv_priv(vq);
284 struct osd_state *osd_device = layer->disp_dev->osd_device;
287 osd_device->ops.disable_layer(osd_device, layer->layer_info.id);
289 /* Get the next frame from the buffer queue */
290 layer->next_frm = layer->cur_frm = list_entry(layer->dma_queue.next,
291 struct vpbe_disp_buffer, list);
292 /* Remove buffer from the buffer queue */
293 list_del(&layer->cur_frm->list);
294 /* Mark state of the current frame to active */
295 layer->cur_frm->vb.state = VB2_BUF_STATE_ACTIVE;
296 /* Initialize field_id and started member */
299 /* Set parameters in OSD and VENC */
300 ret = vpbe_set_osd_display_params(layer->disp_dev, layer);
302 struct vpbe_disp_buffer *buf, *tmp;
304 vb2_buffer_done(&layer->cur_frm->vb, VB2_BUF_STATE_QUEUED);
305 list_for_each_entry_safe(buf, tmp, &layer->dma_queue, list) {
306 list_del(&buf->list);
307 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
314 * if request format is yuv420 semiplanar, need to
315 * enable both video windows
318 layer->layer_first_int = 1;
323 static void vpbe_stop_streaming(struct vb2_queue *vq)
325 struct vpbe_layer *layer = vb2_get_drv_priv(vq);
326 struct osd_state *osd_device = layer->disp_dev->osd_device;
327 struct vpbe_display *disp = layer->disp_dev;
330 if (!vb2_is_streaming(vq))
333 osd_device->ops.disable_layer(osd_device, layer->layer_info.id);
335 /* release all active buffers */
336 spin_lock_irqsave(&disp->dma_queue_lock, flags);
337 if (layer->cur_frm == layer->next_frm) {
338 vb2_buffer_done(&layer->cur_frm->vb, VB2_BUF_STATE_ERROR);
340 if (layer->cur_frm != NULL)
341 vb2_buffer_done(&layer->cur_frm->vb,
342 VB2_BUF_STATE_ERROR);
343 if (layer->next_frm != NULL)
344 vb2_buffer_done(&layer->next_frm->vb,
345 VB2_BUF_STATE_ERROR);
348 while (!list_empty(&layer->dma_queue)) {
349 layer->next_frm = list_entry(layer->dma_queue.next,
350 struct vpbe_disp_buffer, list);
351 list_del(&layer->next_frm->list);
352 vb2_buffer_done(&layer->next_frm->vb, VB2_BUF_STATE_ERROR);
354 spin_unlock_irqrestore(&disp->dma_queue_lock, flags);
357 static struct vb2_ops video_qops = {
358 .queue_setup = vpbe_buffer_queue_setup,
359 .wait_prepare = vb2_ops_wait_prepare,
360 .wait_finish = vb2_ops_wait_finish,
361 .buf_prepare = vpbe_buffer_prepare,
362 .start_streaming = vpbe_start_streaming,
363 .stop_streaming = vpbe_stop_streaming,
364 .buf_queue = vpbe_buffer_queue,
369 _vpbe_display_get_other_win_layer(struct vpbe_display *disp_dev,
370 struct vpbe_layer *layer)
372 enum vpbe_display_device_id thiswin, otherwin;
373 thiswin = layer->device_id;
375 otherwin = (thiswin == VPBE_DISPLAY_DEVICE_0) ?
376 VPBE_DISPLAY_DEVICE_1 : VPBE_DISPLAY_DEVICE_0;
377 return disp_dev->dev[otherwin];
380 static int vpbe_set_osd_display_params(struct vpbe_display *disp_dev,
381 struct vpbe_layer *layer)
383 struct osd_layer_config *cfg = &layer->layer_info.config;
384 struct osd_state *osd_device = disp_dev->osd_device;
385 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
389 addr = vb2_dma_contig_plane_dma_addr(&layer->cur_frm->vb, 0);
390 /* Set address in the display registers */
391 osd_device->ops.start_layer(osd_device,
392 layer->layer_info.id,
394 disp_dev->cbcr_ofst);
396 ret = osd_device->ops.enable_layer(osd_device,
397 layer->layer_info.id, 0);
399 v4l2_err(&vpbe_dev->v4l2_dev,
400 "Error in enabling osd window layer 0\n");
404 /* Enable the window */
405 layer->layer_info.enable = 1;
406 if (cfg->pixfmt == PIXFMT_NV12) {
407 struct vpbe_layer *otherlayer =
408 _vpbe_display_get_other_win_layer(disp_dev, layer);
410 ret = osd_device->ops.enable_layer(osd_device,
411 otherlayer->layer_info.id, 1);
413 v4l2_err(&vpbe_dev->v4l2_dev,
414 "Error in enabling osd window layer 1\n");
417 otherlayer->layer_info.enable = 1;
423 vpbe_disp_calculate_scale_factor(struct vpbe_display *disp_dev,
424 struct vpbe_layer *layer,
425 int expected_xsize, int expected_ysize)
427 struct display_layer_info *layer_info = &layer->layer_info;
428 struct v4l2_pix_format *pixfmt = &layer->pix_fmt;
429 struct osd_layer_config *cfg = &layer->layer_info.config;
430 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
431 int calculated_xsize;
437 v4l2_std_id standard_id = vpbe_dev->current_timings.std_id;
440 * Application initially set the image format. Current display
441 * size is obtained from the vpbe display controller. expected_xsize
442 * and expected_ysize are set through S_CROP ioctl. Based on this,
443 * driver will calculate the scale factors for vertical and
444 * horizontal direction so that the image is displayed scaled
445 * and expanded. Application uses expansion to display the image
446 * in a square pixel. Otherwise it is displayed using displays
447 * pixel aspect ratio.It is expected that application chooses
448 * the crop coordinates for cropped or scaled display. if crop
449 * size is less than the image size, it is displayed cropped or
450 * it is displayed scaled and/or expanded.
452 * to begin with, set the crop window same as expected. Later we
453 * will override with scaled window size
456 cfg->xsize = pixfmt->width;
457 cfg->ysize = pixfmt->height;
458 layer_info->h_zoom = ZOOM_X1; /* no horizontal zoom */
459 layer_info->v_zoom = ZOOM_X1; /* no horizontal zoom */
460 layer_info->h_exp = H_EXP_OFF; /* no horizontal zoom */
461 layer_info->v_exp = V_EXP_OFF; /* no horizontal zoom */
463 if (pixfmt->width < expected_xsize) {
464 h_scale = vpbe_dev->current_timings.xres / pixfmt->width;
467 else if (h_scale >= 4)
471 cfg->xsize *= h_scale;
472 if (cfg->xsize < expected_xsize) {
473 if ((standard_id & V4L2_STD_525_60) ||
474 (standard_id & V4L2_STD_625_50)) {
475 calculated_xsize = (cfg->xsize *
476 VPBE_DISPLAY_H_EXP_RATIO_N) /
477 VPBE_DISPLAY_H_EXP_RATIO_D;
478 if (calculated_xsize <= expected_xsize) {
480 cfg->xsize = calculated_xsize;
485 layer_info->h_zoom = ZOOM_X2;
486 else if (h_scale == 4)
487 layer_info->h_zoom = ZOOM_X4;
489 layer_info->h_exp = H_EXP_9_OVER_8;
491 /* no scaling, only cropping. Set display area to crop area */
492 cfg->xsize = expected_xsize;
495 if (pixfmt->height < expected_ysize) {
496 v_scale = expected_ysize / pixfmt->height;
499 else if (v_scale >= 4)
503 cfg->ysize *= v_scale;
504 if (cfg->ysize < expected_ysize) {
505 if ((standard_id & V4L2_STD_625_50)) {
506 calculated_xsize = (cfg->ysize *
507 VPBE_DISPLAY_V_EXP_RATIO_N) /
508 VPBE_DISPLAY_V_EXP_RATIO_D;
509 if (calculated_xsize <= expected_ysize) {
511 cfg->ysize = calculated_xsize;
516 layer_info->v_zoom = ZOOM_X2;
517 else if (v_scale == 4)
518 layer_info->v_zoom = ZOOM_X4;
520 layer_info->h_exp = V_EXP_6_OVER_5;
522 /* no scaling, only cropping. Set display area to crop area */
523 cfg->ysize = expected_ysize;
525 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
526 "crop display xsize = %d, ysize = %d\n",
527 cfg->xsize, cfg->ysize);
530 static void vpbe_disp_adj_position(struct vpbe_display *disp_dev,
531 struct vpbe_layer *layer,
534 struct osd_layer_config *cfg = &layer->layer_info.config;
535 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
537 cfg->xpos = min((unsigned int)left,
538 vpbe_dev->current_timings.xres - cfg->xsize);
539 cfg->ypos = min((unsigned int)top,
540 vpbe_dev->current_timings.yres - cfg->ysize);
542 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
543 "new xpos = %d, ypos = %d\n",
544 cfg->xpos, cfg->ypos);
547 static void vpbe_disp_check_window_params(struct vpbe_display *disp_dev,
550 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
552 if ((c->width == 0) ||
553 ((c->width + c->left) > vpbe_dev->current_timings.xres))
554 c->width = vpbe_dev->current_timings.xres - c->left;
556 if ((c->height == 0) || ((c->height + c->top) >
557 vpbe_dev->current_timings.yres))
558 c->height = vpbe_dev->current_timings.yres - c->top;
560 /* window height must be even for interlaced display */
561 if (vpbe_dev->current_timings.interlaced)
562 c->height &= (~0x01);
568 * If user application provides width and height, and have bytesperline set
569 * to zero, driver calculates bytesperline and sizeimage based on hardware
572 static int vpbe_try_format(struct vpbe_display *disp_dev,
573 struct v4l2_pix_format *pixfmt, int check)
575 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
582 if ((pixfmt->pixelformat != V4L2_PIX_FMT_UYVY) &&
583 (pixfmt->pixelformat != V4L2_PIX_FMT_NV12))
584 /* choose default as V4L2_PIX_FMT_UYVY */
585 pixfmt->pixelformat = V4L2_PIX_FMT_UYVY;
587 /* Check the field format */
588 if ((pixfmt->field != V4L2_FIELD_INTERLACED) &&
589 (pixfmt->field != V4L2_FIELD_NONE)) {
590 if (vpbe_dev->current_timings.interlaced)
591 pixfmt->field = V4L2_FIELD_INTERLACED;
593 pixfmt->field = V4L2_FIELD_NONE;
596 if (pixfmt->field == V4L2_FIELD_INTERLACED)
599 if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12)
604 max_width = vpbe_dev->current_timings.xres;
605 max_height = vpbe_dev->current_timings.yres;
609 if (!pixfmt->width || (pixfmt->width < min_width) ||
610 (pixfmt->width > max_width)) {
611 pixfmt->width = vpbe_dev->current_timings.xres;
614 if (!pixfmt->height || (pixfmt->height < min_height) ||
615 (pixfmt->height > max_height)) {
616 pixfmt->height = vpbe_dev->current_timings.yres;
619 if (pixfmt->bytesperline < (pixfmt->width * bpp))
620 pixfmt->bytesperline = pixfmt->width * bpp;
622 /* Make the bytesperline 32 byte aligned */
623 pixfmt->bytesperline = ((pixfmt->width * bpp + 31) & ~31);
625 if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12)
626 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height +
627 (pixfmt->bytesperline * pixfmt->height >> 1);
629 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
634 static int vpbe_display_querycap(struct file *file, void *priv,
635 struct v4l2_capability *cap)
637 struct vpbe_layer *layer = video_drvdata(file);
638 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
640 cap->version = VPBE_DISPLAY_VERSION_CODE;
641 cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
642 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
643 snprintf(cap->driver, sizeof(cap->driver), "%s",
644 dev_name(vpbe_dev->pdev));
645 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
646 dev_name(vpbe_dev->pdev));
647 strlcpy(cap->card, vpbe_dev->cfg->module_name, sizeof(cap->card));
652 static int vpbe_display_s_crop(struct file *file, void *priv,
653 const struct v4l2_crop *crop)
655 struct vpbe_layer *layer = video_drvdata(file);
656 struct vpbe_display *disp_dev = layer->disp_dev;
657 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
658 struct osd_layer_config *cfg = &layer->layer_info.config;
659 struct osd_state *osd_device = disp_dev->osd_device;
660 struct v4l2_rect rect = crop->c;
663 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
664 "VIDIOC_S_CROP, layer id = %d\n", layer->device_id);
666 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
667 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buf type\n");
676 vpbe_disp_check_window_params(disp_dev, &rect);
678 osd_device->ops.get_layer_config(osd_device,
679 layer->layer_info.id, cfg);
681 vpbe_disp_calculate_scale_factor(disp_dev, layer,
684 vpbe_disp_adj_position(disp_dev, layer, rect.top,
686 ret = osd_device->ops.set_layer_config(osd_device,
687 layer->layer_info.id, cfg);
689 v4l2_err(&vpbe_dev->v4l2_dev,
690 "Error in set layer config:\n");
694 /* apply zooming and h or v expansion */
695 osd_device->ops.set_zoom(osd_device,
696 layer->layer_info.id,
697 layer->layer_info.h_zoom,
698 layer->layer_info.v_zoom);
699 ret = osd_device->ops.set_vid_expansion(osd_device,
700 layer->layer_info.h_exp,
701 layer->layer_info.v_exp);
703 v4l2_err(&vpbe_dev->v4l2_dev,
704 "Error in set vid expansion:\n");
708 if ((layer->layer_info.h_zoom != ZOOM_X1) ||
709 (layer->layer_info.v_zoom != ZOOM_X1) ||
710 (layer->layer_info.h_exp != H_EXP_OFF) ||
711 (layer->layer_info.v_exp != V_EXP_OFF))
712 /* Enable expansion filter */
713 osd_device->ops.set_interpolation_filter(osd_device, 1);
715 osd_device->ops.set_interpolation_filter(osd_device, 0);
720 static int vpbe_display_g_crop(struct file *file, void *priv,
721 struct v4l2_crop *crop)
723 struct vpbe_layer *layer = video_drvdata(file);
724 struct osd_layer_config *cfg = &layer->layer_info.config;
725 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
726 struct osd_state *osd_device = layer->disp_dev->osd_device;
727 struct v4l2_rect *rect = &crop->c;
729 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
730 "VIDIOC_G_CROP, layer id = %d\n",
733 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
734 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buf type\n");
737 osd_device->ops.get_layer_config(osd_device,
738 layer->layer_info.id, cfg);
739 rect->top = cfg->ypos;
740 rect->left = cfg->xpos;
741 rect->width = cfg->xsize;
742 rect->height = cfg->ysize;
747 static int vpbe_display_cropcap(struct file *file, void *priv,
748 struct v4l2_cropcap *cropcap)
750 struct vpbe_layer *layer = video_drvdata(file);
751 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
753 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_CROPCAP ioctl\n");
755 cropcap->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
756 cropcap->bounds.left = 0;
757 cropcap->bounds.top = 0;
758 cropcap->bounds.width = vpbe_dev->current_timings.xres;
759 cropcap->bounds.height = vpbe_dev->current_timings.yres;
760 cropcap->pixelaspect = vpbe_dev->current_timings.aspect;
761 cropcap->defrect = cropcap->bounds;
765 static int vpbe_display_g_fmt(struct file *file, void *priv,
766 struct v4l2_format *fmt)
768 struct vpbe_layer *layer = video_drvdata(file);
769 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
771 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
772 "VIDIOC_G_FMT, layer id = %d\n",
775 /* If buffer type is video output */
776 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != fmt->type) {
777 v4l2_err(&vpbe_dev->v4l2_dev, "invalid type\n");
780 /* Fill in the information about format */
781 fmt->fmt.pix = layer->pix_fmt;
786 static int vpbe_display_enum_fmt(struct file *file, void *priv,
787 struct v4l2_fmtdesc *fmt)
789 struct vpbe_layer *layer = video_drvdata(file);
790 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
791 unsigned int index = 0;
793 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
794 "VIDIOC_ENUM_FMT, layer id = %d\n",
796 if (fmt->index > 1) {
797 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid format index\n");
801 /* Fill in the information about format */
803 memset(fmt, 0, sizeof(*fmt));
805 fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
807 strcpy(fmt->description, "YUV 4:2:2 - UYVY");
808 fmt->pixelformat = V4L2_PIX_FMT_UYVY;
810 strcpy(fmt->description, "Y/CbCr 4:2:0");
811 fmt->pixelformat = V4L2_PIX_FMT_NV12;
817 static int vpbe_display_s_fmt(struct file *file, void *priv,
818 struct v4l2_format *fmt)
820 struct vpbe_layer *layer = video_drvdata(file);
821 struct vpbe_display *disp_dev = layer->disp_dev;
822 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
823 struct osd_layer_config *cfg = &layer->layer_info.config;
824 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
825 struct osd_state *osd_device = disp_dev->osd_device;
828 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
829 "VIDIOC_S_FMT, layer id = %d\n",
832 /* If streaming is started, return error */
833 if (layer->started) {
834 v4l2_err(&vpbe_dev->v4l2_dev, "Streaming is started\n");
837 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != fmt->type) {
838 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "invalid type\n");
841 /* Check for valid pixel format */
842 ret = vpbe_try_format(disp_dev, pixfmt, 1);
846 /* YUV420 is requested, check availability of the
847 other video window */
849 layer->pix_fmt = *pixfmt;
850 if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12) {
851 struct vpbe_layer *otherlayer;
853 otherlayer = _vpbe_display_get_other_win_layer(disp_dev, layer);
854 /* if other layer is available, only
855 * claim it, do not configure it
857 ret = osd_device->ops.request_layer(osd_device,
858 otherlayer->layer_info.id);
860 v4l2_err(&vpbe_dev->v4l2_dev,
861 "Display Manager failed to allocate layer\n");
866 /* Get osd layer config */
867 osd_device->ops.get_layer_config(osd_device,
868 layer->layer_info.id, cfg);
869 /* Store the pixel format in the layer object */
870 cfg->xsize = pixfmt->width;
871 cfg->ysize = pixfmt->height;
872 cfg->line_length = pixfmt->bytesperline;
875 cfg->interlaced = vpbe_dev->current_timings.interlaced;
877 if (V4L2_PIX_FMT_UYVY == pixfmt->pixelformat)
878 cfg->pixfmt = PIXFMT_YCBCRI;
880 /* Change of the default pixel format for both video windows */
881 if (V4L2_PIX_FMT_NV12 == pixfmt->pixelformat) {
882 struct vpbe_layer *otherlayer;
883 cfg->pixfmt = PIXFMT_NV12;
884 otherlayer = _vpbe_display_get_other_win_layer(disp_dev,
886 otherlayer->layer_info.config.pixfmt = PIXFMT_NV12;
889 /* Set the layer config in the osd window */
890 ret = osd_device->ops.set_layer_config(osd_device,
891 layer->layer_info.id, cfg);
893 v4l2_err(&vpbe_dev->v4l2_dev,
894 "Error in S_FMT params:\n");
898 /* Readback and fill the local copy of current pix format */
899 osd_device->ops.get_layer_config(osd_device,
900 layer->layer_info.id, cfg);
905 static int vpbe_display_try_fmt(struct file *file, void *priv,
906 struct v4l2_format *fmt)
908 struct vpbe_layer *layer = video_drvdata(file);
909 struct vpbe_display *disp_dev = layer->disp_dev;
910 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
911 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
913 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_TRY_FMT\n");
915 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != fmt->type) {
916 v4l2_err(&vpbe_dev->v4l2_dev, "invalid type\n");
920 /* Check for valid field format */
921 return vpbe_try_format(disp_dev, pixfmt, 0);
926 * vpbe_display_s_std - Set the given standard in the encoder
928 * Sets the standard if supported by the current encoder. Return the status.
929 * 0 - success & -EINVAL on error
931 static int vpbe_display_s_std(struct file *file, void *priv,
934 struct vpbe_layer *layer = video_drvdata(file);
935 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
938 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_STD\n");
940 /* If streaming is started, return error */
941 if (layer->started) {
942 v4l2_err(&vpbe_dev->v4l2_dev, "Streaming is started\n");
945 if (NULL != vpbe_dev->ops.s_std) {
946 ret = vpbe_dev->ops.s_std(vpbe_dev, std_id);
948 v4l2_err(&vpbe_dev->v4l2_dev,
949 "Failed to set standard for sub devices\n");
960 * vpbe_display_g_std - Get the standard in the current encoder
962 * Get the standard in the current encoder. Return the status. 0 - success
965 static int vpbe_display_g_std(struct file *file, void *priv,
968 struct vpbe_layer *layer = video_drvdata(file);
969 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
971 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_STD\n");
973 /* Get the standard from the current encoder */
974 if (vpbe_dev->current_timings.timings_type & VPBE_ENC_STD) {
975 *std_id = vpbe_dev->current_timings.std_id;
983 * vpbe_display_enum_output - enumerate outputs
985 * Enumerates the outputs available at the vpbe display
986 * returns the status, -EINVAL if end of output list
988 static int vpbe_display_enum_output(struct file *file, void *priv,
989 struct v4l2_output *output)
991 struct vpbe_layer *layer = video_drvdata(file);
992 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
995 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_OUTPUT\n");
997 /* Enumerate outputs */
999 if (NULL == vpbe_dev->ops.enum_outputs)
1002 ret = vpbe_dev->ops.enum_outputs(vpbe_dev, output);
1004 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
1005 "Failed to enumerate outputs\n");
1013 * vpbe_display_s_output - Set output to
1014 * the output specified by the index
1016 static int vpbe_display_s_output(struct file *file, void *priv,
1019 struct vpbe_layer *layer = video_drvdata(file);
1020 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1023 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_OUTPUT\n");
1024 /* If streaming is started, return error */
1025 if (layer->started) {
1026 v4l2_err(&vpbe_dev->v4l2_dev, "Streaming is started\n");
1029 if (NULL == vpbe_dev->ops.set_output)
1032 ret = vpbe_dev->ops.set_output(vpbe_dev, i);
1034 v4l2_err(&vpbe_dev->v4l2_dev,
1035 "Failed to set output for sub devices\n");
1043 * vpbe_display_g_output - Get output from subdevice
1044 * for a given by the index
1046 static int vpbe_display_g_output(struct file *file, void *priv,
1049 struct vpbe_layer *layer = video_drvdata(file);
1050 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1052 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_OUTPUT\n");
1053 /* Get the standard from the current encoder */
1054 *i = vpbe_dev->current_out_index;
1060 * vpbe_display_enum_dv_timings - Enumerate the dv timings
1062 * enum the timings in the current encoder. Return the status. 0 - success
1066 vpbe_display_enum_dv_timings(struct file *file, void *priv,
1067 struct v4l2_enum_dv_timings *timings)
1069 struct vpbe_layer *layer = video_drvdata(file);
1070 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1073 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_DV_TIMINGS\n");
1075 /* Enumerate outputs */
1076 if (NULL == vpbe_dev->ops.enum_dv_timings)
1079 ret = vpbe_dev->ops.enum_dv_timings(vpbe_dev, timings);
1081 v4l2_err(&vpbe_dev->v4l2_dev,
1082 "Failed to enumerate dv timings info\n");
1090 * vpbe_display_s_dv_timings - Set the dv timings
1092 * Set the timings in the current encoder. Return the status. 0 - success
1096 vpbe_display_s_dv_timings(struct file *file, void *priv,
1097 struct v4l2_dv_timings *timings)
1099 struct vpbe_layer *layer = video_drvdata(file);
1100 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1103 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_DV_TIMINGS\n");
1106 /* If streaming is started, return error */
1107 if (layer->started) {
1108 v4l2_err(&vpbe_dev->v4l2_dev, "Streaming is started\n");
1112 /* Set the given standard in the encoder */
1113 if (!vpbe_dev->ops.s_dv_timings)
1116 ret = vpbe_dev->ops.s_dv_timings(vpbe_dev, timings);
1118 v4l2_err(&vpbe_dev->v4l2_dev,
1119 "Failed to set the dv timings info\n");
1127 * vpbe_display_g_dv_timings - Set the dv timings
1129 * Get the timings in the current encoder. Return the status. 0 - success
1133 vpbe_display_g_dv_timings(struct file *file, void *priv,
1134 struct v4l2_dv_timings *dv_timings)
1136 struct vpbe_layer *layer = video_drvdata(file);
1137 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1139 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_DV_TIMINGS\n");
1141 /* Get the given standard in the encoder */
1143 if (vpbe_dev->current_timings.timings_type &
1144 VPBE_ENC_DV_TIMINGS) {
1145 *dv_timings = vpbe_dev->current_timings.dv_timings;
1154 * vpbe_display_open()
1155 * It creates object of file handle structure and stores it in private_data
1156 * member of filepointer
1158 static int vpbe_display_open(struct file *file)
1160 struct vpbe_layer *layer = video_drvdata(file);
1161 struct vpbe_display *disp_dev = layer->disp_dev;
1162 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
1163 struct osd_state *osd_device = disp_dev->osd_device;
1166 /* creating context for file descriptor */
1167 err = v4l2_fh_open(file);
1169 v4l2_err(&vpbe_dev->v4l2_dev, "v4l2_fh_open failed\n");
1173 /* leaving if layer is already initialized */
1174 if (!v4l2_fh_is_singular_file(file))
1178 if (mutex_lock_interruptible(&layer->opslock))
1179 return -ERESTARTSYS;
1180 /* First claim the layer for this device */
1181 err = osd_device->ops.request_layer(osd_device,
1182 layer->layer_info.id);
1183 mutex_unlock(&layer->opslock);
1185 /* Couldn't get layer */
1186 v4l2_err(&vpbe_dev->v4l2_dev,
1187 "Display Manager failed to allocate layer\n");
1188 v4l2_fh_release(file);
1192 /* Increment layer usrs counter */
1194 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
1195 "vpbe display device opened successfully\n");
1200 * vpbe_display_release()
1201 * This function deletes buffer queue, frees the buffers and the davinci
1202 * display file * handle
1204 static int vpbe_display_release(struct file *file)
1206 struct vpbe_layer *layer = video_drvdata(file);
1207 struct osd_layer_config *cfg = &layer->layer_info.config;
1208 struct vpbe_display *disp_dev = layer->disp_dev;
1209 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
1210 struct osd_state *osd_device = disp_dev->osd_device;
1212 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_release\n");
1214 mutex_lock(&layer->opslock);
1215 /* Reset io_usrs member of layer object */
1218 osd_device->ops.disable_layer(osd_device,
1219 layer->layer_info.id);
1222 /* Decrement layer usrs counter */
1224 /* If this file handle has initialize encoder device, reset it */
1226 if (cfg->pixfmt == PIXFMT_NV12) {
1227 struct vpbe_layer *otherlayer;
1229 _vpbe_display_get_other_win_layer(disp_dev, layer);
1230 osd_device->ops.disable_layer(osd_device,
1231 otherlayer->layer_info.id);
1232 osd_device->ops.release_layer(osd_device,
1233 otherlayer->layer_info.id);
1235 osd_device->ops.disable_layer(osd_device,
1236 layer->layer_info.id);
1237 osd_device->ops.release_layer(osd_device,
1238 layer->layer_info.id);
1241 _vb2_fop_release(file, NULL);
1242 mutex_unlock(&layer->opslock);
1244 disp_dev->cbcr_ofst = 0;
1249 /* vpbe capture ioctl operations */
1250 static const struct v4l2_ioctl_ops vpbe_ioctl_ops = {
1251 .vidioc_querycap = vpbe_display_querycap,
1252 .vidioc_g_fmt_vid_out = vpbe_display_g_fmt,
1253 .vidioc_enum_fmt_vid_out = vpbe_display_enum_fmt,
1254 .vidioc_s_fmt_vid_out = vpbe_display_s_fmt,
1255 .vidioc_try_fmt_vid_out = vpbe_display_try_fmt,
1257 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1258 .vidioc_querybuf = vb2_ioctl_querybuf,
1259 .vidioc_qbuf = vb2_ioctl_qbuf,
1260 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1261 .vidioc_streamon = vb2_ioctl_streamon,
1262 .vidioc_streamoff = vb2_ioctl_streamoff,
1264 .vidioc_cropcap = vpbe_display_cropcap,
1265 .vidioc_g_crop = vpbe_display_g_crop,
1266 .vidioc_s_crop = vpbe_display_s_crop,
1267 .vidioc_s_std = vpbe_display_s_std,
1268 .vidioc_g_std = vpbe_display_g_std,
1269 .vidioc_enum_output = vpbe_display_enum_output,
1270 .vidioc_s_output = vpbe_display_s_output,
1271 .vidioc_g_output = vpbe_display_g_output,
1272 .vidioc_s_dv_timings = vpbe_display_s_dv_timings,
1273 .vidioc_g_dv_timings = vpbe_display_g_dv_timings,
1274 .vidioc_enum_dv_timings = vpbe_display_enum_dv_timings,
1277 static struct v4l2_file_operations vpbe_fops = {
1278 .owner = THIS_MODULE,
1279 .open = vpbe_display_open,
1280 .release = vpbe_display_release,
1281 .unlocked_ioctl = video_ioctl2,
1282 .mmap = vb2_fop_mmap,
1283 .poll = vb2_fop_poll,
1286 static int vpbe_device_get(struct device *dev, void *data)
1288 struct platform_device *pdev = to_platform_device(dev);
1289 struct vpbe_display *vpbe_disp = data;
1291 if (strcmp("vpbe_controller", pdev->name) == 0)
1292 vpbe_disp->vpbe_dev = platform_get_drvdata(pdev);
1294 if (strstr(pdev->name, "vpbe-osd") != NULL)
1295 vpbe_disp->osd_device = platform_get_drvdata(pdev);
1300 static int init_vpbe_layer(int i, struct vpbe_display *disp_dev,
1301 struct platform_device *pdev)
1303 struct vpbe_layer *vpbe_display_layer = NULL;
1304 struct video_device *vbd = NULL;
1306 /* Allocate memory for four plane display objects */
1309 kzalloc(sizeof(struct vpbe_layer), GFP_KERNEL);
1311 /* If memory allocation fails, return error */
1312 if (!disp_dev->dev[i]) {
1313 printk(KERN_ERR "ran out of memory\n");
1316 spin_lock_init(&disp_dev->dev[i]->irqlock);
1317 mutex_init(&disp_dev->dev[i]->opslock);
1319 /* Get the pointer to the layer object */
1320 vpbe_display_layer = disp_dev->dev[i];
1321 vbd = &vpbe_display_layer->video_dev;
1322 /* Initialize field of video device */
1323 vbd->release = video_device_release_empty;
1324 vbd->fops = &vpbe_fops;
1325 vbd->ioctl_ops = &vpbe_ioctl_ops;
1327 vbd->v4l2_dev = &disp_dev->vpbe_dev->v4l2_dev;
1328 vbd->lock = &vpbe_display_layer->opslock;
1329 vbd->vfl_dir = VFL_DIR_TX;
1331 if (disp_dev->vpbe_dev->current_timings.timings_type &
1333 vbd->tvnorms = (V4L2_STD_525_60 | V4L2_STD_625_50);
1335 snprintf(vbd->name, sizeof(vbd->name),
1336 "DaVinci_VPBE Display_DRIVER_V%d.%d.%d",
1337 (VPBE_DISPLAY_VERSION_CODE >> 16) & 0xff,
1338 (VPBE_DISPLAY_VERSION_CODE >> 8) & 0xff,
1339 (VPBE_DISPLAY_VERSION_CODE) & 0xff);
1341 vpbe_display_layer->device_id = i;
1343 vpbe_display_layer->layer_info.id =
1344 ((i == VPBE_DISPLAY_DEVICE_0) ? WIN_VID0 : WIN_VID1);
1350 static int register_device(struct vpbe_layer *vpbe_display_layer,
1351 struct vpbe_display *disp_dev,
1352 struct platform_device *pdev)
1356 v4l2_info(&disp_dev->vpbe_dev->v4l2_dev,
1357 "Trying to register VPBE display device.\n");
1358 v4l2_info(&disp_dev->vpbe_dev->v4l2_dev,
1359 "layer=%x,layer->video_dev=%x\n",
1360 (int)vpbe_display_layer,
1361 (int)&vpbe_display_layer->video_dev);
1363 vpbe_display_layer->video_dev.queue = &vpbe_display_layer->buffer_queue;
1364 err = video_register_device(&vpbe_display_layer->video_dev,
1370 vpbe_display_layer->disp_dev = disp_dev;
1371 /* set the driver data in platform device */
1372 platform_set_drvdata(pdev, disp_dev);
1373 video_set_drvdata(&vpbe_display_layer->video_dev,
1374 vpbe_display_layer);
1382 * vpbe_display_probe()
1383 * This function creates device entries by register itself to the V4L2 driver
1384 * and initializes fields of each layer objects
1386 static int vpbe_display_probe(struct platform_device *pdev)
1388 struct vpbe_display *disp_dev;
1389 struct v4l2_device *v4l2_dev;
1390 struct resource *res = NULL;
1391 struct vb2_queue *q;
1397 printk(KERN_DEBUG "vpbe_display_probe\n");
1398 /* Allocate memory for vpbe_display */
1399 disp_dev = devm_kzalloc(&pdev->dev, sizeof(struct vpbe_display),
1404 spin_lock_init(&disp_dev->dma_queue_lock);
1406 * Scan all the platform devices to find the vpbe
1407 * controller device and get the vpbe_dev object
1409 err = bus_for_each_dev(&platform_bus_type, NULL, disp_dev,
1414 v4l2_dev = &disp_dev->vpbe_dev->v4l2_dev;
1415 /* Initialize the vpbe display controller */
1416 if (NULL != disp_dev->vpbe_dev->ops.initialize) {
1417 err = disp_dev->vpbe_dev->ops.initialize(&pdev->dev,
1418 disp_dev->vpbe_dev);
1420 v4l2_err(v4l2_dev, "Error initing vpbe\n");
1426 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
1427 if (init_vpbe_layer(i, disp_dev, pdev)) {
1433 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1435 v4l2_err(v4l2_dev, "Unable to get VENC interrupt resource\n");
1441 err = devm_request_irq(&pdev->dev, irq, venc_isr, 0,
1442 VPBE_DISPLAY_DRIVER, disp_dev);
1444 v4l2_err(v4l2_dev, "VPBE IRQ request failed\n");
1448 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
1449 /* initialize vb2 queue */
1450 q = &disp_dev->dev[i]->buffer_queue;
1451 memset(q, 0, sizeof(*q));
1452 q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
1453 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
1454 q->drv_priv = disp_dev->dev[i];
1455 q->ops = &video_qops;
1456 q->mem_ops = &vb2_dma_contig_memops;
1457 q->buf_struct_size = sizeof(struct vpbe_disp_buffer);
1458 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1459 q->min_buffers_needed = 1;
1460 q->lock = &disp_dev->dev[i]->opslock;
1461 err = vb2_queue_init(q);
1463 v4l2_err(v4l2_dev, "vb2_queue_init() failed\n");
1467 disp_dev->dev[i]->alloc_ctx =
1468 vb2_dma_contig_init_ctx(disp_dev->vpbe_dev->pdev);
1469 if (IS_ERR(disp_dev->dev[i]->alloc_ctx)) {
1470 v4l2_err(v4l2_dev, "Failed to get the context\n");
1471 err = PTR_ERR(disp_dev->dev[i]->alloc_ctx);
1475 INIT_LIST_HEAD(&disp_dev->dev[i]->dma_queue);
1477 if (register_device(disp_dev->dev[i], disp_dev, pdev)) {
1483 v4l2_dbg(1, debug, v4l2_dev,
1484 "Successfully completed the probing of vpbe v4l2 device\n");
1489 for (k = 0; k < VPBE_DISPLAY_MAX_DEVICES; k++) {
1490 /* Unregister video device */
1491 if (disp_dev->dev[k] != NULL) {
1492 vb2_dma_contig_cleanup_ctx(disp_dev->dev[k]->alloc_ctx);
1493 video_unregister_device(&disp_dev->dev[k]->video_dev);
1494 kfree(disp_dev->dev[k]);
1501 * vpbe_display_remove()
1502 * It un-register hardware layer from V4L2 driver
1504 static int vpbe_display_remove(struct platform_device *pdev)
1506 struct vpbe_layer *vpbe_display_layer;
1507 struct vpbe_display *disp_dev = platform_get_drvdata(pdev);
1508 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
1511 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_remove\n");
1513 /* deinitialize the vpbe display controller */
1514 if (NULL != vpbe_dev->ops.deinitialize)
1515 vpbe_dev->ops.deinitialize(&pdev->dev, vpbe_dev);
1516 /* un-register device */
1517 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
1518 /* Get the pointer to the layer object */
1519 vpbe_display_layer = disp_dev->dev[i];
1520 vb2_dma_contig_cleanup_ctx(vpbe_display_layer->alloc_ctx);
1521 /* Unregister video device */
1522 video_unregister_device(&vpbe_display_layer->video_dev);
1525 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
1526 kfree(disp_dev->dev[i]);
1527 disp_dev->dev[i] = NULL;
1533 static struct platform_driver vpbe_display_driver = {
1535 .name = VPBE_DISPLAY_DRIVER,
1536 .owner = THIS_MODULE,
1537 .bus = &platform_bus_type,
1539 .probe = vpbe_display_probe,
1540 .remove = vpbe_display_remove,
1543 module_platform_driver(vpbe_display_driver);
1545 MODULE_DESCRIPTION("TI DM644x/DM355/DM365 VPBE Display controller");
1546 MODULE_LICENSE("GPL");
1547 MODULE_AUTHOR("Texas Instruments");