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->num_formats; i++)
42 if (icd->formats[i].fourcc == fourcc)
43 return icd->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 /* test physical bus parameters */
79 ret = ici->ops->try_bus_param(icd, f->fmt.pix.pixelformat);
83 /* limit format to hardware capabilities */
84 ret = ici->ops->try_fmt_cap(icd, f);
86 /* calculate missing fields */
87 f->fmt.pix.field = field;
88 f->fmt.pix.bytesperline =
89 (f->fmt.pix.width * fmt->depth) >> 3;
90 f->fmt.pix.sizeimage =
91 f->fmt.pix.height * f->fmt.pix.bytesperline;
96 static int soc_camera_enum_input(struct file *file, void *priv,
97 struct v4l2_input *inp)
102 inp->type = V4L2_INPUT_TYPE_CAMERA;
103 inp->std = V4L2_STD_UNKNOWN;
104 strcpy(inp->name, "Camera");
109 static int soc_camera_g_input(struct file *file, void *priv, unsigned int *i)
116 static int soc_camera_s_input(struct file *file, void *priv, unsigned int i)
124 static int soc_camera_s_std(struct file *file, void *priv, v4l2_std_id *a)
129 static int soc_camera_reqbufs(struct file *file, void *priv,
130 struct v4l2_requestbuffers *p)
133 struct soc_camera_file *icf = file->private_data;
134 struct soc_camera_device *icd = icf->icd;
135 struct soc_camera_host *ici =
136 to_soc_camera_host(icd->dev.parent);
138 WARN_ON(priv != file->private_data);
140 dev_dbg(&icd->dev, "%s: %d\n", __FUNCTION__, p->memory);
142 ret = videobuf_reqbufs(&icf->vb_vidq, p);
146 return ici->ops->reqbufs(icf, p);
151 static int soc_camera_querybuf(struct file *file, void *priv,
152 struct v4l2_buffer *p)
154 struct soc_camera_file *icf = file->private_data;
156 WARN_ON(priv != file->private_data);
158 return videobuf_querybuf(&icf->vb_vidq, p);
161 static int soc_camera_qbuf(struct file *file, void *priv,
162 struct v4l2_buffer *p)
164 struct soc_camera_file *icf = file->private_data;
166 WARN_ON(priv != file->private_data);
168 return videobuf_qbuf(&icf->vb_vidq, p);
171 static int soc_camera_dqbuf(struct file *file, void *priv,
172 struct v4l2_buffer *p)
174 struct soc_camera_file *icf = file->private_data;
176 WARN_ON(priv != file->private_data);
178 return videobuf_dqbuf(&icf->vb_vidq, p, file->f_flags & O_NONBLOCK);
181 static int soc_camera_open(struct inode *inode, struct file *file)
183 struct video_device *vdev;
184 struct soc_camera_device *icd;
185 struct soc_camera_host *ici;
186 struct soc_camera_file *icf;
190 icf = vmalloc(sizeof(*icf));
194 /* Protect against icd->remove() until we module_get() both drivers. */
195 mutex_lock(&video_lock);
197 vdev = video_devdata(file);
198 icd = container_of(vdev->dev, struct soc_camera_device, dev);
199 ici = to_soc_camera_host(icd->dev.parent);
201 if (!try_module_get(icd->ops->owner)) {
202 dev_err(&icd->dev, "Couldn't lock sensor driver.\n");
207 if (!try_module_get(ici->ops->owner)) {
208 dev_err(&icd->dev, "Couldn't lock capture bus driver.\n");
215 icf->lock = ici->ops->spinlock_alloc(icf);
223 /* Now we really have to activate the camera */
224 if (icd->use_count == 1) {
225 ret = ici->ops->add(icd);
227 dev_err(&icd->dev, "Couldn't activate the camera: %d\n", ret);
233 mutex_unlock(&video_lock);
235 file->private_data = icf;
236 dev_dbg(&icd->dev, "camera device open\n");
238 /* We must pass NULL as dev pointer, then all pci_* dma operations
239 * transform to normal dma_* ones. */
240 videobuf_queue_sg_init(&icf->vb_vidq, ici->vbq_ops, NULL, icf->lock,
241 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
246 /* All errors are entered with the video_lock held */
250 if (ici->ops->spinlock_free)
251 ici->ops->spinlock_free(lock);
253 module_put(ici->ops->owner);
255 module_put(icd->ops->owner);
257 mutex_unlock(&video_lock);
262 static int soc_camera_close(struct inode *inode, struct file *file)
264 struct soc_camera_file *icf = file->private_data;
265 struct soc_camera_device *icd = icf->icd;
266 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
267 struct video_device *vdev = icd->vdev;
268 spinlock_t *lock = icf->lock;
270 mutex_lock(&video_lock);
273 ici->ops->remove(icd);
275 if (ici->ops->spinlock_free)
276 ici->ops->spinlock_free(lock);
277 module_put(icd->ops->owner);
278 module_put(ici->ops->owner);
279 mutex_unlock(&video_lock);
283 dev_dbg(vdev->dev, "camera device close\n");
288 static ssize_t soc_camera_read(struct file *file, char __user *buf,
289 size_t count, loff_t *ppos)
291 struct soc_camera_file *icf = file->private_data;
292 struct soc_camera_device *icd = icf->icd;
293 struct video_device *vdev = icd->vdev;
296 dev_err(vdev->dev, "camera device read not implemented\n");
301 static int soc_camera_mmap(struct file *file, struct vm_area_struct *vma)
303 struct soc_camera_file *icf = file->private_data;
304 struct soc_camera_device *icd = icf->icd;
307 dev_dbg(&icd->dev, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
309 err = videobuf_mmap_mapper(&icf->vb_vidq, vma);
311 dev_dbg(&icd->dev, "vma start=0x%08lx, size=%ld, ret=%d\n",
312 (unsigned long)vma->vm_start,
313 (unsigned long)vma->vm_end - (unsigned long)vma->vm_start,
319 static unsigned int soc_camera_poll(struct file *file, poll_table *pt)
321 struct soc_camera_file *icf = file->private_data;
322 struct soc_camera_device *icd = icf->icd;
323 struct soc_camera_host *ici =
324 to_soc_camera_host(icd->dev.parent);
326 if (list_empty(&icf->vb_vidq.stream)) {
327 dev_err(&icd->dev, "Trying to poll with no queued buffers!\n");
331 return ici->ops->poll(file, pt);
335 static struct file_operations soc_camera_fops = {
336 .owner = THIS_MODULE,
337 .open = soc_camera_open,
338 .release = soc_camera_close,
339 .ioctl = video_ioctl2,
340 .read = soc_camera_read,
341 .mmap = soc_camera_mmap,
342 .poll = soc_camera_poll,
347 static int soc_camera_s_fmt_cap(struct file *file, void *priv,
348 struct v4l2_format *f)
350 struct soc_camera_file *icf = file->private_data;
351 struct soc_camera_device *icd = icf->icd;
352 struct soc_camera_host *ici =
353 to_soc_camera_host(icd->dev.parent);
355 struct v4l2_rect rect;
356 const static struct soc_camera_data_format *data_fmt;
358 WARN_ON(priv != file->private_data);
360 data_fmt = format_by_fourcc(icd, f->fmt.pix.pixelformat);
364 /* buswidth may be further adjusted by the ici */
365 icd->buswidth = data_fmt->depth;
367 ret = soc_camera_try_fmt_cap(file, icf, f);
371 rect.left = icd->x_current;
372 rect.top = icd->y_current;
373 rect.width = f->fmt.pix.width;
374 rect.height = f->fmt.pix.height;
375 ret = ici->ops->set_fmt_cap(icd, f->fmt.pix.pixelformat, &rect);
379 icd->current_fmt = data_fmt;
380 icd->width = rect.width;
381 icd->height = rect.height;
382 icf->vb_vidq.field = f->fmt.pix.field;
383 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != f->type)
384 dev_warn(&icd->dev, "Attention! Wrong buf-type %d\n",
387 dev_dbg(&icd->dev, "set width: %d height: %d\n",
388 icd->width, icd->height);
390 /* set physical bus parameters */
391 return ici->ops->set_bus_param(icd, f->fmt.pix.pixelformat);
394 static int soc_camera_enum_fmt_cap(struct file *file, void *priv,
395 struct v4l2_fmtdesc *f)
397 struct soc_camera_file *icf = file->private_data;
398 struct soc_camera_device *icd = icf->icd;
399 const struct soc_camera_data_format *format;
401 WARN_ON(priv != file->private_data);
403 if (f->index >= icd->num_formats)
406 format = &icd->formats[f->index];
408 strlcpy(f->description, format->name, sizeof(f->description));
409 f->pixelformat = format->fourcc;
413 static int soc_camera_g_fmt_cap(struct file *file, void *priv,
414 struct v4l2_format *f)
416 struct soc_camera_file *icf = file->private_data;
417 struct soc_camera_device *icd = icf->icd;
419 WARN_ON(priv != file->private_data);
421 f->fmt.pix.width = icd->width;
422 f->fmt.pix.height = icd->height;
423 f->fmt.pix.field = icf->vb_vidq.field;
424 f->fmt.pix.pixelformat = icd->current_fmt->fourcc;
425 f->fmt.pix.bytesperline =
426 (f->fmt.pix.width * icd->current_fmt->depth) >> 3;
427 f->fmt.pix.sizeimage =
428 f->fmt.pix.height * f->fmt.pix.bytesperline;
429 dev_dbg(&icd->dev, "current_fmt->fourcc: 0x%08x\n",
430 icd->current_fmt->fourcc);
434 static int soc_camera_querycap(struct file *file, void *priv,
435 struct v4l2_capability *cap)
437 struct soc_camera_file *icf = file->private_data;
438 struct soc_camera_device *icd = icf->icd;
439 struct soc_camera_host *ici =
440 to_soc_camera_host(icd->dev.parent);
442 WARN_ON(priv != file->private_data);
444 strlcpy(cap->driver, ici->drv_name, sizeof(cap->driver));
445 return ici->ops->querycap(ici, cap);
448 static int soc_camera_streamon(struct file *file, void *priv,
449 enum v4l2_buf_type i)
451 struct soc_camera_file *icf = file->private_data;
452 struct soc_camera_device *icd = icf->icd;
454 WARN_ON(priv != file->private_data);
456 dev_dbg(&icd->dev, "%s\n", __FUNCTION__);
458 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
461 icd->ops->start_capture(icd);
463 /* This calls buf_queue from host driver's videobuf_queue_ops */
464 return videobuf_streamon(&icf->vb_vidq);
467 static int soc_camera_streamoff(struct file *file, void *priv,
468 enum v4l2_buf_type i)
470 struct soc_camera_file *icf = file->private_data;
471 struct soc_camera_device *icd = icf->icd;
473 WARN_ON(priv != file->private_data);
475 dev_dbg(&icd->dev, "%s\n", __FUNCTION__);
477 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
480 /* This calls buf_release from host driver's videobuf_queue_ops for all
481 * remaining buffers. When the last buffer is freed, stop capture */
482 videobuf_streamoff(&icf->vb_vidq);
484 icd->ops->stop_capture(icd);
489 static int soc_camera_queryctrl(struct file *file, void *priv,
490 struct v4l2_queryctrl *qc)
492 struct soc_camera_file *icf = file->private_data;
493 struct soc_camera_device *icd = icf->icd;
496 WARN_ON(priv != file->private_data);
501 for (i = 0; i < icd->ops->num_controls; i++)
502 if (qc->id == icd->ops->controls[i].id) {
503 memcpy(qc, &(icd->ops->controls[i]),
511 static int soc_camera_g_ctrl(struct file *file, void *priv,
512 struct v4l2_control *ctrl)
514 struct soc_camera_file *icf = file->private_data;
515 struct soc_camera_device *icd = icf->icd;
517 WARN_ON(priv != file->private_data);
521 if (icd->gain == (unsigned short)~0)
523 ctrl->value = icd->gain;
525 case V4L2_CID_EXPOSURE:
526 if (icd->exposure == (unsigned short)~0)
528 ctrl->value = icd->exposure;
532 if (icd->ops->get_control)
533 return icd->ops->get_control(icd, ctrl);
537 static int soc_camera_s_ctrl(struct file *file, void *priv,
538 struct v4l2_control *ctrl)
540 struct soc_camera_file *icf = file->private_data;
541 struct soc_camera_device *icd = icf->icd;
543 WARN_ON(priv != file->private_data);
545 if (icd->ops->set_control)
546 return icd->ops->set_control(icd, ctrl);
550 static int soc_camera_cropcap(struct file *file, void *fh,
551 struct v4l2_cropcap *a)
553 struct soc_camera_file *icf = file->private_data;
554 struct soc_camera_device *icd = icf->icd;
556 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
557 a->bounds.left = icd->x_min;
558 a->bounds.top = icd->y_min;
559 a->bounds.width = icd->width_max;
560 a->bounds.height = icd->height_max;
561 a->defrect.left = icd->x_min;
562 a->defrect.top = icd->y_min;
563 a->defrect.width = 640;
564 a->defrect.height = 480;
565 a->pixelaspect.numerator = 1;
566 a->pixelaspect.denominator = 1;
571 static int soc_camera_g_crop(struct file *file, void *fh,
574 struct soc_camera_file *icf = file->private_data;
575 struct soc_camera_device *icd = icf->icd;
577 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
578 a->c.left = icd->x_current;
579 a->c.top = icd->y_current;
580 a->c.width = icd->width;
581 a->c.height = icd->height;
586 static int soc_camera_s_crop(struct file *file, void *fh,
589 struct soc_camera_file *icf = file->private_data;
590 struct soc_camera_device *icd = icf->icd;
591 struct soc_camera_host *ici =
592 to_soc_camera_host(icd->dev.parent);
595 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
598 ret = ici->ops->set_fmt_cap(icd, 0, &a->c);
600 icd->width = a->c.width;
601 icd->height = a->c.height;
602 icd->x_current = a->c.left;
603 icd->y_current = a->c.top;
609 static int soc_camera_g_chip_ident(struct file *file, void *fh,
610 struct v4l2_chip_ident *id)
612 struct soc_camera_file *icf = file->private_data;
613 struct soc_camera_device *icd = icf->icd;
615 if (!icd->ops->get_chip_id)
618 return icd->ops->get_chip_id(icd, id);
621 #ifdef CONFIG_VIDEO_ADV_DEBUG
622 static int soc_camera_g_register(struct file *file, void *fh,
623 struct v4l2_register *reg)
625 struct soc_camera_file *icf = file->private_data;
626 struct soc_camera_device *icd = icf->icd;
628 if (!icd->ops->get_register)
631 return icd->ops->get_register(icd, reg);
634 static int soc_camera_s_register(struct file *file, void *fh,
635 struct v4l2_register *reg)
637 struct soc_camera_file *icf = file->private_data;
638 struct soc_camera_device *icd = icf->icd;
640 if (!icd->ops->set_register)
643 return icd->ops->set_register(icd, reg);
647 static int device_register_link(struct soc_camera_device *icd)
649 int ret = device_register(&icd->dev);
652 /* Prevent calling device_unregister() */
653 icd->dev.parent = NULL;
654 dev_err(&icd->dev, "Cannot register device: %d\n", ret);
655 /* Even if probe() was unsuccessful for all registered drivers,
656 * device_register() returns 0, and we add the link, just to
657 * document this camera's control device */
658 } else if (icd->control)
659 /* Have to sysfs_remove_link() before device_unregister()? */
660 if (sysfs_create_link(&icd->dev.kobj, &icd->control->kobj,
663 "Failed creating the control symlink\n");
667 /* So far this function cannot fail */
668 static void scan_add_host(struct soc_camera_host *ici)
670 struct soc_camera_device *icd;
672 mutex_lock(&list_lock);
674 list_for_each_entry(icd, &devices, list) {
675 if (icd->iface == ici->nr) {
676 icd->dev.parent = &ici->dev;
677 device_register_link(icd);
681 mutex_unlock(&list_lock);
684 /* return: 0 if no match found or a match found and
685 * device_register() successful, error code otherwise */
686 static int scan_add_device(struct soc_camera_device *icd)
688 struct soc_camera_host *ici;
691 mutex_lock(&list_lock);
693 list_add_tail(&icd->list, &devices);
695 /* Watch out for class_for_each_device / class_find_device API by
696 * Dave Young <hidave.darkstar@gmail.com> */
697 list_for_each_entry(ici, &hosts, list) {
698 if (icd->iface == ici->nr) {
700 icd->dev.parent = &ici->dev;
705 mutex_unlock(&list_lock);
708 ret = device_register_link(icd);
713 static int soc_camera_probe(struct device *dev)
715 struct soc_camera_device *icd = to_soc_camera_dev(dev);
716 struct soc_camera_host *ici =
717 to_soc_camera_host(icd->dev.parent);
720 if (!icd->ops->probe)
723 /* We only call ->add() here to activate and probe the camera.
724 * We shall ->remove() and deactivate it immediately afterwards. */
725 ret = ici->ops->add(icd);
729 ret = icd->ops->probe(icd);
731 const struct v4l2_queryctrl *qctrl;
733 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_GAIN);
734 icd->gain = qctrl ? qctrl->default_value : (unsigned short)~0;
735 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE);
736 icd->exposure = qctrl ? qctrl->default_value :
739 ici->ops->remove(icd);
744 /* This is called on device_unregister, which only means we have to disconnect
745 * from the host, but not remove ourselves from the device list */
746 static int soc_camera_remove(struct device *dev)
748 struct soc_camera_device *icd = to_soc_camera_dev(dev);
750 if (icd->ops->remove)
751 icd->ops->remove(icd);
756 static struct bus_type soc_camera_bus_type = {
757 .name = "soc-camera",
758 .probe = soc_camera_probe,
759 .remove = soc_camera_remove,
762 static struct device_driver ic_drv = {
764 .bus = &soc_camera_bus_type,
765 .owner = THIS_MODULE,
769 * Image capture host - this is a host device, not a bus device, so,
770 * no bus reference, no probing.
772 static struct class soc_camera_host_class = {
773 .owner = THIS_MODULE,
774 .name = "camera_host",
777 static void dummy_release(struct device *dev)
781 static spinlock_t *spinlock_alloc(struct soc_camera_file *icf)
783 spinlock_t *lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
786 spin_lock_init(lock);
791 static void spinlock_free(spinlock_t *lock)
796 int soc_camera_host_register(struct soc_camera_host *ici)
799 struct soc_camera_host *ix;
801 if (!ici->vbq_ops || !ici->ops->add || !ici->ops->remove)
804 /* Number might be equal to the platform device ID */
805 sprintf(ici->dev.bus_id, "camera_host%d", ici->nr);
806 ici->dev.class = &soc_camera_host_class;
808 mutex_lock(&list_lock);
809 list_for_each_entry(ix, &hosts, list) {
810 if (ix->nr == ici->nr) {
811 mutex_unlock(&list_lock);
816 list_add_tail(&ici->list, &hosts);
817 mutex_unlock(&list_lock);
819 ici->dev.release = dummy_release;
821 ret = device_register(&ici->dev);
826 if (!ici->ops->spinlock_alloc) {
827 ici->ops->spinlock_alloc = spinlock_alloc;
828 ici->ops->spinlock_free = spinlock_free;
836 mutex_lock(&list_lock);
837 list_del(&ici->list);
838 mutex_unlock(&list_lock);
842 EXPORT_SYMBOL(soc_camera_host_register);
844 /* Unregister all clients! */
845 void soc_camera_host_unregister(struct soc_camera_host *ici)
847 struct soc_camera_device *icd;
849 mutex_lock(&list_lock);
851 list_del(&ici->list);
853 list_for_each_entry(icd, &devices, list) {
854 if (icd->dev.parent == &ici->dev) {
855 device_unregister(&icd->dev);
856 /* Not before device_unregister(), .remove
857 * needs parent to call ici->ops->remove() */
858 icd->dev.parent = NULL;
859 memset(&icd->dev.kobj, 0, sizeof(icd->dev.kobj));
863 mutex_unlock(&list_lock);
865 device_unregister(&ici->dev);
867 EXPORT_SYMBOL(soc_camera_host_unregister);
869 /* Image capture device */
870 int soc_camera_device_register(struct soc_camera_device *icd)
872 struct soc_camera_device *ix;
878 for (i = 0; i < 256 && num < 0; i++) {
880 list_for_each_entry(ix, &devices, list) {
881 if (ix->iface == icd->iface && ix->devnum == i) {
889 /* ok, we have 256 cameras on this host...
890 * man, stay reasonable... */
894 icd->dev.bus = &soc_camera_bus_type;
895 snprintf(icd->dev.bus_id, sizeof(icd->dev.bus_id),
896 "%u-%u", icd->iface, icd->devnum);
898 icd->dev.release = dummy_release;
900 return scan_add_device(icd);
902 EXPORT_SYMBOL(soc_camera_device_register);
904 void soc_camera_device_unregister(struct soc_camera_device *icd)
906 mutex_lock(&list_lock);
907 list_del(&icd->list);
909 /* The bus->remove will be eventually called */
911 device_unregister(&icd->dev);
912 mutex_unlock(&list_lock);
914 EXPORT_SYMBOL(soc_camera_device_unregister);
916 int soc_camera_video_start(struct soc_camera_device *icd)
918 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
920 struct video_device *vdev;
922 if (!icd->dev.parent)
925 vdev = video_device_alloc();
928 dev_dbg(&ici->dev, "Allocated video_device %p\n", vdev);
930 strlcpy(vdev->name, ici->drv_name, sizeof(vdev->name));
931 /* Maybe better &ici->dev */
932 vdev->dev = &icd->dev;
933 vdev->type = VID_TYPE_CAPTURE;
934 vdev->current_norm = V4L2_STD_UNKNOWN;
935 vdev->fops = &soc_camera_fops;
936 vdev->release = video_device_release;
938 vdev->tvnorms = V4L2_STD_UNKNOWN,
939 vdev->vidioc_querycap = soc_camera_querycap;
940 vdev->vidioc_g_fmt_cap = soc_camera_g_fmt_cap;
941 vdev->vidioc_enum_fmt_cap = soc_camera_enum_fmt_cap;
942 vdev->vidioc_s_fmt_cap = soc_camera_s_fmt_cap;
943 vdev->vidioc_enum_input = soc_camera_enum_input;
944 vdev->vidioc_g_input = soc_camera_g_input;
945 vdev->vidioc_s_input = soc_camera_s_input;
946 vdev->vidioc_s_std = soc_camera_s_std;
947 vdev->vidioc_reqbufs = soc_camera_reqbufs;
948 vdev->vidioc_try_fmt_cap = soc_camera_try_fmt_cap;
949 vdev->vidioc_querybuf = soc_camera_querybuf;
950 vdev->vidioc_qbuf = soc_camera_qbuf;
951 vdev->vidioc_dqbuf = soc_camera_dqbuf;
952 vdev->vidioc_streamon = soc_camera_streamon;
953 vdev->vidioc_streamoff = soc_camera_streamoff;
954 vdev->vidioc_queryctrl = soc_camera_queryctrl;
955 vdev->vidioc_g_ctrl = soc_camera_g_ctrl;
956 vdev->vidioc_s_ctrl = soc_camera_s_ctrl;
957 vdev->vidioc_cropcap = soc_camera_cropcap;
958 vdev->vidioc_g_crop = soc_camera_g_crop;
959 vdev->vidioc_s_crop = soc_camera_s_crop;
960 vdev->vidioc_g_chip_ident = soc_camera_g_chip_ident;
961 #ifdef CONFIG_VIDEO_ADV_DEBUG
962 vdev->vidioc_g_register = soc_camera_g_register;
963 vdev->vidioc_s_register = soc_camera_s_register;
966 icd->current_fmt = &icd->formats[0];
968 err = video_register_device(vdev, VFL_TYPE_GRABBER, vdev->minor);
970 dev_err(vdev->dev, "video_register_device failed\n");
978 video_device_release(vdev);
982 EXPORT_SYMBOL(soc_camera_video_start);
984 void soc_camera_video_stop(struct soc_camera_device *icd)
986 struct video_device *vdev = icd->vdev;
988 dev_dbg(&icd->dev, "%s\n", __FUNCTION__);
990 if (!icd->dev.parent || !vdev)
993 mutex_lock(&video_lock);
994 video_unregister_device(vdev);
996 mutex_unlock(&video_lock);
998 EXPORT_SYMBOL(soc_camera_video_stop);
1000 static int __init soc_camera_init(void)
1002 int ret = bus_register(&soc_camera_bus_type);
1005 ret = driver_register(&ic_drv);
1008 ret = class_register(&soc_camera_host_class);
1015 driver_unregister(&ic_drv);
1017 bus_unregister(&soc_camera_bus_type);
1021 static void __exit soc_camera_exit(void)
1023 class_unregister(&soc_camera_host_class);
1024 driver_unregister(&ic_drv);
1025 bus_unregister(&soc_camera_bus_type);
1028 module_init(soc_camera_init);
1029 module_exit(soc_camera_exit);
1031 MODULE_DESCRIPTION("Image capture bus driver");
1032 MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
1033 MODULE_LICENSE("GPL");