nslm7x.c revision 1.6 1 /* $NetBSD: nslm7x.c,v 1.6 2000/07/30 17:22:26 bouyer Exp $ */
2
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Bill Squier.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/proc.h>
43 #include <sys/device.h>
44 #include <sys/malloc.h>
45 #include <sys/errno.h>
46 #include <sys/queue.h>
47 #include <sys/lock.h>
48 #include <sys/ioctl.h>
49 #include <sys/conf.h>
50 #include <sys/time.h>
51
52 #include <machine/bus.h>
53
54 #include <dev/isa/isareg.h>
55 #include <dev/isa/isavar.h>
56
57 #include <dev/sysmon/sysmonvar.h>
58
59 #include <dev/ic/nslm7xvar.h>
60
61 #include <machine/intr.h>
62 #include <machine/bus.h>
63
64 #if defined(LMDEBUG)
65 #define DPRINTF(x) do { printf x; } while (0)
66 #else
67 #define DPRINTF(x)
68 #endif
69
70 const struct envsys_range lm_ranges[] = { /* sc->sensors sub-intervals */
71 /* for each unit type */
72 { 7, 7, ENVSYS_STEMP },
73 { 8, 10, ENVSYS_SFANRPM },
74 { 1, 0, ENVSYS_SVOLTS_AC }, /* None */
75 { 0, 6, ENVSYS_SVOLTS_DC },
76 { 1, 0, ENVSYS_SOHMS }, /* None */
77 { 1, 0, ENVSYS_SWATTS }, /* None */
78 { 1, 0, ENVSYS_SAMPS } /* None */
79 };
80
81
82 u_int8_t lm_readreg __P((struct lm_softc *, int));
83 void lm_writereg __P((struct lm_softc *, int, int));
84
85 int lm_match __P((struct lm_softc *));
86 void lm_refresh_sensor_data __P((struct lm_softc *));
87
88 int wb_match __P((struct lm_softc *));
89 void wb_refresh_sensor_data __P((struct lm_softc *));
90
91 int def_match __P((struct lm_softc *));
92 void lm_common_match __P((struct lm_softc *));
93
94 int lm_gtredata __P((struct sysmon_envsys *, struct envsys_tre_data *));
95 int lm_streinfo __P((struct sysmon_envsys *, struct envsys_basic_info *));
96 int wb_streinfo __P((struct sysmon_envsys *, struct envsys_basic_info *));
97
98 struct lm_chip {
99 int (*chip_match) __P((struct lm_softc *));
100 };
101
102 struct lm_chip lm_chips[] = {
103 { wb_match},
104 { lm_match},
105 { def_match} /* Must be last */
106 };
107
108
109 u_int8_t
110 lm_readreg(sc, reg)
111 struct lm_softc *sc;
112 int reg;
113 {
114 bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
115 return (bus_space_read_1(sc->lm_iot, sc->lm_ioh, LMC_DATA));
116 }
117
118 void
119 lm_writereg(sc, reg, val)
120 struct lm_softc *sc;
121 int reg;
122 int val;
123 {
124 bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
125 bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_DATA, val);
126 }
127
128
129 /*
130 * bus independent probe
131 */
132 int
133 lm_probe(iot, ioh)
134 bus_space_tag_t iot;
135 bus_space_handle_t ioh;
136 {
137 u_int8_t cr;
138 int rv;
139
140 /* Check for some power-on defaults */
141 bus_space_write_1(iot, ioh, LMC_ADDR, LMD_CONFIG);
142
143 /* Perform LM78 reset */
144 bus_space_write_1(iot, ioh, LMC_DATA, 0x80);
145
146 /* XXX - Why do I have to reselect the register? */
147 bus_space_write_1(iot, ioh, LMC_ADDR, LMD_CONFIG);
148 cr = bus_space_read_1(iot, ioh, LMC_DATA);
149
150 /* XXX - spec says *only* 0x08! */
151 if ((cr == 0x08) || (cr == 0x01))
152 rv = 1;
153 else
154 rv = 0;
155
156 DPRINTF(("lm: rv = %d, cr = %x\n", rv, cr));
157
158 return (rv);
159 }
160
161
162 /*
163 * pre: lmsc contains valid busspace tag and handle
164 */
165 void
166 lm_attach(lmsc)
167 struct lm_softc *lmsc;
168 {
169 int i;
170
171 for (i = 0; i < sizeof(lm_chips) / sizeof(lm_chips[0]); i++)
172 if (lm_chips[i].chip_match(lmsc))
173 break;
174
175 /* Start the monitoring loop */
176 lm_writereg(lmsc, LMD_CONFIG, 0x01);
177
178 /* Indicate we have never read the registers */
179 timerclear(&lmsc->lastread);
180
181 /* Initialize sensors */
182 for (i = 0; i < lmsc->numsensors; ++i) {
183 lmsc->sensors[i].sensor = lmsc->info[i].sensor = i;
184 lmsc->sensors[i].validflags = (ENVSYS_FVALID|ENVSYS_FCURVALID);
185 lmsc->info[i].validflags = ENVSYS_FVALID;
186 lmsc->sensors[i].warnflags = ENVSYS_WARN_OK;
187 }
188 /*
189 * Hook into the System Monitor.
190 */
191 lmsc->sc_sysmon.sme_ranges = lm_ranges;
192 lmsc->sc_sysmon.sme_sensor_info = lmsc->info;
193 lmsc->sc_sysmon.sme_sensor_data = lmsc->sensors;
194 lmsc->sc_sysmon.sme_cookie = lmsc;
195
196 lmsc->sc_sysmon.sme_gtredata = lm_gtredata;
197 /* sme_streinfo set in chip-specific attach */
198
199 lmsc->sc_sysmon.sme_nsensors = lmsc->numsensors;
200 lmsc->sc_sysmon.sme_envsys_version = 1000;
201
202 if (sysmon_envsys_register(&lmsc->sc_sysmon))
203 printf("%s: unable to register with sysmon\n",
204 lmsc->sc_dev.dv_xname);
205 }
206
207 int
208 lm_match(sc)
209 struct lm_softc *sc;
210 {
211 int i;
212
213 /* See if we have an LM78 or LM79 */
214 i = lm_readreg(sc, LMD_CHIPID) & LM_ID_MASK;
215 switch(i) {
216 case LM_ID_LM78:
217 printf(": LM78\n");
218 break;
219 case LM_ID_LM78J:
220 printf(": LM78J\n");
221 break;
222 case LM_ID_LM79:
223 printf(": LM79\n");
224 break;
225 default:
226 return 0;
227 }
228 lm_common_match(sc);
229 return 1;
230 }
231
232 int
233 def_match(sc)
234 struct lm_softc *sc;
235 {
236 int i;
237
238 i = lm_readreg(sc, LMD_CHIPID) & LM_ID_MASK;
239 printf(": Unknow chip (ID %d)\n", i);
240 lm_common_match(sc);
241 return 1;
242 }
243
244 void
245 lm_common_match(sc)
246 struct lm_softc *sc;
247 {
248 int i;
249 sc->numsensors = LM_NUM_SENSORS;
250 sc->refresh_sensor_data = lm_refresh_sensor_data;
251
252 for (i = 0; i < 7; ++i) {
253 sc->sensors[i].units = sc->info[i].units =
254 ENVSYS_SVOLTS_DC;
255 sprintf(sc->info[i].desc, "IN %d", i);
256 }
257
258 /* default correction factors for resistors on higher voltage inputs */
259 sc->info[0].rfact = sc->info[1].rfact =
260 sc->info[2].rfact = 10000;
261 sc->info[3].rfact = (int)(( 90.9 / 60.4) * 10000);
262 sc->info[4].rfact = (int)(( 38.0 / 10.0) * 10000);
263 sc->info[5].rfact = (int)((210.0 / 60.4) * 10000);
264 sc->info[6].rfact = (int)(( 90.9 / 60.4) * 10000);
265
266 sc->sensors[7].units = ENVSYS_STEMP;
267 strcpy(sc->info[7].desc, "Temp");
268
269 for (i = 8; i < 11; ++i) {
270 sc->sensors[i].units = sc->info[i].units = ENVSYS_SFANRPM;
271 sprintf(sc->info[i].desc, "Fan %d", i - 7);
272 }
273 sc->sc_sysmon.sme_streinfo = lm_streinfo;
274 }
275
276 int
277 wb_match(sc)
278 struct lm_softc *sc;
279 {
280 int i, j;
281
282 /* See if we have a winbond */
283 i = lm_readreg(sc, LMD_CHIPID) & LM_ID_MASK;
284 lm_writereg(sc, WB_BANKSEL, WB_BANKSEL_HBAC);
285 j = lm_readreg(sc, WB_VENDID) << 8;
286 lm_writereg(sc, WB_BANKSEL, 0);
287 j |= lm_readreg(sc, WB_VENDID);
288 DPRINTF(("winbond vend id %d\n", j));
289 if (j != WB_VENDID_WINBOND)
290 return 0;
291 printf(": W83627HF (device ID %d)\n", i);
292 sc->numsensors = WB_NUM_SENSORS;
293 sc->refresh_sensor_data = wb_refresh_sensor_data;
294
295 sc->sensors[0].units = sc->info[0].units = ENVSYS_SVOLTS_DC;
296 sprintf(sc->info[0].desc, "VCORE A");
297 sc->info[0].rfact = 10000;
298 sc->sensors[1].units = sc->info[1].units = ENVSYS_SVOLTS_DC;
299 sprintf(sc->info[1].desc, "VCORE B");
300 sc->info[1].rfact = 10000;
301 sc->sensors[2].units = sc->info[2].units = ENVSYS_SVOLTS_DC;
302 sprintf(sc->info[2].desc, "+3.3V");
303 sc->info[2].rfact = 10000;
304 sc->sensors[3].units = sc->info[3].units = ENVSYS_SVOLTS_DC;
305 sprintf(sc->info[3].desc, "+5V");
306 sc->info[3].rfact = 16778;
307 sc->sensors[4].units = sc->info[4].units = ENVSYS_SVOLTS_DC;
308 sprintf(sc->info[4].desc, "+12V");
309 sc->info[4].rfact = 38000;
310 sc->sensors[5].units = sc->info[5].units = ENVSYS_SVOLTS_DC;
311 sprintf(sc->info[5].desc, "-12V");
312 sc->info[5].rfact = 10000;
313 sc->sensors[6].units = sc->info[6].units = ENVSYS_SVOLTS_DC;
314 sprintf(sc->info[6].desc, "-5V");
315 sc->info[6].rfact = 10000;
316 sc->sensors[7].units = sc->info[7].units = ENVSYS_SVOLTS_DC;
317 sprintf(sc->info[7].desc, "+5VSB");
318 sc->info[7].rfact = 15151;
319 sc->sensors[8].units = sc->info[8].units = ENVSYS_SVOLTS_DC;
320 sprintf(sc->info[8].desc, "VBAT");
321 sc->info[8].rfact = 10000;
322
323 sc->sensors[9].units = ENVSYS_STEMP;
324 strcpy(sc->info[9].desc, "Temp 1");
325 sc->sensors[10].units = ENVSYS_STEMP;
326 strcpy(sc->info[10].desc, "Temp 2");
327 sc->sensors[11].units = ENVSYS_STEMP;
328 strcpy(sc->info[11].desc, "Temp 3");
329
330 for (i = 12; i < 15; ++i) {
331 sc->sensors[i].units = sc->info[i].units = ENVSYS_SFANRPM;
332 sprintf(sc->info[i].desc, "Fan %d", i - 11);
333 }
334 sc->sc_sysmon.sme_streinfo = wb_streinfo;
335 return 1;
336 }
337
338 int
339 lm_gtredata(sme, tred)
340 struct sysmon_envsys *sme;
341 struct envsys_tre_data *tred;
342 {
343 static const struct timeval onepointfive = { 1, 500000 };
344 struct timeval t;
345 struct lm_softc *sc = sme->sme_cookie;
346 int i, s;
347
348 /* read new values at most once every 1.5 seconds */
349 timeradd(&sc->lastread, &onepointfive, &t);
350 s = splclock();
351 i = timercmp(&mono_time, &t, >);
352 if (i) {
353 sc->lastread.tv_sec = mono_time.tv_sec;
354 sc->lastread.tv_usec = mono_time.tv_usec;
355 }
356 splx(s);
357
358 if (i)
359 sc->refresh_sensor_data(sc);
360
361 *tred = sc->sensors[tred->sensor];
362
363 return (0);
364 }
365
366 int
367 lm_streinfo(sme, binfo)
368 struct sysmon_envsys *sme;
369 struct envsys_basic_info *binfo;
370 {
371 struct lm_softc *sc = sme->sme_cookie;
372 int divisor;
373 u_int8_t sdata;
374
375 if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
376 sc->info[binfo->sensor].rfact = binfo->rfact;
377 else {
378 /* FAN1 and FAN2 can have divisors set, but not FAN3 */
379 if ((sc->info[binfo->sensor].units == ENVSYS_SFANRPM)
380 && (binfo->sensor != 10)) {
381
382 if (binfo->rpms == 0) {
383 binfo->validflags = 0;
384 return (0);
385 }
386
387 /* 153 is the nominal FAN speed value */
388 divisor = 1350000 / (binfo->rpms * 153);
389
390 /* ...but we need lg(divisor) */
391 if (divisor <= 1)
392 divisor = 0;
393 else if (divisor <= 2)
394 divisor = 1;
395 else if (divisor <= 4)
396 divisor = 2;
397 else
398 divisor = 3;
399
400 /*
401 * FAN1 div is in bits <5:4>, FAN2 div is
402 * in <7:6>
403 */
404 sdata = lm_readreg(sc, LMD_VIDFAN);
405 if ( binfo->sensor == 8 ) { /* FAN1 */
406 divisor <<= 4;
407 sdata = (sdata & 0xCF) | divisor;
408 } else { /* FAN2 */
409 divisor <<= 6;
410 sdata = (sdata & 0x3F) | divisor;
411 }
412
413 lm_writereg(sc, LMD_VIDFAN, sdata);
414 }
415
416 memcpy(sc->info[binfo->sensor].desc, binfo->desc,
417 sizeof(sc->info[binfo->sensor].desc));
418 sc->info[binfo->sensor].desc[
419 sizeof(sc->info[binfo->sensor].desc) - 1] = '\0';
420
421 binfo->validflags = ENVSYS_FVALID;
422 }
423 return (0);
424 }
425
426 int
427 wb_streinfo(sme, binfo)
428 struct sysmon_envsys *sme;
429 struct envsys_basic_info *binfo;
430 {
431 struct lm_softc *sc = sme->sme_cookie;
432 int divisor;
433 u_int8_t sdata;
434 int i;
435
436 if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
437 sc->info[binfo->sensor].rfact = binfo->rfact;
438 else {
439 if (sc->info[binfo->sensor].units == ENVSYS_SFANRPM) {
440
441 if (binfo->rpms == 0) {
442 binfo->validflags = 0;
443 return (0);
444 }
445
446 /* 153 is the nominal FAN speed value */
447 divisor = 1350000 / (binfo->rpms * 153);
448
449 /* ...but we need lg(divisor) */
450 for (i = 0; i < 7; i++) {
451 if (divisor <= (1 << i))
452 break;
453 }
454 divisor = i;
455
456 if (binfo->sensor == 12 || binfo->sensor == 13) {
457 /*
458 * FAN1 div is in bits <5:4>, FAN2 div
459 * is in <7:6>
460 */
461 sdata = lm_readreg(sc, LMD_VIDFAN);
462 if ( binfo->sensor == 12 ) { /* FAN1 */
463 sdata = (sdata & 0xCF) |
464 ((divisor & 0x3) << 4);
465 } else { /* FAN2 */
466 sdata = (sdata & 0x3F) |
467 ((divisor & 0x3) << 6);
468 }
469 lm_writereg(sc, LMD_VIDFAN, sdata);
470 } else {
471 /* FAN3 is in WB_PIN <7:6> */
472 sdata = lm_readreg(sc, WB_PIN);
473 sdata = (sdata & 0x3F) |
474 ((divisor & 0x3) << 6);
475 lm_writereg(sc, LMD_VIDFAN, sdata);
476 }
477 /* Bit 2 of divisor is in WB_BANK0_FANBAT */
478 lm_writereg(sc, WB_BANKSEL, WB_BANKSEL_B0);
479 sdata = lm_readreg(sc, WB_BANK0_FANBAT);
480 sdata &= ~(0x20 << (binfo->sensor - 12));
481 sdata |= (divisor & 0x4) << (binfo->sensor - 9);
482 lm_writereg(sc, WB_BANK0_FANBAT, sdata);
483 }
484
485 memcpy(sc->info[binfo->sensor].desc, binfo->desc,
486 sizeof(sc->info[binfo->sensor].desc));
487 sc->info[binfo->sensor].desc[
488 sizeof(sc->info[binfo->sensor].desc) - 1] = '\0';
489
490 binfo->validflags = ENVSYS_FVALID;
491 }
492 return (0);
493 }
494
495 /*
496 * pre: last read occured >= 1.5 seconds ago
497 * post: sensors[] current data are the latest from the chip
498 */
499 void
500 lm_refresh_sensor_data(sc)
501 struct lm_softc *sc;
502 {
503 int sdata;
504 int i, divisor;
505
506 /* Refresh our stored data for every sensor */
507 for (i = 0; i < LM_NUM_SENSORS; ++i) {
508 sdata = lm_readreg(sc, LMD_SENSORBASE + i);
509
510 switch (sc->sensors[i].units) {
511 case ENVSYS_STEMP:
512 /* temp is given in deg. C, we convert to uK */
513 sc->sensors[i].cur.data_us = sdata * 1000000 +
514 273150000;
515 break;
516
517 case ENVSYS_SVOLTS_DC:
518 /* voltage returned as (mV >> 4), we convert to uVDC */
519 sc->sensors[i].cur.data_s = (sdata << 4);
520 /* rfact is (factor * 10^4) */
521 sc->sensors[i].cur.data_s *= sc->info[i].rfact;
522 /* division by 10 gets us back to uVDC */
523 sc->sensors[i].cur.data_s /= 10;
524
525 /* these two are negative voltages */
526 if ( (i == 5) || (i == 6) )
527 sc->sensors[i].cur.data_s *= -1;
528
529 break;
530
531 case ENVSYS_SFANRPM:
532 if (i == 10)
533 divisor = 2; /* Fixed divisor for FAN3 */
534 else if (i == 9) /* Bits 7 & 6 of VID/FAN */
535 divisor = (lm_readreg(sc, LMD_VIDFAN) >> 6) &
536 0x3;
537 else
538 divisor = (lm_readreg(sc, LMD_VIDFAN) >> 4) &
539 0x3;
540
541 if (sdata == 0xff || sdata == 0x00) {
542 sc->sensors[i].cur.data_us = 0;
543 } else {
544 sc->sensors[i].cur.data_us = 1350000 /
545 (sdata << divisor);
546 }
547 break;
548
549 default:
550 /* XXX - debug log something? */
551 sc->sensors[i].validflags = 0;
552
553 break;
554 }
555 }
556 }
557
558 void
559 wb_refresh_sensor_data(sc)
560 struct lm_softc *sc;
561 {
562 int sdata;
563 int i, divisor;
564
565 /* Refresh our stored data for every sensor */
566 /* first voltage sensors */
567 for (i = 0; i < 9; ++i) {
568 if (i < 7) {
569 sdata = lm_readreg(sc, LMD_SENSORBASE + i);
570 } else {
571 /* from bank5 */
572 lm_writereg(sc, WB_BANKSEL, WB_BANKSEL_B5);
573 sdata = lm_readreg(sc, (i == 7) ?
574 WB_BANK5_5VSB : WB_BANK5_VBAT);
575 }
576 DPRINTF(("sdata[%d] 0x%x\n", i, sdata));
577 /* voltage returned as (mV >> 4), we convert to uV */
578 sdata = sdata << 4;
579 /* special case for negative voltages */
580 if (i == 5) {
581 /*
582 * -12Vdc, assume Winbond recommended values for
583 * resistors
584 */
585 sdata = ((sdata * 1000) - (3600 * 805)) / 195;
586 } else if (i == 6) {
587 /*
588 * -5Vdc, assume Winbond recommended values for
589 * resistors
590 */
591 sdata = ((sdata * 1000) - (3600 * 682)) / 318;
592 }
593 /* rfact is (factor * 10^4) */
594 sc->sensors[i].cur.data_s = sdata * sc->info[i].rfact;
595 /* division by 10 gets us back to uVDC */
596 sc->sensors[i].cur.data_s /= 10;
597 }
598 /* temperatures. Given in dC, we convert to uK */
599 sdata = lm_readreg(sc, LMD_SENSORBASE + 7);
600 DPRINTF(("sdata[%d] 0x%x\n", 9, sdata));
601 sc->sensors[9].cur.data_us = sdata * 1000000 + 273150000;
602 /* from bank1 */
603 lm_writereg(sc, WB_BANKSEL, WB_BANKSEL_B1);
604 sdata = lm_readreg(sc, WB_BANK1_T2H) << 1;
605 sdata |= (lm_readreg(sc, WB_BANK1_T2L) & 0x80) >> 7;
606 DPRINTF(("sdata[%d] 0x%x\n", 10, sdata));
607 sc->sensors[10].cur.data_us = (sdata * 1000000) / 2 + 273150000;
608 /* from bank2 */
609 lm_writereg(sc, WB_BANKSEL, WB_BANKSEL_B2);
610 sdata = lm_readreg(sc, WB_BANK2_T3H) << 1;
611 sdata |= (lm_readreg(sc, WB_BANK2_T3L) & 0x80) >> 7;
612 DPRINTF(("sdata[%d] 0x%x\n", 11, sdata));
613 sc->sensors[11].cur.data_us = (sdata * 1000000) / 2 + 273150000;
614
615 /* Fans */
616 lm_writereg(sc, WB_BANKSEL, WB_BANKSEL_B0);
617 for (i = 12; i < 15; i++) {
618 sdata = lm_readreg(sc, LMD_SENSORBASE + i - 4);
619 if (i == 12)
620 divisor = (lm_readreg(sc, LMD_VIDFAN) >> 4) & 0x3;
621 else if (i == 13)
622 divisor = (lm_readreg(sc, LMD_VIDFAN) >> 6) & 0x3;
623 else
624 divisor = (lm_readreg(sc, WB_PIN) >> 6) & 0x3;
625 divisor |= (lm_readreg(sc, WB_BANK0_FANBAT) >> (i - 9)) & 0x4;
626
627 DPRINTF(("sdata[%d] 0x%x div 0x%x\n", i, sdata, divisor));
628 if (sdata == 0xff || sdata == 0x00) {
629 sc->sensors[i].cur.data_us = 0;
630 } else {
631 sc->sensors[i].cur.data_us = 1350000 /
632 (sdata << divisor);
633 }
634 }
635 }
636