drivers/iio/adc/rzg2l_adc.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/rzg2l_adc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/rzg2l_adc.c- Extension
.c- Size
- 14962 bytes
- Lines
- 607
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- 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.hlinux/reset.h
Detected Declarations
struct rzg2l_adc_hw_paramsstruct rzg2l_adc_datastruct rzg2l_adcstruct rzg2l_adc_channelfunction rzg2l_adc_readlfunction rzg2l_adc_writelfunction rzg2l_adc_pwrfunction rzg2l_adc_start_stopfunction rzg2l_set_triggerfunction rzg2l_adc_ch_to_adsmp_indexfunction rzg2l_adc_conversion_setupfunction rzg2l_adc_conversionfunction rzg2l_adc_read_rawfunction rzg2l_adc_read_labelfunction rzg2l_adc_isrfunction rzg2l_adc_parse_propertiesfunction rzg2l_adc_hw_initfunction rzg2l_adc_probefunction rzg2l_adc_pm_runtime_suspendfunction rzg2l_adc_pm_runtime_resumefunction rzg2l_adc_suspendfunction rzg2l_adc_resume
Annotated Snippet
struct rzg2l_adc_hw_params {
u16 default_adsmp[2];
u16 adsmp_mask;
u16 adint_inten_mask;
u8 default_adcmp;
u8 num_channels;
bool adivc;
};
struct rzg2l_adc_data {
const struct iio_chan_spec *channels;
u8 num_channels;
};
struct rzg2l_adc {
void __iomem *base;
struct reset_control *presetn;
struct reset_control *adrstn;
const struct rzg2l_adc_data *data;
const struct rzg2l_adc_hw_params *hw_params;
struct completion completion;
struct mutex lock;
u16 last_val[RZG2L_ADC_MAX_CHANNELS];
};
/**
* struct rzg2l_adc_channel - ADC channel descriptor
* @name: ADC channel name
* @type: ADC channel type
*/
struct rzg2l_adc_channel {
const char * const name;
enum iio_chan_type type;
};
static const struct rzg2l_adc_channel rzg2l_adc_channels[] = {
{ "adc0", IIO_VOLTAGE },
{ "adc1", IIO_VOLTAGE },
{ "adc2", IIO_VOLTAGE },
{ "adc3", IIO_VOLTAGE },
{ "adc4", IIO_VOLTAGE },
{ "adc5", IIO_VOLTAGE },
{ "adc6", IIO_VOLTAGE },
{ "adc7", IIO_VOLTAGE },
{ "adc8", IIO_TEMP },
};
static unsigned int rzg2l_adc_readl(struct rzg2l_adc *adc, u32 reg)
{
return readl(adc->base + reg);
}
static void rzg2l_adc_writel(struct rzg2l_adc *adc, unsigned int reg, u32 val)
{
writel(val, adc->base + reg);
}
static void rzg2l_adc_pwr(struct rzg2l_adc *adc, bool on)
{
u32 reg;
reg = rzg2l_adc_readl(adc, RZG2L_ADM(0));
if (on)
reg |= RZG2L_ADM0_PWDWNB;
else
reg &= ~RZG2L_ADM0_PWDWNB;
rzg2l_adc_writel(adc, RZG2L_ADM(0), reg);
udelay(2);
}
static void rzg2l_adc_start_stop(struct rzg2l_adc *adc, bool start)
{
int ret;
u32 reg;
reg = rzg2l_adc_readl(adc, RZG2L_ADM(0));
if (start)
reg |= RZG2L_ADM0_ADCE;
else
reg &= ~RZG2L_ADM0_ADCE;
rzg2l_adc_writel(adc, RZG2L_ADM(0), reg);
if (start)
return;
ret = read_poll_timeout(rzg2l_adc_readl, reg, !(reg & (RZG2L_ADM0_ADBSY | RZG2L_ADM0_ADCE)),
200, 1000, true, adc, RZG2L_ADM(0));
if (ret)
pr_err("%s stopping ADC timed out\n", __func__);
}
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 rzg2l_adc_hw_params`, `struct rzg2l_adc_data`, `struct rzg2l_adc`, `struct rzg2l_adc_channel`, `function rzg2l_adc_readl`, `function rzg2l_adc_writel`, `function rzg2l_adc_pwr`, `function rzg2l_adc_start_stop`, `function rzg2l_set_trigger`, `function rzg2l_adc_ch_to_adsmp_index`.
- 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.