Skip to contentSkip to conversation

media: ov7251: Remap "reset" to "enable" for OV7251

PATCH In review Andy Shevchenko 4 participants 14 messages Nov 8, 2024 – Jan 20, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: ov7251: Remap "reset" to "enable" for OV7251

The driver of OmniVision OV7251 expects "enable" pin instead of "reset". Remap "reset" to "enable" and update polarity.

In particular, the Linux kernel can't load the camera sensor driver on Microsoft Surface Book without this change:

ov7251 i2c-INT347E:00: supply vdddo not found, using dummy regulator ov7251 i2c-INT347E:00: supply vddd not found, using dummy regulator ov7251 i2c-INT347E:00: supply vdda not found, using dummy regulator ov7251 i2c-INT347E:00: cannot get enable gpio
ov7251 i2c-INT347E:00: probe with driver ov7251 failed with error -2

---
 drivers/media/i2c/ov7251.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/media/i2c/ov7251.c +14 -0
index 30f61e04ecaf..7b35add1e0ed 100644
@@ -1696,7 +1696,21 @@ static int ov7251_probe(struct i2c_client *client)
 		return PTR_ERR(ov7251->analog_regulator);
 	}
 
+	/*
+	 * The device-tree bindings call this pin "enable", but the
+	 * datasheet describes the pin as "reset (active low with internal
+	 * pull down resistor)". The ACPI tables describing this sensor
+	 * on, e.g., the Microsoft Surface Book use the ACPI equivalent of
+	 * "reset" as pin name, which ACPI glue code then maps to "reset".
+	 * Check for a "reset" pin if there is no "enable" pin.
+	 */
 	ov7251->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH);
+	if (IS_ERR(ov7251->enable_gpio) &&
+	    PTR_ERR(ov7251->enable_gpio) != -EPROBE_DEFER) {
+		ov7251->enable_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
+		if (!IS_ERR(ov7251->enable_gpio))
+			gpiod_toggle_active_low(ov7251->enable_gpio);
+	}
 	if (IS_ERR(ov7251->enable_gpio)) {
 		dev_err(dev, "cannot get enable gpio\n");
 		return PTR_ERR(ov7251->enable_gpio);
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 6 lines · Andy Shevchenko

The driver of OmniVision OV7251 expects "enable" pin instead of "reset". Remap "reset" to "enable" and update polarity.

In particular, the Linux kernel can't load the camera sensor driver on Microsoft Surface Book without this change:

Quoted 8 lines

ov7251 i2c-INT347E:00: supply vdddo not found, using dummy regulator ov7251 i2c-INT347E:00: supply vddd not found, using dummy regulator ov7251 i2c-INT347E:00: supply vdda not found, using dummy regulator ov7251 i2c-INT347E:00: cannot get enable gpio
ov7251 i2c-INT347E:00: probe with driver ov7251 failed with error -2

Thanks, patch looks good to me:

Regards,

Hans

Quoted 30 lines
---
 drivers/media/i2c/ov7251.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/media/i2c/ov7251.c +14 -0
index 30f61e04ecaf..7b35add1e0ed 100644
@@ -1696,7 +1696,21 @@ static int ov7251_probe(struct i2c_client *client)
 		return PTR_ERR(ov7251->analog_regulator);
 	}
 
+	/*
+	 * The device-tree bindings call this pin "enable", but the
+	 * datasheet describes the pin as "reset (active low with internal
+	 * pull down resistor)". The ACPI tables describing this sensor
+	 * on, e.g., the Microsoft Surface Book use the ACPI equivalent of
+	 * "reset" as pin name, which ACPI glue code then maps to "reset".
+	 * Check for a "reset" pin if there is no "enable" pin.
+	 */
 	ov7251->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH);
+	if (IS_ERR(ov7251->enable_gpio) &&
+	    PTR_ERR(ov7251->enable_gpio) != -EPROBE_DEFER) {
+		ov7251->enable_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
+		if (!IS_ERR(ov7251->enable_gpio))
+			gpiod_toggle_active_low(ov7251->enable_gpio);
+	}
 	if (IS_ERR(ov7251->enable_gpio)) {
 		dev_err(dev, "cannot get enable gpio\n");
 		return PTR_ERR(ov7251->enable_gpio);
maintainer
#2 lore raw
In reply to Andy Shevchenko

Hi Andy,

Thanks for the patch.

Quoted 6 lines · Andy Shevchenko

The driver of OmniVision OV7251 expects "enable" pin instead of "reset". Remap "reset" to "enable" and update polarity.

In particular, the Linux kernel can't load the camera sensor driver on Microsoft Surface Book without this change:

Quoted 8 lines

ov7251 i2c-INT347E:00: supply vdddo not found, using dummy regulator ov7251 i2c-INT347E:00: supply vddd not found, using dummy regulator ov7251 i2c-INT347E:00: supply vdda not found, using dummy regulator ov7251 i2c-INT347E:00: cannot get enable gpio
ov7251 i2c-INT347E:00: probe with driver ov7251 failed with error -2

Should this be cc'd to stable? I guess it's not exactly a fix in the driver but a BIOS bug, but it can be worked around in the driver. :-)

Quoted 9 lines
---
 drivers/media/i2c/ov7251.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/media/i2c/ov7251.c +0 -0
index 30f61e04ecaf..7b35add1e0ed 100644

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

Quoted 7 lines
drivers/media/i2c/ov7251.c +4 -0
@@ -1696,7 +1696,21 @@ static int ov7251_probe(struct i2c_client *client)
 		return PTR_ERR(ov7251->analog_regulator);
 	}
 
+	/*
+	 * The device-tree bindings call this pin "enable", but the
+	 * datasheet describes the pin as "reset (active low with internal
+	 * pull down resistor)". The ACPI tables describing this sensor

It's the functionality that matters albeit I guess this is somewhat a matter of taste: a similar pin was named "reset" for MIPI CCS.

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

Quoted 8 lines
drivers/media/i2c/ov7251.c +7 -0
+	 * on, e.g., the Microsoft Surface Book use the ACPI equivalent of
+	 * "reset" as pin name, which ACPI glue code then maps to "reset".
+	 * Check for a "reset" pin if there is no "enable" pin.
+	 */
 	ov7251->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH);
+	if (IS_ERR(ov7251->enable_gpio) &&
+	    PTR_ERR(ov7251->enable_gpio) != -EPROBE_DEFER) {
+		ov7251->enable_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);

This looks like it'd benefit from a line wrap. I can do that if there's no need for v2 otherwise.

