Wed Nov 22 14:56:30 2017 UTC ()
Pull up following revision(s) (requested by msaitoh in ticket #374):
	share/man/man4/lm.4: revision 1.33
	share/man/man4/lm.4: revision 1.34
	sys/dev/ic/nslm7x.c: revision 1.70
	sys/dev/isa/lm_isa_common.c: revision 1.5
	sys/dev/isa/lm_isa_common.c: revision 1.6
	sys/dev/isa/wbsio.c: revision 1.11
	sys/dev/i2c/lm_i2c.c: revision 1.3
	sys/dev/isa/wbsio.c: revision 1.12
	sys/dev/i2c/lm_i2c.c: revision 1.4
	sys/dev/isa/wbsioreg.h: revision 1.1
	sys/dev/isa/wbsio.c: revision 1.13
	sys/dev/isa/wbsioreg.h: revision 1.2
	sys/dev/isa/wbsio.c: revision 1.14
	sys/dev/isa/wbsioreg.h: revision 1.3
	sys/dev/isa/wbsio.c: revision 1.15
	sys/dev/isa/wbsioreg.h: revision 1.4
	sys/dev/isa/wbsioreg.h: revision 1.5
	share/man/man4/wbsio.4: revision 1.4
	share/man/man4/wbsio.4: revision 1.5
	sys/dev/ic/nslm7xvar.h: revision 1.30
	sys/dev/ic/nslm7x.c: revision 1.65
	share/man/man4/wbsio.4: revision 1.6
	sys/dev/ic/nslm7xvar.h: revision 1.31
	sys/dev/ic/nslm7x.c: revision 1.66
	sys/dev/ic/nslm7xvar.h: revision 1.32
	sys/dev/ic/nslm7x.c: revision 1.67
	sys/dev/ic/nslm7xvar.h: revision 1.33
	sys/dev/ic/nslm7x.c: revision 1.68
	sys/dev/ic/nslm7x.c: revision 1.69
  Add Winbond W83627DHG-P, W83627SF, W83627UHG, W83667HGB, W83687THF, W83697UG,
Nuvoton NCT5104D, NCT610[246]D, NCT6775, NCT6779, NCT6791, NCT6792 and NCT6793.
lm(4): Add support for NCT5104D, NCT610[246]D, NCT6775F, NCT6779D and NCT679[1235]D.
wbsio(4): Add support for NCT6795D.
Add note about Nuvoton.
- Add new Nuvoton devices.
- Add CAVEATS section from OpenBSD.
Add space before left-paren
Remove superfluous Pp.
Whitespace.
  Fix a bug that fan RPM wasn't printed correctly. 0xbX is not RPM but counter.
Use 0xcX.
  Fix typo.
- Sprinkle static and const. No functional change.
- Print chip ID in hexadecimal instead of octal in def_match().
  Use uint8_t instead of int. No functional change.
  Print chip name correctly.
- WBSIO_ID_W83627DHG and newer devices have 12bit device ID. So, change sioid
   from 8bit to 16bit and check with it strictly.
- s/lm_match/nslm_match/
- split {wb,lm,def}_match() to XXX_match and XXX_attach().
- Rename lm_probe with lm_match and call {wb,nslm,def}_match() at the end of
   the function to check strictly.
- NCT610[246]D is different from others, so add new nct6102d_sensors[] table.
- Register offsets of vendor ID and chip id of NCT610[246]D are different
   from others. When it failed reading vendor ID or chip ID, fallback to
   NCT610[246]D's register offsets.
- Add debug messages.
  Restore NetBSD RCS Id which was accidentally removed in rev. 1.2.
  s/Id/NetBSD/. Pointed out by wiz!


(martin)
diff -r1.32 -r1.32.40.1 src/share/man/man4/lm.4
diff -r1.3 -r1.3.18.1 src/share/man/man4/wbsio.4
diff -r1.2 -r1.2.80.1 src/sys/dev/i2c/lm_i2c.c
diff -r1.64 -r1.64.10.1 src/sys/dev/ic/nslm7x.c
diff -r1.29 -r1.29.10.1 src/sys/dev/ic/nslm7xvar.h
diff -r1.4 -r1.4.10.1 src/sys/dev/isa/lm_isa_common.c
diff -r1.10 -r1.10.10.1 src/sys/dev/isa/wbsio.c
diff -r0 -r1.5.2.2 src/sys/dev/isa/wbsioreg.h

cvs diff -r1.32 -r1.32.40.1 src/share/man/man4/lm.4 (expand / switch to unified diff)

--- src/share/man/man4/lm.4 2010/02/21 05:16:29 1.32
+++ src/share/man/man4/lm.4 2017/11/22 14:56:30 1.32.40.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: lm.4,v 1.32 2010/02/21 05:16:29 cnst Exp $ 1.\" $NetBSD: lm.4,v 1.32.40.1 2017/11/22 14:56:30 martin Exp $
2.\" 2.\"
3.\" Copyright (c) 2000 The NetBSD Foundation, Inc. 3.\" Copyright (c) 2000 The NetBSD Foundation, Inc.
4.\" All rights reserved. 4.\" All rights reserved.
5.\" 5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation 6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Bill Squier. 7.\" by Bill Squier.
8.\" 8.\"
9.\" Redistribution and use in source and binary forms, with or without 9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions 10.\" modification, are permitted provided that the following conditions
11.\" are met: 11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright 12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer. 13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" 2. Redistributions in binary form must reproduce the above copyright
@@ -17,84 +17,95 @@ @@ -17,84 +17,95 @@
17.\" 17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE. 28.\" POSSIBILITY OF SUCH DAMAGE.
29.\" 29.\"
30.Dd February 16, 2010 30.Dd July 12, 2017
31.Dt LM 4 31.Dt LM 4
32.Os 32.Os
33.Sh NAME 33.Sh NAME
34.Nm lm 34.Nm lm
35.Nd National Semiconductor LM78, LM79 and compatible hardware monitors 35.Nd National Semiconductor LM78, LM79 and compatible hardware monitors
36.Sh SYNOPSIS 36.Sh SYNOPSIS
37.Cd "lm0 at isa? port 0x280 flags 0x00" 37.Cd "lm0 at isa? port 0x280 flags 0x00"
38.Cd "lm1 at isa? port 0x290 flags 0x00" 38.Cd "lm1 at isa? port 0x290 flags 0x00"
39.Cd "lm2 at isa? port 0x310 flags 0x00" 39.Cd "lm2 at isa? port 0x310 flags 0x00"
40.Cd "lm3 at isa? port 0xa00 flags 0x00" 40.Cd "lm3 at isa? port 0xa00 flags 0x00"
41.Cd "lm0 at pnpbios0 index ? flags 0x00" 41.Cd "lm0 at pnpbios0 index ? flags 0x00"
42.Cd "lm0 at iic? addr 0x2e flags 0x00" 42.Cd "lm0 at iic? addr 0x2e flags 0x00"
43.Cd "lm* at wbsio?" 43.Cd "lm* at wbsio?"
44.Sh DESCRIPTION 44.Sh DESCRIPTION
45The 45The
46.Nm 46.Nm
47driver provides support for the 47driver provides support for the
48.Tn National Semiconductor 48.Tn National Semiconductor
49LM series hardware monitors and register compatible chips to be used with 49LM series hardware monitors and register compatible chips to be used with
50the 50the
51.Xr envsys 4 51.Xr envsys 4
52API. 52API.
53.Pp 53.Pp
54Most supported devices possess 11 sensors: 54The original LM78 hardware monitor supports 11 sensors:
55.Bl -column "Sensor" "Units" "Typical" -offset indent 55.Bl -column "Sensor" "Units" "Typical" -offset indent
56.It Sy "Sensor" Ta Sy "Units" Ta Sy "Typical Use" 56.It Sy "Sensor" Ta Sy "Units" Ta Sy "Typical Use"
57.It Li "IN0" Ta "uV DC" Ta "Core voltage" 57.It Li "IN0" Ta "uV DC" Ta "Core voltage"
58.It Li "IN1" Ta "uV DC" Ta "unknown" 58.It Li "IN1" Ta "uV DC" Ta "unknown"
59.It Li "IN2" Ta "uV DC" Ta "+3.3V" 59.It Li "IN2" Ta "uV DC" Ta "+3.3V"
60.It Li "IN3" Ta "uV DC" Ta "+5V" 60.It Li "IN3" Ta "uV DC" Ta "+5V"
61.It Li "IN4" Ta "uV DC" Ta "+12V" 61.It Li "IN4" Ta "uV DC" Ta "+12V"
62.It Li "IN5" Ta "uV DC" Ta "-12V" 62.It Li "IN5" Ta "uV DC" Ta "-12V"
63.It Li "IN6" Ta "uV DC" Ta "-5V" 63.It Li "IN6" Ta "uV DC" Ta "-5V"
64.It Li "Temp" Ta "uK" Ta "Motherboard Temperature" 64.It Li "Temp" Ta "uK" Ta "Motherboard Temperature"
65.It Li "Fan0" Ta "RPM" Ta "Fan" 65.It Li "Fan0" Ta "RPM" Ta "Fan"
66.It Li "Fan1" Ta "RPM" Ta "Chassis Fan" 66.It Li "Fan1" Ta "RPM" Ta "Chassis Fan"
67.It Li "Fan2" Ta "RPM" Ta "Fan" 67.It Li "Fan2" Ta "RPM" Ta "Fan"
68.El 68.El
69for some devices (most Winbond devices) sensor names and numbers will be 69For other devices, sensors' names and numbers will be different.
70different. 
71.Pp 70.Pp
72Due to hardware limitations, fresh sensor data is only available every 71Due to hardware limitations, fresh sensor data is only available every
732 seconds. 722 seconds.
74.Sh HARDWARE 73.Sh HARDWARE
75Chips supported by the 74Chips supported by the
76.Nm 75.Nm
77driver include: 76driver include:
78.Pp 
79.Bl -item -offset indent 77.Bl -item -offset indent
80.It 78.It
81.Tn National Semiconductor 79.Tn National Semiconductor
82.Em LM78 , 80.Em LM78 ,
83.Em LM78-J , 81.Em LM78-J ,
84.Em LM79 82.Em LM79
85and 83and
86.Em LM81 . 84.Em LM81 .
87.It 85.It
 86.Tn Nuvoton
 87.Em NCT5104D ,
 88.Em NCT6775F ,
 89.Em NCT6776F ,
 90.Em NCT6102D ,
 91.Em NCT6104D ,
 92.Em NCT6106D ,
 93.Em NCT6779D ,
 94.Em NCT6791D ,
 95.Em NCT6792D ,
 96.Em NCT6793D ,
 97.Em NCT6795D .
 98.It
88.Tn Winbond 99.Tn Winbond
89.Em W83627HF* , 100.Em W83627HF* ,
90.Em W83627THF* , 101.Em W83627THF* ,
91.Em W83627EHF* , 102.Em W83627EHF* ,
92.Em W83627DHG* , 103.Em W83627DHG* ,
93.Em W83637HF* , 104.Em W83637HF* ,
94.Em W83697HF* , 105.Em W83697HF* ,
95.Em W83781D , 106.Em W83781D ,
96.Em W83782D* , 107.Em W83782D* ,
97.Em W83783S* , 108.Em W83783S* ,
98.Em W83791D* , 109.Em W83791D* ,
99.Em W83791SD 110.Em W83791SD
100and 111and
@@ -114,17 +125,21 @@ sensor: @@ -114,17 +125,21 @@ sensor:
114.It Li "1" Ta "Pentium-II diode" 125.It Li "1" Ta "Pentium-II diode"
115.It Li "2" Ta "2N3904 Bipolar" 126.It Li "2" Ta "2N3904 Bipolar"
116.It Li "4" Ta "Thermistor diode" 127.It Li "4" Ta "Thermistor diode"
117.El 128.El
118.Sh SEE ALSO 129.Sh SEE ALSO
119.Xr envsys 4 , 130.Xr envsys 4 ,
120.Xr wbsio 4 , 131.Xr wbsio 4 ,
121.Xr envstat 8 132.Xr envstat 8
122.Sh HISTORY 133.Sh HISTORY
123The 134The
124.Nm 135.Nm
125device appeared in 136device appeared in
126.Nx 1.5 . 137.Nx 1.5 .
 138.Sh CAVEATS
 139Some vendors connect these chips to non-standard thermal diodes and
 140resistors.
 141This will result in bogus sensor values.
127.Sh BUGS 142.Sh BUGS
128Interrupt support is unimplemented. 143Interrupt support is unimplemented.
129.Pp 144.Pp
130There are currently no known pnpbios IDs assigned to LM chips. 145There are currently no known pnpbios IDs assigned to LM chips.

cvs diff -r1.3 -r1.3.18.1 src/share/man/man4/wbsio.4 (expand / switch to unified diff)

--- src/share/man/man4/wbsio.4 2014/03/18 18:20:39 1.3
+++ src/share/man/man4/wbsio.4 2017/11/22 14:56:30 1.3.18.1
@@ -1,44 +1,45 @@ @@ -1,44 +1,45 @@
1.\" $NetBSD: wbsio.4,v 1.3 2014/03/18 18:20:39 riastradh Exp $ 1.\" $NetBSD: wbsio.4,v 1.3.18.1 2017/11/22 14:56:30 martin Exp $
2.\" $OpenBSD: wbsio.4,v 1.2 2008/02/17 16:48:47 jmc Exp $ 2.\" $OpenBSD: wbsio.4,v 1.2 2008/02/17 16:48:47 jmc Exp $
3.\" 3.\"
4.\" Copyright (c) 2008 Mark Kettenis <kettenis@openbsd.org> 4.\" Copyright (c) 2008 Mark Kettenis <kettenis@openbsd.org>
5.\" 5.\"
6.\" Permission to use, copy, modify, and distribute this software for any 6.\" Permission to use, copy, modify, and distribute this software for any
7.\" purpose with or without fee is hereby granted, provided that the above 7.\" purpose with or without fee is hereby granted, provided that the above
8.\" copyright notice and this permission notice appear in all copies. 8.\" copyright notice and this permission notice appear in all copies.
9.\" 9.\"
10.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17.\" 17.\"
18.Dd February 16, 2010 18.Dd July 12, 2017
19.Dt WBSIO 4 19.Dt WBSIO 4
20.Os 20.Os
21.Sh NAME 21.Sh NAME
22.Nm wbsio 22.Nm wbsio
23.Nd Winbond LPC Super I/O 23.Nd Winbond (Nuvoton) LPC Super I/O
24.Sh SYNOPSIS 24.Sh SYNOPSIS
25.Cd "wbsio* at isa? port 0x2e" 25.Cd "wbsio* at isa? port 0x2e"
26.Cd "wbsio* at isa? port 0x4e" 26.Cd "wbsio* at isa? port 0x4e"
27.Cd "lm* at wbsio?" 27.Cd "lm* at wbsio?"
28.Sh DESCRIPTION 28.Sh DESCRIPTION
29The 29The
30.Nm 30.Nm
31driver provides support for the Winbond LPC Super I/O ICs. 31driver provides support for the Winbond (was spun off as Nuvoton) LPC Super I/O
 32ICs.
32Only the hardware monitoring function is currently supported. 33Only the hardware monitoring function is currently supported.
33.Pp 34.Pp
34Support for the hardware monitor function is provided through the 35Support for the hardware monitor function is provided through the
35.Xr lm 4 36.Xr lm 4
36driver. 37driver.
37.Sh SEE ALSO 38.Sh SEE ALSO
38.Xr intro 4 , 39.Xr intro 4 ,
39.Xr isa 4 , 40.Xr isa 4 ,
40.Xr lm 4 41.Xr lm 4
41.Sh HISTORY 42.Sh HISTORY
42The 43The
43.Nm 44.Nm
44driver first appeared in 45driver first appeared in

cvs diff -r1.2 -r1.2.80.1 src/sys/dev/i2c/lm_i2c.c (expand / switch to unified diff)

--- src/sys/dev/i2c/lm_i2c.c 2008/10/13 11:16:00 1.2
+++ src/sys/dev/i2c/lm_i2c.c 2017/11/22 14:56:30 1.2.80.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lm_i2c.c,v 1.2 2008/10/13 11:16:00 pgoyette Exp $ */ 1/* $NetBSD: lm_i2c.c,v 1.2.80.1 2017/11/22 14:56:30 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000 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 Bill Squier. 8 * by Bill Squier.
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.
@@ -20,73 +20,73 @@ @@ -20,73 +20,73 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: lm_i2c.c,v 1.2 2008/10/13 11:16:00 pgoyette Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: lm_i2c.c,v 1.2.80.1 2017/11/22 14:56:30 martin Exp $");
34 34
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/systm.h> 36#include <sys/systm.h>
37#include <sys/kernel.h> 37#include <sys/kernel.h>
38#include <sys/device.h> 38#include <sys/device.h>
39#include <sys/conf.h> 39#include <sys/conf.h>
40 40
41#include <dev/i2c/i2cvar.h> 41#include <dev/i2c/i2cvar.h>
42 42
43#include <dev/sysmon/sysmonvar.h> 43#include <dev/sysmon/sysmonvar.h>
44 44
45#include <dev/ic/nslm7xvar.h> 45#include <dev/ic/nslm7xvar.h>
46 46
47int lm_i2c_match(device_t, cfdata_t, void *); 47int lm_i2c_match(device_t, cfdata_t, void *);
48void lm_i2c_attach(device_t, device_t, void *); 48void lm_i2c_attach(device_t, device_t, void *);
49int lm_i2c_detach(device_t, int); 49int lm_i2c_detach(device_t, int);
50 50
51uint8_t lm_i2c_readreg(struct lm_softc *, int); 51uint8_t lm_i2c_readreg(struct lm_softc *, int);
52void lm_i2c_writereg(struct lm_softc *, int, int); 52void lm_i2c_writereg(struct lm_softc *, int, uint8_t);
53 53
54struct lm_i2c_softc { 54struct lm_i2c_softc {
55 struct lm_softc sc_lmsc; 55 struct lm_softc sc_lmsc;
56 i2c_tag_t sc_tag; 56 i2c_tag_t sc_tag;
57 i2c_addr_t sc_addr; 57 i2c_addr_t sc_addr;
58}; 58};
59 59
60CFATTACH_DECL_NEW(lm_iic, sizeof(struct lm_i2c_softc), 60CFATTACH_DECL_NEW(lm_iic, sizeof(struct lm_i2c_softc),
61 lm_i2c_match, lm_i2c_attach, lm_i2c_detach, NULL); 61 lm_i2c_match, lm_i2c_attach, lm_i2c_detach, NULL);
62 62
63int 63int
64lm_i2c_match(device_t parent, cfdata_t match, void *aux) 64lm_i2c_match(device_t parent, cfdata_t match, void *aux)
65{ 65{
66 struct i2c_attach_args *ia = aux; 66 struct i2c_attach_args *ia = aux;
67 int rv = 0; 67 int rv = 0;
68 struct lm_i2c_softc sc; 68 struct lm_i2c_softc sc;
69 69
70 /* Must supply an address */ 70 /* Must supply an address */
71 if (ia->ia_addr < 1) 71 if (ia->ia_addr < 1)
72 return 0; 72 return 0;
73 73
74 /* Bus independent probe */ 74 /* Bus independent probe */
75 sc.sc_lmsc.lm_writereg = lm_i2c_writereg; 75 sc.sc_lmsc.lm_writereg = lm_i2c_writereg;
76 sc.sc_lmsc.lm_readreg = lm_i2c_readreg; 76 sc.sc_lmsc.lm_readreg = lm_i2c_readreg;
77 sc.sc_tag = ia->ia_tag; 77 sc.sc_tag = ia->ia_tag;
78 sc.sc_addr = ia->ia_addr; 78 sc.sc_addr = ia->ia_addr;
79 rv = lm_probe(&sc.sc_lmsc); 79 rv = lm_match(&sc.sc_lmsc);
80 80
81 return rv; 81 return rv;
82} 82}
83 83
84 84
85void 85void
86lm_i2c_attach(device_t parent, device_t self, void *aux) 86lm_i2c_attach(device_t parent, device_t self, void *aux)
87{ 87{
88 struct lm_i2c_softc *sc = device_private(self); 88 struct lm_i2c_softc *sc = device_private(self);
89 struct i2c_attach_args *ia = aux; 89 struct i2c_attach_args *ia = aux;
90 90
91 sc->sc_tag = ia->ia_tag; 91 sc->sc_tag = ia->ia_tag;
92 sc->sc_addr = ia->ia_addr; 92 sc->sc_addr = ia->ia_addr;
@@ -117,27 +117,27 @@ lm_i2c_readreg(struct lm_softc *lmsc, in @@ -117,27 +117,27 @@ lm_i2c_readreg(struct lm_softc *lmsc, in
117 iic_acquire_bus(sc->sc_tag, 0); 117 iic_acquire_bus(sc->sc_tag, 0);
118 118
119 cmd = reg; 119 cmd = reg;
120 iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, 120 iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
121 sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0); 121 sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0);
122 122
123 iic_release_bus(sc->sc_tag, 0); 123 iic_release_bus(sc->sc_tag, 0);
124 124
125 return data; 125 return data;
126} 126}
127 127
128 128
129void 129void
130lm_i2c_writereg(struct lm_softc *lmsc, int reg, int val) 130lm_i2c_writereg(struct lm_softc *lmsc, int reg, uint8_t val)
131{ 131{
132 struct lm_i2c_softc *sc = (struct lm_i2c_softc *)lmsc; 132 struct lm_i2c_softc *sc = (struct lm_i2c_softc *)lmsc;
133 uint8_t cmd, data; 133 uint8_t cmd, data;
134 134
135 iic_acquire_bus(sc->sc_tag, 0); 135 iic_acquire_bus(sc->sc_tag, 0);
136 136
137 cmd = reg; 137 cmd = reg;
138 data = val; 138 data = val;
139 iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, 139 iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP,
140 sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0); 140 sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0);
141 141
142 iic_release_bus(sc->sc_tag, 0); 142 iic_release_bus(sc->sc_tag, 0);
143} 143}

