[PATCH v3 1/2] media: i2c: imx412: fix sensor power-on timing

Wenmeng Liu posted 2 patches 3 weeks ago
There is a newer version of this series
[PATCH v3 1/2] media: i2c: imx412: fix sensor power-on timing
Posted by Wenmeng Liu 3 weeks ago
Assert the reset GPIO at the start of power-on, enable regulators and the
clock, then deassert reset. This avoids a mismatch where the first
power-up (when the reset GPIO defaults deasserted) differs from subsequent
cycles.

Signed-off-by: Wenmeng Liu <wenmeng.liu@oss.qualcomm.com>
---
 drivers/media/i2c/imx412.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/imx412.c b/drivers/media/i2c/imx412.c
index b3826f80354703b17b416dc233854da3f5736e38..ebc2fb706442365f541540bf4ce9d307d42e0061 100644
--- a/drivers/media/i2c/imx412.c
+++ b/drivers/media/i2c/imx412.c
@@ -1022,6 +1022,8 @@ static int imx412_power_on(struct device *dev)
 	struct imx412 *imx412 = to_imx412(sd);
 	int ret;
 
+	gpiod_set_value_cansleep(imx412->reset_gpio, 1);
+
 	ret = regulator_bulk_enable(ARRAY_SIZE(imx412_supply_names),
 				    imx412->supplies);
 	if (ret < 0) {
@@ -1029,20 +1031,19 @@ static int imx412_power_on(struct device *dev)
 		return ret;
 	}
 
-	gpiod_set_value_cansleep(imx412->reset_gpio, 0);
-
 	ret = clk_prepare_enable(imx412->inclk);
 	if (ret) {
 		dev_err(imx412->dev, "fail to enable inclk\n");
 		goto error_reset;
 	}
 
+	gpiod_set_value_cansleep(imx412->reset_gpio, 0);
+
 	usleep_range(1000, 1200);
 
 	return 0;
 
 error_reset:
-	gpiod_set_value_cansleep(imx412->reset_gpio, 1);
 	regulator_bulk_disable(ARRAY_SIZE(imx412_supply_names),
 			       imx412->supplies);
 

-- 
2.34.1
Re: [PATCH v3 1/2] media: i2c: imx412: fix sensor power-on timing
Posted by Sakari Ailus 2 weeks, 6 days ago
Hi Wenmeng,

On Mon, Jan 19, 2026 at 06:15:01PM +0800, Wenmeng Liu wrote:
> Assert the reset GPIO at the start of power-on, enable regulators and the
> clock, then deassert reset. This avoids a mismatch where the first
> power-up (when the reset GPIO defaults deasserted) differs from subsequent
> cycles.
> 
> Signed-off-by: Wenmeng Liu <wenmeng.liu@oss.qualcomm.com>
> ---
>  drivers/media/i2c/imx412.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/i2c/imx412.c b/drivers/media/i2c/imx412.c
> index b3826f80354703b17b416dc233854da3f5736e38..ebc2fb706442365f541540bf4ce9d307d42e0061 100644
> --- a/drivers/media/i2c/imx412.c
> +++ b/drivers/media/i2c/imx412.c
> @@ -1022,6 +1022,8 @@ static int imx412_power_on(struct device *dev)
>  	struct imx412 *imx412 = to_imx412(sd);
>  	int ret;
>  
> +	gpiod_set_value_cansleep(imx412->reset_gpio, 1);

I'd assert reset in probe() so you can drop this line.

> +
>  	ret = regulator_bulk_enable(ARRAY_SIZE(imx412_supply_names),
>  				    imx412->supplies);
>  	if (ret < 0) {
> @@ -1029,20 +1031,19 @@ static int imx412_power_on(struct device *dev)
>  		return ret;
>  	}
>  
> -	gpiod_set_value_cansleep(imx412->reset_gpio, 0);
> -
>  	ret = clk_prepare_enable(imx412->inclk);
>  	if (ret) {
>  		dev_err(imx412->dev, "fail to enable inclk\n");
>  		goto error_reset;
>  	}
>  
> +	gpiod_set_value_cansleep(imx412->reset_gpio, 0);
> +
>  	usleep_range(1000, 1200);
>  
>  	return 0;
>  
>  error_reset:
> -	gpiod_set_value_cansleep(imx412->reset_gpio, 1);
>  	regulator_bulk_disable(ARRAY_SIZE(imx412_supply_names),
>  			       imx412->supplies);
>  
> 

-- 
Regards,

Sakari Ailus
Re: [PATCH v3 1/2] media: i2c: imx412: fix sensor power-on timing
Posted by Wenmeng Liu 2 weeks, 6 days ago
Hi Sakari,

On 1/19/2026 7:35 PM, Sakari Ailus wrote:
> Hi Wenmeng,
> 
> On Mon, Jan 19, 2026 at 06:15:01PM +0800, Wenmeng Liu wrote:
>> Assert the reset GPIO at the start of power-on, enable regulators and the
>> clock, then deassert reset. This avoids a mismatch where the first
>> power-up (when the reset GPIO defaults deasserted) differs from subsequent
>> cycles.
>>
>> Signed-off-by: Wenmeng Liu <wenmeng.liu@oss.qualcomm.com>
>> ---
>>   drivers/media/i2c/imx412.c | 7 ++++---
>>   1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/media/i2c/imx412.c b/drivers/media/i2c/imx412.c
>> index b3826f80354703b17b416dc233854da3f5736e38..ebc2fb706442365f541540bf4ce9d307d42e0061 100644
>> --- a/drivers/media/i2c/imx412.c
>> +++ b/drivers/media/i2c/imx412.c
>> @@ -1022,6 +1022,8 @@ static int imx412_power_on(struct device *dev)
>>   	struct imx412 *imx412 = to_imx412(sd);
>>   	int ret;
>>   
>> +	gpiod_set_value_cansleep(imx412->reset_gpio, 1);
> 
> I'd assert reset in probe() so you can drop this line.

Sure, will update the patch.

Thanks,
Wenmeng