From 057ae1f37e02537e6ee9358ea376aaf77e7772ae Mon Sep 17 00:00:00 2001 From: Yuchao Tang Date: Sat, 21 Nov 2026 00:58:25 +0800 Subject: [PATCH 1/3] platform/surface: aggregator_registry: Add thermal sensors and fan speed for Surface Laptop Go The Surface Laptop Go EC provides the same thermal sensor and fan speed interfaces as newer Surface models, but ssam_node_group_slg1 does not register them yet. Add both nodes so that surface_temp and surface_fan can bind. On the Surface Laptop Go 1, the separate fan profile command has no effect, so keep ssam_node_tmp_perf_profile without the has_fan property. ssam_node_group_slg1 is shared by the Surface Laptop Go 1, 2, and 3. This change has only been tested on a Surface Laptop Go 1, where surface_temp exposes the 11 EC thermal channels and surface_fan reports the fan speed; the Go 2 and Go 3 have not been tested on hardware. Signed-off-by: Yuchao Tang --- drivers/platform/surface/surface_aggregator_registry.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c index e0c20a4355a8..fa7e11ddab6f 100644 --- a/drivers/platform/surface/surface_aggregator_registry.c +++ b/drivers/platform/surface/surface_aggregator_registry.c @@ -399,6 +399,8 @@ static const struct software_node *ssam_node_group_slg1[] = { &ssam_node_bat_ac_dptf, &ssam_node_bat_main_dptf, &ssam_node_tmp_perf_profile, + &ssam_node_tmp_sensors, + &ssam_node_fan_speed, NULL, }; From 461490fd261e3e8b4639f7ef9026374390be4739 Mon Sep 17 00:00:00 2001 From: Yuchao Tang Date: Tue, 1 Dec 2026 01:38:22 +0800 Subject: [PATCH 2/3] hwmon: surface_temp: Expose sensor 9 offset via HWMON_T_OFFSET The SAM thermal subsystem supports applying a temperature offset via command 0x24. On Windows, the Surface Management Framework uses this command on sensor 9, which corresponds to the virtual sensor I_VTS1 that drives the EC fan curve. Command 0x24 takes a 5-byte payload containing the 1-based sensor index followed by a 32-bit IEEE 754 float offset in degrees Celsius, and has no response. Consequently, writes appear to succeed even on models or channels where the EC does not implement the command. Expose this command as the hwmon temp9_offset attribute in millidegrees Celsius, gated by the has_offset device property so it is only created on verified devices. Clamp the written value to +/- 5000 millidegrees Celsius and reset the EC offset to 0 at probe, driver removal, and system shutdown so the cached value and EC RAM stay in sync. Tested on a Surface Laptop Go 1, where writing to temp9_offset shifts temp9_input by the requested amount on the next EC update tick and adjusts the fan speed accordingly. Link: https://github.com/linux-surface/linux-surface/issues/2383 Signed-off-by: Yuchao Tang --- drivers/hwmon/surface_temp.c | 130 ++++++++++++++++++++++++++++++++++- 1 file changed, 128 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/surface_temp.c b/drivers/hwmon/surface_temp.c index ba51c567aff0..619e941a1cc2 100644 --- a/drivers/hwmon/surface_temp.c +++ b/drivers/hwmon/surface_temp.c @@ -8,7 +8,10 @@ #include #include #include +#include +#include #include +#include #include #include @@ -29,6 +32,14 @@ */ #define SSAM_TMP_SENSOR_NAME_LENGTH 18 +/* + * Temperature offset limits in millidegrees Celsius and the 0-based + * channel index for sensor 9, which corresponds to I_VTS1. + */ +#define SSAM_TMP_SENSOR_OFFSET_CHANNEL 8 +#define SSAM_TMP_OFFSET_MIN (-5000L) +#define SSAM_TMP_OFFSET_MAX 5000L + struct ssam_tmp_get_name_rsp { __le16 unknown1; char unknown2; @@ -37,6 +48,13 @@ struct ssam_tmp_get_name_rsp { static_assert(sizeof(struct ssam_tmp_get_name_rsp) == 21); +struct ssam_tmp_set_offset_req { + __u8 iid; + __le32 offset_f32; +} __packed; + +static_assert(sizeof(struct ssam_tmp_set_offset_req) == 5); + SSAM_DEFINE_SYNC_REQUEST_CL_R(__ssam_tmp_get_available_sensors, __le16, { .target_category = SSAM_SSH_TC_TMP, .command_id = 0x04, @@ -52,6 +70,11 @@ SSAM_DEFINE_SYNC_REQUEST_MD_R(__ssam_tmp_get_name, struct ssam_tmp_get_name_rsp, .command_id = 0x0e, }); +SSAM_DEFINE_SYNC_REQUEST_MD_W(__ssam_tmp_set_offset, struct ssam_tmp_set_offset_req, { + .target_category = SSAM_SSH_TC_TMP, + .command_id = 0x24, +}); + static int ssam_tmp_get_available_sensors(struct ssam_device *sdev, s16 *sensors) { __le16 sensors_le; @@ -106,12 +129,52 @@ static int ssam_tmp_get_name(struct ssam_device *sdev, u8 iid, char *buf, size_t return 0; } +static u32 ssam_tmp_mc_to_f32(long mc) +{ + u32 sign = 0; + u64 scaled; + u32 mant; + int shift; + int msb; + + if (mc == 0) + return 0; + + if (mc < 0) { + sign = BIT(31); + mc = -mc; + } + + scaled = DIV_ROUND_CLOSEST_ULL((u64)mc << 34, 1000); + msb = fls64(scaled) - 1; + shift = msb - 23; + mant = (scaled + BIT_ULL(shift - 1)) >> shift; + if (mant >= BIT(24)) { + mant >>= 1; + msb++; + } + + return sign | ((127 + msb - 34) << 23) | (mant & GENMASK(22, 0)); +} + +static int ssam_tmp_set_offset(struct ssam_device *sdev, u8 iid, long offset_mc) +{ + struct ssam_tmp_set_offset_req req = { + .iid = iid, + .offset_f32 = cpu_to_le32(ssam_tmp_mc_to_f32(offset_mc)), + }; + + return __ssam_tmp_set_offset(sdev->ctrl, sdev->uid.target, iid, &req); +} + /* -- Driver.---------------------------------------------------------------- */ struct ssam_temp { struct ssam_device *sdev; s16 sensors; char names[SSAM_TMP_SENSOR_MAX_COUNT][SSAM_TMP_SENSOR_NAME_LENGTH]; + bool has_offset; + long offset; }; static umode_t ssam_temp_hwmon_is_visible(const void *data, @@ -123,6 +186,9 @@ static umode_t ssam_temp_hwmon_is_visible(const void *data, if (!(ssam_temp->sensors & BIT(channel))) return 0; + if (type == hwmon_temp && attr == hwmon_temp_offset) + return ssam_temp->has_offset ? 0644 : 0; + return 0444; } @@ -132,7 +198,35 @@ static int ssam_temp_hwmon_read(struct device *dev, { const struct ssam_temp *ssam_temp = dev_get_drvdata(dev); - return ssam_tmp_get_temperature(ssam_temp->sdev, channel + 1, value); + switch (attr) { + case hwmon_temp_input: + return ssam_tmp_get_temperature(ssam_temp->sdev, channel + 1, value); + case hwmon_temp_offset: + *value = ssam_temp->offset; + return 0; + default: + return -EOPNOTSUPP; + } +} + +static int ssam_temp_hwmon_write(struct device *dev, + enum hwmon_sensor_types type, + u32 attr, int channel, long value) +{ + struct ssam_temp *ssam_temp = dev_get_drvdata(dev); + int status; + + if (type != hwmon_temp || attr != hwmon_temp_offset || + channel != SSAM_TMP_SENSOR_OFFSET_CHANNEL || !ssam_temp->has_offset) + return -EOPNOTSUPP; + + value = clamp_val(value, SSAM_TMP_OFFSET_MIN, SSAM_TMP_OFFSET_MAX); + + status = ssam_tmp_set_offset(ssam_temp->sdev, channel + 1, value); + if (!status) + ssam_temp->offset = value; + + return status; } static int ssam_temp_hwmon_read_string(struct device *dev, @@ -157,7 +251,7 @@ static const struct hwmon_channel_info * const ssam_temp_hwmon_info[] = { HWMON_T_INPUT | HWMON_T_LABEL, HWMON_T_INPUT | HWMON_T_LABEL, HWMON_T_INPUT | HWMON_T_LABEL, - HWMON_T_INPUT | HWMON_T_LABEL, + HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET, HWMON_T_INPUT | HWMON_T_LABEL, HWMON_T_INPUT | HWMON_T_LABEL, HWMON_T_INPUT | HWMON_T_LABEL, @@ -171,6 +265,7 @@ static const struct hwmon_channel_info * const ssam_temp_hwmon_info[] = { static const struct hwmon_ops ssam_temp_hwmon_ops = { .is_visible = ssam_temp_hwmon_is_visible, .read = ssam_temp_hwmon_read, + .write = ssam_temp_hwmon_write, .read_string = ssam_temp_hwmon_read_string, }; @@ -179,6 +274,13 @@ static const struct hwmon_chip_info ssam_temp_hwmon_chip_info = { .info = ssam_temp_hwmon_info, }; +static void ssam_temp_reset_offset(void *data) +{ + struct ssam_temp *ssam_temp = data; + + ssam_tmp_set_offset(ssam_temp->sdev, SSAM_TMP_SENSOR_OFFSET_CHANNEL + 1, 0); +} + static int ssam_temp_probe(struct ssam_device *sdev) { struct ssam_temp *ssam_temp; @@ -197,6 +299,7 @@ static int ssam_temp_probe(struct ssam_device *sdev) ssam_temp->sdev = sdev; ssam_temp->sensors = sensors; + ssam_device_set_drvdata(sdev, ssam_temp); /* Retrieve the name for each available sensor. */ for (channel = 0; channel < SSAM_TMP_SENSOR_MAX_COUNT; channel++) { @@ -209,11 +312,33 @@ static int ssam_temp_probe(struct ssam_device *sdev) return status; } + if (device_property_read_bool(&sdev->dev, "has_offset") && + (sensors & BIT(SSAM_TMP_SENSOR_OFFSET_CHANNEL))) { + status = ssam_tmp_set_offset(sdev, SSAM_TMP_SENSOR_OFFSET_CHANNEL + 1, 0); + if (status) + return status; + + ssam_temp->has_offset = true; + + status = devm_add_action_or_reset(&sdev->dev, ssam_temp_reset_offset, ssam_temp); + if (status) + return status; + } + hwmon_dev = devm_hwmon_device_register_with_info(&sdev->dev, "surface_thermal", ssam_temp, &ssam_temp_hwmon_chip_info, NULL); return PTR_ERR_OR_ZERO(hwmon_dev); } +static void ssam_temp_shutdown(struct device *dev) +{ + struct ssam_temp *ssam_temp = dev_get_drvdata(dev); + + if (ssam_temp && ssam_temp->has_offset) + ssam_tmp_set_offset(ssam_temp->sdev, + SSAM_TMP_SENSOR_OFFSET_CHANNEL + 1, 0); +} + static const struct ssam_device_id ssam_temp_match[] = { { SSAM_SDEV(TMP, SAM, 0x00, 0x02) }, { SSAM_SDEV(TMP, KIP, 0x00, 0x02) }, @@ -226,6 +351,7 @@ static struct ssam_device_driver ssam_temp = { .match_table = ssam_temp_match, .driver = { .name = "surface_temp", + .shutdown = ssam_temp_shutdown, .probe_type = PROBE_PREFER_ASYNCHRONOUS, }, }; From 0eddb67c88920ffc371b9106b5d48a8a83c15e32 Mon Sep 17 00:00:00 2001 From: Yuchao Tang Date: Tue, 1 Dec 2026 01:38:54 +0800 Subject: [PATCH 3/3] platform/surface: aggregator_registry: Enable sensor offset on Surface Laptop Go 1 Add a thermal sensor software node with the has_offset property and use it for the Surface Laptop Go 1, where sensor 9 offset writes via command 0x24 have been verified on hardware. Split ssam_node_group_slg2 out from ssam_node_group_slg1 so that the Surface Laptop Go 2 and 3 keep the regular thermal sensor node until offset support is tested on them. Link: https://github.com/linux-surface/linux-surface/issues/2383 Signed-off-by: Yuchao Tang --- .../surface/surface_aggregator_registry.c | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c index fa7e11ddab6f..bf7d23ee9a54 100644 --- a/drivers/platform/surface/surface_aggregator_registry.c +++ b/drivers/platform/surface/surface_aggregator_registry.c @@ -120,6 +120,18 @@ static const struct software_node ssam_node_tmp_sensors = { .parent = &ssam_node_root, }; +/* Thermal sensors with sensor 9 temperature offset support. */ +static const struct property_entry ssam_node_tmp_sensors_has_offset[] = { + PROPERTY_ENTRY_BOOL("has_offset"), + { } +}; + +static const struct software_node ssam_node_tmp_sensors_with_offset = { + .name = "ssam:01:03:01:00:02", + .parent = &ssam_node_root, + .properties = ssam_node_tmp_sensors_has_offset, +}; + /* Thermal sensors of the Surface Book 3 base (KIP). */ static const struct software_node ssam_node_tmp_sensors_sb3base = { .name = "ssam:01:03:02:00:02", @@ -393,8 +405,19 @@ static const struct software_node *ssam_node_group_sls2[] = { NULL, }; -/* Devices for Surface Laptop Go. */ +/* Devices for Surface Laptop Go 1. */ static const struct software_node *ssam_node_group_slg1[] = { + &ssam_node_root, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, + &ssam_node_tmp_perf_profile, + &ssam_node_tmp_sensors_with_offset, + &ssam_node_fan_speed, + NULL, +}; + +/* Devices for Surface Laptop Go 2 and 3. */ +static const struct software_node *ssam_node_group_slg2[] = { &ssam_node_root, &ssam_node_bat_ac_dptf, &ssam_node_bat_main_dptf, @@ -586,10 +609,10 @@ static const struct acpi_device_id ssam_platform_hub_acpi_match[] = { { "MSHW0118", (unsigned long)ssam_node_group_slg1 }, /* Surface Laptop Go 2 */ - { "MSHW0290", (unsigned long)ssam_node_group_slg1 }, + { "MSHW0290", (unsigned long)ssam_node_group_slg2 }, /* Surface Laptop Go 3 */ - { "MSHW0440", (unsigned long)ssam_node_group_slg1 }, + { "MSHW0440", (unsigned long)ssam_node_group_slg2 }, /* Surface Laptop Studio 1 */ { "MSHW0123", (unsigned long)ssam_node_group_sls1 },