nslm7x.c revision 1.21 1 1.21 perry /* $NetBSD: nslm7x.c,v 1.21 2005/02/27 00:27:02 perry 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.21 perry __KERNEL_RCSID(0, "$NetBSD: nslm7x.c,v 1.21 2005/02/27 00:27:02 perry 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.2 groo if ((cr == 0x08) || (cr == 0x01))
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.7 bouyer default:
378 1.7 bouyer printf(": unknow winbond chip ID 0x%x\n", j);
379 1.7 bouyer /* handle as a standart lm7x */
380 1.7 bouyer lm_common_match(sc);
381 1.7 bouyer return 1;
382 1.7 bouyer }
383 1.8 bouyer /* common code for the W83782D and W83627HF */
384 1.8 bouyer wb_setup_volt(sc);
385 1.8 bouyer setup_temp(sc, 9, 3);
386 1.8 bouyer setup_fan(sc, 12, 3);
387 1.5 bouyer sc->numsensors = WB_NUM_SENSORS;
388 1.7 bouyer sc->refresh_sensor_data = wb782_refresh_sensor_data;
389 1.8 bouyer sc->sc_sysmon.sme_streinfo = wb782_streinfo;
390 1.8 bouyer return 1;
391 1.8 bouyer }
392 1.5 bouyer
393 1.8 bouyer static void
394 1.8 bouyer wb_setup_volt(sc)
395 1.8 bouyer struct lm_softc *sc;
396 1.8 bouyer {
397 1.5 bouyer sc->sensors[0].units = sc->info[0].units = ENVSYS_SVOLTS_DC;
398 1.18 itojun snprintf(sc->info[0].desc, sizeof(sc->info[0].desc), "VCORE A");
399 1.5 bouyer sc->info[0].rfact = 10000;
400 1.5 bouyer sc->sensors[1].units = sc->info[1].units = ENVSYS_SVOLTS_DC;
401 1.18 itojun snprintf(sc->info[1].desc, sizeof(sc->info[1].desc), "VCORE B");
402 1.5 bouyer sc->info[1].rfact = 10000;
403 1.5 bouyer sc->sensors[2].units = sc->info[2].units = ENVSYS_SVOLTS_DC;
404 1.18 itojun snprintf(sc->info[2].desc, sizeof(sc->info[2].desc), "+3.3V");
405 1.5 bouyer sc->info[2].rfact = 10000;
406 1.5 bouyer sc->sensors[3].units = sc->info[3].units = ENVSYS_SVOLTS_DC;
407 1.18 itojun snprintf(sc->info[3].desc, sizeof(sc->info[3].desc), "+5V");
408 1.5 bouyer sc->info[3].rfact = 16778;
409 1.5 bouyer sc->sensors[4].units = sc->info[4].units = ENVSYS_SVOLTS_DC;
410 1.18 itojun snprintf(sc->info[4].desc, sizeof(sc->info[4].desc), "+12V");
411 1.5 bouyer sc->info[4].rfact = 38000;
412 1.5 bouyer sc->sensors[5].units = sc->info[5].units = ENVSYS_SVOLTS_DC;
413 1.18 itojun snprintf(sc->info[5].desc, sizeof(sc->info[5].desc), "-12V");
414 1.5 bouyer sc->info[5].rfact = 10000;
415 1.5 bouyer sc->sensors[6].units = sc->info[6].units = ENVSYS_SVOLTS_DC;
416 1.18 itojun snprintf(sc->info[6].desc, sizeof(sc->info[6].desc), "-5V");
417 1.5 bouyer sc->info[6].rfact = 10000;
418 1.5 bouyer sc->sensors[7].units = sc->info[7].units = ENVSYS_SVOLTS_DC;
419 1.18 itojun snprintf(sc->info[7].desc, sizeof(sc->info[7].desc), "+5VSB");
420 1.5 bouyer sc->info[7].rfact = 15151;
421 1.5 bouyer sc->sensors[8].units = sc->info[8].units = ENVSYS_SVOLTS_DC;
422 1.18 itojun snprintf(sc->info[8].desc, sizeof(sc->info[8].desc), "VBAT");
423 1.5 bouyer sc->info[8].rfact = 10000;
424 1.8 bouyer }
425 1.8 bouyer
426 1.19 christos int
427 1.19 christos itec_match(sc)
428 1.19 christos struct lm_softc *sc;
429 1.19 christos {
430 1.19 christos int vendor;
431 1.19 christos /* do the same thing as in lm_probe() */
432 1.19 christos if ((*sc->lm_readreg)(sc, ITEC_RES48) != ITEC_RES48_DEFAULT)
433 1.19 christos return 0;
434 1.19 christos
435 1.19 christos if ((*sc->lm_readreg)(sc, ITEC_RES52) != ITEC_RES52_DEFAULT)
436 1.19 christos return 0;
437 1.19 christos
438 1.19 christos vendor=(*sc->lm_readreg)(sc, ITEC_VENDID);
439 1.19 christos
440 1.19 christos if (vendor == ITEC_VENDID_ITE)
441 1.19 christos printf(": iTE IT8705f\n");
442 1.19 christos else
443 1.19 christos printf(": unknown IT8705f compatible, vendorid 0x%02x\n",
444 1.19 christos vendor);
445 1.19 christos
446 1.19 christos /*
447 1.19 christos * XXX this is a litle bit lame...
448 1.19 christos * All VIN inputs work exactly the same way, it depends of the
449 1.19 christos * external wiring what voltages they monitor and which correction
450 1.19 christos * factors are needed. We assume a pretty standard setup here
451 1.19 christos */
452 1.19 christos wb_setup_volt(sc);
453 1.19 christos strlcpy(sc->info[0].desc, "CPU", sizeof(sc->info[0].desc));
454 1.19 christos strlcpy(sc->info[1].desc, "AGP", sizeof(sc->info[1].desc));
455 1.19 christos strlcpy(sc->info[6].desc, "+2.5V", sizeof(sc->info[6].desc));
456 1.19 christos sc->info[5].rfact = 51100;
457 1.19 christos sc->info[7].rfact = 16778;
458 1.19 christos
459 1.19 christos setup_temp(sc, 9, 3);
460 1.19 christos setup_fan(sc, 12, 3);
461 1.19 christos sc->numsensors = ITEC_NUM_SENSORS;
462 1.19 christos sc->refresh_sensor_data = itec_refresh_sensor_data;
463 1.19 christos sc->sc_sysmon.sme_streinfo = itec_streinfo;
464 1.19 christos
465 1.19 christos return 1;
466 1.19 christos }
467 1.19 christos
468 1.19 christos
469 1.8 bouyer static void
470 1.8 bouyer setup_temp(sc, start, n)
471 1.8 bouyer struct lm_softc *sc;
472 1.8 bouyer int start, n;
473 1.8 bouyer {
474 1.8 bouyer int i;
475 1.5 bouyer
476 1.8 bouyer for (i = 0; i < n; i++) {
477 1.8 bouyer sc->sensors[start + i].units = ENVSYS_STEMP;
478 1.18 itojun snprintf(sc->info[start + i].desc,
479 1.18 itojun sizeof(sc->info[start + i].desc), "Temp %d", i + 1);
480 1.8 bouyer }
481 1.8 bouyer }
482 1.8 bouyer
483 1.8 bouyer
484 1.8 bouyer static void
485 1.8 bouyer setup_fan(sc, start, n)
486 1.8 bouyer struct lm_softc *sc;
487 1.8 bouyer int start, n;
488 1.8 bouyer {
489 1.8 bouyer int i;
490 1.8 bouyer for (i = 0; i < n; ++i) {
491 1.8 bouyer sc->sensors[start + i].units = ENVSYS_SFANRPM;
492 1.8 bouyer sc->info[start + i].units = ENVSYS_SFANRPM;
493 1.18 itojun snprintf(sc->info[start + i].desc,
494 1.18 itojun sizeof(sc->info[start + i].desc), "Fan %d", i + 1);
495 1.5 bouyer }
496 1.1 groo }
497 1.1 groo
498 1.5 bouyer int
499 1.5 bouyer lm_gtredata(sme, tred)
500 1.5 bouyer struct sysmon_envsys *sme;
501 1.5 bouyer struct envsys_tre_data *tred;
502 1.5 bouyer {
503 1.5 bouyer static const struct timeval onepointfive = { 1, 500000 };
504 1.5 bouyer struct timeval t;
505 1.5 bouyer struct lm_softc *sc = sme->sme_cookie;
506 1.5 bouyer int i, s;
507 1.5 bouyer
508 1.5 bouyer /* read new values at most once every 1.5 seconds */
509 1.5 bouyer timeradd(&sc->lastread, &onepointfive, &t);
510 1.5 bouyer s = splclock();
511 1.5 bouyer i = timercmp(&mono_time, &t, >);
512 1.5 bouyer if (i) {
513 1.5 bouyer sc->lastread.tv_sec = mono_time.tv_sec;
514 1.5 bouyer sc->lastread.tv_usec = mono_time.tv_usec;
515 1.5 bouyer }
516 1.5 bouyer splx(s);
517 1.5 bouyer
518 1.5 bouyer if (i)
519 1.5 bouyer sc->refresh_sensor_data(sc);
520 1.5 bouyer
521 1.5 bouyer *tred = sc->sensors[tred->sensor];
522 1.5 bouyer
523 1.19 christos return 0;
524 1.5 bouyer }
525 1.1 groo
526 1.1 groo int
527 1.7 bouyer generic_streinfo_fan(sc, info, n, binfo)
528 1.7 bouyer struct lm_softc *sc;
529 1.7 bouyer struct envsys_basic_info *info;
530 1.7 bouyer int n;
531 1.7 bouyer struct envsys_basic_info *binfo;
532 1.7 bouyer {
533 1.7 bouyer u_int8_t sdata;
534 1.7 bouyer int divisor;
535 1.7 bouyer
536 1.7 bouyer /* FAN1 and FAN2 can have divisors set, but not FAN3 */
537 1.7 bouyer if ((sc->info[binfo->sensor].units == ENVSYS_SFANRPM)
538 1.14 tron && (n < 2)) {
539 1.7 bouyer if (binfo->rpms == 0) {
540 1.7 bouyer binfo->validflags = 0;
541 1.19 christos return 0;
542 1.7 bouyer }
543 1.7 bouyer
544 1.14 tron /* write back the nominal FAN speed */
545 1.14 tron info->rpms = binfo->rpms;
546 1.14 tron
547 1.7 bouyer /* 153 is the nominal FAN speed value */
548 1.7 bouyer divisor = 1350000 / (binfo->rpms * 153);
549 1.7 bouyer
550 1.7 bouyer /* ...but we need lg(divisor) */
551 1.7 bouyer if (divisor <= 1)
552 1.7 bouyer divisor = 0;
553 1.7 bouyer else if (divisor <= 2)
554 1.7 bouyer divisor = 1;
555 1.7 bouyer else if (divisor <= 4)
556 1.7 bouyer divisor = 2;
557 1.7 bouyer else
558 1.7 bouyer divisor = 3;
559 1.7 bouyer
560 1.7 bouyer /*
561 1.7 bouyer * FAN1 div is in bits <5:4>, FAN2 div is
562 1.7 bouyer * in <7:6>
563 1.7 bouyer */
564 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_VIDFAN);
565 1.14 tron if ( n == 0 ) { /* FAN1 */
566 1.7 bouyer divisor <<= 4;
567 1.7 bouyer sdata = (sdata & 0xCF) | divisor;
568 1.7 bouyer } else { /* FAN2 */
569 1.7 bouyer divisor <<= 6;
570 1.7 bouyer sdata = (sdata & 0x3F) | divisor;
571 1.7 bouyer }
572 1.7 bouyer
573 1.17 ad (*sc->lm_writereg)(sc, LMD_VIDFAN, sdata);
574 1.7 bouyer }
575 1.19 christos return 0;
576 1.7 bouyer
577 1.7 bouyer }
578 1.7 bouyer
579 1.7 bouyer int
580 1.4 thorpej lm_streinfo(sme, binfo)
581 1.5 bouyer struct sysmon_envsys *sme;
582 1.5 bouyer struct envsys_basic_info *binfo;
583 1.1 groo {
584 1.5 bouyer struct lm_softc *sc = sme->sme_cookie;
585 1.5 bouyer
586 1.5 bouyer if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
587 1.5 bouyer sc->info[binfo->sensor].rfact = binfo->rfact;
588 1.5 bouyer else {
589 1.7 bouyer if (sc->info[binfo->sensor].units == ENVSYS_SFANRPM) {
590 1.7 bouyer generic_streinfo_fan(sc, &sc->info[binfo->sensor],
591 1.7 bouyer binfo->sensor - 8, binfo);
592 1.7 bouyer }
593 1.19 christos strlcpy(sc->info[binfo->sensor].desc, binfo->desc,
594 1.7 bouyer sizeof(sc->info[binfo->sensor].desc));
595 1.7 bouyer binfo->validflags = ENVSYS_FVALID;
596 1.7 bouyer }
597 1.19 christos return 0;
598 1.7 bouyer }
599 1.5 bouyer
600 1.7 bouyer int
601 1.7 bouyer wb781_streinfo(sme, binfo)
602 1.7 bouyer struct sysmon_envsys *sme;
603 1.7 bouyer struct envsys_basic_info *binfo;
604 1.7 bouyer {
605 1.7 bouyer struct lm_softc *sc = sme->sme_cookie;
606 1.14 tron int divisor;
607 1.14 tron u_int8_t sdata;
608 1.14 tron int i;
609 1.5 bouyer
610 1.7 bouyer if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
611 1.7 bouyer sc->info[binfo->sensor].rfact = binfo->rfact;
612 1.7 bouyer else {
613 1.7 bouyer if (sc->info[binfo->sensor].units == ENVSYS_SFANRPM) {
614 1.14 tron if (binfo->rpms == 0) {
615 1.14 tron binfo->validflags = 0;
616 1.19 christos return 0;
617 1.14 tron }
618 1.14 tron
619 1.14 tron /* write back the nominal FAN speed */
620 1.14 tron sc->info[binfo->sensor].rpms = binfo->rpms;
621 1.14 tron
622 1.14 tron /* 153 is the nominal FAN speed value */
623 1.14 tron divisor = 1350000 / (binfo->rpms * 153);
624 1.14 tron
625 1.14 tron /* ...but we need lg(divisor) */
626 1.14 tron for (i = 0; i < 7; i++) {
627 1.14 tron if (divisor <= (1 << i))
628 1.14 tron break;
629 1.14 tron }
630 1.14 tron divisor = i;
631 1.14 tron
632 1.14 tron if (binfo->sensor == 10 || binfo->sensor == 11) {
633 1.14 tron /*
634 1.14 tron * FAN1 div is in bits <5:4>, FAN2 div
635 1.14 tron * is in <7:6>
636 1.14 tron */
637 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_VIDFAN);
638 1.14 tron if ( binfo->sensor == 10 ) { /* FAN1 */
639 1.14 tron sdata = (sdata & 0xCF) |
640 1.14 tron ((divisor & 0x3) << 4);
641 1.14 tron } else { /* FAN2 */
642 1.14 tron sdata = (sdata & 0x3F) |
643 1.14 tron ((divisor & 0x3) << 6);
644 1.14 tron }
645 1.17 ad (*sc->lm_writereg)(sc, LMD_VIDFAN, sdata);
646 1.14 tron } else {
647 1.14 tron /* FAN3 is in WB_PIN <7:6> */
648 1.17 ad sdata = (*sc->lm_readreg)(sc, WB_PIN);
649 1.14 tron sdata = (sdata & 0x3F) |
650 1.14 tron ((divisor & 0x3) << 6);
651 1.17 ad (*sc->lm_writereg)(sc, WB_PIN, sdata);
652 1.14 tron }
653 1.7 bouyer }
654 1.19 christos strlcpy(sc->info[binfo->sensor].desc, binfo->desc,
655 1.7 bouyer sizeof(sc->info[binfo->sensor].desc));
656 1.7 bouyer binfo->validflags = ENVSYS_FVALID;
657 1.5 bouyer }
658 1.19 christos return 0;
659 1.5 bouyer }
660 1.5 bouyer
661 1.5 bouyer int
662 1.7 bouyer wb782_streinfo(sme, binfo)
663 1.5 bouyer struct sysmon_envsys *sme;
664 1.5 bouyer struct envsys_basic_info *binfo;
665 1.5 bouyer {
666 1.5 bouyer struct lm_softc *sc = sme->sme_cookie;
667 1.5 bouyer int divisor;
668 1.5 bouyer u_int8_t sdata;
669 1.5 bouyer int i;
670 1.5 bouyer
671 1.5 bouyer if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
672 1.5 bouyer sc->info[binfo->sensor].rfact = binfo->rfact;
673 1.5 bouyer else {
674 1.5 bouyer if (sc->info[binfo->sensor].units == ENVSYS_SFANRPM) {
675 1.4 thorpej if (binfo->rpms == 0) {
676 1.4 thorpej binfo->validflags = 0;
677 1.19 christos return 0;
678 1.1 groo }
679 1.1 groo
680 1.14 tron /* write back the nominal FAN speed */
681 1.14 tron sc->info[binfo->sensor].rpms = binfo->rpms;
682 1.14 tron
683 1.4 thorpej /* 153 is the nominal FAN speed value */
684 1.4 thorpej divisor = 1350000 / (binfo->rpms * 153);
685 1.1 groo
686 1.4 thorpej /* ...but we need lg(divisor) */
687 1.5 bouyer for (i = 0; i < 7; i++) {
688 1.5 bouyer if (divisor <= (1 << i))
689 1.5 bouyer break;
690 1.5 bouyer }
691 1.5 bouyer divisor = i;
692 1.4 thorpej
693 1.5 bouyer if (binfo->sensor == 12 || binfo->sensor == 13) {
694 1.5 bouyer /*
695 1.5 bouyer * FAN1 div is in bits <5:4>, FAN2 div
696 1.5 bouyer * is in <7:6>
697 1.5 bouyer */
698 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_VIDFAN);
699 1.5 bouyer if ( binfo->sensor == 12 ) { /* FAN1 */
700 1.5 bouyer sdata = (sdata & 0xCF) |
701 1.5 bouyer ((divisor & 0x3) << 4);
702 1.5 bouyer } else { /* FAN2 */
703 1.5 bouyer sdata = (sdata & 0x3F) |
704 1.5 bouyer ((divisor & 0x3) << 6);
705 1.5 bouyer }
706 1.17 ad (*sc->lm_writereg)(sc, LMD_VIDFAN, sdata);
707 1.5 bouyer } else {
708 1.5 bouyer /* FAN3 is in WB_PIN <7:6> */
709 1.17 ad sdata = (*sc->lm_readreg)(sc, WB_PIN);
710 1.5 bouyer sdata = (sdata & 0x3F) |
711 1.5 bouyer ((divisor & 0x3) << 6);
712 1.17 ad (*sc->lm_writereg)(sc, WB_PIN, sdata);
713 1.1 groo }
714 1.5 bouyer /* Bit 2 of divisor is in WB_BANK0_FANBAT */
715 1.17 ad (*sc->lm_banksel)(sc, 0);
716 1.17 ad sdata = (*sc->lm_readreg)(sc, WB_BANK0_FANBAT);
717 1.5 bouyer sdata &= ~(0x20 << (binfo->sensor - 12));
718 1.5 bouyer sdata |= (divisor & 0x4) << (binfo->sensor - 9);
719 1.17 ad (*sc->lm_writereg)(sc, WB_BANK0_FANBAT, sdata);
720 1.1 groo }
721 1.1 groo
722 1.19 christos strlcpy(sc->info[binfo->sensor].desc, binfo->desc,
723 1.4 thorpej sizeof(sc->info[binfo->sensor].desc));
724 1.19 christos binfo->validflags = ENVSYS_FVALID;
725 1.19 christos }
726 1.19 christos return 0;
727 1.19 christos }
728 1.19 christos
729 1.19 christos int
730 1.19 christos itec_streinfo(sme, binfo)
731 1.19 christos struct sysmon_envsys *sme;
732 1.19 christos struct envsys_basic_info *binfo;
733 1.19 christos {
734 1.19 christos struct lm_softc *sc = sme->sme_cookie;
735 1.19 christos int divisor;
736 1.19 christos u_int8_t sdata;
737 1.19 christos int i;
738 1.19 christos
739 1.19 christos if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
740 1.19 christos sc->info[binfo->sensor].rfact = binfo->rfact;
741 1.19 christos else {
742 1.19 christos if (sc->info[binfo->sensor].units == ENVSYS_SFANRPM) {
743 1.19 christos if (binfo->rpms == 0) {
744 1.19 christos binfo->validflags = 0;
745 1.19 christos return 0;
746 1.19 christos }
747 1.19 christos
748 1.19 christos /* write back the nominal FAN speed */
749 1.19 christos sc->info[binfo->sensor].rpms = binfo->rpms;
750 1.19 christos
751 1.19 christos /* 153 is the nominal FAN speed value */
752 1.19 christos divisor = 1350000 / (binfo->rpms * 153);
753 1.1 groo
754 1.19 christos /* ...but we need lg(divisor) */
755 1.19 christos for (i = 0; i < 7; i++) {
756 1.19 christos if (divisor <= (1 << i))
757 1.19 christos break;
758 1.19 christos }
759 1.19 christos divisor = i;
760 1.19 christos
761 1.19 christos sdata = (*sc->lm_readreg)(sc, ITEC_FANDIV);
762 1.19 christos /*
763 1.19 christos * FAN1 div is in bits <0:2>, FAN2 is in <3:5>
764 1.19 christos * FAN3 is in <6>, if set divisor is 8, else 2
765 1.19 christos */
766 1.19 christos if ( binfo->sensor == 10 ) { /* FAN1 */
767 1.19 christos sdata = (sdata & 0xf8) | divisor;
768 1.19 christos } else if ( binfo->sensor == 11 ) { /* FAN2 */
769 1.19 christos sdata = (sdata & 0xc7) | divisor << 3;
770 1.19 christos } else { /* FAN3 */
771 1.19 christos if (divisor>2)
772 1.19 christos sdata = sdata & 0xbf;
773 1.19 christos else
774 1.19 christos sdata = sdata | 0x40;
775 1.19 christos }
776 1.19 christos (*sc->lm_writereg)(sc, ITEC_FANDIV, sdata);
777 1.19 christos }
778 1.19 christos strlcpy(sc->info[binfo->sensor].desc, binfo->desc,
779 1.19 christos sizeof(sc->info[binfo->sensor].desc));
780 1.4 thorpej binfo->validflags = ENVSYS_FVALID;
781 1.19 christos }
782 1.19 christos return 0;
783 1.1 groo }
784 1.1 groo
785 1.8 bouyer static void
786 1.7 bouyer generic_stemp(sc, sensor)
787 1.7 bouyer struct lm_softc *sc;
788 1.7 bouyer struct envsys_tre_data *sensor;
789 1.7 bouyer {
790 1.17 ad int sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + 7);
791 1.10 bouyer DPRINTF(("sdata[temp] 0x%x\n", sdata));
792 1.7 bouyer /* temp is given in deg. C, we convert to uK */
793 1.7 bouyer sensor->cur.data_us = sdata * 1000000 + 273150000;
794 1.7 bouyer }
795 1.7 bouyer
796 1.8 bouyer static void
797 1.7 bouyer generic_svolt(sc, sensors, infos)
798 1.7 bouyer struct lm_softc *sc;
799 1.7 bouyer struct envsys_tre_data *sensors;
800 1.7 bouyer struct envsys_basic_info *infos;
801 1.7 bouyer {
802 1.7 bouyer int i, sdata;
803 1.7 bouyer
804 1.7 bouyer for (i = 0; i < 7; i++) {
805 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + i);
806 1.10 bouyer DPRINTF(("sdata[volt%d] 0x%x\n", i, sdata));
807 1.7 bouyer /* voltage returned as (mV >> 4), we convert to uVDC */
808 1.7 bouyer sensors[i].cur.data_s = (sdata << 4);
809 1.7 bouyer /* rfact is (factor * 10^4) */
810 1.7 bouyer sensors[i].cur.data_s *= infos[i].rfact;
811 1.7 bouyer /* division by 10 gets us back to uVDC */
812 1.7 bouyer sensors[i].cur.data_s /= 10;
813 1.7 bouyer
814 1.7 bouyer /* these two are negative voltages */
815 1.7 bouyer if ( (i == 5) || (i == 6) )
816 1.7 bouyer sensors[i].cur.data_s *= -1;
817 1.7 bouyer }
818 1.7 bouyer }
819 1.7 bouyer
820 1.8 bouyer static void
821 1.7 bouyer generic_fanrpm(sc, sensors)
822 1.7 bouyer struct lm_softc *sc;
823 1.7 bouyer struct envsys_tre_data *sensors;
824 1.7 bouyer {
825 1.7 bouyer int i, sdata, divisor;
826 1.7 bouyer for (i = 0; i < 3; i++) {
827 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + 8 + i);
828 1.10 bouyer DPRINTF(("sdata[fan%d] 0x%x\n", i, sdata));
829 1.7 bouyer if (i == 2)
830 1.7 bouyer divisor = 2; /* Fixed divisor for FAN3 */
831 1.7 bouyer else if (i == 1) /* Bits 7 & 6 of VID/FAN */
832 1.17 ad divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 6) & 0x3;
833 1.7 bouyer else
834 1.17 ad divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 4) & 0x3;
835 1.7 bouyer
836 1.7 bouyer if (sdata == 0xff || sdata == 0x00) {
837 1.7 bouyer sensors[i].cur.data_us = 0;
838 1.7 bouyer } else {
839 1.7 bouyer sensors[i].cur.data_us = 1350000 / (sdata << divisor);
840 1.7 bouyer }
841 1.7 bouyer }
842 1.7 bouyer }
843 1.7 bouyer
844 1.1 groo /*
845 1.12 wiz * pre: last read occurred >= 1.5 seconds ago
846 1.1 groo * post: sensors[] current data are the latest from the chip
847 1.1 groo */
848 1.1 groo void
849 1.1 groo lm_refresh_sensor_data(sc)
850 1.1 groo struct lm_softc *sc;
851 1.1 groo {
852 1.7 bouyer /* Refresh our stored data for every sensor */
853 1.7 bouyer generic_stemp(sc, &sc->sensors[7]);
854 1.7 bouyer generic_svolt(sc, &sc->sensors[0], &sc->info[0]);
855 1.7 bouyer generic_fanrpm(sc, &sc->sensors[8]);
856 1.7 bouyer }
857 1.7 bouyer
858 1.8 bouyer static void
859 1.8 bouyer wb_svolt(sc)
860 1.7 bouyer struct lm_softc *sc;
861 1.7 bouyer {
862 1.8 bouyer int i, sdata;
863 1.5 bouyer for (i = 0; i < 9; ++i) {
864 1.5 bouyer if (i < 7) {
865 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + i);
866 1.5 bouyer } else {
867 1.5 bouyer /* from bank5 */
868 1.17 ad (*sc->lm_banksel)(sc, 5);
869 1.17 ad sdata = (*sc->lm_readreg)(sc, (i == 7) ?
870 1.5 bouyer WB_BANK5_5VSB : WB_BANK5_VBAT);
871 1.5 bouyer }
872 1.10 bouyer DPRINTF(("sdata[volt%d] 0x%x\n", i, sdata));
873 1.5 bouyer /* voltage returned as (mV >> 4), we convert to uV */
874 1.5 bouyer sdata = sdata << 4;
875 1.5 bouyer /* special case for negative voltages */
876 1.5 bouyer if (i == 5) {
877 1.5 bouyer /*
878 1.5 bouyer * -12Vdc, assume Winbond recommended values for
879 1.5 bouyer * resistors
880 1.5 bouyer */
881 1.5 bouyer sdata = ((sdata * 1000) - (3600 * 805)) / 195;
882 1.5 bouyer } else if (i == 6) {
883 1.5 bouyer /*
884 1.5 bouyer * -5Vdc, assume Winbond recommended values for
885 1.5 bouyer * resistors
886 1.5 bouyer */
887 1.5 bouyer sdata = ((sdata * 1000) - (3600 * 682)) / 318;
888 1.5 bouyer }
889 1.5 bouyer /* rfact is (factor * 10^4) */
890 1.5 bouyer sc->sensors[i].cur.data_s = sdata * sc->info[i].rfact;
891 1.5 bouyer /* division by 10 gets us back to uVDC */
892 1.5 bouyer sc->sensors[i].cur.data_s /= 10;
893 1.5 bouyer }
894 1.8 bouyer }
895 1.5 bouyer
896 1.8 bouyer static void
897 1.8 bouyer wb_stemp(sc, sensors, n)
898 1.8 bouyer struct lm_softc *sc;
899 1.8 bouyer struct envsys_tre_data *sensors;
900 1.8 bouyer int n;
901 1.8 bouyer {
902 1.8 bouyer int sdata;
903 1.8 bouyer /* temperatures. Given in dC, we convert to uK */
904 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + 7);
905 1.10 bouyer DPRINTF(("sdata[temp0] 0x%x\n", sdata));
906 1.8 bouyer sensors[0].cur.data_us = sdata * 1000000 + 273150000;
907 1.8 bouyer /* from bank1 */
908 1.17 ad if ((*sc->lm_banksel)(sc, 1))
909 1.17 ad sensors[1].validflags &= ~ENVSYS_FCURVALID;
910 1.17 ad else {
911 1.17 ad sdata = (*sc->lm_readreg)(sc, WB_BANK1_T2H) << 1;
912 1.17 ad sdata |= ((*sc->lm_readreg)(sc, WB_BANK1_T2L) & 0x80) >> 7;
913 1.17 ad DPRINTF(("sdata[temp1] 0x%x\n", sdata));
914 1.17 ad sensors[1].cur.data_us = (sdata * 1000000) / 2 + 273150000;
915 1.17 ad }
916 1.8 bouyer if (n < 3)
917 1.8 bouyer return;
918 1.8 bouyer /* from bank2 */
919 1.17 ad if ((*sc->lm_banksel)(sc, 2))
920 1.17 ad sensors[2].validflags &= ~ENVSYS_FCURVALID;
921 1.17 ad else {
922 1.17 ad sdata = (*sc->lm_readreg)(sc, WB_BANK2_T3H) << 1;
923 1.17 ad sdata |= ((*sc->lm_readreg)(sc, WB_BANK2_T3L) & 0x80) >> 7;
924 1.17 ad DPRINTF(("sdata[temp2] 0x%x\n", sdata));
925 1.17 ad sensors[2].cur.data_us = (sdata * 1000000) / 2 + 273150000;
926 1.17 ad }
927 1.8 bouyer }
928 1.8 bouyer
929 1.8 bouyer static void
930 1.14 tron wb781_fanrpm(sc, sensors)
931 1.14 tron struct lm_softc *sc;
932 1.14 tron struct envsys_tre_data *sensors;
933 1.14 tron {
934 1.14 tron int i, divisor, sdata;
935 1.17 ad (*sc->lm_banksel)(sc, 0);
936 1.14 tron for (i = 0; i < 3; i++) {
937 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + i + 8);
938 1.14 tron DPRINTF(("sdata[fan%d] 0x%x\n", i, sdata));
939 1.14 tron if (i == 0)
940 1.17 ad divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 4) & 0x3;
941 1.14 tron else if (i == 1)
942 1.17 ad divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 6) & 0x3;
943 1.14 tron else
944 1.17 ad divisor = ((*sc->lm_readreg)(sc, WB_PIN) >> 6) & 0x3;
945 1.14 tron
946 1.14 tron DPRINTF(("sdata[%d] 0x%x div 0x%x\n", i, sdata, divisor));
947 1.14 tron if (sdata == 0xff || sdata == 0x00) {
948 1.14 tron sensors[i].cur.data_us = 0;
949 1.14 tron } else {
950 1.14 tron sensors[i].cur.data_us = 1350000 /
951 1.14 tron (sdata << divisor);
952 1.14 tron }
953 1.14 tron }
954 1.14 tron }
955 1.14 tron
956 1.14 tron static void
957 1.8 bouyer wb_fanrpm(sc, sensors)
958 1.8 bouyer struct lm_softc *sc;
959 1.8 bouyer struct envsys_tre_data *sensors;
960 1.8 bouyer {
961 1.8 bouyer int i, divisor, sdata;
962 1.17 ad (*sc->lm_banksel)(sc, 0);
963 1.8 bouyer for (i = 0; i < 3; i++) {
964 1.17 ad sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + i + 8);
965 1.10 bouyer DPRINTF(("sdata[fan%d] 0x%x\n", i, sdata));
966 1.8 bouyer if (i == 0)
967 1.17 ad divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 4) & 0x3;
968 1.8 bouyer else if (i == 1)
969 1.17 ad divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 6) & 0x3;
970 1.5 bouyer else
971 1.17 ad divisor = ((*sc->lm_readreg)(sc, WB_PIN) >> 6) & 0x3;
972 1.17 ad divisor |= ((*sc->lm_readreg)(sc, WB_BANK0_FANBAT) >> (i + 3)) & 0x4;
973 1.5 bouyer
974 1.5 bouyer DPRINTF(("sdata[%d] 0x%x div 0x%x\n", i, sdata, divisor));
975 1.5 bouyer if (sdata == 0xff || sdata == 0x00) {
976 1.8 bouyer sensors[i].cur.data_us = 0;
977 1.5 bouyer } else {
978 1.8 bouyer sensors[i].cur.data_us = 1350000 /
979 1.5 bouyer (sdata << divisor);
980 1.1 groo }
981 1.1 groo }
982 1.8 bouyer }
983 1.8 bouyer
984 1.8 bouyer void
985 1.8 bouyer wb781_refresh_sensor_data(sc)
986 1.8 bouyer struct lm_softc *sc;
987 1.8 bouyer {
988 1.8 bouyer /* Refresh our stored data for every sensor */
989 1.9 bouyer /* we need to reselect bank0 to access common registers */
990 1.17 ad (*sc->lm_banksel)(sc, 0);
991 1.8 bouyer generic_svolt(sc, &sc->sensors[0], &sc->info[0]);
992 1.17 ad (*sc->lm_banksel)(sc, 0);
993 1.8 bouyer wb_stemp(sc, &sc->sensors[7], 3);
994 1.17 ad (*sc->lm_banksel)(sc, 0);
995 1.14 tron wb781_fanrpm(sc, &sc->sensors[10]);
996 1.8 bouyer }
997 1.8 bouyer
998 1.8 bouyer void
999 1.8 bouyer wb782_refresh_sensor_data(sc)
1000 1.8 bouyer struct lm_softc *sc;
1001 1.8 bouyer {
1002 1.8 bouyer /* Refresh our stored data for every sensor */
1003 1.8 bouyer wb_svolt(sc);
1004 1.8 bouyer wb_stemp(sc, &sc->sensors[9], 3);
1005 1.8 bouyer wb_fanrpm(sc, &sc->sensors[12]);
1006 1.8 bouyer }
1007 1.8 bouyer
1008 1.8 bouyer void
1009 1.8 bouyer wb697_refresh_sensor_data(sc)
1010 1.8 bouyer struct lm_softc *sc;
1011 1.8 bouyer {
1012 1.8 bouyer /* Refresh our stored data for every sensor */
1013 1.8 bouyer wb_svolt(sc);
1014 1.8 bouyer wb_stemp(sc, &sc->sensors[9], 2);
1015 1.8 bouyer wb_fanrpm(sc, &sc->sensors[11]);
1016 1.1 groo }
1017 1.19 christos
1018 1.19 christos static void
1019 1.19 christos itec_svolt(sc, sensors, infos)
1020 1.19 christos struct lm_softc *sc;
1021 1.19 christos struct envsys_tre_data *sensors;
1022 1.19 christos struct envsys_basic_info *infos;
1023 1.19 christos {
1024 1.19 christos int i, sdata;
1025 1.19 christos
1026 1.19 christos for (i = 0; i < 9; i++) {
1027 1.19 christos sdata = (*sc->lm_readreg)(sc, ITEC_VIN0 + i);
1028 1.19 christos DPRINTF(("sdata[volt%d] 0x%x\n", i, sdata));
1029 1.19 christos /* voltage returned as (mV >> 4), we convert to uVDC */
1030 1.19 christos sensors[i].cur.data_s = ( sdata << 4 );
1031 1.19 christos /* rfact is (factor * 10^4) */
1032 1.19 christos
1033 1.19 christos sensors[i].cur.data_s *= infos[i].rfact;
1034 1.19 christos /*
1035 1.19 christos * XXX We assume input 5 is wired the way iTE suggests to
1036 1.19 christos * monitor a negative voltage. I'd prefer using negative rfacts
1037 1.19 christos * for detecting those cases but since rfact is an u_int this
1038 1.19 christos * isn't possible.
1039 1.19 christos */
1040 1.21 perry if (i == 5)
1041 1.21 perry sensors[i].cur.data_s -=
1042 1.19 christos (infos[i].rfact - 10000) * ITEC_VREF;
1043 1.19 christos /* division by 10 gets us back to uVDC */
1044 1.19 christos sensors[i].cur.data_s /= 10;
1045 1.19 christos }
1046 1.19 christos }
1047 1.19 christos
1048 1.19 christos static void
1049 1.19 christos itec_stemp(sc, sensors)
1050 1.19 christos struct lm_softc *sc;
1051 1.19 christos struct envsys_tre_data *sensors;
1052 1.19 christos {
1053 1.19 christos int i, sdata;
1054 1.19 christos
1055 1.19 christos /* temperatures. Given in dC, we convert to uK */
1056 1.19 christos for (i = 0; i < 3; i++) {
1057 1.19 christos sdata = (*sc->lm_readreg)(sc, ITEC_TEMP1 + i);
1058 1.19 christos DPRINTF(("sdata[temp%d] 0x%x\n",i, sdata));
1059 1.19 christos sensors[i].cur.data_us = sdata * 1000000 + 273150000;
1060 1.19 christos }
1061 1.19 christos }
1062 1.19 christos
1063 1.19 christos static void
1064 1.19 christos itec_fanrpm(sc, sensors)
1065 1.19 christos struct lm_softc *sc;
1066 1.19 christos struct envsys_tre_data *sensors;
1067 1.19 christos {
1068 1.19 christos int i, fandiv, divisor, sdata;
1069 1.19 christos (*sc->lm_banksel)(sc, 0);
1070 1.19 christos fandiv = ((*sc->lm_readreg)(sc, ITEC_FANDIV));
1071 1.19 christos
1072 1.19 christos for (i = 0; i < 3; i++) {
1073 1.19 christos sdata = (*sc->lm_readreg)(sc, ITEC_FAN1 + i);
1074 1.19 christos DPRINTF(("sdata[fan%d] 0x%x\n", i, sdata));
1075 1.19 christos switch (i) {
1076 1.19 christos case 0:
1077 1.19 christos divisor = fandiv & 0x7;
1078 1.19 christos break;
1079 1.19 christos case 1:
1080 1.19 christos divisor = (fandiv >> 3) & 0x7;
1081 1.19 christos break;
1082 1.19 christos case 2:
1083 1.19 christos default: /* XXX */
1084 1.19 christos divisor = (fandiv & 0x40) ? 3 : 1;
1085 1.19 christos break;
1086 1.19 christos }
1087 1.19 christos DPRINTF(("sdata[%d] 0x%x div 0x%x\n", i, sdata, divisor));
1088 1.19 christos if (sdata == 0xff || sdata == 0x00) {
1089 1.19 christos sensors[i].cur.data_us = 0;
1090 1.19 christos } else {
1091 1.19 christos sensors[i].cur.data_us = 1350000 /
1092 1.19 christos (sdata << divisor);
1093 1.19 christos }
1094 1.19 christos }
1095 1.19 christos
1096 1.19 christos }
1097 1.19 christos
1098 1.19 christos void
1099 1.19 christos itec_refresh_sensor_data(sc)
1100 1.19 christos struct lm_softc *sc;
1101 1.19 christos {
1102 1.19 christos itec_svolt(sc, &sc->sensors[0], &sc->info[0]);
1103 1.19 christos itec_stemp(sc, &sc->sensors[9]);
1104 1.19 christos itec_fanrpm(sc, &sc->sensors[12]);
1105 1.19 christos }
1106