drivers/iio/adc/envelope-detector.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/envelope-detector.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/envelope-detector.c- Extension
.c- Size
- 10778 bytes
- Lines
- 409
- 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.
- 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/completion.hlinux/device.hlinux/err.hlinux/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/mutex.hlinux/iio/consumer.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/interrupt.hlinux/irq.hlinux/platform_device.hlinux/spinlock.hlinux/workqueue.h
Detected Declarations
struct envelopefunction belowfunction envelope_detector_comp_isrfunction envelope_detector_setup_comparefunction envelope_detector_timeoutfunction envelope_detector_read_rawfunction envelope_show_invertfunction envelope_store_invertfunction envelope_show_comp_intervalfunction envelope_store_comp_intervalfunction envelope_detector_probe
Annotated Snippet
struct envelope {
spinlock_t comp_lock; /* protects comp */
int comp;
struct mutex read_lock; /* protects everything else */
int comp_irq;
u32 comp_irq_trigger;
u32 comp_irq_trigger_inv;
struct iio_channel *dac;
struct delayed_work comp_timeout;
unsigned int comp_interval;
bool invert;
u32 dac_max;
int high;
int level;
int low;
struct completion done;
};
/*
* The envelope_detector_comp_latch function works together with the compare
* interrupt service routine below (envelope_detector_comp_isr) as a latch
* (one-bit memory) for if the interrupt has triggered since last calling
* this function.
* The ..._comp_isr function disables the interrupt so that the cpu does not
* need to service a possible interrupt flood from the comparator when no-one
* cares anyway, and this ..._comp_latch function reenables them again if
* needed.
*/
static int envelope_detector_comp_latch(struct envelope *env)
{
int comp;
spin_lock_irq(&env->comp_lock);
comp = env->comp;
env->comp = 0;
spin_unlock_irq(&env->comp_lock);
if (!comp)
return 0;
/*
* The irq was disabled, and is reenabled just now.
* But there might have been a pending irq that
* happened while the irq was disabled that fires
* just as the irq is reenabled. That is not what
* is desired.
*/
enable_irq(env->comp_irq);
/* So, synchronize this possibly pending irq... */
synchronize_irq(env->comp_irq);
/* ...and redo the whole dance. */
spin_lock_irq(&env->comp_lock);
comp = env->comp;
env->comp = 0;
spin_unlock_irq(&env->comp_lock);
if (comp)
enable_irq(env->comp_irq);
return 1;
}
static irqreturn_t envelope_detector_comp_isr(int irq, void *ctx)
{
struct envelope *env = ctx;
spin_lock(&env->comp_lock);
env->comp = 1;
disable_irq_nosync(env->comp_irq);
spin_unlock(&env->comp_lock);
return IRQ_HANDLED;
}
static void envelope_detector_setup_compare(struct envelope *env)
{
int ret;
/*
* Do a binary search for the peak input level, and stop
* when that level is "trapped" between two adjacent DAC
* values.
Annotation
- Immediate include surface: `linux/completion.h`, `linux/device.h`, `linux/err.h`, `linux/kernel.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/mutex.h`, `linux/iio/consumer.h`.
- Detected declarations: `struct envelope`, `function below`, `function envelope_detector_comp_isr`, `function envelope_detector_setup_compare`, `function envelope_detector_timeout`, `function envelope_detector_read_raw`, `function envelope_show_invert`, `function envelope_store_invert`, `function envelope_show_comp_interval`, `function envelope_store_comp_interval`.
- 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.
- 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.