linux/drivers/iio/light/ltr390.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * IIO driver for Lite-On LTR390 ALS and UV sensor
 * (7-bit I2C slave address 0x53)
 *
 * Based on the work of:
 *   Shreeya Patel and Shi Zhigang (LTRF216 Driver)
 *
 * Copyright (C) 2023 Anshul Dalal <[email protected]>
 *
 * Datasheet:
 *   https://optoelectronics.liteon.com/upload/download/DS86-2015-0004/LTR-390UV_Final_%20DS_V1%201.pdf
 *
 * TODO:
 *   - Support for configurable gain and resolution
 *   - Sensor suspend/resume support
 *   - Add support for reading the ALS
 *   - Interrupt support
 */

#include <linux/i2c.h>
#include <linux/math.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/regmap.h>
#include <linux/bitfield.h>

#include <linux/iio/iio.h>

#include <linux/unaligned.h>

#define LTR390_MAIN_CTRL
#define LTR390_ALS_UVS_MEAS_RATE
#define LTR390_ALS_UVS_GAIN
#define LTR390_PART_ID
#define LTR390_ALS_DATA
#define LTR390_UVS_DATA
#define LTR390_INT_CFG

#define LTR390_PART_NUMBER_ID
#define LTR390_ALS_UVS_GAIN_MASK
#define LTR390_ALS_UVS_INT_TIME_MASK
#define LTR390_ALS_UVS_INT_TIME(x)

#define LTR390_SW_RESET
#define LTR390_UVS_MODE
#define LTR390_SENSOR_ENABLE

#define LTR390_FRACTIONAL_PRECISION

/*
 * At 20-bit resolution (integration time: 400ms) and 18x gain, 2300 counts of
 * the sensor are equal to 1 UV Index [Datasheet Page#8].
 *
 * For the default resolution of 18-bit (integration time: 100ms) and default
 * gain of 3x, the counts/uvi are calculated as follows:
 * 2300 / ((3/18) * (100/400)) = 95.83
 */
#define LTR390_COUNTS_PER_UVI

/*
 * 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 LTR390_WINDOW_FACTOR

enum ltr390_mode {};

struct ltr390_data {};

static const struct regmap_config ltr390_regmap_config =;

static int ltr390_register_read(struct ltr390_data *data, u8 register_address)
{}

static int ltr390_set_mode(struct ltr390_data *data, enum ltr390_mode mode)
{}

static int ltr390_counts_per_uvi(struct ltr390_data *data)
{}

static int ltr390_read_raw(struct iio_dev *iio_device,
			   struct iio_chan_spec const *chan, int *val,
			   int *val2, long mask)
{}

/* integration time in us */
static const int ltr390_int_time_map_us[] =;
static const int ltr390_gain_map[] =;

static const struct iio_chan_spec ltr390_channels[] =;

static int ltr390_set_gain(struct ltr390_data *data, int val)
{}

static int ltr390_set_int_time(struct ltr390_data *data, int val)
{}

static int ltr390_read_avail(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
				const int **vals, int *type, int *length, long mask)
{}

static int ltr390_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
				int val, int val2, long mask)
{}

static const struct iio_info ltr390_info =;

static int ltr390_probe(struct i2c_client *client)
{}

static const struct i2c_device_id ltr390_id[] =;
MODULE_DEVICE_TABLE(i2c, ltr390_id);

static const struct of_device_id ltr390_of_table[] =;
MODULE_DEVICE_TABLE(of, ltr390_of_table);

static struct i2c_driver ltr390_driver =;
module_i2c_driver();

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();