drivers/input/keyboard/clps711x-keypad.c
Source file repositories/reference/linux-study-clean/drivers/input/keyboard/clps711x-keypad.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/keyboard/clps711x-keypad.c- Extension
.c- Size
- 4594 bytes
- Lines
- 186
- 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.
- 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.hlinux/mod_devicetable.hlinux/module.hlinux/gpio/consumer.hlinux/platform_device.hlinux/property.hlinux/regmap.hlinux/sched.hlinux/input/matrix_keypad.hlinux/mfd/syscon.hlinux/mfd/syscon/clps711x.h
Detected Declarations
struct clps711x_gpio_datastruct clps711x_keypad_datafunction clps711x_keypad_pollfunction clps711x_keypad_probe
Annotated Snippet
struct clps711x_gpio_data {
struct gpio_desc *desc;
DECLARE_BITMAP(last_state, CLPS711X_KEYPAD_COL_COUNT);
};
struct clps711x_keypad_data {
struct regmap *syscon;
int row_count;
unsigned int row_shift;
struct clps711x_gpio_data *gpio_data;
};
static void clps711x_keypad_poll(struct input_dev *input)
{
const unsigned short *keycodes = input->keycode;
struct clps711x_keypad_data *priv = input_get_drvdata(input);
bool sync = false;
int col, row;
for (col = 0; col < CLPS711X_KEYPAD_COL_COUNT; col++) {
/* Assert column */
regmap_update_bits(priv->syscon, SYSCON_OFFSET,
SYSCON1_KBDSCAN_MASK,
SYSCON1_KBDSCAN(8 + col));
/* Scan rows */
for (row = 0; row < priv->row_count; row++) {
struct clps711x_gpio_data *data = &priv->gpio_data[row];
bool state, state1;
/* Read twice for protection against fluctuations */
do {
state = gpiod_get_value_cansleep(data->desc);
cond_resched();
state1 = gpiod_get_value_cansleep(data->desc);
} while (state != state1);
if (test_bit(col, data->last_state) != state) {
int code = MATRIX_SCAN_CODE(row, col,
priv->row_shift);
if (state) {
set_bit(col, data->last_state);
input_event(input,
EV_MSC, MSC_SCAN, code);
} else {
clear_bit(col, data->last_state);
}
if (keycodes[code])
input_report_key(input,
keycodes[code], state);
sync = true;
}
}
/* Set all columns to low */
regmap_update_bits(priv->syscon, SYSCON_OFFSET,
SYSCON1_KBDSCAN_MASK, SYSCON1_KBDSCAN(1));
}
if (sync)
input_sync(input);
}
static int clps711x_keypad_probe(struct platform_device *pdev)
{
struct clps711x_keypad_data *priv;
struct device *dev = &pdev->dev;
struct input_dev *input;
u32 poll_interval;
int i, err;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
priv->syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon");
if (IS_ERR(priv->syscon))
return PTR_ERR(priv->syscon);
priv->row_count = gpiod_count(dev, "row");
if (priv->row_count < 1)
return -EINVAL;
priv->gpio_data = devm_kcalloc(dev,
priv->row_count, sizeof(*priv->gpio_data),
GFP_KERNEL);
if (!priv->gpio_data)
return -ENOMEM;
Annotation
- Immediate include surface: `linux/input.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/gpio/consumer.h`, `linux/platform_device.h`, `linux/property.h`, `linux/regmap.h`, `linux/sched.h`.
- Detected declarations: `struct clps711x_gpio_data`, `struct clps711x_keypad_data`, `function clps711x_keypad_poll`, `function clps711x_keypad_probe`.
- Atlas domain: Driver Families / drivers/input.
- Implementation status: source implementation candidate.
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.