Skip to content

Commit de3da0e

Browse files
TomChang19kartben
authored andcommitted
drivers: espi: npcx: update the arbitration for eSPI TAF access
This commit adds the arbitration when EC and eSPI TAF access flash simultaneously. Signed-off-by: Tom Chang <[email protected]>
1 parent ec1b384 commit de3da0e

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

drivers/espi/Kconfig.npcx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ config ESPI_TAF_NPCX_RPMC_SUPPORT
9898
help
9999
This option enable the handler for eSPI TAF RPMC request.
100100

101+
config ESPI_TAF_NPCX_STS_AWAIT_TIMEOUT
102+
int "A timeout value in microseconds to wait for automatic read status"
103+
depends on ESPI_TAF_NPCX
104+
default 20000
105+
help
106+
This option specifies the timeout value in microseconds (us) for checking
107+
automatic read status.
108+
101109
# The default value 'y' for the existing options if ESPI_NPCX is selected.
102110
if ESPI_NPCX
103111

drivers/espi/espi_taf_npcx.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,38 @@ static void espi_taf_event_handler(const struct device *dev, struct espi_callbac
666666
k_work_submit(&npcx_espi_taf_data.work);
667667
}
668668

669+
int espi_taf_npcx_block(const struct device *dev, bool en_block)
670+
{
671+
struct espi_reg *const inst = HAL_INSTANCE(dev);
672+
673+
if (!IS_BIT_SET(inst->FLASHCTL, NPCX_FLASHCTL_SAF_AUTO_READ)) {
674+
return 0;
675+
}
676+
677+
if (en_block) {
678+
if (WAIT_FOR(!IS_BIT_SET(inst->ESPISTS, NPCX_ESPISTS_FLAUTORDREQ),
679+
CONFIG_ESPI_TAF_NPCX_STS_AWAIT_TIMEOUT, NULL) == false) {
680+
LOG_ERR("Check Automatic Read Queue Empty Timeout");
681+
return -ETIMEDOUT;
682+
}
683+
684+
inst->FLASHCTL |= BIT(NPCX_FLASHCTL_AUTO_RD_DIS_CTL);
685+
686+
if (WAIT_FOR(IS_BIT_SET(inst->ESPISTS, NPCX_ESPISTS_AUTO_RD_DIS_STS),
687+
CONFIG_ESPI_TAF_NPCX_STS_AWAIT_TIMEOUT, NULL) == false) {
688+
inst->FLASHCTL &= ~BIT(NPCX_FLASHCTL_AUTO_RD_DIS_CTL);
689+
inst->ESPISTS |= BIT(NPCX_ESPISTS_AUTO_RD_DIS_STS);
690+
LOG_ERR("Check Automatic Read Disable Timeout");
691+
return -ETIMEDOUT;
692+
}
693+
} else {
694+
inst->FLASHCTL &= ~BIT(NPCX_FLASHCTL_AUTO_RD_DIS_CTL);
695+
inst->ESPISTS |= BIT(NPCX_ESPISTS_AUTO_RD_DIS_STS);
696+
}
697+
698+
return 0;
699+
}
700+
669701
int npcx_init_taf(const struct device *dev, sys_slist_t *callbacks)
670702
{
671703
espi_init_callback(&espi_taf_cb, espi_taf_event_handler, ESPI_BUS_TAF_NOTIFICATION);

soc/nuvoton/npcx/common/reg/reg_def.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ struct espi_reg {
753753
#define NPCX_ESPISTS_VWUPD 8
754754
#define NPCX_ESPISTS_ESPIRST 9
755755
#define NPCX_ESPISTS_PLTRST 10
756+
#define NPCX_ESPISTS_FLAUTORDREQ 14
756757
#define NPCX_ESPISTS_AMERR 15
757758
#define NPCX_ESPISTS_AMDONE 16
758759
#define NPCX_ESPISTS_VWUPDW 17
@@ -762,6 +763,7 @@ struct espi_reg {
762763
#define NPCX_ESPISTS_BMBURSTERR 22
763764
#define NPCX_ESPISTS_BMBURSTDONE 23
764765
#define NPCX_ESPISTS_ESPIRST_LVL 24
766+
#define NPCX_ESPISTS_AUTO_RD_DIS_STS 29
765767
#define NPCX_VWSWIRQ_IRQ_NUM FIELD(0, 7)
766768
#define NPCX_VWSWIRQ_IRQ_LVL 7
767769
#define NPCX_VWSWIRQ_INDEX FIELD(8, 7)

soc/nuvoton/npcx/common/soc_espi_taf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ struct npcx_taf_head {
151151

152152
int npcx_init_taf(const struct device *dev, sys_slist_t *callbacks);
153153

154+
int espi_taf_npcx_block(const struct device *dev, bool en_block);
155+
154156
#ifdef __cplusplus
155157
}
156158
#endif

0 commit comments

Comments
 (0)