drivers/platform/x86/xiaomi-wmi.c
Source file repositories/reference/linux-study-clean/drivers/platform/x86/xiaomi-wmi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/x86/xiaomi-wmi.c- Extension
.c- Size
- 2743 bytes
- Lines
- 97
- Domain
- Driver Families
- Bucket
- drivers/platform
- 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.
- 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/input.hlinux/module.hlinux/mutex.hlinux/wmi.huapi/linux/input-event-codes.h
Detected Declarations
struct xiaomi_wmifunction xiaomi_wmi_probefunction xiaomi_wmi_notify
Annotated Snippet
struct xiaomi_wmi {
struct input_dev *input_dev;
struct mutex key_lock; /* Protects the key event sequence */
unsigned int key_code;
};
static int xiaomi_wmi_probe(struct wmi_device *wdev, const void *context)
{
struct xiaomi_wmi *data;
int ret;
if (!context)
return -EINVAL;
data = devm_kzalloc(&wdev->dev, sizeof(struct xiaomi_wmi), GFP_KERNEL);
if (data == NULL)
return -ENOMEM;
dev_set_drvdata(&wdev->dev, data);
ret = devm_mutex_init(&wdev->dev, &data->key_lock);
if (ret < 0)
return ret;
data->input_dev = devm_input_allocate_device(&wdev->dev);
if (data->input_dev == NULL)
return -ENOMEM;
data->input_dev->name = "Xiaomi WMI keys";
data->input_dev->phys = "wmi/input0";
data->key_code = *((const unsigned int *)context);
set_bit(EV_KEY, data->input_dev->evbit);
set_bit(data->key_code, data->input_dev->keybit);
return input_register_device(data->input_dev);
}
static void xiaomi_wmi_notify(struct wmi_device *wdev, const struct wmi_buffer *dummy)
{
struct xiaomi_wmi *data = dev_get_drvdata(&wdev->dev);
mutex_lock(&data->key_lock);
input_report_key(data->input_dev, data->key_code, 1);
input_sync(data->input_dev);
input_report_key(data->input_dev, data->key_code, 0);
input_sync(data->input_dev);
mutex_unlock(&data->key_lock);
}
static const struct wmi_device_id xiaomi_wmi_id_table[] = {
// { XIAOMI_DEVICE(XIAOMI_KEY_FN_ESC_0, KEY_FN_ESC) },
// { XIAOMI_DEVICE(XIAOMI_KEY_FN_ESC_1, KEY_FN_ESC) },
{ XIAOMI_DEVICE(XIAOMI_KEY_FN_FN, KEY_PROG1) },
// { XIAOMI_DEVICE(XIAOMI_KEY_CAPSLOCK, KEY_CAPSLOCK) },
{ XIAOMI_DEVICE(XIAOMI_KEY_FN_F7, KEY_CUT) },
/* Terminating entry */
{ }
};
static struct wmi_driver xiaomi_wmi_driver = {
.driver = {
.name = "xiaomi-wmi",
},
.id_table = xiaomi_wmi_id_table,
.min_event_size = 0,
.probe = xiaomi_wmi_probe,
.notify_new = xiaomi_wmi_notify,
.no_singleton = true,
};
module_wmi_driver(xiaomi_wmi_driver);
MODULE_DEVICE_TABLE(wmi, xiaomi_wmi_id_table);
MODULE_AUTHOR("Mattias Jacobsson");
MODULE_DESCRIPTION("Xiaomi WMI driver");
MODULE_LICENSE("GPL v2");
Annotation
- Immediate include surface: `linux/device.h`, `linux/input.h`, `linux/module.h`, `linux/mutex.h`, `linux/wmi.h`, `uapi/linux/input-event-codes.h`.
- Detected declarations: `struct xiaomi_wmi`, `function xiaomi_wmi_probe`, `function xiaomi_wmi_notify`.
- Atlas domain: Driver Families / drivers/platform.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.