1 // SPDX-License-Identifier: GPL-2.0-only
3 * Support for Lite-On LTR501 and similar ambient light and proximity sensors.
5 * Copyright 2014 Peter Meerwald <pmeerw@pmeerw.net>
7 * 7-bit I2C slave address 0x23
9 * TODO: IR LED characteristics
12 #include <linux/module.h>
13 #include <linux/mod_devicetable.h>
14 #include <linux/i2c.h>
15 #include <linux/err.h>
16 #include <linux/delay.h>
17 #include <linux/regmap.h>
18 #include <linux/regulator/consumer.h>
20 #include <linux/iio/iio.h>
21 #include <linux/iio/events.h>
22 #include <linux/iio/sysfs.h>
23 #include <linux/iio/trigger_consumer.h>
24 #include <linux/iio/buffer.h>
25 #include <linux/iio/triggered_buffer.h>
27 #define LTR501_DRV_NAME "ltr501"
29 #define LTR501_ALS_CONTR 0x80 /* ALS operation mode, SW reset */
30 #define LTR501_PS_CONTR 0x81 /* PS operation mode */
31 #define LTR501_PS_MEAS_RATE 0x84 /* measurement rate*/
32 #define LTR501_ALS_MEAS_RATE 0x85 /* ALS integ time, measurement rate*/
33 #define LTR501_PART_ID 0x86
34 #define LTR501_MANUFAC_ID 0x87
35 #define LTR501_ALS_DATA1 0x88 /* 16-bit, little endian */
36 #define LTR501_ALS_DATA1_UPPER 0x89 /* upper 8 bits of LTR501_ALS_DATA1 */
37 #define LTR501_ALS_DATA0 0x8a /* 16-bit, little endian */
38 #define LTR501_ALS_DATA0_UPPER 0x8b /* upper 8 bits of LTR501_ALS_DATA0 */
39 #define LTR501_ALS_PS_STATUS 0x8c
40 #define LTR501_PS_DATA 0x8d /* 16-bit, little endian */
41 #define LTR501_PS_DATA_UPPER 0x8e /* upper 8 bits of LTR501_PS_DATA */
42 #define LTR501_INTR 0x8f /* output mode, polarity, mode */
43 #define LTR501_PS_THRESH_UP 0x90 /* 11 bit, ps upper threshold */
44 #define LTR501_PS_THRESH_LOW 0x92 /* 11 bit, ps lower threshold */
45 #define LTR501_ALS_THRESH_UP 0x97 /* 16 bit, ALS upper threshold */
46 #define LTR501_ALS_THRESH_LOW 0x99 /* 16 bit, ALS lower threshold */
47 #define LTR501_INTR_PRST 0x9e /* ps thresh, als thresh */
48 #define LTR501_MAX_REG 0x9f
50 #define LTR501_ALS_CONTR_SW_RESET BIT(2)
51 #define LTR501_CONTR_PS_GAIN_MASK (BIT(3) | BIT(2))
52 #define LTR501_CONTR_PS_GAIN_SHIFT 2
53 #define LTR501_CONTR_ALS_GAIN_MASK BIT(3)
54 #define LTR501_CONTR_ACTIVE BIT(1)
56 #define LTR501_STATUS_ALS_INTR BIT(3)
57 #define LTR501_STATUS_ALS_RDY BIT(2)
58 #define LTR501_STATUS_PS_INTR BIT(1)
59 #define LTR501_STATUS_PS_RDY BIT(0)
61 #define LTR501_PS_DATA_MASK 0x7ff
62 #define LTR501_PS_THRESH_MASK 0x7ff
63 #define LTR501_ALS_THRESH_MASK 0xffff
65 #define LTR501_ALS_DEF_PERIOD 500000
66 #define LTR501_PS_DEF_PERIOD 100000
68 #define LTR501_REGMAP_NAME "ltr501_regmap"
70 #define LTR501_LUX_CONV(vis_coeff, vis_data, ir_coeff, ir_data) \
71 ((vis_coeff * vis_data) - (ir_coeff * ir_data))
73 static const int int_time_mapping
[] = {100000, 50000, 200000, 400000};
75 static const struct reg_field reg_field_it
=
76 REG_FIELD(LTR501_ALS_MEAS_RATE
, 3, 4);
77 static const struct reg_field reg_field_als_intr
=
78 REG_FIELD(LTR501_INTR
, 1, 1);
79 static const struct reg_field reg_field_ps_intr
=
80 REG_FIELD(LTR501_INTR
, 0, 0);
81 static const struct reg_field reg_field_als_rate
=
82 REG_FIELD(LTR501_ALS_MEAS_RATE
, 0, 2);
83 static const struct reg_field reg_field_ps_rate
=
84 REG_FIELD(LTR501_PS_MEAS_RATE
, 0, 3);
85 static const struct reg_field reg_field_als_prst
=
86 REG_FIELD(LTR501_INTR_PRST
, 0, 3);
87 static const struct reg_field reg_field_ps_prst
=
88 REG_FIELD(LTR501_INTR_PRST
, 4, 7);
90 struct ltr501_samp_table
{
91 int freq_val
; /* repetition frequency in micro HZ*/
92 int time_val
; /* repetition rate in micro seconds */
95 #define LTR501_RESERVED_GAIN -1
109 static const struct ltr501_gain ltr501_als_gain_tbl
[] = {
114 static const struct ltr501_gain ltr559_als_gain_tbl
[] = {
119 {LTR501_RESERVED_GAIN
, LTR501_RESERVED_GAIN
},
120 {LTR501_RESERVED_GAIN
, LTR501_RESERVED_GAIN
},
125 static const struct ltr501_gain ltr501_ps_gain_tbl
[] = {
132 static const struct ltr501_gain ltr559_ps_gain_tbl
[] = {
133 {0, 62500}, /* x16 gain */
134 {0, 31250}, /* x32 gain */
135 {0, 15625}, /* bits X1 are for x64 gain */
139 struct ltr501_chip_info
{
141 const struct ltr501_gain
*als_gain
;
142 int als_gain_tbl_size
;
143 const struct ltr501_gain
*ps_gain
;
144 int ps_gain_tbl_size
;
148 struct iio_chan_spec
const *channels
;
149 const int no_channels
;
150 const struct iio_info
*info
;
151 const struct iio_info
*info_no_irq
;
155 struct i2c_client
*client
;
156 struct mutex lock_als
, lock_ps
;
157 const struct ltr501_chip_info
*chip_info
;
158 u8 als_contr
, ps_contr
;
159 int als_period
, ps_period
; /* period in micro seconds */
160 struct regmap
*regmap
;
161 struct regmap_field
*reg_it
;
162 struct regmap_field
*reg_als_intr
;
163 struct regmap_field
*reg_ps_intr
;
164 struct regmap_field
*reg_als_rate
;
165 struct regmap_field
*reg_ps_rate
;
166 struct regmap_field
*reg_als_prst
;
167 struct regmap_field
*reg_ps_prst
;
171 static const struct ltr501_samp_table ltr501_als_samp_table
[] = {
172 {20000000, 50000}, {10000000, 100000},
173 {5000000, 200000}, {2000000, 500000},
174 {1000000, 1000000}, {500000, 2000000},
175 {500000, 2000000}, {500000, 2000000}
178 static const struct ltr501_samp_table ltr501_ps_samp_table
[] = {
179 {20000000, 50000}, {14285714, 70000},
180 {10000000, 100000}, {5000000, 200000},
181 {2000000, 500000}, {1000000, 1000000},
182 {500000, 2000000}, {500000, 2000000},
186 static int ltr501_match_samp_freq(const struct ltr501_samp_table
*tab
,
187 int len
, int val
, int val2
)
191 freq
= val
* 1000000 + val2
;
193 for (i
= 0; i
< len
; i
++) {
194 if (tab
[i
].freq_val
== freq
)
201 static int ltr501_als_read_samp_freq(const struct ltr501_data
*data
,
206 ret
= regmap_field_read(data
->reg_als_rate
, &i
);
210 if (i
< 0 || i
>= ARRAY_SIZE(ltr501_als_samp_table
))
213 *val
= ltr501_als_samp_table
[i
].freq_val
/ 1000000;
214 *val2
= ltr501_als_samp_table
[i
].freq_val
% 1000000;
216 return IIO_VAL_INT_PLUS_MICRO
;
219 static int ltr501_ps_read_samp_freq(const struct ltr501_data
*data
,
224 ret
= regmap_field_read(data
->reg_ps_rate
, &i
);
228 if (i
< 0 || i
>= ARRAY_SIZE(ltr501_ps_samp_table
))
231 *val
= ltr501_ps_samp_table
[i
].freq_val
/ 1000000;
232 *val2
= ltr501_ps_samp_table
[i
].freq_val
% 1000000;
234 return IIO_VAL_INT_PLUS_MICRO
;
237 static int ltr501_als_write_samp_freq(struct ltr501_data
*data
,
242 i
= ltr501_match_samp_freq(ltr501_als_samp_table
,
243 ARRAY_SIZE(ltr501_als_samp_table
),
249 mutex_lock(&data
->lock_als
);
250 ret
= regmap_field_write(data
->reg_als_rate
, i
);
251 mutex_unlock(&data
->lock_als
);
256 static int ltr501_ps_write_samp_freq(struct ltr501_data
*data
,
261 i
= ltr501_match_samp_freq(ltr501_ps_samp_table
,
262 ARRAY_SIZE(ltr501_ps_samp_table
),
268 mutex_lock(&data
->lock_ps
);
269 ret
= regmap_field_write(data
->reg_ps_rate
, i
);
270 mutex_unlock(&data
->lock_ps
);
275 static int ltr501_als_read_samp_period(const struct ltr501_data
*data
, int *val
)
279 ret
= regmap_field_read(data
->reg_als_rate
, &i
);
283 if (i
< 0 || i
>= ARRAY_SIZE(ltr501_als_samp_table
))
286 *val
= ltr501_als_samp_table
[i
].time_val
;
291 static int ltr501_ps_read_samp_period(const struct ltr501_data
*data
, int *val
)
295 ret
= regmap_field_read(data
->reg_ps_rate
, &i
);
299 if (i
< 0 || i
>= ARRAY_SIZE(ltr501_ps_samp_table
))
302 *val
= ltr501_ps_samp_table
[i
].time_val
;
307 /* IR and visible spectrum coeff's are given in data sheet */
308 static unsigned long ltr501_calculate_lux(u16 vis_data
, u16 ir_data
)
310 unsigned long ratio
, lux
;
315 /* multiply numerator by 100 to avoid handling ratio < 1 */
316 ratio
= DIV_ROUND_UP(ir_data
* 100, ir_data
+ vis_data
);
319 lux
= LTR501_LUX_CONV(1774, vis_data
, -1105, ir_data
);
320 else if (ratio
>= 45 && ratio
< 64)
321 lux
= LTR501_LUX_CONV(3772, vis_data
, 1336, ir_data
);
322 else if (ratio
>= 64 && ratio
< 85)
323 lux
= LTR501_LUX_CONV(1690, vis_data
, 169, ir_data
);
330 static int ltr501_drdy(const struct ltr501_data
*data
, u8 drdy_mask
)
336 ret
= regmap_read(data
->regmap
, LTR501_ALS_PS_STATUS
, &status
);
339 if ((status
& drdy_mask
) == drdy_mask
)
344 dev_err(&data
->client
->dev
, "ltr501_drdy() failed, data not ready\n");
348 static int ltr501_set_it_time(struct ltr501_data
*data
, int it
)
350 int ret
, i
, index
= -1, status
;
352 for (i
= 0; i
< ARRAY_SIZE(int_time_mapping
); i
++) {
353 if (int_time_mapping
[i
] == it
) {
358 /* Make sure integ time index is valid */
362 ret
= regmap_read(data
->regmap
, LTR501_ALS_CONTR
, &status
);
366 if (status
& LTR501_CONTR_ALS_GAIN_MASK
) {
368 * 200 ms and 400 ms integ time can only be
369 * used in dynamic range 1
374 /* 50 ms integ time can only be used in dynamic range 2 */
378 return regmap_field_write(data
->reg_it
, index
);
381 /* read int time in micro seconds */
382 static int ltr501_read_it_time(const struct ltr501_data
*data
,
387 ret
= regmap_field_read(data
->reg_it
, &index
);
391 /* Make sure integ time index is valid */
392 if (index
< 0 || index
>= ARRAY_SIZE(int_time_mapping
))
395 *val2
= int_time_mapping
[index
];
398 return IIO_VAL_INT_PLUS_MICRO
;
401 static int ltr501_read_als(const struct ltr501_data
*data
, __le16 buf
[2])
405 ret
= ltr501_drdy(data
, LTR501_STATUS_ALS_RDY
);
408 /* always read both ALS channels in given order */
409 return regmap_bulk_read(data
->regmap
, LTR501_ALS_DATA1
,
410 buf
, 2 * sizeof(__le16
));
413 static int ltr501_read_ps(const struct ltr501_data
*data
)
418 ret
= ltr501_drdy(data
, LTR501_STATUS_PS_RDY
);
422 ret
= regmap_bulk_read(data
->regmap
, LTR501_PS_DATA
,
423 &status
, sizeof(status
));
427 return le16_to_cpu(status
);
430 static int ltr501_read_intr_prst(const struct ltr501_data
*data
,
431 enum iio_chan_type type
,
434 int ret
, samp_period
, prst
;
438 ret
= regmap_field_read(data
->reg_als_prst
, &prst
);
442 ret
= ltr501_als_read_samp_period(data
, &samp_period
);
446 *val2
= samp_period
* prst
;
447 return IIO_VAL_INT_PLUS_MICRO
;
449 ret
= regmap_field_read(data
->reg_ps_prst
, &prst
);
453 ret
= ltr501_ps_read_samp_period(data
, &samp_period
);
458 *val2
= samp_period
* prst
;
459 return IIO_VAL_INT_PLUS_MICRO
;
467 static int ltr501_write_intr_prst(struct ltr501_data
*data
,
468 enum iio_chan_type type
,
471 int ret
, samp_period
, new_val
;
472 unsigned long period
;
474 if (val
< 0 || val2
< 0)
477 /* period in microseconds */
478 period
= ((val
* 1000000) + val2
);
482 ret
= ltr501_als_read_samp_period(data
, &samp_period
);
486 /* period should be atleast equal to sampling period */
487 if (period
< samp_period
)
490 new_val
= DIV_ROUND_UP(period
, samp_period
);
491 if (new_val
< 0 || new_val
> 0x0f)
494 mutex_lock(&data
->lock_als
);
495 ret
= regmap_field_write(data
->reg_als_prst
, new_val
);
496 mutex_unlock(&data
->lock_als
);
498 data
->als_period
= period
;
502 ret
= ltr501_ps_read_samp_period(data
, &samp_period
);
506 /* period should be atleast equal to rate */
507 if (period
< samp_period
)
510 new_val
= DIV_ROUND_UP(period
, samp_period
);
511 if (new_val
< 0 || new_val
> 0x0f)
514 mutex_lock(&data
->lock_ps
);
515 ret
= regmap_field_write(data
->reg_ps_prst
, new_val
);
516 mutex_unlock(&data
->lock_ps
);
518 data
->ps_period
= period
;
528 static ssize_t
ltr501_read_near_level(struct iio_dev
*indio_dev
,
530 const struct iio_chan_spec
*chan
,
533 struct ltr501_data
*data
= iio_priv(indio_dev
);
535 return sprintf(buf
, "%u\n", data
->near_level
);
538 static const struct iio_chan_spec_ext_info ltr501_ext_info
[] = {
541 .shared
= IIO_SEPARATE
,
542 .read
= ltr501_read_near_level
,
547 static const struct iio_event_spec ltr501_als_event_spec
[] = {
549 .type
= IIO_EV_TYPE_THRESH
,
550 .dir
= IIO_EV_DIR_RISING
,
551 .mask_separate
= BIT(IIO_EV_INFO_VALUE
),
553 .type
= IIO_EV_TYPE_THRESH
,
554 .dir
= IIO_EV_DIR_FALLING
,
555 .mask_separate
= BIT(IIO_EV_INFO_VALUE
),
557 .type
= IIO_EV_TYPE_THRESH
,
558 .dir
= IIO_EV_DIR_EITHER
,
559 .mask_separate
= BIT(IIO_EV_INFO_ENABLE
) |
560 BIT(IIO_EV_INFO_PERIOD
),
565 static const struct iio_event_spec ltr501_pxs_event_spec
[] = {
567 .type
= IIO_EV_TYPE_THRESH
,
568 .dir
= IIO_EV_DIR_RISING
,
569 .mask_separate
= BIT(IIO_EV_INFO_VALUE
),
571 .type
= IIO_EV_TYPE_THRESH
,
572 .dir
= IIO_EV_DIR_FALLING
,
573 .mask_separate
= BIT(IIO_EV_INFO_VALUE
),
575 .type
= IIO_EV_TYPE_THRESH
,
576 .dir
= IIO_EV_DIR_EITHER
,
577 .mask_separate
= BIT(IIO_EV_INFO_ENABLE
) |
578 BIT(IIO_EV_INFO_PERIOD
),
582 #define LTR501_INTENSITY_CHANNEL(_idx, _addr, _mod, _shared, \
583 _evspec, _evsize) { \
584 .type = IIO_INTENSITY, \
586 .address = (_addr), \
587 .channel2 = (_mod), \
588 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
589 .info_mask_shared_by_type = (_shared), \
590 .scan_index = (_idx), \
595 .endianness = IIO_CPU, \
597 .event_spec = _evspec,\
598 .num_event_specs = _evsize,\
601 #define LTR501_LIGHT_CHANNEL() { \
603 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \
607 static const struct iio_chan_spec ltr501_channels
[] = {
608 LTR501_LIGHT_CHANNEL(),
609 LTR501_INTENSITY_CHANNEL(0, LTR501_ALS_DATA0
, IIO_MOD_LIGHT_BOTH
, 0,
610 ltr501_als_event_spec
,
611 ARRAY_SIZE(ltr501_als_event_spec
)),
612 LTR501_INTENSITY_CHANNEL(1, LTR501_ALS_DATA1
, IIO_MOD_LIGHT_IR
,
613 BIT(IIO_CHAN_INFO_SCALE
) |
614 BIT(IIO_CHAN_INFO_INT_TIME
) |
615 BIT(IIO_CHAN_INFO_SAMP_FREQ
),
618 .type
= IIO_PROXIMITY
,
619 .address
= LTR501_PS_DATA
,
620 .info_mask_separate
= BIT(IIO_CHAN_INFO_RAW
) |
621 BIT(IIO_CHAN_INFO_SCALE
),
627 .endianness
= IIO_CPU
,
629 .event_spec
= ltr501_pxs_event_spec
,
630 .num_event_specs
= ARRAY_SIZE(ltr501_pxs_event_spec
),
631 .ext_info
= ltr501_ext_info
,
633 IIO_CHAN_SOFT_TIMESTAMP(3),
636 static const struct iio_chan_spec ltr301_channels
[] = {
637 LTR501_LIGHT_CHANNEL(),
638 LTR501_INTENSITY_CHANNEL(0, LTR501_ALS_DATA0
, IIO_MOD_LIGHT_BOTH
, 0,
639 ltr501_als_event_spec
,
640 ARRAY_SIZE(ltr501_als_event_spec
)),
641 LTR501_INTENSITY_CHANNEL(1, LTR501_ALS_DATA1
, IIO_MOD_LIGHT_IR
,
642 BIT(IIO_CHAN_INFO_SCALE
) |
643 BIT(IIO_CHAN_INFO_INT_TIME
) |
644 BIT(IIO_CHAN_INFO_SAMP_FREQ
),
646 IIO_CHAN_SOFT_TIMESTAMP(2),
649 static int ltr501_read_raw(struct iio_dev
*indio_dev
,
650 struct iio_chan_spec
const *chan
,
651 int *val
, int *val2
, long mask
)
653 struct ltr501_data
*data
= iio_priv(indio_dev
);
658 case IIO_CHAN_INFO_PROCESSED
:
659 switch (chan
->type
) {
661 ret
= iio_device_claim_direct_mode(indio_dev
);
665 mutex_lock(&data
->lock_als
);
666 ret
= ltr501_read_als(data
, buf
);
667 mutex_unlock(&data
->lock_als
);
668 iio_device_release_direct_mode(indio_dev
);
671 *val
= ltr501_calculate_lux(le16_to_cpu(buf
[1]),
672 le16_to_cpu(buf
[0]));
677 case IIO_CHAN_INFO_RAW
:
678 ret
= iio_device_claim_direct_mode(indio_dev
);
682 switch (chan
->type
) {
684 mutex_lock(&data
->lock_als
);
685 ret
= ltr501_read_als(data
, buf
);
686 mutex_unlock(&data
->lock_als
);
689 *val
= le16_to_cpu(chan
->address
== LTR501_ALS_DATA1
?
694 mutex_lock(&data
->lock_ps
);
695 ret
= ltr501_read_ps(data
);
696 mutex_unlock(&data
->lock_ps
);
699 *val
= ret
& LTR501_PS_DATA_MASK
;
707 iio_device_release_direct_mode(indio_dev
);
710 case IIO_CHAN_INFO_SCALE
:
711 switch (chan
->type
) {
713 i
= (data
->als_contr
& data
->chip_info
->als_gain_mask
)
714 >> data
->chip_info
->als_gain_shift
;
715 *val
= data
->chip_info
->als_gain
[i
].scale
;
716 *val2
= data
->chip_info
->als_gain
[i
].uscale
;
717 return IIO_VAL_INT_PLUS_MICRO
;
719 i
= (data
->ps_contr
& LTR501_CONTR_PS_GAIN_MASK
) >>
720 LTR501_CONTR_PS_GAIN_SHIFT
;
721 *val
= data
->chip_info
->ps_gain
[i
].scale
;
722 *val2
= data
->chip_info
->ps_gain
[i
].uscale
;
723 return IIO_VAL_INT_PLUS_MICRO
;
727 case IIO_CHAN_INFO_INT_TIME
:
728 switch (chan
->type
) {
730 return ltr501_read_it_time(data
, val
, val2
);
734 case IIO_CHAN_INFO_SAMP_FREQ
:
735 switch (chan
->type
) {
737 return ltr501_als_read_samp_freq(data
, val
, val2
);
739 return ltr501_ps_read_samp_freq(data
, val
, val2
);
747 static int ltr501_get_gain_index(const struct ltr501_gain
*gain
, int size
,
752 for (i
= 0; i
< size
; i
++)
753 if (val
== gain
[i
].scale
&& val2
== gain
[i
].uscale
)
759 static int ltr501_write_raw(struct iio_dev
*indio_dev
,
760 struct iio_chan_spec
const *chan
,
761 int val
, int val2
, long mask
)
763 struct ltr501_data
*data
= iio_priv(indio_dev
);
764 int i
, ret
, freq_val
, freq_val2
;
765 const struct ltr501_chip_info
*info
= data
->chip_info
;
767 ret
= iio_device_claim_direct_mode(indio_dev
);
772 case IIO_CHAN_INFO_SCALE
:
773 switch (chan
->type
) {
775 i
= ltr501_get_gain_index(info
->als_gain
,
776 info
->als_gain_tbl_size
,
783 data
->als_contr
&= ~info
->als_gain_mask
;
784 data
->als_contr
|= i
<< info
->als_gain_shift
;
786 ret
= regmap_write(data
->regmap
, LTR501_ALS_CONTR
,
790 i
= ltr501_get_gain_index(info
->ps_gain
,
791 info
->ps_gain_tbl_size
,
797 data
->ps_contr
&= ~LTR501_CONTR_PS_GAIN_MASK
;
798 data
->ps_contr
|= i
<< LTR501_CONTR_PS_GAIN_SHIFT
;
800 ret
= regmap_write(data
->regmap
, LTR501_PS_CONTR
,
809 case IIO_CHAN_INFO_INT_TIME
:
810 switch (chan
->type
) {
816 mutex_lock(&data
->lock_als
);
817 ret
= ltr501_set_it_time(data
, val2
);
818 mutex_unlock(&data
->lock_als
);
826 case IIO_CHAN_INFO_SAMP_FREQ
:
827 switch (chan
->type
) {
829 ret
= ltr501_als_read_samp_freq(data
, &freq_val
,
834 ret
= ltr501_als_write_samp_freq(data
, val
, val2
);
838 /* update persistence count when changing frequency */
839 ret
= ltr501_write_intr_prst(data
, chan
->type
,
840 0, data
->als_period
);
843 ret
= ltr501_als_write_samp_freq(data
, freq_val
,
847 ret
= ltr501_ps_read_samp_freq(data
, &freq_val
,
852 ret
= ltr501_ps_write_samp_freq(data
, val
, val2
);
856 /* update persistence count when changing frequency */
857 ret
= ltr501_write_intr_prst(data
, chan
->type
,
861 ret
= ltr501_ps_write_samp_freq(data
, freq_val
,
875 iio_device_release_direct_mode(indio_dev
);
879 static int ltr501_read_thresh(const struct iio_dev
*indio_dev
,
880 const struct iio_chan_spec
*chan
,
881 enum iio_event_type type
,
882 enum iio_event_direction dir
,
883 enum iio_event_info info
,
886 const struct ltr501_data
*data
= iio_priv(indio_dev
);
887 int ret
, thresh_data
;
889 switch (chan
->type
) {
892 case IIO_EV_DIR_RISING
:
893 ret
= regmap_bulk_read(data
->regmap
,
894 LTR501_ALS_THRESH_UP
,
898 *val
= thresh_data
& LTR501_ALS_THRESH_MASK
;
900 case IIO_EV_DIR_FALLING
:
901 ret
= regmap_bulk_read(data
->regmap
,
902 LTR501_ALS_THRESH_LOW
,
906 *val
= thresh_data
& LTR501_ALS_THRESH_MASK
;
913 case IIO_EV_DIR_RISING
:
914 ret
= regmap_bulk_read(data
->regmap
,
919 *val
= thresh_data
& LTR501_PS_THRESH_MASK
;
921 case IIO_EV_DIR_FALLING
:
922 ret
= regmap_bulk_read(data
->regmap
,
923 LTR501_PS_THRESH_LOW
,
927 *val
= thresh_data
& LTR501_PS_THRESH_MASK
;
939 static int ltr501_write_thresh(struct iio_dev
*indio_dev
,
940 const struct iio_chan_spec
*chan
,
941 enum iio_event_type type
,
942 enum iio_event_direction dir
,
943 enum iio_event_info info
,
946 struct ltr501_data
*data
= iio_priv(indio_dev
);
952 switch (chan
->type
) {
954 if (val
> LTR501_ALS_THRESH_MASK
)
957 case IIO_EV_DIR_RISING
:
958 mutex_lock(&data
->lock_als
);
959 ret
= regmap_bulk_write(data
->regmap
,
960 LTR501_ALS_THRESH_UP
,
962 mutex_unlock(&data
->lock_als
);
964 case IIO_EV_DIR_FALLING
:
965 mutex_lock(&data
->lock_als
);
966 ret
= regmap_bulk_write(data
->regmap
,
967 LTR501_ALS_THRESH_LOW
,
969 mutex_unlock(&data
->lock_als
);
975 if (val
> LTR501_PS_THRESH_MASK
)
978 case IIO_EV_DIR_RISING
:
979 mutex_lock(&data
->lock_ps
);
980 ret
= regmap_bulk_write(data
->regmap
,
983 mutex_unlock(&data
->lock_ps
);
985 case IIO_EV_DIR_FALLING
:
986 mutex_lock(&data
->lock_ps
);
987 ret
= regmap_bulk_write(data
->regmap
,
988 LTR501_PS_THRESH_LOW
,
990 mutex_unlock(&data
->lock_ps
);
1002 static int ltr501_read_event(struct iio_dev
*indio_dev
,
1003 const struct iio_chan_spec
*chan
,
1004 enum iio_event_type type
,
1005 enum iio_event_direction dir
,
1006 enum iio_event_info info
,
1007 int *val
, int *val2
)
1012 case IIO_EV_INFO_VALUE
:
1013 return ltr501_read_thresh(indio_dev
, chan
, type
, dir
,
1015 case IIO_EV_INFO_PERIOD
:
1016 ret
= ltr501_read_intr_prst(iio_priv(indio_dev
),
1018 *val
= *val2
/ 1000000;
1019 *val2
= *val2
% 1000000;
1028 static int ltr501_write_event(struct iio_dev
*indio_dev
,
1029 const struct iio_chan_spec
*chan
,
1030 enum iio_event_type type
,
1031 enum iio_event_direction dir
,
1032 enum iio_event_info info
,
1036 case IIO_EV_INFO_VALUE
:
1039 return ltr501_write_thresh(indio_dev
, chan
, type
, dir
,
1041 case IIO_EV_INFO_PERIOD
:
1042 return ltr501_write_intr_prst(iio_priv(indio_dev
), chan
->type
,
1051 static int ltr501_read_event_config(struct iio_dev
*indio_dev
,
1052 const struct iio_chan_spec
*chan
,
1053 enum iio_event_type type
,
1054 enum iio_event_direction dir
)
1056 struct ltr501_data
*data
= iio_priv(indio_dev
);
1059 switch (chan
->type
) {
1061 ret
= regmap_field_read(data
->reg_als_intr
, &status
);
1066 ret
= regmap_field_read(data
->reg_ps_intr
, &status
);
1077 static int ltr501_write_event_config(struct iio_dev
*indio_dev
,
1078 const struct iio_chan_spec
*chan
,
1079 enum iio_event_type type
,
1080 enum iio_event_direction dir
, bool state
)
1082 struct ltr501_data
*data
= iio_priv(indio_dev
);
1085 switch (chan
->type
) {
1087 mutex_lock(&data
->lock_als
);
1088 ret
= regmap_field_write(data
->reg_als_intr
, state
);
1089 mutex_unlock(&data
->lock_als
);
1092 mutex_lock(&data
->lock_ps
);
1093 ret
= regmap_field_write(data
->reg_ps_intr
, state
);
1094 mutex_unlock(&data
->lock_ps
);
1103 static ssize_t
ltr501_show_proximity_scale_avail(struct device
*dev
,
1104 struct device_attribute
*attr
,
1107 struct ltr501_data
*data
= iio_priv(dev_to_iio_dev(dev
));
1108 const struct ltr501_chip_info
*info
= data
->chip_info
;
1112 for (i
= 0; i
< info
->ps_gain_tbl_size
; i
++) {
1113 if (info
->ps_gain
[i
].scale
== LTR501_RESERVED_GAIN
)
1115 len
+= scnprintf(buf
+ len
, PAGE_SIZE
- len
, "%d.%06d ",
1116 info
->ps_gain
[i
].scale
,
1117 info
->ps_gain
[i
].uscale
);
1120 buf
[len
- 1] = '\n';
1125 static ssize_t
ltr501_show_intensity_scale_avail(struct device
*dev
,
1126 struct device_attribute
*attr
,
1129 struct ltr501_data
*data
= iio_priv(dev_to_iio_dev(dev
));
1130 const struct ltr501_chip_info
*info
= data
->chip_info
;
1134 for (i
= 0; i
< info
->als_gain_tbl_size
; i
++) {
1135 if (info
->als_gain
[i
].scale
== LTR501_RESERVED_GAIN
)
1137 len
+= scnprintf(buf
+ len
, PAGE_SIZE
- len
, "%d.%06d ",
1138 info
->als_gain
[i
].scale
,
1139 info
->als_gain
[i
].uscale
);
1142 buf
[len
- 1] = '\n';
1147 static IIO_CONST_ATTR_INT_TIME_AVAIL("0.05 0.1 0.2 0.4");
1148 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("20 10 5 2 1 0.5");
1150 static IIO_DEVICE_ATTR(in_proximity_scale_available
, S_IRUGO
,
1151 ltr501_show_proximity_scale_avail
, NULL
, 0);
1152 static IIO_DEVICE_ATTR(in_intensity_scale_available
, S_IRUGO
,
1153 ltr501_show_intensity_scale_avail
, NULL
, 0);
1155 static struct attribute
*ltr501_attributes
[] = {
1156 &iio_dev_attr_in_proximity_scale_available
.dev_attr
.attr
,
1157 &iio_dev_attr_in_intensity_scale_available
.dev_attr
.attr
,
1158 &iio_const_attr_integration_time_available
.dev_attr
.attr
,
1159 &iio_const_attr_sampling_frequency_available
.dev_attr
.attr
,
1163 static struct attribute
*ltr301_attributes
[] = {
1164 &iio_dev_attr_in_intensity_scale_available
.dev_attr
.attr
,
1165 &iio_const_attr_integration_time_available
.dev_attr
.attr
,
1166 &iio_const_attr_sampling_frequency_available
.dev_attr
.attr
,
1170 static const struct attribute_group ltr501_attribute_group
= {
1171 .attrs
= ltr501_attributes
,
1174 static const struct attribute_group ltr301_attribute_group
= {
1175 .attrs
= ltr301_attributes
,
1178 static const struct iio_info ltr501_info_no_irq
= {
1179 .read_raw
= ltr501_read_raw
,
1180 .write_raw
= ltr501_write_raw
,
1181 .attrs
= <r501_attribute_group
,
1184 static const struct iio_info ltr501_info
= {
1185 .read_raw
= ltr501_read_raw
,
1186 .write_raw
= ltr501_write_raw
,
1187 .attrs
= <r501_attribute_group
,
1188 .read_event_value
= <r501_read_event
,
1189 .write_event_value
= <r501_write_event
,
1190 .read_event_config
= <r501_read_event_config
,
1191 .write_event_config
= <r501_write_event_config
,
1194 static const struct iio_info ltr301_info_no_irq
= {
1195 .read_raw
= ltr501_read_raw
,
1196 .write_raw
= ltr501_write_raw
,
1197 .attrs
= <r301_attribute_group
,
1200 static const struct iio_info ltr301_info
= {
1201 .read_raw
= ltr501_read_raw
,
1202 .write_raw
= ltr501_write_raw
,
1203 .attrs
= <r301_attribute_group
,
1204 .read_event_value
= <r501_read_event
,
1205 .write_event_value
= <r501_write_event
,
1206 .read_event_config
= <r501_read_event_config
,
1207 .write_event_config
= <r501_write_event_config
,
1210 static const struct ltr501_chip_info ltr501_chip_info_tbl
[] = {
1213 .als_gain
= ltr501_als_gain_tbl
,
1214 .als_gain_tbl_size
= ARRAY_SIZE(ltr501_als_gain_tbl
),
1215 .ps_gain
= ltr501_ps_gain_tbl
,
1216 .ps_gain_tbl_size
= ARRAY_SIZE(ltr501_ps_gain_tbl
),
1217 .als_mode_active
= BIT(0) | BIT(1),
1218 .als_gain_mask
= BIT(3),
1219 .als_gain_shift
= 3,
1220 .info
= <r501_info
,
1221 .info_no_irq
= <r501_info_no_irq
,
1222 .channels
= ltr501_channels
,
1223 .no_channels
= ARRAY_SIZE(ltr501_channels
),
1227 .als_gain
= ltr559_als_gain_tbl
,
1228 .als_gain_tbl_size
= ARRAY_SIZE(ltr559_als_gain_tbl
),
1229 .ps_gain
= ltr559_ps_gain_tbl
,
1230 .ps_gain_tbl_size
= ARRAY_SIZE(ltr559_ps_gain_tbl
),
1231 .als_mode_active
= BIT(0),
1232 .als_gain_mask
= BIT(2) | BIT(3) | BIT(4),
1233 .als_gain_shift
= 2,
1234 .info
= <r501_info
,
1235 .info_no_irq
= <r501_info_no_irq
,
1236 .channels
= ltr501_channels
,
1237 .no_channels
= ARRAY_SIZE(ltr501_channels
),
1241 .als_gain
= ltr501_als_gain_tbl
,
1242 .als_gain_tbl_size
= ARRAY_SIZE(ltr501_als_gain_tbl
),
1243 .als_mode_active
= BIT(0) | BIT(1),
1244 .als_gain_mask
= BIT(3),
1245 .als_gain_shift
= 3,
1246 .info
= <r301_info
,
1247 .info_no_irq
= <r301_info_no_irq
,
1248 .channels
= ltr301_channels
,
1249 .no_channels
= ARRAY_SIZE(ltr301_channels
),
1253 .als_gain
= ltr559_als_gain_tbl
,
1254 .als_gain_tbl_size
= ARRAY_SIZE(ltr559_als_gain_tbl
),
1255 .als_mode_active
= BIT(0),
1256 .als_gain_mask
= BIT(2) | BIT(3) | BIT(4),
1257 .als_gain_shift
= 2,
1258 .info
= <r301_info
,
1259 .info_no_irq
= <r301_info_no_irq
,
1260 .channels
= ltr301_channels
,
1261 .no_channels
= ARRAY_SIZE(ltr301_channels
),
1265 static int ltr501_write_contr(struct ltr501_data
*data
, u8 als_val
, u8 ps_val
)
1269 ret
= regmap_write(data
->regmap
, LTR501_ALS_CONTR
, als_val
);
1273 return regmap_write(data
->regmap
, LTR501_PS_CONTR
, ps_val
);
1276 static irqreturn_t
ltr501_trigger_handler(int irq
, void *p
)
1278 struct iio_poll_func
*pf
= p
;
1279 struct iio_dev
*indio_dev
= pf
->indio_dev
;
1280 struct ltr501_data
*data
= iio_priv(indio_dev
);
1283 s64 ts
__aligned(8);
1290 memset(&scan
, 0, sizeof(scan
));
1292 /* figure out which data needs to be ready */
1293 if (test_bit(0, indio_dev
->active_scan_mask
) ||
1294 test_bit(1, indio_dev
->active_scan_mask
))
1295 mask
|= LTR501_STATUS_ALS_RDY
;
1296 if (test_bit(2, indio_dev
->active_scan_mask
))
1297 mask
|= LTR501_STATUS_PS_RDY
;
1299 ret
= ltr501_drdy(data
, mask
);
1303 if (mask
& LTR501_STATUS_ALS_RDY
) {
1304 ret
= regmap_bulk_read(data
->regmap
, LTR501_ALS_DATA1
,
1305 als_buf
, sizeof(als_buf
));
1308 if (test_bit(0, indio_dev
->active_scan_mask
))
1309 scan
.channels
[j
++] = le16_to_cpu(als_buf
[1]);
1310 if (test_bit(1, indio_dev
->active_scan_mask
))
1311 scan
.channels
[j
++] = le16_to_cpu(als_buf
[0]);
1314 if (mask
& LTR501_STATUS_PS_RDY
) {
1315 ret
= regmap_bulk_read(data
->regmap
, LTR501_PS_DATA
,
1319 scan
.channels
[j
++] = psdata
& LTR501_PS_DATA_MASK
;
1322 iio_push_to_buffers_with_timestamp(indio_dev
, &scan
,
1323 iio_get_time_ns(indio_dev
));
1326 iio_trigger_notify_done(indio_dev
->trig
);
1331 static irqreturn_t
ltr501_interrupt_handler(int irq
, void *private)
1333 struct iio_dev
*indio_dev
= private;
1334 struct ltr501_data
*data
= iio_priv(indio_dev
);
1337 ret
= regmap_read(data
->regmap
, LTR501_ALS_PS_STATUS
, &status
);
1339 dev_err(&data
->client
->dev
,
1340 "irq read int reg failed\n");
1344 if (status
& LTR501_STATUS_ALS_INTR
)
1345 iio_push_event(indio_dev
,
1346 IIO_UNMOD_EVENT_CODE(IIO_INTENSITY
, 0,
1349 iio_get_time_ns(indio_dev
));
1351 if (status
& LTR501_STATUS_PS_INTR
)
1352 iio_push_event(indio_dev
,
1353 IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY
, 0,
1356 iio_get_time_ns(indio_dev
));
1361 static int ltr501_init(struct ltr501_data
*data
)
1365 ret
= regmap_read(data
->regmap
, LTR501_ALS_CONTR
, &status
);
1369 data
->als_contr
= status
| data
->chip_info
->als_mode_active
;
1371 ret
= regmap_read(data
->regmap
, LTR501_PS_CONTR
, &status
);
1375 data
->ps_contr
= status
| LTR501_CONTR_ACTIVE
;
1377 ret
= ltr501_read_intr_prst(data
, IIO_INTENSITY
, &data
->als_period
);
1381 ret
= ltr501_read_intr_prst(data
, IIO_PROXIMITY
, &data
->ps_period
);
1385 return ltr501_write_contr(data
, data
->als_contr
, data
->ps_contr
);
1388 static bool ltr501_is_volatile_reg(struct device
*dev
, unsigned int reg
)
1391 case LTR501_ALS_DATA1
:
1392 case LTR501_ALS_DATA1_UPPER
:
1393 case LTR501_ALS_DATA0
:
1394 case LTR501_ALS_DATA0_UPPER
:
1395 case LTR501_ALS_PS_STATUS
:
1396 case LTR501_PS_DATA
:
1397 case LTR501_PS_DATA_UPPER
:
1404 static const struct regmap_config ltr501_regmap_config
= {
1405 .name
= LTR501_REGMAP_NAME
,
1408 .max_register
= LTR501_MAX_REG
,
1409 .cache_type
= REGCACHE_RBTREE
,
1410 .volatile_reg
= ltr501_is_volatile_reg
,
1413 static int ltr501_powerdown(struct ltr501_data
*data
)
1415 return ltr501_write_contr(data
, data
->als_contr
&
1416 ~data
->chip_info
->als_mode_active
,
1417 data
->ps_contr
& ~LTR501_CONTR_ACTIVE
);
1420 static int ltr501_probe(struct i2c_client
*client
)
1422 const struct i2c_device_id
*id
= i2c_client_get_device_id(client
);
1423 static const char * const regulator_names
[] = { "vdd", "vddio" };
1424 struct ltr501_data
*data
;
1425 struct iio_dev
*indio_dev
;
1426 struct regmap
*regmap
;
1427 const void *ddata
= NULL
;
1428 int partid
, chip_idx
;
1432 indio_dev
= devm_iio_device_alloc(&client
->dev
, sizeof(*data
));
1436 regmap
= devm_regmap_init_i2c(client
, <r501_regmap_config
);
1437 if (IS_ERR(regmap
)) {
1438 dev_err(&client
->dev
, "Regmap initialization failed.\n");
1439 return PTR_ERR(regmap
);
1442 data
= iio_priv(indio_dev
);
1443 i2c_set_clientdata(client
, indio_dev
);
1444 data
->client
= client
;
1445 data
->regmap
= regmap
;
1446 mutex_init(&data
->lock_als
);
1447 mutex_init(&data
->lock_ps
);
1449 ret
= devm_regulator_bulk_get_enable(&client
->dev
,
1450 ARRAY_SIZE(regulator_names
),
1453 return dev_err_probe(&client
->dev
, ret
,
1454 "Failed to get regulators\n");
1456 data
->reg_it
= devm_regmap_field_alloc(&client
->dev
, regmap
,
1458 if (IS_ERR(data
->reg_it
)) {
1459 dev_err(&client
->dev
, "Integ time reg field init failed.\n");
1460 return PTR_ERR(data
->reg_it
);
1463 data
->reg_als_intr
= devm_regmap_field_alloc(&client
->dev
, regmap
,
1464 reg_field_als_intr
);
1465 if (IS_ERR(data
->reg_als_intr
)) {
1466 dev_err(&client
->dev
, "ALS intr mode reg field init failed\n");
1467 return PTR_ERR(data
->reg_als_intr
);
1470 data
->reg_ps_intr
= devm_regmap_field_alloc(&client
->dev
, regmap
,
1472 if (IS_ERR(data
->reg_ps_intr
)) {
1473 dev_err(&client
->dev
, "PS intr mode reg field init failed.\n");
1474 return PTR_ERR(data
->reg_ps_intr
);
1477 data
->reg_als_rate
= devm_regmap_field_alloc(&client
->dev
, regmap
,
1478 reg_field_als_rate
);
1479 if (IS_ERR(data
->reg_als_rate
)) {
1480 dev_err(&client
->dev
, "ALS samp rate field init failed.\n");
1481 return PTR_ERR(data
->reg_als_rate
);
1484 data
->reg_ps_rate
= devm_regmap_field_alloc(&client
->dev
, regmap
,
1486 if (IS_ERR(data
->reg_ps_rate
)) {
1487 dev_err(&client
->dev
, "PS samp rate field init failed.\n");
1488 return PTR_ERR(data
->reg_ps_rate
);
1491 data
->reg_als_prst
= devm_regmap_field_alloc(&client
->dev
, regmap
,
1492 reg_field_als_prst
);
1493 if (IS_ERR(data
->reg_als_prst
)) {
1494 dev_err(&client
->dev
, "ALS prst reg field init failed\n");
1495 return PTR_ERR(data
->reg_als_prst
);
1498 data
->reg_ps_prst
= devm_regmap_field_alloc(&client
->dev
, regmap
,
1500 if (IS_ERR(data
->reg_ps_prst
)) {
1501 dev_err(&client
->dev
, "PS prst reg field init failed.\n");
1502 return PTR_ERR(data
->reg_ps_prst
);
1505 ret
= regmap_read(data
->regmap
, LTR501_PART_ID
, &partid
);
1511 chip_idx
= id
->driver_data
;
1513 name
= iio_get_acpi_device_name_and_data(&client
->dev
, &ddata
);
1514 chip_idx
= (intptr_t)ddata
;
1519 data
->chip_info
= <r501_chip_info_tbl
[chip_idx
];
1521 if ((partid
>> 4) != data
->chip_info
->partid
)
1524 if (device_property_read_u32(&client
->dev
, "proximity-near-level",
1526 data
->near_level
= 0;
1528 indio_dev
->info
= data
->chip_info
->info
;
1529 indio_dev
->channels
= data
->chip_info
->channels
;
1530 indio_dev
->num_channels
= data
->chip_info
->no_channels
;
1531 indio_dev
->name
= name
;
1532 indio_dev
->modes
= INDIO_DIRECT_MODE
;
1534 ret
= ltr501_init(data
);
1538 if (client
->irq
> 0) {
1539 ret
= devm_request_threaded_irq(&client
->dev
, client
->irq
,
1540 NULL
, ltr501_interrupt_handler
,
1541 IRQF_TRIGGER_FALLING
|
1543 "ltr501_thresh_event",
1546 dev_err(&client
->dev
, "request irq (%d) failed\n",
1551 indio_dev
->info
= data
->chip_info
->info_no_irq
;
1554 ret
= iio_triggered_buffer_setup(indio_dev
, NULL
,
1555 ltr501_trigger_handler
, NULL
);
1557 goto powerdown_on_error
;
1559 ret
= iio_device_register(indio_dev
);
1561 goto error_unreg_buffer
;
1566 iio_triggered_buffer_cleanup(indio_dev
);
1568 ltr501_powerdown(data
);
1572 static void ltr501_remove(struct i2c_client
*client
)
1574 struct iio_dev
*indio_dev
= i2c_get_clientdata(client
);
1576 iio_device_unregister(indio_dev
);
1577 iio_triggered_buffer_cleanup(indio_dev
);
1578 ltr501_powerdown(iio_priv(indio_dev
));
1581 static int ltr501_suspend(struct device
*dev
)
1583 struct ltr501_data
*data
= iio_priv(i2c_get_clientdata(
1584 to_i2c_client(dev
)));
1585 return ltr501_powerdown(data
);
1588 static int ltr501_resume(struct device
*dev
)
1590 struct ltr501_data
*data
= iio_priv(i2c_get_clientdata(
1591 to_i2c_client(dev
)));
1593 return ltr501_write_contr(data
, data
->als_contr
,
1597 static DEFINE_SIMPLE_DEV_PM_OPS(ltr501_pm_ops
, ltr501_suspend
, ltr501_resume
);
1599 static const struct acpi_device_id ltr_acpi_match
[] = {
1600 { "LTER0301", ltr301
},
1601 /* https://www.catalog.update.microsoft.com/Search.aspx?q=lter0303 */
1602 { "LTER0303", ltr303
},
1605 MODULE_DEVICE_TABLE(acpi
, ltr_acpi_match
);
1607 static const struct i2c_device_id ltr501_id
[] = {
1608 { "ltr501", ltr501
},
1609 { "ltr559", ltr559
},
1610 { "ltr301", ltr301
},
1611 { "ltr303", ltr303
},
1614 MODULE_DEVICE_TABLE(i2c
, ltr501_id
);
1616 static const struct of_device_id ltr501_of_match
[] = {
1617 { .compatible
= "liteon,ltr501", },
1618 { .compatible
= "liteon,ltr559", },
1619 { .compatible
= "liteon,ltr301", },
1620 { .compatible
= "liteon,ltr303", },
1623 MODULE_DEVICE_TABLE(of
, ltr501_of_match
);
1625 static struct i2c_driver ltr501_driver
= {
1627 .name
= LTR501_DRV_NAME
,
1628 .of_match_table
= ltr501_of_match
,
1629 .pm
= pm_sleep_ptr(<r501_pm_ops
),
1630 .acpi_match_table
= ltr_acpi_match
,
1632 .probe
= ltr501_probe
,
1633 .remove
= ltr501_remove
,
1634 .id_table
= ltr501_id
,
1637 module_i2c_driver(ltr501_driver
);
1639 MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");
1640 MODULE_DESCRIPTION("Lite-On LTR501 ambient light and proximity sensor driver");
1641 MODULE_LICENSE("GPL");