drivers/iio/adc/mxs-lradc-adc.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/mxs-lradc-adc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/mxs-lradc-adc.c- Extension
.c- Size
- 23068 bytes
- Lines
- 830
- 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/device.hlinux/err.hlinux/interrupt.hlinux/mfd/core.hlinux/mfd/mxs-lradc.hlinux/module.hlinux/of_irq.hlinux/platform_device.hlinux/sysfs.hlinux/iio/buffer.hlinux/iio/iio.hlinux/iio/trigger.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.hlinux/iio/sysfs.h
Detected Declarations
struct mxs_lradc_scalestruct mxs_lradc_adcenum mxs_lradc_divbytwofunction mxs_lradc_adc_read_singlefunction mxs_lradc_adc_read_tempfunction mxs_lradc_adc_read_rawfunction mxs_lradc_adc_write_rawfunction mxs_lradc_adc_write_raw_get_fmtfunction mxs_lradc_adc_show_scale_availfunction mxs_lradc_adc_handle_irqfunction mxs_lradc_adc_trigger_handlerfunction for_each_set_bitfunction mxs_lradc_adc_configure_triggerfunction mxs_lradc_adc_trigger_initfunction mxs_lradc_adc_trigger_removefunction mxs_lradc_adc_buffer_preenablefunction for_each_set_bitfunction mxs_lradc_adc_buffer_postdisablefunction mxs_lradc_adc_validate_scan_maskfunction mxs_lradc_adc_hw_initfunction mxs_lradc_adc_hw_stopfunction mxs_lradc_adc_probefunction mxs_lradc_adc_remove
Annotated Snippet
struct mxs_lradc_scale {
unsigned int integer;
unsigned int nano;
};
struct mxs_lradc_adc {
struct mxs_lradc *lradc;
struct device *dev;
void __iomem *base;
/* Maximum of 8 channels + 8 byte ts */
u32 buffer[10] __aligned(8);
struct iio_trigger *trig;
struct completion completion;
spinlock_t lock;
const u32 *vref_mv;
struct mxs_lradc_scale scale_avail[LRADC_MAX_TOTAL_CHANS][2];
unsigned long is_divided;
};
/* Raw I/O operations */
static int mxs_lradc_adc_read_single(struct iio_dev *iio_dev, int chan,
int *val)
{
struct mxs_lradc_adc *adc = iio_priv(iio_dev);
struct mxs_lradc *lradc = adc->lradc;
int ret;
/*
* See if there is no buffered operation in progress. If there is simply
* bail out. This can be improved to support both buffered and raw IO at
* the same time, yet the code becomes horribly complicated. Therefore I
* applied KISS principle here.
*/
if (!iio_device_claim_direct(iio_dev))
return -EBUSY;
reinit_completion(&adc->completion);
/*
* No buffered operation in progress, map the channel and trigger it.
* Virtual channel 0 is always used here as the others are always not
* used if doing raw sampling.
*/
if (lradc->soc == IMX28_LRADC)
writel(LRADC_CTRL1_LRADC_IRQ_EN(0),
adc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR);
writel(0x1, adc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR);
/* Enable / disable the divider per requirement */
if (test_bit(chan, &adc->is_divided))
writel(1 << LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET,
adc->base + LRADC_CTRL2 + STMP_OFFSET_REG_SET);
else
writel(1 << LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET,
adc->base + LRADC_CTRL2 + STMP_OFFSET_REG_CLR);
/* Clean the slot's previous content, then set new one. */
writel(LRADC_CTRL4_LRADCSELECT_MASK(0),
adc->base + LRADC_CTRL4 + STMP_OFFSET_REG_CLR);
writel(chan, adc->base + LRADC_CTRL4 + STMP_OFFSET_REG_SET);
writel(0, adc->base + LRADC_CH(0));
/* Enable the IRQ and start sampling the channel. */
writel(LRADC_CTRL1_LRADC_IRQ_EN(0),
adc->base + LRADC_CTRL1 + STMP_OFFSET_REG_SET);
writel(BIT(0), adc->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET);
/* Wait for completion on the channel, 1 second max. */
ret = wait_for_completion_killable_timeout(&adc->completion, HZ);
if (!ret)
ret = -ETIMEDOUT;
if (ret < 0)
goto err;
/* Read the data. */
*val = readl(adc->base + LRADC_CH(0)) & LRADC_CH_VALUE_MASK;
ret = IIO_VAL_INT;
err:
writel(LRADC_CTRL1_LRADC_IRQ_EN(0),
adc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR);
iio_device_release_direct(iio_dev);
return ret;
}
Annotation
- Immediate include surface: `linux/completion.h`, `linux/device.h`, `linux/err.h`, `linux/interrupt.h`, `linux/mfd/core.h`, `linux/mfd/mxs-lradc.h`, `linux/module.h`, `linux/of_irq.h`.
- Detected declarations: `struct mxs_lradc_scale`, `struct mxs_lradc_adc`, `enum mxs_lradc_divbytwo`, `function mxs_lradc_adc_read_single`, `function mxs_lradc_adc_read_temp`, `function mxs_lradc_adc_read_raw`, `function mxs_lradc_adc_write_raw`, `function mxs_lradc_adc_write_raw_get_fmt`, `function mxs_lradc_adc_show_scale_avail`, `function mxs_lradc_adc_handle_irq`.
- 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.