diff options
author | Jean-François Dagenais <dagenaisj@sonatest.com> | 2011-05-26 19:26:02 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-05-26 20:12:38 -0400 |
commit | 26a6afb917a8e3eb603358be1238a69e8a16d0ee (patch) | |
tree | 54632a0485849b0295af922aeeabe19175615edf /drivers/w1 | |
parent | 89610274bd43edc68c66ff7cf58e05debd519a5e (diff) |
w1: complete the 1-wire (w1) ds1wm driver search algorithm
This adds multi-slave support of the w1 bus for the ds1wm Synthesizable
1-Wire Bus Master. Also many fixes and tweaks based on the rev3 of the
datasheet http://datasheets.maxim-ic.com/en/ds/DS1WM.pdf
Signed-off-by: Jean-François Dagenais <dagenaisj@sonatest.com>
Cc: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Cc: Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>
Cc: Matt Reimer <mreimer@vpop.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/w1')
-rw-r--r-- | drivers/w1/masters/Kconfig | 2 | ||||
-rw-r--r-- | drivers/w1/masters/ds1wm.c | 321 |
2 files changed, 220 insertions, 103 deletions
diff --git a/drivers/w1/masters/Kconfig b/drivers/w1/masters/Kconfig index 7c608c5ccf84..00d615d7aa21 100644 --- a/drivers/w1/masters/Kconfig +++ b/drivers/w1/masters/Kconfig | |||
@@ -42,7 +42,7 @@ config W1_MASTER_MXC | |||
42 | 42 | ||
43 | config W1_MASTER_DS1WM | 43 | config W1_MASTER_DS1WM |
44 | tristate "Maxim DS1WM 1-wire busmaster" | 44 | tristate "Maxim DS1WM 1-wire busmaster" |
45 | depends on W1 && ARM && HAVE_CLK | 45 | depends on W1 |
46 | help | 46 | help |
47 | Say Y here to enable the DS1WM 1-wire driver, such as that | 47 | Say Y here to enable the DS1WM 1-wire driver, such as that |
48 | in HP iPAQ devices like h5xxx, h2200, and ASIC3-based like | 48 | in HP iPAQ devices like h5xxx, h2200, and ASIC3-based like |
diff --git a/drivers/w1/masters/ds1wm.c b/drivers/w1/masters/ds1wm.c index 0855d6cce3c1..ad57593d224a 100644 --- a/drivers/w1/masters/ds1wm.c +++ b/drivers/w1/masters/ds1wm.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #define DS1WM_INT 0x02 /* R/W interrupt status */ | 33 | #define DS1WM_INT 0x02 /* R/W interrupt status */ |
34 | #define DS1WM_INT_EN 0x03 /* R/W interrupt enable */ | 34 | #define DS1WM_INT_EN 0x03 /* R/W interrupt enable */ |
35 | #define DS1WM_CLKDIV 0x04 /* R/W 5 bits of divisor and pre-scale */ | 35 | #define DS1WM_CLKDIV 0x04 /* R/W 5 bits of divisor and pre-scale */ |
36 | #define DS1WM_CNTRL 0x05 /* R/W master control register (not used yet) */ | ||
36 | 37 | ||
37 | #define DS1WM_CMD_1W_RESET (1 << 0) /* force reset on 1-wire bus */ | 38 | #define DS1WM_CMD_1W_RESET (1 << 0) /* force reset on 1-wire bus */ |
38 | #define DS1WM_CMD_SRA (1 << 1) /* enable Search ROM accelerator mode */ | 39 | #define DS1WM_CMD_SRA (1 << 1) /* enable Search ROM accelerator mode */ |
@@ -56,6 +57,7 @@ | |||
56 | #define DS1WM_INTEN_ERSRF (1 << 5) /* enable rx shift register full int */ | 57 | #define DS1WM_INTEN_ERSRF (1 << 5) /* enable rx shift register full int */ |
57 | #define DS1WM_INTEN_DQO (1 << 6) /* enable direct bus driving ops */ | 58 | #define DS1WM_INTEN_DQO (1 << 6) /* enable direct bus driving ops */ |
58 | 59 | ||
60 | #define DS1WM_INTEN_NOT_IAS (~DS1WM_INTEN_IAS) /* all but INTR active state */ | ||
59 | 61 | ||
60 | #define DS1WM_TIMEOUT (HZ * 5) | 62 | #define DS1WM_TIMEOUT (HZ * 5) |
61 | 63 | ||
@@ -63,41 +65,50 @@ static struct { | |||
63 | unsigned long freq; | 65 | unsigned long freq; |
64 | unsigned long divisor; | 66 | unsigned long divisor; |
65 | } freq[] = { | 67 | } freq[] = { |
66 | { 4000000, 0x8 }, | 68 | { 1000000, 0x80 }, |
67 | { 5000000, 0x2 }, | 69 | { 2000000, 0x84 }, |
68 | { 6000000, 0x5 }, | 70 | { 3000000, 0x81 }, |
69 | { 7000000, 0x3 }, | 71 | { 4000000, 0x88 }, |
70 | { 8000000, 0xc }, | 72 | { 5000000, 0x82 }, |
71 | { 10000000, 0x6 }, | 73 | { 6000000, 0x85 }, |
72 | { 12000000, 0x9 }, | 74 | { 7000000, 0x83 }, |
73 | { 14000000, 0x7 }, | 75 | { 8000000, 0x8c }, |
74 | { 16000000, 0x10 }, | 76 | { 10000000, 0x86 }, |
75 | { 20000000, 0xa }, | 77 | { 12000000, 0x89 }, |
76 | { 24000000, 0xd }, | 78 | { 14000000, 0x87 }, |
77 | { 28000000, 0xb }, | 79 | { 16000000, 0x90 }, |
78 | { 32000000, 0x14 }, | 80 | { 20000000, 0x8a }, |
79 | { 40000000, 0xe }, | 81 | { 24000000, 0x8d }, |
80 | { 48000000, 0x11 }, | 82 | { 28000000, 0x8b }, |
81 | { 56000000, 0xf }, | 83 | { 32000000, 0x94 }, |
82 | { 64000000, 0x18 }, | 84 | { 40000000, 0x8e }, |
83 | { 80000000, 0x12 }, | 85 | { 48000000, 0x91 }, |
84 | { 96000000, 0x15 }, | 86 | { 56000000, 0x8f }, |
85 | { 112000000, 0x13 }, | 87 | { 64000000, 0x98 }, |
86 | { 128000000, 0x1c }, | 88 | { 80000000, 0x92 }, |
89 | { 96000000, 0x95 }, | ||
90 | { 112000000, 0x93 }, | ||
91 | { 128000000, 0x9c }, | ||
92 | /* you can continue this table, consult the OPERATION - CLOCK DIVISOR | ||
93 | section of the ds1wm spec sheet. */ | ||
87 | }; | 94 | }; |
88 | 95 | ||
89 | struct ds1wm_data { | 96 | struct ds1wm_data { |
90 | void __iomem *map; | 97 | void __iomem *map; |
91 | int bus_shift; /* # of shifts to calc register offsets */ | 98 | int bus_shift; /* # of shifts to calc register offsets */ |
92 | struct platform_device *pdev; | 99 | struct platform_device *pdev; |
93 | const struct mfd_cell *cell; | 100 | const struct mfd_cell *cell; |
94 | int irq; | 101 | int irq; |
95 | int active_high; | 102 | int slave_present; |
96 | int slave_present; | 103 | void *reset_complete; |
97 | void *reset_complete; | 104 | void *read_complete; |
98 | void *read_complete; | 105 | void *write_complete; |
99 | void *write_complete; | 106 | int read_error; |
100 | u8 read_byte; /* last byte received */ | 107 | /* last byte received */ |
108 | u8 read_byte; | ||
109 | /* byte to write that makes all intr disabled, */ | ||
110 | /* considering active_state (IAS) (optimization) */ | ||
111 | u8 int_en_reg_none; | ||
101 | }; | 112 | }; |
102 | 113 | ||
103 | static inline void ds1wm_write_register(struct ds1wm_data *ds1wm_data, u32 reg, | 114 | static inline void ds1wm_write_register(struct ds1wm_data *ds1wm_data, u32 reg, |
@@ -115,23 +126,39 @@ static inline u8 ds1wm_read_register(struct ds1wm_data *ds1wm_data, u32 reg) | |||
115 | static irqreturn_t ds1wm_isr(int isr, void *data) | 126 | static irqreturn_t ds1wm_isr(int isr, void *data) |
116 | { | 127 | { |
117 | struct ds1wm_data *ds1wm_data = data; | 128 | struct ds1wm_data *ds1wm_data = data; |
118 | u8 intr = ds1wm_read_register(ds1wm_data, DS1WM_INT); | 129 | u8 intr; |
130 | u8 inten = ds1wm_read_register(ds1wm_data, DS1WM_INT_EN); | ||
131 | /* if no bits are set in int enable register (except the IAS) | ||
132 | than go no further, reading the regs below has side effects */ | ||
133 | if (!(inten & DS1WM_INTEN_NOT_IAS)) | ||
134 | return IRQ_NONE; | ||
119 | 135 | ||
120 | ds1wm_data->slave_present = (intr & DS1WM_INT_PDR) ? 0 : 1; | 136 | ds1wm_write_register(ds1wm_data, |
137 | DS1WM_INT_EN, ds1wm_data->int_en_reg_none); | ||
121 | 138 | ||
122 | if ((intr & DS1WM_INT_PD) && ds1wm_data->reset_complete) | 139 | /* this read action clears the INTR and certain flags in ds1wm */ |
123 | complete(ds1wm_data->reset_complete); | 140 | intr = ds1wm_read_register(ds1wm_data, DS1WM_INT); |
124 | 141 | ||
125 | if ((intr & DS1WM_INT_TSRE) && ds1wm_data->write_complete) | 142 | ds1wm_data->slave_present = (intr & DS1WM_INT_PDR) ? 0 : 1; |
126 | complete(ds1wm_data->write_complete); | ||
127 | 143 | ||
144 | if ((intr & DS1WM_INT_TSRE) && ds1wm_data->write_complete) { | ||
145 | inten &= ~DS1WM_INTEN_ETMT; | ||
146 | complete(ds1wm_data->write_complete); | ||
147 | } | ||
128 | if (intr & DS1WM_INT_RBF) { | 148 | if (intr & DS1WM_INT_RBF) { |
149 | /* this read clears the RBF flag */ | ||
129 | ds1wm_data->read_byte = ds1wm_read_register(ds1wm_data, | 150 | ds1wm_data->read_byte = ds1wm_read_register(ds1wm_data, |
130 | DS1WM_DATA); | 151 | DS1WM_DATA); |
152 | inten &= ~DS1WM_INTEN_ERBF; | ||
131 | if (ds1wm_data->read_complete) | 153 | if (ds1wm_data->read_complete) |
132 | complete(ds1wm_data->read_complete); | 154 | complete(ds1wm_data->read_complete); |
133 | } | 155 | } |
156 | if ((intr & DS1WM_INT_PD) && ds1wm_data->reset_complete) { | ||
157 | inten &= ~DS1WM_INTEN_EPD; | ||
158 | complete(ds1wm_data->reset_complete); | ||
159 | } | ||
134 | 160 | ||
161 | ds1wm_write_register(ds1wm_data, DS1WM_INT_EN, inten); | ||
135 | return IRQ_HANDLED; | 162 | return IRQ_HANDLED; |
136 | } | 163 | } |
137 | 164 | ||
@@ -142,33 +169,19 @@ static int ds1wm_reset(struct ds1wm_data *ds1wm_data) | |||
142 | 169 | ||
143 | ds1wm_data->reset_complete = &reset_done; | 170 | ds1wm_data->reset_complete = &reset_done; |
144 | 171 | ||
172 | /* enable Presence detect only */ | ||
145 | ds1wm_write_register(ds1wm_data, DS1WM_INT_EN, DS1WM_INTEN_EPD | | 173 | ds1wm_write_register(ds1wm_data, DS1WM_INT_EN, DS1WM_INTEN_EPD | |
146 | (ds1wm_data->active_high ? DS1WM_INTEN_IAS : 0)); | 174 | ds1wm_data->int_en_reg_none); |
147 | 175 | ||
148 | ds1wm_write_register(ds1wm_data, DS1WM_CMD, DS1WM_CMD_1W_RESET); | 176 | ds1wm_write_register(ds1wm_data, DS1WM_CMD, DS1WM_CMD_1W_RESET); |
149 | 177 | ||
150 | timeleft = wait_for_completion_timeout(&reset_done, DS1WM_TIMEOUT); | 178 | timeleft = wait_for_completion_timeout(&reset_done, DS1WM_TIMEOUT); |
151 | ds1wm_data->reset_complete = NULL; | 179 | ds1wm_data->reset_complete = NULL; |
152 | if (!timeleft) { | 180 | if (!timeleft) { |
153 | dev_err(&ds1wm_data->pdev->dev, "reset failed\n"); | 181 | dev_err(&ds1wm_data->pdev->dev, "reset failed, timed out\n"); |
154 | return 1; | 182 | return 1; |
155 | } | 183 | } |
156 | 184 | ||
157 | /* Wait for the end of the reset. According to the specs, the time | ||
158 | * from when the interrupt is asserted to the end of the reset is: | ||
159 | * tRSTH - tPDH - tPDL - tPDI | ||
160 | * 625 us - 60 us - 240 us - 100 ns = 324.9 us | ||
161 | * | ||
162 | * We'll wait a bit longer just to be sure. | ||
163 | * Was udelay(500), but if it is going to busywait the cpu that long, | ||
164 | * might as well come back later. | ||
165 | */ | ||
166 | msleep(1); | ||
167 | |||
168 | ds1wm_write_register(ds1wm_data, DS1WM_INT_EN, | ||
169 | DS1WM_INTEN_ERBF | DS1WM_INTEN_ETMT | DS1WM_INTEN_EPD | | ||
170 | (ds1wm_data->active_high ? DS1WM_INTEN_IAS : 0)); | ||
171 | |||
172 | if (!ds1wm_data->slave_present) { | 185 | if (!ds1wm_data->slave_present) { |
173 | dev_dbg(&ds1wm_data->pdev->dev, "reset: no devices found\n"); | 186 | dev_dbg(&ds1wm_data->pdev->dev, "reset: no devices found\n"); |
174 | return 1; | 187 | return 1; |
@@ -179,26 +192,47 @@ static int ds1wm_reset(struct ds1wm_data *ds1wm_data) | |||
179 | 192 | ||
180 | static int ds1wm_write(struct ds1wm_data *ds1wm_data, u8 data) | 193 | static int ds1wm_write(struct ds1wm_data *ds1wm_data, u8 data) |
181 | { | 194 | { |
195 | unsigned long timeleft; | ||
182 | DECLARE_COMPLETION_ONSTACK(write_done); | 196 | DECLARE_COMPLETION_ONSTACK(write_done); |
183 | ds1wm_data->write_complete = &write_done; | 197 | ds1wm_data->write_complete = &write_done; |
184 | 198 | ||
199 | ds1wm_write_register(ds1wm_data, DS1WM_INT_EN, | ||
200 | ds1wm_data->int_en_reg_none | DS1WM_INTEN_ETMT); | ||
201 | |||
185 | ds1wm_write_register(ds1wm_data, DS1WM_DATA, data); | 202 | ds1wm_write_register(ds1wm_data, DS1WM_DATA, data); |
186 | 203 | ||
187 | wait_for_completion_timeout(&write_done, DS1WM_TIMEOUT); | 204 | timeleft = wait_for_completion_timeout(&write_done, DS1WM_TIMEOUT); |
205 | |||
188 | ds1wm_data->write_complete = NULL; | 206 | ds1wm_data->write_complete = NULL; |
207 | if (!timeleft) { | ||
208 | dev_err(&ds1wm_data->pdev->dev, "write failed, timed out\n"); | ||
209 | return -ETIMEDOUT; | ||
210 | } | ||
189 | 211 | ||
190 | return 0; | 212 | return 0; |
191 | } | 213 | } |
192 | 214 | ||
193 | static int ds1wm_read(struct ds1wm_data *ds1wm_data, unsigned char write_data) | 215 | static u8 ds1wm_read(struct ds1wm_data *ds1wm_data, unsigned char write_data) |
194 | { | 216 | { |
217 | unsigned long timeleft; | ||
218 | u8 intEnable = DS1WM_INTEN_ERBF | ds1wm_data->int_en_reg_none; | ||
195 | DECLARE_COMPLETION_ONSTACK(read_done); | 219 | DECLARE_COMPLETION_ONSTACK(read_done); |
220 | |||
221 | ds1wm_read_register(ds1wm_data, DS1WM_DATA); | ||
222 | |||
196 | ds1wm_data->read_complete = &read_done; | 223 | ds1wm_data->read_complete = &read_done; |
224 | ds1wm_write_register(ds1wm_data, DS1WM_INT_EN, intEnable); | ||
197 | 225 | ||
198 | ds1wm_write(ds1wm_data, write_data); | 226 | ds1wm_write_register(ds1wm_data, DS1WM_DATA, write_data); |
199 | wait_for_completion_timeout(&read_done, DS1WM_TIMEOUT); | 227 | timeleft = wait_for_completion_timeout(&read_done, DS1WM_TIMEOUT); |
200 | ds1wm_data->read_complete = NULL; | ||
201 | 228 | ||
229 | ds1wm_data->read_complete = NULL; | ||
230 | if (!timeleft) { | ||
231 | dev_err(&ds1wm_data->pdev->dev, "read failed, timed out\n"); | ||
232 | ds1wm_data->read_error = -ETIMEDOUT; | ||
233 | return 0xFF; | ||
234 | } | ||
235 | ds1wm_data->read_error = 0; | ||
202 | return ds1wm_data->read_byte; | 236 | return ds1wm_data->read_byte; |
203 | } | 237 | } |
204 | 238 | ||
@@ -206,8 +240,8 @@ static int ds1wm_find_divisor(int gclk) | |||
206 | { | 240 | { |
207 | int i; | 241 | int i; |
208 | 242 | ||
209 | for (i = 0; i < ARRAY_SIZE(freq); i++) | 243 | for (i = ARRAY_SIZE(freq)-1; i >= 0; --i) |
210 | if (gclk <= freq[i].freq) | 244 | if (gclk >= freq[i].freq) |
211 | return freq[i].divisor; | 245 | return freq[i].divisor; |
212 | 246 | ||
213 | return 0; | 247 | return 0; |
@@ -222,6 +256,8 @@ static void ds1wm_up(struct ds1wm_data *ds1wm_data) | |||
222 | ds1wm_data->cell->enable(ds1wm_data->pdev); | 256 | ds1wm_data->cell->enable(ds1wm_data->pdev); |
223 | 257 | ||
224 | divisor = ds1wm_find_divisor(plat->clock_rate); | 258 | divisor = ds1wm_find_divisor(plat->clock_rate); |
259 | dev_dbg(&ds1wm_data->pdev->dev, | ||
260 | "found divisor 0x%x for clock %d\n", divisor, plat->clock_rate); | ||
225 | if (divisor == 0) { | 261 | if (divisor == 0) { |
226 | dev_err(&ds1wm_data->pdev->dev, | 262 | dev_err(&ds1wm_data->pdev->dev, |
227 | "no suitable divisor for %dHz clock\n", | 263 | "no suitable divisor for %dHz clock\n", |
@@ -242,7 +278,7 @@ static void ds1wm_down(struct ds1wm_data *ds1wm_data) | |||
242 | 278 | ||
243 | /* Disable interrupts. */ | 279 | /* Disable interrupts. */ |
244 | ds1wm_write_register(ds1wm_data, DS1WM_INT_EN, | 280 | ds1wm_write_register(ds1wm_data, DS1WM_INT_EN, |
245 | ds1wm_data->active_high ? DS1WM_INTEN_IAS : 0); | 281 | ds1wm_data->int_en_reg_none); |
246 | 282 | ||
247 | if (ds1wm_data->cell->disable) | 283 | if (ds1wm_data->cell->disable) |
248 | ds1wm_data->cell->disable(ds1wm_data->pdev); | 284 | ds1wm_data->cell->disable(ds1wm_data->pdev); |
@@ -279,41 +315,121 @@ static void ds1wm_search(void *data, struct w1_master *master_dev, | |||
279 | { | 315 | { |
280 | struct ds1wm_data *ds1wm_data = data; | 316 | struct ds1wm_data *ds1wm_data = data; |
281 | int i; | 317 | int i; |
282 | unsigned long long rom_id; | 318 | int ms_discrep_bit = -1; |
283 | 319 | u64 r = 0; /* holds the progress of the search */ | |
284 | /* XXX We need to iterate for multiple devices per the DS1WM docs. | 320 | u64 r_prime, d; |
285 | * See http://www.maxim-ic.com/appnotes.cfm/appnote_number/120. */ | 321 | unsigned slaves_found = 0; |
286 | if (ds1wm_reset(ds1wm_data)) | 322 | unsigned int pass = 0; |
287 | return; | 323 | |
288 | 324 | dev_dbg(&ds1wm_data->pdev->dev, "search begin\n"); | |
289 | ds1wm_write(ds1wm_data, search_type); | 325 | while (true) { |
290 | ds1wm_write_register(ds1wm_data, DS1WM_CMD, DS1WM_CMD_SRA); | 326 | ++pass; |
291 | 327 | if (pass > 100) { | |
292 | for (rom_id = 0, i = 0; i < 16; i++) { | 328 | dev_dbg(&ds1wm_data->pdev->dev, |
293 | 329 | "too many attempts (100), search aborted\n"); | |
294 | unsigned char resp, r, d; | 330 | return; |
295 | 331 | } | |
296 | resp = ds1wm_read(ds1wm_data, 0x00); | 332 | |
297 | 333 | if (ds1wm_reset(ds1wm_data)) { | |
298 | r = ((resp & 0x02) >> 1) | | 334 | dev_dbg(&ds1wm_data->pdev->dev, |
299 | ((resp & 0x08) >> 2) | | 335 | "pass: %d reset error (or no slaves)\n", pass); |
300 | ((resp & 0x20) >> 3) | | 336 | break; |
301 | ((resp & 0x80) >> 4); | 337 | } |
302 | 338 | ||
303 | d = ((resp & 0x01) >> 0) | | 339 | dev_dbg(&ds1wm_data->pdev->dev, |
304 | ((resp & 0x04) >> 1) | | 340 | "pass: %d r : %0#18llx writing SEARCH_ROM\n", pass, r); |
305 | ((resp & 0x10) >> 2) | | 341 | ds1wm_write(ds1wm_data, search_type); |
306 | ((resp & 0x40) >> 3); | 342 | dev_dbg(&ds1wm_data->pdev->dev, |
307 | 343 | "pass: %d entering ASM\n", pass); | |
308 | rom_id |= (unsigned long long) r << (i * 4); | 344 | ds1wm_write_register(ds1wm_data, DS1WM_CMD, DS1WM_CMD_SRA); |
309 | 345 | dev_dbg(&ds1wm_data->pdev->dev, | |
310 | } | 346 | "pass: %d begining nibble loop\n", pass); |
311 | dev_dbg(&ds1wm_data->pdev->dev, "found 0x%08llX\n", rom_id); | 347 | |
312 | 348 | r_prime = 0; | |
313 | ds1wm_write_register(ds1wm_data, DS1WM_CMD, ~DS1WM_CMD_SRA); | 349 | d = 0; |
314 | ds1wm_reset(ds1wm_data); | 350 | /* we work one nibble at a time */ |
315 | 351 | /* each nibble is interleaved to form a byte */ | |
316 | slave_found(master_dev, rom_id); | 352 | for (i = 0; i < 16; i++) { |
353 | |||
354 | unsigned char resp, _r, _r_prime, _d; | ||
355 | |||
356 | _r = (r >> (4*i)) & 0xf; | ||
357 | _r = ((_r & 0x1) << 1) | | ||
358 | ((_r & 0x2) << 2) | | ||
359 | ((_r & 0x4) << 3) | | ||
360 | ((_r & 0x8) << 4); | ||
361 | |||
362 | /* writes _r, then reads back: */ | ||
363 | resp = ds1wm_read(ds1wm_data, _r); | ||
364 | |||
365 | if (ds1wm_data->read_error) { | ||
366 | dev_err(&ds1wm_data->pdev->dev, | ||
367 | "pass: %d nibble: %d read error\n", pass, i); | ||
368 | break; | ||
369 | } | ||
370 | |||
371 | _r_prime = ((resp & 0x02) >> 1) | | ||
372 | ((resp & 0x08) >> 2) | | ||
373 | ((resp & 0x20) >> 3) | | ||
374 | ((resp & 0x80) >> 4); | ||
375 | |||
376 | _d = ((resp & 0x01) >> 0) | | ||
377 | ((resp & 0x04) >> 1) | | ||
378 | ((resp & 0x10) >> 2) | | ||
379 | ((resp & 0x40) >> 3); | ||
380 | |||
381 | r_prime |= (unsigned long long) _r_prime << (i * 4); | ||
382 | d |= (unsigned long long) _d << (i * 4); | ||
383 | |||
384 | } | ||
385 | if (ds1wm_data->read_error) { | ||
386 | dev_err(&ds1wm_data->pdev->dev, | ||
387 | "pass: %d read error, retrying\n", pass); | ||
388 | break; | ||
389 | } | ||
390 | dev_dbg(&ds1wm_data->pdev->dev, | ||
391 | "pass: %d r\': %0#18llx d:%0#18llx\n", | ||
392 | pass, r_prime, d); | ||
393 | dev_dbg(&ds1wm_data->pdev->dev, | ||
394 | "pass: %d nibble loop complete, exiting ASM\n", pass); | ||
395 | ds1wm_write_register(ds1wm_data, DS1WM_CMD, ~DS1WM_CMD_SRA); | ||
396 | dev_dbg(&ds1wm_data->pdev->dev, | ||
397 | "pass: %d resetting bus\n", pass); | ||
398 | ds1wm_reset(ds1wm_data); | ||
399 | if ((r_prime & ((u64)1 << 63)) && (d & ((u64)1 << 63))) { | ||
400 | dev_err(&ds1wm_data->pdev->dev, | ||
401 | "pass: %d bus error, retrying\n", pass); | ||
402 | continue; /* start over */ | ||
403 | } | ||
404 | |||
405 | |||
406 | dev_dbg(&ds1wm_data->pdev->dev, | ||
407 | "pass: %d found %0#18llx\n", pass, r_prime); | ||
408 | slave_found(master_dev, r_prime); | ||
409 | ++slaves_found; | ||
410 | dev_dbg(&ds1wm_data->pdev->dev, | ||
411 | "pass: %d complete, preparing next pass\n", pass); | ||
412 | |||
413 | /* any discrepency found which we already choose the | ||
414 | '1' branch is now is now irrelevant we reveal the | ||
415 | next branch with this: */ | ||
416 | d &= ~r; | ||
417 | /* find last bit set, i.e. the most signif. bit set */ | ||
418 | ms_discrep_bit = fls64(d) - 1; | ||
419 | dev_dbg(&ds1wm_data->pdev->dev, | ||
420 | "pass: %d new d:%0#18llx MS discrep bit:%d\n", | ||
421 | pass, d, ms_discrep_bit); | ||
422 | |||
423 | /* prev_ms_discrep_bit = ms_discrep_bit; | ||
424 | prepare for next ROM search: */ | ||
425 | if (ms_discrep_bit == -1) | ||
426 | break; | ||
427 | |||
428 | r = (r & ~(~0ull << (ms_discrep_bit))) | 1 << ms_discrep_bit; | ||
429 | } /* end while true */ | ||
430 | dev_dbg(&ds1wm_data->pdev->dev, | ||
431 | "pass: %d total: %d search done ms d bit pos: %d\n", pass, | ||
432 | slaves_found, ms_discrep_bit); | ||
317 | } | 433 | } |
318 | 434 | ||
319 | /* --------------------------------------------------------------------- */ | 435 | /* --------------------------------------------------------------------- */ |
@@ -373,15 +489,15 @@ static int ds1wm_probe(struct platform_device *pdev) | |||
373 | goto err1; | 489 | goto err1; |
374 | } | 490 | } |
375 | ds1wm_data->irq = res->start; | 491 | ds1wm_data->irq = res->start; |
376 | ds1wm_data->active_high = plat->active_high; | 492 | ds1wm_data->int_en_reg_none = (plat->active_high ? DS1WM_INTEN_IAS : 0); |
377 | 493 | ||
378 | if (res->flags & IORESOURCE_IRQ_HIGHEDGE) | 494 | if (res->flags & IORESOURCE_IRQ_HIGHEDGE) |
379 | irq_set_irq_type(ds1wm_data->irq, IRQ_TYPE_EDGE_RISING); | 495 | irq_set_irq_type(ds1wm_data->irq, IRQ_TYPE_EDGE_RISING); |
380 | if (res->flags & IORESOURCE_IRQ_LOWEDGE) | 496 | if (res->flags & IORESOURCE_IRQ_LOWEDGE) |
381 | irq_set_irq_type(ds1wm_data->irq, IRQ_TYPE_EDGE_FALLING); | 497 | irq_set_irq_type(ds1wm_data->irq, IRQ_TYPE_EDGE_FALLING); |
382 | 498 | ||
383 | ret = request_irq(ds1wm_data->irq, ds1wm_isr, IRQF_DISABLED, | 499 | ret = request_irq(ds1wm_data->irq, ds1wm_isr, |
384 | "ds1wm", ds1wm_data); | 500 | IRQF_DISABLED | IRQF_SHARED, "ds1wm", ds1wm_data); |
385 | if (ret) | 501 | if (ret) |
386 | goto err1; | 502 | goto err1; |
387 | 503 | ||
@@ -468,5 +584,6 @@ module_exit(ds1wm_exit); | |||
468 | 584 | ||
469 | MODULE_LICENSE("GPL"); | 585 | MODULE_LICENSE("GPL"); |
470 | MODULE_AUTHOR("Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>, " | 586 | MODULE_AUTHOR("Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>, " |
471 | "Matt Reimer <mreimer@vpop.net>"); | 587 | "Matt Reimer <mreimer@vpop.net>," |
588 | "Jean-Francois Dagenais <dagenaisj@sonatest.com>"); | ||
472 | MODULE_DESCRIPTION("DS1WM w1 busmaster driver"); | 589 | MODULE_DESCRIPTION("DS1WM w1 busmaster driver"); |