From 32bc328f8b7b7cb74691c49ff3e080242e4341a1 Mon Sep 17 00:00:00 2001 From: Jay Vasanth Date: Tue, 8 Mar 2022 11:16:34 -0500 Subject: [PATCH] espi: mec172x kbc: Enable custom configs Enable custom configs for KBC IBF event data and KBC OBF callback from ISR. Signed-off-by: Jay Vasanth --- drivers/espi/Kconfig.xec_v2 | 14 ++++++++ drivers/espi/espi_mchp_xec_host_v2.c | 53 ++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/drivers/espi/Kconfig.xec_v2 b/drivers/espi/Kconfig.xec_v2 index 270dbec1ab1..fc5d042e708 100644 --- a/drivers/espi/Kconfig.xec_v2 +++ b/drivers/espi/Kconfig.xec_v2 @@ -154,3 +154,17 @@ config ESPI_PERIPHERAL_ACPI_EC_IBF_EVT_DATA to callback. endif #ESPI_XEC_V2 + +if ESPI_PERIPHERAL_8042_KBC + +config ESPI_PERIPHERAL_KBC_IBF_EVT_DATA + bool "KBC event data format in IBF" + help + Enable espi_evt_data_kbc format for encoding event in KBC IBF ISR + +config ESPI_PERIPHERAL_KBC_OBE_CBK + bool "KBC OBE Callback" + help + Enable KBC OBE callback from OBE ISR + +endif #ESPI_PERIPHERAL_8042_KBC diff --git a/drivers/espi/espi_mchp_xec_host_v2.c b/drivers/espi/espi_mchp_xec_host_v2.c index ad37f3766a2..328bf86c55b 100644 --- a/drivers/espi/espi_mchp_xec_host_v2.c +++ b/drivers/espi/espi_mchp_xec_host_v2.c @@ -191,7 +191,27 @@ static void kbc0_ibf_isr(const struct device *dev) struct espi_xec_data *const data = (struct espi_xec_data *const)dev->data; - +#ifdef CONFIG_ESPI_PERIPHERAL_KBC_IBF_EVT_DATA + /* Chrome solution */ + 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; + /* + * Indicates if the host sent a command or data. + * 0 = data + * 1 = Command. + */ + kbc_evt->type = kbc_hw->EC_KBC_STS & MCHP_KBC_STS_CD ? 1 : 0; + /* The data in KBC Input Buffer */ + kbc_evt->data = kbc_hw->EC_DATA; + /* KBC Input Buffer Full event */ + kbc_evt->evt = HOST_KBC_EVT_IBF; +#else + /* Windows solution */ /* The high byte contains information from the host, * and the lower byte speficies if the host sent * a command or data. 1 = Command. @@ -205,7 +225,7 @@ static void kbc0_ibf_isr(const struct device *dev) .evt_details = ESPI_PERIPHERAL_8042_KBC, .evt_data = isr_data }; - +#endif espi_send_callbacks(&data->callbacks, dev, evt); mchp_xec_ecia_info_girq_src_clr(xec_kbc0_cfg.ibf_ecia_info); @@ -213,8 +233,37 @@ static void kbc0_ibf_isr(const struct device *dev) static void kbc0_obe_isr(const struct device *dev) { +#ifdef CONFIG_ESPI_PERIPHERAL_KBC_OBE_CBK + /* Chrome solution */ + struct espi_xec_data *const data = + (struct espi_xec_data *const)dev->data; + + 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 */ + mchp_xec_ecia_info_girq_src_dis(xec_kbc0_cfg.obe_ecia_info); + + /* + * 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. + */ + kbc_evt->evt = HOST_KBC_EVT_OBE; + kbc_evt->data = 0; + kbc_evt->type = 0; + + espi_send_callbacks(&data->callbacks, dev, evt); +#else + /* Windows solution */ /* disable and clear GIRQ interrupt and status */ mchp_xec_ecia_info_girq_src_dis(xec_kbc0_cfg.obe_ecia_info); +#endif mchp_xec_ecia_info_girq_src_clr(xec_kbc0_cfg.obe_ecia_info); }