drivers/iio/dac/mcp4821.c
Source file repositories/reference/linux-study-clean/drivers/iio/dac/mcp4821.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/dac/mcp4821.c- Extension
.c- Size
- 6004 bytes
- Lines
- 237
- 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/module.hlinux/mod_devicetable.hlinux/spi/spi.hlinux/iio/iio.hlinux/iio/types.hlinux/unaligned.h
Detected Declarations
struct mcp4821_statestruct mcp4821_chip_infoenum mcp4821_supported_drvice_idsfunction mcp4821_read_rawfunction mcp4821_write_rawfunction mcp4821_probe
Annotated Snippet
struct mcp4821_state {
struct spi_device *spi;
u16 dac_value[2];
};
struct mcp4821_chip_info {
const char *name;
int num_channels;
const struct iio_chan_spec channels[2];
};
#define MCP4821_CHAN(channel_id, resolution) \
{ \
.type = IIO_VOLTAGE, .output = 1, .indexed = 1, \
.channel = (channel_id), \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
.scan_type = { \
.realbits = (resolution), \
.shift = 12 - (resolution), \
}, \
}
static const struct mcp4821_chip_info mcp4821_chip_info_table[6] = {
[ID_MCP4801] = {
.name = "mcp4801",
.num_channels = 1,
.channels = {
MCP4821_CHAN(0, 8),
},
},
[ID_MCP4802] = {
.name = "mcp4802",
.num_channels = 2,
.channels = {
MCP4821_CHAN(0, 8),
MCP4821_CHAN(1, 8),
},
},
[ID_MCP4811] = {
.name = "mcp4811",
.num_channels = 1,
.channels = {
MCP4821_CHAN(0, 10),
},
},
[ID_MCP4812] = {
.name = "mcp4812",
.num_channels = 2,
.channels = {
MCP4821_CHAN(0, 10),
MCP4821_CHAN(1, 10),
},
},
[ID_MCP4821] = {
.name = "mcp4821",
.num_channels = 1,
.channels = {
MCP4821_CHAN(0, 12),
},
},
[ID_MCP4822] = {
.name = "mcp4822",
.num_channels = 2,
.channels = {
MCP4821_CHAN(0, 12),
MCP4821_CHAN(1, 12),
},
},
};
static int mcp4821_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int *val,
int *val2, long mask)
{
struct mcp4821_state *state;
switch (mask) {
case IIO_CHAN_INFO_RAW:
state = iio_priv(indio_dev);
*val = state->dac_value[chan->channel];
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
*val = MCP4821_2X_GAIN_VREF_MV;
*val2 = chan->scan_type.realbits;
return IIO_VAL_FRACTIONAL_LOG2;
default:
return -EINVAL;
}
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/mod_devicetable.h`, `linux/spi/spi.h`, `linux/iio/iio.h`, `linux/iio/types.h`, `linux/unaligned.h`.
- Detected declarations: `struct mcp4821_state`, `struct mcp4821_chip_info`, `enum mcp4821_supported_drvice_ids`, `function mcp4821_read_raw`, `function mcp4821_write_raw`, `function mcp4821_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.