drivers/watchdog/atcwdt200_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/atcwdt200_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/atcwdt200_wdt.c- Extension
.c- Size
- 16077 bytes
- Lines
- 581
- 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/bitfield.hlinux/clk.hlinux/device.hlinux/dev_printk.hlinux/math64.hlinux/minmax.hlinux/moduleparam.hlinux/module.hlinux/of.hlinux/of_platform.hlinux/platform_device.hlinux/pm.hlinux/pm_runtime.hlinux/regmap.hlinux/watchdog.h
Detected Declarations
struct atcwdt_drvenum timer_typefunction atcwdt_get_indexfunction atcwdt_get_clock_periodfunction atcwdt_get_timeout_paramsfunction atcwdt_get_int_timer_typefunction atcwdt_pingfunction atcwdt_set_timeoutfunction atcwdt_startfunction atcwdt_stopfunction atcwdt_restartfunction atcwdt_init_resourcefunction atcwdt_enable_clkfunction atcwdt_init_wdt_devicefunction atcwdt_calc_max_timeoutfunction atcwdt_probefunction atcwdt_suspendfunction atcwdt_resume
Annotated Snippet
struct atcwdt_drv {
struct watchdog_device wdt_dev;
struct regmap *regmap;
struct clk *clk;
spinlock_t lock;
unsigned int clk_freq;
unsigned char clk_src;
unsigned char int_timer_type;
};
static const struct watchdog_info atcwdt_info = {
.identity = DRV_NAME,
.options = WDIOF_SETTIMEOUT |
WDIOF_KEEPALIVEPING |
WDIOF_MAGICCLOSE,
};
/**
* atcwdt_get_index - Get the interval value for the specified timer type
* @index: The index of the interval in the array
* @timer_type: The type of timer, which can be TMR_RST, TMR_INT_16, or
* TMR_INT_32.
*
* This function retrieves the interval value based on the timer type and
* ensures the index stays within the valid range for the given timer type.
* For TMR_RST:
* - The maximum array size is 8 (index range: 0-7).
* For TMR_INT_16:
* - The maximum array size is 8 (index range: 0-7).
* For TMR_INT_32:
* - The maximum array size is 16 (index range: 0-15).
*
* If the index exceeds the maximum array size, the function will return
* the last element of the respective array.
*/
static inline unsigned char atcwdt_get_index(unsigned char index,
enum timer_type timer_type)
{
static const unsigned char rst_timer_interval[TMR_SZ_RST] = {
7, 8, 9, 10, 11, 12, 13, 14};
static const unsigned char int_timer_interval[TMR_SZ_INT_32] = {
6, 8, 10, 11, 12, 13, 14, 15, 17, 19, 21, 23, 25, 27, 29, 31};
unsigned char array_index;
if (timer_type == TMR_RST) {
array_index = min(index, TMR_SZ_RST - 1);
return rst_timer_interval[array_index];
}
if (timer_type == TMR_INT_32)
array_index = min(index, TMR_SZ_INT_32 - 1);
else
array_index = min(index, TMR_SZ_INT_16 - 1);
return int_timer_interval[array_index];
}
/**
* atcwdt_get_clock_period - Calculate the closest clock period based on a
* given tick count
* @tick: The target tick count to match
* @timer_type: The type of timer, which can be TMR_RST, TMR_INT_16, or
* TMR_INT_32.
* @index: Pointer to store the index of the selected parameter
*
* This function calculates the closest clock period to the given tick count
* by iterating through the timer parameters and selecting the one that
* minimizes the difference between the target tick count and the calculated
* clock period. The function determines the index of the closest parameter
* and returns the difference between the target tick count and the selected
* clock period.
*
* Return: The difference between the target tick count and the selected
* clock period.
*/
static long long atcwdt_get_clock_period(long long tick,
enum timer_type timer_type,
unsigned char *index)
{
long long result;
unsigned char size;
char i;
if (timer_type == TMR_RST)
size = TMR_SZ_RST;
else if (timer_type == TMR_INT_32)
size = TMR_SZ_INT_32;
else
size = TMR_SZ_INT_16;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/clk.h`, `linux/device.h`, `linux/dev_printk.h`, `linux/math64.h`, `linux/minmax.h`, `linux/moduleparam.h`, `linux/module.h`.
- Detected declarations: `struct atcwdt_drv`, `enum timer_type`, `function atcwdt_get_index`, `function atcwdt_get_clock_period`, `function atcwdt_get_timeout_params`, `function atcwdt_get_int_timer_type`, `function atcwdt_ping`, `function atcwdt_set_timeout`, `function atcwdt_start`, `function atcwdt_stop`.
- 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.