Skip to content

Commit cd3ccdc

Browse files
committed
espi/it8xxx2: waiting till completion of VW send to host
On it8xxx2, there are VW transmitted registers indicating that VW signal has been transmitted to host. This patch checks the register to ensure successful transmission of VW state change. fixes: #89298 Signed-off-by: Dino Li <Dino.Li@ite.com.tw>
1 parent 9a409d6 commit cd3ccdc

File tree

1 file changed

+56
-34
lines changed

1 file changed

+56
-34
lines changed

drivers/espi/espi_it8xxx2.c

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ struct espi_it8xxx2_data {
110110
};
111111

112112
struct vw_channel_t {
113-
uint8_t vw_index; /* VW index of signal */
114-
uint8_t level_mask; /* level bit of signal */
115-
uint8_t valid_mask; /* valid bit of signal */
113+
uint8_t vw_index; /* VW index of signal */
114+
uint8_t level_mask; /* level bit of signal */
115+
uint8_t valid_mask; /* valid bit of signal */
116+
uint8_t vw_sent_reg; /* vw signal sent to host */
116117
};
117118

118119
struct vwidx_isr_t {
@@ -587,41 +588,44 @@ static void pmc2_it8xxx2_init(const struct device *dev)
587588
}
588589
#endif
589590

591+
#define IT8XXX2_ESPI_VW_SEND_TIMEOUT_MS (USEC_PER_MSEC * 10)
592+
590593
/* eSPI api functions */
591-
#define VW_CHAN(signal, index, level, valid) \
592-
[signal] = {.vw_index = index, .level_mask = level, .valid_mask = valid}
594+
#define VW_CHAN(signal, index, level, valid, reg) \
595+
[signal] = {.vw_index = index, .level_mask = level, \
596+
.valid_mask = valid, .vw_sent_reg = reg}
593597

