summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2005-12-20 05:00:48 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2005-12-20 05:00:48 +0000
commitbfe486f003f4f00794a1eaa74f748459b856f2b2 (patch)
treee0c13fa02c3c8491e9a14db413df9220de6241c2
parent337f1d9087664d350d7348986d75d2d911e2793b (diff)
start at a 2nd generation scanner
-rw-r--r--sys/dev/i2c/i2c_scan.c105
1 files changed, 70 insertions, 35 deletions
diff --git a/sys/dev/i2c/i2c_scan.c b/sys/dev/i2c/i2c_scan.c
index 223ed975c6a..e09d360dc9f 100644
--- a/sys/dev/i2c/i2c_scan.c
+++ b/sys/dev/i2c/i2c_scan.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: i2c_scan.c,v 1.1 2005/12/19 19:36:46 grange Exp $ */
+/* $OpenBSD: i2c_scan.c,v 1.2 2005/12/20 05:00:47 deraadt Exp $ */
/*
* Copyright (c) 2005 Alexander Yurchenko <grange@openbsd.org>
@@ -22,52 +22,87 @@
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/device.h>
#define _I2C_PRIVATE
#include <dev/i2c/i2cvar.h>
-/* Device signatures */
-static const struct {
- const char * name;
- i2c_addr_t addr;
- u_int8_t offset;
- u_int8_t value;
-} iicsig[] = {
- { "foo", 0xff, 0xff, 0xff }
+/*
+some basic devices...
+
+ 0x7 == 0x0001 national lm92
+ 0x3e == 0x01 national product
+ 0x3f == 0x73 lm93
+ 0x3e == 0x02
+ 0x3f == 0x06 lm87
+ 0xfe == 0x01 national product
+ 0xff == 0x33 lm90
+ 0xff == 0x49 0x52 lm99 lm89
+ 0xff == 0x17 lm86
+ 0xff == ?? lm83?
+ cannot identify lm81 lm80
+ 0xfe == 0x4d maxim (6659/6658/6659) == lm90
+ no 0x7 register?? maxim (6633/6634/6635) lm92
+
+XXX remove this block of text later
+0x00 National (on LM84)
+0x01 National
+0x12C3 Asus (at 0x4F)
+0x23 Analog Devices
+0x41 Analog Devices (also at 0x16)
+0x49 TI
+0x4D Maxim
+0x54 On Semi
+0x5C SMSC
+0x5D SMSC
+0x55 SMSC
+0x5CA3 Winbond (at 0x4F)
+0x90 ITE (at 0x58)
+0xA1 Philips (at 0x05 too)
+0xA3 Winbond (at 0x4F)
+0xAC Myson (at 0x58)
+0xC3 Asus (at 0x4F)
+0xDA Dallas
+0x54 Microchip (at 0x7)
+
+ */
+
+struct {
+ u_int8_t start, end;
+} probe_paddrs[] = {
+ { 0x20, 0x2f },
+ { 0x48, 0x4f },
+ { 0xad, 0xad }
};
+u_int8_t probe[] = { 0x3e, 0x3f, 0xfe, 0xff, 0x4f, 0x58, 0x07 };
+
void
iic_scan(struct device *self, struct i2cbus_attach_args *iba)
{
i2c_tag_t ic = iba->iba_tag;
u_int8_t cmd = 0, addr, data;
- int i;
-
- /* Do full scan */
- printf("%s: full scan:", self->dv_xname);
- for (addr = 0; addr < 0x80; addr++) {
- ic->ic_acquire_bus(ic->ic_cookie, I2C_F_POLL);
- if (ic->ic_exec(ic->ic_cookie, I2C_OP_READ_WITH_STOP, addr,
- &cmd, 1, NULL, 0, I2C_F_POLL) == 0)
- printf(" 0x%x", addr);
- ic->ic_release_bus(ic->ic_cookie, I2C_F_POLL);
- }
- printf("\n");
-
- /* Scan only for know signatures */
- printf("%s: sign scan:", self->dv_xname);
- for (i = 0; i < sizeof(iicsig) / sizeof(iicsig[0]); i++) {
- addr = iicsig[i].addr;
- cmd = iicsig[i].offset;
+ int i, j;
- ic->ic_acquire_bus(ic->ic_cookie, I2C_F_POLL);
- if (ic->ic_exec(ic->ic_cookie, I2C_OP_READ_WITH_STOP, addr,
- &cmd, 1, &data, 1, I2C_F_POLL) == 0) {
- if (iicsig[i].value == 0xff ||
- iicsig[i].value == data)
- printf(" %s", iicsig[i].name);
+ for (j = 0; j < sizeof(probe_paddrs)/sizeof(probe_paddrs[0]); j++) {
+ for (addr = probe_paddrs[j].start; addr <= probe_paddrs[j].end;
+ addr++) {
+ /* Perform RECEIVE BYTE command */
+ ic->ic_acquire_bus(ic->ic_cookie, I2C_F_POLL);
+ if (ic->ic_exec(ic->ic_cookie, I2C_OP_READ_WITH_STOP, addr,
+ &cmd, 1, NULL, 0, I2C_F_POLL) == 0) {
+ printf("addr 0x%x at %s: ", addr, self->dv_xname);
+ for (i = 0; i < sizeof(probe); i++) {
+ cmd = probe[i];
+ if (ic->ic_exec(ic->ic_cookie,
+ I2C_OP_READ_WITH_STOP, addr,
+ &cmd, 1, &data, 1, I2C_F_POLL) == 0 &&
+ data != 0xff)
+ printf(" %02x=%02x", cmd, data);
+ }
+ printf("\n");
+ }
+ ic->ic_release_bus(ic->ic_cookie, I2C_F_POLL);
}
- ic->ic_release_bus(ic->ic_cookie, I2C_F_POLL);
}
- printf("\n");
}