drivers/iio/light/ltrf216a.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/light/ltrf216a.c
Extension
.c
Size
14481 bytes
Lines
584
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 ltr_chip_info {
	/* Chip contains CLEAR_DATA_0/1/2 registers at offset 0xa..0xc */
	bool		has_clear_data;
	/* Lux calculation multiplier for ALS data */
	int		lux_multiplier;
};

/*
 * Window Factor is needed when the device is under Window glass
 * with coated tinted ink. This is to compensate for the light loss
 * due to the lower transmission rate of the window glass and helps
 * in calculating lux.
 */
#define LTRF216A_WIN_FAC	1

struct ltrf216a_data {
	struct regmap *regmap;
	struct i2c_client *client;
	const struct ltr_chip_info *info;
	u32 int_time;
	u16 int_time_fac;
	u8 als_gain_fac;
	/*
	 * Protects regmap accesses and makes sure integration time
	 * remains constant during the measurement of lux.
	 */
	struct mutex lock;
};

static const struct iio_chan_spec ltrf216a_channels[] = {
	{
		.type = IIO_LIGHT,
		.info_mask_separate =
			BIT(IIO_CHAN_INFO_RAW) |
			BIT(IIO_CHAN_INFO_PROCESSED) |
			BIT(IIO_CHAN_INFO_INT_TIME),
		.info_mask_separate_available =
			BIT(IIO_CHAN_INFO_INT_TIME),
	},
};

static void ltrf216a_reset(struct iio_dev *indio_dev)
{
	struct ltrf216a_data *data = iio_priv(indio_dev);

	/* reset sensor, chip fails to respond to this, so ignore any errors */
	regmap_write(data->regmap, LTRF216A_MAIN_CTRL, LTRF216A_ALS_RESET_MASK);

	/* reset time */
	usleep_range(1000, 2000);
}

static int ltrf216a_enable(struct iio_dev *indio_dev)
{
	struct ltrf216a_data *data = iio_priv(indio_dev);
	struct device *dev = &data->client->dev;
	int ret;

	/* enable sensor */
	ret = regmap_set_bits(data->regmap,
			      LTRF216A_MAIN_CTRL, LTRF216A_ALS_ENABLE_MASK);
	if (ret) {
		dev_err(dev, "failed to enable sensor: %d\n", ret);
		return ret;
	}

	/* sleep for one integration cycle after enabling the device */
	msleep(ltrf216a_int_time_reg[0][0]);

	return 0;
}

static int ltrf216a_disable(struct iio_dev *indio_dev)
{
	struct ltrf216a_data *data = iio_priv(indio_dev);
	struct device *dev = &data->client->dev;
	int ret;

	ret = regmap_write(data->regmap, LTRF216A_MAIN_CTRL, 0);
	if (ret)
		dev_err(dev, "failed to disable sensor: %d\n", ret);

	return ret;
}

static void ltrf216a_cleanup(void *data)
{
	struct iio_dev *indio_dev = data;

	ltrf216a_disable(indio_dev);

Annotation

Implementation Notes