drivers/iio/dac/ad5764.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/dac/ad5764.c
Extension
.c
Size
8685 bytes
Lines
366
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 ad5764_chip_info {
	unsigned long int_vref;
	const struct iio_chan_spec *channels;
};

/**
 * struct ad5764_state - driver instance specific data
 * @spi:		spi_device
 * @chip_info:		chip info
 * @vref_reg:		vref supply regulators
 * @lock:		lock to protect the data buffer during SPI ops
 * @data:		spi transfer buffers
 */

struct ad5764_state {
	struct spi_device		*spi;
	const struct ad5764_chip_info	*chip_info;
	struct regulator_bulk_data	vref_reg[2];
	struct mutex			lock;

	/*
	 * DMA (thus cache coherency maintenance) may require the
	 * transfer buffers to live in their own cache lines.
	 */
	union {
		__be32 d32;
		u8 d8[4];
	} data[2] __aligned(IIO_DMA_MINALIGN);
};

enum ad5764_type {
	ID_AD5744,
	ID_AD5744R,
	ID_AD5764,
	ID_AD5764R,
};

#define AD5764_CHANNEL(_chan, _bits) {				\
	.type = IIO_VOLTAGE,					\
	.indexed = 1,						\
	.output = 1,						\
	.channel = (_chan),					\
	.address = (_chan),					\
	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |		\
		BIT(IIO_CHAN_INFO_SCALE) |			\
		BIT(IIO_CHAN_INFO_CALIBSCALE) |			\
		BIT(IIO_CHAN_INFO_CALIBBIAS),			\
	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET),	\
	.scan_type = {						\
		.sign = 'u',					\
		.realbits = (_bits),				\
		.storagebits = 16,				\
		.shift = 16 - (_bits),				\
	},							\
}

#define DECLARE_AD5764_CHANNELS(_name, _bits) \
const struct iio_chan_spec _name##_channels[] = { \
	AD5764_CHANNEL(0, (_bits)), \
	AD5764_CHANNEL(1, (_bits)), \
	AD5764_CHANNEL(2, (_bits)), \
	AD5764_CHANNEL(3, (_bits)), \
};

static DECLARE_AD5764_CHANNELS(ad5764, 16);
static DECLARE_AD5764_CHANNELS(ad5744, 14);

static const struct ad5764_chip_info ad5764_chip_infos[] = {
	[ID_AD5744] = {
		.int_vref = 0,
		.channels = ad5744_channels,
	},
	[ID_AD5744R] = {
		.int_vref = 5000000,
		.channels = ad5744_channels,
	},
	[ID_AD5764] = {
		.int_vref = 0,
		.channels = ad5764_channels,
	},
	[ID_AD5764R] = {
		.int_vref = 5000000,
		.channels = ad5764_channels,
	},
};

static int ad5764_write(struct iio_dev *indio_dev, unsigned int reg,
	unsigned int val)
{
	struct ad5764_state *st = iio_priv(indio_dev);

Annotation

Implementation Notes