ret = i2c_smbus_write_byte(chip->client,
(TSL2583_CMD_REG | TSL2583_CMD_SPL_FN |
TSL2583_CMD_ALS_INT_CLR));
-
if (ret < 0) {
dev_err(&chip->client->dev, "%s: failed to clear the interrupt bit\n",
__func__);
chip->als_cur_info.lux = 0;
goto done;
}
+
/* calculate ratio */
ratio = (ch1 << 15) / ch0;
+
/* convert to unscaled lux using the pointer to the table */
for (p = (struct tsl2583_lux *)tsl2583_device_lux;
p->ratio != 0 && p->ratio < ratio; p++)
lux64 >>= 13;
lux = lux64;
lux = (lux + 500) / 1000;
+
if (lux > TSL2583_LUX_CALC_OVER_FLOW) { /* check for overflow */
return_max:
lux = TSL2583_LUX_CALC_OVER_FLOW;
__func__);
return -ENODATA;
}
+
lux_val = tsl2583_get_lux(indio_dev);
if (lux_val < 0) {
dev_err(&chip->client->dev, "%s: failed to get lux\n",
__func__);
return lux_val;
}
+
gain_trim_val = (unsigned int)(((chip->als_settings.als_cal_target)
* chip->als_settings.als_gain_trim) / lux_val);
-
if ((gain_trim_val < 250) || (gain_trim_val > 4000)) {
dev_err(&chip->client->dev,
"%s: trim_val of %d is not within the range [250, 4000]\n",
__func__, gain_trim_val);
return -ENODATA;
}
+
chip->als_settings.als_gain_trim = (int)gain_trim_val;
return (int)gain_trim_val;
}
offset += sprintf(buf + offset, "\n");
+
return offset;
}
indio_dev = devm_iio_device_alloc(&clientp->dev, sizeof(*chip));
if (!indio_dev)
return -ENOMEM;
+
chip = iio_priv(indio_dev);
chip->client = clientp;
i2c_set_clientdata(clientp, indio_dev);
indio_dev->dev.parent = &clientp->dev;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->name = chip->client->name;
+
ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
if (ret) {
dev_err(&clientp->dev, "%s: iio registration failed\n",
return ret;
dev_info(&clientp->dev, "Light sensor found.\n");
+
return 0;
}
chip->suspended = true;
mutex_unlock(&chip->als_mutex);
+
return ret;
}
ret = tsl2583_chip_init_and_power_on(indio_dev);
mutex_unlock(&chip->als_mutex);
+
return ret;
}