Quoted 6 lines
drivers/media/i2c/ov7251.c +3 -0
+		if (!IS_ERR(ov7251->enable_gpio))
+			gpiod_toggle_active_low(ov7251->enable_gpio);
+	}
 	if (IS_ERR(ov7251->enable_gpio)) {
 		dev_err(dev, "cannot get enable gpio\n");
 		return PTR_ERR(ov7251->enable_gpio);
Signature · 3 lines
Kind regards,

Sakari Ailus
#3 lore raw
Quoted 12 lines · Sakari Ailus
Quoted 11 lines · Andy Shevchenko

The driver of OmniVision OV7251 expects "enable" pin instead of "reset". Remap "reset" to "enable" and update polarity.

In particular, the Linux kernel can't load the camera sensor driver on Microsoft Surface Book without this change:

ov7251 i2c-INT347E:00: supply vdddo not found, using dummy regulator ov7251 i2c-INT347E:00: supply vddd not found, using dummy regulator ov7251 i2c-INT347E:00: supply vdda not found, using dummy regulator ov7251 i2c-INT347E:00: cannot get enable gpio
ov7251 i2c-INT347E:00: probe with driver ov7251 failed with error -2

...

Quoted 2 lines

Should this be cc'd to stable? I guess it's not exactly a fix in the driver but a BIOS bug, but it can be worked around in the driver. :-)

It's everything, but a BIOS bug, it's DT bug and whoever first introduced that GPIO in the driver. Even in the DT present in kernel the pin was referred as CAM_RST_N, which is exactly how this patch names it.

OTOH it's a fix to the driver that never worked for ACPI case, so there never was a regression to fix.

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

Hi Andy,

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

The driver of OmniVision OV7251 expects "enable" pin instead of "reset". Remap "reset" to "enable" and update polarity.

Quoted 8 lines
Quoted 8 lines

In particular, the Linux kernel can't load the camera sensor driver on Microsoft Surface Book without this change:

ov7251 i2c-INT347E:00: supply vdddo not found, using dummy regulator ov7251 i2c-INT347E:00: supply vddd not found, using dummy regulator ov7251 i2c-INT347E:00: supply vdda not found, using dummy regulator ov7251 i2c-INT347E:00: cannot get enable gpio
ov7251 i2c-INT347E:00: probe with driver ov7251 failed with error -2

Quoted 7 lines

...

Quoted 2 lines

Should this be cc'd to stable? I guess it's not exactly a fix in the driver but a BIOS bug, but it can be worked around in the driver. :-)

It's everything, but a BIOS bug, it's DT bug and whoever first introduced that GPIO in the driver. Even in the DT present in kernel the pin was referred as

How is that a DT (binding?) bug?

Quoted 4 lines

CAM_RST_N, which is exactly how this patch names it.

OTOH it's a fix to the driver that never worked for ACPI case, so there never was a regression to fix.

It probably worked just fine, just not with that Surface Book.

The polarity of the enable gpio appears to be set wrong in devm_gpiod_get() call. I can post a patch but cannot test it.

Similarly, you should actually set the flags to GPIOD_OUT_HIGH as reset should be enabled here -- it's disabled only in power_on() as part of the power-on sequence.

Signature · 3 lines
Regards,

Sakari Ailus
#5 lore raw

Hi,

Quoted 19 lines · Sakari Ailus

Hi Andy,

Quoted 16 lines · Andy Shevchenko
Quoted 12 lines · Sakari Ailus
Quoted 11 lines · Andy Shevchenko

The driver of OmniVision OV7251 expects "enable" pin instead of "reset". Remap "reset" to "enable" and update polarity.

In particular, the Linux kernel can't load the camera sensor driver on Microsoft Surface Book without this change:

ov7251 i2c-INT347E:00: supply vdddo not found, using dummy regulator ov7251 i2c-INT347E:00: supply vddd not found, using dummy regulator ov7251 i2c-INT347E:00: supply vdda not found, using dummy regulator ov7251 i2c-INT347E:00: cannot get enable gpio
ov7251 i2c-INT347E:00: probe with driver ov7251 failed with error -2

...

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Should this be cc'd to stable? I guess it's not exactly a fix in the driver but a BIOS bug, but it can be worked around in the driver. :-)

It's everything, but a BIOS bug, it's DT bug and whoever first introduced that GPIO in the driver. Even in the DT present in kernel the pin was referred as

How is that a DT (binding?) bug?

Since it is not following the datasheet name for the pin, it arguably is a DT binding bug

But whatever, the whole discussion about if it is a bug and whose bug it is is not useful. Since we cannot go back in time and change the DT binding DT and ACPI are simply going to disagree on the name and we will need something like this patch.

Quoted 9 lines
Quoted 4 lines

CAM_RST_N, which is exactly how this patch names it.

OTOH it's a fix to the driver that never worked for ACPI case, so there never was a regression to fix.

It probably worked just fine, just not with that Surface Book.

The polarity of the enable gpio appears to be set wrong in devm_gpiod_get() call. I can post a patch but cannot test it.

That is on purpose, at least the polarity if the devm_gpiod_get(..., "reset", ...) is inverted from the existing one for "enable" because reset needs to be inactive/disabled to enable the sensor.

Quoted 3 lines

Similarly, you should actually set the flags to GPIOD_OUT_HIGH as reset should be enabled here -- it's disabled only in power_on() as part of the power-on sequence.

This seems to be a pre-existing bug in this driver, which currently starts driving enable high, enabling the sensor at gpiod_get() time.

Note that fixing this is tricky-ish, if the pin was already high at gpiod_get() time then changing the gpiod_get() to drive it low will result in it only being driven low for a very short time since ov7251_set_power_on() will get called almost immediately after this and it will drive the pin high again without any delays.

So if the pin was already high then making it low at gpiod_get() time will result in a very short spike to low, immediately followed by the pin going high again. This short spike may very well leave the sensor in a confused state rather then properly resetting it...

OTOH if the pin was already high with the old code where gpiod_get("enable") requests the pin as high (so it is left high), then the existing state of the sensor is simply preserved (no reset) which should be fine for the initial probe which just checks the id register.

And if the pin was low then it is driven high once and kept high, so again no glitch / spike. So arguably the old code is fine.

If this is changed then a delay needs to be added to ensure that the pin is guaranteed to be driven low for some minimum amount of time.

Regards,

Hans

maintainer
#6 lore raw

Hi Hans,

Quoted 56 lines · Hans de Goede

Hi,

Quoted 19 lines · Sakari Ailus

Hi Andy,

Quoted 16 lines · Andy Shevchenko
Quoted 12 lines · Sakari Ailus
Quoted 11 lines · Andy Shevchenko

The driver of OmniVision OV7251 expects "enable" pin instead of "reset". Remap "reset" to "enable" and update polarity.

