Module Name:    src
Committed By:   jmcneill
Date:           Sun Oct  2 16:30:58 UTC 2011

Modified Files:
        src/sys/dev/usb: auvitek.c auvitek_i2c.c auvitekvar.h files.usb

Log Message:
allow attaching an iic to auvitek if AUVITEK_I2C_DEBUG is defined, and
change the auvitek i2c lock from IPL_VM to IPL_NONE


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/usb/auvitek.c \
    src/sys/dev/usb/auvitekvar.h
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/usb/auvitek_i2c.c
cvs rdiff -u -r1.114 -r1.115 src/sys/dev/usb/files.usb

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/auvitek.c
diff -u src/sys/dev/usb/auvitek.c:1.5 src/sys/dev/usb/auvitek.c:1.6
--- src/sys/dev/usb/auvitek.c:1.5	Tue Aug  9 01:42:24 2011
+++ src/sys/dev/usb/auvitek.c	Sun Oct  2 16:30:58 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: auvitek.c,v 1.5 2011/08/09 01:42:24 jmcneill Exp $ */
+/* $NetBSD: auvitek.c,v 1.6 2011/10/02 16:30:58 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2010 Jared D. McNeill <jmcne...@invisible.ca>
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: auvitek.c,v 1.5 2011/08/09 01:42:24 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auvitek.c,v 1.6 2011/10/02 16:30:58 jmcneill Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -313,6 +313,7 @@ auvitek_rescan(device_t self, const char
 
 	auvitek_video_rescan(sc, ifattr, locs);
 	auvitek_dtv_rescan(sc, ifattr, locs);
+	auvitek_i2c_rescan(sc, ifattr, locs);
 
 	return 0;
 }
Index: src/sys/dev/usb/auvitekvar.h
diff -u src/sys/dev/usb/auvitekvar.h:1.5 src/sys/dev/usb/auvitekvar.h:1.6
--- src/sys/dev/usb/auvitekvar.h:1.5	Tue Aug 16 23:35:55 2011
+++ src/sys/dev/usb/auvitekvar.h	Sun Oct  2 16:30:58 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: auvitekvar.h,v 1.5 2011/08/16 23:35:55 dyoung Exp $ */
+/* $NetBSD: auvitekvar.h,v 1.6 2011/10/02 16:30:58 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2010 Jared D. McNeill <jmcne...@invisible.ca>
@@ -101,7 +101,7 @@ struct auvitek_bulk {
 
 struct auvitek_softc {
 	device_t		sc_dev;
-	device_t		sc_videodev, sc_dtvdev, sc_audiodev;
+	device_t		sc_videodev, sc_dtvdev, sc_audiodev, sc_i2cdev;
 	struct i2c_controller	sc_i2c;
 	kmutex_t		sc_i2c_lock;
 
@@ -150,6 +150,8 @@ unsigned int auvitek_board_get_if_freque
 /* auvitek_i2c.c */
 int	auvitek_i2c_attach(struct auvitek_softc *);
 int	auvitek_i2c_detach(struct auvitek_softc *, int);
+void	auvitek_i2c_rescan(struct auvitek_softc *, const char *, const int *);
+void	auvitek_i2c_childdet(struct auvitek_softc *, device_t);
 
 /* auvitek_video.c */
 int	auvitek_video_attach(struct auvitek_softc *);

