Line data Source code
1 : /* $OpenBSD: i2c_scan.c,v 1.145 2015/05/29 00:37:10 uebayasi Exp $ */
2 :
3 : /*
4 : * Copyright (c) 2005 Theo de Raadt <deraadt@openbsd.org>
5 : *
6 : * Permission to use, copy, modify, and distribute this software for any
7 : * purpose with or without fee is hereby granted, provided that the above
8 : * copyright notice and this permission notice appear in all copies.
9 : *
10 : * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 : * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 : * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 : * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 : * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 : * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 : * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 : */
18 :
19 : /*
20 : * I2C bus scanning. We apologize in advance for the massive overuse of 0x.
21 : */
22 :
23 : #include "ipmi.h"
24 :
25 : #include <sys/param.h>
26 : #include <sys/systm.h>
27 : #include <sys/device.h>
28 :
29 : #define _I2C_PRIVATE
30 : #include <dev/i2c/i2cvar.h>
31 :
32 : #undef I2C_DEBUG
33 : #define I2C_VERBOSE
34 :
35 : #define MAX_IGNORE 8
36 : u_int8_t ignore_addrs[MAX_IGNORE];
37 :
38 : struct iicprobelist {
39 : u_int8_t start, end;
40 : };
41 :
42 : /*
43 : * Addresses at which to probe for sensors. Skip address 0x4f, since
44 : * probing it seems to crash at least one Sony VAIO laptop. Only a
45 : * few chips can actually sit at that address, and vendors seem to
46 : * place those at other addresses, so this isn't a big loss.
47 : */
48 : struct iicprobelist probe_addrs_sensor[] = {
49 : { 0x18, 0x1f },
50 : { 0x20, 0x2f },
51 : { 0x48, 0x4e },
52 : { 0, 0 }
53 : };
54 :
55 : /*
56 : * Addresses at which to probe for eeprom devices.
57 : */
58 : struct iicprobelist probe_addrs_eeprom[] = {
59 : { 0x50, 0x57 },
60 : { 0, 0 }
61 : };
62 :
63 : char *iic_probe_sensor(struct device *, u_int8_t);
64 : char *iic_probe_eeprom(struct device *, u_int8_t);
65 :
66 : #define PFLAG_SENSOR 1
67 : static struct {
68 : struct iicprobelist *pl;
69 : char *(*probe)(struct device *, u_int8_t);
70 : int flags;
71 : } probes[] = {
72 : { probe_addrs_sensor, iic_probe_sensor, PFLAG_SENSOR },
73 : { probe_addrs_eeprom, iic_probe_eeprom, 0 },
74 : { NULL, NULL }
75 : };
76 :
77 : /*
78 : * Some Maxim 1617 clones MAY NOT even read cmd 0xfc! When it is
79 : * read, they will power-on-reset. Their default condition
80 : * (control register bit 0x80) therefore will be that they assert
81 : * /ALERT for the 5 potential errors that may occur. One of those
82 : * errors is that the external temperature diode is missing. This
83 : * is unfortunately a common choice of system designers, except
84 : * suddenly now we get a /ALERT, which may on some chipsets cause
85 : * us to receive an entirely unexpected SMI .. and then an NMI.
86 : *
87 : * As we probe each device, if we hit something which looks suspiciously
88 : * like it may potentially be a 1617 or clone, we immediately set this
89 : * variable to avoid reading that register offset.
90 : */
91 : int skip_fc;
92 :
93 : static i2c_tag_t probe_ic;
94 : static u_int8_t probe_addr;
95 : static u_int8_t probe_val[256];
96 :
97 : void iicprobeinit(struct i2cbus_attach_args *, u_int8_t);
98 : u_int8_t iicprobenc(u_int8_t);
99 : u_int8_t iicprobe(u_int8_t);
100 : u_int16_t iicprobew(u_int8_t);
101 : char *lm75probe(void);
102 : char *adm1032cloneprobe(u_int8_t);
103 : void iic_dump(struct device *, u_int8_t, char *);
104 :
105 : void
106 0 : iicprobeinit(struct i2cbus_attach_args *iba, u_int8_t addr)
107 : {
108 0 : probe_ic = iba->iba_tag;
109 0 : probe_addr = addr;
110 0 : memset(probe_val, 0xff, sizeof probe_val);
111 0 : }
112 :
113 : u_int8_t
114 0 : iicprobenc(u_int8_t cmd)
115 : {
116 0 : u_int8_t data;
117 :
118 : /*
119 : * If we think we are talking to an evil Maxim 1617 or clone,
120 : * avoid accessing this register because it is death.
121 : */
122 0 : if (skip_fc && cmd == 0xfc)
123 0 : return (0xff);
124 0 : iic_acquire_bus(probe_ic, 0);
125 0 : if (iic_exec(probe_ic, I2C_OP_READ_WITH_STOP,
126 0 : probe_addr, &cmd, sizeof cmd, &data, sizeof data, 0) != 0)
127 0 : data = 0xff;
128 0 : iic_release_bus(probe_ic, 0);
129 0 : return (data);
130 0 : }
131 :
132 : u_int16_t
133 0 : iicprobew(u_int8_t cmd)
134 : {
135 0 : u_int16_t data;
136 :
137 : /*
138 : * If we think we are talking to an evil Maxim 1617 or clone,
139 : * avoid accessing this register because it is death.
140 : */
141 0 : if (skip_fc && cmd == 0xfc)
142 0 : return (0xffff);
143 0 : iic_acquire_bus(probe_ic, 0);
144 0 : if (iic_exec(probe_ic, I2C_OP_READ_WITH_STOP,
145 0 : probe_addr, &cmd, sizeof cmd, &data, sizeof data, 0) != 0)
146 0 : data = 0xffff;
147 0 : iic_release_bus(probe_ic, 0);
148 0 : return betoh16(data);
149 0 : }
150 :
151 : u_int8_t
152 0 : iicprobe(u_int8_t cmd)
153 : {
154 0 : if (probe_val[cmd] != 0xff)
155 0 : return probe_val[cmd];
156 0 : probe_val[cmd] = iicprobenc(cmd);
157 0 : return (probe_val[cmd]);
158 0 : }
159 :
160 : #define LM75TEMP 0x00
161 : #define LM75CONF 0x01
162 : #define LM75Thyst 0x02
163 : #define LM75Tos 0x03
164 : #define LM77Tlow 0x04
165 : #define LM77Thigh 0x05
166 : #define LM75TMASK 0xff80 /* 9 bits in temperature registers */
167 : #define LM77TMASK 0xfff8 /* 13 bits in temperature registers */
168 :
169 : /*
170 : * The LM75/LM75A/LM77 family are very hard to detect. Thus, we check
171 : * for all other possible chips first. These chips do not have an
172 : * ID register. They do have a few quirks though:
173 : * - on the LM75 and LM77, registers 0x06 and 0x07 return whatever
174 : * value was read before
175 : * - the LM75 lacks registers 0x04 and 0x05, so those act as above
176 : * - the LM75A returns 0xffff for registers 0x04, 0x05, 0x06 and 0x07
177 : * - the chip registers loop every 8 registers
178 : * The downside is that we must read almost every register to guess
179 : * if this is an LM75, LM75A or LM77.
180 : */
181 : char *
182 0 : lm75probe(void)
183 : {
184 : u_int16_t temp, thyst, tos, tlow, thigh, mask = LM75TMASK;
185 : u_int8_t conf;
186 : int i, echocount, ffffcount, score;
187 : int echoreg67, echoreg45, ffffreg67, ffffreg45;
188 :
189 0 : temp = iicprobew(LM75TEMP);
190 :
191 : /*
192 : * Sometimes the other probes can upset the chip, if we get 0xffff
193 : * the first time, try it once more.
194 : */
195 0 : if (temp == 0xffff)
196 0 : temp = iicprobew(LM75TEMP);
197 :
198 0 : conf = iicprobenc(LM75CONF);
199 0 : thyst = iicprobew(LM75Thyst);
200 0 : tos = iicprobew(LM75Tos);
201 :
202 : /* totally bogus data */
203 0 : if (conf == 0xff && temp == 0xffff && thyst == 0xffff)
204 0 : return (NULL);
205 :
206 0 : temp &= mask;
207 0 : thyst &= mask;
208 0 : tos &= mask;
209 :
210 : /* All values the same? Very unlikely */
211 0 : if (temp == thyst && thyst == tos)
212 0 : return (NULL);
213 :
214 : #if notsure
215 : /* more register aliasing effects that indicate not a lm75 */
216 : if ((temp >> 8) == conf)
217 : return (NULL);
218 : #endif
219 :
220 : /*
221 : * LM77/LM75 registers 6, 7
222 : * echo whatever was read just before them from reg 0, 1, or 2
223 : *
224 : * LM75A doesn't appear to do this, but does appear to reliably
225 : * return 0xffff
226 : */
227 0 : for (i = 6, echocount = 2, ffffcount = 0; i <= 7; i++) {
228 0 : if ((iicprobew(LM75TEMP) & mask) != (iicprobew(i) & mask) ||
229 0 : (iicprobew(LM75Thyst) & mask) != (iicprobew(i) & mask) ||
230 0 : (iicprobew(LM75Tos) & mask) != (iicprobew(i) & mask))
231 0 : echocount--;
232 0 : if (iicprobew(i) == 0xffff)
233 0 : ffffcount++;
234 : }
235 :
236 : /* Make sure either both registers echo, or neither does */
237 0 : if (echocount == 1 || ffffcount == 1)
238 0 : return (NULL);
239 :
240 0 : echoreg67 = (echocount == 0) ? 0 : 1;
241 0 : ffffreg67 = (ffffcount == 0) ? 0 : 1;
242 :
243 : /*
244 : * LM75 has no registers 4 or 5, and they will act as echos too
245 : *
246 : * LM75A doesn't appear to do this either, but does appear to
247 : * reliably return 0xffff
248 : */
249 0 : for (i = 4, echocount = 2, ffffcount = 0; i <= 5; i++) {
250 0 : if ((iicprobew(LM75TEMP) & mask) != (iicprobew(i) & mask) ||
251 0 : (iicprobew(LM75Thyst) & mask) != (iicprobew(i) & mask) ||
252 0 : (iicprobew(LM75Tos) & mask) != (iicprobew(i) & mask))
253 0 : echocount--;
254 0 : if (iicprobew(i) == 0xffff)
255 0 : ffffcount++;
256 : }
257 :
258 : /* Make sure either both registers echo, or neither does */
259 0 : if (echocount == 1 || ffffcount == 1)
260 0 : return (NULL);
261 :
262 0 : echoreg45 = (echocount == 0) ? 0 : 1;
263 0 : ffffreg45 = (ffffcount == 0) ? 0 : 1;
264 :
265 : /*
266 : * If we find that 4 and 5 are not echos, and don't return 0xffff
267 : * then based on whether the echo test of registers 6 and 7
268 : * succeeded or not, we may have an LM77
269 : */
270 0 : if (echoreg45 == 0 && ffffreg45 == 0 && echoreg67 == 1) {
271 : mask = LM77TMASK;
272 :
273 : /* mask size changed, must re-read for the next checks */
274 0 : thyst = iicprobew(LM75Thyst) & mask;
275 0 : tos = iicprobew(LM75Tos) & mask;
276 0 : tlow = iicprobew(LM77Tlow) & mask;
277 0 : thigh = iicprobew(LM77Thigh) & mask;
278 0 : }
279 :
280 : /* a real LM75/LM75A/LM77 repeats its registers.... */
281 0 : for (i = 0x08; i <= 0xf8; i += 8) {
282 0 : if (conf != iicprobenc(LM75CONF + i) ||
283 0 : thyst != (iicprobew(LM75Thyst + i) & mask) ||
284 0 : tos != (iicprobew(LM75Tos + i) & mask))
285 0 : return (NULL);
286 :
287 : /*
288 : * Check that the repeated registers 0x06 and 0x07 still
289 : * either echo or return 0xffff
290 : */
291 0 : if (echoreg67 == 1) {
292 0 : tos = iicprobew(LM75Tos) & mask;
293 0 : if (tos != (iicprobew(0x06 + i) & mask) ||
294 0 : tos != (iicprobew(0x07 + i) & mask))
295 0 : return (NULL);
296 0 : } else if (ffffreg67 == 1)
297 0 : if (iicprobew(0x06 + i) != 0xffff ||
298 0 : iicprobew(0x07 + i) != 0xffff)
299 0 : return (NULL);
300 :
301 : /*
302 : * Check that the repeated registers 0x04 and 0x05 still
303 : * either echo or return 0xffff. If they do neither, and
304 : * registers 0x06 and 0x07 echo, then we will be probing
305 : * for an LM77, so make sure those still repeat
306 : */
307 0 : if (echoreg45 == 1) {
308 0 : tos = iicprobew(LM75Tos) & mask;
309 0 : if (tos != (iicprobew(LM77Tlow + i) & mask) ||
310 0 : tos != (iicprobew(LM77Thigh + i) & mask))
311 0 : return (NULL);
312 0 : } else if (ffffreg45 == 1) {
313 0 : if (iicprobew(LM77Tlow + i) != 0xffff ||
314 0 : iicprobew(LM77Thigh + i) != 0xffff)
315 0 : return (NULL);
316 0 : } else if (echoreg67 == 1)
317 0 : if (tlow != (iicprobew(LM77Tlow + i) & mask) ||
318 0 : thigh != (iicprobew(LM77Thigh + i) & mask))
319 0 : return (NULL);
320 : }
321 :
322 : /*
323 : * Given that we now know how the first eight registers behave and
324 : * that this behaviour is consistently repeated, we can now use
325 : * the following table:
326 : *
327 : * echoreg67 | echoreg45 | ffffreg67 | ffffreg45 | chip
328 : * ----------+-----------+-----------+-----------+------
329 : * 1 | 1 | 0 | 0 | LM75
330 : * 1 | 0 | 0 | 0 | LM77
331 : * 0 | 0 | 1 | 1 | LM75A
332 : */
333 :
334 : /* Convert the various flags into a single score */
335 0 : score = (echoreg67 << 3) + (echoreg45 << 2) + (ffffreg67 << 1) +
336 : ffffreg45;
337 :
338 0 : switch (score) {
339 : case 12:
340 0 : return ("lm75");
341 : case 8:
342 0 : return ("lm77");
343 : case 3:
344 0 : return ("lm75a");
345 : default:
346 : #if defined(I2C_DEBUG)
347 : printf("lm75probe: unknown chip, scored %d\n", score);
348 : #endif /* defined(I2C_DEBUG) */
349 0 : return (NULL);
350 : }
351 0 : }
352 :
353 : char *
354 0 : adm1032cloneprobe(u_int8_t addr)
355 : {
356 0 : if (addr == 0x18 || addr == 0x1a || addr == 0x29 ||
357 0 : addr == 0x2b || addr == 0x4c || addr == 0x4e) {
358 : u_int8_t reg, val;
359 : int zero = 0, copy = 0;
360 :
361 0 : val = iicprobe(0x00);
362 0 : for (reg = 0x00; reg < 0x09; reg++) {
363 0 : if (iicprobe(reg) == 0xff)
364 0 : return (NULL);
365 0 : if (iicprobe(reg) == 0x00)
366 0 : zero++;
367 0 : if (val == iicprobe(reg))
368 0 : copy++;
369 : }
370 0 : if (zero > 6 || copy > 6)
371 0 : return (NULL);
372 0 : val = iicprobe(0x09);
373 0 : for (reg = 0x0a; reg < 0xfc; reg++) {
374 0 : if (iicprobe(reg) != val)
375 0 : return (NULL);
376 : }
377 : /* 0xfe may be Maxim, or some other vendor */
378 0 : if (iicprobe(0xfe) == 0x4d)
379 0 : return ("max1617");
380 : /*
381 : * "xeontemp" is the name we choose for clone chips
382 : * which have all sorts of buggy bus interactions, such
383 : * as those we just probed. Why?
384 : * Intel is partly to blame for this situation.
385 : */
386 0 : return ("xeontemp");
387 : }
388 0 : return (NULL);
389 0 : }
390 :
391 : void
392 0 : iic_ignore_addr(u_int8_t addr)
393 : {
394 : int i;
395 :
396 0 : for (i = 0; i < sizeof(ignore_addrs); i++)
397 0 : if (ignore_addrs[i] == 0) {
398 0 : ignore_addrs[i] = addr;
399 0 : return;
400 : }
401 0 : }
402 :
403 : #ifdef I2C_VERBOSE
404 : void
405 0 : iic_dump(struct device *dv, u_int8_t addr, char *name)
406 : {
407 : static u_int8_t iicvalcnt[256];
408 : u_int8_t val, val2, max;
409 : int i, cnt = 0;
410 :
411 : /*
412 : * Don't bother printing the most often repeated register
413 : * value, since it is often weird devices that respond
414 : * incorrectly, busted controller driver, or in the worst
415 : * case, it in mosts cases, the value 0xff.
416 : */
417 0 : bzero(iicvalcnt, sizeof iicvalcnt);
418 0 : val = iicprobe(0);
419 0 : iicvalcnt[val]++;
420 0 : for (i = 1; i <= 0xff; i++) {
421 0 : val2 = iicprobe(i);
422 0 : iicvalcnt[val2]++;
423 0 : if (val == val2)
424 0 : cnt++;
425 : }
426 :
427 0 : for (val = max = i = 0; i <= 0xff; i++)
428 0 : if (max < iicvalcnt[i]) {
429 : max = iicvalcnt[i];
430 0 : val = i;
431 0 : }
432 :
433 0 : if (cnt == 255)
434 0 : return;
435 :
436 0 : printf("%s: addr 0x%x", dv->dv_xname, addr);
437 0 : for (i = 0; i <= 0xff; i++) {
438 0 : if (iicprobe(i) != val)
439 0 : printf(" %02x=%02x", i, iicprobe(i));
440 : }
441 0 : printf(" words");
442 0 : for (i = 0; i < 8; i++)
443 0 : printf(" %02x=%04x", i, iicprobew(i));
444 0 : if (name)
445 0 : printf(": %s", name);
446 0 : printf("\n");
447 0 : }
448 : #endif /* I2C_VERBOSE */
449 :
450 : char *
451 0 : iic_probe_sensor(struct device *self, u_int8_t addr)
452 : {
453 : char *name = NULL;
454 :
455 0 : skip_fc = 0;
456 :
457 : /*
458 : * Many I2C/SMBus devices use register 0x3e as a vendor ID
459 : * register.
460 : */
461 0 : switch (iicprobe(0x3e)) {
462 : case 0x01: /* National Semiconductor */
463 : /*
464 : * Some newer National products use a vendor code at
465 : * 0x3e of 0x01, and then 0x3f contains a product code
466 : * But some older products are missing a product code,
467 : * and contain who knows what in that register. We assume
468 : * that some employee was smart enough to keep the numbers
469 : * unique.
470 : */
471 0 : if ((addr == 0x2c || addr == 0x2d || addr == 0x2e) &&
472 0 : (iicprobe(0x3f) == 0x73 || iicprobe(0x3f) == 0x72) &&
473 0 : iicprobe(0x00) == 0x00)
474 0 : name = "lm93"; /* product 0x72 is the prototype */
475 0 : else if ((addr == 0x2c || addr == 0x2d || addr == 0x2e) &&
476 0 : iicprobe(0x3f) == 0x68)
477 0 : name = "lm96000"; /* adt7460 compat? */
478 0 : else if ((addr == 0x2c || addr == 0x2d || addr == 0x2e) &&
479 0 : (iicprobe(0x3f) == 0x60 || iicprobe(0x3f) == 0x62))
480 0 : name = "lm85"; /* lm85C/B == adt7460 compat */
481 0 : else if ((addr & 0x7c) == 0x2c && /* addr 0b01011xx */
482 0 : iicprobe(0x48) == addr &&
483 0 : (iicprobe(0x3f) == 0x03 || iicprobe(0x3f) == 0x04) &&
484 0 : (iicprobe(0x40) & 0x80) == 0x00)
485 0 : name = "lm81";
486 : break;
487 : case 0x02: /* National Semiconductor? */
488 0 : if ((iicprobe(0x3f) & 0xfc) == 0x04)
489 0 : name = "lm87"; /* complete check */
490 : break;
491 : case 0x23: /* Analog Devices? */
492 0 : if (iicprobe(0x48) == addr &&
493 0 : (iicprobe(0x40) & 0x80) == 0x00 &&
494 0 : (addr & 0x7c) == 0x2c)
495 0 : name = "adm9240"; /* lm87 clone */
496 : break;
497 : case 0x41: /* Analog Devices */
498 : /*
499 : * Newer chips have a valid 0x3d product number, while
500 : * older ones sometimes encoded the product into the
501 : * upper half of the "step register" at 0x3f.
502 : */
503 0 : if ((addr == 0x2c || addr == 0x2e || addr == 0x2f) &&
504 0 : iicprobe(0x3d) == 0x70)
505 0 : name = "adt7470";
506 0 : else if ((addr == 0x2c || addr == 0x2d || addr == 0x2e) &&
507 0 : iicprobe(0x3d) == 0x76)
508 0 : name = "adt7476"; /* or adt7476a */
509 0 : else if (addr == 0x2e && iicprobe(0x3d) == 0x75)
510 0 : name = "adt7475";
511 0 : else if (iicprobe(0x3d) == 0x27 &&
512 0 : (iicprobe(0x3f) == 0x60 || iicprobe(0x3f) == 0x6a))
513 0 : name = "adm1027"; /* or adt7463 */
514 0 : else if (iicprobe(0x3d) == 0x27 &&
515 0 : (iicprobe(0x3f) == 0x62 || iicprobe(0x3f) == 0x6a))
516 0 : name = "adt7460"; /* complete check */
517 0 : else if ((addr == 0x2c || addr == 0x2e) &&
518 0 : iicprobe(0x3d) == 0x62 && iicprobe(0x3f) == 0x04)
519 0 : name = "adt7462";
520 0 : else if (addr == 0x4c &&
521 0 : iicprobe(0x3d) == 0x66 && iicprobe(0x3f) == 0x02)
522 0 : name = "adt7466";
523 0 : else if (addr == 0x2e &&
524 0 : iicprobe(0x3d) == 0x68 && (iicprobe(0x3f) & 0xf0) == 0x70)
525 0 : name = "adt7467"; /* or adt7468 */
526 0 : else if (iicprobe(0x3d) == 0x33 && iicprobe(0x3f) == 0x02)
527 0 : name = "adm1033";
528 0 : else if (iicprobe(0x3d) == 0x34 && iicprobe(0x3f) == 0x02)
529 0 : name = "adm1034";
530 0 : else if ((addr == 0x2c || addr == 0x2d || addr == 0x2e) &&
531 0 : iicprobe(0x3d) == 0x30 &&
532 0 : (iicprobe(0x01) & 0x80) == 0x00 &&
533 0 : (iicprobe(0x0d) & 0x70) == 0x00 &&
534 0 : (iicprobe(0x0e) & 0x70) == 0x00)
535 : /*
536 : * Revision 3 seems to be an adm1031 with
537 : * remote diode 2 shorted. Therefore we
538 : * cannot assume the reserved/unused bits of
539 : * register 0x03 and 0x06 are set to zero.
540 : */
541 0 : name = "adm1030"; /* complete check */
542 0 : else if ((addr == 0x2c || addr == 0x2d || addr == 0x2e) &&
543 0 : iicprobe(0x3d) == 0x31 &&
544 0 : (iicprobe(0x01) & 0x80) == 0x00 &&
545 0 : (iicprobe(0x0d) & 0x70) == 0x00 &&
546 0 : (iicprobe(0x0e) & 0x70) == 0x00 &&
547 0 : (iicprobe(0x0f) & 0x70) == 0x00)
548 0 : name = "adm1031"; /* complete check */
549 0 : else if ((addr & 0x7c) == 0x2c && /* addr 0b01011xx */
550 0 : (iicprobe(0x3f) & 0xf0) == 0x20 &&
551 0 : (iicprobe(0x40) & 0x80) == 0x00 &&
552 0 : (iicprobe(0x41) & 0xc0) == 0x00 &&
553 0 : (iicprobe(0x42) & 0xbc) == 0x00)
554 0 : name = "adm1025"; /* complete check */
555 0 : else if ((addr & 0x7c) == 0x2c && /* addr 0b01011xx */
556 0 : (iicprobe(0x3f) & 0xf0) == 0x10 &&
557 0 : (iicprobe(0x40) & 0x80) == 0x00)
558 0 : name = "adm1024"; /* complete check */
559 0 : else if ((iicprobe(0xff) & 0xf0) == 0x30)
560 0 : name = "adm1023";
561 0 : else if (addr == 0x2e &&
562 0 : (iicprobe(0x3f) & 0xf0) == 0xd0 &&
563 0 : (iicprobe(0x40) & 0x80) == 0x00)
564 0 : name = "adm1028"; /* adm1022 clone? */
565 0 : else if ((addr == 0x2c || addr == 0x2e || addr == 0x2f) &&
566 0 : (iicprobe(0x3f) & 0xf0) == 0xc0 &&
567 0 : (iicprobe(0x40) & 0x80) == 0x00)
568 0 : name = "adm1022";
569 : break;
570 : case 0x49: /* Texas Instruments */
571 0 : if ((addr == 0x2c || addr == 0x2e || addr == 0x2f) &&
572 0 : (iicprobe(0x3f) & 0xf0) == 0xc0 &&
573 0 : (iicprobe(0x40) & 0x80) == 0x00)
574 0 : name = "thmc50"; /* adm1022 clone */
575 : break;
576 : case 0x55: /* SMSC */
577 0 : if ((addr & 0x7c) == 0x2c && /* addr 0b01011xx */
578 0 : iicprobe(0x3f) == 0x20 &&
579 0 : (iicprobe(0x47) & 0x70) == 0x00 &&
580 0 : (iicprobe(0x49) & 0xfe) == 0x80)
581 0 : name = "47m192"; /* adm1025 compat */
582 : break;
583 : case 0x5c: /* SMSC */
584 0 : if ((addr == 0x2c || addr == 0x2d || addr == 0x2e) &&
585 0 : (iicprobe(0x3f) == 0x69))
586 0 : name = "sch5027";
587 0 : else if ((addr == 0x2c || addr == 0x2d || addr == 0x2e) &&
588 0 : (iicprobe(0x3f) & 0xf0) == 0x60)
589 0 : name = "emc6d100"; /* emc6d101, emc6d102, emc6d103 */
590 0 : else if ((addr == 0x2c || addr == 0x2d || addr == 0x2e) &&
591 0 : (iicprobe(0x3f) & 0xf0) == 0x80)
592 0 : name = "sch5017";
593 0 : else if ((addr == 0x2c || addr == 0x2d || addr == 0x2e) &&
594 0 : (iicprobe(0x3f) & 0xf0) == 0xb0)
595 0 : name = "emc6w201";
596 : break;
597 : case 0x61: /* Andigilog */
598 0 : if ((addr == 0x2c || addr == 0x2d || addr == 0x2e) &&
599 0 : iicprobe(0x3f) == 0x69 &&
600 0 : iicprobe(0x22) >= 0xaf && /* Vdd */
601 0 : (iicprobe(0x09) & 0xbf) == 0x00 && iicprobe(0x0f) == 0x00 &&
602 0 : (iicprobe(0x40) & 0xf0) == 0x00)
603 0 : name = "asc7611";
604 0 : else if ((addr == 0x2c || addr == 0x2d || addr == 0x2e) &&
605 0 : iicprobe(0x3f) == 0x6c &&
606 0 : iicprobe(0x22) >= 0xae) /* Vdd */
607 0 : name = "asc7621";
608 : break;
609 : case 0xa1: /* Philips */
610 0 : if ((iicprobe(0x3f) & 0xf0) == 0x20 &&
611 0 : (iicprobe(0x40) & 0x80) == 0x00 &&
612 0 : (iicprobe(0x41) & 0xc0) == 0x00 &&
613 0 : (iicprobe(0x42) & 0xbc) == 0x00)
614 0 : name = "ne1619"; /* adm1025 compat */
615 : break;
616 : case 0xda: /* Dallas Semiconductor */
617 0 : if (iicprobe(0x3f) == 0x01 && iicprobe(0x48) == addr &&
618 0 : (iicprobe(0x40) & 0x80) == 0x00)
619 0 : name = "ds1780"; /* lm87 clones */
620 : break;
621 : }
622 :
623 0 : switch (iicprobe(0x4e)) {
624 : case 0x41: /* Analog Devices */
625 0 : if ((addr == 0x48 || addr == 0x4a || addr == 0x4b) &&
626 0 : (iicprobe(0x4d) == 0x03 || iicprobe(0x4d) == 0x08 ||
627 0 : iicprobe(0x4d) == 0x07))
628 0 : name = "adt7516"; /* adt7517, adt7519 */
629 : break;
630 : }
631 :
632 0 : switch (iicprobe(0xfe)) {
633 : case 0x01: /* National Semiconductor */
634 0 : if (addr == 0x4c &&
635 0 : iicprobe(0xff) == 0x41 && (iicprobe(0x03) & 0x18) == 0 &&
636 0 : iicprobe(0x04) <= 0x0f && (iicprobe(0xbf) & 0xf8) == 0)
637 0 : name = "lm63";
638 0 : else if (addr == 0x4c &&
639 0 : iicprobe(0xff) == 0x11 && (iicprobe(0x03) & 0x2a) == 0 &&
640 0 : iicprobe(0x04) <= 0x09 && (iicprobe(0xbf) & 0xf8) == 0)
641 0 : name = "lm86";
642 0 : else if (addr == 0x4c &&
643 0 : iicprobe(0xff) == 0x31 && (iicprobe(0x03) & 0x2a) == 0 &&
644 0 : iicprobe(0x04) <= 0x09 && (iicprobe(0xbf) & 0xf8) == 0)
645 0 : name = "lm89"; /* or lm99 */
646 0 : else if (addr == 0x4d &&
647 0 : iicprobe(0xff) == 0x34 && (iicprobe(0x03) & 0x2a) == 0 &&
648 0 : iicprobe(0x04) <= 0x09 && (iicprobe(0xbf) & 0xf8) == 0)
649 0 : name = "lm89-1"; /* or lm99-1 */
650 0 : else if (addr == 0x4c &&
651 0 : iicprobe(0xff) == 0x21 && (iicprobe(0x03) & 0x2a) == 0 &&
652 0 : iicprobe(0x04) <= 0x09 && (iicprobe(0xbf) & 0xf8) == 0)
653 0 : name = "lm90";
654 : break;
655 : case 0x23: /* Genesys Logic? */
656 0 : if ((addr == 0x4c) &&
657 0 : (iicprobe(0x03) & 0x3f) == 0x00 && iicprobe(0x04) <= 0x08)
658 : /*
659 : * Genesys Logic doesn't make the datasheet
660 : * for the GL523SM publically available, so
661 : * the checks above are nothing more than a
662 : * (conservative) educated guess.
663 : */
664 0 : name = "gl523sm";
665 : break;
666 : case 0x41: /* Analog Devices */
667 0 : if ((addr == 0x4c || addr == 0x4d) &&
668 0 : iicprobe(0xff) == 0x51 &&
669 0 : (iicprobe(0x03) & 0x1f) == 0x04 &&
670 0 : iicprobe(0x04) <= 0x0a) {
671 : /* If not in adm1032 compatibility mode. */
672 : name = "adt7461";
673 0 : } else if ((addr == 0x18 || addr == 0x19 || addr == 0x1a ||
674 0 : addr == 0x29 || addr == 0x2a || addr == 0x2b ||
675 0 : addr == 0x4c || addr == 0x4d || addr == 0x4e) &&
676 0 : (iicprobe(0xff) & 0xf0) == 0x00 &&
677 0 : (iicprobe(0x03) & 0x3f) == 0x00 &&
678 0 : iicprobe(0x04) <= 0x07) {
679 : name = "adm1021";
680 0 : skip_fc = 1;
681 0 : } else if ((addr == 0x18 || addr == 0x19 || addr == 0x1a ||
682 0 : addr == 0x29 || addr == 0x2a || addr == 0x2b ||
683 0 : addr == 0x4c || addr == 0x4d || addr == 0x4e) &&
684 0 : (iicprobe(0xff) & 0xf0) == 0x30 &&
685 0 : (iicprobe(0x03) & 0x3f) == 0x00 &&
686 0 : iicprobe(0x04) <= 0x07) {
687 : name = "adm1023"; /* or adm1021a */
688 0 : skip_fc = 1;
689 0 : } else if ((addr == 0x4c || addr == 0x4d || addr == 0x4e) &&
690 0 : (iicprobe(0x03) & 0x3f) == 0x00 &&
691 0 : iicprobe(0x04) <= 0x0a) {
692 : name = "adm1032"; /* or adm1020 */
693 0 : skip_fc = 1;
694 0 : }
695 : break;
696 : case 0x47: /* Global Mixed-mode Technology */
697 0 : if (addr == 0x4c && iicprobe(0xff) == 0x01 &&
698 0 : (iicprobe(0x03) & 0x3f) == 0x00 && iicprobe(0x04) <= 0x08)
699 0 : name = "g781";
700 0 : if (addr == 0x4d && iicprobe(0xff) == 0x03 &&
701 0 : (iicprobe(0x03) & 0x3f) == 0x00 && iicprobe(0x04) <= 0x08)
702 0 : name = "g781-1";
703 : break;
704 : case 0x4d: /* Maxim */
705 0 : if ((addr == 0x18 || addr == 0x19 || addr == 0x1a ||
706 0 : addr == 0x29 || addr == 0x2a || addr == 0x2b ||
707 0 : addr == 0x4c || addr == 0x4d || addr == 0x4e) &&
708 0 : iicprobe(0xff) == 0x08 && (iicprobe(0x02) & 0x03) == 0 &&
709 0 : (iicprobe(0x03) & 0x07) == 0 && iicprobe(0x04) <= 0x08)
710 0 : name = "max6690";
711 0 : else if ((addr == 0x4c || addr == 0x4d || addr == 0x4e) &&
712 0 : iicprobe(0xff) == 0x59 && (iicprobe(0x03) & 0x1f) == 0 &&
713 0 : iicprobe(0x04) <= 0x07)
714 0 : name = "max6646"; /* max6647/8/9, max6692 */
715 0 : else if ((addr == 0x4c || addr == 0x4d || addr == 0x4e) &&
716 0 : (iicprobe(0x02) & 0x2b) == 0 &&
717 0 : (iicprobe(0x03) & 0x0f) == 0 && iicprobe(0x04) <= 0x09) {
718 : name = "max6657"; /* max6658, max6659 */
719 0 : skip_fc = 1;
720 0 : } else if ((addr >= 0x48 && addr <= 0x4f) &&
721 0 : (iicprobe(0x02) & 0x2b) == 0 &&
722 0 : (iicprobe(0x03) & 0x0f) == 0)
723 0 : name = "max6642";
724 : break;
725 : case 0x55: /* Texas Instruments */
726 0 : if (addr == 0x4c && iicprobe(0xff) == 0x11 &&
727 0 : (iicprobe(0x03) & 0x1b) == 0x00 &&
728 0 : (iicprobe(0x04) & 0xf0) == 0x00 &&
729 0 : (iicprobe(0x10) & 0x0f) == 0x00 &&
730 0 : (iicprobe(0x13) & 0x0f) == 0x00 &&
731 0 : (iicprobe(0x14) & 0x0f) == 0x00 &&
732 0 : (iicprobe(0x15) & 0x0f) == 0x00 &&
733 0 : (iicprobe(0x16) & 0x0f) == 0x00 &&
734 0 : (iicprobe(0x17) & 0x0f) == 0x00)
735 0 : name = "tmp401";
736 : break;
737 : case 0xa1:
738 0 : if ((addr >= 0x48 && addr <= 0x4f) &&
739 0 : iicprobe(0xff) == 0x00 &&
740 0 : (iicprobe(0x03) & 0xf8) == 0x00 &&
741 0 : iicprobe(0x04) <= 0x09) {
742 : name = "sa56004x"; /* NXP sa56004x */
743 0 : skip_fc = 1;
744 0 : }
745 : break;
746 : }
747 :
748 0 : if (addr == iicprobe(0x48) &&
749 0 : ((iicprobe(0x4f) == 0x5c && (iicprobe(0x4e) & 0x80)) ||
750 0 : (iicprobe(0x4f) == 0xa3 && !(iicprobe(0x4e) & 0x80)))) {
751 : /*
752 : * We could toggle 0x4e bit 0x80, then re-read 0x4f to
753 : * see if the value changes to 0xa3 (indicating Winbond).
754 : * But we are trying to avoid writes.
755 : */
756 0 : if ((iicprobe(0x4e) & 0x07) == 0) {
757 0 : switch (iicprobe(0x58)) {
758 : case 0x10:
759 : case 0x11: /* rev 2? */
760 : name = "w83781d";
761 0 : break;
762 : case 0x21:
763 : name = "w83627hf";
764 0 : break;
765 : case 0x30:
766 : name = "w83782d";
767 0 : break;
768 : case 0x31:
769 : name = "as99127f"; /* rev 2 */
770 0 : break;
771 : case 0x40:
772 : name = "w83783s";
773 0 : break;
774 : case 0x71:
775 : name = "w83791d";
776 0 : break;
777 : case 0x72:
778 : name = "w83791sd";
779 0 : break;
780 : case 0x7a:
781 : name = "w83792d";
782 0 : break;
783 : case 0xc1:
784 : name = "w83627dhg";
785 0 : break;
786 : }
787 : } else {
788 : /*
789 : * The BIOS left the chip in a non-zero
790 : * register bank. Assume it's a W83781D and
791 : * let lm(4) sort out the real model.
792 : */
793 : name = "w83781d";
794 : }
795 0 : } else if (addr == (iicprobe(0xfc) & 0x7f) &&
796 0 : iicprobe(0xfe) == 0x79 && iicprobe(0xfb) == 0x51 &&
797 0 : ((iicprobe(0xfd) == 0x5c && (iicprobe(0x00) & 0x80)) ||
798 0 : (iicprobe(0xfd) == 0xa3 && !(iicprobe(0x00) & 0x80)))) {
799 : /*
800 : * We could toggle 0x00 bit 0x80, then re-read 0xfd to
801 : * see if the value changes to 0xa3 (indicating Nuvoton).
802 : * But we are trying to avoid writes.
803 : */
804 : name = "w83795g";
805 0 : } else if (addr == iicprobe(0x4a) && iicprobe(0x4e) == 0x50 &&
806 0 : iicprobe(0x4c) == 0xa3 && iicprobe(0x4d) == 0x5c) {
807 : name = "w83l784r";
808 0 : } else if (addr == 0x2d && iicprobe(0x4e) == 0x60 &&
809 0 : iicprobe(0x4c) == 0xa3 && iicprobe(0x4d) == 0x5c) {
810 : name = "w83l785r";
811 0 : } else if (addr == 0x2e && iicprobe(0x4e) == 0x70 &&
812 0 : iicprobe(0x4c) == 0xa3 && iicprobe(0x4d) == 0x5c) {
813 : name = "w83l785ts-l";
814 0 : } else if (addr >= 0x2c && addr <= 0x2f &&
815 0 : ((iicprobe(0x00) & 0x07) != 0x0 ||
816 0 : ((iicprobe(0x00) & 0x07) == 0x0 && addr * 2 == iicprobe(0x0b) &&
817 0 : (iicprobe(0x0c) & 0x40) && !(iicprobe(0x0c) & 0x04))) &&
818 0 : iicprobe(0x0e) == 0x7b &&
819 0 : (iicprobe(0x0f) & 0xf0) == 0x10 &&
820 0 : ((iicprobe(0x0d) == 0x5c && (iicprobe(0x00) & 0x80)) ||
821 0 : (iicprobe(0x0d) == 0xa3 && !(iicprobe(0x00) & 0x80)))) {
822 : name = "w83793g";
823 0 : } else if (addr >= 0x28 && addr <= 0x2f &&
824 0 : iicprobe(0x4f) == 0x12 && (iicprobe(0x4e) & 0x80)) {
825 : /*
826 : * We could toggle 0x4e bit 0x80, then re-read 0x4f to
827 : * see if the value changes to 0xc3 (indicating ASUS).
828 : * But we are trying to avoid writes.
829 : */
830 0 : if (iicprobe(0x58) == 0x31)
831 0 : name = "as99127f"; /* rev 1 */
832 0 : } else if ((addr == 0x2d || addr == 0x2e) &&
833 0 : addr * 2 == iicprobe(0x04) &&
834 0 : iicprobe(0x5d) == 0x19 && iicprobe(0x5e) == 0x34 &&
835 0 : iicprobe(0x5a) == 0x03 && iicprobe(0x5b) == 0x06) {
836 : name = "f75375"; /* Fintek */
837 0 : } else if (addr == 0x2d &&
838 0 : ((iicprobe(0x4f) == 0x06 && (iicprobe(0x4e) & 0x80)) ||
839 0 : (iicprobe(0x4f) == 0x94 && !(iicprobe(0x4e) & 0x80)))) {
840 : /*
841 : * We could toggle 0x4e bit 0x80, then re-read 0x4f to
842 : * see if the value changes to 0x94 (indicating ASUS).
843 : * But we are trying to avoid writes.
844 : *
845 : * NB. we won't match if the BIOS has selected a non-zero
846 : * register bank (set via 0x4e). We could select bank 0 so
847 : * we see the right registers, but that would require a
848 : * write. In general though, we bet no BIOS would leave us
849 : * in the wrong state.
850 : */
851 0 : if ((iicprobe(0x58) & 0x7f) == 0x31 &&
852 0 : (iicprobe(0x4e) & 0xf) == 0x00)
853 0 : name = "asb100";
854 0 : } else if ((addr == 0x2c || addr == 0x2d) &&
855 0 : iicprobe(0x00) == 0x80 &&
856 0 : (iicprobe(0x01) == 0x00 || iicprobe(0x01) == 0x80) &&
857 0 : iicprobe(0x02) == 0x00 && (iicprobe(0x03) & 0x83) == 0x00 &&
858 0 : (iicprobe(0x0f) & 0x07) == 0x00 &&
859 0 : (iicprobe(0x11) & 0x80) == 0x00 &&
860 0 : (iicprobe(0x12) & 0x80) == 0x00) {
861 : /*
862 : * The GL518SM is really crappy. It has both byte and
863 : * word registers, and reading a word register with a
864 : * byte read command will make the device crap out and
865 : * hang the bus. This has nasty consequences on some
866 : * machines, like preventing warm reboots. The word
867 : * registers are 0x07 through 0x0c, so make sure the
868 : * checks above don't access those registers. We
869 : * don't want to do this check right up front though
870 : * since this chip is somewhat hard to detect (which
871 : * is why we check for every single fixed bit it has).
872 : */
873 : name = "gl518sm";
874 0 : } else if ((addr == 0x2c || addr == 0x2d || addr == 0x2e) &&
875 0 : iicprobe(0x16) == 0x41 && ((iicprobe(0x17) & 0xf0) == 0x40)) {
876 : name = "adm1026";
877 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x1131 &&
878 0 : (iicprobew(0x07) & 0xfffc) == 0xa200) {
879 : name = "se97"; /* or se97b */
880 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x1131 &&
881 0 : (iicprobew(0x07) & 0xfffc) == 0xa100 &&
882 0 : (iicprobew(0x00) & 0xfff0) == 0x0010) {
883 : name = "se98";
884 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x004d &&
885 0 : iicprobew(0x07) == 0x3e00 &&
886 0 : (iicprobew(0x00) & 0xffe0) == 0x0000) {
887 : name = "max6604";
888 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x0054 &&
889 0 : (iicprobew(0x07) & 0xfffc) == 0x0200 &&
890 0 : (iicprobew(0x00) & 0xffe0) == 0x0000) {
891 : name = "mcp9804";
892 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x0054 &&
893 0 : (iicprobew(0x07) & 0xff00) == 0x0000 &&
894 0 : (iicprobew(0x00) & 0xffe0) == 0x0000) {
895 : name = "mcp9805"; /* or mcp9843 */
896 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x0054 &&
897 0 : (iicprobew(0x07) & 0xfffc) == 0x2000 &&
898 0 : (iicprobew(0x00) & 0xffe0) == 0x0000) {
899 : name = "mcp98242";
900 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x0054 &&
901 0 : (iicprobew(0x07) & 0xff00) == 0x2100 &&
902 0 : (iicprobew(0x00) & 0xff00) == 0x0000) {
903 : name = "mcp98243";
904 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x0054 &&
905 0 : (iicprobew(0x07) & 0xfffc) == 0x2200 &&
906 0 : (iicprobew(0x00) & 0xff00) == 0x0000) {
907 : name = "mcp98244";
908 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x11d4 &&
909 0 : iicprobew(0x07) == 0x0800 &&
910 0 : iicprobew(0x00) == 0x001d) {
911 : name = "adt7408";
912 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x104a &&
913 0 : (iicprobew(0x07) & 0xfffe) == 0x0000 &&
914 0 : (iicprobew(0x00) == 0x002d || iicprobew(0x00) == 0x002f)) {
915 : name = "stts424e02";
916 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x104a &&
917 0 : (iicprobew(0x07) & 0xfffe) == 0x0300 &&
918 0 : (iicprobew(0x00) == 0x006f)) {
919 : name = "stts2002";
920 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x104a &&
921 0 : (iicprobew(0x07) & 0xffff) == 0x2201 &&
922 0 : (iicprobew(0x00) == 0x00ef)) {
923 : name = "stts2004";
924 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x104a &&
925 0 : (iicprobew(0x07) & 0xffff) == 0x0200 &&
926 0 : (iicprobew(0x00) == 0x006f)) {
927 : name = "stts3000";
928 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x104a &&
929 0 : (iicprobew(0x07) & 0xffff) == 0x0101 &&
930 0 : (iicprobew(0x00) == 0x002d || iicprobew(0x00) == 0x002f)) {
931 : name = "stts424";
932 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x1b09 &&
933 0 : (iicprobew(0x07) & 0xffe0) == 0x0800 &&
934 0 : (iicprobew(0x00) & 0x001f) == 0x001f) {
935 : name = "cat34ts02"; /* or cat6095, prod 0x0813 */
936 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x1b09 &&
937 0 : (iicprobew(0x07) & 0xffff) == 0x0a00 &&
938 0 : (iicprobew(0x00) & 0x001f) == 0x001f) {
939 : name = "cat34ts02c";
940 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x1b09 &&
941 0 : (iicprobew(0x07) & 0xffff) == 0x2200 &&
942 0 : (iicprobew(0x00) == 0x007f)) {
943 : name = "cat34ts04";
944 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x00b3 &&
945 0 : (iicprobew(0x07) & 0xffff) == 0x2903 &&
946 0 : (iicprobew(0x00) == 0x004f)) {
947 : name = "ts3000b3"; /* or tse2002b3 */
948 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x00b3 &&
949 0 : (iicprobew(0x07) & 0xffff) == 0x2912 &&
950 0 : (iicprobew(0x00) == 0x006f)) {
951 : name = "ts3000gb2"; /* or tse2002gb2 */
952 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x00b3 &&
953 0 : (iicprobew(0x07) & 0xffff) == 0x2913 &&
954 0 : (iicprobew(0x00) == 0x0077)) {
955 : name = "ts3000gb0";
956 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x00b3 &&
957 0 : (iicprobew(0x07) & 0xffff) == 0x3001 &&
958 0 : (iicprobew(0x00) == 0x006f)) {
959 : name = "ts3001gb2";
960 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x00b3 &&
961 0 : (iicprobew(0x07) & 0xffff) == 0x2214 &&
962 0 : (iicprobew(0x00) == 0x00ff)) {
963 : name = "tse2004gb2";
964 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x001f &&
965 0 : (iicprobew(0x07) & 0xffff) == 0x8201 &&
966 0 : (iicprobew(0x00) & 0xff00) == 0x0000) {
967 : name = "at30ts00"; /* or at30tse002 */
968 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x1114 &&
969 0 : (iicprobew(0x07) & 0xffff) == 0x2200 &&
970 0 : (iicprobew(0x00) & 0xff00) == 0x0000) {
971 : name = "at30tse004";
972 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x1c68 &&
973 0 : (iicprobew(0x07) & 0xffff) == 0x2201 &&
974 0 : (iicprobew(0x00) & 0xff00) == 0x0000) {
975 : name = "gt30ts00";
976 0 : } else if ((addr & 0x78) == 0x18 && iicprobew(0x06) == 0x132d &&
977 0 : (iicprobew(0x07) & 0xffff) == 0x3300 &&
978 0 : (iicprobew(0x00) & 0x001f) == 0x001f) {
979 : name = "gt34ts02";
980 0 : } else if ((addr & 0x7e) == 0x1c && iicprobe(0x0f) == 0x3b &&
981 0 : (iicprobe(0x21) & 0x60) == 0x00 &&
982 0 : iicprobe(0x0f) == iicprobe(0x8f) && /* registers address is 7 bits */
983 0 : iicprobe(0x20) == iicprobe(0xa0) &&
984 0 : iicprobe(0x21) == iicprobe(0xa1) &&
985 0 : iicprobe(0x22) == iicprobe(0xa2) &&
986 0 : iicprobe(0x07) == 0x00) { /* 0x00 to 0x0e are reserved */
987 : name = "lis331dl";
988 0 : } else if (name == NULL &&
989 0 : (addr & 0x78) == 0x48) { /* addr 0b1001xxx */
990 0 : name = lm75probe();
991 0 : }
992 : #if 0
993 : /*
994 : * XXX This probe needs to be improved; the driver does some
995 : * dangerous writes.
996 : */
997 : if (name == NULL && (addr & 0x7c) == 0x48 && /* addr 0b1001xxx */
998 : (iicprobew(0xaa) & 0x0007) == 0x0000 &&
999 : (iicprobew(0xa1) & 0x0007) == 0x0000 &&
1000 : (iicprobew(0xa2) & 0x0007) == 0x0000 &&
1001 : (iicprobe(0xac) & 0x10) == 0x00) {
1002 : if ((iicprobe(0xac) & 0x7e) == 0x0a &&
1003 : iicprobe(0xab) == 0x00 && iicprobe(0xa8) == 0x00)
1004 : name = "ds1624";
1005 : else if ((iicprobe(0xac) & 0x7e) == 0x0c)
1006 : name = "ds1631"; /* terrible probe */
1007 : else if ((iicprobe(0xac) & 0x2e) == 0x2e)
1008 : name = "ds1721"; /* terrible probe */
1009 : }
1010 : #endif
1011 0 : if (name == NULL && (addr & 0xf8) == 0x28 && iicprobe(0x48) == addr &&
1012 0 : (iicprobe(0x00) & 0x90) == 0x10 && iicprobe(0x58) == 0x90) {
1013 0 : if (iicprobe(0x5b) == 0x12)
1014 0 : name = "it8712";
1015 0 : else if (iicprobe(0x5b) == 0x00)
1016 0 : name = "it8712f-a"; /* sis950 too */
1017 : }
1018 :
1019 0 : if (name == NULL && iicprobe(0x48) == addr &&
1020 0 : (iicprobe(0x40) & 0x80) == 0x00 && iicprobe(0x58) == 0xac)
1021 0 : name = "mtp008";
1022 :
1023 0 : if (name == NULL) {
1024 0 : name = adm1032cloneprobe(addr);
1025 0 : if (name)
1026 0 : skip_fc = 1;
1027 : }
1028 :
1029 0 : return (name);
1030 : }
1031 :
1032 : char *
1033 0 : iic_probe_eeprom(struct device *self, u_int8_t addr)
1034 : {
1035 : u_int8_t type;
1036 : char *name = NULL;
1037 :
1038 0 : type = iicprobe(0x02);
1039 : /* limit to SPD types seen in the wild */
1040 0 : if (type < 4 || type > 11)
1041 0 : return (name);
1042 :
1043 : /* more matching in driver(s) */
1044 : name = "eeprom";
1045 :
1046 0 : return (name);
1047 0 : }
1048 :
1049 : void
1050 0 : iic_scan(struct device *self, struct i2cbus_attach_args *iba)
1051 : {
1052 0 : i2c_tag_t ic = iba->iba_tag;
1053 0 : struct i2c_attach_args ia;
1054 : struct iicprobelist *pl;
1055 0 : u_int8_t cmd = 0, addr;
1056 : char *name;
1057 : int i, j, k;
1058 :
1059 0 : bzero(ignore_addrs, sizeof(ignore_addrs));
1060 :
1061 0 : for (i = 0; probes[i].probe; i++) {
1062 : #if NIPMI > 0
1063 : extern int ipmi_enabled;
1064 :
1065 0 : if ((probes[i].flags & PFLAG_SENSOR) && ipmi_enabled) {
1066 0 : printf("%s: skipping sensors to avoid ipmi0 interactions\n",
1067 0 : self->dv_xname);
1068 0 : continue;
1069 : }
1070 : #endif
1071 0 : pl = probes[i].pl;
1072 0 : for (j = 0; pl[j].start && pl[j].end; j++) {
1073 0 : for (addr = pl[j].start; addr <= pl[j].end; addr++) {
1074 0 : for (k = 0; k < sizeof(ignore_addrs); k++)
1075 0 : if (ignore_addrs[k] == addr)
1076 : break;
1077 0 : if (k < sizeof(ignore_addrs))
1078 : continue;
1079 :
1080 : /* Perform RECEIVE BYTE command */
1081 0 : iic_acquire_bus(ic, 0);
1082 0 : if (iic_exec(ic, I2C_OP_READ_WITH_STOP, addr,
1083 0 : &cmd, sizeof cmd, NULL, 0, 0) == 0) {
1084 : iic_release_bus(ic, 0);
1085 :
1086 : /* Some device exists */
1087 0 : iicprobeinit(iba, addr);
1088 0 : name = (*probes[i].probe)(self, addr);
1089 : #ifndef I2C_VERBOSE
1090 : if (name == NULL)
1091 : name = "unknown";
1092 : #endif /* !I2C_VERBOSE */
1093 0 : if (name) {
1094 0 : memset(&ia, 0, sizeof(ia));
1095 0 : ia.ia_tag = iba->iba_tag;
1096 0 : ia.ia_addr = addr;
1097 0 : ia.ia_size = 1;
1098 0 : ia.ia_name = name;
1099 0 : if (config_found(self,
1100 : &ia, iic_print))
1101 : continue;
1102 : }
1103 : #ifdef I2C_VERBOSE
1104 0 : if ((probes[i].flags & PFLAG_SENSOR))
1105 0 : iic_dump(self, addr, name);
1106 : #endif /* I2C_VERBOSE */
1107 : } else
1108 : iic_release_bus(ic, 0);
1109 : }
1110 : }
1111 : }
1112 0 : }
|