In particular, the Linux kernel can't load the camera sensor driver on Microsoft Surface Book without this change:

ov7251 i2c-INT347E:00: supply vdddo not found, using dummy regulator ov7251 i2c-INT347E:00: supply vddd not found, using dummy regulator ov7251 i2c-INT347E:00: supply vdda not found, using dummy regulator ov7251 i2c-INT347E:00: cannot get enable gpio
ov7251 i2c-INT347E:00: probe with driver ov7251 failed with error -2

...

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Should this be cc'd to stable? I guess it's not exactly a fix in the driver but a BIOS bug, but it can be worked around in the driver. :-)

It's everything, but a BIOS bug, it's DT bug and whoever first introduced that GPIO in the driver. Even in the DT present in kernel the pin was referred as

How is that a DT (binding?) bug?

Since it is not following the datasheet name for the pin, it arguably is a DT binding bug

But whatever, the whole discussion about if it is a bug and whose bug it is is not useful. Since we cannot go back in time and change the DT binding DT and ACPI are simply going to disagree on the name and we will need something like this patch.

Quoted 9 lines
Quoted 4 lines

CAM_RST_N, which is exactly how this patch names it.

OTOH it's a fix to the driver that never worked for ACPI case, so there never was a regression to fix.

It probably worked just fine, just not with that Surface Book.

The polarity of the enable gpio appears to be set wrong in devm_gpiod_get() call. I can post a patch but cannot test it.

That is on purpose, at least the polarity if the devm_gpiod_get(..., "reset", ...) is inverted from the existing one for "enable" because reset needs to be inactive/disabled to enable the sensor.

Quoted 3 lines

Similarly, you should actually set the flags to GPIOD_OUT_HIGH as reset should be enabled here -- it's disabled only in power_on() as part of the power-on sequence.

Quoted 8 lines

This seems to be a pre-existing bug in this driver, which currently starts driving enable high, enabling the sensor at gpiod_get() time.

Note that fixing this is tricky-ish, if the pin was already high at gpiod_get() time then changing the gpiod_get() to drive it low will result in it only being driven low for a very short time since ov7251_set_power_on() will get called almost immediately after this and it will drive the pin high again without any delays.

The question here is not about how long the hard reset is applied, but whether or not the sensor's power-on sequence is followed. Currently it is not.

Quoted 6 lines

So if the pin was already high then making it low at gpiod_get() time will result in a very short spike to low, immediately followed by the pin going high again. This short spike may very well leave the sensor in a confused state rather then properly resetting it...

Quoted 8 lines

OTOH if the pin was already high with the old code where gpiod_get("enable") requests the pin as high (so it is left high), then the existing state of the sensor is simply preserved (no reset) which should be fine for the initial probe which just checks the id register.

And if the pin was low then it is driven high once and kept high, so again no glitch / spike. So arguably the old code is fine.

I'm not sure how do you reach that conclusion. Because it happens to work, presumably at least somewhere? The code appears to be part of the

Quoted 4 lines

If this is changed then a delay needs to be added to ensure that the pin is guaranteed to be driven low for some minimum amount of time.

Signature · 3 lines
Regards,

Sakari Ailus
#7 lore raw

Hi,

Quoted 68 lines · Sakari Ailus

Hi Hans,

Quoted 56 lines · Hans de Goede

Hi,

Quoted 19 lines · Sakari Ailus

Hi Andy,

Quoted 16 lines · Andy Shevchenko
Quoted 12 lines · Sakari Ailus
Quoted 11 lines · Andy Shevchenko

The driver of OmniVision OV7251 expects "enable" pin instead of "reset". Remap "reset" to "enable" and update polarity.

In particular, the Linux kernel can't load the camera sensor driver on Microsoft Surface Book without this change:

ov7251 i2c-INT347E:00: supply vdddo not found, using dummy regulator ov7251 i2c-INT347E:00: supply vddd not found, using dummy regulator ov7251 i2c-INT347E:00: supply vdda not found, using dummy regulator ov7251 i2c-INT347E:00: cannot get enable gpio
ov7251 i2c-INT347E:00: probe with driver ov7251 failed with error -2

...

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Should this be cc'd to stable? I guess it's not exactly a fix in the driver but a BIOS bug, but it can be worked around in the driver. :-)

It's everything, but a BIOS bug, it's DT bug and whoever first introduced that GPIO in the driver. Even in the DT present in kernel the pin was referred as

How is that a DT (binding?) bug?

Since it is not following the datasheet name for the pin, it arguably is a DT binding bug

But whatever, the whole discussion about if it is a bug and whose bug it is is not useful. Since we cannot go back in time and change the DT binding DT and ACPI are simply going to disagree on the name and we will need something like this patch.

Quoted 9 lines
Quoted 4 lines

CAM_RST_N, which is exactly how this patch names it.

OTOH it's a fix to the driver that never worked for ACPI case, so there never was a regression to fix.

It probably worked just fine, just not with that Surface Book.

The polarity of the enable gpio appears to be set wrong in devm_gpiod_get() call. I can post a patch but cannot test it.

That is on purpose, at least the polarity if the devm_gpiod_get(..., "reset", ...) is inverted from the existing one for "enable" because reset needs to be inactive/disabled to enable the sensor.

Quoted 3 lines

Similarly, you should actually set the flags to GPIOD_OUT_HIGH as reset should be enabled here -- it's disabled only in power_on() as part of the power-on sequence.

Quoted 8 lines

This seems to be a pre-existing bug in this driver, which currently starts driving enable high, enabling the sensor at gpiod_get() time.

Note that fixing this is tricky-ish, if the pin was already high at gpiod_get() time then changing the gpiod_get() to drive it low will result in it only being driven low for a very short time since ov7251_set_power_on() will get called almost immediately after this and it will drive the pin high again without any delays.

Quoted 3 lines

The question here is not about how long the hard reset is applied, but whether or not the sensor's power-on sequence is followed. Currently it is not.

Right / agreed. The 2 points which I am trying to make are:

1. This is a pre-existing problem unrelated to this patch.

So this should be fixed in a separate patch.

2. That separate patch should put a delay after requesting the GPIO to enforce that it is (logically) low (for "enable") for a minimum amount of time.

Regards,

Hans

#8 lore raw
Quoted 17 lines · Hans de Goede
Quoted 16 lines · Sakari Ailus
Quoted 15 lines · Hans de Goede
Quoted 14 lines · Sakari Ailus
Quoted 13 lines · Andy Shevchenko
Quoted 12 lines · Sakari Ailus
Quoted 11 lines · Andy Shevchenko

The driver of OmniVision OV7251 expects "enable" pin instead of "reset". Remap "reset" to "enable" and update polarity.

