Lines Matching +full:delta +full:- +full:x +full:- +full:threshold
1 // SPDX-License-Identifier: GPL-2.0-only
3 * vcnl4000.c - Support for Vishay VCNL4000/4010/4020/4040/4200 combined ambient
11 * VCNL4000/10/20 (7-bit I2C slave address 0x13)
12 * VCNL4040 (7-bit I2C slave address 0x60)
13 * VCNL4200 (7-bit I2C slave address 0x51)
56 #define VCNL4010_LOW_THR_HI 0x8a /* Low threshold, MSB */
57 #define VCNL4010_LOW_THR_LO 0x8b /* Low threshold, LSB */
58 #define VCNL4010_HIGH_THR_HI 0x8c /* High threshold, MSB */
59 #define VCNL4010_HIGH_THR_LO 0x8d /* High threshold, LSB */
65 #define VCNL4040_PS_THDL_LM 0x06 /* Proximity threshold low */
66 #define VCNL4040_PS_THDH_LM 0x07 /* Proximity threshold high */
67 #define VCNL4040_ALS_THDL_LM 0x02 /* Ambient light threshold low */
68 #define VCNL4040_ALS_THDH_LM 0x01 /* Ambient light threshold high */
80 #define VCNL4000_AL_OD BIT(4) /* start on-demand ALS measurement */
81 #define VCNL4000_PS_OD BIT(3) /* start on-demand proximity measurement */
84 #define VCNL4000_SELF_TIMED_EN BIT(0) /* start self-timed measurement */
97 #define VCNL4040_PS_IF_AWAY BIT(8) /* Proximity event cross low threshold */
98 #define VCNL4040_PS_IF_CLOSE BIT(9) /* Proximity event cross high threshold */
99 #define VCNL4040_ALS_RISING BIT(12) /* Ambient Light cross high threshold */
100 #define VCNL4040_ALS_FALLING BIT(13) /* Ambient Light cross low threshold */
103 #define VCNL4010_INT_THR_SEL BIT(0) /* Select threshold interrupt source */
104 #define VCNL4010_INT_THR_EN BIT(1) /* Threshold interrupt type */
108 #define VCNL4010_INT_THR_HIGH 0 /* High threshold exceeded */
109 #define VCNL4010_INT_THR_LOW 1 /* Low threshold exceeded */
257 ret = i2c_smbus_read_byte_data(data->client, VCNL4000_PROD_REV); in vcnl4000_init()
264 if (data->id != VCNL4000) in vcnl4000_init()
265 dev_warn(&data->client->dev, in vcnl4000_init()
269 if (data->id != VCNL4010) in vcnl4000_init()
270 dev_warn(&data->client->dev, in vcnl4000_init()
274 return -ENODEV; in vcnl4000_init()
277 data->rev = ret & 0xf; in vcnl4000_init()
278 data->al_scale = 250000; in vcnl4000_init()
280 return data->chip_spec->set_power_state(data, true); in vcnl4000_init()
287 mutex_lock(&data->vcnl4000_lock); in vcnl4000_write_als_enable()
289 ret = i2c_smbus_read_word_data(data->client, VCNL4200_AL_CONF); in vcnl4000_write_als_enable()
298 ret = i2c_smbus_write_word_data(data->client, VCNL4200_AL_CONF, ret); in vcnl4000_write_als_enable()
301 mutex_unlock(&data->vcnl4000_lock); in vcnl4000_write_als_enable()
310 mutex_lock(&data->vcnl4000_lock); in vcnl4000_write_ps_enable()
312 ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); in vcnl4000_write_ps_enable()
321 ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, ret); in vcnl4000_write_ps_enable()
324 mutex_unlock(&data->vcnl4000_lock); in vcnl4000_write_ps_enable()
334 if (!on && (data->ps_int || data->als_int)) in vcnl4200_set_power_state()
347 data->vcnl4200_al.last_measurement = ktime_get(); in vcnl4200_set_power_state()
348 data->vcnl4200_ps.last_measurement = ktime_get(); in vcnl4200_set_power_state()
359 ret = i2c_smbus_read_word_data(data->client, VCNL4200_DEV_ID); in vcnl4200_init()
366 ret = i2c_smbus_read_word_data(data->client, VCNL4040_DEV_ID); in vcnl4200_init()
373 return -ENODEV; in vcnl4200_init()
376 dev_dbg(&data->client->dev, "device id 0x%x", id); in vcnl4200_init()
378 data->rev = (ret >> 8) & 0xf; in vcnl4200_init()
379 data->ps_int = 0; in vcnl4200_init()
380 data->als_int = 0; in vcnl4200_init()
382 data->vcnl4200_al.reg = VCNL4200_AL_DATA; in vcnl4200_init()
383 data->vcnl4200_ps.reg = VCNL4200_PS_DATA; in vcnl4200_init()
387 data->vcnl4200_al.sampling_rate = ktime_set(0, 60000 * 1000); in vcnl4200_init()
389 data->vcnl4200_ps.sampling_rate = ktime_set(0, 5760 * 1000); in vcnl4200_init()
393 data->vcnl4200_al.sampling_rate = ktime_set(0, 96000 * 1000); in vcnl4200_init()
395 data->vcnl4200_ps.sampling_rate = ktime_set(0, 6000 * 1000); in vcnl4200_init()
398 data->al_scale = data->chip_spec->ulux_step; in vcnl4200_init()
399 data->ps_scale = 16; in vcnl4200_init()
400 mutex_init(&data->vcnl4200_al.lock); in vcnl4200_init()
401 mutex_init(&data->vcnl4200_ps.lock); in vcnl4200_init()
404 ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); in vcnl4200_init()
409 ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, in vcnl4200_init()
415 ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF3); in vcnl4200_init()
420 ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF3, in vcnl4200_init()
425 ret = data->chip_spec->set_power_state(data, true); in vcnl4200_init()
436 ret = i2c_smbus_read_word_swapped(data->client, data_reg); in vcnl4000_read_data()
447 return -ERANGE; in vcnl4000_write_data()
449 return i2c_smbus_write_word_swapped(data->client, data_reg, val); in vcnl4000_write_data()
459 mutex_lock(&data->vcnl4000_lock); in vcnl4000_measure()
461 ret = i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND, in vcnl4000_measure()
467 while (tries--) { in vcnl4000_measure()
468 ret = i2c_smbus_read_byte_data(data->client, VCNL4000_COMMAND); in vcnl4000_measure()
477 dev_err(&data->client->dev, in vcnl4000_measure()
479 ret = -EIO; in vcnl4000_measure()
487 mutex_unlock(&data->vcnl4000_lock); in vcnl4000_measure()
492 mutex_unlock(&data->vcnl4000_lock); in vcnl4000_measure()
500 s64 delta; in vcnl4200_measure() local
503 mutex_lock(&chan->lock); in vcnl4200_measure()
505 next_measurement = ktime_add(chan->last_measurement, in vcnl4200_measure()
506 chan->sampling_rate); in vcnl4200_measure()
507 delta = ktime_us_delta(next_measurement, ktime_get()); in vcnl4200_measure()
508 if (delta > 0) in vcnl4200_measure()
509 usleep_range(delta, delta + 500); in vcnl4200_measure()
510 chan->last_measurement = ktime_get(); in vcnl4200_measure()
512 mutex_unlock(&chan->lock); in vcnl4200_measure()
514 ret = i2c_smbus_read_word_data(data->client, chan->reg); in vcnl4200_measure()
532 return vcnl4200_measure(data, &data->vcnl4200_al, val); in vcnl4200_measure_light()
544 return vcnl4200_measure(data, &data->vcnl4200_ps, val); in vcnl4200_measure_proximity()
552 ret = i2c_smbus_read_byte_data(data->client, VCNL4010_PROX_RATE); in vcnl4010_read_proxy_samp_freq()
557 return -EINVAL; in vcnl4010_read_proxy_samp_freq()
569 ret = i2c_smbus_read_byte_data(data->client, VCNL4000_COMMAND); in vcnl4010_is_in_periodic_mode()
578 struct device *dev = &data->client->dev; in vcnl4000_set_pm_runtime_state()
595 ret = i2c_smbus_read_word_data(data->client, VCNL4200_AL_CONF); in vcnl4040_read_als_it()
600 if (ret >= data->chip_spec->num_als_it_times) in vcnl4040_read_als_it()
601 return -EINVAL; in vcnl4040_read_als_it()
603 *val = (*data->chip_spec->als_it_times)[ret][0]; in vcnl4040_read_als_it()
604 *val2 = (*data->chip_spec->als_it_times)[ret][1]; in vcnl4040_read_als_it()
615 for (i = 0; i < data->chip_spec->num_als_it_times; i++) { in vcnl4040_write_als_it()
616 if (val == (*data->chip_spec->als_it_times)[i][1]) in vcnl4040_write_als_it()
620 if (i == data->chip_spec->num_als_it_times) in vcnl4040_write_als_it()
621 return -EINVAL; in vcnl4040_write_als_it()
623 data->vcnl4200_al.sampling_rate = ktime_set(0, val * 1200); in vcnl4040_write_als_it()
624 data->al_scale = div_u64(mul_u32_u32(data->chip_spec->ulux_step, in vcnl4040_write_als_it()
625 (*data->chip_spec->als_it_times)[0][1]), in vcnl4040_write_als_it()
628 mutex_lock(&data->vcnl4000_lock); in vcnl4040_write_als_it()
630 ret = i2c_smbus_read_word_data(data->client, VCNL4200_AL_CONF); in vcnl4040_write_als_it()
636 ret = i2c_smbus_write_word_data(data->client, in vcnl4040_write_als_it()
641 mutex_unlock(&data->vcnl4000_lock); in vcnl4040_write_als_it()
649 ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); in vcnl4040_read_ps_it()
655 if (ret >= data->chip_spec->num_ps_it_times) in vcnl4040_read_ps_it()
656 return -EINVAL; in vcnl4040_read_ps_it()
658 *val = (*data->chip_spec->ps_it_times)[ret][0]; in vcnl4040_read_ps_it()
659 *val2 = (*data->chip_spec->ps_it_times)[ret][1]; in vcnl4040_read_ps_it()
667 int ret, index = -1; in vcnl4040_write_ps_it()
670 for (i = 0; i < data->chip_spec->num_ps_it_times; i++) { in vcnl4040_write_ps_it()
671 if (val == (*data->chip_spec->ps_it_times)[i][1]) { in vcnl4040_write_ps_it()
678 return -EINVAL; in vcnl4040_write_ps_it()
680 data->vcnl4200_ps.sampling_rate = ktime_set(0, val * 60 * NSEC_PER_USEC); in vcnl4040_write_ps_it()
682 mutex_lock(&data->vcnl4000_lock); in vcnl4040_write_ps_it()
684 ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); in vcnl4040_write_ps_it()
690 ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, in vcnl4040_write_ps_it()
694 mutex_unlock(&data->vcnl4000_lock); in vcnl4040_write_ps_it()
703 ret = i2c_smbus_read_word_data(data->client, VCNL4200_AL_CONF); in vcnl4040_read_als_period()
709 return -EINVAL; in vcnl4040_read_als_period()
712 if (it >= data->chip_spec->num_als_it_times) in vcnl4040_read_als_period()
713 return -EINVAL; in vcnl4040_read_als_period()
715 val_c = mul_u32_u32((*data->chip_spec->als_it_times)[it][1], in vcnl4040_read_als_period()
729 ret = i2c_smbus_read_word_data(data->client, VCNL4200_AL_CONF); in vcnl4040_write_als_period()
734 if (it >= data->chip_spec->num_als_it_times) in vcnl4040_write_als_period()
735 return -EINVAL; in vcnl4040_write_als_period()
737 for (i = 0; i < ARRAY_SIZE(vcnl4040_als_persistence) - 1; i++) { in vcnl4040_write_als_period()
739 (*data->chip_spec->als_it_times)[it][1])) in vcnl4040_write_als_period()
743 mutex_lock(&data->vcnl4000_lock); in vcnl4040_write_als_period()
745 ret = i2c_smbus_read_word_data(data->client, VCNL4200_AL_CONF); in vcnl4040_write_als_period()
751 ret = i2c_smbus_write_word_data(data->client, VCNL4200_AL_CONF, in vcnl4040_write_als_period()
755 mutex_unlock(&data->vcnl4000_lock); in vcnl4040_write_als_period()
763 ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); in vcnl4040_read_ps_period()
769 return -EINVAL; in vcnl4040_read_ps_period()
772 if (it >= data->chip_spec->num_ps_it_times) in vcnl4040_read_ps_period()
773 return -EINVAL; in vcnl4040_read_ps_period()
775 *val = (*data->chip_spec->ps_it_times)[it][0]; in vcnl4040_read_ps_period()
776 *val2 = (*data->chip_spec->ps_it_times)[it][1] * in vcnl4040_read_ps_period()
787 ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); in vcnl4040_write_ps_period()
792 if (it >= data->chip_spec->num_ps_it_times) in vcnl4040_write_ps_period()
793 return -EINVAL; in vcnl4040_write_ps_period()
796 i = ARRAY_SIZE(vcnl4040_ps_persistence) - 1; in vcnl4040_write_ps_period()
798 for (i = 0; i < ARRAY_SIZE(vcnl4040_ps_persistence) - 1; i++) { in vcnl4040_write_ps_period()
800 (*data->chip_spec->ps_it_times)[it][1]) in vcnl4040_write_ps_period()
805 mutex_lock(&data->vcnl4000_lock); in vcnl4040_write_ps_period()
807 ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); in vcnl4040_write_ps_period()
813 ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, in vcnl4040_write_ps_period()
817 mutex_unlock(&data->vcnl4000_lock); in vcnl4040_write_ps_period()
825 ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF3); in vcnl4040_read_ps_oversampling_ratio()
831 return -EINVAL; in vcnl4040_read_ps_oversampling_ratio()
850 return -EINVAL; in vcnl4040_write_ps_oversampling_ratio()
852 mutex_lock(&data->vcnl4000_lock); in vcnl4040_write_ps_oversampling_ratio()
854 ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF3); in vcnl4040_write_ps_oversampling_ratio()
860 ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF3, in vcnl4040_write_ps_oversampling_ratio()
864 mutex_unlock(&data->vcnl4000_lock); in vcnl4040_write_ps_oversampling_ratio()
872 ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF3); in vcnl4040_read_ps_calibbias()
878 return -EINVAL; in vcnl4040_read_ps_calibbias()
898 return -EINVAL; in vcnl4040_write_ps_calibbias()
900 mutex_lock(&data->vcnl4000_lock); in vcnl4040_write_ps_calibbias()
902 ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF3); in vcnl4040_write_ps_calibbias()
908 ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF3, in vcnl4040_write_ps_calibbias()
912 mutex_unlock(&data->vcnl4000_lock); in vcnl4040_write_ps_calibbias()
929 switch (chan->type) { in vcnl4000_read_raw()
931 ret = data->chip_spec->measure_light(data, val); in vcnl4000_read_raw()
936 ret = data->chip_spec->measure_proximity(data, val); in vcnl4000_read_raw()
937 *val2 = data->ps_scale; in vcnl4000_read_raw()
942 ret = -EINVAL; in vcnl4000_read_raw()
947 if (chan->type != IIO_LIGHT) in vcnl4000_read_raw()
948 return -EINVAL; in vcnl4000_read_raw()
951 *val2 = data->al_scale; in vcnl4000_read_raw()
954 switch (chan->type) { in vcnl4000_read_raw()
962 return -EINVAL; in vcnl4000_read_raw()
968 switch (chan->type) { in vcnl4000_read_raw()
975 return -EINVAL; in vcnl4000_read_raw()
978 switch (chan->type) { in vcnl4000_read_raw()
985 return -EINVAL; in vcnl4000_read_raw()
988 return -EINVAL; in vcnl4000_read_raw()
1001 return -EINVAL; in vcnl4040_write_raw()
1002 switch (chan->type) { in vcnl4040_write_raw()
1008 return -EINVAL; in vcnl4040_write_raw()
1011 switch (chan->type) { in vcnl4040_write_raw()
1015 return -EINVAL; in vcnl4040_write_raw()
1018 switch (chan->type) { in vcnl4040_write_raw()
1022 return -EINVAL; in vcnl4040_write_raw()
1025 return -EINVAL; in vcnl4040_write_raw()
1038 switch (chan->type) { in vcnl4040_read_avail()
1040 *vals = (int *)(*data->chip_spec->als_it_times); in vcnl4040_read_avail()
1041 *length = 2 * data->chip_spec->num_als_it_times; in vcnl4040_read_avail()
1044 *vals = (int *)(*data->chip_spec->ps_it_times); in vcnl4040_read_avail()
1045 *length = 2 * data->chip_spec->num_ps_it_times; in vcnl4040_read_avail()
1048 return -EINVAL; in vcnl4040_read_avail()
1053 switch (chan->type) { in vcnl4040_read_avail()
1060 return -EINVAL; in vcnl4040_read_avail()
1063 switch (chan->type) { in vcnl4040_read_avail()
1070 return -EINVAL; in vcnl4040_read_avail()
1073 return -EINVAL; in vcnl4040_read_avail()
1093 ret = -EBUSY; in vcnl4010_read_raw()
1102 switch (chan->type) { in vcnl4010_read_raw()
1109 return -EINVAL; in vcnl4010_read_raw()
1112 return -EINVAL; in vcnl4010_read_raw()
1128 return -EINVAL; in vcnl4010_read_avail()
1136 int index = -1; in vcnl4010_write_proxy_samp_freq()
1147 return -EINVAL; in vcnl4010_write_proxy_samp_freq()
1149 return i2c_smbus_write_byte_data(data->client, VCNL4010_PROX_RATE, in vcnl4010_write_proxy_samp_freq()
1166 ret = -EBUSY; in vcnl4010_write_raw()
1172 switch (chan->type) { in vcnl4010_write_raw()
1177 ret = -EINVAL; in vcnl4010_write_raw()
1181 ret = -EINVAL; in vcnl4010_write_raw()
1216 return -EINVAL; in vcnl4010_read_event()
1219 return -EINVAL; in vcnl4010_read_event()
1249 return -EINVAL; in vcnl4010_write_event()
1252 return -EINVAL; in vcnl4010_write_event()
1266 switch (chan->type) { in vcnl4040_read_event()
1274 ret = i2c_smbus_read_word_data(data->client, in vcnl4040_read_event()
1278 ret = i2c_smbus_read_word_data(data->client, in vcnl4040_read_event()
1282 return -EINVAL; in vcnl4040_read_event()
1286 return -EINVAL; in vcnl4040_read_event()
1296 ret = i2c_smbus_read_word_data(data->client, in vcnl4040_read_event()
1300 ret = i2c_smbus_read_word_data(data->client, in vcnl4040_read_event()
1304 return -EINVAL; in vcnl4040_read_event()
1308 return -EINVAL; in vcnl4040_read_event()
1312 return -EINVAL; in vcnl4040_read_event()
1330 switch (chan->type) { in vcnl4040_write_event()
1338 ret = i2c_smbus_write_word_data(data->client, in vcnl4040_write_event()
1343 ret = i2c_smbus_write_word_data(data->client, in vcnl4040_write_event()
1348 return -EINVAL; in vcnl4040_write_event()
1352 return -EINVAL; in vcnl4040_write_event()
1362 ret = i2c_smbus_write_word_data(data->client, in vcnl4040_write_event()
1367 ret = i2c_smbus_write_word_data(data->client, in vcnl4040_write_event()
1372 return -EINVAL; in vcnl4040_write_event()
1376 return -EINVAL; in vcnl4040_write_event()
1380 return -EINVAL; in vcnl4040_write_event()
1391 ret = i2c_smbus_read_byte_data(data->client, VCNL4010_INT_CTRL); in vcnl4010_is_thr_enabled()
1405 switch (chan->type) { in vcnl4010_read_event_config()
1409 return -EINVAL; in vcnl4010_read_event_config()
1429 * Enable interrupts on threshold, for proximity data by in vcnl4010_config_threshold()
1441 ret = i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND, in vcnl4010_config_threshold()
1446 ret = i2c_smbus_write_byte_data(data->client, VCNL4010_INT_CTRL, icr); in vcnl4010_config_threshold()
1461 switch (chan->type) { in vcnl4010_write_event_config()
1465 return -EINVAL; in vcnl4010_write_event_config()
1477 switch (chan->type) { in vcnl4040_read_event_config()
1479 ret = i2c_smbus_read_word_data(data->client, VCNL4200_AL_CONF); in vcnl4040_read_event_config()
1483 data->als_int = FIELD_GET(VCNL4040_ALS_CONF_INT_EN, ret); in vcnl4040_read_event_config()
1485 return data->als_int; in vcnl4040_read_event_config()
1487 ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); in vcnl4040_read_event_config()
1491 data->ps_int = FIELD_GET(VCNL4040_PS_CONF2_PS_INT, ret); in vcnl4040_read_event_config()
1497 return -EINVAL; in vcnl4040_read_event_config()
1506 int ret = -EINVAL; in vcnl4040_write_event_config()
1510 mutex_lock(&data->vcnl4000_lock); in vcnl4040_write_event_config()
1512 switch (chan->type) { in vcnl4040_write_event_config()
1514 ret = i2c_smbus_read_word_data(data->client, VCNL4200_AL_CONF); in vcnl4040_write_event_config()
1524 data->als_int = FIELD_GET(VCNL4040_ALS_CONF_INT_EN, val); in vcnl4040_write_event_config()
1525 ret = i2c_smbus_write_word_data(data->client, VCNL4200_AL_CONF, in vcnl4040_write_event_config()
1529 ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); in vcnl4040_write_event_config()
1540 data->ps_int = FIELD_GET(VCNL4040_PS_CONF2_PS_INT, val); in vcnl4040_write_event_config()
1541 ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, in vcnl4040_write_event_config()
1549 mutex_unlock(&data->vcnl4000_lock); in vcnl4040_write_event_config()
1560 ret = i2c_smbus_read_word_data(data->client, data->chip_spec->int_reg); in vcnl4040_irq_thread()
1606 return sprintf(buf, "%u\n", data->near_level); in vcnl4000_read_near_level()
1616 ret = i2c_smbus_read_byte_data(data->client, VCNL4010_ISR); in vcnl4010_irq_thread()
1643 i2c_smbus_write_byte_data(data->client, VCNL4010_ISR, in vcnl4010_irq_thread()
1648 iio_trigger_poll_nested(indio_dev->trig); in vcnl4010_irq_thread()
1657 struct iio_dev *indio_dev = pf->indio_dev; in vcnl4010_trigger_handler()
1659 const unsigned long *active_scan_mask = indio_dev->active_scan_mask; in vcnl4010_trigger_handler()
1660 u16 buffer[8] __aligned(8) = {0}; /* 1x16-bit + naturally aligned ts */ in vcnl4010_trigger_handler()
1666 ret = i2c_smbus_read_byte_data(data->client, VCNL4010_ISR); in vcnl4010_trigger_handler()
1685 ret = i2c_smbus_write_byte_data(data->client, VCNL4010_ISR, in vcnl4010_trigger_handler()
1697 iio_trigger_notify_done(indio_dev->trig); in vcnl4010_trigger_handler()
1709 return -EBUSY; in vcnl4010_buffer_postenable()
1711 ret = i2c_smbus_write_byte_data(data->client, VCNL4010_INT_CTRL, in vcnl4010_buffer_postenable()
1717 return i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND, cmd); in vcnl4010_buffer_postenable()
1725 ret = i2c_smbus_write_byte_data(data->client, VCNL4010_INT_CTRL, 0); in vcnl4010_buffer_predisable()
1729 return i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND, 0); in vcnl4010_buffer_predisable()
1809 .scan_index = -1,
1946 struct i2c_client *client = data->client; in vcnl4010_probe_trigger()
1949 trigger = devm_iio_trigger_alloc(&client->dev, "%s-dev%d", in vcnl4010_probe_trigger()
1950 indio_dev->name, in vcnl4010_probe_trigger()
1953 return -ENOMEM; in vcnl4010_probe_trigger()
1955 trigger->ops = &vcnl4010_trigger_ops; in vcnl4010_probe_trigger()
1958 return devm_iio_trigger_register(&client->dev, trigger); in vcnl4010_probe_trigger()
1968 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in vcnl4000_probe()
1970 return -ENOMEM; in vcnl4000_probe()
1974 data->client = client; in vcnl4000_probe()
1975 data->id = id->driver_data; in vcnl4000_probe()
1976 data->chip_spec = &vcnl4000_chip_spec_cfg[data->id]; in vcnl4000_probe()
1978 mutex_init(&data->vcnl4000_lock); in vcnl4000_probe()
1980 ret = data->chip_spec->init(data); in vcnl4000_probe()
1984 dev_dbg(&client->dev, "%s Ambient light/proximity sensor, Rev: %02x\n", in vcnl4000_probe()
1985 data->chip_spec->prod, data->rev); in vcnl4000_probe()
1987 if (device_property_read_u32(&client->dev, "proximity-near-level", in vcnl4000_probe()
1988 &data->near_level)) in vcnl4000_probe()
1989 data->near_level = 0; in vcnl4000_probe()
1991 indio_dev->info = data->chip_spec->info; in vcnl4000_probe()
1992 indio_dev->channels = data->chip_spec->channels; in vcnl4000_probe()
1993 indio_dev->num_channels = data->chip_spec->num_channels; in vcnl4000_probe()
1994 indio_dev->name = VCNL4000_DRV_NAME; in vcnl4000_probe()
1995 indio_dev->modes = INDIO_DIRECT_MODE; in vcnl4000_probe()
1997 if (data->chip_spec->trig_buffer_func && in vcnl4000_probe()
1998 data->chip_spec->buffer_setup_ops) { in vcnl4000_probe()
1999 ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, in vcnl4000_probe()
2001 data->chip_spec->trig_buffer_func, in vcnl4000_probe()
2002 data->chip_spec->buffer_setup_ops); in vcnl4000_probe()
2004 dev_err(&client->dev, in vcnl4000_probe()
2010 if (client->irq && data->chip_spec->irq_thread) { in vcnl4000_probe()
2011 ret = devm_request_threaded_irq(&client->dev, client->irq, in vcnl4000_probe()
2012 NULL, data->chip_spec->irq_thread, in vcnl4000_probe()
2018 dev_err(&client->dev, "irq request failed\n"); in vcnl4000_probe()
2027 ret = pm_runtime_set_active(&client->dev); in vcnl4000_probe()
2035 pm_runtime_enable(&client->dev); in vcnl4000_probe()
2036 pm_runtime_set_autosuspend_delay(&client->dev, VCNL4000_SLEEP_DELAY_MS); in vcnl4000_probe()
2037 pm_runtime_use_autosuspend(&client->dev); in vcnl4000_probe()
2041 data->chip_spec->set_power_state(data, false); in vcnl4000_probe()
2076 pm_runtime_dont_use_autosuspend(&client->dev); in vcnl4000_remove()
2077 pm_runtime_disable(&client->dev); in vcnl4000_remove()
2079 pm_runtime_set_suspended(&client->dev); in vcnl4000_remove()
2081 ret = data->chip_spec->set_power_state(data, false); in vcnl4000_remove()
2083 dev_warn(&client->dev, "Failed to power down (%pe)\n", in vcnl4000_remove()
2092 return data->chip_spec->set_power_state(data, false); in vcnl4000_runtime_suspend()
2100 return data->chip_spec->set_power_state(data, true); in vcnl4000_runtime_resume()