Source
/*
* veml6070.c - Support for Vishay VEML6070 UV A light sensor
*
* Copyright 2016 Peter Meerwald-Stadler <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 VEML6070 (7-bit I2C slave addresses 0x38 and 0x39)
*
* TODO: integration time, ACK signal
*/
/* read: MSB data, write: config */
/* LSB data */
/* raise interrupt when over threshold */
/* bit mask integration time */
/* reserved, set to 1 */
/* shutdown mode when set */
/* integration time 1x */
struct veml6070_data {
struct i2c_client *client1;
struct i2c_client *client2;
u8 config;
struct mutex lock;
};
static int veml6070_read(struct veml6070_data *data)
{
int ret;
u8 msb, lsb;
mutex_lock(&data->lock);
/* disable shutdown */
ret = i2c_smbus_write_byte(data->client1,
data->config & ~VEML6070_COMMAND_SD);
if (ret < 0)
goto out;
msleep(125 + 10); /* measurement takes up to 125 ms for IT 1x */
ret = i2c_smbus_read_byte(data->client2); /* read MSB, address 0x39 */
if (ret < 0)
goto out;
msb = ret;
ret = i2c_smbus_read_byte(data->client1); /* read LSB, address 0x38 */