[media] m5mols: Implement .get_frame_desc subdev callback
authorSylwester Nawrocki <s.nawrocki@samsung.com>
Tue, 18 Sep 2012 09:18:43 +0000 (06:18 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Sat, 6 Oct 2012 00:28:06 +0000 (21:28 -0300)
.get_frame_desc can be used by host interface driver to query
properties of captured frames, e.g. required memory buffer size.

Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/i2c/m5mols/m5mols.h
drivers/media/i2c/m5mols/m5mols_capture.c
drivers/media/i2c/m5mols/m5mols_core.c
drivers/media/i2c/m5mols/m5mols_reg.h

index 86c815be348cbe9214de2f87d1915b01a2452555..4ab8b370e6650c9cf193ee3ee2220b13d65e028b 100644 (file)
 #include <media/v4l2-subdev.h>
 #include "m5mols_reg.h"
 
+
+/* An amount of data transmitted in addition to the value
+ * determined by CAPP_JPEG_SIZE_MAX register.
+ */
+#define M5MOLS_JPEG_TAGS_SIZE          0x20000
+#define M5MOLS_MAIN_JPEG_SIZE_MAX      (5 * SZ_1M)
+
 extern int m5mols_debug;
 
 enum m5mols_restype {
@@ -67,12 +74,14 @@ struct m5mols_exif {
 /**
  * struct m5mols_capture - Structure for the capture capability
  * @exif: EXIF information
+ * @buf_size: internal JPEG frame buffer size, in bytes
  * @main: size in bytes of the main image
  * @thumb: size in bytes of the thumb image, if it was accompanied
  * @total: total size in bytes of the produced image
  */
 struct m5mols_capture {
        struct m5mols_exif exif;
+       unsigned int buf_size;
        u32 main;
        u32 thumb;
        u32 total;
index cb243bd278ceecce60163b6eed41ce8cb2d5c019..ab34ccedf31ea7a1a72adfe9d3324103de92b7f7 100644 (file)
@@ -105,6 +105,7 @@ static int m5mols_capture_info(struct m5mols_info *info)
 
 int m5mols_start_capture(struct m5mols_info *info)
 {
+       unsigned int framesize = info->cap.buf_size - M5MOLS_JPEG_TAGS_SIZE;
        struct v4l2_subdev *sd = &info->sd;
        int ret;
 
@@ -120,6 +121,8 @@ int m5mols_start_capture(struct m5mols_info *info)
                ret = m5mols_write(sd, CAPP_YUVOUT_MAIN, REG_JPEG);
        if (!ret)
                ret = m5mols_write(sd, CAPP_MAIN_IMAGE_SIZE, info->resolution);
+       if (!ret)
+               ret = m5mols_write(sd, CAPP_JPEG_SIZE_MAX, framesize);
        if (!ret)
                ret = m5mols_set_mode(info, REG_CAPTURE);
        if (!ret)
index 2f490ef26c388e2b868369dd189299430288efa3..8131d651de9ef11ea5c10d8e4111e9c8e4468896 100644 (file)
@@ -599,6 +599,51 @@ static int m5mols_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
        return ret;
 }
 
+static int m5mols_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
+                                struct v4l2_mbus_frame_desc *fd)
+{
+       struct m5mols_info *info = to_m5mols(sd);
+
+       if (pad != 0 || fd == NULL)
+               return -EINVAL;
+
+       mutex_lock(&info->lock);
+       /*
+        * .get_frame_desc is only used for compressed formats,
+        * thus we always return the capture frame parameters here.
+        */
+       fd->entry[0].length = info->cap.buf_size;
+       fd->entry[0].pixelcode = info->ffmt[M5MOLS_RESTYPE_CAPTURE].code;
+       mutex_unlock(&info->lock);
+
+       fd->entry[0].flags = V4L2_MBUS_FRAME_DESC_FL_LEN_MAX;
+       fd->num_entries = 1;
+
+       return 0;
+}
+
+static int m5mols_set_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
+                                struct v4l2_mbus_frame_desc *fd)
+{
+       struct m5mols_info *info = to_m5mols(sd);
+       struct v4l2_mbus_framefmt *mf = &info->ffmt[M5MOLS_RESTYPE_CAPTURE];
+
+       if (pad != 0 || fd == NULL)
+               return -EINVAL;
+
+       fd->entry[0].flags = V4L2_MBUS_FRAME_DESC_FL_LEN_MAX;
+       fd->num_entries = 1;
+       fd->entry[0].length = clamp_t(u32, fd->entry[0].length,
+                                     mf->width * mf->height,
+                                     M5MOLS_MAIN_JPEG_SIZE_MAX);
+       mutex_lock(&info->lock);
+       info->cap.buf_size = fd->entry[0].length;
+       mutex_unlock(&info->lock);
+
+       return 0;
+}
+
+
 static int m5mols_enum_mbus_code(struct v4l2_subdev *sd,
                                 struct v4l2_subdev_fh *fh,
                                 struct v4l2_subdev_mbus_code_enum *code)
@@ -615,6 +660,8 @@ static struct v4l2_subdev_pad_ops m5mols_pad_ops = {
        .enum_mbus_code = m5mols_enum_mbus_code,
        .get_fmt        = m5mols_get_fmt,
        .set_fmt        = m5mols_set_fmt,
+       .get_frame_desc = m5mols_get_frame_desc,
+       .set_frame_desc = m5mols_set_frame_desc,
 };
 
 /**
index 14d4be72aeff67b09c9dafc98416490b1acc3412..58d8027508dfe338a7b4497b2fe77793cdf3312e 100644 (file)
 #define REG_JPEG               0x10
 
 #define CAPP_MAIN_IMAGE_SIZE   I2C_REG(CAT_CAPT_PARM, 0x01, 1)
+#define CAPP_JPEG_SIZE_MAX     I2C_REG(CAT_CAPT_PARM, 0x0f, 4)
 #define CAPP_JPEG_RATIO                I2C_REG(CAT_CAPT_PARM, 0x17, 1)
 
 #define CAPP_MCC_MODE          I2C_REG(CAT_CAPT_PARM, 0x1d, 1)