drivers/watchdog/jz4740_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/jz4740_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/jz4740_wdt.c- Extension
.c- Size
- 5238 bytes
- Lines
- 201
- 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/mfd/ingenic-tcu.hlinux/mfd/syscon.hlinux/module.hlinux/moduleparam.hlinux/types.hlinux/kernel.hlinux/watchdog.hlinux/platform_device.hlinux/io.hlinux/device.hlinux/clk.hlinux/slab.hlinux/err.hlinux/of.hlinux/regmap.h
Detected Declarations
struct jz4740_wdt_drvdatafunction jz4740_wdt_pingfunction jz4740_wdt_set_timeoutfunction jz4740_wdt_startfunction jz4740_wdt_stopfunction jz4740_wdt_restartfunction jz4740_wdt_probe
Annotated Snippet
struct jz4740_wdt_drvdata {
struct watchdog_device wdt;
struct regmap *map;
struct clk *clk;
unsigned long clk_rate;
};
static int jz4740_wdt_ping(struct watchdog_device *wdt_dev)
{
struct jz4740_wdt_drvdata *drvdata = watchdog_get_drvdata(wdt_dev);
regmap_write(drvdata->map, TCU_REG_WDT_TCNT, 0);
return 0;
}
static int jz4740_wdt_set_timeout(struct watchdog_device *wdt_dev,
unsigned int new_timeout)
{
struct jz4740_wdt_drvdata *drvdata = watchdog_get_drvdata(wdt_dev);
u16 timeout_value = (u16)(drvdata->clk_rate * new_timeout);
unsigned int tcer;
regmap_read(drvdata->map, TCU_REG_WDT_TCER, &tcer);
regmap_write(drvdata->map, TCU_REG_WDT_TCER, 0);
regmap_write(drvdata->map, TCU_REG_WDT_TDR, timeout_value);
regmap_write(drvdata->map, TCU_REG_WDT_TCNT, 0);
if (tcer & TCU_WDT_TCER_TCEN)
regmap_write(drvdata->map, TCU_REG_WDT_TCER, TCU_WDT_TCER_TCEN);
wdt_dev->timeout = new_timeout;
return 0;
}
static int jz4740_wdt_start(struct watchdog_device *wdt_dev)
{
struct jz4740_wdt_drvdata *drvdata = watchdog_get_drvdata(wdt_dev);
unsigned int tcer;
int ret;
ret = clk_prepare_enable(drvdata->clk);
if (ret)
return ret;
regmap_read(drvdata->map, TCU_REG_WDT_TCER, &tcer);
jz4740_wdt_set_timeout(wdt_dev, wdt_dev->timeout);
/* Start watchdog if it wasn't started already */
if (!(tcer & TCU_WDT_TCER_TCEN))
regmap_write(drvdata->map, TCU_REG_WDT_TCER, TCU_WDT_TCER_TCEN);
return 0;
}
static int jz4740_wdt_stop(struct watchdog_device *wdt_dev)
{
struct jz4740_wdt_drvdata *drvdata = watchdog_get_drvdata(wdt_dev);
regmap_write(drvdata->map, TCU_REG_WDT_TCER, 0);
clk_disable_unprepare(drvdata->clk);
return 0;
}
static int jz4740_wdt_restart(struct watchdog_device *wdt_dev,
unsigned long action, void *data)
{
wdt_dev->timeout = 0;
jz4740_wdt_start(wdt_dev);
return 0;
}
static const struct watchdog_info jz4740_wdt_info = {
.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
.identity = "jz4740 Watchdog",
};
static const struct watchdog_ops jz4740_wdt_ops = {
.owner = THIS_MODULE,
.start = jz4740_wdt_start,
.stop = jz4740_wdt_stop,
.ping = jz4740_wdt_ping,
.set_timeout = jz4740_wdt_set_timeout,
.restart = jz4740_wdt_restart,
};
#ifdef CONFIG_OF
Annotation
- Immediate include surface: `linux/mfd/ingenic-tcu.h`, `linux/mfd/syscon.h`, `linux/module.h`, `linux/moduleparam.h`, `linux/types.h`, `linux/kernel.h`, `linux/watchdog.h`, `linux/platform_device.h`.
- Detected declarations: `struct jz4740_wdt_drvdata`, `function jz4740_wdt_ping`, `function jz4740_wdt_set_timeout`, `function jz4740_wdt_start`, `function jz4740_wdt_stop`, `function jz4740_wdt_restart`, `function jz4740_wdt_probe`.
- 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.