]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/hwmon.h
Merge tag 'char-misc-5.7-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[mirror_ubuntu-jammy-kernel.git] / include / linux / hwmon.h
CommitLineData
b886d83c 1/* SPDX-License-Identifier: GPL-2.0-only */
1236441f
MH
2/*
3 hwmon.h - part of lm_sensors, Linux kernel modules for hardware monitoring
4
5 This file declares helper functions for the sysfs class "hwmon",
6 for use by sensors drivers.
7
8 Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com>
9
1236441f
MH
10*/
11
12#ifndef _HWMON_H_
13#define _HWMON_H_
14
d560168b
GR
15#include <linux/bitops.h>
16
313162d0 17struct device;
bab2243c 18struct attribute_group;
1236441f 19
d560168b
GR
20enum hwmon_sensor_types {
21 hwmon_chip,
22 hwmon_temp,
23 hwmon_in,
24 hwmon_curr,
25 hwmon_power,
26 hwmon_energy,
6bfcca44 27 hwmon_humidity,
8faee73f 28 hwmon_fan,
f9f7bb3a 29 hwmon_pwm,
4413405f 30 hwmon_intrusion,
d5753800 31 hwmon_max,
d560168b
GR
32};
33
34enum hwmon_chip_attributes {
35 hwmon_chip_temp_reset_history,
00d616cf 36 hwmon_chip_in_reset_history,
9b26947c 37 hwmon_chip_curr_reset_history,
b308f5c7 38 hwmon_chip_power_reset_history,
d560168b
GR
39 hwmon_chip_register_tz,
40 hwmon_chip_update_interval,
41 hwmon_chip_alarms,
9f00995e
GR
42 hwmon_chip_samples,
43 hwmon_chip_curr_samples,
44 hwmon_chip_in_samples,
45 hwmon_chip_power_samples,
46 hwmon_chip_temp_samples,
d560168b
GR
47};
48
49#define HWMON_C_TEMP_RESET_HISTORY BIT(hwmon_chip_temp_reset_history)
50#define HWMON_C_IN_RESET_HISTORY BIT(hwmon_chip_in_reset_history)
9b26947c 51#define HWMON_C_CURR_RESET_HISTORY BIT(hwmon_chip_curr_reset_history)
b308f5c7 52#define HWMON_C_POWER_RESET_HISTORY BIT(hwmon_chip_power_reset_history)
d560168b
GR
53#define HWMON_C_REGISTER_TZ BIT(hwmon_chip_register_tz)
54#define HWMON_C_UPDATE_INTERVAL BIT(hwmon_chip_update_interval)
55#define HWMON_C_ALARMS BIT(hwmon_chip_alarms)
9f00995e
GR
56#define HWMON_C_SAMPLES BIT(hwmon_chip_samples)
57#define HWMON_C_CURR_SAMPLES BIT(hwmon_chip_curr_samples)
58#define HWMON_C_IN_SAMPLES BIT(hwmon_chip_in_samples)
59#define HWMON_C_POWER_SAMPLES BIT(hwmon_chip_power_samples)
60#define HWMON_C_TEMP_SAMPLES BIT(hwmon_chip_temp_samples)
d560168b
GR
61
62enum hwmon_temp_attributes {
002c6b54
GR
63 hwmon_temp_enable,
64 hwmon_temp_input,
d560168b
GR
65 hwmon_temp_type,
66 hwmon_temp_lcrit,
67 hwmon_temp_lcrit_hyst,
68 hwmon_temp_min,
69 hwmon_temp_min_hyst,
70 hwmon_temp_max,
71 hwmon_temp_max_hyst,
72 hwmon_temp_crit,
73 hwmon_temp_crit_hyst,
74 hwmon_temp_emergency,
75 hwmon_temp_emergency_hyst,
76 hwmon_temp_alarm,
77 hwmon_temp_lcrit_alarm,
78 hwmon_temp_min_alarm,
79 hwmon_temp_max_alarm,
80 hwmon_temp_crit_alarm,
81 hwmon_temp_emergency_alarm,
82 hwmon_temp_fault,
83 hwmon_temp_offset,
84 hwmon_temp_label,
85 hwmon_temp_lowest,
86 hwmon_temp_highest,
87 hwmon_temp_reset_history,
88};
89
002c6b54 90#define HWMON_T_ENABLE BIT(hwmon_temp_enable)
d560168b
GR
91#define HWMON_T_INPUT BIT(hwmon_temp_input)
92#define HWMON_T_TYPE BIT(hwmon_temp_type)
93#define HWMON_T_LCRIT BIT(hwmon_temp_lcrit)
94#define HWMON_T_LCRIT_HYST BIT(hwmon_temp_lcrit_hyst)
95#define HWMON_T_MIN BIT(hwmon_temp_min)
96#define HWMON_T_MIN_HYST BIT(hwmon_temp_min_hyst)
97#define HWMON_T_MAX BIT(hwmon_temp_max)
98#define HWMON_T_MAX_HYST BIT(hwmon_temp_max_hyst)
99#define HWMON_T_CRIT BIT(hwmon_temp_crit)
100#define HWMON_T_CRIT_HYST BIT(hwmon_temp_crit_hyst)
101#define HWMON_T_EMERGENCY BIT(hwmon_temp_emergency)
102#define HWMON_T_EMERGENCY_HYST BIT(hwmon_temp_emergency_hyst)
a5023a99 103#define HWMON_T_ALARM BIT(hwmon_temp_alarm)
d560168b
GR
104#define HWMON_T_MIN_ALARM BIT(hwmon_temp_min_alarm)
105#define HWMON_T_MAX_ALARM BIT(hwmon_temp_max_alarm)
106#define HWMON_T_CRIT_ALARM BIT(hwmon_temp_crit_alarm)
2fe31e43 107#define HWMON_T_LCRIT_ALARM BIT(hwmon_temp_lcrit_alarm)
d560168b
GR
108#define HWMON_T_EMERGENCY_ALARM BIT(hwmon_temp_emergency_alarm)
109#define HWMON_T_FAULT BIT(hwmon_temp_fault)
110#define HWMON_T_OFFSET BIT(hwmon_temp_offset)
111#define HWMON_T_LABEL BIT(hwmon_temp_label)
112#define HWMON_T_LOWEST BIT(hwmon_temp_lowest)
113#define HWMON_T_HIGHEST BIT(hwmon_temp_highest)
114#define HWMON_T_RESET_HISTORY BIT(hwmon_temp_reset_history)
115
00d616cf 116enum hwmon_in_attributes {
002c6b54 117 hwmon_in_enable,
00d616cf
GR
118 hwmon_in_input,
119 hwmon_in_min,
120 hwmon_in_max,
121 hwmon_in_lcrit,
122 hwmon_in_crit,
123 hwmon_in_average,
124 hwmon_in_lowest,
125 hwmon_in_highest,
126 hwmon_in_reset_history,
127 hwmon_in_label,
128 hwmon_in_alarm,
129 hwmon_in_min_alarm,
130 hwmon_in_max_alarm,
131 hwmon_in_lcrit_alarm,
132 hwmon_in_crit_alarm,
133};
134
002c6b54 135#define HWMON_I_ENABLE BIT(hwmon_in_enable)
00d616cf
GR
136#define HWMON_I_INPUT BIT(hwmon_in_input)
137#define HWMON_I_MIN BIT(hwmon_in_min)
138#define HWMON_I_MAX BIT(hwmon_in_max)
139#define HWMON_I_LCRIT BIT(hwmon_in_lcrit)
140#define HWMON_I_CRIT BIT(hwmon_in_crit)
141#define HWMON_I_AVERAGE BIT(hwmon_in_average)
142#define HWMON_I_LOWEST BIT(hwmon_in_lowest)
143#define HWMON_I_HIGHEST BIT(hwmon_in_highest)
144#define HWMON_I_RESET_HISTORY BIT(hwmon_in_reset_history)
145#define HWMON_I_LABEL BIT(hwmon_in_label)
146#define HWMON_I_ALARM BIT(hwmon_in_alarm)
147#define HWMON_I_MIN_ALARM BIT(hwmon_in_min_alarm)
148#define HWMON_I_MAX_ALARM BIT(hwmon_in_max_alarm)
149#define HWMON_I_LCRIT_ALARM BIT(hwmon_in_lcrit_alarm)
150#define HWMON_I_CRIT_ALARM BIT(hwmon_in_crit_alarm)
151
9b26947c 152enum hwmon_curr_attributes {
002c6b54 153 hwmon_curr_enable,
9b26947c
GR
154 hwmon_curr_input,
155 hwmon_curr_min,
156 hwmon_curr_max,
157 hwmon_curr_lcrit,
158 hwmon_curr_crit,
159 hwmon_curr_average,
160 hwmon_curr_lowest,
161 hwmon_curr_highest,
162 hwmon_curr_reset_history,
163 hwmon_curr_label,
164 hwmon_curr_alarm,
165 hwmon_curr_min_alarm,
166 hwmon_curr_max_alarm,
167 hwmon_curr_lcrit_alarm,
168 hwmon_curr_crit_alarm,
169};
170
002c6b54 171#define HWMON_C_ENABLE BIT(hwmon_curr_enable)
9b26947c
GR
172#define HWMON_C_INPUT BIT(hwmon_curr_input)
173#define HWMON_C_MIN BIT(hwmon_curr_min)
174#define HWMON_C_MAX BIT(hwmon_curr_max)
175#define HWMON_C_LCRIT BIT(hwmon_curr_lcrit)
176#define HWMON_C_CRIT BIT(hwmon_curr_crit)
177#define HWMON_C_AVERAGE BIT(hwmon_curr_average)
178#define HWMON_C_LOWEST BIT(hwmon_curr_lowest)
179#define HWMON_C_HIGHEST BIT(hwmon_curr_highest)
180#define HWMON_C_RESET_HISTORY BIT(hwmon_curr_reset_history)
181#define HWMON_C_LABEL BIT(hwmon_curr_label)
182#define HWMON_C_ALARM BIT(hwmon_curr_alarm)
183#define HWMON_C_MIN_ALARM BIT(hwmon_curr_min_alarm)
184#define HWMON_C_MAX_ALARM BIT(hwmon_curr_max_alarm)
185#define HWMON_C_LCRIT_ALARM BIT(hwmon_curr_lcrit_alarm)
186#define HWMON_C_CRIT_ALARM BIT(hwmon_curr_crit_alarm)
187
b308f5c7 188enum hwmon_power_attributes {
002c6b54 189 hwmon_power_enable,
b308f5c7
GR
190 hwmon_power_average,
191 hwmon_power_average_interval,
192 hwmon_power_average_interval_max,
193 hwmon_power_average_interval_min,
194 hwmon_power_average_highest,
195 hwmon_power_average_lowest,
196 hwmon_power_average_max,
197 hwmon_power_average_min,
198 hwmon_power_input,
199 hwmon_power_input_highest,
200 hwmon_power_input_lowest,
201 hwmon_power_reset_history,
202 hwmon_power_accuracy,
203 hwmon_power_cap,
204 hwmon_power_cap_hyst,
205 hwmon_power_cap_max,
206 hwmon_power_cap_min,
aa7f29b0 207 hwmon_power_min,
b308f5c7
GR
208 hwmon_power_max,
209 hwmon_power_crit,
aa7f29b0 210 hwmon_power_lcrit,
b308f5c7
GR
211 hwmon_power_label,
212 hwmon_power_alarm,
213 hwmon_power_cap_alarm,
aa7f29b0 214 hwmon_power_min_alarm,
b308f5c7 215 hwmon_power_max_alarm,
aa7f29b0 216 hwmon_power_lcrit_alarm,
b308f5c7
GR
217 hwmon_power_crit_alarm,
218};
219
002c6b54 220#define HWMON_P_ENABLE BIT(hwmon_power_enable)
b308f5c7
GR
221#define HWMON_P_AVERAGE BIT(hwmon_power_average)
222#define HWMON_P_AVERAGE_INTERVAL BIT(hwmon_power_average_interval)
223#define HWMON_P_AVERAGE_INTERVAL_MAX BIT(hwmon_power_average_interval_max)
224#define HWMON_P_AVERAGE_INTERVAL_MIN BIT(hwmon_power_average_interval_min)
225#define HWMON_P_AVERAGE_HIGHEST BIT(hwmon_power_average_highest)
226#define HWMON_P_AVERAGE_LOWEST BIT(hwmon_power_average_lowest)
227#define HWMON_P_AVERAGE_MAX BIT(hwmon_power_average_max)
228#define HWMON_P_AVERAGE_MIN BIT(hwmon_power_average_min)
229#define HWMON_P_INPUT BIT(hwmon_power_input)
230#define HWMON_P_INPUT_HIGHEST BIT(hwmon_power_input_highest)
231#define HWMON_P_INPUT_LOWEST BIT(hwmon_power_input_lowest)
232#define HWMON_P_RESET_HISTORY BIT(hwmon_power_reset_history)
233#define HWMON_P_ACCURACY BIT(hwmon_power_accuracy)
234#define HWMON_P_CAP BIT(hwmon_power_cap)
235#define HWMON_P_CAP_HYST BIT(hwmon_power_cap_hyst)
236#define HWMON_P_CAP_MAX BIT(hwmon_power_cap_max)
237#define HWMON_P_CAP_MIN BIT(hwmon_power_cap_min)
aa7f29b0 238#define HWMON_P_MIN BIT(hwmon_power_min)
b308f5c7 239#define HWMON_P_MAX BIT(hwmon_power_max)
aa7f29b0 240#define HWMON_P_LCRIT BIT(hwmon_power_lcrit)
b308f5c7
GR
241#define HWMON_P_CRIT BIT(hwmon_power_crit)
242#define HWMON_P_LABEL BIT(hwmon_power_label)
243#define HWMON_P_ALARM BIT(hwmon_power_alarm)
244#define HWMON_P_CAP_ALARM BIT(hwmon_power_cap_alarm)
30945d31 245#define HWMON_P_MIN_ALARM BIT(hwmon_power_min_alarm)
b308f5c7 246#define HWMON_P_MAX_ALARM BIT(hwmon_power_max_alarm)
aa7f29b0 247#define HWMON_P_LCRIT_ALARM BIT(hwmon_power_lcrit_alarm)
b308f5c7
GR
248#define HWMON_P_CRIT_ALARM BIT(hwmon_power_crit_alarm)
249
6bfcca44 250enum hwmon_energy_attributes {
002c6b54 251 hwmon_energy_enable,
6bfcca44
GR
252 hwmon_energy_input,
253 hwmon_energy_label,
254};
255
002c6b54 256#define HWMON_E_ENABLE BIT(hwmon_energy_enable)
6bfcca44
GR
257#define HWMON_E_INPUT BIT(hwmon_energy_input)
258#define HWMON_E_LABEL BIT(hwmon_energy_label)
259
260enum hwmon_humidity_attributes {
002c6b54 261 hwmon_humidity_enable,
6bfcca44
GR
262 hwmon_humidity_input,
263 hwmon_humidity_label,
264 hwmon_humidity_min,
265 hwmon_humidity_min_hyst,
266 hwmon_humidity_max,
267 hwmon_humidity_max_hyst,
268 hwmon_humidity_alarm,
269 hwmon_humidity_fault,
270};
271
002c6b54 272#define HWMON_H_ENABLE BIT(hwmon_humidity_enable)
6bfcca44
GR
273#define HWMON_H_INPUT BIT(hwmon_humidity_input)
274#define HWMON_H_LABEL BIT(hwmon_humidity_label)
275#define HWMON_H_MIN BIT(hwmon_humidity_min)
276#define HWMON_H_MIN_HYST BIT(hwmon_humidity_min_hyst)
277#define HWMON_H_MAX BIT(hwmon_humidity_max)
278#define HWMON_H_MAX_HYST BIT(hwmon_humidity_max_hyst)
279#define HWMON_H_ALARM BIT(hwmon_humidity_alarm)
280#define HWMON_H_FAULT BIT(hwmon_humidity_fault)
281
8faee73f 282enum hwmon_fan_attributes {
002c6b54 283 hwmon_fan_enable,
8faee73f
GR
284 hwmon_fan_input,
285 hwmon_fan_label,
286 hwmon_fan_min,
287 hwmon_fan_max,
288 hwmon_fan_div,
289 hwmon_fan_pulses,
290 hwmon_fan_target,
291 hwmon_fan_alarm,
292 hwmon_fan_min_alarm,
293 hwmon_fan_max_alarm,
294 hwmon_fan_fault,
295};
296
002c6b54 297#define HWMON_F_ENABLE BIT(hwmon_fan_enable)
8faee73f
GR
298#define HWMON_F_INPUT BIT(hwmon_fan_input)
299#define HWMON_F_LABEL BIT(hwmon_fan_label)
300#define HWMON_F_MIN BIT(hwmon_fan_min)
301#define HWMON_F_MAX BIT(hwmon_fan_max)
302#define HWMON_F_DIV BIT(hwmon_fan_div)
303#define HWMON_F_PULSES BIT(hwmon_fan_pulses)
304#define HWMON_F_TARGET BIT(hwmon_fan_target)
305#define HWMON_F_ALARM BIT(hwmon_fan_alarm)
306#define HWMON_F_MIN_ALARM BIT(hwmon_fan_min_alarm)
307#define HWMON_F_MAX_ALARM BIT(hwmon_fan_max_alarm)
308#define HWMON_F_FAULT BIT(hwmon_fan_fault)
309
f9f7bb3a
GR
310enum hwmon_pwm_attributes {
311 hwmon_pwm_input,
312 hwmon_pwm_enable,
313 hwmon_pwm_mode,
314 hwmon_pwm_freq,
315};
316
317#define HWMON_PWM_INPUT BIT(hwmon_pwm_input)
318#define HWMON_PWM_ENABLE BIT(hwmon_pwm_enable)
319#define HWMON_PWM_MODE BIT(hwmon_pwm_mode)
320#define HWMON_PWM_FREQ BIT(hwmon_pwm_freq)
321
4413405f
DDAG
322enum hwmon_intrusion_attributes {
323 hwmon_intrusion_alarm,
324 hwmon_intrusion_beep,
325};
326#define HWMON_INTRUSION_ALARM BIT(hwmon_intrusion_alarm)
327#define HWMON_INTRUSION_BEEP BIT(hwmon_intrusion_beep)
328
d560168b
GR
329/**
330 * struct hwmon_ops - hwmon device operations
331 * @is_visible: Callback to return attribute visibility. Mandatory.
332 * Parameters are:
333 * @const void *drvdata:
334 * Pointer to driver-private data structure passed
335 * as argument to hwmon_device_register_with_info().
336 * @type: Sensor type
337 * @attr: Sensor attribute
338 * @channel:
339 * Channel number
340 * The function returns the file permissions.
341 * If the return value is 0, no attribute will be created.
e159ab5c
GR
342 * @read: Read callback for data attributes. Mandatory if readable
343 * data attributes are present.
d560168b
GR
344 * Parameters are:
345 * @dev: Pointer to hardware monitoring device
346 * @type: Sensor type
347 * @attr: Sensor attribute
348 * @channel:
349 * Channel number
350 * @val: Pointer to returned value
351 * The function returns 0 on success or a negative error number.
e159ab5c
GR
352 * @read_string:
353 * Read callback for string attributes. Mandatory if string
354 * attributes are present.
355 * Parameters are:
356 * @dev: Pointer to hardware monitoring device
357 * @type: Sensor type
358 * @attr: Sensor attribute
359 * @channel:
360 * Channel number
361 * @str: Pointer to returned string
362 * The function returns 0 on success or a negative error number.
363 * @write: Write callback for data attributes. Mandatory if writeable
364 * data attributes are present.
d560168b
GR
365 * Parameters are:
366 * @dev: Pointer to hardware monitoring device
367 * @type: Sensor type
368 * @attr: Sensor attribute
369 * @channel:
370 * Channel number
371 * @val: Value to write
372 * The function returns 0 on success or a negative error number.
373 */
374struct hwmon_ops {
375 umode_t (*is_visible)(const void *drvdata, enum hwmon_sensor_types type,
376 u32 attr, int channel);
377 int (*read)(struct device *dev, enum hwmon_sensor_types type,
378 u32 attr, int channel, long *val);
e159ab5c 379 int (*read_string)(struct device *dev, enum hwmon_sensor_types type,
5ba6bcbc 380 u32 attr, int channel, const char **str);
d560168b
GR
381 int (*write)(struct device *dev, enum hwmon_sensor_types type,
382 u32 attr, int channel, long val);
383};
384
385/**
386 * Channel information
387 * @type: Channel type.
388 * @config: Pointer to NULL-terminated list of channel parameters.
389 * Use for per-channel attributes.
390 */
391struct hwmon_channel_info {
392 enum hwmon_sensor_types type;
393 const u32 *config;
394};
395
c43a113c
CK
396#define HWMON_CHANNEL_INFO(stype, ...) \
397 (&(struct hwmon_channel_info) { \
398 .type = hwmon_##stype, \
399 .config = (u32 []) { \
400 __VA_ARGS__, 0 \
401 } \
402 })
403
d560168b
GR
404/**
405 * Chip configuration
406 * @ops: Pointer to hwmon operations.
407 * @info: Null-terminated list of channel information.
408 */
409struct hwmon_chip_info {
410 const struct hwmon_ops *ops;
411 const struct hwmon_channel_info **info;
412};
413
af1bd36c 414/* hwmon_device_register() is deprecated */
1beeffe4 415struct device *hwmon_device_register(struct device *dev);
af1bd36c 416
bab2243c
GR
417struct device *
418hwmon_device_register_with_groups(struct device *dev, const char *name,
419 void *drvdata,
420 const struct attribute_group **groups);
74188cba
GR
421struct device *
422devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
423 void *drvdata,
424 const struct attribute_group **groups);
d560168b
GR
425struct device *
426hwmon_device_register_with_info(struct device *dev,
427 const char *name, void *drvdata,
428 const struct hwmon_chip_info *info,
848ba0a2 429 const struct attribute_group **extra_groups);
d560168b
GR
430struct device *
431devm_hwmon_device_register_with_info(struct device *dev,
848ba0a2
GR
432 const char *name, void *drvdata,
433 const struct hwmon_chip_info *info,
434 const struct attribute_group **extra_groups);
1236441f 435
1beeffe4 436void hwmon_device_unregister(struct device *dev);
74188cba 437void devm_hwmon_device_unregister(struct device *dev);
1236441f 438
dcb5d0fc
AL
439/**
440 * hwmon_is_bad_char - Is the char invalid in a hwmon name
441 * @ch: the char to be considered
442 *
443 * hwmon_is_bad_char() can be used to determine if the given character
444 * may not be used in a hwmon name.
445 *
446 * Returns true if the char is invalid, false otherwise.
447 */
448static inline bool hwmon_is_bad_char(const char ch)
449{
450 switch (ch) {
451 case '-':
452 case '*':
453 case ' ':
454 case '\t':
455 case '\n':
456 return true;
457 default:
458 return false;
459 }
460}
461
1236441f 462#endif