Skip to contentSkip to conversation

CCS cleanups

PATCH New Sakari Ailus 1 participant 6 messages Apr 17, 2025

Subsystems (2)
lore
Share & tools
lore

Sakari Ailus

author maintainer
#0 lore raw

cover CCS cleanups

Hi folks,

This set includes a few I²C access changes, including the removal of the I²C retry hack (could be problematic for user space) as well as explicit access retry after reset.

Sakari Ailus (5):
media: ccs: Don't complain about missing "clock-frequency" property
media: ccs: Try a little longer to access the sensor before giving up
media: ccs: Use read_poll_timeout() in reset polling
media: ccs: Remove I²C write retry hack
media: ccs: Don't complain about lack of quirks

 drivers/media/i2c/ccs/ccs-core.c       | 54 +++++++++++---------------
 drivers/media/i2c/ccs/ccs-reg-access.c |  9 +----
 drivers/media/i2c/ccs/ccs.h            |  2 +
 3 files changed, 25 insertions(+), 40 deletions(-)
Signature · 1 line
2.39.5
author maintainer
#1 lore raw

PATCH 1/5 media: ccs: Don't complain about missing "clock-frequency" property

The clock frequency is often available via the clock itself and not read by the driver from the "clock-frequency" property. Don't complain if the property doesn't exist.

---
 drivers/media/i2c/ccs/ccs-core.c | 2 --
 1 file changed, 2 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +0 -2
index 004d28c33287..32ebc4477fc7 100644
@@ -3131,8 +3131,6 @@ static int ccs_get_hwconfig(struct ccs_sensor *sensor, struct device *dev)
 
 	rval = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
 					&hwcfg->ext_clk);
-	if (rval)
-		dev_info(dev, "can't get clock-frequency\n");
 
 	dev_dbg(dev, "clk %u, mode %u\n", hwcfg->ext_clk,
 		hwcfg->csi_signalling_mode);
Signature · 1 line
2.39.5
author maintainer
#2 lore raw

PATCH 2/5 media: ccs: Try a little longer to access the sensor before giving up

In reply to Sakari Ailus

Some sensors take longer to respond after reset than the spec-required time. Try up to 1 s for the sensor to become accessible.

---
 drivers/media/i2c/ccs/ccs-core.c | 26 +++++++++++++-------------
 drivers/media/i2c/ccs/ccs.h      |  2 ++
 2 files changed, 15 insertions(+), 13 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +13 -13
index 32ebc4477fc7..aeda286a7607 100644
@@ -1354,8 +1354,10 @@ static int ccs_change_cci_addr(struct ccs_sensor *sensor)
 
 	client->addr = sensor->hwcfg.i2c_addr_dfl;
 
-	rval = ccs_write(sensor, CCI_ADDRESS_CTRL,
-			 sensor->hwcfg.i2c_addr_alt << 1);
+	rval = read_poll_timeout(ccs_write, rval, !rval, CCS_RESET_DELAY_US,
+				 CCS_RESET_TIMEOUT_US, false, sensor,
+				 CCI_ADDRESS_CTRL,
+				 sensor->hwcfg.i2c_addr_alt << 1);
 	if (rval)
 		return rval;
 
@@ -1575,27 +1577,25 @@ static int ccs_power_on(struct device *dev)
 		if (ccsdev->flags & CCS_DEVICE_FLAG_IS_SMIA)
 			sleep = SMIAPP_RESET_DELAY(sensor->hwcfg.ext_clk);
 		else
-			sleep = 5000;
+			sleep = CCS_RESET_DELAY_US;
 
 		usleep_range(sleep, sleep);
 	}
 
 	/*
-	 * Failures to respond to the address change command have been noticed.
-	 * Those failures seem to be caused by the sensor requiring a longer
-	 * boot time than advertised. An additional 10ms delay seems to work
-	 * around the issue, but the SMIA++ I2C write retry hack makes the delay
-	 * unnecessary. The failures need to be investigated to find a proper
-	 * fix, and a delay will likely need to be added here if the I2C write
-	 * retry hack is reverted before the root cause of the boot time issue
-	 * is found.
+	 * Some devices take longer than the spec-defined time to respond
+	 * after reset. Try until some time has passed before flagging it
+	 * an error.
 	 */
