Commit | Line | Data |
---|---|---|
3c97c08b JB |
1 | /* |
2 | * Device driver for monitoring ambient light intensity in (lux) | |
3 | * and proximity detection (prox) within the TAOS TSL2X7X family of devices. | |
4 | * | |
5 | * Copyright (c) 2012, TAOS Corporation. | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 | * more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License along | |
18 | * with this program; if not, write to the Free Software Foundation, Inc., | |
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | */ | |
21 | ||
22 | #include <linux/kernel.h> | |
23 | #include <linux/i2c.h> | |
24 | #include <linux/errno.h> | |
25 | #include <linux/delay.h> | |
26 | #include <linux/mutex.h> | |
27 | #include <linux/interrupt.h> | |
28 | #include <linux/slab.h> | |
29 | #include <linux/module.h> | |
30 | #include <linux/version.h> | |
06458e27 JC |
31 | #include <linux/iio/events.h> |
32 | #include <linux/iio/iio.h> | |
33 | #include <linux/iio/sysfs.h> | |
3c97c08b | 34 | #include "tsl2x7x.h" |
3c97c08b JB |
35 | |
36 | /* Cal defs*/ | |
37 | #define PROX_STAT_CAL 0 | |
38 | #define PROX_STAT_SAMP 1 | |
39 | #define MAX_SAMPLES_CAL 200 | |
40 | ||
41 | /* TSL2X7X Device ID */ | |
42 | #define TRITON_ID 0x00 | |
43 | #define SWORDFISH_ID 0x30 | |
44 | #define HALIBUT_ID 0x20 | |
45 | ||
46 | /* Lux calculation constants */ | |
47 | #define TSL2X7X_LUX_CALC_OVER_FLOW 65535 | |
48 | ||
49 | /* TAOS Register definitions - note: | |
50 | * depending on device, some of these register are not used and the | |
51 | * register address is benign. | |
52 | */ | |
53 | /* 2X7X register offsets */ | |
54 | #define TSL2X7X_MAX_CONFIG_REG 16 | |
55 | ||
56 | /* Device Registers and Masks */ | |
57 | #define TSL2X7X_CNTRL 0x00 | |
58 | #define TSL2X7X_ALS_TIME 0X01 | |
59 | #define TSL2X7X_PRX_TIME 0x02 | |
60 | #define TSL2X7X_WAIT_TIME 0x03 | |
61 | #define TSL2X7X_ALS_MINTHRESHLO 0X04 | |
62 | #define TSL2X7X_ALS_MINTHRESHHI 0X05 | |
63 | #define TSL2X7X_ALS_MAXTHRESHLO 0X06 | |
64 | #define TSL2X7X_ALS_MAXTHRESHHI 0X07 | |
65 | #define TSL2X7X_PRX_MINTHRESHLO 0X08 | |
66 | #define TSL2X7X_PRX_MINTHRESHHI 0X09 | |
67 | #define TSL2X7X_PRX_MAXTHRESHLO 0X0A | |
68 | #define TSL2X7X_PRX_MAXTHRESHHI 0X0B | |
69 | #define TSL2X7X_PERSISTENCE 0x0C | |
70 | #define TSL2X7X_PRX_CONFIG 0x0D | |
71 | #define TSL2X7X_PRX_COUNT 0x0E | |
72 | #define TSL2X7X_GAIN 0x0F | |
73 | #define TSL2X7X_NOTUSED 0x10 | |
74 | #define TSL2X7X_REVID 0x11 | |
75 | #define TSL2X7X_CHIPID 0x12 | |
76 | #define TSL2X7X_STATUS 0x13 | |
77 | #define TSL2X7X_ALS_CHAN0LO 0x14 | |
78 | #define TSL2X7X_ALS_CHAN0HI 0x15 | |
79 | #define TSL2X7X_ALS_CHAN1LO 0x16 | |
80 | #define TSL2X7X_ALS_CHAN1HI 0x17 | |
81 | #define TSL2X7X_PRX_LO 0x18 | |
82 | #define TSL2X7X_PRX_HI 0x19 | |
83 | ||
84 | /* tsl2X7X cmd reg masks */ | |
85 | #define TSL2X7X_CMD_REG 0x80 | |
86 | #define TSL2X7X_CMD_SPL_FN 0x60 | |
87 | ||
88 | #define TSL2X7X_CMD_PROX_INT_CLR 0X05 | |
89 | #define TSL2X7X_CMD_ALS_INT_CLR 0x06 | |
90 | #define TSL2X7X_CMD_PROXALS_INT_CLR 0X07 | |
91 | ||
92 | /* tsl2X7X cntrl reg masks */ | |
93 | #define TSL2X7X_CNTL_ADC_ENBL 0x02 | |
94 | #define TSL2X7X_CNTL_PWR_ON 0x01 | |
95 | ||
96 | /* tsl2X7X status reg masks */ | |
97 | #define TSL2X7X_STA_ADC_VALID 0x01 | |
98 | #define TSL2X7X_STA_PRX_VALID 0x02 | |
99 | #define TSL2X7X_STA_ADC_PRX_VALID (TSL2X7X_STA_ADC_VALID |\ | |
100 | TSL2X7X_STA_PRX_VALID) | |
101 | #define TSL2X7X_STA_ALS_INTR 0x10 | |
102 | #define TSL2X7X_STA_PRX_INTR 0x20 | |
103 | ||
104 | /* tsl2X7X cntrl reg masks */ | |
105 | #define TSL2X7X_CNTL_REG_CLEAR 0x00 | |
106 | #define TSL2X7X_CNTL_PROX_INT_ENBL 0X20 | |
107 | #define TSL2X7X_CNTL_ALS_INT_ENBL 0X10 | |
108 | #define TSL2X7X_CNTL_WAIT_TMR_ENBL 0X08 | |
109 | #define TSL2X7X_CNTL_PROX_DET_ENBL 0X04 | |
110 | #define TSL2X7X_CNTL_PWRON 0x01 | |
111 | #define TSL2X7X_CNTL_ALSPON_ENBL 0x03 | |
112 | #define TSL2X7X_CNTL_INTALSPON_ENBL 0x13 | |
113 | #define TSL2X7X_CNTL_PROXPON_ENBL 0x0F | |
114 | #define TSL2X7X_CNTL_INTPROXPON_ENBL 0x2F | |
115 | ||
116 | /*Prox diode to use */ | |
117 | #define TSL2X7X_DIODE0 0x10 | |
118 | #define TSL2X7X_DIODE1 0x20 | |
119 | #define TSL2X7X_DIODE_BOTH 0x30 | |
120 | ||
121 | /* LED Power */ | |
122 | #define TSL2X7X_mA100 0x00 | |
123 | #define TSL2X7X_mA50 0x40 | |
124 | #define TSL2X7X_mA25 0x80 | |
125 | #define TSL2X7X_mA13 0xD0 | |
126 | #define TSL2X7X_MAX_TIMER_CNT (0xFF) | |
127 | ||
128 | /*Common device IIO EventMask */ | |
129 | #define TSL2X7X_EVENT_MASK \ | |
130 | (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | \ | |
131 | IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING)), | |
132 | ||
0f3bcfe6 JB |
133 | #define TSL2X7X_MIN_ITIME 3 |
134 | ||
3c97c08b JB |
135 | /* TAOS txx2x7x Device family members */ |
136 | enum { | |
137 | tsl2571, | |
138 | tsl2671, | |
139 | tmd2671, | |
140 | tsl2771, | |
141 | tmd2771, | |
142 | tsl2572, | |
143 | tsl2672, | |
144 | tmd2672, | |
145 | tsl2772, | |
146 | tmd2772 | |
147 | }; | |
148 | ||
149 | enum { | |
150 | TSL2X7X_CHIP_UNKNOWN = 0, | |
151 | TSL2X7X_CHIP_WORKING = 1, | |
152 | TSL2X7X_CHIP_SUSPENDED = 2 | |
153 | }; | |
154 | ||
155 | struct tsl2x7x_parse_result { | |
156 | int integer; | |
157 | int fract; | |
158 | }; | |
159 | ||
160 | /* Per-device data */ | |
161 | struct tsl2x7x_als_info { | |
162 | u16 als_ch0; | |
163 | u16 als_ch1; | |
164 | u16 lux; | |
165 | }; | |
166 | ||
167 | struct tsl2x7x_prox_stat { | |
168 | int min; | |
169 | int max; | |
170 | int mean; | |
171 | unsigned long stddev; | |
172 | }; | |
173 | ||
174 | struct tsl2x7x_chip_info { | |
175 | int chan_table_elements; | |
176 | struct iio_chan_spec channel[4]; | |
177 | const struct iio_info *info; | |
178 | }; | |
179 | ||
180 | struct tsl2X7X_chip { | |
181 | kernel_ulong_t id; | |
182 | struct mutex prox_mutex; | |
183 | struct mutex als_mutex; | |
184 | struct i2c_client *client; | |
185 | u16 prox_data; | |
186 | struct tsl2x7x_als_info als_cur_info; | |
187 | struct tsl2x7x_settings tsl2x7x_settings; | |
188 | struct tsl2X7X_platform_data *pdata; | |
189 | int als_time_scale; | |
190 | int als_saturation; | |
191 | int tsl2x7x_chip_status; | |
192 | u8 tsl2x7x_config[TSL2X7X_MAX_CONFIG_REG]; | |
193 | const struct tsl2x7x_chip_info *chip_info; | |
194 | const struct iio_info *info; | |
195 | s64 event_timestamp; | |
196 | /* This structure is intentionally large to accommodate | |
197 | * updates via sysfs. */ | |
198 | /* Sized to 9 = max 8 segments + 1 termination segment */ | |
199 | struct tsl2x7x_lux tsl2x7x_device_lux[TSL2X7X_MAX_LUX_TABLE_SIZE]; | |
200 | }; | |
201 | ||
202 | /* Different devices require different coefficents */ | |
203 | static const struct tsl2x7x_lux tsl2x71_lux_table[] = { | |
204 | { 14461, 611, 1211 }, | |
205 | { 18540, 352, 623 }, | |
206 | { 0, 0, 0 }, | |
207 | }; | |
208 | ||
209 | static const struct tsl2x7x_lux tmd2x71_lux_table[] = { | |
210 | { 11635, 115, 256 }, | |
211 | { 15536, 87, 179 }, | |
212 | { 0, 0, 0 }, | |
213 | }; | |
214 | ||
215 | static const struct tsl2x7x_lux tsl2x72_lux_table[] = { | |
216 | { 14013, 466, 917 }, | |
217 | { 18222, 310, 552 }, | |
218 | { 0, 0, 0 }, | |
219 | }; | |
220 | ||
221 | static const struct tsl2x7x_lux tmd2x72_lux_table[] = { | |
222 | { 13218, 130, 262 }, | |
223 | { 17592, 92, 169 }, | |
224 | { 0, 0, 0 }, | |
225 | }; | |
226 | ||
227 | static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[] = { | |
228 | [tsl2571] = tsl2x71_lux_table, | |
229 | [tsl2671] = tsl2x71_lux_table, | |
230 | [tmd2671] = tmd2x71_lux_table, | |
231 | [tsl2771] = tsl2x71_lux_table, | |
232 | [tmd2771] = tmd2x71_lux_table, | |
233 | [tsl2572] = tsl2x72_lux_table, | |
234 | [tsl2672] = tsl2x72_lux_table, | |
235 | [tmd2672] = tmd2x72_lux_table, | |
236 | [tsl2772] = tsl2x72_lux_table, | |
237 | [tmd2772] = tmd2x72_lux_table, | |
238 | }; | |
239 | ||
240 | static const struct tsl2x7x_settings tsl2x7x_default_settings = { | |
241 | .als_time = 219, /* 101 ms */ | |
242 | .als_gain = 0, | |
243 | .prx_time = 254, /* 5.4 ms */ | |
244 | .prox_gain = 1, | |
245 | .wait_time = 245, | |
246 | .prox_config = 0, | |
247 | .als_gain_trim = 1000, | |
248 | .als_cal_target = 150, | |
249 | .als_thresh_low = 200, | |
250 | .als_thresh_high = 256, | |
251 | .persistence = 255, | |
252 | .interrupts_en = 0, | |
253 | .prox_thres_low = 0, | |
254 | .prox_thres_high = 512, | |
255 | .prox_max_samples_cal = 30, | |
256 | .prox_pulse_count = 8 | |
257 | }; | |
258 | ||
259 | static const s16 tsl2X7X_als_gainadj[] = { | |
260 | 1, | |
261 | 8, | |
262 | 16, | |
263 | 120 | |
264 | }; | |
265 | ||
266 | static const s16 tsl2X7X_prx_gainadj[] = { | |
267 | 1, | |
268 | 2, | |
269 | 4, | |
270 | 8 | |
271 | }; | |
272 | ||
273 | /* Channel variations */ | |
274 | enum { | |
275 | ALS, | |
276 | PRX, | |
277 | ALSPRX, | |
278 | PRX2, | |
279 | ALSPRX2, | |
280 | }; | |
281 | ||
0f3bcfe6 | 282 | static const u8 device_channel_config[] = { |
3c97c08b JB |
283 | ALS, |
284 | PRX, | |
285 | PRX, | |
286 | ALSPRX, | |
287 | ALSPRX, | |
288 | ALS, | |
289 | PRX2, | |
290 | PRX2, | |
291 | ALSPRX2, | |
292 | ALSPRX2 | |
293 | }; | |
294 | ||
295 | /** | |
296 | * tsl2x7x_parse_buffer() - parse a decimal result from a buffer. | |
297 | * @*buf: pointer to char buffer to parse | |
298 | * @*result: pointer to buffer to contain | |
299 | * resulting interger / decimal as ints. | |
300 | * | |
301 | */ | |
302 | static int | |
303 | tsl2x7x_parse_buffer(const char *buf, struct tsl2x7x_parse_result *result) | |
304 | { | |
305 | int integer = 0, fract = 0, fract_mult = 100000; | |
306 | bool integer_part = true, negative = false; | |
307 | ||
308 | if (buf[0] == '-') { | |
309 | negative = true; | |
310 | buf++; | |
311 | } | |
312 | ||
313 | while (*buf) { | |
314 | if ('0' <= *buf && *buf <= '9') { | |
315 | if (integer_part) | |
316 | integer = integer*10 + *buf - '0'; | |
317 | else { | |
318 | fract += fract_mult*(*buf - '0'); | |
319 | if (fract_mult == 1) | |
320 | break; | |
321 | fract_mult /= 10; | |
322 | } | |
323 | } else if (*buf == '\n') { | |
324 | if (*(buf + 1) == '\0') | |
325 | break; | |
326 | else | |
327 | return -EINVAL; | |
328 | } else if (*buf == '.') { | |
329 | integer_part = false; | |
330 | } else { | |
331 | return -EINVAL; | |
332 | } | |
333 | buf++; | |
334 | } | |
335 | if (negative) { | |
336 | if (integer) | |
337 | integer = -integer; | |
338 | else | |
339 | fract = -fract; | |
340 | } | |
341 | ||
342 | result->integer = integer; | |
343 | result->fract = fract; | |
344 | ||
345 | return 0; | |
346 | } | |
347 | ||
348 | /** | |
349 | * tsl2x7x_i2c_read() - Read a byte from a register. | |
350 | * @client: i2c client | |
351 | * @reg: device register to read from | |
352 | * @*val: pointer to location to store register contents. | |
353 | * | |
354 | */ | |
355 | static int | |
356 | tsl2x7x_i2c_read(struct i2c_client *client, u8 reg, u8 *val) | |
357 | { | |
358 | int ret = 0; | |
359 | ||
360 | /* select register to write */ | |
361 | ret = i2c_smbus_write_byte(client, (TSL2X7X_CMD_REG | reg)); | |
362 | if (ret < 0) { | |
363 | dev_err(&client->dev, "%s: failed to write register %x\n" | |
364 | , __func__, reg); | |
365 | return ret; | |
366 | } | |
367 | ||
368 | /* read the data */ | |
369 | ret = i2c_smbus_read_byte(client); | |
370 | if (ret >= 0) | |
371 | *val = (u8)ret; | |
372 | else | |
373 | dev_err(&client->dev, "%s: failed to read register %x\n" | |
374 | , __func__, reg); | |
375 | ||
376 | return ret; | |
377 | } | |
378 | ||
379 | /** | |
380 | * tsl2x7x_get_lux() - Reads and calculates current lux value. | |
381 | * @indio_dev: pointer to IIO device | |
382 | * | |
383 | * The raw ch0 and ch1 values of the ambient light sensed in the last | |
384 | * integration cycle are read from the device. | |
385 | * Time scale factor array values are adjusted based on the integration time. | |
386 | * The raw values are multiplied by a scale factor, and device gain is obtained | |
387 | * using gain index. Limit checks are done next, then the ratio of a multiple | |
388 | * of ch1 value, to the ch0 value, is calculated. Array tsl2x7x_device_lux[] | |
389 | * is then scanned to find the first ratio value that is just above the ratio | |
390 | * we just calculated. The ch0 and ch1 multiplier constants in the array are | |
391 | * then used along with the time scale factor array values, to calculate the | |
392 | * lux. | |
393 | */ | |
394 | static int tsl2x7x_get_lux(struct iio_dev *indio_dev) | |
395 | { | |
396 | u16 ch0, ch1; /* separated ch0/ch1 data from device */ | |
397 | u32 lux; /* raw lux calculated from device data */ | |
398 | u64 lux64; | |
399 | u32 ratio; | |
400 | u8 buf[4]; | |
401 | struct tsl2x7x_lux *p; | |
402 | struct tsl2X7X_chip *chip = iio_priv(indio_dev); | |
403 | int i, ret; | |
404 | u32 ch0lux = 0; | |
405 | u32 ch1lux = 0; | |
406 | ||
407 | if (mutex_trylock(&chip->als_mutex) == 0) | |
408 | return chip->als_cur_info.lux; /* busy, so return LAST VALUE */ | |
409 | ||
410 | if (chip->tsl2x7x_chip_status != TSL2X7X_CHIP_WORKING) { | |
411 | /* device is not enabled */ | |
412 | dev_err(&chip->client->dev, "%s: device is not enabled\n", | |
413 | __func__); | |
414 | ret = -EBUSY ; | |
415 | goto out_unlock; | |
416 | } | |
417 | ||
418 | ret = tsl2x7x_i2c_read(chip->client, | |
419 | (TSL2X7X_CMD_REG | TSL2X7X_STATUS), &buf[0]); | |
420 | if (ret < 0) { | |
421 | dev_err(&chip->client->dev, | |
422 | "%s: Failed to read STATUS Reg\n", __func__); | |
423 | goto out_unlock; | |
424 | } | |
425 | /* is data new & valid */ | |
426 | if (!(buf[0] & TSL2X7X_STA_ADC_VALID)) { | |
427 | dev_err(&chip->client->dev, | |
428 | "%s: data not valid yet\n", __func__); | |
429 | ret = chip->als_cur_info.lux; /* return LAST VALUE */ | |
430 | goto out_unlock; | |
431 | } | |
432 | ||
433 | for (i = 0; i < 4; i++) { | |
434 | ret = tsl2x7x_i2c_read(chip->client, | |
435 | (TSL2X7X_CMD_REG | (TSL2X7X_ALS_CHAN0LO + i)), | |
436 | &buf[i]); | |
437 | if (ret < 0) { | |
438 | dev_err(&chip->client->dev, | |
439 | "%s: failed to read. err=%x\n", __func__, ret); | |
440 | goto out_unlock; | |
441 | } | |
442 | } | |
443 | ||
444 | /* clear any existing interrupt status */ | |
445 | ret = i2c_smbus_write_byte(chip->client, | |
446 | (TSL2X7X_CMD_REG | | |
447 | TSL2X7X_CMD_SPL_FN | | |
448 | TSL2X7X_CMD_ALS_INT_CLR)); | |
449 | if (ret < 0) { | |
450 | dev_err(&chip->client->dev, | |
451 | "%s: i2c_write_command failed - err = %d\n", | |
452 | __func__, ret); | |
453 | goto out_unlock; /* have no data, so return failure */ | |
454 | } | |
455 | ||
456 | /* extract ALS/lux data */ | |
457 | ch0 = le16_to_cpup((const __le16 *)&buf[0]); | |
458 | ch1 = le16_to_cpup((const __le16 *)&buf[2]); | |
459 | ||
460 | chip->als_cur_info.als_ch0 = ch0; | |
461 | chip->als_cur_info.als_ch1 = ch1; | |
462 | ||
463 | if ((ch0 >= chip->als_saturation) || (ch1 >= chip->als_saturation)) { | |
464 | lux = TSL2X7X_LUX_CALC_OVER_FLOW; | |
465 | goto return_max; | |
466 | } | |
467 | ||
468 | if (ch0 == 0) { | |
469 | /* have no data, so return LAST VALUE */ | |
470 | ret = chip->als_cur_info.lux; | |
471 | goto out_unlock; | |
472 | } | |
473 | /* calculate ratio */ | |
474 | ratio = (ch1 << 15) / ch0; | |
475 | /* convert to unscaled lux using the pointer to the table */ | |
476 | p = (struct tsl2x7x_lux *) chip->tsl2x7x_device_lux; | |
477 | while (p->ratio != 0 && p->ratio < ratio) | |
478 | p++; | |
479 | ||
480 | if (p->ratio == 0) { | |
481 | lux = 0; | |
482 | } else { | |
483 | ch0lux = DIV_ROUND_UP((ch0 * p->ch0), | |
484 | tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain]); | |
485 | ch1lux = DIV_ROUND_UP((ch1 * p->ch1), | |
486 | tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain]); | |
487 | lux = ch0lux - ch1lux; | |
488 | } | |
489 | ||
490 | /* note: lux is 31 bit max at this point */ | |
491 | if (ch1lux > ch0lux) { | |
492 | dev_dbg(&chip->client->dev, "ch1lux > ch0lux-return last value\n"); | |
493 | ret = chip->als_cur_info.lux; | |
494 | goto out_unlock; | |
495 | } | |
496 | ||
497 | /* adjust for active time scale */ | |
498 | if (chip->als_time_scale == 0) | |
499 | lux = 0; | |
500 | else | |
501 | lux = (lux + (chip->als_time_scale >> 1)) / | |
502 | chip->als_time_scale; | |
503 | ||
504 | /* adjust for active gain scale | |
505 | * The tsl2x7x_device_lux tables have a factor of 256 built-in. | |
506 | * User-specified gain provides a multiplier. | |
507 | * Apply user-specified gain before shifting right to retain precision. | |
508 | * Use 64 bits to avoid overflow on multiplication. | |
509 | * Then go back to 32 bits before division to avoid using div_u64(). | |
510 | */ | |
511 | ||
512 | lux64 = lux; | |
513 | lux64 = lux64 * chip->tsl2x7x_settings.als_gain_trim; | |
514 | lux64 >>= 8; | |
515 | lux = lux64; | |
516 | lux = (lux + 500) / 1000; | |
517 | ||
518 | if (lux > TSL2X7X_LUX_CALC_OVER_FLOW) /* check for overflow */ | |
519 | lux = TSL2X7X_LUX_CALC_OVER_FLOW; | |
520 | ||
521 | /* Update the structure with the latest lux. */ | |
522 | return_max: | |
523 | chip->als_cur_info.lux = lux; | |
524 | ret = lux; | |
525 | ||
526 | out_unlock: | |
527 | mutex_unlock(&chip->als_mutex); | |
528 | ||
529 | return ret; | |
530 | } | |
531 | ||
532 | /** | |
533 | * tsl2x7x_get_prox() - Reads proximity data registers and updates | |
534 | * chip->prox_data. | |
535 | * | |
536 | * @indio_dev: pointer to IIO device | |
537 | */ | |
538 | static int tsl2x7x_get_prox(struct iio_dev *indio_dev) | |
539 | { | |
540 | int i; | |
541 | int ret; | |
542 | u8 status; | |
543 | u8 chdata[2]; | |
544 | struct tsl2X7X_chip *chip = iio_priv(indio_dev); | |
545 | ||
546 | if (mutex_trylock(&chip->prox_mutex) == 0) { | |
547 | dev_err(&chip->client->dev, | |
548 | "%s: Can't get prox mutex\n", __func__); | |
549 | return -EBUSY; | |
550 | } | |
551 | ||
552 | ret = tsl2x7x_i2c_read(chip->client, | |
553 | (TSL2X7X_CMD_REG | TSL2X7X_STATUS), &status); | |
554 | if (ret < 0) { | |
555 | dev_err(&chip->client->dev, | |
556 | "%s: i2c err=%d\n", __func__, ret); | |
557 | goto prox_poll_err; | |
558 | } | |
559 | ||
560 | switch (chip->id) { | |
561 | case tsl2571: | |
562 | case tsl2671: | |
563 | case tmd2671: | |
564 | case tsl2771: | |
565 | case tmd2771: | |
566 | if (!(status & TSL2X7X_STA_ADC_VALID)) | |
567 | goto prox_poll_err; | |
568 | break; | |
569 | case tsl2572: | |
570 | case tsl2672: | |
571 | case tmd2672: | |
572 | case tsl2772: | |
573 | case tmd2772: | |
574 | if (!(status & TSL2X7X_STA_PRX_VALID)) | |
575 | goto prox_poll_err; | |
576 | break; | |
577 | } | |
578 | ||
579 | for (i = 0; i < 2; i++) { | |
580 | ret = tsl2x7x_i2c_read(chip->client, | |
581 | (TSL2X7X_CMD_REG | | |
582 | (TSL2X7X_PRX_LO + i)), &chdata[i]); | |
583 | if (ret < 0) | |
584 | goto prox_poll_err; | |
585 | } | |
586 | ||
587 | chip->prox_data = | |
588 | le16_to_cpup((const __le16 *)&chdata[0]); | |
589 | ||
590 | prox_poll_err: | |
591 | ||
592 | mutex_unlock(&chip->prox_mutex); | |
593 | ||
594 | return chip->prox_data; | |
595 | } | |
596 | ||
597 | /** | |
598 | * tsl2x7x_defaults() - Populates the device nominal operating parameters | |
599 | * with those provided by a 'platform' data struct or | |
600 | * with prefined defaults. | |
601 | * | |
602 | * @chip: pointer to device structure. | |
603 | */ | |
604 | static void tsl2x7x_defaults(struct tsl2X7X_chip *chip) | |
605 | { | |
606 | /* If Operational settings defined elsewhere.. */ | |
607 | if (chip->pdata && chip->pdata->platform_default_settings != 0) | |
608 | memcpy(&(chip->tsl2x7x_settings), | |
609 | chip->pdata->platform_default_settings, | |
610 | sizeof(tsl2x7x_default_settings)); | |
611 | else | |
612 | memcpy(&(chip->tsl2x7x_settings), | |
613 | &tsl2x7x_default_settings, | |
614 | sizeof(tsl2x7x_default_settings)); | |
615 | ||
616 | /* Load up the proper lux table. */ | |
617 | if (chip->pdata && chip->pdata->platform_lux_table[0].ratio != 0) | |
618 | memcpy(chip->tsl2x7x_device_lux, | |
619 | chip->pdata->platform_lux_table, | |
620 | sizeof(chip->pdata->platform_lux_table)); | |
621 | else | |
622 | memcpy(chip->tsl2x7x_device_lux, | |
623 | (struct tsl2x7x_lux *)tsl2x7x_default_lux_table_group[chip->id], | |
624 | MAX_DEFAULT_TABLE_BYTES); | |
625 | } | |
626 | ||
627 | /** | |
628 | * tsl2x7x_als_calibrate() - Obtain single reading and calculate | |
629 | * the als_gain_trim. | |
630 | * | |
631 | * @indio_dev: pointer to IIO device | |
632 | */ | |
633 | static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev) | |
634 | { | |
635 | struct tsl2X7X_chip *chip = iio_priv(indio_dev); | |
636 | u8 reg_val; | |
637 | int gain_trim_val; | |
638 | int ret; | |
639 | int lux_val; | |
640 | ||
641 | ret = i2c_smbus_write_byte(chip->client, | |
642 | (TSL2X7X_CMD_REG | TSL2X7X_CNTRL)); | |
643 | if (ret < 0) { | |
644 | dev_err(&chip->client->dev, | |
645 | "%s: failed to write CNTRL register, ret=%d\n", | |
646 | __func__, ret); | |
647 | return ret; | |
648 | } | |
649 | ||
650 | reg_val = i2c_smbus_read_byte(chip->client); | |
651 | if ((reg_val & (TSL2X7X_CNTL_ADC_ENBL | TSL2X7X_CNTL_PWR_ON)) | |
652 | != (TSL2X7X_CNTL_ADC_ENBL | TSL2X7X_CNTL_PWR_ON)) { | |
653 | dev_err(&chip->client->dev, | |
654 | "%s: failed: ADC not enabled\n", __func__); | |
655 | return -1; | |
656 | } | |
657 | ||
658 | ret = i2c_smbus_write_byte(chip->client, | |
659 | (TSL2X7X_CMD_REG | TSL2X7X_CNTRL)); | |
660 | if (ret < 0) { | |
661 | dev_err(&chip->client->dev, | |
662 | "%s: failed to write ctrl reg: ret=%d\n", | |
663 | __func__, ret); | |
664 | return ret; | |
665 | } | |
666 | ||
667 | reg_val = i2c_smbus_read_byte(chip->client); | |
668 | if ((reg_val & TSL2X7X_STA_ADC_VALID) != TSL2X7X_STA_ADC_VALID) { | |
669 | dev_err(&chip->client->dev, | |
670 | "%s: failed: STATUS - ADC not valid.\n", __func__); | |
671 | return -ENODATA; | |
672 | } | |
673 | ||
674 | lux_val = tsl2x7x_get_lux(indio_dev); | |
675 | if (lux_val < 0) { | |
676 | dev_err(&chip->client->dev, | |
677 | "%s: failed to get lux\n", __func__); | |
678 | return lux_val; | |
679 | } | |
680 | ||
681 | gain_trim_val = (((chip->tsl2x7x_settings.als_cal_target) | |
682 | * chip->tsl2x7x_settings.als_gain_trim) / lux_val); | |
683 | if ((gain_trim_val < 250) || (gain_trim_val > 4000)) | |
684 | return -ERANGE; | |
685 | ||
686 | chip->tsl2x7x_settings.als_gain_trim = gain_trim_val; | |
687 | dev_info(&chip->client->dev, | |
688 | "%s als_calibrate completed\n", chip->client->name); | |
689 | ||
690 | return (int) gain_trim_val; | |
691 | } | |
692 | ||
693 | static int tsl2x7x_chip_on(struct iio_dev *indio_dev) | |
694 | { | |
695 | int i; | |
696 | int ret = 0; | |
697 | u8 *dev_reg; | |
698 | u8 utmp; | |
699 | int als_count; | |
700 | int als_time; | |
701 | struct tsl2X7X_chip *chip = iio_priv(indio_dev); | |
702 | u8 reg_val = 0; | |
703 | ||
704 | if (chip->pdata && chip->pdata->power_on) | |
705 | chip->pdata->power_on(indio_dev); | |
706 | ||
707 | /* Non calculated parameters */ | |
708 | chip->tsl2x7x_config[TSL2X7X_PRX_TIME] = | |
709 | chip->tsl2x7x_settings.prx_time; | |
710 | chip->tsl2x7x_config[TSL2X7X_WAIT_TIME] = | |
711 | chip->tsl2x7x_settings.wait_time; | |
712 | chip->tsl2x7x_config[TSL2X7X_PRX_CONFIG] = | |
713 | chip->tsl2x7x_settings.prox_config; | |
714 | ||
715 | chip->tsl2x7x_config[TSL2X7X_ALS_MINTHRESHLO] = | |
716 | (chip->tsl2x7x_settings.als_thresh_low) & 0xFF; | |
717 | chip->tsl2x7x_config[TSL2X7X_ALS_MINTHRESHHI] = | |
718 | (chip->tsl2x7x_settings.als_thresh_low >> 8) & 0xFF; | |
719 | chip->tsl2x7x_config[TSL2X7X_ALS_MAXTHRESHLO] = | |
720 | (chip->tsl2x7x_settings.als_thresh_high) & 0xFF; | |
721 | chip->tsl2x7x_config[TSL2X7X_ALS_MAXTHRESHHI] = | |
722 | (chip->tsl2x7x_settings.als_thresh_high >> 8) & 0xFF; | |
723 | chip->tsl2x7x_config[TSL2X7X_PERSISTENCE] = | |
724 | chip->tsl2x7x_settings.persistence; | |
725 | ||
726 | chip->tsl2x7x_config[TSL2X7X_PRX_COUNT] = | |
727 | chip->tsl2x7x_settings.prox_pulse_count; | |
728 | chip->tsl2x7x_config[TSL2X7X_PRX_MINTHRESHLO] = | |
729 | chip->tsl2x7x_settings.prox_thres_low; | |
730 | chip->tsl2x7x_config[TSL2X7X_PRX_MAXTHRESHLO] = | |
731 | chip->tsl2x7x_settings.prox_thres_high; | |
732 | ||
733 | /* and make sure we're not already on */ | |
734 | if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING) { | |
735 | /* if forcing a register update - turn off, then on */ | |
736 | dev_info(&chip->client->dev, "device is already enabled\n"); | |
737 | return -EINVAL; | |
738 | } | |
739 | ||
740 | /* determine als integration regster */ | |
741 | als_count = (chip->tsl2x7x_settings.als_time * 100 + 135) / 270; | |
742 | if (als_count == 0) | |
743 | als_count = 1; /* ensure at least one cycle */ | |
744 | ||
745 | /* convert back to time (encompasses overrides) */ | |
746 | als_time = (als_count * 27 + 5) / 10; | |
747 | chip->tsl2x7x_config[TSL2X7X_ALS_TIME] = 256 - als_count; | |
748 | ||
749 | /* Set the gain based on tsl2x7x_settings struct */ | |
750 | chip->tsl2x7x_config[TSL2X7X_GAIN] = | |
751 | (chip->tsl2x7x_settings.als_gain | | |
752 | (TSL2X7X_mA100 | TSL2X7X_DIODE1) | |
753 | | ((chip->tsl2x7x_settings.prox_gain) << 2)); | |
754 | ||
755 | /* set chip struct re scaling and saturation */ | |
756 | chip->als_saturation = als_count * 922; /* 90% of full scale */ | |
757 | chip->als_time_scale = (als_time + 25) / 50; | |
758 | ||
759 | /* TSL2X7X Specific power-on / adc enable sequence | |
760 | * Power on the device 1st. */ | |
761 | utmp = TSL2X7X_CNTL_PWR_ON; | |
762 | ret = i2c_smbus_write_byte_data(chip->client, | |
763 | TSL2X7X_CMD_REG | TSL2X7X_CNTRL, utmp); | |
764 | if (ret < 0) { | |
765 | dev_err(&chip->client->dev, | |
766 | "%s: failed on CNTRL reg.\n", __func__); | |
767 | return ret; | |
768 | } | |
769 | ||
770 | /* Use the following shadow copy for our delay before enabling ADC. | |
771 | * Write all the registers. */ | |
772 | for (i = 0, dev_reg = chip->tsl2x7x_config; | |
773 | i < TSL2X7X_MAX_CONFIG_REG; i++) { | |
774 | ret = i2c_smbus_write_byte_data(chip->client, | |
775 | TSL2X7X_CMD_REG + i, *dev_reg++); | |
776 | if (ret < 0) { | |
777 | dev_err(&chip->client->dev, | |
778 | "%s: failed on write to reg %d.\n", __func__, i); | |
779 | return ret; | |
780 | } | |
781 | } | |
782 | ||
0f3bcfe6 | 783 | mdelay(3); /* Power-on settling time */ |
3c97c08b JB |
784 | |
785 | /* NOW enable the ADC | |
786 | * initialize the desired mode of operation */ | |
787 | utmp = TSL2X7X_CNTL_PWR_ON | | |
788 | TSL2X7X_CNTL_ADC_ENBL | | |
789 | TSL2X7X_CNTL_PROX_DET_ENBL; | |
790 | ret = i2c_smbus_write_byte_data(chip->client, | |
791 | TSL2X7X_CMD_REG | TSL2X7X_CNTRL, utmp); | |
792 | if (ret < 0) { | |
793 | dev_err(&chip->client->dev, | |
794 | "%s: failed on 2nd CTRL reg.\n", __func__); | |
795 | return ret; | |
796 | } | |
797 | ||
798 | chip->tsl2x7x_chip_status = TSL2X7X_CHIP_WORKING; | |
799 | ||
800 | if (chip->tsl2x7x_settings.interrupts_en != 0) { | |
801 | dev_info(&chip->client->dev, "Setting Up Interrupt(s)\n"); | |
802 | ||
803 | reg_val = TSL2X7X_CNTL_PWR_ON | TSL2X7X_CNTL_ADC_ENBL; | |
804 | if ((chip->tsl2x7x_settings.interrupts_en == 0x20) || | |
805 | (chip->tsl2x7x_settings.interrupts_en == 0x30)) | |
806 | reg_val |= TSL2X7X_CNTL_PROX_DET_ENBL; | |
807 | ||
808 | reg_val |= chip->tsl2x7x_settings.interrupts_en; | |
809 | ret = i2c_smbus_write_byte_data(chip->client, | |
810 | (TSL2X7X_CMD_REG | TSL2X7X_CNTRL), reg_val); | |
811 | if (ret < 0) | |
812 | dev_err(&chip->client->dev, | |
813 | "%s: failed in tsl2x7x_IOCTL_INT_SET.\n", | |
814 | __func__); | |
815 | ||
816 | /* Clear out any initial interrupts */ | |
817 | ret = i2c_smbus_write_byte(chip->client, | |
818 | TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN | | |
819 | TSL2X7X_CMD_PROXALS_INT_CLR); | |
820 | if (ret < 0) { | |
821 | dev_err(&chip->client->dev, | |
822 | "%s: Failed to clear Int status\n", | |
823 | __func__); | |
824 | return ret; | |
825 | } | |
826 | } | |
827 | ||
828 | return ret; | |
829 | } | |
830 | ||
831 | static int tsl2x7x_chip_off(struct iio_dev *indio_dev) | |
832 | { | |
833 | int ret; | |
834 | struct tsl2X7X_chip *chip = iio_priv(indio_dev); | |
835 | ||
836 | /* turn device off */ | |
837 | chip->tsl2x7x_chip_status = TSL2X7X_CHIP_SUSPENDED; | |
838 | ||
839 | ret = i2c_smbus_write_byte_data(chip->client, | |
840 | TSL2X7X_CMD_REG | TSL2X7X_CNTRL, 0x00); | |
841 | ||
842 | if (chip->pdata && chip->pdata->power_off) | |
843 | chip->pdata->power_off(chip->client); | |
844 | ||
845 | return ret; | |
846 | } | |
847 | ||
848 | /** | |
849 | * tsl2x7x_invoke_change | |
850 | * @indio_dev: pointer to IIO device | |
851 | * | |
852 | * Obtain and lock both ALS and PROX resources, | |
853 | * determine and save device state (On/Off), | |
854 | * cycle device to implement updated parameter, | |
855 | * put device back into proper state, and unlock | |
856 | * resource. | |
857 | */ | |
0f3bcfe6 | 858 | static |
3c97c08b JB |
859 | int tsl2x7x_invoke_change(struct iio_dev *indio_dev) |
860 | { | |
861 | struct tsl2X7X_chip *chip = iio_priv(indio_dev); | |
862 | int device_status = chip->tsl2x7x_chip_status; | |
863 | ||
864 | mutex_lock(&chip->als_mutex); | |
865 | mutex_lock(&chip->prox_mutex); | |
866 | ||
867 | if (device_status == TSL2X7X_CHIP_WORKING) | |
868 | tsl2x7x_chip_off(indio_dev); | |
869 | ||
870 | tsl2x7x_chip_on(indio_dev); | |
871 | ||
872 | if (device_status != TSL2X7X_CHIP_WORKING) | |
873 | tsl2x7x_chip_off(indio_dev); | |
874 | ||
875 | mutex_unlock(&chip->prox_mutex); | |
876 | mutex_unlock(&chip->als_mutex); | |
877 | ||
878 | return 0; | |
879 | } | |
880 | ||
881 | static | |
882 | void tsl2x7x_prox_calculate(int *data, int length, | |
883 | struct tsl2x7x_prox_stat *statP) | |
884 | { | |
885 | int i; | |
886 | int sample_sum; | |
887 | int tmp; | |
888 | ||
889 | if (length == 0) | |
890 | length = 1; | |
891 | ||
892 | sample_sum = 0; | |
893 | statP->min = INT_MAX; | |
894 | statP->max = INT_MIN; | |
895 | for (i = 0; i < length; i++) { | |
896 | sample_sum += data[i]; | |
897 | statP->min = min(statP->min, data[i]); | |
898 | statP->max = max(statP->max, data[i]); | |
899 | } | |
900 | ||
901 | statP->mean = sample_sum / length; | |
902 | sample_sum = 0; | |
903 | for (i = 0; i < length; i++) { | |
904 | tmp = data[i] - statP->mean; | |
905 | sample_sum += tmp * tmp; | |
906 | } | |
907 | statP->stddev = int_sqrt((long)sample_sum)/length; | |
908 | } | |
909 | ||
910 | /** | |
911 | * tsl2x7x_prox_cal() - Calculates std. and sets thresholds. | |
912 | * @indio_dev: pointer to IIO device | |
913 | * | |
914 | * Calculates a standard deviation based on the samples, | |
915 | * and sets the threshold accordingly. | |
916 | */ | |
917 | static void tsl2x7x_prox_cal(struct iio_dev *indio_dev) | |
918 | { | |
919 | int prox_history[MAX_SAMPLES_CAL + 1]; | |
920 | int i; | |
921 | struct tsl2x7x_prox_stat prox_stat_data[2]; | |
922 | struct tsl2x7x_prox_stat *calP; | |
923 | struct tsl2X7X_chip *chip = iio_priv(indio_dev); | |
924 | u8 tmp_irq_settings; | |
925 | u8 current_state = chip->tsl2x7x_chip_status; | |
926 | ||
927 | if (chip->tsl2x7x_settings.prox_max_samples_cal > MAX_SAMPLES_CAL) { | |
928 | dev_err(&chip->client->dev, | |
929 | "%s: max prox samples cal is too big: %d\n", | |
930 | __func__, chip->tsl2x7x_settings.prox_max_samples_cal); | |
931 | chip->tsl2x7x_settings.prox_max_samples_cal = MAX_SAMPLES_CAL; | |
932 | } | |
933 | ||
934 | /* have to stop to change settings */ | |
935 | tsl2x7x_chip_off(indio_dev); | |
936 | ||
937 | /* Enable proximity detection save just in case prox not wanted yet*/ | |
938 | tmp_irq_settings = chip->tsl2x7x_settings.interrupts_en; | |
939 | chip->tsl2x7x_settings.interrupts_en |= TSL2X7X_CNTL_PROX_INT_ENBL; | |
940 | ||
941 | /*turn on device if not already on*/ | |
942 | tsl2x7x_chip_on(indio_dev); | |
943 | ||
944 | /*gather the samples*/ | |
945 | for (i = 0; i < chip->tsl2x7x_settings.prox_max_samples_cal; i++) { | |
946 | mdelay(15); | |
947 | tsl2x7x_get_prox(indio_dev); | |
948 | prox_history[i] = chip->prox_data; | |
949 | dev_info(&chip->client->dev, "2 i=%d prox data= %d\n", | |
950 | i, chip->prox_data); | |
951 | } | |
952 | ||
953 | tsl2x7x_chip_off(indio_dev); | |
954 | calP = &prox_stat_data[PROX_STAT_CAL]; | |
955 | tsl2x7x_prox_calculate(prox_history, | |
956 | chip->tsl2x7x_settings.prox_max_samples_cal, calP); | |
957 | chip->tsl2x7x_settings.prox_thres_high = (calP->max << 1) - calP->mean; | |
958 | ||
959 | dev_info(&chip->client->dev, " cal min=%d mean=%d max=%d\n", | |
960 | calP->min, calP->mean, calP->max); | |
961 | dev_info(&chip->client->dev, | |
962 | "%s proximity threshold set to %d\n", | |
963 | chip->client->name, chip->tsl2x7x_settings.prox_thres_high); | |
964 | ||
965 | /* back to the way they were */ | |
966 | chip->tsl2x7x_settings.interrupts_en = tmp_irq_settings; | |
967 | if (current_state == TSL2X7X_CHIP_WORKING) | |
968 | tsl2x7x_chip_on(indio_dev); | |
969 | } | |
970 | ||
971 | static ssize_t tsl2x7x_power_state_show(struct device *dev, | |
972 | struct device_attribute *attr, char *buf) | |
973 | { | |
974 | struct tsl2X7X_chip *chip = iio_priv(dev_get_drvdata(dev)); | |
975 | ||
976 | return snprintf(buf, PAGE_SIZE, "%d\n", chip->tsl2x7x_chip_status); | |
977 | } | |
978 | ||
979 | static ssize_t tsl2x7x_power_state_store(struct device *dev, | |
980 | struct device_attribute *attr, const char *buf, size_t len) | |
981 | { | |
982 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | |
983 | bool value; | |
984 | ||
985 | if (strtobool(buf, &value)) | |
986 | return -EINVAL; | |
987 | ||
988 | if (value) | |
989 | tsl2x7x_chip_on(indio_dev); | |
990 | else | |
991 | tsl2x7x_chip_off(indio_dev); | |
992 | ||
993 | return len; | |
994 | } | |
995 | ||
996 | static ssize_t tsl2x7x_gain_available_show(struct device *dev, | |
997 | struct device_attribute *attr, char *buf) | |
998 | { | |
999 | struct tsl2X7X_chip *chip = iio_priv(dev_get_drvdata(dev)); | |
1000 | ||
1001 | switch (chip->id) { | |
1002 | case tsl2571: | |
1003 | case tsl2671: | |
1004 | case tmd2671: | |
1005 | case tsl2771: | |
1006 | case tmd2771: | |
1007 | return snprintf(buf, PAGE_SIZE, "%s\n", "1 8 16 128"); | |
1008 | break; | |
1009 | } | |
1010 | ||
1011 | return snprintf(buf, PAGE_SIZE, "%s\n", "1 8 16 120"); | |
1012 | } | |
1013 | ||
1014 | static ssize_t tsl2x7x_prox_gain_available_show(struct device *dev, | |
1015 | struct device_attribute *attr, char *buf) | |
1016 | { | |
1017 | return snprintf(buf, PAGE_SIZE, "%s\n", "1 2 4 8"); | |
1018 | } | |
1019 | ||
1020 | static ssize_t tsl2x7x_als_time_show(struct device *dev, | |
1021 | struct device_attribute *attr, char *buf) | |
1022 | { | |
1023 | struct tsl2X7X_chip *chip = iio_priv(dev_get_drvdata(dev)); | |
1024 | int y, z; | |
1025 | ||
1026 | y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1; | |
0f3bcfe6 | 1027 | z = y * TSL2X7X_MIN_ITIME; |
3c97c08b JB |
1028 | y /= 1000; |
1029 | z %= 1000; | |
1030 | ||
1031 | return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z); | |
1032 | } | |
1033 | ||
1034 | static ssize_t tsl2x7x_als_time_store(struct device *dev, | |
1035 | struct device_attribute *attr, const char *buf, size_t len) | |
1036 | { | |
1037 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | |
1038 | struct tsl2X7X_chip *chip = iio_priv(dev_get_drvdata(dev)); | |
1039 | struct tsl2x7x_parse_result result; | |
1040 | ||
1041 | result.integer = 0; | |
1042 | result.fract = 0; | |
1043 | ||
1044 | tsl2x7x_parse_buffer(buf, &result); | |
1045 | ||
1046 | result.fract /= 1000; | |
1047 | result.fract /= 3; | |
1048 | chip->tsl2x7x_settings.als_time = | |
1049 | (TSL2X7X_MAX_TIMER_CNT - (u8)result.fract); | |
1050 | ||
1051 | dev_info(&chip->client->dev, "%s: als time = %d", | |
1052 | __func__, chip->tsl2x7x_settings.als_time); | |
1053 | ||
1054 | tsl2x7x_invoke_change(indio_dev); | |
1055 | ||
1056 | return IIO_VAL_INT_PLUS_MICRO; | |
1057 | } | |
1058 | ||
1059 | static IIO_CONST_ATTR(in_illuminance0_integration_time_available, | |
1060 | ".00272 - .696"); | |
1061 | ||
1062 | static ssize_t tsl2x7x_als_cal_target_show(struct device *dev, | |
1063 | struct device_attribute *attr, char *buf) | |
1064 | { | |
1065 | struct tsl2X7X_chip *chip = iio_priv(dev_get_drvdata(dev)); | |
1066 | ||
1067 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
1068 | chip->tsl2x7x_settings.als_cal_target); | |
1069 | } | |
1070 | ||
1071 | static ssize_t tsl2x7x_als_cal_target_store(struct device *dev, | |
1072 | struct device_attribute *attr, const char *buf, size_t len) | |
1073 | { | |
1074 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | |
1075 | struct tsl2X7X_chip *chip = iio_priv(dev_get_drvdata(dev)); | |
1076 | unsigned long value; | |
1077 | ||
1078 | if (kstrtoul(buf, 0, &value)) | |
1079 | return -EINVAL; | |
1080 | ||
1081 | if (value) | |
1082 | chip->tsl2x7x_settings.als_cal_target = value; | |
1083 | ||
1084 | tsl2x7x_invoke_change(indio_dev); | |
1085 | ||
1086 | return len; | |
1087 | } | |
1088 | ||
1089 | /* persistence settings */ | |
1090 | static ssize_t tsl2x7x_als_persistence_show(struct device *dev, | |
1091 | struct device_attribute *attr, char *buf) | |
1092 | { | |
1093 | struct tsl2X7X_chip *chip = iio_priv(dev_get_drvdata(dev)); | |
1094 | int y, z, filter_delay; | |
1095 | ||
1096 | /* Determine integration time */ | |
1097 | y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1; | |
0f3bcfe6 | 1098 | z = y * TSL2X7X_MIN_ITIME; |
3c97c08b JB |
1099 | filter_delay = z * (chip->tsl2x7x_settings.persistence & 0x0F); |
1100 | y = (filter_delay / 1000); | |
1101 | z = (filter_delay % 1000); | |
1102 | ||
1103 | return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z); | |
1104 | } | |
1105 | ||
1106 | static ssize_t tsl2x7x_als_persistence_store(struct device *dev, | |
1107 | struct device_attribute *attr, const char *buf, size_t len) | |
1108 | { | |
1109 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | |
1110 | struct tsl2X7X_chip *chip = iio_priv(dev_get_drvdata(dev)); | |
1111 | struct tsl2x7x_parse_result result; | |
1112 | int y, z, filter_delay; | |
1113 | ||
1114 | result.integer = 0; | |
1115 | result.fract = 0; | |
1116 | tsl2x7x_parse_buffer(buf, &result); | |
1117 | ||
1118 | result.fract /= 1000; | |
1119 | y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1; | |
0f3bcfe6 | 1120 | z = y * TSL2X7X_MIN_ITIME; |
3c97c08b JB |
1121 | |
1122 | filter_delay = | |
1123 | DIV_ROUND_UP(((result.integer * 1000) + result.fract), z); | |
1124 | ||
1125 | chip->tsl2x7x_settings.persistence &= 0xF0; | |
1126 | chip->tsl2x7x_settings.persistence |= (filter_delay & 0x0F); | |
1127 | ||
1128 | dev_info(&chip->client->dev, "%s: als persistence = %d", | |
1129 | __func__, filter_delay); | |
1130 | ||
1131 | tsl2x7x_invoke_change(indio_dev); | |
1132 | ||
1133 | return IIO_VAL_INT_PLUS_MICRO; | |
1134 | } | |
1135 | ||
1136 | static ssize_t tsl2x7x_prox_persistence_show(struct device *dev, | |
1137 | struct device_attribute *attr, char *buf) | |
1138 | { | |
1139 | struct tsl2X7X_chip *chip = iio_priv(dev_get_drvdata(dev)); | |
1140 | int y, z, filter_delay; | |
1141 | ||
1142 | /* Determine integration time */ | |
1143 | y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.prx_time) + 1; | |
0f3bcfe6 | 1144 | z = y * TSL2X7X_MIN_ITIME; |
3c97c08b JB |
1145 | filter_delay = z * ((chip->tsl2x7x_settings.persistence & 0xF0) >> 4); |
1146 | y = (filter_delay / 1000); | |
1147 | z = (filter_delay % 1000); | |
1148 | ||
1149 | return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z); | |
1150 | } | |
1151 | ||
1152 | static ssize_t tsl2x7x_prox_persistence_store(struct device *dev, | |
1153 | struct device_attribute *attr, const char *buf, size_t len) | |
1154 | { | |
1155 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | |
1156 | struct tsl2X7X_chip *chip = iio_priv(dev_get_drvdata(dev)); | |
1157 | struct tsl2x7x_parse_result result; | |
1158 | int y, z, filter_delay; | |
1159 | ||
1160 | result.integer = 0; | |
1161 | result.fract = 0; | |
1162 | tsl2x7x_parse_buffer(buf, &result); | |
1163 | ||
1164 | result.fract /= 1000; | |
1165 | y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.prx_time) + 1; | |
0f3bcfe6 | 1166 | z = y * TSL2X7X_MIN_ITIME; |
3c97c08b JB |
1167 | |
1168 | filter_delay = | |
1169 | DIV_ROUND_UP(((result.integer * 1000) + result.fract), z); | |
1170 | ||
1171 | chip->tsl2x7x_settings.persistence &= 0x0F; | |
1172 | chip->tsl2x7x_settings.persistence |= ((filter_delay << 4) & 0xF0); | |
1173 | ||
1174 | dev_info(&chip->client->dev, "%s: prox persistence = %d", | |
1175 | __func__, filter_delay); | |
1176 | ||
1177 | tsl2x7x_invoke_change(indio_dev); | |
1178 | ||
1179 | return IIO_VAL_INT_PLUS_MICRO; | |
1180 | } | |
1181 | ||
1182 | static ssize_t tsl2x7x_do_calibrate(struct device *dev, | |
1183 | struct device_attribute *attr, const char *buf, size_t len) | |
1184 | { | |
1185 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | |
1186 | bool value; | |
1187 | ||
1188 | if (strtobool(buf, &value)) | |
1189 | return -EINVAL; | |
1190 | ||
1191 | if (value) | |
1192 | tsl2x7x_als_calibrate(indio_dev); | |
1193 | ||
1194 | tsl2x7x_invoke_change(indio_dev); | |
1195 | ||
1196 | return len; | |
1197 | } | |
1198 | ||
1199 | static ssize_t tsl2x7x_luxtable_show(struct device *dev, | |
1200 | struct device_attribute *attr, char *buf) | |
1201 | { | |
1202 | struct tsl2X7X_chip *chip = iio_priv(dev_get_drvdata(dev)); | |
1203 | int i = 0; | |
1204 | int offset = 0; | |
1205 | ||
1206 | while (i < (TSL2X7X_MAX_LUX_TABLE_SIZE * 3)) { | |
1207 | offset += snprintf(buf + offset, PAGE_SIZE, "%d,%d,%d,", | |
1208 | chip->tsl2x7x_device_lux[i].ratio, | |
1209 | chip->tsl2x7x_device_lux[i].ch0, | |
1210 | chip->tsl2x7x_device_lux[i].ch1); | |
1211 | if (chip->tsl2x7x_device_lux[i].ratio == 0) { | |
1212 | /* We just printed the first "0" entry. | |
1213 | * Now get rid of the extra "," and break. */ | |
1214 | offset--; | |
1215 | break; | |
1216 | } | |
1217 | i++; | |
1218 | } | |
1219 | ||
1220 | offset += snprintf(buf + offset, PAGE_SIZE, "\n"); | |
1221 | return offset; | |
1222 | } | |
1223 | ||
1224 | static ssize_t tsl2x7x_luxtable_store(struct device *dev, | |
1225 | struct device_attribute *attr, const char *buf, size_t len) | |
1226 | { | |
1227 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | |
1228 | struct tsl2X7X_chip *chip = iio_priv(dev_get_drvdata(dev)); | |
1229 | int value[ARRAY_SIZE(chip->tsl2x7x_device_lux)*3 + 1]; | |
1230 | int n; | |
1231 | ||
1232 | get_options(buf, ARRAY_SIZE(value), value); | |
1233 | ||
1234 | /* We now have an array of ints starting at value[1], and | |
1235 | * enumerated by value[0]. | |
1236 | * We expect each group of three ints is one table entry, | |
1237 | * and the last table entry is all 0. | |
1238 | */ | |
1239 | n = value[0]; | |
1240 | if ((n % 3) || n < 6 || | |
1241 | n > ((ARRAY_SIZE(chip->tsl2x7x_device_lux) - 1) * 3)) { | |
1242 | dev_info(dev, "LUX TABLE INPUT ERROR 1 Value[0]=%d\n", n); | |
1243 | return -EINVAL; | |
1244 | } | |
1245 | ||
1246 | if ((value[(n - 2)] | value[(n - 1)] | value[n]) != 0) { | |
1247 | dev_info(dev, "LUX TABLE INPUT ERROR 2 Value[0]=%d\n", n); | |
1248 | return -EINVAL; | |
1249 | } | |
1250 | ||
1251 | if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING) | |
1252 | tsl2x7x_chip_off(indio_dev); | |
1253 | ||
1254 | /* Zero out the table */ | |
1255 | memset(chip->tsl2x7x_device_lux, 0, sizeof(chip->tsl2x7x_device_lux)); | |
1256 | memcpy(chip->tsl2x7x_device_lux, &value[1], (value[0] * 4)); | |
1257 | ||
1258 | tsl2x7x_invoke_change(indio_dev); | |
1259 | ||
1260 | return len; | |
1261 | } | |
1262 | ||
1263 | static ssize_t tsl2x7x_do_prox_calibrate(struct device *dev, | |
1264 | struct device_attribute *attr, const char *buf, size_t len) | |
1265 | { | |
1266 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | |
1267 | bool value; | |
1268 | ||
1269 | if (strtobool(buf, &value)) | |
1270 | return -EINVAL; | |
1271 | ||
1272 | if (value) | |
1273 | tsl2x7x_prox_cal(indio_dev); | |
1274 | ||
1275 | tsl2x7x_invoke_change(indio_dev); | |
1276 | ||
1277 | return len; | |
1278 | } | |
1279 | ||
1280 | static int tsl2x7x_read_interrupt_config(struct iio_dev *indio_dev, | |
1281 | u64 event_code) | |
1282 | { | |
1283 | struct tsl2X7X_chip *chip = iio_priv(indio_dev); | |
1284 | int ret; | |
1285 | ||
1286 | if (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code) == IIO_INTENSITY) | |
1287 | ret = !!(chip->tsl2x7x_settings.interrupts_en & 0x10); | |
1288 | else | |
1289 | ret = !!(chip->tsl2x7x_settings.interrupts_en & 0x20); | |
1290 | ||
1291 | return ret; | |
1292 | } | |
1293 | ||
1294 | static int tsl2x7x_write_interrupt_config(struct iio_dev *indio_dev, | |
1295 | u64 event_code, | |
1296 | int val) | |
1297 | { | |
1298 | struct tsl2X7X_chip *chip = iio_priv(indio_dev); | |
1299 | ||
1300 | if (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code) == IIO_INTENSITY) { | |
1301 | if (val) | |
1302 | chip->tsl2x7x_settings.interrupts_en |= 0x10; | |
1303 | else | |
1304 | chip->tsl2x7x_settings.interrupts_en &= 0x20; | |
1305 | } else { | |
1306 | if (val) | |
1307 | chip->tsl2x7x_settings.interrupts_en |= 0x20; | |
1308 | else | |
1309 | chip->tsl2x7x_settings.interrupts_en &= 0x10; | |
1310 | } | |
1311 | ||
1312 | tsl2x7x_invoke_change(indio_dev); | |
1313 | ||
1314 | return 0; | |
1315 | } | |
1316 | ||
1317 | static int tsl2x7x_write_thresh(struct iio_dev *indio_dev, | |
1318 | u64 event_code, | |
1319 | int val) | |
1320 | { | |
1321 | struct tsl2X7X_chip *chip = iio_priv(indio_dev); | |
1322 | ||
1323 | if (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code) == IIO_INTENSITY) { | |
1324 | switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) { | |
1325 | case IIO_EV_DIR_RISING: | |
1326 | chip->tsl2x7x_settings.als_thresh_high = val; | |
1327 | break; | |
1328 | case IIO_EV_DIR_FALLING: | |
1329 | chip->tsl2x7x_settings.als_thresh_low = val; | |
1330 | break; | |
1331 | default: | |
1332 | return -EINVAL; | |
1333 | } | |
1334 | } else { | |
1335 | switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) { | |
1336 | case IIO_EV_DIR_RISING: | |
1337 | chip->tsl2x7x_settings.prox_thres_high = val; | |
1338 | break; | |
1339 | case IIO_EV_DIR_FALLING: | |
1340 | chip->tsl2x7x_settings.prox_thres_low = val; | |
1341 | break; | |
1342 | default: | |
1343 | return -EINVAL; | |
1344 | } | |
1345 | } | |
1346 | ||
1347 | tsl2x7x_invoke_change(indio_dev); | |
1348 | ||
1349 | return 0; | |
1350 | } | |
1351 | ||
1352 | static int tsl2x7x_read_thresh(struct iio_dev *indio_dev, | |
1353 | u64 event_code, | |
1354 | int *val) | |
1355 | { | |
1356 | struct tsl2X7X_chip *chip = iio_priv(indio_dev); | |
1357 | ||
1358 | if (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code) == IIO_INTENSITY) { | |
1359 | switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) { | |
1360 | case IIO_EV_DIR_RISING: | |
1361 | *val = chip->tsl2x7x_settings.als_thresh_high; | |
1362 | break; | |
1363 | case IIO_EV_DIR_FALLING: | |
1364 | *val = chip->tsl2x7x_settings.als_thresh_low; | |
1365 | break; | |
1366 | default: | |
1367 | return -EINVAL; | |
1368 | } | |
1369 | } else { | |
1370 | switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) { | |
1371 | case IIO_EV_DIR_RISING: | |
1372 | *val = chip->tsl2x7x_settings.prox_thres_high; | |
1373 | break; | |
1374 | case IIO_EV_DIR_FALLING: | |
1375 | *val = chip->tsl2x7x_settings.prox_thres_low; | |
1376 | break; | |
1377 | default: | |
1378 | return -EINVAL; | |
1379 | } | |
1380 | } | |
1381 | ||
1382 | return 0; | |
1383 | } | |
1384 | ||
1385 | static int tsl2x7x_read_raw(struct iio_dev *indio_dev, | |
1386 | struct iio_chan_spec const *chan, | |
1387 | int *val, | |
1388 | int *val2, | |
1389 | long mask) | |
1390 | { | |
1391 | int ret = -EINVAL; | |
1392 | struct tsl2X7X_chip *chip = iio_priv(indio_dev); | |
1393 | ||
1394 | switch (mask) { | |
0f3bcfe6 | 1395 | case IIO_CHAN_INFO_PROCESSED: |
3c97c08b JB |
1396 | switch (chan->type) { |
1397 | case IIO_LIGHT: | |
1398 | tsl2x7x_get_lux(indio_dev); | |
1399 | *val = chip->als_cur_info.lux; | |
1400 | ret = IIO_VAL_INT; | |
1401 | break; | |
0f3bcfe6 JB |
1402 | default: |
1403 | return -EINVAL; | |
1404 | break; | |
1405 | } | |
1406 | break; | |
1407 | case IIO_CHAN_INFO_RAW: | |
1408 | switch (chan->type) { | |
3c97c08b JB |
1409 | case IIO_INTENSITY: |
1410 | tsl2x7x_get_lux(indio_dev); | |
1411 | if (chan->channel == 0) | |
1412 | *val = chip->als_cur_info.als_ch0; | |
1413 | else | |
1414 | *val = chip->als_cur_info.als_ch1; | |
1415 | ret = IIO_VAL_INT; | |
1416 | break; | |
1417 | case IIO_PROXIMITY: | |
1418 | tsl2x7x_get_prox(indio_dev); | |
1419 | *val = chip->prox_data; | |
1420 | ret = IIO_VAL_INT; | |
1421 | break; | |
1422 | default: | |
1423 | return -EINVAL; | |
1424 | break; | |
1425 | } | |
1426 | break; | |
1427 | case IIO_CHAN_INFO_CALIBSCALE: | |
1428 | if (chan->type == IIO_LIGHT) | |
1429 | *val = | |
1430 | tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain]; | |
1431 | else | |
1432 | *val = | |
1433 | tsl2X7X_prx_gainadj[chip->tsl2x7x_settings.prox_gain]; | |
1434 | ret = IIO_VAL_INT; | |
1435 | break; | |
1436 | case IIO_CHAN_INFO_CALIBBIAS: | |
1437 | *val = chip->tsl2x7x_settings.als_gain_trim; | |
1438 | ret = IIO_VAL_INT; | |
1439 | break; | |
1440 | ||
1441 | default: | |
1442 | ret = -EINVAL; | |
1443 | } | |
1444 | ||
1445 | return ret; | |
1446 | } | |
1447 | ||
1448 | static int tsl2x7x_write_raw(struct iio_dev *indio_dev, | |
1449 | struct iio_chan_spec const *chan, | |
1450 | int val, | |
1451 | int val2, | |
1452 | long mask) | |
1453 | { | |
1454 | struct tsl2X7X_chip *chip = iio_priv(indio_dev); | |
1455 | ||
1456 | switch (mask) { | |
1457 | case IIO_CHAN_INFO_CALIBSCALE: | |
1458 | if (chan->type == IIO_INTENSITY) { | |
1459 | switch (val) { | |
1460 | case 1: | |
1461 | chip->tsl2x7x_settings.als_gain = 0; | |
1462 | break; | |
1463 | case 8: | |
1464 | chip->tsl2x7x_settings.als_gain = 1; | |
1465 | break; | |
1466 | case 16: | |
1467 | chip->tsl2x7x_settings.als_gain = 2; | |
1468 | break; | |
1469 | case 120: | |
1470 | switch (chip->id) { | |
1471 | case tsl2572: | |
1472 | case tsl2672: | |
1473 | case tmd2672: | |
1474 | case tsl2772: | |
1475 | case tmd2772: | |
1476 | return -EINVAL; | |
1477 | break; | |
1478 | } | |
1479 | chip->tsl2x7x_settings.als_gain = 3; | |
1480 | break; | |
1481 | case 128: | |
1482 | switch (chip->id) { | |
1483 | case tsl2571: | |
1484 | case tsl2671: | |
1485 | case tmd2671: | |
1486 | case tsl2771: | |
1487 | case tmd2771: | |
1488 | return -EINVAL; | |
1489 | break; | |
1490 | } | |
1491 | chip->tsl2x7x_settings.als_gain = 3; | |
1492 | break; | |
1493 | default: | |
1494 | return -EINVAL; | |
1495 | } | |
1496 | } else { | |
1497 | switch (val) { | |
1498 | case 1: | |
1499 | chip->tsl2x7x_settings.prox_gain = 0; | |
1500 | break; | |
1501 | case 2: | |
1502 | chip->tsl2x7x_settings.prox_gain = 1; | |
1503 | break; | |
1504 | case 4: | |
1505 | chip->tsl2x7x_settings.prox_gain = 2; | |
1506 | break; | |
1507 | case 8: | |
1508 | chip->tsl2x7x_settings.prox_gain = 3; | |
1509 | break; | |
1510 | default: | |
1511 | return -EINVAL; | |
1512 | } | |
1513 | } | |
1514 | break; | |
1515 | case IIO_CHAN_INFO_CALIBBIAS: | |
1516 | chip->tsl2x7x_settings.als_gain_trim = val; | |
1517 | break; | |
1518 | ||
1519 | default: | |
1520 | return -EINVAL; | |
1521 | } | |
1522 | ||
1523 | tsl2x7x_invoke_change(indio_dev); | |
1524 | ||
1525 | return 0; | |
1526 | } | |
1527 | ||
1528 | static DEVICE_ATTR(power_state, S_IRUGO | S_IWUSR, | |
1529 | tsl2x7x_power_state_show, tsl2x7x_power_state_store); | |
1530 | ||
1531 | static DEVICE_ATTR(in_proximity0_calibscale_available, S_IRUGO, | |
1532 | tsl2x7x_prox_gain_available_show, NULL); | |
1533 | ||
1534 | static DEVICE_ATTR(in_illuminance0_calibscale_available, S_IRUGO, | |
1535 | tsl2x7x_gain_available_show, NULL); | |
1536 | ||
1537 | static DEVICE_ATTR(in_illuminance0_integration_time, S_IRUGO | S_IWUSR, | |
1538 | tsl2x7x_als_time_show, tsl2x7x_als_time_store); | |
1539 | ||
1540 | static DEVICE_ATTR(in_illuminance0_target_input, S_IRUGO | S_IWUSR, | |
1541 | tsl2x7x_als_cal_target_show, tsl2x7x_als_cal_target_store); | |
1542 | ||
1543 | static DEVICE_ATTR(in_illuminance0_calibrate, S_IWUSR, NULL, | |
1544 | tsl2x7x_do_calibrate); | |
1545 | ||
1546 | static DEVICE_ATTR(in_proximity0_calibrate, S_IWUSR, NULL, | |
1547 | tsl2x7x_do_prox_calibrate); | |
1548 | ||
1549 | static DEVICE_ATTR(in_illuminance0_lux_table, S_IRUGO | S_IWUSR, | |
1550 | tsl2x7x_luxtable_show, tsl2x7x_luxtable_store); | |
1551 | ||
1552 | static DEVICE_ATTR(in_intensity0_thresh_period, S_IRUGO | S_IWUSR, | |
1553 | tsl2x7x_als_persistence_show, tsl2x7x_als_persistence_store); | |
1554 | ||
1555 | static DEVICE_ATTR(in_proximity0_thresh_period, S_IRUGO | S_IWUSR, | |
1556 | tsl2x7x_prox_persistence_show, tsl2x7x_prox_persistence_store); | |
1557 | ||
1558 | /* Use the default register values to identify the Taos device */ | |
1559 | static int tsl2x7x_device_id(unsigned char *id, int target) | |
1560 | { | |
1561 | switch (target) { | |
1562 | case tsl2571: | |
1563 | case tsl2671: | |
1564 | case tsl2771: | |
1565 | return ((*id & 0xf0) == TRITON_ID); | |
1566 | break; | |
1567 | case tmd2671: | |
1568 | case tmd2771: | |
1569 | return ((*id & 0xf0) == HALIBUT_ID); | |
1570 | break; | |
1571 | case tsl2572: | |
1572 | case tsl2672: | |
1573 | case tmd2672: | |
1574 | case tsl2772: | |
1575 | case tmd2772: | |
1576 | return ((*id & 0xf0) == SWORDFISH_ID); | |
1577 | break; | |
1578 | } | |
1579 | ||
1580 | return -EINVAL; | |
1581 | } | |
1582 | ||
1583 | static irqreturn_t tsl2x7x_event_handler(int irq, void *private) | |
1584 | { | |
1585 | struct iio_dev *indio_dev = private; | |
1586 | struct tsl2X7X_chip *chip = iio_priv(indio_dev); | |
1587 | s64 timestamp = iio_get_time_ns(); | |
1588 | int ret; | |
1589 | u8 value; | |
1590 | ||
1591 | value = i2c_smbus_read_byte_data(chip->client, | |
1592 | TSL2X7X_CMD_REG | TSL2X7X_STATUS); | |
1593 | ||
1594 | /* What type of interrupt do we need to process */ | |
1595 | if (value & TSL2X7X_STA_PRX_INTR) { | |
1596 | tsl2x7x_get_prox(indio_dev); /* freshen data for ABI */ | |
1597 | iio_push_event(indio_dev, | |
1598 | IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, | |
1599 | 0, | |
1600 | IIO_EV_TYPE_THRESH, | |
1601 | IIO_EV_DIR_EITHER), | |
1602 | timestamp); | |
1603 | } | |
1604 | ||
1605 | if (value & TSL2X7X_STA_ALS_INTR) { | |
1606 | tsl2x7x_get_lux(indio_dev); /* freshen data for ABI */ | |
1607 | iio_push_event(indio_dev, | |
1608 | IIO_UNMOD_EVENT_CODE(IIO_LIGHT, | |
1609 | 0, | |
1610 | IIO_EV_TYPE_THRESH, | |
1611 | IIO_EV_DIR_EITHER), | |
1612 | timestamp); | |
1613 | } | |
1614 | /* Clear interrupt now that we have handled it. */ | |
1615 | ret = i2c_smbus_write_byte(chip->client, | |
1616 | TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN | | |
1617 | TSL2X7X_CMD_PROXALS_INT_CLR); | |
1618 | if (ret < 0) | |
1619 | dev_err(&chip->client->dev, | |
1620 | "%s: Failed to clear irq from event handler. err = %d\n", | |
1621 | __func__, ret); | |
1622 | ||
1623 | return IRQ_HANDLED; | |
1624 | } | |
1625 | ||
1626 | static struct attribute *tsl2x7x_ALS_device_attrs[] = { | |
1627 | &dev_attr_power_state.attr, | |
1628 | &dev_attr_in_illuminance0_calibscale_available.attr, | |
1629 | &dev_attr_in_illuminance0_integration_time.attr, | |
1630 | &iio_const_attr_in_illuminance0_integration_time_available\ | |
1631 | .dev_attr.attr, | |
1632 | &dev_attr_in_illuminance0_target_input.attr, | |
1633 | &dev_attr_in_illuminance0_calibrate.attr, | |
1634 | &dev_attr_in_illuminance0_lux_table.attr, | |
1635 | NULL | |
1636 | }; | |
1637 | ||
1638 | static struct attribute *tsl2x7x_PRX_device_attrs[] = { | |
1639 | &dev_attr_power_state.attr, | |
1640 | &dev_attr_in_proximity0_calibrate.attr, | |
1641 | NULL | |
1642 | }; | |
1643 | ||
1644 | static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = { | |
1645 | &dev_attr_power_state.attr, | |
1646 | &dev_attr_in_illuminance0_calibscale_available.attr, | |
1647 | &dev_attr_in_illuminance0_integration_time.attr, | |
1648 | &iio_const_attr_in_illuminance0_integration_time_available\ | |
1649 | .dev_attr.attr, | |
1650 | &dev_attr_in_illuminance0_target_input.attr, | |
1651 | &dev_attr_in_illuminance0_calibrate.attr, | |
1652 | &dev_attr_in_illuminance0_lux_table.attr, | |
1653 | &dev_attr_in_proximity0_calibrate.attr, | |
1654 | NULL | |
1655 | }; | |
1656 | ||
1657 | static struct attribute *tsl2x7x_PRX2_device_attrs[] = { | |
1658 | &dev_attr_power_state.attr, | |
1659 | &dev_attr_in_proximity0_calibrate.attr, | |
1660 | &dev_attr_in_proximity0_calibscale_available.attr, | |
1661 | NULL | |
1662 | }; | |
1663 | ||
1664 | static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = { | |
1665 | &dev_attr_power_state.attr, | |
1666 | &dev_attr_in_illuminance0_calibscale_available.attr, | |
1667 | &dev_attr_in_illuminance0_integration_time.attr, | |
1668 | &iio_const_attr_in_illuminance0_integration_time_available\ | |
1669 | .dev_attr.attr, | |
1670 | &dev_attr_in_illuminance0_target_input.attr, | |
1671 | &dev_attr_in_illuminance0_calibrate.attr, | |
1672 | &dev_attr_in_illuminance0_lux_table.attr, | |
1673 | &dev_attr_in_proximity0_calibrate.attr, | |
1674 | &dev_attr_in_proximity0_calibscale_available.attr, | |
1675 | NULL | |
1676 | }; | |
1677 | ||
1678 | static struct attribute *tsl2X7X_ALS_event_attrs[] = { | |
1679 | &dev_attr_in_intensity0_thresh_period.attr, | |
1680 | NULL, | |
1681 | }; | |
1682 | static struct attribute *tsl2X7X_PRX_event_attrs[] = { | |
1683 | &dev_attr_in_proximity0_thresh_period.attr, | |
1684 | NULL, | |
1685 | }; | |
1686 | ||
1687 | static struct attribute *tsl2X7X_ALSPRX_event_attrs[] = { | |
1688 | &dev_attr_in_intensity0_thresh_period.attr, | |
1689 | &dev_attr_in_proximity0_thresh_period.attr, | |
1690 | NULL, | |
1691 | }; | |
1692 | ||
1693 | static const struct attribute_group tsl2X7X_device_attr_group_tbl[] = { | |
1694 | [ALS] = { | |
1695 | .attrs = tsl2x7x_ALS_device_attrs, | |
1696 | }, | |
1697 | [PRX] = { | |
1698 | .attrs = tsl2x7x_PRX_device_attrs, | |
1699 | }, | |
1700 | [ALSPRX] = { | |
1701 | .attrs = tsl2x7x_ALSPRX_device_attrs, | |
1702 | }, | |
1703 | [PRX2] = { | |
1704 | .attrs = tsl2x7x_PRX2_device_attrs, | |
1705 | }, | |
1706 | [ALSPRX2] = { | |
1707 | .attrs = tsl2x7x_ALSPRX2_device_attrs, | |
1708 | }, | |
1709 | }; | |
1710 | ||
1711 | static struct attribute_group tsl2X7X_event_attr_group_tbl[] = { | |
1712 | [ALS] = { | |
1713 | .attrs = tsl2X7X_ALS_event_attrs, | |
1714 | .name = "events", | |
1715 | }, | |
1716 | [PRX] = { | |
1717 | .attrs = tsl2X7X_PRX_event_attrs, | |
1718 | .name = "events", | |
1719 | }, | |
1720 | [ALSPRX] = { | |
1721 | .attrs = tsl2X7X_ALSPRX_event_attrs, | |
1722 | .name = "events", | |
1723 | }, | |
1724 | }; | |
1725 | ||
1726 | static const struct iio_info tsl2X7X_device_info[] = { | |
1727 | [ALS] = { | |
1728 | .attrs = &tsl2X7X_device_attr_group_tbl[ALS], | |
1729 | .event_attrs = &tsl2X7X_event_attr_group_tbl[ALS], | |
1730 | .driver_module = THIS_MODULE, | |
1731 | .read_raw = &tsl2x7x_read_raw, | |
1732 | .write_raw = &tsl2x7x_write_raw, | |
1733 | .read_event_value = &tsl2x7x_read_thresh, | |
1734 | .write_event_value = &tsl2x7x_write_thresh, | |
1735 | .read_event_config = &tsl2x7x_read_interrupt_config, | |
1736 | .write_event_config = &tsl2x7x_write_interrupt_config, | |
1737 | }, | |
1738 | [PRX] = { | |
1739 | .attrs = &tsl2X7X_device_attr_group_tbl[PRX], | |
1740 | .event_attrs = &tsl2X7X_event_attr_group_tbl[PRX], | |
1741 | .driver_module = THIS_MODULE, | |
1742 | .read_raw = &tsl2x7x_read_raw, | |
1743 | .write_raw = &tsl2x7x_write_raw, | |
1744 | .read_event_value = &tsl2x7x_read_thresh, | |
1745 | .write_event_value = &tsl2x7x_write_thresh, | |
1746 | .read_event_config = &tsl2x7x_read_interrupt_config, | |
1747 | .write_event_config = &tsl2x7x_write_interrupt_config, | |
1748 | }, | |
1749 | [ALSPRX] = { | |
1750 | .attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX], | |
1751 | .event_attrs = &tsl2X7X_event_attr_group_tbl[ALSPRX], | |
1752 | .driver_module = THIS_MODULE, | |
1753 | .read_raw = &tsl2x7x_read_raw, | |
1754 | .write_raw = &tsl2x7x_write_raw, | |
1755 | .read_event_value = &tsl2x7x_read_thresh, | |
1756 | .write_event_value = &tsl2x7x_write_thresh, | |
1757 | .read_event_config = &tsl2x7x_read_interrupt_config, | |
1758 | .write_event_config = &tsl2x7x_write_interrupt_config, | |
1759 | }, | |
1760 | [PRX2] = { | |
1761 | .attrs = &tsl2X7X_device_attr_group_tbl[PRX2], | |
1762 | .event_attrs = &tsl2X7X_event_attr_group_tbl[PRX], | |
1763 | .driver_module = THIS_MODULE, | |
1764 | .read_raw = &tsl2x7x_read_raw, | |
1765 | .write_raw = &tsl2x7x_write_raw, | |
1766 | .read_event_value = &tsl2x7x_read_thresh, | |
1767 | .write_event_value = &tsl2x7x_write_thresh, | |
1768 | .read_event_config = &tsl2x7x_read_interrupt_config, | |
1769 | .write_event_config = &tsl2x7x_write_interrupt_config, | |
1770 | }, | |
1771 | [ALSPRX2] = { | |
1772 | .attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX2], | |
1773 | .event_attrs = &tsl2X7X_event_attr_group_tbl[ALSPRX], | |
1774 | .driver_module = THIS_MODULE, | |
1775 | .read_raw = &tsl2x7x_read_raw, | |
1776 | .write_raw = &tsl2x7x_write_raw, | |
1777 | .read_event_value = &tsl2x7x_read_thresh, | |
1778 | .write_event_value = &tsl2x7x_write_thresh, | |
1779 | .read_event_config = &tsl2x7x_read_interrupt_config, | |
1780 | .write_event_config = &tsl2x7x_write_interrupt_config, | |
1781 | }, | |
1782 | }; | |
1783 | ||
1784 | static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = { | |
1785 | [ALS] = { | |
1786 | .channel = { | |
1787 | { | |
1788 | .type = IIO_LIGHT, | |
1789 | .indexed = 1, | |
1790 | .channel = 0, | |
1791 | .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT, | |
1792 | }, { | |
1793 | .type = IIO_INTENSITY, | |
1794 | .indexed = 1, | |
1795 | .channel = 0, | |
1796 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | | |
1797 | IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | | |
1798 | IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, | |
1799 | .event_mask = TSL2X7X_EVENT_MASK | |
1800 | }, { | |
1801 | .type = IIO_INTENSITY, | |
1802 | .indexed = 1, | |
1803 | .channel = 1, | |
1804 | }, | |
1805 | }, | |
1806 | .chan_table_elements = 3, | |
1807 | .info = &tsl2X7X_device_info[ALS], | |
1808 | }, | |
1809 | [PRX] = { | |
1810 | .channel = { | |
1811 | { | |
1812 | .type = IIO_PROXIMITY, | |
1813 | .indexed = 1, | |
1814 | .channel = 0, | |
1815 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, | |
1816 | .event_mask = TSL2X7X_EVENT_MASK | |
1817 | }, | |
1818 | }, | |
1819 | .chan_table_elements = 1, | |
1820 | .info = &tsl2X7X_device_info[PRX], | |
1821 | }, | |
1822 | [ALSPRX] = { | |
1823 | .channel = { | |
1824 | { | |
1825 | .type = IIO_LIGHT, | |
1826 | .indexed = 1, | |
1827 | .channel = 0, | |
1828 | .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT | |
1829 | }, { | |
1830 | .type = IIO_INTENSITY, | |
1831 | .indexed = 1, | |
1832 | .channel = 0, | |
1833 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | | |
1834 | IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | | |
1835 | IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, | |
1836 | .event_mask = TSL2X7X_EVENT_MASK | |
1837 | }, { | |
1838 | .type = IIO_INTENSITY, | |
1839 | .indexed = 1, | |
1840 | .channel = 1, | |
1841 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, | |
1842 | }, { | |
1843 | .type = IIO_PROXIMITY, | |
1844 | .indexed = 1, | |
1845 | .channel = 0, | |
1846 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, | |
1847 | .event_mask = TSL2X7X_EVENT_MASK | |
1848 | }, | |
1849 | }, | |
1850 | .chan_table_elements = 4, | |
1851 | .info = &tsl2X7X_device_info[ALSPRX], | |
1852 | }, | |
1853 | [PRX2] = { | |
1854 | .channel = { | |
1855 | { | |
1856 | .type = IIO_PROXIMITY, | |
1857 | .indexed = 1, | |
1858 | .channel = 0, | |
1859 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | | |
1860 | IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT, | |
1861 | .event_mask = TSL2X7X_EVENT_MASK | |
1862 | }, | |
1863 | }, | |
1864 | .chan_table_elements = 1, | |
1865 | .info = &tsl2X7X_device_info[PRX2], | |
1866 | }, | |
1867 | [ALSPRX2] = { | |
1868 | .channel = { | |
1869 | { | |
1870 | .type = IIO_LIGHT, | |
1871 | .indexed = 1, | |
1872 | .channel = 0, | |
1873 | .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT, | |
1874 | }, { | |
1875 | .type = IIO_INTENSITY, | |
1876 | .indexed = 1, | |
1877 | .channel = 0, | |
1878 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | | |
1879 | IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | | |
1880 | IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, | |
1881 | .event_mask = TSL2X7X_EVENT_MASK | |
1882 | }, { | |
1883 | .type = IIO_INTENSITY, | |
1884 | .indexed = 1, | |
1885 | .channel = 1, | |
1886 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, | |
1887 | }, { | |
1888 | .type = IIO_PROXIMITY, | |
1889 | .indexed = 1, | |
1890 | .channel = 0, | |
1891 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | | |
1892 | IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT, | |
1893 | .event_mask = TSL2X7X_EVENT_MASK | |
1894 | }, | |
1895 | }, | |
1896 | .chan_table_elements = 4, | |
1897 | .info = &tsl2X7X_device_info[ALSPRX2], | |
1898 | }, | |
1899 | }; | |
1900 | ||
1901 | static int __devinit tsl2x7x_probe(struct i2c_client *clientp, | |
1902 | const struct i2c_device_id *id) | |
1903 | { | |
1904 | int ret; | |
1905 | unsigned char device_id; | |
1906 | struct iio_dev *indio_dev; | |
1907 | struct tsl2X7X_chip *chip; | |
1908 | ||
1909 | indio_dev = iio_allocate_device(sizeof(*chip)); | |
1910 | if (!indio_dev) | |
1911 | return -ENOMEM; | |
1912 | ||
1913 | chip = iio_priv(indio_dev); | |
1914 | chip->client = clientp; | |
1915 | i2c_set_clientdata(clientp, indio_dev); | |
1916 | ||
1917 | ret = tsl2x7x_i2c_read(chip->client, | |
1918 | TSL2X7X_CHIPID, &device_id); | |
1919 | if (ret < 0) | |
1920 | goto fail1; | |
1921 | ||
1922 | if ((!tsl2x7x_device_id(&device_id, id->driver_data)) || | |
1923 | (tsl2x7x_device_id(&device_id, id->driver_data) == -EINVAL)) { | |
1924 | dev_info(&chip->client->dev, | |
1925 | "%s: i2c device found does not match expected id\n", | |
1926 | __func__); | |
1927 | goto fail1; | |
1928 | } | |
1929 | ||
1930 | ret = i2c_smbus_write_byte(clientp, (TSL2X7X_CMD_REG | TSL2X7X_CNTRL)); | |
1931 | if (ret < 0) { | |
1932 | dev_err(&clientp->dev, "%s: write to cmd reg failed. err = %d\n", | |
1933 | __func__, ret); | |
1934 | goto fail1; | |
1935 | } | |
1936 | ||
1937 | /* ALS and PROX functions can be invoked via user space poll | |
1938 | * or H/W interrupt. If busy return last sample. */ | |
1939 | mutex_init(&chip->als_mutex); | |
1940 | mutex_init(&chip->prox_mutex); | |
1941 | ||
1942 | chip->tsl2x7x_chip_status = TSL2X7X_CHIP_UNKNOWN; | |
1943 | chip->pdata = clientp->dev.platform_data; | |
1944 | chip->id = id->driver_data; | |
1945 | chip->chip_info = | |
1946 | &tsl2x7x_chip_info_tbl[device_channel_config[id->driver_data]]; | |
1947 | ||
1948 | indio_dev->info = chip->chip_info->info; | |
1949 | indio_dev->dev.parent = &clientp->dev; | |
1950 | indio_dev->modes = INDIO_DIRECT_MODE; | |
1951 | indio_dev->name = chip->client->name; | |
1952 | indio_dev->channels = chip->chip_info->channel; | |
1953 | indio_dev->num_channels = chip->chip_info->chan_table_elements; | |
1954 | ||
1955 | if (clientp->irq) { | |
1956 | ret = request_threaded_irq(clientp->irq, | |
1957 | NULL, | |
1958 | &tsl2x7x_event_handler, | |
1959 | IRQF_TRIGGER_RISING | IRQF_ONESHOT, | |
1960 | "TSL2X7X_event", | |
1961 | indio_dev); | |
1962 | if (ret) { | |
1963 | dev_err(&clientp->dev, | |
1964 | "%s: irq request failed", __func__); | |
1965 | goto fail2; | |
1966 | } | |
1967 | } | |
1968 | ||
1969 | /* Load up the defaults */ | |
1970 | tsl2x7x_defaults(chip); | |
1971 | /* Make sure the chip is on */ | |
1972 | tsl2x7x_chip_on(indio_dev); | |
1973 | ||
1974 | ret = iio_device_register(indio_dev); | |
1975 | if (ret) { | |
1976 | dev_err(&clientp->dev, | |
1977 | "%s: iio registration failed\n", __func__); | |
1978 | goto fail1; | |
1979 | } | |
1980 | ||
1981 | dev_info(&clientp->dev, "%s Light sensor found.\n", id->name); | |
1982 | ||
1983 | return 0; | |
1984 | ||
1985 | fail1: | |
1986 | if (clientp->irq) | |
1987 | free_irq(clientp->irq, indio_dev); | |
1988 | fail2: | |
1989 | iio_free_device(indio_dev); | |
1990 | ||
1991 | return ret; | |
1992 | } | |
1993 | ||
1994 | static int tsl2x7x_suspend(struct device *dev) | |
1995 | { | |
1996 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | |
1997 | struct tsl2X7X_chip *chip = iio_priv(indio_dev); | |
1998 | int ret = 0; | |
1999 | ||
2000 | if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING) { | |
2001 | ret = tsl2x7x_chip_off(indio_dev); | |
2002 | chip->tsl2x7x_chip_status = TSL2X7X_CHIP_SUSPENDED; | |
2003 | } | |
2004 | ||
2005 | if (chip->pdata && chip->pdata->platform_power) { | |
2006 | pm_message_t pmm = {PM_EVENT_SUSPEND}; | |
2007 | chip->pdata->platform_power(dev, pmm); | |
2008 | } | |
2009 | ||
2010 | return ret; | |
2011 | } | |
2012 | ||
2013 | static int tsl2x7x_resume(struct device *dev) | |
2014 | { | |
2015 | struct iio_dev *indio_dev = dev_get_drvdata(dev); | |
2016 | struct tsl2X7X_chip *chip = iio_priv(indio_dev); | |
2017 | int ret = 0; | |
2018 | ||
2019 | if (chip->pdata && chip->pdata->platform_power) { | |
2020 | pm_message_t pmm = {PM_EVENT_RESUME}; | |
2021 | chip->pdata->platform_power(dev, pmm); | |
2022 | } | |
2023 | ||
2024 | if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_SUSPENDED) | |
2025 | ret = tsl2x7x_chip_on(indio_dev); | |
2026 | ||
2027 | return ret; | |
2028 | } | |
2029 | ||
2030 | static int __devexit tsl2x7x_remove(struct i2c_client *client) | |
2031 | { | |
2032 | struct tsl2X7X_chip *chip = i2c_get_clientdata(client); | |
2033 | struct iio_dev *indio_dev = iio_priv_to_dev(chip); | |
2034 | ||
2035 | tsl2x7x_chip_off(indio_dev); | |
2036 | ||
2037 | iio_device_unregister(indio_dev); | |
2038 | if (client->irq) | |
2039 | free_irq(client->irq, chip->client->name); | |
2040 | ||
2041 | iio_free_device(indio_dev); | |
2042 | ||
2043 | return 0; | |
2044 | } | |
2045 | ||
2046 | static struct i2c_device_id tsl2x7x_idtable[] = { | |
2047 | { "tsl2571", tsl2571 }, | |
2048 | { "tsl2671", tsl2671 }, | |
2049 | { "tmd2671", tmd2671 }, | |
2050 | { "tsl2771", tsl2771 }, | |
2051 | { "tmd2771", tmd2771 }, | |
2052 | { "tsl2572", tsl2572 }, | |
2053 | { "tsl2672", tsl2672 }, | |
2054 | { "tmd2672", tmd2672 }, | |
2055 | { "tsl2772", tsl2772 }, | |
2056 | { "tmd2772", tmd2772 }, | |
2057 | {} | |
2058 | }; | |
2059 | ||
2060 | MODULE_DEVICE_TABLE(i2c, tsl2x7x_idtable); | |
2061 | ||
2062 | static const struct dev_pm_ops tsl2x7x_pm_ops = { | |
2063 | .suspend = tsl2x7x_suspend, | |
2064 | .resume = tsl2x7x_resume, | |
2065 | }; | |
2066 | ||
2067 | /* Driver definition */ | |
2068 | static struct i2c_driver tsl2x7x_driver = { | |
2069 | .driver = { | |
2070 | .name = "tsl2x7x", | |
2071 | .pm = &tsl2x7x_pm_ops, | |
2072 | }, | |
2073 | .id_table = tsl2x7x_idtable, | |
2074 | .probe = tsl2x7x_probe, | |
2075 | .remove = __devexit_p(tsl2x7x_remove), | |
2076 | }; | |
2077 | ||
2078 | module_i2c_driver(tsl2x7x_driver); | |
2079 | ||
2080 | MODULE_AUTHOR("J. August Brenner<jbrenner@taosinc.com>"); | |
2081 | MODULE_DESCRIPTION("TAOS tsl2x7x ambient and proximity light sensor driver"); | |
2082 | MODULE_LICENSE("GPL"); |