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/init.h>
71 #include <linux/platform_device.h>
72 #include <linux/interrupt.h>
73 #include <media/v4l2-common.h>
75 #include <media/davinci/vpfe_capture.h>
76 #include "ccdc_hw_device.h"
79 static u32 numbuffers = 3;
80 static u32 bufsize = (720 * 576 * 2);
82 module_param(numbuffers, uint, S_IRUGO);
83 module_param(bufsize, uint, S_IRUGO);
84 module_param(debug, int, 0644);
86 MODULE_PARM_DESC(numbuffers, "buffer count (default:3)");
87 MODULE_PARM_DESC(bufsize, "buffer size in bytes (default:720 x 576 x 2)");
88 MODULE_PARM_DESC(debug, "Debug level 0-1");
90 MODULE_DESCRIPTION("VPFE Video for Linux Capture Driver");
91 MODULE_LICENSE("GPL");
92 MODULE_AUTHOR("Texas Instruments");
94 /* standard information */
95 struct vpfe_standard {
99 struct v4l2_fract pixelaspect;
100 /* 0 - progressive, 1 - interlaced */
104 /* ccdc configuration */
106 /* This make sure vpfe is probed and ready to go */
108 /* name of ccdc device */
110 /* for storing mem maps for CCDC */
112 void *__iomem ccdc_addr;
115 /* data structures */
116 static struct vpfe_config_params config_params = {
119 .min_bufsize = 720 * 480 * 2,
120 .device_bufsize = 720 * 576 * 2,
123 /* ccdc device registered */
124 static struct ccdc_hw_device *ccdc_dev;
125 /* lock for accessing ccdc information */
126 static DEFINE_MUTEX(ccdc_lock);
127 /* ccdc configuration */
128 static struct ccdc_config *ccdc_cfg;
130 const struct vpfe_standard vpfe_standards[] = {
131 {V4L2_STD_525_60, 720, 480, {11, 10}, 1},
132 {V4L2_STD_625_50, 720, 576, {54, 59}, 1},
135 /* Used when raw Bayer image from ccdc is directly captured to SDRAM */
136 static const struct vpfe_pixel_format vpfe_pix_fmts[] = {
140 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
141 .description = "Bayer GrRBGb 8bit A-Law compr.",
142 .pixelformat = V4L2_PIX_FMT_SBGGR8,
149 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
150 .description = "Bayer GrRBGb - 16bit",
151 .pixelformat = V4L2_PIX_FMT_SBGGR16,
158 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
159 .description = "Bayer GrRBGb 8bit DPCM compr.",
160 .pixelformat = V4L2_PIX_FMT_SGRBG10DPCM8,
167 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
168 .description = "YCbCr 4:2:2 Interleaved UYVY",
169 .pixelformat = V4L2_PIX_FMT_UYVY,
176 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
177 .description = "YCbCr 4:2:2 Interleaved YUYV",
178 .pixelformat = V4L2_PIX_FMT_YUYV,
185 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
186 .description = "Y/CbCr 4:2:0 - Semi planar",
187 .pixelformat = V4L2_PIX_FMT_NV12,
194 * vpfe_lookup_pix_format()
195 * lookup an entry in the vpfe pix format table based on pix_format
197 static const struct vpfe_pixel_format *vpfe_lookup_pix_format(u32 pix_format)
201 for (i = 0; i < ARRAY_SIZE(vpfe_pix_fmts); i++) {
202 if (pix_format == vpfe_pix_fmts[i].fmtdesc.pixelformat)
203 return &vpfe_pix_fmts[i];
209 * vpfe_register_ccdc_device. CCDC module calls this to
210 * register with vpfe capture
212 int vpfe_register_ccdc_device(struct ccdc_hw_device *dev)
215 printk(KERN_NOTICE "vpfe_register_ccdc_device: %s\n", dev->name);
217 BUG_ON(!dev->hw_ops.open);
218 BUG_ON(!dev->hw_ops.enable);
219 BUG_ON(!dev->hw_ops.set_hw_if_params);
220 BUG_ON(!dev->hw_ops.configure);
221 BUG_ON(!dev->hw_ops.set_buftype);
222 BUG_ON(!dev->hw_ops.get_buftype);
223 BUG_ON(!dev->hw_ops.enum_pix);
224 BUG_ON(!dev->hw_ops.set_frame_format);
225 BUG_ON(!dev->hw_ops.get_frame_format);
226 BUG_ON(!dev->hw_ops.get_pixel_format);
227 BUG_ON(!dev->hw_ops.set_pixel_format);
228 BUG_ON(!dev->hw_ops.set_params);
229 BUG_ON(!dev->hw_ops.set_image_window);
230 BUG_ON(!dev->hw_ops.get_image_window);
231 BUG_ON(!dev->hw_ops.get_line_length);
232 BUG_ON(!dev->hw_ops.setfbaddr);
233 BUG_ON(!dev->hw_ops.getfid);
235 mutex_lock(&ccdc_lock);
236 if (NULL == ccdc_cfg) {
238 * TODO. Will this ever happen? if so, we need to fix it.
239 * Proabably we need to add the request to a linked list and
240 * walk through it during vpfe probe
242 printk(KERN_ERR "vpfe capture not initialized\n");
247 if (strcmp(dev->name, ccdc_cfg->name)) {
248 /* ignore this ccdc */
254 printk(KERN_ERR "ccdc already registered\n");
260 dev->hw_ops.set_ccdc_base(ccdc_cfg->ccdc_addr,
261 ccdc_cfg->ccdc_addr_size);
263 mutex_unlock(&ccdc_lock);
266 EXPORT_SYMBOL(vpfe_register_ccdc_device);
269 * vpfe_unregister_ccdc_device. CCDC module calls this to
270 * unregister with vpfe capture
272 void vpfe_unregister_ccdc_device(struct ccdc_hw_device *dev)
275 printk(KERN_ERR "invalid ccdc device ptr\n");
279 printk(KERN_NOTICE "vpfe_unregister_ccdc_device, dev->name = %s\n",
282 if (strcmp(dev->name, ccdc_cfg->name)) {
283 /* ignore this ccdc */
287 mutex_lock(&ccdc_lock);
289 mutex_unlock(&ccdc_lock);
292 EXPORT_SYMBOL(vpfe_unregister_ccdc_device);
295 * vpfe_get_ccdc_image_format - Get image parameters based on CCDC settings
297 static int vpfe_get_ccdc_image_format(struct vpfe_device *vpfe_dev,
298 struct v4l2_format *f)
300 struct v4l2_rect image_win;
301 enum ccdc_buftype buf_type;
302 enum ccdc_frmfmt frm_fmt;
304 memset(f, 0, sizeof(*f));
305 f->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
306 ccdc_dev->hw_ops.get_image_window(&image_win);
307 f->fmt.pix.width = image_win.width;
308 f->fmt.pix.height = image_win.height;
309 f->fmt.pix.bytesperline = ccdc_dev->hw_ops.get_line_length();
310 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline *
312 buf_type = ccdc_dev->hw_ops.get_buftype();
313 f->fmt.pix.pixelformat = ccdc_dev->hw_ops.get_pixel_format();
314 frm_fmt = ccdc_dev->hw_ops.get_frame_format();
315 if (frm_fmt == CCDC_FRMFMT_PROGRESSIVE)
316 f->fmt.pix.field = V4L2_FIELD_NONE;
317 else if (frm_fmt == CCDC_FRMFMT_INTERLACED) {
318 if (buf_type == CCDC_BUFTYPE_FLD_INTERLEAVED)
319 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
320 else if (buf_type == CCDC_BUFTYPE_FLD_SEPARATED)
321 f->fmt.pix.field = V4L2_FIELD_SEQ_TB;
323 v4l2_err(&vpfe_dev->v4l2_dev, "Invalid buf_type\n");
327 v4l2_err(&vpfe_dev->v4l2_dev, "Invalid frm_fmt\n");
334 * vpfe_config_ccdc_image_format()
335 * For a pix format, configure ccdc to setup the capture
337 static int vpfe_config_ccdc_image_format(struct vpfe_device *vpfe_dev)
339 enum ccdc_frmfmt frm_fmt = CCDC_FRMFMT_INTERLACED;
342 if (ccdc_dev->hw_ops.set_pixel_format(
343 vpfe_dev->fmt.fmt.pix.pixelformat) < 0) {
344 v4l2_err(&vpfe_dev->v4l2_dev,
345 "couldn't set pix format in ccdc\n");
348 /* configure the image window */
349 ccdc_dev->hw_ops.set_image_window(&vpfe_dev->crop);
351 switch (vpfe_dev->fmt.fmt.pix.field) {
352 case V4L2_FIELD_INTERLACED:
353 /* do nothing, since it is default */
354 ret = ccdc_dev->hw_ops.set_buftype(
355 CCDC_BUFTYPE_FLD_INTERLEAVED);
357 case V4L2_FIELD_NONE:
358 frm_fmt = CCDC_FRMFMT_PROGRESSIVE;
359 /* buffer type only applicable for interlaced scan */
361 case V4L2_FIELD_SEQ_TB:
362 ret = ccdc_dev->hw_ops.set_buftype(
363 CCDC_BUFTYPE_FLD_SEPARATED);
369 /* set the frame format */
371 ret = ccdc_dev->hw_ops.set_frame_format(frm_fmt);
375 * vpfe_config_image_format()
376 * For a given standard, this functions sets up the default
377 * pix format & crop values in the vpfe device and ccdc. It first
378 * starts with defaults based values from the standard table.
379 * It then checks if sub device support g_fmt and then override the
380 * values based on that.Sets crop values to match with scan resolution
381 * starting at 0,0. It calls vpfe_config_ccdc_image_format() set the
384 static int vpfe_config_image_format(struct vpfe_device *vpfe_dev,
385 const v4l2_std_id *std_id)
387 struct vpfe_subdev_info *sdinfo = vpfe_dev->current_subdev;
390 for (i = 0; i < ARRAY_SIZE(vpfe_standards); i++) {
391 if (vpfe_standards[i].std_id & *std_id) {
392 vpfe_dev->std_info.active_pixels =
393 vpfe_standards[i].width;
394 vpfe_dev->std_info.active_lines =
395 vpfe_standards[i].height;
396 vpfe_dev->std_info.frame_format =
397 vpfe_standards[i].frame_format;
398 vpfe_dev->std_index = i;
403 if (i == ARRAY_SIZE(vpfe_standards)) {
404 v4l2_err(&vpfe_dev->v4l2_dev, "standard not supported\n");
408 vpfe_dev->crop.top = 0;
409 vpfe_dev->crop.left = 0;
410 vpfe_dev->crop.width = vpfe_dev->std_info.active_pixels;
411 vpfe_dev->crop.height = vpfe_dev->std_info.active_lines;
412 vpfe_dev->fmt.fmt.pix.width = vpfe_dev->crop.width;
413 vpfe_dev->fmt.fmt.pix.height = vpfe_dev->crop.height;
415 /* first field and frame format based on standard frame format */
416 if (vpfe_dev->std_info.frame_format) {
417 vpfe_dev->fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
418 /* assume V4L2_PIX_FMT_UYVY as default */
419 vpfe_dev->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;
421 vpfe_dev->fmt.fmt.pix.field = V4L2_FIELD_NONE;
422 /* assume V4L2_PIX_FMT_SBGGR8 */
423 vpfe_dev->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR8;
426 /* if sub device supports g_fmt, override the defaults */
427 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev,
428 sdinfo->grp_id, video, g_fmt, &vpfe_dev->fmt);
430 if (ret && ret != -ENOIOCTLCMD) {
431 v4l2_err(&vpfe_dev->v4l2_dev,
432 "error in getting g_fmt from sub device\n");
436 /* Sets the values in CCDC */
437 ret = vpfe_config_ccdc_image_format(vpfe_dev);
441 /* Update the values of sizeimage and bytesperline */
443 vpfe_dev->fmt.fmt.pix.bytesperline =
444 ccdc_dev->hw_ops.get_line_length();
445 vpfe_dev->fmt.fmt.pix.sizeimage =
446 vpfe_dev->fmt.fmt.pix.bytesperline *
447 vpfe_dev->fmt.fmt.pix.height;
452 static int vpfe_initialize_device(struct vpfe_device *vpfe_dev)
456 /* set first input of current subdevice as the current input */
457 vpfe_dev->current_input = 0;
459 /* set default standard */
460 vpfe_dev->std_index = 0;
462 /* Configure the default format information */
463 ret = vpfe_config_image_format(vpfe_dev,
464 &vpfe_standards[vpfe_dev->std_index].std_id);
468 /* now open the ccdc device to initialize it */
469 mutex_lock(&ccdc_lock);
470 if (NULL == ccdc_dev) {
471 v4l2_err(&vpfe_dev->v4l2_dev, "ccdc device not registered\n");
476 if (!try_module_get(ccdc_dev->owner)) {
477 v4l2_err(&vpfe_dev->v4l2_dev, "Couldn't lock ccdc module\n");
481 ret = ccdc_dev->hw_ops.open(vpfe_dev->pdev);
483 vpfe_dev->initialized = 1;
485 mutex_unlock(&ccdc_lock);
490 * vpfe_open : It creates object of file handle structure and
491 * stores it in private_data member of filepointer
493 static int vpfe_open(struct file *file)
495 struct vpfe_device *vpfe_dev = video_drvdata(file);
498 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_open\n");
500 if (!vpfe_dev->cfg->num_subdevs) {
501 v4l2_err(&vpfe_dev->v4l2_dev, "No decoder registered\n");
505 /* Allocate memory for the file handle object */
506 fh = kmalloc(sizeof(struct vpfe_fh), GFP_KERNEL);
508 v4l2_err(&vpfe_dev->v4l2_dev,
509 "unable to allocate memory for file handle object\n");
512 /* store pointer to fh in private_data member of file */
513 file->private_data = fh;
514 fh->vpfe_dev = vpfe_dev;
515 mutex_lock(&vpfe_dev->lock);
516 /* If decoder is not initialized. initialize it */
517 if (!vpfe_dev->initialized) {
518 if (vpfe_initialize_device(vpfe_dev)) {
519 mutex_unlock(&vpfe_dev->lock);
523 /* Increment device usrs counter */
525 /* Set io_allowed member to false */
527 /* Initialize priority of this instance to default priority */
528 fh->prio = V4L2_PRIORITY_UNSET;
529 v4l2_prio_open(&vpfe_dev->prio, &fh->prio);
530 mutex_unlock(&vpfe_dev->lock);
534 static void vpfe_schedule_next_buffer(struct vpfe_device *vpfe_dev)
538 vpfe_dev->next_frm = list_entry(vpfe_dev->dma_queue.next,
539 struct videobuf_buffer, queue);
540 list_del(&vpfe_dev->next_frm->queue);
541 vpfe_dev->next_frm->state = VIDEOBUF_ACTIVE;
542 addr = videobuf_to_dma_contig(vpfe_dev->next_frm);
543 ccdc_dev->hw_ops.setfbaddr(addr);
546 static void vpfe_process_buffer_complete(struct vpfe_device *vpfe_dev)
548 struct timeval timevalue;
550 do_gettimeofday(&timevalue);
551 vpfe_dev->cur_frm->ts = timevalue;
552 vpfe_dev->cur_frm->state = VIDEOBUF_DONE;
553 vpfe_dev->cur_frm->size = vpfe_dev->fmt.fmt.pix.sizeimage;
554 wake_up_interruptible(&vpfe_dev->cur_frm->done);
555 vpfe_dev->cur_frm = vpfe_dev->next_frm;
559 static irqreturn_t vpfe_isr(int irq, void *dev_id)
561 struct vpfe_device *vpfe_dev = dev_id;
562 enum v4l2_field field;
566 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "\nStarting vpfe_isr...\n");
567 field = vpfe_dev->fmt.fmt.pix.field;
569 /* if streaming not started, don't do anything */
570 if (!vpfe_dev->started)
573 /* only for 6446 this will be applicable */
574 if (NULL != ccdc_dev->hw_ops.reset)
575 ccdc_dev->hw_ops.reset();
577 if (field == V4L2_FIELD_NONE) {
578 /* handle progressive frame capture */
579 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev,
580 "frame format is progressive...\n");
581 if (vpfe_dev->cur_frm != vpfe_dev->next_frm)
582 vpfe_process_buffer_complete(vpfe_dev);
586 /* interlaced or TB capture check which field we are in hardware */
587 fid = ccdc_dev->hw_ops.getfid();
589 /* switch the software maintained field id */
590 vpfe_dev->field_id ^= 1;
591 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "field id = %x:%x.\n",
592 fid, vpfe_dev->field_id);
593 if (fid == vpfe_dev->field_id) {
594 /* we are in-sync here,continue */
597 * One frame is just being captured. If the next frame
598 * is available, release the current frame and move on
600 if (vpfe_dev->cur_frm != vpfe_dev->next_frm)
601 vpfe_process_buffer_complete(vpfe_dev);
603 * based on whether the two fields are stored
604 * interleavely or separately in memory, reconfigure
605 * the CCDC memory address
607 if (field == V4L2_FIELD_SEQ_TB) {
609 videobuf_to_dma_contig(vpfe_dev->cur_frm);
610 addr += vpfe_dev->field_off;
611 ccdc_dev->hw_ops.setfbaddr(addr);
616 * if one field is just being captured configure
617 * the next frame get the next frame from the empty
618 * queue if no frame is available hold on to the
621 spin_lock(&vpfe_dev->dma_queue_lock);
622 if (!list_empty(&vpfe_dev->dma_queue) &&
623 vpfe_dev->cur_frm == vpfe_dev->next_frm)
624 vpfe_schedule_next_buffer(vpfe_dev);
625 spin_unlock(&vpfe_dev->dma_queue_lock);
626 } else if (fid == 0) {
628 * out of sync. Recover from any hardware out-of-sync.
629 * May loose one frame
631 vpfe_dev->field_id = fid;
636 /* vdint1_isr - isr handler for VINT1 interrupt */
637 static irqreturn_t vdint1_isr(int irq, void *dev_id)
639 struct vpfe_device *vpfe_dev = dev_id;
641 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "\nInside vdint1_isr...\n");
643 /* if streaming not started, don't do anything */
644 if (!vpfe_dev->started)
647 spin_lock(&vpfe_dev->dma_queue_lock);
648 if ((vpfe_dev->fmt.fmt.pix.field == V4L2_FIELD_NONE) &&
649 !list_empty(&vpfe_dev->dma_queue) &&
650 vpfe_dev->cur_frm == vpfe_dev->next_frm)
651 vpfe_schedule_next_buffer(vpfe_dev);
652 spin_unlock(&vpfe_dev->dma_queue_lock);
656 static void vpfe_detach_irq(struct vpfe_device *vpfe_dev)
658 enum ccdc_frmfmt frame_format;
660 frame_format = ccdc_dev->hw_ops.get_frame_format();
661 if (frame_format == CCDC_FRMFMT_PROGRESSIVE)
662 free_irq(vpfe_dev->ccdc_irq1, vpfe_dev);
665 static int vpfe_attach_irq(struct vpfe_device *vpfe_dev)
667 enum ccdc_frmfmt frame_format;
669 frame_format = ccdc_dev->hw_ops.get_frame_format();
670 if (frame_format == CCDC_FRMFMT_PROGRESSIVE) {
671 return request_irq(vpfe_dev->ccdc_irq1, vdint1_isr,
672 IRQF_DISABLED, "vpfe_capture1",
678 /* vpfe_stop_ccdc_capture: stop streaming in ccdc/isif */
679 static void vpfe_stop_ccdc_capture(struct vpfe_device *vpfe_dev)
681 vpfe_dev->started = 0;
682 ccdc_dev->hw_ops.enable(0);
683 if (ccdc_dev->hw_ops.enable_out_to_sdram)
684 ccdc_dev->hw_ops.enable_out_to_sdram(0);
688 * vpfe_release : This function deletes buffer queue, frees the
689 * buffers and the vpfe file handle
691 static int vpfe_release(struct file *file)
693 struct vpfe_device *vpfe_dev = video_drvdata(file);
694 struct vpfe_fh *fh = file->private_data;
695 struct vpfe_subdev_info *sdinfo;
698 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_release\n");
700 /* Get the device lock */
701 mutex_lock(&vpfe_dev->lock);
702 /* if this instance is doing IO */
703 if (fh->io_allowed) {
704 if (vpfe_dev->started) {
705 sdinfo = vpfe_dev->current_subdev;
706 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev,
709 if (ret && (ret != -ENOIOCTLCMD))
710 v4l2_err(&vpfe_dev->v4l2_dev,
711 "stream off failed in subdev\n");
712 vpfe_stop_ccdc_capture(vpfe_dev);
713 vpfe_detach_irq(vpfe_dev);
714 videobuf_streamoff(&vpfe_dev->buffer_queue);
716 vpfe_dev->io_usrs = 0;
717 vpfe_dev->numbuffers = config_params.numbuffers;
720 /* Decrement device usrs counter */
722 /* Close the priority */
723 v4l2_prio_close(&vpfe_dev->prio, &fh->prio);
724 /* If this is the last file handle */
725 if (!vpfe_dev->usrs) {
726 vpfe_dev->initialized = 0;
727 if (ccdc_dev->hw_ops.close)
728 ccdc_dev->hw_ops.close(vpfe_dev->pdev);
729 module_put(ccdc_dev->owner);
731 mutex_unlock(&vpfe_dev->lock);
732 file->private_data = NULL;
733 /* Free memory allocated to file handle object */
739 * vpfe_mmap : It is used to map kernel space buffers
742 static int vpfe_mmap(struct file *file, struct vm_area_struct *vma)
744 /* Get the device object and file handle object */
745 struct vpfe_device *vpfe_dev = video_drvdata(file);
747 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_mmap\n");
749 return videobuf_mmap_mapper(&vpfe_dev->buffer_queue, vma);
753 * vpfe_poll: It is used for select/poll system call
755 static unsigned int vpfe_poll(struct file *file, poll_table *wait)
757 struct vpfe_device *vpfe_dev = video_drvdata(file);
759 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_poll\n");
761 if (vpfe_dev->started)
762 return videobuf_poll_stream(file,
763 &vpfe_dev->buffer_queue, wait);
767 /* vpfe capture driver file operations */
768 static const struct v4l2_file_operations vpfe_fops = {
769 .owner = THIS_MODULE,
771 .release = vpfe_release,
772 .unlocked_ioctl = video_ioctl2,
778 * vpfe_check_format()
779 * This function adjust the input pixel format as per hardware
780 * capabilities and update the same in pixfmt.
781 * Following algorithm used :-
783 * If given pixformat is not in the vpfe list of pix formats or not
784 * supported by the hardware, current value of pixformat in the device
786 * If given field is not supported, then current field is used. If field
787 * is different from current, then it is matched with that from sub device.
788 * Minimum height is 2 lines for interlaced or tb field and 1 line for
789 * progressive. Maximum height is clamped to active active lines of scan
790 * Minimum width is 32 bytes in memory and width is clamped to active
792 * bytesperline is a multiple of 32.
794 static const struct vpfe_pixel_format *
795 vpfe_check_format(struct vpfe_device *vpfe_dev,
796 struct v4l2_pix_format *pixfmt)
798 u32 min_height = 1, min_width = 32, max_width, max_height;
799 const struct vpfe_pixel_format *vpfe_pix_fmt;
803 vpfe_pix_fmt = vpfe_lookup_pix_format(pixfmt->pixelformat);
804 if (NULL == vpfe_pix_fmt) {
806 * use current pixel format in the vpfe device. We
807 * will find this pix format in the table
809 pixfmt->pixelformat = vpfe_dev->fmt.fmt.pix.pixelformat;
810 vpfe_pix_fmt = vpfe_lookup_pix_format(pixfmt->pixelformat);
813 /* check if hw supports it */
816 while (ccdc_dev->hw_ops.enum_pix(&pix, temp) >= 0) {
817 if (vpfe_pix_fmt->fmtdesc.pixelformat == pix) {
825 /* use current pixel format */
826 pixfmt->pixelformat = vpfe_dev->fmt.fmt.pix.pixelformat;
828 * Since this is currently used in the vpfe device, we
829 * will find this pix format in the table
831 vpfe_pix_fmt = vpfe_lookup_pix_format(pixfmt->pixelformat);
834 /* check what field format is supported */
835 if (pixfmt->field == V4L2_FIELD_ANY) {
836 /* if field is any, use current value as default */
837 pixfmt->field = vpfe_dev->fmt.fmt.pix.field;
841 * if field is not same as current field in the vpfe device
842 * try matching the field with the sub device field
844 if (vpfe_dev->fmt.fmt.pix.field != pixfmt->field) {
846 * If field value is not in the supported fields, use current
847 * field used in the device as default
849 switch (pixfmt->field) {
850 case V4L2_FIELD_INTERLACED:
851 case V4L2_FIELD_SEQ_TB:
852 /* if sub device is supporting progressive, use that */
853 if (!vpfe_dev->std_info.frame_format)
854 pixfmt->field = V4L2_FIELD_NONE;
856 case V4L2_FIELD_NONE:
857 if (vpfe_dev->std_info.frame_format)
858 pixfmt->field = V4L2_FIELD_INTERLACED;
862 /* use current field as default */
863 pixfmt->field = vpfe_dev->fmt.fmt.pix.field;
868 /* Now adjust image resolutions supported */
869 if (pixfmt->field == V4L2_FIELD_INTERLACED ||
870 pixfmt->field == V4L2_FIELD_SEQ_TB)
873 max_width = vpfe_dev->std_info.active_pixels;
874 max_height = vpfe_dev->std_info.active_lines;
875 min_width /= vpfe_pix_fmt->bpp;
877 v4l2_info(&vpfe_dev->v4l2_dev, "width = %d, height = %d, bpp = %d\n",
878 pixfmt->width, pixfmt->height, vpfe_pix_fmt->bpp);
880 pixfmt->width = clamp((pixfmt->width), min_width, max_width);
881 pixfmt->height = clamp((pixfmt->height), min_height, max_height);
883 /* If interlaced, adjust height to be a multiple of 2 */
884 if (pixfmt->field == V4L2_FIELD_INTERLACED)
885 pixfmt->height &= (~1);
887 * recalculate bytesperline and sizeimage since width
888 * and height might have changed
890 pixfmt->bytesperline = (((pixfmt->width * vpfe_pix_fmt->bpp) + 31)
892 if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12)
894 pixfmt->bytesperline * pixfmt->height +
895 ((pixfmt->bytesperline * pixfmt->height) >> 1);
897 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
899 v4l2_info(&vpfe_dev->v4l2_dev, "adjusted width = %d, height ="
900 " %d, bpp = %d, bytesperline = %d, sizeimage = %d\n",
901 pixfmt->width, pixfmt->height, vpfe_pix_fmt->bpp,
902 pixfmt->bytesperline, pixfmt->sizeimage);
906 static int vpfe_querycap(struct file *file, void *priv,
907 struct v4l2_capability *cap)
909 struct vpfe_device *vpfe_dev = video_drvdata(file);
911 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_querycap\n");
913 cap->version = VPFE_CAPTURE_VERSION_CODE;
914 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
915 strlcpy(cap->driver, CAPTURE_DRV_NAME, sizeof(cap->driver));
916 strlcpy(cap->bus_info, "VPFE", sizeof(cap->bus_info));
917 strlcpy(cap->card, vpfe_dev->cfg->card_name, sizeof(cap->card));
921 static int vpfe_g_fmt_vid_cap(struct file *file, void *priv,
922 struct v4l2_format *fmt)
924 struct vpfe_device *vpfe_dev = video_drvdata(file);
927 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_g_fmt_vid_cap\n");
928 /* Fill in the information about format */
929 *fmt = vpfe_dev->fmt;
933 static int vpfe_enum_fmt_vid_cap(struct file *file, void *priv,
934 struct v4l2_fmtdesc *fmt)
936 struct vpfe_device *vpfe_dev = video_drvdata(file);
937 const struct vpfe_pixel_format *pix_fmt;
941 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_enum_fmt_vid_cap\n");
943 if (ccdc_dev->hw_ops.enum_pix(&pix, fmt->index) < 0)
946 /* Fill in the information about format */
947 pix_fmt = vpfe_lookup_pix_format(pix);
948 if (NULL != pix_fmt) {
949 temp_index = fmt->index;
950 *fmt = pix_fmt->fmtdesc;
951 fmt->index = temp_index;
957 static int vpfe_s_fmt_vid_cap(struct file *file, void *priv,
958 struct v4l2_format *fmt)
960 struct vpfe_device *vpfe_dev = video_drvdata(file);
961 const struct vpfe_pixel_format *pix_fmts;
964 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_s_fmt_vid_cap\n");
966 /* If streaming is started, return error */
967 if (vpfe_dev->started) {
968 v4l2_err(&vpfe_dev->v4l2_dev, "Streaming is started\n");
972 /* Check for valid frame format */
973 pix_fmts = vpfe_check_format(vpfe_dev, &fmt->fmt.pix);
975 if (NULL == pix_fmts)
978 /* store the pixel format in the device object */
979 ret = mutex_lock_interruptible(&vpfe_dev->lock);
983 /* First detach any IRQ if currently attached */
984 vpfe_detach_irq(vpfe_dev);
985 vpfe_dev->fmt = *fmt;
986 /* set image capture parameters in the ccdc */
987 ret = vpfe_config_ccdc_image_format(vpfe_dev);
988 mutex_unlock(&vpfe_dev->lock);
992 static int vpfe_try_fmt_vid_cap(struct file *file, void *priv,
993 struct v4l2_format *f)
995 struct vpfe_device *vpfe_dev = video_drvdata(file);
996 const struct vpfe_pixel_format *pix_fmts;
998 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_try_fmt_vid_cap\n");
1000 pix_fmts = vpfe_check_format(vpfe_dev, &f->fmt.pix);
1001 if (NULL == pix_fmts)
1007 * vpfe_get_subdev_input_index - Get subdev index and subdev input index for a
1008 * given app input index
1010 static int vpfe_get_subdev_input_index(struct vpfe_device *vpfe_dev,
1012 int *subdev_input_index,
1013 int app_input_index)
1015 struct vpfe_config *cfg = vpfe_dev->cfg;
1016 struct vpfe_subdev_info *sdinfo;
1019 for (i = 0; i < cfg->num_subdevs; i++) {
1020 sdinfo = &cfg->sub_devs[i];
1021 if (app_input_index < (j + sdinfo->num_inputs)) {
1023 *subdev_input_index = app_input_index - j;
1026 j += sdinfo->num_inputs;
1032 * vpfe_get_app_input - Get app input index for a given subdev input index
1033 * driver stores the input index of the current sub device and translate it
1034 * when application request the current input
1036 static int vpfe_get_app_input_index(struct vpfe_device *vpfe_dev,
1037 int *app_input_index)
1039 struct vpfe_config *cfg = vpfe_dev->cfg;
1040 struct vpfe_subdev_info *sdinfo;
1043 for (i = 0; i < cfg->num_subdevs; i++) {
1044 sdinfo = &cfg->sub_devs[i];
1045 if (!strcmp(sdinfo->name, vpfe_dev->current_subdev->name)) {
1046 if (vpfe_dev->current_input >= sdinfo->num_inputs)
1048 *app_input_index = j + vpfe_dev->current_input;
1051 j += sdinfo->num_inputs;
1056 static int vpfe_enum_input(struct file *file, void *priv,
1057 struct v4l2_input *inp)
1059 struct vpfe_device *vpfe_dev = video_drvdata(file);
1060 struct vpfe_subdev_info *sdinfo;
1063 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_enum_input\n");
1065 if (vpfe_get_subdev_input_index(vpfe_dev,
1069 v4l2_err(&vpfe_dev->v4l2_dev, "input information not found"
1070 " for the subdev\n");
1073 sdinfo = &vpfe_dev->cfg->sub_devs[subdev];
1074 memcpy(inp, &sdinfo->inputs[index], sizeof(struct v4l2_input));
1078 static int vpfe_g_input(struct file *file, void *priv, unsigned int *index)
1080 struct vpfe_device *vpfe_dev = video_drvdata(file);
1082 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_g_input\n");
1084 return vpfe_get_app_input_index(vpfe_dev, index);
1088 static int vpfe_s_input(struct file *file, void *priv, unsigned int index)
1090 struct vpfe_device *vpfe_dev = video_drvdata(file);
1091 struct vpfe_subdev_info *sdinfo;
1092 int subdev_index, inp_index;
1093 struct vpfe_route *route;
1094 u32 input = 0, output = 0;
1097 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_s_input\n");
1099 ret = mutex_lock_interruptible(&vpfe_dev->lock);
1104 * If streaming is started return device busy
1107 if (vpfe_dev->started) {
1108 v4l2_err(&vpfe_dev->v4l2_dev, "Streaming is on\n");
1113 if (vpfe_get_subdev_input_index(vpfe_dev,
1117 v4l2_err(&vpfe_dev->v4l2_dev, "invalid input index\n");
1121 sdinfo = &vpfe_dev->cfg->sub_devs[subdev_index];
1122 route = &sdinfo->routes[inp_index];
1123 if (route && sdinfo->can_route) {
1124 input = route->input;
1125 output = route->output;
1128 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id,
1129 video, s_routing, input, output, 0);
1132 v4l2_err(&vpfe_dev->v4l2_dev,
1133 "vpfe_doioctl:error in setting input in decoder\n");
1137 vpfe_dev->current_subdev = sdinfo;
1138 vpfe_dev->current_input = index;
1139 vpfe_dev->std_index = 0;
1141 /* set the bus/interface parameter for the sub device in ccdc */
1142 ret = ccdc_dev->hw_ops.set_hw_if_params(&sdinfo->ccdc_if_params);
1146 /* set the default image parameters in the device */
1147 ret = vpfe_config_image_format(vpfe_dev,
1148 &vpfe_standards[vpfe_dev->std_index].std_id);
1150 mutex_unlock(&vpfe_dev->lock);
1154 static int vpfe_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
1156 struct vpfe_device *vpfe_dev = video_drvdata(file);
1157 struct vpfe_subdev_info *sdinfo;
1160 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_querystd\n");
1162 ret = mutex_lock_interruptible(&vpfe_dev->lock);
1163 sdinfo = vpfe_dev->current_subdev;
1166 /* Call querystd function of decoder device */
1167 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id,
1168 video, querystd, std_id);
1169 mutex_unlock(&vpfe_dev->lock);
1173 static int vpfe_s_std(struct file *file, void *priv, v4l2_std_id *std_id)
1175 struct vpfe_device *vpfe_dev = video_drvdata(file);
1176 struct vpfe_subdev_info *sdinfo;
1179 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_s_std\n");
1181 /* Call decoder driver function to set the standard */
1182 ret = mutex_lock_interruptible(&vpfe_dev->lock);
1186 sdinfo = vpfe_dev->current_subdev;
1187 /* If streaming is started, return device busy error */
1188 if (vpfe_dev->started) {
1189 v4l2_err(&vpfe_dev->v4l2_dev, "streaming is started\n");
1194 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id,
1195 core, s_std, *std_id);
1197 v4l2_err(&vpfe_dev->v4l2_dev, "Failed to set standard\n");
1200 ret = vpfe_config_image_format(vpfe_dev, std_id);
1203 mutex_unlock(&vpfe_dev->lock);
1207 static int vpfe_g_std(struct file *file, void *priv, v4l2_std_id *std_id)
1209 struct vpfe_device *vpfe_dev = video_drvdata(file);
1211 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_g_std\n");
1213 *std_id = vpfe_standards[vpfe_dev->std_index].std_id;
1217 * Videobuf operations
1219 static int vpfe_videobuf_setup(struct videobuf_queue *vq,
1220 unsigned int *count,
1223 struct vpfe_fh *fh = vq->priv_data;
1224 struct vpfe_device *vpfe_dev = fh->vpfe_dev;
1226 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_buffer_setup\n");
1227 *size = config_params.device_bufsize;
1229 if (*count < config_params.min_numbuffers)
1230 *count = config_params.min_numbuffers;
1231 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev,
1232 "count=%d, size=%d\n", *count, *size);
1236 static int vpfe_videobuf_prepare(struct videobuf_queue *vq,
1237 struct videobuf_buffer *vb,
1238 enum v4l2_field field)
1240 struct vpfe_fh *fh = vq->priv_data;
1241 struct vpfe_device *vpfe_dev = fh->vpfe_dev;
1243 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_buffer_prepare\n");
1245 /* If buffer is not initialized, initialize it */
1246 if (VIDEOBUF_NEEDS_INIT == vb->state) {
1247 vb->width = vpfe_dev->fmt.fmt.pix.width;
1248 vb->height = vpfe_dev->fmt.fmt.pix.height;
1249 vb->size = vpfe_dev->fmt.fmt.pix.sizeimage;
1252 vb->state = VIDEOBUF_PREPARED;
1256 static void vpfe_videobuf_queue(struct videobuf_queue *vq,
1257 struct videobuf_buffer *vb)
1259 /* Get the file handle object and device object */
1260 struct vpfe_fh *fh = vq->priv_data;
1261 struct vpfe_device *vpfe_dev = fh->vpfe_dev;
1262 unsigned long flags;
1264 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_buffer_queue\n");
1266 /* add the buffer to the DMA queue */
1267 spin_lock_irqsave(&vpfe_dev->dma_queue_lock, flags);
1268 list_add_tail(&vb->queue, &vpfe_dev->dma_queue);
1269 spin_unlock_irqrestore(&vpfe_dev->dma_queue_lock, flags);
1271 /* Change state of the buffer */
1272 vb->state = VIDEOBUF_QUEUED;
1275 static void vpfe_videobuf_release(struct videobuf_queue *vq,
1276 struct videobuf_buffer *vb)
1278 struct vpfe_fh *fh = vq->priv_data;
1279 struct vpfe_device *vpfe_dev = fh->vpfe_dev;
1280 unsigned long flags;
1282 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_videobuf_release\n");
1285 * We need to flush the buffer from the dma queue since
1286 * they are de-allocated
1288 spin_lock_irqsave(&vpfe_dev->dma_queue_lock, flags);
1289 INIT_LIST_HEAD(&vpfe_dev->dma_queue);
1290 spin_unlock_irqrestore(&vpfe_dev->dma_queue_lock, flags);
1291 videobuf_dma_contig_free(vq, vb);
1292 vb->state = VIDEOBUF_NEEDS_INIT;
1295 static struct videobuf_queue_ops vpfe_videobuf_qops = {
1296 .buf_setup = vpfe_videobuf_setup,
1297 .buf_prepare = vpfe_videobuf_prepare,
1298 .buf_queue = vpfe_videobuf_queue,
1299 .buf_release = vpfe_videobuf_release,
1303 * vpfe_reqbufs. currently support REQBUF only once opening
1306 static int vpfe_reqbufs(struct file *file, void *priv,
1307 struct v4l2_requestbuffers *req_buf)
1309 struct vpfe_device *vpfe_dev = video_drvdata(file);
1310 struct vpfe_fh *fh = file->private_data;
1313 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_reqbufs\n");
1315 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != req_buf->type) {
1316 v4l2_err(&vpfe_dev->v4l2_dev, "Invalid buffer type\n");
1320 if (V4L2_MEMORY_USERPTR == req_buf->memory) {
1321 /* we don't support user ptr IO */
1322 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_reqbufs:"
1323 " USERPTR IO not supported\n");
1327 ret = mutex_lock_interruptible(&vpfe_dev->lock);
1331 if (vpfe_dev->io_usrs != 0) {
1332 v4l2_err(&vpfe_dev->v4l2_dev, "Only one IO user allowed\n");
1337 vpfe_dev->memory = req_buf->memory;
1338 videobuf_queue_dma_contig_init(&vpfe_dev->buffer_queue,
1339 &vpfe_videobuf_qops,
1343 vpfe_dev->fmt.fmt.pix.field,
1344 sizeof(struct videobuf_buffer),
1348 vpfe_dev->io_usrs = 1;
1349 INIT_LIST_HEAD(&vpfe_dev->dma_queue);
1350 ret = videobuf_reqbufs(&vpfe_dev->buffer_queue, req_buf);
1352 mutex_unlock(&vpfe_dev->lock);
1356 static int vpfe_querybuf(struct file *file, void *priv,
1357 struct v4l2_buffer *buf)
1359 struct vpfe_device *vpfe_dev = video_drvdata(file);
1361 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_querybuf\n");
1363 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != buf->type) {
1364 v4l2_err(&vpfe_dev->v4l2_dev, "Invalid buf type\n");
1368 if (vpfe_dev->memory != V4L2_MEMORY_MMAP) {
1369 v4l2_err(&vpfe_dev->v4l2_dev, "Invalid memory\n");
1372 /* Call videobuf_querybuf to get information */
1373 return videobuf_querybuf(&vpfe_dev->buffer_queue, buf);
1376 static int vpfe_qbuf(struct file *file, void *priv,
1377 struct v4l2_buffer *p)
1379 struct vpfe_device *vpfe_dev = video_drvdata(file);
1380 struct vpfe_fh *fh = file->private_data;
1382 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_qbuf\n");
1384 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != p->type) {
1385 v4l2_err(&vpfe_dev->v4l2_dev, "Invalid buf type\n");
1390 * If this file handle is not allowed to do IO,
1393 if (!fh->io_allowed) {
1394 v4l2_err(&vpfe_dev->v4l2_dev, "fh->io_allowed\n");
1397 return videobuf_qbuf(&vpfe_dev->buffer_queue, p);
1400 static int vpfe_dqbuf(struct file *file, void *priv,
1401 struct v4l2_buffer *buf)
1403 struct vpfe_device *vpfe_dev = video_drvdata(file);
1405 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_dqbuf\n");
1407 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != buf->type) {
1408 v4l2_err(&vpfe_dev->v4l2_dev, "Invalid buf type\n");
1411 return videobuf_dqbuf(&vpfe_dev->buffer_queue,
1412 buf, file->f_flags & O_NONBLOCK);
1415 static int vpfe_queryctrl(struct file *file, void *priv,
1416 struct v4l2_queryctrl *qctrl)
1418 struct vpfe_device *vpfe_dev = video_drvdata(file);
1419 struct vpfe_subdev_info *sdinfo;
1421 sdinfo = vpfe_dev->current_subdev;
1423 return v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id,
1424 core, queryctrl, qctrl);
1428 static int vpfe_g_ctrl(struct file *file, void *priv, struct v4l2_control *ctrl)
1430 struct vpfe_device *vpfe_dev = video_drvdata(file);
1431 struct vpfe_subdev_info *sdinfo;
1433 sdinfo = vpfe_dev->current_subdev;
1435 return v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id,
1436 core, g_ctrl, ctrl);
1439 static int vpfe_s_ctrl(struct file *file, void *priv, struct v4l2_control *ctrl)
1441 struct vpfe_device *vpfe_dev = video_drvdata(file);
1442 struct vpfe_subdev_info *sdinfo;
1444 sdinfo = vpfe_dev->current_subdev;
1446 return v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id,
1447 core, s_ctrl, ctrl);
1451 * vpfe_calculate_offsets : This function calculates buffers offset
1452 * for top and bottom field
1454 static void vpfe_calculate_offsets(struct vpfe_device *vpfe_dev)
1456 struct v4l2_rect image_win;
1458 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_calculate_offsets\n");
1460 ccdc_dev->hw_ops.get_image_window(&image_win);
1461 vpfe_dev->field_off = image_win.height * image_win.width;
1464 /* vpfe_start_ccdc_capture: start streaming in ccdc/isif */
1465 static void vpfe_start_ccdc_capture(struct vpfe_device *vpfe_dev)
1467 ccdc_dev->hw_ops.enable(1);
1468 if (ccdc_dev->hw_ops.enable_out_to_sdram)
1469 ccdc_dev->hw_ops.enable_out_to_sdram(1);
1470 vpfe_dev->started = 1;
1474 * vpfe_streamon. Assume the DMA queue is not empty.
1475 * application is expected to call QBUF before calling
1476 * this ioctl. If not, driver returns error
1478 static int vpfe_streamon(struct file *file, void *priv,
1479 enum v4l2_buf_type buf_type)
1481 struct vpfe_device *vpfe_dev = video_drvdata(file);
1482 struct vpfe_fh *fh = file->private_data;
1483 struct vpfe_subdev_info *sdinfo;
1487 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_streamon\n");
1489 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != buf_type) {
1490 v4l2_err(&vpfe_dev->v4l2_dev, "Invalid buf type\n");
1494 /* If file handle is not allowed IO, return error */
1495 if (!fh->io_allowed) {
1496 v4l2_err(&vpfe_dev->v4l2_dev, "fh->io_allowed\n");
1500 sdinfo = vpfe_dev->current_subdev;
1501 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id,
1502 video, s_stream, 1);
1504 if (ret && (ret != -ENOIOCTLCMD)) {
1505 v4l2_err(&vpfe_dev->v4l2_dev, "stream on failed in subdev\n");
1509 /* If buffer queue is empty, return error */
1510 if (list_empty(&vpfe_dev->buffer_queue.stream)) {
1511 v4l2_err(&vpfe_dev->v4l2_dev, "buffer queue is empty\n");
1515 /* Call videobuf_streamon to start streaming * in videobuf */
1516 ret = videobuf_streamon(&vpfe_dev->buffer_queue);
1521 ret = mutex_lock_interruptible(&vpfe_dev->lock);
1524 /* Get the next frame from the buffer queue */
1525 vpfe_dev->next_frm = list_entry(vpfe_dev->dma_queue.next,
1526 struct videobuf_buffer, queue);
1527 vpfe_dev->cur_frm = vpfe_dev->next_frm;
1528 /* Remove buffer from the buffer queue */
1529 list_del(&vpfe_dev->cur_frm->queue);
1530 /* Mark state of the current frame to active */
1531 vpfe_dev->cur_frm->state = VIDEOBUF_ACTIVE;
1532 /* Initialize field_id and started member */
1533 vpfe_dev->field_id = 0;
1534 addr = videobuf_to_dma_contig(vpfe_dev->cur_frm);
1536 /* Calculate field offset */
1537 vpfe_calculate_offsets(vpfe_dev);
1539 if (vpfe_attach_irq(vpfe_dev) < 0) {
1540 v4l2_err(&vpfe_dev->v4l2_dev,
1541 "Error in attaching interrupt handle\n");
1545 if (ccdc_dev->hw_ops.configure() < 0) {
1546 v4l2_err(&vpfe_dev->v4l2_dev,
1547 "Error in configuring ccdc\n");
1551 ccdc_dev->hw_ops.setfbaddr((unsigned long)(addr));
1552 vpfe_start_ccdc_capture(vpfe_dev);
1553 mutex_unlock(&vpfe_dev->lock);
1556 mutex_unlock(&vpfe_dev->lock);
1558 ret = videobuf_streamoff(&vpfe_dev->buffer_queue);
1562 static int vpfe_streamoff(struct file *file, void *priv,
1563 enum v4l2_buf_type buf_type)
1565 struct vpfe_device *vpfe_dev = video_drvdata(file);
1566 struct vpfe_fh *fh = file->private_data;
1567 struct vpfe_subdev_info *sdinfo;
1570 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_streamoff\n");
1572 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != buf_type) {
1573 v4l2_err(&vpfe_dev->v4l2_dev, "Invalid buf type\n");
1577 /* If io is allowed for this file handle, return error */
1578 if (!fh->io_allowed) {
1579 v4l2_err(&vpfe_dev->v4l2_dev, "fh->io_allowed\n");
1583 /* If streaming is not started, return error */
1584 if (!vpfe_dev->started) {
1585 v4l2_err(&vpfe_dev->v4l2_dev, "device started\n");
1589 ret = mutex_lock_interruptible(&vpfe_dev->lock);
1593 vpfe_stop_ccdc_capture(vpfe_dev);
1594 vpfe_detach_irq(vpfe_dev);
1596 sdinfo = vpfe_dev->current_subdev;
1597 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id,
1598 video, s_stream, 0);
1600 if (ret && (ret != -ENOIOCTLCMD))
1601 v4l2_err(&vpfe_dev->v4l2_dev, "stream off failed in subdev\n");
1602 ret = videobuf_streamoff(&vpfe_dev->buffer_queue);
1603 mutex_unlock(&vpfe_dev->lock);
1607 static int vpfe_cropcap(struct file *file, void *priv,
1608 struct v4l2_cropcap *crop)
1610 struct vpfe_device *vpfe_dev = video_drvdata(file);
1612 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_cropcap\n");
1614 if (vpfe_dev->std_index >= ARRAY_SIZE(vpfe_standards))
1617 memset(crop, 0, sizeof(struct v4l2_cropcap));
1618 crop->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1619 crop->bounds.width = crop->defrect.width =
1620 vpfe_standards[vpfe_dev->std_index].width;
1621 crop->bounds.height = crop->defrect.height =
1622 vpfe_standards[vpfe_dev->std_index].height;
1623 crop->pixelaspect = vpfe_standards[vpfe_dev->std_index].pixelaspect;
1627 static int vpfe_g_crop(struct file *file, void *priv,
1628 struct v4l2_crop *crop)
1630 struct vpfe_device *vpfe_dev = video_drvdata(file);
1632 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_g_crop\n");
1634 crop->c = vpfe_dev->crop;
1638 static int vpfe_s_crop(struct file *file, void *priv,
1639 struct v4l2_crop *crop)
1641 struct vpfe_device *vpfe_dev = video_drvdata(file);
1644 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_s_crop\n");
1646 if (vpfe_dev->started) {
1647 /* make sure streaming is not started */
1648 v4l2_err(&vpfe_dev->v4l2_dev,
1649 "Cannot change crop when streaming is ON\n");
1653 ret = mutex_lock_interruptible(&vpfe_dev->lock);
1657 if (crop->c.top < 0 || crop->c.left < 0) {
1658 v4l2_err(&vpfe_dev->v4l2_dev,
1659 "doesn't support negative values for top & left\n");
1664 /* adjust the width to 16 pixel boundry */
1665 crop->c.width = ((crop->c.width + 15) & ~0xf);
1667 /* make sure parameters are valid */
1668 if ((crop->c.left + crop->c.width >
1669 vpfe_dev->std_info.active_pixels) ||
1670 (crop->c.top + crop->c.height >
1671 vpfe_dev->std_info.active_lines)) {
1672 v4l2_err(&vpfe_dev->v4l2_dev, "Error in S_CROP params\n");
1676 ccdc_dev->hw_ops.set_image_window(&crop->c);
1677 vpfe_dev->fmt.fmt.pix.width = crop->c.width;
1678 vpfe_dev->fmt.fmt.pix.height = crop->c.height;
1679 vpfe_dev->fmt.fmt.pix.bytesperline =
1680 ccdc_dev->hw_ops.get_line_length();
1681 vpfe_dev->fmt.fmt.pix.sizeimage =
1682 vpfe_dev->fmt.fmt.pix.bytesperline *
1683 vpfe_dev->fmt.fmt.pix.height;
1684 vpfe_dev->crop = crop->c;
1686 mutex_unlock(&vpfe_dev->lock);
1691 static long vpfe_param_handler(struct file *file, void *priv,
1692 int cmd, void *param)
1694 struct vpfe_device *vpfe_dev = video_drvdata(file);
1697 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_param_handler\n");
1699 if (vpfe_dev->started) {
1700 /* only allowed if streaming is not started */
1701 v4l2_err(&vpfe_dev->v4l2_dev, "device already started\n");
1705 ret = mutex_lock_interruptible(&vpfe_dev->lock);
1710 case VPFE_CMD_S_CCDC_RAW_PARAMS:
1711 v4l2_warn(&vpfe_dev->v4l2_dev,
1712 "VPFE_CMD_S_CCDC_RAW_PARAMS: experimental ioctl\n");
1713 ret = ccdc_dev->hw_ops.set_params(param);
1715 v4l2_err(&vpfe_dev->v4l2_dev,
1716 "Error in setting parameters in CCDC\n");
1719 if (vpfe_get_ccdc_image_format(vpfe_dev, &vpfe_dev->fmt) < 0) {
1720 v4l2_err(&vpfe_dev->v4l2_dev,
1721 "Invalid image format at CCDC\n");
1729 mutex_unlock(&vpfe_dev->lock);
1734 /* vpfe capture ioctl operations */
1735 static const struct v4l2_ioctl_ops vpfe_ioctl_ops = {
1736 .vidioc_querycap = vpfe_querycap,
1737 .vidioc_g_fmt_vid_cap = vpfe_g_fmt_vid_cap,
1738 .vidioc_enum_fmt_vid_cap = vpfe_enum_fmt_vid_cap,
1739 .vidioc_s_fmt_vid_cap = vpfe_s_fmt_vid_cap,
1740 .vidioc_try_fmt_vid_cap = vpfe_try_fmt_vid_cap,
1741 .vidioc_enum_input = vpfe_enum_input,
1742 .vidioc_g_input = vpfe_g_input,
1743 .vidioc_s_input = vpfe_s_input,
1744 .vidioc_querystd = vpfe_querystd,
1745 .vidioc_s_std = vpfe_s_std,
1746 .vidioc_g_std = vpfe_g_std,
1747 .vidioc_queryctrl = vpfe_queryctrl,
1748 .vidioc_g_ctrl = vpfe_g_ctrl,
1749 .vidioc_s_ctrl = vpfe_s_ctrl,
1750 .vidioc_reqbufs = vpfe_reqbufs,
1751 .vidioc_querybuf = vpfe_querybuf,
1752 .vidioc_qbuf = vpfe_qbuf,
1753 .vidioc_dqbuf = vpfe_dqbuf,
1754 .vidioc_streamon = vpfe_streamon,
1755 .vidioc_streamoff = vpfe_streamoff,
1756 .vidioc_cropcap = vpfe_cropcap,
1757 .vidioc_g_crop = vpfe_g_crop,
1758 .vidioc_s_crop = vpfe_s_crop,
1759 .vidioc_default = vpfe_param_handler,
1762 static struct vpfe_device *vpfe_initialize(void)
1764 struct vpfe_device *vpfe_dev;
1766 /* Default number of buffers should be 3 */
1767 if ((numbuffers > 0) &&
1768 (numbuffers < config_params.min_numbuffers))
1769 numbuffers = config_params.min_numbuffers;
1772 * Set buffer size to min buffers size if invalid buffer size is
1775 if (bufsize < config_params.min_bufsize)
1776 bufsize = config_params.min_bufsize;
1778 config_params.numbuffers = numbuffers;
1781 config_params.device_bufsize = bufsize;
1783 /* Allocate memory for device objects */
1784 vpfe_dev = kzalloc(sizeof(*vpfe_dev), GFP_KERNEL);
1789 static void vpfe_disable_clock(struct vpfe_device *vpfe_dev)
1791 struct vpfe_config *vpfe_cfg = vpfe_dev->cfg;
1793 clk_disable(vpfe_cfg->vpssclk);
1794 clk_put(vpfe_cfg->vpssclk);
1795 clk_disable(vpfe_cfg->slaveclk);
1796 clk_put(vpfe_cfg->slaveclk);
1797 v4l2_info(vpfe_dev->pdev->driver,
1798 "vpfe vpss master & slave clocks disabled\n");
1801 static int vpfe_enable_clock(struct vpfe_device *vpfe_dev)
1803 struct vpfe_config *vpfe_cfg = vpfe_dev->cfg;
1806 vpfe_cfg->vpssclk = clk_get(vpfe_dev->pdev, "vpss_master");
1807 if (NULL == vpfe_cfg->vpssclk) {
1808 v4l2_err(vpfe_dev->pdev->driver, "No clock defined for"
1813 if (clk_enable(vpfe_cfg->vpssclk)) {
1814 v4l2_err(vpfe_dev->pdev->driver,
1815 "vpfe vpss master clock not enabled\n");
1818 v4l2_info(vpfe_dev->pdev->driver,
1819 "vpfe vpss master clock enabled\n");
1821 vpfe_cfg->slaveclk = clk_get(vpfe_dev->pdev, "vpss_slave");
1822 if (NULL == vpfe_cfg->slaveclk) {
1823 v4l2_err(vpfe_dev->pdev->driver,
1824 "No clock defined for vpss slave\n");
1828 if (clk_enable(vpfe_cfg->slaveclk)) {
1829 v4l2_err(vpfe_dev->pdev->driver,
1830 "vpfe vpss slave clock not enabled\n");
1833 v4l2_info(vpfe_dev->pdev->driver, "vpfe vpss slave clock enabled\n");
1836 if (vpfe_cfg->vpssclk)
1837 clk_put(vpfe_cfg->vpssclk);
1838 if (vpfe_cfg->slaveclk)
1839 clk_put(vpfe_cfg->slaveclk);
1845 * vpfe_probe : This function creates device entries by register
1846 * itself to the V4L2 driver and initializes fields of each
1849 static __init int vpfe_probe(struct platform_device *pdev)
1851 struct vpfe_subdev_info *sdinfo;
1852 struct vpfe_config *vpfe_cfg;
1853 struct resource *res1;
1854 struct vpfe_device *vpfe_dev;
1855 struct i2c_adapter *i2c_adap;
1856 struct video_device *vfd;
1857 int ret = -ENOMEM, i, j;
1858 int num_subdevs = 0;
1860 /* Get the pointer to the device object */
1861 vpfe_dev = vpfe_initialize();
1864 v4l2_err(pdev->dev.driver,
1865 "Failed to allocate memory for vpfe_dev\n");
1869 vpfe_dev->pdev = &pdev->dev;
1871 if (NULL == pdev->dev.platform_data) {
1872 v4l2_err(pdev->dev.driver, "Unable to get vpfe config\n");
1874 goto probe_free_dev_mem;
1877 vpfe_cfg = pdev->dev.platform_data;
1878 vpfe_dev->cfg = vpfe_cfg;
1879 if (NULL == vpfe_cfg->ccdc ||
1880 NULL == vpfe_cfg->card_name ||
1881 NULL == vpfe_cfg->sub_devs) {
1882 v4l2_err(pdev->dev.driver, "null ptr in vpfe_cfg\n");
1884 goto probe_free_dev_mem;
1887 /* enable vpss clocks */
1888 ret = vpfe_enable_clock(vpfe_dev);
1890 goto probe_free_dev_mem;
1892 mutex_lock(&ccdc_lock);
1893 /* Allocate memory for ccdc configuration */
1894 ccdc_cfg = kmalloc(sizeof(struct ccdc_config), GFP_KERNEL);
1895 if (NULL == ccdc_cfg) {
1896 v4l2_err(pdev->dev.driver,
1897 "Memory allocation failed for ccdc_cfg\n");
1898 goto probe_disable_clock;
1901 strncpy(ccdc_cfg->name, vpfe_cfg->ccdc, 32);
1902 /* Get VINT0 irq resource */
1903 res1 = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1905 v4l2_err(pdev->dev.driver,
1906 "Unable to get interrupt for VINT0\n");
1908 goto probe_disable_clock;
1910 vpfe_dev->ccdc_irq0 = res1->start;
1912 /* Get VINT1 irq resource */
1913 res1 = platform_get_resource(pdev,
1916 v4l2_err(pdev->dev.driver,
1917 "Unable to get interrupt for VINT1\n");
1919 goto probe_disable_clock;
1921 vpfe_dev->ccdc_irq1 = res1->start;
1923 /* Get address base of CCDC */
1924 res1 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1926 v4l2_err(pdev->dev.driver,
1927 "Unable to get register address map\n");
1929 goto probe_disable_clock;
1932 ccdc_cfg->ccdc_addr_size = res1->end - res1->start + 1;
1933 if (!request_mem_region(res1->start, ccdc_cfg->ccdc_addr_size,
1934 pdev->dev.driver->name)) {
1935 v4l2_err(pdev->dev.driver,
1936 "Failed request_mem_region for ccdc base\n");
1938 goto probe_disable_clock;
1940 ccdc_cfg->ccdc_addr = ioremap_nocache(res1->start,
1941 ccdc_cfg->ccdc_addr_size);
1942 if (!ccdc_cfg->ccdc_addr) {
1943 v4l2_err(pdev->dev.driver, "Unable to ioremap ccdc addr\n");
1945 goto probe_out_release_mem1;
1948 ret = request_irq(vpfe_dev->ccdc_irq0, vpfe_isr, IRQF_DISABLED,
1949 "vpfe_capture0", vpfe_dev);
1952 v4l2_err(pdev->dev.driver, "Unable to request interrupt\n");
1953 goto probe_out_unmap1;
1956 /* Allocate memory for video device */
1957 vfd = video_device_alloc();
1960 v4l2_err(pdev->dev.driver,
1961 "Unable to alloc video device\n");
1962 goto probe_out_release_irq;
1965 /* Initialize field of video device */
1966 vfd->release = video_device_release;
1967 vfd->fops = &vpfe_fops;
1968 vfd->ioctl_ops = &vpfe_ioctl_ops;
1970 vfd->current_norm = V4L2_STD_PAL;
1971 vfd->v4l2_dev = &vpfe_dev->v4l2_dev;
1972 snprintf(vfd->name, sizeof(vfd->name),
1975 (VPFE_CAPTURE_VERSION_CODE >> 16) & 0xff,
1976 (VPFE_CAPTURE_VERSION_CODE >> 8) & 0xff,
1977 (VPFE_CAPTURE_VERSION_CODE) & 0xff);
1978 /* Set video_dev to the video device */
1979 vpfe_dev->video_dev = vfd;
1981 ret = v4l2_device_register(&pdev->dev, &vpfe_dev->v4l2_dev);
1983 v4l2_err(pdev->dev.driver,
1984 "Unable to register v4l2 device.\n");
1985 goto probe_out_video_release;
1987 v4l2_info(&vpfe_dev->v4l2_dev, "v4l2 device registered\n");
1988 spin_lock_init(&vpfe_dev->irqlock);
1989 spin_lock_init(&vpfe_dev->dma_queue_lock);
1990 mutex_init(&vpfe_dev->lock);
1992 /* Initialize field of the device objects */
1993 vpfe_dev->numbuffers = config_params.numbuffers;
1995 /* Initialize prio member of device object */
1996 v4l2_prio_init(&vpfe_dev->prio);
1997 /* register video device */
1998 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev,
1999 "trying to register vpfe device.\n");
2000 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev,
2001 "video_dev=%x\n", (int)&vpfe_dev->video_dev);
2002 vpfe_dev->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2003 ret = video_register_device(vpfe_dev->video_dev,
2004 VFL_TYPE_GRABBER, -1);
2007 v4l2_err(pdev->dev.driver,
2008 "Unable to register video device.\n");
2009 goto probe_out_v4l2_unregister;
2012 v4l2_info(&vpfe_dev->v4l2_dev, "video device registered\n");
2013 /* set the driver data in platform device */
2014 platform_set_drvdata(pdev, vpfe_dev);
2015 /* set driver private data */
2016 video_set_drvdata(vpfe_dev->video_dev, vpfe_dev);
2017 i2c_adap = i2c_get_adapter(vpfe_cfg->i2c_adapter_id);
2018 num_subdevs = vpfe_cfg->num_subdevs;
2019 vpfe_dev->sd = kmalloc(sizeof(struct v4l2_subdev *) * num_subdevs,
2021 if (NULL == vpfe_dev->sd) {
2022 v4l2_err(&vpfe_dev->v4l2_dev,
2023 "unable to allocate memory for subdevice pointers\n");
2025 goto probe_out_video_unregister;
2028 for (i = 0; i < num_subdevs; i++) {
2029 struct v4l2_input *inps;
2031 sdinfo = &vpfe_cfg->sub_devs[i];
2033 /* Load up the subdevice */
2035 v4l2_i2c_new_subdev_board(&vpfe_dev->v4l2_dev,
2038 &sdinfo->board_info,
2040 if (vpfe_dev->sd[i]) {
2041 v4l2_info(&vpfe_dev->v4l2_dev,
2042 "v4l2 sub device %s registered\n",
2044 vpfe_dev->sd[i]->grp_id = sdinfo->grp_id;
2045 /* update tvnorms from the sub devices */
2046 for (j = 0; j < sdinfo->num_inputs; j++) {
2047 inps = &sdinfo->inputs[j];
2048 vfd->tvnorms |= inps->std;
2051 v4l2_info(&vpfe_dev->v4l2_dev,
2052 "v4l2 sub device %s register fails\n",
2058 /* set first sub device as current one */
2059 vpfe_dev->current_subdev = &vpfe_cfg->sub_devs[0];
2061 /* We have at least one sub device to work with */
2062 mutex_unlock(&ccdc_lock);
2066 kfree(vpfe_dev->sd);
2067 probe_out_video_unregister:
2068 video_unregister_device(vpfe_dev->video_dev);
2069 probe_out_v4l2_unregister:
2070 v4l2_device_unregister(&vpfe_dev->v4l2_dev);
2071 probe_out_video_release:
2072 if (!video_is_registered(vpfe_dev->video_dev))
2073 video_device_release(vpfe_dev->video_dev);
2074 probe_out_release_irq:
2075 free_irq(vpfe_dev->ccdc_irq0, vpfe_dev);
2077 iounmap(ccdc_cfg->ccdc_addr);
2078 probe_out_release_mem1:
2079 release_mem_region(res1->start, res1->end - res1->start + 1);
2080 probe_disable_clock:
2081 vpfe_disable_clock(vpfe_dev);
2082 mutex_unlock(&ccdc_lock);
2090 * vpfe_remove : It un-register device from V4L2 driver
2092 static int __devexit vpfe_remove(struct platform_device *pdev)
2094 struct vpfe_device *vpfe_dev = platform_get_drvdata(pdev);
2095 struct resource *res;
2097 v4l2_info(pdev->dev.driver, "vpfe_remove\n");
2099 free_irq(vpfe_dev->ccdc_irq0, vpfe_dev);
2100 kfree(vpfe_dev->sd);
2101 v4l2_device_unregister(&vpfe_dev->v4l2_dev);
2102 video_unregister_device(vpfe_dev->video_dev);
2103 mutex_lock(&ccdc_lock);
2104 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2105 release_mem_region(res->start, res->end - res->start + 1);
2106 iounmap(ccdc_cfg->ccdc_addr);
2107 mutex_unlock(&ccdc_lock);
2108 vpfe_disable_clock(vpfe_dev);
2115 vpfe_suspend(struct device *dev)
2117 /* add suspend code here later */
2122 vpfe_resume(struct device *dev)
2124 /* add resume code here later */
2128 static const struct dev_pm_ops vpfe_dev_pm_ops = {
2129 .suspend = vpfe_suspend,
2130 .resume = vpfe_resume,
2133 static struct platform_driver vpfe_driver = {
2135 .name = CAPTURE_DRV_NAME,
2136 .owner = THIS_MODULE,
2137 .pm = &vpfe_dev_pm_ops,
2139 .probe = vpfe_probe,
2140 .remove = __devexit_p(vpfe_remove),
2143 static __init int vpfe_init(void)
2145 printk(KERN_NOTICE "vpfe_init\n");
2146 /* Register driver to the kernel */
2147 return platform_driver_register(&vpfe_driver);
2151 * vpfe_cleanup : This function un-registers device driver
2153 static void vpfe_cleanup(void)
2155 platform_driver_unregister(&vpfe_driver);
2158 module_init(vpfe_init);
2159 module_exit(vpfe_cleanup);