Skip to contentSkip to conversation

resolve read hystersis return invalid argument issue for hid sensors

PATCH Superseded Ye Xiang 3 participants 9 messages Jan 20, 2021 – Jan 31, 2021 1 message not in the archive

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ye Xiang

author
#0 lore raw

cover resolve read hystersis return invalid argument issue for hid sensors

This patch series move get sensitivity attribute to common layer and resolve read hystersis return invalid argument issue for hid sensors als, incli-3d, rotation, and press on intel ISH Platform.

Ye Xiang (3):
iio: hid-sensors: Move get sensitivity attribute to hid-sensor-common
hid-sensor-common: Add relative sensitivity check
hid-sensors: Add more data fields for sensitivity checking

 drivers/iio/accel/hid-sensor-accel-3d.c       | 23 +++++--------
 .../hid-sensors/hid-sensor-attributes.c       | 26 +++++++++++++-
 drivers/iio/gyro/hid-sensor-gyro-3d.c         | 19 ++++-------
 drivers/iio/humidity/hid-sensor-humidity.c    | 16 ++++-----
 drivers/iio/light/hid-sensor-als.c            | 20 +++++------
 drivers/iio/light/hid-sensor-prox.c           | 27 +++++----------
 drivers/iio/magnetometer/hid-sensor-magn-3d.c | 34 ++++++-------------
 drivers/iio/orientation/hid-sensor-incl-3d.c  | 20 +++++------
 drivers/iio/orientation/hid-sensor-rotation.c | 24 ++++++-------
 .../position/hid-sensor-custom-intel-hinge.c  | 20 ++++-------
 drivers/iio/pressure/hid-sensor-press.c       | 20 +++++------
 .../iio/temperature/hid-sensor-temperature.c  | 16 ++++-----
 drivers/rtc/rtc-hid-sensor-time.c             |  4 ++-
 include/linux/hid-sensor-hub.h                |  4 ++-
 include/linux/hid-sensor-ids.h                |  1 +
 15 files changed, 122 insertions(+), 152 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/3 iio: hid-sensors: Move get sensitivity attribute to hid-sensor-common

No functional change has been made with this patch. The main intent here is to reduce code repetition of get sensitivity attribute.

In the current implementation, sensor_hub_input_get_attribute_info() is called from multiple drivers to get attribute info for sensitivity field. Moving this to common place will avoid code repetition.

---
 drivers/iio/accel/hid-sensor-accel-3d.c       | 23 +++++--------
 .../hid-sensors/hid-sensor-attributes.c       | 17 +++++++++-
 drivers/iio/gyro/hid-sensor-gyro-3d.c         | 19 ++++-------
 drivers/iio/humidity/hid-sensor-humidity.c    | 16 ++++-----
 drivers/iio/light/hid-sensor-als.c            | 19 ++++-------
 drivers/iio/light/hid-sensor-prox.c           | 27 +++++----------
 drivers/iio/magnetometer/hid-sensor-magn-3d.c | 34 ++++++-------------
 drivers/iio/orientation/hid-sensor-incl-3d.c  | 19 ++++-------
 drivers/iio/orientation/hid-sensor-rotation.c | 23 +++++--------
 .../position/hid-sensor-custom-intel-hinge.c  | 20 ++++-------
 drivers/iio/pressure/hid-sensor-press.c       | 19 ++++-------
 .../iio/temperature/hid-sensor-temperature.c  | 16 ++++-----
 drivers/rtc/rtc-hid-sensor-time.c             |  4 ++-
 include/linux/hid-sensor-hub.h                |  4 ++-
 14 files changed, 108 insertions(+), 152 deletions(-)
drivers/iio/accel/hid-sensor-accel-3d.c +9 -14
index 5d63ed19e6e2..2f9465cb382f 100644
@@ -43,6 +43,10 @@ static const u32 accel_3d_addresses[ACCEL_3D_CHANNEL_MAX] = {
 	HID_USAGE_SENSOR_ACCEL_Z_AXIS
 };
 
+static const u32 accel_3d_sensitivity_addresses[] = {
+	HID_USAGE_SENSOR_DATA_ACCELERATION,
+};
+
 /* Channel definitions */
 static const struct iio_chan_spec accel_3d_channels[] = {
 	{
@@ -317,18 +321,6 @@ static int accel_3d_parse_report(struct platform_device *pdev,
 				&st->accel[CHANNEL_SCAN_INDEX_X],
 				&st->scale_pre_decml, &st->scale_post_decml);
 
-	/* Set Sensitivity field ids, when there is no individual modifier */
-	if (st->common_attributes.sensitivity.index < 0) {
-		sensor_hub_input_get_attribute_info(hsdev,
-			HID_FEATURE_REPORT, usage_id,
-			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_DATA_ACCELERATION,
-			&st->common_attributes.sensitivity);
-		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
-			st->common_attributes.sensitivity.index,
-			st->common_attributes.sensitivity.report_id);
-	}
-
 	return ret;
 }
 
@@ -366,8 +358,11 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
 		channel_size = sizeof(gravity_channels);
 		indio_dev->num_channels = ARRAY_SIZE(gravity_channels);
 	}
-	ret = hid_sensor_parse_common_attributes(hsdev, hsdev->usage,
-					&accel_state->common_attributes);
+	ret = hid_sensor_parse_common_attributes(hsdev,
+						 hsdev->usage,
+						 &accel_state->common_attributes,
+						 accel_3d_sensitivity_addresses,
+						 ARRAY_SIZE(accel_3d_sensitivity_addresses));
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup common attributes\n");
 		return ret;
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +16 -1
index 5b822a4298a0..d349ace2e33f 100644
@@ -448,12 +448,15 @@ EXPORT_SYMBOL(hid_sensor_batch_mode_supported);
 
 int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 					u32 usage_id,
-					struct hid_sensor_common *st)
+					struct hid_sensor_common *st,
+					const u32 *sensitivity_addresses,
+					u32 sensitivity_addresses_len)
 {
 
 	struct hid_sensor_hub_attribute_info timestamp;
 	s32 value;
 	int ret;
+	int i;
 
 	hid_sensor_get_reporting_interval(hsdev, usage_id, st);
 
@@ -475,6 +478,18 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 			HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS,
 			 &st->sensitivity);
 