In particular, the Linux kernel can't load the camera sensor driver on Microsoft Surface Book without this change:

ov7251 i2c-INT347E:00: supply vdddo not found, using dummy regulator ov7251 i2c-INT347E:00: supply vddd not found, using dummy regulator ov7251 i2c-INT347E:00: supply vdda not found, using dummy regulator ov7251 i2c-INT347E:00: cannot get enable gpio
ov7251 i2c-INT347E:00: probe with driver ov7251 failed with error -2

...

Quoted 49 lines
Quoted 43 lines
Quoted 34 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Should this be cc'd to stable? I guess it's not exactly a fix in the driver but a BIOS bug, but it can be worked around in the driver. :-)

It's everything, but a BIOS bug, it's DT bug and whoever first introduced that GPIO in the driver. Even in the DT present in kernel the pin was referred as

How is that a DT (binding?) bug?

Since it is not following the datasheet name for the pin, it arguably is a DT binding bug

But whatever, the whole discussion about if it is a bug and whose bug it is is not useful. Since we cannot go back in time and change the DT binding DT and ACPI are simply going to disagree on the name and we will need something like this patch.

Quoted 9 lines
Quoted 4 lines

CAM_RST_N, which is exactly how this patch names it.

OTOH it's a fix to the driver that never worked for ACPI case, so there never was a regression to fix.

It probably worked just fine, just not with that Surface Book.

The polarity of the enable gpio appears to be set wrong in devm_gpiod_get() call. I can post a patch but cannot test it.

That is on purpose, at least the polarity if the devm_gpiod_get(..., "reset", ...) is inverted from the existing one for "enable" because reset needs to be inactive/disabled to enable the sensor.

Quoted 3 lines

Similarly, you should actually set the flags to GPIOD_OUT_HIGH as reset should be enabled here -- it's disabled only in power_on() as part of the power-on sequence.

Quoted 8 lines

This seems to be a pre-existing bug in this driver, which currently starts driving enable high, enabling the sensor at gpiod_get() time.

Note that fixing this is tricky-ish, if the pin was already high at gpiod_get() time then changing the gpiod_get() to drive it low will result in it only being driven low for a very short time since ov7251_set_power_on() will get called almost immediately after this and it will drive the pin high again without any delays.

Quoted 3 lines

The question here is not about how long the hard reset is applied, but whether or not the sensor's power-on sequence is followed. Currently it is not.

Right / agreed. The 2 points which I am trying to make are:

Quoted 7 lines

1. This is a pre-existing problem unrelated to this patch.

So this should be fixed in a separate patch.

2. That separate patch should put a delay after requesting the GPIO to enforce that it is (logically) low (for "enable") for a minimum amount of time.

Sakari, what's the status on this, please?
We have non-working camera just because of this small patch is absent.

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

Hi Andy,

Quoted 72 lines · Andy Shevchenko
Quoted 17 lines · Hans de Goede
Quoted 16 lines · Sakari Ailus
Quoted 15 lines · Hans de Goede
Quoted 14 lines · Sakari Ailus
Quoted 13 lines · Andy Shevchenko
Quoted 12 lines · Sakari Ailus
Quoted 11 lines · Andy Shevchenko

The driver of OmniVision OV7251 expects "enable" pin instead of "reset". Remap "reset" to "enable" and update polarity.

In particular, the Linux kernel can't load the camera sensor driver on Microsoft Surface Book without this change:

ov7251 i2c-INT347E:00: supply vdddo not found, using dummy regulator ov7251 i2c-INT347E:00: supply vddd not found, using dummy regulator ov7251 i2c-INT347E:00: supply vdda not found, using dummy regulator ov7251 i2c-INT347E:00: cannot get enable gpio
ov7251 i2c-INT347E:00: probe with driver ov7251 failed with error -2

...

Quoted 51 lines
Quoted 43 lines
Quoted 34 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Should this be cc'd to stable? I guess it's not exactly a fix in the driver but a BIOS bug, but it can be worked around in the driver. :-)

It's everything, but a BIOS bug, it's DT bug and whoever first introduced that GPIO in the driver. Even in the DT present in kernel the pin was referred as

How is that a DT (binding?) bug?

Since it is not following the datasheet name for the pin, it arguably is a DT binding bug

But whatever, the whole discussion about if it is a bug and whose bug it is is not useful. Since we cannot go back in time and change the DT binding DT and ACPI are simply going to disagree on the name and we will need something like this patch.

Quoted 9 lines
Quoted 4 lines

CAM_RST_N, which is exactly how this patch names it.

OTOH it's a fix to the driver that never worked for ACPI case, so there never was a regression to fix.

It probably worked just fine, just not with that Surface Book.

The polarity of the enable gpio appears to be set wrong in devm_gpiod_get() call. I can post a patch but cannot test it.

That is on purpose, at least the polarity if the devm_gpiod_get(..., "reset", ...) is inverted from the existing one for "enable" because reset needs to be inactive/disabled to enable the sensor.

Quoted 3 lines

Similarly, you should actually set the flags to GPIOD_OUT_HIGH as reset should be enabled here -- it's disabled only in power_on() as part of the power-on sequence.

Quoted 8 lines

This seems to be a pre-existing bug in this driver, which currently starts driving enable high, enabling the sensor at gpiod_get() time.

Note that fixing this is tricky-ish, if the pin was already high at gpiod_get() time then changing the gpiod_get() to drive it low will result in it only being driven low for a very short time since ov7251_set_power_on() will get called almost immediately after this and it will drive the pin high again without any delays.

Quoted 3 lines

The question here is not about how long the hard reset is applied, but whether or not the sensor's power-on sequence is followed. Currently it is not.

Right / agreed. The 2 points which I am trying to make are:

1. This is a pre-existing problem unrelated to this patch.

Quoted 8 lines
Quoted 5 lines

So this should be fixed in a separate patch.

2. That separate patch should put a delay after requesting the GPIO to enforce that it is (logically) low (for "enable") for a minimum amount of time.

Sakari, what's the status on this, please?
We have non-working camera just because of this small patch is absent.

Thanks for the ping.

I took a closer look at the problem, indeed the GPIO name comes from the int3472 driver and it's much better to work around this there than to ram Windows ACPI table specifics to sensor drivers. I'll post a patch for that shortly. Testing would be appreciated as the Surface Go 2 doesn't have a GPIO connected to this sensor.

Maybe backporting would be reasonable even though this isn't a fix as such?

Signature · 3 lines
Regards,

Sakari Ailus
#10 lore raw

+Cc [email protected]

Hi Sakari,

Quoted 84 lines · Sakari Ailus

