int print_mcu_debug(char *pchRcvDataFrame, int *pDataIdx, int iRcvDataFrameLength) { u16 length; int cur = *pDataIdx; memcpy(&length, pchRcvDataFrame + *pDataIdx, 2); *pDataIdx += 2; if (length > iRcvDataFrameLength - *pDataIdx || length <= 0) { ssp_dbg("[SSP]: MSG From MCU - invalid debug length(%u/%d/%d)\n", length, iRcvDataFrameLength, cur); return length ? length : ERROR; } ssp_dbg("[SSP]: MSG From MCU - %s\n", &pchRcvDataFrame[*pDataIdx]); *pDataIdx += length; return 0; }
static ssize_t proximity_thresh_show(struct device *dev, struct device_attribute *attr, char *buf) { struct ssp_data *data = dev_get_drvdata(dev); ssp_dbg("[SSP]: uProxThresh = %u\n", data->uProxThresh); return sprintf(buf, "%u\n", data->uProxThresh); }
static ssize_t show_enable_irq(struct device *dev, struct device_attribute *attr, char *buf) { struct ssp_data *data = dev_get_drvdata(dev); ssp_dbg("[SSP]: %s - %d\n", __func__, !data->bSspShutdown); return sprintf(buf, "%d\n", !data->bSspShutdown); }
static int accel_do_calibrate(struct ssp_data *data, int iEnable) { int iSum[3] = { 0, }; int iRet = 0, iCount; struct file *cal_filp = NULL; mm_segment_t old_fs; if (iEnable) { data->accelcal.x = 0; data->accelcal.y = 0; data->accelcal.z = 0; for (iCount = 0; iCount < CALIBRATION_DATA_AMOUNT; iCount++) { iSum[0] += data->buf[ACCELEROMETER_SENSOR].x; iSum[1] += data->buf[ACCELEROMETER_SENSOR].y; iSum[2] += (data->buf[ACCELEROMETER_SENSOR].z - 1024); mdelay(10); } data->accelcal.x = (iSum[0] / CALIBRATION_DATA_AMOUNT); data->accelcal.y = (iSum[1] / CALIBRATION_DATA_AMOUNT); data->accelcal.z = (iSum[2] / CALIBRATION_DATA_AMOUNT); } else { data->accelcal.x = 0; data->accelcal.y = 0; data->accelcal.z = 0; } ssp_dbg("[SSP] : do accel calibrate %d, %d, %d\n", data->accelcal.x, data->accelcal.y, data->accelcal.z); old_fs = get_fs(); set_fs(KERNEL_DS); cal_filp = filp_open(CALIBRATION_FILE_PATH, O_CREAT | O_TRUNC | O_WRONLY, 0666); if (IS_ERR(cal_filp)) { pr_err("%s: [SSP] Can't open calibration file\n", __func__); set_fs(old_fs); iRet = PTR_ERR(cal_filp); return iRet; } iRet = cal_filp->f_op->write(cal_filp, (char *)&data->accelcal, 3 * sizeof(int), &cal_filp->f_pos); if (iRet != 3 * sizeof(int)) { pr_err("%s: [SSP] Can't write the accelcal to file\n", __func__); iRet = -EIO; } filp_close(cal_filp, current->files); set_fs(old_fs); return iRet; }
static ssize_t accel_reactive_alert_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { char chTempBuf[2] = {0, 10}; int iRet, iDelayCnt = 0; struct ssp_data *data = dev_get_drvdata(dev); if (sysfs_streq(buf, "1")) ssp_dbg("[SSP]: %s - on\n", __func__); else if (sysfs_streq(buf, "0")) ssp_dbg("[SSP]: %s - off\n", __func__); else if (sysfs_streq(buf, "2")) { ssp_dbg("[SSP]: %s - factory\n", __func__); data->uFactorydataReady = 0; memset(data->uFactorydata, 0, sizeof(char) * FACTORY_DATA_MAX); data->bAccelAlert = false; iRet = send_instruction(data, FACTORY_MODE, ACCELEROMETER_FACTORY, chTempBuf, 2); while (!(data->uFactorydataReady & (1 << ACCELEROMETER_FACTORY)) && (iDelayCnt++ < 150) && (iRet == SUCCESS)) msleep(20); if ((iDelayCnt >= 150) || (iRet != SUCCESS)) { pr_err("[SSP]: %s - accel Selftest Timeout!!\n", __func__); goto exit; } mdelay(5); data->bAccelAlert = data->uFactorydata[0]; ssp_dbg("[SSP]: %s factory test success!\n", __func__); } else { pr_err("[SSP]: %s - invalid value %d\n", __func__, *buf); return -EINVAL; } exit: return size; }
static ssize_t show_sensors_enable(struct device *dev, struct device_attribute *attr, char *buf) { struct ssp_data *data = dev_get_drvdata(dev); ssp_dbg("[SSP]: %s - cur_enable = %d\n", __func__, atomic_read(&data->aSensorEnable)); return sprintf(buf, "%9u\n", atomic_read(&data->aSensorEnable)); }
void print_mcu_debug(char *pchRcvDataFrame, int *pDataIdx) { int iLength; iLength = pchRcvDataFrame[0]; pchRcvDataFrame[iLength] = 0; *pDataIdx = *pDataIdx + iLength + 2; ssp_dbg("[SSP] MSG From MCU : %s\n", pchRcvDataFrame + 1); }
static ssize_t ir_current_show(struct device *dev, struct device_attribute *attr, char *buf) { struct ssp_data *data = dev_get_drvdata(dev); ssp_dbg("[SSP]: %s - Ir_Current Setting = %d\n", __func__, data->uIr_Current); return sprintf(buf, "%d\n", data->uIr_Current); }
static void get_factory_data(struct ssp_data *data, int iSensorData, char *pchRcvDataFrame, int *iDataIdx) { int iIdx, iTotalLenth = 0; unsigned int uTemp = 0; switch (iSensorData) { case ACCELEROMETER_FACTORY: uTemp = (1 << ACCELEROMETER_FACTORY); iTotalLenth = ACCEL_FACTORY_DATA_LENGTH; break; case GYROSCOPE_FACTORY: uTemp = (1 << GYROSCOPE_FACTORY); iTotalLenth = GYRO_FACTORY_DATA_LENGTH; break; case GEOMAGNETIC_FACTORY: uTemp = (1 << GEOMAGNETIC_FACTORY); iTotalLenth = MAGNETIC_FACTORY_DATA_LENGTH; break; case PRESSURE_FACTORY: uTemp = (1 << PRESSURE_FACTORY); iTotalLenth = PRESSURE_FACTORY_DATA_LENGTH; break; case MCU_FACTORY: uTemp = (1 << MCU_FACTORY); iTotalLenth = MCU_FACTORY_DATA_LENGTH; break; case GYROSCOPE_TEMP_FACTORY: uTemp = (1 << GYROSCOPE_TEMP_FACTORY); iTotalLenth = GYRO_TEMP_FACTORY_DATA_LENGTH; break; case GYROSCOPE_DPS_FACTORY: uTemp = (1 << GYROSCOPE_DPS_FACTORY); iTotalLenth = GYRO_DPS_FACTORY_DATA_LENGTH; break; case MCU_SLEEP_FACTORY: uTemp = (1 << MCU_SLEEP_FACTORY); iTotalLenth = MCU_SLEEP_FACTORY_DATA_LENGTH; break; case GESTURE_FACTORY: uTemp = (1 << GESTURE_FACTORY); iTotalLenth = GESTURE_FACTORY_DATA_LENGTH; break; case TEMPHUMIDITY_CRC_FACTORY: uTemp = (1 << TEMPHUMIDITY_CRC_FACTORY); iTotalLenth = TEMPHUMIDITY_FACTORY_DATA_LENGTH; break; } ssp_dbg("[SSP]: %s - Factory test data %d\n", __func__, iSensorData); for (iIdx = 0; iIdx < iTotalLenth; iIdx++) data->uFactorydata[iIdx] = (u8)pchRcvDataFrame[(*iDataIdx)++]; data->uFactorydataReady = uTemp; }
static void debug_work_func(struct work_struct *work) { unsigned int uSensorCnt; struct ssp_data *data = container_of(work, struct ssp_data, work_debug); ssp_dbg("[SSP]: %s(%u) - Sensor state: 0x%x, RC: %u, MS: %u\n", __func__, data->uIrqCnt, data->uSensorState, data->uResetCnt, data->uMissSensorCnt); if (data->fw_dl_state >= FW_DL_STATE_DOWNLOADING && data->fw_dl_state < FW_DL_STATE_DONE) { pr_info("[SSP] : %s firmware downloading state = %d\n", __func__, data->fw_dl_state); return; } else if (data->fw_dl_state == FW_DL_STATE_FAIL) { pr_err("[SSP] : %s firmware download failed = %d\n", __func__, data->fw_dl_state); return; } for (uSensorCnt = 0; uSensorCnt < (SENSOR_MAX - 1); uSensorCnt++) if (atomic_read(&data->aSensorEnable) & (1 << uSensorCnt)) print_sensordata(data, uSensorCnt); if ((atomic_read(&data->aSensorEnable) & SSP_BYPASS_SENSORS_EN_ALL)\ && (data->uIrqCnt == 0)) data->uIrqFailCnt++; else data->uIrqFailCnt = 0; if (((data->uSsdFailCnt >= LIMIT_SSD_FAIL_CNT) || (data->uInstFailCnt >= LIMIT_INSTRUCTION_FAIL_CNT) || (data->uIrqFailCnt >= LIMIT_IRQ_FAIL_CNT) || ((data->uTimeOutCnt + data->uBusyCnt) > LIMIT_TIMEOUT_CNT)) && (data->bSspShutdown == false)) { if (data->uResetCnt < LIMIT_RESET_CNT) { pr_info("[SSP] : %s - uSsdFailCnt(%u), uInstFailCnt(%u),"\ "uIrqFailCnt(%u), uTimeOutCnt(%u), uBusyCnt(%u)\n", __func__, data->uSsdFailCnt, data->uInstFailCnt, data->uIrqFailCnt, data->uTimeOutCnt, data->uBusyCnt); reset_mcu(data); data->uResetCnt++; } else ssp_enable(data, false); data->uSsdFailCnt = 0; data->uInstFailCnt = 0; data->uTimeOutCnt = 0; data->uBusyCnt = 0; data->uIrqFailCnt = 0; } data->uIrqCnt = 0; }
static void change_sensor_delay(struct ssp_data *data, int iSensorType, int64_t dNewDelay) { u8 uBuf[2]; int64_t dTempDelay = data->adDelayBuf[iSensorType]; 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]); send_instruction(data, ADD_SENSOR, iSensorType, uBuf, 2); data->aiCheckStatus[iSensorType] = RUNNING_SENSOR_STATE; if (iSensorType == PROXIMITY_SENSOR) { input_report_abs(data->prox_input_dev, ABS_DISTANCE, 1); input_sync(data->prox_input_dev); } break; case RUNNING_SENSOR_STATE: if (dTempDelay == 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; } }
int forced_to_download_binary(struct ssp_data *data, int iBinType) { int iRet = 0; ssp_dbg("[SSP]: %s - mcu binany update!\n", __func__); if (data->bSspShutdown == false) { data->bSspShutdown = true; disable_irq_wake(data->iIrq); disable_irq(data->iIrq); } iRet = update_mcu_bin(data, iBinType); if (iRet < 0) { iRet = ERROR; ssp_dbg("[SSP]: %s - update_mcu_bin failed!\n", __func__); goto out; } iRet = initialize_mcu(data); if (iRet < 0) { iRet = ERROR; ssp_dbg("[SSP]: %s - initialize_mcu failed!\n", __func__); goto out; } sync_sensor_state(data); #ifdef CONFIG_SENSORS_SSP_SENSORHUB ssp_sensorhub_report_notice(data, MSG2SSP_AP_STATUS_RESET); #endif if (data->bSspShutdown == true) { data->bSspShutdown = false; enable_irq(data->iIrq); enable_irq_wake(data->iIrq); } iRet = SUCCESS; out: return iRet; }
static ssize_t proximity_cancel_show(struct device *dev, struct device_attribute *attr, char *buf) { struct ssp_data *data = dev_get_drvdata(dev); ssp_dbg("[SSP]: uProxThresh : hi : %u lo : %u, uProxCanc = %u\n", data->uProxHiThresh, data->uProxLoThresh, data->uProxCanc); return sprintf(buf, "%u,%u,%u\n", data->uProxCanc, data->uProxHiThresh, data->uProxLoThresh); }
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; 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); iRet = update_mcu_bin(data, iBinType); 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); iRet = initialize_mcu(data); if (iRet < 0) { iRet = ERROR; ssp_dbg("[SSP]: %s - initialize_mcu failed!\n", __func__); goto out; } ssp_enable(data, true); 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 ssize_t accel_reactive_alert_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int iRet = 0; char chTempBuf = 1; struct ssp_data *data = dev_get_drvdata(dev); struct ssp_msg *msg; if (sysfs_streq(buf, "1")) ssp_dbg("[SSP]: %s - on\n", __func__); else if (sysfs_streq(buf, "0")) ssp_dbg("[SSP]: %s - off\n", __func__); else if (sysfs_streq(buf, "2")) { ssp_dbg("[SSP]: %s - factory\n", __func__); data->bAccelAlert = 0; msg = kzalloc(sizeof(*msg), GFP_KERNEL); msg->cmd = ACCELEROMETER_FACTORY; msg->length = 1; msg->options = AP2HUB_READ; msg->data = chTempBuf; msg->buffer = &chTempBuf; msg->free_buffer = 0; iRet = ssp_spi_sync(data, msg, 3000); data->bAccelAlert = chTempBuf; if (iRet != SUCCESS) { pr_err("[SSP]: %s - accel Selftest Timeout!!\n", __func__); goto exit; } ssp_dbg("[SSP]: %s factory test success!\n", __func__); } else { pr_err("[SSP]: %s - invalid value %d\n", __func__, *buf); return -EINVAL; } exit: return size; }
ssize_t mcu_sleep_factorytest_show(struct device *dev, struct device_attribute *attr, char *buf) { int iDataIdx, iSensorData = 0; struct ssp_data *data = dev_get_drvdata(dev); struct sensor_value fsb[SENSOR_MAX]; if (!(data->uFactorydataReady & (1 << MCU_SLEEP_FACTORY))) { pr_err("[SSP]: %s - The Sensorhub is not ready\n", __func__); goto exit; } for (iDataIdx = 0; iDataIdx < FACTORY_DATA_MAX;) { iSensorData = (int)data->uFactorydata[iDataIdx++]; if ((iSensorData < 0) || (iSensorData >= (SENSOR_MAX - 1))) { pr_err("[SSP]: %s - Mcu data frame error %d\n", __func__, iSensorData); goto exit; } data->get_sensor_data[iSensorData]((char *)data->uFactorydata, &iDataIdx, &(fsb[iSensorData])); } convert_acc_data(&fsb[ACCELEROMETER_SENSOR].x); convert_acc_data(&fsb[ACCELEROMETER_SENSOR].y); convert_acc_data(&fsb[ACCELEROMETER_SENSOR].z); exit: ssp_dbg("[SSP]: %s Result - " "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%u,%u,%u,%u,%u\n", __func__, fsb[ACCELEROMETER_SENSOR].x, fsb[ACCELEROMETER_SENSOR].y, fsb[ACCELEROMETER_SENSOR].z, fsb[GYROSCOPE_SENSOR].x, fsb[GYROSCOPE_SENSOR].y, fsb[GYROSCOPE_SENSOR].z, fsb[GEOMAGNETIC_SENSOR].x, fsb[GEOMAGNETIC_SENSOR].y, fsb[GEOMAGNETIC_SENSOR].z, fsb[PRESSURE_SENSOR].pressure[0], fsb[PRESSURE_SENSOR].pressure[1], fsb[PROXIMITY_SENSOR].prox[1], fsb[LIGHT_SENSOR].r, fsb[LIGHT_SENSOR].g, fsb[LIGHT_SENSOR].b, fsb[LIGHT_SENSOR].w); return sprintf(buf, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%u,%u,%u,%u,%u\n", fsb[ACCELEROMETER_SENSOR].x, fsb[ACCELEROMETER_SENSOR].y, fsb[ACCELEROMETER_SENSOR].z, fsb[GYROSCOPE_SENSOR].x, fsb[GYROSCOPE_SENSOR].y, fsb[GYROSCOPE_SENSOR].z, fsb[GEOMAGNETIC_SENSOR].x, fsb[GEOMAGNETIC_SENSOR].y, fsb[GEOMAGNETIC_SENSOR].z, fsb[PRESSURE_SENSOR].pressure[0], fsb[PRESSURE_SENSOR].pressure[1], fsb[PROXIMITY_SENSOR].prox[1], fsb[LIGHT_SENSOR].r, fsb[LIGHT_SENSOR].g, fsb[LIGHT_SENSOR].b, fsb[LIGHT_SENSOR].w); }
static ssize_t raw_data_logging_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { u8 uBuf[4] = {0, }; int iRet; int64_t dEnable; struct ssp_data *data = dev_get_drvdata(dev); s32 dMsDelay = 10; memcpy(&uBuf[0], &dMsDelay, 4); iRet = kstrtoll(buf, 10, &dEnable); if (iRet < 0) return iRet; if (dEnable) { ssp_dbg("[SSP]: %s - add %u, New = %dns\n", __func__, 1 << GEOMAGNETIC_SENSOR, dMsDelay); iRet = send_instruction(data, GET_LOGGING, GEOMAGNETIC_SENSOR, uBuf, 4); if (iRet == SUCCESS) { pr_info("[SSP] %s - success\n", __func__); data->bGeomagneticLogged = true; } else { pr_err("[SSP] %s - failed, %d\n", __func__, iRet); data->bGeomagneticLogged = false; } } else { iRet = send_instruction(data, REMOVE_SENSOR, GEOMAGNETIC_SENSOR, uBuf, 4); if (iRet == SUCCESS) { pr_info("[SSP] %s - success\n", __func__); data->bGeomagneticLogged = false; } ssp_dbg("[SSP]: %s - remove sensor = %d\n", __func__, (1 << GEOMAGNETIC_SENSOR)); } return size; }
int proximity_open_lcd_ldi(struct ssp_data *data) { int iRet = 0; mm_segment_t old_fs; struct file *cancel_filp = NULL; old_fs = get_fs(); set_fs(KERNEL_DS); cancel_filp = filp_open(LCD_LDI_FILE_PATH, O_RDONLY, 0666); if (IS_ERR(cancel_filp)) { iRet = PTR_ERR(cancel_filp); if (iRet != -ENOENT) pr_err("[SSP]: %s - Can't open lcd ldi file\n", __func__); set_fs(old_fs); data->chLcdLdi[0] = 0; data->chLcdLdi[1] = 0; goto exit; } iRet = cancel_filp->f_op->read(cancel_filp, (u8 *)data->chLcdLdi, sizeof(u8) * 2, &cancel_filp->f_pos); if (iRet != (sizeof(u8) * 2)) { pr_err("[SSP]: %s - Can't read the lcd ldi data\n", __func__); iRet = -EIO; } ssp_dbg("[SSP]: %s - 1st : %c\n", __func__, data->chLcdLdi[0]); ssp_dbg("[SSP]: %s - 1st : %c\n", __func__, data->chLcdLdi[1]); filp_close(cancel_filp, current->files); set_fs(old_fs); exit: change_proximity_default_threshold(data); return iRet; }
ssize_t mcu_update_show(struct device *dev, struct device_attribute *attr, char *buf) { bool bSuccess = false; int iRet = 0; struct ssp_data *data = dev_get_drvdata(dev); ssp_dbg("[SSP]: %s - mcu binany update!\n", __func__); disable_irq(data->iIrq); disable_irq_wake(data->iIrq); iRet = update_mcu_bin(data); if (iRet < 0) { ssp_dbg("[SSP]: %s - update_mcu_bin failed!\n", __func__); goto exit; } iRet = initialize_mcu(data); if (iRet < 0) { ssp_dbg("[SSP]: %s - initialize_mcu failed!\n", __func__); goto exit; } sync_sensor_state(data); enable_irq(data->iIrq); enable_irq_wake(data->iIrq); #ifdef CONFIG_SENSORS_SSP_SENSORHUB ssp_report_sensorhub_notice(data, MSG2SSP_AP_STATUS_RESET); #endif bSuccess = true; exit: return sprintf(buf, "%s\n", (bSuccess ? "OK" : "NG")); }
ssize_t mcu_factorytest_show(struct device *dev, struct device_attribute *attr, char *buf) { bool bMcuTestSuccessed = false; struct ssp_data *data = dev_get_drvdata(dev); if (data->bSspShutdown == true) { ssp_dbg("[SSP]: %s - MCU Bin is crashed\n", __func__); return sprintf(buf, "NG,NG,NG\n"); } if (data->uFactorydataReady & (1 << MCU_FACTORY)) { ssp_dbg("[SSP] MCU Factory Test Data : %u, %u, %u, %u, %u\n", data->uFactorydata[0], data->uFactorydata[1], data->uFactorydata[2], data->uFactorydata[3], data->uFactorydata[4]); /* system clock, RTC, I2C Master, I2C Slave, externel pin */ if ((data->uFactorydata[0] == SUCCESS) && (data->uFactorydata[1] == SUCCESS) && (data->uFactorydata[2] == SUCCESS) && (data->uFactorydata[3] == SUCCESS) && (data->uFactorydata[4] == SUCCESS)) bMcuTestSuccessed = true; } else { pr_err("[SSP]: %s - The Sensorhub is not ready %u\n", __func__, data->uFactorydataReady); } ssp_dbg("[SSP]: MCU Factory Test Result - %s, %s, %s\n", MODEL_NAME, (data->bMcuIRQTestSuccessed ? "OK" : "NG"), (bMcuTestSuccessed ? "OK" : "NG")); return sprintf(buf, "%s,%s,%s\n", MODEL_NAME, (data->bMcuIRQTestSuccessed ? "OK" : "NG"), (bMcuTestSuccessed ? "OK" : "NG")); }
int remove_af_noise_register(struct remove_af_noise *af_cam) { if (af_cam->af_pdata) af_sensor.af_pdata = af_cam->af_pdata; if (af_cam->af_func) af_sensor.af_func = af_cam->af_func; if (!af_cam->af_pdata || !af_cam->af_func) { ssp_dbg("[SSP]: %s - no af struct\n", __func__); return ERROR; } return 0; }
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; }
ssize_t mcu_update_ums_bin_show(struct device *dev, struct device_attribute *attr, char *buf) { bool bSuccess = false; int iRet = 0; struct ssp_data *data = dev_get_drvdata(dev); ssp_dbg("[SSP]: %s - mcu binany update!\n", __func__); iRet = forced_to_download_binary(data, UMS_BINARY); if (iRet == SUCCESS) bSuccess = true; else bSuccess = false; return sprintf(buf, "%s\n", (bSuccess ? "OK" : "NG")); }
int ssp_parse_motion(struct ssp_data *data, char *dataframe, int start, int end) { int length = end - start; char *buf = dataframe + start;; if (length != 4) return FAIL; if ((buf[0] == 1) && (buf[1] == 1) && (buf[2] == SMART_ALERT_MOTION)) { ssp_dbg("[SSP]: %s - LP MODE WAKEUP\n", __func__); queue_work(data->lpm_motion_wq, &data->work_lpm_motion); //report_key_event(data); return SUCCESS; } return FAIL; }
static void work_function_firmware_update(struct work_struct *work) { struct ssp_data *data = container_of((struct delayed_work *)work, struct ssp_data, work_firmware); int iRet = 0; pr_info("[SSP] : %s\n", __func__); iRet = forced_to_download_binary(data, KERNEL_BINARY); if (iRet < 0) { ssp_dbg("[SSP]: %s - forced_to_download_binary failed!\n", __func__); return; } if (data->uCurFirmRev == SSP_INVALID_REVISION) queue_refresh_task(data, SSP_SW_RESET_TIME); }
static ssize_t accel_calibration_show(struct device *dev, struct device_attribute *attr, char *buf) { int iRet; int iCount = 0; struct ssp_data *data = dev_get_drvdata(dev); iRet = accel_open_calibration(data); if (iRet < 0) pr_err("[SSP]: %s - calibration open failed\n", __func__); ssp_dbg("[SSP] Cal data : %d %d %d - %d\n", data->accelcal.x, data->accelcal.y, data->accelcal.z, iRet); iCount = sprintf(buf, "%d %d %d %d\n", iRet, data->accelcal.x, data->accelcal.y, data->accelcal.z); return iCount; }
static void work_function_firmware_update(struct work_struct *work) { struct ssp_data *data = container_of((struct delayed_work *)work, struct ssp_data, work_firmware); int iRet = 0; pr_info("[SSP] : %s\n", __func__); iRet = forced_to_download_binary(data, KERNEL_BINARY); if (iRet < 0) { ssp_dbg("[SSP]: %s - forced_to_download_binary failed!\n", __func__); return; } data->uCurFirmRev = get_firmware_rev(data); pr_info("[SSP] MCU Firm Rev : New = %8u\n", data->uCurFirmRev); }
static void debug_work_func(struct work_struct *work) { unsigned int uSensorCnt; struct ssp_data *data = container_of(work, struct ssp_data, work_debug); ssp_dbg("[SSP]: %s(%u) - Sensor state: 0x%x, RC: %u, MS: %u\n", __func__, data->uIrqCnt, data->uSensorState, data->uResetCnt, data->uMissSensorCnt); for (uSensorCnt = 0; uSensorCnt < (SENSOR_MAX - 1); uSensorCnt++) if (atomic_read(&data->aSensorEnable) & (1 << uSensorCnt)) print_sensordata(data, uSensorCnt); if ((atomic_read(&data->aSensorEnable) & 0x4f) && (data->uIrqCnt == 0)) data->uIrqFailCnt++; else data->uIrqFailCnt = 0; if (((data->uSsdFailCnt >= LIMIT_SSD_FAIL_CNT) || (data->uInstFailCnt >= LIMIT_INSTRUCTION_FAIL_CNT) || (data->uIrqFailCnt >= LIMIT_IRQ_FAIL_CNT) || ((data->uTimeOutCnt + data->uBusyCnt) > LIMIT_TIMEOUT_CNT)) && (data->bSspShutdown == false)) { if (data->uResetCnt < LIMIT_RESET_CNT) { reset_mcu(data); data->uResetCnt++; } else { if (data->bSspShutdown == false) { data->bSspShutdown = true; disable_irq_wake(data->iIrq); disable_irq(data->iIrq); } } data->uSsdFailCnt = 0; data->uInstFailCnt = 0; data->uTimeOutCnt = 0; data->uBusyCnt = 0; data->uIrqFailCnt = 0; } data->uIrqCnt = 0; }
static ssize_t proximity_thresh_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct ssp_data *data = dev_get_drvdata(dev); u8 uNewThresh = 0x09; int iRet = 0; iRet = kstrtou8(buf, 10, &uNewThresh); if (iRet < 0) pr_err("[SSP]: %s - kstrtoint failed.", __func__); data->uProxThresh = uNewThresh; set_proximity_threshold(data); ssp_dbg("[SSP]: %s - new prox threshold = 0x%x\n", __func__, data->uProxThresh); return size; }