drivers/input/misc/palmas-pwrbutton.c
Source file repositories/reference/linux-study-clean/drivers/input/misc/palmas-pwrbutton.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/misc/palmas-pwrbutton.c- Extension
.c- Size
- 8020 bytes
- Lines
- 326
- 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/bitfield.hlinux/init.hlinux/input.hlinux/interrupt.hlinux/kernel.hlinux/mfd/palmas.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/slab.h
Detected Declarations
struct palmas_pwronstruct palmas_pwron_configfunction palmas_power_button_workfunction pwron_irqfunction palmas_pwron_params_ofinitfunction palmas_pwron_probefunction palmas_pwron_removefunction palmas_pwron_suspendfunction palmas_pwron_resume
Annotated Snippet
struct palmas_pwron {
struct palmas *palmas;
struct input_dev *input_dev;
struct delayed_work input_work;
int irq;
};
/**
* struct palmas_pwron_config - configuration of palmas power on
* @long_press_time_val: value for long press h/w shutdown event
* @pwron_debounce_val: value for debounce of power button
*/
struct palmas_pwron_config {
u8 long_press_time_val;
u8 pwron_debounce_val;
};
/**
* palmas_power_button_work() - Detects the button release event
* @work: work item to detect button release
*/
static void palmas_power_button_work(struct work_struct *work)
{
struct palmas_pwron *pwron = container_of(work,
struct palmas_pwron,
input_work.work);
struct input_dev *input_dev = pwron->input_dev;
unsigned int reg;
int error;
error = palmas_read(pwron->palmas, PALMAS_INTERRUPT_BASE,
PALMAS_INT1_LINE_STATE, ®);
if (error) {
dev_err(input_dev->dev.parent,
"Cannot read palmas PWRON status: %d\n", error);
} else if (reg & BIT(1)) {
/* The button is released, report event. */
input_report_key(input_dev, KEY_POWER, 0);
input_sync(input_dev);
} else {
/* The button is still depressed, keep checking. */
schedule_delayed_work(&pwron->input_work,
msecs_to_jiffies(PALMAS_PWR_KEY_Q_TIME_MS));
}
}
/**
* pwron_irq() - button press isr
* @irq: irq
* @palmas_pwron: pwron struct
*
* Return: IRQ_HANDLED
*/
static irqreturn_t pwron_irq(int irq, void *palmas_pwron)
{
struct palmas_pwron *pwron = palmas_pwron;
struct input_dev *input_dev = pwron->input_dev;
input_report_key(input_dev, KEY_POWER, 1);
pm_wakeup_event(input_dev->dev.parent, 0);
input_sync(input_dev);
mod_delayed_work(system_dfl_wq, &pwron->input_work,
msecs_to_jiffies(PALMAS_PWR_KEY_Q_TIME_MS));
return IRQ_HANDLED;
}
/**
* palmas_pwron_params_ofinit() - device tree parameter parser
* @dev: palmas button device
* @config: configuration params that this fills up
*/
static void palmas_pwron_params_ofinit(struct device *dev,
struct palmas_pwron_config *config)
{
struct device_node *np;
u32 val;
int i, error;
static const u8 lpk_times[] = { 6, 8, 10, 12 };
static const int pwr_on_deb_ms[] = { 15, 100, 500, 1000 };
memset(config, 0, sizeof(*config));
/* Default config parameters */
config->long_press_time_val = ARRAY_SIZE(lpk_times) - 1;
np = dev->of_node;
if (!np)
return;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/init.h`, `linux/input.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/mfd/palmas.h`, `linux/module.h`, `linux/of.h`.
- Detected declarations: `struct palmas_pwron`, `struct palmas_pwron_config`, `function palmas_power_button_work`, `function pwron_irq`, `function palmas_pwron_params_ofinit`, `function palmas_pwron_probe`, `function palmas_pwron_remove`, `function palmas_pwron_suspend`, `function palmas_pwron_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.