Skip to content

Commit ca91ea3

Browse files
flukejonesjwrdegoede
authored andcommitted
asus-wmi: Add panel overdrive functionality
Some ASUS ROG laptops have the ability to drive the display panel a higher rate to eliminate or reduce ghosting. Signed-off-by: Luke D. Jones <luke@ljones.dev> Link: https://lore.kernel.org/r/20210807023656.25020-2-luke@ljones.dev Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
1 parent 411f48b commit ca91ea3

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

‎drivers/platform/x86/asus-wmi.c‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ struct asus_wmi {
216216
// The RSOC controls the maximum charging percentage.
217217
bool battery_rsoc_available;
218218

219+
bool panel_overdrive_available;
220+
bool panel_overdrive;
221+
219222
struct hotplug_slot hotplug_slot;
220223
struct mutex hotplug_lock;
221224
struct mutex wmi_lock;
@@ -1221,6 +1224,87 @@ static int asus_wmi_rfkill_init(struct asus_wmi *asus)
12211224
return result;
12221225
}
12231226

1227+
/* Panel Overdrive ************************************************************/
1228+
static int panel_od_check_present(struct asus_wmi *asus)
1229+
{
1230+
u32 result;
1231+
int err;
1232+
1233+
asus->panel_overdrive_available = false;
1234+
1235+
err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_PANEL_OD, &result);
1236+
if (err) {
1237+
if (err == -ENODEV)
1238+
return 0;
1239+
return err;
1240+
}
1241+
1242+
if (result & ASUS_WMI_DSTS_PRESENCE_BIT) {
1243+
asus->panel_overdrive_available = true;
1244+
asus->panel_overdrive = result & ASUS_WMI_DSTS_STATUS_BIT;
1245+
}
1246+
1247+
return 0;
1248+
}
1249+
1250+
static int panel_od_write(struct asus_wmi *asus)
1251+
{
1252+
u32 retval;
1253+
u8 value;
1254+
int err;
1255+
1256+
/* Don't rely on type conversion */
1257+
value = asus->panel_overdrive ? 1 : 0;
1258+
1259+
err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PANEL_OD, value, &retval);
1260+
1261+
if (err) {
1262+
pr_warn("Failed to set panel overdrive: %d\n", err);
1263+
return err;
1264+
}
1265+
1266+
if (retval > 1 || retval < 0) {
1267+
pr_warn("Failed to set panel overdrive (retval): 0x%x\n", retval);
1268+
return -EIO;
1269+
}
1270+
1271+
sysfs_notify(&asus->platform_device->dev.kobj, NULL, "panel_od");
1272+
1273+
return 0;
1274+
}
1275+
1276+
static ssize_t panel_od_show(struct device *dev,
1277+
struct device_attribute *attr, char *buf)
1278+
{
1279+
struct asus_wmi *asus = dev_get_drvdata(dev);
1280+
1281+
return sysfs_emit(buf, "%d\n", asus->panel_overdrive);
1282+
}
1283+
1284+
static ssize_t panel_od_store(struct device *dev,
1285+
struct device_attribute *attr,
1286+
const char *buf, size_t count)
1287+
{
1288+
bool overdrive;
1289+
int result;
1290+
1291+
struct asus_wmi *asus = dev_get_drvdata(dev);
1292+
1293+
result = kstrtobool(buf, &overdrive);
1294+
if (result)
1295+
return result;
1296+
1297+
asus->panel_overdrive = overdrive;
1298+
result = panel_od_write(asus);
1299+
1300+
if (result)
1301+
return result;
1302+
1303+
return count;
1304+
}
1305+
1306+
static DEVICE_ATTR_RW(panel_od);
1307+
12241308
/* Quirks *********************************************************************/
12251309

12261310
static void asus_wmi_set_xusb2pr(struct asus_wmi *asus)
@@ -2332,6 +2416,7 @@ static struct attribute *platform_attributes[] = {
23322416
&dev_attr_als_enable.attr,
23332417
&dev_attr_fan_boost_mode.attr,
23342418
&dev_attr_throttle_thermal_policy.attr,
2419+
&dev_attr_panel_od.attr,
23352420
NULL
23362421
};
23372422

@@ -2357,6 +2442,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj,
23572442
ok = asus->fan_boost_mode_available;
23582443
else if (attr == &dev_attr_throttle_thermal_policy.attr)
23592444
ok = asus->throttle_thermal_policy_available;
2445+
else if (attr == &dev_attr_panel_od.attr)
2446+
ok = asus->panel_overdrive_available;
23602447

23612448
if (devid != -1)
23622449
ok = !(asus_wmi_get_devstate_simple(asus, devid) < 0);
@@ -2622,6 +2709,10 @@ static int asus_wmi_add(struct platform_device *pdev)
26222709
else
26232710
throttle_thermal_policy_set_default(asus);
26242711

2712+
err = panel_od_check_present(asus);
2713+
if (err)
2714+
goto fail_panel_od;
2715+
26252716
err = asus_wmi_sysfs_init(asus->platform_device);
26262717
if (err)
26272718
goto fail_sysfs;
@@ -2709,6 +2800,7 @@ static int asus_wmi_add(struct platform_device *pdev)
27092800
fail_throttle_thermal_policy:
27102801
fail_fan_boost_mode:
27112802
fail_platform:
2803+
fail_panel_od:
27122804
kfree(asus);
27132805
return err;
27142806
}

‎include/linux/platform_data/x86/asus-wmi.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#define ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY 0x00120075
6262

6363
/* Misc */
64+
#define ASUS_WMI_DEVID_PANEL_OD 0x00050019
6465
#define ASUS_WMI_DEVID_CAMERA 0x00060013
6566
#define ASUS_WMI_DEVID_LID_FLIP 0x00060062
6667

0 commit comments

Comments
 (0)