drivers/iio/dac/max5821.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/dac/max5821.c
Extension
.c
Size
8640 bytes
Lines
367
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 max5821_data {
	struct i2c_client	*client;
	unsigned short		vref_mv;
	bool			powerdown[MAX5821_MAX_DAC_CHANNELS];
	u8			powerdown_mode[MAX5821_MAX_DAC_CHANNELS];
	struct mutex		lock;
};

static const char * const max5821_powerdown_modes[] = {
	"three_state",
	"1kohm_to_gnd",
	"100kohm_to_gnd",
};

enum {
	MAX5821_THREE_STATE,
	MAX5821_1KOHM_TO_GND,
	MAX5821_100KOHM_TO_GND
};

static int max5821_get_powerdown_mode(struct iio_dev *indio_dev,
				      const struct iio_chan_spec *chan)
{
	struct max5821_data *st = iio_priv(indio_dev);

	return st->powerdown_mode[chan->channel];
}

static int max5821_set_powerdown_mode(struct iio_dev *indio_dev,
				      const struct iio_chan_spec *chan,
				      unsigned int mode)
{
	struct max5821_data *st = iio_priv(indio_dev);

	st->powerdown_mode[chan->channel] = mode;

	return 0;
}

static const struct iio_enum max5821_powerdown_mode_enum = {
	.items = max5821_powerdown_modes,
	.num_items = ARRAY_SIZE(max5821_powerdown_modes),
	.get = max5821_get_powerdown_mode,
	.set = max5821_set_powerdown_mode,
};

static ssize_t max5821_read_dac_powerdown(struct iio_dev *indio_dev,
					  uintptr_t private,
					  const struct iio_chan_spec *chan,
					  char *buf)
{
	struct max5821_data *st = iio_priv(indio_dev);

	return sysfs_emit(buf, "%d\n", st->powerdown[chan->channel]);
}

static int max5821_sync_powerdown_mode(struct max5821_data *data,
				       const struct iio_chan_spec *chan)
{
	u8 outbuf[2];
	int ret;

	outbuf[0] = MAX5821_EXTENDED_COMMAND_MODE;

	if (chan->channel == 0)
		outbuf[1] = MAX5821_EXTENDED_DAC_A;
	else
		outbuf[1] = MAX5821_EXTENDED_DAC_B;

	if (data->powerdown[chan->channel])
		outbuf[1] |= data->powerdown_mode[chan->channel] + 1;
	else
		outbuf[1] |= MAX5821_EXTENDED_POWER_UP;

	ret = i2c_master_send(data->client, outbuf, sizeof(outbuf));
	if (ret < 0)
		return ret;
	if (ret != sizeof(outbuf))
		return -EIO;

	return 0;
}

static ssize_t max5821_write_dac_powerdown(struct iio_dev *indio_dev,
					   uintptr_t private,
					   const struct iio_chan_spec *chan,
					   const char *buf, size_t len)
{
	struct max5821_data *data = iio_priv(indio_dev);
	bool powerdown;

Annotation

Implementation Notes