linux/drivers/iio/light/tsl2583.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Device driver for monitoring ambient light intensity (lux)
 * within the TAOS tsl258x family of devices (tsl2580, tsl2581, tsl2583).
 *
 * Copyright (c) 2011, TAOS Corporation.
 * Copyright (c) 2016-2017 Brian Masney <[email protected]>
 */

#include <linux/kernel.h>
#include <linux/i2c.h>
#include <linux/errno.h>
#include <linux/delay.h>
#include <linux/string.h>
#include <linux/mutex.h>
#include <linux/unistd.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/pm_runtime.h>

/* Device Registers and Masks */
#define TSL2583_CNTRL
#define TSL2583_ALS_TIME
#define TSL2583_INTERRUPT
#define TSL2583_GAIN
#define TSL2583_REVID
#define TSL2583_CHIPID
#define TSL2583_ALS_CHAN0LO
#define TSL2583_ALS_CHAN0HI
#define TSL2583_ALS_CHAN1LO
#define TSL2583_ALS_CHAN1HI
#define TSL2583_TMR_LO
#define TSL2583_TMR_HI

/* tsl2583 cmd reg masks */
#define TSL2583_CMD_REG
#define TSL2583_CMD_SPL_FN
#define TSL2583_CMD_ALS_INT_CLR

/* tsl2583 cntrl reg masks */
#define TSL2583_CNTL_ADC_ENBL
#define TSL2583_CNTL_PWR_OFF
#define TSL2583_CNTL_PWR_ON

/* tsl2583 status reg masks */
#define TSL2583_STA_ADC_VALID
#define TSL2583_STA_ADC_INTR

/* Lux calculation constants */
#define TSL2583_LUX_CALC_OVER_FLOW

#define TSL2583_INTERRUPT_DISABLED

#define TSL2583_CHIP_ID
#define TSL2583_CHIP_ID_MASK

#define TSL2583_POWER_OFF_DELAY_MS

/* Per-device data */
struct tsl2583_als_info {};

struct tsl2583_lux {};

static const struct tsl2583_lux tsl2583_default_lux[] =;

#define TSL2583_MAX_LUX_TABLE_ENTRIES

struct tsl2583_settings {};

struct tsl2583_chip {};

struct gainadj {};

/* Index = (0 - 3) Used to validate the gain selection index */
static const struct gainadj gainadj[] =;

/*
 * Provides initial operational parameter defaults.
 * These defaults may be changed through the device's sysfs files.
 */
static void tsl2583_defaults(struct tsl2583_chip *chip)
{}

/*
 * Reads and calculates current lux value.
 * The raw ch0 and ch1 values of the ambient light sensed in the last
 * integration cycle are read from the device.
 * Time scale factor array values are adjusted based on the integration time.
 * The raw values are multiplied by a scale factor, and device gain is obtained
 * using gain index. Limit checks are done next, then the ratio of a multiple
 * of ch1 value, to the ch0 value, is calculated. The array als_device_lux[]
 * declared above is then scanned to find the first ratio value that is just
 * above the ratio we just calculated. The ch0 and ch1 multiplier constants in
 * the array are then used along with the time scale factor array values, to
 * calculate the lux.
 */
static int tsl2583_get_lux(struct iio_dev *indio_dev)
{}

/*
 * Obtain single reading and calculate the als_gain_trim (later used
 * to derive actual lux).
 * Return updated gain_trim value.
 */
static int tsl2583_als_calibrate(struct iio_dev *indio_dev)
{}

static int tsl2583_set_als_time(struct tsl2583_chip *chip)
{}

static int tsl2583_set_als_gain(struct tsl2583_chip *chip)
{}

static int tsl2583_set_power_state(struct tsl2583_chip *chip, u8 state)
{}

/*
 * Turn the device on.
 * Configuration must be set before calling this function.
 */
static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
{}

/* Sysfs Interface Functions */

static ssize_t in_illuminance_input_target_show(struct device *dev,
						struct device_attribute *attr,
						char *buf)
{}

static ssize_t in_illuminance_input_target_store(struct device *dev,
						 struct device_attribute *attr,
						 const char *buf, size_t len)
{}

static ssize_t in_illuminance_calibrate_store(struct device *dev,
					      struct device_attribute *attr,
					      const char *buf, size_t len)
{}

static ssize_t in_illuminance_lux_table_show(struct device *dev,
					     struct device_attribute *attr,
					     char *buf)
{}

static ssize_t in_illuminance_lux_table_store(struct device *dev,
					      struct device_attribute *attr,
					      const char *buf, size_t len)
{}

static IIO_CONST_ATTR(in_illuminance_calibscale_available, "1 8 16 111");
static IIO_CONST_ATTR(in_illuminance_integration_time_available,
		      "0.050 0.100 0.150 0.200 0.250 0.300 0.350 0.400 0.450 0.500 0.550 0.600 0.650");
static IIO_DEVICE_ATTR_RW(in_illuminance_input_target, 0);
static IIO_DEVICE_ATTR_WO(in_illuminance_calibrate, 0);
static IIO_DEVICE_ATTR_RW(in_illuminance_lux_table, 0);

static struct attribute *sysfs_attrs_ctrl[] =;

static const struct attribute_group tsl2583_attribute_group =;

static const struct iio_chan_spec tsl2583_channels[] =;

static int tsl2583_set_pm_runtime_busy(struct tsl2583_chip *chip, bool on)
{}

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

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

static const struct iio_info tsl2583_info =;

static int tsl2583_probe(struct i2c_client *clientp)
{}

static void tsl2583_remove(struct i2c_client *client)
{}

static int tsl2583_suspend(struct device *dev)
{}

static int tsl2583_resume(struct device *dev)
{}

static DEFINE_RUNTIME_DEV_PM_OPS(tsl2583_pm_ops, tsl2583_suspend,
				 tsl2583_resume, NULL);

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

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

/* Driver definition */
static struct i2c_driver tsl2583_driver =;
module_i2c_driver();

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