Ejemplo n.º 1
0
static int bh1721fvc_enable(struct bh1721fvc_data *bh1721fvc)
{

	int err;

	bh1721fvc_dbmsg("starting poll timer, delay %lldns\n",
			ktime_to_ns(bh1721fvc->light_poll_delay));

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

	if (err) {

		pr_err("%s: Failed to write byte (POWER_ON)\n", __func__);

		goto err_power_on;

	}

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

	if (err) {

		pr_err("%s: Failed to write byte (measure mode)\n", __func__);

		goto err_measure_mode;

	}

	if (bh1721fvc->measure_mode == H_MEASURE)

		mdelay(120);

	else if (bh1721fvc->measure_mode == L_MEASURE)

		mdelay(16);

	else
		/* AUTO_MEASURE */
		mdelay(120 + 16);

	hrtimer_start(&bh1721fvc->timer, bh1721fvc->light_poll_delay,
		      HRTIMER_MODE_REL);

	goto done;

err_measure_mode:
err_power_on:
	bh1721fvc_write_byte(bh1721fvc->client, commands[POWER_DOWN]);

done:
	return err;

}
Ejemplo n.º 2
0
static ssize_t factory_file_illuminance_show(struct device *dev,
        struct device_attribute *attr, char *buf)
{
    u16 lux;
    int retry;
    int err;
    unsigned int result;
    struct bh1721fvc_data *bh1721fvc = dev_get_drvdata(dev);

    if (bh1721fvc->state == POWER_DOWN) {
        err = bh1721fvc_write_byte(bh1721fvc->client,
                                   commands[POWER_ON]);
        if (err)
            goto err_exit;

        err = bh1721fvc_write_byte(bh1721fvc->client,
                                   commands[AUTO_MEASURE]);
        if (err)
            goto err_exit;

        msleep(210);
    }

    for (retry = 0; retry < 10; retry++) {
        if (i2c_master_recv(bh1721fvc->client,
                            (u8 *)&lux, 2) == 2) {
            be16_to_cpus(&lux);
            break;
        }
    }

    if (retry == 10) {
        printk(KERN_INFO "I2C read failed.. retry %d\n", retry);
        goto err_exit;
    }
    /*
    *	result = (lux * 10) / 12;
    *	result = result * 139 / 13;
    */
    result = (lux * 89) / 10;
    if (result <= 8)
        result = 0;

    if (bh1721fvc->state == POWER_DOWN)
        bh1721fvc_write_byte(bh1721fvc->client, commands[POWER_DOWN]);

    return sprintf(buf, "%u\n", result);

err_exit:
    bh1721fvc_write_byte(bh1721fvc->client, commands[POWER_DOWN]);
    return err;
}
Ejemplo n.º 3
0
static int bh1721fvc_enable(struct bh1721fvc_data *bh1721fvc)
{
    int err;

#if defined(CONFIG_MACH_SAMSUNG_P4TMO)
    bh1721fvc->light_buffer = 0;
    bh1721fvc->light_count = 0;
    bh1721fvc->light_level_state = 0;
    bh1721fvc->light_buffer_cnt = LIGHT_UPWORD_BUFFER;
#endif

#if defined(CONFIG_MACH_SAMSUNG_P5)
    bh1721fvc->reset_cnt = 0;
    bh1721fvc->zero_cnt = 0;
#endif

    bh1721fvc_dbmsg("starting poll timer, delay %lldns\n",
                    ktime_to_ns(bh1721fvc->light_poll_delay));

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

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

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

    hrtimer_start(&bh1721fvc->timer, bh1721fvc->light_poll_delay,
                  HRTIMER_MODE_REL);
    goto done;

err_measure_mode:
err_power_on:
    bh1721fvc_write_byte(bh1721fvc->client, commands[POWER_DOWN]);
done:
    return err;
}
Ejemplo n.º 4
0
int bh1721fvc_test_luxvalue(struct bh1721fvc_data *bh1721fvc)
{
    unsigned int result;
    int retry;
    u16 lux;
    int err;

    if (bh1721fvc->state == POWER_DOWN) {
        err = bh1721fvc_write_byte(bh1721fvc->client,
                                   commands[POWER_ON]);
        if (err)
            return err;

        err = bh1721fvc_write_byte(bh1721fvc->client,
                                   commands[AUTO_MEASURE]);
        if (err)
            goto err_exit;

        msleep(210);
    }

    for (retry = 0; retry < 5; retry++) {
        if (i2c_master_recv(bh1721fvc->client,
                            (u8 *)&lux, 2) == 2) {
            be16_to_cpus(&lux);
            break;
        }
    }

    if (retry == 5) {
        printk(KERN_INFO "I2C read failed.. retry %d\n", retry);
        goto err_exit;
    }

    result = (lux * 10) / 12;
    result = result * 139 / 13;

    if (bh1721fvc->state == POWER_DOWN)
        bh1721fvc_write_byte(bh1721fvc->client, commands[POWER_DOWN]);

    return (int)result;

err_exit:
    bh1721fvc_write_byte(bh1721fvc->client, commands[POWER_DOWN]);
    return err;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
0
static ssize_t bh1721fvc_light_sensor_lux_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	u16 lux;
	int retry;
	int err;
	u32 result;
	struct bh1721fvc_data *bh1721fvc = dev_get_drvdata(dev);

	if (bh1721fvc->state == POWER_DOWN) {
		err =
		    bh1721fvc_write_byte(bh1721fvc->client, commands[POWER_ON]);
		if (err)
			goto err_exit;
		err =
		    bh1721fvc_write_byte(bh1721fvc->client,
					 commands[AUTO_MEASURE]);
		if (err)
			goto err_exit;
		msleep(210);
	}

	for (retry = 0; retry < 10; retry++) {
		if (i2c_master_recv(bh1721fvc->client, (u8 *) &lux, 2) == 2) {
			be16_to_cpus(&lux);
			break;
		}
	}

	if (retry == 10) {
		pr_err("%s : I2C read failed.. retry %d\n", __func__, retry);
		goto err_exit;
	}

	result = (lux * 89) / 10;
	if (bh1721fvc->state == POWER_DOWN)
		bh1721fvc_write_byte(bh1721fvc->client, commands[POWER_DOWN]);
	return sprintf(buf, "%u\n", result);

err_exit:
	bh1721fvc_write_byte(bh1721fvc->client, commands[POWER_DOWN]);
	return err;
}
Ejemplo n.º 7
0
static int bh1721fvc_disable(struct bh1721fvc_data *bh1721fvc)
{
	int err;

	hrtimer_cancel(&bh1721fvc->timer);
	cancel_work_sync(&bh1721fvc->work_light);
	err = bh1721fvc_write_byte(bh1721fvc->client, commands[POWER_DOWN]);
	if (unlikely(err != 0))
		pr_err("%s: Failed to write byte (POWER_DOWN)\n", __func__);

	return err;
}
Ejemplo n.º 8
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;
}