2 * A iio driver for the light sensor ISL 29018/29023/29035.
4 * IIO driver for monitoring ambient light intensity in luxi, proximity
5 * sensing and infrared sensing.
7 * Copyright (c) 2010, NVIDIA Corporation.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 #include <linux/module.h>
21 #include <linux/i2c.h>
22 #include <linux/err.h>
23 #include <linux/mutex.h>
24 #include <linux/delay.h>
25 #include <linux/regmap.h>
26 #include <linux/regulator/consumer.h>
27 #include <linux/slab.h>
28 #include <linux/iio/iio.h>
29 #include <linux/iio/sysfs.h>
30 #include <linux/acpi.h>
32 #define ISL29018_CONV_TIME_MS 100
34 #define ISL29018_REG_ADD_COMMAND1 0x00
35 #define ISL29018_CMD1_OPMODE_SHIFT 5
36 #define ISL29018_CMD1_OPMODE_MASK (7 << ISL29018_CMD1_OPMODE_SHIFT)
37 #define ISL29018_CMD1_OPMODE_POWER_DOWN 0
38 #define ISL29018_CMD1_OPMODE_ALS_ONCE 1
39 #define ISL29018_CMD1_OPMODE_IR_ONCE 2
40 #define ISL29018_CMD1_OPMODE_PROX_ONCE 3
42 #define ISL29018_REG_ADD_COMMAND2 0x01
43 #define ISL29018_CMD2_RESOLUTION_SHIFT 2
44 #define ISL29018_CMD2_RESOLUTION_MASK (0x3 << ISL29018_CMD2_RESOLUTION_SHIFT)
46 #define ISL29018_CMD2_RANGE_SHIFT 0
47 #define ISL29018_CMD2_RANGE_MASK (0x3 << ISL29018_CMD2_RANGE_SHIFT)
49 #define ISL29018_CMD2_SCHEME_SHIFT 7
50 #define ISL29018_CMD2_SCHEME_MASK (0x1 << ISL29018_CMD2_SCHEME_SHIFT)
52 #define ISL29018_REG_ADD_DATA_LSB 0x02
53 #define ISL29018_REG_ADD_DATA_MSB 0x03
55 #define ISL29018_REG_TEST 0x08
56 #define ISL29018_TEST_SHIFT 0
57 #define ISL29018_TEST_MASK (0xFF << ISL29018_TEST_SHIFT)
59 #define ISL29035_REG_DEVICE_ID 0x0F
60 #define ISL29035_DEVICE_ID_SHIFT 0x03
61 #define ISL29035_DEVICE_ID_MASK (0x7 << ISL29035_DEVICE_ID_SHIFT)
62 #define ISL29035_DEVICE_ID 0x5
63 #define ISL29035_BOUT_SHIFT 0x07
64 #define ISL29035_BOUT_MASK (0x01 << ISL29035_BOUT_SHIFT)
66 enum isl29018_int_time
{
73 static const unsigned int isl29018_int_utimes
[3][4] = {
74 {90000, 5630, 351, 21},
75 {90000, 5600, 352, 22},
76 {105000, 6500, 410, 25},
79 static const struct isl29018_scale
{
82 } isl29018_scales
[4][4] = {
83 { {0, 15258}, {0, 61035}, {0, 244140}, {0, 976562} },
84 { {0, 244140}, {0, 976562}, {3, 906250}, {15, 625000} },
85 { {3, 906250}, {15, 625000}, {62, 500000}, {250, 0} },
86 { {62, 500000}, {250, 0}, {1000, 0}, {4000, 0} }
89 struct isl29018_chip
{
90 struct regmap
*regmap
;
93 unsigned int calibscale
;
94 unsigned int ucalibscale
;
95 unsigned int int_time
;
96 struct isl29018_scale scale
;
99 struct regulator
*vcc_reg
;
102 static int isl29018_set_integration_time(struct isl29018_chip
*chip
,
107 unsigned int int_time
, new_int_time
;
109 for (i
= 0; i
< ARRAY_SIZE(isl29018_int_utimes
[chip
->type
]); ++i
) {
110 if (utime
== isl29018_int_utimes
[chip
->type
][i
]) {
116 if (i
>= ARRAY_SIZE(isl29018_int_utimes
[chip
->type
]))
119 ret
= regmap_update_bits(chip
->regmap
, ISL29018_REG_ADD_COMMAND2
,
120 ISL29018_CMD2_RESOLUTION_MASK
,
121 i
<< ISL29018_CMD2_RESOLUTION_SHIFT
);
125 /* Keep the same range when integration time changes */
126 int_time
= chip
->int_time
;
127 for (i
= 0; i
< ARRAY_SIZE(isl29018_scales
[int_time
]); ++i
) {
128 if (chip
->scale
.scale
== isl29018_scales
[int_time
][i
].scale
&&
129 chip
->scale
.uscale
== isl29018_scales
[int_time
][i
].uscale
) {
130 chip
->scale
= isl29018_scales
[new_int_time
][i
];
134 chip
->int_time
= new_int_time
;
139 static int isl29018_set_scale(struct isl29018_chip
*chip
, int scale
, int uscale
)
143 struct isl29018_scale new_scale
;
145 for (i
= 0; i
< ARRAY_SIZE(isl29018_scales
[chip
->int_time
]); ++i
) {
146 if (scale
== isl29018_scales
[chip
->int_time
][i
].scale
&&
147 uscale
== isl29018_scales
[chip
->int_time
][i
].uscale
) {
148 new_scale
= isl29018_scales
[chip
->int_time
][i
];
153 if (i
>= ARRAY_SIZE(isl29018_scales
[chip
->int_time
]))
156 ret
= regmap_update_bits(chip
->regmap
, ISL29018_REG_ADD_COMMAND2
,
157 ISL29018_CMD2_RANGE_MASK
,
158 i
<< ISL29018_CMD2_RANGE_SHIFT
);
162 chip
->scale
= new_scale
;
167 static int isl29018_read_sensor_input(struct isl29018_chip
*chip
, int mode
)
172 struct device
*dev
= regmap_get_device(chip
->regmap
);
175 status
= regmap_write(chip
->regmap
, ISL29018_REG_ADD_COMMAND1
,
176 mode
<< ISL29018_CMD1_OPMODE_SHIFT
);
179 "Error in setting operating mode err %d\n", status
);
182 msleep(ISL29018_CONV_TIME_MS
);
183 status
= regmap_read(chip
->regmap
, ISL29018_REG_ADD_DATA_LSB
, &lsb
);
186 "Error in reading LSB DATA with err %d\n", status
);
190 status
= regmap_read(chip
->regmap
, ISL29018_REG_ADD_DATA_MSB
, &msb
);
193 "Error in reading MSB DATA with error %d\n", status
);
196 dev_vdbg(dev
, "MSB 0x%x and LSB 0x%x\n", msb
, lsb
);
198 return (msb
<< 8) | lsb
;
201 static int isl29018_read_lux(struct isl29018_chip
*chip
, int *lux
)
204 unsigned int data_x_range
;
206 lux_data
= isl29018_read_sensor_input(chip
,
207 ISL29018_CMD1_OPMODE_ALS_ONCE
);
211 data_x_range
= lux_data
* chip
->scale
.scale
+
212 lux_data
* chip
->scale
.uscale
/ 1000000;
213 *lux
= data_x_range
* chip
->calibscale
+
214 data_x_range
* chip
->ucalibscale
/ 1000000;
219 static int isl29018_read_ir(struct isl29018_chip
*chip
, int *ir
)
223 ir_data
= isl29018_read_sensor_input(chip
,
224 ISL29018_CMD1_OPMODE_IR_ONCE
);
233 static int isl29018_read_proximity_ir(struct isl29018_chip
*chip
, int scheme
,
239 struct device
*dev
= regmap_get_device(chip
->regmap
);
241 /* Do proximity sensing with required scheme */
242 status
= regmap_update_bits(chip
->regmap
, ISL29018_REG_ADD_COMMAND2
,
243 ISL29018_CMD2_SCHEME_MASK
,
244 scheme
<< ISL29018_CMD2_SCHEME_SHIFT
);
246 dev_err(dev
, "Error in setting operating mode\n");
250 prox_data
= isl29018_read_sensor_input(chip
,
251 ISL29018_CMD1_OPMODE_PROX_ONCE
);
256 *near_ir
= prox_data
;
260 ir_data
= isl29018_read_sensor_input(chip
,
261 ISL29018_CMD1_OPMODE_IR_ONCE
);
265 if (prox_data
>= ir_data
)
266 *near_ir
= prox_data
- ir_data
;
273 static ssize_t in_illuminance_scale_available_show
274 (struct device
*dev
, struct device_attribute
*attr
,
277 struct iio_dev
*indio_dev
= dev_to_iio_dev(dev
);
278 struct isl29018_chip
*chip
= iio_priv(indio_dev
);
282 mutex_lock(&chip
->lock
);
283 for (i
= 0; i
< ARRAY_SIZE(isl29018_scales
[chip
->int_time
]); ++i
)
284 len
+= sprintf(buf
+ len
, "%d.%06d ",
285 isl29018_scales
[chip
->int_time
][i
].scale
,
286 isl29018_scales
[chip
->int_time
][i
].uscale
);
287 mutex_unlock(&chip
->lock
);
294 static ssize_t in_illuminance_integration_time_available_show
295 (struct device
*dev
, struct device_attribute
*attr
,
298 struct iio_dev
*indio_dev
= dev_to_iio_dev(dev
);
299 struct isl29018_chip
*chip
= iio_priv(indio_dev
);
303 for (i
= 0; i
< ARRAY_SIZE(isl29018_int_utimes
[chip
->type
]); ++i
)
304 len
+= sprintf(buf
+ len
, "0.%06d ",
305 isl29018_int_utimes
[chip
->type
][i
]);
313 * From ISL29018 Data Sheet (FN6619.4, Oct 8, 2012) regarding the
314 * infrared suppression:
316 * Proximity Sensing Scheme: Bit 7. This bit programs the function
317 * of the proximity detection. Logic 0 of this bit, Scheme 0, makes
318 * full n (4, 8, 12, 16) bits (unsigned) proximity detection. The range
319 * of Scheme 0 proximity count is from 0 to 2^n. Logic 1 of this bit,
320 * Scheme 1, makes n-1 (3, 7, 11, 15) bits (2's complementary)
321 * proximity_less_ambient detection. The range of Scheme 1
322 * proximity count is from -2^(n-1) to 2^(n-1) . The sign bit is extended
323 * for resolutions less than 16. While Scheme 0 has wider dynamic
324 * range, Scheme 1 proximity detection is less affected by the
325 * ambient IR noise variation.
327 * 0 Sensing IR from LED and ambient
328 * 1 Sensing IR from LED with ambient IR rejection
330 static ssize_t proximity_on_chip_ambient_infrared_suppression_show
331 (struct device
*dev
, struct device_attribute
*attr
,
334 struct iio_dev
*indio_dev
= dev_to_iio_dev(dev
);
335 struct isl29018_chip
*chip
= iio_priv(indio_dev
);
338 * Return the "proximity scheme" i.e. if the chip does on chip
339 * infrared suppression (1 means perform on chip suppression)
341 return sprintf(buf
, "%d\n", chip
->prox_scheme
);
344 static ssize_t proximity_on_chip_ambient_infrared_suppression_store
345 (struct device
*dev
, struct device_attribute
*attr
,
346 const char *buf
, size_t count
)
348 struct iio_dev
*indio_dev
= dev_to_iio_dev(dev
);
349 struct isl29018_chip
*chip
= iio_priv(indio_dev
);
352 if (kstrtoint(buf
, 10, &val
))
354 if (!(val
== 0 || val
== 1))
358 * Get the "proximity scheme" i.e. if the chip does on chip
359 * infrared suppression (1 means perform on chip suppression)
361 mutex_lock(&chip
->lock
);
362 chip
->prox_scheme
= val
;
363 mutex_unlock(&chip
->lock
);
368 static int isl29018_write_raw(struct iio_dev
*indio_dev
,
369 struct iio_chan_spec
const *chan
,
374 struct isl29018_chip
*chip
= iio_priv(indio_dev
);
377 mutex_lock(&chip
->lock
);
378 if (chip
->suspended
) {
383 case IIO_CHAN_INFO_CALIBSCALE
:
384 if (chan
->type
== IIO_LIGHT
) {
385 chip
->calibscale
= val
;
386 chip
->ucalibscale
= val2
;
390 case IIO_CHAN_INFO_INT_TIME
:
391 if (chan
->type
== IIO_LIGHT
&& !val
)
392 ret
= isl29018_set_integration_time(chip
, val2
);
394 case IIO_CHAN_INFO_SCALE
:
395 if (chan
->type
== IIO_LIGHT
)
396 ret
= isl29018_set_scale(chip
, val
, val2
);
403 mutex_unlock(&chip
->lock
);
408 static int isl29018_read_raw(struct iio_dev
*indio_dev
,
409 struct iio_chan_spec
const *chan
,
415 struct isl29018_chip
*chip
= iio_priv(indio_dev
);
417 mutex_lock(&chip
->lock
);
418 if (chip
->suspended
) {
423 case IIO_CHAN_INFO_RAW
:
424 case IIO_CHAN_INFO_PROCESSED
:
425 switch (chan
->type
) {
427 ret
= isl29018_read_lux(chip
, val
);
430 ret
= isl29018_read_ir(chip
, val
);
433 ret
= isl29018_read_proximity_ir(chip
,
443 case IIO_CHAN_INFO_INT_TIME
:
444 if (chan
->type
== IIO_LIGHT
) {
446 *val2
= isl29018_int_utimes
[chip
->type
][chip
->int_time
];
447 ret
= IIO_VAL_INT_PLUS_MICRO
;
450 case IIO_CHAN_INFO_SCALE
:
451 if (chan
->type
== IIO_LIGHT
) {
452 *val
= chip
->scale
.scale
;
453 *val2
= chip
->scale
.uscale
;
454 ret
= IIO_VAL_INT_PLUS_MICRO
;
457 case IIO_CHAN_INFO_CALIBSCALE
:
458 if (chan
->type
== IIO_LIGHT
) {
459 *val
= chip
->calibscale
;
460 *val2
= chip
->ucalibscale
;
461 ret
= IIO_VAL_INT_PLUS_MICRO
;
469 mutex_unlock(&chip
->lock
);
474 #define ISL29018_LIGHT_CHANNEL { \
478 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | \
479 BIT(IIO_CHAN_INFO_CALIBSCALE) | \
480 BIT(IIO_CHAN_INFO_SCALE) | \
481 BIT(IIO_CHAN_INFO_INT_TIME), \
484 #define ISL29018_IR_CHANNEL { \
485 .type = IIO_INTENSITY, \
487 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
488 .channel2 = IIO_MOD_LIGHT_IR, \
491 #define ISL29018_PROXIMITY_CHANNEL { \
492 .type = IIO_PROXIMITY, \
493 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
496 static const struct iio_chan_spec isl29018_channels
[] = {
497 ISL29018_LIGHT_CHANNEL
,
499 ISL29018_PROXIMITY_CHANNEL
,
502 static const struct iio_chan_spec isl29023_channels
[] = {
503 ISL29018_LIGHT_CHANNEL
,
507 static IIO_DEVICE_ATTR_RO(in_illuminance_integration_time_available
, 0);
508 static IIO_DEVICE_ATTR_RO(in_illuminance_scale_available
, 0);
509 static IIO_DEVICE_ATTR_RW(proximity_on_chip_ambient_infrared_suppression
, 0);
511 #define ISL29018_DEV_ATTR(name) (&iio_dev_attr_##name.dev_attr.attr)
513 static struct attribute
*isl29018_attributes
[] = {
514 ISL29018_DEV_ATTR(in_illuminance_scale_available
),
515 ISL29018_DEV_ATTR(in_illuminance_integration_time_available
),
516 ISL29018_DEV_ATTR(proximity_on_chip_ambient_infrared_suppression
),
520 static struct attribute
*isl29023_attributes
[] = {
521 ISL29018_DEV_ATTR(in_illuminance_scale_available
),
522 ISL29018_DEV_ATTR(in_illuminance_integration_time_available
),
526 static const struct attribute_group isl29018_group
= {
527 .attrs
= isl29018_attributes
,
530 static const struct attribute_group isl29023_group
= {
531 .attrs
= isl29023_attributes
,
540 static int isl29018_chip_init(struct isl29018_chip
*chip
)
543 struct device
*dev
= regmap_get_device(chip
->regmap
);
545 if (chip
->type
== isl29035
) {
548 status
= regmap_read(chip
->regmap
, ISL29035_REG_DEVICE_ID
, &id
);
551 "Error reading ID register with error %d\n",
556 id
= (id
& ISL29035_DEVICE_ID_MASK
) >> ISL29035_DEVICE_ID_SHIFT
;
558 if (id
!= ISL29035_DEVICE_ID
)
561 /* Clear brownout bit */
562 status
= regmap_update_bits(chip
->regmap
,
563 ISL29035_REG_DEVICE_ID
,
564 ISL29035_BOUT_MASK
, 0);
570 * Code added per Intersil Application Note 1534:
571 * When VDD sinks to approximately 1.8V or below, some of
572 * the part's registers may change their state. When VDD
573 * recovers to 2.25V (or greater), the part may thus be in an
574 * unknown mode of operation. The user can return the part to
575 * a known mode of operation either by (a) setting VDD = 0V for
576 * 1 second or more and then powering back up with a slew rate
577 * of 0.5V/ms or greater, or (b) via I2C disable all ALS/PROX
578 * conversions, clear the test registers, and then rewrite all
579 * registers to the desired values.
581 * For ISL29011, ISL29018, ISL29021, ISL29023
582 * 1. Write 0x00 to register 0x08 (TEST)
583 * 2. Write 0x00 to register 0x00 (CMD1)
584 * 3. Rewrite all registers to the desired values
586 * ISL29018 Data Sheet (FN6619.1, Feb 11, 2010) essentially says
587 * the same thing EXCEPT the data sheet asks for a 1ms delay after
588 * writing the CMD1 register.
590 status
= regmap_write(chip
->regmap
, ISL29018_REG_TEST
, 0x0);
592 dev_err(dev
, "Failed to clear isl29018 TEST reg.(%d)\n",
598 * See Intersil AN1534 comments above.
599 * "Operating Mode" (COMMAND1) register is reprogrammed when
600 * data is read from the device.
602 status
= regmap_write(chip
->regmap
, ISL29018_REG_ADD_COMMAND1
, 0);
604 dev_err(dev
, "Failed to clear isl29018 CMD1 reg.(%d)\n",
609 usleep_range(1000, 2000); /* per data sheet, page 10 */
612 status
= isl29018_set_scale(chip
, chip
->scale
.scale
,
615 dev_err(dev
, "Init of isl29018 fails\n");
619 status
= isl29018_set_integration_time(chip
,
620 isl29018_int_utimes
[chip
->type
][chip
->int_time
]);
622 dev_err(dev
, "Init of isl29018 fails\n");
627 static const struct iio_info isl29018_info
= {
628 .attrs
= &isl29018_group
,
629 .read_raw
= isl29018_read_raw
,
630 .write_raw
= isl29018_write_raw
,
633 static const struct iio_info isl29023_info
= {
634 .attrs
= &isl29023_group
,
635 .read_raw
= isl29018_read_raw
,
636 .write_raw
= isl29018_write_raw
,
639 static bool isl29018_is_volatile_reg(struct device
*dev
, unsigned int reg
)
642 case ISL29018_REG_ADD_DATA_LSB
:
643 case ISL29018_REG_ADD_DATA_MSB
:
644 case ISL29018_REG_ADD_COMMAND1
:
645 case ISL29018_REG_TEST
:
646 case ISL29035_REG_DEVICE_ID
:
653 static const struct regmap_config isl29018_regmap_config
= {
656 .volatile_reg
= isl29018_is_volatile_reg
,
657 .max_register
= ISL29018_REG_TEST
,
658 .num_reg_defaults_raw
= ISL29018_REG_TEST
+ 1,
659 .cache_type
= REGCACHE_RBTREE
,
662 static const struct regmap_config isl29035_regmap_config
= {
665 .volatile_reg
= isl29018_is_volatile_reg
,
666 .max_register
= ISL29035_REG_DEVICE_ID
,
667 .num_reg_defaults_raw
= ISL29035_REG_DEVICE_ID
+ 1,
668 .cache_type
= REGCACHE_RBTREE
,
671 struct isl29018_chip_info
{
672 const struct iio_chan_spec
*channels
;
674 const struct iio_info
*indio_info
;
675 const struct regmap_config
*regmap_cfg
;
678 static const struct isl29018_chip_info isl29018_chip_info_tbl
[] = {
680 .channels
= isl29018_channels
,
681 .num_channels
= ARRAY_SIZE(isl29018_channels
),
682 .indio_info
= &isl29018_info
,
683 .regmap_cfg
= &isl29018_regmap_config
,
686 .channels
= isl29023_channels
,
687 .num_channels
= ARRAY_SIZE(isl29023_channels
),
688 .indio_info
= &isl29023_info
,
689 .regmap_cfg
= &isl29018_regmap_config
,
692 .channels
= isl29023_channels
,
693 .num_channels
= ARRAY_SIZE(isl29023_channels
),
694 .indio_info
= &isl29023_info
,
695 .regmap_cfg
= &isl29035_regmap_config
,
699 static const char *isl29018_match_acpi_device(struct device
*dev
, int *data
)
701 const struct acpi_device_id
*id
;
703 id
= acpi_match_device(dev
->driver
->acpi_match_table
, dev
);
708 *data
= (int)id
->driver_data
;
710 return dev_name(dev
);
713 static void isl29018_disable_regulator_action(void *_data
)
715 struct isl29018_chip
*chip
= _data
;
718 err
= regulator_disable(chip
->vcc_reg
);
720 pr_err("failed to disable isl29018's VCC regulator!\n");
723 static int isl29018_probe(struct i2c_client
*client
,
724 const struct i2c_device_id
*id
)
726 struct isl29018_chip
*chip
;
727 struct iio_dev
*indio_dev
;
729 const char *name
= NULL
;
732 indio_dev
= devm_iio_device_alloc(&client
->dev
, sizeof(*chip
));
736 chip
= iio_priv(indio_dev
);
738 i2c_set_clientdata(client
, indio_dev
);
742 dev_id
= id
->driver_data
;
745 if (ACPI_HANDLE(&client
->dev
))
746 name
= isl29018_match_acpi_device(&client
->dev
, &dev_id
);
748 mutex_init(&chip
->lock
);
751 chip
->calibscale
= 1;
752 chip
->ucalibscale
= 0;
753 chip
->int_time
= ISL29018_INT_TIME_16
;
754 chip
->scale
= isl29018_scales
[chip
->int_time
][0];
755 chip
->suspended
= false;
757 chip
->vcc_reg
= devm_regulator_get(&client
->dev
, "vcc");
758 if (IS_ERR(chip
->vcc_reg
)) {
759 err
= PTR_ERR(chip
->vcc_reg
);
760 if (err
!= -EPROBE_DEFER
)
761 dev_err(&client
->dev
, "failed to get VCC regulator!\n");
765 err
= regulator_enable(chip
->vcc_reg
);
767 dev_err(&client
->dev
, "failed to enable VCC regulator!\n");
771 err
= devm_add_action_or_reset(&client
->dev
, isl29018_disable_regulator_action
,
774 dev_err(&client
->dev
, "failed to setup regulator cleanup action!\n");
778 chip
->regmap
= devm_regmap_init_i2c(client
,
779 isl29018_chip_info_tbl
[dev_id
].regmap_cfg
);
780 if (IS_ERR(chip
->regmap
)) {
781 err
= PTR_ERR(chip
->regmap
);
782 dev_err(&client
->dev
, "regmap initialization fails: %d\n", err
);
786 err
= isl29018_chip_init(chip
);
790 indio_dev
->info
= isl29018_chip_info_tbl
[dev_id
].indio_info
;
791 indio_dev
->channels
= isl29018_chip_info_tbl
[dev_id
].channels
;
792 indio_dev
->num_channels
= isl29018_chip_info_tbl
[dev_id
].num_channels
;
793 indio_dev
->name
= name
;
794 indio_dev
->dev
.parent
= &client
->dev
;
795 indio_dev
->modes
= INDIO_DIRECT_MODE
;
797 return devm_iio_device_register(&client
->dev
, indio_dev
);
800 #ifdef CONFIG_PM_SLEEP
801 static int isl29018_suspend(struct device
*dev
)
803 struct isl29018_chip
*chip
= iio_priv(dev_get_drvdata(dev
));
806 mutex_lock(&chip
->lock
);
809 * Since this driver uses only polling commands, we are by default in
810 * auto shutdown (ie, power-down) mode.
811 * So we do not have much to do here.
813 chip
->suspended
= true;
814 ret
= regulator_disable(chip
->vcc_reg
);
816 dev_err(dev
, "failed to disable VCC regulator\n");
818 mutex_unlock(&chip
->lock
);
823 static int isl29018_resume(struct device
*dev
)
825 struct isl29018_chip
*chip
= iio_priv(dev_get_drvdata(dev
));
828 mutex_lock(&chip
->lock
);
830 err
= regulator_enable(chip
->vcc_reg
);
832 dev_err(dev
, "failed to enable VCC regulator\n");
833 mutex_unlock(&chip
->lock
);
837 err
= isl29018_chip_init(chip
);
839 chip
->suspended
= false;
841 mutex_unlock(&chip
->lock
);
846 static SIMPLE_DEV_PM_OPS(isl29018_pm_ops
, isl29018_suspend
, isl29018_resume
);
847 #define ISL29018_PM_OPS (&isl29018_pm_ops)
849 #define ISL29018_PM_OPS NULL
853 static const struct acpi_device_id isl29018_acpi_match
[] = {
854 {"ISL29018", isl29018
},
855 {"ISL29023", isl29023
},
856 {"ISL29035", isl29035
},
859 MODULE_DEVICE_TABLE(acpi
, isl29018_acpi_match
);
862 static const struct i2c_device_id isl29018_id
[] = {
863 {"isl29018", isl29018
},
864 {"isl29023", isl29023
},
865 {"isl29035", isl29035
},
868 MODULE_DEVICE_TABLE(i2c
, isl29018_id
);
870 static const struct of_device_id isl29018_of_match
[] = {
871 { .compatible
= "isil,isl29018", },
872 { .compatible
= "isil,isl29023", },
873 { .compatible
= "isil,isl29035", },
876 MODULE_DEVICE_TABLE(of
, isl29018_of_match
);
878 static struct i2c_driver isl29018_driver
= {
881 .acpi_match_table
= ACPI_PTR(isl29018_acpi_match
),
882 .pm
= ISL29018_PM_OPS
,
883 .of_match_table
= isl29018_of_match
,
885 .probe
= isl29018_probe
,
886 .id_table
= isl29018_id
,
888 module_i2c_driver(isl29018_driver
);
890 MODULE_DESCRIPTION("ISL29018 Ambient Light Sensor driver");
891 MODULE_LICENSE("GPL");