xref: /linux/drivers/acpi/fan.h (revision 570f7e331f5febb30f1384817463c7e42b65ca7d)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 /*
4  * ACPI fan device IDs are shared between the fan driver and the device power
5  * management code.
6  *
7  * Add new device IDs before the generic ACPI fan one.
8  */
9 
10 #ifndef _ACPI_FAN_H_
11 #define _ACPI_FAN_H_
12 
13 #include <linux/device.h>
14 #include <linux/limits.h>
15 #include <linux/types.h>
16 
17 #define ACPI_FAN_DEVICE_IDS						\
18 	{ .id = "INT3404" },	/* Fan */				\
19 	{ .id = "INTC1044" },	/* Fan for Tiger Lake generation */	\
20 	{ .id = "INTC1048" },	/* Fan for Alder Lake generation */	\
21 	{ .id = "INTC1063" },	/* Fan for Meteor Lake generation */	\
22 	{ .id = "INTC106A" },	/* Fan for Lunar Lake generation */	\
23 	{ .id = "INTC10A2" },	/* Fan for Raptor Lake generation */	\
24 	{ .id = "INTC10D6" },	/* Fan for Panther Lake generation */	\
25 	{ .id = "INTC10FE" },	/* Fan for Wildcat Lake generation */	\
26 	{ .id = "INTC10F5" },	/* Fan for Nova Lake generation */	\
27 	{ .id = "PNP0C0B" }	/* Generic ACPI fan */
28 
29 #define ACPI_FPS_NAME_LEN	20
30 
31 struct acpi_fan_fps {
32 	u64 control;
33 	u64 trip_point;
34 	u64 speed;
35 	u64 noise_level;
36 	u64 power;
37 	char name[ACPI_FPS_NAME_LEN];
38 	struct device_attribute dev_attr;
39 };
40 
41 struct acpi_fan_fif {
42 	u8 revision;
43 	u8 fine_grain_ctrl;
44 	u8 step_size;
45 	u8 low_speed_notification;
46 };
47 
48 struct acpi_fan_fst {
49 	u64 revision;
50 	u64 control;
51 	u64 speed;
52 };
53 
54 struct acpi_fan {
55 	acpi_handle handle;
56 	bool acpi4;
57 	bool has_fst;
58 	struct acpi_fan_fif fif;
59 	struct acpi_fan_fps *fps;
60 	int fps_count;
61 	/* A value of 0 means that trippoint-related functions are not supported */
62 	u32 fan_trip_granularity;
63 #if IS_REACHABLE(CONFIG_HWMON)
64 	struct device *hdev;
65 #endif
66 	struct thermal_cooling_device *cdev;
67 	struct device_attribute fst_speed;
68 	struct device_attribute fine_grain_control;
69 };
70 
71 /**
72  * acpi_fan_speed_valid - Check if fan speed value is valid
73  * @speed: Speed value returned by the ACPI firmware
74  *
75  * Check if the fan speed value returned by the ACPI firmware is valid. This function is
76  * necessary as ACPI firmware implementations can return 0xFFFFFFFF to signal that the
77  * ACPI fan does not support speed reporting. Additionally, some buggy ACPI firmware
78  * implementations return a value larger than the 32-bit integer value defined by
79  * the ACPI specification when using placeholder values. Such invalid values are also
80  * detected by this function.
81  *
82  * Returns: True if the fan speed value is valid, false otherwise.
83  */
84 static inline bool acpi_fan_speed_valid(u64 speed)
85 {
86 	return speed < U32_MAX;
87 }
88 
89 /**
90  * acpi_fan_power_valid - Check if fan power value is valid
91  * @power: Power value returned by the ACPI firmware
92  *
93  * Check if the fan power value returned by the ACPI firmware is valid.
94  * See acpi_fan_speed_valid() for details.
95  *
96  * Returns: True if the fan power value is valid, false otherwise.
97  */
98 static inline bool acpi_fan_power_valid(u64 power)
99 {
100 	return power < U32_MAX;
101 }
102 
103 int acpi_fan_get_fst(acpi_handle handle, struct acpi_fan_fst *fst);
104 int acpi_fan_create_attributes(struct acpi_device *device);
105 void acpi_fan_delete_attributes(struct acpi_device *device);
106 
107 #if IS_REACHABLE(CONFIG_HWMON)
108 int devm_acpi_fan_create_hwmon(struct device *dev);
109 void acpi_fan_notify_hwmon(struct device *dev);
110 #else
111 static inline int devm_acpi_fan_create_hwmon(struct device *dev) { return 0; };
112 static inline void acpi_fan_notify_hwmon(struct device *dev) { };
113 #endif
114 
115 #endif
116