Skip to contentSkip to conversation

media: i2c: alvium: Accelerated alvium_set_power

PATCH In review [email protected] 2 participants 2 messages May 13, 2025 – May 26, 2025

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

PATCH 1/1 media: i2c: alvium: Accelerated alvium_set_power

From: Martin Hecht <[email protected]>

Now alvium_set_power tests if Alvium is up and running already instead of waiting for the period of a full reboot. This safes about 7 seconds delay for each connected and already booted camera especially when using multiple Alvium cameras.

---
 drivers/media/i2c/alvium-csi2.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/media/i2c/alvium-csi2.c +19 -2
index 05b708bd0a64..c7d39b10d1a2 100644
@@ -2367,6 +2367,9 @@ static int alvium_get_dt_data(struct alvium_dev *alvium)
 static int alvium_set_power(struct alvium_dev *alvium, bool on)
 {
 	int ret;
+	int alvium_boot_time_timout = 7000;
+	const int alvium_poll_interval = 500;
+	u64 val = 0;
 
 	if (!on)
 		return regulator_disable(alvium->reg_vcc);
@@ -2375,8 +2378,22 @@ static int alvium_set_power(struct alvium_dev *alvium, bool on)
 	if (ret)
 		return ret;
 
-	/* alvium boot time 7s */
-	msleep(7000);
+	/* alvium boot time is less than 7s, but eventually it's already on */
+	do {
+		alvium_read(alvium, REG_BCRM_HEARTBEAT_RW, &val, &ret);
+		if (ret >= 0)
+			break;
+
+		msleep(alvium_poll_interval);
+		alvium_boot_time_timout -= alvium_poll_interval;
+	} while (alvium_boot_time_timout > 0);
+
+	if (ret < 0)
+		return ret;
+
+	if (alvium_boot_time_timout <= 0)
+		return -ETIMEDOUT;
+
 	return 0;
 }
 
Signature · 1 line
2.43.0
#1 lore raw

Hi Martin,

Thanks for the patch.

Quoted 31 lines · On Tue, May 13, 2025 at 04:10:20PM +0200, [email protected] wrote:

From: Martin Hecht <[email protected]>

Now alvium_set_power tests if Alvium is up and running already instead of waiting for the period of a full reboot. This safes about 7 seconds delay for each connected and already booted camera especially when using multiple Alvium cameras.

---
 drivers/media/i2c/alvium-csi2.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/media/i2c/alvium-csi2.c +3 -1
index 05b708bd0a64..c7d39b10d1a2 100644
@@ -2367,6 +2367,9 @@ static int alvium_get_dt_data(struct alvium_dev *alvium)
 static int alvium_set_power(struct alvium_dev *alvium, bool on)
 {
 	int ret;
+	int alvium_boot_time_timout = 7000;
+	const int alvium_poll_interval = 500;
+	u64 val = 0;
 
 	if (!on)
 		return regulator_disable(alvium->reg_vcc);
@@ -2375,8 +2378,22 @@ static int alvium_set_power(struct alvium_dev *alvium, bool on)
 	if (ret)
 		return ret;
 
-	/* alvium boot time 7s */

drivers/media/i2c/alvium-csi2.c static int alvium_set_power(struct alvium_dev *alvium, bool on) · line 2389

Quoted 10 lines
drivers/media/i2c/alvium-csi2.c +9 -1
-	msleep(7000);
+	/* alvium boot time is less than 7s, but eventually it's already on */
+	do {
+		alvium_read(alvium, REG_BCRM_HEARTBEAT_RW, &val, &ret);
+		if (ret >= 0)
+			break;
+
+		msleep(alvium_poll_interval);
+		alvium_boot_time_timout -= alvium_poll_interval;
+	} while (alvium_boot_time_timout > 0);

Please use read_poll_timeout() for this.

Quoted 10 lines
drivers/media/i2c/alvium-csi2.c +7 -0
+
+	if (ret < 0)
+		return ret;
+
+	if (alvium_boot_time_timout <= 0)
+		return -ETIMEDOUT;
+
 	return 0;
 }
 
Signature · 3 lines
Regards,

Sakari Ailus