Lines Matching +full:cover +full:- +full:comp +full:- +full:gain

1 // SPDX-License-Identifier: GPL-2.0-only
125 struct i2c_client *client = chip->client; in tsl2563_set_power()
139 struct i2c_client *client = chip->client; in tsl2563_get_power()
153 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure()
155 chip->gainlevel->gaintime); in tsl2563_configure()
158 ret = i2c_smbus_write_word_data(chip->client, in tsl2563_configure()
160 chip->high_thres); in tsl2563_configure()
163 ret = i2c_smbus_write_word_data(chip->client, in tsl2563_configure()
165 chip->low_thres); in tsl2563_configure()
195 return ret ? 0 : -ENODEV; in tsl2563_detect()
200 struct i2c_client *client = chip->client; in tsl2563_read_id()
216 chip->intr &= ~TSL2563_INT_MASK; in tsl2563_configure_irq()
218 chip->intr |= TSL2563_INT_LEVEL; in tsl2563_configure_irq()
220 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure_irq()
222 chip->intr); in tsl2563_configure_irq()
226 chip->int_enabled = enable; in tsl2563_configure_irq()
232 * 16x gain. This function returns the number of bits of shift needed to
234 * timing and gain settings.
248 /* no-op */ in tsl2563_adc_shiftbits()
268 switch (chip->gainlevel->gaintime & TSL2563_TIMING_MASK) { in tsl2563_wait_adc()
287 struct i2c_client *client = chip->client; in tsl2563_adjust_gainlevel()
289 if (adc > chip->gainlevel->max || adc < chip->gainlevel->min) { in tsl2563_adjust_gainlevel()
291 (adc > chip->gainlevel->max) ? in tsl2563_adjust_gainlevel()
292 chip->gainlevel++ : chip->gainlevel--; in tsl2563_adjust_gainlevel()
296 chip->gainlevel->gaintime); in tsl2563_adjust_gainlevel()
308 struct i2c_client *client = chip->client; in tsl2563_get_adc()
313 if (chip->suspended) in tsl2563_get_adc()
316 if (!chip->int_enabled) { in tsl2563_get_adc()
317 cancel_delayed_work_sync(&chip->poweroff_work); in tsl2563_get_adc()
346 chip->data0 = tsl2563_normalize_adc(adc0, chip->gainlevel->gaintime); in tsl2563_get_adc()
347 chip->data1 = tsl2563_normalize_adc(adc1, chip->gainlevel->gaintime); in tsl2563_get_adc()
349 if (!chip->int_enabled) in tsl2563_get_adc()
350 schedule_delayed_work(&chip->poweroff_work, 5 * HZ); in tsl2563_get_adc()
371 * The basic formula is lux = c0 * adc0 - c1 * adc1, where c0 and c1 are
429 while (lp->ch_ratio < ratio) in tsl2563_adc_to_lux()
432 lux = ch0 * lp->ch0_coeff - ch1 * lp->ch1_coeff; in tsl2563_adc_to_lux()
457 return -EINVAL; in tsl2563_write_raw()
458 if (chan->channel2 == IIO_MOD_LIGHT_BOTH) in tsl2563_write_raw()
459 chip->calib0 = tsl2563_calib_from_sysfs(val); in tsl2563_write_raw()
460 else if (chan->channel2 == IIO_MOD_LIGHT_IR) in tsl2563_write_raw()
461 chip->calib1 = tsl2563_calib_from_sysfs(val); in tsl2563_write_raw()
463 return -EINVAL; in tsl2563_write_raw()
474 int ret = -EINVAL; in tsl2563_read_raw()
478 mutex_lock(&chip->lock); in tsl2563_read_raw()
482 switch (chan->type) { in tsl2563_read_raw()
487 calib0 = tsl2563_calib_adc(chip->data0, chip->calib0) * in tsl2563_read_raw()
488 chip->cover_comp_gain; in tsl2563_read_raw()
489 calib1 = tsl2563_calib_adc(chip->data1, chip->calib1) * in tsl2563_read_raw()
490 chip->cover_comp_gain; in tsl2563_read_raw()
498 if (chan->channel2 == IIO_MOD_LIGHT_BOTH) in tsl2563_read_raw()
499 *val = chip->data0; in tsl2563_read_raw()
501 *val = chip->data1; in tsl2563_read_raw()
510 if (chan->channel2 == IIO_MOD_LIGHT_BOTH) in tsl2563_read_raw()
511 *val = tsl2563_calib_to_sysfs(chip->calib0); in tsl2563_read_raw()
513 *val = tsl2563_calib_to_sysfs(chip->calib1); in tsl2563_read_raw()
517 ret = -EINVAL; in tsl2563_read_raw()
522 mutex_unlock(&chip->lock); in tsl2563_read_raw()
572 *val = chip->high_thres; in tsl2563_read_thresh()
575 *val = chip->low_thres; in tsl2563_read_thresh()
578 return -EINVAL; in tsl2563_read_thresh()
592 mutex_lock(&chip->lock); in tsl2563_write_thresh()
595 ret = i2c_smbus_write_word_data(chip->client, in tsl2563_write_thresh()
598 ret = i2c_smbus_write_word_data(chip->client, in tsl2563_write_thresh()
604 chip->high_thres = val; in tsl2563_write_thresh()
606 chip->low_thres = val; in tsl2563_write_thresh()
609 mutex_unlock(&chip->lock); in tsl2563_write_thresh()
627 i2c_smbus_write_byte(chip->client, TSL2563_CMD | TSL2563_CLEARINT); in tsl2563_event_handler()
638 mutex_lock(&chip->lock); in tsl2563_write_interrupt_config()
639 if (state && !(chip->intr & TSL2563_INT_MASK)) { in tsl2563_write_interrupt_config()
641 cancel_delayed_work_sync(&chip->poweroff_work); in tsl2563_write_interrupt_config()
653 if (!state && (chip->intr & TSL2563_INT_MASK)) { in tsl2563_write_interrupt_config()
656 schedule_delayed_work(&chip->poweroff_work, 5 * HZ); in tsl2563_write_interrupt_config()
659 mutex_unlock(&chip->lock); in tsl2563_write_interrupt_config()
671 mutex_lock(&chip->lock); in tsl2563_read_interrupt_config()
672 ret = i2c_smbus_read_byte_data(chip->client, in tsl2563_read_interrupt_config()
674 mutex_unlock(&chip->lock); in tsl2563_read_interrupt_config()
697 struct device *dev = &client->dev; in tsl2563_probe()
706 return -ENOMEM; in tsl2563_probe()
711 chip->client = client; in tsl2563_probe()
721 mutex_init(&chip->lock); in tsl2563_probe()
724 chip->low_thres = 0x0; in tsl2563_probe()
725 chip->high_thres = 0xffff; in tsl2563_probe()
726 chip->gainlevel = tsl2563_gainlevel_table; in tsl2563_probe()
727 chip->intr = TSL2563_INT_PERSIST(4); in tsl2563_probe()
728 chip->calib0 = tsl2563_calib_from_sysfs(CALIB_BASE_SYSFS); in tsl2563_probe()
729 chip->calib1 = tsl2563_calib_from_sysfs(CALIB_BASE_SYSFS); in tsl2563_probe()
731 chip->cover_comp_gain = 1; in tsl2563_probe()
732 device_property_read_u32(dev, "amstaos,cover-comp-gain", &chip->cover_comp_gain); in tsl2563_probe()
735 indio_dev->name = client->name; in tsl2563_probe()
736 indio_dev->channels = tsl2563_channels; in tsl2563_probe()
737 indio_dev->num_channels = ARRAY_SIZE(tsl2563_channels); in tsl2563_probe()
738 indio_dev->modes = INDIO_DIRECT_MODE; in tsl2563_probe()
740 if (client->irq) in tsl2563_probe()
741 indio_dev->info = &tsl2563_info; in tsl2563_probe()
743 indio_dev->info = &tsl2563_info_no_irq; in tsl2563_probe()
745 if (client->irq) { in tsl2563_probe()
746 irq_flags = irq_get_trigger_type(client->irq); in tsl2563_probe()
751 err = devm_request_threaded_irq(dev, client->irq, in tsl2563_probe()
765 INIT_DELAYED_WORK(&chip->poweroff_work, tsl2563_poweroff_work); in tsl2563_probe()
768 schedule_delayed_work(&chip->poweroff_work, 5 * HZ); in tsl2563_probe()
779 cancel_delayed_work_sync(&chip->poweroff_work); in tsl2563_probe()
789 if (!chip->int_enabled) in tsl2563_remove()
790 cancel_delayed_work_sync(&chip->poweroff_work); in tsl2563_remove()
791 /* Ensure that interrupts are disabled - then flush any bottom halves */ in tsl2563_remove()
802 mutex_lock(&chip->lock); in tsl2563_suspend()
808 chip->suspended = true; in tsl2563_suspend()
811 mutex_unlock(&chip->lock); in tsl2563_suspend()
821 mutex_lock(&chip->lock); in tsl2563_resume()
831 chip->suspended = false; in tsl2563_resume()
834 mutex_unlock(&chip->lock); in tsl2563_resume()