cvs diff -r1.64 -r1.64.10.1 src/sys/dev/ic/nslm7x.c (expand / switch to unified diff)

--- src/sys/dev/ic/nslm7x.c 2016/06/01 08:06:38 1.64
+++ src/sys/dev/ic/nslm7x.c 2017/11/22 14:56:30 1.64.10.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: nslm7x.c,v 1.64 2016/06/01 08:06:38 pgoyette Exp $ */ 1/* $NetBSD: nslm7x.c,v 1.64.10.1 2017/11/22 14:56:30 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000 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 Bill Squier. 8 * by Bill Squier.
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.
@@ -20,103 +20,112 @@ @@ -20,103 +20,112 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: nslm7x.c,v 1.64 2016/06/01 08:06:38 pgoyette Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: nslm7x.c,v 1.64.10.1 2017/11/22 14:56:30 martin Exp $");
34 34
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/systm.h> 36#include <sys/systm.h>
37#include <sys/kernel.h> 37#include <sys/kernel.h>
38#include <sys/proc.h> 38#include <sys/proc.h>
39#include <sys/device.h> 39#include <sys/device.h>
40#include <sys/module.h> 40#include <sys/module.h>
41#include <sys/conf.h> 41#include <sys/conf.h>
42#include <sys/time.h> 42#include <sys/time.h>
43 43
44#include <sys/bus.h> 44#include <sys/bus.h>
45 45
46#include <dev/isa/isareg.h> 46#include <dev/isa/isareg.h>
47#include <dev/isa/isavar.h> 47#include <dev/isa/isavar.h>
 48#include <dev/isa/wbsioreg.h>
48 49
49#include <dev/sysmon/sysmonvar.h> 50#include <dev/sysmon/sysmonvar.h>
50 51
51#include <dev/ic/nslm7xvar.h> 52#include <dev/ic/nslm7xvar.h>
52 53
53#include <sys/intr.h> 54#include <sys/intr.h>
54 55
55#if defined(LMDEBUG) 56#if defined(LMDEBUG)
56#define DPRINTF(x) do { printf x; } while (0) 57#define DPRINTF(x) do { printf x; } while (0)
57#else 58#else
58#define DPRINTF(x) 59#define DPRINTF(x)
59#endif 60#endif
60 61
61/* 62/*
62 * LM78-compatible chips can typically measure voltages up to 4.096 V. 63 * LM78-compatible chips can typically measure voltages up to 4.096 V.
63 * To measure higher voltages the input is attenuated with (external) 64 * To measure higher voltages the input is attenuated with (external)
64 * resistors. Negative voltages are measured using inverting op amps 65 * resistors. Negative voltages are measured using inverting op amps
65 * and resistors. So we have to convert the sensor values back to 66 * and resistors. So we have to convert the sensor values back to
66 * real voltages by applying the appropriate resistor factor. 67 * real voltages by applying the appropriate resistor factor.
67 */ 68 */
68#define RFACT_NONE 10000 69#define RFACT_NONE 10000
69#define RFACT(x, y) (RFACT_NONE * ((x) + (y)) / (y)) 70#define RFACT(x, y) (RFACT_NONE * ((x) + (y)) / (y))
70#define NRFACT(x, y) (-RFACT_NONE * (x) / (y)) 71#define NRFACT(x, y) (-RFACT_NONE * (x) / (y))
71 72
72#define LM_REFRESH_TIMO (2 * hz) /* 2 seconds */ 73#define LM_REFRESH_TIMO (2 * hz) /* 2 seconds */
73 74
74static int lm_match(struct lm_softc *); 75static const struct wb_product *wb_lookup(struct lm_softc *,
 76 const struct wb_product *, uint16_t);
75static int wb_match(struct lm_softc *); 77static int wb_match(struct lm_softc *);
 78static int wb_attach(struct lm_softc *);
 79static int nslm_match(struct lm_softc *);
 80static int nslm_attach(struct lm_softc *);
76static int def_match(struct lm_softc *); 81static int def_match(struct lm_softc *);
 82static int def_attach(struct lm_softc *);
77static void wb_temp_diode_type(struct lm_softc *, int); 83static void wb_temp_diode_type(struct lm_softc *, int);
 84static uint16_t wb_read_vendorid(struct lm_softc *);
78 85
79static void lm_refresh(void *); 86static void lm_refresh(void *);
80 87
81static void lm_generic_banksel(struct lm_softc *, int); 88static void lm_generic_banksel(struct lm_softc *, uint8_t);
82static void lm_setup_sensors(struct lm_softc *, struct lm_sensor *); 89static void lm_setup_sensors(struct lm_softc *, const struct lm_sensor *);
83static void lm_refresh_sensor_data(struct lm_softc *); 90static void lm_refresh_sensor_data(struct lm_softc *);
84static void lm_refresh_volt(struct lm_softc *, int); 91static void lm_refresh_volt(struct lm_softc *, int);
85static void lm_refresh_temp(struct lm_softc *, int); 92static void lm_refresh_temp(struct lm_softc *, int);
86static void lm_refresh_fanrpm(struct lm_softc *, int); 93static void lm_refresh_fanrpm(struct lm_softc *, int);
87 94
88static void wb_refresh_sensor_data(struct lm_softc *); 95static void wb_refresh_sensor_data(struct lm_softc *);
89static void wb_w83637hf_refresh_vcore(struct lm_softc *, int); 96static void wb_w83637hf_refresh_vcore(struct lm_softc *, int);
90static void wb_refresh_nvolt(struct lm_softc *, int); 97static void wb_refresh_nvolt(struct lm_softc *, int);
91static void wb_w83627ehf_refresh_nvolt(struct lm_softc *, int); 98static void wb_w83627ehf_refresh_nvolt(struct lm_softc *, int);
92static void wb_refresh_temp(struct lm_softc *, int); 99static void wb_refresh_temp(struct lm_softc *, int);
93static void wb_refresh_fanrpm(struct lm_softc *, int); 100static void wb_refresh_fanrpm(struct lm_softc *, int);
94static void wb_w83792d_refresh_fanrpm(struct lm_softc *, int); 101static void wb_w83792d_refresh_fanrpm(struct lm_softc *, int);
95static void wb_nct6776f_refresh_fanrpm(struct lm_softc *, int); 102static void wb_nct6776f_refresh_fanrpm(struct lm_softc *, int);
 103
