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 /* test physical bus parameters */
79 ret
= ici
->try_bus_param(icd
, f
->fmt
.pix
.pixelformat
);
83 /* limit format to hardware capabilities */
84 ret
= ici
->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
->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
;
189 icf
= vmalloc(sizeof(*icf
));
193 /* Protect against icd->remove() until we module_get() both drivers. */
194 mutex_lock(&video_lock
);
196 vdev
= video_devdata(file
);
197 icd
= container_of(vdev
->dev
, struct soc_camera_device
, dev
);
198 ici
= to_soc_camera_host(icd
->dev
.parent
);
200 if (!try_module_get(icd
->ops
->owner
)) {
201 dev_err(&icd
->dev
, "Couldn't lock sensor driver.\n");
206 if (!try_module_get(ici
->owner
)) {
207 dev_err(&icd
->dev
, "Couldn't lock capture bus driver.\n");
216 /* Now we really have to activate the camera */
217 if (icd
->use_count
== 1) {
220 dev_err(&icd
->dev
, "Couldn't activate the camera: %d\n", ret
);
226 mutex_unlock(&video_lock
);
228 file
->private_data
= icf
;
229 dev_dbg(&icd
->dev
, "camera device open\n");
231 /* We must pass NULL as dev pointer, then all pci_* dma operations
232 * transform to normal dma_* ones. Do we need an irqlock? */
233 videobuf_queue_sg_init(&icf
->vb_vidq
, ici
->vbq_ops
, NULL
, NULL
,
234 V4L2_BUF_TYPE_VIDEO_CAPTURE
, V4L2_FIELD_NONE
,
239 /* All errors are entered with the video_lock held */
241 module_put(ici
->owner
);
243 module_put(icd
->ops
->owner
);
245 mutex_unlock(&video_lock
);
250 static int soc_camera_close(struct inode
*inode
, struct file
*file
)
252 struct soc_camera_file
*icf
= file
->private_data
;
253 struct soc_camera_device
*icd
= icf
->icd
;
254 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
255 struct video_device
*vdev
= icd
->vdev
;
257 mutex_lock(&video_lock
);
261 module_put(icd
->ops
->owner
);
262 module_put(ici
->owner
);
263 mutex_unlock(&video_lock
);
265 vfree(file
->private_data
);
267 dev_dbg(vdev
->dev
, "camera device close\n");
272 static int soc_camera_read(struct file
*file
, char __user
*buf
,
273 size_t count
, loff_t
*ppos
)
275 struct soc_camera_file
*icf
= file
->private_data
;
276 struct soc_camera_device
*icd
= icf
->icd
;
277 struct video_device
*vdev
= icd
->vdev
;
280 dev_err(vdev
->dev
, "camera device read not implemented\n");
285 static int soc_camera_mmap(struct file
*file
, struct vm_area_struct
*vma
)
287 struct soc_camera_file
*icf
= file
->private_data
;
288 struct soc_camera_device
*icd
= icf
->icd
;
291 dev_dbg(&icd
->dev
, "mmap called, vma=0x%08lx\n", (unsigned long)vma
);
293 err
= videobuf_mmap_mapper(&icf
->vb_vidq
, vma
);
295 dev_dbg(&icd
->dev
, "vma start=0x%08lx, size=%ld, ret=%d\n",
296 (unsigned long)vma
->vm_start
,
297 (unsigned long)vma
->vm_end
- (unsigned long)vma
->vm_start
,
303 static unsigned int soc_camera_poll(struct file
*file
, poll_table
*pt
)
305 struct soc_camera_file
*icf
= file
->private_data
;
306 struct soc_camera_device
*icd
= icf
->icd
;
307 struct soc_camera_host
*ici
=
308 to_soc_camera_host(icd
->dev
.parent
);
310 if (list_empty(&icf
->vb_vidq
.stream
)) {
311 dev_err(&icd
->dev
, "Trying to poll with no queued buffers!\n");
315 return ici
->poll(file
, pt
);
319 static struct file_operations soc_camera_fops
= {
320 .owner
= THIS_MODULE
,
321 .open
= soc_camera_open
,
322 .release
= soc_camera_close
,
323 .ioctl
= video_ioctl2
,
324 .read
= soc_camera_read
,
325 .mmap
= soc_camera_mmap
,
326 .poll
= soc_camera_poll
,
331 static int soc_camera_s_fmt_cap(struct file
*file
, void *priv
,
332 struct v4l2_format
*f
)
334 struct soc_camera_file
*icf
= file
->private_data
;
335 struct soc_camera_device
*icd
= icf
->icd
;
336 struct soc_camera_host
*ici
=
337 to_soc_camera_host(icd
->dev
.parent
);
339 struct v4l2_rect rect
;
340 const static struct soc_camera_data_format
*data_fmt
;
342 WARN_ON(priv
!= file
->private_data
);
344 data_fmt
= format_by_fourcc(icd
, f
->fmt
.pix
.pixelformat
);
348 /* buswidth may be further adjusted by the ici */
349 icd
->buswidth
= data_fmt
->depth
;
351 ret
= soc_camera_try_fmt_cap(file
, icf
, f
);
355 rect
.left
= icd
->x_current
;
356 rect
.top
= icd
->y_current
;
357 rect
.width
= f
->fmt
.pix
.width
;
358 rect
.height
= f
->fmt
.pix
.height
;
359 ret
= ici
->set_fmt_cap(icd
, f
->fmt
.pix
.pixelformat
, &rect
);
363 icd
->current_fmt
= data_fmt
;
364 icd
->width
= rect
.width
;
365 icd
->height
= rect
.height
;
366 icf
->vb_vidq
.field
= f
->fmt
.pix
.field
;
367 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= f
->type
)
368 dev_warn(&icd
->dev
, "Attention! Wrong buf-type %d\n",
371 dev_dbg(&icd
->dev
, "set width: %d height: %d\n",
372 icd
->width
, icd
->height
);
374 /* set physical bus parameters */
375 return ici
->set_bus_param(icd
, f
->fmt
.pix
.pixelformat
);
378 static int soc_camera_enum_fmt_cap(struct file
*file
, void *priv
,
379 struct v4l2_fmtdesc
*f
)
381 struct soc_camera_file
*icf
= file
->private_data
;
382 struct soc_camera_device
*icd
= icf
->icd
;
383 const struct soc_camera_data_format
*format
;
385 WARN_ON(priv
!= file
->private_data
);
387 if (f
->index
>= icd
->ops
->num_formats
)
390 format
= &icd
->ops
->formats
[f
->index
];
392 strlcpy(f
->description
, format
->name
, sizeof(f
->description
));
393 f
->pixelformat
= format
->fourcc
;
397 static int soc_camera_g_fmt_cap(struct file
*file
, void *priv
,
398 struct v4l2_format
*f
)
400 struct soc_camera_file
*icf
= file
->private_data
;
401 struct soc_camera_device
*icd
= icf
->icd
;
403 WARN_ON(priv
!= file
->private_data
);
405 f
->fmt
.pix
.width
= icd
->width
;
406 f
->fmt
.pix
.height
= icd
->height
;
407 f
->fmt
.pix
.field
= icf
->vb_vidq
.field
;
408 f
->fmt
.pix
.pixelformat
= icd
->current_fmt
->fourcc
;
409 f
->fmt
.pix
.bytesperline
=
410 (f
->fmt
.pix
.width
* icd
->current_fmt
->depth
) >> 3;
411 f
->fmt
.pix
.sizeimage
=
412 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
413 dev_dbg(&icd
->dev
, "current_fmt->fourcc: 0x%08x\n",
414 icd
->current_fmt
->fourcc
);
418 static int soc_camera_querycap(struct file
*file
, void *priv
,
419 struct v4l2_capability
*cap
)
421 struct soc_camera_file
*icf
= file
->private_data
;
422 struct soc_camera_device
*icd
= icf
->icd
;
423 struct soc_camera_host
*ici
=
424 to_soc_camera_host(icd
->dev
.parent
);
426 WARN_ON(priv
!= file
->private_data
);
428 strlcpy(cap
->driver
, ici
->drv_name
, sizeof(cap
->driver
));
429 return ici
->querycap(ici
, cap
);
432 static int soc_camera_streamon(struct file
*file
, void *priv
,
433 enum v4l2_buf_type i
)
435 struct soc_camera_file
*icf
= file
->private_data
;
436 struct soc_camera_device
*icd
= icf
->icd
;
438 WARN_ON(priv
!= file
->private_data
);
440 dev_dbg(&icd
->dev
, "%s\n", __FUNCTION__
);
442 if (i
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
445 icd
->ops
->start_capture(icd
);
447 /* This calls buf_queue from host driver's videobuf_queue_ops */
448 return videobuf_streamon(&icf
->vb_vidq
);
451 static int soc_camera_streamoff(struct file
*file
, void *priv
,
452 enum v4l2_buf_type i
)
454 struct soc_camera_file
*icf
= file
->private_data
;
455 struct soc_camera_device
*icd
= icf
->icd
;
457 WARN_ON(priv
!= file
->private_data
);
459 dev_dbg(&icd
->dev
, "%s\n", __FUNCTION__
);
461 if (i
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
464 /* This calls buf_release from host driver's videobuf_queue_ops for all
465 * remaining buffers. When the last buffer is freed, stop capture */
466 videobuf_streamoff(&icf
->vb_vidq
);
468 icd
->ops
->stop_capture(icd
);
473 static int soc_camera_queryctrl(struct file
*file
, void *priv
,
474 struct v4l2_queryctrl
*qc
)
476 struct soc_camera_file
*icf
= file
->private_data
;
477 struct soc_camera_device
*icd
= icf
->icd
;
480 WARN_ON(priv
!= file
->private_data
);
485 for (i
= 0; i
< icd
->ops
->num_controls
; i
++)
486 if (qc
->id
== icd
->ops
->controls
[i
].id
) {
487 memcpy(qc
, &(icd
->ops
->controls
[i
]),
495 static int soc_camera_g_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
);
505 if (icd
->gain
== (unsigned short)~0)
507 ctrl
->value
= icd
->gain
;
509 case V4L2_CID_EXPOSURE
:
510 if (icd
->exposure
== (unsigned short)~0)
512 ctrl
->value
= icd
->exposure
;
516 if (icd
->ops
->get_control
)
517 return icd
->ops
->get_control(icd
, ctrl
);
521 static int soc_camera_s_ctrl(struct file
*file
, void *priv
,
522 struct v4l2_control
*ctrl
)
524 struct soc_camera_file
*icf
= file
->private_data
;
525 struct soc_camera_device
*icd
= icf
->icd
;
527 WARN_ON(priv
!= file
->private_data
);
529 if (icd
->ops
->set_control
)
530 return icd
->ops
->set_control(icd
, ctrl
);
534 static int soc_camera_cropcap(struct file
*file
, void *fh
,
535 struct v4l2_cropcap
*a
)
537 struct soc_camera_file
*icf
= file
->private_data
;
538 struct soc_camera_device
*icd
= icf
->icd
;
540 a
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
541 a
->bounds
.left
= icd
->x_min
;
542 a
->bounds
.top
= icd
->y_min
;
543 a
->bounds
.width
= icd
->width_max
;
544 a
->bounds
.height
= icd
->height_max
;
545 a
->defrect
.left
= icd
->x_min
;
546 a
->defrect
.top
= icd
->y_min
;
547 a
->defrect
.width
= 640;
548 a
->defrect
.height
= 480;
549 a
->pixelaspect
.numerator
= 1;
550 a
->pixelaspect
.denominator
= 1;
555 static int soc_camera_g_crop(struct file
*file
, void *fh
,
558 struct soc_camera_file
*icf
= file
->private_data
;
559 struct soc_camera_device
*icd
= icf
->icd
;
561 a
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
562 a
->c
.left
= icd
->x_current
;
563 a
->c
.top
= icd
->y_current
;
564 a
->c
.width
= icd
->width
;
565 a
->c
.height
= icd
->height
;
570 static int soc_camera_s_crop(struct file
*file
, void *fh
,
573 struct soc_camera_file
*icf
= file
->private_data
;
574 struct soc_camera_device
*icd
= icf
->icd
;
575 struct soc_camera_host
*ici
=
576 to_soc_camera_host(icd
->dev
.parent
);
579 if (a
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
582 ret
= ici
->set_fmt_cap(icd
, 0, &a
->c
);
584 icd
->width
= a
->c
.width
;
585 icd
->height
= a
->c
.height
;
586 icd
->x_current
= a
->c
.left
;
587 icd
->y_current
= a
->c
.top
;
593 static int soc_camera_g_chip_ident(struct file
*file
, void *fh
,
594 struct v4l2_chip_ident
*id
)
596 struct soc_camera_file
*icf
= file
->private_data
;
597 struct soc_camera_device
*icd
= icf
->icd
;
599 if (!icd
->ops
->get_chip_id
)
602 return icd
->ops
->get_chip_id(icd
, id
);
605 #ifdef CONFIG_VIDEO_ADV_DEBUG
606 static int soc_camera_g_register(struct file
*file
, void *fh
,
607 struct v4l2_register
*reg
)
609 struct soc_camera_file
*icf
= file
->private_data
;
610 struct soc_camera_device
*icd
= icf
->icd
;
612 if (!icd
->ops
->get_register
)
615 return icd
->ops
->get_register(icd
, reg
);
618 static int soc_camera_s_register(struct file
*file
, void *fh
,
619 struct v4l2_register
*reg
)
621 struct soc_camera_file
*icf
= file
->private_data
;
622 struct soc_camera_device
*icd
= icf
->icd
;
624 if (!icd
->ops
->set_register
)
627 return icd
->ops
->set_register(icd
, reg
);
631 static int device_register_link(struct soc_camera_device
*icd
)
633 int ret
= device_register(&icd
->dev
);
636 /* Prevent calling device_unregister() */
637 icd
->dev
.parent
= NULL
;
638 dev_err(&icd
->dev
, "Cannot register device: %d\n", ret
);
639 /* Even if probe() was unsuccessful for all registered drivers,
640 * device_register() returns 0, and we add the link, just to
641 * document this camera's control device */
642 } else if (icd
->control
)
643 /* Have to sysfs_remove_link() before device_unregister()? */
644 if (sysfs_create_link(&icd
->dev
.kobj
, &icd
->control
->kobj
,
647 "Failed creating the control symlink\n");
651 /* So far this function cannot fail */
652 static void scan_add_host(struct soc_camera_host
*ici
)
654 struct soc_camera_device
*icd
;
656 mutex_lock(&list_lock
);
658 list_for_each_entry(icd
, &devices
, list
) {
659 if (icd
->iface
== ici
->nr
) {
660 icd
->dev
.parent
= &ici
->dev
;
661 device_register_link(icd
);
665 mutex_unlock(&list_lock
);
668 /* return: 0 if no match found or a match found and
669 * device_register() successful, error code otherwise */
670 static int scan_add_device(struct soc_camera_device
*icd
)
672 struct soc_camera_host
*ici
;
675 mutex_lock(&list_lock
);
677 list_add_tail(&icd
->list
, &devices
);
679 /* Watch out for class_for_each_device / class_find_device API by
680 * Dave Young <hidave.darkstar@gmail.com> */
681 list_for_each_entry(ici
, &hosts
, list
) {
682 if (icd
->iface
== ici
->nr
) {
684 icd
->dev
.parent
= &ici
->dev
;
689 mutex_unlock(&list_lock
);
692 ret
= device_register_link(icd
);
697 static int soc_camera_probe(struct device
*dev
)
699 struct soc_camera_device
*icd
= to_soc_camera_dev(dev
);
700 struct soc_camera_host
*ici
=
701 to_soc_camera_host(icd
->dev
.parent
);
707 /* We only call ->add() here to activate and probe the camera.
708 * We shall ->remove() and deactivate it immediately afterwards. */
713 ret
= icd
->probe(icd
);
715 const struct v4l2_queryctrl
*qctrl
;
717 qctrl
= soc_camera_find_qctrl(icd
->ops
, V4L2_CID_GAIN
);
718 icd
->gain
= qctrl
? qctrl
->default_value
: (unsigned short)~0;
719 qctrl
= soc_camera_find_qctrl(icd
->ops
, V4L2_CID_EXPOSURE
);
720 icd
->exposure
= qctrl
? qctrl
->default_value
:
728 /* This is called on device_unregister, which only means we have to disconnect
729 * from the host, but not remove ourselves from the device list */
730 static int soc_camera_remove(struct device
*dev
)
732 struct soc_camera_device
*icd
= to_soc_camera_dev(dev
);
740 static struct bus_type soc_camera_bus_type
= {
741 .name
= "soc-camera",
742 .probe
= soc_camera_probe
,
743 .remove
= soc_camera_remove
,
746 static struct device_driver ic_drv
= {
748 .bus
= &soc_camera_bus_type
,
749 .owner
= THIS_MODULE
,
753 * Image capture host - this is a host device, not a bus device, so,
754 * no bus reference, no probing.
756 static struct class soc_camera_host_class
= {
757 .owner
= THIS_MODULE
,
758 .name
= "camera_host",
761 static void dummy_release(struct device
*dev
)
765 int soc_camera_host_register(struct soc_camera_host
*ici
, struct module
*owner
)
768 struct soc_camera_host
*ix
;
770 if (!ici
->vbq_ops
|| !ici
->add
|| !ici
->remove
|| !owner
)
773 /* Number might be equal to the platform device ID */
774 sprintf(ici
->dev
.bus_id
, "camera_host%d", ici
->nr
);
775 ici
->dev
.class = &soc_camera_host_class
;
777 mutex_lock(&list_lock
);
778 list_for_each_entry(ix
, &hosts
, list
) {
779 if (ix
->nr
== ici
->nr
) {
780 mutex_unlock(&list_lock
);
785 list_add_tail(&ici
->list
, &hosts
);
786 mutex_unlock(&list_lock
);
789 ici
->dev
.release
= dummy_release
;
791 ret
= device_register(&ici
->dev
);
801 mutex_lock(&list_lock
);
802 list_del(&ici
->list
);
803 mutex_unlock(&list_lock
);
807 EXPORT_SYMBOL(soc_camera_host_register
);
809 /* Unregister all clients! */
810 void soc_camera_host_unregister(struct soc_camera_host
*ici
)
812 struct soc_camera_device
*icd
;
814 mutex_lock(&list_lock
);
816 list_del(&ici
->list
);
818 list_for_each_entry(icd
, &devices
, list
) {
819 if (icd
->dev
.parent
== &ici
->dev
) {
820 device_unregister(&icd
->dev
);
821 /* Not before device_unregister(), .remove
822 * needs parent to call ici->remove() */
823 icd
->dev
.parent
= NULL
;
824 memset(&icd
->dev
.kobj
, 0, sizeof(icd
->dev
.kobj
));
828 mutex_unlock(&list_lock
);
830 device_unregister(&ici
->dev
);
832 EXPORT_SYMBOL(soc_camera_host_unregister
);
834 /* Image capture device */
835 int soc_camera_device_register(struct soc_camera_device
*icd
)
837 struct soc_camera_device
*ix
;
843 for (i
= 0; i
< 256 && num
< 0; i
++) {
845 list_for_each_entry(ix
, &devices
, list
) {
846 if (ix
->iface
== icd
->iface
&& ix
->devnum
== i
) {
854 /* ok, we have 256 cameras on this host...
855 * man, stay reasonable... */
859 icd
->dev
.bus
= &soc_camera_bus_type
;
860 snprintf(icd
->dev
.bus_id
, sizeof(icd
->dev
.bus_id
),
861 "%u-%u", icd
->iface
, icd
->devnum
);
863 icd
->dev
.release
= dummy_release
;
865 return scan_add_device(icd
);
867 EXPORT_SYMBOL(soc_camera_device_register
);
869 void soc_camera_device_unregister(struct soc_camera_device
*icd
)
871 mutex_lock(&list_lock
);
872 list_del(&icd
->list
);
874 /* The bus->remove will be eventually called */
876 device_unregister(&icd
->dev
);
877 mutex_unlock(&list_lock
);
879 EXPORT_SYMBOL(soc_camera_device_unregister
);
881 int soc_camera_video_start(struct soc_camera_device
*icd
)
883 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
885 struct video_device
*vdev
;
887 if (!icd
->dev
.parent
)
890 vdev
= video_device_alloc();
893 dev_dbg(&ici
->dev
, "Allocated video_device %p\n", vdev
);
895 strlcpy(vdev
->name
, ici
->drv_name
, sizeof(vdev
->name
));
896 /* Maybe better &ici->dev */
897 vdev
->dev
= &icd
->dev
;
898 vdev
->type
= VID_TYPE_CAPTURE
;
899 vdev
->current_norm
= V4L2_STD_UNKNOWN
;
900 vdev
->fops
= &soc_camera_fops
;
901 vdev
->release
= video_device_release
;
903 vdev
->tvnorms
= V4L2_STD_UNKNOWN
,
904 vdev
->vidioc_querycap
= soc_camera_querycap
;
905 vdev
->vidioc_g_fmt_cap
= soc_camera_g_fmt_cap
;
906 vdev
->vidioc_enum_fmt_cap
= soc_camera_enum_fmt_cap
;
907 vdev
->vidioc_s_fmt_cap
= soc_camera_s_fmt_cap
;
908 vdev
->vidioc_enum_input
= soc_camera_enum_input
;
909 vdev
->vidioc_g_input
= soc_camera_g_input
;
910 vdev
->vidioc_s_input
= soc_camera_s_input
;
911 vdev
->vidioc_s_std
= soc_camera_s_std
;
912 vdev
->vidioc_reqbufs
= soc_camera_reqbufs
;
913 vdev
->vidioc_try_fmt_cap
= soc_camera_try_fmt_cap
;
914 vdev
->vidioc_querybuf
= soc_camera_querybuf
;
915 vdev
->vidioc_qbuf
= soc_camera_qbuf
;
916 vdev
->vidioc_dqbuf
= soc_camera_dqbuf
;
917 vdev
->vidioc_streamon
= soc_camera_streamon
;
918 vdev
->vidioc_streamoff
= soc_camera_streamoff
;
919 vdev
->vidioc_queryctrl
= soc_camera_queryctrl
;
920 vdev
->vidioc_g_ctrl
= soc_camera_g_ctrl
;
921 vdev
->vidioc_s_ctrl
= soc_camera_s_ctrl
;
922 vdev
->vidioc_cropcap
= soc_camera_cropcap
;
923 vdev
->vidioc_g_crop
= soc_camera_g_crop
;
924 vdev
->vidioc_s_crop
= soc_camera_s_crop
;
925 vdev
->vidioc_g_chip_ident
= soc_camera_g_chip_ident
;
926 #ifdef CONFIG_VIDEO_ADV_DEBUG
927 vdev
->vidioc_g_register
= soc_camera_g_register
;
928 vdev
->vidioc_s_register
= soc_camera_s_register
;
931 icd
->current_fmt
= &icd
->ops
->formats
[0];
933 err
= video_register_device(vdev
, VFL_TYPE_GRABBER
, vdev
->minor
);
935 dev_err(vdev
->dev
, "video_register_device failed\n");
943 video_device_release(vdev
);
947 EXPORT_SYMBOL(soc_camera_video_start
);
949 void soc_camera_video_stop(struct soc_camera_device
*icd
)
951 struct video_device
*vdev
= icd
->vdev
;
953 dev_dbg(&icd
->dev
, "%s\n", __FUNCTION__
);
955 if (!icd
->dev
.parent
|| !vdev
)
958 mutex_lock(&video_lock
);
959 video_unregister_device(vdev
);
961 mutex_unlock(&video_lock
);
963 EXPORT_SYMBOL(soc_camera_video_stop
);
965 static int __init
soc_camera_init(void)
967 int ret
= bus_register(&soc_camera_bus_type
);
970 ret
= driver_register(&ic_drv
);
973 ret
= class_register(&soc_camera_host_class
);
980 driver_unregister(&ic_drv
);
982 bus_unregister(&soc_camera_bus_type
);
986 static void __exit
soc_camera_exit(void)
988 class_unregister(&soc_camera_host_class
);
989 driver_unregister(&ic_drv
);
990 bus_unregister(&soc_camera_bus_type
);
993 module_init(soc_camera_init
);
994 module_exit(soc_camera_exit
);
996 MODULE_DESCRIPTION("Image capture bus driver");
997 MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
998 MODULE_LICENSE("GPL");