static int proximity_store_calibration(struct device *dev, bool do_calib) { struct gp2a_data *gp2a = dev_get_drvdata(dev); struct file *cancel_filp = NULL; mm_segment_t old_fs; int err = 0; if (do_calib) { gp2a->cal_data = proximity_adc_read(gp2a); if (is_gp2a030a()) gp2a_original_image_030a[3][1] += gp2a->cal_data; else gp2a_original_image[3][1] += gp2a->cal_data; } else { /* reset */ gp2a->cal_data = 0; if (is_gp2a030a()) gp2a_original_image_030a[3][1] = gp2a->default_threshold; else gp2a_original_image[3][1] = gp2a->default_threshold; } /* Update cal data. */ gp2a_update_threshold(gp2a, is_gp2a030a() ? gp2a_original_image_030a : gp2a_original_image, (is_gp2a030a() ? gp2a_original_image_030a[3][1] : gp2a_original_image[3][1]), true); pr_info("%s: prox_cal = %d, prox_thresh = 0x%x\n", __func__, gp2a->cal_data, (is_gp2a030a() ? gp2a_original_image_030a[3][1] : gp2a_original_image[3][1])); old_fs = get_fs(); set_fs(KERNEL_DS); cancel_filp = filp_open(CALIBRATION_FILE_PATH, O_CREAT | O_TRUNC | O_WRONLY | O_SYNC, 0666); if (IS_ERR(cancel_filp)) { pr_err("%s: Can't open cancelation file\n", __func__); set_fs(old_fs); err = PTR_ERR(cancel_filp); return err; } err = cancel_filp->f_op->write(cancel_filp, (char *)&gp2a->cal_data, sizeof(u8), &cancel_filp->f_pos); if (err != sizeof(u8)) { pr_err("%s: Can't write the cancel data to file\n", __func__); err = -EIO; } filp_close(cancel_filp, current->files); set_fs(old_fs); return err; }
static int proximity_do_calibrate(struct px3215_data *data, bool do_calib, bool thresh_set) { struct file *cal_filp; int err; int xtalk_avg = 0; mm_segment_t old_fs; if (do_calib) { if (thresh_set) { /* for proximity_thresh_store */ data->offset_value = data->threshold_high; } else { /* tap offset button */ /* get offset value */ xtalk_avg = proximity_adc_read(data); if (xtalk_avg < PX_PROX_DEFAULT_ADC) { /* do not need calibration */ data->cal_result = 0; err = 0; goto no_cal; } data->offset_value = xtalk_avg;// - PX_PROX_DEFAULT_ADC; } /* update offest */ px3215_set_calib(data->client, data->offset_value); px3215_set_plthres(data->client, PX_PROX_CAL_THREL); px3215_set_phthres(data->client, PX_PROX_CAL_THREH); /* calibration result */ data->cal_result = 1; } else { /* tap reset button */ data->offset_value = 0; /* update offest */ px3215_set_calib(data->client, data->offset_value); px3215_set_plthres(data->client, PX_PROX_DEFAULT_THREL); px3215_set_phthres(data->client, PX_PROX_DEFAULT_THREH); /* calibration result */ data->cal_result = 2; } old_fs = get_fs(); set_fs(KERNEL_DS); cal_filp = filp_open("/efs/prox_cal", O_CREAT | O_TRUNC | O_WRONLY, S_IRUGO | S_IWUSR | S_IWGRP); if (IS_ERR(cal_filp)) { pr_err("%s: Can't open calibration file\n", __func__); set_fs(old_fs); err = PTR_ERR(cal_filp); goto done; } err = cal_filp->f_op->write(cal_filp, (char *)&data->offset_value, sizeof(int), &cal_filp->f_pos); if (err != sizeof(int)) { pr_err("%s: Can't write the cal data to file\n", __func__); err = -EIO; } filp_close(cal_filp, current->files); done: set_fs(old_fs); no_cal: return err; }
static int proximity_do_calibrate(struct gp2a_data *data, bool do_calib, bool thresh_set) { struct file *cal_filp; int err; int xtalk_avg = 0; int offset_change = 0; uint16_t thrd = 0; u8 reg; mm_segment_t old_fs; if (do_calib) { if (thresh_set) { /* for proximity_thresh_store */ data->offset_value = data->threshold_high - (gp2a_reg[6][1] << 8 | gp2a_reg[5][1]); } else { /* tap offset button */ /* get offset value */ xtalk_avg = proximity_adc_read(data); offset_change = (gp2a_reg[6][1] << 8 | gp2a_reg[5][1]) - DEFAULT_HI_THR; if (xtalk_avg < offset_change) { /* do not need calibration */ data->cal_result = 0; err = 0; goto no_cal; } data->offset_value = xtalk_avg - offset_change; } /* update threshold */ thrd = (gp2a_reg[4][1] << 8 | gp2a_reg[3][1]) + (data->offset_value); THR_REG_LSB(thrd, reg); gp2a_i2c_write(data, gp2a_reg[3][0], ®); THR_REG_MSB(thrd, reg); gp2a_i2c_write(data, gp2a_reg[4][0], ®); thrd = (gp2a_reg[4][1] << 8 | gp2a_reg[5][1]) +(data->offset_value); THR_REG_LSB(thrd, reg); gp2a_i2c_write(data, gp2a_reg[5][0], ®); THR_REG_MSB(thrd, reg); gp2a_i2c_write(data, gp2a_reg[6][0], ®); /* calibration result */ if (!thresh_set) data->cal_result = 1; } else { /* tap reset button */ data->offset_value = 0; /* update threshold */ gp2a_i2c_write(data, gp2a_reg[3][0], &gp2a_reg[3][1]); gp2a_i2c_write(data, gp2a_reg[4][0], &gp2a_reg[4][1]); gp2a_i2c_write(data, gp2a_reg[5][0], &gp2a_reg[5][1]); gp2a_i2c_write(data, gp2a_reg[6][0], &gp2a_reg[6][1]); /* calibration result */ data->cal_result = 2; } old_fs = get_fs(); set_fs(KERNEL_DS); cal_filp = filp_open(data->pdata->prox_cal_path, O_CREAT | O_TRUNC | O_WRONLY, S_IRUGO | S_IWUSR | S_IWGRP); if (IS_ERR(cal_filp)) { pr_err("%s: Can't open calibration file\n", __func__); set_fs(old_fs); err = PTR_ERR(cal_filp); goto done; } err = cal_filp->f_op->write(cal_filp, (char *)&data->offset_value, sizeof(int), &cal_filp->f_pos); if (err != sizeof(int)) { pr_err("%s: Can't write the cal data to file\n", __func__); err = -EIO; } filp_close(cal_filp, current->files); done: set_fs(old_fs); no_cal: return err; }
static int proximity_store_offset(struct device *dev, bool do_calib) { struct gp2a_data *gp2a = dev_get_drvdata(dev); struct file *offset_filp = NULL; mm_segment_t old_fs; int err = 0; int xtalk_avg = 0; int offset_change = 0; u8 thrd = 0; if (do_calib) { /* tap offset button */ /* get offset value */ xtalk_avg = proximity_adc_read(gp2a); offset_change = gp2a_original_image[5][1] - DEFAULT_HI_THRESHOLD; if(xtalk_avg < offset_change){ //don't need to calibrate /* calibration result */ gp2a->cal_result = 0; return err; } gp2a->offset_value = xtalk_avg - offset_change; /* update threshold */ thrd = gp2a_original_image[3][1]+(gp2a->offset_value); opt_i2c_write(gp2a_original_image[3][0], &thrd); thrd = gp2a_original_image[5][1]+(gp2a->offset_value); opt_i2c_write(gp2a_original_image[5][0], &thrd); /* calibration result */ gp2a->cal_result = 1; } else{ /* tap reset button */ gp2a->offset_value = 0; /* update threshold */ opt_i2c_write(gp2a_original_image[3][0], &gp2a_original_image[3][1]); opt_i2c_write(gp2a_original_image[5][0], &gp2a_original_image[5][1]); /* calibration result */ gp2a->cal_result = 2; } printk(KERN_INFO "[GP2A] %s : offset_value=%d\n",__func__, gp2a->offset_value); old_fs = get_fs(); set_fs(KERNEL_DS); offset_filp = filp_open(OFFSET_FILE_PATH, O_CREAT | O_TRUNC | O_WRONLY, 0666); if (IS_ERR(offset_filp)) { pr_err("%s: Can't open prox_offset file\n", __func__); set_fs(old_fs); err = PTR_ERR(offset_filp); return err; } err = offset_filp->f_op->write(offset_filp, (char *)&gp2a->offset_value, sizeof(u8), &offset_filp->f_pos); if (err != sizeof(u8)) { pr_err("%s: Can't write the offset data to file\n", __func__); err = -EIO; } filp_close(offset_filp, current->files); set_fs(old_fs); return err; }