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

Commit 6259a314 authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "HID: qvr: Optimized Viewer Requirements"

parents 690765b2 4d7605bd
Loading
Loading
Loading
Loading
+36 −48
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)
@@ -101,10 +103,6 @@ struct qvr_external_sensor {
	int fd;
};

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 +116,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 +154,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 +167,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 +210,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);
	}
@@ -247,13 +247,13 @@ static int qvr_send_package_wrap(u8 *message, int msize, struct hid_device *hid)
	struct external_imu_format imuData = { 0 };
	struct qvr_buf_index *index_buf;

	/*
	 * Actual message size is 369 bytes
	 * to make it 8 byte aligned we created a structure of size 368 bytes.
	 * Ignoring the first byte 'report id' (which is always 1)
	 *
	 */
	memcpy((void *)&imuData, (void *)message + 1, msg_size);
	if (msize != sizeof(struct external_imu_format)) {
		pr_err("%s: data size mismatch %d\n", __func__, msize);
		return -EPROTO;
	}

	memcpy((void *)&imuData, (void *)message,
		sizeof(struct external_imu_format));

	if (!sensor->ts_base)
		sensor->ts_base = ktime_to_ns(ktime_get_boottime());
@@ -267,10 +267,10 @@ static int qvr_send_package_wrap(u8 *message, int msize, struct hid_device *hid)
	data = (struct qvr_sensor_t *)&(sensor_buf[buf_index]);
	if (sensor->ts_offset > imuData.gts0)
		data->ats = sensor->ts_base +
				((sensor->ts_offset - imuData.gts0) * 100);
			sensor->ts_offset - imuData.gts0;
	else
		data->ats = sensor->ts_base +
				((imuData.gts0 - sensor->ts_offset) * 100);
			imuData.gts0 - sensor->ts_offset;
	if (imuData.mts0 == 0)
		data->mts = 0;
	else
@@ -415,7 +415,7 @@ static ssize_t ts_base_store(struct kobject *kobj,
static ssize_t ts_offset_show(struct kobject *kobj,
	struct kobj_attribute *attr, char *buf)
{
	return snprintf(buf, 16, "%lld\n", qvr_external_sensor.ts_offset * 100);
	return snprintf(buf, 16, "%lld\n", qvr_external_sensor.ts_offset);
}

static ssize_t ts_offset_store(struct kobject *kobj,
@@ -454,7 +454,6 @@ static int qvr_external_sensor_probe(struct hid_device *hdev,
	struct qvr_external_sensor *sensor = &qvr_external_sensor;
	int ret;
	char *node_name = "qcom,smp2p-interrupt-qvrexternal-5-out";
	__u8 *hid_buf;
	sensor->hdev = hdev;

	ret = register_smp2p(&hdev->dev, node_name, &sensor->gpio_info_out);
@@ -472,17 +471,6 @@ static int qvr_external_sensor_probe(struct hid_device *hdev,
		pr_err("%s: hid_hw_start failed\n", __func__);
		goto err_free;
	}
	hid_buf = kzalloc(255, GFP_ATOMIC);
	if (hid_buf == NULL)
		return -ENOMEM;
	hid_buf[0] = hid_request_report_id;
	hid_buf[1] = 7;
	ret = hid_hw_raw_request(hdev, hid_buf[0], hid_buf,
		hid_request_report_size,
		HID_FEATURE_REPORT,
		HID_REQ_SET_REPORT);
	kfree(hid_buf);

	sensor->device = &hdev->dev;

	return 0;
+39 −131
Original line number Diff line number Diff line
@@ -18,144 +18,52 @@

#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;
	s16 temp2;
	s16 temp3;
	u8 reportID;
	u8 padding;
	u16 version;
	u16 numIMUs;
	u16 numSamplesPerImuPacket;
	u16 totalPayloadSize;
	u8 reservedPadding[28];

	s16 imuID;
	s16 sampleID;
	s16 temperature;

	u64 gts0;
	u64 gts1;
	u64 gts2;
	u64 gts3;
	s16 gx0;
	s16 gx1;
	s16 gx2;
	s16 gx3;
	s16 gx4;
	s16 gx5;
	s16 gx6;
	s16 gx7;
	s16 gx8;
	s16 gx9;
	s16 gx10;
	s16 gx11;
	s16 gx12;
	s16 gx13;
	s16 gx14;
	s16 gx15;
	s16 gx16;
	s16 gx17;
	s16 gx18;
	s16 gx19;
	s16 gx20;
	s16 gx21;
	s16 gx22;
	s16 gx23;
	s16 gx24;
	s16 gx25;
	s16 gx26;
	s16 gx27;
	s16 gx28;
	s16 gx29;
	s16 gx30;
	s16 gx31;
	s16 gy0;
	s16 gy1;
	s16 gy2;
	s16 gy3;
	s16 gy4;
	s16 gy5;
	s16 gy6;
	s16 gy7;
	s16 gy8;
	s16 gy9;
	s16 gy10;
	s16 gy11;
	s16 gy12;
	s16 gy13;
	s16 gy14;
	s16 gy15;
	s16 gy16;
	s16 gy17;
	s16 gy18;
	s16 gy19;
	s16 gy20;
	s16 gy21;
	s16 gy22;
	s16 gy23;
	s16 gy24;
	s16 gy25;
	s16 gy26;
	s16 gy27;
	s16 gy28;
	s16 gy29;
	s16 gy30;
	s16 gy31;
	s16 gz0;
	s16 gz1;
	s16 gz2;
	s16 gz3;
	s16 gz4;
	s16 gz5;
	s16 gz6;
	s16 gz7;
	s16 gz8;
	s16 gz9;
	s16 gz10;
	s16 gz11;
	s16 gz12;
	s16 gz13;
	s16 gz14;
	s16 gz15;
	s16 gz16;
	s16 gz17;
	s16 gz18;
	s16 gz19;
	s16 gz20;
	s16 gz21;
	s16 gz22;
	s16 gz23;
	s16 gz24;
	s16 gz25;
	s16 gz26;
	s16 gz27;
	s16 gz28;
	s16 gz29;
	s16 gz30;
	s16 gz31;
	u32 gNumerator;
	u32 gDenominator;
	s32 gx0;
	s32 gy0;
	s32 gz0;

	u64 ats0;
	u64 ats1;
	u64 ats2;
	u64 ats3;
	u32 aNumerator;
	u32 aDenominator;
	s32 ax0;
	s32 ax1;
	s32 ax2;
	s32 ax3;
	s32 ay0;
	s32 ay1;
	s32 ay2;
	s32 ay3;
	s32 az0;
	s32 az1;
	s32 az2;
	s32 az3;

	u64 mts0;
	u64 mts1;
	u64 mts2;
	u64 mts3;
	s16 mx0;
	s16 mx1;
	s16 mx2;
	s16 mx3;
	s16 my0;
	s16 my1;
	s16 my2;
	s16 my3;
	s16 mz0;
	s16 mz1;
	s16 mz2;
	s16 mz3; //368 bytes
};
	u32 mNumerator;
	u32 mDenominator;
	s32 mx0;
	s32 my0;
	s32 mz0;
} __packed;

void qvr_clear_def_parmeter(void);
void qvr_init(struct hid_device *hdev);