blob: 61f5924b472d9651e1f84c84156e3281be549fdb [file] [log] [blame]
Rhyland Klein94042872010-10-07 15:48:09 -07001/*
Laurentiu Palcu609acef2014-08-29 15:26:00 +01002 * A iio driver for the light sensor ISL 29018/29023/29035.
Rhyland Klein94042872010-10-07 15:48:09 -07003 *
4 * IIO driver for monitoring ambient light intensity in luxi, proximity
5 * sensing and infrared sensing.
6 *
7 * Copyright (c) 2010, NVIDIA Corporation.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
Rhyland Klein94042872010-10-07 15:48:09 -070018 */
19
20#include <linux/module.h>
21#include <linux/i2c.h>
22#include <linux/err.h>
23#include <linux/mutex.h>
24#include <linux/delay.h>
Laxman Dewangan057340e2012-04-20 12:57:38 +053025#include <linux/regmap.h>
Rhyland Klein94042872010-10-07 15:48:09 -070026#include <linux/slab.h>
Jonathan Cameron06458e22012-04-25 15:54:58 +010027#include <linux/iio/iio.h>
28#include <linux/iio/sysfs.h>
Laurentiu Palcudc4ecaf2014-01-09 10:20:00 +000029#include <linux/acpi.h>
Laxman Dewangan057340e2012-04-20 12:57:38 +053030
Peter Meerwald-Stadler13e6d632016-07-05 13:55:36 +020031#define ISL29018_CONV_TIME_MS 100
Rhyland Klein94042872010-10-07 15:48:09 -070032
33#define ISL29018_REG_ADD_COMMAND1 0x00
Peter Meerwald-Stadler13e6d632016-07-05 13:55:36 +020034#define ISL29018_CMD1_OPMODE_SHIFT 5
35#define ISL29018_CMD1_OPMODE_MASK (7 << ISL29018_CMD1_OPMODE_SHIFT)
36#define ISL29018_CMD1_OPMODE_POWER_DOWN 0
37#define ISL29018_CMD1_OPMODE_ALS_ONCE 1
38#define ISL29018_CMD1_OPMODE_IR_ONCE 2
39#define ISL29018_CMD1_OPMODE_PROX_ONCE 3
Rhyland Klein94042872010-10-07 15:48:09 -070040
Peter Meerwald-Stadler13e6d632016-07-05 13:55:36 +020041#define ISL29018_REG_ADD_COMMAND2 0x01
42#define ISL29018_CMD2_RESOLUTION_SHIFT 2
43#define ISL29018_CMD2_RESOLUTION_MASK (0x3 << ISL29018_CMD2_RESOLUTION_SHIFT)
Rhyland Klein94042872010-10-07 15:48:09 -070044
Peter Meerwald-Stadler13e6d632016-07-05 13:55:36 +020045#define ISL29018_CMD2_RANGE_SHIFT 0
46#define ISL29018_CMD2_RANGE_MASK (0x3 << ISL29018_CMD2_RANGE_SHIFT)
Rhyland Klein94042872010-10-07 15:48:09 -070047
Peter Meerwald-Stadler13e6d632016-07-05 13:55:36 +020048#define ISL29018_CMD2_SCHEME_SHIFT 7
49#define ISL29018_CMD2_SCHEME_MASK (0x1 << ISL29018_CMD2_SCHEME_SHIFT)
Rhyland Klein94042872010-10-07 15:48:09 -070050
51#define ISL29018_REG_ADD_DATA_LSB 0x02
52#define ISL29018_REG_ADD_DATA_MSB 0x03
Rhyland Klein94042872010-10-07 15:48:09 -070053
Grant Grundler176f9f22011-08-09 15:18:14 -070054#define ISL29018_REG_TEST 0x08
55#define ISL29018_TEST_SHIFT 0
56#define ISL29018_TEST_MASK (0xFF << ISL29018_TEST_SHIFT)
57
Laurentiu Palcu609acef2014-08-29 15:26:00 +010058#define ISL29035_REG_DEVICE_ID 0x0F
59#define ISL29035_DEVICE_ID_SHIFT 0x03
60#define ISL29035_DEVICE_ID_MASK (0x7 << ISL29035_DEVICE_ID_SHIFT)
61#define ISL29035_DEVICE_ID 0x5
62#define ISL29035_BOUT_SHIFT 0x07
63#define ISL29035_BOUT_MASK (0x01 << ISL29035_BOUT_SHIFT)
64
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +030065enum isl29018_int_time {
66 ISL29018_INT_TIME_16,
67 ISL29018_INT_TIME_12,
68 ISL29018_INT_TIME_8,
69 ISL29018_INT_TIME_4,
70};
71
72static const unsigned int isl29018_int_utimes[3][4] = {
73 {90000, 5630, 351, 21},
74 {90000, 5600, 352, 22},
75 {105000, 6500, 410, 25},
76};
77
78static const struct isl29018_scale {
79 unsigned int scale;
80 unsigned int uscale;
81} isl29018_scales[4][4] = {
82 { {0, 15258}, {0, 61035}, {0, 244140}, {0, 976562} },
83 { {0, 244140}, {0, 976562}, {3, 906250}, {15, 625000} },
84 { {3, 906250}, {15, 625000}, {62, 500000}, {250, 0} },
85 { {62, 500000}, {250, 0}, {1000, 0}, {4000, 0} }
86};
87
Rhyland Klein94042872010-10-07 15:48:09 -070088struct isl29018_chip {
Laxman Dewangan057340e2012-04-20 12:57:38 +053089 struct regmap *regmap;
Rhyland Klein94042872010-10-07 15:48:09 -070090 struct mutex lock;
Laurentiu Palcu609acef2014-08-29 15:26:00 +010091 int type;
Roberta Dobrescu809a5912015-04-16 22:20:58 +030092 unsigned int calibscale;
93 unsigned int ucalibscale;
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +030094 unsigned int int_time;
95 struct isl29018_scale scale;
Rhyland Klein94042872010-10-07 15:48:09 -070096 int prox_scheme;
Bryan Freed1e45cf32012-10-25 00:39:00 +010097 bool suspended;
Rhyland Klein94042872010-10-07 15:48:09 -070098};
99
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300100static int isl29018_set_integration_time(struct isl29018_chip *chip,
101 unsigned int utime)
Rhyland Klein94042872010-10-07 15:48:09 -0700102{
Brian Masneyea908ab2016-09-25 07:41:07 -0400103 unsigned int i;
104 int ret;
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300105 unsigned int int_time, new_int_time;
Rhyland Klein94042872010-10-07 15:48:09 -0700106
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300107 for (i = 0; i < ARRAY_SIZE(isl29018_int_utimes[chip->type]); ++i) {
108 if (utime == isl29018_int_utimes[chip->type][i]) {
109 new_int_time = i;
Rhyland Klein94042872010-10-07 15:48:09 -0700110 break;
111 }
112 }
113
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300114 if (i >= ARRAY_SIZE(isl29018_int_utimes[chip->type]))
Rhyland Klein94042872010-10-07 15:48:09 -0700115 return -EINVAL;
116
Peter Meerwald-Stadler13e6d632016-07-05 13:55:36 +0200117 ret = regmap_update_bits(chip->regmap, ISL29018_REG_ADD_COMMAND2,
118 ISL29018_CMD2_RESOLUTION_MASK,
119 i << ISL29018_CMD2_RESOLUTION_SHIFT);
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300120 if (ret < 0)
121 return ret;
122
Peter Meerwald-Stadler96273f432016-07-05 13:55:39 +0200123 /* Keep the same range when integration time changes */
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300124 int_time = chip->int_time;
125 for (i = 0; i < ARRAY_SIZE(isl29018_scales[int_time]); ++i) {
126 if (chip->scale.scale == isl29018_scales[int_time][i].scale &&
127 chip->scale.uscale == isl29018_scales[int_time][i].uscale) {
128 chip->scale = isl29018_scales[new_int_time][i];
129 break;
130 }
131 }
132 chip->int_time = new_int_time;
133
134 return 0;
Rhyland Klein94042872010-10-07 15:48:09 -0700135}
136
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300137static int isl29018_set_scale(struct isl29018_chip *chip, int scale, int uscale)
Rhyland Klein94042872010-10-07 15:48:09 -0700138{
Brian Masneyea908ab2016-09-25 07:41:07 -0400139 unsigned int i;
140 int ret;
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300141 struct isl29018_scale new_scale;
Rhyland Klein94042872010-10-07 15:48:09 -0700142
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300143 for (i = 0; i < ARRAY_SIZE(isl29018_scales[chip->int_time]); ++i) {
144 if (scale == isl29018_scales[chip->int_time][i].scale &&
145 uscale == isl29018_scales[chip->int_time][i].uscale) {
146 new_scale = isl29018_scales[chip->int_time][i];
Rhyland Klein94042872010-10-07 15:48:09 -0700147 break;
148 }
149 }
150
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300151 if (i >= ARRAY_SIZE(isl29018_scales[chip->int_time]))
Rhyland Klein94042872010-10-07 15:48:09 -0700152 return -EINVAL;
153
Peter Meerwald-Stadler13e6d632016-07-05 13:55:36 +0200154 ret = regmap_update_bits(chip->regmap, ISL29018_REG_ADD_COMMAND2,
155 ISL29018_CMD2_RANGE_MASK,
156 i << ISL29018_CMD2_RANGE_SHIFT);
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300157 if (ret < 0)
158 return ret;
159
160 chip->scale = new_scale;
161
162 return 0;
Rhyland Klein94042872010-10-07 15:48:09 -0700163}
164
Laxman Dewangan057340e2012-04-20 12:57:38 +0530165static int isl29018_read_sensor_input(struct isl29018_chip *chip, int mode)
Rhyland Klein94042872010-10-07 15:48:09 -0700166{
167 int status;
Laxman Dewangan057340e2012-04-20 12:57:38 +0530168 unsigned int lsb;
169 unsigned int msb;
Alison Schofield64670862016-02-22 12:34:32 -0800170 struct device *dev = regmap_get_device(chip->regmap);
Rhyland Klein94042872010-10-07 15:48:09 -0700171
172 /* Set mode */
Laxman Dewangan057340e2012-04-20 12:57:38 +0530173 status = regmap_write(chip->regmap, ISL29018_REG_ADD_COMMAND1,
Peter Meerwald-Stadler13e6d632016-07-05 13:55:36 +0200174 mode << ISL29018_CMD1_OPMODE_SHIFT);
Rhyland Klein94042872010-10-07 15:48:09 -0700175 if (status) {
Alison Schofield64670862016-02-22 12:34:32 -0800176 dev_err(dev,
Laxman Dewangan057340e2012-04-20 12:57:38 +0530177 "Error in setting operating mode err %d\n", status);
Rhyland Klein94042872010-10-07 15:48:09 -0700178 return status;
179 }
Peter Meerwald-Stadler13e6d632016-07-05 13:55:36 +0200180 msleep(ISL29018_CONV_TIME_MS);
Laxman Dewangan057340e2012-04-20 12:57:38 +0530181 status = regmap_read(chip->regmap, ISL29018_REG_ADD_DATA_LSB, &lsb);
182 if (status < 0) {
Alison Schofield64670862016-02-22 12:34:32 -0800183 dev_err(dev,
Laxman Dewangan057340e2012-04-20 12:57:38 +0530184 "Error in reading LSB DATA with err %d\n", status);
185 return status;
Rhyland Klein94042872010-10-07 15:48:09 -0700186 }
187
Laxman Dewangan057340e2012-04-20 12:57:38 +0530188 status = regmap_read(chip->regmap, ISL29018_REG_ADD_DATA_MSB, &msb);
189 if (status < 0) {
Alison Schofield64670862016-02-22 12:34:32 -0800190 dev_err(dev,
Laxman Dewangan057340e2012-04-20 12:57:38 +0530191 "Error in reading MSB DATA with error %d\n", status);
192 return status;
Rhyland Klein94042872010-10-07 15:48:09 -0700193 }
Alison Schofield64670862016-02-22 12:34:32 -0800194 dev_vdbg(dev, "MSB 0x%x and LSB 0x%x\n", msb, lsb);
Rhyland Klein94042872010-10-07 15:48:09 -0700195
196 return (msb << 8) | lsb;
197}
198
Laxman Dewangan057340e2012-04-20 12:57:38 +0530199static int isl29018_read_lux(struct isl29018_chip *chip, int *lux)
Rhyland Klein94042872010-10-07 15:48:09 -0700200{
201 int lux_data;
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300202 unsigned int data_x_range;
Rhyland Klein94042872010-10-07 15:48:09 -0700203
Peter Meerwald-Stadler13e6d632016-07-05 13:55:36 +0200204 lux_data = isl29018_read_sensor_input(chip,
205 ISL29018_CMD1_OPMODE_ALS_ONCE);
Rhyland Klein94042872010-10-07 15:48:09 -0700206 if (lux_data < 0)
207 return lux_data;
208
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300209 data_x_range = lux_data * chip->scale.scale +
210 lux_data * chip->scale.uscale / 1000000;
211 *lux = data_x_range * chip->calibscale +
212 data_x_range * chip->ucalibscale / 1000000;
Rhyland Klein94042872010-10-07 15:48:09 -0700213
214 return 0;
215}
216
Laxman Dewangan057340e2012-04-20 12:57:38 +0530217static int isl29018_read_ir(struct isl29018_chip *chip, int *ir)
Rhyland Klein94042872010-10-07 15:48:09 -0700218{
219 int ir_data;
220
Peter Meerwald-Stadler13e6d632016-07-05 13:55:36 +0200221 ir_data = isl29018_read_sensor_input(chip,
222 ISL29018_CMD1_OPMODE_IR_ONCE);
Rhyland Klein94042872010-10-07 15:48:09 -0700223 if (ir_data < 0)
224 return ir_data;
225
226 *ir = ir_data;
227
228 return 0;
229}
230
Laxman Dewangan057340e2012-04-20 12:57:38 +0530231static int isl29018_read_proximity_ir(struct isl29018_chip *chip, int scheme,
Eva Rachel Retuyaca52c882016-02-18 15:35:36 +0800232 int *near_ir)
Rhyland Klein94042872010-10-07 15:48:09 -0700233{
234 int status;
235 int prox_data = -1;
236 int ir_data = -1;
Alison Schofield64670862016-02-22 12:34:32 -0800237 struct device *dev = regmap_get_device(chip->regmap);
Rhyland Klein94042872010-10-07 15:48:09 -0700238
239 /* Do proximity sensing with required scheme */
Peter Meerwald-Stadler13e6d632016-07-05 13:55:36 +0200240 status = regmap_update_bits(chip->regmap, ISL29018_REG_ADD_COMMAND2,
241 ISL29018_CMD2_SCHEME_MASK,
242 scheme << ISL29018_CMD2_SCHEME_SHIFT);
Rhyland Klein94042872010-10-07 15:48:09 -0700243 if (status) {
Alison Schofield64670862016-02-22 12:34:32 -0800244 dev_err(dev, "Error in setting operating mode\n");
Rhyland Klein94042872010-10-07 15:48:09 -0700245 return status;
246 }
247
Laxman Dewangan057340e2012-04-20 12:57:38 +0530248 prox_data = isl29018_read_sensor_input(chip,
Peter Meerwald-Stadler13e6d632016-07-05 13:55:36 +0200249 ISL29018_CMD1_OPMODE_PROX_ONCE);
Rhyland Klein94042872010-10-07 15:48:09 -0700250 if (prox_data < 0)
251 return prox_data;
252
253 if (scheme == 1) {
254 *near_ir = prox_data;
255 return 0;
256 }
257
Peter Meerwald-Stadler13e6d632016-07-05 13:55:36 +0200258 ir_data = isl29018_read_sensor_input(chip,
259 ISL29018_CMD1_OPMODE_IR_ONCE);
Rhyland Klein94042872010-10-07 15:48:09 -0700260 if (ir_data < 0)
261 return ir_data;
262
263 if (prox_data >= ir_data)
264 *near_ir = prox_data - ir_data;
265 else
266 *near_ir = 0;
267
268 return 0;
269}
270
Brian Masney02819962016-09-26 20:20:17 -0400271static ssize_t in_illuminance_scale_available_show
272 (struct device *dev, struct device_attribute *attr,
273 char *buf)
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300274{
275 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
276 struct isl29018_chip *chip = iio_priv(indio_dev);
Brian Masneyea908ab2016-09-25 07:41:07 -0400277 unsigned int i;
278 int len = 0;
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300279
Brian Masney5faf98c2016-09-26 20:20:18 -0400280 mutex_lock(&chip->lock);
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300281 for (i = 0; i < ARRAY_SIZE(isl29018_scales[chip->int_time]); ++i)
282 len += sprintf(buf + len, "%d.%06d ",
283 isl29018_scales[chip->int_time][i].scale,
284 isl29018_scales[chip->int_time][i].uscale);
Brian Masney5faf98c2016-09-26 20:20:18 -0400285 mutex_unlock(&chip->lock);
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300286
287 buf[len - 1] = '\n';
288
289 return len;
290}
291
Brian Masney02819962016-09-26 20:20:17 -0400292static ssize_t in_illuminance_integration_time_available_show
293 (struct device *dev, struct device_attribute *attr,
294 char *buf)
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300295{
296 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
297 struct isl29018_chip *chip = iio_priv(indio_dev);
Brian Masneyea908ab2016-09-25 07:41:07 -0400298 unsigned int i;
299 int len = 0;
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300300
301 for (i = 0; i < ARRAY_SIZE(isl29018_int_utimes[chip->type]); ++i)
302 len += sprintf(buf + len, "0.%06d ",
303 isl29018_int_utimes[chip->type][i]);
304
305 buf[len - 1] = '\n';
306
307 return len;
308}
309
Brian Masneye748e282016-10-06 20:48:34 -0400310/*
311 * From ISL29018 Data Sheet (FN6619.4, Oct 8, 2012) regarding the
312 * infrared suppression:
313 *
314 * Proximity Sensing Scheme: Bit 7. This bit programs the function
315 * of the proximity detection. Logic 0 of this bit, Scheme 0, makes
316 * full n (4, 8, 12, 16) bits (unsigned) proximity detection. The range
317 * of Scheme 0 proximity count is from 0 to 2^n. Logic 1 of this bit,
318 * Scheme 1, makes n-1 (3, 7, 11, 15) bits (2's complementary)
319 * proximity_less_ambient detection. The range of Scheme 1
320 * proximity count is from -2^(n-1) to 2^(n-1) . The sign bit is extended
321 * for resolutions less than 16. While Scheme 0 has wider dynamic
322 * range, Scheme 1 proximity detection is less affected by the
323 * ambient IR noise variation.
324 *
325 * 0 Sensing IR from LED and ambient
326 * 1 Sensing IR from LED with ambient IR rejection
327 */
Brian Masney02819962016-09-26 20:20:17 -0400328static ssize_t proximity_on_chip_ambient_infrared_suppression_show
329 (struct device *dev, struct device_attribute *attr,
330 char *buf)
Rhyland Klein94042872010-10-07 15:48:09 -0700331{
Lars-Peter Clausen96f691f2012-05-12 15:39:51 +0200332 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
Jonathan Cameron927afbe2011-06-27 13:07:57 +0100333 struct isl29018_chip *chip = iio_priv(indio_dev);
Rhyland Klein94042872010-10-07 15:48:09 -0700334
Eva Rachel Retuya7f3829a2016-02-18 15:35:38 +0800335 /*
Peter Meerwald-Stadler96273f432016-07-05 13:55:39 +0200336 * Return the "proximity scheme" i.e. if the chip does on chip
Eva Rachel Retuya7f3829a2016-02-18 15:35:38 +0800337 * infrared suppression (1 means perform on chip suppression)
338 */
Rhyland Klein94042872010-10-07 15:48:09 -0700339 return sprintf(buf, "%d\n", chip->prox_scheme);
340}
341
Brian Masney02819962016-09-26 20:20:17 -0400342static ssize_t proximity_on_chip_ambient_infrared_suppression_store
343 (struct device *dev, struct device_attribute *attr,
344 const char *buf, size_t count)
Rhyland Klein94042872010-10-07 15:48:09 -0700345{
Lars-Peter Clausen96f691f2012-05-12 15:39:51 +0200346 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
Jonathan Cameron927afbe2011-06-27 13:07:57 +0100347 struct isl29018_chip *chip = iio_priv(indio_dev);
Jingoo Hane5e26dd2013-08-20 03:31:00 +0100348 int val;
Rhyland Klein94042872010-10-07 15:48:09 -0700349
Jingoo Hane5e26dd2013-08-20 03:31:00 +0100350 if (kstrtoint(buf, 10, &val))
Rhyland Klein94042872010-10-07 15:48:09 -0700351 return -EINVAL;
Peter Meerwald-Stadlerab5b9492016-07-05 13:55:37 +0200352 if (!(val == 0 || val == 1))
Rhyland Klein94042872010-10-07 15:48:09 -0700353 return -EINVAL;
Rhyland Klein94042872010-10-07 15:48:09 -0700354
Eva Rachel Retuya7f3829a2016-02-18 15:35:38 +0800355 /*
Peter Meerwald-Stadler96273f432016-07-05 13:55:39 +0200356 * Get the "proximity scheme" i.e. if the chip does on chip
Eva Rachel Retuya7f3829a2016-02-18 15:35:38 +0800357 * infrared suppression (1 means perform on chip suppression)
358 */
Rhyland Klein94042872010-10-07 15:48:09 -0700359 mutex_lock(&chip->lock);
Jingoo Hane5e26dd2013-08-20 03:31:00 +0100360 chip->prox_scheme = val;
Rhyland Klein94042872010-10-07 15:48:09 -0700361 mutex_unlock(&chip->lock);
362
363 return count;
364}
365
Bryan Freed01e57c52011-07-07 12:01:56 -0700366static int isl29018_write_raw(struct iio_dev *indio_dev,
367 struct iio_chan_spec const *chan,
368 int val,
369 int val2,
370 long mask)
Rhyland Klein94042872010-10-07 15:48:09 -0700371{
Bryan Freed01e57c52011-07-07 12:01:56 -0700372 struct isl29018_chip *chip = iio_priv(indio_dev);
373 int ret = -EINVAL;
374
375 mutex_lock(&chip->lock);
Brian Masney00053562016-09-26 20:20:20 -0400376 if (chip->suspended) {
377 ret = -EBUSY;
378 goto write_done;
379 }
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300380 switch (mask) {
381 case IIO_CHAN_INFO_CALIBSCALE:
382 if (chan->type == IIO_LIGHT) {
383 chip->calibscale = val;
384 chip->ucalibscale = val2;
385 ret = 0;
386 }
387 break;
388 case IIO_CHAN_INFO_INT_TIME:
Brian Masney528021f2016-09-25 07:41:06 -0400389 if (chan->type == IIO_LIGHT && !val)
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300390 ret = isl29018_set_integration_time(chip, val2);
391 break;
392 case IIO_CHAN_INFO_SCALE:
393 if (chan->type == IIO_LIGHT)
394 ret = isl29018_set_scale(chip, val, val2);
395 break;
396 default:
397 break;
Bryan Freed01e57c52011-07-07 12:01:56 -0700398 }
Bryan Freed01e57c52011-07-07 12:01:56 -0700399
Brian Masney00053562016-09-26 20:20:20 -0400400write_done:
401 mutex_unlock(&chip->lock);
Brian Masney744ef622016-10-10 03:19:55 -0400402
Wei Yongjun6dc973d2012-11-08 09:05:00 +0000403 return ret;
Rhyland Klein94042872010-10-07 15:48:09 -0700404}
405
Bryan Freed01e57c52011-07-07 12:01:56 -0700406static int isl29018_read_raw(struct iio_dev *indio_dev,
407 struct iio_chan_spec const *chan,
408 int *val,
409 int *val2,
410 long mask)
Rhyland Klein94042872010-10-07 15:48:09 -0700411{
Bryan Freed01e57c52011-07-07 12:01:56 -0700412 int ret = -EINVAL;
413 struct isl29018_chip *chip = iio_priv(indio_dev);
Bryan Freed01e57c52011-07-07 12:01:56 -0700414
415 mutex_lock(&chip->lock);
Bryan Freed1e45cf32012-10-25 00:39:00 +0100416 if (chip->suspended) {
Brian Masney5611cd62016-09-26 20:20:19 -0400417 ret = -EBUSY;
418 goto read_done;
Bryan Freed1e45cf32012-10-25 00:39:00 +0100419 }
Bryan Freed01e57c52011-07-07 12:01:56 -0700420 switch (mask) {
Jonathan Cameron90354d02012-04-15 17:41:22 +0100421 case IIO_CHAN_INFO_RAW:
422 case IIO_CHAN_INFO_PROCESSED:
Bryan Freed01e57c52011-07-07 12:01:56 -0700423 switch (chan->type) {
424 case IIO_LIGHT:
Laxman Dewangan057340e2012-04-20 12:57:38 +0530425 ret = isl29018_read_lux(chip, val);
Bryan Freed01e57c52011-07-07 12:01:56 -0700426 break;
427 case IIO_INTENSITY:
Laxman Dewangan057340e2012-04-20 12:57:38 +0530428 ret = isl29018_read_ir(chip, val);
Bryan Freed01e57c52011-07-07 12:01:56 -0700429 break;
430 case IIO_PROXIMITY:
Laxman Dewangan057340e2012-04-20 12:57:38 +0530431 ret = isl29018_read_proximity_ir(chip,
Eva Rachel Retuyaca52c882016-02-18 15:35:36 +0800432 chip->prox_scheme,
433 val);
Bryan Freed01e57c52011-07-07 12:01:56 -0700434 break;
435 default:
436 break;
437 }
438 if (!ret)
439 ret = IIO_VAL_INT;
440 break;
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300441 case IIO_CHAN_INFO_INT_TIME:
442 if (chan->type == IIO_LIGHT) {
443 *val = 0;
444 *val2 = isl29018_int_utimes[chip->type][chip->int_time];
445 ret = IIO_VAL_INT_PLUS_MICRO;
446 }
447 break;
448 case IIO_CHAN_INFO_SCALE:
449 if (chan->type == IIO_LIGHT) {
450 *val = chip->scale.scale;
451 *val2 = chip->scale.uscale;
452 ret = IIO_VAL_INT_PLUS_MICRO;
453 }
454 break;
Jonathan Cameronc8a9f802011-10-26 17:41:36 +0100455 case IIO_CHAN_INFO_CALIBSCALE:
Bryan Freed01e57c52011-07-07 12:01:56 -0700456 if (chan->type == IIO_LIGHT) {
Roberta Dobrescu809a5912015-04-16 22:20:58 +0300457 *val = chip->calibscale;
458 *val2 = chip->ucalibscale;
Bryan Freed932323b2012-09-05 20:55:00 +0100459 ret = IIO_VAL_INT_PLUS_MICRO;
Bryan Freed01e57c52011-07-07 12:01:56 -0700460 }
461 break;
462 default:
463 break;
464 }
Brian Masney5611cd62016-09-26 20:20:19 -0400465
466read_done:
Bryan Freed01e57c52011-07-07 12:01:56 -0700467 mutex_unlock(&chip->lock);
Brian Masney744ef622016-10-10 03:19:55 -0400468
Bryan Freed01e57c52011-07-07 12:01:56 -0700469 return ret;
Rhyland Klein94042872010-10-07 15:48:09 -0700470}
471
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100472#define ISL29018_LIGHT_CHANNEL { \
473 .type = IIO_LIGHT, \
474 .indexed = 1, \
475 .channel = 0, \
476 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | \
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300477 BIT(IIO_CHAN_INFO_CALIBSCALE) | \
478 BIT(IIO_CHAN_INFO_SCALE) | \
479 BIT(IIO_CHAN_INFO_INT_TIME), \
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100480}
481
482#define ISL29018_IR_CHANNEL { \
483 .type = IIO_INTENSITY, \
484 .modified = 1, \
485 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
486 .channel2 = IIO_MOD_LIGHT_IR, \
487}
488
489#define ISL29018_PROXIMITY_CHANNEL { \
490 .type = IIO_PROXIMITY, \
491 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
492}
493
Bryan Freed01e57c52011-07-07 12:01:56 -0700494static const struct iio_chan_spec isl29018_channels[] = {
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100495 ISL29018_LIGHT_CHANNEL,
496 ISL29018_IR_CHANNEL,
497 ISL29018_PROXIMITY_CHANNEL,
498};
499
500static const struct iio_chan_spec isl29023_channels[] = {
501 ISL29018_LIGHT_CHANNEL,
502 ISL29018_IR_CHANNEL,
Bryan Freed01e57c52011-07-07 12:01:56 -0700503};
Rhyland Klein94042872010-10-07 15:48:09 -0700504
Brian Masney02819962016-09-26 20:20:17 -0400505static IIO_DEVICE_ATTR_RO(in_illuminance_integration_time_available, 0);
506static IIO_DEVICE_ATTR_RO(in_illuminance_scale_available, 0);
507static IIO_DEVICE_ATTR_RW(proximity_on_chip_ambient_infrared_suppression, 0);
Rhyland Klein94042872010-10-07 15:48:09 -0700508
509#define ISL29018_DEV_ATTR(name) (&iio_dev_attr_##name.dev_attr.attr)
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300510
Rhyland Klein94042872010-10-07 15:48:09 -0700511static struct attribute *isl29018_attributes[] = {
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300512 ISL29018_DEV_ATTR(in_illuminance_scale_available),
513 ISL29018_DEV_ATTR(in_illuminance_integration_time_available),
Peter Meerwald2a1d45e2012-06-18 20:33:07 +0200514 ISL29018_DEV_ATTR(proximity_on_chip_ambient_infrared_suppression),
Rhyland Klein94042872010-10-07 15:48:09 -0700515 NULL
516};
517
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100518static struct attribute *isl29023_attributes[] = {
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300519 ISL29018_DEV_ATTR(in_illuminance_scale_available),
520 ISL29018_DEV_ATTR(in_illuminance_integration_time_available),
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100521 NULL
522};
523
Laurentiu Palcu5b4b5b92014-08-29 15:26:00 +0100524static const struct attribute_group isl29018_group = {
Rhyland Klein94042872010-10-07 15:48:09 -0700525 .attrs = isl29018_attributes,
526};
527
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100528static const struct attribute_group isl29023_group = {
529 .attrs = isl29023_attributes,
530};
531
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100532enum {
533 isl29018,
534 isl29023,
535 isl29035,
536};
537
Laxman Dewangan057340e2012-04-20 12:57:38 +0530538static int isl29018_chip_init(struct isl29018_chip *chip)
Rhyland Klein94042872010-10-07 15:48:09 -0700539{
Rhyland Klein94042872010-10-07 15:48:09 -0700540 int status;
Alison Schofield64670862016-02-22 12:34:32 -0800541 struct device *dev = regmap_get_device(chip->regmap);
Rhyland Klein94042872010-10-07 15:48:09 -0700542
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100543 if (chip->type == isl29035) {
Brian Masney82811012016-10-10 03:19:56 -0400544 unsigned int id;
545
546 status = regmap_read(chip->regmap, ISL29035_REG_DEVICE_ID, &id);
547 if (status < 0) {
548 dev_err(dev,
549 "Error reading ID register with error %d\n",
550 status);
551 return status;
552 }
553
554 id = (id & ISL29035_DEVICE_ID_MASK) >> ISL29035_DEVICE_ID_SHIFT;
555
556 if (id != ISL29035_DEVICE_ID)
557 return -ENODEV;
558
559 /* Clear brownout bit */
560 status = regmap_update_bits(chip->regmap,
561 ISL29035_REG_DEVICE_ID,
562 ISL29035_BOUT_MASK, 0);
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100563 if (status < 0)
564 return status;
565 }
566
Brian Masney19a00a92016-10-10 03:19:57 -0400567 /*
568 * Code added per Intersil Application Note 1534:
Grant Grundler176f9f22011-08-09 15:18:14 -0700569 * When VDD sinks to approximately 1.8V or below, some of
570 * the part's registers may change their state. When VDD
571 * recovers to 2.25V (or greater), the part may thus be in an
572 * unknown mode of operation. The user can return the part to
573 * a known mode of operation either by (a) setting VDD = 0V for
574 * 1 second or more and then powering back up with a slew rate
575 * of 0.5V/ms or greater, or (b) via I2C disable all ALS/PROX
576 * conversions, clear the test registers, and then rewrite all
577 * registers to the desired values.
578 * ...
Peter Meerwald-Stadler96273f432016-07-05 13:55:39 +0200579 * For ISL29011, ISL29018, ISL29021, ISL29023
Grant Grundler176f9f22011-08-09 15:18:14 -0700580 * 1. Write 0x00 to register 0x08 (TEST)
581 * 2. Write 0x00 to register 0x00 (CMD1)
582 * 3. Rewrite all registers to the desired values
583 *
584 * ISL29018 Data Sheet (FN6619.1, Feb 11, 2010) essentially says
585 * the same thing EXCEPT the data sheet asks for a 1ms delay after
586 * writing the CMD1 register.
587 */
Laxman Dewangan057340e2012-04-20 12:57:38 +0530588 status = regmap_write(chip->regmap, ISL29018_REG_TEST, 0x0);
Grant Grundler176f9f22011-08-09 15:18:14 -0700589 if (status < 0) {
Alison Schofield64670862016-02-22 12:34:32 -0800590 dev_err(dev, "Failed to clear isl29018 TEST reg.(%d)\n",
Roberta Dobrescuad3e6462014-09-25 20:09:09 +0300591 status);
Grant Grundler176f9f22011-08-09 15:18:14 -0700592 return status;
593 }
594
Brian Masney19a00a92016-10-10 03:19:57 -0400595 /*
596 * See Intersil AN1534 comments above.
Grant Grundler176f9f22011-08-09 15:18:14 -0700597 * "Operating Mode" (COMMAND1) register is reprogrammed when
598 * data is read from the device.
599 */
Laxman Dewangan057340e2012-04-20 12:57:38 +0530600 status = regmap_write(chip->regmap, ISL29018_REG_ADD_COMMAND1, 0);
Grant Grundler176f9f22011-08-09 15:18:14 -0700601 if (status < 0) {
Alison Schofield64670862016-02-22 12:34:32 -0800602 dev_err(dev, "Failed to clear isl29018 CMD1 reg.(%d)\n",
Roberta Dobrescuad3e6462014-09-25 20:09:09 +0300603 status);
Grant Grundler176f9f22011-08-09 15:18:14 -0700604 return status;
605 }
606
Vaishali Thakkar890d2282014-09-23 09:22:30 +0530607 usleep_range(1000, 2000); /* per data sheet, page 10 */
Grant Grundler176f9f22011-08-09 15:18:14 -0700608
Peter Meerwald-Stadler96273f432016-07-05 13:55:39 +0200609 /* Set defaults */
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300610 status = isl29018_set_scale(chip, chip->scale.scale,
611 chip->scale.uscale);
Rhyland Klein94042872010-10-07 15:48:09 -0700612 if (status < 0) {
Alison Schofield64670862016-02-22 12:34:32 -0800613 dev_err(dev, "Init of isl29018 fails\n");
Rhyland Klein94042872010-10-07 15:48:09 -0700614 return status;
615 }
616
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300617 status = isl29018_set_integration_time(chip,
618 isl29018_int_utimes[chip->type][chip->int_time]);
Brian Masneyaba1a8d2016-10-10 03:19:58 -0400619 if (status < 0)
Alison Schofield64670862016-02-22 12:34:32 -0800620 dev_err(dev, "Init of isl29018 fails\n");
Rhyland Klein94042872010-10-07 15:48:09 -0700621
Brian Masneyaba1a8d2016-10-10 03:19:58 -0400622 return status;
Rhyland Klein94042872010-10-07 15:48:09 -0700623}
624
Laurentiu Palcu5b4b5b92014-08-29 15:26:00 +0100625static const struct iio_info isl29018_info = {
626 .attrs = &isl29018_group,
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100627 .driver_module = THIS_MODULE,
Bhumika Goyal6d9b10c2016-02-12 20:40:27 +0530628 .read_raw = isl29018_read_raw,
629 .write_raw = isl29018_write_raw,
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100630};
631
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100632static const struct iio_info isl29023_info = {
633 .attrs = &isl29023_group,
634 .driver_module = THIS_MODULE,
Bhumika Goyal6d9b10c2016-02-12 20:40:27 +0530635 .read_raw = isl29018_read_raw,
636 .write_raw = isl29018_write_raw,
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100637};
638
Peter Meerwald-Stadler92193762016-07-05 13:55:40 +0200639static bool isl29018_is_volatile_reg(struct device *dev, unsigned int reg)
Laxman Dewangan057340e2012-04-20 12:57:38 +0530640{
641 switch (reg) {
642 case ISL29018_REG_ADD_DATA_LSB:
643 case ISL29018_REG_ADD_DATA_MSB:
644 case ISL29018_REG_ADD_COMMAND1:
645 case ISL29018_REG_TEST:
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100646 case ISL29035_REG_DEVICE_ID:
Laxman Dewangan057340e2012-04-20 12:57:38 +0530647 return true;
648 default:
649 return false;
650 }
651}
652
Laxman Dewangan057340e2012-04-20 12:57:38 +0530653static const struct regmap_config isl29018_regmap_config = {
654 .reg_bits = 8,
655 .val_bits = 8,
Peter Meerwald-Stadler92193762016-07-05 13:55:40 +0200656 .volatile_reg = isl29018_is_volatile_reg,
Laxman Dewangan057340e2012-04-20 12:57:38 +0530657 .max_register = ISL29018_REG_TEST,
658 .num_reg_defaults_raw = ISL29018_REG_TEST + 1,
659 .cache_type = REGCACHE_RBTREE,
660};
661
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100662static const struct regmap_config isl29035_regmap_config = {
663 .reg_bits = 8,
664 .val_bits = 8,
Peter Meerwald-Stadler92193762016-07-05 13:55:40 +0200665 .volatile_reg = isl29018_is_volatile_reg,
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100666 .max_register = ISL29035_REG_DEVICE_ID,
667 .num_reg_defaults_raw = ISL29035_REG_DEVICE_ID + 1,
668 .cache_type = REGCACHE_RBTREE,
669};
670
Peter Meerwald-Stadler92193762016-07-05 13:55:40 +0200671struct isl29018_chip_info {
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100672 const struct iio_chan_spec *channels;
673 int num_channels;
674 const struct iio_info *indio_info;
675 const struct regmap_config *regmap_cfg;
676};
677
Peter Meerwald-Stadler92193762016-07-05 13:55:40 +0200678static const struct isl29018_chip_info isl29018_chip_info_tbl[] = {
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100679 [isl29018] = {
680 .channels = isl29018_channels,
681 .num_channels = ARRAY_SIZE(isl29018_channels),
682 .indio_info = &isl29018_info,
683 .regmap_cfg = &isl29018_regmap_config,
684 },
685 [isl29023] = {
686 .channels = isl29023_channels,
687 .num_channels = ARRAY_SIZE(isl29023_channels),
688 .indio_info = &isl29023_info,
689 .regmap_cfg = &isl29018_regmap_config,
690 },
691 [isl29035] = {
692 .channels = isl29023_channels,
693 .num_channels = ARRAY_SIZE(isl29023_channels),
694 .indio_info = &isl29023_info,
695 .regmap_cfg = &isl29035_regmap_config,
696 },
697};
698
Laurentiu Palcudc4ecaf2014-01-09 10:20:00 +0000699static const char *isl29018_match_acpi_device(struct device *dev, int *data)
700{
701 const struct acpi_device_id *id;
702
703 id = acpi_match_device(dev->driver->acpi_match_table, dev);
704
705 if (!id)
706 return NULL;
707
Eva Rachel Retuya79783b32016-02-18 15:35:37 +0800708 *data = (int)id->driver_data;
Laurentiu Palcudc4ecaf2014-01-09 10:20:00 +0000709
710 return dev_name(dev);
711}
712
Bill Pemberton4ae1c612012-11-19 13:21:57 -0500713static int isl29018_probe(struct i2c_client *client,
Eva Rachel Retuyaca52c882016-02-18 15:35:36 +0800714 const struct i2c_device_id *id)
Rhyland Klein94042872010-10-07 15:48:09 -0700715{
716 struct isl29018_chip *chip;
Jonathan Cameron927afbe2011-06-27 13:07:57 +0100717 struct iio_dev *indio_dev;
Rhyland Klein94042872010-10-07 15:48:09 -0700718 int err;
Laurentiu Palcudc4ecaf2014-01-09 10:20:00 +0000719 const char *name = NULL;
720 int dev_id = 0;
Rhyland Klein94042872010-10-07 15:48:09 -0700721
Sachin Kamate434dcf2013-07-22 12:03:00 +0100722 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip));
Peter Meerwald-Stadlerab5b9492016-07-05 13:55:37 +0200723 if (!indio_dev)
Sachin Kamate434dcf2013-07-22 12:03:00 +0100724 return -ENOMEM;
Brian Masney744ef622016-10-10 03:19:55 -0400725
Jonathan Cameron927afbe2011-06-27 13:07:57 +0100726 chip = iio_priv(indio_dev);
Rhyland Klein94042872010-10-07 15:48:09 -0700727
Jonathan Cameron927afbe2011-06-27 13:07:57 +0100728 i2c_set_clientdata(client, indio_dev);
Rhyland Klein94042872010-10-07 15:48:09 -0700729
Laurentiu Palcudc4ecaf2014-01-09 10:20:00 +0000730 if (id) {
731 name = id->name;
732 dev_id = id->driver_data;
733 }
734
735 if (ACPI_HANDLE(&client->dev))
736 name = isl29018_match_acpi_device(&client->dev, &dev_id);
737
Rhyland Klein94042872010-10-07 15:48:09 -0700738 mutex_init(&chip->lock);
739
Laurentiu Palcudc4ecaf2014-01-09 10:20:00 +0000740 chip->type = dev_id;
Roberta Dobrescu809a5912015-04-16 22:20:58 +0300741 chip->calibscale = 1;
742 chip->ucalibscale = 0;
Roberta Dobrescu6920ccf2015-04-16 22:20:59 +0300743 chip->int_time = ISL29018_INT_TIME_16;
744 chip->scale = isl29018_scales[chip->int_time][0];
Bryan Freed1e45cf32012-10-25 00:39:00 +0100745 chip->suspended = false;
Rhyland Klein94042872010-10-07 15:48:09 -0700746
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100747 chip->regmap = devm_regmap_init_i2c(client,
Peter Meerwald-Stadler92193762016-07-05 13:55:40 +0200748 isl29018_chip_info_tbl[dev_id].regmap_cfg);
Laxman Dewangan057340e2012-04-20 12:57:38 +0530749 if (IS_ERR(chip->regmap)) {
750 err = PTR_ERR(chip->regmap);
Alison Schofield64670862016-02-22 12:34:32 -0800751 dev_err(&client->dev, "regmap initialization fails: %d\n", err);
Sachin Kamate434dcf2013-07-22 12:03:00 +0100752 return err;
Laxman Dewangan057340e2012-04-20 12:57:38 +0530753 }
754
755 err = isl29018_chip_init(chip);
Rhyland Klein94042872010-10-07 15:48:09 -0700756 if (err)
Sachin Kamate434dcf2013-07-22 12:03:00 +0100757 return err;
Rhyland Klein94042872010-10-07 15:48:09 -0700758
Peter Meerwald-Stadler92193762016-07-05 13:55:40 +0200759 indio_dev->info = isl29018_chip_info_tbl[dev_id].indio_info;
760 indio_dev->channels = isl29018_chip_info_tbl[dev_id].channels;
761 indio_dev->num_channels = isl29018_chip_info_tbl[dev_id].num_channels;
Laurentiu Palcudc4ecaf2014-01-09 10:20:00 +0000762 indio_dev->name = name;
Jonathan Cameron927afbe2011-06-27 13:07:57 +0100763 indio_dev->dev.parent = &client->dev;
764 indio_dev->modes = INDIO_DIRECT_MODE;
Brian Masney744ef622016-10-10 03:19:55 -0400765
Peter Meerwald-Stadlerab5b9492016-07-05 13:55:37 +0200766 return devm_iio_device_register(&client->dev, indio_dev);
Rhyland Klein94042872010-10-07 15:48:09 -0700767}
768
Bryan Freed1e45cf32012-10-25 00:39:00 +0100769#ifdef CONFIG_PM_SLEEP
770static int isl29018_suspend(struct device *dev)
771{
772 struct isl29018_chip *chip = iio_priv(dev_get_drvdata(dev));
773
774 mutex_lock(&chip->lock);
775
Brian Masney19a00a92016-10-10 03:19:57 -0400776 /*
777 * Since this driver uses only polling commands, we are by default in
Bryan Freed1e45cf32012-10-25 00:39:00 +0100778 * auto shutdown (ie, power-down) mode.
779 * So we do not have much to do here.
780 */
781 chip->suspended = true;
782
783 mutex_unlock(&chip->lock);
Brian Masney744ef622016-10-10 03:19:55 -0400784
Bryan Freed1e45cf32012-10-25 00:39:00 +0100785 return 0;
786}
787
788static int isl29018_resume(struct device *dev)
789{
790 struct isl29018_chip *chip = iio_priv(dev_get_drvdata(dev));
791 int err;
792
793 mutex_lock(&chip->lock);
794
795 err = isl29018_chip_init(chip);
796 if (!err)
797 chip->suspended = false;
798
799 mutex_unlock(&chip->lock);
Brian Masney744ef622016-10-10 03:19:55 -0400800
Bryan Freed1e45cf32012-10-25 00:39:00 +0100801 return err;
802}
803
804static SIMPLE_DEV_PM_OPS(isl29018_pm_ops, isl29018_suspend, isl29018_resume);
805#define ISL29018_PM_OPS (&isl29018_pm_ops)
806#else
807#define ISL29018_PM_OPS NULL
808#endif
809
Matthias Kaehlcke14b39dc2017-05-19 14:28:53 -0700810#ifdef CONFIG_ACPI
Laurentiu Palcudc4ecaf2014-01-09 10:20:00 +0000811static const struct acpi_device_id isl29018_acpi_match[] = {
812 {"ISL29018", isl29018},
813 {"ISL29023", isl29023},
814 {"ISL29035", isl29035},
815 {},
816};
817MODULE_DEVICE_TABLE(acpi, isl29018_acpi_match);
Matthias Kaehlcke14b39dc2017-05-19 14:28:53 -0700818#endif
Laurentiu Palcudc4ecaf2014-01-09 10:20:00 +0000819
Rhyland Klein94042872010-10-07 15:48:09 -0700820static const struct i2c_device_id isl29018_id[] = {
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100821 {"isl29018", isl29018},
822 {"isl29023", isl29023},
823 {"isl29035", isl29035},
Rhyland Klein94042872010-10-07 15:48:09 -0700824 {}
825};
Rhyland Klein94042872010-10-07 15:48:09 -0700826MODULE_DEVICE_TABLE(i2c, isl29018_id);
827
Olof Johansson4ee19522011-12-22 18:44:43 -0800828static const struct of_device_id isl29018_of_match[] = {
Laxman Dewangan610202d2012-04-24 11:41:38 +0530829 { .compatible = "isil,isl29018", },
Laurentiu Palcu609acef2014-08-29 15:26:00 +0100830 { .compatible = "isil,isl29023", },
831 { .compatible = "isil,isl29035", },
Olof Johansson4ee19522011-12-22 18:44:43 -0800832 { },
833};
834MODULE_DEVICE_TABLE(of, isl29018_of_match);
835
Rhyland Klein94042872010-10-07 15:48:09 -0700836static struct i2c_driver isl29018_driver = {
Rhyland Klein94042872010-10-07 15:48:09 -0700837 .driver = {
838 .name = "isl29018",
Laurentiu Palcudc4ecaf2014-01-09 10:20:00 +0000839 .acpi_match_table = ACPI_PTR(isl29018_acpi_match),
Bryan Freed1e45cf32012-10-25 00:39:00 +0100840 .pm = ISL29018_PM_OPS,
Olof Johansson4ee19522011-12-22 18:44:43 -0800841 .of_match_table = isl29018_of_match,
Rhyland Klein94042872010-10-07 15:48:09 -0700842 },
843 .probe = isl29018_probe,
Rhyland Klein94042872010-10-07 15:48:09 -0700844 .id_table = isl29018_id,
845};
Lars-Peter Clausen6e5af182011-11-16 10:13:38 +0100846module_i2c_driver(isl29018_driver);
Rhyland Klein94042872010-10-07 15:48:09 -0700847
848MODULE_DESCRIPTION("ISL29018 Ambient Light Sensor driver");
849MODULE_LICENSE("GPL");