drivers/hid/hid-steam.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-steam.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-steam.c- Extension
.c- Size
- 55756 bytes
- Lines
- 1881
- 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/input.hlinux/hid.hlinux/module.hlinux/workqueue.hlinux/mutex.hlinux/rcupdate.hlinux/delay.hlinux/power_supply.hhid-ids.h
Detected Declarations
struct steam_devicefunction steam_recv_reportfunction steam_send_reportfunction steam_send_report_bytefunction steam_write_settingsfunction steam_get_serialfunction steam_request_conn_statusfunction steam_haptic_pulsefunction steam_haptic_rumblefunction steam_haptic_rumble_cbfunction steam_play_effectfunction steam_set_lizard_modefunction steam_input_openfunction steam_input_closefunction steam_battery_get_propertyfunction steam_battery_registerfunction steam_input_registerfunction steam_sensors_registerfunction steam_input_unregisterfunction steam_sensors_unregisterfunction steam_battery_unregisterfunction steam_registerfunction steam_unregisterfunction steam_work_connect_cbfunction steam_mode_switch_cbfunction steam_work_unregister_cbfunction steam_is_valve_interfacefunction steam_client_ll_parsefunction steam_client_ll_startfunction steam_client_ll_stopfunction steam_client_ll_closefunction steam_client_ll_raw_requestfunction steam_probefunction steam_removefunction steam_do_connect_eventfunction steam_le16function steam_do_input_eventfunction steam_do_deck_input_eventfunction steam_do_deck_sensors_eventfunction steam_do_battery_eventfunction steam_raw_eventfunction steam_param_set_lizard_mode
Annotated Snippet
struct steam_device {
struct list_head list;
spinlock_t lock;
struct hid_device *hdev, *client_hdev;
struct mutex report_mutex;
unsigned long client_opened;
struct input_dev __rcu *input;
struct input_dev __rcu *sensors;
unsigned long quirks;
struct work_struct work_connect;
bool connected;
char serial_no[STEAM_SERIAL_LEN + 1];
struct power_supply_desc battery_desc;
struct power_supply __rcu *battery;
u8 battery_charge;
u16 voltage;
struct delayed_work mode_switch;
bool did_mode_switch;
bool gamepad_mode;
struct work_struct rumble_work;
u16 rumble_left;
u16 rumble_right;
unsigned int sensor_timestamp_us;
struct work_struct unregister_work;
};
static int steam_recv_report(struct steam_device *steam,
u8 *data, int size)
{
struct hid_report *r;
u8 *buf;
int ret;
r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0];
if (!r) {
hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted - nothing to read\n");
return -EINVAL;
}
if (hid_report_len(r) < 64)
return -EINVAL;
buf = hid_alloc_report_buf(r, GFP_KERNEL);
if (!buf)
return -ENOMEM;
/*
* The report ID is always 0, so strip the first byte from the output.
* hid_report_len() is not counting the report ID, so +1 to the length
* or else we get a EOVERFLOW. We are safe from a buffer overflow
* because hid_alloc_report_buf() allocates +7 bytes.
*/
ret = hid_hw_raw_request(steam->hdev, 0x00,
buf, hid_report_len(r) + 1,
HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
if (ret > 0)
memcpy(data, buf + 1, min(size, ret - 1));
kfree(buf);
return ret;
}
static int steam_send_report(struct steam_device *steam,
u8 *cmd, int size)
{
struct hid_report *r;
u8 *buf;
unsigned int retries = 50;
int ret;
r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0];
if (!r) {
hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted - nothing to read\n");
return -EINVAL;
}
if (hid_report_len(r) < 64)
return -EINVAL;
buf = hid_alloc_report_buf(r, GFP_KERNEL);
if (!buf)
return -ENOMEM;
/* The report ID is always 0 */
memcpy(buf + 1, cmd, size);
/*
* Sometimes the wireless controller fails with EPIPE
* when sending a feature report.
* Doing a HID_REQ_GET_REPORT and waiting for a while
* seems to fix that.
Annotation
- Immediate include surface: `linux/device.h`, `linux/input.h`, `linux/hid.h`, `linux/module.h`, `linux/workqueue.h`, `linux/mutex.h`, `linux/rcupdate.h`, `linux/delay.h`.
- Detected declarations: `struct steam_device`, `function steam_recv_report`, `function steam_send_report`, `function steam_send_report_byte`, `function steam_write_settings`, `function steam_get_serial`, `function steam_request_conn_status`, `function steam_haptic_pulse`, `function steam_haptic_rumble`, `function steam_haptic_rumble_cb`.
- 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.