From nobody Thu Dec 25 17:55:06 2025 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32183569C for ; Sat, 13 Jan 2024 18:33:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iwanders.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iwanders.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iwanders.net header.i=@iwanders.net header.b="ayA3iXRA" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-783182d4a0aso659021785a.2 for ; Sat, 13 Jan 2024 10:33:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iwanders.net; s=google; t=1705170793; x=1705775593; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=OvziupLQyzD7CXIhblfqO3HA/n00b86Rv0OXwbGfPwc=; b=ayA3iXRAae7Qvos2nxnewcRLlz5W5eGvBkPcGRMLXMAR/G6/Dl5g3QZxwe4ImcqVaT Dz8xITHPuj2ZFBxDdI1XR/Nqyh9uHZeNasswC1/fep86sQ/iyXEjMios7Ptl4rZ6Ukvq t7++7MrdH+AOPQTlBXdm/FLvkU7Cju8wDi10o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705170793; x=1705775593; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OvziupLQyzD7CXIhblfqO3HA/n00b86Rv0OXwbGfPwc=; b=m0bHb6MiiVAzYPamJ9M1AxeoWrHPIaxt/u968FVhBJDaPs0G7A+aHt5CEhsNE6+Aqe hfZ36ai4NtN0zxgQ8KMWdylwno6SyytkSHapgALO7urvCbhg7O2A+7BaccOtwv/eU0Ra 74rKSgksvhhwTwFQaMMvqS4oMieBXqcFXatHeskewpvbapN8DRNrPdnM7ej8lWTaCg/g REkrxtIl8OFWyJY3MWxlQPM8eqdtpg4U8SRIb+psyZNY3u89ZUUnObqGPampV63PaH8E XCywavzjkOAR6pcT/RzOUVzRpuqvfiWCqwgbzdwGOO5f0qsLN48bRhRCDX4DdP2KvJIx pSxQ== X-Gm-Message-State: AOJu0YyUvAXjq+na7IaaHYc1O0fy5RBKdt7PiNvo0M0zurB2Vd/QsWks yEUbmv+172MW8LuLXA8qqytZxypIDTx96A== X-Google-Smtp-Source: AGHT+IFQdnDCXCdcfpK4uPkA6Gta2loKR0Z8fUh4ZmrcJurBWNwp64j+YEmBjiyiXp6ir5rk5q8ejg== X-Received: by 2002:a05:620a:28d3:b0:783:562e:b0fc with SMTP id l19-20020a05620a28d300b00783562eb0fcmr750374qkp.7.1705170793048; Sat, 13 Jan 2024 10:33:13 -0800 (PST) Received: from eagle.lan (24-246-30-234.cable.teksavvy.com. [24.246.30.234]) by smtp.gmail.com with ESMTPSA id z4-20020ae9e604000000b0078162695b73sm1855853qkf.104.2024.01.13.10.33.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jan 2024 10:33:12 -0800 (PST) From: Ivor Wanders To: Jean Delvare , Guenter Roeck , Jonathan Corbet , Maximilian Luz , Ivor Wanders , Hans de Goede , Mark Gross Cc: linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v3 1/2] platform/surface: aggregator_registry: add entry for fan speed Date: Sat, 13 Jan 2024 13:33:05 -0500 Message-Id: <20240113183306.9566-2-ivor@iwanders.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240113183306.9566-1-ivor@iwanders.net> References: <20240113183306.9566-1-ivor@iwanders.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add an entry for the fan speed function. Add this new entry to the Surface Pro 9 group. Signed-off-by: Ivor Wanders Link: https://github.com/linux-surface/kernel/pull/144 Reviewed-by: Maximilian Luz --- Changes in v3: - No changes in this patch. Changes in v2: - No changes in this patch. --- drivers/platform/surface/surface_aggregator_registry.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drive= rs/platform/surface/surface_aggregator_registry.c index 530db4db7..b0db25886 100644 --- a/drivers/platform/surface/surface_aggregator_registry.c +++ b/drivers/platform/surface/surface_aggregator_registry.c @@ -74,6 +74,12 @@ static const struct software_node ssam_node_tmp_pprof = =3D { .parent =3D &ssam_node_root, }; =20 +/* Fan speed function. */ +static const struct software_node ssam_node_fan_speed =3D { + .name =3D "ssam:01:05:01:01:01", + .parent =3D &ssam_node_root, +}; + /* Tablet-mode switch via KIP subsystem. */ static const struct software_node ssam_node_kip_tablet_switch =3D { .name =3D "ssam:01:0e:01:00:01", @@ -319,6 +325,7 @@ static const struct software_node *ssam_node_group_sp9[= ] =3D { &ssam_node_bat_ac, &ssam_node_bat_main, &ssam_node_tmp_pprof, + &ssam_node_fan_speed, &ssam_node_pos_tablet_switch, &ssam_node_hid_kip_keyboard, &ssam_node_hid_kip_penstash, --=20 2.17.1 From nobody Thu Dec 25 17:55:06 2025 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94C2763B3 for ; Sat, 13 Jan 2024 18:33:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iwanders.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iwanders.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iwanders.net header.i=@iwanders.net header.b="VQZ0GaEy" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-680d4584a81so58758296d6.1 for ; Sat, 13 Jan 2024 10:33:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iwanders.net; s=google; t=1705170794; x=1705775594; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=MobW3+XlhTNNJtw8t3292CQToiQwtAZjiSF+JGIzm70=; b=VQZ0GaEygBOlDvtL9W3ywKxYIL5nvpTieNMfvMPZJTQ9DGkwiLShJeFLVSiMOeov+w sS8FVp7SCUHz8voV19XHHkplI4tTSxPHf+5KTKEzvXDs01NOuxGY6PjD0balwbQ7aBld OvgFe9gUBu20WyT6YvYNDoaRNxSyXRnPMa0es= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705170794; x=1705775594; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MobW3+XlhTNNJtw8t3292CQToiQwtAZjiSF+JGIzm70=; b=W3dnifSJH+dRVcg6ONCgUCtpNkZhE7S6J4mI+KfgdBsQf5Balkf11B9RiZzr4g4LdS mqKpHGege/jMoyCoD/Slx1gluR9JOctRopxBmuMBJEjAysMnQXd2syeXDChsIZZ+I+28 XzbVU4Y0GrXRrQ8hPt7pJ1esgTb+szRFqc19DaufFQ1fixRHuKsZgVxyhTdIIq3zFz9t hT5+T1mRmeGfb0tH9c58ATHHe3JDd95M+9rnCAw8iji8rtmG0F4x+ejZKaGePfIMyfAP 5AiGfTlDex+iCbk9ys8aVVvtUxaUQ3Jln2uUl9LRUNyNmxG84MMPFpk7NpOFE1vWefWd 0Glg== X-Gm-Message-State: AOJu0YxYbWYdWKD/A/vRVOH1f7REgFYMeMBsktYuWdyH6pC8cr36YM0n xOn8DWGQqX5yncUHK+j+9skbsuY4PxT9NA== X-Google-Smtp-Source: AGHT+IHw3txeHjbrRDgvhtIgYEizVnxlux09HpN6pJbzmk20j7DYEsddOP4fh4MCX+0UCO+lIaVMGQ== X-Received: by 2002:a05:6214:2427:b0:681:35b:ff6f with SMTP id gy7-20020a056214242700b00681035bff6fmr4130564qvb.29.1705170794524; Sat, 13 Jan 2024 10:33:14 -0800 (PST) Received: from eagle.lan (24-246-30-234.cable.teksavvy.com. [24.246.30.234]) by smtp.gmail.com with ESMTPSA id z4-20020ae9e604000000b0078162695b73sm1855853qkf.104.2024.01.13.10.33.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jan 2024 10:33:14 -0800 (PST) From: Ivor Wanders To: Jean Delvare , Guenter Roeck , Jonathan Corbet , Maximilian Luz , Ivor Wanders , Hans de Goede , Mark Gross Cc: linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v3 2/2] hwmon: add fan speed monitoring driver for Surface devices Date: Sat, 13 Jan 2024 13:33:06 -0500 Message-Id: <20240113183306.9566-3-ivor@iwanders.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240113183306.9566-1-ivor@iwanders.net> References: <20240113183306.9566-1-ivor@iwanders.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Adds a driver that provides read only access to the fan speed for Microsoft Surface Pro devices. The fan speed is always regulated by the EC and cannot be influenced directly. Signed-off-by: Ivor Wanders Link: https://github.com/linux-surface/kernel/pull/144 Reviewed-by: Armin Wolf Reviewed-by: Maximilian Luz --- Changes in v3: - Removed type and attr checks in read and is_visible. - Removed assigning sdev to ssam_device drvdata. - Propagate return from __ssam_fan_rpm_get. - Renamed hwmon chip name from 'fan' to 'surface_fan'. - Removed unnecessary platform_device header. Changes in v2: - Removed all sysfs attributes except fan1_input. Simplified code and updated documentation accordingly. --- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/surface_fan.rst | 25 ++++++++ MAINTAINERS | 8 +++ drivers/hwmon/Kconfig | 13 ++++ drivers/hwmon/Makefile | 1 + drivers/hwmon/surface_fan.c | 93 +++++++++++++++++++++++++++++ 6 files changed, 141 insertions(+) create mode 100644 Documentation/hwmon/surface_fan.rst create mode 100644 drivers/hwmon/surface_fan.c diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst index 042e1cf95..4dfb3b9bd 100644 --- a/Documentation/hwmon/index.rst +++ b/Documentation/hwmon/index.rst @@ -202,6 +202,7 @@ Hardware Monitoring Kernel Drivers smsc47m1 sparx5-temp stpddc60 + surface_fan sy7636a-hwmon tc654 tc74 diff --git a/Documentation/hwmon/surface_fan.rst b/Documentation/hwmon/surf= ace_fan.rst new file mode 100644 index 000000000..07942574c --- /dev/null +++ b/Documentation/hwmon/surface_fan.rst @@ -0,0 +1,25 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Kernel driver surface_fan +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + +Supported Devices: + + * Microsoft Surface Pro 9 + +Author: Ivor Wanders + +Description +----------- + +This provides monitoring of the fan found in some Microsoft Surface Pro de= vices, +like the Surface Pro 9. The fan is always controlled by the onboard contro= ller. + +Sysfs interface +--------------- + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D= =3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Name Perm Description +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D= =3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +``fan1_input`` RO Current fan speed in RPM. +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D= =3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/MAINTAINERS b/MAINTAINERS index 439cf523b..8e7870af3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14078,6 +14078,14 @@ F: Documentation/driver-api/surface_aggregator/cli= ents/dtx.rst F: drivers/platform/surface/surface_dtx.c F: include/uapi/linux/surface_aggregator/dtx.h =20 +MICROSOFT SURFACE SENSOR FAN DRIVER +M: Maximilian Luz +M: Ivor Wanders +L: linux-hwmon@vger.kernel.org +S: Maintained +F: Documentation/hwmon/surface_fan.rst +F: drivers/hwmon/surface_fan.c + MICROSOFT SURFACE GPE LID SUPPORT DRIVER M: Maximilian Luz L: platform-driver-x86@vger.kernel.org diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 307477b8a..4b4d999af 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1965,6 +1965,19 @@ config SENSORS_SMM665 This driver can also be built as a module. If so, the module will be called smm665. =20 +config SENSORS_SURFACE_FAN + tristate "Surface Fan Driver" + depends on SURFACE_AGGREGATOR + help + Driver that provides monitoring of the fan on Surface Pro devices that + have a fan, like the Surface Pro 9. + + This makes the fan's current speed accessible through the hwmon + system. It does not provide control over the fan, the firmware is + responsible for that, this driver merely provides monitoring. + + Select M or Y here, if you want to be able to read the fan's speed. + config SENSORS_ADC128D818 tristate "Texas Instruments ADC128D818" depends on I2C diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 3f4b0fda0..5ae214c06 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -198,6 +198,7 @@ obj-$(CONFIG_SENSORS_SMSC47M1) +=3D smsc47m1.o obj-$(CONFIG_SENSORS_SMSC47M192)+=3D smsc47m192.o obj-$(CONFIG_SENSORS_SPARX5) +=3D sparx5-temp.o obj-$(CONFIG_SENSORS_STTS751) +=3D stts751.o +obj-$(CONFIG_SENSORS_SURFACE_FAN)+=3D surface_fan.o obj-$(CONFIG_SENSORS_SY7636A) +=3D sy7636a-hwmon.o obj-$(CONFIG_SENSORS_AMC6821) +=3D amc6821.o obj-$(CONFIG_SENSORS_TC74) +=3D tc74.o diff --git a/drivers/hwmon/surface_fan.c b/drivers/hwmon/surface_fan.c new file mode 100644 index 000000000..7c2e3ae3e --- /dev/null +++ b/drivers/hwmon/surface_fan.c @@ -0,0 +1,93 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Surface Fan driver for Surface System Aggregator Module. It provides ac= cess + * to the fan's rpm through the hwmon system. + * + * Copyright (C) 2023 Ivor Wanders + */ + +#include +#include +#include +#include +#include + +// SSAM +SSAM_DEFINE_SYNC_REQUEST_CL_R(__ssam_fan_rpm_get, __le16, { + .target_category =3D SSAM_SSH_TC_FAN, + .command_id =3D 0x01, +}); + +// hwmon +umode_t surface_fan_hwmon_is_visible(const void *drvdata, + enum hwmon_sensor_types type, u32 attr, + int channel) +{ + return 0444; +} + +static int surface_fan_hwmon_read(struct device *dev, + enum hwmon_sensor_types type, u32 attr, + int channel, long *val) +{ + struct ssam_device *sdev =3D dev_get_drvdata(dev); + int ret; + __le16 value; + + ret =3D __ssam_fan_rpm_get(sdev, &value); + if (ret) + return ret; + + *val =3D le16_to_cpu(value); + + return ret; +} + +static const struct hwmon_channel_info *const surface_fan_info[] =3D { + HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT), + NULL +}; + +static const struct hwmon_ops surface_fan_hwmon_ops =3D { + .is_visible =3D surface_fan_hwmon_is_visible, + .read =3D surface_fan_hwmon_read, +}; + +static const struct hwmon_chip_info surface_fan_chip_info =3D { + .ops =3D &surface_fan_hwmon_ops, + .info =3D surface_fan_info, +}; + +static int surface_fan_probe(struct ssam_device *sdev) +{ + struct device *hdev; + + hdev =3D devm_hwmon_device_register_with_info(&sdev->dev, + "surface_fan", sdev, + &surface_fan_chip_info, + NULL); + if (IS_ERR(hdev)) + return PTR_ERR(hdev); + + return 0; +} + +static const struct ssam_device_id ssam_fan_match[] =3D { + { SSAM_SDEV(FAN, SAM, 0x01, 0x01) }, + {}, +}; +MODULE_DEVICE_TABLE(ssam, ssam_fan_match); + +static struct ssam_device_driver surface_fan =3D { + .probe =3D surface_fan_probe, + .match_table =3D ssam_fan_match, + .driver =3D { + .name =3D "surface_fan", + .probe_type =3D PROBE_PREFER_ASYNCHRONOUS, + }, +}; +module_ssam_device_driver(surface_fan); + +MODULE_AUTHOR("Ivor Wanders "); +MODULE_DESCRIPTION("Fan Driver for Surface System Aggregator Module"); +MODULE_LICENSE("GPL"); --=20 2.17.1