Skip to content

Commit 5a441aa

Browse files
nytowljic23
authored andcommitted
iio: light: vcnl4000 add support for the VCNL4040 proximity and light sensor
The VCNL4040 is almost identical to the VCNL4200 as far as register layout goes but just need to check a different ID register location. Signed-off-by: Angus Ainslie (Purism) <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 5da8aff commit 5a441aa

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

drivers/iio/light/vcnl4000.c

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
/*
2-
* vcnl4000.c - Support for Vishay VCNL4000/4010/4020/4200 combined ambient
2+
* vcnl4000.c - Support for Vishay VCNL4000/4010/4020/4040/4200 combined ambient
33
* light and proximity sensor
44
*
55
* Copyright 2012 Peter Meerwald <[email protected]>
6+
* Copyright 2019 Pursim SPC
67
*
78
* This file is subject to the terms and conditions of version 2 of
89
* the GNU General Public License. See the file COPYING in the main
910
* directory of this archive for more details.
1011
*
1112
* IIO driver for:
1213
* VCNL4000/10/20 (7-bit I2C slave address 0x13)
14+
* VCNL4040 (7-bit I2C slave address 0x60)
1315
* VCNL4200 (7-bit I2C slave address 0x51)
1416
*
1517
* TODO:
1618
* allow to adjust IR current
1719
* proximity threshold and event handling
1820
* periodic ALS/proximity measurement (VCNL4010/20)
19-
* interrupts (VCNL4010/20, VCNL4200)
21+
* interrupts (VCNL4010/20/40, VCNL4200)
2022
*/
2123

2224
#include <linux/module.h>
@@ -30,6 +32,7 @@
3032
#define VCNL4000_DRV_NAME "vcnl4000"
3133
#define VCNL4000_PROD_ID 0x01
3234
#define VCNL4010_PROD_ID 0x02 /* for VCNL4020, VCNL4010 */
35+
#define VCNL4040_PROD_ID 0x86
3336
#define VCNL4200_PROD_ID 0x58
3437

3538
#define VCNL4000_COMMAND 0x80 /* Command register */
@@ -49,6 +52,8 @@
4952
#define VCNL4200_AL_DATA 0x09 /* Ambient light data */
5053
#define VCNL4200_DEV_ID 0x0e /* Device ID, slave address and version */
5154

55+
#define VCNL4040_DEV_ID 0x0c /* Device ID and version */
56+
5257
/* Bit masks for COMMAND register */
5358
#define VCNL4000_AL_RDY BIT(6) /* ALS data ready? */
5459
#define VCNL4000_PS_RDY BIT(5) /* proximity data ready? */
@@ -58,6 +63,7 @@
5863
enum vcnl4000_device_ids {
5964
VCNL4000,
6065
VCNL4010,
66+
VCNL4040,
6167
VCNL4200,
6268
};
6369

@@ -90,6 +96,7 @@ static const struct i2c_device_id vcnl4000_id[] = {
9096
{ "vcnl4000", VCNL4000 },
9197
{ "vcnl4010", VCNL4010 },
9298
{ "vcnl4020", VCNL4010 },
99+
{ "vcnl4040", VCNL4040 },
93100
{ "vcnl4200", VCNL4200 },
94101
{ }
95102
};
@@ -128,14 +135,26 @@ static int vcnl4000_init(struct vcnl4000_data *data)
128135

129136
static int vcnl4200_init(struct vcnl4000_data *data)
130137
{
131-
int ret;
138+
int ret, id;
132139

133140
ret = i2c_smbus_read_word_data(data->client, VCNL4200_DEV_ID);
134141
if (ret < 0)
135142
return ret;
136143

137-
if ((ret & 0xff) != VCNL4200_PROD_ID)
138-
return -ENODEV;
144+
id = ret & 0xff;
145+
146+
if (id != VCNL4200_PROD_ID) {
147+
ret = i2c_smbus_read_word_data(data->client, VCNL4040_DEV_ID);
148+
if (ret < 0)
149+
return ret;
150+
151+
id = ret & 0xff;
152+
153+
if (id != VCNL4040_PROD_ID)
154+
return -ENODEV;
155+
}
156+
157+
dev_dbg(&data->client->dev, "device id 0x%x", id);
139158

140159
data->rev = (ret >> 8) & 0xf;
141160

@@ -150,9 +169,19 @@ static int vcnl4200_init(struct vcnl4000_data *data)
150169
data->al_scale = 24000;
151170
data->vcnl4200_al.reg = VCNL4200_AL_DATA;
152171
data->vcnl4200_ps.reg = VCNL4200_PS_DATA;
153-
/* Integration time is 50ms, but the experiments show 54ms in total. */
154-
data->vcnl4200_al.sampling_rate = ktime_set(0, 54000 * 1000);
155-
data->vcnl4200_ps.sampling_rate = ktime_set(0, 4200 * 1000);
172+
switch (id) {
173+
case VCNL4200_PROD_ID:
174+
/* Integration time is 50ms, but the experiments */
175+
/* show 54ms in total. */
176+
data->vcnl4200_al.sampling_rate = ktime_set(0, 54000 * 1000);
177+
data->vcnl4200_ps.sampling_rate = ktime_set(0, 4200 * 1000);
178+
break;
179+
case VCNL4040_PROD_ID:
180+
/* Integration time is 80ms, add 10ms. */
181+
data->vcnl4200_al.sampling_rate = ktime_set(0, 100000 * 1000);
182+
data->vcnl4200_ps.sampling_rate = ktime_set(0, 100000 * 1000);
183+
break;
184+
}
156185
data->vcnl4200_al.last_measurement = ktime_set(0, 0);
157186
data->vcnl4200_ps.last_measurement = ktime_set(0, 0);
158187
mutex_init(&data->vcnl4200_al.lock);
@@ -271,6 +300,12 @@ static const struct vcnl4000_chip_spec vcnl4000_chip_spec_cfg[] = {
271300
.measure_light = vcnl4000_measure_light,
272301
.measure_proximity = vcnl4000_measure_proximity,
273302
},
303+
[VCNL4040] = {
304+
.prod = "VCNL4040",
305+
.init = vcnl4200_init,
306+
.measure_light = vcnl4200_measure_light,
307+
.measure_proximity = vcnl4200_measure_proximity,
308+
},
274309
[VCNL4200] = {
275310
.prod = "VCNL4200",
276311
.init = vcnl4200_init,

0 commit comments

Comments
 (0)