diff options
author | Evgeniy Polyakov <johnpol@2ka.mipt.ru> | 2005-08-11 09:27:49 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-09-08 17:41:26 -0400 |
commit | ea7d8f65c865ebfa1d7cd67c360a87333ff013c1 (patch) | |
tree | 1e687c32d53a92c10a61fb23ab14763459ff5779 | |
parent | db2d0008de519c5db6baec45f7831e08790301cf (diff) |
[PATCH] w1: Added w1_reset_select_slave() - Resets the bus and then selects the slave by
sending either a skip rom or a rom match.
Patch from Ben Gardner <bgardner@wabtec.com>
Signed-off-by: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/w1/w1_io.c | 24 | ||||
-rw-r--r-- | drivers/w1/w1_io.h | 1 | ||||
-rw-r--r-- | drivers/w1/w1_therm.c | 11 |
3 files changed, 27 insertions, 9 deletions
diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c index 00f032220173..e2a043354ddf 100644 --- a/drivers/w1/w1_io.c +++ b/drivers/w1/w1_io.c | |||
@@ -277,6 +277,29 @@ void w1_search_devices(struct w1_master *dev, w1_slave_found_callback cb) | |||
277 | w1_search(dev, cb); | 277 | w1_search(dev, cb); |
278 | } | 278 | } |
279 | 279 | ||
280 | /** | ||
281 | * Resets the bus and then selects the slave by sending either a skip rom | ||
282 | * or a rom match. | ||
283 | * The w1 master lock must be held. | ||
284 | * | ||
285 | * @param sl the slave to select | ||
286 | * @return 0=success, anything else=error | ||
287 | */ | ||
288 | int w1_reset_select_slave(struct w1_slave *sl) | ||
289 | { | ||
290 | if (w1_reset_bus(sl->master)) | ||
291 | return -1; | ||
292 | |||
293 | if (sl->master->slave_count == 1) | ||
294 | w1_write_8(sl->master, W1_SKIP_ROM); | ||
295 | else { | ||
296 | u8 match[9] = {W1_MATCH_ROM, }; | ||
297 | memcpy(&match[1], (u8 *)&sl->reg_num, 8); | ||
298 | w1_write_block(sl->master, match, 9); | ||
299 | } | ||
300 | return 0; | ||
301 | } | ||
302 | |||
280 | EXPORT_SYMBOL(w1_touch_bit); | 303 | EXPORT_SYMBOL(w1_touch_bit); |
281 | EXPORT_SYMBOL(w1_write_8); | 304 | EXPORT_SYMBOL(w1_write_8); |
282 | EXPORT_SYMBOL(w1_read_8); | 305 | EXPORT_SYMBOL(w1_read_8); |
@@ -286,3 +309,4 @@ EXPORT_SYMBOL(w1_delay); | |||
286 | EXPORT_SYMBOL(w1_read_block); | 309 | EXPORT_SYMBOL(w1_read_block); |
287 | EXPORT_SYMBOL(w1_write_block); | 310 | EXPORT_SYMBOL(w1_write_block); |
288 | EXPORT_SYMBOL(w1_search_devices); | 311 | EXPORT_SYMBOL(w1_search_devices); |
312 | EXPORT_SYMBOL(w1_reset_select_slave); | ||
diff --git a/drivers/w1/w1_io.h b/drivers/w1/w1_io.h index af5829778aaa..232860184a29 100644 --- a/drivers/w1/w1_io.h +++ b/drivers/w1/w1_io.h | |||
@@ -34,5 +34,6 @@ u8 w1_calc_crc8(u8 *, int); | |||
34 | void w1_write_block(struct w1_master *, const u8 *, int); | 34 | void w1_write_block(struct w1_master *, const u8 *, int); |
35 | u8 w1_read_block(struct w1_master *, u8 *, int); | 35 | u8 w1_read_block(struct w1_master *, u8 *, int); |
36 | void w1_search_devices(struct w1_master *dev, w1_slave_found_callback cb); | 36 | void w1_search_devices(struct w1_master *dev, w1_slave_found_callback cb); |
37 | int w1_reset_select_slave(struct w1_slave *sl); | ||
37 | 38 | ||
38 | #endif /* __W1_IO_H */ | 39 | #endif /* __W1_IO_H */ |
diff --git a/drivers/w1/w1_therm.c b/drivers/w1/w1_therm.c index 2259f3d851ff..2ed0e0f48268 100644 --- a/drivers/w1/w1_therm.c +++ b/drivers/w1/w1_therm.c | |||
@@ -176,15 +176,10 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si | |||
176 | crc = 0; | 176 | crc = 0; |
177 | 177 | ||
178 | while (max_trying--) { | 178 | while (max_trying--) { |
179 | if (!w1_reset_bus (dev)) { | 179 | if (!w1_reset_select_slave(sl)) { |
180 | int count = 0; | 180 | int count = 0; |
181 | u8 match[9] = {W1_MATCH_ROM, }; | ||
182 | unsigned int tm = 750; | 181 | unsigned int tm = 750; |
183 | 182 | ||
184 | memcpy(&match[1], (u64 *) & sl->reg_num, 8); | ||
185 | |||
186 | w1_write_block(dev, match, 9); | ||
187 | |||
188 | w1_write_8(dev, W1_CONVERT_TEMP); | 183 | w1_write_8(dev, W1_CONVERT_TEMP); |
189 | 184 | ||
190 | while (tm) { | 185 | while (tm) { |
@@ -193,8 +188,7 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si | |||
193 | flush_signals(current); | 188 | flush_signals(current); |
194 | } | 189 | } |
195 | 190 | ||
196 | if (!w1_reset_bus (dev)) { | 191 | if (!w1_reset_select_slave(sl)) { |
197 | w1_write_block(dev, match, 9); | ||
198 | 192 | ||
199 | w1_write_8(dev, W1_READ_SCRATCHPAD); | 193 | w1_write_8(dev, W1_READ_SCRATCHPAD); |
200 | if ((count = w1_read_block(dev, rom, 9)) != 9) { | 194 | if ((count = w1_read_block(dev, rom, 9)) != 9) { |
@@ -205,7 +199,6 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si | |||
205 | 199 | ||
206 | if (rom[8] == crc && rom[0]) | 200 | if (rom[8] == crc && rom[0]) |
207 | verdict = 1; | 201 | verdict = 1; |
208 | |||
209 | } | 202 | } |
210 | } | 203 | } |
211 | 204 | ||