Hi Andy,

Quoted 72 lines · Andy Shevchenko
Quoted 17 lines · Hans de Goede
Quoted 16 lines · Sakari Ailus
Quoted 15 lines · Hans de Goede
Quoted 14 lines · Sakari Ailus
Quoted 13 lines · Andy Shevchenko
Quoted 12 lines · Sakari Ailus
Quoted 11 lines · Andy Shevchenko

The driver of OmniVision OV7251 expects "enable" pin instead of "reset". Remap "reset" to "enable" and update polarity.

In particular, the Linux kernel can't load the camera sensor driver on Microsoft Surface Book without this change:

ov7251 i2c-INT347E:00: supply vdddo not found, using dummy regulator ov7251 i2c-INT347E:00: supply vddd not found, using dummy regulator ov7251 i2c-INT347E:00: supply vdda not found, using dummy regulator ov7251 i2c-INT347E:00: cannot get enable gpio
ov7251 i2c-INT347E:00: probe with driver ov7251 failed with error -2

...

Quoted 51 lines
Quoted 43 lines
Quoted 34 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Should this be cc'd to stable? I guess it's not exactly a fix in the driver but a BIOS bug, but it can be worked around in the driver. :-)

It's everything, but a BIOS bug, it's DT bug and whoever first introduced that GPIO in the driver. Even in the DT present in kernel the pin was referred as

How is that a DT (binding?) bug?

Since it is not following the datasheet name for the pin, it arguably is a DT binding bug

But whatever, the whole discussion about if it is a bug and whose bug it is is not useful. Since we cannot go back in time and change the DT binding DT and ACPI are simply going to disagree on the name and we will need something like this patch.

Quoted 9 lines
Quoted 4 lines

CAM_RST_N, which is exactly how this patch names it.

OTOH it's a fix to the driver that never worked for ACPI case, so there never was a regression to fix.

It probably worked just fine, just not with that Surface Book.

The polarity of the enable gpio appears to be set wrong in devm_gpiod_get() call. I can post a patch but cannot test it.

That is on purpose, at least the polarity if the devm_gpiod_get(..., "reset", ...) is inverted from the existing one for "enable" because reset needs to be inactive/disabled to enable the sensor.

Quoted 3 lines

Similarly, you should actually set the flags to GPIOD_OUT_HIGH as reset should be enabled here -- it's disabled only in power_on() as part of the power-on sequence.

Quoted 8 lines

This seems to be a pre-existing bug in this driver, which currently starts driving enable high, enabling the sensor at gpiod_get() time.

Note that fixing this is tricky-ish, if the pin was already high at gpiod_get() time then changing the gpiod_get() to drive it low will result in it only being driven low for a very short time since ov7251_set_power_on() will get called almost immediately after this and it will drive the pin high again without any delays.

Quoted 3 lines

The question here is not about how long the hard reset is applied, but whether or not the sensor's power-on sequence is followed. Currently it is not.

Right / agreed. The 2 points which I am trying to make are:

1. This is a pre-existing problem unrelated to this patch.

Quoted 8 lines
Quoted 5 lines

So this should be fixed in a separate patch.

2. That separate patch should put a delay after requesting the GPIO to enforce that it is (logically) low (for "enable") for a minimum amount of time.

Sakari, what's the status on this, please?
We have non-working camera just because of this small patch is absent.

Quoted 7 lines

Thanks for the ping.

I took a closer look at the problem, indeed the GPIO name comes from the int3472 driver and it's much better to work around this there than to ram Windows ACPI table specifics to sensor drivers. I'll post a patch for that shortly. Testing would be appreciated as the Surface Go 2 doesn't have a GPIO connected to this sensor.

Actually Andy wrote this patch after first writing a similar quirk patch as yours from:

https://lore.kernel.org/platform-driver-x86/[email protected]/T/#t

because I asked him to fix this in the sensor driver instead.

The problem is that we cannot fix this in the INT3472 driver without that becoming one big mess of driver specific quirks.

The Windows code seems to have separate power-ctrl/sequence drivers for the INT3472 device vs the rest of the sensor driver and this power-sequence driver happily consumes whatever GPIOs the INT3472 device provides independent of the sensor.

So e.g. on some designs we are going to see a reset pin and on others a powerdown pin.

But in this specific case things are actually more simple, the datasheet describes the pin as:

XSHUTDOWN input reset (active low with internal pull down resistor)

So the devicetree binding calling it "enable" is just wrong and in this case it is actually the DT binding which is buggy (there is no "enable" pin anywhere in the datasheet) and not the ACPI tables.

Also since you match on the sensor-type for the remapping this clearly is a per sensor thing and per sensor handling should be in the sensor drivers, which gives us the per sensor mapping for free.

Yes needing to handle this in the sensor driver makes the sensor driver slightly less pretty. But dealing with platform specifics in drivers is done all over the kernel and I don't see why camera sensor drivers are so special that they get to be excluded from sometimes needing to deal with platform specifics.

Regards,

Hans

#11 lore raw
Quoted 115 lines · Hans de Goede

+Cc [email protected]

Hi Sakari,

Quoted 84 lines · Sakari Ailus

Hi Andy,

Quoted 72 lines · Andy Shevchenko
Quoted 17 lines · Hans de Goede
Quoted 16 lines · Sakari Ailus
Quoted 15 lines · Hans de Goede
Quoted 14 lines · Sakari Ailus
Quoted 13 lines · Andy Shevchenko
Quoted 12 lines · Sakari Ailus
Quoted 11 lines · Andy Shevchenko

The driver of OmniVision OV7251 expects "enable" pin instead of "reset". Remap "reset" to "enable" and update polarity.

In particular, the Linux kernel can't load the camera sensor driver on Microsoft Surface Book without this change:

ov7251 i2c-INT347E:00: supply vdddo not found, using dummy regulator ov7251 i2c-INT347E:00: supply vddd not found, using dummy regulator ov7251 i2c-INT347E:00: supply vdda not found, using dummy regulator ov7251 i2c-INT347E:00: cannot get enable gpio
ov7251 i2c-INT347E:00: probe with driver ov7251 failed with error -2

...

Quoted 51 lines
Quoted 43 lines
Quoted 34 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Should this be cc'd to stable? I guess it's not exactly a fix in the driver but a BIOS bug, but it can be worked around in the driver. :-)

It's everything, but a BIOS bug, it's DT bug and whoever first introduced that GPIO in the driver. Even in the DT present in kernel the pin was referred as

How is that a DT (binding?) bug?

Since it is not following the datasheet name for the pin, it arguably is a DT binding bug

