Lines Matching +full:vled +full:- +full:supply
1 // SPDX-License-Identifier: GPL-2.0-only
6 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
184 static const char reg_vled[] = "Vled";
188 struct i2c_client *client = chip->client; in apds990x_read_byte()
201 struct i2c_client *client = chip->client; in apds990x_read_word()
214 struct i2c_client *client = chip->client; in apds990x_write_byte()
226 struct i2c_client *client = chip->client; in apds990x_write_word()
242 if (chip->prox_en) in apds990x_mode_on()
270 * (count-per-lux) in apds990x_lux_to_threshold()
274 lux = lux * (APDS_CALIB_SCALER / 4) / (chip->lux_calib / 4); in apds990x_lux_to_threshold()
277 cpl = ((u32)chip->atime * (u32)again[chip->again_next] * in apds990x_lux_to_threshold()
278 APDS_PARAM_SCALE * 64) / (chip->cf.ga * chip->cf.df); in apds990x_lux_to_threshold()
286 ir = (u32)chip->lux_ir * (u32)again[chip->again_next] / in apds990x_lux_to_threshold()
287 (u32)again[chip->again_meas]; in apds990x_lux_to_threshold()
293 if (chip->lux_clear * APDS_PARAM_SCALE >= in apds990x_lux_to_threshold()
294 chip->rcf.afactor * chip->lux_ir) in apds990x_lux_to_threshold()
295 thres = (chip->rcf.cf1 * thres + chip->rcf.irf1 * ir) / in apds990x_lux_to_threshold()
298 thres = (chip->rcf.cf2 * thres + chip->rcf.irf2 * ir) / in apds990x_lux_to_threshold()
301 if (thres >= chip->a_max_result) in apds990x_lux_to_threshold()
302 thres = chip->a_max_result - 1; in apds990x_lux_to_threshold()
310 chip->atime = time_ms; in apds990x_set_atime()
312 reg_value = 256 - ((time_ms * TIME_STEP_SCALER) / TIMESTEP); in apds990x_set_atime()
314 chip->a_max_result = (u16)(256 - reg_value) * APDS990X_TIME_TO_ADC; in apds990x_set_atime()
324 if (pm_runtime_suspended(&chip->client->dev)) in apds990x_refresh_pthres()
327 if (data < chip->prox_thres) { in apds990x_refresh_pthres()
329 hi = chip->prox_thres; in apds990x_refresh_pthres()
331 lo = chip->prox_thres - APDS_PROX_HYSTERESIS; in apds990x_refresh_pthres()
332 if (chip->prox_continuous_mode) in apds990x_refresh_pthres()
333 hi = chip->prox_thres; in apds990x_refresh_pthres()
348 if (pm_runtime_suspended(&chip->client->dev)) in apds990x_refresh_athres()
352 apds990x_lux_to_threshold(chip, chip->lux_thres_lo)); in apds990x_refresh_athres()
354 apds990x_lux_to_threshold(chip, chip->lux_thres_hi)); in apds990x_refresh_athres()
371 apds990x_write_word(chip, APDS990X_PILTL, APDS_PROX_DEF_THRES - 1); in apds990x_force_p_refresh()
378 int curr_again = chip->again_meas; in apds990x_calc_again()
379 int next_again = chip->again_meas; in apds990x_calc_again()
383 if (chip->lux_clear == chip->a_max_result) in apds990x_calc_again()
384 next_again -= 2; /* ALS saturated. Decrease gain by 2 steps */ in apds990x_calc_again()
385 else if (chip->lux_clear > chip->a_max_result / 2) in apds990x_calc_again()
386 next_again--; in apds990x_calc_again()
387 else if (chip->lux_clear < APDS_LUX_GAIN_LO_LIMIT_STRICT) in apds990x_calc_again()
389 else if (chip->lux_clear < APDS_LUX_GAIN_LO_LIMIT) in apds990x_calc_again()
399 if (chip->lux_clear == chip->a_max_result) in apds990x_calc_again()
401 ret = -ERANGE; in apds990x_calc_again()
403 chip->lux_clear < APDS_LUX_GAIN_LO_LIMIT_STRICT) in apds990x_calc_again()
408 ret = -ERANGE; in apds990x_calc_again()
410 chip->again_next = next_again; in apds990x_calc_again()
412 (chip->pdrive << 6) | in apds990x_calc_again()
413 (chip->pdiode << 4) | in apds990x_calc_again()
414 (chip->pgain << 2) | in apds990x_calc_again()
415 (chip->again_next << 0)); in apds990x_calc_again()
418 * Error means bad result -> re-measurement is needed. The forced in apds990x_calc_again()
437 * iac1 = CF1 * CLEAR_CH - IRF1 * IR_CH in apds990x_get_lux()
438 * iac2 = CF2 * CLEAR_CH - IRF2 * IR_CH in apds990x_get_lux()
440 iac1 = (chip->cf.cf1 * clear - chip->cf.irf1 * ir) / APDS_PARAM_SCALE; in apds990x_get_lux()
441 iac2 = (chip->cf.cf2 * clear - chip->cf.irf2 * ir) / APDS_PARAM_SCALE; in apds990x_get_lux()
446 lpc = APDS990X_LUX_OUTPUT_SCALE * (chip->cf.df * chip->cf.ga) / in apds990x_get_lux()
447 (u32)(again[chip->again_meas] * (u32)chip->atime); in apds990x_get_lux()
454 struct i2c_client *client = chip->client; in apds990x_ack_int()
482 mutex_lock(&chip->mutex); in apds990x_irq()
483 if (!pm_runtime_suspended(&chip->client->dev)) { in apds990x_irq()
486 &chip->lux_clear); in apds990x_irq()
488 &chip->lux_ir); in apds990x_irq()
490 chip->again_meas = chip->again_next; in apds990x_irq()
492 chip->lux_raw = apds990x_get_lux(chip, in apds990x_irq()
493 chip->lux_clear, in apds990x_irq()
494 chip->lux_ir); in apds990x_irq()
498 chip->lux = chip->lux_raw; in apds990x_irq()
499 chip->lux_wait_fresh_res = false; in apds990x_irq()
500 wake_up(&chip->wait); in apds990x_irq()
501 sysfs_notify(&chip->client->dev.kobj, in apds990x_irq()
506 if ((status & APDS990X_ST_PINT) && chip->prox_en) { in apds990x_irq()
515 if (chip->again_meas == 0 && in apds990x_irq()
516 clr_ch == chip->a_max_result) in apds990x_irq()
517 chip->prox_data = 0; in apds990x_irq()
521 &chip->prox_data); in apds990x_irq()
523 apds990x_refresh_pthres(chip, chip->prox_data); in apds990x_irq()
524 if (chip->prox_data < chip->prox_thres) in apds990x_irq()
525 chip->prox_data = 0; in apds990x_irq()
526 else if (!chip->prox_continuous_mode) in apds990x_irq()
527 chip->prox_data = APDS_PROX_RANGE; in apds990x_irq()
528 sysfs_notify(&chip->client->dev.kobj, in apds990x_irq()
532 mutex_unlock(&chip->mutex); in apds990x_irq()
550 (chip->lux_persistence << APDS990X_APERS_SHIFT) | in apds990x_configure()
551 (chip->prox_persistence << APDS990X_PPERS_SHIFT)); in apds990x_configure()
553 apds990x_write_byte(chip, APDS990X_PPCOUNT, chip->pdata->ppcount); in apds990x_configure()
556 chip->again_meas = 1; in apds990x_configure()
557 chip->again_next = 1; in apds990x_configure()
559 (chip->pdrive << 6) | in apds990x_configure()
560 (chip->pdiode << 4) | in apds990x_configure()
561 (chip->pgain << 2) | in apds990x_configure()
562 (chip->again_next << 0)); in apds990x_configure()
568 struct i2c_client *client = chip->client; in apds990x_detect()
574 dev_err(&client->dev, "ID read failed\n"); in apds990x_detect()
578 ret = apds990x_read_byte(chip, APDS990X_REV, &chip->revision); in apds990x_detect()
580 dev_err(&client->dev, "REV read failed\n"); in apds990x_detect()
588 snprintf(chip->chipname, sizeof(chip->chipname), "APDS-990x"); in apds990x_detect()
591 ret = -ENODEV; in apds990x_detect()
600 int err = regulator_bulk_enable(ARRAY_SIZE(chip->regs), in apds990x_chip_on()
601 chip->regs); in apds990x_chip_on()
608 chip->prox_data = 0; in apds990x_chip_on()
618 regulator_bulk_disable(ARRAY_SIZE(chip->regs), chip->regs); in apds990x_chip_off()
631 return -EIO; in apds990x_lux_show()
633 time_left = wait_event_interruptible_timeout(chip->wait, in apds990x_lux_show()
634 !chip->lux_wait_fresh_res, in apds990x_lux_show()
637 return -EIO; in apds990x_lux_show()
639 mutex_lock(&chip->mutex); in apds990x_lux_show()
640 result = (chip->lux * chip->lux_calib) / APDS_CALIB_SCALER; in apds990x_lux_show()
647 mutex_unlock(&chip->mutex); in apds990x_lux_show()
675 return sprintf(buf, "%u\n", chip->lux_calib); in apds990x_lux_calib_show()
690 chip->lux_calib = value; in apds990x_lux_calib_store()
706 sprintf(buf + pos - 1, "\n"); in apds990x_rate_avail()
715 return sprintf(buf, "%d\n", chip->arate); in apds990x_rate_show()
727 return -EINVAL; in apds990x_set_arate()
730 chip->lux_persistence = apersis[i]; in apds990x_set_arate()
731 chip->arate = arates_hz[i]; in apds990x_set_arate()
734 if (pm_runtime_suspended(&chip->client->dev)) in apds990x_set_arate()
739 (chip->lux_persistence << APDS990X_APERS_SHIFT) | in apds990x_set_arate()
740 (chip->prox_persistence << APDS990X_PPERS_SHIFT)); in apds990x_set_arate()
755 mutex_lock(&chip->mutex); in apds990x_rate_store()
757 mutex_unlock(&chip->mutex); in apds990x_rate_store()
775 if (pm_runtime_suspended(dev) || !chip->prox_en) in apds990x_prox_show()
776 return -EIO; in apds990x_prox_show()
778 mutex_lock(&chip->mutex); in apds990x_prox_show()
779 ret = sprintf(buf, "%d\n", chip->prox_data); in apds990x_prox_show()
780 mutex_unlock(&chip->mutex); in apds990x_prox_show()
799 return sprintf(buf, "%d\n", chip->prox_en); in apds990x_prox_enable_show()
814 mutex_lock(&chip->mutex); in apds990x_prox_enable_store()
816 if (!chip->prox_en) in apds990x_prox_enable_store()
817 chip->prox_data = 0; in apds990x_prox_enable_store()
820 chip->prox_en++; in apds990x_prox_enable_store()
821 else if (chip->prox_en > 0) in apds990x_prox_enable_store()
822 chip->prox_en--; in apds990x_prox_enable_store()
826 mutex_unlock(&chip->mutex); in apds990x_prox_enable_store()
841 reporting_modes[!!chip->prox_continuous_mode]); in apds990x_prox_reporting_mode_show()
855 chip->prox_continuous_mode = ret; in apds990x_prox_reporting_mode_store()
878 return sprintf(buf, "%d\n", chip->lux_thres_hi); in apds990x_lux_thresh_above_show()
886 return sprintf(buf, "%d\n", chip->lux_thres_lo); in apds990x_lux_thresh_below_show()
900 return -EINVAL; in apds990x_set_lux_thresh()
902 mutex_lock(&chip->mutex); in apds990x_set_lux_thresh()
908 if (!chip->lux_wait_fresh_res) in apds990x_set_lux_thresh()
910 mutex_unlock(&chip->mutex); in apds990x_set_lux_thresh()
920 int ret = apds990x_set_lux_thresh(chip, &chip->lux_thres_hi, buf); in apds990x_lux_thresh_above_store()
932 int ret = apds990x_set_lux_thresh(chip, &chip->lux_thres_lo, buf); in apds990x_lux_thresh_below_store()
952 return sprintf(buf, "%d\n", chip->prox_thres); in apds990x_prox_threshold_show()
969 return -EINVAL; in apds990x_prox_threshold_store()
971 mutex_lock(&chip->mutex); in apds990x_prox_threshold_store()
972 chip->prox_thres = value; in apds990x_prox_threshold_store()
975 mutex_unlock(&chip->mutex); in apds990x_prox_threshold_store()
1004 mutex_lock(&chip->mutex); in apds990x_power_state_store()
1005 chip->lux_wait_fresh_res = true; in apds990x_power_state_store()
1008 mutex_unlock(&chip->mutex); in apds990x_power_state_store()
1025 return sprintf(buf, "%s %d\n", chip->chipname, chip->revision); in apds990x_chip_id_show()
1061 return -ENOMEM; in apds990x_probe()
1064 chip->client = client; in apds990x_probe()
1066 init_waitqueue_head(&chip->wait); in apds990x_probe()
1067 mutex_init(&chip->mutex); in apds990x_probe()
1068 chip->pdata = client->dev.platform_data; in apds990x_probe()
1070 if (chip->pdata == NULL) { in apds990x_probe()
1071 dev_err(&client->dev, "platform data is mandatory\n"); in apds990x_probe()
1072 err = -EINVAL; in apds990x_probe()
1076 if (chip->pdata->cf.ga == 0) { in apds990x_probe()
1078 chip->cf.ga = 1966; /* 0.48 * APDS_PARAM_SCALE */ in apds990x_probe()
1079 chip->cf.cf1 = 4096; /* 1.00 * APDS_PARAM_SCALE */ in apds990x_probe()
1080 chip->cf.irf1 = 9134; /* 2.23 * APDS_PARAM_SCALE */ in apds990x_probe()
1081 chip->cf.cf2 = 2867; /* 0.70 * APDS_PARAM_SCALE */ in apds990x_probe()
1082 chip->cf.irf2 = 5816; /* 1.42 * APDS_PARAM_SCALE */ in apds990x_probe()
1083 chip->cf.df = 52; in apds990x_probe()
1085 chip->cf = chip->pdata->cf; in apds990x_probe()
1089 chip->rcf.afactor = in apds990x_probe()
1090 (chip->cf.irf1 - chip->cf.irf2) * APDS_PARAM_SCALE / in apds990x_probe()
1091 (chip->cf.cf1 - chip->cf.cf2); in apds990x_probe()
1092 chip->rcf.cf1 = APDS_PARAM_SCALE * APDS_PARAM_SCALE / in apds990x_probe()
1093 chip->cf.cf1; in apds990x_probe()
1094 chip->rcf.irf1 = chip->cf.irf1 * APDS_PARAM_SCALE / in apds990x_probe()
1095 chip->cf.cf1; in apds990x_probe()
1096 chip->rcf.cf2 = APDS_PARAM_SCALE * APDS_PARAM_SCALE / in apds990x_probe()
1097 chip->cf.cf2; in apds990x_probe()
1098 chip->rcf.irf2 = chip->cf.irf2 * APDS_PARAM_SCALE / in apds990x_probe()
1099 chip->cf.cf2; in apds990x_probe()
1102 chip->lux_thres_hi = APDS_LUX_DEF_THRES_HI; in apds990x_probe()
1103 chip->lux_thres_lo = APDS_LUX_DEF_THRES_LO; in apds990x_probe()
1104 chip->lux_calib = APDS_LUX_NEUTRAL_CALIB_VALUE; in apds990x_probe()
1106 chip->prox_thres = APDS_PROX_DEF_THRES; in apds990x_probe()
1107 chip->pdrive = chip->pdata->pdrive; in apds990x_probe()
1108 chip->pdiode = APDS_PDIODE_IR; in apds990x_probe()
1109 chip->pgain = APDS_PGAIN_1X; in apds990x_probe()
1110 chip->prox_calib = APDS_PROX_NEUTRAL_CALIB_VALUE; in apds990x_probe()
1111 chip->prox_persistence = APDS_DEFAULT_PROX_PERS; in apds990x_probe()
1112 chip->prox_continuous_mode = false; in apds990x_probe()
1114 chip->regs[0].supply = reg_vcc; in apds990x_probe()
1115 chip->regs[1].supply = reg_vled; in apds990x_probe()
1117 err = regulator_bulk_get(&client->dev, in apds990x_probe()
1118 ARRAY_SIZE(chip->regs), chip->regs); in apds990x_probe()
1120 dev_err(&client->dev, "Cannot get regulators\n"); in apds990x_probe()
1124 err = regulator_bulk_enable(ARRAY_SIZE(chip->regs), chip->regs); in apds990x_probe()
1126 dev_err(&client->dev, "Cannot enable regulators\n"); in apds990x_probe()
1134 dev_err(&client->dev, "APDS990X not found\n"); in apds990x_probe()
1138 pm_runtime_set_active(&client->dev); in apds990x_probe()
1144 pm_runtime_enable(&client->dev); in apds990x_probe()
1146 if (chip->pdata->setup_resources) { in apds990x_probe()
1147 err = chip->pdata->setup_resources(); in apds990x_probe()
1149 err = -EINVAL; in apds990x_probe()
1154 err = sysfs_create_group(&chip->client->dev.kobj, in apds990x_probe()
1157 dev_err(&chip->client->dev, "Sysfs registration failed\n"); in apds990x_probe()
1161 err = request_threaded_irq(client->irq, NULL, in apds990x_probe()
1167 dev_err(&client->dev, "could not get IRQ %d\n", in apds990x_probe()
1168 client->irq); in apds990x_probe()
1173 sysfs_remove_group(&chip->client->dev.kobj, in apds990x_probe()
1176 if (chip->pdata && chip->pdata->release_resources) in apds990x_probe()
1177 chip->pdata->release_resources(); in apds990x_probe()
1179 regulator_bulk_disable(ARRAY_SIZE(chip->regs), chip->regs); in apds990x_probe()
1181 regulator_bulk_free(ARRAY_SIZE(chip->regs), chip->regs); in apds990x_probe()
1191 free_irq(client->irq, chip); in apds990x_remove()
1192 sysfs_remove_group(&chip->client->dev.kobj, in apds990x_remove()
1195 if (chip->pdata && chip->pdata->release_resources) in apds990x_remove()
1196 chip->pdata->release_resources(); in apds990x_remove()
1198 if (!pm_runtime_suspended(&client->dev)) in apds990x_remove()
1201 pm_runtime_disable(&client->dev); in apds990x_remove()
1202 pm_runtime_set_suspended(&client->dev); in apds990x_remove()
1204 regulator_bulk_free(ARRAY_SIZE(chip->regs), chip->regs); in apds990x_remove()