From c22c4c3c76d714197b26b06c39356eea00dc1a0e Mon Sep 17 00:00:00 2001 From: Christoffer Sandberg Date: Mon, 17 Jul 2023 13:55:11 +0200 Subject: [PATCH] clevo_leds: Only use enable/disable switch for the rgb keyboard variants - Move set_enable_cmd to clevo_leds - Add suspend/resume hooks - Rename set_enable_cmd to clevo_evaluate_set_status --- src/clevo_keyboard.h | 20 ++------------------ src/clevo_leds.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/src/clevo_keyboard.h b/src/clevo_keyboard.h index 8aea994..a61c5b8 100644 --- a/src/clevo_keyboard.h +++ b/src/clevo_keyboard.h @@ -152,20 +152,6 @@ int clevo_get_active_interface_id(char **id_str) } EXPORT_SYMBOL(clevo_get_active_interface_id); -static int set_enabled_cmd(u8 state) -{ - u32 cmd = 0xE0000000; - TUXEDO_INFO("Set keyboard enabled to: %d\n", state); - - if (state == 0) { - cmd |= 0x003001; - } else { - cmd |= 0x07F001; - } - - return clevo_evaluate_method(CLEVO_CMD_SET_KB_RGB_LEDS, cmd, NULL); -} - static void set_next_color_whole_kb(void) { /* "Calculate" new to-be color */ @@ -304,7 +290,6 @@ static void clevo_keyboard_init(void) set_kbd_backlight_mode(kbd_led_state.mode); clevo_evaluate_method(CLEVO_CMD_SET_EVENTS_ENABLED, 0, NULL); - set_enabled_cmd(1); // Workaround for firmware issue not setting selected performance profile. // Explicitly set "performance" perf. profile on init regardless of what is chosen @@ -354,8 +339,7 @@ static int clevo_keyboard_remove(struct platform_device *dev) static int clevo_keyboard_suspend(struct platform_device *dev, pm_message_t state) { - // turning the keyboard off prevents default colours showing on resume - set_enabled_cmd(0); + clevo_leds_suspend(dev); return 0; } @@ -364,7 +348,7 @@ static int clevo_keyboard_resume(struct platform_device *dev) clevo_evaluate_method(CLEVO_CMD_SET_EVENTS_ENABLED, 0, NULL); clevo_leds_restore_state_extern(); // Sometimes clevo devices forget their last state after // suspend, so let the kernel ensure it. - set_enabled_cmd(1); + clevo_leds_resume(dev); return 0; } diff --git a/src/clevo_leds.h b/src/clevo_leds.h index 275f3f2..8cc1391 100644 --- a/src/clevo_leds.h +++ b/src/clevo_leds.h @@ -34,6 +34,8 @@ enum clevo_kb_backlight_types { int clevo_leds_init(struct platform_device *dev); int clevo_leds_remove(struct platform_device *dev); +int clevo_leds_suspend(struct platform_device *dev); +int clevo_leds_resume(struct platform_device *dev); enum clevo_kb_backlight_types clevo_leds_get_backlight_type(void); void clevo_leds_restore_state_extern(void); void clevo_leds_notify_brightness_change_extern(void); @@ -101,6 +103,20 @@ static int clevo_evaluate_set_rgb_color(u32 zone, u32 color) return clevo_evaluate_method(CLEVO_CMD_SET_KB_RGB_LEDS, clevo_submethod_arg, NULL); } +static int clevo_evaluate_set_keyboard_status(u8 state) +{ + u32 cmd = 0xE0000000; + TUXEDO_INFO("Set keyboard enabled to: %d\n", state); + + if (state == 0) { + cmd |= 0x003001; + } else { + cmd |= 0x07F001; + } + + return clevo_evaluate_method(CLEVO_CMD_SET_KB_RGB_LEDS, cmd, NULL); +} + static void clevo_leds_set_brightness(struct led_classdev *led_cdev __always_unused, enum led_brightness brightness) { int ret = clevo_evaluate_set_white_brightness(brightness); if (ret) { @@ -350,6 +366,7 @@ int clevo_leds_init(struct platform_device *dev) } } else if (clevo_kb_backlight_type == CLEVO_KB_BACKLIGHT_TYPE_1_ZONE_RGB) { + clevo_evaluate_set_keyboard_status(1); pr_debug("Registering single zone rgb leds interface\n"); ret = devm_led_classdev_multicolor_register(&dev->dev, &clevo_mcled_cdevs[0]); if (ret) { @@ -358,6 +375,7 @@ int clevo_leds_init(struct platform_device *dev) } } else if (clevo_kb_backlight_type == CLEVO_KB_BACKLIGHT_TYPE_3_ZONE_RGB) { + clevo_evaluate_set_keyboard_status(1); pr_debug("Registering three zone rgb leds interface\n"); ret = devm_led_classdev_multicolor_register(&dev->dev, &clevo_mcled_cdevs[0]); if (ret) { @@ -384,6 +402,32 @@ int clevo_leds_init(struct platform_device *dev) } EXPORT_SYMBOL(clevo_leds_init); +int clevo_leds_suspend(struct platform_device *dev) +{ + switch (clevo_kb_backlight_type) { + case CLEVO_KB_BACKLIGHT_TYPE_1_ZONE_RGB: + case CLEVO_KB_BACKLIGHT_TYPE_3_ZONE_RGB: + clevo_evaluate_set_keyboard_status(0); + break; + default: + } + return 0; +} +EXPORT_SYMBOL(clevo_leds_suspend); + +int clevo_leds_resume(struct platform_device *dev) +{ + switch (clevo_kb_backlight_type) { + case CLEVO_KB_BACKLIGHT_TYPE_1_ZONE_RGB: + case CLEVO_KB_BACKLIGHT_TYPE_3_ZONE_RGB: + clevo_evaluate_set_keyboard_status(1); + break; + default: + } + return 0; +} +EXPORT_SYMBOL(clevo_leds_resume); + int clevo_leds_remove(struct platform_device *dev) { if (leds_initialized) { if (clevo_kb_backlight_type == CLEVO_KB_BACKLIGHT_TYPE_FIXED_COLOR) {