drivers/iio/dac/ltc2688.c
Source file repositories/reference/linux-study-clean/drivers/iio/dac/ltc2688.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/dac/ltc2688.c- Extension
.c- Size
- 26408 bytes
- Lines
- 1013
- 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/bitfield.hlinux/bits.hlinux/cleanup.hlinux/clk.hlinux/device.hlinux/gpio/consumer.hlinux/iio/iio.hlinux/limits.hlinux/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/mutex.hlinux/of.hlinux/property.hlinux/regmap.hlinux/regulator/consumer.hlinux/spi/spi.h
Detected Declarations
struct ltc2688_chanstruct ltc2688_statefunction ltc2688_spi_readfunction ltc2688_spi_writefunction ltc2688_span_getfunction ltc2688_scale_getfunction ltc2688_offset_getfunction ltc2688_dac_code_writefunction ltc2688_dac_code_readfunction ltc2688_read_availfunction ltc2688_read_rawfunction ltc2688_write_rawfunction ltc2688_dither_toggle_setfunction ltc2688_reg_bool_getfunction ltc2688_reg_bool_setfunction ltc2688_dither_freq_availfunction ltc2688_dither_freq_getfunction ltc2688_dither_freq_setfunction ltc2688_dac_input_readfunction ltc2688_dac_input_writefunction ltc2688_get_dither_phasefunction ltc2688_set_dither_phasefunction ltc2688_reg_accessfunction ltc2688_clk_disablefunction ltc2688_tgp_clk_setupfunction ltc2688_span_lookupfunction ltc2688_channel_configfunction device_for_each_child_node_scopedfunction channelfunction ltc2688_setupfunction ltc2688_reg_readablefunction ltc2688_reg_writablefunction ltc2688_probe
Annotated Snippet
struct ltc2688_chan {
long dither_frequency[LTC2688_DITHER_FREQ_AVAIL_N];
bool overrange;
bool toggle_chan;
u8 mode;
};
struct ltc2688_state {
struct spi_device *spi;
struct regmap *regmap;
struct ltc2688_chan channels[LTC2688_DAC_CHANNELS];
struct iio_chan_spec *iio_chan;
/* lock to protect against multiple access to the device and shared data */
struct mutex lock;
int vref;
/*
* DMA (thus cache coherency maintenance) may require the
* transfer buffers to live in their own cache lines.
*/
u8 tx_data[6] __aligned(IIO_DMA_MINALIGN);
u8 rx_data[3];
};
static int ltc2688_spi_read(void *context, const void *reg, size_t reg_size,
void *val, size_t val_size)
{
struct ltc2688_state *st = context;
struct spi_transfer xfers[] = {
{
.tx_buf = st->tx_data,
.len = reg_size + val_size,
.cs_change = 1,
}, {
.tx_buf = st->tx_data + 3,
.rx_buf = st->rx_data,
.len = reg_size + val_size,
},
};
int ret;
memcpy(st->tx_data, reg, reg_size);
ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));
if (ret)
return ret;
memcpy(val, &st->rx_data[1], val_size);
return 0;
}
static int ltc2688_spi_write(void *context, const void *data, size_t count)
{
struct ltc2688_state *st = context;
return spi_write(st->spi, data, count);
}
static int ltc2688_span_get(const struct ltc2688_state *st, int c)
{
int ret, reg, span;
ret = regmap_read(st->regmap, LTC2688_CMD_CH_SETTING(c), ®);
if (ret)
return ret;
span = FIELD_GET(LTC2688_CH_SPAN_MSK, reg);
/* sanity check to make sure we don't get any weird value from the HW */
if (span >= LTC2688_SPAN_RANGE_MAX)
return -EIO;
return span;
}
static const int ltc2688_span_helper[LTC2688_SPAN_RANGE_MAX][2] = {
{0, 5000}, {0, 10000}, {-5000, 5000}, {-10000, 10000}, {-15000, 15000},
};
static int ltc2688_scale_get(const struct ltc2688_state *st, int c, int *val)
{
const struct ltc2688_chan *chan = &st->channels[c];
int span, fs;
span = ltc2688_span_get(st, c);
if (span < 0)
return span;
fs = ltc2688_span_helper[span][1] - ltc2688_span_helper[span][0];
if (chan->overrange)
fs = mult_frac(fs, 105, 100);
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bits.h`, `linux/cleanup.h`, `linux/clk.h`, `linux/device.h`, `linux/gpio/consumer.h`, `linux/iio/iio.h`, `linux/limits.h`.
- Detected declarations: `struct ltc2688_chan`, `struct ltc2688_state`, `function ltc2688_spi_read`, `function ltc2688_spi_write`, `function ltc2688_span_get`, `function ltc2688_scale_get`, `function ltc2688_offset_get`, `function ltc2688_dac_code_write`, `function ltc2688_dac_code_read`, `function ltc2688_read_avail`.
- 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.