From eb4ded6925d147478fb75a4afcfb6534a2faaa5a Mon Sep 17 00:00:00 2001 From: Bill XIE Date: Thu, 26 Oct 2017 11:45:49 +0800 Subject: ec/acpi: add mechanisms to clear EC output queue EC's output could be considered as a queue, and sometimes (observed on Thinkpad T400s during cold boot) a few (only one observed) garbage bytes may detained in such queue after power up. Those garbage bytes should be checked and discarded first before real interactions, otherwise they may disrupt the interaction during EC's enablement, causing a locked rfkill. Change-Id: Iee031306c02f5211a4512c6b4ec90f7f0db196ae Signed-off-by: Bill XIE Reviewed-on: https://review.coreboot.org/22180 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Rudolph --- src/ec/acpi/ec.c | 15 +++++++++++++++ src/ec/acpi/ec.h | 1 + 2 files changed, 16 insertions(+) (limited to 'src/ec') diff --git a/src/ec/acpi/ec.c b/src/ec/acpi/ec.c index a739b98df3..61cad656eb 100644 --- a/src/ec/acpi/ec.c +++ b/src/ec/acpi/ec.c @@ -111,6 +111,21 @@ u8 recv_ec_data(void) return data; } +void ec_clear_out_queue(void) +{ + int timeout = 0x7fff; + printk(BIOS_SPEW, "Clearing EC output queue...\n"); + while (--timeout && (inb(ec_cmd_reg) & EC_OBF)) { + u8 data = inb(ec_data_reg); + printk(BIOS_SPEW, "Discarding a garbage byte: 0x%02x\n", data); + udelay(10); + } + if (!timeout) + printk(BIOS_ERR, "Timeout while clearing EC output queue!\n"); + else + printk(BIOS_SPEW, "EC output queue has been cleared.\n"); +} + u8 ec_read(u8 addr) { send_ec_command(0x80); diff --git a/src/ec/acpi/ec.h b/src/ec/acpi/ec.h index d9487e9015..48982d315e 100644 --- a/src/ec/acpi/ec.h +++ b/src/ec/acpi/ec.h @@ -40,6 +40,7 @@ int send_ec_command(u8 command); int send_ec_data(u8 data); int send_ec_data_nowait(u8 data); u8 recv_ec_data(void); +void ec_clear_out_queue(void); u8 ec_status(void); u8 ec_query(void); u8 ec_read(u8 addr); -- cgit v1.2.3