diff mbox series

[54/57] media: atomisp: ov2722: Power on sensor from set_fmt() callback

Message ID 20230123125205.622152-55-hdegoede@redhat.com (mailing list archive)
State New, archived
Headers show
Series media: atomisp: Big power-management changes + lots of fixes | expand

Commit Message

Hans de Goede Jan. 23, 2023, 12:52 p.m. UTC
Depending on which order userspace makes various v4l2 calls, the sensor
might still be powered down when set_fmt is called.

What should really happen here is delay the writing of the mode-related
registers till streaming is started, but for now use the same quick fix
as the atomisp_ov2680 / atomisp_gc0310 code and call power_up() from
set_fmt() in combination with keeping track of the power-state to avoid
doing the power-up sequence twice.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/staging/media/atomisp/i2c/atomisp-ov2722.c | 12 ++++++++++++
 drivers/staging/media/atomisp/i2c/ov2722.h         |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

Comments

Andy Shevchenko Jan. 23, 2023, 6:42 p.m. UTC | #1
On Mon, Jan 23, 2023 at 01:52:02PM +0100, Hans de Goede wrote:
> Depending on which order userspace makes various v4l2 calls, the sensor
> might still be powered down when set_fmt is called.
> 
> What should really happen here is delay the writing of the mode-related
> registers till streaming is started, but for now use the same quick fix
> as the atomisp_ov2680 / atomisp_gc0310 code and call power_up() from
> set_fmt() in combination with keeping track of the power-state to avoid
> doing the power-up sequence twice.

OK.
Reviewed-by: Andy Shevchenko <andy@kernel.org>

Is there a plan to drop this hack from all of the (AtomISP) sensor drivers?

> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/staging/media/atomisp/i2c/atomisp-ov2722.c | 12 ++++++++++++
>  drivers/staging/media/atomisp/i2c/ov2722.h         |  2 +-
>  2 files changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/media/atomisp/i2c/atomisp-ov2722.c b/drivers/staging/media/atomisp/i2c/atomisp-ov2722.c
> index e09c80d1f9ec..5d2e6e2e72f0 100644
> --- a/drivers/staging/media/atomisp/i2c/atomisp-ov2722.c
> +++ b/drivers/staging/media/atomisp/i2c/atomisp-ov2722.c
> @@ -528,6 +528,9 @@ static int power_up(struct v4l2_subdev *sd)
>  		return -ENODEV;
>  	}
>  
> +	if (dev->power_on == 1)
> +		return 0; /* Already on */
> +
>  	/* power control */
>  	ret = power_ctrl(sd, 1);
>  	if (ret)
> @@ -552,6 +555,7 @@ static int power_up(struct v4l2_subdev *sd)
>  	/* according to DS, 20ms is needed between PWDN and i2c access */
>  	msleep(20);
>  
> +	dev->power_on = 1;
>  	return 0;
>  
>  fail_clk:
> @@ -575,6 +579,9 @@ static int power_down(struct v4l2_subdev *sd)
>  		return -ENODEV;
>  	}
>  
> +	if (dev->power_on == 0)
> +		return 0; /* Already off */
> +
>  	ret = dev->platform_data->flisclk_ctrl(sd, 0);
>  	if (ret)
>  		dev_err(&client->dev, "flisclk failed\n");
> @@ -592,6 +599,7 @@ static int power_down(struct v4l2_subdev *sd)
>  	if (ret)
>  		dev_err(&client->dev, "vprog failed.\n");
>  
> +	dev->power_on = 0;
>  	return ret;
>  }
>  
> @@ -669,6 +677,9 @@ static int ov2722_set_fmt(struct v4l2_subdev *sd,
>  
>  	mutex_lock(&dev->input_lock);
>  
> +	/* s_power has not been called yet for std v4l2 clients (camorama) */
> +	power_up(sd);
> +
>  	dev->pixels_per_line = dev->res->pixels_per_line;
>  	dev->lines_per_frame = dev->res->lines_per_frame;
>  
> @@ -959,6 +970,7 @@ static int ov2722_probe(struct i2c_client *client)
>  		return -ENOMEM;
>  
>  	mutex_init(&dev->input_lock);
> +	dev->power_on = -1;
>  
>  	dev->res = &ov2722_res_preview[0];
>  	v4l2_i2c_subdev_init(&dev->sd, client, &ov2722_ops);
> diff --git a/drivers/staging/media/atomisp/i2c/ov2722.h b/drivers/staging/media/atomisp/i2c/ov2722.h
> index 020743a944c4..640d3ffcaa5c 100644
> --- a/drivers/staging/media/atomisp/i2c/ov2722.h
> +++ b/drivers/staging/media/atomisp/i2c/ov2722.h
> @@ -198,7 +198,7 @@ struct ov2722_device {
>  	struct ov2722_resolution *res;
>  
>  	struct camera_sensor_platform_data *platform_data;
> -	int run_mode;
> +	int power_on;
>  	u16 pixels_per_line;
>  	u16 lines_per_frame;
>  	u8 type;
> -- 
> 2.39.0
>
Hans de Goede Jan. 24, 2023, 11:32 a.m. UTC | #2
Hi,

On 1/23/23 19:42, Andy Shevchenko wrote:
> On Mon, Jan 23, 2023 at 01:52:02PM +0100, Hans de Goede wrote:
>> Depending on which order userspace makes various v4l2 calls, the sensor
>> might still be powered down when set_fmt is called.
>>
>> What should really happen here is delay the writing of the mode-related
>> registers till streaming is started, but for now use the same quick fix
>> as the atomisp_ov2680 / atomisp_gc0310 code and call power_up() from
>> set_fmt() in combination with keeping track of the power-state to avoid
>> doing the power-up sequence twice.
> 
> OK.
> Reviewed-by: Andy Shevchenko <andy@kernel.org>
> 
> Is there a plan to drop this hack from all of the (AtomISP) sensor drivers?

Yes this is the next one on my list to convert to runtime-pm +
ACPI powermanagement. Which needs to be done on a sensor by sensor
basis :|

Regards,

Hans




> 
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  drivers/staging/media/atomisp/i2c/atomisp-ov2722.c | 12 ++++++++++++
>>  drivers/staging/media/atomisp/i2c/ov2722.h         |  2 +-
>>  2 files changed, 13 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/staging/media/atomisp/i2c/atomisp-ov2722.c b/drivers/staging/media/atomisp/i2c/atomisp-ov2722.c
>> index e09c80d1f9ec..5d2e6e2e72f0 100644
>> --- a/drivers/staging/media/atomisp/i2c/atomisp-ov2722.c
>> +++ b/drivers/staging/media/atomisp/i2c/atomisp-ov2722.c
>> @@ -528,6 +528,9 @@ static int power_up(struct v4l2_subdev *sd)
>>  		return -ENODEV;
>>  	}
>>  
>> +	if (dev->power_on == 1)
>> +		return 0; /* Already on */
>> +
>>  	/* power control */
>>  	ret = power_ctrl(sd, 1);
>>  	if (ret)
>> @@ -552,6 +555,7 @@ static int power_up(struct v4l2_subdev *sd)
>>  	/* according to DS, 20ms is needed between PWDN and i2c access */
>>  	msleep(20);
>>  
>> +	dev->power_on = 1;
>>  	return 0;
>>  
>>  fail_clk:
>> @@ -575,6 +579,9 @@ static int power_down(struct v4l2_subdev *sd)
>>  		return -ENODEV;
>>  	}
>>  
>> +	if (dev->power_on == 0)
>> +		return 0; /* Already off */
>> +
>>  	ret = dev->platform_data->flisclk_ctrl(sd, 0);
>>  	if (ret)
>>  		dev_err(&client->dev, "flisclk failed\n");
>> @@ -592,6 +599,7 @@ static int power_down(struct v4l2_subdev *sd)
>>  	if (ret)
>>  		dev_err(&client->dev, "vprog failed.\n");
>>  
>> +	dev->power_on = 0;
>>  	return ret;
>>  }
>>  
>> @@ -669,6 +677,9 @@ static int ov2722_set_fmt(struct v4l2_subdev *sd,
>>  
>>  	mutex_lock(&dev->input_lock);
>>  
>> +	/* s_power has not been called yet for std v4l2 clients (camorama) */
>> +	power_up(sd);
>> +
>>  	dev->pixels_per_line = dev->res->pixels_per_line;
>>  	dev->lines_per_frame = dev->res->lines_per_frame;
>>  
>> @@ -959,6 +970,7 @@ static int ov2722_probe(struct i2c_client *client)
>>  		return -ENOMEM;
>>  
>>  	mutex_init(&dev->input_lock);
>> +	dev->power_on = -1;
>>  
>>  	dev->res = &ov2722_res_preview[0];
>>  	v4l2_i2c_subdev_init(&dev->sd, client, &ov2722_ops);
>> diff --git a/drivers/staging/media/atomisp/i2c/ov2722.h b/drivers/staging/media/atomisp/i2c/ov2722.h
>> index 020743a944c4..640d3ffcaa5c 100644
>> --- a/drivers/staging/media/atomisp/i2c/ov2722.h
>> +++ b/drivers/staging/media/atomisp/i2c/ov2722.h
>> @@ -198,7 +198,7 @@ struct ov2722_device {
>>  	struct ov2722_resolution *res;
>>  
>>  	struct camera_sensor_platform_data *platform_data;
>> -	int run_mode;
>> +	int power_on;
>>  	u16 pixels_per_line;
>>  	u16 lines_per_frame;
>>  	u8 type;
>> -- 
>> 2.39.0
>>
>
diff mbox series

Patch

diff --git a/drivers/staging/media/atomisp/i2c/atomisp-ov2722.c b/drivers/staging/media/atomisp/i2c/atomisp-ov2722.c
index e09c80d1f9ec..5d2e6e2e72f0 100644
--- a/drivers/staging/media/atomisp/i2c/atomisp-ov2722.c
+++ b/drivers/staging/media/atomisp/i2c/atomisp-ov2722.c
@@ -528,6 +528,9 @@  static int power_up(struct v4l2_subdev *sd)
 		return -ENODEV;
 	}
 
+	if (dev->power_on == 1)
+		return 0; /* Already on */
+
 	/* power control */
 	ret = power_ctrl(sd, 1);
 	if (ret)
@@ -552,6 +555,7 @@  static int power_up(struct v4l2_subdev *sd)
 	/* according to DS, 20ms is needed between PWDN and i2c access */
 	msleep(20);
 
+	dev->power_on = 1;
 	return 0;
 
 fail_clk:
@@ -575,6 +579,9 @@  static int power_down(struct v4l2_subdev *sd)
 		return -ENODEV;
 	}
 
