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/device.h>
20 #include <linux/err.h>
21 #include <linux/i2c.h>
22 #include <linux/init.h>
23 #include <linux/list.h>
24 #include <linux/mutex.h>
25 #include <linux/module.h>
26 #include <linux/platform_device.h>
27 #include <linux/regulator/consumer.h>
28 #include <linux/slab.h>
29 #include <linux/pm_runtime.h>
30 #include <linux/vmalloc.h>
32 #include <media/soc_camera.h>
33 #include <media/v4l2-common.h>
34 #include <media/v4l2-ioctl.h>
35 #include <media/v4l2-dev.h>
36 #include <media/videobuf-core.h>
37 #include <media/videobuf2-core.h>
38 #include <media/soc_mediabus.h>
40 /* Default to VGA resolution */
41 #define DEFAULT_WIDTH 640
42 #define DEFAULT_HEIGHT 480
44 #define is_streaming(ici, icd) \
45 (((ici)->ops->init_videobuf) ? \
46 (icd)->vb_vidq.streaming : \
47 vb2_is_streaming(&(icd)->vb2_vidq))
49 static LIST_HEAD(hosts
);
50 static LIST_HEAD(devices
);
51 static DEFINE_MUTEX(list_lock
); /* Protects the list of hosts */
53 int soc_camera_power_on(struct device
*dev
, struct soc_camera_link
*icl
)
55 int ret
= regulator_bulk_enable(icl
->num_regulators
,
58 dev_err(dev
, "Cannot enable regulators\n");
63 ret
= icl
->power(dev
, 1);
66 "Platform failed to power-on the camera.\n");
67 regulator_bulk_disable(icl
->num_regulators
,
74 EXPORT_SYMBOL(soc_camera_power_on
);
76 int soc_camera_power_off(struct device
*dev
, struct soc_camera_link
*icl
)
82 err
= icl
->power(dev
, 0);
85 "Platform failed to power-off the camera.\n");
90 err
= regulator_bulk_disable(icl
->num_regulators
,
93 dev_err(dev
, "Cannot disable regulators\n");
99 EXPORT_SYMBOL(soc_camera_power_off
);
101 static int __soc_camera_power_on(struct soc_camera_device
*icd
)
103 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
106 ret
= v4l2_subdev_call(sd
, core
, s_power
, 1);
107 if (ret
< 0 && ret
!= -ENOIOCTLCMD
&& ret
!= -ENODEV
)
113 static int __soc_camera_power_off(struct soc_camera_device
*icd
)
115 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
118 ret
= v4l2_subdev_call(sd
, core
, s_power
, 0);
119 if (ret
< 0 && ret
!= -ENOIOCTLCMD
&& ret
!= -ENODEV
)
125 const struct soc_camera_format_xlate
*soc_camera_xlate_by_fourcc(
126 struct soc_camera_device
*icd
, unsigned int fourcc
)
130 for (i
= 0; i
< icd
->num_user_formats
; i
++)
131 if (icd
->user_formats
[i
].host_fmt
->fourcc
== fourcc
)
132 return icd
->user_formats
+ i
;
135 EXPORT_SYMBOL(soc_camera_xlate_by_fourcc
);
138 * soc_camera_apply_board_flags() - apply platform SOCAM_SENSOR_INVERT_* flags
139 * @icl: camera platform parameters
140 * @cfg: media bus configuration
141 * @return: resulting flags
143 unsigned long soc_camera_apply_board_flags(struct soc_camera_link
*icl
,
144 const struct v4l2_mbus_config
*cfg
)
146 unsigned long f
, flags
= cfg
->flags
;
148 /* If only one of the two polarities is supported, switch to the opposite */
149 if (icl
->flags
& SOCAM_SENSOR_INVERT_HSYNC
) {
150 f
= flags
& (V4L2_MBUS_HSYNC_ACTIVE_HIGH
| V4L2_MBUS_HSYNC_ACTIVE_LOW
);
151 if (f
== V4L2_MBUS_HSYNC_ACTIVE_HIGH
|| f
== V4L2_MBUS_HSYNC_ACTIVE_LOW
)
152 flags
^= V4L2_MBUS_HSYNC_ACTIVE_HIGH
| V4L2_MBUS_HSYNC_ACTIVE_LOW
;
155 if (icl
->flags
& SOCAM_SENSOR_INVERT_VSYNC
) {
156 f
= flags
& (V4L2_MBUS_VSYNC_ACTIVE_HIGH
| V4L2_MBUS_VSYNC_ACTIVE_LOW
);
157 if (f
== V4L2_MBUS_VSYNC_ACTIVE_HIGH
|| f
== V4L2_MBUS_VSYNC_ACTIVE_LOW
)
158 flags
^= V4L2_MBUS_VSYNC_ACTIVE_HIGH
| V4L2_MBUS_VSYNC_ACTIVE_LOW
;
161 if (icl
->flags
& SOCAM_SENSOR_INVERT_PCLK
) {
162 f
= flags
& (V4L2_MBUS_PCLK_SAMPLE_RISING
| V4L2_MBUS_PCLK_SAMPLE_FALLING
);
163 if (f
== V4L2_MBUS_PCLK_SAMPLE_RISING
|| f
== V4L2_MBUS_PCLK_SAMPLE_FALLING
)
164 flags
^= V4L2_MBUS_PCLK_SAMPLE_RISING
| V4L2_MBUS_PCLK_SAMPLE_FALLING
;
169 EXPORT_SYMBOL(soc_camera_apply_board_flags
);
171 #define pixfmtstr(x) (x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, \
174 static int soc_camera_try_fmt(struct soc_camera_device
*icd
,
175 struct v4l2_format
*f
)
177 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
178 const struct soc_camera_format_xlate
*xlate
;
179 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
182 dev_dbg(icd
->pdev
, "TRY_FMT(%c%c%c%c, %ux%u)\n",
183 pixfmtstr(pix
->pixelformat
), pix
->width
, pix
->height
);
185 if (pix
->pixelformat
!= V4L2_PIX_FMT_JPEG
&&
186 !(ici
->capabilities
& SOCAM_HOST_CAP_STRIDE
)) {
187 pix
->bytesperline
= 0;
191 ret
= ici
->ops
->try_fmt(icd
, f
);
195 xlate
= soc_camera_xlate_by_fourcc(icd
, pix
->pixelformat
);
199 ret
= soc_mbus_bytes_per_line(pix
->width
, xlate
->host_fmt
);
203 pix
->bytesperline
= max_t(u32
, pix
->bytesperline
, ret
);
205 ret
= soc_mbus_image_size(xlate
->host_fmt
, pix
->bytesperline
,
210 pix
->sizeimage
= max_t(u32
, pix
->sizeimage
, ret
);
215 static int soc_camera_try_fmt_vid_cap(struct file
*file
, void *priv
,
216 struct v4l2_format
*f
)
218 struct soc_camera_device
*icd
= file
->private_data
;
220 WARN_ON(priv
!= file
->private_data
);
222 /* Only single-plane capture is supported so far */
223 if (f
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
226 /* limit format to hardware capabilities */
227 return soc_camera_try_fmt(icd
, f
);
230 static int soc_camera_enum_input(struct file
*file
, void *priv
,
231 struct v4l2_input
*inp
)
236 /* default is camera */
237 inp
->type
= V4L2_INPUT_TYPE_CAMERA
;
238 inp
->std
= V4L2_STD_UNKNOWN
;
239 strcpy(inp
->name
, "Camera");
244 static int soc_camera_g_input(struct file
*file
, void *priv
, unsigned int *i
)
251 static int soc_camera_s_input(struct file
*file
, void *priv
, unsigned int i
)
259 static int soc_camera_s_std(struct file
*file
, void *priv
, v4l2_std_id
*a
)
261 struct soc_camera_device
*icd
= file
->private_data
;
262 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
264 return v4l2_subdev_call(sd
, core
, s_std
, *a
);
267 static int soc_camera_g_std(struct file
*file
, void *priv
, v4l2_std_id
*a
)
269 struct soc_camera_device
*icd
= file
->private_data
;
270 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
272 return v4l2_subdev_call(sd
, core
, g_std
, a
);
275 static int soc_camera_enum_framesizes(struct file
*file
, void *fh
,
276 struct v4l2_frmsizeenum
*fsize
)
278 struct soc_camera_device
*icd
= file
->private_data
;
279 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
281 return ici
->ops
->enum_framesizes(icd
, fsize
);
284 static int soc_camera_reqbufs(struct file
*file
, void *priv
,
285 struct v4l2_requestbuffers
*p
)
288 struct soc_camera_device
*icd
= file
->private_data
;
289 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
291 WARN_ON(priv
!= file
->private_data
);
293 if (icd
->streamer
&& icd
->streamer
!= file
)
296 if (ici
->ops
->init_videobuf
) {
297 ret
= videobuf_reqbufs(&icd
->vb_vidq
, p
);
301 ret
= ici
->ops
->reqbufs(icd
, p
);
303 ret
= vb2_reqbufs(&icd
->vb2_vidq
, p
);
306 if (!ret
&& !icd
->streamer
)
307 icd
->streamer
= file
;
312 static int soc_camera_querybuf(struct file
*file
, void *priv
,
313 struct v4l2_buffer
*p
)
315 struct soc_camera_device
*icd
= file
->private_data
;
316 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
318 WARN_ON(priv
!= file
->private_data
);
320 if (ici
->ops
->init_videobuf
)
321 return videobuf_querybuf(&icd
->vb_vidq
, p
);
323 return vb2_querybuf(&icd
->vb2_vidq
, p
);
326 static int soc_camera_qbuf(struct file
*file
, void *priv
,
327 struct v4l2_buffer
*p
)
329 struct soc_camera_device
*icd
= file
->private_data
;
330 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
332 WARN_ON(priv
!= file
->private_data
);
334 if (icd
->streamer
!= file
)
337 if (ici
->ops
->init_videobuf
)
338 return videobuf_qbuf(&icd
->vb_vidq
, p
);
340 return vb2_qbuf(&icd
->vb2_vidq
, p
);
343 static int soc_camera_dqbuf(struct file
*file
, void *priv
,
344 struct v4l2_buffer
*p
)
346 struct soc_camera_device
*icd
= file
->private_data
;
347 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
349 WARN_ON(priv
!= file
->private_data
);
351 if (icd
->streamer
!= file
)
354 if (ici
->ops
->init_videobuf
)
355 return videobuf_dqbuf(&icd
->vb_vidq
, p
, file
->f_flags
& O_NONBLOCK
);
357 return vb2_dqbuf(&icd
->vb2_vidq
, p
, file
->f_flags
& O_NONBLOCK
);
360 static int soc_camera_create_bufs(struct file
*file
, void *priv
,
361 struct v4l2_create_buffers
*create
)
363 struct soc_camera_device
*icd
= file
->private_data
;
364 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
367 if (ici
->ops
->init_videobuf
)
370 return vb2_create_bufs(&icd
->vb2_vidq
, create
);
373 static int soc_camera_prepare_buf(struct file
*file
, void *priv
,
374 struct v4l2_buffer
*b
)
376 struct soc_camera_device
*icd
= file
->private_data
;
377 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
380 if (ici
->ops
->init_videobuf
)
383 return vb2_prepare_buf(&icd
->vb2_vidq
, b
);
386 /* Always entered with .host_lock held */
387 static int soc_camera_init_user_formats(struct soc_camera_device
*icd
)
389 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
390 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
391 unsigned int i
, fmts
= 0, raw_fmts
= 0;
393 enum v4l2_mbus_pixelcode code
;
395 while (!v4l2_subdev_call(sd
, video
, enum_mbus_fmt
, raw_fmts
, &code
))
398 if (!ici
->ops
->get_formats
)
400 * Fallback mode - the host will have to serve all
401 * sensor-provided formats one-to-one to the user
406 * First pass - only count formats this host-sensor
407 * configuration can provide
409 for (i
= 0; i
< raw_fmts
; i
++) {
410 ret
= ici
->ops
->get_formats(icd
, i
, NULL
);
420 vmalloc(fmts
* sizeof(struct soc_camera_format_xlate
));
421 if (!icd
->user_formats
)
424 dev_dbg(icd
->pdev
, "Found %d supported formats.\n", fmts
);
426 /* Second pass - actually fill data formats */
428 for (i
= 0; i
< raw_fmts
; i
++)
429 if (!ici
->ops
->get_formats
) {
430 v4l2_subdev_call(sd
, video
, enum_mbus_fmt
, i
, &code
);
431 icd
->user_formats
[fmts
].host_fmt
=
432 soc_mbus_get_fmtdesc(code
);
433 if (icd
->user_formats
[fmts
].host_fmt
)
434 icd
->user_formats
[fmts
++].code
= code
;
436 ret
= ici
->ops
->get_formats(icd
, i
,
437 &icd
->user_formats
[fmts
]);
443 icd
->num_user_formats
= fmts
;
444 icd
->current_fmt
= &icd
->user_formats
[0];
449 vfree(icd
->user_formats
);
453 /* Always entered with .host_lock held */
454 static void soc_camera_free_user_formats(struct soc_camera_device
*icd
)
456 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
458 if (ici
->ops
->put_formats
)
459 ici
->ops
->put_formats(icd
);
460 icd
->current_fmt
= NULL
;
461 icd
->num_user_formats
= 0;
462 vfree(icd
->user_formats
);
463 icd
->user_formats
= NULL
;
466 /* Called with .vb_lock held, or from the first open(2), see comment there */
467 static int soc_camera_set_fmt(struct soc_camera_device
*icd
,
468 struct v4l2_format
*f
)
470 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
471 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
474 dev_dbg(icd
->pdev
, "S_FMT(%c%c%c%c, %ux%u)\n",
475 pixfmtstr(pix
->pixelformat
), pix
->width
, pix
->height
);
477 /* We always call try_fmt() before set_fmt() or set_crop() */
478 ret
= soc_camera_try_fmt(icd
, f
);
482 ret
= ici
->ops
->set_fmt(icd
, f
);
485 } else if (!icd
->current_fmt
||
486 icd
->current_fmt
->host_fmt
->fourcc
!= pix
->pixelformat
) {
488 "Host driver hasn't set up current format correctly!\n");
492 icd
->user_width
= pix
->width
;
493 icd
->user_height
= pix
->height
;
494 icd
->bytesperline
= pix
->bytesperline
;
495 icd
->sizeimage
= pix
->sizeimage
;
496 icd
->colorspace
= pix
->colorspace
;
497 icd
->field
= pix
->field
;
498 if (ici
->ops
->init_videobuf
)
499 icd
->vb_vidq
.field
= pix
->field
;
501 dev_dbg(icd
->pdev
, "set width: %d height: %d\n",
502 icd
->user_width
, icd
->user_height
);
504 /* set physical bus parameters */
505 return ici
->ops
->set_bus_param(icd
);
508 static int soc_camera_open(struct file
*file
)
510 struct video_device
*vdev
= video_devdata(file
);
511 struct soc_camera_device
*icd
= dev_get_drvdata(vdev
->parent
);
512 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
513 struct soc_camera_host
*ici
;
516 if (!to_soc_camera_control(icd
))
517 /* No device driver attached */
521 * Don't mess with the host during probe: wait until the loop in
522 * scan_add_host() completes
524 if (mutex_lock_interruptible(&list_lock
))
526 ici
= to_soc_camera_host(icd
->parent
);
527 mutex_unlock(&list_lock
);
529 if (mutex_lock_interruptible(&ici
->host_lock
))
531 if (!try_module_get(ici
->ops
->owner
)) {
532 dev_err(icd
->pdev
, "Couldn't lock capture bus driver.\n");
539 /* Now we really have to activate the camera */
540 if (icd
->use_count
== 1) {
541 /* Restore parameters before the last close() per V4L2 API */
542 struct v4l2_format f
= {
543 .type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
,
545 .width
= icd
->user_width
,
546 .height
= icd
->user_height
,
548 .colorspace
= icd
->colorspace
,
550 icd
->current_fmt
->host_fmt
->fourcc
,
554 /* The camera could have been already on, try to reset */
556 icl
->reset(icd
->pdev
);
558 ret
= ici
->ops
->add(icd
);
560 dev_err(icd
->pdev
, "Couldn't activate the camera: %d\n", ret
);
564 ret
= __soc_camera_power_on(icd
);
568 pm_runtime_enable(&icd
->vdev
->dev
);
569 ret
= pm_runtime_resume(&icd
->vdev
->dev
);
570 if (ret
< 0 && ret
!= -ENOSYS
)
574 * Try to configure with default parameters. Notice: this is the
575 * very first open, so, we cannot race against other calls,
576 * apart from someone else calling open() simultaneously, but
577 * .host_lock is protecting us against it.
579 ret
= soc_camera_set_fmt(icd
, &f
);
583 if (ici
->ops
->init_videobuf
) {
584 ici
->ops
->init_videobuf(&icd
->vb_vidq
, icd
);
586 ret
= ici
->ops
->init_videobuf2(&icd
->vb2_vidq
, icd
);
590 v4l2_ctrl_handler_setup(&icd
->ctrl_handler
);
592 mutex_unlock(&ici
->host_lock
);
594 file
->private_data
= icd
;
595 dev_dbg(icd
->pdev
, "camera device open\n");
600 * First four errors are entered with the .host_lock held
605 pm_runtime_disable(&icd
->vdev
->dev
);
607 __soc_camera_power_off(icd
);
609 ici
->ops
->remove(icd
);
612 module_put(ici
->ops
->owner
);
614 mutex_unlock(&ici
->host_lock
);
619 static int soc_camera_close(struct file
*file
)
621 struct soc_camera_device
*icd
= file
->private_data
;
622 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
624 mutex_lock(&ici
->host_lock
);
626 if (!icd
->use_count
) {
627 pm_runtime_suspend(&icd
->vdev
->dev
);
628 pm_runtime_disable(&icd
->vdev
->dev
);
630 if (ici
->ops
->init_videobuf2
)
631 vb2_queue_release(&icd
->vb2_vidq
);
632 ici
->ops
->remove(icd
);
634 __soc_camera_power_off(icd
);
637 if (icd
->streamer
== file
)
638 icd
->streamer
= NULL
;
639 mutex_unlock(&ici
->host_lock
);
641 module_put(ici
->ops
->owner
);
643 dev_dbg(icd
->pdev
, "camera device close\n");
648 static ssize_t
soc_camera_read(struct file
*file
, char __user
*buf
,
649 size_t count
, loff_t
*ppos
)
651 struct soc_camera_device
*icd
= file
->private_data
;
652 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
654 dev_dbg(icd
->pdev
, "read called, buf %p\n", buf
);
656 if (ici
->ops
->init_videobuf2
&& icd
->vb2_vidq
.io_modes
& VB2_READ
)
657 return vb2_read(&icd
->vb2_vidq
, buf
, count
, ppos
,
658 file
->f_flags
& O_NONBLOCK
);
660 dev_err(icd
->pdev
, "camera device read not implemented\n");
665 static int soc_camera_mmap(struct file
*file
, struct vm_area_struct
*vma
)
667 struct soc_camera_device
*icd
= file
->private_data
;
668 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
671 dev_dbg(icd
->pdev
, "mmap called, vma=0x%08lx\n", (unsigned long)vma
);
673 if (icd
->streamer
!= file
)
676 if (mutex_lock_interruptible(&ici
->host_lock
))
678 if (ici
->ops
->init_videobuf
)
679 err
= videobuf_mmap_mapper(&icd
->vb_vidq
, vma
);
681 err
= vb2_mmap(&icd
->vb2_vidq
, vma
);
682 mutex_unlock(&ici
->host_lock
);
684 dev_dbg(icd
->pdev
, "vma start=0x%08lx, size=%ld, ret=%d\n",
685 (unsigned long)vma
->vm_start
,
686 (unsigned long)vma
->vm_end
- (unsigned long)vma
->vm_start
,
692 static unsigned int soc_camera_poll(struct file
*file
, poll_table
*pt
)
694 struct soc_camera_device
*icd
= file
->private_data
;
695 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
696 unsigned res
= POLLERR
;
698 if (icd
->streamer
!= file
)
701 mutex_lock(&ici
->host_lock
);
702 if (ici
->ops
->init_videobuf
&& list_empty(&icd
->vb_vidq
.stream
))
703 dev_err(icd
->pdev
, "Trying to poll with no queued buffers!\n");
705 res
= ici
->ops
->poll(file
, pt
);
706 mutex_unlock(&ici
->host_lock
);
710 void soc_camera_lock(struct vb2_queue
*vq
)
712 struct soc_camera_device
*icd
= vb2_get_drv_priv(vq
);
713 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
714 mutex_lock(&ici
->host_lock
);
716 EXPORT_SYMBOL(soc_camera_lock
);
718 void soc_camera_unlock(struct vb2_queue
*vq
)
720 struct soc_camera_device
*icd
= vb2_get_drv_priv(vq
);
721 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
722 mutex_unlock(&ici
->host_lock
);
724 EXPORT_SYMBOL(soc_camera_unlock
);
726 static struct v4l2_file_operations soc_camera_fops
= {
727 .owner
= THIS_MODULE
,
728 .open
= soc_camera_open
,
729 .release
= soc_camera_close
,
730 .unlocked_ioctl
= video_ioctl2
,
731 .read
= soc_camera_read
,
732 .mmap
= soc_camera_mmap
,
733 .poll
= soc_camera_poll
,
736 static int soc_camera_s_fmt_vid_cap(struct file
*file
, void *priv
,
737 struct v4l2_format
*f
)
739 struct soc_camera_device
*icd
= file
->private_data
;
742 WARN_ON(priv
!= file
->private_data
);
744 if (f
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
745 dev_warn(icd
->pdev
, "Wrong buf-type %d\n", f
->type
);
749 if (icd
->streamer
&& icd
->streamer
!= file
)
752 if (is_streaming(to_soc_camera_host(icd
->parent
), icd
)) {
753 dev_err(icd
->pdev
, "S_FMT denied: queue initialised\n");
757 ret
= soc_camera_set_fmt(icd
, f
);
759 if (!ret
&& !icd
->streamer
)
760 icd
->streamer
= file
;
765 static int soc_camera_enum_fmt_vid_cap(struct file
*file
, void *priv
,
766 struct v4l2_fmtdesc
*f
)
768 struct soc_camera_device
*icd
= file
->private_data
;
769 const struct soc_mbus_pixelfmt
*format
;
771 WARN_ON(priv
!= file
->private_data
);
773 if (f
->index
>= icd
->num_user_formats
)
776 format
= icd
->user_formats
[f
->index
].host_fmt
;
779 strlcpy(f
->description
, format
->name
, sizeof(f
->description
));
780 f
->pixelformat
= format
->fourcc
;
784 static int soc_camera_g_fmt_vid_cap(struct file
*file
, void *priv
,
785 struct v4l2_format
*f
)
787 struct soc_camera_device
*icd
= file
->private_data
;
788 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
790 WARN_ON(priv
!= file
->private_data
);
792 if (f
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
795 pix
->width
= icd
->user_width
;
796 pix
->height
= icd
->user_height
;
797 pix
->bytesperline
= icd
->bytesperline
;
798 pix
->sizeimage
= icd
->sizeimage
;
799 pix
->field
= icd
->field
;
800 pix
->pixelformat
= icd
->current_fmt
->host_fmt
->fourcc
;
801 pix
->colorspace
= icd
->colorspace
;
802 dev_dbg(icd
->pdev
, "current_fmt->fourcc: 0x%08x\n",
803 icd
->current_fmt
->host_fmt
->fourcc
);
807 static int soc_camera_querycap(struct file
*file
, void *priv
,
808 struct v4l2_capability
*cap
)
810 struct soc_camera_device
*icd
= file
->private_data
;
811 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
813 WARN_ON(priv
!= file
->private_data
);
815 strlcpy(cap
->driver
, ici
->drv_name
, sizeof(cap
->driver
));
816 return ici
->ops
->querycap(ici
, cap
);
819 static int soc_camera_streamon(struct file
*file
, void *priv
,
820 enum v4l2_buf_type i
)
822 struct soc_camera_device
*icd
= file
->private_data
;
823 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
824 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
827 WARN_ON(priv
!= file
->private_data
);
829 if (i
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
832 if (icd
->streamer
!= file
)
835 /* This calls buf_queue from host driver's videobuf_queue_ops */
836 if (ici
->ops
->init_videobuf
)
837 ret
= videobuf_streamon(&icd
->vb_vidq
);
839 ret
= vb2_streamon(&icd
->vb2_vidq
, i
);
842 v4l2_subdev_call(sd
, video
, s_stream
, 1);
847 static int soc_camera_streamoff(struct file
*file
, void *priv
,
848 enum v4l2_buf_type i
)
850 struct soc_camera_device
*icd
= file
->private_data
;
851 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
852 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
854 WARN_ON(priv
!= file
->private_data
);
856 if (i
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
859 if (icd
->streamer
!= file
)
863 * This calls buf_release from host driver's videobuf_queue_ops for all
864 * remaining buffers. When the last buffer is freed, stop capture
866 if (ici
->ops
->init_videobuf
)
867 videobuf_streamoff(&icd
->vb_vidq
);
869 vb2_streamoff(&icd
->vb2_vidq
, i
);
871 v4l2_subdev_call(sd
, video
, s_stream
, 0);
876 static int soc_camera_cropcap(struct file
*file
, void *fh
,
877 struct v4l2_cropcap
*a
)
879 struct soc_camera_device
*icd
= file
->private_data
;
880 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
882 return ici
->ops
->cropcap(icd
, a
);
885 static int soc_camera_g_crop(struct file
*file
, void *fh
,
888 struct soc_camera_device
*icd
= file
->private_data
;
889 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
892 ret
= ici
->ops
->get_crop(icd
, a
);
898 * According to the V4L2 API, drivers shall not update the struct v4l2_crop
899 * argument with the actual geometry, instead, the user shall use G_CROP to
902 static int soc_camera_s_crop(struct file
*file
, void *fh
,
903 const struct v4l2_crop
*a
)
905 struct soc_camera_device
*icd
= file
->private_data
;
906 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
907 const struct v4l2_rect
*rect
= &a
->c
;
908 struct v4l2_crop current_crop
;
911 if (a
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
914 dev_dbg(icd
->pdev
, "S_CROP(%ux%u@%u:%u)\n",
915 rect
->width
, rect
->height
, rect
->left
, rect
->top
);
917 current_crop
.type
= a
->type
;
919 /* If get_crop fails, we'll let host and / or client drivers decide */
920 ret
= ici
->ops
->get_crop(icd
, ¤t_crop
);
922 /* Prohibit window size change with initialised buffers */
925 "S_CROP denied: getting current crop failed\n");
926 } else if ((a
->c
.width
== current_crop
.c
.width
&&
927 a
->c
.height
== current_crop
.c
.height
) ||
928 !is_streaming(ici
, icd
)) {
929 /* same size or not streaming - use .set_crop() */
930 ret
= ici
->ops
->set_crop(icd
, a
);
931 } else if (ici
->ops
->set_livecrop
) {
932 ret
= ici
->ops
->set_livecrop(icd
, a
);
935 "S_CROP denied: queue initialised and sizes differ\n");
942 static int soc_camera_g_selection(struct file
*file
, void *fh
,
943 struct v4l2_selection
*s
)
945 struct soc_camera_device
*icd
= file
->private_data
;
946 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
948 /* With a wrong type no need to try to fall back to cropping */
949 if (s
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
952 if (!ici
->ops
->get_selection
)
955 return ici
->ops
->get_selection(icd
, s
);
958 static int soc_camera_s_selection(struct file
*file
, void *fh
,
959 struct v4l2_selection
*s
)
961 struct soc_camera_device
*icd
= file
->private_data
;
962 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
965 /* In all these cases cropping emulation will not help */
966 if (s
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
||
967 (s
->target
!= V4L2_SEL_TGT_COMPOSE
&&
968 s
->target
!= V4L2_SEL_TGT_CROP
))
971 if (s
->target
== V4L2_SEL_TGT_COMPOSE
) {
972 /* No output size change during a running capture! */
973 if (is_streaming(ici
, icd
) &&
974 (icd
->user_width
!= s
->r
.width
||
975 icd
->user_height
!= s
->r
.height
))
979 * Only one user is allowed to change the output format, touch
980 * buffers, start / stop streaming, poll for data
982 if (icd
->streamer
&& icd
->streamer
!= file
)
986 if (!ici
->ops
->set_selection
)
989 ret
= ici
->ops
->set_selection(icd
, s
);
991 s
->target
== V4L2_SEL_TGT_COMPOSE
) {
992 icd
->user_width
= s
->r
.width
;
993 icd
->user_height
= s
->r
.height
;
995 icd
->streamer
= file
;
1001 static int soc_camera_g_parm(struct file
*file
, void *fh
,
1002 struct v4l2_streamparm
*a
)
1004 struct soc_camera_device
*icd
= file
->private_data
;
1005 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
1007 if (ici
->ops
->get_parm
)
1008 return ici
->ops
->get_parm(icd
, a
);
1010 return -ENOIOCTLCMD
;
1013 static int soc_camera_s_parm(struct file
*file
, void *fh
,
1014 struct v4l2_streamparm
*a
)
1016 struct soc_camera_device
*icd
= file
->private_data
;
1017 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
1019 if (ici
->ops
->set_parm
)
1020 return ici
->ops
->set_parm(icd
, a
);
1022 return -ENOIOCTLCMD
;
1025 static int soc_camera_g_chip_ident(struct file
*file
, void *fh
,
1026 struct v4l2_dbg_chip_ident
*id
)
1028 struct soc_camera_device
*icd
= file
->private_data
;
1029 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1031 return v4l2_subdev_call(sd
, core
, g_chip_ident
, id
);
1034 #ifdef CONFIG_VIDEO_ADV_DEBUG
1035 static int soc_camera_g_register(struct file
*file
, void *fh
,
1036 struct v4l2_dbg_register
*reg
)
1038 struct soc_camera_device
*icd
= file
->private_data
;
1039 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1041 return v4l2_subdev_call(sd
, core
, g_register
, reg
);
1044 static int soc_camera_s_register(struct file
*file
, void *fh
,
1045 struct v4l2_dbg_register
*reg
)
1047 struct soc_camera_device
*icd
= file
->private_data
;
1048 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1050 return v4l2_subdev_call(sd
, core
, s_register
, reg
);
1054 static int soc_camera_probe(struct soc_camera_device
*icd
);
1056 /* So far this function cannot fail */
1057 static void scan_add_host(struct soc_camera_host
*ici
)
1059 struct soc_camera_device
*icd
;
1061 mutex_lock(&list_lock
);
1063 list_for_each_entry(icd
, &devices
, list
) {
1064 if (icd
->iface
== ici
->nr
) {
1065 icd
->parent
= ici
->v4l2_dev
.dev
;
1066 soc_camera_probe(icd
);
1070 mutex_unlock(&list_lock
);
1073 #ifdef CONFIG_I2C_BOARDINFO
1074 static int soc_camera_init_i2c(struct soc_camera_device
*icd
,
1075 struct soc_camera_link
*icl
)
1077 struct i2c_client
*client
;
1078 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
1079 struct i2c_adapter
*adap
= i2c_get_adapter(icl
->i2c_adapter_id
);
1080 struct v4l2_subdev
*subdev
;
1083 dev_err(icd
->pdev
, "Cannot get I2C adapter #%d. No driver?\n",
1084 icl
->i2c_adapter_id
);
1088 icl
->board_info
->platform_data
= icl
;
1090 subdev
= v4l2_i2c_new_subdev_board(&ici
->v4l2_dev
, adap
,
1091 icl
->board_info
, NULL
);
1095 client
= v4l2_get_subdevdata(subdev
);
1097 /* Use to_i2c_client(dev) to recover the i2c client */
1098 icd
->control
= &client
->dev
;
1102 i2c_put_adapter(adap
);
1107 static void soc_camera_free_i2c(struct soc_camera_device
*icd
)
1109 struct i2c_client
*client
=
1110 to_i2c_client(to_soc_camera_control(icd
));
1111 struct i2c_adapter
*adap
= client
->adapter
;
1113 icd
->control
= NULL
;
1114 v4l2_device_unregister_subdev(i2c_get_clientdata(client
));
1115 i2c_unregister_device(client
);
1116 i2c_put_adapter(adap
);
1119 #define soc_camera_init_i2c(icd, icl) (-ENODEV)
1120 #define soc_camera_free_i2c(icd) do {} while (0)
1123 static int soc_camera_video_start(struct soc_camera_device
*icd
);
1124 static int video_dev_create(struct soc_camera_device
*icd
);
1125 /* Called during host-driver probe */
1126 static int soc_camera_probe(struct soc_camera_device
*icd
)
1128 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
1129 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
1130 struct device
*control
= NULL
;
1131 struct v4l2_subdev
*sd
;
1132 struct v4l2_mbus_framefmt mf
;
1135 dev_info(icd
->pdev
, "Probing %s\n", dev_name(icd
->pdev
));
1138 * Currently the subdev with the largest number of controls (13) is
1139 * ov6550. So let's pick 16 as a hint for the control handler. Note
1140 * that this is a hint only: too large and you waste some memory, too
1141 * small and there is a (very) small performance hit when looking up
1142 * controls in the internal hash.
1144 ret
= v4l2_ctrl_handler_init(&icd
->ctrl_handler
, 16);
1148 /* The camera could have been already on, try to reset */
1150 icl
->reset(icd
->pdev
);
1152 mutex_lock(&ici
->host_lock
);
1153 ret
= ici
->ops
->add(icd
);
1154 mutex_unlock(&ici
->host_lock
);
1158 /* Must have icd->vdev before registering the device */
1159 ret
= video_dev_create(icd
);
1163 /* Non-i2c cameras, e.g., soc_camera_platform, have no board_info */
1164 if (icl
->board_info
) {
1165 ret
= soc_camera_init_i2c(icd
, icl
);
1168 } else if (!icl
->add_device
|| !icl
->del_device
) {
1172 if (icl
->module_name
)
1173 ret
= request_module(icl
->module_name
);
1175 ret
= icl
->add_device(icd
);
1180 * FIXME: this is racy, have to use driver-binding notification,
1181 * when it is available
1183 control
= to_soc_camera_control(icd
);
1184 if (!control
|| !control
->driver
|| !dev_get_drvdata(control
) ||
1185 !try_module_get(control
->driver
->owner
)) {
1186 icl
->del_device(icd
);
1192 sd
= soc_camera_to_subdev(icd
);
1193 sd
->grp_id
= soc_camera_grp_id(icd
);
1194 v4l2_set_subdev_hostdata(sd
, icd
);
1196 ret
= v4l2_ctrl_add_handler(&icd
->ctrl_handler
, sd
->ctrl_handler
, NULL
);
1200 /* At this point client .probe() should have run already */
1201 ret
= soc_camera_init_user_formats(icd
);
1205 icd
->field
= V4L2_FIELD_ANY
;
1208 * ..._video_start() will create a device node, video_register_device()
1209 * itself is protected against concurrent open() calls, but we also have
1210 * to protect our data.
1212 mutex_lock(&ici
->host_lock
);
1214 ret
= soc_camera_video_start(icd
);
1218 /* Try to improve our guess of a reasonable window format */
1219 if (!v4l2_subdev_call(sd
, video
, g_mbus_fmt
, &mf
)) {
1220 icd
->user_width
= mf
.width
;
1221 icd
->user_height
= mf
.height
;
1222 icd
->colorspace
= mf
.colorspace
;
1223 icd
->field
= mf
.field
;
1226 ici
->ops
->remove(icd
);
1228 mutex_unlock(&ici
->host_lock
);
1233 mutex_unlock(&ici
->host_lock
);
1234 soc_camera_free_user_formats(icd
);
1237 if (icl
->board_info
) {
1238 soc_camera_free_i2c(icd
);
1240 icl
->del_device(icd
);
1241 module_put(control
->driver
->owner
);
1245 video_device_release(icd
->vdev
);
1248 mutex_lock(&ici
->host_lock
);
1249 ici
->ops
->remove(icd
);
1250 mutex_unlock(&ici
->host_lock
);
1252 v4l2_ctrl_handler_free(&icd
->ctrl_handler
);
1257 * This is called on device_unregister, which only means we have to disconnect
1258 * from the host, but not remove ourselves from the device list
1260 static int soc_camera_remove(struct soc_camera_device
*icd
)
1262 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
1263 struct video_device
*vdev
= icd
->vdev
;
1265 BUG_ON(!icd
->parent
);
1267 v4l2_ctrl_handler_free(&icd
->ctrl_handler
);
1269 video_unregister_device(vdev
);
1273 if (icl
->board_info
) {
1274 soc_camera_free_i2c(icd
);
1276 struct device_driver
*drv
= to_soc_camera_control(icd
)->driver
;
1278 icl
->del_device(icd
);
1279 module_put(drv
->owner
);
1282 soc_camera_free_user_formats(icd
);
1287 static int default_cropcap(struct soc_camera_device
*icd
,
1288 struct v4l2_cropcap
*a
)
1290 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1291 return v4l2_subdev_call(sd
, video
, cropcap
, a
);
1294 static int default_g_crop(struct soc_camera_device
*icd
, struct v4l2_crop
*a
)
1296 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1297 return v4l2_subdev_call(sd
, video
, g_crop
, a
);
1300 static int default_s_crop(struct soc_camera_device
*icd
, const struct v4l2_crop
*a
)
1302 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1303 return v4l2_subdev_call(sd
, video
, s_crop
, a
);
1306 static int default_g_parm(struct soc_camera_device
*icd
,
1307 struct v4l2_streamparm
*parm
)
1309 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1310 return v4l2_subdev_call(sd
, video
, g_parm
, parm
);
1313 static int default_s_parm(struct soc_camera_device
*icd
,
1314 struct v4l2_streamparm
*parm
)
1316 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1317 return v4l2_subdev_call(sd
, video
, s_parm
, parm
);
1320 static int default_enum_framesizes(struct soc_camera_device
*icd
,
1321 struct v4l2_frmsizeenum
*fsize
)
1324 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1325 const struct soc_camera_format_xlate
*xlate
;
1326 __u32 pixfmt
= fsize
->pixel_format
;
1327 struct v4l2_frmsizeenum fsize_mbus
= *fsize
;
1329 xlate
= soc_camera_xlate_by_fourcc(icd
, pixfmt
);
1332 /* map xlate-code to pixel_format, sensor only handle xlate-code*/
1333 fsize_mbus
.pixel_format
= xlate
->code
;
1335 ret
= v4l2_subdev_call(sd
, video
, enum_framesizes
, &fsize_mbus
);
1339 *fsize
= fsize_mbus
;
1340 fsize
->pixel_format
= pixfmt
;
1345 int soc_camera_host_register(struct soc_camera_host
*ici
)
1347 struct soc_camera_host
*ix
;
1350 if (!ici
|| !ici
->ops
||
1351 !ici
->ops
->try_fmt
||
1352 !ici
->ops
->set_fmt
||
1353 !ici
->ops
->set_bus_param
||
1354 !ici
->ops
->querycap
||
1355 ((!ici
->ops
->init_videobuf
||
1356 !ici
->ops
->reqbufs
) &&
1357 !ici
->ops
->init_videobuf2
) ||
1359 !ici
->ops
->remove
||
1364 if (!ici
->ops
->set_crop
)
1365 ici
->ops
->set_crop
= default_s_crop
;
1366 if (!ici
->ops
->get_crop
)
1367 ici
->ops
->get_crop
= default_g_crop
;
1368 if (!ici
->ops
->cropcap
)
1369 ici
->ops
->cropcap
= default_cropcap
;
1370 if (!ici
->ops
->set_parm
)
1371 ici
->ops
->set_parm
= default_s_parm
;
1372 if (!ici
->ops
->get_parm
)
1373 ici
->ops
->get_parm
= default_g_parm
;
1374 if (!ici
->ops
->enum_framesizes
)
1375 ici
->ops
->enum_framesizes
= default_enum_framesizes
;
1377 mutex_lock(&list_lock
);
1378 list_for_each_entry(ix
, &hosts
, list
) {
1379 if (ix
->nr
== ici
->nr
) {
1385 ret
= v4l2_device_register(ici
->v4l2_dev
.dev
, &ici
->v4l2_dev
);
1389 list_add_tail(&ici
->list
, &hosts
);
1390 mutex_unlock(&list_lock
);
1392 mutex_init(&ici
->host_lock
);
1398 mutex_unlock(&list_lock
);
1401 EXPORT_SYMBOL(soc_camera_host_register
);
1403 /* Unregister all clients! */
1404 void soc_camera_host_unregister(struct soc_camera_host
*ici
)
1406 struct soc_camera_device
*icd
;
1408 mutex_lock(&list_lock
);
1410 list_del(&ici
->list
);
1411 list_for_each_entry(icd
, &devices
, list
)
1412 if (icd
->iface
== ici
->nr
&& to_soc_camera_control(icd
))
1413 soc_camera_remove(icd
);
1415 mutex_unlock(&list_lock
);
1417 v4l2_device_unregister(&ici
->v4l2_dev
);
1419 EXPORT_SYMBOL(soc_camera_host_unregister
);
1421 /* Image capture device */
1422 static int soc_camera_device_register(struct soc_camera_device
*icd
)
1424 struct soc_camera_device
*ix
;
1427 for (i
= 0; i
< 256 && num
< 0; i
++) {
1429 /* Check if this index is available on this interface */
1430 list_for_each_entry(ix
, &devices
, list
) {
1431 if (ix
->iface
== icd
->iface
&& ix
->devnum
== i
) {
1440 * ok, we have 256 cameras on this host...
1441 * man, stay reasonable...
1447 icd
->host_priv
= NULL
;
1449 list_add_tail(&icd
->list
, &devices
);
1454 static const struct v4l2_ioctl_ops soc_camera_ioctl_ops
= {
1455 .vidioc_querycap
= soc_camera_querycap
,
1456 .vidioc_try_fmt_vid_cap
= soc_camera_try_fmt_vid_cap
,
1457 .vidioc_g_fmt_vid_cap
= soc_camera_g_fmt_vid_cap
,
1458 .vidioc_s_fmt_vid_cap
= soc_camera_s_fmt_vid_cap
,
1459 .vidioc_enum_fmt_vid_cap
= soc_camera_enum_fmt_vid_cap
,
1460 .vidioc_enum_input
= soc_camera_enum_input
,
1461 .vidioc_g_input
= soc_camera_g_input
,
1462 .vidioc_s_input
= soc_camera_s_input
,
1463 .vidioc_s_std
= soc_camera_s_std
,
1464 .vidioc_g_std
= soc_camera_g_std
,
1465 .vidioc_enum_framesizes
= soc_camera_enum_framesizes
,
1466 .vidioc_reqbufs
= soc_camera_reqbufs
,
1467 .vidioc_querybuf
= soc_camera_querybuf
,
1468 .vidioc_qbuf
= soc_camera_qbuf
,
1469 .vidioc_dqbuf
= soc_camera_dqbuf
,
1470 .vidioc_create_bufs
= soc_camera_create_bufs
,
1471 .vidioc_prepare_buf
= soc_camera_prepare_buf
,
1472 .vidioc_streamon
= soc_camera_streamon
,
1473 .vidioc_streamoff
= soc_camera_streamoff
,
1474 .vidioc_cropcap
= soc_camera_cropcap
,
1475 .vidioc_g_crop
= soc_camera_g_crop
,
1476 .vidioc_s_crop
= soc_camera_s_crop
,
1477 .vidioc_g_selection
= soc_camera_g_selection
,
1478 .vidioc_s_selection
= soc_camera_s_selection
,
1479 .vidioc_g_parm
= soc_camera_g_parm
,
1480 .vidioc_s_parm
= soc_camera_s_parm
,
1481 .vidioc_g_chip_ident
= soc_camera_g_chip_ident
,
1482 #ifdef CONFIG_VIDEO_ADV_DEBUG
1483 .vidioc_g_register
= soc_camera_g_register
,
1484 .vidioc_s_register
= soc_camera_s_register
,
1488 static int video_dev_create(struct soc_camera_device
*icd
)
1490 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
1491 struct video_device
*vdev
= video_device_alloc();
1496 strlcpy(vdev
->name
, ici
->drv_name
, sizeof(vdev
->name
));
1498 vdev
->parent
= icd
->pdev
;
1499 vdev
->current_norm
= V4L2_STD_UNKNOWN
;
1500 vdev
->fops
= &soc_camera_fops
;
1501 vdev
->ioctl_ops
= &soc_camera_ioctl_ops
;
1502 vdev
->release
= video_device_release
;
1503 vdev
->tvnorms
= V4L2_STD_UNKNOWN
;
1504 vdev
->ctrl_handler
= &icd
->ctrl_handler
;
1505 vdev
->lock
= &ici
->host_lock
;
1513 * Called from soc_camera_probe() above with .host_lock held
1515 static int soc_camera_video_start(struct soc_camera_device
*icd
)
1517 const struct device_type
*type
= icd
->vdev
->dev
.type
;
1523 ret
= video_register_device(icd
->vdev
, VFL_TYPE_GRABBER
, -1);
1525 dev_err(icd
->pdev
, "video_register_device failed: %d\n", ret
);
1529 /* Restore device type, possibly set by the subdevice driver */
1530 icd
->vdev
->dev
.type
= type
;
1535 static int __devinit
soc_camera_pdrv_probe(struct platform_device
*pdev
)
1537 struct soc_camera_link
*icl
= pdev
->dev
.platform_data
;
1538 struct soc_camera_device
*icd
;
1544 icd
= devm_kzalloc(&pdev
->dev
, sizeof(*icd
), GFP_KERNEL
);
1548 ret
= devm_regulator_bulk_get(&pdev
->dev
, icl
->num_regulators
,
1553 icd
->iface
= icl
->bus_id
;
1555 icd
->pdev
= &pdev
->dev
;
1556 platform_set_drvdata(pdev
, icd
);
1558 icd
->user_width
= DEFAULT_WIDTH
;
1559 icd
->user_height
= DEFAULT_HEIGHT
;
1561 return soc_camera_device_register(icd
);
1565 * Only called on rmmod for each platform device, since they are not
1566 * hot-pluggable. Now we know, that all our users - hosts and devices have
1567 * been unloaded already
1569 static int __devexit
soc_camera_pdrv_remove(struct platform_device
*pdev
)
1571 struct soc_camera_device
*icd
= platform_get_drvdata(pdev
);
1576 list_del(&icd
->list
);
1581 static struct platform_driver __refdata soc_camera_pdrv
= {
1582 .probe
= soc_camera_pdrv_probe
,
1583 .remove
= __devexit_p(soc_camera_pdrv_remove
),
1585 .name
= "soc-camera-pdrv",
1586 .owner
= THIS_MODULE
,
1590 module_platform_driver(soc_camera_pdrv
);
1592 MODULE_DESCRIPTION("Image capture bus driver");
1593 MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
1594 MODULE_LICENSE("GPL");
1595 MODULE_ALIAS("platform:soc-camera-pdrv");