22 #include <asm/types.h>
24 #include <linux/kernel.h>
25 #include <linux/module.h>
27 #include <linux/sched.h>
28 #include <linux/device.h>
29 #include <linux/types.h>
33 #include "../w1_int.h"
34 #include "../w1_family.h"
45 static int w1_strong_pullup = 1;
48 static u8 bad_roms[][9] = {
49 {0xaa, 0x00, 0x4b, 0x46, 0xff, 0xff, 0x0c, 0x10, 0x87},
59 static int w1_therm_add_slave(
struct w1_slave *
sl)
64 static void w1_therm_remove_slave(
struct w1_slave *
sl)
70 .add_slave = w1_therm_add_slave,
71 .remove_slave = w1_therm_remove_slave,
74 static struct w1_family w1_therm_family_DS18S20 = {
76 .fops = &w1_therm_fops,
79 static struct w1_family w1_therm_family_DS18B20 = {
81 .fops = &w1_therm_fops,
84 static struct w1_family w1_therm_family_DS1822 = {
86 .fops = &w1_therm_fops,
89 static struct w1_family w1_therm_family_DS28EA00 = {
91 .fops = &w1_therm_fops,
94 static struct w1_family w1_therm_family_DS1825 = {
96 .fops = &w1_therm_fops,
108 static inline int w1_DS18B20_convert_temp(
u8 rom[9]);
109 static inline int w1_DS18S20_convert_temp(
u8 rom[9]);
113 .f = &w1_therm_family_DS18S20,
114 .convert = w1_DS18S20_convert_temp
117 .f = &w1_therm_family_DS1822,
118 .convert = w1_DS18B20_convert_temp
121 .f = &w1_therm_family_DS18B20,
122 .convert = w1_DS18B20_convert_temp
125 .f = &w1_therm_family_DS28EA00,
126 .convert = w1_DS18B20_convert_temp
129 .f = &w1_therm_family_DS1825,
130 .convert = w1_DS18B20_convert_temp
134 static inline int w1_DS18B20_convert_temp(
u8 rom[9])
140 static inline int w1_DS18S20_convert_temp(
u8 rom[9])
148 t = ((
s32)rom[0] >> 1)*1000;
150 t = 1000*(-1*(
s32)(0x100-rom[0]) >> 1);
153 h = 1000*((
s32)rom[7] - (
s32)rom[6]);
160 static inline int w1_convert_temp(
u8 rom[9],
u8 fid)
164 for (i = 0; i <
ARRAY_SIZE(w1_therm_families); ++
i)
165 if (w1_therm_families[i].
f->fid == fid)
166 return w1_therm_families[
i].
convert(rom);
171 static int w1_therm_check_rom(
u8 rom[9])
175 for (i=0; i<
sizeof(bad_roms)/9; ++
i)
176 if (!
memcmp(bad_roms[i], rom, 9))
185 struct w1_slave *
sl = dev_to_w1_slave(device);
186 struct w1_master *
dev = sl->master;
187 u8 rom[9],
crc, verdict, external_power;
188 int i, max_trying = 10;
195 memset(rom, 0,
sizeof(rom));
200 while (max_trying--) {
203 unsigned int tm = 750;
204 unsigned long sleep_rem;
213 if (!external_power && w1_strong_pullup)
218 if (external_power) {
228 }
else if (!w1_strong_pullup) {
230 if (sleep_rem != 0) {
241 "returned %u instead of 9.\n",
252 if (!w1_therm_check_rom(rom))
256 for (i = 0; i < 9; ++
i)
259 crc, (verdict) ?
"YES" :
"NO");
261 memcpy(sl->rom, rom,
sizeof(sl->rom));
263 dev_warn(device,
"18S20 doesn't respond to CONVERT_TEMP.\n");
265 for (i = 0; i < 9; ++
i)
269 w1_convert_temp(rom, sl->family->fid));
275 static int __init w1_therm_init(
void)
279 for (i = 0; i <
ARRAY_SIZE(w1_therm_families); ++
i) {
282 w1_therm_families[
i].
broken = 1;
288 static void __exit w1_therm_fini(
void)
292 for (i = 0; i <
ARRAY_SIZE(w1_therm_families); ++
i)
293 if (!w1_therm_families[i].broken)