drivers/input/misc/stpmic1_onkey.c
Source file repositories/reference/linux-study-clean/drivers/input/misc/stpmic1_onkey.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/misc/stpmic1_onkey.c- Extension
.c- Size
- 4986 bytes
- Lines
- 193
- 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/input.hlinux/interrupt.hlinux/mfd/stpmic1.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/property.hlinux/regmap.h
Detected Declarations
struct stpmic1_onkeyfunction onkey_falling_irqfunction onkey_rising_irqfunction stpmic1_onkey_probefunction stpmic1_onkey_suspendfunction stpmic1_onkey_resume
Annotated Snippet
struct stpmic1_onkey {
struct input_dev *input_dev;
int irq_falling;
int irq_rising;
};
static irqreturn_t onkey_falling_irq(int irq, void *ponkey)
{
struct stpmic1_onkey *onkey = ponkey;
struct input_dev *input_dev = onkey->input_dev;
input_report_key(input_dev, KEY_POWER, 1);
pm_wakeup_event(input_dev->dev.parent, 0);
input_sync(input_dev);
return IRQ_HANDLED;
}
static irqreturn_t onkey_rising_irq(int irq, void *ponkey)
{
struct stpmic1_onkey *onkey = ponkey;
struct input_dev *input_dev = onkey->input_dev;
input_report_key(input_dev, KEY_POWER, 0);
pm_wakeup_event(input_dev->dev.parent, 0);
input_sync(input_dev);
return IRQ_HANDLED;
}
static int stpmic1_onkey_probe(struct platform_device *pdev)
{
struct stpmic1 *pmic = dev_get_drvdata(pdev->dev.parent);
struct device *dev = &pdev->dev;
struct input_dev *input_dev;
struct stpmic1_onkey *onkey;
unsigned int val, reg = 0;
int error;
onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL);
if (!onkey)
return -ENOMEM;
onkey->irq_falling = platform_get_irq_byname(pdev, "onkey-falling");
if (onkey->irq_falling < 0)
return onkey->irq_falling;
onkey->irq_rising = platform_get_irq_byname(pdev, "onkey-rising");
if (onkey->irq_rising < 0)
return onkey->irq_rising;
if (!device_property_read_u32(dev, "power-off-time-sec", &val)) {
if (val > 0 && val <= 16) {
dev_dbg(dev, "power-off-time=%d seconds\n", val);
reg |= PONKEY_PWR_OFF;
reg |= ((16 - val) & PONKEY_TURNOFF_TIMER_MASK);
} else {
dev_err(dev, "power-off-time-sec out of range\n");
return -EINVAL;
}
}
if (device_property_present(dev, "st,onkey-clear-cc-flag"))
reg |= PONKEY_CC_FLAG_CLEAR;
error = regmap_update_bits(pmic->regmap, PKEY_TURNOFF_CR,
PONKEY_TURNOFF_MASK, reg);
if (error) {
dev_err(dev, "PKEY_TURNOFF_CR write failed: %d\n", error);
return error;
}
if (device_property_present(dev, "st,onkey-pu-inactive")) {
error = regmap_update_bits(pmic->regmap, PADS_PULL_CR,
PONKEY_PU_INACTIVE,
PONKEY_PU_INACTIVE);
if (error) {
dev_err(dev, "ONKEY Pads configuration failed: %d\n",
error);
return error;
}
}
input_dev = devm_input_allocate_device(dev);
if (!input_dev) {
dev_err(dev, "Can't allocate Pwr Onkey Input Device\n");
return -ENOMEM;
}
input_dev->name = "pmic_onkey";
Annotation
- Immediate include surface: `linux/input.h`, `linux/interrupt.h`, `linux/mfd/stpmic1.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/property.h`, `linux/regmap.h`.
- Detected declarations: `struct stpmic1_onkey`, `function onkey_falling_irq`, `function onkey_rising_irq`, `function stpmic1_onkey_probe`, `function stpmic1_onkey_suspend`, `function stpmic1_onkey_resume`.
- 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.