drivers/iio/potentiometer/max5487.c
Source file repositories/reference/linux-study-clean/drivers/iio/potentiometer/max5487.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/potentiometer/max5487.c- Extension
.c- Size
- 3856 bytes
- Lines
- 158
- 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/module.hlinux/mod_devicetable.hlinux/spi/spi.hlinux/iio/sysfs.hlinux/iio/iio.h
Detected Declarations
struct max5487_datafunction max5487_write_cmdfunction max5487_read_rawfunction max5487_write_rawfunction max5487_spi_probefunction max5487_spi_remove
Annotated Snippet
struct max5487_data {
struct spi_device *spi;
int kohms;
};
#define MAX5487_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), \
}
static const struct iio_chan_spec max5487_channels[] = {
MAX5487_CHANNEL(0, MAX5487_WRITE_WIPER_A),
MAX5487_CHANNEL(1, MAX5487_WRITE_WIPER_B),
};
static int max5487_write_cmd(struct spi_device *spi, u16 cmd)
{
return spi_write(spi, (const void *) &cmd, sizeof(u16));
}
static int max5487_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
struct max5487_data *data = iio_priv(indio_dev);
if (mask != IIO_CHAN_INFO_SCALE)
return -EINVAL;
*val = 1000 * data->kohms;
*val2 = MAX5487_MAX_POS;
return IIO_VAL_FRACTIONAL;
}
static int max5487_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val, int val2, long mask)
{
struct max5487_data *data = iio_priv(indio_dev);
if (mask != IIO_CHAN_INFO_RAW)
return -EINVAL;
if (val < 0 || val > MAX5487_MAX_POS)
return -EINVAL;
return max5487_write_cmd(data->spi, chan->address | val);
}
static const struct iio_info max5487_info = {
.read_raw = max5487_read_raw,
.write_raw = max5487_write_raw,
};
static int max5487_spi_probe(struct spi_device *spi)
{
struct iio_dev *indio_dev;
struct max5487_data *data;
const struct spi_device_id *id = spi_get_device_id(spi);
int ret;
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data));
if (!indio_dev)
return -ENOMEM;
spi_set_drvdata(spi, indio_dev);
data = iio_priv(indio_dev);
data->spi = spi;
data->kohms = id->driver_data;
indio_dev->info = &max5487_info;
indio_dev->name = id->name;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = max5487_channels;
indio_dev->num_channels = ARRAY_SIZE(max5487_channels);
/* restore both wiper regs from NV regs */
ret = max5487_write_cmd(data->spi, MAX5487_COPY_NV_TO_AB);
if (ret < 0)
return ret;
return iio_device_register(indio_dev);
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/mod_devicetable.h`, `linux/spi/spi.h`, `linux/iio/sysfs.h`, `linux/iio/iio.h`.
- Detected declarations: `struct max5487_data`, `function max5487_write_cmd`, `function max5487_read_raw`, `function max5487_write_raw`, `function max5487_spi_probe`, `function max5487_spi_remove`.
- 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.