/*For Factory Test Mode*/ static ssize_t lightsensor_file_state_show(struct device *dev, struct device_attribute *attr, char *buf) { struct bh1721_data *bh1721 = dev_get_drvdata(dev); unsigned int result; /* * POWER ON command is possible to omit. */ printk("[%s] lightsensor_file_state_show \n", __func__); bh1721_write_command(bh1721->i2c_client, &POWER_ON); bh1721_write_command(bh1721->i2c_client, &H_RESOLUTION_2); /* Maximum measurement time */ msleep(180); bh1721_read_value(bh1721->i2c_client, bh1721->illuminance_data); bh1721_write_command(bh1721->i2c_client, &POWER_DOWN); result = bh1721->illuminance_data[0] << 8 | bh1721->illuminance_data[1]; result = (result*10)/12; /* apply hysteresis */ printk("[%s] original lux = %u\n", __func__, result); result = get_next_level(result); printk("[%s] representative lux = %u\n", __func__, result); return sprintf(buf, "%d\n", result); }
static ssize_t lightsensor_lux_show(struct device *dev, struct device_attribute *attr, char *buf) { unsigned int result; struct bh1721_data *bh1721 = dev_get_drvdata(dev); /* * POWER ON command is possible to omit. */ if (!(bh1721->power_state & LIGHT_ENABLED)){ if((bh1721_write_command(bh1721->i2c_client, &POWER_ON))>0) light_enable = ON; bh1721_write_command(bh1721->i2c_client, &AUTO_RESOLUTION_1); /* Maximum measurement time */ msleep(180); } bh1721_read_value(bh1721->i2c_client, bh1721->illuminance_data); if ( !(bh1721->power_state & LIGHT_ENABLED) ){ if((bh1721_write_command(bh1721->i2c_client, &POWER_DOWN))>0) light_enable = OFF; } result = bh1721->illuminance_data[0] << 8 | bh1721->illuminance_data[1]; result = (result * 10) / 12; result = result * 139 / 13; return sprintf(buf, "%d\n", result); }
static void bh1721_light_enable(struct bh1721_data *bh1721) { printk("[Light Sensor] starting poll timer, delay %lldns\n", ktime_to_ns(bh1721->light_poll_delay)); hrtimer_start(&bh1721->timer, bh1721->light_poll_delay, HRTIMER_MODE_REL); if((bh1721_write_command(bh1721->i2c_client, &POWER_ON))>0) printk("[Light Sensor] Power ON"); if((bh1721_write_command(bh1721->i2c_client, &AUTO_RESOLUTION_1 ))>0) printk("[Light Sensor] auto resoulution ON"); }
static ssize_t lightsensor_file_cmd_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int mode,ret; ret=0; sscanf(buf,"%d",&mode); if(mode ==0) { bh1721_write_command(chip->client, &POWER_DOWN); light_enable = OFF; } else if(mode ==1) { bh1721_write_command(chip->client, &POWER_ON); light_enable = ON; } return count; }
static void bh1721_light_disable(struct bh1721_data *bh1721) { printk("[Light Sensor] cancelling poll timer\n"); hrtimer_cancel(&bh1721->timer); cancel_work_sync(&bh1721->work_light); if((bh1721_write_command(bh1721->i2c_client, &POWER_DOWN))>0) printk("[Light Sensor] Power off"); }
/*For Factory Test Mode*/ static ssize_t lightsensor_file_state_show(struct device *dev, struct device_attribute *attr, char *buf) { unsigned int result; /* * POWER ON command is possible to omit. */ if((bh1721_write_command(chip->client, &POWER_ON))>0) light_enable = ON; bh1721_write_command(chip->client, &H_RESOLUTION_2); /* Maximum measurement time */ msleep(180); bh1721_read_value(chip->client, chip->illuminance_data); if((bh1721_write_command(chip->client, &POWER_DOWN))>0) light_enable = OFF; result = chip->illuminance_data[0] << 8 | chip->illuminance_data[1]; result = (result*10)/12; return sprintf(buf, "%d\n", result); }
/*For Factory Test Mode*/ static ssize_t bh1721_show_illuminance(struct device *dev, struct device_attribute *attr, char *buf) { struct bh1721_data *bh1721 = dev_get_drvdata(dev); unsigned int result; /* * POWER ON command is possible to omit. */ if((bh1721_write_command(bh1721->i2c_client, &POWER_ON))>0) light_enable = ON; bh1721_write_command(bh1721->i2c_client, &AUTO_RESOLUTION_1); /* Maximum measurement time */ msleep(180); bh1721_read_value(bh1721->i2c_client, bh1721->illuminance_data); if((bh1721_write_command(bh1721->i2c_client, &POWER_DOWN))>0) light_enable = OFF; result = bh1721->illuminance_data[0] << 8 | bh1721->illuminance_data[1]; return sprintf(buf, "%d\n", result); }
static unsigned int lightsensor_get_adcvalue(struct bh1721_data *bh1721) { unsigned int result; bh1721_write_command(bh1721->i2c_client, &H_RESOLUTION_2); /* Maximum measurement time */ msleep(180); bh1721_read_value(bh1721->i2c_client, bh1721->illuminance_data); result = bh1721->illuminance_data[0] << 8 | bh1721->illuminance_data[1]; result = (result*10)/12; result = get_next_level(result); return result; }
static int bh1721_suspend(struct i2c_client *client, pm_message_t mesg) { bh1721_write_command(chip->client, &POWER_DOWN); return 0; }