drivers/power/reset/syscon-poweroff.c
Source file repositories/reference/linux-study-clean/drivers/power/reset/syscon-poweroff.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/reset/syscon-poweroff.c- Extension
.c- Size
- 2393 bytes
- Lines
- 99
- 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.
- 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/delay.hlinux/io.hlinux/notifier.hlinux/mfd/syscon.hlinux/of.hlinux/platform_device.hlinux/pm.hlinux/reboot.hlinux/regmap.h
Detected Declarations
struct syscon_poweroff_datafunction syscon_powerofffunction syscon_poweroff_probe
Annotated Snippet
struct syscon_poweroff_data {
struct regmap *map;
u32 offset;
u32 value;
u32 mask;
};
static int syscon_poweroff(struct sys_off_data *off_data)
{
struct syscon_poweroff_data *data = off_data->cb_data;
/* Issue the poweroff */
regmap_update_bits(data->map, data->offset, data->mask, data->value);
mdelay(1000);
pr_emerg("Unable to poweroff system\n");
return NOTIFY_DONE;
}
static int syscon_poweroff_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct syscon_poweroff_data *data;
int mask_err, value_err;
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
data->map = syscon_regmap_lookup_by_phandle(dev->of_node, "regmap");
if (IS_ERR(data->map)) {
data->map = syscon_node_to_regmap(dev->parent->of_node);
if (IS_ERR(data->map)) {
dev_err(dev, "unable to get syscon");
return PTR_ERR(data->map);
}
}
if (of_property_read_u32(dev->of_node, "offset", &data->offset)) {
dev_err(dev, "unable to read 'offset'");
return -EINVAL;
}
value_err = of_property_read_u32(dev->of_node, "value", &data->value);
mask_err = of_property_read_u32(dev->of_node, "mask", &data->mask);
if (value_err && mask_err) {
dev_err(dev, "unable to read 'value' and 'mask'");
return -EINVAL;
}
if (value_err) {
/* support old binding */
data->value = data->mask;
data->mask = 0xFFFFFFFF;
} else if (mask_err) {
/* support value without mask*/
data->mask = 0xFFFFFFFF;
}
return devm_register_sys_off_handler(&pdev->dev,
SYS_OFF_MODE_POWER_OFF,
SYS_OFF_PRIO_DEFAULT,
syscon_poweroff, data);
}
static const struct of_device_id syscon_poweroff_of_match[] = {
{ .compatible = "syscon-poweroff" },
{}
};
static struct platform_driver syscon_poweroff_driver = {
.probe = syscon_poweroff_probe,
.driver = {
.name = "syscon-poweroff",
.of_match_table = syscon_poweroff_of_match,
},
};
builtin_platform_driver(syscon_poweroff_driver);
Annotation
- Immediate include surface: `linux/delay.h`, `linux/io.h`, `linux/notifier.h`, `linux/mfd/syscon.h`, `linux/of.h`, `linux/platform_device.h`, `linux/pm.h`, `linux/reboot.h`.
- Detected declarations: `struct syscon_poweroff_data`, `function syscon_poweroff`, `function syscon_poweroff_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.