From 4dbaa4a83dcd44a47dd6928feedd70d089bab5fa Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Mon, 24 Oct 2022 16:10:44 +0200 Subject: [PATCH 1/2] Check available steps for white only --- src/clevo_interfaces.h | 9 ++++++--- src/clevo_leds.h | 26 ++++++++++++++++++-------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/clevo_interfaces.h b/src/clevo_interfaces.h index 3666523..fabeff5 100644 --- a/src/clevo_interfaces.h +++ b/src/clevo_interfaces.h @@ -41,9 +41,12 @@ #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 +#define CLEVO_CMD_GET_BIOS_FEATURES_1 0x52 +#define CLEVO_CMD_GET_BIOS_FEATURES_1_SUB_WHITE_ONLY_KB 0x40000000 +#define CLEVO_CMD_GET_BIOS_FEATURES_1_SUB_3_ZONE_RGB_KB 0x00400000 + +#define CLEVO_CMD_GET_BIOS_FEATURES_2 0x7A +#define CLEVO_CMD_GET_BIOS_FEATURES_2_SUB_WHITE_ONLY_KB_MAX_5 0x4000 // 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 30945bb..672c885 100644 --- a/src/clevo_leds.h +++ b/src/clevo_leds.h @@ -52,7 +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_MAX_5 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 @@ -273,23 +273,33 @@ int clevo_leds_init(struct platform_device *dev) 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"); + pr_notice("CLEVO_CMD_GET_SPECS does not exist on this device or failed, trying CLEVO_CMD_GET_BIOS_FEATURES_1\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); + status = clevo_evaluate_method(CLEVO_CMD_GET_BIOS_FEATURES_1, 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) { + pr_debug("CLEVO_CMD_GET_BIOS_FEATURES_1 result_fallback: 0x%08x\n", result_fallback); + if (result_fallback & CLEVO_CMD_GET_BIOS_FEATURES_1_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) { + else if (result_fallback & CLEVO_CMD_GET_BIOS_FEATURES_1_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; + + status = clevo_evaluate_method(CLEVO_CMD_GET_BIOS_FEATURES_2, 0, &result_fallback); + if (!status) { + pr_debug("CLEVO_CMD_GET_BIOS_FEATURES_2 result_fallback: 0x%08x\n", result_fallback); + if (result_fallback & CLEVO_CMD_GET_BIOS_FEATURES_2_SUB_WHITE_ONLY_KB_MAX_5) { + clevo_led_cdev.max_brightness = CLEVO_KBD_BRIGHTNESS_WHITE_MAX_5; + } + } + else { + pr_notice("CLEVO_CMD_GET_BIOS_FEATURES_2 does not exist on this device or failed\n"); + } } } else { - pr_notice("CLEVO_CMD_GET_BIOS_FEATURES does not exist on this device or failed\n"); + pr_notice("CLEVO_CMD_GET_BIOS_FEATURES_1 does not exist on this device or failed\n"); } } pr_debug("Keyboard backlight type: 0x%02x\n", clevo_kb_backlight_type); From 011ad1c5565c639a1dc6e22b74957fe5c361a5b3 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Mon, 24 Oct 2022 16:27:20 +0200 Subject: [PATCH 2/2] Fix default brightness --- src/clevo_leds.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/clevo_leds.h b/src/clevo_leds.h index 672c885..a0a7790 100644 --- a/src/clevo_leds.h +++ b/src/clevo_leds.h @@ -50,10 +50,11 @@ void clevo_leds_set_color_extern(u32 color); #define CLEVO_KBD_BRIGHTNESS_MAX 0xff #define CLEVO_KBD_BRIGHTNESS_DEFAULT (CLEVO_KBD_BRIGHTNESS_MAX * 0.5) -#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_5 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_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_DEFAULT (CLEVO_KBD_BRIGHTNESS_WHITE_MAX * 0.5) +#define CLEVO_KBD_BRIGHTNESS_WHITE_MAX_5 0x05 // Devices <= Intel 7th gen had a different white control with 5 brightness values + off +#define CLEVO_KBD_BRIGHTNESS_WHITE_MAX_5_DEFAULT (CLEVO_KBD_BRIGHTNESS_WHITE_MAX * 0.5) #define CLEVO_KB_COLOR_DEFAULT_RED 0xff #define CLEVO_KB_COLOR_DEFAULT_GREEN 0xff @@ -259,6 +260,7 @@ int clevo_leds_init(struct platform_device *dev) u32 status; union acpi_object *result; u32 result_fallback; + u8 default_brightness = CLEVO_KBD_BRIGHTNESS_DEFAULT; status = clevo_evaluate_method2(CLEVO_CMD_GET_SPECS, 0, &result); if (!status) { @@ -304,7 +306,11 @@ int clevo_leds_init(struct platform_device *dev) } pr_debug("Keyboard backlight type: 0x%02x\n", clevo_kb_backlight_type); - clevo_leds_set_brightness_extern(CLEVO_KBD_BRIGHTNESS_DEFAULT); + if (clevo_kb_backlight_type == CLEVO_KB_BACKLIGHT_TYPE_FIXED_COLOR) { + default_brightness = clevo_led_cdev.max_brightness / 2; + } + + clevo_leds_set_brightness_extern(default_brightness); clevo_leds_set_color_extern(CLEVO_KB_COLOR_DEFAULT); if (clevo_kb_backlight_type == CLEVO_KB_BACKLIGHT_TYPE_FIXED_COLOR) {