drivers/watchdog/npcm_wdt.c

Source file repositories/reference/linux-study-clean/drivers/watchdog/npcm_wdt.c

File Facts

System
Linux kernel
Corpus path
drivers/watchdog/npcm_wdt.c
Extension
.c
Size
6040 bytes
Lines
264
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct npcm_wdt {
	struct watchdog_device  wdd;
	void __iomem		*reg;
	struct clk		*clk;
};

static inline struct npcm_wdt *to_npcm_wdt(struct watchdog_device *wdd)
{
	return container_of(wdd, struct npcm_wdt, wdd);
}

static int npcm_wdt_ping(struct watchdog_device *wdd)
{
	struct npcm_wdt *wdt = to_npcm_wdt(wdd);
	u32 val;

	val = readl(wdt->reg);
	writel(val | NPCM_WTR, wdt->reg);

	return 0;
}

static int npcm_wdt_start(struct watchdog_device *wdd)
{
	struct npcm_wdt *wdt = to_npcm_wdt(wdd);
	u32 val;

	clk_prepare_enable(wdt->clk);

	if (wdd->timeout < 2)
		val = 0x800;
	else if (wdd->timeout < 3)
		val = 0x420;
	else if (wdd->timeout < 6)
		val = 0x810;
	else if (wdd->timeout < 11)
		val = 0x430;
	else if (wdd->timeout < 22)
		val = 0x820;
	else if (wdd->timeout < 44)
		val = 0xC00;
	else if (wdd->timeout < 87)
		val = 0x830;
	else if (wdd->timeout < 173)
		val = 0xC10;
	else if (wdd->timeout < 688)
		val = 0xC20;
	else
		val = 0xC30;

	val |= NPCM_WTRE | NPCM_WTE | NPCM_WTR | NPCM_WTIE;

	writel(val, wdt->reg);

	return 0;
}

static int npcm_wdt_stop(struct watchdog_device *wdd)
{
	struct npcm_wdt *wdt = to_npcm_wdt(wdd);

	writel(0, wdt->reg);

	clk_disable_unprepare(wdt->clk);

	return 0;
}

static int npcm_wdt_set_timeout(struct watchdog_device *wdd,
				unsigned int timeout)
{
	if (timeout < 2)
		wdd->timeout = 1;
	else if (timeout < 3)
		wdd->timeout = 2;
	else if (timeout < 6)
		wdd->timeout = 5;
	else if (timeout < 11)
		wdd->timeout = 10;
	else if (timeout < 22)
		wdd->timeout = 21;
	else if (timeout < 44)
		wdd->timeout = 43;
	else if (timeout < 87)
		wdd->timeout = 86;
	else if (timeout < 173)
		wdd->timeout = 172;
	else if (timeout < 688)
		wdd->timeout = 687;
	else

Annotation

Implementation Notes