drm/nouveau: consume the return of large GSP message
[drm/drm-misc.git] / drivers / iio / light / ltr390.c
blobdf664f36090301e21d6e2f92035198e15e018712
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * IIO driver for Lite-On LTR390 ALS and UV sensor
4 * (7-bit I2C slave address 0x53)
6 * Based on the work of:
7 * Shreeya Patel and Shi Zhigang (LTRF216 Driver)
9 * Copyright (C) 2023 Anshul Dalal <anshulusr@gmail.com>
11 * Datasheet:
12 * https://optoelectronics.liteon.com/upload/download/DS86-2015-0004/LTR-390UV_Final_%20DS_V1%201.pdf
14 * TODO:
15 * - Support for configurable gain and resolution
16 * - Sensor suspend/resume support
17 * - Add support for reading the ALS
18 * - Interrupt support
21 #include <linux/bitfield.h>
22 #include <linux/device.h>
23 #include <linux/i2c.h>
24 #include <linux/irq.h>
25 #include <linux/interrupt.h>
26 #include <linux/math.h>
27 #include <linux/module.h>
28 #include <linux/mutex.h>
29 #include <linux/regmap.h>
31 #include <linux/iio/iio.h>
32 #include <linux/iio/events.h>
34 #include <linux/unaligned.h>
36 #define LTR390_MAIN_CTRL 0x00
37 #define LTR390_ALS_UVS_MEAS_RATE 0x04
38 #define LTR390_ALS_UVS_GAIN 0x05
39 #define LTR390_PART_ID 0x06
40 #define LTR390_MAIN_STATUS 0x07
41 #define LTR390_ALS_DATA 0x0D
42 #define LTR390_UVS_DATA 0x10
43 #define LTR390_INT_CFG 0x19
44 #define LTR390_INT_PST 0x1A
45 #define LTR390_THRESH_UP 0x21
46 #define LTR390_THRESH_LOW 0x24
48 #define LTR390_PART_NUMBER_ID 0xb
49 #define LTR390_ALS_UVS_GAIN_MASK GENMASK(2, 0)
50 #define LTR390_ALS_UVS_MEAS_RATE_MASK GENMASK(2, 0)
51 #define LTR390_ALS_UVS_INT_TIME_MASK GENMASK(6, 4)
52 #define LTR390_ALS_UVS_INT_TIME(x) FIELD_PREP(LTR390_ALS_UVS_INT_TIME_MASK, (x))
53 #define LTR390_INT_PST_MASK GENMASK(7, 4)
54 #define LTR390_INT_PST_VAL(x) FIELD_PREP(LTR390_INT_PST_MASK, (x))
56 #define LTR390_SW_RESET BIT(4)
57 #define LTR390_UVS_MODE BIT(3)
58 #define LTR390_SENSOR_ENABLE BIT(1)
59 #define LTR390_LS_INT_EN BIT(2)
60 #define LTR390_LS_INT_SEL_UVS BIT(5)
62 #define LTR390_FRACTIONAL_PRECISION 100
65 * At 20-bit resolution (integration time: 400ms) and 18x gain, 2300 counts of
66 * the sensor are equal to 1 UV Index [Datasheet Page#8].
68 * For the default resolution of 18-bit (integration time: 100ms) and default
69 * gain of 3x, the counts/uvi are calculated as follows:
70 * 2300 / ((3/18) * (100/400)) = 95.83
72 #define LTR390_COUNTS_PER_UVI 96
75 * Window Factor is needed when the device is under Window glass with coated
76 * tinted ink. This is to compensate for the light loss due to the lower
77 * transmission rate of the window glass and helps * in calculating lux.
79 #define LTR390_WINDOW_FACTOR 1
81 enum ltr390_mode {
82 LTR390_SET_ALS_MODE,
83 LTR390_SET_UVS_MODE,
86 enum ltr390_meas_rate {
87 LTR390_GET_FREQ,
88 LTR390_GET_PERIOD,
91 struct ltr390_data {
92 struct regmap *regmap;
93 struct i2c_client *client;
94 /* Protects device from simulataneous reads */
95 struct mutex lock;
96 enum ltr390_mode mode;
97 int gain;
98 int int_time_us;
101 static const struct regmap_config ltr390_regmap_config = {
102 .name = "ltr390",
103 .reg_bits = 8,
104 .reg_stride = 1,
105 .val_bits = 8,
108 /* Sampling frequency is in mili Hz and mili Seconds */
109 static const int ltr390_samp_freq_table[][2] = {
110 [0] = { 40000, 25 },
111 [1] = { 20000, 50 },
112 [2] = { 10000, 100 },
113 [3] = { 5000, 200 },
114 [4] = { 2000, 500 },
115 [5] = { 1000, 1000 },
116 [6] = { 500, 2000 },
117 [7] = { 500, 2000 },
120 static int ltr390_register_read(struct ltr390_data *data, u8 register_address)
122 struct device *dev = &data->client->dev;
123 int ret;
124 u8 recieve_buffer[3];
126 ret = regmap_bulk_read(data->regmap, register_address, recieve_buffer,
127 sizeof(recieve_buffer));
128 if (ret) {
129 dev_err(dev, "failed to read measurement data");
130 return ret;
133 return get_unaligned_le24(recieve_buffer);
136 static int ltr390_set_mode(struct ltr390_data *data, enum ltr390_mode mode)
138 int ret;
140 if (data->mode == mode)
141 return 0;
143 switch (mode) {
144 case LTR390_SET_ALS_MODE:
145 ret = regmap_clear_bits(data->regmap, LTR390_MAIN_CTRL, LTR390_UVS_MODE);
146 break;
148 case LTR390_SET_UVS_MODE:
149 ret = regmap_set_bits(data->regmap, LTR390_MAIN_CTRL, LTR390_UVS_MODE);
150 break;
153 if (ret)
154 return ret;
156 data->mode = mode;
157 return 0;
160 static int ltr390_counts_per_uvi(struct ltr390_data *data)
162 const int orig_gain = 18;
163 const int orig_int_time = 400;
165 return DIV_ROUND_CLOSEST(23 * data->gain * data->int_time_us, 10 * orig_gain * orig_int_time);
168 static int ltr390_get_samp_freq_or_period(struct ltr390_data *data,
169 enum ltr390_meas_rate option)
171 int ret, value;
173 ret = regmap_read(data->regmap, LTR390_ALS_UVS_MEAS_RATE, &value);
174 if (ret < 0)
175 return ret;
176 value = FIELD_GET(LTR390_ALS_UVS_MEAS_RATE_MASK, value);
178 return ltr390_samp_freq_table[value][option];
181 static int ltr390_read_raw(struct iio_dev *iio_device,
182 struct iio_chan_spec const *chan, int *val,
183 int *val2, long mask)
185 int ret;
186 struct ltr390_data *data = iio_priv(iio_device);
188 guard(mutex)(&data->lock);
189 switch (mask) {
190 case IIO_CHAN_INFO_RAW:
191 switch (chan->type) {
192 case IIO_UVINDEX:
193 ret = ltr390_set_mode(data, LTR390_SET_UVS_MODE);
194 if (ret < 0)
195 return ret;
197 ret = ltr390_register_read(data, LTR390_UVS_DATA);
198 if (ret < 0)
199 return ret;
200 break;
202 case IIO_LIGHT:
203 ret = ltr390_set_mode(data, LTR390_SET_ALS_MODE);
204 if (ret < 0)
205 return ret;
207 ret = ltr390_register_read(data, LTR390_ALS_DATA);
208 if (ret < 0)
209 return ret;
210 break;
212 default:
213 return -EINVAL;
215 *val = ret;
216 return IIO_VAL_INT;
217 case IIO_CHAN_INFO_SCALE:
218 switch (chan->type) {
219 case IIO_UVINDEX:
220 *val = LTR390_WINDOW_FACTOR * LTR390_FRACTIONAL_PRECISION;
221 *val2 = ltr390_counts_per_uvi(data);
222 return IIO_VAL_FRACTIONAL;
224 case IIO_LIGHT:
225 *val = LTR390_WINDOW_FACTOR * 6 * 100;
226 *val2 = data->gain * data->int_time_us;
227 return IIO_VAL_FRACTIONAL;
229 default:
230 return -EINVAL;
233 case IIO_CHAN_INFO_INT_TIME:
234 *val = data->int_time_us;
235 return IIO_VAL_INT;
237 case IIO_CHAN_INFO_SAMP_FREQ:
238 *val = ltr390_get_samp_freq_or_period(data, LTR390_GET_FREQ);
239 return IIO_VAL_INT;
241 default:
242 return -EINVAL;
246 /* integration time in us */
247 static const int ltr390_int_time_map_us[] = { 400000, 200000, 100000, 50000, 25000, 12500 };
248 static const int ltr390_gain_map[] = { 1, 3, 6, 9, 18 };
249 static const int ltr390_freq_map[] = { 40000, 20000, 10000, 5000, 2000, 1000, 500, 500 };
251 static const struct iio_event_spec ltr390_event_spec[] = {
253 .type = IIO_EV_TYPE_THRESH,
254 .dir = IIO_EV_DIR_RISING,
255 .mask_separate = BIT(IIO_EV_INFO_VALUE),
256 }, {
257 .type = IIO_EV_TYPE_THRESH,
258 .dir = IIO_EV_DIR_FALLING,
259 .mask_separate = BIT(IIO_EV_INFO_VALUE),
260 }, {
261 .type = IIO_EV_TYPE_THRESH,
262 .dir = IIO_EV_DIR_EITHER,
263 .mask_separate = BIT(IIO_EV_INFO_ENABLE) |
264 BIT(IIO_EV_INFO_PERIOD),
268 static const struct iio_chan_spec ltr390_channels[] = {
269 /* UV sensor */
271 .type = IIO_UVINDEX,
272 .scan_index = 0,
273 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
274 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME) | BIT(IIO_CHAN_INFO_SAMP_FREQ),
275 .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) |
276 BIT(IIO_CHAN_INFO_SCALE) |
277 BIT(IIO_CHAN_INFO_SAMP_FREQ),
278 .event_spec = ltr390_event_spec,
279 .num_event_specs = ARRAY_SIZE(ltr390_event_spec),
281 /* ALS sensor */
283 .type = IIO_LIGHT,
284 .scan_index = 1,
285 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
286 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME) | BIT(IIO_CHAN_INFO_SAMP_FREQ),
287 .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) |
288 BIT(IIO_CHAN_INFO_SCALE) |
289 BIT(IIO_CHAN_INFO_SAMP_FREQ),
290 .event_spec = ltr390_event_spec,
291 .num_event_specs = ARRAY_SIZE(ltr390_event_spec),
295 static int ltr390_set_gain(struct ltr390_data *data, int val)
297 int ret, idx;
299 for (idx = 0; idx < ARRAY_SIZE(ltr390_gain_map); idx++) {
300 if (ltr390_gain_map[idx] != val)
301 continue;
303 guard(mutex)(&data->lock);
304 ret = regmap_update_bits(data->regmap,
305 LTR390_ALS_UVS_GAIN,
306 LTR390_ALS_UVS_GAIN_MASK, idx);
307 if (ret)
308 return ret;
310 data->gain = ltr390_gain_map[idx];
311 return 0;
314 return -EINVAL;
317 static int ltr390_set_int_time(struct ltr390_data *data, int val)
319 int ret, idx;
321 for (idx = 0; idx < ARRAY_SIZE(ltr390_int_time_map_us); idx++) {
322 if (ltr390_int_time_map_us[idx] != val)
323 continue;
325 guard(mutex)(&data->lock);
326 ret = regmap_update_bits(data->regmap,
327 LTR390_ALS_UVS_MEAS_RATE,
328 LTR390_ALS_UVS_INT_TIME_MASK,
329 LTR390_ALS_UVS_INT_TIME(idx));
330 if (ret)
331 return ret;
333 data->int_time_us = ltr390_int_time_map_us[idx];
334 return 0;
337 return -EINVAL;
340 static int ltr390_set_samp_freq(struct ltr390_data *data, int val)
342 int idx;
344 for (idx = 0; idx < ARRAY_SIZE(ltr390_samp_freq_table); idx++) {
345 if (ltr390_samp_freq_table[idx][0] != val)
346 continue;
348 guard(mutex)(&data->lock);
349 return regmap_update_bits(data->regmap,
350 LTR390_ALS_UVS_MEAS_RATE,
351 LTR390_ALS_UVS_MEAS_RATE_MASK, idx);
354 return -EINVAL;
357 static int ltr390_read_avail(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
358 const int **vals, int *type, int *length, long mask)
360 switch (mask) {
361 case IIO_CHAN_INFO_SCALE:
362 *length = ARRAY_SIZE(ltr390_gain_map);
363 *type = IIO_VAL_INT;
364 *vals = ltr390_gain_map;
365 return IIO_AVAIL_LIST;
366 case IIO_CHAN_INFO_INT_TIME:
367 *length = ARRAY_SIZE(ltr390_int_time_map_us);
368 *type = IIO_VAL_INT;
369 *vals = ltr390_int_time_map_us;
370 return IIO_AVAIL_LIST;
371 case IIO_CHAN_INFO_SAMP_FREQ:
372 *length = ARRAY_SIZE(ltr390_freq_map);
373 *type = IIO_VAL_INT;
374 *vals = ltr390_freq_map;
375 return IIO_AVAIL_LIST;
376 default:
377 return -EINVAL;
381 static int ltr390_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
382 int val, int val2, long mask)
384 struct ltr390_data *data = iio_priv(indio_dev);
386 switch (mask) {
387 case IIO_CHAN_INFO_SCALE:
388 if (val2 != 0)
389 return -EINVAL;
391 return ltr390_set_gain(data, val);
393 case IIO_CHAN_INFO_INT_TIME:
394 if (val2 != 0)
395 return -EINVAL;
397 return ltr390_set_int_time(data, val);
399 case IIO_CHAN_INFO_SAMP_FREQ:
400 if (val2 != 0)
401 return -EINVAL;
403 return ltr390_set_samp_freq(data, val);
405 default:
406 return -EINVAL;
410 static int ltr390_read_intr_prst(struct ltr390_data *data, int *val)
412 int ret, prst, samp_period;
414 samp_period = ltr390_get_samp_freq_or_period(data, LTR390_GET_PERIOD);
415 ret = regmap_read(data->regmap, LTR390_INT_PST, &prst);
416 if (ret < 0)
417 return ret;
418 *val = prst * samp_period;
420 return IIO_VAL_INT;
423 static int ltr390_write_intr_prst(struct ltr390_data *data, int val)
425 int ret, samp_period, new_val;
427 samp_period = ltr390_get_samp_freq_or_period(data, LTR390_GET_PERIOD);
429 /* persist period should be greater than or equal to samp period */
430 if (val < samp_period)
431 return -EINVAL;
433 new_val = DIV_ROUND_UP(val, samp_period);
434 if (new_val < 0 || new_val > 0x0f)
435 return -EINVAL;
437 guard(mutex)(&data->lock);
438 ret = regmap_update_bits(data->regmap,
439 LTR390_INT_PST,
440 LTR390_INT_PST_MASK,
441 LTR390_INT_PST_VAL(new_val));
442 if (ret)
443 return ret;
445 return 0;
448 static int ltr390_read_threshold(struct iio_dev *indio_dev,
449 enum iio_event_direction dir,
450 int *val, int *val2)
452 struct ltr390_data *data = iio_priv(indio_dev);
453 int ret;
455 switch (dir) {
456 case IIO_EV_DIR_RISING:
457 ret = ltr390_register_read(data, LTR390_THRESH_UP);
458 if (ret < 0)
459 return ret;
460 *val = ret;
461 return IIO_VAL_INT;
463 case IIO_EV_DIR_FALLING:
464 ret = ltr390_register_read(data, LTR390_THRESH_LOW);
465 if (ret < 0)
466 return ret;
467 *val = ret;
468 return IIO_VAL_INT;
469 default:
470 return -EINVAL;
474 static int ltr390_write_threshold(struct iio_dev *indio_dev,
475 enum iio_event_direction dir,
476 int val, int val2)
478 struct ltr390_data *data = iio_priv(indio_dev);
480 guard(mutex)(&data->lock);
481 switch (dir) {
482 case IIO_EV_DIR_RISING:
483 return regmap_bulk_write(data->regmap, LTR390_THRESH_UP, &val, 3);
485 case IIO_EV_DIR_FALLING:
486 return regmap_bulk_write(data->regmap, LTR390_THRESH_LOW, &val, 3);
488 default:
489 return -EINVAL;
493 static int ltr390_read_event_value(struct iio_dev *indio_dev,
494 const struct iio_chan_spec *chan,
495 enum iio_event_type type,
496 enum iio_event_direction dir,
497 enum iio_event_info info,
498 int *val, int *val2)
500 switch (info) {
501 case IIO_EV_INFO_VALUE:
502 return ltr390_read_threshold(indio_dev, dir, val, val2);
504 case IIO_EV_INFO_PERIOD:
505 return ltr390_read_intr_prst(iio_priv(indio_dev), val);
507 default:
508 return -EINVAL;
512 static int ltr390_write_event_value(struct iio_dev *indio_dev,
513 const struct iio_chan_spec *chan,
514 enum iio_event_type type,
515 enum iio_event_direction dir,
516 enum iio_event_info info,
517 int val, int val2)
519 switch (info) {
520 case IIO_EV_INFO_VALUE:
521 if (val2 != 0)
522 return -EINVAL;
524 return ltr390_write_threshold(indio_dev, dir, val, val2);
526 case IIO_EV_INFO_PERIOD:
527 if (val2 != 0)
528 return -EINVAL;
530 return ltr390_write_intr_prst(iio_priv(indio_dev), val);
532 default:
533 return -EINVAL;
537 static int ltr390_read_event_config(struct iio_dev *indio_dev,
538 const struct iio_chan_spec *chan,
539 enum iio_event_type type,
540 enum iio_event_direction dir)
542 struct ltr390_data *data = iio_priv(indio_dev);
543 int ret, status;
545 ret = regmap_read(data->regmap, LTR390_INT_CFG, &status);
546 if (ret < 0)
547 return ret;
549 return FIELD_GET(LTR390_LS_INT_EN, status);
552 static int ltr390_write_event_config(struct iio_dev *indio_dev,
553 const struct iio_chan_spec *chan,
554 enum iio_event_type type,
555 enum iio_event_direction dir,
556 bool state)
558 struct ltr390_data *data = iio_priv(indio_dev);
559 int ret;
561 if (!state)
562 return regmap_clear_bits(data->regmap, LTR390_INT_CFG, LTR390_LS_INT_EN);
564 guard(mutex)(&data->lock);
565 ret = regmap_set_bits(data->regmap, LTR390_INT_CFG, LTR390_LS_INT_EN);
566 if (ret < 0)
567 return ret;
569 switch (chan->type) {
570 case IIO_LIGHT:
571 ret = ltr390_set_mode(data, LTR390_SET_ALS_MODE);
572 if (ret < 0)
573 return ret;
575 return regmap_clear_bits(data->regmap, LTR390_INT_CFG, LTR390_LS_INT_SEL_UVS);
577 case IIO_UVINDEX:
578 ret = ltr390_set_mode(data, LTR390_SET_UVS_MODE);
579 if (ret < 0)
580 return ret;
582 return regmap_set_bits(data->regmap, LTR390_INT_CFG, LTR390_LS_INT_SEL_UVS);
584 default:
585 return -EINVAL;
589 static const struct iio_info ltr390_info = {
590 .read_raw = ltr390_read_raw,
591 .write_raw = ltr390_write_raw,
592 .read_avail = ltr390_read_avail,
593 .read_event_value = ltr390_read_event_value,
594 .read_event_config = ltr390_read_event_config,
595 .write_event_value = ltr390_write_event_value,
596 .write_event_config = ltr390_write_event_config,
599 static irqreturn_t ltr390_interrupt_handler(int irq, void *private)
601 struct iio_dev *indio_dev = private;
602 struct ltr390_data *data = iio_priv(indio_dev);
603 int ret, status;
605 /* Reading the status register to clear the interrupt flag, Datasheet pg: 17*/
606 ret = regmap_read(data->regmap, LTR390_MAIN_STATUS, &status);
607 if (ret < 0)
608 return ret;
610 switch (data->mode) {
611 case LTR390_SET_ALS_MODE:
612 iio_push_event(indio_dev,
613 IIO_UNMOD_EVENT_CODE(IIO_LIGHT, 0,
614 IIO_EV_TYPE_THRESH,
615 IIO_EV_DIR_EITHER),
616 iio_get_time_ns(indio_dev));
617 break;
619 case LTR390_SET_UVS_MODE:
620 iio_push_event(indio_dev,
621 IIO_UNMOD_EVENT_CODE(IIO_UVINDEX, 0,
622 IIO_EV_TYPE_THRESH,
623 IIO_EV_DIR_EITHER),
624 iio_get_time_ns(indio_dev));
625 break;
628 return IRQ_HANDLED;
631 static int ltr390_probe(struct i2c_client *client)
633 struct ltr390_data *data;
634 struct iio_dev *indio_dev;
635 struct device *dev;
636 int ret, part_number;
638 dev = &client->dev;
639 indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
640 if (!indio_dev)
641 return -ENOMEM;
643 data = iio_priv(indio_dev);
645 data->regmap = devm_regmap_init_i2c(client, &ltr390_regmap_config);
646 if (IS_ERR(data->regmap))
647 return dev_err_probe(dev, PTR_ERR(data->regmap),
648 "regmap initialization failed\n");
650 data->client = client;
651 /* default value of integration time from pg: 15 of the datasheet */
652 data->int_time_us = 100000;
653 /* default value of gain from pg: 16 of the datasheet */
654 data->gain = 3;
655 /* default mode for ltr390 is ALS mode */
656 data->mode = LTR390_SET_ALS_MODE;
658 mutex_init(&data->lock);
660 indio_dev->info = &ltr390_info;
661 indio_dev->channels = ltr390_channels;
662 indio_dev->num_channels = ARRAY_SIZE(ltr390_channels);
663 indio_dev->name = "ltr390";
665 ret = regmap_read(data->regmap, LTR390_PART_ID, &part_number);
666 if (ret)
667 return dev_err_probe(dev, ret,
668 "failed to get sensor's part id\n");
669 /* Lower 4 bits of `part_number` change with hardware revisions */
670 if (part_number >> 4 != LTR390_PART_NUMBER_ID)
671 dev_info(dev, "received invalid product id: 0x%x", part_number);
672 dev_dbg(dev, "LTR390, product id: 0x%x\n", part_number);
674 /* reset sensor, chip fails to respond to this, so ignore any errors */
675 regmap_set_bits(data->regmap, LTR390_MAIN_CTRL, LTR390_SW_RESET);
677 /* Wait for the registers to reset before proceeding */
678 usleep_range(1000, 2000);
680 ret = regmap_set_bits(data->regmap, LTR390_MAIN_CTRL, LTR390_SENSOR_ENABLE);
681 if (ret)
682 return dev_err_probe(dev, ret, "failed to enable the sensor\n");
684 if (client->irq) {
685 ret = devm_request_threaded_irq(dev, client->irq,
686 NULL, ltr390_interrupt_handler,
687 IRQF_ONESHOT,
688 "ltr390_thresh_event",
689 indio_dev);
690 if (ret)
691 return dev_err_probe(dev, ret,
692 "request irq (%d) failed\n", client->irq);
695 return devm_iio_device_register(dev, indio_dev);
698 static int ltr390_suspend(struct device *dev)
700 struct iio_dev *indio_dev = dev_get_drvdata(dev);
701 struct ltr390_data *data = iio_priv(indio_dev);
703 return regmap_clear_bits(data->regmap, LTR390_MAIN_CTRL,
704 LTR390_SENSOR_ENABLE);
707 static int ltr390_resume(struct device *dev)
709 struct iio_dev *indio_dev = dev_get_drvdata(dev);
710 struct ltr390_data *data = iio_priv(indio_dev);
712 return regmap_set_bits(data->regmap, LTR390_MAIN_CTRL,
713 LTR390_SENSOR_ENABLE);
716 static DEFINE_SIMPLE_DEV_PM_OPS(ltr390_pm_ops, ltr390_suspend, ltr390_resume);
718 static const struct i2c_device_id ltr390_id[] = {
719 { "ltr390" },
720 { /* Sentinel */ }
722 MODULE_DEVICE_TABLE(i2c, ltr390_id);
724 static const struct of_device_id ltr390_of_table[] = {
725 { .compatible = "liteon,ltr390" },
726 { /* Sentinel */ }
728 MODULE_DEVICE_TABLE(of, ltr390_of_table);
730 static struct i2c_driver ltr390_driver = {
731 .driver = {
732 .name = "ltr390",
733 .of_match_table = ltr390_of_table,
734 .pm = pm_sleep_ptr(&ltr390_pm_ops),
736 .probe = ltr390_probe,
737 .id_table = ltr390_id,
739 module_i2c_driver(ltr390_driver);
741 MODULE_AUTHOR("Anshul Dalal <anshulusr@gmail.com>");
742 MODULE_DESCRIPTION("Lite-On LTR390 ALS and UV sensor Driver");
743 MODULE_LICENSE("GPL");