static int cm3663_resume(struct device *dev) { /* Turn power back on if we were before suspend. */ struct i2c_client *client = to_i2c_client(dev); struct cm3663_data *cm3663 = i2c_get_clientdata(client); /* [S2PLUS] Temporary Patch */ #if defined(CONFIG_MACH_S2PLUS) struct regulator *regulator; int ret = 0; regulator = regulator_get(NULL, "vcc_pls_2.8v"); if (IS_ERR(regulator)) { printk(KERN_ERR "vcc_pls_2.8v regulator get err\n"); return -1; } if (!regulator_is_enabled(regulator)) { printk(KERN_ERR "%s: vcc_pls_2.8v is off. so ON\n", __func__); ret = regulator_enable(regulator); } regulator_put(regulator); mdelay(100); #endif if (cm3663->power_state & LIGHT_ENABLED) cm3663_light_enable(cm3663); return 0; }
static ssize_t light_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct cm3663_data *cm3663 = 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(&cm3663->power_lock); if (new_value && !(cm3663->power_state & LIGHT_ENABLED)) { cm3663->power_state |= LIGHT_ENABLED; cm3663_light_enable(cm3663); } else if (!new_value && (cm3663->power_state & LIGHT_ENABLED)) { cm3663_light_disable(cm3663); cm3663->power_state &= ~LIGHT_ENABLED; } mutex_unlock(&cm3663->power_lock); return size; }
static int cm3663_resume(struct device *dev) { /* Turn power back on if we were before suspend. */ struct i2c_client *client = to_i2c_client(dev); struct cm3663_data *cm3663 = i2c_get_clientdata(client); if (cm3663->power_state & LIGHT_ENABLED) cm3663_light_enable(cm3663); return 0; }
static ssize_t lightsensor_file_state_show(struct device *dev, struct device_attribute *attr, char *buf) { struct cm3663_data *cm3663 = dev_get_drvdata(dev); int adc = 0; if (!(cm3663->power_state & LIGHT_ENABLED)) cm3663_light_enable(cm3663); adc = lightsensor_get_alsvalue(cm3663); if (!(cm3663->power_state & LIGHT_ENABLED)) cm3663_light_disable(cm3663); return sprintf(buf, "%d\n", adc); }
static ssize_t poll_delay_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct cm3663_data *cm3663 = dev_get_drvdata(dev); int64_t new_delay; int err; err = strict_strtoll(buf, 10, &new_delay); if (err < 0) return err; mutex_lock(&cm3663->power_lock); if (new_delay != ktime_to_ns(cm3663->light_poll_delay)) { cm3663->light_poll_delay = ns_to_ktime(new_delay); if (cm3663->power_state & LIGHT_ENABLED) { cm3663_light_disable(cm3663); cm3663_light_enable(cm3663); } } mutex_unlock(&cm3663->power_lock); return size; }
static int lightsensor_get_alsvalue(struct cm3663_data *cm3663) { int value = 0; u8 als_high, als_low; #ifdef CONFIG_TARGET_LOCALE_KOR /* Verify power state of light sensor */ if (!(cm3663->power_state & LIGHT_ENABLED)) { pr_err("%s: Light Sensor was disabled by logic, " "cm3663->power_state = 0x%x\n", __func__, cm3663->power_state); cm3663_light_enable(cm3663); cm3663->power_state |= LIGHT_ENABLED; } #endif /* get ALS */ cm3663_i2c_read(cm3663, REGS_ALS_LSB, &als_low); cm3663_i2c_read(cm3663, REGS_ALS_MSB, &als_high); value = ((als_high << 8) | als_low) * 5; return value; }