drivers/hid/hid-sensor-hub.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-sensor-hub.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-sensor-hub.c- Extension
.c- Size
- 21831 bytes
- Lines
- 782
- Domain
- Driver Families
- Bucket
- drivers/hid
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/module.hlinux/slab.hlinux/mfd/core.hlinux/list.hlinux/hid-sensor-ids.hlinux/hid-sensor-hub.hhid-ids.h
Detected Declarations
struct sensor_hub_datastruct hid_sensor_hub_callbacks_listfunction list_for_each_entryfunction sensor_hub_get_physical_device_countfunction sensor_hub_fill_attr_infofunction sensor_hub_register_callbackfunction sensor_hub_remove_callbackfunction sensor_hub_set_featurefunction sensor_hub_get_featurefunction sensor_hub_input_attr_get_raw_valuefunction hid_sensor_get_usage_indexfunction sensor_hub_input_get_attribute_infofunction sensor_hub_suspendfunction sensor_hub_resumefunction sensor_hub_reset_resumefunction sensor_hub_raw_eventfunction sensor_hub_device_openfunction sensor_hub_device_closefunction sensor_hub_probefunction sensor_hub_finalize_pending_fnfunction sensor_hub_removeexport sensor_hub_register_callbackexport sensor_hub_remove_callbackexport sensor_hub_set_featureexport sensor_hub_get_featureexport sensor_hub_input_attr_get_raw_valueexport hid_sensor_get_usage_indexexport sensor_hub_input_get_attribute_infoexport sensor_hub_device_openexport sensor_hub_device_close
Annotated Snippet
struct sensor_hub_data {
struct mutex mutex;
spinlock_t lock;
struct list_head dyn_callback_list;
spinlock_t dyn_callback_lock;
struct mfd_cell *hid_sensor_hub_client_devs;
int hid_sensor_client_cnt;
int ref_cnt;
};
/**
* struct hid_sensor_hub_callbacks_list - Stores callback list
* @list: list head.
* @usage_id: usage id for a physical device.
* @hsdev: Stored hid instance for current hub device.
* @usage_callback: Stores registered callback functions.
* @priv: Private data for a physical device.
*/
struct hid_sensor_hub_callbacks_list {
struct list_head list;
u32 usage_id;
struct hid_sensor_hub_device *hsdev;
struct hid_sensor_hub_callbacks *usage_callback;
void *priv;
};
static struct hid_report *sensor_hub_report(int id, struct hid_device *hdev,
int dir)
{
struct hid_report *report;
list_for_each_entry(report, &hdev->report_enum[dir].report_list, list) {
if (report->id == id)
return report;
}
hid_warn(hdev, "No report with id 0x%x found\n", id);
return NULL;
}
static int sensor_hub_get_physical_device_count(struct hid_device *hdev)
{
int i;
int count = 0;
for (i = 0; i < hdev->maxcollection; ++i) {
struct hid_collection *collection = &hdev->collection[i];
if (collection->type == HID_COLLECTION_PHYSICAL ||
collection->type == HID_COLLECTION_APPLICATION)
++count;
}
return count;
}
static void sensor_hub_fill_attr_info(
struct hid_sensor_hub_attribute_info *info,
s32 index, s32 report_id, struct hid_field *field)
{
info->index = index;
info->report_id = report_id;
info->units = field->unit;
info->unit_expo = field->unit_exponent;
info->size = (field->report_size * field->report_count)/8;
info->logical_minimum = field->logical_minimum;
info->logical_maximum = field->logical_maximum;
}
static struct hid_sensor_hub_callbacks *sensor_hub_get_callback(
struct hid_device *hdev,
u32 usage_id,
int collection_index,
struct hid_sensor_hub_device **hsdev,
void **priv)
{
struct hid_sensor_hub_callbacks_list *callback;
struct sensor_hub_data *pdata = hid_get_drvdata(hdev);
unsigned long flags;
spin_lock_irqsave(&pdata->dyn_callback_lock, flags);
list_for_each_entry(callback, &pdata->dyn_callback_list, list)
if ((callback->usage_id == usage_id ||
callback->usage_id == HID_USAGE_SENSOR_COLLECTION) &&
(collection_index >=
callback->hsdev->start_collection_index) &&
(collection_index <
callback->hsdev->end_collection_index)) {
*priv = callback->priv;
*hsdev = callback->hsdev;
spin_unlock_irqrestore(&pdata->dyn_callback_lock,
Annotation
- Immediate include surface: `linux/device.h`, `linux/hid.h`, `linux/module.h`, `linux/slab.h`, `linux/mfd/core.h`, `linux/list.h`, `linux/hid-sensor-ids.h`, `linux/hid-sensor-hub.h`.
- Detected declarations: `struct sensor_hub_data`, `struct hid_sensor_hub_callbacks_list`, `function list_for_each_entry`, `function sensor_hub_get_physical_device_count`, `function sensor_hub_fill_attr_info`, `function sensor_hub_register_callback`, `function sensor_hub_remove_callback`, `function sensor_hub_set_feature`, `function sensor_hub_get_feature`, `function sensor_hub_input_attr_get_raw_value`.
- Atlas domain: Driver Families / drivers/hid.
- Implementation status: integration 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.