i2c_scan.c 35 KB

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