Index: src/sys/dev/usb/auvitek_i2c.c
diff -u src/sys/dev/usb/auvitek_i2c.c:1.2 src/sys/dev/usb/auvitek_i2c.c:1.3
--- src/sys/dev/usb/auvitek_i2c.c:1.2	Sat Jul  9 15:00:45 2011
+++ src/sys/dev/usb/auvitek_i2c.c	Sun Oct  2 16:30:58 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: auvitek_i2c.c,v 1.2 2011/07/09 15:00:45 jmcneill Exp $ */
+/* $NetBSD: auvitek_i2c.c,v 1.3 2011/10/02 16:30:58 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2010 Jared D. McNeill <jmcne...@invisible.ca>
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: auvitek_i2c.c,v 1.2 2011/07/09 15:00:45 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auvitek_i2c.c,v 1.3 2011/10/02 16:30:58 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -50,6 +50,8 @@ __KERNEL_RCSID(0, "$NetBSD: auvitek_i2c.
 #include <dev/usb/auvitekreg.h>
 #include <dev/usb/auvitekvar.h>
 
+/* #define AUVITEK_I2C_DEBUG */
+
 static int	auvitek_i2c_acquire_bus(void *, int);
 static void	auvitek_i2c_release_bus(void *, int);
 static int	auvitek_i2c_exec(void *, i2c_op_t, i2c_addr_t,
@@ -67,12 +69,14 @@ static bool	auvitek_i2c_wait_wrdone(stru
 int
 auvitek_i2c_attach(struct auvitek_softc *sc)
 {
-	mutex_init(&sc->sc_i2c_lock, MUTEX_DEFAULT, IPL_VM);
+	mutex_init(&sc->sc_i2c_lock, MUTEX_DEFAULT, IPL_NONE);
 	sc->sc_i2c.ic_cookie = sc;
 	sc->sc_i2c.ic_acquire_bus = auvitek_i2c_acquire_bus;
 	sc->sc_i2c.ic_release_bus = auvitek_i2c_release_bus;
 	sc->sc_i2c.ic_exec = auvitek_i2c_exec;
 
+	auvitek_i2c_rescan(sc, NULL, NULL);
+
 	return 0;
 }
 
@@ -81,15 +85,47 @@ auvitek_i2c_detach(struct auvitek_softc 
 {
 	mutex_destroy(&sc->sc_i2c_lock);
 
+	if (sc->sc_i2cdev)
+		config_detach(sc->sc_i2cdev, flags);
+
 	return 0;
 }
 
+void
+auvitek_i2c_rescan(struct auvitek_softc *sc, const char *ifattr,
+    const int *locs)
+{
+#ifdef AUVITEK_I2C_DEBUG
+	struct i2cbus_attach_args iba;
+
+	if (ifattr_match(ifattr, "i2cbus") && sc->sc_i2cdev == NULL) {
+		memset(&iba, 0, sizeof(iba));
+		iba.iba_type = I2C_TYPE_SMBUS;
+		iba.iba_tag = &sc->sc_i2c;
+		sc->sc_i2cdev = config_found_ia(sc->sc_dev, "i2cbus",
+		    &iba, iicbus_print);
+	}
+#endif
+}
+
+void
+auvitek_i2c_childdet(struct auvitek_softc *sc, device_t child)
+{
+	if (sc->sc_i2cdev == child)
+		sc->sc_i2cdev = NULL;
+}
+
 static int
 auvitek_i2c_acquire_bus(void *opaque, int flags)
 {
 	struct auvitek_softc *sc = opaque;
 
-	mutex_enter(&sc->sc_i2c_lock);
+	if (flags & I2C_F_POLL) {
+		if (!mutex_tryenter(&sc->sc_i2c_lock))
+			return EBUSY;
+	} else {
+		mutex_enter(&sc->sc_i2c_lock);
+	}
 
 	return 0;
 }

Index: src/sys/dev/usb/files.usb
diff -u src/sys/dev/usb/files.usb:1.114 src/sys/dev/usb/files.usb:1.115
--- src/sys/dev/usb/files.usb:1.114	Tue Aug 23 16:16:43 2011
+++ src/sys/dev/usb/files.usb	Sun Oct  2 16:30:58 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: files.usb,v 1.114 2011/08/23 16:16:43 christos Exp $
+#	$NetBSD: files.usb,v 1.115 2011/10/02 16:30:58 jmcneill Exp $
 #
 # Config file and device description for machine-independent USB code.
 # Included by ports that need it.  Ports that use it must provide
@@ -160,7 +160,7 @@ attach	uvideo at usbifif
 file	dev/usb/uvideo.c		uvideo
 
 # Auvitek AU0828
-device	auvitek: videobus, dtvbus, i2cexec, usbifif, au8522, xc5k
+device	auvitek: videobus, dtvbus, i2cbus, i2cexec, usbifif, au8522, xc5k
 attach	auvitek at usbdevif
 file	dev/usb/auvitek.c		auvitek
 file	dev/usb/auvitek_audio.c		auvitek

Reply via email to