drivers/input/keyboard/snvs_pwrkey.c
Source file repositories/reference/linux-study-clean/drivers/input/keyboard/snvs_pwrkey.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/keyboard/snvs_pwrkey.c- Extension
.c- Size
- 6331 bytes
- Lines
- 249
- 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/clk.hlinux/device.hlinux/err.hlinux/init.hlinux/input.hlinux/interrupt.hlinux/io.hlinux/jiffies.hlinux/kernel.hlinux/module.hlinux/of.hlinux/of_address.hlinux/platform_device.hlinux/pm_wakeirq.hlinux/mfd/syscon.hlinux/regmap.h
Detected Declarations
struct pwrkey_drv_datafunction imx_imx_snvs_check_for_eventsfunction imx_snvs_pwrkey_interruptfunction imx_snvs_pwrkey_actfunction imx_snvs_pwrkey_probe
Annotated Snippet
struct pwrkey_drv_data {
struct regmap *snvs;
int irq;
int keycode;
int keystate; /* 1:pressed */
int wakeup;
struct timer_list check_timer;
struct input_dev *input;
u8 minor_rev;
};
static void imx_imx_snvs_check_for_events(struct timer_list *t)
{
struct pwrkey_drv_data *pdata = timer_container_of(pdata, t,
check_timer);
struct input_dev *input = pdata->input;
u32 state;
regmap_read(pdata->snvs, SNVS_HPSR_REG, &state);
state = state & SNVS_HPSR_BTN ? 1 : 0;
/* only report new event if status changed */
if (state ^ pdata->keystate) {
pdata->keystate = state;
input_event(input, EV_KEY, pdata->keycode, state);
input_sync(input);
pm_relax(pdata->input->dev.parent);
}
/* repeat check if pressed long */
if (state) {
mod_timer(&pdata->check_timer,
jiffies + msecs_to_jiffies(REPEAT_INTERVAL));
}
}
static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id)
{
struct platform_device *pdev = dev_id;
struct pwrkey_drv_data *pdata = platform_get_drvdata(pdev);
struct input_dev *input = pdata->input;
u32 lp_status;
pm_wakeup_event(input->dev.parent, 0);
regmap_read(pdata->snvs, SNVS_LPSR_REG, &lp_status);
if (lp_status & SNVS_LPSR_SPO) {
if (pdata->minor_rev == 0) {
/*
* The first generation i.MX6 SoCs only sends an
* interrupt on button release. To mimic power-key
* usage, we'll prepend a press event.
*/
input_report_key(input, pdata->keycode, 1);
input_sync(input);
input_report_key(input, pdata->keycode, 0);
input_sync(input);
pm_relax(input->dev.parent);
} else {
mod_timer(&pdata->check_timer,
jiffies + msecs_to_jiffies(DEBOUNCE_TIME));
}
}
/* clear SPO status */
regmap_write(pdata->snvs, SNVS_LPSR_REG, SNVS_LPSR_SPO);
return IRQ_HANDLED;
}
static void imx_snvs_pwrkey_act(void *pdata)
{
struct pwrkey_drv_data *pd = pdata;
timer_delete_sync(&pd->check_timer);
}
static int imx_snvs_pwrkey_probe(struct platform_device *pdev)
{
struct pwrkey_drv_data *pdata;
struct input_dev *input;
struct device_node *np;
struct clk *clk;
int error;
unsigned int val;
unsigned int bpt;
u32 vid;
/* Get SNVS register Page */
np = pdev->dev.of_node;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/device.h`, `linux/err.h`, `linux/init.h`, `linux/input.h`, `linux/interrupt.h`, `linux/io.h`, `linux/jiffies.h`.
- Detected declarations: `struct pwrkey_drv_data`, `function imx_imx_snvs_check_for_events`, `function imx_snvs_pwrkey_interrupt`, `function imx_snvs_pwrkey_act`, `function imx_snvs_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.