Skip to content

Surface: Expose the DPTF battery data (0x53) and the adapter rating - #195

Merged
qzed merged 3 commits into
linux-surface:v7.3-surface-develfrom
larsschellhas:surface-dptf-battery-charger
Nov 17, 2026
Merged

qzed merged 3 commits into
linux-surface:v7.3-surface-develfrom
larsschellhas:surface-dptf-battery-charger

Conversation

@larsschellhas

@larsschellhas larsschellhas commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

The SAM EC provides the data that platform power management (DPTF) uses: event and request 0x53 in the battery subsystem, and the adapter rating (0x0f) next to the power source (0x0d). surface_battery already receives the 0x53 event but drops it ("TODO: Implement support for DPTF event"). This PR exposes the data in sysfs. Background and the field decoding: linux-surface/surface-aggregator-module#29.

Two commits:

  1. surface_battery: a dptf_battery attribute group on each battery. The attributes are max_platform_power_mw, max_steady_state_power_mw, high_freq_impedance_mohm, no_load_voltage_mv, available_input_power_mw and rest_of_platform_power_mw.
    • The data are requested at probe and on external power changes, and updated from the event.
    • The group is hidden if the EC does not answer the request.
  2. surface_charger: dptf_power/adapter_rating_mw on the AC device. Reading it gives ENODATA while the EC reports no rating.

The names and units follow the existing DPTF participant ABI (drivers/acpi/dptf/dptf_power.c, Documentation/ABI/testing/sysfs-platform-dptf), so user space finds the same attributes as on Intel DPTF platforms. available_input_power_mw is the one field without a DPTF counterpart there. Both are documented in sysfs-class-power-surface.

