drivers/hid/hid-wiimote-core.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-wiimote-core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-wiimote-core.c- Extension
.c- Size
- 50014 bytes
- Lines
- 1895
- Domain
- Driver Families
- Bucket
- drivers/hid
- 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/completion.hlinux/device.hlinux/hid.hlinux/input.hlinux/module.hlinux/mutex.hlinux/spinlock.hhid-ids.hhid-wiimote.h
Detected Declarations
struct wiiproto_handlerfunction Copyrightfunction wiimote_queue_workerfunction wiimote_queuefunction wiiproto_keep_rumblefunction wiiproto_req_rumblefunction wiiproto_req_ledsfunction select_drmfunction wiiproto_req_drmfunction wiiproto_req_statusfunction wiiproto_req_accelfunction wiiproto_req_ir1function wiiproto_req_ir2function wiiproto_req_wmemfunction wiiproto_req_rmemfunction wiimote_cmd_writefunction wiimote_cmd_readfunction wiimote_cmd_init_extfunction wiimote_cmd_read_extfunction wiimote_cmd_init_mpfunction wiimote_cmd_map_mpfunction wiimote_cmd_read_mpfunction wiimote_cmd_read_mp_mappedfunction wiimote_modules_loadfunction wiimote_modules_unloadfunction wiimote_ext_loadfunction wiimote_ext_unloadfunction wiimote_mp_loadfunction wiimote_mp_unloadfunction wiimote_init_set_typefunction wiimote_init_detectfunction wiimote_init_poll_mpfunction wiimote_init_checkfunction read_mp_mappedfunction read_extfunction mp_mappedfunction wiimote_init_hotplugfunction wiimote_init_workerfunction __wiimote_schedulefunction wiimote_schedulefunction wiimote_init_timeoutfunction handler_keysfunction handler_accelfunction valid_ext_handlerfunction handler_extfunction handler_irfunction handler_status_Kfunction handler_status
Annotated Snippet
struct wiiproto_handler {
__u8 id;
size_t size;
void (*func)(struct wiimote_data *wdata, const __u8 *payload);
};
static const struct wiiproto_handler handlers[] = {
{ .id = WIIPROTO_REQ_STATUS, .size = 6, .func = handler_status },
{ .id = WIIPROTO_REQ_STATUS, .size = 2, .func = handler_status_K },
{ .id = WIIPROTO_REQ_DATA, .size = 21, .func = handler_data },
{ .id = WIIPROTO_REQ_DATA, .size = 2, .func = handler_generic_K },
{ .id = WIIPROTO_REQ_RETURN, .size = 4, .func = handler_return },
{ .id = WIIPROTO_REQ_RETURN, .size = 2, .func = handler_generic_K },
{ .id = WIIPROTO_REQ_DRM_K, .size = 2, .func = handler_keys },
{ .id = WIIPROTO_REQ_DRM_KA, .size = 5, .func = handler_drm_KA },
{ .id = WIIPROTO_REQ_DRM_KA, .size = 2, .func = handler_generic_K },
{ .id = WIIPROTO_REQ_DRM_KE, .size = 10, .func = handler_drm_KE },
{ .id = WIIPROTO_REQ_DRM_KE, .size = 2, .func = handler_generic_K },
{ .id = WIIPROTO_REQ_DRM_KAI, .size = 17, .func = handler_drm_KAI },
{ .id = WIIPROTO_REQ_DRM_KAI, .size = 2, .func = handler_generic_K },
{ .id = WIIPROTO_REQ_DRM_KEE, .size = 21, .func = handler_drm_KEE },
{ .id = WIIPROTO_REQ_DRM_KEE, .size = 2, .func = handler_generic_K },
{ .id = WIIPROTO_REQ_DRM_KAE, .size = 21, .func = handler_drm_KAE },
{ .id = WIIPROTO_REQ_DRM_KAE, .size = 2, .func = handler_generic_K },
{ .id = WIIPROTO_REQ_DRM_KIE, .size = 21, .func = handler_drm_KIE },
{ .id = WIIPROTO_REQ_DRM_KIE, .size = 2, .func = handler_generic_K },
{ .id = WIIPROTO_REQ_DRM_KAIE, .size = 21, .func = handler_drm_KAIE },
{ .id = WIIPROTO_REQ_DRM_KAIE, .size = 2, .func = handler_generic_K },
{ .id = WIIPROTO_REQ_DRM_E, .size = 21, .func = handler_drm_E },
{ .id = WIIPROTO_REQ_DRM_SKAI1, .size = 21, .func = handler_drm_SKAI1 },
{ .id = WIIPROTO_REQ_DRM_SKAI2, .size = 21, .func = handler_drm_SKAI2 },
{ .id = 0 }
};
static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report,
u8 *raw_data, int size)
{
struct wiimote_data *wdata = hid_get_drvdata(hdev);
const struct wiiproto_handler *h;
int i;
unsigned long flags;
if (size < 1)
return -EINVAL;
for (i = 0; handlers[i].id; ++i) {
h = &handlers[i];
if (h->id == raw_data[0] && h->size < size) {
spin_lock_irqsave(&wdata->state.lock, flags);
h->func(wdata, &raw_data[1]);
spin_unlock_irqrestore(&wdata->state.lock, flags);
break;
}
}
if (!handlers[i].id)
hid_warn(hdev, "Unhandled report %hhu size %d\n", raw_data[0],
size);
return 0;
}
static ssize_t wiimote_ext_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct wiimote_data *wdata = dev_to_wii(dev);
__u8 type;
unsigned long flags;
spin_lock_irqsave(&wdata->state.lock, flags);
type = wdata->state.exttype;
spin_unlock_irqrestore(&wdata->state.lock, flags);
switch (type) {
case WIIMOTE_EXT_NONE:
return sprintf(buf, "none\n");
case WIIMOTE_EXT_NUNCHUK:
return sprintf(buf, "nunchuk\n");
case WIIMOTE_EXT_CLASSIC_CONTROLLER:
return sprintf(buf, "classic\n");
case WIIMOTE_EXT_BALANCE_BOARD:
return sprintf(buf, "balanceboard\n");
case WIIMOTE_EXT_PRO_CONTROLLER:
return sprintf(buf, "procontroller\n");
case WIIMOTE_EXT_DRUMS:
return sprintf(buf, "drums\n");
case WIIMOTE_EXT_GUITAR:
return sprintf(buf, "guitar\n");
case WIIMOTE_EXT_TURNTABLE:
Annotation
- Immediate include surface: `linux/completion.h`, `linux/device.h`, `linux/hid.h`, `linux/input.h`, `linux/module.h`, `linux/mutex.h`, `linux/spinlock.h`, `hid-ids.h`.
- Detected declarations: `struct wiiproto_handler`, `function Copyright`, `function wiimote_queue_worker`, `function wiimote_queue`, `function wiiproto_keep_rumble`, `function wiiproto_req_rumble`, `function wiiproto_req_leds`, `function select_drm`, `function wiiproto_req_drm`, `function wiiproto_req_status`.
- Atlas domain: Driver Families / drivers/hid.
- 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.