Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

platform/chrome: cros_ec_sensorhub: Retries when a sensor is not ready

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>
Link: https://lore.kernel.org/r/20250623210518.306740-1-gwendal@google.com
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>

authored by

Gwendal Grignou and committed by
Tzung-Bi Shih
981d7f91 545daf90

+19 -4
+19 -4
drivers/platform/chrome/cros_ec_sensorhub.c
··· 8 8 9 9 #include <linux/init.h> 10 10 #include <linux/device.h> 11 + #include <linux/delay.h> 11 12 #include <linux/mod_devicetable.h> 12 13 #include <linux/module.h> 13 14 #include <linux/platform_data/cros_ec_commands.h> ··· 19 18 #include <linux/types.h> 20 19 21 20 #define DRV_NAME "cros-ec-sensorhub" 21 + #define CROS_EC_CMD_INFO_RETRIES 50 22 22 23 23 static void cros_ec_sensorhub_free_sensor(void *arg) 24 24 { ··· 55 53 int sensor_type[MOTIONSENSE_TYPE_MAX] = { 0 }; 56 54 struct cros_ec_command *msg = sensorhub->msg; 57 55 struct cros_ec_dev *ec = sensorhub->ec; 58 - int ret, i; 56 + int ret, i, retries; 59 57 char *name; 60 58 61 59 ··· 67 65 sensorhub->params->cmd = MOTIONSENSE_CMD_INFO; 68 66 sensorhub->params->info.sensor_num = i; 69 67 70 - ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg); 68 + retries = CROS_EC_CMD_INFO_RETRIES; 69 + do { 70 + ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg); 71 + if (ret == -EBUSY) { 72 + /* The EC is still busy initializing sensors. */ 73 + usleep_range(5000, 6000); 74 + retries--; 75 + } 76 + } while (ret == -EBUSY && retries); 77 + 71 78 if (ret < 0) { 72 - dev_warn(dev, "no info for EC sensor %d : %d/%d\n", 73 - i, ret, msg->result); 79 + dev_err(dev, "no info for EC sensor %d : %d/%d\n", 80 + i, ret, msg->result); 74 81 continue; 82 + } 83 + if (retries < CROS_EC_CMD_INFO_RETRIES) { 84 + dev_warn(dev, "%d retries needed to bring up sensor %d\n", 85 + CROS_EC_CMD_INFO_RETRIES - retries, i); 75 86 } 76 87 77 88 switch (sensorhub->resp->info.type) {