Skip to contentSkip to conversation

Surface fan monitoring driver

PATCH Superseded Ivor Wanders 2 participants 5 messages Jan 30, 2024 – Jan 31, 2024

Subsystems (6)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Ivor Wanders

author maintainer
#0 lore raw

v4 cover Surface fan monitoring driver

Fourth version of a hwmon driver to monitor the fan's rpm on Microsoft Surface devices, originally submitted in [1], v2 at [2], v3 at [3]. Changes since v3 are two minor code changes based on feedback.

Changes in v4:
- Return 0 from surface_fan_hwmon_read instead of ret.
- Use PTR_ERR_OR_ZERO in probe instead of if statement.
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 unsupported sysfs attributes from the hwmon driver, leaving the fan input as the only supported attribute.

[1] https://lore.kernel.org/linux-hwmon/[email protected]/T/
[2] https://lore.kernel.org/linux-hwmon/[email protected]/T/
[3] https://lore.kernel.org/linux-hwmon/[email protected]/T/

Ivor Wanders (2):
platform/surface: aggregator_registry: add entry for fan speed
hwmon: add fan speed monitoring driver for Surface devices

 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                   | 91 +++++++++++++++++++
 .../surface/surface_aggregator_registry.c     |  7 ++
 7 files changed, 146 insertions(+)
 create mode 100644 Documentation/hwmon/surface_fan.rst
 create mode 100644 drivers/hwmon/surface_fan.c
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH v4 1/2 platform/surface: aggregator_registry: add entry for fan speed

Add an entry for the fan speed function.
Add this new entry to the Surface Pro 9 group.

---
Changes in v4:
- No changes in this patch.
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(+)
drivers/platform/surface/surface_aggregator_registry.c +7 -0
index 530db4db7..b0db25886 100644
@@ -74,6 +74,12 @@ static const struct software_node ssam_node_tmp_pprof = {
 	.parent = &ssam_node_root,
 };
 
