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.timestamp);
78 vb2_buffer_done(&layer->cur_frm->vb.vb2_buf, 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.vb2_buf.state = VB2_BUF_STATE_ACTIVE;
108 addr = vb2_dma_contig_plane_dma_addr(&layer->next_frm->vb.vb2_buf, 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 void *parg,
232 unsigned int *nbuffers, unsigned int *nplanes,
233 unsigned int sizes[], void *alloc_ctxs[])
236 const struct v4l2_format *fmt = parg;
237 /* Get the file handle object and layer object */
238 struct vpbe_layer *layer = vb2_get_drv_priv(vq);
239 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
241 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_buffer_setup\n");
243 if (fmt && fmt->fmt.pix.sizeimage < layer->pix_fmt.sizeimage)
246 /* Store number of buffers allocated in numbuffer member */
247 if (vq->num_buffers + *nbuffers < VPBE_DEFAULT_NUM_BUFS)
248 *nbuffers = VPBE_DEFAULT_NUM_BUFS - vq->num_buffers;
251 sizes[0] = fmt ? fmt->fmt.pix.sizeimage : layer->pix_fmt.sizeimage;
252 alloc_ctxs[0] = layer->alloc_ctx;
258 * vpbe_buffer_queue()
259 * This function adds the buffer to DMA queue
261 static void vpbe_buffer_queue(struct vb2_buffer *vb)
263 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
264 /* Get the file handle object and layer object */
265 struct vpbe_disp_buffer *buf = container_of(vbuf,
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.vb2_buf.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,
305 VB2_BUF_STATE_QUEUED);
306 list_for_each_entry_safe(buf, tmp, &layer->dma_queue, list) {
307 list_del(&buf->list);
308 vb2_buffer_done(&buf->vb.vb2_buf,
309 VB2_BUF_STATE_QUEUED);
316 * if request format is yuv420 semiplanar, need to
317 * enable both video windows
319 layer->layer_first_int = 1;
324 static void vpbe_stop_streaming(struct vb2_queue *vq)
326 struct vpbe_layer *layer = vb2_get_drv_priv(vq);
327 struct osd_state *osd_device = layer->disp_dev->osd_device;
328 struct vpbe_display *disp = layer->disp_dev;
331 if (!vb2_is_streaming(vq))
334 osd_device->ops.disable_layer(osd_device, layer->layer_info.id);
336 /* release all active buffers */
337 spin_lock_irqsave(&disp->dma_queue_lock, flags);
338 if (layer->cur_frm == layer->next_frm) {
339 vb2_buffer_done(&layer->cur_frm->vb.vb2_buf,
340 VB2_BUF_STATE_ERROR);
342 if (layer->cur_frm != NULL)
343 vb2_buffer_done(&layer->cur_frm->vb.vb2_buf,
344 VB2_BUF_STATE_ERROR);
345 if (layer->next_frm != NULL)
346 vb2_buffer_done(&layer->next_frm->vb.vb2_buf,
347 VB2_BUF_STATE_ERROR);
350 while (!list_empty(&layer->dma_queue)) {
351 layer->next_frm = list_entry(layer->dma_queue.next,
352 struct vpbe_disp_buffer, list);
353 list_del(&layer->next_frm->list);
354 vb2_buffer_done(&layer->next_frm->vb.vb2_buf,
355 VB2_BUF_STATE_ERROR);
357 spin_unlock_irqrestore(&disp->dma_queue_lock, flags);
360 static struct vb2_ops video_qops = {
361 .queue_setup = vpbe_buffer_queue_setup,
362 .wait_prepare = vb2_ops_wait_prepare,
363 .wait_finish = vb2_ops_wait_finish,
364 .buf_prepare = vpbe_buffer_prepare,
365 .start_streaming = vpbe_start_streaming,
366 .stop_streaming = vpbe_stop_streaming,
367 .buf_queue = vpbe_buffer_queue,
372 _vpbe_display_get_other_win_layer(struct vpbe_display *disp_dev,
373 struct vpbe_layer *layer)
375 enum vpbe_display_device_id thiswin, otherwin;
376 thiswin = layer->device_id;
378 otherwin = (thiswin == VPBE_DISPLAY_DEVICE_0) ?
379 VPBE_DISPLAY_DEVICE_1 : VPBE_DISPLAY_DEVICE_0;
380 return disp_dev->dev[otherwin];
383 static int vpbe_set_osd_display_params(struct vpbe_display *disp_dev,
384 struct vpbe_layer *layer)
386 struct osd_layer_config *cfg = &layer->layer_info.config;
387 struct osd_state *osd_device = disp_dev->osd_device;
388 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
392 addr = vb2_dma_contig_plane_dma_addr(&layer->cur_frm->vb.vb2_buf, 0);
393 /* Set address in the display registers */
394 osd_device->ops.start_layer(osd_device,
395 layer->layer_info.id,
397 disp_dev->cbcr_ofst);
399 ret = osd_device->ops.enable_layer(osd_device,
400 layer->layer_info.id, 0);
402 v4l2_err(&vpbe_dev->v4l2_dev,
403 "Error in enabling osd window layer 0\n");
407 /* Enable the window */
408 layer->layer_info.enable = 1;
409 if (cfg->pixfmt == PIXFMT_NV12) {
410 struct vpbe_layer *otherlayer =
411 _vpbe_display_get_other_win_layer(disp_dev, layer);
413 ret = osd_device->ops.enable_layer(osd_device,
414 otherlayer->layer_info.id, 1);
416 v4l2_err(&vpbe_dev->v4l2_dev,
417 "Error in enabling osd window layer 1\n");
420 otherlayer->layer_info.enable = 1;
426 vpbe_disp_calculate_scale_factor(struct vpbe_display *disp_dev,
427 struct vpbe_layer *layer,
428 int expected_xsize, int expected_ysize)
430 struct display_layer_info *layer_info = &layer->layer_info;
431 struct v4l2_pix_format *pixfmt = &layer->pix_fmt;
432 struct osd_layer_config *cfg = &layer->layer_info.config;
433 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
434 int calculated_xsize;
440 v4l2_std_id standard_id = vpbe_dev->current_timings.std_id;
443 * Application initially set the image format. Current display
444 * size is obtained from the vpbe display controller. expected_xsize
445 * and expected_ysize are set through S_CROP ioctl. Based on this,
446 * driver will calculate the scale factors for vertical and
447 * horizontal direction so that the image is displayed scaled
448 * and expanded. Application uses expansion to display the image
449 * in a square pixel. Otherwise it is displayed using displays
450 * pixel aspect ratio.It is expected that application chooses
451 * the crop coordinates for cropped or scaled display. if crop
452 * size is less than the image size, it is displayed cropped or
453 * it is displayed scaled and/or expanded.
455 * to begin with, set the crop window same as expected. Later we
456 * will override with scaled window size
459 cfg->xsize = pixfmt->width;
460 cfg->ysize = pixfmt->height;
461 layer_info->h_zoom = ZOOM_X1; /* no horizontal zoom */
462 layer_info->v_zoom = ZOOM_X1; /* no horizontal zoom */
463 layer_info->h_exp = H_EXP_OFF; /* no horizontal zoom */
464 layer_info->v_exp = V_EXP_OFF; /* no horizontal zoom */
466 if (pixfmt->width < expected_xsize) {
467 h_scale = vpbe_dev->current_timings.xres / pixfmt->width;
470 else if (h_scale >= 4)
474 cfg->xsize *= h_scale;
475 if (cfg->xsize < expected_xsize) {
476 if ((standard_id & V4L2_STD_525_60) ||
477 (standard_id & V4L2_STD_625_50)) {
478 calculated_xsize = (cfg->xsize *
479 VPBE_DISPLAY_H_EXP_RATIO_N) /
480 VPBE_DISPLAY_H_EXP_RATIO_D;
481 if (calculated_xsize <= expected_xsize) {
483 cfg->xsize = calculated_xsize;
488 layer_info->h_zoom = ZOOM_X2;
489 else if (h_scale == 4)
490 layer_info->h_zoom = ZOOM_X4;
492 layer_info->h_exp = H_EXP_9_OVER_8;
494 /* no scaling, only cropping. Set display area to crop area */
495 cfg->xsize = expected_xsize;
498 if (pixfmt->height < expected_ysize) {
499 v_scale = expected_ysize / pixfmt->height;
502 else if (v_scale >= 4)
506 cfg->ysize *= v_scale;
507 if (cfg->ysize < expected_ysize) {
508 if ((standard_id & V4L2_STD_625_50)) {
509 calculated_xsize = (cfg->ysize *
510 VPBE_DISPLAY_V_EXP_RATIO_N) /
511 VPBE_DISPLAY_V_EXP_RATIO_D;
512 if (calculated_xsize <= expected_ysize) {
514 cfg->ysize = calculated_xsize;
519 layer_info->v_zoom = ZOOM_X2;
520 else if (v_scale == 4)
521 layer_info->v_zoom = ZOOM_X4;
523 layer_info->h_exp = V_EXP_6_OVER_5;
525 /* no scaling, only cropping. Set display area to crop area */
526 cfg->ysize = expected_ysize;
528 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
529 "crop display xsize = %d, ysize = %d\n",
530 cfg->xsize, cfg->ysize);
533 static void vpbe_disp_adj_position(struct vpbe_display *disp_dev,
534 struct vpbe_layer *layer,
537 struct osd_layer_config *cfg = &layer->layer_info.config;
538 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
540 cfg->xpos = min((unsigned int)left,
541 vpbe_dev->current_timings.xres - cfg->xsize);
542 cfg->ypos = min((unsigned int)top,
543 vpbe_dev->current_timings.yres - cfg->ysize);
545 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
546 "new xpos = %d, ypos = %d\n",
547 cfg->xpos, cfg->ypos);
550 static void vpbe_disp_check_window_params(struct vpbe_display *disp_dev,
553 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
555 if ((c->width == 0) ||
556 ((c->width + c->left) > vpbe_dev->current_timings.xres))
557 c->width = vpbe_dev->current_timings.xres - c->left;
559 if ((c->height == 0) || ((c->height + c->top) >
560 vpbe_dev->current_timings.yres))
561 c->height = vpbe_dev->current_timings.yres - c->top;
563 /* window height must be even for interlaced display */
564 if (vpbe_dev->current_timings.interlaced)
565 c->height &= (~0x01);
571 * If user application provides width and height, and have bytesperline set
572 * to zero, driver calculates bytesperline and sizeimage based on hardware
575 static int vpbe_try_format(struct vpbe_display *disp_dev,
576 struct v4l2_pix_format *pixfmt, int check)
578 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
585 if ((pixfmt->pixelformat != V4L2_PIX_FMT_UYVY) &&
586 (pixfmt->pixelformat != V4L2_PIX_FMT_NV12))
587 /* choose default as V4L2_PIX_FMT_UYVY */
588 pixfmt->pixelformat = V4L2_PIX_FMT_UYVY;
590 /* Check the field format */
591 if ((pixfmt->field != V4L2_FIELD_INTERLACED) &&
592 (pixfmt->field != V4L2_FIELD_NONE)) {
593 if (vpbe_dev->current_timings.interlaced)
594 pixfmt->field = V4L2_FIELD_INTERLACED;
596 pixfmt->field = V4L2_FIELD_NONE;
599 if (pixfmt->field == V4L2_FIELD_INTERLACED)
602 if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12)
607 max_width = vpbe_dev->current_timings.xres;
608 max_height = vpbe_dev->current_timings.yres;
612 if (!pixfmt->width || (pixfmt->width < min_width) ||
613 (pixfmt->width > max_width)) {
614 pixfmt->width = vpbe_dev->current_timings.xres;
617 if (!pixfmt->height || (pixfmt->height < min_height) ||
618 (pixfmt->height > max_height)) {
619 pixfmt->height = vpbe_dev->current_timings.yres;
622 if (pixfmt->bytesperline < (pixfmt->width * bpp))
623 pixfmt->bytesperline = pixfmt->width * bpp;
625 /* Make the bytesperline 32 byte aligned */
626 pixfmt->bytesperline = ((pixfmt->width * bpp + 31) & ~31);
628 if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12)
629 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height +
630 (pixfmt->bytesperline * pixfmt->height >> 1);
632 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
637 static int vpbe_display_querycap(struct file *file, void *priv,
638 struct v4l2_capability *cap)
640 struct vpbe_layer *layer = video_drvdata(file);
641 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
643 cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
644 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
645 snprintf(cap->driver, sizeof(cap->driver), "%s",
646 dev_name(vpbe_dev->pdev));
647 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
648 dev_name(vpbe_dev->pdev));
649 strlcpy(cap->card, vpbe_dev->cfg->module_name, sizeof(cap->card));
654 static int vpbe_display_s_crop(struct file *file, void *priv,
655 const struct v4l2_crop *crop)
657 struct vpbe_layer *layer = video_drvdata(file);
658 struct vpbe_display *disp_dev = layer->disp_dev;
659 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
660 struct osd_layer_config *cfg = &layer->layer_info.config;
661 struct osd_state *osd_device = disp_dev->osd_device;
662 struct v4l2_rect rect = crop->c;
665 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
666 "VIDIOC_S_CROP, layer id = %d\n", layer->device_id);
668 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
669 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buf type\n");
678 vpbe_disp_check_window_params(disp_dev, &rect);
680 osd_device->ops.get_layer_config(osd_device,
681 layer->layer_info.id, cfg);
683 vpbe_disp_calculate_scale_factor(disp_dev, layer,
686 vpbe_disp_adj_position(disp_dev, layer, rect.top,
688 ret = osd_device->ops.set_layer_config(osd_device,
689 layer->layer_info.id, cfg);
691 v4l2_err(&vpbe_dev->v4l2_dev,
692 "Error in set layer config:\n");
696 /* apply zooming and h or v expansion */
697 osd_device->ops.set_zoom(osd_device,
698 layer->layer_info.id,
699 layer->layer_info.h_zoom,
700 layer->layer_info.v_zoom);
701 ret = osd_device->ops.set_vid_expansion(osd_device,
702 layer->layer_info.h_exp,
703 layer->layer_info.v_exp);
705 v4l2_err(&vpbe_dev->v4l2_dev,
706 "Error in set vid expansion:\n");
710 if ((layer->layer_info.h_zoom != ZOOM_X1) ||
711 (layer->layer_info.v_zoom != ZOOM_X1) ||
712 (layer->layer_info.h_exp != H_EXP_OFF) ||
713 (layer->layer_info.v_exp != V_EXP_OFF))
714 /* Enable expansion filter */
715 osd_device->ops.set_interpolation_filter(osd_device, 1);
717 osd_device->ops.set_interpolation_filter(osd_device, 0);
722 static int vpbe_display_g_crop(struct file *file, void *priv,
723 struct v4l2_crop *crop)
725 struct vpbe_layer *layer = video_drvdata(file);
726 struct osd_layer_config *cfg = &layer->layer_info.config;
727 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
728 struct osd_state *osd_device = layer->disp_dev->osd_device;
729 struct v4l2_rect *rect = &crop->c;
731 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
732 "VIDIOC_G_CROP, layer id = %d\n",
735 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
736 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buf type\n");
739 osd_device->ops.get_layer_config(osd_device,
740 layer->layer_info.id, cfg);
741 rect->top = cfg->ypos;
742 rect->left = cfg->xpos;
743 rect->width = cfg->xsize;
744 rect->height = cfg->ysize;
749 static int vpbe_display_cropcap(struct file *file, void *priv,
750 struct v4l2_cropcap *cropcap)
752 struct vpbe_layer *layer = video_drvdata(file);
753 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
755 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_CROPCAP ioctl\n");
757 cropcap->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
758 cropcap->bounds.left = 0;
759 cropcap->bounds.top = 0;
760 cropcap->bounds.width = vpbe_dev->current_timings.xres;
761 cropcap->bounds.height = vpbe_dev->current_timings.yres;
762 cropcap->pixelaspect = vpbe_dev->current_timings.aspect;
763 cropcap->defrect = cropcap->bounds;
767 static int vpbe_display_g_fmt(struct file *file, void *priv,
768 struct v4l2_format *fmt)
770 struct vpbe_layer *layer = video_drvdata(file);
771 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
773 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
774 "VIDIOC_G_FMT, layer id = %d\n",
777 /* If buffer type is video output */
778 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != fmt->type) {
779 v4l2_err(&vpbe_dev->v4l2_dev, "invalid type\n");
782 /* Fill in the information about format */
783 fmt->fmt.pix = layer->pix_fmt;
788 static int vpbe_display_enum_fmt(struct file *file, void *priv,
789 struct v4l2_fmtdesc *fmt)
791 struct vpbe_layer *layer = video_drvdata(file);
792 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
793 unsigned int index = 0;
795 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
796 "VIDIOC_ENUM_FMT, layer id = %d\n",
798 if (fmt->index > 1) {
799 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid format index\n");
803 /* Fill in the information about format */
805 memset(fmt, 0, sizeof(*fmt));
807 fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
809 strcpy(fmt->description, "YUV 4:2:2 - UYVY");
810 fmt->pixelformat = V4L2_PIX_FMT_UYVY;
812 strcpy(fmt->description, "Y/CbCr 4:2:0");
813 fmt->pixelformat = V4L2_PIX_FMT_NV12;
819 static int vpbe_display_s_fmt(struct file *file, void *priv,
820 struct v4l2_format *fmt)
822 struct vpbe_layer *layer = video_drvdata(file);
823 struct vpbe_display *disp_dev = layer->disp_dev;
824 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
825 struct osd_layer_config *cfg = &layer->layer_info.config;
826 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
827 struct osd_state *osd_device = disp_dev->osd_device;
830 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
831 "VIDIOC_S_FMT, layer id = %d\n",
834 if (vb2_is_busy(&layer->buffer_queue))
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 (vb2_is_busy(&layer->buffer_queue))
943 if (NULL != vpbe_dev->ops.s_std) {
944 ret = vpbe_dev->ops.s_std(vpbe_dev, std_id);
946 v4l2_err(&vpbe_dev->v4l2_dev,
947 "Failed to set standard for sub devices\n");
958 * vpbe_display_g_std - Get the standard in the current encoder
960 * Get the standard in the current encoder. Return the status. 0 - success
963 static int vpbe_display_g_std(struct file *file, void *priv,
966 struct vpbe_layer *layer = video_drvdata(file);
967 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
969 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_STD\n");
971 /* Get the standard from the current encoder */
972 if (vpbe_dev->current_timings.timings_type & VPBE_ENC_STD) {
973 *std_id = vpbe_dev->current_timings.std_id;
981 * vpbe_display_enum_output - enumerate outputs
983 * Enumerates the outputs available at the vpbe display
984 * returns the status, -EINVAL if end of output list
986 static int vpbe_display_enum_output(struct file *file, void *priv,
987 struct v4l2_output *output)
989 struct vpbe_layer *layer = video_drvdata(file);
990 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
993 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_OUTPUT\n");
995 /* Enumerate outputs */
997 if (NULL == vpbe_dev->ops.enum_outputs)
1000 ret = vpbe_dev->ops.enum_outputs(vpbe_dev, output);
1002 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
1003 "Failed to enumerate outputs\n");
1011 * vpbe_display_s_output - Set output to
1012 * the output specified by the index
1014 static int vpbe_display_s_output(struct file *file, void *priv,
1017 struct vpbe_layer *layer = video_drvdata(file);
1018 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1021 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_OUTPUT\n");
1023 if (vb2_is_busy(&layer->buffer_queue))
1026 if (NULL == vpbe_dev->ops.set_output)
1029 ret = vpbe_dev->ops.set_output(vpbe_dev, i);
1031 v4l2_err(&vpbe_dev->v4l2_dev,
1032 "Failed to set output for sub devices\n");
1040 * vpbe_display_g_output - Get output from subdevice
1041 * for a given by the index
1043 static int vpbe_display_g_output(struct file *file, void *priv,
1046 struct vpbe_layer *layer = video_drvdata(file);
1047 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1049 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_OUTPUT\n");
1050 /* Get the standard from the current encoder */
1051 *i = vpbe_dev->current_out_index;
1057 * vpbe_display_enum_dv_timings - Enumerate the dv timings
1059 * enum the timings in the current encoder. Return the status. 0 - success
1063 vpbe_display_enum_dv_timings(struct file *file, void *priv,
1064 struct v4l2_enum_dv_timings *timings)
1066 struct vpbe_layer *layer = video_drvdata(file);
1067 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1070 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_DV_TIMINGS\n");
1072 /* Enumerate outputs */
1073 if (NULL == vpbe_dev->ops.enum_dv_timings)
1076 ret = vpbe_dev->ops.enum_dv_timings(vpbe_dev, timings);
1078 v4l2_err(&vpbe_dev->v4l2_dev,
1079 "Failed to enumerate dv timings info\n");
1087 * vpbe_display_s_dv_timings - Set the dv timings
1089 * Set the timings in the current encoder. Return the status. 0 - success
1093 vpbe_display_s_dv_timings(struct file *file, void *priv,
1094 struct v4l2_dv_timings *timings)
1096 struct vpbe_layer *layer = video_drvdata(file);
1097 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1100 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_DV_TIMINGS\n");
1102 if (vb2_is_busy(&layer->buffer_queue))
1105 /* Set the given standard in the encoder */
1106 if (!vpbe_dev->ops.s_dv_timings)
1109 ret = vpbe_dev->ops.s_dv_timings(vpbe_dev, timings);
1111 v4l2_err(&vpbe_dev->v4l2_dev,
1112 "Failed to set the dv timings info\n");
1120 * vpbe_display_g_dv_timings - Set the dv timings
1122 * Get the timings in the current encoder. Return the status. 0 - success
1126 vpbe_display_g_dv_timings(struct file *file, void *priv,
1127 struct v4l2_dv_timings *dv_timings)
1129 struct vpbe_layer *layer = video_drvdata(file);
1130 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1132 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_DV_TIMINGS\n");
1134 /* Get the given standard in the encoder */
1136 if (vpbe_dev->current_timings.timings_type &
1137 VPBE_ENC_DV_TIMINGS) {
1138 *dv_timings = vpbe_dev->current_timings.dv_timings;
1147 * vpbe_display_open()
1148 * It creates object of file handle structure and stores it in private_data
1149 * member of filepointer
1151 static int vpbe_display_open(struct file *file)
1153 struct vpbe_layer *layer = video_drvdata(file);
1154 struct vpbe_display *disp_dev = layer->disp_dev;
1155 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
1156 struct osd_state *osd_device = disp_dev->osd_device;
1159 /* creating context for file descriptor */
1160 err = v4l2_fh_open(file);
1162 v4l2_err(&vpbe_dev->v4l2_dev, "v4l2_fh_open failed\n");
1166 /* leaving if layer is already initialized */
1167 if (!v4l2_fh_is_singular_file(file))
1171 if (mutex_lock_interruptible(&layer->opslock))
1172 return -ERESTARTSYS;
1173 /* First claim the layer for this device */
1174 err = osd_device->ops.request_layer(osd_device,
1175 layer->layer_info.id);
1176 mutex_unlock(&layer->opslock);
1178 /* Couldn't get layer */
1179 v4l2_err(&vpbe_dev->v4l2_dev,
1180 "Display Manager failed to allocate layer\n");
1181 v4l2_fh_release(file);
1185 /* Increment layer usrs counter */
1187 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
1188 "vpbe display device opened successfully\n");
1193 * vpbe_display_release()
1194 * This function deletes buffer queue, frees the buffers and the davinci
1195 * display file * handle
1197 static int vpbe_display_release(struct file *file)
1199 struct vpbe_layer *layer = video_drvdata(file);
1200 struct osd_layer_config *cfg = &layer->layer_info.config;
1201 struct vpbe_display *disp_dev = layer->disp_dev;
1202 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
1203 struct osd_state *osd_device = disp_dev->osd_device;
1205 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_release\n");
1207 mutex_lock(&layer->opslock);
1209 osd_device->ops.disable_layer(osd_device,
1210 layer->layer_info.id);
1211 /* Decrement layer usrs counter */
1213 /* If this file handle has initialize encoder device, reset it */
1215 if (cfg->pixfmt == PIXFMT_NV12) {
1216 struct vpbe_layer *otherlayer;
1218 _vpbe_display_get_other_win_layer(disp_dev, layer);
1219 osd_device->ops.disable_layer(osd_device,
1220 otherlayer->layer_info.id);
1221 osd_device->ops.release_layer(osd_device,
1222 otherlayer->layer_info.id);
1224 osd_device->ops.disable_layer(osd_device,
1225 layer->layer_info.id);
1226 osd_device->ops.release_layer(osd_device,
1227 layer->layer_info.id);
1230 _vb2_fop_release(file, NULL);
1231 mutex_unlock(&layer->opslock);
1233 disp_dev->cbcr_ofst = 0;
1238 /* vpbe capture ioctl operations */
1239 static const struct v4l2_ioctl_ops vpbe_ioctl_ops = {
1240 .vidioc_querycap = vpbe_display_querycap,
1241 .vidioc_g_fmt_vid_out = vpbe_display_g_fmt,
1242 .vidioc_enum_fmt_vid_out = vpbe_display_enum_fmt,
1243 .vidioc_s_fmt_vid_out = vpbe_display_s_fmt,
1244 .vidioc_try_fmt_vid_out = vpbe_display_try_fmt,
1246 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1247 .vidioc_create_bufs = vb2_ioctl_create_bufs,
1248 .vidioc_querybuf = vb2_ioctl_querybuf,
1249 .vidioc_qbuf = vb2_ioctl_qbuf,
1250 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1251 .vidioc_streamon = vb2_ioctl_streamon,
1252 .vidioc_streamoff = vb2_ioctl_streamoff,
1253 .vidioc_expbuf = vb2_ioctl_expbuf,
1255 .vidioc_cropcap = vpbe_display_cropcap,
1256 .vidioc_g_crop = vpbe_display_g_crop,
1257 .vidioc_s_crop = vpbe_display_s_crop,
1259 .vidioc_s_std = vpbe_display_s_std,
1260 .vidioc_g_std = vpbe_display_g_std,
1262 .vidioc_enum_output = vpbe_display_enum_output,
1263 .vidioc_s_output = vpbe_display_s_output,
1264 .vidioc_g_output = vpbe_display_g_output,
1266 .vidioc_s_dv_timings = vpbe_display_s_dv_timings,
1267 .vidioc_g_dv_timings = vpbe_display_g_dv_timings,
1268 .vidioc_enum_dv_timings = vpbe_display_enum_dv_timings,
1271 static struct v4l2_file_operations vpbe_fops = {
1272 .owner = THIS_MODULE,
1273 .open = vpbe_display_open,
1274 .release = vpbe_display_release,
1275 .unlocked_ioctl = video_ioctl2,
1276 .mmap = vb2_fop_mmap,
1277 .poll = vb2_fop_poll,
1280 static int vpbe_device_get(struct device *dev, void *data)
1282 struct platform_device *pdev = to_platform_device(dev);
1283 struct vpbe_display *vpbe_disp = data;
1285 if (strcmp("vpbe_controller", pdev->name) == 0)
1286 vpbe_disp->vpbe_dev = platform_get_drvdata(pdev);
1288 if (strstr(pdev->name, "vpbe-osd") != NULL)
1289 vpbe_disp->osd_device = platform_get_drvdata(pdev);
1294 static int init_vpbe_layer(int i, struct vpbe_display *disp_dev,
1295 struct platform_device *pdev)
1297 struct vpbe_layer *vpbe_display_layer = NULL;
1298 struct video_device *vbd = NULL;
1300 /* Allocate memory for four plane display objects */
1303 kzalloc(sizeof(struct vpbe_layer), GFP_KERNEL);
1305 /* If memory allocation fails, return error */
1306 if (!disp_dev->dev[i]) {
1307 printk(KERN_ERR "ran out of memory\n");
1310 spin_lock_init(&disp_dev->dev[i]->irqlock);
1311 mutex_init(&disp_dev->dev[i]->opslock);
1313 /* Get the pointer to the layer object */
1314 vpbe_display_layer = disp_dev->dev[i];
1315 vbd = &vpbe_display_layer->video_dev;
1316 /* Initialize field of video device */
1317 vbd->release = video_device_release_empty;
1318 vbd->fops = &vpbe_fops;
1319 vbd->ioctl_ops = &vpbe_ioctl_ops;
1321 vbd->v4l2_dev = &disp_dev->vpbe_dev->v4l2_dev;
1322 vbd->lock = &vpbe_display_layer->opslock;
1323 vbd->vfl_dir = VFL_DIR_TX;
1325 if (disp_dev->vpbe_dev->current_timings.timings_type &
1327 vbd->tvnorms = (V4L2_STD_525_60 | V4L2_STD_625_50);
1329 snprintf(vbd->name, sizeof(vbd->name),
1330 "DaVinci_VPBE Display_DRIVER_V%d.%d.%d",
1331 (VPBE_DISPLAY_VERSION_CODE >> 16) & 0xff,
1332 (VPBE_DISPLAY_VERSION_CODE >> 8) & 0xff,
1333 (VPBE_DISPLAY_VERSION_CODE) & 0xff);
1335 vpbe_display_layer->device_id = i;
1337 vpbe_display_layer->layer_info.id =
1338 ((i == VPBE_DISPLAY_DEVICE_0) ? WIN_VID0 : WIN_VID1);
1344 static int register_device(struct vpbe_layer *vpbe_display_layer,
1345 struct vpbe_display *disp_dev,
1346 struct platform_device *pdev)
1350 v4l2_info(&disp_dev->vpbe_dev->v4l2_dev,
1351 "Trying to register VPBE display device.\n");
1352 v4l2_info(&disp_dev->vpbe_dev->v4l2_dev,
1353 "layer=%x,layer->video_dev=%x\n",
1354 (int)vpbe_display_layer,
1355 (int)&vpbe_display_layer->video_dev);
1357 vpbe_display_layer->video_dev.queue = &vpbe_display_layer->buffer_queue;
1358 err = video_register_device(&vpbe_display_layer->video_dev,
1364 vpbe_display_layer->disp_dev = disp_dev;
1365 /* set the driver data in platform device */
1366 platform_set_drvdata(pdev, disp_dev);
1367 video_set_drvdata(&vpbe_display_layer->video_dev,
1368 vpbe_display_layer);
1376 * vpbe_display_probe()
1377 * This function creates device entries by register itself to the V4L2 driver
1378 * and initializes fields of each layer objects
1380 static int vpbe_display_probe(struct platform_device *pdev)
1382 struct vpbe_display *disp_dev;
1383 struct v4l2_device *v4l2_dev;
1384 struct resource *res = NULL;
1385 struct vb2_queue *q;
1391 printk(KERN_DEBUG "vpbe_display_probe\n");
1392 /* Allocate memory for vpbe_display */
1393 disp_dev = devm_kzalloc(&pdev->dev, sizeof(struct vpbe_display),
1398 spin_lock_init(&disp_dev->dma_queue_lock);
1400 * Scan all the platform devices to find the vpbe
1401 * controller device and get the vpbe_dev object
1403 err = bus_for_each_dev(&platform_bus_type, NULL, disp_dev,
1408 v4l2_dev = &disp_dev->vpbe_dev->v4l2_dev;
1409 /* Initialize the vpbe display controller */
1410 if (NULL != disp_dev->vpbe_dev->ops.initialize) {
1411 err = disp_dev->vpbe_dev->ops.initialize(&pdev->dev,
1412 disp_dev->vpbe_dev);
1414 v4l2_err(v4l2_dev, "Error initing vpbe\n");
1420 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
1421 if (init_vpbe_layer(i, disp_dev, pdev)) {
1427 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1429 v4l2_err(v4l2_dev, "Unable to get VENC interrupt resource\n");
1435 err = devm_request_irq(&pdev->dev, irq, venc_isr, 0,
1436 VPBE_DISPLAY_DRIVER, disp_dev);
1438 v4l2_err(v4l2_dev, "VPBE IRQ request failed\n");
1442 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
1443 /* initialize vb2 queue */
1444 q = &disp_dev->dev[i]->buffer_queue;
1445 memset(q, 0, sizeof(*q));
1446 q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
1447 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
1448 q->drv_priv = disp_dev->dev[i];
1449 q->ops = &video_qops;
1450 q->mem_ops = &vb2_dma_contig_memops;
1451 q->buf_struct_size = sizeof(struct vpbe_disp_buffer);
1452 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1453 q->min_buffers_needed = 1;
1454 q->lock = &disp_dev->dev[i]->opslock;
1455 err = vb2_queue_init(q);
1457 v4l2_err(v4l2_dev, "vb2_queue_init() failed\n");
1461 disp_dev->dev[i]->alloc_ctx =
1462 vb2_dma_contig_init_ctx(disp_dev->vpbe_dev->pdev);
1463 if (IS_ERR(disp_dev->dev[i]->alloc_ctx)) {
1464 v4l2_err(v4l2_dev, "Failed to get the context\n");
1465 err = PTR_ERR(disp_dev->dev[i]->alloc_ctx);
1469 INIT_LIST_HEAD(&disp_dev->dev[i]->dma_queue);
1471 if (register_device(disp_dev->dev[i], disp_dev, pdev)) {
1477 v4l2_dbg(1, debug, v4l2_dev,
1478 "Successfully completed the probing of vpbe v4l2 device\n");
1483 for (k = 0; k < VPBE_DISPLAY_MAX_DEVICES; k++) {
1484 /* Unregister video device */
1485 if (disp_dev->dev[k] != NULL) {
1486 vb2_dma_contig_cleanup_ctx(disp_dev->dev[k]->alloc_ctx);
1487 video_unregister_device(&disp_dev->dev[k]->video_dev);
1488 kfree(disp_dev->dev[k]);
1495 * vpbe_display_remove()
1496 * It un-register hardware layer from V4L2 driver
1498 static int vpbe_display_remove(struct platform_device *pdev)
1500 struct vpbe_layer *vpbe_display_layer;
1501 struct vpbe_display *disp_dev = platform_get_drvdata(pdev);
1502 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
1505 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_remove\n");
1507 /* deinitialize the vpbe display controller */
1508 if (NULL != vpbe_dev->ops.deinitialize)
1509 vpbe_dev->ops.deinitialize(&pdev->dev, vpbe_dev);
1510 /* un-register device */
1511 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
1512 /* Get the pointer to the layer object */
1513 vpbe_display_layer = disp_dev->dev[i];
1514 vb2_dma_contig_cleanup_ctx(vpbe_display_layer->alloc_ctx);
1515 /* Unregister video device */
1516 video_unregister_device(&vpbe_display_layer->video_dev);
1519 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
1520 kfree(disp_dev->dev[i]);
1521 disp_dev->dev[i] = NULL;
1527 static struct platform_driver vpbe_display_driver = {
1529 .name = VPBE_DISPLAY_DRIVER,
1530 .bus = &platform_bus_type,
1532 .probe = vpbe_display_probe,
1533 .remove = vpbe_display_remove,
1536 module_platform_driver(vpbe_display_driver);
1538 MODULE_DESCRIPTION("TI DM644x/DM355/DM365 VPBE Display controller");
1539 MODULE_LICENSE("GPL");
1540 MODULE_AUTHOR("Texas Instruments");