Sun Jul 31 16:05:01 2011 UTC ()
modularize


(jmcneill)
diff -r1.30 -r1.31 src/sys/dev/i2c/dbcool.c

cvs diff -r1.30 -r1.31 src/sys/dev/i2c/dbcool.c (expand / switch to unified diff)

--- src/sys/dev/i2c/dbcool.c 2011/06/20 20:16:19 1.30
+++ src/sys/dev/i2c/dbcool.c 2011/07/31 16:05:01 1.31
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dbcool.c,v 1.30 2011/06/20 20:16:19 pgoyette Exp $ */ 1/* $NetBSD: dbcool.c,v 1.31 2011/07/31 16:05:01 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Paul Goyette 8 * by Paul Goyette
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -40,34 +40,35 @@ @@ -40,34 +40,35 @@
40 * http://www.onsemi.com/pub/Collateral/ADT7466.PDF 40 * http://www.onsemi.com/pub/Collateral/ADT7466.PDF
41 * http://www.onsemi.com/pub/Collateral/ADT7467-D.PDF 41 * http://www.onsemi.com/pub/Collateral/ADT7467-D.PDF
42 * http://www.onsemi.com/pub/Collateral/ADT7468-D.PDF 42 * http://www.onsemi.com/pub/Collateral/ADT7468-D.PDF
43 * http://www.onsemi.com/pub/Collateral/ADT7473-D.PDF 43 * http://www.onsemi.com/pub/Collateral/ADT7473-D.PDF
44 * http://www.onsemi.com/pub/Collateral/ADT7475-D.PDF 44 * http://www.onsemi.com/pub/Collateral/ADT7475-D.PDF
45 * http://www.onsemi.com/pub/Collateral/ADT7476-D.PDF 45 * http://www.onsemi.com/pub/Collateral/ADT7476-D.PDF
46 * http://www.onsemi.com/pub/Collateral/ADT7490-D.PDF 46 * http://www.onsemi.com/pub/Collateral/ADT7490-D.PDF
47 * http://www.smsc.com/media/Downloads_Public/Data_Sheets/6d103s.pdf 47 * http://www.smsc.com/media/Downloads_Public/Data_Sheets/6d103s.pdf
48 * 48 *
49 * (URLs are correct as of October 5, 2008) 49 * (URLs are correct as of October 5, 2008)
50 */ 50 */
51 51
52#include <sys/cdefs.h> 52#include <sys/cdefs.h>
53__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.30 2011/06/20 20:16:19 pgoyette Exp $"); 53__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.31 2011/07/31 16:05:01 jmcneill Exp $");
54 54
55#include <sys/param.h> 55#include <sys/param.h>
56#include <sys/systm.h> 56#include <sys/systm.h>
57#include <sys/kernel.h> 57#include <sys/kernel.h>
58#include <sys/device.h> 58#include <sys/device.h>
59#include <sys/malloc.h> 59#include <sys/malloc.h>
60#include <sys/sysctl.h> 60#include <sys/sysctl.h>
 61#include <sys/module.h>