594598
/* VW signals used in eSPI */
595599
static const struct vw_channel_t vw_channel_list[] = {
596-
VW_CHAN(ESPI_VWIRE_SIGNAL_SLP_S3, 0x02, BIT(0), BIT(4)),
597-
VW_CHAN(ESPI_VWIRE_SIGNAL_SLP_S4, 0x02, BIT(1), BIT(5)),
598-
VW_CHAN(ESPI_VWIRE_SIGNAL_SLP_S5, 0x02, BIT(2), BIT(6)),
599-
VW_CHAN(ESPI_VWIRE_SIGNAL_OOB_RST_WARN, 0x03, BIT(2), BIT(6)),
600-
VW_CHAN(ESPI_VWIRE_SIGNAL_PLTRST, 0x03, BIT(1), BIT(5)),
601-
VW_CHAN(ESPI_VWIRE_SIGNAL_SUS_STAT, 0x03, BIT(0), BIT(4)),
602-
VW_CHAN(ESPI_VWIRE_SIGNAL_NMIOUT, 0x07, BIT(2), BIT(6)),
603-
VW_CHAN(ESPI_VWIRE_SIGNAL_SMIOUT, 0x07, BIT(1), BIT(5)),
604-
VW_CHAN(ESPI_VWIRE_SIGNAL_HOST_RST_WARN, 0x07, BIT(0), BIT(4)),
605-
VW_CHAN(ESPI_VWIRE_SIGNAL_SLP_A, 0x41, BIT(3), BIT(7)),
606-
VW_CHAN(ESPI_VWIRE_SIGNAL_SUS_PWRDN_ACK, 0x41, BIT(1), BIT(5)),
607-
VW_CHAN(ESPI_VWIRE_SIGNAL_SUS_WARN, 0x41, BIT(0), BIT(4)),
608-
VW_CHAN(ESPI_VWIRE_SIGNAL_SLP_WLAN, 0x42, BIT(1), BIT(5)),
609-
VW_CHAN(ESPI_VWIRE_SIGNAL_SLP_LAN, 0x42, BIT(0), BIT(4)),
610-
VW_CHAN(ESPI_VWIRE_SIGNAL_HOST_C10, 0x47, BIT(0), BIT(4)),
611-
VW_CHAN(ESPI_VWIRE_SIGNAL_DNX_WARN, 0x4a, BIT(1), BIT(5)),
612-
VW_CHAN(ESPI_VWIRE_SIGNAL_PME, 0x04, BIT(3), BIT(7)),
613-
VW_CHAN(ESPI_VWIRE_SIGNAL_WAKE, 0x04, BIT(2), BIT(6)),
614-
VW_CHAN(ESPI_VWIRE_SIGNAL_OOB_RST_ACK, 0x04, BIT(0), BIT(4)),
615-
VW_CHAN(ESPI_VWIRE_SIGNAL_TARGET_BOOT_STS, 0x05, BIT(3), BIT(7)),
616-
VW_CHAN(ESPI_VWIRE_SIGNAL_ERR_NON_FATAL, 0x05, BIT(2), BIT(6)),
617-
VW_CHAN(ESPI_VWIRE_SIGNAL_ERR_FATAL, 0x05, BIT(1), BIT(5)),
618-
VW_CHAN(ESPI_VWIRE_SIGNAL_TARGET_BOOT_DONE, 0x05, BIT(0), BIT(4)),
619-
VW_CHAN(ESPI_VWIRE_SIGNAL_HOST_RST_ACK, 0x06, BIT(3), BIT(7)),
620-
VW_CHAN(ESPI_VWIRE_SIGNAL_RST_CPU_INIT, 0x06, BIT(2), BIT(6)),
621-
VW_CHAN(ESPI_VWIRE_SIGNAL_SMI, 0x06, BIT(1), BIT(5)),
622-
VW_CHAN(ESPI_VWIRE_SIGNAL_SCI, 0x06, BIT(0), BIT(4)),
623-
VW_CHAN(ESPI_VWIRE_SIGNAL_DNX_ACK, 0x40, BIT(1), BIT(5)),
624-
VW_CHAN(ESPI_VWIRE_SIGNAL_SUS_ACK, 0x40, BIT(0), BIT(4)),
600+
VW_CHAN(ESPI_VWIRE_SIGNAL_SLP_S3, 0x02, BIT(0), BIT(4), 0),
601+
VW_CHAN(ESPI_VWIRE_SIGNAL_SLP_S4, 0x02, BIT(1), BIT(5), 0),
602+
VW_CHAN(ESPI_VWIRE_SIGNAL_SLP_S5, 0x02, BIT(2), BIT(6), 0),
603+
VW_CHAN(ESPI_VWIRE_SIGNAL_OOB_RST_WARN, 0x03, BIT(2), BIT(6), 0),
604+
VW_CHAN(ESPI_VWIRE_SIGNAL_PLTRST, 0x03, BIT(1), BIT(5), 0),
605+
VW_CHAN(ESPI_VWIRE_SIGNAL_SUS_STAT, 0x03, BIT(0), BIT(4), 0),
606+
VW_CHAN(ESPI_VWIRE_SIGNAL_NMIOUT, 0x07, BIT(2), BIT(6), 0),
607+
VW_CHAN(ESPI_VWIRE_SIGNAL_SMIOUT, 0x07, BIT(1), BIT(5), 0),
608+
VW_CHAN(ESPI_VWIRE_SIGNAL_HOST_RST_WARN, 0x07, BIT(0), BIT(4), 0),
609+
VW_CHAN(ESPI_VWIRE_SIGNAL_SLP_A, 0x41, BIT(3), BIT(7), 0),
610+
VW_CHAN(ESPI_VWIRE_SIGNAL_SUS_PWRDN_ACK, 0x41, BIT(1), BIT(5), 0),
611+
VW_CHAN(ESPI_VWIRE_SIGNAL_SUS_WARN, 0x41, BIT(0), BIT(4), 0),
612+
VW_CHAN(ESPI_VWIRE_SIGNAL_SLP_WLAN, 0x42, BIT(1), BIT(5), 0),
613+
VW_CHAN(ESPI_VWIRE_SIGNAL_SLP_LAN, 0x42, BIT(0), BIT(4), 0),
614+
VW_CHAN(ESPI_VWIRE_SIGNAL_HOST_C10, 0x47, BIT(0), BIT(4), 0),
615+
VW_CHAN(ESPI_VWIRE_SIGNAL_DNX_WARN, 0x4a, BIT(1), BIT(5), 0),
616+
VW_CHAN(ESPI_VWIRE_SIGNAL_PME, 0x04, BIT(3), BIT(7), 0xe1),
617+
VW_CHAN(ESPI_VWIRE_SIGNAL_WAKE, 0x04, BIT(2), BIT(6), 0xe1),
618+
VW_CHAN(ESPI_VWIRE_SIGNAL_OOB_RST_ACK, 0x04, BIT(0), BIT(4), 0xe1),
619+
VW_CHAN(ESPI_VWIRE_SIGNAL_TARGET_BOOT_STS, 0x05, BIT(3), BIT(7), 0xe2),
620+
VW_CHAN(ESPI_VWIRE_SIGNAL_ERR_NON_FATAL, 0x05, BIT(2), BIT(6), 0xe2),
621+
VW_CHAN(ESPI_VWIRE_SIGNAL_ERR_FATAL, 0x05, BIT(1), BIT(5), 0xe2),
622+
VW_CHAN(ESPI_VWIRE_SIGNAL_TARGET_BOOT_DONE, 0x05, BIT(0), BIT(4), 0xe2),
623+
VW_CHAN(ESPI_VWIRE_SIGNAL_HOST_RST_ACK, 0x06, BIT(3), BIT(7), 0xe3),
624+
VW_CHAN(ESPI_VWIRE_SIGNAL_RST_CPU_INIT, 0x06, BIT(2), BIT(6), 0xe3),
625+
VW_CHAN(ESPI_VWIRE_SIGNAL_SMI, 0x06, BIT(1), BIT(5), 0xe3),
626+
VW_CHAN(ESPI_VWIRE_SIGNAL_SCI, 0x06, BIT(0), BIT(4), 0xe3),
627+
VW_CHAN(ESPI_VWIRE_SIGNAL_DNX_ACK, 0x40, BIT(1), BIT(5), 0xe4),
628+
VW_CHAN(ESPI_VWIRE_SIGNAL_SUS_ACK, 0x40, BIT(0), BIT(4), 0xe4),
625629
};
626630

