drivers/watchdog/mena21_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/mena21_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/mena21_wdt.c- Extension
.c- Size
- 5228 bytes
- Lines
- 229
- 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/module.hlinux/moduleparam.hlinux/types.hlinux/kernel.hlinux/slab.hlinux/platform_device.hlinux/watchdog.hlinux/uaccess.hlinux/gpio/consumer.hlinux/delay.hlinux/bitops.hlinux/of.h
Detected Declarations
struct a21_wdt_drvenum a21_wdt_gpiosfunction a21_wdt_get_bootstatusfunction a21_wdt_startfunction a21_wdt_stopfunction a21_wdt_pingfunction a21_wdt_set_timeoutfunction a21_wdt_probefunction a21_wdt_shutdown
Annotated Snippet
struct a21_wdt_drv {
struct watchdog_device wdt;
struct gpio_desc *gpios[NUM_GPIOS];
};
static bool nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, bool, 0);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
static unsigned int a21_wdt_get_bootstatus(struct a21_wdt_drv *drv)
{
int reset = 0;
reset |= gpiod_get_value(drv->gpios[GPIO_WD_RST0]) ? (1 << 0) : 0;
reset |= gpiod_get_value(drv->gpios[GPIO_WD_RST1]) ? (1 << 1) : 0;
reset |= gpiod_get_value(drv->gpios[GPIO_WD_RST2]) ? (1 << 2) : 0;
return reset;
}
static int a21_wdt_start(struct watchdog_device *wdt)
{
struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
gpiod_set_value(drv->gpios[GPIO_WD_ENAB], 1);
return 0;
}
static int a21_wdt_stop(struct watchdog_device *wdt)
{
struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
gpiod_set_value(drv->gpios[GPIO_WD_ENAB], 0);
return 0;
}
static int a21_wdt_ping(struct watchdog_device *wdt)
{
struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
gpiod_set_value(drv->gpios[GPIO_WD_TRIG], 0);
ndelay(10);
gpiod_set_value(drv->gpios[GPIO_WD_TRIG], 1);
return 0;
}
static int a21_wdt_set_timeout(struct watchdog_device *wdt,
unsigned int timeout)
{
struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
if (timeout != 1 && timeout != 30) {
dev_err(wdt->parent, "Only 1 and 30 allowed as timeout\n");
return -EINVAL;
}
if (timeout == 30 && wdt->timeout == 1) {
dev_err(wdt->parent,
"Transition from fast to slow mode not allowed\n");
return -EINVAL;
}
if (timeout == 1)
gpiod_set_value(drv->gpios[GPIO_WD_FAST], 1);
else
gpiod_set_value(drv->gpios[GPIO_WD_FAST], 0);
wdt->timeout = timeout;
return 0;
}
static const struct watchdog_info a21_wdt_info = {
.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
.identity = "MEN A21 Watchdog",
};
static const struct watchdog_ops a21_wdt_ops = {
.owner = THIS_MODULE,
.start = a21_wdt_start,
.stop = a21_wdt_stop,
.ping = a21_wdt_ping,
.set_timeout = a21_wdt_set_timeout,
};
static struct watchdog_device a21_wdt = {
Annotation
- Immediate include surface: `linux/module.h`, `linux/moduleparam.h`, `linux/types.h`, `linux/kernel.h`, `linux/slab.h`, `linux/platform_device.h`, `linux/watchdog.h`, `linux/uaccess.h`.
- Detected declarations: `struct a21_wdt_drv`, `enum a21_wdt_gpios`, `function a21_wdt_get_bootstatus`, `function a21_wdt_start`, `function a21_wdt_stop`, `function a21_wdt_ping`, `function a21_wdt_set_timeout`, `function a21_wdt_probe`, `function a21_wdt_shutdown`.
- 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.