26 #include <linux/module.h>
31 static int w1_delay_parm = 1;
34 static int w1_disable_irqs = 0;
37 static u8 w1_crc8_table[] = {
38 0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65,
39 157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220,
40 35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98,
41 190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255,
42 70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7,
43 219, 133, 103, 57, 186, 228, 6, 88, 25, 71, 165, 251, 120, 38, 196, 154,
44 101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36,
45 248, 166, 68, 26, 153, 199, 37, 123, 58, 100, 134, 216, 91, 5, 231, 185,
46 140, 210, 48, 110, 237, 179, 81, 15, 78, 16, 242, 172, 47, 113, 147, 205,
47 17, 79, 173, 243, 112, 46, 204, 146, 211, 141, 111, 49, 178, 236, 14, 80,
48 175, 241, 19, 77, 206, 144, 114, 44, 109, 51, 209, 143, 12, 82, 176, 238,
49 50, 108, 142, 208, 83, 13, 239, 177, 240, 174, 76, 18, 145, 207, 45, 115,
50 202, 148, 118, 40, 171, 245, 23, 73, 8, 86, 180, 234, 105, 55, 213, 139,
51 87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22,
52 233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168,
53 116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53
56 static void w1_delay(
unsigned long tm)
58 udelay(tm * w1_delay_parm);
61 static void w1_write_bit(
struct w1_master *
dev,
int bit);
62 static u8 w1_read_bit(
struct w1_master *
dev);
67 static u8 w1_touch_bit(
struct w1_master *
dev,
int bit)
69 if (dev->bus_master->touch_bit)
70 return dev->bus_master->touch_bit(dev->bus_master->data, bit);
72 return w1_read_bit(dev);
83 static void w1_write_bit(
struct w1_master *dev,
int bit)
85 unsigned long flags = 0;
90 dev->bus_master->write_bit(dev->bus_master->data, 0);
92 dev->bus_master->write_bit(dev->bus_master->data, 1);
95 dev->bus_master->write_bit(dev->bus_master->data, 0);
97 dev->bus_master->write_bit(dev->bus_master->data, 1);
111 static void w1_pre_write(
struct w1_master *dev)
113 if (dev->pullup_duration &&
114 dev->enable_pullup && dev->bus_master->set_pullup) {
115 dev->bus_master->set_pullup(dev->bus_master->data,
116 dev->pullup_duration);
127 static void w1_post_write(
struct w1_master *dev)
129 if (dev->pullup_duration) {
130 if (dev->enable_pullup && dev->bus_master->set_pullup)
131 dev->bus_master->set_pullup(dev->bus_master->data, 0);
133 msleep(dev->pullup_duration);
134 dev->pullup_duration = 0;
148 if (dev->bus_master->write_byte) {
150 dev->bus_master->write_byte(dev->bus_master->data, byte);
153 for (i = 0; i < 8; ++
i) {
156 w1_touch_bit(dev, (byte >> i) & 0x1);
167 static u8 w1_read_bit(
struct w1_master *dev)
170 unsigned long flags = 0;
174 dev->bus_master->write_bit(dev->bus_master->data, 0);
176 dev->bus_master->write_bit(dev->bus_master->data, 1);
179 result = dev->bus_master->read_bit(dev->bus_master->data);
201 if (dev->bus_master->triplet)
202 return dev->bus_master->triplet(dev->bus_master->data, bdir);
204 u8 id_bit = w1_touch_bit(dev, 1);
205 u8 comp_bit = w1_touch_bit(dev, 1);
208 if (id_bit && comp_bit)
211 if (!id_bit && !comp_bit) {
213 retval = bdir ? 0x04 : 0;
217 retval = id_bit ? 0x05 : 0x02;
220 if (dev->bus_master->touch_bit)
221 w1_touch_bit(dev, bdir);
223 w1_write_bit(dev, bdir);
239 if (dev->bus_master->read_byte)
240 res = dev->bus_master->read_byte(dev->bus_master->data);
242 for (i = 0; i < 8; ++
i)
243 res |= (w1_touch_bit(dev,1) << i);
260 if (dev->bus_master->write_block) {
262 dev->bus_master->write_block(dev->bus_master->data, buf, len);
265 for (i = 0; i < len; ++
i)
283 for (i = 0; i < len; ++
i) {
285 for (j = 0; j < 8; ++
j) {
288 tmp |= w1_touch_bit(dev, (buf[i] >> j) & 0x1) <<
j;
309 if (dev->bus_master->read_block)
310 ret = dev->bus_master->read_block(dev->bus_master->data, buf, len);
312 for (i = 0; i < len; ++
i)
330 unsigned long flags = 0;
334 if (dev->bus_master->reset_bus)
335 result = dev->bus_master->reset_bus(dev->bus_master->data) & 0x1;
337 dev->bus_master->write_bit(dev->bus_master->data, 0);
346 dev->bus_master->write_bit(dev->bus_master->data, 1);
349 result = dev->bus_master->read_bit(dev->bus_master->data) & 0x1;
369 crc = w1_crc8_table[crc ^ *data++];
378 if (dev->bus_master->search)
379 dev->bus_master->search(dev->bus_master->data, dev,
398 if (sl->master->slave_count == 1)
401 u8 match[9] = {W1_MATCH_ROM, };
404 memcpy(&match[1], &rn, 8);
450 dev->pullup_duration =
delay;