drivers/iio/dac/ti-dac7311.c
Source file repositories/reference/linux-study-clean/drivers/iio/dac/ti-dac7311.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/dac/ti-dac7311.c- Extension
.c- Size
- 7744 bytes
- Lines
- 335
- 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/regulator/consumer.hlinux/spi/spi.h
Detected Declarations
struct ti_dac_specstruct ti_dac_chipfunction ti_dac_get_powerfunction 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 resolution;
};
static const struct ti_dac_spec ti_dac_spec[] = {
[ID_DAC5311] = { .resolution = 8 },
[ID_DAC6311] = { .resolution = 10 },
[ID_DAC7311] = { .resolution = 12 },
};
/**
* struct ti_dac_chip - TI DAC chip
* @lock: protects write sequences
* @vref: regulator generating Vref
* @spi: SPI device to send data to the device
* @val: cached value
* @powerdown: whether the chip is powered down
* @powerdown_mode: selected by the user
* @resolution: resolution of the chip
* @buf: buffer for transfer data
*/
struct ti_dac_chip {
struct mutex lock;
struct regulator *vref;
struct spi_device *spi;
u16 val;
bool powerdown;
u8 powerdown_mode;
u8 resolution;
u8 buf[2] __aligned(IIO_DMA_MINALIGN);
};
static u8 ti_dac_get_power(struct ti_dac_chip *ti_dac, bool powerdown)
{
if (powerdown)
return ti_dac->powerdown_mode + 1;
return 0;
}
static int ti_dac_cmd(struct ti_dac_chip *ti_dac, u8 power, u16 val)
{
u8 shift = 14 - ti_dac->resolution;
ti_dac->buf[0] = (val << shift) & 0xFF;
ti_dac->buf[1] = (power << 6) | (val >> (8 - shift));
return spi_write(ti_dac->spi, ti_dac->buf, 2);
}
static const char * const ti_dac_powerdown_modes[] = {
"1kohm_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);
ti_dac->powerdown_mode = mode;
return 0;
}
static const struct iio_enum ti_dac_powerdown_mode = {
.items = ti_dac_powerdown_modes,
.num_items = ARRAY_SIZE(ti_dac_powerdown_modes),
.get = ti_dac_get_powerdown_mode,
.set = ti_dac_set_powerdown_mode,
};
static ssize_t ti_dac_read_powerdown(struct iio_dev *indio_dev,
uintptr_t private,
const struct iio_chan_spec *chan,
char *buf)
{
struct ti_dac_chip *ti_dac = iio_priv(indio_dev);
return sysfs_emit(buf, "%d\n", ti_dac->powerdown);
}
Annotation
- Immediate include surface: `linux/iio/iio.h`, `linux/module.h`, `linux/regulator/consumer.h`, `linux/spi/spi.h`.
- Detected declarations: `struct ti_dac_spec`, `struct ti_dac_chip`, `function ti_dac_get_power`, `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`.
- 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.