From dd22af992474fd58cad0fa6bc9768cc0919a51f8 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Mon, 24 Oct 2022 14:20:16 +0200 Subject: [PATCH 1/5] Add keyboard type check for old devices --- src/clevo_interfaces.h | 3 +++ src/clevo_leds.h | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/clevo_interfaces.h b/src/clevo_interfaces.h index 9077032..3666523 100644 --- a/src/clevo_interfaces.h +++ b/src/clevo_interfaces.h @@ -41,6 +41,9 @@ #define CLEVO_CMD_GET_EVENT 0x01 #define CLEVO_CMD_GET_SPECS 0x0D // Returns buffer -> only works with clevo_evaluate_method2 +#define CLEVO_CMD_GET_BIOS_FEATURES 0x52 +#define CLEVO_CMD_GET_BIOS_FEATURES_SUB_WHITE_ONLY_KB 0x40000000 +#define CLEVO_CMD_GET_BIOS_FEATURES_SUB_3_ZONE_RGB_KB 0x00400000 // The clevo set commands expect a parameter #define CLEVO_CMD_SET_FANSPEED_VALUE 0x68 diff --git a/src/clevo_leds.h b/src/clevo_leds.h index cb18c54..7070308 100644 --- a/src/clevo_leds.h +++ b/src/clevo_leds.h @@ -257,6 +257,7 @@ int clevo_leds_init(struct platform_device *dev) int ret; u32 status; union acpi_object *result; + u32 result_fallback; status = clevo_evaluate_method2(CLEVO_CMD_GET_SPECS, 0, &result); if (!status) { @@ -270,7 +271,21 @@ int clevo_leds_init(struct platform_device *dev) ACPI_FREE(result); } else { - pr_err("CLEVO_CMD_GET_SPECS failed\n"); + pr_notice("CLEVO_CMD_GET_SPECS does not exist on this device or failed, trying CLEVO_CMD_GET_BIOS_FEATURES\n"); + + // check for devices <= Intel 7th gen (only white only, 3 zone RGB, or no backlight on these devices) + status = clevo_evaluate_method(CLEVO_CMD_GET_BIOS_FEATURES, 0, &result_fallback); + if (!status) { + if (result_fallback & CLEVO_CMD_GET_BIOS_FEATURES_SUB_3_ZONE_RGB_KB) { + clevo_kb_backlight_type = CLEVO_KB_BACKLIGHT_TYPE_3_ZONE_RGB; + } + else if (result_fallback & CLEVO_CMD_GET_BIOS_FEATURES_SUB_WHITE_ONLY_KB) { + clevo_kb_backlight_type = CLEVO_KB_BACKLIGHT_TYPE_FIXED_COLOR; + } + } + else { + pr_notice("CLEVO_CMD_GET_BIOS_FEATURES failed\n"); + } } pr_debug("Keyboard backlight type: 0x%02x\n", clevo_kb_backlight_type); From c4b7644f83fe22e8ac73f725cc2fac4de9f0247c Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Mon, 24 Oct 2022 14:32:43 +0200 Subject: [PATCH 2/5] Fix if case logic --- src/clevo_leds.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/clevo_leds.h b/src/clevo_leds.h index 7070308..42bfdfd 100644 --- a/src/clevo_leds.h +++ b/src/clevo_leds.h @@ -266,13 +266,15 @@ int clevo_leds_init(struct platform_device *dev) clevo_kb_backlight_type = result->buffer.pointer[0x0f]; } else { - pr_err("CLEVO_CMD_GET_SPECS return value has wrong type\n"); + pr_err("CLEVO_CMD_GET_SPECS does not exist on this device or return value has wrong type, trying CLEVO_CMD_GET_BIOS_FEATURES\n"); + status = -EINVAL } ACPI_FREE(result); } else { pr_notice("CLEVO_CMD_GET_SPECS does not exist on this device or failed, trying CLEVO_CMD_GET_BIOS_FEATURES\n"); - + } + if (status) { // check for devices <= Intel 7th gen (only white only, 3 zone RGB, or no backlight on these devices) status = clevo_evaluate_method(CLEVO_CMD_GET_BIOS_FEATURES, 0, &result_fallback); if (!status) { @@ -284,7 +286,7 @@ int clevo_leds_init(struct platform_device *dev) } } else { - pr_notice("CLEVO_CMD_GET_BIOS_FEATURES failed\n"); + pr_notice("CLEVO_CMD_GET_BIOS_FEATURES does not exist on this device or failed\n"); } } pr_debug("Keyboard backlight type: 0x%02x\n", clevo_kb_backlight_type); From 8e2d526a8a572b44b587d060a703f1bbad1849fa Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Mon, 24 Oct 2022 14:33:50 +0200 Subject: [PATCH 3/5] Add missing ; --- src/clevo_leds.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clevo_leds.h b/src/clevo_leds.h index 42bfdfd..ab67098 100644 --- a/src/clevo_leds.h +++ b/src/clevo_leds.h @@ -267,7 +267,7 @@ int clevo_leds_init(struct platform_device *dev) } else { pr_err("CLEVO_CMD_GET_SPECS does not exist on this device or return value has wrong type, trying CLEVO_CMD_GET_BIOS_FEATURES\n"); - status = -EINVAL + status = -EINVAL; } ACPI_FREE(result); } From 55b6b5ce940caae0d9bf2b0c58651ea56c05c55f Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Mon, 24 Oct 2022 14:52:12 +0200 Subject: [PATCH 4/5] More debug output --- src/clevo_leds.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/clevo_leds.h b/src/clevo_leds.h index ab67098..ea77717 100644 --- a/src/clevo_leds.h +++ b/src/clevo_leds.h @@ -262,8 +262,8 @@ int clevo_leds_init(struct platform_device *dev) status = clevo_evaluate_method2(CLEVO_CMD_GET_SPECS, 0, &result); if (!status) { if (result->type == ACPI_TYPE_BUFFER) { - pr_debug("CLEVO_CMD_GET_SPECS successful\n"); - clevo_kb_backlight_type = result->buffer.pointer[0x0f]; + pr_debug("CLEVO_CMD_GET_SPECS result->buffer.pointer[0x0f]: 0x%02x\n", result->buffer.pointer[0x0f]); + clevo_kb_backlight_type = result->buffer.pointer[0x0f]; } else { pr_err("CLEVO_CMD_GET_SPECS does not exist on this device or return value has wrong type, trying CLEVO_CMD_GET_BIOS_FEATURES\n"); @@ -278,6 +278,7 @@ int clevo_leds_init(struct platform_device *dev) // check for devices <= Intel 7th gen (only white only, 3 zone RGB, or no backlight on these devices) status = clevo_evaluate_method(CLEVO_CMD_GET_BIOS_FEATURES, 0, &result_fallback); if (!status) { + pr_debug("CLEVO_CMD_GET_BIOS_FEATURES result_fallback: 0x%08x\n", result_fallback); if (result_fallback & CLEVO_CMD_GET_BIOS_FEATURES_SUB_3_ZONE_RGB_KB) { clevo_kb_backlight_type = CLEVO_KB_BACKLIGHT_TYPE_3_ZONE_RGB; } From fafba1181734ade65860d045f977f18fee36c50f Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Mon, 24 Oct 2022 15:09:13 +0200 Subject: [PATCH 5/5] Fix number of steps --- src/clevo_leds.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/clevo_leds.h b/src/clevo_leds.h index ea77717..30945bb 100644 --- a/src/clevo_leds.h +++ b/src/clevo_leds.h @@ -52,6 +52,7 @@ void clevo_leds_set_color_extern(u32 color); #define CLEVO_KBD_BRIGHTNESS_WHITE_MIN 0x00 #define CLEVO_KBD_BRIGHTNESS_WHITE_MAX 0x02 // White only keyboards can only be off, half, or full brightness +#define CLEVO_KBD_BRIGHTNESS_WHITE_MAX_OLD_DEVS 0x05 // Devices <= Intel 7th gen had a different white control with 5 brightness values + off #define CLEVO_KBD_BRIGHTNESS_WHITE_DEFAULT (CLEVO_KBD_BRIGHTNESS_WHITE_MAX * 0.5) #define CLEVO_KB_COLOR_DEFAULT_RED 0xff @@ -284,6 +285,7 @@ int clevo_leds_init(struct platform_device *dev) } else if (result_fallback & CLEVO_CMD_GET_BIOS_FEATURES_SUB_WHITE_ONLY_KB) { clevo_kb_backlight_type = CLEVO_KB_BACKLIGHT_TYPE_FIXED_COLOR; + clevo_led_cdev.max_brightness = CLEVO_KBD_BRIGHTNESS_WHITE_MAX_OLD_DEVS; } } else {