Skip to contentSkip to conversation

media: ov08x40: Various improvements

PATCH Superseded Hans de Goede 2 participants 23 messages Dec 19, 2024 – Dec 20, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover media: ov08x40: Various improvements

Hi All,

Here is a new ov08x40 patch series replacing my previous series:
https://lore.kernel.org/linux-media/[email protected]/

I have not marked this as a v2 series since after rebasing on top of Bryan O'Donoghue changes this essentially is a whole new series.

The below series has been tested on a HP Spectre x360 14-eu0xxx laptop, but unfortunately the sensor will still not power-on (identify() fails with -121) after this series.

Still I believe that these are all good improvements to have.

Bryan, can you test this on your ov08x40 setup and check that it does not cause any regressions there?

Regards,

Hans

Hans de Goede (8):
media: ov08x40: Properly turn sensor on/off when runtime-suspended
media: ov08x40: Move fwnode_graph_get_next_endpoint() call up
media: ov08x40: Get reset GPIO and regulators on ACPI platforms too
media: ov08x40: Get clock on ACPI platforms too
media: ov08x40: Move ov08x40_identify_module() function up
media: ov08x40: Improve ov08x40_identify_module() error logging
media: ov08x40: Improve ov08x40_[read|write]_reg() error returns
media: ov08x40: Add missing ov08x40_identify_module() call on
stream-start

 drivers/media/i2c/ov08x40.c | 157 +++++++++++++++++++-----------------
 1 file changed, 82 insertions(+), 75 deletions(-)
Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/8 media: ov08x40: Properly turn sensor on/off when runtime-suspended

Commit df1ae2251a50 ("media: ov08x40: Add OF probe support") added support for a reset GPIO, regulators and a clk provider controlled through new ov08x40_power_off() and ov08x40_power_on() functions.

But it missed adding a pm ops structure to call these functions on runtime suspend/resume. Add the missing pm ops and only call ov08x40_power_off() on remove() when not already runtime-suspended to avoid unbalanced regulator / clock disable calls.

Fixes df1ae2251a50 ("media: ov08x40: Add OF probe support")
---
 drivers/media/i2c/ov08x40.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/media/i2c/ov08x40.c +6 -2
index b9682264e2f5..aae923da1e86 100644
@@ -2324,11 +2324,14 @@ static void ov08x40_remove(struct i2c_client *client)
 	ov08x40_free_controls(ov08x);
 
 	pm_runtime_disable(&client->dev);
+	if (!pm_runtime_status_suspended(&client->dev))
+		ov08x40_power_off(&client->dev);
 	pm_runtime_set_suspended(&client->dev);
-
-	ov08x40_power_off(&client->dev);
 }
 
+static DEFINE_RUNTIME_DEV_PM_OPS(ov08x40_pm_ops, ov08x40_power_on,
+				 ov08x40_power_off, NULL);
+
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id ov08x40_acpi_ids[] = {
 	{"OVTI08F4"},
@@ -2349,6 +2352,7 @@ static struct i2c_driver ov08x40_i2c_driver = {
 		.name = "ov08x40",
 		.acpi_match_table = ACPI_PTR(ov08x40_acpi_ids),
 		.of_match_table = ov08x40_of_match,
+		.pm = pm_sleep_ptr(&ov08x40_pm_ops),
 	},
 	.probe = ov08x40_probe,
 	.remove = ov08x40_remove,
Signature · 1 line
2.47.1
#2 lore raw

Re: [PATCH 1/8] media: ov08x40: Properly turn sensor on/off when runtime-suspended

Quoted 37 lines · Hans de Goede

Commit df1ae2251a50 ("media: ov08x40: Add OF probe support") added support for a reset GPIO, regulators and a clk provider controlled through new ov08x40_power_off() and ov08x40_power_on() functions.

But it missed adding a pm ops structure to call these functions on runtime suspend/resume. Add the missing pm ops and only call ov08x40_power_off() on remove() when not already runtime-suspended to avoid unbalanced regulator / clock disable calls.

Fixes df1ae2251a50 ("media: ov08x40: Add OF probe support")
---
  drivers/media/i2c/ov08x40.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/media/i2c/ov08x40.c +5 -2
index b9682264e2f5..aae923da1e86 100644
@@ -2324,11 +2324,14 @@ static void ov08x40_remove(struct i2c_client *client)
  	ov08x40_free_controls(ov08x);
 
  	pm_runtime_disable(&client->dev);
+	if (!pm_runtime_status_suspended(&client->dev))
+		ov08x40_power_off(&client->dev);
  	pm_runtime_set_suspended(&client->dev);
-
-	ov08x40_power_off(&client->dev);
  }
 
