drivers/input/keyboard/gpio_keys_polled.c
Source file repositories/reference/linux-study-clean/drivers/input/keyboard/gpio_keys_polled.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/keyboard/gpio_keys_polled.c- Extension
.c- Size
- 9853 bytes
- Lines
- 382
- 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/kernel.hlinux/module.hlinux/slab.hlinux/input.hlinux/ioport.hlinux/platform_device.hlinux/gpio.hlinux/gpio/consumer.hlinux/gpio_keys.hlinux/property.h
Detected Declarations
struct gpio_keys_button_datastruct gpio_keys_polled_devfunction gpio_keys_button_eventfunction gpio_keys_polled_check_statefunction gpio_keys_polled_pollfunction for_each_set_bitfunction for_each_set_bitfunction gpio_keys_polled_openfunction gpio_keys_polled_closefunction gpio_keys_polled_get_devtree_pdatafunction device_for_each_child_node_scopedfunction gpio_keys_polled_set_abs_paramsfunction gpio_keys_polled_probe
Annotated Snippet
struct gpio_keys_button_data {
struct gpio_desc *gpiod;
int last_state;
int count;
int threshold;
};
struct gpio_keys_polled_dev {
struct input_dev *input;
struct device *dev;
const struct gpio_keys_platform_data *pdata;
unsigned long rel_axis_seen[BITS_TO_LONGS(REL_CNT)];
unsigned long abs_axis_seen[BITS_TO_LONGS(ABS_CNT)];
struct gpio_keys_button_data data[];
};
static void gpio_keys_button_event(struct input_dev *input,
const struct gpio_keys_button *button,
int state)
{
struct gpio_keys_polled_dev *bdev = input_get_drvdata(input);
unsigned int type = button->type ?: EV_KEY;
if (type == EV_REL) {
if (state) {
input_event(input, type, button->code, button->value);
__set_bit(button->code, bdev->rel_axis_seen);
}
} else if (type == EV_ABS) {
if (state) {
input_event(input, type, button->code, button->value);
__set_bit(button->code, bdev->abs_axis_seen);
}
} else {
input_event(input, type, button->code, state);
input_sync(input);
}
}
static void gpio_keys_polled_check_state(struct input_dev *input,
const struct gpio_keys_button *button,
struct gpio_keys_button_data *bdata)
{
int state;
state = gpiod_get_value_cansleep(bdata->gpiod);
if (state < 0) {
dev_err(input->dev.parent,
"failed to get gpio state: %d\n", state);
} else {
gpio_keys_button_event(input, button, state);
if (state != bdata->last_state) {
bdata->count = 0;
bdata->last_state = state;
}
}
}
static void gpio_keys_polled_poll(struct input_dev *input)
{
struct gpio_keys_polled_dev *bdev = input_get_drvdata(input);
const struct gpio_keys_platform_data *pdata = bdev->pdata;
int i;
memset(bdev->rel_axis_seen, 0, sizeof(bdev->rel_axis_seen));
memset(bdev->abs_axis_seen, 0, sizeof(bdev->abs_axis_seen));
for (i = 0; i < pdata->nbuttons; i++) {
struct gpio_keys_button_data *bdata = &bdev->data[i];
if (bdata->count < bdata->threshold) {
bdata->count++;
gpio_keys_button_event(input, &pdata->buttons[i],
bdata->last_state);
} else {
gpio_keys_polled_check_state(input, &pdata->buttons[i],
bdata);
}
}
for_each_set_bit(i, input->relbit, REL_CNT) {
if (!test_bit(i, bdev->rel_axis_seen))
input_event(input, EV_REL, i, 0);
}
for_each_set_bit(i, input->absbit, ABS_CNT) {
if (!test_bit(i, bdev->abs_axis_seen))
input_event(input, EV_ABS, i, 0);
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/slab.h`, `linux/input.h`, `linux/ioport.h`, `linux/platform_device.h`, `linux/gpio.h`, `linux/gpio/consumer.h`.
- Detected declarations: `struct gpio_keys_button_data`, `struct gpio_keys_polled_dev`, `function gpio_keys_button_event`, `function gpio_keys_polled_check_state`, `function gpio_keys_polled_poll`, `function for_each_set_bit`, `function for_each_set_bit`, `function gpio_keys_polled_open`, `function gpio_keys_polled_close`, `function gpio_keys_polled_get_devtree_pdata`.
- 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.