drivers/iio/adc/ad799x.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/ad799x.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/ad799x.c- Extension
.c- Size
- 22994 bytes
- Lines
- 976
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/interrupt.hlinux/device.hlinux/kernel.hlinux/sysfs.hlinux/i2c.hlinux/regulator/consumer.hlinux/slab.hlinux/types.hlinux/err.hlinux/module.hlinux/mutex.hlinux/bitops.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/events.hlinux/iio/buffer.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.h
Detected Declarations
struct ad799x_chip_configstruct ad799x_chip_infostruct ad799x_statefunction ad799x_write_configfunction ad799x_read_configfunction ad799x_update_configfunction ad799x_trigger_handlerfunction ad799x_update_scan_modefunction ad799x_scan_directfunction ad799x_read_rawfunction ad799x_read_frequencyfunction ad799x_write_frequencyfunction ad799x_read_event_configfunction ad799x_write_event_configfunction ad799x_threshold_regfunction ad799x_write_event_valuefunction ad799x_read_event_valuefunction ad799x_event_handlerfunction ad799x_probefunction ad799x_removefunction ad799x_suspendfunction ad799x_resume
Annotated Snippet
struct ad799x_chip_config {
const struct iio_chan_spec channel[9];
u16 default_config;
const struct iio_info *info;
};
/**
* struct ad799x_chip_info - chip specific information
* @num_channels: number of channels
* @noirq_config: device configuration w/o IRQ
* @irq_config: device configuration w/IRQ
* @has_vref: device supports external reference voltage
*/
struct ad799x_chip_info {
int num_channels;
const struct ad799x_chip_config noirq_config;
const struct ad799x_chip_config irq_config;
bool has_vref;
};
struct ad799x_state {
struct i2c_client *client;
const struct ad799x_chip_config *chip_config;
struct regulator *reg;
struct regulator *vref;
/* lock to protect against multiple access to the device */
struct mutex lock;
unsigned int id;
u16 config;
u8 *rx_buf;
unsigned int transfer_size;
};
static int ad799x_write_config(struct ad799x_state *st, u16 val)
{
switch (st->id) {
case ad7997:
case ad7998:
return i2c_smbus_write_word_swapped(st->client, AD7998_CONF_REG,
val);
case ad7992:
case ad7993:
case ad7994:
return i2c_smbus_write_byte_data(st->client, AD7998_CONF_REG,
val);
default:
/* Will be written when doing a conversion */
st->config = val;
return 0;
}
}
static int ad799x_read_config(struct ad799x_state *st)
{
switch (st->id) {
case ad7997:
case ad7998:
return i2c_smbus_read_word_swapped(st->client, AD7998_CONF_REG);
case ad7992:
case ad7993:
case ad7994:
return i2c_smbus_read_byte_data(st->client, AD7998_CONF_REG);
default:
/* No readback support */
return st->config;
}
}
static int ad799x_update_config(struct ad799x_state *st, u16 config)
{
int ret;
ret = ad799x_write_config(st, config);
if (ret < 0)
return ret;
ret = ad799x_read_config(st);
if (ret < 0)
return ret;
st->config = ret;
return 0;
}
static irqreturn_t ad799x_trigger_handler(int irq, void *p)
{
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->indio_dev;
struct ad799x_state *st = iio_priv(indio_dev);
int b_sent;
Annotation
- Immediate include surface: `linux/interrupt.h`, `linux/device.h`, `linux/kernel.h`, `linux/sysfs.h`, `linux/i2c.h`, `linux/regulator/consumer.h`, `linux/slab.h`, `linux/types.h`.
- Detected declarations: `struct ad799x_chip_config`, `struct ad799x_chip_info`, `struct ad799x_state`, `function ad799x_write_config`, `function ad799x_read_config`, `function ad799x_update_config`, `function ad799x_trigger_handler`, `function ad799x_update_scan_mode`, `function ad799x_scan_direct`, `function ad799x_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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.