History

platform/x86: asus-wmi: Add support for charge threshold

Most newer ASUS laptops supports limiting the battery charge level, which help prolonging the battery life. Tested on a Zenbook UX430UNR.

Kristian Klausen committed 7 years ago

Commit d507a541 parent 02a5e9b2 files · +49 −0Browse files

Unified · Split

2 files
  1. drivers/platform/x86/asus-wmi.c +48 −0
  2. include/linux/platform_data/x86/asus-wmi.h +1 −0
drivers/platform/x86/asus-wmi.c+48−0
@@ -195,6 +195,8 @@ struct asus_wmi { · 194 unmodified lines
195195 u8 fan_boost_mode_mask;
196196 u8 fan_boost_mode;
197197
198+ int charge_threshold;
199+
198200 struct hotplug_slot hotplug_slot;
199201 struct mutex hotplug_lock;
200202 struct mutex wmi_lock;
@@ -2075,6 +2077,43 @@ static ssize_t cpufv_store(struct device *dev, struct device_attribute *attr, · 1874 unmodified lines
20752077
20762078 static DEVICE_ATTR_WO(cpufv);
20772079
2080+
2081+static ssize_t charge_threshold_store(struct device *dev,
2082+ struct device_attribute *attr,
2083+ const char *buf, size_t count)
2084+{
2085+ struct asus_wmi *asus = dev_get_drvdata(dev);
2086+ int value, ret, rv;
2087+
2088+ ret = kstrtouint(buf, 10, &value);
2089+
2090+ if (!count || ret != 0)
2091+ return -EINVAL;
2092+ if (value < 0 || value > 100)
2093+ return -EINVAL;
2094+
2095+ asus_wmi_set_devstate(ASUS_WMI_CHARGE_THRESHOLD, value, &rv);
2096+
2097+ if (rv != 1)
2098+ return -EIO;
2099+
2100+ /* There isn't any method in the DSDT to read the threshold, so we
2101+ * save the threshold.
2102+ */
2103+ asus->charge_threshold = value;
2104+ return count;
2105+}
2106+
2107+static ssize_t charge_threshold_show(struct device *dev,
2108+ struct device_attribute *attr, char *buf)
2109+{
2110+ struct asus_wmi *asus = dev_get_drvdata(dev);
2111+
2112+ return sprintf(buf, "%d\n", asus->charge_threshold);
2113+}
2114+
2115+static DEVICE_ATTR_RW(charge_threshold);
2116+
20782117 static struct attribute *platform_attributes[] = {
20792118 &dev_attr_cpufv.attr,
20802119 &dev_attr_camera.attr,
@@ -2083,6 +2122,7 @@ static struct attribute *platform_attributes[] = { · 2 unmodified lines
20832122 &dev_attr_lid_resume.attr,
20842123 &dev_attr_als_enable.attr,
20852124 &dev_attr_fan_boost_mode.attr,
2125+ &dev_attr_charge_threshold.attr,
20862126 NULL
20872127 };
20882128
@@ -2106,6 +2146,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, · 17 unmodified lines
21062146 devid = ASUS_WMI_DEVID_ALS_ENABLE;
21072147 else if (attr == &dev_attr_fan_boost_mode.attr)
21082148 ok = asus->fan_boost_mode_available;
2149+ else if (attr == &dev_attr_charge_threshold.attr)
2150+ devid = ASUS_WMI_CHARGE_THRESHOLD;
21092151
21102152 if (devid != -1)
21112153 ok = !(asus_wmi_get_devstate_simple(asus, devid) < 0);
@@ -2434,6 +2476,12 @@ static int asus_wmi_add(struct platform_device *pdev) · 322 unmodified lines
24342476 }
24352477
24362478 asus_wmi_debugfs_init(asus);
2479+ /* The charge threshold is only reset when the system is power cycled,
2480+ * and we can't get the current threshold so let set it to 100% on
2481+ * module load.
2482+ */
2483+ asus_wmi_set_devstate(ASUS_WMI_CHARGE_THRESHOLD, 100, NULL);
2484+ asus->charge_threshold = 100;
24372485
24382486 return 0;
24392487
include/linux/platform_data/x86/asus-wmi.h+1−0
@@ -61,6 +61,7 @@ · 60 unmodified lines
6161
6262 /* Misc */
6363 #define ASUS_WMI_DEVID_CAMERA 0x00060013
64+#define ASUS_WMI_CHARGE_THRESHOLD 0x00120057
6465
6566 /* Storage */
6667 #define ASUS_WMI_DEVID_CARDREADER 0x00080013

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t