drivers/iio/light/noa1305.c

Source file repositories/reference/linux-study-clean/drivers/iio/light/noa1305.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/light/noa1305.c
Extension
.c
Size
8647 bytes
Lines
338
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 noa1305_priv {
	struct i2c_client *client;
	struct regmap *regmap;
};

static int noa1305_measure(struct noa1305_priv *priv, int *val)
{
	__le16 data;
	int ret;

	ret = regmap_bulk_read(priv->regmap, NOA1305_REG_ALS_DATA_LSB, &data,
			       2);
	if (ret < 0)
		return ret;

	*val = le16_to_cpu(data);

	return IIO_VAL_INT;
}

static int noa1305_scale(struct noa1305_priv *priv, int *val, int *val2)
{
	int data;
	int ret;

	ret = regmap_read(priv->regmap, NOA1305_REG_INTEGRATION_TIME, &data);
	if (ret < 0)
		return ret;

	/*
	 * Lux = count / (<Integration Constant> * <Integration Time>)
	 *
	 * Integration Constant = 7.7
	 * Integration Time in Seconds
	 */
	data &= NOA1305_INTEGR_TIME_MASK;
	*val = noa1305_scale_available[2 * data + 0];
	*val2 = noa1305_scale_available[2 * data + 1];

	return IIO_VAL_FRACTIONAL;
}

static int noa1305_int_time(struct noa1305_priv *priv, int *val, int *val2)
{
	int data;
	int ret;

	ret = regmap_read(priv->regmap, NOA1305_REG_INTEGRATION_TIME, &data);
	if (ret < 0)
		return ret;

	data &= NOA1305_INTEGR_TIME_MASK;
	*val = noa1305_int_time_available[2 * data + 0];
	*val2 = noa1305_int_time_available[2 * data + 1];

	return IIO_VAL_INT_PLUS_MICRO;
}

static const struct iio_chan_spec noa1305_channels[] = {
	{
		.type = IIO_LIGHT,
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
		.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE),
		.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME),
		.info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME),
	}
};

static int noa1305_read_avail(struct iio_dev *indio_dev,
			      struct iio_chan_spec const *chan,
			      const int **vals, int *type,
			      int *length, long mask)
{
	if (chan->type != IIO_LIGHT)
		return -EINVAL;

	switch (mask) {
	case IIO_CHAN_INFO_SCALE:
		*vals = noa1305_scale_available;
		*length = ARRAY_SIZE(noa1305_scale_available);
		*type = IIO_VAL_FRACTIONAL;
		return IIO_AVAIL_LIST;
	case IIO_CHAN_INFO_INT_TIME:
		*vals = noa1305_int_time_available;
		*length = ARRAY_SIZE(noa1305_int_time_available);
		*type = IIO_VAL_INT_PLUS_MICRO;
		return IIO_AVAIL_LIST;
	default:
		return -EINVAL;

Annotation

Implementation Notes