+	/*
+	 * Set Sensitivity field ids, when there is no individual modifier, will
+	 * check absolute sensitivity of data field
+	 */
+	for (i = 0; i < sensitivity_addresses_len && st->sensitivity.index < 0; i++) {
+		sensor_hub_input_get_attribute_info(hsdev,
+				HID_FEATURE_REPORT, usage_id,
+				HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
+					sensitivity_addresses[i],
+				&st->sensitivity);
+	}
+
 	st->raw_hystersis = -1;
 
 	sensor_hub_input_get_attribute_info(hsdev,
drivers/iio/gyro/hid-sensor-gyro-3d.c +7 -12
index fb0d678ece1a..dad26ee4fd1f 100644
@@ -45,6 +45,10 @@ static const u32 gyro_3d_addresses[GYRO_3D_CHANNEL_MAX] = {
 	HID_USAGE_SENSOR_ANGL_VELOCITY_Z_AXIS
 };
 
+static const u32 gryo_3d_sensitivity_addresses[] = {
+	HID_USAGE_SENSOR_DATA_ANGL_VELOCITY,
+};
+
 /* Channel definitions */
 static const struct iio_chan_spec gyro_3d_channels[] = {
 	{
@@ -271,17 +275,6 @@ static int gyro_3d_parse_report(struct platform_device *pdev,
 				&st->gyro[CHANNEL_SCAN_INDEX_X],
 				&st->scale_pre_decml, &st->scale_post_decml);
 
-	/* Set Sensitivity field ids, when there is no individual modifier */
-	if (st->common_attributes.sensitivity.index < 0) {
-		sensor_hub_input_get_attribute_info(hsdev,
-			HID_FEATURE_REPORT, usage_id,
-			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_DATA_ANGL_VELOCITY,
-			&st->common_attributes.sensitivity);
-		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
-			st->common_attributes.sensitivity.index,
-			st->common_attributes.sensitivity.report_id);
-	}
 	return ret;
 }
 
@@ -305,7 +298,9 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)
 
 	ret = hid_sensor_parse_common_attributes(hsdev,
 						HID_USAGE_SENSOR_GYRO_3D,
-						&gyro_state->common_attributes);
+						&gyro_state->common_attributes,
+						gryo_3d_sensitivity_addresses,
+						ARRAY_SIZE(gryo_3d_sensitivity_addresses));
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup common attributes\n");
 		return ret;
drivers/iio/humidity/hid-sensor-humidity.c +7 -9
index 52f605114ef7..ec88ae3f233d 100644
@@ -22,6 +22,10 @@ struct hid_humidity_state {
 	int value_offset;
 };
 
+static const u32 humidity_sensitivity_addresses[] = {
+	HID_USAGE_SENSOR_ATMOSPHERIC_HUMIDITY,
+};
+
 /* Channel definitions */
 static const struct iio_chan_spec humidity_channels[] = {
 	{
@@ -174,14 +178,6 @@ static int humidity_parse_report(struct platform_device *pdev,
 						&st->scale_pre_decml,
 						&st->scale_post_decml);
 
-	/* Set Sensitivity field ids, when there is no individual modifier */
-	if (st->common_attributes.sensitivity.index < 0)
-		sensor_hub_input_get_attribute_info(hsdev,
-			HID_FEATURE_REPORT, usage_id,
-			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_ATMOSPHERIC_HUMIDITY,
-			&st->common_attributes.sensitivity);
-
 	return ret;
 }
 
@@ -210,7 +206,9 @@ static int hid_humidity_probe(struct platform_device *pdev)
 
 	ret = hid_sensor_parse_common_attributes(hsdev,
 					HID_USAGE_SENSOR_HUMIDITY,
-					&humid_st->common_attributes);
+					&humid_st->common_attributes,
+					humidity_sensitivity_addresses,
+					ARRAY_SIZE(humidity_sensitivity_addresses));
 	if (ret)
 		return ret;
 
drivers/iio/light/hid-sensor-als.c +7 -12
index 4093f2353d95..8bf6e9e0a0e0 100644
@@ -39,6 +39,10 @@ struct als_state {
 	s64 timestamp;
 };
 
+static const u32 als_sensitivity_addresses[] = {
+	HID_USAGE_SENSOR_DATA_LIGHT,
+};
+
 /* Channel definitions */
 static const struct iio_chan_spec als_channels[] = {
 	{
@@ -252,17 +256,6 @@ static int als_parse_report(struct platform_device *pdev,
 				&st->als_illum,
 				&st->scale_pre_decml, &st->scale_post_decml);
 
-	/* Set Sensitivity field ids, when there is no individual modifier */
-	if (st->common_attributes.sensitivity.index < 0) {
-		sensor_hub_input_get_attribute_info(hsdev,
-			HID_FEATURE_REPORT, usage_id,
-			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_DATA_LIGHT,
-			&st->common_attributes.sensitivity);
-		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
-			st->common_attributes.sensitivity.index,
-			st->common_attributes.sensitivity.report_id);
-	}
 	return ret;
 }
 
@@ -285,7 +278,9 @@ static int hid_als_probe(struct platform_device *pdev)
 	als_state->common_attributes.pdev = pdev;
 
 	ret = hid_sensor_parse_common_attributes(hsdev, HID_USAGE_SENSOR_ALS,
-					&als_state->common_attributes);
+					&als_state->common_attributes,
+					als_sensitivity_addresses,
+					ARRAY_SIZE(als_sensitivity_addresses));
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup common attributes\n");
 		return ret;
drivers/iio/light/hid-sensor-prox.c +8 -19
index 330cf359e0b8..4ab285a418d5 100644
@@ -25,6 +25,11 @@ struct prox_state {
 	u32 human_presence;
 };
 
