linux/drivers/iio/light/si1145.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * si1145.c - Support for Silabs SI1132 and SI1141/2/3/5/6/7 combined ambient
 * light, UV index and proximity sensors
 *
 * Copyright 2014-16 Peter Meerwald-Stadler <[email protected]>
 * Copyright 2016 Crestez Dan Leonard <[email protected]>
 *
 * SI1132 (7-bit I2C slave address 0x60)
 * SI1141/2/3 (7-bit I2C slave address 0x5a)
 * SI1145/6/6 (7-bit I2C slave address 0x60)
 */

#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/err.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/irq.h>

#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/iio/trigger.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
#include <linux/iio/buffer.h>
#include <linux/util_macros.h>

#define SI1145_REG_PART_ID
#define SI1145_REG_REV_ID
#define SI1145_REG_SEQ_ID
#define SI1145_REG_INT_CFG
#define SI1145_REG_IRQ_ENABLE
#define SI1145_REG_IRQ_MODE
#define SI1145_REG_HW_KEY
#define SI1145_REG_MEAS_RATE
#define SI1145_REG_PS_LED21
#define SI1145_REG_PS_LED3
#define SI1145_REG_UCOEF1
#define SI1145_REG_UCOEF2
#define SI1145_REG_UCOEF3
#define SI1145_REG_UCOEF4
#define SI1145_REG_PARAM_WR
#define SI1145_REG_COMMAND
#define SI1145_REG_RESPONSE
#define SI1145_REG_IRQ_STATUS
#define SI1145_REG_ALSVIS_DATA
#define SI1145_REG_ALSIR_DATA
#define SI1145_REG_PS1_DATA
#define SI1145_REG_PS2_DATA
#define SI1145_REG_PS3_DATA
#define SI1145_REG_AUX_DATA
#define SI1145_REG_PARAM_RD
#define SI1145_REG_CHIP_STAT

#define SI1145_UCOEF1_DEFAULT
#define SI1145_UCOEF2_DEFAULT
#define SI1145_UCOEF3_DEFAULT
#define SI1145_UCOEF4_DEFAULT

/* Helper to figure out PS_LED register / shift per channel */
#define SI1145_PS_LED_REG(ch)
#define SI1145_PS_LED_SHIFT(ch)

/* Parameter offsets */
#define SI1145_PARAM_CHLIST
#define SI1145_PARAM_PSLED12_SELECT
#define SI1145_PARAM_PSLED3_SELECT
#define SI1145_PARAM_PS_ENCODING
#define SI1145_PARAM_ALS_ENCODING
#define SI1145_PARAM_PS1_ADC_MUX
#define SI1145_PARAM_PS2_ADC_MUX
#define SI1145_PARAM_PS3_ADC_MUX
#define SI1145_PARAM_PS_ADC_COUNTER
#define SI1145_PARAM_PS_ADC_GAIN
#define SI1145_PARAM_PS_ADC_MISC
#define SI1145_PARAM_ALS_ADC_MUX
#define SI1145_PARAM_ALSIR_ADC_MUX
#define SI1145_PARAM_AUX_ADC_MUX
#define SI1145_PARAM_ALSVIS_ADC_COUNTER
#define SI1145_PARAM_ALSVIS_ADC_GAIN
#define SI1145_PARAM_ALSVIS_ADC_MISC
#define SI1145_PARAM_LED_RECOVERY
#define SI1145_PARAM_ALSIR_ADC_COUNTER
#define SI1145_PARAM_ALSIR_ADC_GAIN
#define SI1145_PARAM_ALSIR_ADC_MISC
#define SI1145_PARAM_ADC_OFFSET

/* Channel enable masks for CHLIST parameter */
#define SI1145_CHLIST_EN_PS1
#define SI1145_CHLIST_EN_PS2
#define SI1145_CHLIST_EN_PS3
#define SI1145_CHLIST_EN_ALSVIS
#define SI1145_CHLIST_EN_ALSIR
#define SI1145_CHLIST_EN_AUX
#define SI1145_CHLIST_EN_UV

/* Proximity measurement mode for ADC_MISC parameter */
#define SI1145_PS_ADC_MODE_NORMAL
/* Signal range mask for ADC_MISC parameter */
#define SI1145_ADC_MISC_RANGE

/* Commands for REG_COMMAND */
#define SI1145_CMD_NOP
#define SI1145_CMD_RESET
#define SI1145_CMD_PS_FORCE
#define SI1145_CMD_ALS_FORCE
#define SI1145_CMD_PSALS_FORCE
#define SI1145_CMD_PS_PAUSE
#define SI1145_CMD_ALS_PAUSE
#define SI1145_CMD_PSALS_PAUSE
#define SI1145_CMD_PS_AUTO
#define SI1145_CMD_ALS_AUTO
#define SI1145_CMD_PSALS_AUTO
#define SI1145_CMD_PARAM_QUERY
#define SI1145_CMD_PARAM_SET

#define SI1145_RSP_INVALID_SETTING
#define SI1145_RSP_COUNTER_MASK

/* Minimum sleep after each command to ensure it's received */
#define SI1145_COMMAND_MINSLEEP_MS
/* Return -ETIMEDOUT after this long */
#define SI1145_COMMAND_TIMEOUT_MS

/* Interrupt configuration masks for INT_CFG register */
#define SI1145_INT_CFG_OE
#define SI1145_INT_CFG_MODE

/* Interrupt enable masks for IRQ_ENABLE register */
#define SI1145_MASK_ALL_IE

#define SI1145_MUX_TEMP
#define SI1145_MUX_VDD

/* Proximity LED current; see Table 2 in datasheet */
#define SI1145_LED_CURRENT_45mA

