Skip to content

Commit 021da53

Browse files
Ivan Zaentsevgregkh
authored andcommitted
w1: w1_therm: Add sysfs entries to control conversion time and driver features
The conversion time of common DS18B20 clones deviates from datasheet specs. Allow adjustment and automatic measure of the conversion time. Add 'conv_time' sysfs attribute: *read*: Current conversion time in milliseconds. *write*: '0': Set default conversion time. '1': Measure and set the conversion time. Make a single temperature conversion, poll and measure an actual value. Measured value is increased by 20% for temperature drift. A new conversion time is returned by reading the same attribute. other positive value: Set the conversion time in milliseconds. The setting is active until a resolution change. Then it is reset to default conversion time for a new resolution. Add 'features' sysfs attribute to control optional driver settings per device. Bit masks to read/write (logical OR): 1: Enable check for conversion success. If byte 6 of scratchpad memory is 0xC after conversion, and temperature reads 85.00 (powerup value) or 127.94 (insufficient power) - return a conversion error. 2: Enable poll for conversion completion. Generate read cycles after the conversion start and wait for 1's. In parasite power mode this feature is not available. There are some clones of DS18B20 with fixed 12 bit resolution. Make the driver verify the resolution by reading back the device after resolution change. Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru> Acked-by: Evgeniy Polyakov <zbr@ioremap.net> Link: https://lore.kernel.org/r/20200904160004.87710-1-ivan.zaentsev@wirenboard.ru Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b31de43 commit 021da53

3 files changed

Lines changed: 410 additions & 31 deletions

File tree

‎Documentation/ABI/testing/sysfs-driver-w1_therm‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ Description:
5353
or resolution to set in bit
5454
* '-xx': xx is kernel error when reading the resolution
5555
* Anything else: do nothing
56+
Some DS18B20 clones are fixed in 12-bit resolution, so the
57+
actual resolution is read back from the chip and verified. Error
58+
is reported if the results differ.
5659
Users: any user space application which wants to communicate with
5760
w1_term device
5861

@@ -114,3 +117,47 @@ Description:
114117
of the bulk read command (not the current temperature).
115118
Users: any user space application which wants to communicate with
116119
w1_term device
120+
121+
122+
What: /sys/bus/w1/devices/.../conv_time
123+
Date: July 2020
124+
Contact: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
125+
Description:
126+
(RW) Get, set, or measure a temperature conversion time. The
127+
setting remains active until a resolution change. Then it is
128+
reset to default (datasheet) conversion time for a new
129+
resolution.
130+
131+
*read*: Actual conversion time in milliseconds. *write*:
132+
'0': Set the default conversion time from the datasheet.
133+
'1': Measure and set the conversion time. Make a single
134+
temperature conversion, measure an actual value.
135+
Increase it by 20% for temperature range. A new
136+
conversion time can be obtained by reading this
137+
same attribute.
138+
other positive value:
139+
Set the conversion time in milliseconds.
140+
141+
Users: An application using the w1_term device
142+
143+
144+
What: /sys/bus/w1/devices/.../features
145+
Date: July 2020
146+
Contact: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
147+
Description:
148+
(RW) Control optional driver settings.
149+
Bit masks to read/write (logical OR):
150+
151+
1: Enable check for conversion success. If byte 6 of
152+
scratchpad memory is 0xC after conversion, and
153+
temperature reads 85.00 (powerup value) or 127.94
154+
(insufficient power) - return a conversion error.
155+
156+
2: Enable poll for conversion completion. Generate read cycles
157+
after the conversion start and wait for 1's. In parasite
158+
power mode this feature is not available.
159+
160+
*read*: Currently selected features, bitwise OR.
161+
*write*: Select features, bitwise OR.
162+
163+
Users: An application using the w1_term device

‎Documentation/w1/slaves/w1_therm.rst‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ read is sent but one sensor is not read immediately, the next access to
5252
temperature on this device will return the temperature measured at the
5353
time of issue of the bulk read command (not the current temperature).
5454

55+
A strong pullup will be applied during the conversion if required.
56+
57+
``conv_time`` sysfs entry is used to get current conversion time (read), and
58+
adjust it (write). A temperature conversion time depends on the device type and
59+
it's current resolution. Default conversion time is set by the driver according
60+
to the device datasheet. A conversion time for many original device clones
61+
deviate from datasheet specs. There are three options: 1) manually set the
62+
correct conversion time by writing a value in milliseconds to ``conv_time``; 2)
63+
auto measure and set a conversion time by writing ``1`` to
64+
``conv_time``; 3) use ``features`` entry to enable poll for conversion
65+
completion. Options 2, 3 can't be used in parasite power mode. To get back to
66+
the default conversion time write ``0`` to ``conv_time``.
67+
5568
Writing a value between 9 and 12 to the sysfs w1_slave file will change the
5669
precision of the sensor for the next readings. This value is in (volatile)
5770
SRAM, so it is reset when the sensor gets power-cycled.
@@ -61,11 +74,14 @@ has to be written to the sysfs w1_slave file. Since the EEPROM has a limited
6174
amount of writes (>50k), this command should be used wisely.
6275

6376
Alternatively, resolution can be set or read (value from 9 to 12) using the
64-
dedicated resolution sysfs entry on each device. This sysfs entry is not
65-
present for devices not supporting this feature. Driver will adjust the
66-
correct conversion time for each device regarding to its resolution setting.
67-
In particular, strong pullup will be applied if required during the conversion
68-
duration.
77+
dedicated resolution sysfs entry on each device. This sysfs entry is not present
78+
for devices not supporting this feature.
79+
80+
Some non-genuine DS18B20 chips are
81+
fixed in 12-bit mode only, so the actual resolution is read back from the chip
82+
and verified by the driver.
83+
84+
Note: Changing the resolution reverts the conversion time to default.
6985

7086
The write-only sysfs entry eeprom is an alternative for EEPROM operations:
7187
* 'save': will save device RAM to EEPROM
@@ -104,3 +120,14 @@ location of the chip in the 1-wire bus without needing pre-existing
104120
knowledge of the bus ordering. Support is provided through the sysfs
105121
w1_seq file. The file will contain a single line with an integer value
106122
representing the device index in the bus starting at 0.
123+
124+
``features`` sysfs entry controls optional driver settings per device.
125+
Insufficient power in parasite mode, line noise and insufficient conversion time
126+
may lead to conversion failure. Original DS18B20 and some clones allow for
127+
detection of invalid conversion. Write bit mask ``1`` to ``features`` to enable
128+
checking the conversion success. If byte 6 of scratchpad memory is 0xC after
129+
conversion and temperature reads 85.00 (powerup value) or 127.94 (insufficient
130+
power), the driver returns a conversion error. Bit mask ``2`` enables poll for
131+
conversion completion (normal power only) by generating read cycles on the bus
132+
after conversion starts. In parasite power mode this feature is not available.
133+
Feature bit masks may be combined (OR).

0 commit comments

Comments
 (0)