linux/drivers/iio/light/tsl2772.c

// SPDX-License-Identifier: GPL-2.0+
/*
 * Device driver for monitoring ambient light intensity in (lux) and proximity
 * detection (prox) within the TAOS TSL2571, TSL2671, TMD2671, TSL2771, TMD2771,
 * TSL2572, TSL2672, TMD2672, TSL2772, and TMD2772 devices.
 *
 * Copyright (c) 2012, TAOS Corporation.
 * Copyright (c) 2017-2018 Brian Masney <[email protected]>
 */

#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/property.h>
#include <linux/slab.h>

#include <linux/iio/events.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/platform_data/tsl2772.h>
#include <linux/regulator/consumer.h>

/* Cal defs */
#define PROX_STAT_CAL
#define PROX_STAT_SAMP
#define MAX_SAMPLES_CAL

/* TSL2772 Device ID */
#define TRITON_ID
#define SWORDFISH_ID
#define HALIBUT_ID

/* Lux calculation constants */
#define TSL2772_LUX_CALC_OVER_FLOW

/*
 * TAOS Register definitions - Note: depending on device, some of these register
 * are not used and the register address is benign.
 */

/* Register offsets */
#define TSL2772_MAX_CONFIG_REG

/* Device Registers and Masks */
#define TSL2772_CNTRL
#define TSL2772_ALS_TIME
#define TSL2772_PRX_TIME
#define TSL2772_WAIT_TIME
#define TSL2772_ALS_MINTHRESHLO
#define TSL2772_ALS_MINTHRESHHI
#define TSL2772_ALS_MAXTHRESHLO
#define TSL2772_ALS_MAXTHRESHHI
#define TSL2772_PRX_MINTHRESHLO
#define TSL2772_PRX_MINTHRESHHI
#define TSL2772_PRX_MAXTHRESHLO
#define TSL2772_PRX_MAXTHRESHHI
#define TSL2772_PERSISTENCE
#define TSL2772_ALS_PRX_CONFIG
#define TSL2772_PRX_COUNT
#define TSL2772_GAIN
#define TSL2772_NOTUSED
#define TSL2772_REVID
#define TSL2772_CHIPID
#define TSL2772_STATUS
#define TSL2772_ALS_CHAN0LO
#define TSL2772_ALS_CHAN0HI
#define TSL2772_ALS_CHAN1LO
#define TSL2772_ALS_CHAN1HI
#define TSL2772_PRX_LO
#define TSL2772_PRX_HI

/* tsl2772 cmd reg masks */
#define TSL2772_CMD_REG
#define TSL2772_CMD_SPL_FN
#define TSL2772_CMD_REPEAT_PROTO
#define TSL2772_CMD_AUTOINC_PROTO

#define TSL2772_CMD_PROX_INT_CLR
#define TSL2772_CMD_ALS_INT_CLR
#define TSL2772_CMD_PROXALS_INT_CLR

/* tsl2772 cntrl reg masks */
#define TSL2772_CNTL_ADC_ENBL
#define TSL2772_CNTL_PWR_ON

/* tsl2772 status reg masks */
#define TSL2772_STA_ADC_VALID
#define TSL2772_STA_PRX_VALID
#define TSL2772_STA_ADC_PRX_VALID
#define TSL2772_STA_ALS_INTR
#define TSL2772_STA_PRX_INTR

/* tsl2772 cntrl reg masks */
#define TSL2772_CNTL_REG_CLEAR
#define TSL2772_CNTL_PROX_INT_ENBL
#define TSL2772_CNTL_ALS_INT_ENBL
#define TSL2772_CNTL_WAIT_TMR_ENBL
#define TSL2772_CNTL_PROX_DET_ENBL
#define TSL2772_CNTL_PWRON
#define TSL2772_CNTL_ALSPON_ENBL
#define TSL2772_CNTL_INTALSPON_ENBL
#define TSL2772_CNTL_PROXPON_ENBL
#define TSL2772_CNTL_INTPROXPON_ENBL

#define TSL2772_ALS_GAIN_TRIM_MIN
#define TSL2772_ALS_GAIN_TRIM_MAX

#define TSL2772_MAX_PROX_LEDS

#define TSL2772_BOOT_MIN_SLEEP_TIME
#define TSL2772_BOOT_MAX_SLEEP_TIME

/* Device family members */
enum {};

enum {};

enum {};

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

struct tsl2772_chip_info {};

static const int tsl2772_led_currents[][2] =;

struct tsl2772_chip {};

/*
 * Different devices require different coefficents, and these numbers were
 * derived from the 'Lux Equation' section of the various device datasheets.
 * All of these coefficients assume a Glass Attenuation (GA) factor of 1.
 * The coefficients are multiplied by 1000 to avoid floating point operations.
 * The two rows in each table correspond to the Lux1 and Lux2 equations from
 * the datasheets.
 */
static const struct tsl2772_lux tsl2x71_lux_table[TSL2772_DEF_LUX_TABLE_SZ] =;

static const struct tsl2772_lux tmd2x71_lux_table[TSL2772_DEF_LUX_TABLE_SZ] =;

static const struct tsl2772_lux tsl2x72_lux_table[TSL2772_DEF_LUX_TABLE_SZ] =;

static const struct tsl2772_lux tmd2x72_lux_table[TSL2772_DEF_LUX_TABLE_SZ] =;

static const struct tsl2772_lux apds9930_lux_table[TSL2772_DEF_LUX_TABLE_SZ] =;

static const struct tsl2772_lux *tsl2772_default_lux_table_group[] =;

static const struct tsl2772_settings tsl2772_default_settings =;

