Repository navigation
Conversation
|
Update: tested on 7.3.4-1-surface as well, with exactly the code of this PR, built through DKMS:
|
…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>
eb0819b to
cfd8625
Compare
|
v2 after qzed's review (surface-aggregator-module#29): no more probing by request, since unsupported commands time out.
|
|
Couple of points:
|
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>
cfd8625 to
f79837a
Compare
|
Thanks, v3 pushed:
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). |
|
FYI: I'll also push a cleanup commit for the |
|
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
Does that work for you, or would you do it differently? |
The SAM EC provides the data that platform power management (DPTF) uses: event and request
0x53in the battery subsystem, and the adapter rating (0x0f) next to the power source (0x0d).surface_batteryalready receives the0x53event 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:
surface_battery: adptf_batteryattribute group on each battery. The attributes aremax_platform_power_mw,max_steady_state_power_mw,high_freq_impedance_mohm,no_load_voltage_mv,available_input_power_mwandrest_of_platform_power_mw.surface_charger:dptf_power/adapter_rating_mwon 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_mwis the one field without a DPTF counterpart there. Both are documented insysfs-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):
available_input_power_mwwithin a second (119.25 W → 65 W → 119.25 W).adapter_rating_mwread 120000 with the Surface PSU and 65000 with only USB-C.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).checkpatch.pl --strictreports 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.