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/videobuf-core.h>
30 #include <media/soc_camera.h>
32 static LIST_HEAD(hosts);
33 static LIST_HEAD(devices);
34 static DEFINE_MUTEX(list_lock);
35 static DEFINE_MUTEX(video_lock);
37 const static struct soc_camera_data_format*
38 format_by_fourcc(struct soc_camera_device *icd, unsigned int fourcc)
42 for (i = 0; i < icd->num_formats; i++)
43 if (icd->formats[i].fourcc == fourcc)
44 return icd->formats + i;
48 static int soc_camera_try_fmt_vid_cap(struct file *file, void *priv,
49 struct v4l2_format *f)
51 struct soc_camera_file *icf = file->private_data;
52 struct soc_camera_device *icd = icf->icd;
53 struct soc_camera_host *ici =
54 to_soc_camera_host(icd->dev.parent);
55 enum v4l2_field field;
56 const struct soc_camera_data_format *fmt;
59 WARN_ON(priv != file->private_data);
61 fmt = format_by_fourcc(icd, f->fmt.pix.pixelformat);
63 dev_dbg(&icd->dev, "invalid format 0x%08x\n",
64 f->fmt.pix.pixelformat);
68 dev_dbg(&icd->dev, "fmt: 0x%08x\n", fmt->fourcc);
70 field = f->fmt.pix.field;
72 if (field == V4L2_FIELD_ANY) {
73 field = V4L2_FIELD_NONE;
74 } else if (V4L2_FIELD_NONE != field) {
75 dev_err(&icd->dev, "Field type invalid.\n");
79 /* test physical bus parameters */
80 ret = ici->ops->try_bus_param(icd, f->fmt.pix.pixelformat);
84 /* limit format to hardware capabilities */
85 ret = ici->ops->try_fmt_cap(icd, f);
87 /* calculate missing fields */
88 f->fmt.pix.field = field;
89 f->fmt.pix.bytesperline =
90 (f->fmt.pix.width * fmt->depth) >> 3;
91 f->fmt.pix.sizeimage =
92 f->fmt.pix.height * f->fmt.pix.bytesperline;
97 static int soc_camera_enum_input(struct file *file, void *priv,
98 struct v4l2_input *inp)
103 inp->type = V4L2_INPUT_TYPE_CAMERA;
104 inp->std = V4L2_STD_UNKNOWN;
105 strcpy(inp->name, "Camera");
110 static int soc_camera_g_input(struct file *file, void *priv, unsigned int *i)
117 static int soc_camera_s_input(struct file *file, void *priv, unsigned int i)
125 static int soc_camera_s_std(struct file *file, void *priv, v4l2_std_id *a)
130 static int soc_camera_reqbufs(struct file *file, void *priv,
131 struct v4l2_requestbuffers *p)
134 struct soc_camera_file *icf = file->private_data;
135 struct soc_camera_device *icd = icf->icd;
136 struct soc_camera_host *ici =
137 to_soc_camera_host(icd->dev.parent);
139 WARN_ON(priv != file->private_data);
141 dev_dbg(&icd->dev, "%s: %d\n", __func__, p->memory);
143 ret = videobuf_reqbufs(&icf->vb_vidq, p);
147 return ici->ops->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->ops->owner)) {
206 dev_err(&icd->dev, "Couldn't lock capture bus driver.\n");
214 /* Now we really have to activate the camera */
215 if (icd->use_count == 1) {
216 ret = ici->ops->add(icd);
218 dev_err(&icd->dev, "Couldn't activate the camera: %d\n", ret);
224 mutex_unlock(&video_lock);
226 file->private_data = icf;
227 dev_dbg(&icd->dev, "camera device open\n");
229 ici->ops->init_videobuf(&icf->vb_vidq, icd);
233 /* All errors are entered with the video_lock held */
235 module_put(ici->ops->owner);
237 module_put(icd->ops->owner);
239 mutex_unlock(&video_lock);
244 static int soc_camera_close(struct inode *inode, struct file *file)
246 struct soc_camera_file *icf = file->private_data;
247 struct soc_camera_device *icd = icf->icd;
248 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
249 struct video_device *vdev = icd->vdev;
251 mutex_lock(&video_lock);
254 ici->ops->remove(icd);
255 module_put(icd->ops->owner);
256 module_put(ici->ops->owner);
257 mutex_unlock(&video_lock);
261 dev_dbg(vdev->dev, "camera device close\n");
266 static ssize_t soc_camera_read(struct file *file, char __user *buf,
267 size_t count, loff_t *ppos)
269 struct soc_camera_file *icf = file->private_data;
270 struct soc_camera_device *icd = icf->icd;
271 struct video_device *vdev = icd->vdev;
274 dev_err(vdev->dev, "camera device read not implemented\n");
279 static int soc_camera_mmap(struct file *file, struct vm_area_struct *vma)
281 struct soc_camera_file *icf = file->private_data;
282 struct soc_camera_device *icd = icf->icd;
285 dev_dbg(&icd->dev, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
287 err = videobuf_mmap_mapper(&icf->vb_vidq, vma);
289 dev_dbg(&icd->dev, "vma start=0x%08lx, size=%ld, ret=%d\n",
290 (unsigned long)vma->vm_start,
291 (unsigned long)vma->vm_end - (unsigned long)vma->vm_start,
297 static unsigned int soc_camera_poll(struct file *file, poll_table *pt)
299 struct soc_camera_file *icf = file->private_data;
300 struct soc_camera_device *icd = icf->icd;
301 struct soc_camera_host *ici =
302 to_soc_camera_host(icd->dev.parent);
304 if (list_empty(&icf->vb_vidq.stream)) {
305 dev_err(&icd->dev, "Trying to poll with no queued buffers!\n");
309 return ici->ops->poll(file, pt);
313 static struct file_operations soc_camera_fops = {
314 .owner = THIS_MODULE,
315 .open = soc_camera_open,
316 .release = soc_camera_close,
317 .ioctl = video_ioctl2,
318 .read = soc_camera_read,
319 .mmap = soc_camera_mmap,
320 .poll = soc_camera_poll,
325 static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv,
326 struct v4l2_format *f)
328 struct soc_camera_file *icf = file->private_data;
329 struct soc_camera_device *icd = icf->icd;
330 struct soc_camera_host *ici =
331 to_soc_camera_host(icd->dev.parent);
333 struct v4l2_rect rect;
334 const static struct soc_camera_data_format *data_fmt;
336 WARN_ON(priv != file->private_data);
338 data_fmt = format_by_fourcc(icd, f->fmt.pix.pixelformat);
342 /* buswidth may be further adjusted by the ici */
343 icd->buswidth = data_fmt->depth;
345 ret = soc_camera_try_fmt_vid_cap(file, icf, f);
349 rect.left = icd->x_current;
350 rect.top = icd->y_current;
351 rect.width = f->fmt.pix.width;
352 rect.height = f->fmt.pix.height;
353 ret = ici->ops->set_fmt_cap(icd, f->fmt.pix.pixelformat, &rect);
357 icd->current_fmt = data_fmt;
358 icd->width = rect.width;
359 icd->height = rect.height;
360 icf->vb_vidq.field = f->fmt.pix.field;
361 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != f->type)
362 dev_warn(&icd->dev, "Attention! Wrong buf-type %d\n",
365 dev_dbg(&icd->dev, "set width: %d height: %d\n",
366 icd->width, icd->height);
368 /* set physical bus parameters */
369 return ici->ops->set_bus_param(icd, f->fmt.pix.pixelformat);
372 static int soc_camera_enum_fmt_vid_cap(struct file *file, void *priv,
373 struct v4l2_fmtdesc *f)
375 struct soc_camera_file *icf = file->private_data;
376 struct soc_camera_device *icd = icf->icd;
377 const struct soc_camera_data_format *format;
379 WARN_ON(priv != file->private_data);
381 if (f->index >= icd->num_formats)
384 format = &icd->formats[f->index];
386 strlcpy(f->description, format->name, sizeof(f->description));
387 f->pixelformat = format->fourcc;
391 static int soc_camera_g_fmt_vid_cap(struct file *file, void *priv,
392 struct v4l2_format *f)
394 struct soc_camera_file *icf = file->private_data;
395 struct soc_camera_device *icd = icf->icd;
397 WARN_ON(priv != file->private_data);
399 f->fmt.pix.width = icd->width;
400 f->fmt.pix.height = icd->height;
401 f->fmt.pix.field = icf->vb_vidq.field;
402 f->fmt.pix.pixelformat = icd->current_fmt->fourcc;
403 f->fmt.pix.bytesperline =
404 (f->fmt.pix.width * icd->current_fmt->depth) >> 3;
405 f->fmt.pix.sizeimage =
406 f->fmt.pix.height * f->fmt.pix.bytesperline;
407 dev_dbg(&icd->dev, "current_fmt->fourcc: 0x%08x\n",
408 icd->current_fmt->fourcc);
412 static int soc_camera_querycap(struct file *file, void *priv,
413 struct v4l2_capability *cap)
415 struct soc_camera_file *icf = file->private_data;
416 struct soc_camera_device *icd = icf->icd;
417 struct soc_camera_host *ici =
418 to_soc_camera_host(icd->dev.parent);
420 WARN_ON(priv != file->private_data);
422 strlcpy(cap->driver, ici->drv_name, sizeof(cap->driver));
423 return ici->ops->querycap(ici, cap);
426 static int soc_camera_streamon(struct file *file, void *priv,
427 enum v4l2_buf_type i)
429 struct soc_camera_file *icf = file->private_data;
430 struct soc_camera_device *icd = icf->icd;
432 WARN_ON(priv != file->private_data);
434 dev_dbg(&icd->dev, "%s\n", __func__);
436 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
439 icd->ops->start_capture(icd);
441 /* This calls buf_queue from host driver's videobuf_queue_ops */
442 return videobuf_streamon(&icf->vb_vidq);
445 static int soc_camera_streamoff(struct file *file, void *priv,
446 enum v4l2_buf_type i)
448 struct soc_camera_file *icf = file->private_data;
449 struct soc_camera_device *icd = icf->icd;
451 WARN_ON(priv != file->private_data);
453 dev_dbg(&icd->dev, "%s\n", __func__);
455 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
458 /* This calls buf_release from host driver's videobuf_queue_ops for all
459 * remaining buffers. When the last buffer is freed, stop capture */
460 videobuf_streamoff(&icf->vb_vidq);
462 icd->ops->stop_capture(icd);
467 static int soc_camera_queryctrl(struct file *file, void *priv,
468 struct v4l2_queryctrl *qc)
470 struct soc_camera_file *icf = file->private_data;
471 struct soc_camera_device *icd = icf->icd;
474 WARN_ON(priv != file->private_data);
479 for (i = 0; i < icd->ops->num_controls; i++)
480 if (qc->id == icd->ops->controls[i].id) {
481 memcpy(qc, &(icd->ops->controls[i]),
489 static int soc_camera_g_ctrl(struct file *file, void *priv,
490 struct v4l2_control *ctrl)
492 struct soc_camera_file *icf = file->private_data;
493 struct soc_camera_device *icd = icf->icd;
495 WARN_ON(priv != file->private_data);
499 if (icd->gain == (unsigned short)~0)
501 ctrl->value = icd->gain;
503 case V4L2_CID_EXPOSURE:
504 if (icd->exposure == (unsigned short)~0)
506 ctrl->value = icd->exposure;
510 if (icd->ops->get_control)
511 return icd->ops->get_control(icd, ctrl);
515 static int soc_camera_s_ctrl(struct file *file, void *priv,
516 struct v4l2_control *ctrl)
518 struct soc_camera_file *icf = file->private_data;
519 struct soc_camera_device *icd = icf->icd;
521 WARN_ON(priv != file->private_data);
523 if (icd->ops->set_control)
524 return icd->ops->set_control(icd, ctrl);
528 static int soc_camera_cropcap(struct file *file, void *fh,
529 struct v4l2_cropcap *a)
531 struct soc_camera_file *icf = file->private_data;
532 struct soc_camera_device *icd = icf->icd;
534 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
535 a->bounds.left = icd->x_min;
536 a->bounds.top = icd->y_min;
537 a->bounds.width = icd->width_max;
538 a->bounds.height = icd->height_max;
539 a->defrect.left = icd->x_min;
540 a->defrect.top = icd->y_min;
541 a->defrect.width = 640;
542 a->defrect.height = 480;
543 a->pixelaspect.numerator = 1;
544 a->pixelaspect.denominator = 1;
549 static int soc_camera_g_crop(struct file *file, void *fh,
552 struct soc_camera_file *icf = file->private_data;
553 struct soc_camera_device *icd = icf->icd;
555 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
556 a->c.left = icd->x_current;
557 a->c.top = icd->y_current;
558 a->c.width = icd->width;
559 a->c.height = icd->height;
564 static int soc_camera_s_crop(struct file *file, void *fh,
567 struct soc_camera_file *icf = file->private_data;
568 struct soc_camera_device *icd = icf->icd;
569 struct soc_camera_host *ici =
570 to_soc_camera_host(icd->dev.parent);
573 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
576 ret = ici->ops->set_fmt_cap(icd, 0, &a->c);
578 icd->width = a->c.width;
579 icd->height = a->c.height;
580 icd->x_current = a->c.left;
581 icd->y_current = a->c.top;
587 static int soc_camera_g_chip_ident(struct file *file, void *fh,
588 struct v4l2_chip_ident *id)
590 struct soc_camera_file *icf = file->private_data;
591 struct soc_camera_device *icd = icf->icd;
593 if (!icd->ops->get_chip_id)
596 return icd->ops->get_chip_id(icd, id);
599 #ifdef CONFIG_VIDEO_ADV_DEBUG
600 static int soc_camera_g_register(struct file *file, void *fh,
601 struct v4l2_register *reg)
603 struct soc_camera_file *icf = file->private_data;
604 struct soc_camera_device *icd = icf->icd;
606 if (!icd->ops->get_register)
609 return icd->ops->get_register(icd, reg);
612 static int soc_camera_s_register(struct file *file, void *fh,
613 struct v4l2_register *reg)
615 struct soc_camera_file *icf = file->private_data;
616 struct soc_camera_device *icd = icf->icd;
618 if (!icd->ops->set_register)
621 return icd->ops->set_register(icd, reg);
625 static int device_register_link(struct soc_camera_device *icd)
627 int ret = device_register(&icd->dev);
630 /* Prevent calling device_unregister() */
631 icd->dev.parent = NULL;
632 dev_err(&icd->dev, "Cannot register device: %d\n", ret);
633 /* Even if probe() was unsuccessful for all registered drivers,
634 * device_register() returns 0, and we add the link, just to
635 * document this camera's control device */
636 } else if (icd->control)
637 /* Have to sysfs_remove_link() before device_unregister()? */
638 if (sysfs_create_link(&icd->dev.kobj, &icd->control->kobj,
641 "Failed creating the control symlink\n");
645 /* So far this function cannot fail */
646 static void scan_add_host(struct soc_camera_host *ici)
648 struct soc_camera_device *icd;
650 mutex_lock(&list_lock);
652 list_for_each_entry(icd, &devices, list) {
653 if (icd->iface == ici->nr) {
654 icd->dev.parent = &ici->dev;
655 device_register_link(icd);
659 mutex_unlock(&list_lock);
662 /* return: 0 if no match found or a match found and
663 * device_register() successful, error code otherwise */
664 static int scan_add_device(struct soc_camera_device *icd)
666 struct soc_camera_host *ici;
669 mutex_lock(&list_lock);
671 list_add_tail(&icd->list, &devices);
673 /* Watch out for class_for_each_device / class_find_device API by
674 * Dave Young <hidave.darkstar@gmail.com> */
675 list_for_each_entry(ici, &hosts, list) {
676 if (icd->iface == ici->nr) {
678 icd->dev.parent = &ici->dev;
683 mutex_unlock(&list_lock);
686 ret = device_register_link(icd);
691 static int soc_camera_probe(struct device *dev)
693 struct soc_camera_device *icd = to_soc_camera_dev(dev);
694 struct soc_camera_host *ici =
695 to_soc_camera_host(icd->dev.parent);
698 if (!icd->ops->probe)
701 /* We only call ->add() here to activate and probe the camera.
702 * We shall ->remove() and deactivate it immediately afterwards. */
703 ret = ici->ops->add(icd);
707 ret = icd->ops->probe(icd);
709 const struct v4l2_queryctrl *qctrl;
711 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_GAIN);
712 icd->gain = qctrl ? qctrl->default_value : (unsigned short)~0;
713 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE);
714 icd->exposure = qctrl ? qctrl->default_value :
717 ici->ops->remove(icd);
722 /* This is called on device_unregister, which only means we have to disconnect
723 * from the host, but not remove ourselves from the device list */
724 static int soc_camera_remove(struct device *dev)
726 struct soc_camera_device *icd = to_soc_camera_dev(dev);
728 if (icd->ops->remove)
729 icd->ops->remove(icd);
734 static struct bus_type soc_camera_bus_type = {
735 .name = "soc-camera",
736 .probe = soc_camera_probe,
737 .remove = soc_camera_remove,
740 static struct device_driver ic_drv = {
742 .bus = &soc_camera_bus_type,
743 .owner = THIS_MODULE,
746 static void dummy_release(struct device *dev)
750 int soc_camera_host_register(struct soc_camera_host *ici)
753 struct soc_camera_host *ix;
755 if (!ici->ops->init_videobuf || !ici->ops->add || !ici->ops->remove)
758 /* Number might be equal to the platform device ID */
759 sprintf(ici->dev.bus_id, "camera_host%d", ici->nr);
761 mutex_lock(&list_lock);
762 list_for_each_entry(ix, &hosts, list) {
763 if (ix->nr == ici->nr) {
764 mutex_unlock(&list_lock);
769 list_add_tail(&ici->list, &hosts);
770 mutex_unlock(&list_lock);
772 ici->dev.release = dummy_release;
774 ret = device_register(&ici->dev);
784 mutex_lock(&list_lock);
785 list_del(&ici->list);
786 mutex_unlock(&list_lock);
790 EXPORT_SYMBOL(soc_camera_host_register);
792 /* Unregister all clients! */
793 void soc_camera_host_unregister(struct soc_camera_host *ici)
795 struct soc_camera_device *icd;
797 mutex_lock(&list_lock);
799 list_del(&ici->list);
801 list_for_each_entry(icd, &devices, list) {
802 if (icd->dev.parent == &ici->dev) {
803 device_unregister(&icd->dev);
804 /* Not before device_unregister(), .remove
805 * needs parent to call ici->ops->remove() */
806 icd->dev.parent = NULL;
807 memset(&icd->dev.kobj, 0, sizeof(icd->dev.kobj));
811 mutex_unlock(&list_lock);
813 device_unregister(&ici->dev);
815 EXPORT_SYMBOL(soc_camera_host_unregister);
817 /* Image capture device */
818 int soc_camera_device_register(struct soc_camera_device *icd)
820 struct soc_camera_device *ix;
826 for (i = 0; i < 256 && num < 0; i++) {
828 list_for_each_entry(ix, &devices, list) {
829 if (ix->iface == icd->iface && ix->devnum == i) {
837 /* ok, we have 256 cameras on this host...
838 * man, stay reasonable... */
842 icd->dev.bus = &soc_camera_bus_type;
843 snprintf(icd->dev.bus_id, sizeof(icd->dev.bus_id),
844 "%u-%u", icd->iface, icd->devnum);
846 icd->dev.release = dummy_release;
848 return scan_add_device(icd);
850 EXPORT_SYMBOL(soc_camera_device_register);
852 void soc_camera_device_unregister(struct soc_camera_device *icd)
854 mutex_lock(&list_lock);
855 list_del(&icd->list);
857 /* The bus->remove will be eventually called */
859 device_unregister(&icd->dev);
860 mutex_unlock(&list_lock);
862 EXPORT_SYMBOL(soc_camera_device_unregister);
864 int soc_camera_video_start(struct soc_camera_device *icd)
866 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
868 struct video_device *vdev;
870 if (!icd->dev.parent)
873 vdev = video_device_alloc();
876 dev_dbg(&ici->dev, "Allocated video_device %p\n", vdev);
878 strlcpy(vdev->name, ici->drv_name, sizeof(vdev->name));
879 /* Maybe better &ici->dev */
880 vdev->dev = &icd->dev;
881 vdev->type = VID_TYPE_CAPTURE;
882 vdev->current_norm = V4L2_STD_UNKNOWN;
883 vdev->fops = &soc_camera_fops;
884 vdev->release = video_device_release;
886 vdev->tvnorms = V4L2_STD_UNKNOWN,
887 vdev->vidioc_querycap = soc_camera_querycap;
888 vdev->vidioc_g_fmt_vid_cap = soc_camera_g_fmt_vid_cap;
889 vdev->vidioc_enum_fmt_vid_cap = soc_camera_enum_fmt_vid_cap;
890 vdev->vidioc_s_fmt_vid_cap = soc_camera_s_fmt_vid_cap;
891 vdev->vidioc_enum_input = soc_camera_enum_input;
892 vdev->vidioc_g_input = soc_camera_g_input;
893 vdev->vidioc_s_input = soc_camera_s_input;
894 vdev->vidioc_s_std = soc_camera_s_std;
895 vdev->vidioc_reqbufs = soc_camera_reqbufs;
896 vdev->vidioc_try_fmt_vid_cap = soc_camera_try_fmt_vid_cap;
897 vdev->vidioc_querybuf = soc_camera_querybuf;
898 vdev->vidioc_qbuf = soc_camera_qbuf;
899 vdev->vidioc_dqbuf = soc_camera_dqbuf;
900 vdev->vidioc_streamon = soc_camera_streamon;
901 vdev->vidioc_streamoff = soc_camera_streamoff;
902 vdev->vidioc_queryctrl = soc_camera_queryctrl;
903 vdev->vidioc_g_ctrl = soc_camera_g_ctrl;
904 vdev->vidioc_s_ctrl = soc_camera_s_ctrl;
905 vdev->vidioc_cropcap = soc_camera_cropcap;
906 vdev->vidioc_g_crop = soc_camera_g_crop;
907 vdev->vidioc_s_crop = soc_camera_s_crop;
908 vdev->vidioc_g_chip_ident = soc_camera_g_chip_ident;
909 #ifdef CONFIG_VIDEO_ADV_DEBUG
910 vdev->vidioc_g_register = soc_camera_g_register;
911 vdev->vidioc_s_register = soc_camera_s_register;
914 icd->current_fmt = &icd->formats[0];
916 err = video_register_device(vdev, VFL_TYPE_GRABBER, vdev->minor);
918 dev_err(vdev->dev, "video_register_device failed\n");
926 video_device_release(vdev);
930 EXPORT_SYMBOL(soc_camera_video_start);
932 void soc_camera_video_stop(struct soc_camera_device *icd)
934 struct video_device *vdev = icd->vdev;
936 dev_dbg(&icd->dev, "%s\n", __func__);
938 if (!icd->dev.parent || !vdev)
941 mutex_lock(&video_lock);
942 video_unregister_device(vdev);
944 mutex_unlock(&video_lock);
946 EXPORT_SYMBOL(soc_camera_video_stop);
948 static int __init soc_camera_init(void)
950 int ret = bus_register(&soc_camera_bus_type);
953 ret = driver_register(&ic_drv);
960 bus_unregister(&soc_camera_bus_type);
964 static void __exit soc_camera_exit(void)
966 driver_unregister(&ic_drv);
967 bus_unregister(&soc_camera_bus_type);
970 module_init(soc_camera_init);
971 module_exit(soc_camera_exit);
973 MODULE_DESCRIPTION("Image capture bus driver");
974 MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
975 MODULE_LICENSE("GPL");