drivers/watchdog/menf21bmc_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/menf21bmc_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/menf21bmc_wdt.c- Extension
.c- Size
- 4882 bytes
- Lines
- 185
- 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.
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/device.hlinux/module.hlinux/watchdog.hlinux/platform_device.hlinux/i2c.h
Detected Declarations
struct menf21bmc_wdtfunction menf21bmc_wdt_set_bootstatusfunction menf21bmc_wdt_startfunction menf21bmc_wdt_stopfunction menf21bmc_wdt_settimeoutfunction menf21bmc_wdt_pingfunction menf21bmc_wdt_probefunction menf21bmc_wdt_shutdown
Annotated Snippet
struct menf21bmc_wdt {
struct watchdog_device wdt;
struct i2c_client *i2c_client;
};
static int menf21bmc_wdt_set_bootstatus(struct menf21bmc_wdt *data)
{
int rst_rsn;
rst_rsn = i2c_smbus_read_byte_data(data->i2c_client, BMC_CMD_RST_RSN);
if (rst_rsn < 0)
return rst_rsn;
if (rst_rsn == 0x02)
data->wdt.bootstatus |= WDIOF_CARDRESET;
else if (rst_rsn == 0x05)
data->wdt.bootstatus |= WDIOF_EXTERN1;
else if (rst_rsn == 0x06)
data->wdt.bootstatus |= WDIOF_EXTERN2;
else if (rst_rsn == 0x0A)
data->wdt.bootstatus |= WDIOF_POWERUNDER;
return 0;
}
static int menf21bmc_wdt_start(struct watchdog_device *wdt)
{
struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
return i2c_smbus_write_byte(drv_data->i2c_client, BMC_CMD_WD_ON);
}
static int menf21bmc_wdt_stop(struct watchdog_device *wdt)
{
struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
return i2c_smbus_write_byte_data(drv_data->i2c_client,
BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
}
static int
menf21bmc_wdt_settimeout(struct watchdog_device *wdt, unsigned int timeout)
{
int ret;
struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
/*
* BMC Watchdog does have a resolution of 100ms.
* Watchdog API defines the timeout in seconds, so we have to
* multiply the value.
*/
ret = i2c_smbus_write_word_data(drv_data->i2c_client,
BMC_CMD_WD_TIME, timeout * 10);
if (ret < 0)
return ret;
wdt->timeout = timeout;
return 0;
}
static int menf21bmc_wdt_ping(struct watchdog_device *wdt)
{
struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
return i2c_smbus_write_byte(drv_data->i2c_client, BMC_CMD_WD_TRIG);
}
static const struct watchdog_info menf21bmc_wdt_info = {
.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
.identity = DEVNAME,
};
static const struct watchdog_ops menf21bmc_wdt_ops = {
.owner = THIS_MODULE,
.start = menf21bmc_wdt_start,
.stop = menf21bmc_wdt_stop,
.ping = menf21bmc_wdt_ping,
.set_timeout = menf21bmc_wdt_settimeout,
};
static int menf21bmc_wdt_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
int ret, bmc_timeout;
struct menf21bmc_wdt *drv_data;
struct i2c_client *i2c_client = to_i2c_client(dev->parent);
drv_data = devm_kzalloc(dev, sizeof(struct menf21bmc_wdt), GFP_KERNEL);
if (!drv_data)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/device.h`, `linux/module.h`, `linux/watchdog.h`, `linux/platform_device.h`, `linux/i2c.h`.
- Detected declarations: `struct menf21bmc_wdt`, `function menf21bmc_wdt_set_bootstatus`, `function menf21bmc_wdt_start`, `function menf21bmc_wdt_stop`, `function menf21bmc_wdt_settimeout`, `function menf21bmc_wdt_ping`, `function menf21bmc_wdt_probe`, `function menf21bmc_wdt_shutdown`.
- Atlas domain: Driver Families / drivers/watchdog.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.