drivers/platform/x86/redmi-wmi.c
Source file repositories/reference/linux-study-clean/drivers/platform/x86/redmi-wmi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/x86/redmi-wmi.c- Extension
.c- Size
- 3852 bytes
- Lines
- 155
- 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.
- 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/acpi.hlinux/bits.hlinux/device.hlinux/input.hlinux/input/sparse-keymap.hlinux/module.hlinux/mutex.hlinux/unaligned.hlinux/wmi.huapi/linux/input-event-codes.h
Detected Declarations
struct redmi_wmifunction redmi_wmi_probefunction redmi_wmi_notify
Annotated Snippet
struct redmi_wmi {
struct input_dev *input_dev;
/* Protects the key event sequence */
struct mutex key_lock;
};
static int redmi_wmi_probe(struct wmi_device *wdev, const void *context)
{
struct redmi_wmi *data;
int err;
/* Init dev */
data = devm_kzalloc(&wdev->dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
dev_set_drvdata(&wdev->dev, data);
err = devm_mutex_init(&wdev->dev, &data->key_lock);
if (err)
return err;
data->input_dev = devm_input_allocate_device(&wdev->dev);
if (!data->input_dev)
return -ENOMEM;
data->input_dev->name = "Redmibook WMI keys";
data->input_dev->phys = "wmi/input0";
err = sparse_keymap_setup(data->input_dev, redmi_wmi_keymap, NULL);
if (err)
return err;
return input_register_device(data->input_dev);
}
static void redmi_wmi_notify(struct wmi_device *wdev, union acpi_object *obj)
{
struct key_entry *entry;
struct redmi_wmi *data = dev_get_drvdata(&wdev->dev);
bool autorelease = true;
u32 payload;
int value = 1;
if (obj->type != ACPI_TYPE_BUFFER) {
dev_err(&wdev->dev, "Bad response type %u\n", obj->type);
return;
}
if (obj->buffer.length < 32) {
dev_err(&wdev->dev, "Invalid buffer length %u\n", obj->buffer.length);
return;
}
payload = get_unaligned_le32(obj->buffer.pointer);
entry = sparse_keymap_entry_from_scancode(data->input_dev, payload);
if (!entry) {
dev_dbg(&wdev->dev, "Unknown WMI event with payload %u", payload);
return;
}
/* AI key quirk */
if (entry->keycode == KEY_ASSISTANT) {
value = !(payload & AI_KEY_VALUE_MASK);
autorelease = false;
}
guard(mutex)(&data->key_lock);
sparse_keymap_report_entry(data->input_dev, entry, value, autorelease);
}
static const struct wmi_device_id redmi_wmi_id_table[] = {
{ WMI_REDMIBOOK_KEYBOARD_EVENT_GUID, NULL },
{ }
};
static struct wmi_driver redmi_wmi_driver = {
.driver = {
.name = "redmi-wmi",
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
},
.id_table = redmi_wmi_id_table,
.min_event_size = 32,
.probe = redmi_wmi_probe,
.notify = redmi_wmi_notify,
.no_singleton = true,
};
module_wmi_driver(redmi_wmi_driver);
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/bits.h`, `linux/device.h`, `linux/input.h`, `linux/input/sparse-keymap.h`, `linux/module.h`, `linux/mutex.h`, `linux/unaligned.h`.
- Detected declarations: `struct redmi_wmi`, `function redmi_wmi_probe`, `function redmi_wmi_notify`.
- Atlas domain: Driver Families / drivers/platform.
- 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.