drivers/watchdog/meson_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/meson_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/meson_wdt.c- Extension
.c- Size
- 5839 bytes
- Lines
- 227
- 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/clk.hlinux/delay.hlinux/err.hlinux/init.hlinux/io.hlinux/kernel.hlinux/mod_devicetable.hlinux/module.hlinux/moduleparam.hlinux/platform_device.hlinux/property.hlinux/types.hlinux/watchdog.h
Detected Declarations
struct meson_wdt_datastruct meson_wdt_devfunction meson_wdt_restartfunction meson_wdt_pingfunction meson_wdt_change_timeoutfunction meson_wdt_set_timeoutfunction meson_wdt_stopfunction meson_wdt_startfunction meson_wdt_probe
Annotated Snippet
struct meson_wdt_data {
unsigned int enable;
unsigned int terminal_count_mask;
unsigned int count_unit;
};
static struct meson_wdt_data meson6_wdt_data = {
.enable = BIT(22),
.terminal_count_mask = 0x3fffff,
.count_unit = 100000, /* 10 us */
};
static struct meson_wdt_data meson8b_wdt_data = {
.enable = BIT(19),
.terminal_count_mask = 0xffff,
.count_unit = 7812, /* 128 us */
};
struct meson_wdt_dev {
struct watchdog_device wdt_dev;
void __iomem *wdt_base;
const struct meson_wdt_data *data;
};
static int meson_wdt_restart(struct watchdog_device *wdt_dev,
unsigned long action, void *data)
{
struct meson_wdt_dev *meson_wdt = watchdog_get_drvdata(wdt_dev);
u32 tc_reboot = MESON_WDT_DC_RESET;
tc_reboot |= meson_wdt->data->enable;
while (1) {
writel(tc_reboot, meson_wdt->wdt_base + MESON_WDT_TC);
mdelay(5);
}
return 0;
}
static int meson_wdt_ping(struct watchdog_device *wdt_dev)
{
struct meson_wdt_dev *meson_wdt = watchdog_get_drvdata(wdt_dev);
writel(0, meson_wdt->wdt_base + MESON_WDT_RESET);
return 0;
}
static void meson_wdt_change_timeout(struct watchdog_device *wdt_dev,
unsigned int timeout)
{
struct meson_wdt_dev *meson_wdt = watchdog_get_drvdata(wdt_dev);
u32 reg;
reg = readl(meson_wdt->wdt_base + MESON_WDT_TC);
reg &= ~meson_wdt->data->terminal_count_mask;
reg |= MESON_SEC_TO_TC(timeout, meson_wdt->data->count_unit);
writel(reg, meson_wdt->wdt_base + MESON_WDT_TC);
}
static int meson_wdt_set_timeout(struct watchdog_device *wdt_dev,
unsigned int timeout)
{
wdt_dev->timeout = timeout;
meson_wdt_change_timeout(wdt_dev, timeout);
meson_wdt_ping(wdt_dev);
return 0;
}
static int meson_wdt_stop(struct watchdog_device *wdt_dev)
{
struct meson_wdt_dev *meson_wdt = watchdog_get_drvdata(wdt_dev);
u32 reg;
reg = readl(meson_wdt->wdt_base + MESON_WDT_TC);
reg &= ~meson_wdt->data->enable;
writel(reg, meson_wdt->wdt_base + MESON_WDT_TC);
return 0;
}
static int meson_wdt_start(struct watchdog_device *wdt_dev)
{
struct meson_wdt_dev *meson_wdt = watchdog_get_drvdata(wdt_dev);
u32 reg;
meson_wdt_change_timeout(wdt_dev, meson_wdt->wdt_dev.timeout);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/err.h`, `linux/init.h`, `linux/io.h`, `linux/kernel.h`, `linux/mod_devicetable.h`, `linux/module.h`.
- Detected declarations: `struct meson_wdt_data`, `struct meson_wdt_dev`, `function meson_wdt_restart`, `function meson_wdt_ping`, `function meson_wdt_change_timeout`, `function meson_wdt_set_timeout`, `function meson_wdt_stop`, `function meson_wdt_start`, `function meson_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.