diff --git a/drivers/espi/host_subs_npcx.c b/drivers/espi/host_subs_npcx.c index 63d96fb336e..875e5b32959 100644 --- a/drivers/espi/host_subs_npcx.c +++ b/drivers/espi/host_subs_npcx.c @@ -235,9 +235,8 @@ static void host_kbc_ibf_isr(void *arg) * The high byte contains information from the host, and the lower byte * indicates if the host sent a command or data. 1 = Command. */ - evt.evt_data = (inst_kbc->HIKMDI << NPCX_8042_DATA_POS) | - (IS_BIT_SET(inst_kbc->HIKMST, NPCX_HIKMST_A2) << - NPCX_8042_TYPE_POS); + evt.evt_data = NPCX_8042_EVT_DATA(NPCX_8042_EVT_IBF, inst_kbc->HIKMDI, + IS_BIT_SET(inst_kbc->HIKMST, NPCX_HIKMST_A2)); LOG_DBG("%s: kbc data 0x%02x", __func__, evt.evt_data); espi_send_callbacks(host_sub_data.callbacks, host_sub_data.host_bus_dev, @@ -248,6 +247,9 @@ static void host_kbc_obe_isr(void *arg) { ARG_UNUSED(arg); struct kbc_reg *const inst_kbc = host_sub_cfg.inst_kbc; + struct espi_event evt = { ESPI_BUS_PERIPHERAL_NOTIFICATION, + ESPI_PERIPHERAL_8042_KBC, ESPI_PERIPHERAL_NODATA + }; /* Disable KBC OBE interrupt first */ inst_kbc->HICTRL &= ~BIT(NPCX_HICTRL_OBECIE); @@ -255,11 +257,13 @@ static void host_kbc_obe_isr(void *arg) LOG_DBG("%s: kbc status 0x%02x", __func__, inst_kbc->HIKMST); /* - * TODO: Notify application that host already read out data. We might - * use E8042_SET_FLAG in espi_api_lpc_write_request() instead of setting - * status of HIKMST here directly. + * Notify application that host already read out data. The application + * might need to clear status register via espi_api_lpc_write_request() + * with E8042_CLEAR_FLAG opcode in callback. */ - inst_kbc->HIKMST &= ~BIT(NPCX_HIKMST_ST1); + evt.evt_data = NPCX_8042_EVT_DATA(NPCX_8042_EVT_OBE, 0, 0); + espi_send_callbacks(host_sub_data.callbacks, host_sub_data.host_bus_dev, + evt); } static void host_kbc_init(void) diff --git a/soc/arm/nuvoton_npcx/common/soc_espi.h b/soc/arm/nuvoton_npcx/common/soc_espi.h index 54a8894e30a..97d32cadd35 100644 --- a/soc/arm/nuvoton_npcx/common/soc_espi.h +++ b/soc/arm/nuvoton_npcx/common/soc_espi.h @@ -12,9 +12,23 @@ extern "C" { #endif /* 8042 event data format */ +#define NPCX_8042_EVT_POS 16U #define NPCX_8042_DATA_POS 8U #define NPCX_8042_TYPE_POS 0U +/* 8042 event type format */ +#define NPCX_8042_EVT_IBF BIT(0) +#define NPCX_8042_EVT_OBE BIT(1) + +/* + * The format of event data for KBC 8042 protocol: + * [23:16] - 8042 event type: 1: Input buffer full, 2: Output buffer empty. + * [15:8] - 8042 data: 8-bit 8042 data. + * [0:7] - 8042 protocol type: 0: data type, 1: command type. + */ +#define NPCX_8042_EVT_DATA(event, data, type) (((event) << NPCX_8042_EVT_POS) \ + | ((data) << NPCX_8042_DATA_POS) | ((type) << NPCX_8042_TYPE_POS)); + /* ACPI event data format */ #define NPCX_ACPI_DATA_POS 8U #define NPCX_ACPI_TYPE_POS 0U