Skip to content

Commit 3d4ca76

Browse files
Wer-Wolfrafaeljw
authored andcommitted
ACPI: fan: Add hwmon notification support
The platform firmware can notify the ACPI fan device that the fan speed has changed. Relay this notification to the hwmon device if present so that userspace applications can react to it. Signed-off-by: Armin Wolf <W_Armin@gmx.de> Link: https://patch.msgid.link/20251024183824.5656-3-W_Armin@gmx.de Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 0670b9a commit 3d4ca76

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

drivers/acpi/fan.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ struct acpi_fan {
5656
struct acpi_fan_fif fif;
5757
struct acpi_fan_fps *fps;
5858
int fps_count;
59+
#if IS_REACHABLE(CONFIG_HWMON)
60+
struct device *hdev;
61+
#endif
5962
struct thermal_cooling_device *cdev;
6063
struct device_attribute fst_speed;
6164
struct device_attribute fine_grain_control;
@@ -99,8 +102,10 @@ void acpi_fan_delete_attributes(struct acpi_device *device);
99102

100103
#if IS_REACHABLE(CONFIG_HWMON)
101104
int devm_acpi_fan_create_hwmon(struct device *dev);
105+
void acpi_fan_notify_hwmon(struct device *dev);
102106
#else
103107
static inline int devm_acpi_fan_create_hwmon(struct device *dev) { return 0; };
108+
static inline void acpi_fan_notify_hwmon(struct device *dev) { };
104109
#endif
105110

106111
#endif

drivers/acpi/fan_core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ static void acpi_fan_notify_handler(acpi_handle handle, u32 event, void *context
326326
if (ret < 0)
327327
dev_err(dev, "Error retrieving current fan status: %d\n", ret);
328328

329+
acpi_fan_notify_hwmon(dev);
329330
acpi_bus_generate_netlink_event("fan", dev_name(dev), event, 0);
330331
break;
331332
default:

drivers/acpi/fan_hwmon.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,19 @@ static const struct hwmon_chip_info acpi_fan_hwmon_chip_info = {
162162
.info = acpi_fan_hwmon_info,
163163
};
164164

165+
void acpi_fan_notify_hwmon(struct device *dev)
166+
{
167+
struct acpi_fan *fan = dev_get_drvdata(dev);
168+
169+
hwmon_notify_event(fan->hdev, hwmon_fan, hwmon_fan_input, 0);
170+
}
171+
165172
int devm_acpi_fan_create_hwmon(struct device *dev)
166173
{
167174
struct acpi_fan *fan = dev_get_drvdata(dev);
168-
struct device *hdev;
169175

170-
hdev = devm_hwmon_device_register_with_info(dev, "acpi_fan", fan, &acpi_fan_hwmon_chip_info,
171-
NULL);
172-
return PTR_ERR_OR_ZERO(hdev);
176+
fan->hdev = devm_hwmon_device_register_with_info(dev, "acpi_fan", fan,
177+
&acpi_fan_hwmon_chip_info, NULL);
178+
179+
return PTR_ERR_OR_ZERO(fan->hdev);
173180
}

0 commit comments

Comments
 (0)