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-ioctl.h>
29 #include <media/v4l2-dev.h>
30 #include <media/videobuf-core.h>
31 #include <media/soc_camera.h>
33 static LIST_HEAD(hosts);
34 static LIST_HEAD(devices);
35 static DEFINE_MUTEX(list_lock);
36 static DEFINE_MUTEX(video_lock);
38 const struct soc_camera_data_format *soc_camera_format_by_fourcc(
39 struct soc_camera_device *icd, unsigned int fourcc)
43 for (i = 0; i < icd->num_formats; i++)
44 if (icd->formats[i].fourcc == fourcc)
45 return icd->formats + i;
48 EXPORT_SYMBOL(soc_camera_format_by_fourcc);
50 static int soc_camera_try_fmt_vid_cap(struct file *file, void *priv,
51 struct v4l2_format *f)
53 struct soc_camera_file *icf = file->private_data;
54 struct soc_camera_device *icd = icf->icd;
55 struct soc_camera_host *ici =
56 to_soc_camera_host(icd->dev.parent);
57 enum v4l2_field field;
60 WARN_ON(priv != file->private_data);
63 * TODO: this might also have to migrate to host-drivers, if anyone
64 * wishes to support other fields
66 field = f->fmt.pix.field;
68 if (field == V4L2_FIELD_ANY) {
69 f->fmt.pix.field = V4L2_FIELD_NONE;
70 } else if (field != V4L2_FIELD_NONE) {
71 dev_err(&icd->dev, "Field type invalid.\n");
75 /* limit format to hardware capabilities */
76 ret = ici->ops->try_fmt_cap(icd, f);
81 static int soc_camera_enum_input(struct file *file, void *priv,
82 struct v4l2_input *inp)
87 inp->type = V4L2_INPUT_TYPE_CAMERA;
88 inp->std = V4L2_STD_UNKNOWN;
89 strcpy(inp->name, "Camera");
94 static int soc_camera_g_input(struct file *file, void *priv, unsigned int *i)
101 static int soc_camera_s_input(struct file *file, void *priv, unsigned int i)
109 static int soc_camera_s_std(struct file *file, void *priv, v4l2_std_id *a)
114 static int soc_camera_reqbufs(struct file *file, void *priv,
115 struct v4l2_requestbuffers *p)
118 struct soc_camera_file *icf = file->private_data;
119 struct soc_camera_device *icd = icf->icd;
120 struct soc_camera_host *ici =
121 to_soc_camera_host(icd->dev.parent);
123 WARN_ON(priv != file->private_data);
125 dev_dbg(&icd->dev, "%s: %d\n", __func__, p->memory);
127 ret = videobuf_reqbufs(&icf->vb_vidq, p);
131 return ici->ops->reqbufs(icf, p);
134 static int soc_camera_querybuf(struct file *file, void *priv,
135 struct v4l2_buffer *p)
137 struct soc_camera_file *icf = file->private_data;
139 WARN_ON(priv != file->private_data);
141 return videobuf_querybuf(&icf->vb_vidq, p);
144 static int soc_camera_qbuf(struct file *file, void *priv,
145 struct v4l2_buffer *p)
147 struct soc_camera_file *icf = file->private_data;
149 WARN_ON(priv != file->private_data);
151 return videobuf_qbuf(&icf->vb_vidq, p);
154 static int soc_camera_dqbuf(struct file *file, void *priv,
155 struct v4l2_buffer *p)
157 struct soc_camera_file *icf = file->private_data;
159 WARN_ON(priv != file->private_data);
161 return videobuf_dqbuf(&icf->vb_vidq, p, file->f_flags & O_NONBLOCK);
164 static int soc_camera_open(struct inode *inode, struct file *file)
166 struct video_device *vdev;
167 struct soc_camera_device *icd;
168 struct soc_camera_host *ici;
169 struct soc_camera_file *icf;
172 icf = vmalloc(sizeof(*icf));
176 /* Protect against icd->remove() until we module_get() both drivers. */
177 mutex_lock(&video_lock);
179 vdev = video_devdata(file);
180 icd = container_of(vdev->parent, struct soc_camera_device, dev);
181 ici = to_soc_camera_host(icd->dev.parent);
183 if (!try_module_get(icd->ops->owner)) {
184 dev_err(&icd->dev, "Couldn't lock sensor driver.\n");
189 if (!try_module_get(ici->ops->owner)) {
190 dev_err(&icd->dev, "Couldn't lock capture bus driver.\n");
198 /* Now we really have to activate the camera */
199 if (icd->use_count == 1) {
200 ret = ici->ops->add(icd);
202 dev_err(&icd->dev, "Couldn't activate the camera: %d\n", ret);
208 mutex_unlock(&video_lock);
210 file->private_data = icf;
211 dev_dbg(&icd->dev, "camera device open\n");
213 ici->ops->init_videobuf(&icf->vb_vidq, icd);
217 /* All errors are entered with the video_lock held */
219 module_put(ici->ops->owner);
221 module_put(icd->ops->owner);
223 mutex_unlock(&video_lock);
228 static int soc_camera_close(struct inode *inode, struct file *file)
230 struct soc_camera_file *icf = file->private_data;
231 struct soc_camera_device *icd = icf->icd;
232 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
233 struct video_device *vdev = icd->vdev;
235 mutex_lock(&video_lock);
238 ici->ops->remove(icd);
239 module_put(icd->ops->owner);
240 module_put(ici->ops->owner);
241 mutex_unlock(&video_lock);
245 dev_dbg(vdev->parent, "camera device close\n");
250 static ssize_t soc_camera_read(struct file *file, char __user *buf,
251 size_t count, loff_t *ppos)
253 struct soc_camera_file *icf = file->private_data;
254 struct soc_camera_device *icd = icf->icd;
255 struct video_device *vdev = icd->vdev;
258 dev_err(vdev->parent, "camera device read not implemented\n");
263 static int soc_camera_mmap(struct file *file, struct vm_area_struct *vma)
265 struct soc_camera_file *icf = file->private_data;
266 struct soc_camera_device *icd = icf->icd;
269 dev_dbg(&icd->dev, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
271 err = videobuf_mmap_mapper(&icf->vb_vidq, vma);
273 dev_dbg(&icd->dev, "vma start=0x%08lx, size=%ld, ret=%d\n",
274 (unsigned long)vma->vm_start,
275 (unsigned long)vma->vm_end - (unsigned long)vma->vm_start,
281 static unsigned int soc_camera_poll(struct file *file, poll_table *pt)
283 struct soc_camera_file *icf = file->private_data;
284 struct soc_camera_device *icd = icf->icd;
285 struct soc_camera_host *ici =
286 to_soc_camera_host(icd->dev.parent);
288 if (list_empty(&icf->vb_vidq.stream)) {
289 dev_err(&icd->dev, "Trying to poll with no queued buffers!\n");
293 return ici->ops->poll(file, pt);
296 static struct file_operations soc_camera_fops = {
297 .owner = THIS_MODULE,
298 .open = soc_camera_open,
299 .release = soc_camera_close,
300 .ioctl = video_ioctl2,
301 .read = soc_camera_read,
302 .mmap = soc_camera_mmap,
303 .poll = soc_camera_poll,
307 static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv,
308 struct v4l2_format *f)
310 struct soc_camera_file *icf = file->private_data;
311 struct soc_camera_device *icd = icf->icd;
312 struct soc_camera_host *ici =
313 to_soc_camera_host(icd->dev.parent);
315 struct v4l2_rect rect;
317 WARN_ON(priv != file->private_data);
319 ret = soc_camera_try_fmt_vid_cap(file, priv, f);
323 rect.left = icd->x_current;
324 rect.top = icd->y_current;
325 rect.width = f->fmt.pix.width;
326 rect.height = f->fmt.pix.height;
327 ret = ici->ops->set_fmt_cap(icd, f->fmt.pix.pixelformat, &rect);
330 } else if (!icd->current_fmt ||
331 icd->current_fmt->fourcc != f->fmt.pix.pixelformat) {
332 dev_err(&ici->dev, "Host driver hasn't set up current "
333 "format correctly!\n");
337 /* buswidth may be further adjusted by the ici */
338 icd->buswidth = icd->current_fmt->depth;
339 icd->width = rect.width;
340 icd->height = rect.height;
341 icf->vb_vidq.field = f->fmt.pix.field;
342 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
343 dev_warn(&icd->dev, "Attention! Wrong buf-type %d\n",
346 dev_dbg(&icd->dev, "set width: %d height: %d\n",
347 icd->width, icd->height);
349 /* set physical bus parameters */
350 return ici->ops->set_bus_param(icd, f->fmt.pix.pixelformat);
353 static int soc_camera_enum_fmt_vid_cap(struct file *file, void *priv,
354 struct v4l2_fmtdesc *f)
356 struct soc_camera_file *icf = file->private_data;
357 struct soc_camera_device *icd = icf->icd;
358 const struct soc_camera_data_format *format;
360 WARN_ON(priv != file->private_data);
362 if (f->index >= icd->num_formats)
365 format = &icd->formats[f->index];
367 strlcpy(f->description, format->name, sizeof(f->description));
368 f->pixelformat = format->fourcc;
372 static int soc_camera_g_fmt_vid_cap(struct file *file, void *priv,
373 struct v4l2_format *f)
375 struct soc_camera_file *icf = file->private_data;
376 struct soc_camera_device *icd = icf->icd;
378 WARN_ON(priv != file->private_data);
380 f->fmt.pix.width = icd->width;
381 f->fmt.pix.height = icd->height;
382 f->fmt.pix.field = icf->vb_vidq.field;
383 f->fmt.pix.pixelformat = icd->current_fmt->fourcc;
384 f->fmt.pix.bytesperline = f->fmt.pix.width *
385 DIV_ROUND_UP(icd->current_fmt->depth, 8);
386 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
387 dev_dbg(&icd->dev, "current_fmt->fourcc: 0x%08x\n",
388 icd->current_fmt->fourcc);
392 static int soc_camera_querycap(struct file *file, void *priv,
393 struct v4l2_capability *cap)
395 struct soc_camera_file *icf = file->private_data;
396 struct soc_camera_device *icd = icf->icd;
397 struct soc_camera_host *ici =
398 to_soc_camera_host(icd->dev.parent);
400 WARN_ON(priv != file->private_data);
402 strlcpy(cap->driver, ici->drv_name, sizeof(cap->driver));
403 return ici->ops->querycap(ici, cap);
406 static int soc_camera_streamon(struct file *file, void *priv,
407 enum v4l2_buf_type i)
409 struct soc_camera_file *icf = file->private_data;
410 struct soc_camera_device *icd = icf->icd;
412 WARN_ON(priv != file->private_data);
414 dev_dbg(&icd->dev, "%s\n", __func__);
416 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
419 icd->ops->start_capture(icd);
421 /* This calls buf_queue from host driver's videobuf_queue_ops */
422 return videobuf_streamon(&icf->vb_vidq);
425 static int soc_camera_streamoff(struct file *file, void *priv,
426 enum v4l2_buf_type i)
428 struct soc_camera_file *icf = file->private_data;
429 struct soc_camera_device *icd = icf->icd;
431 WARN_ON(priv != file->private_data);
433 dev_dbg(&icd->dev, "%s\n", __func__);
435 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
438 /* This calls buf_release from host driver's videobuf_queue_ops for all
439 * remaining buffers. When the last buffer is freed, stop capture */
440 videobuf_streamoff(&icf->vb_vidq);
442 icd->ops->stop_capture(icd);
447 static int soc_camera_queryctrl(struct file *file, void *priv,
448 struct v4l2_queryctrl *qc)
450 struct soc_camera_file *icf = file->private_data;
451 struct soc_camera_device *icd = icf->icd;
454 WARN_ON(priv != file->private_data);
459 for (i = 0; i < icd->ops->num_controls; i++)
460 if (qc->id == icd->ops->controls[i].id) {
461 memcpy(qc, &(icd->ops->controls[i]),
469 static int soc_camera_g_ctrl(struct file *file, void *priv,
470 struct v4l2_control *ctrl)
472 struct soc_camera_file *icf = file->private_data;
473 struct soc_camera_device *icd = icf->icd;
475 WARN_ON(priv != file->private_data);
479 if (icd->gain == (unsigned short)~0)
481 ctrl->value = icd->gain;
483 case V4L2_CID_EXPOSURE:
484 if (icd->exposure == (unsigned short)~0)
486 ctrl->value = icd->exposure;
490 if (icd->ops->get_control)
491 return icd->ops->get_control(icd, ctrl);
495 static int soc_camera_s_ctrl(struct file *file, void *priv,
496 struct v4l2_control *ctrl)
498 struct soc_camera_file *icf = file->private_data;
499 struct soc_camera_device *icd = icf->icd;
501 WARN_ON(priv != file->private_data);
503 if (icd->ops->set_control)
504 return icd->ops->set_control(icd, ctrl);
508 static int soc_camera_cropcap(struct file *file, void *fh,
509 struct v4l2_cropcap *a)
511 struct soc_camera_file *icf = file->private_data;
512 struct soc_camera_device *icd = icf->icd;
514 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
515 a->bounds.left = icd->x_min;
516 a->bounds.top = icd->y_min;
517 a->bounds.width = icd->width_max;
518 a->bounds.height = icd->height_max;
519 a->defrect.left = icd->x_min;
520 a->defrect.top = icd->y_min;
521 a->defrect.width = 640;
522 a->defrect.height = 480;
523 a->pixelaspect.numerator = 1;
524 a->pixelaspect.denominator = 1;
529 static int soc_camera_g_crop(struct file *file, void *fh,
532 struct soc_camera_file *icf = file->private_data;
533 struct soc_camera_device *icd = icf->icd;
535 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
536 a->c.left = icd->x_current;
537 a->c.top = icd->y_current;
538 a->c.width = icd->width;
539 a->c.height = icd->height;
544 static int soc_camera_s_crop(struct file *file, void *fh,
547 struct soc_camera_file *icf = file->private_data;
548 struct soc_camera_device *icd = icf->icd;
549 struct soc_camera_host *ici =
550 to_soc_camera_host(icd->dev.parent);
553 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
556 ret = ici->ops->set_fmt_cap(icd, 0, &a->c);
558 icd->width = a->c.width;
559 icd->height = a->c.height;
560 icd->x_current = a->c.left;
561 icd->y_current = a->c.top;
567 static int soc_camera_g_chip_ident(struct file *file, void *fh,
568 struct v4l2_chip_ident *id)
570 struct soc_camera_file *icf = file->private_data;
571 struct soc_camera_device *icd = icf->icd;
573 if (!icd->ops->get_chip_id)
576 return icd->ops->get_chip_id(icd, id);
579 #ifdef CONFIG_VIDEO_ADV_DEBUG
580 static int soc_camera_g_register(struct file *file, void *fh,
581 struct v4l2_register *reg)
583 struct soc_camera_file *icf = file->private_data;
584 struct soc_camera_device *icd = icf->icd;
586 if (!icd->ops->get_register)
589 return icd->ops->get_register(icd, reg);
592 static int soc_camera_s_register(struct file *file, void *fh,
593 struct v4l2_register *reg)
595 struct soc_camera_file *icf = file->private_data;
596 struct soc_camera_device *icd = icf->icd;
598 if (!icd->ops->set_register)
601 return icd->ops->set_register(icd, reg);
605 static int device_register_link(struct soc_camera_device *icd)
607 int ret = device_register(&icd->dev);
610 /* Prevent calling device_unregister() */
611 icd->dev.parent = NULL;
612 dev_err(&icd->dev, "Cannot register device: %d\n", ret);
613 /* Even if probe() was unsuccessful for all registered drivers,
614 * device_register() returns 0, and we add the link, just to
615 * document this camera's control device */
616 } else if (icd->control)
617 /* Have to sysfs_remove_link() before device_unregister()? */
618 if (sysfs_create_link(&icd->dev.kobj, &icd->control->kobj,
621 "Failed creating the control symlink\n");
625 /* So far this function cannot fail */
626 static void scan_add_host(struct soc_camera_host *ici)
628 struct soc_camera_device *icd;
630 mutex_lock(&list_lock);
632 list_for_each_entry(icd, &devices, list) {
633 if (icd->iface == ici->nr) {
634 icd->dev.parent = &ici->dev;
635 device_register_link(icd);
639 mutex_unlock(&list_lock);
642 /* return: 0 if no match found or a match found and
643 * device_register() successful, error code otherwise */
644 static int scan_add_device(struct soc_camera_device *icd)
646 struct soc_camera_host *ici;
649 mutex_lock(&list_lock);
651 list_add_tail(&icd->list, &devices);
653 /* Watch out for class_for_each_device / class_find_device API by
654 * Dave Young <hidave.darkstar@gmail.com> */
655 list_for_each_entry(ici, &hosts, list) {
656 if (icd->iface == ici->nr) {
658 icd->dev.parent = &ici->dev;
663 mutex_unlock(&list_lock);
666 ret = device_register_link(icd);
671 static int soc_camera_probe(struct device *dev)
673 struct soc_camera_device *icd = to_soc_camera_dev(dev);
674 struct soc_camera_host *ici =
675 to_soc_camera_host(icd->dev.parent);
678 if (!icd->ops->probe)
681 /* We only call ->add() here to activate and probe the camera.
682 * We shall ->remove() and deactivate it immediately afterwards. */
683 ret = ici->ops->add(icd);
687 ret = icd->ops->probe(icd);
689 const struct v4l2_queryctrl *qctrl;
691 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_GAIN);
692 icd->gain = qctrl ? qctrl->default_value : (unsigned short)~0;
693 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE);
694 icd->exposure = qctrl ? qctrl->default_value :
697 ici->ops->remove(icd);
702 /* This is called on device_unregister, which only means we have to disconnect
703 * from the host, but not remove ourselves from the device list */
704 static int soc_camera_remove(struct device *dev)
706 struct soc_camera_device *icd = to_soc_camera_dev(dev);
708 if (icd->ops->remove)
709 icd->ops->remove(icd);
714 static int soc_camera_suspend(struct device *dev, pm_message_t state)
716 struct soc_camera_device *icd = to_soc_camera_dev(dev);
717 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
720 if (ici->ops->suspend)
721 ret = ici->ops->suspend(icd, state);
726 static int soc_camera_resume(struct device *dev)
728 struct soc_camera_device *icd = to_soc_camera_dev(dev);
729 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
732 if (ici->ops->resume)
733 ret = ici->ops->resume(icd);
738 static struct bus_type soc_camera_bus_type = {
739 .name = "soc-camera",
740 .probe = soc_camera_probe,
741 .remove = soc_camera_remove,
742 .suspend = soc_camera_suspend,
743 .resume = soc_camera_resume,
746 static struct device_driver ic_drv = {
748 .bus = &soc_camera_bus_type,
749 .owner = THIS_MODULE,
752 static void dummy_release(struct device *dev)
756 int soc_camera_host_register(struct soc_camera_host *ici)
759 struct soc_camera_host *ix;
761 if (!ici->ops->init_videobuf || !ici->ops->add || !ici->ops->remove)
764 /* Number might be equal to the platform device ID */
765 dev_set_name(&ici->dev, "camera_host%d", ici->nr);
767 mutex_lock(&list_lock);
768 list_for_each_entry(ix, &hosts, list) {
769 if (ix->nr == ici->nr) {
770 mutex_unlock(&list_lock);
775 list_add_tail(&ici->list, &hosts);
776 mutex_unlock(&list_lock);
778 ici->dev.release = dummy_release;
780 ret = device_register(&ici->dev);
790 mutex_lock(&list_lock);
791 list_del(&ici->list);
792 mutex_unlock(&list_lock);
796 EXPORT_SYMBOL(soc_camera_host_register);
798 /* Unregister all clients! */
799 void soc_camera_host_unregister(struct soc_camera_host *ici)
801 struct soc_camera_device *icd;
803 mutex_lock(&list_lock);
805 list_del(&ici->list);
807 list_for_each_entry(icd, &devices, list) {
808 if (icd->dev.parent == &ici->dev) {
809 device_unregister(&icd->dev);
810 /* Not before device_unregister(), .remove
811 * needs parent to call ici->ops->remove() */
812 icd->dev.parent = NULL;
813 memset(&icd->dev.kobj, 0, sizeof(icd->dev.kobj));
817 mutex_unlock(&list_lock);
819 device_unregister(&ici->dev);
821 EXPORT_SYMBOL(soc_camera_host_unregister);
823 /* Image capture device */
824 int soc_camera_device_register(struct soc_camera_device *icd)
826 struct soc_camera_device *ix;
832 for (i = 0; i < 256 && num < 0; i++) {
834 list_for_each_entry(ix, &devices, list) {
835 if (ix->iface == icd->iface && ix->devnum == i) {
843 /* ok, we have 256 cameras on this host...
844 * man, stay reasonable... */
848 icd->dev.bus = &soc_camera_bus_type;
849 dev_set_name(&icd->dev, "%u-%u", icd->iface, icd->devnum);
851 icd->dev.release = dummy_release;
853 return scan_add_device(icd);
855 EXPORT_SYMBOL(soc_camera_device_register);
857 void soc_camera_device_unregister(struct soc_camera_device *icd)
859 mutex_lock(&list_lock);
860 list_del(&icd->list);
862 /* The bus->remove will be eventually called */
864 device_unregister(&icd->dev);
865 mutex_unlock(&list_lock);
867 EXPORT_SYMBOL(soc_camera_device_unregister);
869 static const struct v4l2_ioctl_ops soc_camera_ioctl_ops = {
870 .vidioc_querycap = soc_camera_querycap,
871 .vidioc_g_fmt_vid_cap = soc_camera_g_fmt_vid_cap,
872 .vidioc_enum_fmt_vid_cap = soc_camera_enum_fmt_vid_cap,
873 .vidioc_s_fmt_vid_cap = soc_camera_s_fmt_vid_cap,
874 .vidioc_enum_input = soc_camera_enum_input,
875 .vidioc_g_input = soc_camera_g_input,
876 .vidioc_s_input = soc_camera_s_input,
877 .vidioc_s_std = soc_camera_s_std,
878 .vidioc_reqbufs = soc_camera_reqbufs,
879 .vidioc_try_fmt_vid_cap = soc_camera_try_fmt_vid_cap,
880 .vidioc_querybuf = soc_camera_querybuf,
881 .vidioc_qbuf = soc_camera_qbuf,
882 .vidioc_dqbuf = soc_camera_dqbuf,
883 .vidioc_streamon = soc_camera_streamon,
884 .vidioc_streamoff = soc_camera_streamoff,
885 .vidioc_queryctrl = soc_camera_queryctrl,
886 .vidioc_g_ctrl = soc_camera_g_ctrl,
887 .vidioc_s_ctrl = soc_camera_s_ctrl,
888 .vidioc_cropcap = soc_camera_cropcap,
889 .vidioc_g_crop = soc_camera_g_crop,
890 .vidioc_s_crop = soc_camera_s_crop,
891 .vidioc_g_chip_ident = soc_camera_g_chip_ident,
892 #ifdef CONFIG_VIDEO_ADV_DEBUG
893 .vidioc_g_register = soc_camera_g_register,
894 .vidioc_s_register = soc_camera_s_register,
898 int soc_camera_video_start(struct soc_camera_device *icd)
900 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
902 struct video_device *vdev;
904 if (!icd->dev.parent)
907 vdev = video_device_alloc();
910 dev_dbg(&ici->dev, "Allocated video_device %p\n", vdev);
912 strlcpy(vdev->name, ici->drv_name, sizeof(vdev->name));
913 /* Maybe better &ici->dev */
914 vdev->parent = &icd->dev;
915 vdev->current_norm = V4L2_STD_UNKNOWN;
916 vdev->fops = &soc_camera_fops;
917 vdev->ioctl_ops = &soc_camera_ioctl_ops;
918 vdev->release = video_device_release;
920 vdev->tvnorms = V4L2_STD_UNKNOWN,
922 icd->current_fmt = &icd->formats[0];
924 err = video_register_device(vdev, VFL_TYPE_GRABBER, vdev->minor);
926 dev_err(vdev->parent, "video_register_device failed\n");
934 video_device_release(vdev);
938 EXPORT_SYMBOL(soc_camera_video_start);
940 void soc_camera_video_stop(struct soc_camera_device *icd)
942 struct video_device *vdev = icd->vdev;
944 dev_dbg(&icd->dev, "%s\n", __func__);
946 if (!icd->dev.parent || !vdev)
949 mutex_lock(&video_lock);
950 video_unregister_device(vdev);
952 mutex_unlock(&video_lock);
954 EXPORT_SYMBOL(soc_camera_video_stop);
956 static int __init soc_camera_init(void)
958 int ret = bus_register(&soc_camera_bus_type);
961 ret = driver_register(&ic_drv);
968 bus_unregister(&soc_camera_bus_type);
972 static void __exit soc_camera_exit(void)
974 driver_unregister(&ic_drv);
975 bus_unregister(&soc_camera_bus_type);
978 module_init(soc_camera_init);
979 module_exit(soc_camera_exit);
981 MODULE_DESCRIPTION("Image capture bus driver");
982 MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
983 MODULE_LICENSE("GPL");