From fd9fc525109d0c5004bd0e64c3ee0cb782fb7031 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Wed, 31 Aug 2022 11:04:51 +0200 Subject: [PATCH 1/6] More specific name for sub command --- src/clevo_interfaces.h | 10 +++++----- src/clevo_leds.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/clevo_interfaces.h b/src/clevo_interfaces.h index a624258..0a32c72 100644 --- a/src/clevo_interfaces.h +++ b/src/clevo_interfaces.h @@ -54,11 +54,11 @@ #define CLEVO_CMD_SET_EVENTS_ENABLED 0x46 -#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 -#define CLEVO_CMD_SET_KB_LEDS_SUB_RGB_ZONE_3 0xF3000000 // Unused on all known Clevo devices -#define CLEVO_CMD_SET_KB_LEDS_SUB_BRIGHTNESS 0xF4000000 +#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 +#define CLEVO_CMD_SET_KB_LEDS_SUB_RGB_ZONE_3 0xF3000000 // Unused on all known Clevo devices +#define CLEVO_CMD_SET_KB_LEDS_SUB_RGB_BRIGHTNESS 0xF4000000 #define CLEVO_CMD_OPT 0x79 #define CLEVO_OPT_SUBCMD_SET_PERF_PROF 0x19 diff --git a/src/clevo_leds.h b/src/clevo_leds.h index bb58624..f187488 100644 --- a/src/clevo_leds.h +++ b/src/clevo_leds.h @@ -65,7 +65,7 @@ static int clevo_evaluate_set_brightness(u8 brightness) { pr_debug("Set brightness on %d\n", brightness); - return clevo_evaluate_method (CLEVO_CMD_SET_KB_LEDS, 0xF4000000 | brightness, NULL); + return clevo_evaluate_method (CLEVO_CMD_SET_KB_LEDS, CLEVO_CMD_SET_KB_LEDS_SUB_RGB_BRIGHTNESS | brightness, NULL); } static int clevo_evaluate_set_color(u32 zone, u32 color) From 0cfe09ac06e079c14bf61435c7b8ceac4177c855 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Wed, 31 Aug 2022 18:58:44 +0200 Subject: [PATCH 2/6] Cleanup --- src/clevo_interfaces.h | 2 +- src/tuxedo_io/tuxedo_io.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clevo_interfaces.h b/src/clevo_interfaces.h index 0a32c72..50d327b 100644 --- a/src/clevo_interfaces.h +++ b/src/clevo_interfaces.h @@ -61,7 +61,7 @@ #define CLEVO_CMD_SET_KB_LEDS_SUB_RGB_BRIGHTNESS 0xF4000000 #define CLEVO_CMD_OPT 0x79 -#define CLEVO_OPT_SUBCMD_SET_PERF_PROF 0x19 +#define CLEVO_CMD_OPT_SUB_SET_PERF_PROF 0x19 struct clevo_interface_t { char *string_id; diff --git a/src/tuxedo_io/tuxedo_io.c b/src/tuxedo_io/tuxedo_io.c index 22f51e4..e7ec2ac 100644 --- a/src/tuxedo_io/tuxedo_io.c +++ b/src/tuxedo_io/tuxedo_io.c @@ -148,7 +148,7 @@ static long clevo_ioctl_interface(struct file *file, unsigned int cmd, unsigned break; case W_CL_PERF_PROFILE: copy_result = copy_from_user(&argument, (int32_t *) arg, sizeof(argument)); - clevo_arg = (CLEVO_OPT_SUBCMD_SET_PERF_PROF << 0x18) | (argument & 0xff); + clevo_arg = (CLEVO_CMD_OPT_SUB_SET_PERF_PROF << 0x18) | (argument & 0xff); clevo_evaluate_method(CLEVO_CMD_OPT, clevo_arg, &result); break; } From 1d5f679f66da090beb7e7a6de0c8b052d6b17308 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Wed, 31 Aug 2022 19:05:04 +0200 Subject: [PATCH 3/6] 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] = { From 1f9eb8fd10bb8ac80ebc2f5a3b18380959434001 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Wed, 31 Aug 2022 19:12:39 +0200 Subject: [PATCH 4/6] Change default keyboard type as old RGB keyboards are not controllable from OS --- src/clevo_leds.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/clevo_leds.h b/src/clevo_leds.h index 65164d7..20b5f8c 100644 --- a/src/clevo_leds.h +++ b/src/clevo_leds.h @@ -59,10 +59,7 @@ void clevo_leds_set_color_extern(u32 color); #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 -// a missing one. This is a temporary fix until we find a way to identify these early keyboard backlight devices. -static enum clevo_kb_backlight_types clevo_kb_backlight_type = CLEVO_KB_BACKLIGHT_TYPE_FIXED_COLOR; +static enum clevo_kb_backlight_types clevo_kb_backlight_type = CLEVO_KB_BACKLIGHT_TYPE_NONE; static bool leds_initiaized; static int clevo_evaluate_set_white_brightness(u8 brightness) From b9b3c12b643c73a210f222c049a62707cc403f53 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Wed, 31 Aug 2022 19:13:38 +0200 Subject: [PATCH 5/6] Fix spelling and reset value --- src/clevo_leds.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/clevo_leds.h b/src/clevo_leds.h index 20b5f8c..5175e9e 100644 --- a/src/clevo_leds.h +++ b/src/clevo_leds.h @@ -60,7 +60,7 @@ void clevo_leds_set_color_extern(u32 color); #define CLEVO_KB_COLOR_DEFAULT ((CLEVO_KB_COLOR_DEFAULT_RED << 16) + (CLEVO_KB_COLOR_DEFAULT_GREEN << 8) + CLEVO_KB_COLOR_DEFAULT_BLUE) static enum clevo_kb_backlight_types clevo_kb_backlight_type = CLEVO_KB_BACKLIGHT_TYPE_NONE; -static bool leds_initiaized; +static bool leds_initialized = false; static int clevo_evaluate_set_white_brightness(u8 brightness) { @@ -315,7 +315,7 @@ int clevo_leds_init(struct platform_device *dev) } } - leds_initiaized = true; + leds_initialized = true; return 0; } EXPORT_SYMBOL(clevo_leds_init); @@ -335,6 +335,8 @@ int clevo_leds_remove(struct platform_device *dev) { } } + leds_initialized = false; + return 0; } EXPORT_SYMBOL(clevo_leds_remove); From 965e37a5c62329c785033be58b4af246da71dc22 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Wed, 31 Aug 2022 19:14:21 +0200 Subject: [PATCH 6/6] Fixed missing variable rename --- 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 5175e9e..cb18c54 100644 --- a/src/clevo_leds.h +++ b/src/clevo_leds.h @@ -321,7 +321,7 @@ int clevo_leds_init(struct platform_device *dev) EXPORT_SYMBOL(clevo_leds_init); int clevo_leds_remove(struct platform_device *dev) { - if (leds_initiaized) { + if (leds_initialized) { if (clevo_kb_backlight_type == CLEVO_KB_BACKLIGHT_TYPE_FIXED_COLOR) { led_classdev_unregister(&clevo_led_cdev); }