drivers/watchdog/arm_smc_wdt.c

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

File Facts

System
Linux kernel
Corpus path
drivers/watchdog/arm_smc_wdt.c
Extension
.c
Size
4518 bytes
Lines
200
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

// SPDX-License-Identifier: GPL-2.0-only
/*
 * ARM Secure Monitor Call watchdog driver
 *
 * Copyright 2020 Google LLC.
 * Julius Werner <jwerner@chromium.org>
 * Based on mtk_wdt.c
 */

#include <linux/arm-smccc.h>
#include <linux/err.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/types.h>
#include <linux/watchdog.h>
#include <uapi/linux/psci.h>

#define DRV_NAME		"arm_smc_wdt"
#define DRV_VERSION		"1.0"

enum smcwd_call {
	SMCWD_INIT		= 0,
	SMCWD_SET_TIMEOUT	= 1,
	SMCWD_ENABLE		= 2,
	SMCWD_PET		= 3,
	SMCWD_GET_TIMELEFT	= 4,
};

static bool nowayout = WATCHDOG_NOWAYOUT;
static unsigned int timeout;

static int smcwd_call(struct watchdog_device *wdd, enum smcwd_call call,
		      unsigned long arg, struct arm_smccc_res *res)
{
	struct arm_smccc_res local_res;

	if (!res)
		res = &local_res;

	arm_smccc_smc((u32)(uintptr_t)watchdog_get_drvdata(wdd), call, arg, 0,
		      0, 0, 0, 0, res);

	if (res->a0 == PSCI_RET_NOT_SUPPORTED)
		return -ENODEV;
	if (res->a0 == PSCI_RET_INVALID_PARAMS)
		return -EINVAL;
	if (res->a0 == PSCI_RET_DISABLED)
		return -ENODATA;
	if (res->a0 != PSCI_RET_SUCCESS)
		return -EIO;
	return 0;
}

static int smcwd_ping(struct watchdog_device *wdd)
{
	return smcwd_call(wdd, SMCWD_PET, 0, NULL);
}

static unsigned int smcwd_get_timeleft(struct watchdog_device *wdd)
{
	struct arm_smccc_res res;

	smcwd_call(wdd, SMCWD_GET_TIMELEFT, 0, &res);
	if (res.a0)
		return 0;
	return res.a1;
}

static int smcwd_set_timeout(struct watchdog_device *wdd, unsigned int timeout)
{
	int res;

	res = smcwd_call(wdd, SMCWD_SET_TIMEOUT, timeout, NULL);
	if (!res)
		wdd->timeout = timeout;
	return res;
}

static int smcwd_stop(struct watchdog_device *wdd)
{
	return smcwd_call(wdd, SMCWD_ENABLE, 0, NULL);
}

static int smcwd_start(struct watchdog_device *wdd)
{
	return smcwd_call(wdd, SMCWD_ENABLE, 1, NULL);
}

Annotation

Implementation Notes