1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
5 #include <linux/kernel.h>
6 #include <linux/init.h>
7 #include <linux/module.h>
8 #include <linux/errno.h>
9 #include <linux/interrupt.h>
10 #include <linux/string.h>
11 #include <linux/wait.h>
12 #include <linux/time.h>
13 #include <linux/platform_device.h>
14 #include <linux/irq.h>
16 #include <linux/mutex.h>
17 #include <linux/videodev2.h>
18 #include <linux/slab.h>
20 #include <asm/pgtable.h>
22 #ifdef CONFIG_ARCH_DAVINCI
23 #include <mach/cputype.h>
26 #include <media/v4l2-dev.h>
27 #include <media/v4l2-common.h>
28 #include <media/v4l2-ioctl.h>
29 #include <media/v4l2-device.h>
30 #include <media/davinci/vpbe_display.h>
31 #include <media/davinci/vpbe_types.h>
32 #include <media/davinci/vpbe.h>
33 #include <media/davinci/vpbe_venc.h>
34 #include <media/davinci/vpbe_osd.h>
35 #include "vpbe_venc_regs.h"
37 #define VPBE_DISPLAY_DRIVER "vpbe-v4l2"
41 #define VPBE_DEFAULT_NUM_BUFS 3
43 module_param(debug, int, 0644);
45 static int vpbe_set_osd_display_params(struct vpbe_display *disp_dev,
46 struct vpbe_layer *layer);
48 static int venc_is_second_field(struct vpbe_display *disp_dev)
50 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
53 ret = v4l2_subdev_call(vpbe_dev->venc,
59 v4l2_err(&vpbe_dev->v4l2_dev,
60 "Error in getting Field ID 0\n");
66 static void vpbe_isr_even_field(struct vpbe_display *disp_obj,
67 struct vpbe_layer *layer)
69 if (layer->cur_frm == layer->next_frm)
72 layer->cur_frm->vb.vb2_buf.timestamp = ktime_get_ns();
73 vb2_buffer_done(&layer->cur_frm->vb.vb2_buf, VB2_BUF_STATE_DONE);
74 /* Make cur_frm pointing to next_frm */
75 layer->cur_frm = layer->next_frm;
78 static void vpbe_isr_odd_field(struct vpbe_display *disp_obj,
79 struct vpbe_layer *layer)
81 struct osd_state *osd_device = disp_obj->osd_device;
84 spin_lock(&disp_obj->dma_queue_lock);
85 if (list_empty(&layer->dma_queue) ||
86 (layer->cur_frm != layer->next_frm)) {
87 spin_unlock(&disp_obj->dma_queue_lock);
91 * one field is displayed configure
92 * the next frame if it is available
93 * otherwise hold on current frame
94 * Get next from the buffer queue
96 layer->next_frm = list_entry(layer->dma_queue.next,
97 struct vpbe_disp_buffer, list);
98 /* Remove that from the buffer queue */
99 list_del(&layer->next_frm->list);
100 spin_unlock(&disp_obj->dma_queue_lock);
101 /* Mark state of the frame to active */
102 layer->next_frm->vb.vb2_buf.state = VB2_BUF_STATE_ACTIVE;
103 addr = vb2_dma_contig_plane_dma_addr(&layer->next_frm->vb.vb2_buf, 0);
104 osd_device->ops.start_layer(osd_device,
105 layer->layer_info.id,
107 disp_obj->cbcr_ofst);
110 /* interrupt service routine */
111 static irqreturn_t venc_isr(int irq, void *arg)
113 struct vpbe_display *disp_dev = (struct vpbe_display *)arg;
114 struct vpbe_layer *layer;
115 static unsigned last_event;
120 if (!arg || !disp_dev->dev[0])
123 if (venc_is_second_field(disp_dev))
124 event |= VENC_SECOND_FIELD;
126 event |= VENC_FIRST_FIELD;
128 if (event == (last_event & ~VENC_END_OF_FRAME)) {
130 * If the display is non-interlaced, then we need to flag the
131 * end-of-frame event at every interrupt regardless of the
132 * value of the FIDST bit. We can conclude that the display is
133 * non-interlaced if the value of the FIDST bit is unchanged
134 * from the previous interrupt.
136 event |= VENC_END_OF_FRAME;
137 } else if (event == VENC_SECOND_FIELD) {
138 /* end-of-frame for interlaced display */
139 event |= VENC_END_OF_FRAME;
143 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
144 layer = disp_dev->dev[i];
146 if (!vb2_start_streaming_called(&layer->buffer_queue))
149 if (layer->layer_first_int) {
150 layer->layer_first_int = 0;
153 /* Check the field format */
154 if ((V4L2_FIELD_NONE == layer->pix_fmt.field) &&
155 (event & VENC_END_OF_FRAME)) {
156 /* Progressive mode */
158 vpbe_isr_even_field(disp_dev, layer);
159 vpbe_isr_odd_field(disp_dev, layer);
161 /* Interlaced mode */
163 layer->field_id ^= 1;
164 if (event & VENC_FIRST_FIELD)
170 * If field id does not match with store
173 if (fid != layer->field_id) {
174 /* Make them in sync */
175 layer->field_id = fid;
179 * device field id and local field id are
180 * in sync. If this is even field
183 vpbe_isr_even_field(disp_dev, layer);
185 vpbe_isr_odd_field(disp_dev, layer);
193 * vpbe_buffer_prepare()
194 * This is the callback function called from vb2_qbuf() function
195 * the buffer is prepared and user space virtual address is converted into
198 static int vpbe_buffer_prepare(struct vb2_buffer *vb)
200 struct vb2_queue *q = vb->vb2_queue;
201 struct vpbe_layer *layer = vb2_get_drv_priv(q);
202 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
205 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
206 "vpbe_buffer_prepare\n");
208 vb2_set_plane_payload(vb, 0, layer->pix_fmt.sizeimage);
209 if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
212 addr = vb2_dma_contig_plane_dma_addr(vb, 0);
213 if (!IS_ALIGNED(addr, 8)) {
214 v4l2_err(&vpbe_dev->v4l2_dev,
215 "buffer_prepare:offset is not aligned to 32 bytes\n");
222 * vpbe_buffer_setup()
223 * This function allocates memory for the buffers
226 vpbe_buffer_queue_setup(struct vb2_queue *vq,
227 unsigned int *nbuffers, unsigned int *nplanes,
228 unsigned int sizes[], struct device *alloc_devs[])
231 /* Get the file handle object and layer object */
232 struct vpbe_layer *layer = vb2_get_drv_priv(vq);
233 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
235 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_buffer_setup\n");
237 /* Store number of buffers allocated in numbuffer member */
238 if (vq->num_buffers + *nbuffers < VPBE_DEFAULT_NUM_BUFS)
239 *nbuffers = VPBE_DEFAULT_NUM_BUFS - vq->num_buffers;
242 return sizes[0] < layer->pix_fmt.sizeimage ? -EINVAL : 0;
245 sizes[0] = layer->pix_fmt.sizeimage;
251 * vpbe_buffer_queue()
252 * This function adds the buffer to DMA queue
254 static void vpbe_buffer_queue(struct vb2_buffer *vb)
256 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
257 /* Get the file handle object and layer object */
258 struct vpbe_disp_buffer *buf = container_of(vbuf,
259 struct vpbe_disp_buffer, vb);
260 struct vpbe_layer *layer = vb2_get_drv_priv(vb->vb2_queue);
261 struct vpbe_display *disp = layer->disp_dev;
262 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
265 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
266 "vpbe_buffer_queue\n");
268 /* add the buffer to the DMA queue */
269 spin_lock_irqsave(&disp->dma_queue_lock, flags);
270 list_add_tail(&buf->list, &layer->dma_queue);
271 spin_unlock_irqrestore(&disp->dma_queue_lock, flags);
274 static int vpbe_start_streaming(struct vb2_queue *vq, unsigned int count)
276 struct vpbe_layer *layer = vb2_get_drv_priv(vq);
277 struct osd_state *osd_device = layer->disp_dev->osd_device;
280 osd_device->ops.disable_layer(osd_device, layer->layer_info.id);
282 /* Get the next frame from the buffer queue */
283 layer->next_frm = layer->cur_frm = list_entry(layer->dma_queue.next,
284 struct vpbe_disp_buffer, list);
285 /* Remove buffer from the buffer queue */
286 list_del(&layer->cur_frm->list);
287 /* Mark state of the current frame to active */
288 layer->cur_frm->vb.vb2_buf.state = VB2_BUF_STATE_ACTIVE;
289 /* Initialize field_id and started member */
292 /* Set parameters in OSD and VENC */
293 ret = vpbe_set_osd_display_params(layer->disp_dev, layer);
295 struct vpbe_disp_buffer *buf, *tmp;
297 vb2_buffer_done(&layer->cur_frm->vb.vb2_buf,
298 VB2_BUF_STATE_QUEUED);
299 list_for_each_entry_safe(buf, tmp, &layer->dma_queue, list) {
300 list_del(&buf->list);
301 vb2_buffer_done(&buf->vb.vb2_buf,
302 VB2_BUF_STATE_QUEUED);
309 * if request format is yuv420 semiplanar, need to
310 * enable both video windows
312 layer->layer_first_int = 1;
317 static void vpbe_stop_streaming(struct vb2_queue *vq)
319 struct vpbe_layer *layer = vb2_get_drv_priv(vq);
320 struct osd_state *osd_device = layer->disp_dev->osd_device;
321 struct vpbe_display *disp = layer->disp_dev;
324 if (!vb2_is_streaming(vq))
327 osd_device->ops.disable_layer(osd_device, layer->layer_info.id);
329 /* release all active buffers */
330 spin_lock_irqsave(&disp->dma_queue_lock, flags);
331 if (layer->cur_frm == layer->next_frm) {
332 vb2_buffer_done(&layer->cur_frm->vb.vb2_buf,
333 VB2_BUF_STATE_ERROR);
336 vb2_buffer_done(&layer->cur_frm->vb.vb2_buf,
337 VB2_BUF_STATE_ERROR);
339 vb2_buffer_done(&layer->next_frm->vb.vb2_buf,
340 VB2_BUF_STATE_ERROR);
343 while (!list_empty(&layer->dma_queue)) {
344 layer->next_frm = list_entry(layer->dma_queue.next,
345 struct vpbe_disp_buffer, list);
346 list_del(&layer->next_frm->list);
347 vb2_buffer_done(&layer->next_frm->vb.vb2_buf,
348 VB2_BUF_STATE_ERROR);
350 spin_unlock_irqrestore(&disp->dma_queue_lock, flags);
353 static const struct vb2_ops video_qops = {
354 .queue_setup = vpbe_buffer_queue_setup,
355 .wait_prepare = vb2_ops_wait_prepare,
356 .wait_finish = vb2_ops_wait_finish,
357 .buf_prepare = vpbe_buffer_prepare,
358 .start_streaming = vpbe_start_streaming,
359 .stop_streaming = vpbe_stop_streaming,
360 .buf_queue = vpbe_buffer_queue,
365 _vpbe_display_get_other_win_layer(struct vpbe_display *disp_dev,
366 struct vpbe_layer *layer)
368 enum vpbe_display_device_id thiswin, otherwin;
369 thiswin = layer->device_id;
371 otherwin = (thiswin == VPBE_DISPLAY_DEVICE_0) ?
372 VPBE_DISPLAY_DEVICE_1 : VPBE_DISPLAY_DEVICE_0;
373 return disp_dev->dev[otherwin];
376 static int vpbe_set_osd_display_params(struct vpbe_display *disp_dev,
377 struct vpbe_layer *layer)
379 struct osd_layer_config *cfg = &layer->layer_info.config;
380 struct osd_state *osd_device = disp_dev->osd_device;
381 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
385 addr = vb2_dma_contig_plane_dma_addr(&layer->cur_frm->vb.vb2_buf, 0);
386 /* Set address in the display registers */
387 osd_device->ops.start_layer(osd_device,
388 layer->layer_info.id,
390 disp_dev->cbcr_ofst);
392 ret = osd_device->ops.enable_layer(osd_device,
393 layer->layer_info.id, 0);
395 v4l2_err(&vpbe_dev->v4l2_dev,
396 "Error in enabling osd window layer 0\n");
400 /* Enable the window */
401 layer->layer_info.enable = 1;
402 if (cfg->pixfmt == PIXFMT_NV12) {
403 struct vpbe_layer *otherlayer =
404 _vpbe_display_get_other_win_layer(disp_dev, layer);
406 ret = osd_device->ops.enable_layer(osd_device,
407 otherlayer->layer_info.id, 1);
409 v4l2_err(&vpbe_dev->v4l2_dev,
410 "Error in enabling osd window layer 1\n");
413 otherlayer->layer_info.enable = 1;
419 vpbe_disp_calculate_scale_factor(struct vpbe_display *disp_dev,
420 struct vpbe_layer *layer,
421 int expected_xsize, int expected_ysize)
423 struct display_layer_info *layer_info = &layer->layer_info;
424 struct v4l2_pix_format *pixfmt = &layer->pix_fmt;
425 struct osd_layer_config *cfg = &layer->layer_info.config;
426 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
427 int calculated_xsize;
433 v4l2_std_id standard_id = vpbe_dev->current_timings.std_id;
436 * Application initially set the image format. Current display
437 * size is obtained from the vpbe display controller. expected_xsize
438 * and expected_ysize are set through S_SELECTION ioctl. Based on this,
439 * driver will calculate the scale factors for vertical and
440 * horizontal direction so that the image is displayed scaled
441 * and expanded. Application uses expansion to display the image
442 * in a square pixel. Otherwise it is displayed using displays
443 * pixel aspect ratio.It is expected that application chooses
444 * the crop coordinates for cropped or scaled display. if crop
445 * size is less than the image size, it is displayed cropped or
446 * it is displayed scaled and/or expanded.
448 * to begin with, set the crop window same as expected. Later we
449 * will override with scaled window size
452 cfg->xsize = pixfmt->width;
453 cfg->ysize = pixfmt->height;
454 layer_info->h_zoom = ZOOM_X1; /* no horizontal zoom */
455 layer_info->v_zoom = ZOOM_X1; /* no horizontal zoom */
456 layer_info->h_exp = H_EXP_OFF; /* no horizontal zoom */
457 layer_info->v_exp = V_EXP_OFF; /* no horizontal zoom */
459 if (pixfmt->width < expected_xsize) {
460 h_scale = vpbe_dev->current_timings.xres / pixfmt->width;
463 else if (h_scale >= 4)
467 cfg->xsize *= h_scale;
468 if (cfg->xsize < expected_xsize) {
469 if ((standard_id & V4L2_STD_525_60) ||
470 (standard_id & V4L2_STD_625_50)) {
471 calculated_xsize = (cfg->xsize *
472 VPBE_DISPLAY_H_EXP_RATIO_N) /
473 VPBE_DISPLAY_H_EXP_RATIO_D;
474 if (calculated_xsize <= expected_xsize) {
476 cfg->xsize = calculated_xsize;
481 layer_info->h_zoom = ZOOM_X2;
482 else if (h_scale == 4)
483 layer_info->h_zoom = ZOOM_X4;
485 layer_info->h_exp = H_EXP_9_OVER_8;
487 /* no scaling, only cropping. Set display area to crop area */
488 cfg->xsize = expected_xsize;
491 if (pixfmt->height < expected_ysize) {
492 v_scale = expected_ysize / pixfmt->height;
495 else if (v_scale >= 4)
499 cfg->ysize *= v_scale;
500 if (cfg->ysize < expected_ysize) {
501 if ((standard_id & V4L2_STD_625_50)) {
502 calculated_xsize = (cfg->ysize *
503 VPBE_DISPLAY_V_EXP_RATIO_N) /
504 VPBE_DISPLAY_V_EXP_RATIO_D;
505 if (calculated_xsize <= expected_ysize) {
507 cfg->ysize = calculated_xsize;
512 layer_info->v_zoom = ZOOM_X2;
513 else if (v_scale == 4)
514 layer_info->v_zoom = ZOOM_X4;
516 layer_info->v_exp = V_EXP_6_OVER_5;
518 /* no scaling, only cropping. Set display area to crop area */
519 cfg->ysize = expected_ysize;
521 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
522 "crop display xsize = %d, ysize = %d\n",
523 cfg->xsize, cfg->ysize);
526 static void vpbe_disp_adj_position(struct vpbe_display *disp_dev,
527 struct vpbe_layer *layer,
530 struct osd_layer_config *cfg = &layer->layer_info.config;
531 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
533 cfg->xpos = min((unsigned int)left,
534 vpbe_dev->current_timings.xres - cfg->xsize);
535 cfg->ypos = min((unsigned int)top,
536 vpbe_dev->current_timings.yres - cfg->ysize);
538 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
539 "new xpos = %d, ypos = %d\n",
540 cfg->xpos, cfg->ypos);
543 static void vpbe_disp_check_window_params(struct vpbe_display *disp_dev,
546 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
548 if ((c->width == 0) ||
549 ((c->width + c->left) > vpbe_dev->current_timings.xres))
550 c->width = vpbe_dev->current_timings.xres - c->left;
552 if ((c->height == 0) || ((c->height + c->top) >
553 vpbe_dev->current_timings.yres))
554 c->height = vpbe_dev->current_timings.yres - c->top;
556 /* window height must be even for interlaced display */
557 if (vpbe_dev->current_timings.interlaced)
558 c->height &= (~0x01);
564 * If user application provides width and height, and have bytesperline set
565 * to zero, driver calculates bytesperline and sizeimage based on hardware
568 static int vpbe_try_format(struct vpbe_display *disp_dev,
569 struct v4l2_pix_format *pixfmt, int check)
571 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
578 if ((pixfmt->pixelformat != V4L2_PIX_FMT_UYVY) &&
579 (pixfmt->pixelformat != V4L2_PIX_FMT_NV12))
580 /* choose default as V4L2_PIX_FMT_UYVY */
581 pixfmt->pixelformat = V4L2_PIX_FMT_UYVY;
583 /* Check the field format */
584 if ((pixfmt->field != V4L2_FIELD_INTERLACED) &&
585 (pixfmt->field != V4L2_FIELD_NONE)) {
586 if (vpbe_dev->current_timings.interlaced)
587 pixfmt->field = V4L2_FIELD_INTERLACED;
589 pixfmt->field = V4L2_FIELD_NONE;
592 if (pixfmt->field == V4L2_FIELD_INTERLACED)
595 if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12)
600 max_width = vpbe_dev->current_timings.xres;
601 max_height = vpbe_dev->current_timings.yres;
605 if (!pixfmt->width || (pixfmt->width < min_width) ||
606 (pixfmt->width > max_width)) {
607 pixfmt->width = vpbe_dev->current_timings.xres;
610 if (!pixfmt->height || (pixfmt->height < min_height) ||
611 (pixfmt->height > max_height)) {
612 pixfmt->height = vpbe_dev->current_timings.yres;
615 if (pixfmt->bytesperline < (pixfmt->width * bpp))
616 pixfmt->bytesperline = pixfmt->width * bpp;
618 /* Make the bytesperline 32 byte aligned */
619 pixfmt->bytesperline = ((pixfmt->width * bpp + 31) & ~31);
621 if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12)
622 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height +
623 (pixfmt->bytesperline * pixfmt->height >> 1);
625 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
630 static int vpbe_display_querycap(struct file *file, void *priv,
631 struct v4l2_capability *cap)
633 struct vpbe_layer *layer = video_drvdata(file);
634 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
636 cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
637 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
638 snprintf(cap->driver, sizeof(cap->driver), "%s",
639 dev_name(vpbe_dev->pdev));
640 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
641 dev_name(vpbe_dev->pdev));
642 strscpy(cap->card, vpbe_dev->cfg->module_name, sizeof(cap->card));
647 static int vpbe_display_s_selection(struct file *file, void *priv,
648 struct v4l2_selection *sel)
650 struct vpbe_layer *layer = video_drvdata(file);
651 struct vpbe_display *disp_dev = layer->disp_dev;
652 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
653 struct osd_layer_config *cfg = &layer->layer_info.config;
654 struct osd_state *osd_device = disp_dev->osd_device;
655 struct v4l2_rect rect = sel->r;
658 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
659 "VIDIOC_S_SELECTION, layer id = %d\n", layer->device_id);
661 if (sel->type != V4L2_BUF_TYPE_VIDEO_OUTPUT ||
662 sel->target != V4L2_SEL_TGT_CROP)
670 vpbe_disp_check_window_params(disp_dev, &rect);
672 osd_device->ops.get_layer_config(osd_device,
673 layer->layer_info.id, cfg);
675 vpbe_disp_calculate_scale_factor(disp_dev, layer,
678 vpbe_disp_adj_position(disp_dev, layer, rect.top,
680 ret = osd_device->ops.set_layer_config(osd_device,
681 layer->layer_info.id, cfg);
683 v4l2_err(&vpbe_dev->v4l2_dev,
684 "Error in set layer config:\n");
688 /* apply zooming and h or v expansion */
689 osd_device->ops.set_zoom(osd_device,
690 layer->layer_info.id,
691 layer->layer_info.h_zoom,
692 layer->layer_info.v_zoom);
693 ret = osd_device->ops.set_vid_expansion(osd_device,
694 layer->layer_info.h_exp,
695 layer->layer_info.v_exp);
697 v4l2_err(&vpbe_dev->v4l2_dev,
698 "Error in set vid expansion:\n");
702 if ((layer->layer_info.h_zoom != ZOOM_X1) ||
703 (layer->layer_info.v_zoom != ZOOM_X1) ||
704 (layer->layer_info.h_exp != H_EXP_OFF) ||
705 (layer->layer_info.v_exp != V_EXP_OFF))
706 /* Enable expansion filter */
707 osd_device->ops.set_interpolation_filter(osd_device, 1);
709 osd_device->ops.set_interpolation_filter(osd_device, 0);
715 static int vpbe_display_g_selection(struct file *file, void *priv,
716 struct v4l2_selection *sel)
718 struct vpbe_layer *layer = video_drvdata(file);
719 struct osd_layer_config *cfg = &layer->layer_info.config;
720 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
721 struct osd_state *osd_device = layer->disp_dev->osd_device;
722 struct v4l2_rect *rect = &sel->r;
724 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
725 "VIDIOC_G_SELECTION, layer id = %d\n",
728 if (sel->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
731 switch (sel->target) {
732 case V4L2_SEL_TGT_CROP:
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;
740 case V4L2_SEL_TGT_CROP_DEFAULT:
741 case V4L2_SEL_TGT_CROP_BOUNDS:
744 rect->width = vpbe_dev->current_timings.xres;
745 rect->height = vpbe_dev->current_timings.yres;
754 static int vpbe_display_g_pixelaspect(struct file *file, void *priv,
755 int type, struct v4l2_fract *f)
757 struct vpbe_layer *layer = video_drvdata(file);
758 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
760 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_CROPCAP ioctl\n");
762 if (type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
765 *f = vpbe_dev->current_timings.aspect;
769 static int vpbe_display_g_fmt(struct file *file, void *priv,
770 struct v4l2_format *fmt)
772 struct vpbe_layer *layer = video_drvdata(file);
773 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
775 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
776 "VIDIOC_G_FMT, layer id = %d\n",
779 /* If buffer type is video output */
780 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != fmt->type) {
781 v4l2_err(&vpbe_dev->v4l2_dev, "invalid type\n");
784 /* Fill in the information about format */
785 fmt->fmt.pix = layer->pix_fmt;
790 static int vpbe_display_enum_fmt(struct file *file, void *priv,
791 struct v4l2_fmtdesc *fmt)
793 struct vpbe_layer *layer = video_drvdata(file);
794 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
795 unsigned int index = 0;
797 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
798 "VIDIOC_ENUM_FMT, layer id = %d\n",
800 if (fmt->index > 1) {
801 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid format index\n");
805 /* Fill in the information about format */
807 memset(fmt, 0, sizeof(*fmt));
809 fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
811 strscpy(fmt->description, "YUV 4:2:2 - UYVY",
812 sizeof(fmt->description));
813 fmt->pixelformat = V4L2_PIX_FMT_UYVY;
815 strscpy(fmt->description, "Y/CbCr 4:2:0",
816 sizeof(fmt->description));
817 fmt->pixelformat = V4L2_PIX_FMT_NV12;
823 static int vpbe_display_s_fmt(struct file *file, void *priv,
824 struct v4l2_format *fmt)
826 struct vpbe_layer *layer = video_drvdata(file);
827 struct vpbe_display *disp_dev = layer->disp_dev;
828 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
829 struct osd_layer_config *cfg = &layer->layer_info.config;
830 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
831 struct osd_state *osd_device = disp_dev->osd_device;
834 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
835 "VIDIOC_S_FMT, layer id = %d\n",
838 if (vb2_is_busy(&layer->buffer_queue))
841 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != fmt->type) {
842 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "invalid type\n");
845 /* Check for valid pixel format */
846 ret = vpbe_try_format(disp_dev, pixfmt, 1);
850 /* YUV420 is requested, check availability of the
851 other video window */
853 layer->pix_fmt = *pixfmt;
854 if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12) {
855 struct vpbe_layer *otherlayer;
857 otherlayer = _vpbe_display_get_other_win_layer(disp_dev, layer);
858 /* if other layer is available, only
859 * claim it, do not configure it
861 ret = osd_device->ops.request_layer(osd_device,
862 otherlayer->layer_info.id);
864 v4l2_err(&vpbe_dev->v4l2_dev,
865 "Display Manager failed to allocate layer\n");
870 /* Get osd layer config */
871 osd_device->ops.get_layer_config(osd_device,
872 layer->layer_info.id, cfg);
873 /* Store the pixel format in the layer object */
874 cfg->xsize = pixfmt->width;
875 cfg->ysize = pixfmt->height;
876 cfg->line_length = pixfmt->bytesperline;
879 cfg->interlaced = vpbe_dev->current_timings.interlaced;
881 if (V4L2_PIX_FMT_UYVY == pixfmt->pixelformat)
882 cfg->pixfmt = PIXFMT_YCBCRI;
884 /* Change of the default pixel format for both video windows */
885 if (V4L2_PIX_FMT_NV12 == pixfmt->pixelformat) {
886 struct vpbe_layer *otherlayer;
887 cfg->pixfmt = PIXFMT_NV12;
888 otherlayer = _vpbe_display_get_other_win_layer(disp_dev,
890 otherlayer->layer_info.config.pixfmt = PIXFMT_NV12;
893 /* Set the layer config in the osd window */
894 ret = osd_device->ops.set_layer_config(osd_device,
895 layer->layer_info.id, cfg);
897 v4l2_err(&vpbe_dev->v4l2_dev,
898 "Error in S_FMT params:\n");
902 /* Readback and fill the local copy of current pix format */
903 osd_device->ops.get_layer_config(osd_device,
904 layer->layer_info.id, cfg);
909 static int vpbe_display_try_fmt(struct file *file, void *priv,
910 struct v4l2_format *fmt)
912 struct vpbe_layer *layer = video_drvdata(file);
913 struct vpbe_display *disp_dev = layer->disp_dev;
914 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
915 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
917 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_TRY_FMT\n");
919 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != fmt->type) {
920 v4l2_err(&vpbe_dev->v4l2_dev, "invalid type\n");
924 /* Check for valid field format */
925 return vpbe_try_format(disp_dev, pixfmt, 0);
930 * vpbe_display_s_std - Set the given standard in the encoder
932 * Sets the standard if supported by the current encoder. Return the status.
933 * 0 - success & -EINVAL on error
935 static int vpbe_display_s_std(struct file *file, void *priv,
938 struct vpbe_layer *layer = video_drvdata(file);
939 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
942 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_STD\n");
944 if (vb2_is_busy(&layer->buffer_queue))
947 if (vpbe_dev->ops.s_std) {
948 ret = vpbe_dev->ops.s_std(vpbe_dev, std_id);
950 v4l2_err(&vpbe_dev->v4l2_dev,
951 "Failed to set standard for sub devices\n");
962 * vpbe_display_g_std - Get the standard in the current encoder
964 * Get the standard in the current encoder. Return the status. 0 - success
967 static int vpbe_display_g_std(struct file *file, void *priv,
970 struct vpbe_layer *layer = video_drvdata(file);
971 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
973 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_STD\n");
975 /* Get the standard from the current encoder */
976 if (vpbe_dev->current_timings.timings_type & VPBE_ENC_STD) {
977 *std_id = vpbe_dev->current_timings.std_id;
985 * vpbe_display_enum_output - enumerate outputs
987 * Enumerates the outputs available at the vpbe display
988 * returns the status, -EINVAL if end of output list
990 static int vpbe_display_enum_output(struct file *file, void *priv,
991 struct v4l2_output *output)
993 struct vpbe_layer *layer = video_drvdata(file);
994 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
997 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_OUTPUT\n");
999 /* Enumerate outputs */
1000 if (!vpbe_dev->ops.enum_outputs)
1003 ret = vpbe_dev->ops.enum_outputs(vpbe_dev, output);
1005 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
1006 "Failed to enumerate outputs\n");
1014 * vpbe_display_s_output - Set output to
1015 * the output specified by the index
1017 static int vpbe_display_s_output(struct file *file, void *priv,
1020 struct vpbe_layer *layer = video_drvdata(file);
1021 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1024 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_OUTPUT\n");
1026 if (vb2_is_busy(&layer->buffer_queue))
1029 if (!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 (!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");
1105 if (vb2_is_busy(&layer->buffer_queue))
1108 /* Set the given standard in the encoder */
1109 if (!vpbe_dev->ops.s_dv_timings)
1112 ret = vpbe_dev->ops.s_dv_timings(vpbe_dev, timings);
1114 v4l2_err(&vpbe_dev->v4l2_dev,
1115 "Failed to set the dv timings info\n");
1123 * vpbe_display_g_dv_timings - Set the dv timings
1125 * Get the timings in the current encoder. Return the status. 0 - success
1129 vpbe_display_g_dv_timings(struct file *file, void *priv,
1130 struct v4l2_dv_timings *dv_timings)
1132 struct vpbe_layer *layer = video_drvdata(file);
1133 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1135 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_DV_TIMINGS\n");
1137 /* Get the given standard in the encoder */
1139 if (vpbe_dev->current_timings.timings_type &
1140 VPBE_ENC_DV_TIMINGS) {
1141 *dv_timings = vpbe_dev->current_timings.dv_timings;
1150 * vpbe_display_open()
1151 * It creates object of file handle structure and stores it in private_data
1152 * member of filepointer
1154 static int vpbe_display_open(struct file *file)
1156 struct vpbe_layer *layer = video_drvdata(file);
1157 struct vpbe_display *disp_dev = layer->disp_dev;
1158 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
1159 struct osd_state *osd_device = disp_dev->osd_device;
1162 /* creating context for file descriptor */
1163 err = v4l2_fh_open(file);
1165 v4l2_err(&vpbe_dev->v4l2_dev, "v4l2_fh_open failed\n");
1169 /* leaving if layer is already initialized */
1170 if (!v4l2_fh_is_singular_file(file))
1174 if (mutex_lock_interruptible(&layer->opslock))
1175 return -ERESTARTSYS;
1176 /* First claim the layer for this device */
1177 err = osd_device->ops.request_layer(osd_device,
1178 layer->layer_info.id);
1179 mutex_unlock(&layer->opslock);
1181 /* Couldn't get layer */
1182 v4l2_err(&vpbe_dev->v4l2_dev,
1183 "Display Manager failed to allocate layer\n");
1184 v4l2_fh_release(file);
1188 /* Increment layer usrs counter */
1190 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
1191 "vpbe display device opened successfully\n");
1196 * vpbe_display_release()
1197 * This function deletes buffer queue, frees the buffers and the davinci
1198 * display file * handle
1200 static int vpbe_display_release(struct file *file)
1202 struct vpbe_layer *layer = video_drvdata(file);
1203 struct osd_layer_config *cfg = &layer->layer_info.config;
1204 struct vpbe_display *disp_dev = layer->disp_dev;
1205 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
1206 struct osd_state *osd_device = disp_dev->osd_device;
1208 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_release\n");
1210 mutex_lock(&layer->opslock);
1212 osd_device->ops.disable_layer(osd_device,
1213 layer->layer_info.id);
1214 /* Decrement layer usrs counter */
1216 /* If this file handle has initialize encoder device, reset it */
1218 if (cfg->pixfmt == PIXFMT_NV12) {
1219 struct vpbe_layer *otherlayer;
1221 _vpbe_display_get_other_win_layer(disp_dev, layer);
1222 osd_device->ops.disable_layer(osd_device,
1223 otherlayer->layer_info.id);
1224 osd_device->ops.release_layer(osd_device,
1225 otherlayer->layer_info.id);
1227 osd_device->ops.disable_layer(osd_device,
1228 layer->layer_info.id);
1229 osd_device->ops.release_layer(osd_device,
1230 layer->layer_info.id);
1233 _vb2_fop_release(file, NULL);
1234 mutex_unlock(&layer->opslock);
1236 disp_dev->cbcr_ofst = 0;
1241 /* vpbe capture ioctl operations */
1242 static const struct v4l2_ioctl_ops vpbe_ioctl_ops = {
1243 .vidioc_querycap = vpbe_display_querycap,
1244 .vidioc_g_fmt_vid_out = vpbe_display_g_fmt,
1245 .vidioc_enum_fmt_vid_out = vpbe_display_enum_fmt,
1246 .vidioc_s_fmt_vid_out = vpbe_display_s_fmt,
1247 .vidioc_try_fmt_vid_out = vpbe_display_try_fmt,
1249 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1250 .vidioc_create_bufs = vb2_ioctl_create_bufs,
1251 .vidioc_querybuf = vb2_ioctl_querybuf,
1252 .vidioc_qbuf = vb2_ioctl_qbuf,
1253 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1254 .vidioc_streamon = vb2_ioctl_streamon,
1255 .vidioc_streamoff = vb2_ioctl_streamoff,
1256 .vidioc_expbuf = vb2_ioctl_expbuf,
1258 .vidioc_g_pixelaspect = vpbe_display_g_pixelaspect,
1259 .vidioc_g_selection = vpbe_display_g_selection,
1260 .vidioc_s_selection = vpbe_display_s_selection,
1262 .vidioc_s_std = vpbe_display_s_std,
1263 .vidioc_g_std = vpbe_display_g_std,
1265 .vidioc_enum_output = vpbe_display_enum_output,
1266 .vidioc_s_output = vpbe_display_s_output,
1267 .vidioc_g_output = vpbe_display_g_output,
1269 .vidioc_s_dv_timings = vpbe_display_s_dv_timings,
1270 .vidioc_g_dv_timings = vpbe_display_g_dv_timings,
1271 .vidioc_enum_dv_timings = vpbe_display_enum_dv_timings,
1274 static const struct v4l2_file_operations vpbe_fops = {
1275 .owner = THIS_MODULE,
1276 .open = vpbe_display_open,
1277 .release = vpbe_display_release,
1278 .unlocked_ioctl = video_ioctl2,
1279 .mmap = vb2_fop_mmap,
1280 .poll = vb2_fop_poll,
1283 static int vpbe_device_get(struct device *dev, void *data)
1285 struct platform_device *pdev = to_platform_device(dev);
1286 struct vpbe_display *vpbe_disp = data;
1288 if (strcmp("vpbe_controller", pdev->name) == 0)
1289 vpbe_disp->vpbe_dev = platform_get_drvdata(pdev);
1291 if (strstr(pdev->name, "vpbe-osd"))
1292 vpbe_disp->osd_device = platform_get_drvdata(pdev);
1297 static int init_vpbe_layer(int i, struct vpbe_display *disp_dev,
1298 struct platform_device *pdev)
1300 struct vpbe_layer *vpbe_display_layer = NULL;
1301 struct video_device *vbd = NULL;
1303 /* Allocate memory for four plane display objects */
1304 disp_dev->dev[i] = kzalloc(sizeof(*disp_dev->dev[i]), GFP_KERNEL);
1305 if (!disp_dev->dev[i])
1308 spin_lock_init(&disp_dev->dev[i]->irqlock);
1309 mutex_init(&disp_dev->dev[i]->opslock);
1311 /* Get the pointer to the layer object */
1312 vpbe_display_layer = disp_dev->dev[i];
1313 vbd = &vpbe_display_layer->video_dev;
1314 /* Initialize field of video device */
1315 vbd->release = video_device_release_empty;
1316 vbd->fops = &vpbe_fops;
1317 vbd->ioctl_ops = &vpbe_ioctl_ops;
1319 vbd->v4l2_dev = &disp_dev->vpbe_dev->v4l2_dev;
1320 vbd->lock = &vpbe_display_layer->opslock;
1321 vbd->vfl_dir = VFL_DIR_TX;
1323 if (disp_dev->vpbe_dev->current_timings.timings_type &
1325 vbd->tvnorms = (V4L2_STD_525_60 | V4L2_STD_625_50);
1327 snprintf(vbd->name, sizeof(vbd->name),
1328 "DaVinci_VPBE Display_DRIVER_V%d.%d.%d",
1329 (VPBE_DISPLAY_VERSION_CODE >> 16) & 0xff,
1330 (VPBE_DISPLAY_VERSION_CODE >> 8) & 0xff,
1331 (VPBE_DISPLAY_VERSION_CODE) & 0xff);
1333 vpbe_display_layer->device_id = i;
1335 vpbe_display_layer->layer_info.id =
1336 ((i == VPBE_DISPLAY_DEVICE_0) ? WIN_VID0 : WIN_VID1);
1342 static int register_device(struct vpbe_layer *vpbe_display_layer,
1343 struct vpbe_display *disp_dev,
1344 struct platform_device *pdev)
1348 v4l2_info(&disp_dev->vpbe_dev->v4l2_dev,
1349 "Trying to register VPBE display device.\n");
1350 v4l2_info(&disp_dev->vpbe_dev->v4l2_dev,
1351 "layer=%p,layer->video_dev=%p\n",
1353 &vpbe_display_layer->video_dev);
1355 vpbe_display_layer->video_dev.queue = &vpbe_display_layer->buffer_queue;
1356 err = video_register_device(&vpbe_display_layer->video_dev,
1362 vpbe_display_layer->disp_dev = disp_dev;
1363 /* set the driver data in platform device */
1364 platform_set_drvdata(pdev, disp_dev);
1365 video_set_drvdata(&vpbe_display_layer->video_dev,
1366 vpbe_display_layer);
1374 * vpbe_display_probe()
1375 * This function creates device entries by register itself to the V4L2 driver
1376 * and initializes fields of each layer objects
1378 static int vpbe_display_probe(struct platform_device *pdev)
1380 struct vpbe_display *disp_dev;
1381 struct v4l2_device *v4l2_dev;
1382 struct resource *res = NULL;
1383 struct vb2_queue *q;
1389 printk(KERN_DEBUG "vpbe_display_probe\n");
1390 /* Allocate memory for vpbe_display */
1391 disp_dev = devm_kzalloc(&pdev->dev, sizeof(*disp_dev), GFP_KERNEL);
1395 spin_lock_init(&disp_dev->dma_queue_lock);
1397 * Scan all the platform devices to find the vpbe
1398 * controller device and get the vpbe_dev object
1400 err = bus_for_each_dev(&platform_bus_type, NULL, disp_dev,
1405 v4l2_dev = &disp_dev->vpbe_dev->v4l2_dev;
1406 /* Initialize the vpbe display controller */
1407 if (disp_dev->vpbe_dev->ops.initialize) {
1408 err = disp_dev->vpbe_dev->ops.initialize(&pdev->dev,
1409 disp_dev->vpbe_dev);
1411 v4l2_err(v4l2_dev, "Error initing vpbe\n");
1417 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
1418 if (init_vpbe_layer(i, disp_dev, pdev)) {
1424 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1426 v4l2_err(v4l2_dev, "Unable to get VENC interrupt resource\n");
1432 err = devm_request_irq(&pdev->dev, irq, venc_isr, 0,
1433 VPBE_DISPLAY_DRIVER, disp_dev);
1435 v4l2_err(v4l2_dev, "VPBE IRQ request failed\n");
1439 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
1440 /* initialize vb2 queue */
1441 q = &disp_dev->dev[i]->buffer_queue;
1442 memset(q, 0, sizeof(*q));
1443 q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
1444 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
1445 q->drv_priv = disp_dev->dev[i];
1446 q->ops = &video_qops;
1447 q->mem_ops = &vb2_dma_contig_memops;
1448 q->buf_struct_size = sizeof(struct vpbe_disp_buffer);
1449 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1450 q->min_buffers_needed = 1;
1451 q->lock = &disp_dev->dev[i]->opslock;
1452 q->dev = disp_dev->vpbe_dev->pdev;
1453 err = vb2_queue_init(q);
1455 v4l2_err(v4l2_dev, "vb2_queue_init() failed\n");
1459 INIT_LIST_HEAD(&disp_dev->dev[i]->dma_queue);
1461 if (register_device(disp_dev->dev[i], disp_dev, pdev)) {
1467 v4l2_dbg(1, debug, v4l2_dev,
1468 "Successfully completed the probing of vpbe v4l2 device\n");
1473 for (k = 0; k < VPBE_DISPLAY_MAX_DEVICES; k++) {
1474 /* Unregister video device */
1475 if (disp_dev->dev[k]) {
1476 video_unregister_device(&disp_dev->dev[k]->video_dev);
1477 kfree(disp_dev->dev[k]);
1484 * vpbe_display_remove()
1485 * It un-register hardware layer from V4L2 driver
1487 static int vpbe_display_remove(struct platform_device *pdev)
1489 struct vpbe_layer *vpbe_display_layer;
1490 struct vpbe_display *disp_dev = platform_get_drvdata(pdev);
1491 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
1494 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_remove\n");
1496 /* deinitialize the vpbe display controller */
1497 if (vpbe_dev->ops.deinitialize)
1498 vpbe_dev->ops.deinitialize(&pdev->dev, vpbe_dev);
1499 /* un-register device */
1500 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
1501 /* Get the pointer to the layer object */
1502 vpbe_display_layer = disp_dev->dev[i];
1503 /* Unregister video device */
1504 video_unregister_device(&vpbe_display_layer->video_dev);
1507 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
1508 kfree(disp_dev->dev[i]);
1509 disp_dev->dev[i] = NULL;
1515 static struct platform_driver vpbe_display_driver = {
1517 .name = VPBE_DISPLAY_DRIVER,
1518 .bus = &platform_bus_type,
1520 .probe = vpbe_display_probe,
1521 .remove = vpbe_display_remove,
1524 module_platform_driver(vpbe_display_driver);
1526 MODULE_DESCRIPTION("TI DM644x/DM355/DM365 VPBE Display controller");
1527 MODULE_LICENSE("GPL");
1528 MODULE_AUTHOR("Texas Instruments");