1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * A iio driver for the light sensor ISL 29018/29023/29035.
5 * IIO driver for monitoring ambient light intensity in luxi, proximity
6 * sensing and infrared sensing.
8 * Copyright (c) 2010, NVIDIA Corporation.
11 #include <linux/i2c.h>
12 #include <linux/err.h>
13 #include <linux/mod_devicetable.h>
14 #include <linux/module.h>
15 #include <linux/mutex.h>
16 #include <linux/delay.h>
17 #include <linux/regmap.h>
18 #include <linux/regulator/consumer.h>
19 #include <linux/slab.h>
21 #include <linux/iio/iio.h>
22 #include <linux/iio/sysfs.h>
24 #define ISL29018_CONV_TIME_MS 100
26 #define ISL29018_REG_ADD_COMMAND1 0x00
27 #define ISL29018_CMD1_OPMODE_SHIFT 5
28 #define ISL29018_CMD1_OPMODE_MASK (7 << ISL29018_CMD1_OPMODE_SHIFT)
29 #define ISL29018_CMD1_OPMODE_POWER_DOWN 0
30 #define ISL29018_CMD1_OPMODE_ALS_ONCE 1
31 #define ISL29018_CMD1_OPMODE_IR_ONCE 2
32 #define ISL29018_CMD1_OPMODE_PROX_ONCE 3
34 #define ISL29018_REG_ADD_COMMAND2 0x01
35 #define ISL29018_CMD2_RESOLUTION_SHIFT 2
36 #define ISL29018_CMD2_RESOLUTION_MASK (0x3 << ISL29018_CMD2_RESOLUTION_SHIFT)
38 #define ISL29018_CMD2_RANGE_SHIFT 0
39 #define ISL29018_CMD2_RANGE_MASK (0x3 << ISL29018_CMD2_RANGE_SHIFT)
41 #define ISL29018_CMD2_SCHEME_SHIFT 7
42 #define ISL29018_CMD2_SCHEME_MASK (0x1 << ISL29018_CMD2_SCHEME_SHIFT)
44 #define ISL29018_REG_ADD_DATA_LSB 0x02
45 #define ISL29018_REG_ADD_DATA_MSB 0x03
47 #define ISL29018_REG_TEST 0x08
48 #define ISL29018_TEST_SHIFT 0
49 #define ISL29018_TEST_MASK (0xFF << ISL29018_TEST_SHIFT)
51 #define ISL29035_REG_DEVICE_ID 0x0F
52 #define ISL29035_DEVICE_ID_SHIFT 0x03
53 #define ISL29035_DEVICE_ID_MASK (0x7 << ISL29035_DEVICE_ID_SHIFT)
54 #define ISL29035_DEVICE_ID 0x5
55 #define ISL29035_BOUT_SHIFT 0x07
56 #define ISL29035_BOUT_MASK (0x01 << ISL29035_BOUT_SHIFT)
58 enum isl29018_int_time
{
65 static const unsigned int isl29018_int_utimes
[3][4] = {
66 {90000, 5630, 351, 21},
67 {90000, 5600, 352, 22},
68 {105000, 6500, 410, 25},
71 static const struct isl29018_scale
{
74 } isl29018_scales
[4][4] = {
75 { {0, 15258}, {0, 61035}, {0, 244140}, {0, 976562} },
76 { {0, 244140}, {0, 976562}, {3, 906250}, {15, 625000} },
77 { {3, 906250}, {15, 625000}, {62, 500000}, {250, 0} },
78 { {62, 500000}, {250, 0}, {1000, 0}, {4000, 0} }
81 struct isl29018_chip
{
82 struct regmap
*regmap
;
85 unsigned int calibscale
;
86 unsigned int ucalibscale
;
87 unsigned int int_time
;
88 struct isl29018_scale scale
;
91 struct regulator
*vcc_reg
;
94 static int isl29018_set_integration_time(struct isl29018_chip
*chip
,
99 unsigned int int_time
, new_int_time
;
101 for (i
= 0; i
< ARRAY_SIZE(isl29018_int_utimes
[chip
->type
]); ++i
) {
102 if (utime
== isl29018_int_utimes
[chip
->type
][i
]) {
108 if (i
>= ARRAY_SIZE(isl29018_int_utimes
[chip
->type
]))
111 ret
= regmap_update_bits(chip
->regmap
, ISL29018_REG_ADD_COMMAND2
,
112 ISL29018_CMD2_RESOLUTION_MASK
,
113 i
<< ISL29018_CMD2_RESOLUTION_SHIFT
);
117 /* Keep the same range when integration time changes */
118 int_time
= chip
->int_time
;
119 for (i
= 0; i
< ARRAY_SIZE(isl29018_scales
[int_time
]); ++i
) {
120 if (chip
->scale
.scale
== isl29018_scales
[int_time
][i
].scale
&&
121 chip
->scale
.uscale
== isl29018_scales
[int_time
][i
].uscale
) {
122 chip
->scale
= isl29018_scales
[new_int_time
][i
];
126 chip
->int_time
= new_int_time
;
131 static int isl29018_set_scale(struct isl29018_chip
*chip
, int scale
, int uscale
)
135 struct isl29018_scale new_scale
;
137 for (i
= 0; i
< ARRAY_SIZE(isl29018_scales
[chip
->int_time
]); ++i
) {
138 if (scale
== isl29018_scales
[chip
->int_time
][i
].scale
&&
139 uscale
== isl29018_scales
[chip
->int_time
][i
].uscale
) {
140 new_scale
= isl29018_scales
[chip
->int_time
][i
];
145 if (i
>= ARRAY_SIZE(isl29018_scales
[chip
->int_time
]))
148 ret
= regmap_update_bits(chip
->regmap
, ISL29018_REG_ADD_COMMAND2
,
149 ISL29018_CMD2_RANGE_MASK
,
150 i
<< ISL29018_CMD2_RANGE_SHIFT
);
154 chip
->scale
= new_scale
;
159 static int isl29018_read_sensor_input(struct isl29018_chip
*chip
, int mode
)
164 struct device
*dev
= regmap_get_device(chip
->regmap
);
167 status
= regmap_write(chip
->regmap
, ISL29018_REG_ADD_COMMAND1
,
168 mode
<< ISL29018_CMD1_OPMODE_SHIFT
);
171 "Error in setting operating mode err %d\n", status
);
174 msleep(ISL29018_CONV_TIME_MS
);
175 status
= regmap_read(chip
->regmap
, ISL29018_REG_ADD_DATA_LSB
, &lsb
);
178 "Error in reading LSB DATA with err %d\n", status
);
182 status
= regmap_read(chip
->regmap
, ISL29018_REG_ADD_DATA_MSB
, &msb
);
185 "Error in reading MSB DATA with error %d\n", status
);
188 dev_vdbg(dev
, "MSB 0x%x and LSB 0x%x\n", msb
, lsb
);
190 return (msb
<< 8) | lsb
;
193 static int isl29018_read_lux(struct isl29018_chip
*chip
, int *lux
)
196 unsigned int data_x_range
;
198 lux_data
= isl29018_read_sensor_input(chip
,
199 ISL29018_CMD1_OPMODE_ALS_ONCE
);
203 data_x_range
= lux_data
* chip
->scale
.scale
+
204 lux_data
* chip
->scale
.uscale
/ 1000000;
205 *lux
= data_x_range
* chip
->calibscale
+
206 data_x_range
* chip
->ucalibscale
/ 1000000;
211 static int isl29018_read_ir(struct isl29018_chip
*chip
, int *ir
)
215 ir_data
= isl29018_read_sensor_input(chip
,
216 ISL29018_CMD1_OPMODE_IR_ONCE
);
225 static int isl29018_read_proximity_ir(struct isl29018_chip
*chip
, int scheme
,
231 struct device
*dev
= regmap_get_device(chip
->regmap
);
233 /* Do proximity sensing with required scheme */
234 status
= regmap_update_bits(chip
->regmap
, ISL29018_REG_ADD_COMMAND2
,
235 ISL29018_CMD2_SCHEME_MASK
,
236 scheme
<< ISL29018_CMD2_SCHEME_SHIFT
);
238 dev_err(dev
, "Error in setting operating mode\n");
242 prox_data
= isl29018_read_sensor_input(chip
,
243 ISL29018_CMD1_OPMODE_PROX_ONCE
);
248 *near_ir
= prox_data
;
252 ir_data
= isl29018_read_sensor_input(chip
,
253 ISL29018_CMD1_OPMODE_IR_ONCE
);
257 if (prox_data
>= ir_data
)
258 *near_ir
= prox_data
- ir_data
;
265 static ssize_t in_illuminance_scale_available_show
266 (struct device
*dev
, struct device_attribute
*attr
,
269 struct iio_dev
*indio_dev
= dev_to_iio_dev(dev
);
270 struct isl29018_chip
*chip
= iio_priv(indio_dev
);
274 mutex_lock(&chip
->lock
);
275 for (i
= 0; i
< ARRAY_SIZE(isl29018_scales
[chip
->int_time
]); ++i
)
276 len
+= sprintf(buf
+ len
, "%d.%06d ",
277 isl29018_scales
[chip
->int_time
][i
].scale
,
278 isl29018_scales
[chip
->int_time
][i
].uscale
);
279 mutex_unlock(&chip
->lock
);
286 static ssize_t in_illuminance_integration_time_available_show
287 (struct device
*dev
, struct device_attribute
*attr
,
290 struct iio_dev
*indio_dev
= dev_to_iio_dev(dev
);
291 struct isl29018_chip
*chip
= iio_priv(indio_dev
);
295 for (i
= 0; i
< ARRAY_SIZE(isl29018_int_utimes
[chip
->type
]); ++i
)
296 len
+= sprintf(buf
+ len
, "0.%06d ",
297 isl29018_int_utimes
[chip
->type
][i
]);
305 * From ISL29018 Data Sheet (FN6619.4, Oct 8, 2012) regarding the
306 * infrared suppression:
308 * Proximity Sensing Scheme: Bit 7. This bit programs the function
309 * of the proximity detection. Logic 0 of this bit, Scheme 0, makes
310 * full n (4, 8, 12, 16) bits (unsigned) proximity detection. The range
311 * of Scheme 0 proximity count is from 0 to 2^n. Logic 1 of this bit,
312 * Scheme 1, makes n-1 (3, 7, 11, 15) bits (2's complementary)
313 * proximity_less_ambient detection. The range of Scheme 1
314 * proximity count is from -2^(n-1) to 2^(n-1) . The sign bit is extended
315 * for resolutions less than 16. While Scheme 0 has wider dynamic
316 * range, Scheme 1 proximity detection is less affected by the
317 * ambient IR noise variation.
319 * 0 Sensing IR from LED and ambient
320 * 1 Sensing IR from LED with ambient IR rejection
322 static ssize_t proximity_on_chip_ambient_infrared_suppression_show
323 (struct device
*dev
, struct device_attribute
*attr
,
326 struct iio_dev
*indio_dev
= dev_to_iio_dev(dev
);
327 struct isl29018_chip
*chip
= iio_priv(indio_dev
);
330 * Return the "proximity scheme" i.e. if the chip does on chip
331 * infrared suppression (1 means perform on chip suppression)
333 return sprintf(buf
, "%d\n", chip
->prox_scheme
);
336 static ssize_t proximity_on_chip_ambient_infrared_suppression_store
337 (struct device
*dev
, struct device_attribute
*attr
,
338 const char *buf
, size_t count
)
340 struct iio_dev
*indio_dev
= dev_to_iio_dev(dev
);
341 struct isl29018_chip
*chip
= iio_priv(indio_dev
);
344 if (kstrtoint(buf
, 10, &val
))
346 if (!(val
== 0 || val
== 1))
350 * Get the "proximity scheme" i.e. if the chip does on chip
351 * infrared suppression (1 means perform on chip suppression)
353 mutex_lock(&chip
->lock
);
354 chip
->prox_scheme
= val
;
355 mutex_unlock(&chip
->lock
);
360 static int isl29018_write_raw(struct iio_dev
*indio_dev
,
361 struct iio_chan_spec
const *chan
,
366 struct isl29018_chip
*chip
= iio_priv(indio_dev
);
369 mutex_lock(&chip
->lock
);
370 if (chip
->suspended
) {
375 case IIO_CHAN_INFO_CALIBSCALE
:
376 if (chan
->type
== IIO_LIGHT
) {
377 chip
->calibscale
= val
;
378 chip
->ucalibscale
= val2
;
382 case IIO_CHAN_INFO_INT_TIME
:
383 if (chan
->type
== IIO_LIGHT
&& !val
)
384 ret
= isl29018_set_integration_time(chip
, val2
);
386 case IIO_CHAN_INFO_SCALE
:
387 if (chan
->type
== IIO_LIGHT
)
388 ret
= isl29018_set_scale(chip
, val
, val2
);
395 mutex_unlock(&chip
->lock
);
400 static int isl29018_read_raw(struct iio_dev
*indio_dev
,
401 struct iio_chan_spec
const *chan
,
407 struct isl29018_chip
*chip
= iio_priv(indio_dev
);
409 mutex_lock(&chip
->lock
);
410 if (chip
->suspended
) {
415 case IIO_CHAN_INFO_RAW
:
416 case IIO_CHAN_INFO_PROCESSED
:
417 switch (chan
->type
) {
419 ret
= isl29018_read_lux(chip
, val
);
422 ret
= isl29018_read_ir(chip
, val
);
425 ret
= isl29018_read_proximity_ir(chip
,
435 case IIO_CHAN_INFO_INT_TIME
:
436 if (chan
->type
== IIO_LIGHT
) {
438 *val2
= isl29018_int_utimes
[chip
->type
][chip
->int_time
];
439 ret
= IIO_VAL_INT_PLUS_MICRO
;
442 case IIO_CHAN_INFO_SCALE
:
443 if (chan
->type
== IIO_LIGHT
) {
444 *val
= chip
->scale
.scale
;
445 *val2
= chip
->scale
.uscale
;
446 ret
= IIO_VAL_INT_PLUS_MICRO
;
449 case IIO_CHAN_INFO_CALIBSCALE
:
450 if (chan
->type
== IIO_LIGHT
) {
451 *val
= chip
->calibscale
;
452 *val2
= chip
->ucalibscale
;
453 ret
= IIO_VAL_INT_PLUS_MICRO
;
461 mutex_unlock(&chip
->lock
);
466 #define ISL29018_LIGHT_CHANNEL { \
470 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | \
471 BIT(IIO_CHAN_INFO_CALIBSCALE) | \
472 BIT(IIO_CHAN_INFO_SCALE) | \
473 BIT(IIO_CHAN_INFO_INT_TIME), \
476 #define ISL29018_IR_CHANNEL { \
477 .type = IIO_INTENSITY, \
479 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
480 .channel2 = IIO_MOD_LIGHT_IR, \
483 #define ISL29018_PROXIMITY_CHANNEL { \
484 .type = IIO_PROXIMITY, \
485 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
488 static const struct iio_chan_spec isl29018_channels
[] = {
489 ISL29018_LIGHT_CHANNEL
,
491 ISL29018_PROXIMITY_CHANNEL
,
494 static const struct iio_chan_spec isl29023_channels
[] = {
495 ISL29018_LIGHT_CHANNEL
,
499 static IIO_DEVICE_ATTR_RO(in_illuminance_integration_time_available
, 0);
500 static IIO_DEVICE_ATTR_RO(in_illuminance_scale_available
, 0);
501 static IIO_DEVICE_ATTR_RW(proximity_on_chip_ambient_infrared_suppression
, 0);
503 #define ISL29018_DEV_ATTR(name) (&iio_dev_attr_##name.dev_attr.attr)
505 static struct attribute
*isl29018_attributes
[] = {
506 ISL29018_DEV_ATTR(in_illuminance_scale_available
),
507 ISL29018_DEV_ATTR(in_illuminance_integration_time_available
),
508 ISL29018_DEV_ATTR(proximity_on_chip_ambient_infrared_suppression
),
512 static struct attribute
*isl29023_attributes
[] = {
513 ISL29018_DEV_ATTR(in_illuminance_scale_available
),
514 ISL29018_DEV_ATTR(in_illuminance_integration_time_available
),
518 static const struct attribute_group isl29018_group
= {
519 .attrs
= isl29018_attributes
,
522 static const struct attribute_group isl29023_group
= {
523 .attrs
= isl29023_attributes
,
532 static int isl29018_chip_init(struct isl29018_chip
*chip
)
535 struct device
*dev
= regmap_get_device(chip
->regmap
);
537 if (chip
->type
== isl29035
) {
540 status
= regmap_read(chip
->regmap
, ISL29035_REG_DEVICE_ID
, &id
);
543 "Error reading ID register with error %d\n",
548 id
= (id
& ISL29035_DEVICE_ID_MASK
) >> ISL29035_DEVICE_ID_SHIFT
;
550 if (id
!= ISL29035_DEVICE_ID
)
553 /* Clear brownout bit */
554 status
= regmap_clear_bits(chip
->regmap
,
555 ISL29035_REG_DEVICE_ID
,
562 * Code added per Intersil Application Note 1534:
563 * When VDD sinks to approximately 1.8V or below, some of
564 * the part's registers may change their state. When VDD
565 * recovers to 2.25V (or greater), the part may thus be in an
566 * unknown mode of operation. The user can return the part to
567 * a known mode of operation either by (a) setting VDD = 0V for
568 * 1 second or more and then powering back up with a slew rate
569 * of 0.5V/ms or greater, or (b) via I2C disable all ALS/PROX
570 * conversions, clear the test registers, and then rewrite all
571 * registers to the desired values.
573 * For ISL29011, ISL29018, ISL29021, ISL29023
574 * 1. Write 0x00 to register 0x08 (TEST)
575 * 2. Write 0x00 to register 0x00 (CMD1)
576 * 3. Rewrite all registers to the desired values
578 * ISL29018 Data Sheet (FN6619.1, Feb 11, 2010) essentially says
579 * the same thing EXCEPT the data sheet asks for a 1ms delay after
580 * writing the CMD1 register.
582 status
= regmap_write(chip
->regmap
, ISL29018_REG_TEST
, 0x0);
584 dev_err(dev
, "Failed to clear isl29018 TEST reg.(%d)\n",
590 * See Intersil AN1534 comments above.
591 * "Operating Mode" (COMMAND1) register is reprogrammed when
592 * data is read from the device.
594 status
= regmap_write(chip
->regmap
, ISL29018_REG_ADD_COMMAND1
, 0);
596 dev_err(dev
, "Failed to clear isl29018 CMD1 reg.(%d)\n",
601 usleep_range(1000, 2000); /* per data sheet, page 10 */
604 status
= isl29018_set_scale(chip
, chip
->scale
.scale
,
607 dev_err(dev
, "Init of isl29018 fails\n");
611 status
= isl29018_set_integration_time(chip
,
612 isl29018_int_utimes
[chip
->type
][chip
->int_time
]);
614 dev_err(dev
, "Init of isl29018 fails\n");
619 static const struct iio_info isl29018_info
= {
620 .attrs
= &isl29018_group
,
621 .read_raw
= isl29018_read_raw
,
622 .write_raw
= isl29018_write_raw
,
625 static const struct iio_info isl29023_info
= {
626 .attrs
= &isl29023_group
,
627 .read_raw
= isl29018_read_raw
,
628 .write_raw
= isl29018_write_raw
,
631 static bool isl29018_is_volatile_reg(struct device
*dev
, unsigned int reg
)
634 case ISL29018_REG_ADD_DATA_LSB
:
635 case ISL29018_REG_ADD_DATA_MSB
:
636 case ISL29018_REG_ADD_COMMAND1
:
637 case ISL29018_REG_TEST
:
638 case ISL29035_REG_DEVICE_ID
:
645 static const struct regmap_config isl29018_regmap_config
= {
648 .volatile_reg
= isl29018_is_volatile_reg
,
649 .max_register
= ISL29018_REG_TEST
,
650 .num_reg_defaults_raw
= ISL29018_REG_TEST
+ 1,
651 .cache_type
= REGCACHE_RBTREE
,
654 static const struct regmap_config isl29035_regmap_config
= {
657 .volatile_reg
= isl29018_is_volatile_reg
,
658 .max_register
= ISL29035_REG_DEVICE_ID
,
659 .num_reg_defaults_raw
= ISL29035_REG_DEVICE_ID
+ 1,
660 .cache_type
= REGCACHE_RBTREE
,
663 struct isl29018_chip_info
{
664 const struct iio_chan_spec
*channels
;
666 const struct iio_info
*indio_info
;
667 const struct regmap_config
*regmap_cfg
;
670 static const struct isl29018_chip_info isl29018_chip_info_tbl
[] = {
672 .channels
= isl29018_channels
,
673 .num_channels
= ARRAY_SIZE(isl29018_channels
),
674 .indio_info
= &isl29018_info
,
675 .regmap_cfg
= &isl29018_regmap_config
,
678 .channels
= isl29023_channels
,
679 .num_channels
= ARRAY_SIZE(isl29023_channels
),
680 .indio_info
= &isl29023_info
,
681 .regmap_cfg
= &isl29018_regmap_config
,
684 .channels
= isl29023_channels
,
685 .num_channels
= ARRAY_SIZE(isl29023_channels
),
686 .indio_info
= &isl29023_info
,
687 .regmap_cfg
= &isl29035_regmap_config
,
691 static void isl29018_disable_regulator_action(void *_data
)
693 struct isl29018_chip
*chip
= _data
;
696 err
= regulator_disable(chip
->vcc_reg
);
698 pr_err("failed to disable isl29018's VCC regulator!\n");
701 static int isl29018_probe(struct i2c_client
*client
)
703 const struct i2c_device_id
*id
= i2c_client_get_device_id(client
);
704 struct isl29018_chip
*chip
;
705 struct iio_dev
*indio_dev
;
706 const void *ddata
= NULL
;
711 indio_dev
= devm_iio_device_alloc(&client
->dev
, sizeof(*chip
));
715 chip
= iio_priv(indio_dev
);
717 i2c_set_clientdata(client
, indio_dev
);
721 dev_id
= id
->driver_data
;
723 name
= iio_get_acpi_device_name_and_data(&client
->dev
, &ddata
);
724 dev_id
= (intptr_t)ddata
;
727 mutex_init(&chip
->lock
);
730 chip
->calibscale
= 1;
731 chip
->ucalibscale
= 0;
732 chip
->int_time
= ISL29018_INT_TIME_16
;
733 chip
->scale
= isl29018_scales
[chip
->int_time
][0];
734 chip
->suspended
= false;
736 chip
->vcc_reg
= devm_regulator_get(&client
->dev
, "vcc");
737 if (IS_ERR(chip
->vcc_reg
))
738 return dev_err_probe(&client
->dev
, PTR_ERR(chip
->vcc_reg
),
739 "failed to get VCC regulator!\n");
741 err
= regulator_enable(chip
->vcc_reg
);
743 dev_err(&client
->dev
, "failed to enable VCC regulator!\n");
747 err
= devm_add_action_or_reset(&client
->dev
, isl29018_disable_regulator_action
,
750 dev_err(&client
->dev
, "failed to setup regulator cleanup action!\n");
754 chip
->regmap
= devm_regmap_init_i2c(client
,
755 isl29018_chip_info_tbl
[dev_id
].regmap_cfg
);
756 if (IS_ERR(chip
->regmap
)) {
757 err
= PTR_ERR(chip
->regmap
);
758 dev_err(&client
->dev
, "regmap initialization fails: %d\n", err
);
762 err
= isl29018_chip_init(chip
);
766 indio_dev
->info
= isl29018_chip_info_tbl
[dev_id
].indio_info
;
767 indio_dev
->channels
= isl29018_chip_info_tbl
[dev_id
].channels
;
768 indio_dev
->num_channels
= isl29018_chip_info_tbl
[dev_id
].num_channels
;
769 indio_dev
->name
= name
;
770 indio_dev
->modes
= INDIO_DIRECT_MODE
;
772 return devm_iio_device_register(&client
->dev
, indio_dev
);
775 static int isl29018_suspend(struct device
*dev
)
777 struct isl29018_chip
*chip
= iio_priv(dev_get_drvdata(dev
));
780 mutex_lock(&chip
->lock
);
783 * Since this driver uses only polling commands, we are by default in
784 * auto shutdown (ie, power-down) mode.
785 * So we do not have much to do here.
787 chip
->suspended
= true;
788 ret
= regulator_disable(chip
->vcc_reg
);
790 dev_err(dev
, "failed to disable VCC regulator\n");
792 mutex_unlock(&chip
->lock
);
797 static int isl29018_resume(struct device
*dev
)
799 struct isl29018_chip
*chip
= iio_priv(dev_get_drvdata(dev
));
802 mutex_lock(&chip
->lock
);
804 err
= regulator_enable(chip
->vcc_reg
);
806 dev_err(dev
, "failed to enable VCC regulator\n");
807 mutex_unlock(&chip
->lock
);
811 err
= isl29018_chip_init(chip
);
813 chip
->suspended
= false;
815 mutex_unlock(&chip
->lock
);
820 static DEFINE_SIMPLE_DEV_PM_OPS(isl29018_pm_ops
, isl29018_suspend
,
823 static const struct acpi_device_id isl29018_acpi_match
[] = {
824 {"ISL29018", isl29018
},
825 {"ISL29023", isl29023
},
826 {"ISL29035", isl29035
},
829 MODULE_DEVICE_TABLE(acpi
, isl29018_acpi_match
);
831 static const struct i2c_device_id isl29018_id
[] = {
832 {"isl29018", isl29018
},
833 {"isl29023", isl29023
},
834 {"isl29035", isl29035
},
837 MODULE_DEVICE_TABLE(i2c
, isl29018_id
);
839 static const struct of_device_id isl29018_of_match
[] = {
840 { .compatible
= "isil,isl29018", },
841 { .compatible
= "isil,isl29023", },
842 { .compatible
= "isil,isl29035", },
845 MODULE_DEVICE_TABLE(of
, isl29018_of_match
);
847 static struct i2c_driver isl29018_driver
= {
850 .acpi_match_table
= isl29018_acpi_match
,
851 .pm
= pm_sleep_ptr(&isl29018_pm_ops
),
852 .of_match_table
= isl29018_of_match
,
854 .probe
= isl29018_probe
,
855 .id_table
= isl29018_id
,
857 module_i2c_driver(isl29018_driver
);
859 MODULE_DESCRIPTION("ISL29018 Ambient Light Sensor driver");
860 MODULE_LICENSE("GPL");