drivers/power/reset/qnap-poweroff.c
Source file repositories/reference/linux-study-clean/drivers/power/reset/qnap-poweroff.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/reset/qnap-poweroff.c- Extension
.c- Size
- 3191 bytes
- Lines
- 132
- 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/kernel.hlinux/module.hlinux/platform_device.hlinux/serial_reg.hlinux/of.hlinux/io.hlinux/clk.h
Detected Declarations
struct power_off_cfgfunction qnap_power_offfunction qnap_power_off_probefunction qnap_power_off_remove
Annotated Snippet
struct power_off_cfg {
u32 baud;
char cmd;
};
static const struct power_off_cfg qnap_power_off_cfg = {
.baud = 19200,
.cmd = 'A',
};
static const struct power_off_cfg synology_power_off_cfg = {
.baud = 9600,
.cmd = '1',
};
static const struct of_device_id qnap_power_off_of_match_table[] = {
{ .compatible = "qnap,power-off",
.data = &qnap_power_off_cfg,
},
{ .compatible = "synology,power-off",
.data = &synology_power_off_cfg,
},
{}
};
MODULE_DEVICE_TABLE(of, qnap_power_off_of_match_table);
static void __iomem *base;
static unsigned long tclk;
static const struct power_off_cfg *cfg;
static void qnap_power_off(void)
{
const unsigned divisor = ((tclk + (8 * cfg->baud)) / (16 * cfg->baud));
pr_err("%s: triggering power-off...\n", __func__);
/* hijack UART1 and reset into sane state */
writel(0x83, UART1_REG(LCR));
writel(divisor & 0xff, UART1_REG(DLL));
writel((divisor >> 8) & 0xff, UART1_REG(DLM));
writel(0x03, UART1_REG(LCR));
writel(0x00, UART1_REG(IER));
writel(0x00, UART1_REG(FCR));
writel(0x00, UART1_REG(MCR));
/* send the power-off command to PIC */
writel(cfg->cmd, UART1_REG(TX));
}
static int qnap_power_off_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
struct resource *res;
struct clk *clk;
const struct of_device_id *match =
of_match_node(qnap_power_off_of_match_table, np);
cfg = match->data;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(&pdev->dev, "Missing resource");
return -EINVAL;
}
base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
if (!base) {
dev_err(&pdev->dev, "Unable to map resource");
return -EINVAL;
}
/* We need to know tclk in order to calculate the UART divisor */
clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(clk)) {
dev_err(&pdev->dev, "Clk missing");
return PTR_ERR(clk);
}
tclk = clk_get_rate(clk);
/* Check that nothing else has already setup a handler */
if (pm_power_off) {
dev_err(&pdev->dev, "pm_power_off already claimed for %ps",
pm_power_off);
return -EBUSY;
}
pm_power_off = qnap_power_off;
return 0;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/platform_device.h`, `linux/serial_reg.h`, `linux/of.h`, `linux/io.h`, `linux/clk.h`.
- Detected declarations: `struct power_off_cfg`, `function qnap_power_off`, `function qnap_power_off_probe`, `function qnap_power_off_remove`.
- 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.