2 * drivers/iio/light/tsl2563.c
4 * Copyright (C) 2008 Nokia Corporation
6 * Written by Timo O. Karjalainen <timo.o.karjalainen@nokia.com>
7 * Contact: Amit Kucheria <amit.kucheria@verdurent.com>
9 * Converted to IIO driver
10 * Amit Kucheria <amit.kucheria@verdurent.com>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * version 2 as published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 #include <linux/module.h>
28 #include <linux/i2c.h>
29 #include <linux/interrupt.h>
30 #include <linux/irq.h>
31 #include <linux/sched.h>
32 #include <linux/mutex.h>
33 #include <linux/delay.h>
35 #include <linux/err.h>
36 #include <linux/slab.h>
38 #include <linux/iio/iio.h>
39 #include <linux/iio/sysfs.h>
40 #include <linux/iio/events.h>
41 #include <linux/platform_data/tsl2563.h>
43 /* Use this many bits for fraction part. */
44 #define ADC_FRAC_BITS 14
46 /* Given number of 1/10000's in ADC_FRAC_BITS precision. */
47 #define FRAC10K(f) (((f) * (1L << (ADC_FRAC_BITS))) / (10000))
49 /* Bits used for fraction in calibration coefficients.*/
50 #define CALIB_FRAC_BITS 10
51 /* 0.5 in CALIB_FRAC_BITS precision */
52 #define CALIB_FRAC_HALF (1 << (CALIB_FRAC_BITS - 1))
53 /* Make a fraction from a number n that was multiplied with b. */
54 #define CALIB_FRAC(n, b) (((n) << CALIB_FRAC_BITS) / (b))
55 /* Decimal 10^(digits in sysfs presentation) */
56 #define CALIB_BASE_SYSFS 1000
58 #define TSL2563_CMD 0x80
59 #define TSL2563_CLEARINT 0x40
61 #define TSL2563_REG_CTRL 0x00
62 #define TSL2563_REG_TIMING 0x01
63 #define TSL2563_REG_LOWLOW 0x02 /* data0 low threshold, 2 bytes */
64 #define TSL2563_REG_LOWHIGH 0x03
65 #define TSL2563_REG_HIGHLOW 0x04 /* data0 high threshold, 2 bytes */
66 #define TSL2563_REG_HIGHHIGH 0x05
67 #define TSL2563_REG_INT 0x06
68 #define TSL2563_REG_ID 0x0a
69 #define TSL2563_REG_DATA0LOW 0x0c /* broadband sensor value, 2 bytes */
70 #define TSL2563_REG_DATA0HIGH 0x0d
71 #define TSL2563_REG_DATA1LOW 0x0e /* infrared sensor value, 2 bytes */
72 #define TSL2563_REG_DATA1HIGH 0x0f
74 #define TSL2563_CMD_POWER_ON 0x03
75 #define TSL2563_CMD_POWER_OFF 0x00
76 #define TSL2563_CTRL_POWER_MASK 0x03
78 #define TSL2563_TIMING_13MS 0x00
79 #define TSL2563_TIMING_100MS 0x01
80 #define TSL2563_TIMING_400MS 0x02
81 #define TSL2563_TIMING_MASK 0x03
82 #define TSL2563_TIMING_GAIN16 0x10
83 #define TSL2563_TIMING_GAIN1 0x00
85 #define TSL2563_INT_DISBLED 0x00
86 #define TSL2563_INT_LEVEL 0x10
87 #define TSL2563_INT_PERSIST(n) ((n) & 0x0F)
89 struct tsl2563_gainlevel_coeff
{
95 static const struct tsl2563_gainlevel_coeff tsl2563_gainlevel_table
[] = {
97 .gaintime
= TSL2563_TIMING_400MS
| TSL2563_TIMING_GAIN16
,
101 .gaintime
= TSL2563_TIMING_400MS
| TSL2563_TIMING_GAIN1
,
105 .gaintime
= TSL2563_TIMING_100MS
| TSL2563_TIMING_GAIN1
,
109 .gaintime
= TSL2563_TIMING_13MS
| TSL2563_TIMING_GAIN1
,
115 struct tsl2563_chip
{
117 struct i2c_client
*client
;
118 struct delayed_work poweroff_work
;
120 /* Remember state for suspend and resume functions */
123 struct tsl2563_gainlevel_coeff
const *gainlevel
;
130 /* Calibration coefficients */
135 /* Cache current values, to be returned while suspended */
140 static int tsl2563_set_power(struct tsl2563_chip
*chip
, int on
)
142 struct i2c_client
*client
= chip
->client
;
145 cmd
= on
? TSL2563_CMD_POWER_ON
: TSL2563_CMD_POWER_OFF
;
146 return i2c_smbus_write_byte_data(client
,
147 TSL2563_CMD
| TSL2563_REG_CTRL
, cmd
);
151 * Return value is 0 for off, 1 for on, or a negative error
152 * code if reading failed.
154 static int tsl2563_get_power(struct tsl2563_chip
*chip
)
156 struct i2c_client
*client
= chip
->client
;
159 ret
= i2c_smbus_read_byte_data(client
, TSL2563_CMD
| TSL2563_REG_CTRL
);
163 return (ret
& TSL2563_CTRL_POWER_MASK
) == TSL2563_CMD_POWER_ON
;
166 static int tsl2563_configure(struct tsl2563_chip
*chip
)
170 ret
= i2c_smbus_write_byte_data(chip
->client
,
171 TSL2563_CMD
| TSL2563_REG_TIMING
,
172 chip
->gainlevel
->gaintime
);
175 ret
= i2c_smbus_write_byte_data(chip
->client
,
176 TSL2563_CMD
| TSL2563_REG_HIGHLOW
,
177 chip
->high_thres
& 0xFF);
180 ret
= i2c_smbus_write_byte_data(chip
->client
,
181 TSL2563_CMD
| TSL2563_REG_HIGHHIGH
,
182 (chip
->high_thres
>> 8) & 0xFF);
185 ret
= i2c_smbus_write_byte_data(chip
->client
,
186 TSL2563_CMD
| TSL2563_REG_LOWLOW
,
187 chip
->low_thres
& 0xFF);
190 ret
= i2c_smbus_write_byte_data(chip
->client
,
191 TSL2563_CMD
| TSL2563_REG_LOWHIGH
,
192 (chip
->low_thres
>> 8) & 0xFF);
194 * Interrupt register is automatically written anyway if it is relevant
201 static void tsl2563_poweroff_work(struct work_struct
*work
)
203 struct tsl2563_chip
*chip
=
204 container_of(work
, struct tsl2563_chip
, poweroff_work
.work
);
205 tsl2563_set_power(chip
, 0);
208 static int tsl2563_detect(struct tsl2563_chip
*chip
)
212 ret
= tsl2563_set_power(chip
, 1);
216 ret
= tsl2563_get_power(chip
);
220 return ret
? 0 : -ENODEV
;
223 static int tsl2563_read_id(struct tsl2563_chip
*chip
, u8
*id
)
225 struct i2c_client
*client
= chip
->client
;
228 ret
= i2c_smbus_read_byte_data(client
, TSL2563_CMD
| TSL2563_REG_ID
);
238 * "Normalized" ADC value is one obtained with 400ms of integration time and
239 * 16x gain. This function returns the number of bits of shift needed to
240 * convert between normalized values and HW values obtained using given
241 * timing and gain settings.
243 static int adc_shiftbits(u8 timing
)
247 switch (timing
& TSL2563_TIMING_MASK
) {
248 case TSL2563_TIMING_13MS
:
251 case TSL2563_TIMING_100MS
:
254 case TSL2563_TIMING_400MS
:
259 if (!(timing
& TSL2563_TIMING_GAIN16
))
265 /* Convert a HW ADC value to normalized scale. */
266 static u32
normalize_adc(u16 adc
, u8 timing
)
268 return adc
<< adc_shiftbits(timing
);
271 static void tsl2563_wait_adc(struct tsl2563_chip
*chip
)
275 switch (chip
->gainlevel
->gaintime
& TSL2563_TIMING_MASK
) {
276 case TSL2563_TIMING_13MS
:
279 case TSL2563_TIMING_100MS
:
286 * TODO: Make sure that we wait at least required delay but why we
287 * have to extend it one tick more?
289 schedule_timeout_interruptible(msecs_to_jiffies(delay
) + 2);
292 static int tsl2563_adjust_gainlevel(struct tsl2563_chip
*chip
, u16 adc
)
294 struct i2c_client
*client
= chip
->client
;
296 if (adc
> chip
->gainlevel
->max
|| adc
< chip
->gainlevel
->min
) {
298 (adc
> chip
->gainlevel
->max
) ?
299 chip
->gainlevel
++ : chip
->gainlevel
--;
301 i2c_smbus_write_byte_data(client
,
302 TSL2563_CMD
| TSL2563_REG_TIMING
,
303 chip
->gainlevel
->gaintime
);
305 tsl2563_wait_adc(chip
);
306 tsl2563_wait_adc(chip
);
313 static int tsl2563_get_adc(struct tsl2563_chip
*chip
)
315 struct i2c_client
*client
= chip
->client
;
323 if (!chip
->int_enabled
) {
324 cancel_delayed_work(&chip
->poweroff_work
);
326 if (!tsl2563_get_power(chip
)) {
327 ret
= tsl2563_set_power(chip
, 1);
330 ret
= tsl2563_configure(chip
);
333 tsl2563_wait_adc(chip
);
338 ret
= i2c_smbus_read_word_data(client
,
339 TSL2563_CMD
| TSL2563_REG_DATA0LOW
);
344 ret
= i2c_smbus_read_word_data(client
,
345 TSL2563_CMD
| TSL2563_REG_DATA1LOW
);
350 retry
= tsl2563_adjust_gainlevel(chip
, adc0
);
353 chip
->data0
= normalize_adc(adc0
, chip
->gainlevel
->gaintime
);
354 chip
->data1
= normalize_adc(adc1
, chip
->gainlevel
->gaintime
);
356 if (!chip
->int_enabled
)
357 schedule_delayed_work(&chip
->poweroff_work
, 5 * HZ
);
364 static inline int calib_to_sysfs(u32 calib
)
366 return (int) (((calib
* CALIB_BASE_SYSFS
) +
367 CALIB_FRAC_HALF
) >> CALIB_FRAC_BITS
);
370 static inline u32
calib_from_sysfs(int value
)
372 return (((u32
) value
) << CALIB_FRAC_BITS
) / CALIB_BASE_SYSFS
;
376 * Conversions between lux and ADC values.
378 * The basic formula is lux = c0 * adc0 - c1 * adc1, where c0 and c1 are
379 * appropriate constants. Different constants are needed for different
380 * kinds of light, determined by the ratio adc1/adc0 (basically the ratio
381 * of the intensities in infrared and visible wavelengths). lux_table below
382 * lists the upper threshold of the adc1/adc0 ratio and the corresponding
386 struct tsl2563_lux_coeff
{
387 unsigned long ch_ratio
;
388 unsigned long ch0_coeff
;
389 unsigned long ch1_coeff
;
392 static const struct tsl2563_lux_coeff lux_table
[] = {
394 .ch_ratio
= FRAC10K(1300),
395 .ch0_coeff
= FRAC10K(315),
396 .ch1_coeff
= FRAC10K(262),
398 .ch_ratio
= FRAC10K(2600),
399 .ch0_coeff
= FRAC10K(337),
400 .ch1_coeff
= FRAC10K(430),
402 .ch_ratio
= FRAC10K(3900),
403 .ch0_coeff
= FRAC10K(363),
404 .ch1_coeff
= FRAC10K(529),
406 .ch_ratio
= FRAC10K(5200),
407 .ch0_coeff
= FRAC10K(392),
408 .ch1_coeff
= FRAC10K(605),
410 .ch_ratio
= FRAC10K(6500),
411 .ch0_coeff
= FRAC10K(229),
412 .ch1_coeff
= FRAC10K(291),
414 .ch_ratio
= FRAC10K(8000),
415 .ch0_coeff
= FRAC10K(157),
416 .ch1_coeff
= FRAC10K(180),
418 .ch_ratio
= FRAC10K(13000),
419 .ch0_coeff
= FRAC10K(34),
420 .ch1_coeff
= FRAC10K(26),
422 .ch_ratio
= ULONG_MAX
,
428 /* Convert normalized, scaled ADC values to lux. */
429 static unsigned int adc_to_lux(u32 adc0
, u32 adc1
)
431 const struct tsl2563_lux_coeff
*lp
= lux_table
;
432 unsigned long ratio
, lux
, ch0
= adc0
, ch1
= adc1
;
434 ratio
= ch0
? ((ch1
<< ADC_FRAC_BITS
) / ch0
) : ULONG_MAX
;
436 while (lp
->ch_ratio
< ratio
)
439 lux
= ch0
* lp
->ch0_coeff
- ch1
* lp
->ch1_coeff
;
441 return (unsigned int) (lux
>> ADC_FRAC_BITS
);
444 /* Apply calibration coefficient to ADC count. */
445 static u32
calib_adc(u32 adc
, u32 calib
)
447 unsigned long scaled
= adc
;
450 scaled
>>= CALIB_FRAC_BITS
;
455 static int tsl2563_write_raw(struct iio_dev
*indio_dev
,
456 struct iio_chan_spec
const *chan
,
461 struct tsl2563_chip
*chip
= iio_priv(indio_dev
);
463 if (chan
->channel
== IIO_MOD_LIGHT_BOTH
)
464 chip
->calib0
= calib_from_sysfs(val
);
466 chip
->calib1
= calib_from_sysfs(val
);
471 static int tsl2563_read_raw(struct iio_dev
*indio_dev
,
472 struct iio_chan_spec
const *chan
,
479 struct tsl2563_chip
*chip
= iio_priv(indio_dev
);
481 mutex_lock(&chip
->lock
);
483 case IIO_CHAN_INFO_RAW
:
484 case IIO_CHAN_INFO_PROCESSED
:
485 switch (chan
->type
) {
487 ret
= tsl2563_get_adc(chip
);
490 calib0
= calib_adc(chip
->data0
, chip
->calib0
) *
491 chip
->cover_comp_gain
;
492 calib1
= calib_adc(chip
->data1
, chip
->calib1
) *
493 chip
->cover_comp_gain
;
494 *val
= adc_to_lux(calib0
, calib1
);
498 ret
= tsl2563_get_adc(chip
);
501 if (chan
->channel
== 0)
512 case IIO_CHAN_INFO_CALIBSCALE
:
513 if (chan
->channel
== 0)
514 *val
= calib_to_sysfs(chip
->calib0
);
516 *val
= calib_to_sysfs(chip
->calib1
);
525 mutex_unlock(&chip
->lock
);
529 static const struct iio_event_spec tsl2563_events
[] = {
531 .type
= IIO_EV_TYPE_THRESH
,
532 .dir
= IIO_EV_DIR_RISING
,
533 .mask_separate
= BIT(IIO_EV_INFO_VALUE
) |
534 BIT(IIO_EV_INFO_ENABLE
),
536 .type
= IIO_EV_TYPE_THRESH
,
537 .dir
= IIO_EV_DIR_FALLING
,
538 .mask_separate
= BIT(IIO_EV_INFO_VALUE
) |
539 BIT(IIO_EV_INFO_ENABLE
),
543 static const struct iio_chan_spec tsl2563_channels
[] = {
547 .info_mask_separate
= BIT(IIO_CHAN_INFO_PROCESSED
),
550 .type
= IIO_INTENSITY
,
552 .channel2
= IIO_MOD_LIGHT_BOTH
,
553 .info_mask_separate
= BIT(IIO_CHAN_INFO_RAW
) |
554 BIT(IIO_CHAN_INFO_CALIBSCALE
),
555 .event_spec
= tsl2563_events
,
556 .num_event_specs
= ARRAY_SIZE(tsl2563_events
),
558 .type
= IIO_INTENSITY
,
560 .channel2
= IIO_MOD_LIGHT_IR
,
561 .info_mask_separate
= BIT(IIO_CHAN_INFO_RAW
) |
562 BIT(IIO_CHAN_INFO_CALIBSCALE
),
566 static int tsl2563_read_thresh(struct iio_dev
*indio_dev
,
567 const struct iio_chan_spec
*chan
, enum iio_event_type type
,
568 enum iio_event_direction dir
, enum iio_event_info info
, int *val
,
571 struct tsl2563_chip
*chip
= iio_priv(indio_dev
);
574 case IIO_EV_DIR_RISING
:
575 *val
= chip
->high_thres
;
577 case IIO_EV_DIR_FALLING
:
578 *val
= chip
->low_thres
;
587 static int tsl2563_write_thresh(struct iio_dev
*indio_dev
,
588 const struct iio_chan_spec
*chan
, enum iio_event_type type
,
589 enum iio_event_direction dir
, enum iio_event_info info
, int val
,
592 struct tsl2563_chip
*chip
= iio_priv(indio_dev
);
596 if (dir
== IIO_EV_DIR_RISING
)
597 address
= TSL2563_REG_HIGHLOW
;
599 address
= TSL2563_REG_LOWLOW
;
600 mutex_lock(&chip
->lock
);
601 ret
= i2c_smbus_write_byte_data(chip
->client
, TSL2563_CMD
| address
,
605 ret
= i2c_smbus_write_byte_data(chip
->client
,
606 TSL2563_CMD
| (address
+ 1),
608 if (dir
== IIO_EV_DIR_RISING
)
609 chip
->high_thres
= val
;
611 chip
->low_thres
= val
;
614 mutex_unlock(&chip
->lock
);
619 static irqreturn_t
tsl2563_event_handler(int irq
, void *private)
621 struct iio_dev
*dev_info
= private;
622 struct tsl2563_chip
*chip
= iio_priv(dev_info
);
624 iio_push_event(dev_info
,
625 IIO_UNMOD_EVENT_CODE(IIO_LIGHT
,
631 /* clear the interrupt and push the event */
632 i2c_smbus_write_byte(chip
->client
, TSL2563_CMD
| TSL2563_CLEARINT
);
636 static int tsl2563_write_interrupt_config(struct iio_dev
*indio_dev
,
637 const struct iio_chan_spec
*chan
, enum iio_event_type type
,
638 enum iio_event_direction dir
, int state
)
640 struct tsl2563_chip
*chip
= iio_priv(indio_dev
);
643 mutex_lock(&chip
->lock
);
644 if (state
&& !(chip
->intr
& 0x30)) {
647 /* ensure the chip is actually on */
648 cancel_delayed_work(&chip
->poweroff_work
);
649 if (!tsl2563_get_power(chip
)) {
650 ret
= tsl2563_set_power(chip
, 1);
653 ret
= tsl2563_configure(chip
);
657 ret
= i2c_smbus_write_byte_data(chip
->client
,
658 TSL2563_CMD
| TSL2563_REG_INT
,
660 chip
->int_enabled
= true;
663 if (!state
&& (chip
->intr
& 0x30)) {
665 ret
= i2c_smbus_write_byte_data(chip
->client
,
666 TSL2563_CMD
| TSL2563_REG_INT
,
668 chip
->int_enabled
= false;
669 /* now the interrupt is not enabled, we can go to sleep */
670 schedule_delayed_work(&chip
->poweroff_work
, 5 * HZ
);
673 mutex_unlock(&chip
->lock
);
678 static int tsl2563_read_interrupt_config(struct iio_dev
*indio_dev
,
679 const struct iio_chan_spec
*chan
, enum iio_event_type type
,
680 enum iio_event_direction dir
)
682 struct tsl2563_chip
*chip
= iio_priv(indio_dev
);
685 mutex_lock(&chip
->lock
);
686 ret
= i2c_smbus_read_byte_data(chip
->client
,
687 TSL2563_CMD
| TSL2563_REG_INT
);
688 mutex_unlock(&chip
->lock
);
692 return !!(ret
& 0x30);
695 static const struct iio_info tsl2563_info_no_irq
= {
696 .driver_module
= THIS_MODULE
,
697 .read_raw
= &tsl2563_read_raw
,
698 .write_raw
= &tsl2563_write_raw
,
701 static const struct iio_info tsl2563_info
= {
702 .driver_module
= THIS_MODULE
,
703 .read_raw
= &tsl2563_read_raw
,
704 .write_raw
= &tsl2563_write_raw
,
705 .read_event_value
= &tsl2563_read_thresh
,
706 .write_event_value
= &tsl2563_write_thresh
,
707 .read_event_config
= &tsl2563_read_interrupt_config
,
708 .write_event_config
= &tsl2563_write_interrupt_config
,
711 static int tsl2563_probe(struct i2c_client
*client
,
712 const struct i2c_device_id
*device_id
)
714 struct iio_dev
*indio_dev
;
715 struct tsl2563_chip
*chip
;
716 struct tsl2563_platform_data
*pdata
= client
->dev
.platform_data
;
717 struct device_node
*np
= client
->dev
.of_node
;
721 indio_dev
= devm_iio_device_alloc(&client
->dev
, sizeof(*chip
));
725 chip
= iio_priv(indio_dev
);
727 i2c_set_clientdata(client
, chip
);
728 chip
->client
= client
;
730 err
= tsl2563_detect(chip
);
732 dev_err(&client
->dev
, "detect error %d\n", -err
);
736 err
= tsl2563_read_id(chip
, &id
);
738 dev_err(&client
->dev
, "read id error %d\n", -err
);
742 mutex_init(&chip
->lock
);
744 /* Default values used until userspace says otherwise */
745 chip
->low_thres
= 0x0;
746 chip
->high_thres
= 0xffff;
747 chip
->gainlevel
= tsl2563_gainlevel_table
;
748 chip
->intr
= TSL2563_INT_PERSIST(4);
749 chip
->calib0
= calib_from_sysfs(CALIB_BASE_SYSFS
);
750 chip
->calib1
= calib_from_sysfs(CALIB_BASE_SYSFS
);
753 chip
->cover_comp_gain
= pdata
->cover_comp_gain
;
755 of_property_read_u32(np
, "amstaos,cover-comp-gain",
756 &chip
->cover_comp_gain
);
758 chip
->cover_comp_gain
= 1;
760 dev_info(&client
->dev
, "model %d, rev. %d\n", id
>> 4, id
& 0x0f);
761 indio_dev
->name
= client
->name
;
762 indio_dev
->channels
= tsl2563_channels
;
763 indio_dev
->num_channels
= ARRAY_SIZE(tsl2563_channels
);
764 indio_dev
->dev
.parent
= &client
->dev
;
765 indio_dev
->modes
= INDIO_DIRECT_MODE
;
768 indio_dev
->info
= &tsl2563_info
;
770 indio_dev
->info
= &tsl2563_info_no_irq
;
773 err
= devm_request_threaded_irq(&client
->dev
, client
->irq
,
775 &tsl2563_event_handler
,
776 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
780 dev_err(&client
->dev
, "irq request error %d\n", -err
);
785 err
= tsl2563_configure(chip
);
787 dev_err(&client
->dev
, "configure error %d\n", -err
);
791 INIT_DELAYED_WORK(&chip
->poweroff_work
, tsl2563_poweroff_work
);
793 /* The interrupt cannot yet be enabled so this is fine without lock */
794 schedule_delayed_work(&chip
->poweroff_work
, 5 * HZ
);
796 err
= iio_device_register(indio_dev
);
798 dev_err(&client
->dev
, "iio registration error %d\n", -err
);
805 cancel_delayed_work(&chip
->poweroff_work
);
806 flush_scheduled_work();
810 static int tsl2563_remove(struct i2c_client
*client
)
812 struct tsl2563_chip
*chip
= i2c_get_clientdata(client
);
813 struct iio_dev
*indio_dev
= iio_priv_to_dev(chip
);
815 iio_device_unregister(indio_dev
);
816 if (!chip
->int_enabled
)
817 cancel_delayed_work(&chip
->poweroff_work
);
818 /* Ensure that interrupts are disabled - then flush any bottom halves */
820 i2c_smbus_write_byte_data(chip
->client
, TSL2563_CMD
| TSL2563_REG_INT
,
822 flush_scheduled_work();
823 tsl2563_set_power(chip
, 0);
828 #ifdef CONFIG_PM_SLEEP
829 static int tsl2563_suspend(struct device
*dev
)
831 struct tsl2563_chip
*chip
= i2c_get_clientdata(to_i2c_client(dev
));
834 mutex_lock(&chip
->lock
);
836 ret
= tsl2563_set_power(chip
, 0);
840 chip
->suspended
= true;
843 mutex_unlock(&chip
->lock
);
847 static int tsl2563_resume(struct device
*dev
)
849 struct tsl2563_chip
*chip
= i2c_get_clientdata(to_i2c_client(dev
));
852 mutex_lock(&chip
->lock
);
854 ret
= tsl2563_set_power(chip
, 1);
858 ret
= tsl2563_configure(chip
);
862 chip
->suspended
= false;
865 mutex_unlock(&chip
->lock
);
869 static SIMPLE_DEV_PM_OPS(tsl2563_pm_ops
, tsl2563_suspend
, tsl2563_resume
);
870 #define TSL2563_PM_OPS (&tsl2563_pm_ops)
872 #define TSL2563_PM_OPS NULL
875 static const struct i2c_device_id tsl2563_id
[] = {
882 MODULE_DEVICE_TABLE(i2c
, tsl2563_id
);
884 static struct i2c_driver tsl2563_i2c_driver
= {
887 .pm
= TSL2563_PM_OPS
,
889 .probe
= tsl2563_probe
,
890 .remove
= tsl2563_remove
,
891 .id_table
= tsl2563_id
,
893 module_i2c_driver(tsl2563_i2c_driver
);
895 MODULE_AUTHOR("Nokia Corporation");
896 MODULE_DESCRIPTION("tsl2563 light sensor driver");
897 MODULE_LICENSE("GPL");