mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 1/2] media: i2c: OV5647: ensure clock lane in LP-11 state before streaming on
@ 2017-10-01 10:22 Jacob Chen
  2017-10-01 10:22 ` [PATCH v3 2/2] media: i2c: OV5647: change to use macro for the registers Jacob Chen
  2017-10-16 12:23 ` [PATCH v3 1/2] media: i2c: OV5647: ensure clock lane in LP-11 state before streaming on Sakari Ailus
  0 siblings, 2 replies; 5+ messages in thread
From: Jacob Chen @ 2017-10-01 10:22 UTC (permalink / raw)
  To: linux-media
  Cc: linux-kernel, mchehab, vladimir_zapolskiy, hans.verkuil,
	sakari.ailus, lolivei, p.zabel, Jacob Chen

When I was supporting Rpi Camera Module on the ASUS Tinker board,
I found this driver have some issues with rockchip's mipi-csi driver.
It didn't place clock lane in LP-11 state before performing
D-PHY initialisation.

>From our experience, on some OV sensors,
LP-11 state is not achieved while BIT(5)-0x4800 is cleared.

So let's set BIT(5) and BIT(0) both while not streaming, in order to
coax the clock lane into LP-11 state.

0x4800 : MIPI CTRL 00
	BIT(5) : clock lane gate enable
		0: continuous
		1: none-continuous
	BIT(0) : manually set clock lane
		0: Not used
		1: used

Signed-off-by: Jacob Chen <jacob-chen@iotwrt.com>
---
 drivers/media/i2c/ov5647.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
index 95ce90fdb876..247302d01f53 100644
--- a/drivers/media/i2c/ov5647.c
+++ b/drivers/media/i2c/ov5647.c
@@ -253,6 +253,10 @@ static int ov5647_stream_on(struct v4l2_subdev *sd)
 {
 	int ret;
 
+	ret = ov5647_write(sd, 0x4800, 0x04);
+	if (ret < 0)
+		return ret;
+
 	ret = ov5647_write(sd, 0x4202, 0x00);
 	if (ret < 0)
 		return ret;
@@ -264,6 +268,10 @@ static int ov5647_stream_off(struct v4l2_subdev *sd)
 {
 	int ret;
 
+	ret = ov5647_write(sd, 0x4800, 0x25);
+	if (ret < 0)
+		return ret;
+
 	ret = ov5647_write(sd, 0x4202, 0x0f);
 	if (ret < 0)
 		return ret;
@@ -320,7 +328,10 @@ static int __sensor_init(struct v4l2_subdev *sd)
 			return ret;
 	}
 
-	return ov5647_write(sd, 0x4800, 0x04);
+	/*
+	 * stream off to make the clock lane into LP-11 state.
+	 */
+	return ov5647_stream_off(sd);
 }
 
 static int ov5647_sensor_power(struct v4l2_subdev *sd, int on)
-- 
2.14.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 2/2] media: i2c: OV5647: change to use macro for the registers
  2017-10-01 10:22 [PATCH v3 1/2] media: i2c: OV5647: ensure clock lane in LP-11 state before streaming on Jacob Chen
@ 2017-10-01 10:22 ` Jacob Chen
  2017-10-16 12:23 ` [PATCH v3 1/2] media: i2c: OV5647: ensure clock lane in LP-11 state before streaming on Sakari Ailus
  1 sibling, 0 replies; 5+ messages in thread
From: Jacob Chen @ 2017-10-01 10:22 UTC (permalink / raw)
  To: linux-media
  Cc: linux-kernel, mchehab, vladimir_zapolskiy, hans.verkuil,
	sakari.ailus, lolivei, p.zabel, Jacob Chen

ref docuemnt:
  ov5647-datasheet-v1.00-2009

Signed-off-by: Jacob Chen <jacob-chen@iotwrt.com>
---
 drivers/media/i2c/ov5647.c | 42 ++++++++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
index 247302d01f53..34179d232a35 100644
--- a/drivers/media/i2c/ov5647.c
+++ b/drivers/media/i2c/ov5647.c
@@ -35,9 +35,18 @@
 
 #define SENSOR_NAME "ov5647"
 
