V4L/DVB (9787): soc-camera: let camera host drivers decide upon pixel format
[safe/jmp/linux-2.6] / drivers / media / video / pxa_camera.c
index 2a811f8..a375872 100644 (file)
@@ -907,17 +907,43 @@ static int pxa_camera_try_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
 static int pxa_camera_set_fmt_cap(struct soc_camera_device *icd,
                                  __u32 pixfmt, struct v4l2_rect *rect)
 {
-       return icd->ops->set_fmt_cap(icd, pixfmt, rect);
+       const struct soc_camera_data_format *cam_fmt;
+       int ret;
+
+       /*
+        * TODO: find a suitable supported by the SoC output format, check
+        * whether the sensor supports one of acceptable input formats.
+        */
+       if (pixfmt) {
+               cam_fmt = soc_camera_format_by_fourcc(icd, pixfmt);
+               if (!cam_fmt)
+                       return -EINVAL;
+       }
+
+       ret = icd->ops->set_fmt_cap(icd, pixfmt, rect);
+       if (pixfmt && !ret)
+               icd->current_fmt = cam_fmt;
+
+       return ret;
 }
 
 static int pxa_camera_try_fmt_cap(struct soc_camera_device *icd,
                                  struct v4l2_format *f)
 {
+       const struct soc_camera_data_format *cam_fmt;
        int ret = pxa_camera_try_bus_param(icd, f->fmt.pix.pixelformat);
 
        if (ret < 0)
                return ret;
 
+       /*
+        * TODO: find a suitable supported by the SoC output format, check
+        * whether the sensor supports one of acceptable input formats.
+        */
+       cam_fmt = soc_camera_format_by_fourcc(icd, f->fmt.pix.pixelformat);
+       if (!cam_fmt)
+               return -EINVAL;
+
        /* limit to pxa hardware capabilities */
        if (f->fmt.pix.height < 32)
                f->fmt.pix.height = 32;
@@ -929,6 +955,10 @@ static int pxa_camera_try_fmt_cap(struct soc_camera_device *icd,
                f->fmt.pix.width = 2048;
        f->fmt.pix.width &= ~0x01;
 
+       f->fmt.pix.bytesperline = f->fmt.pix.width *
+               DIV_ROUND_UP(cam_fmt->depth, 8);
+       f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
+
        /* limit to sensor capabilities */
        return icd->ops->try_fmt_cap(icd, f);
 }