For SMBus, add the ability to enumerate devices on the bus.

This does NOT identify the devices, merely indicates the
presence of devices at certain addresses.  Tested on ichsmb
and nfsmb - other SMBus devices will need to ensure the
proper bus type is set. (I2C_TYPE_SMBUS)

From Nicolas Joly, via Paul Goyette, in PR#36744.
This commit is contained in:
riz 2007-09-01 22:19:25 +00:00
parent eb606989ed
commit a550eae132
3 changed files with 28 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: i2c.c,v 1.14 2007/07/09 21:00:32 ad Exp $ */
/* $NetBSD: i2c.c,v 1.15 2007/09/01 22:19:25 riz Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@ -109,8 +109,11 @@ iic_attach(struct device *parent, struct device *self, void *aux)
{
struct iic_softc *sc = device_private(self);
struct i2cbus_attach_args *iba = aux;
i2c_addr_t addr;
i2c_tag_t ic;
int rv;
int found = 0;
uint8_t cmd = 0, val;
aprint_naive(": I2C bus\n");
aprint_normal(": I2C bus\n");
@ -128,6 +131,24 @@ iic_attach(struct device *parent, struct device *self, void *aux)
if (rv)
printf("%s: unable to create intr thread\n", ic->ic_devname);
if (sc->sc_type == I2C_TYPE_SMBUS) {
for (addr = 0x0; addr < 0x80; addr++) {
iic_acquire_bus(ic, 0);
if (iic_exec(ic, I2C_OP_READ_WITH_STOP, addr,
&cmd, 1, &val, 1, 0) == 0) {
if (found == 0)
aprint_normal("%s: devices at",
ic->ic_devname);
found++;
aprint_normal(" 0x%02x", addr);
}
iic_release_bus(ic, 0);
}
if (found == 0)
aprint_normal("%s: no devices found", ic->ic_devname);
aprint_normal("\n");
}
/*
* Attach all i2c devices described in the kernel
* configuration file.

View File

@ -1,4 +1,4 @@
/* $NetBSD: ichsmb.c,v 1.8 2007/08/27 15:57:14 xtraeme Exp $ */
/* $NetBSD: ichsmb.c,v 1.9 2007/09/01 22:19:25 riz Exp $ */
/* $OpenBSD: ichiic.c,v 1.18 2007/05/03 09:36:26 dlg Exp $ */
/*
@ -22,7 +22,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ichsmb.c,v 1.8 2007/08/27 15:57:14 xtraeme Exp $");
__KERNEL_RCSID(0, "$NetBSD: ichsmb.c,v 1.9 2007/09/01 22:19:25 riz Exp $");
#include <sys/param.h>
#include <sys/device.h>
@ -171,6 +171,7 @@ ichsmb_attach(struct device *parent, struct device *self, void *aux)
sc->sc_i2c_tag.ic_exec = ichsmb_i2c_exec;
bzero(&iba, sizeof(iba));
iba.iba_type = I2C_TYPE_SMBUS;
iba.iba_tag = &sc->sc_i2c_tag;
config_found(self, &iba, iicbus_print);

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfsmb.c,v 1.5 2007/08/27 15:57:13 xtraeme Exp $ */
/* $NetBSD: nfsmb.c,v 1.6 2007/09/01 22:19:25 riz Exp $ */
/*
* Copyright (c) 2007 KIYOHARA Takashi
* All rights reserved.
@ -26,7 +26,7 @@
*
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nfsmb.c,v 1.5 2007/08/27 15:57:13 xtraeme Exp $");
__KERNEL_RCSID(0, "$NetBSD: nfsmb.c,v 1.6 2007/09/01 22:19:25 riz Exp $");
#include <sys/param.h>
#include <sys/device.h>
@ -217,6 +217,7 @@ nfsmb_attach(struct device *parent, struct device *self, void *aux)
return;
}
iba.iba_type = I2C_TYPE_SMBUS;
iba.iba_tag = &sc->sc_i2c;
(void) config_found_ia(&sc->sc_dev, "i2cbus", &iba, iicbus_print);
}