aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/iicbus/iicbus.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/iicbus/iicbus.c')
-rw-r--r--sys/dev/iicbus/iicbus.c147
1 files changed, 37 insertions, 110 deletions
diff --git a/sys/dev/iicbus/iicbus.c b/sys/dev/iicbus/iicbus.c
index cf9f6ba5ac26..41a0cea4f01c 100644
--- a/sys/dev/iicbus/iicbus.c
+++ b/sys/dev/iicbus/iicbus.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: iicbus.c,v 1.6 1998/12/07 21:58:16 archie Exp $
+ * $Id: iicbus.c,v 1.1.2.7 1998/08/29 16:54:16 son Exp $
*
*/
@@ -54,7 +54,6 @@ struct iicbus_device {
int iicd_class; /* driver or slave device class */
const char *iicd_desc; /* device descriptor */
u_char iicd_addr; /* address of the device */
- int iicd_waitack; /* wait for ack timeout or delay */
int iicd_alive; /* 1 if device found */
};
@@ -62,10 +61,10 @@ struct iicbus_device {
* Common I2C addresses
*/
#define I2C_GENERAL_CALL 0x0
-#define PCF_MASTER_ADDRESS 0xaa
-#define FIRST_SLAVE_ADDR 0x2
+#define I2C_MASTER_ADDRESS 0xaa
+#define I2C_INET_ADDRESS 0xaa
-#define LAST_SLAVE_ADDR 255
+#define MAXSLAVE 256
#define IICBUS_UNKNOWN_CLASS 0
#define IICBUS_DEVICE_CLASS 1
@@ -73,15 +72,13 @@ struct iicbus_device {
/*
* list of known devices
- *
- * XXX only one smb driver should exist for each I2C interface
*/
struct iicbus_device iicbus_children[] = {
+ { "iic", IICBUS_DRIVER_CLASS, "General Call", I2C_GENERAL_CALL },
{ "iicsmb", IICBUS_DRIVER_CLASS, "I2C to SMB bridge" },
- { "iic", IICBUS_DRIVER_CLASS, "I2C general purpose I/O" },
-#if 0
- { "ic", IICBUS_DEVICE_CLASS, "network interface", PCF_MASTER_ADDRESS },
-#endif
+ { "iic", IICBUS_DEVICE_CLASS, "PCF8574 I2C to 8 bits parallel i/o", 64},
+ { "iic", IICBUS_DEVICE_CLASS, "PCF8584 as slave", I2C_MASTER_ADDRESS },
+ { "ic", IICBUS_DEVICE_CLASS, "network interface", I2C_INET_ADDRESS },
{ NULL, 0 }
};
@@ -94,7 +91,6 @@ static int iicbus_probe(device_t);
static int iicbus_attach(device_t);
static void iicbus_print_child(device_t, device_t);
static int iicbus_read_ivar(device_t , device_t, int, u_long *);
-static int iicbus_write_ivar(device_t , device_t, int, u_long);
static device_method_t iicbus_methods[] = {
/* device interface */
@@ -106,7 +102,9 @@ static device_method_t iicbus_methods[] = {
/* bus interface */
DEVMETHOD(bus_print_child, iicbus_print_child),
DEVMETHOD(bus_read_ivar, iicbus_read_ivar),
- DEVMETHOD(bus_write_ivar, iicbus_write_ivar),
+ DEVMETHOD(bus_write_ivar, bus_generic_write_ivar),
+ DEVMETHOD(bus_create_intr, bus_generic_create_intr),
+ DEVMETHOD(bus_connect_intr, bus_generic_connect_intr),
{ 0, 0 }
};
@@ -118,118 +116,59 @@ static driver_t iicbus_driver = {
sizeof(struct iicbus_softc),
};
-static int
-iicbus_probe(device_t dev)
-{
- device_set_desc(dev, "Philips I2C bus");
-
- return (0);
-}
-
-#if 0
-static int
-iic_probe_device(device_t dev, u_char addr)
-{
- int count;
- char byte;
-
- if ((addr & 1) == 0) {
- /* is device writable? */
- if (!iicbus_start(dev, (u_char)addr, 0)) {
- iicbus_stop(dev);
- return (1);
- }
- } else {
- /* is device readable? */
- if (!iicbus_block_read(dev, (u_char)addr, &byte, 1, &count))
- return (1);
- }
-
- return (0);
-}
-#endif
-
/*
- * We add all the devices which we know about.
- * The generic attach routine will attach them if they are alive.
+ * At 'probe' time, we add all the devices which we know about to the
+ * bus. The generic attach routine will probe and attach them if they
+ * are alive.
*/
static int
-iicbus_attach(device_t dev)
+iicbus_probe(device_t dev)
{
+ struct iicbus_softc *sc = device_get_softc(dev);
struct iicbus_device *iicdev;
device_t child;
- iicbus_reset(dev, IIC_FASTEST, 0, NULL);
+ /* XXX should query parent */
+ sc->ownaddr = I2C_MASTER_ADDRESS;
- /* device probing is meaningless since the bus is supposed to be
- * hot-plug. Moreover, some I2C chips do not appreciate random
- * accesses like stop after start to fast, reads for less than
- * x bytes...
- */
-#if 0
- printf("Probing for devices on iicbus%d:", device_get_unit(dev));
+ iicbus_reset(dev, IIC_FASTEST);
- /* probe any devices */
- for (addr = FIRST_SLAVE_ADDR; addr <= LAST_SLAVE_ADDR; addr++) {
- if (iic_probe_device(dev, (u_char)addr)) {
- printf(" <%x>", addr);
- }
- }
- printf("\n");
-#endif
-
- /* attach known devices */
for (iicdev = iicbus_children; iicdev->iicd_name; iicdev++) {
+
+ /* probe devices, not drivers */
switch (iicdev->iicd_class) {
case IICBUS_DEVICE_CLASS:
- /* check if the devclass exists */
- if (devclass_find(iicdev->iicd_name))
+ if (!iicbus_start(dev, iicdev->iicd_addr)) {
+ iicbus_stop(dev);
iicdev->iicd_alive = 1;
- else if (bootverbose)
- printf("iicbus: %s devclass not found\n",
- iicdev->iicd_name);
+ }
break;
-
case IICBUS_DRIVER_CLASS:
- /* check if the devclass exists */
- if (devclass_find(iicdev->iicd_name))
- iicdev->iicd_alive = 1;
- else if (bootverbose)
- printf("iicbus: %s devclass not found\n",
- iicdev->iicd_name);
+ iicdev->iicd_addr = sc->ownaddr;
break;
-
default:
panic("%s: unknown class!", __FUNCTION__);
}
- if (iicdev->iicd_alive) {
- child = device_add_child(dev, iicdev->iicd_name,
- -1, iicdev);
- device_set_desc(child, iicdev->iicd_desc);
- }
+ child = device_add_child(dev, iicdev->iicd_name, -1, iicdev);
+ device_set_desc(child, iicdev->iicd_desc);
}
- bus_generic_attach(dev);
-
- return (0);
-}
-int
-iicbus_generic_intr(device_t dev, int event, char *buf)
-{
return (0);
}
-int
-iicbus_null_callback(device_t dev, int index, caddr_t data)
+static int
+iicbus_attach(device_t dev)
{
- return (0);
+ bus_generic_attach(dev);
+
+ return (0);
}
int
-iicbus_null_repeated_start(device_t dev, u_char addr)
+iicbus_generic_intr(device_t dev, int event, char *buf)
{
- return (IIC_ENOTSUPP);
+ return (0);
}
static void
@@ -239,8 +178,9 @@ iicbus_print_child(device_t bus, device_t dev)
switch (iicdev->iicd_class) {
case IICBUS_DEVICE_CLASS:
- printf(" on %s%d addr 0x%x", device_get_name(bus),
- device_get_unit(bus), iicdev->iicd_addr);
+ printf(" on %s%d addr %d %s", device_get_name(bus),
+ device_get_unit(bus), iicdev->iicd_addr,
+ (iicdev->iicd_alive) ? "found" : "not found");
break;
case IICBUS_DRIVER_CLASS:
@@ -272,17 +212,4 @@ iicbus_read_ivar(device_t bus, device_t dev, int index, u_long* result)
return (0);
}
-static int
-iicbus_write_ivar(device_t bus, device_t dev, int index, u_long val)
-{
- switch (index) {
- default:
- return (ENOENT);
- }
-
- return (0);
-}
-
DRIVER_MODULE(iicbus, pcf, iicbus_driver, iicbus_devclass, 0, 0);
-DRIVER_MODULE(iicbus, iicbb, iicbus_driver, iicbus_devclass, 0, 0);
-DRIVER_MODULE(iicbus, bti2c, iicbus_driver, iicbus_devclass, 0, 0);