aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/w1/masters/ds2490.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/w1/masters/ds2490.c')
-rw-r--r--drivers/w1/masters/ds2490.c348
1 files changed, 214 insertions, 134 deletions
diff --git a/drivers/w1/masters/ds2490.c b/drivers/w1/masters/ds2490.c
index b63b5e044a4c..59ad6e95af8f 100644
--- a/drivers/w1/masters/ds2490.c
+++ b/drivers/w1/masters/ds2490.c
@@ -88,7 +88,7 @@
88#define COMM_DT 0x2000 88#define COMM_DT 0x2000
89#define COMM_SPU 0x1000 89#define COMM_SPU 0x1000
90#define COMM_F 0x0800 90#define COMM_F 0x0800
91#define COMM_NTP 0x0400 91#define COMM_NTF 0x0400
92#define COMM_ICP 0x0200 92#define COMM_ICP 0x0200
93#define COMM_RST 0x0100 93#define COMM_RST 0x0100
94 94
@@ -98,11 +98,6 @@
98#define BRANCH_MAIN 0xCC 98#define BRANCH_MAIN 0xCC
99#define BRANCH_AUX 0x33 99#define BRANCH_AUX 0x33
100 100
101/*
102 * Duration of the strong pull-up pulse in milliseconds.
103 */
104#define PULLUP_PULSE_DURATION 750
105
106/* Status flags */ 101/* Status flags */
107#define ST_SPUA 0x01 /* Strong Pull-up is active */ 102#define ST_SPUA 0x01 /* Strong Pull-up is active */
108#define ST_PRGA 0x02 /* 12V programming pulse is being generated */ 103#define ST_PRGA 0x02 /* 12V programming pulse is being generated */
@@ -112,6 +107,17 @@
112#define ST_IDLE 0x20 /* DS2490 is currently idle */ 107#define ST_IDLE 0x20 /* DS2490 is currently idle */
113#define ST_EPOF 0x80 108#define ST_EPOF 0x80
114 109
110/* Result Register flags */
111#define RR_DETECT 0xA5 /* New device detected */
112#define RR_NRS 0x01 /* Reset no presence or ... */
113#define RR_SH 0x02 /* short on reset or set path */
114#define RR_APP 0x04 /* alarming presence on reset */
115#define RR_VPP 0x08 /* 12V expected not seen */
116#define RR_CMP 0x10 /* compare error */
117#define RR_CRC 0x20 /* CRC error detected */
118#define RR_RDP 0x40 /* redirected page */
119#define RR_EOS 0x80 /* end of search error */
120
115#define SPEED_NORMAL 0x00 121#define SPEED_NORMAL 0x00
116#define SPEED_FLEXIBLE 0x01 122#define SPEED_FLEXIBLE 0x01
117#define SPEED_OVERDRIVE 0x02 123#define SPEED_OVERDRIVE 0x02
@@ -131,6 +137,15 @@ struct ds_device
131 137
132 int ep[NUM_EP]; 138 int ep[NUM_EP];
133 139
140 /* Strong PullUp
141 * 0: pullup not active, else duration in milliseconds
142 */
143 int spu_sleep;
144 /* spu_bit contains COMM_SPU or 0 depending on if the strong pullup
145 * should be active or not for writes.
146 */
147 u16 spu_bit;
148
134 struct w1_bus_master master; 149 struct w1_bus_master master;
135}; 150};
136 151
@@ -164,7 +179,6 @@ MODULE_DEVICE_TABLE(usb, ds_id_table);
164static int ds_probe(struct usb_interface *, const struct usb_device_id *); 179static int ds_probe(struct usb_interface *, const struct usb_device_id *);
165static void ds_disconnect(struct usb_interface *); 180static void ds_disconnect(struct usb_interface *);
166 181
167static inline void ds_dump_status(unsigned char *, unsigned char *, int);
168static int ds_send_control(struct ds_device *, u16, u16); 182static int ds_send_control(struct ds_device *, u16, u16);
169static int ds_send_control_cmd(struct ds_device *, u16, u16); 183static int ds_send_control_cmd(struct ds_device *, u16, u16);
170 184
@@ -192,7 +206,7 @@ static int ds_send_control_cmd(struct ds_device *dev, u16 value, u16 index)
192 206
193 return err; 207 return err;
194} 208}
195#if 0 209
196static int ds_send_control_mode(struct ds_device *dev, u16 value, u16 index) 210static int ds_send_control_mode(struct ds_device *dev, u16 value, u16 index)
197{ 211{
198 int err; 212 int err;
@@ -207,7 +221,7 @@ static int ds_send_control_mode(struct ds_device *dev, u16 value, u16 index)
207 221
208 return err; 222 return err;
209} 223}
210#endif 224
211static int ds_send_control(struct ds_device *dev, u16 value, u16 index) 225static int ds_send_control(struct ds_device *dev, u16 value, u16 index)
212{ 226{
213 int err; 227 int err;
@@ -223,11 +237,6 @@ static int ds_send_control(struct ds_device *dev, u16 value, u16 index)
223 return err; 237 return err;
224} 238}
225 239
226static inline void ds_dump_status(unsigned char *buf, unsigned char *str, int off)
227{
228 printk("%45s: %8x\n", str, buf[off]);
229}
230
231static int ds_recv_status_nodump(struct ds_device *dev, struct ds_status *st, 240static int ds_recv_status_nodump(struct ds_device *dev, struct ds_status *st,
232 unsigned char *buf, int size) 241 unsigned char *buf, int size)
233{ 242{
@@ -248,62 +257,81 @@ static int ds_recv_status_nodump(struct ds_device *dev, struct ds_status *st,
248 return count; 257 return count;
249} 258}
250 259
251static int ds_recv_status(struct ds_device *dev, struct ds_status *st) 260static inline void ds_print_msg(unsigned char *buf, unsigned char *str, int off)
252{ 261{
253 unsigned char buf[64]; 262 printk(KERN_INFO "%45s: %8x\n", str, buf[off]);
254 int count, err = 0, i; 263}
255
256 memcpy(st, buf, sizeof(*st));
257 264
258 count = ds_recv_status_nodump(dev, st, buf, sizeof(buf)); 265static void ds_dump_status(struct ds_device *dev, unsigned char *buf, int count)
259 if (count < 0) 266{
260 return err; 267 int i;
261 268
262 printk("0x%x: count=%d, status: ", dev->ep[EP_STATUS], count); 269 printk(KERN_INFO "0x%x: count=%d, status: ", dev->ep[EP_STATUS], count);
263 for (i=0; i<count; ++i) 270 for (i=0; i<count; ++i)
264 printk("%02x ", buf[i]); 271 printk("%02x ", buf[i]);
265 printk("\n"); 272 printk(KERN_INFO "\n");
266 273
267 if (count >= 16) { 274 if (count >= 16) {
268 ds_dump_status(buf, "enable flag", 0); 275 ds_print_msg(buf, "enable flag", 0);
269 ds_dump_status(buf, "1-wire speed", 1); 276 ds_print_msg(buf, "1-wire speed", 1);
270 ds_dump_status(buf, "strong pullup duration", 2); 277 ds_print_msg(buf, "strong pullup duration", 2);
271 ds_dump_status(buf, "programming pulse duration", 3); 278 ds_print_msg(buf, "programming pulse duration", 3);
272 ds_dump_status(buf, "pulldown slew rate control", 4); 279 ds_print_msg(buf, "pulldown slew rate control", 4);
273 ds_dump_status(buf, "write-1 low time", 5); 280 ds_print_msg(buf, "write-1 low time", 5);
274 ds_dump_status(buf, "data sample offset/write-0 recovery time", 6); 281 ds_print_msg(buf, "data sample offset/write-0 recovery time",
275 ds_dump_status(buf, "reserved (test register)", 7); 282 6);
276 ds_dump_status(buf, "device status flags", 8); 283 ds_print_msg(buf, "reserved (test register)", 7);
277 ds_dump_status(buf, "communication command byte 1", 9); 284 ds_print_msg(buf, "device status flags", 8);
278 ds_dump_status(buf, "communication command byte 2", 10); 285 ds_print_msg(buf, "communication command byte 1", 9);
279 ds_dump_status(buf, "communication command buffer status", 11); 286 ds_print_msg(buf, "communication command byte 2", 10);
280 ds_dump_status(buf, "1-wire data output buffer status", 12); 287 ds_print_msg(buf, "communication command buffer status", 11);
281 ds_dump_status(buf, "1-wire data input buffer status", 13); 288 ds_print_msg(buf, "1-wire data output buffer status", 12);
282 ds_dump_status(buf, "reserved", 14); 289 ds_print_msg(buf, "1-wire data input buffer status", 13);
283 ds_dump_status(buf, "reserved", 15); 290 ds_print_msg(buf, "reserved", 14);
291 ds_print_msg(buf, "reserved", 15);
284 } 292 }
285 293 for (i = 16; i < count; ++i) {
286 memcpy(st, buf, sizeof(*st)); 294 if (buf[i] == RR_DETECT) {
287 295 ds_print_msg(buf, "new device detect", i);
288 if (st->status & ST_EPOF) { 296 continue;
289 printk(KERN_INFO "Resetting device after ST_EPOF.\n"); 297 }
290 err = ds_send_control_cmd(dev, CTL_RESET_DEVICE, 0); 298 ds_print_msg(buf, "Result Register Value: ", i);
291 if (err) 299 if (buf[i] & RR_NRS)
292 return err; 300 printk(KERN_INFO "NRS: Reset no presence or ...\n");
293 count = ds_recv_status_nodump(dev, st, buf, sizeof(buf)); 301 if (buf[i] & RR_SH)
294 if (count < 0) 302 printk(KERN_INFO "SH: short on reset or set path\n");
295 return err; 303 if (buf[i] & RR_APP)
296 } 304 printk(KERN_INFO "APP: alarming presence on reset\n");
297#if 0 305 if (buf[i] & RR_VPP)
298 if (st->status & ST_IDLE) { 306 printk(KERN_INFO "VPP: 12V expected not seen\n");
299 printk(KERN_INFO "Resetting pulse after ST_IDLE.\n"); 307 if (buf[i] & RR_CMP)
300 err = ds_start_pulse(dev, PULLUP_PULSE_DURATION); 308 printk(KERN_INFO "CMP: compare error\n");
301 if (err) 309 if (buf[i] & RR_CRC)
302 return err; 310 printk(KERN_INFO "CRC: CRC error detected\n");
311 if (buf[i] & RR_RDP)
312 printk(KERN_INFO "RDP: redirected page\n");
313 if (buf[i] & RR_EOS)
314 printk(KERN_INFO "EOS: end of search error\n");
303 } 315 }
304#endif 316}
305 317
306 return err; 318static void ds_reset_device(struct ds_device *dev)
319{
320 ds_send_control_cmd(dev, CTL_RESET_DEVICE, 0);
321 /* Always allow strong pullup which allow individual writes to use
322 * the strong pullup.
323 */
324 if (ds_send_control_mode(dev, MOD_PULSE_EN, PULSE_SPUE))
325 printk(KERN_ERR "ds_reset_device: "
326 "Error allowing strong pullup\n");
327 /* Chip strong pullup time was cleared. */
328 if (dev->spu_sleep) {
329 /* lower 4 bits are 0, see ds_set_pullup */
330 u8 del = dev->spu_sleep>>4;
331 if (ds_send_control(dev, COMM_SET_DURATION | COMM_IM, del))
332 printk(KERN_ERR "ds_reset_device: "
333 "Error setting duration\n");
334 }
307} 335}
308 336
309static int ds_recv_data(struct ds_device *dev, unsigned char *buf, int size) 337static int ds_recv_data(struct ds_device *dev, unsigned char *buf, int size)
@@ -311,13 +339,27 @@ static int ds_recv_data(struct ds_device *dev, unsigned char *buf, int size)
311 int count, err; 339 int count, err;
312 struct ds_status st; 340 struct ds_status st;
313 341
342 /* Careful on size. If size is less than what is available in
343 * the input buffer, the device fails the bulk transfer and
344 * clears the input buffer. It could read the maximum size of
345 * the data buffer, but then do you return the first, last, or
346 * some set of the middle size bytes? As long as the rest of
347 * the code is correct there will be size bytes waiting. A
348 * call to ds_wait_status will wait until the device is idle
349 * and any data to be received would have been available.
350 */
314 count = 0; 351 count = 0;
315 err = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN]), 352 err = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN]),
316 buf, size, &count, 1000); 353 buf, size, &count, 1000);
317 if (err < 0) { 354 if (err < 0) {
355 u8 buf[0x20];
356 int count;
357
318 printk(KERN_INFO "Clearing ep0x%x.\n", dev->ep[EP_DATA_IN]); 358 printk(KERN_INFO "Clearing ep0x%x.\n", dev->ep[EP_DATA_IN]);
319 usb_clear_halt(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN])); 359 usb_clear_halt(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN]));
320 ds_recv_status(dev, &st); 360
361 count = ds_recv_status_nodump(dev, &st, buf, sizeof(buf));
362 ds_dump_status(dev, buf, count);
321 return err; 363 return err;
322 } 364 }
323 365
@@ -341,7 +383,8 @@ static int ds_send_data(struct ds_device *dev, unsigned char *buf, int len)
341 count = 0; 383 count = 0;
342 err = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, dev->ep[EP_DATA_OUT]), buf, len, &count, 1000); 384 err = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, dev->ep[EP_DATA_OUT]), buf, len, &count, 1000);
343 if (err < 0) { 385 if (err < 0) {
344 printk(KERN_ERR "Failed to read 1-wire data from 0x02: err=%d.\n", err); 386 printk(KERN_ERR "Failed to write 1-wire data to ep0x%x: "
387 "err=%d.\n", dev->ep[EP_DATA_OUT], err);
345 return err; 388 return err;
346 } 389 }
347 390
@@ -397,7 +440,7 @@ int ds_detect(struct ds_device *dev, struct ds_status *st)
397 if (err) 440 if (err)
398 return err; 441 return err;
399 442
400 err = ds_recv_status(dev, st); 443 err = ds_dump_status(dev, st);
401 444
402 return err; 445 return err;
403} 446}
@@ -420,33 +463,49 @@ static int ds_wait_status(struct ds_device *dev, struct ds_status *st)
420 printk("\n"); 463 printk("\n");
421 } 464 }
422#endif 465#endif
423 } while(!(buf[0x08] & 0x20) && !(err < 0) && ++count < 100); 466 } while (!(buf[0x08] & ST_IDLE) && !(err < 0) && ++count < 100);
467
468 if (err >= 16 && st->status & ST_EPOF) {
469 printk(KERN_INFO "Resetting device after ST_EPOF.\n");
470 ds_reset_device(dev);
471 /* Always dump the device status. */
472 count = 101;
473 }
424 474
475 /* Dump the status for errors or if there is extended return data.
476 * The extended status includes new device detection (maybe someone
477 * can do something with it).
478 */
479 if (err > 16 || count >= 100 || err < 0)
480 ds_dump_status(dev, buf, err);
425 481
426 if (((err > 16) && (buf[0x10] & 0x01)) || count >= 100 || err < 0) { 482 /* Extended data isn't an error. Well, a short is, but the dump
427 ds_recv_status(dev, st); 483 * would have already told the user that and we can't do anything
484 * about it in software anyway.
485 */
486 if (count >= 100 || err < 0)
428 return -1; 487 return -1;
429 } else 488 else
430 return 0; 489 return 0;
431} 490}
432 491
433static int ds_reset(struct ds_device *dev, struct ds_status *st) 492static int ds_reset(struct ds_device *dev)
434{ 493{
435 int err; 494 int err;
436 495
437 //err = ds_send_control(dev, COMM_1_WIRE_RESET | COMM_F | COMM_IM | COMM_SE, SPEED_FLEXIBLE); 496 /* Other potentionally interesting flags for reset.
438 err = ds_send_control(dev, 0x43, SPEED_NORMAL); 497 *
498 * COMM_NTF: Return result register feedback. This could be used to
499 * detect some conditions such as short, alarming presence, or
500 * detect if a new device was detected.
501 *
502 * COMM_SE which allows SPEED_NORMAL, SPEED_FLEXIBLE, SPEED_OVERDRIVE:
503 * Select the data transfer rate.
504 */
505 err = ds_send_control(dev, COMM_1_WIRE_RESET | COMM_IM, SPEED_NORMAL);
439 if (err) 506 if (err)
440 return err; 507 return err;
441 508
442 ds_wait_status(dev, st);
443#if 0
444 if (st->command_buffer_status) {
445 printk(KERN_INFO "Short circuit.\n");
446 return -EIO;
447 }
448#endif
449
450 return 0; 509 return 0;
451} 510}
452 511
@@ -471,60 +530,43 @@ static int ds_set_speed(struct ds_device *dev, int speed)
471} 530}
472#endif /* 0 */ 531#endif /* 0 */
473 532
474static int ds_start_pulse(struct ds_device *dev, int delay) 533static int ds_set_pullup(struct ds_device *dev, int delay)
475{ 534{
476 int err; 535 int err = 0;
477 u8 del = 1 + (u8)(delay >> 4); 536 u8 del = 1 + (u8)(delay >> 4);
478 struct ds_status st; 537 /* Just storing delay would not get the trunication and roundup. */
479 538 int ms = del<<4;
480#if 0 539
481 err = ds_stop_pulse(dev, 10); 540 /* Enable spu_bit if a delay is set. */
482 if (err) 541 dev->spu_bit = delay ? COMM_SPU : 0;
542 /* If delay is zero, it has already been disabled, if the time is
543 * the same as the hardware was last programmed to, there is also
544 * nothing more to do. Compare with the recalculated value ms
545 * rather than del or delay which can have a different value.
546 */
547 if (delay == 0 || ms == dev->spu_sleep)
483 return err; 548 return err;
484 549
485 err = ds_send_control_mode(dev, MOD_PULSE_EN, PULSE_SPUE);
486 if (err)
487 return err;
488#endif
489 err = ds_send_control(dev, COMM_SET_DURATION | COMM_IM, del); 550 err = ds_send_control(dev, COMM_SET_DURATION | COMM_IM, del);
490 if (err) 551 if (err)
491 return err; 552 return err;
492 553
493 err = ds_send_control(dev, COMM_PULSE | COMM_IM | COMM_F, 0); 554 dev->spu_sleep = ms;
494 if (err)
495 return err;
496
497 mdelay(delay);
498
499 ds_wait_status(dev, &st);
500 555
501 return err; 556 return err;
502} 557}
503 558
504static int ds_touch_bit(struct ds_device *dev, u8 bit, u8 *tbit) 559static int ds_touch_bit(struct ds_device *dev, u8 bit, u8 *tbit)
505{ 560{
506 int err, count; 561 int err;
507 struct ds_status st; 562 struct ds_status st;
508 u16 value = (COMM_BIT_IO | COMM_IM) | ((bit) ? COMM_D : 0);
509 u16 cmd;
510 563
511 err = ds_send_control(dev, value, 0); 564 err = ds_send_control(dev, COMM_BIT_IO | COMM_IM | (bit ? COMM_D : 0),
565 0);
512 if (err) 566 if (err)
513 return err; 567 return err;
514 568
515 count = 0; 569 ds_wait_status(dev, &st);
516 do {
517 err = ds_wait_status(dev, &st);
518 if (err)
519 return err;
520
521 cmd = st.command0 | (st.command1 << 8);
522 } while (cmd != value && ++count < 10);
523
524 if (err < 0 || count >= 10) {
525 printk(KERN_ERR "Failed to obtain status.\n");
526 return -EINVAL;
527 }
528 570
529 err = ds_recv_data(dev, tbit, sizeof(*tbit)); 571 err = ds_recv_data(dev, tbit, sizeof(*tbit));
530 if (err < 0) 572 if (err < 0)
@@ -533,12 +575,18 @@ static int ds_touch_bit(struct ds_device *dev, u8 bit, u8 *tbit)
533 return 0; 575 return 0;
534} 576}
535 577
578#if 0
536static int ds_write_bit(struct ds_device *dev, u8 bit) 579static int ds_write_bit(struct ds_device *dev, u8 bit)
537{ 580{
538 int err; 581 int err;
539 struct ds_status st; 582 struct ds_status st;
540 583
541 err = ds_send_control(dev, COMM_BIT_IO | COMM_IM | (bit) ? COMM_D : 0, 0); 584 /* Set COMM_ICP to write without a readback. Note, this will
585 * produce one time slot, a down followed by an up with COMM_D
586 * only determing the timing.
587 */
588 err = ds_send_control(dev, COMM_BIT_IO | COMM_IM | COMM_ICP |
589 (bit ? COMM_D : 0), 0);
542 if (err) 590 if (err)
543 return err; 591 return err;
544 592
@@ -546,6 +594,7 @@ static int ds_write_bit(struct ds_device *dev, u8 bit)
546 594
547 return 0; 595 return 0;
548} 596}
597#endif
549 598
550static int ds_write_byte(struct ds_device *dev, u8 byte) 599static int ds_write_byte(struct ds_device *dev, u8 byte)
551{ 600{
@@ -553,10 +602,13 @@ static int ds_write_byte(struct ds_device *dev, u8 byte)
553 struct ds_status st; 602 struct ds_status st;
554 u8 rbyte; 603 u8 rbyte;
555 604
556 err = ds_send_control(dev, COMM_BYTE_IO | COMM_IM | COMM_SPU, byte); 605 err = ds_send_control(dev, COMM_BYTE_IO | COMM_IM | dev->spu_bit, byte);
557 if (err) 606 if (err)
558 return err; 607 return err;
559 608
609 if (dev->spu_bit)
610 msleep(dev->spu_sleep);
611
560 err = ds_wait_status(dev, &st); 612 err = ds_wait_status(dev, &st);
561 if (err) 613 if (err)
562 return err; 614 return err;
@@ -565,8 +617,6 @@ static int ds_write_byte(struct ds_device *dev, u8 byte)
565 if (err < 0) 617 if (err < 0)
566 return err; 618 return err;
567 619
568 ds_start_pulse(dev, PULLUP_PULSE_DURATION);
569
570 return !(byte == rbyte); 620 return !(byte == rbyte);
571} 621}
572 622
@@ -602,7 +652,7 @@ static int ds_read_block(struct ds_device *dev, u8 *buf, int len)
602 if (err < 0) 652 if (err < 0)
603 return err; 653 return err;
604 654
605 err = ds_send_control(dev, COMM_BLOCK_IO | COMM_IM | COMM_SPU, len); 655 err = ds_send_control(dev, COMM_BLOCK_IO | COMM_IM, len);
606 if (err) 656 if (err)
607 return err; 657 return err;
608 658
@@ -623,20 +673,19 @@ static int ds_write_block(struct ds_device *dev, u8 *buf, int len)
623 if (err < 0) 673 if (err < 0)
624 return err; 674 return err;
625 675
626 ds_wait_status(dev, &st); 676 err = ds_send_control(dev, COMM_BLOCK_IO | COMM_IM | dev->spu_bit, len);
627
628 err = ds_send_control(dev, COMM_BLOCK_IO | COMM_IM | COMM_SPU, len);
629 if (err) 677 if (err)
630 return err; 678 return err;
631 679
680 if (dev->spu_bit)
681 msleep(dev->spu_sleep);
682
632 ds_wait_status(dev, &st); 683 ds_wait_status(dev, &st);
633 684
634 err = ds_recv_data(dev, buf, len); 685 err = ds_recv_data(dev, buf, len);
635 if (err < 0) 686 if (err < 0)
636 return err; 687 return err;
637 688
638 ds_start_pulse(dev, PULLUP_PULSE_DURATION);
639
640 return !(err == len); 689 return !(err == len);
641} 690}
642 691
@@ -728,6 +777,7 @@ static u8 ds9490r_touch_bit(void *data, u8 bit)
728 return ret; 777 return ret;
729} 778}
730 779
780#if 0
731static void ds9490r_write_bit(void *data, u8 bit) 781static void ds9490r_write_bit(void *data, u8 bit)
732{ 782{
733 struct ds_device *dev = data; 783 struct ds_device *dev = data;
@@ -735,13 +785,6 @@ static void ds9490r_write_bit(void *data, u8 bit)
735 ds_write_bit(dev, bit); 785 ds_write_bit(dev, bit);
736} 786}
737 787
738static void ds9490r_write_byte(void *data, u8 byte)
739{
740 struct ds_device *dev = data;
741
742 ds_write_byte(dev, byte);
743}
744
745static u8 ds9490r_read_bit(void *data) 788static u8 ds9490r_read_bit(void *data)
746{ 789{
747 struct ds_device *dev = data; 790 struct ds_device *dev = data;
@@ -754,6 +797,14 @@ static u8 ds9490r_read_bit(void *data)
754 797
755 return bit & 1; 798 return bit & 1;
756} 799}
800#endif
801
802static void ds9490r_write_byte(void *data, u8 byte)
803{
804 struct ds_device *dev = data;
805
806 ds_write_byte(dev, byte);
807}
757 808
758static u8 ds9490r_read_byte(void *data) 809static u8 ds9490r_read_byte(void *data)
759{ 810{
@@ -790,31 +841,58 @@ static u8 ds9490r_read_block(void *data, u8 *buf, int len)
790static u8 ds9490r_reset(void *data) 841static u8 ds9490r_reset(void *data)
791{ 842{
792 struct ds_device *dev = data; 843 struct ds_device *dev = data;
793 struct ds_status st;
794 int err; 844 int err;
795 845
796 memset(&st, 0, sizeof(st)); 846 err = ds_reset(dev);
797
798 err = ds_reset(dev, &st);
799 if (err) 847 if (err)
800 return 1; 848 return 1;
801 849
802 return 0; 850 return 0;
803} 851}
804 852
853static u8 ds9490r_set_pullup(void *data, int delay)
854{
855 struct ds_device *dev = data;
856
857 if (ds_set_pullup(dev, delay))
858 return 1;
859
860 return 0;
861}
862
805static int ds_w1_init(struct ds_device *dev) 863static int ds_w1_init(struct ds_device *dev)
806{ 864{
807 memset(&dev->master, 0, sizeof(struct w1_bus_master)); 865 memset(&dev->master, 0, sizeof(struct w1_bus_master));
808 866
867 /* Reset the device as it can be in a bad state.
868 * This is necessary because a block write will wait for data
869 * to be placed in the output buffer and block any later
870 * commands which will keep accumulating and the device will
871 * not be idle. Another case is removing the ds2490 module
872 * while a bus search is in progress, somehow a few commands
873 * get through, but the input transfers fail leaving data in
874 * the input buffer. This will cause the next read to fail
875 * see the note in ds_recv_data.
876 */
877 ds_reset_device(dev);
878
809 dev->master.data = dev; 879 dev->master.data = dev;
810 dev->master.touch_bit = &ds9490r_touch_bit; 880 dev->master.touch_bit = &ds9490r_touch_bit;
881 /* read_bit and write_bit in w1_bus_master are expected to set and
882 * sample the line level. For write_bit that means it is expected to
883 * set it to that value and leave it there. ds2490 only supports an
884 * individual time slot at the lowest level. The requirement from
885 * pulling the bus state down to reading the state is 15us, something
886 * that isn't realistic on the USB bus anyway.
811 dev->master.read_bit = &ds9490r_read_bit; 887 dev->master.read_bit = &ds9490r_read_bit;
812 dev->master.write_bit = &ds9490r_write_bit; 888 dev->master.write_bit = &ds9490r_write_bit;
889 */
813 dev->master.read_byte = &ds9490r_read_byte; 890 dev->master.read_byte = &ds9490r_read_byte;
814 dev->master.write_byte = &ds9490r_write_byte; 891 dev->master.write_byte = &ds9490r_write_byte;
815 dev->master.read_block = &ds9490r_read_block; 892 dev->master.read_block = &ds9490r_read_block;
816 dev->master.write_block = &ds9490r_write_block; 893 dev->master.write_block = &ds9490r_write_block;
817 dev->master.reset_bus = &ds9490r_reset; 894 dev->master.reset_bus = &ds9490r_reset;
895 dev->master.set_pullup = &ds9490r_set_pullup;
818 896
819 return w1_add_master_device(&dev->master); 897 return w1_add_master_device(&dev->master);
820} 898}
@@ -838,6 +916,8 @@ static int ds_probe(struct usb_interface *intf,
838 printk(KERN_INFO "Failed to allocate new DS9490R structure.\n"); 916 printk(KERN_INFO "Failed to allocate new DS9490R structure.\n");
839 return -ENOMEM; 917 return -ENOMEM;
840 } 918 }
919 dev->spu_sleep = 0;
920 dev->spu_bit = 0;
841 dev->udev = usb_get_dev(udev); 921 dev->udev = usb_get_dev(udev);
842 if (!dev->udev) { 922 if (!dev->udev) {
843 err = -ENOMEM; 923 err = -ENOMEM;