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 if (layer->cur_frm == layer->next_frm)
77 v4l2_get_timestamp(&layer->cur_frm->vb.v4l2_buf.timestamp);
78 vb2_buffer_done(&layer->cur_frm->vb, VB2_BUF_STATE_DONE);
79 /* Make cur_frm pointing to next_frm */
80 layer->cur_frm = layer->next_frm;
83 static void vpbe_isr_odd_field(struct vpbe_display *disp_obj,
84 struct vpbe_layer *layer)
86 struct osd_state *osd_device = disp_obj->osd_device;
89 spin_lock(&disp_obj->dma_queue_lock);
90 if (list_empty(&layer->dma_queue) ||
91 (layer->cur_frm != layer->next_frm)) {
92 spin_unlock(&disp_obj->dma_queue_lock);
96 * one field is displayed configure
97 * the next frame if it is available
98 * otherwise hold on current frame
99 * Get next from the buffer queue
101 layer->next_frm = list_entry(layer->dma_queue.next,
102 struct vpbe_disp_buffer, list);
103 /* Remove that from the buffer queue */
104 list_del(&layer->next_frm->list);
105 spin_unlock(&disp_obj->dma_queue_lock);
106 /* Mark state of the frame to active */
107 layer->next_frm->vb.state = VB2_BUF_STATE_ACTIVE;
108 addr = vb2_dma_contig_plane_dma_addr(&layer->next_frm->vb, 0);
109 osd_device->ops.start_layer(osd_device,
110 layer->layer_info.id,
112 disp_obj->cbcr_ofst);
115 /* interrupt service routine */
116 static irqreturn_t venc_isr(int irq, void *arg)
118 struct vpbe_display *disp_dev = (struct vpbe_display *)arg;
119 struct vpbe_layer *layer;
120 static unsigned last_event;
125 if ((NULL == arg) || (NULL == disp_dev->dev[0]))
128 if (venc_is_second_field(disp_dev))
129 event |= VENC_SECOND_FIELD;
131 event |= VENC_FIRST_FIELD;
133 if (event == (last_event & ~VENC_END_OF_FRAME)) {
135 * If the display is non-interlaced, then we need to flag the
136 * end-of-frame event at every interrupt regardless of the
137 * value of the FIDST bit. We can conclude that the display is
138 * non-interlaced if the value of the FIDST bit is unchanged
139 * from the previous interrupt.
141 event |= VENC_END_OF_FRAME;
142 } else if (event == VENC_SECOND_FIELD) {
143 /* end-of-frame for interlaced display */
144 event |= VENC_END_OF_FRAME;
148 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
149 layer = disp_dev->dev[i];
151 if (!vb2_start_streaming_called(&layer->buffer_queue))
154 if (layer->layer_first_int) {
155 layer->layer_first_int = 0;
158 /* Check the field format */
159 if ((V4L2_FIELD_NONE == layer->pix_fmt.field) &&
160 (event & VENC_END_OF_FRAME)) {
161 /* Progressive mode */
163 vpbe_isr_even_field(disp_dev, layer);
164 vpbe_isr_odd_field(disp_dev, layer);
166 /* Interlaced mode */
168 layer->field_id ^= 1;
169 if (event & VENC_FIRST_FIELD)
175 * If field id does not match with store
178 if (fid != layer->field_id) {
179 /* Make them in sync */
180 layer->field_id = fid;
184 * device field id and local field id are
185 * in sync. If this is even field
188 vpbe_isr_even_field(disp_dev, layer);
190 vpbe_isr_odd_field(disp_dev, layer);
198 * vpbe_buffer_prepare()
199 * This is the callback function called from vb2_qbuf() function
200 * the buffer is prepared and user space virtual address is converted into
203 static int vpbe_buffer_prepare(struct vb2_buffer *vb)
205 struct vb2_queue *q = vb->vb2_queue;
206 struct vpbe_layer *layer = vb2_get_drv_priv(q);
207 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
210 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
211 "vpbe_buffer_prepare\n");
213 vb2_set_plane_payload(vb, 0, layer->pix_fmt.sizeimage);
214 if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
217 addr = vb2_dma_contig_plane_dma_addr(vb, 0);
218 if (!IS_ALIGNED(addr, 8)) {
219 v4l2_err(&vpbe_dev->v4l2_dev,
220 "buffer_prepare:offset is not aligned to 32 bytes\n");
227 * vpbe_buffer_setup()
228 * This function allocates memory for the buffers
231 vpbe_buffer_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
232 unsigned int *nbuffers, unsigned int *nplanes,
233 unsigned int sizes[], void *alloc_ctxs[])
236 /* Get the file handle object and layer object */
237 struct vpbe_layer *layer = vb2_get_drv_priv(vq);
238 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
240 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_buffer_setup\n");
242 if (fmt && fmt->fmt.pix.sizeimage < layer->pix_fmt.sizeimage)
245 /* Store number of buffers allocated in numbuffer member */
246 if (vq->num_buffers + *nbuffers < VPBE_DEFAULT_NUM_BUFS)
247 *nbuffers = VPBE_DEFAULT_NUM_BUFS - vq->num_buffers;
250 sizes[0] = fmt ? fmt->fmt.pix.sizeimage : layer->pix_fmt.sizeimage;
251 alloc_ctxs[0] = layer->alloc_ctx;
257 * vpbe_buffer_queue()
258 * This function adds the buffer to DMA queue
260 static void vpbe_buffer_queue(struct vb2_buffer *vb)
262 /* Get the file handle object and layer object */
263 struct vpbe_disp_buffer *buf = container_of(vb,
264 struct vpbe_disp_buffer, vb);
265 struct vpbe_layer *layer = vb2_get_drv_priv(vb->vb2_queue);
266 struct vpbe_display *disp = layer->disp_dev;
267 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
270 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
271 "vpbe_buffer_queue\n");
273 /* add the buffer to the DMA queue */
274 spin_lock_irqsave(&disp->dma_queue_lock, flags);
275 list_add_tail(&buf->list, &layer->dma_queue);
276 spin_unlock_irqrestore(&disp->dma_queue_lock, flags);
279 static int vpbe_start_streaming(struct vb2_queue *vq, unsigned int count)
281 struct vpbe_layer *layer = vb2_get_drv_priv(vq);
282 struct osd_state *osd_device = layer->disp_dev->osd_device;
285 osd_device->ops.disable_layer(osd_device, layer->layer_info.id);
287 /* Get the next frame from the buffer queue */
288 layer->next_frm = layer->cur_frm = list_entry(layer->dma_queue.next,
289 struct vpbe_disp_buffer, list);
290 /* Remove buffer from the buffer queue */
291 list_del(&layer->cur_frm->list);
292 /* Mark state of the current frame to active */
293 layer->cur_frm->vb.state = VB2_BUF_STATE_ACTIVE;
294 /* Initialize field_id and started member */
297 /* Set parameters in OSD and VENC */
298 ret = vpbe_set_osd_display_params(layer->disp_dev, layer);
300 struct vpbe_disp_buffer *buf, *tmp;
302 vb2_buffer_done(&layer->cur_frm->vb, VB2_BUF_STATE_QUEUED);
303 list_for_each_entry_safe(buf, tmp, &layer->dma_queue, list) {
304 list_del(&buf->list);
305 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
312 * if request format is yuv420 semiplanar, need to
313 * enable both video windows
315 layer->layer_first_int = 1;
320 static void vpbe_stop_streaming(struct vb2_queue *vq)
322 struct vpbe_layer *layer = vb2_get_drv_priv(vq);
323 struct osd_state *osd_device = layer->disp_dev->osd_device;
324 struct vpbe_display *disp = layer->disp_dev;
327 if (!vb2_is_streaming(vq))
330 osd_device->ops.disable_layer(osd_device, layer->layer_info.id);
332 /* release all active buffers */
333 spin_lock_irqsave(&disp->dma_queue_lock, flags);
334 if (layer->cur_frm == layer->next_frm) {
335 vb2_buffer_done(&layer->cur_frm->vb, VB2_BUF_STATE_ERROR);
337 if (layer->cur_frm != NULL)
338 vb2_buffer_done(&layer->cur_frm->vb,
339 VB2_BUF_STATE_ERROR);
340 if (layer->next_frm != NULL)
341 vb2_buffer_done(&layer->next_frm->vb,
342 VB2_BUF_STATE_ERROR);
345 while (!list_empty(&layer->dma_queue)) {
346 layer->next_frm = list_entry(layer->dma_queue.next,
347 struct vpbe_disp_buffer, list);
348 list_del(&layer->next_frm->list);
349 vb2_buffer_done(&layer->next_frm->vb, VB2_BUF_STATE_ERROR);
351 spin_unlock_irqrestore(&disp->dma_queue_lock, flags);
354 static struct vb2_ops video_qops = {
355 .queue_setup = vpbe_buffer_queue_setup,
356 .wait_prepare = vb2_ops_wait_prepare,
357 .wait_finish = vb2_ops_wait_finish,
358 .buf_prepare = vpbe_buffer_prepare,
359 .start_streaming = vpbe_start_streaming,
360 .stop_streaming = vpbe_stop_streaming,
361 .buf_queue = vpbe_buffer_queue,
366 _vpbe_display_get_other_win_layer(struct vpbe_display *disp_dev,
367 struct vpbe_layer *layer)
369 enum vpbe_display_device_id thiswin, otherwin;
370 thiswin = layer->device_id;
372 otherwin = (thiswin == VPBE_DISPLAY_DEVICE_0) ?
373 VPBE_DISPLAY_DEVICE_1 : VPBE_DISPLAY_DEVICE_0;
374 return disp_dev->dev[otherwin];
377 static int vpbe_set_osd_display_params(struct vpbe_display *disp_dev,
378 struct vpbe_layer *layer)
380 struct osd_layer_config *cfg = &layer->layer_info.config;
381 struct osd_state *osd_device = disp_dev->osd_device;
382 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
386 addr = vb2_dma_contig_plane_dma_addr(&layer->cur_frm->vb, 0);
387 /* Set address in the display registers */
388 osd_device->ops.start_layer(osd_device,
389 layer->layer_info.id,
391 disp_dev->cbcr_ofst);
393 ret = osd_device->ops.enable_layer(osd_device,
394 layer->layer_info.id, 0);
396 v4l2_err(&vpbe_dev->v4l2_dev,
397 "Error in enabling osd window layer 0\n");
401 /* Enable the window */
402 layer->layer_info.enable = 1;
403 if (cfg->pixfmt == PIXFMT_NV12) {
404 struct vpbe_layer *otherlayer =
405 _vpbe_display_get_other_win_layer(disp_dev, layer);
407 ret = osd_device->ops.enable_layer(osd_device,
408 otherlayer->layer_info.id, 1);
410 v4l2_err(&vpbe_dev->v4l2_dev,
411 "Error in enabling osd window layer 1\n");
414 otherlayer->layer_info.enable = 1;
420 vpbe_disp_calculate_scale_factor(struct vpbe_display *disp_dev,
421 struct vpbe_layer *layer,
422 int expected_xsize, int expected_ysize)
424 struct display_layer_info *layer_info = &layer->layer_info;
425 struct v4l2_pix_format *pixfmt = &layer->pix_fmt;
426 struct osd_layer_config *cfg = &layer->layer_info.config;
427 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
428 int calculated_xsize;
434 v4l2_std_id standard_id = vpbe_dev->current_timings.std_id;
437 * Application initially set the image format. Current display
438 * size is obtained from the vpbe display controller. expected_xsize
439 * and expected_ysize are set through S_CROP ioctl. Based on this,
440 * driver will calculate the scale factors for vertical and
441 * horizontal direction so that the image is displayed scaled
442 * and expanded. Application uses expansion to display the image
443 * in a square pixel. Otherwise it is displayed using displays
444 * pixel aspect ratio.It is expected that application chooses
445 * the crop coordinates for cropped or scaled display. if crop
446 * size is less than the image size, it is displayed cropped or
447 * it is displayed scaled and/or expanded.
449 * to begin with, set the crop window same as expected. Later we
450 * will override with scaled window size
453 cfg->xsize = pixfmt->width;
454 cfg->ysize = pixfmt->height;
455 layer_info->h_zoom = ZOOM_X1; /* no horizontal zoom */
456 layer_info->v_zoom = ZOOM_X1; /* no horizontal zoom */
457 layer_info->h_exp = H_EXP_OFF; /* no horizontal zoom */
458 layer_info->v_exp = V_EXP_OFF; /* no horizontal zoom */
460 if (pixfmt->width < expected_xsize) {
461 h_scale = vpbe_dev->current_timings.xres / pixfmt->width;
464 else if (h_scale >= 4)
468 cfg->xsize *= h_scale;
469 if (cfg->xsize < expected_xsize) {
470 if ((standard_id & V4L2_STD_525_60) ||
471 (standard_id & V4L2_STD_625_50)) {
472 calculated_xsize = (cfg->xsize *
473 VPBE_DISPLAY_H_EXP_RATIO_N) /
474 VPBE_DISPLAY_H_EXP_RATIO_D;
475 if (calculated_xsize <= expected_xsize) {
477 cfg->xsize = calculated_xsize;
482 layer_info->h_zoom = ZOOM_X2;
483 else if (h_scale == 4)
484 layer_info->h_zoom = ZOOM_X4;
486 layer_info->h_exp = H_EXP_9_OVER_8;
488 /* no scaling, only cropping. Set display area to crop area */
489 cfg->xsize = expected_xsize;
492 if (pixfmt->height < expected_ysize) {
493 v_scale = expected_ysize / pixfmt->height;
496 else if (v_scale >= 4)
500 cfg->ysize *= v_scale;
501 if (cfg->ysize < expected_ysize) {
502 if ((standard_id & V4L2_STD_625_50)) {
503 calculated_xsize = (cfg->ysize *
504 VPBE_DISPLAY_V_EXP_RATIO_N) /
505 VPBE_DISPLAY_V_EXP_RATIO_D;
506 if (calculated_xsize <= expected_ysize) {
508 cfg->ysize = calculated_xsize;
513 layer_info->v_zoom = ZOOM_X2;
514 else if (v_scale == 4)
515 layer_info->v_zoom = ZOOM_X4;
517 layer_info->h_exp = V_EXP_6_OVER_5;
519 /* no scaling, only cropping. Set display area to crop area */
520 cfg->ysize = expected_ysize;
522 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
523 "crop display xsize = %d, ysize = %d\n",
524 cfg->xsize, cfg->ysize);
527 static void vpbe_disp_adj_position(struct vpbe_display *disp_dev,
528 struct vpbe_layer *layer,
531 struct osd_layer_config *cfg = &layer->layer_info.config;
532 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
534 cfg->xpos = min((unsigned int)left,
535 vpbe_dev->current_timings.xres - cfg->xsize);
536 cfg->ypos = min((unsigned int)top,
537 vpbe_dev->current_timings.yres - cfg->ysize);
539 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
540 "new xpos = %d, ypos = %d\n",
541 cfg->xpos, cfg->ypos);
544 static void vpbe_disp_check_window_params(struct vpbe_display *disp_dev,
547 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
549 if ((c->width == 0) ||
550 ((c->width + c->left) > vpbe_dev->current_timings.xres))
551 c->width = vpbe_dev->current_timings.xres - c->left;
553 if ((c->height == 0) || ((c->height + c->top) >
554 vpbe_dev->current_timings.yres))
555 c->height = vpbe_dev->current_timings.yres - c->top;
557 /* window height must be even for interlaced display */
558 if (vpbe_dev->current_timings.interlaced)
559 c->height &= (~0x01);
565 * If user application provides width and height, and have bytesperline set
566 * to zero, driver calculates bytesperline and sizeimage based on hardware
569 static int vpbe_try_format(struct vpbe_display *disp_dev,
570 struct v4l2_pix_format *pixfmt, int check)
572 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
579 if ((pixfmt->pixelformat != V4L2_PIX_FMT_UYVY) &&
580 (pixfmt->pixelformat != V4L2_PIX_FMT_NV12))
581 /* choose default as V4L2_PIX_FMT_UYVY */
582 pixfmt->pixelformat = V4L2_PIX_FMT_UYVY;
584 /* Check the field format */
585 if ((pixfmt->field != V4L2_FIELD_INTERLACED) &&
586 (pixfmt->field != V4L2_FIELD_NONE)) {
587 if (vpbe_dev->current_timings.interlaced)
588 pixfmt->field = V4L2_FIELD_INTERLACED;
590 pixfmt->field = V4L2_FIELD_NONE;
593 if (pixfmt->field == V4L2_FIELD_INTERLACED)
596 if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12)
601 max_width = vpbe_dev->current_timings.xres;
602 max_height = vpbe_dev->current_timings.yres;
606 if (!pixfmt->width || (pixfmt->width < min_width) ||
607 (pixfmt->width > max_width)) {
608 pixfmt->width = vpbe_dev->current_timings.xres;
611 if (!pixfmt->height || (pixfmt->height < min_height) ||
612 (pixfmt->height > max_height)) {
613 pixfmt->height = vpbe_dev->current_timings.yres;
616 if (pixfmt->bytesperline < (pixfmt->width * bpp))
617 pixfmt->bytesperline = pixfmt->width * bpp;
619 /* Make the bytesperline 32 byte aligned */
620 pixfmt->bytesperline = ((pixfmt->width * bpp + 31) & ~31);
622 if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12)
623 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height +
624 (pixfmt->bytesperline * pixfmt->height >> 1);
626 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
631 static int vpbe_display_querycap(struct file *file, void *priv,
632 struct v4l2_capability *cap)
634 struct vpbe_layer *layer = video_drvdata(file);
635 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
637 cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
638 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
639 snprintf(cap->driver, sizeof(cap->driver), "%s",
640 dev_name(vpbe_dev->pdev));
641 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
642 dev_name(vpbe_dev->pdev));
643 strlcpy(cap->card, vpbe_dev->cfg->module_name, sizeof(cap->card));
648 static int vpbe_display_s_crop(struct file *file, void *priv,
649 const struct v4l2_crop *crop)
651 struct vpbe_layer *layer = video_drvdata(file);
652 struct vpbe_display *disp_dev = layer->disp_dev;
653 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
654 struct osd_layer_config *cfg = &layer->layer_info.config;
655 struct osd_state *osd_device = disp_dev->osd_device;
656 struct v4l2_rect rect = crop->c;
659 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
660 "VIDIOC_S_CROP, layer id = %d\n", layer->device_id);
662 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
663 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buf type\n");
672 vpbe_disp_check_window_params(disp_dev, &rect);
674 osd_device->ops.get_layer_config(osd_device,
675 layer->layer_info.id, cfg);
677 vpbe_disp_calculate_scale_factor(disp_dev, layer,
680 vpbe_disp_adj_position(disp_dev, layer, rect.top,
682 ret = osd_device->ops.set_layer_config(osd_device,
683 layer->layer_info.id, cfg);
685 v4l2_err(&vpbe_dev->v4l2_dev,
686 "Error in set layer config:\n");
690 /* apply zooming and h or v expansion */
691 osd_device->ops.set_zoom(osd_device,
692 layer->layer_info.id,
693 layer->layer_info.h_zoom,
694 layer->layer_info.v_zoom);
695 ret = osd_device->ops.set_vid_expansion(osd_device,
696 layer->layer_info.h_exp,
697 layer->layer_info.v_exp);
699 v4l2_err(&vpbe_dev->v4l2_dev,
700 "Error in set vid expansion:\n");
704 if ((layer->layer_info.h_zoom != ZOOM_X1) ||
705 (layer->layer_info.v_zoom != ZOOM_X1) ||
706 (layer->layer_info.h_exp != H_EXP_OFF) ||
707 (layer->layer_info.v_exp != V_EXP_OFF))
708 /* Enable expansion filter */
709 osd_device->ops.set_interpolation_filter(osd_device, 1);
711 osd_device->ops.set_interpolation_filter(osd_device, 0);
716 static int vpbe_display_g_crop(struct file *file, void *priv,
717 struct v4l2_crop *crop)
719 struct vpbe_layer *layer = video_drvdata(file);
720 struct osd_layer_config *cfg = &layer->layer_info.config;
721 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
722 struct osd_state *osd_device = layer->disp_dev->osd_device;
723 struct v4l2_rect *rect = &crop->c;
725 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
726 "VIDIOC_G_CROP, layer id = %d\n",
729 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
730 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buf type\n");
733 osd_device->ops.get_layer_config(osd_device,
734 layer->layer_info.id, cfg);
735 rect->top = cfg->ypos;
736 rect->left = cfg->xpos;
737 rect->width = cfg->xsize;
738 rect->height = cfg->ysize;
743 static int vpbe_display_cropcap(struct file *file, void *priv,
744 struct v4l2_cropcap *cropcap)
746 struct vpbe_layer *layer = video_drvdata(file);
747 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
749 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_CROPCAP ioctl\n");
751 cropcap->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
752 cropcap->bounds.left = 0;
753 cropcap->bounds.top = 0;
754 cropcap->bounds.width = vpbe_dev->current_timings.xres;
755 cropcap->bounds.height = vpbe_dev->current_timings.yres;
756 cropcap->pixelaspect = vpbe_dev->current_timings.aspect;
757 cropcap->defrect = cropcap->bounds;
761 static int vpbe_display_g_fmt(struct file *file, void *priv,
762 struct v4l2_format *fmt)
764 struct vpbe_layer *layer = video_drvdata(file);
765 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
767 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
768 "VIDIOC_G_FMT, layer id = %d\n",
771 /* If buffer type is video output */
772 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != fmt->type) {
773 v4l2_err(&vpbe_dev->v4l2_dev, "invalid type\n");
776 /* Fill in the information about format */
777 fmt->fmt.pix = layer->pix_fmt;
782 static int vpbe_display_enum_fmt(struct file *file, void *priv,
783 struct v4l2_fmtdesc *fmt)
785 struct vpbe_layer *layer = video_drvdata(file);
786 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
787 unsigned int index = 0;
789 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
790 "VIDIOC_ENUM_FMT, layer id = %d\n",
792 if (fmt->index > 1) {
793 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid format index\n");
797 /* Fill in the information about format */
799 memset(fmt, 0, sizeof(*fmt));
801 fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
803 strcpy(fmt->description, "YUV 4:2:2 - UYVY");
804 fmt->pixelformat = V4L2_PIX_FMT_UYVY;
806 strcpy(fmt->description, "Y/CbCr 4:2:0");
807 fmt->pixelformat = V4L2_PIX_FMT_NV12;
813 static int vpbe_display_s_fmt(struct file *file, void *priv,
814 struct v4l2_format *fmt)
816 struct vpbe_layer *layer = video_drvdata(file);
817 struct vpbe_display *disp_dev = layer->disp_dev;
818 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
819 struct osd_layer_config *cfg = &layer->layer_info.config;
820 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
821 struct osd_state *osd_device = disp_dev->osd_device;
824 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
825 "VIDIOC_S_FMT, layer id = %d\n",
828 if (vb2_is_busy(&layer->buffer_queue))
831 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != fmt->type) {
832 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "invalid type\n");
835 /* Check for valid pixel format */
836 ret = vpbe_try_format(disp_dev, pixfmt, 1);
840 /* YUV420 is requested, check availability of the
841 other video window */
843 layer->pix_fmt = *pixfmt;
844 if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12) {
845 struct vpbe_layer *otherlayer;
847 otherlayer = _vpbe_display_get_other_win_layer(disp_dev, layer);
848 /* if other layer is available, only
849 * claim it, do not configure it
851 ret = osd_device->ops.request_layer(osd_device,
852 otherlayer->layer_info.id);
854 v4l2_err(&vpbe_dev->v4l2_dev,
855 "Display Manager failed to allocate layer\n");
860 /* Get osd layer config */
861 osd_device->ops.get_layer_config(osd_device,
862 layer->layer_info.id, cfg);
863 /* Store the pixel format in the layer object */
864 cfg->xsize = pixfmt->width;
865 cfg->ysize = pixfmt->height;
866 cfg->line_length = pixfmt->bytesperline;
869 cfg->interlaced = vpbe_dev->current_timings.interlaced;
871 if (V4L2_PIX_FMT_UYVY == pixfmt->pixelformat)
872 cfg->pixfmt = PIXFMT_YCBCRI;
874 /* Change of the default pixel format for both video windows */
875 if (V4L2_PIX_FMT_NV12 == pixfmt->pixelformat) {
876 struct vpbe_layer *otherlayer;
877 cfg->pixfmt = PIXFMT_NV12;
878 otherlayer = _vpbe_display_get_other_win_layer(disp_dev,
880 otherlayer->layer_info.config.pixfmt = PIXFMT_NV12;
883 /* Set the layer config in the osd window */
884 ret = osd_device->ops.set_layer_config(osd_device,
885 layer->layer_info.id, cfg);
887 v4l2_err(&vpbe_dev->v4l2_dev,
888 "Error in S_FMT params:\n");
892 /* Readback and fill the local copy of current pix format */
893 osd_device->ops.get_layer_config(osd_device,
894 layer->layer_info.id, cfg);
899 static int vpbe_display_try_fmt(struct file *file, void *priv,
900 struct v4l2_format *fmt)
902 struct vpbe_layer *layer = video_drvdata(file);
903 struct vpbe_display *disp_dev = layer->disp_dev;
904 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
905 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
907 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_TRY_FMT\n");
909 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != fmt->type) {
910 v4l2_err(&vpbe_dev->v4l2_dev, "invalid type\n");
914 /* Check for valid field format */
915 return vpbe_try_format(disp_dev, pixfmt, 0);
920 * vpbe_display_s_std - Set the given standard in the encoder
922 * Sets the standard if supported by the current encoder. Return the status.
923 * 0 - success & -EINVAL on error
925 static int vpbe_display_s_std(struct file *file, void *priv,
928 struct vpbe_layer *layer = video_drvdata(file);
929 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
932 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_STD\n");
934 if (vb2_is_busy(&layer->buffer_queue))
937 if (NULL != vpbe_dev->ops.s_std) {
938 ret = vpbe_dev->ops.s_std(vpbe_dev, std_id);
940 v4l2_err(&vpbe_dev->v4l2_dev,
941 "Failed to set standard for sub devices\n");
952 * vpbe_display_g_std - Get the standard in the current encoder
954 * Get the standard in the current encoder. Return the status. 0 - success
957 static int vpbe_display_g_std(struct file *file, void *priv,
960 struct vpbe_layer *layer = video_drvdata(file);
961 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
963 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_STD\n");
965 /* Get the standard from the current encoder */
966 if (vpbe_dev->current_timings.timings_type & VPBE_ENC_STD) {
967 *std_id = vpbe_dev->current_timings.std_id;
975 * vpbe_display_enum_output - enumerate outputs
977 * Enumerates the outputs available at the vpbe display
978 * returns the status, -EINVAL if end of output list
980 static int vpbe_display_enum_output(struct file *file, void *priv,
981 struct v4l2_output *output)
983 struct vpbe_layer *layer = video_drvdata(file);
984 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
987 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_OUTPUT\n");
989 /* Enumerate outputs */
991 if (NULL == vpbe_dev->ops.enum_outputs)
994 ret = vpbe_dev->ops.enum_outputs(vpbe_dev, output);
996 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
997 "Failed to enumerate outputs\n");
1005 * vpbe_display_s_output - Set output to
1006 * the output specified by the index
1008 static int vpbe_display_s_output(struct file *file, void *priv,
1011 struct vpbe_layer *layer = video_drvdata(file);
1012 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1015 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_OUTPUT\n");
1017 if (vb2_is_busy(&layer->buffer_queue))
1020 if (NULL == vpbe_dev->ops.set_output)
1023 ret = vpbe_dev->ops.set_output(vpbe_dev, i);
1025 v4l2_err(&vpbe_dev->v4l2_dev,
1026 "Failed to set output for sub devices\n");
1034 * vpbe_display_g_output - Get output from subdevice
1035 * for a given by the index
1037 static int vpbe_display_g_output(struct file *file, void *priv,
1040 struct vpbe_layer *layer = video_drvdata(file);
1041 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1043 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_OUTPUT\n");
1044 /* Get the standard from the current encoder */
1045 *i = vpbe_dev->current_out_index;
1051 * vpbe_display_enum_dv_timings - Enumerate the dv timings
1053 * enum the timings in the current encoder. Return the status. 0 - success
1057 vpbe_display_enum_dv_timings(struct file *file, void *priv,
1058 struct v4l2_enum_dv_timings *timings)
1060 struct vpbe_layer *layer = video_drvdata(file);
1061 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1064 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_DV_TIMINGS\n");
1066 /* Enumerate outputs */
1067 if (NULL == vpbe_dev->ops.enum_dv_timings)
1070 ret = vpbe_dev->ops.enum_dv_timings(vpbe_dev, timings);
1072 v4l2_err(&vpbe_dev->v4l2_dev,
1073 "Failed to enumerate dv timings info\n");
1081 * vpbe_display_s_dv_timings - Set the dv timings
1083 * Set the timings in the current encoder. Return the status. 0 - success
1087 vpbe_display_s_dv_timings(struct file *file, void *priv,
1088 struct v4l2_dv_timings *timings)
1090 struct vpbe_layer *layer = video_drvdata(file);
1091 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1094 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_DV_TIMINGS\n");
1096 if (vb2_is_busy(&layer->buffer_queue))
1099 /* Set the given standard in the encoder */
1100 if (!vpbe_dev->ops.s_dv_timings)
1103 ret = vpbe_dev->ops.s_dv_timings(vpbe_dev, timings);
1105 v4l2_err(&vpbe_dev->v4l2_dev,
1106 "Failed to set the dv timings info\n");
1114 * vpbe_display_g_dv_timings - Set the dv timings
1116 * Get the timings in the current encoder. Return the status. 0 - success
1120 vpbe_display_g_dv_timings(struct file *file, void *priv,
1121 struct v4l2_dv_timings *dv_timings)
1123 struct vpbe_layer *layer = video_drvdata(file);
1124 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1126 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_DV_TIMINGS\n");
1128 /* Get the given standard in the encoder */
1130 if (vpbe_dev->current_timings.timings_type &
1131 VPBE_ENC_DV_TIMINGS) {
1132 *dv_timings = vpbe_dev->current_timings.dv_timings;
1141 * vpbe_display_open()
1142 * It creates object of file handle structure and stores it in private_data
1143 * member of filepointer
1145 static int vpbe_display_open(struct file *file)
1147 struct vpbe_layer *layer = video_drvdata(file);
1148 struct vpbe_display *disp_dev = layer->disp_dev;
1149 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
1150 struct osd_state *osd_device = disp_dev->osd_device;
1153 /* creating context for file descriptor */
1154 err = v4l2_fh_open(file);
1156 v4l2_err(&vpbe_dev->v4l2_dev, "v4l2_fh_open failed\n");
1160 /* leaving if layer is already initialized */
1161 if (!v4l2_fh_is_singular_file(file))
1165 if (mutex_lock_interruptible(&layer->opslock))
1166 return -ERESTARTSYS;
1167 /* First claim the layer for this device */
1168 err = osd_device->ops.request_layer(osd_device,
1169 layer->layer_info.id);
1170 mutex_unlock(&layer->opslock);
1172 /* Couldn't get layer */
1173 v4l2_err(&vpbe_dev->v4l2_dev,
1174 "Display Manager failed to allocate layer\n");
1175 v4l2_fh_release(file);
1179 /* Increment layer usrs counter */
1181 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
1182 "vpbe display device opened successfully\n");
1187 * vpbe_display_release()
1188 * This function deletes buffer queue, frees the buffers and the davinci
1189 * display file * handle
1191 static int vpbe_display_release(struct file *file)
1193 struct vpbe_layer *layer = video_drvdata(file);
1194 struct osd_layer_config *cfg = &layer->layer_info.config;
1195 struct vpbe_display *disp_dev = layer->disp_dev;
1196 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
1197 struct osd_state *osd_device = disp_dev->osd_device;
1199 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_release\n");
1201 mutex_lock(&layer->opslock);
1203 osd_device->ops.disable_layer(osd_device,
1204 layer->layer_info.id);
1205 /* Decrement layer usrs counter */
1207 /* If this file handle has initialize encoder device, reset it */
1209 if (cfg->pixfmt == PIXFMT_NV12) {
1210 struct vpbe_layer *otherlayer;
1212 _vpbe_display_get_other_win_layer(disp_dev, layer);
1213 osd_device->ops.disable_layer(osd_device,
1214 otherlayer->layer_info.id);
1215 osd_device->ops.release_layer(osd_device,
1216 otherlayer->layer_info.id);
1218 osd_device->ops.disable_layer(osd_device,
1219 layer->layer_info.id);
1220 osd_device->ops.release_layer(osd_device,
1221 layer->layer_info.id);
1224 _vb2_fop_release(file, NULL);
1225 mutex_unlock(&layer->opslock);
1227 disp_dev->cbcr_ofst = 0;
1232 /* vpbe capture ioctl operations */
1233 static const struct v4l2_ioctl_ops vpbe_ioctl_ops = {
1234 .vidioc_querycap = vpbe_display_querycap,
1235 .vidioc_g_fmt_vid_out = vpbe_display_g_fmt,
1236 .vidioc_enum_fmt_vid_out = vpbe_display_enum_fmt,
1237 .vidioc_s_fmt_vid_out = vpbe_display_s_fmt,
1238 .vidioc_try_fmt_vid_out = vpbe_display_try_fmt,
1240 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1241 .vidioc_create_bufs = vb2_ioctl_create_bufs,
1242 .vidioc_querybuf = vb2_ioctl_querybuf,
1243 .vidioc_qbuf = vb2_ioctl_qbuf,
1244 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1245 .vidioc_streamon = vb2_ioctl_streamon,
1246 .vidioc_streamoff = vb2_ioctl_streamoff,
1247 .vidioc_expbuf = vb2_ioctl_expbuf,
1249 .vidioc_cropcap = vpbe_display_cropcap,
1250 .vidioc_g_crop = vpbe_display_g_crop,
1251 .vidioc_s_crop = vpbe_display_s_crop,
1253 .vidioc_s_std = vpbe_display_s_std,
1254 .vidioc_g_std = vpbe_display_g_std,
1256 .vidioc_enum_output = vpbe_display_enum_output,
1257 .vidioc_s_output = vpbe_display_s_output,
1258 .vidioc_g_output = vpbe_display_g_output,
1260 .vidioc_s_dv_timings = vpbe_display_s_dv_timings,
1261 .vidioc_g_dv_timings = vpbe_display_g_dv_timings,
1262 .vidioc_enum_dv_timings = vpbe_display_enum_dv_timings,
1265 static struct v4l2_file_operations vpbe_fops = {
1266 .owner = THIS_MODULE,
1267 .open = vpbe_display_open,
1268 .release = vpbe_display_release,
1269 .unlocked_ioctl = video_ioctl2,
1270 .mmap = vb2_fop_mmap,
1271 .poll = vb2_fop_poll,
1274 static int vpbe_device_get(struct device *dev, void *data)
1276 struct platform_device *pdev = to_platform_device(dev);
1277 struct vpbe_display *vpbe_disp = data;
1279 if (strcmp("vpbe_controller", pdev->name) == 0)
1280 vpbe_disp->vpbe_dev = platform_get_drvdata(pdev);
1282 if (strstr(pdev->name, "vpbe-osd") != NULL)
1283 vpbe_disp->osd_device = platform_get_drvdata(pdev);
1288 static int init_vpbe_layer(int i, struct vpbe_display *disp_dev,
1289 struct platform_device *pdev)
1291 struct vpbe_layer *vpbe_display_layer = NULL;
1292 struct video_device *vbd = NULL;
1294 /* Allocate memory for four plane display objects */
1297 kzalloc(sizeof(struct vpbe_layer), GFP_KERNEL);
1299 /* If memory allocation fails, return error */
1300 if (!disp_dev->dev[i]) {
1301 printk(KERN_ERR "ran out of memory\n");
1304 spin_lock_init(&disp_dev->dev[i]->irqlock);
1305 mutex_init(&disp_dev->dev[i]->opslock);
1307 /* Get the pointer to the layer object */
1308 vpbe_display_layer = disp_dev->dev[i];
1309 vbd = &vpbe_display_layer->video_dev;
1310 /* Initialize field of video device */
1311 vbd->release = video_device_release_empty;
1312 vbd->fops = &vpbe_fops;
1313 vbd->ioctl_ops = &vpbe_ioctl_ops;
1315 vbd->v4l2_dev = &disp_dev->vpbe_dev->v4l2_dev;
1316 vbd->lock = &vpbe_display_layer->opslock;
1317 vbd->vfl_dir = VFL_DIR_TX;
1319 if (disp_dev->vpbe_dev->current_timings.timings_type &
1321 vbd->tvnorms = (V4L2_STD_525_60 | V4L2_STD_625_50);
1323 snprintf(vbd->name, sizeof(vbd->name),
1324 "DaVinci_VPBE Display_DRIVER_V%d.%d.%d",
1325 (VPBE_DISPLAY_VERSION_CODE >> 16) & 0xff,
1326 (VPBE_DISPLAY_VERSION_CODE >> 8) & 0xff,
1327 (VPBE_DISPLAY_VERSION_CODE) & 0xff);
1329 vpbe_display_layer->device_id = i;
1331 vpbe_display_layer->layer_info.id =
1332 ((i == VPBE_DISPLAY_DEVICE_0) ? WIN_VID0 : WIN_VID1);
1338 static int register_device(struct vpbe_layer *vpbe_display_layer,
1339 struct vpbe_display *disp_dev,
1340 struct platform_device *pdev)
1344 v4l2_info(&disp_dev->vpbe_dev->v4l2_dev,
1345 "Trying to register VPBE display device.\n");
1346 v4l2_info(&disp_dev->vpbe_dev->v4l2_dev,
1347 "layer=%x,layer->video_dev=%x\n",
1348 (int)vpbe_display_layer,
1349 (int)&vpbe_display_layer->video_dev);
1351 vpbe_display_layer->video_dev.queue = &vpbe_display_layer->buffer_queue;
1352 err = video_register_device(&vpbe_display_layer->video_dev,
1358 vpbe_display_layer->disp_dev = disp_dev;
1359 /* set the driver data in platform device */
1360 platform_set_drvdata(pdev, disp_dev);
1361 video_set_drvdata(&vpbe_display_layer->video_dev,
1362 vpbe_display_layer);
1370 * vpbe_display_probe()
1371 * This function creates device entries by register itself to the V4L2 driver
1372 * and initializes fields of each layer objects
1374 static int vpbe_display_probe(struct platform_device *pdev)
1376 struct vpbe_display *disp_dev;
1377 struct v4l2_device *v4l2_dev;
1378 struct resource *res = NULL;
1379 struct vb2_queue *q;
1385 printk(KERN_DEBUG "vpbe_display_probe\n");
1386 /* Allocate memory for vpbe_display */
1387 disp_dev = devm_kzalloc(&pdev->dev, sizeof(struct vpbe_display),
1392 spin_lock_init(&disp_dev->dma_queue_lock);
1394 * Scan all the platform devices to find the vpbe
1395 * controller device and get the vpbe_dev object
1397 err = bus_for_each_dev(&platform_bus_type, NULL, disp_dev,
1402 v4l2_dev = &disp_dev->vpbe_dev->v4l2_dev;
1403 /* Initialize the vpbe display controller */
1404 if (NULL != disp_dev->vpbe_dev->ops.initialize) {
1405 err = disp_dev->vpbe_dev->ops.initialize(&pdev->dev,
1406 disp_dev->vpbe_dev);
1408 v4l2_err(v4l2_dev, "Error initing vpbe\n");
1414 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
1415 if (init_vpbe_layer(i, disp_dev, pdev)) {
1421 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1423 v4l2_err(v4l2_dev, "Unable to get VENC interrupt resource\n");
1429 err = devm_request_irq(&pdev->dev, irq, venc_isr, 0,
1430 VPBE_DISPLAY_DRIVER, disp_dev);
1432 v4l2_err(v4l2_dev, "VPBE IRQ request failed\n");
1436 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
1437 /* initialize vb2 queue */
1438 q = &disp_dev->dev[i]->buffer_queue;
1439 memset(q, 0, sizeof(*q));
1440 q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
1441 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
1442 q->drv_priv = disp_dev->dev[i];
1443 q->ops = &video_qops;
1444 q->mem_ops = &vb2_dma_contig_memops;
1445 q->buf_struct_size = sizeof(struct vpbe_disp_buffer);
1446 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1447 q->min_buffers_needed = 1;
1448 q->lock = &disp_dev->dev[i]->opslock;
1449 err = vb2_queue_init(q);
1451 v4l2_err(v4l2_dev, "vb2_queue_init() failed\n");
1455 disp_dev->dev[i]->alloc_ctx =
1456 vb2_dma_contig_init_ctx(disp_dev->vpbe_dev->pdev);
1457 if (IS_ERR(disp_dev->dev[i]->alloc_ctx)) {
1458 v4l2_err(v4l2_dev, "Failed to get the context\n");
1459 err = PTR_ERR(disp_dev->dev[i]->alloc_ctx);
1463 INIT_LIST_HEAD(&disp_dev->dev[i]->dma_queue);
1465 if (register_device(disp_dev->dev[i], disp_dev, pdev)) {
1471 v4l2_dbg(1, debug, v4l2_dev,
1472 "Successfully completed the probing of vpbe v4l2 device\n");
1477 for (k = 0; k < VPBE_DISPLAY_MAX_DEVICES; k++) {
1478 /* Unregister video device */
1479 if (disp_dev->dev[k] != NULL) {
1480 vb2_dma_contig_cleanup_ctx(disp_dev->dev[k]->alloc_ctx);
1481 video_unregister_device(&disp_dev->dev[k]->video_dev);
1482 kfree(disp_dev->dev[k]);
1489 * vpbe_display_remove()
1490 * It un-register hardware layer from V4L2 driver
1492 static int vpbe_display_remove(struct platform_device *pdev)
1494 struct vpbe_layer *vpbe_display_layer;
1495 struct vpbe_display *disp_dev = platform_get_drvdata(pdev);
1496 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
1499 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_remove\n");
1501 /* deinitialize the vpbe display controller */
1502 if (NULL != vpbe_dev->ops.deinitialize)
1503 vpbe_dev->ops.deinitialize(&pdev->dev, vpbe_dev);
1504 /* un-register device */
1505 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
1506 /* Get the pointer to the layer object */
1507 vpbe_display_layer = disp_dev->dev[i];
1508 vb2_dma_contig_cleanup_ctx(vpbe_display_layer->alloc_ctx);
1509 /* Unregister video device */
1510 video_unregister_device(&vpbe_display_layer->video_dev);
1513 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
1514 kfree(disp_dev->dev[i]);
1515 disp_dev->dev[i] = NULL;
1521 static struct platform_driver vpbe_display_driver = {
1523 .name = VPBE_DISPLAY_DRIVER,
1524 .bus = &platform_bus_type,
1526 .probe = vpbe_display_probe,
1527 .remove = vpbe_display_remove,
1530 module_platform_driver(vpbe_display_driver);
1532 MODULE_DESCRIPTION("TI DM644x/DM355/DM365 VPBE Display controller");
1533 MODULE_LICENSE("GPL");
1534 MODULE_AUTHOR("Texas Instruments");