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 static int soc_camera_power_set(struct soc_camera_device
*icd
,
54 struct soc_camera_link
*icl
,
60 ret
= regulator_bulk_enable(icl
->num_regulators
,
63 dev_err(&icd
->dev
, "Cannot enable regulators\n");
68 ret
= icl
->power(icd
->pdev
, power_on
);
71 "Platform failed to power-on the camera.\n");
73 regulator_bulk_disable(icl
->num_regulators
,
80 ret
= icl
->power(icd
->pdev
, 0);
83 "Platform failed to power-off the camera.\n");
87 ret
= regulator_bulk_disable(icl
->num_regulators
,
90 dev_err(&icd
->dev
, "Cannot disable regulators\n");
98 const struct soc_camera_format_xlate
*soc_camera_xlate_by_fourcc(
99 struct soc_camera_device
*icd
, unsigned int fourcc
)
103 for (i
= 0; i
< icd
->num_user_formats
; i
++)
104 if (icd
->user_formats
[i
].host_fmt
->fourcc
== fourcc
)
105 return icd
->user_formats
+ i
;
108 EXPORT_SYMBOL(soc_camera_xlate_by_fourcc
);
111 * soc_camera_apply_sensor_flags() - apply platform SOCAM_SENSOR_INVERT_* flags
112 * @icl: camera platform parameters
113 * @flags: flags to be inverted according to platform configuration
114 * @return: resulting flags
116 unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link
*icl
,
121 /* If only one of the two polarities is supported, switch to the opposite */
122 if (icl
->flags
& SOCAM_SENSOR_INVERT_HSYNC
) {
123 f
= flags
& (SOCAM_HSYNC_ACTIVE_HIGH
| SOCAM_HSYNC_ACTIVE_LOW
);
124 if (f
== SOCAM_HSYNC_ACTIVE_HIGH
|| f
== SOCAM_HSYNC_ACTIVE_LOW
)
125 flags
^= SOCAM_HSYNC_ACTIVE_HIGH
| SOCAM_HSYNC_ACTIVE_LOW
;
128 if (icl
->flags
& SOCAM_SENSOR_INVERT_VSYNC
) {
129 f
= flags
& (SOCAM_VSYNC_ACTIVE_HIGH
| SOCAM_VSYNC_ACTIVE_LOW
);
130 if (f
== SOCAM_VSYNC_ACTIVE_HIGH
|| f
== SOCAM_VSYNC_ACTIVE_LOW
)
131 flags
^= SOCAM_VSYNC_ACTIVE_HIGH
| SOCAM_VSYNC_ACTIVE_LOW
;
134 if (icl
->flags
& SOCAM_SENSOR_INVERT_PCLK
) {
135 f
= flags
& (SOCAM_PCLK_SAMPLE_RISING
| SOCAM_PCLK_SAMPLE_FALLING
);
136 if (f
== SOCAM_PCLK_SAMPLE_RISING
|| f
== SOCAM_PCLK_SAMPLE_FALLING
)
137 flags
^= SOCAM_PCLK_SAMPLE_RISING
| SOCAM_PCLK_SAMPLE_FALLING
;
142 EXPORT_SYMBOL(soc_camera_apply_sensor_flags
);
144 #define pixfmtstr(x) (x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, \
147 static int soc_camera_try_fmt(struct soc_camera_device
*icd
,
148 struct v4l2_format
*f
)
150 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
151 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
154 dev_dbg(&icd
->dev
, "TRY_FMT(%c%c%c%c, %ux%u)\n",
155 pixfmtstr(pix
->pixelformat
), pix
->width
, pix
->height
);
157 pix
->bytesperline
= 0;
160 ret
= ici
->ops
->try_fmt(icd
, f
);
164 if (!pix
->sizeimage
) {
165 if (!pix
->bytesperline
) {
166 const struct soc_camera_format_xlate
*xlate
;
168 xlate
= soc_camera_xlate_by_fourcc(icd
, pix
->pixelformat
);
172 ret
= soc_mbus_bytes_per_line(pix
->width
,
175 pix
->bytesperline
= ret
;
177 if (pix
->bytesperline
)
178 pix
->sizeimage
= pix
->bytesperline
* pix
->height
;
184 static int soc_camera_try_fmt_vid_cap(struct file
*file
, void *priv
,
185 struct v4l2_format
*f
)
187 struct soc_camera_device
*icd
= file
->private_data
;
189 WARN_ON(priv
!= file
->private_data
);
191 /* Only single-plane capture is supported so far */
192 if (f
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
195 /* limit format to hardware capabilities */
196 return soc_camera_try_fmt(icd
, f
);
199 static int soc_camera_enum_input(struct file
*file
, void *priv
,
200 struct v4l2_input
*inp
)
202 struct soc_camera_device
*icd
= file
->private_data
;
208 if (icd
->ops
->enum_input
)
209 ret
= icd
->ops
->enum_input(icd
, inp
);
211 /* default is camera */
212 inp
->type
= V4L2_INPUT_TYPE_CAMERA
;
213 inp
->std
= V4L2_STD_UNKNOWN
;
214 strcpy(inp
->name
, "Camera");
220 static int soc_camera_g_input(struct file
*file
, void *priv
, unsigned int *i
)
227 static int soc_camera_s_input(struct file
*file
, void *priv
, unsigned int i
)
235 static int soc_camera_s_std(struct file
*file
, void *priv
, v4l2_std_id
*a
)
237 struct soc_camera_device
*icd
= file
->private_data
;
238 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
240 return v4l2_subdev_call(sd
, core
, s_std
, *a
);
243 static int soc_camera_enum_fsizes(struct file
*file
, void *fh
,
244 struct v4l2_frmsizeenum
*fsize
)
246 struct soc_camera_device
*icd
= file
->private_data
;
247 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
249 return ici
->ops
->enum_fsizes(icd
, fsize
);
252 static int soc_camera_reqbufs(struct file
*file
, void *priv
,
253 struct v4l2_requestbuffers
*p
)
256 struct soc_camera_device
*icd
= file
->private_data
;
257 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
259 WARN_ON(priv
!= file
->private_data
);
261 if (icd
->streamer
&& icd
->streamer
!= file
)
264 if (ici
->ops
->init_videobuf
) {
265 ret
= videobuf_reqbufs(&icd
->vb_vidq
, p
);
269 ret
= ici
->ops
->reqbufs(icd
, p
);
271 ret
= vb2_reqbufs(&icd
->vb2_vidq
, p
);
274 if (!ret
&& !icd
->streamer
)
275 icd
->streamer
= file
;
280 static int soc_camera_querybuf(struct file
*file
, void *priv
,
281 struct v4l2_buffer
*p
)
283 struct soc_camera_device
*icd
= file
->private_data
;
284 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
286 WARN_ON(priv
!= file
->private_data
);
288 if (ici
->ops
->init_videobuf
)
289 return videobuf_querybuf(&icd
->vb_vidq
, p
);
291 return vb2_querybuf(&icd
->vb2_vidq
, p
);
294 static int soc_camera_qbuf(struct file
*file
, void *priv
,
295 struct v4l2_buffer
*p
)
297 struct soc_camera_device
*icd
= file
->private_data
;
298 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
300 WARN_ON(priv
!= file
->private_data
);
302 if (icd
->streamer
!= file
)
305 if (ici
->ops
->init_videobuf
)
306 return videobuf_qbuf(&icd
->vb_vidq
, p
);
308 return vb2_qbuf(&icd
->vb2_vidq
, p
);
311 static int soc_camera_dqbuf(struct file
*file
, void *priv
,
312 struct v4l2_buffer
*p
)
314 struct soc_camera_device
*icd
= file
->private_data
;
315 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
317 WARN_ON(priv
!= file
->private_data
);
319 if (icd
->streamer
!= file
)
322 if (ici
->ops
->init_videobuf
)
323 return videobuf_dqbuf(&icd
->vb_vidq
, p
, file
->f_flags
& O_NONBLOCK
);
325 return vb2_dqbuf(&icd
->vb2_vidq
, p
, file
->f_flags
& O_NONBLOCK
);
328 /* Always entered with .video_lock held */
329 static int soc_camera_init_user_formats(struct soc_camera_device
*icd
)
331 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
332 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
333 unsigned int i
, fmts
= 0, raw_fmts
= 0;
335 enum v4l2_mbus_pixelcode code
;
337 while (!v4l2_subdev_call(sd
, video
, enum_mbus_fmt
, raw_fmts
, &code
))
340 if (!ici
->ops
->get_formats
)
342 * Fallback mode - the host will have to serve all
343 * sensor-provided formats one-to-one to the user
348 * First pass - only count formats this host-sensor
349 * configuration can provide
351 for (i
= 0; i
< raw_fmts
; i
++) {
352 ret
= ici
->ops
->get_formats(icd
, i
, NULL
);
362 vmalloc(fmts
* sizeof(struct soc_camera_format_xlate
));
363 if (!icd
->user_formats
)
366 dev_dbg(&icd
->dev
, "Found %d supported formats.\n", fmts
);
368 /* Second pass - actually fill data formats */
370 for (i
= 0; i
< raw_fmts
; i
++)
371 if (!ici
->ops
->get_formats
) {
372 v4l2_subdev_call(sd
, video
, enum_mbus_fmt
, i
, &code
);
373 icd
->user_formats
[fmts
].host_fmt
=
374 soc_mbus_get_fmtdesc(code
);
375 if (icd
->user_formats
[fmts
].host_fmt
)
376 icd
->user_formats
[fmts
++].code
= code
;
378 ret
= ici
->ops
->get_formats(icd
, i
,
379 &icd
->user_formats
[fmts
]);
385 icd
->num_user_formats
= fmts
;
386 icd
->current_fmt
= &icd
->user_formats
[0];
391 vfree(icd
->user_formats
);
395 /* Always entered with .video_lock held */
396 static void soc_camera_free_user_formats(struct soc_camera_device
*icd
)
398 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
400 if (ici
->ops
->put_formats
)
401 ici
->ops
->put_formats(icd
);
402 icd
->current_fmt
= NULL
;
403 icd
->num_user_formats
= 0;
404 vfree(icd
->user_formats
);
405 icd
->user_formats
= NULL
;
408 /* Called with .vb_lock held, or from the first open(2), see comment there */
409 static int soc_camera_set_fmt(struct soc_camera_device
*icd
,
410 struct v4l2_format
*f
)
412 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
413 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
416 dev_dbg(&icd
->dev
, "S_FMT(%c%c%c%c, %ux%u)\n",
417 pixfmtstr(pix
->pixelformat
), pix
->width
, pix
->height
);
419 /* We always call try_fmt() before set_fmt() or set_crop() */
420 ret
= soc_camera_try_fmt(icd
, f
);
424 ret
= ici
->ops
->set_fmt(icd
, f
);
427 } else if (!icd
->current_fmt
||
428 icd
->current_fmt
->host_fmt
->fourcc
!= pix
->pixelformat
) {
430 "Host driver hasn't set up current format correctly!\n");
434 icd
->user_width
= pix
->width
;
435 icd
->user_height
= pix
->height
;
436 icd
->bytesperline
= pix
->bytesperline
;
437 icd
->sizeimage
= pix
->sizeimage
;
438 icd
->colorspace
= pix
->colorspace
;
439 icd
->field
= pix
->field
;
440 if (ici
->ops
->init_videobuf
)
441 icd
->vb_vidq
.field
= pix
->field
;
443 dev_dbg(&icd
->dev
, "set width: %d height: %d\n",
444 icd
->user_width
, icd
->user_height
);
446 /* set physical bus parameters */
447 return ici
->ops
->set_bus_param(icd
, pix
->pixelformat
);
450 static int soc_camera_open(struct file
*file
)
452 struct video_device
*vdev
= video_devdata(file
);
453 struct soc_camera_device
*icd
= container_of(vdev
->parent
,
454 struct soc_camera_device
,
456 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
457 struct soc_camera_host
*ici
;
461 /* No device driver attached */
464 ici
= to_soc_camera_host(icd
->dev
.parent
);
466 if (!try_module_get(ici
->ops
->owner
)) {
467 dev_err(&icd
->dev
, "Couldn't lock capture bus driver.\n");
473 /* Now we really have to activate the camera */
474 if (icd
->use_count
== 1) {
475 /* Restore parameters before the last close() per V4L2 API */
476 struct v4l2_format f
= {
477 .type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
,
479 .width
= icd
->user_width
,
480 .height
= icd
->user_height
,
482 .colorspace
= icd
->colorspace
,
484 icd
->current_fmt
->host_fmt
->fourcc
,
488 ret
= soc_camera_power_set(icd
, icl
, 1);
492 /* The camera could have been already on, try to reset */
494 icl
->reset(icd
->pdev
);
496 ret
= ici
->ops
->add(icd
);
498 dev_err(&icd
->dev
, "Couldn't activate the camera: %d\n", ret
);
502 pm_runtime_enable(&icd
->vdev
->dev
);
503 ret
= pm_runtime_resume(&icd
->vdev
->dev
);
504 if (ret
< 0 && ret
!= -ENOSYS
)
508 * Try to configure with default parameters. Notice: this is the
509 * very first open, so, we cannot race against other calls,
510 * apart from someone else calling open() simultaneously, but
511 * .video_lock is protecting us against it.
513 ret
= soc_camera_set_fmt(icd
, &f
);
517 if (ici
->ops
->init_videobuf
) {
518 ici
->ops
->init_videobuf(&icd
->vb_vidq
, icd
);
520 ret
= ici
->ops
->init_videobuf2(&icd
->vb2_vidq
, icd
);
526 file
->private_data
= icd
;
527 dev_dbg(&icd
->dev
, "camera device open\n");
532 * First four errors are entered with the .video_lock held
537 pm_runtime_disable(&icd
->vdev
->dev
);
539 ici
->ops
->remove(icd
);
541 soc_camera_power_set(icd
, icl
, 0);
544 module_put(ici
->ops
->owner
);
549 static int soc_camera_close(struct file
*file
)
551 struct soc_camera_device
*icd
= file
->private_data
;
552 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
555 if (!icd
->use_count
) {
556 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
558 pm_runtime_suspend(&icd
->vdev
->dev
);
559 pm_runtime_disable(&icd
->vdev
->dev
);
561 ici
->ops
->remove(icd
);
562 if (ici
->ops
->init_videobuf2
)
563 vb2_queue_release(&icd
->vb2_vidq
);
565 soc_camera_power_set(icd
, icl
, 0);
568 if (icd
->streamer
== file
)
569 icd
->streamer
= NULL
;
571 module_put(ici
->ops
->owner
);
573 dev_dbg(&icd
->dev
, "camera device close\n");
578 static ssize_t
soc_camera_read(struct file
*file
, char __user
*buf
,
579 size_t count
, loff_t
*ppos
)
581 struct soc_camera_device
*icd
= file
->private_data
;
584 dev_err(&icd
->dev
, "camera device read not implemented\n");
589 static int soc_camera_mmap(struct file
*file
, struct vm_area_struct
*vma
)
591 struct soc_camera_device
*icd
= file
->private_data
;
592 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
595 dev_dbg(&icd
->dev
, "mmap called, vma=0x%08lx\n", (unsigned long)vma
);
597 if (icd
->streamer
!= file
)
600 if (ici
->ops
->init_videobuf
)
601 err
= videobuf_mmap_mapper(&icd
->vb_vidq
, vma
);
603 err
= vb2_mmap(&icd
->vb2_vidq
, vma
);
605 dev_dbg(&icd
->dev
, "vma start=0x%08lx, size=%ld, ret=%d\n",
606 (unsigned long)vma
->vm_start
,
607 (unsigned long)vma
->vm_end
- (unsigned long)vma
->vm_start
,
613 static unsigned int soc_camera_poll(struct file
*file
, poll_table
*pt
)
615 struct soc_camera_device
*icd
= file
->private_data
;
616 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
618 if (icd
->streamer
!= file
)
621 if (ici
->ops
->init_videobuf
&& list_empty(&icd
->vb_vidq
.stream
)) {
622 dev_err(&icd
->dev
, "Trying to poll with no queued buffers!\n");
626 return ici
->ops
->poll(file
, pt
);
629 void soc_camera_lock(struct vb2_queue
*vq
)
631 struct soc_camera_device
*icd
= vb2_get_drv_priv(vq
);
632 mutex_lock(&icd
->video_lock
);
634 EXPORT_SYMBOL(soc_camera_lock
);
636 void soc_camera_unlock(struct vb2_queue
*vq
)
638 struct soc_camera_device
*icd
= vb2_get_drv_priv(vq
);
639 mutex_unlock(&icd
->video_lock
);
641 EXPORT_SYMBOL(soc_camera_unlock
);
643 static struct v4l2_file_operations soc_camera_fops
= {
644 .owner
= THIS_MODULE
,
645 .open
= soc_camera_open
,
646 .release
= soc_camera_close
,
647 .unlocked_ioctl
= video_ioctl2
,
648 .read
= soc_camera_read
,
649 .mmap
= soc_camera_mmap
,
650 .poll
= soc_camera_poll
,
653 static int soc_camera_s_fmt_vid_cap(struct file
*file
, void *priv
,
654 struct v4l2_format
*f
)
656 struct soc_camera_device
*icd
= file
->private_data
;
659 WARN_ON(priv
!= file
->private_data
);
661 if (f
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
662 dev_warn(&icd
->dev
, "Wrong buf-type %d\n", f
->type
);
666 if (icd
->streamer
&& icd
->streamer
!= file
)
669 if (is_streaming(to_soc_camera_host(icd
->dev
.parent
), icd
)) {
670 dev_err(&icd
->dev
, "S_FMT denied: queue initialised\n");
674 ret
= soc_camera_set_fmt(icd
, f
);
676 if (!ret
&& !icd
->streamer
)
677 icd
->streamer
= file
;
682 static int soc_camera_enum_fmt_vid_cap(struct file
*file
, void *priv
,
683 struct v4l2_fmtdesc
*f
)
685 struct soc_camera_device
*icd
= file
->private_data
;
686 const struct soc_mbus_pixelfmt
*format
;
688 WARN_ON(priv
!= file
->private_data
);
690 if (f
->index
>= icd
->num_user_formats
)
693 format
= icd
->user_formats
[f
->index
].host_fmt
;
696 strlcpy(f
->description
, format
->name
, sizeof(f
->description
));
697 f
->pixelformat
= format
->fourcc
;
701 static int soc_camera_g_fmt_vid_cap(struct file
*file
, void *priv
,
702 struct v4l2_format
*f
)
704 struct soc_camera_device
*icd
= file
->private_data
;
705 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
707 WARN_ON(priv
!= file
->private_data
);
709 if (f
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
712 pix
->width
= icd
->user_width
;
713 pix
->height
= icd
->user_height
;
714 pix
->bytesperline
= icd
->bytesperline
;
715 pix
->sizeimage
= icd
->sizeimage
;
716 pix
->field
= icd
->field
;
717 pix
->pixelformat
= icd
->current_fmt
->host_fmt
->fourcc
;
718 pix
->colorspace
= icd
->colorspace
;
719 dev_dbg(&icd
->dev
, "current_fmt->fourcc: 0x%08x\n",
720 icd
->current_fmt
->host_fmt
->fourcc
);
724 static int soc_camera_querycap(struct file
*file
, void *priv
,
725 struct v4l2_capability
*cap
)
727 struct soc_camera_device
*icd
= file
->private_data
;
728 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
730 WARN_ON(priv
!= file
->private_data
);
732 strlcpy(cap
->driver
, ici
->drv_name
, sizeof(cap
->driver
));
733 return ici
->ops
->querycap(ici
, cap
);
736 static int soc_camera_streamon(struct file
*file
, void *priv
,
737 enum v4l2_buf_type i
)
739 struct soc_camera_device
*icd
= file
->private_data
;
740 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
741 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
744 WARN_ON(priv
!= file
->private_data
);
746 if (i
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
749 if (icd
->streamer
!= file
)
752 /* This calls buf_queue from host driver's videobuf_queue_ops */
753 if (ici
->ops
->init_videobuf
)
754 ret
= videobuf_streamon(&icd
->vb_vidq
);
756 ret
= vb2_streamon(&icd
->vb2_vidq
, i
);
759 v4l2_subdev_call(sd
, video
, s_stream
, 1);
764 static int soc_camera_streamoff(struct file
*file
, void *priv
,
765 enum v4l2_buf_type i
)
767 struct soc_camera_device
*icd
= file
->private_data
;
768 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
769 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
771 WARN_ON(priv
!= file
->private_data
);
773 if (i
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
776 if (icd
->streamer
!= file
)
780 * This calls buf_release from host driver's videobuf_queue_ops for all
781 * remaining buffers. When the last buffer is freed, stop capture
783 if (ici
->ops
->init_videobuf
)
784 videobuf_streamoff(&icd
->vb_vidq
);
786 vb2_streamoff(&icd
->vb2_vidq
, i
);
788 v4l2_subdev_call(sd
, video
, s_stream
, 0);
793 static int soc_camera_queryctrl(struct file
*file
, void *priv
,
794 struct v4l2_queryctrl
*qc
)
796 struct soc_camera_device
*icd
= file
->private_data
;
797 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
800 WARN_ON(priv
!= file
->private_data
);
805 /* First check host controls */
806 for (i
= 0; i
< ici
->ops
->num_controls
; i
++)
807 if (qc
->id
== ici
->ops
->controls
[i
].id
) {
808 memcpy(qc
, &(ici
->ops
->controls
[i
]),
813 /* Then device controls */
814 for (i
= 0; i
< icd
->ops
->num_controls
; i
++)
815 if (qc
->id
== icd
->ops
->controls
[i
].id
) {
816 memcpy(qc
, &(icd
->ops
->controls
[i
]),
824 static int soc_camera_g_ctrl(struct file
*file
, void *priv
,
825 struct v4l2_control
*ctrl
)
827 struct soc_camera_device
*icd
= file
->private_data
;
828 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
829 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
832 WARN_ON(priv
!= file
->private_data
);
834 if (ici
->ops
->get_ctrl
) {
835 ret
= ici
->ops
->get_ctrl(icd
, ctrl
);
836 if (ret
!= -ENOIOCTLCMD
)
840 return v4l2_subdev_call(sd
, core
, g_ctrl
, ctrl
);
843 static int soc_camera_s_ctrl(struct file
*file
, void *priv
,
844 struct v4l2_control
*ctrl
)
846 struct soc_camera_device
*icd
= file
->private_data
;
847 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
848 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
851 WARN_ON(priv
!= file
->private_data
);
853 if (ici
->ops
->set_ctrl
) {
854 ret
= ici
->ops
->set_ctrl(icd
, ctrl
);
855 if (ret
!= -ENOIOCTLCMD
)
859 return v4l2_subdev_call(sd
, core
, s_ctrl
, ctrl
);
862 static int soc_camera_cropcap(struct file
*file
, void *fh
,
863 struct v4l2_cropcap
*a
)
865 struct soc_camera_device
*icd
= file
->private_data
;
866 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
868 return ici
->ops
->cropcap(icd
, a
);
871 static int soc_camera_g_crop(struct file
*file
, void *fh
,
874 struct soc_camera_device
*icd
= file
->private_data
;
875 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
878 ret
= ici
->ops
->get_crop(icd
, a
);
884 * According to the V4L2 API, drivers shall not update the struct v4l2_crop
885 * argument with the actual geometry, instead, the user shall use G_CROP to
888 static int soc_camera_s_crop(struct file
*file
, void *fh
,
891 struct soc_camera_device
*icd
= file
->private_data
;
892 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
893 struct v4l2_rect
*rect
= &a
->c
;
894 struct v4l2_crop current_crop
;
897 if (a
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
900 dev_dbg(&icd
->dev
, "S_CROP(%ux%u@%u:%u)\n",
901 rect
->width
, rect
->height
, rect
->left
, rect
->top
);
903 /* If get_crop fails, we'll let host and / or client drivers decide */
904 ret
= ici
->ops
->get_crop(icd
, ¤t_crop
);
906 /* Prohibit window size change with initialised buffers */
909 "S_CROP denied: getting current crop failed\n");
910 } else if ((a
->c
.width
== current_crop
.c
.width
&&
911 a
->c
.height
== current_crop
.c
.height
) ||
912 !is_streaming(ici
, icd
)) {
913 /* same size or not streaming - use .set_crop() */
914 ret
= ici
->ops
->set_crop(icd
, a
);
915 } else if (ici
->ops
->set_livecrop
) {
916 ret
= ici
->ops
->set_livecrop(icd
, a
);
919 "S_CROP denied: queue initialised and sizes differ\n");
926 static int soc_camera_g_parm(struct file
*file
, void *fh
,
927 struct v4l2_streamparm
*a
)
929 struct soc_camera_device
*icd
= file
->private_data
;
930 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
932 if (ici
->ops
->get_parm
)
933 return ici
->ops
->get_parm(icd
, a
);
938 static int soc_camera_s_parm(struct file
*file
, void *fh
,
939 struct v4l2_streamparm
*a
)
941 struct soc_camera_device
*icd
= file
->private_data
;
942 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
944 if (ici
->ops
->set_parm
)
945 return ici
->ops
->set_parm(icd
, a
);
950 static int soc_camera_g_chip_ident(struct file
*file
, void *fh
,
951 struct v4l2_dbg_chip_ident
*id
)
953 struct soc_camera_device
*icd
= file
->private_data
;
954 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
956 return v4l2_subdev_call(sd
, core
, g_chip_ident
, id
);
959 #ifdef CONFIG_VIDEO_ADV_DEBUG
960 static int soc_camera_g_register(struct file
*file
, void *fh
,
961 struct v4l2_dbg_register
*reg
)
963 struct soc_camera_device
*icd
= file
->private_data
;
964 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
966 return v4l2_subdev_call(sd
, core
, g_register
, reg
);
969 static int soc_camera_s_register(struct file
*file
, void *fh
,
970 struct v4l2_dbg_register
*reg
)
972 struct soc_camera_device
*icd
= file
->private_data
;
973 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
975 return v4l2_subdev_call(sd
, core
, s_register
, reg
);
979 /* So far this function cannot fail */
980 static void scan_add_host(struct soc_camera_host
*ici
)
982 struct soc_camera_device
*icd
;
984 mutex_lock(&list_lock
);
986 list_for_each_entry(icd
, &devices
, list
) {
987 if (icd
->iface
== ici
->nr
) {
989 icd
->dev
.parent
= ici
->v4l2_dev
.dev
;
990 dev_set_name(&icd
->dev
, "%u-%u", icd
->iface
,
992 ret
= device_register(&icd
->dev
);
994 icd
->dev
.parent
= NULL
;
996 "Cannot register device: %d\n", ret
);
1001 mutex_unlock(&list_lock
);
1004 #ifdef CONFIG_I2C_BOARDINFO
1005 static int soc_camera_init_i2c(struct soc_camera_device
*icd
,
1006 struct soc_camera_link
*icl
)
1008 struct i2c_client
*client
;
1009 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
1010 struct i2c_adapter
*adap
= i2c_get_adapter(icl
->i2c_adapter_id
);
1011 struct v4l2_subdev
*subdev
;
1014 dev_err(&icd
->dev
, "Cannot get I2C adapter #%d. No driver?\n",
1015 icl
->i2c_adapter_id
);
1019 icl
->board_info
->platform_data
= icd
;
1021 subdev
= v4l2_i2c_new_subdev_board(&ici
->v4l2_dev
, adap
,
1022 icl
->board_info
, NULL
);
1026 client
= v4l2_get_subdevdata(subdev
);
1028 /* Use to_i2c_client(dev) to recover the i2c client */
1029 dev_set_drvdata(&icd
->dev
, &client
->dev
);
1033 i2c_put_adapter(adap
);
1038 static void soc_camera_free_i2c(struct soc_camera_device
*icd
)
1040 struct i2c_client
*client
=
1041 to_i2c_client(to_soc_camera_control(icd
));
1042 struct i2c_adapter
*adap
= client
->adapter
;
1043 dev_set_drvdata(&icd
->dev
, NULL
);
1044 v4l2_device_unregister_subdev(i2c_get_clientdata(client
));
1045 i2c_unregister_device(client
);
1046 i2c_put_adapter(adap
);
1049 #define soc_camera_init_i2c(icd, icl) (-ENODEV)
1050 #define soc_camera_free_i2c(icd) do {} while (0)
1053 static int soc_camera_video_start(struct soc_camera_device
*icd
);
1054 static int video_dev_create(struct soc_camera_device
*icd
);
1055 /* Called during host-driver probe */
1056 static int soc_camera_probe(struct device
*dev
)
1058 struct soc_camera_device
*icd
= to_soc_camera_dev(dev
);
1059 struct soc_camera_host
*ici
= to_soc_camera_host(dev
->parent
);
1060 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
1061 struct device
*control
= NULL
;
1062 struct v4l2_subdev
*sd
;
1063 struct v4l2_mbus_framefmt mf
;
1066 dev_info(dev
, "Probing %s\n", dev_name(dev
));
1068 ret
= regulator_bulk_get(icd
->pdev
, icl
->num_regulators
,
1073 ret
= soc_camera_power_set(icd
, icl
, 1);
1077 /* The camera could have been already on, try to reset */
1079 icl
->reset(icd
->pdev
);
1081 ret
= ici
->ops
->add(icd
);
1085 /* Must have icd->vdev before registering the device */
1086 ret
= video_dev_create(icd
);
1090 /* Non-i2c cameras, e.g., soc_camera_platform, have no board_info */
1091 if (icl
->board_info
) {
1092 ret
= soc_camera_init_i2c(icd
, icl
);
1095 } else if (!icl
->add_device
|| !icl
->del_device
) {
1099 if (icl
->module_name
)
1100 ret
= request_module(icl
->module_name
);
1102 ret
= icl
->add_device(icl
, &icd
->dev
);
1107 * FIXME: this is racy, have to use driver-binding notification,
1108 * when it is available
1110 control
= to_soc_camera_control(icd
);
1111 if (!control
|| !control
->driver
|| !dev_get_drvdata(control
) ||
1112 !try_module_get(control
->driver
->owner
)) {
1113 icl
->del_device(icl
);
1118 sd
= soc_camera_to_subdev(icd
);
1119 sd
->grp_id
= (long)icd
;
1121 /* At this point client .probe() should have run already */
1122 ret
= soc_camera_init_user_formats(icd
);
1126 icd
->field
= V4L2_FIELD_ANY
;
1128 icd
->vdev
->lock
= &icd
->video_lock
;
1131 * ..._video_start() will create a device node, video_register_device()
1132 * itself is protected against concurrent open() calls, but we also have
1133 * to protect our data.
1135 mutex_lock(&icd
->video_lock
);
1137 ret
= soc_camera_video_start(icd
);
1141 /* Try to improve our guess of a reasonable window format */
1142 if (!v4l2_subdev_call(sd
, video
, g_mbus_fmt
, &mf
)) {
1143 icd
->user_width
= mf
.width
;
1144 icd
->user_height
= mf
.height
;
1145 icd
->colorspace
= mf
.colorspace
;
1146 icd
->field
= mf
.field
;
1149 /* Do we have to sysfs_remove_link() before device_unregister()? */
1150 if (sysfs_create_link(&icd
->dev
.kobj
, &to_soc_camera_control(icd
)->kobj
,
1152 dev_warn(&icd
->dev
, "Failed creating the control symlink\n");
1154 ici
->ops
->remove(icd
);
1156 soc_camera_power_set(icd
, icl
, 0);
1158 mutex_unlock(&icd
->video_lock
);
1163 mutex_unlock(&icd
->video_lock
);
1164 soc_camera_free_user_formats(icd
);
1166 if (icl
->board_info
) {
1167 soc_camera_free_i2c(icd
);
1169 icl
->del_device(icl
);
1170 module_put(control
->driver
->owner
);
1174 video_device_release(icd
->vdev
);
1176 ici
->ops
->remove(icd
);
1178 soc_camera_power_set(icd
, icl
, 0);
1180 regulator_bulk_free(icl
->num_regulators
, icl
->regulators
);
1186 * This is called on device_unregister, which only means we have to disconnect
1187 * from the host, but not remove ourselves from the device list
1189 static int soc_camera_remove(struct device
*dev
)
1191 struct soc_camera_device
*icd
= to_soc_camera_dev(dev
);
1192 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
1193 struct video_device
*vdev
= icd
->vdev
;
1195 BUG_ON(!dev
->parent
);
1198 video_unregister_device(vdev
);
1202 if (icl
->board_info
) {
1203 soc_camera_free_i2c(icd
);
1205 struct device_driver
*drv
= to_soc_camera_control(icd
) ?
1206 to_soc_camera_control(icd
)->driver
: NULL
;
1208 icl
->del_device(icl
);
1209 module_put(drv
->owner
);
1212 soc_camera_free_user_formats(icd
);
1214 regulator_bulk_free(icl
->num_regulators
, icl
->regulators
);
1219 static int soc_camera_suspend(struct device
*dev
, pm_message_t state
)
1221 struct soc_camera_device
*icd
= to_soc_camera_dev(dev
);
1222 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
1225 if (ici
->ops
->suspend
)
1226 ret
= ici
->ops
->suspend(icd
, state
);
1231 static int soc_camera_resume(struct device
*dev
)
1233 struct soc_camera_device
*icd
= to_soc_camera_dev(dev
);
1234 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->dev
.parent
);
1237 if (ici
->ops
->resume
)
1238 ret
= ici
->ops
->resume(icd
);
1243 struct bus_type soc_camera_bus_type
= {
1244 .name
= "soc-camera",
1245 .probe
= soc_camera_probe
,
1246 .remove
= soc_camera_remove
,
1247 .suspend
= soc_camera_suspend
,
1248 .resume
= soc_camera_resume
,
1250 EXPORT_SYMBOL_GPL(soc_camera_bus_type
);
1252 static struct device_driver ic_drv
= {
1254 .bus
= &soc_camera_bus_type
,
1255 .owner
= THIS_MODULE
,
1258 static void dummy_release(struct device
*dev
)
1262 static int default_cropcap(struct soc_camera_device
*icd
,
1263 struct v4l2_cropcap
*a
)
1265 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1266 return v4l2_subdev_call(sd
, video
, cropcap
, a
);
1269 static int default_g_crop(struct soc_camera_device
*icd
, struct v4l2_crop
*a
)
1271 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1272 return v4l2_subdev_call(sd
, video
, g_crop
, a
);
1275 static int default_s_crop(struct soc_camera_device
*icd
, struct v4l2_crop
*a
)
1277 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1278 return v4l2_subdev_call(sd
, video
, s_crop
, a
);
1281 static int default_g_parm(struct soc_camera_device
*icd
,
1282 struct v4l2_streamparm
*parm
)
1284 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1285 return v4l2_subdev_call(sd
, video
, g_parm
, parm
);
1288 static int default_s_parm(struct soc_camera_device
*icd
,
1289 struct v4l2_streamparm
*parm
)
1291 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1292 return v4l2_subdev_call(sd
, video
, s_parm
, parm
);
1295 static int default_enum_fsizes(struct soc_camera_device
*icd
,
1296 struct v4l2_frmsizeenum
*fsize
)
1299 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1300 const struct soc_camera_format_xlate
*xlate
;
1301 __u32 pixfmt
= fsize
->pixel_format
;
1302 struct v4l2_frmsizeenum fsize_mbus
= *fsize
;
1304 xlate
= soc_camera_xlate_by_fourcc(icd
, pixfmt
);
1307 /* map xlate-code to pixel_format, sensor only handle xlate-code*/
1308 fsize_mbus
.pixel_format
= xlate
->code
;
1310 ret
= v4l2_subdev_call(sd
, video
, enum_mbus_fsizes
, &fsize_mbus
);
1314 *fsize
= fsize_mbus
;
1315 fsize
->pixel_format
= pixfmt
;
1320 static void soc_camera_device_init(struct device
*dev
, void *pdata
)
1322 dev
->platform_data
= pdata
;
1323 dev
->bus
= &soc_camera_bus_type
;
1324 dev
->release
= dummy_release
;
1327 int soc_camera_host_register(struct soc_camera_host
*ici
)
1329 struct soc_camera_host
*ix
;
1332 if (!ici
|| !ici
->ops
||
1333 !ici
->ops
->try_fmt
||
1334 !ici
->ops
->set_fmt
||
1335 !ici
->ops
->set_bus_param
||
1336 !ici
->ops
->querycap
||
1337 ((!ici
->ops
->init_videobuf
||
1338 !ici
->ops
->reqbufs
) &&
1339 !ici
->ops
->init_videobuf2
) ||
1341 !ici
->ops
->remove
||
1346 if (!ici
->ops
->set_crop
)
1347 ici
->ops
->set_crop
= default_s_crop
;
1348 if (!ici
->ops
->get_crop
)
1349 ici
->ops
->get_crop
= default_g_crop
;
1350 if (!ici
->ops
->cropcap
)
1351 ici
->ops
->cropcap
= default_cropcap
;
1352 if (!ici
->ops
->set_parm
)
1353 ici
->ops
->set_parm
= default_s_parm
;
1354 if (!ici
->ops
->get_parm
)
1355 ici
->ops
->get_parm
= default_g_parm
;
1356 if (!ici
->ops
->enum_fsizes
)
1357 ici
->ops
->enum_fsizes
= default_enum_fsizes
;
1359 mutex_lock(&list_lock
);
1360 list_for_each_entry(ix
, &hosts
, list
) {
1361 if (ix
->nr
== ici
->nr
) {
1367 ret
= v4l2_device_register(ici
->v4l2_dev
.dev
, &ici
->v4l2_dev
);
1371 list_add_tail(&ici
->list
, &hosts
);
1372 mutex_unlock(&list_lock
);
1379 mutex_unlock(&list_lock
);
1382 EXPORT_SYMBOL(soc_camera_host_register
);
1384 /* Unregister all clients! */
1385 void soc_camera_host_unregister(struct soc_camera_host
*ici
)
1387 struct soc_camera_device
*icd
;
1389 mutex_lock(&list_lock
);
1391 list_del(&ici
->list
);
1393 list_for_each_entry(icd
, &devices
, list
) {
1394 if (icd
->iface
== ici
->nr
) {
1395 void *pdata
= icd
->dev
.platform_data
;
1396 /* The bus->remove will be called */
1397 device_unregister(&icd
->dev
);
1399 * Not before device_unregister(), .remove
1400 * needs parent to call ici->ops->remove().
1401 * If the host module is loaded again, device_register()
1402 * would complain "already initialised," since 2.6.32
1403 * this is also needed to prevent use-after-free of the
1404 * device private data.
1406 memset(&icd
->dev
, 0, sizeof(icd
->dev
));
1407 soc_camera_device_init(&icd
->dev
, pdata
);
1411 mutex_unlock(&list_lock
);
1413 v4l2_device_unregister(&ici
->v4l2_dev
);
1415 EXPORT_SYMBOL(soc_camera_host_unregister
);
1417 /* Image capture device */
1418 static int soc_camera_device_register(struct soc_camera_device
*icd
)
1420 struct soc_camera_device
*ix
;
1423 for (i
= 0; i
< 256 && num
< 0; i
++) {
1425 /* Check if this index is available on this interface */
1426 list_for_each_entry(ix
, &devices
, list
) {
1427 if (ix
->iface
== icd
->iface
&& ix
->devnum
== i
) {
1436 * ok, we have 256 cameras on this host...
1437 * man, stay reasonable...
1443 icd
->host_priv
= NULL
;
1444 mutex_init(&icd
->video_lock
);
1446 list_add_tail(&icd
->list
, &devices
);
1451 static void soc_camera_device_unregister(struct soc_camera_device
*icd
)
1453 list_del(&icd
->list
);
1456 static const struct v4l2_ioctl_ops soc_camera_ioctl_ops
= {
1457 .vidioc_querycap
= soc_camera_querycap
,
1458 .vidioc_g_fmt_vid_cap
= soc_camera_g_fmt_vid_cap
,
1459 .vidioc_enum_fmt_vid_cap
= soc_camera_enum_fmt_vid_cap
,
1460 .vidioc_s_fmt_vid_cap
= soc_camera_s_fmt_vid_cap
,
1461 .vidioc_enum_input
= soc_camera_enum_input
,
1462 .vidioc_g_input
= soc_camera_g_input
,
1463 .vidioc_s_input
= soc_camera_s_input
,
1464 .vidioc_s_std
= soc_camera_s_std
,
1465 .vidioc_enum_framesizes
= soc_camera_enum_fsizes
,
1466 .vidioc_reqbufs
= soc_camera_reqbufs
,
1467 .vidioc_try_fmt_vid_cap
= soc_camera_try_fmt_vid_cap
,
1468 .vidioc_querybuf
= soc_camera_querybuf
,
1469 .vidioc_qbuf
= soc_camera_qbuf
,
1470 .vidioc_dqbuf
= soc_camera_dqbuf
,
1471 .vidioc_streamon
= soc_camera_streamon
,
1472 .vidioc_streamoff
= soc_camera_streamoff
,
1473 .vidioc_queryctrl
= soc_camera_queryctrl
,
1474 .vidioc_g_ctrl
= soc_camera_g_ctrl
,
1475 .vidioc_s_ctrl
= soc_camera_s_ctrl
,
1476 .vidioc_cropcap
= soc_camera_cropcap
,
1477 .vidioc_g_crop
= soc_camera_g_crop
,
1478 .vidioc_s_crop
= soc_camera_s_crop
,
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
->dev
.parent
);
1491 struct video_device
*vdev
= video_device_alloc();
1496 strlcpy(vdev
->name
, ici
->drv_name
, sizeof(vdev
->name
));
1498 vdev
->parent
= &icd
->dev
;
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
;
1511 * Called from soc_camera_probe() above (with .video_lock held???)
1513 static int soc_camera_video_start(struct soc_camera_device
*icd
)
1515 const struct device_type
*type
= icd
->vdev
->dev
.type
;
1518 if (!icd
->dev
.parent
)
1522 !icd
->ops
->query_bus_param
||
1523 !icd
->ops
->set_bus_param
)
1526 ret
= video_register_device(icd
->vdev
, VFL_TYPE_GRABBER
, -1);
1528 dev_err(&icd
->dev
, "video_register_device failed: %d\n", ret
);
1532 /* Restore device type, possibly set by the subdevice driver */
1533 icd
->vdev
->dev
.type
= type
;
1538 static int __devinit
soc_camera_pdrv_probe(struct platform_device
*pdev
)
1540 struct soc_camera_link
*icl
= pdev
->dev
.platform_data
;
1541 struct soc_camera_device
*icd
;
1547 icd
= kzalloc(sizeof(*icd
), GFP_KERNEL
);
1551 icd
->iface
= icl
->bus_id
;
1552 icd
->pdev
= &pdev
->dev
;
1553 platform_set_drvdata(pdev
, icd
);
1555 ret
= soc_camera_device_register(icd
);
1559 soc_camera_device_init(&icd
->dev
, icl
);
1561 icd
->user_width
= DEFAULT_WIDTH
;
1562 icd
->user_height
= DEFAULT_HEIGHT
;
1573 * Only called on rmmod for each platform device, since they are not
1574 * hot-pluggable. Now we know, that all our users - hosts and devices have
1575 * been unloaded already
1577 static int __devexit
soc_camera_pdrv_remove(struct platform_device
*pdev
)
1579 struct soc_camera_device
*icd
= platform_get_drvdata(pdev
);
1584 soc_camera_device_unregister(icd
);
1591 static struct platform_driver __refdata soc_camera_pdrv
= {
1592 .remove
= __devexit_p(soc_camera_pdrv_remove
),
1594 .name
= "soc-camera-pdrv",
1595 .owner
= THIS_MODULE
,
1599 static int __init
soc_camera_init(void)
1601 int ret
= bus_register(&soc_camera_bus_type
);
1604 ret
= driver_register(&ic_drv
);
1608 ret
= platform_driver_probe(&soc_camera_pdrv
, soc_camera_pdrv_probe
);
1615 driver_unregister(&ic_drv
);
1617 bus_unregister(&soc_camera_bus_type
);
1621 static void __exit
soc_camera_exit(void)
1623 platform_driver_unregister(&soc_camera_pdrv
);
1624 driver_unregister(&ic_drv
);
1625 bus_unregister(&soc_camera_bus_type
);
1628 module_init(soc_camera_init
);
1629 module_exit(soc_camera_exit
);
1631 MODULE_DESCRIPTION("Image capture bus driver");
1632 MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
1633 MODULE_LICENSE("GPL");
1634 MODULE_ALIAS("platform:soc-camera-pdrv");