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); }
/*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 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; }
/*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); }