Skip to content

Commit

Permalink
platform/x86: asus-wmi: add support for showing charger mode
Browse files Browse the repository at this point in the history
Expose a WMI method in sysfs platform for showing which connected
charger the laptop is currently using.

Signed-off-by: Luke D. Jones <[email protected]>
Reviewed-by: Hans de Goede <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Hans de Goede <[email protected]>
  • Loading branch information
flukejones authored and jwrdegoede committed Jul 12, 2023
1 parent 9204fc5 commit 77ee9d2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Documentation/ABI/testing/sysfs-platform-asus-wmi
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,13 @@ Description:
Enable an LCD response-time boost to reduce or remove ghosting:
* 0 - Disable,
* 1 - Enable

What: /sys/devices/platform/<platform>/charge_mode
Date: Jun 2023
KernelVersion: 6.5
Contact: "Luke Jones" <[email protected]>
Description:
Get the current charging mode being used:
* 1 - Barrel connected charger,
* 2 - USB-C charging
* 3 - Both connected, barrel used for charging
21 changes: 21 additions & 0 deletions drivers/platform/x86/asus-wmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ struct asus_wmi {
u8 fan_boost_mode_mask;
u8 fan_boost_mode;

bool charge_mode_available;
bool egpu_enable_available;
bool dgpu_disable_available;
bool gpu_mux_mode_available;
Expand Down Expand Up @@ -586,6 +587,22 @@ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus)
asus_wmi_tablet_sw_report(asus, result);
}

/* Charging mode, 1=Barrel, 2=USB ******************************************/
static ssize_t charge_mode_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct asus_wmi *asus = dev_get_drvdata(dev);
int result, value;

result = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_CHARGE_MODE, &value);
if (result < 0)
return result;

return sysfs_emit(buf, "%d\n", value & 0xff);
}

static DEVICE_ATTR_RO(charge_mode);

/* dGPU ********************************************************************/
static ssize_t dgpu_disable_show(struct device *dev,
struct device_attribute *attr, char *buf)
Expand Down Expand Up @@ -3462,6 +3479,7 @@ static struct attribute *platform_attributes[] = {
&dev_attr_camera.attr,
&dev_attr_cardr.attr,
&dev_attr_touchpad.attr,
&dev_attr_charge_mode.attr,
&dev_attr_egpu_enable.attr,
&dev_attr_dgpu_disable.attr,
&dev_attr_gpu_mux_mode.attr,
Expand Down Expand Up @@ -3491,6 +3509,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj,
devid = ASUS_WMI_DEVID_LID_RESUME;
else if (attr == &dev_attr_als_enable.attr)
devid = ASUS_WMI_DEVID_ALS_ENABLE;
else if (attr == &dev_attr_charge_mode.attr)
ok = asus->charge_mode_available;
else if (attr == &dev_attr_egpu_enable.attr)
ok = asus->egpu_enable_available;
else if (attr == &dev_attr_dgpu_disable.attr)
Expand Down Expand Up @@ -3757,6 +3777,7 @@ static int asus_wmi_add(struct platform_device *pdev)
if (err)
goto fail_platform;

asus->charge_mode_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_CHARGE_MODE);
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);
Expand Down
3 changes: 3 additions & 0 deletions include/linux/platform_data/x86/asus-wmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
/* Keyboard dock */
#define ASUS_WMI_DEVID_KBD_DOCK 0x00120063

/* Charging mode - 1=Barrel, 2=USB */
#define ASUS_WMI_DEVID_CHARGE_MODE 0x0012006C

/* dgpu on/off */
#define ASUS_WMI_DEVID_EGPU 0x00090019

Expand Down

0 comments on commit 77ee9d2

Please sign in to comment.