drivers/hid/hid-megaworld.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-megaworld.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-megaworld.c- Extension
.c- Size
- 2807 bytes
- Lines
- 127
- 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.
- 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/hid.hlinux/input.hlinux/module.hlinux/slab.hhid-ids.h
Detected Declarations
struct mwctrl_devicefunction mwctrl_playfunction mwctrl_initfunction mwctrl_probe
Annotated Snippet
struct mwctrl_device {
struct hid_report *report;
s32 *weak;
s32 *strong;
};
static int mwctrl_play(struct input_dev *dev, void *data,
struct ff_effect *effect)
{
struct hid_device *hid = input_get_drvdata(dev);
struct mwctrl_device *mwctrl = data;
*mwctrl->strong = effect->u.rumble.strong_magnitude >> 8;
*mwctrl->weak = effect->u.rumble.weak_magnitude >> 8;
hid_hw_request(hid, mwctrl->report, HID_REQ_SET_REPORT);
return 0;
}
static int mwctrl_init(struct hid_device *hid)
{
struct mwctrl_device *mwctrl;
struct hid_report *report;
struct hid_input *hidinput;
struct input_dev *dev;
int error;
int i;
if (list_empty(&hid->inputs)) {
hid_err(hid, "no inputs found\n");
return -ENODEV;
}
hidinput = list_entry(hid->inputs.next, struct hid_input, list);
dev = hidinput->input;
for (i = 0; i < 4; i++) {
report = hid_validate_values(hid, HID_OUTPUT_REPORT, 0, i, 1);
if (!report)
return -ENODEV;
}
mwctrl = kzalloc_obj(struct mwctrl_device);
if (!mwctrl)
return -ENOMEM;
set_bit(FF_RUMBLE, dev->ffbit);
error = input_ff_create_memless(dev, mwctrl, mwctrl_play);
if (error) {
kfree(mwctrl);
return error;
}
mwctrl->report = report;
/* Field 0 is always 2, and field 1 is always 0. The original
* windows driver has a 5 bytes command, where the 5th byte is
* a repeat of the 3rd byte, however the device has only 4
* fields. It could be a bug in the driver, or there is a
* different device that needs it.
*/
report->field[0]->value[0] = 0x02;
mwctrl->strong = &report->field[2]->value[0];
mwctrl->weak = &report->field[3]->value[0];
return 0;
}
static int mwctrl_probe(struct hid_device *hdev, const struct hid_device_id *id)
{
int ret;
ret = hid_parse(hdev);
if (ret) {
hid_err(hdev, "parse failed\n");
return ret;
}
ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
if (ret) {
hid_err(hdev, "hw start failed\n");
return ret;
}
ret = mwctrl_init(hdev);
if (ret)
hid_hw_stop(hdev);
Annotation
- Immediate include surface: `linux/hid.h`, `linux/input.h`, `linux/module.h`, `linux/slab.h`, `hid-ids.h`.
- Detected declarations: `struct mwctrl_device`, `function mwctrl_play`, `function mwctrl_init`, `function mwctrl_probe`.
- Atlas domain: Driver Families / drivers/hid.
- 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.