Skip to contentSkip to conversation

media: i2c: ov7251: Set enable GPIO low in probe

PATCH In review Sakari Ailus 3 participants 10 messages Jan 20, 2025 – Jan 23, 2025

Subsystems (2)
lore
Share & tools
lore

Sakari Ailus

author maintainer
#0 lore raw

PATCH 1/2 media: i2c: ov7251: Set enable GPIO low in probe

Set the enable GPIO low when acquiring it.

Fixes d30bb512da3d ("media: Add a driver for the ov7251 camera sensor")
---
 drivers/media/i2c/ov7251.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ov7251.c +1 -1
index 30f61e04ecaf..f3e2d26bb840 100644
@@ -1696,7 +1696,7 @@ static int ov7251_probe(struct i2c_client *client)
 		return PTR_ERR(ov7251->analog_regulator);
 	}
 
-	ov7251->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH);
+	ov7251->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW);
 	if (IS_ERR(ov7251->enable_gpio)) {
 		dev_err(dev, "cannot get enable gpio\n");
 		return PTR_ERR(ov7251->enable_gpio);

base-commit: 5de275c450c9496031006e0fb3f7c96a8fcaaa55

Signature · 1 line
2.39.5
author maintainer
#1 lore raw

PATCH 2/2 media: i2c: ov7251: Introduce 1 ms delay between regulators and en GPIO

Lift the xshutdown (enable) GPIO 1 ms after enabling the regulators, as required by the sensor's power-up sequence.

Fixes d30bb512da3d ("media: Add a driver for the ov7251 camera sensor")
---
 drivers/media/i2c/ov7251.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/i2c/ov7251.c +2 -0
index f3e2d26bb840..3226888d77e9 100644
@@ -922,6 +922,8 @@ static int ov7251_set_power_on(struct device *dev)
 		return ret;
 	}
 
+	usleep_range(1000, 1100);
+
 	gpiod_set_value_cansleep(ov7251->enable_gpio, 1);
 
 	/* wait at least 65536 external clock cycles */
Signature · 1 line
2.39.5
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] media: i2c: ov7251: Introduce 1 ms delay between regulators and en GPIO

Quoted 7 lines · Sakari Ailus

Lift the xshutdown (enable) GPIO 1 ms after enabling the regulators, as required by the sensor's power-up sequence.

Fixes d30bb512da3d ("media: Add a driver for the ov7251 camera sensor")
Quoted 21 lines
---
 drivers/media/i2c/ov7251.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/i2c/ov7251.c +2 -1
index f3e2d26bb840..3226888d77e9 100644
@@ -922,6 +922,8 @@ static int ov7251_set_power_on(struct device *dev)
                return ret;
        }
 
+       usleep_range(1000, 1100);
+
        gpiod_set_value_cansleep(ov7251->enable_gpio, 1);
 
        /* wait at least 65536 external clock cycles */
--

2.39.5

#3 lore raw

Re: [PATCH 2/2] media: i2c: ov7251: Introduce 1 ms delay between regulators and en GPIO

In reply to Sakari Ailus
Quoted 2 lines · Sakari Ailus

Lift the xshutdown (enable) GPIO 1 ms after enabling the regulators, as required by the sensor's power-up sequence.

...

drivers/media/i2c/ov7251.c static int ov7251_set_power_on(struct device *dev) · line 925

Quoted 1 line
drivers/media/i2c/ov7251.c +1 -0
+	usleep_range(1000, 1100);

Why not fsleep() ?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#4 lore raw

Re: [PATCH 2/2] media: i2c: ov7251: Introduce 1 ms delay between regulators and en GPIO

Hi Andy,

Quoted 9 lines · Andy Shevchenko
Quoted 2 lines · Sakari Ailus

Lift the xshutdown (enable) GPIO 1 ms after enabling the regulators, as required by the sensor's power-up sequence.

...

drivers/media/i2c/ov7251.c static int ov7251_set_power_on(struct device *dev) · line 925

Quoted 1 line
drivers/media/i2c/ov7251.c +1 -0
+	usleep_range(1000, 1100);

Why not fsleep() ?

Could be, but fsleep() uses a range that is as large as the delay is.

Signature · 1 line
Sakari Ailus
#5 lore raw

Re: [PATCH 2/2] media: i2c: ov7251: Introduce 1 ms delay between regulators and en GPIO

Quoted 4 lines · Sakari Ailus
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Sakari Ailus

Lift the xshutdown (enable) GPIO 1 ms after enabling the regulators, as required by the sensor's power-up sequence.

...

Quoted 5 lines
Quoted 3 lines

drivers/media/i2c/ov7251.c static int ov7251_set_power_on(struct device *dev) · line 925

Quoted 1 line
drivers/media/i2c/ov7251.c +1 -0
+	usleep_range(1000, 1100);

Why not fsleep() ?

Could be, but fsleep() uses a range that is as large as the delay is.

fsleep() is recommended way as it knows much better the implementation details of the delay APIs and which one to choose based on input. As recently stated by the fix series to delay APIs the fsleep() will give up to 25% on top of the asked delay, meaning in this case somewhat 250us. Taking it into account the resulting values I do not think usleep_range() should be here. I.o.w. I do not see enough justification for _not_ using fsleep().

Also note that fsleep() ranges try to keep balance between oversleep and power consumption. Your delay is rather tough as sometimes 100us is almost the time needed to go to the deep sleep for the CPU package and return from it.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#6 lore raw

