drivers/iio/dac/ad5791.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/dac/ad5791.c
Extension
.c
Size
16728 bytes
Lines
612
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 ad5791_chip_info {
	const char *name;
	const struct iio_chan_spec channel;
	const struct iio_chan_spec channel_offload;
	int (*get_lin_comp)(unsigned int span);
};

/**
 * struct ad5791_state - driver instance specific data
 * @spi:			spi_device
 * @gpio_reset:		reset gpio
 * @gpio_clear:		clear gpio
 * @gpio_ldac:		load dac gpio
 * @chip_info:		chip model specific constants
 * @offload_msg:	spi message used for offload
 * @offload_xfer:	spi transfer used for offload
 * @offload:		offload device
 * @offload_trigger:	offload trigger
 * @offload_trigger_hz:	offload sample rate
 * @vref_mv:		actual reference voltage used
 * @vref_neg_mv:	voltage of the negative supply
 * @ctrl:		control register cache
 * @pwr_down_mode:	current power down mode
 * @pwr_down:		true if device is powered down
 * @data:		spi transfer buffers
 */
struct ad5791_state {
	struct spi_device		*spi;
	struct gpio_desc		*gpio_reset;
	struct gpio_desc		*gpio_clear;
	struct gpio_desc		*gpio_ldac;
	const struct ad5791_chip_info	*chip_info;
	struct spi_message		offload_msg;
	struct spi_transfer		offload_xfer;
	struct spi_offload		*offload;
	struct spi_offload_trigger	*offload_trigger;
	unsigned int			offload_trigger_hz;
	unsigned short			vref_mv;
	unsigned int			vref_neg_mv;
	unsigned			ctrl;
	unsigned			pwr_down_mode;
	bool				pwr_down;

	union {
		__be32 d32;
		u8 d8[4];
	} data[3] __aligned(IIO_DMA_MINALIGN);
};

static int ad5791_spi_write(struct ad5791_state *st, u8 addr, u32 val)
{
	st->data[0].d32 = cpu_to_be32(AD5791_CMD_WRITE |
			      AD5791_ADDR(addr) |
			      (val & AD5791_DAC_MASK));

	return spi_write(st->spi, &st->data[0].d8[1], 3);
}

static int ad5791_spi_read(struct ad5791_state *st, u8 addr, u32 *val)
{
	int ret;
	struct spi_transfer xfers[] = {
		{
			.tx_buf = &st->data[0].d8[1],
			.len = 3,
			.cs_change = 1,
		}, {
			.tx_buf = &st->data[1].d8[1],
			.rx_buf = &st->data[2].d8[1],
			.len = 3,
		},
	};

	st->data[0].d32 = cpu_to_be32(AD5791_CMD_READ |
			      AD5791_ADDR(addr));
	st->data[1].d32 = cpu_to_be32(AD5791_ADDR(AD5791_ADDR_NOOP));

	ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));

	*val = be32_to_cpu(st->data[2].d32);

	return ret;
}

static const char * const ad5791_powerdown_modes[] = {
	"6kohm_to_gnd",
	"three_state",
};

static int ad5791_get_powerdown_mode(struct iio_dev *indio_dev,

Annotation

Implementation Notes