]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
media: ov5640: Set JPEG output timings when outputting JPEG data
authorChen-Yu Tsai <wens@csie.org>
Fri, 18 Jan 2019 08:52:05 +0000 (03:52 -0500)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Mon, 18 Feb 2019 16:29:56 +0000 (11:29 -0500)
When compression is turned on, the on-bus data is framed according to
the compression mode, and the height and width set in VFIFO_VSIZE and
VFIFO_HSIZE. If these are not updated correctly, the sensor will send
data framed in a manner unexpected by the capture interface, such as
having more bytes per line than expected, and having the extra data
dropped. This ultimately results in corrupted data.

Set the two values when the media bus is configured for JPEG data,
meaning the sensor would be in JPEG mode.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/i2c/ov5640.c

index 13311483792c02885bb16981a997adaa3defc8aa..1c1dc401c6787205a0da9a9835b9172a9679cddc 100644 (file)
@@ -83,6 +83,8 @@
 #define OV5640_REG_SIGMADELTA_CTRL0C   0x3c0c
 #define OV5640_REG_FRAME_CTRL01                0x4202
 #define OV5640_REG_FORMAT_CONTROL00    0x4300
+#define OV5640_REG_VFIFO_HSIZE         0x4602
+#define OV5640_REG_VFIFO_VSIZE         0x4604
 #define OV5640_REG_POLARITY_CTRL00     0x4740
 #define OV5640_REG_MIPI_CTRL00         0x4800
 #define OV5640_REG_DEBUG_MODE          0x4814
@@ -1043,12 +1045,31 @@ static int ov5640_set_dvp_pclk(struct ov5640_dev *sensor, unsigned long rate)
                              (ilog2(pclk_div) << 4));
 }
 
+/* set JPEG framing sizes */
+static int ov5640_set_jpeg_timings(struct ov5640_dev *sensor,
+                                  const struct ov5640_mode_info *mode)
+{
+       int ret;
+
+       ret = ov5640_write_reg16(sensor, OV5640_REG_VFIFO_HSIZE, mode->hact);
+       if (ret < 0)
+               return ret;
+
+       return ov5640_write_reg16(sensor, OV5640_REG_VFIFO_VSIZE, mode->vact);
+}
+
 /* download ov5640 settings to sensor through i2c */
 static int ov5640_set_timings(struct ov5640_dev *sensor,
                              const struct ov5640_mode_info *mode)
 {
        int ret;
 
+       if (sensor->fmt.code == MEDIA_BUS_FMT_JPEG_1X8) {
+               ret = ov5640_set_jpeg_timings(sensor, mode);
+               if (ret < 0)
+                       return ret;
+       }
+
        ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_DVPHO, mode->hact);
        if (ret < 0)
                return ret;