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.

Dependency Surface

Detected Declarations

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

Implementation Notes