61 62
62#include <dev/i2c/dbcool_var.h> 63#include <dev/i2c/dbcool_var.h>
63#include <dev/i2c/dbcool_reg.h> 64#include <dev/i2c/dbcool_reg.h>
64 65
65/* Config interface */ 66/* Config interface */
66static int dbcool_match(device_t, cfdata_t, void *); 67static int dbcool_match(device_t, cfdata_t, void *);
67static void dbcool_attach(device_t, device_t, void *); 68static void dbcool_attach(device_t, device_t, void *);
68static int dbcool_detach(device_t, int); 69static int dbcool_detach(device_t, int);
69 70
70/* Device attributes */ 71/* Device attributes */
71static int dbcool_supply_voltage(struct dbcool_softc *); 72static int dbcool_supply_voltage(struct dbcool_softc *);
72static bool dbcool_islocked(struct dbcool_softc *); 73static bool dbcool_islocked(struct dbcool_softc *);
73 74
@@ -784,26 +785,28 @@ dbcool_attach(device_t parent, device_t  @@ -784,26 +785,28 @@ dbcool_attach(device_t parent, device_t
784 "(rev 0x%04x)\n", sc->sc_dc.dc_chip->name, ver); 785 "(rev 0x%04x)\n", sc->sc_dc.dc_chip->name, ver);
785 786
786 dbcool_setup(self); 787 dbcool_setup(self);
787 788
788 if (!pmf_device_register(self, dbcool_pmf_suspend, dbcool_pmf_resume)) 789 if (!pmf_device_register(self, dbcool_pmf_suspend, dbcool_pmf_resume))
789 aprint_error_dev(self, "couldn't establish power handler\n"); 790 aprint_error_dev(self, "couldn't establish power handler\n");
790} 791}
791 792
792static int 793static int
793dbcool_detach(device_t self, int flags) 794dbcool_detach(device_t self, int flags)
794{ 795{
795 struct dbcool_softc *sc = device_private(self); 796 struct dbcool_softc *sc = device_private(self);
796 797
 798 pmf_device_deregister(self);
 799
797 sysmon_envsys_unregister(sc->sc_sme); 800 sysmon_envsys_unregister(sc->sc_sme);
798 sc->sc_sme = NULL; 801 sc->sc_sme = NULL;
799 return 0; 802 return 0;
800} 803}
801 804
802/* On suspend, we save the state of the SHDN bit, then set it */ 805/* On suspend, we save the state of the SHDN bit, then set it */
803bool dbcool_pmf_suspend(device_t dev, const pmf_qual_t *qual) 806bool dbcool_pmf_suspend(device_t dev, const pmf_qual_t *qual)
804{ 807{
805 struct dbcool_softc *sc = device_private(dev); 808 struct dbcool_softc *sc = device_private(dev);
806 uint8_t reg, bit, cfg; 809 uint8_t reg, bit, cfg;
807 810
808 if ((sc->sc_dc.dc_chip->flags && DBCFLAG_HAS_SHDN) == 0) 811 if ((sc->sc_dc.dc_chip->flags && DBCFLAG_HAS_SHDN) == 0)
809 return true; 812 return true;
@@ -2149,13 +2152,42 @@ dbcool_set_fan_limits(struct dbcool_soft @@ -2149,13 +2152,42 @@ dbcool_set_fan_limits(struct dbcool_soft
2149 if (limit > 0xffff) 2152 if (limit > 0xffff)
2150 limit = 0xffff; 2153 limit = 0xffff;
2151 } 2154 }
2152 sc->sc_dc.dc_writereg(&sc->sc_dc, reg->lo_lim_reg, 2155 sc->sc_dc.dc_writereg(&sc->sc_dc, reg->lo_lim_reg,
2153 limit & 0xff); 2156 limit & 0xff);
2154 limit >>= 8; 2157 limit >>= 8;
2155 sc->sc_dc.dc_writereg(&sc->sc_dc, reg->lo_lim_reg + 1, 2158 sc->sc_dc.dc_writereg(&sc->sc_dc, reg->lo_lim_reg + 1,
2156 limit & 0xff); 2159 limit & 0xff);
2157 } else if (*props & PROP_DRIVER_LIMITS) { 2160 } else if (*props & PROP_DRIVER_LIMITS) {
2158 sc->sc_dc.dc_writereg(&sc->sc_dc, reg->lo_lim_reg, 0xff); 2161 sc->sc_dc.dc_writereg(&sc->sc_dc, reg->lo_lim_reg, 0xff);
2159 sc->sc_dc.dc_writereg(&sc->sc_dc, reg->lo_lim_reg + 1, 0xff); 2162 sc->sc_dc.dc_writereg(&sc->sc_dc, reg->lo_lim_reg + 1, 0xff);
2160 } 2163 }
2161} 2164}
 2165
 2166MODULE(MODULE_CLASS_DRIVER, dbcool, NULL);
 2167
 2168#ifdef _MODULE
 2169#include "ioconf.c"
 2170#endif
 2171
 2172static int
 2173dbcool_modcmd(modcmd_t cmd, void *opaque)
 2174{
 2175 int error = 0;
 2176
 2177 switch (cmd) {
 2178 case MODULE_CMD_INIT:
 2179#ifdef _MODULE
 2180 error = config_init_component(cfdriver_ioconf_dbcool,
 2181 cfattach_ioconf_dbcool, cfdata_ioconf_dbcool);
 2182#endif
 2183 return error;
 2184 case MODULE_CMD_FINI:
 2185#ifdef _MODULE
 2186 error = config_fini_component(cfdriver_ioconf_dbcool,
 2187 cfattach_ioconf_dbcool, cfdata_ioconf_dbcool);
 2188#endif
 2189 return error;
 2190 default:
 2191 return ENOTTY;
 2192 }
 2193}