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