-#define OV5647_SW_RESET		0x0103
-#define OV5647_REG_CHIPID_H	0x300A
-#define OV5647_REG_CHIPID_L	0x300B
+#define MIPI_CTRL00_CLOCK_LANE_GATE		BIT(5)
+#define MIPI_CTRL00_BUS_IDLE			BIT(2)
+#define MIPI_CTRL00_CLOCK_LANE_DISABLE		BIT(0)
+
+#define OV5647_SW_STANDBY		0x0100
+#define OV5647_SW_RESET			0x0103
+#define OV5647_REG_CHIPID_H		0x300A
+#define OV5647_REG_CHIPID_L		0x300B
+#define OV5640_REG_PAD_OUT		0x300D
+#define OV5647_REG_FRAME_OFF_NUMBER	0x4202
+#define OV5647_REG_MIPI_CTRL00		0x4800
+#define OV5647_REG_MIPI_CTRL14		0x4814
 
 #define REG_TERM 0xfffe
 #define VAL_TERM 0xfe
@@ -241,42 +250,43 @@ static int ov5647_set_virtual_channel(struct v4l2_subdev *sd, int channel)
 	u8 channel_id;
 	int ret;
 
-	ret = ov5647_read(sd, 0x4814, &channel_id);
+	ret = ov5647_read(sd, OV5647_REG_MIPI_CTRL14, &channel_id);
 	if (ret < 0)
 		return ret;
 
 	channel_id &= ~(3 << 6);
-	return ov5647_write(sd, 0x4814, channel_id | (channel << 6));
+	return ov5647_write(sd, OV5647_REG_MIPI_CTRL14, channel_id | (channel << 6));
 }
 
 static int ov5647_stream_on(struct v4l2_subdev *sd)
 {
 	int ret;
 
-	ret = ov5647_write(sd, 0x4800, 0x04);
+	ret = ov5647_write(sd, OV5647_REG_MIPI_CTRL00, MIPI_CTRL00_BUS_IDLE);
 	if (ret < 0)
 		return ret;
 
-	ret = ov5647_write(sd, 0x4202, 0x00);
+	ret = ov5647_write(sd, OV5647_REG_FRAME_OFF_NUMBER, 0x00);
 	if (ret < 0)
 		return ret;
 
-	return ov5647_write(sd, 0x300D, 0x00);
+	return ov5647_write(sd, OV5640_REG_PAD_OUT, 0x00);
 }
 
 static int ov5647_stream_off(struct v4l2_subdev *sd)
 {
 	int ret;
 
-	ret = ov5647_write(sd, 0x4800, 0x25);
+	ret = ov5647_write(sd, OV5647_REG_MIPI_CTRL00, MIPI_CTRL00_CLOCK_LANE_GATE
+			   | MIPI_CTRL00_BUS_IDLE | MIPI_CTRL00_CLOCK_LANE_DISABLE);
 	if (ret < 0)
 		return ret;
 
-	ret = ov5647_write(sd, 0x4202, 0x0f);
+	ret = ov5647_write(sd, OV5647_REG_FRAME_OFF_NUMBER, 0x0f);
 	if (ret < 0)
 		return ret;
 
-	return ov5647_write(sd, 0x300D, 0x01);
+	return ov5647_write(sd, OV5640_REG_PAD_OUT, 0x01);
 }
 
 static int set_sw_standby(struct v4l2_subdev *sd, bool standby)
@@ -284,7 +294,7 @@ static int set_sw_standby(struct v4l2_subdev *sd, bool standby)
 	int ret;
 	u8 rdval;
 
-	ret = ov5647_read(sd, 0x0100, &rdval);
+	ret = ov5647_read(sd, OV5647_SW_STANDBY, &rdval);
 	if (ret < 0)
 		return ret;
 
@@ -293,7 +303,7 @@ static int set_sw_standby(struct v4l2_subdev *sd, bool standby)
 	else
 		rdval |= 0x01;
 
-	return ov5647_write(sd, 0x0100, rdval);
+	return ov5647_write(sd, OV5647_SW_STANDBY, rdval);
 }
 
 static int __sensor_init(struct v4l2_subdev *sd)
