drivers/iio/adc/vf610_adc.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/vf610_adc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/vf610_adc.c- Extension
.c- Size
- 23578 bytes
- Lines
- 963
- 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/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/property.hlinux/platform_device.hlinux/interrupt.hlinux/cleanup.hlinux/delay.hlinux/kernel.hlinux/slab.hlinux/io.hlinux/clk.hlinux/completion.hlinux/regulator/consumer.hlinux/err.hlinux/iio/iio.hlinux/iio/buffer.hlinux/iio/sysfs.hlinux/iio/trigger.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.h
Detected Declarations
struct vf610_adc_featurestruct vf610_adcstruct vf610_chip_infoenum clk_selenum vol_refenum average_selenum conversion_mode_selenum lst_adder_selfunction vf610_adc_calculate_ratesfunction vf610_adc_cfg_initfunction vf610_adc_cfg_post_setfunction vf610_adc_calibrationfunction vf610_adc_cfg_setfunction vf610_adc_sample_setfunction vf610_adc_hw_initfunction vf610_set_conversion_modefunction vf610_get_conversion_modefunction BITfunction vf610_adc_read_datafunction vf610_adc_isrfunction vf610_show_samp_freq_availfunction vf610_read_samplefunction vf610_read_rawfunction vf610_write_rawfunction vf610_adc_buffer_postenablefunction vf610_adc_buffer_predisablefunction vf610_adc_reg_accessfunction vf610_adc_action_removefunction vf610_adc_probefunction vf610_adc_suspendfunction vf610_adc_resume
Annotated Snippet
struct vf610_adc_feature {
enum clk_sel clk_sel;
enum vol_ref vol_ref;
enum conversion_mode_sel conv_mode;
int clk_div;
int sample_rate;
int res_mode;
u32 lst_adder_index;
u32 default_sample_time;
bool calibration;
bool ovwren;
};
struct vf610_adc {
struct device *dev;
void __iomem *regs;
struct clk *clk;
/* lock to protect against multiple access to the device */
struct mutex lock;
u32 vref_uv;
u32 value;
struct regulator *vref;
u32 max_adck_rate[3];
struct vf610_adc_feature adc_feature;
u32 sample_freq_avail[5];
struct completion completion;
/* Ensure the timestamp is naturally aligned */
struct {
u16 chan;
aligned_s64 timestamp;
} scan;
};
struct vf610_chip_info {
u8 num_channels;
};
static const u32 vf610_hw_avgs[] = { 1, 4, 8, 16, 32 };
static const u32 vf610_lst_adder[] = { 3, 5, 7, 9, 13, 17, 21, 25 };
static inline void vf610_adc_calculate_rates(struct vf610_adc *info)
{
struct vf610_adc_feature *adc_feature = &info->adc_feature;
unsigned long adck_rate, ipg_rate = clk_get_rate(info->clk);
u32 adck_period, lst_addr_min;
int divisor, i;
adck_rate = info->max_adck_rate[adc_feature->conv_mode];
if (adck_rate) {
/* calculate clk divider which is within specification */
divisor = ipg_rate / adck_rate;
adc_feature->clk_div = 1 << fls(divisor + 1);
} else {
/* fall-back value using a safe divisor */
adc_feature->clk_div = 8;
}
adck_rate = ipg_rate / adc_feature->clk_div;
/*
* Determine the long sample time adder value to be used based
* on the default minimum sample time provided.
*/
adck_period = NSEC_PER_SEC / adck_rate;
lst_addr_min = adc_feature->default_sample_time / adck_period;
for (i = 0; i < ARRAY_SIZE(vf610_lst_adder); i++) {
if (vf610_lst_adder[i] > lst_addr_min) {
adc_feature->lst_adder_index = i;
break;
}
}
/*
* Calculate ADC sample frequencies
* Sample time unit is ADCK cycles. ADCK clk source is ipg clock,
* which is the same as bus clock.
*
* ADC conversion time = SFCAdder + AverageNum x (BCT + LSTAdder)
* SFCAdder: fixed to 6 ADCK cycles
* AverageNum: 1, 4, 8, 16, 32 samples for hardware average.
* BCT (Base Conversion Time): fixed to 25 ADCK cycles for 12 bit mode
* LSTAdder(Long Sample Time): 3, 5, 7, 9, 13, 17, 21, 25 ADCK cycles
Annotation
- Immediate include surface: `linux/mod_devicetable.h`, `linux/module.h`, `linux/mutex.h`, `linux/property.h`, `linux/platform_device.h`, `linux/interrupt.h`, `linux/cleanup.h`, `linux/delay.h`.
- Detected declarations: `struct vf610_adc_feature`, `struct vf610_adc`, `struct vf610_chip_info`, `enum clk_sel`, `enum vol_ref`, `enum average_sel`, `enum conversion_mode_sel`, `enum lst_adder_sel`, `function vf610_adc_calculate_rates`, `function vf610_adc_cfg_init`.
- 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.