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

Commit b3f4737d authored by Srinivas Pandruvada's avatar Srinivas Pandruvada Committed by Jiri Kosina
Browse files

HID: hid-sensor-hub: Extend API for async reads



Add additional flag to read in async mode. In this mode the caller will get
reply via registered callback for capture_sample. Callbacks can be registered
using sensor_hub_register_callback function. The usage id parameter of the
capture_sample can be matched with the usage id of the requested attribute.

Signed-off-by: default avatarSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Acked-by: default avatarJonathan Cameron <jic23@kernel.org>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent cb67126f
Loading
Loading
Loading
Loading
+35 −30
Original line number Original line Diff line number Diff line
@@ -250,14 +250,21 @@ EXPORT_SYMBOL_GPL(sensor_hub_get_feature);


int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
					u32 usage_id,
					u32 usage_id,
					u32 attr_usage_id, u32 report_id)
					u32 attr_usage_id, u32 report_id,
					enum sensor_hub_read_flags flag)
{
{
	struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
	struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
	unsigned long flags;
	unsigned long flags;
	struct hid_report *report;
	struct hid_report *report;
	int ret_val = 0;
	int ret_val = 0;


	report = sensor_hub_report(report_id, hsdev->hdev,
				   HID_INPUT_REPORT);
	if (!report)
		return -EINVAL;

	mutex_lock(&hsdev->mutex);
	mutex_lock(&hsdev->mutex);
	if (flag == SENSOR_HUB_SYNC) {
		memset(&hsdev->pending, 0, sizeof(hsdev->pending));
		memset(&hsdev->pending, 0, sizeof(hsdev->pending));
		init_completion(&hsdev->pending.ready);
		init_completion(&hsdev->pending.ready);
		hsdev->pending.usage_id = usage_id;
		hsdev->pending.usage_id = usage_id;
@@ -267,14 +274,13 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
		spin_lock_irqsave(&data->lock, flags);
		spin_lock_irqsave(&data->lock, flags);
		hsdev->pending.status = true;
		hsdev->pending.status = true;
		spin_unlock_irqrestore(&data->lock, flags);
		spin_unlock_irqrestore(&data->lock, flags);
	report = sensor_hub_report(report_id, hsdev->hdev, HID_INPUT_REPORT);
	}
	if (!report)
		goto err_free;

	mutex_lock(&data->mutex);
	mutex_lock(&data->mutex);
	hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT);
	hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT);
	mutex_unlock(&data->mutex);
	mutex_unlock(&data->mutex);
	wait_for_completion_interruptible_timeout(&hsdev->pending.ready, HZ*5);
	if (flag == SENSOR_HUB_SYNC) {
		wait_for_completion_interruptible_timeout(
						&hsdev->pending.ready, HZ*5);
		switch (hsdev->pending.raw_size) {
		switch (hsdev->pending.raw_size) {
		case 1:
		case 1:
			ret_val = *(u8 *)hsdev->pending.raw_data;
			ret_val = *(u8 *)hsdev->pending.raw_data;
@@ -289,9 +295,8 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
			ret_val = 0;
			ret_val = 0;
		}
		}
		kfree(hsdev->pending.raw_data);
		kfree(hsdev->pending.raw_data);

err_free:
		hsdev->pending.status = false;
		hsdev->pending.status = false;
	}
	mutex_unlock(&hsdev->mutex);
	mutex_unlock(&hsdev->mutex);


	return ret_val;
	return ret_val;
+2 −1
Original line number Original line Diff line number Diff line
@@ -130,7 +130,8 @@ static int accel_3d_read_raw(struct iio_dev *indio_dev,
			*val = sensor_hub_input_attr_get_raw_value(
			*val = sensor_hub_input_attr_get_raw_value(
					accel_state->common_attributes.hsdev,
					accel_state->common_attributes.hsdev,
					HID_USAGE_SENSOR_ACCEL_3D, address,
					HID_USAGE_SENSOR_ACCEL_3D, address,
					report_id);
					report_id,
					SENSOR_HUB_SYNC);
		else {
		else {
			*val = 0;
			*val = 0;
			hid_sensor_power_state(&accel_state->common_attributes,
			hid_sensor_power_state(&accel_state->common_attributes,
+2 −1
Original line number Original line Diff line number Diff line
@@ -130,7 +130,8 @@ static int gyro_3d_read_raw(struct iio_dev *indio_dev,
			*val = sensor_hub_input_attr_get_raw_value(
			*val = sensor_hub_input_attr_get_raw_value(
					gyro_state->common_attributes.hsdev,
					gyro_state->common_attributes.hsdev,
					HID_USAGE_SENSOR_GYRO_3D, address,
					HID_USAGE_SENSOR_GYRO_3D, address,
					report_id);
					report_id,
					SENSOR_HUB_SYNC);
		else {
		else {
			*val = 0;
			*val = 0;
			hid_sensor_power_state(&gyro_state->common_attributes,
			hid_sensor_power_state(&gyro_state->common_attributes,
+2 −1
Original line number Original line Diff line number Diff line
@@ -109,7 +109,8 @@ static int als_read_raw(struct iio_dev *indio_dev,
			*val = sensor_hub_input_attr_get_raw_value(
			*val = sensor_hub_input_attr_get_raw_value(
					als_state->common_attributes.hsdev,
					als_state->common_attributes.hsdev,
					HID_USAGE_SENSOR_ALS, address,
					HID_USAGE_SENSOR_ALS, address,
					report_id);
					report_id,
					SENSOR_HUB_SYNC);
			hid_sensor_power_state(&als_state->common_attributes,
			hid_sensor_power_state(&als_state->common_attributes,
						false);
						false);
		} else {
		} else {
+2 −1
Original line number Original line Diff line number Diff line
@@ -105,7 +105,8 @@ static int prox_read_raw(struct iio_dev *indio_dev,
			*val = sensor_hub_input_attr_get_raw_value(
			*val = sensor_hub_input_attr_get_raw_value(
				prox_state->common_attributes.hsdev,
				prox_state->common_attributes.hsdev,
				HID_USAGE_SENSOR_PROX, address,
				HID_USAGE_SENSOR_PROX, address,
				report_id);
				report_id,
				SENSOR_HUB_SYNC);
			hid_sensor_power_state(&prox_state->common_attributes,
			hid_sensor_power_state(&prox_state->common_attributes,
						false);
						false);
		} else {
		} else {
Loading