Skip to content

Commit eb5597e

Browse files
TomChang19kartben
authored andcommitted
drivers: espi: npcx: ensure the host receives the value from eSPI VW
This commit adds an option to verify weather the host has read the value after the wire 3-0 bits have been updated. Signed-off-by: Tom Chang <CHChang19@nuvoton.com>
1 parent 26c0300 commit eb5597e

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

drivers/espi/Kconfig.npcx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ config ESPI_NPCX_PERIPHERAL_DEBUG_PORT_80_RING_BUF_SIZE
6060
The size of the ring buffer in byte used by the Port80 ISR to store
6161
Postcodes from Host.
6262

63+
config ESPI_NPCX_VWIRE_ENABLE_SEND_CHECK
64+
bool "Check the value was read by host after wire bits changed"
65+
help
66+
This option enables the function to check whether the host has read the value
67+
after the wire data changes.
68+
69+
config ESPI_NPCX_WIRE_SEND_TIMEOUT_US
70+
int "eSPI virtual wire send timeout count"
71+
default 1000
72+
help
73+
The times to check status after sending the eSPI virtual wire signal. The unit
74+
is microseconds (µs).
75+
6376
config ESPI_TAF_NPCX
6477
bool "Nuvoton NPCX embedded controller (EC) ESPI TAF driver"
6578
depends on SOC_SERIES_NPCX4

drivers/espi/espi_npcx.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,9 +859,25 @@ static int espi_npcx_send_vwire(const struct device *dev,
859859
if (signal >= ESPI_VWIRE_SIGNAL_TARGET_GPIO_0) {
860860
SET_FIELD(inst->VWGPSM[reg_idx], NPCX_VWEVSM_WIRE, val);
861861
reg_val = inst->VWGPSM[reg_idx];
862+
863+
if (IS_ENABLED(CONFIG_ESPI_NPCX_VWIRE_ENABLE_SEND_CHECK)) {
864+
if (!WAIT_FOR(!IS_BIT_SET(inst->VWGPSM[reg_idx], NPCX_VWEVSM_DIRTY),
865+
CONFIG_ESPI_NPCX_WIRE_SEND_TIMEOUT_US, NULL)) {
866+
LOG_ERR("%s signal %d timeout", __func__, signal);
867+
return -ETIMEDOUT;
868+
}
869+
}
862870
} else {
863871
SET_FIELD(inst->VWEVSM[reg_idx], NPCX_VWEVSM_WIRE, val);
864872
reg_val = inst->VWEVSM[reg_idx];
873+
874+
if (IS_ENABLED(CONFIG_ESPI_NPCX_VWIRE_ENABLE_SEND_CHECK)) {
875+
if (!WAIT_FOR(!IS_BIT_SET(inst->VWEVSM[reg_idx], NPCX_VWEVSM_DIRTY),
876+
CONFIG_ESPI_NPCX_WIRE_SEND_TIMEOUT_US, NULL)) {
877+
LOG_ERR("%s signal %d timeout", __func__, signal);
878+
return -ETIMEDOUT;
879+
}
880+
}
865881
}
866882

867883
LOG_DBG("Send VW: %s%d 0x%08X", reg_name, reg_idx, reg_val);

soc/nuvoton/npcx/common/npcxn/include/reg_def.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ struct espi_reg {
727727
#define NPCX_VWEVSM_INDEX FIELD(8, 7)
728728
#define NPCX_VWEVSM_INDEX_EN 15
729729
#define NPCX_VWEVSM_BIT_VALID(n) (4+n)
730+
#define NPCX_VWEVSM_DIRTY 16
730731
#define NPCX_VWEVSM_HW_WIRE FIELD(24, 4)
731732
#define NPCX_VWGPSM_INDEX_EN 15
732733
#define NPCX_OOBCTL_OOB_FREE 0

0 commit comments

Comments
 (0)