From 860a768ea5987a44c8ed16d77127763b1f93c74b Mon Sep 17 00:00:00 2001 From: Lars Schellhas van Kisfeld Date: Mon, 16 Nov 2026 17:00:35 +0100 Subject: [PATCH 1/3] platform/surface: aggregator_registry: Add has_dptf property for battery and AC The battery subsystem of the Surface Aggregator Module EC has two DPTF commands: the battery data (command 0x53) and the adapter rating (command 0x0f). Not every EC supports them. An EC that does not support a command does not answer it, so the request runs into a timeout and the drivers cannot find out about the support by sending the request. Add software nodes for the AC adapter and the primary battery with the boolean property "has_dptf", and use them in the groups of the devices whose EC supports the commands. The secondary battery of the Surface Book 3 gets the property as well. The surface_battery and surface_charger drivers send the requests only if the property is set (next patches). Surface Laptop 3 (15", AMD) and 4, Surface Pro 7+ and Surface Pro 9, 10 and 11 (Intel) shared a group with devices that have no evidence (see below). They get their own group with the property. The device IDs without evidence stay on the old group. Devices that get the property, and why. M: the EC was measured to answer both commands. P: the Windows power management configuration of the device uses the battery data and the adapter rating, i.e. it expects the EC to answer. D: the Windows driver package of the device contains the component that provides this data to the configuration. Surface Book 3 (13.5", 15") M (15"), P, D Surface Laptop 3 (15", AMD) P Surface Laptop 4 (13", Intel; 15", AMD) P, D Surface Laptop 5, 6 P Surface Laptop Go 1, 3 P Surface Laptop Go 2 P, D Surface Laptop Studio 1 P, D Surface Laptop Studio 2 P Surface Pro 7+ P, D Surface Pro 8 P, D Surface Pro 9 P Surface Pro 10 (also 5G), Surface Pro 11 P, D Surface Pro 9 5G (ARM) P Surface Pro 11 (ARM) P, D Devices without the property, because the evidence above is missing for them: Surface Laptop 3 (13", Intel), Surface Pro 7 and Surface Pro 12 (Intel). All other groups have no battery nodes. The property can be added for more devices when someone measures them. The analysis, the patch and this changelog were prepared with the help of an AI coding assistant (Claude, Anthropic). I reviewed the change. Link: https://github.com/linux-surface/surface-aggregator-module/issues/29 Signed-off-by: Lars Schellhas van Kisfeld --- .../surface/surface_aggregator_registry.c | 119 ++++++++++++++---- 1 file changed, 92 insertions(+), 27 deletions(-) diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c index ef87965fcc930..fbe183e5280eb 100644 --- a/drivers/platform/surface/surface_aggregator_registry.c +++ b/drivers/platform/surface/surface_aggregator_registry.c @@ -51,6 +51,12 @@ static const struct software_node ssam_node_hub_base = { .parent = &ssam_node_root, }; +/* Property of the battery and AC adapter devices of an EC with DPTF support. */ +static const struct property_entry ssam_node_has_dptf[] = { + PROPERTY_ENTRY_BOOL("has_dptf"), + { } +}; + /* AC adapter. */ static const struct software_node ssam_node_bat_ac = { .name = "ssam:01:02:01:01:01", @@ -67,6 +73,25 @@ static const struct software_node ssam_node_bat_main = { static const struct software_node ssam_node_bat_sb3base = { .name = "ssam:01:02:02:01:00", .parent = &ssam_node_hub_base, + .properties = ssam_node_has_dptf, +}; + +/* + * AC adapter and primary battery of devices whose EC answers the DPTF + * requests (battery data, adapter rating). Sending these requests to an EC + * that does not support them runs into a timeout, so the drivers only send + * them if the device has the "has_dptf" property. + */ +static const struct software_node ssam_node_bat_ac_dptf = { + .name = "ssam:01:02:01:01:01", + .parent = &ssam_node_root, + .properties = ssam_node_has_dptf, +}; + +static const struct software_node ssam_node_bat_main_dptf = { + .name = "ssam:01:02:01:01:00", + .parent = &ssam_node_root, + .properties = ssam_node_has_dptf, }; /* Platform profile / performance-mode device without a fan. */ @@ -237,8 +262,8 @@ static const struct software_node *ssam_node_group_gen5[] = { static const struct software_node *ssam_node_group_sb3[] = { &ssam_node_root, &ssam_node_hub_base, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_bat_sb3base, &ssam_node_tmp_perf_profile, &ssam_node_bas_dtx, @@ -249,7 +274,7 @@ static const struct software_node *ssam_node_group_sb3[] = { NULL, }; -/* Devices for Surface Laptop 3 and 4. */ +/* Devices for Surface Laptop 3 (13", Intel), without DPTF. */ static const struct software_node *ssam_node_group_sl3[] = { &ssam_node_root, &ssam_node_bat_ac, @@ -261,11 +286,23 @@ static const struct software_node *ssam_node_group_sl3[] = { NULL, }; +/* Devices for Surface Laptop 3 (15", AMD) and 4 (13", Intel; 15", AMD), with DPTF. */ +static const struct software_node *ssam_node_group_sl3_dptf[] = { + &ssam_node_root, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, + &ssam_node_tmp_perf_profile, + &ssam_node_hid_main_keyboard, + &ssam_node_hid_main_touchpad, + &ssam_node_hid_main_iid5, + NULL, +}; + /* Devices for Surface Laptop 5. */ static const struct software_node *ssam_node_group_sl5[] = { &ssam_node_root, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_tmp_perf_profile_with_fan, &ssam_node_tmp_sensors, &ssam_node_fan_speed, @@ -279,8 +316,8 @@ static const struct software_node *ssam_node_group_sl5[] = { /* Devices for Surface Laptop 6. */ static const struct software_node *ssam_node_group_sl6[] = { &ssam_node_root, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_tmp_perf_profile_with_fan, &ssam_node_tmp_sensors, &ssam_node_fan_speed, @@ -305,8 +342,8 @@ static const struct software_node *ssam_node_group_sl7[] = { /* Devices for Surface Laptop Studio 1. */ static const struct software_node *ssam_node_group_sls1[] = { &ssam_node_root, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_tmp_perf_profile, &ssam_node_pos_tablet_switch, &ssam_node_hid_sam_keyboard, @@ -321,8 +358,8 @@ static const struct software_node *ssam_node_group_sls1[] = { /* Devices for Surface Laptop Studio 2. */ static const struct software_node *ssam_node_group_sls2[] = { &ssam_node_root, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_tmp_perf_profile_with_fan, &ssam_node_tmp_sensors, &ssam_node_fan_speed, @@ -337,13 +374,13 @@ static const struct software_node *ssam_node_group_sls2[] = { /* Devices for Surface Laptop Go. */ static const struct software_node *ssam_node_group_slg1[] = { &ssam_node_root, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_tmp_perf_profile, NULL, }; -/* Devices for Surface Pro 7 and Surface Pro 7+. */ +/* Devices for Surface Pro 7, without DPTF. */ static const struct software_node *ssam_node_group_sp7[] = { &ssam_node_root, &ssam_node_bat_ac, @@ -352,12 +389,21 @@ static const struct software_node *ssam_node_group_sp7[] = { NULL, }; +/* Devices for Surface Pro 7+, with DPTF. */ +static const struct software_node *ssam_node_group_sp7_dptf[] = { + &ssam_node_root, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, + &ssam_node_tmp_perf_profile, + NULL, +}; + /* Devices for Surface Pro 8 */ static const struct software_node *ssam_node_group_sp8[] = { &ssam_node_root, &ssam_node_hub_kip, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_tmp_perf_profile, &ssam_node_kip_tablet_switch, &ssam_node_hid_kip_keyboard, @@ -369,7 +415,7 @@ static const struct software_node *ssam_node_group_sp8[] = { NULL, }; -/* Devices for Surface Pro 9, 10 and 11 (Intel/x86) */ +/* Devices for Surface Pro 12 (Intel/x86), without DPTF. */ static const struct software_node *ssam_node_group_sp9[] = { &ssam_node_root, &ssam_node_hub_kip, @@ -388,12 +434,31 @@ static const struct software_node *ssam_node_group_sp9[] = { NULL, }; +/* Devices for Surface Pro 9, 10 and 11 (Intel/x86), with DPTF. */ +static const struct software_node *ssam_node_group_sp9_dptf[] = { + &ssam_node_root, + &ssam_node_hub_kip, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, + &ssam_node_tmp_perf_profile_with_fan, + &ssam_node_tmp_sensors, + &ssam_node_fan_speed, + &ssam_node_pos_tablet_switch, + &ssam_node_hid_kip_keyboard, + &ssam_node_hid_kip_penstash, + &ssam_node_hid_kip_touchpad, + &ssam_node_hid_kip_fwupd, + &ssam_node_hid_sam_sensors, + &ssam_node_hid_sam_ucm_ucsi, + NULL, +}; + /* Devices for Surface Pro 9 5G (ARM/QCOM) */ static const struct software_node *ssam_node_group_sp9_5g[] = { &ssam_node_root, &ssam_node_hub_kip, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_tmp_sensors, &ssam_node_hid_kip_keyboard, &ssam_node_hid_kip_penstash, @@ -408,8 +473,8 @@ static const struct software_node *ssam_node_group_sp9_5g[] = { static const struct software_node *ssam_node_group_sp11[] = { &ssam_node_root, &ssam_node_hub_kip, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_tmp_sensors, &ssam_node_hid_kip_keyboard, &ssam_node_hid_kip_penstash, @@ -446,19 +511,19 @@ static const struct acpi_device_id ssam_platform_hub_acpi_match[] = { { "MSHW0116", (unsigned long)ssam_node_group_sp7 }, /* Surface Pro 7+ */ - { "MSHW0119", (unsigned long)ssam_node_group_sp7 }, + { "MSHW0119", (unsigned long)ssam_node_group_sp7_dptf }, /* Surface Pro 8 */ { "MSHW0263", (unsigned long)ssam_node_group_sp8 }, /* Surface Pro 9 */ - { "MSHW0343", (unsigned long)ssam_node_group_sp9 }, + { "MSHW0343", (unsigned long)ssam_node_group_sp9_dptf }, /* Surface Pro 10 */ - { "MSHW0510", (unsigned long)ssam_node_group_sp9 }, + { "MSHW0510", (unsigned long)ssam_node_group_sp9_dptf }, /* Surface Pro 11 */ - { "MSHW0583", (unsigned long)ssam_node_group_sp9 }, + { "MSHW0583", (unsigned long)ssam_node_group_sp9_dptf }, /* Surface Pro 12 (Intel) */ { "MSHW0743", (unsigned long)ssam_node_group_sp9 }, @@ -479,10 +544,10 @@ static const struct acpi_device_id ssam_platform_hub_acpi_match[] = { { "MSHW0114", (unsigned long)ssam_node_group_sl3 }, /* Surface Laptop 3 (15", AMD) and 4 (15", AMD) */ - { "MSHW0110", (unsigned long)ssam_node_group_sl3 }, + { "MSHW0110", (unsigned long)ssam_node_group_sl3_dptf }, /* Surface Laptop 4 (13", Intel) */ - { "MSHW0250", (unsigned long)ssam_node_group_sl3 }, + { "MSHW0250", (unsigned long)ssam_node_group_sl3_dptf }, /* Surface Laptop 5 */ { "MSHW0350", (unsigned long)ssam_node_group_sl5 }, From ee0b8a79601e947648f7d99f0972d8681bda148d Mon Sep 17 00:00:00 2001 From: Lars Schellhas van Kisfeld Date: Mon, 16 Nov 2026 21:20:34 +0100 Subject: [PATCH 2/3] power: supply: surface_battery: Add DPTF battery data The battery subsystem of the Surface Aggregator Module EC provides the data that platform power management (DPTF) uses: the battery's peak and sustained power, its impedance and no-load voltage, the power available from the connected sources and the rest-of-platform power. The EC sends it as event 0x53 when the power source changes, and answers a request with the same command ID. The driver already receives the event, but drops it ("TODO: Implement support for DPTF event"). Request the data at probe time, when the external power changes and after resume from suspend (it can be stale then, for example if the power was disconnected while suspended), update it from the event, and expose it in a "dptf" attribute group on the battery. The attribute names and units follow the DPTF battery participant (drivers/acpi/dptf/dptf_power.c, INT3532). The group name is neutral on purpose: the driver does not implement that participant's interface. An EC that does not support the command does not answer the request and the request runs into a timeout, so the driver cannot use the request to find out about the support. It handles the data only on devices that have the "has_dptf" device property, which the Surface Aggregator registry sets for the devices that support it. Everywhere else the driver sends no request, ignores the event and does not create the attribute group. If the request fails on a device with the property, the driver logs a warning and goes on without the data. The first byte of the data is a version, which is 1 on the Surface Book 3. The driver warns once per device about any other value but still exposes the data, since the layout is checked by its length. User space uses this to reproduce the Windows power management, which sets, for example, the platform power limit (psys) from the available input power. On Linux it otherwise stays at its boot value. Tested on a Surface Book 3 (15", i7-1065G7, 7.3.4-1-surface) with the three patches built out of tree: the values for both batteries match the raw EC data read through the SSAM debug device, and unplugging and replugging the Surface PSU (with a USB-C charger connected) updated the base battery's available input power within a second (119.25 W -> 65 W -> 119.25 W). Over 60 s at idle the driver sent no 0x53 request and no SAM request timed out. The analysis, the patch and this changelog were prepared with the help of an AI coding assistant (Claude, Anthropic). I reviewed the change. Link: https://github.com/linux-surface/surface-aggregator-module/issues/29 Link: https://github.com/linux-surface/linux-surface/issues/2383 Signed-off-by: Lars Schellhas van Kisfeld --- .../ABI/testing/sysfs-class-power-surface | 92 +++++++++ drivers/power/supply/surface_battery.c | 175 +++++++++++++++++- 2 files changed, 261 insertions(+), 6 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-class-power-surface b/Documentation/ABI/testing/sysfs-class-power-surface index 79cde4dcf2f5e..739cbb5ee327f 100644 --- a/Documentation/ABI/testing/sysfs-class-power-surface +++ b/Documentation/ABI/testing/sysfs-class-power-surface @@ -13,3 +13,95 @@ Description: Valid values: In micro-Wh or micro-Ah, depending on the power unit of the battery + +What: /sys/class/power_supply//dptf/max_platform_power_mw +Date: November 2026 +KernelVersion: 7.4 +Contact: Lars Schellhas van Kisfeld +Description: + Maximum peak power the battery can deliver, in mW (DPTF PMAX). + + The embedded controller provides this value for platform power + management (DPTF) and updates it when the power source changes + and on resume from suspend. + The attribute is only present on devices whose embedded + controller is known to provide the data. + + Access: Read + +What: /sys/class/power_supply//dptf/max_steady_state_power_mw +Date: November 2026 +KernelVersion: 7.4 +Contact: Lars Schellhas van Kisfeld +Description: + Maximum sustained power the battery can deliver, in mW (DPTF PBSS). + + The embedded controller provides this value for platform power + management (DPTF) and updates it when the power source changes + and on resume from suspend. + The attribute is only present on devices whose embedded + controller is known to provide the data. + + Access: Read + +What: /sys/class/power_supply//dptf/high_freq_impedance_mohm +Date: November 2026 +KernelVersion: 7.4 +Contact: Lars Schellhas van Kisfeld +Description: + High-frequency impedance of the battery, in mOhm (DPTF RBHF). + + The embedded controller provides this value for platform power + management (DPTF) and updates it when the power source changes + and on resume from suspend. + The attribute is only present on devices whose embedded + controller is known to provide the data. + + Access: Read + +What: /sys/class/power_supply//dptf/no_load_voltage_mv +Date: November 2026 +KernelVersion: 7.4 +Contact: Lars Schellhas van Kisfeld +Description: + No-load voltage of the battery, in mV (DPTF VBNL). + + The embedded controller provides this value for platform power + management (DPTF) and updates it when the power source changes + and on resume from suspend. + The attribute is only present on devices whose embedded + controller is known to provide the data. + + Access: Read + +What: /sys/class/power_supply//dptf/available_input_power_mw +Date: November 2026 +KernelVersion: 7.4 +Contact: Lars Schellhas van Kisfeld +Description: + Power available to the platform from the connected power sources, + in mW, as reported by the embedded controller. + + The embedded controller provides this value for platform power + management (DPTF) and updates it when the power source changes + and on resume from suspend. + The attribute is only present on devices whose embedded + controller is known to provide the data. + + Access: Read + +What: /sys/class/power_supply//dptf/rest_of_platform_power_mw +Date: November 2026 +KernelVersion: 7.4 +Contact: Lars Schellhas van Kisfeld +Description: + Power of the rest of the platform, in mW (DPTF PROP), as reported + by the embedded controller. + + The embedded controller provides this value for platform power + management (DPTF) and updates it when the power source changes + and on resume from suspend. + The attribute is only present on devices whose embedded + controller is known to provide the data. + + Access: Read diff --git a/drivers/power/supply/surface_battery.c b/drivers/power/supply/surface_battery.c index 1273b6082311d..a3176c34dac1d 100644 --- a/drivers/power/supply/surface_battery.c +++ b/drivers/power/supply/surface_battery.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -81,6 +82,26 @@ struct spwr_bst { static_assert(sizeof(struct spwr_bst) == 16); +/* + * Battery data for platform power management (DPTF), command 0x53. The EC + * also sends it as an event when the power source changes. The field names + * follow the DPTF battery participant (see drivers/acpi/dptf/dptf_power.c). + */ +struct spwr_dptf { + __u8 version; + __le32 max_platform_power; /* mW, peak power the battery can deliver (PMAX) */ + __le32 max_steady_state_power; /* mW, sustained battery power (PBSS) */ + __le16 high_freq_impedance; /* mOhm (RBHF) */ + __le16 no_load_voltage; /* mV (VBNL) */ + __le32 available_input_power; /* mW, power available from all sources */ + __le32 rest_of_platform_power; /* mW (PROP) */ +} __packed; + +static_assert(sizeof(struct spwr_dptf) == 21); + +/* The only DPTF data version seen on devices so far (Surface Book 3). */ +#define SPWR_DPTF_VERSION 1 + #define SPWR_BIX_REVISION 0 #define SPWR_BATTERY_VALUE_UNKNOWN 0xffffffff @@ -102,6 +123,12 @@ SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_bst, struct spwr_bst, { .command_id = 0x03, }); +/* Get battery data for platform power management (DPTF). */ +SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_dptf, struct spwr_dptf, { + .target_category = SSAM_SSH_TC_BAT, + .command_id = 0x53, +}); + /* Set battery trip point (_BTP). */ SSAM_DEFINE_SYNC_REQUEST_CL_W(ssam_bat_set_btp, __le32, { .target_category = SSAM_SSH_TC_BAT, @@ -134,6 +161,10 @@ struct spwr_battery_device { struct spwr_bix bix; struct spwr_bst bst; u32 alarm; + + bool has_dptf; /* the device supports the DPTF request (device property) */ + bool dptf_version_warned; + struct spwr_dptf dptf; }; @@ -196,6 +227,47 @@ static int spwr_battery_load_bst(struct spwr_battery_device *bat) return ssam_retry(ssam_bat_get_bst, bat->sdev, &bat->bst); } +static void spwr_battery_check_dptf_version(struct spwr_battery_device *bat) +{ + lockdep_assert_held(&bat->lock); + + if (bat->dptf.version == SPWR_DPTF_VERSION || bat->dptf_version_warned) + return; + + bat->dptf_version_warned = true; + dev_warn(&bat->sdev->dev, "unexpected DPTF data version %u, the values may be wrong\n", + bat->dptf.version); +} + +static int spwr_battery_load_dptf_unlocked(struct spwr_battery_device *bat) +{ + int status; + + lockdep_assert_held(&bat->lock); + + status = ssam_retry(ssam_bat_get_dptf, bat->sdev, &bat->dptf); + if (!status) + spwr_battery_check_dptf_version(bat); + + return status; +} + +/* Reload the DPTF data, which can go stale while the driver is not notified. */ +static void spwr_battery_reload_dptf(struct spwr_battery_device *bat) +{ + int status; + + if (!bat->has_dptf) + return; + + mutex_lock(&bat->lock); + status = spwr_battery_load_dptf_unlocked(bat); + mutex_unlock(&bat->lock); + + if (status) + dev_warn(&bat->sdev->dev, "failed to update DPTF data: %d\n", status); +} + static int spwr_battery_set_alarm_unlocked(struct spwr_battery_device *bat, u32 value) { __le32 value_le = cpu_to_le32(value); @@ -340,6 +412,23 @@ static int spwr_battery_recheck_status(struct spwr_battery_device *bat) return status; } +static int spwr_battery_update_dptf(struct spwr_battery_device *bat, const struct ssam_event *event) +{ + if (!bat->has_dptf) + return 0; + + if (event->length < sizeof(bat->dptf)) + return -EPROTO; + + mutex_lock(&bat->lock); + memcpy(&bat->dptf, event->data, sizeof(bat->dptf)); + spwr_battery_check_dptf_version(bat); + mutex_unlock(&bat->lock); + + power_supply_changed(bat->psy); + return 0; +} + static u32 spwr_notify_bat(struct ssam_event_notifier *nf, const struct ssam_event *event) { struct spwr_battery_device *bat = container_of(nf, struct spwr_battery_device, notif); @@ -376,10 +465,7 @@ static u32 spwr_notify_bat(struct ssam_event_notifier *nf, const struct ssam_eve break; case SAM_EVENT_CID_BAT_DPTF: - /* - * TODO: Implement support for DPTF event. - */ - status = 0; + status = spwr_battery_update_dptf(bat, event); break; default: @@ -397,6 +483,9 @@ static void spwr_battery_update_bst_workfn(struct work_struct *work) bat = container_of(dwork, struct spwr_battery_device, update_work); + /* The EC does not send the DPTF event for every power source change. */ + spwr_battery_reload_dptf(bat); + status = spwr_battery_update_bst(bat, false); if (status) { dev_err(&bat->sdev->dev, "failed to update battery state: %d\n", status); @@ -713,7 +802,62 @@ static struct attribute *spwr_battery_attrs[] = { &dev_attr_alarm.attr, NULL, }; -ATTRIBUTE_GROUPS(spwr_battery); + +static const struct attribute_group spwr_battery_group = { + .attrs = spwr_battery_attrs, +}; + +/* -- DPTF attributes. ------------------------------------------------------ */ + +#define SPWR_DPTF_SHOW(_name, _field, _get) \ +static ssize_t _name##_show(struct device *dev, struct device_attribute *attr, char *buf) \ +{ \ + struct spwr_battery_device *bat = power_supply_get_drvdata(dev_to_psy(dev)); \ + u32 value; \ + \ + mutex_lock(&bat->lock); \ + value = _get(&bat->dptf._field); \ + mutex_unlock(&bat->lock); \ + \ + return sysfs_emit(buf, "%u\n", value); \ +} \ +static DEVICE_ATTR_RO(_name) + +SPWR_DPTF_SHOW(max_platform_power_mw, max_platform_power, get_unaligned_le32); +SPWR_DPTF_SHOW(max_steady_state_power_mw, max_steady_state_power, get_unaligned_le32); +SPWR_DPTF_SHOW(high_freq_impedance_mohm, high_freq_impedance, get_unaligned_le16); +SPWR_DPTF_SHOW(no_load_voltage_mv, no_load_voltage, get_unaligned_le16); +SPWR_DPTF_SHOW(available_input_power_mw, available_input_power, get_unaligned_le32); +SPWR_DPTF_SHOW(rest_of_platform_power_mw, rest_of_platform_power, get_unaligned_le32); + +static struct attribute *spwr_dptf_attrs[] = { + &dev_attr_max_platform_power_mw.attr, + &dev_attr_max_steady_state_power_mw.attr, + &dev_attr_high_freq_impedance_mohm.attr, + &dev_attr_no_load_voltage_mv.attr, + &dev_attr_available_input_power_mw.attr, + &dev_attr_rest_of_platform_power_mw.attr, + NULL, +}; + +static umode_t spwr_dptf_is_visible(struct kobject *kobj, struct attribute *attr, int n) +{ + struct spwr_battery_device *bat = power_supply_get_drvdata(dev_to_psy(kobj_to_dev(kobj))); + + return bat->has_dptf ? attr->mode : 0; +} + +static const struct attribute_group spwr_dptf_group = { + .name = "dptf", + .attrs = spwr_dptf_attrs, + .is_visible = spwr_dptf_is_visible, +}; + +static const struct attribute_group *spwr_battery_groups[] = { + &spwr_battery_group, + &spwr_dptf_group, + NULL, +}; /* -- Device setup. --------------------------------------------------------- */ @@ -755,6 +899,12 @@ static int spwr_battery_register(struct spwr_battery_device *bat) if ((le32_to_cpu(sta) & SAM_BATTERY_STA_OK) != SAM_BATTERY_STA_OK) return -ENODEV; + /* + * The EC does not answer the DPTF request if it does not support it, + * so only send it if the device is marked as supporting it. + */ + bat->has_dptf = device_property_read_bool(&bat->sdev->dev, "has_dptf"); + /* Satisfy lockdep although we are in an exclusive context here. */ mutex_lock(&bat->lock); @@ -764,6 +914,14 @@ static int spwr_battery_register(struct spwr_battery_device *bat) return status; } + if (bat->has_dptf) { + status = spwr_battery_load_dptf_unlocked(bat); + if (status) { + dev_warn(&bat->sdev->dev, "failed to load DPTF data: %d\n", status); + bat->has_dptf = false; + } + } + if (spwr_battery_present(bat)) { u32 cap_warn = get_unaligned_le32(&bat->bix.design_cap_warn); @@ -810,7 +968,12 @@ static int spwr_battery_register(struct spwr_battery_device *bat) static int __maybe_unused surface_battery_resume(struct device *dev) { - return spwr_battery_recheck_full(dev_get_drvdata(dev)); + struct spwr_battery_device *bat = dev_get_drvdata(dev); + + /* The power source can have changed while suspended. */ + spwr_battery_reload_dptf(bat); + + return spwr_battery_recheck_full(bat); } static SIMPLE_DEV_PM_OPS(surface_battery_pm_ops, NULL, surface_battery_resume); From f79837a12574b3f12134311a17b118caacf68b29 Mon Sep 17 00:00:00 2001 From: Lars Schellhas van Kisfeld Date: Mon, 16 Nov 2026 21:20:45 +0100 Subject: [PATCH 3/3] power: supply: surface_charger: Add the adapter rating The EC also reports the power rating of the connected adapter (DPTF ARTG, command 0x0f), next to the power source (PSRC, 0x0d) that the driver already reads. Expose it as dptf/adapter_rating_mw on the AC device, with the name and unit of the DPTF power participant (drivers/acpi/dptf/dptf_power.c, INT3407). The group name is neutral on purpose: the driver does not implement that participant's interface. Reading it fails with ENODATA while the EC reports no known rating. The driver requests the value on every read and caches nothing, so it is never stale after resume. An EC that does not support the command does not answer the request and the request runs into a timeout, so the driver cannot use the request to find out about the support. It creates the attribute only on devices that have the "has_dptf" device property, which the Surface Aggregator registry sets for the devices that support it, and sends no request otherwise. Tested on a Surface Book 3 (15", i7-1065G7, 7.3.4-1-surface) with the three patches built out of tree: it reads 120000 with the Surface PSU, matching the raw EC data read through the SSAM debug device, and 65000 while only a 65 W USB-C charger was connected. The analysis, the patch and this changelog were prepared with the help of an AI coding assistant (Claude, Anthropic). I reviewed the change. Link: https://github.com/linux-surface/surface-aggregator-module/issues/29 Signed-off-by: Lars Schellhas van Kisfeld --- .../ABI/testing/sysfs-class-power-surface | 13 ++++ drivers/power/supply/surface_charger.c | 60 +++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-power-surface b/Documentation/ABI/testing/sysfs-class-power-surface index 739cbb5ee327f..176533cd33f69 100644 --- a/Documentation/ABI/testing/sysfs-class-power-surface +++ b/Documentation/ABI/testing/sysfs-class-power-surface @@ -105,3 +105,16 @@ Description: controller is known to provide the data. Access: Read + +What: /sys/class/power_supply//dptf/adapter_rating_mw +Date: November 2026 +KernelVersion: 7.4 +Contact: Lars Schellhas van Kisfeld +Description: + Power rating of the connected adapter, in mW (DPTF ARTG), as + reported by the embedded controller. Reading it fails with + ENODATA while no rating is known. The attribute is only present + on devices whose embedded controller is known to provide the + value. + + Access: Read diff --git a/drivers/power/supply/surface_charger.c b/drivers/power/supply/surface_charger.c index d4bba6b417947..e397a0c9887d3 100644 --- a/drivers/power/supply/surface_charger.c +++ b/drivers/power/supply/surface_charger.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,15 @@ SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_psrc, __le32, { }); +/* Get the power rating of the connected adapter (DPTF ARTG), in mW. */ +SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_artg, __le32, { + .target_category = SSAM_SSH_TC_BAT, + .command_id = 0x0f, +}); + +/* ARTG value while no rating is known (e.g. no adapter connected). */ +#define SPWR_AC_ARTG_UNKNOWN 0x80000000 + /* -- Device structures. ---------------------------------------------------- */ struct spwr_psy_properties { @@ -59,6 +69,7 @@ struct spwr_ac_device { struct mutex lock; /* Guards access to state below. */ __le32 state; + bool has_artg; /* the device supports the ARTG request (device property) */ }; @@ -164,6 +175,48 @@ static int spwr_ac_get_property(struct power_supply *psy, enum power_supply_prop } +/* -- DPTF attributes. ------------------------------------------------------ */ + +static ssize_t adapter_rating_mw_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct spwr_ac_device *ac = power_supply_get_drvdata(dev_to_psy(dev)); + __le32 artg; + int status; + + status = ssam_retry(ssam_bat_get_artg, ac->sdev, &artg); + if (status) + return status; + + if (le32_to_cpu(artg) == SPWR_AC_ARTG_UNKNOWN) + return -ENODATA; + + return sysfs_emit(buf, "%u\n", le32_to_cpu(artg)); +} +static DEVICE_ATTR_RO(adapter_rating_mw); + +static struct attribute *spwr_ac_dptf_attrs[] = { + &dev_attr_adapter_rating_mw.attr, + NULL, +}; + +static umode_t spwr_ac_dptf_is_visible(struct kobject *kobj, struct attribute *attr, int n) +{ + struct spwr_ac_device *ac = power_supply_get_drvdata(dev_to_psy(kobj_to_dev(kobj))); + + return ac->has_artg ? attr->mode : 0; +} + +static const struct attribute_group spwr_ac_dptf_group = { + .name = "dptf", + .attrs = spwr_ac_dptf_attrs, + .is_visible = spwr_ac_dptf_is_visible, +}; + +static const struct attribute_group *spwr_ac_groups[] = { + &spwr_ac_dptf_group, + NULL, +}; + /* -- Device setup. --------------------------------------------------------- */ static char *battery_supplied_to[] = { @@ -208,7 +261,14 @@ static int spwr_ac_register(struct spwr_ac_device *ac) if ((le32_to_cpu(sta) & SAM_BATTERY_STA_OK) != SAM_BATTERY_STA_OK) return -ENODEV; + /* + * An EC that does not support the ARTG request does not answer it, so + * only send it on devices marked as supporting it. + */ + ac->has_artg = device_property_read_bool(&ac->sdev->dev, "has_dptf"); + psy_cfg.drv_data = ac; + psy_cfg.attr_grp = spwr_ac_groups; psy_cfg.supplied_to = battery_supplied_to; psy_cfg.num_supplicants = ARRAY_SIZE(battery_supplied_to);