drivers/watchdog/txx9wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/txx9wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/txx9wdt.c- Extension
.c- Size
- 4427 bytes
- Lines
- 173
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/moduleparam.hlinux/types.hlinux/watchdog.hlinux/init.hlinux/platform_device.hlinux/clk.hlinux/err.hlinux/io.hasm/txx9tmr.h
Detected Declarations
function txx9wdt_pingfunction txx9wdt_startfunction txx9wdt_stopfunction txx9wdt_set_timeoutfunction txx9wdt_probefunction txx9wdt_removefunction txx9wdt_shutdown
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* txx9wdt: A Hardware Watchdog Driver for TXx9 SoCs
*
* Copyright (C) 2007 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/types.h>
#include <linux/watchdog.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/io.h>
#include <asm/txx9tmr.h>
#define WD_TIMER_CCD 7 /* 1/256 */
#define WD_TIMER_CLK (clk_get_rate(txx9_imclk) / (2 << WD_TIMER_CCD))
#define WD_MAX_TIMEOUT ((0xffffffff >> (32 - TXX9_TIMER_BITS)) / WD_TIMER_CLK)
#define TIMER_MARGIN 60 /* Default is 60 seconds */
static unsigned int timeout = TIMER_MARGIN; /* in seconds */
module_param(timeout, uint, 0);
MODULE_PARM_DESC(timeout,
"Watchdog timeout in seconds. "
"(0<timeout<((2^" __MODULE_STRING(TXX9_TIMER_BITS) ")/(IMCLK/256)), "
"default=" __MODULE_STRING(TIMER_MARGIN) ")");
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 struct txx9_tmr_reg __iomem *txx9wdt_reg;
static struct clk *txx9_imclk;
static DEFINE_SPINLOCK(txx9_lock);
static int txx9wdt_ping(struct watchdog_device *wdt_dev)
{
spin_lock(&txx9_lock);
__raw_writel(TXx9_TMWTMR_TWIE | TXx9_TMWTMR_TWC, &txx9wdt_reg->wtmr);
spin_unlock(&txx9_lock);
return 0;
}
static int txx9wdt_start(struct watchdog_device *wdt_dev)
{
spin_lock(&txx9_lock);
__raw_writel(WD_TIMER_CLK * wdt_dev->timeout, &txx9wdt_reg->cpra);
__raw_writel(WD_TIMER_CCD, &txx9wdt_reg->ccdr);
__raw_writel(0, &txx9wdt_reg->tisr); /* clear pending interrupt */
__raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG,
&txx9wdt_reg->tcr);
__raw_writel(TXx9_TMWTMR_TWIE | TXx9_TMWTMR_TWC, &txx9wdt_reg->wtmr);
spin_unlock(&txx9_lock);
return 0;
}
static int txx9wdt_stop(struct watchdog_device *wdt_dev)
{
spin_lock(&txx9_lock);
__raw_writel(TXx9_TMWTMR_WDIS, &txx9wdt_reg->wtmr);
__raw_writel(__raw_readl(&txx9wdt_reg->tcr) & ~TXx9_TMTCR_TCE,
&txx9wdt_reg->tcr);
spin_unlock(&txx9_lock);
return 0;
}
static int txx9wdt_set_timeout(struct watchdog_device *wdt_dev,
unsigned int new_timeout)
{
wdt_dev->timeout = new_timeout;
txx9wdt_stop(wdt_dev);
txx9wdt_start(wdt_dev);
return 0;
}
static const struct watchdog_info txx9wdt_info = {
.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
.identity = "Hardware Watchdog for TXx9",
};
static const struct watchdog_ops txx9wdt_ops = {
.owner = THIS_MODULE,
.start = txx9wdt_start,
Annotation
- Immediate include surface: `linux/module.h`, `linux/moduleparam.h`, `linux/types.h`, `linux/watchdog.h`, `linux/init.h`, `linux/platform_device.h`, `linux/clk.h`, `linux/err.h`.
- Detected declarations: `function txx9wdt_ping`, `function txx9wdt_start`, `function txx9wdt_stop`, `function txx9wdt_set_timeout`, `function txx9wdt_probe`, `function txx9wdt_remove`, `function txx9wdt_shutdown`.
- Atlas domain: Driver Families / drivers/watchdog.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.