drivers/input/misc/rt5120-pwrkey.c
Source file repositories/reference/linux-study-clean/drivers/input/misc/rt5120-pwrkey.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/misc/rt5120-pwrkey.c- Extension
.c- Size
- 2928 bytes
- Lines
- 121
- Domain
- Driver Families
- Bucket
- drivers/input
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/bits.hlinux/input.hlinux/interrupt.hlinux/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.hlinux/regmap.h
Detected Declarations
struct rt5120_privfunction rt5120_pwrkey_handlerfunction rt5120_pwrkey_probe
Annotated Snippet
struct rt5120_priv {
struct regmap *regmap;
struct input_dev *input;
};
static irqreturn_t rt5120_pwrkey_handler(int irq, void *devid)
{
struct rt5120_priv *priv = devid;
unsigned int stat;
int error;
error = regmap_read(priv->regmap, RT5120_REG_INTSTAT, &stat);
if (error)
return IRQ_NONE;
input_report_key(priv->input, KEY_POWER,
!(stat & RT5120_PWRKEYSTAT_MASK));
input_sync(priv->input);
return IRQ_HANDLED;
}
static int rt5120_pwrkey_probe(struct platform_device *pdev)
{
struct rt5120_priv *priv;
struct device *dev = &pdev->dev;
int press_irq, release_irq;
int error;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
priv->regmap = dev_get_regmap(dev->parent, NULL);
if (!priv->regmap) {
dev_err(dev, "Failed to init regmap\n");
return -ENODEV;
}
press_irq = platform_get_irq_byname(pdev, "pwrkey-press");
if (press_irq < 0)
return press_irq;
release_irq = platform_get_irq_byname(pdev, "pwrkey-release");
if (release_irq < 0)
return release_irq;
/* Make input device be device resource managed */
priv->input = devm_input_allocate_device(dev);
if (!priv->input)
return -ENOMEM;
priv->input->name = "rt5120_pwrkey";
priv->input->phys = "rt5120_pwrkey/input0";
priv->input->id.bustype = BUS_I2C;
input_set_capability(priv->input, EV_KEY, KEY_POWER);
error = input_register_device(priv->input);
if (error) {
dev_err(dev, "Failed to register input device: %d\n", error);
return error;
}
error = devm_request_threaded_irq(dev, press_irq,
NULL, rt5120_pwrkey_handler,
0, "pwrkey-press", priv);
if (error) {
dev_err(dev,
"Failed to register pwrkey press irq: %d\n", error);
return error;
}
error = devm_request_threaded_irq(dev, release_irq,
NULL, rt5120_pwrkey_handler,
0, "pwrkey-release", priv);
if (error) {
dev_err(dev,
"Failed to register pwrkey release irq: %d\n", error);
return error;
}
return 0;
}
static const struct of_device_id r5120_pwrkey_match_table[] = {
{ .compatible = "richtek,rt5120-pwrkey" },
{}
};
MODULE_DEVICE_TABLE(of, r5120_pwrkey_match_table);
Annotation
- Immediate include surface: `linux/bits.h`, `linux/input.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`, `linux/regmap.h`.
- Detected declarations: `struct rt5120_priv`, `function rt5120_pwrkey_handler`, `function rt5120_pwrkey_probe`.
- Atlas domain: Driver Families / drivers/input.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.