Skip to content

Commit ddd73ca

Browse files
MulinChaonashif
authored andcommitted
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 <[email protected]>
1 parent eb52f98 commit ddd73ca

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

drivers/espi/host_subs_npcx.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,8 @@ static void host_kbc_ibf_isr(void *arg)
235235
* The high byte contains information from the host, and the lower byte
236236
* indicates if the host sent a command or data. 1 = Command.
237237
*/
238-
evt.evt_data = (inst_kbc->HIKMDI << NPCX_8042_DATA_POS) |
239-
(IS_BIT_SET(inst_kbc->HIKMST, NPCX_HIKMST_A2) <<
240-
NPCX_8042_TYPE_POS);
238+
evt.evt_data = NPCX_8042_EVT_DATA(NPCX_8042_EVT_IBF, inst_kbc->HIKMDI,
239+
IS_BIT_SET(inst_kbc->HIKMST, NPCX_HIKMST_A2));
241240

242241
LOG_DBG("%s: kbc data 0x%02x", __func__, evt.evt_data);
243242
espi_send_callbacks(host_sub_data.callbacks, host_sub_data.host_bus_dev,
@@ -248,18 +247,23 @@ static void host_kbc_obe_isr(void *arg)
248247
{
249248
ARG_UNUSED(arg);
250249
struct kbc_reg *const inst_kbc = host_sub_cfg.inst_kbc;
250+
struct espi_event evt = { ESPI_BUS_PERIPHERAL_NOTIFICATION,
251+
ESPI_PERIPHERAL_8042_KBC, ESPI_PERIPHERAL_NODATA
252+
};
251253

252254
/* Disable KBC OBE interrupt first */
253255
inst_kbc->HICTRL &= ~BIT(NPCX_HICTRL_OBECIE);
254256

255257
LOG_DBG("%s: kbc status 0x%02x", __func__, inst_kbc->HIKMST);
256258

257259
/*
258-
* TODO: Notify application that host already read out data. We might
259-
* use E8042_SET_FLAG in espi_api_lpc_write_request() instead of setting
260-
* status of HIKMST here directly.
260+
* Notify application that host already read out data. The application
261+
* might need to clear status register via espi_api_lpc_write_request()
262+
* with E8042_CLEAR_FLAG opcode in callback.
261263
*/
262-
inst_kbc->HIKMST &= ~BIT(NPCX_HIKMST_ST1);
264+
evt.evt_data = NPCX_8042_EVT_DATA(NPCX_8042_EVT_OBE, 0, 0);
265+
espi_send_callbacks(host_sub_data.callbacks, host_sub_data.host_bus_dev,
266+
evt);
263267
}
264268

265269
static void host_kbc_init(void)

soc/arm/nuvoton_npcx/common/soc_espi.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,23 @@ extern "C" {
1212
#endif
1313

1414
/* 8042 event data format */
15+
#define NPCX_8042_EVT_POS 16U
1516
#define NPCX_8042_DATA_POS 8U
1617
#define NPCX_8042_TYPE_POS 0U
1718

19+
/* 8042 event type format */
20+
#define NPCX_8042_EVT_IBF BIT(0)
21+
#define NPCX_8042_EVT_OBE BIT(1)
22+
23+
/*
24+
* The format of event data for KBC 8042 protocol:
25+
* [23:16] - 8042 event type: 1: Input buffer full, 2: Output buffer empty.
26+
* [15:8] - 8042 data: 8-bit 8042 data.
27+
* [0:7] - 8042 protocol type: 0: data type, 1: command type.
28+
*/
29+
#define NPCX_8042_EVT_DATA(event, data, type) (((event) << NPCX_8042_EVT_POS) \
30+
| ((data) << NPCX_8042_DATA_POS) | ((type) << NPCX_8042_TYPE_POS));
31+
1832
/* ACPI event data format */
1933
#define NPCX_ACPI_DATA_POS 8U
2034
#define NPCX_ACPI_TYPE_POS 0U

0 commit comments

Comments
 (0)