driver: eSPI: unify the bit fields of ACPI/KBC event data

The KBC/ACPI event data is 4-byte in width and composed of
event/data/type fields. However, the field position is defined by each
chip vendor via macro and not unified in the current implementation.
The commit uses the structure bit field to define and unify the field
position. It helps the application access it with a common approach.

Signed-off-by: Jun Lin <CHLin56@nuvoton.com>
This commit is contained in:
Jun Lin 2021-07-26 11:11:09 +08:00 committed by Christopher Friedt
commit c51a4ecd42
3 changed files with 47 additions and 32 deletions

View file

@ -230,13 +230,19 @@ static void host_kbc_ibf_isr(void *arg)
struct espi_event evt = { ESPI_BUS_PERIPHERAL_NOTIFICATION,
ESPI_PERIPHERAL_8042_KBC, ESPI_PERIPHERAL_NODATA
};
struct espi_evt_data_kbc *kbc_evt =
(struct espi_evt_data_kbc *)&evt.evt_data;
/* KBC Input Buffer Full event */
kbc_evt->evt = HOST_KBC_EVT_IBF;
/* The data in KBC Input Buffer */
kbc_evt->data = inst_kbc->HIKMDI;
/*
* The high byte contains information from the host, and the lower byte
* indicates if the host sent a command or data. 1 = Command.
* Indicates if the host sent a command or data.
* 0 = data
* 1 = Command.
*/
evt.evt_data = NPCX_8042_EVT_DATA(NPCX_8042_EVT_IBF, inst_kbc->HIKMDI,
IS_BIT_SET(inst_kbc->HIKMST, NPCX_HIKMST_A2));
kbc_evt->type = 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,
@ -250,6 +256,8 @@ static void host_kbc_obe_isr(void *arg)
struct espi_event evt = { ESPI_BUS_PERIPHERAL_NOTIFICATION,
ESPI_PERIPHERAL_8042_KBC, ESPI_PERIPHERAL_NODATA
};
struct espi_evt_data_kbc *kbc_evt =
(struct espi_evt_data_kbc *)&evt.evt_data;
/* Disable KBC OBE interrupt first */
inst_kbc->HICTRL &= ~BIT(NPCX_HICTRL_OBECIE);
@ -261,7 +269,10 @@ static void host_kbc_obe_isr(void *arg)
* might need to clear status register via espi_api_lpc_write_request()
* with E8042_CLEAR_FLAG opcode in callback.
*/
evt.evt_data = NPCX_8042_EVT_DATA(NPCX_8042_EVT_OBE, 0, 0);
kbc_evt->evt = HOST_KBC_EVT_OBE;
kbc_evt->data = 0;
kbc_evt->type = 0;
espi_send_callbacks(host_sub_data.callbacks, host_sub_data.host_bus_dev,
evt);
}
@ -301,16 +312,19 @@ static void host_acpi_process_input_data(uint8_t data)
.evt_details = ESPI_PERIPHERAL_HOST_IO,
.evt_data = ESPI_PERIPHERAL_NODATA
};
struct espi_evt_data_acpi *acpi_evt =
(struct espi_evt_data_acpi *)&evt.evt_data;
LOG_DBG("%s: acpi data 0x%02x", __func__, data);
/*
* The high byte contains information from the host, and the lower byte
* indicates if the host sent a command or data. 1 = Command.
* Indicates if the host sent a command or data.
* 0 = data
* 1 = Command.
*/
evt.evt_data = (data << NPCX_ACPI_DATA_POS) |
(IS_BIT_SET(inst_acpi->HIPMST, NPCX_HIPMST_CMD) <<
NPCX_ACPI_TYPE_POS);
acpi_evt->type = IS_BIT_SET(inst_acpi->HIPMST, NPCX_HIPMST_CMD);
acpi_evt->data = data;
espi_send_callbacks(host_sub_data.callbacks, host_sub_data.host_bus_dev,
evt);
}

View file

@ -253,6 +253,29 @@ enum lpc_peripheral_opcode {
#endif /* CONFIG_ESPI_PERIPHERAL_CUSTOM_OPCODE */
};
/* KBC 8042 event: Input Buffer Full */
#define HOST_KBC_EVT_IBF BIT(0)
/* KBC 8042 event: Output Buffer Empty */
#define HOST_KBC_EVT_OBE BIT(1)
/**
* @brief Bit field definition of evt_data in struct espi_event for KBC.
*/
struct espi_evt_data_kbc {
uint32_t type:8;
uint32_t data:8;
uint32_t evt:8;
uint32_t reserved:8;
};
/**
* @brief Bit field definition of evt_data in struct espi_event for ACPI.
*/
struct espi_evt_data_acpi {
uint32_t type:8;
uint32_t data:8;
uint32_t reserved:16;
};
/**
* @brief eSPI event
*/

View file

@ -14,28 +14,6 @@
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
/**
* @brief Turn on all interrupts of eSPI host interface module.
*