drivers/iio/dac/ad5766.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/dac/ad5766.c
Extension
.c
Size
17438 bytes
Lines
673
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 ad5766_chip_info {
	unsigned int			num_channels;
	const struct iio_chan_spec	*channels;
};

enum {
	AD5766_DITHER_ENABLE,
	AD5766_DITHER_INVERT,
	AD5766_DITHER_SOURCE,
};

/*
 * Dither signal can also be scaled.
 * Available dither scale strings corresponding to "dither_scale" field in
 * "struct ad5766_state".
 */
static const char * const ad5766_dither_scales[] = {
	"1",
	"0.75",
	"0.5",
	"0.25",
};

/**
 * struct ad5766_state - driver instance specific data
 * @spi:		SPI device
 * @lock:		Lock used to restrict concurrent access to SPI device
 * @chip_info:		Chip model specific constants
 * @gpio_reset:		Reset GPIO, used to reset the device
 * @crt_range:		Current selected output range
 * @dither_enable:	Power enable bit for each channel dither block (for
 *			example, D15 = DAC 15,D8 = DAC 8, and D0 = DAC 0)
 *			0 - Normal operation, 1 - Power down
 * @dither_invert:	Inverts the dither signal applied to the selected DAC
 *			outputs
 * @dither_source:	Selects between 2 possible sources:
 *			1: N0, 2: N1
 *			Two bits are used for each channel
 * @dither_scale:	Two bits are used for each of the 16 channels:
 *			0: 1 SCALING, 1: 0.75 SCALING, 2: 0.5 SCALING,
 *			3: 0.25 SCALING.
 * @data:		SPI transfer buffers
 */
struct ad5766_state {
	struct spi_device		*spi;
	struct mutex			lock;
	const struct ad5766_chip_info	*chip_info;
	struct gpio_desc		*gpio_reset;
	enum ad5766_voltage_range	crt_range;
	u16		dither_enable;
	u16		dither_invert;
	u32		dither_source;
	u32		dither_scale;
	union {
		u32	d32;
		u16	w16[2];
		u8	b8[4];
	} data[3] __aligned(IIO_DMA_MINALIGN);
};

struct ad5766_span_tbl {
	int		min;
	int		max;
};

static const struct ad5766_span_tbl ad5766_span_tbl[] = {
	[AD5766_VOLTAGE_RANGE_M20V_0V] =	{-20, 0},
	[AD5766_VOLTAGE_RANGE_M16V_to_0V] =	{-16, 0},
	[AD5766_VOLTAGE_RANGE_M10V_to_0V] =	{-10, 0},
	[AD5766_VOLTAGE_RANGE_M12V_to_14V] =	{-12, 14},
	[AD5766_VOLTAGE_RANGE_M16V_to_10V] =	{-16, 10},
	[AD5766_VOLTAGE_RANGE_M10V_to_6V] =	{-10, 6},
	[AD5766_VOLTAGE_RANGE_M5V_to_5V] =	{-5, 5},
	[AD5766_VOLTAGE_RANGE_M10V_to_10V] =	{-10, 10},
};

static int __ad5766_spi_read(struct ad5766_state *st, u8 dac, int *val)
{
	int ret;
	struct spi_transfer xfers[] = {
		{
			.tx_buf = &st->data[0].d32,
			.len = 3,
			.cs_change = 1,
		}, {
			.tx_buf = &st->data[1].d32,
			.rx_buf = &st->data[2].d32,
			.len = 3,
		},
	};

Annotation

Implementation Notes