drivers/iio/potentiometer/ds1803.c
Source file repositories/reference/linux-study-clean/drivers/iio/potentiometer/ds1803.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/potentiometer/ds1803.c- Extension
.c- Size
- 6333 bytes
- Lines
- 261
- 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/err.hlinux/i2c.hlinux/iio/iio.hlinux/module.hlinux/mod_devicetable.hlinux/property.h
Detected Declarations
struct ds1803_cfgstruct ds1803_dataenum ds1803_typefunction ds1803_readfunction ds3502_readfunction ds1803_read_rawfunction ds1803_write_rawfunction ds1803_read_availfunction ds1803_probe
Annotated Snippet
struct ds1803_cfg {
int wipers;
int avail[3];
int kohms;
const struct iio_chan_spec *channels;
u8 num_channels;
int (*read)(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int *val);
};
struct ds1803_data {
struct i2c_client *client;
const struct ds1803_cfg *cfg;
};
#define DS1803_CHANNEL(ch, addr) { \
.type = IIO_RESISTANCE, \
.indexed = 1, \
.output = 1, \
.channel = (ch), \
.address = (addr), \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_RAW), \
}
static const struct iio_chan_spec ds1803_channels[] = {
DS1803_CHANNEL(0, DS1803_WIPER_0),
DS1803_CHANNEL(1, DS1803_WIPER_1),
};
static const struct iio_chan_spec ds3502_channels[] = {
DS1803_CHANNEL(0, DS3502_WR_IVR),
};
static int ds1803_read(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val)
{
struct ds1803_data *data = iio_priv(indio_dev);
int ret;
u8 result[ARRAY_SIZE(ds1803_channels)];
ret = i2c_master_recv(data->client, result, indio_dev->num_channels);
if (ret < 0)
return ret;
*val = result[chan->channel];
return ret;
}
static int ds3502_read(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val)
{
struct ds1803_data *data = iio_priv(indio_dev);
int ret;
ret = i2c_smbus_read_byte_data(data->client, chan->address);
if (ret < 0)
return ret;
*val = ret;
return ret;
}
static const struct ds1803_cfg ds1803_cfg[] = {
[DS1803_010] = {
.wipers = 2,
.avail = { 0, 1, 255 },
.kohms = 10,
.channels = ds1803_channels,
.num_channels = ARRAY_SIZE(ds1803_channels),
.read = ds1803_read,
},
[DS1803_050] = {
.wipers = 2,
.avail = { 0, 1, 255 },
.kohms = 50,
.channels = ds1803_channels,
.num_channels = ARRAY_SIZE(ds1803_channels),
.read = ds1803_read,
},
[DS1803_100] = {
.wipers = 2,
.avail = { 0, 1, 255 },
.kohms = 100,
.channels = ds1803_channels,
.num_channels = ARRAY_SIZE(ds1803_channels),
.read = ds1803_read,
Annotation
- Immediate include surface: `linux/err.h`, `linux/i2c.h`, `linux/iio/iio.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/property.h`.
- Detected declarations: `struct ds1803_cfg`, `struct ds1803_data`, `enum ds1803_type`, `function ds1803_read`, `function ds3502_read`, `function ds1803_read_raw`, `function ds1803_write_raw`, `function ds1803_read_avail`, `function ds1803_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.