-
 	if (!sensor->reset && !sensor->xshutdown) {
 		u8 retry = 100;
 		u32 reset;
 
-		rval = ccs_write(sensor, SOFTWARE_RESET, CCS_SOFTWARE_RESET_ON);
+		rval = read_poll_timeout(ccs_write, rval, !rval,
+					 CCS_RESET_DELAY_US,
+					 CCS_RESET_TIMEOUT_US,
+					 false, sensor, SOFTWARE_RESET,
+					 CCS_SOFTWARE_RESET_ON);
 		if (rval < 0) {
 			dev_err(dev, "software reset failed\n");
 			goto out_cci_addr_fail;
drivers/media/i2c/ccs/ccs.h +2 -0
index 096573845a10..0726c4687f0f 100644
@@ -43,6 +43,8 @@
 #define SMIAPP_RESET_DELAY(clk)				\
 	(1000 +	(SMIAPP_RESET_DELAY_CLOCKS * 1000	\
 		 + (clk) / 1000 - 1) / ((clk) / 1000))
+#define CCS_RESET_DELAY_US		5000
+#define CCS_RESET_TIMEOUT_US		1000000
 
 #define CCS_COLOUR_COMPONENTS		4
 
Signature · 1 line
2.39.5
author maintainer
#3 lore raw

PATCH 3/5 media: ccs: Use read_poll_timeout() in reset polling

In reply to Sakari Ailus

Use read_poll_timeout() in polling the device after a reset, either hard or soft. While at it, improve the related error message.

---
 drivers/media/i2c/ccs/ccs-core.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +9 -13
index aeda286a7607..d5c369bbb1b6 100644
@@ -1588,7 +1588,6 @@ static int ccs_power_on(struct device *dev)
 	 * an error.
 	 */
 	if (!sensor->reset && !sensor->xshutdown) {
-		u8 retry = 100;
 		u32 reset;
 
 		rval = read_poll_timeout(ccs_write, rval, !rval,
@@ -1601,18 +1600,15 @@ static int ccs_power_on(struct device *dev)
 			goto out_cci_addr_fail;
 		}
 
-		do {
-			rval = ccs_read(sensor, SOFTWARE_RESET, &reset);
-			reset = !rval && reset == CCS_SOFTWARE_RESET_OFF;
-			if (reset)
-				break;
-
-			usleep_range(1000, 2000);
-		} while (--retry);
-
-		if (!reset) {
-			dev_err(dev, "software reset failed\n");
-			rval = -EIO;
+		rval = read_poll_timeout(ccs_read, rval,
+					 !rval &&
+						reset == CCS_SOFTWARE_RESET_OFF,
+					 CCS_RESET_DELAY_US,
+					 CCS_RESET_TIMEOUT_US, false, sensor,
+					 SOFTWARE_RESET, &reset);
+		if (rval < 0) {
+			dev_err_probe(dev, rval,
+				      "failed to respond after reset\n");
 			goto out_cci_addr_fail;
 		}
 	}
Signature · 1 line
2.39.5
author maintainer
#4 lore raw

PATCH 4/5 media: ccs: Remove I²C write retry hack

In reply to Sakari Ailus

The I²C retry hack has been there in order to address transient I²C register write access issues on a few very old sensors and possibly it has addressed also first I²C access problems (device not responding until a certain amount of time has passed) but that is now separately handled. The retry hack has a good potential for introducing hard to debug problems in updating sensor settings while streaming. Remove it and instead pass those rare errors to the user space -- which is also what virtually all other drivers do.

---
 drivers/media/i2c/ccs/ccs-reg-access.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/media/i2c/ccs/ccs-reg-access.c +1 -8
index a696a0ec8ff5..fd36889ccc1d 100644
@@ -210,7 +210,6 @@ int ccs_read_addr_noconv(struct ccs_sensor *sensor, u32 reg, u32 *val)
  */
 int ccs_write_addr(struct ccs_sensor *sensor, u32 reg, u32 val)
 {
-	unsigned int retries = 10;
 	int rval;
 
 	rval = ccs_call_quirk(sensor, reg_access, true, &reg, &val);
@@ -219,13 +218,7 @@ int ccs_write_addr(struct ccs_sensor *sensor, u32 reg, u32 val)
 	if (rval < 0)
 		return rval;
 
-	rval = 0;
-	do {
-		if (cci_write(sensor->regmap, reg, val, &rval))
-			fsleep(1000);
-	} while (rval && --retries);
-
-	return rval;
+	return cci_write(sensor->regmap, reg, val, NULL);
 }
 
 #define MAX_WRITE_LEN	32U
Signature · 1 line
2.39.5
author maintainer
#5 lore raw

PATCH 5/5 media: ccs: Don't complain about lack of quirks

In reply to Sakari Ailus

Generally any deviance from the standard is handled via CCS static data nowadays and so not having quirks is expected. Don't warn about it.

---
 drivers/media/i2c/ccs/ccs-core.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +0 -4
index d5c369bbb1b6..89416afea26e 100644
@@ -2853,10 +2853,6 @@ static int ccs_identify_module(struct ccs_sensor *sensor)
 		break;
 	}
 
-	if (i >= ARRAY_SIZE(ccs_module_idents))
-		dev_warn(&client->dev,
-			 "no quirks for this module; let's hope it's fully compliant\n");
-
 	dev_dbg(&client->dev, "the sensor is called %s\n", minfo->name);
 
 	return 0;
Signature · 1 line
2.39.5