sysfs-interface 21 KB

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