From 1d5f679f66da090beb7e7a6de0c8b052d6b17308 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Wed, 31 Aug 2022 19:05:04 +0200 Subject: [PATCH] Fix white only keyboards --- src/clevo_interfaces.h | 4 +-- src/clevo_keyboard.h | 4 +-- src/clevo_leds.h | 57 +++++++++++++++++++++++++----------------- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/clevo_interfaces.h b/src/clevo_interfaces.h index 50d327b..9077032 100644 --- a/src/clevo_interfaces.h +++ b/src/clevo_interfaces.h @@ -50,10 +50,10 @@ #define CLEVO_CMD_SET_FLIGHTMODE_SW 0x20 #define CLEVO_CMD_SET_TOUCHPAD_SW 0x2a -#define CLEVO_CMD_SET_KB_LEDS 0x67 // used to set color, brightness, blinking pattern, etc. - #define CLEVO_CMD_SET_EVENTS_ENABLED 0x46 +#define CLEVO_CMD_SET_KB_WHITE_LEDS 0x27 // Set brightness of single color keyboard backlights +#define CLEVO_CMD_SET_KB_RGB_LEDS 0x67 // Used to set color, brightness, blinking pattern, etc. #define CLEVO_CMD_SET_KB_LEDS_SUB_RGB_ZONE_0 0xF0000000 // 1-zone RGB and 3-zone RGB left #define CLEVO_CMD_SET_KB_LEDS_SUB_RGB_ZONE_1 0xF1000000 // 3-zone RGB center #define CLEVO_CMD_SET_KB_LEDS_SUB_RGB_ZONE_2 0xF2000000 // 3-Zone RGB right diff --git a/src/clevo_keyboard.h b/src/clevo_keyboard.h index 6dfd0bb..f68dbda 100644 --- a/src/clevo_keyboard.h +++ b/src/clevo_keyboard.h @@ -163,7 +163,7 @@ static int set_enabled_cmd(u8 state) cmd |= 0x07F001; } - return clevo_evaluate_method(CLEVO_CMD_SET_KB_LEDS, cmd, NULL); + return clevo_evaluate_method(CLEVO_CMD_SET_KB_RGB_LEDS, cmd, NULL); } static void set_next_color_whole_kb(void) @@ -190,7 +190,7 @@ static void set_kbd_backlight_mode(u8 kbd_backlight_mode) { TUXEDO_INFO("Set keyboard backlight mode on %s", kbd_backlight_modes[kbd_backlight_mode].name); - if (!clevo_evaluate_method(CLEVO_CMD_SET_KB_LEDS, kbd_backlight_modes[kbd_backlight_mode].value, NULL)) { + if (!clevo_evaluate_method(CLEVO_CMD_SET_KB_RGB_LEDS, kbd_backlight_modes[kbd_backlight_mode].value, NULL)) { // method was succesfull so update ur internal state struct kbd_led_state.mode = kbd_backlight_mode; } diff --git a/src/clevo_leds.h b/src/clevo_leds.h index f187488..65164d7 100644 --- a/src/clevo_leds.h +++ b/src/clevo_leds.h @@ -46,14 +46,18 @@ void clevo_leds_set_color_extern(u32 color); #include #include -#define CLEVO_KBD_BRIGHTNESS_MIN 0x00 -#define CLEVO_KBD_BRIGHTNESS_MAX 0xff -#define CLEVO_KBD_BRIGHTNESS_DEFAULT (CLEVO_KBD_BRIGHTNESS_MAX * 0.5) +#define CLEVO_KBD_BRIGHTNESS_MIN 0x00 +#define CLEVO_KBD_BRIGHTNESS_MAX 0xff +#define CLEVO_KBD_BRIGHTNESS_DEFAULT (CLEVO_KBD_BRIGHTNESS_MAX * 0.5) -#define CLEVO_KB_COLOR_DEFAULT_RED 0xff -#define CLEVO_KB_COLOR_DEFAULT_GREEN 0xff -#define CLEVO_KB_COLOR_DEFAULT_BLUE 0xff -#define CLEVO_KB_COLOR_DEFAULT ((CLEVO_KB_COLOR_DEFAULT_RED << 16) + (CLEVO_KB_COLOR_DEFAULT_GREEN << 8) + CLEVO_KB_COLOR_DEFAULT_BLUE) +#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_KB_COLOR_DEFAULT_RED 0xff +#define CLEVO_KB_COLOR_DEFAULT_GREEN 0xff +#define CLEVO_KB_COLOR_DEFAULT_BLUE 0xff +#define CLEVO_KB_COLOR_DEFAULT ((CLEVO_KB_COLOR_DEFAULT_RED << 16) + (CLEVO_KB_COLOR_DEFAULT_GREEN << 8) + CLEVO_KB_COLOR_DEFAULT_BLUE) // The very first Clevos with keyboard backlight did have fixed color, but not yet the CLEVO_METHOD_ID_GET_SPECS. To // not break these, we set this as default for the time being, better having an extra sysfs entry without function than @@ -61,27 +65,34 @@ void clevo_leds_set_color_extern(u32 color); static enum clevo_kb_backlight_types clevo_kb_backlight_type = CLEVO_KB_BACKLIGHT_TYPE_FIXED_COLOR; static bool leds_initiaized; -static int clevo_evaluate_set_brightness(u8 brightness) +static int clevo_evaluate_set_white_brightness(u8 brightness) { - pr_debug("Set brightness on %d\n", brightness); + pr_debug("Set white brightness on %d\n", brightness); - return clevo_evaluate_method (CLEVO_CMD_SET_KB_LEDS, CLEVO_CMD_SET_KB_LEDS_SUB_RGB_BRIGHTNESS | brightness, NULL); + return clevo_evaluate_method (CLEVO_CMD_SET_KB_WHITE_LEDS, brightness, NULL); } -static int clevo_evaluate_set_color(u32 zone, u32 color) +static int clevo_evaluate_set_rgb_brightness(u8 brightness) +{ + pr_debug("Set RGB brightness on %d\n", brightness); + + return clevo_evaluate_method (CLEVO_CMD_SET_KB_RGB_LEDS, CLEVO_CMD_SET_KB_LEDS_SUB_RGB_BRIGHTNESS | brightness, NULL); +} + +static int clevo_evaluate_set_rgb_color(u32 zone, u32 color) { u32 cset = ((color & 0x0000FF) << 16) | ((color & 0xFF0000) >> 8) | ((color & 0x00FF00) >> 8); u32 clevo_submethod_arg = zone | cset; pr_debug("Set Color 0x%08x for region 0x%08x\n", color, zone); - return clevo_evaluate_method(CLEVO_CMD_SET_KB_LEDS, clevo_submethod_arg, NULL); + return clevo_evaluate_method(CLEVO_CMD_SET_KB_RGB_LEDS, clevo_submethod_arg, NULL); } static void clevo_leds_set_brightness(struct led_classdev *led_cdev __always_unused, enum led_brightness brightness) { - int ret = clevo_evaluate_set_brightness(brightness); + int ret = clevo_evaluate_set_white_brightness(brightness); if (ret) { - pr_debug("clevo_leds_set_brightness(): clevo_evaluate_set_brightness() failed\n"); + pr_debug("clevo_leds_set_brightness(): clevo_evaluate_set_white_brightness() failed\n"); return; } led_cdev->brightness = brightness; @@ -105,9 +116,9 @@ static void clevo_leds_set_brightness(struct led_classdev *led_cdev __always_unu (mcled_cdev->subled_info[1].brightness << 8) + mcled_cdev->subled_info[2].brightness; - ret = clevo_evaluate_set_color(zone, color); + ret = clevo_evaluate_set_rgb_color(zone, color); if (ret) { - pr_debug("clevo_leds_set_brightness_mc(): clevo_evaluate_set_color() failed\n"); + pr_debug("clevo_leds_set_brightness_mc(): clevo_evaluate_set_rgb_color() failed\n"); return; } led_cdev->brightness = brightness; @@ -115,7 +126,7 @@ static void clevo_leds_set_brightness(struct led_classdev *led_cdev __always_unu // Temprary fix for KDE: KDE does only set one kbd_backlight brightness value, this version of the // function uses clevos built in brightness setting to set the whole keyboard brightness at once. -// -> use clevo_evaluate_set_brightness() to set overall brightness via firmware instead of scaling +// -> use clevo_evaluate_set_rgb_brightness() to set overall brightness via firmware instead of scaling // the RGB values // -> update all clevo_mcled_cdevs brightness levels to refect that the firmware method sets the // the whole keyboard brightness and not just one zone @@ -126,9 +137,9 @@ static void clevo_leds_set_brightness_mc(struct led_classdev *led_cdev, enum led u32 zone, color; struct led_classdev_mc *mcled_cdev = lcdev_to_mccdev(led_cdev); - ret = clevo_evaluate_set_brightness(brightness); + ret = clevo_evaluate_set_rgb_brightness(brightness); if (ret) { - pr_debug("clevo_leds_set_brightness_mc(): clevo_evaluate_set_brightness() failed\n"); + pr_debug("clevo_leds_set_brightness_mc(): clevo_evaluate_set_rgb_brightness() failed\n"); return; } clevo_mcled_cdevs[0].led_cdev.brightness = brightness; @@ -141,17 +152,17 @@ static void clevo_leds_set_brightness_mc(struct led_classdev *led_cdev, enum led (mcled_cdev->subled_info[1].intensity << 8) + mcled_cdev->subled_info[2].intensity; - ret = clevo_evaluate_set_color(zone, color); + ret = clevo_evaluate_set_rgb_color(zone, color); if (ret) { - pr_debug("clevo_leds_set_brightness_mc(): clevo_evaluate_set_color() failed\n"); + pr_debug("clevo_leds_set_brightness_mc(): clevo_evaluate_set_rgb_color() failed\n"); } } static struct led_classdev clevo_led_cdev = { .name = "white:" LED_FUNCTION_KBD_BACKLIGHT, - .max_brightness = CLEVO_KBD_BRIGHTNESS_MAX, + .max_brightness = CLEVO_KBD_BRIGHTNESS_WHITE_MAX, .brightness_set = &clevo_leds_set_brightness, - .brightness = CLEVO_KBD_BRIGHTNESS_DEFAULT + .brightness = CLEVO_KBD_BRIGHTNESS_WHITE_DEFAULT }; static struct mc_subled clevo_mcled_cdevs_subleds[3][3] = {