Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c add detach support, modularize, build with WARNS=4



details:   https://anonhg.NetBSD.org/src/rev/19e2aa82bbca
branches:  trunk
changeset: 767813:19e2aa82bbca
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Jul 31 15:59:45 2011 +0000

description:
add detach support, modularize, build with WARNS=4

diffstat:

 sys/dev/i2c/sdtemp.c |  54 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 50 insertions(+), 4 deletions(-)

diffs (102 lines):

diff -r aecf07260227 -r 19e2aa82bbca sys/dev/i2c/sdtemp.c
--- a/sys/dev/i2c/sdtemp.c      Sun Jul 31 15:58:25 2011 +0000
+++ b/sys/dev/i2c/sdtemp.c      Sun Jul 31 15:59:45 2011 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: sdtemp.c,v 1.18 2010/07/29 13:07:14 pgoyette Exp $        */
+/*      $NetBSD: sdtemp.c,v 1.19 2011/07/31 15:59:45 jmcneill Exp $        */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.18 2010/07/29 13:07:14 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.19 2011/07/31 15:59:45 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -38,6 +38,7 @@
 #include <sys/device.h>
 #include <sys/kernel.h>
 #include <sys/endian.h>
+#include <sys/module.h>
 
 #include <dev/sysmon/sysmonvar.h>
 
@@ -59,9 +60,10 @@
 
 static int  sdtemp_match(device_t, cfdata_t, void *);
 static void sdtemp_attach(device_t, device_t, void *);
+static int  sdtemp_detach(device_t, int);
 
 CFATTACH_DECL_NEW(sdtemp, sizeof(struct sdtemp_softc),
-       sdtemp_match, sdtemp_attach, NULL, NULL);
+       sdtemp_match, sdtemp_attach, sdtemp_detach, NULL);
 
 static void    sdtemp_refresh(struct sysmon_envsys *, envsys_data_t *);
 static void    sdtemp_get_limits(struct sysmon_envsys *, envsys_data_t *,
@@ -281,7 +283,7 @@
        /* Retrieve and display hardware monitor limits */
        sdtemp_get_limits(sc->sc_sme, sc->sc_sensor, &sc->sc_deflims,
            &sc->sc_defprops);
-       aprint_normal_dev(self, "");
+       aprint_normal("%s: ", device_xname(self));
        i = 0;
        if (sc->sc_defprops & PROP_WARNMIN) {
                aprint_normal("low limit %dC",
@@ -311,6 +313,21 @@
        sysmon_envsys_destroy(sc->sc_sme);
 }
 
+static int
+sdtemp_detach(device_t self, int flags)
+{
+       struct sdtemp_softc *sc = device_private(self);
+
+       pmf_device_deregister(self);
+
+       if (sc->sc_sme)
+               sysmon_envsys_unregister(sc->sc_sme);
+       if (sc->sc_sensor)
+               kmem_free(sc->sc_sensor, sizeof(envsys_data_t));
+
+       return 0;
+}
+
 /* Retrieve current limits from device, and encode in uKelvins */
 static void
 sdtemp_get_limits(struct sysmon_envsys *sme, envsys_data_t *edata,
@@ -530,3 +547,32 @@
        iic_release_bus(sc->sc_tag, 0);
        return (error == 0);
 }
+
+MODULE(MODULE_CLASS_DRIVER, sdtemp, NULL);
+
+#ifdef _MODULE
+#include "ioconf.c"
+#endif
+
+static int
+sdtemp_modcmd(modcmd_t cmd, void *opaque)
+{
+       int error = 0;
+
+       switch (cmd) {
+       case MODULE_CMD_INIT:
+#ifdef _MODULE
+               error = config_init_component(cfdriver_ioconf_sdtemp,
+                   cfattach_ioconf_sdtemp, cfdata_ioconf_sdtemp);
+#endif
+               return error;
+       case MODULE_CMD_FINI:
+#ifdef _MODULE
+               error = config_fini_component(cfdriver_ioconf_sdtemp,
+                   cfattach_ioconf_sdtemp, cfdata_ioconf_sdtemp);
+#endif
+               return error;
+       default:
+               return ENOTTY;
+       }
+}



Home | Main Index | Thread Index | Old Index