drivers/iio/adc/rzt2h_adc.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/rzt2h_adc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/rzt2h_adc.c- Extension
.c- Size
- 7011 bytes
- Lines
- 305
- 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/bitfield.hlinux/cleanup.hlinux/completion.hlinux/delay.hlinux/iio/adc-helpers.hlinux/iio/iio.hlinux/interrupt.hlinux/io.hlinux/iopoll.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/pm_runtime.hlinux/property.h
Detected Declarations
struct rzt2h_adcfunction rzt2h_adc_startfunction rzt2h_adc_stopfunction rzt2h_adc_read_singlefunction rzt2h_adc_set_calfunction rzt2h_adc_calibratefunction rzt2h_adc_read_rawfunction rzt2h_adc_isrfunction rzt2h_adc_parse_propertiesfunction rzt2h_adc_probefunction rzt2h_adc_pm_runtime_resume
Annotated Snippet
struct rzt2h_adc {
void __iomem *base;
struct device *dev;
struct completion completion;
/* lock to protect against multiple access to the device */
struct mutex lock;
const struct iio_chan_spec *channels;
unsigned int num_channels;
unsigned int max_channels;
};
static void rzt2h_adc_start(struct rzt2h_adc *adc, unsigned int conversion_type)
{
u16 reg;
reg = readw(adc->base + RZT2H_ADCSR_REG);
/* Set conversion type */
FIELD_MODIFY(RZT2H_ADCSR_ADCS_MASK, ®, conversion_type);
/* Set end of conversion interrupt and start bit. */
reg |= RZT2H_ADCSR_ADIE_MASK | RZT2H_ADCSR_ADST_MASK;
writew(reg, adc->base + RZT2H_ADCSR_REG);
}
static void rzt2h_adc_stop(struct rzt2h_adc *adc)
{
u16 reg;
reg = readw(adc->base + RZT2H_ADCSR_REG);
/* Clear end of conversion interrupt and start bit. */
reg &= ~(RZT2H_ADCSR_ADIE_MASK | RZT2H_ADCSR_ADST_MASK);
writew(reg, adc->base + RZT2H_ADCSR_REG);
}
static int rzt2h_adc_read_single(struct rzt2h_adc *adc, unsigned int ch, int *val)
{
int ret;
ret = pm_runtime_resume_and_get(adc->dev);
if (ret)
return ret;
mutex_lock(&adc->lock);
reinit_completion(&adc->completion);
/* Enable a single channel */
writew(RZT2H_ADANSA0_CH_MASK(ch), adc->base + RZT2H_ADANSA0_REG);
rzt2h_adc_start(adc, RZT2H_ADCSR_ADCS_SINGLE);
/*
* Datasheet Page 2770, Table 41.1:
* 0.32us per channel when sample-and-hold circuits are not in use.
*/
ret = wait_for_completion_timeout(&adc->completion, usecs_to_jiffies(1));
if (!ret) {
ret = -ETIMEDOUT;
goto disable;
}
*val = readw(adc->base + RZT2H_ADDR_REG(ch));
ret = IIO_VAL_INT;
disable:
rzt2h_adc_stop(adc);
mutex_unlock(&adc->lock);
pm_runtime_put_autosuspend(adc->dev);
return ret;
}
static void rzt2h_adc_set_cal(struct rzt2h_adc *adc, bool cal)
{
u16 val;
val = readw(adc->base + RZT2H_ADCALCTL_REG);
if (cal)
val |= RZT2H_ADCALCTL_CAL_MASK;
else
val &= ~RZT2H_ADCALCTL_CAL_MASK;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/cleanup.h`, `linux/completion.h`, `linux/delay.h`, `linux/iio/adc-helpers.h`, `linux/iio/iio.h`, `linux/interrupt.h`, `linux/io.h`.
- Detected declarations: `struct rzt2h_adc`, `function rzt2h_adc_start`, `function rzt2h_adc_stop`, `function rzt2h_adc_read_single`, `function rzt2h_adc_set_cal`, `function rzt2h_adc_calibrate`, `function rzt2h_adc_read_raw`, `function rzt2h_adc_isr`, `function rzt2h_adc_parse_properties`, `function rzt2h_adc_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.