nslm7x.c revision 1.23 1 1.23 xtraeme /* $NetBSD: nslm7x.c,v 1.23 2005/10/15 00:41:48 xtraeme Exp $ */
2 1.1 groo
3 1.1 groo /*-
4 1.1 groo * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.1 groo * All rights reserved.
6 1.1 groo *
7 1.1 groo * This code is derived from software contributed to The NetBSD Foundation
8 1.1 groo * by Bill Squier.
9 1.1 groo *
10 1.1 groo * Redistribution and use in source and binary forms, with or without
11 1.1 groo * modification, are permitted provided that the following conditions
12 1.1 groo * are met:
13 1.1 groo * 1. Redistributions of source code must retain the above copyright
14 1.1 groo * notice, this list of conditions and the following disclaimer.
15 1.1 groo * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 groo * notice, this list of conditions and the following disclaimer in the
17 1.1 groo * documentation and/or other materials provided with the distribution.
18 1.1 groo * 3. All advertising materials mentioning features or use of this software
19 1.1 groo * must display the following acknowledgement:
20 1.1 groo * This product includes software developed by the NetBSD
21 1.1 groo * Foundation, Inc. and its contributors.
22 1.1 groo * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 groo * contributors may be used to endorse or promote products derived
24 1.1 groo * from this software without specific prior written permission.
25 1.1 groo *
26 1.1 groo * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 groo * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 groo * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 groo * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 groo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 groo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 groo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 groo * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 groo * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 groo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 groo * POSSIBILITY OF SUCH DAMAGE.
37 1.1 groo */
38 1.13 lukem
39 1.13 lukem #include <sys/cdefs.h>
40 1.23 xtraeme __KERNEL_RCSID(0, "$NetBSD: nslm7x.c,v 1.23 2005/10/15 00:41:48 xtraeme Exp $");
41 1.1 groo
42 1.1 groo #include <sys/param.h>
43 1.1 groo #include <sys/systm.h>
44 1.1 groo #include <sys/kernel.h>
45 1.1 groo #include <sys/proc.h>
46 1.1 groo #include <sys/device.h>
47 1.1 groo #include <sys/malloc.h>
48 1.1 groo #include <sys/errno.h>
49 1.1 groo #include <sys/queue.h>
50 1.1 groo #include <sys/lock.h>
51 1.1 groo #include <sys/ioctl.h>
52 1.1 groo #include <sys/conf.h>
53 1.1 groo #include <sys/time.h>
54 1.1 groo
55 1.1 groo #include <machine/bus.h>
56 1.1 groo
57 1.1 groo #include <dev/isa/isareg.h>
58 1.1 groo #include <dev/isa/isavar.h>
59 1.1 groo
60 1.4 thorpej #include <dev/sysmon/sysmonvar.h>
61 1.4 thorpej
62 1.1 groo #include <dev/ic/nslm7xvar.h>
63 1.1 groo
64 1.1 groo #include <machine/intr.h>
65 1.1 groo #include <machine/bus.h>
66 1.1 groo
67 1.1 groo #if defined(LMDEBUG)
68 1.19 christos #define DPRINTF(x) printf x
69 1.1 groo #else
70 1.1 groo #define DPRINTF(x)
71 1.1 groo #endif
72 1.1 groo
73 1.4 thorpej const struct envsys_range lm_ranges[] = { /* sc->sensors sub-intervals */
74 1.5 bouyer /* for each unit type */
75 1.1 groo { 7, 7, ENVSYS_STEMP },
76 1.1 groo { 8, 10, ENVSYS_SFANRPM },
77 1.1 groo { 1, 0, ENVSYS_SVOLTS_AC }, /* None */
78 1.1 groo { 0, 6, ENVSYS_SVOLTS_DC },
79 1.1 groo { 1, 0, ENVSYS_SOHMS }, /* None */
80 1.1 groo { 1, 0, ENVSYS_SWATTS }, /* None */
81 1.1 groo { 1, 0, ENVSYS_SAMPS } /* None */
82 1.1 groo };
83 1.1 groo
84 1.5 bouyer
85 1.20 perry static void setup_fan(struct lm_softc *, int, int);
86 1.20 perry static void setup_temp(struct lm_softc *, int, int);
87 1.20 perry static void wb_setup_volt(struct lm_softc *);
88 1.20 perry
89 1.20 perry int lm_match(struct lm_softc *);
90 1.20 perry int wb_match(struct lm_softc *);
91 1.20 perry int itec_match(struct lm_softc *);
92 1.20 perry int def_match(struct lm_softc *);
93 1.20 perry void lm_common_match(struct lm_softc *);
94 1.20 perry static int lm_generic_banksel(struct lm_softc *, int);
95 1.20 perry
96 1.20 perry static void generic_stemp(struct lm_softc *, struct envsys_tre_data *);
97 1.20 perry static void generic_svolt(struct lm_softc *, struct envsys_tre_data *,
98 1.20 perry struct envsys_basic_info *);
99 1.20 perry static void generic_fanrpm(struct lm_softc *, struct envsys_tre_data *);
100 1.20 perry
101 1.20 perry void lm_refresh_sensor_data(struct lm_softc *);
102 1.20 perry
103 1.20 perry static void wb_svolt(struct lm_softc *);
104 1.20 perry static void wb_stemp(struct lm_softc *, struct envsys_tre_data *, int);
105 1.20 perry static void wb781_fanrpm(struct lm_softc *, struct envsys_tre_data *);
106 1.20 perry static void wb_fanrpm(struct lm_softc *, struct envsys_tre_data *);
107 1.20 perry
108 1.20 perry void wb781_refresh_sensor_data(struct lm_softc *);
109 1.20 perry void wb782_refresh_sensor_data(struct lm_softc *);
110 1.20 perry void wb697_refresh_sensor_data(struct lm_softc *);
111 1.20 perry
112 1.20 perry static void itec_svolt(struct lm_softc *, struct envsys_tre_data *,
113 1.20 perry struct envsys_basic_info *);
114 1.20 perry static void itec_stemp(struct lm_softc *, struct envsys_tre_data *);
115 1.20 perry static void itec_fanrpm(struct lm_softc *, struct envsys_tre_data *);
116 1.20 perry void itec_refresh_sensor_data(struct lm_softc *);
117 1.20 perry
118 1.20 perry int lm_gtredata(struct sysmon_envsys *, struct envsys_tre_data *);
119 1.20 perry
120 1.20 perry int generic_streinfo_fan(struct lm_softc *, struct envsys_basic_info *,
121 1.20 perry int, struct envsys_basic_info *);
122 1.20 perry int lm_streinfo(struct sysmon_envsys *, struct envsys_basic_info *);
123 1.20 perry int wb781_streinfo(struct sysmon_envsys *, struct envsys_basic_info *);
124 1.20 perry int wb782_streinfo(struct sysmon_envsys *, struct envsys_basic_info *);
125 1.20 perry int itec_streinfo(struct sysmon_envsys *, struct envsys_basic_info *);
126 1.5 bouyer
127 1.5 bouyer struct lm_chip {
128 1.20 perry int (*chip_match)(struct lm_softc *);
129 1.5 bouyer };
130 1.5 bouyer
131 1.5 bouyer struct lm_chip lm_chips[] = {
132 1.19 christos { itec_match },
133 1.8 bouyer { wb_match },
134 1.8 bouyer { lm_match },
135 1.8 bouyer { def_match } /* Must be last */
136 1.5 bouyer };
137 1.5 bouyer
138 1.1 groo
139 1.17 ad int
140 1.17 ad lm_generic_banksel(lmsc, bank)
141 1.17 ad struct lm_softc *lmsc;
142 1.17 ad int bank;
143 1.1 groo {
144 1.1 groo
145 1.17 ad (*lmsc->lm_writereg)(lmsc, WB_BANKSEL, bank);
146 1.19 christos return 0;
147 1.1 groo }
148 1.1 groo
149 1.1 groo
150 1.1 groo /*
151 1.2 groo * bus independent probe
152 1.2 groo */
153 1.2 groo int
154 1.2 groo lm_probe(iot, ioh)
155 1.2 groo bus_space_tag_t iot;
156 1.2 groo bus_space_handle_t ioh;
157 1.2 groo {
158 1.2 groo u_int8_t cr;
159 1.2 groo int rv;
160 1.2 groo
161 1.19 christos /*
162 1.19 christos * Check for it8705f, before we do the chip reset.
163 1.19 christos * In case of an it8705f this might reset all the fan control
164 1.19 christos * parameters to defaults which would void all settings done by
165 1.19 christos * the BOOTROM/BIOS.
166 1.19 christos */
167 1.19 christos bus_space_write_1(iot, ioh, LMC_ADDR, ITEC_RES48);
168 1.19 christos cr = bus_space_read_1(iot, ioh, LMC_DATA);
169 1.19 christos
170 1.19 christos if (cr == ITEC_RES48_DEFAULT) {
171 1.19 christos bus_space_write_1(iot, ioh, LMC_ADDR, ITEC_RES52);
172 1.19 christos cr = bus_space_read_1(iot, ioh, LMC_DATA);
173 1.19 christos if (cr == ITEC_RES52_DEFAULT)
174 1.19 christos return 1;
175 1.19 christos }
176 1.19 christos
177 1.2 groo /* Check for some power-on defaults */
178 1.2 groo bus_space_write_1(iot, ioh, LMC_ADDR, LMD_CONFIG);
179 1.2 groo
180 1.2 groo /* Perform LM78 reset */
181 1.2 groo bus_space_write_1(iot, ioh, LMC_DATA, 0x80);
182 1.2 groo
183 1.2 groo /* XXX - Why do I have to reselect the register? */
184 1.2 groo bus_space_write_1(iot, ioh, LMC_ADDR, LMD_CONFIG);
185 1.2 groo cr = bus_space_read_1(iot, ioh, LMC_DATA);
186 1.2 groo
187 1.2 groo /* XXX - spec says *only* 0x08! */
188 1.23 xtraeme if ((cr == 0x08) || (cr == 0x01) || (cr == 0x03))
189 1.2 groo rv = 1;
190 1.2 groo else
191 1.2 groo rv = 0;
192 1.2 groo
193 1.2 groo DPRINTF(("lm: rv = %d, cr = %x\n", rv, cr));
194 1.2 groo
195 1.2 groo return (rv);
196 1.2 groo }
197 1.2 groo
198 1.2 groo
199 1.2 groo /*
200 1.1 groo * pre: lmsc contains valid busspace tag and handle
201 1.1 groo */
202 1.1 groo void
203 1.1 groo lm_attach(lmsc)
204 1.1 groo struct lm_softc *lmsc;
205 1.1 groo {
206 1.16 thorpej u_int i;
207 1.1 groo
208 1.17 ad /* Install default bank selection routine, if none given. */
209 1.17 ad if (lmsc->lm_banksel == NULL)
210 1.17 ad lmsc->lm_banksel = lm_generic_banksel;
211 1.17 ad
212 1.5 bouyer for (i = 0; i < sizeof(lm_chips) / sizeof(lm_chips[0]); i++)
213 1.5 bouyer if (lm_chips[i].chip_match(lmsc))
214 1.5 bouyer break;
215 1.1 groo
216 1.1 groo /* Start the monitoring loop */
217 1.17 ad (*lmsc->lm_writereg)(lmsc, LMD_CONFIG, 0x01);
218 1.1 groo
219 1.1 groo /* Indicate we have never read the registers */
220 1.1 groo timerclear(&lmsc->lastread);
221 1.1 groo
222 1.1 groo /* Initialize sensors */
223 1.5 bouyer for (i = 0; i < lmsc->numsensors; ++i) {
224 1.1 groo lmsc->sensors[i].sensor = lmsc->info[i].sensor = i;
225 1.1 groo lmsc->sensors[i].validflags = (ENVSYS_FVALID|ENVSYS_FCURVALID);
226 1.1 groo lmsc->info[i].validflags = ENVSYS_FVALID;
227 1.1 groo lmsc->sensors[i].warnflags = ENVSYS_WARN_OK;
228 1.1 groo }
229 1.4 thorpej /*
230 1.4 thorpej * Hook into the System Monitor.
231 1.4 thorpej */
232 1.4 thorpej lmsc->sc_sysmon.sme_ranges = lm_ranges;
233 1.4 thorpej lmsc->sc_sysmon.sme_sensor_info = lmsc->info;
234 1.4 thorpej lmsc->sc_sysmon.sme_sensor_data = lmsc->sensors;
235 1.4 thorpej lmsc->sc_sysmon.sme_cookie = lmsc;
236 1.4 thorpej
237 1.4 thorpej lmsc->sc_sysmon.sme_gtredata = lm_gtredata;
238 1.5 bouyer /* sme_streinfo set in chip-specific attach */
239 1.4 thorpej
240 1.5 bouyer lmsc->sc_sysmon.sme_nsensors = lmsc->numsensors;
241 1.4 thorpej lmsc->sc_sysmon.sme_envsys_version = 1000;
242 1.4 thorpej
243 1.4 thorpej if (sysmon_envsys_register(&lmsc->sc_sysmon))
244 1.4 thorpej printf("%s: unable to register with sysmon\n",
245 1.4 thorpej lmsc->sc_dev.dv_xname);
246 1.1 groo }
247 1.1 groo
248 1.5 bouyer int
249 1.5 bouyer lm_match(sc)
250 1.5 bouyer struct lm_softc *sc;
251 1.5 bouyer {
252 1.5 bouyer int i;
253 1.5 bouyer
254 1.5 bouyer /* See if we have an LM78 or LM79 */
255 1.17 ad i = (*sc->lm_readreg)(sc, LMD_CHIPID) & LM_ID_MASK;
256 1.5 bouyer switch(i) {
257 1.5 bouyer case LM_ID_LM78:
258 1.5 bouyer printf(": LM78\n");
259 1.5 bouyer break;
260 1.5 bouyer case LM_ID_LM78J:
261 1.5 bouyer printf(": LM78J\n");
262 1.5 bouyer break;
263 1.5 bouyer case LM_ID_LM79:
264 1.5 bouyer printf(": LM79\n");
265 1.15 bouyer break;
266 1.15 bouyer case LM_ID_LM81:
267 1.15 bouyer printf(": LM81\n");
268 1.5 bouyer break;
269 1.5 bouyer default:
270 1.5 bouyer return 0;
271 1.5 bouyer }
272 1.5 bouyer lm_common_match(sc);
273 1.5 bouyer return 1;
274 1.5 bouyer }
275 1.1 groo
276 1.1 groo int
277 1.5 bouyer def_match(sc)
278 1.5 bouyer struct lm_softc *sc;
279 1.5 bouyer {
280 1.5 bouyer int i;
281 1.5 bouyer
282 1.17 ad i = (*sc->lm_readreg)(sc, LMD_CHIPID) & LM_ID_MASK;
283 1.17 ad printf(": Unknown chip (ID %d)\n", i);
284 1.5 bouyer lm_common_match(sc);
285 1.5 bouyer return 1;
286 1.5 bouyer }
287 1.5 bouyer
288 1.5 bouyer void
289 1.5 bouyer lm_common_match(sc)
290 1.5 bouyer struct lm_softc *sc;
291 1.1 groo {
292 1.5 bouyer int i;
293 1.5 bouyer sc->numsensors = LM_NUM_SENSORS;
294 1.5 bouyer sc->refresh_sensor_data = lm_refresh_sensor_data;
295 1.5 bouyer
296 1.5 bouyer for (i = 0; i < 7; ++i) {
297 1.5 bouyer sc->sensors[i].units = sc->info[i].units =
298 1.5 bouyer ENVSYS_SVOLTS_DC;
299 1.18 itojun snprintf(sc->info[i].desc, sizeof(sc->info[i].desc),
300 1.18 itojun "IN %d", i);
301 1.5 bouyer }
302 1.5 bouyer
303 1.5 bouyer /* default correction factors for resistors on higher voltage inputs */
304 1.5 bouyer sc->info[0].rfact = sc->info[1].rfact =
305 1.5 bouyer sc->info[2].rfact = 10000;
306 1.5 bouyer sc->info[3].rfact = (int)(( 90.9 / 60.4) * 10000);
307 1.5 bouyer sc->info[4].rfact = (int)(( 38.0 / 10.0) * 10000);
308 1.5 bouyer sc->info[5].rfact = (int)((210.0 / 60.4) * 10000);
309 1.5 bouyer sc->info[6].rfact = (int)(( 90.9 / 60.4) * 10000);
310 1.5 bouyer
311 1.5 bouyer sc->sensors[7].units = ENVSYS_STEMP;
312 1.5 bouyer strcpy(sc->info[7].desc, "Temp");
313 1.5 bouyer
314 1.8 bouyer setup_fan(sc, 8, 3);
315 1.5 bouyer sc->sc_sysmon.sme_streinfo = lm_streinfo;
316 1.5 bouyer }
317 1.1 groo
318 1.5 bouyer int
319 1.5 bouyer wb_match(sc)
320 1.5 bouyer struct lm_softc *sc;
321 1.5 bouyer {
322 1.5 bouyer int i, j;
323 1.1 groo
324 1.17 ad (*sc->lm_writereg)(sc, WB_BANKSEL, WB_BANKSEL_HBAC);
325 1.17 ad j = (*sc->lm_readreg)(sc, WB_VENDID) << 8;
326 1.17 ad (*sc->lm_writereg)(sc, WB_BANKSEL, 0);
327 1.17 ad j |= (*sc->lm_readreg)(sc, WB_VENDID);
328 1.11 veego DPRINTF(("winbond vend id 0x%x\n", j));
329 1.5 bouyer if (j != WB_VENDID_WINBOND)
330 1.5 bouyer return 0;
331 1.7 bouyer /* read device ID */
332 1.17 ad (*sc->lm_banksel)(sc, 0);
333 1.17 ad j = (*sc->lm_readreg)(sc, WB_BANK0_CHIPID);
334 1.11 veego DPRINTF(("winbond chip id 0x%x\n", j));
335 1.7 bouyer switch(j) {
336 1.7 bouyer case WB_CHIPID_83781:
337 1.10 bouyer case WB_CHIPID_83781_2:
338 1.7 bouyer printf(": W83781D\n");
339 1.7 bouyer
340 1.7 bouyer for (i = 0; i < 7; ++i) {
341 1.7 bouyer sc->sensors[i].units = sc->info[i].units =
342 1.7 bouyer ENVSYS_SVOLTS_DC;
343 1.18 itojun snprintf(sc->info[i].desc, sizeof(sc->info[i].desc),
344 1.18 itojun "IN %d", i);
345 1.7 bouyer }
346 1.7 bouyer
347 1.7 bouyer /* default correction factors for higher voltage inputs */
348 1.7 bouyer sc->info[0].rfact = sc->info[1].rfact =
349 1.7 bouyer sc->info[2].rfact = 10000;
350 1.7 bouyer sc->info[3].rfact = (int)(( 90.9 / 60.4) * 10000);
351 1.7 bouyer sc->info[4].rfact = (int)(( 38.0 / 10.0) * 10000);
352 1.7 bouyer sc->info[5].rfact = (int)((210.0 / 60.4) * 10000);
353 1.7 bouyer sc->info[6].rfact = (int)(( 90.9 / 60.4) * 10000);
354 1.7 bouyer
355 1.9 bouyer setup_temp(sc, 7, 3);
356 1.9 bouyer setup_fan(sc, 10, 3);
357 1.7 bouyer
358 1.9 bouyer sc->numsensors = WB83781_NUM_SENSORS;
359 1.9 bouyer sc->refresh_sensor_data = wb781_refresh_sensor_data;
360 1.7 bouyer sc->sc_sysmon.sme_streinfo = wb781_streinfo;
361 1.7 bouyer return 1;
362 1.8 bouyer case WB_CHIPID_83697:
363 1.8 bouyer printf(": W83697HF\n");
364 1.8 bouyer wb_setup_volt(sc);
365 1.8 bouyer setup_temp(sc, 9, 2);
366 1.8 bouyer setup_fan(sc, 11, 3);
367 1.8 bouyer sc->numsensors = WB83697_NUM_SENSORS;
368 1.8 bouyer sc->refresh_sensor_data = wb697_refresh_sensor_data;
369 1.8 bouyer sc->sc_sysmon.sme_streinfo = wb782_streinfo;
370 1.17 ad return 1;
371 1.7 bouyer case WB_CHIPID_83782:
372 1.7 bouyer printf(": W83782D\n");
373 1.7 bouyer break;
374 1.7 bouyer case WB_CHIPID_83627:
375 1.7 bouyer printf(": W83627HF\n");
376 1.7 bouyer break;
377 1.23 xtraeme case WB_CHIPID_83627THF:
378 1.23 xtraeme printf(": W83627THF\n");
379 1.23 xtraeme break;
380 1.7 bouyer default:
381 1.7 bouyer printf(": unknow winbond chip ID 0x%x\n", j);
382 1.7 bouyer /* handle as a standart lm7x */
383 1.7 bouyer lm_common_match(sc);
384 1.7 bouyer return 1;
385 1.7 bouyer }
386 1.8 bouyer /* common code for the W83782D and W83627HF */
387 1.8 bouyer wb_setup_volt(sc);
388 1.8 bouyer setup_temp(sc, 9, 3);
389 1.8 bouyer setup_fan(sc, 12, 3);
390 1.5 bouyer sc->numsensors = WB_NUM_SENSORS;
391 1.7 bouyer sc->refresh_sensor_data = wb782_refresh_sensor_data;
392 1.8 bouyer sc->sc_sysmon.sme_streinfo = wb782_streinfo;
393 1.8 bouyer return 1;
394 1.8 bouyer }
395 1.5 bouyer
396 1.8 bouyer static void
397 1.8 bouyer wb_setup_volt(sc)
398 1.8 bouyer struct lm_softc *sc;
399 1.8 bouyer {
400 1.5 bouyer sc->sensors[0].units = sc->info[0].units = ENVSYS_SVOLTS_DC;
401 1.18 itojun snprintf(sc->info[0].desc, sizeof(sc->info[0].desc), "VCORE A");
402 1.5 bouyer sc->info[0].rfact = 10000;
403 1.5 bouyer sc->sensors[1].units = sc->info[1].units = ENVSYS_SVOLTS_DC;
404 1.18 itojun snprintf(sc->info[1].desc, sizeof(sc->info[1].desc), "VCORE B");
405 1.5 bouyer sc->info[1].rfact = 10000;
406 1.5 bouyer sc->sensors[2].units = sc->info[2].units = ENVSYS_SVOLTS_DC;
407 1.18 itojun snprintf(sc->info[2].desc, sizeof(sc->info[2].desc), "+3.3V");
408 1.5 bouyer sc->info[2].rfact = 10000;
409 1.5 bouyer sc->sensors[3].units = sc->info[3].units = ENVSYS_SVOLTS_DC;
410 1.18 itojun snprintf(sc->info[3].desc, sizeof(sc->info[3].desc), "+5V");
411 1.5 bouyer sc->info[3].rfact = 16778;
412 1.5 bouyer sc->sensors[4].units = sc->info[4].units = ENVSYS_SVOLTS_DC;
413 1.18 itojun snprintf(sc->info[4].desc, sizeof(sc->info[4].desc), "+12V");
414 1.5 bouyer sc->info[4].rfact = 38000;
415 1.5 bouyer sc->sensors[5].units = sc->info[5].units = ENVSYS_SVOLTS_DC;
416 1.18 itojun snprintf(sc->info[5].desc, sizeof(sc->info[5].desc), "-12V");
417 1.5 bouyer sc->info[5].rfact = 10000;
418 1.5 bouyer sc->sensors[6].units = sc->info[6].units = ENVSYS_SVOLTS_DC;
419 1.18 itojun snprintf(sc->info[6].desc, sizeof(sc->info[6].desc), "-5V");
420 1.5 bouyer sc->info[6].rfact = 10000;
421 1.5 bouyer sc->sensors[7].units = sc->info[7].units = ENVSYS_SVOLTS_DC;
422 1.18 itojun snprintf(sc->info[7].desc, sizeof(sc->info[7].desc), "+5VSB");
423 1.5 bouyer sc->info[7].rfact = 15151;
424 1.5 bouyer sc->sensors[8].units = sc->info[8].units = ENVSYS_SVOLTS_DC;
425 1.18 itojun snprintf(sc->info[8].desc, sizeof(sc->info[8].desc), "VBAT");
426 1.5 bouyer sc->info[8].rfact = 10000;
427 1.8 bouyer }
428 1.8 bouyer
429 1.19 christos int
430 1.19 christos itec_match(sc)
431 1.19 christos struct lm_softc *sc;
432 1.19 christos {
433 1.22 xtraeme int vendor, coreid;
434 1.22 xtraeme
435 1.19 christos /* do the same thing as in lm_probe() */
436 1.19 christos if ((*sc->lm_readreg)(sc, ITEC_RES48) != ITEC_RES48_DEFAULT)
437 1.19 christos return 0;
438 1.19 christos
439 1.19 christos if ((*sc->lm_readreg)(sc, ITEC_RES52) != ITEC_RES52_DEFAULT)
440 1.19 christos return 0;
441 1.19 christos
442 1.22 xtraeme /* We check for the core ID register (0x5B), which is available
443 1.22 xtraeme * only in the 8712F, if that fails, we check the vendor ID
444 1.22 xtraeme * register, available on 8705F and 8712F */
445 1.22 xtraeme
446 1.22 xtraeme coreid = (*sc->lm_readreg)(sc, ITEC_COREID);
447 1.19 christos
448 1.22 xtraeme if (coreid == ITEC_COREID_ITE)
449 1.22 xtraeme printf(": ITE8712F\n");
450 1.22 xtraeme else {
451 1.22 xtraeme vendor = (*sc->lm_readreg)(sc, ITEC_VENDID);
452 1.22 xtraeme if (vendor == ITEC_VENDID_ITE)
453 1.22 xtraeme printf(": ITE8705F\n");
454 1.22 xtraeme else
455 1.22 xtraeme printf(": unknown ITE87%02x compatible\n", vendor);
456 1.22 xtraeme }
457 1.19 christos
458 1.19 christos /*
459 1.19 christos * XXX this is a litle bit lame...
460 1.19 christos * All VIN inputs work exactly the same way, it depends of the
461 1.19 christos * external wiring what voltages they monitor and which correction
462 1.19 christos * factors are needed. We assume a pretty standard setup here
463 1.19 christos */
464 1.19 christos wb_setup_volt(sc);
465 1.19 christos strlcpy(sc->info[0].desc, "CPU", sizeof(sc->info[0].desc));
466 1.19 christos strlcpy(sc->info[1].desc, "AGP", sizeof(sc->info[1].desc));
467 1.19 christos strlcpy(sc->info[6].desc, "+2.5V", sizeof(sc->info[6].desc));
468 1.19 christos sc->info[5].rfact = 51100;
469 1.19 christos sc->info[7].rfact = 16778;
470 1.19 christos
471 1.19 christos setup_temp(sc, 9, 3);
472 1.19 christos setup_fan(sc, 12, 3);
473 1.19 christos sc->numsensors = ITEC_NUM_SENSORS;
474 1.19 christos sc->refresh_sensor_data = itec_refresh_sensor_data;
475 1.19 christos sc->sc_sysmon.sme_streinfo = itec_streinfo;
476 1.19 christos
477 1.19 christos return 1;
478 1.19 christos }
479 1.19 christos
480 1.19 christos
481 1.8 bouyer static void
482 1.8 bouyer setup_temp(sc, start, n)
483 1.8 bouyer struct lm_softc *sc;
484 1.8 bouyer int start, n;
485 1.8 bouyer {
486 1.8 bouyer int i;
487 1.5 bouyer
488 1.8 bouyer for (i = 0; i < n; i++) {
489 1.8 bouyer sc->sensors[start + i].units = ENVSYS_STEMP;
490 1.18 itojun snprintf(sc->info[start + i].desc,
491 1.18 itojun sizeof(sc->info[start + i].desc), "Temp %d", i + 1);
492 1.8 bouyer }
493 1.8 bouyer }
494 1.8 bouyer
495 1.8 bouyer
496 1.8 bouyer static void
497 1.8 bouyer setup_fan(sc, start, n)
498 1.8 bouyer struct lm_softc *sc;
499 1.8 bouyer int start, n;
500 1.8 bouyer {
501 1.8 bouyer int i;
502 1.8 bouyer for (i = 0; i < n; ++i) {
503 1.8 bouyer sc->sensors[start + i].units = ENVSYS_SFANRPM;
504 1.8 bouyer sc->info[start + i].units = ENVSYS_SFANRPM;
505 1.18 itojun snprintf(sc->info[start + i].desc,
506 1.18 itojun sizeof(sc->info[start + i].desc), "Fan %d", i + 1);
507 1.5 bouyer }
508 1.1 groo }
509 1.1 groo
510 1.5 bouyer int
511 1.5 bouyer lm_gtredata(sme, tred)
512 1.5 bouyer struct sysmon_envsys *sme;
513 1.5 bouyer struct envsys_tre_data *tred;
514 1.5 bouyer {
515 1.5 bouyer static const struct timeval onepointfive = { 1, 500000 };
516 1.5 bouyer struct timeval t;
517 1.5 bouyer struct lm_softc *sc = sme->sme_cookie;
518 1.5 bouyer int i, s;
519 1.5 bouyer
520 1.5 bouyer /* read new values at most once every 1.5 seconds */
521 1.5 bouyer timeradd(&sc->lastread, &onepointfive, &t);
522 1.5 bouyer s = splclock();
523 1.5 bouyer i = timercmp(&mono_time, &t, >);
524 1.5 bouyer if (i) {
525 1.5 bouyer sc->lastread.tv_sec = mono_time.tv_sec;
526 1.5 bouyer sc->lastread.tv_usec = mono_time.tv_usec;
527 1.5 bouyer }
528 1.5 bouyer splx(s);
529 1.5 bouyer
530 1.5 bouyer if (i)
531 1.5 bouyer sc->refresh_sensor_data(sc);
532 1.5 bouyer
533 1.5 bouyer *tred = sc->sensors[tred->sensor];
534 1.5 bouyer
535 1.19 christos return 0;
536 1.5 bouyer }
537 1.1 groo
538 1.1 groo int
539 1.7 bouyer generic_streinfo_fan(sc, info, n, binfo)
540 1.7 bouyer struct lm_softc *sc;
541 1.7 bouyer struct envsys_basic_info *info;
542 1.7 bouyer int n;
543 1.7 bouyer struct envsys_basic_info *binfo;
544 1.7 bouyer {
545 1.7 bouyer u_int8_t sdata;
546 1.7 bouyer int divisor;
547 1.7 bouyer
548 1.7 bouyer /* FAN1 and FAN2 can have divisors set, but not FAN3 */
549 1.7 bouyer if ((sc->info[binfo->sensor].units == ENVSYS_SFANRPM)
550 1.14 tron && (n < 2)) {
551 1.7 bouyer if (binfo->rpms == 0) {
552 1.7 bouyer binfo->validflags = 0;
553 1.19 christos return 0;
554 1.7 bouyer }
555 1.7 bouyer
556 1.14 tron /* write back the nominal FAN speed */
557 1.14 tron info->rpms = binfo->rpms;
558 1.14 tron
559 1.7 bouyer /* 153 is the nominal FAN speed value */
560 1.7 bouyer divisor = 1350000 / (binfo->rpms * 153);
561 1.7 bouyer
562 1.7 bouyer /* ...but we need lg(divisor) */
563 1.7 bouyer if (divisor <= 1)
564 1.7 bouyer divisor = 0;
565 1.7 bouyer else if (divisor <= 2)
566 1.7 bouyer divisor = 1;
567 1.7 bouyer else if (divisor <= 4)
568 1.7 bouyer divisor = 2;
569 1.7 bouyer else
570 1.7 bouyer divisor = 3;
571 1.7 bouyer
572 1.7 bouyer /*
573 1.7 bouyer * FAN1 div is in bits <5:4>, FAN2 div is
574 1.7 bouyer * in <7:6>
575 1.7 bouyer */
576 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_VIDFAN);
577 1.14 tron if ( n == 0 ) { /* FAN1 */
578 1.7 bouyer divisor <<= 4;
579 1.7 bouyer sdata = (sdata & 0xCF) | divisor;
580 1.7 bouyer } else { /* FAN2 */
581 1.7 bouyer divisor <<= 6;
582 1.7 bouyer sdata = (sdata & 0x3F) | divisor;
583 1.7 bouyer }
584 1.7 bouyer
585 1.17 ad (*sc->lm_writereg)(sc, LMD_VIDFAN, sdata);
586 1.7 bouyer }
587 1.19 christos return 0;
588 1.7 bouyer
589 1.7 bouyer }
590 1.7 bouyer
591 1.7 bouyer int
592 1.4 thorpej lm_streinfo(sme, binfo)
593 1.5 bouyer struct sysmon_envsys *sme;
594 1.5 bouyer struct envsys_basic_info *binfo;
595 1.1 groo {
596 1.5 bouyer struct lm_softc *sc = sme->sme_cookie;
597 1.5 bouyer
598 1.5 bouyer if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
599 1.5 bouyer sc->info[binfo->sensor].rfact = binfo->rfact;
600 1.5 bouyer else {
601 1.7 bouyer if (sc->info[binfo->sensor].units == ENVSYS_SFANRPM) {
602 1.7 bouyer generic_streinfo_fan(sc, &sc->info[binfo->sensor],
603 1.7 bouyer binfo->sensor - 8, binfo);
604 1.7 bouyer }
605 1.19 christos strlcpy(sc->info[binfo->sensor].desc, binfo->desc,
606 1.7 bouyer sizeof(sc->info[binfo->sensor].desc));
607 1.7 bouyer binfo->validflags = ENVSYS_FVALID;
608 1.7 bouyer }
609 1.19 christos return 0;
610 1.7 bouyer }
611 1.5 bouyer
612 1.7 bouyer int
613 1.7 bouyer wb781_streinfo(sme, binfo)
614 1.7 bouyer struct sysmon_envsys *sme;
615 1.7 bouyer struct envsys_basic_info *binfo;
616 1.7 bouyer {
617 1.7 bouyer struct lm_softc *sc = sme->sme_cookie;
618 1.14 tron int divisor;
619 1.14 tron u_int8_t sdata;
620 1.14 tron int i;
621 1.5 bouyer
622 1.7 bouyer if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
623 1.7 bouyer sc->info[binfo->sensor].rfact = binfo->rfact;
624 1.7 bouyer else {
625 1.7 bouyer if (sc->info[binfo->sensor].units == ENVSYS_SFANRPM) {
626 1.14 tron if (binfo->rpms == 0) {
627 1.14 tron binfo->validflags = 0;
628 1.19 christos return 0;
629 1.14 tron }
630 1.14 tron
631 1.14 tron /* write back the nominal FAN speed */
632 1.14 tron sc->info[binfo->sensor].rpms = binfo->rpms;
633 1.14 tron
634 1.14 tron /* 153 is the nominal FAN speed value */
635 1.14 tron divisor = 1350000 / (binfo->rpms * 153);
636 1.14 tron
637 1.14 tron /* ...but we need lg(divisor) */
638 1.14 tron for (i = 0; i < 7; i++) {
639 1.14 tron if (divisor <= (1 << i))
640 1.14 tron break;
641 1.14 tron }
642 1.14 tron divisor = i;
643 1.14 tron
644 1.14 tron if (binfo->sensor == 10 || binfo->sensor == 11) {
645 1.14 tron /*
646 1.14 tron * FAN1 div is in bits <5:4>, FAN2 div
647 1.14 tron * is in <7:6>
648 1.14 tron */
649 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_VIDFAN);
650 1.14 tron if ( binfo->sensor == 10 ) { /* FAN1 */
651 1.14 tron sdata = (sdata & 0xCF) |
652 1.14 tron ((divisor & 0x3) << 4);
653 1.14 tron } else { /* FAN2 */
654 1.14 tron sdata = (sdata & 0x3F) |
655 1.14 tron ((divisor & 0x3) << 6);
656 1.14 tron }
657 1.17 ad (*sc->lm_writereg)(sc, LMD_VIDFAN, sdata);
658 1.14 tron } else {
659 1.14 tron /* FAN3 is in WB_PIN <7:6> */
660 1.17 ad sdata = (*sc->lm_readreg)(sc, WB_PIN);
661 1.14 tron sdata = (sdata & 0x3F) |
662 1.14 tron ((divisor & 0x3) << 6);
663 1.17 ad (*sc->lm_writereg)(sc, WB_PIN, sdata);
664 1.14 tron }
665 1.7 bouyer }
666 1.19 christos strlcpy(sc->info[binfo->sensor].desc, binfo->desc,
667 1.7 bouyer sizeof(sc->info[binfo->sensor].desc));
668 1.7 bouyer binfo->validflags = ENVSYS_FVALID;
669 1.5 bouyer }
670 1.19 christos return 0;
671 1.5 bouyer }
672 1.5 bouyer
673 1.5 bouyer int
674 1.7 bouyer wb782_streinfo(sme, binfo)
675 1.5 bouyer struct sysmon_envsys *sme;
676 1.5 bouyer struct envsys_basic_info *binfo;
677 1.5 bouyer {
678 1.5 bouyer struct lm_softc *sc = sme->sme_cookie;
679 1.5 bouyer int divisor;
680 1.5 bouyer u_int8_t sdata;
681 1.5 bouyer int i;
682 1.5 bouyer
683 1.5 bouyer if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
684 1.5 bouyer sc->info[binfo->sensor].rfact = binfo->rfact;
685 1.5 bouyer else {
686 1.5 bouyer if (sc->info[binfo->sensor].units == ENVSYS_SFANRPM) {
687 1.4 thorpej if (binfo->rpms == 0) {
688 1.4 thorpej binfo->validflags = 0;
689 1.19 christos return 0;
690 1.1 groo }
691 1.1 groo
692 1.14 tron /* write back the nominal FAN speed */
693 1.14 tron sc->info[binfo->sensor].rpms = binfo->rpms;
694 1.14 tron
695 1.4 thorpej /* 153 is the nominal FAN speed value */
696 1.4 thorpej divisor = 1350000 / (binfo->rpms * 153);
697 1.1 groo
698 1.4 thorpej /* ...but we need lg(divisor) */
699 1.5 bouyer for (i = 0; i < 7; i++) {
700 1.5 bouyer if (divisor <= (1 << i))
701 1.5 bouyer break;
702 1.5 bouyer }
703 1.5 bouyer divisor = i;
704 1.4 thorpej
705 1.5 bouyer if (binfo->sensor == 12 || binfo->sensor == 13) {
706 1.5 bouyer /*
707 1.5 bouyer * FAN1 div is in bits <5:4>, FAN2 div
708 1.5 bouyer * is in <7:6>
709 1.5 bouyer */
710 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_VIDFAN);
711 1.5 bouyer if ( binfo->sensor == 12 ) { /* FAN1 */
712 1.5 bouyer sdata = (sdata & 0xCF) |
713 1.5 bouyer ((divisor & 0x3) << 4);
714 1.5 bouyer } else { /* FAN2 */
715 1.5 bouyer sdata = (sdata & 0x3F) |
716 1.5 bouyer ((divisor & 0x3) << 6);
717 1.5 bouyer }
718 1.17 ad (*sc->lm_writereg)(sc, LMD_VIDFAN, sdata);
719 1.5 bouyer } else {
720 1.5 bouyer /* FAN3 is in WB_PIN <7:6> */
721 1.17 ad sdata = (*sc->lm_readreg)(sc, WB_PIN);
722 1.5 bouyer sdata = (sdata & 0x3F) |
723 1.5 bouyer ((divisor & 0x3) << 6);
724 1.17 ad (*sc->lm_writereg)(sc, WB_PIN, sdata);
725 1.1 groo }
726 1.5 bouyer /* Bit 2 of divisor is in WB_BANK0_FANBAT */
727 1.17 ad (*sc->lm_banksel)(sc, 0);
728 1.17 ad sdata = (*sc->lm_readreg)(sc, WB_BANK0_FANBAT);
729 1.5 bouyer sdata &= ~(0x20 << (binfo->sensor - 12));
730 1.5 bouyer sdata |= (divisor & 0x4) << (binfo->sensor - 9);
731 1.17 ad (*sc->lm_writereg)(sc, WB_BANK0_FANBAT, sdata);
732 1.1 groo }
733 1.1 groo
734 1.19 christos strlcpy(sc->info[binfo->sensor].desc, binfo->desc,
735 1.4 thorpej sizeof(sc->info[binfo->sensor].desc));
736 1.19 christos binfo->validflags = ENVSYS_FVALID;
737 1.19 christos }
738 1.19 christos return 0;
739 1.19 christos }
740 1.19 christos
741 1.19 christos int
742 1.19 christos itec_streinfo(sme, binfo)
743 1.19 christos struct sysmon_envsys *sme;
744 1.19 christos struct envsys_basic_info *binfo;
745 1.19 christos {
746 1.19 christos struct lm_softc *sc = sme->sme_cookie;
747 1.19 christos int divisor;
748 1.19 christos u_int8_t sdata;
749 1.19 christos int i;
750 1.19 christos
751 1.19 christos if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
752 1.19 christos sc->info[binfo->sensor].rfact = binfo->rfact;
753 1.19 christos else {
754 1.19 christos if (sc->info[binfo->sensor].units == ENVSYS_SFANRPM) {
755 1.19 christos if (binfo->rpms == 0) {
756 1.19 christos binfo->validflags = 0;
757 1.19 christos return 0;
758 1.19 christos }
759 1.19 christos
760 1.19 christos /* write back the nominal FAN speed */
761 1.19 christos sc->info[binfo->sensor].rpms = binfo->rpms;
762 1.19 christos
763 1.19 christos /* 153 is the nominal FAN speed value */
764 1.19 christos divisor = 1350000 / (binfo->rpms * 153);
765 1.1 groo
766 1.19 christos /* ...but we need lg(divisor) */
767 1.19 christos for (i = 0; i < 7; i++) {
768 1.19 christos if (divisor <= (1 << i))
769 1.19 christos break;
770 1.19 christos }
771 1.19 christos divisor = i;
772 1.19 christos
773 1.19 christos sdata = (*sc->lm_readreg)(sc, ITEC_FANDIV);
774 1.19 christos /*
775 1.19 christos * FAN1 div is in bits <0:2>, FAN2 is in <3:5>
776 1.19 christos * FAN3 is in <6>, if set divisor is 8, else 2
777 1.19 christos */
778 1.19 christos if ( binfo->sensor == 10 ) { /* FAN1 */
779 1.19 christos sdata = (sdata & 0xf8) | divisor;
780 1.19 christos } else if ( binfo->sensor == 11 ) { /* FAN2 */
781 1.19 christos sdata = (sdata & 0xc7) | divisor << 3;
782 1.19 christos } else { /* FAN3 */
783 1.19 christos if (divisor>2)
784 1.19 christos sdata = sdata & 0xbf;
785 1.19 christos else
786 1.19 christos sdata = sdata | 0x40;
787 1.19 christos }
788 1.19 christos (*sc->lm_writereg)(sc, ITEC_FANDIV, sdata);
789 1.19 christos }
790 1.19 christos strlcpy(sc->info[binfo->sensor].desc, binfo->desc,
791 1.19 christos sizeof(sc->info[binfo->sensor].desc));
792 1.4 thorpej binfo->validflags = ENVSYS_FVALID;
793 1.19 christos }
794 1.19 christos return 0;
795 1.1 groo }
796 1.1 groo
797 1.8 bouyer static void
798 1.7 bouyer generic_stemp(sc, sensor)
799 1.7 bouyer struct lm_softc *sc;
800 1.7 bouyer struct envsys_tre_data *sensor;
801 1.7 bouyer {
802 1.17 ad int sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + 7);
803 1.10 bouyer DPRINTF(("sdata[temp] 0x%x\n", sdata));
804 1.7 bouyer /* temp is given in deg. C, we convert to uK */
805 1.7 bouyer sensor->cur.data_us = sdata * 1000000 + 273150000;
806 1.7 bouyer }
807 1.7 bouyer
808 1.8 bouyer static void
809 1.7 bouyer generic_svolt(sc, sensors, infos)
810 1.7 bouyer struct lm_softc *sc;
811 1.7 bouyer struct envsys_tre_data *sensors;
812 1.7 bouyer struct envsys_basic_info *infos;
813 1.7 bouyer {
814 1.7 bouyer int i, sdata;
815 1.7 bouyer
816 1.7 bouyer for (i = 0; i < 7; i++) {
817 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + i);
818 1.10 bouyer DPRINTF(("sdata[volt%d] 0x%x\n", i, sdata));
819 1.7 bouyer /* voltage returned as (mV >> 4), we convert to uVDC */
820 1.7 bouyer sensors[i].cur.data_s = (sdata << 4);
821 1.7 bouyer /* rfact is (factor * 10^4) */
822 1.7 bouyer sensors[i].cur.data_s *= infos[i].rfact;
823 1.7 bouyer /* division by 10 gets us back to uVDC */
824 1.7 bouyer sensors[i].cur.data_s /= 10;
825 1.7 bouyer
826 1.7 bouyer /* these two are negative voltages */
827 1.7 bouyer if ( (i == 5) || (i == 6) )
828 1.7 bouyer sensors[i].cur.data_s *= -1;
829 1.7 bouyer }
830 1.7 bouyer }
831 1.7 bouyer
832 1.8 bouyer static void
833 1.7 bouyer generic_fanrpm(sc, sensors)
834 1.7 bouyer struct lm_softc *sc;
835 1.7 bouyer struct envsys_tre_data *sensors;
836 1.7 bouyer {
837 1.7 bouyer int i, sdata, divisor;
838 1.7 bouyer for (i = 0; i < 3; i++) {
839 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + 8 + i);
840 1.10 bouyer DPRINTF(("sdata[fan%d] 0x%x\n", i, sdata));
841 1.7 bouyer if (i == 2)
842 1.7 bouyer divisor = 2; /* Fixed divisor for FAN3 */
843 1.7 bouyer else if (i == 1) /* Bits 7 & 6 of VID/FAN */
844 1.17 ad divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 6) & 0x3;
845 1.7 bouyer else
846 1.17 ad divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 4) & 0x3;
847 1.7 bouyer
848 1.7 bouyer if (sdata == 0xff || sdata == 0x00) {
849 1.7 bouyer sensors[i].cur.data_us = 0;
850 1.7 bouyer } else {
851 1.7 bouyer sensors[i].cur.data_us = 1350000 / (sdata << divisor);
852 1.7 bouyer }
853 1.7 bouyer }
854 1.7 bouyer }
855 1.7 bouyer
856 1.1 groo /*
857 1.12 wiz * pre: last read occurred >= 1.5 seconds ago
858 1.1 groo * post: sensors[] current data are the latest from the chip
859 1.1 groo */
860 1.1 groo void
861 1.1 groo lm_refresh_sensor_data(sc)
862 1.1 groo struct lm_softc *sc;
863 1.1 groo {
864 1.7 bouyer /* Refresh our stored data for every sensor */
865 1.7 bouyer generic_stemp(sc, &sc->sensors[7]);
866 1.7 bouyer generic_svolt(sc, &sc->sensors[0], &sc->info[0]);
867 1.7 bouyer generic_fanrpm(sc, &sc->sensors[8]);
868 1.7 bouyer }
869 1.7 bouyer
870 1.8 bouyer static void
871 1.8 bouyer wb_svolt(sc)
872 1.7 bouyer struct lm_softc *sc;
873 1.7 bouyer {
874 1.8 bouyer int i, sdata;
875 1.5 bouyer for (i = 0; i < 9; ++i) {
876 1.5 bouyer if (i < 7) {
877 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + i);
878 1.5 bouyer } else {
879 1.5 bouyer /* from bank5 */
880 1.17 ad (*sc->lm_banksel)(sc, 5);
881 1.17 ad sdata = (*sc->lm_readreg)(sc, (i == 7) ?
882 1.5 bouyer WB_BANK5_5VSB : WB_BANK5_VBAT);
883 1.5 bouyer }
884 1.10 bouyer DPRINTF(("sdata[volt%d] 0x%x\n", i, sdata));
885 1.5 bouyer /* voltage returned as (mV >> 4), we convert to uV */
886 1.5 bouyer sdata = sdata << 4;
887 1.5 bouyer /* special case for negative voltages */
888 1.5 bouyer if (i == 5) {
889 1.5 bouyer /*
890 1.5 bouyer * -12Vdc, assume Winbond recommended values for
891 1.5 bouyer * resistors
892 1.5 bouyer */
893 1.5 bouyer sdata = ((sdata * 1000) - (3600 * 805)) / 195;
894 1.5 bouyer } else if (i == 6) {
895 1.5 bouyer /*
896 1.5 bouyer * -5Vdc, assume Winbond recommended values for
897 1.5 bouyer * resistors
898 1.5 bouyer */
899 1.5 bouyer sdata = ((sdata * 1000) - (3600 * 682)) / 318;
900 1.5 bouyer }
901 1.5 bouyer /* rfact is (factor * 10^4) */
902 1.5 bouyer sc->sensors[i].cur.data_s = sdata * sc->info[i].rfact;
903 1.5 bouyer /* division by 10 gets us back to uVDC */
904 1.5 bouyer sc->sensors[i].cur.data_s /= 10;
905 1.5 bouyer }
906 1.8 bouyer }
907 1.5 bouyer
908 1.8 bouyer static void
909 1.8 bouyer wb_stemp(sc, sensors, n)
910 1.8 bouyer struct lm_softc *sc;
911 1.8 bouyer struct envsys_tre_data *sensors;
912 1.8 bouyer int n;
913 1.8 bouyer {
914 1.8 bouyer int sdata;
915 1.8 bouyer /* temperatures. Given in dC, we convert to uK */
916 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + 7);
917 1.10 bouyer DPRINTF(("sdata[temp0] 0x%x\n", sdata));
918 1.8 bouyer sensors[0].cur.data_us = sdata * 1000000 + 273150000;
919 1.8 bouyer /* from bank1 */
920 1.17 ad if ((*sc->lm_banksel)(sc, 1))
921 1.17 ad sensors[1].validflags &= ~ENVSYS_FCURVALID;
922 1.17 ad else {
923 1.17 ad sdata = (*sc->lm_readreg)(sc, WB_BANK1_T2H) << 1;
924 1.17 ad sdata |= ((*sc->lm_readreg)(sc, WB_BANK1_T2L) & 0x80) >> 7;
925 1.17 ad DPRINTF(("sdata[temp1] 0x%x\n", sdata));
926 1.17 ad sensors[1].cur.data_us = (sdata * 1000000) / 2 + 273150000;
927 1.17 ad }
928 1.8 bouyer if (n < 3)
929 1.8 bouyer return;
930 1.8 bouyer /* from bank2 */
931 1.17 ad if ((*sc->lm_banksel)(sc, 2))
932 1.17 ad sensors[2].validflags &= ~ENVSYS_FCURVALID;
933 1.17 ad else {
934 1.17 ad sdata = (*sc->lm_readreg)(sc, WB_BANK2_T3H) << 1;
935 1.17 ad sdata |= ((*sc->lm_readreg)(sc, WB_BANK2_T3L) & 0x80) >> 7;
936 1.17 ad DPRINTF(("sdata[temp2] 0x%x\n", sdata));
937 1.17 ad sensors[2].cur.data_us = (sdata * 1000000) / 2 + 273150000;
938 1.17 ad }
939 1.8 bouyer }
940 1.8 bouyer
941 1.8 bouyer static void
942 1.14 tron wb781_fanrpm(sc, sensors)
943 1.14 tron struct lm_softc *sc;
944 1.14 tron struct envsys_tre_data *sensors;
945 1.14 tron {
946 1.14 tron int i, divisor, sdata;
947 1.17 ad (*sc->lm_banksel)(sc, 0);
948 1.14 tron for (i = 0; i < 3; i++) {
949 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + i + 8);
950 1.14 tron DPRINTF(("sdata[fan%d] 0x%x\n", i, sdata));
951 1.14 tron if (i == 0)
952 1.17 ad divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 4) & 0x3;
953 1.14 tron else if (i == 1)
954 1.17 ad divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 6) & 0x3;
955 1.14 tron else
956 1.17 ad divisor = ((*sc->lm_readreg)(sc, WB_PIN) >> 6) & 0x3;
957 1.14 tron
958 1.14 tron DPRINTF(("sdata[%d] 0x%x div 0x%x\n", i, sdata, divisor));
959 1.14 tron if (sdata == 0xff || sdata == 0x00) {
960 1.14 tron sensors[i].cur.data_us = 0;
961 1.14 tron } else {
962 1.14 tron sensors[i].cur.data_us = 1350000 /
963 1.14 tron (sdata << divisor);
964 1.14 tron }
965 1.14 tron }
966 1.14 tron }
967 1.14 tron
968 1.14 tron static void
969 1.8 bouyer wb_fanrpm(sc, sensors)
970 1.8 bouyer struct lm_softc *sc;
971 1.8 bouyer struct envsys_tre_data *sensors;
972 1.8 bouyer {
973 1.8 bouyer int i, divisor, sdata;
974 1.17 ad (*sc->lm_banksel)(sc, 0);
975 1.8 bouyer for (i = 0; i < 3; i++) {
976 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + i + 8);
977 1.10 bouyer DPRINTF(("sdata[fan%d] 0x%x\n", i, sdata));
978 1.8 bouyer if (i == 0)
979 1.17 ad divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 4) & 0x3;
980 1.8 bouyer else if (i == 1)
981 1.17 ad divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 6) & 0x3;
982 1.5 bouyer else
983 1.17 ad divisor = ((*sc->lm_readreg)(sc, WB_PIN) >> 6) & 0x3;
984 1.17 ad divisor |= ((*sc->lm_readreg)(sc, WB_BANK0_FANBAT) >> (i + 3)) & 0x4;
985 1.5 bouyer
986 1.5 bouyer DPRINTF(("sdata[%d] 0x%x div 0x%x\n", i, sdata, divisor));
987 1.5 bouyer if (sdata == 0xff || sdata == 0x00) {
988 1.8 bouyer sensors[i].cur.data_us = 0;
989 1.5 bouyer } else {
990 1.8 bouyer sensors[i].cur.data_us = 1350000 /
991 1.5 bouyer (sdata << divisor);
992 1.1 groo }
993 1.1 groo }
994 1.8 bouyer }
995 1.8 bouyer
996 1.8 bouyer void
997 1.8 bouyer wb781_refresh_sensor_data(sc)
998 1.8 bouyer struct lm_softc *sc;
999 1.8 bouyer {
1000 1.8 bouyer /* Refresh our stored data for every sensor */
1001 1.9 bouyer /* we need to reselect bank0 to access common registers */
1002 1.17 ad (*sc->lm_banksel)(sc, 0);
1003 1.8 bouyer generic_svolt(sc, &sc->sensors[0], &sc->info[0]);
1004 1.17 ad (*sc->lm_banksel)(sc, 0);
1005 1.8 bouyer wb_stemp(sc, &sc->sensors[7], 3);
1006 1.17 ad (*sc->lm_banksel)(sc, 0);
1007 1.14 tron wb781_fanrpm(sc, &sc->sensors[10]);
1008 1.8 bouyer }
1009 1.8 bouyer
1010 1.8 bouyer void
1011 1.8 bouyer wb782_refresh_sensor_data(sc)
1012 1.8 bouyer struct lm_softc *sc;
1013 1.8 bouyer {
1014 1.8 bouyer /* Refresh our stored data for every sensor */
1015 1.8 bouyer wb_svolt(sc);
1016 1.8 bouyer wb_stemp(sc, &sc->sensors[9], 3);
1017 1.8 bouyer wb_fanrpm(sc, &sc->sensors[12]);
1018 1.8 bouyer }
1019 1.8 bouyer
1020 1.8 bouyer void
1021 1.8 bouyer wb697_refresh_sensor_data(sc)
1022 1.8 bouyer struct lm_softc *sc;
1023 1.8 bouyer {
1024 1.8 bouyer /* Refresh our stored data for every sensor */
1025 1.8 bouyer wb_svolt(sc);
1026 1.8 bouyer wb_stemp(sc, &sc->sensors[9], 2);
1027 1.8 bouyer wb_fanrpm(sc, &sc->sensors[11]);
1028 1.1 groo }
1029 1.19 christos
1030 1.19 christos static void
1031 1.19 christos itec_svolt(sc, sensors, infos)
1032 1.19 christos struct lm_softc *sc;
1033 1.19 christos struct envsys_tre_data *sensors;
1034 1.19 christos struct envsys_basic_info *infos;
1035 1.19 christos {
1036 1.19 christos int i, sdata;
1037 1.19 christos
1038 1.19 christos for (i = 0; i < 9; i++) {
1039 1.19 christos sdata = (*sc->lm_readreg)(sc, ITEC_VIN0 + i);
1040 1.19 christos DPRINTF(("sdata[volt%d] 0x%x\n", i, sdata));
1041 1.19 christos /* voltage returned as (mV >> 4), we convert to uVDC */
1042 1.19 christos sensors[i].cur.data_s = ( sdata << 4 );
1043 1.19 christos /* rfact is (factor * 10^4) */
1044 1.19 christos
1045 1.19 christos sensors[i].cur.data_s *= infos[i].rfact;
1046 1.19 christos /*
1047 1.19 christos * XXX We assume input 5 is wired the way iTE suggests to
1048 1.19 christos * monitor a negative voltage. I'd prefer using negative rfacts
1049 1.19 christos * for detecting those cases but since rfact is an u_int this
1050 1.19 christos * isn't possible.
1051 1.19 christos */
1052 1.21 perry if (i == 5)
1053 1.21 perry sensors[i].cur.data_s -=
1054 1.19 christos (infos[i].rfact - 10000) * ITEC_VREF;
1055 1.19 christos /* division by 10 gets us back to uVDC */
1056 1.19 christos sensors[i].cur.data_s /= 10;
1057 1.19 christos }
1058 1.19 christos }
1059 1.19 christos
1060 1.19 christos static void
1061 1.19 christos itec_stemp(sc, sensors)
1062 1.19 christos struct lm_softc *sc;
1063 1.19 christos struct envsys_tre_data *sensors;
1064 1.19 christos {
1065 1.19 christos int i, sdata;
1066 1.19 christos
1067 1.19 christos /* temperatures. Given in dC, we convert to uK */
1068 1.19 christos for (i = 0; i < 3; i++) {
1069 1.19 christos sdata = (*sc->lm_readreg)(sc, ITEC_TEMP1 + i);
1070 1.19 christos DPRINTF(("sdata[temp%d] 0x%x\n",i, sdata));
1071 1.19 christos sensors[i].cur.data_us = sdata * 1000000 + 273150000;
1072 1.19 christos }
1073 1.19 christos }
1074 1.19 christos
1075 1.19 christos static void
1076 1.19 christos itec_fanrpm(sc, sensors)
1077 1.19 christos struct lm_softc *sc;
1078 1.19 christos struct envsys_tre_data *sensors;
1079 1.19 christos {
1080 1.19 christos int i, fandiv, divisor, sdata;
1081 1.19 christos (*sc->lm_banksel)(sc, 0);
1082 1.19 christos fandiv = ((*sc->lm_readreg)(sc, ITEC_FANDIV));
1083 1.19 christos
1084 1.19 christos for (i = 0; i < 3; i++) {
1085 1.19 christos sdata = (*sc->lm_readreg)(sc, ITEC_FAN1 + i);
1086 1.19 christos DPRINTF(("sdata[fan%d] 0x%x\n", i, sdata));
1087 1.19 christos switch (i) {
1088 1.19 christos case 0:
1089 1.19 christos divisor = fandiv & 0x7;
1090 1.19 christos break;
1091 1.19 christos case 1:
1092 1.19 christos divisor = (fandiv >> 3) & 0x7;
1093 1.19 christos break;
1094 1.19 christos case 2:
1095 1.19 christos default: /* XXX */
1096 1.19 christos divisor = (fandiv & 0x40) ? 3 : 1;
1097 1.19 christos break;
1098 1.19 christos }
1099 1.19 christos DPRINTF(("sdata[%d] 0x%x div 0x%x\n", i, sdata, divisor));
1100 1.19 christos if (sdata == 0xff || sdata == 0x00) {
1101 1.19 christos sensors[i].cur.data_us = 0;
1102 1.19 christos } else {
1103 1.19 christos sensors[i].cur.data_us = 1350000 /
1104 1.19 christos (sdata << divisor);
1105 1.19 christos }
1106 1.19 christos }
1107 1.19 christos
1108 1.19 christos }
1109 1.19 christos
1110 1.19 christos void
1111 1.19 christos itec_refresh_sensor_data(sc)
1112 1.19 christos struct lm_softc *sc;
1113 1.19 christos {
1114 1.19 christos itec_svolt(sc, &sc->sensors[0], &sc->info[0]);
1115 1.19 christos itec_stemp(sc, &sc->sensors[9]);
1116 1.19 christos itec_fanrpm(sc, &sc->sensors[12]);
1117 1.19 christos }
1118