Why: the Windows power management (SMF) sets, for example, the platform power limit (psys) from the available input power. On Linux, psys stays at its boot value (#117). A user-space implementation of the Windows behaviour is in progress (linux-surface/linux-surface#2383). For now it reads these values through the SSAM debug device, which needs root and surface_aggregator_cdev. With this PR it no longer needs either.

Testing (Surface Book 3 15", i7-1065G7, kernel 7.2.15-1-surface, drivers built out of tree):

  • Battery data: all values for both batteries match the raw EC data read through the SSAM debug device.
  • Event: unplugging and replugging the Surface PSU, with a USB-C charger connected, updated the base battery's available_input_power_mw within a second (119.25 W → 65 W → 119.25 W).
  • Adapter rating: adapter_rating_mw read 120000 with the Surface PSU and 65000 with only USB-C.
  • Kernel log: no warnings.
  • 7.3: apart from the match-table formatting, the 7.2 driver sources are identical to v7.3-surface-devel, and the patches apply unchanged. The same results hold on 7.3.4-1-surface with exactly the code of this PR, built through DKMS (see the comment below).
  • Not tested: a kernel built with these patches (only the equivalent modules), and devices other than the SB3. On devices whose EC does not answer, the attributes stay hidden.

checkpatch.pl --strict reports only "multiple blank lines" before the new /* -- … -- */ section comments, which follows the existing style of both files.

Open question: is a named attribute group on the power supply the form you'd like, or would you prefer something else? I asked this in surface-aggregator-module#29 as well.

The analysis, the patches and the changelogs were prepared with the help of an AI coding assistant (Claude, Anthropic). I reviewed the changes and tested them on the device as described.

@larsschellhas

Copy link
Copy Markdown
Contributor Author

Update: tested on 7.3.4-1-surface as well, with exactly the code of this PR, built through DKMS:

  • Both drivers bind, the dptf_battery values of both batteries and adapter_rating_mw are present, and the kernel log is clean.
  • Unplugging and replugging the Surface PSU (with USB-C connected) updated the base battery's available_input_power_mw within 2–4 s (119.25 W → 65 W → 119.25 W), and adapter_rating_mw followed (120 W → 65 W → 120 W).

…ery 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: linux-surface/surface-aggregator-module#29
Signed-off-by: Lars Schellhas van Kisfeld <lars.schellhas-van-kisfeld@schellhasconsulting.de>
@larsschellhas
larsschellhas force-pushed the surface-dptf-battery-charger branch from eb0819b to cfd8625 Compare November 16, 2026 18:49
@larsschellhas

Copy link
Copy Markdown
Contributor Author

v2 after qzed's review (surface-aggregator-module#29): no more probing by request, since unsupported commands time out.

  • New first patch: registry property has_dptf on the battery and AC nodes, set only for devices with evidence (list in the commit message).
  • Battery and charger send their requests only with the property.
  • checkpatch --strict clean. Tested on the SB3 (7.3.4): values as before, PSU replug tracked, and 60 s idle: no 0x53 request, no timeout.

@qzed

qzed commented Nov 16, 2026

Copy link
Copy Markdown
Member

Couple of points:

  • I think we should refresh the DPTF data on resume. Seems like it could get stale (e.g. power being disconnected) while the device is suspended?
  • I don't think I have a good answer to the whole group thing. It would be nice if we could follow the dptf_power/dptf_battery split already established in the other drivers, but from what I understand the EC data kind of conflicts that (with input power etc being per battery). So maybe following that naming scheme would be a bit more confusing? I'd maybe go for a neutral dptf group. The other one would suggest more compatibility than there seems to be.
  • Does the EC report a known version field? Maybe we should match/assert against that and issue a warning if it doesn't contain any expected values just to have a hint if we might be reading garbage/misinterpreting things?

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: linux-surface/surface-aggregator-module#29
Link: linux-surface/linux-surface#2383
Signed-off-by: Lars Schellhas van Kisfeld <lars.schellhas-van-kisfeld@schellhasconsulting.de>
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: linux-surface/surface-aggregator-module#29
Signed-off-by: Lars Schellhas van Kisfeld <lars.schellhas-van-kisfeld@schellhasconsulting.de>
@larsschellhas
larsschellhas force-pushed the surface-dptf-battery-charger branch from cfd8625 to f79837a Compare November 17, 2026 07:50
@larsschellhas

Copy link
Copy Markdown
Contributor Author

Thanks, v3 pushed:

  • Resume: surface_battery reloads the DPTF data on resume. The charger reads the rating on every access, so nothing to refresh there.
  • Group name: now dptf on both batteries and the AC.
  • Version: byte 0 is 1 in every 0x53 answer and event I captured on the SB3 (both batteries). The driver warns once if it differs and still exposes the data. No other device's value known yet; the Windows client I checked doesn't test it.

Tested on the SB3 (7.3.4-2, with the suspend fix): values as before, the adapter rating tracked a PSU replug (120 → 65 → 120 W), no version warning, 60 s idle: no 0x53 request, no timeout. Resume: PSU plugged in during suspend, after wake the base battery's input power was updated (65 → 119.25 W).

@qzed
qzed merged commit b762806 into linux-surface:v7.3-surface-devel Nov 17, 2026
@qzed

qzed commented Nov 17, 2026

Copy link
Copy Markdown
Member

FYI: I'll also push a cleanup commit for the _sp9 entry, renaming that to _sp12, since it's not unused. When you submit this upstream please feel free to include that/squash that in.

@larsschellhas

Copy link
Copy Markdown
Contributor Author

Before I send #190 and #195 upstream (my first upstream submission, so I'd like to get the procedure right), a proposal:

Jan's SP12 (Intel) patch is on the list but not applied yet (lore). It maps MSHW0743 to ssam_node_group_sp9, so upstream will need the same split as here.

  1. Upstream has_dptf patch: keep ssam_node_group_sp9 for SP9/10/11 and give it the DPTF nodes in place; move SP12 (Intel) to a new ssam_node_group_sp12 without DPTF. Same result as here now, just without sp9_dptf, so your rename isn't needed upstream.
  2. Downstream: a small follow-up renaming sp9_dptf back to sp9, so both sides match and the patches can simply be dropped on a later rebase. I can open the PR.
  3. Series: one series of 8 patches (Surface Book 3: Add thermal sensors and fans (main and base) #190, then Surface: Expose the DPTF battery data (0x53) and the adapter rating #195) on pdx86/for-next, on top of Jan's patch (or after it's applied). Registry patches via pdx86; the hwmon and power-supply patches either with acks via pdx86 or through their own trees, whatever the maintainers prefer.

Does that work for you, or would you do it differently?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants