Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb allow attaching an iic to auvitek if AUVITEK_I2C...



details:   https://anonhg.NetBSD.org/src/rev/69785742a1c6
branches:  trunk
changeset: 770058:69785742a1c6
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Oct 02 16:30:58 2011 +0000

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

diffstat:

 sys/dev/usb/auvitek.c     |   5 +++--
 sys/dev/usb/auvitek_i2c.c |  44 ++++++++++++++++++++++++++++++++++++++++----
 sys/dev/usb/auvitekvar.h  |   6 ++++--
 sys/dev/usb/files.usb     |   4 ++--
 4 files changed, 49 insertions(+), 10 deletions(-)

diffs (163 lines):

diff -r 37cb71d6b1bc -r 69785742a1c6 sys/dev/usb/auvitek.c
--- a/sys/dev/usb/auvitek.c     Sun Oct 02 15:04:47 2011 +0000
+++ b/sys/dev/usb/auvitek.c     Sun Oct 02 16:30:58 2011 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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_video_rescan(sc, ifattr, locs);
        auvitek_dtv_rescan(sc, ifattr, locs);
+       auvitek_i2c_rescan(sc, ifattr, locs);
 
        return 0;
 }
diff -r 37cb71d6b1bc -r 69785742a1c6 sys/dev/usb/auvitek_i2c.c
--- a/sys/dev/usb/auvitek_i2c.c Sun Oct 02 15:04:47 2011 +0000
+++ b/sys/dev/usb/auvitek_i2c.c Sun Oct 02 16:30:58 2011 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 @@
 #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 @@
 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 @@
 {
        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;
 }
diff -r 37cb71d6b1bc -r 69785742a1c6 sys/dev/usb/auvitekvar.h
--- a/sys/dev/usb/auvitekvar.h  Sun Oct 02 15:04:47 2011 +0000
+++ b/sys/dev/usb/auvitekvar.h  Sun Oct 02 16:30:58 2011 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -101,7 +101,7 @@
 
 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 @@
 /* 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 *);
diff -r 37cb71d6b1bc -r 69785742a1c6 sys/dev/usb/files.usb
--- a/sys/dev/usb/files.usb     Sun Oct 02 15:04:47 2011 +0000
+++ b/sys/dev/usb/files.usb     Sun Oct 02 16:30:58 2011 +0000
@@ -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 @@
 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



Home | Main Index | Thread Index | Old Index