Skip to content

Commit 981d7f9

Browse files
gwendalcrTzung-Bi Shih
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Tzung-Bi Shih <[email protected]>
1 parent 545daf9 commit 981d7f9

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

drivers/platform/chrome/cros_ec_sensorhub.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <linux/init.h>
1010
#include <linux/device.h>
11+
#include <linux/delay.h>
1112
#include <linux/mod_devicetable.h>
1213
#include <linux/module.h>
1314
#include <linux/platform_data/cros_ec_commands.h>
@@ -18,6 +19,7 @@
1819
#include <linux/types.h>
1920

2021
#define DRV_NAME "cros-ec-sensorhub"
22+
#define CROS_EC_CMD_INFO_RETRIES 50
2123

2224
static void cros_ec_sensorhub_free_sensor(void *arg)
2325
{
@@ -53,7 +55,7 @@ static int cros_ec_sensorhub_register(struct device *dev,
5355
int sensor_type[MOTIONSENSE_TYPE_MAX] = { 0 };
5456
struct cros_ec_command *msg = sensorhub->msg;
5557
struct cros_ec_dev *ec = sensorhub->ec;
56-
int ret, i;
58+
int ret, i, retries;
5759
char *name;
5860

5961

@@ -65,12 +67,25 @@ static int cros_ec_sensorhub_register(struct device *dev,
6567
sensorhub->params->cmd = MOTIONSENSE_CMD_INFO;
6668
sensorhub->params->info.sensor_num = i;
6769

68-
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
70+
retries = CROS_EC_CMD_INFO_RETRIES;
71+
do {
72+
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
73+
if (ret == -EBUSY) {
74+
/* The EC is still busy initializing sensors. */
75+
usleep_range(5000, 6000);
76+
retries--;
77+
}
78+
} while (ret == -EBUSY && retries);
79+
6980
if (ret < 0) {
70-
dev_warn(dev, "no info for EC sensor %d : %d/%d\n",
71-
i, ret, msg->result);
81+
dev_err(dev, "no info for EC sensor %d : %d/%d\n",
82+
i, ret, msg->result);
7283
continue;
7384
}
85+
if (retries < CROS_EC_CMD_INFO_RETRIES) {
86+
dev_warn(dev, "%d retries needed to bring up sensor %d\n",
87+
CROS_EC_CMD_INFO_RETRIES - retries, i);
88+
}
7489

7590
switch (sensorhub->resp->info.type) {
7691
case MOTIONSENSE_TYPE_ACCEL:

0 commit comments

Comments
 (0)