itesio_isa.c revision 1.22 1 /* $NetBSD: itesio_isa.c,v 1.22 2011/06/20 18:12:54 pgoyette Exp $ */
2 /* Derived from $OpenBSD: it.c,v 1.19 2006/04/10 00:57:54 deraadt Exp $ */
3
4 /*
5 * Copyright (c) 2006-2007 Juan Romero Pardines <xtraeme (at) netbsd.org>
6 * Copyright (c) 2003 Julien Bordet <zejames (at) greyhats.org>
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITD TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITD TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 /*
31 * Driver for the iTE IT87xxF Super I/O. Currently supporting
32 * the Environmental Controller to monitor the sensors and the
33 * Watchdog Timer.
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: itesio_isa.c,v 1.22 2011/06/20 18:12:54 pgoyette Exp $");
38
39 #include <sys/param.h>
40 #include <sys/kernel.h>
41 #include <sys/device.h>
42
43 #include <sys/bus.h>
44
45 #include <dev/isa/isareg.h>
46 #include <dev/isa/isavar.h>
47
48 #include <dev/sysmon/sysmonvar.h>
49
50 #include <dev/isa/itesio_isavar.h>
51
52 #define IT_VOLTSTART_IDX 3 /* voltage start index */
53 #define IT_FANSTART_IDX 12 /* fan start index */
54
55 #if defined(ITESIO_DEBUG)
56 #define DPRINTF(x) do { printf x; } while (0)
57 #else
58 #define DPRINTF(x)
59 #endif
60
61 /*
62 * IT87-compatible chips can typically measure voltages up to 4.096 V.
63 * To measure higher voltages the input is attenuated with (external)
64 * resistors. Negative voltages are measured using a reference
65 * voltage. So we have to convert the sensor values back to real
66 * voltages by applying the appropriate resistor factor.
67 */
68 #define RFACT_NONE 10000
69 #define RFACT(x, y) (RFACT_NONE * ((x) + (y)) / (y))
70
71 /* autoconf(9) functions */
72 static int itesio_isa_match(device_t, cfdata_t, void *);
73 static void itesio_isa_attach(device_t, device_t, void *);
74 static int itesio_isa_detach(device_t, int);
75
76 CFATTACH_DECL_NEW(itesio, sizeof(struct itesio_softc),
77 itesio_isa_match, itesio_isa_attach, itesio_isa_detach, NULL);
78
79 /* driver functions */
80 static uint8_t itesio_ecreadreg(struct itesio_softc *, int);
81 static void itesio_ecwritereg(struct itesio_softc *, int, int);
82 static uint8_t itesio_readreg(bus_space_tag_t, bus_space_handle_t, int);
83 static void itesio_writereg(bus_space_tag_t, bus_space_handle_t, int, int);
84 static void itesio_enter(bus_space_tag_t, bus_space_handle_t);
85 static void itesio_exit(bus_space_tag_t, bus_space_handle_t);
86
87 /* sysmon_envsys(9) glue */
88 static void itesio_setup_sensors(struct itesio_softc *);
89 static void itesio_refresh_temp(struct itesio_softc *, envsys_data_t *);
90 static void itesio_refresh_volts(struct itesio_softc *, envsys_data_t *);
91 static void itesio_refresh_fans(struct itesio_softc *, envsys_data_t *);
92 static void itesio_refresh(struct sysmon_envsys *, envsys_data_t *);
93
94 /* sysmon_wdog glue */
95 static bool itesio_wdt_suspend(device_t, const pmf_qual_t *);
96 static int itesio_wdt_setmode(struct sysmon_wdog *);
97 static int itesio_wdt_tickle(struct sysmon_wdog *);
98
99 /* rfact values for voltage sensors */
100 static const int itesio_vrfact[] = {
101 RFACT_NONE, /* VCORE_A */
102 RFACT_NONE, /* VCORE_B */
103 RFACT_NONE, /* +3.3V */
104 RFACT(68, 100), /* +5V */
105 RFACT(30, 10), /* +12V */
106 RFACT(21, 10), /* -5V */
107 RFACT(83, 20), /* -12V */
108 RFACT(68, 100), /* STANDBY */
109 RFACT_NONE /* VBAT */
110 };
111
112 static int
113 itesio_isa_match(device_t parent, cfdata_t match, void *aux)
114 {
115 struct isa_attach_args *ia = aux;
116 bus_space_handle_t ioh;
117 uint16_t cr;
118
119 /* Must supply an address */
120 if (ia->ia_nio < 1)
121 return 0;
122
123 if (ISA_DIRECT_CONFIG(ia))
124 return 0;
125
126 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
127 return 0;
128
129 if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 2, 0, &ioh))
130 return 0;
131
132 itesio_enter(ia->ia_iot, ioh);
133 cr = (itesio_readreg(ia->ia_iot, ioh, ITESIO_CHIPID1) << 8);
134 cr |= itesio_readreg(ia->ia_iot, ioh, ITESIO_CHIPID2);
135 itesio_exit(ia->ia_iot, ioh);
136 bus_space_unmap(ia->ia_iot, ioh, 2);
137
138 switch (cr) {
139 case ITESIO_ID8705:
140 case ITESIO_ID8712:
141 case ITESIO_ID8716:
142 case ITESIO_ID8718:
143 case ITESIO_ID8721:
144 case ITESIO_ID8726:
145 ia->ia_nio = 1;
146 ia->ia_io[0].ir_size = 2;
147 ia->ia_niomem = 0;
148 ia->ia_nirq = 0;
149 ia->ia_ndrq = 0;
150 return 1;
151 default:
152 return 0;
153 }
154 }
155
156 static void
157 itesio_isa_attach(device_t parent, device_t self, void *aux)
158 {
159 struct itesio_softc *sc = device_private(self);
160 struct isa_attach_args *ia = aux;
161 int i;
162 uint8_t cr;
163
164 sc->sc_iot = ia->ia_iot;
165
166 if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, 2, 0,
167 &sc->sc_pnp_ioh)) {
168 aprint_error(": can't map pnp i/o space\n");
169 return;
170 }
171
172 aprint_naive("\n");
173
174 /*
175 * Enter to the Super I/O MB PNP mode.
176 */
177 itesio_enter(sc->sc_iot, sc->sc_pnp_ioh);
178 /*
179 * Get info from the Super I/O Global Configuration Registers:
180 * Chip IDs and Device Revision.
181 */
182 sc->sc_chipid = (itesio_readreg(sc->sc_iot, sc->sc_pnp_ioh,
183 ITESIO_CHIPID1) << 8);
184 sc->sc_chipid |= itesio_readreg(sc->sc_iot, sc->sc_pnp_ioh,
185 ITESIO_CHIPID2);
186 sc->sc_devrev = (itesio_readreg(sc->sc_iot, sc->sc_pnp_ioh,
187 ITESIO_DEVREV) & 0x0f);
188 /*
189 * Select the EC LDN to get the Base Address.
190 */
191 itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_LDNSEL,
192 ITESIO_EC_LDN);
193 sc->sc_hwmon_baseaddr =
194 (itesio_readreg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_EC_MSB) << 8);
195 sc->sc_hwmon_baseaddr |= itesio_readreg(sc->sc_iot, sc->sc_pnp_ioh,
196 ITESIO_EC_LSB);
197 /*
198 * We are done, exit MB PNP mode.
199 */
200 itesio_exit(sc->sc_iot, sc->sc_pnp_ioh);
201
202 aprint_normal(": iTE IT%4xF Super I/O (rev %d)\n",
203 sc->sc_chipid, sc->sc_devrev);
204 aprint_normal_dev(self, "Hardware Monitor registers at 0x%x\n",
205 sc->sc_hwmon_baseaddr);
206
207 if (bus_space_map(sc->sc_iot, sc->sc_hwmon_baseaddr, 8, 0,
208 &sc->sc_ec_ioh)) {
209 aprint_error_dev(self, "cannot map hwmon i/o space\n");
210 goto out2;
211 }
212
213 sc->sc_hwmon_mapped = true;
214
215 /* Activate monitoring */
216 cr = itesio_ecreadreg(sc, ITESIO_EC_CONFIG);
217 SET(cr, 0x01);
218 itesio_ecwritereg(sc, ITESIO_EC_CONFIG, cr);
219
220 #ifdef notyet
221 /* Enable beep alarms */
222 cr = itesio_ecreadreg(sc, ITESIO_EC_BEEPEER);
223 SET(cr, 0x02); /* Voltage exceeds limit */
224 SET(cr, 0x04); /* Temperature exceeds limit */
225 itesio_ecwritereg(sc, ITESIO_EC_BEEPEER, cr);
226 #endif
227
228 /*
229 * Initialize and attach sensors.
230 */
231 itesio_setup_sensors(sc);
232 sc->sc_sme = sysmon_envsys_create();
233 for (i = 0; i < IT_NUM_SENSORS; i++) {
234 if (sysmon_envsys_sensor_attach(sc->sc_sme,
235 &sc->sc_sensor[i])) {
236 sysmon_envsys_destroy(sc->sc_sme);
237 goto out;
238 }
239 }
240 /*
241 * Hook into the system monitor.
242 */
243 sc->sc_sme->sme_name = device_xname(self);
244 sc->sc_sme->sme_cookie = sc;
245 sc->sc_sme->sme_refresh = itesio_refresh;
246
247 if ((i = sysmon_envsys_register(sc->sc_sme))) {
248 aprint_error_dev(self,
249 "unable to register with sysmon (%d)\n", i);
250 sysmon_envsys_destroy(sc->sc_sme);
251 goto out;
252 }
253 sc->sc_hwmon_enabled = true;
254
255 if (!pmf_device_register(self, NULL, NULL))
256 aprint_error_dev(self, "couldn't establish power handler\n");
257
258 /* The IT8705 doesn't support the WDT */
259 if (sc->sc_chipid == ITESIO_ID8705)
260 goto out2;
261
262 /*
263 * Initialize the watchdog timer.
264 */
265 sc->sc_smw.smw_name = device_xname(self);
266 sc->sc_smw.smw_cookie = sc;
267 sc->sc_smw.smw_setmode = itesio_wdt_setmode;
268 sc->sc_smw.smw_tickle = itesio_wdt_tickle;
269 sc->sc_smw.smw_period = 60;
270
271 if (sysmon_wdog_register(&sc->sc_smw)) {
272 aprint_error_dev(self, "unable to register watchdog timer\n");
273 goto out2;
274 }
275 sc->sc_wdt_enabled = true;
276 aprint_normal_dev(self, "Watchdog Timer present\n");
277
278 pmf_device_deregister(self);
279 if (!pmf_device_register(self, itesio_wdt_suspend, NULL))
280 aprint_error_dev(self, "couldn't establish power handler\n");
281
282 return;
283
284 out:
285 bus_space_unmap(sc->sc_iot, sc->sc_ec_ioh, 8);
286 out2:
287 bus_space_unmap(sc->sc_iot, sc->sc_pnp_ioh, 2);
288 }
289
290 static int
291 itesio_isa_detach(device_t self, int flags)
292 {
293 struct itesio_softc *sc = device_private(self);
294
295 if (sc->sc_hwmon_enabled)
296 sysmon_envsys_unregister(sc->sc_sme);
297 if (sc->sc_hwmon_mapped)
298 bus_space_unmap(sc->sc_iot, sc->sc_ec_ioh, 8);
299 if (sc->sc_wdt_enabled) {
300 sysmon_wdog_unregister(&sc->sc_smw);
301 bus_space_unmap(sc->sc_iot, sc->sc_pnp_ioh, 2);
302 }
303
304 return 0;
305 }
306
307 static bool
308 itesio_wdt_suspend(device_t dev, const pmf_qual_t *qual)
309 {
310 struct itesio_softc *sc = device_private(dev);
311
312 /* Don't allow suspend if watchdog is armed */
313 if ((sc->sc_smw.smw_mode & WDOG_MODE_MASK) != WDOG_MODE_DISARMED)
314 return false;
315 return true;
316 }
317
318 /*
319 * Functions to read/write to the Environmental Controller.
320 */
321 static uint8_t
322 itesio_ecreadreg(struct itesio_softc *sc, int reg)
323 {
324 bus_space_write_1(sc->sc_iot, sc->sc_ec_ioh, ITESIO_EC_ADDR, reg);
325 return bus_space_read_1(sc->sc_iot, sc->sc_ec_ioh, ITESIO_EC_DATA);
326 }
327
328 static void
329 itesio_ecwritereg(struct itesio_softc *sc, int reg, int val)
330 {
331 bus_space_write_1(sc->sc_iot, sc->sc_ec_ioh, ITESIO_EC_ADDR, reg);
332 bus_space_write_1(sc->sc_iot, sc->sc_ec_ioh, ITESIO_EC_DATA, val);
333 }
334
335 /*
336 * Functions to enter/exit/read/write to the Super I/O.
337 */
338 static uint8_t
339 itesio_readreg(bus_space_tag_t iot, bus_space_handle_t ioh, int reg)
340 {
341 bus_space_write_1(iot, ioh, ITESIO_ADDR, reg);
342 return bus_space_read_1(iot, ioh, ITESIO_DATA);
343 }
344
345 static void
346 itesio_writereg(bus_space_tag_t iot, bus_space_handle_t ioh, int reg, int val)
347 {
348 bus_space_write_1(iot, ioh, ITESIO_ADDR, reg);
349 bus_space_write_1(iot, ioh, ITESIO_DATA, val);
350 }
351
352 static void
353 itesio_enter(bus_space_tag_t iot, bus_space_handle_t ioh)
354 {
355 bus_space_write_1(iot, ioh, ITESIO_ADDR, 0x87);
356 bus_space_write_1(iot, ioh, ITESIO_ADDR, 0x01);
357 bus_space_write_1(iot, ioh, ITESIO_ADDR, 0x55);
358 bus_space_write_1(iot, ioh, ITESIO_ADDR, 0x55);
359 }
360
361 static void
362 itesio_exit(bus_space_tag_t iot, bus_space_handle_t ioh)
363 {
364 bus_space_write_1(iot, ioh, ITESIO_ADDR, 0x02);
365 bus_space_write_1(iot, ioh, ITESIO_DATA, 0x02);
366 }
367
368
369 #define COPYDESCR(x, y) \
370 do { \
371 strlcpy((x), (y), sizeof(x)); \
372 } while (0)
373 /*
374 * sysmon_envsys(9) glue.
375 */
376 static void
377 itesio_setup_sensors(struct itesio_softc *sc)
378 {
379 int i;
380
381 /* temperatures */
382 for (i = 0; i < IT_VOLTSTART_IDX; i++)
383 sc->sc_sensor[i].units = ENVSYS_STEMP;
384
385 COPYDESCR(sc->sc_sensor[0].desc, "CPU Temp");
386 COPYDESCR(sc->sc_sensor[1].desc, "System Temp");
387 COPYDESCR(sc->sc_sensor[2].desc, "Aux Temp");
388
389 /* voltages */
390 for (i = IT_VOLTSTART_IDX; i < IT_FANSTART_IDX; i++) {
391 sc->sc_sensor[i].units = ENVSYS_SVOLTS_DC;
392 sc->sc_sensor[i].flags = ENVSYS_FCHANGERFACT;
393 }
394
395 COPYDESCR(sc->sc_sensor[3].desc, "VCORE_A");
396 COPYDESCR(sc->sc_sensor[4].desc, "VCORE_B");
397 COPYDESCR(sc->sc_sensor[5].desc, "+3.3V");
398 COPYDESCR(sc->sc_sensor[6].desc, "+5V");
399 COPYDESCR(sc->sc_sensor[7].desc, "+12V");
400 COPYDESCR(sc->sc_sensor[8].desc, "-5V");
401 COPYDESCR(sc->sc_sensor[9].desc, "-12V");
402 COPYDESCR(sc->sc_sensor[10].desc, "STANDBY");
403 COPYDESCR(sc->sc_sensor[11].desc, "VBAT");
404
405 /* fans */
406 for (i = IT_FANSTART_IDX; i < IT_NUM_SENSORS; i++)
407 sc->sc_sensor[i].units = ENVSYS_SFANRPM;
408
409 COPYDESCR(sc->sc_sensor[12].desc, "CPU Fan");
410 COPYDESCR(sc->sc_sensor[13].desc, "System Fan");
411 COPYDESCR(sc->sc_sensor[14].desc, "Aux Fan");
412
413 /* all */
414 for (i = 0; i < IT_NUM_SENSORS; i++)
415 sc->sc_sensor[i].state = ENVSYS_SINVALID;
416 }
417 #undef COPYDESCR
418
419 static void
420 itesio_refresh_temp(struct itesio_softc *sc, envsys_data_t *edata)
421 {
422 int sdata;
423
424 sdata = itesio_ecreadreg(sc, ITESIO_EC_SENSORTEMPBASE + edata->sensor);
425 /* sensor is not connected or reporting invalid data */
426 if (sdata == 0 || sdata >= 0xfa) {
427 edata->state = ENVSYS_SINVALID;
428 return;
429 }
430
431 DPRINTF(("%s: sdata[temp%d] 0x%x\n", __func__, edata->sensor, sdata));
432 /* Convert temperature to uK */
433 edata->value_cur = sdata * 1000000 + 273150000;
434 edata->state = ENVSYS_SVALID;
435 }
436
437 static void
438 itesio_refresh_volts(struct itesio_softc *sc, envsys_data_t *edata)
439 {
440 uint8_t vbatcr = 0;
441 int i, sdata;
442
443 i = edata->sensor - IT_VOLTSTART_IDX;
444
445 sdata = itesio_ecreadreg(sc, ITESIO_EC_SENSORVOLTBASE + i);
446 /* not connected */
447 if (sdata == 0 || sdata == 0xff) {
448 edata->state = ENVSYS_SINVALID;
449 return;
450 }
451
452 /*
453 * update VBAT voltage reading every time we read it, to get
454 * latest value.
455 */
456 if (i == 8) {
457 vbatcr = itesio_ecreadreg(sc, ITESIO_EC_CONFIG);
458 SET(vbatcr, ITESIO_EC_UPDATEVBAT);
459 itesio_ecwritereg(sc, ITESIO_EC_CONFIG, vbatcr);
460 }
461
462 DPRINTF(("%s: sdata[volt%d] 0x%x\n", __func__, i, sdata));
463
464 /* voltage returned as (mV << 4) */
465 edata->value_cur = (sdata << 4);
466 /* negative values */
467 if (i == 5 || i == 6)
468 edata->value_cur -= ITESIO_EC_VREF;
469 /* rfact is (factor * 10^4) */
470 if (edata->rfact)
471 edata->value_cur *= edata->rfact;
472 else
473 edata->value_cur *= itesio_vrfact[i];
474 /* division by 10 gets us back to uVDC */
475 edata->value_cur /= 10;
476 if (i == 5 || i == 6)
477 edata->value_cur += ITESIO_EC_VREF * 1000;
478
479 edata->state = ENVSYS_SVALID;
480 }
481
482 static void
483 itesio_refresh_fans(struct itesio_softc *sc, envsys_data_t *edata)
484 {
485 uint8_t mode = 0;
486 uint16_t sdata = 0;
487 int i, divisor, odivisor, ndivisor;
488
489 i = edata->sensor - IT_FANSTART_IDX;
490 divisor = odivisor = ndivisor = 0;
491
492 if (sc->sc_chipid == ITESIO_ID8705 || sc->sc_chipid == ITESIO_ID8712) {
493 /*
494 * Use the Fan Tachometer Divisor Register for
495 * IT8705F and IT8712F.
496 */
497 divisor = odivisor = ndivisor =
498 itesio_ecreadreg(sc, ITESIO_EC_FAN_TDR);
499 sdata = itesio_ecreadreg(sc, ITESIO_EC_SENSORFANBASE + i);
500 if (sdata == 0xff) {
501 edata->state = ENVSYS_SINVALID;
502 if (i == 2)
503 ndivisor |= 0x40;
504 else {
505 ndivisor &= ~(7 << (i * 3));
506 ndivisor |= ((divisor + 1) & 7) << (i * 3);
507 }
508 } else {
509 if (i == 2)
510 divisor = divisor & 1 ? 3 : 1;
511
512 if ((sdata << (divisor & 7)) == 0)
513 edata->state = ENVSYS_SINVALID;
514 else {
515 edata->value_cur =
516 1350000 / (sdata << (divisor & 7));
517 edata->state = ENVSYS_SVALID;
518 }
519 }
520 DPRINTF(("%s: 8bit sdata[fan%d] 0x%x div: 0x%x\n", __func__,
521 i, sdata, divisor));
522 if (ndivisor != odivisor)
523 itesio_ecwritereg(sc, ITESIO_EC_FAN_TDR, ndivisor);
524 } else {
525 mode = itesio_ecreadreg(sc, ITESIO_EC_FAN16_CER);
526 sdata = itesio_ecreadreg(sc, ITESIO_EC_SENSORFANBASE + i);
527 if (mode & (1 << i))
528 sdata += (itesio_ecreadreg(sc,
529 ITESIO_EC_SENSORFANEXTBASE + i) << 8);
530 edata->state = ENVSYS_SVALID;
531 if (sdata == 0 ||
532 sdata == ((mode & (1 << i)) ? 0xffff : 0xff))
533 edata->state = ENVSYS_SINVALID;
534 else {
535 edata->value_cur = 1350000 / 2 / sdata;
536 edata->state = ENVSYS_SVALID;
537 }
538 DPRINTF(("%s: 16bit sdata[fan%d] 0x%x\n", __func__, i, sdata));
539 }
540 }
541
542 static void
543 itesio_refresh(struct sysmon_envsys *sme, struct envsys_data *edata)
544 {
545 struct itesio_softc *sc = sme->sme_cookie;
546
547 if (edata->sensor < IT_VOLTSTART_IDX)
548 itesio_refresh_temp(sc, edata);
549 else if (edata->sensor >= IT_VOLTSTART_IDX &&
550 edata->sensor < IT_FANSTART_IDX)
551 itesio_refresh_volts(sc, edata);
552 else
553 itesio_refresh_fans(sc, edata);
554 }
555
556 static int
557 itesio_wdt_setmode(struct sysmon_wdog *smw)
558 {
559 struct itesio_softc *sc = smw->smw_cookie;
560 int period = smw->smw_period;
561
562 /* Enter MB PNP mode and select the WDT LDN */
563 itesio_enter(sc->sc_iot, sc->sc_pnp_ioh);
564 itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_LDNSEL,
565 ITESIO_WDT_LDN);
566
567 if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
568 /* Disable the watchdog */
569 itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_CTL, 0);
570 itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_CNF, 0);
571 itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_TMO_MSB, 0);
572 itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_TMO_LSB, 0);
573 } else {
574 /* Enable the watchdog */
575 if (period > ITESIO_WDT_MAXTIMO || period < 1)
576 period = smw->smw_period = ITESIO_WDT_MAXTIMO;
577
578 period *= 2;
579
580 /* set the timeout and start the watchdog */
581 itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_TMO_MSB,
582 period >> 8);
583 itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_TMO_LSB,
584 period & 0xff);
585 itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_CNF,
586 ITESIO_WDT_CNF_SECS | ITESIO_WDT_CNF_KRST |
587 ITESIO_WDT_CNF_PWROK);
588 }
589 /* we are done, exit MB PNP mode */
590 itesio_exit(sc->sc_iot, sc->sc_pnp_ioh);
591
592 return 0;
593 }
594
595 static int
596 itesio_wdt_tickle(struct sysmon_wdog *smw)
597 {
598 struct itesio_softc *sc = smw->smw_cookie;
599 int period = smw->smw_period * 2;
600
601 /* refresh timeout value and exit */
602 itesio_enter(sc->sc_iot, sc->sc_pnp_ioh);
603 itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_LDNSEL,
604 ITESIO_WDT_LDN);
605 itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_TMO_MSB,
606 period >> 8);
607 itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_TMO_LSB,
608 period & 0xff);
609 itesio_exit(sc->sc_iot, sc->sc_pnp_ioh);
610
611 return 0;
612 }
613