diff options
author | nsouch <nsouch@FreeBSD.org> | 2002-03-23 15:49:15 +0000 |
---|---|---|
committer | nsouch <nsouch@FreeBSD.org> | 2002-03-23 15:49:15 +0000 |
commit | 82395b7295123f4d9a786ebd89495ef101103a61 (patch) | |
tree | f78e24d69b8d02162ae886a610fb85cac8989741 /sys/dev/smbus | |
parent | 0dcefe7b55beecbfaeba7c0b20e4b1277b781733 (diff) | |
download | FreeBSD-src-82395b7295123f4d9a786ebd89495ef101103a61.zip FreeBSD-src-82395b7295123f4d9a786ebd89495ef101103a61.tar.gz |
Major rework of the iicbus/smbus framework:
- VIA chipset SMBus controllers added
- alpm driver updated
- Support for dynamic modules added
- bktr FreeBSD smbus updated but not tested
- cleanup
Diffstat (limited to 'sys/dev/smbus')
-rw-r--r-- | sys/dev/smbus/smb.c | 54 | ||||
-rw-r--r-- | sys/dev/smbus/smbconf.c | 34 | ||||
-rw-r--r-- | sys/dev/smbus/smbconf.h | 5 | ||||
-rw-r--r-- | sys/dev/smbus/smbus.c | 74 |
4 files changed, 60 insertions, 107 deletions
diff --git a/sys/dev/smbus/smb.c b/sys/dev/smbus/smb.c index beb3c4a..e07d4b4 100644 --- a/sys/dev/smbus/smb.c +++ b/sys/dev/smbus/smb.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998 Nicolas Souchu + * Copyright (c) 1998, 2001 Nicolas Souchu * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -46,13 +46,8 @@ struct smb_softc { - int sc_addr; /* address on smbus */ int sc_count; /* >0 if device opened */ - - char *sc_cp; /* output buffer pointer */ - - char sc_buffer[BUFSIZE]; /* output buffer */ - char sc_inbuf[BUFSIZE]; /* input buffer */ + dev_t sc_devnode; }; #define IIC_SOFTC(unit) \ @@ -63,13 +58,17 @@ struct smb_softc { static int smb_probe(device_t); static int smb_attach(device_t); +static int smb_detach(device_t); +static void smb_identify(driver_t *driver, device_t parent); static devclass_t smb_devclass; static device_method_t smb_methods[] = { /* device interface */ + DEVMETHOD(device_identify, smb_identify), DEVMETHOD(device_probe, smb_probe), DEVMETHOD(device_attach, smb_attach), + DEVMETHOD(device_detach, smb_detach), /* smbus interface */ DEVMETHOD(smbus_intr, smbus_generic_intr), @@ -106,30 +105,45 @@ static struct cdevsw smb_cdevsw = { /* flags */ 0, }; -/* - * smbprobe() - */ +static void +smb_identify(driver_t *driver, device_t parent) +{ + BUS_ADD_CHILD(parent, 0, "smb", 0); +} + static int smb_probe(device_t dev) { - struct smb_softc *sc = (struct smb_softc *)device_get_softc(dev); - - sc->sc_addr = smbus_get_addr(dev); - - /* XXX detect chip with start/stop conditions */ + device_set_desc(dev, "SMBus generic I/O"); return (0); } -/* - * smbattach() - */ static int smb_attach(device_t dev) { - make_dev(&smb_cdevsw, device_get_unit(dev), /* XXX cleanup */ + struct smb_softc *sc = (struct smb_softc *)device_get_softc(dev); + + if (!sc) + return (ENOMEM); + + bzero(sc, sizeof(struct smb_softc *)); + + sc->sc_devnode = make_dev(&smb_cdevsw, device_get_unit(dev), UID_ROOT, GID_WHEEL, 0600, "smb%d", device_get_unit(dev)); + + return (0); +} + +static int +smb_detach(device_t dev) +{ + struct smb_softc *sc = (struct smb_softc *)device_get_softc(dev); + + if (sc->sc_devnode) + destroy_dev(sc->sc_devnode); + return (0); } @@ -267,3 +281,5 @@ smbioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct thread *td) } DRIVER_MODULE(smb, smbus, smb_driver, smb_devclass, 0, 0); +MODULE_DEPEND(smb, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER); +MODULE_VERSION(smb, 1); diff --git a/sys/dev/smbus/smbconf.c b/sys/dev/smbus/smbconf.c index b91f3d3..9e9a2cb 100644 --- a/sys/dev/smbus/smbconf.c +++ b/sys/dev/smbus/smbconf.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998 Nicolas Souchu + * Copyright (c) 1998, 2001 Nicolas Souchu * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -78,22 +78,6 @@ smbus_error(int smb_error) return (error); } -/* - * smbus_alloc_bus() - * - * Allocate a new bus connected to the given parent device - */ -device_t -smbus_alloc_bus(device_t parent) -{ - device_t child; - - /* add the bus to the parent */ - child = device_add_child(parent, "smbus", -1); - - return (child); -} - static int smbus_poll(struct smbus_softc *sc, int how) { @@ -190,19 +174,3 @@ smbus_release_bus(device_t bus, device_t dev) return (0); } - -/* - * smbus_get_addr() - * - * Get the I2C 7 bits address of the device - */ -u_char -smbus_get_addr(device_t dev) -{ - uintptr_t addr; - device_t parent = device_get_parent(dev); - - BUS_READ_IVAR(parent, dev, SMBUS_IVAR_ADDR, &addr); - - return ((u_char)addr); -} diff --git a/sys/dev/smbus/smbconf.h b/sys/dev/smbus/smbconf.h index 40289f7..64b0a33 100644 --- a/sys/dev/smbus/smbconf.h +++ b/sys/dev/smbus/smbconf.h @@ -101,4 +101,9 @@ extern u_char smbus_get_addr(device_t); #define smbus_bread(bus,slave,cmd,count,buf) \ (SMBUS_BREAD(device_get_parent(bus), slave, cmd, count, buf)) +#define SMBUS_MODVER 1 +#define SMBUS_MINVER 1 +#define SMBUS_MAXVER 1 +#define SMBUS_PREFVER SMBUS_MODVER + #endif diff --git a/sys/dev/smbus/smbus.c b/sys/dev/smbus/smbus.c index 4650608..99b7ca3 100644 --- a/sys/dev/smbus/smbus.c +++ b/sys/dev/smbus/smbus.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998 Nicolas Souchu + * Copyright (c) 1998, 2001 Nicolas Souchu * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -41,22 +41,6 @@ #define DEVTOSMBUS(dev) ((struct smbus_device*)device_get_ivars(dev)) -/* - * structure used to attach devices to the I2C bus - */ -struct smbus_device { - const char *smbd_name; /* device name */ - const char *smbd_desc; /* device descriptor */ -}; - -/* - * list of known devices - */ -struct smbus_device smbus_children[] = { - { "smb", "SMBus general purpose I/O" }, - { NULL, 0 } -}; - static devclass_t smbus_devclass; /* @@ -64,22 +48,17 @@ static devclass_t smbus_devclass; */ static int smbus_probe(device_t); static int smbus_attach(device_t); - -#if 0 -static int smbus_read_ivar(device_t , device_t, int, u_long *); -#endif +static int smbus_add_child(device_t dev, int order, const char *name, int unit); static device_method_t smbus_methods[] = { /* device interface */ DEVMETHOD(device_probe, smbus_probe), DEVMETHOD(device_attach, smbus_attach), DEVMETHOD(device_detach, bus_generic_detach), - DEVMETHOD(device_shutdown, bus_generic_shutdown), /* bus interface */ + DEVMETHOD(bus_add_child, smbus_add_child), DEVMETHOD(bus_print_child, bus_generic_print_child), - DEVMETHOD(bus_read_ivar, bus_generic_read_ivar), - DEVMETHOD(bus_write_ivar, bus_generic_write_ivar), { 0, 0 } }; @@ -106,48 +85,33 @@ smbus_probe(device_t dev) static int smbus_attach(device_t dev) { - struct smbus_device *smbdev; - - /* add known devices */ - for (smbdev = smbus_children; smbdev->smbd_name; smbdev++) { - device_t child; - - if (devclass_find(smbdev->smbd_name)) { - child = device_add_child(dev, smbdev->smbd_name, -1); - device_set_ivars(child, smbdev); - device_set_desc(child, smbdev->smbd_desc); - } else if (bootverbose) - printf("smbus: %s devclass not found\n", - smbdev->smbd_name); - } + device_add_child(dev, NULL, -1); bus_generic_attach(dev); return (0); } -void -smbus_generic_intr(device_t dev, u_char devaddr, char low, char high) +static int +smbus_add_child(device_t dev, int order, const char *name, int unit) { - return; + device_add_child_ordered(dev, order, name, unit); + + bus_generic_attach(dev); + + return (0); } -#if 0 -static int -smbus_read_ivar(device_t bus, device_t dev, int index, u_long* result) +void +smbus_generic_intr(device_t dev, u_char devaddr, char low, char high) { - struct smbus_device* smbdev = DEVTOSMBUS(dev); - - switch (index) { - default: - break; - } - return (ENOENT); + return; } -#endif DRIVER_MODULE(smbus, iicsmb, smbus_driver, smbus_devclass, 0, 0); -DRIVER_MODULE(smbus, bti2c, smbus_driver, smbus_devclass, 0, 0); +DRIVER_MODULE(smbus, bktr, smbus_driver, smbus_devclass, 0, 0); DRIVER_MODULE(smbus, intsmb, smbus_driver, smbus_devclass, 0, 0); -DRIVER_MODULE(smbus, alsmb, smbus_driver, smbus_devclass, 0, 0); +DRIVER_MODULE(smbus, alpm, smbus_driver, smbus_devclass, 0, 0); DRIVER_MODULE(smbus, ichsmb, smbus_driver, smbus_devclass, 0, 0); -DRIVER_MODULE(smbus, amdsmb, smbus_driver, smbus_devclass, 0, 0); +DRIVER_MODULE(smbus, amdpm, smbus_driver, smbus_devclass, 0, 0); +DRIVER_MODULE(smbus, viapropm, smbus_driver, smbus_devclass, 0, 0); +MODULE_VERSION(smbus, SMBUS_MODVER); |