drivers/input/keyboard/mt6779-keypad.c
Source file repositories/reference/linux-study-clean/drivers/input/keyboard/mt6779-keypad.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/keyboard/mt6779-keypad.c- Extension
.c- Size
- 7027 bytes
- Lines
- 261
- 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/bitops.hlinux/clk.hlinux/input.hlinux/input/matrix_keypad.hlinux/interrupt.hlinux/module.hlinux/property.hlinux/platform_device.hlinux/regmap.h
Detected Declarations
struct mt6779_keypadfunction mt6779_keypad_irq_handlerfunction for_each_set_bitfunction mt6779_keypad_calc_row_col_singlefunction mt6779_keypad_calc_row_col_doublefunction mt6779_keypad_pdrv_probe
Annotated Snippet
struct mt6779_keypad {
struct regmap *regmap;
struct input_dev *input_dev;
struct clk *clk;
u32 n_rows;
u32 n_cols;
void (*calc_row_col)(unsigned int key,
unsigned int *row, unsigned int *col);
DECLARE_BITMAP(keymap_state, MTK_KPD_NUM_BITS);
};
static const struct regmap_config mt6779_keypad_regmap_cfg = {
.reg_bits = 32,
.val_bits = 32,
.reg_stride = sizeof(u32),
.max_register = 36,
};
static irqreturn_t mt6779_keypad_irq_handler(int irq, void *dev_id)
{
struct mt6779_keypad *keypad = dev_id;
const unsigned short *keycode = keypad->input_dev->keycode;
DECLARE_BITMAP(new_state, MTK_KPD_NUM_BITS);
DECLARE_BITMAP(change, MTK_KPD_NUM_BITS);
unsigned int bit_nr, key;
unsigned int row, col;
unsigned int scancode;
unsigned int row_shift = get_count_order(keypad->n_cols);
bool pressed;
regmap_bulk_read(keypad->regmap, MTK_KPD_MEM,
new_state, MTK_KPD_NUM_MEMS);
bitmap_xor(change, new_state, keypad->keymap_state, MTK_KPD_NUM_BITS);
for_each_set_bit(bit_nr, change, MTK_KPD_NUM_BITS) {
/*
* Registers are 32bits, but only bits [15:0] are used to
* indicate key status.
*/
if (bit_nr % 32 >= 16)
continue;
key = bit_nr / 32 * 16 + bit_nr % 32;
keypad->calc_row_col(key, &row, &col);
scancode = MATRIX_SCAN_CODE(row, col, row_shift);
/* 1: not pressed, 0: pressed */
pressed = !test_bit(bit_nr, new_state);
dev_dbg(&keypad->input_dev->dev, "%s",
pressed ? "pressed" : "released");
input_event(keypad->input_dev, EV_MSC, MSC_SCAN, scancode);
input_report_key(keypad->input_dev, keycode[scancode], pressed);
input_sync(keypad->input_dev);
dev_dbg(&keypad->input_dev->dev,
"report Linux keycode = %d\n", keycode[scancode]);
}
bitmap_copy(keypad->keymap_state, new_state, MTK_KPD_NUM_BITS);
return IRQ_HANDLED;
}
static void mt6779_keypad_calc_row_col_single(unsigned int key,
unsigned int *row,
unsigned int *col)
{
*row = key / 9;
*col = key % 9;
}
static void mt6779_keypad_calc_row_col_double(unsigned int key,
unsigned int *row,
unsigned int *col)
{
*row = key / 13;
*col = (key % 13) / 2;
}
static int mt6779_keypad_pdrv_probe(struct platform_device *pdev)
{
struct mt6779_keypad *keypad;
void __iomem *base;
int irq;
u32 debounce;
u32 keys_per_group;
bool wakeup;
int error;
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/clk.h`, `linux/input.h`, `linux/input/matrix_keypad.h`, `linux/interrupt.h`, `linux/module.h`, `linux/property.h`, `linux/platform_device.h`.
- Detected declarations: `struct mt6779_keypad`, `function mt6779_keypad_irq_handler`, `function for_each_set_bit`, `function mt6779_keypad_calc_row_col_single`, `function mt6779_keypad_calc_row_col_double`, `function mt6779_keypad_pdrv_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.