drivers/iio/dac/ad5504.c
Source file repositories/reference/linux-study-clean/drivers/iio/dac/ad5504.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/dac/ad5504.c- Extension
.c- Size
- 8123 bytes
- Lines
- 339
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/interrupt.hlinux/fs.hlinux/device.hlinux/kernel.hlinux/spi/spi.hlinux/slab.hlinux/sysfs.hlinux/regulator/consumer.hlinux/module.hlinux/bitops.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/events.hlinux/iio/dac/ad5504.h
Detected Declarations
struct ad5504_stateenum ad5504_supported_device_idsfunction ad5504_spi_writefunction ad5504_spi_readfunction ad5504_read_rawfunction ad5504_write_rawfunction ad5504_get_powerdown_modefunction ad5504_set_powerdown_modefunction ad5504_read_dac_powerdownfunction ad5504_write_dac_powerdownfunction ad5504_event_handlerfunction ad5504_probe
Annotated Snippet
struct ad5504_state {
struct spi_device *spi;
struct regulator *reg;
unsigned short vref_mv;
unsigned pwr_down_mask;
unsigned pwr_down_mode;
__be16 data[2] __aligned(IIO_DMA_MINALIGN);
};
/*
* ad5504_supported_device_ids:
*/
enum ad5504_supported_device_ids {
ID_AD5504,
ID_AD5501,
};
static int ad5504_spi_write(struct ad5504_state *st, u8 addr, u16 val)
{
st->data[0] = cpu_to_be16(AD5504_CMD_WRITE | AD5504_ADDR(addr) |
(val & AD5504_RES_MASK));
return spi_write(st->spi, &st->data[0], 2);
}
static int ad5504_spi_read(struct ad5504_state *st, u8 addr)
{
int ret;
struct spi_transfer t = {
.tx_buf = &st->data[0],
.rx_buf = &st->data[1],
.len = 2,
};
st->data[0] = cpu_to_be16(AD5504_CMD_READ | AD5504_ADDR(addr));
ret = spi_sync_transfer(st->spi, &t, 1);
if (ret < 0)
return ret;
return be16_to_cpu(st->data[1]) & AD5504_RES_MASK;
}
static int ad5504_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val,
int *val2,
long m)
{
struct ad5504_state *st = iio_priv(indio_dev);
int ret;
switch (m) {
case IIO_CHAN_INFO_RAW:
ret = ad5504_spi_read(st, chan->address);
if (ret < 0)
return ret;
*val = ret;
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
*val = st->vref_mv;
*val2 = chan->scan_type.realbits;
return IIO_VAL_FRACTIONAL_LOG2;
}
return -EINVAL;
}
static int ad5504_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val,
int val2,
long mask)
{
struct ad5504_state *st = iio_priv(indio_dev);
switch (mask) {
case IIO_CHAN_INFO_RAW:
if (val >= (1 << chan->scan_type.realbits) || val < 0)
return -EINVAL;
return ad5504_spi_write(st, chan->address, val);
default:
return -EINVAL;
}
}
static const char * const ad5504_powerdown_modes[] = {
"20kohm_to_gnd",
Annotation
- Immediate include surface: `linux/interrupt.h`, `linux/fs.h`, `linux/device.h`, `linux/kernel.h`, `linux/spi/spi.h`, `linux/slab.h`, `linux/sysfs.h`, `linux/regulator/consumer.h`.
- Detected declarations: `struct ad5504_state`, `enum ad5504_supported_device_ids`, `function ad5504_spi_write`, `function ad5504_spi_read`, `function ad5504_read_raw`, `function ad5504_write_raw`, `function ad5504_get_powerdown_mode`, `function ad5504_set_powerdown_mode`, `function ad5504_read_dac_powerdown`, `function ad5504_write_dac_powerdown`.
- 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.