Source
x
/*
* vcnl4000.c - Support for Vishay VCNL4000/4010/4020/4200 combined ambient
* light and proximity sensor
*
* Copyright 2012 Peter Meerwald <pmeerw@pmeerw.net>
*
* This file is subject to the terms and conditions of version 2 of
* the GNU General Public License. See the file COPYING in the main
* directory of this archive for more details.
*
* IIO driver for:
* VCNL4000/10/20 (7-bit I2C slave address 0x13)
* VCNL4200 (7-bit I2C slave address 0x51)
*
* TODO:
* allow to adjust IR current
* proximity threshold and event handling
* periodic ALS/proximity measurement (VCNL4010/20)
* interrupts (VCNL4010/20, VCNL4200)
*/
/* for VCNL4020, VCNL4010 */
/* Command register */
/* Product ID and Revision ID */
/* IR LED current for proximity mode */
/* Ambient light parameter register */
/* Ambient light result register, MSB */
/* Ambient light result register, LSB */
/* Proximity result register, MSB */
/* Proximity result register, LSB */
/* Proximity test signal frequency */
/* Proximity modulator timing adjustment */
/* Ambient light configuration */
/* Proximity configuration */
/* Proximity data */
/* Ambient light data */
/* Device ID, slave address and version */
/* Bit masks for COMMAND register */
/* ALS data ready? */
/* proximity data ready? */
/* start on-demand ALS measurement */
/* start on-demand proximity measurement */
enum vcnl4000_device_ids {
VCNL4000,
VCNL4010,
VCNL4200,
};
struct vcnl4200_channel {
u8 reg;
ktime_t last_measurement;
ktime_t sampling_rate;
struct mutex lock;
};
struct vcnl4000_data {
struct i2c_client *client;
enum vcnl4000_device_ids id;
int rev;
int al_scale;
const struct vcnl4000_chip_spec *chip_spec;
struct mutex vcnl4000_lock;
struct vcnl4200_channel vcnl4200_al;
struct vcnl4200_channel vcnl4200_ps;
};
struct vcnl4000_chip_spec {
const char *prod;
int (*init)(struct vcnl4000_data *data);
int (*measure_light)(struct vcnl4000_data *data, int *val);
int (*measure_proximity)(struct vcnl4000_data *data, int *val);
};
static const struct i2c_device_id vcnl4000_id[] = {
{ "vcnl4000", VCNL4000 },
{ "vcnl4010", VCNL4010 },
{ "vcnl4020", VCNL4010 },