But whatever, the whole discussion about if it is a bug and whose bug it is is not useful. Since we cannot go back in time and change the DT binding DT and ACPI are simply going to disagree on the name and we will need something like this patch.

Quoted 9 lines
Quoted 4 lines

CAM_RST_N, which is exactly how this patch names it.

OTOH it's a fix to the driver that never worked for ACPI case, so there never was a regression to fix.

It probably worked just fine, just not with that Surface Book.

The polarity of the enable gpio appears to be set wrong in devm_gpiod_get() call. I can post a patch but cannot test it.

That is on purpose, at least the polarity if the devm_gpiod_get(..., "reset", ...) is inverted from the existing one for "enable" because reset needs to be inactive/disabled to enable the sensor.

Quoted 3 lines

Similarly, you should actually set the flags to GPIOD_OUT_HIGH as reset should be enabled here -- it's disabled only in power_on() as part of the power-on sequence.

Quoted 8 lines

This seems to be a pre-existing bug in this driver, which currently starts driving enable high, enabling the sensor at gpiod_get() time.

Note that fixing this is tricky-ish, if the pin was already high at gpiod_get() time then changing the gpiod_get() to drive it low will result in it only being driven low for a very short time since ov7251_set_power_on() will get called almost immediately after this and it will drive the pin high again without any delays.

Quoted 3 lines

The question here is not about how long the hard reset is applied, but whether or not the sensor's power-on sequence is followed. Currently it is not.

Right / agreed. The 2 points which I am trying to make are:

1. This is a pre-existing problem unrelated to this patch.

Quoted 8 lines
Quoted 5 lines

So this should be fixed in a separate patch.

2. That separate patch should put a delay after requesting the GPIO to enforce that it is (logically) low (for "enable") for a minimum amount of time.

Sakari, what's the status on this, please?
We have non-working camera just because of this small patch is absent.

Quoted 7 lines

Thanks for the ping.

I took a closer look at the problem, indeed the GPIO name comes from the int3472 driver and it's much better to work around this there than to ram Windows ACPI table specifics to sensor drivers. I'll post a patch for that shortly. Testing would be appreciated as the Surface Go 2 doesn't have a GPIO connected to this sensor.

Actually Andy wrote this patch after first writing a similar quirk patch as yours from:

https://lore.kernel.org/platform-driver-x86/[email protected]/T/#t

because I asked him to fix this in the sensor driver instead.

The problem is that we cannot fix this in the INT3472 driver without that becoming one big mess of driver specific quirks.

The Windows code seems to have separate power-ctrl/sequence drivers for the INT3472 device vs the rest of the sensor driver and this power-sequence driver happily consumes whatever GPIOs the INT3472 device provides independent of the sensor.

So e.g. on some designs we are going to see a reset pin and on others a powerdown pin.

Quoted 8 lines

But in this specific case things are actually more simple, the datasheet describes the pin as:

XSHUTDOWN input reset (active low with internal pull down resistor)

So the devicetree binding calling it "enable" is just wrong and in this case it is actually the DT binding which is buggy (there is no "enable" pin anywhere in the datasheet) and not the ACPI tables.

There has never been a requirement for the GPIO in DT to match the pin name from the datasheet. It's actually quite the contrary, DT maintainers request GPIO names to be standardized. Using "xshutdown-gpios" wouldn't be appreciated, instead DT bindings are encouraged to use standard names such as "reset", "enable" and "powerdown". As the pin is called "XSHUTDOWN", "enable" is not necessarily a bad match. "reset" could have been picked too, but that wasn't the case and we can't change that.

The core of the issue here is that we have two firmware representations, DT and ACPI, and no coordination between the two. I don't expect that to change, and until Windows OEMs collaborate to standardize ACPI bindings, I'll consider this as a Windows-specific hack that I don't want to see being pushed to indidividual sensor drivers. This would be better handled in my opinion in the INT3472 driver.

Quoted 9 lines

Also since you match on the sensor-type for the remapping this clearly is a per sensor thing and per sensor handling should be in the sensor drivers, which gives us the per sensor mapping for free.

Yes needing to handle this in the sensor driver makes the sensor driver slightly less pretty. But dealing with platform specifics in drivers is done all over the kernel and I don't see why camera sensor drivers are so special that they get to be excluded from sometimes needing to deal with platform specifics.

The whole point of having standardized firmware descriptions is to avoid board-specific code in drivers. INT3472 is meant to handle board specificities.

Signature · 3 lines
Regards,

Laurent Pinchart
#12 lore raw

Hi Laurent,

Quoted 151 lines · Laurent Pinchart
Quoted 115 lines · Hans de Goede

+Cc [email protected]

Hi Sakari,

Quoted 84 lines · Sakari Ailus

Hi Andy,

Quoted 72 lines · Andy Shevchenko
Quoted 17 lines · Hans de Goede
Quoted 16 lines · Sakari Ailus
Quoted 15 lines · Hans de Goede
Quoted 14 lines · Sakari Ailus
Quoted 13 lines · Andy Shevchenko
Quoted 12 lines · Sakari Ailus
Quoted 11 lines · Andy Shevchenko

The driver of OmniVision OV7251 expects "enable" pin instead of "reset". Remap "reset" to "enable" and update polarity.

In particular, the Linux kernel can't load the camera sensor driver on Microsoft Surface Book without this change:

ov7251 i2c-INT347E:00: supply vdddo not found, using dummy regulator ov7251 i2c-INT347E:00: supply vddd not found, using dummy regulator ov7251 i2c-INT347E:00: supply vdda not found, using dummy regulator ov7251 i2c-INT347E:00: cannot get enable gpio
ov7251 i2c-INT347E:00: probe with driver ov7251 failed with error -2

...

Quoted 51 lines
Quoted 43 lines
Quoted 34 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Should this be cc'd to stable? I guess it's not exactly a fix in the driver but a BIOS bug, but it can be worked around in the driver. :-)

It's everything, but a BIOS bug, it's DT bug and whoever first introduced that GPIO in the driver. Even in the DT present in kernel the pin was referred as

How is that a DT (binding?) bug?

Since it is not following the datasheet name for the pin, it arguably is a DT binding bug

But whatever, the whole discussion about if it is a bug and whose bug it is is not useful. Since we cannot go back in time and change the DT binding DT and ACPI are simply going to disagree on the name and we will need something like this patch.

Quoted 9 lines
Quoted 4 lines

CAM_RST_N, which is exactly how this patch names it.

OTOH it's a fix to the driver that never worked for ACPI case, so there never was a regression to fix.

It probably worked just fine, just not with that Surface Book.

The polarity of the enable gpio appears to be set wrong in devm_gpiod_get() call. I can post a patch but cannot test it.