enum {};

struct si1145_part_info {};

/**
 * struct si1145_data - si1145 chip state data
 * @client:	I2C client
 * @lock:	mutex to protect shared state.
 * @cmdlock:	Low-level mutex to protect command execution only
 * @rsp_seq:	Next expected response number or -1 if counter reset required
 * @scan_mask:	Saved scan mask to avoid duplicate set_chlist
 * @autonomous: If automatic measurements are active (for buffer support)
 * @part_info:	Part information
 * @trig:	Pointer to iio trigger
 * @meas_rate:	Value of MEAS_RATE register. Only set in HW in auto mode
 * @buffer:	Used to pack data read from sensor.
 */
struct si1145_data {};

/*
 * __si1145_command_reset() - Send CMD_NOP and wait for response 0
 *
 * Does not modify data->rsp_seq
 *
 * Return: 0 on success and -errno on error.
 */
static int __si1145_command_reset(struct si1145_data *data)
{}

/*
 * si1145_command() - Execute a command and poll the response register
 *
 * All conversion overflows are reported as -EOVERFLOW
 * INVALID_SETTING is reported as -EINVAL
 * Timeouts are reported as -ETIMEDOUT
 *
 * Return: 0 on success or -errno on failure
 */
static int si1145_command(struct si1145_data *data, u8 cmd)
{}

static int si1145_param_update(struct si1145_data *data, u8 op, u8 param,
			       u8 value)
{}

static int si1145_param_set(struct si1145_data *data, u8 param, u8 value)
{}

/* Set param. Returns negative errno or current value */
static int si1145_param_query(struct si1145_data *data, u8 param)
{}

/* Expand 8 bit compressed value to 16 bit, see Silabs AN498 */
static u16 si1145_uncompress(u8 x)
{}

/* Compress 16 bit value to 8 bit, see Silabs AN498 */
static u8 si1145_compress(u16 x)
{}

/* Write meas_rate in hardware */
static int si1145_set_meas_rate(struct si1145_data *data, int interval)
{}

static int si1145_read_samp_freq(struct si1145_data *data, int *val, int *val2)
{}

/* Set the samp freq in driver private data */
static int si1145_store_samp_freq(struct si1145_data *data, int val)
{}

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

static int si1145_set_chlist(struct iio_dev *indio_dev, unsigned long scan_mask)
{}

static int si1145_measure(struct iio_dev *indio_dev,
			  struct iio_chan_spec const *chan)
{}

/*
 * Conversion between iio scale and ADC_GAIN values
 * These could be further adjusted but proximity/intensity are dimensionless
 */
static const int si1145_proximity_scale_available[] =;
static const int si1145_intensity_scale_available[] =;
static IIO_CONST_ATTR(in_proximity_scale_available,
	"128 64 32 16 8 4");
static IIO_CONST_ATTR(in_intensity_scale_available,
	"128 64 32 16 8 4 2 1");
static IIO_CONST_ATTR(in_intensity_ir_scale_available,
	"128 64 32 16 8 4 2 1");

static int si1145_scale_from_adcgain(int regval)
{}

static int si1145_proximity_adcgain_from_scale(int val, int val2)
{}

static int si1145_intensity_adcgain_from_scale(int val, int val2)
{}

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

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

#define SI1145_ST

#define SI1145_INTENSITY_CHANNEL(_si)

#define SI1145_INTENSITY_IR_CHANNEL(_si)

#define SI1145_TEMP_CHANNEL(_si)

#define SI1145_UV_CHANNEL(_si)

#define SI1145_PROXIMITY_CHANNEL(_si, _ch)

#define SI1145_VOLTAGE_CHANNEL(_si)

#define SI1145_CURRENT_CHANNEL(_ch)

static const struct iio_chan_spec si1132_channels[] =;

static const struct iio_chan_spec si1141_channels[] =;

static const struct iio_chan_spec si1142_channels[] =;

static const struct iio_chan_spec si1143_channels[] =;

static const struct iio_chan_spec si1145_channels[] =;

static const struct iio_chan_spec si1146_channels[] =;

static const struct iio_chan_spec si1147_channels[] =;

static struct attribute *si1132_attributes[] =;

static struct attribute *si114x_attributes[] =;

static const struct attribute_group si1132_attribute_group =;

static const struct attribute_group si114x_attribute_group =;


static const struct iio_info si1132_info =;

static const struct iio_info si114x_info =;

#define SI1145_PART(id, iio_info, chans, leds, uncompressed_meas_rate)

static const struct si1145_part_info si1145_part_info[] =;

static int si1145_initialize(struct si1145_data *data)
{}

/*
 * Program the channels we want to measure with CMD_PSALS_AUTO. No need for
 * _postdisable as we stop with CMD_PSALS_PAUSE; single measurement (direct)
 * mode reprograms the channels list anyway...
 */
static int si1145_buffer_preenable(struct iio_dev *indio_dev)
{}

static bool si1145_validate_scan_mask(struct iio_dev *indio_dev,
			       const unsigned long *scan_mask)
{}

static const struct iio_buffer_setup_ops si1145_buffer_setup_ops =;

/*
 * si1145_trigger_set_state() - Set trigger state
 *
 * When not using triggers interrupts are disabled and measurement rate is
 * set to zero in order to minimize power consumption.
 */
static int si1145_trigger_set_state(struct iio_trigger *trig, bool state)
{}

static const struct iio_trigger_ops si1145_trigger_ops =;

static int si1145_probe_trigger(struct iio_dev *indio_dev)
{}

static int si1145_probe(struct i2c_client *client)
{}

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

static struct i2c_driver si1145_driver =;

module_i2c_driver();

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