1 // SPDX-License-Identifier: GPL-2.0-only
3 * drivers/iio/light/tsl2563.c
5 * Copyright (C) 2008 Nokia Corporation
7 * Written by Timo O. Karjalainen <timo.o.karjalainen@nokia.com>
8 * Contact: Amit Kucheria <amit.kucheria@verdurent.com>
10 * Converted to IIO driver
11 * Amit Kucheria <amit.kucheria@verdurent.com>
14 #include <linux/module.h>
15 #include <linux/i2c.h>
16 #include <linux/interrupt.h>
17 #include <linux/irq.h>
18 #include <linux/sched.h>
19 #include <linux/mutex.h>
20 #include <linux/delay.h>
22 #include <linux/err.h>
23 #include <linux/slab.h>
25 #include <linux/iio/iio.h>
26 #include <linux/iio/sysfs.h>
27 #include <linux/iio/events.h>
28 #include <linux/platform_data/tsl2563.h>
30 /* Use this many bits for fraction part. */
31 #define ADC_FRAC_BITS 14
33 /* Given number of 1/10000's in ADC_FRAC_BITS precision. */
34 #define FRAC10K(f) (((f) * (1L << (ADC_FRAC_BITS))) / (10000))
36 /* Bits used for fraction in calibration coefficients.*/
37 #define CALIB_FRAC_BITS 10
38 /* 0.5 in CALIB_FRAC_BITS precision */
39 #define CALIB_FRAC_HALF (1 << (CALIB_FRAC_BITS - 1))
40 /* Make a fraction from a number n that was multiplied with b. */
41 #define CALIB_FRAC(n, b) (((n) << CALIB_FRAC_BITS) / (b))
42 /* Decimal 10^(digits in sysfs presentation) */
43 #define CALIB_BASE_SYSFS 1000
45 #define TSL2563_CMD 0x80
46 #define TSL2563_CLEARINT 0x40
48 #define TSL2563_REG_CTRL 0x00
49 #define TSL2563_REG_TIMING 0x01
50 #define TSL2563_REG_LOWLOW 0x02 /* data0 low threshold, 2 bytes */
51 #define TSL2563_REG_LOWHIGH 0x03
52 #define TSL2563_REG_HIGHLOW 0x04 /* data0 high threshold, 2 bytes */
53 #define TSL2563_REG_HIGHHIGH 0x05
54 #define TSL2563_REG_INT 0x06
55 #define TSL2563_REG_ID 0x0a
56 #define TSL2563_REG_DATA0LOW 0x0c /* broadband sensor value, 2 bytes */
57 #define TSL2563_REG_DATA0HIGH 0x0d
58 #define TSL2563_REG_DATA1LOW 0x0e /* infrared sensor value, 2 bytes */
59 #define TSL2563_REG_DATA1HIGH 0x0f
61 #define TSL2563_CMD_POWER_ON 0x03
62 #define TSL2563_CMD_POWER_OFF 0x00
63 #define TSL2563_CTRL_POWER_MASK 0x03
65 #define TSL2563_TIMING_13MS 0x00
66 #define TSL2563_TIMING_100MS 0x01
67 #define TSL2563_TIMING_400MS 0x02
68 #define TSL2563_TIMING_MASK 0x03
69 #define TSL2563_TIMING_GAIN16 0x10
70 #define TSL2563_TIMING_GAIN1 0x00
72 #define TSL2563_INT_DISBLED 0x00
73 #define TSL2563_INT_LEVEL 0x10
74 #define TSL2563_INT_PERSIST(n) ((n) & 0x0F)
76 struct tsl2563_gainlevel_coeff
{
82 static const struct tsl2563_gainlevel_coeff tsl2563_gainlevel_table
[] = {
84 .gaintime
= TSL2563_TIMING_400MS
| TSL2563_TIMING_GAIN16
,
88 .gaintime
= TSL2563_TIMING_400MS
| TSL2563_TIMING_GAIN1
,
92 .gaintime
= TSL2563_TIMING_100MS
| TSL2563_TIMING_GAIN1
,
96 .gaintime
= TSL2563_TIMING_13MS
| TSL2563_TIMING_GAIN1
,
102 struct tsl2563_chip
{
104 struct i2c_client
*client
;
105 struct delayed_work poweroff_work
;
107 /* Remember state for suspend and resume functions */
110 struct tsl2563_gainlevel_coeff
const *gainlevel
;
117 /* Calibration coefficients */
122 /* Cache current values, to be returned while suspended */
127 static int tsl2563_set_power(struct tsl2563_chip
*chip
, int on
)
129 struct i2c_client
*client
= chip
->client
;
132 cmd
= on
? TSL2563_CMD_POWER_ON
: TSL2563_CMD_POWER_OFF
;
133 return i2c_smbus_write_byte_data(client
,
134 TSL2563_CMD
| TSL2563_REG_CTRL
, cmd
);
138 * Return value is 0 for off, 1 for on, or a negative error
139 * code if reading failed.
141 static int tsl2563_get_power(struct tsl2563_chip
*chip
)
143 struct i2c_client
*client
= chip
->client
;
146 ret
= i2c_smbus_read_byte_data(client
, TSL2563_CMD
| TSL2563_REG_CTRL
);
150 return (ret
& TSL2563_CTRL_POWER_MASK
) == TSL2563_CMD_POWER_ON
;
153 static int tsl2563_configure(struct tsl2563_chip
*chip
)
157 ret
= i2c_smbus_write_byte_data(chip
->client
,
158 TSL2563_CMD
| TSL2563_REG_TIMING
,
159 chip
->gainlevel
->gaintime
);
162 ret
= i2c_smbus_write_byte_data(chip
->client
,
163 TSL2563_CMD
| TSL2563_REG_HIGHLOW
,
164 chip
->high_thres
& 0xFF);
167 ret
= i2c_smbus_write_byte_data(chip
->client
,
168 TSL2563_CMD
| TSL2563_REG_HIGHHIGH
,
169 (chip
->high_thres
>> 8) & 0xFF);
172 ret
= i2c_smbus_write_byte_data(chip
->client
,
173 TSL2563_CMD
| TSL2563_REG_LOWLOW
,
174 chip
->low_thres
& 0xFF);
177 ret
= i2c_smbus_write_byte_data(chip
->client
,
178 TSL2563_CMD
| TSL2563_REG_LOWHIGH
,
179 (chip
->low_thres
>> 8) & 0xFF);
181 * Interrupt register is automatically written anyway if it is relevant
188 static void tsl2563_poweroff_work(struct work_struct
*work
)
190 struct tsl2563_chip
*chip
=
191 container_of(work
, struct tsl2563_chip
, poweroff_work
.work
);
192 tsl2563_set_power(chip
, 0);
195 static int tsl2563_detect(struct tsl2563_chip
*chip
)
199 ret
= tsl2563_set_power(chip
, 1);
203 ret
= tsl2563_get_power(chip
);
207 return ret
? 0 : -ENODEV
;
210 static int tsl2563_read_id(struct tsl2563_chip
*chip
, u8
*id
)
212 struct i2c_client
*client
= chip
->client
;
215 ret
= i2c_smbus_read_byte_data(client
, TSL2563_CMD
| TSL2563_REG_ID
);
225 * "Normalized" ADC value is one obtained with 400ms of integration time and
226 * 16x gain. This function returns the number of bits of shift needed to
227 * convert between normalized values and HW values obtained using given
228 * timing and gain settings.
230 static int tsl2563_adc_shiftbits(u8 timing
)
234 switch (timing
& TSL2563_TIMING_MASK
) {
235 case TSL2563_TIMING_13MS
:
238 case TSL2563_TIMING_100MS
:
241 case TSL2563_TIMING_400MS
:
246 if (!(timing
& TSL2563_TIMING_GAIN16
))
252 /* Convert a HW ADC value to normalized scale. */
253 static u32
tsl2563_normalize_adc(u16 adc
, u8 timing
)
255 return adc
<< tsl2563_adc_shiftbits(timing
);
258 static void tsl2563_wait_adc(struct tsl2563_chip
*chip
)
262 switch (chip
->gainlevel
->gaintime
& TSL2563_TIMING_MASK
) {
263 case TSL2563_TIMING_13MS
:
266 case TSL2563_TIMING_100MS
:
273 * TODO: Make sure that we wait at least required delay but why we
274 * have to extend it one tick more?
276 schedule_timeout_interruptible(msecs_to_jiffies(delay
) + 2);
279 static int tsl2563_adjust_gainlevel(struct tsl2563_chip
*chip
, u16 adc
)
281 struct i2c_client
*client
= chip
->client
;
283 if (adc
> chip
->gainlevel
->max
|| adc
< chip
->gainlevel
->min
) {
285 (adc
> chip
->gainlevel
->max
) ?
286 chip
->gainlevel
++ : chip
->gainlevel
--;
288 i2c_smbus_write_byte_data(client
,
289 TSL2563_CMD
| TSL2563_REG_TIMING
,
290 chip
->gainlevel
->gaintime
);
292 tsl2563_wait_adc(chip
);
293 tsl2563_wait_adc(chip
);
300 static int tsl2563_get_adc(struct tsl2563_chip
*chip
)
302 struct i2c_client
*client
= chip
->client
;
310 if (!chip
->int_enabled
) {
311 cancel_delayed_work(&chip
->poweroff_work
);
313 if (!tsl2563_get_power(chip
)) {
314 ret
= tsl2563_set_power(chip
, 1);
317 ret
= tsl2563_configure(chip
);
320 tsl2563_wait_adc(chip
);
325 ret
= i2c_smbus_read_word_data(client
,
326 TSL2563_CMD
| TSL2563_REG_DATA0LOW
);
331 ret
= i2c_smbus_read_word_data(client
,
332 TSL2563_CMD
| TSL2563_REG_DATA1LOW
);
337 retry
= tsl2563_adjust_gainlevel(chip
, adc0
);
340 chip
->data0
= tsl2563_normalize_adc(adc0
, chip
->gainlevel
->gaintime
);
341 chip
->data1
= tsl2563_normalize_adc(adc1
, chip
->gainlevel
->gaintime
);
343 if (!chip
->int_enabled
)
344 schedule_delayed_work(&chip
->poweroff_work
, 5 * HZ
);
351 static inline int tsl2563_calib_to_sysfs(u32 calib
)
353 return (int) (((calib
* CALIB_BASE_SYSFS
) +
354 CALIB_FRAC_HALF
) >> CALIB_FRAC_BITS
);
357 static inline u32
tsl2563_calib_from_sysfs(int value
)
359 return (((u32
) value
) << CALIB_FRAC_BITS
) / CALIB_BASE_SYSFS
;
363 * Conversions between lux and ADC values.
365 * The basic formula is lux = c0 * adc0 - c1 * adc1, where c0 and c1 are
366 * appropriate constants. Different constants are needed for different
367 * kinds of light, determined by the ratio adc1/adc0 (basically the ratio
368 * of the intensities in infrared and visible wavelengths). lux_table below
369 * lists the upper threshold of the adc1/adc0 ratio and the corresponding
373 struct tsl2563_lux_coeff
{
374 unsigned long ch_ratio
;
375 unsigned long ch0_coeff
;
376 unsigned long ch1_coeff
;
379 static const struct tsl2563_lux_coeff lux_table
[] = {
381 .ch_ratio
= FRAC10K(1300),
382 .ch0_coeff
= FRAC10K(315),
383 .ch1_coeff
= FRAC10K(262),
385 .ch_ratio
= FRAC10K(2600),
386 .ch0_coeff
= FRAC10K(337),
387 .ch1_coeff
= FRAC10K(430),
389 .ch_ratio
= FRAC10K(3900),
390 .ch0_coeff
= FRAC10K(363),
391 .ch1_coeff
= FRAC10K(529),
393 .ch_ratio
= FRAC10K(5200),
394 .ch0_coeff
= FRAC10K(392),
395 .ch1_coeff
= FRAC10K(605),
397 .ch_ratio
= FRAC10K(6500),
398 .ch0_coeff
= FRAC10K(229),
399 .ch1_coeff
= FRAC10K(291),
401 .ch_ratio
= FRAC10K(8000),
402 .ch0_coeff
= FRAC10K(157),
403 .ch1_coeff
= FRAC10K(180),
405 .ch_ratio
= FRAC10K(13000),
406 .ch0_coeff
= FRAC10K(34),
407 .ch1_coeff
= FRAC10K(26),
409 .ch_ratio
= ULONG_MAX
,
415 /* Convert normalized, scaled ADC values to lux. */
416 static unsigned int tsl2563_adc_to_lux(u32 adc0
, u32 adc1
)
418 const struct tsl2563_lux_coeff
*lp
= lux_table
;
419 unsigned long ratio
, lux
, ch0
= adc0
, ch1
= adc1
;
421 ratio
= ch0
? ((ch1
<< ADC_FRAC_BITS
) / ch0
) : ULONG_MAX
;
423 while (lp
->ch_ratio
< ratio
)
426 lux
= ch0
* lp
->ch0_coeff
- ch1
* lp
->ch1_coeff
;
428 return (unsigned int) (lux
>> ADC_FRAC_BITS
);
431 /* Apply calibration coefficient to ADC count. */
432 static u32
tsl2563_calib_adc(u32 adc
, u32 calib
)
434 unsigned long scaled
= adc
;
437 scaled
>>= CALIB_FRAC_BITS
;
442 static int tsl2563_write_raw(struct iio_dev
*indio_dev
,
443 struct iio_chan_spec
const *chan
,
448 struct tsl2563_chip
*chip
= iio_priv(indio_dev
);
450 if (mask
!= IIO_CHAN_INFO_CALIBSCALE
)
452 if (chan
->channel2
== IIO_MOD_LIGHT_BOTH
)
453 chip
->calib0
= tsl2563_calib_from_sysfs(val
);
454 else if (chan
->channel2
== IIO_MOD_LIGHT_IR
)
455 chip
->calib1
= tsl2563_calib_from_sysfs(val
);
462 static int tsl2563_read_raw(struct iio_dev
*indio_dev
,
463 struct iio_chan_spec
const *chan
,
470 struct tsl2563_chip
*chip
= iio_priv(indio_dev
);
472 mutex_lock(&chip
->lock
);
474 case IIO_CHAN_INFO_RAW
:
475 case IIO_CHAN_INFO_PROCESSED
:
476 switch (chan
->type
) {
478 ret
= tsl2563_get_adc(chip
);
481 calib0
= tsl2563_calib_adc(chip
->data0
, chip
->calib0
) *
482 chip
->cover_comp_gain
;
483 calib1
= tsl2563_calib_adc(chip
->data1
, chip
->calib1
) *
484 chip
->cover_comp_gain
;
485 *val
= tsl2563_adc_to_lux(calib0
, calib1
);
489 ret
= tsl2563_get_adc(chip
);
492 if (chan
->channel2
== IIO_MOD_LIGHT_BOTH
)
503 case IIO_CHAN_INFO_CALIBSCALE
:
504 if (chan
->channel2
== IIO_MOD_LIGHT_BOTH
)
505 *val
= tsl2563_calib_to_sysfs(chip
->calib0
);
507 *val
= tsl2563_calib_to_sysfs(chip
->calib1
);
516 mutex_unlock(&chip
->lock
);
520 static const struct iio_event_spec tsl2563_events
[] = {
522 .type
= IIO_EV_TYPE_THRESH
,
523 .dir
= IIO_EV_DIR_RISING
,
524 .mask_separate
= BIT(IIO_EV_INFO_VALUE
) |
525 BIT(IIO_EV_INFO_ENABLE
),
527 .type
= IIO_EV_TYPE_THRESH
,
528 .dir
= IIO_EV_DIR_FALLING
,
529 .mask_separate
= BIT(IIO_EV_INFO_VALUE
) |
530 BIT(IIO_EV_INFO_ENABLE
),
534 static const struct iio_chan_spec tsl2563_channels
[] = {
538 .info_mask_separate
= BIT(IIO_CHAN_INFO_PROCESSED
),
541 .type
= IIO_INTENSITY
,
543 .channel2
= IIO_MOD_LIGHT_BOTH
,
544 .info_mask_separate
= BIT(IIO_CHAN_INFO_RAW
) |
545 BIT(IIO_CHAN_INFO_CALIBSCALE
),
546 .event_spec
= tsl2563_events
,
547 .num_event_specs
= ARRAY_SIZE(tsl2563_events
),
549 .type
= IIO_INTENSITY
,
551 .channel2
= IIO_MOD_LIGHT_IR
,
552 .info_mask_separate
= BIT(IIO_CHAN_INFO_RAW
) |
553 BIT(IIO_CHAN_INFO_CALIBSCALE
),
557 static int tsl2563_read_thresh(struct iio_dev
*indio_dev
,
558 const struct iio_chan_spec
*chan
, enum iio_event_type type
,
559 enum iio_event_direction dir
, enum iio_event_info info
, int *val
,
562 struct tsl2563_chip
*chip
= iio_priv(indio_dev
);
565 case IIO_EV_DIR_RISING
:
566 *val
= chip
->high_thres
;
568 case IIO_EV_DIR_FALLING
:
569 *val
= chip
->low_thres
;
578 static int tsl2563_write_thresh(struct iio_dev
*indio_dev
,
579 const struct iio_chan_spec
*chan
, enum iio_event_type type
,
580 enum iio_event_direction dir
, enum iio_event_info info
, int val
,
583 struct tsl2563_chip
*chip
= iio_priv(indio_dev
);
587 if (dir
== IIO_EV_DIR_RISING
)
588 address
= TSL2563_REG_HIGHLOW
;
590 address
= TSL2563_REG_LOWLOW
;
591 mutex_lock(&chip
->lock
);
592 ret
= i2c_smbus_write_byte_data(chip
->client
, TSL2563_CMD
| address
,
596 ret
= i2c_smbus_write_byte_data(chip
->client
,
597 TSL2563_CMD
| (address
+ 1),
599 if (dir
== IIO_EV_DIR_RISING
)
600 chip
->high_thres
= val
;
602 chip
->low_thres
= val
;
605 mutex_unlock(&chip
->lock
);
610 static irqreturn_t
tsl2563_event_handler(int irq
, void *private)
612 struct iio_dev
*dev_info
= private;
613 struct tsl2563_chip
*chip
= iio_priv(dev_info
);
615 iio_push_event(dev_info
,
616 IIO_UNMOD_EVENT_CODE(IIO_INTENSITY
,
620 iio_get_time_ns(dev_info
));
622 /* clear the interrupt and push the event */
623 i2c_smbus_write_byte(chip
->client
, TSL2563_CMD
| TSL2563_CLEARINT
);
627 static int tsl2563_write_interrupt_config(struct iio_dev
*indio_dev
,
628 const struct iio_chan_spec
*chan
, enum iio_event_type type
,
629 enum iio_event_direction dir
, int state
)
631 struct tsl2563_chip
*chip
= iio_priv(indio_dev
);
634 mutex_lock(&chip
->lock
);
635 if (state
&& !(chip
->intr
& 0x30)) {
638 /* ensure the chip is actually on */
639 cancel_delayed_work(&chip
->poweroff_work
);
640 if (!tsl2563_get_power(chip
)) {
641 ret
= tsl2563_set_power(chip
, 1);
644 ret
= tsl2563_configure(chip
);
648 ret
= i2c_smbus_write_byte_data(chip
->client
,
649 TSL2563_CMD
| TSL2563_REG_INT
,
651 chip
->int_enabled
= true;
654 if (!state
&& (chip
->intr
& 0x30)) {
656 ret
= i2c_smbus_write_byte_data(chip
->client
,
657 TSL2563_CMD
| TSL2563_REG_INT
,
659 chip
->int_enabled
= false;
660 /* now the interrupt is not enabled, we can go to sleep */
661 schedule_delayed_work(&chip
->poweroff_work
, 5 * HZ
);
664 mutex_unlock(&chip
->lock
);
669 static int tsl2563_read_interrupt_config(struct iio_dev
*indio_dev
,
670 const struct iio_chan_spec
*chan
, enum iio_event_type type
,
671 enum iio_event_direction dir
)
673 struct tsl2563_chip
*chip
= iio_priv(indio_dev
);
676 mutex_lock(&chip
->lock
);
677 ret
= i2c_smbus_read_byte_data(chip
->client
,
678 TSL2563_CMD
| TSL2563_REG_INT
);
679 mutex_unlock(&chip
->lock
);
683 return !!(ret
& 0x30);
686 static const struct iio_info tsl2563_info_no_irq
= {
687 .read_raw
= &tsl2563_read_raw
,
688 .write_raw
= &tsl2563_write_raw
,
691 static const struct iio_info tsl2563_info
= {
692 .read_raw
= &tsl2563_read_raw
,
693 .write_raw
= &tsl2563_write_raw
,
694 .read_event_value
= &tsl2563_read_thresh
,
695 .write_event_value
= &tsl2563_write_thresh
,
696 .read_event_config
= &tsl2563_read_interrupt_config
,
697 .write_event_config
= &tsl2563_write_interrupt_config
,
700 static int tsl2563_probe(struct i2c_client
*client
,
701 const struct i2c_device_id
*device_id
)
703 struct iio_dev
*indio_dev
;
704 struct tsl2563_chip
*chip
;
705 struct tsl2563_platform_data
*pdata
= client
->dev
.platform_data
;
706 struct device_node
*np
= client
->dev
.of_node
;
710 indio_dev
= devm_iio_device_alloc(&client
->dev
, sizeof(*chip
));
714 chip
= iio_priv(indio_dev
);
716 i2c_set_clientdata(client
, chip
);
717 chip
->client
= client
;
719 err
= tsl2563_detect(chip
);
721 dev_err(&client
->dev
, "detect error %d\n", -err
);
725 err
= tsl2563_read_id(chip
, &id
);
727 dev_err(&client
->dev
, "read id error %d\n", -err
);
731 mutex_init(&chip
->lock
);
733 /* Default values used until userspace says otherwise */
734 chip
->low_thres
= 0x0;
735 chip
->high_thres
= 0xffff;
736 chip
->gainlevel
= tsl2563_gainlevel_table
;
737 chip
->intr
= TSL2563_INT_PERSIST(4);
738 chip
->calib0
= tsl2563_calib_from_sysfs(CALIB_BASE_SYSFS
);
739 chip
->calib1
= tsl2563_calib_from_sysfs(CALIB_BASE_SYSFS
);
742 chip
->cover_comp_gain
= pdata
->cover_comp_gain
;
744 of_property_read_u32(np
, "amstaos,cover-comp-gain",
745 &chip
->cover_comp_gain
);
747 chip
->cover_comp_gain
= 1;
749 dev_info(&client
->dev
, "model %d, rev. %d\n", id
>> 4, id
& 0x0f);
750 indio_dev
->name
= client
->name
;
751 indio_dev
->channels
= tsl2563_channels
;
752 indio_dev
->num_channels
= ARRAY_SIZE(tsl2563_channels
);
753 indio_dev
->dev
.parent
= &client
->dev
;
754 indio_dev
->modes
= INDIO_DIRECT_MODE
;
757 indio_dev
->info
= &tsl2563_info
;
759 indio_dev
->info
= &tsl2563_info_no_irq
;
762 err
= devm_request_threaded_irq(&client
->dev
, client
->irq
,
764 &tsl2563_event_handler
,
765 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
769 dev_err(&client
->dev
, "irq request error %d\n", -err
);
774 err
= tsl2563_configure(chip
);
776 dev_err(&client
->dev
, "configure error %d\n", -err
);
780 INIT_DELAYED_WORK(&chip
->poweroff_work
, tsl2563_poweroff_work
);
782 /* The interrupt cannot yet be enabled so this is fine without lock */
783 schedule_delayed_work(&chip
->poweroff_work
, 5 * HZ
);
785 err
= iio_device_register(indio_dev
);
787 dev_err(&client
->dev
, "iio registration error %d\n", -err
);
794 cancel_delayed_work_sync(&chip
->poweroff_work
);
798 static int tsl2563_remove(struct i2c_client
*client
)
800 struct tsl2563_chip
*chip
= i2c_get_clientdata(client
);
801 struct iio_dev
*indio_dev
= iio_priv_to_dev(chip
);
803 iio_device_unregister(indio_dev
);
804 if (!chip
->int_enabled
)
805 cancel_delayed_work(&chip
->poweroff_work
);
806 /* Ensure that interrupts are disabled - then flush any bottom halves */
808 i2c_smbus_write_byte_data(chip
->client
, TSL2563_CMD
| TSL2563_REG_INT
,
810 flush_scheduled_work();
811 tsl2563_set_power(chip
, 0);
816 #ifdef CONFIG_PM_SLEEP
817 static int tsl2563_suspend(struct device
*dev
)
819 struct tsl2563_chip
*chip
= i2c_get_clientdata(to_i2c_client(dev
));
822 mutex_lock(&chip
->lock
);
824 ret
= tsl2563_set_power(chip
, 0);
828 chip
->suspended
= true;
831 mutex_unlock(&chip
->lock
);
835 static int tsl2563_resume(struct device
*dev
)
837 struct tsl2563_chip
*chip
= i2c_get_clientdata(to_i2c_client(dev
));
840 mutex_lock(&chip
->lock
);
842 ret
= tsl2563_set_power(chip
, 1);
846 ret
= tsl2563_configure(chip
);
850 chip
->suspended
= false;
853 mutex_unlock(&chip
->lock
);
857 static SIMPLE_DEV_PM_OPS(tsl2563_pm_ops
, tsl2563_suspend
, tsl2563_resume
);
858 #define TSL2563_PM_OPS (&tsl2563_pm_ops)
860 #define TSL2563_PM_OPS NULL
863 static const struct i2c_device_id tsl2563_id
[] = {
870 MODULE_DEVICE_TABLE(i2c
, tsl2563_id
);
872 static const struct of_device_id tsl2563_of_match
[] = {
873 { .compatible
= "amstaos,tsl2560" },
874 { .compatible
= "amstaos,tsl2561" },
875 { .compatible
= "amstaos,tsl2562" },
876 { .compatible
= "amstaos,tsl2563" },
879 MODULE_DEVICE_TABLE(of
, tsl2563_of_match
);
881 static struct i2c_driver tsl2563_i2c_driver
= {
884 .of_match_table
= tsl2563_of_match
,
885 .pm
= TSL2563_PM_OPS
,
887 .probe
= tsl2563_probe
,
888 .remove
= tsl2563_remove
,
889 .id_table
= tsl2563_id
,
891 module_i2c_driver(tsl2563_i2c_driver
);
893 MODULE_AUTHOR("Nokia Corporation");
894 MODULE_DESCRIPTION("tsl2563 light sensor driver");
895 MODULE_LICENSE("GPL");