Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / drivers / media / video / soc_camera.c
index 07525e7..aedb970 100644 (file)
 #define DEFAULT_WIDTH  640
 #define DEFAULT_HEIGHT 480
 
+#define is_streaming(ici, icd)                         \
+       (((ici)->ops->init_videobuf) ?                  \
+        (icd)->vb_vidq.streaming :                     \
+        vb2_is_streaming(&(icd)->vb2_vidq))
+
 static LIST_HEAD(hosts);
 static LIST_HEAD(devices);
 static DEFINE_MUTEX(list_lock);                /* Protects the list of hosts */
 
-static int soc_camera_power_set(struct soc_camera_device *icd,
-                               struct soc_camera_link *icl,
-                               int power_on)
+static int soc_camera_power_on(struct soc_camera_device *icd,
+                              struct soc_camera_link *icl)
 {
-       int ret;
+       struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
+       int ret = regulator_bulk_enable(icl->num_regulators,
+                                       icl->regulators);
+       if (ret < 0) {
+               dev_err(icd->pdev, "Cannot enable regulators\n");
+               return ret;
+       }
 
-       if (power_on) {
-               ret = regulator_bulk_enable(icl->num_regulators,
-                                           icl->regulators);
+       if (icl->power) {
+               ret = icl->power(icd->pdev, 1);
                if (ret < 0) {
-                       dev_err(&icd->dev, "Cannot enable regulators\n");
-                       return ret;
+                       dev_err(icd->pdev,
+                               "Platform failed to power-on the camera.\n");
+                       goto elinkpwr;
                }
+       }
 
-               if (icl->power)
-                       ret = icl->power(icd->pdev, power_on);
-               if (ret < 0) {
-                       dev_err(&icd->dev,
-                               "Platform failed to power-on the camera.\n");
+       ret = v4l2_subdev_call(sd, core, s_power, 1);
+       if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
+               goto esdpwr;
 
-                       regulator_bulk_disable(icl->num_regulators,
-                                              icl->regulators);
-                       return ret;
-               }
-       } else {
-               ret = 0;
-               if (icl->power)
-                       ret = icl->power(icd->pdev, 0);
-               if (ret < 0) {
-                       dev_err(&icd->dev,
-                               "Platform failed to power-off the camera.\n");
-                       return ret;
-               }
+       return 0;
+
+esdpwr:
+       if (icl->power)
+               icl->power(icd->pdev, 0);
+elinkpwr:
+       regulator_bulk_disable(icl->num_regulators,
+                              icl->regulators);
+       return ret;
+}
+
+static int soc_camera_power_off(struct soc_camera_device *icd,
+                               struct soc_camera_link *icl)
+{
+       struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
+       int ret = v4l2_subdev_call(sd, core, s_power, 0);
 
-               ret = regulator_bulk_disable(icl->num_regulators,
-                                            icl->regulators);
+       if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
+               return ret;
+
+       if (icl->power) {
+               ret = icl->power(icd->pdev, 0);
                if (ret < 0) {
-                       dev_err(&icd->dev, "Cannot disable regulators\n");
+                       dev_err(icd->pdev,
+                               "Platform failed to power-off the camera.\n");
                        return ret;
                }
        }
 
-       return 0;
+       ret = regulator_bulk_disable(icl->num_regulators,
+                                    icl->regulators);
+       if (ret < 0)
+               dev_err(icd->pdev, "Cannot disable regulators\n");
+
+       return ret;
 }
 
 const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc(
@@ -103,70 +124,106 @@ const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc(
 EXPORT_SYMBOL(soc_camera_xlate_by_fourcc);
 
 /**
- * soc_camera_apply_sensor_flags() - apply platform SOCAM_SENSOR_INVERT_* flags
+ * soc_camera_apply_board_flags() - apply platform SOCAM_SENSOR_INVERT_* flags
  * @icl:       camera platform parameters
- * @flags:     flags to be inverted according to platform configuration
+ * @cfg:       media bus configuration
  * @return:    resulting flags
  */
-unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl,
-                                           unsigned long flags)
+unsigned long soc_camera_apply_board_flags(struct soc_camera_link *icl,
+                                          const struct v4l2_mbus_config *cfg)
 {
-       unsigned long f;
+       unsigned long f, flags = cfg->flags;
 
        /* If only one of the two polarities is supported, switch to the opposite */
        if (icl->flags & SOCAM_SENSOR_INVERT_HSYNC) {
-               f = flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW);
-               if (f == SOCAM_HSYNC_ACTIVE_HIGH || f == SOCAM_HSYNC_ACTIVE_LOW)
-                       flags ^= SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW;
+               f = flags & (V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW);
+               if (f == V4L2_MBUS_HSYNC_ACTIVE_HIGH || f == V4L2_MBUS_HSYNC_ACTIVE_LOW)
+                       flags ^= V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW;
        }
 
        if (icl->flags & SOCAM_SENSOR_INVERT_VSYNC) {
-               f = flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW);
-               if (f == SOCAM_VSYNC_ACTIVE_HIGH || f == SOCAM_VSYNC_ACTIVE_LOW)
-                       flags ^= SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW;
+               f = flags & (V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW);
+               if (f == V4L2_MBUS_VSYNC_ACTIVE_HIGH || f == V4L2_MBUS_VSYNC_ACTIVE_LOW)
+                       flags ^= V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW;
        }
 
        if (icl->flags & SOCAM_SENSOR_INVERT_PCLK) {
-               f = flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING);
-               if (f == SOCAM_PCLK_SAMPLE_RISING || f == SOCAM_PCLK_SAMPLE_FALLING)
-                       flags ^= SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING;
+               f = flags & (V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING);
+               if (f == V4L2_MBUS_PCLK_SAMPLE_RISING || f == V4L2_MBUS_PCLK_SAMPLE_FALLING)
+                       flags ^= V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING;
        }
 
        return flags;
 }
