drivers/input/misc/ariel-pwrbutton.c
Source file repositories/reference/linux-study-clean/drivers/input/misc/ariel-pwrbutton.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/misc/ariel-pwrbutton.c- Extension
.c- Size
- 4119 bytes
- Lines
- 171
- 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/device.hlinux/gfp.hlinux/input.hlinux/interrupt.hlinux/mod_devicetable.hlinux/module.hlinux/spi/spi.h
Detected Declarations
struct ec_input_responsestruct ariel_pwrbuttonfunction ec_input_readfunction ec_input_interruptfunction ariel_pwrbutton_probe
Annotated Snippet
struct ec_input_response {
u8 reserved;
u8 header;
u8 data[3];
} __packed;
struct ariel_pwrbutton {
struct spi_device *client;
struct input_dev *input;
u8 msg_counter;
};
static int ec_input_read(struct ariel_pwrbutton *priv,
struct ec_input_response *response)
{
u8 read_request[] = { 0x00, 0x5a, 0xa5, 0x00, 0x00 };
struct spi_device *spi = priv->client;
struct spi_transfer t = {
.tx_buf = read_request,
.rx_buf = response,
.len = sizeof(read_request),
};
compiletime_assert(sizeof(read_request) == sizeof(*response),
"SPI xfer request/response size mismatch");
return spi_sync_transfer(spi, &t, 1);
}
static irqreturn_t ec_input_interrupt(int irq, void *dev_id)
{
struct ariel_pwrbutton *priv = dev_id;
struct spi_device *spi = priv->client;
struct ec_input_response response;
int error;
int i;
error = ec_input_read(priv, &response);
if (error < 0) {
dev_err(&spi->dev, "EC read failed: %d\n", error);
goto out;
}
if (priv->msg_counter == RESP_COUNTER(response)) {
dev_warn(&spi->dev, "No new data to read?\n");
goto out;
}
priv->msg_counter = RESP_COUNTER(response);
if (RESP_TYPE(response) != 0x3 && RESP_TYPE(response) != 0xc) {
dev_dbg(&spi->dev, "Ignoring message that's not kbd data\n");
goto out;
}
for (i = 0; i < RESP_SIZE(response); i++) {
switch (response.data[i]) {
case 0x74:
input_report_key(priv->input, KEY_POWER, 1);
input_sync(priv->input);
break;
case 0xf4:
input_report_key(priv->input, KEY_POWER, 0);
input_sync(priv->input);
break;
default:
dev_dbg(&spi->dev, "Unknown scan code: %02x\n",
response.data[i]);
}
}
out:
return IRQ_HANDLED;
}
static int ariel_pwrbutton_probe(struct spi_device *spi)
{
struct ec_input_response response;
struct ariel_pwrbutton *priv;
int error;
if (!spi->irq) {
dev_err(&spi->dev, "Missing IRQ.\n");
return -EINVAL;
}
priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
Annotation
- Immediate include surface: `linux/device.h`, `linux/gfp.h`, `linux/input.h`, `linux/interrupt.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/spi/spi.h`.
- Detected declarations: `struct ec_input_response`, `struct ariel_pwrbutton`, `function ec_input_read`, `function ec_input_interrupt`, `function ariel_pwrbutton_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.