2 * Copyright (C) 2008-2009 Texas Instruments Inc
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Driver name : VPFE Capture driver
19 * VPFE Capture driver allows applications to capture and stream video
20 * frames on DaVinci SoCs (DM6446, DM355 etc) from a YUV source such as
21 * TVP5146 or Raw Bayer RGB image data from an image sensor
22 * such as Microns' MT9T001, MT9T031 etc.
24 * These SoCs have, in common, a Video Processing Subsystem (VPSS) that
25 * consists of a Video Processing Front End (VPFE) for capturing
26 * video/raw image data and Video Processing Back End (VPBE) for displaying
27 * YUV data through an in-built analog encoder or Digital LCD port. This
28 * driver is for capture through VPFE. A typical EVM using these SoCs have
29 * following high level configuration.
32 * decoder(TVP5146/ YUV/
33 * MT9T001) --> Raw Bayer RGB ---> MUX -> VPFE (CCDC/ISIF)
42 * The data flow happens from a decoder connected to the VPFE over a
43 * YUV embedded (BT.656/BT.1120) or separate sync or raw bayer rgb interface
44 * and to the input of VPFE through an optional MUX (if more inputs are
45 * to be interfaced on the EVM). The input data is first passed through
46 * CCDC (CCD Controller, a.k.a Image Sensor Interface, ISIF). The CCDC
47 * does very little or no processing on YUV data and does pre-process Raw
48 * Bayer RGB data through modules such as Defect Pixel Correction (DFC)
49 * Color Space Conversion (CSC), data gain/offset etc. After this, data
50 * can be written to SDRAM or can be connected to the image processing
51 * block such as IPIPE (on DM355 only).
55 * - Capture using TVP5146 over BT.656
56 * - support for interfacing decoders using sub device model
57 * - Work with DM355 or DM6446 CCDC to do Raw Bayer RGB/YUV
58 * data capture to SDRAM.
60 * - Support multiple REQBUF after open
61 * - Support for de-allocating buffers through REQBUF
62 * - Support for Raw Bayer RGB capture
63 * - Support for chaining Image Processor
64 * - Support for static allocation of buffers
65 * - Support for USERPTR IO
66 * - Support for STREAMON before QBUF
67 * - Support for control ioctls
69 #include <linux/module.h>
70 #include <linux/slab.h>
71 #include <linux/init.h>
72 #include <linux/platform_device.h>
73 #include <linux/interrupt.h>
74 #include <media/v4l2-common.h>
76 #include <media/davinci/vpfe_capture.h>
77 #include "ccdc_hw_device.h"
80 static u32 numbuffers
= 3;
81 static u32 bufsize
= (720 * 576 * 2);
83 module_param(numbuffers
, uint
, S_IRUGO
);
84 module_param(bufsize
, uint
, S_IRUGO
);
85 module_param(debug
, int, 0644);
87 MODULE_PARM_DESC(numbuffers
, "buffer count (default:3)");
88 MODULE_PARM_DESC(bufsize
, "buffer size in bytes (default:720 x 576 x 2)");
89 MODULE_PARM_DESC(debug
, "Debug level 0-1");
91 MODULE_DESCRIPTION("VPFE Video for Linux Capture Driver");
92 MODULE_LICENSE("GPL");
93 MODULE_AUTHOR("Texas Instruments");
95 /* standard information */
96 struct vpfe_standard
{
100 struct v4l2_fract pixelaspect
;
101 /* 0 - progressive, 1 - interlaced */
105 /* ccdc configuration */
107 /* This make sure vpfe is probed and ready to go */
109 /* name of ccdc device */
113 /* data structures */
114 static struct vpfe_config_params config_params
= {
117 .min_bufsize
= 720 * 480 * 2,
118 .device_bufsize
= 720 * 576 * 2,
121 /* ccdc device registered */
122 static struct ccdc_hw_device
*ccdc_dev
;
123 /* lock for accessing ccdc information */
124 static DEFINE_MUTEX(ccdc_lock
);
125 /* ccdc configuration */
126 static struct ccdc_config
*ccdc_cfg
;
128 static const struct vpfe_standard vpfe_standards
[] = {
129 {V4L2_STD_525_60
, 720, 480, {11, 10}, 1},
130 {V4L2_STD_625_50
, 720, 576, {54, 59}, 1},
133 /* Used when raw Bayer image from ccdc is directly captured to SDRAM */
134 static const struct vpfe_pixel_format vpfe_pix_fmts
[] = {
138 .type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
,
139 .description
= "Bayer GrRBGb 8bit A-Law compr.",
140 .pixelformat
= V4L2_PIX_FMT_SBGGR8
,
147 .type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
,
148 .description
= "Bayer GrRBGb - 16bit",
149 .pixelformat
= V4L2_PIX_FMT_SBGGR16
,
156 .type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
,
157 .description
= "Bayer GrRBGb 8bit DPCM compr.",
158 .pixelformat
= V4L2_PIX_FMT_SGRBG10DPCM8
,
165 .type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
,
166 .description
= "YCbCr 4:2:2 Interleaved UYVY",
167 .pixelformat
= V4L2_PIX_FMT_UYVY
,
174 .type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
,
175 .description
= "YCbCr 4:2:2 Interleaved YUYV",
176 .pixelformat
= V4L2_PIX_FMT_YUYV
,
183 .type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
,
184 .description
= "Y/CbCr 4:2:0 - Semi planar",
185 .pixelformat
= V4L2_PIX_FMT_NV12
,
192 * vpfe_lookup_pix_format()
193 * lookup an entry in the vpfe pix format table based on pix_format
195 static const struct vpfe_pixel_format
*vpfe_lookup_pix_format(u32 pix_format
)
199 for (i
= 0; i
< ARRAY_SIZE(vpfe_pix_fmts
); i
++) {
200 if (pix_format
== vpfe_pix_fmts
[i
].fmtdesc
.pixelformat
)
201 return &vpfe_pix_fmts
[i
];
207 * vpfe_register_ccdc_device. CCDC module calls this to
208 * register with vpfe capture
210 int vpfe_register_ccdc_device(struct ccdc_hw_device
*dev
)
213 printk(KERN_NOTICE
"vpfe_register_ccdc_device: %s\n", dev
->name
);
215 BUG_ON(!dev
->hw_ops
.open
);
216 BUG_ON(!dev
->hw_ops
.enable
);
217 BUG_ON(!dev
->hw_ops
.set_hw_if_params
);
218 BUG_ON(!dev
->hw_ops
.configure
);
219 BUG_ON(!dev
->hw_ops
.set_buftype
);
220 BUG_ON(!dev
->hw_ops
.get_buftype
);
221 BUG_ON(!dev
->hw_ops
.enum_pix
);
222 BUG_ON(!dev
->hw_ops
.set_frame_format
);
223 BUG_ON(!dev
->hw_ops
.get_frame_format
);
224 BUG_ON(!dev
->hw_ops
.get_pixel_format
);
225 BUG_ON(!dev
->hw_ops
.set_pixel_format
);
226 BUG_ON(!dev
->hw_ops
.set_image_window
);
227 BUG_ON(!dev
->hw_ops
.get_image_window
);
228 BUG_ON(!dev
->hw_ops
.get_line_length
);
229 BUG_ON(!dev
->hw_ops
.getfid
);
231 mutex_lock(&ccdc_lock
);
232 if (NULL
== ccdc_cfg
) {
234 * TODO. Will this ever happen? if so, we need to fix it.
235 * Proabably we need to add the request to a linked list and
236 * walk through it during vpfe probe
238 printk(KERN_ERR
"vpfe capture not initialized\n");
243 if (strcmp(dev
->name
, ccdc_cfg
->name
)) {
244 /* ignore this ccdc */
250 printk(KERN_ERR
"ccdc already registered\n");
257 mutex_unlock(&ccdc_lock
);
260 EXPORT_SYMBOL(vpfe_register_ccdc_device
);
263 * vpfe_unregister_ccdc_device. CCDC module calls this to
264 * unregister with vpfe capture
266 void vpfe_unregister_ccdc_device(struct ccdc_hw_device
*dev
)
269 printk(KERN_ERR
"invalid ccdc device ptr\n");
273 printk(KERN_NOTICE
"vpfe_unregister_ccdc_device, dev->name = %s\n",
276 if (strcmp(dev
->name
, ccdc_cfg
->name
)) {
277 /* ignore this ccdc */
281 mutex_lock(&ccdc_lock
);
283 mutex_unlock(&ccdc_lock
);
286 EXPORT_SYMBOL(vpfe_unregister_ccdc_device
);
289 * vpfe_get_ccdc_image_format - Get image parameters based on CCDC settings
291 static int vpfe_get_ccdc_image_format(struct vpfe_device
*vpfe_dev
,
292 struct v4l2_format
*f
)
294 struct v4l2_rect image_win
;
295 enum ccdc_buftype buf_type
;
296 enum ccdc_frmfmt frm_fmt
;
298 memset(f
, 0, sizeof(*f
));
299 f
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
300 ccdc_dev
->hw_ops
.get_image_window(&image_win
);
301 f
->fmt
.pix
.width
= image_win
.width
;
302 f
->fmt
.pix
.height
= image_win
.height
;
303 f
->fmt
.pix
.bytesperline
= ccdc_dev
->hw_ops
.get_line_length();
304 f
->fmt
.pix
.sizeimage
= f
->fmt
.pix
.bytesperline
*
306 buf_type
= ccdc_dev
->hw_ops
.get_buftype();
307 f
->fmt
.pix
.pixelformat
= ccdc_dev
->hw_ops
.get_pixel_format();
308 frm_fmt
= ccdc_dev
->hw_ops
.get_frame_format();
309 if (frm_fmt
== CCDC_FRMFMT_PROGRESSIVE
)
310 f
->fmt
.pix
.field
= V4L2_FIELD_NONE
;
311 else if (frm_fmt
== CCDC_FRMFMT_INTERLACED
) {
312 if (buf_type
== CCDC_BUFTYPE_FLD_INTERLEAVED
)
313 f
->fmt
.pix
.field
= V4L2_FIELD_INTERLACED
;
314 else if (buf_type
== CCDC_BUFTYPE_FLD_SEPARATED
)
315 f
->fmt
.pix
.field
= V4L2_FIELD_SEQ_TB
;
317 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid buf_type\n");
321 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid frm_fmt\n");
328 * vpfe_config_ccdc_image_format()
329 * For a pix format, configure ccdc to setup the capture
331 static int vpfe_config_ccdc_image_format(struct vpfe_device
*vpfe_dev
)
333 enum ccdc_frmfmt frm_fmt
= CCDC_FRMFMT_INTERLACED
;
336 if (ccdc_dev
->hw_ops
.set_pixel_format(
337 vpfe_dev
->fmt
.fmt
.pix
.pixelformat
) < 0) {
338 v4l2_err(&vpfe_dev
->v4l2_dev
,
339 "couldn't set pix format in ccdc\n");
342 /* configure the image window */
343 ccdc_dev
->hw_ops
.set_image_window(&vpfe_dev
->crop
);
345 switch (vpfe_dev
->fmt
.fmt
.pix
.field
) {
346 case V4L2_FIELD_INTERLACED
:
347 /* do nothing, since it is default */
348 ret
= ccdc_dev
->hw_ops
.set_buftype(
349 CCDC_BUFTYPE_FLD_INTERLEAVED
);
351 case V4L2_FIELD_NONE
:
352 frm_fmt
= CCDC_FRMFMT_PROGRESSIVE
;
353 /* buffer type only applicable for interlaced scan */
355 case V4L2_FIELD_SEQ_TB
:
356 ret
= ccdc_dev
->hw_ops
.set_buftype(
357 CCDC_BUFTYPE_FLD_SEPARATED
);
363 /* set the frame format */
365 ret
= ccdc_dev
->hw_ops
.set_frame_format(frm_fmt
);
369 * vpfe_config_image_format()
370 * For a given standard, this functions sets up the default
371 * pix format & crop values in the vpfe device and ccdc. It first
372 * starts with defaults based values from the standard table.
373 * It then checks if sub device supports get_fmt and then override the
374 * values based on that.Sets crop values to match with scan resolution
375 * starting at 0,0. It calls vpfe_config_ccdc_image_format() set the
378 static int vpfe_config_image_format(struct vpfe_device
*vpfe_dev
,
381 struct vpfe_subdev_info
*sdinfo
= vpfe_dev
->current_subdev
;
382 struct v4l2_subdev_format fmt
= {
383 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
385 struct v4l2_mbus_framefmt
*mbus_fmt
= &fmt
.format
;
386 struct v4l2_pix_format
*pix
= &vpfe_dev
->fmt
.fmt
.pix
;
389 for (i
= 0; i
< ARRAY_SIZE(vpfe_standards
); i
++) {
390 if (vpfe_standards
[i
].std_id
& std_id
) {
391 vpfe_dev
->std_info
.active_pixels
=
392 vpfe_standards
[i
].width
;
393 vpfe_dev
->std_info
.active_lines
=
394 vpfe_standards
[i
].height
;
395 vpfe_dev
->std_info
.frame_format
=
396 vpfe_standards
[i
].frame_format
;
397 vpfe_dev
->std_index
= i
;
402 if (i
== ARRAY_SIZE(vpfe_standards
)) {
403 v4l2_err(&vpfe_dev
->v4l2_dev
, "standard not supported\n");
407 vpfe_dev
->crop
.top
= 0;
408 vpfe_dev
->crop
.left
= 0;
409 vpfe_dev
->crop
.width
= vpfe_dev
->std_info
.active_pixels
;
410 vpfe_dev
->crop
.height
= vpfe_dev
->std_info
.active_lines
;
411 pix
->width
= vpfe_dev
->crop
.width
;
412 pix
->height
= vpfe_dev
->crop
.height
;
414 /* first field and frame format based on standard frame format */
415 if (vpfe_dev
->std_info
.frame_format
) {
416 pix
->field
= V4L2_FIELD_INTERLACED
;
417 /* assume V4L2_PIX_FMT_UYVY as default */
418 pix
->pixelformat
= V4L2_PIX_FMT_UYVY
;
419 v4l2_fill_mbus_format(mbus_fmt
, pix
,
420 MEDIA_BUS_FMT_YUYV10_2X10
);
422 pix
->field
= V4L2_FIELD_NONE
;
423 /* assume V4L2_PIX_FMT_SBGGR8 */
424 pix
->pixelformat
= V4L2_PIX_FMT_SBGGR8
;
425 v4l2_fill_mbus_format(mbus_fmt
, pix
,
426 MEDIA_BUS_FMT_SBGGR8_1X8
);
429 /* if sub device supports get_fmt, override the defaults */
430 ret
= v4l2_device_call_until_err(&vpfe_dev
->v4l2_dev
,
431 sdinfo
->grp_id
, pad
, get_fmt
, NULL
, &fmt
);
433 if (ret
&& ret
!= -ENOIOCTLCMD
) {
434 v4l2_err(&vpfe_dev
->v4l2_dev
,
435 "error in getting get_fmt from sub device\n");
438 v4l2_fill_pix_format(pix
, mbus_fmt
);
439 pix
->bytesperline
= pix
->width
* 2;
440 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
442 /* Sets the values in CCDC */
443 ret
= vpfe_config_ccdc_image_format(vpfe_dev
);
447 /* Update the values of sizeimage and bytesperline */
448 pix
->bytesperline
= ccdc_dev
->hw_ops
.get_line_length();
449 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
454 static int vpfe_initialize_device(struct vpfe_device
*vpfe_dev
)
458 /* set first input of current subdevice as the current input */
459 vpfe_dev
->current_input
= 0;
461 /* set default standard */
462 vpfe_dev
->std_index
= 0;
464 /* Configure the default format information */
465 ret
= vpfe_config_image_format(vpfe_dev
,
466 vpfe_standards
[vpfe_dev
->std_index
].std_id
);
470 /* now open the ccdc device to initialize it */
471 mutex_lock(&ccdc_lock
);
472 if (NULL
== ccdc_dev
) {
473 v4l2_err(&vpfe_dev
->v4l2_dev
, "ccdc device not registered\n");
478 if (!try_module_get(ccdc_dev
->owner
)) {
479 v4l2_err(&vpfe_dev
->v4l2_dev
, "Couldn't lock ccdc module\n");
483 ret
= ccdc_dev
->hw_ops
.open(vpfe_dev
->pdev
);
485 vpfe_dev
->initialized
= 1;
487 /* Clear all VPFE/CCDC interrupts */
488 if (vpfe_dev
->cfg
->clr_intr
)
489 vpfe_dev
->cfg
->clr_intr(-1);
492 mutex_unlock(&ccdc_lock
);
497 * vpfe_open : It creates object of file handle structure and
498 * stores it in private_data member of filepointer
500 static int vpfe_open(struct file
*file
)
502 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
503 struct video_device
*vdev
= video_devdata(file
);
506 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_open\n");
508 if (!vpfe_dev
->cfg
->num_subdevs
) {
509 v4l2_err(&vpfe_dev
->v4l2_dev
, "No decoder registered\n");
513 /* Allocate memory for the file handle object */
514 fh
= kmalloc(sizeof(struct vpfe_fh
), GFP_KERNEL
);
516 v4l2_err(&vpfe_dev
->v4l2_dev
,
517 "unable to allocate memory for file handle object\n");
520 /* store pointer to fh in private_data member of file */
521 file
->private_data
= fh
;
522 fh
->vpfe_dev
= vpfe_dev
;
523 v4l2_fh_init(&fh
->fh
, vdev
);
524 mutex_lock(&vpfe_dev
->lock
);
525 /* If decoder is not initialized. initialize it */
526 if (!vpfe_dev
->initialized
) {
527 if (vpfe_initialize_device(vpfe_dev
)) {
528 mutex_unlock(&vpfe_dev
->lock
);
532 /* Increment device usrs counter */
534 /* Set io_allowed member to false */
536 v4l2_fh_add(&fh
->fh
);
537 mutex_unlock(&vpfe_dev
->lock
);
541 static void vpfe_schedule_next_buffer(struct vpfe_device
*vpfe_dev
)
545 vpfe_dev
->next_frm
= list_entry(vpfe_dev
->dma_queue
.next
,
546 struct videobuf_buffer
, queue
);
547 list_del(&vpfe_dev
->next_frm
->queue
);
548 vpfe_dev
->next_frm
->state
= VIDEOBUF_ACTIVE
;
549 addr
= videobuf_to_dma_contig(vpfe_dev
->next_frm
);
551 ccdc_dev
->hw_ops
.setfbaddr(addr
);
554 static void vpfe_schedule_bottom_field(struct vpfe_device
*vpfe_dev
)
558 addr
= videobuf_to_dma_contig(vpfe_dev
->cur_frm
);
559 addr
+= vpfe_dev
->field_off
;
560 ccdc_dev
->hw_ops
.setfbaddr(addr
);
563 static void vpfe_process_buffer_complete(struct vpfe_device
*vpfe_dev
)
565 v4l2_get_timestamp(&vpfe_dev
->cur_frm
->ts
);
566 vpfe_dev
->cur_frm
->state
= VIDEOBUF_DONE
;
567 vpfe_dev
->cur_frm
->size
= vpfe_dev
->fmt
.fmt
.pix
.sizeimage
;
568 wake_up_interruptible(&vpfe_dev
->cur_frm
->done
);
569 vpfe_dev
->cur_frm
= vpfe_dev
->next_frm
;
573 static irqreturn_t
vpfe_isr(int irq
, void *dev_id
)
575 struct vpfe_device
*vpfe_dev
= dev_id
;
576 enum v4l2_field field
;
579 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "\nStarting vpfe_isr...\n");
580 field
= vpfe_dev
->fmt
.fmt
.pix
.field
;
582 /* if streaming not started, don't do anything */
583 if (!vpfe_dev
->started
)
586 /* only for 6446 this will be applicable */
587 if (NULL
!= ccdc_dev
->hw_ops
.reset
)
588 ccdc_dev
->hw_ops
.reset();
590 if (field
== V4L2_FIELD_NONE
) {
591 /* handle progressive frame capture */
592 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
,
593 "frame format is progressive...\n");
594 if (vpfe_dev
->cur_frm
!= vpfe_dev
->next_frm
)
595 vpfe_process_buffer_complete(vpfe_dev
);
599 /* interlaced or TB capture check which field we are in hardware */
600 fid
= ccdc_dev
->hw_ops
.getfid();
602 /* switch the software maintained field id */
603 vpfe_dev
->field_id
^= 1;
604 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "field id = %x:%x.\n",
605 fid
, vpfe_dev
->field_id
);
606 if (fid
== vpfe_dev
->field_id
) {
607 /* we are in-sync here,continue */
610 * One frame is just being captured. If the next frame
611 * is available, release the current frame and move on
613 if (vpfe_dev
->cur_frm
!= vpfe_dev
->next_frm
)
614 vpfe_process_buffer_complete(vpfe_dev
);
616 * based on whether the two fields are stored
617 * interleavely or separately in memory, reconfigure
618 * the CCDC memory address
620 if (field
== V4L2_FIELD_SEQ_TB
) {
621 vpfe_schedule_bottom_field(vpfe_dev
);
626 * if one field is just being captured configure
627 * the next frame get the next frame from the empty
628 * queue if no frame is available hold on to the
631 spin_lock(&vpfe_dev
->dma_queue_lock
);
632 if (!list_empty(&vpfe_dev
->dma_queue
) &&
633 vpfe_dev
->cur_frm
== vpfe_dev
->next_frm
)
634 vpfe_schedule_next_buffer(vpfe_dev
);
635 spin_unlock(&vpfe_dev
->dma_queue_lock
);
636 } else if (fid
== 0) {
638 * out of sync. Recover from any hardware out-of-sync.
639 * May loose one frame
641 vpfe_dev
->field_id
= fid
;
644 if (vpfe_dev
->cfg
->clr_intr
)
645 vpfe_dev
->cfg
->clr_intr(irq
);
650 /* vdint1_isr - isr handler for VINT1 interrupt */
651 static irqreturn_t
vdint1_isr(int irq
, void *dev_id
)
653 struct vpfe_device
*vpfe_dev
= dev_id
;
655 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "\nInside vdint1_isr...\n");
657 /* if streaming not started, don't do anything */
658 if (!vpfe_dev
->started
) {
659 if (vpfe_dev
->cfg
->clr_intr
)
660 vpfe_dev
->cfg
->clr_intr(irq
);
664 spin_lock(&vpfe_dev
->dma_queue_lock
);
665 if ((vpfe_dev
->fmt
.fmt
.pix
.field
== V4L2_FIELD_NONE
) &&
666 !list_empty(&vpfe_dev
->dma_queue
) &&
667 vpfe_dev
->cur_frm
== vpfe_dev
->next_frm
)
668 vpfe_schedule_next_buffer(vpfe_dev
);
669 spin_unlock(&vpfe_dev
->dma_queue_lock
);
671 if (vpfe_dev
->cfg
->clr_intr
)
672 vpfe_dev
->cfg
->clr_intr(irq
);
677 static void vpfe_detach_irq(struct vpfe_device
*vpfe_dev
)
679 enum ccdc_frmfmt frame_format
;
681 frame_format
= ccdc_dev
->hw_ops
.get_frame_format();
682 if (frame_format
== CCDC_FRMFMT_PROGRESSIVE
)
683 free_irq(vpfe_dev
->ccdc_irq1
, vpfe_dev
);
686 static int vpfe_attach_irq(struct vpfe_device
*vpfe_dev
)
688 enum ccdc_frmfmt frame_format
;
690 frame_format
= ccdc_dev
->hw_ops
.get_frame_format();
691 if (frame_format
== CCDC_FRMFMT_PROGRESSIVE
) {
692 return request_irq(vpfe_dev
->ccdc_irq1
, vdint1_isr
,
699 /* vpfe_stop_ccdc_capture: stop streaming in ccdc/isif */
700 static void vpfe_stop_ccdc_capture(struct vpfe_device
*vpfe_dev
)
702 vpfe_dev
->started
= 0;
703 ccdc_dev
->hw_ops
.enable(0);
704 if (ccdc_dev
->hw_ops
.enable_out_to_sdram
)
705 ccdc_dev
->hw_ops
.enable_out_to_sdram(0);
709 * vpfe_release : This function deletes buffer queue, frees the
710 * buffers and the vpfe file handle
712 static int vpfe_release(struct file
*file
)
714 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
715 struct vpfe_fh
*fh
= file
->private_data
;
716 struct vpfe_subdev_info
*sdinfo
;
719 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_release\n");
721 /* Get the device lock */
722 mutex_lock(&vpfe_dev
->lock
);
723 /* if this instance is doing IO */
724 if (fh
->io_allowed
) {
725 if (vpfe_dev
->started
) {
726 sdinfo
= vpfe_dev
->current_subdev
;
727 ret
= v4l2_device_call_until_err(&vpfe_dev
->v4l2_dev
,
730 if (ret
&& (ret
!= -ENOIOCTLCMD
))
731 v4l2_err(&vpfe_dev
->v4l2_dev
,
732 "stream off failed in subdev\n");
733 vpfe_stop_ccdc_capture(vpfe_dev
);
734 vpfe_detach_irq(vpfe_dev
);
735 videobuf_streamoff(&vpfe_dev
->buffer_queue
);
737 vpfe_dev
->io_usrs
= 0;
738 vpfe_dev
->numbuffers
= config_params
.numbuffers
;
739 videobuf_stop(&vpfe_dev
->buffer_queue
);
740 videobuf_mmap_free(&vpfe_dev
->buffer_queue
);
743 /* Decrement device usrs counter */
745 v4l2_fh_del(&fh
->fh
);
746 v4l2_fh_exit(&fh
->fh
);
747 /* If this is the last file handle */
748 if (!vpfe_dev
->usrs
) {
749 vpfe_dev
->initialized
= 0;
750 if (ccdc_dev
->hw_ops
.close
)
751 ccdc_dev
->hw_ops
.close(vpfe_dev
->pdev
);
752 module_put(ccdc_dev
->owner
);
754 mutex_unlock(&vpfe_dev
->lock
);
755 file
->private_data
= NULL
;
756 /* Free memory allocated to file handle object */
762 * vpfe_mmap : It is used to map kernel space buffers
765 static int vpfe_mmap(struct file
*file
, struct vm_area_struct
*vma
)
767 /* Get the device object and file handle object */
768 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
770 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_mmap\n");
772 return videobuf_mmap_mapper(&vpfe_dev
->buffer_queue
, vma
);
776 * vpfe_poll: It is used for select/poll system call
778 static unsigned int vpfe_poll(struct file
*file
, poll_table
*wait
)
780 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
782 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_poll\n");
784 if (vpfe_dev
->started
)
785 return videobuf_poll_stream(file
,
786 &vpfe_dev
->buffer_queue
, wait
);
790 /* vpfe capture driver file operations */
791 static const struct v4l2_file_operations vpfe_fops
= {
792 .owner
= THIS_MODULE
,
794 .release
= vpfe_release
,
795 .unlocked_ioctl
= video_ioctl2
,
801 * vpfe_check_format()
802 * This function adjust the input pixel format as per hardware
803 * capabilities and update the same in pixfmt.
804 * Following algorithm used :-
806 * If given pixformat is not in the vpfe list of pix formats or not
807 * supported by the hardware, current value of pixformat in the device
809 * If given field is not supported, then current field is used. If field
810 * is different from current, then it is matched with that from sub device.
811 * Minimum height is 2 lines for interlaced or tb field and 1 line for
812 * progressive. Maximum height is clamped to active active lines of scan
813 * Minimum width is 32 bytes in memory and width is clamped to active
815 * bytesperline is a multiple of 32.
817 static const struct vpfe_pixel_format
*
818 vpfe_check_format(struct vpfe_device
*vpfe_dev
,
819 struct v4l2_pix_format
*pixfmt
)
821 u32 min_height
= 1, min_width
= 32, max_width
, max_height
;
822 const struct vpfe_pixel_format
*vpfe_pix_fmt
;
826 vpfe_pix_fmt
= vpfe_lookup_pix_format(pixfmt
->pixelformat
);
827 if (NULL
== vpfe_pix_fmt
) {
829 * use current pixel format in the vpfe device. We
830 * will find this pix format in the table
832 pixfmt
->pixelformat
= vpfe_dev
->fmt
.fmt
.pix
.pixelformat
;
833 vpfe_pix_fmt
= vpfe_lookup_pix_format(pixfmt
->pixelformat
);
836 /* check if hw supports it */
839 while (ccdc_dev
->hw_ops
.enum_pix(&pix
, temp
) >= 0) {
840 if (vpfe_pix_fmt
->fmtdesc
.pixelformat
== pix
) {
848 /* use current pixel format */
849 pixfmt
->pixelformat
= vpfe_dev
->fmt
.fmt
.pix
.pixelformat
;
851 * Since this is currently used in the vpfe device, we
852 * will find this pix format in the table
854 vpfe_pix_fmt
= vpfe_lookup_pix_format(pixfmt
->pixelformat
);
857 /* check what field format is supported */
858 if (pixfmt
->field
== V4L2_FIELD_ANY
) {
859 /* if field is any, use current value as default */
860 pixfmt
->field
= vpfe_dev
->fmt
.fmt
.pix
.field
;
864 * if field is not same as current field in the vpfe device
865 * try matching the field with the sub device field
867 if (vpfe_dev
->fmt
.fmt
.pix
.field
!= pixfmt
->field
) {
869 * If field value is not in the supported fields, use current
870 * field used in the device as default
872 switch (pixfmt
->field
) {
873 case V4L2_FIELD_INTERLACED
:
874 case V4L2_FIELD_SEQ_TB
:
875 /* if sub device is supporting progressive, use that */
876 if (!vpfe_dev
->std_info
.frame_format
)
877 pixfmt
->field
= V4L2_FIELD_NONE
;
879 case V4L2_FIELD_NONE
:
880 if (vpfe_dev
->std_info
.frame_format
)
881 pixfmt
->field
= V4L2_FIELD_INTERLACED
;
885 /* use current field as default */
886 pixfmt
->field
= vpfe_dev
->fmt
.fmt
.pix
.field
;
891 /* Now adjust image resolutions supported */
892 if (pixfmt
->field
== V4L2_FIELD_INTERLACED
||
893 pixfmt
->field
== V4L2_FIELD_SEQ_TB
)
896 max_width
= vpfe_dev
->std_info
.active_pixels
;
897 max_height
= vpfe_dev
->std_info
.active_lines
;
898 min_width
/= vpfe_pix_fmt
->bpp
;
900 v4l2_info(&vpfe_dev
->v4l2_dev
, "width = %d, height = %d, bpp = %d\n",
901 pixfmt
->width
, pixfmt
->height
, vpfe_pix_fmt
->bpp
);
903 pixfmt
->width
= clamp((pixfmt
->width
), min_width
, max_width
);
904 pixfmt
->height
= clamp((pixfmt
->height
), min_height
, max_height
);
906 /* If interlaced, adjust height to be a multiple of 2 */
907 if (pixfmt
->field
== V4L2_FIELD_INTERLACED
)
908 pixfmt
->height
&= (~1);
910 * recalculate bytesperline and sizeimage since width
911 * and height might have changed
913 pixfmt
->bytesperline
= (((pixfmt
->width
* vpfe_pix_fmt
->bpp
) + 31)
915 if (pixfmt
->pixelformat
== V4L2_PIX_FMT_NV12
)
917 pixfmt
->bytesperline
* pixfmt
->height
+
918 ((pixfmt
->bytesperline
* pixfmt
->height
) >> 1);
920 pixfmt
->sizeimage
= pixfmt
->bytesperline
* pixfmt
->height
;
922 v4l2_info(&vpfe_dev
->v4l2_dev
, "adjusted width = %d, height ="
923 " %d, bpp = %d, bytesperline = %d, sizeimage = %d\n",
924 pixfmt
->width
, pixfmt
->height
, vpfe_pix_fmt
->bpp
,
925 pixfmt
->bytesperline
, pixfmt
->sizeimage
);
929 static int vpfe_querycap(struct file
*file
, void *priv
,
930 struct v4l2_capability
*cap
)
932 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
934 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_querycap\n");
936 cap
->device_caps
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_STREAMING
;
937 cap
->capabilities
= cap
->device_caps
| V4L2_CAP_DEVICE_CAPS
;
938 strlcpy(cap
->driver
, CAPTURE_DRV_NAME
, sizeof(cap
->driver
));
939 strlcpy(cap
->bus_info
, "VPFE", sizeof(cap
->bus_info
));
940 strlcpy(cap
->card
, vpfe_dev
->cfg
->card_name
, sizeof(cap
->card
));
944 static int vpfe_g_fmt_vid_cap(struct file
*file
, void *priv
,
945 struct v4l2_format
*fmt
)
947 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
949 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_g_fmt_vid_cap\n");
950 /* Fill in the information about format */
951 *fmt
= vpfe_dev
->fmt
;
955 static int vpfe_enum_fmt_vid_cap(struct file
*file
, void *priv
,
956 struct v4l2_fmtdesc
*fmt
)
958 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
959 const struct vpfe_pixel_format
*pix_fmt
;
963 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_enum_fmt_vid_cap\n");
965 if (ccdc_dev
->hw_ops
.enum_pix(&pix
, fmt
->index
) < 0)
968 /* Fill in the information about format */
969 pix_fmt
= vpfe_lookup_pix_format(pix
);
970 if (NULL
!= pix_fmt
) {
971 temp_index
= fmt
->index
;
972 *fmt
= pix_fmt
->fmtdesc
;
973 fmt
->index
= temp_index
;
979 static int vpfe_s_fmt_vid_cap(struct file
*file
, void *priv
,
980 struct v4l2_format
*fmt
)
982 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
983 const struct vpfe_pixel_format
*pix_fmts
;
986 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_s_fmt_vid_cap\n");
988 /* If streaming is started, return error */
989 if (vpfe_dev
->started
) {
990 v4l2_err(&vpfe_dev
->v4l2_dev
, "Streaming is started\n");
994 /* Check for valid frame format */
995 pix_fmts
= vpfe_check_format(vpfe_dev
, &fmt
->fmt
.pix
);
997 if (NULL
== pix_fmts
)
1000 /* store the pixel format in the device object */
1001 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1005 /* First detach any IRQ if currently attached */
1006 vpfe_detach_irq(vpfe_dev
);
1007 vpfe_dev
->fmt
= *fmt
;
1008 /* set image capture parameters in the ccdc */
1009 ret
= vpfe_config_ccdc_image_format(vpfe_dev
);
1010 mutex_unlock(&vpfe_dev
->lock
);
1014 static int vpfe_try_fmt_vid_cap(struct file
*file
, void *priv
,
1015 struct v4l2_format
*f
)
1017 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1018 const struct vpfe_pixel_format
*pix_fmts
;
1020 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_try_fmt_vid_cap\n");
1022 pix_fmts
= vpfe_check_format(vpfe_dev
, &f
->fmt
.pix
);
1023 if (NULL
== pix_fmts
)
1029 * vpfe_get_subdev_input_index - Get subdev index and subdev input index for a
1030 * given app input index
1032 static int vpfe_get_subdev_input_index(struct vpfe_device
*vpfe_dev
,
1034 int *subdev_input_index
,
1035 int app_input_index
)
1037 struct vpfe_config
*cfg
= vpfe_dev
->cfg
;
1038 struct vpfe_subdev_info
*sdinfo
;
1041 for (i
= 0; i
< cfg
->num_subdevs
; i
++) {
1042 sdinfo
= &cfg
->sub_devs
[i
];
1043 if (app_input_index
< (j
+ sdinfo
->num_inputs
)) {
1045 *subdev_input_index
= app_input_index
- j
;
1048 j
+= sdinfo
->num_inputs
;
1054 * vpfe_get_app_input - Get app input index for a given subdev input index
1055 * driver stores the input index of the current sub device and translate it
1056 * when application request the current input
1058 static int vpfe_get_app_input_index(struct vpfe_device
*vpfe_dev
,
1059 int *app_input_index
)
1061 struct vpfe_config
*cfg
= vpfe_dev
->cfg
;
1062 struct vpfe_subdev_info
*sdinfo
;
1065 for (i
= 0; i
< cfg
->num_subdevs
; i
++) {
1066 sdinfo
= &cfg
->sub_devs
[i
];
1067 if (!strcmp(sdinfo
->name
, vpfe_dev
->current_subdev
->name
)) {
1068 if (vpfe_dev
->current_input
>= sdinfo
->num_inputs
)
1070 *app_input_index
= j
+ vpfe_dev
->current_input
;
1073 j
+= sdinfo
->num_inputs
;
1078 static int vpfe_enum_input(struct file
*file
, void *priv
,
1079 struct v4l2_input
*inp
)
1081 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1082 struct vpfe_subdev_info
*sdinfo
;
1085 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_enum_input\n");
1087 if (vpfe_get_subdev_input_index(vpfe_dev
,
1091 v4l2_err(&vpfe_dev
->v4l2_dev
, "input information not found"
1092 " for the subdev\n");
1095 sdinfo
= &vpfe_dev
->cfg
->sub_devs
[subdev
];
1096 memcpy(inp
, &sdinfo
->inputs
[index
], sizeof(struct v4l2_input
));
1100 static int vpfe_g_input(struct file
*file
, void *priv
, unsigned int *index
)
1102 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1104 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_g_input\n");
1106 return vpfe_get_app_input_index(vpfe_dev
, index
);
1110 static int vpfe_s_input(struct file
*file
, void *priv
, unsigned int index
)
1112 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1113 struct v4l2_subdev
*sd
;
1114 struct vpfe_subdev_info
*sdinfo
;
1115 int subdev_index
, inp_index
;
1116 struct vpfe_route
*route
;
1117 u32 input
= 0, output
= 0;
1120 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_s_input\n");
1122 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1127 * If streaming is started return device busy
1130 if (vpfe_dev
->started
) {
1131 v4l2_err(&vpfe_dev
->v4l2_dev
, "Streaming is on\n");
1135 ret
= vpfe_get_subdev_input_index(vpfe_dev
,
1140 v4l2_err(&vpfe_dev
->v4l2_dev
, "invalid input index\n");
1144 sdinfo
= &vpfe_dev
->cfg
->sub_devs
[subdev_index
];
1145 sd
= vpfe_dev
->sd
[subdev_index
];
1146 route
= &sdinfo
->routes
[inp_index
];
1147 if (route
&& sdinfo
->can_route
) {
1148 input
= route
->input
;
1149 output
= route
->output
;
1153 ret
= v4l2_subdev_call(sd
, video
, s_routing
, input
, output
, 0);
1156 v4l2_err(&vpfe_dev
->v4l2_dev
,
1157 "vpfe_doioctl:error in setting input in decoder\n");
1161 vpfe_dev
->current_subdev
= sdinfo
;
1163 vpfe_dev
->v4l2_dev
.ctrl_handler
= sd
->ctrl_handler
;
1164 vpfe_dev
->current_input
= index
;
1165 vpfe_dev
->std_index
= 0;
1167 /* set the bus/interface parameter for the sub device in ccdc */
1168 ret
= ccdc_dev
->hw_ops
.set_hw_if_params(&sdinfo
->ccdc_if_params
);
1172 /* set the default image parameters in the device */
1173 ret
= vpfe_config_image_format(vpfe_dev
,
1174 vpfe_standards
[vpfe_dev
->std_index
].std_id
);
1176 mutex_unlock(&vpfe_dev
->lock
);
1180 static int vpfe_querystd(struct file
*file
, void *priv
, v4l2_std_id
*std_id
)
1182 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1183 struct vpfe_subdev_info
*sdinfo
;
1186 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_querystd\n");
1188 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1189 sdinfo
= vpfe_dev
->current_subdev
;
1192 /* Call querystd function of decoder device */
1193 ret
= v4l2_device_call_until_err(&vpfe_dev
->v4l2_dev
, sdinfo
->grp_id
,
1194 video
, querystd
, std_id
);
1195 mutex_unlock(&vpfe_dev
->lock
);
1199 static int vpfe_s_std(struct file
*file
, void *priv
, v4l2_std_id std_id
)
1201 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1202 struct vpfe_subdev_info
*sdinfo
;
1205 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_s_std\n");
1207 /* Call decoder driver function to set the standard */
1208 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1212 sdinfo
= vpfe_dev
->current_subdev
;
1213 /* If streaming is started, return device busy error */
1214 if (vpfe_dev
->started
) {
1215 v4l2_err(&vpfe_dev
->v4l2_dev
, "streaming is started\n");
1220 ret
= v4l2_device_call_until_err(&vpfe_dev
->v4l2_dev
, sdinfo
->grp_id
,
1221 video
, s_std
, std_id
);
1223 v4l2_err(&vpfe_dev
->v4l2_dev
, "Failed to set standard\n");
1226 ret
= vpfe_config_image_format(vpfe_dev
, std_id
);
1229 mutex_unlock(&vpfe_dev
->lock
);
1233 static int vpfe_g_std(struct file
*file
, void *priv
, v4l2_std_id
*std_id
)
1235 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1237 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_g_std\n");
1239 *std_id
= vpfe_standards
[vpfe_dev
->std_index
].std_id
;
1243 * Videobuf operations
1245 static int vpfe_videobuf_setup(struct videobuf_queue
*vq
,
1246 unsigned int *count
,
1249 struct vpfe_fh
*fh
= vq
->priv_data
;
1250 struct vpfe_device
*vpfe_dev
= fh
->vpfe_dev
;
1252 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_buffer_setup\n");
1253 *size
= vpfe_dev
->fmt
.fmt
.pix
.sizeimage
;
1254 if (vpfe_dev
->memory
== V4L2_MEMORY_MMAP
&&
1255 vpfe_dev
->fmt
.fmt
.pix
.sizeimage
> config_params
.device_bufsize
)
1256 *size
= config_params
.device_bufsize
;
1258 if (*count
< config_params
.min_numbuffers
)
1259 *count
= config_params
.min_numbuffers
;
1260 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
,
1261 "count=%d, size=%d\n", *count
, *size
);
1265 static int vpfe_videobuf_prepare(struct videobuf_queue
*vq
,
1266 struct videobuf_buffer
*vb
,
1267 enum v4l2_field field
)
1269 struct vpfe_fh
*fh
= vq
->priv_data
;
1270 struct vpfe_device
*vpfe_dev
= fh
->vpfe_dev
;
1274 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_buffer_prepare\n");
1276 /* If buffer is not initialized, initialize it */
1277 if (VIDEOBUF_NEEDS_INIT
== vb
->state
) {
1278 vb
->width
= vpfe_dev
->fmt
.fmt
.pix
.width
;
1279 vb
->height
= vpfe_dev
->fmt
.fmt
.pix
.height
;
1280 vb
->size
= vpfe_dev
->fmt
.fmt
.pix
.sizeimage
;
1283 ret
= videobuf_iolock(vq
, vb
, NULL
);
1287 addr
= videobuf_to_dma_contig(vb
);
1288 /* Make sure user addresses are aligned to 32 bytes */
1289 if (!ALIGN(addr
, 32))
1292 vb
->state
= VIDEOBUF_PREPARED
;
1297 static void vpfe_videobuf_queue(struct videobuf_queue
*vq
,
1298 struct videobuf_buffer
*vb
)
1300 /* Get the file handle object and device object */
1301 struct vpfe_fh
*fh
= vq
->priv_data
;
1302 struct vpfe_device
*vpfe_dev
= fh
->vpfe_dev
;
1303 unsigned long flags
;
1305 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_buffer_queue\n");
1307 /* add the buffer to the DMA queue */
1308 spin_lock_irqsave(&vpfe_dev
->dma_queue_lock
, flags
);
1309 list_add_tail(&vb
->queue
, &vpfe_dev
->dma_queue
);
1310 spin_unlock_irqrestore(&vpfe_dev
->dma_queue_lock
, flags
);
1312 /* Change state of the buffer */
1313 vb
->state
= VIDEOBUF_QUEUED
;
1316 static void vpfe_videobuf_release(struct videobuf_queue
*vq
,
1317 struct videobuf_buffer
*vb
)
1319 struct vpfe_fh
*fh
= vq
->priv_data
;
1320 struct vpfe_device
*vpfe_dev
= fh
->vpfe_dev
;
1321 unsigned long flags
;
1323 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_videobuf_release\n");
1326 * We need to flush the buffer from the dma queue since
1327 * they are de-allocated
1329 spin_lock_irqsave(&vpfe_dev
->dma_queue_lock
, flags
);
1330 INIT_LIST_HEAD(&vpfe_dev
->dma_queue
);
1331 spin_unlock_irqrestore(&vpfe_dev
->dma_queue_lock
, flags
);
1332 videobuf_dma_contig_free(vq
, vb
);
1333 vb
->state
= VIDEOBUF_NEEDS_INIT
;
1336 static struct videobuf_queue_ops vpfe_videobuf_qops
= {
1337 .buf_setup
= vpfe_videobuf_setup
,
1338 .buf_prepare
= vpfe_videobuf_prepare
,
1339 .buf_queue
= vpfe_videobuf_queue
,
1340 .buf_release
= vpfe_videobuf_release
,
1344 * vpfe_reqbufs. currently support REQBUF only once opening
1347 static int vpfe_reqbufs(struct file
*file
, void *priv
,
1348 struct v4l2_requestbuffers
*req_buf
)
1350 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1351 struct vpfe_fh
*fh
= file
->private_data
;
1354 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_reqbufs\n");
1356 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= req_buf
->type
) {
1357 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid buffer type\n");
1361 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1365 if (vpfe_dev
->io_usrs
!= 0) {
1366 v4l2_err(&vpfe_dev
->v4l2_dev
, "Only one IO user allowed\n");
1371 vpfe_dev
->memory
= req_buf
->memory
;
1372 videobuf_queue_dma_contig_init(&vpfe_dev
->buffer_queue
,
1373 &vpfe_videobuf_qops
,
1377 vpfe_dev
->fmt
.fmt
.pix
.field
,
1378 sizeof(struct videobuf_buffer
),
1382 vpfe_dev
->io_usrs
= 1;
1383 INIT_LIST_HEAD(&vpfe_dev
->dma_queue
);
1384 ret
= videobuf_reqbufs(&vpfe_dev
->buffer_queue
, req_buf
);
1386 mutex_unlock(&vpfe_dev
->lock
);
1390 static int vpfe_querybuf(struct file
*file
, void *priv
,
1391 struct v4l2_buffer
*buf
)
1393 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1395 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_querybuf\n");
1397 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= buf
->type
) {
1398 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid buf type\n");
1402 if (vpfe_dev
->memory
!= V4L2_MEMORY_MMAP
) {
1403 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid memory\n");
1406 /* Call videobuf_querybuf to get information */
1407 return videobuf_querybuf(&vpfe_dev
->buffer_queue
, buf
);
1410 static int vpfe_qbuf(struct file
*file
, void *priv
,
1411 struct v4l2_buffer
*p
)
1413 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1414 struct vpfe_fh
*fh
= file
->private_data
;
1416 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_qbuf\n");
1418 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= p
->type
) {
1419 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid buf type\n");
1424 * If this file handle is not allowed to do IO,
1427 if (!fh
->io_allowed
) {
1428 v4l2_err(&vpfe_dev
->v4l2_dev
, "fh->io_allowed\n");
1431 return videobuf_qbuf(&vpfe_dev
->buffer_queue
, p
);
1434 static int vpfe_dqbuf(struct file
*file
, void *priv
,
1435 struct v4l2_buffer
*buf
)
1437 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1439 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_dqbuf\n");
1441 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= buf
->type
) {
1442 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid buf type\n");
1445 return videobuf_dqbuf(&vpfe_dev
->buffer_queue
,
1446 buf
, file
->f_flags
& O_NONBLOCK
);
1450 * vpfe_calculate_offsets : This function calculates buffers offset
1451 * for top and bottom field
1453 static void vpfe_calculate_offsets(struct vpfe_device
*vpfe_dev
)
1455 struct v4l2_rect image_win
;
1457 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_calculate_offsets\n");
1459 ccdc_dev
->hw_ops
.get_image_window(&image_win
);
1460 vpfe_dev
->field_off
= image_win
.height
* image_win
.width
;
1463 /* vpfe_start_ccdc_capture: start streaming in ccdc/isif */
1464 static void vpfe_start_ccdc_capture(struct vpfe_device
*vpfe_dev
)
1466 ccdc_dev
->hw_ops
.enable(1);
1467 if (ccdc_dev
->hw_ops
.enable_out_to_sdram
)
1468 ccdc_dev
->hw_ops
.enable_out_to_sdram(1);
1469 vpfe_dev
->started
= 1;
1473 * vpfe_streamon. Assume the DMA queue is not empty.
1474 * application is expected to call QBUF before calling
1475 * this ioctl. If not, driver returns error
1477 static int vpfe_streamon(struct file
*file
, void *priv
,
1478 enum v4l2_buf_type buf_type
)
1480 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1481 struct vpfe_fh
*fh
= file
->private_data
;
1482 struct vpfe_subdev_info
*sdinfo
;
1486 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_streamon\n");
1488 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= buf_type
) {
1489 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid buf type\n");
1493 /* If file handle is not allowed IO, return error */
1494 if (!fh
->io_allowed
) {
1495 v4l2_err(&vpfe_dev
->v4l2_dev
, "fh->io_allowed\n");
1499 sdinfo
= vpfe_dev
->current_subdev
;
1500 ret
= v4l2_device_call_until_err(&vpfe_dev
->v4l2_dev
, sdinfo
->grp_id
,
1501 video
, s_stream
, 1);
1503 if (ret
&& (ret
!= -ENOIOCTLCMD
)) {
1504 v4l2_err(&vpfe_dev
->v4l2_dev
, "stream on failed in subdev\n");
1508 /* If buffer queue is empty, return error */
1509 if (list_empty(&vpfe_dev
->buffer_queue
.stream
)) {
1510 v4l2_err(&vpfe_dev
->v4l2_dev
, "buffer queue is empty\n");
1514 /* Call videobuf_streamon to start streaming * in videobuf */
1515 ret
= videobuf_streamon(&vpfe_dev
->buffer_queue
);
1520 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1523 /* Get the next frame from the buffer queue */
1524 vpfe_dev
->next_frm
= list_entry(vpfe_dev
->dma_queue
.next
,
1525 struct videobuf_buffer
, queue
);
1526 vpfe_dev
->cur_frm
= vpfe_dev
->next_frm
;
1527 /* Remove buffer from the buffer queue */
1528 list_del(&vpfe_dev
->cur_frm
->queue
);
1529 /* Mark state of the current frame to active */
1530 vpfe_dev
->cur_frm
->state
= VIDEOBUF_ACTIVE
;
1531 /* Initialize field_id and started member */
1532 vpfe_dev
->field_id
= 0;
1533 addr
= videobuf_to_dma_contig(vpfe_dev
->cur_frm
);
1535 /* Calculate field offset */
1536 vpfe_calculate_offsets(vpfe_dev
);
1538 if (vpfe_attach_irq(vpfe_dev
) < 0) {
1539 v4l2_err(&vpfe_dev
->v4l2_dev
,
1540 "Error in attaching interrupt handle\n");
1544 if (ccdc_dev
->hw_ops
.configure() < 0) {
1545 v4l2_err(&vpfe_dev
->v4l2_dev
,
1546 "Error in configuring ccdc\n");
1550 ccdc_dev
->hw_ops
.setfbaddr((unsigned long)(addr
));
1551 vpfe_start_ccdc_capture(vpfe_dev
);
1552 mutex_unlock(&vpfe_dev
->lock
);
1555 mutex_unlock(&vpfe_dev
->lock
);
1557 ret
= videobuf_streamoff(&vpfe_dev
->buffer_queue
);
1561 static int vpfe_streamoff(struct file
*file
, void *priv
,
1562 enum v4l2_buf_type buf_type
)
1564 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1565 struct vpfe_fh
*fh
= file
->private_data
;
1566 struct vpfe_subdev_info
*sdinfo
;
1569 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_streamoff\n");
1571 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= buf_type
) {
1572 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid buf type\n");
1576 /* If io is allowed for this file handle, return error */
1577 if (!fh
->io_allowed
) {
1578 v4l2_err(&vpfe_dev
->v4l2_dev
, "fh->io_allowed\n");
1582 /* If streaming is not started, return error */
1583 if (!vpfe_dev
->started
) {
1584 v4l2_err(&vpfe_dev
->v4l2_dev
, "device started\n");
1588 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1592 vpfe_stop_ccdc_capture(vpfe_dev
);
1593 vpfe_detach_irq(vpfe_dev
);
1595 sdinfo
= vpfe_dev
->current_subdev
;
1596 ret
= v4l2_device_call_until_err(&vpfe_dev
->v4l2_dev
, sdinfo
->grp_id
,
1597 video
, s_stream
, 0);
1599 if (ret
&& (ret
!= -ENOIOCTLCMD
))
1600 v4l2_err(&vpfe_dev
->v4l2_dev
, "stream off failed in subdev\n");
1601 ret
= videobuf_streamoff(&vpfe_dev
->buffer_queue
);
1602 mutex_unlock(&vpfe_dev
->lock
);
1606 static int vpfe_cropcap(struct file
*file
, void *priv
,
1607 struct v4l2_cropcap
*crop
)
1609 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1611 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_cropcap\n");
1613 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1615 /* If std_index is invalid, then just return (== 1:1 aspect) */
1616 if (vpfe_dev
->std_index
>= ARRAY_SIZE(vpfe_standards
))
1619 crop
->pixelaspect
= vpfe_standards
[vpfe_dev
->std_index
].pixelaspect
;
1623 static int vpfe_g_selection(struct file
*file
, void *priv
,
1624 struct v4l2_selection
*sel
)
1626 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1628 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_g_selection\n");
1630 if (sel
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1633 switch (sel
->target
) {
1634 case V4L2_SEL_TGT_CROP
:
1635 sel
->r
= vpfe_dev
->crop
;
1637 case V4L2_SEL_TGT_CROP_DEFAULT
:
1638 case V4L2_SEL_TGT_CROP_BOUNDS
:
1639 sel
->r
.width
= vpfe_standards
[vpfe_dev
->std_index
].width
;
1640 sel
->r
.height
= vpfe_standards
[vpfe_dev
->std_index
].height
;
1648 static int vpfe_s_selection(struct file
*file
, void *priv
,
1649 struct v4l2_selection
*sel
)
1651 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1652 struct v4l2_rect rect
= sel
->r
;
1655 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_s_selection\n");
1657 if (sel
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
||
1658 sel
->target
!= V4L2_SEL_TGT_CROP
)
1661 if (vpfe_dev
->started
) {
1662 /* make sure streaming is not started */
1663 v4l2_err(&vpfe_dev
->v4l2_dev
,
1664 "Cannot change crop when streaming is ON\n");
1668 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1672 if (rect
.top
< 0 || rect
.left
< 0) {
1673 v4l2_err(&vpfe_dev
->v4l2_dev
,
1674 "doesn't support negative values for top & left\n");
1679 /* adjust the width to 16 pixel boundary */
1680 rect
.width
= ((rect
.width
+ 15) & ~0xf);
1682 /* make sure parameters are valid */
1683 if ((rect
.left
+ rect
.width
>
1684 vpfe_dev
->std_info
.active_pixels
) ||
1685 (rect
.top
+ rect
.height
>
1686 vpfe_dev
->std_info
.active_lines
)) {
1687 v4l2_err(&vpfe_dev
->v4l2_dev
, "Error in S_SELECTION params\n");
1691 ccdc_dev
->hw_ops
.set_image_window(&rect
);
1692 vpfe_dev
->fmt
.fmt
.pix
.width
= rect
.width
;
1693 vpfe_dev
->fmt
.fmt
.pix
.height
= rect
.height
;
1694 vpfe_dev
->fmt
.fmt
.pix
.bytesperline
=
1695 ccdc_dev
->hw_ops
.get_line_length();
1696 vpfe_dev
->fmt
.fmt
.pix
.sizeimage
=
1697 vpfe_dev
->fmt
.fmt
.pix
.bytesperline
*
1698 vpfe_dev
->fmt
.fmt
.pix
.height
;
1699 vpfe_dev
->crop
= rect
;
1702 mutex_unlock(&vpfe_dev
->lock
);
1707 static long vpfe_param_handler(struct file
*file
, void *priv
,
1708 bool valid_prio
, unsigned int cmd
, void *param
)
1710 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1713 v4l2_dbg(2, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_param_handler\n");
1715 if (vpfe_dev
->started
) {
1716 /* only allowed if streaming is not started */
1717 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
,
1718 "device already started\n");
1722 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1727 case VPFE_CMD_S_CCDC_RAW_PARAMS
:
1729 v4l2_warn(&vpfe_dev
->v4l2_dev
,
1730 "VPFE_CMD_S_CCDC_RAW_PARAMS not supported\n");
1736 mutex_unlock(&vpfe_dev
->lock
);
1741 /* vpfe capture ioctl operations */
1742 static const struct v4l2_ioctl_ops vpfe_ioctl_ops
= {
1743 .vidioc_querycap
= vpfe_querycap
,
1744 .vidioc_g_fmt_vid_cap
= vpfe_g_fmt_vid_cap
,
1745 .vidioc_enum_fmt_vid_cap
= vpfe_enum_fmt_vid_cap
,
1746 .vidioc_s_fmt_vid_cap
= vpfe_s_fmt_vid_cap
,
1747 .vidioc_try_fmt_vid_cap
= vpfe_try_fmt_vid_cap
,
1748 .vidioc_enum_input
= vpfe_enum_input
,
1749 .vidioc_g_input
= vpfe_g_input
,
1750 .vidioc_s_input
= vpfe_s_input
,
1751 .vidioc_querystd
= vpfe_querystd
,
1752 .vidioc_s_std
= vpfe_s_std
,
1753 .vidioc_g_std
= vpfe_g_std
,
1754 .vidioc_reqbufs
= vpfe_reqbufs
,
1755 .vidioc_querybuf
= vpfe_querybuf
,
1756 .vidioc_qbuf
= vpfe_qbuf
,
1757 .vidioc_dqbuf
= vpfe_dqbuf
,
1758 .vidioc_streamon
= vpfe_streamon
,
1759 .vidioc_streamoff
= vpfe_streamoff
,
1760 .vidioc_cropcap
= vpfe_cropcap
,
1761 .vidioc_g_selection
= vpfe_g_selection
,
1762 .vidioc_s_selection
= vpfe_s_selection
,
1763 .vidioc_default
= vpfe_param_handler
,
1766 static struct vpfe_device
*vpfe_initialize(void)
1768 struct vpfe_device
*vpfe_dev
;
1770 /* Default number of buffers should be 3 */
1771 if ((numbuffers
> 0) &&
1772 (numbuffers
< config_params
.min_numbuffers
))
1773 numbuffers
= config_params
.min_numbuffers
;
1776 * Set buffer size to min buffers size if invalid buffer size is
1779 if (bufsize
< config_params
.min_bufsize
)
1780 bufsize
= config_params
.min_bufsize
;
1782 config_params
.numbuffers
= numbuffers
;
1785 config_params
.device_bufsize
= bufsize
;
1787 /* Allocate memory for device objects */
1788 vpfe_dev
= kzalloc(sizeof(*vpfe_dev
), GFP_KERNEL
);
1794 * vpfe_probe : This function creates device entries by register
1795 * itself to the V4L2 driver and initializes fields of each
1798 static int vpfe_probe(struct platform_device
*pdev
)
1800 struct vpfe_subdev_info
*sdinfo
;
1801 struct vpfe_config
*vpfe_cfg
;
1802 struct resource
*res1
;
1803 struct vpfe_device
*vpfe_dev
;
1804 struct i2c_adapter
*i2c_adap
;
1805 struct video_device
*vfd
;
1806 int ret
= -ENOMEM
, i
, j
;
1807 int num_subdevs
= 0;
1809 /* Get the pointer to the device object */
1810 vpfe_dev
= vpfe_initialize();
1813 v4l2_err(pdev
->dev
.driver
,
1814 "Failed to allocate memory for vpfe_dev\n");
1818 vpfe_dev
->pdev
= &pdev
->dev
;
1820 if (NULL
== pdev
->dev
.platform_data
) {
1821 v4l2_err(pdev
->dev
.driver
, "Unable to get vpfe config\n");
1823 goto probe_free_dev_mem
;
1826 vpfe_cfg
= pdev
->dev
.platform_data
;
1827 vpfe_dev
->cfg
= vpfe_cfg
;
1828 if (NULL
== vpfe_cfg
->ccdc
||
1829 NULL
== vpfe_cfg
->card_name
||
1830 NULL
== vpfe_cfg
->sub_devs
) {
1831 v4l2_err(pdev
->dev
.driver
, "null ptr in vpfe_cfg\n");
1833 goto probe_free_dev_mem
;
1836 /* Allocate memory for ccdc configuration */
1837 ccdc_cfg
= kmalloc(sizeof(struct ccdc_config
), GFP_KERNEL
);
1838 if (NULL
== ccdc_cfg
) {
1839 v4l2_err(pdev
->dev
.driver
,
1840 "Memory allocation failed for ccdc_cfg\n");
1841 goto probe_free_dev_mem
;
1844 mutex_lock(&ccdc_lock
);
1846 strncpy(ccdc_cfg
->name
, vpfe_cfg
->ccdc
, 32);
1847 /* Get VINT0 irq resource */
1848 res1
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
1850 v4l2_err(pdev
->dev
.driver
,
1851 "Unable to get interrupt for VINT0\n");
1853 goto probe_free_ccdc_cfg_mem
;
1855 vpfe_dev
->ccdc_irq0
= res1
->start
;
1857 /* Get VINT1 irq resource */
1858 res1
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 1);
1860 v4l2_err(pdev
->dev
.driver
,
1861 "Unable to get interrupt for VINT1\n");
1863 goto probe_free_ccdc_cfg_mem
;
1865 vpfe_dev
->ccdc_irq1
= res1
->start
;
1867 ret
= request_irq(vpfe_dev
->ccdc_irq0
, vpfe_isr
, 0,
1868 "vpfe_capture0", vpfe_dev
);
1871 v4l2_err(pdev
->dev
.driver
, "Unable to request interrupt\n");
1872 goto probe_free_ccdc_cfg_mem
;
1875 vfd
= &vpfe_dev
->video_dev
;
1876 /* Initialize field of video device */
1877 vfd
->release
= video_device_release_empty
;
1878 vfd
->fops
= &vpfe_fops
;
1879 vfd
->ioctl_ops
= &vpfe_ioctl_ops
;
1881 vfd
->v4l2_dev
= &vpfe_dev
->v4l2_dev
;
1882 snprintf(vfd
->name
, sizeof(vfd
->name
),
1885 (VPFE_CAPTURE_VERSION_CODE
>> 16) & 0xff,
1886 (VPFE_CAPTURE_VERSION_CODE
>> 8) & 0xff,
1887 (VPFE_CAPTURE_VERSION_CODE
) & 0xff);
1889 ret
= v4l2_device_register(&pdev
->dev
, &vpfe_dev
->v4l2_dev
);
1891 v4l2_err(pdev
->dev
.driver
,
1892 "Unable to register v4l2 device.\n");
1893 goto probe_out_release_irq
;
1895 v4l2_info(&vpfe_dev
->v4l2_dev
, "v4l2 device registered\n");
1896 spin_lock_init(&vpfe_dev
->irqlock
);
1897 spin_lock_init(&vpfe_dev
->dma_queue_lock
);
1898 mutex_init(&vpfe_dev
->lock
);
1900 /* Initialize field of the device objects */
1901 vpfe_dev
->numbuffers
= config_params
.numbuffers
;
1903 /* register video device */
1904 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
,
1905 "trying to register vpfe device.\n");
1906 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
,
1907 "video_dev=%p\n", &vpfe_dev
->video_dev
);
1908 vpfe_dev
->fmt
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1909 ret
= video_register_device(&vpfe_dev
->video_dev
,
1910 VFL_TYPE_GRABBER
, -1);
1913 v4l2_err(pdev
->dev
.driver
,
1914 "Unable to register video device.\n");
1915 goto probe_out_v4l2_unregister
;
1918 v4l2_info(&vpfe_dev
->v4l2_dev
, "video device registered\n");
1919 /* set the driver data in platform device */
1920 platform_set_drvdata(pdev
, vpfe_dev
);
1921 /* set driver private data */
1922 video_set_drvdata(&vpfe_dev
->video_dev
, vpfe_dev
);
1923 i2c_adap
= i2c_get_adapter(vpfe_cfg
->i2c_adapter_id
);
1924 num_subdevs
= vpfe_cfg
->num_subdevs
;
1925 vpfe_dev
->sd
= kmalloc(sizeof(struct v4l2_subdev
*) * num_subdevs
,
1927 if (NULL
== vpfe_dev
->sd
) {
1928 v4l2_err(&vpfe_dev
->v4l2_dev
,
1929 "unable to allocate memory for subdevice pointers\n");
1931 goto probe_out_video_unregister
;
1934 for (i
= 0; i
< num_subdevs
; i
++) {
1935 struct v4l2_input
*inps
;
1937 sdinfo
= &vpfe_cfg
->sub_devs
[i
];
1939 /* Load up the subdevice */
1941 v4l2_i2c_new_subdev_board(&vpfe_dev
->v4l2_dev
,
1943 &sdinfo
->board_info
,
1945 if (vpfe_dev
->sd
[i
]) {
1946 v4l2_info(&vpfe_dev
->v4l2_dev
,
1947 "v4l2 sub device %s registered\n",
1949 vpfe_dev
->sd
[i
]->grp_id
= sdinfo
->grp_id
;
1950 /* update tvnorms from the sub devices */
1951 for (j
= 0; j
< sdinfo
->num_inputs
; j
++) {
1952 inps
= &sdinfo
->inputs
[j
];
1953 vfd
->tvnorms
|= inps
->std
;
1956 v4l2_info(&vpfe_dev
->v4l2_dev
,
1957 "v4l2 sub device %s register fails\n",
1963 /* set first sub device as current one */
1964 vpfe_dev
->current_subdev
= &vpfe_cfg
->sub_devs
[0];
1965 vpfe_dev
->v4l2_dev
.ctrl_handler
= vpfe_dev
->sd
[0]->ctrl_handler
;
1967 /* We have at least one sub device to work with */
1968 mutex_unlock(&ccdc_lock
);
1972 kfree(vpfe_dev
->sd
);
1973 probe_out_video_unregister
:
1974 video_unregister_device(&vpfe_dev
->video_dev
);
1975 probe_out_v4l2_unregister
:
1976 v4l2_device_unregister(&vpfe_dev
->v4l2_dev
);
1977 probe_out_release_irq
:
1978 free_irq(vpfe_dev
->ccdc_irq0
, vpfe_dev
);
1979 probe_free_ccdc_cfg_mem
:
1981 mutex_unlock(&ccdc_lock
);
1988 * vpfe_remove : It un-register device from V4L2 driver
1990 static int vpfe_remove(struct platform_device
*pdev
)
1992 struct vpfe_device
*vpfe_dev
= platform_get_drvdata(pdev
);
1994 v4l2_info(pdev
->dev
.driver
, "vpfe_remove\n");
1996 free_irq(vpfe_dev
->ccdc_irq0
, vpfe_dev
);
1997 kfree(vpfe_dev
->sd
);
1998 v4l2_device_unregister(&vpfe_dev
->v4l2_dev
);
1999 video_unregister_device(&vpfe_dev
->video_dev
);
2005 static int vpfe_suspend(struct device
*dev
)
2010 static int vpfe_resume(struct device
*dev
)
2015 static const struct dev_pm_ops vpfe_dev_pm_ops
= {
2016 .suspend
= vpfe_suspend
,
2017 .resume
= vpfe_resume
,
2020 static struct platform_driver vpfe_driver
= {
2022 .name
= CAPTURE_DRV_NAME
,
2023 .pm
= &vpfe_dev_pm_ops
,
2025 .probe
= vpfe_probe
,
2026 .remove
= vpfe_remove
,
2029 module_platform_driver(vpfe_driver
);