aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/w1/slaves/w1_therm.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/w1/slaves/w1_therm.c')
-rw-r--r--drivers/w1/slaves/w1_therm.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index 92d08e7fcba2..c1a702f8c803 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -41,14 +41,18 @@ MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol, temperature famil
41 * If it was disabled a parasite powered device might not get the require 41 * If it was disabled a parasite powered device might not get the require
42 * current to do a temperature conversion. If it is enabled parasite powered 42 * current to do a temperature conversion. If it is enabled parasite powered
43 * devices have a better chance of getting the current required. 43 * devices have a better chance of getting the current required.
44 * In case the parasite power-detection is not working (seems to be the case
45 * for some DS18S20) the strong pullup can also be forced, regardless of the
46 * power state of the devices.
47 *
48 * Summary of options:
49 * - strong_pullup = 0 Disable strong pullup completely
50 * - strong_pullup = 1 Enable automatic strong pullup detection
51 * - strong_pullup = 2 Force strong pullup
44 */ 52 */
45static int w1_strong_pullup = 1; 53static int w1_strong_pullup = 1;
46module_param_named(strong_pullup, w1_strong_pullup, int, 0); 54module_param_named(strong_pullup, w1_strong_pullup, int, 0);
47 55
48static u8 bad_roms[][9] = {
49 {0xaa, 0x00, 0x4b, 0x46, 0xff, 0xff, 0x0c, 0x10, 0x87},
50 {}
51 };
52 56
53static ssize_t w1_therm_read(struct device *device, 57static ssize_t w1_therm_read(struct device *device,
54 struct device_attribute *attr, char *buf); 58 struct device_attribute *attr, char *buf);
@@ -168,16 +172,6 @@ static inline int w1_convert_temp(u8 rom[9], u8 fid)
168 return 0; 172 return 0;
169} 173}
170 174
171static int w1_therm_check_rom(u8 rom[9])
172{
173 int i;
174
175 for (i=0; i<sizeof(bad_roms)/9; ++i)
176 if (!memcmp(bad_roms[i], rom, 9))
177 return 1;
178
179 return 0;
180}
181 175
182static ssize_t w1_therm_read(struct device *device, 176static ssize_t w1_therm_read(struct device *device,
183 struct device_attribute *attr, char *buf) 177 struct device_attribute *attr, char *buf)
@@ -194,10 +188,11 @@ static ssize_t w1_therm_read(struct device *device,
194 188
195 memset(rom, 0, sizeof(rom)); 189 memset(rom, 0, sizeof(rom));
196 190
197 verdict = 0;
198 crc = 0;
199
200 while (max_trying--) { 191 while (max_trying--) {
192
193 verdict = 0;
194 crc = 0;
195
201 if (!w1_reset_select_slave(sl)) { 196 if (!w1_reset_select_slave(sl)) {
202 int count = 0; 197 int count = 0;
203 unsigned int tm = 750; 198 unsigned int tm = 750;
@@ -210,7 +205,8 @@ static ssize_t w1_therm_read(struct device *device,
210 continue; 205 continue;
211 206
212 /* 750ms strong pullup (or delay) after the convert */ 207 /* 750ms strong pullup (or delay) after the convert */
213 if (!external_power && w1_strong_pullup) 208 if (w1_strong_pullup == 2 ||
209 (!external_power && w1_strong_pullup))
214 w1_next_pullup(dev, tm); 210 w1_next_pullup(dev, tm);
215 211
216 w1_write_8(dev, W1_CONVERT_TEMP); 212 w1_write_8(dev, W1_CONVERT_TEMP);
@@ -249,7 +245,7 @@ static ssize_t w1_therm_read(struct device *device,
249 } 245 }
250 } 246 }
251 247
252 if (!w1_therm_check_rom(rom)) 248 if (verdict)
253 break; 249 break;
254 } 250 }
255 251
@@ -260,7 +256,7 @@ static ssize_t w1_therm_read(struct device *device,
260 if (verdict) 256 if (verdict)
261 memcpy(sl->rom, rom, sizeof(sl->rom)); 257 memcpy(sl->rom, rom, sizeof(sl->rom));
262 else 258 else
263 dev_warn(device, "18S20 doesn't respond to CONVERT_TEMP.\n"); 259 dev_warn(device, "Read failed CRC check\n");
264 260
265 for (i = 0; i < 9; ++i) 261 for (i = 0; i < 9; ++i)
266 c -= snprintf(buf + PAGE_SIZE - c, c, "%02x ", sl->rom[i]); 262 c -= snprintf(buf + PAGE_SIZE - c, c, "%02x ", sl->rom[i]);