public inbox for chrome-platform@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] platform: chromeos: sensorhub: retries when a sensor is not ready
@ 2025-06-23 21:05 Gwendal Grignou
  2025-06-24  2:58 ` Tzung-Bi Shih
  2025-06-24  2:59 ` Tzung-Bi Shih
  0 siblings, 2 replies; 3+ messages in thread
From: Gwendal Grignou @ 2025-06-23 21:05 UTC (permalink / raw)
  To: tzungbi; +Cc: chrome-platform, Gwendal Grignou

When the EC/ISH starts, it can take a while for all the sensors to be up
and running or declared broken.

If the sensor stack return -EBUSY when checking for sensor information,
retry up to 50 times.
It has been observed 100ms wait time is enough to have valid sensors
ready. It can take more time in case a sensor is really broken and is
not coming up.

Signed-off-by: Gwendal Grignou <gwendal@google.com>
---
 drivers/platform/chrome/cros_ec_sensorhub.c | 23 +++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_sensorhub.c b/drivers/platform/chrome/cros_ec_sensorhub.c
index 518152cb4ee10..c246640a9e7e7 100644
--- a/drivers/platform/chrome/cros_ec_sensorhub.c
+++ b/drivers/platform/chrome/cros_ec_sensorhub.c
@@ -8,6 +8,7 @@
 
 #include <linux/init.h>
 #include <linux/device.h>
+#include <linux/delay.h>
 #include <linux/module.h>
 #include <linux/platform_data/cros_ec_commands.h>
 #include <linux/platform_data/cros_ec_proto.h>
@@ -17,6 +18,7 @@
 #include <linux/types.h>
 
 #define DRV_NAME		"cros-ec-sensorhub"
+#define CROS_EC_CMD_INFO_RETRIES 50
 
 static void cros_ec_sensorhub_free_sensor(void *arg)
 {
@@ -52,7 +54,7 @@ static int cros_ec_sensorhub_register(struct device *dev,
 	int sensor_type[MOTIONSENSE_TYPE_MAX] = { 0 };
 	struct cros_ec_command *msg = sensorhub->msg;
 	struct cros_ec_dev *ec = sensorhub->ec;
-	int ret, i;
+	int ret, i, retries;
 	char *name;
 
 
@@ -64,12 +66,25 @@ static int cros_ec_sensorhub_register(struct device *dev,
 		sensorhub->params->cmd = MOTIONSENSE_CMD_INFO;
 		sensorhub->params->info.sensor_num = i;
 
-		ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+		retries = CROS_EC_CMD_INFO_RETRIES;
+		do {
+			ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+			if (ret == -EBUSY) {
+				/* The EC is still busy initializing sensors. */
+				usleep_range(5000, 6000);
+				retries--;
+			}
+		} while (ret == -EBUSY && retries);
+
 		if (ret < 0) {
-			dev_warn(dev, "no info for EC sensor %d : %d/%d\n",
-				 i, ret, msg->result);
+			dev_err(dev, "no info for EC sensor %d : %d/%d\n",
+				i, ret, msg->result);
 			continue;
 		}
+		if (retries < CROS_EC_CMD_INFO_RETRIES) {
+			dev_warn(dev, "%d retries needed to bring up sensor %d\n",
+				 CROS_EC_CMD_INFO_RETRIES - retries, i);
+		}
 
 		switch (sensorhub->resp->info.type) {
 		case MOTIONSENSE_TYPE_ACCEL:
-- 
2.50.0.rc2.761.g2dc52ea45b-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] platform: chromeos: sensorhub: retries when a sensor is not ready
  2025-06-23 21:05 [PATCH] platform: chromeos: sensorhub: retries when a sensor is not ready Gwendal Grignou
@ 2025-06-24  2:58 ` Tzung-Bi Shih
  2025-06-24  2:59 ` Tzung-Bi Shih
  1 sibling, 0 replies; 3+ messages in thread
From: Tzung-Bi Shih @ 2025-06-24  2:58 UTC (permalink / raw)
  To: Gwendal Grignou; +Cc: chrome-platform, Gwendal Grignou

On Mon, Jun 23, 2025 at 02:05:18PM -0700, Gwendal Grignou wrote:
>  drivers/platform/chrome/cros_ec_sensorhub.c | 23 +++++++++++++++++----

Please take `git log --oneline ...cros_ec_sensorhub.c` as examples for what
patch prefixes it could use next time.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] platform: chromeos: sensorhub: retries when a sensor is not ready
  2025-06-23 21:05 [PATCH] platform: chromeos: sensorhub: retries when a sensor is not ready Gwendal Grignou
  2025-06-24  2:58 ` Tzung-Bi Shih
@ 2025-06-24  2:59 ` Tzung-Bi Shih
  1 sibling, 0 replies; 3+ messages in thread
From: Tzung-Bi Shih @ 2025-06-24  2:59 UTC (permalink / raw)
  To: Gwendal Grignou; +Cc: chrome-platform, Gwendal Grignou

On Mon, Jun 23, 2025 at 02:05:18PM -0700, Gwendal Grignou wrote:
> When the EC/ISH starts, it can take a while for all the sensors to be up
> and running or declared broken.
> 
> If the sensor stack return -EBUSY when checking for sensor information,
> retry up to 50 times.
> It has been observed 100ms wait time is enough to have valid sensors
> ready. It can take more time in case a sensor is really broken and is
> not coming up.
> [...]

Applied to

    https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next

[1/1] platform: chromeos: sensorhub: retries when a sensor is not ready
      commit: 981d7f91aeda17424b29f033249f4fa7cd2a7556

Thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-06-24  2:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-23 21:05 [PATCH] platform: chromeos: sensorhub: retries when a sensor is not ready Gwendal Grignou
2025-06-24  2:58 ` Tzung-Bi Shih
2025-06-24  2:59 ` Tzung-Bi Shih

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox