drivers/iio/adc/ad7191.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/ad7191.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/ad7191.c- Extension
.c- Size
- 13764 bytes
- Lines
- 555
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/clk.hlinux/device.hlinux/err.hlinux/gpio/consumer.hlinux/interrupt.hlinux/mod_devicetable.hlinux/mutex.hlinux/property.hlinux/regulator/consumer.hlinux/spi/spi.hlinux/types.hlinux/units.hlinux/iio/adc/ad_sigma_delta.hlinux/iio/iio.h
Detected Declarations
struct ad7191_stateenum ad7191_channelfunction ad7191_set_channelfunction ad7191_set_csfunction ad7191_set_modefunction ad7191_init_regulatorsfunction ad7191_config_setupfunction ad7191_clock_setupfunction ad7191_setupfunction ad7191_read_rawfunction ad7191_set_gainfunction ad7191_set_samp_freqfunction __ad7191_write_rawfunction ad7191_write_rawfunction ad7191_write_raw_get_fmtfunction ad7191_read_availfunction ad7191_probe
Annotated Snippet
struct ad7191_state {
struct ad_sigma_delta sd;
struct mutex lock; /* Protect device state */
struct gpio_descs *odr_gpios;
struct gpio_descs *pga_gpios;
struct gpio_desc *temp_gpio;
struct gpio_desc *chan_gpio;
u16 int_vref_mv;
const u32 (*scale_avail)[2];
size_t scale_avail_size;
u32 scale_index;
const u32 *samp_freq_avail;
size_t samp_freq_avail_size;
u32 samp_freq_index;
struct clk *mclk;
};
static int ad7191_set_channel(struct ad_sigma_delta *sd, unsigned int address)
{
struct ad7191_state *st = ad_sigma_delta_to_ad7191(sd);
u8 temp_gpio_val, chan_gpio_val;
if (!FIELD_FIT(AD7191_CHAN_MASK | AD7191_TEMP_MASK, address))
return -EINVAL;
chan_gpio_val = FIELD_GET(AD7191_CHAN_MASK, address);
temp_gpio_val = FIELD_GET(AD7191_TEMP_MASK, address);
gpiod_set_value(st->chan_gpio, chan_gpio_val);
gpiod_set_value(st->temp_gpio, temp_gpio_val);
return 0;
}
static int ad7191_set_cs(struct ad_sigma_delta *sigma_delta, int assert)
{
struct spi_transfer t = {
.len = 0,
.cs_change = assert,
};
struct spi_message m;
spi_message_init_with_transfers(&m, &t, 1);
return spi_sync_locked(sigma_delta->spi, &m);
}
static int ad7191_set_mode(struct ad_sigma_delta *sd,
enum ad_sigma_delta_mode mode)
{
struct ad7191_state *st = ad_sigma_delta_to_ad7191(sd);
switch (mode) {
case AD_SD_MODE_CONTINUOUS:
case AD_SD_MODE_SINGLE:
return ad7191_set_cs(&st->sd, 1);
case AD_SD_MODE_IDLE:
return ad7191_set_cs(&st->sd, 0);
default:
return -EINVAL;
}
}
static const struct ad_sigma_delta_info ad7191_sigma_delta_info = {
.set_channel = ad7191_set_channel,
.set_mode = ad7191_set_mode,
.has_registers = false,
};
static int ad7191_init_regulators(struct iio_dev *indio_dev)
{
struct ad7191_state *st = iio_priv(indio_dev);
struct device *dev = &st->sd.spi->dev;
int ret;
ret = devm_regulator_get_enable(dev, "avdd");
if (ret)
return dev_err_probe(dev, ret, "Failed to enable specified AVdd supply\n");
ret = devm_regulator_get_enable(dev, "dvdd");
if (ret)
return dev_err_probe(dev, ret, "Failed to enable specified DVdd supply\n");
ret = devm_regulator_get_enable_read_voltage(dev, "vref");
if (ret < 0)
return dev_err_probe(dev, ret, "Failed to get Vref voltage\n");
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/clk.h`, `linux/device.h`, `linux/err.h`, `linux/gpio/consumer.h`, `linux/interrupt.h`, `linux/mod_devicetable.h`, `linux/mutex.h`.
- Detected declarations: `struct ad7191_state`, `enum ad7191_channel`, `function ad7191_set_channel`, `function ad7191_set_cs`, `function ad7191_set_mode`, `function ad7191_init_regulators`, `function ad7191_config_setup`, `function ad7191_clock_setup`, `function ad7191_setup`, `function ad7191_read_raw`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.