Example #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;
}
static ssize_t store_als_ir_mode(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	struct iio_dev *indio_dev = dev_get_drvdata(dev);
	struct isl29028_chip *chip = iio_priv(indio_dev);
	struct i2c_client *client = chip->client;
	bool st = true;
	unsigned long lval;

	dev_vdbg(dev, "%s()\n", __func__);

	if (strict_strtoul(buf, 10, &lval))
		return -EINVAL;
	if (lval > 2) {
		dev_err(dev, "illegal value %lu\n", lval);
		return -EINVAL;
	}

	mutex_lock(&chip->lock);

	if (lval == chip->is_prox_enable) {
		mutex_unlock(&chip->lock);
		return count;
	}

	switch (lval) {
	case MODE_NONE:
		if (chip->is_prox_enable)
			st = isl29028_set_als_ir_mode(client, false, false);
		else if (chip->isl_reg)
			regulator_disable(chip->isl_reg);
			break;
	case MODE_ALS:
	case MODE_IR:
		if (!chip->is_prox_enable && chip->isl_reg)
			regulator_enable(chip->isl_reg);
		st = isl29028_set_als_ir_mode(client, true, (lval == MODE_ALS));
	}

	if (st)
		chip->als_ir_mode = (int)lval;
	else
		dev_err(dev, "Error in enabling als/ir mode\n");

	mutex_unlock(&chip->lock);
	return count;
}
static int isl29028_resume(struct device *dev)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct iio_dev *indio_dev = i2c_get_clientdata(client);
	struct isl29028_chip *chip = iio_priv(indio_dev);

	dev_dbg(&client->dev, "%s()\n", __func__);
	mutex_lock(&chip->lock);
	if (chip->isl_reg && (chip->is_prox_enable || chip->als_ir_mode))
		regulator_enable(chip->isl_reg);
	switch (chip->als_ir_mode) {
	case MODE_ALS:
		isl29028_set_als_ir_mode(client, true, true);
		break;
	case MODE_IR:
		isl29028_set_als_ir_mode(client, true, false);
	}
	if (chip->is_prox_enable)
		isl29028_set_proxim_period(client, true, chip->prox_period);
	mutex_unlock(&chip->lock);
	return 0;
}
Example #4
0
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);
}
Example #5
0
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);
}