Install dev/i2c/i2c_io.h and implement the API in the iic(4) driver.
Obsolete the I2C_SCAN option as this can now be done from userland.
This commit is contained in:
parent
0f85e13f2d
commit
ab747348b5
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: mi,v 1.1683 2011/09/30 22:08:18 jym Exp $
|
||||
# $NetBSD: mi,v 1.1684 2011/10/02 16:39:45 jmcneill Exp $
|
||||
#
|
||||
# Note: don't delete entries from here - mark them as "obsolete" instead.
|
||||
#
|
||||
|
@ -282,6 +282,7 @@
|
|||
./usr/include/dev/hpc/hpcfbio.h comp-c-include
|
||||
./usr/include/dev/i2c/i2c_bus.h comp-obsolete obsolete
|
||||
./usr/include/dev/i2c/i2c_eeprom.h comp-obsolete obsolete
|
||||
./usr/include/dev/i2c/i2c_io.h comp-c-include
|
||||
./usr/include/dev/i2o/i2o.h comp-c-include
|
||||
./usr/include/dev/i2o/iopio.h comp-c-include
|
||||
./usr/include/dev/i2o/iopvar.h comp-obsolete obsolete
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/sh -
|
||||
# $NetBSD: MAKEDEV.tmpl,v 1.142 2011/09/06 13:34:44 apb Exp $
|
||||
# $NetBSD: MAKEDEV.tmpl,v 1.143 2011/10/02 16:39:46 jmcneill Exp $
|
||||
#
|
||||
# Copyright (c) 2003,2007,2008 The NetBSD Foundation, Inc.
|
||||
# All rights reserved.
|
||||
|
@ -811,6 +811,10 @@ dtv)
|
|||
makedev dtv0 dtv1 dtv2 dtv3
|
||||
;;
|
||||
|
||||
iic)
|
||||
makedev iic0 iic1 iic2 iic3
|
||||
;;
|
||||
|
||||
altmem)
|
||||
makedev altmem0 altmem1
|
||||
;;
|
||||
|
@ -1417,6 +1421,12 @@ dtv[0-9]*)
|
|||
mkdev dvb/adapter$unit/dvr0 c %dtv_chr% $(($unit + 32)) 666
|
||||
;;
|
||||
|
||||
iic[0-9]*)
|
||||
unit=${i#iic}
|
||||
: ${unit:-0}
|
||||
mkdev iic$unit c %iic_chr% $unit 600
|
||||
;;
|
||||
|
||||
amr[0-9]*)
|
||||
unit=${i#amr}
|
||||
mkdev amr$unit c %amr_chr% $unit
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: iic.4,v 1.8 2011/08/30 07:44:37 mbalmer Exp $
|
||||
.\" $NetBSD: iic.4,v 1.9 2011/10/02 16:39:46 jmcneill Exp $
|
||||
.\" $OpenBSD: iic.4,v 1.74 2008/09/10 16:13:43 reyk Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2004, 2006 Alexander Yurchenko <grange@openbsd.org>
|
||||
|
@ -16,7 +16,7 @@
|
|||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
.\"
|
||||
.Dd August 30, 2011
|
||||
.Dd October 2, 2011
|
||||
.Dt IIC 4
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -50,8 +50,6 @@
|
|||
.Cd "iic* at piixpm? # amd64 i386 "
|
||||
.Cd "iic0 at slugiic0 # evbarm "
|
||||
.Cd "iic* at viapcib? # i386 "
|
||||
.Pp
|
||||
.Cd "options I2C_SCAN"
|
||||
.Sh DESCRIPTION
|
||||
.Tn I2C
|
||||
is a two-wire bus developed by Philips used for connecting
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: options.4,v 1.408 2011/06/17 18:13:49 wiz Exp $
|
||||
.\" $NetBSD: options.4,v 1.409 2011/10/02 16:39:46 jmcneill Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1996
|
||||
.\" Perry E. Metzger. All rights reserved.
|
||||
|
@ -30,7 +30,7 @@
|
|||
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.\"
|
||||
.Dd June 17, 2011
|
||||
.Dd October 2, 2011
|
||||
.Dt OPTIONS 4
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -1494,19 +1494,6 @@ Support for
|
|||
Number of storage slots per file for
|
||||
.Xr fileassoc 9 .
|
||||
Default is 4.
|
||||
.It Cd options I2C_SCAN
|
||||
Scan each i2c bus to determine which addresses respond.
|
||||
.Pp
|
||||
.Em WARNING !
|
||||
Using this option can access some devices in such a
|
||||
manner as to leave them in an unstable or unuseable state, and
|
||||
can prevent those devices from being properly matched and/or
|
||||
attached.
|
||||
It can also lock up the entire
|
||||
.Xr iic 4
|
||||
bus and even prevent a machine from completing the boot process.
|
||||
Don't use this option unless you know what you're doing and can
|
||||
accept all sorts of unforeseen consequences.
|
||||
.El
|
||||
.Ss Networking Options
|
||||
.Bl -ohang
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: ALL,v 1.321 2011/09/26 18:14:07 jakllsch Exp $
|
||||
# $NetBSD: ALL,v 1.322 2011/10/02 16:39:47 jmcneill Exp $
|
||||
# From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
|
||||
#
|
||||
# ALL machine description file
|
||||
|
@ -17,7 +17,7 @@ include "arch/i386/conf/std.i386"
|
|||
|
||||
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
|
||||
|
||||
#ident "ALL-$Revision: 1.321 $"
|
||||
#ident "ALL-$Revision: 1.322 $"
|
||||
|
||||
maxusers 64 # estimated number of users
|
||||
|
||||
|
@ -254,7 +254,6 @@ options USBVERBOSE # verbose USB device autoconfig messages
|
|||
options PNPBIOSVERBOSE # verbose PnP BIOS messages
|
||||
#options PNPBIOSDEBUG # more fulsome PnP BIOS debugging messages
|
||||
options MCAVERBOSE # verbose MCA device autoconfig messages
|
||||
options I2C_SCAN # Scan i2c bus for responses
|
||||
|
||||
options NFS_BOOT_DHCP,NFS_BOOT_BOOTPARAM
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: majors,v 1.56 2011/07/09 14:47:27 jmcneill Exp $
|
||||
# $NetBSD: majors,v 1.57 2011/10/02 16:39:47 jmcneill Exp $
|
||||
#
|
||||
# Device majors for Machine-Independent drivers.
|
||||
#
|
||||
|
@ -46,3 +46,4 @@ device-major rumpblk char 197 block 197 rumpblk
|
|||
device-major npf char 198 npf
|
||||
device-major flash char 199 block 199 flash
|
||||
device-major dtv char 200 dtv
|
||||
device-major iic char 201 iic
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# $NetBSD: Makefile,v 1.31 2011/07/09 14:52:03 jmcneill Exp $
|
||||
# $NetBSD: Makefile,v 1.32 2011/10/02 16:39:47 jmcneill Exp $
|
||||
|
||||
SUBDIR= apm ata bluetooth dec dm dmover dtv hpc i2o ic ieee1394 ir isa \
|
||||
SUBDIR= apm ata bluetooth dec dm dmover dtv hpc i2c i2o ic ieee1394 ir isa \
|
||||
microcode ofw pci pckbport pcmcia pud putter raidframe sbus scsipi \
|
||||
sun tc usb vme wscons
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
# $NetBSD: Makefile,v 1.3 2011/10/02 16:39:47 jmcneill Exp $
|
||||
|
||||
INCSDIR= /usr/include/dev/i2c
|
||||
INCS= i2c_io.h
|
||||
|
||||
.include <bsd.kinc.mk>
|
|
@ -1,6 +1,6 @@
|
|||
# $NetBSD: files.i2c,v 1.42 2011/08/13 18:31:38 jmcneill Exp $
|
||||
# $NetBSD: files.i2c,v 1.43 2011/10/02 16:39:47 jmcneill Exp $
|
||||
|
||||
defflag opt_i2cbus.h I2C_SCAN
|
||||
obsolete defflag opt_i2cbus.h I2C_SCAN
|
||||
define i2cbus { }
|
||||
define i2cexec
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: i2c.c,v 1.30 2011/10/02 12:25:40 mbalmer Exp $ */
|
||||
/* $NetBSD: i2c.c,v 1.31 2011/10/02 16:39:47 jmcneill Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003 Wasabi Systems, Inc.
|
||||
|
@ -36,7 +36,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.30 2011/10/02 12:25:40 mbalmer Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.31 2011/10/02 16:39:47 jmcneill Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -52,9 +52,6 @@ __KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.30 2011/10/02 12:25:40 mbalmer Exp $");
|
|||
#include <dev/i2c/i2cvar.h>
|
||||
|
||||
#include "locators.h"
|
||||
#ifdef KERNEL_OPT
|
||||
#include <opt_i2cbus.h>
|
||||
#endif
|
||||
|
||||
#define I2C_MAX_ADDR 0x3ff /* 10-bit address, max */
|
||||
|
||||
|
@ -64,6 +61,17 @@ struct iic_softc {
|
|||
device_t sc_devices[I2C_MAX_ADDR + 1];
|
||||
};
|
||||
|
||||
static dev_type_open(iic_open);
|
||||
static dev_type_close(iic_close);
|
||||
static dev_type_ioctl(iic_ioctl);
|
||||
|
||||
const struct cdevsw iic_cdevsw = {
|
||||
iic_open, iic_close, noread, nowrite, iic_ioctl,
|
||||
nostop, notty, nopoll, nommap, nokqfilter, D_OTHER
|
||||
};
|
||||
|
||||
extern struct cfdriver iic_cd;
|
||||
|
||||
static void iic_smbus_intr_thread(void *);
|
||||
static void iic_fill_compat(struct i2c_attach_args*, const char*,
|
||||
size_t, char **);
|
||||
|
@ -182,70 +190,6 @@ iic_attach(device_t parent, device_t self, void *aux)
|
|||
if (rv)
|
||||
aprint_error_dev(self, "unable to create intr thread\n");
|
||||
|
||||
#if I2C_SCAN
|
||||
if (sc->sc_type == I2C_TYPE_SMBUS) {
|
||||
int err;
|
||||
int found = 0;
|
||||
i2c_addr_t addr;
|
||||
uint8_t val;
|
||||
|
||||
for (addr = 0x09; addr < 0x78; addr++) {
|
||||
/*
|
||||
* Skip certain i2c addresses:
|
||||
* 0x00 General Call / START
|
||||
* 0x01 CBUS Address
|
||||
* 0x02 Different Bus format
|
||||
* 0x03 - 0x07 Reserved
|
||||
* 0x08 Host Address
|
||||
* 0x0c Alert Response Address
|
||||
* 0x28 ACCESS.Bus host
|
||||
* 0x37 ACCESS.Bus default address
|
||||
* 0x48 - 0x4b Prototypes
|
||||
* 0x61 Device Default Address
|
||||
* 0x78 - 0x7b 10-bit addresses
|
||||
* 0x7c - 0x7f Reserved
|
||||
*
|
||||
* Some of these are skipped by judicious selection
|
||||
* of the range of the above for (;;) statement.
|
||||
*
|
||||
* if (addr <= 0x08 || addr >= 0x78)
|
||||
* continue;
|
||||
*/
|
||||
if (addr == 0x0c || addr == 0x28 || addr == 0x37 ||
|
||||
addr == 0x61 || (addr & 0x7c) == 0x48)
|
||||
continue;
|
||||
|
||||
iic_acquire_bus(ic, 0);
|
||||
/*
|
||||
* Use SMBus quick_write command to detect most
|
||||
* addresses; should avoid hanging the bus on
|
||||
* some write-only devices (like clocks that show
|
||||
* up at address 0x69)
|
||||
*
|
||||
* XXX The quick_write() is allegedly known to
|
||||
* XXX corrupt the Atmel AT24RF08 EEPROM found
|
||||
* XXX on some IBM Thinkpads!
|
||||
*/
|
||||
if ((addr & 0xf8) == 0x30 ||
|
||||
(addr & 0xf0) == 0x50)
|
||||
err = iic_smbus_receive_byte(ic, addr, &val, 0);
|
||||
else
|
||||
err = iic_smbus_quick_write(ic, addr, 0);
|
||||
if (err == 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");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!pmf_device_register(self, NULL, NULL))
|
||||
aprint_error_dev(self, "couldn't establish power handler\n");
|
||||
|
||||
|
@ -459,6 +403,84 @@ iic_compat_match(struct i2c_attach_args *ia, const char ** compats)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
iic_open(dev_t dev, int flag, int fmt, lwp_t *l)
|
||||
{
|
||||
struct iic_softc *sc = device_lookup_private(&iic_cd, minor(dev));
|
||||
|
||||
if (sc == NULL)
|
||||
return ENXIO;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
iic_close(dev_t dev, int flag, int fmt, lwp_t *l)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
iic_ioctl_exec(struct iic_softc *sc, i2c_ioctl_exec_t *iie)
|
||||
{
|
||||
i2c_tag_t ic = sc->sc_tag;
|
||||
uint8_t buf[I2C_EXEC_MAX_BUFLEN];
|
||||
int error;
|
||||
void *cmd;
|
||||
|
||||
/* Validate parameters */
|
||||
if (iie->iie_addr > I2C_MAX_ADDR)
|
||||
return EINVAL;
|
||||
if (iie->iie_cmdlen > I2C_EXEC_MAX_CMDLEN ||
|
||||
iie->iie_buflen > I2C_EXEC_MAX_BUFLEN)
|
||||
return EINVAL;
|
||||
if (iie->iie_cmd != NULL && iie->iie_cmdlen == 0)
|
||||
return EINVAL;
|
||||
if (iie->iie_buf != NULL && iie->iie_buflen == 0)
|
||||
return EINVAL;
|
||||
|
||||
#if 0
|
||||
/* Disallow userspace access to devices that have drivers attached. */
|
||||
if (sc->sc_devices[iie->iie_addr] != NULL)
|
||||
return EBUSY;
|
||||
#endif
|
||||
|
||||
if (iie->iie_cmd != NULL) {
|
||||
error = copyin(iie->iie_cmd, cmd, iie->iie_cmdlen);
|
||||
if (error)
|
||||
return error;
|
||||
}
|
||||
|
||||
iic_acquire_bus(ic, 0);
|
||||
error = iic_exec(ic, iie->iie_op, iie->iie_addr, cmd, iie->iie_cmdlen,
|
||||
buf, iie->iie_buflen, 0);
|
||||
iic_release_bus(ic, 0);
|
||||
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
if (iie->iie_buf)
|
||||
error = copyout(buf, iie->iie_buf, iie->iie_buflen);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
static int
|
||||
iic_ioctl(dev_t dev, u_long cmd, void *data, int flag, lwp_t *l)
|
||||
{
|
||||
struct iic_softc *sc = device_lookup_private(&iic_cd, minor(dev));
|
||||
|
||||
if (sc == NULL)
|
||||
return ENXIO;
|
||||
|
||||
switch (cmd) {
|
||||
case I2C_IOCTL_EXEC:
|
||||
return iic_ioctl_exec(sc, (i2c_ioctl_exec_t *)data);
|
||||
default:
|
||||
return ENODEV;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CFATTACH_DECL2_NEW(iic, sizeof(struct iic_softc),
|
||||
iic_match, iic_attach, NULL, NULL, iic_rescan, iic_child_detach);
|
||||
|
|
Loading…
Reference in New Issue