Skip to contentSkip to conversation

Better support for ACPI in smiapp

PATCH New Sakari Ailus 1 participant 5 messages Aug 29, 2017 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

cover Better support for ACPI in smiapp

Hi,

The few patches here fix a bug (power sequence error handling) and change clock handling in a way that allow using the driver in systems without explicit clock control, e.g. ACPI.

Sakari Ailus (4):
smiapp: Fix error handling in power on sequence
smiapp: Verify clock frequency after setting it, prevent changing it
smiapp: Get clock rate if it's not available through DT
smiapp: Make clock control optional

 drivers/media/i2c/smiapp/smiapp-core.c | 50 ++++++++++++++++++++++++++--------
 1 file changed, 38 insertions(+), 12 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/4 smiapp: Fix error handling in power on sequence

The error handling code in smiapp_power_on() returned in case of a failed I2C write instead of cleaning up the mess. Fix this.

---
 drivers/media/i2c/smiapp/smiapp-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/smiapp/smiapp-core.c +1 -1
index 700f433261d0..d581625d7826 100644
@@ -1313,7 +1313,7 @@ static int smiapp_power_on(struct device *dev)
 	rval = smiapp_write(sensor, SMIAPP_REG_U8_DPHY_CTRL,
 			    SMIAPP_DPHY_CTRL_UI);
 	if (rval < 0)
