drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
Source file repositories/reference/linux-study-clean/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/common/inv_sensors/inv_sensors_timestamp.c- Extension
.c- Size
- 5996 bytes
- Lines
- 206
- 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/errno.hlinux/kernel.hlinux/math64.hlinux/module.hlinux/iio/common/inv_sensors_timestamp.h
Detected Declarations
function Copyrightfunction inv_sensors_timestamp_initfunction inv_sensors_timestamp_update_odrfunction inv_validate_periodfunction inv_update_chip_periodfunction inv_align_timestamp_itfunction inv_sensors_timestamp_interruptfunction inv_sensors_timestamp_apply_odrfunction undertermined
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2020 Invensense, Inc.
*/
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/math64.h>
#include <linux/module.h>
#include <linux/iio/common/inv_sensors_timestamp.h>
/* compute jitter, min and max following jitter in per mille */
#define INV_SENSORS_TIMESTAMP_JITTER(_val, _jitter) \
(div_s64((_val) * (_jitter), 1000))
#define INV_SENSORS_TIMESTAMP_MIN(_val, _jitter) \
(((_val) * (1000 - (_jitter))) / 1000)
#define INV_SENSORS_TIMESTAMP_MAX(_val, _jitter) \
(((_val) * (1000 + (_jitter))) / 1000)
/* Add a new value inside an accumulator and update the estimate value */
static void inv_update_acc(struct inv_sensors_timestamp_acc *acc, uint32_t val)
{
uint64_t sum = 0;
size_t i;
acc->values[acc->idx++] = val;
if (acc->idx >= ARRAY_SIZE(acc->values))
acc->idx = 0;
/* compute the mean of all stored values, use 0 as empty slot */
for (i = 0; i < ARRAY_SIZE(acc->values); ++i) {
if (acc->values[i] == 0)
break;
sum += acc->values[i];
}
acc->val = div_u64(sum, i);
}
void inv_sensors_timestamp_init(struct inv_sensors_timestamp *ts,
const struct inv_sensors_timestamp_chip *chip)
{
memset(ts, 0, sizeof(*ts));
/* save chip parameters and compute min and max clock period */
ts->chip = *chip;
ts->min_period = INV_SENSORS_TIMESTAMP_MIN(chip->clock_period, chip->jitter);
ts->max_period = INV_SENSORS_TIMESTAMP_MAX(chip->clock_period, chip->jitter);
/* current multiplier and period values after reset */
ts->mult = chip->init_period / chip->clock_period;
ts->period = chip->init_period;
/* use theoretical value for chip period */
inv_update_acc(&ts->chip_period, chip->clock_period);
}
EXPORT_SYMBOL_NS_GPL(inv_sensors_timestamp_init, "IIO_INV_SENSORS_TIMESTAMP");
int inv_sensors_timestamp_update_odr(struct inv_sensors_timestamp *ts,
uint32_t period, bool fifo)
{
uint32_t mult;
/* when FIFO is on, prevent odr change if one is already pending */
if (fifo && ts->new_mult != 0)
return -EAGAIN;
mult = period / ts->chip.clock_period;
if (mult != ts->mult)
ts->new_mult = mult;
/* When FIFO is off, directly apply the new ODR */
if (!fifo)
inv_sensors_timestamp_apply_odr(ts, 0, 0, 0);
return 0;
}
EXPORT_SYMBOL_NS_GPL(inv_sensors_timestamp_update_odr, "IIO_INV_SENSORS_TIMESTAMP");
static bool inv_validate_period(struct inv_sensors_timestamp *ts, uint32_t period)
{
uint32_t period_min, period_max;
/* check that period is acceptable */
period_min = ts->min_period * ts->mult;
period_max = ts->max_period * ts->mult;
if (period > period_min && period < period_max)
return true;
else
Annotation
- Immediate include surface: `linux/errno.h`, `linux/kernel.h`, `linux/math64.h`, `linux/module.h`, `linux/iio/common/inv_sensors_timestamp.h`.
- Detected declarations: `function Copyright`, `function inv_sensors_timestamp_init`, `function inv_sensors_timestamp_update_odr`, `function inv_validate_period`, `function inv_update_chip_period`, `function inv_align_timestamp_it`, `function inv_sensors_timestamp_interrupt`, `function inv_sensors_timestamp_apply_odr`, `function undertermined`.
- 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.