Lines Matching +full:ch0 +full:- +full:2

1 // SPDX-License-Identifier: GPL-2.0-only
41 #define CALIB_FRAC_HALF (1 << (CALIB_FRAC_BITS - 1))
52 #define TSL2563_REG_LOWLOW 0x02 /* data0 low threshold, 2 bytes */
54 #define TSL2563_REG_HIGHLOW 0x04 /* data0 high threshold, 2 bytes */
58 #define TSL2563_REG_DATA0LOW 0x0c /* broadband sensor value, 2 bytes */
60 #define TSL2563_REG_DATA1LOW 0x0e /* infrared sensor value, 2 bytes */
131 struct i2c_client *client = chip->client; in tsl2563_set_power()
145 struct i2c_client *client = chip->client; in tsl2563_get_power()
159 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure()
161 chip->gainlevel->gaintime); in tsl2563_configure()
164 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure()
166 chip->high_thres & 0xFF); in tsl2563_configure()
169 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure()
171 (chip->high_thres >> 8) & 0xFF); in tsl2563_configure()
174 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure()
176 chip->low_thres & 0xFF); in tsl2563_configure()
179 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure()
181 (chip->low_thres >> 8) & 0xFF); in tsl2563_configure()
209 return ret ? 0 : -ENODEV; in tsl2563_detect()
214 struct i2c_client *client = chip->client; in tsl2563_read_id()
241 shift += 2; in tsl2563_adc_shiftbits()
244 /* no-op */ in tsl2563_adc_shiftbits()
264 switch (chip->gainlevel->gaintime & TSL2563_TIMING_MASK) { in tsl2563_wait_adc()
278 schedule_timeout_interruptible(msecs_to_jiffies(delay) + 2); in tsl2563_wait_adc()
283 struct i2c_client *client = chip->client; in tsl2563_adjust_gainlevel()
285 if (adc > chip->gainlevel->max || adc < chip->gainlevel->min) { in tsl2563_adjust_gainlevel()
287 (adc > chip->gainlevel->max) ? in tsl2563_adjust_gainlevel()
288 chip->gainlevel++ : chip->gainlevel--; in tsl2563_adjust_gainlevel()
292 chip->gainlevel->gaintime); in tsl2563_adjust_gainlevel()
304 struct i2c_client *client = chip->client; in tsl2563_get_adc()
309 if (chip->suspended) in tsl2563_get_adc()
312 if (!chip->int_enabled) { in tsl2563_get_adc()
313 cancel_delayed_work(&chip->poweroff_work); in tsl2563_get_adc()
342 chip->data0 = tsl2563_normalize_adc(adc0, chip->gainlevel->gaintime); in tsl2563_get_adc()
343 chip->data1 = tsl2563_normalize_adc(adc1, chip->gainlevel->gaintime); in tsl2563_get_adc()
345 if (!chip->int_enabled) in tsl2563_get_adc()
346 schedule_delayed_work(&chip->poweroff_work, 5 * HZ); in tsl2563_get_adc()
367 * The basic formula is lux = c0 * adc0 - c1 * adc1, where c0 and c1 are
421 unsigned long ratio, lux, ch0 = adc0, ch1 = adc1; in tsl2563_adc_to_lux() local
423 ratio = ch0 ? ((ch1 << ADC_FRAC_BITS) / ch0) : ULONG_MAX; in tsl2563_adc_to_lux()
425 while (lp->ch_ratio < ratio) in tsl2563_adc_to_lux()
428 lux = ch0 * lp->ch0_coeff - ch1 * lp->ch1_coeff; in tsl2563_adc_to_lux()
453 return -EINVAL; in tsl2563_write_raw()
454 if (chan->channel2 == IIO_MOD_LIGHT_BOTH) in tsl2563_write_raw()
455 chip->calib0 = tsl2563_calib_from_sysfs(val); in tsl2563_write_raw()
456 else if (chan->channel2 == IIO_MOD_LIGHT_IR) in tsl2563_write_raw()
457 chip->calib1 = tsl2563_calib_from_sysfs(val); in tsl2563_write_raw()
459 return -EINVAL; in tsl2563_write_raw()
470 int ret = -EINVAL; in tsl2563_read_raw()
474 mutex_lock(&chip->lock); in tsl2563_read_raw()
478 switch (chan->type) { in tsl2563_read_raw()
483 calib0 = tsl2563_calib_adc(chip->data0, chip->calib0) * in tsl2563_read_raw()
484 chip->cover_comp_gain; in tsl2563_read_raw()
485 calib1 = tsl2563_calib_adc(chip->data1, chip->calib1) * in tsl2563_read_raw()
486 chip->cover_comp_gain; in tsl2563_read_raw()
494 if (chan->channel2 == IIO_MOD_LIGHT_BOTH) in tsl2563_read_raw()
495 *val = chip->data0; in tsl2563_read_raw()
497 *val = chip->data1; in tsl2563_read_raw()
506 if (chan->channel2 == IIO_MOD_LIGHT_BOTH) in tsl2563_read_raw()
507 *val = tsl2563_calib_to_sysfs(chip->calib0); in tsl2563_read_raw()
509 *val = tsl2563_calib_to_sysfs(chip->calib1); in tsl2563_read_raw()
513 ret = -EINVAL; in tsl2563_read_raw()
518 mutex_unlock(&chip->lock); in tsl2563_read_raw()
568 *val = chip->high_thres; in tsl2563_read_thresh()
571 *val = chip->low_thres; in tsl2563_read_thresh()
574 return -EINVAL; in tsl2563_read_thresh()
593 mutex_lock(&chip->lock); in tsl2563_write_thresh()
594 ret = i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | address, in tsl2563_write_thresh()
598 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_write_thresh()
602 chip->high_thres = val; in tsl2563_write_thresh()
604 chip->low_thres = val; in tsl2563_write_thresh()
607 mutex_unlock(&chip->lock); in tsl2563_write_thresh()
625 i2c_smbus_write_byte(chip->client, TSL2563_CMD | TSL2563_CLEARINT); in tsl2563_event_handler()
636 mutex_lock(&chip->lock); in tsl2563_write_interrupt_config()
637 if (state && !(chip->intr & 0x30)) { in tsl2563_write_interrupt_config()
638 chip->intr &= ~0x30; in tsl2563_write_interrupt_config()
639 chip->intr |= 0x10; in tsl2563_write_interrupt_config()
641 cancel_delayed_work(&chip->poweroff_work); in tsl2563_write_interrupt_config()
650 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_write_interrupt_config()
652 chip->intr); in tsl2563_write_interrupt_config()
653 chip->int_enabled = true; in tsl2563_write_interrupt_config()
656 if (!state && (chip->intr & 0x30)) { in tsl2563_write_interrupt_config()
657 chip->intr &= ~0x30; in tsl2563_write_interrupt_config()
658 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_write_interrupt_config()
660 chip->intr); in tsl2563_write_interrupt_config()
661 chip->int_enabled = false; in tsl2563_write_interrupt_config()
663 schedule_delayed_work(&chip->poweroff_work, 5 * HZ); in tsl2563_write_interrupt_config()
666 mutex_unlock(&chip->lock); in tsl2563_write_interrupt_config()
678 mutex_lock(&chip->lock); in tsl2563_read_interrupt_config()
679 ret = i2c_smbus_read_byte_data(chip->client, in tsl2563_read_interrupt_config()
681 mutex_unlock(&chip->lock); in tsl2563_read_interrupt_config()
707 struct tsl2563_platform_data *pdata = client->dev.platform_data; in tsl2563_probe()
711 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); in tsl2563_probe()
713 return -ENOMEM; in tsl2563_probe()
718 chip->client = client; in tsl2563_probe()
722 dev_err(&client->dev, "detect error %d\n", -err); in tsl2563_probe()
728 dev_err(&client->dev, "read id error %d\n", -err); in tsl2563_probe()
732 mutex_init(&chip->lock); in tsl2563_probe()
735 chip->low_thres = 0x0; in tsl2563_probe()
736 chip->high_thres = 0xffff; in tsl2563_probe()
737 chip->gainlevel = tsl2563_gainlevel_table; in tsl2563_probe()
738 chip->intr = TSL2563_INT_PERSIST(4); in tsl2563_probe()
739 chip->calib0 = tsl2563_calib_from_sysfs(CALIB_BASE_SYSFS); in tsl2563_probe()
740 chip->calib1 = tsl2563_calib_from_sysfs(CALIB_BASE_SYSFS); in tsl2563_probe()
743 chip->cover_comp_gain = pdata->cover_comp_gain; in tsl2563_probe()
745 err = device_property_read_u32(&client->dev, "amstaos,cover-comp-gain", in tsl2563_probe()
746 &chip->cover_comp_gain); in tsl2563_probe()
748 chip->cover_comp_gain = 1; in tsl2563_probe()
751 dev_info(&client->dev, "model %d, rev. %d\n", id >> 4, id & 0x0f); in tsl2563_probe()
752 indio_dev->name = client->name; in tsl2563_probe()
753 indio_dev->channels = tsl2563_channels; in tsl2563_probe()
754 indio_dev->num_channels = ARRAY_SIZE(tsl2563_channels); in tsl2563_probe()
755 indio_dev->modes = INDIO_DIRECT_MODE; in tsl2563_probe()
757 if (client->irq) in tsl2563_probe()
758 indio_dev->info = &tsl2563_info; in tsl2563_probe()
760 indio_dev->info = &tsl2563_info_no_irq; in tsl2563_probe()
762 if (client->irq) { in tsl2563_probe()
763 err = devm_request_threaded_irq(&client->dev, client->irq, in tsl2563_probe()
770 dev_err(&client->dev, "irq request error %d\n", -err); in tsl2563_probe()
777 dev_err(&client->dev, "configure error %d\n", -err); in tsl2563_probe()
781 INIT_DELAYED_WORK(&chip->poweroff_work, tsl2563_poweroff_work); in tsl2563_probe()
784 schedule_delayed_work(&chip->poweroff_work, 5 * HZ); in tsl2563_probe()
788 dev_err(&client->dev, "iio registration error %d\n", -err); in tsl2563_probe()
795 cancel_delayed_work_sync(&chip->poweroff_work); in tsl2563_probe()
805 if (!chip->int_enabled) in tsl2563_remove()
806 cancel_delayed_work(&chip->poweroff_work); in tsl2563_remove()
807 /* Ensure that interrupts are disabled - then flush any bottom halves */ in tsl2563_remove()
808 chip->intr &= ~0x30; in tsl2563_remove()
809 i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | TSL2563_REG_INT, in tsl2563_remove()
810 chip->intr); in tsl2563_remove()
824 mutex_lock(&chip->lock); in tsl2563_suspend()
830 chip->suspended = true; in tsl2563_suspend()
833 mutex_unlock(&chip->lock); in tsl2563_suspend()
843 mutex_lock(&chip->lock); in tsl2563_resume()
853 chip->suspended = false; in tsl2563_resume()
856 mutex_unlock(&chip->lock); in tsl2563_resume()
869 { "tsl2562", 2 },