From 230acf394012a34d8c4a967194523e9bbfc5b19d Mon Sep 17 00:00:00 2001 From: Christoffer Sandberg Date: Mon, 13 Feb 2023 12:13:04 +0100 Subject: [PATCH] uniwill_wmi: Restructure busy wait loop to include delay before read --- src/uniwill_wmi.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/uniwill_wmi.c b/src/uniwill_wmi.c index e7ea578..dd5c05d 100644 --- a/src/uniwill_wmi.c +++ b/src/uniwill_wmi.c @@ -124,6 +124,7 @@ static u32 uw_ec_read_addr_direct(u8 addr_low, u8 addr_high, union uw_ec_read_re { u32 result; u8 tmp, count, flags; + bool ready; mutex_lock(&uniwill_ec_lock); @@ -146,10 +147,11 @@ static u32 uw_ec_read_addr_direct(u8 addr_low, u8 addr_high, union uw_ec_read_re // Wait for ready flag count = UW_EC_WAIT_CYCLES; - ec_read(UNIWILL_EC_REG_FLAGS, &tmp); - while (((tmp & (1 << UNIWILL_EC_BIT_DRDY)) == 0) && count != 0) { + ready = false; + while (!ready && count != 0) { msleep(1); ec_read(UNIWILL_EC_REG_FLAGS, &tmp); + ready = (tmp & (1 << UNIWILL_EC_BIT_DRDY)) != 0; count -= 1; } @@ -178,6 +180,7 @@ static u32 uw_ec_write_addr_direct(u8 addr_low, u8 addr_high, u8 data_low, u8 da { u32 result = 0; u8 tmp, count, flags; + bool ready; mutex_lock(&uniwill_ec_lock); @@ -202,10 +205,11 @@ static u32 uw_ec_write_addr_direct(u8 addr_low, u8 addr_high, u8 data_low, u8 da // Wait for ready flag count = UW_EC_WAIT_CYCLES; - ec_read(UNIWILL_EC_REG_FLAGS, &tmp); - while (((tmp & (1 << UNIWILL_EC_BIT_DRDY)) == 0) && count != 0) { + ready = false; + while (!ready && count != 0) { msleep(1); ec_read(UNIWILL_EC_REG_FLAGS, &tmp); + ready = (tmp & (1 << UNIWILL_EC_BIT_DRDY)) != 0; count -= 1; }