That is on purpose, at least the polarity if the devm_gpiod_get(..., "reset", ...) is inverted from the existing one for "enable" because reset needs to be inactive/disabled to enable the sensor.

Quoted 3 lines

Similarly, you should actually set the flags to GPIOD_OUT_HIGH as reset should be enabled here -- it's disabled only in power_on() as part of the power-on sequence.

Quoted 8 lines

This seems to be a pre-existing bug in this driver, which currently starts driving enable high, enabling the sensor at gpiod_get() time.

Note that fixing this is tricky-ish, if the pin was already high at gpiod_get() time then changing the gpiod_get() to drive it low will result in it only being driven low for a very short time since ov7251_set_power_on() will get called almost immediately after this and it will drive the pin high again without any delays.

Quoted 3 lines

The question here is not about how long the hard reset is applied, but whether or not the sensor's power-on sequence is followed. Currently it is not.

Right / agreed. The 2 points which I am trying to make are:

1. This is a pre-existing problem unrelated to this patch.

Quoted 8 lines
Quoted 5 lines

So this should be fixed in a separate patch.

2. That separate patch should put a delay after requesting the GPIO to enforce that it is (logically) low (for "enable") for a minimum amount of time.

Sakari, what's the status on this, please?
We have non-working camera just because of this small patch is absent.

Quoted 7 lines

Thanks for the ping.

I took a closer look at the problem, indeed the GPIO name comes from the int3472 driver and it's much better to work around this there than to ram Windows ACPI table specifics to sensor drivers. I'll post a patch for that shortly. Testing would be appreciated as the Surface Go 2 doesn't have a GPIO connected to this sensor.

Actually Andy wrote this patch after first writing a similar quirk patch as yours from:

https://lore.kernel.org/platform-driver-x86/[email protected]/T/#t

because I asked him to fix this in the sensor driver instead.

The problem is that we cannot fix this in the INT3472 driver without that becoming one big mess of driver specific quirks.

The Windows code seems to have separate power-ctrl/sequence drivers for the INT3472 device vs the rest of the sensor driver and this power-sequence driver happily consumes whatever GPIOs the INT3472 device provides independent of the sensor.

So e.g. on some designs we are going to see a reset pin and on others a powerdown pin.

Quoted 8 lines

But in this specific case things are actually more simple, the datasheet describes the pin as:

XSHUTDOWN input reset (active low with internal pull down resistor)

So the devicetree binding calling it "enable" is just wrong and in this case it is actually the DT binding which is buggy (there is no "enable" pin anywhere in the datasheet) and not the ACPI tables.

There has never been a requirement for the GPIO in DT to match the pin name from the datasheet. It's actually quite the contrary, DT maintainers request GPIO names to be standardized. Using "xshutdown-gpios" wouldn't be appreciated, instead DT bindings are encouraged to use standard names such as "reset", "enable" and "powerdown". As the pin is called "XSHUTDOWN", "enable" is not necessarily a bad match. "reset" could have been picked too, but that wasn't the case and we can't change that.

The core of the issue here is that we have two firmware representations, DT and ACPI, and no coordination between the two. I don't expect that to change, and until Windows OEMs collaborate to standardize ACPI bindings, I'll consider this as a Windows-specific hack that I don't want to see being pushed to indidividual sensor drivers. This would be better handled in my opinion in the INT3472 driver.

Quoted 9 lines

Also since you match on the sensor-type for the remapping this clearly is a per sensor thing and per sensor handling should be in the sensor drivers, which gives us the per sensor mapping for free.

Yes needing to handle this in the sensor driver makes the sensor driver slightly less pretty. But dealing with platform specifics in drivers is done all over the kernel and I don't see why camera sensor drivers are so special that they get to be excluded from sometimes needing to deal with platform specifics.

Quoted 3 lines

The whole point of having standardized firmware descriptions is to avoid board-specific code in drivers. INT3472 is meant to handle board specificities.

The problem is that some issues are relatively easy to fix in a generic manner in the driver's while they are quite hard to fix, requiring per board/laptop-model enablement using DMI quirks in the platform glue code.

A good example of this is this case from further down the thread:

On atomisp tablets there typically is a standard camera connector with both reset and powerdown signals and the atomisp _DSM equivalent of the INT3472 GPIO map _DSM typically contains both signals. But on sensors with only 1 reset pin it is unclear which of the 2 is actually used. One model camera module with sensor X may connect the sensor's single pin to the powerdown signal on the standard camera connector, while another camera module may use the reset signal on the standard connector.

There are 2 ways to handle this:

1. Make the driver deal with the fact that there may be 2 GPIOs, treating both as optional and driving both low/high at the same time since only 1 will actually be used. This is somewhat ugly on the driver side, but then fixes things for all tablets/laptops out there using this sensor model.

2. Make this the platform glue's problem and require the platform code to have per laptop/tablet model quirks using DMI matching meaning that instead of things just working OOTB for models not added to the quirk table, we now need users to report an issue and then manually fix that for every model under the sun. Which is very much sub optimal.

See e.g.:

https://github.com/jwrdegoede/linux-sunxi/commit/e43be8f19b5913a2e4bd715e7eef88fd909a2d1d

(which I have not posted upstream yet since I don't have the mt9m114 driver working on atomisp models yet)

Dealing with this specific case at the glue code level requires per laptop-model knowledge to map the right one of the 2 pins to "reset" which means needing to manually add a quirk every time we learn about a new model and perhaps more importantly this means things not workin OOTB until we add such a quirk.

When working on the UVC driver you sometimes ask / wonder what
does Windows do here? In this case it is pretty clear that
Window simply sets all GPIOs listed in the INT3472 ACPI resources/ the DSM call describing the GPIOs to their "on" state when the sensor needs to be turned on.

Since we don't have the sensor-power-sequencing part split of from the rest of the sensor driver code as Windows appears to have, we need to at least be able to mimick Windows to get things to "just work" which in some cases means driving 2 GPIOs even if the sensor really only has one enable/reset input.

I'm most interested in how we can solve the mentioned mt9m114 example here, since that is a case where per model DMI quirks will be necessary for a glue level solution, where as a sensor-driver level solution will solve this once for all models with that sensor.

Also drivers/media/i2c so far is quite unique in trying to completely avoid any ACPI platform specific handling. Almost all other driver subsystems I have worked in have various platform specific code-paths, sometimes for device-tree specific things and sometimes for ACPI specific things, e.g. :

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/input/touchscreen/goodix.c#n811

but that is just one example out of many. Although I understand that it is desirable to keep platform specific code out of the sensor drivers we also need to be pragmatic here IMHO.

Regards,

Hans

#13 lore raw
In reply to Laurent Pinchart
Quoted 21 lines · Laurent Pinchart
Quoted 20 lines · Hans de Goede
Quoted 19 lines · Sakari Ailus
Quoted 18 lines · Andy Shevchenko
Quoted 17 lines · Hans de Goede
Quoted 16 lines · Sakari Ailus
Quoted 15 lines · Hans de Goede
Quoted 14 lines · Sakari Ailus
Quoted 13 lines · Andy Shevchenko
Quoted 12 lines · Sakari Ailus
Quoted 11 lines · Andy Shevchenko

The driver of OmniVision OV7251 expects "enable" pin instead of "reset". Remap "reset" to "enable" and update polarity.

In particular, the Linux kernel can't load the camera sensor driver on Microsoft Surface Book without this change:

ov7251 i2c-INT347E:00: supply vdddo not found, using dummy regulator ov7251 i2c-INT347E:00: supply vddd not found, using dummy regulator ov7251 i2c-INT347E:00: supply vdda not found, using dummy regulator ov7251 i2c-INT347E:00: cannot get enable gpio
ov7251 i2c-INT347E:00: probe with driver ov7251 failed with error -2

...

Quoted 95 lines
Quoted 86 lines
Quoted 60 lines
Quoted 51 lines
Quoted 51 lines
Quoted 43 lines
Quoted 34 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Should this be cc'd to stable? I guess it's not exactly a fix in the driver but a BIOS bug, but it can be worked around in the driver. :-)

