blob: 1b74ad11a5a478947cec869905fa107fc1d63f9d [file] [log] [blame]
Mark M. Hoffman12364412005-07-15 21:38:08 -04001/*
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
Guenter Roeckd5601682015-08-26 19:38:11 -070017#include <linux/bitops.h>
18
Paul Gortmaker313162d2012-01-30 11:46:54 -050019struct device;
Guenter Roeckbab22432013-07-06 13:57:23 -070020struct attribute_group;
Mark M. Hoffman12364412005-07-15 21:38:08 -040021
Guenter Roeckd5601682015-08-26 19:38:11 -070022enum hwmon_sensor_types {
23 hwmon_chip,
24 hwmon_temp,
25 hwmon_in,
26 hwmon_curr,
27 hwmon_power,
28 hwmon_energy,
Guenter Roeck6bfcca42016-06-20 11:38:37 -070029 hwmon_humidity,
Guenter Roeck8faee732016-06-25 19:52:13 -070030 hwmon_fan,
Guenter Roeckf9f7bb32016-06-26 12:20:46 -070031 hwmon_pwm,
Sudeep Hollad5753802017-09-27 16:20:50 +010032 hwmon_max,
Guenter Roeckd5601682015-08-26 19:38:11 -070033};
34
35enum hwmon_chip_attributes {
36 hwmon_chip_temp_reset_history,
Guenter Roeck00d616c2016-06-20 11:01:57 -070037 hwmon_chip_in_reset_history,
Guenter Roeck9b269472016-06-20 11:10:33 -070038 hwmon_chip_curr_reset_history,
Guenter Roeckb308f5c2016-06-20 11:27:36 -070039 hwmon_chip_power_reset_history,
Guenter Roeckd5601682015-08-26 19:38:11 -070040 hwmon_chip_register_tz,
41 hwmon_chip_update_interval,
42 hwmon_chip_alarms,
43};
44
45#define HWMON_C_TEMP_RESET_HISTORY BIT(hwmon_chip_temp_reset_history)
46#define HWMON_C_IN_RESET_HISTORY BIT(hwmon_chip_in_reset_history)
Guenter Roeck9b269472016-06-20 11:10:33 -070047#define HWMON_C_CURR_RESET_HISTORY BIT(hwmon_chip_curr_reset_history)
Guenter Roeckb308f5c2016-06-20 11:27:36 -070048#define HWMON_C_POWER_RESET_HISTORY BIT(hwmon_chip_power_reset_history)
Guenter Roeckd5601682015-08-26 19:38:11 -070049#define HWMON_C_REGISTER_TZ BIT(hwmon_chip_register_tz)
50#define HWMON_C_UPDATE_INTERVAL BIT(hwmon_chip_update_interval)
51#define HWMON_C_ALARMS BIT(hwmon_chip_alarms)
52
53enum hwmon_temp_attributes {
54 hwmon_temp_input = 0,
55 hwmon_temp_type,
56 hwmon_temp_lcrit,
57 hwmon_temp_lcrit_hyst,
58 hwmon_temp_min,
59 hwmon_temp_min_hyst,
60 hwmon_temp_max,
61 hwmon_temp_max_hyst,
62 hwmon_temp_crit,
63 hwmon_temp_crit_hyst,
64 hwmon_temp_emergency,
65 hwmon_temp_emergency_hyst,
66 hwmon_temp_alarm,
67 hwmon_temp_lcrit_alarm,
68 hwmon_temp_min_alarm,
69 hwmon_temp_max_alarm,
70 hwmon_temp_crit_alarm,
71 hwmon_temp_emergency_alarm,
72 hwmon_temp_fault,
73 hwmon_temp_offset,
74 hwmon_temp_label,
75 hwmon_temp_lowest,
76 hwmon_temp_highest,
77 hwmon_temp_reset_history,
78};
79
80#define HWMON_T_INPUT BIT(hwmon_temp_input)
81#define HWMON_T_TYPE BIT(hwmon_temp_type)
82#define HWMON_T_LCRIT BIT(hwmon_temp_lcrit)
83#define HWMON_T_LCRIT_HYST BIT(hwmon_temp_lcrit_hyst)
84#define HWMON_T_MIN BIT(hwmon_temp_min)
85#define HWMON_T_MIN_HYST BIT(hwmon_temp_min_hyst)
86#define HWMON_T_MAX BIT(hwmon_temp_max)
87#define HWMON_T_MAX_HYST BIT(hwmon_temp_max_hyst)
88#define HWMON_T_CRIT BIT(hwmon_temp_crit)
89#define HWMON_T_CRIT_HYST BIT(hwmon_temp_crit_hyst)
90#define HWMON_T_EMERGENCY BIT(hwmon_temp_emergency)
91#define HWMON_T_EMERGENCY_HYST BIT(hwmon_temp_emergency_hyst)
Peter Huewea5023a92017-03-17 00:28:56 +010092#define HWMON_T_ALARM BIT(hwmon_temp_alarm)
Guenter Roeckd5601682015-08-26 19:38:11 -070093#define HWMON_T_MIN_ALARM BIT(hwmon_temp_min_alarm)
94#define HWMON_T_MAX_ALARM BIT(hwmon_temp_max_alarm)
95#define HWMON_T_CRIT_ALARM BIT(hwmon_temp_crit_alarm)
Andrew Lunn2fe31e42018-07-17 21:48:10 +020096#define HWMON_T_LCRIT_ALARM BIT(hwmon_temp_lcrit_alarm)
Guenter Roeckd5601682015-08-26 19:38:11 -070097#define HWMON_T_EMERGENCY_ALARM BIT(hwmon_temp_emergency_alarm)
98#define HWMON_T_FAULT BIT(hwmon_temp_fault)
99#define HWMON_T_OFFSET BIT(hwmon_temp_offset)
100#define HWMON_T_LABEL BIT(hwmon_temp_label)
101#define HWMON_T_LOWEST BIT(hwmon_temp_lowest)
102#define HWMON_T_HIGHEST BIT(hwmon_temp_highest)
103#define HWMON_T_RESET_HISTORY BIT(hwmon_temp_reset_history)
104
Guenter Roeck00d616c2016-06-20 11:01:57 -0700105enum hwmon_in_attributes {
106 hwmon_in_input,
107 hwmon_in_min,
108 hwmon_in_max,
109 hwmon_in_lcrit,
110 hwmon_in_crit,
111 hwmon_in_average,
112 hwmon_in_lowest,
113 hwmon_in_highest,
114 hwmon_in_reset_history,
115 hwmon_in_label,
116 hwmon_in_alarm,
117 hwmon_in_min_alarm,
118 hwmon_in_max_alarm,
119 hwmon_in_lcrit_alarm,
120 hwmon_in_crit_alarm,
121};
122
123#define HWMON_I_INPUT BIT(hwmon_in_input)
124#define HWMON_I_MIN BIT(hwmon_in_min)
125#define HWMON_I_MAX BIT(hwmon_in_max)
126#define HWMON_I_LCRIT BIT(hwmon_in_lcrit)
127#define HWMON_I_CRIT BIT(hwmon_in_crit)
128#define HWMON_I_AVERAGE BIT(hwmon_in_average)
129#define HWMON_I_LOWEST BIT(hwmon_in_lowest)
130#define HWMON_I_HIGHEST BIT(hwmon_in_highest)
131#define HWMON_I_RESET_HISTORY BIT(hwmon_in_reset_history)
132#define HWMON_I_LABEL BIT(hwmon_in_label)
133#define HWMON_I_ALARM BIT(hwmon_in_alarm)
134#define HWMON_I_MIN_ALARM BIT(hwmon_in_min_alarm)
135#define HWMON_I_MAX_ALARM BIT(hwmon_in_max_alarm)
136#define HWMON_I_LCRIT_ALARM BIT(hwmon_in_lcrit_alarm)
137#define HWMON_I_CRIT_ALARM BIT(hwmon_in_crit_alarm)
138
Guenter Roeck9b269472016-06-20 11:10:33 -0700139enum hwmon_curr_attributes {
140 hwmon_curr_input,
141 hwmon_curr_min,
142 hwmon_curr_max,
143 hwmon_curr_lcrit,
144 hwmon_curr_crit,
145 hwmon_curr_average,
146 hwmon_curr_lowest,
147 hwmon_curr_highest,
148 hwmon_curr_reset_history,
149 hwmon_curr_label,
150 hwmon_curr_alarm,
151 hwmon_curr_min_alarm,
152 hwmon_curr_max_alarm,
153 hwmon_curr_lcrit_alarm,
154 hwmon_curr_crit_alarm,
155};
156
157#define HWMON_C_INPUT BIT(hwmon_curr_input)
158#define HWMON_C_MIN BIT(hwmon_curr_min)
159#define HWMON_C_MAX BIT(hwmon_curr_max)
160#define HWMON_C_LCRIT BIT(hwmon_curr_lcrit)
161#define HWMON_C_CRIT BIT(hwmon_curr_crit)
162#define HWMON_C_AVERAGE BIT(hwmon_curr_average)
163#define HWMON_C_LOWEST BIT(hwmon_curr_lowest)
164#define HWMON_C_HIGHEST BIT(hwmon_curr_highest)
165#define HWMON_C_RESET_HISTORY BIT(hwmon_curr_reset_history)
166#define HWMON_C_LABEL BIT(hwmon_curr_label)
167#define HWMON_C_ALARM BIT(hwmon_curr_alarm)
168#define HWMON_C_MIN_ALARM BIT(hwmon_curr_min_alarm)
169#define HWMON_C_MAX_ALARM BIT(hwmon_curr_max_alarm)
170#define HWMON_C_LCRIT_ALARM BIT(hwmon_curr_lcrit_alarm)
171#define HWMON_C_CRIT_ALARM BIT(hwmon_curr_crit_alarm)
172
Guenter Roeckb308f5c2016-06-20 11:27:36 -0700173enum hwmon_power_attributes {
174 hwmon_power_average,
175 hwmon_power_average_interval,
176 hwmon_power_average_interval_max,
177 hwmon_power_average_interval_min,
178 hwmon_power_average_highest,
179 hwmon_power_average_lowest,
180 hwmon_power_average_max,
181 hwmon_power_average_min,
182 hwmon_power_input,
183 hwmon_power_input_highest,
184 hwmon_power_input_lowest,
185 hwmon_power_reset_history,
186 hwmon_power_accuracy,
187 hwmon_power_cap,
188 hwmon_power_cap_hyst,
189 hwmon_power_cap_max,
190 hwmon_power_cap_min,
191 hwmon_power_max,
192 hwmon_power_crit,
193 hwmon_power_label,
194 hwmon_power_alarm,
195 hwmon_power_cap_alarm,
196 hwmon_power_max_alarm,
197 hwmon_power_crit_alarm,
198};
199
200#define HWMON_P_AVERAGE BIT(hwmon_power_average)
201#define HWMON_P_AVERAGE_INTERVAL BIT(hwmon_power_average_interval)
202#define HWMON_P_AVERAGE_INTERVAL_MAX BIT(hwmon_power_average_interval_max)
203#define HWMON_P_AVERAGE_INTERVAL_MIN BIT(hwmon_power_average_interval_min)
204#define HWMON_P_AVERAGE_HIGHEST BIT(hwmon_power_average_highest)
205#define HWMON_P_AVERAGE_LOWEST BIT(hwmon_power_average_lowest)
206#define HWMON_P_AVERAGE_MAX BIT(hwmon_power_average_max)
207#define HWMON_P_AVERAGE_MIN BIT(hwmon_power_average_min)
208#define HWMON_P_INPUT BIT(hwmon_power_input)
209#define HWMON_P_INPUT_HIGHEST BIT(hwmon_power_input_highest)
210#define HWMON_P_INPUT_LOWEST BIT(hwmon_power_input_lowest)
211#define HWMON_P_RESET_HISTORY BIT(hwmon_power_reset_history)
212#define HWMON_P_ACCURACY BIT(hwmon_power_accuracy)
213#define HWMON_P_CAP BIT(hwmon_power_cap)
214#define HWMON_P_CAP_HYST BIT(hwmon_power_cap_hyst)
215#define HWMON_P_CAP_MAX BIT(hwmon_power_cap_max)
216#define HWMON_P_CAP_MIN BIT(hwmon_power_cap_min)
217#define HWMON_P_MAX BIT(hwmon_power_max)
218#define HWMON_P_CRIT BIT(hwmon_power_crit)
219#define HWMON_P_LABEL BIT(hwmon_power_label)
220#define HWMON_P_ALARM BIT(hwmon_power_alarm)
221#define HWMON_P_CAP_ALARM BIT(hwmon_power_cap_alarm)
222#define HWMON_P_MAX_ALARM BIT(hwmon_power_max_alarm)
223#define HWMON_P_CRIT_ALARM BIT(hwmon_power_crit_alarm)
224
Guenter Roeck6bfcca42016-06-20 11:38:37 -0700225enum hwmon_energy_attributes {
226 hwmon_energy_input,
227 hwmon_energy_label,
228};
229
230#define HWMON_E_INPUT BIT(hwmon_energy_input)
231#define HWMON_E_LABEL BIT(hwmon_energy_label)
232
233enum hwmon_humidity_attributes {
234 hwmon_humidity_input,
235 hwmon_humidity_label,
236 hwmon_humidity_min,
237 hwmon_humidity_min_hyst,
238 hwmon_humidity_max,
239 hwmon_humidity_max_hyst,
240 hwmon_humidity_alarm,
241 hwmon_humidity_fault,
242};
243
244#define HWMON_H_INPUT BIT(hwmon_humidity_input)
245#define HWMON_H_LABEL BIT(hwmon_humidity_label)
246#define HWMON_H_MIN BIT(hwmon_humidity_min)
247#define HWMON_H_MIN_HYST BIT(hwmon_humidity_min_hyst)
248#define HWMON_H_MAX BIT(hwmon_humidity_max)
249#define HWMON_H_MAX_HYST BIT(hwmon_humidity_max_hyst)
250#define HWMON_H_ALARM BIT(hwmon_humidity_alarm)
251#define HWMON_H_FAULT BIT(hwmon_humidity_fault)
252
Guenter Roeck8faee732016-06-25 19:52:13 -0700253enum hwmon_fan_attributes {
254 hwmon_fan_input,
255 hwmon_fan_label,
256 hwmon_fan_min,
257 hwmon_fan_max,
258 hwmon_fan_div,
259 hwmon_fan_pulses,
260 hwmon_fan_target,
261 hwmon_fan_alarm,
262 hwmon_fan_min_alarm,
263 hwmon_fan_max_alarm,
264 hwmon_fan_fault,
265};
266
267#define HWMON_F_INPUT BIT(hwmon_fan_input)
268#define HWMON_F_LABEL BIT(hwmon_fan_label)
269#define HWMON_F_MIN BIT(hwmon_fan_min)
270#define HWMON_F_MAX BIT(hwmon_fan_max)
271#define HWMON_F_DIV BIT(hwmon_fan_div)
272#define HWMON_F_PULSES BIT(hwmon_fan_pulses)
273#define HWMON_F_TARGET BIT(hwmon_fan_target)
274#define HWMON_F_ALARM BIT(hwmon_fan_alarm)
275#define HWMON_F_MIN_ALARM BIT(hwmon_fan_min_alarm)
276#define HWMON_F_MAX_ALARM BIT(hwmon_fan_max_alarm)
277#define HWMON_F_FAULT BIT(hwmon_fan_fault)
278
Guenter Roeckf9f7bb32016-06-26 12:20:46 -0700279enum hwmon_pwm_attributes {
280 hwmon_pwm_input,
281 hwmon_pwm_enable,
282 hwmon_pwm_mode,
283 hwmon_pwm_freq,
284};
285
286#define HWMON_PWM_INPUT BIT(hwmon_pwm_input)
287#define HWMON_PWM_ENABLE BIT(hwmon_pwm_enable)
288#define HWMON_PWM_MODE BIT(hwmon_pwm_mode)
289#define HWMON_PWM_FREQ BIT(hwmon_pwm_freq)
290
Guenter Roeckd5601682015-08-26 19:38:11 -0700291/**
292 * struct hwmon_ops - hwmon device operations
293 * @is_visible: Callback to return attribute visibility. Mandatory.
294 * Parameters are:
295 * @const void *drvdata:
296 * Pointer to driver-private data structure passed
297 * as argument to hwmon_device_register_with_info().
298 * @type: Sensor type
299 * @attr: Sensor attribute
300 * @channel:
301 * Channel number
302 * The function returns the file permissions.
303 * If the return value is 0, no attribute will be created.
Guenter Roecke159ab52016-08-07 20:51:25 -0700304 * @read: Read callback for data attributes. Mandatory if readable
305 * data attributes are present.
Guenter Roeckd5601682015-08-26 19:38:11 -0700306 * Parameters are:
307 * @dev: Pointer to hardware monitoring device
308 * @type: Sensor type
309 * @attr: Sensor attribute
310 * @channel:
311 * Channel number
312 * @val: Pointer to returned value
313 * The function returns 0 on success or a negative error number.
Guenter Roecke159ab52016-08-07 20:51:25 -0700314 * @read_string:
315 * Read callback for string attributes. Mandatory if string
316 * attributes are present.
317 * Parameters are:
318 * @dev: Pointer to hardware monitoring device
319 * @type: Sensor type
320 * @attr: Sensor attribute
321 * @channel:
322 * Channel number
323 * @str: Pointer to returned string
324 * The function returns 0 on success or a negative error number.
325 * @write: Write callback for data attributes. Mandatory if writeable
326 * data attributes are present.
Guenter Roeckd5601682015-08-26 19:38:11 -0700327 * Parameters are:
328 * @dev: Pointer to hardware monitoring device
329 * @type: Sensor type
330 * @attr: Sensor attribute
331 * @channel:
332 * Channel number
333 * @val: Value to write
334 * The function returns 0 on success or a negative error number.
335 */
336struct hwmon_ops {
337 umode_t (*is_visible)(const void *drvdata, enum hwmon_sensor_types type,
338 u32 attr, int channel);
339 int (*read)(struct device *dev, enum hwmon_sensor_types type,
340 u32 attr, int channel, long *val);
Guenter Roecke159ab52016-08-07 20:51:25 -0700341 int (*read_string)(struct device *dev, enum hwmon_sensor_types type,
Jean Delvare5ba6bcb2017-03-07 06:15:15 -0800342 u32 attr, int channel, const char **str);
Guenter Roeckd5601682015-08-26 19:38:11 -0700343 int (*write)(struct device *dev, enum hwmon_sensor_types type,
344 u32 attr, int channel, long val);
345};
346
347/**
348 * Channel information
349 * @type: Channel type.
350 * @config: Pointer to NULL-terminated list of channel parameters.
351 * Use for per-channel attributes.
352 */
353struct hwmon_channel_info {
354 enum hwmon_sensor_types type;
355 const u32 *config;
356};
357
358/**
359 * Chip configuration
360 * @ops: Pointer to hwmon operations.
361 * @info: Null-terminated list of channel information.
362 */
363struct hwmon_chip_info {
364 const struct hwmon_ops *ops;
365 const struct hwmon_channel_info **info;
366};
367
Guenter Roeckaf1bd362016-10-16 11:31:08 -0700368/* hwmon_device_register() is deprecated */
Tony Jones1beeffe2007-08-20 13:46:20 -0700369struct device *hwmon_device_register(struct device *dev);
Guenter Roeckaf1bd362016-10-16 11:31:08 -0700370
Guenter Roeckbab22432013-07-06 13:57:23 -0700371struct device *
372hwmon_device_register_with_groups(struct device *dev, const char *name,
373 void *drvdata,
374 const struct attribute_group **groups);
Guenter Roeck74188cb2013-07-11 20:00:12 -0700375struct device *
376devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
377 void *drvdata,
378 const struct attribute_group **groups);
Guenter Roeckd5601682015-08-26 19:38:11 -0700379struct device *
380hwmon_device_register_with_info(struct device *dev,
381 const char *name, void *drvdata,
382 const struct hwmon_chip_info *info,
Guenter Roeck848ba0a2016-10-16 17:20:43 -0700383 const struct attribute_group **extra_groups);
Guenter Roeckd5601682015-08-26 19:38:11 -0700384struct device *
385devm_hwmon_device_register_with_info(struct device *dev,
Guenter Roeck848ba0a2016-10-16 17:20:43 -0700386 const char *name, void *drvdata,
387 const struct hwmon_chip_info *info,
388 const struct attribute_group **extra_groups);
Mark M. Hoffman12364412005-07-15 21:38:08 -0400389
Tony Jones1beeffe2007-08-20 13:46:20 -0700390void hwmon_device_unregister(struct device *dev);
Guenter Roeck74188cb2013-07-11 20:00:12 -0700391void devm_hwmon_device_unregister(struct device *dev);
Mark M. Hoffman12364412005-07-15 21:38:08 -0400392
Mark M. Hoffman12364412005-07-15 21:38:08 -0400393#endif