From cef0d4a74a9d8f085bc873c72d50da0d41452a85 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Mon, 12 Jun 2023 19:05:53 +0200 Subject: [PATCH 1/5] Fix variable type --- src/uniwill_keyboard.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/uniwill_keyboard.h b/src/uniwill_keyboard.h index 332acd6..d255a25 100644 --- a/src/uniwill_keyboard.h +++ b/src/uniwill_keyboard.h @@ -122,8 +122,7 @@ EXPORT_SYMBOL(uniwill_write_ec_ram); int uniwill_write_ec_ram_with_retry(u16 address, u8 data, int retries) { - u32 status; - int i; + int status, i; u8 control_data; for (i = 0; i < retries; ++i) { From 587b95eb1b4fb360fa60055e0a6995bb80afd0e0 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Mon, 12 Jun 2023 19:06:34 +0200 Subject: [PATCH 2/5] Automatically correct ROMID --- src/uniwill_interfaces.h | 5 +++ src/uniwill_keyboard.h | 85 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/src/uniwill_interfaces.h b/src/uniwill_interfaces.h index 9273da7..9071906 100644 --- a/src/uniwill_interfaces.h +++ b/src/uniwill_interfaces.h @@ -70,6 +70,11 @@ typedef void (uniwill_event_callb_t)(u32); #define UW_EC_REG_FEATURES_1 0x0766 #define UW_EC_REG_FEATURES_1_BIT_1_ZONE_RGB_KB 0x04 +#define UW_EC_REG_ROMID_START 0x0770 +#define UW_EC_REG_ROMID_END 0x077d +#define UW_EC_REG_ROMID_SPECIAL_1 0x077e +#define UW_EC_REG_ROMID_SPECIAL_2 0x077f + struct uniwill_interface_t { char *string_id; uniwill_event_callb_t *event_callb; diff --git a/src/uniwill_keyboard.h b/src/uniwill_keyboard.h index d255a25..ab3f2e3 100644 --- a/src/uniwill_keyboard.h +++ b/src/uniwill_keyboard.h @@ -105,6 +105,22 @@ int uniwill_read_ec_ram(u16 address, u8 *data) } EXPORT_SYMBOL(uniwill_read_ec_ram); +int uniwill_read_ec_ram_with_retry(u16 address, u8 *data, int retries) +{ + int status, i; + + for (i = 0; i < retries; ++i) { + status = uniwill_read_ec_ram(address, data); + if (status != 0) { + pr_debug("uniwill_read_ec_ram(...) failed.\n"); + break; + } + } + + return status; +} +EXPORT_SYMBOL(uniwill_read_ec_ram_with_retry); + int uniwill_write_ec_ram(u16 address, u8 data) { int status; @@ -949,6 +965,73 @@ static ssize_t uw_charging_prio_store(struct device *child, return -EINVAL; } +static const u8 uw_romid_PH4PxX[14] = {0x0C, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + +static const struct dmi_system_id uw_sku_romid_table[] = { + { + .matches = { + DMI_MATCH(DMI_PRODUCT_SKU, "IBP1XI08MK1"), + }, + .driver_data = (void *)&uw_romid_PH4PxX + }, + {} +}; + +static int set_rom_id(void) { + int i, ret; + const struct dmi_system_id *uw_sku_romid; + const u8 *romid; + u8 data; + bool romid_false = false; + + uw_sku_romid = dmi_first_match(uw_sku_romid_table); + if (!uw_sku_romid) + return 0; + + romid = (const u8 *)uw_sku_romid->driver_data; + pr_debug("ROMID 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n", + romid[0], romid[1], romid[2], romid[3], romid[4], romid[5], romid[6], romid[7], + romid[8], romid[9], romid[10], romid[11], romid[12], romid[13]); + + for (i = 0; i < 14; ++i) { + ret = uniwill_read_ec_ram_with_retry(UW_EC_REG_ROMID_START + i, &data, 3); + if (ret) { + pr_debug("uniwill_read_ec_ram_with_retry(...) failed.\n"); + return ret; + } + pr_debug("ROMID index: %d, expected value: 0x%02X, actual value: 0x%02X\n", i, romid[i], data); + if (data != romid[i]) { + pr_debug("ROMID is false. Correcting...\n"); + romid_false = true; + break; + } + } + + if (romid_false) { + ret = uniwill_write_ec_ram_with_retry(UW_EC_REG_ROMID_SPECIAL_1, 0xA5, 3); + if (ret) { + pr_debug("uniwill_write_ec_ram_with_retry(...) failed.\n"); + return ret; + } + ret = uniwill_write_ec_ram_with_retry(UW_EC_REG_ROMID_SPECIAL_2, 0x78, 3); + if (ret) { + pr_debug("uniwill_write_ec_ram_with_retry(...) failed.\n"); + return ret; + } + for (i = 0; i < 14; ++i) { + ret = uniwill_write_ec_ram_with_retry(UW_EC_REG_ROMID_START + i, romid[i], 3); + if (ret) { + pr_debug("uniwill_write_ec_ram_with_retry(...) failed.\n"); + return ret; + } + } + } + else + pr_debug("ROMID is correct.\n"); + + return 0; +} + static int has_universal_ec_fan_control(void) { int ret; u8 data; @@ -1058,6 +1141,8 @@ static int uniwill_keyboard_probe(struct platform_device *dev) u8 data; int status; + set_rom_id(); + struct uniwill_device_features_t *uw_feats = uniwill_get_device_features(); // FIXME Hard set balanced profile until we have implemented a way to From 3d7d74a56588fd927c24f6b2d2d2757cd106e5ff Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Mon, 12 Jun 2023 19:16:11 +0200 Subject: [PATCH 3/5] Remove unused define --- src/uniwill_interfaces.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/uniwill_interfaces.h b/src/uniwill_interfaces.h index 9071906..628cf04 100644 --- a/src/uniwill_interfaces.h +++ b/src/uniwill_interfaces.h @@ -71,7 +71,6 @@ typedef void (uniwill_event_callb_t)(u32); #define UW_EC_REG_FEATURES_1_BIT_1_ZONE_RGB_KB 0x04 #define UW_EC_REG_ROMID_START 0x0770 -#define UW_EC_REG_ROMID_END 0x077d #define UW_EC_REG_ROMID_SPECIAL_1 0x077e #define UW_EC_REG_ROMID_SPECIAL_2 0x077f From e1d1e1349a5e72334c001087f47db861af9ec512 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Tue, 13 Jun 2023 14:56:16 +0200 Subject: [PATCH 4/5] Fix retry logic --- src/uniwill_keyboard.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uniwill_keyboard.h b/src/uniwill_keyboard.h index ab3f2e3..20dcc02 100644 --- a/src/uniwill_keyboard.h +++ b/src/uniwill_keyboard.h @@ -111,10 +111,10 @@ int uniwill_read_ec_ram_with_retry(u16 address, u8 *data, int retries) for (i = 0; i < retries; ++i) { status = uniwill_read_ec_ram(address, data); - if (status != 0) { + if (status != 0) pr_debug("uniwill_read_ec_ram(...) failed.\n"); + else break; - } } return status; From 33208b835942f13bae8c20306d42df245973b67d Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Tue, 13 Jun 2023 14:59:29 +0200 Subject: [PATCH 5/5] Add definitions --- src/uniwill_interfaces.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/uniwill_interfaces.h b/src/uniwill_interfaces.h index 628cf04..bb8b80c 100644 --- a/src/uniwill_interfaces.h +++ b/src/uniwill_interfaces.h @@ -36,6 +36,7 @@ #define UNIWILL_INTERFACE_WMI_STRID "uniwill_wmi" typedef int (uniwill_read_ec_ram_t)(u16, u8*); +typedef int (uniwill_read_ec_ram_with_retry_t)(u16, u8*, int); typedef int (uniwill_write_ec_ram_t)(u16, u8); typedef int (uniwill_write_ec_ram_with_retry_t)(u16, u8, int); typedef void (uniwill_event_callb_t)(u32); @@ -86,6 +87,7 @@ int uniwill_remove_interface(struct uniwill_interface_t *interface); uniwill_read_ec_ram_t uniwill_read_ec_ram; uniwill_write_ec_ram_t uniwill_write_ec_ram; uniwill_write_ec_ram_with_retry_t uniwill_write_ec_ram_with_retry; +uniwill_read_ec_ram_with_retry_t uniwill_read_ec_ram_with_retry; int uniwill_get_active_interface_id(char **id_str); #define UW_MODEL_PF5LUXG 0x09