drivers/iio/dac/ltc1660.c
Source file repositories/reference/linux-study-clean/drivers/iio/dac/ltc1660.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/dac/ltc1660.c- Extension
.c- Size
- 6142 bytes
- Lines
- 248
- 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/iio/iio.hlinux/iio/sysfs.hlinux/init.hlinux/module.hlinux/regulator/consumer.hlinux/regmap.hlinux/spi/spi.h
Detected Declarations
struct ltc1660_privenum ltc1660_supported_device_idsfunction ltc1660_read_rawfunction ltc1660_write_rawfunction ltc1660_suspendfunction ltc1660_resumefunction ltc1660_probefunction ltc1660_remove
Annotated Snippet
struct ltc1660_priv {
struct spi_device *spi;
struct regmap *regmap;
struct regulator *vref_reg;
unsigned int value[LTC1660_NUM_CHANNELS];
unsigned int vref_mv;
};
static int ltc1660_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val,
int *val2,
long mask)
{
struct ltc1660_priv *priv = iio_priv(indio_dev);
switch (mask) {
case IIO_CHAN_INFO_RAW:
*val = priv->value[chan->channel];
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
*val = regulator_get_voltage(priv->vref_reg);
if (*val < 0) {
dev_err(&priv->spi->dev, "failed to read vref regulator: %d\n",
*val);
return *val;
}
/* Convert to mV */
*val /= 1000;
*val2 = chan->scan_type.realbits;
return IIO_VAL_FRACTIONAL_LOG2;
default:
return -EINVAL;
}
}
static int ltc1660_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val,
int val2,
long mask)
{
struct ltc1660_priv *priv = iio_priv(indio_dev);
int ret;
switch (mask) {
case IIO_CHAN_INFO_RAW:
if (val2 != 0)
return -EINVAL;
if (val < 0 || val > GENMASK(chan->scan_type.realbits - 1, 0))
return -EINVAL;
ret = regmap_write(priv->regmap, chan->channel,
(val << chan->scan_type.shift));
if (!ret)
priv->value[chan->channel] = val;
return ret;
default:
return -EINVAL;
}
}
#define LTC1660_CHAN(chan, bits) { \
.type = IIO_VOLTAGE, \
.indexed = 1, \
.output = 1, \
.channel = chan, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
.scan_type = { \
.sign = 'u', \
.realbits = (bits), \
.storagebits = 16, \
.shift = 12 - (bits), \
}, \
}
#define LTC1660_OCTAL_CHANNELS(bits) { \
LTC1660_CHAN(LTC1660_REG_DAC_A, bits), \
LTC1660_CHAN(LTC1660_REG_DAC_B, bits), \
LTC1660_CHAN(LTC1660_REG_DAC_C, bits), \
LTC1660_CHAN(LTC1660_REG_DAC_D, bits), \
LTC1660_CHAN(LTC1660_REG_DAC_E, bits), \
LTC1660_CHAN(LTC1660_REG_DAC_F, bits), \
LTC1660_CHAN(LTC1660_REG_DAC_G, bits), \
LTC1660_CHAN(LTC1660_REG_DAC_H, bits), \
}
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`, `linux/init.h`, `linux/module.h`, `linux/regulator/consumer.h`, `linux/regmap.h`, `linux/spi/spi.h`.
- Detected declarations: `struct ltc1660_priv`, `enum ltc1660_supported_device_ids`, `function ltc1660_read_raw`, `function ltc1660_write_raw`, `function ltc1660_suspend`, `function ltc1660_resume`, `function ltc1660_probe`, `function ltc1660_remove`.
- 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.