driver: espi: add more KBC 8042 support in npcx series.

This CL added more additional details for KBC (Keyboard and Mouse
Controller) bus in espi_event structure. It helps the application to
handle different 8042 events in the callback function.

The format of event data for KBC 8042 protocol is:
[23:16] - 8042 event type: 1: Input buf full, 2: Output buf empty.
[15:8]  - 8042 data: 8-bit 8042 data.
[0:7]   - 8042 protocol type: 0: data type, 1: command type.

Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
This commit is contained in:
Mulin Chao 2021-01-28 23:45:17 -08:00 committed by Anas Nashif
commit ddd73ca508
2 changed files with 25 additions and 7 deletions

View file

@ -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)

View file

@ -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