+static DEFINE_RUNTIME_DEV_PM_OPS(ov08x40_pm_ops, ov08x40_power_on,
+				 ov08x40_power_off, NULL);
+
  #ifdef CONFIG_ACPI
  static const struct acpi_device_id ov08x40_acpi_ids[] = {
  	{"OVTI08F4"},

drivers/media/i2c/ov08x40.c static struct i2c_driver ov08x40_i2c_driver = { · line 2358

Quoted 7 lines
drivers/media/i2c/ov08x40.c +1 -0
@@ -2349,6 +2352,7 @@ static struct i2c_driver ov08x40_i2c_driver = {
  		.name = "ov08x40",
  		.acpi_match_table = ACPI_PTR(ov08x40_acpi_ids),
  		.of_match_table = ov08x40_of_match,
+		.pm = pm_sleep_ptr(&ov08x40_pm_ops),
  	},
  	.probe = ov08x40_probe,
  	.remove = ov08x40_remove,

Here's a trace of what I'm finding on the qcom crd with this patch.

[    4.383434] ov08x40 1-0036: ov08x40_power_on
[    4.393299] ov08x40 1-0036: ov08x40_power_on
[   10.119144] ov08x40 1-0036: ov08x40_set_stream
[   10.127842] ov08x40 1-0036: ov08x40_set_stream do pm_runtime_resume_and_get
[   10.135067] ov08x40 1-0036: ov08x40_power_off
[   10.139608] ov08x40 1-0036: ov08x40_start_streaming
[   10.150832] ov08x40 1-0036: ov08x40_start_streaming failed to set powerup registers
[   10.165625] ov08x40 1-0036: ov08x40_power_on
drivers/media/i2c/ov08x40.c +5 -1
index 579b4aa5f041d..c1dead0ca0756 100644
@@ -1321,7 +1321,7 @@ static int ov08x40_power_on(struct device *dev)
        struct v4l2_subdev *sd = dev_get_drvdata(dev);
        struct ov08x40 *ov08x = to_ov08x40(sd);
        int ret;
-
+dev_info(dev, "%s\n", __func__);
        ret = clk_prepare_enable(ov08x->xvclk);
        if (ret < 0) {
                dev_err(dev, "failed to enable xvclk\n");
@@ -1356,6 +1356,8 @@ static int ov08x40_power_off(struct device *dev)
        struct v4l2_subdev *sd = dev_get_drvdata(dev);
        struct ov08x40 *ov08x = to_ov08x40(sd);
 
+dev_info(dev, "%s\n", __func__);
+
        if (ov08x->reset_gpio)
                gpiod_set_value_cansleep(ov08x->reset_gpio, 1);
 
@@ -1874,6 +1876,8 @@ static int ov08x40_start_streaming(struct ov08x40 *ov08x)
        const struct ov08x40_reg_list *reg_list;
        int ret, link_freq_index;
 
+dev_info(&client->dev, "%s\n", __func__);
+
        /* Get out of from software reset */
        ret = ov08x40_write_reg(ov08x, OV08X40_REG_SOFTWARE_RST,
                                OV08X40_REG_VALUE_08BIT, 

OV08X40_SOFTWARE_RST);
@@ -1967,9 +1971,11 @@ static int ov08x40_set_stream(struct v4l2_subdev *sd, int enable)

        struct i2c_client *client = v4l2_get_subdevdata(sd);
        int ret = 0;
+dev_info(&client->dev, "%s\n", __func__);
        mutex_lock(&ov08x->mutex);

        if (enable) {
+               dev_info(&client->dev, "%s do pm_runtime_resume_and_get\n", __func__);
                ret = pm_runtime_resume_and_get(&client->dev);
                if (ret < 0)
                        goto err_unlock;
#3 lore raw

Re: [PATCH 1/8] media: ov08x40: Properly turn sensor on/off when runtime-suspended

Hi,

Quoted 16 lines · Bryan O'Donoghue
Quoted 15 lines · Hans de Goede

Commit df1ae2251a50 ("media: ov08x40: Add OF probe support") added support for a reset GPIO, regulators and a clk provider controlled through new ov08x40_power_off() and ov08x40_power_on() functions.

But it missed adding a pm ops structure to call these functions on runtime suspend/resume. Add the missing pm ops and only call ov08x40_power_off() on remove() when not already runtime-suspended to avoid unbalanced regulator / clock disable calls.

Fixes df1ae2251a50 ("media: ov08x40: Add OF probe support")

---
  drivers/media/i2c/ov08x40.c | 8 ++++++--

  1 file changed, 6 insertions(+), 2 deletions(-)
Quoted 16 lines
Quoted 6 lines
drivers/media/i2c/ov08x40.c +0 -0
index b9682264e2f5..aae923da1e86 100644
@@ -2324,11 +2324,14 @@ static void ov08x40_remove(struct i2c_client *client)
       ov08x40_free_controls(ov08x);

drivers/media/i2c/ov08x40.c static void ov08x40_remove(struct i2c_client *client) · line 2332

Quoted 10 lines
drivers/media/i2c/ov08x40.c +4 -2
         pm_runtime_disable(&client->dev);
+    if (!pm_runtime_status_suspended(&client->dev))
+        ov08x40_power_off(&client->dev);
       pm_runtime_set_suspended(&client->dev);
-
-    ov08x40_power_off(&client->dev);
   }
   +static DEFINE_RUNTIME_DEV_PM_OPS(ov08x40_pm_ops, ov08x40_power_on,
+                 ov08x40_power_off, NULL);
+

Ugh I have on/off swapped here, second argument of the macro is the suspend function so that should be ov08x40_power_off. IOW this should be:

static DEFINE_RUNTIME_DEV_PM_OPS(ov08x40_pm_ops, ov08x40_power_off,

				 ov08x40_power_on, NULL);

Can you give this a try with that change?

Regards,

Hans

Quoted 68 lines

drivers/media/i2c/ov08x40.c static struct i2c_driver ov08x40_i2c_driver = { · line 2358

Quoted 11 lines
drivers/media/i2c/ov08x40.c +1 -0
   #ifdef CONFIG_ACPI
   static const struct acpi_device_id ov08x40_acpi_ids[] = {
       {"OVTI08F4"},
@@ -2349,6 +2352,7 @@ static struct i2c_driver ov08x40_i2c_driver = {
           .name = "ov08x40",
           .acpi_match_table = ACPI_PTR(ov08x40_acpi_ids),
           .of_match_table = ov08x40_of_match,
+        .pm = pm_sleep_ptr(&ov08x40_pm_ops),
       },
       .probe = ov08x40_probe,
       .remove = ov08x40_remove,

Here's a trace of what I'm finding on the qcom crd with this patch.

[    4.383434] ov08x40 1-0036: ov08x40_power_on
[    4.393299] ov08x40 1-0036: ov08x40_power_on
[   10.119144] ov08x40 1-0036: ov08x40_set_stream
[   10.127842] ov08x40 1-0036: ov08x40_set_stream do pm_runtime_resume_and_get [   10.135067] ov08x40 1-0036: ov08x40_power_off
[   10.139608] ov08x40 1-0036: ov08x40_start_streaming
[   10.150832] ov08x40 1-0036: ov08x40_start_streaming failed to set powerup registers [   10.165625] ov08x40 1-0036: ov08x40_power_on

drivers/media/i2c/ov08x40.c +7 -1
index 579b4aa5f041d..c1dead0ca0756 100644
@@ -1321,7 +1321,7 @@ static int ov08x40_power_on(struct device *dev)
         struct v4l2_subdev *sd = dev_get_drvdata(dev);
         struct ov08x40 *ov08x = to_ov08x40(sd);
         int ret;
-
+dev_info(dev, "%s\n", __func__);
         ret = clk_prepare_enable(ov08x->xvclk);
         if (ret < 0) {
                 dev_err(dev, "failed to enable xvclk\n");
@@ -1356,6 +1356,8 @@ static int ov08x40_power_off(struct device *dev)
         struct v4l2_subdev *sd = dev_get_drvdata(dev);
         struct ov08x40 *ov08x = to_ov08x40(sd);
 
+dev_info(dev, "%s\n", __func__);
+
         if (ov08x->reset_gpio)
                 gpiod_set_value_cansleep(ov08x->reset_gpio, 1);
 
@@ -1874,6 +1876,8 @@ static int ov08x40_start_streaming(struct ov08x40 *ov08x)
         const struct ov08x40_reg_list *reg_list;
         int ret, link_freq_index;
 
+dev_info(&client->dev, "%s\n", __func__);
+
         /* Get out of from software reset */
         ret = ov08x40_write_reg(ov08x, OV08X40_REG_SOFTWARE_RST,
                                 OV08X40_REG_VALUE_08BIT, OV08X40_SOFTWARE_RST);
@@ -1967,9 +1971,11 @@ static int ov08x40_set_stream(struct v4l2_subdev *sd, int enable)
         struct i2c_client *client = v4l2_get_subdevdata(sd);
         int ret = 0;
 
+dev_info(&client->dev, "%s\n", __func__);
         mutex_lock(&ov08x->mutex);
 
         if (enable) {
+               dev_info(&client->dev, "%s do pm_runtime_resume_and_get\n", __func__);
                 ret = pm_runtime_resume_and_get(&client->dev);
                 if (ret < 0)
                         goto err_unlock;
#4 lore raw

Re: [PATCH 1/8] media: ov08x40: Properly turn sensor on/off when runtime-suspended

Quoted 7 lines · Hans de Goede
Quoted 4 lines
Quoted 4 lines

  }
  +static DEFINE_RUNTIME_DEV_PM_OPS(ov08x40_pm_ops, ov08x40_power_on,
+                 ov08x40_power_off, NULL);
+

Ugh I have on/off swapped here, second argument of the macro is the suspend function so that should be ov08x40_power_off. IOW this should be:

Quoted 8 lines

static DEFINE_RUNTIME_DEV_PM_OPS(ov08x40_pm_ops, ov08x40_power_off,

				 ov08x40_power_on, NULL);

Can you give this a try with that change?

Regards,

Hans

Heh.

That'd do it, works now.

---
bod

#5 lore raw

Re: [PATCH 1/8] media: ov08x40: Properly turn sensor on/off when runtime-suspended

Hi,

Quoted 13 lines · Bryan O'Donoghue
Quoted 12 lines · Hans de Goede
Quoted 4 lines
Quoted 4 lines

   }
   +static DEFINE_RUNTIME_DEV_PM_OPS(ov08x40_pm_ops, ov08x40_power_on, +                 ov08x40_power_off, NULL);
+

Ugh I have on/off swapped here, second argument of the macro is the suspend function so that should be ov08x40_power_off. IOW this should be:

static DEFINE_RUNTIME_DEV_PM_OPS(ov08x40_pm_ops, ov08x40_power_off, ov08x40_power_on, NULL);

Can you give this a try with that change?

Quoted 7 lines
Quoted 3 lines

Regards,

Hans

Heh.

That'd do it, works now.

Great, thank you for testing!

This probably also explains why this series did not help to get the sensor powered on on some x86 HP laptops...

I guess you are going to test the rest of the series and then provided a Tested-by?

If yes then I'll wait with posting v2 until you're done testing.

Regards,

Hans

#6 lore raw

Re: [PATCH 1/8] media: ov08x40: Properly turn sensor on/off when runtime-suspended

Quoted 4 lines · Hans de Goede

I guess you are going to test the rest of the series and then provided a Tested-by?

If yes then I'll wait with posting v2 until you're done testing.

I can give you Tested-by: for the series now + the change we discussed.

---
bod

#7 lore raw

Re: [PATCH 1/8] media: ov08x40: Properly turn sensor on/off when runtime-suspended

Hi,

Quoted 7 lines · Bryan O'Donoghue
Quoted 4 lines · Hans de Goede

I guess you are going to test the rest of the series and then provided a Tested-by?

If yes then I'll wait with posting v2 until you're done testing.

I can give you Tested-by: for the series now + the change we discussed.

Yes please, then I can include it in the v2 posting.

Regards,

Hans

#8 lore raw

Re: [PATCH 1/8] media: ov08x40: Properly turn sensor on/off when runtime-suspended

Quoted 9 lines · Hans de Goede

Hi,

Quoted 6 lines · Bryan O'Donoghue
Quoted 4 lines · Hans de Goede

I guess you are going to test the rest of the series and then provided a Tested-by?

If yes then I'll wait with posting v2 until you're done testing.

Quoted 8 lines
Quoted 1 line

I can give you Tested-by: for the series now + the change we discussed.

Yes please, then I can include it in the v2 posting.

Regards,

Hans

With the change discussed

#9 lore raw

PATCH 2/8 media: ov08x40: Move fwnode_graph_get_next_endpoint() call up

In reply to Hans de Goede

If the bridge has not yet setup the fwnode-graph then the fwnode_property_read_u32("clock-frequency") call will fail.

Make the fwnode_graph_get_next_endpoint() call the first call in ov08x40_check_hwcfg() and return -EPROBE_DEFER if it fails.

---
Changes in v2:
- Rebase on top of Bryan O'Donoghue OF support changes

---
 drivers/media/i2c/ov08x40.c | 40 +++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 17 deletions(-)
drivers/media/i2c/ov08x40.c +23 -17
index aae923da1e86..e4046d4705c3 100644
@@ -2151,23 +2151,37 @@ static int ov08x40_check_hwcfg(struct ov08x40 *ov08x, struct device *dev)
 	int ret;
 	u32 xvclk_rate;
 
-	if (!fwnode)
-		return -ENXIO;
+	/*
+	 * Sometimes the fwnode graph is initialized by the bridge driver.
+	 * Bridge drivers doing this also add sensor properties, wait for this.
+	 */
+	ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
+	if (!ep)
+		return dev_err_probe(dev, -EPROBE_DEFER,
+				     "waiting for fwnode graph endpoint\n");
+
+	ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg);
+	fwnode_handle_put(ep);
+	if (ret)
+		return ret;
 
 	if (!is_acpi_node(fwnode)) {
 		ov08x->xvclk = devm_clk_get(dev, NULL);
 		if (IS_ERR(ov08x->xvclk)) {
 			dev_err(dev, "could not get xvclk clock (%pe)\n",
 				ov08x->xvclk);
-			return PTR_ERR(ov08x->xvclk);
+			ret = PTR_ERR(ov08x->xvclk);
+			goto out_err;
 		}
 
 		xvclk_rate = clk_get_rate(ov08x->xvclk);
 
 		ov08x->reset_gpio = devm_gpiod_get_optional(dev, "reset",
 							    GPIOD_OUT_LOW);
-		if (IS_ERR(ov08x->reset_gpio))
-			return PTR_ERR(ov08x->reset_gpio);
+		if (IS_ERR(ov08x->reset_gpio)) {
+			ret = PTR_ERR(ov08x->reset_gpio);
+			goto out_err;
+		}
 
 		for (i = 0; i < ARRAY_SIZE(ov08x40_supply_names); i++)
 			ov08x->supplies[i].supply = ov08x40_supply_names[i];
@@ -2176,31 +2190,23 @@ static int ov08x40_check_hwcfg(struct ov08x40 *ov08x, struct device *dev)
 					      ARRAY_SIZE(ov08x40_supply_names),
 					      ov08x->supplies);
 		if (ret)
-			return ret;
+			goto out_err;
 	} else {
 		ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
 					       &xvclk_rate);
 		if (ret) {
 			dev_err(dev, "can't get clock frequency");
-			return ret;
+			goto out_err;
 		}
 	}
 
 	if (xvclk_rate != OV08X40_XVCLK) {
 		dev_err(dev, "external clock %d is not supported",
 			xvclk_rate);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto out_err;
 	}
 
-	ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
-	if (!ep)
-		return -ENXIO;
-
-	ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg);
-	fwnode_handle_put(ep);
-	if (ret)
-		return ret;
-
 	if (bus_cfg.bus.mipi_csi2.num_data_lanes != OV08X40_DATA_LANES) {
 		dev_err(dev, "number of CSI2 data lanes %d is not supported",
 			bus_cfg.bus.mipi_csi2.num_data_lanes);
Signature · 1 line
2.47.1
Tested-by on v1 2/8
#10 lore raw

Re: [PATCH 2/8] media: ov08x40: Move fwnode_graph_get_next_endpoint() call up

Quoted 7 lines · Hans de Goede

If the bridge has not yet setup the fwnode-graph then the fwnode_property_read_u32("clock-frequency") call will fail.

Make the fwnode_graph_get_next_endpoint() call the first call in ov08x40_check_hwcfg() and return -EPROBE_DEFER if it fails.

#11 lore raw

PATCH 3/8 media: ov08x40: Get reset GPIO and regulators on ACPI platforms too

In reply to Hans de Goede

ACPI platforms might also have a reset GPIO and regulators, move the code to get these outside of the if (!is_acpi_node(fwnode)) check.

This also removes the is_acpi_node(fwnode) checks from ov08x40_power_on() / ov08x40_power_off() both the GPIO hand the clk frameworks functions used there will happily accept the NULL pointer returned from the optional get() functions when there is no reset GPIO / no clk.

While moving the code around also at error logging to the error exit path for getting the reset GPIO.

---
 drivers/media/i2c/ov08x40.c | 38 ++++++++++++++++---------------------
 1 file changed, 16 insertions(+), 22 deletions(-)
drivers/media/i2c/ov08x40.c +16 -22
index e4046d4705c3..8b1380506778 100644
@@ -1322,9 +1322,6 @@ static int ov08x40_power_on(struct device *dev)
 	struct ov08x40 *ov08x = to_ov08x40(sd);
 	int ret;
 
-	if (is_acpi_node(dev_fwnode(dev)))
-		return 0;
-
 	ret = clk_prepare_enable(ov08x->xvclk);
 	if (ret < 0) {
 		dev_err(dev, "failed to enable xvclk\n");
@@ -1360,9 +1357,6 @@ static int ov08x40_power_off(struct device *dev)
 	struct v4l2_subdev *sd = dev_get_drvdata(dev);
 	struct ov08x40 *ov08x = to_ov08x40(sd);
 
-	if (is_acpi_node(dev_fwnode(dev)))
-		return 0;
-
 	gpiod_set_value_cansleep(ov08x->reset_gpio, 1);
 	regulator_bulk_disable(ARRAY_SIZE(ov08x40_supply_names),
 			       ov08x->supplies);
@@ -2165,6 +2159,22 @@ static int ov08x40_check_hwcfg(struct ov08x40 *ov08x, struct device *dev)
 	if (ret)
 		return ret;
 
+	ov08x->reset_gpio = devm_gpiod_get_optional(dev, "reset",
+						    GPIOD_OUT_LOW);
+	if (IS_ERR(ov08x->reset_gpio)) {
+		ret = dev_err_probe(dev, PTR_ERR(ov08x->reset_gpio),
+				    "getting reset GPIO\n");
+		goto out_err;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(ov08x40_supply_names); i++)
+		ov08x->supplies[i].supply = ov08x40_supply_names[i];
+
+	ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ov08x40_supply_names),
+				      ov08x->supplies);
+	if (ret)
+		goto out_err;
+
 	if (!is_acpi_node(fwnode)) {
 		ov08x->xvclk = devm_clk_get(dev, NULL);
 		if (IS_ERR(ov08x->xvclk)) {
@@ -2175,22 +2185,6 @@ static int ov08x40_check_hwcfg(struct ov08x40 *ov08x, struct device *dev)
 		}
 
 		xvclk_rate = clk_get_rate(ov08x->xvclk);
-
-		ov08x->reset_gpio = devm_gpiod_get_optional(dev, "reset",
-							    GPIOD_OUT_LOW);
-		if (IS_ERR(ov08x->reset_gpio)) {
-			ret = PTR_ERR(ov08x->reset_gpio);
-			goto out_err;
-		}
-
-		for (i = 0; i < ARRAY_SIZE(ov08x40_supply_names); i++)
-			ov08x->supplies[i].supply = ov08x40_supply_names[i];
-
-		ret = devm_regulator_bulk_get(dev,
-					      ARRAY_SIZE(ov08x40_supply_names),
-					      ov08x->supplies);
-		if (ret)
-			goto out_err;
 	} else {
 		ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
 					       &xvclk_rate);
Signature · 1 line
2.47.1
Tested-by on v1 3/8
#12 lore raw

Re: [PATCH 3/8] media: ov08x40: Get reset GPIO and regulators on ACPI platforms too

Quoted 8 lines · Hans de Goede

ACPI platforms might also have a reset GPIO and regulators, move the code to get these outside of the if (!is_acpi_node(fwnode)) check.

This also removes the is_acpi_node(fwnode) checks from ov08x40_power_on() / ov08x40_power_off() both the GPIO hand the clk frameworks functions used there will happily accept the NULL pointer returned from the optional get() functions when there is no reset GPIO / no clk.

Quoted 4 lines

While moving the code around also at error logging to the error exit path for getting the reset GPIO.

#13 lore raw

PATCH 4/8 media: ov08x40: Get clock on ACPI platforms too

In reply to Hans de Goede

ACPI platforms might also have a clk provider which needs to be controlled, always try to get a clk using clk_get_optional() and when that fails fall back to getting the xvclk frequency from the "clock-frequency" property.

---
 drivers/media/i2c/ov08x40.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/media/i2c/ov08x40.c +7 -9
index 8b1380506778..de8291e8b6e7 100644
@@ -2175,15 +2175,13 @@ static int ov08x40_check_hwcfg(struct ov08x40 *ov08x, struct device *dev)
 	if (ret)
 		goto out_err;
 
-	if (!is_acpi_node(fwnode)) {
-		ov08x->xvclk = devm_clk_get(dev, NULL);
-		if (IS_ERR(ov08x->xvclk)) {
-			dev_err(dev, "could not get xvclk clock (%pe)\n",
-				ov08x->xvclk);
-			ret = PTR_ERR(ov08x->xvclk);
-			goto out_err;
-		}
-
+	ov08x->xvclk = devm_clk_get_optional(dev, NULL);
+	if (IS_ERR(ov08x->xvclk)) {
+		ret = dev_err_probe(dev, PTR_ERR(ov08x->xvclk),
+				    "getting xvclk\n");
+		goto out_err;
+	}
+	if (ov08x->xvclk) {
 		xvclk_rate = clk_get_rate(ov08x->xvclk);
 	} else {
 		ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
Signature · 1 line
2.47.1
Tested-by on v1 4/8
#14 lore raw

Re: [PATCH 4/8] media: ov08x40: Get clock on ACPI platforms too

Quoted 5 lines · Hans de Goede

ACPI platforms might also have a clk provider which needs to be controlled, always try to get a clk using clk_get_optional() and when that fails fall back to getting the xvclk frequency from the "clock-frequency" property.

#15 lore raw

PATCH 5/8 media: ov08x40: Move ov08x40_identify_module() function up

In reply to Hans de Goede

Move the ov08x40_identify_module() function to above ov08x40_set_stream() this is a preparation patch for adding a missing ov08x40_identify_module() call to ov08x40_set_stream().

No functional changes, just moving code around.

---
 drivers/media/i2c/ov08x40.c | 52 ++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 26 deletions(-)
drivers/media/i2c/ov08x40.c +26 -26
index de8291e8b6e7..44989a37c2f3 100644
@@ -1931,6 +1931,32 @@ static int ov08x40_stop_streaming(struct ov08x40 *ov08x)
 				 OV08X40_REG_VALUE_08BIT, OV08X40_MODE_STANDBY);
 }
 
+/* Verify chip ID */
+static int ov08x40_identify_module(struct ov08x40 *ov08x)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&ov08x->sd);
+	int ret;
+	u32 val;
+
+	if (ov08x->identified)
+		return 0;
+
+	ret = ov08x40_read_reg(ov08x, OV08X40_REG_CHIP_ID,
+			       OV08X40_REG_VALUE_24BIT, &val);
+	if (ret)
+		return ret;
+
+	if (val != OV08X40_CHIP_ID) {
+		dev_err(&client->dev, "chip id mismatch: %x!=%x\n",
+			OV08X40_CHIP_ID, val);
+		return -ENXIO;
+	}
+
+	ov08x->identified = true;
+
+	return 0;
+}
+
 static int ov08x40_set_stream(struct v4l2_subdev *sd, int enable)
 {
 	struct ov08x40 *ov08x = to_ov08x40(sd);
@@ -1968,32 +1994,6 @@ static int ov08x40_set_stream(struct v4l2_subdev *sd, int enable)
 	return ret;
 }
 
