drivers/iio/potentiometer/ad5272.c
Source file repositories/reference/linux-study-clean/drivers/iio/potentiometer/ad5272.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/potentiometer/ad5272.c- Extension
.c- Size
- 5539 bytes
- Lines
- 230
- 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/delay.hlinux/gpio/consumer.hlinux/i2c.hlinux/iio/iio.hlinux/module.hlinux/mod_devicetable.h
Detected Declarations
struct ad5272_cfgstruct ad5272_dataenum ad5272_typefunction ad5272_writefunction ad5272_readfunction ad5272_read_rawfunction ad5272_write_rawfunction ad5272_resetfunction ad5272_probe
Annotated Snippet
struct ad5272_cfg {
int max_pos;
int kohms;
int shift;
};
enum ad5272_type {
AD5272_020,
AD5272_050,
AD5272_100,
AD5274_020,
AD5274_100,
};
static const struct ad5272_cfg ad5272_cfg[] = {
[AD5272_020] = { .max_pos = 1024, .kohms = 20 },
[AD5272_050] = { .max_pos = 1024, .kohms = 50 },
[AD5272_100] = { .max_pos = 1024, .kohms = 100 },
[AD5274_020] = { .max_pos = 256, .kohms = 20, .shift = 2 },
[AD5274_100] = { .max_pos = 256, .kohms = 100, .shift = 2 },
};
struct ad5272_data {
struct i2c_client *client;
struct mutex lock;
const struct ad5272_cfg *cfg;
u8 buf[2] __aligned(IIO_DMA_MINALIGN);
};
static const struct iio_chan_spec ad5272_channel = {
.type = IIO_RESISTANCE,
.output = 1,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
};
static int ad5272_write(struct ad5272_data *data, int reg, int val)
{
int ret;
data->buf[0] = (reg << 2) | ((val >> 8) & 0x3);
data->buf[1] = (u8)val;
mutex_lock(&data->lock);
ret = i2c_master_send(data->client, data->buf, sizeof(data->buf));
mutex_unlock(&data->lock);
return ret < 0 ? ret : 0;
}
static int ad5272_read(struct ad5272_data *data, int reg, int *val)
{
int ret;
data->buf[0] = reg << 2;
data->buf[1] = 0;
mutex_lock(&data->lock);
ret = i2c_master_send(data->client, data->buf, sizeof(data->buf));
if (ret < 0)
goto error;
ret = i2c_master_recv(data->client, data->buf, sizeof(data->buf));
if (ret < 0)
goto error;
*val = ((data->buf[0] & 0x3) << 8) | data->buf[1];
ret = 0;
error:
mutex_unlock(&data->lock);
return ret;
}
static int ad5272_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
struct ad5272_data *data = iio_priv(indio_dev);
int ret;
switch (mask) {
case IIO_CHAN_INFO_RAW: {
ret = ad5272_read(data, AD5272_RDAC_RD, val);
*val = *val >> data->cfg->shift;
return ret ? ret : IIO_VAL_INT;
}
case IIO_CHAN_INFO_SCALE:
*val = 1000 * data->cfg->kohms;
*val2 = data->cfg->max_pos;
return IIO_VAL_FRACTIONAL;
}
Annotation
- Immediate include surface: `linux/delay.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/iio/iio.h`, `linux/module.h`, `linux/mod_devicetable.h`.
- Detected declarations: `struct ad5272_cfg`, `struct ad5272_data`, `enum ad5272_type`, `function ad5272_write`, `function ad5272_read`, `function ad5272_read_raw`, `function ad5272_write_raw`, `function ad5272_reset`, `function ad5272_probe`.
- 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.