drivers/power/reset/tdx-ec-poweroff.c
Source file repositories/reference/linux-study-clean/drivers/power/reset/tdx-ec-poweroff.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/reset/tdx-ec-poweroff.c- Extension
.c- Size
- 4236 bytes
- Lines
- 170
- Domain
- Driver Families
- Bucket
- drivers/power
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/array_size.hlinux/bug.hlinux/delay.hlinux/device.hlinux/dev_printk.hlinux/err.hlinux/i2c.hlinux/mod_devicetable.hlinux/module.hlinux/reboot.hlinux/regmap.hlinux/types.h
Detected Declarations
function tdx_ec_cmdfunction tdx_ec_power_offfunction tdx_ec_restartfunction tdx_ec_register_power_off_restartfunction tdx_ec_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Toradex Embedded Controller driver
*
* Copyright (C) 2025 Toradex
*
* Author: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>
*/
#include <linux/array_size.h>
#include <linux/bug.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/dev_printk.h>
#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/reboot.h>
#include <linux/regmap.h>
#include <linux/types.h>
#define EC_CHIP_ID_REG 0x00
#define EC_CHIP_ID_SMARC_IMX95 0x11
#define EC_CHIP_ID_SMARC_IMX8MP 0x12
#define EC_VERSION_REG_MAJOR 0x01
#define EC_VERSION_REG_MINOR 0x02
#define EC_ID_VERSION_LEN 3
#define EC_CMD_REG 0xD0
#define EC_CMD_POWEROFF 0x01
#define EC_CMD_RESET 0x02
#define EC_REG_MAX 0xD0
#define EC_CMD_TIMEOUT_MS 1000
static const struct regmap_range volatile_ranges[] = {
regmap_reg_range(EC_CMD_REG, EC_CMD_REG),
};
static const struct regmap_access_table volatile_table = {
.yes_ranges = volatile_ranges,
.n_yes_ranges = ARRAY_SIZE(volatile_ranges),
};
static const struct regmap_range read_ranges[] = {
regmap_reg_range(EC_CHIP_ID_REG, EC_VERSION_REG_MINOR),
};
static const struct regmap_access_table read_table = {
.yes_ranges = read_ranges,
.n_yes_ranges = ARRAY_SIZE(read_ranges),
};
static const struct regmap_config regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = EC_REG_MAX,
.cache_type = REGCACHE_RBTREE,
.rd_table = &read_table,
.volatile_table = &volatile_table,
};
static int tdx_ec_cmd(struct regmap *regmap, u8 cmd)
{
int err = regmap_write(regmap, EC_CMD_REG, cmd);
if (err)
dev_err(regmap_get_device(regmap), "Failed to send command 0x%02X: %d\n", cmd, err);
return err;
}
static int tdx_ec_power_off(struct sys_off_data *data)
{
struct regmap *regmap = data->cb_data;
int err;
err = tdx_ec_cmd(regmap, EC_CMD_POWEROFF);
if (err) {
dev_err(data->dev, "Failed to send power off command\n");
} else {
mdelay(EC_CMD_TIMEOUT_MS);
WARN_ONCE(1, "Unable to power off system\n");
}
return err ? NOTIFY_BAD : NOTIFY_DONE;
Annotation
- Immediate include surface: `linux/array_size.h`, `linux/bug.h`, `linux/delay.h`, `linux/device.h`, `linux/dev_printk.h`, `linux/err.h`, `linux/i2c.h`, `linux/mod_devicetable.h`.
- Detected declarations: `function tdx_ec_cmd`, `function tdx_ec_power_off`, `function tdx_ec_restart`, `function tdx_ec_register_power_off_restart`, `function tdx_ec_probe`.
- Atlas domain: Driver Families / drivers/power.
- 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.