static int send_grip_factory_cmd(struct ssp_data *data, char reg_addr, char value) { struct ssp_msg *msg; int ret; msg = kzalloc(sizeof(*msg), GFP_KERNEL); if (msg == NULL) { pr_err("[SSP] %s, failed to alloc memory for ssp_msg\n", __func__); return -ENOMEM; } msg->cmd = MSG2SSP_AP_MCU_GRIP_FACTORY; msg->options = AP2HUB_WRITE; msg->buffer = kzalloc(sizeof(reg_addr) + sizeof(value), GFP_KERNEL); msg->length = sizeof(reg_addr) + sizeof(value); msg->free_buffer = 1; memcpy(&msg->buffer[0], ®_addr, sizeof(reg_addr)); memcpy(&msg->buffer[1], &value, sizeof(reg_addr)); ret = ssp_spi_async(data, msg); if (ret != SUCCESS) { pr_err("[SSP]: %s - MSG2SSP_AP_MCU_GRIP_FACTORY CMD fail %d\n", __func__, ret); return -EIO; } return SUCCESS; }
static int set_grip_factory_data(struct ssp_data *data, int cmd, char *buffer, int len) { struct ssp_msg *msg; int ret = 0; msg = kzalloc(sizeof(*msg), GFP_KERNEL); if (msg == NULL) { pr_err("[SSP] %s, failed to alloc memory for ssp_msg\n", __func__); return -ENOMEM; } msg->cmd = cmd; msg->options = AP2HUB_WRITE; msg->buffer = buffer; msg->length = len; msg->free_buffer = 0; ret = ssp_spi_async(data, msg); if (ret != SUCCESS) { pr_err("[SSP]: %s - %d CMD fail %d\n", __func__, cmd, ret); return -EIO; } return SUCCESS; }
int set_static_matrix(struct ssp_data *data) { int iRet = 0; struct ssp_msg *msg; s16 static_matrix[9] = YAS_STATIC_ELLIPSOID_MATRIX; if (!(data->uSensorState & 0x04)) { pr_info("[SSP]: %s - Skip this function!!!"\ ", magnetic sensor is not connected(0x%x)\n", __func__, data->uSensorState); return iRet; } msg = kzalloc(sizeof(*msg), GFP_KERNEL); msg->cmd = MSG2SSP_AP_SET_MAGNETIC_STATIC_MATRIX; msg->length = 18; msg->options = AP2HUB_WRITE; msg->buffer = (char*) kzalloc(18, GFP_KERNEL); msg->free_buffer = 1; memcpy(msg->buffer, static_matrix, 18); iRet = ssp_spi_async(data, msg); if (iRet != SUCCESS) { pr_err("[SSP]: %s - i2c fail %d\n", __func__, iRet); iRet = ERROR; } pr_info("[SSP]: %s: finished \n", __func__); return iRet; }
ssize_t mcu_sleep_factorytest_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct ssp_data *data = dev_get_drvdata(dev); int iRet = 0; struct ssp_msg *msg; if (sysfs_streq(buf, "1")) { msg = kzalloc(sizeof(*msg), GFP_KERNEL); if (msg == NULL) { pr_err("[SSP] %s, failed to alloc memory for ssp_msg\n", __func__); return -ENOMEM; } msg->cmd = MCU_SLEEP_FACTORY; msg->length = FACTORY_DATA_MAX; msg->options = AP2HUB_READ; msg->buffer = buffer; msg->free_buffer = 0; iRet = ssp_spi_async(data, msg); } else { pr_err("[SSP]: %s - invalid value %d\n", __func__, *buf); return -EINVAL; } ssp_dbg("[SSP]: MCU Sleep Factory Test Start! - %d\n", iRet); return size; }
int set_accel_cal(struct ssp_data *data) { int iRet = 0; struct ssp_msg *msg; s16 accel_cal[3]; if (!(data->uSensorState & (1 << ACCELEROMETER_SENSOR))) { pr_info("[SSP]: %s - Skip this function!!!"\ ", accel sensor is not connected(0x%x)\n", __func__, data->uSensorState); return iRet; } accel_cal[0] = data->accelcal.x; accel_cal[1] = data->accelcal.y; accel_cal[2] = data->accelcal.z; msg = kzalloc(sizeof(*msg), GFP_KERNEL); msg->cmd = MSG2SSP_AP_MCU_SET_ACCEL_CAL; msg->length = 6; msg->options = AP2HUB_WRITE; msg->buffer = (char*) kzalloc(6, GFP_KERNEL); msg->free_buffer = 1; memcpy(msg->buffer, accel_cal, 6); iRet = ssp_spi_async(data, msg); if (iRet != SUCCESS) { pr_err("[SSP]: %s - i2c fail %d\n", __func__, iRet); iRet = ERROR; } pr_info("[SSP] Set accel cal data %d, %d, %d\n", accel_cal[0], accel_cal[1], accel_cal[2]); return iRet; }
int set_hw_offset(struct ssp_data *data) { int iRet = 0; struct ssp_msg *msg; if (!(data->uSensorState & 0x04)) { pr_info("[SSP]: %s - Skip this function!!!"\ ", magnetic sensor is not connected(0x%x)\n", __func__, data->uSensorState); return iRet; } msg = kzalloc(sizeof(*msg), GFP_KERNEL); msg->cmd = MSG2SSP_AP_SET_MAGNETIC_HWOFFSET; msg->length = 3; msg->options = AP2HUB_WRITE; msg->buffer = (char*) kzalloc(3, GFP_KERNEL); msg->free_buffer = 1; msg->buffer[0] = data->magoffset.x; msg->buffer[1] = data->magoffset.y; msg->buffer[2] = data->magoffset.z; iRet = ssp_spi_async(data, msg); if (iRet != SUCCESS) { pr_err("[SSP]: %s - i2c fail %d\n", __func__, iRet); iRet = ERROR; } pr_info("[SSP]: %s: x: %d, y: %d, z: %d\n", __func__, (s8)data->magoffset.x, (s8)data->magoffset.y, (s8)data->magoffset.z); return iRet; }
ssize_t mcu_factorytest_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct ssp_data *data = dev_get_drvdata(dev); int iRet = 0; struct ssp_msg *msg; if (sysfs_streq(buf, "1")) { msg = kzalloc(sizeof(*msg), GFP_KERNEL); msg->cmd = MCU_FACTORY; msg->length = 5; msg->options = AP2HUB_READ; msg->buffer = buffer; msg->free_buffer = 0; memset(msg->buffer, 0, 5); iRet = ssp_spi_async(data, msg); } else { pr_err("[SSP]: %s - invalid value %d\n", __func__, *buf); return -EINVAL; } ssp_dbg("[SSP]: MCU Factory Test Start! - %d\n", iRet); return size; }
int set_gyro_cal(struct ssp_data *data) { int iRet = 0; struct ssp_msg *msg; s16 gyro_cal[3]; gyro_cal[0] = data->gyrocal.x; gyro_cal[1] = data->gyrocal.y; gyro_cal[2] = data->gyrocal.z; msg = kzalloc(sizeof(*msg), GFP_KERNEL); if (msg == NULL) { pr_err("[SSP] %s, failed to alloc memory for ssp_msg\n", __func__); return -ENOMEM; } msg->cmd = MSG2SSP_AP_MCU_SET_GYRO_CAL; msg->length = 6; msg->options = AP2HUB_WRITE; msg->buffer = (char*) kzalloc(6, GFP_KERNEL); msg->free_buffer = 1; memcpy(msg->buffer, gyro_cal, 6); iRet = ssp_spi_async(data, msg); if (iRet != SUCCESS) { pr_err("[SSP]: %s - i2c fail %d\n", __func__, iRet); iRet = ERROR; } pr_info("[SSP] Set gyro cal data %d, %d, %d\n", gyro_cal[0], gyro_cal[1], gyro_cal[2]); return iRet; }
int set_accel_cal(struct ssp_data *data) { int iRet = 0; struct ssp_msg *msg; s16 accel_cal[3]; accel_cal[0] = data->accelcal.x; accel_cal[1] = data->accelcal.y; accel_cal[2] = data->accelcal.z; msg = kzalloc(sizeof(*msg), GFP_KERNEL); if(!msg) return -ENOMEM; msg->cmd = MSG2SSP_AP_MCU_SET_ACCEL_CAL; msg->length = 6; msg->options = AP2HUB_WRITE; msg->buffer = (char*) kzalloc(6, GFP_KERNEL); if(!(msg->buffer)){ kfree(msg); return -ENOMEM; } msg->free_buffer = 1; memcpy(msg->buffer, accel_cal, 6); iRet = ssp_spi_async(data, msg); if (iRet != SUCCESS) { pr_err("[SSP]: %s - i2c fail %d\n", __func__, iRet); iRet = ERROR; } pr_info("[SSP] Set accel cal data %d, %d, %d\n", accel_cal[0], accel_cal[1], accel_cal[2]); return iRet; }
void mobeam_write(struct ssp_data *data, int type, u8* u_buf) { int iRet = 0; u8 command = -1; u8 data_length = 0; struct ssp_msg *msg; if (!(data->uSensorState & (1 << PROXIMITY_SENSOR))) { pr_info("[SSP]: %s - Skip this function!!!"\ ", proximity sensor is not connected(0x%x)\n", __func__, data->uSensorState); return; } pr_info("[SSP] %s start, command_type = %d\n", __func__, type); switch (type) { case dataset: command = MSG2SSP_AP_MOBEAM_DATA_SET; data_length = 128; break; case registerset: command = MSG2SSP_AP_MOBEAM_REGISTER_SET; data_length = 6; break; case countset: command = MSG2SSP_AP_MOBEAM_COUNT_SET; data_length = 1; break; case start: command = MSG2SSP_AP_MOBEAM_START; data_length = 1; Is_beaming = BEAMING_ON; break; default: pr_info("[SSP] %s - unknown cmd type\n", __func__); break; } msg= kzalloc(sizeof(*msg), GFP_KERNEL); msg->cmd = command; msg->length = data_length; msg->options = AP2HUB_WRITE; msg->buffer = (char*) kzalloc(data_length, GFP_KERNEL); msg->free_buffer = 1; memcpy(msg->buffer, u_buf, data_length); iRet = ssp_spi_async(data, msg); if (iRet != SUCCESS) { pr_err("[SSP]: %s - MOBEAM CMD fail %d\n", __func__, iRet); return; } data->uInstFailCnt = 0; pr_info("[SSP] %s command = 0x%X\n", __func__, command); }
static int set_pdc_matrix(struct ssp_data *data) { int ret = 0; struct ssp_msg *msg; if (!(data->uSensorState & 0x04)) { pr_info("[SSP] %s - Skip this function!!!"\ ", magnetic sensor is not connected(0x%llx)\n", __func__, data->uSensorState); return ret; } msg = kzalloc(sizeof(*msg), GFP_KERNEL); if (msg == NULL) { pr_err("[SSP] %s, failed to alloc memory for ssp msg\n", __func__); return -ENOMEM; } msg->cmd = MSG2SSP_AP_SET_MAGNETIC_STATIC_MATRIX; msg->length = sizeof(data->pdc_matrix); msg->options = AP2HUB_WRITE; msg->buffer = kzalloc(sizeof(data->pdc_matrix), GFP_KERNEL); if (msg->buffer == NULL) { pr_err("[SSP] %s, failed to alloc memory\n", __func__); kfree(msg); return -ENOMEM; } msg->free_buffer = 1; memcpy(msg->buffer, data->pdc_matrix, sizeof(data->pdc_matrix)); ret = ssp_spi_async(data, msg); if (ret != SUCCESS) { pr_err("[SSP] %s - i2c fail %d\n", __func__, ret); ret = ERROR; } pr_info("[SSP] %s: finished\n", __func__); return ret; }
int set_gyro_cal(struct ssp_data *data) { int iRet = 0; struct ssp_msg *msg; s16 gyro_cal[3]; if (!(data->uSensorState & (1 << GYROSCOPE_SENSOR))) { pr_info("[SSP]: %s - Skip this function!!!"\ ", gyro sensor is not connected(0x%x)\n", __func__, data->uSensorState); return iRet; } gyro_cal[0] = data->gyrocal.x; gyro_cal[1] = data->gyrocal.y; gyro_cal[2] = data->gyrocal.z; msg = kzalloc(sizeof(*msg), GFP_KERNEL); if (msg == NULL) { pr_err("[SSP] %s, failed to alloc memory for ssp_msg\n", __func__); return -ENOMEM; } msg->cmd = MSG2SSP_AP_MCU_SET_GYRO_CAL; msg->length = 6; msg->options = AP2HUB_WRITE; msg->buffer = kzalloc(6, GFP_KERNEL); msg->free_buffer = 1; memcpy(msg->buffer, gyro_cal, 6); iRet = ssp_spi_async(data, msg); if (iRet != SUCCESS) { pr_err("[SSP]: %s - i2c fail %d\n", __func__, iRet); iRet = ERROR; } pr_info("[SSP] Set gyro cal data %d, %d, %d\n", gyro_cal[0], gyro_cal[1], gyro_cal[2]); return iRet; }
static ssize_t accel_lowpassfilter_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int iRet = 0, new_enable = 1; struct ssp_data *data = dev_get_drvdata(dev); struct ssp_msg *msg = kzalloc(sizeof(*msg), GFP_KERNEL); if (msg == NULL) { pr_err("[SSP] %s, failed to alloc memory\n", __func__); goto exit; } if (sysfs_streq(buf, "1")) new_enable = 1; else if (sysfs_streq(buf, "0")) new_enable = 0; else ssp_dbg("[SSP]: %s - invalid value!\n", __func__); msg->cmd = MSG2SSP_AP_SENSOR_LPF; msg->length = 1; msg->options = AP2HUB_WRITE; msg->buffer = (char*) kzalloc(1, GFP_KERNEL); if (msg->buffer == NULL) { pr_err("[SSP] %s, failed to alloc memory\n", __func__); kfree(msg); goto exit; } *msg->buffer = new_enable; msg->free_buffer = 1; iRet = ssp_spi_async(data, msg); if (iRet != SUCCESS) pr_err("[SSP] %s - fail %d\n", __func__, iRet); else pr_info("[SSP] %s - %d\n", __func__, new_enable); exit: return size; }