Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 1 | /* |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 2 | * A iio driver for the light sensor ISL 29018/29023/29035. |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 3 | * |
| 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 Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 18 | */ |
| 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 Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 25 | #include <linux/regmap.h> |
Anson Huang | 1a02d12 | 2019-01-08 09:09:39 +0000 | [diff] [blame^] | 26 | #include <linux/regulator/consumer.h> |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 27 | #include <linux/slab.h> |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 28 | #include <linux/iio/iio.h> |
| 29 | #include <linux/iio/sysfs.h> |
Laurentiu Palcu | dc4ecaf | 2014-01-09 10:20:00 +0000 | [diff] [blame] | 30 | #include <linux/acpi.h> |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 31 | |
Peter Meerwald-Stadler | 13e6d63 | 2016-07-05 13:55:36 +0200 | [diff] [blame] | 32 | #define ISL29018_CONV_TIME_MS 100 |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 33 | |
| 34 | #define ISL29018_REG_ADD_COMMAND1 0x00 |
Peter Meerwald-Stadler | 13e6d63 | 2016-07-05 13:55:36 +0200 | [diff] [blame] | 35 | #define ISL29018_CMD1_OPMODE_SHIFT 5 |
| 36 | #define ISL29018_CMD1_OPMODE_MASK (7 << ISL29018_CMD1_OPMODE_SHIFT) |
| 37 | #define ISL29018_CMD1_OPMODE_POWER_DOWN 0 |
| 38 | #define ISL29018_CMD1_OPMODE_ALS_ONCE 1 |
| 39 | #define ISL29018_CMD1_OPMODE_IR_ONCE 2 |
| 40 | #define ISL29018_CMD1_OPMODE_PROX_ONCE 3 |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 41 | |
Peter Meerwald-Stadler | 13e6d63 | 2016-07-05 13:55:36 +0200 | [diff] [blame] | 42 | #define ISL29018_REG_ADD_COMMAND2 0x01 |
| 43 | #define ISL29018_CMD2_RESOLUTION_SHIFT 2 |
| 44 | #define ISL29018_CMD2_RESOLUTION_MASK (0x3 << ISL29018_CMD2_RESOLUTION_SHIFT) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 45 | |
Peter Meerwald-Stadler | 13e6d63 | 2016-07-05 13:55:36 +0200 | [diff] [blame] | 46 | #define ISL29018_CMD2_RANGE_SHIFT 0 |
| 47 | #define ISL29018_CMD2_RANGE_MASK (0x3 << ISL29018_CMD2_RANGE_SHIFT) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 48 | |
Peter Meerwald-Stadler | 13e6d63 | 2016-07-05 13:55:36 +0200 | [diff] [blame] | 49 | #define ISL29018_CMD2_SCHEME_SHIFT 7 |
| 50 | #define ISL29018_CMD2_SCHEME_MASK (0x1 << ISL29018_CMD2_SCHEME_SHIFT) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 51 | |
| 52 | #define ISL29018_REG_ADD_DATA_LSB 0x02 |
| 53 | #define ISL29018_REG_ADD_DATA_MSB 0x03 |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 54 | |
Grant Grundler | 176f9f2 | 2011-08-09 15:18:14 -0700 | [diff] [blame] | 55 | #define ISL29018_REG_TEST 0x08 |
| 56 | #define ISL29018_TEST_SHIFT 0 |
| 57 | #define ISL29018_TEST_MASK (0xFF << ISL29018_TEST_SHIFT) |
| 58 | |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 59 | #define ISL29035_REG_DEVICE_ID 0x0F |
| 60 | #define ISL29035_DEVICE_ID_SHIFT 0x03 |
| 61 | #define ISL29035_DEVICE_ID_MASK (0x7 << ISL29035_DEVICE_ID_SHIFT) |
| 62 | #define ISL29035_DEVICE_ID 0x5 |
| 63 | #define ISL29035_BOUT_SHIFT 0x07 |
| 64 | #define ISL29035_BOUT_MASK (0x01 << ISL29035_BOUT_SHIFT) |
| 65 | |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 66 | enum isl29018_int_time { |
| 67 | ISL29018_INT_TIME_16, |
| 68 | ISL29018_INT_TIME_12, |
| 69 | ISL29018_INT_TIME_8, |
| 70 | ISL29018_INT_TIME_4, |
| 71 | }; |
| 72 | |
| 73 | static const unsigned int isl29018_int_utimes[3][4] = { |
| 74 | {90000, 5630, 351, 21}, |
| 75 | {90000, 5600, 352, 22}, |
| 76 | {105000, 6500, 410, 25}, |
| 77 | }; |
| 78 | |
| 79 | static const struct isl29018_scale { |
| 80 | unsigned int scale; |
| 81 | unsigned int uscale; |
| 82 | } isl29018_scales[4][4] = { |
| 83 | { {0, 15258}, {0, 61035}, {0, 244140}, {0, 976562} }, |
| 84 | { {0, 244140}, {0, 976562}, {3, 906250}, {15, 625000} }, |
| 85 | { {3, 906250}, {15, 625000}, {62, 500000}, {250, 0} }, |
| 86 | { {62, 500000}, {250, 0}, {1000, 0}, {4000, 0} } |
| 87 | }; |
| 88 | |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 89 | struct isl29018_chip { |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 90 | struct regmap *regmap; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 91 | struct mutex lock; |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 92 | int type; |
Roberta Dobrescu | 809a591 | 2015-04-16 22:20:58 +0300 | [diff] [blame] | 93 | unsigned int calibscale; |
| 94 | unsigned int ucalibscale; |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 95 | unsigned int int_time; |
| 96 | struct isl29018_scale scale; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 97 | int prox_scheme; |
Bryan Freed | 1e45cf3 | 2012-10-25 00:39:00 +0100 | [diff] [blame] | 98 | bool suspended; |
Anson Huang | 1a02d12 | 2019-01-08 09:09:39 +0000 | [diff] [blame^] | 99 | struct regulator *vcc_reg; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 102 | static int isl29018_set_integration_time(struct isl29018_chip *chip, |
| 103 | unsigned int utime) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 104 | { |
Brian Masney | ea908ab | 2016-09-25 07:41:07 -0400 | [diff] [blame] | 105 | unsigned int i; |
| 106 | int ret; |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 107 | unsigned int int_time, new_int_time; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 108 | |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 109 | for (i = 0; i < ARRAY_SIZE(isl29018_int_utimes[chip->type]); ++i) { |
| 110 | if (utime == isl29018_int_utimes[chip->type][i]) { |
| 111 | new_int_time = i; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 112 | break; |
| 113 | } |
| 114 | } |
| 115 | |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 116 | if (i >= ARRAY_SIZE(isl29018_int_utimes[chip->type])) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 117 | return -EINVAL; |
| 118 | |
Peter Meerwald-Stadler | 13e6d63 | 2016-07-05 13:55:36 +0200 | [diff] [blame] | 119 | ret = regmap_update_bits(chip->regmap, ISL29018_REG_ADD_COMMAND2, |
| 120 | ISL29018_CMD2_RESOLUTION_MASK, |
| 121 | i << ISL29018_CMD2_RESOLUTION_SHIFT); |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 122 | if (ret < 0) |
| 123 | return ret; |
| 124 | |
Peter Meerwald-Stadler | 96273f43 | 2016-07-05 13:55:39 +0200 | [diff] [blame] | 125 | /* Keep the same range when integration time changes */ |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 126 | int_time = chip->int_time; |
| 127 | for (i = 0; i < ARRAY_SIZE(isl29018_scales[int_time]); ++i) { |
| 128 | if (chip->scale.scale == isl29018_scales[int_time][i].scale && |
| 129 | chip->scale.uscale == isl29018_scales[int_time][i].uscale) { |
| 130 | chip->scale = isl29018_scales[new_int_time][i]; |
| 131 | break; |
| 132 | } |
| 133 | } |
| 134 | chip->int_time = new_int_time; |
| 135 | |
| 136 | return 0; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 139 | static int isl29018_set_scale(struct isl29018_chip *chip, int scale, int uscale) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 140 | { |
Brian Masney | ea908ab | 2016-09-25 07:41:07 -0400 | [diff] [blame] | 141 | unsigned int i; |
| 142 | int ret; |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 143 | struct isl29018_scale new_scale; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 144 | |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 145 | for (i = 0; i < ARRAY_SIZE(isl29018_scales[chip->int_time]); ++i) { |
| 146 | if (scale == isl29018_scales[chip->int_time][i].scale && |
| 147 | uscale == isl29018_scales[chip->int_time][i].uscale) { |
| 148 | new_scale = isl29018_scales[chip->int_time][i]; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 149 | break; |
| 150 | } |
| 151 | } |
| 152 | |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 153 | if (i >= ARRAY_SIZE(isl29018_scales[chip->int_time])) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 154 | return -EINVAL; |
| 155 | |
Peter Meerwald-Stadler | 13e6d63 | 2016-07-05 13:55:36 +0200 | [diff] [blame] | 156 | ret = regmap_update_bits(chip->regmap, ISL29018_REG_ADD_COMMAND2, |
| 157 | ISL29018_CMD2_RANGE_MASK, |
| 158 | i << ISL29018_CMD2_RANGE_SHIFT); |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 159 | if (ret < 0) |
| 160 | return ret; |
| 161 | |
| 162 | chip->scale = new_scale; |
| 163 | |
| 164 | return 0; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 167 | static int isl29018_read_sensor_input(struct isl29018_chip *chip, int mode) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 168 | { |
| 169 | int status; |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 170 | unsigned int lsb; |
| 171 | unsigned int msb; |
Alison Schofield | 6467086 | 2016-02-22 12:34:32 -0800 | [diff] [blame] | 172 | struct device *dev = regmap_get_device(chip->regmap); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 173 | |
| 174 | /* Set mode */ |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 175 | status = regmap_write(chip->regmap, ISL29018_REG_ADD_COMMAND1, |
Peter Meerwald-Stadler | 13e6d63 | 2016-07-05 13:55:36 +0200 | [diff] [blame] | 176 | mode << ISL29018_CMD1_OPMODE_SHIFT); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 177 | if (status) { |
Alison Schofield | 6467086 | 2016-02-22 12:34:32 -0800 | [diff] [blame] | 178 | dev_err(dev, |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 179 | "Error in setting operating mode err %d\n", status); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 180 | return status; |
| 181 | } |
Peter Meerwald-Stadler | 13e6d63 | 2016-07-05 13:55:36 +0200 | [diff] [blame] | 182 | msleep(ISL29018_CONV_TIME_MS); |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 183 | status = regmap_read(chip->regmap, ISL29018_REG_ADD_DATA_LSB, &lsb); |
| 184 | if (status < 0) { |
Alison Schofield | 6467086 | 2016-02-22 12:34:32 -0800 | [diff] [blame] | 185 | dev_err(dev, |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 186 | "Error in reading LSB DATA with err %d\n", status); |
| 187 | return status; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 190 | status = regmap_read(chip->regmap, ISL29018_REG_ADD_DATA_MSB, &msb); |
| 191 | if (status < 0) { |
Alison Schofield | 6467086 | 2016-02-22 12:34:32 -0800 | [diff] [blame] | 192 | dev_err(dev, |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 193 | "Error in reading MSB DATA with error %d\n", status); |
| 194 | return status; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 195 | } |
Alison Schofield | 6467086 | 2016-02-22 12:34:32 -0800 | [diff] [blame] | 196 | dev_vdbg(dev, "MSB 0x%x and LSB 0x%x\n", msb, lsb); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 197 | |
| 198 | return (msb << 8) | lsb; |
| 199 | } |
| 200 | |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 201 | static int isl29018_read_lux(struct isl29018_chip *chip, int *lux) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 202 | { |
| 203 | int lux_data; |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 204 | unsigned int data_x_range; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 205 | |
Peter Meerwald-Stadler | 13e6d63 | 2016-07-05 13:55:36 +0200 | [diff] [blame] | 206 | lux_data = isl29018_read_sensor_input(chip, |
| 207 | ISL29018_CMD1_OPMODE_ALS_ONCE); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 208 | if (lux_data < 0) |
| 209 | return lux_data; |
| 210 | |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 211 | data_x_range = lux_data * chip->scale.scale + |
| 212 | lux_data * chip->scale.uscale / 1000000; |
| 213 | *lux = data_x_range * chip->calibscale + |
| 214 | data_x_range * chip->ucalibscale / 1000000; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 219 | static int isl29018_read_ir(struct isl29018_chip *chip, int *ir) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 220 | { |
| 221 | int ir_data; |
| 222 | |
Peter Meerwald-Stadler | 13e6d63 | 2016-07-05 13:55:36 +0200 | [diff] [blame] | 223 | ir_data = isl29018_read_sensor_input(chip, |
| 224 | ISL29018_CMD1_OPMODE_IR_ONCE); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 225 | if (ir_data < 0) |
| 226 | return ir_data; |
| 227 | |
| 228 | *ir = ir_data; |
| 229 | |
| 230 | return 0; |
| 231 | } |
| 232 | |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 233 | static int isl29018_read_proximity_ir(struct isl29018_chip *chip, int scheme, |
Eva Rachel Retuya | ca52c88 | 2016-02-18 15:35:36 +0800 | [diff] [blame] | 234 | int *near_ir) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 235 | { |
| 236 | int status; |
| 237 | int prox_data = -1; |
| 238 | int ir_data = -1; |
Alison Schofield | 6467086 | 2016-02-22 12:34:32 -0800 | [diff] [blame] | 239 | struct device *dev = regmap_get_device(chip->regmap); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 240 | |
| 241 | /* Do proximity sensing with required scheme */ |
Peter Meerwald-Stadler | 13e6d63 | 2016-07-05 13:55:36 +0200 | [diff] [blame] | 242 | status = regmap_update_bits(chip->regmap, ISL29018_REG_ADD_COMMAND2, |
| 243 | ISL29018_CMD2_SCHEME_MASK, |
| 244 | scheme << ISL29018_CMD2_SCHEME_SHIFT); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 245 | if (status) { |
Alison Schofield | 6467086 | 2016-02-22 12:34:32 -0800 | [diff] [blame] | 246 | dev_err(dev, "Error in setting operating mode\n"); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 247 | return status; |
| 248 | } |
| 249 | |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 250 | prox_data = isl29018_read_sensor_input(chip, |
Peter Meerwald-Stadler | 13e6d63 | 2016-07-05 13:55:36 +0200 | [diff] [blame] | 251 | ISL29018_CMD1_OPMODE_PROX_ONCE); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 252 | if (prox_data < 0) |
| 253 | return prox_data; |
| 254 | |
| 255 | if (scheme == 1) { |
| 256 | *near_ir = prox_data; |
| 257 | return 0; |
| 258 | } |
| 259 | |
Peter Meerwald-Stadler | 13e6d63 | 2016-07-05 13:55:36 +0200 | [diff] [blame] | 260 | ir_data = isl29018_read_sensor_input(chip, |
| 261 | ISL29018_CMD1_OPMODE_IR_ONCE); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 262 | if (ir_data < 0) |
| 263 | return ir_data; |
| 264 | |
| 265 | if (prox_data >= ir_data) |
| 266 | *near_ir = prox_data - ir_data; |
| 267 | else |
| 268 | *near_ir = 0; |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
Brian Masney | 0281996 | 2016-09-26 20:20:17 -0400 | [diff] [blame] | 273 | static ssize_t in_illuminance_scale_available_show |
| 274 | (struct device *dev, struct device_attribute *attr, |
| 275 | char *buf) |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 276 | { |
| 277 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
| 278 | struct isl29018_chip *chip = iio_priv(indio_dev); |
Brian Masney | ea908ab | 2016-09-25 07:41:07 -0400 | [diff] [blame] | 279 | unsigned int i; |
| 280 | int len = 0; |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 281 | |
Brian Masney | 5faf98c | 2016-09-26 20:20:18 -0400 | [diff] [blame] | 282 | mutex_lock(&chip->lock); |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 283 | for (i = 0; i < ARRAY_SIZE(isl29018_scales[chip->int_time]); ++i) |
| 284 | len += sprintf(buf + len, "%d.%06d ", |
| 285 | isl29018_scales[chip->int_time][i].scale, |
| 286 | isl29018_scales[chip->int_time][i].uscale); |
Brian Masney | 5faf98c | 2016-09-26 20:20:18 -0400 | [diff] [blame] | 287 | mutex_unlock(&chip->lock); |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 288 | |
| 289 | buf[len - 1] = '\n'; |
| 290 | |
| 291 | return len; |
| 292 | } |
| 293 | |
Brian Masney | 0281996 | 2016-09-26 20:20:17 -0400 | [diff] [blame] | 294 | static ssize_t in_illuminance_integration_time_available_show |
| 295 | (struct device *dev, struct device_attribute *attr, |
| 296 | char *buf) |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 297 | { |
| 298 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
| 299 | struct isl29018_chip *chip = iio_priv(indio_dev); |
Brian Masney | ea908ab | 2016-09-25 07:41:07 -0400 | [diff] [blame] | 300 | unsigned int i; |
| 301 | int len = 0; |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 302 | |
| 303 | for (i = 0; i < ARRAY_SIZE(isl29018_int_utimes[chip->type]); ++i) |
| 304 | len += sprintf(buf + len, "0.%06d ", |
| 305 | isl29018_int_utimes[chip->type][i]); |
| 306 | |
| 307 | buf[len - 1] = '\n'; |
| 308 | |
| 309 | return len; |
| 310 | } |
| 311 | |
Brian Masney | e748e28 | 2016-10-06 20:48:34 -0400 | [diff] [blame] | 312 | /* |
| 313 | * From ISL29018 Data Sheet (FN6619.4, Oct 8, 2012) regarding the |
| 314 | * infrared suppression: |
| 315 | * |
| 316 | * Proximity Sensing Scheme: Bit 7. This bit programs the function |
| 317 | * of the proximity detection. Logic 0 of this bit, Scheme 0, makes |
| 318 | * full n (4, 8, 12, 16) bits (unsigned) proximity detection. The range |
| 319 | * of Scheme 0 proximity count is from 0 to 2^n. Logic 1 of this bit, |
| 320 | * Scheme 1, makes n-1 (3, 7, 11, 15) bits (2's complementary) |
| 321 | * proximity_less_ambient detection. The range of Scheme 1 |
| 322 | * proximity count is from -2^(n-1) to 2^(n-1) . The sign bit is extended |
| 323 | * for resolutions less than 16. While Scheme 0 has wider dynamic |
| 324 | * range, Scheme 1 proximity detection is less affected by the |
| 325 | * ambient IR noise variation. |
| 326 | * |
| 327 | * 0 Sensing IR from LED and ambient |
| 328 | * 1 Sensing IR from LED with ambient IR rejection |
| 329 | */ |
Brian Masney | 0281996 | 2016-09-26 20:20:17 -0400 | [diff] [blame] | 330 | static ssize_t proximity_on_chip_ambient_infrared_suppression_show |
| 331 | (struct device *dev, struct device_attribute *attr, |
| 332 | char *buf) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 333 | { |
Lars-Peter Clausen | 96f691f | 2012-05-12 15:39:51 +0200 | [diff] [blame] | 334 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
Jonathan Cameron | 927afbe | 2011-06-27 13:07:57 +0100 | [diff] [blame] | 335 | struct isl29018_chip *chip = iio_priv(indio_dev); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 336 | |
Eva Rachel Retuya | 7f3829a | 2016-02-18 15:35:38 +0800 | [diff] [blame] | 337 | /* |
Peter Meerwald-Stadler | 96273f43 | 2016-07-05 13:55:39 +0200 | [diff] [blame] | 338 | * Return the "proximity scheme" i.e. if the chip does on chip |
Eva Rachel Retuya | 7f3829a | 2016-02-18 15:35:38 +0800 | [diff] [blame] | 339 | * infrared suppression (1 means perform on chip suppression) |
| 340 | */ |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 341 | return sprintf(buf, "%d\n", chip->prox_scheme); |
| 342 | } |
| 343 | |
Brian Masney | 0281996 | 2016-09-26 20:20:17 -0400 | [diff] [blame] | 344 | static ssize_t proximity_on_chip_ambient_infrared_suppression_store |
| 345 | (struct device *dev, struct device_attribute *attr, |
| 346 | const char *buf, size_t count) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 347 | { |
Lars-Peter Clausen | 96f691f | 2012-05-12 15:39:51 +0200 | [diff] [blame] | 348 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
Jonathan Cameron | 927afbe | 2011-06-27 13:07:57 +0100 | [diff] [blame] | 349 | struct isl29018_chip *chip = iio_priv(indio_dev); |
Jingoo Han | e5e26dd | 2013-08-20 03:31:00 +0100 | [diff] [blame] | 350 | int val; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 351 | |
Jingoo Han | e5e26dd | 2013-08-20 03:31:00 +0100 | [diff] [blame] | 352 | if (kstrtoint(buf, 10, &val)) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 353 | return -EINVAL; |
Peter Meerwald-Stadler | ab5b949 | 2016-07-05 13:55:37 +0200 | [diff] [blame] | 354 | if (!(val == 0 || val == 1)) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 355 | return -EINVAL; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 356 | |
Eva Rachel Retuya | 7f3829a | 2016-02-18 15:35:38 +0800 | [diff] [blame] | 357 | /* |
Peter Meerwald-Stadler | 96273f43 | 2016-07-05 13:55:39 +0200 | [diff] [blame] | 358 | * Get the "proximity scheme" i.e. if the chip does on chip |
Eva Rachel Retuya | 7f3829a | 2016-02-18 15:35:38 +0800 | [diff] [blame] | 359 | * infrared suppression (1 means perform on chip suppression) |
| 360 | */ |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 361 | mutex_lock(&chip->lock); |
Jingoo Han | e5e26dd | 2013-08-20 03:31:00 +0100 | [diff] [blame] | 362 | chip->prox_scheme = val; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 363 | mutex_unlock(&chip->lock); |
| 364 | |
| 365 | return count; |
| 366 | } |
| 367 | |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 368 | static int isl29018_write_raw(struct iio_dev *indio_dev, |
| 369 | struct iio_chan_spec const *chan, |
| 370 | int val, |
| 371 | int val2, |
| 372 | long mask) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 373 | { |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 374 | struct isl29018_chip *chip = iio_priv(indio_dev); |
| 375 | int ret = -EINVAL; |
| 376 | |
| 377 | mutex_lock(&chip->lock); |
Brian Masney | 0005356 | 2016-09-26 20:20:20 -0400 | [diff] [blame] | 378 | if (chip->suspended) { |
| 379 | ret = -EBUSY; |
| 380 | goto write_done; |
| 381 | } |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 382 | switch (mask) { |
| 383 | case IIO_CHAN_INFO_CALIBSCALE: |
| 384 | if (chan->type == IIO_LIGHT) { |
| 385 | chip->calibscale = val; |
| 386 | chip->ucalibscale = val2; |
| 387 | ret = 0; |
| 388 | } |
| 389 | break; |
| 390 | case IIO_CHAN_INFO_INT_TIME: |
Brian Masney | 528021f | 2016-09-25 07:41:06 -0400 | [diff] [blame] | 391 | if (chan->type == IIO_LIGHT && !val) |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 392 | ret = isl29018_set_integration_time(chip, val2); |
| 393 | break; |
| 394 | case IIO_CHAN_INFO_SCALE: |
| 395 | if (chan->type == IIO_LIGHT) |
| 396 | ret = isl29018_set_scale(chip, val, val2); |
| 397 | break; |
| 398 | default: |
| 399 | break; |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 400 | } |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 401 | |
Brian Masney | 0005356 | 2016-09-26 20:20:20 -0400 | [diff] [blame] | 402 | write_done: |
| 403 | mutex_unlock(&chip->lock); |
Brian Masney | 744ef62 | 2016-10-10 03:19:55 -0400 | [diff] [blame] | 404 | |
Wei Yongjun | 6dc973d | 2012-11-08 09:05:00 +0000 | [diff] [blame] | 405 | return ret; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 408 | static int isl29018_read_raw(struct iio_dev *indio_dev, |
| 409 | struct iio_chan_spec const *chan, |
| 410 | int *val, |
| 411 | int *val2, |
| 412 | long mask) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 413 | { |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 414 | int ret = -EINVAL; |
| 415 | struct isl29018_chip *chip = iio_priv(indio_dev); |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 416 | |
| 417 | mutex_lock(&chip->lock); |
Bryan Freed | 1e45cf3 | 2012-10-25 00:39:00 +0100 | [diff] [blame] | 418 | if (chip->suspended) { |
Brian Masney | 5611cd6 | 2016-09-26 20:20:19 -0400 | [diff] [blame] | 419 | ret = -EBUSY; |
| 420 | goto read_done; |
Bryan Freed | 1e45cf3 | 2012-10-25 00:39:00 +0100 | [diff] [blame] | 421 | } |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 422 | switch (mask) { |
Jonathan Cameron | 90354d0 | 2012-04-15 17:41:22 +0100 | [diff] [blame] | 423 | case IIO_CHAN_INFO_RAW: |
| 424 | case IIO_CHAN_INFO_PROCESSED: |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 425 | switch (chan->type) { |
| 426 | case IIO_LIGHT: |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 427 | ret = isl29018_read_lux(chip, val); |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 428 | break; |
| 429 | case IIO_INTENSITY: |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 430 | ret = isl29018_read_ir(chip, val); |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 431 | break; |
| 432 | case IIO_PROXIMITY: |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 433 | ret = isl29018_read_proximity_ir(chip, |
Eva Rachel Retuya | ca52c88 | 2016-02-18 15:35:36 +0800 | [diff] [blame] | 434 | chip->prox_scheme, |
| 435 | val); |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 436 | break; |
| 437 | default: |
| 438 | break; |
| 439 | } |
| 440 | if (!ret) |
| 441 | ret = IIO_VAL_INT; |
| 442 | break; |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 443 | case IIO_CHAN_INFO_INT_TIME: |
| 444 | if (chan->type == IIO_LIGHT) { |
| 445 | *val = 0; |
| 446 | *val2 = isl29018_int_utimes[chip->type][chip->int_time]; |
| 447 | ret = IIO_VAL_INT_PLUS_MICRO; |
| 448 | } |
| 449 | break; |
| 450 | case IIO_CHAN_INFO_SCALE: |
| 451 | if (chan->type == IIO_LIGHT) { |
| 452 | *val = chip->scale.scale; |
| 453 | *val2 = chip->scale.uscale; |
| 454 | ret = IIO_VAL_INT_PLUS_MICRO; |
| 455 | } |
| 456 | break; |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 457 | case IIO_CHAN_INFO_CALIBSCALE: |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 458 | if (chan->type == IIO_LIGHT) { |
Roberta Dobrescu | 809a591 | 2015-04-16 22:20:58 +0300 | [diff] [blame] | 459 | *val = chip->calibscale; |
| 460 | *val2 = chip->ucalibscale; |
Bryan Freed | 932323b | 2012-09-05 20:55:00 +0100 | [diff] [blame] | 461 | ret = IIO_VAL_INT_PLUS_MICRO; |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 462 | } |
| 463 | break; |
| 464 | default: |
| 465 | break; |
| 466 | } |
Brian Masney | 5611cd6 | 2016-09-26 20:20:19 -0400 | [diff] [blame] | 467 | |
| 468 | read_done: |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 469 | mutex_unlock(&chip->lock); |
Brian Masney | 744ef62 | 2016-10-10 03:19:55 -0400 | [diff] [blame] | 470 | |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 471 | return ret; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 474 | #define ISL29018_LIGHT_CHANNEL { \ |
| 475 | .type = IIO_LIGHT, \ |
| 476 | .indexed = 1, \ |
| 477 | .channel = 0, \ |
| 478 | .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | \ |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 479 | BIT(IIO_CHAN_INFO_CALIBSCALE) | \ |
| 480 | BIT(IIO_CHAN_INFO_SCALE) | \ |
| 481 | BIT(IIO_CHAN_INFO_INT_TIME), \ |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | #define ISL29018_IR_CHANNEL { \ |
| 485 | .type = IIO_INTENSITY, \ |
| 486 | .modified = 1, \ |
| 487 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ |
| 488 | .channel2 = IIO_MOD_LIGHT_IR, \ |
| 489 | } |
| 490 | |
| 491 | #define ISL29018_PROXIMITY_CHANNEL { \ |
| 492 | .type = IIO_PROXIMITY, \ |
| 493 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ |
| 494 | } |
| 495 | |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 496 | static const struct iio_chan_spec isl29018_channels[] = { |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 497 | ISL29018_LIGHT_CHANNEL, |
| 498 | ISL29018_IR_CHANNEL, |
| 499 | ISL29018_PROXIMITY_CHANNEL, |
| 500 | }; |
| 501 | |
| 502 | static const struct iio_chan_spec isl29023_channels[] = { |
| 503 | ISL29018_LIGHT_CHANNEL, |
| 504 | ISL29018_IR_CHANNEL, |
Bryan Freed | 01e57c5 | 2011-07-07 12:01:56 -0700 | [diff] [blame] | 505 | }; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 506 | |
Brian Masney | 0281996 | 2016-09-26 20:20:17 -0400 | [diff] [blame] | 507 | static IIO_DEVICE_ATTR_RO(in_illuminance_integration_time_available, 0); |
| 508 | static IIO_DEVICE_ATTR_RO(in_illuminance_scale_available, 0); |
| 509 | static IIO_DEVICE_ATTR_RW(proximity_on_chip_ambient_infrared_suppression, 0); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 510 | |
| 511 | #define ISL29018_DEV_ATTR(name) (&iio_dev_attr_##name.dev_attr.attr) |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 512 | |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 513 | static struct attribute *isl29018_attributes[] = { |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 514 | ISL29018_DEV_ATTR(in_illuminance_scale_available), |
| 515 | ISL29018_DEV_ATTR(in_illuminance_integration_time_available), |
Peter Meerwald | 2a1d45e | 2012-06-18 20:33:07 +0200 | [diff] [blame] | 516 | ISL29018_DEV_ATTR(proximity_on_chip_ambient_infrared_suppression), |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 517 | NULL |
| 518 | }; |
| 519 | |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 520 | static struct attribute *isl29023_attributes[] = { |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 521 | ISL29018_DEV_ATTR(in_illuminance_scale_available), |
| 522 | ISL29018_DEV_ATTR(in_illuminance_integration_time_available), |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 523 | NULL |
| 524 | }; |
| 525 | |
Laurentiu Palcu | 5b4b5b9 | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 526 | static const struct attribute_group isl29018_group = { |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 527 | .attrs = isl29018_attributes, |
| 528 | }; |
| 529 | |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 530 | static const struct attribute_group isl29023_group = { |
| 531 | .attrs = isl29023_attributes, |
| 532 | }; |
| 533 | |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 534 | enum { |
| 535 | isl29018, |
| 536 | isl29023, |
| 537 | isl29035, |
| 538 | }; |
| 539 | |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 540 | static int isl29018_chip_init(struct isl29018_chip *chip) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 541 | { |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 542 | int status; |
Alison Schofield | 6467086 | 2016-02-22 12:34:32 -0800 | [diff] [blame] | 543 | struct device *dev = regmap_get_device(chip->regmap); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 544 | |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 545 | if (chip->type == isl29035) { |
Brian Masney | 8281101 | 2016-10-10 03:19:56 -0400 | [diff] [blame] | 546 | unsigned int id; |
| 547 | |
| 548 | status = regmap_read(chip->regmap, ISL29035_REG_DEVICE_ID, &id); |
| 549 | if (status < 0) { |
| 550 | dev_err(dev, |
| 551 | "Error reading ID register with error %d\n", |
| 552 | status); |
| 553 | return status; |
| 554 | } |
| 555 | |
| 556 | id = (id & ISL29035_DEVICE_ID_MASK) >> ISL29035_DEVICE_ID_SHIFT; |
| 557 | |
| 558 | if (id != ISL29035_DEVICE_ID) |
| 559 | return -ENODEV; |
| 560 | |
| 561 | /* Clear brownout bit */ |
| 562 | status = regmap_update_bits(chip->regmap, |
| 563 | ISL29035_REG_DEVICE_ID, |
| 564 | ISL29035_BOUT_MASK, 0); |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 565 | if (status < 0) |
| 566 | return status; |
| 567 | } |
| 568 | |
Brian Masney | 19a00a9 | 2016-10-10 03:19:57 -0400 | [diff] [blame] | 569 | /* |
| 570 | * Code added per Intersil Application Note 1534: |
Grant Grundler | 176f9f2 | 2011-08-09 15:18:14 -0700 | [diff] [blame] | 571 | * When VDD sinks to approximately 1.8V or below, some of |
| 572 | * the part's registers may change their state. When VDD |
| 573 | * recovers to 2.25V (or greater), the part may thus be in an |
| 574 | * unknown mode of operation. The user can return the part to |
| 575 | * a known mode of operation either by (a) setting VDD = 0V for |
| 576 | * 1 second or more and then powering back up with a slew rate |
| 577 | * of 0.5V/ms or greater, or (b) via I2C disable all ALS/PROX |
| 578 | * conversions, clear the test registers, and then rewrite all |
| 579 | * registers to the desired values. |
| 580 | * ... |
Peter Meerwald-Stadler | 96273f43 | 2016-07-05 13:55:39 +0200 | [diff] [blame] | 581 | * For ISL29011, ISL29018, ISL29021, ISL29023 |
Grant Grundler | 176f9f2 | 2011-08-09 15:18:14 -0700 | [diff] [blame] | 582 | * 1. Write 0x00 to register 0x08 (TEST) |
| 583 | * 2. Write 0x00 to register 0x00 (CMD1) |
| 584 | * 3. Rewrite all registers to the desired values |
| 585 | * |
| 586 | * ISL29018 Data Sheet (FN6619.1, Feb 11, 2010) essentially says |
| 587 | * the same thing EXCEPT the data sheet asks for a 1ms delay after |
| 588 | * writing the CMD1 register. |
| 589 | */ |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 590 | status = regmap_write(chip->regmap, ISL29018_REG_TEST, 0x0); |
Grant Grundler | 176f9f2 | 2011-08-09 15:18:14 -0700 | [diff] [blame] | 591 | if (status < 0) { |
Alison Schofield | 6467086 | 2016-02-22 12:34:32 -0800 | [diff] [blame] | 592 | dev_err(dev, "Failed to clear isl29018 TEST reg.(%d)\n", |
Roberta Dobrescu | ad3e646 | 2014-09-25 20:09:09 +0300 | [diff] [blame] | 593 | status); |
Grant Grundler | 176f9f2 | 2011-08-09 15:18:14 -0700 | [diff] [blame] | 594 | return status; |
| 595 | } |
| 596 | |
Brian Masney | 19a00a9 | 2016-10-10 03:19:57 -0400 | [diff] [blame] | 597 | /* |
| 598 | * See Intersil AN1534 comments above. |
Grant Grundler | 176f9f2 | 2011-08-09 15:18:14 -0700 | [diff] [blame] | 599 | * "Operating Mode" (COMMAND1) register is reprogrammed when |
| 600 | * data is read from the device. |
| 601 | */ |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 602 | status = regmap_write(chip->regmap, ISL29018_REG_ADD_COMMAND1, 0); |
Grant Grundler | 176f9f2 | 2011-08-09 15:18:14 -0700 | [diff] [blame] | 603 | if (status < 0) { |
Alison Schofield | 6467086 | 2016-02-22 12:34:32 -0800 | [diff] [blame] | 604 | dev_err(dev, "Failed to clear isl29018 CMD1 reg.(%d)\n", |
Roberta Dobrescu | ad3e646 | 2014-09-25 20:09:09 +0300 | [diff] [blame] | 605 | status); |
Grant Grundler | 176f9f2 | 2011-08-09 15:18:14 -0700 | [diff] [blame] | 606 | return status; |
| 607 | } |
| 608 | |
Vaishali Thakkar | 890d228 | 2014-09-23 09:22:30 +0530 | [diff] [blame] | 609 | usleep_range(1000, 2000); /* per data sheet, page 10 */ |
Grant Grundler | 176f9f2 | 2011-08-09 15:18:14 -0700 | [diff] [blame] | 610 | |
Peter Meerwald-Stadler | 96273f43 | 2016-07-05 13:55:39 +0200 | [diff] [blame] | 611 | /* Set defaults */ |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 612 | status = isl29018_set_scale(chip, chip->scale.scale, |
| 613 | chip->scale.uscale); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 614 | if (status < 0) { |
Alison Schofield | 6467086 | 2016-02-22 12:34:32 -0800 | [diff] [blame] | 615 | dev_err(dev, "Init of isl29018 fails\n"); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 616 | return status; |
| 617 | } |
| 618 | |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 619 | status = isl29018_set_integration_time(chip, |
| 620 | isl29018_int_utimes[chip->type][chip->int_time]); |
Brian Masney | aba1a8d | 2016-10-10 03:19:58 -0400 | [diff] [blame] | 621 | if (status < 0) |
Alison Schofield | 6467086 | 2016-02-22 12:34:32 -0800 | [diff] [blame] | 622 | dev_err(dev, "Init of isl29018 fails\n"); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 623 | |
Brian Masney | aba1a8d | 2016-10-10 03:19:58 -0400 | [diff] [blame] | 624 | return status; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 625 | } |
| 626 | |
Laurentiu Palcu | 5b4b5b9 | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 627 | static const struct iio_info isl29018_info = { |
| 628 | .attrs = &isl29018_group, |
Bhumika Goyal | 6d9b10c | 2016-02-12 20:40:27 +0530 | [diff] [blame] | 629 | .read_raw = isl29018_read_raw, |
| 630 | .write_raw = isl29018_write_raw, |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 631 | }; |
| 632 | |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 633 | static const struct iio_info isl29023_info = { |
| 634 | .attrs = &isl29023_group, |
Bhumika Goyal | 6d9b10c | 2016-02-12 20:40:27 +0530 | [diff] [blame] | 635 | .read_raw = isl29018_read_raw, |
| 636 | .write_raw = isl29018_write_raw, |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 637 | }; |
| 638 | |
Peter Meerwald-Stadler | 9219376 | 2016-07-05 13:55:40 +0200 | [diff] [blame] | 639 | static bool isl29018_is_volatile_reg(struct device *dev, unsigned int reg) |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 640 | { |
| 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 Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 646 | case ISL29035_REG_DEVICE_ID: |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 647 | return true; |
| 648 | default: |
| 649 | return false; |
| 650 | } |
| 651 | } |
| 652 | |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 653 | static const struct regmap_config isl29018_regmap_config = { |
| 654 | .reg_bits = 8, |
| 655 | .val_bits = 8, |
Peter Meerwald-Stadler | 9219376 | 2016-07-05 13:55:40 +0200 | [diff] [blame] | 656 | .volatile_reg = isl29018_is_volatile_reg, |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 657 | .max_register = ISL29018_REG_TEST, |
| 658 | .num_reg_defaults_raw = ISL29018_REG_TEST + 1, |
| 659 | .cache_type = REGCACHE_RBTREE, |
| 660 | }; |
| 661 | |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 662 | static const struct regmap_config isl29035_regmap_config = { |
| 663 | .reg_bits = 8, |
| 664 | .val_bits = 8, |
Peter Meerwald-Stadler | 9219376 | 2016-07-05 13:55:40 +0200 | [diff] [blame] | 665 | .volatile_reg = isl29018_is_volatile_reg, |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 666 | .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-Stadler | 9219376 | 2016-07-05 13:55:40 +0200 | [diff] [blame] | 671 | struct isl29018_chip_info { |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 672 | 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-Stadler | 9219376 | 2016-07-05 13:55:40 +0200 | [diff] [blame] | 678 | static const struct isl29018_chip_info isl29018_chip_info_tbl[] = { |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 679 | [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 Palcu | dc4ecaf | 2014-01-09 10:20:00 +0000 | [diff] [blame] | 699 | static 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 Retuya | 79783b3 | 2016-02-18 15:35:37 +0800 | [diff] [blame] | 708 | *data = (int)id->driver_data; |
Laurentiu Palcu | dc4ecaf | 2014-01-09 10:20:00 +0000 | [diff] [blame] | 709 | |
| 710 | return dev_name(dev); |
| 711 | } |
| 712 | |
Anson Huang | 1a02d12 | 2019-01-08 09:09:39 +0000 | [diff] [blame^] | 713 | static void isl29018_disable_regulator_action(void *_data) |
| 714 | { |
| 715 | struct isl29018_chip *chip = _data; |
| 716 | int err; |
| 717 | |
| 718 | err = regulator_disable(chip->vcc_reg); |
| 719 | if (err) |
| 720 | pr_err("failed to disable isl29018's VCC regulator!\n"); |
| 721 | } |
| 722 | |
Bill Pemberton | 4ae1c61 | 2012-11-19 13:21:57 -0500 | [diff] [blame] | 723 | static int isl29018_probe(struct i2c_client *client, |
Eva Rachel Retuya | ca52c88 | 2016-02-18 15:35:36 +0800 | [diff] [blame] | 724 | const struct i2c_device_id *id) |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 725 | { |
| 726 | struct isl29018_chip *chip; |
Jonathan Cameron | 927afbe | 2011-06-27 13:07:57 +0100 | [diff] [blame] | 727 | struct iio_dev *indio_dev; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 728 | int err; |
Laurentiu Palcu | dc4ecaf | 2014-01-09 10:20:00 +0000 | [diff] [blame] | 729 | const char *name = NULL; |
| 730 | int dev_id = 0; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 731 | |
Sachin Kamat | e434dcf | 2013-07-22 12:03:00 +0100 | [diff] [blame] | 732 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); |
Peter Meerwald-Stadler | ab5b949 | 2016-07-05 13:55:37 +0200 | [diff] [blame] | 733 | if (!indio_dev) |
Sachin Kamat | e434dcf | 2013-07-22 12:03:00 +0100 | [diff] [blame] | 734 | return -ENOMEM; |
Brian Masney | 744ef62 | 2016-10-10 03:19:55 -0400 | [diff] [blame] | 735 | |
Jonathan Cameron | 927afbe | 2011-06-27 13:07:57 +0100 | [diff] [blame] | 736 | chip = iio_priv(indio_dev); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 737 | |
Jonathan Cameron | 927afbe | 2011-06-27 13:07:57 +0100 | [diff] [blame] | 738 | i2c_set_clientdata(client, indio_dev); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 739 | |
Laurentiu Palcu | dc4ecaf | 2014-01-09 10:20:00 +0000 | [diff] [blame] | 740 | if (id) { |
| 741 | name = id->name; |
| 742 | dev_id = id->driver_data; |
| 743 | } |
| 744 | |
| 745 | if (ACPI_HANDLE(&client->dev)) |
| 746 | name = isl29018_match_acpi_device(&client->dev, &dev_id); |
| 747 | |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 748 | mutex_init(&chip->lock); |
| 749 | |
Laurentiu Palcu | dc4ecaf | 2014-01-09 10:20:00 +0000 | [diff] [blame] | 750 | chip->type = dev_id; |
Roberta Dobrescu | 809a591 | 2015-04-16 22:20:58 +0300 | [diff] [blame] | 751 | chip->calibscale = 1; |
| 752 | chip->ucalibscale = 0; |
Roberta Dobrescu | 6920ccf | 2015-04-16 22:20:59 +0300 | [diff] [blame] | 753 | chip->int_time = ISL29018_INT_TIME_16; |
| 754 | chip->scale = isl29018_scales[chip->int_time][0]; |
Bryan Freed | 1e45cf3 | 2012-10-25 00:39:00 +0100 | [diff] [blame] | 755 | chip->suspended = false; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 756 | |
Anson Huang | 1a02d12 | 2019-01-08 09:09:39 +0000 | [diff] [blame^] | 757 | chip->vcc_reg = devm_regulator_get(&client->dev, "vcc"); |
| 758 | if (IS_ERR(chip->vcc_reg)) { |
| 759 | err = PTR_ERR(chip->vcc_reg); |
| 760 | if (err != -EPROBE_DEFER) |
| 761 | dev_err(&client->dev, "failed to get VCC regulator!\n"); |
| 762 | return err; |
| 763 | } |
| 764 | |
| 765 | err = regulator_enable(chip->vcc_reg); |
| 766 | if (err) { |
| 767 | dev_err(&client->dev, "failed to enable VCC regulator!\n"); |
| 768 | return err; |
| 769 | } |
| 770 | |
| 771 | err = devm_add_action_or_reset(&client->dev, isl29018_disable_regulator_action, |
| 772 | chip); |
| 773 | if (err) { |
| 774 | dev_err(&client->dev, "failed to setup regulator cleanup action!\n"); |
| 775 | return err; |
| 776 | } |
| 777 | |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 778 | chip->regmap = devm_regmap_init_i2c(client, |
Peter Meerwald-Stadler | 9219376 | 2016-07-05 13:55:40 +0200 | [diff] [blame] | 779 | isl29018_chip_info_tbl[dev_id].regmap_cfg); |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 780 | if (IS_ERR(chip->regmap)) { |
| 781 | err = PTR_ERR(chip->regmap); |
Alison Schofield | 6467086 | 2016-02-22 12:34:32 -0800 | [diff] [blame] | 782 | dev_err(&client->dev, "regmap initialization fails: %d\n", err); |
Sachin Kamat | e434dcf | 2013-07-22 12:03:00 +0100 | [diff] [blame] | 783 | return err; |
Laxman Dewangan | 057340e | 2012-04-20 12:57:38 +0530 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | err = isl29018_chip_init(chip); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 787 | if (err) |
Sachin Kamat | e434dcf | 2013-07-22 12:03:00 +0100 | [diff] [blame] | 788 | return err; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 789 | |
Peter Meerwald-Stadler | 9219376 | 2016-07-05 13:55:40 +0200 | [diff] [blame] | 790 | indio_dev->info = isl29018_chip_info_tbl[dev_id].indio_info; |
| 791 | indio_dev->channels = isl29018_chip_info_tbl[dev_id].channels; |
| 792 | indio_dev->num_channels = isl29018_chip_info_tbl[dev_id].num_channels; |
Laurentiu Palcu | dc4ecaf | 2014-01-09 10:20:00 +0000 | [diff] [blame] | 793 | indio_dev->name = name; |
Jonathan Cameron | 927afbe | 2011-06-27 13:07:57 +0100 | [diff] [blame] | 794 | indio_dev->dev.parent = &client->dev; |
| 795 | indio_dev->modes = INDIO_DIRECT_MODE; |
Brian Masney | 744ef62 | 2016-10-10 03:19:55 -0400 | [diff] [blame] | 796 | |
Peter Meerwald-Stadler | ab5b949 | 2016-07-05 13:55:37 +0200 | [diff] [blame] | 797 | return devm_iio_device_register(&client->dev, indio_dev); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Bryan Freed | 1e45cf3 | 2012-10-25 00:39:00 +0100 | [diff] [blame] | 800 | #ifdef CONFIG_PM_SLEEP |
| 801 | static int isl29018_suspend(struct device *dev) |
| 802 | { |
| 803 | struct isl29018_chip *chip = iio_priv(dev_get_drvdata(dev)); |
Anson Huang | 1a02d12 | 2019-01-08 09:09:39 +0000 | [diff] [blame^] | 804 | int ret; |
Bryan Freed | 1e45cf3 | 2012-10-25 00:39:00 +0100 | [diff] [blame] | 805 | |
| 806 | mutex_lock(&chip->lock); |
| 807 | |
Brian Masney | 19a00a9 | 2016-10-10 03:19:57 -0400 | [diff] [blame] | 808 | /* |
| 809 | * Since this driver uses only polling commands, we are by default in |
Bryan Freed | 1e45cf3 | 2012-10-25 00:39:00 +0100 | [diff] [blame] | 810 | * auto shutdown (ie, power-down) mode. |
| 811 | * So we do not have much to do here. |
| 812 | */ |
| 813 | chip->suspended = true; |
Anson Huang | 1a02d12 | 2019-01-08 09:09:39 +0000 | [diff] [blame^] | 814 | ret = regulator_disable(chip->vcc_reg); |
| 815 | if (ret) |
| 816 | dev_err(dev, "failed to disable VCC regulator\n"); |
Bryan Freed | 1e45cf3 | 2012-10-25 00:39:00 +0100 | [diff] [blame] | 817 | |
| 818 | mutex_unlock(&chip->lock); |
Brian Masney | 744ef62 | 2016-10-10 03:19:55 -0400 | [diff] [blame] | 819 | |
Anson Huang | 1a02d12 | 2019-01-08 09:09:39 +0000 | [diff] [blame^] | 820 | return ret; |
Bryan Freed | 1e45cf3 | 2012-10-25 00:39:00 +0100 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | static int isl29018_resume(struct device *dev) |
| 824 | { |
| 825 | struct isl29018_chip *chip = iio_priv(dev_get_drvdata(dev)); |
| 826 | int err; |
| 827 | |
| 828 | mutex_lock(&chip->lock); |
| 829 | |
Anson Huang | 1a02d12 | 2019-01-08 09:09:39 +0000 | [diff] [blame^] | 830 | err = regulator_enable(chip->vcc_reg); |
| 831 | if (err) { |
| 832 | dev_err(dev, "failed to enable VCC regulator\n"); |
| 833 | mutex_unlock(&chip->lock); |
| 834 | return err; |
| 835 | } |
| 836 | |
Bryan Freed | 1e45cf3 | 2012-10-25 00:39:00 +0100 | [diff] [blame] | 837 | err = isl29018_chip_init(chip); |
| 838 | if (!err) |
| 839 | chip->suspended = false; |
| 840 | |
| 841 | mutex_unlock(&chip->lock); |
Brian Masney | 744ef62 | 2016-10-10 03:19:55 -0400 | [diff] [blame] | 842 | |
Bryan Freed | 1e45cf3 | 2012-10-25 00:39:00 +0100 | [diff] [blame] | 843 | return err; |
| 844 | } |
| 845 | |
| 846 | static SIMPLE_DEV_PM_OPS(isl29018_pm_ops, isl29018_suspend, isl29018_resume); |
| 847 | #define ISL29018_PM_OPS (&isl29018_pm_ops) |
| 848 | #else |
| 849 | #define ISL29018_PM_OPS NULL |
| 850 | #endif |
| 851 | |
Matthias Kaehlcke | 14b39dc | 2017-05-19 14:28:53 -0700 | [diff] [blame] | 852 | #ifdef CONFIG_ACPI |
Laurentiu Palcu | dc4ecaf | 2014-01-09 10:20:00 +0000 | [diff] [blame] | 853 | static const struct acpi_device_id isl29018_acpi_match[] = { |
| 854 | {"ISL29018", isl29018}, |
| 855 | {"ISL29023", isl29023}, |
| 856 | {"ISL29035", isl29035}, |
| 857 | {}, |
| 858 | }; |
| 859 | MODULE_DEVICE_TABLE(acpi, isl29018_acpi_match); |
Matthias Kaehlcke | 14b39dc | 2017-05-19 14:28:53 -0700 | [diff] [blame] | 860 | #endif |
Laurentiu Palcu | dc4ecaf | 2014-01-09 10:20:00 +0000 | [diff] [blame] | 861 | |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 862 | static const struct i2c_device_id isl29018_id[] = { |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 863 | {"isl29018", isl29018}, |
| 864 | {"isl29023", isl29023}, |
| 865 | {"isl29035", isl29035}, |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 866 | {} |
| 867 | }; |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 868 | MODULE_DEVICE_TABLE(i2c, isl29018_id); |
| 869 | |
Olof Johansson | 4ee1952 | 2011-12-22 18:44:43 -0800 | [diff] [blame] | 870 | static const struct of_device_id isl29018_of_match[] = { |
Laxman Dewangan | 610202d | 2012-04-24 11:41:38 +0530 | [diff] [blame] | 871 | { .compatible = "isil,isl29018", }, |
Laurentiu Palcu | 609acef | 2014-08-29 15:26:00 +0100 | [diff] [blame] | 872 | { .compatible = "isil,isl29023", }, |
| 873 | { .compatible = "isil,isl29035", }, |
Olof Johansson | 4ee1952 | 2011-12-22 18:44:43 -0800 | [diff] [blame] | 874 | { }, |
| 875 | }; |
| 876 | MODULE_DEVICE_TABLE(of, isl29018_of_match); |
| 877 | |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 878 | static struct i2c_driver isl29018_driver = { |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 879 | .driver = { |
| 880 | .name = "isl29018", |
Laurentiu Palcu | dc4ecaf | 2014-01-09 10:20:00 +0000 | [diff] [blame] | 881 | .acpi_match_table = ACPI_PTR(isl29018_acpi_match), |
Bryan Freed | 1e45cf3 | 2012-10-25 00:39:00 +0100 | [diff] [blame] | 882 | .pm = ISL29018_PM_OPS, |
Olof Johansson | 4ee1952 | 2011-12-22 18:44:43 -0800 | [diff] [blame] | 883 | .of_match_table = isl29018_of_match, |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 884 | }, |
| 885 | .probe = isl29018_probe, |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 886 | .id_table = isl29018_id, |
| 887 | }; |
Lars-Peter Clausen | 6e5af18 | 2011-11-16 10:13:38 +0100 | [diff] [blame] | 888 | module_i2c_driver(isl29018_driver); |
Rhyland Klein | 9404287 | 2010-10-07 15:48:09 -0700 | [diff] [blame] | 889 | |
| 890 | MODULE_DESCRIPTION("ISL29018 Ambient Light Sensor driver"); |
| 891 | MODULE_LICENSE("GPL"); |