@@ -302,7 +312,7 @@ static int __sensor_init(struct v4l2_subdev *sd)
 	u8 resetval, rdval;
 	struct i2c_client *client = v4l2_get_subdevdata(sd);
 
-	ret = ov5647_read(sd, 0x0100, &rdval);
+	ret = ov5647_read(sd, OV5647_SW_STANDBY, &rdval);
 	if (ret < 0)
 		return ret;
 
@@ -317,13 +327,13 @@ static int __sensor_init(struct v4l2_subdev *sd)
 	if (ret < 0)
 		return ret;
 
-	ret = ov5647_read(sd, 0x0100, &resetval);
+	ret = ov5647_read(sd, OV5647_SW_STANDBY, &resetval);
 	if (ret < 0)
 		return ret;
 
 	if (!(resetval & 0x01)) {
 		dev_err(&client->dev, "Device was in SW standby");
-		ret = ov5647_write(sd, 0x0100, 0x01);
+		ret = ov5647_write(sd, OV5647_SW_STANDBY, 0x01);
 		if (ret < 0)
 			return ret;
 	}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 1/2] media: i2c: OV5647: ensure clock lane in LP-11 state before streaming on
  2017-10-01 10:22 [PATCH v3 1/2] media: i2c: OV5647: ensure clock lane in LP-11 state before streaming on Jacob Chen
  2017-10-01 10:22 ` [PATCH v3 2/2] media: i2c: OV5647: change to use macro for the registers Jacob Chen
@ 2017-10-16 12:23 ` Sakari Ailus
  2017-10-16 14:19   ` Luis Oliveira
  1 sibling, 1 reply; 5+ messages in thread
From: Sakari Ailus @ 2017-10-16 12:23 UTC (permalink / raw)
  To: Jacob Chen
  Cc: linux-media, linux-kernel, mchehab, vladimir_zapolskiy,
	hans.verkuil, sakari.ailus, lolivei, p.zabel, Luis.Oliveira

Luis,

Any comment on these?

On Sun, Oct 01, 2017 at 06:22:37PM +0800, Jacob Chen wrote:
> When I was supporting Rpi Camera Module on the ASUS Tinker board,
> I found this driver have some issues with rockchip's mipi-csi driver.
> It didn't place clock lane in LP-11 state before performing
> D-PHY initialisation.
> 
> From our experience, on some OV sensors,
> LP-11 state is not achieved while BIT(5)-0x4800 is cleared.
> 
> So let's set BIT(5) and BIT(0) both while not streaming, in order to
> coax the clock lane into LP-11 state.
> 
> 0x4800 : MIPI CTRL 00
> 	BIT(5) : clock lane gate enable
> 		0: continuous
> 		1: none-continuous
> 	BIT(0) : manually set clock lane
> 		0: Not used
> 		1: used
> 
> Signed-off-by: Jacob Chen <jacob-chen@iotwrt.com>
> ---
>  drivers/media/i2c/ov5647.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
> index 95ce90fdb876..247302d01f53 100644
> --- a/drivers/media/i2c/ov5647.c
> +++ b/drivers/media/i2c/ov5647.c
> @@ -253,6 +253,10 @@ static int ov5647_stream_on(struct v4l2_subdev *sd)
>  {
>  	int ret;
>  
> +	ret = ov5647_write(sd, 0x4800, 0x04);
> +	if (ret < 0)
> +		return ret;
> +
>  	ret = ov5647_write(sd, 0x4202, 0x00);
>  	if (ret < 0)
>  		return ret;
> @@ -264,6 +268,10 @@ static int ov5647_stream_off(struct v4l2_subdev *sd)
>  {
>  	int ret;
>  
> +	ret = ov5647_write(sd, 0x4800, 0x25);
> +	if (ret < 0)
> +		return ret;
> +
>  	ret = ov5647_write(sd, 0x4202, 0x0f);
>  	if (ret < 0)
>  		return ret;
> @@ -320,7 +328,10 @@ static int __sensor_init(struct v4l2_subdev *sd)
>  			return ret;
>  	}
>  
> -	return ov5647_write(sd, 0x4800, 0x04);
> +	/*
> +	 * stream off to make the clock lane into LP-11 state.
> +	 */
> +	return ov5647_stream_off(sd);
>  }
>  
>  static int ov5647_sensor_power(struct v4l2_subdev *sd, int on)
> -- 
> 2.14.1
> 

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 1/2] media: i2c: OV5647: ensure clock lane in LP-11 state before streaming on
  2017-10-16 12:23 ` [PATCH v3 1/2] media: i2c: OV5647: ensure clock lane in LP-11 state before streaming on Sakari Ailus
