drivers/iio/adc/ad4851.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/ad4851.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/ad4851.c- Extension
.c- Size
- 32375 bytes
- Lines
- 1318
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/array_size.hlinux/bitfield.hlinux/bits.hlinux/delay.hlinux/device.hlinux/err.hlinux/minmax.hlinux/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/pwm.hlinux/regmap.hlinux/regulator/consumer.hlinux/spi/spi.hlinux/types.hlinux/unaligned.hlinux/units.hlinux/iio/backend.hlinux/iio/iio.h
Detected Declarations
struct ad4851_scalestruct ad4851_chip_infostruct ad4851_statefunction ad4851_reg_accessfunction ad4851_set_sampling_freqfunction ad4851_osr_to_regvalfunction __ad4851_get_scalefunction ad4851_scale_fillfunction ad4851_set_oversampling_ratiofunction ad4851_get_oversampling_ratiofunction ad4851_pwm_disablefunction ad4851_setupfunction ad4851_find_optfunction for_each_clear_bitrange_fromfunction ad4851_calibratefunction ad4851_get_calibscalefunction ad4851_set_calibscalefunction ad4851_get_calibbiasfunction ad4851_set_calibbiasfunction ad4851_set_scalefunction ad4851_get_scalefunction ad4851_read_rawfunction ad4851_write_rawfunction ad4851_update_scan_modefunction ad4851_read_availfunction ad4851_get_current_scan_typefunction BITfunction device_for_each_child_node_scopedfunction ad4857_parse_channelsfunction ad4858_parse_channelsfunction device_for_each_child_node_scopedfunction ad4851_probe
Annotated Snippet
struct ad4851_scale {
unsigned int scale_val;
u8 reg_val;
};
static const struct ad4851_scale ad4851_scale_table_unipolar[] = {
{ 2500, 0x0 },
{ 5000, 0x2 },
{ 6250, 0x4 },
{ 10000, 0x6 },
{ 12500, 0x8 },
{ 20000, 0xA },
{ 25000, 0xC },
{ 40000, 0xE },
};
static const struct ad4851_scale ad4851_scale_table_bipolar[] = {
{ 5000, 0x1 },
{ 10000, 0x3 },
{ 12500, 0x5 },
{ 20000, 0x7 },
{ 25000, 0x9 },
{ 40000, 0xB },
{ 50000, 0xD },
{ 80000, 0xF },
};
static const unsigned int ad4851_scale_avail_unipolar[] = {
2500,
5000,
6250,
10000,
12500,
20000,
25000,
40000,
};
static const unsigned int ad4851_scale_avail_bipolar[] = {
5000,
10000,
12500,
20000,
25000,
40000,
50000,
80000,
};
struct ad4851_chip_info {
const char *name;
unsigned int product_id;
int num_scales;
unsigned long max_sample_rate_hz;
unsigned int resolution;
unsigned int max_channels;
int (*parse_channels)(struct iio_dev *indio_dev);
};
enum {
AD4851_SCAN_TYPE_NORMAL,
AD4851_SCAN_TYPE_RESOLUTION_BOOST,
};
struct ad4851_state {
struct spi_device *spi;
struct pwm_device *cnv;
struct iio_backend *back;
/*
* Synchronize access to members the of driver state, and ensure
* atomicity of consecutive regmap operations.
*/
struct mutex lock;
struct regmap *regmap;
const struct ad4851_chip_info *info;
struct gpio_desc *pd_gpio;
bool resolution_boost_enabled;
unsigned long cnv_trigger_rate_hz;
unsigned int osr;
bool vrefbuf_en;
bool vrefio_en;
bool bipolar_ch[AD4851_MAX_CH_NR];
unsigned int scales_unipolar[AD4841_MAX_SCALE_AVAIL][2];
unsigned int scales_bipolar[AD4841_MAX_SCALE_AVAIL][2];
};
static int ad4851_reg_access(struct iio_dev *indio_dev,
unsigned int reg,
unsigned int writeval,
unsigned int *readval)
Annotation
- Immediate include surface: `linux/array_size.h`, `linux/bitfield.h`, `linux/bits.h`, `linux/delay.h`, `linux/device.h`, `linux/err.h`, `linux/minmax.h`, `linux/mod_devicetable.h`.
- Detected declarations: `struct ad4851_scale`, `struct ad4851_chip_info`, `struct ad4851_state`, `function ad4851_reg_access`, `function ad4851_set_sampling_freq`, `function ad4851_osr_to_regval`, `function __ad4851_get_scale`, `function ad4851_scale_fill`, `function ad4851_set_oversampling_ratio`, `function ad4851_get_oversampling_ratio`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
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.