drivers/input/keyboard/tca8418_keypad.c
Source file repositories/reference/linux-study-clean/drivers/input/keyboard/tca8418_keypad.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/keyboard/tca8418_keypad.c- Extension
.c- Size
- 9645 bytes
- Lines
- 381
- 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/delay.hlinux/i2c.hlinux/init.hlinux/input.hlinux/input/matrix_keypad.hlinux/interrupt.hlinux/module.hlinux/of.hlinux/property.hlinux/slab.hlinux/types.h
Detected Declarations
struct tca8418_keypadfunction tca8418_write_bytefunction tca8418_read_bytefunction tca8418_read_keypadfunction canfunction tca8418_configurefunction tca8418_keypad_probe
Annotated Snippet
struct tca8418_keypad {
struct i2c_client *client;
struct input_dev *input;
unsigned int row_shift;
};
/*
* Write a byte to the TCA8418
*/
static int tca8418_write_byte(struct tca8418_keypad *keypad_data,
int reg, u8 val)
{
int error;
error = i2c_smbus_write_byte_data(keypad_data->client, reg, val);
if (error < 0) {
dev_err(&keypad_data->client->dev,
"%s failed, reg: %d, val: %d, error: %d\n",
__func__, reg, val, error);
return error;
}
return 0;
}
/*
* Read a byte from the TCA8418
*/
static int tca8418_read_byte(struct tca8418_keypad *keypad_data,
int reg, u8 *val)
{
int error;
error = i2c_smbus_read_byte_data(keypad_data->client, reg);
if (error < 0) {
dev_err(&keypad_data->client->dev,
"%s failed, reg: %d, error: %d\n",
__func__, reg, error);
return error;
}
*val = (u8)error;
return 0;
}
static void tca8418_read_keypad(struct tca8418_keypad *keypad_data)
{
struct input_dev *input = keypad_data->input;
unsigned short *keymap = input->keycode;
int error, col, row;
u8 reg, state, code;
do {
error = tca8418_read_byte(keypad_data, REG_KEY_EVENT_A, ®);
if (error < 0) {
dev_err(&keypad_data->client->dev,
"unable to read REG_KEY_EVENT_A\n");
break;
}
/* Assume that key code 0 signifies empty FIFO */
if (reg <= 0)
break;
state = reg & KEY_EVENT_VALUE;
code = reg & KEY_EVENT_CODE;
row = code / TCA8418_MAX_COLS;
col = code % TCA8418_MAX_COLS;
row = (col) ? row : row - 1;
col = (col) ? col - 1 : TCA8418_MAX_COLS - 1;
code = MATRIX_SCAN_CODE(row, col, keypad_data->row_shift);
input_event(input, EV_MSC, MSC_SCAN, code);
input_report_key(input, keymap[code], state);
} while (1);
input_sync(input);
}
/*
* Threaded IRQ handler and this can (and will) sleep.
*/
static irqreturn_t tca8418_irq_handler(int irq, void *dev_id)
{
struct tca8418_keypad *keypad_data = dev_id;
Annotation
- Immediate include surface: `linux/delay.h`, `linux/i2c.h`, `linux/init.h`, `linux/input.h`, `linux/input/matrix_keypad.h`, `linux/interrupt.h`, `linux/module.h`, `linux/of.h`.
- Detected declarations: `struct tca8418_keypad`, `function tca8418_write_byte`, `function tca8418_read_byte`, `function tca8418_read_keypad`, `function can`, `function tca8418_configure`, `function tca8418_keypad_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.