drivers/iio/dac/ad8801.c
Source file repositories/reference/linux-study-clean/drivers/iio/dac/ad8801.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/dac/ad8801.c- Extension
.c- Size
- 3987 bytes
- Lines
- 172
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/iio/iio.hlinux/module.hlinux/regulator/consumer.hlinux/spi/spi.hlinux/sysfs.h
Detected Declarations
struct ad8801_stateenum ad8801_device_idsfunction ad8801_spi_writefunction ad8801_write_rawfunction ad8801_read_rawfunction ad8801_probe
Annotated Snippet
struct ad8801_state {
struct spi_device *spi;
unsigned char dac_cache[8]; /* Value write on each channel */
unsigned int vrefh_mv;
unsigned int vrefl_mv;
__be16 data __aligned(IIO_DMA_MINALIGN);
};
static int ad8801_spi_write(struct ad8801_state *state,
u8 channel, unsigned char value)
{
state->data = cpu_to_be16((channel << AD8801_CFG_ADDR_OFFSET) | value);
return spi_write(state->spi, &state->data, sizeof(state->data));
}
static int ad8801_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int val, int val2, long mask)
{
struct ad8801_state *state = iio_priv(indio_dev);
int ret;
switch (mask) {
case IIO_CHAN_INFO_RAW:
if (val >= 256 || val < 0)
return -EINVAL;
ret = ad8801_spi_write(state, chan->channel, val);
if (ret == 0)
state->dac_cache[chan->channel] = val;
break;
default:
ret = -EINVAL;
}
return ret;
}
static int ad8801_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int *val, int *val2, long info)
{
struct ad8801_state *state = iio_priv(indio_dev);
switch (info) {
case IIO_CHAN_INFO_RAW:
*val = state->dac_cache[chan->channel];
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
*val = state->vrefh_mv - state->vrefl_mv;
*val2 = 8;
return IIO_VAL_FRACTIONAL_LOG2;
case IIO_CHAN_INFO_OFFSET:
*val = state->vrefl_mv;
return IIO_VAL_INT;
default:
return -EINVAL;
}
return -EINVAL;
}
static const struct iio_info ad8801_info = {
.read_raw = ad8801_read_raw,
.write_raw = ad8801_write_raw,
};
#define AD8801_CHANNEL(chan) { \
.type = IIO_VOLTAGE, \
.indexed = 1, \
.output = 1, \
.channel = chan, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
BIT(IIO_CHAN_INFO_OFFSET), \
}
static const struct iio_chan_spec ad8801_channels[] = {
AD8801_CHANNEL(0),
AD8801_CHANNEL(1),
AD8801_CHANNEL(2),
AD8801_CHANNEL(3),
AD8801_CHANNEL(4),
AD8801_CHANNEL(5),
AD8801_CHANNEL(6),
AD8801_CHANNEL(7),
};
static int ad8801_probe(struct spi_device *spi)
{
struct iio_dev *indio_dev;
Annotation
- Immediate include surface: `linux/iio/iio.h`, `linux/module.h`, `linux/regulator/consumer.h`, `linux/spi/spi.h`, `linux/sysfs.h`.
- Detected declarations: `struct ad8801_state`, `enum ad8801_device_ids`, `function ad8801_spi_write`, `function ad8801_write_raw`, `function ad8801_read_raw`, `function ad8801_probe`.
- 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.