Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c7f19b79 authored by rohit bandi's avatar rohit bandi Committed by Rohit Bandi
Browse files

HID: qvr: Code refactoring



Refactoring code for hid-qvr to improve
readability.

Change-Id: I00f679b6e1cf6f59d576243757cba1a88c9286b6
Signed-off-by: default avatarRohit Bandi <rohitbandi@codeaurora.org>
parent 1aee7abb
Loading
Loading
Loading
Loading
+28 −26
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@
#include "hid-qvr.h"
#include "hid-trace.h"

#define WAIT_EVENT_INT_TOUT 1000

#define QVR_START_IMU		_IO('q', 1)
#define QVR_STOP_IMU		_IO('q', 2)
#define QVR_READ_CALIB_DATA_LEN	_IOR('q', 3, int32_t)
@@ -102,8 +104,6 @@ struct qvr_external_sensor {
};

const static int msg_size = 368;
const static int hid_request_report_id = 2;
const static int hid_request_report_size = 64;

static DECLARE_WAIT_QUEUE_HEAD(wq);
static struct qvr_external_sensor qvr_external_sensor;
@@ -118,17 +118,18 @@ static int read_calibration_len(void)
	if (hid_buf == NULL)
		return -ENOMEM;

	hid_buf[0] = 2;
	hid_buf[1] = 20;
	hid_buf[0] = QVR_HID_REPORT_ID_CAL;
	hid_buf[1] = QVR_CMD_ID_CALIBRATION_DATA_SIZE;

	ret = hid_hw_raw_request(sensor->hdev, hid_buf[0],
		hid_buf,
		hid_request_report_size,
		QVR_HID_REQUEST_REPORT_SIZE,
		HID_FEATURE_REPORT,
		HID_REQ_SET_REPORT);

	ret = wait_event_interruptible_timeout(wq,
		sensor->calib_data_len != -1, msecs_to_jiffies(1000));
		sensor->calib_data_len != -1,
		msecs_to_jiffies(WAIT_EVENT_INT_TOUT));
	if (ret == 0) {
		kfree(hid_buf);
		return -ETIME;
@@ -155,8 +156,8 @@ static uint8_t *read_calibration_data(void)
	if (hid_buf == NULL)
		return NULL;

	hid_buf[0] = 2;
	hid_buf[1] = 21;
	hid_buf[0] = QVR_HID_REPORT_ID_CAL;
	hid_buf[1] = QVR_CMD_ID_CALIBRATION_BLOCK_DATA;

	complete_data = kzalloc(sensor->calib_data_len, GFP_KERNEL);
	if (complete_data == NULL) {
@@ -168,11 +169,12 @@ static uint8_t *read_calibration_data(void)
		sensor->calib_data_recv = 0;
		ret = hid_hw_raw_request(sensor->hdev, hid_buf[0],
			hid_buf,
			hid_request_report_size,
			QVR_HID_REQUEST_REPORT_SIZE,
			HID_FEATURE_REPORT,
			HID_REQ_SET_REPORT);
		ret = wait_event_interruptible_timeout(wq,
			sensor->calib_data_recv == 1, msecs_to_jiffies(1000));
			sensor->calib_data_recv == 1,
			msecs_to_jiffies(WAIT_EVENT_INT_TOUT));
		if (ret == 0) {
			pr_err("%s:get calibration data timeout\n", __func__);
			kfree(hid_buf);
@@ -210,23 +212,23 @@ static int control_imu_stream(bool status)
	if (hid_buf == NULL)
		return -ENOMEM;

	hid_buf[0] = 2;
	hid_buf[1] = 25;
	hid_buf[0] = QVR_HID_REPORT_ID_CAL;
	hid_buf[1] = QVR_CMD_ID_IMU_CONTROL;
	hid_buf[2] = status;

	ret = hid_hw_raw_request(sensor->hdev, hid_buf[0],
		hid_buf,
		hid_request_report_size,
		QVR_HID_REQUEST_REPORT_SIZE,
		HID_FEATURE_REPORT,
		HID_REQ_SET_REPORT);
	ret = wait_event_interruptible_timeout(wq, sensor->ext_ack == 1,
		msecs_to_jiffies(1000));
		msecs_to_jiffies(WAIT_EVENT_INT_TOUT));
	if (!ret && status) {
		pr_debug("qvr: falling back - start IMU stream failed\n");
		hid_buf[0] = hid_request_report_id;
		hid_buf[1] = 7;
		hid_buf[0] = QVR_HID_REPORT_ID_CAL;
		hid_buf[1] = QVR_CMD_ID_IMU_CONTROL_FALLBACK;
		ret = hid_hw_raw_request(sensor->hdev, hid_buf[0], hid_buf,
				hid_request_report_size,
			QVR_HID_REQUEST_REPORT_SIZE,
			HID_FEATURE_REPORT,
			HID_REQ_SET_REPORT);
	}
+12 −0
Original line number Diff line number Diff line
@@ -18,6 +18,18 @@

#define QVR_EXTERNAL_SENSOR_REPORT_ID 0x1

//CMD IDs
#define QVR_CMD_ID_CALIBRATION_DATA_SIZE      20
#define QVR_CMD_ID_CALIBRATION_BLOCK_DATA     21
#define QVR_CMD_ID_START_CALIBRATION_UPDATE   22
#define QVR_CMD_ID_UPDATE_CALIBRATION_BLOCK   23
#define QVR_CMD_ID_FINISH_CALIBRATION_UPDATE  24
#define QVR_CMD_ID_IMU_CONTROL                25
#define QVR_CMD_ID_IMU_CONTROL_FALLBACK       7

#define QVR_HID_REPORT_ID_CAL                 2
#define QVR_HID_REQUEST_REPORT_SIZE           64

struct external_imu_format {
	s16 temp0;
	s16 temp1;