drivers/watchdog/msc313e_wdt.c

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

File Facts

System
Linux kernel
Corpus path
drivers/watchdog/msc313e_wdt.c
Extension
.c
Size
4345 bytes
Lines
171
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 msc313e_wdt_priv {
	void __iomem *base;
	struct watchdog_device wdev;
	struct clk *clk;
};

static int msc313e_wdt_start(struct watchdog_device *wdev)
{
	struct msc313e_wdt_priv *priv = watchdog_get_drvdata(wdev);
	u32 timeout;
	int err;

	err = clk_prepare_enable(priv->clk);
	if (err)
		return err;

	timeout = wdev->timeout * clk_get_rate(priv->clk);
	writew(timeout & 0xffff, priv->base + REG_WDT_MAX_PRD_L);
	writew((timeout >> 16) & 0xffff, priv->base + REG_WDT_MAX_PRD_H);
	writew(1, priv->base + REG_WDT_CLR);
	return 0;
}

static int msc313e_wdt_ping(struct watchdog_device *wdev)
{
	struct msc313e_wdt_priv *priv = watchdog_get_drvdata(wdev);

	writew(1, priv->base + REG_WDT_CLR);
	return 0;
}

static int msc313e_wdt_stop(struct watchdog_device *wdev)
{
	struct msc313e_wdt_priv *priv = watchdog_get_drvdata(wdev);

	writew(0, priv->base + REG_WDT_MAX_PRD_L);
	writew(0, priv->base + REG_WDT_MAX_PRD_H);
	writew(0, priv->base + REG_WDT_CLR);
	clk_disable_unprepare(priv->clk);
	return 0;
}

static int msc313e_wdt_settimeout(struct watchdog_device *wdev, unsigned int new_time)
{
	wdev->timeout = new_time;

	return msc313e_wdt_start(wdev);
}

static const struct watchdog_info msc313e_wdt_ident = {
	.identity = "MSC313e watchdog",
	.options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT,
};

static const struct watchdog_ops msc313e_wdt_ops = {
	.owner = THIS_MODULE,
	.start = msc313e_wdt_start,
	.stop = msc313e_wdt_stop,
	.ping = msc313e_wdt_ping,
	.set_timeout = msc313e_wdt_settimeout,
};

static const struct of_device_id msc313e_wdt_of_match[] = {
	{ .compatible = "mstar,msc313e-wdt", },
	{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, msc313e_wdt_of_match);

static int msc313e_wdt_probe(struct platform_device *pdev)
{
	struct device *dev = &pdev->dev;
	struct msc313e_wdt_priv *priv;

	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

	priv->base = devm_platform_ioremap_resource(pdev, 0);
	if (IS_ERR(priv->base))
		return PTR_ERR(priv->base);

	priv->clk = devm_clk_get(dev, NULL);
	if (IS_ERR(priv->clk)) {
		dev_err(dev, "No input clock\n");
		return PTR_ERR(priv->clk);
	}

	priv->wdev.info = &msc313e_wdt_ident,
	priv->wdev.ops = &msc313e_wdt_ops,
	priv->wdev.parent = dev;

Annotation

Implementation Notes