627631
static int espi_it8xxx2_configure(const struct device *dev,
@@ -704,6 +708,7 @@ static int espi_it8xxx2_send_vwire(const struct device *dev,
704708
uint8_t vw_index = vw_channel_list[signal].vw_index;
705709
uint8_t level_mask = vw_channel_list[signal].level_mask;
706710
uint8_t valid_mask = vw_channel_list[signal].valid_mask;
711+
uint8_t vw_sent = vw_channel_list[signal].vw_sent_reg;
707712

708713
if (signal > ARRAY_SIZE(vw_channel_list)) {
709714
return -EIO;
@@ -717,6 +722,23 @@ static int espi_it8xxx2_send_vwire(const struct device *dev,
717722

718723
vw_reg->VW_INDEX[vw_index] |= valid_mask;
719724

725+
if (espi_it8xxx2_channel_ready(dev, ESPI_CHANNEL_VWIRE) && vw_sent) {
726+
uint32_t timeout = 0;
727+
728+
/* Waiting till completion of VW send to host */
729+
while ((vw_reg->VW_INDEX[vw_index] !=
730+
sys_read8(config->base_espi_vw + vw_sent)) &&
731+
timeout < IT8XXX2_ESPI_VW_SEND_TIMEOUT_MS) {
732+
k_busy_wait(10);
733+
timeout += 10;
734+
}
735+
736+
if (timeout >= IT8XXX2_ESPI_VW_SEND_TIMEOUT_MS) {
737+
LOG_WRN("VW send to host has timed out vw[0x%x] = 0x%x",
738+
vw_index, vw_reg->VW_INDEX[vw_index]);
739+
}
740+
}
741+
720742
return 0;
721743
}
722744

0 commit comments

Comments
 (0)