drivers/hid/hid-mf.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-mf.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-mf.c- Extension
.c- Size
- 4455 bytes
- Lines
- 171
- 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/input.hlinux/slab.hlinux/hid.hlinux/module.hhid-ids.h
Detected Declarations
struct mf_devicefunction mf_playfunction mf_initfunction mf_probe
Annotated Snippet
struct mf_device {
struct hid_report *report;
};
static int mf_play(struct input_dev *dev, void *data, struct ff_effect *effect)
{
struct hid_device *hid = input_get_drvdata(dev);
struct mf_device *mf = data;
int strong, weak;
strong = effect->u.rumble.strong_magnitude;
weak = effect->u.rumble.weak_magnitude;
dbg_hid("Called with 0x%04x 0x%04x.\n", strong, weak);
strong = strong * 0xff / 0xffff;
weak = weak * 0xff / 0xffff;
dbg_hid("Running with 0x%02x 0x%02x.\n", strong, weak);
mf->report->field[0]->value[0] = weak;
mf->report->field[0]->value[1] = strong;
hid_hw_request(hid, mf->report, HID_REQ_SET_REPORT);
return 0;
}
static int mf_init(struct hid_device *hid)
{
struct mf_device *mf;
struct list_head *report_list =
&hid->report_enum[HID_OUTPUT_REPORT].report_list;
struct list_head *report_ptr;
struct hid_report *report;
struct list_head *input_ptr = &hid->inputs;
struct hid_input *input;
struct input_dev *dev;
int error;
/* Setup each of the four inputs */
list_for_each(report_ptr, report_list) {
report = list_entry(report_ptr, struct hid_report, list);
if (report->maxfield < 1 || report->field[0]->report_count < 2) {
hid_err(hid, "Invalid report, this should never happen!\n");
return -ENODEV;
}
if (list_is_last(input_ptr, &hid->inputs)) {
hid_err(hid, "Missing input, this should never happen!\n");
return -ENODEV;
}
input_ptr = input_ptr->next;
input = list_entry(input_ptr, struct hid_input, list);
mf = kzalloc_obj(struct mf_device);
if (!mf)
return -ENOMEM;
dev = input->input;
set_bit(FF_RUMBLE, dev->ffbit);
error = input_ff_create_memless(dev, mf, mf_play);
if (error) {
kfree(mf);
return error;
}
mf->report = report;
mf->report->field[0]->value[0] = 0x00;
mf->report->field[0]->value[1] = 0x00;
hid_hw_request(hid, mf->report, HID_REQ_SET_REPORT);
}
hid_info(hid, "Force feedback for HJZ Mayflash game controller "
"adapters by Marcel Hasler <mahasler@gmail.com>\n");
return 0;
}
static int mf_probe(struct hid_device *hid, const struct hid_device_id *id)
{
int error;
Annotation
- Immediate include surface: `linux/input.h`, `linux/slab.h`, `linux/hid.h`, `linux/module.h`, `hid-ids.h`.
- Detected declarations: `struct mf_device`, `function mf_play`, `function mf_init`, `function mf_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.