drivers/iio/dac/ti-dac082s085.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/dac/ti-dac082s085.c
Extension
.c
Size
9056 bytes
Lines
362
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 ti_dac_spec {
	u8 num_channels;
	u8 resolution;
};

static const struct ti_dac_spec ti_dac_spec[] = {
	[dual_8bit]  = { .num_channels = 2, .resolution = 8  },
	[dual_10bit] = { .num_channels = 2, .resolution = 10 },
	[dual_12bit] = { .num_channels = 2, .resolution = 12 },
	[quad_8bit]  = { .num_channels = 4, .resolution = 8  },
	[quad_10bit] = { .num_channels = 4, .resolution = 10 },
	[quad_12bit] = { .num_channels = 4, .resolution = 12 },
};

/**
 * struct ti_dac_chip - TI DAC chip
 * @lock: protects write sequences
 * @vref: regulator generating Vref
 * @mesg: SPI message to perform a write
 * @xfer: SPI transfer used by @mesg
 * @val: cached value of each output
 * @powerdown: whether the chip is powered down
 * @powerdown_mode: selected by the user
 * @resolution: resolution of the chip
 * @buf: buffer for @xfer
 */
struct ti_dac_chip {
	struct mutex lock;
	struct regulator *vref;
	struct spi_message mesg;
	struct spi_transfer xfer;
	u16 val[4];
	bool powerdown;
	u8 powerdown_mode;
	u8 resolution;
	u8 buf[2] __aligned(IIO_DMA_MINALIGN);
};

#define WRITE_NOT_UPDATE(chan)	(0x00 | (chan) << 6)
#define WRITE_AND_UPDATE(chan)	(0x10 | (chan) << 6)
#define WRITE_ALL_UPDATE	 0x20
#define POWERDOWN(mode) 	(0x30 | ((mode) + 1) << 6)

static int ti_dac_cmd(struct ti_dac_chip *ti_dac, u8 cmd, u16 val)
{
	u8 shift = 12 - ti_dac->resolution;

	ti_dac->buf[0] = cmd | (val >> (8 - shift));
	ti_dac->buf[1] = (val << shift) & 0xff;
	return spi_sync(ti_dac->mesg.spi, &ti_dac->mesg);
}

static const char * const ti_dac_powerdown_modes[] = {
	"2.5kohm_to_gnd", "100kohm_to_gnd", "three_state",
};

static int ti_dac_get_powerdown_mode(struct iio_dev *indio_dev,
				     const struct iio_chan_spec *chan)
{
	struct ti_dac_chip *ti_dac = iio_priv(indio_dev);

	return ti_dac->powerdown_mode;
}

static int ti_dac_set_powerdown_mode(struct iio_dev *indio_dev,
				     const struct iio_chan_spec *chan,
				     unsigned int mode)
{
	struct ti_dac_chip *ti_dac = iio_priv(indio_dev);
	int ret = 0;

	if (ti_dac->powerdown_mode == mode)
		return 0;

	mutex_lock(&ti_dac->lock);
	if (ti_dac->powerdown) {
		ret = ti_dac_cmd(ti_dac, POWERDOWN(mode), 0);
		if (ret)
			goto out;
	}
	ti_dac->powerdown_mode = mode;

out:
	mutex_unlock(&ti_dac->lock);
	return ret;
}

static const struct iio_enum ti_dac_powerdown_mode = {
	.items = ti_dac_powerdown_modes,
	.num_items = ARRAY_SIZE(ti_dac_powerdown_modes),

Annotation

Implementation Notes