drivers/iio/light/hid-sensor-prox.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/hid-sensor-prox.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/hid-sensor-prox.c- Extension
.c- Size
- 10697 bytes
- Lines
- 387
- Domain
- Driver Families
- Bucket
- drivers/iio
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/platform_device.hlinux/module.hlinux/mod_devicetable.hlinux/slab.hlinux/hid-sensor-hub.hlinux/iio/iio.hlinux/iio/buffer.h../common/hid-sensors/hid-sensor-trigger.h
Detected Declarations
struct prox_statefunction prox_adjust_channel_bit_maskfunction prox_read_rawfunction prox_write_rawfunction prox_proc_eventfunction prox_capture_samplefunction prox_parse_reportfunction hid_prox_probefunction hid_prox_remove
Annotated Snippet
struct prox_state {
struct hid_sensor_hub_callbacks callbacks;
struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info prox_attr[MAX_CHANNELS];
struct iio_chan_spec channels[MAX_CHANNELS];
u32 channel2usage[MAX_CHANNELS];
u32 human_presence[MAX_CHANNELS];
int scale_pre_decml[MAX_CHANNELS];
int scale_post_decml[MAX_CHANNELS];
int scale_precision[MAX_CHANNELS];
unsigned long scan_mask[2]; /* One entry plus one terminator. */
int num_channels;
};
static const u32 prox_sensitivity_addresses[] = {
HID_USAGE_SENSOR_HUMAN_PRESENCE,
HID_USAGE_SENSOR_DATA_PRESENCE,
};
#define PROX_CHANNEL(_is_proximity, _channel) \
{\
.type = _is_proximity ? IIO_PROXIMITY : IIO_ATTENTION,\
.info_mask_separate = \
(_is_proximity ? BIT(IIO_CHAN_INFO_RAW) :\
BIT(IIO_CHAN_INFO_PROCESSED)) |\
BIT(IIO_CHAN_INFO_OFFSET) |\
BIT(IIO_CHAN_INFO_SCALE) |\
BIT(IIO_CHAN_INFO_SAMP_FREQ) |\
BIT(IIO_CHAN_INFO_HYSTERESIS),\
.indexed = _is_proximity,\
.channel = _channel,\
}
/* Channel definitions (same order as prox_usage_ids) */
static const struct iio_chan_spec prox_channels[] = {
PROX_CHANNEL(true, HID_HUMAN_PRESENCE),
PROX_CHANNEL(true, HID_HUMAN_PROXIMITY),
PROX_CHANNEL(false, 0),
};
/* Adjust channel real bits based on report descriptor */
static void prox_adjust_channel_bit_mask(struct iio_chan_spec *channels,
int channel, int size)
{
channels[channel].scan_type.sign = 's';
/* Real storage bits will change based on the report desc. */
channels[channel].scan_type.realbits = size * 8;
/* Maximum size of a sample to capture is u32 */
channels[channel].scan_type.storagebits = sizeof(u32) * 8;
}
/* Channel read_raw handler */
static int prox_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2,
long mask)
{
struct prox_state *prox_state = iio_priv(indio_dev);
struct hid_sensor_hub_device *hsdev;
int report_id;
u32 address;
int ret_type;
s32 min;
*val = 0;
*val2 = 0;
switch (mask) {
case IIO_CHAN_INFO_RAW:
case IIO_CHAN_INFO_PROCESSED:
if (chan->scan_index >= prox_state->num_channels)
return -EINVAL;
address = prox_state->channel2usage[chan->scan_index];
report_id = prox_state->prox_attr[chan->scan_index].report_id;
hsdev = prox_state->common_attributes.hsdev;
min = prox_state->prox_attr[chan->scan_index].logical_minimum;
hid_sensor_power_state(&prox_state->common_attributes, true);
*val = sensor_hub_input_attr_get_raw_value(hsdev,
hsdev->usage,
address,
report_id,
SENSOR_HUB_SYNC,
min < 0);
if (prox_state->channel2usage[chan->scan_index] ==
HID_USAGE_SENSOR_HUMAN_ATTENTION)
*val *= 100;
hid_sensor_power_state(&prox_state->common_attributes, false);
ret_type = IIO_VAL_INT;
break;
case IIO_CHAN_INFO_SCALE:
if (chan->scan_index >= prox_state->num_channels)
Annotation
- Immediate include surface: `linux/device.h`, `linux/platform_device.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/slab.h`, `linux/hid-sensor-hub.h`, `linux/iio/iio.h`, `linux/iio/buffer.h`.
- Detected declarations: `struct prox_state`, `function prox_adjust_channel_bit_mask`, `function prox_read_raw`, `function prox_write_raw`, `function prox_proc_event`, `function prox_capture_sample`, `function prox_parse_report`, `function hid_prox_probe`, `function hid_prox_remove`.
- Atlas domain: Driver Families / drivers/iio.
- 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.