drivers/watchdog/kempld_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/kempld_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/kempld_wdt.c- Extension
.c- Size
- 13903 bytes
- Lines
- 546
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/uaccess.hlinux/watchdog.hlinux/platform_device.hlinux/mfd/kempld.h
Detected Declarations
struct kempld_wdt_stagestruct kempld_wdt_datafunction kempld_wdt_set_stage_actionfunction kempld_wdt_set_stage_timeoutfunction kempld_wdt_get_timeoutfunction kempld_wdt_set_timeoutfunction kempld_wdt_set_pretimeoutfunction kempld_wdt_update_timeoutsfunction kempld_wdt_startfunction kempld_wdt_stopfunction kempld_wdt_keepalivefunction kempld_wdt_ioctlfunction kempld_wdt_probe_stagesfunction kempld_wdt_probefunction kempld_wdt_suspendfunction kempld_wdt_resume
Annotated Snippet
struct kempld_wdt_stage {
unsigned int id;
u32 mask;
};
struct kempld_wdt_data {
struct kempld_device_data *pld;
struct watchdog_device wdd;
unsigned int pretimeout;
struct kempld_wdt_stage stage[KEMPLD_WDT_MAX_STAGES];
u8 pm_status_store;
};
#define DEFAULT_TIMEOUT 30 /* seconds */
#define DEFAULT_PRETIMEOUT 0
static unsigned int timeout = DEFAULT_TIMEOUT;
module_param(timeout, uint, 0);
MODULE_PARM_DESC(timeout,
"Watchdog timeout in seconds. (>=0, default="
__MODULE_STRING(DEFAULT_TIMEOUT) ")");
static unsigned int pretimeout = DEFAULT_PRETIMEOUT;
module_param(pretimeout, uint, 0);
MODULE_PARM_DESC(pretimeout,
"Watchdog pretimeout in seconds. (>=0, default="
__MODULE_STRING(DEFAULT_PRETIMEOUT) ")");
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 int kempld_wdt_set_stage_action(struct kempld_wdt_data *wdt_data,
struct kempld_wdt_stage *stage,
u8 action)
{
struct kempld_device_data *pld = wdt_data->pld;
u8 stage_cfg;
if (!stage || !stage->mask)
return -EINVAL;
kempld_get_mutex(pld);
stage_cfg = kempld_read8(pld, KEMPLD_WDT_STAGE_CFG(stage->id));
stage_cfg &= ~STAGE_CFG_ACTION_MASK;
stage_cfg |= (action & STAGE_CFG_ACTION_MASK);
if (action == ACTION_RESET)
stage_cfg |= STAGE_CFG_ASSERT;
else
stage_cfg &= ~STAGE_CFG_ASSERT;
kempld_write8(pld, KEMPLD_WDT_STAGE_CFG(stage->id), stage_cfg);
kempld_release_mutex(pld);
return 0;
}
static int kempld_wdt_set_stage_timeout(struct kempld_wdt_data *wdt_data,
struct kempld_wdt_stage *stage,
unsigned int timeout)
{
struct kempld_device_data *pld = wdt_data->pld;
u32 prescaler;
u64 stage_timeout64;
u32 stage_timeout;
u32 remainder;
u8 stage_cfg;
prescaler = kempld_prescaler[PRESCALER_21];
if (!stage)
return -EINVAL;
stage_timeout64 = (u64)timeout * pld->pld_clock;
remainder = do_div(stage_timeout64, prescaler);
if (remainder)
stage_timeout64++;
if (stage_timeout64 > stage->mask)
return -EINVAL;
stage_timeout = stage_timeout64 & stage->mask;
kempld_get_mutex(pld);
stage_cfg = kempld_read8(pld, KEMPLD_WDT_STAGE_CFG(stage->id));
stage_cfg &= ~STAGE_CFG_PRESCALER_MASK;
stage_cfg |= STAGE_CFG_SET_PRESCALER(PRESCALER_21);
Annotation
- Immediate include surface: `linux/module.h`, `linux/moduleparam.h`, `linux/uaccess.h`, `linux/watchdog.h`, `linux/platform_device.h`, `linux/mfd/kempld.h`.
- Detected declarations: `struct kempld_wdt_stage`, `struct kempld_wdt_data`, `function kempld_wdt_set_stage_action`, `function kempld_wdt_set_stage_timeout`, `function kempld_wdt_get_timeout`, `function kempld_wdt_set_timeout`, `function kempld_wdt_set_pretimeout`, `function kempld_wdt_update_timeouts`, `function kempld_wdt_start`, `function kempld_wdt_stop`.
- Atlas domain: Driver Families / drivers/watchdog.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.