drivers/iio/dac/ad5791.c
Source file repositories/reference/linux-study-clean/drivers/iio/dac/ad5791.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/dac/ad5791.c- Extension
.c- Size
- 16728 bytes
- Lines
- 612
- 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/bitops.hlinux/delay.hlinux/device.hlinux/fs.hlinux/interrupt.hlinux/kernel.hlinux/module.hlinux/regulator/consumer.hlinux/slab.hlinux/spi/offload/consumer.hlinux/spi/spi.hlinux/sysfs.hlinux/units.hlinux/iio/buffer-dmaengine.hlinux/iio/dac/ad5791.hlinux/iio/iio.hlinux/iio/sysfs.h
Detected Declarations
struct ad5791_chip_infostruct ad5791_statefunction ad5791_spi_writefunction ad5791_spi_readfunction ad5791_get_powerdown_modefunction ad5791_set_powerdown_modefunction ad5791_read_dac_powerdownfunction ad5791_write_dac_powerdownfunction ad5791_get_lin_compfunction ad5780_get_lin_compfunction ad5791_set_sample_freqfunction ad5791_read_rawfunction ad5791_write_rawfunction ad5791_write_raw_get_fmtfunction ad5791_buffer_preenablefunction ad5791_buffer_postdisablefunction ad5791_offload_setupfunction ad5791_probe
Annotated Snippet
struct ad5791_chip_info {
const char *name;
const struct iio_chan_spec channel;
const struct iio_chan_spec channel_offload;
int (*get_lin_comp)(unsigned int span);
};
/**
* struct ad5791_state - driver instance specific data
* @spi: spi_device
* @gpio_reset: reset gpio
* @gpio_clear: clear gpio
* @gpio_ldac: load dac gpio
* @chip_info: chip model specific constants
* @offload_msg: spi message used for offload
* @offload_xfer: spi transfer used for offload
* @offload: offload device
* @offload_trigger: offload trigger
* @offload_trigger_hz: offload sample rate
* @vref_mv: actual reference voltage used
* @vref_neg_mv: voltage of the negative supply
* @ctrl: control register cache
* @pwr_down_mode: current power down mode
* @pwr_down: true if device is powered down
* @data: spi transfer buffers
*/
struct ad5791_state {
struct spi_device *spi;
struct gpio_desc *gpio_reset;
struct gpio_desc *gpio_clear;
struct gpio_desc *gpio_ldac;
const struct ad5791_chip_info *chip_info;
struct spi_message offload_msg;
struct spi_transfer offload_xfer;
struct spi_offload *offload;
struct spi_offload_trigger *offload_trigger;
unsigned int offload_trigger_hz;
unsigned short vref_mv;
unsigned int vref_neg_mv;
unsigned ctrl;
unsigned pwr_down_mode;
bool pwr_down;
union {
__be32 d32;
u8 d8[4];
} data[3] __aligned(IIO_DMA_MINALIGN);
};
static int ad5791_spi_write(struct ad5791_state *st, u8 addr, u32 val)
{
st->data[0].d32 = cpu_to_be32(AD5791_CMD_WRITE |
AD5791_ADDR(addr) |
(val & AD5791_DAC_MASK));
return spi_write(st->spi, &st->data[0].d8[1], 3);
}
static int ad5791_spi_read(struct ad5791_state *st, u8 addr, u32 *val)
{
int ret;
struct spi_transfer xfers[] = {
{
.tx_buf = &st->data[0].d8[1],
.len = 3,
.cs_change = 1,
}, {
.tx_buf = &st->data[1].d8[1],
.rx_buf = &st->data[2].d8[1],
.len = 3,
},
};
st->data[0].d32 = cpu_to_be32(AD5791_CMD_READ |
AD5791_ADDR(addr));
st->data[1].d32 = cpu_to_be32(AD5791_ADDR(AD5791_ADDR_NOOP));
ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));
*val = be32_to_cpu(st->data[2].d32);
return ret;
}
static const char * const ad5791_powerdown_modes[] = {
"6kohm_to_gnd",
"three_state",
};
static int ad5791_get_powerdown_mode(struct iio_dev *indio_dev,
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/delay.h`, `linux/device.h`, `linux/fs.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/module.h`, `linux/regulator/consumer.h`.
- Detected declarations: `struct ad5791_chip_info`, `struct ad5791_state`, `function ad5791_spi_write`, `function ad5791_spi_read`, `function ad5791_get_powerdown_mode`, `function ad5791_set_powerdown_mode`, `function ad5791_read_dac_powerdown`, `function ad5791_write_dac_powerdown`, `function ad5791_get_lin_comp`, `function ad5780_get_lin_comp`.
- 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.