drivers/input/input-poller.c
Source file repositories/reference/linux-study-clean/drivers/input/input-poller.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/input-poller.c- Extension
.c- Size
- 5382 bytes
- Lines
- 222
- Domain
- Driver Families
- Bucket
- drivers/input
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/device.hlinux/export.hlinux/input.hlinux/jiffies.hlinux/mutex.hlinux/slab.hlinux/types.hlinux/workqueue.hinput-poller.h
Detected Declarations
struct input_dev_pollerfunction input_dev_poller_queue_workfunction input_dev_poller_workfunction input_dev_poller_finalizefunction input_dev_poller_startfunction input_dev_poller_stopfunction input_setup_pollingfunction input_dev_ensure_pollerfunction input_set_poll_intervalfunction input_set_min_poll_intervalfunction input_set_max_poll_intervalfunction input_get_poll_intervalfunction input_dev_get_poll_intervalfunction input_dev_set_poll_intervalfunction input_dev_get_poll_maxfunction input_dev_get_poll_minfunction input_poller_attrs_visibleexport input_setup_pollingexport input_set_poll_intervalexport input_set_min_poll_intervalexport input_set_max_poll_intervalexport input_get_poll_interval
Annotated Snippet
struct input_dev_poller {
void (*poll)(struct input_dev *dev);
unsigned int poll_interval; /* msec */
unsigned int poll_interval_max; /* msec */
unsigned int poll_interval_min; /* msec */
struct input_dev *input;
struct delayed_work work;
};
static void input_dev_poller_queue_work(struct input_dev_poller *poller)
{
unsigned long delay;
delay = msecs_to_jiffies(poller->poll_interval);
if (delay >= HZ)
delay = round_jiffies_relative(delay);
queue_delayed_work(system_freezable_wq, &poller->work, delay);
}
static void input_dev_poller_work(struct work_struct *work)
{
struct input_dev_poller *poller =
container_of(work, struct input_dev_poller, work.work);
poller->poll(poller->input);
input_dev_poller_queue_work(poller);
}
void input_dev_poller_finalize(struct input_dev_poller *poller)
{
if (!poller->poll_interval)
poller->poll_interval = 500;
if (!poller->poll_interval_max)
poller->poll_interval_max = poller->poll_interval;
}
void input_dev_poller_start(struct input_dev_poller *poller)
{
/* Only start polling if polling is enabled */
if (poller->poll_interval > 0) {
poller->poll(poller->input);
input_dev_poller_queue_work(poller);
}
}
void input_dev_poller_stop(struct input_dev_poller *poller)
{
cancel_delayed_work_sync(&poller->work);
}
int input_setup_polling(struct input_dev *dev,
void (*poll_fn)(struct input_dev *dev))
{
struct input_dev_poller *poller;
poller = kzalloc_obj(*poller);
if (!poller) {
/*
* We want to show message even though kzalloc() may have
* printed backtrace as knowing what instance of input
* device we were dealing with is helpful.
*/
dev_err(dev->dev.parent ?: &dev->dev,
"%s: unable to allocate poller structure\n", __func__);
return -ENOMEM;
}
INIT_DELAYED_WORK(&poller->work, input_dev_poller_work);
poller->input = dev;
poller->poll = poll_fn;
dev->poller = poller;
return 0;
}
EXPORT_SYMBOL(input_setup_polling);
static bool input_dev_ensure_poller(struct input_dev *dev)
{
if (!dev->poller) {
dev_err(dev->dev.parent ?: &dev->dev,
"poller structure has not been set up\n");
return false;
}
return true;
}
Annotation
- Immediate include surface: `linux/device.h`, `linux/export.h`, `linux/input.h`, `linux/jiffies.h`, `linux/mutex.h`, `linux/slab.h`, `linux/types.h`, `linux/workqueue.h`.
- Detected declarations: `struct input_dev_poller`, `function input_dev_poller_queue_work`, `function input_dev_poller_work`, `function input_dev_poller_finalize`, `function input_dev_poller_start`, `function input_dev_poller_stop`, `function input_setup_polling`, `function input_dev_ensure_poller`, `function input_set_poll_interval`, `function input_set_min_poll_interval`.
- Atlas domain: Driver Families / drivers/input.
- Implementation status: integration 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.