96static void as_refresh_temp(struct lm_softc *, int); 104static void as_refresh_temp(struct lm_softc *, int);
97 105
98struct lm_chip { 106struct lm_chip {
99 int (*chip_match)(struct lm_softc *); 107 int (*chip_match)(struct lm_softc *);
 108 int (*chip_attach)(struct lm_softc *);
100}; 109};
101 110
102static struct lm_chip lm_chips[] = { 111static struct lm_chip lm_chips[] = {
103 { wb_match }, 112 { wb_match, wb_attach },
104 { lm_match }, 113 { nslm_match, nslm_attach },
105 { def_match } /* Must be last */ 114 { def_match, def_attach } /* Must be last */
106}; 115};
107 116
108/* LM78/78J/79/81 */ 117/* LM78/78J/79/81 */
109static struct lm_sensor lm78_sensors[] = { 118static const struct lm_sensor lm78_sensors[] = {
110 /* Voltage */ 119 /* Voltage */
111 { 120 {
112 .desc = "VCore A", 121 .desc = "VCore A",
113 .type = ENVSYS_SVOLTS_DC, 122 .type = ENVSYS_SVOLTS_DC,
114 .bank = 0, 123 .bank = 0,
115 .reg = 0x20, 124 .reg = 0x20,
116 .refresh = lm_refresh_volt, 125 .refresh = lm_refresh_volt,
117 .rfact = RFACT_NONE 126 .rfact = RFACT_NONE
118 }, 127 },
119 { 128 {
120 .desc = "VCore B", 129 .desc = "VCore B",
121 .type = ENVSYS_SVOLTS_DC, 130 .type = ENVSYS_SVOLTS_DC,
122 .bank = 0, 131 .bank = 0,
@@ -195,27 +204,27 @@ static struct lm_sensor lm78_sensors[] = @@ -195,27 +204,27 @@ static struct lm_sensor lm78_sensors[] =
195 { 204 {
196 .desc = "Fan2", 205 .desc = "Fan2",
197 .type = ENVSYS_SFANRPM, 206 .type = ENVSYS_SFANRPM,
198 .bank = 0, 207 .bank = 0,
199 .reg = 0x2a, 208 .reg = 0x2a,
200 .refresh = lm_refresh_fanrpm, 209 .refresh = lm_refresh_fanrpm,
201 .rfact = 0 210 .rfact = 0
202 }, 211 },
203 212
204 { .desc = NULL } 213 { .desc = NULL }
205}; 214};
206 215
207/* W83627HF */ 216/* W83627HF */
208static struct lm_sensor w83627hf_sensors[] = { 217static const struct lm_sensor w83627hf_sensors[] = {
209 /* Voltage */ 218 /* Voltage */
210 { 219 {
211 .desc = "VCore A", 220 .desc = "VCore A",
212 .type = ENVSYS_SVOLTS_DC, 221 .type = ENVSYS_SVOLTS_DC,
213 .bank = 0, 222 .bank = 0,
214 .reg = 0x20, 223 .reg = 0x20,
215 .refresh = lm_refresh_volt, 224 .refresh = lm_refresh_volt,
216 .rfact = RFACT_NONE 225 .rfact = RFACT_NONE
217 }, 226 },
218 { 227 {
219 .desc = "VCore B", 228 .desc = "VCore B",
220 .type = ENVSYS_SVOLTS_DC, 229 .type = ENVSYS_SVOLTS_DC,
221 .bank = 0, 230 .bank = 0,
@@ -334,27 +343,27 @@ static struct lm_sensor w83627hf_sensors @@ -334,27 +343,27 @@ static struct lm_sensor w83627hf_sensors
334 343
335 { .desc = NULL } 344 { .desc = NULL }
336}; 345};
337 346
338/* W8627EHF */ 347/* W8627EHF */
339 348
340/* 349/*
341 * The W83627EHF can measure voltages up to 2.048 V instead of the 350 * The W83627EHF can measure voltages up to 2.048 V instead of the
342 * traditional 4.096 V. For measuring positive voltages, this can be 351 * traditional 4.096 V. For measuring positive voltages, this can be
343 * accounted for by halving the resistor factor. Negative voltages 352 * accounted for by halving the resistor factor. Negative voltages
344 * need special treatment, also because the reference voltage is 2.048 V 353 * need special treatment, also because the reference voltage is 2.048 V
345 * instead of the traditional 3.6 V. 354 * instead of the traditional 3.6 V.
346 */ 355 */
347static struct lm_sensor w83627ehf_sensors[] = { 356static const struct lm_sensor w83627ehf_sensors[] = {
348 /* Voltage */ 357 /* Voltage */
349 { 358 {
350 .desc = "VCore", 359 .desc = "VCore",
351 .type = ENVSYS_SVOLTS_DC, 360 .type = ENVSYS_SVOLTS_DC,
352 .bank = 0, 361 .bank = 0,
353 .reg = 0x20, 362 .reg = 0x20,
354 .refresh = lm_refresh_volt, 363 .refresh = lm_refresh_volt,
355 .rfact = RFACT_NONE / 2 364 .rfact = RFACT_NONE / 2
356 }, 365 },
357 { 366 {
358 .desc = "+12V", 367 .desc = "+12V",
359 .type = ENVSYS_SVOLTS_DC, 368 .type = ENVSYS_SVOLTS_DC,
360 .bank = 0, 369 .bank = 0,
@@ -473,27 +482,27 @@ static struct lm_sensor w83627ehf_sensor @@ -473,27 +482,27 @@ static struct lm_sensor w83627ehf_sensor
473 { 482 {
474 .desc = "Fan2", 483 .desc = "Fan2",
475 .type = ENVSYS_SFANRPM, 484 .type = ENVSYS_SFANRPM,
476 .bank = 0, 485 .bank = 0,
477 .reg = 0x2a, 486 .reg = 0x2a,
478 .refresh = wb_refresh_fanrpm, 487 .refresh = wb_refresh_fanrpm,
479 .rfact = 0 488 .rfact = 0
480 }, 489 },
481 490
482 { .desc = NULL } 491 { .desc = NULL }
483}; 492};
484 493
485/* W83627DHG */ 494/* W83627DHG */
486static struct lm_sensor w83627dhg_sensors[] = { 495static const struct lm_sensor w83627dhg_sensors[] = {
487 /* Voltage */ 496 /* Voltage */
488 { 497 {
489 .desc = "VCore", 498 .desc = "VCore",
490 .type = ENVSYS_SVOLTS_DC, 499 .type = ENVSYS_SVOLTS_DC,
491 .bank = 0, 500 .bank = 0,
492 .reg = 0x20, 501 .reg = 0x20,
493 .refresh = lm_refresh_volt, 502 .refresh = lm_refresh_volt,
494 .rfact = RFACT_NONE / 2 503 .rfact = RFACT_NONE / 2
495 }, 504 },
496 { 505 {
497 .desc = "+12V", 506 .desc = "+12V",
498 .type = ENVSYS_SVOLTS_DC, 507 .type = ENVSYS_SVOLTS_DC,
499 .bank = 0, 508 .bank = 0,
@@ -604,27 +613,27 @@ static struct lm_sensor w83627dhg_sensor @@ -604,27 +613,27 @@ static struct lm_sensor w83627dhg_sensor
604 { 613 {
605 .desc = "Aux Fan", 614 .desc = "Aux Fan",
606 .type = ENVSYS_SFANRPM, 615 .type = ENVSYS_SFANRPM,
607 .bank = 0, 616 .bank = 0,
608 .reg = 0x2a, 617 .reg = 0x2a,
609 .refresh = wb_refresh_fanrpm, 618 .refresh = wb_refresh_fanrpm,
610 .rfact = 0 619 .rfact = 0
611 }, 620 },
612 621
613 { .desc = NULL } 622 { .desc = NULL }
614}; 623};
615 624
616/* W83637HF */ 625/* W83637HF */
617static struct lm_sensor w83637hf_sensors[] = { 626static const struct lm_sensor w83637hf_sensors[] = {
618 /* Voltage */ 627 /* Voltage */
619 { 628 {
620 .desc = "VCore", 629 .desc = "VCore",
621 .type = ENVSYS_SVOLTS_DC, 630 .type = ENVSYS_SVOLTS_DC,
622 .bank = 0, 631 .bank = 0,
623 .reg = 0x20, 632 .reg = 0x20,
624 .refresh = wb_w83637hf_refresh_vcore, 633 .refresh = wb_w83637hf_refresh_vcore,
625 .rfact = 0 634 .rfact = 0
626 }, 635 },
627 { 636 {
628 .desc = "+12V", 637 .desc = "+12V",
629 .type = ENVSYS_SVOLTS_DC, 638 .type = ENVSYS_SVOLTS_DC,
630 .bank = 0, 639 .bank = 0,
@@ -719,27 +728,27 @@ static struct lm_sensor w83637hf_sensors @@ -719,27 +728,27 @@ static struct lm_sensor w83637hf_sensors
719 { 728 {
720 .desc = "Fan2", 729 .desc = "Fan2",
721 .type = ENVSYS_SFANRPM, 730 .type = ENVSYS_SFANRPM,
722 .bank = 0, 731 .bank = 0,
723 .reg = 0x2a, 732 .reg = 0x2a,
724 .refresh = wb_refresh_fanrpm, 733 .refresh = wb_refresh_fanrpm,
725 .rfact = 0 734 .rfact = 0
726 }, 735 },
727 736
728 { .desc = NULL } 737 { .desc = NULL }
729}; 738};
730 739
731/* W83697HF */ 740/* W83697HF */
732static struct lm_sensor w83697hf_sensors[] = { 741static const struct lm_sensor w83697hf_sensors[] = {
733 /* Voltage */ 742 /* Voltage */
734 { 743 {
735 .desc = "VCore", 744 .desc = "VCore",
736 .type = ENVSYS_SVOLTS_DC, 745 .type = ENVSYS_SVOLTS_DC,
737 .bank = 0, 746 .bank = 0,
738 .reg = 0x20, 747 .reg = 0x20,
739 .refresh = lm_refresh_volt, 748 .refresh = lm_refresh_volt,
740 .rfact = RFACT_NONE 749 .rfact = RFACT_NONE
741 }, 750 },
742 { 751 {
743 .desc = "+3.3V", 752 .desc = "+3.3V",
744 .type = ENVSYS_SVOLTS_DC, 753 .type = ENVSYS_SVOLTS_DC,
745 .bank = 0, 754 .bank = 0,
@@ -832,27 +841,27 @@ static struct lm_sensor w83697hf_sensors @@ -832,27 +841,27 @@ static struct lm_sensor w83697hf_sensors
832 .rfact = 0 841 .rfact = 0
833 }, 842 },
834 843
835 { .desc = NULL } 844 { .desc = NULL }
836}; 845};
837 846
838/* W83781D */ 847/* W83781D */
839 848
840/* 849/*
841 * The datasheet doesn't mention the (internal) resistors used for the 850 * The datasheet doesn't mention the (internal) resistors used for the
842 * +5V, but using the values from the W83782D datasheets seems to 851 * +5V, but using the values from the W83782D datasheets seems to
843 * provide sensible results. 852 * provide sensible results.
844 */ 853 */
845static struct lm_sensor w83781d_sensors[] = { 854static const struct lm_sensor w83781d_sensors[] = {
846 /* Voltage */ 855 /* Voltage */
847 { 856 {
848 .desc = "VCore A", 857 .desc = "VCore A",
849 .type = ENVSYS_SVOLTS_DC, 858 .type = ENVSYS_SVOLTS_DC,
850 .bank = 0, 859 .bank = 0,
851 .reg = 0x20, 860 .reg = 0x20,
852 .refresh = lm_refresh_volt, 861 .refresh = lm_refresh_volt,
853 .rfact = RFACT_NONE 862 .rfact = RFACT_NONE
854 }, 863 },
855 { 864 {
856 .desc = "VCore B", 865 .desc = "VCore B",
857 .type = ENVSYS_SVOLTS_DC, 866 .type = ENVSYS_SVOLTS_DC,
858 .bank = 0, 867 .bank = 0,
@@ -947,27 +956,27 @@ static struct lm_sensor w83781d_sensors[ @@ -947,27 +956,27 @@ static struct lm_sensor w83781d_sensors[
947 { 956 {
948 .desc = "Fan2", 957 .desc = "Fan2",
949 .type = ENVSYS_SFANRPM, 958 .type = ENVSYS_SFANRPM,
950 .bank = 0, 959 .bank = 0,
951 .reg = 0x2a, 960 .reg = 0x2a,
952 .refresh = lm_refresh_fanrpm, 961 .refresh = lm_refresh_fanrpm,
953 .rfact = 0 962 .rfact = 0
954 }, 963 },
955 964
956 { .desc = NULL } 965 { .desc = NULL }
957}; 966};
958 967
959/* W83782D */ 968/* W83782D */
960static struct lm_sensor w83782d_sensors[] = { 969static const struct lm_sensor w83782d_sensors[] = {
961 /* Voltage */ 970 /* Voltage */
962 { 971 {
963 .desc = "VCore", 972 .desc = "VCore",
964 .type = ENVSYS_SVOLTS_DC, 973 .type = ENVSYS_SVOLTS_DC,
965 .bank = 0, 974 .bank = 0,
966 .reg = 0x20, 975 .reg = 0x20,
967 .refresh = lm_refresh_volt, 976 .refresh = lm_refresh_volt,
968 .rfact = RFACT_NONE 977 .rfact = RFACT_NONE
969 }, 978 },
970 { 979 {
971 .desc = "VINR0", 980 .desc = "VINR0",
972 .type = ENVSYS_SVOLTS_DC, 981 .type = ENVSYS_SVOLTS_DC,
973 .bank = 0, 982 .bank = 0,
@@ -1078,27 +1087,27 @@ static struct lm_sensor w83782d_sensors[ @@ -1078,27 +1087,27 @@ static struct lm_sensor w83782d_sensors[
1078 { 1087 {
1079 .desc = "Fan2", 1088 .desc = "Fan2",
1080 .type = ENVSYS_SFANRPM, 1089 .type = ENVSYS_SFANRPM,
1081 .bank = 0, 1090 .bank = 0,
1082 .reg = 0x2a, 1091 .reg = 0x2a,
1083 .refresh = wb_refresh_fanrpm, 1092 .refresh = wb_refresh_fanrpm,
1084 .rfact = 0 1093 .rfact = 0
1085 }, 1094 },
1086 1095
1087 { .desc = NULL } 1096 { .desc = NULL }
1088}; 1097};
1089 1098
1090/* W83783S */ 1099/* W83783S */
1091static struct lm_sensor w83783s_sensors[] = { 1100static const struct lm_sensor w83783s_sensors[] = {
1092 /* Voltage */ 1101 /* Voltage */
1093 { 1102 {
1094 .desc = "VCore", 1103 .desc = "VCore",
1095 .type = ENVSYS_SVOLTS_DC, 1104 .type = ENVSYS_SVOLTS_DC,
1096 .bank = 0, 1105 .bank = 0,
1097 .reg = 0x20, 1106 .reg = 0x20,
1098 .refresh = lm_refresh_volt, 1107 .refresh = lm_refresh_volt,
1099 .rfact = RFACT_NONE 1108 .rfact = RFACT_NONE
1100 }, 1109 },
1101 { 1110 {
1102 .desc = "+3.3V", 1111 .desc = "+3.3V",
1103 .type = ENVSYS_SVOLTS_DC, 1112 .type = ENVSYS_SVOLTS_DC,
1104 .bank = 0, 1113 .bank = 0,
@@ -1177,27 +1186,27 @@ static struct lm_sensor w83783s_sensors[ @@ -1177,27 +1186,27 @@ static struct lm_sensor w83783s_sensors[
1177 { 1186 {
1178 .desc = "Fan2", 1187 .desc = "Fan2",
1179 .type = ENVSYS_SFANRPM, 1188 .type = ENVSYS_SFANRPM,
1180 .bank = 0, 1189 .bank = 0,
1181 .reg = 0x2a, 1190 .reg = 0x2a,
1182 .refresh = wb_refresh_fanrpm, 1191 .refresh = wb_refresh_fanrpm,
1183 .rfact = 0 1192 .rfact = 0
1184 }, 1193 },
1185 1194
1186 { .desc = NULL } 1195 { .desc = NULL }
1187}; 1196};
1188 1197
1189/* W83791D */ 1198/* W83791D */
1190static struct lm_sensor w83791d_sensors[] = { 1199static const struct lm_sensor w83791d_sensors[] = {
1191 /* Voltage */ 1200 /* Voltage */
1192 { 1201 {
1193 .desc = "VCore", 1202 .desc = "VCore",
1194 .type = ENVSYS_SVOLTS_DC, 1203 .type = ENVSYS_SVOLTS_DC,
1195 .bank = 0, 1204 .bank = 0,
1196 .reg = 0x20, 1205 .reg = 0x20,
1197 .refresh = lm_refresh_volt, 1206 .refresh = lm_refresh_volt,
1198 .rfact = 10000 1207 .rfact = 10000
1199 }, 1208 },
1200 { 1209 {
1201 .desc = "VINR0", 1210 .desc = "VINR0",
1202 .type = ENVSYS_SVOLTS_DC, 1211 .type = ENVSYS_SVOLTS_DC,
1203 .bank = 0, 1212 .bank = 0,
@@ -1332,27 +1341,27 @@ static struct lm_sensor w83791d_sensors[ @@ -1332,27 +1341,27 @@ static struct lm_sensor w83791d_sensors[
1332 { 1341 {
1333 .desc = "Fan4", 1342 .desc = "Fan4",
1334 .type = ENVSYS_SFANRPM, 1343 .type = ENVSYS_SFANRPM,
1335 .bank = 0, 1344 .bank = 0,
1336 .reg = 0xbb, 1345 .reg = 0xbb,
1337 .refresh = wb_refresh_fanrpm, 1346 .refresh = wb_refresh_fanrpm,
1338 .rfact = 0 1347 .rfact = 0
1339 }, 1348 },
1340 1349
1341 { .desc = NULL } 1350 { .desc = NULL }
1342}; 1351};
1343 1352
1344/* W83792D */ 1353/* W83792D */
1345static struct lm_sensor w83792d_sensors[] = { 1354static const struct lm_sensor w83792d_sensors[] = {
1346 /* Voltage */ 1355 /* Voltage */
1347 { 1356 {
1348 .desc = "VCore A", 1357 .desc = "VCore A",
1349 .type = ENVSYS_SVOLTS_DC, 1358 .type = ENVSYS_SVOLTS_DC,
1350 .bank = 0, 1359 .bank = 0,
1351 .reg = 0x20, 1360 .reg = 0x20,
1352 .refresh = lm_refresh_volt, 1361 .refresh = lm_refresh_volt,
1353 .rfact = RFACT_NONE 1362 .rfact = RFACT_NONE
1354 }, 1363 },
1355 { 1364 {
1356 .desc = "VCore B", 1365 .desc = "VCore B",
1357 .type = ENVSYS_SVOLTS_DC, 1366 .type = ENVSYS_SVOLTS_DC,
1358 .bank = 0, 1367 .bank = 0,
@@ -1495,27 +1504,27 @@ static struct lm_sensor w83792d_sensors[ @@ -1495,27 +1504,27 @@ static struct lm_sensor w83792d_sensors[
1495 { 1504 {
1496 .desc = "Fan6", 1505 .desc = "Fan6",
1497 .type = ENVSYS_SFANRPM, 1506 .type = ENVSYS_SFANRPM,
1498 .bank = 0, 1507 .bank = 0,
1499 .reg = 0xbe, 1508 .reg = 0xbe,
1500 .refresh = wb_w83792d_refresh_fanrpm, 1509 .refresh = wb_w83792d_refresh_fanrpm,
1501 .rfact = 0 1510 .rfact = 0
1502 }, 1511 },
1503 1512
1504 { .desc = NULL } 1513 { .desc = NULL }
1505}; 1514};
1506 1515
1507/* AS99127F */ 1516/* AS99127F */
1508static struct lm_sensor as99127f_sensors[] = { 1517static const struct lm_sensor as99127f_sensors[] = {
1509 /* Voltage */ 1518 /* Voltage */
1510 { 1519 {
1511 .desc = "VCore A", 1520 .desc = "VCore A",
1512 .type = ENVSYS_SVOLTS_DC, 1521 .type = ENVSYS_SVOLTS_DC,
1513 .bank = 0, 1522 .bank = 0,
1514 .reg = 0x20, 1523 .reg = 0x20,
1515 .refresh = lm_refresh_volt, 1524 .refresh = lm_refresh_volt,
1516 .rfact = RFACT_NONE 1525 .rfact = RFACT_NONE
1517 }, 1526 },
1518 { 1527 {
1519 .desc = "VCore B", 1528 .desc = "VCore B",
1520 .type = ENVSYS_SVOLTS_DC, 1529 .type = ENVSYS_SVOLTS_DC,
1521 .bank = 0, 1530 .bank = 0,
@@ -1609,28 +1618,28 @@ static struct lm_sensor as99127f_sensors @@ -1609,28 +1618,28 @@ static struct lm_sensor as99127f_sensors
1609 }, 1618 },
1610 { 1619 {
1611 .desc = "Fan2", 1620 .desc = "Fan2",
1612 .type = ENVSYS_SFANRPM, 1621 .type = ENVSYS_SFANRPM,
1613 .bank = 0, 1622 .bank = 0,
1614 .reg = 0x2a, 1623 .reg = 0x2a,
1615 .refresh = lm_refresh_fanrpm, 1624 .refresh = lm_refresh_fanrpm,
1616 .rfact = 0 1625 .rfact = 0
1617 }, 1626 },
1618 1627
1619 { .desc = NULL } 1628 { .desc = NULL }
1620}; 1629};
1621 1630
1622/* NCT6776F */ 1631/* NCT6776F */
1623static struct lm_sensor nct6776f_sensors[] = { 1632static const struct lm_sensor nct6776f_sensors[] = {
1624 /* Voltage */ 1633 /* Voltage */
1625 { 1634 {
1626 .desc = "VCore", 1635 .desc = "VCore",
1627 .type = ENVSYS_SVOLTS_DC, 1636 .type = ENVSYS_SVOLTS_DC,
1628 .bank = 0, 1637 .bank = 0,
1629 .reg = 0x20, 1638 .reg = 0x20,
1630 .refresh = lm_refresh_volt, 1639 .refresh = lm_refresh_volt,
1631 .rfact = RFACT_NONE / 2 1640 .rfact = RFACT_NONE / 2
1632 }, 1641 },
1633 { 1642 {
1634 .desc = "+12V", 1643 .desc = "+12V",
1635 .type = ENVSYS_SVOLTS_DC, 1644 .type = ENVSYS_SVOLTS_DC,
1636 .bank = 0, 1645 .bank = 0,
@@ -1757,79 +1766,497 @@ static struct lm_sensor nct6776f_sensors @@ -1757,79 +1766,497 @@ static struct lm_sensor nct6776f_sensors
1757 1766
1758 { 1767 {
1759 .desc = "Aux Fan2", 1768 .desc = "Aux Fan2",
1760 .type = ENVSYS_SFANRPM, 1769 .type = ENVSYS_SFANRPM,
1761 .bank = 6, 1770 .bank = 6,
1762 .reg = 0x5e, 1771 .reg = 0x5e,
1763 .refresh = wb_nct6776f_refresh_fanrpm, 1772 .refresh = wb_nct6776f_refresh_fanrpm,
1764 .rfact = 0 1773 .rfact = 0
1765 }, 1774 },
1766 1775
1767 { .desc = NULL } 1776 { .desc = NULL }
1768}; 1777};
1769 1778
 1779/* NCT610[246]D */
 1780static const struct lm_sensor nct6102d_sensors[] = {
 1781 /* Voltage */
 1782 {
 1783 .desc = "VCore",
 1784 .type = ENVSYS_SVOLTS_DC,
 1785 .bank = 0,
 1786 .reg = 0x00,
 1787 .refresh = lm_refresh_volt,
 1788 .rfact = RFACT_NONE
 1789 },
 1790 {
 1791 .desc = "VIN0",
 1792 .type = ENVSYS_SVOLTS_DC,
 1793 .bank = 0,
 1794 .reg = 0x01,
 1795 .refresh = lm_refresh_volt,
 1796 .rfact = RFACT_NONE
 1797 },
 1798 {
 1799 .desc = "AVCC",
 1800 .type = ENVSYS_SVOLTS_DC,
 1801 .bank = 0,
 1802 .reg = 0x02,
 1803 .refresh = lm_refresh_volt,
 1804 .rfact = RFACT(34, 34) / 2
 1805 },
 1806 {
 1807 .desc = "3VCC",
 1808 .type = ENVSYS_SVOLTS_DC,
 1809 .bank = 0,
 1810 .reg = 0x03,
 1811 .refresh = lm_refresh_volt,
 1812 .rfact = RFACT(34, 34) / 2
 1813 },
 1814 {
 1815 .desc = "VIN1",
 1816 .type = ENVSYS_SVOLTS_DC,
 1817 .bank = 0,
 1818 .reg = 0x04,
 1819 .refresh = lm_refresh_volt,
 1820 .rfact = RFACT_NONE
 1821 },
 1822 {
 1823 .desc = "VIN2",
 1824 .type = ENVSYS_SVOLTS_DC,
 1825 .bank = 0,
 1826 .reg = 0x05,
 1827 .refresh = lm_refresh_volt,
 1828 .rfact = RFACT(34, 34) / 2
 1829 },
 1830 {
 1831 .desc = "+3.3VSB",
 1832 .type = ENVSYS_SVOLTS_DC,
 1833 .bank = 0,
 1834 .reg = 0x07,
 1835 .refresh = lm_refresh_volt,
 1836 .rfact = RFACT(34, 34) / 2
 1837 },
 1838 {
 1839 .desc = "VBAT",
 1840 .type = ENVSYS_SVOLTS_DC,
 1841 .bank = 0,
 1842 .reg = 0x08,
 1843 .refresh = lm_refresh_volt,
 1844 .rfact = RFACT(34, 34) / 2
 1845 },
 1846 {
 1847 .desc = "VTT",
 1848 .type = ENVSYS_SVOLTS_DC,
 1849 .bank = 0,
 1850 .reg = 0x09,
 1851 .refresh = lm_refresh_volt,
 1852 .rfact = RFACT_NONE
 1853 },
 1854
 1855 /* Temperature */
 1856 {
 1857 .desc = "MB Temperature",
 1858 .type = ENVSYS_STEMP,
 1859 .bank = 0,
 1860 .reg = 0x18,
 1861 .refresh = lm_refresh_temp,
 1862 .rfact = 0
 1863 },
 1864 {
 1865 .desc = "CPU Temperature",
 1866 .type = ENVSYS_STEMP,
 1867 .bank = 0,
 1868 .reg = 0x19,
 1869 .refresh = lm_refresh_temp,
 1870 .rfact = 0
 1871 },
 1872 {
 1873 .desc = "Aux Temp",
 1874 .type = ENVSYS_STEMP,
 1875 .bank = 0,
 1876 .reg = 0x1a,
 1877 .refresh = lm_refresh_temp,
 1878 .rfact = 0
 1879 },
 1880
 1881 /* Fans */
 1882 {
 1883 .desc = "System Fan",
 1884 .type = ENVSYS_SFANRPM,
 1885 .bank = 0,
 1886 .reg = 0x30,
 1887 .refresh = wb_nct6776f_refresh_fanrpm,
 1888 .rfact = 0
 1889 },
 1890 {
 1891 .desc = "CPU Fan",
 1892 .type = ENVSYS_SFANRPM,
 1893 .bank = 0,
 1894 .reg = 0x32,
 1895 .refresh = wb_nct6776f_refresh_fanrpm,
 1896 .rfact = 0
 1897 },
 1898 {
 1899 .desc = "Aux Fan",
 1900 .type = ENVSYS_SFANRPM,
 1901 .bank = 0,
 1902 .reg = 0x34,
 1903 .refresh = wb_nct6776f_refresh_fanrpm,
 1904 .rfact = 0
 1905 },
 1906
 1907 { .desc = NULL }
 1908};
 1909
 1910/* NCT6779D */
 1911static const struct lm_sensor nct6779d_sensors[] = {
 1912 /* Voltage */
 1913 {
 1914 .desc = "VCore",
 1915 .type = ENVSYS_SVOLTS_DC,
 1916 .bank = 4,
 1917 .reg = 0x80,
 1918 .refresh = lm_refresh_volt,
 1919 .rfact = RFACT_NONE / 2
 1920 },
 1921 {
 1922 .desc = "VIN1",
 1923 .type = ENVSYS_SVOLTS_DC,
 1924 .bank = 4,
 1925 .reg = 0x81,
 1926 .refresh = lm_refresh_volt,
 1927 .rfact = RFACT(56, 10) / 2
 1928 },
 1929 {
 1930 .desc = "AVCC",
 1931 .type = ENVSYS_SVOLTS_DC,
 1932 .bank = 4,
 1933 .reg = 0x82,
 1934 .refresh = lm_refresh_volt,
 1935 .rfact = RFACT(34, 34) / 2
 1936 },
 1937 {
 1938 .desc = "+3.3V",
 1939 .type = ENVSYS_SVOLTS_DC,
 1940 .bank = 4,
 1941 .reg = 0x83,
 1942 .refresh = lm_refresh_volt,
 1943 .rfact = RFACT(34, 34) / 2
 1944 },
 1945 {
 1946 .desc = "VIN0",
 1947 .type = ENVSYS_SVOLTS_DC,
 1948 .bank = 4,
 1949 .reg = 0x84,
 1950 .refresh = lm_refresh_volt,
 1951 .rfact = RFACT(48600, 10000)
 1952 },
 1953 {
 1954 .desc = "VIN8",
 1955 .type = ENVSYS_SVOLTS_DC,
 1956 .bank = 4,
 1957 .reg = 0x85,
 1958 .refresh = lm_refresh_volt,
 1959 .rfact = RFACT_NONE / 2
 1960 },
 1961 {
 1962 .desc = "VIN4",
 1963 .type = ENVSYS_SVOLTS_DC,
 1964 .bank = 4,
 1965 .reg = 0x86,
 1966 .refresh = lm_refresh_volt,
 1967 .rfact = RFACT_NONE
 1968 },
 1969 {
 1970 .desc = "+3.3VSB",
 1971 .type = ENVSYS_SVOLTS_DC,
 1972 .bank = 4,
 1973 .reg = 0x87,
 1974 .refresh = lm_refresh_volt,
 1975 .rfact = RFACT(34, 34) / 2
 1976 },
 1977 {
 1978 .desc = "VBAT",
 1979 .type = ENVSYS_SVOLTS_DC,
 1980 .bank = 4,
 1981 .reg = 0x88,
 1982 .refresh = lm_refresh_volt,
 1983 .rfact = RFACT_NONE
 1984 },
 1985 {
 1986 .desc = "VTT",
 1987 .type = ENVSYS_SVOLTS_DC,
 1988 .bank = 4,
 1989 .reg = 0x89,
 1990 .refresh = lm_refresh_volt,
 1991 .rfact = RFACT_NONE
 1992 },
 1993 {
 1994 .desc = "VIN5",
 1995 .type = ENVSYS_SVOLTS_DC,
 1996 .bank = 4,
 1997 .reg = 0x8a,
 1998 .refresh = lm_refresh_volt,
 1999 .rfact = RFACT_NONE
 2000 },
 2001 {
 2002 .desc = "VIN6",
 2003 .type = ENVSYS_SVOLTS_DC,
 2004 .bank = 4,
 2005 .reg = 0x8b,
 2006 .refresh = lm_refresh_volt,
 2007 .rfact = RFACT_NONE
 2008 },
 2009 {
 2010 .desc = "VIN2",
 2011 .type = ENVSYS_SVOLTS_DC,
 2012 .bank = 4,
 2013 .reg = 0x8c,
 2014 .refresh = lm_refresh_volt,
 2015 .rfact = RFACT_NONE
 2016 },
 2017 {
 2018 .desc = "VIN3",
 2019 .type = ENVSYS_SVOLTS_DC,
 2020 .bank = 4,
 2021 .reg = 0x8d,
 2022 .refresh = lm_refresh_volt,
 2023 .rfact = RFACT(14414, 10000)
 2024 },
 2025 {
 2026 .desc = "VIN7",
 2027 .type = ENVSYS_SVOLTS_DC,
 2028 .bank = 4,
 2029 .reg = 0x8e,
 2030 .refresh = lm_refresh_volt,
 2031 .rfact = RFACT_NONE / 2
 2032 },
 2033
 2034 /* Temperature */
 2035 {
 2036 .desc = "MB Temperature",
 2037 .type = ENVSYS_STEMP,
 2038 .bank = 4,
 2039 .reg = 0x90,
 2040 .refresh = lm_refresh_temp,
 2041 .rfact = 0
 2042 },
 2043 {
 2044 .desc = "CPU Temperature",
 2045 .type = ENVSYS_STEMP,
 2046 .bank = 4,
 2047 .reg = 0x91,
 2048 .refresh = wb_refresh_temp,
 2049 .rfact = 0
 2050 },
 2051 {
 2052 .desc = "Aux Temp0",
 2053 .type = ENVSYS_STEMP,
 2054 .bank = 4,
 2055 .reg = 0x92,
 2056 .refresh = wb_refresh_temp,
 2057 .rfact = 0
 2058 },
 2059 {
 2060 .desc = "Aux Temp1",
 2061 .type = ENVSYS_STEMP,
 2062 .bank = 4,
 2063 .reg = 0x93,
 2064 .refresh = wb_refresh_temp,
 2065 .rfact = 0
 2066 },
 2067 {
 2068 .desc = "Aux Temp2",
 2069 .type = ENVSYS_STEMP,
 2070 .bank = 4,
 2071 .reg = 0x94,
 2072 .refresh = wb_refresh_temp,
 2073 .rfact = 0
 2074 },
 2075 {
 2076 .desc = "Aux Temp3",
 2077 .type = ENVSYS_STEMP,
 2078 .bank = 4,
 2079 .reg = 0x95,
 2080 .refresh = wb_refresh_temp,
 2081 .rfact = 0
 2082 },
 2083
 2084 /* Fans */
 2085 {
 2086 .desc = "System Fan",
 2087 .type = ENVSYS_SFANRPM,
 2088 .bank = 4,
 2089 .reg = 0xc0,
 2090 .refresh = wb_nct6776f_refresh_fanrpm,
 2091 .rfact = 0
 2092 },
 2093 {
 2094 .desc = "CPU Fan",
 2095 .type = ENVSYS_SFANRPM,
 2096 .bank = 4,
 2097 .reg = 0xc2,
 2098 .refresh = wb_nct6776f_refresh_fanrpm,
 2099 .rfact = 0
 2100 },
 2101 {
 2102 .desc = "Aux Fan0",
 2103 .type = ENVSYS_SFANRPM,
 2104 .bank = 4,
 2105 .reg = 0xc4,
 2106 .refresh = wb_nct6776f_refresh_fanrpm,
 2107 .rfact = 0
 2108 },
 2109 {
 2110 .desc = "Aux Fan1",
 2111 .type = ENVSYS_SFANRPM,
 2112 .bank = 4,
 2113 .reg = 0xc6,
 2114 .refresh = wb_nct6776f_refresh_fanrpm,
 2115 .rfact = 0
 2116 },
 2117 {
 2118 .desc = "Aux Fan2",
 2119 .type = ENVSYS_SFANRPM,
 2120 .bank = 4,
 2121 .reg = 0xc8,
 2122 .refresh = wb_nct6776f_refresh_fanrpm,
 2123 .rfact = 0
 2124 },
 2125
 2126 { .desc = NULL }
 2127};
 2128
 2129static const struct wb_product wb_products[] = {
 2130 { WB_CHIPID_W83627HF, "W83627HF", w83627hf_sensors, NULL },
 2131 { WB_CHIPID_W83627THF, "W83627THF",w83637hf_sensors, NULL },
 2132 { WB_CHIPID_W83627EHF_A,"W83627EHF-A",w83627ehf_sensors,NULL },
 2133 { WB_CHIPID_W83627EHF, "W83627EHF",w83627ehf_sensors,NULL },
 2134 { WB_CHIPID_W83627DHG, NULL, NULL, NULL },
 2135 { WB_CHIPID_W83637HF, "W83637HF", w83637hf_sensors, NULL },
 2136 { WB_CHIPID_W83697HF, "W83697HF", w83697hf_sensors, NULL },
 2137 { WB_CHIPID_W83781D, "W83781D", w83781d_sensors, NULL },
 2138 { WB_CHIPID_W83781D_2, "W83781D", w83781d_sensors, NULL },
 2139 { WB_CHIPID_W83782D, "W83782D", w83782d_sensors, NULL },
 2140 { WB_CHIPID_W83783S, "W83783S", w83783s_sensors, NULL },
 2141 { WB_CHIPID_W83791D, "W83791D", w83791d_sensors, NULL },
 2142 { WB_CHIPID_W83791SD, "W83791SD", NULL, NULL },
 2143 { WB_CHIPID_W83792D, "W83792D", w83792d_sensors, NULL },
 2144 { WB_CHIPID_AS99127F, NULL, NULL, NULL },
 2145 { 0, NULL, NULL, NULL }
 2146};
 2147
 2148static const struct wb_product wbsio_products[] = {
 2149 { WBSIO_ID_W83627DHG, "W83627DHG",w83627dhg_sensors,NULL },
 2150 { WBSIO_ID_NCT6775F, "NCT6775F", nct6776f_sensors, NULL },
 2151 { WBSIO_ID_NCT6776F, "NCT6776F", nct6776f_sensors, NULL },
 2152 { WBSIO_ID_NCT5104D, "NCT5104D or 610[246]D",nct6102d_sensors,NULL },
 2153 { WBSIO_ID_NCT6779D, "NCT6779D", nct6779d_sensors, NULL },
 2154 { WBSIO_ID_NCT6791D, "NCT6791D", nct6779d_sensors, NULL },
 2155 { WBSIO_ID_NCT6792D, "NCT6792D", nct6779d_sensors, NULL },
 2156 { WBSIO_ID_NCT6793D, "NCT6793D", nct6779d_sensors, NULL },
 2157 { WBSIO_ID_NCT6795D, "NCT6795D", nct6779d_sensors, NULL },
 2158 { 0, NULL, NULL, NULL }
 2159};
 2160
 2161static const struct wb_product as99127f_products[] = {
 2162 { WB_VENDID_ASUS, "AS99127F", w83781d_sensors, NULL },
 2163 { WB_VENDID_WINBOND, "AS99127F rev 2",as99127f_sensors,NULL },
 2164 { 0, NULL, NULL, NULL }
 2165};
 2166
1770static void 2167static void
1771lm_generic_banksel(struct lm_softc *lmsc, int bank) 2168lm_generic_banksel(struct lm_softc *lmsc, uint8_t bank)
1772{ 2169{
1773 (*lmsc->lm_writereg)(lmsc, WB_BANKSEL, bank); 2170 (*lmsc->lm_writereg)(lmsc, WB_BANKSEL, bank);
1774} 2171}
1775 2172
1776/* 2173/*
1777 * bus independent probe 2174 * bus independent match
1778 * 2175 *
1779 * prerequisites: lmsc contains valid lm_{read,write}reg() routines 2176 * prerequisites: lmsc contains valid lm_{read,write}reg() routines
1780 * and associated bus access data is present in attachment's softc 2177 * and associated bus access data is present in attachment's softc
1781 */ 2178 */
1782int 2179int
1783lm_probe(struct lm_softc *lmsc) 2180lm_match(struct lm_softc *lmsc)
1784{ 2181{
1785 uint8_t cr; 2182 uint8_t cr;
1786 int rv; 2183 int i, rv;
1787 2184
1788 /* Perform LM78 reset */ 2185 /* Perform LM78 reset */
1789 /*(*lmsc->lm_writereg)(lmsc, LMD_CONFIG, 0x80); */ 2186 /*(*lmsc->lm_writereg)(lmsc, LMD_CONFIG, 0x80); */
1790 2187
1791 cr = (*lmsc->lm_readreg)(lmsc, LMD_CONFIG); 2188 cr = (*lmsc->lm_readreg)(lmsc, LMD_CONFIG);
1792 2189
1793 /* XXX - spec says *only* 0x08! */ 2190 /* XXX - spec says *only* 0x08! */
1794 if ((cr == 0x08) || (cr == 0x01) || (cr == 0x03) || (cr == 0x06)) 2191 if ((cr != 0x08) && (cr != 0x01) && (cr != 0x03) && (cr != 0x06))
1795 rv = 1; 2192 return 0;
1796 else 2193
1797 rv = 0; 2194 DPRINTF(("%s: 0x80 check: cr = %x\n", __func__, cr));
 2195
 2196 for (i = 0; i < __arraycount(lm_chips); i++)
 2197 if ((rv = lm_chips[i].chip_match(lmsc)) != 0)
 2198 return rv;
 2199
 2200 return 0;
 2201}
1798 2202
1799 DPRINTF(("%s: rv = %d, cr = %x\n", __func__, rv, cr)); 2203int
 2204nslm_match(struct lm_softc *sc)
 2205{
 2206 uint8_t chipid;
1800 2207
1801 return rv; 2208 /* See if we have an LM78/LM78J/LM79 or LM81 */
 2209 chipid = (*sc->lm_readreg)(sc, LMD_CHIPID) & LM_ID_MASK;
 2210 switch(chipid) {
 2211 case LM_ID_LM78:
 2212 case LM_ID_LM78J:
 2213 case LM_ID_LM79:
 2214 case LM_ID_LM81:
 2215 break;
 2216 default:
 2217 return 0;
 2218 }
 2219 DPRINTF(("%s: chipid %x\n", __func__, chipid));
 2220 return 1;
1802} 2221}
1803 2222
1804void 2223void
1805lm_attach(struct lm_softc *lmsc) 2224lm_attach(struct lm_softc *lmsc)
1806{ 2225{
1807 uint32_t i; 2226 uint32_t i;
 2227 int rv;
1808 2228
1809 for (i = 0; i < __arraycount(lm_chips); i++) 2229 for (i = 0; i < __arraycount(lm_chips); i++) {
1810 if (lm_chips[i].chip_match(lmsc)) 2230 if (lm_chips[i].chip_match(lmsc) != 0) {
1811 break; 2231 if (lm_chips[i].chip_attach(lmsc) == 0)
 2232 break;
 2233 else
 2234 return;
 2235 }
 2236 }
1812 2237
1813 /* Start the monitoring loop */ 2238 /* Start the monitoring loop */
1814 (*lmsc->lm_writereg)(lmsc, LMD_CONFIG, 0x01); 2239 (*lmsc->lm_writereg)(lmsc, LMD_CONFIG, 0x01);
1815 2240
1816 lmsc->sc_sme = sysmon_envsys_create(); 2241 lmsc->sc_sme = sysmon_envsys_create();
1817 /* Initialize sensors */ 2242 /* Initialize sensors */
1818 for (i = 0; i < lmsc->numsensors; i++) { 2243 for (i = 0; i < lmsc->numsensors; i++) {
1819 lmsc->sensors[i].state = ENVSYS_SINVALID; 2244 lmsc->sensors[i].state = ENVSYS_SINVALID;
1820 if (sysmon_envsys_sensor_attach(lmsc->sc_sme, 2245 if ((rv = sysmon_envsys_sensor_attach(lmsc->sc_sme,
1821 &lmsc->sensors[i])) { 2246 &lmsc->sensors[i])) != 0) {
1822 sysmon_envsys_destroy(lmsc->sc_sme); 2247 sysmon_envsys_destroy(lmsc->sc_sme);
 2248 aprint_error_dev(lmsc->sc_dev,
 2249 "sysmon_envsys_sensor_attach() returned %d\n", rv);
1823 return; 2250 return;
1824 } 2251 }
1825 } 2252 }
1826 2253
1827 /* 2254 /*
1828 * Setup the callout to refresh sensor data every 2 seconds. 2255 * Setup the callout to refresh sensor data every 2 seconds.
1829 */ 2256 */
1830 callout_init(&lmsc->sc_callout, 0); 2257 callout_init(&lmsc->sc_callout, 0);
1831 callout_setfunc(&lmsc->sc_callout, lm_refresh, lmsc); 2258 callout_setfunc(&lmsc->sc_callout, lm_refresh, lmsc);
1832 callout_schedule(&lmsc->sc_callout, LM_REFRESH_TIMO); 2259 callout_schedule(&lmsc->sc_callout, LM_REFRESH_TIMO);
1833 2260
1834 /* 2261 /*
1835 * Hook into the System Monitor. 2262 * Hook into the System Monitor.
@@ -1856,79 +2283,86 @@ lm_detach(struct lm_softc *lmsc) @@ -1856,79 +2283,86 @@ lm_detach(struct lm_softc *lmsc)
1856 sysmon_envsys_unregister(lmsc->sc_sme); 2283 sysmon_envsys_unregister(lmsc->sc_sme);
1857} 2284}
1858 2285
1859static void 2286static void
1860lm_refresh(void *arg) 2287lm_refresh(void *arg)
1861{ 2288{
1862 struct lm_softc *lmsc = arg; 2289 struct lm_softc *lmsc = arg;
1863 2290
1864 lmsc->refresh_sensor_data(lmsc); 2291 lmsc->refresh_sensor_data(lmsc);
1865 callout_schedule(&lmsc->sc_callout, LM_REFRESH_TIMO); 2292 callout_schedule(&lmsc->sc_callout, LM_REFRESH_TIMO);
1866} 2293}
1867 2294
1868static int 2295static int
1869lm_match(struct lm_softc *sc) 2296nslm_attach(struct lm_softc *sc)
1870{ 2297{
1871 const char *model = NULL; 2298 const char *model = NULL;
1872 int chipid; 2299 uint8_t chipid;
1873 2300
1874 /* See if we have an LM78/LM78J/LM79 or LM81 */ 2301 /* See if we have an LM78/LM78J/LM79 or LM81 */
1875 chipid = (*sc->lm_readreg)(sc, LMD_CHIPID) & LM_ID_MASK; 2302 chipid = (*sc->lm_readreg)(sc, LMD_CHIPID) & LM_ID_MASK;
1876 switch(chipid) { 2303 switch(chipid) {
1877 case LM_ID_LM78: 2304 case LM_ID_LM78:
1878 model = "LM78"; 2305 model = "LM78";
1879 break; 2306 break;
1880 case LM_ID_LM78J: 2307 case LM_ID_LM78J:
1881 model = "LM78J"; 2308 model = "LM78J";
1882 break; 2309 break;
1883 case LM_ID_LM79: 2310 case LM_ID_LM79:
1884 model = "LM79"; 2311 model = "LM79";
1885 break; 2312 break;
1886 case LM_ID_LM81: 2313 case LM_ID_LM81:
1887 model = "LM81"; 2314 model = "LM81";
1888 break; 2315 break;
1889 default: 2316 default:
1890 return 0; 2317 return -1;
1891 } 2318 }
1892 2319
1893 aprint_naive("\n"); 2320 aprint_naive("\n");
1894 aprint_normal("\n"); 2321 aprint_normal("\n");
1895 aprint_normal_dev(sc->sc_dev, 2322 aprint_normal_dev(sc->sc_dev,
1896 "National Semiconductor %s Hardware monitor\n", model); 2323 "National Semiconductor %s Hardware monitor\n", model);
1897 2324
1898 lm_setup_sensors(sc, lm78_sensors); 2325 lm_setup_sensors(sc, lm78_sensors);
1899 sc->refresh_sensor_data = lm_refresh_sensor_data; 2326 sc->refresh_sensor_data = lm_refresh_sensor_data;
1900 return 1; 2327 return 0;
1901} 2328}
1902 2329
1903static int 2330static int
1904def_match(struct lm_softc *sc) 2331def_match(struct lm_softc *sc)
1905{ 2332{
1906 int chipid; 2333
 2334 return 1;
 2335}
 2336
 2337static int
 2338def_attach(struct lm_softc *sc)
 2339{
 2340 uint8_t chipid;
1907 2341
1908 chipid = (*sc->lm_readreg)(sc, LMD_CHIPID) & LM_ID_MASK; 2342 chipid = (*sc->lm_readreg)(sc, LMD_CHIPID) & LM_ID_MASK;
1909 aprint_naive("\n"); 2343 aprint_naive("\n");
1910 aprint_normal("\n"); 2344 aprint_normal("\n");
1911 aprint_error_dev(sc->sc_dev, "Unknown chip (ID %d)\n", chipid); 2345 aprint_error_dev(sc->sc_dev, "Unknown chip (ID 0x%02x)\n", chipid);
1912 2346
1913 lm_setup_sensors(sc, lm78_sensors); 2347 lm_setup_sensors(sc, lm78_sensors);
1914 sc->refresh_sensor_data = lm_refresh_sensor_data; 2348 sc->refresh_sensor_data = lm_refresh_sensor_data;
1915 return 1; 2349 return 0;
1916} 2350}
1917 2351
1918static void 2352static void
1919wb_temp_diode_type(struct lm_softc *sc, int diode_type) 2353wb_temp_diode_type(struct lm_softc *sc, int diode_type)
1920{ 2354{
1921 int regval, banksel; 2355 uint8_t regval, banksel;
1922 2356
1923 banksel = (*sc->lm_readreg)(sc, WB_BANKSEL); 2357 banksel = (*sc->lm_readreg)(sc, WB_BANKSEL);
1924 switch (diode_type) { 2358 switch (diode_type) {
1925 case 1: /* Switch to Pentium-II diode mode */ 2359 case 1: /* Switch to Pentium-II diode mode */
1926 lm_generic_banksel(sc, WB_BANKSEL_B0); 2360 lm_generic_banksel(sc, WB_BANKSEL_B0);
1927 regval = (*sc->lm_readreg)(sc, WB_BANK0_VBAT); 2361 regval = (*sc->lm_readreg)(sc, WB_BANK0_VBAT);
1928 regval |= 0x0e; 2362 regval |= 0x0e;
1929 (*sc->lm_writereg)(sc, WB_BANK0_VBAT, regval); 2363 (*sc->lm_writereg)(sc, WB_BANK0_VBAT, regval);
1930 regval = (*sc->lm_readreg)(sc, WB_BANK0_RESVD1); 2364 regval = (*sc->lm_readreg)(sc, WB_BANK0_RESVD1);
1931 regval |= 0x70; 2365 regval |= 0x70;
1932 (*sc->lm_writereg)(sc, WB_BANK0_RESVD1, 0x0); 2366 (*sc->lm_writereg)(sc, WB_BANK0_RESVD1, 0x0);
1933 lm_generic_banksel(sc, banksel); 2367 lm_generic_banksel(sc, banksel);
1934 aprint_verbose_dev(sc->sc_dev, "Pentium-II diode temp sensors\n"); 2368 aprint_verbose_dev(sc->sc_dev, "Pentium-II diode temp sensors\n");
@@ -1953,156 +2387,260 @@ wb_temp_diode_type(struct lm_softc *sc,  @@ -1953,156 +2387,260 @@ wb_temp_diode_type(struct lm_softc *sc,
1953 aprint_verbose_dev(sc->sc_dev, "Thermistor temp sensors\n"); 2387 aprint_verbose_dev(sc->sc_dev, "Thermistor temp sensors\n");
1954 break; 2388 break;
1955 case 0: /* Unspecified - use default */ 2389 case 0: /* Unspecified - use default */
1956 aprint_verbose_dev(sc->sc_dev, "Using default temp sensors\n"); 2390 aprint_verbose_dev(sc->sc_dev, "Using default temp sensors\n");
1957 break; 2391 break;
1958 default: 2392 default:
1959 aprint_error_dev(sc->sc_dev, 2393 aprint_error_dev(sc->sc_dev,
1960 "Ignoring invalid temp sensor mode %d\n", 2394 "Ignoring invalid temp sensor mode %d\n",
1961 diode_type); 2395 diode_type);
1962 break; 2396 break;
1963 } 2397 }
1964} 2398}
1965 2399
1966static int 2400static const struct wb_product *
1967wb_match(struct lm_softc *sc) 2401wb_lookup(struct lm_softc *sc, const struct wb_product *products, uint16_t id)
1968{ 2402{
1969 const char *model = NULL; 2403 const struct wb_product *prod = products;
1970 const char *vendor = "Winbond"; 2404 int i = 0;
1971 int banksel, vendid, cf_flags; 
1972 2405
1973 aprint_naive("\n"); 2406 while (prod[i].id != 0) {
1974 aprint_normal("\n"); 2407 if (prod[i].id != id) {
1975 /* Read vendor ID */ 2408 i++;
 2409 continue;
 2410 }
 2411 if (prod[i].str == NULL) {
 2412 if (products == wb_products) {
 2413 if (id == WB_CHIPID_W83627DHG) {
 2414 /*
 2415 * Lookup wbsio_products
 2416 * with WBSIO_ID.
 2417 */
 2418 return wb_lookup(sc, wbsio_products,
 2419 sc->sioid);
 2420 } else if (id == WB_CHIPID_AS99127F) {
 2421 /*
 2422 * Lookup as99127f_products
 2423 * with WB_VENDID.
 2424 */
 2425 return wb_lookup(sc, as99127f_products,
 2426 wb_read_vendorid(sc));
 2427 } else
 2428 return NULL; /* not occur */
 2429 }
 2430 return NULL; /* not occur */
 2431 }
 2432 return &prod[i];
 2433 }
 2434
 2435 /* Not found */
 2436 return NULL;
 2437}
 2438
 2439static uint16_t
 2440wb_read_vendorid(struct lm_softc *sc)
 2441{
 2442 uint16_t vendid;
 2443 uint8_t vendidreg;
 2444 uint8_t banksel;
 2445
 2446 /* Save bank */
1976 banksel = (*sc->lm_readreg)(sc, WB_BANKSEL); 2447 banksel = (*sc->lm_readreg)(sc, WB_BANKSEL);
 2448
 2449 /* Check default vendor ID register first */
 2450 vendidreg = WB_VENDID;
 2451
 2452retry:
 2453 /* Read vendor ID */
1977 lm_generic_banksel(sc, WB_BANKSEL_HBAC); 2454 lm_generic_banksel(sc, WB_BANKSEL_HBAC);
1978 vendid = (*sc->lm_readreg)(sc, WB_VENDID) << 8; 2455 vendid = (*sc->lm_readreg)(sc, vendidreg) << 8;
1979 lm_generic_banksel(sc, 0); 2456 lm_generic_banksel(sc, 0);
1980 vendid |= (*sc->lm_readreg)(sc, WB_VENDID); 2457 vendid |= (*sc->lm_readreg)(sc, vendidreg);
1981 DPRINTF(("%s: winbond vend id 0x%x\n", __func__, vendid)); 
1982 if (vendid != WB_VENDID_WINBOND && vendid != WB_VENDID_ASUS) 
1983 return 0; 
1984 2458
1985 /* Read device/chip ID */ 2459 if ((vendidreg == WB_VENDID)
 2460 && (vendid != WB_VENDID_WINBOND && vendid != WB_VENDID_ASUS)) {
 2461 /* If it failed, try NCT6102 vendor ID register */
 2462 vendidreg = WB_NCT6102_VENDID;
 2463 goto retry;
 2464 } else if ((vendidreg == WB_NCT6102_VENDID)
 2465 && (vendid != WB_VENDID_WINBOND))
 2466 vendid = 0; /* XXX */
 2467
 2468 /* Restore bank */
 2469 lm_generic_banksel(sc, banksel);
 2470
 2471 return vendid;
 2472}
 2473
 2474static uint8_t
 2475wb_read_chipid(struct lm_softc *sc)
 2476{
 2477 const struct wb_product *prod;
 2478 uint8_t chipidreg, chipid, banksel;
 2479
 2480 /* Save bank */
 2481 banksel = (*sc->lm_readreg)(sc, WB_BANKSEL);
 2482
 2483 /* Check default vendor ID register first */
 2484 chipidreg = WB_BANK0_CHIPID;
1986 lm_generic_banksel(sc, WB_BANKSEL_B0); 2485 lm_generic_banksel(sc, WB_BANKSEL_B0);
 2486
 2487retry:
1987 (void)(*sc->lm_readreg)(sc, LMD_CHIPID); 2488 (void)(*sc->lm_readreg)(sc, LMD_CHIPID);
1988 sc->chipid = (*sc->lm_readreg)(sc, WB_BANK0_CHIPID); 2489 chipid = (*sc->lm_readreg)(sc, chipidreg);
 2490 prod = wb_lookup(sc, wb_products, chipid);
 2491 if (prod == NULL) {
 2492 if (chipidreg == WB_BANK0_CHIPID) {
 2493 chipidreg = WB_BANK0_NCT6102_CHIPID;
 2494 goto retry;
 2495 } else
 2496 chipid = 0;
 2497 }
 2498 /* Restore bank */
1989 lm_generic_banksel(sc, banksel); 2499 lm_generic_banksel(sc, banksel);
1990 cf_flags = device_cfdata(sc->sc_dev)->cf_flags; 2500
 2501 return chipid;
 2502}
 2503
 2504static int
 2505wb_match(struct lm_softc *sc)
 2506{
 2507 const struct wb_product *prod;
 2508 uint16_t vendid;
 2509 uint8_t chipid;
 2510
 2511 /* Read vendor ID */
 2512 vendid = wb_read_vendorid(sc);
 2513 DPRINTF(("%s: winbond vend id 0x%x\n", __func__, vendid));
 2514 if ((vendid != WB_VENDID_WINBOND && vendid != WB_VENDID_ASUS))
 2515 return 0;
 2516
 2517 /* Read device/chip ID */
 2518 chipid = wb_read_chipid(sc);
 2519 DPRINTF(("%s: winbond chip id 0x%x\n", __func__, chipid));
 2520 prod = wb_lookup(sc, wb_products, chipid);
 2521
 2522 if (prod == NULL) {
 2523 if (vendid == WB_VENDID_WINBOND)
 2524 return 1; /* Generic match */
 2525 else
 2526 return 0;
 2527 }
 2528 DPRINTF(("%s: chipid %02x, sioid = %04x\n", __func__, chipid,
 2529 sc->sioid));
 2530
 2531 return 10; /* found */
 2532}
 2533
 2534static int
 2535wb_attach(struct lm_softc *sc)
 2536{
 2537 device_t dev = sc->sc_dev;
 2538 const struct wb_product *prod;
 2539 const char *model = NULL;
 2540 const char *vendor = "Winbond";
 2541 const struct lm_sensor *sensors;
 2542 uint16_t vendid;
 2543 uint8_t banksel;
 2544 int cf_flags;
 2545
 2546 aprint_naive("\n");
 2547 aprint_normal("\n");
 2548 /* Read device/chip ID */
 2549 sc->chipid = wb_read_chipid(sc);
1991 DPRINTF(("%s: winbond chip id 0x%x\n", __func__, sc->chipid)); 2550 DPRINTF(("%s: winbond chip id 0x%x\n", __func__, sc->chipid));
1992 2551
 2552 if ((prod = wb_lookup(sc, wb_products, sc->chipid)) != NULL) {
 2553 switch (prod->str[0]) {
 2554 case 'W':
 2555 vendor = "Winbond";
 2556 break;
 2557 case 'A':
 2558 vendor = "ASUS";
 2559 break;
 2560 case 'N':
 2561 vendor = "Nuvoton";
 2562 break;
 2563 default:
 2564 aprint_error_dev(dev, "Unknown model (%s)\n", model);
 2565 return -1;
 2566 }
 2567 model = prod->str;
 2568 sensors = prod->sensors;
 2569 sc->refresh_sensor_data = wb_refresh_sensor_data;
 2570 if (prod->extattach != NULL)
 2571 prod->extattach(sc);
 2572 } else {
 2573 vendid = wb_read_vendorid(sc);
 2574 if (vendid == WB_VENDID_WINBOND) {
 2575 vendor = "Winbond";
 2576 model = "unknown-model";
 2577
 2578 /* Handle as a standard LM78. */
 2579 sensors = lm78_sensors;
 2580 sc->refresh_sensor_data = lm_refresh_sensor_data;
 2581 } else {
 2582 aprint_error_dev(dev, "Unknown chip (ID %02x)\n",
 2583 sc->chipid);
 2584 return -1;
 2585 }
 2586 }
 2587
 2588 cf_flags = device_cfdata(dev)->cf_flags;
 2589
 2590 if (sensors != NULL) {
 2591 lm_setup_sensors(sc, sensors);
 2592
 2593 /* XXX Is this correct? Check all datasheets. */
 2594 switch (sc->chipid) {
 2595 case WB_CHIPID_W83627EHF_A:
 2596 case WB_CHIPID_W83781D:
 2597 case WB_CHIPID_W83781D_2:
 2598 case WB_CHIPID_W83791SD:
 2599 case WB_CHIPID_W83792D:
 2600 case WB_CHIPID_AS99127F:
 2601 break;
 2602 default:
 2603 wb_temp_diode_type(sc, cf_flags);
 2604 break;
 2605 }
 2606 }
 2607
 2608 /* XXX Is this correct? Check all datasheets. */
 2609 banksel = (*sc->lm_readreg)(sc, WB_BANKSEL);
1993 switch(sc->chipid) { 2610 switch(sc->chipid) {
1994 case WB_CHIPID_W83627HF: 
1995 model = "W83627HF"; 
1996 lm_setup_sensors(sc, w83627hf_sensors); 
1997 wb_temp_diode_type(sc, cf_flags); 
1998 break; 
1999 case WB_CHIPID_W83627THF: 2611 case WB_CHIPID_W83627THF:
2000 model = "W83627THF"; 
2001 lm_generic_banksel(sc, WB_BANKSEL_B0); 2612 lm_generic_banksel(sc, WB_BANKSEL_B0);
2002 if ((*sc->lm_readreg)(sc, WB_BANK0_CONFIG) & WB_CONFIG_VMR9) 2613 if ((*sc->lm_readreg)(sc, WB_BANK0_CONFIG) & WB_CONFIG_VMR9)
2003 sc->vrm9 = 1; 2614 sc->vrm9 = 1;
2004 lm_generic_banksel(sc, banksel); 2615 lm_generic_banksel(sc, banksel);
2005 lm_setup_sensors(sc, w83637hf_sensors); 
2006 wb_temp_diode_type(sc, cf_flags); 
2007 break; 
2008 case WB_CHIPID_W83627EHF_A: 
2009 model = "W83627EHF-A"; 
2010 lm_setup_sensors(sc, w83627ehf_sensors); 
2011 break; 
2012 case WB_CHIPID_W83627EHF: 
2013 model = "W83627EHF"; 
2014 lm_setup_sensors(sc, w83627ehf_sensors); 
2015 wb_temp_diode_type(sc, cf_flags); 
2016 break; 
2017 case WB_CHIPID_W83627DHG: 
2018 if (sc->sioid == WBSIO_ID_NCT6776F) { 
2019 vendor = "Nuvoton"; 
2020 model = "NCT6776F"; 
2021 lm_setup_sensors(sc, nct6776f_sensors); 
2022 } else { 
2023 model = "W83627DHG"; 
2024 lm_setup_sensors(sc, w83627dhg_sensors); 
2025 } 
2026 wb_temp_diode_type(sc, cf_flags); 
2027 break; 2616 break;
2028 case WB_CHIPID_W83637HF: 2617 case WB_CHIPID_W83637HF:
2029 model = "W83637HF"; 
2030 lm_generic_banksel(sc, WB_BANKSEL_B0); 2618 lm_generic_banksel(sc, WB_BANKSEL_B0);
2031 if ((*sc->lm_readreg)(sc, WB_BANK0_CONFIG) & WB_CONFIG_VMR9) 2619 if ((*sc->lm_readreg)(sc, WB_BANK0_CONFIG) & WB_CONFIG_VMR9)
2032 sc->vrm9 = 1; 2620 sc->vrm9 = 1;
2033 lm_generic_banksel(sc, banksel); 2621 lm_generic_banksel(sc, banksel);
2034 lm_setup_sensors(sc, w83637hf_sensors); 
2035 wb_temp_diode_type(sc, cf_flags); 
2036 break; 
2037 case WB_CHIPID_W83697HF: 
2038 model = "W83697HF"; 
2039 lm_setup_sensors(sc, w83697hf_sensors); 
2040 wb_temp_diode_type(sc, cf_flags); 
2041 break; 
2042 case WB_CHIPID_W83781D: 
2043 case WB_CHIPID_W83781D_2: 
2044 model = "W83781D"; 
2045 lm_setup_sensors(sc, w83781d_sensors); 
2046 break; 
2047 case WB_CHIPID_W83782D: 
2048 model = "W83782D"; 
2049 lm_setup_sensors(sc, w83782d_sensors); 
2050 wb_temp_diode_type(sc, cf_flags); 
2051 break; 
2052 case WB_CHIPID_W83783S: 
2053 model = "W83783S"; 
2054 lm_setup_sensors(sc, w83783s_sensors); 
2055 wb_temp_diode_type(sc, cf_flags); 
2056 break; 
2057 case WB_CHIPID_W83791D: 
2058 model = "W83791D"; 
2059 lm_setup_sensors(sc, w83791d_sensors); 
2060 wb_temp_diode_type(sc, cf_flags); 
2061 break; 
2062 case WB_CHIPID_W83791SD: 
2063 model = "W83791SD"; 
2064 break; 
2065 case WB_CHIPID_W83792D: 
2066 model = "W83792D"; 
2067 lm_setup_sensors(sc, w83792d_sensors); 
2068 break; 
2069 case WB_CHIPID_AS99127F: 
2070 vendor = "ASUS"; 
2071 if (vendid == WB_VENDID_ASUS) { 
2072 model = "AS99127F"; 
2073 lm_setup_sensors(sc, w83781d_sensors); 
2074 } else { 
2075 model = "AS99127F rev 2"; 
2076 lm_setup_sensors(sc, as99127f_sensors); 
2077 } 
2078 break; 2622 break;
2079 default: 2623 default:
2080 aprint_normal_dev(sc->sc_dev, 2624 break;
2081 "unknown Winbond chip (ID 0x%x)\n", sc->chipid); 
2082 /* Handle as a standard LM78. */ 
2083 lm_setup_sensors(sc, lm78_sensors); 
2084 sc->refresh_sensor_data = lm_refresh_sensor_data; 
2085 return 1; 
2086 } 2625 }
2087 2626
2088 aprint_normal_dev(sc->sc_dev, "%s %s Hardware monitor\n", vendor, model); 2627 aprint_normal_dev(dev, "%s %s Hardware monitor\n", vendor, model);
2089 2628
2090 sc->refresh_sensor_data = wb_refresh_sensor_data; 2629 return 0;
2091 return 1; 
2092} 2630}
2093 2631
2094static void 2632static void
2095lm_setup_sensors(struct lm_softc *sc, struct lm_sensor *sensors) 2633lm_setup_sensors(struct lm_softc *sc, const struct lm_sensor *sensors)
2096{ 2634{
2097 int i; 2635 int i;
2098 2636
2099 for (i = 0; sensors[i].desc; i++) { 2637 for (i = 0; sensors[i].desc; i++) {
2100 sc->sensors[i].units = sensors[i].type; 2638 sc->sensors[i].units = sensors[i].type;
2101 if (sc->sensors[i].units == ENVSYS_SVOLTS_DC) 2639 if (sc->sensors[i].units == ENVSYS_SVOLTS_DC)
2102 sc->sensors[i].flags = ENVSYS_FCHANGERFACT; 2640 sc->sensors[i].flags = ENVSYS_FCHANGERFACT;
2103 strlcpy(sc->sensors[i].desc, sensors[i].desc, 2641 strlcpy(sc->sensors[i].desc, sensors[i].desc,
2104 sizeof(sc->sensors[i].desc)); 2642 sizeof(sc->sensors[i].desc));
2105 sc->numsensors++; 2643 sc->numsensors++;
2106 } 2644 }
2107 sc->lm_sensors = sensors; 2645 sc->lm_sensors = sensors;
2108} 2646}
@@ -2188,27 +2726,28 @@ lm_refresh_fanrpm(struct lm_softc *sc, i @@ -2188,27 +2726,28 @@ lm_refresh_fanrpm(struct lm_softc *sc, i
2188 if (data == 0xff || data == 0x00) 2726 if (data == 0xff || data == 0x00)
2189 sc->sensors[n].state = ENVSYS_SINVALID; 2727 sc->sensors[n].state = ENVSYS_SINVALID;
2190 else { 2728 else {
2191 sc->sensors[n].state = ENVSYS_SVALID; 2729 sc->sensors[n].state = ENVSYS_SVALID;
2192 sc->sensors[n].value_cur = 1350000 / (data << divisor); 2730 sc->sensors[n].value_cur = 1350000 / (data << divisor);
2193 } 2731 }
2194 DPRINTF(("%s: fan[%d] data=0x%x value_cur=%d\n", 2732 DPRINTF(("%s: fan[%d] data=0x%x value_cur=%d\n",
2195 __func__, n, data, sc->sensors[n].value_cur)); 2733 __func__, n, data, sc->sensors[n].value_cur));
2196} 2734}
2197 2735
2198static void 2736static void
2199wb_refresh_sensor_data(struct lm_softc *sc) 2737wb_refresh_sensor_data(struct lm_softc *sc)
2200{ 2738{
2201 int banksel, bank, i; 2739 uint8_t banksel, bank;
 2740 int i;
2202 2741
2203 /* 2742 /*
2204 * Properly save and restore bank selection register. 2743 * Properly save and restore bank selection register.
2205 */ 2744 */
2206 banksel = bank = sc->lm_readreg(sc, WB_BANKSEL); 2745 banksel = bank = sc->lm_readreg(sc, WB_BANKSEL);
2207 for (i = 0; i < sc->numsensors; i++) { 2746 for (i = 0; i < sc->numsensors; i++) {
2208 if (bank != sc->lm_sensors[i].bank) { 2747 if (bank != sc->lm_sensors[i].bank) {
2209 bank = sc->lm_sensors[i].bank; 2748 bank = sc->lm_sensors[i].bank;
2210 lm_generic_banksel(sc, bank); 2749 lm_generic_banksel(sc, bank);
2211 } 2750 }
2212 sc->lm_sensors[i].refresh(sc, i); 2751 sc->lm_sensors[i].refresh(sc, i);
2213 } 2752 }
2214 lm_generic_banksel(sc, banksel); 2753 lm_generic_banksel(sc, banksel);
@@ -2357,27 +2896,28 @@ wb_nct6776f_refresh_fanrpm(struct lm_sof @@ -2357,27 +2896,28 @@ wb_nct6776f_refresh_fanrpm(struct lm_sof
2357 datal = (*sc->lm_readreg)(sc, sc->lm_sensors[n].reg + 1); 2896 datal = (*sc->lm_readreg)(sc, sc->lm_sensors[n].reg + 1);
2358 2897
2359 if ((datah == 0xff) || (datah == 0)) { 2898 if ((datah == 0xff) || (datah == 0)) {
2360 sc->sensors[n].state = ENVSYS_SINVALID; 2899 sc->sensors[n].state = ENVSYS_SINVALID;
2361 } else { 2900 } else {
2362 sc->sensors[n].state = ENVSYS_SVALID; 2901 sc->sensors[n].state = ENVSYS_SVALID;
2363 sc->sensors[n].value_cur = (datah << 8) | datal; 2902 sc->sensors[n].value_cur = (datah << 8) | datal;
2364 } 2903 }
2365} 2904}
2366 2905
2367static void 2906static void
2368wb_w83792d_refresh_fanrpm(struct lm_softc *sc, int n) 2907wb_w83792d_refresh_fanrpm(struct lm_softc *sc, int n)
2369{ 2908{
2370 int reg, shift, data, divisor = 1; 2909 int shift, data, divisor = 1;
 2910 uint8_t reg;
2371 2911
2372 shift = 0; 2912 shift = 0;
2373 2913
2374 switch (sc->lm_sensors[n].reg) { 2914 switch (sc->lm_sensors[n].reg) {
2375 case 0x28: 2915 case 0x28:
2376 reg = 0x47; shift = 0; 2916 reg = 0x47; shift = 0;
2377 break; 2917 break;
2378 case 0x29: 2918 case 0x29:
2379 reg = 0x47; shift = 4; 2919 reg = 0x47; shift = 4;
2380 break; 2920 break;
2381 case 0x2a: 2921 case 0x2a:
2382 reg = 0x5b; shift = 0; 2922 reg = 0x5b; shift = 0;
2383 break; 2923 break;

cvs diff -r1.29 -r1.29.10.1 src/sys/dev/ic/nslm7xvar.h (expand / switch to unified diff)

--- src/sys/dev/ic/nslm7xvar.h 2016/06/01 02:37:47 1.29
+++ src/sys/dev/ic/nslm7xvar.h 2017/11/22 14:56:30 1.29.10.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: nslm7xvar.h,v 1.29 2016/06/01 02:37:47 pgoyette Exp $ */ 1/* $NetBSD: nslm7xvar.h,v 1.29.10.1 2017/11/22 14:56:30 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000 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 Bill Squier. 8 * by Bill Squier.
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.
@@ -76,36 +76,38 @@ @@ -76,36 +76,38 @@
76 * Winbond registers 76 * Winbond registers
77 * 77 *
78 * Several models exists. The W83781D is mostly compatible with the 78 * Several models exists. The W83781D is mostly compatible with the
79 * LM78, but has two extra temperatures. Later models add extra 79 * LM78, but has two extra temperatures. Later models add extra
80 * voltage sensors, fans and bigger fan divisors to accomodate slow 80 * voltage sensors, fans and bigger fan divisors to accomodate slow
81 * running fans. To accomodate the extra sensors some models have 81 * running fans. To accomodate the extra sensors some models have
82 * different memory banks. 82 * different memory banks.
83 */ 83 */
84 84
85#define WB_T23ADDR 0x4a /* Temperature 2 and 3 Serial Bus Address */ 85#define WB_T23ADDR 0x4a /* Temperature 2 and 3 Serial Bus Address */
86#define WB_PIN 0x4b /* Pin Control */ 86#define WB_PIN 0x4b /* Pin Control */
87#define WB_BANKSEL 0x4e /* Bank Select */ 87#define WB_BANKSEL 0x4e /* Bank Select */
88#define WB_VENDID 0x4f /* Vendor ID */ 88#define WB_VENDID 0x4f /* Vendor ID */
 89#define WB_NCT6102_VENDID 0xfe /* Vendor ID for NCT610[246] */
89 90
90/* Bank 0 regs */ 91/* Bank 0 regs */
91#define WB_BANK0_CHIPID 0x58 /* Chip ID */ 92#define WB_BANK0_CHIPID 0x58 /* Chip ID */
92#define WB_BANK0_RESVD1 0x59 /* Resvd, bits 6-4 select temp sensor mode */ 93#define WB_BANK0_RESVD1 0x59 /* Resvd, bits 6-4 select temp sensor mode */
93#define WB_BANK0_FAN45 0x5c /* Fan 4/5 Divisor Control (W83791D only) */ 94#define WB_BANK0_FAN45 0x5c /* Fan 4/5 Divisor Control (W83791D only) */
94#define WB_BANK0_VBAT 0x5d /* VBAT Monitor Control */ 95#define WB_BANK0_VBAT 0x5d /* VBAT Monitor Control */
95#define WB_BANK0_FAN4 0xba /* Fan 4 reading (W83791D only) */ 96#define WB_BANK0_FAN4 0xba /* Fan 4 reading (W83791D only) */
96#define WB_BANK0_FAN5 0xbb /* Fan 5 reading (W83791D only) */ 97#define WB_BANK0_FAN5 0xbb /* Fan 5 reading (W83791D only) */
97 98
98#define WB_BANK0_CONFIG 0x18 /* VRM & OVT Config (W83627THF/W83637HF) */ 99#define WB_BANK0_CONFIG 0x18 /* VRM & OVT Config (W83627THF/W83637HF) */
 100#define WB_BANK0_NCT6102_CHIPID 0xff /* Chip ID for NCT610[246] */
99 101
100/* Bank 1 registers */ 102/* Bank 1 registers */
101#define WB_BANK1_T2H 0x50 /* Temperature 2 High Byte */ 103#define WB_BANK1_T2H 0x50 /* Temperature 2 High Byte */
102#define WB_BANK1_T2L 0x51 /* Temperature 2 Low Byte */ 104#define WB_BANK1_T2L 0x51 /* Temperature 2 Low Byte */
103 105
104/* Bank 2 registers */ 106/* Bank 2 registers */
105#define WB_BANK2_T3H 0x50 /* Temperature 3 High Byte */ 107#define WB_BANK2_T3H 0x50 /* Temperature 3 High Byte */
106#define WB_BANK2_T3L 0x51 /* Temperature 3 Low Byte */ 108#define WB_BANK2_T3L 0x51 /* Temperature 3 Low Byte */
107 109
108/* Bank 4 registers (W83782D/W83627HF and later models only) */ 110/* Bank 4 registers (W83782D/W83627HF and later models only) */
109#define WB_BANK4_T1OFF 0x54 /* Temperature 1 Offset */ 111#define WB_BANK4_T1OFF 0x54 /* Temperature 1 Offset */
110#define WB_BANK4_T2OFF 0x55 /* Temperature 2 Offset */ 112#define WB_BANK4_T2OFF 0x55 /* Temperature 2 Offset */
111#define WB_BANK4_T3OFF 0x56 /* Temperature 3 Offset */ 113#define WB_BANK4_T3OFF 0x56 /* Temperature 3 Offset */
@@ -134,59 +136,63 @@ @@ -134,59 +136,63 @@
134#define WB_CHIPID_AS99127F 0x31 /* Asus W83781D clone */ 136#define WB_CHIPID_AS99127F 0x31 /* Asus W83781D clone */
135#define WB_CHIPID_W83782D 0x30 137#define WB_CHIPID_W83782D 0x30
136#define WB_CHIPID_W83783S 0x40 138#define WB_CHIPID_W83783S 0x40
137#define WB_CHIPID_W83697HF 0x60 139#define WB_CHIPID_W83697HF 0x60
138#define WB_CHIPID_W83791D 0x71 140#define WB_CHIPID_W83791D 0x71
139#define WB_CHIPID_W83791SD 0x72 141#define WB_CHIPID_W83791SD 0x72
140#define WB_CHIPID_W83792D 0x7a 142#define WB_CHIPID_W83792D 0x7a
141#define WB_CHIPID_W83637HF 0x80 143#define WB_CHIPID_W83637HF 0x80
142#define WB_CHIPID_W83627EHF_A 0x88 /* early version, only for ASUS MBs */ 144#define WB_CHIPID_W83627EHF_A 0x88 /* early version, only for ASUS MBs */
143#define WB_CHIPID_W83627THF 0x90 145#define WB_CHIPID_W83627THF 0x90
144#define WB_CHIPID_W83627EHF 0xa1 146#define WB_CHIPID_W83627EHF 0xa1
145#define WB_CHIPID_W83627DHG 0xc1 147#define WB_CHIPID_W83627DHG 0xc1
146 148
147/* wbsio Device IDs */ 
148#define WBSIO_ID_NCT6776F 0xc3 
149 
150/* Config bits */ 149/* Config bits */
151#define WB_CONFIG_VMR9 0x01 150#define WB_CONFIG_VMR9 0x01
152 151
153/* Reference voltage (mV) */ 152/* Reference voltage (mV) */
154#define WB_VREF 3600 153#define WB_VREF 3600
155#define WB_W83627EHF_VREF 2048 154#define WB_W83627EHF_VREF 2048
156 155
157#define WB_MAX_SENSORS 19 156#define WB_MAX_SENSORS 36
158 157
159struct lm_softc { 158struct lm_softc {
160 device_t sc_dev; 159 device_t sc_dev;
161 160
162 callout_t sc_callout; 161 callout_t sc_callout;
163 162
164 envsys_data_t sensors[WB_MAX_SENSORS]; 163 envsys_data_t sensors[WB_MAX_SENSORS];
165 struct sysmon_envsys *sc_sme; 164 struct sysmon_envsys *sc_sme;
166 uint8_t numsensors; 165 uint8_t numsensors;
167 166
168 void (*refresh_sensor_data)(struct lm_softc *); 167 void (*refresh_sensor_data)(struct lm_softc *);
169 168
170 uint8_t (*lm_readreg)(struct lm_softc *, int); 169 uint8_t (*lm_readreg)(struct lm_softc *, int);
171 void (*lm_writereg)(struct lm_softc *, int, int); 170 void (*lm_writereg)(struct lm_softc *, int, uint8_t);
172 171
173 struct lm_sensor *lm_sensors; 172 const struct lm_sensor *lm_sensors;
174 uint8_t chipid; 173 uint8_t chipid;
175 uint8_t vrm9; 174 uint8_t vrm9;
176 uint8_t sioid; 175 uint16_t sioid;
177}; 176};
178 177
179struct lm_sensor { 178struct lm_sensor {
180 const char *desc; 179 const char *desc;
181 enum envsys_units type; 180 enum envsys_units type;
182 uint8_t bank; 181 uint8_t bank;
183 uint8_t reg; 182 uint8_t reg;
184 void (*refresh)(struct lm_softc *, int); 183 void (*refresh)(struct lm_softc *, int);
185 int rfact; 184 int rfact;
186}; 185};
187 186
 187struct wb_product {
 188 uint16_t id; /* WB_CHIPID(8b) or WBSIO_ID(16b) or WB_VENDID(16b) */
 189 const char *str;
 190 const struct lm_sensor *sensors;
 191 void (*extattach)(struct lm_softc *);
 192};
 193
 194int lm_match(struct lm_softc *);
188void lm_attach(struct lm_softc *); 195void lm_attach(struct lm_softc *);
189void lm_detach(struct lm_softc *); 196void lm_detach(struct lm_softc *);
190int lm_probe(struct lm_softc *); 
191 197
192#endif /* _DEV_ISA_NSLM7XVAR_H_ */ 198#endif /* _DEV_ISA_NSLM7XVAR_H_ */

cvs diff -r1.4 -r1.4.10.1 src/sys/dev/isa/lm_isa_common.c (expand / switch to unified diff)

--- src/sys/dev/isa/lm_isa_common.c 2016/06/01 02:37:47 1.4
+++ src/sys/dev/isa/lm_isa_common.c 2017/11/22 14:56:30 1.4.10.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lm_isa_common.c,v 1.4 2016/06/01 02:37:47 pgoyette Exp $ */ 1/* $NetBSD: lm_isa_common.c,v 1.4.10.1 2017/11/22 14:56:30 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000 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 Bill Squier. 8 * by Bill Squier.
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.
@@ -20,48 +20,48 @@ @@ -20,48 +20,48 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: lm_isa_common.c,v 1.4 2016/06/01 02:37:47 pgoyette Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: lm_isa_common.c,v 1.4.10.1 2017/11/22 14:56:30 martin Exp $");
34 34
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/systm.h> 36#include <sys/systm.h>
37#include <sys/kernel.h> 37#include <sys/kernel.h>
38#include <sys/device.h> 38#include <sys/device.h>
39#include <sys/module.h> 39#include <sys/module.h>
40#include <sys/conf.h> 40#include <sys/conf.h>
41 41
42#include <sys/bus.h> 42#include <sys/bus.h>
43 43
44#include <dev/isa/isareg.h> 44#include <dev/isa/isareg.h>
45#include <dev/isa/isavar.h> 45#include <dev/isa/isavar.h>
46 46
47#include <dev/ic/nslm7xvar.h> 47#include <dev/ic/nslm7xvar.h>
48 48
49int lm_isa_match(device_t, cfdata_t, void *); 49int lm_isa_match(device_t, cfdata_t, void *);
50void lm_isa_attach(device_t, device_t, void *); 50void lm_isa_attach(device_t, device_t, void *);
51int lm_isa_detach(device_t, int); 51int lm_isa_detach(device_t, int);
52 52
53static uint8_t lm_isa_readreg(struct lm_softc *, int); 53static uint8_t lm_isa_readreg(struct lm_softc *, int);
54static void lm_isa_writereg(struct lm_softc *, int, int); 54static void lm_isa_writereg(struct lm_softc *, int, uint8_t);
55 55
56struct lm_isa_softc { 56struct lm_isa_softc {
57 struct lm_softc lmsc; 57 struct lm_softc lmsc;
58 bus_space_tag_t lm_iot; 58 bus_space_tag_t lm_iot;
59 bus_space_handle_t lm_ioh; 59 bus_space_handle_t lm_ioh;
60}; 60};
61 61
62int 62int
63lm_isa_match(device_t parent, cfdata_t match, void *aux) 63lm_isa_match(device_t parent, cfdata_t match, void *aux)
64{ 64{
65 bus_space_handle_t ioh; 65 bus_space_handle_t ioh;
66 struct isa_attach_args *ia = aux; 66 struct isa_attach_args *ia = aux;
67 struct lm_isa_softc sc; 67 struct lm_isa_softc sc;
@@ -70,33 +70,32 @@ lm_isa_match(device_t parent, cfdata_t m @@ -70,33 +70,32 @@ lm_isa_match(device_t parent, cfdata_t m
70 /* Must supply an address */ 70 /* Must supply an address */
71 if (ia->ia_nio < 1) 71 if (ia->ia_nio < 1)
72 return 0; 72 return 0;
73 73
74 if (ISA_DIRECT_CONFIG(ia)) 74 if (ISA_DIRECT_CONFIG(ia))
75 return 0; 75 return 0;
76 76
77 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT) 77 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
78 return 0; 78 return 0;
79 79
80 if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0, &ioh)) 80 if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0, &ioh))
81 return 0; 81 return 0;
82 82
83 
84 /* Bus independent probe */ 83 /* Bus independent probe */
85 sc.lm_iot = ia->ia_iot; 84 sc.lm_iot = ia->ia_iot;
86 sc.lm_ioh = ioh; 85 sc.lm_ioh = ioh;
87 sc.lmsc.lm_writereg = lm_isa_writereg; 86 sc.lmsc.lm_writereg = lm_isa_writereg;
88 sc.lmsc.lm_readreg = lm_isa_readreg; 87 sc.lmsc.lm_readreg = lm_isa_readreg;
89 rv = lm_probe(&sc.lmsc); 88 rv = lm_match(&sc.lmsc);
90 89
91 bus_space_unmap(ia->ia_iot, ioh, 8); 90 bus_space_unmap(ia->ia_iot, ioh, 8);
92 91
93 if (rv) { 92 if (rv) {
94 ia->ia_nio = 1; 93 ia->ia_nio = 1;
95 ia->ia_io[0].ir_size = 8; 94 ia->ia_io[0].ir_size = 8;
96 95
97 ia->ia_niomem = 0; 96 ia->ia_niomem = 0;
98 ia->ia_nirq = 0; 97 ia->ia_nirq = 0;
99 ia->ia_ndrq = 0; 98 ia->ia_ndrq = 0;
100 } 99 }
101 100
102 return rv; 101 return rv;
@@ -112,52 +111,52 @@ lm_isa_attach(device_t parent, device_t  @@ -112,52 +111,52 @@ lm_isa_attach(device_t parent, device_t
112 sc->lm_iot = ia->ia_iot; 111 sc->lm_iot = ia->ia_iot;
113 112
114 if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0, 113 if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0,
115 &sc->lm_ioh)) { 114 &sc->lm_ioh)) {
116 aprint_error(": can't map i/o space\n"); 115 aprint_error(": can't map i/o space\n");
117 return; 116 return;
118 } 117 }
119 118
120 /* Bus-independent attachment */ 119 /* Bus-independent attachment */
121 sc->lmsc.sc_dev = self; 120 sc->lmsc.sc_dev = self;
122 sc->lmsc.lm_writereg = lm_isa_writereg; 121 sc->lmsc.lm_writereg = lm_isa_writereg;
123 sc->lmsc.lm_readreg = lm_isa_readreg; 122 sc->lmsc.lm_readreg = lm_isa_readreg;
124 /* pass wbsio Device ID */ 123 /* pass wbsio Device ID */
125 sc->lmsc.sioid = (uint8_t)(uintptr_t)ia->ia_aux; 124 sc->lmsc.sioid = (uint16_t)(uintptr_t)ia->ia_aux;
126 125
127 lm_attach(&sc->lmsc); 126 lm_attach(&sc->lmsc);
128} 127}
129 128
130int 129int
131lm_isa_detach(device_t self, int flags) 130lm_isa_detach(device_t self, int flags)
132{ 131{
133 struct lm_isa_softc *sc = device_private(self); 132 struct lm_isa_softc *sc = device_private(self);
134 133
135 lm_detach(&sc->lmsc); 134 lm_detach(&sc->lmsc);
136 bus_space_unmap(sc->lm_iot, sc->lm_ioh, 8); 135 bus_space_unmap(sc->lm_iot, sc->lm_ioh, 8);
137 return 0; 136 return 0;
138} 137}
139 138
140static uint8_t 139static uint8_t
141lm_isa_readreg(struct lm_softc *lmsc, int reg) 140lm_isa_readreg(struct lm_softc *lmsc, int reg)
142{ 141{
143 struct lm_isa_softc *sc = (struct lm_isa_softc *)lmsc; 142 struct lm_isa_softc *sc = (struct lm_isa_softc *)lmsc;
144 143
145 bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg); 144 bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
146 return bus_space_read_1(sc->lm_iot, sc->lm_ioh, LMC_DATA); 145 return bus_space_read_1(sc->lm_iot, sc->lm_ioh, LMC_DATA);
147} 146}
148 147
149static void 148static void
150lm_isa_writereg(struct lm_softc *lmsc, int reg, int val) 149lm_isa_writereg(struct lm_softc *lmsc, int reg, uint8_t val)
151{ 150{
152 struct lm_isa_softc *sc = (struct lm_isa_softc *)lmsc; 151 struct lm_isa_softc *sc = (struct lm_isa_softc *)lmsc;
153 152
154 bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg); 153 bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
155 bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_DATA, val); 154 bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_DATA, val);
156} 155}
157 156
158MODULE(MODULE_CLASS_DRIVER, lm_isa_common, "lm"); 157MODULE(MODULE_CLASS_DRIVER, lm_isa_common, "lm");
159 158
160static int 159static int
161lm_isa_common_modcmd(modcmd_t cmd, void *priv) 160lm_isa_common_modcmd(modcmd_t cmd, void *priv)
162{ 161{
163 if ((cmd == MODULE_CMD_INIT) || (cmd == MODULE_CMD_FINI)) 162 if ((cmd == MODULE_CMD_INIT) || (cmd == MODULE_CMD_FINI))

cvs diff -r1.10 -r1.10.10.1 src/sys/dev/isa/wbsio.c (expand / switch to unified diff)

--- src/sys/dev/isa/wbsio.c 2016/06/01 02:37:47 1.10
+++ src/sys/dev/isa/wbsio.c 2017/11/22 14:56:30 1.10.10.1
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1/* $NetBSD: wbsio.c,v 1.10 2016/06/01 02:37:47 pgoyette Exp $ */ 1/* $NetBSD: wbsio.c,v 1.10.10.1 2017/11/22 14:56:30 martin Exp $ */
2/* $OpenBSD: wbsio.c,v 1.5 2009/03/29 21:53:52 sthen Exp $ */ 2/* $OpenBSD: wbsio.c,v 1.10 2015/03/14 03:38:47 jsg Exp $ */
3/* 3/*
4 * Copyright (c) 2008 Mark Kettenis <kettenis@openbsd.org> 4 * Copyright (c) 2008 Mark Kettenis <kettenis@openbsd.org>
5 * 5 *
6 * Permission to use, copy, modify, and distribute this software for any 6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above 7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies. 8 * copyright notice and this permission notice appear in all copies.
9 * 9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
@@ -20,80 +20,78 @@ @@ -20,80 +20,78 @@
20 * Winbond LPC Super I/O driver. 20 * Winbond LPC Super I/O driver.
21 */ 21 */
22 22
23#include <sys/param.h> 23#include <sys/param.h>
24#include <sys/device.h> 24#include <sys/device.h>
25#include <sys/kernel.h> 25#include <sys/kernel.h>
26#include <sys/module.h> 26#include <sys/module.h>
27#include <sys/systm.h> 27#include <sys/systm.h>
28 28
29#include <sys/bus.h> 29#include <sys/bus.h>
30 30
31#include <dev/isa/isareg.h> 31#include <dev/isa/isareg.h>
32#include <dev/isa/isavar.h> 32#include <dev/isa/isavar.h>
33 33#include <dev/isa/wbsioreg.h>
34/* ISA bus registers */ 
35#define WBSIO_INDEX 0x00 /* Configuration Index Register */ 
36#define WBSIO_DATA 0x01 /* Configuration Data Register */ 
37 
38#define WBSIO_IOSIZE 0x02 /* ISA I/O space size */ 
39 
40#define WBSIO_CONF_EN_MAGIC 0x87 /* enable configuration mode */ 
41#define WBSIO_CONF_DS_MAGIC 0xaa /* disable configuration mode */ 
42 
43/* Configuration Space Registers */ 
44#define WBSIO_LDN 0x07 /* Logical Device Number */ 
45#define WBSIO_ID 0x20 /* Device ID */ 
46#define WBSIO_REV 0x21 /* Device Revision */ 
47 
48#define WBSIO_ID_W83627HF 0x52 
49#define WBSIO_ID_W83627THF 0x82 
50#define WBSIO_ID_W83627EHF 0x88 
51#define WBSIO_ID_W83627DHG 0xa0 
52#define WBSIO_ID_W83627SF 0x59 
53#define WBSIO_ID_W83637HF 0x70 
54#define WBSIO_ID_W83667HG 0xa5 
55#define WBSIO_ID_W83697HF 0x60 
56#define WBSIO_ID_NCT6776F 0xc3 
57 
58/* Logical Device Number (LDN) Assignments */ 
59#define WBSIO_LDN_HM 0x0b 
60 
61/* Hardware Monitor Control Registers (LDN B) */ 
62#define WBSIO_HM_ADDR_MSB 0x60 /* Address [15:8] */ 
63#define WBSIO_HM_ADDR_LSB 0x61 /* Address [7:0] */ 
64 34
65struct wbsio_softc { 35struct wbsio_softc {
66 device_t sc_dev; 36 device_t sc_dev;
67 device_t sc_lm_dev; 37 device_t sc_lm_dev;
68 38
69 bus_space_tag_t sc_iot; 39 bus_space_tag_t sc_iot;
70 bus_space_handle_t sc_ioh; 40 bus_space_handle_t sc_ioh;
71 41
72 struct isa_attach_args sc_ia; 42 struct isa_attach_args sc_ia;
73 struct isa_io sc_io; 43 struct isa_io sc_io;
74}; 44};
75 45
76int wbsio_probe(device_t, cfdata_t, void *); 46static const struct wbsio_product {
77void wbsio_attach(device_t, device_t, void *); 47 uint16_t id;
78int wbsio_detach(device_t, int); 48 bool idis12bits;
79int wbsio_rescan(device_t, const char *, const int *); 49 const char *str;
80void wbsio_childdet(device_t, device_t); 50} wbsio_products[] = {
81int wbsio_print(void *, const char *); 51 { WBSIO_ID_W83627HF, false, "W83627HF" },
 52 { WBSIO_ID_W83697HF, false, "W83697HF" },
 53 { WBSIO_ID_W83637HF, false, "W83637HF" },
 54 { WBSIO_ID_W83627THF, false, "W83627THF" },
 55 { WBSIO_ID_W83687THF, false, "W83687THF" },
 56 { WBSIO_ID_W83627DHG, true, "W83627DHG" },
 57 { WBSIO_ID_W83627DHGP, true, "W83627DHG-P" },
 58 { WBSIO_ID_W83627EHF, true, "W83627EHF" },
 59 { WBSIO_ID_W83627SF, true, "W83627SF" },
 60 { WBSIO_ID_W83627UHG, true, "W83627UHG" },
 61 { WBSIO_ID_W83667HG, true, "W83667HG" },
 62 { WBSIO_ID_W83667HGB, true, "W83667HGB" },
 63 { WBSIO_ID_W83697UG, true, "W83697UG" },
 64 { WBSIO_ID_NCT6775F, true, "NCT6775F" },
 65 { WBSIO_ID_NCT6776F, true, "NCT6776F" },
 66 { WBSIO_ID_NCT5104D, true, "NCT5104D or 610[246]D" },
 67 { WBSIO_ID_NCT6779D, true, "NCT6779D" },
 68 { WBSIO_ID_NCT6791D, true, "NCT6791D" },
 69 { WBSIO_ID_NCT6792D, true, "NCT6792D" },
 70 { WBSIO_ID_NCT6793D, true, "NCT6793D" },
 71 { WBSIO_ID_NCT6795D, true, "NCT6795D" },
 72};
82 73
83static int wbsio_search(device_t, cfdata_t, const int *, void *); 74static const struct wbsio_product *wbsio_lookup(uint8_t id, uint8_t rev);
 75static int wbsio_match(device_t, cfdata_t, void *);
 76static void wbsio_attach(device_t, device_t, void *);
 77static int wbsio_detach(device_t, int);
 78static int wbsio_rescan(device_t, const char *, const int *);
 79static void wbsio_childdet(device_t, device_t);
 80static int wbsio_print(void *, const char *);
 81static int wbsio_search(device_t, cfdata_t, const int *, void *);
84 82
85CFATTACH_DECL2_NEW(wbsio, sizeof(struct wbsio_softc), 83CFATTACH_DECL2_NEW(wbsio, sizeof(struct wbsio_softc),
86 wbsio_probe, wbsio_attach, wbsio_detach, NULL, 84 wbsio_match, wbsio_attach, wbsio_detach, NULL,
87 wbsio_rescan, wbsio_childdet); 85 wbsio_rescan, wbsio_childdet);
88 86
89static __inline void 87static __inline void
90wbsio_conf_enable(bus_space_tag_t iot, bus_space_handle_t ioh) 88wbsio_conf_enable(bus_space_tag_t iot, bus_space_handle_t ioh)
91{ 89{
92 bus_space_write_1(iot, ioh, WBSIO_INDEX, WBSIO_CONF_EN_MAGIC); 90 bus_space_write_1(iot, ioh, WBSIO_INDEX, WBSIO_CONF_EN_MAGIC);
93 bus_space_write_1(iot, ioh, WBSIO_INDEX, WBSIO_CONF_EN_MAGIC); 91 bus_space_write_1(iot, ioh, WBSIO_INDEX, WBSIO_CONF_EN_MAGIC);
94} 92}
95 93
96static __inline void 94static __inline void
97wbsio_conf_disable(bus_space_tag_t iot, bus_space_handle_t ioh) 95wbsio_conf_disable(bus_space_tag_t iot, bus_space_handle_t ioh)
98{ 96{
99 bus_space_write_1(iot, ioh, WBSIO_INDEX, WBSIO_CONF_DS_MAGIC); 97 bus_space_write_1(iot, ioh, WBSIO_INDEX, WBSIO_CONF_DS_MAGIC);
@@ -104,134 +102,140 @@ wbsio_conf_read(bus_space_tag_t iot, bus @@ -104,134 +102,140 @@ wbsio_conf_read(bus_space_tag_t iot, bus
104{ 102{
105 bus_space_write_1(iot, ioh, WBSIO_INDEX, index); 103 bus_space_write_1(iot, ioh, WBSIO_INDEX, index);
106 return (bus_space_read_1(iot, ioh, WBSIO_DATA)); 104 return (bus_space_read_1(iot, ioh, WBSIO_DATA));
107} 105}
108 106
109static __inline void 107static __inline void
110wbsio_conf_write(bus_space_tag_t iot, bus_space_handle_t ioh, uint8_t index, 108wbsio_conf_write(bus_space_tag_t iot, bus_space_handle_t ioh, uint8_t index,
111 uint8_t data) 109 uint8_t data)
112{ 110{
113 bus_space_write_1(iot, ioh, WBSIO_INDEX, index); 111 bus_space_write_1(iot, ioh, WBSIO_INDEX, index);
114 bus_space_write_1(iot, ioh, WBSIO_DATA, data); 112 bus_space_write_1(iot, ioh, WBSIO_DATA, data);
115} 113}
116 114
 115static const struct wbsio_product *
 116wbsio_lookup(uint8_t id, uint8_t rev)
 117{
 118 uint16_t wid = ((uint16_t)id << 4) | (rev >> 4);
 119 int i;
 120
 121 for (i = 0; i < __arraycount(wbsio_products); i++) {
 122 if (wbsio_products[i].idis12bits) {
 123 if (wbsio_products[i].id == wid)
 124 return &wbsio_products[i];
 125 } else {
 126 if (wbsio_products[i].id == id)
 127 return &wbsio_products[i];
 128 }
 129 }
 130
 131 /* Not found */
 132 return NULL;
 133}
 134
117int 135int
118wbsio_probe(device_t parent, cfdata_t match, void *aux) 136wbsio_match(device_t parent, cfdata_t match, void *aux)
119{ 137{
120 struct isa_attach_args *ia = aux; 138 struct isa_attach_args *ia = aux;
 139 const struct wbsio_product *product;
121 bus_space_tag_t iot; 140 bus_space_tag_t iot;
122 bus_space_handle_t ioh; 141 bus_space_handle_t ioh;
123 uint8_t reg; 142 uint8_t id, rev;
124 143
125 /* Must supply an address */ 144 /* Must supply an address */
126 if (ia->ia_nio < 1) 145 if (ia->ia_nio < 1)
127 return 0; 146 return 0;
128 147
129 if (ISA_DIRECT_CONFIG(ia)) 148 if (ISA_DIRECT_CONFIG(ia))
130 return 0; 149 return 0;
131 150
132 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT) 151 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
133 return 0; 152 return 0;
134 153
135 /* Match by device ID */ 154 /* Match by device ID */
136 iot = ia->ia_iot; 155 iot = ia->ia_iot;
137 if (bus_space_map(iot, ia->ia_io[0].ir_addr, WBSIO_IOSIZE, 0, &ioh)) 156 if (bus_space_map(iot, ia->ia_io[0].ir_addr, WBSIO_IOSIZE, 0, &ioh))
138 return 0; 157 return 0;
139 wbsio_conf_enable(iot, ioh); 158 wbsio_conf_enable(iot, ioh);
140 reg = wbsio_conf_read(iot, ioh, WBSIO_ID); 159 id = wbsio_conf_read(iot, ioh, WBSIO_ID);
141 aprint_debug("wbsio_probe: id 0x%02x\n", reg); 160 rev = wbsio_conf_read(iot, ioh, WBSIO_REV);
 161 aprint_debug("wbsio_probe: id 0x%02x, rev 0x%02x\n", id, rev);
142 wbsio_conf_disable(iot, ioh); 162 wbsio_conf_disable(iot, ioh);
143 bus_space_unmap(iot, ioh, WBSIO_IOSIZE); 163 bus_space_unmap(iot, ioh, WBSIO_IOSIZE);
144 switch (reg) { 
145 case WBSIO_ID_W83627HF: 
146 case WBSIO_ID_W83627THF: 
147 case WBSIO_ID_W83627EHF: 
148 case WBSIO_ID_W83627DHG: 
149 case WBSIO_ID_W83637HF: 
150 case WBSIO_ID_W83697HF: 
151 case WBSIO_ID_NCT6776F: 
152 ia->ia_nio = 1; 
153 ia->ia_io[0].ir_size = WBSIO_IOSIZE; 
154 ia->ia_niomem = 0; 
155 ia->ia_nirq = 0; 
156 ia->ia_ndrq = 0; 
157 return 1; 
158 } 
159 164
160 return 0; 165 if ((product = wbsio_lookup(id, rev)) == NULL)
 166 return 0;
 167
 168 ia->ia_nio = 1;
 169 ia->ia_io[0].ir_size = WBSIO_IOSIZE;
 170 ia->ia_niomem = 0;
 171 ia->ia_nirq = 0;
 172 ia->ia_ndrq = 0;
 173 return 1;
161} 174}
162 175
163void 176void
164wbsio_attach(device_t parent, device_t self, void *aux) 177wbsio_attach(device_t parent, device_t self, void *aux)
165{ 178{
166 struct wbsio_softc *sc = device_private(self); 179 struct wbsio_softc *sc = device_private(self);
167 struct isa_attach_args *ia = aux; 180 struct isa_attach_args *ia = aux;
168 const char *desc = NULL; 181 const struct wbsio_product *product;
169 const char *vendor = "Winbond"; 182 const char *desc;
170 uint8_t reg; 183 const char *vendor;
 184 uint8_t id, rev;
171 185
172 sc->sc_dev = self; 186 sc->sc_dev = self;
173 187
174 sc->sc_ia = *ia; 188 sc->sc_ia = *ia;
175 189
176 /* Map ISA I/O space */ 190 /* Map ISA I/O space */
177 sc->sc_iot = ia->ia_iot; 191 sc->sc_iot = ia->ia_iot;
178 if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, 192 if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr,
179 WBSIO_IOSIZE, 0, &sc->sc_ioh)) { 193 WBSIO_IOSIZE, 0, &sc->sc_ioh)) {
180 aprint_error(": can't map i/o space\n"); 194 aprint_error(": can't map i/o space\n");
181 return; 195 return;
182 } 196 }
183 197
184 /* Enter configuration mode */ 198 /* Enter configuration mode */
185 wbsio_conf_enable(sc->sc_iot, sc->sc_ioh); 199 wbsio_conf_enable(sc->sc_iot, sc->sc_ioh);
186 200
187 /* Read device ID */ 201 /* Read device ID */
188 reg = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_ID); 202 id = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_ID);
189 switch (reg) { 
190 case WBSIO_ID_W83627HF: 
191 desc = "W83627HF"; 
192 break; 
193 case WBSIO_ID_W83627THF: 
194 desc = "W83627THF"; 
195 break; 
196 case WBSIO_ID_W83627EHF: 
197 desc = "W83627EHF"; 
198 break; 
199 case WBSIO_ID_W83627DHG: 
200 desc = "W83627DHG"; 
201 break; 
202 case WBSIO_ID_W83637HF: 
203 desc = "W83637HF"; 
204 break; 
205 case WBSIO_ID_W83667HG: 
206 desc = "W83667HG"; 
207 break; 
208 case WBSIO_ID_W83697HF: 
209 desc = "W83697HF"; 
210 break; 
211 case WBSIO_ID_NCT6776F: 
212 vendor = "Nuvoton"; 
213 desc = "NCT6776F"; 
214 break; 
215 } 
216 /* Read device revision */ 203 /* Read device revision */
217 reg = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_REV); 204 rev = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_REV);
218 
219 aprint_naive("\n"); 
220 aprint_normal(": %s LPC Super I/O %s rev 0x%02x\n", vendor, desc, reg); 
221 205
222 /* Escape from configuration mode */ 206 /* Escape from configuration mode */
223 wbsio_conf_disable(sc->sc_iot, sc->sc_ioh); 207 wbsio_conf_disable(sc->sc_iot, sc->sc_ioh);
224 208
 209 if ((product = wbsio_lookup(id, rev)) == NULL) {
 210 aprint_error_dev(self, "Unknown device. Failed to attach\n");
 211 return;
 212 }
 213 if (product->idis12bits)
 214 rev &= 0x0f; /* Revision is low 4bits */
 215
 216 desc = product->str;
 217 if (desc[0] == 'W')
 218 vendor = "Winbond";
 219 else
 220 vendor = "Nuvoton";
 221 aprint_naive("\n");
 222 aprint_normal(": %s LPC Super I/O %s rev ", vendor, desc);
 223 if (product->idis12bits) {
 224 /* Revision filed is 4bit only */
 225 aprint_normal("%c\n", 'A' + rev);
 226 } else
 227 aprint_normal("0x%02x\n", rev);
 228
225 if (!pmf_device_register(self, NULL, NULL)) 229 if (!pmf_device_register(self, NULL, NULL))
226 aprint_error_dev(self, "couldn't establish power handler\n"); 230 aprint_error_dev(self, "couldn't establish power handler\n");
227 wbsio_rescan(self, "wbsio", NULL); 231 wbsio_rescan(self, "wbsio", NULL);
228} 232}
229 233
230int 234int
231wbsio_detach(device_t self, int flags) 235wbsio_detach(device_t self, int flags)
232{ 236{
233 struct wbsio_softc *sc = device_private(self); 237 struct wbsio_softc *sc = device_private(self);
234 int rc; 238 int rc;
235 239
236 if ((rc = config_detach_children(self, flags)) != 0) 240 if ((rc = config_detach_children(self, flags)) != 0)
237 return rc; 241 return rc;
@@ -252,59 +256,69 @@ wbsio_rescan(device_t self, const char * @@ -252,59 +256,69 @@ wbsio_rescan(device_t self, const char *
252void 256void
253wbsio_childdet(device_t self, device_t child) 257wbsio_childdet(device_t self, device_t child)
254{ 258{
255 struct wbsio_softc *sc = device_private(self); 259 struct wbsio_softc *sc = device_private(self);
256 260
257 if (sc->sc_lm_dev == child) 261 if (sc->sc_lm_dev == child)
258 sc->sc_lm_dev = NULL; 262 sc->sc_lm_dev = NULL;
259} 263}
260 264
261static int 265static int
262wbsio_search(device_t parent, cfdata_t cf, const int *slocs, void *aux) 266wbsio_search(device_t parent, cfdata_t cf, const int *slocs, void *aux)
263{ 267{
264 struct wbsio_softc *sc = device_private(parent); 268 struct wbsio_softc *sc = device_private(parent);
 269 const struct wbsio_product *product;
265 uint16_t iobase; 270 uint16_t iobase;
266 uint8_t reg0, reg1, devid; 271 uint16_t devid;
 272 uint8_t reg0, reg1, rev;
267 273
268 /* Enter configuration mode */ 274 /* Enter configuration mode */
269 wbsio_conf_enable(sc->sc_iot, sc->sc_ioh); 275 wbsio_conf_enable(sc->sc_iot, sc->sc_ioh);
270 276
271 /* Select HM logical device */ 277 /* Select HM logical device */
272 wbsio_conf_write(sc->sc_iot, sc->sc_ioh, WBSIO_LDN, WBSIO_LDN_HM); 278 wbsio_conf_write(sc->sc_iot, sc->sc_ioh, WBSIO_LDN, WBSIO_LDN_HM);
273 279
274 /* 280 /*
275 * The address should be 8-byte aligned, but it seems some 281 * The address should be 8-byte aligned, but it seems some
276 * BIOSes ignore this. They get away with it, because 282 * BIOSes ignore this. They get away with it, because
277 * Apparently the hardware simply ignores the lower three 283 * Apparently the hardware simply ignores the lower three
278 * bits. We do the same here. 284 * bits. We do the same here.
279 */ 285 */
280 reg0 = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_HM_ADDR_LSB); 286 reg0 = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_HM_ADDR_LSB);
281 reg1 = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_HM_ADDR_MSB); 287 reg1 = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_HM_ADDR_MSB);
282 288
283 /* Escape from configuration mode */ 289 /* Escape from configuration mode */
284 wbsio_conf_disable(sc->sc_iot, sc->sc_ioh); 290 wbsio_conf_disable(sc->sc_iot, sc->sc_ioh);
285 291
286 iobase = (reg1 << 8) | (reg0 & ~0x7); 292 iobase = (reg1 << 8) | (reg0 & ~0x7);
287 293
288 if (iobase == 0) 294 if (iobase == 0)
289 return -1; 295 return -1;
290 296
291 /* Enter configuration mode */ 297 /* Enter configuration mode */
292 wbsio_conf_enable(sc->sc_iot, sc->sc_ioh); 298 wbsio_conf_enable(sc->sc_iot, sc->sc_ioh);
293 /* Read device ID */ 299 /* Read device ID and revision */
294 devid = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_ID); 300 devid = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_ID);
 301 rev = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_REV);
295 /* Escape from configuration mode */ 302 /* Escape from configuration mode */
296 wbsio_conf_disable(sc->sc_iot, sc->sc_ioh); 303 wbsio_conf_disable(sc->sc_iot, sc->sc_ioh);
297 304
 305 if ((product = wbsio_lookup(devid, rev)) == NULL) {
 306 aprint_error_dev(parent, "%s: Unknown device.\n", __func__);
 307 return -1;
 308 }
 309 if (product->idis12bits)
 310 devid = (devid << 4) | (rev >> 4);
 311
298 sc->sc_ia.ia_nio = 1; 312 sc->sc_ia.ia_nio = 1;
299 sc->sc_ia.ia_io = &sc->sc_io; 313 sc->sc_ia.ia_io = &sc->sc_io;
300 sc->sc_ia.ia_io[0].ir_addr = iobase; 314 sc->sc_ia.ia_io[0].ir_addr = iobase;
301 sc->sc_ia.ia_io[0].ir_size = 8; 315 sc->sc_ia.ia_io[0].ir_size = 8;
302 sc->sc_ia.ia_niomem = 0; 316 sc->sc_ia.ia_niomem = 0;
303 sc->sc_ia.ia_nirq = 0; 317 sc->sc_ia.ia_nirq = 0;
304 sc->sc_ia.ia_ndrq = 0; 318 sc->sc_ia.ia_ndrq = 0;
305 /* Store device-id to ia_aux */ 319 /* Store device-id to ia_aux */
306 sc->sc_ia.ia_aux = (void *)(uintptr_t)devid; 320 sc->sc_ia.ia_aux = (void *)(uintptr_t)devid;
307 sc->sc_lm_dev = config_attach(parent, cf, &sc->sc_ia, wbsio_print); 321 sc->sc_lm_dev = config_attach(parent, cf, &sc->sc_ia, wbsio_print);
308 322
309 return 0; 323 return 0;
310} 324}

File Added: src/sys/dev/isa/wbsioreg.h
/* $NetBSD: wbsioreg.h,v 1.5.2.2 2017/11/22 14:56:30 martin Exp $ */

/* $OpenBSD: wbsioreg.h,v 1.4 2015/01/02 23:02:54 chris Exp $ */
/*
 * Copyright (c) 2008 Mark Kettenis <kettenis@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 * Winbond LPC Super I/O driver registers
 */

/* ISA bus registers */
#define WBSIO_INDEX		0x00	/* Configuration Index Register */
#define WBSIO_DATA		0x01	/* Configuration Data Register */

#define WBSIO_IOSIZE		0x02	/* ISA I/O space size */

#define WBSIO_CONF_EN_MAGIC	0x87	/* enable configuration mode */
#define WBSIO_CONF_DS_MAGIC	0xaa	/* disable configuration mode */

/* Configuration Space Registers */
#define WBSIO_LDN		0x07	/* Logical Device Number */
#define WBSIO_ID		0x20	/* Device ID */
#define WBSIO_REV		0x21	/* Device Revision */

#define WBSIO_ID_W83627HF	0x52
#define WBSIO_ID_W83697HF	0x60
#define WBSIO_ID_W83637HF	0x70
#define WBSIO_ID_W83627THF	0x82
#define WBSIO_ID_W83687THF	0x85
#define WBSIO_ID_W83627SF	0x595
#define WBSIO_ID_W83697UG	0x681
#define WBSIO_ID_W83627EHF_A	0x885
#define WBSIO_ID_W83627EHF	0x886
#define WBSIO_ID_W83627DHG	0xa02
#define WBSIO_ID_W83627UHG	0xa23
#define WBSIO_ID_W83667HG	0xa51
#define WBSIO_ID_W83627DHGP	0xb07
#define WBSIO_ID_W83667HGB	0xb35
#define WBSIO_ID_NCT6775F	0xb47
#define WBSIO_ID_NCT6776F	0xc33
#define WBSIO_ID_NCT5104D	0xc45	/* 610[246]D */
#define WBSIO_ID_NCT6779D	0xc56
#define WBSIO_ID_NCT6791D	0xc80
#define WBSIO_ID_NCT6792D	0xc91
#define WBSIO_ID_NCT6793D	0xd12
#define WBSIO_ID_NCT6795D	0xd35

/* Logical Device Number (LDN) Assignments */
#define WBSIO_LDN_HM		0x0b

/* Hardware Monitor Control Registers (LDN B) */
#define WBSIO_HM_ADDR_MSB	0x60	/* Address [15:8] */
#define WBSIO_HM_ADDR_LSB	0x61	/* Address [7:0] */