Example #1
0
static int bh1721fvc_resume(struct device *dev)
{

	int err = 0;

	struct i2c_client *client = to_i2c_client(dev);

	struct bh1721fvc_data *bh1721fvc = i2c_get_clientdata(client);

	bh1721fvc_dbmsg("bh1721fvc_resume +\n");

	if (bh1721fvc_is_measuring(bh1721fvc)) {

		err = bh1721fvc_enable(bh1721fvc);

		if (err)

			pr_err("%s: could not enable\n", __func__);

	}

	bh1721fvc_dbmsg("bh1721fvc_resume -\n");

	return err;

}
Example #2
0
static ssize_t bh1721fvc_poll_delay_store(struct device *dev,
				struct device_attribute *attr,
				const char *buf, size_t size)
{
	int err;
	int64_t new_delay;
	struct bh1721fvc_data *bh1721fvc = dev_get_drvdata(dev);

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

	bh1721fvc_dbmsg("new delay = %lldns, old delay = %lldns\n",
			new_delay, ktime_to_ns(bh1721fvc->light_poll_delay));

	mutex_lock(&bh1721fvc->lock);
	if (new_delay != ktime_to_ns(bh1721fvc->light_poll_delay)) {
		bh1721fvc->light_poll_delay = ns_to_ktime(new_delay);
		if (bh1721fvc_is_measuring(bh1721fvc)) {
			bh1721fvc_disable(bh1721fvc);
			bh1721fvc_enable(bh1721fvc);
		}

	}
	mutex_unlock(&bh1721fvc->lock);

	return size;
}
Example #3
0
static int bh1721fvc_remove(struct i2c_client *client)
{

	struct bh1721fvc_data *bh1721fvc = i2c_get_clientdata(client);

	sensors_unregister(bh1721fvc->light_sensor_device);

	sysfs_remove_group(&bh1721fvc->input_dev->dev.kobj,
			   &bh1721fvc_attribute_group);

	input_unregister_device(bh1721fvc->input_dev);

	if (bh1721fvc_is_measuring(bh1721fvc))

		bh1721fvc_disable(bh1721fvc);

	destroy_workqueue(bh1721fvc->wq);

	mutex_destroy(&bh1721fvc->lock);

	kfree(bh1721fvc);

	bh1721fvc_dbmsg("bh1721fvc_remove -\n");

	return 0;

}
Example #4
0
static ssize_t bh1721fvc_light_sensor_mode_store(struct device *dev,
				struct device_attribute *attr,
				const char *buf, size_t size)
{
	u8 measure_mode;
	struct bh1721fvc_data *bh1721fvc = dev_get_drvdata(dev);

	bh1721fvc_dbmsg("bh1721fvc_light_sensor_mode_store +\n");

	if (sysfs_streq(buf, "auto")) {
		measure_mode = AUTO_MEASURE;
	} else if (sysfs_streq(buf, "high")) {
		measure_mode = H_MEASURE;
	} else if (sysfs_streq(buf, "low")) {
		measure_mode = L_MEASURE;
	} else {
		pr_err("%s: invalid value %s\n", __func__, buf);
		return -EINVAL;
	}

	mutex_lock(&bh1721fvc->lock);
	if (bh1721fvc->measure_mode != measure_mode) {
		bh1721fvc->measure_mode = measure_mode;
		if (bh1721fvc_is_measuring(bh1721fvc)) {
			bh1721fvc_disable(bh1721fvc);
			bh1721fvc_enable(bh1721fvc);
			bh1721fvc->state = measure_mode;
		}
	}
	mutex_unlock(&bh1721fvc->lock);

	bh1721fvc_dbmsg("bh1721fvc_light_sensor_mode_store -\n");

	return size;
}
Example #5
0
static ssize_t bh1721fvc_light_enable_show(struct device *dev,
				 struct device_attribute *attr, char *buf)
{
	struct bh1721fvc_data *bh1721fvc = dev_get_drvdata(dev);

