drivers/iio/dac/ad5770r.c

Source file repositories/reference/linux-study-clean/drivers/iio/dac/ad5770r.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/dac/ad5770r.c
Extension
.c
Size
16909 bytes
Lines
664
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 ad5770r_out_range {
	u8	out_scale;
	u8	out_range_mode;
};

/**
 * struct ad5770r_state - driver instance specific data
 * @spi:		spi_device
 * @regmap:		regmap
 * @gpio_reset:		gpio descriptor
 * @output_mode:	array contains channels output ranges
 * @vref:		reference value
 * @ch_pwr_down:	powerdown flags
 * @internal_ref:	internal reference flag
 * @external_res:	external 2.5k resistor flag
 * @transf_buf:		cache aligned buffer for spi read/write
 */
struct ad5770r_state {
	struct spi_device		*spi;
	struct regmap			*regmap;
	struct gpio_desc		*gpio_reset;
	struct ad5770r_out_range	output_mode[AD5770R_MAX_CHANNELS];
	int				vref;
	bool				ch_pwr_down[AD5770R_MAX_CHANNELS];
	bool				internal_ref;
	bool				external_res;
	u8				transf_buf[2] __aligned(IIO_DMA_MINALIGN);
};

static const struct regmap_config ad5770r_spi_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
	.read_flag_mask = BIT(7),
};

struct ad5770r_output_modes {
	unsigned int ch;
	u8 mode;
	int min;
	int max;
};

static const struct ad5770r_output_modes ad5770r_rng_tbl[] = {
	{ 0, AD5770R_CH0_0_300, 0, 300 },
	{ 0, AD5770R_CH0_NEG_60_0, -60, 0 },
	{ 0, AD5770R_CH0_NEG_60_300, -60, 300 },
	{ 1, AD5770R_CH1_0_140_LOW_HEAD, 0, 140 },
	{ 1, AD5770R_CH1_0_140_LOW_NOISE, 0, 140 },
	{ 1, AD5770R_CH1_0_250, 0, 250 },
	{ 2, AD5770R_CH_LOW_RANGE, 0, 55 },
	{ 2, AD5770R_CH_HIGH_RANGE, 0, 150 },
	{ 3, AD5770R_CH_LOW_RANGE, 0, 45 },
	{ 3, AD5770R_CH_HIGH_RANGE, 0, 100 },
	{ 4, AD5770R_CH_LOW_RANGE, 0, 45 },
	{ 4, AD5770R_CH_HIGH_RANGE, 0, 100 },
	{ 5, AD5770R_CH_LOW_RANGE, 0, 45 },
	{ 5, AD5770R_CH_HIGH_RANGE, 0, 100 },
};

static const unsigned int ad5770r_filter_freqs[] = {
	153, 357, 715, 1400, 2800, 262000,
};

static const unsigned int ad5770r_filter_reg_vals[] = {
	AD5770R_FILTER_104_KOHM,
	AD5770R_FILTER_44_4_KOHM,
	AD5770R_FILTER_22_2_KOHM,
	AD5770R_FILTER_11_2_KOHM,
	AD5770R_FILTER_5_6_KOHM,
	AD5770R_FILTER_60_OHM
};

static int ad5770r_set_output_mode(struct ad5770r_state *st,
				   const struct ad5770r_out_range *out_mode,
				   int channel)
{
	unsigned int regval;

	regval = AD5770R_RANGE_OUTPUT_SCALING(out_mode->out_scale) |
		 AD5770R_RANGE_MODE(out_mode->out_range_mode);

	return regmap_write(st->regmap,
			    AD5770R_OUTPUT_RANGE(channel), regval);
}

static int ad5770r_set_reference(struct ad5770r_state *st)
{
	unsigned int regval;

	regval = AD5770R_REF_RESISTOR_SEL(st->external_res);

Annotation

Implementation Notes