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>
30 #ifdef CONFIG_ARCH_DAVINCI
31 #include <mach/cputype.h>
34 #include <media/v4l2-dev.h>
35 #include <media/v4l2-common.h>
36 #include <media/v4l2-ioctl.h>
37 #include <media/v4l2-device.h>
38 #include <media/davinci/vpbe_display.h>
39 #include <media/davinci/vpbe_types.h>
40 #include <media/davinci/vpbe.h>
41 #include <media/davinci/vpbe_venc.h>
42 #include <media/davinci/vpbe_osd.h>
43 #include "vpbe_venc_regs.h"
45 #define VPBE_DISPLAY_DRIVER "vpbe-v4l2"
49 #define VPBE_DEFAULT_NUM_BUFS 3
51 module_param(debug
, int, 0644);
53 static int vpbe_set_osd_display_params(struct vpbe_display
*disp_dev
,
54 struct vpbe_layer
*layer
);
56 static int venc_is_second_field(struct vpbe_display
*disp_dev
)
58 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
61 ret
= v4l2_subdev_call(vpbe_dev
->venc
,
67 v4l2_err(&vpbe_dev
->v4l2_dev
,
68 "Error in getting Field ID 0\n");
74 static void vpbe_isr_even_field(struct vpbe_display
*disp_obj
,
75 struct vpbe_layer
*layer
)
77 if (layer
->cur_frm
== layer
->next_frm
)
80 layer
->cur_frm
->vb
.vb2_buf
.timestamp
= ktime_get_ns();
81 vb2_buffer_done(&layer
->cur_frm
->vb
.vb2_buf
, VB2_BUF_STATE_DONE
);
82 /* Make cur_frm pointing to next_frm */
83 layer
->cur_frm
= layer
->next_frm
;
86 static void vpbe_isr_odd_field(struct vpbe_display
*disp_obj
,
87 struct vpbe_layer
*layer
)
89 struct osd_state
*osd_device
= disp_obj
->osd_device
;
92 spin_lock(&disp_obj
->dma_queue_lock
);
93 if (list_empty(&layer
->dma_queue
) ||
94 (layer
->cur_frm
!= layer
->next_frm
)) {
95 spin_unlock(&disp_obj
->dma_queue_lock
);
99 * one field is displayed configure
100 * the next frame if it is available
101 * otherwise hold on current frame
102 * Get next from the buffer queue
104 layer
->next_frm
= list_entry(layer
->dma_queue
.next
,
105 struct vpbe_disp_buffer
, list
);
106 /* Remove that from the buffer queue */
107 list_del(&layer
->next_frm
->list
);
108 spin_unlock(&disp_obj
->dma_queue_lock
);
109 /* Mark state of the frame to active */
110 layer
->next_frm
->vb
.vb2_buf
.state
= VB2_BUF_STATE_ACTIVE
;
111 addr
= vb2_dma_contig_plane_dma_addr(&layer
->next_frm
->vb
.vb2_buf
, 0);
112 osd_device
->ops
.start_layer(osd_device
,
113 layer
->layer_info
.id
,
115 disp_obj
->cbcr_ofst
);
118 /* interrupt service routine */
119 static irqreturn_t
venc_isr(int irq
, void *arg
)
121 struct vpbe_display
*disp_dev
= (struct vpbe_display
*)arg
;
122 struct vpbe_layer
*layer
;
123 static unsigned last_event
;
128 if (!arg
|| !disp_dev
->dev
[0])
131 if (venc_is_second_field(disp_dev
))
132 event
|= VENC_SECOND_FIELD
;
134 event
|= VENC_FIRST_FIELD
;
136 if (event
== (last_event
& ~VENC_END_OF_FRAME
)) {
138 * If the display is non-interlaced, then we need to flag the
139 * end-of-frame event at every interrupt regardless of the
140 * value of the FIDST bit. We can conclude that the display is
141 * non-interlaced if the value of the FIDST bit is unchanged
142 * from the previous interrupt.
144 event
|= VENC_END_OF_FRAME
;
145 } else if (event
== VENC_SECOND_FIELD
) {
146 /* end-of-frame for interlaced display */
147 event
|= VENC_END_OF_FRAME
;
151 for (i
= 0; i
< VPBE_DISPLAY_MAX_DEVICES
; i
++) {
152 layer
= disp_dev
->dev
[i
];
154 if (!vb2_start_streaming_called(&layer
->buffer_queue
))
157 if (layer
->layer_first_int
) {
158 layer
->layer_first_int
= 0;
161 /* Check the field format */
162 if ((V4L2_FIELD_NONE
== layer
->pix_fmt
.field
) &&
163 (event
& VENC_END_OF_FRAME
)) {
164 /* Progressive mode */
166 vpbe_isr_even_field(disp_dev
, layer
);
167 vpbe_isr_odd_field(disp_dev
, layer
);
169 /* Interlaced mode */
171 layer
->field_id
^= 1;
172 if (event
& VENC_FIRST_FIELD
)
178 * If field id does not match with store
181 if (fid
!= layer
->field_id
) {
182 /* Make them in sync */
183 layer
->field_id
= fid
;
187 * device field id and local field id are
188 * in sync. If this is even field
191 vpbe_isr_even_field(disp_dev
, layer
);
193 vpbe_isr_odd_field(disp_dev
, layer
);
201 * vpbe_buffer_prepare()
202 * This is the callback function called from vb2_qbuf() function
203 * the buffer is prepared and user space virtual address is converted into
206 static int vpbe_buffer_prepare(struct vb2_buffer
*vb
)
208 struct vb2_queue
*q
= vb
->vb2_queue
;
209 struct vpbe_layer
*layer
= vb2_get_drv_priv(q
);
210 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
213 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
214 "vpbe_buffer_prepare\n");
216 vb2_set_plane_payload(vb
, 0, layer
->pix_fmt
.sizeimage
);
217 if (vb2_get_plane_payload(vb
, 0) > vb2_plane_size(vb
, 0))
220 addr
= vb2_dma_contig_plane_dma_addr(vb
, 0);
221 if (!IS_ALIGNED(addr
, 8)) {
222 v4l2_err(&vpbe_dev
->v4l2_dev
,
223 "buffer_prepare:offset is not aligned to 32 bytes\n");
230 * vpbe_buffer_setup()
231 * This function allocates memory for the buffers
234 vpbe_buffer_queue_setup(struct vb2_queue
*vq
,
235 unsigned int *nbuffers
, unsigned int *nplanes
,
236 unsigned int sizes
[], struct device
*alloc_devs
[])
239 /* Get the file handle object and layer object */
240 struct vpbe_layer
*layer
= vb2_get_drv_priv(vq
);
241 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
243 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "vpbe_buffer_setup\n");
245 /* Store number of buffers allocated in numbuffer member */
246 if (vq
->num_buffers
+ *nbuffers
< VPBE_DEFAULT_NUM_BUFS
)
247 *nbuffers
= VPBE_DEFAULT_NUM_BUFS
- vq
->num_buffers
;
250 return sizes
[0] < layer
->pix_fmt
.sizeimage
? -EINVAL
: 0;
253 sizes
[0] = layer
->pix_fmt
.sizeimage
;
259 * vpbe_buffer_queue()
260 * This function adds the buffer to DMA queue
262 static void vpbe_buffer_queue(struct vb2_buffer
*vb
)
264 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
265 /* Get the file handle object and layer object */
266 struct vpbe_disp_buffer
*buf
= container_of(vbuf
,
267 struct vpbe_disp_buffer
, vb
);
268 struct vpbe_layer
*layer
= vb2_get_drv_priv(vb
->vb2_queue
);
269 struct vpbe_display
*disp
= layer
->disp_dev
;
270 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
273 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
274 "vpbe_buffer_queue\n");
276 /* add the buffer to the DMA queue */
277 spin_lock_irqsave(&disp
->dma_queue_lock
, flags
);
278 list_add_tail(&buf
->list
, &layer
->dma_queue
);
279 spin_unlock_irqrestore(&disp
->dma_queue_lock
, flags
);
282 static int vpbe_start_streaming(struct vb2_queue
*vq
, unsigned int count
)
284 struct vpbe_layer
*layer
= vb2_get_drv_priv(vq
);
285 struct osd_state
*osd_device
= layer
->disp_dev
->osd_device
;
288 osd_device
->ops
.disable_layer(osd_device
, layer
->layer_info
.id
);
290 /* Get the next frame from the buffer queue */
291 layer
->next_frm
= layer
->cur_frm
= list_entry(layer
->dma_queue
.next
,
292 struct vpbe_disp_buffer
, list
);
293 /* Remove buffer from the buffer queue */
294 list_del(&layer
->cur_frm
->list
);
295 /* Mark state of the current frame to active */
296 layer
->cur_frm
->vb
.vb2_buf
.state
= VB2_BUF_STATE_ACTIVE
;
297 /* Initialize field_id and started member */
300 /* Set parameters in OSD and VENC */
301 ret
= vpbe_set_osd_display_params(layer
->disp_dev
, layer
);
303 struct vpbe_disp_buffer
*buf
, *tmp
;
305 vb2_buffer_done(&layer
->cur_frm
->vb
.vb2_buf
,
306 VB2_BUF_STATE_QUEUED
);
307 list_for_each_entry_safe(buf
, tmp
, &layer
->dma_queue
, list
) {
308 list_del(&buf
->list
);
309 vb2_buffer_done(&buf
->vb
.vb2_buf
,
310 VB2_BUF_STATE_QUEUED
);
317 * if request format is yuv420 semiplanar, need to
318 * enable both video windows
320 layer
->layer_first_int
= 1;
325 static void vpbe_stop_streaming(struct vb2_queue
*vq
)
327 struct vpbe_layer
*layer
= vb2_get_drv_priv(vq
);
328 struct osd_state
*osd_device
= layer
->disp_dev
->osd_device
;
329 struct vpbe_display
*disp
= layer
->disp_dev
;
332 if (!vb2_is_streaming(vq
))
335 osd_device
->ops
.disable_layer(osd_device
, layer
->layer_info
.id
);
337 /* release all active buffers */
338 spin_lock_irqsave(&disp
->dma_queue_lock
, flags
);
339 if (layer
->cur_frm
== layer
->next_frm
) {
340 vb2_buffer_done(&layer
->cur_frm
->vb
.vb2_buf
,
341 VB2_BUF_STATE_ERROR
);
344 vb2_buffer_done(&layer
->cur_frm
->vb
.vb2_buf
,
345 VB2_BUF_STATE_ERROR
);
347 vb2_buffer_done(&layer
->next_frm
->vb
.vb2_buf
,
348 VB2_BUF_STATE_ERROR
);
351 while (!list_empty(&layer
->dma_queue
)) {
352 layer
->next_frm
= list_entry(layer
->dma_queue
.next
,
353 struct vpbe_disp_buffer
, list
);
354 list_del(&layer
->next_frm
->list
);
355 vb2_buffer_done(&layer
->next_frm
->vb
.vb2_buf
,
356 VB2_BUF_STATE_ERROR
);
358 spin_unlock_irqrestore(&disp
->dma_queue_lock
, flags
);
361 static const struct vb2_ops video_qops
= {
362 .queue_setup
= vpbe_buffer_queue_setup
,
363 .wait_prepare
= vb2_ops_wait_prepare
,
364 .wait_finish
= vb2_ops_wait_finish
,
365 .buf_prepare
= vpbe_buffer_prepare
,
366 .start_streaming
= vpbe_start_streaming
,
367 .stop_streaming
= vpbe_stop_streaming
,
368 .buf_queue
= vpbe_buffer_queue
,
373 _vpbe_display_get_other_win_layer(struct vpbe_display
*disp_dev
,
374 struct vpbe_layer
*layer
)
376 enum vpbe_display_device_id thiswin
, otherwin
;
377 thiswin
= layer
->device_id
;
379 otherwin
= (thiswin
== VPBE_DISPLAY_DEVICE_0
) ?
380 VPBE_DISPLAY_DEVICE_1
: VPBE_DISPLAY_DEVICE_0
;
381 return disp_dev
->dev
[otherwin
];
384 static int vpbe_set_osd_display_params(struct vpbe_display
*disp_dev
,
385 struct vpbe_layer
*layer
)
387 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
388 struct osd_state
*osd_device
= disp_dev
->osd_device
;
389 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
393 addr
= vb2_dma_contig_plane_dma_addr(&layer
->cur_frm
->vb
.vb2_buf
, 0);
394 /* Set address in the display registers */
395 osd_device
->ops
.start_layer(osd_device
,
396 layer
->layer_info
.id
,
398 disp_dev
->cbcr_ofst
);
400 ret
= osd_device
->ops
.enable_layer(osd_device
,
401 layer
->layer_info
.id
, 0);
403 v4l2_err(&vpbe_dev
->v4l2_dev
,
404 "Error in enabling osd window layer 0\n");
408 /* Enable the window */
409 layer
->layer_info
.enable
= 1;
410 if (cfg
->pixfmt
== PIXFMT_NV12
) {
411 struct vpbe_layer
*otherlayer
=
412 _vpbe_display_get_other_win_layer(disp_dev
, layer
);
414 ret
= osd_device
->ops
.enable_layer(osd_device
,
415 otherlayer
->layer_info
.id
, 1);
417 v4l2_err(&vpbe_dev
->v4l2_dev
,
418 "Error in enabling osd window layer 1\n");
421 otherlayer
->layer_info
.enable
= 1;
427 vpbe_disp_calculate_scale_factor(struct vpbe_display
*disp_dev
,
428 struct vpbe_layer
*layer
,
429 int expected_xsize
, int expected_ysize
)
431 struct display_layer_info
*layer_info
= &layer
->layer_info
;
432 struct v4l2_pix_format
*pixfmt
= &layer
->pix_fmt
;
433 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
434 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
435 int calculated_xsize
;
441 v4l2_std_id standard_id
= vpbe_dev
->current_timings
.std_id
;
444 * Application initially set the image format. Current display
445 * size is obtained from the vpbe display controller. expected_xsize
446 * and expected_ysize are set through S_SELECTION ioctl. Based on this,
447 * driver will calculate the scale factors for vertical and
448 * horizontal direction so that the image is displayed scaled
449 * and expanded. Application uses expansion to display the image
450 * in a square pixel. Otherwise it is displayed using displays
451 * pixel aspect ratio.It is expected that application chooses
452 * the crop coordinates for cropped or scaled display. if crop
453 * size is less than the image size, it is displayed cropped or
454 * it is displayed scaled and/or expanded.
456 * to begin with, set the crop window same as expected. Later we
457 * will override with scaled window size
460 cfg
->xsize
= pixfmt
->width
;
461 cfg
->ysize
= pixfmt
->height
;
462 layer_info
->h_zoom
= ZOOM_X1
; /* no horizontal zoom */
463 layer_info
->v_zoom
= ZOOM_X1
; /* no horizontal zoom */
464 layer_info
->h_exp
= H_EXP_OFF
; /* no horizontal zoom */
465 layer_info
->v_exp
= V_EXP_OFF
; /* no horizontal zoom */
467 if (pixfmt
->width
< expected_xsize
) {
468 h_scale
= vpbe_dev
->current_timings
.xres
/ pixfmt
->width
;
471 else if (h_scale
>= 4)
475 cfg
->xsize
*= h_scale
;
476 if (cfg
->xsize
< expected_xsize
) {
477 if ((standard_id
& V4L2_STD_525_60
) ||
478 (standard_id
& V4L2_STD_625_50
)) {
479 calculated_xsize
= (cfg
->xsize
*
480 VPBE_DISPLAY_H_EXP_RATIO_N
) /
481 VPBE_DISPLAY_H_EXP_RATIO_D
;
482 if (calculated_xsize
<= expected_xsize
) {
484 cfg
->xsize
= calculated_xsize
;
489 layer_info
->h_zoom
= ZOOM_X2
;
490 else if (h_scale
== 4)
491 layer_info
->h_zoom
= ZOOM_X4
;
493 layer_info
->h_exp
= H_EXP_9_OVER_8
;
495 /* no scaling, only cropping. Set display area to crop area */
496 cfg
->xsize
= expected_xsize
;
499 if (pixfmt
->height
< expected_ysize
) {
500 v_scale
= expected_ysize
/ pixfmt
->height
;
503 else if (v_scale
>= 4)
507 cfg
->ysize
*= v_scale
;
508 if (cfg
->ysize
< expected_ysize
) {
509 if ((standard_id
& V4L2_STD_625_50
)) {
510 calculated_xsize
= (cfg
->ysize
*
511 VPBE_DISPLAY_V_EXP_RATIO_N
) /
512 VPBE_DISPLAY_V_EXP_RATIO_D
;
513 if (calculated_xsize
<= expected_ysize
) {
515 cfg
->ysize
= calculated_xsize
;
520 layer_info
->v_zoom
= ZOOM_X2
;
521 else if (v_scale
== 4)
522 layer_info
->v_zoom
= ZOOM_X4
;
524 layer_info
->h_exp
= V_EXP_6_OVER_5
;
526 /* no scaling, only cropping. Set display area to crop area */
527 cfg
->ysize
= expected_ysize
;
529 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
530 "crop display xsize = %d, ysize = %d\n",
531 cfg
->xsize
, cfg
->ysize
);
534 static void vpbe_disp_adj_position(struct vpbe_display
*disp_dev
,
535 struct vpbe_layer
*layer
,
538 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
539 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
541 cfg
->xpos
= min((unsigned int)left
,
542 vpbe_dev
->current_timings
.xres
- cfg
->xsize
);
543 cfg
->ypos
= min((unsigned int)top
,
544 vpbe_dev
->current_timings
.yres
- cfg
->ysize
);
546 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
547 "new xpos = %d, ypos = %d\n",
548 cfg
->xpos
, cfg
->ypos
);
551 static void vpbe_disp_check_window_params(struct vpbe_display
*disp_dev
,
554 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
556 if ((c
->width
== 0) ||
557 ((c
->width
+ c
->left
) > vpbe_dev
->current_timings
.xres
))
558 c
->width
= vpbe_dev
->current_timings
.xres
- c
->left
;
560 if ((c
->height
== 0) || ((c
->height
+ c
->top
) >
561 vpbe_dev
->current_timings
.yres
))
562 c
->height
= vpbe_dev
->current_timings
.yres
- c
->top
;
564 /* window height must be even for interlaced display */
565 if (vpbe_dev
->current_timings
.interlaced
)
566 c
->height
&= (~0x01);
572 * If user application provides width and height, and have bytesperline set
573 * to zero, driver calculates bytesperline and sizeimage based on hardware
576 static int vpbe_try_format(struct vpbe_display
*disp_dev
,
577 struct v4l2_pix_format
*pixfmt
, int check
)
579 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
586 if ((pixfmt
->pixelformat
!= V4L2_PIX_FMT_UYVY
) &&
587 (pixfmt
->pixelformat
!= V4L2_PIX_FMT_NV12
))
588 /* choose default as V4L2_PIX_FMT_UYVY */
589 pixfmt
->pixelformat
= V4L2_PIX_FMT_UYVY
;
591 /* Check the field format */
592 if ((pixfmt
->field
!= V4L2_FIELD_INTERLACED
) &&
593 (pixfmt
->field
!= V4L2_FIELD_NONE
)) {
594 if (vpbe_dev
->current_timings
.interlaced
)
595 pixfmt
->field
= V4L2_FIELD_INTERLACED
;
597 pixfmt
->field
= V4L2_FIELD_NONE
;
600 if (pixfmt
->field
== V4L2_FIELD_INTERLACED
)
603 if (pixfmt
->pixelformat
== V4L2_PIX_FMT_NV12
)
608 max_width
= vpbe_dev
->current_timings
.xres
;
609 max_height
= vpbe_dev
->current_timings
.yres
;
613 if (!pixfmt
->width
|| (pixfmt
->width
< min_width
) ||
614 (pixfmt
->width
> max_width
)) {
615 pixfmt
->width
= vpbe_dev
->current_timings
.xres
;
618 if (!pixfmt
->height
|| (pixfmt
->height
< min_height
) ||
619 (pixfmt
->height
> max_height
)) {
620 pixfmt
->height
= vpbe_dev
->current_timings
.yres
;
623 if (pixfmt
->bytesperline
< (pixfmt
->width
* bpp
))
624 pixfmt
->bytesperline
= pixfmt
->width
* bpp
;
626 /* Make the bytesperline 32 byte aligned */
627 pixfmt
->bytesperline
= ((pixfmt
->width
* bpp
+ 31) & ~31);
629 if (pixfmt
->pixelformat
== V4L2_PIX_FMT_NV12
)
630 pixfmt
->sizeimage
= pixfmt
->bytesperline
* pixfmt
->height
+
631 (pixfmt
->bytesperline
* pixfmt
->height
>> 1);
633 pixfmt
->sizeimage
= pixfmt
->bytesperline
* pixfmt
->height
;
638 static int vpbe_display_querycap(struct file
*file
, void *priv
,
639 struct v4l2_capability
*cap
)
641 struct vpbe_layer
*layer
= video_drvdata(file
);
642 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
644 cap
->device_caps
= V4L2_CAP_VIDEO_OUTPUT
| V4L2_CAP_STREAMING
;
645 cap
->capabilities
= cap
->device_caps
| V4L2_CAP_DEVICE_CAPS
;
646 snprintf(cap
->driver
, sizeof(cap
->driver
), "%s",
647 dev_name(vpbe_dev
->pdev
));
648 snprintf(cap
->bus_info
, sizeof(cap
->bus_info
), "platform:%s",
649 dev_name(vpbe_dev
->pdev
));
650 strlcpy(cap
->card
, vpbe_dev
->cfg
->module_name
, sizeof(cap
->card
));
655 static int vpbe_display_s_selection(struct file
*file
, void *priv
,
656 struct v4l2_selection
*sel
)
658 struct vpbe_layer
*layer
= video_drvdata(file
);
659 struct vpbe_display
*disp_dev
= layer
->disp_dev
;
660 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
661 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
662 struct osd_state
*osd_device
= disp_dev
->osd_device
;
663 struct v4l2_rect rect
= sel
->r
;
666 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
667 "VIDIOC_S_SELECTION, layer id = %d\n", layer
->device_id
);
669 if (sel
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
||
670 sel
->target
!= V4L2_SEL_TGT_CROP
)
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);
723 static int vpbe_display_g_selection(struct file
*file
, void *priv
,
724 struct v4l2_selection
*sel
)
726 struct vpbe_layer
*layer
= video_drvdata(file
);
727 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
728 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
729 struct osd_state
*osd_device
= layer
->disp_dev
->osd_device
;
730 struct v4l2_rect
*rect
= &sel
->r
;
732 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
733 "VIDIOC_G_SELECTION, layer id = %d\n",
736 if (sel
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
739 switch (sel
->target
) {
740 case V4L2_SEL_TGT_CROP
:
741 osd_device
->ops
.get_layer_config(osd_device
,
742 layer
->layer_info
.id
, cfg
);
743 rect
->top
= cfg
->ypos
;
744 rect
->left
= cfg
->xpos
;
745 rect
->width
= cfg
->xsize
;
746 rect
->height
= cfg
->ysize
;
748 case V4L2_SEL_TGT_CROP_DEFAULT
:
749 case V4L2_SEL_TGT_CROP_BOUNDS
:
752 rect
->width
= vpbe_dev
->current_timings
.xres
;
753 rect
->height
= vpbe_dev
->current_timings
.yres
;
762 static int vpbe_display_cropcap(struct file
*file
, void *priv
,
763 struct v4l2_cropcap
*cropcap
)
765 struct vpbe_layer
*layer
= video_drvdata(file
);
766 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
768 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_CROPCAP ioctl\n");
770 if (cropcap
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
773 cropcap
->pixelaspect
= vpbe_dev
->current_timings
.aspect
;
777 static int vpbe_display_g_fmt(struct file
*file
, void *priv
,
778 struct v4l2_format
*fmt
)
780 struct vpbe_layer
*layer
= video_drvdata(file
);
781 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
783 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
784 "VIDIOC_G_FMT, layer id = %d\n",
787 /* If buffer type is video output */
788 if (V4L2_BUF_TYPE_VIDEO_OUTPUT
!= fmt
->type
) {
789 v4l2_err(&vpbe_dev
->v4l2_dev
, "invalid type\n");
792 /* Fill in the information about format */
793 fmt
->fmt
.pix
= layer
->pix_fmt
;
798 static int vpbe_display_enum_fmt(struct file
*file
, void *priv
,
799 struct v4l2_fmtdesc
*fmt
)
801 struct vpbe_layer
*layer
= video_drvdata(file
);
802 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
803 unsigned int index
= 0;
805 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
806 "VIDIOC_ENUM_FMT, layer id = %d\n",
808 if (fmt
->index
> 1) {
809 v4l2_err(&vpbe_dev
->v4l2_dev
, "Invalid format index\n");
813 /* Fill in the information about format */
815 memset(fmt
, 0, sizeof(*fmt
));
817 fmt
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
819 strcpy(fmt
->description
, "YUV 4:2:2 - UYVY");
820 fmt
->pixelformat
= V4L2_PIX_FMT_UYVY
;
822 strcpy(fmt
->description
, "Y/CbCr 4:2:0");
823 fmt
->pixelformat
= V4L2_PIX_FMT_NV12
;
829 static int vpbe_display_s_fmt(struct file
*file
, void *priv
,
830 struct v4l2_format
*fmt
)
832 struct vpbe_layer
*layer
= video_drvdata(file
);
833 struct vpbe_display
*disp_dev
= layer
->disp_dev
;
834 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
835 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
836 struct v4l2_pix_format
*pixfmt
= &fmt
->fmt
.pix
;
837 struct osd_state
*osd_device
= disp_dev
->osd_device
;
840 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
841 "VIDIOC_S_FMT, layer id = %d\n",
844 if (vb2_is_busy(&layer
->buffer_queue
))
847 if (V4L2_BUF_TYPE_VIDEO_OUTPUT
!= fmt
->type
) {
848 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "invalid type\n");
851 /* Check for valid pixel format */
852 ret
= vpbe_try_format(disp_dev
, pixfmt
, 1);
856 /* YUV420 is requested, check availability of the
857 other video window */
859 layer
->pix_fmt
= *pixfmt
;
860 if (pixfmt
->pixelformat
== V4L2_PIX_FMT_NV12
) {
861 struct vpbe_layer
*otherlayer
;
863 otherlayer
= _vpbe_display_get_other_win_layer(disp_dev
, layer
);
864 /* if other layer is available, only
865 * claim it, do not configure it
867 ret
= osd_device
->ops
.request_layer(osd_device
,
868 otherlayer
->layer_info
.id
);
870 v4l2_err(&vpbe_dev
->v4l2_dev
,
871 "Display Manager failed to allocate layer\n");
876 /* Get osd layer config */
877 osd_device
->ops
.get_layer_config(osd_device
,
878 layer
->layer_info
.id
, cfg
);
879 /* Store the pixel format in the layer object */
880 cfg
->xsize
= pixfmt
->width
;
881 cfg
->ysize
= pixfmt
->height
;
882 cfg
->line_length
= pixfmt
->bytesperline
;
885 cfg
->interlaced
= vpbe_dev
->current_timings
.interlaced
;
887 if (V4L2_PIX_FMT_UYVY
== pixfmt
->pixelformat
)
888 cfg
->pixfmt
= PIXFMT_YCBCRI
;
890 /* Change of the default pixel format for both video windows */
891 if (V4L2_PIX_FMT_NV12
== pixfmt
->pixelformat
) {
892 struct vpbe_layer
*otherlayer
;
893 cfg
->pixfmt
= PIXFMT_NV12
;
894 otherlayer
= _vpbe_display_get_other_win_layer(disp_dev
,
896 otherlayer
->layer_info
.config
.pixfmt
= PIXFMT_NV12
;
899 /* Set the layer config in the osd window */
900 ret
= osd_device
->ops
.set_layer_config(osd_device
,
901 layer
->layer_info
.id
, cfg
);
903 v4l2_err(&vpbe_dev
->v4l2_dev
,
904 "Error in S_FMT params:\n");
908 /* Readback and fill the local copy of current pix format */
909 osd_device
->ops
.get_layer_config(osd_device
,
910 layer
->layer_info
.id
, cfg
);
915 static int vpbe_display_try_fmt(struct file
*file
, void *priv
,
916 struct v4l2_format
*fmt
)
918 struct vpbe_layer
*layer
= video_drvdata(file
);
919 struct vpbe_display
*disp_dev
= layer
->disp_dev
;
920 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
921 struct v4l2_pix_format
*pixfmt
= &fmt
->fmt
.pix
;
923 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_TRY_FMT\n");
925 if (V4L2_BUF_TYPE_VIDEO_OUTPUT
!= fmt
->type
) {
926 v4l2_err(&vpbe_dev
->v4l2_dev
, "invalid type\n");
930 /* Check for valid field format */
931 return vpbe_try_format(disp_dev
, pixfmt
, 0);
936 * vpbe_display_s_std - Set the given standard in the encoder
938 * Sets the standard if supported by the current encoder. Return the status.
939 * 0 - success & -EINVAL on error
941 static int vpbe_display_s_std(struct file
*file
, void *priv
,
944 struct vpbe_layer
*layer
= video_drvdata(file
);
945 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
948 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_S_STD\n");
950 if (vb2_is_busy(&layer
->buffer_queue
))
953 if (vpbe_dev
->ops
.s_std
) {
954 ret
= vpbe_dev
->ops
.s_std(vpbe_dev
, std_id
);
956 v4l2_err(&vpbe_dev
->v4l2_dev
,
957 "Failed to set standard for sub devices\n");
968 * vpbe_display_g_std - Get the standard in the current encoder
970 * Get the standard in the current encoder. Return the status. 0 - success
973 static int vpbe_display_g_std(struct file
*file
, void *priv
,
976 struct vpbe_layer
*layer
= video_drvdata(file
);
977 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
979 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_G_STD\n");
981 /* Get the standard from the current encoder */
982 if (vpbe_dev
->current_timings
.timings_type
& VPBE_ENC_STD
) {
983 *std_id
= vpbe_dev
->current_timings
.std_id
;
991 * vpbe_display_enum_output - enumerate outputs
993 * Enumerates the outputs available at the vpbe display
994 * returns the status, -EINVAL if end of output list
996 static int vpbe_display_enum_output(struct file
*file
, void *priv
,
997 struct v4l2_output
*output
)
999 struct vpbe_layer
*layer
= video_drvdata(file
);
1000 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
1003 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_ENUM_OUTPUT\n");
1005 /* Enumerate outputs */
1006 if (!vpbe_dev
->ops
.enum_outputs
)
1009 ret
= vpbe_dev
->ops
.enum_outputs(vpbe_dev
, output
);
1011 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
1012 "Failed to enumerate outputs\n");
1020 * vpbe_display_s_output - Set output to
1021 * the output specified by the index
1023 static int vpbe_display_s_output(struct file
*file
, void *priv
,
1026 struct vpbe_layer
*layer
= video_drvdata(file
);
1027 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
1030 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_S_OUTPUT\n");
1032 if (vb2_is_busy(&layer
->buffer_queue
))
1035 if (!vpbe_dev
->ops
.set_output
)
1038 ret
= vpbe_dev
->ops
.set_output(vpbe_dev
, i
);
1040 v4l2_err(&vpbe_dev
->v4l2_dev
,
1041 "Failed to set output for sub devices\n");
1049 * vpbe_display_g_output - Get output from subdevice
1050 * for a given by the index
1052 static int vpbe_display_g_output(struct file
*file
, void *priv
,
1055 struct vpbe_layer
*layer
= video_drvdata(file
);
1056 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
1058 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_G_OUTPUT\n");
1059 /* Get the standard from the current encoder */
1060 *i
= vpbe_dev
->current_out_index
;
1066 * vpbe_display_enum_dv_timings - Enumerate the dv timings
1068 * enum the timings in the current encoder. Return the status. 0 - success
1072 vpbe_display_enum_dv_timings(struct file
*file
, void *priv
,
1073 struct v4l2_enum_dv_timings
*timings
)
1075 struct vpbe_layer
*layer
= video_drvdata(file
);
1076 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
1079 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_ENUM_DV_TIMINGS\n");
1081 /* Enumerate outputs */
1082 if (!vpbe_dev
->ops
.enum_dv_timings
)
1085 ret
= vpbe_dev
->ops
.enum_dv_timings(vpbe_dev
, timings
);
1087 v4l2_err(&vpbe_dev
->v4l2_dev
,
1088 "Failed to enumerate dv timings info\n");
1096 * vpbe_display_s_dv_timings - Set the dv timings
1098 * Set the timings in the current encoder. Return the status. 0 - success
1102 vpbe_display_s_dv_timings(struct file
*file
, void *priv
,
1103 struct v4l2_dv_timings
*timings
)
1105 struct vpbe_layer
*layer
= video_drvdata(file
);
1106 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
1109 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_S_DV_TIMINGS\n");
1111 if (vb2_is_busy(&layer
->buffer_queue
))
1114 /* Set the given standard in the encoder */
1115 if (!vpbe_dev
->ops
.s_dv_timings
)
1118 ret
= vpbe_dev
->ops
.s_dv_timings(vpbe_dev
, timings
);
1120 v4l2_err(&vpbe_dev
->v4l2_dev
,
1121 "Failed to set the dv timings info\n");
1129 * vpbe_display_g_dv_timings - Set the dv timings
1131 * Get the timings in the current encoder. Return the status. 0 - success
1135 vpbe_display_g_dv_timings(struct file
*file
, void *priv
,
1136 struct v4l2_dv_timings
*dv_timings
)
1138 struct vpbe_layer
*layer
= video_drvdata(file
);
1139 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
1141 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_G_DV_TIMINGS\n");
1143 /* Get the given standard in the encoder */
1145 if (vpbe_dev
->current_timings
.timings_type
&
1146 VPBE_ENC_DV_TIMINGS
) {
1147 *dv_timings
= vpbe_dev
->current_timings
.dv_timings
;
1156 * vpbe_display_open()
1157 * It creates object of file handle structure and stores it in private_data
1158 * member of filepointer
1160 static int vpbe_display_open(struct file
*file
)
1162 struct vpbe_layer
*layer
= video_drvdata(file
);
1163 struct vpbe_display
*disp_dev
= layer
->disp_dev
;
1164 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
1165 struct osd_state
*osd_device
= disp_dev
->osd_device
;
1168 /* creating context for file descriptor */
1169 err
= v4l2_fh_open(file
);
1171 v4l2_err(&vpbe_dev
->v4l2_dev
, "v4l2_fh_open failed\n");
1175 /* leaving if layer is already initialized */
1176 if (!v4l2_fh_is_singular_file(file
))
1180 if (mutex_lock_interruptible(&layer
->opslock
))
1181 return -ERESTARTSYS
;
1182 /* First claim the layer for this device */
1183 err
= osd_device
->ops
.request_layer(osd_device
,
1184 layer
->layer_info
.id
);
1185 mutex_unlock(&layer
->opslock
);
1187 /* Couldn't get layer */
1188 v4l2_err(&vpbe_dev
->v4l2_dev
,
1189 "Display Manager failed to allocate layer\n");
1190 v4l2_fh_release(file
);
1194 /* Increment layer usrs counter */
1196 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
1197 "vpbe display device opened successfully\n");
1202 * vpbe_display_release()
1203 * This function deletes buffer queue, frees the buffers and the davinci
1204 * display file * handle
1206 static int vpbe_display_release(struct file
*file
)
1208 struct vpbe_layer
*layer
= video_drvdata(file
);
1209 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
1210 struct vpbe_display
*disp_dev
= layer
->disp_dev
;
1211 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
1212 struct osd_state
*osd_device
= disp_dev
->osd_device
;
1214 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "vpbe_display_release\n");
1216 mutex_lock(&layer
->opslock
);
1218 osd_device
->ops
.disable_layer(osd_device
,
1219 layer
->layer_info
.id
);
1220 /* Decrement layer usrs counter */
1222 /* If this file handle has initialize encoder device, reset it */
1224 if (cfg
->pixfmt
== PIXFMT_NV12
) {
1225 struct vpbe_layer
*otherlayer
;
1227 _vpbe_display_get_other_win_layer(disp_dev
, layer
);
1228 osd_device
->ops
.disable_layer(osd_device
,
1229 otherlayer
->layer_info
.id
);
1230 osd_device
->ops
.release_layer(osd_device
,
1231 otherlayer
->layer_info
.id
);
1233 osd_device
->ops
.disable_layer(osd_device
,
1234 layer
->layer_info
.id
);
1235 osd_device
->ops
.release_layer(osd_device
,
1236 layer
->layer_info
.id
);
1239 _vb2_fop_release(file
, NULL
);
1240 mutex_unlock(&layer
->opslock
);
1242 disp_dev
->cbcr_ofst
= 0;
1247 /* vpbe capture ioctl operations */
1248 static const struct v4l2_ioctl_ops vpbe_ioctl_ops
= {
1249 .vidioc_querycap
= vpbe_display_querycap
,
1250 .vidioc_g_fmt_vid_out
= vpbe_display_g_fmt
,
1251 .vidioc_enum_fmt_vid_out
= vpbe_display_enum_fmt
,
1252 .vidioc_s_fmt_vid_out
= vpbe_display_s_fmt
,
1253 .vidioc_try_fmt_vid_out
= vpbe_display_try_fmt
,
1255 .vidioc_reqbufs
= vb2_ioctl_reqbufs
,
1256 .vidioc_create_bufs
= vb2_ioctl_create_bufs
,
1257 .vidioc_querybuf
= vb2_ioctl_querybuf
,
1258 .vidioc_qbuf
= vb2_ioctl_qbuf
,
1259 .vidioc_dqbuf
= vb2_ioctl_dqbuf
,
1260 .vidioc_streamon
= vb2_ioctl_streamon
,
1261 .vidioc_streamoff
= vb2_ioctl_streamoff
,
1262 .vidioc_expbuf
= vb2_ioctl_expbuf
,
1264 .vidioc_cropcap
= vpbe_display_cropcap
,
1265 .vidioc_g_selection
= vpbe_display_g_selection
,
1266 .vidioc_s_selection
= vpbe_display_s_selection
,
1268 .vidioc_s_std
= vpbe_display_s_std
,
1269 .vidioc_g_std
= vpbe_display_g_std
,
1271 .vidioc_enum_output
= vpbe_display_enum_output
,
1272 .vidioc_s_output
= vpbe_display_s_output
,
1273 .vidioc_g_output
= vpbe_display_g_output
,
1275 .vidioc_s_dv_timings
= vpbe_display_s_dv_timings
,
1276 .vidioc_g_dv_timings
= vpbe_display_g_dv_timings
,
1277 .vidioc_enum_dv_timings
= vpbe_display_enum_dv_timings
,
1280 static const struct v4l2_file_operations vpbe_fops
= {
1281 .owner
= THIS_MODULE
,
1282 .open
= vpbe_display_open
,
1283 .release
= vpbe_display_release
,
1284 .unlocked_ioctl
= video_ioctl2
,
1285 .mmap
= vb2_fop_mmap
,
1286 .poll
= vb2_fop_poll
,
1289 static int vpbe_device_get(struct device
*dev
, void *data
)
1291 struct platform_device
*pdev
= to_platform_device(dev
);
1292 struct vpbe_display
*vpbe_disp
= data
;
1294 if (strcmp("vpbe_controller", pdev
->name
) == 0)
1295 vpbe_disp
->vpbe_dev
= platform_get_drvdata(pdev
);
1297 if (strstr(pdev
->name
, "vpbe-osd"))
1298 vpbe_disp
->osd_device
= platform_get_drvdata(pdev
);
1303 static int init_vpbe_layer(int i
, struct vpbe_display
*disp_dev
,
1304 struct platform_device
*pdev
)
1306 struct vpbe_layer
*vpbe_display_layer
= NULL
;
1307 struct video_device
*vbd
= NULL
;
1309 /* Allocate memory for four plane display objects */
1310 disp_dev
->dev
[i
] = kzalloc(sizeof(*disp_dev
->dev
[i
]), GFP_KERNEL
);
1311 if (!disp_dev
->dev
[i
])
1314 spin_lock_init(&disp_dev
->dev
[i
]->irqlock
);
1315 mutex_init(&disp_dev
->dev
[i
]->opslock
);
1317 /* Get the pointer to the layer object */
1318 vpbe_display_layer
= disp_dev
->dev
[i
];
1319 vbd
= &vpbe_display_layer
->video_dev
;
1320 /* Initialize field of video device */
1321 vbd
->release
= video_device_release_empty
;
1322 vbd
->fops
= &vpbe_fops
;
1323 vbd
->ioctl_ops
= &vpbe_ioctl_ops
;
1325 vbd
->v4l2_dev
= &disp_dev
->vpbe_dev
->v4l2_dev
;
1326 vbd
->lock
= &vpbe_display_layer
->opslock
;
1327 vbd
->vfl_dir
= VFL_DIR_TX
;
1329 if (disp_dev
->vpbe_dev
->current_timings
.timings_type
&
1331 vbd
->tvnorms
= (V4L2_STD_525_60
| V4L2_STD_625_50
);
1333 snprintf(vbd
->name
, sizeof(vbd
->name
),
1334 "DaVinci_VPBE Display_DRIVER_V%d.%d.%d",
1335 (VPBE_DISPLAY_VERSION_CODE
>> 16) & 0xff,
1336 (VPBE_DISPLAY_VERSION_CODE
>> 8) & 0xff,
1337 (VPBE_DISPLAY_VERSION_CODE
) & 0xff);
1339 vpbe_display_layer
->device_id
= i
;
1341 vpbe_display_layer
->layer_info
.id
=
1342 ((i
== VPBE_DISPLAY_DEVICE_0
) ? WIN_VID0
: WIN_VID1
);
1348 static int register_device(struct vpbe_layer
*vpbe_display_layer
,
1349 struct vpbe_display
*disp_dev
,
1350 struct platform_device
*pdev
)
1354 v4l2_info(&disp_dev
->vpbe_dev
->v4l2_dev
,
1355 "Trying to register VPBE display device.\n");
1356 v4l2_info(&disp_dev
->vpbe_dev
->v4l2_dev
,
1357 "layer=%p,layer->video_dev=%p\n",
1359 &vpbe_display_layer
->video_dev
);
1361 vpbe_display_layer
->video_dev
.queue
= &vpbe_display_layer
->buffer_queue
;
1362 err
= video_register_device(&vpbe_display_layer
->video_dev
,
1368 vpbe_display_layer
->disp_dev
= disp_dev
;
1369 /* set the driver data in platform device */
1370 platform_set_drvdata(pdev
, disp_dev
);
1371 video_set_drvdata(&vpbe_display_layer
->video_dev
,
1372 vpbe_display_layer
);
1380 * vpbe_display_probe()
1381 * This function creates device entries by register itself to the V4L2 driver
1382 * and initializes fields of each layer objects
1384 static int vpbe_display_probe(struct platform_device
*pdev
)
1386 struct vpbe_display
*disp_dev
;
1387 struct v4l2_device
*v4l2_dev
;
1388 struct resource
*res
= NULL
;
1389 struct vb2_queue
*q
;
1395 printk(KERN_DEBUG
"vpbe_display_probe\n");
1396 /* Allocate memory for vpbe_display */
1397 disp_dev
= devm_kzalloc(&pdev
->dev
, sizeof(*disp_dev
), GFP_KERNEL
);
1401 spin_lock_init(&disp_dev
->dma_queue_lock
);
1403 * Scan all the platform devices to find the vpbe
1404 * controller device and get the vpbe_dev object
1406 err
= bus_for_each_dev(&platform_bus_type
, NULL
, disp_dev
,
1411 v4l2_dev
= &disp_dev
->vpbe_dev
->v4l2_dev
;
1412 /* Initialize the vpbe display controller */
1413 if (disp_dev
->vpbe_dev
->ops
.initialize
) {
1414 err
= disp_dev
->vpbe_dev
->ops
.initialize(&pdev
->dev
,
1415 disp_dev
->vpbe_dev
);
1417 v4l2_err(v4l2_dev
, "Error initing vpbe\n");
1423 for (i
= 0; i
< VPBE_DISPLAY_MAX_DEVICES
; i
++) {
1424 if (init_vpbe_layer(i
, disp_dev
, pdev
)) {
1430 res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
1432 v4l2_err(v4l2_dev
, "Unable to get VENC interrupt resource\n");
1438 err
= devm_request_irq(&pdev
->dev
, irq
, venc_isr
, 0,
1439 VPBE_DISPLAY_DRIVER
, disp_dev
);
1441 v4l2_err(v4l2_dev
, "VPBE IRQ request failed\n");
1445 for (i
= 0; i
< VPBE_DISPLAY_MAX_DEVICES
; i
++) {
1446 /* initialize vb2 queue */
1447 q
= &disp_dev
->dev
[i
]->buffer_queue
;
1448 memset(q
, 0, sizeof(*q
));
1449 q
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
1450 q
->io_modes
= VB2_MMAP
| VB2_USERPTR
| VB2_DMABUF
;
1451 q
->drv_priv
= disp_dev
->dev
[i
];
1452 q
->ops
= &video_qops
;
1453 q
->mem_ops
= &vb2_dma_contig_memops
;
1454 q
->buf_struct_size
= sizeof(struct vpbe_disp_buffer
);
1455 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1456 q
->min_buffers_needed
= 1;
1457 q
->lock
= &disp_dev
->dev
[i
]->opslock
;
1458 q
->dev
= disp_dev
->vpbe_dev
->pdev
;
1459 err
= vb2_queue_init(q
);
1461 v4l2_err(v4l2_dev
, "vb2_queue_init() failed\n");
1465 INIT_LIST_HEAD(&disp_dev
->dev
[i
]->dma_queue
);
1467 if (register_device(disp_dev
->dev
[i
], disp_dev
, pdev
)) {
1473 v4l2_dbg(1, debug
, v4l2_dev
,
1474 "Successfully completed the probing of vpbe v4l2 device\n");
1479 for (k
= 0; k
< VPBE_DISPLAY_MAX_DEVICES
; k
++) {
1480 /* Unregister video device */
1481 if (disp_dev
->dev
[k
]) {
1482 video_unregister_device(&disp_dev
->dev
[k
]->video_dev
);
1483 kfree(disp_dev
->dev
[k
]);
1490 * vpbe_display_remove()
1491 * It un-register hardware layer from V4L2 driver
1493 static int vpbe_display_remove(struct platform_device
*pdev
)
1495 struct vpbe_layer
*vpbe_display_layer
;
1496 struct vpbe_display
*disp_dev
= platform_get_drvdata(pdev
);
1497 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
1500 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "vpbe_display_remove\n");
1502 /* deinitialize the vpbe display controller */
1503 if (vpbe_dev
->ops
.deinitialize
)
1504 vpbe_dev
->ops
.deinitialize(&pdev
->dev
, vpbe_dev
);
1505 /* un-register device */
1506 for (i
= 0; i
< VPBE_DISPLAY_MAX_DEVICES
; i
++) {
1507 /* Get the pointer to the layer object */
1508 vpbe_display_layer
= disp_dev
->dev
[i
];
1509 /* Unregister video device */
1510 video_unregister_device(&vpbe_display_layer
->video_dev
);
1513 for (i
= 0; i
< VPBE_DISPLAY_MAX_DEVICES
; i
++) {
1514 kfree(disp_dev
->dev
[i
]);
1515 disp_dev
->dev
[i
] = NULL
;
1521 static struct platform_driver vpbe_display_driver
= {
1523 .name
= VPBE_DISPLAY_DRIVER
,
1524 .bus
= &platform_bus_type
,
1526 .probe
= vpbe_display_probe
,
1527 .remove
= vpbe_display_remove
,
1530 module_platform_driver(vpbe_display_driver
);
1532 MODULE_DESCRIPTION("TI DM644x/DM355/DM365 VPBE Display controller");
1533 MODULE_LICENSE("GPL");
1534 MODULE_AUTHOR("Texas Instruments");