-EXPORT_SYMBOL(soc_camera_apply_sensor_flags);
+EXPORT_SYMBOL(soc_camera_apply_board_flags);
+
+#define pixfmtstr(x) (x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, \
+       ((x) >> 24) & 0xff
+
+static int soc_camera_try_fmt(struct soc_camera_device *icd,
+                             struct v4l2_format *f)
+{
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
+       struct v4l2_pix_format *pix = &f->fmt.pix;
+       int ret;
+
+       dev_dbg(icd->pdev, "TRY_FMT(%c%c%c%c, %ux%u)\n",
+               pixfmtstr(pix->pixelformat), pix->width, pix->height);
+
+       pix->bytesperline = 0;
+       pix->sizeimage = 0;
+
+       ret = ici->ops->try_fmt(icd, f);
+       if (ret < 0)
+               return ret;
+
+       if (!pix->sizeimage) {
+               if (!pix->bytesperline) {
+                       const struct soc_camera_format_xlate *xlate;
+
+                       xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
+                       if (!xlate)
+                               return -EINVAL;
+
+                       ret = soc_mbus_bytes_per_line(pix->width,
+                                                     xlate->host_fmt);
+                       if (ret > 0)
+                               pix->bytesperline = ret;
+               }
+               if (pix->bytesperline)
+                       pix->sizeimage = pix->bytesperline * pix->height;
+       }
+
+       return 0;
+}
 
 static int soc_camera_try_fmt_vid_cap(struct file *file, void *priv,
                                      struct v4l2_format *f)
 {
        struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
 
        WARN_ON(priv != file->private_data);
 
+       /* Only single-plane capture is supported so far */
+       if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+               return -EINVAL;
+
        /* limit format to hardware capabilities */
-       return ici->ops->try_fmt(icd, f);
+       return soc_camera_try_fmt(icd, f);
 }
 
 static int soc_camera_enum_input(struct file *file, void *priv,
                                 struct v4l2_input *inp)
 {
-       struct soc_camera_device *icd = file->private_data;
-       int ret = 0;
-
        if (inp->index != 0)
                return -EINVAL;
 
-       if (icd->ops->enum_input)
-               ret = icd->ops->enum_input(icd, inp);
-       else {
-               /* default is camera */
-               inp->type = V4L2_INPUT_TYPE_CAMERA;
-               inp->std  = V4L2_STD_UNKNOWN;
-               strcpy(inp->name, "Camera");
-       }
+       /* default is camera */
+       inp->type = V4L2_INPUT_TYPE_CAMERA;
+       inp->std  = V4L2_STD_UNKNOWN;
+       strcpy(inp->name, "Camera");
 
-       return ret;
+       return 0;
 }
 
 static int soc_camera_g_input(struct file *file, void *priv, unsigned int *i)
@@ -192,11 +249,19 @@ static int soc_camera_s_std(struct file *file, void *priv, v4l2_std_id *a)
        return v4l2_subdev_call(sd, core, s_std, *a);
 }
 
+static int soc_camera_g_std(struct file *file, void *priv, v4l2_std_id *a)
+{
+       struct soc_camera_device *icd = file->private_data;
+       struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
+
+       return v4l2_subdev_call(sd, core, g_std, a);
+}
+
 static int soc_camera_enum_fsizes(struct file *file, void *fh,
                                         struct v4l2_frmsizeenum *fsize)
 {
        struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
        return ici->ops->enum_fsizes(icd, fsize);
 }
