All of lore.kernel.org
 help / color / mirror / Atom feed
From: mhecht73@googlemail.com
To: linux-media@vger.kernel.org
Cc: sakari.ailus@linux.intel.com, tomm.merciai@gmail.com,
	martin.hecht@avnet.com, Martin Hecht <mhecht73@gmail.com>
Subject: [PATCH] media: i2c: alvium: Accelerated alvium_set_power
Date: Tue, 13 May 2025 16:10:20 +0200	[thread overview]
Message-ID: <20250513141019.3871882-2-mhecht73@gmail.com> (raw)

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 --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;
 }
 
-- 
2.43.0


             reply	other threads:[~2025-05-13 14:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-13 14:10 mhecht73 [this message]
2025-05-26  8:04 ` [PATCH] media: i2c: alvium: Accelerated alvium_set_power Sakari Ailus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250513141019.3871882-2-mhecht73@gmail.com \
    --to=mhecht73@googlemail.com \
    --cc=linux-media@vger.kernel.org \
    --cc=martin.hecht@avnet.com \
    --cc=mhecht73@gmail.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tomm.merciai@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.