	return sprintf(buf, "%d\n", bh1721fvc_is_measuring(bh1721fvc));
}
static int  bh1721fvc_remove(struct i2c_client *client)
{
	struct bh1721fvc_data *bh1721fvc = i2c_get_clientdata(client);

	device_remove_file(bh1721fvc->factory_dev,
			&dev_attr_sensor_info);
	device_remove_file(bh1721fvc->factory_dev,
			&dev_attr_lightsensor_file_cmd);
	device_remove_file(bh1721fvc->factory_dev,
			&dev_attr_lightsensor_file_illuminance);
	device_destroy(bh1721fvc->factory_class, 0);
	class_destroy(bh1721fvc->factory_class);

	sysfs_remove_group(&bh1721fvc->input_dev->dev.kobj,
				&bh1721fvc_attribute_group);
	input_unregister_device(bh1721fvc->input_dev);

	if (bh1721fvc_is_measuring(bh1721fvc))
		bh1721fvc_disable(bh1721fvc);

	destroy_workqueue(bh1721fvc->wq);
	mutex_destroy(&bh1721fvc->lock);
	kfree(bh1721fvc);

	bh1721fvc_dbmsg("bh1721fvc_remove -\n");
	return 0;
}
Example #7
0
static ssize_t bh1721fvc_light_enable_store(struct device *dev,
					struct device_attribute *attr,
					const char *buf, size_t size)
{
	int err = 0;
	bool new_value = false;
	struct bh1721fvc_data *bh1721fvc = dev_get_drvdata(dev);

	bh1721fvc_dbmsg("enable %s\n", buf);

	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;
	}

	bh1721fvc_dbmsg("new_value = %d, old state = %d\n",
			new_value, bh1721fvc_is_measuring(bh1721fvc));

	mutex_lock(&bh1721fvc->lock);
	if (new_value && (!bh1721fvc_is_measuring(bh1721fvc))) {
		err = bh1721fvc_enable(bh1721fvc);
		if (!err) {
			bh1721fvc->state = bh1721fvc->measure_mode;
		} else {
			pr_err("%s: couldn't enable", __func__);
			bh1721fvc->state = POWER_DOWN;
		}
		bh1721fvc->als_buf_initialized = false;
	} else if (!new_value && (bh1721fvc_is_measuring(bh1721fvc))) {
		err = bh1721fvc_disable(bh1721fvc);
		if (!err)
			bh1721fvc->state = POWER_DOWN;
		else
			pr_err("%s: couldn't enable", __func__);
	} else {
		bh1721fvc_dbmsg("no nothing\n");
	}

	mutex_unlock(&bh1721fvc->lock);

	return size;
}
Example #8
0
static int bh1721fvc_suspend(struct device *dev)
{
	int err = 0;
	struct i2c_client *client = to_i2c_client(dev);
	struct bh1721fvc_data *bh1721fvc = i2c_get_clientdata(client);

	if (bh1721fvc_is_measuring(bh1721fvc)) {
		err = bh1721fvc_disable(bh1721fvc);
		if (err)
			pr_err("%s: could not disable\n", __func__);
	}

	return err;
}
Example #9
0
static int bh1721fvc_reset(struct bh1721fvc_data *bh1721fvc)
{
    int err = 0;

    bh1721fvc->reset();

    msleep(20);

    if (bh1721fvc_is_measuring(bh1721fvc)) {
        err = bh1721fvc_write_byte(bh1721fvc->client,
                                   commands[POWER_DOWN]);
        if (err) {
            printk(KERN_INFO "%s: Failed to write byte (POWER_ON)\n",
                   __func__);
            return err;
        }

        msleep(20);

        err = bh1721fvc_write_byte(bh1721fvc->client,
                                   commands[POWER_ON]);
        if (err) {
            printk(KERN_INFO "%s: Failed to write byte (POWER_ON)\n",
                   __func__);
            return err;
        }

        err = bh1721fvc_write_byte(bh1721fvc->client,
                                   commands[bh1721fvc->measure_mode]);
        if (err) {
            printk(KERN_INFO "%s: Failed to write byte (measure mode)\n",
                   __func__);
            return err;
        }

        if (bh1721fvc->measure_mode == H_MEASURE)
            mdelay(120);
        else if (bh1721fvc->measure_mode == L_MEASURE)
            mdelay(16);
        else   /* AUTO_MEASURE */
            mdelay(120 + 16);
    }

    printk(KERN_INFO "bh1721fvc_reset done!\n");
    return 0;
}
Example #10
0
static int bh1721fvc_suspend(struct device *dev)
{
	int err = 0;
	struct i2c_client *client = to_i2c_client(dev);
	struct bh1721fvc_data *bh1721fvc = i2c_get_clientdata(client);

	if (bh1721fvc_is_measuring(bh1721fvc)) {
		err = bh1721fvc_disable(bh1721fvc);
		if (err)
			pr_err("%s: could not disable\n", __func__);
	}
#if defined(CONFIG_MACH_SAMSUNG_P5)
	bh1721fvc->output(0);
#endif

	return err;
}
Example #11
0
static int bh1721fvc_resume(struct device *dev)
{
	int err = 0;
	struct i2c_client *client = to_i2c_client(dev);
	struct bh1721fvc_data *bh1721fvc = i2c_get_clientdata(client);

	bh1721fvc_dbmsg("bh1721fvc_resume +\n");

#if defined(CONFIG_MACH_SAMSUNG_P5)
	bh1721fvc->output(1);
#endif

	if (bh1721fvc_is_measuring(bh1721fvc)) {
		err = bh1721fvc_enable(bh1721fvc);
		if (err)
			pr_err("%s: could not enable\n", __func__);
	}

	bh1721fvc_dbmsg("bh1721fvc_resume -\n");
	return err;
}
Example #12
0
static int bh1721fvc_reset(struct bh1721fvc_data *bh1721fvc)
{	
	int ret = 0,err;
		
	// reset sensor
	bh1721fvc->reset();

	printk("bh1721fvc->reset()\n");
	msleep(10);

	// disable & enable sensor again
	if (bh1721fvc_is_measuring(bh1721fvc)) 
	{
		err = bh1721fvc_write_byte(bh1721fvc->client, commands[POWER_DOWN]);
		msleep(10);
	
		err = bh1721fvc_write_byte(bh1721fvc->client, commands[POWER_ON]);
		if (err) {
			printk("%s: Failed to write byte (POWER_ON)\n", __func__);
		}

		err = bh1721fvc_write_byte(bh1721fvc->client, commands[bh1721fvc->measure_mode]);

		if (err) {
			printk("%s: Failed to write byte (measure mode)\n", __func__);
		}
	
		if (bh1721fvc->measure_mode == H_MEASURE)
			mdelay(120);
		else if (bh1721fvc->measure_mode == L_MEASURE)
			mdelay(16);
		else                                                 /* AUTO_MEASURE */
			mdelay(120 + 16);
	}

	printk("bh1721fvc_reset done!\n");
	return ret;
}