+static const u32 prox_sensitivity_addresses[] = {
+	HID_USAGE_SENSOR_HUMAN_PRESENCE,
+	HID_USAGE_SENSOR_DATA_PRESENCE,
+};
+
 /* Channel definitions */
 static const struct iio_chan_spec prox_channels[] = {
 	{
@@ -216,24 +221,6 @@ static int prox_parse_report(struct platform_device *pdev,
 	dev_dbg(&pdev->dev, "prox %x:%x\n", st->prox_attr.index,
 			st->prox_attr.report_id);
 
-	/* Set Sensitivity field ids, when there is no individual modifier */
-	if (st->common_attributes.sensitivity.index < 0) {
-		sensor_hub_input_get_attribute_info(hsdev,
-			HID_FEATURE_REPORT, usage_id,
-			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_DATA_PRESENCE,
-			&st->common_attributes.sensitivity);
-		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
-			st->common_attributes.sensitivity.index,
-			st->common_attributes.sensitivity.report_id);
-	}
-	if (st->common_attributes.sensitivity.index < 0)
-		sensor_hub_input_get_attribute_info(hsdev,
-			HID_FEATURE_REPORT, usage_id,
-			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_HUMAN_PRESENCE,
-			&st->common_attributes.sensitivity);
-
 	return ret;
 }
 
@@ -257,7 +244,9 @@ static int hid_prox_probe(struct platform_device *pdev)
 	prox_state->common_attributes.pdev = pdev;
 
 	ret = hid_sensor_parse_common_attributes(hsdev, HID_USAGE_SENSOR_PROX,
-					&prox_state->common_attributes);
+					&prox_state->common_attributes,
+					prox_sensitivity_addresses,
+					ARRAY_SIZE(prox_sensitivity_addresses));
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup common attributes\n");
 		return ret;
drivers/iio/magnetometer/hid-sensor-magn-3d.c +11 -23
index fa48044b7f5b..338b7e6b1d0f 100644
@@ -62,6 +62,11 @@ static const u32 magn_3d_addresses[MAGN_3D_CHANNEL_MAX] = {
 	HID_USAGE_SENSOR_TIME_TIMESTAMP,
 };
 
+static const u32 magn_3d_sensitivity_addresses[] = {
+	HID_USAGE_SENSOR_DATA_ORIENTATION,
+	HID_USAGE_SENSOR_ORIENT_MAGN_FLUX,
+};
+
 /* Channel definitions */
 static const struct iio_chan_spec magn_3d_channels[] = {
 	{
@@ -448,32 +453,11 @@ static int magn_3d_parse_report(struct platform_device *pdev,
 			&st->rot_attr.scale_pre_decml,
 			&st->rot_attr.scale_post_decml);
 
-	/* Set Sensitivity field ids, when there is no individual modifier */
-	if (st->magn_flux_attributes.sensitivity.index < 0) {
-		sensor_hub_input_get_attribute_info(hsdev,
-			HID_FEATURE_REPORT, usage_id,
-			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_DATA_ORIENTATION,
-			&st->magn_flux_attributes.sensitivity);
-		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
-			st->magn_flux_attributes.sensitivity.index,
-			st->magn_flux_attributes.sensitivity.report_id);
-	}
-	if (st->magn_flux_attributes.sensitivity.index < 0) {
-		sensor_hub_input_get_attribute_info(hsdev,
-			HID_FEATURE_REPORT, usage_id,
-			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_ORIENT_MAGN_FLUX,
-			&st->magn_flux_attributes.sensitivity);
-		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
-			st->magn_flux_attributes.sensitivity.index,
-			st->magn_flux_attributes.sensitivity.report_id);
-	}
 	if (st->rot_attributes.sensitivity.index < 0) {
 		sensor_hub_input_get_attribute_info(hsdev,
 			HID_FEATURE_REPORT, usage_id,
 			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH,
+				HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH,
 			&st->rot_attributes.sensitivity);
 		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
 			st->rot_attributes.sensitivity.index,
@@ -507,12 +491,16 @@ static int hid_magn_3d_probe(struct platform_device *pdev)
 
 	ret = hid_sensor_parse_common_attributes(hsdev,
 				HID_USAGE_SENSOR_COMPASS_3D,
-				&magn_state->magn_flux_attributes);
+				&magn_state->magn_flux_attributes,
+				magn_3d_sensitivity_addresses,
+				ARRAY_SIZE(magn_3d_sensitivity_addresses));
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup common attributes\n");
 		return ret;
 	}
 	magn_state->rot_attributes = magn_state->magn_flux_attributes;
+	/* sensitivity of rot_attribute is not the same as magn_flux_attributes */
+	magn_state->rot_attributes.sensitivity.index = -1;
 
 	ret = magn_3d_parse_report(pdev, hsdev,
 				&channels, &chan_count,
drivers/iio/orientation/hid-sensor-incl-3d.c +7 -12
index 52ebef30f9be..6e69f6e673cc 100644
@@ -47,6 +47,10 @@ static const u32 incl_3d_addresses[INCLI_3D_CHANNEL_MAX] = {
 	HID_USAGE_SENSOR_ORIENT_TILT_Z
 };
 
+static const u32 incl_3d_sensitivity_addresses[] = {
+	HID_USAGE_SENSOR_DATA_ORIENTATION,
+};
+
 /* Channel definitions */
 static const struct iio_chan_spec incl_3d_channels[] = {
 	{
@@ -291,17 +295,6 @@ static int incl_3d_parse_report(struct platform_device *pdev,
 				&st->incl[CHANNEL_SCAN_INDEX_X],
 				&st->scale_pre_decml, &st->scale_post_decml);
 
-	/* Set Sensitivity field ids, when there is no individual modifier */
-	if (st->common_attributes.sensitivity.index < 0) {
-		sensor_hub_input_get_attribute_info(hsdev,
-			HID_FEATURE_REPORT, usage_id,
-			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_DATA_ORIENTATION,
-			&st->common_attributes.sensitivity);
-		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
-			st->common_attributes.sensitivity.index,
-			st->common_attributes.sensitivity.report_id);
-	}
 	return ret;
 }
 
@@ -327,7 +320,9 @@ static int hid_incl_3d_probe(struct platform_device *pdev)
 
 	ret = hid_sensor_parse_common_attributes(hsdev,
 				HID_USAGE_SENSOR_INCLINOMETER_3D,
-				&incl_state->common_attributes);
+				&incl_state->common_attributes,
+				incl_3d_sensitivity_addresses,
+				ARRAY_SIZE(incl_3d_sensitivity_addresses));
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup common attributes\n");
 		return ret;
