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