static ssize_t proximity_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct gp2a_data *gp2a = dev_get_drvdata(dev); bool new_value; u8 value; int ret; #ifdef GP2AP002X_PROXIMITY_OFFSET int err; #endif 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(&gp2a->power_lock); gp2a_dbgmsg("new_value = %d, old state = %d\n", new_value, (gp2a->power_state & PROXIMITY_ENABLED) ? 1 : 0); #ifdef ALPS_DEBUG pr_info("[TMP] new_value = %d, old state = %d\n", new_value, (gp2a->power_state & PROXIMITY_ENABLED) ? 1 : 0); #endif if (new_value && !(gp2a->power_state & PROXIMITY_ENABLED)) { pr_info("[TMP] %s, %d\n", __func__, __LINE__); #if defined(CONFIG_MACH_AMAZING_CDMA) LED_onoff(1); #endif #ifdef GP2AP002X_PROXIMITY_OFFSET err = gp2a_cal_mode_read_file(&gp2a->cal_mode); if (err < 0 && err != -ENOENT) pr_err("%s: cal_mode file read fail\n", __func__); pr_info("%s: mode = %02x\n", __func__, gp2a->cal_mode); if (gp2a->cal_mode == 2) { nondetect = PROX_NONDETECT_MODE2; detect = PROX_DETECT_MODE2; } else if (gp2a->cal_mode == 1) { nondetect = PROX_NONDETECT_MODE1; detect = PROX_DETECT_MODE1; } else { nondetect = PROX_NONDETECT; detect = PROX_DETECT; } #endif gp2a->val_state = 1; input_report_abs(gp2a->proximity_input_dev, ABS_DISTANCE, gp2a->val_state); input_sync(gp2a->proximity_input_dev); gp2a->power_state |= PROXIMITY_ENABLED; gp2a->pdata->power(true); msleep(20); value = 0x18; gp2a_i2c_write(gp2a, REGS_CON, &value); #if defined(CONFIG_MACH_KYLE) value = 0x00; #else value = 0x08; #endif gp2a_i2c_write(gp2a, REGS_GAIN, &value); value = nondetect; gp2a_i2c_write(gp2a, REGS_HYS, &value); value = 0x04; gp2a_i2c_write(gp2a, REGS_CYCLE, &value); #if defined(CONFIG_MACH_GEIM) enable_irq_wake(gp2a->irq); #else enable_irq_wake(gp2a->irq); #endif value = 0x03; ret = gp2a_i2c_write(gp2a, REGS_OPMOD, &value); pr_info("%s: ret = %d\n", __func__, ret); enable_irq(gp2a->irq); value = 0x00; ret = gp2a_i2c_write(gp2a, REGS_CON, &value); pr_info("%s: ret = %d\n", __func__, ret); } else if (!new_value && (gp2a->power_state & PROXIMITY_ENABLED)) { pr_info("[TMP] %s, %d\n", __func__, __LINE__); #if defined(CONFIG_MACH_AMAZING_CDMA) LED_onoff(0); #endif #if defined(CONFIG_MACH_GEIM) disable_irq_wake(gp2a->irq); #else disable_irq_wake(gp2a->irq); #endif disable_irq(gp2a->irq); value = 0x02; gp2a_i2c_write(gp2a, REGS_OPMOD, &value); gp2a->power_state &= ~PROXIMITY_ENABLED; gp2a->pdata->power(false); } mutex_unlock(&gp2a->power_lock); return size; }
static ssize_t proximity_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct gp2a_data *gp2a = dev_get_drvdata(dev); int value = 0; int err = 0; err = kstrtoint(buf, 10, &value); if (err) { pr_err("%s,kstrtoint failed.", __func__); goto done; } if (value != 0 && value != 1) { pr_err("%s,wrong value(%d)\n", __func__, value); goto done; } mutex_lock(&gp2a->power_lock); if (gp2a->power_state != value) { pr_info("%s,enable(%d)\n", __func__, value); if (value) { err = gp2a_cal_mode_read_file(gp2a); if (err < 0 && err != -ENOENT) pr_err("%s,cal_mode file read fail\n", __func__); pr_info("%s,mode(%d)\n", __func__, gp2a->cal_mode); if (gp2a->cal_mode == 2) { gp2a->nondetect = PROX_NONDETECT_MODE2; gp2a->detect = PROX_DETECT_MODE2; } else if (gp2a->cal_mode == 1) { gp2a->nondetect = PROX_NONDETECT_MODE1; gp2a->detect = PROX_DETECT_MODE1; } else { gp2a->nondetect = PROX_NONDETECT; gp2a->detect = PROX_DETECT; } gp2a_regulator_onoff(&gp2a->i2c_client->dev, true); gp2a_power_onoff(gp2a, 1); gp2a->power_state = value; gp2a->val_state = value; input_report_abs(gp2a->input, ABS_DISTANCE, gp2a->val_state); input_sync(gp2a->input); } else { gp2a_power_onoff(gp2a, 0); gp2a_regulator_onoff(&gp2a->i2c_client->dev, false); gp2a->power_state = value; } } else { pr_err("%s,wrong cmd for enable\n", __func__); } mutex_unlock(&gp2a->power_lock); done: return size; }
static ssize_t proximity_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct gp2a_data *gp2a = dev_get_drvdata(dev); bool new_value; u8 value; #ifdef GP2AP002X_PROXIMITY_OFFSET int err; #endif 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(&gp2a->power_lock); gp2a_dbgmsg("new_value = %d, old state = %d\n", new_value, (gp2a->power_state & PROXIMITY_ENABLED) ? 1 : 0); if (new_value && !(gp2a->power_state & PROXIMITY_ENABLED)) { pr_info("%s, %d\n", __func__, __LINE__); #ifdef GP2AP002X_PROXIMITY_OFFSET pr_info("%s, %d GP2AP002X_PROXIMITY_OFFSET\n", __func__, __LINE__); err = gp2a_cal_mode_read_file(&gp2a->cal_mode); if (err < 0 && err != -ENOENT) pr_err("%s: cal_mode file read fail\n", __func__); pr_info("%s: mode = %02x\n", __func__, gp2a->cal_mode); if (gp2a->cal_mode == 2) { nondetect = PROX_NONDETECT_MODE2; detect = PROX_DETECT_MODE2; } else if (gp2a->cal_mode == 1) { nondetect = PROX_NONDETECT_MODE1; detect = PROX_DETECT_MODE1; } else { nondetect = PROX_NONDETECT; detect = PROX_DETECT; } #endif /* We send 1 for far status, 0 for close status */ gp2a->val_state = 1; input_report_abs(gp2a->proximity_input_dev, ABS_DISTANCE, gp2a->val_state); input_sync(gp2a->proximity_input_dev); gp2a->power_state |= PROXIMITY_ENABLED; msleep(20); value = 0x18; gp2a_i2c_write(gp2a, REGS_CON, &value); value = 0x08; gp2a_i2c_write(gp2a, REGS_GAIN, &value); value = nondetect; gp2a_i2c_write(gp2a, REGS_HYS, &value); value = 0x04; gp2a_i2c_write(gp2a, REGS_CYCLE, &value); enable_irq_wake(gp2a->irq); value = 0x03; gp2a_i2c_write(gp2a, REGS_OPMOD, &value); enable_irq(gp2a->irq); value = 0x00; gp2a_i2c_write(gp2a, REGS_CON, &value); } else if (!new_value && (gp2a->power_state & PROXIMITY_ENABLED)) { pr_info("%s, %d\n", __func__, __LINE__); disable_irq_wake(gp2a->irq); disable_irq(gp2a->irq); value = 0x02; gp2a_i2c_write(gp2a, REGS_OPMOD, &value); gp2a->power_state &= ~PROXIMITY_ENABLED; } mutex_unlock(&gp2a->power_lock); return size; }
static long gp2a_prox_ioctl(struct file *filp, unsigned int ioctl_cmd, unsigned long arg) { int ret = 0; short data = 0; char cal_mode=0; if( _IOC_TYPE(ioctl_cmd) != PROX_IOC_MAGIC ) { error("Wrong _IOC_TYPE 0x%x",ioctl_cmd); return -ENOTTY; } switch (ioctl_cmd) { case PROX_IOC_NORMAL_MODE: { printk(KERN_INFO "[GP2A] PROX_IOC_NORMAL_MODE\n"); if(0==proximity_enable) { if( (ret = gp2a_prox_mode(1)) < 0 ) error("PROX_IOC_NORMAL_MODE failed"); } else debug("Proximity Sensor is already Normal Mode"); break; } case PROX_IOC_SHUTDOWN_MODE: { printk(KERN_INFO "[GP2A] PROX_IOC_SHUTDOWN_MODE\n"); if(1==proximity_enable) { if( (ret = gp2a_prox_mode(0)) < 0 ) error("PROX_IOC_SHUTDOWN_MODE failed"); } else debug("Proximity Sensor is already set in Shutdown mode"); break; } case PROX_IOC_SET_CALIBRATION: { printk(KERN_INFO "[GP2A] PROX_IOC_SET_CALIBRATION\n"); if (copy_from_user(&data, (void __user *)arg, sizeof(data))) return -EFAULT; ret = gp2a_cal_mode_read_file(&cal_mode); if (ret < 0 && ret != -ENOENT) { printk(KERN_INFO "[GP2A] gp2a_cal_mode_read_file() failed\n"); }else { if(cal_mode >=0 && cal_mode <=2){ gp2a_prox_cal_mode(cal_mode); gp2a_data->cal_mode = cal_mode; printk(KERN_INFO "[GP2A] cal mode (%d)\n", gp2a_data->cal_mode); } else { gp2a_data->cal_mode = 0; } } break; } case PROX_IOC_GET_CALIBRATION: { printk(KERN_INFO "[GP2A] PROX_IOC_GET_CALIBRATION\n"); data = gp2a_data->cal_mode; if (copy_to_user((void __user *)arg, &data, sizeof(data))) return -EFAULT; break; } default: error("Unknown IOCTL command"); ret = -ENOTTY; break; } return ret; }