drivers/iio/adc/ad7124.c

Source file repositories/reference/linux-study-clean/drivers/iio/adc/ad7124.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/adc/ad7124.c
Extension
.c
Size
46999 bytes
Lines
1707
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct ad7124_chip_info {
	const char *name;
	unsigned int chip_id;
	unsigned int num_inputs;
};

enum ad7124_filter_type {
	AD7124_FILTER_TYPE_SINC3,
	AD7124_FILTER_TYPE_SINC3_PF1,
	AD7124_FILTER_TYPE_SINC3_PF2,
	AD7124_FILTER_TYPE_SINC3_PF3,
	AD7124_FILTER_TYPE_SINC3_PF4,
	AD7124_FILTER_TYPE_SINC3_REJ60,
	AD7124_FILTER_TYPE_SINC3_SINC1,
	AD7124_FILTER_TYPE_SINC4,
	AD7124_FILTER_TYPE_SINC4_REJ60,
	AD7124_FILTER_TYPE_SINC4_SINC1,
};

struct ad7124_channel_config {
	unsigned int cfg_slot;
	unsigned int requested_odr;
	unsigned int requested_odr_micro;
	/*
	 * Following fields are used to compare for equality. If you
	 * make adaptations in it, you most likely also have to adapt
	 * ad7124_config_equal(), too.
	 */
	struct_group(config_props,
		enum ad7124_ref_sel refsel;
		bool bipolar;
		bool buf_positive;
		bool buf_negative;
		unsigned int vref_mv;
		unsigned int pga_bits;
		unsigned int odr_sel_bits;
		enum ad7124_filter_type filter_type;
		unsigned int calibration_offset;
		unsigned int calibration_gain;
	);
};

struct ad7124_channel {
	struct ad7124_channel_config cfg;
	unsigned int ain;
	unsigned int slot;
	u8 syscalib_mode;
};

struct ad7124_state {
	const struct ad7124_chip_info *chip_info;
	struct ad_sigma_delta sd;
	struct ad7124_channel *channels;
	struct regulator *vref[4];
	u32 clk_hz;
	unsigned int adc_control;
	unsigned int num_channels;
	struct mutex cfgs_lock; /* lock for configs access */
	u8 cfg_slot_use_count[AD7124_MAX_CONFIGS];

	/*
	 * Stores the power-on reset value for the GAIN(x) registers which are
	 * needed for measurements at gain 1 (i.e. CONFIG(x).PGA == 0)
	 */
	unsigned int gain_default;
	bool enable_single_cycle;
};

static const struct ad7124_chip_info ad7124_4_chip_info = {
	.name = "ad7124-4",
	.chip_id = AD7124_ID_DEVICE_ID_AD7124_4,
	.num_inputs = 8,
};

static const struct ad7124_chip_info ad7124_8_chip_info = {
	.name = "ad7124-8",
	.chip_id = AD7124_ID_DEVICE_ID_AD7124_8,
	.num_inputs = 16,
};

static int ad7124_find_closest_match(const int *array,
				     unsigned int size, int val)
{
	int i, idx;
	unsigned int diff_new, diff_old;

	diff_old = U32_MAX;
	idx = 0;

	for (i = 0; i < size; i++) {

Annotation

Implementation Notes