X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=drivers%2Fw1%2Fw1_io.c;h=e2a043354ddfa3040fdc10c17350efb4c8fc653d;hb=ea7d8f65c865ebfa1d7cd67c360a87333ff013c1;hp=2173336b60a72898f9fe016351a0d0aee95f0ccf;hpb=be57ce267fd558c52d2389530c15618681b7cfa7;p=linux-2.6 diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c index 2173336b60..e2a043354d 100644 --- a/drivers/w1/w1_io.c +++ b/drivers/w1/w1_io.c @@ -129,6 +129,47 @@ static u8 w1_read_bit(struct w1_master *dev) return result & 0x1; } +/** + * Does a triplet - used for searching ROM addresses. + * Return bits: + * bit 0 = id_bit + * bit 1 = comp_bit + * bit 2 = dir_taken + * If both bits 0 & 1 are set, the search should be restarted. + * + * @param dev the master device + * @param bdir the bit to write if both id_bit and comp_bit are 0 + * @return bit fields - see above + */ +u8 w1_triplet(struct w1_master *dev, int bdir) +{ + if ( dev->bus_master->triplet ) + return(dev->bus_master->triplet(dev->bus_master->data, bdir)); + else { + u8 id_bit = w1_touch_bit(dev, 1); + u8 comp_bit = w1_touch_bit(dev, 1); + u8 retval; + + if ( id_bit && comp_bit ) + return(0x03); /* error */ + + if ( !id_bit && !comp_bit ) { + /* Both bits are valid, take the direction given */ + retval = bdir ? 0x04 : 0; + } else { + /* Only one bit is valid, take that direction */ + bdir = id_bit; + retval = id_bit ? 0x05 : 0x02; + } + + if ( dev->bus_master->touch_bit ) + w1_touch_bit(dev, bdir); + else + w1_write_bit(dev, bdir); + return(retval); + } +} + /** * Reads 8 bits. * @@ -233,7 +274,30 @@ void w1_search_devices(struct w1_master *dev, w1_slave_found_callback cb) if (dev->bus_master->search) dev->bus_master->search(dev->bus_master->data, cb); else - w1_search(dev); + w1_search(dev, cb); +} + +/** + * Resets the bus and then selects the slave by sending either a skip rom + * or a rom match. + * The w1 master lock must be held. + * + * @param sl the slave to select + * @return 0=success, anything else=error + */ +int w1_reset_select_slave(struct w1_slave *sl) +{ + if (w1_reset_bus(sl->master)) + return -1; + + if (sl->master->slave_count == 1) + w1_write_8(sl->master, W1_SKIP_ROM); + else { + u8 match[9] = {W1_MATCH_ROM, }; + memcpy(&match[1], (u8 *)&sl->reg_num, 8); + w1_write_block(sl->master, match, 9); + } + return 0; } EXPORT_SYMBOL(w1_touch_bit); @@ -245,3 +309,4 @@ EXPORT_SYMBOL(w1_delay); EXPORT_SYMBOL(w1_read_block); EXPORT_SYMBOL(w1_write_block); EXPORT_SYMBOL(w1_search_devices); +EXPORT_SYMBOL(w1_reset_select_slave);