]> asedeno.scripts.mit.edu Git - linux.git/blob - include/linux/hwmon.h
hwmon: (core) Add fan attribute support to new API
[linux.git] / include / linux / hwmon.h
1 /*
2     hwmon.h - part of lm_sensors, Linux kernel modules for hardware monitoring
3
4     This file declares helper functions for the sysfs class "hwmon",
5     for use by sensors drivers.
6
7     Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com>
8
9     This program is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; version 2 of the License.
12 */
13
14 #ifndef _HWMON_H_
15 #define _HWMON_H_
16
17 #include <linux/bitops.h>
18
19 struct device;
20 struct attribute_group;
21
22 enum hwmon_sensor_types {
23         hwmon_chip,
24         hwmon_temp,
25         hwmon_in,
26         hwmon_curr,
27         hwmon_power,
28         hwmon_energy,
29         hwmon_humidity,
30         hwmon_fan,
31 };
32
33 enum hwmon_chip_attributes {
34         hwmon_chip_temp_reset_history,
35         hwmon_chip_in_reset_history,
36         hwmon_chip_curr_reset_history,
37         hwmon_chip_power_reset_history,
38         hwmon_chip_register_tz,
39         hwmon_chip_update_interval,
40         hwmon_chip_alarms,
41 };
42
43 #define HWMON_C_TEMP_RESET_HISTORY      BIT(hwmon_chip_temp_reset_history)
44 #define HWMON_C_IN_RESET_HISTORY        BIT(hwmon_chip_in_reset_history)
45 #define HWMON_C_CURR_RESET_HISTORY      BIT(hwmon_chip_curr_reset_history)
46 #define HWMON_C_POWER_RESET_HISTORY     BIT(hwmon_chip_power_reset_history)
47 #define HWMON_C_REGISTER_TZ             BIT(hwmon_chip_register_tz)
48 #define HWMON_C_UPDATE_INTERVAL         BIT(hwmon_chip_update_interval)
49 #define HWMON_C_ALARMS                  BIT(hwmon_chip_alarms)
50
51 enum hwmon_temp_attributes {
52         hwmon_temp_input = 0,
53         hwmon_temp_type,
54         hwmon_temp_lcrit,
55         hwmon_temp_lcrit_hyst,
56         hwmon_temp_min,
57         hwmon_temp_min_hyst,
58         hwmon_temp_max,
59         hwmon_temp_max_hyst,
60         hwmon_temp_crit,
61         hwmon_temp_crit_hyst,
62         hwmon_temp_emergency,
63         hwmon_temp_emergency_hyst,
64         hwmon_temp_alarm,
65         hwmon_temp_lcrit_alarm,
66         hwmon_temp_min_alarm,
67         hwmon_temp_max_alarm,
68         hwmon_temp_crit_alarm,
69         hwmon_temp_emergency_alarm,
70         hwmon_temp_fault,
71         hwmon_temp_offset,
72         hwmon_temp_label,
73         hwmon_temp_lowest,
74         hwmon_temp_highest,
75         hwmon_temp_reset_history,
76 };
77
78 #define HWMON_T_INPUT           BIT(hwmon_temp_input)
79 #define HWMON_T_TYPE            BIT(hwmon_temp_type)
80 #define HWMON_T_LCRIT           BIT(hwmon_temp_lcrit)
81 #define HWMON_T_LCRIT_HYST      BIT(hwmon_temp_lcrit_hyst)
82 #define HWMON_T_MIN             BIT(hwmon_temp_min)
83 #define HWMON_T_MIN_HYST        BIT(hwmon_temp_min_hyst)
84 #define HWMON_T_MAX             BIT(hwmon_temp_max)
85 #define HWMON_T_MAX_HYST        BIT(hwmon_temp_max_hyst)
86 #define HWMON_T_CRIT            BIT(hwmon_temp_crit)
87 #define HWMON_T_CRIT_HYST       BIT(hwmon_temp_crit_hyst)
88 #define HWMON_T_EMERGENCY       BIT(hwmon_temp_emergency)
89 #define HWMON_T_EMERGENCY_HYST  BIT(hwmon_temp_emergency_hyst)
90 #define HWMON_T_MIN_ALARM       BIT(hwmon_temp_min_alarm)
91 #define HWMON_T_MAX_ALARM       BIT(hwmon_temp_max_alarm)
92 #define HWMON_T_CRIT_ALARM      BIT(hwmon_temp_crit_alarm)
93 #define HWMON_T_EMERGENCY_ALARM BIT(hwmon_temp_emergency_alarm)
94 #define HWMON_T_FAULT           BIT(hwmon_temp_fault)
95 #define HWMON_T_OFFSET          BIT(hwmon_temp_offset)
96 #define HWMON_T_LABEL           BIT(hwmon_temp_label)
97 #define HWMON_T_LOWEST          BIT(hwmon_temp_lowest)
98 #define HWMON_T_HIGHEST         BIT(hwmon_temp_highest)
99 #define HWMON_T_RESET_HISTORY   BIT(hwmon_temp_reset_history)
100
101 enum hwmon_in_attributes {
102         hwmon_in_input,
103         hwmon_in_min,
104         hwmon_in_max,
105         hwmon_in_lcrit,
106         hwmon_in_crit,
107         hwmon_in_average,
108         hwmon_in_lowest,
109         hwmon_in_highest,
110         hwmon_in_reset_history,
111         hwmon_in_label,
112         hwmon_in_alarm,
113         hwmon_in_min_alarm,
114         hwmon_in_max_alarm,
115         hwmon_in_lcrit_alarm,
116         hwmon_in_crit_alarm,
117 };
118
119 #define HWMON_I_INPUT           BIT(hwmon_in_input)
120 #define HWMON_I_MIN             BIT(hwmon_in_min)
121 #define HWMON_I_MAX             BIT(hwmon_in_max)
122 #define HWMON_I_LCRIT           BIT(hwmon_in_lcrit)
123 #define HWMON_I_CRIT            BIT(hwmon_in_crit)
124 #define HWMON_I_AVERAGE         BIT(hwmon_in_average)
125 #define HWMON_I_LOWEST          BIT(hwmon_in_lowest)
126 #define HWMON_I_HIGHEST         BIT(hwmon_in_highest)
127 #define HWMON_I_RESET_HISTORY   BIT(hwmon_in_reset_history)
128 #define HWMON_I_LABEL           BIT(hwmon_in_label)
129 #define HWMON_I_ALARM           BIT(hwmon_in_alarm)
130 #define HWMON_I_MIN_ALARM       BIT(hwmon_in_min_alarm)
131 #define HWMON_I_MAX_ALARM       BIT(hwmon_in_max_alarm)
132 #define HWMON_I_LCRIT_ALARM     BIT(hwmon_in_lcrit_alarm)
133 #define HWMON_I_CRIT_ALARM      BIT(hwmon_in_crit_alarm)
134
135 enum hwmon_curr_attributes {
136         hwmon_curr_input,
137         hwmon_curr_min,
138         hwmon_curr_max,
139         hwmon_curr_lcrit,
140         hwmon_curr_crit,
141         hwmon_curr_average,
142         hwmon_curr_lowest,
143         hwmon_curr_highest,
144         hwmon_curr_reset_history,
145         hwmon_curr_label,
146         hwmon_curr_alarm,
147         hwmon_curr_min_alarm,
148         hwmon_curr_max_alarm,
149         hwmon_curr_lcrit_alarm,
150         hwmon_curr_crit_alarm,
151 };
152
153 #define HWMON_C_INPUT           BIT(hwmon_curr_input)
154 #define HWMON_C_MIN             BIT(hwmon_curr_min)
155 #define HWMON_C_MAX             BIT(hwmon_curr_max)
156 #define HWMON_C_LCRIT           BIT(hwmon_curr_lcrit)
157 #define HWMON_C_CRIT            BIT(hwmon_curr_crit)
158 #define HWMON_C_AVERAGE         BIT(hwmon_curr_average)
159 #define HWMON_C_LOWEST          BIT(hwmon_curr_lowest)
160 #define HWMON_C_HIGHEST         BIT(hwmon_curr_highest)
161 #define HWMON_C_RESET_HISTORY   BIT(hwmon_curr_reset_history)
162 #define HWMON_C_LABEL           BIT(hwmon_curr_label)
163 #define HWMON_C_ALARM           BIT(hwmon_curr_alarm)
164 #define HWMON_C_MIN_ALARM       BIT(hwmon_curr_min_alarm)
165 #define HWMON_C_MAX_ALARM       BIT(hwmon_curr_max_alarm)
166 #define HWMON_C_LCRIT_ALARM     BIT(hwmon_curr_lcrit_alarm)
167 #define HWMON_C_CRIT_ALARM      BIT(hwmon_curr_crit_alarm)
168
169 enum hwmon_power_attributes {
170         hwmon_power_average,
171         hwmon_power_average_interval,
172         hwmon_power_average_interval_max,
173         hwmon_power_average_interval_min,
174         hwmon_power_average_highest,
175         hwmon_power_average_lowest,
176         hwmon_power_average_max,
177         hwmon_power_average_min,
178         hwmon_power_input,
179         hwmon_power_input_highest,
180         hwmon_power_input_lowest,
181         hwmon_power_reset_history,
182         hwmon_power_accuracy,
183         hwmon_power_cap,
184         hwmon_power_cap_hyst,
185         hwmon_power_cap_max,
186         hwmon_power_cap_min,
187         hwmon_power_max,
188         hwmon_power_crit,
189         hwmon_power_label,
190         hwmon_power_alarm,
191         hwmon_power_cap_alarm,
192         hwmon_power_max_alarm,
193         hwmon_power_crit_alarm,
194 };
195
196 #define HWMON_P_AVERAGE                 BIT(hwmon_power_average)
197 #define HWMON_P_AVERAGE_INTERVAL        BIT(hwmon_power_average_interval)
198 #define HWMON_P_AVERAGE_INTERVAL_MAX    BIT(hwmon_power_average_interval_max)
199 #define HWMON_P_AVERAGE_INTERVAL_MIN    BIT(hwmon_power_average_interval_min)
200 #define HWMON_P_AVERAGE_HIGHEST         BIT(hwmon_power_average_highest)
201 #define HWMON_P_AVERAGE_LOWEST          BIT(hwmon_power_average_lowest)
202 #define HWMON_P_AVERAGE_MAX             BIT(hwmon_power_average_max)
203 #define HWMON_P_AVERAGE_MIN             BIT(hwmon_power_average_min)
204 #define HWMON_P_INPUT                   BIT(hwmon_power_input)
205 #define HWMON_P_INPUT_HIGHEST           BIT(hwmon_power_input_highest)
206 #define HWMON_P_INPUT_LOWEST            BIT(hwmon_power_input_lowest)
207 #define HWMON_P_RESET_HISTORY           BIT(hwmon_power_reset_history)
208 #define HWMON_P_ACCURACY                BIT(hwmon_power_accuracy)
209 #define HWMON_P_CAP                     BIT(hwmon_power_cap)
210 #define HWMON_P_CAP_HYST                BIT(hwmon_power_cap_hyst)
211 #define HWMON_P_CAP_MAX                 BIT(hwmon_power_cap_max)
212 #define HWMON_P_CAP_MIN                 BIT(hwmon_power_cap_min)
213 #define HWMON_P_MAX                     BIT(hwmon_power_max)
214 #define HWMON_P_CRIT                    BIT(hwmon_power_crit)
215 #define HWMON_P_LABEL                   BIT(hwmon_power_label)
216 #define HWMON_P_ALARM                   BIT(hwmon_power_alarm)
217 #define HWMON_P_CAP_ALARM               BIT(hwmon_power_cap_alarm)
218 #define HWMON_P_MAX_ALARM               BIT(hwmon_power_max_alarm)
219 #define HWMON_P_CRIT_ALARM              BIT(hwmon_power_crit_alarm)
220
221 enum hwmon_energy_attributes {
222         hwmon_energy_input,
223         hwmon_energy_label,
224 };
225
226 #define HWMON_E_INPUT                   BIT(hwmon_energy_input)
227 #define HWMON_E_LABEL                   BIT(hwmon_energy_label)
228
229 enum hwmon_humidity_attributes {
230         hwmon_humidity_input,
231         hwmon_humidity_label,
232         hwmon_humidity_min,
233         hwmon_humidity_min_hyst,
234         hwmon_humidity_max,
235         hwmon_humidity_max_hyst,
236         hwmon_humidity_alarm,
237         hwmon_humidity_fault,
238 };
239
240 #define HWMON_H_INPUT                   BIT(hwmon_humidity_input)
241 #define HWMON_H_LABEL                   BIT(hwmon_humidity_label)
242 #define HWMON_H_MIN                     BIT(hwmon_humidity_min)
243 #define HWMON_H_MIN_HYST                BIT(hwmon_humidity_min_hyst)
244 #define HWMON_H_MAX                     BIT(hwmon_humidity_max)
245 #define HWMON_H_MAX_HYST                BIT(hwmon_humidity_max_hyst)
246 #define HWMON_H_ALARM                   BIT(hwmon_humidity_alarm)
247 #define HWMON_H_FAULT                   BIT(hwmon_humidity_fault)
248
249 enum hwmon_fan_attributes {
250         hwmon_fan_input,
251         hwmon_fan_label,
252         hwmon_fan_min,
253         hwmon_fan_max,
254         hwmon_fan_div,
255         hwmon_fan_pulses,
256         hwmon_fan_target,
257         hwmon_fan_alarm,
258         hwmon_fan_min_alarm,
259         hwmon_fan_max_alarm,
260         hwmon_fan_fault,
261 };
262
263 #define HWMON_F_INPUT                   BIT(hwmon_fan_input)
264 #define HWMON_F_LABEL                   BIT(hwmon_fan_label)
265 #define HWMON_F_MIN                     BIT(hwmon_fan_min)
266 #define HWMON_F_MAX                     BIT(hwmon_fan_max)
267 #define HWMON_F_DIV                     BIT(hwmon_fan_div)
268 #define HWMON_F_PULSES                  BIT(hwmon_fan_pulses)
269 #define HWMON_F_TARGET                  BIT(hwmon_fan_target)
270 #define HWMON_F_ALARM                   BIT(hwmon_fan_alarm)
271 #define HWMON_F_MIN_ALARM               BIT(hwmon_fan_min_alarm)
272 #define HWMON_F_MAX_ALARM               BIT(hwmon_fan_max_alarm)
273 #define HWMON_F_FAULT                   BIT(hwmon_fan_fault)
274
275 /**
276  * struct hwmon_ops - hwmon device operations
277  * @is_visible: Callback to return attribute visibility. Mandatory.
278  *              Parameters are:
279  *              @const void *drvdata:
280  *                      Pointer to driver-private data structure passed
281  *                      as argument to hwmon_device_register_with_info().
282  *              @type:  Sensor type
283  *              @attr:  Sensor attribute
284  *              @channel:
285  *                      Channel number
286  *              The function returns the file permissions.
287  *              If the return value is 0, no attribute will be created.
288  * @read:       Read callback. Optional. If not provided, attributes
289  *              will not be readable.
290  *              Parameters are:
291  *              @dev:   Pointer to hardware monitoring device
292  *              @type:  Sensor type
293  *              @attr:  Sensor attribute
294  *              @channel:
295  *                      Channel number
296  *              @val:   Pointer to returned value
297  *              The function returns 0 on success or a negative error number.
298  * @write:      Write callback. Optional. If not provided, attributes
299  *              will not be writable.
300  *              Parameters are:
301  *              @dev:   Pointer to hardware monitoring device
302  *              @type:  Sensor type
303  *              @attr:  Sensor attribute
304  *              @channel:
305  *                      Channel number
306  *              @val:   Value to write
307  *              The function returns 0 on success or a negative error number.
308  */
309 struct hwmon_ops {
310         umode_t (*is_visible)(const void *drvdata, enum hwmon_sensor_types type,
311                               u32 attr, int channel);
312         int (*read)(struct device *dev, enum hwmon_sensor_types type,
313                     u32 attr, int channel, long *val);
314         int (*write)(struct device *dev, enum hwmon_sensor_types type,
315                      u32 attr, int channel, long val);
316 };
317
318 /**
319  * Channel information
320  * @type:       Channel type.
321  * @config:     Pointer to NULL-terminated list of channel parameters.
322  *              Use for per-channel attributes.
323  */
324 struct hwmon_channel_info {
325         enum hwmon_sensor_types type;
326         const u32 *config;
327 };
328
329 /**
330  * Chip configuration
331  * @ops:        Pointer to hwmon operations.
332  * @info:       Null-terminated list of channel information.
333  */
334 struct hwmon_chip_info {
335         const struct hwmon_ops *ops;
336         const struct hwmon_channel_info **info;
337 };
338
339 struct device *hwmon_device_register(struct device *dev);
340 struct device *
341 hwmon_device_register_with_groups(struct device *dev, const char *name,
342                                   void *drvdata,
343                                   const struct attribute_group **groups);
344 struct device *
345 devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
346                                        void *drvdata,
347                                        const struct attribute_group **groups);
348 struct device *
349 hwmon_device_register_with_info(struct device *dev,
350                                 const char *name, void *drvdata,
351                                 const struct hwmon_chip_info *info,
352                                 const struct attribute_group **groups);
353 struct device *
354 devm_hwmon_device_register_with_info(struct device *dev,
355                                      const char *name, void *drvdata,
356                                      const struct hwmon_chip_info *info,
357                                      const struct attribute_group **groups);
358
359 void hwmon_device_unregister(struct device *dev);
360 void devm_hwmon_device_unregister(struct device *dev);
361
362 #endif