drivers/iio/cdc/ad7150.c

Source file repositories/reference/linux-study-clean/drivers/iio/cdc/ad7150.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/cdc/ad7150.c
Extension
.c
Size
17856 bytes
Lines
658
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 ad7150_chip_info {
	struct i2c_client *client;
	u16 threshold[2][2];
	u8 thresh_sensitivity[2][2];
	u8 thresh_timeout[2][2];
	struct mutex state_lock;
	int interrupts[2];
	bool int_enabled[2];
	enum iio_event_type type;
	enum iio_event_direction dir;
};

static const u8 ad7150_addresses[][6] = {
	{ AD7150_CH1_DATA_HIGH_REG, AD7150_CH1_AVG_HIGH_REG,
	  AD7150_CH1_SETUP_REG, AD7150_CH1_THR_HOLD_H_REG,
	  AD7150_CH1_SENSITIVITY_REG, AD7150_CH1_TIMEOUT_REG },
	{ AD7150_CH2_DATA_HIGH_REG, AD7150_CH2_AVG_HIGH_REG,
	  AD7150_CH2_SETUP_REG, AD7150_CH2_THR_HOLD_H_REG,
	  AD7150_CH2_SENSITIVITY_REG, AD7150_CH2_TIMEOUT_REG },
};

static int ad7150_read_raw(struct iio_dev *indio_dev,
			   struct iio_chan_spec const *chan,
			   int *val,
			   int *val2,
			   long mask)
{
	struct ad7150_chip_info *chip = iio_priv(indio_dev);
	int channel = chan->channel;
	int ret;

	switch (mask) {
	case IIO_CHAN_INFO_RAW:
		ret = i2c_smbus_read_word_swapped(chip->client,
						  ad7150_addresses[channel][0]);
		if (ret < 0)
			return ret;
		*val = ret >> 4;

		return IIO_VAL_INT;
	case IIO_CHAN_INFO_AVERAGE_RAW:
		ret = i2c_smbus_read_word_swapped(chip->client,
						  ad7150_addresses[channel][1]);
		if (ret < 0)
			return ret;
		*val = ret;

		return IIO_VAL_INT;
	case IIO_CHAN_INFO_SCALE:
		/*
		 * Base units for capacitance are nano farads and the value
		 * calculated from the datasheet formula is in picofarad
		 * so multiply by 1000
		 */
		*val = 1000;
		*val2 = 40944 >> 4; /* To match shift in _RAW */
		return IIO_VAL_FRACTIONAL;
	case IIO_CHAN_INFO_OFFSET:
		*val = -(12288 >> 4); /* To match shift in _RAW */
		return IIO_VAL_INT;
	case IIO_CHAN_INFO_SAMP_FREQ:
		/* Strangely same for both 1 and 2 chan parts */
		*val = 100;
		return IIO_VAL_INT;
	default:
		return -EINVAL;
	}
}

static int ad7150_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 ad7150_chip_info *chip = iio_priv(indio_dev);
	u8 threshtype;
	bool thrfixed;
	int ret;

	ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG_REG);
	if (ret < 0)
		return ret;

	threshtype = FIELD_GET(AD7150_CFG_THRESHTYPE_MSK, ret);

	/*check if threshold mode is fixed or adaptive*/
	thrfixed = FIELD_GET(AD7150_CFG_FIX, ret);

	switch (type) {
	case IIO_EV_TYPE_THRESH_ADAPTIVE:

Annotation

Implementation Notes