[PATCH v2 03/13] platform/chrome: Allow transport-specific LPC response timeouts

From: Wang Yang

Date: Thu Dec 03 2026 - 23:21:42 EST


Preserve the LPC default of one second and -EIO. Let a transport
supply a deadline and timeout error without copying the polling loop.

Prepared with OpenAI Codex assistance.

Signed-off-by: Wang Yang <yang.wang@xxxxxxxxxxxxxxxx>
---
drivers/platform/chrome/cros_ec_lpc_proto.c | 9 +++++----
drivers/platform/chrome/cros_ec_lpc_proto.h | 4 ++++
2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_lpc_proto.c b/drivers/platform/chrome/cros_ec_lpc_proto.c
index 1dfc32a6ecd7..f0bd70e70a9c 100644
--- a/drivers/platform/chrome/cros_ec_lpc_proto.c
+++ b/drivers/platform/chrome/cros_ec_lpc_proto.c
@@ -13,7 +13,8 @@
static int ec_response_timed_out(struct cros_ec_device *ec,
const struct cros_ec_lpc_io *io)
{
- unsigned long one_second = jiffies + HZ;
+ unsigned long timeout = jiffies + (io->response_timeout_ms ?
+ msecs_to_jiffies(io->response_timeout_ms) : HZ);
u8 data;
int ret;

@@ -25,7 +26,7 @@ static int ec_response_timed_out(struct cros_ec_device *ec,
if (!(data & EC_LPC_STATUS_BUSY_MASK))
return 0;
usleep_range(100, 200);
- } while (time_before(jiffies, one_second));
+ } while (time_before(jiffies, timeout));

return 1;
}
@@ -59,7 +60,7 @@ int cros_ec_lpc_pkt_xfer(struct cros_ec_device *ec,
goto done;
if (ret) {
dev_warn(ec->dev, "EC response timed out\n");
- ret = -EIO;
+ ret = io->timeout_error ?: -EIO;
goto done;
}

@@ -158,7 +159,7 @@ int cros_ec_lpc_cmd_xfer(struct cros_ec_device *ec,
goto done;
if (ret) {
dev_warn(ec->dev, "EC response timed out\n");
- ret = -EIO;
+ ret = io->timeout_error ?: -EIO;
goto done;
}

diff --git a/drivers/platform/chrome/cros_ec_lpc_proto.h b/drivers/platform/chrome/cros_ec_lpc_proto.h
index 7f884ffe823a..9276fb09807d 100644
--- a/drivers/platform/chrome/cros_ec_lpc_proto.h
+++ b/drivers/platform/chrome/cros_ec_lpc_proto.h
@@ -11,12 +11,16 @@ struct cros_ec_command;
* struct cros_ec_lpc_io - byte access to an LPC-style EC interface
* @read: Read bytes, returning their checksum or a negative error.
* @write: Write bytes, returning their checksum or a negative error.
+ * @response_timeout_ms: Response timeout in milliseconds, or zero for one second.
+ * @timeout_error: Negative timeout error, or zero for the LPC default (-EIO).
*/
struct cros_ec_lpc_io {
int (*read)(struct cros_ec_device *ec, unsigned int offset,
unsigned int length, u8 *dest);
int (*write)(struct cros_ec_device *ec, unsigned int offset,
unsigned int length, const u8 *src);
+ unsigned int response_timeout_ms;
+ int timeout_error;
};

int cros_ec_lpc_pkt_xfer(struct cros_ec_device *ec,
--
2.43.0