drivers/watchdog/imx7ulp_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/imx7ulp_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/imx7ulp_wdt.c- Extension
.c- Size
- 10591 bytes
- Lines
- 440
- 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/io.hlinux/iopoll.hlinux/kernel.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/reboot.hlinux/watchdog.h
Detected Declarations
struct imx_wdt_hw_featurestruct imx7ulp_wdt_devicefunction imx7ulp_wdt_wait_ulkfunction imx7ulp_wdt_wait_rcsfunction _imx7ulp_wdt_enablefunction imx7ulp_wdt_enablefunction imx7ulp_wdt_pingfunction imx7ulp_wdt_startfunction imx7ulp_wdt_stopfunction _imx7ulp_wdt_set_timeoutfunction imx7ulp_wdt_set_timeoutfunction imx7ulp_wdt_restartfunction _imx7ulp_wdt_initfunction imx7ulp_wdt_initfunction imx7ulp_wdt_probefunction imx7ulp_wdt_suspend_noirqfunction imx7ulp_wdt_resume_noirq
Annotated Snippet
struct imx_wdt_hw_feature {
bool prescaler_enable;
bool post_rcs_wait;
bool cpu_lpm_auto_cg;
u32 wdog_clock_rate;
};
struct imx7ulp_wdt_device {
struct watchdog_device wdd;
void __iomem *base;
struct clk *clk;
bool ext_reset;
const struct imx_wdt_hw_feature *hw;
};
static int imx7ulp_wdt_wait_ulk(void __iomem *base)
{
u32 val = readl(base + WDOG_CS);
if (!(val & WDOG_CS_ULK) &&
readl_poll_timeout_atomic(base + WDOG_CS, val,
val & WDOG_CS_ULK, 0,
WDOG_ULK_WAIT_TIMEOUT))
return -ETIMEDOUT;
return 0;
}
static int imx7ulp_wdt_wait_rcs(struct imx7ulp_wdt_device *wdt)
{
int ret = 0;
u32 val = readl(wdt->base + WDOG_CS);
u64 timeout = (val & WDOG_CS_PRES) ?
WDOG_RCS_WAIT_TIMEOUT * 256 : WDOG_RCS_WAIT_TIMEOUT;
unsigned long wait_min = (val & WDOG_CS_PRES) ?
WDOG_RCS_POST_WAIT * 256 : WDOG_RCS_POST_WAIT;
if (!(val & WDOG_CS_RCS) &&
readl_poll_timeout(wdt->base + WDOG_CS, val, val & WDOG_CS_RCS, 100,
timeout))
ret = -ETIMEDOUT;
/* Wait 2.5 clocks after RCS done */
if (wdt->hw->post_rcs_wait)
usleep_range(wait_min, wait_min + 2000);
return ret;
}
static int _imx7ulp_wdt_enable(struct imx7ulp_wdt_device *wdt, bool enable)
{
u32 val = readl(wdt->base + WDOG_CS);
int ret;
local_irq_disable();
writel(UNLOCK, wdt->base + WDOG_CNT);
ret = imx7ulp_wdt_wait_ulk(wdt->base);
if (ret)
goto enable_out;
if (enable)
writel(val | WDOG_CS_EN, wdt->base + WDOG_CS);
else
writel(val & ~WDOG_CS_EN, wdt->base + WDOG_CS);
local_irq_enable();
ret = imx7ulp_wdt_wait_rcs(wdt);
return ret;
enable_out:
local_irq_enable();
return ret;
}
static int imx7ulp_wdt_enable(struct watchdog_device *wdog, bool enable)
{
struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog);
int ret;
u32 val;
u32 loop = RETRY_MAX;
do {
ret = _imx7ulp_wdt_enable(wdt, enable);
val = readl(wdt->base + WDOG_CS);
} while (--loop > 0 && ((!!(val & WDOG_CS_EN)) != enable || ret));
if (loop == 0)
return -EBUSY;
return ret;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/io.h`, `linux/iopoll.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/reboot.h`.
- Detected declarations: `struct imx_wdt_hw_feature`, `struct imx7ulp_wdt_device`, `function imx7ulp_wdt_wait_ulk`, `function imx7ulp_wdt_wait_rcs`, `function _imx7ulp_wdt_enable`, `function imx7ulp_wdt_enable`, `function imx7ulp_wdt_ping`, `function imx7ulp_wdt_start`, `function imx7ulp_wdt_stop`, `function _imx7ulp_wdt_set_timeout`.
- 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.