drivers/iio/adc/max1118.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/max1118.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/max1118.c- Extension
.c- Size
- 6534 bytes
- Lines
- 288
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/iio.hlinux/iio/buffer.hlinux/iio/triggered_buffer.hlinux/iio/trigger_consumer.hlinux/regulator/consumer.h
Detected Declarations
struct max1118enum max1118_idfunction max1118_readfunction max1118_get_vref_mVfunction max1118_read_rawfunction max1118_trigger_handlerfunction iio_for_each_active_channelfunction max1118_reg_disablefunction max1118_probe
Annotated Snippet
struct max1118 {
struct spi_device *spi;
struct mutex lock;
struct regulator *reg;
/* Ensure natural alignment of buffer elements */
struct {
u8 channels[2];
aligned_s64 ts;
} scan;
u8 data __aligned(IIO_DMA_MINALIGN);
};
#define MAX1118_CHANNEL(ch) \
{ \
.type = IIO_VOLTAGE, \
.indexed = 1, \
.channel = (ch), \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
.scan_index = ch, \
.scan_type = { \
.sign = 'u', \
.realbits = 8, \
.storagebits = 8, \
}, \
}
static const struct iio_chan_spec max1118_channels[] = {
MAX1118_CHANNEL(0),
MAX1118_CHANNEL(1),
IIO_CHAN_SOFT_TIMESTAMP(2),
};
static int max1118_read(struct iio_dev *indio_dev, int channel)
{
struct max1118 *adc = iio_priv(indio_dev);
struct spi_transfer xfers[] = {
/*
* To select CH1 for conversion, CNVST pin must be brought high
* and low for a second time.
*/
{
.len = 0,
.delay = { /* > CNVST Low Time 100 ns */
.value = 1,
.unit = SPI_DELAY_UNIT_USECS
},
.cs_change = 1,
},
/*
* The acquisition interval begins with the falling edge of
* CNVST. The total acquisition and conversion process takes
* <7.5us.
*/
{
.len = 0,
.delay = {
.value = 8,
.unit = SPI_DELAY_UNIT_USECS
},
},
{
.rx_buf = &adc->data,
.len = 1,
},
};
int ret;
if (channel == 0)
ret = spi_sync_transfer(adc->spi, xfers + 1, 2);
else
ret = spi_sync_transfer(adc->spi, xfers, 3);
if (ret)
return ret;
return adc->data;
}
static int max1118_get_vref_mV(struct iio_dev *indio_dev)
{
struct max1118 *adc = iio_priv(indio_dev);
const struct spi_device_id *id = spi_get_device_id(adc->spi);
int vref_uV;
switch (id->driver_data) {
case max1117:
return 2048;
case max1119:
Annotation
- Immediate include surface: `linux/module.h`, `linux/mod_devicetable.h`, `linux/spi/spi.h`, `linux/iio/iio.h`, `linux/iio/buffer.h`, `linux/iio/triggered_buffer.h`, `linux/iio/trigger_consumer.h`, `linux/regulator/consumer.h`.
- Detected declarations: `struct max1118`, `enum max1118_id`, `function max1118_read`, `function max1118_get_vref_mV`, `function max1118_read_raw`, `function max1118_trigger_handler`, `function iio_for_each_active_channel`, `function max1118_reg_disable`, `function max1118_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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.