@ 2017-10-16 14:19   ` Luis Oliveira
  2017-10-16 14:49     ` Sakari Ailus
  0 siblings, 1 reply; 5+ messages in thread
From: Luis Oliveira @ 2017-10-16 14:19 UTC (permalink / raw)
  To: Sakari Ailus, Jacob Chen
  Cc: linux-media, linux-kernel, mchehab, vladimir_zapolskiy,
	hans.verkuil, sakari.ailus, Luis.Oliveira, p.zabel, Joao Pinto

Hi all,

Sorry for the delay and thank you for the fix.
I just checked the databook and the changes makes sense.

cheers,
Luis

On 16-Oct-17 13:23, Sakari Ailus wrote:
> Luis,
> 
> Any comment on these?
> 
> On Sun, Oct 01, 2017 at 06:22:37PM +0800, Jacob Chen wrote:
>> When I was supporting Rpi Camera Module on the ASUS Tinker board,
>> I found this driver have some issues with rockchip's mipi-csi driver.
>> It didn't place clock lane in LP-11 state before performing
>> D-PHY initialisation.
>>
>> From our experience, on some OV sensors,
>> LP-11 state is not achieved while BIT(5)-0x4800 is cleared.
>>
>> So let's set BIT(5) and BIT(0) both while not streaming, in order to
>> coax the clock lane into LP-11 state.
>>
>> 0x4800 : MIPI CTRL 00
>> 	BIT(5) : clock lane gate enable
>> 		0: continuous
>> 		1: none-continuous
>> 	BIT(0) : manually set clock lane
>> 		0: Not used
>> 		1: used
>>
>> Signed-off-by: Jacob Chen <jacob-chen@iotwrt.com>
>> ---
>>  drivers/media/i2c/ov5647.c | 13 ++++++++++++-
>>  1 file changed, 12 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
>> index 95ce90fdb876..247302d01f53 100644
>> --- a/drivers/media/i2c/ov5647.c
>> +++ b/drivers/media/i2c/ov5647.c
>> @@ -253,6 +253,10 @@ static int ov5647_stream_on(struct v4l2_subdev *sd)
>>  {
>>  	int ret;
>>  
>> +	ret = ov5647_write(sd, 0x4800, 0x04);
>> +	if (ret < 0)
>> +		return ret;
>> +
>>  	ret = ov5647_write(sd, 0x4202, 0x00);
>>  	if (ret < 0)
>>  		return ret;
>> @@ -264,6 +268,10 @@ static int ov5647_stream_off(struct v4l2_subdev *sd)
>>  {
>>  	int ret;
>>  
>> +	ret = ov5647_write(sd, 0x4800, 0x25);
>> +	if (ret < 0)
>> +		return ret;
>> +
>>  	ret = ov5647_write(sd, 0x4202, 0x0f);
>>  	if (ret < 0)
>>  		return ret;
>> @@ -320,7 +328,10 @@ static int __sensor_init(struct v4l2_subdev *sd)
>>  			return ret;
>>  	}
>>  
>> -	return ov5647_write(sd, 0x4800, 0x04);
>> +	/*
>> +	 * stream off to make the clock lane into LP-11 state.
>> +	 */
>> +	return ov5647_stream_off(sd);
>>  }
>>  
>>  static int ov5647_sensor_power(struct v4l2_subdev *sd, int on)
>> -- 
>> 2.14.1
>>
> 
Reviewed-by: Luis Oliveira <lolivei@synopsys.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 1/2] media: i2c: OV5647: ensure clock lane in LP-11 state before streaming on
  2017-10-16 14:19   ` Luis Oliveira
@ 2017-10-16 14:49     ` Sakari Ailus
  0 siblings, 0 replies; 5+ messages in thread