@@ -206,7 +271,7 @@ static int soc_camera_reqbufs(struct file *file, void *priv,
 {
        int ret;
        struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
        WARN_ON(priv != file->private_data);
 
@@ -233,7 +298,7 @@ static int soc_camera_querybuf(struct file *file, void *priv,
                               struct v4l2_buffer *p)
 {
        struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
        WARN_ON(priv != file->private_data);
 
@@ -247,7 +312,7 @@ static int soc_camera_qbuf(struct file *file, void *priv,
                           struct v4l2_buffer *p)
 {
        struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
        WARN_ON(priv != file->private_data);
 
@@ -264,7 +329,7 @@ static int soc_camera_dqbuf(struct file *file, void *priv,
                            struct v4l2_buffer *p)
 {
        struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
        WARN_ON(priv != file->private_data);
 
@@ -277,11 +342,37 @@ static int soc_camera_dqbuf(struct file *file, void *priv,
                return vb2_dqbuf(&icd->vb2_vidq, p, file->f_flags & O_NONBLOCK);
 }
 
+static int soc_camera_create_bufs(struct file *file, void *priv,
+                           struct v4l2_create_buffers *create)
+{
+       struct soc_camera_device *icd = file->private_data;
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
+
+       /* videobuf2 only */
+       if (ici->ops->init_videobuf)
+               return -EINVAL;
+       else
+               return vb2_create_bufs(&icd->vb2_vidq, create);
+}
+
+static int soc_camera_prepare_buf(struct file *file, void *priv,
+                                 struct v4l2_buffer *b)
+{
+       struct soc_camera_device *icd = file->private_data;
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
+
+       /* videobuf2 only */
+       if (ici->ops->init_videobuf)
+               return -EINVAL;
+       else
+               return vb2_prepare_buf(&icd->vb2_vidq, b);
+}
+
 /* Always entered with .video_lock held */
 static int soc_camera_init_user_formats(struct soc_camera_device *icd)
 {
        struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
        unsigned int i, fmts = 0, raw_fmts = 0;
        int ret;
        enum v4l2_mbus_pixelcode code;
@@ -315,18 +406,17 @@ static int soc_camera_init_user_formats(struct soc_camera_device *icd)
        if (!icd->user_formats)
                return -ENOMEM;
 
-       icd->num_user_formats = fmts;
-
-       dev_dbg(&icd->dev, "Found %d supported formats.\n", fmts);
+       dev_dbg(icd->pdev, "Found %d supported formats.\n", fmts);
 
        /* Second pass - actually fill data formats */
        fmts = 0;
        for (i = 0; i < raw_fmts; i++)
                if (!ici->ops->get_formats) {
                        v4l2_subdev_call(sd, video, enum_mbus_fmt, i, &code);
-                       icd->user_formats[i].host_fmt =
+                       icd->user_formats[fmts].host_fmt =
                                soc_mbus_get_fmtdesc(code);
-                       icd->user_formats[i].code = code;
+                       if (icd->user_formats[fmts].host_fmt)
+                               icd->user_formats[fmts++].code = code;
                } else {
                        ret = ici->ops->get_formats(icd, i,
                                                    &icd->user_formats[fmts]);
@@ -335,12 +425,12 @@ static int soc_camera_init_user_formats(struct soc_camera_device *icd)
                        fmts += ret;
                }
 
+       icd->num_user_formats = fmts;
        icd->current_fmt = &icd->user_formats[0];
 
        return 0;
 
 egfmt:
-       icd->num_user_formats = 0;
        vfree(icd->user_formats);
        return ret;
 }
@@ -348,7 +438,7 @@ egfmt:
 /* Always entered with .video_lock held */
 static void soc_camera_free_user_formats(struct soc_camera_device *icd)
 {
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
        if (ici->ops->put_formats)
                ici->ops->put_formats(icd);
@@ -358,22 +448,19 @@ static void soc_camera_free_user_formats(struct soc_camera_device *icd)
        icd->user_formats = NULL;
 }
 
-#define pixfmtstr(x) (x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, \
-       ((x) >> 24) & 0xff
-
 /* Called with .vb_lock held, or from the first open(2), see comment there */
 static int soc_camera_set_fmt(struct soc_camera_device *icd,
                              struct v4l2_format *f)
 {
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
        struct v4l2_pix_format *pix = &f->fmt.pix;
        int ret;
 
-       dev_dbg(&icd->dev, "S_FMT(%c%c%c%c, %ux%u)\n",
+       dev_dbg(icd->pdev, "S_FMT(%c%c%c%c, %ux%u)\n",
                pixfmtstr(pix->pixelformat), pix->width, pix->height);
 
        /* We always call try_fmt() before set_fmt() or set_crop() */
-       ret = ici->ops->try_fmt(icd, f);
+       ret = soc_camera_try_fmt(icd, f);
        if (ret < 0)
                return ret;
 
@@ -382,7 +469,7 @@ static int soc_camera_set_fmt(struct soc_camera_device *icd,
                return ret;
        } else if (!icd->current_fmt ||
                   icd->current_fmt->host_fmt->fourcc != pix->pixelformat) {
-               dev_err(&icd->dev,
+               dev_err(icd->pdev,
                        "Host driver hasn't set up current format correctly!\n");
                return -EINVAL;
        }
@@ -396,35 +483,29 @@ static int soc_camera_set_fmt(struct soc_camera_device *icd,
        if (ici->ops->init_videobuf)
                icd->vb_vidq.field = pix->field;
 
-       if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
-               dev_warn(&icd->dev, "Attention! Wrong buf-type %d\n",
-                        f->type);
-
-       dev_dbg(&icd->dev, "set width: %d height: %d\n",
+       dev_dbg(icd->pdev, "set width: %d height: %d\n",
                icd->user_width, icd->user_height);
 
        /* set physical bus parameters */
-       return ici->ops->set_bus_param(icd, pix->pixelformat);
+       return ici->ops->set_bus_param(icd);
 }
 
 static int soc_camera_open(struct file *file)
 {
        struct video_device *vdev = video_devdata(file);
-       struct soc_camera_device *icd = container_of(vdev->parent,
-                                                    struct soc_camera_device,
-                                                    dev);
+       struct soc_camera_device *icd = dev_get_drvdata(vdev->parent);
        struct soc_camera_link *icl = to_soc_camera_link(icd);
        struct soc_camera_host *ici;
        int ret;
 
-       if (!icd->ops)
+       if (!to_soc_camera_control(icd))
                /* No device driver attached */
                return -ENODEV;
 
-       ici = to_soc_camera_host(icd->dev.parent);
+       ici = to_soc_camera_host(icd->parent);
 
        if (!try_module_get(ici->ops->owner)) {
-               dev_err(&icd->dev, "Couldn't lock capture bus driver.\n");
+               dev_err(icd->pdev, "Couldn't lock capture bus driver.\n");
                return -EINVAL;
        }
 
@@ -445,20 +526,23 @@ static int soc_camera_open(struct file *file)
                        },
                };
 
-               ret = soc_camera_power_set(icd, icl, 1);
-               if (ret < 0)
-                       goto epower;
-
                /* The camera could have been already on, try to reset */
                if (icl->reset)
                        icl->reset(icd->pdev);
 
+               /* Don't mess with the host during probe */
+               mutex_lock(&ici->host_lock);
                ret = ici->ops->add(icd);
+               mutex_unlock(&ici->host_lock);
                if (ret < 0) {
-                       dev_err(&icd->dev, "Couldn't activate the camera: %d\n", ret);
+                       dev_err(icd->pdev, "Couldn't activate the camera: %d\n", ret);
                        goto eiciadd;
                }
 
+               ret = soc_camera_power_on(icd, icl);
+               if (ret < 0)
+                       goto epower;
+
                pm_runtime_enable(&icd->vdev->dev);
                ret = pm_runtime_resume(&icd->vdev->dev);
                if (ret < 0 && ret != -ENOSYS)
@@ -481,10 +565,11 @@ static int soc_camera_open(struct file *file)
                        if (ret < 0)
                                goto einitvb;
                }
+               v4l2_ctrl_handler_setup(&icd->ctrl_handler);
        }
 
        file->private_data = icd;
-       dev_dbg(&icd->dev, "camera device open\n");
+       dev_dbg(icd->pdev, "camera device open\n");
 
        return 0;
 
@@ -496,10 +581,10 @@ einitvb:
 esfmt:
        pm_runtime_disable(&icd->vdev->dev);
 eresume:
+       soc_camera_power_off(icd, icl);
+epower:
        ici->ops->remove(icd);
 eiciadd:
-       soc_camera_power_set(icd, icl, 0);
-epower:
        icd->use_count--;
        module_put(ici->ops->owner);
 
@@ -509,7 +594,7 @@ epower:
 static int soc_camera_close(struct file *file)
 {
        struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
        icd->use_count--;
        if (!icd->use_count) {
@@ -518,11 +603,11 @@ static int soc_camera_close(struct file *file)
                pm_runtime_suspend(&icd->vdev->dev);
                pm_runtime_disable(&icd->vdev->dev);
 
-               ici->ops->remove(icd);
                if (ici->ops->init_videobuf2)
                        vb2_queue_release(&icd->vb2_vidq);
+               ici->ops->remove(icd);
 
-               soc_camera_power_set(icd, icl, 0);
+               soc_camera_power_off(icd, icl);
        }
 
        if (icd->streamer == file)
@@ -530,7 +615,7 @@ static int soc_camera_close(struct file *file)
 
        module_put(ici->ops->owner);
 
-       dev_dbg(&icd->dev, "camera device close\n");
+       dev_dbg(icd->pdev, "camera device close\n");
 
        return 0;
 }
@@ -541,7 +626,7 @@ static ssize_t soc_camera_read(struct file *file, char __user *buf,
        struct soc_camera_device *icd = file->private_data;
        int err = -EINVAL;
 
-       dev_err(&icd->dev, "camera device read not implemented\n");
+       dev_err(icd->pdev, "camera device read not implemented\n");
 
        return err;
 }
@@ -549,10 +634,10 @@ static ssize_t soc_camera_read(struct file *file, char __user *buf,
 static int soc_camera_mmap(struct file *file, struct vm_area_struct *vma)
 {
        struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
        int err;
 
-       dev_dbg(&icd->dev, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
+       dev_dbg(icd->pdev, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
 
        if (icd->streamer != file)
                return -EBUSY;
@@ -562,7 +647,7 @@ static int soc_camera_mmap(struct file *file, struct vm_area_struct *vma)
        else
                err = vb2_mmap(&icd->vb2_vidq, vma);
 
-       dev_dbg(&icd->dev, "vma start=0x%08lx, size=%ld, ret=%d\n",
+       dev_dbg(icd->pdev, "vma start=0x%08lx, size=%ld, ret=%d\n",
                (unsigned long)vma->vm_start,
                (unsigned long)vma->vm_end - (unsigned long)vma->vm_start,
                err);
@@ -573,13 +658,13 @@ static int soc_camera_mmap(struct file *file, struct vm_area_struct *vma)
 static unsigned int soc_camera_poll(struct file *file, poll_table *pt)
 {
        struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
        if (icd->streamer != file)
                return -EBUSY;
 
        if (ici->ops->init_videobuf && list_empty(&icd->vb_vidq.stream)) {
-               dev_err(&icd->dev, "Trying to poll with no queued buffers!\n");
+               dev_err(icd->pdev, "Trying to poll with no queued buffers!\n");
                return POLLERR;
        }
 
@@ -618,11 +703,16 @@ static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv,
 
        WARN_ON(priv != file->private_data);
 
+       if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+               dev_warn(icd->pdev, "Wrong buf-type %d\n", f->type);
+               return -EINVAL;
+       }
+
        if (icd->streamer && icd->streamer != file)
                return -EBUSY;
 
-       if (icd->vb_vidq.bufs[0]) {
-               dev_err(&icd->dev, "S_FMT denied: queue initialised\n");
+       if (is_streaming(to_soc_camera_host(icd->parent), icd)) {
+               dev_err(icd->pdev, "S_FMT denied: queue initialised\n");
                return -EBUSY;
        }
 
@@ -661,6 +751,9 @@ static int soc_camera_g_fmt_vid_cap(struct file *file, void *priv,
 
        WARN_ON(priv != file->private_data);
 
+       if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+               return -EINVAL;
+
        pix->width              = icd->user_width;
        pix->height             = icd->user_height;
        pix->bytesperline       = icd->bytesperline;
@@ -668,7 +761,7 @@ static int soc_camera_g_fmt_vid_cap(struct file *file, void *priv,
        pix->field              = icd->field;
        pix->pixelformat        = icd->current_fmt->host_fmt->fourcc;
        pix->colorspace         = icd->colorspace;
-       dev_dbg(&icd->dev, "current_fmt->fourcc: 0x%08x\n",
+       dev_dbg(icd->pdev, "current_fmt->fourcc: 0x%08x\n",
                icd->current_fmt->host_fmt->fourcc);
        return 0;
 }
@@ -677,7 +770,7 @@ static int soc_camera_querycap(struct file *file, void  *priv,
                               struct v4l2_capability *cap)
 {
        struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
        WARN_ON(priv != file->private_data);
 
@@ -689,7 +782,7 @@ static int soc_camera_streamon(struct file *file, void *priv,
                               enum v4l2_buf_type i)
 {
        struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
        struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
        int ret;
 
@@ -718,7 +811,7 @@ static int soc_camera_streamoff(struct file *file, void *priv,
 {
        struct soc_camera_device *icd = file->private_data;
        struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
        WARN_ON(priv != file->private_data);
 
@@ -742,80 +835,11 @@ static int soc_camera_streamoff(struct file *file, void *priv,
        return 0;
 }
 
-static int soc_camera_queryctrl(struct file *file, void *priv,
-                               struct v4l2_queryctrl *qc)
-{
-       struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
-       int i;
-
-       WARN_ON(priv != file->private_data);
-
-       if (!qc->id)
-               return -EINVAL;
-
-       /* First check host controls */
-       for (i = 0; i < ici->ops->num_controls; i++)
-               if (qc->id == ici->ops->controls[i].id) {
-                       memcpy(qc, &(ici->ops->controls[i]),
-                               sizeof(*qc));
-                       return 0;
-               }
-
-       /* Then device controls */
-       for (i = 0; i < icd->ops->num_controls; i++)
-               if (qc->id == icd->ops->controls[i].id) {
-                       memcpy(qc, &(icd->ops->controls[i]),
-                               sizeof(*qc));
-                       return 0;
-               }
-
-       return -EINVAL;
-}
-
-static int soc_camera_g_ctrl(struct file *file, void *priv,
-                            struct v4l2_control *ctrl)
-{
-       struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
-       struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
-       int ret;
-
-       WARN_ON(priv != file->private_data);
-
-       if (ici->ops->get_ctrl) {
-               ret = ici->ops->get_ctrl(icd, ctrl);
-               if (ret != -ENOIOCTLCMD)
-                       return ret;
-       }
-
-       return v4l2_subdev_call(sd, core, g_ctrl, ctrl);
-}
-
-static int soc_camera_s_ctrl(struct file *file, void *priv,
-                            struct v4l2_control *ctrl)
-{
-       struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
-       struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
-       int ret;
-
-       WARN_ON(priv != file->private_data);
-
-       if (ici->ops->set_ctrl) {
-               ret = ici->ops->set_ctrl(icd, ctrl);
-               if (ret != -ENOIOCTLCMD)
-                       return ret;
-       }
-
-       return v4l2_subdev_call(sd, core, s_ctrl, ctrl);
-}
-
 static int soc_camera_cropcap(struct file *file, void *fh,
                              struct v4l2_cropcap *a)
 {
        struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
        return ici->ops->cropcap(icd, a);
 }
@@ -824,7 +848,7 @@ static int soc_camera_g_crop(struct file *file, void *fh,
                             struct v4l2_crop *a)
 {
        struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
        int ret;
 
        ret = ici->ops->get_crop(icd, a);
@@ -841,7 +865,7 @@ static int soc_camera_s_crop(struct file *file, void *fh,
                             struct v4l2_crop *a)
 {
        struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
        struct v4l2_rect *rect = &a->c;
        struct v4l2_crop current_crop;
        int ret;
@@ -849,7 +873,7 @@ static int soc_camera_s_crop(struct file *file, void *fh,
        if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
                return -EINVAL;
 
-       dev_dbg(&icd->dev, "S_CROP(%ux%u@%u:%u)\n",
+       dev_dbg(icd->pdev, "S_CROP(%ux%u@%u:%u)\n",
                rect->width, rect->height, rect->left, rect->top);
 
        /* If get_crop fails, we'll let host and / or client drivers decide */
@@ -857,16 +881,19 @@ static int soc_camera_s_crop(struct file *file, void *fh,
 
        /* Prohibit window size change with initialised buffers */
        if (ret < 0) {
-               dev_err(&icd->dev,
+               dev_err(icd->pdev,
                        "S_CROP denied: getting current crop failed\n");
-       } else if (icd->vb_vidq.bufs[0] &&
-                  (a->c.width != current_crop.c.width ||
-                   a->c.height != current_crop.c.height)) {
-               dev_err(&icd->dev,
+       } else if ((a->c.width == current_crop.c.width &&
+                   a->c.height == current_crop.c.height) ||
+                  !is_streaming(ici, icd)) {
+               /* same size or not streaming - use .set_crop() */
+               ret = ici->ops->set_crop(icd, a);
+       } else if (ici->ops->set_livecrop) {
+               ret = ici->ops->set_livecrop(icd, a);
+       } else {
+               dev_err(icd->pdev,
                        "S_CROP denied: queue initialised and sizes differ\n");
                ret = -EBUSY;
-       } else {
-               ret = ici->ops->set_crop(icd, a);
        }
 
        return ret;
@@ -876,7 +903,7 @@ static int soc_camera_g_parm(struct file *file, void *fh,
                             struct v4l2_streamparm *a)
 {
        struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
        if (ici->ops->get_parm)
                return ici->ops->get_parm(icd, a);
@@ -888,7 +915,7 @@ static int soc_camera_s_parm(struct file *file, void *fh,
                             struct v4l2_streamparm *a)
 {
        struct soc_camera_device *icd = file->private_data;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
        if (ici->ops->set_parm)
                return ici->ops->set_parm(icd, a);
@@ -925,29 +952,25 @@ static int soc_camera_s_register(struct file *file, void *fh,
 }
 #endif
 
+static int soc_camera_probe(struct soc_camera_device *icd);
+
 /* So far this function cannot fail */
 static void scan_add_host(struct soc_camera_host *ici)
 {
        struct soc_camera_device *icd;
 
-       mutex_lock(&list_lock);
+       mutex_lock(&ici->host_lock);
 
        list_for_each_entry(icd, &devices, list) {
                if (icd->iface == ici->nr) {
                        int ret;
-                       icd->dev.parent = ici->v4l2_dev.dev;
-                       dev_set_name(&icd->dev, "%u-%u", icd->iface,
-                                    icd->devnum);
-                       ret = device_register(&icd->dev);
-                       if (ret < 0) {
-                               icd->dev.parent = NULL;
-                               dev_err(&icd->dev,
-                                       "Cannot register device: %d\n", ret);
-                       }
+
+                       icd->parent = ici->v4l2_dev.dev;
+                       ret = soc_camera_probe(icd);
                }
        }
 
-       mutex_unlock(&list_lock);
+       mutex_unlock(&ici->host_lock);
 }
 
 #ifdef CONFIG_I2C_BOARDINFO
@@ -955,17 +978,17 @@ static int soc_camera_init_i2c(struct soc_camera_device *icd,
                               struct soc_camera_link *icl)
 {
        struct i2c_client *client;
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
        struct i2c_adapter *adap = i2c_get_adapter(icl->i2c_adapter_id);
        struct v4l2_subdev *subdev;
 
        if (!adap) {
-               dev_err(&icd->dev, "Cannot get I2C adapter #%d. No driver?\n",
+               dev_err(icd->pdev, "Cannot get I2C adapter #%d. No driver?\n",
                        icl->i2c_adapter_id);
                goto ei2cga;
        }
 
-       icl->board_info->platform_data = icd;
+       icl->board_info->platform_data = icl;
 
        subdev = v4l2_i2c_new_subdev_board(&ici->v4l2_dev, adap,
                                icl->board_info, NULL);
@@ -975,7 +998,7 @@ static int soc_camera_init_i2c(struct soc_camera_device *icd,
        client = v4l2_get_subdevdata(subdev);
 
        /* Use to_i2c_client(dev) to recover the i2c client */
-       dev_set_drvdata(&icd->dev, &client->dev);
+       icd->control = &client->dev;
 
        return 0;
 ei2cnd:
@@ -988,10 +1011,12 @@ static void soc_camera_free_i2c(struct soc_camera_device *icd)
 {
        struct i2c_client *client =
                to_i2c_client(to_soc_camera_control(icd));
-       dev_set_drvdata(&icd->dev, NULL);
+       struct i2c_adapter *adap = client->adapter;
+
+       icd->control = NULL;
        v4l2_device_unregister_subdev(i2c_get_clientdata(client));
        i2c_unregister_device(client);
-       i2c_put_adapter(client->adapter);
+       i2c_put_adapter(adap);
 }
 #else
 #define soc_camera_init_i2c(icd, icl)  (-ENODEV)
@@ -1001,27 +1026,33 @@ static void soc_camera_free_i2c(struct soc_camera_device *icd)
 static int soc_camera_video_start(struct soc_camera_device *icd);
 static int video_dev_create(struct soc_camera_device *icd);
 /* Called during host-driver probe */
-static int soc_camera_probe(struct device *dev)
+static int soc_camera_probe(struct soc_camera_device *icd)
 {
-       struct soc_camera_device *icd = to_soc_camera_dev(dev);
-       struct soc_camera_host *ici = to_soc_camera_host(dev->parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
        struct soc_camera_link *icl = to_soc_camera_link(icd);
        struct device *control = NULL;
        struct v4l2_subdev *sd;
        struct v4l2_mbus_framefmt mf;
        int ret;
 
-       dev_info(dev, "Probing %s\n", dev_name(dev));
+       dev_info(icd->pdev, "Probing %s\n", dev_name(icd->pdev));
+
+       /*
+        * Currently the subdev with the largest number of controls (13) is
+        * ov6550. So let's pick 16 as a hint for the control handler. Note
+        * that this is a hint only: too large and you waste some memory, too
+        * small and there is a (very) small performance hit when looking up
+        * controls in the internal hash.
+        */
+       ret = v4l2_ctrl_handler_init(&icd->ctrl_handler, 16);
+       if (ret < 0)
+               return ret;
 
        ret = regulator_bulk_get(icd->pdev, icl->num_regulators,
                                 icl->regulators);
        if (ret < 0)
                goto ereg;
 
-       ret = soc_camera_power_set(icd, icl, 1);
-       if (ret < 0)
-               goto epower;
-
        /* The camera could have been already on, try to reset */
        if (icl->reset)
                icl->reset(icd->pdev);
@@ -1030,6 +1061,16 @@ static int soc_camera_probe(struct device *dev)
        if (ret < 0)
                goto eadd;
 
+       /*
+        * This will not yet call v4l2_subdev_core_ops::s_power(1), because the
+        * subdevice has not been initialised yet. We'll have to call it once
+        * again after initialisation, even though it shouldn't be needed, we
+        * don't do any IO here.
+        */
+       ret = soc_camera_power_on(icd, icl);
+       if (ret < 0)
+               goto epower;
+
        /* Must have icd->vdev before registering the device */
        ret = video_dev_create(icd);
        if (ret < 0)
@@ -1047,7 +1088,7 @@ static int soc_camera_probe(struct device *dev)
                if (icl->module_name)
                        ret = request_module(icl->module_name);
 
-               ret = icl->add_device(icl, &icd->dev);
+               ret = icl->add_device(icd);
                if (ret < 0)
                        goto eadddev;
 
@@ -1058,11 +1099,19 @@ static int soc_camera_probe(struct device *dev)
                control = to_soc_camera_control(icd);
                if (!control || !control->driver || !dev_get_drvdata(control) ||
                    !try_module_get(control->driver->owner)) {
-                       icl->del_device(icl);
+                       icl->del_device(icd);
+                       ret = -ENODEV;
                        goto enodrv;
                }
        }
 
+       sd = soc_camera_to_subdev(icd);
+       sd->grp_id = soc_camera_grp_id(icd);
+       v4l2_set_subdev_hostdata(sd, icd);
+
+       if (v4l2_ctrl_add_handler(&icd->ctrl_handler, sd->ctrl_handler))
+               goto ectrl;
+
        /* At this point client .probe() should have run already */
        ret = soc_camera_init_user_formats(icd);
        if (ret < 0)
@@ -1070,8 +1119,6 @@ static int soc_camera_probe(struct device *dev)
 
        icd->field = V4L2_FIELD_ANY;
 
-       icd->vdev->lock = &icd->video_lock;
-
        /*
         * ..._video_start() will create a device node, video_register_device()
         * itself is protected against concurrent open() calls, but we also have
@@ -1083,8 +1130,11 @@ static int soc_camera_probe(struct device *dev)
        if (ret < 0)
                goto evidstart;
 
+       ret = v4l2_subdev_call(sd, core, s_power, 1);
+       if (ret < 0 && ret != -ENOIOCTLCMD)
+               goto esdpwr;
+
        /* Try to improve our guess of a reasonable window format */
-       sd = soc_camera_to_subdev(icd);
        if (!v4l2_subdev_call(sd, video, g_mbus_fmt, &mf)) {
                icd->user_width         = mf.width;
                icd->user_height        = mf.height;
@@ -1092,39 +1142,39 @@ static int soc_camera_probe(struct device *dev)
                icd->field              = mf.field;
        }
 
-       /* Do we have to sysfs_remove_link() before device_unregister()? */
-       if (sysfs_create_link(&icd->dev.kobj, &to_soc_camera_control(icd)->kobj,
-                             "control"))
-               dev_warn(&icd->dev, "Failed creating the control symlink\n");
-
        ici->ops->remove(icd);
 
-       soc_camera_power_set(icd, icl, 0);
+       soc_camera_power_off(icd, icl);
 
        mutex_unlock(&icd->video_lock);
 
        return 0;
 
+esdpwr:
+       video_unregister_device(icd->vdev);
 evidstart:
        mutex_unlock(&icd->video_lock);
        soc_camera_free_user_formats(icd);
 eiufmt:
+ectrl:
        if (icl->board_info) {
                soc_camera_free_i2c(icd);
        } else {
-               icl->del_device(icl);
+               icl->del_device(icd);
                module_put(control->driver->owner);
        }
 enodrv:
 eadddev:
        video_device_release(icd->vdev);
+       icd->vdev = NULL;
 evdc:
+       soc_camera_power_off(icd, icl);
+epower:
        ici->ops->remove(icd);
 eadd:
-       soc_camera_power_set(icd, icl, 0);
-epower:
        regulator_bulk_free(icl->num_regulators, icl->regulators);
 ereg:
+       v4l2_ctrl_handler_free(&icd->ctrl_handler);
        return ret;
 }
 
@@ -1132,14 +1182,14 @@ ereg:
  * This is called on device_unregister, which only means we have to disconnect
  * from the host, but not remove ourselves from the device list
  */
-static int soc_camera_remove(struct device *dev)
+static int soc_camera_remove(struct soc_camera_device *icd)
 {
-       struct soc_camera_device *icd = to_soc_camera_dev(dev);
        struct soc_camera_link *icl = to_soc_camera_link(icd);
        struct video_device *vdev = icd->vdev;
 
-       BUG_ON(!dev->parent);
+       BUG_ON(!icd->parent);
 
+       v4l2_ctrl_handler_free(&icd->ctrl_handler);
        if (vdev) {
                video_unregister_device(vdev);
                icd->vdev = NULL;
@@ -1148,10 +1198,9 @@ static int soc_camera_remove(struct device *dev)
        if (icl->board_info) {
                soc_camera_free_i2c(icd);
        } else {
-               struct device_driver *drv = to_soc_camera_control(icd) ?
-                       to_soc_camera_control(icd)->driver : NULL;
+               struct device_driver *drv = to_soc_camera_control(icd)->driver;
                if (drv) {
-                       icl->del_device(icl);
+                       icl->del_device(icd);
                        module_put(drv->owner);
                }
        }
@@ -1162,49 +1211,6 @@ static int soc_camera_remove(struct device *dev)
        return 0;
 }
 
-static int soc_camera_suspend(struct device *dev, pm_message_t state)
-{
-       struct soc_camera_device *icd = to_soc_camera_dev(dev);
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
-       int ret = 0;
-
-       if (ici->ops->suspend)
-               ret = ici->ops->suspend(icd, state);
-
-       return ret;
-}
-
-static int soc_camera_resume(struct device *dev)
-{
-       struct soc_camera_device *icd = to_soc_camera_dev(dev);
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
-       int ret = 0;
-
-       if (ici->ops->resume)
-               ret = ici->ops->resume(icd);
-
-       return ret;
-}
-
-struct bus_type soc_camera_bus_type = {
-       .name           = "soc-camera",
-       .probe          = soc_camera_probe,
-       .remove         = soc_camera_remove,
-       .suspend        = soc_camera_suspend,
-       .resume         = soc_camera_resume,
-};
-EXPORT_SYMBOL_GPL(soc_camera_bus_type);
-
-static struct device_driver ic_drv = {
-       .name   = "camera",
-       .bus    = &soc_camera_bus_type,
-       .owner  = THIS_MODULE,
-};
-
-static void dummy_release(struct device *dev)
-{
-}
-
 static int default_cropcap(struct soc_camera_device *icd,
                           struct v4l2_cropcap *a)
 {
@@ -1263,13 +1269,6 @@ static int default_enum_fsizes(struct soc_camera_device *icd,
        return 0;
 }
 
-static void soc_camera_device_init(struct device *dev, void *pdata)
-{
-       dev->platform_data      = pdata;
-       dev->bus                = &soc_camera_bus_type;
-       dev->release            = dummy_release;
-}
-
 int soc_camera_host_register(struct soc_camera_host *ici)
 {
        struct soc_camera_host *ix;
@@ -1317,6 +1316,7 @@ int soc_camera_host_register(struct soc_camera_host *ici)
        list_add_tail(&ici->list, &hosts);
        mutex_unlock(&list_lock);
 
+       mutex_init(&ici->host_lock);
        scan_add_host(ici);
 
        return 0;
@@ -1335,24 +1335,9 @@ void soc_camera_host_unregister(struct soc_camera_host *ici)
        mutex_lock(&list_lock);
 
        list_del(&ici->list);
-
-       list_for_each_entry(icd, &devices, list) {
-               if (icd->iface == ici->nr) {
-                       void *pdata = icd->dev.platform_data;
-                       /* The bus->remove will be called */
-                       device_unregister(&icd->dev);
-                       /*
-                        * Not before device_unregister(), .remove
-                        * needs parent to call ici->ops->remove().
-                        * If the host module is loaded again, device_register()
-                        * would complain "already initialised," since 2.6.32
-                        * this is also needed to prevent use-after-free of the
-                        * device private data.
-                        */
-                       memset(&icd->dev, 0, sizeof(icd->dev));
-                       soc_camera_device_init(&icd->dev, pdata);
-               }
-       }
+       list_for_each_entry(icd, &devices, list)
+               if (icd->iface == ici->nr && to_soc_camera_control(icd))
+                       soc_camera_remove(icd);
 
        mutex_unlock(&list_lock);
 
@@ -1394,31 +1379,26 @@ static int soc_camera_device_register(struct soc_camera_device *icd)
        return 0;
 }
 
-static void soc_camera_device_unregister(struct soc_camera_device *icd)
-{
-       list_del(&icd->list);
-}
-
 static const struct v4l2_ioctl_ops soc_camera_ioctl_ops = {
        .vidioc_querycap         = soc_camera_querycap,
+       .vidioc_try_fmt_vid_cap  = soc_camera_try_fmt_vid_cap,
        .vidioc_g_fmt_vid_cap    = soc_camera_g_fmt_vid_cap,
-       .vidioc_enum_fmt_vid_cap = soc_camera_enum_fmt_vid_cap,
        .vidioc_s_fmt_vid_cap    = soc_camera_s_fmt_vid_cap,
+       .vidioc_enum_fmt_vid_cap = soc_camera_enum_fmt_vid_cap,
        .vidioc_enum_input       = soc_camera_enum_input,
        .vidioc_g_input          = soc_camera_g_input,
        .vidioc_s_input          = soc_camera_s_input,
        .vidioc_s_std            = soc_camera_s_std,
+       .vidioc_g_std            = soc_camera_g_std,
        .vidioc_enum_framesizes  = soc_camera_enum_fsizes,
        .vidioc_reqbufs          = soc_camera_reqbufs,
-       .vidioc_try_fmt_vid_cap  = soc_camera_try_fmt_vid_cap,
        .vidioc_querybuf         = soc_camera_querybuf,
        .vidioc_qbuf             = soc_camera_qbuf,
        .vidioc_dqbuf            = soc_camera_dqbuf,
+       .vidioc_create_bufs      = soc_camera_create_bufs,
+       .vidioc_prepare_buf      = soc_camera_prepare_buf,
        .vidioc_streamon         = soc_camera_streamon,
        .vidioc_streamoff        = soc_camera_streamoff,
-       .vidioc_queryctrl        = soc_camera_queryctrl,
-       .vidioc_g_ctrl           = soc_camera_g_ctrl,
-       .vidioc_s_ctrl           = soc_camera_s_ctrl,
        .vidioc_cropcap          = soc_camera_cropcap,
        .vidioc_g_crop           = soc_camera_g_crop,
        .vidioc_s_crop           = soc_camera_s_crop,
@@ -1433,7 +1413,7 @@ static const struct v4l2_ioctl_ops soc_camera_ioctl_ops = {
 
 static int video_dev_create(struct soc_camera_device *icd)
 {
-       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
        struct video_device *vdev = video_device_alloc();
 
        if (!vdev)
@@ -1441,12 +1421,14 @@ static int video_dev_create(struct soc_camera_device *icd)
 
        strlcpy(vdev->name, ici->drv_name, sizeof(vdev->name));
 
-       vdev->parent            = &icd->dev;
+       vdev->parent            = icd->pdev;
        vdev->current_norm      = V4L2_STD_UNKNOWN;
        vdev->fops              = &soc_camera_fops;
        vdev->ioctl_ops         = &soc_camera_ioctl_ops;
        vdev->release           = video_device_release;
        vdev->tvnorms           = V4L2_STD_UNKNOWN;
+       vdev->ctrl_handler      = &icd->ctrl_handler;
+       vdev->lock              = &icd->video_lock;
 
        icd->vdev = vdev;
 
@@ -1458,20 +1440,15 @@ static int video_dev_create(struct soc_camera_device *icd)
  */
 static int soc_camera_video_start(struct soc_camera_device *icd)
 {
-       struct device_type *type = icd->vdev->dev.type;
+       const struct device_type *type = icd->vdev->dev.type;
        int ret;
 
-       if (!icd->dev.parent)
+       if (!icd->parent)
                return -ENODEV;
 
-       if (!icd->ops ||
-           !icd->ops->query_bus_param ||
-           !icd->ops->set_bus_param)
-               return -EINVAL;
-
        ret = video_register_device(icd->vdev, VFL_TYPE_GRABBER, -1);
        if (ret < 0) {
-               dev_err(&icd->dev, "video_register_device failed: %d\n", ret);
+               dev_err(icd->pdev, "video_register_device failed: %d\n", ret);
                return ret;
        }
 
@@ -1495,6 +1472,7 @@ static int __devinit soc_camera_pdrv_probe(struct platform_device *pdev)
                return -ENOMEM;
 
        icd->iface = icl->bus_id;
+       icd->link = icl;
        icd->pdev = &pdev->dev;
        platform_set_drvdata(pdev, icd);
 
@@ -1502,8 +1480,6 @@ static int __devinit soc_camera_pdrv_probe(struct platform_device *pdev)
        if (ret < 0)
                goto escdevreg;
 
-       soc_camera_device_init(&icd->dev, icl);
-
        icd->user_width         = DEFAULT_WIDTH;
        icd->user_height        = DEFAULT_HEIGHT;
 
@@ -1527,7 +1503,7 @@ static int __devexit soc_camera_pdrv_remove(struct platform_device *pdev)
        if (!icd)
                return -EINVAL;
 
-       soc_camera_device_unregister(icd);
+       list_del(&icd->list);
 
        kfree(icd);
 
@@ -1544,31 +1520,12 @@ static struct platform_driver __refdata soc_camera_pdrv = {
 
 static int __init soc_camera_init(void)
 {
-       int ret = bus_register(&soc_camera_bus_type);
-       if (ret)
-               return ret;
-       ret = driver_register(&ic_drv);
-       if (ret)
-               goto edrvr;
-
-       ret = platform_driver_probe(&soc_camera_pdrv, soc_camera_pdrv_probe);
-       if (ret)
-               goto epdr;
-
-       return 0;
-
-epdr:
-       driver_unregister(&ic_drv);
-edrvr:
-       bus_unregister(&soc_camera_bus_type);
-       return ret;
+       return platform_driver_probe(&soc_camera_pdrv, soc_camera_pdrv_probe);
 }
 
 static void __exit soc_camera_exit(void)
 {
        platform_driver_unregister(&soc_camera_pdrv);
-       driver_unregister(&ic_drv);
-       bus_unregister(&soc_camera_bus_type);
 }
 
 module_init(soc_camera_init);