drivers/iio/common/hid-sensors/hid-sensor-attributes.c
Source file repositories/reference/linux-study-clean/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/common/hid-sensors/hid-sensor-attributes.c- Extension
.c- Size
- 15450 bytes
- Lines
- 595
- Domain
- Driver Families
- Bucket
- drivers/iio
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/kernel.hlinux/time.hlinux/units.hlinux/hid-sensor-hub.hlinux/iio/iio.h
Detected Declarations
function simple_divfunction split_micro_fractionfunction convert_from_vtf_formatfunction convert_to_vtf_formatfunction hid_sensor_read_poll_valuefunction hid_sensor_read_samp_freq_valuefunction hid_sensor_write_samp_freq_valuefunction hid_sensor_read_raw_hyst_valuefunction hid_sensor_read_raw_hyst_rel_valuefunction hid_sensor_write_raw_hyst_valuefunction hid_sensor_write_raw_hyst_rel_valuefunction adjust_exponent_nanofunction hid_sensor_format_scalefunction hid_sensor_convert_timestampfunction hid_sensor_get_reporting_intervalfunction hid_sensor_get_report_latency_infofunction hid_sensor_get_report_latencyfunction hid_sensor_set_report_latencyfunction hid_sensor_batch_mode_supportedfunction hid_sensor_parse_common_attributes
Annotated Snippet
while (rem <= divisor) {
rem *= 10;
exp++;
}
*micro_frac = (rem / divisor) * int_pow(10, 6 - exp);
}
}
static void split_micro_fraction(unsigned int no, int exp, int *val1, int *val2)
{
int divisor = int_pow(10, exp);
*val1 = no / divisor;
*val2 = no % divisor * int_pow(10, 6 - exp);
}
/*
VTF format uses exponent and variable size format.
For example if the size is 2 bytes
0x0067 with VTF16E14 format -> +1.03
To convert just change to 0x67 to decimal and use two decimal as E14 stands
for 10^-2.
Negative numbers are 2's complement
*/
static void convert_from_vtf_format(u32 value, int size, int exp,
int *val1, int *val2)
{
int sign = 1;
if (value & BIT(size*8 - 1)) {
value = ((1LL << (size * 8)) - value);
sign = -1;
}
exp = hid_sensor_convert_exponent(exp);
if (exp >= 0) {
*val1 = sign * value * int_pow(10, exp);
*val2 = 0;
} else {
split_micro_fraction(value, -exp, val1, val2);
if (*val1)
*val1 = sign * (*val1);
else
*val2 = sign * (*val2);
}
}
static u32 convert_to_vtf_format(int size, int exp, int val1, int val2)
{
int divisor;
u32 value;
int sign = 1;
if (val1 < 0 || val2 < 0)
sign = -1;
exp = hid_sensor_convert_exponent(exp);
if (exp < 0) {
divisor = int_pow(10, 6 + exp);
value = abs(val1) * int_pow(10, -exp);
value += abs(val2) / divisor;
} else {
divisor = int_pow(10, exp);
value = abs(val1) / divisor;
}
if (sign < 0)
value = ((1LL << (size * 8)) - value);
return value;
}
s32 hid_sensor_read_poll_value(struct hid_sensor_common *st)
{
s32 value = 0;
int ret;
ret = sensor_hub_get_feature(st->hsdev,
st->poll.report_id,
st->poll.index, sizeof(value), &value);
if (ret < 0 || value < 0) {
return -EINVAL;
} else {
if (st->poll.units == HID_USAGE_SENSOR_UNITS_SECOND)
value = value * 1000;
}
return value;
}
EXPORT_SYMBOL_NS(hid_sensor_read_poll_value, "IIO_HID_ATTRIBUTES");
int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/time.h`, `linux/units.h`, `linux/hid-sensor-hub.h`, `linux/iio/iio.h`.
- Detected declarations: `function simple_div`, `function split_micro_fraction`, `function convert_from_vtf_format`, `function convert_to_vtf_format`, `function hid_sensor_read_poll_value`, `function hid_sensor_read_samp_freq_value`, `function hid_sensor_write_samp_freq_value`, `function hid_sensor_read_raw_hyst_value`, `function hid_sensor_read_raw_hyst_rel_value`, `function hid_sensor_write_raw_hyst_value`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: integration 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.