Adds support for TUF laptop RGB mode control. Two paths are added: - /sys/devices/platform/asus-nb-wmi/kernel_rgb_mode - /sys/devices/platform/asus-nb-wmi/kernel_rgb_mode_index Signed-off-by: Luke D. Jones <luke@xxxxxxxxxx> --- drivers/platform/x86/asus-wmi.c | 86 +++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 33384e3321bb..9e6b83d8dd75 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -118,6 +118,9 @@ static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL }; static int throttle_thermal_policy_write(struct asus_wmi *); +static int tuf_rgb_brightness_set(struct led_classdev *cdev, + enum led_brightness brightness); + static bool ashs_present(void) { int i = 0; @@ -194,6 +197,9 @@ struct fan_curve_data { struct keyboard_rgb_led { struct led_classdev_mc dev; struct mc_subled subled_info[3]; /* r g b */ + u8 save; + u8 mode; + u8 speed; }; struct asus_wmi { @@ -743,6 +749,72 @@ static ssize_t egpu_enable_store(struct device *dev, static DEVICE_ATTR_RW(egpu_enable); +/* TUF Laptop Keyboard RGB Modes **********************************************/ +static int keyboard_rgb_mode_check_present(struct asus_wmi *asus) +{ + u32 result; + int err; + + asus->keyboard_rgb_mode_available = false; + + err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_TUF_RGB_MODE, &result); + if (err) { + if (err == -ENODEV) + return 0; + return err; + } + + if (result & ASUS_WMI_DSTS_PRESENCE_BIT) { + asus->keyboard_rgb_mode_available = true; + } + + return 0; +} + +static ssize_t keyboard_rgb_mode_store(struct device *device, + struct device_attribute *attr, + const char *buf, size_t count) +{ + u8 save, mode, speed; + int err; + + struct asus_wmi *asus = dev_get_drvdata(device); + struct led_classdev *cdev = &asus->keyboard_rgb_mode.dev.led_cdev; + + if (sscanf(buf, "%hhd %hhd %hhd", &save, &mode, &speed) != 3) + return -EINVAL; + + asus->keyboard_rgb_mode.save = save > 0 ? 1 : 0; + + /* These are the known usable modes across all TUF/ROG */ + asus->keyboard_rgb_mode.mode = mode < 12 && mode != 9 ? mode : 0x0a; + + if (speed == 0) + asus->keyboard_rgb_mode.speed = 0xe1; + else if (speed == 1) + asus->keyboard_rgb_mode.speed = 0xeb; + else if (speed == 2) + asus->keyboard_rgb_mode.speed = 0xf5; + else + asus->keyboard_rgb_mode.speed = 0xeb; + + err = tuf_rgb_brightness_set(cdev, cdev->brightness); + if (err) + return err; + return 0; +} + +static DEVICE_ATTR_WO(keyboard_rgb_mode); + +static ssize_t keyboard_rgb_mode_index_show(struct device *device, + struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%s\n", "save mode speed\n"); +} + +static DEVICE_ATTR_RO(keyboard_rgb_mode_index); + /* Battery ********************************************************************/ /* The battery maximum charging percentage */ @@ -1180,6 +1252,9 @@ static int asus_wmi_led_init(struct asus_wmi *asus) * write these defaults to the device because they will overwrite a * users last saved boot setting (in NVRAM). */ + asus->keyboard_rgb_mode.save = 1; + asus->keyboard_rgb_mode.mode = 0; + asus->keyboard_rgb_mode.speed = 1; mc_cdev->led_cdev.brightness = brightness; mc_cdev->led_cdev.max_brightness = brightness; mc_led_info[0].intensity = brightness; @@ -3347,6 +3422,8 @@ static struct attribute *platform_attributes[] = { &dev_attr_touchpad.attr, &dev_attr_egpu_enable.attr, &dev_attr_dgpu_disable.attr, + &dev_attr_keyboard_rgb_mode.attr, + &dev_attr_keyboard_rgb_mode_index.attr, &dev_attr_lid_resume.attr, &dev_attr_als_enable.attr, &dev_attr_fan_boost_mode.attr, @@ -3377,6 +3454,10 @@ 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_keyboard_rgb_mode.attr) + ok = asus->keyboard_rgb_mode_available; + else if (attr == &dev_attr_keyboard_rgb_mode_index.attr) + ok = asus->keyboard_rgb_mode_available; else if (attr == &dev_attr_fan_boost_mode.attr) ok = asus->fan_boost_mode_available; else if (attr == &dev_attr_throttle_thermal_policy.attr) @@ -3646,6 +3727,10 @@ static int asus_wmi_add(struct platform_device *pdev) if (err) goto fail_dgpu_disable; + err = keyboard_rgb_mode_check_present(asus); + if (err) + goto fail_keyboard_rgb_mode; + err = fan_boost_mode_check_present(asus); if (err) goto fail_fan_boost_mode; @@ -3760,6 +3845,7 @@ static int asus_wmi_add(struct platform_device *pdev) fail_fan_boost_mode: fail_egpu_enable: fail_dgpu_disable: +fail_keyboard_rgb_mode: fail_platform: fail_panel_od: kfree(asus); -- 2.37.1