2 * vpif-display - VPIF display driver
3 * Display driver for TI DaVinci VPIF
5 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
6 * Copyright (C) 2014 Lad, Prabhakar <prabhakar.csengg@gmail.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation version 2.
12 * This program is distributed .as is. WITHOUT ANY WARRANTY of any
13 * kind, whether express or implied; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/interrupt.h>
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
21 #include <linux/slab.h>
23 #include <media/v4l2-ioctl.h>
26 #include "vpif_display.h"
28 MODULE_DESCRIPTION("TI DaVinci VPIF Display driver");
29 MODULE_LICENSE("GPL");
30 MODULE_VERSION(VPIF_DISPLAY_VERSION
);
32 #define VPIF_V4L2_STD (V4L2_STD_525_60 | V4L2_STD_625_50)
34 #define vpif_err(fmt, arg...) v4l2_err(&vpif_obj.v4l2_dev, fmt, ## arg)
35 #define vpif_dbg(level, debug, fmt, arg...) \
36 v4l2_dbg(level, debug, &vpif_obj.v4l2_dev, fmt, ## arg)
40 module_param(debug
, int, 0644);
42 MODULE_PARM_DESC(debug
, "Debug level 0-1");
44 #define VPIF_DRIVER_NAME "vpif_display"
46 /* Is set to 1 in case of SDTV formats, 2 in case of HDTV formats. */
47 static int ycmux_mode
;
49 static u8 channel_first_int
[VPIF_NUMOBJECTS
][2] = { {1, 1} };
51 static struct vpif_device vpif_obj
= { {NULL
} };
52 static struct device
*vpif_dev
;
53 static void vpif_calculate_offsets(struct channel_obj
*ch
);
54 static void vpif_config_addr(struct channel_obj
*ch
, int muxmode
);
56 static inline struct vpif_disp_buffer
*to_vpif_buffer(struct vb2_buffer
*vb
)
58 return container_of(vb
, struct vpif_disp_buffer
, vb
);
62 * vpif_buffer_prepare : callback function for buffer prepare
63 * @vb: ptr to vb2_buffer
65 * This is the callback function for buffer prepare when vb2_qbuf()
66 * function is called. The buffer is prepared and user space virtual address
67 * or user address is converted into physical address
69 static int vpif_buffer_prepare(struct vb2_buffer
*vb
)
71 struct channel_obj
*ch
= vb2_get_drv_priv(vb
->vb2_queue
);
72 struct common_obj
*common
;
74 common
= &ch
->common
[VPIF_VIDEO_INDEX
];
76 vb2_set_plane_payload(vb
, 0, common
->fmt
.fmt
.pix
.sizeimage
);
77 if (vb2_get_plane_payload(vb
, 0) > vb2_plane_size(vb
, 0))
80 vb
->v4l2_buf
.field
= common
->fmt
.fmt
.pix
.field
;
82 if (vb
->vb2_queue
->type
!= V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
) {
83 unsigned long addr
= vb2_dma_contig_plane_dma_addr(vb
, 0);
85 if (!ISALIGNED(addr
+ common
->ytop_off
) ||
86 !ISALIGNED(addr
+ common
->ybtm_off
) ||
87 !ISALIGNED(addr
+ common
->ctop_off
) ||
88 !ISALIGNED(addr
+ common
->cbtm_off
)) {
89 vpif_err("buffer offset not aligned to 8 bytes\n");
98 * vpif_buffer_queue_setup : Callback function for buffer setup.
101 * @nbuffers: ptr to number of buffers requested by application
102 * @nplanes:: contains number of distinct video planes needed to hold a frame
103 * @sizes[]: contains the size (in bytes) of each plane.
104 * @alloc_ctxs: ptr to allocation context
106 * This callback function is called when reqbuf() is called to adjust
107 * the buffer count and buffer size
109 static int vpif_buffer_queue_setup(struct vb2_queue
*vq
,
110 const struct v4l2_format
*fmt
,
111 unsigned int *nbuffers
, unsigned int *nplanes
,
112 unsigned int sizes
[], void *alloc_ctxs
[])
114 struct channel_obj
*ch
= vb2_get_drv_priv(vq
);
115 struct common_obj
*common
= &ch
->common
[VPIF_VIDEO_INDEX
];
117 if (fmt
&& fmt
->fmt
.pix
.sizeimage
< common
->fmt
.fmt
.pix
.sizeimage
)
120 if (vq
->num_buffers
+ *nbuffers
< 3)
121 *nbuffers
= 3 - vq
->num_buffers
;
124 sizes
[0] = fmt
? fmt
->fmt
.pix
.sizeimage
: common
->fmt
.fmt
.pix
.sizeimage
;
125 alloc_ctxs
[0] = common
->alloc_ctx
;
127 /* Calculate the offset for Y and C data in the buffer */
128 vpif_calculate_offsets(ch
);
134 * vpif_buffer_queue : Callback function to add buffer to DMA queue
135 * @vb: ptr to vb2_buffer
137 * This callback fucntion queues the buffer to DMA engine
139 static void vpif_buffer_queue(struct vb2_buffer
*vb
)
141 struct vpif_disp_buffer
*buf
= to_vpif_buffer(vb
);
142 struct channel_obj
*ch
= vb2_get_drv_priv(vb
->vb2_queue
);
143 struct common_obj
*common
;
146 common
= &ch
->common
[VPIF_VIDEO_INDEX
];
148 /* add the buffer to the DMA queue */
149 spin_lock_irqsave(&common
->irqlock
, flags
);
150 list_add_tail(&buf
->list
, &common
->dma_queue
);
151 spin_unlock_irqrestore(&common
->irqlock
, flags
);
155 * vpif_start_streaming : Starts the DMA engine for streaming
156 * @vb: ptr to vb2_buffer
157 * @count: number of buffers
159 static int vpif_start_streaming(struct vb2_queue
*vq
, unsigned int count
)
161 struct vpif_display_config
*vpif_config_data
=
162 vpif_dev
->platform_data
;
163 struct channel_obj
*ch
= vb2_get_drv_priv(vq
);
164 struct common_obj
*common
= &ch
->common
[VPIF_VIDEO_INDEX
];
165 struct vpif_params
*vpif
= &ch
->vpifparams
;
166 struct vpif_disp_buffer
*buf
, *tmp
;
167 unsigned long addr
, flags
;
170 spin_lock_irqsave(&common
->irqlock
, flags
);
172 /* Initialize field_id */
176 if (vpif_config_data
->set_clock
) {
177 ret
= vpif_config_data
->set_clock(ch
->vpifparams
.std_info
.
178 ycmux_mode
, ch
->vpifparams
.std_info
.hd_sd
);
180 vpif_err("can't set clock\n");
185 /* set the parameters and addresses */
186 ret
= vpif_set_video_params(vpif
, ch
->channel_id
+ 2);
191 vpif_config_addr(ch
, ret
);
192 /* Get the next frame from the buffer queue */
193 common
->next_frm
= common
->cur_frm
=
194 list_entry(common
->dma_queue
.next
,
195 struct vpif_disp_buffer
, list
);
197 list_del(&common
->cur_frm
->list
);
198 spin_unlock_irqrestore(&common
->irqlock
, flags
);
199 /* Mark state of the current frame to active */
200 common
->cur_frm
->vb
.state
= VB2_BUF_STATE_ACTIVE
;
202 addr
= vb2_dma_contig_plane_dma_addr(&common
->cur_frm
->vb
, 0);
203 common
->set_addr((addr
+ common
->ytop_off
),
204 (addr
+ common
->ybtm_off
),
205 (addr
+ common
->ctop_off
),
206 (addr
+ common
->cbtm_off
));
209 * Set interrupt for both the fields in VPIF
210 * Register enable channel in VPIF register
212 channel_first_int
[VPIF_VIDEO_INDEX
][ch
->channel_id
] = 1;
213 if (VPIF_CHANNEL2_VIDEO
== ch
->channel_id
) {
214 channel2_intr_assert();
215 channel2_intr_enable(1);
217 if (vpif_config_data
->chan_config
[VPIF_CHANNEL2_VIDEO
].clip_en
)
218 channel2_clipping_enable(1);
221 if (VPIF_CHANNEL3_VIDEO
== ch
->channel_id
|| ycmux_mode
== 2) {
222 channel3_intr_assert();
223 channel3_intr_enable(1);
225 if (vpif_config_data
->chan_config
[VPIF_CHANNEL3_VIDEO
].clip_en
)
226 channel3_clipping_enable(1);
232 list_for_each_entry_safe(buf
, tmp
, &common
->dma_queue
, list
) {
233 list_del(&buf
->list
);
234 vb2_buffer_done(&buf
->vb
, VB2_BUF_STATE_QUEUED
);
241 * vpif_stop_streaming : Stop the DMA engine
242 * @vq: ptr to vb2_queue
244 * This callback stops the DMA engine and any remaining buffers
245 * in the DMA queue are released.
247 static void vpif_stop_streaming(struct vb2_queue
*vq
)
249 struct channel_obj
*ch
= vb2_get_drv_priv(vq
);
250 struct common_obj
*common
;
253 common
= &ch
->common
[VPIF_VIDEO_INDEX
];
255 /* Disable channel */
256 if (VPIF_CHANNEL2_VIDEO
== ch
->channel_id
) {
258 channel2_intr_enable(0);
260 if (VPIF_CHANNEL3_VIDEO
== ch
->channel_id
|| ycmux_mode
== 2) {
262 channel3_intr_enable(0);
265 /* release all active buffers */
266 spin_lock_irqsave(&common
->irqlock
, flags
);
267 if (common
->cur_frm
== common
->next_frm
) {
268 vb2_buffer_done(&common
->cur_frm
->vb
, VB2_BUF_STATE_ERROR
);
270 if (common
->cur_frm
!= NULL
)
271 vb2_buffer_done(&common
->cur_frm
->vb
,
272 VB2_BUF_STATE_ERROR
);
273 if (common
->next_frm
!= NULL
)
274 vb2_buffer_done(&common
->next_frm
->vb
,
275 VB2_BUF_STATE_ERROR
);
278 while (!list_empty(&common
->dma_queue
)) {
279 common
->next_frm
= list_entry(common
->dma_queue
.next
,
280 struct vpif_disp_buffer
, list
);
281 list_del(&common
->next_frm
->list
);
282 vb2_buffer_done(&common
->next_frm
->vb
, VB2_BUF_STATE_ERROR
);
284 spin_unlock_irqrestore(&common
->irqlock
, flags
);
287 static struct vb2_ops video_qops
= {
288 .queue_setup
= vpif_buffer_queue_setup
,
289 .wait_prepare
= vb2_ops_wait_prepare
,
290 .wait_finish
= vb2_ops_wait_finish
,
291 .buf_prepare
= vpif_buffer_prepare
,
292 .start_streaming
= vpif_start_streaming
,
293 .stop_streaming
= vpif_stop_streaming
,
294 .buf_queue
= vpif_buffer_queue
,
297 static void process_progressive_mode(struct common_obj
*common
)
299 unsigned long addr
= 0;
301 spin_lock(&common
->irqlock
);
302 /* Get the next buffer from buffer queue */
303 common
->next_frm
= list_entry(common
->dma_queue
.next
,
304 struct vpif_disp_buffer
, list
);
305 /* Remove that buffer from the buffer queue */
306 list_del(&common
->next_frm
->list
);
307 spin_unlock(&common
->irqlock
);
308 /* Mark status of the buffer as active */
309 common
->next_frm
->vb
.state
= VB2_BUF_STATE_ACTIVE
;
311 /* Set top and bottom field addrs in VPIF registers */
312 addr
= vb2_dma_contig_plane_dma_addr(&common
->next_frm
->vb
, 0);
313 common
->set_addr(addr
+ common
->ytop_off
,
314 addr
+ common
->ybtm_off
,
315 addr
+ common
->ctop_off
,
316 addr
+ common
->cbtm_off
);
319 static void process_interlaced_mode(int fid
, struct common_obj
*common
)
321 /* device field id and local field id are in sync */
322 /* If this is even field */
324 if (common
->cur_frm
== common
->next_frm
)
327 /* one frame is displayed If next frame is
328 * available, release cur_frm and move on */
329 /* Copy frame display time */
330 v4l2_get_timestamp(&common
->cur_frm
->vb
.v4l2_buf
.timestamp
);
331 /* Change status of the cur_frm */
332 vb2_buffer_done(&common
->cur_frm
->vb
,
334 /* Make cur_frm pointing to next_frm */
335 common
->cur_frm
= common
->next_frm
;
337 } else if (1 == fid
) { /* odd field */
338 spin_lock(&common
->irqlock
);
339 if (list_empty(&common
->dma_queue
)
340 || (common
->cur_frm
!= common
->next_frm
)) {
341 spin_unlock(&common
->irqlock
);
344 spin_unlock(&common
->irqlock
);
345 /* one field is displayed configure the next
346 * frame if it is available else hold on current
348 /* Get next from the buffer queue */
349 process_progressive_mode(common
);
354 * vpif_channel_isr: It changes status of the displayed buffer, takes next
355 * buffer from the queue and sets its address in VPIF registers
357 static irqreturn_t
vpif_channel_isr(int irq
, void *dev_id
)
359 struct vpif_device
*dev
= &vpif_obj
;
360 struct channel_obj
*ch
;
361 struct common_obj
*common
;
362 enum v4l2_field field
;
366 channel_id
= *(int *)(dev_id
);
367 if (!vpif_intr_status(channel_id
+ 2))
370 ch
= dev
->dev
[channel_id
];
371 field
= ch
->common
[VPIF_VIDEO_INDEX
].fmt
.fmt
.pix
.field
;
372 for (i
= 0; i
< VPIF_NUMOBJECTS
; i
++) {
373 common
= &ch
->common
[i
];
374 /* If streaming is started in this channel */
376 if (1 == ch
->vpifparams
.std_info
.frm_fmt
) {
377 spin_lock(&common
->irqlock
);
378 if (list_empty(&common
->dma_queue
)) {
379 spin_unlock(&common
->irqlock
);
382 spin_unlock(&common
->irqlock
);
384 /* Progressive mode */
385 if (!channel_first_int
[i
][channel_id
]) {
386 /* Mark status of the cur_frm to
387 * done and unlock semaphore on it */
388 v4l2_get_timestamp(&common
->cur_frm
->vb
.
390 vb2_buffer_done(&common
->cur_frm
->vb
,
392 /* Make cur_frm pointing to next_frm */
393 common
->cur_frm
= common
->next_frm
;
396 channel_first_int
[i
][channel_id
] = 0;
397 process_progressive_mode(common
);
399 /* Interlaced mode */
400 /* If it is first interrupt, ignore it */
402 if (channel_first_int
[i
][channel_id
]) {
403 channel_first_int
[i
][channel_id
] = 0;
409 /* Get field id from VPIF registers */
410 fid
= vpif_channel_getfid(ch
->channel_id
+ 2);
411 /* If fid does not match with stored field id */
412 if (fid
!= ch
->field_id
) {
413 /* Make them in sync */
420 process_interlaced_mode(fid
, common
);
427 static int vpif_update_std_info(struct channel_obj
*ch
)
429 struct video_obj
*vid_ch
= &ch
->video
;
430 struct vpif_params
*vpifparams
= &ch
->vpifparams
;
431 struct vpif_channel_config_params
*std_info
= &vpifparams
->std_info
;
432 const struct vpif_channel_config_params
*config
;
436 for (i
= 0; i
< vpif_ch_params_count
; i
++) {
437 config
= &vpif_ch_params
[i
];
438 if (config
->hd_sd
== 0) {
439 vpif_dbg(2, debug
, "SD format\n");
440 if (config
->stdid
& vid_ch
->stdid
) {
441 memcpy(std_info
, config
, sizeof(*config
));
447 if (i
== vpif_ch_params_count
) {
448 vpif_dbg(1, debug
, "Format not found\n");
455 static int vpif_update_resolution(struct channel_obj
*ch
)
457 struct common_obj
*common
= &ch
->common
[VPIF_VIDEO_INDEX
];
458 struct video_obj
*vid_ch
= &ch
->video
;
459 struct vpif_params
*vpifparams
= &ch
->vpifparams
;
460 struct vpif_channel_config_params
*std_info
= &vpifparams
->std_info
;
462 if (!vid_ch
->stdid
&& !vid_ch
->dv_timings
.bt
.height
)
466 if (vpif_update_std_info(ch
))
470 common
->fmt
.fmt
.pix
.pixelformat
= V4L2_PIX_FMT_YUV422P
;
471 common
->fmt
.fmt
.pix
.width
= std_info
->width
;
472 common
->fmt
.fmt
.pix
.height
= std_info
->height
;
473 vpif_dbg(1, debug
, "Pixel details: Width = %d,Height = %d\n",
474 common
->fmt
.fmt
.pix
.width
, common
->fmt
.fmt
.pix
.height
);
476 /* Set height and width paramateres */
477 common
->height
= std_info
->height
;
478 common
->width
= std_info
->width
;
479 common
->fmt
.fmt
.pix
.sizeimage
= common
->height
* common
->width
* 2;
482 common
->fmt
.fmt
.pix
.colorspace
= V4L2_COLORSPACE_SMPTE170M
;
484 common
->fmt
.fmt
.pix
.colorspace
= V4L2_COLORSPACE_REC709
;
486 if (ch
->vpifparams
.std_info
.frm_fmt
)
487 common
->fmt
.fmt
.pix
.field
= V4L2_FIELD_NONE
;
489 common
->fmt
.fmt
.pix
.field
= V4L2_FIELD_INTERLACED
;
495 * vpif_calculate_offsets: This function calculates buffers offset for Y and C
496 * in the top and bottom field
498 static void vpif_calculate_offsets(struct channel_obj
*ch
)
500 struct common_obj
*common
= &ch
->common
[VPIF_VIDEO_INDEX
];
501 struct vpif_params
*vpifparams
= &ch
->vpifparams
;
502 enum v4l2_field field
= common
->fmt
.fmt
.pix
.field
;
503 struct video_obj
*vid_ch
= &ch
->video
;
504 unsigned int hpitch
, vpitch
, sizeimage
;
506 if (V4L2_FIELD_ANY
== common
->fmt
.fmt
.pix
.field
) {
507 if (ch
->vpifparams
.std_info
.frm_fmt
)
508 vid_ch
->buf_field
= V4L2_FIELD_NONE
;
510 vid_ch
->buf_field
= V4L2_FIELD_INTERLACED
;
512 vid_ch
->buf_field
= common
->fmt
.fmt
.pix
.field
;
515 sizeimage
= common
->fmt
.fmt
.pix
.sizeimage
;
517 hpitch
= common
->fmt
.fmt
.pix
.bytesperline
;
518 vpitch
= sizeimage
/ (hpitch
* 2);
519 if ((V4L2_FIELD_NONE
== vid_ch
->buf_field
) ||
520 (V4L2_FIELD_INTERLACED
== vid_ch
->buf_field
)) {
521 common
->ytop_off
= 0;
522 common
->ybtm_off
= hpitch
;
523 common
->ctop_off
= sizeimage
/ 2;
524 common
->cbtm_off
= sizeimage
/ 2 + hpitch
;
525 } else if (V4L2_FIELD_SEQ_TB
== vid_ch
->buf_field
) {
526 common
->ytop_off
= 0;
527 common
->ybtm_off
= sizeimage
/ 4;
528 common
->ctop_off
= sizeimage
/ 2;
529 common
->cbtm_off
= common
->ctop_off
+ sizeimage
/ 4;
530 } else if (V4L2_FIELD_SEQ_BT
== vid_ch
->buf_field
) {
531 common
->ybtm_off
= 0;
532 common
->ytop_off
= sizeimage
/ 4;
533 common
->cbtm_off
= sizeimage
/ 2;
534 common
->ctop_off
= common
->cbtm_off
+ sizeimage
/ 4;
537 if ((V4L2_FIELD_NONE
== vid_ch
->buf_field
) ||
538 (V4L2_FIELD_INTERLACED
== vid_ch
->buf_field
)) {
539 vpifparams
->video_params
.storage_mode
= 1;
541 vpifparams
->video_params
.storage_mode
= 0;
544 if (ch
->vpifparams
.std_info
.frm_fmt
== 1) {
545 vpifparams
->video_params
.hpitch
=
546 common
->fmt
.fmt
.pix
.bytesperline
;
548 if ((field
== V4L2_FIELD_ANY
) ||
549 (field
== V4L2_FIELD_INTERLACED
))
550 vpifparams
->video_params
.hpitch
=
551 common
->fmt
.fmt
.pix
.bytesperline
* 2;
553 vpifparams
->video_params
.hpitch
=
554 common
->fmt
.fmt
.pix
.bytesperline
;
557 ch
->vpifparams
.video_params
.stdid
= ch
->vpifparams
.std_info
.stdid
;
560 static void vpif_config_addr(struct channel_obj
*ch
, int muxmode
)
562 struct common_obj
*common
= &ch
->common
[VPIF_VIDEO_INDEX
];
564 if (VPIF_CHANNEL3_VIDEO
== ch
->channel_id
) {
565 common
->set_addr
= ch3_set_videobuf_addr
;
568 common
->set_addr
= ch2_set_videobuf_addr_yc_nmux
;
570 common
->set_addr
= ch2_set_videobuf_addr
;
574 /* functions implementing ioctls */
576 * vpif_querycap() - QUERYCAP handler
579 * @cap: ptr to v4l2_capability structure
581 static int vpif_querycap(struct file
*file
, void *priv
,
582 struct v4l2_capability
*cap
)
584 struct vpif_display_config
*config
= vpif_dev
->platform_data
;
586 cap
->device_caps
= V4L2_CAP_VIDEO_OUTPUT
| V4L2_CAP_STREAMING
;
587 cap
->capabilities
= cap
->device_caps
| V4L2_CAP_DEVICE_CAPS
;
588 strlcpy(cap
->driver
, VPIF_DRIVER_NAME
, sizeof(cap
->driver
));
589 snprintf(cap
->bus_info
, sizeof(cap
->bus_info
), "platform:%s",
591 strlcpy(cap
->card
, config
->card_name
, sizeof(cap
->card
));
596 static int vpif_enum_fmt_vid_out(struct file
*file
, void *priv
,
597 struct v4l2_fmtdesc
*fmt
)
602 /* Fill in the information about format */
603 fmt
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
604 strcpy(fmt
->description
, "YCbCr4:2:2 YC Planar");
605 fmt
->pixelformat
= V4L2_PIX_FMT_YUV422P
;
610 static int vpif_g_fmt_vid_out(struct file
*file
, void *priv
,
611 struct v4l2_format
*fmt
)
613 struct video_device
*vdev
= video_devdata(file
);
614 struct channel_obj
*ch
= video_get_drvdata(vdev
);
615 struct common_obj
*common
= &ch
->common
[VPIF_VIDEO_INDEX
];
617 /* Check the validity of the buffer type */
618 if (common
->fmt
.type
!= fmt
->type
)
621 if (vpif_update_resolution(ch
))
627 static int vpif_try_fmt_vid_out(struct file
*file
, void *priv
,
628 struct v4l2_format
*fmt
)
630 struct video_device
*vdev
= video_devdata(file
);
631 struct channel_obj
*ch
= video_get_drvdata(vdev
);
632 struct common_obj
*common
= &ch
->common
[VPIF_VIDEO_INDEX
];
633 struct v4l2_pix_format
*pixfmt
= &fmt
->fmt
.pix
;
636 * to supress v4l-compliance warnings silently correct
639 if (pixfmt
->pixelformat
!= V4L2_PIX_FMT_YUV422P
)
640 pixfmt
->pixelformat
= common
->fmt
.fmt
.pix
.pixelformat
;
642 if (vpif_update_resolution(ch
))
645 pixfmt
->colorspace
= common
->fmt
.fmt
.pix
.colorspace
;
646 pixfmt
->field
= common
->fmt
.fmt
.pix
.field
;
647 pixfmt
->bytesperline
= common
->fmt
.fmt
.pix
.width
;
648 pixfmt
->width
= common
->fmt
.fmt
.pix
.width
;
649 pixfmt
->height
= common
->fmt
.fmt
.pix
.height
;
650 pixfmt
->sizeimage
= pixfmt
->bytesperline
* pixfmt
->height
* 2;
656 static int vpif_s_fmt_vid_out(struct file
*file
, void *priv
,
657 struct v4l2_format
*fmt
)
659 struct video_device
*vdev
= video_devdata(file
);
660 struct channel_obj
*ch
= video_get_drvdata(vdev
);
661 struct common_obj
*common
= &ch
->common
[VPIF_VIDEO_INDEX
];
662 struct v4l2_pix_format
*pixfmt
= &fmt
->fmt
.pix
;
665 if (vb2_is_busy(&common
->buffer_queue
))
668 ret
= vpif_try_fmt_vid_out(file
, priv
, fmt
);
672 /* store the pix format in the channel object */
673 common
->fmt
.fmt
.pix
= *pixfmt
;
675 /* store the format in the channel object */
680 static int vpif_s_std(struct file
*file
, void *priv
, v4l2_std_id std_id
)
682 struct vpif_display_config
*config
= vpif_dev
->platform_data
;
683 struct video_device
*vdev
= video_devdata(file
);
684 struct channel_obj
*ch
= video_get_drvdata(vdev
);
685 struct common_obj
*common
= &ch
->common
[VPIF_VIDEO_INDEX
];
686 struct vpif_display_chan_config
*chan_cfg
;
687 struct v4l2_output output
;
690 if (config
->chan_config
[ch
->channel_id
].outputs
== NULL
)
693 chan_cfg
= &config
->chan_config
[ch
->channel_id
];
694 output
= chan_cfg
->outputs
[ch
->output_idx
].output
;
695 if (output
.capabilities
!= V4L2_OUT_CAP_STD
)
698 if (vb2_is_busy(&common
->buffer_queue
))
702 if (!(std_id
& VPIF_V4L2_STD
))
705 /* Call encoder subdevice function to set the standard */
706 ch
->video
.stdid
= std_id
;
707 memset(&ch
->video
.dv_timings
, 0, sizeof(ch
->video
.dv_timings
));
708 /* Get the information about the standard */
709 if (vpif_update_resolution(ch
))
712 common
->fmt
.fmt
.pix
.bytesperline
= common
->fmt
.fmt
.pix
.width
;
714 ret
= v4l2_device_call_until_err(&vpif_obj
.v4l2_dev
, 1, video
,
715 s_std_output
, std_id
);
717 vpif_err("Failed to set output standard\n");
721 ret
= v4l2_device_call_until_err(&vpif_obj
.v4l2_dev
, 1, video
,
724 vpif_err("Failed to set standard for sub devices\n");
728 static int vpif_g_std(struct file
*file
, void *priv
, v4l2_std_id
*std
)
730 struct vpif_display_config
*config
= vpif_dev
->platform_data
;
731 struct video_device
*vdev
= video_devdata(file
);
732 struct channel_obj
*ch
= video_get_drvdata(vdev
);
733 struct vpif_display_chan_config
*chan_cfg
;
734 struct v4l2_output output
;
736 if (config
->chan_config
[ch
->channel_id
].outputs
== NULL
)
739 chan_cfg
= &config
->chan_config
[ch
->channel_id
];
740 output
= chan_cfg
->outputs
[ch
->output_idx
].output
;
741 if (output
.capabilities
!= V4L2_OUT_CAP_STD
)
744 *std
= ch
->video
.stdid
;
748 static int vpif_enum_output(struct file
*file
, void *fh
,
749 struct v4l2_output
*output
)
752 struct vpif_display_config
*config
= vpif_dev
->platform_data
;
753 struct video_device
*vdev
= video_devdata(file
);
754 struct channel_obj
*ch
= video_get_drvdata(vdev
);
755 struct vpif_display_chan_config
*chan_cfg
;
757 chan_cfg
= &config
->chan_config
[ch
->channel_id
];
758 if (output
->index
>= chan_cfg
->output_count
) {
759 vpif_dbg(1, debug
, "Invalid output index\n");
763 *output
= chan_cfg
->outputs
[output
->index
].output
;
768 * vpif_output_to_subdev() - Maps output to sub device
769 * @vpif_cfg - global config ptr
770 * @chan_cfg - channel config ptr
771 * @index - Given output index from application
773 * lookup the sub device information for a given output index.
774 * we report all the output to application. output table also
775 * has sub device name for the each output
778 vpif_output_to_subdev(struct vpif_display_config
*vpif_cfg
,
779 struct vpif_display_chan_config
*chan_cfg
, int index
)
781 struct vpif_subdev_info
*subdev_info
;
782 const char *subdev_name
;
785 vpif_dbg(2, debug
, "vpif_output_to_subdev\n");
787 if (chan_cfg
->outputs
== NULL
)
790 subdev_name
= chan_cfg
->outputs
[index
].subdev_name
;
791 if (subdev_name
== NULL
)
794 /* loop through the sub device list to get the sub device info */
795 for (i
= 0; i
< vpif_cfg
->subdev_count
; i
++) {
796 subdev_info
= &vpif_cfg
->subdevinfo
[i
];
797 if (!strcmp(subdev_info
->name
, subdev_name
))
804 * vpif_set_output() - Select an output
805 * @vpif_cfg - global config ptr
807 * @index - Given output index from application
809 * Select the given output.
811 static int vpif_set_output(struct vpif_display_config
*vpif_cfg
,
812 struct channel_obj
*ch
, int index
)
814 struct vpif_display_chan_config
*chan_cfg
=
815 &vpif_cfg
->chan_config
[ch
->channel_id
];
816 struct vpif_subdev_info
*subdev_info
= NULL
;
817 struct v4l2_subdev
*sd
= NULL
;
818 u32 input
= 0, output
= 0;
822 sd_index
= vpif_output_to_subdev(vpif_cfg
, chan_cfg
, index
);
824 sd
= vpif_obj
.sd
[sd_index
];
825 subdev_info
= &vpif_cfg
->subdevinfo
[sd_index
];
829 input
= chan_cfg
->outputs
[index
].input_route
;
830 output
= chan_cfg
->outputs
[index
].output_route
;
831 ret
= v4l2_subdev_call(sd
, video
, s_routing
, input
, output
, 0);
832 if (ret
< 0 && ret
!= -ENOIOCTLCMD
) {
833 vpif_err("Failed to set output\n");
838 ch
->output_idx
= index
;
840 if (chan_cfg
->outputs
!= NULL
)
841 /* update tvnorms from the sub device output info */
842 ch
->video_dev
->tvnorms
= chan_cfg
->outputs
[index
].output
.std
;
846 static int vpif_s_output(struct file
*file
, void *priv
, unsigned int i
)
848 struct vpif_display_config
*config
= vpif_dev
->platform_data
;
849 struct video_device
*vdev
= video_devdata(file
);
850 struct channel_obj
*ch
= video_get_drvdata(vdev
);
851 struct vpif_display_chan_config
*chan_cfg
;
852 struct common_obj
*common
= &ch
->common
[VPIF_VIDEO_INDEX
];
854 if (vb2_is_busy(&common
->buffer_queue
))
857 chan_cfg
= &config
->chan_config
[ch
->channel_id
];
859 if (i
>= chan_cfg
->output_count
)
862 return vpif_set_output(config
, ch
, i
);
865 static int vpif_g_output(struct file
*file
, void *priv
, unsigned int *i
)
867 struct video_device
*vdev
= video_devdata(file
);
868 struct channel_obj
*ch
= video_get_drvdata(vdev
);
876 * vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler
879 * @timings: input timings
882 vpif_enum_dv_timings(struct file
*file
, void *priv
,
883 struct v4l2_enum_dv_timings
*timings
)
885 struct vpif_display_config
*config
= vpif_dev
->platform_data
;
886 struct video_device
*vdev
= video_devdata(file
);
887 struct channel_obj
*ch
= video_get_drvdata(vdev
);
888 struct vpif_display_chan_config
*chan_cfg
;
889 struct v4l2_output output
;
892 if (config
->chan_config
[ch
->channel_id
].outputs
== NULL
)
895 chan_cfg
= &config
->chan_config
[ch
->channel_id
];
896 output
= chan_cfg
->outputs
[ch
->output_idx
].output
;
897 if (output
.capabilities
!= V4L2_OUT_CAP_DV_TIMINGS
)
902 ret
= v4l2_subdev_call(ch
->sd
, pad
, enum_dv_timings
, timings
);
903 if (ret
== -ENOIOCTLCMD
|| ret
== -ENODEV
)
909 * vpif_s_dv_timings() - S_DV_TIMINGS handler
912 * @timings: digital video timings
914 static int vpif_s_dv_timings(struct file
*file
, void *priv
,
915 struct v4l2_dv_timings
*timings
)
917 struct vpif_display_config
*config
= vpif_dev
->platform_data
;
918 struct video_device
*vdev
= video_devdata(file
);
919 struct channel_obj
*ch
= video_get_drvdata(vdev
);
920 struct vpif_params
*vpifparams
= &ch
->vpifparams
;
921 struct common_obj
*common
= &ch
->common
[VPIF_VIDEO_INDEX
];
922 struct vpif_channel_config_params
*std_info
= &vpifparams
->std_info
;
923 struct video_obj
*vid_ch
= &ch
->video
;
924 struct v4l2_bt_timings
*bt
= &vid_ch
->dv_timings
.bt
;
925 struct vpif_display_chan_config
*chan_cfg
;
926 struct v4l2_output output
;
929 if (config
->chan_config
[ch
->channel_id
].outputs
== NULL
)
932 chan_cfg
= &config
->chan_config
[ch
->channel_id
];
933 output
= chan_cfg
->outputs
[ch
->output_idx
].output
;
934 if (output
.capabilities
!= V4L2_OUT_CAP_DV_TIMINGS
)
937 if (vb2_is_busy(&common
->buffer_queue
))
940 if (timings
->type
!= V4L2_DV_BT_656_1120
) {
941 vpif_dbg(2, debug
, "Timing type not defined\n");
945 /* Configure subdevice timings, if any */
946 ret
= v4l2_subdev_call(ch
->sd
, video
, s_dv_timings
, timings
);
947 if (ret
== -ENOIOCTLCMD
|| ret
== -ENODEV
)
950 vpif_dbg(2, debug
, "Error setting custom DV timings\n");
954 if (!(timings
->bt
.width
&& timings
->bt
.height
&&
955 (timings
->bt
.hbackporch
||
956 timings
->bt
.hfrontporch
||
957 timings
->bt
.hsync
) &&
958 timings
->bt
.vfrontporch
&&
959 (timings
->bt
.vbackporch
||
960 timings
->bt
.vsync
))) {
961 vpif_dbg(2, debug
, "Timings for width, height, "
962 "horizontal back porch, horizontal sync, "
963 "horizontal front porch, vertical back porch, "
964 "vertical sync and vertical back porch "
965 "must be defined\n");
969 vid_ch
->dv_timings
= *timings
;
971 /* Configure video port timings */
973 std_info
->eav2sav
= V4L2_DV_BT_BLANKING_WIDTH(bt
) - 8;
974 std_info
->sav2eav
= bt
->width
;
977 std_info
->l3
= bt
->vsync
+ bt
->vbackporch
+ 1;
979 std_info
->vsize
= V4L2_DV_BT_FRAME_HEIGHT(bt
);
980 if (bt
->interlaced
) {
981 if (bt
->il_vbackporch
|| bt
->il_vfrontporch
|| bt
->il_vsync
) {
982 std_info
->l5
= std_info
->vsize
/2 -
983 (bt
->vfrontporch
- 1);
984 std_info
->l7
= std_info
->vsize
/2 + 1;
985 std_info
->l9
= std_info
->l7
+ bt
->il_vsync
+
986 bt
->il_vbackporch
+ 1;
987 std_info
->l11
= std_info
->vsize
-
988 (bt
->il_vfrontporch
- 1);
990 vpif_dbg(2, debug
, "Required timing values for "
991 "interlaced BT format missing\n");
995 std_info
->l5
= std_info
->vsize
- (bt
->vfrontporch
- 1);
997 strncpy(std_info
->name
, "Custom timings BT656/1120",
999 std_info
->width
= bt
->width
;
1000 std_info
->height
= bt
->height
;
1001 std_info
->frm_fmt
= bt
->interlaced
? 0 : 1;
1002 std_info
->ycmux_mode
= 0;
1003 std_info
->capture_format
= 0;
1004 std_info
->vbi_supported
= 0;
1005 std_info
->hd_sd
= 1;
1006 std_info
->stdid
= 0;
1013 * vpif_g_dv_timings() - G_DV_TIMINGS handler
1015 * @priv: file handle
1016 * @timings: digital video timings
1018 static int vpif_g_dv_timings(struct file
*file
, void *priv
,
1019 struct v4l2_dv_timings
*timings
)
1021 struct vpif_display_config
*config
= vpif_dev
->platform_data
;
1022 struct video_device
*vdev
= video_devdata(file
);
1023 struct channel_obj
*ch
= video_get_drvdata(vdev
);
1024 struct vpif_display_chan_config
*chan_cfg
;
1025 struct video_obj
*vid_ch
= &ch
->video
;
1026 struct v4l2_output output
;
1028 if (config
->chan_config
[ch
->channel_id
].outputs
== NULL
)
1031 chan_cfg
= &config
->chan_config
[ch
->channel_id
];
1032 output
= chan_cfg
->outputs
[ch
->output_idx
].output
;
1034 if (output
.capabilities
!= V4L2_OUT_CAP_DV_TIMINGS
)
1037 *timings
= vid_ch
->dv_timings
;
1045 * vpif_log_status() - Status information
1047 * @priv: file handle
1051 static int vpif_log_status(struct file
*filep
, void *priv
)
1053 /* status for sub devices */
1054 v4l2_device_call_all(&vpif_obj
.v4l2_dev
, 0, core
, log_status
);
1059 /* vpif display ioctl operations */
1060 static const struct v4l2_ioctl_ops vpif_ioctl_ops
= {
1061 .vidioc_querycap
= vpif_querycap
,
1062 .vidioc_enum_fmt_vid_out
= vpif_enum_fmt_vid_out
,
1063 .vidioc_g_fmt_vid_out
= vpif_g_fmt_vid_out
,
1064 .vidioc_s_fmt_vid_out
= vpif_s_fmt_vid_out
,
1065 .vidioc_try_fmt_vid_out
= vpif_try_fmt_vid_out
,
1067 .vidioc_reqbufs
= vb2_ioctl_reqbufs
,
1068 .vidioc_create_bufs
= vb2_ioctl_create_bufs
,
1069 .vidioc_querybuf
= vb2_ioctl_querybuf
,
1070 .vidioc_qbuf
= vb2_ioctl_qbuf
,
1071 .vidioc_dqbuf
= vb2_ioctl_dqbuf
,
1072 .vidioc_expbuf
= vb2_ioctl_expbuf
,
1073 .vidioc_streamon
= vb2_ioctl_streamon
,
1074 .vidioc_streamoff
= vb2_ioctl_streamoff
,
1076 .vidioc_s_std
= vpif_s_std
,
1077 .vidioc_g_std
= vpif_g_std
,
1079 .vidioc_enum_output
= vpif_enum_output
,
1080 .vidioc_s_output
= vpif_s_output
,
1081 .vidioc_g_output
= vpif_g_output
,
1083 .vidioc_enum_dv_timings
= vpif_enum_dv_timings
,
1084 .vidioc_s_dv_timings
= vpif_s_dv_timings
,
1085 .vidioc_g_dv_timings
= vpif_g_dv_timings
,
1087 .vidioc_log_status
= vpif_log_status
,
1090 static const struct v4l2_file_operations vpif_fops
= {
1091 .owner
= THIS_MODULE
,
1092 .open
= v4l2_fh_open
,
1093 .release
= vb2_fop_release
,
1094 .unlocked_ioctl
= video_ioctl2
,
1095 .mmap
= vb2_fop_mmap
,
1096 .poll
= vb2_fop_poll
1099 /*Configure the channels, buffer sizei, request irq */
1100 static int initialize_vpif(void)
1102 int free_channel_objects_index
;
1105 /* Allocate memory for six channel objects */
1106 for (i
= 0; i
< VPIF_DISPLAY_MAX_DEVICES
; i
++) {
1108 kzalloc(sizeof(struct channel_obj
), GFP_KERNEL
);
1109 /* If memory allocation fails, return error */
1110 if (!vpif_obj
.dev
[i
]) {
1111 free_channel_objects_index
= i
;
1113 goto vpif_init_free_channel_objects
;
1119 vpif_init_free_channel_objects
:
1120 for (j
= 0; j
< free_channel_objects_index
; j
++)
1121 kfree(vpif_obj
.dev
[j
]);
1125 static int vpif_async_bound(struct v4l2_async_notifier
*notifier
,
1126 struct v4l2_subdev
*subdev
,
1127 struct v4l2_async_subdev
*asd
)
1131 for (i
= 0; i
< vpif_obj
.config
->subdev_count
; i
++)
1132 if (!strcmp(vpif_obj
.config
->subdevinfo
[i
].name
,
1134 vpif_obj
.sd
[i
] = subdev
;
1135 vpif_obj
.sd
[i
]->grp_id
= 1 << i
;
1142 static int vpif_probe_complete(void)
1144 struct common_obj
*common
;
1145 struct video_device
*vdev
;
1146 struct channel_obj
*ch
;
1147 struct vb2_queue
*q
;
1150 for (j
= 0; j
< VPIF_DISPLAY_MAX_DEVICES
; j
++) {
1151 ch
= vpif_obj
.dev
[j
];
1152 /* Initialize field of the channel objects */
1153 for (k
= 0; k
< VPIF_NUMOBJECTS
; k
++) {
1154 common
= &ch
->common
[k
];
1155 spin_lock_init(&common
->irqlock
);
1156 mutex_init(&common
->lock
);
1157 common
->set_addr
= NULL
;
1158 common
->ytop_off
= 0;
1159 common
->ybtm_off
= 0;
1160 common
->ctop_off
= 0;
1161 common
->cbtm_off
= 0;
1162 common
->cur_frm
= NULL
;
1163 common
->next_frm
= NULL
;
1164 memset(&common
->fmt
, 0, sizeof(common
->fmt
));
1166 ch
->initialized
= 0;
1167 if (vpif_obj
.config
->subdev_count
)
1168 ch
->sd
= vpif_obj
.sd
[0];
1171 memset(&ch
->vpifparams
, 0, sizeof(ch
->vpifparams
));
1173 ch
->common
[VPIF_VIDEO_INDEX
].fmt
.type
=
1174 V4L2_BUF_TYPE_VIDEO_OUTPUT
;
1176 /* select output 0 */
1177 err
= vpif_set_output(vpif_obj
.config
, ch
, 0);
1181 /* set initial format */
1182 ch
->video
.stdid
= V4L2_STD_525_60
;
1183 memset(&ch
->video
.dv_timings
, 0, sizeof(ch
->video
.dv_timings
));
1184 vpif_update_resolution(ch
);
1186 /* Initialize vb2 queue */
1187 q
= &common
->buffer_queue
;
1188 q
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
1189 q
->io_modes
= VB2_MMAP
| VB2_USERPTR
| VB2_DMABUF
;
1191 q
->ops
= &video_qops
;
1192 q
->mem_ops
= &vb2_dma_contig_memops
;
1193 q
->buf_struct_size
= sizeof(struct vpif_disp_buffer
);
1194 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1195 q
->min_buffers_needed
= 1;
1196 q
->lock
= &common
->lock
;
1197 err
= vb2_queue_init(q
);
1199 vpif_err("vpif_display: vb2_queue_init() failed\n");
1203 common
->alloc_ctx
= vb2_dma_contig_init_ctx(vpif_dev
);
1204 if (IS_ERR(common
->alloc_ctx
)) {
1205 vpif_err("Failed to get the context\n");
1206 err
= PTR_ERR(common
->alloc_ctx
);
1210 INIT_LIST_HEAD(&common
->dma_queue
);
1212 /* register video device */
1213 vpif_dbg(1, debug
, "channel=%x,channel->video_dev=%x\n",
1214 (int)ch
, (int)&ch
->video_dev
);
1216 /* Initialize the video_device structure */
1217 vdev
= ch
->video_dev
;
1218 strlcpy(vdev
->name
, VPIF_DRIVER_NAME
, sizeof(vdev
->name
));
1219 vdev
->release
= video_device_release
;
1220 vdev
->fops
= &vpif_fops
;
1221 vdev
->ioctl_ops
= &vpif_ioctl_ops
;
1222 vdev
->v4l2_dev
= &vpif_obj
.v4l2_dev
;
1223 vdev
->vfl_dir
= VFL_DIR_TX
;
1225 vdev
->lock
= &common
->lock
;
1226 set_bit(V4L2_FL_USE_FH_PRIO
, &vdev
->flags
);
1227 video_set_drvdata(ch
->video_dev
, ch
);
1228 err
= video_register_device(vdev
, VFL_TYPE_GRABBER
,
1237 for (k
= 0; k
< j
; k
++) {
1238 ch
= vpif_obj
.dev
[k
];
1239 common
= &ch
->common
[k
];
1240 vb2_dma_contig_cleanup_ctx(common
->alloc_ctx
);
1241 video_unregister_device(ch
->video_dev
);
1242 video_device_release(ch
->video_dev
);
1243 ch
->video_dev
= NULL
;
1248 static int vpif_async_complete(struct v4l2_async_notifier
*notifier
)
1250 return vpif_probe_complete();
1254 * vpif_probe: This function creates device entries by register itself to the
1255 * V4L2 driver and initializes fields of each channel objects
1257 static __init
int vpif_probe(struct platform_device
*pdev
)
1259 struct vpif_subdev_info
*subdevdata
;
1260 int i
, j
= 0, err
= 0;
1262 struct i2c_adapter
*i2c_adap
;
1263 struct channel_obj
*ch
;
1264 struct video_device
*vfd
;
1265 struct resource
*res
;
1268 vpif_dev
= &pdev
->dev
;
1269 err
= initialize_vpif();
1272 v4l2_err(vpif_dev
->driver
, "Error initializing vpif\n");
1276 err
= v4l2_device_register(vpif_dev
, &vpif_obj
.v4l2_dev
);
1278 v4l2_err(vpif_dev
->driver
, "Error registering v4l2 device\n");
1282 while ((res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, res_idx
))) {
1283 err
= devm_request_irq(&pdev
->dev
, res
->start
, vpif_channel_isr
,
1284 IRQF_SHARED
, VPIF_DRIVER_NAME
,
1285 (void *)(&vpif_obj
.dev
[res_idx
]->
1289 vpif_err("VPIF IRQ request failed\n");
1290 goto vpif_unregister
;
1295 for (i
= 0; i
< VPIF_DISPLAY_MAX_DEVICES
; i
++) {
1296 /* Get the pointer to the channel object */
1297 ch
= vpif_obj
.dev
[i
];
1299 /* Allocate memory for video device */
1300 vfd
= video_device_alloc();
1302 for (j
= 0; j
< i
; j
++) {
1303 ch
= vpif_obj
.dev
[j
];
1304 video_device_release(ch
->video_dev
);
1307 goto vpif_unregister
;
1310 /* Set video_dev to the video device */
1311 ch
->video_dev
= vfd
;
1314 vpif_obj
.config
= pdev
->dev
.platform_data
;
1315 subdev_count
= vpif_obj
.config
->subdev_count
;
1316 subdevdata
= vpif_obj
.config
->subdevinfo
;
1317 vpif_obj
.sd
= kzalloc(sizeof(struct v4l2_subdev
*) * subdev_count
,
1319 if (vpif_obj
.sd
== NULL
) {
1320 vpif_err("unable to allocate memory for subdevice pointers\n");
1325 if (!vpif_obj
.config
->asd_sizes
) {
1326 i2c_adap
= i2c_get_adapter(1);
1327 for (i
= 0; i
< subdev_count
; i
++) {
1329 v4l2_i2c_new_subdev_board(&vpif_obj
.v4l2_dev
,
1334 if (!vpif_obj
.sd
[i
]) {
1335 vpif_err("Error registering v4l2 subdevice\n");
1337 goto probe_subdev_out
;
1341 vpif_obj
.sd
[i
]->grp_id
= 1 << i
;
1343 vpif_probe_complete();
1345 vpif_obj
.notifier
.subdevs
= vpif_obj
.config
->asd
;
1346 vpif_obj
.notifier
.num_subdevs
= vpif_obj
.config
->asd_sizes
[0];
1347 vpif_obj
.notifier
.bound
= vpif_async_bound
;
1348 vpif_obj
.notifier
.complete
= vpif_async_complete
;
1349 err
= v4l2_async_notifier_register(&vpif_obj
.v4l2_dev
,
1350 &vpif_obj
.notifier
);
1352 vpif_err("Error registering async notifier\n");
1354 goto probe_subdev_out
;
1363 for (i
= 0; i
< VPIF_DISPLAY_MAX_DEVICES
; i
++) {
1364 ch
= vpif_obj
.dev
[i
];
1365 /* Note: does nothing if ch->video_dev == NULL */
1366 video_device_release(ch
->video_dev
);
1369 v4l2_device_unregister(&vpif_obj
.v4l2_dev
);
1375 * vpif_remove: It un-register channels from V4L2 driver
1377 static int vpif_remove(struct platform_device
*device
)
1379 struct common_obj
*common
;
1380 struct channel_obj
*ch
;
1383 v4l2_device_unregister(&vpif_obj
.v4l2_dev
);
1386 /* un-register device */
1387 for (i
= 0; i
< VPIF_DISPLAY_MAX_DEVICES
; i
++) {
1388 /* Get the pointer to the channel object */
1389 ch
= vpif_obj
.dev
[i
];
1390 common
= &ch
->common
[i
];
1391 vb2_dma_contig_cleanup_ctx(common
->alloc_ctx
);
1392 /* Unregister video device */
1393 video_unregister_device(ch
->video_dev
);
1395 ch
->video_dev
= NULL
;
1396 kfree(vpif_obj
.dev
[i
]);
1402 #ifdef CONFIG_PM_SLEEP
1403 static int vpif_suspend(struct device
*dev
)
1405 struct common_obj
*common
;
1406 struct channel_obj
*ch
;
1409 for (i
= 0; i
< VPIF_DISPLAY_MAX_DEVICES
; i
++) {
1410 /* Get the pointer to the channel object */
1411 ch
= vpif_obj
.dev
[i
];
1412 common
= &ch
->common
[VPIF_VIDEO_INDEX
];
1414 if (!vb2_is_streaming(&common
->buffer_queue
))
1417 mutex_lock(&common
->lock
);
1418 /* Disable channel */
1419 if (ch
->channel_id
== VPIF_CHANNEL2_VIDEO
) {
1421 channel2_intr_enable(0);
1423 if (ch
->channel_id
== VPIF_CHANNEL3_VIDEO
||
1426 channel3_intr_enable(0);
1428 mutex_unlock(&common
->lock
);
1434 static int vpif_resume(struct device
*dev
)
1437 struct common_obj
*common
;
1438 struct channel_obj
*ch
;
1441 for (i
= 0; i
< VPIF_DISPLAY_MAX_DEVICES
; i
++) {
1442 /* Get the pointer to the channel object */
1443 ch
= vpif_obj
.dev
[i
];
1444 common
= &ch
->common
[VPIF_VIDEO_INDEX
];
1446 if (!vb2_is_streaming(&common
->buffer_queue
))
1449 mutex_lock(&common
->lock
);
1450 /* Enable channel */
1451 if (ch
->channel_id
== VPIF_CHANNEL2_VIDEO
) {
1453 channel2_intr_enable(1);
1455 if (ch
->channel_id
== VPIF_CHANNEL3_VIDEO
||
1458 channel3_intr_enable(1);
1460 mutex_unlock(&common
->lock
);
1468 static SIMPLE_DEV_PM_OPS(vpif_pm_ops
, vpif_suspend
, vpif_resume
);
1470 static __refdata
struct platform_driver vpif_driver
= {
1472 .name
= VPIF_DRIVER_NAME
,
1473 .owner
= THIS_MODULE
,
1476 .probe
= vpif_probe
,
1477 .remove
= vpif_remove
,
1480 module_platform_driver(vpif_driver
);