+/* Fan speed function. */
+static const struct software_node ssam_node_fan_speed = {
+	.name = "ssam:01:05:01:01:01",
+	.parent = &ssam_node_root,
+};
+
 /* Tablet-mode switch via KIP subsystem. */
 static const struct software_node ssam_node_kip_tablet_switch = {
 	.name = "ssam:01:0e:01:00:01",
@@ -319,6 +325,7 @@ static const struct software_node *ssam_node_group_sp9[] = {
 	&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,
Signature · 1 line
2.17.1
author maintainer
#2 lore raw

PATCH v4 2/2 hwmon: add fan speed monitoring driver for Surface devices

In reply to Ivor Wanders

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.

---
Changes in v4:
- Return 0 from surface_fan_hwmon_read instead of ret.
- Use PTR_ERR_OR_ZERO in probe instead of if statement.
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         | 91 +++++++++++++++++++++++++++++
 6 files changed, 139 insertions(+)
 create mode 100644 Documentation/hwmon/surface_fan.rst
 create mode 100644 drivers/hwmon/surface_fan.c
Documentation/hwmon/index.rst +1 -0
index 042e1cf95..4dfb3b9bd 100644
@@ -202,6 +202,7 @@ Hardware Monitoring Kernel Drivers
    smsc47m1
    sparx5-temp
    stpddc60
+   surface_fan
    sy7636a-hwmon
    tc654
    tc74
Documentation/hwmon/surface_fan.rst new file +25 -0
new file mode 100644
index 000000000..07942574c
@@ -0,0 +1,25 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver surface_fan
+=========================
+
+Supported Devices:
+
+  * Microsoft Surface Pro 9
+
+Author: Ivor Wanders <[email protected]>
+
+Description
+-----------
+
+This provides monitoring of the fan found in some Microsoft Surface Pro devices,
+like the Surface Pro 9. The fan is always controlled by the onboard controller.
+
+Sysfs interface
+---------------
+
+======================= ======= =========================================
+Name                    Perm    Description
+======================= ======= =========================================
+``fan1_input``          RO      Current fan speed in RPM.
+======================= ======= =========================================
MAINTAINERS +8 -0
index 439cf523b..8e7870af3 100644
@@ -14078,6 +14078,14 @@ F:	Documentation/driver-api/surface_aggregator/clients/dtx.rst
 F:	drivers/platform/surface/surface_dtx.c
 F:	include/uapi/linux/surface_aggregator/dtx.h
 
+MICROSOFT SURFACE SENSOR FAN DRIVER
+M:	Maximilian Luz <[email protected]>
+M:	Ivor Wanders <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/hwmon/surface_fan.rst
+F:	drivers/hwmon/surface_fan.c
+
 MICROSOFT SURFACE GPE LID SUPPORT DRIVER
 M:	Maximilian Luz <[email protected]>
 L:	[email protected]
drivers/hwmon/Kconfig +13 -0
index 307477b8a..4b4d999af 100644
@@ -1965,6 +1965,19 @@ config SENSORS_SMM665
 	  This driver can also be built as a module. If so, the module will
 	  be called smm665.
 
+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
drivers/hwmon/Makefile +1 -0
index 3f4b0fda0..5ae214c06 100644
@@ -198,6 +198,7 @@ obj-$(CONFIG_SENSORS_SMSC47M1)	+= smsc47m1.o
 obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
 obj-$(CONFIG_SENSORS_SPARX5)	+= sparx5-temp.o
 obj-$(CONFIG_SENSORS_STTS751)	+= stts751.o
+obj-$(CONFIG_SENSORS_SURFACE_FAN)+= surface_fan.o
 obj-$(CONFIG_SENSORS_SY7636A)	+= sy7636a-hwmon.o
 obj-$(CONFIG_SENSORS_AMC6821)	+= amc6821.o
 obj-$(CONFIG_SENSORS_TC74)	+= tc74.o
drivers/hwmon/surface_fan.c new file +91 -0

91 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#3 lore raw

Re: [PATCH v4 2/2] hwmon: add fan speed monitoring driver for Surface devices

drivers/hwmon/Kconfig config SENSORS_SMM665

Quoted 99 lines · Ivor Wanders

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.

---
Changes in v4:
- Return 0 from surface_fan_hwmon_read instead of ret.
- Use PTR_ERR_OR_ZERO in probe instead of if statement.
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         | 91 +++++++++++++++++++++++++++++
  6 files changed, 139 insertions(+)

create mode 100644 Documentation/hwmon/surface_fan.rst create mode 100644 drivers/hwmon/surface_fan.c

Documentation/hwmon/index.rst +1 -0
index 042e1cf95..4dfb3b9bd 100644
@@ -202,6 +202,7 @@ Hardware Monitoring Kernel Drivers
     smsc47m1
     sparx5-temp
     stpddc60
+   surface_fan
     sy7636a-hwmon
     tc654
     tc74
Documentation/hwmon/surface_fan.rst new file +25 -0
new file mode 100644
index 000000000..07942574c
@@ -0,0 +1,25 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver surface_fan
+=========================
+
+Supported Devices:
+
+  * Microsoft Surface Pro 9
+
+Author: Ivor Wanders <[email protected]>
+
+Description
+-----------
+
+This provides monitoring of the fan found in some Microsoft Surface Pro devices,
+like the Surface Pro 9. The fan is always controlled by the onboard controller.
+
+Sysfs interface
+---------------
+
+======================= ======= =========================================
+Name                    Perm    Description
+======================= ======= =========================================
+``fan1_input``          RO      Current fan speed in RPM.
+======================= ======= =========================================
MAINTAINERS +8 -0
index 439cf523b..8e7870af3 100644
@@ -14078,6 +14078,14 @@ F:	Documentation/driver-api/surface_aggregator/clients/dtx.rst
  F:	drivers/platform/surface/surface_dtx.c
  F:	include/uapi/linux/surface_aggregator/dtx.h
 
+MICROSOFT SURFACE SENSOR FAN DRIVER
+M:	Maximilian Luz <[email protected]>
+M:	Ivor Wanders <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/hwmon/surface_fan.rst
+F:	drivers/hwmon/surface_fan.c
+
  MICROSOFT SURFACE GPE LID SUPPORT DRIVER
  M:	Maximilian Luz <[email protected]>
  L:	[email protected]
drivers/hwmon/Kconfig +0 -0
index 307477b8a..4b4d999af 100644
@@ -1965,6 +1965,19 @@ config SENSORS_SMM665

I just noticed this. There is no SENSORS_SMM665 in the upstream kernel. That driver was removed in v6.7. What is your baseline ? It doesn't even seem to be based on a mainline kernel. When I try to apply the patch, it fails completely.

Applying: hwmon: add fan speed monitoring driver for Surface devices
error: sha1 information is lacking or useless (MAINTAINERS).
error: could not build fake ancestor
Patch failed at 0001 hwmon: add fan speed monitoring driver for Surface devices

Please base your patches on the latest mainline kernel.

Thanks,
Guenter

author maintainer
#4 lore raw

Re: [PATCH v4 2/2] hwmon: add fan speed monitoring driver for Surface devices

Hello Guenter,

Quoted 1 line

What is your baseline? It doesn't even seem to be based on a mainline kernel.

Ah, yes, this is from the linux-surface kernel tree, which is still on v6.6.

Quoted 1 line

Please base your patches on the latest mainline kernel.

Will rebase this and send v5 shortly.

~Ivor