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); if (kstrtoll(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 size; 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 */ /* In case of enabling */ /* we will sensor instruction on change_sensor_delay. */ break; } atomic_set(&data->aSensorEnable, uNewEnable); return size; }
static ssize_t cm3323_poll_delay_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct cm3323_p *data = dev_get_drvdata(dev); int64_t new_delay; int ret; ret = kstrtoll(buf, 10, &new_delay); if (ret) { pr_err("[SENSOR]: %s - Invalid Argument\n", __func__); return ret; } mutex_lock(&data->power_lock); if (new_delay != ktime_to_ms(data->poll_delay)) { data->poll_delay = ns_to_ktime(new_delay * NSEC_PER_MSEC); if (data->power_state & LIGHT_ENABLED) { cm3323_light_disable(data); cm3323_light_enable(data); } pr_info("[SENSOR]: %s - poll_delay = %lld\n", __func__, new_delay); } mutex_unlock(&data->power_lock); return size; }
static ssize_t acc_store_delay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int64_t delay = 0; int64_t mdelay = 0; int ret = 0; struct acc_context *cxt = NULL; mutex_lock(&acc_context_obj->acc_op_mutex); cxt = acc_context_obj; if (NULL == cxt->acc_ctl.set_delay) { ACC_LOG("acc_ctl set_delay NULL\n"); mutex_unlock(&acc_context_obj->acc_op_mutex); return count; } ret = kstrtoll(buf, 10, &delay); if (ret != 0) { ACC_ERR("invalid format!!\n"); mutex_unlock(&acc_context_obj->acc_op_mutex); return count; } if (false == cxt->acc_ctl.is_report_input_direct) { mdelay = delay; do_div(mdelay, 1000000); atomic_set(&acc_context_obj->delay, mdelay); } cxt->acc_ctl.set_delay(delay); ACC_LOG(" acc_delay %lld ns\n", delay); mutex_unlock(&acc_context_obj->acc_op_mutex); return count; }
static ssize_t uv_poll_delay_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct uv_info *uv = dev_get_drvdata(dev); int64_t new_delay; int err; err = kstrtoll(buf, 10, &new_delay); if (err < 0) return err; mutex_lock(&uv->power_lock); if (uv->onoff) { hrtimer_cancel(&uv->uv_timer); cancel_work_sync(&uv->work_uv); } if (new_delay != ktime_to_ns(uv->uv_poll_delay)) { uv->uv_poll_delay = ns_to_ktime(new_delay); pr_info("%s, poll_delay = %lld\n", __func__, new_delay); } if (uv->onoff) hrtimer_start(&uv->uv_timer, uv->uv_poll_delay, HRTIMER_MODE_REL); mutex_unlock(&uv->power_lock); return size; }
static ssize_t proximity_avg_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { char chTempbuf[4] = { 0 }; int iRet; int64_t dEnable; struct ssp_data *data = dev_get_drvdata(dev); s32 dMsDelay = 20; memcpy(&chTempbuf[0], &dMsDelay, 4); iRet = kstrtoll(buf, 10, &dEnable); if (iRet < 0) return iRet; if (dEnable) { send_instruction(data, ADD_SENSOR, PROXIMITY_RAW, chTempbuf, 4); data->bProximityRawEnabled = true; } else { send_instruction(data, REMOVE_SENSOR, PROXIMITY_RAW, chTempbuf, 4); data->bProximityRawEnabled = false; } return size; }
static KMETHOD TypeCheck_ExtendedIntLiteral(KonohaContext *kctx, KonohaStack *sfp) { VAR_TypeCheck(expr, gma, reqty); kToken *tk = expr->TermToken; long long n = kstrtoll(kString_text(tk->text)); KReturn(SUGAR kNode_SetUnboxConst(kctx, expr, KType_Int, (uintptr_t)n)); }
static ssize_t k303c_acc_delay_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int ret; int64_t delay; struct k303c_acc_p *data = dev_get_drvdata(dev); pr_info("%s\n", __func__); ret = kstrtoll(buf, 10, &delay); if (ret) { pr_err("%s - Invalid Argument\n", __func__); return ret; } data->poll_delay = ns_to_ktime(delay); k303c_acc_set_odr(data); if (atomic_read(&data->enable) == ON) { k303c_acc_set_mode(data, K303C_MODE_SUSPEND); k303c_acc_set_mode(data, K303C_MODE_NORMAL); } pr_info("%s - poll_delay = %lld\n", __func__, delay); return size; }
static ssize_t set_temp_humi_delay(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int64_t dNewDelay; struct ssp_data *data = dev_get_drvdata(dev); if (kstrtoll(buf, 10, &dNewDelay) < 0) return -1; change_sensor_delay(data, TEMPERATURE_HUMIDITY_SENSOR, dNewDelay); return size; }
static ssize_t set_light_delay(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int64_t dNewDelay; struct ssp_data *data = dev_get_drvdata(dev); if (kstrtoll(buf, 10, &dNewDelay) < 0) return -1; change_sensor_delay(data, LIGHT_SENSOR, dNewDelay); return size; }
static ssize_t set_uncalib_gyro_delay(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int64_t dNewDelay; struct ssp_data *data = dev_get_drvdata(dev); if (kstrtoll(buf, 10, &dNewDelay) < 0) return -EINVAL; change_sensor_delay(data, GYRO_UNCALIB_SENSOR, dNewDelay); return size; }
static ssize_t set_game_rot_delay(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int64_t dNewDelay; struct ssp_data *data = dev_get_drvdata(dev); if (kstrtoll(buf, 10, &dNewDelay) < 0) return -EINVAL; change_sensor_delay(data, GAME_ROTATION_VECTOR, dNewDelay); return size; }
int kstrtos8(const char *s, unsigned int base, s8 *res) { long long tmp; int rv; rv = kstrtoll(s, base, &tmp); if (rv < 0) return rv; if (tmp != (long long)(s8)tmp) return -ERANGE; *res = tmp; return 0; }
static ssize_t raw_data_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { char chTempbuf[9] = { 0 }; int iRet; int64_t dEnable; int iRetries = 50; struct ssp_data *data = dev_get_drvdata(dev); s32 dMsDelay = 20; memcpy(&chTempbuf[0], &dMsDelay, 4); memcpy(&chTempbuf[4], &data->batchLatencyBuf[GEOMAGNETIC_RAW], 4); chTempbuf[8] = data->batchOptBuf[GEOMAGNETIC_RAW]; iRet = kstrtoll(buf, 10, &dEnable); if (iRet < 0) return iRet; if (dEnable) { data->buf[GEOMAGNETIC_RAW].x = 0; data->buf[GEOMAGNETIC_RAW].y = 0; data->buf[GEOMAGNETIC_RAW].z = 0; send_instruction(data, ADD_SENSOR, GEOMAGNETIC_RAW, chTempbuf, 9); #if 0 do { msleep(20); if (check_data_spec(data) == SUCCESS) break; } while (--iRetries); #endif if (iRetries > 0) { pr_info("[SSP] %s - success, %d\n", __func__, iRetries); data->bGeomagneticRawEnabled = true; } else { pr_err("[SSP] %s - wait timeout, %d\n", __func__, iRetries); data->bGeomagneticRawEnabled = false; } } else { send_instruction(data, REMOVE_SENSOR, GEOMAGNETIC_RAW, chTempbuf, 4); data->bGeomagneticRawEnabled = false; } return size; }
static ssize_t bma280_calibration_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int ret; int64_t dEnable; struct bma280_p *data = dev_get_drvdata(dev); ret = kstrtoll(buf, 10, &dEnable); if (ret < 0) return ret; ret = bma280_do_calibrate(data, (int)dEnable); if (ret < 0) pr_err("[SENSOR]: %s - accel calibrate failed\n", __func__); return size; }
static ssize_t accel_calibration_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int iRet; int64_t dEnable; struct ssp_data *data = dev_get_drvdata(dev); iRet = kstrtoll(buf, 10, &dEnable); if (iRet < 0) return iRet; iRet = accel_do_calibrate(data, (int)dEnable); if (iRet < 0) pr_err("[SSP]: %s - accel_do_calibrate() failed\n", __func__); return size; }
static ssize_t set_acc_delay(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int64_t dNewDelay; struct ssp_data *data = dev_get_drvdata(dev); if (kstrtoll(buf, 10, &dNewDelay) < 0) return -1; if ((atomic_read(&data->aSensorEnable) & (1 << ORIENTATION_SENSOR)) && (data->adDelayBuf[ORIENTATION_SENSOR] < dNewDelay)) data->adDelayBuf[ACCELEROMETER_SENSOR] = dNewDelay; else change_sensor_delay(data, ACCELEROMETER_SENSOR, dNewDelay); return size; }
static ssize_t barcode_emul_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int iRet; int64_t dEnable; struct ssp_data *data = dev_get_drvdata(dev); iRet = kstrtoll(buf, 10, &dEnable); if (iRet < 0) return iRet; if (dEnable) set_proximity_barcode_enable(data, true); else set_proximity_barcode_enable(data, false); return size; }
static ssize_t bma255_delay_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int ret; int64_t delay; struct bma255_p *data = dev_get_drvdata(dev); ret = kstrtoll(buf, 10, &delay); if (ret) { pr_err("[SENSOR]: %s - Invalid Argument\n", __func__); return ret; } atomic_set(&data->delay, (unsigned int)delay); pr_info("[SENSOR]: %s - poll_delay = %lld\n", __func__, delay); return size; }
static ssize_t raw_data_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { char chTempbuf[2] = { 1, 20}; int iRet; int64_t dEnable; int iRetries = 50; struct ssp_data *data = dev_get_drvdata(dev); iRet = kstrtoll(buf, 10, &dEnable); if (iRet < 0) return iRet; if (dEnable) { data->buf[MAGNETIC_SENSOR].x = 0; data->buf[MAGNETIC_SENSOR].y = 0; data->buf[MAGNETIC_SENSOR].z = 0; send_instruction(data, ADD_SENSOR, MAGNETIC_RAW, chTempbuf, 2); do { msleep(20); if (check_rawdata_spec(data) == SUCCESS) break; } while (--iRetries); if (iRetries > 0) { pr_info("[SSP] %s - success, %d\n", __func__, iRetries); data->bGeomagneticRawEnabled = true; } else { pr_err("[SSP] %s - wait timeout, %d\n", __func__, iRetries); data->bGeomagneticRawEnabled = false; } } else { send_instruction(data, REMOVE_SENSOR, MAGNETIC_RAW, chTempbuf, 2); data->bGeomagneticRawEnabled = false; } return size; }
static ssize_t ak09911c_delay_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int ret; int64_t delay; struct ak09911c_p *data = dev_get_drvdata(dev); ret = kstrtoll(buf, 10, &delay); if (ret) { pr_err("%s Invalid Argument\n", __func__); return ret; } atomic_set(&data->delay, delay); pr_info("%s poll_delay = %lld\n", __func__, delay); return size; }
static ssize_t set_ori_delay(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int64_t dNewDelay; struct ssp_data *data = dev_get_drvdata(dev); if (kstrtoll(buf, 10, &dNewDelay) < 0) return -1; if (data->aiCheckStatus[ACCELEROMETER_SENSOR] == NO_SENSOR_STATE) { data->aiCheckStatus[ACCELEROMETER_SENSOR] = ADD_SENSOR_STATE; change_sensor_delay(data, ORIENTATION_SENSOR, dNewDelay); } else if (data->aiCheckStatus[ACCELEROMETER_SENSOR] == RUNNING_SENSOR_STATE) { if (dNewDelay < data->adDelayBuf[ACCELEROMETER_SENSOR]) change_sensor_delay(data, ORIENTATION_SENSOR, dNewDelay); else data->adDelayBuf[ORIENTATION_SENSOR] = dNewDelay; } return size; }
static ssize_t bma280_delay_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int ret; int64_t delay; struct bma280_p *data = dev_get_drvdata(dev); ret = kstrtoll(buf, 10, &delay); if (ret) { pr_err("[SENSOR]: %s - Invalid Argument\n", __func__); goto exit; } else if (ktime_to_ns(data->poll_delay) == delay) { goto exit; } if (delay <= 3000000LL) bma280_set_bandwidth(data, BMA280_BW_500HZ); else if (delay <= 5000000LL) bma280_set_bandwidth(data, BMA280_BW_125HZ); else if (delay <= 10000000LL) bma280_set_bandwidth(data, BMA280_BW_62_50HZ); else if (delay <= 20000000LL) bma280_set_bandwidth(data, BMA280_BW_31_25HZ); else bma280_set_bandwidth(data, BMA280_BW_7_81HZ); data->poll_delay = ns_to_ktime(delay); pr_info("[SENSOR]: %s - poll_delay = %lld\n", __func__, delay); if (atomic_read(&data->enable) == ON) { bma280_set_mode(data, BMA280_MODE_SUSPEND); bma280_set_enable(data, OFF); bma280_set_mode(data, BMA280_MODE_NORMAL); bma280_set_enable(data, ON); } exit: return size; }
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; }
static int __init kread_init(void) { unsigned int j = 0; unsigned int i = 0; unsigned int state = 0; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! unsigned int choiceSeq = 0; long long int timeStart = 0; long long int timeEnd = 0; size_t n; loff_t offset = 0; // For write. loff_t file_offset = 0; // For read. mm_segment_t fs; long move; // Step at reading. int endRWC = 0; // Initialization of rbTree. struct dataRBTree *itemRBTree; struct rb_root rbTree = RB_ROOT; //struct rb_node *node; // Initialization of hash table. /*int size = 0; struct list_head *hashList; struct dataListHash *itemHashTable; size = numberBuckets * sizeof(*hashList); hashList = kmalloc(size, GFP_KERNEL); for (i = 0; i < numberBuckets; ++i) INIT_LIST_HEAD(&hashList[i]);*/ fs = get_fs(); set_fs(get_ds()); if (file != NULL) // If set module parameter "file". strcpy(pathToInputFile, file); fileInput = filp_open(pathToInputFile, O_RDONLY, 0); // Open the file for read. if (isOpenIncorrect(fileInput, pathToInputFile, fs)) return -ENOENT; if (log != NULL) // If set module parameter "log". strcpy(pathToOutputFile, log); fileOutput = filp_open(pathToOutputFile, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); // Open the file for write. if (isOpenIncorrect(fileOutput, pathToOutputFile, fs)) return -ENOENT; move = vfs_llseek(fileInput, numberOfBytes, 0); // 0 means SEEK_SET. (set in begin of file) i = 0; //timeStart = ktime_to_ns(ktime_get()); while (1) { n = vfs_read(fileInput, buff, move, &file_offset); if (n == 0) // If the file is ended. { if (strlen(str) > 0) { vfs_write(fileOutput, "New line: ", 10, &offset); vfs_write(fileOutput, str, strlen(str), &offset); } break; } for (j = 0; j < n; j++) { if (buff[j] == ' ' || buff[j] == ':') continue; else if (buff[j] == 'q') choiceSeq = 1; else if (buff[j] == 'l') state = 1; else if ((buff[j] == 'b' || buff[j] == 'e') && state == 1) state = 2; else if ((buff[j] == 'a' || buff[j] == 'n') && state == 2) state = 3; else if ((state == 3 || state == 4) && buff[j] >= '0' && buff[j] <= '9') // Reads the number. { state = 4; str[i] = buff[j]; str[i + 1] = '\0'; i++; } else if (state == 4 && buff[j] == ',') // Read lba. { strcpy(strLba, str); i = 0; strcpy(str, ""); // Clean the string. } else if (state == 4 && !(buff[j] >= '0' && buff[j] <= '9')) // Read lba and len. { // Work with RBTree. itemRBTree = kmalloc(sizeof(*itemRBTree), GFP_KERNEL); kstrtoll(strLba, 10, &itemRBTree->lbaMain); itemRBTree->lbaAux = endRWC; kstrtoll(str, 10, &itemRBTree->length); endRWC += itemRBTree->length; //timeStart = ktime_to_ns(ktime_get()); if (choiceSeq) { timeStart = ktime_to_ns(ktime_get()); rbTreeCorrect(&rbTree, NULL, itemRBTree->lbaMain, itemRBTree->lbaAux, itemRBTree->length); timeEnd = ktime_to_ns(ktime_get()); tostring(str, (timeEnd - timeStart)); vfs_write(fileOutput, str, strlen(str), &offset); vfs_write(fileOutput, "\n", 1, &offset); //printk("Time: %lld\n", (timeEnd - timeStart)); } else rbTreeInsert(&rbTree, itemRBTree); //timeEnd = ktime_to_ns(ktime_get()); //tostring(str, (timeEnd - timeStart)); //vfs_write(fileOutput, str, strlen(str), &offset); //vfs_write(fileOutput, "\n", 1, &offset); //printk("Time: %lld\n", (timeEnd - timeStart)); //if (countOfNodesRBTree > 1000) //{ //timeStart = ktime_to_ns(ktime_get()); //removeDataFromRBTree(&rbTree, 1000); //timeEnd = ktime_to_ns(ktime_get()); //tostring(str, (timeEnd - timeStart)); //vfs_write(fileOutput, str, strlen(str), &offset); //vfs_write(fileOutput, "\n", 1, &offset); //printk("Time: %lld\n", (timeEnd - timeStart)); //} // Work with hash table. /*itemHashTable = kmalloc(sizeof(*itemHashTable), GFP_KERNEL); kstrtoll(strLba, 10, &itemHashTable->lbaMain); itemHashTable->lbaAux = endRWC; kstrtoll(str, 10, &itemHashTable->length); endRWC += itemHashTable->length; timeStart = ktime_to_ns(ktime_get()); * if (choiceSeq) { timeStart = ktime_to_ns(ktime_get()); hashTableCorrect(hashList, NULL, itemRBTree->lbaMain, itemRBTree->lbaAux, itemRBTree->length); timeEnd = ktime_to_ns(ktime_get()); tostring(str, (timeEnd - timeStart)); vfs_write(fileOutput, str, strlen(str), &offset); vfs_write(fileOutput, "\n", 1, &offset); //printk("Time: %lld\n", (timeEnd - timeStart)); } else hashTableInsert(hashList, itemHashTable, choiceSeq); timeEnd = ktime_to_ns(ktime_get()); tostring(str, (timeEnd - timeStart)); vfs_write(fileOutput, str, strlen(str), &offset); vfs_write(fileOutput, "\n", 1, &offset); printk("Time: %lld\n", (timeEnd - timeStart)); if (countOfNodesHashTable > 1000) { //timeStart = ktime_to_ns(ktime_get()); removeDataFromHashTable(hashList, 1000); //timeEnd = ktime_to_ns(ktime_get()); //tostring(str, (timeEnd - timeStart)); //vfs_write(fileOutput, str, strlen(str), &offset); //vfs_write(fileOutput, "\n", 1, &offset); //printk("Time: %lld\n", (timeEnd - timeStart)); }*/ i = 0; strcpy(str, ""); // Clean the string. state = 0; // Go to search 'l'. choiceSeq = 0; } } } //timeEnd = ktime_to_ns(ktime_get()); //tostring(str, (timeEnd - timeStart)); //vfs_write(fileOutput, str, strlen(str), &offset); //vfs_write(fileOutput, "\n", 1, &offset); //printk("Time: %lld\n", (timeEnd - timeStart)); set_fs(fs); filp_close(fileInput, NULL); // Close the input file. filp_close(fileOutput, NULL); // Close the output file. //removeDataFromRBTree(&rbTree, 100); //removeDataFromHashTable(hashList); //printk("Hash Table:\n"); //hashTablePrint(hashList); /*printk("Root\n"); for (node = rb_first(&rbTree); node; node = rb_next(node)) printk("lbaMain=%lld lbaAux=%lld length=%lld\n", rb_entry(node, struct dataRBTree, node)->lbaMain, rb_entry(node, struct dataRBTree, node)->lbaAux, rb_entry(node, struct dataRBTree, node)->length);*/ return 0; }