drivers/input/keyboard/nspire-keypad.c
Source file repositories/reference/linux-study-clean/drivers/input/keyboard/nspire-keypad.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/keyboard/nspire-keypad.c- Extension
.c- Size
- 7008 bytes
- Lines
- 278
- 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/input/matrix_keypad.hlinux/platform_device.hlinux/interrupt.hlinux/io.hlinux/delay.hlinux/input.hlinux/slab.hlinux/clk.hlinux/module.hlinux/of.h
Detected Declarations
struct nspire_keypadfunction nspire_keypad_irqfunction nspire_keypad_openfunction nspire_keypad_closefunction nspire_keypad_probe
Annotated Snippet
struct nspire_keypad {
void __iomem *reg_base;
u32 int_mask;
struct input_dev *input;
struct clk *clk;
struct matrix_keymap_data *keymap;
int row_shift;
/* Maximum delay estimated assuming 33MHz APB */
u32 scan_interval; /* In microseconds (~2000us max) */
u32 row_delay; /* In microseconds (~500us max) */
u16 state[KEYPAD_BITMASK_ROWS];
bool active_low;
};
static irqreturn_t nspire_keypad_irq(int irq, void *dev_id)
{
struct nspire_keypad *keypad = dev_id;
struct input_dev *input = keypad->input;
unsigned short *keymap = input->keycode;
unsigned int code;
int row, col;
u32 int_sts;
u16 state[8];
u16 bits, changed;
int_sts = readl(keypad->reg_base + KEYPAD_INT) & keypad->int_mask;
if (!int_sts)
return IRQ_NONE;
memcpy_fromio(state, keypad->reg_base + KEYPAD_DATA, sizeof(state));
for (row = 0; row < KEYPAD_BITMASK_ROWS; row++) {
bits = state[row];
if (keypad->active_low)
bits = ~bits;
changed = bits ^ keypad->state[row];
if (!changed)
continue;
keypad->state[row] = bits;
for (col = 0; col < KEYPAD_BITMASK_COLS; col++) {
if (!(changed & (1U << col)))
continue;
code = MATRIX_SCAN_CODE(row, col, keypad->row_shift);
input_event(input, EV_MSC, MSC_SCAN, code);
input_report_key(input, keymap[code],
bits & (1U << col));
}
}
input_sync(input);
writel(0x3, keypad->reg_base + KEYPAD_INT);
return IRQ_HANDLED;
}
static int nspire_keypad_open(struct input_dev *input)
{
struct nspire_keypad *keypad = input_get_drvdata(input);
unsigned long val = 0, cycles_per_us, delay_cycles, row_delay_cycles;
int error;
error = clk_prepare_enable(keypad->clk);
if (error)
return error;
cycles_per_us = (clk_get_rate(keypad->clk) / 1000000);
if (cycles_per_us == 0)
cycles_per_us = 1;
delay_cycles = cycles_per_us * keypad->scan_interval;
WARN_ON(delay_cycles >= (1 << 16)); /* Overflow */
delay_cycles &= 0xffff;
row_delay_cycles = cycles_per_us * keypad->row_delay;
WARN_ON(row_delay_cycles >= (1 << 14)); /* Overflow */
row_delay_cycles &= 0x3fff;
val |= 3 << 0; /* Set scan mode to 3 (continuous scan) */
val |= row_delay_cycles << 2; /* Delay between scanning each row */
val |= delay_cycles << 16; /* Delay between scans */
Annotation
- Immediate include surface: `linux/input/matrix_keypad.h`, `linux/platform_device.h`, `linux/interrupt.h`, `linux/io.h`, `linux/delay.h`, `linux/input.h`, `linux/slab.h`, `linux/clk.h`.
- Detected declarations: `struct nspire_keypad`, `function nspire_keypad_irq`, `function nspire_keypad_open`, `function nspire_keypad_close`, `function nspire_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.