Lines Matching refs:chip
140 static int tsl2563_set_power(struct tsl2563_chip *chip, int on) in tsl2563_set_power() argument
142 struct i2c_client *client = chip->client; in tsl2563_set_power()
154 static int tsl2563_get_power(struct tsl2563_chip *chip) in tsl2563_get_power() argument
156 struct i2c_client *client = chip->client; in tsl2563_get_power()
166 static int tsl2563_configure(struct tsl2563_chip *chip) in tsl2563_configure() argument
170 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure()
172 chip->gainlevel->gaintime); in tsl2563_configure()
175 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure()
177 chip->high_thres & 0xFF); in tsl2563_configure()
180 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure()
182 (chip->high_thres >> 8) & 0xFF); in tsl2563_configure()
185 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure()
187 chip->low_thres & 0xFF); in tsl2563_configure()
190 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_configure()
192 (chip->low_thres >> 8) & 0xFF); in tsl2563_configure()
203 struct tsl2563_chip *chip = in tsl2563_poweroff_work() local
205 tsl2563_set_power(chip, 0); in tsl2563_poweroff_work()
208 static int tsl2563_detect(struct tsl2563_chip *chip) in tsl2563_detect() argument
212 ret = tsl2563_set_power(chip, 1); in tsl2563_detect()
216 ret = tsl2563_get_power(chip); in tsl2563_detect()
223 static int tsl2563_read_id(struct tsl2563_chip *chip, u8 *id) in tsl2563_read_id() argument
225 struct i2c_client *client = chip->client; in tsl2563_read_id()
271 static void tsl2563_wait_adc(struct tsl2563_chip *chip) in tsl2563_wait_adc() argument
275 switch (chip->gainlevel->gaintime & TSL2563_TIMING_MASK) { in tsl2563_wait_adc()
292 static int tsl2563_adjust_gainlevel(struct tsl2563_chip *chip, u16 adc) in tsl2563_adjust_gainlevel() argument
294 struct i2c_client *client = chip->client; in tsl2563_adjust_gainlevel()
296 if (adc > chip->gainlevel->max || adc < chip->gainlevel->min) { in tsl2563_adjust_gainlevel()
298 (adc > chip->gainlevel->max) ? in tsl2563_adjust_gainlevel()
299 chip->gainlevel++ : chip->gainlevel--; in tsl2563_adjust_gainlevel()
303 chip->gainlevel->gaintime); in tsl2563_adjust_gainlevel()
305 tsl2563_wait_adc(chip); in tsl2563_adjust_gainlevel()
306 tsl2563_wait_adc(chip); in tsl2563_adjust_gainlevel()
313 static int tsl2563_get_adc(struct tsl2563_chip *chip) in tsl2563_get_adc() argument
315 struct i2c_client *client = chip->client; in tsl2563_get_adc()
320 if (chip->suspended) in tsl2563_get_adc()
323 if (!chip->int_enabled) { in tsl2563_get_adc()
324 cancel_delayed_work(&chip->poweroff_work); in tsl2563_get_adc()
326 if (!tsl2563_get_power(chip)) { in tsl2563_get_adc()
327 ret = tsl2563_set_power(chip, 1); in tsl2563_get_adc()
330 ret = tsl2563_configure(chip); in tsl2563_get_adc()
333 tsl2563_wait_adc(chip); in tsl2563_get_adc()
350 retry = tsl2563_adjust_gainlevel(chip, adc0); in tsl2563_get_adc()
353 chip->data0 = normalize_adc(adc0, chip->gainlevel->gaintime); in tsl2563_get_adc()
354 chip->data1 = normalize_adc(adc1, chip->gainlevel->gaintime); in tsl2563_get_adc()
356 if (!chip->int_enabled) in tsl2563_get_adc()
357 schedule_delayed_work(&chip->poweroff_work, 5 * HZ); in tsl2563_get_adc()
461 struct tsl2563_chip *chip = iio_priv(indio_dev); in tsl2563_write_raw() local
466 chip->calib0 = calib_from_sysfs(val); in tsl2563_write_raw()
468 chip->calib1 = calib_from_sysfs(val); in tsl2563_write_raw()
483 struct tsl2563_chip *chip = iio_priv(indio_dev); in tsl2563_read_raw() local
485 mutex_lock(&chip->lock); in tsl2563_read_raw()
491 ret = tsl2563_get_adc(chip); in tsl2563_read_raw()
494 calib0 = calib_adc(chip->data0, chip->calib0) * in tsl2563_read_raw()
495 chip->cover_comp_gain; in tsl2563_read_raw()
496 calib1 = calib_adc(chip->data1, chip->calib1) * in tsl2563_read_raw()
497 chip->cover_comp_gain; in tsl2563_read_raw()
502 ret = tsl2563_get_adc(chip); in tsl2563_read_raw()
506 *val = chip->data0; in tsl2563_read_raw()
508 *val = chip->data1; in tsl2563_read_raw()
518 *val = calib_to_sysfs(chip->calib0); in tsl2563_read_raw()
520 *val = calib_to_sysfs(chip->calib1); in tsl2563_read_raw()
529 mutex_unlock(&chip->lock); in tsl2563_read_raw()
575 struct tsl2563_chip *chip = iio_priv(indio_dev); in tsl2563_read_thresh() local
579 *val = chip->high_thres; in tsl2563_read_thresh()
582 *val = chip->low_thres; in tsl2563_read_thresh()
596 struct tsl2563_chip *chip = iio_priv(indio_dev); in tsl2563_write_thresh() local
604 mutex_lock(&chip->lock); in tsl2563_write_thresh()
605 ret = i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | address, in tsl2563_write_thresh()
609 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_write_thresh()
613 chip->high_thres = val; in tsl2563_write_thresh()
615 chip->low_thres = val; in tsl2563_write_thresh()
618 mutex_unlock(&chip->lock); in tsl2563_write_thresh()
626 struct tsl2563_chip *chip = iio_priv(dev_info); in tsl2563_event_handler() local
636 i2c_smbus_write_byte(chip->client, TSL2563_CMD | TSL2563_CLEARINT); in tsl2563_event_handler()
644 struct tsl2563_chip *chip = iio_priv(indio_dev); in tsl2563_write_interrupt_config() local
647 mutex_lock(&chip->lock); in tsl2563_write_interrupt_config()
648 if (state && !(chip->intr & 0x30)) { in tsl2563_write_interrupt_config()
649 chip->intr &= ~0x30; in tsl2563_write_interrupt_config()
650 chip->intr |= 0x10; in tsl2563_write_interrupt_config()
652 cancel_delayed_work(&chip->poweroff_work); in tsl2563_write_interrupt_config()
653 if (!tsl2563_get_power(chip)) { in tsl2563_write_interrupt_config()
654 ret = tsl2563_set_power(chip, 1); in tsl2563_write_interrupt_config()
657 ret = tsl2563_configure(chip); in tsl2563_write_interrupt_config()
661 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_write_interrupt_config()
663 chip->intr); in tsl2563_write_interrupt_config()
664 chip->int_enabled = true; in tsl2563_write_interrupt_config()
667 if (!state && (chip->intr & 0x30)) { in tsl2563_write_interrupt_config()
668 chip->intr &= ~0x30; in tsl2563_write_interrupt_config()
669 ret = i2c_smbus_write_byte_data(chip->client, in tsl2563_write_interrupt_config()
671 chip->intr); in tsl2563_write_interrupt_config()
672 chip->int_enabled = false; in tsl2563_write_interrupt_config()
674 schedule_delayed_work(&chip->poweroff_work, 5 * HZ); in tsl2563_write_interrupt_config()
677 mutex_unlock(&chip->lock); in tsl2563_write_interrupt_config()
686 struct tsl2563_chip *chip = iio_priv(indio_dev); in tsl2563_read_interrupt_config() local
689 mutex_lock(&chip->lock); in tsl2563_read_interrupt_config()
690 ret = i2c_smbus_read_byte_data(chip->client, in tsl2563_read_interrupt_config()
692 mutex_unlock(&chip->lock); in tsl2563_read_interrupt_config()
719 struct tsl2563_chip *chip; in tsl2563_probe() local
725 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); in tsl2563_probe()
729 chip = iio_priv(indio_dev); in tsl2563_probe()
731 i2c_set_clientdata(client, chip); in tsl2563_probe()
732 chip->client = client; in tsl2563_probe()
734 err = tsl2563_detect(chip); in tsl2563_probe()
740 err = tsl2563_read_id(chip, &id); in tsl2563_probe()
746 mutex_init(&chip->lock); in tsl2563_probe()
749 chip->low_thres = 0x0; in tsl2563_probe()
750 chip->high_thres = 0xffff; in tsl2563_probe()
751 chip->gainlevel = tsl2563_gainlevel_table; in tsl2563_probe()
752 chip->intr = TSL2563_INT_PERSIST(4); in tsl2563_probe()
753 chip->calib0 = calib_from_sysfs(CALIB_BASE_SYSFS); in tsl2563_probe()
754 chip->calib1 = calib_from_sysfs(CALIB_BASE_SYSFS); in tsl2563_probe()
757 chip->cover_comp_gain = pdata->cover_comp_gain; in tsl2563_probe()
760 &chip->cover_comp_gain); in tsl2563_probe()
762 chip->cover_comp_gain = 1; in tsl2563_probe()
789 err = tsl2563_configure(chip); in tsl2563_probe()
795 INIT_DELAYED_WORK(&chip->poweroff_work, tsl2563_poweroff_work); in tsl2563_probe()
798 schedule_delayed_work(&chip->poweroff_work, 5 * HZ); in tsl2563_probe()
809 cancel_delayed_work(&chip->poweroff_work); in tsl2563_probe()
816 struct tsl2563_chip *chip = i2c_get_clientdata(client); in tsl2563_remove() local
817 struct iio_dev *indio_dev = iio_priv_to_dev(chip); in tsl2563_remove()
820 if (!chip->int_enabled) in tsl2563_remove()
821 cancel_delayed_work(&chip->poweroff_work); in tsl2563_remove()
823 chip->intr &= ~0x30; in tsl2563_remove()
824 i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | TSL2563_REG_INT, in tsl2563_remove()
825 chip->intr); in tsl2563_remove()
827 tsl2563_set_power(chip, 0); in tsl2563_remove()
835 struct tsl2563_chip *chip = i2c_get_clientdata(to_i2c_client(dev)); in tsl2563_suspend() local
838 mutex_lock(&chip->lock); in tsl2563_suspend()
840 ret = tsl2563_set_power(chip, 0); in tsl2563_suspend()
844 chip->suspended = true; in tsl2563_suspend()
847 mutex_unlock(&chip->lock); in tsl2563_suspend()
853 struct tsl2563_chip *chip = i2c_get_clientdata(to_i2c_client(dev)); in tsl2563_resume() local
856 mutex_lock(&chip->lock); in tsl2563_resume()
858 ret = tsl2563_set_power(chip, 1); in tsl2563_resume()
862 ret = tsl2563_configure(chip); in tsl2563_resume()
866 chip->suspended = false; in tsl2563_resume()
869 mutex_unlock(&chip->lock); in tsl2563_resume()