diff mbox series

media: i2c: alvium: Accelerated alvium_set_power

Message ID 20250513141019.3871882-2-mhecht73@gmail.com
State New
Headers show
Series media: i2c: alvium: Accelerated alvium_set_power | expand

Commit Message

mhecht73@googlemail.com May 13, 2025, 2:10 p.m. UTC
From: Martin Hecht <mhecht73@gmail.com>

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.

Signed-off-by: Martin Hecht <mhecht73@gmail.com>
---
 drivers/media/i2c/alvium-csi2.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c
index 05b708bd0a64..c7d39b10d1a2 100644
--- a/drivers/media/i2c/alvium-csi2.c
+++ b/drivers/media/i2c/alvium-csi2.c
@@ -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;
 }