MLK-22861: media: imx8: fix camera hang issue after system resume rel_imx_4.19.35_1.1.0
authorGuoniu.zhou <guoniu.zhou@nxp.com>
Wed, 30 Oct 2019 06:18:41 +0000 (14:18 +0800)
committerGuoniu.zhou <guoniu.zhou@nxp.com>
Wed, 30 Oct 2019 11:02:38 +0000 (19:02 +0800)
For imx8qxp/qm, gpio will go to low level when system suspend and
will to high when system resume. It will lead ov5640 sensor to reset.
So add reinitialization for sensor when system resume at first time.

For imx815, gpio will have no this issue because GPIO will keep high
when system suspend. So the patch is for fixing issue introduced by
MLK-22202-1. More info, please refer to the ticket.

OV5640 will work at DVP mode by default, but in our use case, it need
to work on MIPI mode, so we can know whether sensor is resetted by
system by checking 0x300E[2] bits.

Signed-off-by: Guoniu.zhou <guoniu.zhou@nxp.com>
drivers/media/platform/imx8/ov5640_mipi_v3.c

index 7b90aa2..63d80e8 100644 (file)
@@ -39,6 +39,9 @@
 #define OV5640_CHIP_ID_HIGH_BYTE        0x300A
 #define OV5640_CHIP_ID_LOW_BYTE         0x300B
 
+#define OV5640_MIPI_CONTROLL_00                0x300E
+#define MIPI_CONTROLL00_MIPI_MODE      BIT(2)
+
 #define OV5640_SENS_PAD_SOURCE 0
 #define OV5640_SENS_PADS_NUM   1
 
@@ -1011,6 +1014,7 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
        struct i2c_client *client = v4l2_get_subdevdata(sd);
        struct ov5640 *sensor = to_ov5640(client);
        int ret;
+       u8 val;
 
        if (format->pad)
                return -EINVAL;
@@ -1026,6 +1030,11 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
        if (format->which == V4L2_SUBDEV_FORMAT_TRY)
                return 0;
 
+       /* Need to reinitialize sensor after system suspend/resume */
+       ov5640_read_reg(sensor, OV5640_MIPI_CONTROLL_00, &val);
+       if (!(val & MIPI_CONTROLL00_MIPI_MODE))
+               init_device(sensor);
+
        ret = ov5640_change_mode(sensor);
        sensor->fmt = fmt;