-/* Verify chip ID */
-static int ov08x40_identify_module(struct ov08x40 *ov08x)
-{
-	struct i2c_client *client = v4l2_get_subdevdata(&ov08x->sd);
-	int ret;
-	u32 val;
-
-	if (ov08x->identified)
-		return 0;
-
-	ret = ov08x40_read_reg(ov08x, OV08X40_REG_CHIP_ID,
-			       OV08X40_REG_VALUE_24BIT, &val);
-	if (ret)
-		return ret;
-
-	if (val != OV08X40_CHIP_ID) {
-		dev_err(&client->dev, "chip id mismatch: %x!=%x\n",
-			OV08X40_CHIP_ID, val);
-		return -ENXIO;
-	}
-
-	ov08x->identified = true;
-
-	return 0;
-}
-
 static const struct v4l2_subdev_video_ops ov08x40_video_ops = {
 	.s_stream = ov08x40_set_stream,
 };
Signature · 1 line
2.47.1
Tested-by on v1 5/8
#16 lore raw

Re: [PATCH 5/8] media: ov08x40: Move ov08x40_identify_module() function up

Quoted 7 lines · Hans de Goede

Move the ov08x40_identify_module() function to above ov08x40_set_stream() this is a preparation patch for adding a missing ov08x40_identify_module() call to ov08x40_set_stream().

