From e3eb9bedec7ea707d0fbc114baf1322b66e19a78 Mon Sep 17 00:00:00 2001 From: Jose Alberto Meza Date: Thu, 27 Aug 2020 14:48:10 -0700 Subject: [PATCH] samples: drivers: espi: Showcase how to handle lenghty boot initializations Add sample where a fictious lenghty operation is required before a more elaborate handshake is perform with eSPI master. This requires sending SLAVE_BOOT_DONE virtual wire explicitly. Signed-off-by: Jose Alberto Meza --- samples/drivers/espi/src/main.c | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/samples/drivers/espi/src/main.c b/samples/drivers/espi/src/main.c index 834d9974fad..e15905371a4 100644 --- a/samples/drivers/espi/src/main.c +++ b/samples/drivers/espi/src/main.c @@ -523,6 +523,25 @@ int get_pch_temp(struct device *dev, int *temp) return 0; } +#ifndef CONFIG_ESPI_AUTOMATIC_BOOT_DONE_ACKNOWLEDGE +static void send_slave_bootdone(void) +{ + int ret; + uint8_t boot_done; + + ret = espi_receive_vwire(espi_dev, ESPI_VWIRE_SIGNAL_SLV_BOOT_DONE, + &boot_done); + LOG_INF("%s boot_done: %d", __func__, boot_done); + if (ret) { + LOG_WRN("Fail to retrieve slave boot done"); + } else if (!boot_done) { + /* SLAVE_BOOT_DONE & SLAVE_LOAD_STS have to be sent together */ + espi_send_vwire(espi_dev, ESPI_VWIRE_SIGNAL_SLV_BOOT_STS, 1); + espi_send_vwire(espi_dev, ESPI_VWIRE_SIGNAL_SLV_BOOT_DONE, 1); + } +} +#endif + int espi_test(void) { int ret; @@ -601,6 +620,26 @@ int espi_test(void) return ret; } +#ifndef CONFIG_ESPI_AUTOMATIC_BOOT_DONE_ACKNOWLEDGE + /* When automatic acknowledge is disabled to perform lenghty operations + * in the eSPI slave, need to explicitly send slave boot + */ + bool vw_ch_sts; + + /* Simulate lenghty operation during boot */ + k_sleep(K_SECONDS(2)); + + do { + vw_ch_sts = espi_get_channel_status(espi_dev, + ESPI_CHANNEL_VWIRE); + k_busy_wait(100); + } while (!vw_ch_sts); + + + send_slave_bootdone(); +#endif + + #ifdef CONFIG_ESPI_FLASH_CHANNEL /* Flash operation need to be perform before VW handshake or * after eSPI host completes full initialization.