void sync_sensor_state(struct ssp_data *data) { unsigned char uBuf[2] = {0,}; unsigned int uSensorCnt; int iRet = 0; proximity_open_calibration(data); iRet = set_hw_offset(data); if (iRet < 0) { pr_err("[SSP]: %s - set_hw_offset failed\n", __func__); } udelay(10); for (uSensorCnt = 0; uSensorCnt < (SENSOR_MAX - 1); uSensorCnt++) { if (atomic_read(&data->aSensorEnable) & (1 << uSensorCnt)) { uBuf[1] = (u8)get_msdelay(data->adDelayBuf[uSensorCnt]); uBuf[0] = (u8)get_delay_cmd(uBuf[1]); send_instruction(data, ADD_SENSOR, uSensorCnt, uBuf, 2); udelay(10); } } if (data->bProximityRawEnabled == true) { uBuf[0] = 1; uBuf[1] = 20; send_instruction(data, ADD_SENSOR, PROXIMITY_RAW, uBuf, 2); } }
static int ssp_remove_sensor(struct ssp_data *data, unsigned int uChangedSensor, unsigned int uNewEnable) { u8 uBuf[2]; int64_t dSensorDelay = data->adDelayBuf[uChangedSensor]; ssp_dbg("[SSP]: %s - remove sensor = %d, current state = %d\n", __func__, (1 << uChangedSensor), uNewEnable); data->adDelayBuf[uChangedSensor] = DEFUALT_POLLING_DELAY; if (data->aiCheckStatus[uChangedSensor] == INITIALIZATION_STATE) { data->aiCheckStatus[uChangedSensor] = NO_SENSOR_STATE; if (uChangedSensor == ACCELEROMETER_SENSOR) accel_open_calibration(data); else if (uChangedSensor == GYROSCOPE_SENSOR) gyro_open_calibration(data); else if (uChangedSensor == PRESSURE_SENSOR) pressure_open_calibration(data); else if (uChangedSensor == PROXIMITY_SENSOR) proximity_open_calibration(data); return 0; } else if (uChangedSensor == ORIENTATION_SENSOR) { if (!(atomic_read(&data->aSensorEnable) & (1 << ACCELEROMETER_SENSOR))) uChangedSensor = ACCELEROMETER_SENSOR; else { change_sensor_delay(data, ACCELEROMETER_SENSOR, data->adDelayBuf[ACCELEROMETER_SENSOR]); return 0; } } else if (uChangedSensor == ACCELEROMETER_SENSOR) { if (atomic_read(&data->aSensorEnable) & (1 << ORIENTATION_SENSOR)) { change_sensor_delay(data, ORIENTATION_SENSOR, data->adDelayBuf[ORIENTATION_SENSOR]); return 0; } } if (!uNewEnable) { if (data->bCheckSuspend == false) { disable_debug_timer(data); data->bDebugEnabled = false; } } uBuf[1] = (u8)get_msdelay(dSensorDelay); uBuf[0] = (u8)get_delay_cmd(uBuf[1]); send_instruction(data, REMOVE_SENSOR, uChangedSensor, uBuf, 2); data->aiCheckStatus[uChangedSensor] = NO_SENSOR_STATE; return 0; }
int forced_to_download_binary(struct ssp_data *data, int iBinType) { int iRet = 0; int retry = 3; ssp_dbg("[SSP] %s, mcu binany update!\n", __func__); ssp_enable(data, false); #if SSP_STATUS_MONITOR cancel_delayed_work_sync(&data->polling_work); #endif data->fw_dl_state = FW_DL_STATE_DOWNLOADING; pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state); data->spi->max_speed_hz = BOOT_SPI_HZ; if (spi_setup(data->spi)) pr_err("failed to setup spi for ssp_boot\n"); do { pr_info("[SSP] %d try\n", 3 - retry); iRet = update_mcu_bin(data, iBinType); } while (retry -- > 0 && iRet < 0); data->spi->max_speed_hz = NORM_SPI_HZ; if (spi_setup(data->spi)) pr_err("failed to setup spi for ssp_norm\n"); if (iRet < 0) { ssp_dbg("[SSP] %s, update_mcu_bin failed!\n", __func__); goto out; } data->fw_dl_state = FW_DL_STATE_SYNC; pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state); ssp_enable(data, true); get_proximity_threshold(data); proximity_open_calibration(data); accel_open_calibration(data); gyro_open_calibration(data); pressure_open_calibration(data); data->fw_dl_state = FW_DL_STATE_DONE; pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state); #if SSP_STATUS_MONITOR schedule_delayed_work(&data->polling_work, msecs_to_jiffies(7000)); #endif iRet = SUCCESS; out: return iRet; }
int forced_to_download_binary(struct ssp_data *data, int iBinType) { int iRet = 0; int retry = 3; ssp_dbg("[SSP] %s, mcu binany update!\n", __func__); ssp_enable(data, false); data->fw_dl_state = FW_DL_STATE_DOWNLOADING; data->spi->mode = SPI_MODE_0; pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state); data->spi->max_speed_hz = BOOT_SPI_HZ; if (spi_setup(data->spi)) pr_err("failed to setup spi for ssp_boot\n"); do { pr_info("[SSP] %d try\n", 3 - retry); iRet = update_mcu_bin(data, iBinType); pr_info("======[SSP] SCHEDULE!!!!!\n"); schedule(); /*Defence for cpu schedule blocking watchdog*/ msleep(3); } while (retry -- > 0 && iRet < 0); data->spi->max_speed_hz = NORM_SPI_HZ; data->spi->mode = SPI_MODE_1; if (spi_setup(data->spi)) pr_err("failed to setup spi for ssp_norm\n"); if (iRet < 0) { ssp_dbg("[SSP] %s, update_mcu_bin failed!\n", __func__); goto out; } data->fw_dl_state = FW_DL_STATE_SYNC; pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state); ssp_enable(data, true); proximity_open_lcd_ldi(data); proximity_open_calibration(data); accel_open_calibration(data); gyro_open_calibration(data); pressure_open_calibration(data); data->fw_dl_state = FW_DL_STATE_DONE; pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state); iRet = SUCCESS; out: return iRet; }
static ssize_t proximity_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 = 0; char input; int err = 0; err = kstrtoint(buf, 10, &value); if (err) pr_err("%s, kstrtoint failed.", __func__); if (value != 0 && value != 1) return count; gprintk("value = %d\n", value); if (data->enabled && !value) { /* Proximity power off */ disable_irq(data->irq); proximity_enable = value; proximity_onoff(0); disable_irq_wake(data->irq); data->pdata->gp2a_led_on(false); } else if (!data->enabled && value) { /* proximity power on */ data->pdata->gp2a_led_on(true); /*msleep(1); */ #ifdef GP2A_CALIBRATION /* open cancelation data */ err = proximity_open_calibration(data); if (err < 0 && err != -ENOENT) pr_err("%s: proximity_open_calibration() failed\n", __func__); #endif proximity_enable = value; proximity_onoff(1); enable_irq_wake(data->irq); input = gpio_get_value(data->pdata->p_out); input_report_abs(data->input_dev, ABS_DISTANCE, input); input_sync(data->input_dev); enable_irq(data->irq); } data->enabled = value; return count; }
static long gp2a_opt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { int ret = 0; short data = 0; u8 thrd = 0; u8 reg; switch (cmd) { 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 = proximity_open_calibration(gp2a_opt_data); if (ret < 0 && ret != -ENOENT) { printk(KERN_INFO "[GP2A] proximity_open_offset() failed\n"); }else { thrd = gp2a_reg[3][1]+(gp2a_opt_data->offset_value); THR_REG_LSB(thrd, reg); gp2a_i2c_write(gp2a_reg[3][0], ®); THR_REG_MSB(thrd, reg); gp2a_i2c_write(gp2a_reg[4][0], ®); thrd = gp2a_reg[5][1]+(gp2a_opt_data->offset_value); THR_REG_LSB(thrd, reg); gp2a_i2c_write(gp2a_reg[5][0], ®); THR_REG_MSB(thrd, reg); gp2a_i2c_write(gp2a_reg[6][0], ®); } break; } case PROX_IOC_GET_CALIBRATION: { printk(KERN_INFO "[GP2A] PROX_IOC_GET_CALIBRATION\n"); data = gp2a_opt_data->offset_value; if (copy_to_user((void __user *)arg, &data, sizeof(data))) return -EFAULT; break; } default: printk(KERN_ERR "Unknown IOCTL command"); ret = -ENOTTY; break; } return ret; }
int forced_to_download_binary(struct ssp_data *data, int iBinType) { int iRet = 0; int retry = 3; ssp_dbg("[SSP]: %s - mcu binany update!\n", __func__); ssp_enable(data, false); data->fw_dl_state = FW_DL_STATE_DOWNLOADING; pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state); data->spi->max_speed_hz = BOOT_SPI_HZ; if (spi_setup(data->spi)) pr_err("failed to setup spi for ssp_boot\n"); do { pr_info("[SSP] %d try\n", 3 - retry); iRet = update_mcu_bin(data, iBinType); } while (retry -- > 0 && iRet < 0); data->spi->max_speed_hz = NORM_SPI_HZ; if (spi_setup(data->spi)) pr_err("failed to setup spi for ssp_norm\n"); if (iRet < 0) { ssp_dbg("[SSP]: %s - update_mcu_bin failed!\n", __func__); goto out; } data->fw_dl_state = FW_DL_STATE_SYNC; pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state); ssp_enable(data, true); proximity_open_lcd_ldi(data); proximity_open_calibration(data); accel_open_calibration(data); gyro_open_calibration(data); #ifdef CONFIG_SENSORS_SSP_BMP182 pressure_open_calibration(data); #endif data->fw_dl_state = FW_DL_STATE_DONE; pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state); iRet = SUCCESS; out: return iRet; }
static ssize_t set_sensors_enable(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int64_t dTemp; unsigned int uNewEnable = 0, uChangedSensor = 0; struct ssp_data *data = dev_get_drvdata(dev); int iRet; if (strict_strtoll(buf, 10, &dTemp) < 0) return -1; uNewEnable = (unsigned int)dTemp; ssp_dbg("[SSP]: %s - new_enable = %u, old_enable = %u\n", __func__, uNewEnable, atomic_read(&data->aSensorEnable)); if (uNewEnable == atomic_read(&data->aSensorEnable)) return 0; for (uChangedSensor = 0; uChangedSensor < SENSOR_MAX; uChangedSensor++) if ((atomic_read(&data->aSensorEnable) & (1 << uChangedSensor)) != (uNewEnable & (1 << uChangedSensor))) { if (!(uNewEnable & (1 << uChangedSensor))) ssp_remove_sensor(data, uChangedSensor, uNewEnable); /* disable */ else { /* Change to ADD_SENSOR_STATE from KitKat */ if (data->aiCheckStatus[uChangedSensor] == INITIALIZATION_STATE) { if (uChangedSensor == ACCELEROMETER_SENSOR) accel_open_calibration(data); else if (uChangedSensor == GYROSCOPE_SENSOR) gyro_open_calibration(data); else if (uChangedSensor == PRESSURE_SENSOR) pressure_open_calibration(data); else if (uChangedSensor == PROXIMITY_SENSOR) { proximity_open_lcd_ldi(data); proximity_open_calibration(data); } } data->aiCheckStatus[uChangedSensor] = ADD_SENSOR_STATE; } break; } atomic_set(&data->aSensorEnable, uNewEnable); return size; }
int forced_to_download_binary(struct ssp_data *data, int iBinType) { int iRet = 0; int retry = 3; ssp_infof("mcu binany update!"); ssp_enable(data, false); data->fw_dl_state = FW_DL_STATE_DOWNLOADING; ssp_infof("DL state = %d", data->fw_dl_state); data->spi->max_speed_hz = BOOT_SPI_HZ; if (spi_setup(data->spi)) ssp_err("failed to setup spi for ssp_boot"); do { ssp_info("%d try", 3 - retry); iRet = update_mcu_bin(data, iBinType); } while (retry-- > 0 && iRet < 0); data->spi->max_speed_hz = NORM_SPI_HZ; if (spi_setup(data->spi)) ssp_err("failed to setup spi for ssp_norm"); if (iRet < 0) { ssp_infof("update_mcu_bin failed!"); goto out; } data->fw_dl_state = FW_DL_STATE_SYNC; ssp_infof("DL state = %d", data->fw_dl_state); ssp_enable(data, true); get_proximity_threshold(data); proximity_open_calibration(data); accel_open_calibration(data); gyro_open_calibration(data); pressure_open_calibration(data); data->fw_dl_state = FW_DL_STATE_DONE; ssp_infof("DL state = %d", data->fw_dl_state); iRet = SUCCESS; out: return iRet; }
static ssize_t proximity_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct input_dev *input = to_input_dev(dev); struct px3215_data *data = input_get_drvdata(input); int enable = simple_strtoul(buf, NULL,10); int err = 0; if (enable) { err = proximity_open_calibration(data); if (err < 0 && err != -ENOENT) pr_err("%s: proximity_open_offset() failed\n", __func__); else { if (data->cal_result==1) { 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); } } input_report_abs(data->input, ABS_DISTANCE, 1); input_sync(data->input); px3215_set_mode(data->client, 2); enable_irq(data->irq); enable_irq_wake(data->irq); } else { disable_irq_wake(data->irq); disable_irq(data->irq); px3215_set_mode(data->client, 0); } return size; }
static ssize_t proximity_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 = 0; char input; int err = 0; int16_t thrd; u8 reg; err = kstrtoint(buf, 10, &value); if (err) { pr_err("%s, kstrtoint failed.", __func__); goto done; } if (value != 0 && value != 1) goto done; pr_info("%s, %d value = %d\n", __func__, __LINE__, value); if (data->proximity_enabled && !value) { /* Prox power off */ disable_irq(data->irq); proximity_onoff(0, data); disable_irq_wake(data->irq); if (data->pdata->led_on) data->pdata->led_on(false); } if (!data->proximity_enabled && value) { /* prox power on */ if (data->pdata->led_on) data->pdata->led_on(true); usleep_range(1000, 1100); proximity_onoff(1, data); err = proximity_open_calibration(data); if (err < 0 && err != -ENOENT) pr_err("%s: proximity_open_offset() failed\n", __func__); else { thrd = 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[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], ®); } enable_irq_wake(data->irq); msleep(160); input = gpio_get_value_cansleep(data->pdata->p_out); if (input == 0) { input_report_abs(data->proximity_input_dev, ABS_DISTANCE, 1); input_sync(data->proximity_input_dev); } enable_irq(data->irq); } data->proximity_enabled = value; done: return count; }
int forced_to_download_binary(struct ssp_data *data, int iBinType) { int iRet = 0; int retry = 3; ssp_dbg("[SSP]: %s - mcu binany update!\n", __func__); ssp_enable(data, false); data->fw_dl_state = FW_DL_STATE_DOWNLOADING; pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state); data->spi->max_speed_hz = BOOT_SPI_HZ; if (spi_setup(data->spi)) pr_err("failed to setup spi for ssp_boot\n"); do { pr_info("[SSP] %d try\n", 3 - retry); iRet = update_mcu_bin(data, iBinType); } while (retry -- > 0 && iRet < 0); data->spi->max_speed_hz = NORM_SPI_HZ; if (spi_setup(data->spi)) pr_err("failed to setup spi for ssp_norm\n"); if (iRet < 0) { ssp_dbg("[SSP]: %s - update_mcu_bin failed!\n", __func__); goto out; } data->fw_dl_state = FW_DL_STATE_SYNC; pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state); clean_pending_list(data); ssp_enable(data, true); iRet = initialize_mcu(data); if (iRet < 0) { iRet = ERROR; ssp_dbg("[SSP]: %s - initialize_mcu failed!\n", __func__); goto out; } proximity_open_lcd_ldi(data); proximity_open_calibration(data); accel_open_calibration(data); gyro_open_calibration(data); pressure_open_calibration(data); if (mag_open_hwoffset(data) < 0) pr_info("[SSP]: %s - mag_open_hw_offset" " failed, %d\n", __func__, iRet); sync_sensor_state(data); #ifdef CONFIG_SENSORS_SSP_SENSORHUB ssp_sensorhub_report_notice(data, MSG2SSP_AP_STATUS_RESET); #endif data->fw_dl_state = FW_DL_STATE_DONE; pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state); iRet = SUCCESS; out: return iRet; }
static void change_sensor_delay(struct ssp_data *data, int iSensorType, int64_t dNewDelay) { u8 uBuf[2]; unsigned int uNewEnable = 0; int64_t dTempDelay = data->adDelayBuf[iSensorType]; if (!(atomic_read(&data->aSensorEnable) & (1 << iSensorType))) { data->aiCheckStatus[iSensorType] = NO_SENSOR_STATE; return; } data->adDelayBuf[iSensorType] = dNewDelay; if (iSensorType == ORIENTATION_SENSOR) iSensorType = ACCELEROMETER_SENSOR; switch (data->aiCheckStatus[iSensorType]) { case ADD_SENSOR_STATE: ssp_dbg("[SSP]: %s - add %u, New = %lldns\n", __func__, 1 << iSensorType, dNewDelay); uBuf[1] = (u8)get_msdelay(dNewDelay); uBuf[0] = (u8)get_delay_cmd(uBuf[1]); if (send_instruction(data, ADD_SENSOR, iSensorType, uBuf, 2) != SUCCESS) { uNewEnable = (unsigned int)atomic_read(&data->aSensorEnable) & (~(unsigned int)(1 << iSensorType)); atomic_set(&data->aSensorEnable, uNewEnable); data->aiCheckStatus[iSensorType] = NO_SENSOR_STATE; data->uMissSensorCnt++; break; } data->aiCheckStatus[iSensorType] = RUNNING_SENSOR_STATE; if (iSensorType == PROXIMITY_SENSOR) { proximity_open_lcd_ldi(data); proximity_open_calibration(data); input_report_abs(data->prox_input_dev, ABS_DISTANCE, 1); input_sync(data->prox_input_dev); } break; case RUNNING_SENSOR_STATE: if (get_msdelay(dTempDelay) == get_msdelay(data->adDelayBuf[iSensorType])) break; ssp_dbg("[SSP]: %s - Change %u, New = %lldns\n", __func__, 1 << iSensorType, dNewDelay); uBuf[1] = (u8)get_msdelay(dNewDelay); uBuf[0] = (u8)get_delay_cmd(uBuf[1]); send_instruction(data, CHANGE_DELAY, iSensorType, uBuf, 2); break; default: data->aiCheckStatus[iSensorType] = ADD_SENSOR_STATE; } }
static int ssp_remove_sensor(struct ssp_data *data, unsigned int uChangedSensor, unsigned int uNewEnable) { u8 uBuf[2]; int iRet = 0; int64_t dSensorDelay = data->adDelayBuf[uChangedSensor]; ssp_dbg("[SSP]: %s - remove sensor = %d, current state = %d\n", __func__, (1 << uChangedSensor), uNewEnable); data->adDelayBuf[uChangedSensor] = DEFUALT_POLLING_DELAY; if (data->aiCheckStatus[uChangedSensor] == INITIALIZATION_STATE) { data->aiCheckStatus[uChangedSensor] = NO_SENSOR_STATE; if (uChangedSensor == ACCELEROMETER_SENSOR) accel_open_calibration(data); else if (uChangedSensor == GYROSCOPE_SENSOR) gyro_open_calibration(data); else if (uChangedSensor == PRESSURE_SENSOR) pressure_open_calibration(data); else if (uChangedSensor == PROXIMITY_SENSOR) { proximity_open_lcd_ldi(data); proximity_open_calibration(data); } else if (uChangedSensor == GEOMAGNETIC_SENSOR) { iRet = mag_open_hwoffset(data); if (iRet < 0) pr_err("[SSP]: %s - mag_open_hw_offset" " failed, %d\n", __func__, iRet); iRet = set_hw_offset(data); if (iRet < 0) { pr_err("[SSP]: %s - set_hw_offset failed\n", __func__); } } return 0; } else if (uChangedSensor == ORIENTATION_SENSOR) { if (!(atomic_read(&data->aSensorEnable) & (1 << ACCELEROMETER_SENSOR))) { uChangedSensor = ACCELEROMETER_SENSOR; } else { change_sensor_delay(data, ACCELEROMETER_SENSOR, data->adDelayBuf[ACCELEROMETER_SENSOR]); return 0; } } else if (uChangedSensor == ACCELEROMETER_SENSOR) { if (atomic_read(&data->aSensorEnable) & (1 << ORIENTATION_SENSOR)) { change_sensor_delay(data, ORIENTATION_SENSOR, data->adDelayBuf[ORIENTATION_SENSOR]); return 0; } } else if (uChangedSensor == GEOMAGNETIC_SENSOR) { if (mag_store_hwoffset(data)) pr_err("mag_store_hwoffset success\n"); } if (atomic_read(&data->aSensorEnable) & (1 << uChangedSensor)) { uBuf[1] = (u8)get_msdelay(dSensorDelay); uBuf[0] = (u8)get_delay_cmd(uBuf[1]); send_instruction(data, REMOVE_SENSOR, uChangedSensor, uBuf, 2); } data->aiCheckStatus[uChangedSensor] = NO_SENSOR_STATE; return 0; }