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 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_params
);
227 BUG_ON(!dev
->hw_ops
.set_image_window
);
228 BUG_ON(!dev
->hw_ops
.get_image_window
);
229 BUG_ON(!dev
->hw_ops
.get_line_length
);
230 BUG_ON(!dev
->hw_ops
.getfid
);
232 mutex_lock(&ccdc_lock
);
233 if (NULL
== ccdc_cfg
) {
235 * TODO. Will this ever happen? if so, we need to fix it.
236 * Proabably we need to add the request to a linked list and
237 * walk through it during vpfe probe
239 printk(KERN_ERR
"vpfe capture not initialized\n");
244 if (strcmp(dev
->name
, ccdc_cfg
->name
)) {
245 /* ignore this ccdc */
251 printk(KERN_ERR
"ccdc already registered\n");
258 mutex_unlock(&ccdc_lock
);
261 EXPORT_SYMBOL(vpfe_register_ccdc_device
);
264 * vpfe_unregister_ccdc_device. CCDC module calls this to
265 * unregister with vpfe capture
267 void vpfe_unregister_ccdc_device(struct ccdc_hw_device
*dev
)
270 printk(KERN_ERR
"invalid ccdc device ptr\n");
274 printk(KERN_NOTICE
"vpfe_unregister_ccdc_device, dev->name = %s\n",
277 if (strcmp(dev
->name
, ccdc_cfg
->name
)) {
278 /* ignore this ccdc */
282 mutex_lock(&ccdc_lock
);
284 mutex_unlock(&ccdc_lock
);
287 EXPORT_SYMBOL(vpfe_unregister_ccdc_device
);
290 * vpfe_get_ccdc_image_format - Get image parameters based on CCDC settings
292 static int vpfe_get_ccdc_image_format(struct vpfe_device
*vpfe_dev
,
293 struct v4l2_format
*f
)
295 struct v4l2_rect image_win
;
296 enum ccdc_buftype buf_type
;
297 enum ccdc_frmfmt frm_fmt
;
299 memset(f
, 0, sizeof(*f
));
300 f
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
301 ccdc_dev
->hw_ops
.get_image_window(&image_win
);
302 f
->fmt
.pix
.width
= image_win
.width
;
303 f
->fmt
.pix
.height
= image_win
.height
;
304 f
->fmt
.pix
.bytesperline
= ccdc_dev
->hw_ops
.get_line_length();
305 f
->fmt
.pix
.sizeimage
= f
->fmt
.pix
.bytesperline
*
307 buf_type
= ccdc_dev
->hw_ops
.get_buftype();
308 f
->fmt
.pix
.pixelformat
= ccdc_dev
->hw_ops
.get_pixel_format();
309 frm_fmt
= ccdc_dev
->hw_ops
.get_frame_format();
310 if (frm_fmt
== CCDC_FRMFMT_PROGRESSIVE
)
311 f
->fmt
.pix
.field
= V4L2_FIELD_NONE
;
312 else if (frm_fmt
== CCDC_FRMFMT_INTERLACED
) {
313 if (buf_type
== CCDC_BUFTYPE_FLD_INTERLEAVED
)
314 f
->fmt
.pix
.field
= V4L2_FIELD_INTERLACED
;
315 else if (buf_type
== CCDC_BUFTYPE_FLD_SEPARATED
)
316 f
->fmt
.pix
.field
= V4L2_FIELD_SEQ_TB
;
318 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid buf_type\n");
322 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid frm_fmt\n");
329 * vpfe_config_ccdc_image_format()
330 * For a pix format, configure ccdc to setup the capture
332 static int vpfe_config_ccdc_image_format(struct vpfe_device
*vpfe_dev
)
334 enum ccdc_frmfmt frm_fmt
= CCDC_FRMFMT_INTERLACED
;
337 if (ccdc_dev
->hw_ops
.set_pixel_format(
338 vpfe_dev
->fmt
.fmt
.pix
.pixelformat
) < 0) {
339 v4l2_err(&vpfe_dev
->v4l2_dev
,
340 "couldn't set pix format in ccdc\n");
343 /* configure the image window */
344 ccdc_dev
->hw_ops
.set_image_window(&vpfe_dev
->crop
);
346 switch (vpfe_dev
->fmt
.fmt
.pix
.field
) {
347 case V4L2_FIELD_INTERLACED
:
348 /* do nothing, since it is default */
349 ret
= ccdc_dev
->hw_ops
.set_buftype(
350 CCDC_BUFTYPE_FLD_INTERLEAVED
);
352 case V4L2_FIELD_NONE
:
353 frm_fmt
= CCDC_FRMFMT_PROGRESSIVE
;
354 /* buffer type only applicable for interlaced scan */
356 case V4L2_FIELD_SEQ_TB
:
357 ret
= ccdc_dev
->hw_ops
.set_buftype(
358 CCDC_BUFTYPE_FLD_SEPARATED
);
364 /* set the frame format */
366 ret
= ccdc_dev
->hw_ops
.set_frame_format(frm_fmt
);
370 * vpfe_config_image_format()
371 * For a given standard, this functions sets up the default
372 * pix format & crop values in the vpfe device and ccdc. It first
373 * starts with defaults based values from the standard table.
374 * It then checks if sub device support g_fmt and then override the
375 * values based on that.Sets crop values to match with scan resolution
376 * starting at 0,0. It calls vpfe_config_ccdc_image_format() set the
379 static int vpfe_config_image_format(struct vpfe_device
*vpfe_dev
,
380 const v4l2_std_id
*std_id
)
382 struct vpfe_subdev_info
*sdinfo
= vpfe_dev
->current_subdev
;
385 for (i
= 0; i
< ARRAY_SIZE(vpfe_standards
); i
++) {
386 if (vpfe_standards
[i
].std_id
& *std_id
) {
387 vpfe_dev
->std_info
.active_pixels
=
388 vpfe_standards
[i
].width
;
389 vpfe_dev
->std_info
.active_lines
=
390 vpfe_standards
[i
].height
;
391 vpfe_dev
->std_info
.frame_format
=
392 vpfe_standards
[i
].frame_format
;
393 vpfe_dev
->std_index
= i
;
398 if (i
== ARRAY_SIZE(vpfe_standards
)) {
399 v4l2_err(&vpfe_dev
->v4l2_dev
, "standard not supported\n");
403 vpfe_dev
->crop
.top
= 0;
404 vpfe_dev
->crop
.left
= 0;
405 vpfe_dev
->crop
.width
= vpfe_dev
->std_info
.active_pixels
;
406 vpfe_dev
->crop
.height
= vpfe_dev
->std_info
.active_lines
;
407 vpfe_dev
->fmt
.fmt
.pix
.width
= vpfe_dev
->crop
.width
;
408 vpfe_dev
->fmt
.fmt
.pix
.height
= vpfe_dev
->crop
.height
;
410 /* first field and frame format based on standard frame format */
411 if (vpfe_dev
->std_info
.frame_format
) {
412 vpfe_dev
->fmt
.fmt
.pix
.field
= V4L2_FIELD_INTERLACED
;
413 /* assume V4L2_PIX_FMT_UYVY as default */
414 vpfe_dev
->fmt
.fmt
.pix
.pixelformat
= V4L2_PIX_FMT_UYVY
;
416 vpfe_dev
->fmt
.fmt
.pix
.field
= V4L2_FIELD_NONE
;
417 /* assume V4L2_PIX_FMT_SBGGR8 */
418 vpfe_dev
->fmt
.fmt
.pix
.pixelformat
= V4L2_PIX_FMT_SBGGR8
;
421 /* if sub device supports g_fmt, override the defaults */
422 ret
= v4l2_device_call_until_err(&vpfe_dev
->v4l2_dev
,
423 sdinfo
->grp_id
, video
, g_fmt
, &vpfe_dev
->fmt
);
425 if (ret
&& ret
!= -ENOIOCTLCMD
) {
426 v4l2_err(&vpfe_dev
->v4l2_dev
,
427 "error in getting g_fmt from sub device\n");
431 /* Sets the values in CCDC */
432 ret
= vpfe_config_ccdc_image_format(vpfe_dev
);
436 /* Update the values of sizeimage and bytesperline */
438 vpfe_dev
->fmt
.fmt
.pix
.bytesperline
=
439 ccdc_dev
->hw_ops
.get_line_length();
440 vpfe_dev
->fmt
.fmt
.pix
.sizeimage
=
441 vpfe_dev
->fmt
.fmt
.pix
.bytesperline
*
442 vpfe_dev
->fmt
.fmt
.pix
.height
;
447 static int vpfe_initialize_device(struct vpfe_device
*vpfe_dev
)
451 /* set first input of current subdevice as the current input */
452 vpfe_dev
->current_input
= 0;
454 /* set default standard */
455 vpfe_dev
->std_index
= 0;
457 /* Configure the default format information */
458 ret
= vpfe_config_image_format(vpfe_dev
,
459 &vpfe_standards
[vpfe_dev
->std_index
].std_id
);
463 /* now open the ccdc device to initialize it */
464 mutex_lock(&ccdc_lock
);
465 if (NULL
== ccdc_dev
) {
466 v4l2_err(&vpfe_dev
->v4l2_dev
, "ccdc device not registered\n");
471 if (!try_module_get(ccdc_dev
->owner
)) {
472 v4l2_err(&vpfe_dev
->v4l2_dev
, "Couldn't lock ccdc module\n");
476 ret
= ccdc_dev
->hw_ops
.open(vpfe_dev
->pdev
);
478 vpfe_dev
->initialized
= 1;
480 mutex_unlock(&ccdc_lock
);
485 * vpfe_open : It creates object of file handle structure and
486 * stores it in private_data member of filepointer
488 static int vpfe_open(struct file
*file
)
490 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
493 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_open\n");
495 if (!vpfe_dev
->cfg
->num_subdevs
) {
496 v4l2_err(&vpfe_dev
->v4l2_dev
, "No decoder registered\n");
500 /* Allocate memory for the file handle object */
501 fh
= kmalloc(sizeof(struct vpfe_fh
), GFP_KERNEL
);
503 v4l2_err(&vpfe_dev
->v4l2_dev
,
504 "unable to allocate memory for file handle object\n");
507 /* store pointer to fh in private_data member of file */
508 file
->private_data
= fh
;
509 fh
->vpfe_dev
= vpfe_dev
;
510 mutex_lock(&vpfe_dev
->lock
);
511 /* If decoder is not initialized. initialize it */
512 if (!vpfe_dev
->initialized
) {
513 if (vpfe_initialize_device(vpfe_dev
)) {
514 mutex_unlock(&vpfe_dev
->lock
);
518 /* Increment device usrs counter */
520 /* Set io_allowed member to false */
522 /* Initialize priority of this instance to default priority */
523 fh
->prio
= V4L2_PRIORITY_UNSET
;
524 v4l2_prio_open(&vpfe_dev
->prio
, &fh
->prio
);
525 mutex_unlock(&vpfe_dev
->lock
);
529 static void vpfe_schedule_next_buffer(struct vpfe_device
*vpfe_dev
)
533 vpfe_dev
->next_frm
= list_entry(vpfe_dev
->dma_queue
.next
,
534 struct videobuf_buffer
, queue
);
535 list_del(&vpfe_dev
->next_frm
->queue
);
536 vpfe_dev
->next_frm
->state
= VIDEOBUF_ACTIVE
;
537 addr
= videobuf_to_dma_contig(vpfe_dev
->next_frm
);
538 ccdc_dev
->hw_ops
.setfbaddr(addr
);
541 static void vpfe_process_buffer_complete(struct vpfe_device
*vpfe_dev
)
543 struct timeval timevalue
;
545 do_gettimeofday(&timevalue
);
546 vpfe_dev
->cur_frm
->ts
= timevalue
;
547 vpfe_dev
->cur_frm
->state
= VIDEOBUF_DONE
;
548 vpfe_dev
->cur_frm
->size
= vpfe_dev
->fmt
.fmt
.pix
.sizeimage
;
549 wake_up_interruptible(&vpfe_dev
->cur_frm
->done
);
550 vpfe_dev
->cur_frm
= vpfe_dev
->next_frm
;
554 static irqreturn_t
vpfe_isr(int irq
, void *dev_id
)
556 struct vpfe_device
*vpfe_dev
= dev_id
;
557 enum v4l2_field field
;
561 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "\nStarting vpfe_isr...\n");
562 field
= vpfe_dev
->fmt
.fmt
.pix
.field
;
564 /* if streaming not started, don't do anything */
565 if (!vpfe_dev
->started
)
568 /* only for 6446 this will be applicable */
569 if (NULL
!= ccdc_dev
->hw_ops
.reset
)
570 ccdc_dev
->hw_ops
.reset();
572 if (field
== V4L2_FIELD_NONE
) {
573 /* handle progressive frame capture */
574 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
,
575 "frame format is progressive...\n");
576 if (vpfe_dev
->cur_frm
!= vpfe_dev
->next_frm
)
577 vpfe_process_buffer_complete(vpfe_dev
);
581 /* interlaced or TB capture check which field we are in hardware */
582 fid
= ccdc_dev
->hw_ops
.getfid();
584 /* switch the software maintained field id */
585 vpfe_dev
->field_id
^= 1;
586 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "field id = %x:%x.\n",
587 fid
, vpfe_dev
->field_id
);
588 if (fid
== vpfe_dev
->field_id
) {
589 /* we are in-sync here,continue */
592 * One frame is just being captured. If the next frame
593 * is available, release the current frame and move on
595 if (vpfe_dev
->cur_frm
!= vpfe_dev
->next_frm
)
596 vpfe_process_buffer_complete(vpfe_dev
);
598 * based on whether the two fields are stored
599 * interleavely or separately in memory, reconfigure
600 * the CCDC memory address
602 if (field
== V4L2_FIELD_SEQ_TB
) {
604 videobuf_to_dma_contig(vpfe_dev
->cur_frm
);
605 addr
+= vpfe_dev
->field_off
;
606 ccdc_dev
->hw_ops
.setfbaddr(addr
);
611 * if one field is just being captured configure
612 * the next frame get the next frame from the empty
613 * queue if no frame is available hold on to the
616 spin_lock(&vpfe_dev
->dma_queue_lock
);
617 if (!list_empty(&vpfe_dev
->dma_queue
) &&
618 vpfe_dev
->cur_frm
== vpfe_dev
->next_frm
)
619 vpfe_schedule_next_buffer(vpfe_dev
);
620 spin_unlock(&vpfe_dev
->dma_queue_lock
);
621 } else if (fid
== 0) {
623 * out of sync. Recover from any hardware out-of-sync.
624 * May loose one frame
626 vpfe_dev
->field_id
= fid
;
631 /* vdint1_isr - isr handler for VINT1 interrupt */
632 static irqreturn_t
vdint1_isr(int irq
, void *dev_id
)
634 struct vpfe_device
*vpfe_dev
= dev_id
;
636 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "\nInside vdint1_isr...\n");
638 /* if streaming not started, don't do anything */
639 if (!vpfe_dev
->started
)
642 spin_lock(&vpfe_dev
->dma_queue_lock
);
643 if ((vpfe_dev
->fmt
.fmt
.pix
.field
== V4L2_FIELD_NONE
) &&
644 !list_empty(&vpfe_dev
->dma_queue
) &&
645 vpfe_dev
->cur_frm
== vpfe_dev
->next_frm
)
646 vpfe_schedule_next_buffer(vpfe_dev
);
647 spin_unlock(&vpfe_dev
->dma_queue_lock
);
651 static void vpfe_detach_irq(struct vpfe_device
*vpfe_dev
)
653 enum ccdc_frmfmt frame_format
;
655 frame_format
= ccdc_dev
->hw_ops
.get_frame_format();
656 if (frame_format
== CCDC_FRMFMT_PROGRESSIVE
)
657 free_irq(vpfe_dev
->ccdc_irq1
, vpfe_dev
);
660 static int vpfe_attach_irq(struct vpfe_device
*vpfe_dev
)
662 enum ccdc_frmfmt frame_format
;
664 frame_format
= ccdc_dev
->hw_ops
.get_frame_format();
665 if (frame_format
== CCDC_FRMFMT_PROGRESSIVE
) {
666 return request_irq(vpfe_dev
->ccdc_irq1
, vdint1_isr
,
667 IRQF_DISABLED
, "vpfe_capture1",
673 /* vpfe_stop_ccdc_capture: stop streaming in ccdc/isif */
674 static void vpfe_stop_ccdc_capture(struct vpfe_device
*vpfe_dev
)
676 vpfe_dev
->started
= 0;
677 ccdc_dev
->hw_ops
.enable(0);
678 if (ccdc_dev
->hw_ops
.enable_out_to_sdram
)
679 ccdc_dev
->hw_ops
.enable_out_to_sdram(0);
683 * vpfe_release : This function deletes buffer queue, frees the
684 * buffers and the vpfe file handle
686 static int vpfe_release(struct file
*file
)
688 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
689 struct vpfe_fh
*fh
= file
->private_data
;
690 struct vpfe_subdev_info
*sdinfo
;
693 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_release\n");
695 /* Get the device lock */
696 mutex_lock(&vpfe_dev
->lock
);
697 /* if this instance is doing IO */
698 if (fh
->io_allowed
) {
699 if (vpfe_dev
->started
) {
700 sdinfo
= vpfe_dev
->current_subdev
;
701 ret
= v4l2_device_call_until_err(&vpfe_dev
->v4l2_dev
,
704 if (ret
&& (ret
!= -ENOIOCTLCMD
))
705 v4l2_err(&vpfe_dev
->v4l2_dev
,
706 "stream off failed in subdev\n");
707 vpfe_stop_ccdc_capture(vpfe_dev
);
708 vpfe_detach_irq(vpfe_dev
);
709 videobuf_streamoff(&vpfe_dev
->buffer_queue
);
711 vpfe_dev
->io_usrs
= 0;
712 vpfe_dev
->numbuffers
= config_params
.numbuffers
;
715 /* Decrement device usrs counter */
717 /* Close the priority */
718 v4l2_prio_close(&vpfe_dev
->prio
, &fh
->prio
);
719 /* If this is the last file handle */
720 if (!vpfe_dev
->usrs
) {
721 vpfe_dev
->initialized
= 0;
722 if (ccdc_dev
->hw_ops
.close
)
723 ccdc_dev
->hw_ops
.close(vpfe_dev
->pdev
);
724 module_put(ccdc_dev
->owner
);
726 mutex_unlock(&vpfe_dev
->lock
);
727 file
->private_data
= NULL
;
728 /* Free memory allocated to file handle object */
734 * vpfe_mmap : It is used to map kernel space buffers
737 static int vpfe_mmap(struct file
*file
, struct vm_area_struct
*vma
)
739 /* Get the device object and file handle object */
740 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
742 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_mmap\n");
744 return videobuf_mmap_mapper(&vpfe_dev
->buffer_queue
, vma
);
748 * vpfe_poll: It is used for select/poll system call
750 static unsigned int vpfe_poll(struct file
*file
, poll_table
*wait
)
752 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
754 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_poll\n");
756 if (vpfe_dev
->started
)
757 return videobuf_poll_stream(file
,
758 &vpfe_dev
->buffer_queue
, wait
);
762 /* vpfe capture driver file operations */
763 static const struct v4l2_file_operations vpfe_fops
= {
764 .owner
= THIS_MODULE
,
766 .release
= vpfe_release
,
767 .unlocked_ioctl
= video_ioctl2
,
773 * vpfe_check_format()
774 * This function adjust the input pixel format as per hardware
775 * capabilities and update the same in pixfmt.
776 * Following algorithm used :-
778 * If given pixformat is not in the vpfe list of pix formats or not
779 * supported by the hardware, current value of pixformat in the device
781 * If given field is not supported, then current field is used. If field
782 * is different from current, then it is matched with that from sub device.
783 * Minimum height is 2 lines for interlaced or tb field and 1 line for
784 * progressive. Maximum height is clamped to active active lines of scan
785 * Minimum width is 32 bytes in memory and width is clamped to active
787 * bytesperline is a multiple of 32.
789 static const struct vpfe_pixel_format
*
790 vpfe_check_format(struct vpfe_device
*vpfe_dev
,
791 struct v4l2_pix_format
*pixfmt
)
793 u32 min_height
= 1, min_width
= 32, max_width
, max_height
;
794 const struct vpfe_pixel_format
*vpfe_pix_fmt
;
798 vpfe_pix_fmt
= vpfe_lookup_pix_format(pixfmt
->pixelformat
);
799 if (NULL
== vpfe_pix_fmt
) {
801 * use current pixel format in the vpfe device. We
802 * will find this pix format in the table
804 pixfmt
->pixelformat
= vpfe_dev
->fmt
.fmt
.pix
.pixelformat
;
805 vpfe_pix_fmt
= vpfe_lookup_pix_format(pixfmt
->pixelformat
);
808 /* check if hw supports it */
811 while (ccdc_dev
->hw_ops
.enum_pix(&pix
, temp
) >= 0) {
812 if (vpfe_pix_fmt
->fmtdesc
.pixelformat
== pix
) {
820 /* use current pixel format */
821 pixfmt
->pixelformat
= vpfe_dev
->fmt
.fmt
.pix
.pixelformat
;
823 * Since this is currently used in the vpfe device, we
824 * will find this pix format in the table
826 vpfe_pix_fmt
= vpfe_lookup_pix_format(pixfmt
->pixelformat
);
829 /* check what field format is supported */
830 if (pixfmt
->field
== V4L2_FIELD_ANY
) {
831 /* if field is any, use current value as default */
832 pixfmt
->field
= vpfe_dev
->fmt
.fmt
.pix
.field
;
836 * if field is not same as current field in the vpfe device
837 * try matching the field with the sub device field
839 if (vpfe_dev
->fmt
.fmt
.pix
.field
!= pixfmt
->field
) {
841 * If field value is not in the supported fields, use current
842 * field used in the device as default
844 switch (pixfmt
->field
) {
845 case V4L2_FIELD_INTERLACED
:
846 case V4L2_FIELD_SEQ_TB
:
847 /* if sub device is supporting progressive, use that */
848 if (!vpfe_dev
->std_info
.frame_format
)
849 pixfmt
->field
= V4L2_FIELD_NONE
;
851 case V4L2_FIELD_NONE
:
852 if (vpfe_dev
->std_info
.frame_format
)
853 pixfmt
->field
= V4L2_FIELD_INTERLACED
;
857 /* use current field as default */
858 pixfmt
->field
= vpfe_dev
->fmt
.fmt
.pix
.field
;
863 /* Now adjust image resolutions supported */
864 if (pixfmt
->field
== V4L2_FIELD_INTERLACED
||
865 pixfmt
->field
== V4L2_FIELD_SEQ_TB
)
868 max_width
= vpfe_dev
->std_info
.active_pixels
;
869 max_height
= vpfe_dev
->std_info
.active_lines
;
870 min_width
/= vpfe_pix_fmt
->bpp
;
872 v4l2_info(&vpfe_dev
->v4l2_dev
, "width = %d, height = %d, bpp = %d\n",
873 pixfmt
->width
, pixfmt
->height
, vpfe_pix_fmt
->bpp
);
875 pixfmt
->width
= clamp((pixfmt
->width
), min_width
, max_width
);
876 pixfmt
->height
= clamp((pixfmt
->height
), min_height
, max_height
);
878 /* If interlaced, adjust height to be a multiple of 2 */
879 if (pixfmt
->field
== V4L2_FIELD_INTERLACED
)
880 pixfmt
->height
&= (~1);
882 * recalculate bytesperline and sizeimage since width
883 * and height might have changed
885 pixfmt
->bytesperline
= (((pixfmt
->width
* vpfe_pix_fmt
->bpp
) + 31)
887 if (pixfmt
->pixelformat
== V4L2_PIX_FMT_NV12
)
889 pixfmt
->bytesperline
* pixfmt
->height
+
890 ((pixfmt
->bytesperline
* pixfmt
->height
) >> 1);
892 pixfmt
->sizeimage
= pixfmt
->bytesperline
* pixfmt
->height
;
894 v4l2_info(&vpfe_dev
->v4l2_dev
, "adjusted width = %d, height ="
895 " %d, bpp = %d, bytesperline = %d, sizeimage = %d\n",
896 pixfmt
->width
, pixfmt
->height
, vpfe_pix_fmt
->bpp
,
897 pixfmt
->bytesperline
, pixfmt
->sizeimage
);
901 static int vpfe_querycap(struct file
*file
, void *priv
,
902 struct v4l2_capability
*cap
)
904 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
906 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_querycap\n");
908 cap
->version
= VPFE_CAPTURE_VERSION_CODE
;
909 cap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_STREAMING
;
910 strlcpy(cap
->driver
, CAPTURE_DRV_NAME
, sizeof(cap
->driver
));
911 strlcpy(cap
->bus_info
, "VPFE", sizeof(cap
->bus_info
));
912 strlcpy(cap
->card
, vpfe_dev
->cfg
->card_name
, sizeof(cap
->card
));
916 static int vpfe_g_fmt_vid_cap(struct file
*file
, void *priv
,
917 struct v4l2_format
*fmt
)
919 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
922 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_g_fmt_vid_cap\n");
923 /* Fill in the information about format */
924 *fmt
= vpfe_dev
->fmt
;
928 static int vpfe_enum_fmt_vid_cap(struct file
*file
, void *priv
,
929 struct v4l2_fmtdesc
*fmt
)
931 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
932 const struct vpfe_pixel_format
*pix_fmt
;
936 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_enum_fmt_vid_cap\n");
938 if (ccdc_dev
->hw_ops
.enum_pix(&pix
, fmt
->index
) < 0)
941 /* Fill in the information about format */
942 pix_fmt
= vpfe_lookup_pix_format(pix
);
943 if (NULL
!= pix_fmt
) {
944 temp_index
= fmt
->index
;
945 *fmt
= pix_fmt
->fmtdesc
;
946 fmt
->index
= temp_index
;
952 static int vpfe_s_fmt_vid_cap(struct file
*file
, void *priv
,
953 struct v4l2_format
*fmt
)
955 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
956 const struct vpfe_pixel_format
*pix_fmts
;
959 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_s_fmt_vid_cap\n");
961 /* If streaming is started, return error */
962 if (vpfe_dev
->started
) {
963 v4l2_err(&vpfe_dev
->v4l2_dev
, "Streaming is started\n");
967 /* Check for valid frame format */
968 pix_fmts
= vpfe_check_format(vpfe_dev
, &fmt
->fmt
.pix
);
970 if (NULL
== pix_fmts
)
973 /* store the pixel format in the device object */
974 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
978 /* First detach any IRQ if currently attached */
979 vpfe_detach_irq(vpfe_dev
);
980 vpfe_dev
->fmt
= *fmt
;
981 /* set image capture parameters in the ccdc */
982 ret
= vpfe_config_ccdc_image_format(vpfe_dev
);
983 mutex_unlock(&vpfe_dev
->lock
);
987 static int vpfe_try_fmt_vid_cap(struct file
*file
, void *priv
,
988 struct v4l2_format
*f
)
990 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
991 const struct vpfe_pixel_format
*pix_fmts
;
993 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_try_fmt_vid_cap\n");
995 pix_fmts
= vpfe_check_format(vpfe_dev
, &f
->fmt
.pix
);
996 if (NULL
== pix_fmts
)
1002 * vpfe_get_subdev_input_index - Get subdev index and subdev input index for a
1003 * given app input index
1005 static int vpfe_get_subdev_input_index(struct vpfe_device
*vpfe_dev
,
1007 int *subdev_input_index
,
1008 int app_input_index
)
1010 struct vpfe_config
*cfg
= vpfe_dev
->cfg
;
1011 struct vpfe_subdev_info
*sdinfo
;
1014 for (i
= 0; i
< cfg
->num_subdevs
; i
++) {
1015 sdinfo
= &cfg
->sub_devs
[i
];
1016 if (app_input_index
< (j
+ sdinfo
->num_inputs
)) {
1018 *subdev_input_index
= app_input_index
- j
;
1021 j
+= sdinfo
->num_inputs
;
1027 * vpfe_get_app_input - Get app input index for a given subdev input index
1028 * driver stores the input index of the current sub device and translate it
1029 * when application request the current input
1031 static int vpfe_get_app_input_index(struct vpfe_device
*vpfe_dev
,
1032 int *app_input_index
)
1034 struct vpfe_config
*cfg
= vpfe_dev
->cfg
;
1035 struct vpfe_subdev_info
*sdinfo
;
1038 for (i
= 0; i
< cfg
->num_subdevs
; i
++) {
1039 sdinfo
= &cfg
->sub_devs
[i
];
1040 if (!strcmp(sdinfo
->name
, vpfe_dev
->current_subdev
->name
)) {
1041 if (vpfe_dev
->current_input
>= sdinfo
->num_inputs
)
1043 *app_input_index
= j
+ vpfe_dev
->current_input
;
1046 j
+= sdinfo
->num_inputs
;
1051 static int vpfe_enum_input(struct file
*file
, void *priv
,
1052 struct v4l2_input
*inp
)
1054 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1055 struct vpfe_subdev_info
*sdinfo
;
1058 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_enum_input\n");
1060 if (vpfe_get_subdev_input_index(vpfe_dev
,
1064 v4l2_err(&vpfe_dev
->v4l2_dev
, "input information not found"
1065 " for the subdev\n");
1068 sdinfo
= &vpfe_dev
->cfg
->sub_devs
[subdev
];
1069 memcpy(inp
, &sdinfo
->inputs
[index
], sizeof(struct v4l2_input
));
1073 static int vpfe_g_input(struct file
*file
, void *priv
, unsigned int *index
)
1075 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1077 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_g_input\n");
1079 return vpfe_get_app_input_index(vpfe_dev
, index
);
1083 static int vpfe_s_input(struct file
*file
, void *priv
, unsigned int index
)
1085 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1086 struct vpfe_subdev_info
*sdinfo
;
1087 int subdev_index
, inp_index
;
1088 struct vpfe_route
*route
;
1089 u32 input
= 0, output
= 0;
1092 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_s_input\n");
1094 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1099 * If streaming is started return device busy
1102 if (vpfe_dev
->started
) {
1103 v4l2_err(&vpfe_dev
->v4l2_dev
, "Streaming is on\n");
1108 if (vpfe_get_subdev_input_index(vpfe_dev
,
1112 v4l2_err(&vpfe_dev
->v4l2_dev
, "invalid input index\n");
1116 sdinfo
= &vpfe_dev
->cfg
->sub_devs
[subdev_index
];
1117 route
= &sdinfo
->routes
[inp_index
];
1118 if (route
&& sdinfo
->can_route
) {
1119 input
= route
->input
;
1120 output
= route
->output
;
1123 ret
= v4l2_device_call_until_err(&vpfe_dev
->v4l2_dev
, sdinfo
->grp_id
,
1124 video
, s_routing
, input
, output
, 0);
1127 v4l2_err(&vpfe_dev
->v4l2_dev
,
1128 "vpfe_doioctl:error in setting input in decoder\n");
1132 vpfe_dev
->current_subdev
= sdinfo
;
1133 vpfe_dev
->current_input
= index
;
1134 vpfe_dev
->std_index
= 0;
1136 /* set the bus/interface parameter for the sub device in ccdc */
1137 ret
= ccdc_dev
->hw_ops
.set_hw_if_params(&sdinfo
->ccdc_if_params
);
1141 /* set the default image parameters in the device */
1142 ret
= vpfe_config_image_format(vpfe_dev
,
1143 &vpfe_standards
[vpfe_dev
->std_index
].std_id
);
1145 mutex_unlock(&vpfe_dev
->lock
);
1149 static int vpfe_querystd(struct file
*file
, void *priv
, v4l2_std_id
*std_id
)
1151 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1152 struct vpfe_subdev_info
*sdinfo
;
1155 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_querystd\n");
1157 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1158 sdinfo
= vpfe_dev
->current_subdev
;
1161 /* Call querystd function of decoder device */
1162 ret
= v4l2_device_call_until_err(&vpfe_dev
->v4l2_dev
, sdinfo
->grp_id
,
1163 video
, querystd
, std_id
);
1164 mutex_unlock(&vpfe_dev
->lock
);
1168 static int vpfe_s_std(struct file
*file
, void *priv
, v4l2_std_id
*std_id
)
1170 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1171 struct vpfe_subdev_info
*sdinfo
;
1174 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_s_std\n");
1176 /* Call decoder driver function to set the standard */
1177 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1181 sdinfo
= vpfe_dev
->current_subdev
;
1182 /* If streaming is started, return device busy error */
1183 if (vpfe_dev
->started
) {
1184 v4l2_err(&vpfe_dev
->v4l2_dev
, "streaming is started\n");
1189 ret
= v4l2_device_call_until_err(&vpfe_dev
->v4l2_dev
, sdinfo
->grp_id
,
1190 core
, s_std
, *std_id
);
1192 v4l2_err(&vpfe_dev
->v4l2_dev
, "Failed to set standard\n");
1195 ret
= vpfe_config_image_format(vpfe_dev
, std_id
);
1198 mutex_unlock(&vpfe_dev
->lock
);
1202 static int vpfe_g_std(struct file
*file
, void *priv
, v4l2_std_id
*std_id
)
1204 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1206 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_g_std\n");
1208 *std_id
= vpfe_standards
[vpfe_dev
->std_index
].std_id
;
1212 * Videobuf operations
1214 static int vpfe_videobuf_setup(struct videobuf_queue
*vq
,
1215 unsigned int *count
,
1218 struct vpfe_fh
*fh
= vq
->priv_data
;
1219 struct vpfe_device
*vpfe_dev
= fh
->vpfe_dev
;
1221 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_buffer_setup\n");
1222 *size
= config_params
.device_bufsize
;
1224 if (*count
< config_params
.min_numbuffers
)
1225 *count
= config_params
.min_numbuffers
;
1226 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
,
1227 "count=%d, size=%d\n", *count
, *size
);
1231 static int vpfe_videobuf_prepare(struct videobuf_queue
*vq
,
1232 struct videobuf_buffer
*vb
,
1233 enum v4l2_field field
)
1235 struct vpfe_fh
*fh
= vq
->priv_data
;
1236 struct vpfe_device
*vpfe_dev
= fh
->vpfe_dev
;
1238 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_buffer_prepare\n");
1240 /* If buffer is not initialized, initialize it */
1241 if (VIDEOBUF_NEEDS_INIT
== vb
->state
) {
1242 vb
->width
= vpfe_dev
->fmt
.fmt
.pix
.width
;
1243 vb
->height
= vpfe_dev
->fmt
.fmt
.pix
.height
;
1244 vb
->size
= vpfe_dev
->fmt
.fmt
.pix
.sizeimage
;
1247 vb
->state
= VIDEOBUF_PREPARED
;
1251 static void vpfe_videobuf_queue(struct videobuf_queue
*vq
,
1252 struct videobuf_buffer
*vb
)
1254 /* Get the file handle object and device object */
1255 struct vpfe_fh
*fh
= vq
->priv_data
;
1256 struct vpfe_device
*vpfe_dev
= fh
->vpfe_dev
;
1257 unsigned long flags
;
1259 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_buffer_queue\n");
1261 /* add the buffer to the DMA queue */
1262 spin_lock_irqsave(&vpfe_dev
->dma_queue_lock
, flags
);
1263 list_add_tail(&vb
->queue
, &vpfe_dev
->dma_queue
);
1264 spin_unlock_irqrestore(&vpfe_dev
->dma_queue_lock
, flags
);
1266 /* Change state of the buffer */
1267 vb
->state
= VIDEOBUF_QUEUED
;
1270 static void vpfe_videobuf_release(struct videobuf_queue
*vq
,
1271 struct videobuf_buffer
*vb
)
1273 struct vpfe_fh
*fh
= vq
->priv_data
;
1274 struct vpfe_device
*vpfe_dev
= fh
->vpfe_dev
;
1275 unsigned long flags
;
1277 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_videobuf_release\n");
1280 * We need to flush the buffer from the dma queue since
1281 * they are de-allocated
1283 spin_lock_irqsave(&vpfe_dev
->dma_queue_lock
, flags
);
1284 INIT_LIST_HEAD(&vpfe_dev
->dma_queue
);
1285 spin_unlock_irqrestore(&vpfe_dev
->dma_queue_lock
, flags
);
1286 videobuf_dma_contig_free(vq
, vb
);
1287 vb
->state
= VIDEOBUF_NEEDS_INIT
;
1290 static struct videobuf_queue_ops vpfe_videobuf_qops
= {
1291 .buf_setup
= vpfe_videobuf_setup
,
1292 .buf_prepare
= vpfe_videobuf_prepare
,
1293 .buf_queue
= vpfe_videobuf_queue
,
1294 .buf_release
= vpfe_videobuf_release
,
1298 * vpfe_reqbufs. currently support REQBUF only once opening
1301 static int vpfe_reqbufs(struct file
*file
, void *priv
,
1302 struct v4l2_requestbuffers
*req_buf
)
1304 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1305 struct vpfe_fh
*fh
= file
->private_data
;
1308 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_reqbufs\n");
1310 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= req_buf
->type
) {
1311 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid buffer type\n");
1315 if (V4L2_MEMORY_USERPTR
== req_buf
->memory
) {
1316 /* we don't support user ptr IO */
1317 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_reqbufs:"
1318 " USERPTR IO not supported\n");
1322 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1326 if (vpfe_dev
->io_usrs
!= 0) {
1327 v4l2_err(&vpfe_dev
->v4l2_dev
, "Only one IO user allowed\n");
1332 vpfe_dev
->memory
= req_buf
->memory
;
1333 videobuf_queue_dma_contig_init(&vpfe_dev
->buffer_queue
,
1334 &vpfe_videobuf_qops
,
1338 vpfe_dev
->fmt
.fmt
.pix
.field
,
1339 sizeof(struct videobuf_buffer
),
1343 vpfe_dev
->io_usrs
= 1;
1344 INIT_LIST_HEAD(&vpfe_dev
->dma_queue
);
1345 ret
= videobuf_reqbufs(&vpfe_dev
->buffer_queue
, req_buf
);
1347 mutex_unlock(&vpfe_dev
->lock
);
1351 static int vpfe_querybuf(struct file
*file
, void *priv
,
1352 struct v4l2_buffer
*buf
)
1354 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1356 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_querybuf\n");
1358 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= buf
->type
) {
1359 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid buf type\n");
1363 if (vpfe_dev
->memory
!= V4L2_MEMORY_MMAP
) {
1364 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid memory\n");
1367 /* Call videobuf_querybuf to get information */
1368 return videobuf_querybuf(&vpfe_dev
->buffer_queue
, buf
);
1371 static int vpfe_qbuf(struct file
*file
, void *priv
,
1372 struct v4l2_buffer
*p
)
1374 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1375 struct vpfe_fh
*fh
= file
->private_data
;
1377 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_qbuf\n");
1379 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= p
->type
) {
1380 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid buf type\n");
1385 * If this file handle is not allowed to do IO,
1388 if (!fh
->io_allowed
) {
1389 v4l2_err(&vpfe_dev
->v4l2_dev
, "fh->io_allowed\n");
1392 return videobuf_qbuf(&vpfe_dev
->buffer_queue
, p
);
1395 static int vpfe_dqbuf(struct file
*file
, void *priv
,
1396 struct v4l2_buffer
*buf
)
1398 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1400 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_dqbuf\n");
1402 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= buf
->type
) {
1403 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid buf type\n");
1406 return videobuf_dqbuf(&vpfe_dev
->buffer_queue
,
1407 buf
, file
->f_flags
& O_NONBLOCK
);
1410 static int vpfe_queryctrl(struct file
*file
, void *priv
,
1411 struct v4l2_queryctrl
*qctrl
)
1413 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1414 struct vpfe_subdev_info
*sdinfo
;
1416 sdinfo
= vpfe_dev
->current_subdev
;
1418 return v4l2_device_call_until_err(&vpfe_dev
->v4l2_dev
, sdinfo
->grp_id
,
1419 core
, queryctrl
, qctrl
);
1423 static int vpfe_g_ctrl(struct file
*file
, void *priv
, struct v4l2_control
*ctrl
)
1425 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1426 struct vpfe_subdev_info
*sdinfo
;
1428 sdinfo
= vpfe_dev
->current_subdev
;
1430 return v4l2_device_call_until_err(&vpfe_dev
->v4l2_dev
, sdinfo
->grp_id
,
1431 core
, g_ctrl
, ctrl
);
1434 static int vpfe_s_ctrl(struct file
*file
, void *priv
, struct v4l2_control
*ctrl
)
1436 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1437 struct vpfe_subdev_info
*sdinfo
;
1439 sdinfo
= vpfe_dev
->current_subdev
;
1441 return v4l2_device_call_until_err(&vpfe_dev
->v4l2_dev
, sdinfo
->grp_id
,
1442 core
, s_ctrl
, ctrl
);
1446 * vpfe_calculate_offsets : This function calculates buffers offset
1447 * for top and bottom field
1449 static void vpfe_calculate_offsets(struct vpfe_device
*vpfe_dev
)
1451 struct v4l2_rect image_win
;
1453 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_calculate_offsets\n");
1455 ccdc_dev
->hw_ops
.get_image_window(&image_win
);
1456 vpfe_dev
->field_off
= image_win
.height
* image_win
.width
;
1459 /* vpfe_start_ccdc_capture: start streaming in ccdc/isif */
1460 static void vpfe_start_ccdc_capture(struct vpfe_device
*vpfe_dev
)
1462 ccdc_dev
->hw_ops
.enable(1);
1463 if (ccdc_dev
->hw_ops
.enable_out_to_sdram
)
1464 ccdc_dev
->hw_ops
.enable_out_to_sdram(1);
1465 vpfe_dev
->started
= 1;
1469 * vpfe_streamon. Assume the DMA queue is not empty.
1470 * application is expected to call QBUF before calling
1471 * this ioctl. If not, driver returns error
1473 static int vpfe_streamon(struct file
*file
, void *priv
,
1474 enum v4l2_buf_type buf_type
)
1476 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1477 struct vpfe_fh
*fh
= file
->private_data
;
1478 struct vpfe_subdev_info
*sdinfo
;
1482 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_streamon\n");
1484 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= buf_type
) {
1485 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid buf type\n");
1489 /* If file handle is not allowed IO, return error */
1490 if (!fh
->io_allowed
) {
1491 v4l2_err(&vpfe_dev
->v4l2_dev
, "fh->io_allowed\n");
1495 sdinfo
= vpfe_dev
->current_subdev
;
1496 ret
= v4l2_device_call_until_err(&vpfe_dev
->v4l2_dev
, sdinfo
->grp_id
,
1497 video
, s_stream
, 1);
1499 if (ret
&& (ret
!= -ENOIOCTLCMD
)) {
1500 v4l2_err(&vpfe_dev
->v4l2_dev
, "stream on failed in subdev\n");
1504 /* If buffer queue is empty, return error */
1505 if (list_empty(&vpfe_dev
->buffer_queue
.stream
)) {
1506 v4l2_err(&vpfe_dev
->v4l2_dev
, "buffer queue is empty\n");
1510 /* Call videobuf_streamon to start streaming * in videobuf */
1511 ret
= videobuf_streamon(&vpfe_dev
->buffer_queue
);
1516 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1519 /* Get the next frame from the buffer queue */
1520 vpfe_dev
->next_frm
= list_entry(vpfe_dev
->dma_queue
.next
,
1521 struct videobuf_buffer
, queue
);
1522 vpfe_dev
->cur_frm
= vpfe_dev
->next_frm
;
1523 /* Remove buffer from the buffer queue */
1524 list_del(&vpfe_dev
->cur_frm
->queue
);
1525 /* Mark state of the current frame to active */
1526 vpfe_dev
->cur_frm
->state
= VIDEOBUF_ACTIVE
;
1527 /* Initialize field_id and started member */
1528 vpfe_dev
->field_id
= 0;
1529 addr
= videobuf_to_dma_contig(vpfe_dev
->cur_frm
);
1531 /* Calculate field offset */
1532 vpfe_calculate_offsets(vpfe_dev
);
1534 if (vpfe_attach_irq(vpfe_dev
) < 0) {
1535 v4l2_err(&vpfe_dev
->v4l2_dev
,
1536 "Error in attaching interrupt handle\n");
1540 if (ccdc_dev
->hw_ops
.configure() < 0) {
1541 v4l2_err(&vpfe_dev
->v4l2_dev
,
1542 "Error in configuring ccdc\n");
1546 ccdc_dev
->hw_ops
.setfbaddr((unsigned long)(addr
));
1547 vpfe_start_ccdc_capture(vpfe_dev
);
1548 mutex_unlock(&vpfe_dev
->lock
);
1551 mutex_unlock(&vpfe_dev
->lock
);
1553 ret
= videobuf_streamoff(&vpfe_dev
->buffer_queue
);
1557 static int vpfe_streamoff(struct file
*file
, void *priv
,
1558 enum v4l2_buf_type buf_type
)
1560 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1561 struct vpfe_fh
*fh
= file
->private_data
;
1562 struct vpfe_subdev_info
*sdinfo
;
1565 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_streamoff\n");
1567 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= buf_type
) {
1568 v4l2_err(&vpfe_dev
->v4l2_dev
, "Invalid buf type\n");
1572 /* If io is allowed for this file handle, return error */
1573 if (!fh
->io_allowed
) {
1574 v4l2_err(&vpfe_dev
->v4l2_dev
, "fh->io_allowed\n");
1578 /* If streaming is not started, return error */
1579 if (!vpfe_dev
->started
) {
1580 v4l2_err(&vpfe_dev
->v4l2_dev
, "device started\n");
1584 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1588 vpfe_stop_ccdc_capture(vpfe_dev
);
1589 vpfe_detach_irq(vpfe_dev
);
1591 sdinfo
= vpfe_dev
->current_subdev
;
1592 ret
= v4l2_device_call_until_err(&vpfe_dev
->v4l2_dev
, sdinfo
->grp_id
,
1593 video
, s_stream
, 0);
1595 if (ret
&& (ret
!= -ENOIOCTLCMD
))
1596 v4l2_err(&vpfe_dev
->v4l2_dev
, "stream off failed in subdev\n");
1597 ret
= videobuf_streamoff(&vpfe_dev
->buffer_queue
);
1598 mutex_unlock(&vpfe_dev
->lock
);
1602 static int vpfe_cropcap(struct file
*file
, void *priv
,
1603 struct v4l2_cropcap
*crop
)
1605 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1607 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_cropcap\n");
1609 if (vpfe_dev
->std_index
>= ARRAY_SIZE(vpfe_standards
))
1612 memset(crop
, 0, sizeof(struct v4l2_cropcap
));
1613 crop
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1614 crop
->bounds
.width
= crop
->defrect
.width
=
1615 vpfe_standards
[vpfe_dev
->std_index
].width
;
1616 crop
->bounds
.height
= crop
->defrect
.height
=
1617 vpfe_standards
[vpfe_dev
->std_index
].height
;
1618 crop
->pixelaspect
= vpfe_standards
[vpfe_dev
->std_index
].pixelaspect
;
1622 static int vpfe_g_crop(struct file
*file
, void *priv
,
1623 struct v4l2_crop
*crop
)
1625 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1627 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_g_crop\n");
1629 crop
->c
= vpfe_dev
->crop
;
1633 static int vpfe_s_crop(struct file
*file
, void *priv
,
1634 struct v4l2_crop
*crop
)
1636 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1639 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_s_crop\n");
1641 if (vpfe_dev
->started
) {
1642 /* make sure streaming is not started */
1643 v4l2_err(&vpfe_dev
->v4l2_dev
,
1644 "Cannot change crop when streaming is ON\n");
1648 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1652 if (crop
->c
.top
< 0 || crop
->c
.left
< 0) {
1653 v4l2_err(&vpfe_dev
->v4l2_dev
,
1654 "doesn't support negative values for top & left\n");
1659 /* adjust the width to 16 pixel boundry */
1660 crop
->c
.width
= ((crop
->c
.width
+ 15) & ~0xf);
1662 /* make sure parameters are valid */
1663 if ((crop
->c
.left
+ crop
->c
.width
>
1664 vpfe_dev
->std_info
.active_pixels
) ||
1665 (crop
->c
.top
+ crop
->c
.height
>
1666 vpfe_dev
->std_info
.active_lines
)) {
1667 v4l2_err(&vpfe_dev
->v4l2_dev
, "Error in S_CROP params\n");
1671 ccdc_dev
->hw_ops
.set_image_window(&crop
->c
);
1672 vpfe_dev
->fmt
.fmt
.pix
.width
= crop
->c
.width
;
1673 vpfe_dev
->fmt
.fmt
.pix
.height
= crop
->c
.height
;
1674 vpfe_dev
->fmt
.fmt
.pix
.bytesperline
=
1675 ccdc_dev
->hw_ops
.get_line_length();
1676 vpfe_dev
->fmt
.fmt
.pix
.sizeimage
=
1677 vpfe_dev
->fmt
.fmt
.pix
.bytesperline
*
1678 vpfe_dev
->fmt
.fmt
.pix
.height
;
1679 vpfe_dev
->crop
= crop
->c
;
1681 mutex_unlock(&vpfe_dev
->lock
);
1686 static long vpfe_param_handler(struct file
*file
, void *priv
,
1687 int cmd
, void *param
)
1689 struct vpfe_device
*vpfe_dev
= video_drvdata(file
);
1692 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
, "vpfe_param_handler\n");
1694 if (vpfe_dev
->started
) {
1695 /* only allowed if streaming is not started */
1696 v4l2_err(&vpfe_dev
->v4l2_dev
, "device already started\n");
1700 ret
= mutex_lock_interruptible(&vpfe_dev
->lock
);
1705 case VPFE_CMD_S_CCDC_RAW_PARAMS
:
1706 v4l2_warn(&vpfe_dev
->v4l2_dev
,
1707 "VPFE_CMD_S_CCDC_RAW_PARAMS: experimental ioctl\n");
1708 ret
= ccdc_dev
->hw_ops
.set_params(param
);
1710 v4l2_err(&vpfe_dev
->v4l2_dev
,
1711 "Error in setting parameters in CCDC\n");
1714 if (vpfe_get_ccdc_image_format(vpfe_dev
, &vpfe_dev
->fmt
) < 0) {
1715 v4l2_err(&vpfe_dev
->v4l2_dev
,
1716 "Invalid image format at CCDC\n");
1724 mutex_unlock(&vpfe_dev
->lock
);
1729 /* vpfe capture ioctl operations */
1730 static const struct v4l2_ioctl_ops vpfe_ioctl_ops
= {
1731 .vidioc_querycap
= vpfe_querycap
,
1732 .vidioc_g_fmt_vid_cap
= vpfe_g_fmt_vid_cap
,
1733 .vidioc_enum_fmt_vid_cap
= vpfe_enum_fmt_vid_cap
,
1734 .vidioc_s_fmt_vid_cap
= vpfe_s_fmt_vid_cap
,
1735 .vidioc_try_fmt_vid_cap
= vpfe_try_fmt_vid_cap
,
1736 .vidioc_enum_input
= vpfe_enum_input
,
1737 .vidioc_g_input
= vpfe_g_input
,
1738 .vidioc_s_input
= vpfe_s_input
,
1739 .vidioc_querystd
= vpfe_querystd
,
1740 .vidioc_s_std
= vpfe_s_std
,
1741 .vidioc_g_std
= vpfe_g_std
,
1742 .vidioc_queryctrl
= vpfe_queryctrl
,
1743 .vidioc_g_ctrl
= vpfe_g_ctrl
,
1744 .vidioc_s_ctrl
= vpfe_s_ctrl
,
1745 .vidioc_reqbufs
= vpfe_reqbufs
,
1746 .vidioc_querybuf
= vpfe_querybuf
,
1747 .vidioc_qbuf
= vpfe_qbuf
,
1748 .vidioc_dqbuf
= vpfe_dqbuf
,
1749 .vidioc_streamon
= vpfe_streamon
,
1750 .vidioc_streamoff
= vpfe_streamoff
,
1751 .vidioc_cropcap
= vpfe_cropcap
,
1752 .vidioc_g_crop
= vpfe_g_crop
,
1753 .vidioc_s_crop
= vpfe_s_crop
,
1754 .vidioc_default
= vpfe_param_handler
,
1757 static struct vpfe_device
*vpfe_initialize(void)
1759 struct vpfe_device
*vpfe_dev
;
1761 /* Default number of buffers should be 3 */
1762 if ((numbuffers
> 0) &&
1763 (numbuffers
< config_params
.min_numbuffers
))
1764 numbuffers
= config_params
.min_numbuffers
;
1767 * Set buffer size to min buffers size if invalid buffer size is
1770 if (bufsize
< config_params
.min_bufsize
)
1771 bufsize
= config_params
.min_bufsize
;
1773 config_params
.numbuffers
= numbuffers
;
1776 config_params
.device_bufsize
= bufsize
;
1778 /* Allocate memory for device objects */
1779 vpfe_dev
= kzalloc(sizeof(*vpfe_dev
), GFP_KERNEL
);
1785 * vpfe_probe : This function creates device entries by register
1786 * itself to the V4L2 driver and initializes fields of each
1789 static __init
int vpfe_probe(struct platform_device
*pdev
)
1791 struct vpfe_subdev_info
*sdinfo
;
1792 struct vpfe_config
*vpfe_cfg
;
1793 struct resource
*res1
;
1794 struct vpfe_device
*vpfe_dev
;
1795 struct i2c_adapter
*i2c_adap
;
1796 struct video_device
*vfd
;
1797 int ret
= -ENOMEM
, i
, j
;
1798 int num_subdevs
= 0;
1800 /* Get the pointer to the device object */
1801 vpfe_dev
= vpfe_initialize();
1804 v4l2_err(pdev
->dev
.driver
,
1805 "Failed to allocate memory for vpfe_dev\n");
1809 vpfe_dev
->pdev
= &pdev
->dev
;
1811 if (NULL
== pdev
->dev
.platform_data
) {
1812 v4l2_err(pdev
->dev
.driver
, "Unable to get vpfe config\n");
1814 goto probe_free_dev_mem
;
1817 vpfe_cfg
= pdev
->dev
.platform_data
;
1818 vpfe_dev
->cfg
= vpfe_cfg
;
1819 if (NULL
== vpfe_cfg
->ccdc
||
1820 NULL
== vpfe_cfg
->card_name
||
1821 NULL
== vpfe_cfg
->sub_devs
) {
1822 v4l2_err(pdev
->dev
.driver
, "null ptr in vpfe_cfg\n");
1824 goto probe_free_dev_mem
;
1827 mutex_lock(&ccdc_lock
);
1828 /* Allocate memory for ccdc configuration */
1829 ccdc_cfg
= kmalloc(sizeof(struct ccdc_config
), GFP_KERNEL
);
1830 if (NULL
== ccdc_cfg
) {
1831 v4l2_err(pdev
->dev
.driver
,
1832 "Memory allocation failed for ccdc_cfg\n");
1833 goto probe_free_dev_mem
;
1836 strncpy(ccdc_cfg
->name
, vpfe_cfg
->ccdc
, 32);
1837 /* Get VINT0 irq resource */
1838 res1
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
1840 v4l2_err(pdev
->dev
.driver
,
1841 "Unable to get interrupt for VINT0\n");
1843 goto probe_free_ccdc_cfg_mem
;
1845 vpfe_dev
->ccdc_irq0
= res1
->start
;
1847 /* Get VINT1 irq resource */
1848 res1
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 1);
1850 v4l2_err(pdev
->dev
.driver
,
1851 "Unable to get interrupt for VINT1\n");
1853 goto probe_free_ccdc_cfg_mem
;
1855 vpfe_dev
->ccdc_irq1
= res1
->start
;
1857 ret
= request_irq(vpfe_dev
->ccdc_irq0
, vpfe_isr
, IRQF_DISABLED
,
1858 "vpfe_capture0", vpfe_dev
);
1861 v4l2_err(pdev
->dev
.driver
, "Unable to request interrupt\n");
1862 goto probe_free_ccdc_cfg_mem
;
1865 /* Allocate memory for video device */
1866 vfd
= video_device_alloc();
1869 v4l2_err(pdev
->dev
.driver
, "Unable to alloc video device\n");
1870 goto probe_out_release_irq
;
1873 /* Initialize field of video device */
1874 vfd
->release
= video_device_release
;
1875 vfd
->fops
= &vpfe_fops
;
1876 vfd
->ioctl_ops
= &vpfe_ioctl_ops
;
1878 vfd
->current_norm
= V4L2_STD_PAL
;
1879 vfd
->v4l2_dev
= &vpfe_dev
->v4l2_dev
;
1880 snprintf(vfd
->name
, sizeof(vfd
->name
),
1883 (VPFE_CAPTURE_VERSION_CODE
>> 16) & 0xff,
1884 (VPFE_CAPTURE_VERSION_CODE
>> 8) & 0xff,
1885 (VPFE_CAPTURE_VERSION_CODE
) & 0xff);
1886 /* Set video_dev to the video device */
1887 vpfe_dev
->video_dev
= vfd
;
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_video_release
;
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 /* Initialize prio member of device object */
1904 v4l2_prio_init(&vpfe_dev
->prio
);
1905 /* register video device */
1906 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
,
1907 "trying to register vpfe device.\n");
1908 v4l2_dbg(1, debug
, &vpfe_dev
->v4l2_dev
,
1909 "video_dev=%x\n", (int)&vpfe_dev
->video_dev
);
1910 vpfe_dev
->fmt
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1911 ret
= video_register_device(vpfe_dev
->video_dev
,
1912 VFL_TYPE_GRABBER
, -1);
1915 v4l2_err(pdev
->dev
.driver
,
1916 "Unable to register video device.\n");
1917 goto probe_out_v4l2_unregister
;
1920 v4l2_info(&vpfe_dev
->v4l2_dev
, "video device registered\n");
1921 /* set the driver data in platform device */
1922 platform_set_drvdata(pdev
, vpfe_dev
);
1923 /* set driver private data */
1924 video_set_drvdata(vpfe_dev
->video_dev
, vpfe_dev
);
1925 i2c_adap
= i2c_get_adapter(vpfe_cfg
->i2c_adapter_id
);
1926 num_subdevs
= vpfe_cfg
->num_subdevs
;
1927 vpfe_dev
->sd
= kmalloc(sizeof(struct v4l2_subdev
*) * num_subdevs
,
1929 if (NULL
== vpfe_dev
->sd
) {
1930 v4l2_err(&vpfe_dev
->v4l2_dev
,
1931 "unable to allocate memory for subdevice pointers\n");
1933 goto probe_out_video_unregister
;
1936 for (i
= 0; i
< num_subdevs
; i
++) {
1937 struct v4l2_input
*inps
;
1939 sdinfo
= &vpfe_cfg
->sub_devs
[i
];
1941 /* Load up the subdevice */
1943 v4l2_i2c_new_subdev_board(&vpfe_dev
->v4l2_dev
,
1946 &sdinfo
->board_info
,
1948 if (vpfe_dev
->sd
[i
]) {
1949 v4l2_info(&vpfe_dev
->v4l2_dev
,
1950 "v4l2 sub device %s registered\n",
1952 vpfe_dev
->sd
[i
]->grp_id
= sdinfo
->grp_id
;
1953 /* update tvnorms from the sub devices */
1954 for (j
= 0; j
< sdinfo
->num_inputs
; j
++) {
1955 inps
= &sdinfo
->inputs
[j
];
1956 vfd
->tvnorms
|= inps
->std
;
1959 v4l2_info(&vpfe_dev
->v4l2_dev
,
1960 "v4l2 sub device %s register fails\n",
1966 /* set first sub device as current one */
1967 vpfe_dev
->current_subdev
= &vpfe_cfg
->sub_devs
[0];
1969 /* We have at least one sub device to work with */
1970 mutex_unlock(&ccdc_lock
);
1974 kfree(vpfe_dev
->sd
);
1975 probe_out_video_unregister
:
1976 video_unregister_device(vpfe_dev
->video_dev
);
1977 probe_out_v4l2_unregister
:
1978 v4l2_device_unregister(&vpfe_dev
->v4l2_dev
);
1979 probe_out_video_release
:
1980 if (!video_is_registered(vpfe_dev
->video_dev
))
1981 video_device_release(vpfe_dev
->video_dev
);
1982 probe_out_release_irq
:
1983 free_irq(vpfe_dev
->ccdc_irq0
, vpfe_dev
);
1984 probe_free_ccdc_cfg_mem
:
1985 mutex_unlock(&ccdc_lock
);
1993 * vpfe_remove : It un-register device from V4L2 driver
1995 static int __devexit
vpfe_remove(struct platform_device
*pdev
)
1997 struct vpfe_device
*vpfe_dev
= platform_get_drvdata(pdev
);
1999 v4l2_info(pdev
->dev
.driver
, "vpfe_remove\n");
2001 free_irq(vpfe_dev
->ccdc_irq0
, vpfe_dev
);
2002 kfree(vpfe_dev
->sd
);
2003 v4l2_device_unregister(&vpfe_dev
->v4l2_dev
);
2004 video_unregister_device(vpfe_dev
->video_dev
);
2011 vpfe_suspend(struct device
*dev
)
2013 /* add suspend code here later */
2018 vpfe_resume(struct device
*dev
)
2020 /* add resume code here later */
2024 static const struct dev_pm_ops vpfe_dev_pm_ops
= {
2025 .suspend
= vpfe_suspend
,
2026 .resume
= vpfe_resume
,
2029 static struct platform_driver vpfe_driver
= {
2031 .name
= CAPTURE_DRV_NAME
,
2032 .owner
= THIS_MODULE
,
2033 .pm
= &vpfe_dev_pm_ops
,
2035 .probe
= vpfe_probe
,
2036 .remove
= __devexit_p(vpfe_remove
),
2039 static __init
int vpfe_init(void)
2041 printk(KERN_NOTICE
"vpfe_init\n");
2042 /* Register driver to the kernel */
2043 return platform_driver_register(&vpfe_driver
);
2047 * vpfe_cleanup : This function un-registers device driver
2049 static void vpfe_cleanup(void)
2051 platform_driver_unregister(&vpfe_driver
);
2054 module_init(vpfe_init
);
2055 module_exit(vpfe_cleanup
);