// SPDX-License-Identifier: GPL-2.0-or-later /* * SMsC 37B787 Watchdog Timer driver for Linux 2.6.x.x * * Based on acquirewdt.c by Alan Cox <alan@lxorguk.ukuu.org.uk> * and some other existing drivers * * The authors do NOT admit liability nor provide warranty for * any of this software. This material is provided "AS-IS" in * the hope that it may be useful for others. * * (C) Copyright 2003-2006 Sven Anders <anders@anduras.de> * * History: * 2003 - Created version 1.0 for Linux 2.4.x. * 2006 - Ported to Linux 2.6, added nowayout and MAGICCLOSE * features. Released version 1.1 * * Theory of operation: * * A Watchdog Timer (WDT) is a hardware circuit that can * reset the computer system in case of a software fault. * You probably knew that already. * * Usually a userspace daemon will notify the kernel WDT driver * via the /dev/watchdog special device file that userspace is * still alive, at regular intervals. When such a notification * occurs, the driver will usually tell the hardware watchdog * that everything is in order, and that the watchdog should wait * for yet another little while to reset the system. * If userspace fails (RAM error, kernel bug, whatever), the * notifications cease to occur, and the hardware watchdog will * reset the system (causing a reboot) after the timeout occurs. * * Create device with: * mknod /dev/watchdog c 10 130 * * For an example userspace keep-alive daemon, see: * Documentation/watchdog/wdt.rst
*/
/* enable support for minutes as units? */ /* (does not always work correctly, so disabled by default!) */ #define SMSC_SUPPORT_MINUTES #undef SMSC_SUPPORT_MINUTES
/* write to the control register */ staticinlinevoid write_io_cr(unsignedchar reg, unsignedchar data)
{
outb(reg, IOPORT);
outb(data, IOPORT+1);
}
/* read from the control register */ staticinlinechar read_io_cr(unsignedchar reg)
{
outb(reg, IOPORT); return inb(IOPORT+1);
}
/* -- Medium level functions ------------------------------------*/
staticinlinevoid gpio_bit12(unsignedchar reg)
{ /* -- General Purpose I/O Bit 1.2 -- * Bit 0, In/Out: 0 = Output, 1 = Input * Bit 1, Polarity: 0 = No Invert, 1 = Invert * Bit 2, Group Enable Intr.: 0 = Disable, 1 = Enable * Bit 3/4, Function select: 00 = GPI/O, 01 = WDT, 10 = P17, * 11 = Either Edge Triggered Intr. 2 * Bit 5/6 (Reserved) * Bit 7, Output Type: 0 = Push Pull Bit, 1 = Open Drain
*/
write_io_cr(0xE2, reg);
}
staticinlinevoid gpio_bit13(unsignedchar reg)
{ /* -- General Purpose I/O Bit 1.3 -- * Bit 0, In/Out: 0 = Output, 1 = Input * Bit 1, Polarity: 0 = No Invert, 1 = Invert * Bit 2, Group Enable Intr.: 0 = Disable, 1 = Enable * Bit 3, Function select: 0 = GPI/O, 1 = LED * Bit 4-6 (Reserved) * Bit 7, Output Type: 0 = Push Pull Bit, 1 = Open Drain
*/
write_io_cr(0xE3, reg);
}
staticinlinevoid wdt_timer_units(unsignedchar new_units)
{ /* -- Watchdog timer units -- * Bit 0-6 (Reserved) * Bit 7, WDT Time-out Value Units Select * (0 = Minutes, 1 = Seconds)
*/
write_io_cr(0xF1, new_units);
}
staticinlinevoid wdt_timeout_value(unsignedchar new_timeout)
{ /* -- Watchdog Timer Time-out Value -- * Bit 0-7 Binary coded units (0=Disabled, 1..255)
*/
write_io_cr(0xF2, new_timeout);
}
staticinlinevoid wdt_timer_conf(unsignedchar conf)
{ /* -- Watchdog timer configuration -- * Bit 0 Joystick enable: 0* = No Reset, 1 = Reset WDT upon * Gameport I/O * Bit 1 Keyboard enable: 0* = No Reset, 1 = Reset WDT upon KBD Intr. * Bit 2 Mouse enable: 0* = No Reset, 1 = Reset WDT upon Mouse Intr * Bit 3 Reset the timer * (Wrong in SMsC documentation? Given as: PowerLED Timout * Enabled) * Bit 4-7 WDT Interrupt Mapping: (0000* = Disabled, * 0001=IRQ1, 0010=(Invalid), 0011=IRQ3 to 1111=IRQ15)
*/
write_io_cr(0xF3, conf);
}
staticinlinevoid wdt_timer_ctrl(unsignedchar reg)
{ /* -- Watchdog timer control -- * Bit 0 Status Bit: 0 = Timer counting, 1 = Timeout occurred * Bit 1 Power LED Toggle: 0 = Disable Toggle, 1 = Toggle at 1 Hz * Bit 2 Force Timeout: 1 = Forces WD timeout event (self-cleaning) * Bit 3 P20 Force Timeout enabled: * 0 = P20 activity does not generate the WD timeout event * 1 = P20 Allows rising edge of P20, from the keyboard * controller, to force the WD timeout event. * Bit 4 (Reserved) * -- Soft power management -- * Bit 5 Stop Counter: 1 = Stop software power down counter * set via register 0xB8, (self-cleaning) * (Upon read: 0 = Counter running, 1 = Counter stopped) * Bit 6 Restart Counter: 1 = Restart software power down counter * set via register 0xB8, (self-cleaning) * Bit 7 SPOFF: 1 = Force software power down (self-cleaning)
*/
write_io_cr(0xF4, reg);
}
/* write => update the timer to keep the machine alive */
static ssize_t wb_smsc_wdt_write(struct file *file, constchar __user *data,
size_t len, loff_t *ppos)
{ /* See if we got the magic character 'V' and reload the timer */ if (len) { if (!nowayout) {
size_t i;
/* reset expect flag */
expect_close = 0;
/* scan to see whether or not we got the
magic character */ for (i = 0; i != len; i++) { char c; if (get_user(c, data + i)) return -EFAULT; if (c == 'V')
expect_close = 42;
}
}
/* someone wrote to us, we should reload the timer */
wb_smsc_wdt_reset_timer();
} return len;
}
switch (cmd) { case WDIOC_GETSUPPORT: return copy_to_user(uarg.ident, &ident, sizeof(ident))
? -EFAULT : 0; case WDIOC_GETSTATUS: return put_user(wb_smsc_wdt_status(), uarg.i); case WDIOC_GETBOOTSTATUS: return put_user(0, uarg.i); case WDIOC_SETOPTIONS:
{ int options, retval = -EINVAL;
if (get_user(options, uarg.i)) return -EFAULT;
if (options & WDIOS_DISABLECARD) {
wb_smsc_wdt_disable();
retval = 0;
} if (options & WDIOS_ENABLECARD) {
wb_smsc_wdt_enable();
retval = 0;
} return retval;
} case WDIOC_KEEPALIVE:
wb_smsc_wdt_reset_timer(); return0; case WDIOC_SETTIMEOUT: if (get_user(new_timeout, uarg.i)) return -EFAULT; /* the API states this is given in secs */ if (unit == UNIT_MINUTE)
new_timeout /= 60; if (new_timeout < 0 || new_timeout > MAX_TIMEOUT) return -EINVAL;
timeout = new_timeout;
wb_smsc_wdt_set_timeout(timeout);
fallthrough; /* and return the new timeout */ case WDIOC_GETTIMEOUT:
new_timeout = timeout; if (unit == UNIT_MINUTE)
new_timeout *= 60; return put_user(new_timeout, uarg.i); default: return -ENOTTY;
}
}
staticvoid __exit wb_smsc_wdt_exit(void)
{ /* Stop the timer before we leave */ if (!nowayout) {
wb_smsc_wdt_shutdown();
pr_info("Watchdog disabled\n");
}
MODULE_AUTHOR("Sven Anders <anders@anduras.de>");
MODULE_DESCRIPTION("Driver for SMsC 37B787 watchdog component (Version "
VERSION ")");
MODULE_LICENSE("GPL");
#ifdef SMSC_SUPPORT_MINUTES
module_param(unit, int, 0);
MODULE_PARM_DESC(unit, "set unit to use, 0=seconds or 1=minutes, default is 0"); #endif
module_param(timeout, int, 0);
MODULE_PARM_DESC(timeout, "range is 1-255 units, default is 60");
module_param(nowayout, bool, 0);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-07)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.