Fix white only keyboards

This commit is contained in:
Werner Sembach 2022-08-31 19:05:04 +02:00
parent 0cfe09ac06
commit 1d5f679f66
3 changed files with 38 additions and 27 deletions

View file

@ -50,10 +50,10 @@
#define CLEVO_CMD_SET_FLIGHTMODE_SW 0x20 #define CLEVO_CMD_SET_FLIGHTMODE_SW 0x20
#define CLEVO_CMD_SET_TOUCHPAD_SW 0x2a #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_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_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_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_2 0xF2000000 // 3-Zone RGB right

View file

@ -163,7 +163,7 @@ static int set_enabled_cmd(u8 state)
cmd |= 0x07F001; 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) 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); 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 // method was succesfull so update ur internal state struct
kbd_led_state.mode = kbd_backlight_mode; kbd_led_state.mode = kbd_backlight_mode;
} }

View file

@ -46,14 +46,18 @@ void clevo_leds_set_color_extern(u32 color);
#include <linux/leds.h> #include <linux/leds.h>
#include <linux/led-class-multicolor.h> #include <linux/led-class-multicolor.h>
#define CLEVO_KBD_BRIGHTNESS_MIN 0x00 #define CLEVO_KBD_BRIGHTNESS_MIN 0x00
#define CLEVO_KBD_BRIGHTNESS_MAX 0xff #define CLEVO_KBD_BRIGHTNESS_MAX 0xff
#define CLEVO_KBD_BRIGHTNESS_DEFAULT (CLEVO_KBD_BRIGHTNESS_MAX * 0.5) #define CLEVO_KBD_BRIGHTNESS_DEFAULT (CLEVO_KBD_BRIGHTNESS_MAX * 0.5)
#define CLEVO_KB_COLOR_DEFAULT_RED 0xff #define CLEVO_KBD_BRIGHTNESS_WHITE_MIN 0x00
#define CLEVO_KB_COLOR_DEFAULT_GREEN 0xff #define CLEVO_KBD_BRIGHTNESS_WHITE_MAX 0x02 // White only keyboards can only be off, half, or full brightness
#define CLEVO_KB_COLOR_DEFAULT_BLUE 0xff #define CLEVO_KBD_BRIGHTNESS_WHITE_DEFAULT (CLEVO_KBD_BRIGHTNESS_WHITE_MAX * 0.5)
#define CLEVO_KB_COLOR_DEFAULT ((CLEVO_KB_COLOR_DEFAULT_RED << 16) + (CLEVO_KB_COLOR_DEFAULT_GREEN << 8) + CLEVO_KB_COLOR_DEFAULT_BLUE)
#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 // 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 // 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 enum clevo_kb_backlight_types clevo_kb_backlight_type = CLEVO_KB_BACKLIGHT_TYPE_FIXED_COLOR;
static bool leds_initiaized; 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 cset = ((color & 0x0000FF) << 16) | ((color & 0xFF0000) >> 8) | ((color & 0x00FF00) >> 8);
u32 clevo_submethod_arg = zone | cset; u32 clevo_submethod_arg = zone | cset;
pr_debug("Set Color 0x%08x for region 0x%08x\n", color, zone); 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) { 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) { 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; return;
} }
led_cdev->brightness = brightness; 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[1].brightness << 8) +
mcled_cdev->subled_info[2].brightness; mcled_cdev->subled_info[2].brightness;
ret = clevo_evaluate_set_color(zone, color); ret = clevo_evaluate_set_rgb_color(zone, color);
if (ret) { 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; return;
} }
led_cdev->brightness = brightness; 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 // 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. // 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 // the RGB values
// -> update all clevo_mcled_cdevs brightness levels to refect that the firmware method sets the // -> update all clevo_mcled_cdevs brightness levels to refect that the firmware method sets the
// the whole keyboard brightness and not just one zone // 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; u32 zone, color;
struct led_classdev_mc *mcled_cdev = lcdev_to_mccdev(led_cdev); 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) { 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; return;
} }
clevo_mcled_cdevs[0].led_cdev.brightness = brightness; 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[1].intensity << 8) +
mcled_cdev->subled_info[2].intensity; mcled_cdev->subled_info[2].intensity;
ret = clevo_evaluate_set_color(zone, color); ret = clevo_evaluate_set_rgb_color(zone, color);
if (ret) { 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 = { static struct led_classdev clevo_led_cdev = {
.name = "white:" LED_FUNCTION_KBD_BACKLIGHT, .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_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] = { static struct mc_subled clevo_mcled_cdevs_subleds[3][3] = {