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 static struct soc_camera_data_format
*
39 format_by_fourcc(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
;
49 static int soc_camera_try_fmt_vid_cap(struct file
*file
, void *priv
,
50 struct v4l2_format
*f
)
52 struct soc_camera_file
*icf
= file
->private_data
;
53 struct soc_camera_device
*icd
= icf
->icd
;
54 struct soc_camera_host
*ici
=
55 to_soc_camera_host(icd
->dev
.parent
);
56 enum v4l2_field field
;
57 const struct soc_camera_data_format
*fmt
;
60 WARN_ON(priv
!= file
->private_data
);
62 fmt
= format_by_fourcc(icd
, f
->fmt
.pix
.pixelformat
);
64 dev_dbg(&icd
->dev
, "invalid format 0x%08x\n",
65 f
->fmt
.pix
.pixelformat
);
69 dev_dbg(&icd
->dev
, "fmt: 0x%08x\n", fmt
->fourcc
);
71 field
= f
->fmt
.pix
.field
;
73 if (field
== V4L2_FIELD_ANY
) {
74 field
= V4L2_FIELD_NONE
;
75 } else if (V4L2_FIELD_NONE
!= field
) {
76 dev_err(&icd
->dev
, "Field type invalid.\n");
80 /* test physical bus parameters */
81 ret
= ici
->ops
->try_bus_param(icd
, f
->fmt
.pix
.pixelformat
);
85 /* limit format to hardware capabilities */
86 ret
= ici
->ops
->try_fmt_cap(icd
, f
);
88 /* calculate missing fields */
89 f
->fmt
.pix
.field
= field
;
90 f
->fmt
.pix
.bytesperline
=
91 (f
->fmt
.pix
.width
* fmt
->depth
) >> 3;
92 f
->fmt
.pix
.sizeimage
=
93 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
98 static int soc_camera_enum_input(struct file
*file
, void *priv
,
99 struct v4l2_input
*inp
)
104 inp
->type
= V4L2_INPUT_TYPE_CAMERA
;
105 inp
->std
= V4L2_STD_UNKNOWN
;
106 strcpy(inp
->name
, "Camera");
111 static int soc_camera_g_input(struct file
*file
, void *priv
, unsigned int *i
)
118 static int soc_camera_s_input(struct file
*file
, void *priv
, unsigned int i
)
126 static int soc_camera_s_std(struct file
*file
, void *priv
, v4l2_std_id
*a
)
131 static int soc_camera_reqbufs(struct file
*file
, void *priv
,
132 struct v4l2_requestbuffers
*p
)
135 struct soc_camera_file
*icf
= file
->private_data
;
136 struct soc_camera_device
*icd
= icf
->icd
;
137 struct soc_camera_host
*ici
=
138 to_soc_camera_host(icd
->dev
.parent
);
140 WARN_ON(priv
!= file
->private_data
);
142 dev_dbg(&icd
->dev
, "%s: %d\n", __func__
, p
->memory
);
144 ret
= videobuf_reqbufs(&icf
->vb_vidq
, p
);
148 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
;
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
->parent
, 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
->ops
->owner
)) {
207 dev_err(&icd
->dev
, "Couldn't lock capture bus driver.\n");
215 /* Now we really have to activate the camera */
216 if (icd
->use_count
== 1) {
217 ret
= ici
->ops
->add(icd
);
219 dev_err(&icd
->dev
, "Couldn't activate the camera: %d\n", ret
);
225 mutex_unlock(&video_lock
);
227 file
->private_data
= icf
;
228 dev_dbg(&icd
->dev
, "camera device open\n");
230 ici
->ops
->init_videobuf(&icf
->vb_vidq
, icd
);
234 /* All errors are entered with the video_lock held */
236 module_put(ici
->ops
->owner
);
238 module_put(icd
->ops
->owner
);
240 mutex_unlock(&video_lock
);
245 static int soc_camera_close(struct inode
*inode
, struct file
*file
)
247 struct soc_camera_file
*icf
= file
->private_data
;
248 struct soc_camera_device
*icd
= icf
->icd
;
249 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
250 struct video_device
*vdev
= icd
->vdev
;
252 mutex_lock(&video_lock
);
255 ici
->ops
->remove(icd
);
256 module_put(icd
->ops
->owner
);
257 module_put(ici
->ops
->owner
);
258 mutex_unlock(&video_lock
);
262 dev_dbg(vdev
->parent
, "camera device close\n");
267 static ssize_t
soc_camera_read(struct file
*file
, char __user
*buf
,
268 size_t count
, loff_t
*ppos
)
270 struct soc_camera_file
*icf
= file
->private_data
;
271 struct soc_camera_device
*icd
= icf
->icd
;
272 struct video_device
*vdev
= icd
->vdev
;
275 dev_err(vdev
->parent
, "camera device read not implemented\n");
280 static int soc_camera_mmap(struct file
*file
, struct vm_area_struct
*vma
)
282 struct soc_camera_file
*icf
= file
->private_data
;
283 struct soc_camera_device
*icd
= icf
->icd
;
286 dev_dbg(&icd
->dev
, "mmap called, vma=0x%08lx\n", (unsigned long)vma
);
288 err
= videobuf_mmap_mapper(&icf
->vb_vidq
, vma
);
290 dev_dbg(&icd
->dev
, "vma start=0x%08lx, size=%ld, ret=%d\n",
291 (unsigned long)vma
->vm_start
,
292 (unsigned long)vma
->vm_end
- (unsigned long)vma
->vm_start
,
298 static unsigned int soc_camera_poll(struct file
*file
, poll_table
*pt
)
300 struct soc_camera_file
*icf
= file
->private_data
;
301 struct soc_camera_device
*icd
= icf
->icd
;
302 struct soc_camera_host
*ici
=
303 to_soc_camera_host(icd
->dev
.parent
);
305 if (list_empty(&icf
->vb_vidq
.stream
)) {
306 dev_err(&icd
->dev
, "Trying to poll with no queued buffers!\n");
310 return ici
->ops
->poll(file
, pt
);
314 static struct file_operations soc_camera_fops
= {
315 .owner
= THIS_MODULE
,
316 .open
= soc_camera_open
,
317 .release
= soc_camera_close
,
318 .ioctl
= video_ioctl2
,
319 .read
= soc_camera_read
,
320 .mmap
= soc_camera_mmap
,
321 .poll
= soc_camera_poll
,
326 static int soc_camera_s_fmt_vid_cap(struct file
*file
, void *priv
,
327 struct v4l2_format
*f
)
329 struct soc_camera_file
*icf
= file
->private_data
;
330 struct soc_camera_device
*icd
= icf
->icd
;
331 struct soc_camera_host
*ici
=
332 to_soc_camera_host(icd
->dev
.parent
);
334 struct v4l2_rect rect
;
335 const static struct soc_camera_data_format
*data_fmt
;
337 WARN_ON(priv
!= file
->private_data
);
339 data_fmt
= format_by_fourcc(icd
, f
->fmt
.pix
.pixelformat
);
343 /* buswidth may be further adjusted by the ici */
344 icd
->buswidth
= data_fmt
->depth
;
346 ret
= soc_camera_try_fmt_vid_cap(file
, icf
, f
);
350 rect
.left
= icd
->x_current
;
351 rect
.top
= icd
->y_current
;
352 rect
.width
= f
->fmt
.pix
.width
;
353 rect
.height
= f
->fmt
.pix
.height
;
354 ret
= ici
->ops
->set_fmt_cap(icd
, f
->fmt
.pix
.pixelformat
, &rect
);
358 icd
->current_fmt
= data_fmt
;
359 icd
->width
= rect
.width
;
360 icd
->height
= rect
.height
;
361 icf
->vb_vidq
.field
= f
->fmt
.pix
.field
;
362 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= f
->type
)
363 dev_warn(&icd
->dev
, "Attention! Wrong buf-type %d\n",
366 dev_dbg(&icd
->dev
, "set width: %d height: %d\n",
367 icd
->width
, icd
->height
);
369 /* set physical bus parameters */
370 return ici
->ops
->set_bus_param(icd
, f
->fmt
.pix
.pixelformat
);
373 static int soc_camera_enum_fmt_vid_cap(struct file
*file
, void *priv
,
374 struct v4l2_fmtdesc
*f
)
376 struct soc_camera_file
*icf
= file
->private_data
;
377 struct soc_camera_device
*icd
= icf
->icd
;
378 const struct soc_camera_data_format
*format
;
380 WARN_ON(priv
!= file
->private_data
);
382 if (f
->index
>= icd
->num_formats
)
385 format
= &icd
->formats
[f
->index
];
387 strlcpy(f
->description
, format
->name
, sizeof(f
->description
));
388 f
->pixelformat
= format
->fourcc
;
392 static int soc_camera_g_fmt_vid_cap(struct file
*file
, void *priv
,
393 struct v4l2_format
*f
)
395 struct soc_camera_file
*icf
= file
->private_data
;
396 struct soc_camera_device
*icd
= icf
->icd
;
398 WARN_ON(priv
!= file
->private_data
);
400 f
->fmt
.pix
.width
= icd
->width
;
401 f
->fmt
.pix
.height
= icd
->height
;
402 f
->fmt
.pix
.field
= icf
->vb_vidq
.field
;
403 f
->fmt
.pix
.pixelformat
= icd
->current_fmt
->fourcc
;
404 f
->fmt
.pix
.bytesperline
=
405 (f
->fmt
.pix
.width
* icd
->current_fmt
->depth
) >> 3;
406 f
->fmt
.pix
.sizeimage
=
407 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
408 dev_dbg(&icd
->dev
, "current_fmt->fourcc: 0x%08x\n",
409 icd
->current_fmt
->fourcc
);
413 static int soc_camera_querycap(struct file
*file
, void *priv
,
414 struct v4l2_capability
*cap
)
416 struct soc_camera_file
*icf
= file
->private_data
;
417 struct soc_camera_device
*icd
= icf
->icd
;
418 struct soc_camera_host
*ici
=
419 to_soc_camera_host(icd
->dev
.parent
);
421 WARN_ON(priv
!= file
->private_data
);
423 strlcpy(cap
->driver
, ici
->drv_name
, sizeof(cap
->driver
));
424 return ici
->ops
->querycap(ici
, cap
);
427 static int soc_camera_streamon(struct file
*file
, void *priv
,
428 enum v4l2_buf_type i
)
430 struct soc_camera_file
*icf
= file
->private_data
;
431 struct soc_camera_device
*icd
= icf
->icd
;
433 WARN_ON(priv
!= file
->private_data
);
435 dev_dbg(&icd
->dev
, "%s\n", __func__
);
437 if (i
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
440 icd
->ops
->start_capture(icd
);
442 /* This calls buf_queue from host driver's videobuf_queue_ops */
443 return videobuf_streamon(&icf
->vb_vidq
);
446 static int soc_camera_streamoff(struct file
*file
, void *priv
,
447 enum v4l2_buf_type i
)
449 struct soc_camera_file
*icf
= file
->private_data
;
450 struct soc_camera_device
*icd
= icf
->icd
;
452 WARN_ON(priv
!= file
->private_data
);
454 dev_dbg(&icd
->dev
, "%s\n", __func__
);
456 if (i
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
459 /* This calls buf_release from host driver's videobuf_queue_ops for all
460 * remaining buffers. When the last buffer is freed, stop capture */
461 videobuf_streamoff(&icf
->vb_vidq
);
463 icd
->ops
->stop_capture(icd
);
468 static int soc_camera_queryctrl(struct file
*file
, void *priv
,
469 struct v4l2_queryctrl
*qc
)
471 struct soc_camera_file
*icf
= file
->private_data
;
472 struct soc_camera_device
*icd
= icf
->icd
;
475 WARN_ON(priv
!= file
->private_data
);
480 for (i
= 0; i
< icd
->ops
->num_controls
; i
++)
481 if (qc
->id
== icd
->ops
->controls
[i
].id
) {
482 memcpy(qc
, &(icd
->ops
->controls
[i
]),
490 static int soc_camera_g_ctrl(struct file
*file
, void *priv
,
491 struct v4l2_control
*ctrl
)
493 struct soc_camera_file
*icf
= file
->private_data
;
494 struct soc_camera_device
*icd
= icf
->icd
;
496 WARN_ON(priv
!= file
->private_data
);
500 if (icd
->gain
== (unsigned short)~0)
502 ctrl
->value
= icd
->gain
;
504 case V4L2_CID_EXPOSURE
:
505 if (icd
->exposure
== (unsigned short)~0)
507 ctrl
->value
= icd
->exposure
;
511 if (icd
->ops
->get_control
)
512 return icd
->ops
->get_control(icd
, ctrl
);
516 static int soc_camera_s_ctrl(struct file
*file
, void *priv
,
517 struct v4l2_control
*ctrl
)
519 struct soc_camera_file
*icf
= file
->private_data
;
520 struct soc_camera_device
*icd
= icf
->icd
;
522 WARN_ON(priv
!= file
->private_data
);
524 if (icd
->ops
->set_control
)
525 return icd
->ops
->set_control(icd
, ctrl
);
529 static int soc_camera_cropcap(struct file
*file
, void *fh
,
530 struct v4l2_cropcap
*a
)
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
->bounds
.left
= icd
->x_min
;
537 a
->bounds
.top
= icd
->y_min
;
538 a
->bounds
.width
= icd
->width_max
;
539 a
->bounds
.height
= icd
->height_max
;
540 a
->defrect
.left
= icd
->x_min
;
541 a
->defrect
.top
= icd
->y_min
;
542 a
->defrect
.width
= 640;
543 a
->defrect
.height
= 480;
544 a
->pixelaspect
.numerator
= 1;
545 a
->pixelaspect
.denominator
= 1;
550 static int soc_camera_g_crop(struct file
*file
, void *fh
,
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
->c
.left
= icd
->x_current
;
558 a
->c
.top
= icd
->y_current
;
559 a
->c
.width
= icd
->width
;
560 a
->c
.height
= icd
->height
;
565 static int soc_camera_s_crop(struct file
*file
, void *fh
,
568 struct soc_camera_file
*icf
= file
->private_data
;
569 struct soc_camera_device
*icd
= icf
->icd
;
570 struct soc_camera_host
*ici
=
571 to_soc_camera_host(icd
->dev
.parent
);
574 if (a
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
577 ret
= ici
->ops
->set_fmt_cap(icd
, 0, &a
->c
);
579 icd
->width
= a
->c
.width
;
580 icd
->height
= a
->c
.height
;
581 icd
->x_current
= a
->c
.left
;
582 icd
->y_current
= a
->c
.top
;
588 static int soc_camera_g_chip_ident(struct file
*file
, void *fh
,
589 struct v4l2_chip_ident
*id
)
591 struct soc_camera_file
*icf
= file
->private_data
;
592 struct soc_camera_device
*icd
= icf
->icd
;
594 if (!icd
->ops
->get_chip_id
)
597 return icd
->ops
->get_chip_id(icd
, id
);
600 #ifdef CONFIG_VIDEO_ADV_DEBUG
601 static int soc_camera_g_register(struct file
*file
, void *fh
,
602 struct v4l2_register
*reg
)
604 struct soc_camera_file
*icf
= file
->private_data
;
605 struct soc_camera_device
*icd
= icf
->icd
;
607 if (!icd
->ops
->get_register
)
610 return icd
->ops
->get_register(icd
, reg
);
613 static int soc_camera_s_register(struct file
*file
, void *fh
,
614 struct v4l2_register
*reg
)
616 struct soc_camera_file
*icf
= file
->private_data
;
617 struct soc_camera_device
*icd
= icf
->icd
;
619 if (!icd
->ops
->set_register
)
622 return icd
->ops
->set_register(icd
, reg
);
626 static int device_register_link(struct soc_camera_device
*icd
)
628 int ret
= device_register(&icd
->dev
);
631 /* Prevent calling device_unregister() */
632 icd
->dev
.parent
= NULL
;
633 dev_err(&icd
->dev
, "Cannot register device: %d\n", ret
);
634 /* Even if probe() was unsuccessful for all registered drivers,
635 * device_register() returns 0, and we add the link, just to
636 * document this camera's control device */
637 } else if (icd
->control
)
638 /* Have to sysfs_remove_link() before device_unregister()? */
639 if (sysfs_create_link(&icd
->dev
.kobj
, &icd
->control
->kobj
,
642 "Failed creating the control symlink\n");
646 /* So far this function cannot fail */
647 static void scan_add_host(struct soc_camera_host
*ici
)
649 struct soc_camera_device
*icd
;
651 mutex_lock(&list_lock
);
653 list_for_each_entry(icd
, &devices
, list
) {
654 if (icd
->iface
== ici
->nr
) {
655 icd
->dev
.parent
= &ici
->dev
;
656 device_register_link(icd
);
660 mutex_unlock(&list_lock
);
663 /* return: 0 if no match found or a match found and
664 * device_register() successful, error code otherwise */
665 static int scan_add_device(struct soc_camera_device
*icd
)
667 struct soc_camera_host
*ici
;
670 mutex_lock(&list_lock
);
672 list_add_tail(&icd
->list
, &devices
);
674 /* Watch out for class_for_each_device / class_find_device API by
675 * Dave Young <hidave.darkstar@gmail.com> */
676 list_for_each_entry(ici
, &hosts
, list
) {
677 if (icd
->iface
== ici
->nr
) {
679 icd
->dev
.parent
= &ici
->dev
;
684 mutex_unlock(&list_lock
);
687 ret
= device_register_link(icd
);
692 static int soc_camera_probe(struct device
*dev
)
694 struct soc_camera_device
*icd
= to_soc_camera_dev(dev
);
695 struct soc_camera_host
*ici
=
696 to_soc_camera_host(icd
->dev
.parent
);
699 if (!icd
->ops
->probe
)
702 /* We only call ->add() here to activate and probe the camera.
703 * We shall ->remove() and deactivate it immediately afterwards. */
704 ret
= ici
->ops
->add(icd
);
708 ret
= icd
->ops
->probe(icd
);
710 const struct v4l2_queryctrl
*qctrl
;
712 qctrl
= soc_camera_find_qctrl(icd
->ops
, V4L2_CID_GAIN
);
713 icd
->gain
= qctrl
? qctrl
->default_value
: (unsigned short)~0;
714 qctrl
= soc_camera_find_qctrl(icd
->ops
, V4L2_CID_EXPOSURE
);
715 icd
->exposure
= qctrl
? qctrl
->default_value
:
718 ici
->ops
->remove(icd
);
723 /* This is called on device_unregister, which only means we have to disconnect
724 * from the host, but not remove ourselves from the device list */
725 static int soc_camera_remove(struct device
*dev
)
727 struct soc_camera_device
*icd
= to_soc_camera_dev(dev
);
729 if (icd
->ops
->remove
)
730 icd
->ops
->remove(icd
);
735 static int soc_camera_suspend(struct device
*dev
, pm_message_t state
)
737 struct soc_camera_device
*icd
= to_soc_camera_dev(dev
);
738 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
741 if (ici
->ops
->suspend
)
742 ret
= ici
->ops
->suspend(icd
, state
);
747 static int soc_camera_resume(struct device
*dev
)
749 struct soc_camera_device
*icd
= to_soc_camera_dev(dev
);
750 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
753 if (ici
->ops
->resume
)
754 ret
= ici
->ops
->resume(icd
);
759 static struct bus_type soc_camera_bus_type
= {
760 .name
= "soc-camera",
761 .probe
= soc_camera_probe
,
762 .remove
= soc_camera_remove
,
763 .suspend
= soc_camera_suspend
,
764 .resume
= soc_camera_resume
,
767 static struct device_driver ic_drv
= {
769 .bus
= &soc_camera_bus_type
,
770 .owner
= THIS_MODULE
,
773 static void dummy_release(struct device
*dev
)
777 int soc_camera_host_register(struct soc_camera_host
*ici
)
780 struct soc_camera_host
*ix
;
782 if (!ici
->ops
->init_videobuf
|| !ici
->ops
->add
|| !ici
->ops
->remove
)
785 /* Number might be equal to the platform device ID */
786 sprintf(ici
->dev
.bus_id
, "camera_host%d", ici
->nr
);
788 mutex_lock(&list_lock
);
789 list_for_each_entry(ix
, &hosts
, list
) {
790 if (ix
->nr
== ici
->nr
) {
791 mutex_unlock(&list_lock
);
796 list_add_tail(&ici
->list
, &hosts
);
797 mutex_unlock(&list_lock
);
799 ici
->dev
.release
= dummy_release
;
801 ret
= device_register(&ici
->dev
);
811 mutex_lock(&list_lock
);
812 list_del(&ici
->list
);
813 mutex_unlock(&list_lock
);
817 EXPORT_SYMBOL(soc_camera_host_register
);
819 /* Unregister all clients! */
820 void soc_camera_host_unregister(struct soc_camera_host
*ici
)
822 struct soc_camera_device
*icd
;
824 mutex_lock(&list_lock
);
826 list_del(&ici
->list
);
828 list_for_each_entry(icd
, &devices
, list
) {
829 if (icd
->dev
.parent
== &ici
->dev
) {
830 device_unregister(&icd
->dev
);
831 /* Not before device_unregister(), .remove
832 * needs parent to call ici->ops->remove() */
833 icd
->dev
.parent
= NULL
;
834 memset(&icd
->dev
.kobj
, 0, sizeof(icd
->dev
.kobj
));
838 mutex_unlock(&list_lock
);
840 device_unregister(&ici
->dev
);
842 EXPORT_SYMBOL(soc_camera_host_unregister
);
844 /* Image capture device */
845 int soc_camera_device_register(struct soc_camera_device
*icd
)
847 struct soc_camera_device
*ix
;
853 for (i
= 0; i
< 256 && num
< 0; i
++) {
855 list_for_each_entry(ix
, &devices
, list
) {
856 if (ix
->iface
== icd
->iface
&& ix
->devnum
== i
) {
864 /* ok, we have 256 cameras on this host...
865 * man, stay reasonable... */
869 icd
->dev
.bus
= &soc_camera_bus_type
;
870 snprintf(icd
->dev
.bus_id
, sizeof(icd
->dev
.bus_id
),
871 "%u-%u", icd
->iface
, icd
->devnum
);
873 icd
->dev
.release
= dummy_release
;
875 return scan_add_device(icd
);
877 EXPORT_SYMBOL(soc_camera_device_register
);
879 void soc_camera_device_unregister(struct soc_camera_device
*icd
)
881 mutex_lock(&list_lock
);
882 list_del(&icd
->list
);
884 /* The bus->remove will be eventually called */
886 device_unregister(&icd
->dev
);
887 mutex_unlock(&list_lock
);
889 EXPORT_SYMBOL(soc_camera_device_unregister
);
891 static const struct v4l2_ioctl_ops soc_camera_ioctl_ops
= {
892 .vidioc_querycap
= soc_camera_querycap
,
893 .vidioc_g_fmt_vid_cap
= soc_camera_g_fmt_vid_cap
,
894 .vidioc_enum_fmt_vid_cap
= soc_camera_enum_fmt_vid_cap
,
895 .vidioc_s_fmt_vid_cap
= soc_camera_s_fmt_vid_cap
,
896 .vidioc_enum_input
= soc_camera_enum_input
,
897 .vidioc_g_input
= soc_camera_g_input
,
898 .vidioc_s_input
= soc_camera_s_input
,
899 .vidioc_s_std
= soc_camera_s_std
,
900 .vidioc_reqbufs
= soc_camera_reqbufs
,
901 .vidioc_try_fmt_vid_cap
= soc_camera_try_fmt_vid_cap
,
902 .vidioc_querybuf
= soc_camera_querybuf
,
903 .vidioc_qbuf
= soc_camera_qbuf
,
904 .vidioc_dqbuf
= soc_camera_dqbuf
,
905 .vidioc_streamon
= soc_camera_streamon
,
906 .vidioc_streamoff
= soc_camera_streamoff
,
907 .vidioc_queryctrl
= soc_camera_queryctrl
,
908 .vidioc_g_ctrl
= soc_camera_g_ctrl
,
909 .vidioc_s_ctrl
= soc_camera_s_ctrl
,
910 .vidioc_cropcap
= soc_camera_cropcap
,
911 .vidioc_g_crop
= soc_camera_g_crop
,
912 .vidioc_s_crop
= soc_camera_s_crop
,
913 .vidioc_g_chip_ident
= soc_camera_g_chip_ident
,
914 #ifdef CONFIG_VIDEO_ADV_DEBUG
915 .vidioc_g_register
= soc_camera_g_register
,
916 .vidioc_s_register
= soc_camera_s_register
,
920 int soc_camera_video_start(struct soc_camera_device
*icd
)
922 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
924 struct video_device
*vdev
;
926 if (!icd
->dev
.parent
)
929 vdev
= video_device_alloc();
932 dev_dbg(&ici
->dev
, "Allocated video_device %p\n", vdev
);
934 strlcpy(vdev
->name
, ici
->drv_name
, sizeof(vdev
->name
));
935 /* Maybe better &ici->dev */
936 vdev
->parent
= &icd
->dev
;
937 vdev
->current_norm
= V4L2_STD_UNKNOWN
;
938 vdev
->fops
= &soc_camera_fops
;
939 vdev
->ioctl_ops
= &soc_camera_ioctl_ops
;
940 vdev
->release
= video_device_release
;
942 vdev
->tvnorms
= V4L2_STD_UNKNOWN
,
944 icd
->current_fmt
= &icd
->formats
[0];
946 err
= video_register_device(vdev
, VFL_TYPE_GRABBER
, vdev
->minor
);
948 dev_err(vdev
->parent
, "video_register_device failed\n");
956 video_device_release(vdev
);
960 EXPORT_SYMBOL(soc_camera_video_start
);
962 void soc_camera_video_stop(struct soc_camera_device
*icd
)
964 struct video_device
*vdev
= icd
->vdev
;
966 dev_dbg(&icd
->dev
, "%s\n", __func__
);
968 if (!icd
->dev
.parent
|| !vdev
)
971 mutex_lock(&video_lock
);
972 video_unregister_device(vdev
);
974 mutex_unlock(&video_lock
);
976 EXPORT_SYMBOL(soc_camera_video_stop
);
978 static int __init
soc_camera_init(void)
980 int ret
= bus_register(&soc_camera_bus_type
);
983 ret
= driver_register(&ic_drv
);
990 bus_unregister(&soc_camera_bus_type
);
994 static void __exit
soc_camera_exit(void)
996 driver_unregister(&ic_drv
);
997 bus_unregister(&soc_camera_bus_type
);
1000 module_init(soc_camera_init
);
1001 module_exit(soc_camera_exit
);
1003 MODULE_DESCRIPTION("Image capture bus driver");
1004 MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
1005 MODULE_LICENSE("GPL");