drivers/hid/hid-wiimote-modules.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-wiimote-modules.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-wiimote-modules.c- Extension
.c- Size
- 88334 bytes
- Lines
- 2886
- 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/device.hlinux/hid.hlinux/input.hlinux/spinlock.hhid-wiimote.h
Detected Declarations
enum wiimod_nunchuk_keysenum wiimod_classic_keysenum wiimod_pro_keysenum wiimod_guitar_keysenum wiimod_turntable_keysfunction wiimod_keys_in_keysfunction wiimod_keys_probefunction wiimod_rumble_workerfunction wiimod_rumble_playfunction wiimod_rumble_probefunction wiimod_rumble_removefunction wiimod_battery_get_propertyfunction wiimod_battery_probefunction wiimod_battery_removefunction wiimod_led_getfunction wiimod_led_setfunction wiimod_led_probefunction wiimod_led_removefunction wiimod_accel_in_accelfunction wiimod_accel_openfunction wiimod_accel_closefunction wiimod_accel_probefunction wiimod_accel_removefunction wiimod_ir_in_irfunction wiimod_ir_changefunction wiimod_ir_openfunction wiimod_ir_closefunction wiimod_ir_probefunction wiimod_ir_removefunction wiimod_nunchuk_in_extfunction wiimod_nunchuk_openfunction wiimod_nunchuk_closefunction wiimod_nunchuk_probefunction wiimod_nunchuk_removefunction wiimod_classic_in_extfunction wiimod_classic_openfunction wiimod_classic_closefunction wiimod_classic_probefunction wiimod_classic_removefunction wiimod_bboard_in_keysfunction wiimod_bboard_in_extfunction wiimod_bboard_openfunction wiimod_bboard_closefunction wiimod_bboard_calib_showfunction wiimod_bboard_probefunction wiimod_bboard_removefunction wiimod_pro_in_extfunction wiimod_pro_open
Annotated Snippet
if (wdata->leds[i] == led_dev) {
spin_lock_irqsave(&wdata->state.lock, flags);
value = wdata->state.flags & WIIPROTO_FLAG_LED(i + 1);
spin_unlock_irqrestore(&wdata->state.lock, flags);
break;
}
}
return value ? LED_FULL : LED_OFF;
}
static void wiimod_led_set(struct led_classdev *led_dev,
enum led_brightness value)
{
struct device *dev = led_dev->dev->parent;
struct wiimote_data *wdata = dev_to_wii(dev);
int i;
unsigned long flags;
__u8 state, flag;
for (i = 0; i < 4; ++i) {
if (wdata->leds[i] == led_dev) {
flag = WIIPROTO_FLAG_LED(i + 1);
spin_lock_irqsave(&wdata->state.lock, flags);
state = wdata->state.flags;
if (value == LED_OFF)
wiiproto_req_leds(wdata, state & ~flag);
else
wiiproto_req_leds(wdata, state | flag);
spin_unlock_irqrestore(&wdata->state.lock, flags);
break;
}
}
}
static int wiimod_led_probe(const struct wiimod_ops *ops,
struct wiimote_data *wdata)
{
struct device *dev = &wdata->hdev->dev;
size_t namesz = strlen(dev_name(dev)) + 9;
struct led_classdev *led;
unsigned long flags;
char *name;
int ret;
led = kzalloc(sizeof(struct led_classdev) + namesz, GFP_KERNEL);
if (!led)
return -ENOMEM;
name = (void*)&led[1];
snprintf(name, namesz, "%s:blue:p%lu", dev_name(dev), ops->arg);
led->name = name;
led->brightness = 0;
led->max_brightness = 1;
led->brightness_get = wiimod_led_get;
led->brightness_set = wiimod_led_set;
wdata->leds[ops->arg] = led;
ret = led_classdev_register(dev, led);
if (ret)
goto err_free;
/* enable LED1 to stop initial LED-blinking */
if (ops->arg == 0) {
spin_lock_irqsave(&wdata->state.lock, flags);
wiiproto_req_leds(wdata, WIIPROTO_FLAG_LED1);
spin_unlock_irqrestore(&wdata->state.lock, flags);
}
return 0;
err_free:
wdata->leds[ops->arg] = NULL;
kfree(led);
return ret;
}
static void wiimod_led_remove(const struct wiimod_ops *ops,
struct wiimote_data *wdata)
{
if (!wdata->leds[ops->arg])
return;
led_classdev_unregister(wdata->leds[ops->arg]);
kfree(wdata->leds[ops->arg]);
wdata->leds[ops->arg] = NULL;
}
static const struct wiimod_ops wiimod_leds[4] = {
{
Annotation
- Immediate include surface: `linux/device.h`, `linux/hid.h`, `linux/input.h`, `linux/spinlock.h`, `hid-wiimote.h`.
- Detected declarations: `enum wiimod_nunchuk_keys`, `enum wiimod_classic_keys`, `enum wiimod_pro_keys`, `enum wiimod_guitar_keys`, `enum wiimod_turntable_keys`, `function wiimod_keys_in_keys`, `function wiimod_keys_probe`, `function wiimod_rumble_worker`, `function wiimod_rumble_play`, `function wiimod_rumble_probe`.
- 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.