diff options
Diffstat (limited to 'sys/dev/smbus')
-rw-r--r-- | sys/dev/smbus/smb.c | 50 | ||||
-rw-r--r-- | sys/dev/smbus/smbconf.c | 60 | ||||
-rw-r--r-- | sys/dev/smbus/smbconf.h | 10 | ||||
-rw-r--r-- | sys/dev/smbus/smbus.c | 49 | ||||
-rw-r--r-- | sys/dev/smbus/smbus_if.m | 19 |
5 files changed, 83 insertions, 105 deletions
diff --git a/sys/dev/smbus/smb.c b/sys/dev/smbus/smb.c index b5d29194430eb..94719fb83ad68 100644 --- a/sys/dev/smbus/smb.c +++ b/sys/dev/smbus/smb.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: smb.c,v 1.5 1999/01/09 18:08:23 nsouch Exp $ + * $Id: smb.c,v 1.2 1998/09/04 17:53:42 nsouch Exp $ * */ #include <sys/param.h> @@ -119,6 +119,8 @@ smb_probe(device_t dev) static int smb_attach(device_t dev) { + struct smb_softc *sc = (struct smb_softc *)device_get_softc(dev); + return (0); } @@ -157,9 +159,24 @@ smbclose(dev_t dev, int flags, int fmt, struct proc *p) static int smbwrite(dev_t dev, struct uio * uio, int ioflag) { - /* not supported */ + device_t smbdev = IIC_DEVICE(minor(dev)); + struct smb_softc *sc = IIC_SOFTC(minor(dev)); + int error, count; - return (EINVAL); + if (!sc || !smbdev) + return (EINVAL); + + if (sc->sc_count == 0) + return (EINVAL); + + count = min(uio->uio_resid, BUFSIZE); + uiomove(sc->sc_buffer, count, uio); + + /* we consider the command char as the first character to send */ + smbus_bwrite(device_get_parent(smbdev), sc->sc_addr, + sc->sc_buffer[0], count-1, sc->sc_buffer+1); + + return (0); } static int @@ -180,62 +197,65 @@ smbioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p) int error = 0; struct smbcmd *s = (struct smbcmd *)data; - if (!sc || !s) + if (!sc) return (EINVAL); switch (cmd) { case SMB_QUICK_WRITE: - error=smbus_quick(parent, s->slave, SMB_QWRITE); + smbus_quick(parent, sc->sc_addr, SMB_QWRITE); goto end; case SMB_QUICK_READ: - error=smbus_quick(parent, s->slave, SMB_QREAD); + smbus_quick(parent, sc->sc_addr, SMB_QREAD); goto end; }; + if (!s) + return (EINVAL); + switch (cmd) { case SMB_SENDB: - error=smbus_sendb(parent, s->slave, s->cmd); + smbus_sendb(parent, sc->sc_addr, s->cmd); break; case SMB_RECVB: - error=smbus_recvb(parent, s->slave, &s->cmd); + smbus_recvb(parent, sc->sc_addr, &s->cmd); break; case SMB_WRITEB: - error=smbus_writeb(parent, s->slave, s->cmd, s->data.byte); + smbus_writeb(parent, sc->sc_addr, s->cmd, s->data.byte); break; case SMB_WRITEW: - error=smbus_writew(parent, s->slave, s->cmd, s->data.word); + smbus_writew(parent, sc->sc_addr, s->cmd, s->data.word); break; case SMB_READB: if (s->data.byte_ptr) - error=smbus_readb(parent, s->slave, s->cmd, + smbus_readb(parent, sc->sc_addr, s->cmd, s->data.byte_ptr); break; case SMB_READW: if (s->data.word_ptr) - error=smbus_readw(parent, s->slave, s->cmd, s->data.word_ptr); + smbus_readw(parent, sc->sc_addr, s->cmd, s->data.word_ptr); break; case SMB_PCALL: if (s->data.process.rdata) - error=smbus_pcall(parent, s->slave, s->cmd, + smbus_pcall(parent, sc->sc_addr, s->cmd, s->data.process.sdata, s->data.process.rdata); break; case SMB_BWRITE: if (s->count && s->data.byte_ptr) - error=smbus_bwrite(parent, s->slave, s->cmd, s->count, + smbus_bwrite(parent, sc->sc_addr, s->cmd, s->count, s->data.byte_ptr); break; case SMB_BREAD: if (s->count && s->data.byte_ptr) - error=smbus_bread(parent, s->slave, s->cmd, s->count, + smbus_bread(parent, sc->sc_addr, s->cmd, s->count, s->data.byte_ptr); break; diff --git a/sys/dev/smbus/smbconf.c b/sys/dev/smbus/smbconf.c index 458916f8e8e8e..60798f5c82ddb 100644 --- a/sys/dev/smbus/smbconf.c +++ b/sys/dev/smbus/smbconf.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: smbconf.c,v 1.3 1998/11/22 22:01:42 nsouch Exp $ + * $Id: smbconf.c,v 1.1.1.2 1998/08/13 15:16:57 son Exp $ * */ #include <sys/param.h> @@ -65,29 +65,10 @@ smbus_alloc_bus(device_t parent) /* add the bus to the parent */ child = device_add_child(parent, "smbus", -1, NULL); - return (child); -} - -static int -smbus_poll(struct smbus_softc *sc, int how) -{ - int error; - - switch (how) { - case (SMB_WAIT | SMB_INTR): - error = tsleep(sc, SMBPRI|PCATCH, "smbreq", 0); - break; - - case (SMB_WAIT | SMB_NOINTR): - error = tsleep(sc, SMBPRI, "smbreq", 0); - break; - - default: - return (EWOULDBLOCK); - break; - } + if (child) + device_set_desc(child, "System Management Bus"); - return (error); + return (child); } /* @@ -103,20 +84,25 @@ smbus_request_bus(device_t bus, device_t dev, int how) struct smbus_softc *sc = (struct smbus_softc *)device_get_softc(bus); int s, error = 0; - /* first, ask the underlying layers if the request is ok */ - do { - error = SMBUS_CALLBACK(device_get_parent(bus), - SMB_REQUEST_BUS, (caddr_t)&how); - if (error) - error = smbus_poll(sc, how); - } while (error); - while (!error) { s = splhigh(); if (sc->owner) { splx(s); - error = smbus_poll(sc, how); + switch (how) { + case (SMB_WAIT | SMB_INTR): + error = tsleep(sc, SMBPRI|PCATCH, "smbreq", 0); + break; + + case (SMB_WAIT | SMB_NOINTR): + error = tsleep(sc, SMBPRI, "smbreq", 0); + break; + + default: + return (EWOULDBLOCK); + break; + } + } else { sc->owner = dev; @@ -137,13 +123,7 @@ int smbus_release_bus(device_t bus, device_t dev) { struct smbus_softc *sc = (struct smbus_softc *)device_get_softc(bus); - int s, error; - - /* first, ask the underlying layers if the release is ok */ - error = SMBUS_CALLBACK(device_get_parent(bus), SMB_RELEASE_BUS, NULL); - - if (error) - return (error); + int s; s = splhigh(); if (sc->owner != dev) { @@ -168,7 +148,7 @@ smbus_release_bus(device_t bus, device_t dev) u_char smbus_get_addr(device_t dev) { - uintptr_t addr; + u_long addr; device_t parent = device_get_parent(dev); BUS_READ_IVAR(parent, dev, SMBUS_IVAR_ADDR, &addr); diff --git a/sys/dev/smbus/smbconf.h b/sys/dev/smbus/smbconf.h index 0a442ec9633ae..10fc3bcb011ca 100644 --- a/sys/dev/smbus/smbconf.h +++ b/sys/dev/smbus/smbconf.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: smbconf.h,v 1.1.1.1 1998/09/03 20:52:54 nsouch Exp $ + * $Id: smbconf.h,v 1.1.1.2 1998/08/13 15:16:58 son Exp $ */ #ifndef __SMBONF_H #define __SMBONF_H @@ -43,18 +43,10 @@ #define SMB_INTR 0x2 /* - * callback index - */ -#define SMB_REQUEST_BUS 0x1 -#define SMB_RELEASE_BUS 0x2 - -/* * SMB bus errors */ #define SMB_ENOERR 0x0 #define SMB_EBUSERR 0x1 -#define SMB_ENOTSUPP 0x2 -#define SMB_ENOACK 0x3 /* * How Quick command is executed diff --git a/sys/dev/smbus/smbus.c b/sys/dev/smbus/smbus.c index ca067103c43e3..f9f787d3a4719 100644 --- a/sys/dev/smbus/smbus.c +++ b/sys/dev/smbus/smbus.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: smbus.c,v 1.6 1998/12/28 19:07:51 nsouch Exp $ + * $Id: smbus.c,v 1.1.1.2 1998/08/13 15:16:58 son Exp $ * */ #include <sys/param.h> @@ -46,6 +46,7 @@ */ struct smbus_device { const char *smbd_name; /* device name */ + const u_char smbd_addr; /* address of the device */ const char *smbd_desc; /* device descriptor */ }; @@ -53,7 +54,7 @@ struct smbus_device { * list of known devices */ struct smbus_device smbus_children[] = { - { "smb", "SMBus general purpose I/O" }, + { "smb", 0, "General Call" }, { NULL, 0 } }; @@ -65,10 +66,7 @@ static devclass_t smbus_devclass; static int smbus_probe(device_t); static int smbus_attach(device_t); static void smbus_print_child(device_t, device_t); - -#if 0 static int smbus_read_ivar(device_t , device_t, int, u_long *); -#endif static device_method_t smbus_methods[] = { /* device interface */ @@ -79,8 +77,10 @@ static device_method_t smbus_methods[] = { /* bus interface */ DEVMETHOD(bus_print_child, smbus_print_child), - DEVMETHOD(bus_read_ivar, bus_generic_read_ivar), + DEVMETHOD(bus_read_ivar, smbus_read_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 } }; @@ -100,7 +100,14 @@ static driver_t smbus_driver = { static int smbus_probe(device_t dev) { - device_set_desc(dev, "System Management Bus"); + struct smbus_device *smbdev; + device_t child; + + for (smbdev = smbus_children; smbdev->smbd_name; smbdev++) { + + child = device_add_child(dev, smbdev->smbd_name, -1, smbdev); + device_set_desc(child, smbdev->smbd_desc); + } return (0); } @@ -108,20 +115,10 @@ smbus_probe(device_t dev) static int smbus_attach(device_t dev) { - struct smbus_device *smbdev; + struct smbus_softc *sc = device_get_softc(dev); + device_t parent = device_get_parent(dev); - /* 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, smbdev); - device_set_desc(child, smbdev->smbd_desc); - } else if (bootverbose) - printf("smbus: %s devclass not found\n", - smbdev->smbd_name); - } + printf("Probing for devices on the SMB bus:\n"); bus_generic_attach(dev); return (0); @@ -136,27 +133,25 @@ smbus_generic_intr(device_t dev, u_char devaddr, char low, char high) static void smbus_print_child(device_t bus, device_t dev) { + struct smbus_device* smbdev = DEVTOSMBUS(dev); - printf(" on %s%d", device_get_name(bus), device_get_unit(bus)); + printf(" on %s%d addr 0x%x", device_get_name(bus), + device_get_unit(bus), smbdev->smbd_addr); return; } -#if 0 static int smbus_read_ivar(device_t bus, device_t dev, int index, u_long* result) { struct smbus_device* smbdev = DEVTOSMBUS(dev); switch (index) { - default: + case SMBUS_IVAR_ADDR: + *result = smbdev->smbd_addr; break; } return (ENOENT); } -#endif DRIVER_MODULE(smbus, iicsmb, smbus_driver, smbus_devclass, 0, 0); -DRIVER_MODULE(smbus, bti2c, smbus_driver, smbus_devclass, 0, 0); -DRIVER_MODULE(smbus, intsmb, smbus_driver, smbus_devclass, 0, 0); -DRIVER_MODULE(smbus, smbv, smbus_driver, smbus_devclass, 0, 0); diff --git a/sys/dev/smbus/smbus_if.m b/sys/dev/smbus/smbus_if.m index 3e118811b5b06..3c9ee5a0ecc1d 100644 --- a/sys/dev/smbus/smbus_if.m +++ b/sys/dev/smbus/smbus_if.m @@ -23,13 +23,13 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# $Id: smbus_if.m,v 1.3 1998/11/07 14:56:04 nsouch Exp $ +# $Id: smbus_if.m,v 1.1.1.2 1998/08/13 15:16:58 son Exp $ # -INTERFACE smbus; +INTERFACE smbus # -# Interpret interrupt +# Interprete interrupt # METHOD void intr { device_t dev; @@ -40,15 +40,6 @@ METHOD void intr { }; # -# smbus callback -# -METHOD int callback { - device_t dev; - int index; - caddr_t data; -}; - -# # Quick command # METHOD int quick { @@ -129,7 +120,7 @@ METHOD int pcall { # # Block Write command # -METHOD int bwrite { +METHODE int bwrite { device_t dev; u_char slave; char cmd; @@ -140,7 +131,7 @@ METHOD int bwrite { # # Block Read command # -METHOD int bread { +METHODE int bread { device_t dev; u_char slave; char cmd; |