drivers/watchdog/bcm_kona_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/bcm_kona_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/bcm_kona_wdt.c- Extension
.c- Size
- 8551 bytes
- Lines
- 340
- 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.
- 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/debugfs.hlinux/delay.hlinux/err.hlinux/io.hlinux/module.hlinux/of_address.hlinux/platform_device.hlinux/watchdog.h
Detected Declarations
struct bcm_kona_wdtfunction secure_register_readfunction bcm_kona_showfunction bcm_kona_wdt_debug_initfunction bcm_kona_wdt_debug_exitfunction bcm_kona_wdt_debug_initfunction bcm_kona_wdt_set_resolution_regfunction bcm_kona_wdt_set_timeout_regfunction bcm_kona_wdt_set_timeoutfunction bcm_kona_wdt_get_timeleftfunction bcm_kona_wdt_startfunction bcm_kona_wdt_stopfunction bcm_kona_wdt_probefunction bcm_kona_wdt_remove
Annotated Snippet
struct bcm_kona_wdt {
void __iomem *base;
/*
* One watchdog tick is 1/(2^resolution) seconds. Resolution can take
* the values 0-15, meaning one tick can be 1s to 30.52us. Our default
* resolution of 4 means one tick is 62.5ms.
*
* The watchdog counter is 20 bits. Depending on resolution, the maximum
* counter value of 0xfffff expires after about 12 days (resolution 0)
* down to only 32s (resolution 15). The default resolution of 4 gives
* us a maximum of about 18 hours and 12 minutes before the watchdog
* times out.
*/
int resolution;
spinlock_t lock;
#ifdef CONFIG_BCM_KONA_WDT_DEBUG
unsigned long busy_count;
struct dentry *debugfs;
#endif
};
static int secure_register_read(struct bcm_kona_wdt *wdt, uint32_t offset)
{
uint32_t val;
unsigned count = 0;
/*
* If the WD_LOAD_FLAG is set, the watchdog counter field is being
* updated in hardware. Once the WD timer is updated in hardware, it
* gets cleared.
*/
do {
if (unlikely(count > 1))
udelay(5);
val = readl_relaxed(wdt->base + offset);
count++;
} while ((val & SECWDOG_WD_LOAD_FLAG) && count < SECWDOG_MAX_TRY);
#ifdef CONFIG_BCM_KONA_WDT_DEBUG
/* Remember the maximum number iterations due to WD_LOAD_FLAG */
if (count > wdt->busy_count)
wdt->busy_count = count;
#endif
/* This is the only place we return a negative value. */
if (val & SECWDOG_WD_LOAD_FLAG)
return -ETIMEDOUT;
/* We always mask out reserved bits. */
val &= SECWDOG_RESERVED_MASK;
return val;
}
#ifdef CONFIG_BCM_KONA_WDT_DEBUG
static int bcm_kona_show(struct seq_file *s, void *data)
{
int ctl_val, cur_val;
unsigned long flags;
struct bcm_kona_wdt *wdt = s->private;
if (!wdt) {
seq_puts(s, "No device pointer\n");
return 0;
}
spin_lock_irqsave(&wdt->lock, flags);
ctl_val = secure_register_read(wdt, SECWDOG_CTRL_REG);
cur_val = secure_register_read(wdt, SECWDOG_COUNT_REG);
spin_unlock_irqrestore(&wdt->lock, flags);
if (ctl_val < 0 || cur_val < 0) {
seq_puts(s, "Error accessing hardware\n");
} else {
int ctl, cur, ctl_sec, cur_sec, res;
ctl = ctl_val & SECWDOG_COUNT_MASK;
res = (ctl_val & SECWDOG_RES_MASK) >> SECWDOG_CLKS_SHIFT;
cur = cur_val & SECWDOG_COUNT_MASK;
ctl_sec = TICKS_TO_SECS(ctl, wdt);
cur_sec = TICKS_TO_SECS(cur, wdt);
seq_printf(s,
"Resolution: %d / %d\n"
"Control: %d s / %d (%#x) ticks\n"
"Current: %d s / %d (%#x) ticks\n"
"Busy count: %lu\n",
res, wdt->resolution,
ctl_sec, ctl, ctl,
cur_sec, cur, cur,
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/delay.h`, `linux/err.h`, `linux/io.h`, `linux/module.h`, `linux/of_address.h`, `linux/platform_device.h`, `linux/watchdog.h`.
- Detected declarations: `struct bcm_kona_wdt`, `function secure_register_read`, `function bcm_kona_show`, `function bcm_kona_wdt_debug_init`, `function bcm_kona_wdt_debug_exit`, `function bcm_kona_wdt_debug_init`, `function bcm_kona_wdt_set_resolution_reg`, `function bcm_kona_wdt_set_timeout_reg`, `function bcm_kona_wdt_set_timeout`, `function bcm_kona_wdt_get_timeleft`.
- 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.