Subject: Re: support for unconfigured PCI devices, esp. SD card reader
To: Quentin Garnier <cube@cubidou.net>
From: Paul Goyette <paul@whooppee.com>
List: port-i386
Date: 07/29/2007 23:55:12
Here's the code that Nicolas Joly wrote, with slight mod's by me, to 
locate which device addresses respond on the SMBus.  Note that there's 
still no way to figure out what these devices are, only determine if 
they exist or not.

Also, you need to set the bus type.  PAtch for the nForce nfsmb follows.

Index: i2c.c
===================================================================
RCS file: /cvsroot/src/sys/dev/i2c/i2c.c,v
retrieving revision 1.14
diff -u -p -r1.14 i2c.c
--- i2c.c	9 Jul 2007 21:00:32 -0000	1.14
+++ i2c.c	30 Jul 2007 06:51:43 -0000
@@ -109,8 +109,11 @@ iic_attach(struct device *parent, struct
  {
  	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
  	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.

Index: nfsmb.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/nfsmb.c,v
retrieving revision 1.3
diff -u -p -r1.3 nfsmb.c
--- nfsmb.c     28 Jul 2007 12:31:50 -0000      1.3
+++ nfsmb.c     30 Jul 2007 06:53:34 -0000
@@ -217,6 +217,7 @@ nfsmb_attach(struct device *parent, stru
                 return;
         }

+       iba.iba_type = I2C_TYPE_SMBUS;
         iba.iba_tag = &sc->sc_i2c;
         (void) config_found_ia(&sc->sc_dev, "i2cbus", &iba, 
iicbus_print);
  }



On Mon, 30 Jul 2007, Quentin Garnier wrote:

> On Mon, Jul 30, 2007 at 01:34:48PM +1000, Daniel Carosone wrote:
>> On Mon, Jul 30, 2007 at 05:29:13AM +0200, Quentin Garnier wrote:
>>> SMBus is a lot like I2C, and you will usually find various kind of
>>> sensors attached there.
>>
>> How?
>
> SMBus can be enumerated;  bug Nicolas Joly, he has code for it
> apparently.
>
> -- 
> Quentin Garnier - cube@cubidou.net - cube@NetBSD.org
> "You could have made it, spitting out benchmarks
> Owe it to yourself not to fail"
> Amplifico, Spitting Out Benchmarks, Hometakes Vol. 2, 2005.
>

----------------------------------------------------------------------
|   Paul Goyette   | PGP DSS Key fingerprint: |  E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 |  paul@whooppee.com   |
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette@juniper.net |
----------------------------------------------------------------------