drivers/hid/hid-emsff.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-emsff.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-emsff.c- Extension
.c- Size
- 3372 bytes
- Lines
- 150
- 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.hhid-ids.h
Detected Declarations
struct emsff_devicefunction emsff_playfunction emsff_initfunction ems_probe
Annotated Snippet
struct emsff_device {
struct hid_report *report;
};
static int emsff_play(struct input_dev *dev, void *data,
struct ff_effect *effect)
{
struct hid_device *hid = input_get_drvdata(dev);
struct emsff_device *emsff = data;
int weak, strong;
weak = effect->u.rumble.weak_magnitude;
strong = effect->u.rumble.strong_magnitude;
dbg_hid("called with 0x%04x 0x%04x\n", strong, weak);
weak = weak * 0xff / 0xffff;
strong = strong * 0xff / 0xffff;
emsff->report->field[0]->value[1] = weak;
emsff->report->field[0]->value[2] = strong;
dbg_hid("running with 0x%02x 0x%02x\n", strong, weak);
hid_hw_request(hid, emsff->report, HID_REQ_SET_REPORT);
return 0;
}
static int emsff_init(struct hid_device *hid)
{
struct emsff_device *emsff;
struct hid_report *report;
struct hid_input *hidinput;
struct list_head *report_list =
&hid->report_enum[HID_OUTPUT_REPORT].report_list;
struct input_dev *dev;
int error;
if (list_empty(&hid->inputs)) {
hid_err(hid, "no inputs found\n");
return -ENODEV;
}
hidinput = list_first_entry(&hid->inputs, struct hid_input, list);
dev = hidinput->input;
if (list_empty(report_list)) {
hid_err(hid, "no output reports found\n");
return -ENODEV;
}
report = list_first_entry(report_list, struct hid_report, list);
if (report->maxfield < 1) {
hid_err(hid, "no fields in the report\n");
return -ENODEV;
}
if (report->field[0]->report_count < 7) {
hid_err(hid, "not enough values in the field\n");
return -ENODEV;
}
emsff = kzalloc_obj(struct emsff_device);
if (!emsff)
return -ENOMEM;
set_bit(FF_RUMBLE, dev->ffbit);
error = input_ff_create_memless(dev, emsff, emsff_play);
if (error) {
kfree(emsff);
return error;
}
emsff->report = report;
emsff->report->field[0]->value[0] = 0x01;
emsff->report->field[0]->value[1] = 0x00;
emsff->report->field[0]->value[2] = 0x00;
emsff->report->field[0]->value[3] = 0x00;
emsff->report->field[0]->value[4] = 0x00;
emsff->report->field[0]->value[5] = 0x00;
emsff->report->field[0]->value[6] = 0x00;
hid_hw_request(hid, emsff->report, HID_REQ_SET_REPORT);
hid_info(hid, "force feedback for EMS based devices by Ignaz Forster <ignaz.forster@gmx.de>\n");
return 0;
}
static int ems_probe(struct hid_device *hdev, const struct hid_device_id *id)
{
Annotation
- Immediate include surface: `linux/hid.h`, `linux/input.h`, `linux/module.h`, `hid-ids.h`.
- Detected declarations: `struct emsff_device`, `function emsff_play`, `function emsff_init`, `function ems_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.