Merge branch 'generalize_keyboard_backlight_brightness_clevo_working' into generalize_keyboard_backlight_brightness

This commit is contained in:
Werner Sembach 2022-09-20 11:55:03 +02:00
commit 5bf3547781
4 changed files with 51 additions and 41 deletions

View file

@ -50,18 +50,18 @@
#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
#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_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_BRIGHTNESS 0xF4000000
#define CLEVO_CMD_OPT 0x79 #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 { struct clevo_interface_t {
char *string_id; char *string_id;

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

@ -50,38 +50,46 @@ void clevo_leds_set_color_extern(u32 color);
#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_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_RED 0xff
#define CLEVO_KB_COLOR_DEFAULT_GREEN 0xff #define CLEVO_KB_COLOR_DEFAULT_GREEN 0xff
#define CLEVO_KB_COLOR_DEFAULT_BLUE 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_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 static enum clevo_kb_backlight_types clevo_kb_backlight_type = CLEVO_KB_BACKLIGHT_TYPE_NONE;
// not break these, we set this as default for the time being, better having an extra sysfs entry without function than static bool leds_initialized = false;
// 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 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, 0xF4000000 | 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 +113,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 +123,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 +134,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 +149,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] = {
@ -307,13 +315,13 @@ int clevo_leds_init(struct platform_device *dev)
} }
} }
leds_initiaized = true; leds_initialized = true;
return 0; return 0;
} }
EXPORT_SYMBOL(clevo_leds_init); EXPORT_SYMBOL(clevo_leds_init);
int clevo_leds_remove(struct platform_device *dev) { 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) { if (clevo_kb_backlight_type == CLEVO_KB_BACKLIGHT_TYPE_FIXED_COLOR) {
led_classdev_unregister(&clevo_led_cdev); led_classdev_unregister(&clevo_led_cdev);
} }
@ -327,6 +335,8 @@ int clevo_leds_remove(struct platform_device *dev) {
} }
} }
leds_initialized = false;
return 0; return 0;
} }
EXPORT_SYMBOL(clevo_leds_remove); EXPORT_SYMBOL(clevo_leds_remove);

View file

@ -148,7 +148,7 @@ static long clevo_ioctl_interface(struct file *file, unsigned int cmd, unsigned
break; break;
case W_CL_PERF_PROFILE: case W_CL_PERF_PROFILE:
copy_result = copy_from_user(&argument, (int32_t *) arg, sizeof(argument)); 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); clevo_evaluate_method(CLEVO_CMD_OPT, clevo_arg, &result);
break; break;
} }