drivers/iio/dac/mcp4725.c
Source file repositories/reference/linux-study-clean/drivers/iio/dac/mcp4725.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/dac/mcp4725.c- Extension
.c- Size
- 12904 bytes
- Lines
- 560
- 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/i2c.hlinux/err.hlinux/delay.hlinux/regulator/consumer.hlinux/mod_devicetable.hlinux/property.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/dac/mcp4725.h
Detected Declarations
struct mcp4725_chip_infostruct mcp4725_dataenum chip_idfunction mcp4725_suspendfunction mcp4725_resumefunction mcp4725_store_eepromfunction mcp4725_get_powerdown_modefunction mcp4725_set_powerdown_modefunction mcp4725_read_powerdownfunction mcp4725_write_powerdownfunction mcp4725_set_valuefunction mcp4726_set_cfgfunction mcp4725_read_rawfunction mcp4725_write_rawfunction mcp4725_probe_dtfunction mcp4725_probefunction mcp4725_remove
Annotated Snippet
struct mcp4725_chip_info {
const struct iio_chan_spec *chan_spec;
u8 dac_reg_offset;
bool use_ext_ref_voltage;
};
struct mcp4725_data {
struct i2c_client *client;
unsigned ref_mode;
bool vref_buffered;
u16 dac_value;
bool powerdown;
unsigned powerdown_mode;
struct regulator *vdd_reg;
struct regulator *vref_reg;
};
static int mcp4725_suspend(struct device *dev)
{
struct mcp4725_data *data = iio_priv(i2c_get_clientdata(
to_i2c_client(dev)));
u8 outbuf[2];
int ret;
outbuf[0] = (data->powerdown_mode + 1) << 4;
outbuf[1] = 0;
data->powerdown = true;
ret = i2c_master_send(data->client, outbuf, 2);
if (ret < 0)
return ret;
else if (ret != 2)
return -EIO;
return 0;
}
static int mcp4725_resume(struct device *dev)
{
struct mcp4725_data *data = iio_priv(i2c_get_clientdata(
to_i2c_client(dev)));
u8 outbuf[2];
int ret;
/* restore previous DAC value */
outbuf[0] = (data->dac_value >> 8) & 0xf;
outbuf[1] = data->dac_value & 0xff;
data->powerdown = false;
ret = i2c_master_send(data->client, outbuf, 2);
if (ret < 0)
return ret;
else if (ret != 2)
return -EIO;
return 0;
}
static DEFINE_SIMPLE_DEV_PM_OPS(mcp4725_pm_ops, mcp4725_suspend,
mcp4725_resume);
static ssize_t mcp4725_store_eeprom(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
{
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct mcp4725_data *data = iio_priv(indio_dev);
int tries = 20;
u8 inoutbuf[3];
bool state;
int ret;
ret = kstrtobool(buf, &state);
if (ret < 0)
return ret;
if (!state)
return 0;
inoutbuf[0] = 0x60; /* write EEPROM */
inoutbuf[0] |= data->ref_mode << 3;
inoutbuf[0] |= data->powerdown ? ((data->powerdown_mode + 1) << 1) : 0;
inoutbuf[1] = data->dac_value >> 4;
inoutbuf[2] = (data->dac_value & 0xf) << 4;
ret = i2c_master_send(data->client, inoutbuf, 3);
if (ret < 0)
return ret;
else if (ret != 3)
return -EIO;
/* wait for write complete, takes up to 50ms */
while (tries--) {
msleep(20);
Annotation
- Immediate include surface: `linux/module.h`, `linux/i2c.h`, `linux/err.h`, `linux/delay.h`, `linux/regulator/consumer.h`, `linux/mod_devicetable.h`, `linux/property.h`, `linux/iio/iio.h`.
- Detected declarations: `struct mcp4725_chip_info`, `struct mcp4725_data`, `enum chip_id`, `function mcp4725_suspend`, `function mcp4725_resume`, `function mcp4725_store_eeprom`, `function mcp4725_get_powerdown_mode`, `function mcp4725_set_powerdown_mode`, `function mcp4725_read_powerdown`, `function mcp4725_write_powerdown`.
- 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.