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 layer
->cur_frm
->vb
.vb2_buf
.timestamp
= ktime_get_ns();
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
,
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 /* Store number of buffers allocated in numbuffer member */
243 if (vq
->num_buffers
+ *nbuffers
< VPBE_DEFAULT_NUM_BUFS
)
244 *nbuffers
= VPBE_DEFAULT_NUM_BUFS
- vq
->num_buffers
;
245 alloc_ctxs
[0] = layer
->alloc_ctx
;
248 return sizes
[0] < layer
->pix_fmt
.sizeimage
? -EINVAL
: 0;
251 sizes
[0] = layer
->pix_fmt
.sizeimage
;
257 * vpbe_buffer_queue()
258 * This function adds the buffer to DMA queue
260 static void vpbe_buffer_queue(struct vb2_buffer
*vb
)
262 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
263 /* Get the file handle object and layer object */
264 struct vpbe_disp_buffer
*buf
= container_of(vbuf
,
265 struct vpbe_disp_buffer
, vb
);
266 struct vpbe_layer
*layer
= vb2_get_drv_priv(vb
->vb2_queue
);
267 struct vpbe_display
*disp
= layer
->disp_dev
;
268 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
271 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
272 "vpbe_buffer_queue\n");
274 /* add the buffer to the DMA queue */
275 spin_lock_irqsave(&disp
->dma_queue_lock
, flags
);
276 list_add_tail(&buf
->list
, &layer
->dma_queue
);
277 spin_unlock_irqrestore(&disp
->dma_queue_lock
, flags
);
280 static int vpbe_start_streaming(struct vb2_queue
*vq
, unsigned int count
)
282 struct vpbe_layer
*layer
= vb2_get_drv_priv(vq
);
283 struct osd_state
*osd_device
= layer
->disp_dev
->osd_device
;
286 osd_device
->ops
.disable_layer(osd_device
, layer
->layer_info
.id
);
288 /* Get the next frame from the buffer queue */
289 layer
->next_frm
= layer
->cur_frm
= list_entry(layer
->dma_queue
.next
,
290 struct vpbe_disp_buffer
, list
);
291 /* Remove buffer from the buffer queue */
292 list_del(&layer
->cur_frm
->list
);
293 /* Mark state of the current frame to active */
294 layer
->cur_frm
->vb
.vb2_buf
.state
= VB2_BUF_STATE_ACTIVE
;
295 /* Initialize field_id and started member */
298 /* Set parameters in OSD and VENC */
299 ret
= vpbe_set_osd_display_params(layer
->disp_dev
, layer
);
301 struct vpbe_disp_buffer
*buf
, *tmp
;
303 vb2_buffer_done(&layer
->cur_frm
->vb
.vb2_buf
,
304 VB2_BUF_STATE_QUEUED
);
305 list_for_each_entry_safe(buf
, tmp
, &layer
->dma_queue
, list
) {
306 list_del(&buf
->list
);
307 vb2_buffer_done(&buf
->vb
.vb2_buf
,
308 VB2_BUF_STATE_QUEUED
);
315 * if request format is yuv420 semiplanar, need to
316 * enable both video windows
318 layer
->layer_first_int
= 1;
323 static void vpbe_stop_streaming(struct vb2_queue
*vq
)
325 struct vpbe_layer
*layer
= vb2_get_drv_priv(vq
);
326 struct osd_state
*osd_device
= layer
->disp_dev
->osd_device
;
327 struct vpbe_display
*disp
= layer
->disp_dev
;
330 if (!vb2_is_streaming(vq
))
333 osd_device
->ops
.disable_layer(osd_device
, layer
->layer_info
.id
);
335 /* release all active buffers */
336 spin_lock_irqsave(&disp
->dma_queue_lock
, flags
);
337 if (layer
->cur_frm
== layer
->next_frm
) {
338 vb2_buffer_done(&layer
->cur_frm
->vb
.vb2_buf
,
339 VB2_BUF_STATE_ERROR
);
341 if (layer
->cur_frm
!= NULL
)
342 vb2_buffer_done(&layer
->cur_frm
->vb
.vb2_buf
,
343 VB2_BUF_STATE_ERROR
);
344 if (layer
->next_frm
!= NULL
)
345 vb2_buffer_done(&layer
->next_frm
->vb
.vb2_buf
,
346 VB2_BUF_STATE_ERROR
);
349 while (!list_empty(&layer
->dma_queue
)) {
350 layer
->next_frm
= list_entry(layer
->dma_queue
.next
,
351 struct vpbe_disp_buffer
, list
);
352 list_del(&layer
->next_frm
->list
);
353 vb2_buffer_done(&layer
->next_frm
->vb
.vb2_buf
,
354 VB2_BUF_STATE_ERROR
);
356 spin_unlock_irqrestore(&disp
->dma_queue_lock
, flags
);
359 static struct vb2_ops video_qops
= {
360 .queue_setup
= vpbe_buffer_queue_setup
,
361 .wait_prepare
= vb2_ops_wait_prepare
,
362 .wait_finish
= vb2_ops_wait_finish
,
363 .buf_prepare
= vpbe_buffer_prepare
,
364 .start_streaming
= vpbe_start_streaming
,
365 .stop_streaming
= vpbe_stop_streaming
,
366 .buf_queue
= vpbe_buffer_queue
,
371 _vpbe_display_get_other_win_layer(struct vpbe_display
*disp_dev
,
372 struct vpbe_layer
*layer
)
374 enum vpbe_display_device_id thiswin
, otherwin
;
375 thiswin
= layer
->device_id
;
377 otherwin
= (thiswin
== VPBE_DISPLAY_DEVICE_0
) ?
378 VPBE_DISPLAY_DEVICE_1
: VPBE_DISPLAY_DEVICE_0
;
379 return disp_dev
->dev
[otherwin
];
382 static int vpbe_set_osd_display_params(struct vpbe_display
*disp_dev
,
383 struct vpbe_layer
*layer
)
385 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
386 struct osd_state
*osd_device
= disp_dev
->osd_device
;
387 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
391 addr
= vb2_dma_contig_plane_dma_addr(&layer
->cur_frm
->vb
.vb2_buf
, 0);
392 /* Set address in the display registers */
393 osd_device
->ops
.start_layer(osd_device
,
394 layer
->layer_info
.id
,
396 disp_dev
->cbcr_ofst
);
398 ret
= osd_device
->ops
.enable_layer(osd_device
,
399 layer
->layer_info
.id
, 0);
401 v4l2_err(&vpbe_dev
->v4l2_dev
,
402 "Error in enabling osd window layer 0\n");
406 /* Enable the window */
407 layer
->layer_info
.enable
= 1;
408 if (cfg
->pixfmt
== PIXFMT_NV12
) {
409 struct vpbe_layer
*otherlayer
=
410 _vpbe_display_get_other_win_layer(disp_dev
, layer
);
412 ret
= osd_device
->ops
.enable_layer(osd_device
,
413 otherlayer
->layer_info
.id
, 1);
415 v4l2_err(&vpbe_dev
->v4l2_dev
,
416 "Error in enabling osd window layer 1\n");
419 otherlayer
->layer_info
.enable
= 1;
425 vpbe_disp_calculate_scale_factor(struct vpbe_display
*disp_dev
,
426 struct vpbe_layer
*layer
,
427 int expected_xsize
, int expected_ysize
)
429 struct display_layer_info
*layer_info
= &layer
->layer_info
;
430 struct v4l2_pix_format
*pixfmt
= &layer
->pix_fmt
;
431 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
432 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
433 int calculated_xsize
;
439 v4l2_std_id standard_id
= vpbe_dev
->current_timings
.std_id
;
442 * Application initially set the image format. Current display
443 * size is obtained from the vpbe display controller. expected_xsize
444 * and expected_ysize are set through S_CROP ioctl. Based on this,
445 * driver will calculate the scale factors for vertical and
446 * horizontal direction so that the image is displayed scaled
447 * and expanded. Application uses expansion to display the image
448 * in a square pixel. Otherwise it is displayed using displays
449 * pixel aspect ratio.It is expected that application chooses
450 * the crop coordinates for cropped or scaled display. if crop
451 * size is less than the image size, it is displayed cropped or
452 * it is displayed scaled and/or expanded.
454 * to begin with, set the crop window same as expected. Later we
455 * will override with scaled window size
458 cfg
->xsize
= pixfmt
->width
;
459 cfg
->ysize
= pixfmt
->height
;
460 layer_info
->h_zoom
= ZOOM_X1
; /* no horizontal zoom */
461 layer_info
->v_zoom
= ZOOM_X1
; /* no horizontal zoom */
462 layer_info
->h_exp
= H_EXP_OFF
; /* no horizontal zoom */
463 layer_info
->v_exp
= V_EXP_OFF
; /* no horizontal zoom */
465 if (pixfmt
->width
< expected_xsize
) {
466 h_scale
= vpbe_dev
->current_timings
.xres
/ pixfmt
->width
;
469 else if (h_scale
>= 4)
473 cfg
->xsize
*= h_scale
;
474 if (cfg
->xsize
< expected_xsize
) {
475 if ((standard_id
& V4L2_STD_525_60
) ||
476 (standard_id
& V4L2_STD_625_50
)) {
477 calculated_xsize
= (cfg
->xsize
*
478 VPBE_DISPLAY_H_EXP_RATIO_N
) /
479 VPBE_DISPLAY_H_EXP_RATIO_D
;
480 if (calculated_xsize
<= expected_xsize
) {
482 cfg
->xsize
= calculated_xsize
;
487 layer_info
->h_zoom
= ZOOM_X2
;
488 else if (h_scale
== 4)
489 layer_info
->h_zoom
= ZOOM_X4
;
491 layer_info
->h_exp
= H_EXP_9_OVER_8
;
493 /* no scaling, only cropping. Set display area to crop area */
494 cfg
->xsize
= expected_xsize
;
497 if (pixfmt
->height
< expected_ysize
) {
498 v_scale
= expected_ysize
/ pixfmt
->height
;
501 else if (v_scale
>= 4)
505 cfg
->ysize
*= v_scale
;
506 if (cfg
->ysize
< expected_ysize
) {
507 if ((standard_id
& V4L2_STD_625_50
)) {
508 calculated_xsize
= (cfg
->ysize
*
509 VPBE_DISPLAY_V_EXP_RATIO_N
) /
510 VPBE_DISPLAY_V_EXP_RATIO_D
;
511 if (calculated_xsize
<= expected_ysize
) {
513 cfg
->ysize
= calculated_xsize
;
518 layer_info
->v_zoom
= ZOOM_X2
;
519 else if (v_scale
== 4)
520 layer_info
->v_zoom
= ZOOM_X4
;
522 layer_info
->h_exp
= V_EXP_6_OVER_5
;
524 /* no scaling, only cropping. Set display area to crop area */
525 cfg
->ysize
= expected_ysize
;
527 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
528 "crop display xsize = %d, ysize = %d\n",
529 cfg
->xsize
, cfg
->ysize
);
532 static void vpbe_disp_adj_position(struct vpbe_display
*disp_dev
,
533 struct vpbe_layer
*layer
,
536 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
537 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
539 cfg
->xpos
= min((unsigned int)left
,
540 vpbe_dev
->current_timings
.xres
- cfg
->xsize
);
541 cfg
->ypos
= min((unsigned int)top
,
542 vpbe_dev
->current_timings
.yres
- cfg
->ysize
);
544 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
545 "new xpos = %d, ypos = %d\n",
546 cfg
->xpos
, cfg
->ypos
);
549 static void vpbe_disp_check_window_params(struct vpbe_display
*disp_dev
,
552 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
554 if ((c
->width
== 0) ||
555 ((c
->width
+ c
->left
) > vpbe_dev
->current_timings
.xres
))
556 c
->width
= vpbe_dev
->current_timings
.xres
- c
->left
;
558 if ((c
->height
== 0) || ((c
->height
+ c
->top
) >
559 vpbe_dev
->current_timings
.yres
))
560 c
->height
= vpbe_dev
->current_timings
.yres
- c
->top
;
562 /* window height must be even for interlaced display */
563 if (vpbe_dev
->current_timings
.interlaced
)
564 c
->height
&= (~0x01);
570 * If user application provides width and height, and have bytesperline set
571 * to zero, driver calculates bytesperline and sizeimage based on hardware
574 static int vpbe_try_format(struct vpbe_display
*disp_dev
,
575 struct v4l2_pix_format
*pixfmt
, int check
)
577 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
584 if ((pixfmt
->pixelformat
!= V4L2_PIX_FMT_UYVY
) &&
585 (pixfmt
->pixelformat
!= V4L2_PIX_FMT_NV12
))
586 /* choose default as V4L2_PIX_FMT_UYVY */
587 pixfmt
->pixelformat
= V4L2_PIX_FMT_UYVY
;
589 /* Check the field format */
590 if ((pixfmt
->field
!= V4L2_FIELD_INTERLACED
) &&
591 (pixfmt
->field
!= V4L2_FIELD_NONE
)) {
592 if (vpbe_dev
->current_timings
.interlaced
)
593 pixfmt
->field
= V4L2_FIELD_INTERLACED
;
595 pixfmt
->field
= V4L2_FIELD_NONE
;
598 if (pixfmt
->field
== V4L2_FIELD_INTERLACED
)
601 if (pixfmt
->pixelformat
== V4L2_PIX_FMT_NV12
)
606 max_width
= vpbe_dev
->current_timings
.xres
;
607 max_height
= vpbe_dev
->current_timings
.yres
;
611 if (!pixfmt
->width
|| (pixfmt
->width
< min_width
) ||
612 (pixfmt
->width
> max_width
)) {
613 pixfmt
->width
= vpbe_dev
->current_timings
.xres
;
616 if (!pixfmt
->height
|| (pixfmt
->height
< min_height
) ||
617 (pixfmt
->height
> max_height
)) {
618 pixfmt
->height
= vpbe_dev
->current_timings
.yres
;
621 if (pixfmt
->bytesperline
< (pixfmt
->width
* bpp
))
622 pixfmt
->bytesperline
= pixfmt
->width
* bpp
;
624 /* Make the bytesperline 32 byte aligned */
625 pixfmt
->bytesperline
= ((pixfmt
->width
* bpp
+ 31) & ~31);
627 if (pixfmt
->pixelformat
== V4L2_PIX_FMT_NV12
)
628 pixfmt
->sizeimage
= pixfmt
->bytesperline
* pixfmt
->height
+
629 (pixfmt
->bytesperline
* pixfmt
->height
>> 1);
631 pixfmt
->sizeimage
= pixfmt
->bytesperline
* pixfmt
->height
;
636 static int vpbe_display_querycap(struct file
*file
, void *priv
,
637 struct v4l2_capability
*cap
)
639 struct vpbe_layer
*layer
= video_drvdata(file
);
640 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
642 cap
->device_caps
= V4L2_CAP_VIDEO_OUTPUT
| V4L2_CAP_STREAMING
;
643 cap
->capabilities
= cap
->device_caps
| V4L2_CAP_DEVICE_CAPS
;
644 snprintf(cap
->driver
, sizeof(cap
->driver
), "%s",
645 dev_name(vpbe_dev
->pdev
));
646 snprintf(cap
->bus_info
, sizeof(cap
->bus_info
), "platform:%s",
647 dev_name(vpbe_dev
->pdev
));
648 strlcpy(cap
->card
, vpbe_dev
->cfg
->module_name
, sizeof(cap
->card
));
653 static int vpbe_display_s_crop(struct file
*file
, void *priv
,
654 const struct v4l2_crop
*crop
)
656 struct vpbe_layer
*layer
= video_drvdata(file
);
657 struct vpbe_display
*disp_dev
= layer
->disp_dev
;
658 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
659 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
660 struct osd_state
*osd_device
= disp_dev
->osd_device
;
661 struct v4l2_rect rect
= crop
->c
;
664 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
665 "VIDIOC_S_CROP, layer id = %d\n", layer
->device_id
);
667 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
) {
668 v4l2_err(&vpbe_dev
->v4l2_dev
, "Invalid buf type\n");
677 vpbe_disp_check_window_params(disp_dev
, &rect
);
679 osd_device
->ops
.get_layer_config(osd_device
,
680 layer
->layer_info
.id
, cfg
);
682 vpbe_disp_calculate_scale_factor(disp_dev
, layer
,
685 vpbe_disp_adj_position(disp_dev
, layer
, rect
.top
,
687 ret
= osd_device
->ops
.set_layer_config(osd_device
,
688 layer
->layer_info
.id
, cfg
);
690 v4l2_err(&vpbe_dev
->v4l2_dev
,
691 "Error in set layer config:\n");
695 /* apply zooming and h or v expansion */
696 osd_device
->ops
.set_zoom(osd_device
,
697 layer
->layer_info
.id
,
698 layer
->layer_info
.h_zoom
,
699 layer
->layer_info
.v_zoom
);
700 ret
= osd_device
->ops
.set_vid_expansion(osd_device
,
701 layer
->layer_info
.h_exp
,
702 layer
->layer_info
.v_exp
);
704 v4l2_err(&vpbe_dev
->v4l2_dev
,
705 "Error in set vid expansion:\n");
709 if ((layer
->layer_info
.h_zoom
!= ZOOM_X1
) ||
710 (layer
->layer_info
.v_zoom
!= ZOOM_X1
) ||
711 (layer
->layer_info
.h_exp
!= H_EXP_OFF
) ||
712 (layer
->layer_info
.v_exp
!= V_EXP_OFF
))
713 /* Enable expansion filter */
714 osd_device
->ops
.set_interpolation_filter(osd_device
, 1);
716 osd_device
->ops
.set_interpolation_filter(osd_device
, 0);
721 static int vpbe_display_g_crop(struct file
*file
, void *priv
,
722 struct v4l2_crop
*crop
)
724 struct vpbe_layer
*layer
= video_drvdata(file
);
725 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
726 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
727 struct osd_state
*osd_device
= layer
->disp_dev
->osd_device
;
728 struct v4l2_rect
*rect
= &crop
->c
;
730 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
731 "VIDIOC_G_CROP, layer id = %d\n",
734 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
) {
735 v4l2_err(&vpbe_dev
->v4l2_dev
, "Invalid buf type\n");
738 osd_device
->ops
.get_layer_config(osd_device
,
739 layer
->layer_info
.id
, cfg
);
740 rect
->top
= cfg
->ypos
;
741 rect
->left
= cfg
->xpos
;
742 rect
->width
= cfg
->xsize
;
743 rect
->height
= cfg
->ysize
;
748 static int vpbe_display_cropcap(struct file
*file
, void *priv
,
749 struct v4l2_cropcap
*cropcap
)
751 struct vpbe_layer
*layer
= video_drvdata(file
);
752 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
754 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_CROPCAP ioctl\n");
756 cropcap
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
757 cropcap
->bounds
.left
= 0;
758 cropcap
->bounds
.top
= 0;
759 cropcap
->bounds
.width
= vpbe_dev
->current_timings
.xres
;
760 cropcap
->bounds
.height
= vpbe_dev
->current_timings
.yres
;
761 cropcap
->pixelaspect
= vpbe_dev
->current_timings
.aspect
;
762 cropcap
->defrect
= cropcap
->bounds
;
766 static int vpbe_display_g_fmt(struct file
*file
, void *priv
,
767 struct v4l2_format
*fmt
)
769 struct vpbe_layer
*layer
= video_drvdata(file
);
770 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
772 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
773 "VIDIOC_G_FMT, layer id = %d\n",
776 /* If buffer type is video output */
777 if (V4L2_BUF_TYPE_VIDEO_OUTPUT
!= fmt
->type
) {
778 v4l2_err(&vpbe_dev
->v4l2_dev
, "invalid type\n");
781 /* Fill in the information about format */
782 fmt
->fmt
.pix
= layer
->pix_fmt
;
787 static int vpbe_display_enum_fmt(struct file
*file
, void *priv
,
788 struct v4l2_fmtdesc
*fmt
)
790 struct vpbe_layer
*layer
= video_drvdata(file
);
791 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
792 unsigned int index
= 0;
794 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
795 "VIDIOC_ENUM_FMT, layer id = %d\n",
797 if (fmt
->index
> 1) {
798 v4l2_err(&vpbe_dev
->v4l2_dev
, "Invalid format index\n");
802 /* Fill in the information about format */
804 memset(fmt
, 0, sizeof(*fmt
));
806 fmt
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
808 strcpy(fmt
->description
, "YUV 4:2:2 - UYVY");
809 fmt
->pixelformat
= V4L2_PIX_FMT_UYVY
;
811 strcpy(fmt
->description
, "Y/CbCr 4:2:0");
812 fmt
->pixelformat
= V4L2_PIX_FMT_NV12
;
818 static int vpbe_display_s_fmt(struct file
*file
, void *priv
,
819 struct v4l2_format
*fmt
)
821 struct vpbe_layer
*layer
= video_drvdata(file
);
822 struct vpbe_display
*disp_dev
= layer
->disp_dev
;
823 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
824 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
825 struct v4l2_pix_format
*pixfmt
= &fmt
->fmt
.pix
;
826 struct osd_state
*osd_device
= disp_dev
->osd_device
;
829 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
830 "VIDIOC_S_FMT, layer id = %d\n",
833 if (vb2_is_busy(&layer
->buffer_queue
))
836 if (V4L2_BUF_TYPE_VIDEO_OUTPUT
!= fmt
->type
) {
837 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "invalid type\n");
840 /* Check for valid pixel format */
841 ret
= vpbe_try_format(disp_dev
, pixfmt
, 1);
845 /* YUV420 is requested, check availability of the
846 other video window */
848 layer
->pix_fmt
= *pixfmt
;
849 if (pixfmt
->pixelformat
== V4L2_PIX_FMT_NV12
) {
850 struct vpbe_layer
*otherlayer
;
852 otherlayer
= _vpbe_display_get_other_win_layer(disp_dev
, layer
);
853 /* if other layer is available, only
854 * claim it, do not configure it
856 ret
= osd_device
->ops
.request_layer(osd_device
,
857 otherlayer
->layer_info
.id
);
859 v4l2_err(&vpbe_dev
->v4l2_dev
,
860 "Display Manager failed to allocate layer\n");
865 /* Get osd layer config */
866 osd_device
->ops
.get_layer_config(osd_device
,
867 layer
->layer_info
.id
, cfg
);
868 /* Store the pixel format in the layer object */
869 cfg
->xsize
= pixfmt
->width
;
870 cfg
->ysize
= pixfmt
->height
;
871 cfg
->line_length
= pixfmt
->bytesperline
;
874 cfg
->interlaced
= vpbe_dev
->current_timings
.interlaced
;
876 if (V4L2_PIX_FMT_UYVY
== pixfmt
->pixelformat
)
877 cfg
->pixfmt
= PIXFMT_YCBCRI
;
879 /* Change of the default pixel format for both video windows */
880 if (V4L2_PIX_FMT_NV12
== pixfmt
->pixelformat
) {
881 struct vpbe_layer
*otherlayer
;
882 cfg
->pixfmt
= PIXFMT_NV12
;
883 otherlayer
= _vpbe_display_get_other_win_layer(disp_dev
,
885 otherlayer
->layer_info
.config
.pixfmt
= PIXFMT_NV12
;
888 /* Set the layer config in the osd window */
889 ret
= osd_device
->ops
.set_layer_config(osd_device
,
890 layer
->layer_info
.id
, cfg
);
892 v4l2_err(&vpbe_dev
->v4l2_dev
,
893 "Error in S_FMT params:\n");
897 /* Readback and fill the local copy of current pix format */
898 osd_device
->ops
.get_layer_config(osd_device
,
899 layer
->layer_info
.id
, cfg
);
904 static int vpbe_display_try_fmt(struct file
*file
, void *priv
,
905 struct v4l2_format
*fmt
)
907 struct vpbe_layer
*layer
= video_drvdata(file
);
908 struct vpbe_display
*disp_dev
= layer
->disp_dev
;
909 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
910 struct v4l2_pix_format
*pixfmt
= &fmt
->fmt
.pix
;
912 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_TRY_FMT\n");
914 if (V4L2_BUF_TYPE_VIDEO_OUTPUT
!= fmt
->type
) {
915 v4l2_err(&vpbe_dev
->v4l2_dev
, "invalid type\n");
919 /* Check for valid field format */
920 return vpbe_try_format(disp_dev
, pixfmt
, 0);
925 * vpbe_display_s_std - Set the given standard in the encoder
927 * Sets the standard if supported by the current encoder. Return the status.
928 * 0 - success & -EINVAL on error
930 static int vpbe_display_s_std(struct file
*file
, void *priv
,
933 struct vpbe_layer
*layer
= video_drvdata(file
);
934 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
937 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_S_STD\n");
939 if (vb2_is_busy(&layer
->buffer_queue
))
942 if (NULL
!= vpbe_dev
->ops
.s_std
) {
943 ret
= vpbe_dev
->ops
.s_std(vpbe_dev
, std_id
);
945 v4l2_err(&vpbe_dev
->v4l2_dev
,
946 "Failed to set standard for sub devices\n");
957 * vpbe_display_g_std - Get the standard in the current encoder
959 * Get the standard in the current encoder. Return the status. 0 - success
962 static int vpbe_display_g_std(struct file
*file
, void *priv
,
965 struct vpbe_layer
*layer
= video_drvdata(file
);
966 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
968 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_G_STD\n");
970 /* Get the standard from the current encoder */
971 if (vpbe_dev
->current_timings
.timings_type
& VPBE_ENC_STD
) {
972 *std_id
= vpbe_dev
->current_timings
.std_id
;
980 * vpbe_display_enum_output - enumerate outputs
982 * Enumerates the outputs available at the vpbe display
983 * returns the status, -EINVAL if end of output list
985 static int vpbe_display_enum_output(struct file
*file
, void *priv
,
986 struct v4l2_output
*output
)
988 struct vpbe_layer
*layer
= video_drvdata(file
);
989 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
992 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_ENUM_OUTPUT\n");
994 /* Enumerate outputs */
996 if (NULL
== vpbe_dev
->ops
.enum_outputs
)
999 ret
= vpbe_dev
->ops
.enum_outputs(vpbe_dev
, output
);
1001 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
1002 "Failed to enumerate outputs\n");
1010 * vpbe_display_s_output - Set output to
1011 * the output specified by the index
1013 static int vpbe_display_s_output(struct file
*file
, void *priv
,
1016 struct vpbe_layer
*layer
= video_drvdata(file
);
1017 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
1020 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_S_OUTPUT\n");
1022 if (vb2_is_busy(&layer
->buffer_queue
))
1025 if (NULL
== vpbe_dev
->ops
.set_output
)
1028 ret
= vpbe_dev
->ops
.set_output(vpbe_dev
, i
);
1030 v4l2_err(&vpbe_dev
->v4l2_dev
,
1031 "Failed to set output for sub devices\n");
1039 * vpbe_display_g_output - Get output from subdevice
1040 * for a given by the index
1042 static int vpbe_display_g_output(struct file
*file
, void *priv
,
1045 struct vpbe_layer
*layer
= video_drvdata(file
);
1046 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
1048 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_G_OUTPUT\n");
1049 /* Get the standard from the current encoder */
1050 *i
= vpbe_dev
->current_out_index
;
1056 * vpbe_display_enum_dv_timings - Enumerate the dv timings
1058 * enum the timings in the current encoder. Return the status. 0 - success
1062 vpbe_display_enum_dv_timings(struct file
*file
, void *priv
,
1063 struct v4l2_enum_dv_timings
*timings
)
1065 struct vpbe_layer
*layer
= video_drvdata(file
);
1066 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
1069 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_ENUM_DV_TIMINGS\n");
1071 /* Enumerate outputs */
1072 if (NULL
== vpbe_dev
->ops
.enum_dv_timings
)
1075 ret
= vpbe_dev
->ops
.enum_dv_timings(vpbe_dev
, timings
);
1077 v4l2_err(&vpbe_dev
->v4l2_dev
,
1078 "Failed to enumerate dv timings info\n");
1086 * vpbe_display_s_dv_timings - Set the dv timings
1088 * Set the timings in the current encoder. Return the status. 0 - success
1092 vpbe_display_s_dv_timings(struct file
*file
, void *priv
,
1093 struct v4l2_dv_timings
*timings
)
1095 struct vpbe_layer
*layer
= video_drvdata(file
);
1096 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
1099 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_S_DV_TIMINGS\n");
1101 if (vb2_is_busy(&layer
->buffer_queue
))
1104 /* Set the given standard in the encoder */
1105 if (!vpbe_dev
->ops
.s_dv_timings
)
1108 ret
= vpbe_dev
->ops
.s_dv_timings(vpbe_dev
, timings
);
1110 v4l2_err(&vpbe_dev
->v4l2_dev
,
1111 "Failed to set the dv timings info\n");
1119 * vpbe_display_g_dv_timings - Set the dv timings
1121 * Get the timings in the current encoder. Return the status. 0 - success
1125 vpbe_display_g_dv_timings(struct file
*file
, void *priv
,
1126 struct v4l2_dv_timings
*dv_timings
)
1128 struct vpbe_layer
*layer
= video_drvdata(file
);
1129 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
1131 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_G_DV_TIMINGS\n");
1133 /* Get the given standard in the encoder */
1135 if (vpbe_dev
->current_timings
.timings_type
&
1136 VPBE_ENC_DV_TIMINGS
) {
1137 *dv_timings
= vpbe_dev
->current_timings
.dv_timings
;
1146 * vpbe_display_open()
1147 * It creates object of file handle structure and stores it in private_data
1148 * member of filepointer
1150 static int vpbe_display_open(struct file
*file
)
1152 struct vpbe_layer
*layer
= video_drvdata(file
);
1153 struct vpbe_display
*disp_dev
= layer
->disp_dev
;
1154 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
1155 struct osd_state
*osd_device
= disp_dev
->osd_device
;
1158 /* creating context for file descriptor */
1159 err
= v4l2_fh_open(file
);
1161 v4l2_err(&vpbe_dev
->v4l2_dev
, "v4l2_fh_open failed\n");
1165 /* leaving if layer is already initialized */
1166 if (!v4l2_fh_is_singular_file(file
))
1170 if (mutex_lock_interruptible(&layer
->opslock
))
1171 return -ERESTARTSYS
;
1172 /* First claim the layer for this device */
1173 err
= osd_device
->ops
.request_layer(osd_device
,
1174 layer
->layer_info
.id
);
1175 mutex_unlock(&layer
->opslock
);
1177 /* Couldn't get layer */
1178 v4l2_err(&vpbe_dev
->v4l2_dev
,
1179 "Display Manager failed to allocate layer\n");
1180 v4l2_fh_release(file
);
1184 /* Increment layer usrs counter */
1186 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
1187 "vpbe display device opened successfully\n");
1192 * vpbe_display_release()
1193 * This function deletes buffer queue, frees the buffers and the davinci
1194 * display file * handle
1196 static int vpbe_display_release(struct file
*file
)
1198 struct vpbe_layer
*layer
= video_drvdata(file
);
1199 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
1200 struct vpbe_display
*disp_dev
= layer
->disp_dev
;
1201 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
1202 struct osd_state
*osd_device
= disp_dev
->osd_device
;
1204 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "vpbe_display_release\n");
1206 mutex_lock(&layer
->opslock
);
1208 osd_device
->ops
.disable_layer(osd_device
,
1209 layer
->layer_info
.id
);
1210 /* Decrement layer usrs counter */
1212 /* If this file handle has initialize encoder device, reset it */
1214 if (cfg
->pixfmt
== PIXFMT_NV12
) {
1215 struct vpbe_layer
*otherlayer
;
1217 _vpbe_display_get_other_win_layer(disp_dev
, layer
);
1218 osd_device
->ops
.disable_layer(osd_device
,
1219 otherlayer
->layer_info
.id
);
1220 osd_device
->ops
.release_layer(osd_device
,
1221 otherlayer
->layer_info
.id
);
1223 osd_device
->ops
.disable_layer(osd_device
,
1224 layer
->layer_info
.id
);
1225 osd_device
->ops
.release_layer(osd_device
,
1226 layer
->layer_info
.id
);
1229 _vb2_fop_release(file
, NULL
);
1230 mutex_unlock(&layer
->opslock
);
1232 disp_dev
->cbcr_ofst
= 0;
1237 /* vpbe capture ioctl operations */
1238 static const struct v4l2_ioctl_ops vpbe_ioctl_ops
= {
1239 .vidioc_querycap
= vpbe_display_querycap
,
1240 .vidioc_g_fmt_vid_out
= vpbe_display_g_fmt
,
1241 .vidioc_enum_fmt_vid_out
= vpbe_display_enum_fmt
,
1242 .vidioc_s_fmt_vid_out
= vpbe_display_s_fmt
,
1243 .vidioc_try_fmt_vid_out
= vpbe_display_try_fmt
,
1245 .vidioc_reqbufs
= vb2_ioctl_reqbufs
,
1246 .vidioc_create_bufs
= vb2_ioctl_create_bufs
,
1247 .vidioc_querybuf
= vb2_ioctl_querybuf
,
1248 .vidioc_qbuf
= vb2_ioctl_qbuf
,
1249 .vidioc_dqbuf
= vb2_ioctl_dqbuf
,
1250 .vidioc_streamon
= vb2_ioctl_streamon
,
1251 .vidioc_streamoff
= vb2_ioctl_streamoff
,
1252 .vidioc_expbuf
= vb2_ioctl_expbuf
,
1254 .vidioc_cropcap
= vpbe_display_cropcap
,
1255 .vidioc_g_crop
= vpbe_display_g_crop
,
1256 .vidioc_s_crop
= vpbe_display_s_crop
,
1258 .vidioc_s_std
= vpbe_display_s_std
,
1259 .vidioc_g_std
= vpbe_display_g_std
,
1261 .vidioc_enum_output
= vpbe_display_enum_output
,
1262 .vidioc_s_output
= vpbe_display_s_output
,
1263 .vidioc_g_output
= vpbe_display_g_output
,
1265 .vidioc_s_dv_timings
= vpbe_display_s_dv_timings
,
1266 .vidioc_g_dv_timings
= vpbe_display_g_dv_timings
,
1267 .vidioc_enum_dv_timings
= vpbe_display_enum_dv_timings
,
1270 static struct v4l2_file_operations vpbe_fops
= {
1271 .owner
= THIS_MODULE
,
1272 .open
= vpbe_display_open
,
1273 .release
= vpbe_display_release
,
1274 .unlocked_ioctl
= video_ioctl2
,
1275 .mmap
= vb2_fop_mmap
,
1276 .poll
= vb2_fop_poll
,
1279 static int vpbe_device_get(struct device
*dev
, void *data
)
1281 struct platform_device
*pdev
= to_platform_device(dev
);
1282 struct vpbe_display
*vpbe_disp
= data
;
1284 if (strcmp("vpbe_controller", pdev
->name
) == 0)
1285 vpbe_disp
->vpbe_dev
= platform_get_drvdata(pdev
);
1287 if (strstr(pdev
->name
, "vpbe-osd") != NULL
)
1288 vpbe_disp
->osd_device
= platform_get_drvdata(pdev
);
1293 static int init_vpbe_layer(int i
, struct vpbe_display
*disp_dev
,
1294 struct platform_device
*pdev
)
1296 struct vpbe_layer
*vpbe_display_layer
= NULL
;
1297 struct video_device
*vbd
= NULL
;
1299 /* Allocate memory for four plane display objects */
1302 kzalloc(sizeof(struct vpbe_layer
), GFP_KERNEL
);
1304 /* If memory allocation fails, return error */
1305 if (!disp_dev
->dev
[i
]) {
1306 printk(KERN_ERR
"ran out of memory\n");
1309 spin_lock_init(&disp_dev
->dev
[i
]->irqlock
);
1310 mutex_init(&disp_dev
->dev
[i
]->opslock
);
1312 /* Get the pointer to the layer object */
1313 vpbe_display_layer
= disp_dev
->dev
[i
];
1314 vbd
= &vpbe_display_layer
->video_dev
;
1315 /* Initialize field of video device */
1316 vbd
->release
= video_device_release_empty
;
1317 vbd
->fops
= &vpbe_fops
;
1318 vbd
->ioctl_ops
= &vpbe_ioctl_ops
;
1320 vbd
->v4l2_dev
= &disp_dev
->vpbe_dev
->v4l2_dev
;
1321 vbd
->lock
= &vpbe_display_layer
->opslock
;
1322 vbd
->vfl_dir
= VFL_DIR_TX
;
1324 if (disp_dev
->vpbe_dev
->current_timings
.timings_type
&
1326 vbd
->tvnorms
= (V4L2_STD_525_60
| V4L2_STD_625_50
);
1328 snprintf(vbd
->name
, sizeof(vbd
->name
),
1329 "DaVinci_VPBE Display_DRIVER_V%d.%d.%d",
1330 (VPBE_DISPLAY_VERSION_CODE
>> 16) & 0xff,
1331 (VPBE_DISPLAY_VERSION_CODE
>> 8) & 0xff,
1332 (VPBE_DISPLAY_VERSION_CODE
) & 0xff);
1334 vpbe_display_layer
->device_id
= i
;
1336 vpbe_display_layer
->layer_info
.id
=
1337 ((i
== VPBE_DISPLAY_DEVICE_0
) ? WIN_VID0
: WIN_VID1
);
1343 static int register_device(struct vpbe_layer
*vpbe_display_layer
,
1344 struct vpbe_display
*disp_dev
,
1345 struct platform_device
*pdev
)
1349 v4l2_info(&disp_dev
->vpbe_dev
->v4l2_dev
,
1350 "Trying to register VPBE display device.\n");
1351 v4l2_info(&disp_dev
->vpbe_dev
->v4l2_dev
,
1352 "layer=%x,layer->video_dev=%x\n",
1353 (int)vpbe_display_layer
,
1354 (int)&vpbe_display_layer
->video_dev
);
1356 vpbe_display_layer
->video_dev
.queue
= &vpbe_display_layer
->buffer_queue
;
1357 err
= video_register_device(&vpbe_display_layer
->video_dev
,
1363 vpbe_display_layer
->disp_dev
= disp_dev
;
1364 /* set the driver data in platform device */
1365 platform_set_drvdata(pdev
, disp_dev
);
1366 video_set_drvdata(&vpbe_display_layer
->video_dev
,
1367 vpbe_display_layer
);
1375 * vpbe_display_probe()
1376 * This function creates device entries by register itself to the V4L2 driver
1377 * and initializes fields of each layer objects
1379 static int vpbe_display_probe(struct platform_device
*pdev
)
1381 struct vpbe_display
*disp_dev
;
1382 struct v4l2_device
*v4l2_dev
;
1383 struct resource
*res
= NULL
;
1384 struct vb2_queue
*q
;
1390 printk(KERN_DEBUG
"vpbe_display_probe\n");
1391 /* Allocate memory for vpbe_display */
1392 disp_dev
= devm_kzalloc(&pdev
->dev
, sizeof(struct vpbe_display
),
1397 spin_lock_init(&disp_dev
->dma_queue_lock
);
1399 * Scan all the platform devices to find the vpbe
1400 * controller device and get the vpbe_dev object
1402 err
= bus_for_each_dev(&platform_bus_type
, NULL
, disp_dev
,
1407 v4l2_dev
= &disp_dev
->vpbe_dev
->v4l2_dev
;
1408 /* Initialize the vpbe display controller */
1409 if (NULL
!= disp_dev
->vpbe_dev
->ops
.initialize
) {
1410 err
= disp_dev
->vpbe_dev
->ops
.initialize(&pdev
->dev
,
1411 disp_dev
->vpbe_dev
);
1413 v4l2_err(v4l2_dev
, "Error initing vpbe\n");
1419 for (i
= 0; i
< VPBE_DISPLAY_MAX_DEVICES
; i
++) {
1420 if (init_vpbe_layer(i
, disp_dev
, pdev
)) {
1426 res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
1428 v4l2_err(v4l2_dev
, "Unable to get VENC interrupt resource\n");
1434 err
= devm_request_irq(&pdev
->dev
, irq
, venc_isr
, 0,
1435 VPBE_DISPLAY_DRIVER
, disp_dev
);
1437 v4l2_err(v4l2_dev
, "VPBE IRQ request failed\n");
1441 for (i
= 0; i
< VPBE_DISPLAY_MAX_DEVICES
; i
++) {
1442 /* initialize vb2 queue */
1443 q
= &disp_dev
->dev
[i
]->buffer_queue
;
1444 memset(q
, 0, sizeof(*q
));
1445 q
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
1446 q
->io_modes
= VB2_MMAP
| VB2_USERPTR
| VB2_DMABUF
;
1447 q
->drv_priv
= disp_dev
->dev
[i
];
1448 q
->ops
= &video_qops
;
1449 q
->mem_ops
= &vb2_dma_contig_memops
;
1450 q
->buf_struct_size
= sizeof(struct vpbe_disp_buffer
);
1451 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1452 q
->min_buffers_needed
= 1;
1453 q
->lock
= &disp_dev
->dev
[i
]->opslock
;
1454 err
= vb2_queue_init(q
);
1456 v4l2_err(v4l2_dev
, "vb2_queue_init() failed\n");
1460 disp_dev
->dev
[i
]->alloc_ctx
=
1461 vb2_dma_contig_init_ctx(disp_dev
->vpbe_dev
->pdev
);
1462 if (IS_ERR(disp_dev
->dev
[i
]->alloc_ctx
)) {
1463 v4l2_err(v4l2_dev
, "Failed to get the context\n");
1464 err
= PTR_ERR(disp_dev
->dev
[i
]->alloc_ctx
);
1468 INIT_LIST_HEAD(&disp_dev
->dev
[i
]->dma_queue
);
1470 if (register_device(disp_dev
->dev
[i
], disp_dev
, pdev
)) {
1476 v4l2_dbg(1, debug
, v4l2_dev
,
1477 "Successfully completed the probing of vpbe v4l2 device\n");
1482 for (k
= 0; k
< VPBE_DISPLAY_MAX_DEVICES
; k
++) {
1483 /* Unregister video device */
1484 if (disp_dev
->dev
[k
] != NULL
) {
1485 vb2_dma_contig_cleanup_ctx(disp_dev
->dev
[k
]->alloc_ctx
);
1486 video_unregister_device(&disp_dev
->dev
[k
]->video_dev
);
1487 kfree(disp_dev
->dev
[k
]);
1494 * vpbe_display_remove()
1495 * It un-register hardware layer from V4L2 driver
1497 static int vpbe_display_remove(struct platform_device
*pdev
)
1499 struct vpbe_layer
*vpbe_display_layer
;
1500 struct vpbe_display
*disp_dev
= platform_get_drvdata(pdev
);
1501 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
1504 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "vpbe_display_remove\n");
1506 /* deinitialize the vpbe display controller */
1507 if (NULL
!= vpbe_dev
->ops
.deinitialize
)
1508 vpbe_dev
->ops
.deinitialize(&pdev
->dev
, vpbe_dev
);
1509 /* un-register device */
1510 for (i
= 0; i
< VPBE_DISPLAY_MAX_DEVICES
; i
++) {
1511 /* Get the pointer to the layer object */
1512 vpbe_display_layer
= disp_dev
->dev
[i
];
1513 vb2_dma_contig_cleanup_ctx(vpbe_display_layer
->alloc_ctx
);
1514 /* Unregister video device */
1515 video_unregister_device(&vpbe_display_layer
->video_dev
);
1518 for (i
= 0; i
< VPBE_DISPLAY_MAX_DEVICES
; i
++) {
1519 kfree(disp_dev
->dev
[i
]);
1520 disp_dev
->dev
[i
] = NULL
;
1526 static struct platform_driver vpbe_display_driver
= {
1528 .name
= VPBE_DISPLAY_DRIVER
,
1529 .bus
= &platform_bus_type
,
1531 .probe
= vpbe_display_probe
,
1532 .remove
= vpbe_display_remove
,
1535 module_platform_driver(vpbe_display_driver
);
1537 MODULE_DESCRIPTION("TI DM644x/DM355/DM365 VPBE Display controller");
1538 MODULE_LICENSE("GPL");
1539 MODULE_AUTHOR("Texas Instruments");