2 hwmon.h - part of lm_sensors, Linux kernel modules for hardware monitoring
4 This file declares helper functions for the sysfs class "hwmon",
5 for use by sensors drivers.
7 Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com>
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.
17 #include <linux/bitops.h>
20 struct attribute_group
;
22 enum hwmon_sensor_types
{
35 enum hwmon_chip_attributes
{
36 hwmon_chip_temp_reset_history
,
37 hwmon_chip_in_reset_history
,
38 hwmon_chip_curr_reset_history
,
39 hwmon_chip_power_reset_history
,
40 hwmon_chip_register_tz
,
41 hwmon_chip_update_interval
,
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)
47 #define HWMON_C_CURR_RESET_HISTORY BIT(hwmon_chip_curr_reset_history)
48 #define HWMON_C_POWER_RESET_HISTORY BIT(hwmon_chip_power_reset_history)
49 #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)
53 enum hwmon_temp_attributes
{
57 hwmon_temp_lcrit_hyst
,
65 hwmon_temp_emergency_hyst
,
67 hwmon_temp_lcrit_alarm
,
70 hwmon_temp_crit_alarm
,
71 hwmon_temp_emergency_alarm
,
77 hwmon_temp_reset_history
,
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)
92 #define HWMON_T_ALARM BIT(hwmon_temp_alarm)
93 #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)
96 #define HWMON_T_LCRIT_ALARM BIT(hwmon_temp_lcrit_alarm)
97 #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)
105 enum hwmon_in_attributes
{
114 hwmon_in_reset_history
,
119 hwmon_in_lcrit_alarm
,
124 #define HWMON_I_INPUT BIT(hwmon_in_input)
125 #define HWMON_I_MIN BIT(hwmon_in_min)
126 #define HWMON_I_MAX BIT(hwmon_in_max)
127 #define HWMON_I_LCRIT BIT(hwmon_in_lcrit)
128 #define HWMON_I_CRIT BIT(hwmon_in_crit)
129 #define HWMON_I_AVERAGE BIT(hwmon_in_average)
130 #define HWMON_I_LOWEST BIT(hwmon_in_lowest)
131 #define HWMON_I_HIGHEST BIT(hwmon_in_highest)
132 #define HWMON_I_RESET_HISTORY BIT(hwmon_in_reset_history)
133 #define HWMON_I_LABEL BIT(hwmon_in_label)
134 #define HWMON_I_ALARM BIT(hwmon_in_alarm)
135 #define HWMON_I_MIN_ALARM BIT(hwmon_in_min_alarm)
136 #define HWMON_I_MAX_ALARM BIT(hwmon_in_max_alarm)
137 #define HWMON_I_LCRIT_ALARM BIT(hwmon_in_lcrit_alarm)
138 #define HWMON_I_CRIT_ALARM BIT(hwmon_in_crit_alarm)
139 #define HWMON_I_ENABLE BIT(hwmon_in_enable)
141 enum hwmon_curr_attributes
{
150 hwmon_curr_reset_history
,
153 hwmon_curr_min_alarm
,
154 hwmon_curr_max_alarm
,
155 hwmon_curr_lcrit_alarm
,
156 hwmon_curr_crit_alarm
,
159 #define HWMON_C_INPUT BIT(hwmon_curr_input)
160 #define HWMON_C_MIN BIT(hwmon_curr_min)
161 #define HWMON_C_MAX BIT(hwmon_curr_max)
162 #define HWMON_C_LCRIT BIT(hwmon_curr_lcrit)
163 #define HWMON_C_CRIT BIT(hwmon_curr_crit)
164 #define HWMON_C_AVERAGE BIT(hwmon_curr_average)
165 #define HWMON_C_LOWEST BIT(hwmon_curr_lowest)
166 #define HWMON_C_HIGHEST BIT(hwmon_curr_highest)
167 #define HWMON_C_RESET_HISTORY BIT(hwmon_curr_reset_history)
168 #define HWMON_C_LABEL BIT(hwmon_curr_label)
169 #define HWMON_C_ALARM BIT(hwmon_curr_alarm)
170 #define HWMON_C_MIN_ALARM BIT(hwmon_curr_min_alarm)
171 #define HWMON_C_MAX_ALARM BIT(hwmon_curr_max_alarm)
172 #define HWMON_C_LCRIT_ALARM BIT(hwmon_curr_lcrit_alarm)
173 #define HWMON_C_CRIT_ALARM BIT(hwmon_curr_crit_alarm)
175 enum hwmon_power_attributes
{
177 hwmon_power_average_interval
,
178 hwmon_power_average_interval_max
,
179 hwmon_power_average_interval_min
,
180 hwmon_power_average_highest
,
181 hwmon_power_average_lowest
,
182 hwmon_power_average_max
,
183 hwmon_power_average_min
,
185 hwmon_power_input_highest
,
186 hwmon_power_input_lowest
,
187 hwmon_power_reset_history
,
188 hwmon_power_accuracy
,
190 hwmon_power_cap_hyst
,
199 hwmon_power_cap_alarm
,
200 hwmon_power_min_alarm
,
201 hwmon_power_max_alarm
,
202 hwmon_power_lcrit_alarm
,
203 hwmon_power_crit_alarm
,
206 #define HWMON_P_AVERAGE BIT(hwmon_power_average)
207 #define HWMON_P_AVERAGE_INTERVAL BIT(hwmon_power_average_interval)
208 #define HWMON_P_AVERAGE_INTERVAL_MAX BIT(hwmon_power_average_interval_max)
209 #define HWMON_P_AVERAGE_INTERVAL_MIN BIT(hwmon_power_average_interval_min)
210 #define HWMON_P_AVERAGE_HIGHEST BIT(hwmon_power_average_highest)
211 #define HWMON_P_AVERAGE_LOWEST BIT(hwmon_power_average_lowest)
212 #define HWMON_P_AVERAGE_MAX BIT(hwmon_power_average_max)
213 #define HWMON_P_AVERAGE_MIN BIT(hwmon_power_average_min)
214 #define HWMON_P_INPUT BIT(hwmon_power_input)
215 #define HWMON_P_INPUT_HIGHEST BIT(hwmon_power_input_highest)
216 #define HWMON_P_INPUT_LOWEST BIT(hwmon_power_input_lowest)
217 #define HWMON_P_RESET_HISTORY BIT(hwmon_power_reset_history)
218 #define HWMON_P_ACCURACY BIT(hwmon_power_accuracy)
219 #define HWMON_P_CAP BIT(hwmon_power_cap)
220 #define HWMON_P_CAP_HYST BIT(hwmon_power_cap_hyst)
221 #define HWMON_P_CAP_MAX BIT(hwmon_power_cap_max)
222 #define HWMON_P_CAP_MIN BIT(hwmon_power_cap_min)
223 #define HWMON_P_MIN BIT(hwmon_power_min)
224 #define HWMON_P_MAX BIT(hwmon_power_max)
225 #define HWMON_P_LCRIT BIT(hwmon_power_lcrit)
226 #define HWMON_P_CRIT BIT(hwmon_power_crit)
227 #define HWMON_P_LABEL BIT(hwmon_power_label)
228 #define HWMON_P_ALARM BIT(hwmon_power_alarm)
229 #define HWMON_P_CAP_ALARM BIT(hwmon_power_cap_alarm)
230 #define HWMON_P_MIN_ALARM BIT(hwmon_power_max_alarm)
231 #define HWMON_P_MAX_ALARM BIT(hwmon_power_max_alarm)
232 #define HWMON_P_LCRIT_ALARM BIT(hwmon_power_lcrit_alarm)
233 #define HWMON_P_CRIT_ALARM BIT(hwmon_power_crit_alarm)
235 enum hwmon_energy_attributes
{
240 #define HWMON_E_INPUT BIT(hwmon_energy_input)
241 #define HWMON_E_LABEL BIT(hwmon_energy_label)
243 enum hwmon_humidity_attributes
{
244 hwmon_humidity_input
,
245 hwmon_humidity_label
,
247 hwmon_humidity_min_hyst
,
249 hwmon_humidity_max_hyst
,
250 hwmon_humidity_alarm
,
251 hwmon_humidity_fault
,
254 #define HWMON_H_INPUT BIT(hwmon_humidity_input)
255 #define HWMON_H_LABEL BIT(hwmon_humidity_label)
256 #define HWMON_H_MIN BIT(hwmon_humidity_min)
257 #define HWMON_H_MIN_HYST BIT(hwmon_humidity_min_hyst)
258 #define HWMON_H_MAX BIT(hwmon_humidity_max)
259 #define HWMON_H_MAX_HYST BIT(hwmon_humidity_max_hyst)
260 #define HWMON_H_ALARM BIT(hwmon_humidity_alarm)
261 #define HWMON_H_FAULT BIT(hwmon_humidity_fault)
263 enum hwmon_fan_attributes
{
277 #define HWMON_F_INPUT BIT(hwmon_fan_input)
278 #define HWMON_F_LABEL BIT(hwmon_fan_label)
279 #define HWMON_F_MIN BIT(hwmon_fan_min)
280 #define HWMON_F_MAX BIT(hwmon_fan_max)
281 #define HWMON_F_DIV BIT(hwmon_fan_div)
282 #define HWMON_F_PULSES BIT(hwmon_fan_pulses)
283 #define HWMON_F_TARGET BIT(hwmon_fan_target)
284 #define HWMON_F_ALARM BIT(hwmon_fan_alarm)
285 #define HWMON_F_MIN_ALARM BIT(hwmon_fan_min_alarm)
286 #define HWMON_F_MAX_ALARM BIT(hwmon_fan_max_alarm)
287 #define HWMON_F_FAULT BIT(hwmon_fan_fault)
289 enum hwmon_pwm_attributes
{
296 #define HWMON_PWM_INPUT BIT(hwmon_pwm_input)
297 #define HWMON_PWM_ENABLE BIT(hwmon_pwm_enable)
298 #define HWMON_PWM_MODE BIT(hwmon_pwm_mode)
299 #define HWMON_PWM_FREQ BIT(hwmon_pwm_freq)
302 * struct hwmon_ops - hwmon device operations
303 * @is_visible: Callback to return attribute visibility. Mandatory.
305 * @const void *drvdata:
306 * Pointer to driver-private data structure passed
307 * as argument to hwmon_device_register_with_info().
309 * @attr: Sensor attribute
312 * The function returns the file permissions.
313 * If the return value is 0, no attribute will be created.
314 * @read: Read callback for data attributes. Mandatory if readable
315 * data attributes are present.
317 * @dev: Pointer to hardware monitoring device
319 * @attr: Sensor attribute
322 * @val: Pointer to returned value
323 * The function returns 0 on success or a negative error number.
325 * Read callback for string attributes. Mandatory if string
326 * attributes are present.
328 * @dev: Pointer to hardware monitoring device
330 * @attr: Sensor attribute
333 * @str: Pointer to returned string
334 * The function returns 0 on success or a negative error number.
335 * @write: Write callback for data attributes. Mandatory if writeable
336 * data attributes are present.
338 * @dev: Pointer to hardware monitoring device
340 * @attr: Sensor attribute
343 * @val: Value to write
344 * The function returns 0 on success or a negative error number.
347 umode_t (*is_visible
)(const void *drvdata
, enum hwmon_sensor_types type
,
348 u32 attr
, int channel
);
349 int (*read
)(struct device
*dev
, enum hwmon_sensor_types type
,
350 u32 attr
, int channel
, long *val
);
351 int (*read_string
)(struct device
*dev
, enum hwmon_sensor_types type
,
352 u32 attr
, int channel
, const char **str
);
353 int (*write
)(struct device
*dev
, enum hwmon_sensor_types type
,
354 u32 attr
, int channel
, long val
);
358 * Channel information
359 * @type: Channel type.
360 * @config: Pointer to NULL-terminated list of channel parameters.
361 * Use for per-channel attributes.
363 struct hwmon_channel_info
{
364 enum hwmon_sensor_types type
;
370 * @ops: Pointer to hwmon operations.
371 * @info: Null-terminated list of channel information.
373 struct hwmon_chip_info
{
374 const struct hwmon_ops
*ops
;
375 const struct hwmon_channel_info
**info
;
378 /* hwmon_device_register() is deprecated */
379 struct device
*hwmon_device_register(struct device
*dev
);
382 hwmon_device_register_with_groups(struct device
*dev
, const char *name
,
384 const struct attribute_group
**groups
);
386 devm_hwmon_device_register_with_groups(struct device
*dev
, const char *name
,
388 const struct attribute_group
**groups
);
390 hwmon_device_register_with_info(struct device
*dev
,
391 const char *name
, void *drvdata
,
392 const struct hwmon_chip_info
*info
,
393 const struct attribute_group
**extra_groups
);
395 devm_hwmon_device_register_with_info(struct device
*dev
,
396 const char *name
, void *drvdata
,
397 const struct hwmon_chip_info
*info
,
398 const struct attribute_group
**extra_groups
);
400 void hwmon_device_unregister(struct device
*dev
);
401 void devm_hwmon_device_unregister(struct device
*dev
);
404 * hwmon_is_bad_char - Is the char invalid in a hwmon name
405 * @ch: the char to be considered
407 * hwmon_is_bad_char() can be used to determine if the given character
408 * may not be used in a hwmon name.
410 * Returns true if the char is invalid, false otherwise.
412 static inline bool hwmon_is_bad_char(const char ch
)