blob: f4a8ebc1ef1acc11ae4bdd22c9299f4b84467c73 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001Naming and data format standards for sysfs files
2------------------------------------------------
3
4The libsensors library offers an interface to the raw sensors data
5through the sysfs interface. See libsensors documentation and source for
Jean Delvare740e06a2006-06-05 20:31:20 +02006further information. As of writing this document, libsensors
7(from lm_sensors 2.8.3) is heavily chip-dependent. Adding or updating
Linus Torvalds1da177e2005-04-16 15:20:36 -07008support for any given chip requires modifying the library's code.
9This is because libsensors was written for the procfs interface
10older kernel modules were using, which wasn't standardized enough.
11Recent versions of libsensors (from lm_sensors 2.8.2 and later) have
12support for the sysfs interface, though.
13
Jean Delvare740e06a2006-06-05 20:31:20 +020014The new sysfs interface was designed to be as chip-independent as
Linus Torvalds1da177e2005-04-16 15:20:36 -070015possible.
16
17Note that motherboards vary widely in the connections to sensor chips.
18There is no standard that ensures, for example, that the second
19temperature sensor is connected to the CPU, or that the second fan is on
20the CPU. Also, some values reported by the chips need some computation
21before they make full sense. For example, most chips can only measure
22voltages between 0 and +4V. Other voltages are scaled back into that
23range using external resistors. Since the values of these resistors
24can change from motherboard to motherboard, the conversions cannot be
25hard coded into the driver and have to be done in user space.
26
Jean Delvare740e06a2006-06-05 20:31:20 +020027For this reason, even if we aim at a chip-independent libsensors, it will
Linus Torvalds1da177e2005-04-16 15:20:36 -070028still require a configuration file (e.g. /etc/sensors.conf) for proper
29values conversion, labeling of inputs and hiding of unused inputs.
30
31An alternative method that some programs use is to access the sysfs
32files directly. This document briefly describes the standards that the
33drivers follow, so that an application program can scan for entries and
34access this data in a simple and consistent way. That said, such programs
35will have to implement conversion, labeling and hiding of inputs. For
36this reason, it is still not recommended to bypass the library.
37
38If you are developing a userspace application please send us feedback on
39this standard.
40
41Note that this standard isn't completely established yet, so it is subject
Jean Delvare740e06a2006-06-05 20:31:20 +020042to changes. If you are writing a new hardware monitoring driver those
43features can't seem to fit in this interface, please contact us with your
44extension proposal. Keep in mind that backward compatibility must be
45preserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47Each chip gets its own directory in the sysfs /sys/devices tree. To
Jean Delvare740e06a2006-06-05 20:31:20 +020048find all sensor chips, it is easier to follow the device symlinks from
49/sys/class/hwmon/hwmon*.
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Jean Delvare740e06a2006-06-05 20:31:20 +020051All sysfs values are fixed point numbers.
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53There is only one value per file, unlike the older /proc specification.
54The common scheme for files naming is: <type><number>_<item>. Usual
55types for sensor chips are "in" (voltage), "temp" (temperature) and
56"fan" (fan). Usual items are "input" (measured value), "max" (high
57threshold, "min" (low threshold). Numbering usually starts from 1,
58except for voltages which start from 0 (because most data sheets use
59this). A number is always used for elements that can be present more
60than once, even if there is a single element of the given type on the
61specific chip. Other files do not refer to a specific element, so
62they have a simple name, and no number.
63
64Alarms are direct indications read from the chips. The drivers do NOT
65make comparisons of readings to thresholds. This allows violations
66between readings to be caught and alarmed. The exact definition of an
67alarm (for example, whether a threshold must be met or must be exceeded
68to cause an alarm) is chip-dependent.
69
Hans de Goede2ed42632007-09-21 17:03:32 +020070When setting values of hwmon sysfs attributes, the string representation of
71the desired value must be written, note that strings which are not a number
72are interpreted as 0! For more on how written strings are interpreted see the
73"sysfs attribute writes interpretation" section at the end of this file.
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75-------------------------------------------------------------------------
76
Rudolf Marek057bc352006-06-04 20:03:39 +020077[0-*] denotes any positive number starting from 0
78[1-*] denotes any positive number starting from 1
79RO read only value
80RW read/write value
81
82Read/write values may be read-only for some chips, depending on the
83hardware implementation.
84
Jean Delvare176544d2007-08-20 16:44:44 +020085All entries (except name) are optional, and should only be created in a
86given driver if the chip has the feature.
87
88
89********
90* Name *
91********
92
93name The chip name.
94 This should be a short, lowercase string, not containing
95 spaces nor dashes, representing the chip name. This is
96 the only mandatory attribute.
97 I2C devices get this attribute created automatically.
98 RO
99
Jean Delvare740e06a2006-06-05 20:31:20 +0200100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101************
102* Voltages *
103************
104
Rudolf Marek057bc352006-06-04 20:03:39 +0200105in[0-*]_min Voltage min value.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 Unit: millivolt
Rudolf Marek057bc352006-06-04 20:03:39 +0200107 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Rudolf Marek057bc352006-06-04 20:03:39 +0200109in[0-*]_max Voltage max value.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 Unit: millivolt
Rudolf Marek057bc352006-06-04 20:03:39 +0200111 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Rudolf Marek057bc352006-06-04 20:03:39 +0200113in[0-*]_input Voltage input value.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 Unit: millivolt
Rudolf Marek057bc352006-06-04 20:03:39 +0200115 RO
116 Voltage measured on the chip pin.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 Actual voltage depends on the scaling resistors on the
118 motherboard, as recommended in the chip datasheet.
119 This varies by chip and by motherboard.
120 Because of this variation, values are generally NOT scaled
121 by the chip driver, and must be done by the application.
122 However, some drivers (notably lm87 and via686a)
Rudolf Marek057bc352006-06-04 20:03:39 +0200123 do scale, because of internal resistors built into a chip.
Jean Delvare176544d2007-08-20 16:44:44 +0200124 These drivers will output the actual voltage. Rule of
125 thumb: drivers should report the voltage values at the
126 "pins" of the chip.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Jean Delvare176544d2007-08-20 16:44:44 +0200128in[0-*]_label Suggested voltage channel label.
129 Text string
130 Should only be created if the driver has hints about what
131 this voltage channel is being used for, and user-space
132 doesn't. In all other cases, the label is provided by
133 user-space.
134 RO
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Rudolf Marek057bc352006-06-04 20:03:39 +0200136cpu[0-*]_vid CPU core reference voltage.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 Unit: millivolt
Rudolf Marek057bc352006-06-04 20:03:39 +0200138 RO
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 Not always correct.
140
141vrm Voltage Regulator Module version number.
Rudolf Marek057bc352006-06-04 20:03:39 +0200142 RW (but changing it should no more be necessary)
143 Originally the VRM standard version multiplied by 10, but now
144 an arbitrary number, as not all standards have a version
145 number.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 Affects the way the driver calculates the CPU core reference
147 voltage from the vid pins.
148
Rudolf Marek057bc352006-06-04 20:03:39 +0200149Also see the Alarms section for status flags associated with voltages.
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152********
153* Fans *
154********
155
Rudolf Marek057bc352006-06-04 20:03:39 +0200156fan[1-*]_min Fan minimum value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 Unit: revolution/min (RPM)
Rudolf Marek057bc352006-06-04 20:03:39 +0200158 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Rudolf Marek057bc352006-06-04 20:03:39 +0200160fan[1-*]_input Fan input value.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 Unit: revolution/min (RPM)
Rudolf Marek057bc352006-06-04 20:03:39 +0200162 RO
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Rudolf Marek057bc352006-06-04 20:03:39 +0200164fan[1-*]_div Fan divisor.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 Integer value in powers of two (1, 2, 4, 8, 16, 32, 64, 128).
Rudolf Marek057bc352006-06-04 20:03:39 +0200166 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 Some chips only support values 1, 2, 4 and 8.
168 Note that this is actually an internal clock divisor, which
169 affects the measurable speed range, not the read value.
170
Jean Delvare2dbc5142007-05-08 17:22:00 +0200171fan[1-*]_target
172 Desired fan speed
173 Unit: revolution/min (RPM)
174 RW
175 Only makes sense if the chip supports closed-loop fan speed
176 control based on the measured fan speed.
177
Jean Delvare176544d2007-08-20 16:44:44 +0200178fan[1-*]_label Suggested fan channel label.
179 Text string
180 Should only be created if the driver has hints about what
181 this fan channel is being used for, and user-space doesn't.
182 In all other cases, the label is provided by user-space.
183 RO
184
Rudolf Marek057bc352006-06-04 20:03:39 +0200185Also see the Alarms section for status flags associated with fans.
186
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188*******
189* PWM *
190*******
191
Rudolf Marek057bc352006-06-04 20:03:39 +0200192pwm[1-*] Pulse width modulation fan control.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 Integer value in the range 0 to 255
Rudolf Marek057bc352006-06-04 20:03:39 +0200194 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 255 is max or 100%.
196
Rudolf Marek057bc352006-06-04 20:03:39 +0200197pwm[1-*]_enable
Jean Delvare875f25d2007-06-27 21:26:08 +0200198 Fan speed control method:
199 0: no fan speed control (i.e. fan at full speed)
200 1: manual fan speed control enabled (using pwm[1-*])
201 2+: automatic fan speed control enabled
Jean Delvaref8d0c192007-02-14 21:15:02 +0100202 Check individual chip documentation files for automatic mode
203 details.
Rudolf Marek057bc352006-06-04 20:03:39 +0200204 RW
205
Jean Delvaref8d0c192007-02-14 21:15:02 +0100206pwm[1-*]_mode 0: DC mode (direct current)
207 1: PWM mode (pulse-width modulation)
208 RW
209
210pwm[1-*]_freq Base PWM frequency in Hz.
211 Only possibly available when pwmN_mode is PWM, but not always
212 present even then.
Rudolf Marek057bc352006-06-04 20:03:39 +0200213 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215pwm[1-*]_auto_channels_temp
216 Select which temperature channels affect this PWM output in
217 auto mode. Bitfield, 1 is temp1, 2 is temp2, 4 is temp3 etc...
218 Which values are possible depend on the chip used.
Rudolf Marek057bc352006-06-04 20:03:39 +0200219 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221pwm[1-*]_auto_point[1-*]_pwm
222pwm[1-*]_auto_point[1-*]_temp
223pwm[1-*]_auto_point[1-*]_temp_hyst
224 Define the PWM vs temperature curve. Number of trip points is
225 chip-dependent. Use this for chips which associate trip points
226 to PWM output channels.
Rudolf Marek057bc352006-06-04 20:03:39 +0200227 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229OR
230
231temp[1-*]_auto_point[1-*]_pwm
232temp[1-*]_auto_point[1-*]_temp
233temp[1-*]_auto_point[1-*]_temp_hyst
234 Define the PWM vs temperature curve. Number of trip points is
235 chip-dependent. Use this for chips which associate trip points
236 to temperature channels.
Rudolf Marek057bc352006-06-04 20:03:39 +0200237 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239
240****************
241* Temperatures *
242****************
243
Rudolf Marek057bc352006-06-04 20:03:39 +0200244temp[1-*]_type Sensor type selection.
Jean Delvareb26f9332007-08-16 14:30:01 +0200245 Integers 1 to 6
Rudolf Marek057bc352006-06-04 20:03:39 +0200246 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 1: PII/Celeron Diode
248 2: 3904 transistor
249 3: thermal diode
Jean Delvareb26f9332007-08-16 14:30:01 +0200250 4: thermistor
Rudolf Marek61db0112006-12-12 18:18:30 +0100251 5: AMD AMDSI
252 6: Intel PECI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 Not all types are supported by all chips
254
Rudolf Marek057bc352006-06-04 20:03:39 +0200255temp[1-*]_max Temperature max value.
Jean Delvare740e06a2006-06-05 20:31:20 +0200256 Unit: millidegree Celsius (or millivolt, see below)
Rudolf Marek057bc352006-06-04 20:03:39 +0200257 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Rudolf Marek057bc352006-06-04 20:03:39 +0200259temp[1-*]_min Temperature min value.
Jean Delvare740e06a2006-06-05 20:31:20 +0200260 Unit: millidegree Celsius
Rudolf Marek057bc352006-06-04 20:03:39 +0200261 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Rudolf Marek057bc352006-06-04 20:03:39 +0200263temp[1-*]_max_hyst
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 Temperature hysteresis value for max limit.
Jean Delvare740e06a2006-06-05 20:31:20 +0200265 Unit: millidegree Celsius
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 Must be reported as an absolute temperature, NOT a delta
267 from the max value.
Rudolf Marek057bc352006-06-04 20:03:39 +0200268 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Rudolf Marek057bc352006-06-04 20:03:39 +0200270temp[1-*]_input Temperature input value.
Jean Delvare740e06a2006-06-05 20:31:20 +0200271 Unit: millidegree Celsius
Rudolf Marek057bc352006-06-04 20:03:39 +0200272 RO
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Rudolf Marek057bc352006-06-04 20:03:39 +0200274temp[1-*]_crit Temperature critical value, typically greater than
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 corresponding temp_max values.
Jean Delvare740e06a2006-06-05 20:31:20 +0200276 Unit: millidegree Celsius
Rudolf Marek057bc352006-06-04 20:03:39 +0200277 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Rudolf Marek057bc352006-06-04 20:03:39 +0200279temp[1-*]_crit_hyst
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 Temperature hysteresis value for critical limit.
Jean Delvare740e06a2006-06-05 20:31:20 +0200281 Unit: millidegree Celsius
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 Must be reported as an absolute temperature, NOT a delta
283 from the critical value.
Rudolf Marek057bc352006-06-04 20:03:39 +0200284 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Jean Delvare176544d2007-08-20 16:44:44 +0200286temp[1-*]_offset
Hartmut Rick59ac8362006-03-23 16:37:23 +0100287 Temperature offset which is added to the temperature reading
288 by the chip.
289 Unit: millidegree Celsius
290 Read/Write value.
291
Jean Delvare176544d2007-08-20 16:44:44 +0200292temp[1-*]_label Suggested temperature channel label.
293 Text string
294 Should only be created if the driver has hints about what
295 this temperature channel is being used for, and user-space
296 doesn't. In all other cases, the label is provided by
297 user-space.
298 RO
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Jean Delvare740e06a2006-06-05 20:31:20 +0200300Some chips measure temperature using external thermistors and an ADC, and
301report the temperature measurement as a voltage. Converting this voltage
302back to a temperature (or the other way around for limits) requires
303mathematical functions not available in the kernel, so the conversion
304must occur in user space. For these chips, all temp* files described
305above should contain values expressed in millivolt instead of millidegree
306Celsius. In other words, such temperature channels are handled as voltage
307channels by the driver.
308
Rudolf Marek057bc352006-06-04 20:03:39 +0200309Also see the Alarms section for status flags associated with temperatures.
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312************
313* Currents *
314************
315
316Note that no known chip provides current measurements as of writing,
317so this part is theoretical, so to say.
318
Rudolf Marek057bc352006-06-04 20:03:39 +0200319curr[1-*]_max Current max value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 Unit: milliampere
Rudolf Marek057bc352006-06-04 20:03:39 +0200321 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Rudolf Marek057bc352006-06-04 20:03:39 +0200323curr[1-*]_min Current min value.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 Unit: milliampere
Rudolf Marek057bc352006-06-04 20:03:39 +0200325 RW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Rudolf Marek057bc352006-06-04 20:03:39 +0200327curr[1-*]_input Current input value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 Unit: milliampere
Rudolf Marek057bc352006-06-04 20:03:39 +0200329 RO
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Darrick J. Wong38fb56a2007-10-09 13:39:24 -0700331*********
332* Power *
333*********
334
335power[1-*]_average Average power use
336 Unit: microWatt
337 RO
338
339power[1-*]_average_highest Historical average maximum power use
340 Unit: microWatt
341 RO
342
343power[1-*]_average_lowest Historical average minimum power use
344 Unit: microWatt
345 RO
346
347power[1-*]_input Instantaneous power use
348 Unit: microWatt
349 RO
350
351power[1-*]_input_highest Historical maximum power use
352 Unit: microWatt
353 RO
354
355power[1-*]_input_lowest Historical minimum power use
356 Unit: microWatt
357 RO
358
359power[1-*]_reset_history Reset input_highest, input_lowest,
360 average_highest and average_lowest.
361 WO
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Jean Delvare400b48e2006-03-23 16:46:47 +0100363**********
364* Alarms *
365**********
366
367Each channel or limit may have an associated alarm file, containing a
368boolean value. 1 means than an alarm condition exists, 0 means no alarm.
369
370Usually a given chip will either use channel-related alarms, or
371limit-related alarms, not both. The driver should just reflect the hardware
372implementation.
373
Rudolf Marek057bc352006-06-04 20:03:39 +0200374in[0-*]_alarm
375fan[1-*]_alarm
376temp[1-*]_alarm
Jean Delvare400b48e2006-03-23 16:46:47 +0100377 Channel alarm
Rudolf Marek057bc352006-06-04 20:03:39 +0200378 0: no alarm
379 1: alarm
380 RO
Jean Delvare400b48e2006-03-23 16:46:47 +0100381
382OR
383
Rudolf Marek057bc352006-06-04 20:03:39 +0200384in[0-*]_min_alarm
385in[0-*]_max_alarm
386fan[1-*]_min_alarm
387temp[1-*]_min_alarm
388temp[1-*]_max_alarm
389temp[1-*]_crit_alarm
Jean Delvare400b48e2006-03-23 16:46:47 +0100390 Limit alarm
Rudolf Marek057bc352006-06-04 20:03:39 +0200391 0: no alarm
392 1: alarm
393 RO
Jean Delvare400b48e2006-03-23 16:46:47 +0100394
395Each input channel may have an associated fault file. This can be used
396to notify open diodes, unconnected fans etc. where the hardware
397supports it. When this boolean has value 1, the measurement for that
398channel should not be trusted.
399
Jean Delvare7817a392007-06-09 10:11:16 -0400400in[0-*]_fault
401fan[1-*]_fault
402temp[1-*]_fault
Jean Delvare400b48e2006-03-23 16:46:47 +0100403 Input fault condition
Rudolf Marek057bc352006-06-04 20:03:39 +0200404 0: no fault occured
405 1: fault condition
406 RO
Jean Delvare400b48e2006-03-23 16:46:47 +0100407
408Some chips also offer the possibility to get beeped when an alarm occurs:
409
410beep_enable Master beep enable
Rudolf Marek057bc352006-06-04 20:03:39 +0200411 0: no beeps
412 1: beeps
413 RW
Jean Delvare400b48e2006-03-23 16:46:47 +0100414
Rudolf Marek057bc352006-06-04 20:03:39 +0200415in[0-*]_beep
416fan[1-*]_beep
417temp[1-*]_beep
Jean Delvare400b48e2006-03-23 16:46:47 +0100418 Channel beep
Rudolf Marek057bc352006-06-04 20:03:39 +0200419 0: disable
420 1: enable
421 RW
Jean Delvare400b48e2006-03-23 16:46:47 +0100422
423In theory, a chip could provide per-limit beep masking, but no such chip
424was seen so far.
425
426Old drivers provided a different, non-standard interface to alarms and
427beeps. These interface files are deprecated, but will be kept around
428for compatibility reasons:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430alarms Alarm bitmask.
Rudolf Marek057bc352006-06-04 20:03:39 +0200431 RO
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 Integer representation of one to four bytes.
433 A '1' bit means an alarm.
434 Chips should be programmed for 'comparator' mode so that
435 the alarm will 'come back' after you read the register
436 if it is still valid.
437 Generally a direct representation of a chip's internal
438 alarm registers; there is no standard for the position
Jean Delvare400b48e2006-03-23 16:46:47 +0100439 of individual bits. For this reason, the use of this
440 interface file for new drivers is discouraged. Use
441 individual *_alarm and *_fault files instead.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 Bits are defined in kernel/include/sensors.h.
443
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444beep_mask Bitmask for beep.
Jean Delvare400b48e2006-03-23 16:46:47 +0100445 Same format as 'alarms' with the same bit locations,
446 use discouraged for the same reason. Use individual
447 *_beep files instead.
Rudolf Marek057bc352006-06-04 20:03:39 +0200448 RW
Hans de Goede2ed42632007-09-21 17:03:32 +0200449
450
451sysfs attribute writes interpretation
452-------------------------------------
453
454hwmon sysfs attributes always contain numbers, so the first thing to do is to
455convert the input to a number, there are 2 ways todo this depending whether
456the number can be negative or not:
457unsigned long u = simple_strtoul(buf, NULL, 10);
458long s = simple_strtol(buf, NULL, 10);
459
460With buf being the buffer with the user input being passed by the kernel.
461Notice that we do not use the second argument of strto[u]l, and thus cannot
462tell when 0 is returned, if this was really 0 or is caused by invalid input.
463This is done deliberately as checking this everywhere would add a lot of
464code to the kernel.
465
466Notice that it is important to always store the converted value in an
467unsigned long or long, so that no wrap around can happen before any further
468checking.
469
470After the input string is converted to an (unsigned) long, the value should be
471checked if its acceptable. Be careful with further conversions on the value
472before checking it for validity, as these conversions could still cause a wrap
473around before the check. For example do not multiply the result, and only
474add/subtract if it has been divided before the add/subtract.
475
476What to do if a value is found to be invalid, depends on the type of the
477sysfs attribute that is being set. If it is a continuous setting like a
478tempX_max or inX_max attribute, then the value should be clamped to its
479limits using SENSORS_LIMIT(value, min_limit, max_limit). If it is not
480continuous like for example a tempX_type, then when an invalid value is
481written, -EINVAL should be returned.
482
483Example1, temp1_max, register is a signed 8 bit value (-128 - 127 degrees):
Jean Delvare5fbea512007-10-07 22:44:33 +0200484
485 long v = simple_strtol(buf, NULL, 10) / 1000;
486 v = SENSORS_LIMIT(v, -128, 127);
487 /* write v to register */
Hans de Goede2ed42632007-09-21 17:03:32 +0200488
489Example2, fan divider setting, valid values 2, 4 and 8:
Hans de Goede2ed42632007-09-21 17:03:32 +0200490
Jean Delvare5fbea512007-10-07 22:44:33 +0200491 unsigned long v = simple_strtoul(buf, NULL, 10);
492
493 switch (v) {
494 case 2: v = 1; break;
495 case 4: v = 2; break;
496 case 8: v = 3; break;
497 default:
498 return -EINVAL;
499 }
500 /* write v to register */