drivers/iio/orientation/hid-sensor-rotation.c +9 -14
index 18e4ef060096..03d2845a7b2c 100644
@@ -31,6 +31,10 @@ struct dev_rot_state {
 	s64 timestamp;
 };
 
+static const u32 rotation_sensitivity_addresses[] = {
+	HID_USAGE_SENSOR_DATA_ORIENTATION,
+};
+
 /* Channel definitions */
 static const struct iio_chan_spec dev_rot_channels[] = {
 	{
@@ -214,18 +218,6 @@ static int dev_rot_parse_report(struct platform_device *pdev,
 				&st->quaternion,
 				&st->scale_pre_decml, &st->scale_post_decml);
 
-	/* Set Sensitivity field ids, when there is no individual modifier */
-	if (st->common_attributes.sensitivity.index < 0) {
-		sensor_hub_input_get_attribute_info(hsdev,
-			HID_FEATURE_REPORT, usage_id,
-			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_DATA_ORIENTATION,
-			&st->common_attributes.sensitivity);
-		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
-			st->common_attributes.sensitivity.index,
-			st->common_attributes.sensitivity.report_id);
-	}
-
 	return 0;
 }
 
@@ -263,8 +255,11 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	ret = hid_sensor_parse_common_attributes(hsdev, hsdev->usage,
-				&rot_state->common_attributes);
+	ret = hid_sensor_parse_common_attributes(hsdev,
+						 hsdev->usage,
+						 &rot_state->common_attributes,
+						 rotation_sensitivity_addresses,
+						 ARRAY_SIZE(rotation_sensitivity_addresses));
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup common attributes\n");
 		return ret;
drivers/iio/position/hid-sensor-custom-intel-hinge.c +7 -13
index 64a7fa7db6af..fd77e7ee87f3 100644
@@ -47,6 +47,10 @@ struct hinge_state {
 	u64 timestamp;
 };
 
+static const u32 hinge_sensitivity_addresses[] = {
+	HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE(1),
+};
+
 /* Channel definitions */
 static const struct iio_chan_spec hinge_channels[] = {
 	{
@@ -251,18 +255,6 @@ static int hinge_parse_report(struct platform_device *pdev,
 			&st->hinge[CHANNEL_SCAN_INDEX_HINGE_ANGLE],
 			&st->scale_pre_decml, &st->scale_post_decml);
 
-	/* Set Sensitivity field ids, when there is no individual modifier */
-	if (st->common_attributes.sensitivity.index < 0) {
-		sensor_hub_input_get_attribute_info(hsdev,
-				HID_FEATURE_REPORT, usage_id,
-				HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-					HID_USAGE_SENSOR_DATA_FIELD_CUSTOM_VALUE(1),
-				&st->common_attributes.sensitivity);
-		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
-			st->common_attributes.sensitivity.index,
-			st->common_attributes.sensitivity.report_id);
-	}
-
 	return ret;
 }
 
@@ -289,7 +281,9 @@ static int hid_hinge_probe(struct platform_device *pdev)
 		st->labels[i] = hinge_labels[i];
 
 	ret = hid_sensor_parse_common_attributes(hsdev, hsdev->usage,
-						 &st->common_attributes);
+						 &st->common_attributes,
+						 hinge_sensitivity_addresses,
+						 ARRAY_SIZE(hinge_sensitivity_addresses));
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup common attributes\n");
 		return ret;
drivers/iio/pressure/hid-sensor-press.c +7 -12
index 5c458788f346..8cac2c94e75a 100644
@@ -29,6 +29,10 @@ struct press_state {
 	int value_offset;
 };
 
+static const u32 press_sensitivity_addresses[] = {
+	HID_USAGE_SENSOR_DATA_ATMOSPHERIC_PRESSURE,
+};
+
 /* Channel definitions */
 static const struct iio_chan_spec press_channels[] = {
 	{
@@ -225,17 +229,6 @@ static int press_parse_report(struct platform_device *pdev,
 				&st->press_attr,
 				&st->scale_pre_decml, &st->scale_post_decml);
 
-	/* Set Sensitivity field ids, when there is no individual modifier */
-	if (st->common_attributes.sensitivity.index < 0) {
-		sensor_hub_input_get_attribute_info(hsdev,
-			HID_FEATURE_REPORT, usage_id,
-			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_DATA_ATMOSPHERIC_PRESSURE,
-			&st->common_attributes.sensitivity);
-		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
-			st->common_attributes.sensitivity.index,
-			st->common_attributes.sensitivity.report_id);
-	}
 	return ret;
 }
 
@@ -260,7 +253,9 @@ static int hid_press_probe(struct platform_device *pdev)
 
 	ret = hid_sensor_parse_common_attributes(hsdev,
 					HID_USAGE_SENSOR_PRESSURE,
-					&press_state->common_attributes);
+					&press_state->common_attributes,
+					press_sensitivity_addresses,
+					ARRAY_SIZE(press_sensitivity_addresses));
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup common attributes\n");
 		return ret;
drivers/iio/temperature/hid-sensor-temperature.c +7 -9
index 81688f1b932f..e3d38cbcf354 100644
@@ -22,6 +22,10 @@ struct temperature_state {
 	int value_offset;
 };
 
+static const u32 temperature_sensitivity_addresses[] = {
+	HID_USAGE_SENSOR_DATA_ENVIRONMENTAL_TEMPERATURE,
+};
+
 /* Channel definitions */
 static const struct iio_chan_spec temperature_channels[] = {
 	{
@@ -171,14 +175,6 @@ static int temperature_parse_report(struct platform_device *pdev,
 				&st->temperature_attr,
 				&st->scale_pre_decml, &st->scale_post_decml);
 
-	/* Set Sensitivity field ids, when there is no individual modifier */
-	if (st->common_attributes.sensitivity.index < 0)
-		sensor_hub_input_get_attribute_info(hsdev,
-			HID_FEATURE_REPORT, usage_id,
-			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_DATA_ENVIRONMENTAL_TEMPERATURE,
-			&st->common_attributes.sensitivity);
-
 	return ret;
 }
 
@@ -207,7 +203,9 @@ static int hid_temperature_probe(struct platform_device *pdev)
 
 	ret = hid_sensor_parse_common_attributes(hsdev,
 					HID_USAGE_SENSOR_TEMPERATURE,
-					&temp_st->common_attributes);
+					&temp_st->common_attributes,
+					temperature_sensitivity_addresses,
+					ARRAY_SIZE(temperature_sensitivity_addresses));
 	if (ret)
 		return ret;
 
