drivers/iio/dac/max5522.c
Source file repositories/reference/linux-study-clean/drivers/iio/dac/max5522.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/dac/max5522.c- Extension
.c- Size
- 4494 bytes
- Lines
- 195
- 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/device.hlinux/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/regmap.hlinux/regulator/consumer.hlinux/slab.hlinux/spi/spi.hlinux/units.hlinux/iio/iio.h
Detected Declarations
struct max5522_chip_infostruct max5522_stateenum max5522_typefunction max5522_info_to_regfunction max5522_read_rawfunction max5522_write_rawfunction max5522_spi_probe
Annotated Snippet
struct max5522_chip_info {
const char *name;
const struct iio_chan_spec *channels;
unsigned int num_channels;
};
struct max5522_state {
struct regmap *regmap;
const struct max5522_chip_info *chip_info;
unsigned short dac_cache[2];
int vref_mV;
};
#define MAX5522_CHANNEL(chan) { \
.type = IIO_VOLTAGE, \
.indexed = 1, \
.output = 1, \
.channel = chan, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
BIT(IIO_CHAN_INFO_SCALE), \
.scan_type = { \
.sign = 'u', \
.realbits = 10, \
.storagebits = 16, \
.shift = 2, \
} \
}
static const struct iio_chan_spec max5522_channels[] = {
MAX5522_CHANNEL(0),
MAX5522_CHANNEL(1),
};
enum max5522_type {
ID_MAX5522,
};
static const struct max5522_chip_info max5522_chip_info_tbl[] = {
[ID_MAX5522] = {
.name = "max5522",
.channels = max5522_channels,
.num_channels = 2,
},
};
static inline int max5522_info_to_reg(struct iio_chan_spec const *chan)
{
return MAX5522_REG_DATA(chan->channel);
}
static int max5522_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long info)
{
struct max5522_state *state = iio_priv(indio_dev);
switch (info) {
case IIO_CHAN_INFO_RAW:
*val = state->dac_cache[chan->channel];
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
*val = state->vref_mV;
*val2 = 10;
return IIO_VAL_FRACTIONAL_LOG2;
default:
return -EINVAL;
}
return -EINVAL;
}
static int max5522_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val, int val2, long info)
{
struct max5522_state *state = iio_priv(indio_dev);
int rval;
if (val > 1023 || val < 0)
return -EINVAL;
rval = regmap_write(state->regmap, max5522_info_to_reg(chan),
val << chan->scan_type.shift);
if (rval < 0)
return rval;
state->dac_cache[chan->channel] = val;
return 0;
}
Annotation
- Immediate include surface: `linux/device.h`, `linux/kernel.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/regmap.h`, `linux/regulator/consumer.h`, `linux/slab.h`, `linux/spi/spi.h`.
- Detected declarations: `struct max5522_chip_info`, `struct max5522_state`, `enum max5522_type`, `function max5522_info_to_reg`, `function max5522_read_raw`, `function max5522_write_raw`, `function max5522_spi_probe`.
- 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.