Submitted by: nsouch
System Management Bus generic support over new bus architecture.
This commit is contained in:
parent
c3e2dc6b48
commit
d70424edcb
287
sys/dev/smbus/smb.c
Normal file
287
sys/dev/smbus/smb.c
Normal file
@ -0,0 +1,287 @@
|
||||
/*-
|
||||
* Copyright (c) 1998 Nicolas Souchu
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: smb.c,v 1.1.2.1 1998/08/13 15:15:19 son Exp $
|
||||
*
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/buf.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <machine/clock.h>
|
||||
|
||||
#include <dev/smbus/smbconf.h>
|
||||
#include <dev/smbus/smbus.h>
|
||||
#include <machine/smb.h>
|
||||
|
||||
#include "smbus_if.h"
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
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 */
|
||||
};
|
||||
|
||||
#define IIC_SOFTC(unit) \
|
||||
((struct smb_softc *)devclass_get_softc(smb_devclass, (unit)))
|
||||
|
||||
#define IIC_DEVICE(unit) \
|
||||
(devclass_get_device(smb_devclass, (unit)))
|
||||
|
||||
static int smb_probe(device_t);
|
||||
static int smb_attach(device_t);
|
||||
|
||||
static devclass_t smb_devclass;
|
||||
|
||||
static device_method_t smb_methods[] = {
|
||||
/* device interface */
|
||||
DEVMETHOD(device_probe, smb_probe),
|
||||
DEVMETHOD(device_attach, smb_attach),
|
||||
|
||||
/* smbus interface */
|
||||
DEVMETHOD(smbus_intr, smbus_generic_intr),
|
||||
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
static driver_t smb_driver = {
|
||||
"smb",
|
||||
smb_methods,
|
||||
DRIVER_TYPE_MISC,
|
||||
sizeof(struct smb_softc),
|
||||
};
|
||||
|
||||
static d_open_t smbopen;
|
||||
static d_close_t smbclose;
|
||||
static d_write_t smbwrite;
|
||||
static d_read_t smbread;
|
||||
static d_ioctl_t smbioctl;
|
||||
|
||||
#define CDEV_MAJOR 73
|
||||
static struct cdevsw smb_cdevsw =
|
||||
{ smbopen, smbclose, smbread, smbwrite, /*73*/
|
||||
smbioctl, nullstop, nullreset, nodevtotty, /*smb*/
|
||||
seltrue, nommap, nostrat, "smb", NULL, -1 };
|
||||
|
||||
/*
|
||||
* smbprobe()
|
||||
*/
|
||||
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 */
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* smbattach()
|
||||
*/
|
||||
static int
|
||||
smb_attach(device_t dev)
|
||||
{
|
||||
struct smb_softc *sc = (struct smb_softc *)device_get_softc(dev);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
smbopen (dev_t dev, int flags, int fmt, struct proc *p)
|
||||
{
|
||||
struct smb_softc *sc = IIC_SOFTC(minor(dev));
|
||||
|
||||
if (!sc)
|
||||
return (EINVAL);
|
||||
|
||||
if (sc->sc_count)
|
||||
return (EBUSY);
|
||||
|
||||
sc->sc_count++;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
smbclose(dev_t dev, int flags, int fmt, struct proc *p)
|
||||
{
|
||||
struct smb_softc *sc = IIC_SOFTC(minor(dev));
|
||||
|
||||
if (!sc)
|
||||
return (EINVAL);
|
||||
|
||||
if (!sc->sc_count)
|
||||
return (EINVAL);
|
||||
|
||||
sc->sc_count--;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
smbwrite(dev_t dev, struct uio * uio, int ioflag)
|
||||
{
|
||||
device_t smbdev = IIC_DEVICE(minor(dev));
|
||||
struct smb_softc *sc = IIC_SOFTC(minor(dev));
|
||||
int error, count;
|
||||
|
||||
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
|
||||
smbread(dev_t dev, struct uio * uio, int ioflag)
|
||||
{
|
||||
/* not supported */
|
||||
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
static int
|
||||
smbioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
|
||||
{
|
||||
device_t smbdev = IIC_DEVICE(minor(dev));
|
||||
struct smb_softc *sc = IIC_SOFTC(minor(dev));
|
||||
device_t parent = device_get_parent(smbdev);
|
||||
|
||||
int error = 0;
|
||||
struct smbcmd *s = (struct smbcmd *)data;
|
||||
|
||||
if (!sc)
|
||||
return (EINVAL);
|
||||
|
||||
switch (cmd) {
|
||||
case SMB_QUICK_WRITE:
|
||||
smbus_quick(parent, sc->sc_addr, SMB_QWRITE);
|
||||
goto end;
|
||||
|
||||
case SMB_QUICK_READ:
|
||||
smbus_quick(parent, sc->sc_addr, SMB_QREAD);
|
||||
goto end;
|
||||
};
|
||||
|
||||
if (!s)
|
||||
return (EINVAL);
|
||||
|
||||
switch (cmd) {
|
||||
case SMB_SENDB:
|
||||
smbus_sendb(parent, sc->sc_addr, s->cmd);
|
||||
break;
|
||||
|
||||
case SMB_RECVB:
|
||||
smbus_recvb(parent, sc->sc_addr, &s->cmd);
|
||||
break;
|
||||
|
||||
case SMB_WRITEB:
|
||||
smbus_writeb(parent, sc->sc_addr, s->cmd, s->data.byte);
|
||||
break;
|
||||
|
||||
case SMB_WRITEW:
|
||||
smbus_writew(parent, sc->sc_addr, s->cmd, s->data.word);
|
||||
break;
|
||||
|
||||
case SMB_READB:
|
||||
if (s->data.byte_ptr)
|
||||
smbus_readb(parent, sc->sc_addr, s->cmd,
|
||||
s->data.byte_ptr);
|
||||
break;
|
||||
|
||||
case SMB_READW:
|
||||
if (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)
|
||||
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)
|
||||
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)
|
||||
smbus_bread(parent, sc->sc_addr, s->cmd, s->count,
|
||||
s->data.byte_ptr);
|
||||
break;
|
||||
|
||||
default:
|
||||
error = ENODEV;
|
||||
}
|
||||
|
||||
end:
|
||||
return (error);
|
||||
}
|
||||
|
||||
static int smb_devsw_installed = 0;
|
||||
|
||||
static void
|
||||
smb_drvinit(void *unused)
|
||||
{
|
||||
dev_t dev;
|
||||
|
||||
if( ! smb_devsw_installed ) {
|
||||
dev = makedev(CDEV_MAJOR,0);
|
||||
cdevsw_add(&dev,&smb_cdevsw,NULL);
|
||||
smb_devsw_installed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
CDEV_DRIVER_MODULE(smb, smbus, smb_driver, smb_devclass, CDEV_MAJOR,
|
||||
smb_cdevsw, 0, 0);
|
||||
|
||||
SYSINIT(smbdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,smb_drvinit,NULL)
|
157
sys/dev/smbus/smbconf.c
Normal file
157
sys/dev/smbus/smbconf.c
Normal file
@ -0,0 +1,157 @@
|
||||
/*-
|
||||
* Copyright (c) 1998 Nicolas Souchu
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: smbconf.c,v 1.1.1.2 1998/08/13 15:16:57 son Exp $
|
||||
*
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/bus.h>
|
||||
|
||||
#include <dev/smbus/smbconf.h>
|
||||
#include <dev/smbus/smbus.h>
|
||||
#include "smbus_if.h"
|
||||
|
||||
/*
|
||||
* smbus_intr()
|
||||
*/
|
||||
void
|
||||
smbus_intr(device_t bus, u_char devaddr, char low, char high, int error)
|
||||
{
|
||||
struct smbus_softc *sc = (struct smbus_softc *)device_get_softc(bus);
|
||||
|
||||
/* call owner's intr routine */
|
||||
if (sc->owner)
|
||||
SMBUS_INTR(sc->owner, devaddr, low, high, error);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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, NULL);
|
||||
|
||||
if (child)
|
||||
device_set_desc(child, "System Management Bus");
|
||||
|
||||
return (child);
|
||||
}
|
||||
|
||||
/*
|
||||
* smbus_request_bus()
|
||||
*
|
||||
* Allocate the device to perform transfers.
|
||||
*
|
||||
* how : SMB_WAIT or SMB_DONTWAIT
|
||||
*/
|
||||
int
|
||||
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;
|
||||
|
||||
while (!error) {
|
||||
s = splhigh();
|
||||
if (sc->owner) {
|
||||
splx(s);
|
||||
|
||||
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;
|
||||
|
||||
splx(s);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* smbus_release_bus()
|
||||
*
|
||||
* Release the device allocated with smbus_request_dev()
|
||||
*/
|
||||
int
|
||||
smbus_release_bus(device_t bus, device_t dev)
|
||||
{
|
||||
struct smbus_softc *sc = (struct smbus_softc *)device_get_softc(bus);
|
||||
int s;
|
||||
|
||||
s = splhigh();
|
||||
if (sc->owner != dev) {
|
||||
splx(s);
|
||||
return (EACCES);
|
||||
}
|
||||
|
||||
sc->owner = 0;
|
||||
splx(s);
|
||||
|
||||
/* wakeup waiting processes */
|
||||
wakeup(sc);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* smbus_get_addr()
|
||||
*
|
||||
* Get the I2C 7 bits address of the device
|
||||
*/
|
||||
u_char
|
||||
smbus_get_addr(device_t dev)
|
||||
{
|
||||
u_long addr;
|
||||
device_t parent = device_get_parent(dev);
|
||||
|
||||
BUS_READ_IVAR(parent, dev, SMBUS_IVAR_ADDR, &addr);
|
||||
|
||||
return ((u_char)addr);
|
||||
}
|
91
sys/dev/smbus/smbconf.h
Normal file
91
sys/dev/smbus/smbconf.h
Normal file
@ -0,0 +1,91 @@
|
||||
/*-
|
||||
* Copyright (c) 1998 Nicolas Souchu
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: smbconf.h,v 1.1.1.2 1998/08/13 15:16:58 son Exp $
|
||||
*/
|
||||
#ifndef __SMBONF_H
|
||||
#define __SMBONF_H
|
||||
|
||||
#include <sys/queue.h>
|
||||
|
||||
#define SMBPRI PZERO+8 /* XXX sleep/wakeup queue priority */
|
||||
|
||||
#define n(flags) (~(flags) & (flags))
|
||||
|
||||
/*
|
||||
* How tsleep() is called in smb_request_bus().
|
||||
*/
|
||||
#define SMB_DONTWAIT 0
|
||||
#define SMB_NOINTR 0
|
||||
#define SMB_WAIT 0x1
|
||||
#define SMB_INTR 0x2
|
||||
|
||||
/*
|
||||
* SMB bus errors
|
||||
*/
|
||||
#define SMB_ENOERR 0x0
|
||||
#define SMB_EBUSERR 0x1
|
||||
|
||||
/*
|
||||
* How Quick command is executed
|
||||
*/
|
||||
#define SMB_QWRITE 0x0
|
||||
#define SMB_QREAD 0x1
|
||||
|
||||
/*
|
||||
* ivars codes
|
||||
*/
|
||||
#define SMBUS_IVAR_ADDR 0x1 /* I2C address of the device */
|
||||
|
||||
extern int smbus_request_bus(device_t, device_t, int);
|
||||
extern int smbus_release_bus(device_t, device_t);
|
||||
extern device_t smbus_alloc_bus(device_t);
|
||||
|
||||
extern void smbus_intr(device_t, u_char, char low, char high, int error);
|
||||
|
||||
extern u_char smbus_get_addr(device_t);
|
||||
|
||||
#define smbus_quick(bus,slave,how) \
|
||||
(SMBUS_QUICK(device_get_parent(bus), slave, how))
|
||||
#define smbus_sendb(bus,slave,byte) \
|
||||
(SMBUS_SENDB(device_get_parent(bus), slave, byte))
|
||||
#define smbus_recvb(bus,slave,byte) \
|
||||
(SMBUS_RECVB(device_get_parent(bus), slave, byte))
|
||||
#define smbus_writeb(bus,slave,cmd,byte) \
|
||||
(SMBUS_WRITEB(device_get_parent(bus), slave, cmd, byte))
|
||||
#define smbus_writew(bus,slave,cmd,word) \
|
||||
(SMBUS_WRITEW(device_get_parent(bus), slave, cmd, word))
|
||||
#define smbus_readb(bus,slave,cmd,byte) \
|
||||
(SMBUS_READB(device_get_parent(bus), slave, cmd, byte))
|
||||
#define smbus_readw(bus,slave,cmd,word) \
|
||||
(SMBUS_READW(device_get_parent(bus), slave, cmd, word))
|
||||
#define smbus_pcall(bus,slave,cmd,sdata,rdata) \
|
||||
(SMBUS_PCALL(device_get_parent(bus), slave, cmd, sdata, rdata))
|
||||
#define smbus_bwrite(bus,slave,cmd,count,buf) \
|
||||
(SMBUS_BWRITE(device_get_parent(bus), slave, cmd, count, buf))
|
||||
#define smbus_bread(bus,slave,cmd,count,buf) \
|
||||
(SMBUS_BREAD(device_get_parent(bus), slave, cmd, count, buf))
|
||||
|
||||
#endif
|
157
sys/dev/smbus/smbus.c
Normal file
157
sys/dev/smbus/smbus.c
Normal file
@ -0,0 +1,157 @@
|
||||
/*-
|
||||
* Copyright (c) 1998 Nicolas Souchu
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: smbus.c,v 1.1.1.2 1998/08/13 15:16:58 son Exp $
|
||||
*
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/bus.h>
|
||||
|
||||
#include <dev/smbus/smbconf.h>
|
||||
#include <dev/smbus/smbus.h>
|
||||
|
||||
/*
|
||||
* Autoconfiguration and support routines for the Philips serial I2C bus
|
||||
*/
|
||||
|
||||
#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 u_char smbd_addr; /* address of the device */
|
||||
const char *smbd_desc; /* device descriptor */
|
||||
};
|
||||
|
||||
/*
|
||||
* list of known devices
|
||||
*/
|
||||
struct smbus_device smbus_children[] = {
|
||||
{ "smb", 0, "General Call" },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
static devclass_t smbus_devclass;
|
||||
|
||||
/*
|
||||
* Device methods
|
||||
*/
|
||||
static int smbus_probe(device_t);
|
||||
static int smbus_attach(device_t);
|
||||
static void smbus_print_child(device_t, device_t);
|
||||
static int smbus_read_ivar(device_t , device_t, int, u_long *);
|
||||
|
||||
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_print_child, smbus_print_child),
|
||||
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 }
|
||||
};
|
||||
|
||||
static driver_t smbus_driver = {
|
||||
"smbus",
|
||||
smbus_methods,
|
||||
DRIVER_TYPE_MISC,
|
||||
sizeof(struct smbus_softc),
|
||||
};
|
||||
|
||||
/*
|
||||
* 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
|
||||
smbus_probe(device_t dev)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
static int
|
||||
smbus_attach(device_t dev)
|
||||
{
|
||||
struct smbus_softc *sc = device_get_softc(dev);
|
||||
device_t parent = device_get_parent(dev);
|
||||
|
||||
printf("Probing for devices on the SMB bus:\n");
|
||||
bus_generic_attach(dev);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
smbus_generic_intr(device_t dev, u_char devaddr, char low, char high)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
smbus_print_child(device_t bus, device_t dev)
|
||||
{
|
||||
struct smbus_device* smbdev = DEVTOSMBUS(dev);
|
||||
|
||||
printf(" on %s%d addr 0x%x", device_get_name(bus),
|
||||
device_get_unit(bus), smbdev->smbd_addr);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int
|
||||
smbus_read_ivar(device_t bus, device_t dev, int index, u_long* result)
|
||||
{
|
||||
struct smbus_device* smbdev = DEVTOSMBUS(dev);
|
||||
|
||||
switch (index) {
|
||||
case SMBUS_IVAR_ADDR:
|
||||
*result = smbdev->smbd_addr;
|
||||
break;
|
||||
}
|
||||
return (ENOENT);
|
||||
}
|
||||
|
||||
DRIVER_MODULE(smbus, iicsmb, smbus_driver, smbus_devclass, 0, 0);
|
41
sys/dev/smbus/smbus.h
Normal file
41
sys/dev/smbus/smbus.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*-
|
||||
* Copyright (c) 1998 Nicolas Souchu
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: smbus.h,v 1.1.1.1 1998/08/10 18:26:05 son Exp $
|
||||
*
|
||||
*/
|
||||
#ifndef __SMBUS_H
|
||||
#define __SMBUS_H
|
||||
|
||||
struct smbus_softc {
|
||||
|
||||
device_t owner; /* smbus owner device structure */
|
||||
};
|
||||
|
||||
extern devclass_t smbus_devclass;
|
||||
|
||||
extern void smbus_generic_intr(device_t dev, u_char devaddr, char low, char high);
|
||||
|
||||
#endif
|
140
sys/dev/smbus/smbus_if.m
Normal file
140
sys/dev/smbus/smbus_if.m
Normal file
@ -0,0 +1,140 @@
|
||||
#
|
||||
# Copyright (c) 1998 Nicolas Souchu
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
# SUCH DAMAGE.
|
||||
#
|
||||
# $Id: smbus_if.m,v 1.1.1.2 1998/08/13 15:16:58 son Exp $
|
||||
#
|
||||
|
||||
INTERFACE smbus
|
||||
|
||||
#
|
||||
# Interprete interrupt
|
||||
#
|
||||
METHOD void intr {
|
||||
device_t dev;
|
||||
u_char devaddr;
|
||||
char low;
|
||||
char high;
|
||||
int error;
|
||||
};
|
||||
|
||||
#
|
||||
# Quick command
|
||||
#
|
||||
METHOD int quick {
|
||||
device_t dev;
|
||||
u_char slave;
|
||||
int how;
|
||||
};
|
||||
|
||||
#
|
||||
# Send Byte command
|
||||
#
|
||||
METHOD int sendb {
|
||||
device_t dev;
|
||||
u_char slave;
|
||||
char byte;
|
||||
};
|
||||
|
||||
#
|
||||
# Receive Byte command
|
||||
#
|
||||
METHOD int recvb {
|
||||
device_t dev;
|
||||
u_char slave;
|
||||
char *byte;
|
||||
};
|
||||
|
||||
#
|
||||
# Write Byte command
|
||||
#
|
||||
METHOD int writeb {
|
||||
device_t dev;
|
||||
u_char slave;
|
||||
char cmd;
|
||||
char byte;
|
||||
};
|
||||
|
||||
#
|
||||
# Write Word command
|
||||
#
|
||||
METHOD int writew {
|
||||
device_t dev;
|
||||
u_char slave;
|
||||
char cmd;
|
||||
short word;
|
||||
};
|
||||
|
||||
#
|
||||
# Read Byte command
|
||||
#
|
||||
METHOD int readb {
|
||||
device_t dev;
|
||||
u_char slave;
|
||||
char cmd;
|
||||
char *byte;
|
||||
};
|
||||
|
||||
#
|
||||
# Read Word command
|
||||
#
|
||||
METHOD int readw {
|
||||
device_t dev;
|
||||
u_char slave;
|
||||
char cmd;
|
||||
short *word;
|
||||
};
|
||||
|
||||
#
|
||||
# Process Call command
|
||||
#
|
||||
METHOD int pcall {
|
||||
device_t dev;
|
||||
u_char slave;
|
||||
char cmd;
|
||||
short sdata;
|
||||
short *rdata;
|
||||
};
|
||||
|
||||
#
|
||||
# Block Write command
|
||||
#
|
||||
METHODE int bwrite {
|
||||
device_t dev;
|
||||
u_char slave;
|
||||
char cmd;
|
||||
u_char count;
|
||||
char *buf;
|
||||
};
|
||||
|
||||
#
|
||||
# Block Read command
|
||||
#
|
||||
METHODE int bread {
|
||||
device_t dev;
|
||||
u_char slave;
|
||||
char cmd;
|
||||
u_char count;
|
||||
char *buf;
|
||||
};
|
Loading…
Reference in New Issue
Block a user