w1: add ability to set (SRAM) and store (EEPROM) configuration for temp sensors like DS18B20
Subsystems (2)
PATCH v2 1/1 w1: add ability to set (SRAM) and store (EEPROM) configuration for temp sensors like DS18B20
Since many temperature sensors come "preconfigured" with a lower precision, people are stuck at that precision when running on a kernel based device (unlike the Dallas 1Wire library for e.g. Arduino, which supports writing the configuration/scratchpad). This patch adds write support for the scratchpad/precision registers via w1_slave sysfs.
Now with real name, sorry for the back and forth.
Signed-off-by Ben Sen <[email protected]>
--- Documentation/w1/slaves/w1_therm | 10 +- drivers/w1/slaves/w1_therm.c | 218 +++++++++++++++++++++++++++++++++++++-- drivers/w1/w1.h | 2 + 3 files changed, 222 insertions(+), 8 deletions(-)
Documentation/w1/slaves/w1_therm +9 -1
@@ -33,7 +33,15 @@ temperature conversion at a time. If none of the devices are parasite powered it would be possible to convert all the devices at the same time and then go back to read individual sensors. That isn't currently supported. The driver also doesn't support reduced -precision (which would also reduce the conversion time). +precision (which would also reduce the conversion time) when reading values. + +Writing a value between 9 and 12 to the sysfs w1_slave file will change the +precision of the sensor for the next readings. This value is in (volatile) +SRAM, so it is reset when the sensor gets power-cycled. + +To store the current precision configuration into EEPROM, the value 0 +has to be written to the sysfs w1_slave file. Since the EEPROM has a limited +amount of writes (>50k), this command should be used wisely. The module parameter strong_pullup can be set to 0 to disable the strong pullup, 1 to enable autodetection or 2 to force strong pullup.
drivers/w1/slaves/w1_therm.c +211 -7
268 lines not on this page · raw message
drivers/w1/w1.h +2 -0
@@ -58,6 +58,8 @@ struct w1_reg_num#define W1_ALARM_SEARCH 0xEC#define W1_CONVERT_TEMP 0x44#define W1_SKIP_ROM 0xCC +#define W1_COPY_SCRATCHPAD 0x48 +#define W1_WRITE_SCRATCHPAD 0x4E#define W1_READ_SCRATCHPAD 0xBE#define W1_READ_ROM 0x33#define W1_READ_PSUPPLY 0xB4
Signature · 1 line
2.5.0