drivers/iio/multiplexer/iio-mux.c
Source file repositories/reference/linux-study-clean/drivers/iio/multiplexer/iio-mux.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/multiplexer/iio-mux.c- Extension
.c- Size
- 10390 bytes
- Lines
- 467
- 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/cleanup.hlinux/err.hlinux/iio/consumer.hlinux/iio/iio.hlinux/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/mux/consumer.hlinux/platform_device.hlinux/property.h
Detected Declarations
struct mux_ext_info_cachestruct mux_childstruct muxfunction iio_mux_selectfunction iio_mux_deselectfunction mux_read_rawfunction mux_read_availfunction mux_write_rawfunction mux_read_ext_infofunction mux_write_ext_infofunction mux_configure_chan_ext_infofunction mux_configure_channelfunction mux_probe
Annotated Snippet
struct mux_ext_info_cache {
char *data;
ssize_t size;
};
struct mux_child {
struct mux_ext_info_cache *ext_info_cache;
};
struct mux {
int cached_state;
struct mux_control *control;
struct iio_channel *parent;
struct iio_chan_spec *chan;
struct iio_chan_spec_ext_info *ext_info;
struct mux_child *child;
u32 delay_us;
};
static int iio_mux_select(struct mux *mux, int idx)
{
struct mux_child *child = &mux->child[idx];
struct iio_chan_spec const *chan = &mux->chan[idx];
int ret;
int i;
ret = mux_control_select_delay(mux->control, chan->channel,
mux->delay_us);
if (ret < 0) {
mux->cached_state = -1;
return ret;
}
if (mux->cached_state == chan->channel)
return 0;
if (chan->ext_info) {
for (i = 0; chan->ext_info[i].name; ++i) {
const char *attr = chan->ext_info[i].name;
struct mux_ext_info_cache *cache;
cache = &child->ext_info_cache[i];
if (cache->size < 0)
continue;
ret = iio_write_channel_ext_info(mux->parent, attr,
cache->data,
cache->size);
if (ret < 0) {
mux_control_deselect(mux->control);
mux->cached_state = -1;
return ret;
}
}
}
mux->cached_state = chan->channel;
return 0;
}
static void iio_mux_deselect(struct mux *mux)
{
mux_control_deselect(mux->control);
}
static int mux_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
struct mux *mux = iio_priv(indio_dev);
int idx = chan - mux->chan;
int ret;
ret = iio_mux_select(mux, idx);
if (ret < 0)
return ret;
switch (mask) {
case IIO_CHAN_INFO_RAW:
ret = iio_read_channel_raw(mux->parent, val);
break;
case IIO_CHAN_INFO_SCALE:
ret = iio_read_channel_scale(mux->parent, val, val2);
break;
default:
ret = -EINVAL;
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/err.h`, `linux/iio/consumer.h`, `linux/iio/iio.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/mutex.h`, `linux/mux/consumer.h`.
- Detected declarations: `struct mux_ext_info_cache`, `struct mux_child`, `struct mux`, `function iio_mux_select`, `function iio_mux_deselect`, `function mux_read_raw`, `function mux_read_avail`, `function mux_write_raw`, `function mux_read_ext_info`, `function mux_write_ext_info`.
- 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.