drivers/iio/potentiometer/ad5110.c
Source file repositories/reference/linux-study-clean/drivers/iio/potentiometer/ad5110.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/potentiometer/ad5110.c- Extension
.c- Size
- 8227 bytes
- Lines
- 350
- 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/delay.hlinux/device.hlinux/i2c.hlinux/module.hlinux/iio/iio.hlinux/iio/sysfs.h
Detected Declarations
struct ad5110_cfgstruct ad5110_dataenum ad5110_typefunction ad5110_readfunction ad5110_writefunction ad5110_resistor_tolfunction store_eeprom_showfunction store_eeprom_storefunction ad5110_read_rawfunction ad5110_write_rawfunction ad5110_probe
Annotated Snippet
struct ad5110_cfg {
int max_pos;
int kohms;
int shift;
};
enum ad5110_type {
AD5110_10,
AD5110_80,
AD5112_05,
AD5112_10,
AD5112_80,
AD5114_10,
AD5114_80,
};
static const struct ad5110_cfg ad5110_cfg[] = {
[AD5110_10] = { .max_pos = 128, .kohms = 10 },
[AD5110_80] = { .max_pos = 128, .kohms = 80 },
[AD5112_05] = { .max_pos = 64, .kohms = 5, .shift = 1 },
[AD5112_10] = { .max_pos = 64, .kohms = 10, .shift = 1 },
[AD5112_80] = { .max_pos = 64, .kohms = 80, .shift = 1 },
[AD5114_10] = { .max_pos = 32, .kohms = 10, .shift = 2 },
[AD5114_80] = { .max_pos = 32, .kohms = 80, .shift = 2 },
};
struct ad5110_data {
struct i2c_client *client;
s16 tol; /* resistor tolerance */
bool enable;
struct mutex lock;
const struct ad5110_cfg *cfg;
/*
* DMA (thus cache coherency maintenance) may require the
* transfer buffers to live in their own cache lines.
*/
u8 buf[2] __aligned(IIO_DMA_MINALIGN);
};
static const struct iio_chan_spec ad5110_channels[] = {
{
.type = IIO_RESISTANCE,
.output = 1,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_OFFSET) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_ENABLE),
},
};
static int ad5110_read(struct ad5110_data *data, u8 cmd, int *val)
{
int ret;
mutex_lock(&data->lock);
data->buf[0] = cmd;
data->buf[1] = *val;
ret = i2c_master_send_dmasafe(data->client, data->buf, sizeof(data->buf));
if (ret < 0) {
goto error;
} else if (ret != sizeof(data->buf)) {
ret = -EIO;
goto error;
}
ret = i2c_master_recv_dmasafe(data->client, data->buf, 1);
if (ret < 0) {
goto error;
} else if (ret != 1) {
ret = -EIO;
goto error;
}
*val = data->buf[0];
ret = 0;
error:
mutex_unlock(&data->lock);
return ret;
}
static int ad5110_write(struct ad5110_data *data, u8 cmd, u8 val)
{
int ret;
mutex_lock(&data->lock);
data->buf[0] = cmd;
data->buf[1] = val;
ret = i2c_master_send_dmasafe(data->client, data->buf, sizeof(data->buf));
if (ret < 0) {
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/delay.h`, `linux/device.h`, `linux/i2c.h`, `linux/module.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`.
- Detected declarations: `struct ad5110_cfg`, `struct ad5110_data`, `enum ad5110_type`, `function ad5110_read`, `function ad5110_write`, `function ad5110_resistor_tol`, `function store_eeprom_show`, `function store_eeprom_store`, `function ad5110_read_raw`, `function ad5110_write_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.