drivers/iio/dac/dpot-dac.c
Source file repositories/reference/linux-study-clean/drivers/iio/dac/dpot-dac.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/dac/dpot-dac.c- Extension
.c- Size
- 6214 bytes
- Lines
- 257
- 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/err.hlinux/iio/consumer.hlinux/iio/iio.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.hlinux/regulator/consumer.h
Detected Declarations
struct dpot_dacfunction dpot_dac_read_rawfunction dpot_dac_read_availfunction dpot_dac_write_rawfunction dpot_dac_channel_max_ohmsfunction dpot_dac_probefunction dpot_dac_remove
Annotated Snippet
struct dpot_dac {
struct regulator *vref;
struct iio_channel *dpot;
u32 max_ohms;
};
static const struct iio_chan_spec dpot_dac_iio_channel = {
.type = IIO_VOLTAGE,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW)
| BIT(IIO_CHAN_INFO_SCALE),
.info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW),
.output = 1,
.indexed = 1,
};
static int dpot_dac_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
struct dpot_dac *dac = iio_priv(indio_dev);
int ret;
unsigned long long tmp;
switch (mask) {
case IIO_CHAN_INFO_RAW:
return iio_read_channel_raw(dac->dpot, val);
case IIO_CHAN_INFO_SCALE:
ret = iio_read_channel_scale(dac->dpot, val, val2);
switch (ret) {
case IIO_VAL_FRACTIONAL_LOG2:
tmp = *val * 1000000000LL;
do_div(tmp, dac->max_ohms);
tmp *= regulator_get_voltage(dac->vref) / 1000;
do_div(tmp, 1000000000LL);
*val = tmp;
return ret;
case IIO_VAL_INT:
/*
* Convert integer scale to fractional scale by
* setting the denominator (val2) to one...
*/
*val2 = 1;
ret = IIO_VAL_FRACTIONAL;
/* ...and fall through. Say it again for GCC. */
fallthrough;
case IIO_VAL_FRACTIONAL:
*val *= regulator_get_voltage(dac->vref) / 1000;
*val2 *= dac->max_ohms;
break;
}
return ret;
}
return -EINVAL;
}
static int dpot_dac_read_avail(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
const int **vals, int *type, int *length,
long mask)
{
struct dpot_dac *dac = iio_priv(indio_dev);
switch (mask) {
case IIO_CHAN_INFO_RAW:
*type = IIO_VAL_INT;
return iio_read_avail_channel_raw(dac->dpot, vals, length);
}
return -EINVAL;
}
static int dpot_dac_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val, int val2, long mask)
{
struct dpot_dac *dac = iio_priv(indio_dev);
switch (mask) {
case IIO_CHAN_INFO_RAW:
return iio_write_channel_raw(dac->dpot, val);
}
return -EINVAL;
}
static const struct iio_info dpot_dac_info = {
.read_raw = dpot_dac_read_raw,
Annotation
- Immediate include surface: `linux/err.h`, `linux/iio/consumer.h`, `linux/iio/iio.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`, `linux/regulator/consumer.h`.
- Detected declarations: `struct dpot_dac`, `function dpot_dac_read_raw`, `function dpot_dac_read_avail`, `function dpot_dac_write_raw`, `function dpot_dac_channel_max_ohms`, `function dpot_dac_probe`, `function dpot_dac_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.