drivers/iio/potentiometer/mcp41010.c
Source file repositories/reference/linux-study-clean/drivers/iio/potentiometer/mcp41010.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/potentiometer/mcp41010.c- Extension
.c- Size
- 5204 bytes
- Lines
- 203
- 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/cache.hlinux/err.hlinux/iio/iio.hlinux/iio/types.hlinux/module.hlinux/mod_devicetable.hlinux/mutex.hlinux/property.hlinux/spi/spi.h
Detected Declarations
struct mcp41010_cfgstruct mcp41010_dataenum mcp41010_typefunction mcp41010_read_rawfunction mcp41010_write_rawfunction mcp41010_probe
Annotated Snippet
struct mcp41010_cfg {
char name[16];
int wipers;
int kohms;
};
enum mcp41010_type {
MCP41010,
MCP41050,
MCP41100,
MCP42010,
MCP42050,
MCP42100,
};
static const struct mcp41010_cfg mcp41010_cfg[] = {
[MCP41010] = { .name = "mcp41010", .wipers = 1, .kohms = 10, },
[MCP41050] = { .name = "mcp41050", .wipers = 1, .kohms = 50, },
[MCP41100] = { .name = "mcp41100", .wipers = 1, .kohms = 100, },
[MCP42010] = { .name = "mcp42010", .wipers = 2, .kohms = 10, },
[MCP42050] = { .name = "mcp42050", .wipers = 2, .kohms = 50, },
[MCP42100] = { .name = "mcp42100", .wipers = 2, .kohms = 100, },
};
struct mcp41010_data {
struct spi_device *spi;
const struct mcp41010_cfg *cfg;
struct mutex lock; /* Protect write sequences */
unsigned int value[MCP41010_MAX_WIPERS]; /* Cache wiper values */
u8 buf[2] __aligned(IIO_DMA_MINALIGN);
};
#define MCP41010_CHANNEL(ch) { \
.type = IIO_RESISTANCE, \
.indexed = 1, \
.output = 1, \
.channel = (ch), \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
}
static const struct iio_chan_spec mcp41010_channels[] = {
MCP41010_CHANNEL(0),
MCP41010_CHANNEL(1),
};
static int mcp41010_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
struct mcp41010_data *data = iio_priv(indio_dev);
int channel = chan->channel;
switch (mask) {
case IIO_CHAN_INFO_RAW:
*val = data->value[channel];
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
*val = 1000 * data->cfg->kohms;
*val2 = MCP41010_WIPER_MAX;
return IIO_VAL_FRACTIONAL;
}
return -EINVAL;
}
static int mcp41010_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val, int val2, long mask)
{
int err;
struct mcp41010_data *data = iio_priv(indio_dev);
int channel = chan->channel;
if (mask != IIO_CHAN_INFO_RAW)
return -EINVAL;
if (val > MCP41010_WIPER_MAX || val < 0)
return -EINVAL;
mutex_lock(&data->lock);
data->buf[0] = MCP41010_WIPER_CHANNEL << channel;
data->buf[0] |= MCP41010_WRITE;
data->buf[1] = val & 0xff;
err = spi_write(data->spi, data->buf, sizeof(data->buf));
if (!err)
data->value[channel] = val;
Annotation
- Immediate include surface: `linux/cache.h`, `linux/err.h`, `linux/iio/iio.h`, `linux/iio/types.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/mutex.h`, `linux/property.h`.
- Detected declarations: `struct mcp41010_cfg`, `struct mcp41010_data`, `enum mcp41010_type`, `function mcp41010_read_raw`, `function mcp41010_write_raw`, `function mcp41010_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.