asus-wmi: Add support for RGB keyboards
Luke D. Jones
maintainerv4 cover asus-wmi: Add support for RGB keyboards
This is a patch series to add RGB support for ASUS laptops. The laptops with this RGB tend to be the TUF series of gamer laptops.
These types of keyboards implement a slightly more complex interface than just RGB control - they also have modes with can be static LED, blinking, rainbow, color cycles, and more. They also have some custom animations that can play depending on device state, such as suspended playing a fancy colour cycle, or playing a "wave" animation.
Two of the patches add support for these features.
It should be noted that these patches progressed from an initial version much like the one here, to an implementation using the multicolor RGB class that is available. This class was found to be unsuitable after testing actual use because these keyboards provide a asus::kbd_backlight backlight control which is 4-step, and completely turns off LEDs, alongside the fact that some laptops boot with LEDs off by default, making multicolor invisible.
The added attributes for RGB control are added to attr groups under asus::kbd_backlight.
Previous discussion regarding the above can be found here:
https://lore.kernel.org/platform-driver-x86/[email protected]/
Changelog:
- V4:
+ Reimplement an version of the patch with attributes for control.
+ Add the control attributes as a group under asus::kbd_backlight
+ Rebased on review-hans
- V3: patch 2: asus-wmi RGB mode control
+ Split save, speed, mode in to separate nodes
+ Remove the _index node as it is not required with the above nodes
+ Cleanup of a one-line ternary
+ rename asus->keyboard_rgb_mode to keyboard_rgb_led to be clearer about purpose
+ Attach documentation to this patch
- V3: patch 3:
+ Use BIT() in place of previous hex for flags
+ Comment on purpose of 0xbd in state write
+ Attach documentation to this patch
- V3: patch 6: asus-wmi: hardware GPU MUX:
+ Include the correct patch for this feature
- V2: patch 1: asus-wmi - RGB
+ shorten a few lines
+ move unused keyboard_rgb_mode_available to next patch
+ remove tuf_rgb_brightness_get() is it was only returning current led_classdev brightness, not reading it from device
+ remove unnecessary setting of brightness on multicolor init
+ set brightness_get to null for TUF RGB
+ actually use the member subled_info in keyboard_rgb_led struct and not the leftover dynamic allocation (now removed)
- V2: patch 2: asus-wmi RGB mode control
+ tuf_rgb_brightness_set() was still using hardcoded save/mode/speed from testing. This is now using the pre-set default.
+ asus_wmi_led_init(), set speed value to a correct value
+ keyboard_rgb_mode_store() return count, not 0
+ correctly unregister the mulicolor led on module exit
+ use switch/case in keyboard_rgb_mode_store() for speed
+ remove a single line bracket block
- V2: patch 3: asus-wmi RGB power control
+ Try to fix the indent warning from buildbot
+ Use correct date on added API docs
+ Add missing panel_od doc
+ correctly label attribute for keyboard_rgb_state
Luke D. Jones (2):
asus-wmi: Implement TUF laptop keyboard LED modes
asus-wmi: Implement TUF laptop keyboard power states
drivers/platform/x86/asus-wmi.c | 157 ++++++++++++++++++++- include/linux/platform_data/x86/asus-wmi.h | 6 + 2 files changed, 162 insertions(+), 1 deletion(-)
Signature · 1 line
2.37.1
Luke D. Jones
maintainerPATCH v4 1/2 asus-wmi: Implement TUF laptop keyboard LED modes
Adds support for changing the laptop keyboard LED mode and colour.
The modes are visible effects such as static, rainbow, pulsing, colour cycles.
These sysfs attributes are added to asus::kbd_backlight:
- kbd_rgb_mode
- kbd_rgb_mode_index
--- drivers/platform/x86/asus-wmi.c | 76 +++++++++++++++++++++- include/linux/platform_data/x86/asus-wmi.h | 3 + 2 files changed, 78 insertions(+), 1 deletion(-)
drivers/platform/x86/asus-wmi.c +75 -1
@@ -237,6 +237,8 @@ struct asus_wmi {bool dgpu_disable_available;bool gpu_mux_mode_available; +bool kbd_rgb_mode_available; +bool throttle_thermal_policy_available;u8 throttle_thermal_policy_mode;
@@ -720,6 +722,69 @@ static ssize_t gpu_mux_mode_store(struct device *dev, }static DEVICE_ATTR_RW (gpu_mux_mode); +/* TUF Laptop Keyboard RGB Modes **********************************************/ +static ssize_t kbd_rgb_mode_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +u32 cmd, mode, r, g, b, speed; +int err; + +if (sscanf (buf,"%d %d %d %d %d %d" , &cmd, &mode, &r, &g, &b, &speed) !=6 ) +return -EINVAL ; + + cmd = !!cmd; + +/* These are the known usable modes across all TUF/ROG */ +if (mode >=12 || mode ==9 ) + mode =10 ; + +switch (speed) { +case 0 : + speed =0xe1 ; +break ; +case 1 : + speed =0xeb ; +break ; +case 2 : + speed =0xf5 ; +break ; +default : + speed =0xeb ; + } + + err =asus_wmi_evaluate_method3 (ASUS_WMI_METHODID_DEVS ,ASUS_WMI_DEVID_TUF_RGB_MODE , + cmd | (mode <<8 ) | (r <<16 ) | (g <<24 ), b | (speed <<8 ),NULL ); +if (err) +return err; + +return count; +} +static DEVICE_ATTR_WO (kbd_rgb_mode); + +static ssize_t kbd_rgb_mode_index_show (struct device *device, +struct device_attribute *attr, +char *buf) +{ +return sysfs_emit (buf,"%s\n" ,"cmd mode red green blue speed" ); +} +static DEVICE_ATTR_RO (kbd_rgb_mode_index); + +static struct attribute *kbd_rgb_mode_attrs[] = { + &dev_attr_kbd_rgb_mode.attr, + &dev_attr_kbd_rgb_mode_index.attr, +NULL , +}; + +static const struct attribute_group kbd_rgb_mode_group = { + .attrs = kbd_rgb_mode_attrs, +}; + +const struct attribute_group *kbd_rgb_mode_groups[] = { +NULL , +NULL , +}; +/* Battery ********************************************************************/ /* The battery maximum charging percentage */
@@ -1038,7 +1103,10 @@ static void asus_wmi_led_exit(struct asus_wmi *asus)static int asus_wmi_led_init (struct asus_wmi *asus) { -int rv =0 , led_val; +int rv =0 , num_rgb_groups =0 , led_val; + +if (asus->kbd_rgb_mode_available) + kbd_rgb_mode_groups[num_rgb_groups++] = &kbd_rgb_mode_group; asus->led_workqueue =create_singlethread_workqueue ("led_workqueue" );if (!asus->led_workqueue)
@@ -1066,6 +1134,9 @@ static int asus_wmi_led_init(struct asus_wmi *asus) asus->kbd_led.brightness_get = kbd_led_get; asus->kbd_led.max_brightness =3 ; +if (num_rgb_groups !=0 ) + asus->kbd_led.groups = kbd_rgb_mode_groups; + rv =led_classdev_register (&asus->platform_device->dev, &asus->kbd_led);if (rv)
@@ -3253,6 +3324,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, ok = asus->egpu_enable_available; else if (attr == &dev_attr_dgpu_disable.attr) ok = asus->dgpu_disable_available; + else if (attr == &dev_attr_dgpu_disable.attr) + ok = asus->dgpu_disable_available; else if (attr == &dev_attr_gpu_mux_mode.attr) ok = asus->gpu_mux_mode_available; else if (attr == &dev_attr_fan_boost_mode.attr)
@@ -3519,6 +3592,7 @@ static int asus_wmi_add(struct platform_device *pdev) asus->egpu_enable_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_EGPU ); asus->dgpu_disable_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_DGPU ); asus->gpu_mux_mode_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_GPU_MUX ); + asus->kbd_rgb_mode_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_TUF_RGB_MODE ); asus->panel_overdrive_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_PANEL_OD ); err =fan_boost_mode_check_present (asus);
include/linux/platform_data/x86/asus-wmi.h +3 -0
@@ -103,6 +103,9 @@/* gpu mux switch, 0 = dGPU, 1 = Optimus */ #define ASUS_WMI_DEVID_GPU_MUX 0x00090016 +/* TUF laptop RGB modes/colours */ +#define ASUS_WMI_DEVID_TUF_RGB_MODE 0x00100056 +/* DSTS masks */ #define ASUS_WMI_DSTS_STATUS_BIT 0x00000001#define ASUS_WMI_DSTS_UNKNOWN_BIT 0x00000002
Signature · 1 line
2.37.2
Re: [PATCH v4 1/2] asus-wmi: Implement TUF laptop keyboard LED modes
Hi Luke,
Quoted 121 lines · Luke D. Jones
Adds support for changing the laptop keyboard LED mode and colour.
The modes are visible effects such as static, rainbow, pulsing, colour cycles.
These sysfs attributes are added to
asus::kbd_backlight:
-kbd_rgb_mode
-kbd_rgb_mode_indexSigned-off-by Luke D. Jones <[email protected]>--- drivers/platform/x86/asus-wmi.c | 76 +++++++++++++++++++++- include/linux/platform_data/x86/asus-wmi.h | 3 + 2 files changed, 78 insertions(+), 1 deletion(-)drivers/platform/x86/asus-wmi.c +72
-1@@ -237,6 +237,8 @@ struct asus_wmi {bool dgpu_disable_available;bool gpu_mux_mode_available; +bool kbd_rgb_mode_available; +bool throttle_thermal_policy_available;u8 throttle_thermal_policy_mode;@@ -720,6 +722,69 @@ static ssize_t gpu_mux_mode_store(struct device *dev, }static DEVICE_ATTR_RW (gpu_mux_mode); +/* TUF Laptop Keyboard RGB Modes **********************************************/ +static ssize_t kbd_rgb_mode_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +u32 cmd, mode, r, g, b, speed; +int err; + +if (sscanf (buf,"%d %d %d %d %d %d" , &cmd, &mode, &r, &g, &b, &speed) !=6 ) +return -EINVAL ; + + cmd = !!cmd; + +/* These are the known usable modes across all TUF/ROG */ +if (mode >=12 || mode ==9 ) + mode =10 ; + +switch (speed) { +case 0 : + speed =0xe1 ; +break ; +case 1 : + speed =0xeb ; +break ; +case 2 : + speed =0xf5 ; +break ; +default : + speed =0xeb ; + } + + err =asus_wmi_evaluate_method3 (ASUS_WMI_METHODID_DEVS ,ASUS_WMI_DEVID_TUF_RGB_MODE , + cmd | (mode <<8 ) | (r <<16 ) | (g <<24 ), b | (speed <<8 ),NULL ); +if (err) +return err; + +return count; +} +static DEVICE_ATTR_WO (kbd_rgb_mode); + +static ssize_t kbd_rgb_mode_index_show (struct device *device, +struct device_attribute *attr, +char *buf) +{ +return sysfs_emit (buf,"%s\n" ,"cmd mode red green blue speed" ); +} +static DEVICE_ATTR_RO (kbd_rgb_mode_index); + +static struct attribute *kbd_rgb_mode_attrs[] = { + &dev_attr_kbd_rgb_mode.attr, + &dev_attr_kbd_rgb_mode_index.attr, +NULL , +}; + +static const struct attribute_group kbd_rgb_mode_group = { + .attrs = kbd_rgb_mode_attrs, +}; + +const struct attribute_group *kbd_rgb_mode_groups[] = { +NULL , +NULL , +}; +/* Battery ********************************************************************/ /* The battery maximum charging percentage */ @@ -1038,7 +1103,10 @@ static void asus_wmi_led_exit(struct asus_wmi *asus)static int asus_wmi_led_init (struct asus_wmi *asus) { -int rv =0 , led_val; +int rv =0 , num_rgb_groups =0 , led_val; + +if (asus->kbd_rgb_mode_available) + kbd_rgb_mode_groups[num_rgb_groups++] = &kbd_rgb_mode_group; asus->led_workqueue =create_singlethread_workqueue ("led_workqueue" );if (!asus->led_workqueue)@@ -1066,6 +1134,9 @@ static int asus_wmi_led_init(struct asus_wmi *asus) asus->kbd_led.brightness_get = kbd_led_get; asus->kbd_led.max_brightness =3 ; +if (num_rgb_groups !=0 ) + asus->kbd_led.groups = kbd_rgb_mode_groups; + rv =led_classdev_register (&asus->platform_device->dev, &asus->kbd_led);if (rv)
drivers/platform/x86/asus-wmi.c static umode_t asus_sysfs_is_visible(struct kobject *kobj, · line 3331
Quoted 8 lines
drivers/platform/x86/asus-wmi.c +2
-0@@ -3253,6 +3324,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, ok = asus->egpu_enable_available; else if (attr == &dev_attr_dgpu_disable.attr) ok = asus->dgpu_disable_available; + else if (attr == &dev_attr_dgpu_disable.attr) + ok = asus->dgpu_disable_available; else if (attr == &dev_attr_gpu_mux_mode.attr) ok = asus->gpu_mux_mode_available; else if (attr == &dev_attr_fan_boost_mode.attr)
This patch-hunk looks like it is a (mangled) leftover from previous versions of the patch.
Other then that this latest version of the series looks nice and clean, so I've added the series to my review-hans branch minus this patch-hunk.
One request can you do a follow up patch documenting the new attributes in Documentation/ABI/testing/sysfs-platform-asus-wmi I know the attributes sit under the LED class device, but this still seems the best place for documenting them.
Regards,
Hans
Quoted 22 lines
drivers/platform/x86/asus-wmi.c +1
-0@@ -3519,6 +3592,7 @@ static int asus_wmi_add(struct platform_device *pdev) asus->egpu_enable_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_EGPU ); asus->dgpu_disable_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_DGPU ); asus->gpu_mux_mode_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_GPU_MUX ); + asus->kbd_rgb_mode_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_TUF_RGB_MODE ); asus->panel_overdrive_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_PANEL_OD ); err =fan_boost_mode_check_present (asus);include/linux/platform_data/x86/asus-wmi.h +3
-0@@ -103,6 +103,9 @@/* gpu mux switch, 0 = dGPU, 1 = Optimus */ #define ASUS_WMI_DEVID_GPU_MUX 0x00090016 +/* TUF laptop RGB modes/colours */ +#define ASUS_WMI_DEVID_TUF_RGB_MODE 0x00100056 +/* DSTS masks */ #define ASUS_WMI_DSTS_STATUS_BIT 0x00000001#define ASUS_WMI_DSTS_UNKNOWN_BIT 0x00000002
Luke Jones
maintainerRe: [PATCH v4 1/2] asus-wmi: Implement TUF laptop keyboard LED modes
Quoted 145 lines · Hans de Goede
Hi Luke,
Quoted 125 lines · Luke D. Jones
Adds support for changing the laptop keyboard LED mode and colour.
The modes are visible effects such as static, rainbow, pulsing, colour cycles.
These sysfs attributes are added to
asus::kbd_backlight:
-kbd_rgb_mode
-kbd_rgb_mode_indexSigned-off-by Luke D. Jones <[email protected]>---
drivers/platform/x86/asus-wmi.c | 76 +++++++++++++++++++++- include/linux/platform_data/x86/asus-wmi.h | 3 + 2 files changed, 78 insertions(+), 1 deletion(-)diff --git
a/drivers/platform/x86/asus-wmi.cb/drivers/platform/x86/asus-wmi.c
index0f9f79f249c7..92f16bb9b4ef100644
---a/drivers/platform/x86/asus-wmi.c
+++b/drivers/platform/x86/asus-wmi.c
@@ -237,6 +237,8 @@ structasus_wmi{
booldgpu_disable_available;
boolgpu_mux_mode_available;+ bool
kbd_rgb_mode_available;
+
boolthrottle_thermal_policy_available;
u8throttle_thermal_policy_mode;@@ -720,6 +722,69 @@ static
ssize_tgpu_mux_mode_store(struct
device *dev,
}
staticDEVICE_ATTR_RW(gpu_mux_mode);+/* TUF Laptop Keyboard RGB Modes
**********************************************/
+staticssize_tkbd_rgb_mode_store(struct device *dev,
+ structdevice_attribute*attr,
+ const char *buf,size_tcount)
+{
+ u32 cmd, mode, r, g, b, speed;
+ int err;
+
+ if (sscanf(buf, "%d %d %d %d %d %d", &cmd, &mode, &r, &g, &b,
&speed) != 6)
+ return-EINVAL;
+
+ cmd = !!cmd;
+
+ /* These are the known usable modes across all TUF/ROG */
+ if (mode >= 12 || mode == 9)
+ mode = 10;
+
+ switch (speed) {
+ case 0:
+ speed =0xe1;
+ break;
+ case 1:
+ speed =0xeb;
+ break;
+ case 2:
+ speed =0xf5;
+ break;
+ default:
+ speed =0xeb;
+ }
+
+ err = asus_wmi_evaluate_method3(ASUS_WMI_METHODID_DEVS,ASUS_WMI_DEVID_TUF_RGB_MODE,
+ cmd | (mode << 8) | (r << 16) | (g << 24), b | (speed << 8),
NULL);
+ if (err)
+ return err;
+
+ return count;
+}
+staticDEVICE_ATTR_WO(kbd_rgb_mode);
+
+staticssize_tkbd_rgb_mode_index_show(struct device *device,
+ structdevice_attribute*attr,
+ char *buf)
+{
+ returnsysfs_emit(buf, "%s\n", "cmd mode red green blue speed");
+}
+staticDEVICE_ATTR_RO(kbd_rgb_mode_index);
+
+static struct attribute *kbd_rgb_mode_attrs[] = {
+ &dev_attr_kbd_rgb_mode.attr,
+ &dev_attr_kbd_rgb_mode_index.attr,
+ NULL,
+};
+
+static const structattribute_groupkbd_rgb_mode_group= {
+ .attrs =kbd_rgb_mode_attrs,
+};
+
+const structattribute_group*kbd_rgb_mode_groups[] = {
+ NULL,
+ NULL,
+};
+
/* Battery
********************************************************************//* The battery maximum charging percentage */
@@ -1038,7 +1103,10 @@ static void asus_wmi_led_exit(structasus_wmi*asus)static int
asus_wmi_led_init(struct asus_wmi *asus){
- int rv = 0,led_val;
+ int rv = 0,num_rgb_groups= 0,led_val;
+
+ if (asus->kbd_rgb_mode_available)
+ kbd_rgb_mode_groups[num_rgb_groups++] =&kbd_rgb_mode_group;
asus->led_workqueue=create_singlethread_workqueue("led_workqueue");
if (!asus->led_workqueue)
@@ -1066,6 +1134,9 @@ static int asus_wmi_led_init(structasus_wmi
*asus)
asus->kbd_led.brightness_get=kbd_led_get;asus->kbd_led.max_brightness= 3;Quoted 16 lines
+ if (
num_rgb_groups!= 0)
+asus->kbd_led.groups=kbd_rgb_mode_groups;
+
rv = led_classdev_register(&asus->platform_device->dev,
&asus->kbd_led);
if (rv)
@@ -3253,6 +3324,8 @@ staticumode_tasus_sysfs_is_visible(struct
kobject *kobj,
ok =asus->egpu_enable_available;
else if (attr == &dev_attr_dgpu_disable.attr)
ok =asus->dgpu_disable_available;
+ else if (attr == &dev_attr_dgpu_disable.attr)
+ ok =asus->dgpu_disable_available;
else if (attr == &dev_attr_gpu_mux_mode.attr)
ok =asus->gpu_mux_mode_available;
else if (attr == &dev_attr_fan_boost_mode.attr)
Quoted 2 lines
This patch-hunk looks like it is a (mangled) leftover from previous versions of the patch.
Do you mean:
+ else if (attr == &dev_attr_dgpu_disable.attr)
+ ok = asus->dgpu_disable_available;
Quoted 8 lines
Other then that this latest version of the series looks nice and clean, so I've added the series to my review-hans branch minus this patch-hunk.
One request can you do a follow up patch documenting the new attributes in
Documentation/ABI/testing/sysfs-platform-asus-wmiI know the attributes sit under the LED class device, but this still seems the best place for documenting them.
Yes for sure. I wasn't actually certain where I should put the doc.
Quoted 38 lines
Regards,
Hans
Quoted 29 lines
@@ -3519,6 +3592,7 @@ static int asus_wmi_add(struct
platform_device*pdev)
asus->egpu_enable_available= asus_wmi_dev_is_present(asus,ASUS_WMI_DEVID_EGPU);
asus->dgpu_disable_available= asus_wmi_dev_is_present(asus,ASUS_WMI_DEVID_DGPU);
asus->gpu_mux_mode_available= asus_wmi_dev_is_present(asus,ASUS_WMI_DEVID_GPU_MUX);
+asus->kbd_rgb_mode_available= asus_wmi_dev_is_present(asus,ASUS_WMI_DEVID_TUF_RGB_MODE);
asus->panel_overdrive_available= asus_wmi_dev_is_present(asus,ASUS_WMI_DEVID_PANEL_OD);err =
fan_boost_mode_check_present(asus);
diff --gita/include/linux/platform_data/x86/asus-wmi.hb/include/linux/platform_data/x86/asus-wmi.h
index6e8a95c10d17..3d861477cb20100644
---a/include/linux/platform_data/x86/asus-wmi.h+++b/include/linux/platform_data/x86/asus-wmi.h@@ -103,6 +103,9 @@
/* gpu mux switch, 0 = dGPU, 1 = Optimus */
#defineASUS_WMI_DEVID_GPU_MUX0x00090016+/* TUF laptop RGB modes/colours */
+#defineASUS_WMI_DEVID_TUF_RGB_MODE0x00100056
+
/* DSTS masks */
#defineASUS_WMI_DSTS_STATUS_BIT0x00000001
#defineASUS_WMI_DSTS_UNKNOWN_BIT0x00000002
Re: [PATCH v4 1/2] asus-wmi: Implement TUF laptop keyboard LED modes
Hi,
Quoted 136 lines · Luke Jones
Quoted 133 lines · Hans de Goede
Hi Luke,
Quoted 129 lines · Luke D. Jones
Adds support for changing the laptop keyboard LED mode and colour.
The modes are visible effects such as static, rainbow, pulsing, colour cycles.
These sysfs attributes are added to
asus::kbd_backlight:
-kbd_rgb_mode
-kbd_rgb_mode_indexSigned-off-by Luke D. Jones <[email protected]>---
drivers/platform/x86/asus-wmi.c | 76 +++++++++++++++++++++-include/linux/platform_data/x86/asus-wmi.h| 3 +2 files changed, 78 insertions(+), 1 deletion(-)diff --git
a/drivers/platform/x86/asus-wmi.cb/drivers/platform/x86/asus-wmi.cindex0f9f79f249c7..92f16bb9b4ef100644
---a/drivers/platform/x86/asus-wmi.c
+++b/drivers/platform/x86/asus-wmi.c
@@ -237,6 +237,8 @@ structasus_wmi{
booldgpu_disable_available;
boolgpu_mux_mode_available;+ bool
kbd_rgb_mode_available;
+
boolthrottle_thermal_policy_available;
u8throttle_thermal_policy_mode;@@ -720,6 +722,69 @@ static
ssize_tgpu_mux_mode_store(struct device *dev, }
staticDEVICE_ATTR_RW(gpu_mux_mode);+/* TUF Laptop Keyboard RGB Modes **********************************************/ +static
ssize_tkbd_rgb_mode_store(struct device *dev,
+ structdevice_attribute*attr,
+ const char *buf,size_tcount)
+{
+ u32 cmd, mode, r, g, b, speed;
+ int err;
+
+ if (sscanf(buf, "%d %d %d %d %d %d", &cmd, &mode, &r, &g, &b, &speed)!= 6) + return-EINVAL;
+
+ cmd = !!cmd;
+
+ /* These are the known usable modes across all TUF/ROG */
+ if (mode >= 12 || mode == 9)
+ mode = 10;
+
+ switch (speed) {
+ case 0:
+ speed =0xe1;
+ break;
+ case 1:
+ speed =0xeb;
+ break;
+ case 2:
+ speed =0xf5;
+ break;
+ default:
+ speed =0xeb;
+ }
+
+ err = asus_wmi_evaluate_method3(ASUS_WMI_METHODID_DEVS,ASUS_WMI_DEVID_TUF_RGB_MODE, + cmd | (mode << 8) | (r << 16) | (g << 24), b | (speed << 8), NULL); + if (err)
+ return err;
+
+ return count;
+}
+staticDEVICE_ATTR_WO(kbd_rgb_mode);
+
+staticssize_tkbd_rgb_mode_index_show(struct device *device,
+ structdevice_attribute*attr,
+ char *buf)
+{
+ returnsysfs_emit(buf, "%s\n", "cmd mode red green blue speed");
+}
+staticDEVICE_ATTR_RO(kbd_rgb_mode_index);
+
+static struct attribute *kbd_rgb_mode_attrs[] = {
+ &dev_attr_kbd_rgb_mode.attr,
+ &dev_attr_kbd_rgb_mode_index.attr,
+ NULL,
+};
+
+static const structattribute_groupkbd_rgb_mode_group= {
+ .attrs =kbd_rgb_mode_attrs,
+};
+
+const structattribute_group*kbd_rgb_mode_groups[] = {
+ NULL,
+ NULL,
+};
+
/* Battery ********************************************************************//* The battery maximum charging percentage */
@@ -1038,7 +1103,10 @@ static voidasus_wmi_led_exit(struct asus_wmi *asus)static int
asus_wmi_led_init(struct asus_wmi *asus)
{
- int rv = 0,led_val;
+ int rv = 0,num_rgb_groups= 0,led_val;
+
+ if (asus->kbd_rgb_mode_available)
+ kbd_rgb_mode_groups[num_rgb_groups++] =&kbd_rgb_mode_group;
asus->led_workqueue=create_singlethread_workqueue("led_workqueue"); if (!asus->led_workqueue)
@@ -1066,6 +1134,9 @@ static intasus_wmi_led_init(struct asus_wmi *asus)asus->kbd_led.brightness_get=kbd_led_get;asus->kbd_led.max_brightness= 3;+ if (
num_rgb_groups!= 0)
+asus->kbd_led.groups=kbd_rgb_mode_groups;
+
rv =led_classdev_register(&asus->platform_device->dev, &asus->kbd_led);
if (rv)
@@ -3253,6 +3324,8 @@ staticumode_tasus_sysfs_is_visible(struct kobject *kobj, ok =asus->egpu_enable_available;
else if (attr == &dev_attr_dgpu_disable.attr)
ok =asus->dgpu_disable_available;
+ else if (attr == &dev_attr_dgpu_disable.attr)
+ ok =asus->dgpu_disable_available;
else if (attr == &dev_attr_gpu_mux_mode.attr)
ok =asus->gpu_mux_mode_available;
else if (attr == &dev_attr_fan_boost_mode.attr)
Quoted 7 lines
Quoted 2 lines
This patch-hunk looks like it is a (mangled) leftover from previous versions of the patch.
Do you mean:
+ else if (attr == &dev_attr_dgpu_disable.attr) + ok =
asus->dgpu_disable_available;
Yes, patch hunks or chunks are the parts of a patch between a "@@ ... @@" line and the next "@@ ... @@" line.
Regards,
Hans
Quoted 25 lines
Quoted 23 lines
Quoted 22 lines
@@ -3519,6 +3592,7 @@ static int
asus_wmi_add(struct platform_device *pdev)asus->egpu_enable_available=asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_EGPU);asus->dgpu_disable_available=asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_DGPU);asus->gpu_mux_mode_available=asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_GPU_MUX); +asus->kbd_rgb_mode_available=asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE);asus->panel_overdrive_available=asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PANEL_OD);err =
fan_boost_mode_check_present(asus);
diff --gita/include/linux/platform_data/x86/asus-wmi.hb/include/linux/platform_data/x86/asus-wmi.hindex6e8a95c10d17..3d861477cb20100644
---a/include/linux/platform_data/x86/asus-wmi.h
+++b/include/linux/platform_data/x86/asus-wmi.h
@@ -103,6 +103,9 @@
/* gpu mux switch, 0 = dGPU, 1 = Optimus */
#define ASUS_WMI_DEVID_GPU_MUX0x00090016+/* TUF laptop RGB modes/colours */ +#define ASUS_WMI_DEVID_TUF_RGB_MODE
0x00100056+
/* DSTS masks */
#define ASUS_WMI_DSTS_STATUS_BIT0x00000001#define ASUS_WMI_DSTS_UNKNOWN_BIT0x00000002
Luke Jones
maintainerRe: [PATCH v4 1/2] asus-wmi: Implement TUF laptop keyboard LED modes
Quoted 159 lines · Hans de Goede
Hi,
Quoted 156 lines · Luke Jones
Quoted 151 lines · Hans de Goede
Hi Luke,
Quoted 131 lines · Luke D. Jones
Adds support for changing the laptop keyboard LED mode and
colour.The modes are visible effects such as static, rainbow, pulsing, colour cycles.
These sysfs attributes are added to
asus::kbd_backlight:
-kbd_rgb_mode
-kbd_rgb_mode_indexSigned-off-by Luke D. Jones <[email protected]>---
drivers/platform/x86/asus-wmi.c | 76 +++++++++++++++++++++- include/linux/platform_data/x86/asus-wmi.h | 3 + 2 files changed, 78 insertions(+), 1 deletion(-)diff --git
a/drivers/platform/x86/asus-wmi.cb/drivers/platform/x86/asus-wmi.c
index0f9f79f249c7..92f16bb9b4ef100644
---a/drivers/platform/x86/asus-wmi.c
+++b/drivers/platform/x86/asus-wmi.c@@ -237,6 +237,8 @@ struct asus_wmi { bool dgpu_disable_available; bool gpu_mux_mode_available;+ bool
kbd_rgb_mode_available;
+bool throttle_thermal_policy_available; u8 throttle_thermal_policy_mode;@@ -720,6 +722,69 @@ static
ssize_tgpu_mux_mode_store(struct
device *dev,
}
staticDEVICE_ATTR_RW(gpu_mux_mode);+/* TUF Laptop Keyboard RGB Modes
**********************************************/
+staticssize_tkbd_rgb_mode_store(struct device *dev,
+ structdevice_attribute*attr,
+ const char *buf,size_tcount)
+{
+ u32 cmd, mode, r, g, b, speed;
+ int err;
+
+ if (sscanf(buf, "%d %d %d %d %d %d", &cmd, &mode, &r, &g,
&b, &speed) != 6)
+ return-EINVAL;
+
+ cmd = !!cmd;
+
+ /* These are the known usable modes across all TUF/ROG */
+ if (mode >= 12 || mode == 9)
+ mode = 10;
+
+ switch (speed) {
+ case 0:
+ speed =0xe1;
+ break;
+ case 1:
+ speed =0xeb;
+ break;
+ case 2:
+ speed =0xf5;
+ break;
+ default:
+ speed =0xeb;
+ }
+
+ err = asus_wmi_evaluate_method3(ASUS_WMI_METHODID_DEVS,ASUS_WMI_DEVID_TUF_RGB_MODE,
+ cmd | (mode << 8) | (r << 16) | (g << 24), b |
(speed << 8), NULL);
+ if (err)
+ return err;
+
+ return count;
+}
+staticDEVICE_ATTR_WO(kbd_rgb_mode);
+
+staticssize_tkbd_rgb_mode_index_show(struct device *device,
+ structdevice_attribute*attr,
+ char *buf)
+{
+ return sysfs_emit(buf, "%s\n", "cmd mode red green blue
speed");
+}
+staticDEVICE_ATTR_RO(kbd_rgb_mode_index);
+
+static struct attribute *kbd_rgb_mode_attrs[] = {+ &dev_attr_kbd_rgb_mode.attr, + &dev_attr_kbd_rgb_mode_index.attr, + NULL,+};
+
+static const structattribute_groupkbd_rgb_mode_group= {
+ .attrs =kbd_rgb_mode_attrs,
+};
+
+const structattribute_group*kbd_rgb_mode_groups[] = {
+ NULL,
+ NULL,
+};
+
/* Battery
********************************************************************//* The battery maximum charging percentage */@@ -1038,7 +1103,10 @@ static void asus_wmi_led_exit(struct
asus_wmi*asus)static int
asus_wmi_led_init(struct asus_wmi *asus){
- int rv = 0,led_val;
+ int rv = 0,num_rgb_groups= 0,led_val;
+
+ if (asus->kbd_rgb_mode_available)
+ kbd_rgb_mode_groups[num_rgb_groups++] =&kbd_rgb_mode_group;asus->led_workqueue = create_singlethread_workqueue("led_workqueue"); if (!asus->led_workqueue) @@ -1066,6 +1134,9 @@ static int asus_wmi_led_init(struct asus_wmi *asus) asus->kbd_led.brightness_get = kbd_led_get; asus->kbd_led.max_brightness = 3;+ if (
num_rgb_groups!= 0)
+asus->kbd_led.groups=kbd_rgb_mode_groups;
+Quoted 13 lines
rv = led_classdev_register(&asus->platform_device->dev, &asus->kbd_led); if (rv) @@ -3253,6 +3324,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, ok = asus->egpu_enable_available; else if (attr == &dev_attr_dgpu_disable.attr) ok = asus->dgpu_disable_available; + else if (attr == &dev_attr_dgpu_disable.attr) + ok = asus->dgpu_disable_available; else if (attr == &dev_attr_gpu_mux_mode.attr) ok = asus->gpu_mux_mode_available; else if (attr == &dev_attr_fan_boost_mode.attr)This patch-hunk looks like it is a (mangled) leftover from
previous versions
of the patch.
Quoted 7 lines
Quoted 4 lines
Do you mean:
+ else if (attr == &dev_attr_dgpu_disable.attr)
+ ok =asus->dgpu_disable_available;Yes, patch hunks or chunks are the parts of a patch between a "@@ ... @@" line and the next "@@ ... @@" line.
Thanks. Oh gosh i see now... dgpu_disable. I'm unsure how I missed that. My apologies..
Quoted 42 lines
Regards,
Hans
Quoted 32 lines
Quoted 30 lines
Quoted 29 lines
@@ -3519,6 +3592,7 @@ static int asus_wmi_add(struct
platform_device*pdev)asus->egpu_enable_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_EGPU); asus->dgpu_disable_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_DGPU); asus->gpu_mux_mode_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_GPU_MUX); + asus->kbd_rgb_mode_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE); asus->panel_overdrive_available =
asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_PANEL_OD);err = fan_boost_mode_check_present(asus);diff --git
a/include/linux/platform_data/x86/asus-wmi.hb/include/linux/platform_data/x86/asus-wmi.h
index6e8a95c10d17..3d861477cb20100644
---a/include/linux/platform_data/x86/asus-wmi.h+++b/include/linux/platform_data/x86/asus-wmi.h@@ -103,6 +103,9 @@
/* gpu mux switch, 0 = dGPU, 1 = Optimus */
#defineASUS_WMI_DEVID_GPU_MUX0x00090016+/* TUF laptop RGB modes/colours */ +#define ASUS_WMI_DEVID_TUF_RGB_MODE 0x00100056 + /* DSTS masks */ #define ASUS_WMI_DSTS_STATUS_BIT 0x00000001 #define ASUS_WMI_DSTS_UNKNOWN_BIT 0x00000002
Luke D. Jones
maintainerPATCH v4 2/2 asus-wmi: Implement TUF laptop keyboard power states
In reply to Luke D. JonesAdds support for setting various power states of TUF keyboards. These states are combinations of:
- boot, set if a boot animation is shown on keyboard
- awake, set if the keyboard LEDs are visible while laptop is on
- sleep, set if an animation is displayed while the laptop is suspended
- keyboard (unknown effect)
Adds two sysfs attributes to asus::kbd_backlight:
- kbd_rgb_state
- kbd_rgb_state_index
--- drivers/platform/x86/asus-wmi.c | 57 ++++++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 3 ++ 2 files changed, 60 insertions(+)
drivers/platform/x86/asus-wmi.c +57 -0
@@ -238,6 +238,7 @@ struct asus_wmi {bool gpu_mux_mode_available;bool kbd_rgb_mode_available; +bool kbd_rgb_state_available;bool throttle_thermal_policy_available;u8 throttle_thermal_policy_mode;
@@ -780,9 +781,62 @@ static const struct attribute_group kbd_rgb_mode_group = { .attrs = kbd_rgb_mode_attrs, }; +/* TUF Laptop Keyboard RGB State **********************************************/ +static ssize_t kbd_rgb_state_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +u32 flags, cmd, boot, awake, sleep, keyboard; +int err; + +if (sscanf (buf,"%d %d %d %d %d" , &cmd, &boot, &awake, &sleep, &keyboard) !=5 ) +return -EINVAL ; + +if (cmd) + cmd =BIT (2 ); + + flags =0 ; +if (boot) + flags |=BIT (1 ); +if (awake) + flags |=BIT (3 ); +if (sleep) + flags |=BIT (5 ); +if (keyboard) + flags |=BIT (7 ); + +/* 0xbd is the required default arg0 for the method. Nothing happens otherwise */ + err =asus_wmi_evaluate_method3 (ASUS_WMI_METHODID_DEVS , +ASUS_WMI_DEVID_TUF_RGB_STATE ,0xbd | cmd <<8 | (flags <<16 ),0 ,NULL ); +if (err) +return err; + +return count; +} +static DEVICE_ATTR_WO (kbd_rgb_state); + +static ssize_t kbd_rgb_state_index_show (struct device *device, +struct device_attribute *attr, +char *buf) +{ +return sysfs_emit (buf,"%s\n" ,"cmd boot awake sleep keyboard" ); +} +static DEVICE_ATTR_RO (kbd_rgb_state_index); + +static struct attribute *kbd_rgb_state_attrs[] = { + &dev_attr_kbd_rgb_state.attr, + &dev_attr_kbd_rgb_state_index.attr, +NULL , +}; + +static const struct attribute_group kbd_rgb_state_group = { + .attrs = kbd_rgb_state_attrs, +}; +const struct attribute_group *kbd_rgb_mode_groups[] = {NULL ,NULL , +NULL , };/* Battery ********************************************************************/
@@ -1107,6 +1161,8 @@ static int asus_wmi_led_init(struct asus_wmi *asus)if (asus->kbd_rgb_mode_available) kbd_rgb_mode_groups[num_rgb_groups++] = &kbd_rgb_mode_group; +if (asus->kbd_rgb_state_available) + kbd_rgb_mode_groups[num_rgb_groups++] = &kbd_rgb_state_group; asus->led_workqueue =create_singlethread_workqueue ("led_workqueue" );if (!asus->led_workqueue)
@@ -3593,6 +3649,7 @@ static int asus_wmi_add(struct platform_device *pdev) asus->dgpu_disable_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_DGPU ); asus->gpu_mux_mode_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_GPU_MUX ); asus->kbd_rgb_mode_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_TUF_RGB_MODE ); + asus->kbd_rgb_state_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_TUF_RGB_STATE ); asus->panel_overdrive_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_PANEL_OD ); err =fan_boost_mode_check_present (asus);
include/linux/platform_data/x86/asus-wmi.h +3 -0
@@ -106,6 +106,9 @@/* TUF laptop RGB modes/colours */ #define ASUS_WMI_DEVID_TUF_RGB_MODE 0x00100056 +/* TUF laptop RGB power/state */ +#define ASUS_WMI_DEVID_TUF_RGB_STATE 0x00100057 +/* DSTS masks */ #define ASUS_WMI_DSTS_STATUS_BIT 0x00000001#define ASUS_WMI_DSTS_UNKNOWN_BIT 0x00000002
Signature · 1 line
2.37.2