w83795g.c revision 1.1.2.3 1 /* $NetBSD: w83795g.c,v 1.1.2.3 2013/10/20 13:36:43 bouyer Exp $ */
2
3 /*
4 * Copyright (c) 2013 Soren S. Jorvang. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: w83795g.c,v 1.1.2.3 2013/10/20 13:36:43 bouyer Exp $");
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/device.h>
34 #include <sys/conf.h>
35 #include <sys/gpio.h>
36 #include <sys/wdog.h>
37
38 #include <dev/i2c/i2cvar.h>
39 #include <dev/gpio/gpiovar.h>
40 #include <dev/sysmon/sysmonvar.h>
41
42 #include <dev/i2c/w83795greg.h>
43
44 #define NUM_SENSORS 53
45 static const struct w83795g_sensor {
46 const char *desc;
47 enum envsys_units type;
48 uint8_t en_reg;
49 uint8_t en_mask;
50 uint8_t en_bits;
51 uint8_t msb;
52 } sensors[NUM_SENSORS] = {
53 #define _VOLT ENVSYS_SVOLTS_DC
54 { "VSEN1", _VOLT, W83795G_V_CTRL1, 0x01, 0x01, W83795G_VSEN1 },
55 { "VSEN2", _VOLT, W83795G_V_CTRL1, 0x02, 0x02, W83795G_VSEN2 },
56 { "VSEN3", _VOLT, W83795G_V_CTRL1, 0x04, 0x04, W83795G_VSEN3 },
57 { "VSEN4", _VOLT, W83795G_V_CTRL1, 0x08, 0x08, W83795G_VSEN4 },
58 { "VSEN5", _VOLT, W83795G_V_CTRL1, 0x10, 0x10, W83795G_VSEN5 },
59 { "VSEN6", _VOLT, W83795G_V_CTRL1, 0x20, 0x20, W83795G_VSEN6 },
60 { "VSEN7", _VOLT, W83795G_V_CTRL1, 0x40, 0x40, W83795G_VSEN7 },
61 { "VSEN8", _VOLT, W83795G_V_CTRL1, 0x80, 0x80, W83795G_VSEN8 },
62 { "VSEN9", _VOLT, W83795G_V_CTRL2, 0x01, 0x01, W83795G_VSEN9 },
63 { "VSEN10", _VOLT, W83795G_V_CTRL2, 0x02, 0x02, W83795G_VSEN10 },
64 { "VSEN11", _VOLT, W83795G_V_CTRL2, 0x04, 0x04, W83795G_VSEN11 },
65 { "VTT", _VOLT, W83795G_V_CTRL2, 0x08, 0x08, W83795G_VTT },
66 { "3VDD", _VOLT, W83795G_V_CTRL2, 0x10, 0x10, W83795G_3VDD },
67 { "3VSB", _VOLT, W83795G_V_CTRL2, 0x20, 0x20, W83795G_3VSB },
68 { "VBAT", _VOLT, W83795G_V_CTRL2, 0x40, 0x40, W83795G_VBAT },
69 { "VSEN12", _VOLT, W83795G_T_CTRL1, 0x03, 0x02, W83795G_VSEN12 },
70 { "VSEN13", _VOLT, W83795G_T_CTRL1, 0x0c, 0x08, W83795G_VSEN13 },
71 { "VDSEN14", _VOLT, W83795G_T_CTRL2, 0x03, 0x02, W83795G_VDSEN14 },
72 { "VDSEN15", _VOLT, W83795G_T_CTRL2, 0x0c, 0x08, W83795G_VDSEN15 },
73 { "VDSEN16", _VOLT, W83795G_T_CTRL2, 0x30, 0x20, W83795G_VDSEN16 },
74 { "VDSEN17", _VOLT, W83795G_T_CTRL2, 0xc0, 0x80, W83795G_VDSEN17 },
75 #define _TEMP ENVSYS_STEMP
76 { "TR5", _TEMP, W83795G_T_CTRL1, 0x03, 0x03, W83795G_TR5 },
77 { "TR6", _TEMP, W83795G_T_CTRL1, 0x0c, 0x0c, W83795G_TR6 },
78 { "TD1", _TEMP, W83795G_T_CTRL2, 0x03, 0x01, W83795G_TD1 },
79 { "TD2", _TEMP, W83795G_T_CTRL2, 0x0c, 0x04, W83795G_TD2 },
80 { "TD3", _TEMP, W83795G_T_CTRL2, 0x30, 0x10, W83795G_TD3 },
81 { "TD4", _TEMP, W83795G_T_CTRL2, 0xc0, 0x40, W83795G_TD4 },
82 { "TR1", _TEMP, W83795G_T_CTRL2, 0x03, 0x03, W83795G_TR1 },
83 { "TR2", _TEMP, W83795G_T_CTRL2, 0x0c, 0x0c, W83795G_TR2 },
84 { "TR3", _TEMP, W83795G_T_CTRL2, 0x30, 0x30, W83795G_TR3 },
85 { "TR4", _TEMP, W83795G_T_CTRL2, 0xc0, 0xc0, W83795G_TR4 },
86 { "DTS1", _TEMP, W83795G_T_CTRL1, 0x20, 0x20, W83795G_DTS1 },
87 { "DTS2", _TEMP, W83795G_T_CTRL1, 0x20, 0x20, W83795G_DTS2 },
88 { "DTS3", _TEMP, W83795G_T_CTRL1, 0x20, 0x20, W83795G_DTS3 },
89 { "DTS4", _TEMP, W83795G_T_CTRL1, 0x20, 0x20, W83795G_DTS4 },
90 { "DTS5", _TEMP, W83795G_T_CTRL1, 0x20, 0x20, W83795G_DTS5 },
91 { "DTS6", _TEMP, W83795G_T_CTRL1, 0x20, 0x20, W83795G_DTS6 },
92 { "DTS7", _TEMP, W83795G_T_CTRL1, 0x20, 0x20, W83795G_DTS7 },
93 { "DTS8", _TEMP, W83795G_T_CTRL1, 0x20, 0x20, W83795G_DTS8 },
94 #define _FAN ENVSYS_SFANRPM
95 { "FANIN1", _FAN, W83795G_F_CTRL1, 0x01, 0x01, W83795G_FANIN1 },
96 { "FANIN2", _FAN, W83795G_F_CTRL1, 0x02, 0x02, W83795G_FANIN2 },
97 { "FANIN3", _FAN, W83795G_F_CTRL1, 0x04, 0x04, W83795G_FANIN3 },
98 { "FANIN4", _FAN, W83795G_F_CTRL1, 0x08, 0x08, W83795G_FANIN4 },
99 { "FANIN5", _FAN, W83795G_F_CTRL1, 0x10, 0x10, W83795G_FANIN5 },
100 { "FANIN6", _FAN, W83795G_F_CTRL1, 0x20, 0x20, W83795G_FANIN6 },
101 { "FANIN7", _FAN, W83795G_F_CTRL1, 0x40, 0x40, W83795G_FANIN7 },
102 { "FANIN8", _FAN, W83795G_F_CTRL1, 0x80, 0x80, W83795G_FANIN8 },
103 { "FANIN9", _FAN, W83795G_F_CTRL2, 0x01, 0x01, W83795G_FANIN9 },
104 { "FANIN10", _FAN, W83795G_F_CTRL2, 0x02, 0x02, W83795G_FANIN10 },
105 { "FANIN11", _FAN, W83795G_F_CTRL2, 0x04, 0x04, W83795G_FANIN11 },
106 { "FANIN12", _FAN, W83795G_F_CTRL2, 0x08, 0x08, W83795G_FANIN12 },
107 { "FANIN13", _FAN, W83795G_F_CTRL2, 0x10, 0x10, W83795G_FANIN13 },
108 { "FANIN14", _FAN, W83795G_F_CTRL2, 0x20, 0x20, W83795G_FANIN14 },
109 };
110
111 struct w83795g_softc {
112 device_t sc_dev;
113 i2c_tag_t sc_tag;
114 i2c_addr_t sc_addr;
115 struct gpio_chipset_tag sc_gpio_gc;
116 gpio_pin_t sc_gpio_pins[8];
117 struct sysmon_envsys *sc_sme;
118 envsys_data_t sc_sensors[NUM_SENSORS];
119 struct sysmon_wdog sc_smw;
120 };
121
122 static int w83795g_match(device_t, cfdata_t, void *);
123 static void w83795g_attach(device_t, device_t, void *);
124
125 CFATTACH_DECL_NEW(w83795g, sizeof(struct w83795g_softc),
126 w83795g_match, w83795g_attach, NULL, NULL);
127
128 static void w83795g_refresh(struct sysmon_envsys *, envsys_data_t *);
129 static void w83795g_get_limits(struct sysmon_envsys *, envsys_data_t *,
130 sysmon_envsys_lim_t *limits, uint32_t *props);
131
132 static int w83795g_gpio_read(void *, int);
133 static void w83795g_gpio_write(void *, int, int);
134 static void w83795g_gpio_ctl(void *, int, int);
135
136 static int w83795g_wdog_setmode(struct sysmon_wdog *);
137 static int w83795g_wdog_tickle(struct sysmon_wdog *);
138
139 static int
140 w83795g_match(device_t parent, cfdata_t match, void *aux)
141 {
142 struct i2c_attach_args *ia = aux;
143 uint8_t bank, vend, chip, deva;
144
145 if (ia->ia_addr < I2CADDR_MINADDR || ia->ia_addr > I2CADDR_MAXADDR)
146 return 0;
147
148 iic_acquire_bus(ia->ia_tag, 0);
149 iic_smbus_read_byte(ia->ia_tag, ia->ia_addr, W83795G_BANKSEL, &bank, 0);
150 iic_smbus_read_byte(ia->ia_tag, ia->ia_addr, W83795G_VENDOR, &vend, 0);
151 iic_smbus_read_byte(ia->ia_tag, ia->ia_addr, W83795G_CHIP, &chip, 0);
152 iic_smbus_read_byte(ia->ia_tag, ia->ia_addr, W83795G_DEVICEA, &deva, 0);
153 iic_release_bus(ia->ia_tag, 0);
154
155 if ((bank & BANKSEL_HBACS && vend == VENDOR_NUVOTON_ID_HI) ||
156 (~bank & BANKSEL_HBACS && vend == VENDOR_NUVOTON_ID_LO))
157 if (chip == CHIP_W83795G && deva == DEVICEA_A)
158 return 1;
159
160 return 0;
161 }
162
163 static void
164 w83795g_attach(device_t parent, device_t self, void *aux)
165 {
166 struct w83795g_softc *sc = device_private(self);
167 struct i2c_attach_args *ia = aux;
168 struct gpiobus_attach_args gba;
169 uint8_t conf, rev, reg, gpiom, en_reg;
170 int i;
171
172 sc->sc_dev = self;
173 sc->sc_tag = ia->ia_tag;
174 sc->sc_addr = ia->ia_addr;
175 sc->sc_gpio_gc.gp_cookie = sc;
176 sc->sc_gpio_gc.gp_pin_read = w83795g_gpio_read;
177 sc->sc_gpio_gc.gp_pin_write = w83795g_gpio_write;
178 sc->sc_gpio_gc.gp_pin_ctl = w83795g_gpio_ctl;
179 sc->sc_sme = sysmon_envsys_create();
180 sc->sc_sme->sme_name = device_xname(self);
181 sc->sc_sme->sme_cookie = sc;
182 sc->sc_sme->sme_refresh = w83795g_refresh;
183 sc->sc_sme->sme_get_limits = w83795g_get_limits;
184 sc->sc_smw.smw_name = device_xname(self);
185 sc->sc_smw.smw_cookie = sc;
186 sc->sc_smw.smw_setmode = w83795g_wdog_setmode;
187 sc->sc_smw.smw_tickle = w83795g_wdog_tickle;
188 sc->sc_smw.smw_period = 60;
189
190 iic_acquire_bus(sc->sc_tag, 0);
191 iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, W83795G_BANKSEL, 0, 0);
192 iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, W83795G_CONFIG, &conf, 0);
193 iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, W83795G_DEVICE, &rev, 0);
194
195 aprint_normal(": Nuvaton W83795");
196 if (conf & CONFIG_CONFIG48)
197 aprint_normal("ADG");
198 else
199 aprint_normal("G");
200 aprint_verbose(" (rev %c)", rev - DEVICEA_A + 'A');
201 aprint_normal(" Hardware Monitor\n");
202 aprint_naive(": Hardware Monitor\n");
203
204 /* Debug dump of all register banks */
205 for (i = 0; i < 1024; i++) {
206 if (i % 256 == 0) {
207 iic_smbus_write_byte(sc->sc_tag, sc->sc_addr,
208 W83795G_BANKSEL, i / 256, 0);
209 aprint_debug_dev(self, "register bank %d:\n", i / 256);
210 }
211 if (i % 32 == 0)
212 aprint_debug_dev(self, "%02x ", i % 256);
213 iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, i % 256, ®, 0);
214 aprint_debug("%02x", reg);
215 if (i % 32 == 31)
216 aprint_debug("\n");
217 else if (i % 8 == 7)
218 aprint_debug(" ");
219 }
220
221 iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, W83795G_BANKSEL, 0, 0);
222
223 for (i = 0; i < NUM_SENSORS; i++) {
224 iic_smbus_read_byte(sc->sc_tag, sc->sc_addr,
225 sensors[i].en_reg, &en_reg, 0);
226
227 if ((en_reg & sensors[i].en_mask) != sensors[i].en_bits)
228 continue;
229
230 strcpy(sc->sc_sensors[i].desc, sensors[i].desc);
231 sc->sc_sensors[i].units = sensors[i].type;
232 sc->sc_sensors[i].state = ENVSYS_SINVALID;
233 sc->sc_sensors[i].flags = ENVSYS_FMONLIMITS;
234 sc->sc_sensors[i].private = i;
235 sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensors[i]);
236 }
237
238 iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, W83795G_GPIO_M, &gpiom, 0);
239 iic_release_bus(sc->sc_tag, 0);
240
241 if (conf & CONFIG_CONFIG48)
242 gba.gba_npins = 4;
243 else
244 gba.gba_npins = 8;
245 gba.gba_gc = &sc->sc_gpio_gc;
246 gba.gba_pins = sc->sc_gpio_pins;
247
248 for (i = 0; i < gba.gba_npins; i++) {
249 sc->sc_gpio_pins[i].pin_num = i;
250 sc->sc_gpio_pins[i].pin_caps = GPIO_PIN_OUTPUT | GPIO_PIN_INPUT;
251 sc->sc_gpio_pins[i].pin_flags = (gpiom & (1 << i)) ?
252 GPIO_PIN_OUTPUT : GPIO_PIN_INPUT;
253 sc->sc_gpio_pins[i].pin_state = w83795g_gpio_read(sc, i);
254 }
255
256 if (sysmon_envsys_register(sc->sc_sme))
257 aprint_error_dev(self, "unable to register with sysmon\n");
258
259 if (sysmon_wdog_register(&sc->sc_smw) != 0)
260 aprint_error_dev(self, "couldn't register watchdog\n");
261
262 if (!pmf_device_register(self, NULL, NULL))
263 aprint_error_dev(self, "couldn't establish power handler\n");
264
265 config_found(self, &gba, gpiobus_print);
266 }
267
268 static void
269 w83795g_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
270 {
271 struct w83795g_softc *sc = sme->sme_cookie;
272 const struct w83795g_sensor *sensor = &sensors[edata->private];
273 uint8_t msb, lsb;
274
275 sensor = &sensors[edata->private];
276
277 iic_acquire_bus(sc->sc_tag, 0);
278 iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, W83795G_BANKSEL, 0, 0);
279 iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, sensor->msb, &msb, 0);
280 iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, W83795G_VR_LSB, &lsb, 0);
281 iic_release_bus(sc->sc_tag, 0);
282
283 switch (edata->units) {
284 case ENVSYS_SVOLTS_DC:
285 if (sensor->msb == W83795G_3VDD ||
286 sensor->msb == W83795G_3VSB ||
287 sensor->msb == W83795G_VBAT)
288 edata->value_cur = (msb << 2 | lsb >> 6) * 6000;
289 else
290 edata->value_cur = (msb << 2 | lsb >> 6) * 2000;
291 break;
292 case ENVSYS_STEMP:
293 edata->value_cur = ((int8_t)msb << 2 | lsb >> 6) * 250000 +
294 273150000;
295 break;
296 case ENVSYS_SFANRPM:
297 edata->value_cur = 1350000 / (msb << 4 | lsb >> 4);
298 break;
299 }
300
301 edata->state = ENVSYS_SVALID;
302 }
303
304 static void
305 w83795g_get_limits(struct sysmon_envsys *sme, envsys_data_t *edata,
306 sysmon_envsys_lim_t *limits, uint32_t *props)
307 {
308 struct w83795g_softc *sc = sme->sme_cookie;
309 const struct w83795g_sensor *sensor = &sensors[edata->private];
310 uint8_t index, msb, lsb;
311
312 iic_acquire_bus(sc->sc_tag, 0);
313 iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, W83795G_BANKSEL, 0, 0);
314
315 switch (edata->units) {
316 case ENVSYS_SVOLTS_DC:
317 break;
318 case ENVSYS_STEMP:
319 if (sensor->msb == W83795G_TR5)
320 index = W83795G_TR5CRIT;
321 else if (sensor->msb == W83795G_TR6)
322 index = W83795G_TR6CRIT;
323 else if (sensor->msb >= W83795G_DTS1)
324 index = W83795G_DTSCRIT;
325 else
326 index = W83795G_TD1CRIT +
327 (sensor->msb - W83795G_TD1) * 4;
328 iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, index, &msb, 0);
329 limits->sel_critmax = (int8_t)msb * 1000000 + 273150000;
330 index += 2;
331 iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, index++, &msb, 0);
332 limits->sel_warnmax = (int8_t)msb * 1000000 + 273150000;
333 *props |= PROP_CRITMAX | PROP_WARNMAX;
334 break;
335 case ENVSYS_SFANRPM:
336 index = W83795G_FAN1HL + (sensor->msb - W83795G_FANIN1) * 2;
337 iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, index, &msb, 0);
338 index = W83795G_FHL1LSB + (sensor->msb - W83795G_FANIN1) / 2;
339 iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, index, &lsb, 0);
340 if (index % 2)
341 lsb >> 4;
342 else
343 lsb &= 0xf;
344 limits->sel_warnmin = 1350000 / (msb << 4 | lsb);
345 *props |= PROP_WARNMIN;
346 break;
347 }
348
349 iic_release_bus(sc->sc_tag, 0);
350 }
351
352 static int
353 w83795g_gpio_read(void *arg, int pin)
354 {
355 struct w83795g_softc *sc = arg;
356 uint8_t in, out;
357
358 iic_acquire_bus(sc->sc_tag, 0);
359 iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, W83795G_BANKSEL, 0, 0);
360 iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, W83795G_GPIO_I, &in, 0);
361 iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, W83795G_GPIO_O, &out, 0);
362 iic_release_bus(sc->sc_tag, 0);
363
364 if (sc->sc_gpio_pins[pin].pin_flags == GPIO_PIN_OUTPUT)
365 in = out;
366
367 return (in & (1 << pin)) ? GPIO_PIN_HIGH : GPIO_PIN_LOW;
368 }
369
370 static void
371 w83795g_gpio_write(void *arg, int pin, int value)
372 {
373 struct w83795g_softc *sc = arg;
374 uint8_t out;
375
376 iic_acquire_bus(sc->sc_tag, 0);
377 iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, W83795G_BANKSEL, 0, 0);
378 iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, W83795G_GPIO_O, &out, 0);
379
380 if (value == GPIO_PIN_LOW)
381 out &= ~(1 << pin);
382 else if (value == GPIO_PIN_HIGH)
383 out |= (1 << pin);
384
385 iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, W83795G_GPIO_O, out, 0);
386 iic_release_bus(sc->sc_tag, 0);
387 }
388
389 static void
390 w83795g_gpio_ctl(void *arg, int pin, int flags)
391 {
392 struct w83795g_softc *sc = arg;
393 uint8_t mode;
394
395 iic_acquire_bus(sc->sc_tag, 0);
396 iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, W83795G_BANKSEL, 0, 0);
397 iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, W83795G_GPIO_M, &mode, 0);
398
399 if (flags & GPIO_PIN_INPUT)
400 mode &= ~(1 << pin);
401 if (flags & GPIO_PIN_OUTPUT)
402 mode |= (1 << pin);
403
404 iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, W83795G_GPIO_M, mode, 0);
405 iic_release_bus(sc->sc_tag, 0);
406 }
407
408 static int
409 w83795g_wdog_setmode(struct sysmon_wdog *smw)
410 {
411 struct w83795g_softc *sc = smw->smw_cookie;
412
413 /*
414 * This device also supports a "hard" watchdog mode, which survives
415 * across reboots, but making use of that would require sysmon_wdog
416 * to have a way of querying the watchdog state at startup.
417 */
418
419 iic_acquire_bus(sc->sc_tag, 0);
420 iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, W83795G_BANKSEL, 0, 0);
421 iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, W83795G_WDT_ENA,
422 WDT_ENA_ENWDT | WDT_ENA_SOFT, 0);
423 if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED)
424 iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, W83795G_WDTLOCK,
425 WDTLOCK_DISABLE_SOFT, 0);
426 else
427 iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, W83795G_WDTLOCK,
428 WDTLOCK_ENABLE_SOFT, 0);
429 iic_release_bus(sc->sc_tag, 0);
430
431 if (smw->smw_period == WDOG_PERIOD_DEFAULT)
432 smw->smw_period = 60;
433 smw->smw_period = roundup(smw->smw_period, 60);
434 w83795g_wdog_tickle(smw);
435
436 return 0;
437 }
438
439 static int
440 w83795g_wdog_tickle(struct sysmon_wdog *smw)
441 {
442 struct w83795g_softc *sc = smw->smw_cookie;
443
444 iic_acquire_bus(sc->sc_tag, 0);
445 iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, W83795G_BANKSEL, 0, 0);
446 iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, W83795G_WDT_CNT,
447 smw->smw_period / 60, 0);
448 iic_release_bus(sc->sc_tag, 0);
449
450 return 0;
451 }
452