drivers/iio/adc/nct7201.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/adc/nct7201.c
Extension
.c
Size
14326 bytes
Lines
502
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 nct7201_chip_info {
	struct regmap *regmap;
	struct regmap *regmap16;
	int num_vin_channels;
	__le16 vin_mask;
};

struct nct7201_adc_model_data {
	const char *model_name;
	const struct iio_chan_spec *channels;
	unsigned int num_channels;
	int num_vin_channels;
};

static const struct iio_event_spec nct7201_events[] = {
	{
		.type = IIO_EV_TYPE_THRESH,
		.dir = IIO_EV_DIR_RISING,
		.mask_separate = BIT(IIO_EV_INFO_VALUE) |
				 BIT(IIO_EV_INFO_ENABLE),
	}, {
		.type = IIO_EV_TYPE_THRESH,
		.dir = IIO_EV_DIR_FALLING,
		.mask_separate = BIT(IIO_EV_INFO_VALUE) |
				 BIT(IIO_EV_INFO_ENABLE),
	},
};

#define NCT7201_VOLTAGE_CHANNEL(num)					\
	{								\
		.type = IIO_VOLTAGE,					\
		.indexed = 1,						\
		.channel = num + 1,					\
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),		\
		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),	\
		.address = num,						\
		.event_spec = nct7201_events,				\
		.num_event_specs = ARRAY_SIZE(nct7201_events),		\
	}

static const struct iio_chan_spec nct7201_channels[] = {
	NCT7201_VOLTAGE_CHANNEL(0),
	NCT7201_VOLTAGE_CHANNEL(1),
	NCT7201_VOLTAGE_CHANNEL(2),
	NCT7201_VOLTAGE_CHANNEL(3),
	NCT7201_VOLTAGE_CHANNEL(4),
	NCT7201_VOLTAGE_CHANNEL(5),
	NCT7201_VOLTAGE_CHANNEL(6),
	NCT7201_VOLTAGE_CHANNEL(7),
};

static const struct iio_chan_spec nct7202_channels[] = {
	NCT7201_VOLTAGE_CHANNEL(0),
	NCT7201_VOLTAGE_CHANNEL(1),
	NCT7201_VOLTAGE_CHANNEL(2),
	NCT7201_VOLTAGE_CHANNEL(3),
	NCT7201_VOLTAGE_CHANNEL(4),
	NCT7201_VOLTAGE_CHANNEL(5),
	NCT7201_VOLTAGE_CHANNEL(6),
	NCT7201_VOLTAGE_CHANNEL(7),
	NCT7201_VOLTAGE_CHANNEL(8),
	NCT7201_VOLTAGE_CHANNEL(9),
	NCT7201_VOLTAGE_CHANNEL(10),
	NCT7201_VOLTAGE_CHANNEL(11),
};

static int nct7201_read_raw(struct iio_dev *indio_dev,
			    struct iio_chan_spec const *chan,
			    int *val, int *val2, long mask)
{
	struct nct7201_chip_info *chip = iio_priv(indio_dev);
	unsigned int value;
	int err;

	if (chan->type != IIO_VOLTAGE)
		return -EOPNOTSUPP;

	switch (mask) {
	case IIO_CHAN_INFO_RAW:
		err = regmap_read(chip->regmap16, NCT7201_REG_VIN(chan->address), &value);
		if (err)
			return err;
		*val = FIELD_GET(NCT7201_REG_VIN_MASK, value);
		return IIO_VAL_INT;
	case IIO_CHAN_INFO_SCALE:
		/* From the datasheet, we have to multiply by 0.0004995 */
		*val = 0;
		*val2 = 499500;
		return IIO_VAL_INT_PLUS_NANO;
	default:

Annotation

Implementation Notes