Lines Matching +full:cover +full:- +full:comp +full:- +full:gain
1 // SPDX-License-Identifier: GPL-2.0-only
39 #define CALIB_FRAC_HALF (1 << (CALIB_FRAC_BITS - 1))
129 struct i2c_client *client = chip->client; in tsl2563_set_power()
143 struct i2c_client *client = chip->client; in tsl2563_get_power()
157 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure()
159 chip->gainlevel->gaintime); in tsl2563_configure()
162 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure()
164 chip->high_thres & 0xFF); in tsl2563_configure()
167 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure()
169 (chip->high_thres >> 8) & 0xFF); in tsl2563_configure()
172 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure()
174 chip->low_thres & 0xFF); in tsl2563_configure()
177 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure()
179 (chip->low_thres >> 8) & 0xFF); in tsl2563_configure()
207 return ret ? 0 : -ENODEV; in tsl2563_detect()
212 struct i2c_client *client = chip->client; in tsl2563_read_id()
226 * 16x gain. This function returns the number of bits of shift needed to
228 * timing and gain settings.
242 /* no-op */ in tsl2563_adc_shiftbits()
262 switch (chip->gainlevel->gaintime & TSL2563_TIMING_MASK) { in tsl2563_wait_adc()
281 struct i2c_client *client = chip->client; in tsl2563_adjust_gainlevel()
283 if (adc > chip->gainlevel->max || adc < chip->gainlevel->min) { in tsl2563_adjust_gainlevel()
285 (adc > chip->gainlevel->max) ? in tsl2563_adjust_gainlevel()
286 chip->gainlevel++ : chip->gainlevel--; in tsl2563_adjust_gainlevel()
290 chip->gainlevel->gaintime); in tsl2563_adjust_gainlevel()
302 struct i2c_client *client = chip->client; in tsl2563_get_adc()
307 if (chip->suspended) in tsl2563_get_adc()
310 if (!chip->int_enabled) { in tsl2563_get_adc()
311 cancel_delayed_work(&chip->poweroff_work); in tsl2563_get_adc()
340 chip->data0 = tsl2563_normalize_adc(adc0, chip->gainlevel->gaintime); in tsl2563_get_adc()
341 chip->data1 = tsl2563_normalize_adc(adc1, chip->gainlevel->gaintime); in tsl2563_get_adc()
343 if (!chip->int_enabled) in tsl2563_get_adc()
344 schedule_delayed_work(&chip->poweroff_work, 5 * HZ); in tsl2563_get_adc()
365 * The basic formula is lux = c0 * adc0 - c1 * adc1, where c0 and c1 are
423 while (lp->ch_ratio < ratio) in tsl2563_adc_to_lux()
426 lux = ch0 * lp->ch0_coeff - ch1 * lp->ch1_coeff; in tsl2563_adc_to_lux()
451 return -EINVAL; in tsl2563_write_raw()
452 if (chan->channel2 == IIO_MOD_LIGHT_BOTH) in tsl2563_write_raw()
453 chip->calib0 = tsl2563_calib_from_sysfs(val); in tsl2563_write_raw()
454 else if (chan->channel2 == IIO_MOD_LIGHT_IR) in tsl2563_write_raw()
455 chip->calib1 = tsl2563_calib_from_sysfs(val); in tsl2563_write_raw()
457 return -EINVAL; in tsl2563_write_raw()
468 int ret = -EINVAL; in tsl2563_read_raw()
472 mutex_lock(&chip->lock); in tsl2563_read_raw()
476 switch (chan->type) { in tsl2563_read_raw()
481 calib0 = tsl2563_calib_adc(chip->data0, chip->calib0) * in tsl2563_read_raw()
482 chip->cover_comp_gain; in tsl2563_read_raw()
483 calib1 = tsl2563_calib_adc(chip->data1, chip->calib1) * in tsl2563_read_raw()
484 chip->cover_comp_gain; in tsl2563_read_raw()
492 if (chan->channel2 == IIO_MOD_LIGHT_BOTH) in tsl2563_read_raw()
493 *val = chip->data0; in tsl2563_read_raw()
495 *val = chip->data1; in tsl2563_read_raw()
504 if (chan->channel2 == IIO_MOD_LIGHT_BOTH) in tsl2563_read_raw()
505 *val = tsl2563_calib_to_sysfs(chip->calib0); in tsl2563_read_raw()
507 *val = tsl2563_calib_to_sysfs(chip->calib1); in tsl2563_read_raw()
511 ret = -EINVAL; in tsl2563_read_raw()
516 mutex_unlock(&chip->lock); in tsl2563_read_raw()
566 *val = chip->high_thres; in tsl2563_read_thresh()
569 *val = chip->low_thres; in tsl2563_read_thresh()
572 return -EINVAL; in tsl2563_read_thresh()
591 mutex_lock(&chip->lock); in tsl2563_write_thresh()
592 ret = i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | address, in tsl2563_write_thresh()
596 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_write_thresh()
600 chip->high_thres = val; in tsl2563_write_thresh()
602 chip->low_thres = val; in tsl2563_write_thresh()
605 mutex_unlock(&chip->lock); in tsl2563_write_thresh()
623 i2c_smbus_write_byte(chip->client, TSL2563_CMD | TSL2563_CLEARINT); in tsl2563_event_handler()
634 mutex_lock(&chip->lock); in tsl2563_write_interrupt_config()
635 if (state && !(chip->intr & 0x30)) { in tsl2563_write_interrupt_config()
636 chip->intr &= ~0x30; in tsl2563_write_interrupt_config()
637 chip->intr |= 0x10; in tsl2563_write_interrupt_config()
639 cancel_delayed_work(&chip->poweroff_work); in tsl2563_write_interrupt_config()
648 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_write_interrupt_config()
650 chip->intr); in tsl2563_write_interrupt_config()
651 chip->int_enabled = true; in tsl2563_write_interrupt_config()
654 if (!state && (chip->intr & 0x30)) { in tsl2563_write_interrupt_config()
655 chip->intr &= ~0x30; in tsl2563_write_interrupt_config()
656 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_write_interrupt_config()
658 chip->intr); in tsl2563_write_interrupt_config()
659 chip->int_enabled = false; in tsl2563_write_interrupt_config()
661 schedule_delayed_work(&chip->poweroff_work, 5 * HZ); in tsl2563_write_interrupt_config()
664 mutex_unlock(&chip->lock); in tsl2563_write_interrupt_config()
676 mutex_lock(&chip->lock); in tsl2563_read_interrupt_config()
677 ret = i2c_smbus_read_byte_data(chip->client, in tsl2563_read_interrupt_config()
679 mutex_unlock(&chip->lock); in tsl2563_read_interrupt_config()
705 struct tsl2563_platform_data *pdata = client->dev.platform_data; in tsl2563_probe()
706 struct device_node *np = client->dev.of_node; in tsl2563_probe()
710 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); in tsl2563_probe()
712 return -ENOMEM; in tsl2563_probe()
717 chip->client = client; in tsl2563_probe()
721 dev_err(&client->dev, "detect error %d\n", -err); in tsl2563_probe()
727 dev_err(&client->dev, "read id error %d\n", -err); in tsl2563_probe()
731 mutex_init(&chip->lock); in tsl2563_probe()
734 chip->low_thres = 0x0; in tsl2563_probe()
735 chip->high_thres = 0xffff; in tsl2563_probe()
736 chip->gainlevel = tsl2563_gainlevel_table; in tsl2563_probe()
737 chip->intr = TSL2563_INT_PERSIST(4); in tsl2563_probe()
738 chip->calib0 = tsl2563_calib_from_sysfs(CALIB_BASE_SYSFS); in tsl2563_probe()
739 chip->calib1 = tsl2563_calib_from_sysfs(CALIB_BASE_SYSFS); in tsl2563_probe()
742 chip->cover_comp_gain = pdata->cover_comp_gain; in tsl2563_probe()
744 of_property_read_u32(np, "amstaos,cover-comp-gain", in tsl2563_probe()
745 &chip->cover_comp_gain); in tsl2563_probe()
747 chip->cover_comp_gain = 1; in tsl2563_probe()
749 dev_info(&client->dev, "model %d, rev. %d\n", id >> 4, id & 0x0f); in tsl2563_probe()
750 indio_dev->name = client->name; in tsl2563_probe()
751 indio_dev->channels = tsl2563_channels; in tsl2563_probe()
752 indio_dev->num_channels = ARRAY_SIZE(tsl2563_channels); in tsl2563_probe()
753 indio_dev->modes = INDIO_DIRECT_MODE; in tsl2563_probe()
755 if (client->irq) in tsl2563_probe()
756 indio_dev->info = &tsl2563_info; in tsl2563_probe()
758 indio_dev->info = &tsl2563_info_no_irq; in tsl2563_probe()
760 if (client->irq) { in tsl2563_probe()
761 err = devm_request_threaded_irq(&client->dev, client->irq, in tsl2563_probe()
768 dev_err(&client->dev, "irq request error %d\n", -err); in tsl2563_probe()
775 dev_err(&client->dev, "configure error %d\n", -err); in tsl2563_probe()
779 INIT_DELAYED_WORK(&chip->poweroff_work, tsl2563_poweroff_work); in tsl2563_probe()
782 schedule_delayed_work(&chip->poweroff_work, 5 * HZ); in tsl2563_probe()
786 dev_err(&client->dev, "iio registration error %d\n", -err); in tsl2563_probe()
793 cancel_delayed_work_sync(&chip->poweroff_work); in tsl2563_probe()
803 if (!chip->int_enabled) in tsl2563_remove()
804 cancel_delayed_work(&chip->poweroff_work); in tsl2563_remove()
805 /* Ensure that interrupts are disabled - then flush any bottom halves */ in tsl2563_remove()
806 chip->intr &= ~0x30; in tsl2563_remove()
807 i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | TSL2563_REG_INT, in tsl2563_remove()
808 chip->intr); in tsl2563_remove()
822 mutex_lock(&chip->lock); in tsl2563_suspend()
828 chip->suspended = true; in tsl2563_suspend()
831 mutex_unlock(&chip->lock); in tsl2563_suspend()
841 mutex_lock(&chip->lock); in tsl2563_resume()
851 chip->suspended = false; in tsl2563_resume()
854 mutex_unlock(&chip->lock); in tsl2563_resume()