示例#1
0
static int isl29028_als_get(struct isl29028_chip *chip, int *als_data)
{
	struct device *dev = regmap_get_device(chip->regmap);
	int ret;
	int als_ir_data;

	if (chip->als_ir_mode != MODE_ALS) {
		ret = isl29028_set_als_ir_mode(chip, MODE_ALS);
		if (ret < 0) {
			dev_err(dev,
				"Error in enabling ALS mode err %d\n", ret);
			return ret;
		}
		chip->als_ir_mode = MODE_ALS;
	}

	ret = isl29028_read_als_ir(chip, &als_ir_data);
	if (ret < 0)
		return ret;

	/*
	 * convert als data count to lux.
	 * if lux_scale = 125,  lux = count * 0.031
	 * if lux_scale = 2000, lux = count * 0.49
	 */
	if (chip->lux_scale == 125)
		als_ir_data = (als_ir_data * 31) / 1000;
	else
		als_ir_data = (als_ir_data * 49) / 100;

	*als_data = als_ir_data;
	return 0;
}
/* Display als data  */
static ssize_t show_als_data(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct iio_dev *indio_dev = dev_get_drvdata(dev);
	struct isl29028_chip *chip = iio_priv(indio_dev);
	int als_ir_data;
	bool st;
	ssize_t buf_count = 0;

	dev_vdbg(dev, "%s()\n", __func__);
	mutex_lock(&chip->lock);

	if (chip->als_ir_mode == MODE_ALS) {
		st = isl29028_read_als_ir(chip->client, &als_ir_data);
		if (st) {
			/* convert als data count to lux */
			/* if als_range = 0, lux = count * 0.0326 */
			/* if als_range = 1, lux = count * 0.522 */
			if (!chip->als_range)
				als_ir_data = (als_ir_data * 326) / 10000;
			else
				als_ir_data = (als_ir_data * 522) / 1000;

			buf_count = sprintf(buf, "%d\n", als_ir_data);
			chip->als_reading = als_ir_data;
		}
	} else
		buf_count = sprintf(buf, "%d\n", chip->als_reading);
	mutex_unlock(&chip->lock);
	return buf_count;
}
示例#3
0
文件: isl29028.c 项目: 19Dan01/linux
static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data)
{
	int ret;

	if (chip->als_ir_mode != MODE_IR) {
		ret = isl29028_set_als_ir_mode(chip, MODE_IR);
		if (ret < 0) {
			dev_err(chip->dev,
				"Error in enabling IR mode err %d\n", ret);
			return ret;
		}
		chip->als_ir_mode = MODE_IR;
	}
	return isl29028_read_als_ir(chip, ir_data);
}
示例#4
0
文件: isl29028.c 项目: acton393/linux
static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data)
{
	struct device *dev = regmap_get_device(chip->regmap);
	int ret;

	if (chip->als_ir_mode != ISL29028_MODE_IR) {
		ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR);
		if (ret < 0) {
			dev_err(dev,
				"Error in enabling IR mode err %d\n", ret);
			return ret;
		}
		chip->als_ir_mode = ISL29028_MODE_IR;
	}
	return isl29028_read_als_ir(chip, ir_data);
}
/* Display IR data  */
static ssize_t show_ir_data(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct iio_dev *indio_dev = dev_get_drvdata(dev);
	struct isl29028_chip *chip = iio_priv(indio_dev);
	int als_ir_data;
	bool st;
	ssize_t buf_count = 0;

	dev_vdbg(dev, "%s()\n", __func__);
	mutex_lock(&chip->lock);

	if (chip->als_ir_mode == MODE_IR) {
		st = isl29028_read_als_ir(chip->client, &als_ir_data);
		if (st) {
			buf_count = sprintf(buf, "%d\n", als_ir_data);
			chip->ir_reading = als_ir_data;
		}
	} else
		buf_count = sprintf(buf, "%d\n", chip->ir_reading);
	mutex_unlock(&chip->lock);
	return buf_count;
}