drivers/iio/dac/ad5421.c
Source file repositories/reference/linux-study-clean/drivers/iio/dac/ad5421.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/dac/ad5421.c- Extension
.c- Size
- 13152 bytes
- Lines
- 538
- 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/device.hlinux/delay.hlinux/err.hlinux/module.hlinux/interrupt.hlinux/kernel.hlinux/spi/spi.hlinux/slab.hlinux/sysfs.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/events.hlinux/iio/dac/ad5421.h
Detected Declarations
struct ad5421_statefunction ad5421_write_unlockedfunction ad5421_writefunction ad5421_readfunction ad5421_update_ctrlfunction ad5421_fault_handlerfunction ad5421_get_current_min_maxfunction ad5421_get_offsetfunction ad5421_read_rawfunction ad5421_write_rawfunction ad5421_write_event_configfunction ad5421_read_event_configfunction ad5421_read_event_valuefunction ad5421_probe
Annotated Snippet
struct ad5421_state {
struct spi_device *spi;
unsigned int ctrl;
enum ad5421_current_range current_range;
unsigned int fault_mask;
struct mutex lock;
/*
* DMA (thus cache coherency maintenance) may require the
* transfer buffers to live in their own cache lines.
*/
union {
__be32 d32;
u8 d8[4];
} data[2] __aligned(IIO_DMA_MINALIGN);
};
static const struct iio_event_spec ad5421_current_event[] = {
{
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_RISING,
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
BIT(IIO_EV_INFO_ENABLE),
}, {
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_FALLING,
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
BIT(IIO_EV_INFO_ENABLE),
},
};
static const struct iio_event_spec ad5421_temp_event[] = {
{
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_RISING,
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
BIT(IIO_EV_INFO_ENABLE),
},
};
static const struct iio_chan_spec ad5421_channels[] = {
{
.type = IIO_CURRENT,
.indexed = 1,
.output = 1,
.channel = 0,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_CALIBSCALE) |
BIT(IIO_CHAN_INFO_CALIBBIAS),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_OFFSET),
.scan_type = {
.sign = 'u',
.realbits = 16,
.storagebits = 16,
},
.event_spec = ad5421_current_event,
.num_event_specs = ARRAY_SIZE(ad5421_current_event),
},
{
.type = IIO_TEMP,
.channel = -1,
.event_spec = ad5421_temp_event,
.num_event_specs = ARRAY_SIZE(ad5421_temp_event),
},
};
static int ad5421_write_unlocked(struct iio_dev *indio_dev,
unsigned int reg, unsigned int val)
{
struct ad5421_state *st = iio_priv(indio_dev);
st->data[0].d32 = cpu_to_be32((reg << 16) | val);
return spi_write(st->spi, &st->data[0].d8[1], 3);
}
static int ad5421_write(struct iio_dev *indio_dev, unsigned int reg,
unsigned int val)
{
struct ad5421_state *st = iio_priv(indio_dev);
int ret;
mutex_lock(&st->lock);
ret = ad5421_write_unlocked(indio_dev, reg, val);
mutex_unlock(&st->lock);
return ret;
}
Annotation
- Immediate include surface: `linux/device.h`, `linux/delay.h`, `linux/err.h`, `linux/module.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/spi/spi.h`, `linux/slab.h`.
- Detected declarations: `struct ad5421_state`, `function ad5421_write_unlocked`, `function ad5421_write`, `function ad5421_read`, `function ad5421_update_ctrl`, `function ad5421_fault_handler`, `function ad5421_get_current_min_max`, `function ad5421_get_offset`, `function ad5421_read_raw`, `function ad5421_write_raw`.
- 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.