drivers/input/misc/ibm-panel.c
Source file repositories/reference/linux-study-clean/drivers/input/misc/ibm-panel.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/misc/ibm-panel.c- Extension
.c- Size
- 4522 bytes
- Lines
- 197
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/i2c.hlinux/init.hlinux/input.hlinux/kernel.hlinux/limits.hlinux/module.hlinux/of.hlinux/spinlock.h
Detected Declarations
struct ibm_panelfunction ibm_panel_calculate_checksumfunction ibm_panel_process_commandfunction ibm_panel_i2c_slave_cbfunction ibm_panel_probefunction ibm_panel_remove
Annotated Snippet
struct ibm_panel {
u8 idx;
u8 command[11];
u32 keycodes[PANEL_KEYCODES_COUNT];
spinlock_t lock; /* protects writes to idx and command */
struct input_dev *input;
};
static u8 ibm_panel_calculate_checksum(struct ibm_panel *panel)
{
u8 chksum;
u16 sum = 0;
unsigned int i;
for (i = 0; i < sizeof(panel->command) - 1; ++i) {
sum += panel->command[i];
if (sum & 0xff00) {
sum &= 0xff;
sum++;
}
}
chksum = sum & 0xff;
chksum = ~chksum;
chksum++;
return chksum;
}
static void ibm_panel_process_command(struct ibm_panel *panel)
{
u8 button;
u8 chksum;
if (panel->command[0] != 0xff && panel->command[1] != 0xf0) {
dev_dbg(&panel->input->dev, "command invalid: %02x %02x\n",
panel->command[0], panel->command[1]);
return;
}
chksum = ibm_panel_calculate_checksum(panel);
if (chksum != panel->command[sizeof(panel->command) - 1]) {
dev_dbg(&panel->input->dev,
"command failed checksum: %u != %u\n", chksum,
panel->command[sizeof(panel->command) - 1]);
return;
}
button = panel->command[2] & 0xf;
if (button < PANEL_KEYCODES_COUNT) {
input_report_key(panel->input, panel->keycodes[button],
!(panel->command[2] & 0x80));
input_sync(panel->input);
} else {
dev_dbg(&panel->input->dev, "unknown button %u\n",
button);
}
}
static int ibm_panel_i2c_slave_cb(struct i2c_client *client,
enum i2c_slave_event event, u8 *val)
{
struct ibm_panel *panel = i2c_get_clientdata(client);
dev_dbg(&panel->input->dev, "event: %u data: %02x\n", event, *val);
guard(spinlock_irqsave)(&panel->lock);
switch (event) {
case I2C_SLAVE_STOP:
if (panel->idx == sizeof(panel->command))
ibm_panel_process_command(panel);
else
dev_dbg(&panel->input->dev,
"command incorrect size %u\n", panel->idx);
fallthrough;
case I2C_SLAVE_WRITE_REQUESTED:
panel->idx = 0;
break;
case I2C_SLAVE_WRITE_RECEIVED:
if (panel->idx < sizeof(panel->command))
panel->command[panel->idx++] = *val;
else
/*
* The command is too long and therefore invalid, so set the index
* to it's largest possible value. When a STOP is finally received,
* the command will be rejected upon processing.
*/
panel->idx = U8_MAX;
break;
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/init.h`, `linux/input.h`, `linux/kernel.h`, `linux/limits.h`, `linux/module.h`, `linux/of.h`, `linux/spinlock.h`.
- Detected declarations: `struct ibm_panel`, `function ibm_panel_calculate_checksum`, `function ibm_panel_process_command`, `function ibm_panel_i2c_slave_cb`, `function ibm_panel_probe`, `function ibm_panel_remove`.
- Atlas domain: Driver Families / drivers/input.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.