Module Name: src
Committed By: jmcneill
Date: Sun Oct 2 16:39:47 UTC 2011
Modified Files:
src/distrib/sets/lists/comp: mi
src/etc: MAKEDEV.tmpl
src/share/man/man4: iic.4 options.4
src/sys/arch/i386/conf: ALL
src/sys/conf: majors
src/sys/dev: Makefile
src/sys/dev/i2c: files.i2c i2c.c
Added Files:
src/sys/dev/i2c: Makefile
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.1683 -r1.1684 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.142 -r1.143 src/etc/MAKEDEV.tmpl
cvs rdiff -u -r1.8 -r1.9 src/share/man/man4/iic.4
cvs rdiff -u -r1.408 -r1.409 src/share/man/man4/options.4
cvs rdiff -u -r1.321 -r1.322 src/sys/arch/i386/conf/ALL
cvs rdiff -u -r1.56 -r1.57 src/sys/conf/majors
cvs rdiff -u -r1.31 -r1.32 src/sys/dev/Makefile
cvs rdiff -u -r0 -r1.3 src/sys/dev/i2c/Makefile
cvs rdiff -u -r1.42 -r1.43 src/sys/dev/i2c/files.i2c
cvs rdiff -u -r1.30 -r1.31 src/sys/dev/i2c/i2c.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.1683 src/distrib/sets/lists/comp/mi:1.1684
--- src/distrib/sets/lists/comp/mi:1.1683 Fri Sep 30 22:08:18 2011
+++ src/distrib/sets/lists/comp/mi Sun Oct 2 16:39:45 2011
@@ -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
Index: src/etc/MAKEDEV.tmpl
diff -u src/etc/MAKEDEV.tmpl:1.142 src/etc/MAKEDEV.tmpl:1.143
--- src/etc/MAKEDEV.tmpl:1.142 Tue Sep 6 13:34:44 2011
+++ src/etc/MAKEDEV.tmpl Sun Oct 2 16:39:46 2011
@@ -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
Index: src/share/man/man4/iic.4
diff -u src/share/man/man4/iic.4:1.8 src/share/man/man4/iic.4:1.9
--- src/share/man/man4/iic.4:1.8 Tue Aug 30 07:44:37 2011
+++ src/share/man/man4/iic.4 Sun Oct 2 16:39:46 2011
@@ -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 <[email protected]>
@@ -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
Index: src/share/man/man4/options.4
diff -u src/share/man/man4/options.4:1.408 src/share/man/man4/options.4:1.409
--- src/share/man/man4/options.4:1.408 Fri Jun 17 18:13:49 2011
+++ src/share/man/man4/options.4 Sun Oct 2 16:39:46 2011
@@ -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
Index: src/sys/arch/i386/conf/ALL
diff -u src/sys/arch/i386/conf/ALL:1.321 src/sys/arch/i386/conf/ALL:1.322
--- src/sys/arch/i386/conf/ALL:1.321 Mon Sep 26 18:14:07 2011
+++ src/sys/arch/i386/conf/ALL Sun Oct 2 16:39:47 2011
@@ -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
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
Index: src/sys/conf/majors
diff -u src/sys/conf/majors:1.56 src/sys/conf/majors:1.57
--- src/sys/conf/majors:1.56 Sat Jul 9 14:47:27 2011
+++ src/sys/conf/majors Sun Oct 2 16:39:47 2011
@@ -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 19
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
Index: src/sys/dev/Makefile
diff -u src/sys/dev/Makefile:1.31 src/sys/dev/Makefile:1.32
--- src/sys/dev/Makefile:1.31 Sat Jul 9 14:52:03 2011
+++ src/sys/dev/Makefile Sun Oct 2 16:39:47 2011
@@ -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
Index: src/sys/dev/i2c/files.i2c
diff -u src/sys/dev/i2c/files.i2c:1.42 src/sys/dev/i2c/files.i2c:1.43
--- src/sys/dev/i2c/files.i2c:1.42 Sat Aug 13 18:31:38 2011
+++ src/sys/dev/i2c/files.i2c Sun Oct 2 16:39:47 2011
@@ -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
Index: src/sys/dev/i2c/i2c.c
diff -u src/sys/dev/i2c/i2c.c:1.30 src/sys/dev/i2c/i2c.c:1.31
--- src/sys/dev/i2c/i2c.c:1.30 Sun Oct 2 12:25:40 2011
+++ src/sys/dev/i2c/i2c.c Sun Oct 2 16:39:47 2011
@@ -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
#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 sel
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
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);
Added files:
Index: src/sys/dev/i2c/Makefile
diff -u /dev/null src/sys/dev/i2c/Makefile:1.3
--- /dev/null Sun Oct 2 16:39:47 2011
+++ src/sys/dev/i2c/Makefile Sun Oct 2 16:39:47 2011
@@ -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>