drivers/rtc/rtc-hid-sensor-time.c +3 -1
index 1b42ee0758d2..47cd12db2356 100644
@@ -238,7 +238,9 @@ static int hid_time_probe(struct platform_device *pdev)
 
 	ret = hid_sensor_parse_common_attributes(hsdev,
 				HID_USAGE_SENSOR_TIME,
-				&time_state->common_attributes);
+				&time_state->common_attributes,
+				NULL,
+				0);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup common attributes!\n");
 		return ret;
include/linux/hid-sensor-hub.h +3 -1
index 46bcef380446..8b2599348554 100644
@@ -247,7 +247,9 @@ static inline int hid_sensor_convert_exponent(int unit_expo)
 
 int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 					u32 usage_id,
-					struct hid_sensor_common *st);
+					struct hid_sensor_common *st,
+					const u32 *sensitivity_addresses,
+					u32 sensitivity_addresses_len);
 int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
 					int val1, int val2);
 int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH 1/3] iio: hid-sensors: Move get sensitivity attribute to hid-sensor-common

Quoted 8 lines · On Wed, 20 Jan 2021 15:47:04 +0800 Ye Xiang <[email protected]> wrote:

No functional change has been made with this patch. The main intent here is to reduce code repetition of get sensitivity attribute.

In the current implementation, sensor_hub_input_get_attribute_info() is called from multiple drivers to get attribute info for sensitivity field. Moving this to common place will avoid code repetition.

One trivial note inline about an accidental indentation change. If that's all I find in the series I'll fix it up whilst applying.

Thanks,

Jonathan

...

Quoted 24 lines

/* Channel definitions */
static const struct iio_chan_spec magn_3d_channels[] = {

drivers/iio/magnetometer/hid-sensor-magn-3d.c +0 -17
 	{
@@ -448,32 +453,11 @@ static int magn_3d_parse_report(struct platform_device *pdev,
 			&st->rot_attr.scale_pre_decml,
 			&st->rot_attr.scale_post_decml);
 
-	/* Set Sensitivity field ids, when there is no individual modifier */
-	if (st->magn_flux_attributes.sensitivity.index < 0) {
-		sensor_hub_input_get_attribute_info(hsdev,
-			HID_FEATURE_REPORT, usage_id,
-			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_DATA_ORIENTATION,
-			&st->magn_flux_attributes.sensitivity);
-		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
-			st->magn_flux_attributes.sensitivity.index,
-			st->magn_flux_attributes.sensitivity.report_id);
-	}
-	if (st->magn_flux_attributes.sensitivity.index < 0) {
-		sensor_hub_input_get_attribute_info(hsdev,
-			HID_FEATURE_REPORT, usage_id,
-			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_ORIENT_MAGN_FLUX,
-			&st->magn_flux_attributes.sensitivity);

drivers/iio/magnetometer/hid-sensor-magn-3d.c static int magn_3d_parse_report(struct platform_device *pdev, · line 460

Quoted 10 lines
drivers/iio/magnetometer/hid-sensor-magn-3d.c +1 -5
-		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
-			st->magn_flux_attributes.sensitivity.index,
-			st->magn_flux_attributes.sensitivity.report_id);
-	}
 	if (st->rot_attributes.sensitivity.index < 0) {
 		sensor_hub_input_get_attribute_info(hsdev,
 			HID_FEATURE_REPORT, usage_id,
 			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-			HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH,
+				HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH,

This change of alignment shouldn't be here.

Quoted 21 lines
drivers/iio/magnetometer/hid-sensor-magn-3d.c +5 -1
 			&st->rot_attributes.sensitivity);
 		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
 			st->rot_attributes.sensitivity.index,
@@ -507,12 +491,16 @@ static int hid_magn_3d_probe(struct platform_device *pdev)
 
 	ret = hid_sensor_parse_common_attributes(hsdev,
 				HID_USAGE_SENSOR_COMPASS_3D,
-				&magn_state->magn_flux_attributes);
+				&magn_state->magn_flux_attributes,
+				magn_3d_sensitivity_addresses,
+				ARRAY_SIZE(magn_3d_sensitivity_addresses));
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup common attributes\n");
 		return ret;
 	}
 	magn_state->rot_attributes = magn_state->magn_flux_attributes;
