drivers/iio/common/st_sensors/st_sensors_trigger.c
Source file repositories/reference/linux-study-clean/drivers/iio/common/st_sensors/st_sensors_trigger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/common/st_sensors/st_sensors_trigger.c- Extension
.c- Size
- 6968 bytes
- Lines
- 241
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/iio/iio.hlinux/iio/trigger.hlinux/interrupt.hlinux/regmap.hlinux/iio/common/st_sensors.hst_sensors_core.h
Detected Declarations
function st_sensors_new_samples_availablefunction st_sensors_irq_handlerfunction st_sensors_irq_threadfunction st_sensors_new_samples_availablefunction st_sensors_new_samples_availablefunction st_sensors_allocate_triggerfunction st_sensors_validate_device
Annotated Snippet
st_sensors_new_samples_available(indio_dev, sdata)) {
iio_trigger_poll_nested(p);
} else {
dev_dbg(indio_dev->dev.parent, "spurious IRQ\n");
return IRQ_NONE;
}
/*
* If we have proper level IRQs the handler will be re-entered if
* the line is still active, so return here and come back in through
* the top half if need be.
*/
if (!sdata->edge_irq)
return IRQ_HANDLED;
/*
* If we are using edge IRQs, new samples arrived while processing
* the IRQ and those may be missed unless we pick them here, so poll
* again. If the sensor delivery frequency is very high, this thread
* turns into a polled loop handler.
*/
while (sdata->hw_irq_trigger &&
st_sensors_new_samples_available(indio_dev, sdata)) {
dev_dbg(indio_dev->dev.parent,
"more samples came in during polling\n");
sdata->hw_timestamp = iio_get_time_ns(indio_dev);
iio_trigger_poll_nested(p);
}
return IRQ_HANDLED;
}
int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
const struct iio_trigger_ops *trigger_ops)
{
struct st_sensor_data *sdata = iio_priv(indio_dev);
struct device *parent = indio_dev->dev.parent;
unsigned long irq_trig;
int err;
sdata->trig = devm_iio_trigger_alloc(parent, "%s-trigger",
indio_dev->name);
if (sdata->trig == NULL) {
dev_err(parent, "failed to allocate iio trigger.\n");
return -ENOMEM;
}
iio_trigger_set_drvdata(sdata->trig, indio_dev);
sdata->trig->ops = trigger_ops;
/*
* If the IRQ is triggered on falling edge, we need to mark the
* interrupt as active low, if the hardware supports this.
*/
irq_trig = irq_get_trigger_type(sdata->irq);
switch(irq_trig) {
case IRQF_TRIGGER_FALLING:
case IRQF_TRIGGER_LOW:
if (!sdata->sensor_settings->drdy_irq.addr_ihl) {
dev_err(parent,
"falling/low specified for IRQ but hardware supports only rising/high: will request rising/high\n");
if (irq_trig == IRQF_TRIGGER_FALLING)
irq_trig = IRQF_TRIGGER_RISING;
if (irq_trig == IRQF_TRIGGER_LOW)
irq_trig = IRQF_TRIGGER_HIGH;
} else {
/* Set up INT active low i.e. falling edge */
err = st_sensors_write_data_with_mask(indio_dev,
sdata->sensor_settings->drdy_irq.addr_ihl,
sdata->sensor_settings->drdy_irq.mask_ihl, 1);
if (err < 0)
return err;
dev_info(parent,
"interrupts on the falling edge or active low level\n");
}
break;
case IRQF_TRIGGER_RISING:
dev_info(parent, "interrupts on the rising edge\n");
break;
case IRQF_TRIGGER_HIGH:
dev_info(parent, "interrupts active high level\n");
break;
default:
/* This is the most preferred mode, if possible */
dev_err(parent,
"unsupported IRQ trigger specified (%lx), enforce rising edge\n", irq_trig);
irq_trig = IRQF_TRIGGER_RISING;
}
/* Tell the interrupt handler that we're dealing with edges */
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/iio/iio.h`, `linux/iio/trigger.h`, `linux/interrupt.h`, `linux/regmap.h`, `linux/iio/common/st_sensors.h`, `st_sensors_core.h`.
- Detected declarations: `function st_sensors_new_samples_available`, `function st_sensors_irq_handler`, `function st_sensors_irq_thread`, `function st_sensors_new_samples_available`, `function st_sensors_new_samples_available`, `function st_sensors_allocate_trigger`, `function st_sensors_validate_device`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: integration implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.