It's everything, but a BIOS bug, it's DT bug and whoever first introduced that GPIO in the driver. Even in the DT present in kernel the pin was referred as

How is that a DT (binding?) bug?

Since it is not following the datasheet name for the pin, it arguably is a DT binding bug

But whatever, the whole discussion about if it is a bug and whose bug it is is not useful. Since we cannot go back in time and change the DT binding DT and ACPI are simply going to disagree on the name and we will need something like this patch.

Quoted 9 lines
Quoted 4 lines

CAM_RST_N, which is exactly how this patch names it.

OTOH it's a fix to the driver that never worked for ACPI case, so there never was a regression to fix.

It probably worked just fine, just not with that Surface Book.

The polarity of the enable gpio appears to be set wrong in devm_gpiod_get() call. I can post a patch but cannot test it.

That is on purpose, at least the polarity if the devm_gpiod_get(..., "reset", ...) is inverted from the existing one for "enable" because reset needs to be inactive/disabled to enable the sensor.

Quoted 3 lines

Similarly, you should actually set the flags to GPIOD_OUT_HIGH as reset should be enabled here -- it's disabled only in power_on() as part of the power-on sequence.

Quoted 8 lines

This seems to be a pre-existing bug in this driver, which currently starts driving enable high, enabling the sensor at gpiod_get() time.

Note that fixing this is tricky-ish, if the pin was already high at gpiod_get() time then changing the gpiod_get() to drive it low will result in it only being driven low for a very short time since ov7251_set_power_on() will get called almost immediately after this and it will drive the pin high again without any delays.

Quoted 3 lines

The question here is not about how long the hard reset is applied, but whether or not the sensor's power-on sequence is followed. Currently it is not.

Right / agreed. The 2 points which I am trying to make are:

1. This is a pre-existing problem unrelated to this patch.

Quoted 8 lines
Quoted 5 lines

So this should be fixed in a separate patch.

2. That separate patch should put a delay after requesting the GPIO to enforce that it is (logically) low (for "enable") for a minimum amount of time.

Sakari, what's the status on this, please?
We have non-working camera just because of this small patch is absent.

Quoted 7 lines

Thanks for the ping.

I took a closer look at the problem, indeed the GPIO name comes from the int3472 driver and it's much better to work around this there than to ram Windows ACPI table specifics to sensor drivers. I'll post a patch for that shortly. Testing would be appreciated as the Surface Go 2 doesn't have a GPIO connected to this sensor.

Actually Andy wrote this patch after first writing a similar quirk patch as yours from:

https://lore.kernel.org/platform-driver-x86/[email protected]/T/#t

because I asked him to fix this in the sensor driver instead.

The problem is that we cannot fix this in the INT3472 driver without that becoming one big mess of driver specific quirks.

The Windows code seems to have separate power-ctrl/sequence drivers for the INT3472 device vs the rest of the sensor driver and this power-sequence driver happily consumes whatever GPIOs the INT3472 device provides independent of the sensor.

So e.g. on some designs we are going to see a reset pin and on others a powerdown pin.

Quoted 8 lines

But in this specific case things are actually more simple, the datasheet describes the pin as:

XSHUTDOWN input reset (active low with internal pull down resistor)

So the devicetree binding calling it "enable" is just wrong and in this case it is actually the DT binding which is buggy (there is no "enable" pin anywhere in the datasheet) and not the ACPI tables.

Quoted 8 lines

There has never been a requirement for the GPIO in DT to match the pin name from the datasheet. It's actually quite the contrary, DT maintainers request GPIO names to be standardized. Using "xshutdown-gpios" wouldn't be appreciated, instead DT bindings are encouraged to use standard names such as "reset", "enable" and "powerdown". As the pin is called "XSHUTDOWN", "enable" is not necessarily a bad match. "reset" could have been picked too, but that wasn't the case and we can't change that.

This is very strange. I always thought that DT is about describing _hardware_ and not some abstractions like Linux ones. The HW is pretty much clear that the pin is "reset" by semantics (if you want standardization), and not "enable".

Quoted 6 lines

The core of the issue here is that we have two firmware representations, DT and ACPI, and no coordination between the two. I don't expect that to change, and until Windows OEMs collaborate to standardize ACPI bindings, I'll consider this as a Windows-specific hack that I don't want to see being pushed to indidividual sensor drivers. This would be better handled in my opinion in the INT3472 driver.

Yeah and to me it's clearly the bug in DT schema for this pin. It had to be "reset" from day 1 in accordance with datasheet.

Quoted 10 lines
Quoted 9 lines

Also since you match on the sensor-type for the remapping this clearly is a per sensor thing and per sensor handling should be in the sensor drivers, which gives us the per sensor mapping for free.

Yes needing to handle this in the sensor driver makes the sensor driver slightly less pretty. But dealing with platform specifics in drivers is done all over the kernel and I don't see why camera sensor drivers are so special that they get to be excluded from sometimes needing to deal with platform specifics.

Quoted 3 lines

The whole point of having standardized firmware descriptions is to avoid board-specific code in drivers. INT3472 is meant to handle board specificities.

Yes, but world is not ideal and people made mistakes...

Signature · 2 lines
With Best Regards,
Andy Shevchenko