static const s16 tsl2772_als_gain[] =;

static const s16 tsl2772_prox_gain[] =;

static const int tsl2772_int_time_avail[][6] =;

static int tsl2772_int_calibscale_avail[] =;

static int tsl2772_prox_calibscale_avail[] =;

/* Channel variations */
enum {};

static const u8 device_channel_config[] =;

static int tsl2772_read_status(struct tsl2772_chip *chip)
{}

static int tsl2772_write_control_reg(struct tsl2772_chip *chip, u8 data)
{}

static int tsl2772_read_autoinc_regs(struct tsl2772_chip *chip, int lower_reg,
				     int upper_reg)
{}

/**
 * tsl2772_get_lux() - Reads and calculates current lux value.
 * @indio_dev:	pointer to IIO device
 *
 * The raw ch0 and ch1 values of the ambient light sensed in the last
 * integration cycle are read from the device. The raw values are multiplied
 * by a device-specific scale factor, and divided by the integration time and
 * device gain. The code supports multiple lux equations through the lux table
 * coefficients. A lux gain trim is applied to each lux equation, and then the
 * maximum lux within the interval 0..65535 is selected.
 */
static int tsl2772_get_lux(struct iio_dev *indio_dev)
{}

/**
 * tsl2772_get_prox() - Reads proximity data registers and updates
 *                      chip->prox_data.
 *
 * @indio_dev:	pointer to IIO device
 */
static int tsl2772_get_prox(struct iio_dev *indio_dev)
{}

static int tsl2772_read_prox_led_current(struct tsl2772_chip *chip)
{}

static int tsl2772_read_prox_diodes(struct tsl2772_chip *chip)
{}

static void tsl2772_parse_dt(struct tsl2772_chip *chip)
{}

/**
 * tsl2772_defaults() - Populates the device nominal operating parameters
 *                      with those provided by a 'platform' data struct or
 *                      with prefined defaults.
 *
 * @chip:               pointer to device structure.
 */
static void tsl2772_defaults(struct tsl2772_chip *chip)
{}

/**
 * tsl2772_als_calibrate() -	Obtain single reading and calculate
 *                              the als_gain_trim.
 *
 * @indio_dev:	pointer to IIO device
 */
static int tsl2772_als_calibrate(struct iio_dev *indio_dev)
{}

static void tsl2772_disable_regulators_action(void *_data)
{}

static int tsl2772_chip_on(struct iio_dev *indio_dev)
{}

static int tsl2772_chip_off(struct iio_dev *indio_dev)
{}

static void tsl2772_chip_off_action(void *data)
{}

/**
 * tsl2772_invoke_change - power cycle the device to implement the user
 *                         parameters
 * @indio_dev:	pointer to IIO device
 *
 * Obtain and lock both ALS and PROX resources, determine and save device state
 * (On/Off), cycle device to implement updated parameter, put device back into
 * proper state, and unlock resource.
 */
static int tsl2772_invoke_change(struct iio_dev *indio_dev)
{}

static int tsl2772_prox_cal(struct iio_dev *indio_dev)
{}

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

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

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

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

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

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

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

static int tsl2772_read_interrupt_config(struct iio_dev *indio_dev,
					 const struct iio_chan_spec *chan,
					 enum iio_event_type type,
					 enum iio_event_direction dir)
{}

static int tsl2772_write_interrupt_config(struct iio_dev *indio_dev,
					  const struct iio_chan_spec *chan,
					  enum iio_event_type type,
					  enum iio_event_direction dir,
					  int val)
{}

static int tsl2772_write_event_value(struct iio_dev *indio_dev,
				     const struct iio_chan_spec *chan,
				     enum iio_event_type type,
				     enum iio_event_direction dir,
				     enum iio_event_info info,
				     int val, int val2)
{}

static int tsl2772_read_event_value(struct iio_dev *indio_dev,
				    const struct iio_chan_spec *chan,
				    enum iio_event_type type,
				    enum iio_event_direction dir,
				    enum iio_event_info info,
				    int *val, int *val2)
{}

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

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

static DEVICE_ATTR_RW(in_illuminance0_target_input);

static DEVICE_ATTR_WO(in_illuminance0_calibrate);

static DEVICE_ATTR_WO(in_proximity0_calibrate);

static DEVICE_ATTR_RW(in_illuminance0_lux_table);

/* Use the default register values to identify the Taos device */
static int tsl2772_device_id_verif(int id, int target)
{}

static irqreturn_t tsl2772_event_handler(int irq, void *private)
{}

static struct attribute *tsl2772_ALS_device_attrs[] =;

static struct attribute *tsl2772_PRX_device_attrs[] =;

static struct attribute *tsl2772_ALSPRX_device_attrs[] =;

static struct attribute *tsl2772_PRX2_device_attrs[] =;

static struct attribute *tsl2772_ALSPRX2_device_attrs[] =;

static const struct attribute_group tsl2772_device_attr_group_tbl[] =;

#define TSL2772_DEVICE_INFO(type)

static const struct iio_info tsl2772_device_info[] =;

static const struct iio_event_spec tsl2772_events[] =;

static const struct tsl2772_chip_info tsl2772_chip_info_tbl[] =;

static int tsl2772_probe(struct i2c_client *clientp)
{}

static int tsl2772_suspend(struct device *dev)
{}

static int tsl2772_resume(struct device *dev)
{}

static const struct i2c_device_id tsl2772_idtable[] =;

MODULE_DEVICE_TABLE(i2c, tsl2772_idtable);

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

static const struct dev_pm_ops tsl2772_pm_ops =;

static struct i2c_driver tsl2772_driver =;

module_i2c_driver();

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