static void asp01_open_calibration(struct asp01_data *data) { int i; int err; int count = CAL_DATA_NUM; #ifdef GRIP_DEBUG u8 reg; #endif asp01_load_caldata(data); for (i = 0; i < CAL_DATA_NUM; i++) { if (!data->cal_data[i]) count -= 1; } if (count) { asp01_restore_from_eeprom(data); err = asp01_reset(data); if (err) { pr_err("%s: asp01_reset, err=%d\n", __func__, err); return; } msleep(500); /* If MFM is not calibrated, count will be zero. */ err = asp01_init_code_set(data); if (err < ASP01_DEV_WORKING) { pr_err("%s: asp01_init_code_set, err=%d\n", __func__, err); return; } } else pr_info("%s: There is no cal data.\n", __func__); #ifdef GRIP_DEBUG /* verifiying MFM value*/ for (i = 0; i < MFM_DATA_NUM; i++) { reg = i2c_smbus_read_byte_data(data->client, REG_MFM_INIT_REF0 + i); if (reg < 0) { pr_err("%s : i2c read fail, err=%d, %d line\n", __func__, reg, __LINE__); return; } pr_info("%s: verify reg(0x%x) = 0x%x\n", __func__, REG_MFM_INIT_REF0 + i, reg); } #endif return; }
static void asp01_open_calibration(struct asp01_data *data) { struct file *cal_filp = NULL; int i; int err = 0; int count = CAL_DATA_NUM; mm_segment_t old_fs; #ifdef GRIP_DEBUG u8 reg; #endif old_fs = get_fs(); set_fs(KERNEL_DS); cal_filp = filp_open(CALIBRATION_FILE_PATH, O_RDONLY, S_IRUGO | S_IWUSR | S_IWGRP); if (IS_ERR(cal_filp)) { err = PTR_ERR(cal_filp); if (err != -ENOENT) pr_err("%s: Can't open calibration file\n", __func__); else { pr_info("%s: need calibration\n", __func__); /* calibration status init */ for (i = 0; i < CAL_DATA_NUM; i++) data->cal_data[i] = 0; } set_fs(old_fs); if (err == -ENOENT) goto set_init_code; else return; } err = cal_filp->f_op->read(cal_filp, (char *)data->cal_data, CAL_DATA_NUM * sizeof(u8), &cal_filp->f_pos); if (err != CAL_DATA_NUM * sizeof(u8)) pr_err("%s: Can't read the cal data from file\n", __func__); filp_close(cal_filp, current->files); set_fs(old_fs); set_init_code: for (i = 0; i < CAL_DATA_NUM; i++) { if (!data->cal_data[i]) count -= 1; } mutex_lock(&data->data_mutex); err = asp01_reset(data); if (err) { pr_err("%s: asp01_reset, err=%d\n", __func__, err); mutex_unlock(&data->data_mutex); return; } #ifdef USE_EEPROM if (!count) { #endif err = asp01_init_code_set(data, count); if (err < 0) { pr_err("%s: asp01_init_code_set, err=%d\n", __func__, err); mutex_unlock(&data->data_mutex); return; } #ifdef USE_EEPROM } else pr_info("%s: now use eeprom\n", __func__); #endif #ifdef GRIP_DEBUG /* verifiying MFM value*/ for (i = 0; i < MFM_DATA_NUM; i++) { reg = i2c_smbus_read_byte_data(data->client, REG_MFM_INIT_REF0 + i); if (reg < 0) { pr_err("%s : i2c read fail, err=%d, %d line\n", __func__, reg, __LINE__); err = -EIO; mutex_unlock(&data->data_mutex); return; } pr_info("%s: verify reg(0x%x) = 0x%x\n", __func__, REG_MFM_INIT_REF0 + i, reg); } #endif mutex_unlock(&data->data_mutex); return; }