From 0d90331a44d0f718b7327a94fc72612ddcb4ac0f Mon Sep 17 00:00:00 2001 From: Frieder Schrempf Date: Thu, 22 Apr 2021 18:01:44 +0200 Subject: [PATCH] media: i2c: adv7180: Don't enable CSI2 output before streaming started Currently the MIPI CSI data output is turned on when s_power() is called. This can cause trouble with the host, when the upstream controller is turned on while the data stream is already running. Let's move the switching of the output to s_stream() to handle this properly. TODO: Fix the runtime suspend Signed-off-by: Frieder Schrempf --- drivers/media/i2c/adv7180.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c index 78b51d2ee3518..9156ca30cec7f 100644 --- a/drivers/media/i2c/adv7180.c +++ b/drivers/media/i2c/adv7180.c @@ -502,33 +502,13 @@ static void adv7180_set_reset_pin(struct adv7180_state *state, bool on) static int adv7180_set_power(struct adv7180_state *state, bool on) { u8 val; - int ret; if (on) val = ADV7180_PWR_MAN_ON; else val = ADV7180_PWR_MAN_OFF; - ret = adv7180_write(state, ADV7180_REG_PWR_MAN, val); - if (ret) - return ret; - - if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) { - if (on) { - adv7180_csi_write(state, 0xDE, 0x02); - adv7180_csi_write(state, 0xD2, 0xF7); - adv7180_csi_write(state, 0xD8, 0x65); - adv7180_csi_write(state, 0xE0, 0x09); - adv7180_csi_write(state, 0x2C, 0x00); - if (state->field == V4L2_FIELD_NONE) - adv7180_csi_write(state, 0x1D, 0x80); - adv7180_csi_write(state, 0x00, 0x00); - } else { - adv7180_csi_write(state, 0x00, 0x80); - } - } - - return 0; + return adv7180_write(state, ADV7180_REG_PWR_MAN, val); } static int adv7180_s_power(struct v4l2_subdev *sd, int on) @@ -834,6 +814,7 @@ static int adv7180_s_stream(struct v4l2_subdev *sd, int enable) /* It's always safe to stop streaming, no need to take the lock */ if (!enable) { + adv7180_csi_write(state, 0x00, 0x80); state->streaming = enable; return 0; } @@ -842,6 +823,16 @@ static int adv7180_s_stream(struct v4l2_subdev *sd, int enable) ret = mutex_lock_interruptible(&state->mutex); if (ret) return ret; + + adv7180_csi_write(state, 0xDE, 0x02); + adv7180_csi_write(state, 0xD2, 0xF7); + adv7180_csi_write(state, 0xD8, 0x65); + adv7180_csi_write(state, 0xE0, 0x09); + adv7180_csi_write(state, 0x2C, 0x00); + if (state->field == V4L2_FIELD_NONE) + adv7180_csi_write(state, 0x1D, 0x80); + adv7180_csi_write(state, 0x00, 0x00); + state->streaming = enable; mutex_unlock(&state->mutex); return 0; -- GitLab