+	/* sensitivity of rot_attribute is not the same as magn_flux_attributes */
+	magn_state->rot_attributes.sensitivity.index = -1;
 
 	ret = magn_3d_parse_report(pdev, hsdev,
 				&channels, &chan_count,
author
#3 lore raw

PATCH 2/3 hid-sensor-common: Add relative sensitivity check

In reply to Ye Xiang

Some hid sensors may use relative sensitivity such as als sensor. This patch add relative sensitivity check for all hid-sensors.

---
 .../iio/common/hid-sensors/hid-sensor-attributes.c    | 11 ++++++++++-
 include/linux/hid-sensor-ids.h                        |  1 +
 2 files changed, 11 insertions(+), 1 deletion(-)
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +10 -1
index d349ace2e33f..b685c292a179 100644
@@ -480,7 +480,7 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 
 	/*
 	 * Set Sensitivity field ids, when there is no individual modifier, will
-	 * check absolute sensitivity of data field
+	 * check absolute sensitivity and relative sensitivity of data field
 	 */
 	for (i = 0; i < sensitivity_addresses_len && st->sensitivity.index < 0; i++) {
 		sensor_hub_input_get_attribute_info(hsdev,
@@ -488,6 +488,15 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 				HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
 					sensitivity_addresses[i],
 				&st->sensitivity);
+
+		if (st->sensitivity.index >= 0)
+			break;
+
+		sensor_hub_input_get_attribute_info(hsdev,
+				HID_FEATURE_REPORT, usage_id,
+				HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_REL_PCT |
+					sensitivity_addresses[i],
+				&st->sensitivity);
 	}
 
 	st->raw_hystersis = -1;
include/linux/hid-sensor-ids.h +1 -0
index 3bbdbccc5805..ac631159403a 100644
@@ -149,6 +149,7 @@
 /* Per data field properties */
 #define HID_USAGE_SENSOR_DATA_MOD_NONE					0x00
 #define HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS		0x1000
+#define HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_REL_PCT            0xE000
 
 /* Power state enumerations */
 #define HID_USAGE_SENSOR_PROP_POWER_STATE_UNDEFINED_ENUM	0x200850
Signature · 1 line
2.17.1
maintainer
#4 lore raw

Re: [PATCH 2/3] hid-sensor-common: Add relative sensitivity check

Quoted 25 lines · On Wed, 20 Jan 2021 15:47:05 +0800 Ye Xiang <[email protected]> wrote:

Some hid sensors may use relative sensitivity such as als sensor. This patch add relative sensitivity check for all hid-sensors.

---
 .../iio/common/hid-sensors/hid-sensor-attributes.c    | 11 ++++++++++-
 include/linux/hid-sensor-ids.h                        |  1 +
 2 files changed, 11 insertions(+), 1 deletion(-)
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +1 -1
index d349ace2e33f..b685c292a179 100644
@@ -480,7 +480,7 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 
 	/*
 	 * Set Sensitivity field ids, when there is no individual modifier, will
-	 * check absolute sensitivity of data field
+	 * check absolute sensitivity and relative sensitivity of data field
 	 */
 	for (i = 0; i < sensitivity_addresses_len && st->sensitivity.index < 0; i++) {
 		sensor_hub_input_get_attribute_info(hsdev,
@@ -488,6 +488,15 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 				HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
 					sensitivity_addresses[i],

drivers/iio/common/hid-sensors/hid-sensor-attributes.c int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev, · line 499

Quoted 10 lines
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +9 -0
 				&st->sensitivity);
+
+		if (st->sensitivity.index >= 0)
+			break;
+
+		sensor_hub_input_get_attribute_info(hsdev,
+				HID_FEATURE_REPORT, usage_id,
+				HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_REL_PCT |
+					sensitivity_addresses[i],
+				&st->sensitivity);

We can't provide the value to userspace without reflecting the difference between the two ways of expressing it.

It seems there are 3 ways sensitivity is expressed.
1. Raw value in same units as the measurement (easy one and what is currently reported)
2. Percentage of range - also relatively easy to transform into the same as 1.
3. Percentage of prior reading.. This one doesn't fit in any existing ABI, so unfortunately we'll have to invent something new along the lines of *_hysteresis_relative

Jonathan

Quoted 15 lines
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0 -0
 	}
 
 	st->raw_hystersis = -1;
include/linux/hid-sensor-ids.h +1 -0
index 3bbdbccc5805..ac631159403a 100644
@@ -149,6 +149,7 @@
 /* Per data field properties */
 #define HID_USAGE_SENSOR_DATA_MOD_NONE					0x00
 #define HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS		0x1000
+#define HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_REL_PCT            0xE000
 
 /* Power state enumerations */
 #define HID_USAGE_SENSOR_PROP_POWER_STATE_UNDEFINED_ENUM	0x200850
#5 lore raw

Re: [PATCH 2/3] hid-sensor-common: Add relative sensitivity check

Quoted 52 lines · Jonathan Cameron
Quoted 42 lines · On Wed, 20 Jan 2021 15:47:05 +0800 Ye Xiang <[email protected]> wrote:

Some hid sensors may use relative sensitivity such as als sensor. This patch add relative sensitivity check for all hid-sensors.

---
 .../iio/common/hid-sensors/hid-sensor-attributes.c    | 11
++++++++++-
 include/linux/hid-sensor-ids.h                        |  1 +
 2 files changed, 11 insertions(+), 1 deletion(-)
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0 -0
index d349ace2e33f..b685c292a179 100644
@@ -480,7 +480,7 @@ int hid_sensor_parse_common_attributes(struct
 hid_sensor_hub_device *hsdev,
 
 	/*
 	 * Set Sensitivity field ids, when there is no individual

modifier, will

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +1 -1
-	 * check absolute sensitivity of data field
+	 * check absolute sensitivity and relative sensitivity of data

field

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0 -0
 	 */
 	for (i = 0; i < sensitivity_addresses_len && st-
Quoted 1 line

sensitivity.index < 0; i++) {

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0 -0
 		sensor_hub_input_get_attribute_info(hsdev,
@@ -488,6 +488,15 @@ int hid_sensor_parse_common_attributes(struct
 hid_sensor_hub_device *hsdev,
 				HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSIT

IVITY_ABS |

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +7 -0
 					sensitivity_addresses[i],
 				&st->sensitivity);
+
+		if (st->sensitivity.index >= 0)
+			break;
+
+		sensor_hub_input_get_attribute_info(hsdev,
+				HID_FEATURE_REPORT, usage_id,
+				HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSIT

IVITY_REL_PCT |

drivers/iio/common/hid-sensors/hid-sensor-attributes.c int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev, · line 499

Quoted 2 lines
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +2 -0
+					sensitivity_addresses[i],
+				&st->sensitivity);

We can't provide the value to userspace without reflecting the difference between
the two ways of expressing it.

Quoted 10 lines

It seems there are 3 ways sensitivity is expressed.
1. Raw value in same units as the measurement (easy one and what is currently reported)
2. Percentage of range - also relatively easy to transform into the same as 1.
3. Percentage of prior reading.. This one doesn't fit in any existing ABI, so
unfortunately we'll have to invent something new along the lines
of
*_hysteresis_relative

This is why it was not added before when I developed. But later few years back there was a patch to add this by one of our developer. There was some discussion, I thought it was decided it is OK to add.

But I agree, we should add new ABI as you suggested. Now almost every laptop has HID sensors, better to address this.

Thanks,
Srinivas

Quoted 25 lines

Jonathan

Quoted 21 lines
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0 -0
 	}
 
 	st->raw_hystersis = -1;
include/linux/hid- renamed from include/linux/hid-sensor-ids.h +0 -0

sensor-ids.h
index 3bbdbccc5805..ac631159403a 100644

include/linux/hid-sensor-ids.h +0 -0
@@ -149,6 +149,7 @@
 /* Per data field properties */
 #define HID_USAGE_SENSOR_DATA_MOD_NONE				
 	0x00
 #define HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS		

0x1000
+#define
HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_REL_PCT 0xE
000

/* Power state enumerations */
#define HID_USAGE_SENSOR_PROP_POWER_STATE_UNDEFINED_ENUM 0x20085
0

author
#6 lore raw

Re: [PATCH 2/3] hid-sensor-common: Add relative sensitivity check

Hi Srinivas andd Jonathan

Thanks for the review.

Quoted 53 lines · Srinivas Pandruvada
Quoted 52 lines · Jonathan Cameron
Quoted 42 lines · On Wed, 20 Jan 2021 15:47:05 +0800 Ye Xiang <[email protected]> wrote:

Some hid sensors may use relative sensitivity such as als sensor. This patch add relative sensitivity check for all hid-sensors.

---
 .../iio/common/hid-sensors/hid-sensor-attributes.c    | 11
++++++++++-
 include/linux/hid-sensor-ids.h                        |  1 +
 2 files changed, 11 insertions(+), 1 deletion(-)
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0 -0
index d349ace2e33f..b685c292a179 100644
@@ -480,7 +480,7 @@ int hid_sensor_parse_common_attributes(struct
 hid_sensor_hub_device *hsdev,
 
 	/*
 	 * Set Sensitivity field ids, when there is no individual

modifier, will

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +1 -1
-	 * check absolute sensitivity of data field
+	 * check absolute sensitivity and relative sensitivity of data

field

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0 -0
 	 */
 	for (i = 0; i < sensitivity_addresses_len && st-
Quoted 1 line

sensitivity.index < 0; i++) {

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0 -0
 		sensor_hub_input_get_attribute_info(hsdev,
@@ -488,6 +488,15 @@ int hid_sensor_parse_common_attributes(struct
 hid_sensor_hub_device *hsdev,
 				HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSIT

IVITY_ABS |

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +7 -0
 					sensitivity_addresses[i],
 				&st->sensitivity);
+
+		if (st->sensitivity.index >= 0)
+			break;
+
+		sensor_hub_input_get_attribute_info(hsdev,
+				HID_FEATURE_REPORT, usage_id,
+				HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSIT

IVITY_REL_PCT |

drivers/iio/common/hid-sensors/hid-sensor-attributes.c int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev, · line 499

Quoted 2 lines
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +2 -0
+					sensitivity_addresses[i],
+				&st->sensitivity);

We can't provide the value to userspace without reflecting the difference between
the two ways of expressing it.

Quoted 10 lines
Quoted 10 lines

It seems there are 3 ways sensitivity is expressed.
1. Raw value in same units as the measurement (easy one and what is currently reported)
2. Percentage of range - also relatively easy to transform into the same as 1.
3. Percentage of prior reading.. This one doesn't fit in any existing ABI, so
unfortunately we'll have to invent something new along the lines
of
*_hysteresis_relative

yes, the 3th version sensitivity (Percentage of prior reading) is what we are using for als sensor now. the 1th version sensitivity is common used by other hid sensors. Do you have suggestion or reference about how to add *_hysteresis_relative field to iio model?

Quoted 8 lines

This is why it was not added before when I developed. But later few years back there was a patch to add this by one of our developer. There was some discussion, I thought it was decided it is OK to add.

But I agree, we should add new ABI as you suggested. Now almost every laptop has HID sensors, better to address this.

I think the add relative hystersis patch should be separated into a independent patch series, for it's a independent function and need more effort for coding and testing. And I can submit the other two patch in this patch series first.

Quoted 25 lines
Quoted 24 lines
Quoted 24 lines
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0 -0
 	}
 
 	st->raw_hystersis = -1;
include/linux/hid- renamed from include/linux/hid-sensor-ids.h +0 -0

sensor-ids.h
index 3bbdbccc5805..ac631159403a 100644

include/linux/hid-sensor-ids.h +0 -0
@@ -149,6 +149,7 @@
 /* Per data field properties */
 #define HID_USAGE_SENSOR_DATA_MOD_NONE				
 	0x00
 #define HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS		

0x1000
+#define
HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_REL_PCT 0xE
000

/* Power state enumerations */
#define HID_USAGE_SENSOR_PROP_POWER_STATE_UNDEFINED_ENUM 0x20085
0

A message that is not in the archive (sent off-list or not yet received): 20210131112648.3299b2a0@archlinux

#8 lore raw

Re: [PATCH 2/3] hid-sensor-common: Add relative sensitivity check

Quoted 101 lines · Jonathan Cameron
Quoted 84 lines · Xiang

Hi Srinivas andd Jonathan

Thanks for the review.

Quoted 64 lines · Srinivas Pandruvada
Quoted 63 lines · Jonathan Cameron
Quoted 54 lines · On Wed, 20 Jan 2021 15:47:05 +0800 Ye Xiang <[email protected]> wrote:

Some hid sensors may use relative sensitivity such as als sensor.
This patch add relative sensitivity check for all hid- sensors.

---
 .../iio/common/hid-sensors/hid-sensor-attributes.c    | 11
++++++++++-
 include/linux/hid-sensor-ids.h                        |  1 +
 2 files changed, 11 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c index d349ace2e33f..b685c292a179 100644

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0 -0
@@ -480,7 +480,7 @@ int

hid_sensor_parse_common_attributes(struct
hid_sensor_hub_device *hsdev,

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0 -0
 	/*
 	 * Set Sensitivity field ids, when there is no

individualsha512sum
modifier, will

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +1 -1
-	 * check absolute sensitivity of data field
+	 * check absolute sensitivity and relative sensitivity

of data
field

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0 -0
 	 */
 	for (i = 0; i < sensitivity_addresses_len && st-  
Quoted 1 line

sensitivity.index < 0; i++) {

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0 -0
 		sensor_hub_input_get_attribute_info(hsdev,
@@ -488,6 +488,15 @@ int

hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
HID_USAGE_SENSOR_DATA_MOD_CHANG
E_SENSIT
IVITY_ABS |
sensitivity_addresses[i
],

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +7 -0
 				&st->sensitivity);
+
+		if (st->sensitivity.index >= 0)
+			break;
+
+		sensor_hub_input_get_attribute_info(hsdev,
+				HID_FEATURE_REPORT, usage_id,
+				HID_USAGE_SENSOR_DATA_MOD_CHANG

E_SENSIT
IVITY_REL_PCT |

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +1 -0
+					sensitivity_addresses[i

],

drivers/iio/common/hid-sensors/hid-sensor-attributes.c int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev, · line 499

Quoted 1 line
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +1 -0
+				&st->sensitivity);  

We can't provide the value to userspace without reflecting the difference between
the two ways of expressing it.

Quoted 13 lines
Quoted 5 lines

It seems there are 3 ways sensitivity is expressed.
1. Raw value in same units as the measurement (easy one and what is
currently reported)
2. Percentage of range - also relatively easy to transform into

Quoted 8 lines

the
same as 1.
3. Percentage of prior reading.. This one doesn't fit in any existing ABI, so
unfortunately we'll have to invent something new along the
lines
of
*_hysteresis_relative

Quoted 6 lines

yes, the 3th version sensitivity (Percentage of prior reading) is what we
are using for als sensor now. the 1th version sensitivity is common used
by other hid sensors. Do you have suggestion or reference about how to add *_hysteresis_relative field to iio model?

Follow through how elements of iio_chan_info_enum in include/linux/iio/types.h are used and you should see how to add a new
one (basically add an entry to that and also the string to the right array in industrialio-core.c + document it in Documentation/ABI/testing/sysfs-bus-iio.

Quoted 7 lines

The issue with putting this in is we are going to be 'fixing' the ABI for
that ALS sensor which is going to cause problems for any userspace users
of that interface... I have no idea how commonly this is used, but it is
possible we'll have to leave that one as incorrect :(

Currently we don't have relative usage id treatment, So user space gets error in read/write for ALS. So I think it shouldn't be a problem.

Thanks,
Srinivas

Quoted 54 lines
Quoted 12 lines
Quoted 11 lines

This is why it was not added before when I developed. But later few
years back there was a patch to add this by one of our developer. There
was some discussion, I thought it was decided it is OK to add.

But I agree, we should add new ABI as you suggested. Now almost every
laptop has HID sensors, better to address this.

Quoted 6 lines

I think the add relative hystersis patch should be separated into a independent
patch series, for it's a independent function and need more effort for coding and
testing. And I can submit the other two patch in this patch series first.

Sure, if they are independent that should be fine.

Thanks,

Jonathan

Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 28 lines
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0 -0
 	}
 
 	st->raw_hystersis = -1;
include/linux/hid- renamed from include/linux/hid-sensor-ids.h +0 -0

sensor-ids.h
index 3bbdbccc5805..ac631159403a 100644

include/linux/hid-sensor-ids.h +0 -0
@@ -149,6 +149,7 @@
 /* Per data field properties */
 #define HID_USAGE_SENSOR_DATA_MOD_NONE			
 
 	0x00
 #define HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS	
 

0x1000
+#define HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_REL_PCT
0xE
000

/* Power state enumerations */
#define HID_USAGE_SENSOR_PROP_POWER_STATE_UNDEFINED_ENUM
0x20085
0

author
#9 lore raw

PATCH 3/3 hid-sensors: Add more data fields for sensitivity checking

In reply to Ye Xiang

Before, when reading/writing the hysteresis of als, incli-3d, press, and rotation sensor, we will get invalid argument error.

This patch add more sensitivity data fields for these sensors, so that these sensors can get sensitivity index and return correct hysteresis value.

---
 drivers/iio/light/hid-sensor-als.c            | 1 +
 drivers/iio/orientation/hid-sensor-incl-3d.c  | 1 +
 drivers/iio/orientation/hid-sensor-rotation.c | 1 +
 drivers/iio/pressure/hid-sensor-press.c       | 1 +
 4 files changed, 4 insertions(+)
drivers/iio/light/hid-sensor-als.c +1 -0
index 8bf6e9e0a0e0..afcdb424bfb8 100644
@@ -41,6 +41,7 @@ struct als_state {
 
 static const u32 als_sensitivity_addresses[] = {
 	HID_USAGE_SENSOR_DATA_LIGHT,
+	HID_USAGE_SENSOR_LIGHT_ILLUM,
 };
 
 /* Channel definitions */
drivers/iio/orientation/hid-sensor-incl-3d.c +1 -0
index 6e69f6e673cc..7af48d336285 100644
@@ -49,6 +49,7 @@ static const u32 incl_3d_addresses[INCLI_3D_CHANNEL_MAX] = {
 
 static const u32 incl_3d_sensitivity_addresses[] = {
 	HID_USAGE_SENSOR_DATA_ORIENTATION,
+	HID_USAGE_SENSOR_ORIENT_TILT,
 };
 
 /* Channel definitions */
drivers/iio/orientation/hid-sensor-rotation.c +1 -0
index 03d2845a7b2c..b0245b3b7ffc 100644
@@ -33,6 +33,7 @@ struct dev_rot_state {
 
 static const u32 rotation_sensitivity_addresses[] = {
 	HID_USAGE_SENSOR_DATA_ORIENTATION,
+	HID_USAGE_SENSOR_ORIENT_QUATERNION,
 };
 
 /* Channel definitions */
drivers/iio/pressure/hid-sensor-press.c +1 -0
index 8cac2c94e75a..c416d261e3e3 100644
@@ -31,6 +31,7 @@ struct press_state {
 
 static const u32 press_sensitivity_addresses[] = {
 	HID_USAGE_SENSOR_DATA_ATMOSPHERIC_PRESSURE,
+	HID_USAGE_SENSOR_ATMOSPHERIC_PRESSURE
 };
 
 /* Channel definitions */
Signature · 1 line
2.17.1