drivers/iio/dummy/iio_simple_dummy_buffer.c
Source file repositories/reference/linux-study-clean/drivers/iio/dummy/iio_simple_dummy_buffer.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/dummy/iio_simple_dummy_buffer.c- Extension
.c- Size
- 3348 bytes
- Lines
- 118
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/export.hlinux/slab.hlinux/interrupt.hlinux/irq.hlinux/bitmap.hlinux/iio/iio.hlinux/iio/buffer.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.hiio_simple_dummy.h
Detected Declarations
struct dummy_scanfunction iio_simple_dummy_trigger_hfunction iio_simple_dummy_configure_bufferfunction iio_simple_dummy_unconfigure_buffer
Annotated Snippet
struct dummy_scan {
s16 data[ARRAY_SIZE(fakedata)];
aligned_s64 timestamp;
};
/**
* iio_simple_dummy_trigger_h() - the trigger handler function
* @irq: the interrupt number
* @p: private data - always a pointer to the poll func.
*
* This is the guts of buffered capture. On a trigger event occurring,
* if the pollfunc is attached then this handler is called as a threaded
* interrupt (and hence may sleep). It is responsible for grabbing data
* from the device and pushing it into the associated buffer.
*/
static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
{
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->indio_dev;
struct dummy_scan *scan;
int i = 0, j;
/*
* Note that some buses such as SPI require DMA safe buffers which
* cannot be on the stack. Two easy ways to do this:
* - Local kzalloc (as done here)
* - A buffer at the end of the structure accessed via iio_priv()
* that is marked __aligned(IIO_DMA_MINALIGN).
*/
scan = kzalloc_obj(*scan);
if (!scan)
goto done;
/*
* Three common options here:
* hardware scans:
* certain combinations of channels make up a fast read. The capture
* will consist of all of them. Hence we just call the grab data
* function and fill the buffer without processing.
* software scans:
* can be considered to be random access so efficient reading is just
* a case of minimal bus transactions.
* software culled hardware scans:
* occasionally a driver may process the nearest hardware scan to avoid
* storing elements that are not desired. This is the fiddliest option
* by far.
* Here let's pretend we have random access. And the values are in the
* constant table fakedata.
*/
iio_for_each_active_channel(indio_dev, j)
scan->data[i++] = fakedata[j];
iio_push_to_buffers_with_ts(indio_dev, scan, sizeof(*scan),
iio_get_time_ns(indio_dev));
kfree(scan);
done:
/*
* Tell the core we are done with this trigger and ready for the
* next one.
*/
iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED;
}
static const struct iio_buffer_setup_ops iio_simple_dummy_buffer_setup_ops = {
};
int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
{
return iio_triggered_buffer_setup(indio_dev, NULL,
iio_simple_dummy_trigger_h,
&iio_simple_dummy_buffer_setup_ops);
}
/**
* iio_simple_dummy_unconfigure_buffer() - release buffer resources
* @indio_dev: device instance state
*/
void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev)
{
iio_triggered_buffer_cleanup(indio_dev);
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/export.h`, `linux/slab.h`, `linux/interrupt.h`, `linux/irq.h`, `linux/bitmap.h`, `linux/iio/iio.h`, `linux/iio/buffer.h`.
- Detected declarations: `struct dummy_scan`, `function iio_simple_dummy_trigger_h`, `function iio_simple_dummy_configure_buffer`, `function iio_simple_dummy_unconfigure_buffer`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source 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.