-		return rval;
+		goto out_cci_addr_fail;
 
 	rval = smiapp_call_quirk(sensor, post_poweron);
 	if (rval) {
Signature · 1 line
2.11.0
#2 lore raw

PATCH 2/4 smiapp: Verify clock frequency after setting it, prevent changing it

In reply to Sakari Ailus

The external clock frequency was set by the driver but the obtained frequency was never verified. Do that.

Being able to obtain the exact frequency is important as the value is used for PLL calculations which may result in frequencies that violate the PLL tree limits.

---
 drivers/media/i2c/smiapp/smiapp-core.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/media/i2c/smiapp/smiapp-core.c +9 -0
index d581625d7826..55771826b446 100644
@@ -2870,6 +2870,7 @@ static int smiapp_probe(struct i2c_client *client,
 {
 	struct smiapp_sensor *sensor;
 	struct smiapp_hwconfig *hwcfg = smiapp_get_hwconfig(&client->dev);
+	unsigned long rate;
 	unsigned int i;
 	int rval;
 
@@ -2908,6 +2909,14 @@ static int smiapp_probe(struct i2c_client *client,
 		return rval;
 	}
 
+	rate = clk_get_rate(sensor->ext_clk);
+	if (rate != sensor->hwcfg->ext_clk) {
+		dev_err(&client->dev,
+			"can't set clock freq, asked for %u but got %lu\n",
+			sensor->hwcfg->ext_clk, rate);
+		return rval;
+	}
+
 	sensor->xshutdown = devm_gpiod_get_optional(&client->dev, "xshutdown",
 						    GPIOD_OUT_LOW);
 	if (IS_ERR(sensor->xshutdown))
Signature · 1 line
2.11.0
#3 lore raw

PATCH 3/4 smiapp: Get clock rate if it's not available through DT

In reply to Sakari Ailus

Obtain the clock rate from the clock framework if it's not available through DT. The assumption is that the parent device (camera module) defines the rate as clock control is a part of the power on and power off sequences --- which are camera module specific.

Also use the clock rate from DT if no clock is provided.

---
 drivers/media/i2c/smiapp/smiapp-core.c | 52 +++++++++++++++++++++-------------
 1 file changed, 33 insertions(+), 19 deletions(-)
drivers/media/i2c/smiapp/smiapp-core.c +33 -19
index 55771826b446..009b5e26204b 100644
@@ -2829,12 +2829,10 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 	/* NVM size is not mandatory */
 	fwnode_property_read_u32(fwnode, "nokia,nvm-size", &hwcfg->nvm_size);
 
-	rval = fwnode_property_read_u32(fwnode, "clock-frequency",
+	rval = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
 					&hwcfg->ext_clk);
-	if (rval) {
-		dev_warn(dev, "can't get clock-frequency\n");
-		goto out_err;
-	}
+	if (rval)
+		dev_info(dev, "can't get clock-frequency\n");
 
 	dev_dbg(dev, "nvm %d, clk %d, mode %d\n",
 		hwcfg->nvm_size, hwcfg->ext_clk, hwcfg->csi_signalling_mode);
@@ -2870,7 +2868,6 @@ static int smiapp_probe(struct i2c_client *client,
 {
 	struct smiapp_sensor *sensor;
 	struct smiapp_hwconfig *hwcfg = smiapp_get_hwconfig(&client->dev);
-	unsigned long rate;
 	unsigned int i;
 	int rval;
 
@@ -2901,20 +2898,37 @@ static int smiapp_probe(struct i2c_client *client,
 		return -EPROBE_DEFER;
 	}
 
-	rval = clk_set_rate(sensor->ext_clk, sensor->hwcfg->ext_clk);
-	if (rval < 0) {
-		dev_err(&client->dev,
-			"unable to set clock freq to %u\n",
-			sensor->hwcfg->ext_clk);
-		return rval;
-	}
+	if (sensor->ext_clk) {
+		if (sensor->hwcfg->ext_clk) {
+			unsigned long rate;
 
-	rate = clk_get_rate(sensor->ext_clk);
-	if (rate != sensor->hwcfg->ext_clk) {
-		dev_err(&client->dev,
-			"can't set clock freq, asked for %u but got %lu\n",
-			sensor->hwcfg->ext_clk, rate);
-		return rval;
+			rval = clk_set_rate(sensor->ext_clk,
+					    sensor->hwcfg->ext_clk);
+			if (rval < 0) {
+				dev_err(&client->dev,
+					"unable to set clock freq to %u\n",
+					sensor->hwcfg->ext_clk);
+				return rval;
+			}
+
+			rate = clk_get_rate(sensor->ext_clk);
+			if (rate != sensor->hwcfg->ext_clk) {
+				dev_err(&client->dev,
+					"can't set clock freq, asked for %u but got %lu\n",
+					sensor->hwcfg->ext_clk, rate);
+				return rval;
+			}
+		} else {
+			sensor->hwcfg->ext_clk = clk_get_rate(sensor->ext_clk);
+			dev_dbg(&client->dev, "obtained clock freq %u\n",
+				sensor->hwcfg->ext_clk);
+		}
+	} else if (sensor->hwcfg->ext_clk) {
+		dev_dbg(&client->dev, "assuming clock freq %u\n",
+			sensor->hwcfg->ext_clk);
+	} else {
+		dev_err(&client->dev, "unable to obtain clock freq\n");
+		return -EINVAL;
 	}
 
 	sensor->xshutdown = devm_gpiod_get_optional(&client->dev, "xshutdown",
Signature · 1 line
2.11.0
#4 lore raw

PATCH 4/4 smiapp: Make clock control optional

In reply to Sakari Ailus

The clock control is not explicitly controlled by the driver in two cases:
ACPI based systems and when the clock is part of the power sequence of the camera module.

---
 drivers/media/i2c/smiapp/smiapp-core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/i2c/smiapp/smiapp-core.c +4 -1
index 009b5e26204b..fbd851be51d2 100644
@@ -2892,7 +2892,10 @@ static int smiapp_probe(struct i2c_client *client,
 	}
 
 	sensor->ext_clk = devm_clk_get(&client->dev, NULL);
-	if (IS_ERR(sensor->ext_clk)) {
+	if (PTR_ERR(sensor->ext_clk) == -ENOENT) {
+		dev_info(&client->dev, "no clock defined, continuing...\n");
+		sensor->ext_clk = NULL;
+	} else if (IS_ERR(sensor->ext_clk)) {
 		dev_err(&client->dev, "could not get clock (%ld)\n",
 			PTR_ERR(sensor->ext_clk));
 		return -EPROBE_DEFER;
Signature · 1 line
2.11.0