drivers/iio/trigger/iio-trig-hrtimer.c
Source file repositories/reference/linux-study-clean/drivers/iio/trigger/iio-trig-hrtimer.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/trigger/iio-trig-hrtimer.c- Extension
.c- Size
- 5183 bytes
- Lines
- 201
- 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.
- 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/kernel.hlinux/slab.hlinux/hrtimer.hlinux/iio/iio.hlinux/iio/trigger.hlinux/iio/sw_trigger.h
Detected Declarations
struct iio_hrtimer_infofunction iio_hrtimer_show_sampling_frequencyfunction iio_hrtimer_store_sampling_frequencyfunction iio_hrtimer_trig_handlerfunction iio_trig_hrtimer_set_statefunction iio_trig_hrtimer_remove
Annotated Snippet
struct iio_hrtimer_info {
struct iio_sw_trigger swt;
struct hrtimer timer;
int sampling_frequency[2];
ktime_t period;
};
static const struct config_item_type iio_hrtimer_type = {
.ct_owner = THIS_MODULE,
};
static
ssize_t iio_hrtimer_show_sampling_frequency(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct iio_trigger *trig = to_iio_trigger(dev);
struct iio_hrtimer_info *info = iio_trigger_get_drvdata(trig);
return iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO,
ARRAY_SIZE(info->sampling_frequency),
info->sampling_frequency);
}
static
ssize_t iio_hrtimer_store_sampling_frequency(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t len)
{
struct iio_trigger *trig = to_iio_trigger(dev);
struct iio_hrtimer_info *info = iio_trigger_get_drvdata(trig);
unsigned long long val;
u64 period;
int integer, fract, ret;
ret = iio_str_to_fixpoint(buf, 100, &integer, &fract);
if (ret)
return ret;
if (integer < 0 || fract < 0)
return -ERANGE;
val = fract + 1000ULL * integer; /* mHz */
if (!val || val > UINT_MAX)
return -EINVAL;
info->sampling_frequency[0] = integer; /* Hz */
info->sampling_frequency[1] = fract * 1000; /* uHz */
period = PSEC_PER_SEC;
do_div(period, val);
info->period = period; /* nS */
return len;
}
static DEVICE_ATTR(sampling_frequency, S_IRUGO | S_IWUSR,
iio_hrtimer_show_sampling_frequency,
iio_hrtimer_store_sampling_frequency);
static struct attribute *iio_hrtimer_attrs[] = {
&dev_attr_sampling_frequency.attr,
NULL
};
static const struct attribute_group iio_hrtimer_attr_group = {
.attrs = iio_hrtimer_attrs,
};
static const struct attribute_group *iio_hrtimer_attr_groups[] = {
&iio_hrtimer_attr_group,
NULL
};
static enum hrtimer_restart iio_hrtimer_trig_handler(struct hrtimer *timer)
{
struct iio_hrtimer_info *info;
info = container_of(timer, struct iio_hrtimer_info, timer);
hrtimer_forward_now(timer, info->period);
iio_trigger_poll(info->swt.trigger);
return HRTIMER_RESTART;
}
static int iio_trig_hrtimer_set_state(struct iio_trigger *trig, bool state)
{
struct iio_hrtimer_info *trig_info;
trig_info = iio_trigger_get_drvdata(trig);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/slab.h`, `linux/hrtimer.h`, `linux/iio/iio.h`, `linux/iio/trigger.h`, `linux/iio/sw_trigger.h`.
- Detected declarations: `struct iio_hrtimer_info`, `function iio_hrtimer_show_sampling_frequency`, `function iio_hrtimer_store_sampling_frequency`, `function iio_hrtimer_trig_handler`, `function iio_trig_hrtimer_set_state`, `function iio_trig_hrtimer_remove`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source 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.