drivers/watchdog/nct6694_wdt.c

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

File Facts

System
Linux kernel
Corpus path
drivers/watchdog/nct6694_wdt.c
Extension
.c
Size
7825 bytes
Lines
308
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 nct6694_wdt_data {
	struct watchdog_device wdev;
	struct device *dev;
	struct nct6694 *nct6694;
	union nct6694_wdt_msg *msg;
	unsigned char wdev_idx;
};

static int nct6694_wdt_setting(struct watchdog_device *wdev,
			       u32 timeout_val, u8 timeout_act,
			       u32 pretimeout_val, u8 pretimeout_act)
{
	struct nct6694_wdt_data *data = watchdog_get_drvdata(wdev);
	struct nct6694_wdt_setup *setup = &data->msg->setup;
	const struct nct6694_cmd_header cmd_hd = {
		.mod = NCT6694_WDT_MOD,
		.cmd = NCT6694_WDT_SETUP,
		.sel = NCT6694_WDT_SETUP_SEL(data->wdev_idx),
		.len = cpu_to_le16(sizeof(*setup))
	};
	unsigned int timeout_fmt, pretimeout_fmt;

	if (pretimeout_val == 0)
		pretimeout_act = NCT6694_ACTION_NONE;

	timeout_fmt = (timeout_val * 1000) | (timeout_act << 24);
	pretimeout_fmt = (pretimeout_val * 1000) | (pretimeout_act << 24);

	memset(setup, 0, sizeof(*setup));
	setup->timeout = cpu_to_le32(timeout_fmt);
	setup->pretimeout = cpu_to_le32(pretimeout_fmt);

	return nct6694_write_msg(data->nct6694, &cmd_hd, setup);
}

static int nct6694_wdt_start(struct watchdog_device *wdev)
{
	struct nct6694_wdt_data *data = watchdog_get_drvdata(wdev);
	int ret;

	ret = nct6694_wdt_setting(wdev, wdev->timeout, NCT6694_ACTION_GPO,
				  wdev->pretimeout, NCT6694_ACTION_GPO);
	if (ret)
		return ret;

	dev_dbg(data->dev, "Setting WDT(%d): timeout = %d, pretimeout = %d\n",
		data->wdev_idx, wdev->timeout, wdev->pretimeout);

	return ret;
}

static int nct6694_wdt_stop(struct watchdog_device *wdev)
{
	struct nct6694_wdt_data *data = watchdog_get_drvdata(wdev);
	struct nct6694_wdt_cmd *cmd = &data->msg->cmd;
	const struct nct6694_cmd_header cmd_hd = {
		.mod = NCT6694_WDT_MOD,
		.cmd = NCT6694_WDT_COMMAND,
		.sel = NCT6694_WDT_COMMAND_SEL(data->wdev_idx),
		.len = cpu_to_le16(sizeof(*cmd))
	};

	memcpy(&cmd->wdt_cmd, "WDTC", 4);
	cmd->reserved = 0;

	return nct6694_write_msg(data->nct6694, &cmd_hd, cmd);
}

static int nct6694_wdt_ping(struct watchdog_device *wdev)
{
	struct nct6694_wdt_data *data = watchdog_get_drvdata(wdev);
	struct nct6694_wdt_cmd *cmd = &data->msg->cmd;
	const struct nct6694_cmd_header cmd_hd = {
		.mod = NCT6694_WDT_MOD,
		.cmd = NCT6694_WDT_COMMAND,
		.sel = NCT6694_WDT_COMMAND_SEL(data->wdev_idx),
		.len = cpu_to_le16(sizeof(*cmd))
	};

	memcpy(&cmd->wdt_cmd, "WDTS", 4);
	cmd->reserved = 0;

	return nct6694_write_msg(data->nct6694, &cmd_hd, cmd);
}

static int nct6694_wdt_set_timeout(struct watchdog_device *wdev,
				   unsigned int new_timeout)
{
	int ret;

Annotation

Implementation Notes