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

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

HID: hid-sensor-hub: Enhance get feature report API



Some hid sensor feature report can contain more than one reports.
This API can now support receiving multiple values from the feature
report.
Also update the parameters in the users of this API.

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 b3f4737d
Loading
Loading
Loading
Loading
+13 −2
Original line number Original line Diff line number Diff line
@@ -223,10 +223,11 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
EXPORT_SYMBOL_GPL(sensor_hub_set_feature);
EXPORT_SYMBOL_GPL(sensor_hub_set_feature);


int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
				u32 field_index, s32 *value)
			   u32 field_index, int buffer_size, void *buffer)
{
{
	struct hid_report *report;
	struct hid_report *report;
	struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
	struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
	int report_size;
	int ret = 0;
	int ret = 0;


	mutex_lock(&data->mutex);
	mutex_lock(&data->mutex);
@@ -238,7 +239,17 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
	}
	}
	hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT);
	hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT);
	hid_hw_wait(hsdev->hdev);
	hid_hw_wait(hsdev->hdev);
	*value = report->field[field_index]->value[0];

	/* calculate number of bytes required to read this field */
	report_size = DIV_ROUND_UP(report->field[field_index]->report_size,
				   8) *
				   report->field[field_index]->report_count;
	if (!report_size) {
		ret = -EINVAL;
		goto done_proc;
	}
	ret = min(report_size, buffer_size);
	memcpy(buffer, report->field[field_index]->value, ret);


done_proc:
done_proc:
	mutex_unlock(&data->mutex);
	mutex_unlock(&data->mutex);
+7 −6
Original line number Original line Diff line number Diff line
@@ -154,7 +154,7 @@ s32 hid_sensor_read_poll_value(struct hid_sensor_common *st)


	ret = sensor_hub_get_feature(st->hsdev,
	ret = sensor_hub_get_feature(st->hsdev,
				     st->poll.report_id,
				     st->poll.report_id,
		st->poll.index, &value);
				     st->poll.index, sizeof(value), &value);


	if (ret < 0 || value < 0) {
	if (ret < 0 || value < 0) {
		return -EINVAL;
		return -EINVAL;
@@ -175,7 +175,7 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,


	ret = sensor_hub_get_feature(st->hsdev,
	ret = sensor_hub_get_feature(st->hsdev,
				     st->poll.report_id,
				     st->poll.report_id,
		st->poll.index, &value);
				     st->poll.index, sizeof(value), &value);
	if (ret < 0 || value < 0) {
	if (ret < 0 || value < 0) {
		*val1 = *val2 = 0;
		*val1 = *val2 = 0;
		return -EINVAL;
		return -EINVAL;
@@ -230,7 +230,8 @@ int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,


	ret = sensor_hub_get_feature(st->hsdev,
	ret = sensor_hub_get_feature(st->hsdev,
				     st->sensitivity.report_id,
				     st->sensitivity.report_id,
		st->sensitivity.index, &value);
				     st->sensitivity.index, sizeof(value),
				     &value);
	if (ret < 0 || value < 0) {
	if (ret < 0 || value < 0) {
		*val1 = *val2 = 0;
		*val1 = *val2 = 0;
		return -EINVAL;
		return -EINVAL;
+2 −2
Original line number Original line Diff line number Diff line
@@ -77,7 +77,7 @@ int hid_sensor_power_state(struct hid_sensor_common *st, bool state)


	sensor_hub_get_feature(st->hsdev, st->power_state.report_id,
	sensor_hub_get_feature(st->hsdev, st->power_state.report_id,
			       st->power_state.index,
			       st->power_state.index,
					&state_val);
			       sizeof(state_val), &state_val);
	return 0;
	return 0;
}
}
EXPORT_SYMBOL(hid_sensor_power_state);
EXPORT_SYMBOL(hid_sensor_power_state);
+5 −3
Original line number Original line Diff line number Diff line
@@ -206,13 +206,15 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
* sensor_hub_get_feature() - Feature get request
* sensor_hub_get_feature() - Feature get request
* @report_id:	Report id to look for
* @report_id:	Report id to look for
* @field_index:	Field index inside a report
* @field_index:	Field index inside a report
* @value:	Place holder for return value
* @buffer_size:	size of the buffer
* @buffer:	buffer to copy output
*
*
* Used to get a field in feature report. For example this can get polling
* Used to get a field in feature report. For example this can get polling
* interval, sensitivity, activate/deactivate state.
* interval, sensitivity, activate/deactivate state. On success it returns
* number of bytes copied to buffer. On failure, it returns value < 0.
*/
*/
int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
			u32 field_index, s32 *value);
			   u32 field_index, int buffer_size, void *buffer);


/* hid-sensor-attributes */
/* hid-sensor-attributes */