static ssize_t light_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct gp2a_data *data = dev_get_drvdata(dev); int value; int err = 0; err = kstrtoint(buf, 10, &value); if (err) pr_err("%s, kstrtoint failed.", __func__); printk(KERN_INFO "[GP2A] light_enable_store : value=%d\n", value); if (value != 0 && value != 1) return count; mutex_lock(&data->light_mutex); if (data->light_enabled && !value) { cancel_delayed_work_sync(&data->light_work); lightsensor_onoff(0, data); #if defined (CONFIG_MACH_CRATER_CHN_CTC) if(data->proximity_enabled != 1) #endif data->pdata->power_on(0); } if (!data->light_enabled && value) { data->pdata->power_on(1); msleep(5); data->light_data_first = true; lightsensor_onoff(1, data); schedule_delayed_work(&data->light_work, 300); } data->light_enabled = value; mutex_unlock(&data->light_mutex); return count; }
static void gp2a_work_func_light(struct work_struct *work) { struct gp2a_data *data = container_of((struct delayed_work *)work, struct gp2a_data, light_work); int adc; static int count; if (data == NULL || data->light_input_dev == NULL) return; adc = lightsensor_get_adc(data); /* detecting 0 after 3.6sec, set the register again. */ if (adc == 0) { count++; if (count == 18) { lightsensor_onoff(1, data); count = 0; pr_info("%s: register reset\n", __func__); } } else count = 0; input_report_rel(data->light_input_dev, REL_MISC, adc + 1); input_sync(data->light_input_dev); if (data->light_enabled) schedule_delayed_work(&data->light_work, msecs_to_jiffies(data->light_delay)); }
static void gp2a_work_func_light(struct work_struct *work) { struct gp2a_data *data = container_of((struct delayed_work *)work, struct gp2a_data, light_work); int adc = 0; #if defined(CONFIG_MACH_BAFFIN_DUOS_CTC) volatile static int count = 0; #endif adc = lightsensor_get_adcvalue(data); #if defined(CONFIG_MACH_BAFFIN_DUOS_CTC) if(adc == 0) { count++; if(count == 18) //detecting 0 after 3.6sec, set the register again. { printk(KERN_INFO" [GP2A]: add for ESD \n"); lightsensor_onoff(1,data); count = 0; } } #endif input_report_abs(data->light_input_dev, ABS_MISC, adc); input_sync(data->light_input_dev); if (lightval_logcount++ > 250) { printk(KERN_INFO "[GP2A] light value = %d \n", adc); lightval_logcount = 0; } if (data->light_enabled) schedule_delayed_work(&data->light_work, msecs_to_jiffies(data->light_delay)); }
static ssize_t gp2a_light_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct gp2a_data *data = dev_get_drvdata(dev); int value; int err = 0; if (bShutdown == true) { pr_err("%s already shutdown.", __func__); goto done; } err = kstrtoint(buf, 10, &value); if (err) { pr_err("%s kstrtoint failed.", __func__); goto done; } pr_info("%s %d value = %d\n", __func__, __LINE__, value); if (value != SENSOR_DISABLE && value != SENSOR_ENABLE) goto done; if (value) { if (data->light_enabled == SENSOR_DISABLE) { lightsensor_onoff(1, data); schedule_delayed_work(&data->light_work, msecs_to_jiffies(100)); data->light_enabled = SENSOR_ENABLE; } else { pr_err("%s already enabled\n", __func__); } } else { if (data->light_enabled == SENSOR_ENABLE) { lightsensor_onoff(0, data); schedule_delayed_work(&data->light_work, msecs_to_jiffies(data->light_delay)); data->light_enabled = SENSOR_DISABLE; } else { pr_err("%s already disabled\n", __func__); } } done: return count; }
static ssize_t light_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct sensor_data *data = dev_get_drvdata(dev); int value; int err = 0; #if defined(CONFIG_MACH_M3_USA_TMO) data->reset_cnt = 0; data->zero_cnt = 0; #endif err = kstrtoint(buf, 10, &value); if (err) printk(KERN_ERR "%s, kstrtoint failed.", __func__); gprintk("value = %d\n", value); if (value != 0 && value != 1) return count; mutex_lock(&data->mutex); if (data->enabled && !value) { cancel_delayed_work_sync(&data->work); gprintk("timer canceled.\n"); lightsensor_onoff(0); data->enabled = value; } if (!data->enabled && value) { lightsensor_onoff(1); data->enabled = value; first_value = true; queue_delayed_work(data->wq, &data->work, 0); gprintk("timer started.\n"); } mutex_unlock(&data->mutex); return count; }
static ssize_t light_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct gp2a_data *data = dev_get_drvdata(dev); int value; int err = 0; err = kstrtoint(buf, 10, &value); if (err) { pr_err("%s, kstrtoint failed.", __func__); goto done; } printk(KERN_INFO "[GP2A] light_enable_store : value=%d\n", value); if (value != 0 && value != 1) goto done; mutex_lock(&data->light_mutex); if (data->light_enabled && !value) { data->light_enabled = value; cancel_delayed_work_sync(&data->light_work); lightsensor_onoff(0, data); regulator_disable(prox_regulator); } if (!data->light_enabled && value) { data->light_enabled = value; regulator_enable(prox_regulator); msleep(5); lightsensor_onoff(1, data); schedule_delayed_work(&data->light_work, msecs_to_jiffies(20)); } mutex_unlock(&data->light_mutex); done: return count; }
static void gp2a_work_func_light(struct work_struct *work) { struct sensor_data *data = container_of((struct delayed_work *)work, struct sensor_data, work); int adc = 0; #ifdef CONFIG_MACH_BAFFIN int count = 0; while (adc == 0 && count < 5) { adc = lightsensor_get_adcvalue(data); count++; } #else adc = lightsensor_get_adcvalue(data); #endif input_report_rel(data->input_dev, REL_MISC, adc + 1); input_sync(data->input_dev); /*Reset lightsensor, if 0 lux data is continuously reported for 5 secs*/ if (adc == 0) { if (data->zero_cnt++ > 25) { data->zero_cnt = 0; if (data->reset_cnt++ <= LIMIT_RESET_COUNT) { lightsensor_onoff(0); lightsensor_onoff(1); pr_info("%s : lightsensor reset done.\n", __func__); } else { data->reset_cnt = LIMIT_RESET_COUNT + 1; } } } else { data->reset_cnt = 0; data->zero_cnt = 0; } if (data->enabled) queue_delayed_work(data->wq, &data->work, msecs_to_jiffies(data->delay)); }
static ssize_t light_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct gp2a_data *data = dev_get_drvdata(dev); int value; int err = 0; err = kstrtoint(buf, 10, &value); if (err) { pr_err("%s, kstrtoint failed.", __func__); goto done; } pr_debug("%s, %d value = %d\n", __func__, __LINE__, value); if (value != 0 && value != 1) goto done; mutex_lock(&data->light_mutex); if (data->light_enabled && !value) { cancel_delayed_work_sync(&data->light_work); lightsensor_onoff(0, data); } if (!data->light_enabled && value) { lightsensor_onoff(1, data); schedule_delayed_work(&data->light_work, msecs_to_jiffies(100)); } data->light_enabled = value; mutex_unlock(&data->light_mutex); done: return count; }
static int gp2a_suspend(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct gp2a_data *data = i2c_get_clientdata(client); disable_irq(data->irq); if (data->light_enabled) { cancel_delayed_work_sync(&data->light_work); lightsensor_onoff(0, data); } pr_info("%s, is called\n", __func__); return 0; }
static void gp2a_shutdown(struct i2c_client *client) { struct gp2a_data *data = i2c_get_clientdata(client); pr_info("%s, is called\n", __func__); if (data->light_enabled) { cancel_delayed_work_sync(&data->light_work); lightsensor_onoff(0, data); input_report_rel(data->light_input_dev, REL_MISC, data->lux + 1); input_sync(data->light_input_dev); } if (data->prox_enabled) { disable_irq(data->irq); disable_irq_wake(data->irq); gp2a_prox_onoff(0, data); wake_unlock(&data->prx_wake_lock); } wake_lock_destroy(&data->prx_wake_lock); mutex_destroy(&data->light_mutex); mutex_destroy(&data->data_mutex); sensors_unregister(data->prox_sensor_device, prox_sensor_attrs); sensors_unregister(data->light_sensor_device, light_sensor_attrs); sysfs_remove_group(&data->prox_input_dev->dev.kobj, &gp2a_prox_attribute_group); sensors_remove_symlink(&data->prox_input_dev->dev.kobj, data->prox_input_dev->name); input_unregister_device(data->prox_input_dev); input_free_device(data->prox_input_dev); gpio_free(data->gpio); sysfs_remove_group(&data->light_input_dev->dev.kobj, &gp2a_light_attribute_group); sensors_remove_symlink(&data->light_input_dev->dev.kobj, data->light_input_dev->name); input_unregister_device(data->light_input_dev); input_free_device(data->light_input_dev); sensor_power_on_vdd(data, 0); kfree(data); bShutdown = true; }
static int gp2a_resume(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct gp2a_data *data = i2c_get_clientdata(client); if (data->light_enabled) { lightsensor_onoff(1, data); schedule_delayed_work(&data->light_work, msecs_to_jiffies(data->light_delay)); } enable_irq(data->irq); pr_info("%s, is called\n", __func__); return 0; }
static void gp2a_shutdown(struct i2c_client *client) { struct gp2a_data *data = i2c_get_clientdata(client); pr_info("%s, is called\n", __func__); bShutdown = true; if (data->light_enabled) { cancel_delayed_work_sync(&data->light_work); lightsensor_onoff(0, data); input_report_rel(data->light_input_dev, REL_MISC, data->lux + 1); input_sync(data->light_input_dev); } input_unregister_device(data->light_input_dev); input_free_device(data->light_input_dev); #ifdef CONFIG_SENSORS_GP2A030A_PROX if (data->prox_enabled) { disable_irq(data->irq); disable_irq_wake(data->irq); gp2a_prox_onoff(0, data); wake_unlock(&data->prx_wake_lock); } wake_lock_destroy(&data->prx_wake_lock); input_unregister_device(data->prox_input_dev); input_free_device(data->prox_input_dev); gpio_free(data->gpio); if (system_rev >= 12) { gpio_free(data->con_gpio); } #ifndef CONFIG_SEC_BERLUTI_PROJECT gpio_free(data->vled_gpio); #endif #endif mutex_destroy(&data->light_mutex); mutex_destroy(&data->data_mutex); kfree(data); gp2a_regulator_onoff(&client->dev, false); }
static void gp2a_work_func_light(struct work_struct *work) { struct sensor_data *data = container_of((struct delayed_work *)work, struct sensor_data, work); int i; int adc = 0; #ifdef CONFIG_MACH_BAFFIN int count = 0; #endif #ifdef CONFIG_MACH_BAFFIN while (adc == 0 && count < 5) { adc = lightsensor_get_adcvalue(data); count++; } #else adc = lightsensor_get_adcvalue(data); #endif if (is_gp2a030a()) { for (i = 0; ARRAY_SIZE(adc_table_030a); i++) if (adc <= adc_table_030a[i]) break; } else { for (i = 0; ARRAY_SIZE(adc_table); i++) if (adc <= adc_table[i]) break; } if (data->light_buffer == i) { if (data->light_count++ == LIGHT_BUFFER_NUM) { input_report_rel(data->input_dev, REL_MISC, (adc ? adc : 1)); input_sync(data->input_dev); data->light_count = 0; } } else { data->light_buffer = i; data->light_count = 0; } #if defined(CONFIG_MACH_M3_USA_TMO) if (adc == 0) { if (data->zero_cnt++ > 25) { data->zero_cnt = 0; if (data->reset_cnt++ <= LIMIT_RESET_COUNT) { lightsensor_onoff(0); lightsensor_onoff(1); pr_info("%s : lightsensor reset done.\n", __func__); } else { data->reset_cnt = LIMIT_RESET_COUNT + 1; } } } else { data->reset_cnt = 0; data->zero_cnt = 0; } #endif if (data->enabled) queue_delayed_work(data->wq, &data->work, msecs_to_jiffies(data->delay)); }