platform/x86: lg-laptop: Fix WMAB call in fan_mode_store()

When WMAB is called to set the fan mode, the new mode is read from either
bits 0-1 or bits 4-5 (depending on the value of some other EC register).
Thus when WMAB is called with bits 4-5 zeroed and called again with
bits 0-1 zeroed, the second call undoes the effect of the first call.
This causes writes to /sys/devices/platform/lg-laptop/fan_mode to have
no effect (and causes reads to always report a status of zero).

Fix this by calling WMAB once, with the mode set in bits 0,1 and 4,5.
When the fan mode is returned from WMAB it always has this form, so
there is no need to preserve the other bits.  As a bonus, the driver
now supports the "Performance" fan mode seen in the LG-provided Windows
control app, which provides less aggressive CPU throttling but louder
fan noise and shorter battery life.

Also, correct the documentation to reflect that 0 corresponds to the
default mode (what the Windows app calls "Optimal") and 1 corresponds
to the silent mode.

Fixes: dbf0c5a6b1 ("platform/x86: Add LG Gram laptop special features driver")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=204913#c4
Signed-off-by: Daniel Lee <dany97@live.ca>
Link: https://patch.msgid.link/MN2PR06MB55989CB10E91C8DA00EE868DDC1CA@MN2PR06MB5598.namprd06.prod.outlook.com
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
This commit is contained in:
Daniel Lee 2025-09-24 14:17:17 -04:00 committed by Ilpo Järvinen
parent a15b5aefa8
commit 3ed17349f1
No known key found for this signature in database
GPG Key ID: 59AC4F6153E5CE31
2 changed files with 16 additions and 22 deletions

View File

@ -48,8 +48,8 @@ This value is reset to 100 when the kernel boots.
Fan mode Fan mode
-------- --------
Writing 1/0 to /sys/devices/platform/lg-laptop/fan_mode disables/enables Writing 0/1/2 to /sys/devices/platform/lg-laptop/fan_mode sets fan mode to
the fan silent mode. Optimal/Silent/Performance respectively.
USB charge USB charge

View File

@ -8,6 +8,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/acpi.h> #include <linux/acpi.h>
#include <linux/bitfield.h>
#include <linux/bits.h> #include <linux/bits.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/dev_printk.h> #include <linux/dev_printk.h>
@ -75,6 +76,9 @@ MODULE_PARM_DESC(fw_debug, "Enable printing of firmware debug messages");
#define WMBB_USB_CHARGE 0x10B #define WMBB_USB_CHARGE 0x10B
#define WMBB_BATT_LIMIT 0x10C #define WMBB_BATT_LIMIT 0x10C
#define FAN_MODE_LOWER GENMASK(1, 0)
#define FAN_MODE_UPPER GENMASK(5, 4)
#define PLATFORM_NAME "lg-laptop" #define PLATFORM_NAME "lg-laptop"
MODULE_ALIAS("wmi:" WMI_EVENT_GUID0); MODULE_ALIAS("wmi:" WMI_EVENT_GUID0);
@ -274,29 +278,19 @@ static ssize_t fan_mode_store(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buffer, size_t count) const char *buffer, size_t count)
{ {
bool value; unsigned long value;
union acpi_object *r; union acpi_object *r;
u32 m;
int ret; int ret;
ret = kstrtobool(buffer, &value); ret = kstrtoul(buffer, 10, &value);
if (ret) if (ret)
return ret; return ret;
if (value >= 3)
return -EINVAL;
r = lg_wmab(dev, WM_FAN_MODE, WM_GET, 0); r = lg_wmab(dev, WM_FAN_MODE, WM_SET,
if (!r) FIELD_PREP(FAN_MODE_LOWER, value) |
return -EIO; FIELD_PREP(FAN_MODE_UPPER, value));
if (r->type != ACPI_TYPE_INTEGER) {
kfree(r);
return -EIO;
}
m = r->integer.value;
kfree(r);
r = lg_wmab(dev, WM_FAN_MODE, WM_SET, (m & 0xffffff0f) | (value << 4));
kfree(r);
r = lg_wmab(dev, WM_FAN_MODE, WM_SET, (m & 0xfffffff0) | value);
kfree(r); kfree(r);
return count; return count;
@ -305,7 +299,7 @@ static ssize_t fan_mode_store(struct device *dev,
static ssize_t fan_mode_show(struct device *dev, static ssize_t fan_mode_show(struct device *dev,
struct device_attribute *attr, char *buffer) struct device_attribute *attr, char *buffer)
{ {
unsigned int status; unsigned int mode;
union acpi_object *r; union acpi_object *r;
r = lg_wmab(dev, WM_FAN_MODE, WM_GET, 0); r = lg_wmab(dev, WM_FAN_MODE, WM_GET, 0);
@ -317,10 +311,10 @@ static ssize_t fan_mode_show(struct device *dev,
return -EIO; return -EIO;
} }
status = r->integer.value & 0x01; mode = FIELD_GET(FAN_MODE_LOWER, r->integer.value);
kfree(r); kfree(r);
return sysfs_emit(buffer, "%d\n", status); return sysfs_emit(buffer, "%d\n", mode);
} }
static ssize_t usb_charge_store(struct device *dev, static ssize_t usb_charge_store(struct device *dev,