drivers/iio/adc/ad7091r-base.c

Source file repositories/reference/linux-study-clean/drivers/iio/adc/ad7091r-base.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/adc/ad7091r-base.c
Extension
.c
Size
9542 bytes
Lines
398
Domain
Driver Families
Bucket
drivers/iio
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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

if (st->vref) {
			ret = regulator_get_voltage(st->vref);
			if (ret < 0)
				return ret;

			*val = ret / 1000;
		} else {
			*val = st->chip_info->vref_mV;
		}

		*val2 = chan->scan_type.realbits;
		return IIO_VAL_FRACTIONAL_LOG2;

	default:
		return -EINVAL;
	}
}

static int ad7091r_read_event_config(struct iio_dev *indio_dev,
				     const struct iio_chan_spec *chan,
				     enum iio_event_type type,
				     enum iio_event_direction dir)
{
	struct ad7091r_state *st = iio_priv(indio_dev);
	int val, ret;

	switch (dir) {
	case IIO_EV_DIR_RISING:
		ret = regmap_read(st->map,
				  AD7091R_REG_CH_HIGH_LIMIT(chan->channel),
				  &val);
		if (ret)
			return ret;
		return val != AD7091R_HIGH_LIMIT;
	case IIO_EV_DIR_FALLING:
		ret = regmap_read(st->map,
				  AD7091R_REG_CH_LOW_LIMIT(chan->channel),
				  &val);
		if (ret)
			return ret;
		return val != AD7091R_LOW_LIMIT;
	default:
		return -EINVAL;
	}
}

static int ad7091r_write_event_config(struct iio_dev *indio_dev,
				      const struct iio_chan_spec *chan,
				      enum iio_event_type type,
				      enum iio_event_direction dir,
				      bool state)
{
	struct ad7091r_state *st = iio_priv(indio_dev);

	if (state) {
		return regmap_set_bits(st->map, AD7091R_REG_CONF,
				       AD7091R_REG_CONF_ALERT_EN);
	} else {
		/*
		 * Set thresholds either to 0 or to 2^12 - 1 as appropriate to
		 * prevent alerts and thus disable event generation.
		 */
		switch (dir) {
		case IIO_EV_DIR_RISING:
			return regmap_write(st->map,
					    AD7091R_REG_CH_HIGH_LIMIT(chan->channel),
					    AD7091R_HIGH_LIMIT);
		case IIO_EV_DIR_FALLING:
			return regmap_write(st->map,
					    AD7091R_REG_CH_LOW_LIMIT(chan->channel),
					    AD7091R_LOW_LIMIT);
		default:
			return -EINVAL;
		}
	}
}

static int ad7091r_read_event_value(struct iio_dev *indio_dev,
				    const struct iio_chan_spec *chan,
				    enum iio_event_type type,
				    enum iio_event_direction dir,
				    enum iio_event_info info, int *val, int *val2)
{
	struct ad7091r_state *st = iio_priv(indio_dev);
	int ret;

	switch (info) {
	case IIO_EV_INFO_VALUE:
		switch (dir) {
		case IIO_EV_DIR_RISING:

Annotation

Implementation Notes