No functional changes, just moving code around.

#17 lore raw

PATCH 6/8 media: ov08x40: Improve ov08x40_identify_module() error logging

In reply to Hans de Goede

ov08x40_identify_module() already logs an error if the read ID mismatches, so having its caller also log an error results in 2 errors in this case.

Add error logging to the ID register read in ov08x40_identify_module() and drop the error logging in the caller.

---
 drivers/media/i2c/ov08x40.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/i2c/ov08x40.c +4 -4
index 44989a37c2f3..ca004343a9d8 100644
@@ -1943,8 +1943,10 @@ static int ov08x40_identify_module(struct ov08x40 *ov08x)
 
 	ret = ov08x40_read_reg(ov08x, OV08X40_REG_CHIP_ID,
 			       OV08X40_REG_VALUE_24BIT, &val);
-	if (ret)
+	if (ret) {
+		dev_err(&client->dev, "error reading chip-id register: %d\n", ret);
 		return ret;
+	}
 
 	if (val != OV08X40_CHIP_ID) {
 		dev_err(&client->dev, "chip id mismatch: %x!=%x\n",
@@ -2262,10 +2264,8 @@ static int ov08x40_probe(struct i2c_client *client)
 
 		/* Check module identity */
 		ret = ov08x40_identify_module(ov08x);
-		if (ret) {
-			dev_err(&client->dev, "failed to find sensor: %d\n", ret);
+		if (ret)
 			goto probe_power_off;
-		}
 	}
 
 	/* Set default mode to max resolution */
Signature · 1 line
2.47.1
Tested-by on v1 6/8
#18 lore raw

Re: [PATCH 6/8] media: ov08x40: Improve ov08x40_identify_module() error logging

Quoted 7 lines · Hans de Goede

ov08x40_identify_module() already logs an error if the read ID mismatches, so having its caller also log an error results in 2 errors in this case.

Add error logging to the ID register read in ov08x40_identify_module() and drop the error logging in the caller.

#19 lore raw

PATCH 7/8 media: ov08x40: Improve ov08x40_[read|write]_reg() error returns

In reply to Hans de Goede

Improve ov08x40_[read|write]_reg() error returns, if we got an errno value from the I2C core use that instead of always returning -EIO.

---
 drivers/media/i2c/ov08x40.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/media/i2c/ov08x40.c +5 -4
index ca004343a9d8..7fde422039cb 100644
@@ -1394,7 +1394,7 @@ static int ov08x40_read_reg(struct ov08x40 *ov08x,
 
 	ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
 	if (ret != ARRAY_SIZE(msgs))
-		return -EIO;
+		return ret < 0 ? ret : -EIO;
 
 	*val = be32_to_cpu(data_be);
 
@@ -1463,7 +1463,7 @@ static int ov08x40_write_reg(struct ov08x40 *ov08x,
 			     u16 reg, u32 len, u32 __val)
 {
 	struct i2c_client *client = v4l2_get_subdevdata(&ov08x->sd);
-	int buf_i, val_i;
+	int buf_i, val_i, ret;
 	u8 buf[6], *val_p;
 	__be32 val;
 
@@ -1481,8 +1481,9 @@ static int ov08x40_write_reg(struct ov08x40 *ov08x,
 	while (val_i < 4)
 		buf[buf_i++] = val_p[val_i++];
 
-	if (i2c_master_send(client, buf, len + 2) != len + 2)
-		return -EIO;
+	ret = i2c_master_send(client, buf, len + 2);
+	if (ret != len + 2)
+		return ret < 0 ? ret : -EIO;
 
 	return 0;
 }
Signature · 1 line
2.47.1
#21 lore raw

PATCH 8/8 media: ov08x40: Add missing ov08x40_identify_module() call on stream-start

In reply to Hans de Goede

The driver might skip the ov08x40_identify_module() on probe() based on the acpi_dev_state_d0() check done in probe().

If the ov08x40_identify_module() call is skipped on probe() it should be done on the first stream start. Add the missing call.

Note ov08x40_identify_module() will only do something on its first call, subsequent calls are no-ops.

---
 drivers/media/i2c/ov08x40.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/media/i2c/ov08x40.c +4 -0
index 7fde422039cb..b6e69e0c2ecf 100644
@@ -1973,6 +1973,10 @@ static int ov08x40_set_stream(struct v4l2_subdev *sd, int enable)
 		if (ret < 0)
 			goto err_unlock;
 
+		ret = ov08x40_identify_module(ov08x);
+		if (ret)
+			goto err_rpm_put;
+
 		/*
 		 * Apply default & customized values
 		 * and then start streaming.
Signature · 1 line
2.47.1
Tested-by on v1 8/8
#22 lore raw

Re: [PATCH 8/8] media: ov08x40: Add missing ov08x40_identify_module() call on stream-start

Quoted 10 lines · Hans de Goede

The driver might skip the ov08x40_identify_module() on probe() based on the acpi_dev_state_d0() check done in probe().

If the ov08x40_identify_module() call is skipped on probe() it should be done on the first stream start. Add the missing call.

Note ov08x40_identify_module() will only do something on its first call, subsequent calls are no-ops.