+	if (dev->power_on == 0)
+		return 0; /* Already off */
+
 	ret = dev->platform_data->flisclk_ctrl(sd, 0);
 	if (ret)
 		dev_err(&client->dev, "flisclk failed\n");
@@ -592,6 +599,7 @@  static int power_down(struct v4l2_subdev *sd)
 	if (ret)
 		dev_err(&client->dev, "vprog failed.\n");
 
+	dev->power_on = 0;
 	return ret;
 }
 
@@ -669,6 +677,9 @@  static int ov2722_set_fmt(struct v4l2_subdev *sd,
 
 	mutex_lock(&dev->input_lock);
 
+	/* s_power has not been called yet for std v4l2 clients (camorama) */
+	power_up(sd);
+
 	dev->pixels_per_line = dev->res->pixels_per_line;
 	dev->lines_per_frame = dev->res->lines_per_frame;
 
@@ -959,6 +970,7 @@  static int ov2722_probe(struct i2c_client *client)
 		return -ENOMEM;
 
 	mutex_init(&dev->input_lock);
+	dev->power_on = -1;
 
 	dev->res = &ov2722_res_preview[0];
 	v4l2_i2c_subdev_init(&dev->sd, client, &ov2722_ops);
diff --git a/drivers/staging/media/atomisp/i2c/ov2722.h b/drivers/staging/media/atomisp/i2c/ov2722.h
index 020743a944c4..640d3ffcaa5c 100644
--- a/drivers/staging/media/atomisp/i2c/ov2722.h
+++ b/drivers/staging/media/atomisp/i2c/ov2722.h
@@ -198,7 +198,7 @@  struct ov2722_device {
 	struct ov2722_resolution *res;
 
 	struct camera_sensor_platform_data *platform_data;
-	int run_mode;
+	int power_on;
 	u16 pixels_per_line;
 	u16 lines_per_frame;
 	u8 type;