Lines Matching refs:chip
123 static int tsl2563_set_power(struct tsl2563_chip *chip, int on)
125 struct i2c_client *client = chip->client;
137 static int tsl2563_get_power(struct tsl2563_chip *chip)
139 struct i2c_client *client = chip->client;
149 static int tsl2563_configure(struct tsl2563_chip *chip)
153 ret = i2c_smbus_write_byte_data(chip->client,
155 chip->gainlevel->gaintime);
158 ret = i2c_smbus_write_word_data(chip->client,
160 chip->high_thres);
163 ret = i2c_smbus_write_word_data(chip->client,
165 chip->low_thres);
178 struct tsl2563_chip *chip =
180 tsl2563_set_power(chip, 0);
183 static int tsl2563_detect(struct tsl2563_chip *chip)
187 ret = tsl2563_set_power(chip, 1);
191 ret = tsl2563_get_power(chip);
198 static int tsl2563_read_id(struct tsl2563_chip *chip, u8 *id)
200 struct i2c_client *client = chip->client;
212 static int tsl2563_configure_irq(struct tsl2563_chip *chip, bool enable)
216 chip->intr &= ~TSL2563_INT_MASK;
218 chip->intr |= TSL2563_INT_LEVEL;
220 ret = i2c_smbus_write_byte_data(chip->client,
222 chip->intr);
226 chip->int_enabled = enable;
264 static void tsl2563_wait_adc(struct tsl2563_chip *chip)
268 switch (chip->gainlevel->gaintime & TSL2563_TIMING_MASK) {
285 static int tsl2563_adjust_gainlevel(struct tsl2563_chip *chip, u16 adc)
287 struct i2c_client *client = chip->client;
289 if (adc > chip->gainlevel->max || adc < chip->gainlevel->min) {
291 (adc > chip->gainlevel->max) ?
292 chip->gainlevel++ : chip->gainlevel--;
296 chip->gainlevel->gaintime);
298 tsl2563_wait_adc(chip);
299 tsl2563_wait_adc(chip);
306 static int tsl2563_get_adc(struct tsl2563_chip *chip)
308 struct i2c_client *client = chip->client;
313 if (chip->suspended)
316 if (!chip->int_enabled) {
317 cancel_delayed_work_sync(&chip->poweroff_work);
319 if (!tsl2563_get_power(chip)) {
320 ret = tsl2563_set_power(chip, 1);
323 ret = tsl2563_configure(chip);
326 tsl2563_wait_adc(chip);
343 retry = tsl2563_adjust_gainlevel(chip, adc0);
346 chip->data0 = tsl2563_normalize_adc(adc0, chip->gainlevel->gaintime);
347 chip->data1 = tsl2563_normalize_adc(adc1, chip->gainlevel->gaintime);
349 if (!chip->int_enabled)
350 schedule_delayed_work(&chip->poweroff_work, 5 * HZ);
454 struct tsl2563_chip *chip = iio_priv(indio_dev);
459 chip->calib0 = tsl2563_calib_from_sysfs(val);
461 chip->calib1 = tsl2563_calib_from_sysfs(val);
476 struct tsl2563_chip *chip = iio_priv(indio_dev);
478 mutex_lock(&chip->lock);
484 ret = tsl2563_get_adc(chip);
487 calib0 = tsl2563_calib_adc(chip->data0, chip->calib0) *
488 chip->cover_comp_gain;
489 calib1 = tsl2563_calib_adc(chip->data1, chip->calib1) *
490 chip->cover_comp_gain;
495 ret = tsl2563_get_adc(chip);
499 *val = chip->data0;
501 *val = chip->data1;
511 *val = tsl2563_calib_to_sysfs(chip->calib0);
513 *val = tsl2563_calib_to_sysfs(chip->calib1);
522 mutex_unlock(&chip->lock);
568 struct tsl2563_chip *chip = iio_priv(indio_dev);
572 *val = chip->high_thres;
575 *val = chip->low_thres;
589 struct tsl2563_chip *chip = iio_priv(indio_dev);
592 mutex_lock(&chip->lock);
595 ret = i2c_smbus_write_word_data(chip->client,
598 ret = i2c_smbus_write_word_data(chip->client,
604 chip->high_thres = val;
606 chip->low_thres = val;
609 mutex_unlock(&chip->lock);
617 struct tsl2563_chip *chip = iio_priv(dev_info);
627 i2c_smbus_write_byte(chip->client, TSL2563_CMD | TSL2563_CLEARINT);
635 struct tsl2563_chip *chip = iio_priv(indio_dev);
638 mutex_lock(&chip->lock);
639 if (state && !(chip->intr & TSL2563_INT_MASK)) {
640 /* ensure the chip is actually on */
641 cancel_delayed_work_sync(&chip->poweroff_work);
642 if (!tsl2563_get_power(chip)) {
643 ret = tsl2563_set_power(chip, 1);
646 ret = tsl2563_configure(chip);
650 ret = tsl2563_configure_irq(chip, true);
653 if (!state && (chip->intr & TSL2563_INT_MASK)) {
654 ret = tsl2563_configure_irq(chip, false);
656 schedule_delayed_work(&chip->poweroff_work, 5 * HZ);
659 mutex_unlock(&chip->lock);
668 struct tsl2563_chip *chip = iio_priv(indio_dev);
671 mutex_lock(&chip->lock);
672 ret = i2c_smbus_read_byte_data(chip->client,
674 mutex_unlock(&chip->lock);
699 struct tsl2563_chip *chip;
704 indio_dev = devm_iio_device_alloc(dev, sizeof(*chip));
708 chip = iio_priv(indio_dev);
711 chip->client = client;
713 err = tsl2563_detect(chip);
717 err = tsl2563_read_id(chip, &id);
721 mutex_init(&chip->lock);
724 chip->low_thres = 0x0;
725 chip->high_thres = 0xffff;
726 chip->gainlevel = tsl2563_gainlevel_table;
727 chip->intr = TSL2563_INT_PERSIST(4);
728 chip->calib0 = tsl2563_calib_from_sysfs(CALIB_BASE_SYSFS);
729 chip->calib1 = tsl2563_calib_from_sysfs(CALIB_BASE_SYSFS);
731 chip->cover_comp_gain = 1;
732 device_property_read_u32(dev, "amstaos,cover-comp-gain", &chip->cover_comp_gain);
761 err = tsl2563_configure(chip);
765 INIT_DELAYED_WORK(&chip->poweroff_work, tsl2563_poweroff_work);
768 schedule_delayed_work(&chip->poweroff_work, 5 * HZ);
779 cancel_delayed_work_sync(&chip->poweroff_work);
786 struct tsl2563_chip *chip = iio_priv(indio_dev);
789 if (!chip->int_enabled)
790 cancel_delayed_work_sync(&chip->poweroff_work);
792 tsl2563_configure_irq(chip, false);
793 tsl2563_set_power(chip, 0);
799 struct tsl2563_chip *chip = iio_priv(indio_dev);
802 mutex_lock(&chip->lock);
804 ret = tsl2563_set_power(chip, 0);
808 chip->suspended = true;
811 mutex_unlock(&chip->lock);
818 struct tsl2563_chip *chip = iio_priv(indio_dev);
821 mutex_lock(&chip->lock);
823 ret = tsl2563_set_power(chip, 1);
827 ret = tsl2563_configure(chip);
831 chip->suspended = false;
834 mutex_unlock(&chip->lock);