From 2c36616dd2b264cff6fde65c4ebea18ecd4fbc15 Mon Sep 17 00:00:00 2001 From: Aditya Bhutada Date: Mon, 14 Apr 2025 14:14:57 -0700 Subject: [PATCH] drivers: espi: espi_mchp_xec: Fix the VW change check time Adjusted the VW change check timings: - Polling time changed from 100 uSec to 1 uSec. - Timeout value changed from 10 mSec to 1 mSec. This is to achieve the lowest possible pulse width for SCI VW in S0, while ensuring that the VW change check is still reliable for S0iX where SoC may take longer to process upstream events. Also added -ETIMEDOUT error when failure. Signed-off-by: Aditya Bhutada --- drivers/espi/espi_mchp_xec.c | 13 +++++++++---- drivers/espi/espi_mchp_xec_v2.c | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/espi/espi_mchp_xec.c b/drivers/espi/espi_mchp_xec.c index a609c7a8921..01103e31bd4 100644 --- a/drivers/espi/espi_mchp_xec.c +++ b/drivers/espi/espi_mchp_xec.c @@ -19,9 +19,9 @@ #define ESPI_XEC_VWIRE_ACK_DELAY 10ul /* Maximum timeout to transmit a virtual wire packet. - * 10 ms expressed in multiples of 100us + * 1 ms expressed in multiples of 1us */ -#define ESPI_XEC_VWIRE_SEND_TIMEOUT 100ul +#define ESPI_XEC_VWIRE_SEND_TIMEOUT 1000ul #define VW_MAX_GIRQS 2ul @@ -461,10 +461,15 @@ static int espi_xec_send_vwire(const struct device *dev, /* Ensure eSPI virtual wire packet is transmitted * There is no interrupt, so need to poll register */ - uint8_t rd_cnt = ESPI_XEC_VWIRE_SEND_TIMEOUT; + uint16_t rd_cnt = ESPI_XEC_VWIRE_SEND_TIMEOUT; while (reg->SRC_CHG && rd_cnt--) { - k_busy_wait(100); + k_busy_wait(1); + } + + if (rd_cnt == 0) { + LOG_ERR("VW %d send timeout", signal); + return -ETIMEDOUT; } } diff --git a/drivers/espi/espi_mchp_xec_v2.c b/drivers/espi/espi_mchp_xec_v2.c index 22410a7f619..e4f315438be 100644 --- a/drivers/espi/espi_mchp_xec_v2.c +++ b/drivers/espi/espi_mchp_xec_v2.c @@ -25,9 +25,9 @@ #define ESPI_XEC_VWIRE_ACK_DELAY 10ul /* Maximum timeout to transmit a virtual wire packet. - * 10 ms expressed in multiples of 100us + * 1 ms expressed in multiples of 1us */ -#define ESPI_XEC_VWIRE_SEND_TIMEOUT 100ul +#define ESPI_XEC_VWIRE_SEND_TIMEOUT 1000ul #define VW_MAX_GIRQS 2ul @@ -325,10 +325,15 @@ static int espi_xec_send_vwire(const struct device *dev, /* Ensure eSPI virtual wire packet is transmitted * There is no interrupt, so need to poll register */ - uint8_t rd_cnt = ESPI_XEC_VWIRE_SEND_TIMEOUT; + uint16_t rd_cnt = ESPI_XEC_VWIRE_SEND_TIMEOUT; while (sys_read8(regaddr + SMVW_BI_SRC_CHG) && rd_cnt--) { - k_busy_wait(100); + k_busy_wait(1); + } + + if (rd_cnt == 0) { + LOG_ERR("VW %d send timeout", signal); + return -ETIMEDOUT; } }