drivers/watchdog/mt7621_wdt.c

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

File Facts

System
Linux kernel
Corpus path
drivers/watchdog/mt7621_wdt.c
Extension
.c
Size
5834 bytes
Lines
230
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 mt7621_wdt_data {
	void __iomem *base;
	struct reset_control *rst;
	struct regmap *sysc;
	struct watchdog_device wdt;
};

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 inline void rt_wdt_w32(void __iomem *base, unsigned int reg, u32 val)
{
	iowrite32(val, base + reg);
}

static inline u32 rt_wdt_r32(void __iomem *base, unsigned int reg)
{
	return ioread32(base + reg);
}

static int mt7621_wdt_ping(struct watchdog_device *w)
{
	struct mt7621_wdt_data *drvdata = watchdog_get_drvdata(w);

	rt_wdt_w32(drvdata->base, TIMER_REG_TMRSTAT, TMR1CTL_RESTART);

	return 0;
}

static int mt7621_wdt_set_timeout(struct watchdog_device *w, unsigned int t)
{
	struct mt7621_wdt_data *drvdata = watchdog_get_drvdata(w);

	w->timeout = t;
	rt_wdt_w32(drvdata->base, TIMER_REG_TMR1LOAD, t * 1000);
	mt7621_wdt_ping(w);

	return 0;
}

static int mt7621_wdt_start(struct watchdog_device *w)
{
	struct mt7621_wdt_data *drvdata = watchdog_get_drvdata(w);
	u32 t;

	/* set the prescaler to 1ms == 1000us */
	rt_wdt_w32(drvdata->base, TIMER_REG_TMR1CTL, 1000 << TMR1CTL_PRESCALE_SHIFT);

	mt7621_wdt_set_timeout(w, w->timeout);

	t = rt_wdt_r32(drvdata->base, TIMER_REG_TMR1CTL);
	t |= TMR1CTL_ENABLE;
	rt_wdt_w32(drvdata->base, TIMER_REG_TMR1CTL, t);

	return 0;
}

static int mt7621_wdt_stop(struct watchdog_device *w)
{
	struct mt7621_wdt_data *drvdata = watchdog_get_drvdata(w);
	u32 t;

	mt7621_wdt_ping(w);

	t = rt_wdt_r32(drvdata->base, TIMER_REG_TMR1CTL);
	t &= ~TMR1CTL_ENABLE;
	rt_wdt_w32(drvdata->base, TIMER_REG_TMR1CTL, t);

	return 0;
}

static int mt7621_wdt_bootcause(struct mt7621_wdt_data *d)
{
	u32 val;

	regmap_read(d->sysc, SYSC_RSTSTAT, &val);
	if (val & WDT_RST_CAUSE)
		return WDIOF_CARDRESET;

	return 0;
}

static int mt7621_wdt_is_running(struct watchdog_device *w)
{
	struct mt7621_wdt_data *drvdata = watchdog_get_drvdata(w);

	return !!(rt_wdt_r32(drvdata->base, TIMER_REG_TMR1CTL) & TMR1CTL_ENABLE);

Annotation

Implementation Notes