drivers/iio/adc/ti-adc128s052.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/ti-adc128s052.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/ti-adc128s052.c- Extension
.c- Size
- 7826 bytes
- Lines
- 287
- 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/cleanup.hlinux/err.hlinux/iio/iio.hlinux/mod_devicetable.hlinux/module.hlinux/property.hlinux/regulator/consumer.hlinux/spi/spi.h
Detected Declarations
struct adc128_configurationstruct adc128function adc128_adc_conversionfunction adc128_read_rawfunction adc128_probe
Annotated Snippet
struct adc128_configuration {
const struct iio_chan_spec *channels;
u8 num_channels;
const char *refname;
int num_other_regulators;
const char * const (*other_regulators)[];
};
struct adc128 {
struct spi_device *spi;
/*
* Serialize the SPI 'write-channel + read data' accesses and protect
* the shared buffer.
*/
struct mutex lock;
int vref_mv;
union {
__be16 buffer16;
u8 buffer[2];
} __aligned(IIO_DMA_MINALIGN);
};
static int adc128_adc_conversion(struct adc128 *adc, u8 channel)
{
int ret;
guard(mutex)(&adc->lock);
adc->buffer[0] = channel << 3;
adc->buffer[1] = 0;
ret = spi_write(adc->spi, &adc->buffer, sizeof(adc->buffer));
if (ret < 0)
return ret;
ret = spi_read(adc->spi, &adc->buffer16, sizeof(adc->buffer16));
if (ret < 0)
return ret;
return be16_to_cpu(adc->buffer16) & 0xFFF;
}
static int adc128_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *channel, int *val,
int *val2, long mask)
{
struct adc128 *adc = iio_priv(indio_dev);
int ret;
switch (mask) {
case IIO_CHAN_INFO_RAW:
ret = adc128_adc_conversion(adc, channel->channel);
if (ret < 0)
return ret;
*val = ret;
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
*val = adc->vref_mv;
*val2 = 12;
return IIO_VAL_FRACTIONAL_LOG2;
default:
return -EINVAL;
}
}
#define ADC128_VOLTAGE_CHANNEL(num) \
{ \
.type = IIO_VOLTAGE, \
.indexed = 1, \
.channel = (num), \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \
}
static const struct iio_chan_spec simple_1chan_adc_channels[] = {
ADC128_VOLTAGE_CHANNEL(0),
};
static const struct iio_chan_spec simple_2chan_adc_channels[] = {
ADC128_VOLTAGE_CHANNEL(0),
ADC128_VOLTAGE_CHANNEL(1),
};
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/err.h`, `linux/iio/iio.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/property.h`, `linux/regulator/consumer.h`, `linux/spi/spi.h`.
- Detected declarations: `struct adc128_configuration`, `struct adc128`, `function adc128_adc_conversion`, `function adc128_read_raw`, `function adc128_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.