xref: /linux/Documentation/hwmon/sysfs-interface.rst (revision cb01c6914ed57a68b4f5d67f47208e24f9a45408)
1Naming and data format standards for sysfs files
2================================================
3
4The libsensors library offers an interface to the raw sensors data
5through the sysfs interface. Since lm-sensors 3.0.0, libsensors is
6completely chip-independent. It assumes that all the kernel drivers
7implement the standard sysfs interface described in this document.
8This makes adding or updating support for any given chip very easy, as
9libsensors, and applications using it, do not need to be modified.
10This is a major improvement compared to lm-sensors 2.
11
12Note that motherboards vary widely in the connections to sensor chips.
13There is no standard that ensures, for example, that the second
14temperature sensor is connected to the CPU, or that the second fan is on
15the CPU. Also, some values reported by the chips need some computation
16before they make full sense. For example, most chips can only measure
17voltages between 0 and +4V. Other voltages are scaled back into that
18range using external resistors. Since the values of these resistors
19can change from motherboard to motherboard, the conversions cannot be
20hard coded into the driver and have to be done in user space.
21
22For this reason, even if we aim at a chip-independent libsensors, it will
23still require a configuration file (e.g. /etc/sensors.conf) for proper
24values conversion, labeling of inputs and hiding of unused inputs.
25
26An alternative method that some programs use is to access the sysfs
27files directly. This document briefly describes the standards that the
28drivers follow, so that an application program can scan for entries and
29access this data in a simple and consistent way. That said, such programs
30will have to implement conversion, labeling and hiding of inputs. For
31this reason, it is still not recommended to bypass the library.
32
33Each chip gets its own directory in the sysfs /sys/devices tree.  To
34find all sensor chips, it is easier to follow the device symlinks from
35`/sys/class/hwmon/hwmon*`.
36
37Up to lm-sensors 3.0.0, libsensors looks for hardware monitoring attributes
38in the "physical" device directory. Since lm-sensors 3.0.1, attributes found
39in the hwmon "class" device directory are also supported. Complex drivers
40(e.g. drivers for multifunction chips) may want to use this possibility to
41avoid namespace pollution. The only drawback will be that older versions of
42libsensors won't support the driver in question.
43
44All sysfs values are fixed point numbers.
45
46There is only one value per file, unlike the older /proc specification.
47The common scheme for files naming is: <type><number>_<item>. Usual
48types for sensor chips are "in" (voltage), "temp" (temperature) and
49"fan" (fan). Usual items are "input" (measured value), "max" (high
50threshold), "min" (low threshold). Numbering usually starts from 1,
51except for voltages which start from 0 (because most data sheets use
52this). A number is always used for elements that can be present more
53than once, even if there is a single element of the given type on the
54specific chip. Other files do not refer to a specific element, so
55they have a simple name, and no number.
56
57Alarms are direct indications read from the chips. The drivers do NOT
58make comparisons of readings to thresholds. This allows violations
59between readings to be caught and alarmed. The exact definition of an
60alarm (for example, whether a threshold must be met or must be exceeded
61to cause an alarm) is chip-dependent.
62
63When setting values of hwmon sysfs attributes, the string representation of
64the desired value must be written, note that strings which are not a number
65are interpreted as 0! For more on how written strings are interpreted see the
66"sysfs attribute writes interpretation" section at the end of this file.
67
68Attribute access
69----------------
70
71Hardware monitoring sysfs attributes are displayed by unrestricted userspace
72applications. For this reason, all standard ABI attributes shall be world
73readable. Writeable standard ABI attributes shall be writeable only for
74privileged users.
75
76-------------------------------------------------------------------------
77
78======= ===========================================
79`[0-*]`	denotes any positive number starting from 0
80`[1-*]`	denotes any positive number starting from 1
81RO	read only value
82WO	write only value
83RW	read/write value
84======= ===========================================
85
86Read/write values may be read-only for some chips, depending on the
87hardware implementation.
88
89All entries (except name) are optional, and should only be created in a
90given driver if the chip has the feature.
91
92See Documentation/ABI/testing/sysfs-class-hwmon for a complete description
93of the attributes.
94
95*****************
96Global attributes
97*****************
98
99`name`
100		The chip name.
101
102`label`
103		A descriptive label that allows to uniquely identify a device
104		within the system.
105
106`update_interval`
107		The interval at which the chip will update readings.
108
109`update_interval_us`
110		The interval at which the chip will update readings,
111		expressed in microseconds for finer resolution.
112
113
114********
115Voltages
116********
117
118`in[0-*]_min`
119		Voltage min value.
120
121`in[0-*]_lcrit`
122		Voltage critical min value.
123
124`in[0-*]_lemergency`
125		Voltage emergency min value.
126
127`in[0-*]_max`
128		Voltage max value.
129
130`in[0-*]_crit`
131		Voltage critical max value.
132
133`in[0-*]_emergency`
134		Voltage emergency max value.
135
136`in[0-*]_input`
137		Voltage input value.
138
139`in[0-*]_average`
140		Average voltage
141
142`in[0-*]_lowest`
143		Historical minimum voltage
144
145`in[0-*]_highest`
146		Historical maximum voltage
147
148`in[0-*]_reset_history`
149		Reset inX_lowest and inX_highest
150
151`in_reset_history`
152		Reset inX_lowest and inX_highest for all sensors
153
154`in[0-*]_label`
155		Suggested voltage channel label.
156
157`in[0-*]_enable`
158		Enable or disable the sensors.
159
160`cpu[0-*]_vid`
161		CPU core reference voltage.
162
163`vrm`
164		Voltage Regulator Module version number.
165
166`in[0-*]_rated_min`
167		Minimum rated voltage.
168
169`in[0-*]_rated_max`
170		Maximum rated voltage.
171
172Also see the Alarms section for status flags associated with voltages.
173
174
175****
176Fans
177****
178
179`fan[1-*]_min`
180		Fan minimum value
181
182`fan[1-*]_max`
183		Fan maximum value
184
185`fan[1-*]_input`
186		Fan input value.
187
188`fan[1-*]_div`
189		Fan divisor.
190
191`fan[1-*]_pulses`
192		Number of tachometer pulses per fan revolution.
193
194`fan[1-*]_target`
195		Desired fan speed
196
197`fan[1-*]_label`
198		Suggested fan channel label.
199
200`fan[1-*]_enable`
201		Enable or disable the sensors.
202
203Also see the Alarms section for status flags associated with fans.
204
205
206***
207PWM
208***
209
210`pwm[1-*]`
211		Pulse width modulation fan control.
212
213`pwm[1-*]_enable`
214		Fan speed control method.
215
216`pwm[1-*]_mode`
217		direct current or pulse-width modulation.
218
219`pwm[1-*]_freq`
220		Base PWM frequency in Hz.
221
222`pwm[1-*]_auto_channels_temp`
223		Select which temperature channels affect this PWM output in
224		auto mode.
225
226`pwm[1-*]_auto_point[1-*]_pwm` / `pwm[1-*]_auto_point[1-*]_temp` / `pwm[1-*]_auto_point[1-*]_temp_hyst`
227		Define the PWM vs temperature curve.
228
229`temp[1-*]_auto_point[1-*]_pwm` / `temp[1-*]_auto_point[1-*]_temp` / `temp[1-*]_auto_point[1-*]_temp_hyst`
230		Define the PWM vs temperature curve.
231
232There is a third case where trip points are associated to both PWM output
233channels and temperature channels: the PWM values are associated to PWM
234output channels while the temperature values are associated to temperature
235channels. In that case, the result is determined by the mapping between
236temperature inputs and PWM outputs. When several temperature inputs are
237mapped to a given PWM output, this leads to several candidate PWM values.
238The actual result is up to the chip, but in general the highest candidate
239value (fastest fan speed) wins.
240
241
242************
243Temperatures
244************
245
246`temp[1-*]_type`
247		Sensor type selection.
248
249`temp[1-*]_max`
250		Temperature max value.
251
252`temp[1-*]_min`
253		Temperature min value.
254
255`temp[1-*]_max_hyst`
256		Temperature hysteresis value for max limit.
257
258`temp[1-*]_min_hyst`
259		Temperature hysteresis value for min limit.
260
261`temp[1-*]_input`
262		Temperature input value.
263
264`temp[1-*]_crit`
265		Temperature critical max value, typically greater than
266		corresponding temp_max values.
267
268`temp[1-*]_crit_hyst`
269		Temperature hysteresis value for critical limit.
270
271`temp[1-*]_emergency`
272		Temperature emergency max value, for chips supporting more than
273		two upper temperature limits.
274
275`temp[1-*]_emergency_hyst`
276		Temperature hysteresis value for emergency limit.
277
278`temp[1-*]_lcrit`
279		Temperature critical min value, typically lower than
280		corresponding temp_min values.
281
282`temp[1-*]_lcrit_hyst`
283		Temperature hysteresis value for critical min limit.
284
285`temp[1-*]_offset`
286		Temperature offset which is added to the temperature reading
287		by the chip.
288
289`temp[1-*]_label`
290		Suggested temperature channel label.
291
292`temp[1-*]_lowest`
293		Historical minimum temperature
294
295`temp[1-*]_highest`
296		Historical maximum temperature
297
298`temp[1-*]_reset_history`
299		Reset temp_lowest and temp_highest
300
301`temp_reset_history`
302		Reset temp_lowest and temp_highest for all sensors
303
304`temp[1-*]_enable`
305		Enable or disable the sensors.
306
307`temp[1-*]_rated_min`
308		Minimum rated temperature.
309
310`temp[1-*]_rated_max`
311		Maximum rated temperature.
312
313Some chips measure temperature using external thermistors and an ADC, and
314report the temperature measurement as a voltage. Converting this voltage
315back to a temperature (or the other way around for limits) requires
316mathematical functions not available in the kernel, so the conversion
317must occur in user space. For these chips, all temp* files described
318above should contain values expressed in millivolt instead of millidegree
319Celsius. In other words, such temperature channels are handled as voltage
320channels by the driver.
321
322Also see the Alarms section for status flags associated with temperatures.
323
324
325********
326Currents
327********
328
329`curr[1-*]_max`
330		Current max value.
331
332`curr[1-*]_min`
333		Current min value.
334
335`curr[1-*]_lcrit`
336		Current critical low value
337
338`curr[1-*]_crit`
339		Current critical high value.
340
341`curr[1-*]_emergency`
342		Current emergency high value.
343
344`curr[1-*]_input`
345		Current input value.
346
347`curr[1-*]_average`
348		Average current use.
349
350`curr[1-*]_lowest`
351		Historical minimum current.
352
353`curr[1-*]_highest`
354		Historical maximum current.
355
356`curr[1-*]_reset_history`
357		Reset currX_lowest and currX_highest
358
359		WO
360
361`curr_reset_history`
362		Reset currX_lowest and currX_highest for all sensors.
363
364`curr[1-*]_enable`
365		Enable or disable the sensors.
366
367`curr[1-*]_rated_min`
368		Minimum rated current.
369
370`curr[1-*]_rated_max`
371		Maximum rated current.
372
373Also see the Alarms section for status flags associated with currents.
374
375*****
376Power
377*****
378
379`power[1-*]_average`
380		Average power use.
381
382`power[1-*]_average_interval`
383		Power use averaging interval.
384
385`power[1-*]_average_interval_max`
386		Maximum power use averaging interval.
387
388`power[1-*]_average_interval_min`
389		Minimum power use averaging interval.
390
391`power[1-*]_average_highest`
392		Historical average maximum power use
393
394`power[1-*]_average_lowest`
395		Historical average minimum power use
396
397`power[1-*]_average_max`
398		A poll notification is sent to `power[1-*]_average` when
399		power use rises above this value.
400
401`power[1-*]_average_min`
402		A poll notification is sent to `power[1-*]_average` when
403		power use sinks below this value.
404
405`power[1-*]_input`
406		Instantaneous power use.
407
408`power[1-*]_input_highest`
409		Historical maximum power use
410
411`power[1-*]_input_lowest`
412		Historical minimum power use.
413
414`power[1-*]_reset_history`
415		Reset input_highest, input_lowest, average_highest and
416		average_lowest.
417
418`power[1-*]_accuracy`
419		Accuracy of the power meter.
420
421`power[1-*]_cap`
422		If power use rises above this limit, the
423		system should take action to reduce power use.
424
425`power[1-*]_cap_hyst`
426		Margin of hysteresis built around capping and notification.
427
428`power[1-*]_cap_max`
429		Maximum cap that can be set.
430
431`power[1-*]_cap_min`
432		Minimum cap that can be set.
433
434`power[1-*]_max`
435		Maximum power.
436
437`power[1-*]_crit`
438				Critical maximum power.
439
440				If power rises to or above this limit, the
441				system is expected take drastic action to reduce
442				power consumption, such as a system shutdown or
443				a forced powerdown of some devices.
444
445				Unit: microWatt
446
447				RW
448
449`power[1-*]_enable`
450				Enable or disable the sensors.
451
452				When disabled the sensor read will return
453				-ENODATA.
454
455				- 1: Enable
456				- 0: Disable
457
458				RW
459
460`power[1-*]_rated_min`
461				Minimum rated power.
462
463				Unit: microWatt
464
465				RO
466
467`power[1-*]_rated_max`
468				Maximum rated power.
469
470				Unit: microWatt
471
472				RO
473
474Also see the Alarms section for status flags associated with power readings.
475
476******
477Energy
478******
479
480`energy[1-*]_input`
481				Cumulative energy use
482
483				Unit: microJoule
484
485				RO
486
487`energy[1-*]_enable`
488				Enable or disable the sensors.
489
490				When disabled the sensor read will return
491				-ENODATA.
492
493				- 1: Enable
494				- 0: Disable
495
496				RW
497
498********
499Humidity
500********
501
502`humidity[1-*]_input`
503		Humidity.
504
505`humidity[1-*]_enable`
506		Enable or disable the sensors.
507
508`humidity[1-*]_rated_min`
509		Minimum rated humidity.
510
511`humidity[1-*]_rated_max`
512		Maximum rated humidity.
513
514******
515Alarms
516******
517
518Each channel or limit may have an associated alarm file, containing a
519boolean value. 1 means than an alarm condition exists, 0 means no alarm.
520
521Usually a given chip will either use channel-related alarms, or
522limit-related alarms, not both. The driver should just reflect the hardware
523implementation.
524
525+-------------------------------+-----------------------+
526| **`in[0-*]_alarm`,		| Channel alarm		|
527| `curr[1-*]_alarm`,		|			|
528| `power[1-*]_alarm`,		|   - 0: no alarm	|
529| `fan[1-*]_alarm`,		|   - 1: alarm		|
530| `temp[1-*]_alarm`**		|			|
531|				|   RO			|
532+-------------------------------+-----------------------+
533
534**OR**
535
536+-------------------------------+-----------------------+
537| **`in[0-*]_min_alarm`,	| Limit alarm		|
538| `in[0-*]_max_alarm`,		|			|
539| `in[0-*]_lemergency_alarm`,	|			|
540| `in[0-*]_lcrit_alarm`,	|   - 0: no alarm	|
541| `in[0-*]_crit_alarm`,		|   - 1: alarm		|
542| `in[0-*]_emergency_alarm`,	|			|
543| `curr[1-*]_min_alarm`,	|			|
544| `curr[1-*]_max_alarm`,	| RO			|
545| `curr[1-*]_lcrit_alarm`,	|			|
546| `curr[1-*]_crit_alarm`,	|			|
547| `curr[1-*]_emergency_alarm`,	|			|
548| `power[1-*]_cap_alarm`,	|			|
549| `power[1-*]_max_alarm`,	|			|
550| `power[1-*]_crit_alarm`,	|			|
551| `fan[1-*]_min_alarm`,		|			|
552| `fan[1-*]_max_alarm`,		|			|
553| `temp[1-*]_min_alarm`,	|			|
554| `temp[1-*]_max_alarm`,	|			|
555| `temp[1-*]_lcrit_alarm`,	|			|
556| `temp[1-*]_crit_alarm`,	|			|
557| `temp[1-*]_emergency_alarm`**	|			|
558+-------------------------------+-----------------------+
559
560Each input channel may have an associated fault file. This can be used
561to notify open diodes, unconnected fans etc. where the hardware
562supports it. When this boolean has value 1, the measurement for that
563channel should not be trusted.
564
565`fan[1-*]_fault` / `temp[1-*]_fault`
566		Input fault condition.
567
568Some chips also offer the possibility to get beeped when an alarm occurs:
569
570`beep_enable`
571		Master beep enable.
572
573`in[0-*]_beep`, `curr[1-*]_beep`, `fan[1-*]_beep`, `temp[1-*]_beep`,
574		Channel beep.
575
576In theory, a chip could provide per-limit beep masking, but no such chip
577was seen so far.
578
579Old drivers provided a different, non-standard interface to alarms and
580beeps. These interface files are deprecated, but will be kept around
581for compatibility reasons:
582
583`alarms`
584		Alarm bitmask.
585
586`beep_mask`
587		Bitmask for beep.
588
589
590*******************
591Intrusion detection
592*******************
593
594`intrusion[0-*]_alarm`
595		Chassis intrusion detection.
596
597`intrusion[0-*]_beep`
598		Chassis intrusion beep.
599
600****************************
601Average sample configuration
602****************************
603
604Devices allowing for reading {in,power,curr,temp}_average values may export
605attributes for controlling number of samples used to compute average.
606
607+--------------+---------------------------------------------------------------+
608| samples      | Sets number of average samples for all types of measurements. |
609|	       |							       |
610|	       | RW							       |
611+--------------+---------------------------------------------------------------+
612| in_samples   | Sets number of average samples for specific type of	       |
613| power_samples| measurements.						       |
614| curr_samples |							       |
615| temp_samples | Note that on some devices it won't be possible to set all of  |
616|	       | them to different values so changing one might also change    |
617|	       | some others.						       |
618|	       |							       |
619|	       | RW							       |
620+--------------+---------------------------------------------------------------+
621
622sysfs attribute writes interpretation
623-------------------------------------
624
625hwmon sysfs attributes always contain numbers, so the first thing to do is to
626convert the input to a number, there are 2 ways todo this depending whether
627the number can be negative or not::
628
629	unsigned long u = simple_strtoul(buf, NULL, 10);
630	long s = simple_strtol(buf, NULL, 10);
631
632With buf being the buffer with the user input being passed by the kernel.
633Notice that we do not use the second argument of strto[u]l, and thus cannot
634tell when 0 is returned, if this was really 0 or is caused by invalid input.
635This is done deliberately as checking this everywhere would add a lot of
636code to the kernel.
637
638Notice that it is important to always store the converted value in an
639unsigned long or long, so that no wrap around can happen before any further
640checking.
641
642After the input string is converted to an (unsigned) long, the value should be
643checked if its acceptable. Be careful with further conversions on the value
644before checking it for validity, as these conversions could still cause a wrap
645around before the check. For example do not multiply the result, and only
646add/subtract if it has been divided before the add/subtract.
647
648What to do if a value is found to be invalid, depends on the type of the
649sysfs attribute that is being set. If it is a continuous setting like a
650tempX_max or inX_max attribute, then the value should be clamped to its
651limits using clamp_val(value, min_limit, max_limit). If it is not continuous
652like for example a tempX_type, then when an invalid value is written,
653-EINVAL should be returned.
654
655Example1, temp1_max, register is a signed 8 bit value (-128 - 127 degrees)::
656
657	long v = simple_strtol(buf, NULL, 10) / 1000;
658	v = clamp_val(v, -128, 127);
659	/* write v to register */
660
661Example2, fan divider setting, valid values 2, 4 and 8::
662
663	unsigned long v = simple_strtoul(buf, NULL, 10);
664
665	switch (v) {
666	case 2: v = 1; break;
667	case 4: v = 2; break;
668	case 8: v = 3; break;
669	default:
670		return -EINVAL;
671	}
672	/* write v to register */
673