From: Sakari Ailus @ 2017-10-16 14:49 UTC (permalink / raw)
  To: Luis Oliveira
  Cc: Jacob Chen, linux-media, linux-kernel, mchehab,
	vladimir_zapolskiy, hans.verkuil, sakari.ailus, p.zabel,
	Joao Pinto

On Mon, Oct 16, 2017 at 03:19:09PM +0100, Luis Oliveira wrote:
> Hi all,
> 
> Sorry for the delay and thank you for the fix.
> I just checked the databook and the changes makes sense.
> 
> cheers,
> Luis
> 
> On 16-Oct-17 13:23, Sakari Ailus wrote:
> > Luis,
> > 
> > Any comment on these?
> > 
> > On Sun, Oct 01, 2017 at 06:22:37PM +0800, Jacob Chen wrote:
> >> When I was supporting Rpi Camera Module on the ASUS Tinker board,
> >> I found this driver have some issues with rockchip's mipi-csi driver.
> >> It didn't place clock lane in LP-11 state before performing
> >> D-PHY initialisation.
> >>
> >> From our experience, on some OV sensors,
> >> LP-11 state is not achieved while BIT(5)-0x4800 is cleared.
> >>
> >> So let's set BIT(5) and BIT(0) both while not streaming, in order to
> >> coax the clock lane into LP-11 state.
> >>
> >> 0x4800 : MIPI CTRL 00
> >> 	BIT(5) : clock lane gate enable
> >> 		0: continuous
> >> 		1: none-continuous
> >> 	BIT(0) : manually set clock lane
> >> 		0: Not used
> >> 		1: used
> >>
> >> Signed-off-by: Jacob Chen <jacob-chen@iotwrt.com>
> >> ---
> >>  drivers/media/i2c/ov5647.c | 13 ++++++++++++-
> >>  1 file changed, 12 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
> >> index 95ce90fdb876..247302d01f53 100644
> >> --- a/drivers/media/i2c/ov5647.c
> >> +++ b/drivers/media/i2c/ov5647.c
> >> @@ -253,6 +253,10 @@ static int ov5647_stream_on(struct v4l2_subdev *sd)
> >>  {
> >>  	int ret;
> >>  
> >> +	ret = ov5647_write(sd, 0x4800, 0x04);
> >> +	if (ret < 0)
> >> +		return ret;
> >> +
> >>  	ret = ov5647_write(sd, 0x4202, 0x00);
> >>  	if (ret < 0)
> >>  		return ret;
> >> @@ -264,6 +268,10 @@ static int ov5647_stream_off(struct v4l2_subdev *sd)
> >>  {
> >>  	int ret;
> >>  
> >> +	ret = ov5647_write(sd, 0x4800, 0x25);
> >> +	if (ret < 0)
> >> +		return ret;
> >> +
> >>  	ret = ov5647_write(sd, 0x4202, 0x0f);
> >>  	if (ret < 0)
> >>  		return ret;
> >> @@ -320,7 +328,10 @@ static int __sensor_init(struct v4l2_subdev *sd)
> >>  			return ret;
> >>  	}
> >>  
> >> -	return ov5647_write(sd, 0x4800, 0x04);
> >> +	/*
> >> +	 * stream off to make the clock lane into LP-11 state.
> >> +	 */
> >> +	return ov5647_stream_off(sd);
> >>  }
> >>  
> >>  static int ov5647_sensor_power(struct v4l2_subdev *sd, int on)
> >> -- 
> >> 2.14.1
> >>
> > 
> Reviewed-by: Luis Oliveira <lolivei@synopsys.com>

Thanks. I'll apply the patches then.

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-10-16 14:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-01 10:22 [PATCH v3 1/2] media: i2c: OV5647: ensure clock lane in LP-11 state before streaming on Jacob Chen
2017-10-01 10:22 ` [PATCH v3 2/2] media: i2c: OV5647: change to use macro for the registers Jacob Chen
2017-10-16 12:23 ` [PATCH v3 1/2] media: i2c: OV5647: ensure clock lane in LP-11 state before streaming on Sakari Ailus
2017-10-16 14:19   ` Luis Oliveira
2017-10-16 14:49     ` Sakari Ailus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®