drivers/watchdog/ni903x_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/ni903x_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/ni903x_wdt.c- Extension
.c- Size
- 6372 bytes
- Lines
- 257
- Domain
- Driver Families
- Bucket
- drivers/watchdog
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/acpi.hlinux/device.hlinux/interrupt.hlinux/io.hlinux/module.hlinux/platform_device.hlinux/watchdog.h
Detected Declarations
struct ni903x_wdtfunction ni903x_startfunction ni903x_wdd_set_timeoutfunction ni903x_wdd_get_timeleftfunction ni903x_wdd_pingfunction ni903x_wdd_startfunction ni903x_wdd_stopfunction ni903x_resourcesfunction ni903x_acpi_probefunction ni903x_acpi_remove
Annotated Snippet
struct ni903x_wdt {
struct device *dev;
u16 io_base;
struct watchdog_device wdd;
};
static unsigned int timeout;
module_param(timeout, uint, 0);
MODULE_PARM_DESC(timeout,
"Watchdog timeout in seconds. (default="
__MODULE_STRING(NIWD_DEFAULT_TIMEOUT) ")");
static int nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, int, S_IRUGO);
MODULE_PARM_DESC(nowayout,
"Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
static void ni903x_start(struct ni903x_wdt *wdt)
{
u8 control = inb(wdt->io_base + NIWD_CONTROL);
outb(control | NIWD_CONTROL_RESET, wdt->io_base + NIWD_CONTROL);
outb(control | NIWD_CONTROL_PET, wdt->io_base + NIWD_CONTROL);
}
static int ni903x_wdd_set_timeout(struct watchdog_device *wdd,
unsigned int timeout)
{
struct ni903x_wdt *wdt = watchdog_get_drvdata(wdd);
u32 counter = timeout * (1000000000 / NIWD_PERIOD_NS);
outb(((0x00FF0000 & counter) >> 16), wdt->io_base + NIWD_SEED2);
outb(((0x0000FF00 & counter) >> 8), wdt->io_base + NIWD_SEED1);
outb((0x000000FF & counter), wdt->io_base + NIWD_SEED0);
wdd->timeout = timeout;
return 0;
}
static unsigned int ni903x_wdd_get_timeleft(struct watchdog_device *wdd)
{
struct ni903x_wdt *wdt = watchdog_get_drvdata(wdd);
u8 control, counter0, counter1, counter2;
u32 counter;
control = inb(wdt->io_base + NIWD_CONTROL);
control |= NIWD_CONTROL_CAPTURECOUNTER;
outb(control, wdt->io_base + NIWD_CONTROL);
counter2 = inb(wdt->io_base + NIWD_COUNTER2);
counter1 = inb(wdt->io_base + NIWD_COUNTER1);
counter0 = inb(wdt->io_base + NIWD_COUNTER0);
counter = (counter2 << 16) | (counter1 << 8) | counter0;
return counter / (1000000000 / NIWD_PERIOD_NS);
}
static int ni903x_wdd_ping(struct watchdog_device *wdd)
{
struct ni903x_wdt *wdt = watchdog_get_drvdata(wdd);
u8 control;
control = inb(wdt->io_base + NIWD_CONTROL);
outb(control | NIWD_CONTROL_PET, wdt->io_base + NIWD_CONTROL);
return 0;
}
static int ni903x_wdd_start(struct watchdog_device *wdd)
{
struct ni903x_wdt *wdt = watchdog_get_drvdata(wdd);
outb(NIWD_CONTROL_RESET | NIWD_CONTROL_PROC_RESET,
wdt->io_base + NIWD_CONTROL);
ni903x_wdd_set_timeout(wdd, wdd->timeout);
ni903x_start(wdt);
return 0;
}
static int ni903x_wdd_stop(struct watchdog_device *wdd)
{
struct ni903x_wdt *wdt = watchdog_get_drvdata(wdd);
outb(NIWD_CONTROL_RESET, wdt->io_base + NIWD_CONTROL);
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/device.h`, `linux/interrupt.h`, `linux/io.h`, `linux/module.h`, `linux/platform_device.h`, `linux/watchdog.h`.
- Detected declarations: `struct ni903x_wdt`, `function ni903x_start`, `function ni903x_wdd_set_timeout`, `function ni903x_wdd_get_timeleft`, `function ni903x_wdd_ping`, `function ni903x_wdd_start`, `function ni903x_wdd_stop`, `function ni903x_resources`, `function ni903x_acpi_probe`, `function ni903x_acpi_remove`.
- Atlas domain: Driver Families / drivers/watchdog.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.