drivers/iio/adc/ad7780.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/ad7780.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/ad7780.c- Extension
.c- Size
- 8953 bytes
- Lines
- 379
- 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/interrupt.hlinux/device.hlinux/kernel.hlinux/slab.hlinux/sysfs.hlinux/spi/spi.hlinux/regulator/consumer.hlinux/err.hlinux/sched.hlinux/gpio/consumer.hlinux/module.hlinux/bits.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/adc/ad_sigma_delta.h
Detected Declarations
struct ad7780_chip_infostruct ad7780_stateenum ad7780_supported_device_idsfunction ad7780_set_modefunction ad7780_read_rawfunction ad7780_write_rawfunction ad7780_postprocess_samplefunction ad7780_init_gpiosfunction ad7780_reg_disablefunction ad7780_probe
Annotated Snippet
struct ad7780_chip_info {
struct iio_chan_spec channel;
unsigned int pattern_mask;
unsigned int pattern;
bool is_ad778x;
};
struct ad7780_state {
const struct ad7780_chip_info *chip_info;
struct regulator *reg;
struct gpio_desc *powerdown_gpio;
struct gpio_desc *gain_gpio;
struct gpio_desc *filter_gpio;
unsigned int gain;
unsigned int odr;
unsigned int int_vref_mv;
struct ad_sigma_delta sd;
};
enum ad7780_supported_device_ids {
ID_AD7170,
ID_AD7171,
ID_AD7780,
ID_AD7781,
};
static struct ad7780_state *ad_sigma_delta_to_ad7780(struct ad_sigma_delta *sd)
{
return container_of(sd, struct ad7780_state, sd);
}
static int ad7780_set_mode(struct ad_sigma_delta *sigma_delta,
enum ad_sigma_delta_mode mode)
{
struct ad7780_state *st = ad_sigma_delta_to_ad7780(sigma_delta);
unsigned int val;
switch (mode) {
case AD_SD_MODE_SINGLE:
case AD_SD_MODE_CONTINUOUS:
val = 1;
break;
default:
val = 0;
break;
}
gpiod_set_value(st->powerdown_gpio, val);
return 0;
}
static int ad7780_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val,
int *val2,
long m)
{
struct ad7780_state *st = iio_priv(indio_dev);
int voltage_uv;
switch (m) {
case IIO_CHAN_INFO_RAW:
return ad_sigma_delta_single_conversion(indio_dev, chan, val);
case IIO_CHAN_INFO_SCALE:
voltage_uv = regulator_get_voltage(st->reg);
if (voltage_uv < 0)
return voltage_uv;
voltage_uv /= 1000;
*val = voltage_uv * st->gain;
*val2 = chan->scan_type.realbits - 1;
st->int_vref_mv = voltage_uv;
return IIO_VAL_FRACTIONAL_LOG2;
case IIO_CHAN_INFO_OFFSET:
*val = -(1 << (chan->scan_type.realbits - 1));
return IIO_VAL_INT;
case IIO_CHAN_INFO_SAMP_FREQ:
*val = st->odr;
return IIO_VAL_INT;
default:
break;
}
return -EINVAL;
}
static int ad7780_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val,
Annotation
- Immediate include surface: `linux/interrupt.h`, `linux/device.h`, `linux/kernel.h`, `linux/slab.h`, `linux/sysfs.h`, `linux/spi/spi.h`, `linux/regulator/consumer.h`, `linux/err.h`.
- Detected declarations: `struct ad7780_chip_info`, `struct ad7780_state`, `enum ad7780_supported_device_ids`, `function ad7780_set_mode`, `function ad7780_read_raw`, `function ad7780_write_raw`, `function ad7780_postprocess_sample`, `function ad7780_init_gpios`, `function ad7780_reg_disable`, `function ad7780_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.