2 * camera image capture (abstract) bus driver
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This driver provides an interface between platform-specific camera
7 * busses and camera devices. It should be used if the camera is
8 * connected not over a "proper" bus like PCI or USB, but over a
9 * special bus, like, for example, the Quick Capture interface on PXA270
10 * SoCs. Later it should also be used for i.MX31 SoCs from Freescale.
11 * It can handle multiple cameras and / or multiple busses, which can
12 * be used, e.g., in stereo-vision applications.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/device.h>
22 #include <linux/list.h>
23 #include <linux/err.h>
24 #include <linux/mutex.h>
25 #include <linux/vmalloc.h>
27 #include <media/v4l2-common.h>
28 #include <media/v4l2-dev.h>
29 #include <media/soc_camera.h>
31 static LIST_HEAD(hosts);
32 static LIST_HEAD(devices);
33 static DEFINE_MUTEX(list_lock);
34 static DEFINE_MUTEX(video_lock);
36 const static struct soc_camera_data_format*
37 format_by_fourcc(struct soc_camera_device *icd, unsigned int fourcc)
41 for (i = 0; i < icd->ops->num_formats; i++)
42 if (icd->ops->formats[i].fourcc == fourcc)
43 return icd->ops->formats + i;
47 static int soc_camera_try_fmt_cap(struct file *file, void *priv,
48 struct v4l2_format *f)
50 struct soc_camera_file *icf = file->private_data;
51 struct soc_camera_device *icd = icf->icd;
52 struct soc_camera_host *ici =
53 to_soc_camera_host(icd->dev.parent);
54 enum v4l2_field field;
55 const struct soc_camera_data_format *fmt;
58 WARN_ON(priv != file->private_data);
60 fmt = format_by_fourcc(icd, f->fmt.pix.pixelformat);
62 dev_dbg(&icd->dev, "invalid format 0x%08x\n",
63 f->fmt.pix.pixelformat);
67 dev_dbg(&icd->dev, "fmt: 0x%08x\n", fmt->fourcc);
69 field = f->fmt.pix.field;
71 if (field == V4L2_FIELD_ANY) {
72 field = V4L2_FIELD_NONE;
73 } else if (V4L2_FIELD_NONE != field) {
74 dev_err(&icd->dev, "Field type invalid.\n");
78 /* limit to host capabilities */
79 ret = ici->try_fmt_cap(ici, f);
81 /* limit to sensor capabilities */
83 ret = icd->ops->try_fmt_cap(icd, f);
85 /* calculate missing fields */
86 f->fmt.pix.field = field;
87 f->fmt.pix.bytesperline =
88 (f->fmt.pix.width * fmt->depth) >> 3;
89 f->fmt.pix.sizeimage =
90 f->fmt.pix.height * f->fmt.pix.bytesperline;
95 static int soc_camera_enum_input(struct file *file, void *priv,
96 struct v4l2_input *inp)
101 inp->type = V4L2_INPUT_TYPE_CAMERA;
102 inp->std = V4L2_STD_UNKNOWN;
103 strcpy(inp->name, "Camera");
108 static int soc_camera_g_input(struct file *file, void *priv, unsigned int *i)
115 static int soc_camera_s_input(struct file *file, void *priv, unsigned int i)
123 static int soc_camera_s_std(struct file *file, void *priv, v4l2_std_id *a)
128 static int soc_camera_reqbufs(struct file *file, void *priv,
129 struct v4l2_requestbuffers *p)
132 struct soc_camera_file *icf = file->private_data;
133 struct soc_camera_device *icd = icf->icd;
134 struct soc_camera_host *ici =
135 to_soc_camera_host(icd->dev.parent);
137 WARN_ON(priv != file->private_data);
139 dev_dbg(&icd->dev, "%s: %d\n", __FUNCTION__, p->memory);
141 ret = videobuf_reqbufs(&icf->vb_vidq, p);
145 return ici->reqbufs(icf, p);
150 static int soc_camera_querybuf(struct file *file, void *priv,
151 struct v4l2_buffer *p)
153 struct soc_camera_file *icf = file->private_data;
155 WARN_ON(priv != file->private_data);
157 return videobuf_querybuf(&icf->vb_vidq, p);
160 static int soc_camera_qbuf(struct file *file, void *priv,
161 struct v4l2_buffer *p)
163 struct soc_camera_file *icf = file->private_data;
165 WARN_ON(priv != file->private_data);
167 return videobuf_qbuf(&icf->vb_vidq, p);
170 static int soc_camera_dqbuf(struct file *file, void *priv,
171 struct v4l2_buffer *p)
173 struct soc_camera_file *icf = file->private_data;
175 WARN_ON(priv != file->private_data);
177 return videobuf_dqbuf(&icf->vb_vidq, p, file->f_flags & O_NONBLOCK);
180 static int soc_camera_open(struct inode *inode, struct file *file)
182 struct video_device *vdev;
183 struct soc_camera_device *icd;
184 struct soc_camera_host *ici;
185 struct soc_camera_file *icf;
188 icf = vmalloc(sizeof(*icf));
192 /* Protect against icd->remove() until we module_get() both drivers. */
193 mutex_lock(&video_lock);
195 vdev = video_devdata(file);
196 icd = container_of(vdev->dev, struct soc_camera_device, dev);
197 ici = to_soc_camera_host(icd->dev.parent);
199 if (!try_module_get(icd->ops->owner)) {
200 dev_err(&icd->dev, "Couldn't lock sensor driver.\n");
205 if (!try_module_get(ici->owner)) {
206 dev_err(&icd->dev, "Couldn't lock capture bus driver.\n");
215 /* Now we really have to activate the camera */
216 if (icd->use_count == 1) {
219 dev_err(&icd->dev, "Couldn't activate the camera: %d\n", ret);
225 mutex_unlock(&video_lock);
227 file->private_data = icf;
228 dev_dbg(&icd->dev, "camera device open\n");
230 /* We must pass NULL as dev pointer, then all pci_* dma operations
231 * transform to normal dma_* ones. Do we need an irqlock? */
232 videobuf_queue_sg_init(&icf->vb_vidq, ici->vbq_ops, NULL, NULL,
233 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
238 /* All errors are entered with the video_lock held */
240 module_put(ici->owner);
242 module_put(icd->ops->owner);
244 mutex_unlock(&video_lock);
249 static int soc_camera_close(struct inode *inode, struct file *file)
251 struct soc_camera_file *icf = file->private_data;
252 struct soc_camera_device *icd = icf->icd;
253 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
254 struct video_device *vdev = icd->vdev;
256 mutex_lock(&video_lock);
260 module_put(icd->ops->owner);
261 module_put(ici->owner);
262 mutex_unlock(&video_lock);
264 vfree(file->private_data);
266 dev_dbg(vdev->dev, "camera device close\n");
271 static int soc_camera_read(struct file *file, char __user *buf,
272 size_t count, loff_t *ppos)
274 struct soc_camera_file *icf = file->private_data;
275 struct soc_camera_device *icd = icf->icd;
276 struct video_device *vdev = icd->vdev;
279 dev_err(vdev->dev, "camera device read not implemented\n");
284 static int soc_camera_mmap(struct file *file, struct vm_area_struct *vma)
286 struct soc_camera_file *icf = file->private_data;
287 struct soc_camera_device *icd = icf->icd;
290 dev_dbg(&icd->dev, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
292 err = videobuf_mmap_mapper(&icf->vb_vidq, vma);
294 dev_dbg(&icd->dev, "vma start=0x%08lx, size=%ld, ret=%d\n",
295 (unsigned long)vma->vm_start,
296 (unsigned long)vma->vm_end - (unsigned long)vma->vm_start,
302 static unsigned int soc_camera_poll(struct file *file, poll_table *pt)
304 struct soc_camera_file *icf = file->private_data;
305 struct soc_camera_device *icd = icf->icd;
306 struct soc_camera_host *ici =
307 to_soc_camera_host(icd->dev.parent);
309 if (list_empty(&icf->vb_vidq.stream)) {
310 dev_err(&icd->dev, "Trying to poll with no queued buffers!\n");
314 return ici->poll(file, pt);
318 static struct file_operations soc_camera_fops = {
319 .owner = THIS_MODULE,
320 .open = soc_camera_open,
321 .release = soc_camera_close,
322 .ioctl = video_ioctl2,
323 .read = soc_camera_read,
324 .mmap = soc_camera_mmap,
325 .poll = soc_camera_poll,
330 static int soc_camera_s_fmt_cap(struct file *file, void *priv,
331 struct v4l2_format *f)
333 struct soc_camera_file *icf = file->private_data;
334 struct soc_camera_device *icd = icf->icd;
335 struct soc_camera_host *ici =
336 to_soc_camera_host(icd->dev.parent);
338 struct v4l2_rect rect;
339 const static struct soc_camera_data_format *data_fmt;
341 WARN_ON(priv != file->private_data);
343 data_fmt = format_by_fourcc(icd, f->fmt.pix.pixelformat);
347 /* cached_datawidth may be further adjusted by the ici */
348 icd->cached_datawidth = data_fmt->depth;
350 ret = soc_camera_try_fmt_cap(file, icf, f);
354 rect.left = icd->x_current;
355 rect.top = icd->y_current;
356 rect.width = f->fmt.pix.width;
357 rect.height = f->fmt.pix.height;
358 ret = ici->set_capture_format(icd, f->fmt.pix.pixelformat, &rect);
361 icd->current_fmt = data_fmt;
362 icd->width = rect.width;
363 icd->height = rect.height;
364 icf->vb_vidq.field = f->fmt.pix.field;
365 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != f->type)
366 dev_warn(&icd->dev, "Attention! Wrong buf-type %d\n",
369 dev_dbg(&icd->dev, "set width: %d height: %d\n",
370 icd->width, icd->height);
376 static int soc_camera_enum_fmt_cap(struct file *file, void *priv,
377 struct v4l2_fmtdesc *f)
379 struct soc_camera_file *icf = file->private_data;
380 struct soc_camera_device *icd = icf->icd;
381 const struct soc_camera_data_format *format;
383 WARN_ON(priv != file->private_data);
385 if (f->index >= icd->ops->num_formats)
388 format = &icd->ops->formats[f->index];
390 strlcpy(f->description, format->name, sizeof(f->description));
391 f->pixelformat = format->fourcc;
395 static int soc_camera_g_fmt_cap(struct file *file, void *priv,
396 struct v4l2_format *f)
398 struct soc_camera_file *icf = file->private_data;
399 struct soc_camera_device *icd = icf->icd;
401 WARN_ON(priv != file->private_data);
403 f->fmt.pix.width = icd->width;
404 f->fmt.pix.height = icd->height;
405 f->fmt.pix.field = icf->vb_vidq.field;
406 f->fmt.pix.pixelformat = icd->current_fmt->fourcc;
407 f->fmt.pix.bytesperline =
408 (f->fmt.pix.width * icd->current_fmt->depth) >> 3;
409 f->fmt.pix.sizeimage =
410 f->fmt.pix.height * f->fmt.pix.bytesperline;
411 dev_dbg(&icd->dev, "current_fmt->fourcc: 0x%08x\n",
412 icd->current_fmt->fourcc);
416 static int soc_camera_querycap(struct file *file, void *priv,
417 struct v4l2_capability *cap)
419 struct soc_camera_file *icf = file->private_data;
420 struct soc_camera_device *icd = icf->icd;
421 struct soc_camera_host *ici =
422 to_soc_camera_host(icd->dev.parent);
424 WARN_ON(priv != file->private_data);
426 strlcpy(cap->driver, ici->drv_name, sizeof(cap->driver));
427 return ici->querycap(ici, cap);
430 static int soc_camera_streamon(struct file *file, void *priv,
431 enum v4l2_buf_type i)
433 struct soc_camera_file *icf = file->private_data;
434 struct soc_camera_device *icd = icf->icd;
436 WARN_ON(priv != file->private_data);
438 dev_dbg(&icd->dev, "%s\n", __FUNCTION__);
440 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
443 icd->ops->start_capture(icd);
445 /* This calls buf_queue from host driver's videobuf_queue_ops */
446 return videobuf_streamon(&icf->vb_vidq);
449 static int soc_camera_streamoff(struct file *file, void *priv,
450 enum v4l2_buf_type i)
452 struct soc_camera_file *icf = file->private_data;
453 struct soc_camera_device *icd = icf->icd;
455 WARN_ON(priv != file->private_data);
457 dev_dbg(&icd->dev, "%s\n", __FUNCTION__);
459 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
462 /* This calls buf_release from host driver's videobuf_queue_ops for all
463 * remaining buffers. When the last buffer is freed, stop capture */
464 videobuf_streamoff(&icf->vb_vidq);
466 icd->ops->stop_capture(icd);
471 static int soc_camera_queryctrl(struct file *file, void *priv,
472 struct v4l2_queryctrl *qc)
474 struct soc_camera_file *icf = file->private_data;
475 struct soc_camera_device *icd = icf->icd;
478 WARN_ON(priv != file->private_data);
483 for (i = 0; i < icd->ops->num_controls; i++)
484 if (qc->id == icd->ops->controls[i].id) {
485 memcpy(qc, &(icd->ops->controls[i]),
493 static int soc_camera_g_ctrl(struct file *file, void *priv,
494 struct v4l2_control *ctrl)
496 struct soc_camera_file *icf = file->private_data;
497 struct soc_camera_device *icd = icf->icd;
499 WARN_ON(priv != file->private_data);
503 if (icd->gain == (unsigned short)~0)
505 ctrl->value = icd->gain;
507 case V4L2_CID_EXPOSURE:
508 if (icd->exposure == (unsigned short)~0)
510 ctrl->value = icd->exposure;
514 if (icd->ops->get_control)
515 return icd->ops->get_control(icd, ctrl);
519 static int soc_camera_s_ctrl(struct file *file, void *priv,
520 struct v4l2_control *ctrl)
522 struct soc_camera_file *icf = file->private_data;
523 struct soc_camera_device *icd = icf->icd;
525 WARN_ON(priv != file->private_data);
527 if (icd->ops->set_control)
528 return icd->ops->set_control(icd, ctrl);
532 static int soc_camera_cropcap(struct file *file, void *fh,
533 struct v4l2_cropcap *a)
535 struct soc_camera_file *icf = file->private_data;
536 struct soc_camera_device *icd = icf->icd;
538 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
539 a->bounds.left = icd->x_min;
540 a->bounds.top = icd->y_min;
541 a->bounds.width = icd->width_max;
542 a->bounds.height = icd->height_max;
543 a->defrect.left = icd->x_min;
544 a->defrect.top = icd->y_min;
545 a->defrect.width = 640;
546 a->defrect.height = 480;
547 a->pixelaspect.numerator = 1;
548 a->pixelaspect.denominator = 1;
553 static int soc_camera_g_crop(struct file *file, void *fh,
556 struct soc_camera_file *icf = file->private_data;
557 struct soc_camera_device *icd = icf->icd;
559 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
560 a->c.left = icd->x_current;
561 a->c.top = icd->y_current;
562 a->c.width = icd->width;
563 a->c.height = icd->height;
568 static int soc_camera_s_crop(struct file *file, void *fh,
571 struct soc_camera_file *icf = file->private_data;
572 struct soc_camera_device *icd = icf->icd;
573 struct soc_camera_host *ici =
574 to_soc_camera_host(icd->dev.parent);
577 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
580 ret = ici->set_capture_format(icd, 0, &a->c);
582 icd->width = a->c.width;
583 icd->height = a->c.height;
584 icd->x_current = a->c.left;
585 icd->y_current = a->c.top;
591 static int soc_camera_g_chip_ident(struct file *file, void *fh,
592 struct v4l2_chip_ident *id)
594 struct soc_camera_file *icf = file->private_data;
595 struct soc_camera_device *icd = icf->icd;
597 if (!icd->ops->get_chip_id)
600 return icd->ops->get_chip_id(icd, id);
603 #ifdef CONFIG_VIDEO_ADV_DEBUG
604 static int soc_camera_g_register(struct file *file, void *fh,
605 struct v4l2_register *reg)
607 struct soc_camera_file *icf = file->private_data;
608 struct soc_camera_device *icd = icf->icd;
610 if (!icd->ops->get_register)
613 return icd->ops->get_register(icd, reg);
616 static int soc_camera_s_register(struct file *file, void *fh,
617 struct v4l2_register *reg)
619 struct soc_camera_file *icf = file->private_data;
620 struct soc_camera_device *icd = icf->icd;
622 if (!icd->ops->set_register)
625 return icd->ops->set_register(icd, reg);
629 static int device_register_link(struct soc_camera_device *icd)
631 int ret = device_register(&icd->dev);
634 /* Prevent calling device_unregister() */
635 icd->dev.parent = NULL;
636 dev_err(&icd->dev, "Cannot register device: %d\n", ret);
637 /* Even if probe() was unsuccessful for all registered drivers,
638 * device_register() returns 0, and we add the link, just to
639 * document this camera's control device */
640 } else if (icd->control)
641 /* Have to sysfs_remove_link() before device_unregister()? */
642 if (sysfs_create_link(&icd->dev.kobj, &icd->control->kobj,
645 "Failed creating the control symlink\n");
649 /* So far this function cannot fail */
650 static void scan_add_host(struct soc_camera_host *ici)
652 struct soc_camera_device *icd;
654 mutex_lock(&list_lock);
656 list_for_each_entry(icd, &devices, list) {
657 if (icd->iface == ici->nr) {
658 icd->dev.parent = &ici->dev;
659 device_register_link(icd);
663 mutex_unlock(&list_lock);
666 /* return: 0 if no match found or a match found and
667 * device_register() successful, error code otherwise */
668 static int scan_add_device(struct soc_camera_device *icd)
670 struct soc_camera_host *ici;
673 mutex_lock(&list_lock);
675 list_add_tail(&icd->list, &devices);
677 /* Watch out for class_for_each_device / class_find_device API by
678 * Dave Young <hidave.darkstar@gmail.com> */
679 list_for_each_entry(ici, &hosts, list) {
680 if (icd->iface == ici->nr) {
682 icd->dev.parent = &ici->dev;
687 mutex_unlock(&list_lock);
690 ret = device_register_link(icd);
695 static int soc_camera_probe(struct device *dev)
697 struct soc_camera_device *icd = to_soc_camera_dev(dev);
698 struct soc_camera_host *ici =
699 to_soc_camera_host(icd->dev.parent);
705 /* We only call ->add() here to activate and probe the camera.
706 * We shall ->remove() and deactivate it immediately afterwards. */
711 ret = icd->probe(icd);
713 const struct v4l2_queryctrl *qctrl;
715 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_GAIN);
716 icd->gain = qctrl ? qctrl->default_value : (unsigned short)~0;
717 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE);
718 icd->exposure = qctrl ? qctrl->default_value :
726 /* This is called on device_unregister, which only means we have to disconnect
727 * from the host, but not remove ourselves from the device list */
728 static int soc_camera_remove(struct device *dev)
730 struct soc_camera_device *icd = to_soc_camera_dev(dev);
738 static struct bus_type soc_camera_bus_type = {
739 .name = "soc-camera",
740 .probe = soc_camera_probe,
741 .remove = soc_camera_remove,
744 static struct device_driver ic_drv = {
746 .bus = &soc_camera_bus_type,
747 .owner = THIS_MODULE,
751 * Image capture host - this is a host device, not a bus device, so,
752 * no bus reference, no probing.
754 static struct class soc_camera_host_class = {
755 .owner = THIS_MODULE,
756 .name = "camera_host",
759 static void dummy_release(struct device *dev)
763 int soc_camera_host_register(struct soc_camera_host *ici, struct module *owner)
766 struct soc_camera_host *ix;
768 if (!ici->vbq_ops || !ici->add || !ici->remove || !owner)
771 /* Number might be equal to the platform device ID */
772 sprintf(ici->dev.bus_id, "camera_host%d", ici->nr);
773 ici->dev.class = &soc_camera_host_class;
775 mutex_lock(&list_lock);
776 list_for_each_entry(ix, &hosts, list) {
777 if (ix->nr == ici->nr) {
778 mutex_unlock(&list_lock);
783 list_add_tail(&ici->list, &hosts);
784 mutex_unlock(&list_lock);
787 ici->dev.release = dummy_release;
789 ret = device_register(&ici->dev);
799 mutex_lock(&list_lock);
800 list_del(&ici->list);
801 mutex_unlock(&list_lock);
805 EXPORT_SYMBOL(soc_camera_host_register);
807 /* Unregister all clients! */
808 void soc_camera_host_unregister(struct soc_camera_host *ici)
810 struct soc_camera_device *icd;
812 mutex_lock(&list_lock);
814 list_del(&ici->list);
816 list_for_each_entry(icd, &devices, list) {
817 if (icd->dev.parent == &ici->dev) {
818 device_unregister(&icd->dev);
819 /* Not before device_unregister(), .remove
820 * needs parent to call ici->remove() */
821 icd->dev.parent = NULL;
822 memset(&icd->dev.kobj, 0, sizeof(icd->dev.kobj));
826 mutex_unlock(&list_lock);
828 device_unregister(&ici->dev);
830 EXPORT_SYMBOL(soc_camera_host_unregister);
832 /* Image capture device */
833 int soc_camera_device_register(struct soc_camera_device *icd)
835 struct soc_camera_device *ix;
841 for (i = 0; i < 256 && num < 0; i++) {
843 list_for_each_entry(ix, &devices, list) {
844 if (ix->iface == icd->iface && ix->devnum == i) {
852 /* ok, we have 256 cameras on this host...
853 * man, stay reasonable... */
857 icd->dev.bus = &soc_camera_bus_type;
858 snprintf(icd->dev.bus_id, sizeof(icd->dev.bus_id),
859 "%u-%u", icd->iface, icd->devnum);
861 icd->dev.release = dummy_release;
863 if (icd->ops->get_datawidth)
864 icd->cached_datawidth = icd->ops->get_datawidth(icd);
866 return scan_add_device(icd);
868 EXPORT_SYMBOL(soc_camera_device_register);
870 void soc_camera_device_unregister(struct soc_camera_device *icd)
872 mutex_lock(&list_lock);
873 list_del(&icd->list);
875 /* The bus->remove will be eventually called */
877 device_unregister(&icd->dev);
878 mutex_unlock(&list_lock);
880 EXPORT_SYMBOL(soc_camera_device_unregister);
882 int soc_camera_video_start(struct soc_camera_device *icd)
884 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
886 struct video_device *vdev;
888 if (!icd->dev.parent)
891 vdev = video_device_alloc();
894 dev_dbg(&ici->dev, "Allocated video_device %p\n", vdev);
896 strlcpy(vdev->name, ici->drv_name, sizeof(vdev->name));
897 /* Maybe better &ici->dev */
898 vdev->dev = &icd->dev;
899 vdev->type = VID_TYPE_CAPTURE;
900 vdev->current_norm = V4L2_STD_UNKNOWN;
901 vdev->fops = &soc_camera_fops;
902 vdev->release = video_device_release;
904 vdev->tvnorms = V4L2_STD_UNKNOWN,
905 vdev->vidioc_querycap = soc_camera_querycap;
906 vdev->vidioc_g_fmt_cap = soc_camera_g_fmt_cap;
907 vdev->vidioc_enum_fmt_cap = soc_camera_enum_fmt_cap;
908 vdev->vidioc_s_fmt_cap = soc_camera_s_fmt_cap;
909 vdev->vidioc_enum_input = soc_camera_enum_input;
910 vdev->vidioc_g_input = soc_camera_g_input;
911 vdev->vidioc_s_input = soc_camera_s_input;
912 vdev->vidioc_s_std = soc_camera_s_std;
913 vdev->vidioc_reqbufs = soc_camera_reqbufs;
914 vdev->vidioc_try_fmt_cap = soc_camera_try_fmt_cap;
915 vdev->vidioc_querybuf = soc_camera_querybuf;
916 vdev->vidioc_qbuf = soc_camera_qbuf;
917 vdev->vidioc_dqbuf = soc_camera_dqbuf;
918 vdev->vidioc_streamon = soc_camera_streamon;
919 vdev->vidioc_streamoff = soc_camera_streamoff;
920 vdev->vidioc_queryctrl = soc_camera_queryctrl;
921 vdev->vidioc_g_ctrl = soc_camera_g_ctrl;
922 vdev->vidioc_s_ctrl = soc_camera_s_ctrl;
923 vdev->vidioc_cropcap = soc_camera_cropcap;
924 vdev->vidioc_g_crop = soc_camera_g_crop;
925 vdev->vidioc_s_crop = soc_camera_s_crop;
926 vdev->vidioc_g_chip_ident = soc_camera_g_chip_ident;
927 #ifdef CONFIG_VIDEO_ADV_DEBUG
928 vdev->vidioc_g_register = soc_camera_g_register;
929 vdev->vidioc_s_register = soc_camera_s_register;
932 icd->current_fmt = &icd->ops->formats[0];
934 err = video_register_device(vdev, VFL_TYPE_GRABBER, vdev->minor);
936 dev_err(vdev->dev, "video_register_device failed\n");
944 video_device_release(vdev);
948 EXPORT_SYMBOL(soc_camera_video_start);
950 void soc_camera_video_stop(struct soc_camera_device *icd)
952 struct video_device *vdev = icd->vdev;
954 dev_dbg(&icd->dev, "%s\n", __FUNCTION__);
956 if (!icd->dev.parent || !vdev)
959 mutex_lock(&video_lock);
960 video_unregister_device(vdev);
962 mutex_unlock(&video_lock);
964 EXPORT_SYMBOL(soc_camera_video_stop);
966 static int __init soc_camera_init(void)
968 int ret = bus_register(&soc_camera_bus_type);
971 ret = driver_register(&ic_drv);
974 ret = class_register(&soc_camera_host_class);
981 driver_unregister(&ic_drv);
983 bus_unregister(&soc_camera_bus_type);
987 static void __exit soc_camera_exit(void)
989 class_unregister(&soc_camera_host_class);
990 driver_unregister(&ic_drv);
991 bus_unregister(&soc_camera_bus_type);
994 module_init(soc_camera_init);
995 module_exit(soc_camera_exit);
997 MODULE_DESCRIPTION("Image capture bus driver");
998 MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
999 MODULE_LICENSE("GPL");