Re: [PATCH 2/2] media: i2c: ov7251: Introduce 1 ms delay between regulators and en GPIO

Hi Andy,

Quoted 21 lines · Andy Shevchenko
Quoted 4 lines · Sakari Ailus
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Sakari Ailus

Lift the xshutdown (enable) GPIO 1 ms after enabling the regulators, as required by the sensor's power-up sequence.

...

Quoted 5 lines
Quoted 3 lines

drivers/media/i2c/ov7251.c static int ov7251_set_power_on(struct device *dev) · line 925

Quoted 1 line
drivers/media/i2c/ov7251.c +1 -0
+	usleep_range(1000, 1100);

Why not fsleep() ?

Could be, but fsleep() uses a range that is as large as the delay is.

fsleep() is recommended way as it knows much better the implementation details of the delay APIs and which one to choose based on input. As recently stated by the fix series to delay APIs the fsleep() will give up to 25% on top of the asked delay, meaning in this case somewhat 250us. Taking it into account the resulting values I do not think usleep_range() should be here. I.o.w. I do not see enough justification for _not_ using fsleep().

Quoted 3 lines

Also note that fsleep() ranges try to keep balance between oversleep and power consumption. Your delay is rather tough as sometimes 100us is almost the time needed to go to the deep sleep for the CPU package and return from it.

Have you looked at what fsleep() does? I agree most of the time it's the best choice when you need to sleep (at least) some time, but generally sensor power-up time is critical.

I'm fine using 1000 for both, too.

Signature · 3 lines
Regards,

Sakari Ailus
#7 lore raw

Re: [PATCH 2/2] media: i2c: ov7251: Introduce 1 ms delay between regulators and en GPIO

Quoted 6 lines · Sakari Ailus
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Sakari Ailus
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Sakari Ailus

Lift the xshutdown (enable) GPIO 1 ms after enabling the regulators, as required by the sensor's power-up sequence.

...

Quoted 13 lines
Quoted 13 lines
Quoted 5 lines
Quoted 3 lines

drivers/media/i2c/ov7251.c static int ov7251_set_power_on(struct device *dev) · line 925

Quoted 1 line
drivers/media/i2c/ov7251.c +1 -0
+	usleep_range(1000, 1100);

Why not fsleep() ?

Could be, but fsleep() uses a range that is as large as the delay is.

fsleep() is recommended way as it knows much better the implementation details of the delay APIs and which one to choose based on input. As recently stated by the fix series to delay APIs the fsleep() will give up to 25% on top of the asked delay, meaning in this case somewhat 250us. Taking it into account the resulting values I do not think usleep_range() should be here. I.o.w. I do not see enough justification for _not_ using fsleep().

Quoted 5 lines
Quoted 3 lines

Also note that fsleep() ranges try to keep balance between oversleep and power consumption. Your delay is rather tough as sometimes 100us is almost the time needed to go to the deep sleep for the CPU package and return from it.

Have you looked at what fsleep() does?

Definitely, and also read the (updated) documentation. So, let me repeat:
I do not see any justification for usleep_range() here and how 150us overhead (on top of what you proposed) makes any difference.

Quoted 2 lines

I agree most of the time it's the best choice when you need to sleep (at least) some time, but generally sensor power-up time is critical.

Why? I don't see this in the commit message. Please also answer the question "what is the bad thing happen if we delay slightly more?" and the question of how this will cope with the case when HRTIMER is off in the kernel.

Quoted 1 line

I'm fine using 1000 for both, too.

In accordance with the documentation one has to consider

fsleep(1000)
msleep(1)
usleep_range(1000, 1100)

(in this order), so I prefer that we use fsleep() if there is no good justification for the other one(s).

Also just noticed that in the commit message you even used "ms" units and not "us", which pretty much suggests that tough range for usleep_range() is not justified.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on v1 1/2
#8 lore raw
In reply to Sakari Ailus

Hi Sakari

Quoted 6 lines · Sakari Ailus

Set the enable GPIO low when acquiring it.

Fixes d30bb512da3d ("media: Add a driver for the ov7251 camera sensor")

Agreed that the datasheet says that as the regulators aren't on at this point, the enable GPIO must be low.

Quoted 23 lines
---
 drivers/media/i2c/ov7251.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ov7251.c +1 -1
index 30f61e04ecaf..f3e2d26bb840 100644
@@ -1696,7 +1696,7 @@ static int ov7251_probe(struct i2c_client *client)
                return PTR_ERR(ov7251->analog_regulator);
        }
 
-       ov7251->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH);
+       ov7251->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW);
        if (IS_ERR(ov7251->enable_gpio)) {
                dev_err(dev, "cannot get enable gpio\n");
                return PTR_ERR(ov7251->enable_gpio);

base-commit: 5de275c450c9496031006e0fb3f7c96a8fcaaa55 --
2.39.5

#9 lore raw
In reply to Sakari Ailus
Quoted 1 line · Sakari Ailus

Set the enable GPIO low when acquiring it.

...

drivers/media/i2c/ov7251.c static int ov7251_probe(struct i2c_client *client) · line 1699

Quoted 2 lines
drivers/media/i2c/ov7251.c +1 -1
-	ov7251->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH);
+	ov7251->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW);

Fine with me, but it's not helpful for MS Surface family of the devices anyway.

Signature · 2 lines
With Best Regards,
Andy Shevchenko