Пример #1
0
static ssize_t light_enable_store(struct device *dev,
				  struct device_attribute *attr,
				  const char *buf, size_t size)
{
	struct cm3323_data *cm3323 = dev_get_drvdata(dev);
	bool new_value;

	if (sysfs_streq(buf, "1"))
		new_value = true;
	else if (sysfs_streq(buf, "0"))
		new_value = false;
	else {
		pr_err("%s: invalid value %d\n", __func__, *buf);
		return -EINVAL;
	}

	mutex_lock(&cm3323->power_lock);
	pr_info("%s,new_value=%d\n", __func__, new_value);
	if (new_value && !(cm3323->power_state & LIGHT_ENABLED)) {
		cm3323->power_state |= LIGHT_ENABLED;
		cm3323_light_enable(cm3323);
	} else if (!new_value && (cm3323->power_state & LIGHT_ENABLED)) {
		cm3323_light_disable(cm3323);
		cm3323->power_state &= ~LIGHT_ENABLED;
	}
	mutex_unlock(&cm3323->power_lock);
	return size;
}
Пример #2
0
static int cm3323_i2c_remove(struct i2c_client *client)
{
	struct cm3323_data *cm3323 = i2c_get_clientdata(client);


	/* device off */
	if (cm3323->power_state & LIGHT_ENABLED)
		cm3323_light_disable(cm3323);

	/* destroy workqueue */
	destroy_workqueue(cm3323->light_wq);

	/* sysfs destroy */
	device_remove_file(cm3323->light_dev, &dev_attr_name);
	device_remove_file(cm3323->light_dev, &dev_attr_vendor);
	device_remove_file(cm3323->light_dev, &dev_attr_raw_data);
	device_remove_file(cm3323->light_dev, &dev_attr_lux);
	sensors_classdev_unregister(cm3323->light_dev);

	/* input device destroy */
	sysfs_remove_group(&cm3323->light_input_dev->dev.kobj,
			   &light_attribute_group);
	input_unregister_device(cm3323->light_input_dev);

	/* lock destroy */
	mutex_destroy(&cm3323->read_lock);
	mutex_destroy(&cm3323->power_lock);

	kfree(cm3323);

	return 0;
}
static int __devexit cm3323_remove(struct i2c_client *client)
{
	struct cm3323_p *data = i2c_get_clientdata(client);

	/* device off */
	if (data->power_state & LIGHT_ENABLED)
		cm3323_light_disable(data);

	/* destroy workqueue */
	destroy_workqueue(data->light_wq);

	/* lock destroy */
	mutex_destroy(&data->read_lock);
	mutex_destroy(&data->power_lock);

	/* sysfs destroy */
	sensors_unregister(data->light_dev, sensor_attrs);
	sensors_remove_symlink(&data->input->dev.kobj, data->input->name);

	/* input device destroy */
	sysfs_remove_group(&data->input->dev.kobj, &light_attribute_group);
	input_unregister_device(data->input);
	kfree(data);

	return 0;
}
Пример #4
0
static ssize_t cm3323_poll_delay_store(struct device *dev,
					struct device_attribute *attr,
					const char *buf, size_t size)
{
	struct cm3323_data *cm3323 = dev_get_drvdata(dev);
	int64_t new_delay;
	int err;

	err = strict_strtoll(buf, 10, &new_delay);
	if (err < 0)
		return err;

	mutex_lock(&cm3323->power_lock);
	if (new_delay != ktime_to_ns(cm3323->light_poll_delay)) {
		cm3323->light_poll_delay = ns_to_ktime(new_delay);
		if (cm3323->power_state & LIGHT_ENABLED) {
			cm3323_light_disable(cm3323);
			cm3323_light_enable(cm3323);
		}
		pr_info("%s, poll_delay = %lld\n", __func__, new_delay);
	}
	mutex_unlock(&cm3323->power_lock);

	return size;
}
static ssize_t light_enable_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t size)
{
	u8 enable;
	int ret;
	struct cm3323_p *data = dev_get_drvdata(dev);

	ret = kstrtou8(buf, 2, &enable);
	if (ret) {
		pr_err("[SENSOR]: %s - Invalid Argument\n", __func__);
		return ret;
	}

	pr_info("[SENSOR]: %s - new_value = %u\n", __func__, enable);
	mutex_lock(&data->power_lock);
	if (enable && !(data->power_state & LIGHT_ENABLED)) {
		data->power_state |= LIGHT_ENABLED;
		cm3323_light_enable(data);
	} else if (!enable && (data->power_state & LIGHT_ENABLED)) {
		cm3323_light_disable(data);
		data->power_state &= ~LIGHT_ENABLED;
	}
	mutex_unlock(&data->power_lock);

	return size;
}
static ssize_t cm3323_poll_delay_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t size)
{
	struct cm3323_p *data = dev_get_drvdata(dev);
	int64_t new_delay;
	int ret;

	ret = kstrtoll(buf, 10, &new_delay);
	if (ret) {
		pr_err("[SENSOR]: %s - Invalid Argument\n", __func__);
		return ret;
	}

	mutex_lock(&data->power_lock);
	if (new_delay != ktime_to_ms(data->poll_delay)) {
		data->poll_delay = ns_to_ktime(new_delay * NSEC_PER_MSEC);
		if (data->power_state & LIGHT_ENABLED) {
			cm3323_light_disable(data);
			cm3323_light_enable(data);
		}
		pr_info("[SENSOR]: %s - poll_delay = %lld\n",
			__func__, new_delay);
	}
	mutex_unlock(&data->power_lock);

	return size;
}
Пример #7
0
static ssize_t light_enable_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t size)
{
	u8 enable;
	int ret;
	struct cm3323_p *data = dev_get_drvdata(dev);

	ret = kstrtou8(buf, 2, &enable);
	if (ret) {
		pr_err("[SENSOR]: %s - Invalid Argument\n", __func__);
		return ret;
	}

	pr_info("[SENSOR]: %s - new_value = %u\n", __func__, enable);
	if (enable && !(data->power_state & LIGHT_ENABLED)) {
		data->power_state |= LIGHT_ENABLED;
		cm3323_light_enable(data);
#ifdef CONFIG_SENSORS_ESD_DEFENCE
		data->zero_cnt = 0;
		data->reset_cnt = 0;
#endif
	} else if (!enable && (data->power_state & LIGHT_ENABLED)) {
		cm3323_light_disable(data);
		data->power_state &= ~LIGHT_ENABLED;
	}

	return size;
}
Пример #8
0
static void cm3323_shutdown(struct i2c_client *client)
{
	struct cm3323_p *data = i2c_get_clientdata(client);

	pr_info("[SENSOR]: %s\n", __func__);
	if (data->power_state & LIGHT_ENABLED)
		cm3323_light_disable(data);
}
Пример #9
0
static int cm3323_suspend(struct device *dev)
{
	struct cm3323_p *data = dev_get_drvdata(dev);

	if (data->power_state & LIGHT_ENABLED) {
		pr_info("[SENSOR]: %s\n", __func__);
		cm3323_light_disable(data);
	}

	return 0;
}
Пример #10
0
static int cm3323_suspend(struct device *dev)
{
	/* We disable power only if proximity is disabled.  If proximity
	   is enabled, we leave power on because proximity is allowed
	   to wake up device.  We remove power without changing
	   cm3323->power_state because we use that state in resume.
	 */
	struct cm3323_data *cm3323 = dev_get_drvdata(dev);

	if (cm3323->power_state & LIGHT_ENABLED)
		cm3323_light_disable(cm3323);

	return 0;
}