drivers/input/keyboard/gpio_keys.c
Source file repositories/reference/linux-study-clean/drivers/input/keyboard/gpio_keys.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/keyboard/gpio_keys.c- Extension
.c- Size
- 28443 bytes
- Lines
- 1130
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/module.hlinux/hrtimer.hlinux/init.hlinux/fs.hlinux/interrupt.hlinux/irq.hlinux/sched.hlinux/pm.hlinux/slab.hlinux/sysctl.hlinux/proc_fs.hlinux/delay.hlinux/platform_device.hlinux/input.hlinux/gpio_keys.hlinux/workqueue.hlinux/gpio.hlinux/gpio/consumer.hlinux/of.hlinux/of_irq.hlinux/spinlock.hdt-bindings/input/gpio-keys.h
Detected Declarations
struct gpio_button_datastruct gpio_keys_drvdatafunction keyfunction get_bm_events_by_typefunction gpio_keys_quiesce_keyfunction gpio_keys_disable_buttonfunction gpio_keys_enable_buttonfunction gpio_keys_attr_show_helperfunction gpio_keys_attr_store_helperfunction gpio_keys_gpio_report_eventfunction gpio_keys_debounce_eventfunction gpio_keys_gpio_work_funcfunction gpio_keys_debounce_timerfunction gpio_keys_gpio_isrfunction gpio_keys_irq_timerfunction gpio_keys_irq_isrfunction gpio_keys_setup_keyfunction gpio_keys_report_statefunction gpio_keys_openfunction gpio_keys_closefunction gpio_keys_get_devtree_pdatafunction device_for_each_child_node_scopedfunction gpio_keys_probefunction gpio_keys_button_enable_wakeupfunction gpio_keys_button_disable_wakeupfunction gpio_keys_enable_wakeupfunction gpio_keys_disable_wakeupfunction gpio_keys_suspendfunction gpio_keys_resumefunction gpio_keys_shutdownfunction gpio_keys_initfunction gpio_keys_exit
Annotated Snippet
struct gpio_button_data {
const struct gpio_keys_button *button;
struct input_dev *input;
struct gpio_desc *gpiod;
unsigned short *code;
struct hrtimer release_timer;
unsigned int release_delay; /* in msecs, for IRQ-only buttons */
struct delayed_work work;
struct hrtimer debounce_timer;
unsigned int software_debounce; /* in msecs, for GPIO-driven buttons */
unsigned int irq;
unsigned int wakeirq;
unsigned int wakeup_trigger_type;
spinlock_t lock;
bool disabled;
bool key_pressed;
bool suspended;
bool debounce_use_hrtimer;
};
struct gpio_keys_drvdata {
const struct gpio_keys_platform_data *pdata;
struct input_dev *input;
struct mutex disable_lock;
unsigned short *keymap;
struct gpio_button_data data[];
};
/*
* SYSFS interface for enabling/disabling keys and switches:
*
* There are 4 attributes under /sys/devices/platform/gpio-keys/
* keys [ro] - bitmap of keys (EV_KEY) which can be
* disabled
* switches [ro] - bitmap of switches (EV_SW) which can be
* disabled
* disabled_keys [rw] - bitmap of keys currently disabled
* disabled_switches [rw] - bitmap of switches currently disabled
*
* Userland can change these values and hence disable event generation
* for each key (or switch). Disabling a key means its interrupt line
* is disabled.
*
* For example, if we have following switches set up as gpio-keys:
* SW_DOCK = 5
* SW_CAMERA_LENS_COVER = 9
* SW_KEYPAD_SLIDE = 10
* SW_FRONT_PROXIMITY = 11
* This is read from switches:
* 11-9,5
* Next we want to disable proximity (11) and dock (5), we write:
* 11,5
* to file disabled_switches. Now proximity and dock IRQs are disabled.
* This can be verified by reading the file disabled_switches:
* 11,5
* If we now want to enable proximity (11) switch we write:
* 5
* to disabled_switches.
*
* We can disable only those keys which don't allow sharing the irq.
*/
/**
* get_n_events_by_type() - returns maximum number of events per @type
* @type: type of button (%EV_KEY, %EV_SW)
*
* Return value of this function can be used to allocate bitmap
* large enough to hold all bits for given type.
*/
static int get_n_events_by_type(int type)
{
BUG_ON(type != EV_SW && type != EV_KEY);
return (type == EV_KEY) ? KEY_CNT : SW_CNT;
}
/**
* get_bm_events_by_type() - returns bitmap of supported events per @type
* @dev: input device from which bitmap is retrieved
* @type: type of button (%EV_KEY, %EV_SW)
*
* Return value of this function can be used to allocate bitmap
* large enough to hold all bits for given type.
*/
static const unsigned long *get_bm_events_by_type(struct input_dev *dev,
Annotation
- Immediate include surface: `linux/module.h`, `linux/hrtimer.h`, `linux/init.h`, `linux/fs.h`, `linux/interrupt.h`, `linux/irq.h`, `linux/sched.h`, `linux/pm.h`.
- Detected declarations: `struct gpio_button_data`, `struct gpio_keys_drvdata`, `function key`, `function get_bm_events_by_type`, `function gpio_keys_quiesce_key`, `function gpio_keys_disable_button`, `function gpio_keys_enable_button`, `function gpio_keys_attr_show_helper`, `function gpio_keys_attr_store_helper`, `function gpio_keys_gpio_report_event`.
- Atlas domain: Driver Families / drivers/input.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.