drivers/iio/adc/rn5t618-adc.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/rn5t618-adc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/rn5t618-adc.c- Extension
.c- Size
- 6452 bytes
- Lines
- 260
- 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.
- 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/kernel.hlinux/device.hlinux/errno.hlinux/interrupt.hlinux/init.hlinux/module.hlinux/mfd/rn5t618.hlinux/platform_device.hlinux/completion.hlinux/regmap.hlinux/iio/iio.hlinux/iio/driver.hlinux/iio/machine.hlinux/slab.h
Detected Declarations
struct rn5t618_adc_dataenum rn5t618_channelsfunction rn5t618_read_adc_regfunction rn5t618_adc_irqfunction rn5t618_adc_readfunction rn5t618_adc_probe
Annotated Snippet
struct rn5t618_adc_data {
struct device *dev;
struct rn5t618 *rn5t618;
struct completion conv_completion;
int irq;
};
enum rn5t618_channels {
LIMMON = 0,
VBAT,
VADP,
VUSB,
VSYS,
VTHM,
AIN1,
AIN0
};
static const struct u16_fract rn5t618_ratios[8] = {
[LIMMON] = {50, 32}, /* measured across 20mOhm, amplified by 32 */
[VBAT] = {2, 1},
[VADP] = {3, 1},
[VUSB] = {3, 1},
[VSYS] = {3, 1},
[VTHM] = {1, 1},
[AIN1] = {1, 1},
[AIN0] = {1, 1},
};
static int rn5t618_read_adc_reg(struct rn5t618 *rn5t618, int reg, u16 *val)
{
u8 data[2];
int ret;
ret = regmap_bulk_read(rn5t618->regmap, reg, data, sizeof(data));
if (ret < 0)
return ret;
*val = (data[0] << 4) | (data[1] & 0xF);
return 0;
}
static irqreturn_t rn5t618_adc_irq(int irq, void *data)
{
struct rn5t618_adc_data *adc = data;
unsigned int r = 0;
int ret;
/* clear low & high threshold irqs */
regmap_write(adc->rn5t618->regmap, RN5T618_IR_ADC1, 0);
regmap_write(adc->rn5t618->regmap, RN5T618_IR_ADC2, 0);
ret = regmap_read(adc->rn5t618->regmap, RN5T618_IR_ADC3, &r);
if (ret < 0)
dev_err(adc->dev, "failed to read IRQ status: %d\n", ret);
regmap_write(adc->rn5t618->regmap, RN5T618_IR_ADC3, 0);
if (r & RN5T618_ADCEND_IRQ)
complete(&adc->conv_completion);
return IRQ_HANDLED;
}
static int rn5t618_adc_read(struct iio_dev *iio_dev,
const struct iio_chan_spec *chan,
int *val, int *val2, long mask)
{
struct rn5t618_adc_data *adc = iio_priv(iio_dev);
u16 raw;
int ret;
if (mask == IIO_CHAN_INFO_SCALE) {
*val = RN5T618_REFERENCE_VOLT *
rn5t618_ratios[chan->channel].numerator;
*val2 = rn5t618_ratios[chan->channel].denominator * 4095;
return IIO_VAL_FRACTIONAL;
}
/* select channel */
ret = regmap_update_bits(adc->rn5t618->regmap, RN5T618_ADCCNT3,
RN5T618_ADCCNT3_CHANNEL_MASK,
chan->channel);
if (ret < 0)
return ret;
ret = regmap_write(adc->rn5t618->regmap, RN5T618_EN_ADCIR3,
RN5T618_ADCEND_IRQ);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/device.h`, `linux/errno.h`, `linux/interrupt.h`, `linux/init.h`, `linux/module.h`, `linux/mfd/rn5t618.h`, `linux/platform_device.h`.
- Detected declarations: `struct rn5t618_adc_data`, `enum rn5t618_channels`, `function rn5t618_read_adc_reg`, `function rn5t618_adc_irq`, `function rn5t618_adc_read`, `function rn5t618_adc_probe`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- 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.