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 #include <media/v4l2-dev.h>
23 #include <media/v4l2-common.h>
24 #include <media/v4l2-ioctl.h>
25 #include <media/v4l2-device.h>
26 #include <media/davinci/vpbe_display.h>
27 #include <media/davinci/vpbe_types.h>
28 #include <media/davinci/vpbe.h>
29 #include <media/davinci/vpbe_venc.h>
30 #include <media/davinci/vpbe_osd.h>
31 #include "vpbe_venc_regs.h"
33 #define VPBE_DISPLAY_DRIVER "vpbe-v4l2"
37 #define VPBE_DEFAULT_NUM_BUFS 3
39 module_param(debug
, int, 0644);
41 static int vpbe_set_osd_display_params(struct vpbe_display
*disp_dev
,
42 struct vpbe_layer
*layer
);
44 static int venc_is_second_field(struct vpbe_display
*disp_dev
)
46 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
49 ret
= v4l2_subdev_call(vpbe_dev
->venc
,
55 v4l2_err(&vpbe_dev
->v4l2_dev
,
56 "Error in getting Field ID 0\n");
62 static void vpbe_isr_even_field(struct vpbe_display
*disp_obj
,
63 struct vpbe_layer
*layer
)
65 if (layer
->cur_frm
== layer
->next_frm
)
68 layer
->cur_frm
->vb
.vb2_buf
.timestamp
= ktime_get_ns();
69 vb2_buffer_done(&layer
->cur_frm
->vb
.vb2_buf
, VB2_BUF_STATE_DONE
);
70 /* Make cur_frm pointing to next_frm */
71 layer
->cur_frm
= layer
->next_frm
;
74 static void vpbe_isr_odd_field(struct vpbe_display
*disp_obj
,
75 struct vpbe_layer
*layer
)
77 struct osd_state
*osd_device
= disp_obj
->osd_device
;
80 spin_lock(&disp_obj
->dma_queue_lock
);
81 if (list_empty(&layer
->dma_queue
) ||
82 (layer
->cur_frm
!= layer
->next_frm
)) {
83 spin_unlock(&disp_obj
->dma_queue_lock
);
87 * one field is displayed configure
88 * the next frame if it is available
89 * otherwise hold on current frame
90 * Get next from the buffer queue
92 layer
->next_frm
= list_entry(layer
->dma_queue
.next
,
93 struct vpbe_disp_buffer
, list
);
94 /* Remove that from the buffer queue */
95 list_del(&layer
->next_frm
->list
);
96 spin_unlock(&disp_obj
->dma_queue_lock
);
97 /* Mark state of the frame to active */
98 layer
->next_frm
->vb
.vb2_buf
.state
= VB2_BUF_STATE_ACTIVE
;
99 addr
= vb2_dma_contig_plane_dma_addr(&layer
->next_frm
->vb
.vb2_buf
, 0);
100 osd_device
->ops
.start_layer(osd_device
,
101 layer
->layer_info
.id
,
103 disp_obj
->cbcr_ofst
);
106 /* interrupt service routine */
107 static irqreturn_t
venc_isr(int irq
, void *arg
)
109 struct vpbe_display
*disp_dev
= (struct vpbe_display
*)arg
;
110 struct vpbe_layer
*layer
;
111 static unsigned last_event
;
116 if (!arg
|| !disp_dev
->dev
[0])
119 if (venc_is_second_field(disp_dev
))
120 event
|= VENC_SECOND_FIELD
;
122 event
|= VENC_FIRST_FIELD
;
124 if (event
== (last_event
& ~VENC_END_OF_FRAME
)) {
126 * If the display is non-interlaced, then we need to flag the
127 * end-of-frame event at every interrupt regardless of the
128 * value of the FIDST bit. We can conclude that the display is
129 * non-interlaced if the value of the FIDST bit is unchanged
130 * from the previous interrupt.
132 event
|= VENC_END_OF_FRAME
;
133 } else if (event
== VENC_SECOND_FIELD
) {
134 /* end-of-frame for interlaced display */
135 event
|= VENC_END_OF_FRAME
;
139 for (i
= 0; i
< VPBE_DISPLAY_MAX_DEVICES
; i
++) {
140 layer
= disp_dev
->dev
[i
];
142 if (!vb2_start_streaming_called(&layer
->buffer_queue
))
145 if (layer
->layer_first_int
) {
146 layer
->layer_first_int
= 0;
149 /* Check the field format */
150 if ((V4L2_FIELD_NONE
== layer
->pix_fmt
.field
) &&
151 (event
& VENC_END_OF_FRAME
)) {
152 /* Progressive mode */
154 vpbe_isr_even_field(disp_dev
, layer
);
155 vpbe_isr_odd_field(disp_dev
, layer
);
157 /* Interlaced mode */
159 layer
->field_id
^= 1;
160 if (event
& VENC_FIRST_FIELD
)
166 * If field id does not match with store
169 if (fid
!= layer
->field_id
) {
170 /* Make them in sync */
171 layer
->field_id
= fid
;
175 * device field id and local field id are
176 * in sync. If this is even field
179 vpbe_isr_even_field(disp_dev
, layer
);
181 vpbe_isr_odd_field(disp_dev
, layer
);
189 * vpbe_buffer_prepare()
190 * This is the callback function called from vb2_qbuf() function
191 * the buffer is prepared and user space virtual address is converted into
194 static int vpbe_buffer_prepare(struct vb2_buffer
*vb
)
196 struct vb2_queue
*q
= vb
->vb2_queue
;
197 struct vpbe_layer
*layer
= vb2_get_drv_priv(q
);
198 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
201 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
202 "vpbe_buffer_prepare\n");
204 vb2_set_plane_payload(vb
, 0, layer
->pix_fmt
.sizeimage
);
205 if (vb2_get_plane_payload(vb
, 0) > vb2_plane_size(vb
, 0))
208 addr
= vb2_dma_contig_plane_dma_addr(vb
, 0);
209 if (!IS_ALIGNED(addr
, 8)) {
210 v4l2_err(&vpbe_dev
->v4l2_dev
,
211 "buffer_prepare:offset is not aligned to 32 bytes\n");
218 * vpbe_buffer_setup()
219 * This function allocates memory for the buffers
222 vpbe_buffer_queue_setup(struct vb2_queue
*vq
,
223 unsigned int *nbuffers
, unsigned int *nplanes
,
224 unsigned int sizes
[], struct device
*alloc_devs
[])
227 /* Get the file handle object and layer object */
228 struct vpbe_layer
*layer
= vb2_get_drv_priv(vq
);
229 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
231 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "vpbe_buffer_setup\n");
233 /* Store number of buffers allocated in numbuffer member */
234 if (vq
->num_buffers
+ *nbuffers
< VPBE_DEFAULT_NUM_BUFS
)
235 *nbuffers
= VPBE_DEFAULT_NUM_BUFS
- vq
->num_buffers
;
238 return sizes
[0] < layer
->pix_fmt
.sizeimage
? -EINVAL
: 0;
241 sizes
[0] = layer
->pix_fmt
.sizeimage
;
247 * vpbe_buffer_queue()
248 * This function adds the buffer to DMA queue
250 static void vpbe_buffer_queue(struct vb2_buffer
*vb
)
252 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
253 /* Get the file handle object and layer object */
254 struct vpbe_disp_buffer
*buf
= container_of(vbuf
,
255 struct vpbe_disp_buffer
, vb
);
256 struct vpbe_layer
*layer
= vb2_get_drv_priv(vb
->vb2_queue
);
257 struct vpbe_display
*disp
= layer
->disp_dev
;
258 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
261 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
262 "vpbe_buffer_queue\n");
264 /* add the buffer to the DMA queue */
265 spin_lock_irqsave(&disp
->dma_queue_lock
, flags
);
266 list_add_tail(&buf
->list
, &layer
->dma_queue
);
267 spin_unlock_irqrestore(&disp
->dma_queue_lock
, flags
);
270 static int vpbe_start_streaming(struct vb2_queue
*vq
, unsigned int count
)
272 struct vpbe_layer
*layer
= vb2_get_drv_priv(vq
);
273 struct osd_state
*osd_device
= layer
->disp_dev
->osd_device
;
276 osd_device
->ops
.disable_layer(osd_device
, layer
->layer_info
.id
);
278 /* Get the next frame from the buffer queue */
279 layer
->next_frm
= layer
->cur_frm
= list_entry(layer
->dma_queue
.next
,
280 struct vpbe_disp_buffer
, list
);
281 /* Remove buffer from the buffer queue */
282 list_del(&layer
->cur_frm
->list
);
283 /* Mark state of the current frame to active */
284 layer
->cur_frm
->vb
.vb2_buf
.state
= VB2_BUF_STATE_ACTIVE
;
285 /* Initialize field_id and started member */
288 /* Set parameters in OSD and VENC */
289 ret
= vpbe_set_osd_display_params(layer
->disp_dev
, layer
);
291 struct vpbe_disp_buffer
*buf
, *tmp
;
293 vb2_buffer_done(&layer
->cur_frm
->vb
.vb2_buf
,
294 VB2_BUF_STATE_QUEUED
);
295 list_for_each_entry_safe(buf
, tmp
, &layer
->dma_queue
, list
) {
296 list_del(&buf
->list
);
297 vb2_buffer_done(&buf
->vb
.vb2_buf
,
298 VB2_BUF_STATE_QUEUED
);
305 * if request format is yuv420 semiplanar, need to
306 * enable both video windows
308 layer
->layer_first_int
= 1;
313 static void vpbe_stop_streaming(struct vb2_queue
*vq
)
315 struct vpbe_layer
*layer
= vb2_get_drv_priv(vq
);
316 struct osd_state
*osd_device
= layer
->disp_dev
->osd_device
;
317 struct vpbe_display
*disp
= layer
->disp_dev
;
320 if (!vb2_is_streaming(vq
))
323 osd_device
->ops
.disable_layer(osd_device
, layer
->layer_info
.id
);
325 /* release all active buffers */
326 spin_lock_irqsave(&disp
->dma_queue_lock
, flags
);
327 if (layer
->cur_frm
== layer
->next_frm
) {
328 vb2_buffer_done(&layer
->cur_frm
->vb
.vb2_buf
,
329 VB2_BUF_STATE_ERROR
);
332 vb2_buffer_done(&layer
->cur_frm
->vb
.vb2_buf
,
333 VB2_BUF_STATE_ERROR
);
335 vb2_buffer_done(&layer
->next_frm
->vb
.vb2_buf
,
336 VB2_BUF_STATE_ERROR
);
339 while (!list_empty(&layer
->dma_queue
)) {
340 layer
->next_frm
= list_entry(layer
->dma_queue
.next
,
341 struct vpbe_disp_buffer
, list
);
342 list_del(&layer
->next_frm
->list
);
343 vb2_buffer_done(&layer
->next_frm
->vb
.vb2_buf
,
344 VB2_BUF_STATE_ERROR
);
346 spin_unlock_irqrestore(&disp
->dma_queue_lock
, flags
);
349 static const struct vb2_ops video_qops
= {
350 .queue_setup
= vpbe_buffer_queue_setup
,
351 .wait_prepare
= vb2_ops_wait_prepare
,
352 .wait_finish
= vb2_ops_wait_finish
,
353 .buf_prepare
= vpbe_buffer_prepare
,
354 .start_streaming
= vpbe_start_streaming
,
355 .stop_streaming
= vpbe_stop_streaming
,
356 .buf_queue
= vpbe_buffer_queue
,
361 _vpbe_display_get_other_win_layer(struct vpbe_display
*disp_dev
,
362 struct vpbe_layer
*layer
)
364 enum vpbe_display_device_id thiswin
, otherwin
;
365 thiswin
= layer
->device_id
;
367 otherwin
= (thiswin
== VPBE_DISPLAY_DEVICE_0
) ?
368 VPBE_DISPLAY_DEVICE_1
: VPBE_DISPLAY_DEVICE_0
;
369 return disp_dev
->dev
[otherwin
];
372 static int vpbe_set_osd_display_params(struct vpbe_display
*disp_dev
,
373 struct vpbe_layer
*layer
)
375 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
376 struct osd_state
*osd_device
= disp_dev
->osd_device
;
377 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
381 addr
= vb2_dma_contig_plane_dma_addr(&layer
->cur_frm
->vb
.vb2_buf
, 0);
382 /* Set address in the display registers */
383 osd_device
->ops
.start_layer(osd_device
,
384 layer
->layer_info
.id
,
386 disp_dev
->cbcr_ofst
);
388 ret
= osd_device
->ops
.enable_layer(osd_device
,
389 layer
->layer_info
.id
, 0);
391 v4l2_err(&vpbe_dev
->v4l2_dev
,
392 "Error in enabling osd window layer 0\n");
396 /* Enable the window */
397 layer
->layer_info
.enable
= 1;
398 if (cfg
->pixfmt
== PIXFMT_NV12
) {
399 struct vpbe_layer
*otherlayer
=
400 _vpbe_display_get_other_win_layer(disp_dev
, layer
);
402 ret
= osd_device
->ops
.enable_layer(osd_device
,
403 otherlayer
->layer_info
.id
, 1);
405 v4l2_err(&vpbe_dev
->v4l2_dev
,
406 "Error in enabling osd window layer 1\n");
409 otherlayer
->layer_info
.enable
= 1;
415 vpbe_disp_calculate_scale_factor(struct vpbe_display
*disp_dev
,
416 struct vpbe_layer
*layer
,
417 int expected_xsize
, int expected_ysize
)
419 struct display_layer_info
*layer_info
= &layer
->layer_info
;
420 struct v4l2_pix_format
*pixfmt
= &layer
->pix_fmt
;
421 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
422 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
423 int calculated_xsize
;
429 v4l2_std_id standard_id
= vpbe_dev
->current_timings
.std_id
;
432 * Application initially set the image format. Current display
433 * size is obtained from the vpbe display controller. expected_xsize
434 * and expected_ysize are set through S_SELECTION ioctl. Based on this,
435 * driver will calculate the scale factors for vertical and
436 * horizontal direction so that the image is displayed scaled
437 * and expanded. Application uses expansion to display the image
438 * in a square pixel. Otherwise it is displayed using displays
439 * pixel aspect ratio.It is expected that application chooses
440 * the crop coordinates for cropped or scaled display. if crop
441 * size is less than the image size, it is displayed cropped or
442 * it is displayed scaled and/or expanded.
444 * to begin with, set the crop window same as expected. Later we
445 * will override with scaled window size
448 cfg
->xsize
= pixfmt
->width
;
449 cfg
->ysize
= pixfmt
->height
;
450 layer_info
->h_zoom
= ZOOM_X1
; /* no horizontal zoom */
451 layer_info
->v_zoom
= ZOOM_X1
; /* no horizontal zoom */
452 layer_info
->h_exp
= H_EXP_OFF
; /* no horizontal zoom */
453 layer_info
->v_exp
= V_EXP_OFF
; /* no horizontal zoom */
455 if (pixfmt
->width
< expected_xsize
) {
456 h_scale
= vpbe_dev
->current_timings
.xres
/ pixfmt
->width
;
459 else if (h_scale
>= 4)
463 cfg
->xsize
*= h_scale
;
464 if (cfg
->xsize
< expected_xsize
) {
465 if ((standard_id
& V4L2_STD_525_60
) ||
466 (standard_id
& V4L2_STD_625_50
)) {
467 calculated_xsize
= (cfg
->xsize
*
468 VPBE_DISPLAY_H_EXP_RATIO_N
) /
469 VPBE_DISPLAY_H_EXP_RATIO_D
;
470 if (calculated_xsize
<= expected_xsize
) {
472 cfg
->xsize
= calculated_xsize
;
477 layer_info
->h_zoom
= ZOOM_X2
;
478 else if (h_scale
== 4)
479 layer_info
->h_zoom
= ZOOM_X4
;
481 layer_info
->h_exp
= H_EXP_9_OVER_8
;
483 /* no scaling, only cropping. Set display area to crop area */
484 cfg
->xsize
= expected_xsize
;
487 if (pixfmt
->height
< expected_ysize
) {
488 v_scale
= expected_ysize
/ pixfmt
->height
;
491 else if (v_scale
>= 4)
495 cfg
->ysize
*= v_scale
;
496 if (cfg
->ysize
< expected_ysize
) {
497 if ((standard_id
& V4L2_STD_625_50
)) {
498 calculated_xsize
= (cfg
->ysize
*
499 VPBE_DISPLAY_V_EXP_RATIO_N
) /
500 VPBE_DISPLAY_V_EXP_RATIO_D
;
501 if (calculated_xsize
<= expected_ysize
) {
503 cfg
->ysize
= calculated_xsize
;
508 layer_info
->v_zoom
= ZOOM_X2
;
509 else if (v_scale
== 4)
510 layer_info
->v_zoom
= ZOOM_X4
;
512 layer_info
->v_exp
= V_EXP_6_OVER_5
;
514 /* no scaling, only cropping. Set display area to crop area */
515 cfg
->ysize
= expected_ysize
;
517 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
518 "crop display xsize = %d, ysize = %d\n",
519 cfg
->xsize
, cfg
->ysize
);
522 static void vpbe_disp_adj_position(struct vpbe_display
*disp_dev
,
523 struct vpbe_layer
*layer
,
526 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
527 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
529 cfg
->xpos
= min((unsigned int)left
,
530 vpbe_dev
->current_timings
.xres
- cfg
->xsize
);
531 cfg
->ypos
= min((unsigned int)top
,
532 vpbe_dev
->current_timings
.yres
- cfg
->ysize
);
534 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
535 "new xpos = %d, ypos = %d\n",
536 cfg
->xpos
, cfg
->ypos
);
539 static void vpbe_disp_check_window_params(struct vpbe_display
*disp_dev
,
542 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
544 if ((c
->width
== 0) ||
545 ((c
->width
+ c
->left
) > vpbe_dev
->current_timings
.xres
))
546 c
->width
= vpbe_dev
->current_timings
.xres
- c
->left
;
548 if ((c
->height
== 0) || ((c
->height
+ c
->top
) >
549 vpbe_dev
->current_timings
.yres
))
550 c
->height
= vpbe_dev
->current_timings
.yres
- c
->top
;
552 /* window height must be even for interlaced display */
553 if (vpbe_dev
->current_timings
.interlaced
)
554 c
->height
&= (~0x01);
560 * If user application provides width and height, and have bytesperline set
561 * to zero, driver calculates bytesperline and sizeimage based on hardware
564 static int vpbe_try_format(struct vpbe_display
*disp_dev
,
565 struct v4l2_pix_format
*pixfmt
, int check
)
567 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
574 if ((pixfmt
->pixelformat
!= V4L2_PIX_FMT_UYVY
) &&
575 (pixfmt
->pixelformat
!= V4L2_PIX_FMT_NV12
))
576 /* choose default as V4L2_PIX_FMT_UYVY */
577 pixfmt
->pixelformat
= V4L2_PIX_FMT_UYVY
;
579 /* Check the field format */
580 if ((pixfmt
->field
!= V4L2_FIELD_INTERLACED
) &&
581 (pixfmt
->field
!= V4L2_FIELD_NONE
)) {
582 if (vpbe_dev
->current_timings
.interlaced
)
583 pixfmt
->field
= V4L2_FIELD_INTERLACED
;
585 pixfmt
->field
= V4L2_FIELD_NONE
;
588 if (pixfmt
->field
== V4L2_FIELD_INTERLACED
)
591 if (pixfmt
->pixelformat
== V4L2_PIX_FMT_NV12
)
596 max_width
= vpbe_dev
->current_timings
.xres
;
597 max_height
= vpbe_dev
->current_timings
.yres
;
601 if (!pixfmt
->width
|| (pixfmt
->width
< min_width
) ||
602 (pixfmt
->width
> max_width
)) {
603 pixfmt
->width
= vpbe_dev
->current_timings
.xres
;
606 if (!pixfmt
->height
|| (pixfmt
->height
< min_height
) ||
607 (pixfmt
->height
> max_height
)) {
608 pixfmt
->height
= vpbe_dev
->current_timings
.yres
;
611 if (pixfmt
->bytesperline
< (pixfmt
->width
* bpp
))
612 pixfmt
->bytesperline
= pixfmt
->width
* bpp
;
614 /* Make the bytesperline 32 byte aligned */
615 pixfmt
->bytesperline
= ((pixfmt
->width
* bpp
+ 31) & ~31);
617 if (pixfmt
->pixelformat
== V4L2_PIX_FMT_NV12
)
618 pixfmt
->sizeimage
= pixfmt
->bytesperline
* pixfmt
->height
+
619 (pixfmt
->bytesperline
* pixfmt
->height
>> 1);
621 pixfmt
->sizeimage
= pixfmt
->bytesperline
* pixfmt
->height
;
626 static int vpbe_display_querycap(struct file
*file
, void *priv
,
627 struct v4l2_capability
*cap
)
629 struct vpbe_layer
*layer
= video_drvdata(file
);
630 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
632 snprintf(cap
->driver
, sizeof(cap
->driver
), "%s",
633 dev_name(vpbe_dev
->pdev
));
634 snprintf(cap
->bus_info
, sizeof(cap
->bus_info
), "platform:%s",
635 dev_name(vpbe_dev
->pdev
));
636 strscpy(cap
->card
, vpbe_dev
->cfg
->module_name
, sizeof(cap
->card
));
641 static int vpbe_display_s_selection(struct file
*file
, void *priv
,
642 struct v4l2_selection
*sel
)
644 struct vpbe_layer
*layer
= video_drvdata(file
);
645 struct vpbe_display
*disp_dev
= layer
->disp_dev
;
646 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
647 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
648 struct osd_state
*osd_device
= disp_dev
->osd_device
;
649 struct v4l2_rect rect
= sel
->r
;
652 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
653 "VIDIOC_S_SELECTION, layer id = %d\n", layer
->device_id
);
655 if (sel
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
||
656 sel
->target
!= V4L2_SEL_TGT_CROP
)
664 vpbe_disp_check_window_params(disp_dev
, &rect
);
666 osd_device
->ops
.get_layer_config(osd_device
,
667 layer
->layer_info
.id
, cfg
);
669 vpbe_disp_calculate_scale_factor(disp_dev
, layer
,
672 vpbe_disp_adj_position(disp_dev
, layer
, rect
.top
,
674 ret
= osd_device
->ops
.set_layer_config(osd_device
,
675 layer
->layer_info
.id
, cfg
);
677 v4l2_err(&vpbe_dev
->v4l2_dev
,
678 "Error in set layer config:\n");
682 /* apply zooming and h or v expansion */
683 osd_device
->ops
.set_zoom(osd_device
,
684 layer
->layer_info
.id
,
685 layer
->layer_info
.h_zoom
,
686 layer
->layer_info
.v_zoom
);
687 ret
= osd_device
->ops
.set_vid_expansion(osd_device
,
688 layer
->layer_info
.h_exp
,
689 layer
->layer_info
.v_exp
);
691 v4l2_err(&vpbe_dev
->v4l2_dev
,
692 "Error in set vid expansion:\n");
696 if ((layer
->layer_info
.h_zoom
!= ZOOM_X1
) ||
697 (layer
->layer_info
.v_zoom
!= ZOOM_X1
) ||
698 (layer
->layer_info
.h_exp
!= H_EXP_OFF
) ||
699 (layer
->layer_info
.v_exp
!= V_EXP_OFF
))
700 /* Enable expansion filter */
701 osd_device
->ops
.set_interpolation_filter(osd_device
, 1);
703 osd_device
->ops
.set_interpolation_filter(osd_device
, 0);
709 static int vpbe_display_g_selection(struct file
*file
, void *priv
,
710 struct v4l2_selection
*sel
)
712 struct vpbe_layer
*layer
= video_drvdata(file
);
713 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
714 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
715 struct osd_state
*osd_device
= layer
->disp_dev
->osd_device
;
716 struct v4l2_rect
*rect
= &sel
->r
;
718 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
719 "VIDIOC_G_SELECTION, layer id = %d\n",
722 if (sel
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
725 switch (sel
->target
) {
726 case V4L2_SEL_TGT_CROP
:
727 osd_device
->ops
.get_layer_config(osd_device
,
728 layer
->layer_info
.id
, cfg
);
729 rect
->top
= cfg
->ypos
;
730 rect
->left
= cfg
->xpos
;
731 rect
->width
= cfg
->xsize
;
732 rect
->height
= cfg
->ysize
;
734 case V4L2_SEL_TGT_CROP_DEFAULT
:
735 case V4L2_SEL_TGT_CROP_BOUNDS
:
738 rect
->width
= vpbe_dev
->current_timings
.xres
;
739 rect
->height
= vpbe_dev
->current_timings
.yres
;
748 static int vpbe_display_g_pixelaspect(struct file
*file
, void *priv
,
749 int type
, struct v4l2_fract
*f
)
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 if (type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
759 *f
= vpbe_dev
->current_timings
.aspect
;
763 static int vpbe_display_g_fmt(struct file
*file
, void *priv
,
764 struct v4l2_format
*fmt
)
766 struct vpbe_layer
*layer
= video_drvdata(file
);
767 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
769 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
770 "VIDIOC_G_FMT, layer id = %d\n",
773 /* If buffer type is video output */
774 if (V4L2_BUF_TYPE_VIDEO_OUTPUT
!= fmt
->type
) {
775 v4l2_err(&vpbe_dev
->v4l2_dev
, "invalid type\n");
778 /* Fill in the information about format */
779 fmt
->fmt
.pix
= layer
->pix_fmt
;
784 static int vpbe_display_enum_fmt(struct file
*file
, void *priv
,
785 struct v4l2_fmtdesc
*fmt
)
787 struct vpbe_layer
*layer
= video_drvdata(file
);
788 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
790 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
791 "VIDIOC_ENUM_FMT, layer id = %d\n",
793 if (fmt
->index
> 1) {
794 v4l2_err(&vpbe_dev
->v4l2_dev
, "Invalid format index\n");
798 /* Fill in the information about format */
800 fmt
->pixelformat
= V4L2_PIX_FMT_UYVY
;
802 fmt
->pixelformat
= V4L2_PIX_FMT_NV12
;
807 static int vpbe_display_s_fmt(struct file
*file
, void *priv
,
808 struct v4l2_format
*fmt
)
810 struct vpbe_layer
*layer
= video_drvdata(file
);
811 struct vpbe_display
*disp_dev
= layer
->disp_dev
;
812 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
813 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
814 struct v4l2_pix_format
*pixfmt
= &fmt
->fmt
.pix
;
815 struct osd_state
*osd_device
= disp_dev
->osd_device
;
818 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
819 "VIDIOC_S_FMT, layer id = %d\n",
822 if (vb2_is_busy(&layer
->buffer_queue
))
825 if (V4L2_BUF_TYPE_VIDEO_OUTPUT
!= fmt
->type
) {
826 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "invalid type\n");
829 /* Check for valid pixel format */
830 ret
= vpbe_try_format(disp_dev
, pixfmt
, 1);
834 /* YUV420 is requested, check availability of the
835 other video window */
837 layer
->pix_fmt
= *pixfmt
;
838 if (pixfmt
->pixelformat
== V4L2_PIX_FMT_NV12
) {
839 struct vpbe_layer
*otherlayer
;
841 otherlayer
= _vpbe_display_get_other_win_layer(disp_dev
, layer
);
842 /* if other layer is available, only
843 * claim it, do not configure it
845 ret
= osd_device
->ops
.request_layer(osd_device
,
846 otherlayer
->layer_info
.id
);
848 v4l2_err(&vpbe_dev
->v4l2_dev
,
849 "Display Manager failed to allocate layer\n");
854 /* Get osd layer config */
855 osd_device
->ops
.get_layer_config(osd_device
,
856 layer
->layer_info
.id
, cfg
);
857 /* Store the pixel format in the layer object */
858 cfg
->xsize
= pixfmt
->width
;
859 cfg
->ysize
= pixfmt
->height
;
860 cfg
->line_length
= pixfmt
->bytesperline
;
863 cfg
->interlaced
= vpbe_dev
->current_timings
.interlaced
;
865 if (V4L2_PIX_FMT_UYVY
== pixfmt
->pixelformat
)
866 cfg
->pixfmt
= PIXFMT_YCBCRI
;
868 /* Change of the default pixel format for both video windows */
869 if (V4L2_PIX_FMT_NV12
== pixfmt
->pixelformat
) {
870 struct vpbe_layer
*otherlayer
;
871 cfg
->pixfmt
= PIXFMT_NV12
;
872 otherlayer
= _vpbe_display_get_other_win_layer(disp_dev
,
874 otherlayer
->layer_info
.config
.pixfmt
= PIXFMT_NV12
;
877 /* Set the layer config in the osd window */
878 ret
= osd_device
->ops
.set_layer_config(osd_device
,
879 layer
->layer_info
.id
, cfg
);
881 v4l2_err(&vpbe_dev
->v4l2_dev
,
882 "Error in S_FMT params:\n");
886 /* Readback and fill the local copy of current pix format */
887 osd_device
->ops
.get_layer_config(osd_device
,
888 layer
->layer_info
.id
, cfg
);
893 static int vpbe_display_try_fmt(struct file
*file
, void *priv
,
894 struct v4l2_format
*fmt
)
896 struct vpbe_layer
*layer
= video_drvdata(file
);
897 struct vpbe_display
*disp_dev
= layer
->disp_dev
;
898 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
899 struct v4l2_pix_format
*pixfmt
= &fmt
->fmt
.pix
;
901 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_TRY_FMT\n");
903 if (V4L2_BUF_TYPE_VIDEO_OUTPUT
!= fmt
->type
) {
904 v4l2_err(&vpbe_dev
->v4l2_dev
, "invalid type\n");
908 /* Check for valid field format */
909 return vpbe_try_format(disp_dev
, pixfmt
, 0);
914 * vpbe_display_s_std - Set the given standard in the encoder
916 * Sets the standard if supported by the current encoder. Return the status.
917 * 0 - success & -EINVAL on error
919 static int vpbe_display_s_std(struct file
*file
, void *priv
,
922 struct vpbe_layer
*layer
= video_drvdata(file
);
923 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
926 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_S_STD\n");
928 if (vb2_is_busy(&layer
->buffer_queue
))
931 if (vpbe_dev
->ops
.s_std
) {
932 ret
= vpbe_dev
->ops
.s_std(vpbe_dev
, std_id
);
934 v4l2_err(&vpbe_dev
->v4l2_dev
,
935 "Failed to set standard for sub devices\n");
946 * vpbe_display_g_std - Get the standard in the current encoder
948 * Get the standard in the current encoder. Return the status. 0 - success
951 static int vpbe_display_g_std(struct file
*file
, void *priv
,
954 struct vpbe_layer
*layer
= video_drvdata(file
);
955 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
957 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_G_STD\n");
959 /* Get the standard from the current encoder */
960 if (vpbe_dev
->current_timings
.timings_type
& VPBE_ENC_STD
) {
961 *std_id
= vpbe_dev
->current_timings
.std_id
;
969 * vpbe_display_enum_output - enumerate outputs
971 * Enumerates the outputs available at the vpbe display
972 * returns the status, -EINVAL if end of output list
974 static int vpbe_display_enum_output(struct file
*file
, void *priv
,
975 struct v4l2_output
*output
)
977 struct vpbe_layer
*layer
= video_drvdata(file
);
978 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
981 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_ENUM_OUTPUT\n");
983 /* Enumerate outputs */
984 if (!vpbe_dev
->ops
.enum_outputs
)
987 ret
= vpbe_dev
->ops
.enum_outputs(vpbe_dev
, output
);
989 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
990 "Failed to enumerate outputs\n");
998 * vpbe_display_s_output - Set output to
999 * the output specified by the index
1001 static int vpbe_display_s_output(struct file
*file
, void *priv
,
1004 struct vpbe_layer
*layer
= video_drvdata(file
);
1005 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
1008 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_S_OUTPUT\n");
1010 if (vb2_is_busy(&layer
->buffer_queue
))
1013 if (!vpbe_dev
->ops
.set_output
)
1016 ret
= vpbe_dev
->ops
.set_output(vpbe_dev
, i
);
1018 v4l2_err(&vpbe_dev
->v4l2_dev
,
1019 "Failed to set output for sub devices\n");
1027 * vpbe_display_g_output - Get output from subdevice
1028 * for a given by the index
1030 static int vpbe_display_g_output(struct file
*file
, void *priv
,
1033 struct vpbe_layer
*layer
= video_drvdata(file
);
1034 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
1036 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_G_OUTPUT\n");
1037 /* Get the standard from the current encoder */
1038 *i
= vpbe_dev
->current_out_index
;
1044 * vpbe_display_enum_dv_timings - Enumerate the dv timings
1046 * enum the timings in the current encoder. Return the status. 0 - success
1050 vpbe_display_enum_dv_timings(struct file
*file
, void *priv
,
1051 struct v4l2_enum_dv_timings
*timings
)
1053 struct vpbe_layer
*layer
= video_drvdata(file
);
1054 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
1057 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_ENUM_DV_TIMINGS\n");
1059 /* Enumerate outputs */
1060 if (!vpbe_dev
->ops
.enum_dv_timings
)
1063 ret
= vpbe_dev
->ops
.enum_dv_timings(vpbe_dev
, timings
);
1065 v4l2_err(&vpbe_dev
->v4l2_dev
,
1066 "Failed to enumerate dv timings info\n");
1074 * vpbe_display_s_dv_timings - Set the dv timings
1076 * Set the timings in the current encoder. Return the status. 0 - success
1080 vpbe_display_s_dv_timings(struct file
*file
, void *priv
,
1081 struct v4l2_dv_timings
*timings
)
1083 struct vpbe_layer
*layer
= video_drvdata(file
);
1084 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
1087 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_S_DV_TIMINGS\n");
1089 if (vb2_is_busy(&layer
->buffer_queue
))
1092 /* Set the given standard in the encoder */
1093 if (!vpbe_dev
->ops
.s_dv_timings
)
1096 ret
= vpbe_dev
->ops
.s_dv_timings(vpbe_dev
, timings
);
1098 v4l2_err(&vpbe_dev
->v4l2_dev
,
1099 "Failed to set the dv timings info\n");
1107 * vpbe_display_g_dv_timings - Set the dv timings
1109 * Get the timings in the current encoder. Return the status. 0 - success
1113 vpbe_display_g_dv_timings(struct file
*file
, void *priv
,
1114 struct v4l2_dv_timings
*dv_timings
)
1116 struct vpbe_layer
*layer
= video_drvdata(file
);
1117 struct vpbe_device
*vpbe_dev
= layer
->disp_dev
->vpbe_dev
;
1119 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "VIDIOC_G_DV_TIMINGS\n");
1121 /* Get the given standard in the encoder */
1123 if (vpbe_dev
->current_timings
.timings_type
&
1124 VPBE_ENC_DV_TIMINGS
) {
1125 *dv_timings
= vpbe_dev
->current_timings
.dv_timings
;
1134 * vpbe_display_open()
1135 * It creates object of file handle structure and stores it in private_data
1136 * member of filepointer
1138 static int vpbe_display_open(struct file
*file
)
1140 struct vpbe_layer
*layer
= video_drvdata(file
);
1141 struct vpbe_display
*disp_dev
= layer
->disp_dev
;
1142 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
1143 struct osd_state
*osd_device
= disp_dev
->osd_device
;
1146 /* creating context for file descriptor */
1147 err
= v4l2_fh_open(file
);
1149 v4l2_err(&vpbe_dev
->v4l2_dev
, "v4l2_fh_open failed\n");
1153 /* leaving if layer is already initialized */
1154 if (!v4l2_fh_is_singular_file(file
))
1158 if (mutex_lock_interruptible(&layer
->opslock
))
1159 return -ERESTARTSYS
;
1160 /* First claim the layer for this device */
1161 err
= osd_device
->ops
.request_layer(osd_device
,
1162 layer
->layer_info
.id
);
1163 mutex_unlock(&layer
->opslock
);
1165 /* Couldn't get layer */
1166 v4l2_err(&vpbe_dev
->v4l2_dev
,
1167 "Display Manager failed to allocate layer\n");
1168 v4l2_fh_release(file
);
1172 /* Increment layer usrs counter */
1174 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
,
1175 "vpbe display device opened successfully\n");
1180 * vpbe_display_release()
1181 * This function deletes buffer queue, frees the buffers and the davinci
1182 * display file * handle
1184 static int vpbe_display_release(struct file
*file
)
1186 struct vpbe_layer
*layer
= video_drvdata(file
);
1187 struct osd_layer_config
*cfg
= &layer
->layer_info
.config
;
1188 struct vpbe_display
*disp_dev
= layer
->disp_dev
;
1189 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
1190 struct osd_state
*osd_device
= disp_dev
->osd_device
;
1192 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "vpbe_display_release\n");
1194 mutex_lock(&layer
->opslock
);
1196 osd_device
->ops
.disable_layer(osd_device
,
1197 layer
->layer_info
.id
);
1198 /* Decrement layer usrs counter */
1200 /* If this file handle has initialize encoder device, reset it */
1202 if (cfg
->pixfmt
== PIXFMT_NV12
) {
1203 struct vpbe_layer
*otherlayer
;
1205 _vpbe_display_get_other_win_layer(disp_dev
, layer
);
1206 osd_device
->ops
.disable_layer(osd_device
,
1207 otherlayer
->layer_info
.id
);
1208 osd_device
->ops
.release_layer(osd_device
,
1209 otherlayer
->layer_info
.id
);
1211 osd_device
->ops
.disable_layer(osd_device
,
1212 layer
->layer_info
.id
);
1213 osd_device
->ops
.release_layer(osd_device
,
1214 layer
->layer_info
.id
);
1217 _vb2_fop_release(file
, NULL
);
1218 mutex_unlock(&layer
->opslock
);
1220 disp_dev
->cbcr_ofst
= 0;
1225 /* vpbe capture ioctl operations */
1226 static const struct v4l2_ioctl_ops vpbe_ioctl_ops
= {
1227 .vidioc_querycap
= vpbe_display_querycap
,
1228 .vidioc_g_fmt_vid_out
= vpbe_display_g_fmt
,
1229 .vidioc_enum_fmt_vid_out
= vpbe_display_enum_fmt
,
1230 .vidioc_s_fmt_vid_out
= vpbe_display_s_fmt
,
1231 .vidioc_try_fmt_vid_out
= vpbe_display_try_fmt
,
1233 .vidioc_reqbufs
= vb2_ioctl_reqbufs
,
1234 .vidioc_create_bufs
= vb2_ioctl_create_bufs
,
1235 .vidioc_querybuf
= vb2_ioctl_querybuf
,
1236 .vidioc_qbuf
= vb2_ioctl_qbuf
,
1237 .vidioc_dqbuf
= vb2_ioctl_dqbuf
,
1238 .vidioc_streamon
= vb2_ioctl_streamon
,
1239 .vidioc_streamoff
= vb2_ioctl_streamoff
,
1240 .vidioc_expbuf
= vb2_ioctl_expbuf
,
1242 .vidioc_g_pixelaspect
= vpbe_display_g_pixelaspect
,
1243 .vidioc_g_selection
= vpbe_display_g_selection
,
1244 .vidioc_s_selection
= vpbe_display_s_selection
,
1246 .vidioc_s_std
= vpbe_display_s_std
,
1247 .vidioc_g_std
= vpbe_display_g_std
,
1249 .vidioc_enum_output
= vpbe_display_enum_output
,
1250 .vidioc_s_output
= vpbe_display_s_output
,
1251 .vidioc_g_output
= vpbe_display_g_output
,
1253 .vidioc_s_dv_timings
= vpbe_display_s_dv_timings
,
1254 .vidioc_g_dv_timings
= vpbe_display_g_dv_timings
,
1255 .vidioc_enum_dv_timings
= vpbe_display_enum_dv_timings
,
1258 static const struct v4l2_file_operations vpbe_fops
= {
1259 .owner
= THIS_MODULE
,
1260 .open
= vpbe_display_open
,
1261 .release
= vpbe_display_release
,
1262 .unlocked_ioctl
= video_ioctl2
,
1263 .mmap
= vb2_fop_mmap
,
1264 .poll
= vb2_fop_poll
,
1267 static int vpbe_device_get(struct device
*dev
, void *data
)
1269 struct platform_device
*pdev
= to_platform_device(dev
);
1270 struct vpbe_display
*vpbe_disp
= data
;
1272 if (strcmp("vpbe_controller", pdev
->name
) == 0)
1273 vpbe_disp
->vpbe_dev
= platform_get_drvdata(pdev
);
1275 if (strstr(pdev
->name
, "vpbe-osd"))
1276 vpbe_disp
->osd_device
= platform_get_drvdata(pdev
);
1281 static int init_vpbe_layer(int i
, struct vpbe_display
*disp_dev
,
1282 struct platform_device
*pdev
)
1284 struct vpbe_layer
*vpbe_display_layer
= NULL
;
1285 struct video_device
*vbd
= NULL
;
1287 /* Allocate memory for four plane display objects */
1288 disp_dev
->dev
[i
] = kzalloc(sizeof(*disp_dev
->dev
[i
]), GFP_KERNEL
);
1289 if (!disp_dev
->dev
[i
])
1292 spin_lock_init(&disp_dev
->dev
[i
]->irqlock
);
1293 mutex_init(&disp_dev
->dev
[i
]->opslock
);
1295 /* Get the pointer to the layer object */
1296 vpbe_display_layer
= disp_dev
->dev
[i
];
1297 vbd
= &vpbe_display_layer
->video_dev
;
1298 /* Initialize field of video device */
1299 vbd
->release
= video_device_release_empty
;
1300 vbd
->fops
= &vpbe_fops
;
1301 vbd
->ioctl_ops
= &vpbe_ioctl_ops
;
1303 vbd
->v4l2_dev
= &disp_dev
->vpbe_dev
->v4l2_dev
;
1304 vbd
->lock
= &vpbe_display_layer
->opslock
;
1305 vbd
->vfl_dir
= VFL_DIR_TX
;
1306 vbd
->device_caps
= V4L2_CAP_VIDEO_OUTPUT
| V4L2_CAP_STREAMING
;
1308 if (disp_dev
->vpbe_dev
->current_timings
.timings_type
&
1310 vbd
->tvnorms
= (V4L2_STD_525_60
| V4L2_STD_625_50
);
1312 snprintf(vbd
->name
, sizeof(vbd
->name
),
1313 "DaVinci_VPBE Display_DRIVER_V%d.%d.%d",
1314 (VPBE_DISPLAY_VERSION_CODE
>> 16) & 0xff,
1315 (VPBE_DISPLAY_VERSION_CODE
>> 8) & 0xff,
1316 (VPBE_DISPLAY_VERSION_CODE
) & 0xff);
1318 vpbe_display_layer
->device_id
= i
;
1320 vpbe_display_layer
->layer_info
.id
=
1321 ((i
== VPBE_DISPLAY_DEVICE_0
) ? WIN_VID0
: WIN_VID1
);
1327 static int register_device(struct vpbe_layer
*vpbe_display_layer
,
1328 struct vpbe_display
*disp_dev
,
1329 struct platform_device
*pdev
)
1333 v4l2_info(&disp_dev
->vpbe_dev
->v4l2_dev
,
1334 "Trying to register VPBE display device.\n");
1335 v4l2_info(&disp_dev
->vpbe_dev
->v4l2_dev
,
1336 "layer=%p,layer->video_dev=%p\n",
1338 &vpbe_display_layer
->video_dev
);
1340 vpbe_display_layer
->video_dev
.queue
= &vpbe_display_layer
->buffer_queue
;
1341 err
= video_register_device(&vpbe_display_layer
->video_dev
,
1347 vpbe_display_layer
->disp_dev
= disp_dev
;
1348 /* set the driver data in platform device */
1349 platform_set_drvdata(pdev
, disp_dev
);
1350 video_set_drvdata(&vpbe_display_layer
->video_dev
,
1351 vpbe_display_layer
);
1359 * vpbe_display_probe()
1360 * This function creates device entries by register itself to the V4L2 driver
1361 * and initializes fields of each layer objects
1363 static int vpbe_display_probe(struct platform_device
*pdev
)
1365 struct vpbe_display
*disp_dev
;
1366 struct v4l2_device
*v4l2_dev
;
1367 struct resource
*res
= NULL
;
1368 struct vb2_queue
*q
;
1374 printk(KERN_DEBUG
"vpbe_display_probe\n");
1375 /* Allocate memory for vpbe_display */
1376 disp_dev
= devm_kzalloc(&pdev
->dev
, sizeof(*disp_dev
), GFP_KERNEL
);
1380 spin_lock_init(&disp_dev
->dma_queue_lock
);
1382 * Scan all the platform devices to find the vpbe
1383 * controller device and get the vpbe_dev object
1385 err
= bus_for_each_dev(&platform_bus_type
, NULL
, disp_dev
,
1390 v4l2_dev
= &disp_dev
->vpbe_dev
->v4l2_dev
;
1391 /* Initialize the vpbe display controller */
1392 if (disp_dev
->vpbe_dev
->ops
.initialize
) {
1393 err
= disp_dev
->vpbe_dev
->ops
.initialize(&pdev
->dev
,
1394 disp_dev
->vpbe_dev
);
1396 v4l2_err(v4l2_dev
, "Error initing vpbe\n");
1402 for (i
= 0; i
< VPBE_DISPLAY_MAX_DEVICES
; i
++) {
1403 if (init_vpbe_layer(i
, disp_dev
, pdev
)) {
1409 res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
1411 v4l2_err(v4l2_dev
, "Unable to get VENC interrupt resource\n");
1417 err
= devm_request_irq(&pdev
->dev
, irq
, venc_isr
, 0,
1418 VPBE_DISPLAY_DRIVER
, disp_dev
);
1420 v4l2_err(v4l2_dev
, "VPBE IRQ request failed\n");
1424 for (i
= 0; i
< VPBE_DISPLAY_MAX_DEVICES
; i
++) {
1425 /* initialize vb2 queue */
1426 q
= &disp_dev
->dev
[i
]->buffer_queue
;
1427 memset(q
, 0, sizeof(*q
));
1428 q
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
1429 q
->io_modes
= VB2_MMAP
| VB2_USERPTR
| VB2_DMABUF
;
1430 q
->drv_priv
= disp_dev
->dev
[i
];
1431 q
->ops
= &video_qops
;
1432 q
->mem_ops
= &vb2_dma_contig_memops
;
1433 q
->buf_struct_size
= sizeof(struct vpbe_disp_buffer
);
1434 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1435 q
->min_buffers_needed
= 1;
1436 q
->lock
= &disp_dev
->dev
[i
]->opslock
;
1437 q
->dev
= disp_dev
->vpbe_dev
->pdev
;
1438 err
= vb2_queue_init(q
);
1440 v4l2_err(v4l2_dev
, "vb2_queue_init() failed\n");
1444 INIT_LIST_HEAD(&disp_dev
->dev
[i
]->dma_queue
);
1446 if (register_device(disp_dev
->dev
[i
], disp_dev
, pdev
)) {
1452 v4l2_dbg(1, debug
, v4l2_dev
,
1453 "Successfully completed the probing of vpbe v4l2 device\n");
1458 for (k
= 0; k
< VPBE_DISPLAY_MAX_DEVICES
; k
++) {
1459 /* Unregister video device */
1460 if (disp_dev
->dev
[k
]) {
1461 video_unregister_device(&disp_dev
->dev
[k
]->video_dev
);
1462 kfree(disp_dev
->dev
[k
]);
1469 * vpbe_display_remove()
1470 * It un-register hardware layer from V4L2 driver
1472 static int vpbe_display_remove(struct platform_device
*pdev
)
1474 struct vpbe_layer
*vpbe_display_layer
;
1475 struct vpbe_display
*disp_dev
= platform_get_drvdata(pdev
);
1476 struct vpbe_device
*vpbe_dev
= disp_dev
->vpbe_dev
;
1479 v4l2_dbg(1, debug
, &vpbe_dev
->v4l2_dev
, "vpbe_display_remove\n");
1481 /* deinitialize the vpbe display controller */
1482 if (vpbe_dev
->ops
.deinitialize
)
1483 vpbe_dev
->ops
.deinitialize(&pdev
->dev
, vpbe_dev
);
1484 /* un-register device */
1485 for (i
= 0; i
< VPBE_DISPLAY_MAX_DEVICES
; i
++) {
1486 /* Get the pointer to the layer object */
1487 vpbe_display_layer
= disp_dev
->dev
[i
];
1488 /* Unregister video device */
1489 video_unregister_device(&vpbe_display_layer
->video_dev
);
1492 for (i
= 0; i
< VPBE_DISPLAY_MAX_DEVICES
; i
++) {
1493 kfree(disp_dev
->dev
[i
]);
1494 disp_dev
->dev
[i
] = NULL
;
1500 static struct platform_driver vpbe_display_driver
= {
1502 .name
= VPBE_DISPLAY_DRIVER
,
1503 .bus
= &platform_bus_type
,
1505 .probe
= vpbe_display_probe
,
1506 .remove
= vpbe_display_remove
,
1509 module_platform_driver(vpbe_display_driver
);
1511 MODULE_DESCRIPTION("TI DM644x/DM355/DM365 VPBE Display controller");
1512 MODULE_LICENSE("GPL");
1513 MODULE_AUTHOR("Texas Instruments");