drivers/iio/adc/stmpe-adc.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/stmpe-adc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/stmpe-adc.c- Extension
.c- Size
- 8418 bytes
- Lines
- 366
- 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/completion.hlinux/err.hlinux/iio/iio.hlinux/interrupt.hlinux/kernel.hlinux/mfd/stmpe.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/device.h
Detected Declarations
struct stmpe_adcfunction stmpe_read_voltagefunction stmpe_read_tempfunction stmpe_read_rawfunction stmpe_adc_isrfunction stmpe_adc_voltage_chanfunction stmpe_adc_temp_chanfunction stmpe_adc_init_hwfunction stmpe_adc_probefunction stmpe_adc_resume
Annotated Snippet
struct stmpe_adc {
struct stmpe *stmpe;
struct clk *clk;
struct device *dev;
struct mutex lock;
/* We are allocating plus one for the temperature channel */
struct iio_chan_spec stmpe_adc_iio_channels[STMPE_ADC_LAST_NR + 2];
struct completion completion;
u8 channel;
u32 value;
};
static int stmpe_read_voltage(struct stmpe_adc *info,
struct iio_chan_spec const *chan, int *val)
{
unsigned long ret;
mutex_lock(&info->lock);
reinit_completion(&info->completion);
info->channel = (u8)chan->channel;
if (info->channel > STMPE_ADC_LAST_NR) {
mutex_unlock(&info->lock);
return -EINVAL;
}
stmpe_reg_write(info->stmpe, STMPE_REG_ADC_CAPT,
STMPE_ADC_CH(info->channel));
ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
if (ret == 0) {
stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA,
STMPE_ADC_CH(info->channel));
mutex_unlock(&info->lock);
return -ETIMEDOUT;
}
*val = info->value;
mutex_unlock(&info->lock);
return 0;
}
static int stmpe_read_temp(struct stmpe_adc *info,
struct iio_chan_spec const *chan, int *val)
{
unsigned long ret;
mutex_lock(&info->lock);
reinit_completion(&info->completion);
info->channel = (u8)chan->channel;
if (info->channel != STMPE_TEMP_CHANNEL) {
mutex_unlock(&info->lock);
return -EINVAL;
}
stmpe_reg_write(info->stmpe, STMPE_REG_TEMP_CTRL,
STMPE_START_ONE_TEMP_CONV);
ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
if (ret == 0) {
mutex_unlock(&info->lock);
return -ETIMEDOUT;
}
/*
* absolute temp = +V3.3 * value /7.51 [K]
* scale to [milli °C]
*/
*val = ((449960l * info->value) / 1024l) - 273150;
mutex_unlock(&info->lock);
return 0;
}
static int stmpe_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val,
Annotation
- Immediate include surface: `linux/completion.h`, `linux/err.h`, `linux/iio/iio.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/mfd/stmpe.h`, `linux/module.h`, `linux/of.h`.
- Detected declarations: `struct stmpe_adc`, `function stmpe_read_voltage`, `function stmpe_read_temp`, `function stmpe_read_raw`, `function stmpe_adc_isr`, `function stmpe_adc_voltage_chan`, `function stmpe_adc_temp_chan`, `function stmpe_adc_init_hw`, `function stmpe_adc_probe`, `function stmpe_adc_resume`.
- 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.