drivers/iio/dac/ti-dac082s085.c
Source file repositories/reference/linux-study-clean/drivers/iio/dac/ti-dac082s085.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/dac/ti-dac082s085.c- Extension
.c- Size
- 9056 bytes
- Lines
- 362
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/iio/iio.hlinux/module.hlinux/mod_devicetable.hlinux/regulator/consumer.hlinux/spi/spi.h
Detected Declarations
struct ti_dac_specstruct ti_dac_chipfunction ti_dac_cmdfunction ti_dac_get_powerdown_modefunction ti_dac_set_powerdown_modefunction ti_dac_read_powerdownfunction ti_dac_write_powerdownfunction ti_dac_read_rawfunction ti_dac_write_rawfunction ti_dac_write_raw_get_fmtfunction ti_dac_probefunction ti_dac_remove
Annotated Snippet
struct ti_dac_spec {
u8 num_channels;
u8 resolution;
};
static const struct ti_dac_spec ti_dac_spec[] = {
[dual_8bit] = { .num_channels = 2, .resolution = 8 },
[dual_10bit] = { .num_channels = 2, .resolution = 10 },
[dual_12bit] = { .num_channels = 2, .resolution = 12 },
[quad_8bit] = { .num_channels = 4, .resolution = 8 },
[quad_10bit] = { .num_channels = 4, .resolution = 10 },
[quad_12bit] = { .num_channels = 4, .resolution = 12 },
};
/**
* struct ti_dac_chip - TI DAC chip
* @lock: protects write sequences
* @vref: regulator generating Vref
* @mesg: SPI message to perform a write
* @xfer: SPI transfer used by @mesg
* @val: cached value of each output
* @powerdown: whether the chip is powered down
* @powerdown_mode: selected by the user
* @resolution: resolution of the chip
* @buf: buffer for @xfer
*/
struct ti_dac_chip {
struct mutex lock;
struct regulator *vref;
struct spi_message mesg;
struct spi_transfer xfer;
u16 val[4];
bool powerdown;
u8 powerdown_mode;
u8 resolution;
u8 buf[2] __aligned(IIO_DMA_MINALIGN);
};
#define WRITE_NOT_UPDATE(chan) (0x00 | (chan) << 6)
#define WRITE_AND_UPDATE(chan) (0x10 | (chan) << 6)
#define WRITE_ALL_UPDATE 0x20
#define POWERDOWN(mode) (0x30 | ((mode) + 1) << 6)
static int ti_dac_cmd(struct ti_dac_chip *ti_dac, u8 cmd, u16 val)
{
u8 shift = 12 - ti_dac->resolution;
ti_dac->buf[0] = cmd | (val >> (8 - shift));
ti_dac->buf[1] = (val << shift) & 0xff;
return spi_sync(ti_dac->mesg.spi, &ti_dac->mesg);
}
static const char * const ti_dac_powerdown_modes[] = {
"2.5kohm_to_gnd", "100kohm_to_gnd", "three_state",
};
static int ti_dac_get_powerdown_mode(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan)
{
struct ti_dac_chip *ti_dac = iio_priv(indio_dev);
return ti_dac->powerdown_mode;
}
static int ti_dac_set_powerdown_mode(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan,
unsigned int mode)
{
struct ti_dac_chip *ti_dac = iio_priv(indio_dev);
int ret = 0;
if (ti_dac->powerdown_mode == mode)
return 0;
mutex_lock(&ti_dac->lock);
if (ti_dac->powerdown) {
ret = ti_dac_cmd(ti_dac, POWERDOWN(mode), 0);
if (ret)
goto out;
}
ti_dac->powerdown_mode = mode;
out:
mutex_unlock(&ti_dac->lock);
return ret;
}
static const struct iio_enum ti_dac_powerdown_mode = {
.items = ti_dac_powerdown_modes,
.num_items = ARRAY_SIZE(ti_dac_powerdown_modes),
Annotation
- Immediate include surface: `linux/iio/iio.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/regulator/consumer.h`, `linux/spi/spi.h`.
- Detected declarations: `struct ti_dac_spec`, `struct ti_dac_chip`, `function ti_dac_cmd`, `function ti_dac_get_powerdown_mode`, `function ti_dac_set_powerdown_mode`, `function ti_dac_read_powerdown`, `function ti_dac_write_powerdown`, `function ti_dac_read_raw`, `function ti_dac_write_raw`, `function ti_dac_write_raw_get_fmt`.
- 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.
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.