All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/16] iio: hid-sensors: Convert units and exponent
@ 2014-04-18 23:22 Srinivas Pandruvada
  2014-04-18 23:22 ` [PATCH 02/16] iio: hid-sensors: Add api to get poll value Srinivas Pandruvada
                   ` (16 more replies)
  0 siblings, 17 replies; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-18 23:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

HID sensor hub specify a default unit and alternative units. This
along with unit exponent can be used adjust scale. This change
change HID sensor data units to IIO defined units for each
sensor type. So in this way user space can use a simply use:
"(data + offset) * scale" to get final result.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 .../iio/common/hid-sensors/hid-sensor-attributes.c | 114 +++++++++++++++++++++
 include/linux/hid-sensor-hub.h                     |   4 +
 2 files changed, 118 insertions(+)

diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 75b5473..451a95b 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -26,6 +26,40 @@
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
 
+struct {
+	u32 usage_id;
+	int unit; /* 0 for default others from HID sensor spec */
+	int scale_val0; /* scale, whole number */
+	int scale_val1; /* scale, fraction in micros */
+} unit_conversion[] = {
+	{HID_USAGE_SENSOR_ACCEL_3D, 0, 9, 806650},
+	{HID_USAGE_SENSOR_ACCEL_3D,
+		HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD, 1, 0},
+	{HID_USAGE_SENSOR_ACCEL_3D,
+		HID_USAGE_SENSOR_UNITS_G, 9, 806650},
+
+	{HID_USAGE_SENSOR_GYRO_3D, 0, 0, 17453},
+	{HID_USAGE_SENSOR_GYRO_3D,
+		HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND, 1, 0},
+	{HID_USAGE_SENSOR_GYRO_3D,
+		HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND, 0, 17453},
+
+	{HID_USAGE_SENSOR_COMPASS_3D, 0, 1000, 0},
+	{HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},
+
+	{HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 17453, 0},
+	{HID_USAGE_SENSOR_INCLINOMETER_3D,
+		HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453},
+	{HID_USAGE_SENSOR_INCLINOMETER_3D,
+		HID_USAGE_SENSOR_UNITS_RADIANS, 1, 0},
+
+	{HID_USAGE_SENSOR_ALS, 0, 1, 0},
+	{HID_USAGE_SENSOR_ALS, HID_USAGE_SENSOR_UNITS_LUX, 1, 0},
+
+	{HID_USAGE_SENSOR_PRESSURE, 0, 100000, 0},
+	{HID_USAGE_SENSOR_PRESSURE, HID_USAGE_SENSOR_UNITS_PASCAL, 1, 0},
+};
+
 static int pow_10(unsigned power)
 {
 	int i;
@@ -209,6 +243,86 @@ int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
 }
 EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
 
+/*
+ * This fuction applies the unit exponent to the scale.
+ * For example:
+ * 9.806650 ->exp:2-> val0[980]val1[6650]
+ * 9.000806 ->exp:2-> val0[900]val1[806]
+ * 0.174535 ->exp:2-> val0[17]val1[4535]
+ * 1.001745 ->exp:0-> val0[1]val1[1745]
+ * 1.001745 ->exp:2-> val0[100]val1[1745]
+ * 1.001745 ->exp:4-> val0[10017]val1[45]
+ * 9.806650 ->exp:-2-> val0[0]val1[98066]
+ */
+static void adjust_exponent_micro(int *val0, int *val1, int scale0,
+				  int scale1, int exp)
+{
+	int i;
+	int x;
+	int res;
+	int rem;
+
+	if (exp > 0) {
+		*val0 = scale0 * pow_10(exp);
+		res = 0;
+		if (exp > 6) {
+			*val1 = 0;
+			return;
+		}
+		for (i = 0; i < exp; ++i) {
+			x = scale1 / pow_10(5 - i);
+			res += (pow_10(exp - 1 - i) * x);
+			scale1 = scale1 % pow_10(5 - i);
+		}
+		*val0 += res;
+			*val1 = scale1 * pow_10(exp);
+	} else if (exp < 0) {
+		exp = abs(exp);
+		if (exp > 6) {
+			*val0 = *val1 = 0;
+			return;
+		}
+		*val0 = scale0 / pow_10(exp);
+		rem = scale0 % pow_10(exp);
+		res = 0;
+		for (i = 0; i < (6 - exp); ++i) {
+			x = scale1 / pow_10(5 - i);
+			res += (pow_10(5 - exp - i) * x);
+			scale1 = scale1 % pow_10(5 - i);
+		}
+		*val1 = rem * pow_10(6 - exp) + res;
+	} else {
+		*val0 = scale0;
+		*val1 = scale1;
+	}
+}
+
+int hid_sensor_format_scale(u32 usage_id,
+			struct hid_sensor_hub_attribute_info *attr_info,
+			int *val0, int *val1)
+{
+	int i;
+	int exp;
+
+	*val0 = 1;
+	*val1 = 0;
+
+	for (i = 0; ARRAY_SIZE(unit_conversion); ++i) {
+		if (unit_conversion[i].usage_id == usage_id &&
+			unit_conversion[i].unit == attr_info->units) {
+			exp  = hid_sensor_convert_exponent(
+						attr_info->unit_expo);
+			adjust_exponent_micro(val0, val1,
+					unit_conversion[i].scale_val0,
+					unit_conversion[i].scale_val1, exp);
+			break;
+		}
+	}
+
+	return IIO_VAL_INT_PLUS_MICRO;
+}
+EXPORT_SYMBOL(hid_sensor_format_scale);
+
 int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 					u32 usage_id,
 					struct hid_sensor_common *st)
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
index b70cfd7..89626b2 100644
--- a/include/linux/hid-sensor-hub.h
+++ b/include/linux/hid-sensor-hub.h
@@ -223,4 +223,8 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
 int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
 				u32 report_id, int field_index, u32 usage_id);
 
+int hid_sensor_format_scale(u32 usage_id,
+			    struct hid_sensor_hub_attribute_info *attr_info,
+			    int *val0, int *val1);
+
 #endif
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 02/16] iio: hid-sensors: Add api to get poll value
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
@ 2014-04-18 23:22 ` Srinivas Pandruvada
  2014-05-03 19:34   ` Jonathan Cameron
  2014-04-18 23:22 ` [PATCH 03/16] iio: hid-sensors: Accelerometer 3D: adjust scale and offset Srinivas Pandruvada
                   ` (15 subsequent siblings)
  16 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-18 23:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Added interface to get poll value in milli-seconds. This value is
changed by changing sampling frequency. This API allows clients
to wait for atleast some poll milli seconds before reading a new sample.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 .../iio/common/hid-sensors/hid-sensor-attributes.c   | 20 ++++++++++++++++++++
 include/linux/hid-sensor-hub.h                       |  2 ++
 2 files changed, 22 insertions(+)

diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 451a95b..4a533b8 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -147,6 +147,26 @@ static u32 convert_to_vtf_format(int size, int exp, int val1, int val2)
 	return value;
 }
 
+s32 hid_sensor_read_poll_value(struct hid_sensor_common *st)
+{
+	s32 value = 0;
+	int ret;
+
+	ret = sensor_hub_get_feature(st->hsdev,
+		st->poll.report_id,
+		st->poll.index, &value);
+
+	if (ret < 0 || value < 0) {
+		return -EINVAL;
+	} else {
+		if (st->poll.units == HID_USAGE_SENSOR_UNITS_SECOND)
+			value = value * 1000;
+	}
+
+	return value;
+}
+EXPORT_SYMBOL(hid_sensor_read_poll_value);
+
 int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
 				int *val1, int *val2)
 {
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
index 89626b2..88d8d63 100644
--- a/include/linux/hid-sensor-hub.h
+++ b/include/linux/hid-sensor-hub.h
@@ -227,4 +227,6 @@ int hid_sensor_format_scale(u32 usage_id,
 			    struct hid_sensor_hub_attribute_info *attr_info,
 			    int *val0, int *val1);
 
+s32 hid_sensor_read_poll_value(struct hid_sensor_common *st);
+
 #endif
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 03/16] iio: hid-sensors: Accelerometer 3D: adjust scale and offset
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
  2014-04-18 23:22 ` [PATCH 02/16] iio: hid-sensors: Add api to get poll value Srinivas Pandruvada
@ 2014-04-18 23:22 ` Srinivas Pandruvada
  2014-05-03 19:35   ` Jonathan Cameron
  2014-04-18 23:22 ` [PATCH 04/16] iio: hid-sensors: Gyro 3D : " Srinivas Pandruvada
                   ` (14 subsequent siblings)
  16 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-18 23:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Using units and unit exponent to calculate scale which is compliant
to IIO ABI.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/accel/hid-sensor-accel-3d.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index 3dcdbad..ca50a91 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -42,6 +42,10 @@ struct accel_3d_state {
 	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX];
 	u32 accel_val[ACCEL_3D_CHANNEL_MAX];
+	int scale_pre_decml;
+	int scale_post_decml;
+	int scale_precision;
+	int value_offset;
 };
 
 static const u32 accel_3d_addresses[ACCEL_3D_CHANNEL_MAX] = {
@@ -123,12 +127,12 @@ static int accel_3d_read_raw(struct iio_dev *indio_dev,
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SCALE:
-		*val = accel_state->accel[CHANNEL_SCAN_INDEX_X].units;
-		ret_type = IIO_VAL_INT;
+		*val = accel_state->scale_pre_decml;
+		*val2 = accel_state->scale_post_decml;
+		ret_type = accel_state->scale_precision;
 		break;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = hid_sensor_convert_exponent(
-			accel_state->accel[CHANNEL_SCAN_INDEX_X].unit_expo);
+		*val = accel_state->value_offset;
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SAMP_FREQ:
@@ -262,6 +266,11 @@ static int accel_3d_parse_report(struct platform_device *pdev,
 			st->accel[1].index, st->accel[1].report_id,
 			st->accel[2].index, st->accel[2].report_id);
 
+	st->scale_precision = hid_sensor_format_scale(
+				HID_USAGE_SENSOR_ACCEL_3D,
+				&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,
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 04/16] iio: hid-sensors: Gyro 3D : adjust scale and offset
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
  2014-04-18 23:22 ` [PATCH 02/16] iio: hid-sensors: Add api to get poll value Srinivas Pandruvada
  2014-04-18 23:22 ` [PATCH 03/16] iio: hid-sensors: Accelerometer 3D: adjust scale and offset Srinivas Pandruvada
@ 2014-04-18 23:22 ` Srinivas Pandruvada
  2014-05-03 19:35   ` Jonathan Cameron
  2014-04-18 23:22 ` [PATCH 05/16] iio: hid-sensors: ALS: " Srinivas Pandruvada
                   ` (13 subsequent siblings)
  16 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-18 23:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Using units and unit exponent to calculate scale which is compliant
to IIO ABI.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/gyro/hid-sensor-gyro-3d.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
index 59d6bc3..53ac060 100644
--- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
+++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
@@ -42,6 +42,10 @@ struct gyro_3d_state {
 	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info gyro[GYRO_3D_CHANNEL_MAX];
 	u32 gyro_val[GYRO_3D_CHANNEL_MAX];
+	int scale_pre_decml;
+	int scale_post_decml;
+	int scale_precision;
+	int value_offset;
 };
 
 static const u32 gyro_3d_addresses[GYRO_3D_CHANNEL_MAX] = {
@@ -123,12 +127,12 @@ static int gyro_3d_read_raw(struct iio_dev *indio_dev,
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SCALE:
-		*val = gyro_state->gyro[CHANNEL_SCAN_INDEX_X].units;
-		ret_type = IIO_VAL_INT;
+		*val = gyro_state->scale_pre_decml;
+		*val2 = gyro_state->scale_post_decml;
+		ret_type = gyro_state->scale_precision;
 		break;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = hid_sensor_convert_exponent(
-			gyro_state->gyro[CHANNEL_SCAN_INDEX_X].unit_expo);
+		*val = gyro_state->value_offset;
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SAMP_FREQ:
@@ -262,6 +266,11 @@ static int gyro_3d_parse_report(struct platform_device *pdev,
 			st->gyro[1].index, st->gyro[1].report_id,
 			st->gyro[2].index, st->gyro[2].report_id);
 
+	st->scale_precision = hid_sensor_format_scale(
+				HID_USAGE_SENSOR_GYRO_3D,
+				&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,
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 05/16] iio: hid-sensors: ALS: adjust scale and offset
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
                   ` (2 preceding siblings ...)
  2014-04-18 23:22 ` [PATCH 04/16] iio: hid-sensors: Gyro 3D : " Srinivas Pandruvada
@ 2014-04-18 23:22 ` Srinivas Pandruvada
  2014-05-03 19:36   ` Jonathan Cameron
  2014-04-18 23:22 ` [PATCH 06/16] iio: hid-sensors: Compass 3D: " Srinivas Pandruvada
                   ` (12 subsequent siblings)
  16 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-18 23:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Using units and unit exponent to calculate scale which is compliant
to IIO ABI.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/light/hid-sensor-als.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index 621541f..39b50be 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -37,6 +37,10 @@ struct als_state {
 	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info als_illum;
 	u32 illum;
+	int scale_pre_decml;
+	int scale_post_decml;
+	int scale_precision;
+	int value_offset;
 };
 
 /* Channel definitions */
@@ -102,12 +106,12 @@ static int als_read_raw(struct iio_dev *indio_dev,
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SCALE:
-		*val = als_state->als_illum.units;
-		ret_type = IIO_VAL_INT;
+		*val = als_state->scale_pre_decml;
+		*val2 = als_state->scale_post_decml;
+		ret_type = als_state->scale_precision;
 		break;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = hid_sensor_convert_exponent(
-				als_state->als_illum.unit_expo);
+		*val = als_state->value_offset;
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SAMP_FREQ:
@@ -229,6 +233,11 @@ static int als_parse_report(struct platform_device *pdev,
 	dev_dbg(&pdev->dev, "als %x:%x\n", st->als_illum.index,
 			st->als_illum.report_id);
 
+	st->scale_precision = hid_sensor_format_scale(
+				HID_USAGE_SENSOR_ALS,
+				&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,
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 06/16] iio: hid-sensors: Compass 3D: adjust scale and offset
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
                   ` (3 preceding siblings ...)
  2014-04-18 23:22 ` [PATCH 05/16] iio: hid-sensors: ALS: " Srinivas Pandruvada
@ 2014-04-18 23:22 ` Srinivas Pandruvada
  2014-05-03 19:36   ` Jonathan Cameron
  2014-04-18 23:22 ` [PATCH 07/16] iio: hid-sensors: Inclinometer " Srinivas Pandruvada
                   ` (11 subsequent siblings)
  16 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-18 23:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Using units and unit exponent to calculate scale which is compliant
to IIO ABI.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/magnetometer/hid-sensor-magn-3d.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
index 6d162b7..131ced0 100644
--- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
+++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
@@ -42,6 +42,10 @@ struct magn_3d_state {
 	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX];
 	u32 magn_val[MAGN_3D_CHANNEL_MAX];
+	int scale_pre_decml;
+	int scale_post_decml;
+	int scale_precision;
+	int value_offset;
 };
 
 static const u32 magn_3d_addresses[MAGN_3D_CHANNEL_MAX] = {
@@ -124,12 +128,12 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev,
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SCALE:
-		*val = magn_state->magn[CHANNEL_SCAN_INDEX_X].units;
-		ret_type = IIO_VAL_INT;
+		*val = magn_state->scale_pre_decml;
+		*val2 = magn_state->scale_post_decml;
+		ret_type = magn_state->scale_precision;
 		break;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = hid_sensor_convert_exponent(
-			magn_state->magn[CHANNEL_SCAN_INDEX_X].unit_expo);
+		*val = magn_state->value_offset;
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SAMP_FREQ:
@@ -263,6 +267,11 @@ static int magn_3d_parse_report(struct platform_device *pdev,
 			st->magn[1].index, st->magn[1].report_id,
 			st->magn[2].index, st->magn[2].report_id);
 
+	st->scale_precision = hid_sensor_format_scale(
+				HID_USAGE_SENSOR_COMPASS_3D,
+				&st->magn[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,
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 07/16] iio: hid-sensors: Inclinometer 3D: adjust scale and offset
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
                   ` (4 preceding siblings ...)
  2014-04-18 23:22 ` [PATCH 06/16] iio: hid-sensors: Compass 3D: " Srinivas Pandruvada
@ 2014-04-18 23:22 ` Srinivas Pandruvada
  2014-05-03 19:37   ` Jonathan Cameron
  2014-04-18 23:22 ` [PATCH 08/16] iio: hid-sensors: Pressure: " Srinivas Pandruvada
                   ` (10 subsequent siblings)
  16 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-18 23:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Using units and unit exponent to calculate scale which is compliant
to IIO ABI.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/orientation/hid-sensor-incl-3d.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/orientation/hid-sensor-incl-3d.c b/drivers/iio/orientation/hid-sensor-incl-3d.c
index 070feab..f0c465c 100644
--- a/drivers/iio/orientation/hid-sensor-incl-3d.c
+++ b/drivers/iio/orientation/hid-sensor-incl-3d.c
@@ -42,6 +42,10 @@ struct incl_3d_state {
 	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info incl[INCLI_3D_CHANNEL_MAX];
 	u32 incl_val[INCLI_3D_CHANNEL_MAX];
+	int scale_pre_decml;
+	int scale_post_decml;
+	int scale_precision;
+	int value_offset;
 };
 
 static const u32 incl_3d_addresses[INCLI_3D_CHANNEL_MAX] = {
@@ -125,12 +129,12 @@ static int incl_3d_read_raw(struct iio_dev *indio_dev,
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SCALE:
-		*val = incl_state->incl[CHANNEL_SCAN_INDEX_X].units;
-		ret_type = IIO_VAL_INT;
+		*val = incl_state->scale_pre_decml;
+		*val2 = incl_state->scale_post_decml;
+		ret_type = incl_state->scale_precision;
 		break;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = hid_sensor_convert_exponent(
-			incl_state->incl[CHANNEL_SCAN_INDEX_X].unit_expo);
+		*val = incl_state->value_offset;
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SAMP_FREQ:
@@ -279,6 +283,11 @@ static int incl_3d_parse_report(struct platform_device *pdev,
 			st->incl[1].index, st->incl[1].report_id,
 			st->incl[2].index, st->incl[2].report_id);
 
+	st->scale_precision = hid_sensor_format_scale(
+				HID_USAGE_SENSOR_INCLINOMETER_3D,
+				&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,
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 08/16] iio: hid-sensors: Pressure:  adjust scale and offset
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
                   ` (5 preceding siblings ...)
  2014-04-18 23:22 ` [PATCH 07/16] iio: hid-sensors: Inclinometer " Srinivas Pandruvada
@ 2014-04-18 23:22 ` Srinivas Pandruvada
  2014-05-03 19:37   ` Jonathan Cameron
  2014-04-18 23:22 ` [PATCH 09/16] iio: hid-sensors: Add API to power on/off Srinivas Pandruvada
                   ` (9 subsequent siblings)
  16 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-18 23:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Using units and unit exponent to calculate scale which is compliant
to IIO ABI.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/pressure/hid-sensor-press.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/pressure/hid-sensor-press.c b/drivers/iio/pressure/hid-sensor-press.c
index e0e6409..ff69da4 100644
--- a/drivers/iio/pressure/hid-sensor-press.c
+++ b/drivers/iio/pressure/hid-sensor-press.c
@@ -36,6 +36,10 @@ struct press_state {
 	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info press_attr;
 	u32 press_data;
+	int scale_pre_decml;
+	int scale_post_decml;
+	int scale_precision;
+	int value_offset;
 };
 
 /* Channel definitions */
@@ -102,12 +106,12 @@ static int press_read_raw(struct iio_dev *indio_dev,
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SCALE:
-		*val = press_state->press_attr.units;
-		ret_type = IIO_VAL_INT;
+		*val = press_state->scale_pre_decml;
+		*val2 = press_state->scale_post_decml;
+		ret_type = press_state->scale_precision;
 		break;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = hid_sensor_convert_exponent(
-				press_state->press_attr.unit_expo);
+		*val = press_state->value_offset;
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SAMP_FREQ:
@@ -229,6 +233,11 @@ static int press_parse_report(struct platform_device *pdev,
 	dev_dbg(&pdev->dev, "press %x:%x\n", st->press_attr.index,
 			st->press_attr.report_id);
 
+	st->scale_precision = hid_sensor_format_scale(
+				HID_USAGE_SENSOR_PRESSURE,
+				&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,
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 09/16] iio: hid-sensors: Add API to power on/off
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
                   ` (6 preceding siblings ...)
  2014-04-18 23:22 ` [PATCH 08/16] iio: hid-sensors: Pressure: " Srinivas Pandruvada
@ 2014-04-18 23:22 ` Srinivas Pandruvada
  2014-05-03 19:38   ` Jonathan Cameron
  2014-04-18 23:22 ` [PATCH 10/16] iio: hid-sensors: Accelerometer 3D: Raw read support Srinivas Pandruvada
                   ` (8 subsequent siblings)
  16 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-18 23:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Added an API to allow client drivers to turn ON and OFF sensors for
quick read. Added data_read as counting varaible instead of boolean,
so that sensor is powered off only when last user released it.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/accel/hid-sensor-accel-3d.c             |  7 +++----
 drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 17 +++++++++++++----
 drivers/iio/common/hid-sensors/hid-sensor-trigger.h |  1 +
 drivers/iio/gyro/hid-sensor-gyro-3d.c               |  7 +++----
 drivers/iio/light/hid-sensor-als.c                  |  7 +++----
 drivers/iio/light/hid-sensor-prox.c                 |  7 +++----
 drivers/iio/magnetometer/hid-sensor-magn-3d.c       |  7 +++----
 drivers/iio/orientation/hid-sensor-incl-3d.c        |  7 +++----
 drivers/iio/orientation/hid-sensor-rotation.c       |  8 +++-----
 drivers/iio/pressure/hid-sensor-press.c             |  7 +++----
 include/linux/hid-sensor-hub.h                      |  2 +-
 11 files changed, 39 insertions(+), 38 deletions(-)

diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index ca50a91..cf61c87 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -201,9 +201,8 @@ static int accel_3d_proc_event(struct hid_sensor_hub_device *hsdev,
 	struct iio_dev *indio_dev = platform_get_drvdata(priv);
 	struct accel_3d_state *accel_state = iio_priv(indio_dev);
 
-	dev_dbg(&indio_dev->dev, "accel_3d_proc_event [%d]\n",
-				accel_state->common_attributes.data_ready);
-	if (accel_state->common_attributes.data_ready)
+	dev_dbg(&indio_dev->dev, "accel_3d_proc_event\n");
+	if (atomic_read(&accel_state->common_attributes.data_ready))
 		hid_sensor_push_data(indio_dev,
 				accel_state->accel_val,
 				sizeof(accel_state->accel_val));
@@ -342,7 +341,7 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
 		goto error_free_dev_mem;
 	}
-	accel_state->common_attributes.data_ready = false;
+	atomic_set(&accel_state->common_attributes.data_ready, 0);
 	ret = hid_sensor_setup_trigger(indio_dev, name,
 					&accel_state->common_attributes);
 	if (ret < 0) {
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index dbefbda..73282ce 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -28,16 +28,17 @@
 #include <linux/iio/sysfs.h>
 #include "hid-sensor-trigger.h"
 
-static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
-						bool state)
+int hid_sensor_power_state(struct hid_sensor_common *st, bool state)
 {
-	struct hid_sensor_common *st = iio_trigger_get_drvdata(trig);
 	int state_val;
 	int report_val;
 
 	if (state) {
 		if (sensor_hub_device_open(st->hsdev))
 			return -EIO;
+
+		atomic_inc(&st->data_ready);
+
 		state_val = hid_sensor_get_usage_index(st->hsdev,
 			st->power_state.report_id,
 			st->power_state.index,
@@ -47,6 +48,8 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
 			st->report_state.index,
 			HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM);
 	} else {
+		if (!atomic_dec_and_test(&st->data_ready))
+			return 0;
 		sensor_hub_device_close(st->hsdev);
 		state_val = hid_sensor_get_usage_index(st->hsdev,
 			st->power_state.report_id,
@@ -57,7 +60,6 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
 			st->report_state.index,
 			HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM);
 	}
-	st->data_ready = state;
 
 	if (state_val >= 0) {
 		state_val += st->power_state.logical_minimum;
@@ -75,6 +77,13 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
 
 	return 0;
 }
+EXPORT_SYMBOL(hid_sensor_power_state);
+
+static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
+						bool state)
+{
+	return hid_sensor_power_state(iio_trigger_get_drvdata(trig), state);
+}
 
 void hid_sensor_remove_trigger(struct hid_sensor_common *attrb)
 {
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
index ca02f78..0f8e78c 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
@@ -22,5 +22,6 @@
 int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
 				struct hid_sensor_common *attrb);
 void hid_sensor_remove_trigger(struct hid_sensor_common *attrb);
+int hid_sensor_power_state(struct hid_sensor_common *st, bool state);
 
 #endif
diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
index 53ac060..392c30b 100644
--- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
+++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
@@ -201,9 +201,8 @@ static int gyro_3d_proc_event(struct hid_sensor_hub_device *hsdev,
 	struct iio_dev *indio_dev = platform_get_drvdata(priv);
 	struct gyro_3d_state *gyro_state = iio_priv(indio_dev);
 
-	dev_dbg(&indio_dev->dev, "gyro_3d_proc_event [%d]\n",
-				gyro_state->common_attributes.data_ready);
-	if (gyro_state->common_attributes.data_ready)
+	dev_dbg(&indio_dev->dev, "gyro_3d_proc_event\n");
+	if (atomic_read(&gyro_state->common_attributes.data_ready))
 		hid_sensor_push_data(indio_dev,
 				gyro_state->gyro_val,
 				sizeof(gyro_state->gyro_val));
@@ -339,7 +338,7 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
 		goto error_free_dev_mem;
 	}
-	gyro_state->common_attributes.data_ready = false;
+	atomic_set(&gyro_state->common_attributes.data_ready, 0);
 	ret = hid_sensor_setup_trigger(indio_dev, name,
 					&gyro_state->common_attributes);
 	if (ret < 0) {
diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index 39b50be..e124b39 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -180,9 +180,8 @@ static int als_proc_event(struct hid_sensor_hub_device *hsdev,
 	struct iio_dev *indio_dev = platform_get_drvdata(priv);
 	struct als_state *als_state = iio_priv(indio_dev);
 
-	dev_dbg(&indio_dev->dev, "als_proc_event [%d]\n",
-				als_state->common_attributes.data_ready);
-	if (als_state->common_attributes.data_ready)
+	dev_dbg(&indio_dev->dev, "als_proc_event\n");
+	if (atomic_read(&als_state->common_attributes.data_ready))
 		hid_sensor_push_data(indio_dev,
 				&als_state->illum,
 				sizeof(als_state->illum));
@@ -305,7 +304,7 @@ static int hid_als_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
 		goto error_free_dev_mem;
 	}
-	als_state->common_attributes.data_ready = false;
+	atomic_set(&als_state->common_attributes.data_ready, 0);
 	ret = hid_sensor_setup_trigger(indio_dev, name,
 				&als_state->common_attributes);
 	if (ret < 0) {
diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c
index 1894ab1..07e98ec8 100644
--- a/drivers/iio/light/hid-sensor-prox.c
+++ b/drivers/iio/light/hid-sensor-prox.c
@@ -176,9 +176,8 @@ static int prox_proc_event(struct hid_sensor_hub_device *hsdev,
 	struct iio_dev *indio_dev = platform_get_drvdata(priv);
 	struct prox_state *prox_state = iio_priv(indio_dev);
 
-	dev_dbg(&indio_dev->dev, "prox_proc_event [%d]\n",
-				prox_state->common_attributes.data_ready);
-	if (prox_state->common_attributes.data_ready)
+	dev_dbg(&indio_dev->dev, "prox_proc_event\n");
+	if (atomic_read(&prox_state->common_attributes.data_ready))
 		hid_sensor_push_data(indio_dev,
 				&prox_state->human_presence,
 				sizeof(prox_state->human_presence));
@@ -297,7 +296,7 @@ static int hid_prox_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
 		goto error_free_dev_mem;
 	}
-	prox_state->common_attributes.data_ready = false;
+	atomic_set(&prox_state->common_attributes.data_ready, 0);
 	ret = hid_sensor_setup_trigger(indio_dev, name,
 				&prox_state->common_attributes);
 	if (ret) {
diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
index 131ced0..54eea6a 100644
--- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
+++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
@@ -202,9 +202,8 @@ static int magn_3d_proc_event(struct hid_sensor_hub_device *hsdev,
 	struct iio_dev *indio_dev = platform_get_drvdata(priv);
 	struct magn_3d_state *magn_state = iio_priv(indio_dev);
 
-	dev_dbg(&indio_dev->dev, "magn_3d_proc_event [%d]\n",
-				magn_state->common_attributes.data_ready);
-	if (magn_state->common_attributes.data_ready)
+	dev_dbg(&indio_dev->dev, "magn_3d_proc_event\n");
+	if (atomic_read(&magn_state->common_attributes.data_ready))
 		hid_sensor_push_data(indio_dev,
 				magn_state->magn_val,
 				sizeof(magn_state->magn_val));
@@ -343,7 +342,7 @@ static int hid_magn_3d_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
 		goto error_free_dev_mem;
 	}
-	magn_state->common_attributes.data_ready = false;
+	atomic_set(&magn_state->common_attributes.data_ready, 0);
 	ret = hid_sensor_setup_trigger(indio_dev, name,
 					&magn_state->common_attributes);
 	if (ret < 0) {
diff --git a/drivers/iio/orientation/hid-sensor-incl-3d.c b/drivers/iio/orientation/hid-sensor-incl-3d.c
index f0c465c..bf11678 100644
--- a/drivers/iio/orientation/hid-sensor-incl-3d.c
+++ b/drivers/iio/orientation/hid-sensor-incl-3d.c
@@ -200,9 +200,8 @@ static int incl_3d_proc_event(struct hid_sensor_hub_device *hsdev,
 	struct iio_dev *indio_dev = platform_get_drvdata(priv);
 	struct incl_3d_state *incl_state = iio_priv(indio_dev);
 
-	dev_dbg(&indio_dev->dev, "incl_3d_proc_event [%d]\n",
-				incl_state->common_attributes.data_ready);
-	if (incl_state->common_attributes.data_ready)
+	dev_dbg(&indio_dev->dev, "incl_3d_proc_event\n");
+	if (atomic_read(&incl_state->common_attributes.data_ready))
 		hid_sensor_push_data(indio_dev,
 				(u8 *)incl_state->incl_val,
 				sizeof(incl_state->incl_val));
@@ -358,7 +357,7 @@ static int hid_incl_3d_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
 		goto error_free_dev_mem;
 	}
-	incl_state->common_attributes.data_ready = false;
+	atomic_set(&incl_state->common_attributes.data_ready, 0);
 	ret = hid_sensor_setup_trigger(indio_dev, name,
 					&incl_state->common_attributes);
 	if (ret) {
diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c
index 51387bb..dccf848 100644
--- a/drivers/iio/orientation/hid-sensor-rotation.c
+++ b/drivers/iio/orientation/hid-sensor-rotation.c
@@ -145,10 +145,8 @@ static int dev_rot_proc_event(struct hid_sensor_hub_device *hsdev,
 	struct iio_dev *indio_dev = platform_get_drvdata(priv);
 	struct dev_rot_state *rot_state = iio_priv(indio_dev);
 
-	dev_dbg(&indio_dev->dev, "dev_rot_proc_event [%d]\n",
-				rot_state->common_attributes.data_ready);
-
-	if (rot_state->common_attributes.data_ready)
+	dev_dbg(&indio_dev->dev, "dev_rot_proc_event\n");
+	if (atomic_read(&rot_state->common_attributes.data_ready))
 		hid_sensor_push_data(indio_dev,
 				(u8 *)rot_state->sampled_vals,
 				sizeof(rot_state->sampled_vals));
@@ -272,7 +270,7 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
 		return ret;
 	}
-	rot_state->common_attributes.data_ready = false;
+	atomic_set(&rot_state->common_attributes.data_ready, 0);
 	ret = hid_sensor_setup_trigger(indio_dev, name,
 					&rot_state->common_attributes);
 	if (ret) {
diff --git a/drivers/iio/pressure/hid-sensor-press.c b/drivers/iio/pressure/hid-sensor-press.c
index ff69da4..39df50c 100644
--- a/drivers/iio/pressure/hid-sensor-press.c
+++ b/drivers/iio/pressure/hid-sensor-press.c
@@ -180,9 +180,8 @@ static int press_proc_event(struct hid_sensor_hub_device *hsdev,
 	struct iio_dev *indio_dev = platform_get_drvdata(priv);
 	struct press_state *press_state = iio_priv(indio_dev);
 
-	dev_dbg(&indio_dev->dev, "press_proc_event [%d]\n",
-				press_state->common_attributes.data_ready);
-	if (press_state->common_attributes.data_ready)
+	dev_dbg(&indio_dev->dev, "press_proc_event\n");
+	if (atomic_read(&press_state->common_attributes.data_ready))
 		hid_sensor_push_data(indio_dev,
 				&press_state->press_data,
 				sizeof(press_state->press_data));
@@ -307,7 +306,7 @@ static int hid_press_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
 		goto error_free_dev_mem;
 	}
-	press_state->common_attributes.data_ready = false;
+	atomic_set(&press_state->common_attributes.data_ready, 0);
 	ret = hid_sensor_setup_trigger(indio_dev, name,
 				&press_state->common_attributes);
 	if (ret) {
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
index 88d8d63..51f7cca 100644
--- a/include/linux/hid-sensor-hub.h
+++ b/include/linux/hid-sensor-hub.h
@@ -189,7 +189,7 @@ struct hid_sensor_common {
 	struct hid_sensor_hub_device *hsdev;
 	struct platform_device *pdev;
 	unsigned usage_id;
-	bool data_ready;
+	atomic_t data_ready;
 	struct iio_trigger *trigger;
 	struct hid_sensor_hub_attribute_info poll;
 	struct hid_sensor_hub_attribute_info report_state;
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 10/16] iio: hid-sensors: Accelerometer 3D: Raw read support
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
                   ` (7 preceding siblings ...)
  2014-04-18 23:22 ` [PATCH 09/16] iio: hid-sensors: Add API to power on/off Srinivas Pandruvada
@ 2014-04-18 23:22 ` Srinivas Pandruvada
  2014-05-03 19:38   ` Jonathan Cameron
  2014-04-18 23:22 ` [PATCH 11/16] iio: hid-sensors: Gyro " Srinivas Pandruvada
                   ` (7 subsequent siblings)
  16 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-18 23:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Added support for raw reading of channel. If the sensor is powered
off, it will turn on for reading value.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/accel/hid-sensor-accel-3d.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index cf61c87..69abf91 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -22,6 +22,7 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/slab.h>
+#include <linux/delay.h>
 #include <linux/hid-sensor-hub.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
@@ -60,6 +61,7 @@ static const struct iio_chan_spec accel_3d_channels[] = {
 		.type = IIO_ACCEL,
 		.modified = 1,
 		.channel2 = IIO_MOD_X,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
@@ -69,6 +71,7 @@ static const struct iio_chan_spec accel_3d_channels[] = {
 		.type = IIO_ACCEL,
 		.modified = 1,
 		.channel2 = IIO_MOD_Y,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
@@ -78,6 +81,7 @@ static const struct iio_chan_spec accel_3d_channels[] = {
 		.type = IIO_ACCEL,
 		.modified = 1,
 		.channel2 = IIO_MOD_Z,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
@@ -108,22 +112,33 @@ static int accel_3d_read_raw(struct iio_dev *indio_dev,
 	u32 address;
 	int ret;
 	int ret_type;
+	s32 poll_value;
 
 	*val = 0;
 	*val2 = 0;
 	switch (mask) {
 	case 0:
+		poll_value = hid_sensor_read_poll_value(
+					&accel_state->common_attributes);
+		if (poll_value < 0)
+			return -EINVAL;
+
+		hid_sensor_power_state(&accel_state->common_attributes, true);
+		msleep_interruptible(poll_value * 2);
 		report_id = accel_state->accel[chan->scan_index].report_id;
 		address = accel_3d_addresses[chan->scan_index];
 		if (report_id >= 0)
 			*val = sensor_hub_input_attr_get_raw_value(
-				accel_state->common_attributes.hsdev,
-				HID_USAGE_SENSOR_ACCEL_3D, address,
-				report_id);
+					accel_state->common_attributes.hsdev,
+					HID_USAGE_SENSOR_ACCEL_3D, address,
+					report_id);
 		else {
 			*val = 0;
+			hid_sensor_power_state(&accel_state->common_attributes,
+						 false);
 			return -EINVAL;
 		}
+		hid_sensor_power_state(&accel_state->common_attributes, false);
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SCALE:
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 11/16] iio: hid-sensors: Gyro 3D: Raw read support
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
                   ` (8 preceding siblings ...)
  2014-04-18 23:22 ` [PATCH 10/16] iio: hid-sensors: Accelerometer 3D: Raw read support Srinivas Pandruvada
@ 2014-04-18 23:22 ` Srinivas Pandruvada
  2014-05-03 19:39   ` Jonathan Cameron
  2014-04-18 23:22 ` [PATCH 12/16] iio: hid-sensors: ALS: " Srinivas Pandruvada
                   ` (6 subsequent siblings)
  16 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-18 23:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Added support for raw reading of channel. If the sensor is powered
off, it will turn on for reading value.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/gyro/hid-sensor-gyro-3d.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
index 392c30b..40f4e49 100644
--- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
+++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
@@ -22,6 +22,7 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/slab.h>
+#include <linux/delay.h>
 #include <linux/hid-sensor-hub.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
@@ -60,6 +61,7 @@ static const struct iio_chan_spec gyro_3d_channels[] = {
 		.type = IIO_ANGL_VEL,
 		.modified = 1,
 		.channel2 = IIO_MOD_X,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
@@ -69,6 +71,7 @@ static const struct iio_chan_spec gyro_3d_channels[] = {
 		.type = IIO_ANGL_VEL,
 		.modified = 1,
 		.channel2 = IIO_MOD_Y,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
@@ -78,6 +81,7 @@ static const struct iio_chan_spec gyro_3d_channels[] = {
 		.type = IIO_ANGL_VEL,
 		.modified = 1,
 		.channel2 = IIO_MOD_Z,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
@@ -108,22 +112,33 @@ static int gyro_3d_read_raw(struct iio_dev *indio_dev,
 	u32 address;
 	int ret;
 	int ret_type;
+	s32 poll_value;
 
 	*val = 0;
 	*val2 = 0;
 	switch (mask) {
 	case 0:
+		poll_value = hid_sensor_read_poll_value(
+					&gyro_state->common_attributes);
+		if (poll_value < 0)
+			return -EINVAL;
+
+		hid_sensor_power_state(&gyro_state->common_attributes, true);
+		msleep_interruptible(poll_value * 2);
 		report_id = gyro_state->gyro[chan->scan_index].report_id;
 		address = gyro_3d_addresses[chan->scan_index];
 		if (report_id >= 0)
 			*val = sensor_hub_input_attr_get_raw_value(
-				gyro_state->common_attributes.hsdev,
-				HID_USAGE_SENSOR_GYRO_3D, address,
-				report_id);
+					gyro_state->common_attributes.hsdev,
+					HID_USAGE_SENSOR_GYRO_3D, address,
+					report_id);
 		else {
 			*val = 0;
+			hid_sensor_power_state(&gyro_state->common_attributes,
+						false);
 			return -EINVAL;
 		}
+		hid_sensor_power_state(&gyro_state->common_attributes, false);
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SCALE:
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 12/16] iio: hid-sensors: ALS: Raw read support
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
                   ` (9 preceding siblings ...)
  2014-04-18 23:22 ` [PATCH 11/16] iio: hid-sensors: Gyro " Srinivas Pandruvada
@ 2014-04-18 23:22 ` Srinivas Pandruvada
  2014-05-03 19:39   ` Jonathan Cameron
  2014-04-18 23:22 ` [PATCH 13/16] iio: hid-sensors: Proximity: " Srinivas Pandruvada
                   ` (5 subsequent siblings)
  16 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-18 23:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Added support for raw reading of channel. If the sensor is powered
off, it will turn on for reading value.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/light/hid-sensor-als.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index e124b39..f34c943 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -22,6 +22,7 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/slab.h>
+#include <linux/delay.h>
 #include <linux/hid-sensor-hub.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
@@ -49,6 +50,7 @@ static const struct iio_chan_spec als_channels[] = {
 		.type = IIO_INTENSITY,
 		.modified = 1,
 		.channel2 = IIO_MOD_LIGHT_BOTH,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
@@ -79,6 +81,7 @@ static int als_read_raw(struct iio_dev *indio_dev,
 	u32 address;
 	int ret;
 	int ret_type;
+	s32 poll_value;
 
 	*val = 0;
 	*val2 = 0;
@@ -94,12 +97,23 @@ static int als_read_raw(struct iio_dev *indio_dev,
 			report_id = -1;
 			break;
 		}
-		if (report_id >= 0)
+		if (report_id >= 0) {
+			poll_value = hid_sensor_read_poll_value(
+						&als_state->common_attributes);
+			if (poll_value < 0)
+				return -EINVAL;
+
+			hid_sensor_power_state(&als_state->common_attributes,
+						true);
+			msleep_interruptible(poll_value * 2);
+
 			*val = sensor_hub_input_attr_get_raw_value(
-				als_state->common_attributes.hsdev,
-				HID_USAGE_SENSOR_ALS, address,
-				report_id);
-		else {
+					als_state->common_attributes.hsdev,
+					HID_USAGE_SENSOR_ALS, address,
+					report_id);
+			hid_sensor_power_state(&als_state->common_attributes,
+						false);
+		} else {
 			*val = 0;
 			return -EINVAL;
 		}
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 13/16] iio: hid-sensors: Proximity: Raw read support
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
                   ` (10 preceding siblings ...)
  2014-04-18 23:22 ` [PATCH 12/16] iio: hid-sensors: ALS: " Srinivas Pandruvada
@ 2014-04-18 23:22 ` Srinivas Pandruvada
  2014-05-03 19:40   ` Jonathan Cameron
  2014-04-18 23:22 ` [PATCH 14/16] iio: hid-sensors: Compass 3D: " Srinivas Pandruvada
                   ` (4 subsequent siblings)
  16 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-18 23:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Added support for raw reading of channel. If the sensor is powered
off, it will turn on for reading value.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/light/hid-sensor-prox.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c
index 07e98ec8..d203ef4 100644
--- a/drivers/iio/light/hid-sensor-prox.c
+++ b/drivers/iio/light/hid-sensor-prox.c
@@ -21,6 +21,7 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/slab.h>
+#include <linux/delay.h>
 #include <linux/hid-sensor-hub.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
@@ -75,6 +76,7 @@ static int prox_read_raw(struct iio_dev *indio_dev,
 	u32 address;
 	int ret;
 	int ret_type;
+	s32 poll_value;
 
 	*val = 0;
 	*val2 = 0;
@@ -90,12 +92,24 @@ static int prox_read_raw(struct iio_dev *indio_dev,
 			report_id = -1;
 			break;
 		}
-		if (report_id >= 0)
+		if (report_id >= 0) {
+			poll_value = hid_sensor_read_poll_value(
+					&prox_state->common_attributes);
+			if (poll_value < 0)
+				return -EINVAL;
+
+			hid_sensor_power_state(&prox_state->common_attributes,
+						true);
+
+			msleep_interruptible(poll_value * 2);
+
 			*val = sensor_hub_input_attr_get_raw_value(
 				prox_state->common_attributes.hsdev,
 				HID_USAGE_SENSOR_PROX, address,
 				report_id);
-		else {
+			hid_sensor_power_state(&prox_state->common_attributes,
+						false);
+		} else {
 			*val = 0;
 			return -EINVAL;
 		}
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 14/16] iio: hid-sensors: Compass 3D: Raw read support
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
                   ` (11 preceding siblings ...)
  2014-04-18 23:22 ` [PATCH 13/16] iio: hid-sensors: Proximity: " Srinivas Pandruvada
@ 2014-04-18 23:22 ` Srinivas Pandruvada
  2014-05-03 19:41   ` Jonathan Cameron
  2014-04-18 23:22 ` [PATCH 15/16] iio: hid-sensors: Inclinometer " Srinivas Pandruvada
                   ` (3 subsequent siblings)
  16 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-18 23:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Added support for raw reading of channel. If the sensor is powered
off, it will turn on for reading value

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/magnetometer/hid-sensor-magn-3d.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
index 54eea6a..41cf29e 100644
--- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
+++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
@@ -22,6 +22,7 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/slab.h>
+#include <linux/delay.h>
 #include <linux/hid-sensor-hub.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
@@ -60,6 +61,7 @@ static const struct iio_chan_spec magn_3d_channels[] = {
 		.type = IIO_MAGN,
 		.modified = 1,
 		.channel2 = IIO_MOD_X,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
@@ -69,6 +71,7 @@ static const struct iio_chan_spec magn_3d_channels[] = {
 		.type = IIO_MAGN,
 		.modified = 1,
 		.channel2 = IIO_MOD_Y,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
@@ -78,6 +81,7 @@ static const struct iio_chan_spec magn_3d_channels[] = {
 		.type = IIO_MAGN,
 		.modified = 1,
 		.channel2 = IIO_MOD_Z,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
@@ -108,11 +112,20 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev,
 	u32 address;
 	int ret;
 	int ret_type;
+	s32 poll_value;
 
 	*val = 0;
 	*val2 = 0;
 	switch (mask) {
 	case 0:
+		poll_value = hid_sensor_read_poll_value(
+					&magn_state->common_attributes);
+		if (poll_value < 0)
+				return -EINVAL;
+
+		hid_sensor_power_state(&magn_state->common_attributes, true);
+		msleep_interruptible(poll_value * 2);
+
 		report_id =
 			magn_state->magn[chan->scan_index].report_id;
 		address = magn_3d_addresses[chan->scan_index];
@@ -123,8 +136,11 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev,
 				report_id);
 		else {
 			*val = 0;
+			hid_sensor_power_state(&magn_state->common_attributes,
+						false);
 			return -EINVAL;
 		}
+		hid_sensor_power_state(&magn_state->common_attributes, false);
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SCALE:
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 15/16] iio: hid-sensors: Inclinometer 3D: Raw read support
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
                   ` (12 preceding siblings ...)
  2014-04-18 23:22 ` [PATCH 14/16] iio: hid-sensors: Compass 3D: " Srinivas Pandruvada
@ 2014-04-18 23:22 ` Srinivas Pandruvada
  2014-05-03 19:41   ` Jonathan Cameron
  2014-04-18 23:22 ` [PATCH 16/16] iio: hid-sensors: Pressure: " Srinivas Pandruvada
                   ` (2 subsequent siblings)
  16 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-18 23:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Added support for raw reading of channel. If the sensor is powered
off, it will turn on for reading value.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/orientation/hid-sensor-incl-3d.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/iio/orientation/hid-sensor-incl-3d.c b/drivers/iio/orientation/hid-sensor-incl-3d.c
index bf11678..2478f6c 100644
--- a/drivers/iio/orientation/hid-sensor-incl-3d.c
+++ b/drivers/iio/orientation/hid-sensor-incl-3d.c
@@ -22,6 +22,7 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/slab.h>
+#include <linux/delay.h>
 #include <linux/hid-sensor-hub.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
@@ -110,11 +111,20 @@ static int incl_3d_read_raw(struct iio_dev *indio_dev,
 	int report_id = -1;
 	u32 address;
 	int ret_type;
+	s32 poll_value;
 
 	*val = 0;
 	*val2 = 0;
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
+		poll_value = hid_sensor_read_poll_value(
+					&incl_state->common_attributes);
+		if (poll_value < 0)
+			return -EINVAL;
+
+		hid_sensor_power_state(&incl_state->common_attributes, true);
+		msleep_interruptible(poll_value * 2);
+
 		report_id =
 			incl_state->incl[chan->scan_index].report_id;
 		address = incl_3d_addresses[chan->scan_index];
@@ -124,8 +134,11 @@ static int incl_3d_read_raw(struct iio_dev *indio_dev,
 				HID_USAGE_SENSOR_INCLINOMETER_3D, address,
 				report_id);
 		else {
+			hid_sensor_power_state(&incl_state->common_attributes,
+						false);
 			return -EINVAL;
 		}
+		hid_sensor_power_state(&incl_state->common_attributes, false);
 		ret_type = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SCALE:
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 16/16] iio: hid-sensors: Pressure: Raw read support
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
                   ` (13 preceding siblings ...)
  2014-04-18 23:22 ` [PATCH 15/16] iio: hid-sensors: Inclinometer " Srinivas Pandruvada
@ 2014-04-18 23:22 ` Srinivas Pandruvada
  2014-04-23 21:03   ` Jonathan Cameron
  2014-04-23 20:57 ` [PATCH 01/16] iio: hid-sensors: Convert units and exponent Jonathan Cameron
  2014-04-25 18:30 ` Jonathan Cameron
  16 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-18 23:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Added support for raw reading of channel. If the sensor is powered
off, it will turn on for reading value.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/pressure/hid-sensor-press.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/pressure/hid-sensor-press.c b/drivers/iio/pressure/hid-sensor-press.c
index 39df50c..1cd190c 100644
--- a/drivers/iio/pressure/hid-sensor-press.c
+++ b/drivers/iio/pressure/hid-sensor-press.c
@@ -21,6 +21,7 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/slab.h>
+#include <linux/delay.h>
 #include <linux/hid-sensor-hub.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
@@ -79,6 +80,7 @@ static int press_read_raw(struct iio_dev *indio_dev,
 	u32 address;
 	int ret;
 	int ret_type;
+	s32 poll_value;
 
 	*val = 0;
 	*val2 = 0;
@@ -94,12 +96,23 @@ static int press_read_raw(struct iio_dev *indio_dev,
 			report_id = -1;
 			break;
 		}
-		if (report_id >= 0)
+		if (report_id >= 0) {
+			poll_value = hid_sensor_read_poll_value(
+					&press_state->common_attributes);
+			if (poll_value < 0)
+				return -EINVAL;
+			hid_sensor_power_state(&press_state->common_attributes,
+						true);
+
+			msleep_interruptible(poll_value * 2);
+
 			*val = sensor_hub_input_attr_get_raw_value(
 				press_state->common_attributes.hsdev,
 				HID_USAGE_SENSOR_PRESSURE, address,
 				report_id);
-		else {
+			hid_sensor_power_state(&press_state->common_attributes,
+						false);
+		} else {
 			*val = 0;
 			return -EINVAL;
 		}
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* Re: [PATCH 01/16] iio: hid-sensors: Convert units and exponent
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
                   ` (14 preceding siblings ...)
  2014-04-18 23:22 ` [PATCH 16/16] iio: hid-sensors: Pressure: " Srinivas Pandruvada
@ 2014-04-23 20:57 ` Jonathan Cameron
  2014-04-23 21:17   ` Srinivas Pandruvada
  2014-04-25 18:30 ` Jonathan Cameron
  16 siblings, 1 reply; 41+ messages in thread
From: Jonathan Cameron @ 2014-04-23 20:57 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> HID sensor hub specify a default unit and alternative units. This
> along with unit exponent can be used adjust scale. This change
> change HID sensor data units to IIO defined units for each
> sensor type. So in this way user space can use a simply use:
> "(data + offset) * scale" to get final result.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>

Hi Srinivas,

What 'grief' is this abi change likely to cause us?

I know I effectively asked you to fix this, but I'd like to get
a handle on just how many people are likely to shout.

The original code is a gross breaking of the published ABI so
it probably is reasonable to change it...

I'm too tired to review this properly right now so only the most
superficial comments in line.
> ---
>   .../iio/common/hid-sensors/hid-sensor-attributes.c | 114 +++++++++++++++++++++
>   include/linux/hid-sensor-hub.h                     |   4 +
>   2 files changed, 118 insertions(+)
>
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> index 75b5473..451a95b 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> @@ -26,6 +26,40 @@
>   #include <linux/iio/iio.h>
>   #include <linux/iio/sysfs.h>
>
> +struct {
> +	u32 usage_id;
> +	int unit; /* 0 for default others from HID sensor spec */
> +	int scale_val0; /* scale, whole number */
> +	int scale_val1; /* scale, fraction in micros */
> +} unit_conversion[] = {
> +	{HID_USAGE_SENSOR_ACCEL_3D, 0, 9, 806650},
> +	{HID_USAGE_SENSOR_ACCEL_3D,
> +		HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD, 1, 0},
> +	{HID_USAGE_SENSOR_ACCEL_3D,
> +		HID_USAGE_SENSOR_UNITS_G, 9, 806650},
> +
> +	{HID_USAGE_SENSOR_GYRO_3D, 0, 0, 17453},
> +	{HID_USAGE_SENSOR_GYRO_3D,
> +		HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND, 1, 0},
> +	{HID_USAGE_SENSOR_GYRO_3D,
> +		HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND, 0, 17453},
> +
> +	{HID_USAGE_SENSOR_COMPASS_3D, 0, 1000, 0},
> +	{HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},
> +
> +	{HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 17453, 0},
> +	{HID_USAGE_SENSOR_INCLINOMETER_3D,
> +		HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453},
> +	{HID_USAGE_SENSOR_INCLINOMETER_3D,
> +		HID_USAGE_SENSOR_UNITS_RADIANS, 1, 0},
> +
> +	{HID_USAGE_SENSOR_ALS, 0, 1, 0},
> +	{HID_USAGE_SENSOR_ALS, HID_USAGE_SENSOR_UNITS_LUX, 1, 0},
> +
> +	{HID_USAGE_SENSOR_PRESSURE, 0, 100000, 0},
> +	{HID_USAGE_SENSOR_PRESSURE, HID_USAGE_SENSOR_UNITS_PASCAL, 1, 0},
> +};
> +
>   static int pow_10(unsigned power)
>   {
>   	int i;
> @@ -209,6 +243,86 @@ int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
>   }
>   EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
>
> +/*
> + * This fuction applies the unit exponent to the scale.
function.

Good examples btw.
> + * For example:
> + * 9.806650 ->exp:2-> val0[980]val1[6650]
> + * 9.000806 ->exp:2-> val0[900]val1[806]
> + * 0.174535 ->exp:2-> val0[17]val1[4535]
> + * 1.001745 ->exp:0-> val0[1]val1[1745]
> + * 1.001745 ->exp:2-> val0[100]val1[1745]
> + * 1.001745 ->exp:4-> val0[10017]val1[45]
> + * 9.806650 ->exp:-2-> val0[0]val1[98066]
> + */
> +static void adjust_exponent_micro(int *val0, int *val1, int scale0,
> +				  int scale1, int exp)
> +{
> +	int i;
> +	int x;
> +	int res;
> +	int rem;
> +
> +	if (exp > 0) {
> +		*val0 = scale0 * pow_10(exp);
> +		res = 0;
> +		if (exp > 6) {
> +			*val1 = 0;
> +			return;
> +		}
> +		for (i = 0; i < exp; ++i) {
> +			x = scale1 / pow_10(5 - i);
> +			res += (pow_10(exp - 1 - i) * x);
> +			scale1 = scale1 % pow_10(5 - i);
> +		}
> +		*val0 += res;
> +			*val1 = scale1 * pow_10(exp);
> +	} else if (exp < 0) {
> +		exp = abs(exp);
> +		if (exp > 6) {
> +			*val0 = *val1 = 0;
> +			return;
> +		}
> +		*val0 = scale0 / pow_10(exp);
> +		rem = scale0 % pow_10(exp);
> +		res = 0;
> +		for (i = 0; i < (6 - exp); ++i) {
> +			x = scale1 / pow_10(5 - i);
> +			res += (pow_10(5 - exp - i) * x);
> +			scale1 = scale1 % pow_10(5 - i);
> +		}
> +		*val1 = rem * pow_10(6 - exp) + res;
> +	} else {
> +		*val0 = scale0;
> +		*val1 = scale1;
> +	}
> +}
> +
> +int hid_sensor_format_scale(u32 usage_id,
> +			struct hid_sensor_hub_attribute_info *attr_info,
> +			int *val0, int *val1)
> +{
> +	int i;
> +	int exp;
> +
> +	*val0 = 1;
> +	*val1 = 0;
> +
> +	for (i = 0; ARRAY_SIZE(unit_conversion); ++i) {
> +		if (unit_conversion[i].usage_id == usage_id &&
> +			unit_conversion[i].unit == attr_info->units) {
> +			exp  = hid_sensor_convert_exponent(
> +						attr_info->unit_expo);
> +			adjust_exponent_micro(val0, val1,
> +					unit_conversion[i].scale_val0,
> +					unit_conversion[i].scale_val1, exp);
> +			break;
> +		}
> +	}
> +
> +	return IIO_VAL_INT_PLUS_MICRO;
> +}
> +EXPORT_SYMBOL(hid_sensor_format_scale);
> +
>   int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
>   					u32 usage_id,
>   					struct hid_sensor_common *st)
> diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
> index b70cfd7..89626b2 100644
> --- a/include/linux/hid-sensor-hub.h
> +++ b/include/linux/hid-sensor-hub.h
> @@ -223,4 +223,8 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
>   int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
>   				u32 report_id, int field_index, u32 usage_id);
>
> +int hid_sensor_format_scale(u32 usage_id,
> +			    struct hid_sensor_hub_attribute_info *attr_info,
> +			    int *val0, int *val1);
> +
>   #endif
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 16/16] iio: hid-sensors: Pressure: Raw read support
  2014-04-18 23:22 ` [PATCH 16/16] iio: hid-sensors: Pressure: " Srinivas Pandruvada
@ 2014-04-23 21:03   ` Jonathan Cameron
  2014-05-03 19:45     ` Jonathan Cameron
  0 siblings, 1 reply; 41+ messages in thread
From: Jonathan Cameron @ 2014-04-23 21:03 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> Added support for raw reading of channel. If the sensor is powered
> off, it will turn on for reading value.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Hi Srinivas.

Looks like a good patch set.  Probably should have been 'formally'
broken in two to separate the ABI related fixes and the new stuff.

I'll let this sit for a while to garner opinions on the ABI change.
> ---
>   drivers/iio/pressure/hid-sensor-press.c | 17 +++++++++++++++--
>   1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/pressure/hid-sensor-press.c b/drivers/iio/pressure/hid-sensor-press.c
> index 39df50c..1cd190c 100644
> --- a/drivers/iio/pressure/hid-sensor-press.c
> +++ b/drivers/iio/pressure/hid-sensor-press.c
> @@ -21,6 +21,7 @@
>   #include <linux/interrupt.h>
>   #include <linux/irq.h>
>   #include <linux/slab.h>
> +#include <linux/delay.h>
>   #include <linux/hid-sensor-hub.h>
>   #include <linux/iio/iio.h>
>   #include <linux/iio/sysfs.h>
> @@ -79,6 +80,7 @@ static int press_read_raw(struct iio_dev *indio_dev,
>   	u32 address;
>   	int ret;
>   	int ret_type;
> +	s32 poll_value;
>
>   	*val = 0;
>   	*val2 = 0;
> @@ -94,12 +96,23 @@ static int press_read_raw(struct iio_dev *indio_dev,
>   			report_id = -1;
>   			break;
>   		}
> -		if (report_id >= 0)
> +		if (report_id >= 0) {
> +			poll_value = hid_sensor_read_poll_value(
> +					&press_state->common_attributes);
> +			if (poll_value < 0)
> +				return -EINVAL;
> +			hid_sensor_power_state(&press_state->common_attributes,
> +						true);
> +
> +			msleep_interruptible(poll_value * 2);
> +
>   			*val = sensor_hub_input_attr_get_raw_value(
>   				press_state->common_attributes.hsdev,
>   				HID_USAGE_SENSOR_PRESSURE, address,
>   				report_id);
> -		else {
> +			hid_sensor_power_state(&press_state->common_attributes,
> +						false);
> +		} else {
>   			*val = 0;
>   			return -EINVAL;
>   		}
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 01/16] iio: hid-sensors: Convert units and exponent
  2014-04-23 20:57 ` [PATCH 01/16] iio: hid-sensors: Convert units and exponent Jonathan Cameron
@ 2014-04-23 21:17   ` Srinivas Pandruvada
  2014-04-25 18:34     ` Jonathan Cameron
  0 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-23 21:17 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio


On 04/23/2014 01:57 PM, Jonathan Cameron wrote:
> On 19/04/14 00:22, Srinivas Pandruvada wrote:
>> HID sensor hub specify a default unit and alternative units. This
>> along with unit exponent can be used adjust scale. This change
>> change HID sensor data units to IIO defined units for each
>> sensor type. So in this way user space can use a simply use:
>> "(data + offset) * scale" to get final result.
>>
>> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
>
> Hi Srinivas,
>
> What 'grief' is this abi change likely to cause us?
>
Hi Jonathan,

Since the products are just released with the hubs, I don't think there 
is much impact.
I have notified few users I knew, who pointed me about this disparity.


Thanks,
Srinivas
> I know I effectively asked you to fix this, but I'd like to get
> a handle on just how many people are likely to shout.
>
> The original code is a gross breaking of the published ABI so
> it probably is reasonable to change it...
>
> I'm too tired to review this properly right now so only the most
> superficial comments in line.
>> ---
>>   .../iio/common/hid-sensors/hid-sensor-attributes.c | 114 
>> +++++++++++++++++++++
>>   include/linux/hid-sensor-hub.h                     |   4 +
>>   2 files changed, 118 insertions(+)
>>
>> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c 
>> b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>> index 75b5473..451a95b 100644
>> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>> @@ -26,6 +26,40 @@
>>   #include <linux/iio/iio.h>
>>   #include <linux/iio/sysfs.h>
>>
>> +struct {
>> +    u32 usage_id;
>> +    int unit; /* 0 for default others from HID sensor spec */
>> +    int scale_val0; /* scale, whole number */
>> +    int scale_val1; /* scale, fraction in micros */
>> +} unit_conversion[] = {
>> +    {HID_USAGE_SENSOR_ACCEL_3D, 0, 9, 806650},
>> +    {HID_USAGE_SENSOR_ACCEL_3D,
>> +        HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD, 1, 0},
>> +    {HID_USAGE_SENSOR_ACCEL_3D,
>> +        HID_USAGE_SENSOR_UNITS_G, 9, 806650},
>> +
>> +    {HID_USAGE_SENSOR_GYRO_3D, 0, 0, 17453},
>> +    {HID_USAGE_SENSOR_GYRO_3D,
>> +        HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND, 1, 0},
>> +    {HID_USAGE_SENSOR_GYRO_3D,
>> +        HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND, 0, 17453},
>> +
>> +    {HID_USAGE_SENSOR_COMPASS_3D, 0, 1000, 0},
>> +    {HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},
>> +
>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 17453, 0},
>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D,
>> +        HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453},
>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D,
>> +        HID_USAGE_SENSOR_UNITS_RADIANS, 1, 0},
>> +
>> +    {HID_USAGE_SENSOR_ALS, 0, 1, 0},
>> +    {HID_USAGE_SENSOR_ALS, HID_USAGE_SENSOR_UNITS_LUX, 1, 0},
>> +
>> +    {HID_USAGE_SENSOR_PRESSURE, 0, 100000, 0},
>> +    {HID_USAGE_SENSOR_PRESSURE, HID_USAGE_SENSOR_UNITS_PASCAL, 1, 0},
>> +};
>> +
>>   static int pow_10(unsigned power)
>>   {
>>       int i;
>> @@ -209,6 +243,86 @@ int hid_sensor_write_raw_hyst_value(struct 
>> hid_sensor_common *st,
>>   }
>>   EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
>>
>> +/*
>> + * This fuction applies the unit exponent to the scale.
> function.
>
> Good examples btw.
>> + * For example:
>> + * 9.806650 ->exp:2-> val0[980]val1[6650]
>> + * 9.000806 ->exp:2-> val0[900]val1[806]
>> + * 0.174535 ->exp:2-> val0[17]val1[4535]
>> + * 1.001745 ->exp:0-> val0[1]val1[1745]
>> + * 1.001745 ->exp:2-> val0[100]val1[1745]
>> + * 1.001745 ->exp:4-> val0[10017]val1[45]
>> + * 9.806650 ->exp:-2-> val0[0]val1[98066]
>> + */
>> +static void adjust_exponent_micro(int *val0, int *val1, int scale0,
>> +                  int scale1, int exp)
>> +{
>> +    int i;
>> +    int x;
>> +    int res;
>> +    int rem;
>> +
>> +    if (exp > 0) {
>> +        *val0 = scale0 * pow_10(exp);
>> +        res = 0;
>> +        if (exp > 6) {
>> +            *val1 = 0;
>> +            return;
>> +        }
>> +        for (i = 0; i < exp; ++i) {
>> +            x = scale1 / pow_10(5 - i);
>> +            res += (pow_10(exp - 1 - i) * x);
>> +            scale1 = scale1 % pow_10(5 - i);
>> +        }
>> +        *val0 += res;
>> +            *val1 = scale1 * pow_10(exp);
>> +    } else if (exp < 0) {
>> +        exp = abs(exp);
>> +        if (exp > 6) {
>> +            *val0 = *val1 = 0;
>> +            return;
>> +        }
>> +        *val0 = scale0 / pow_10(exp);
>> +        rem = scale0 % pow_10(exp);
>> +        res = 0;
>> +        for (i = 0; i < (6 - exp); ++i) {
>> +            x = scale1 / pow_10(5 - i);
>> +            res += (pow_10(5 - exp - i) * x);
>> +            scale1 = scale1 % pow_10(5 - i);
>> +        }
>> +        *val1 = rem * pow_10(6 - exp) + res;
>> +    } else {
>> +        *val0 = scale0;
>> +        *val1 = scale1;
>> +    }
>> +}
>> +
>> +int hid_sensor_format_scale(u32 usage_id,
>> +            struct hid_sensor_hub_attribute_info *attr_info,
>> +            int *val0, int *val1)
>> +{
>> +    int i;
>> +    int exp;
>> +
>> +    *val0 = 1;
>> +    *val1 = 0;
>> +
>> +    for (i = 0; ARRAY_SIZE(unit_conversion); ++i) {
>> +        if (unit_conversion[i].usage_id == usage_id &&
>> +            unit_conversion[i].unit == attr_info->units) {
>> +            exp  = hid_sensor_convert_exponent(
>> +                        attr_info->unit_expo);
>> +            adjust_exponent_micro(val0, val1,
>> +                    unit_conversion[i].scale_val0,
>> +                    unit_conversion[i].scale_val1, exp);
>> +            break;
>> +        }
>> +    }
>> +
>> +    return IIO_VAL_INT_PLUS_MICRO;
>> +}
>> +EXPORT_SYMBOL(hid_sensor_format_scale);
>> +
>>   int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device 
>> *hsdev,
>>                       u32 usage_id,
>>                       struct hid_sensor_common *st)
>> diff --git a/include/linux/hid-sensor-hub.h 
>> b/include/linux/hid-sensor-hub.h
>> index b70cfd7..89626b2 100644
>> --- a/include/linux/hid-sensor-hub.h
>> +++ b/include/linux/hid-sensor-hub.h
>> @@ -223,4 +223,8 @@ int hid_sensor_read_samp_freq_value(struct 
>> hid_sensor_common *st,
>>   int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
>>                   u32 report_id, int field_index, u32 usage_id);
>>
>> +int hid_sensor_format_scale(u32 usage_id,
>> +                struct hid_sensor_hub_attribute_info *attr_info,
>> +                int *val0, int *val1);
>> +
>>   #endif
>>
>
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 01/16] iio: hid-sensors: Convert units and exponent
  2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
                   ` (15 preceding siblings ...)
  2014-04-23 20:57 ` [PATCH 01/16] iio: hid-sensors: Convert units and exponent Jonathan Cameron
@ 2014-04-25 18:30 ` Jonathan Cameron
  2014-04-26 19:34   ` Srinivas Pandruvada
  16 siblings, 1 reply; 41+ messages in thread
From: Jonathan Cameron @ 2014-04-25 18:30 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> HID sensor hub specify a default unit and alternative units. This
> along with unit exponent can be used adjust scale. This change
> change HID sensor data units to IIO defined units for each
> sensor type. So in this way user space can use a simply use:
> "(data + offset) * scale" to get final result.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
see inline.
> ---
>   .../iio/common/hid-sensors/hid-sensor-attributes.c | 114 +++++++++++++++++++++
>   include/linux/hid-sensor-hub.h                     |   4 +
>   2 files changed, 118 insertions(+)
>
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> index 75b5473..451a95b 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> @@ -26,6 +26,40 @@
>   #include <linux/iio/iio.h>
>   #include <linux/iio/sysfs.h>
>
> +struct {
> +	u32 usage_id;
> +	int unit; /* 0 for default others from HID sensor spec */
> +	int scale_val0; /* scale, whole number */
> +	int scale_val1; /* scale, fraction in micros */
> +} unit_conversion[] = {
> +	{HID_USAGE_SENSOR_ACCEL_3D, 0, 9, 806650},
> +	{HID_USAGE_SENSOR_ACCEL_3D,
> +		HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD, 1, 0},
> +	{HID_USAGE_SENSOR_ACCEL_3D,
> +		HID_USAGE_SENSOR_UNITS_G, 9, 806650},
> +
> +	{HID_USAGE_SENSOR_GYRO_3D, 0, 0, 17453},
> +	{HID_USAGE_SENSOR_GYRO_3D,
> +		HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND, 1, 0},
> +	{HID_USAGE_SENSOR_GYRO_3D,
> +		HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND, 0, 17453},
> +
> +	{HID_USAGE_SENSOR_COMPASS_3D, 0, 1000, 0},
> +	{HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},
> +
> +	{HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 17453, 0},
> +	{HID_USAGE_SENSOR_INCLINOMETER_3D,
> +		HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453},
> +	{HID_USAGE_SENSOR_INCLINOMETER_3D,
> +		HID_USAGE_SENSOR_UNITS_RADIANS, 1, 0},
> +
> +	{HID_USAGE_SENSOR_ALS, 0, 1, 0},
> +	{HID_USAGE_SENSOR_ALS, HID_USAGE_SENSOR_UNITS_LUX, 1, 0},
> +
> +	{HID_USAGE_SENSOR_PRESSURE, 0, 100000, 0},
> +	{HID_USAGE_SENSOR_PRESSURE, HID_USAGE_SENSOR_UNITS_PASCAL, 1, 0},
> +};
> +
>   static int pow_10(unsigned power)
>   {
>   	int i;
> @@ -209,6 +243,86 @@ int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
>   }
>   EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
>
> +/*
> + * This fuction applies the unit exponent to the scale.
> + * For example:
Function
> + * 9.806650 ->exp:2-> val0[980]val1[6650]
> + * 9.000806 ->exp:2-> val0[900]val1[806]
> + * 0.174535 ->exp:2-> val0[17]val1[4535]
> + * 1.001745 ->exp:0-> val0[1]val1[1745]
> + * 1.001745 ->exp:2-> val0[100]val1[1745]
> + * 1.001745 ->exp:4-> val0[10017]val1[45]
> + * 9.806650 ->exp:-2-> val0[0]val1[98066]
It took me a while to get what you meant here, perhaps for the examples it
is worth showing the actual value directly as well. Maybe.
9.806650 exp:2->980.6650 -> val0[980]val1[665000] (note the above is I think
incorrect due to lack of trailing zeros on val1.
> + */
> +static void adjust_exponent_micro(int *val0, int *val1, int scale0,
> +				  int scale1, int exp)
> +{
> +	int i;
> +	int x;
> +	int res;
> +	int rem;
> +
> +	if (exp > 0) {
> +		*val0 = scale0 * pow_10(exp);
> +		res = 0;
> +		if (exp > 6) {
> +			*val1 = 0;
> +			return;
> +		}
so if example 1 above..
val0 = 900 as desired.
i  = 0;
sca1e1 = 806650
x = 806650/100000 = 8;
res = 80;
scale1 = 06650
i = 1
x = 06650/10000 = 0;
res = 80;
  so 980. Good.
> +		for (i = 0; i < exp; ++i) {
> +			x = scale1 / pow_10(5 - i);
> +			res += (pow_10(exp - 1 - i) * x);
> +			scale1 = scale1 % pow_10(5 - i);
> +		}
> +		*val0 += res;
> +			*val1 = scale1 * pow_10(exp);
val1 = 665000 which is correct with the trailing zeros in val2.
So your code is good but examples need those zeros!
> +	} else if (exp < 0) {
> +		exp = abs(exp);
> +		if (exp > 6) {
> +			*val0 = *val1 = 0;
> +			return;
> +		}
> +		*val0 = scale0 / pow_10(exp);
> +		rem = scale0 % pow_10(exp);
> +		res = 0;
> +		for (i = 0; i < (6 - exp); ++i) {
> +			x = scale1 / pow_10(5 - i);
> +			res += (pow_10(5 - exp - i) * x);
> +			scale1 = scale1 % pow_10(5 - i);
> +		}
> +		*val1 = rem * pow_10(6 - exp) + res;
> +	} else {
> +		*val0 = scale0;
> +		*val1 = scale1;
> +	}
> +}
> +
> +int hid_sensor_format_scale(u32 usage_id,
> +			struct hid_sensor_hub_attribute_info *attr_info,
> +			int *val0, int *val1)
> +{
> +	int i;
> +	int exp;
> +
> +	*val0 = 1;
> +	*val1 = 0;
> +
> +	for (i = 0; ARRAY_SIZE(unit_conversion); ++i) {
> +		if (unit_conversion[i].usage_id == usage_id &&
> +			unit_conversion[i].unit == attr_info->units) {
> +			exp  = hid_sensor_convert_exponent(
> +						attr_info->unit_expo);
> +			adjust_exponent_micro(val0, val1,
> +					unit_conversion[i].scale_val0,
> +					unit_conversion[i].scale_val1, exp);
> +			break;
> +		}
> +	}
> +
> +	return IIO_VAL_INT_PLUS_MICRO;
> +}
> +EXPORT_SYMBOL(hid_sensor_format_scale);
> +
>   int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
>   					u32 usage_id,
>   					struct hid_sensor_common *st)
> diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
> index b70cfd7..89626b2 100644
> --- a/include/linux/hid-sensor-hub.h
> +++ b/include/linux/hid-sensor-hub.h
> @@ -223,4 +223,8 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
>   int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
>   				u32 report_id, int field_index, u32 usage_id);
>
> +int hid_sensor_format_scale(u32 usage_id,
> +			    struct hid_sensor_hub_attribute_info *attr_info,
> +			    int *val0, int *val1);
> +
>   #endif
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 01/16] iio: hid-sensors: Convert units and exponent
  2014-04-23 21:17   ` Srinivas Pandruvada
@ 2014-04-25 18:34     ` Jonathan Cameron
  0 siblings, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-04-25 18:34 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 23/04/14 22:17, Srinivas Pandruvada wrote:
>
> On 04/23/2014 01:57 PM, Jonathan Cameron wrote:
>> On 19/04/14 00:22, Srinivas Pandruvada wrote:
>>> HID sensor hub specify a default unit and alternative units. This
>>> along with unit exponent can be used adjust scale. This change
>>> change HID sensor data units to IIO defined units for each
>>> sensor type. So in this way user space can use a simply use:
>>> "(data + offset) * scale" to get final result.
>>>
>>> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
>>
>> Hi Srinivas,
>>
>> What 'grief' is this abi change likely to cause us?
>>
> Hi Jonathan,
>
> Since the products are just released with the hubs, I don't think there is much impact.
> I have notified few users I knew, who pointed me about this disparity.
>
>
> Thanks,
> Srinivas
Cool. I'll attach a health warning to the pull request that this 'might cause'
grief, but the view is that it is unlikely and we are simply bringing the driver
in line with the API that existed at the time.  I'll also add that we have users
noticing and querying the disrepency.
  
>> I know I effectively asked you to fix this, but I'd like to get
>> a handle on just how many people are likely to shout.
>>
>> The original code is a gross breaking of the published ABI so
>> it probably is reasonable to change it...
>>
>> I'm too tired to review this properly right now so only the most
>> superficial comments in line.
>>> ---
>>>   .../iio/common/hid-sensors/hid-sensor-attributes.c | 114 +++++++++++++++++++++
>>>   include/linux/hid-sensor-hub.h                     |   4 +
>>>   2 files changed, 118 insertions(+)
>>>
>>> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>>> index 75b5473..451a95b 100644
>>> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>>> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>>> @@ -26,6 +26,40 @@
>>>   #include <linux/iio/iio.h>
>>>   #include <linux/iio/sysfs.h>
>>>
>>> +struct {
>>> +    u32 usage_id;
>>> +    int unit; /* 0 for default others from HID sensor spec */
>>> +    int scale_val0; /* scale, whole number */
>>> +    int scale_val1; /* scale, fraction in micros */
>>> +} unit_conversion[] = {
>>> +    {HID_USAGE_SENSOR_ACCEL_3D, 0, 9, 806650},
>>> +    {HID_USAGE_SENSOR_ACCEL_3D,
>>> +        HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD, 1, 0},
>>> +    {HID_USAGE_SENSOR_ACCEL_3D,
>>> +        HID_USAGE_SENSOR_UNITS_G, 9, 806650},
>>> +
>>> +    {HID_USAGE_SENSOR_GYRO_3D, 0, 0, 17453},
>>> +    {HID_USAGE_SENSOR_GYRO_3D,
>>> +        HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND, 1, 0},
>>> +    {HID_USAGE_SENSOR_GYRO_3D,
>>> +        HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND, 0, 17453},
>>> +
>>> +    {HID_USAGE_SENSOR_COMPASS_3D, 0, 1000, 0},
>>> +    {HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},
>>> +
>>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 17453, 0},
>>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D,
>>> +        HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453},
>>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D,
>>> +        HID_USAGE_SENSOR_UNITS_RADIANS, 1, 0},
>>> +
>>> +    {HID_USAGE_SENSOR_ALS, 0, 1, 0},
>>> +    {HID_USAGE_SENSOR_ALS, HID_USAGE_SENSOR_UNITS_LUX, 1, 0},
>>> +
>>> +    {HID_USAGE_SENSOR_PRESSURE, 0, 100000, 0},
>>> +    {HID_USAGE_SENSOR_PRESSURE, HID_USAGE_SENSOR_UNITS_PASCAL, 1, 0},
>>> +};
>>> +
>>>   static int pow_10(unsigned power)
>>>   {
>>>       int i;
>>> @@ -209,6 +243,86 @@ int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
>>>   }
>>>   EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
>>>
>>> +/*
>>> + * This fuction applies the unit exponent to the scale.
>> function.
>>
>> Good examples btw.
>>> + * For example:
>>> + * 9.806650 ->exp:2-> val0[980]val1[6650]
>>> + * 9.000806 ->exp:2-> val0[900]val1[806]
>>> + * 0.174535 ->exp:2-> val0[17]val1[4535]
>>> + * 1.001745 ->exp:0-> val0[1]val1[1745]
>>> + * 1.001745 ->exp:2-> val0[100]val1[1745]
>>> + * 1.001745 ->exp:4-> val0[10017]val1[45]
>>> + * 9.806650 ->exp:-2-> val0[0]val1[98066]
>>> + */
>>> +static void adjust_exponent_micro(int *val0, int *val1, int scale0,
>>> +                  int scale1, int exp)
>>> +{
>>> +    int i;
>>> +    int x;
>>> +    int res;
>>> +    int rem;
>>> +
>>> +    if (exp > 0) {
>>> +        *val0 = scale0 * pow_10(exp);
>>> +        res = 0;
>>> +        if (exp > 6) {
>>> +            *val1 = 0;
>>> +            return;
>>> +        }
>>> +        for (i = 0; i < exp; ++i) {
>>> +            x = scale1 / pow_10(5 - i);
>>> +            res += (pow_10(exp - 1 - i) * x);
>>> +            scale1 = scale1 % pow_10(5 - i);
>>> +        }
>>> +        *val0 += res;
>>> +            *val1 = scale1 * pow_10(exp);
>>> +    } else if (exp < 0) {
>>> +        exp = abs(exp);
>>> +        if (exp > 6) {
>>> +            *val0 = *val1 = 0;
>>> +            return;
>>> +        }
>>> +        *val0 = scale0 / pow_10(exp);
>>> +        rem = scale0 % pow_10(exp);
>>> +        res = 0;
>>> +        for (i = 0; i < (6 - exp); ++i) {
>>> +            x = scale1 / pow_10(5 - i);
>>> +            res += (pow_10(5 - exp - i) * x);
>>> +            scale1 = scale1 % pow_10(5 - i);
>>> +        }
>>> +        *val1 = rem * pow_10(6 - exp) + res;
>>> +    } else {
>>> +        *val0 = scale0;
>>> +        *val1 = scale1;
>>> +    }
>>> +}
>>> +
>>> +int hid_sensor_format_scale(u32 usage_id,
>>> +            struct hid_sensor_hub_attribute_info *attr_info,
>>> +            int *val0, int *val1)
>>> +{
>>> +    int i;
>>> +    int exp;
>>> +
>>> +    *val0 = 1;
>>> +    *val1 = 0;
>>> +
>>> +    for (i = 0; ARRAY_SIZE(unit_conversion); ++i) {
>>> +        if (unit_conversion[i].usage_id == usage_id &&
>>> +            unit_conversion[i].unit == attr_info->units) {
>>> +            exp  = hid_sensor_convert_exponent(
>>> +                        attr_info->unit_expo);
>>> +            adjust_exponent_micro(val0, val1,
>>> +                    unit_conversion[i].scale_val0,
>>> +                    unit_conversion[i].scale_val1, exp);
>>> +            break;
>>> +        }
>>> +    }
>>> +
>>> +    return IIO_VAL_INT_PLUS_MICRO;
>>> +}
>>> +EXPORT_SYMBOL(hid_sensor_format_scale);
>>> +
>>>   int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
>>>                       u32 usage_id,
>>>                       struct hid_sensor_common *st)
>>> diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
>>> index b70cfd7..89626b2 100644
>>> --- a/include/linux/hid-sensor-hub.h
>>> +++ b/include/linux/hid-sensor-hub.h
>>> @@ -223,4 +223,8 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
>>>   int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
>>>                   u32 report_id, int field_index, u32 usage_id);
>>>
>>> +int hid_sensor_format_scale(u32 usage_id,
>>> +                struct hid_sensor_hub_attribute_info *attr_info,
>>> +                int *val0, int *val1);
>>> +
>>>   #endif
>>>
>>
>>
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 01/16] iio: hid-sensors: Convert units and exponent
  2014-04-25 18:30 ` Jonathan Cameron
@ 2014-04-26 19:34   ` Srinivas Pandruvada
  2014-05-03 19:24     ` Jonathan Cameron
  0 siblings, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-04-26 19:34 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio


On 04/25/2014 11:30 AM, Jonathan Cameron wrote:
> On 19/04/14 00:22, Srinivas Pandruvada wrote:
>> HID sensor hub specify a default unit and alternative units. This
>> along with unit exponent can be used adjust scale. This change
>> change HID sensor data units to IIO defined units for each
>> sensor type. So in this way user space can use a simply use:
>> "(data + offset) * scale" to get final result.
>>
>> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> see inline.
>> ---
>>   .../iio/common/hid-sensors/hid-sensor-attributes.c | 114 
>> +++++++++++++++++++++
>>   include/linux/hid-sensor-hub.h                     |   4 +
>>   2 files changed, 118 insertions(+)
>>
>> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c 
>> b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>> index 75b5473..451a95b 100644
>> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>> @@ -26,6 +26,40 @@
>>   #include <linux/iio/iio.h>
>>   #include <linux/iio/sysfs.h>
>>
>> +struct {
>> +    u32 usage_id;
>> +    int unit; /* 0 for default others from HID sensor spec */
>> +    int scale_val0; /* scale, whole number */
>> +    int scale_val1; /* scale, fraction in micros */
>> +} unit_conversion[] = {
>> +    {HID_USAGE_SENSOR_ACCEL_3D, 0, 9, 806650},
>> +    {HID_USAGE_SENSOR_ACCEL_3D,
>> +        HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD, 1, 0},
>> +    {HID_USAGE_SENSOR_ACCEL_3D,
>> +        HID_USAGE_SENSOR_UNITS_G, 9, 806650},
>> +
>> +    {HID_USAGE_SENSOR_GYRO_3D, 0, 0, 17453},
>> +    {HID_USAGE_SENSOR_GYRO_3D,
>> +        HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND, 1, 0},
>> +    {HID_USAGE_SENSOR_GYRO_3D,
>> +        HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND, 0, 17453},
>> +
>> +    {HID_USAGE_SENSOR_COMPASS_3D, 0, 1000, 0},
>> +    {HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},
>> +
>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 17453, 0},
>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D,
>> +        HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453},
>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D,
>> +        HID_USAGE_SENSOR_UNITS_RADIANS, 1, 0},
>> +
>> +    {HID_USAGE_SENSOR_ALS, 0, 1, 0},
>> +    {HID_USAGE_SENSOR_ALS, HID_USAGE_SENSOR_UNITS_LUX, 1, 0},
>> +
>> +    {HID_USAGE_SENSOR_PRESSURE, 0, 100000, 0},
>> +    {HID_USAGE_SENSOR_PRESSURE, HID_USAGE_SENSOR_UNITS_PASCAL, 1, 0},
>> +};
>> +
>>   static int pow_10(unsigned power)
>>   {
>>       int i;
>> @@ -209,6 +243,86 @@ int hid_sensor_write_raw_hyst_value(struct 
>> hid_sensor_common *st,
>>   }
>>   EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
>>
>> +/*
>> + * This fuction applies the unit exponent to the scale.
>> + * For example:
> Function
>> + * 9.806650 ->exp:2-> val0[980]val1[6650]
>> + * 9.000806 ->exp:2-> val0[900]val1[806]
>> + * 0.174535 ->exp:2-> val0[17]val1[4535]
>> + * 1.001745 ->exp:0-> val0[1]val1[1745]
>> + * 1.001745 ->exp:2-> val0[100]val1[1745]
>> + * 1.001745 ->exp:4-> val0[10017]val1[45]
>> + * 9.806650 ->exp:-2-> val0[0]val1[98066]
> It took me a while to get what you meant here, perhaps for the 
> examples it
> is worth showing the actual value directly as well. Maybe.
> 9.806650 exp:2->980.6650 -> val0[980]val1[665000] (note the above is I 
> think
> incorrect due to lack of trailing zeros on val1.
>> + */
>> +static void adjust_exponent_micro(int *val0, int *val1, int scale0,
>> +                  int scale1, int exp)
>> +{
>> +    int i;
>> +    int x;
>> +    int res;
>> +    int rem;
>> +
>> +    if (exp > 0) {
>> +        *val0 = scale0 * pow_10(exp);
>> +        res = 0;
>> +        if (exp > 6) {
>> +            *val1 = 0;
>> +            return;
>> +        }
> so if example 1 above..
> val0 = 900 as desired.
> i  = 0;
> sca1e1 = 806650
> x = 806650/100000 = 8;
> res = 80;
> scale1 = 06650
> i = 1
> x = 06650/10000 = 0;
> res = 80;
>  so 980. Good.
>> +        for (i = 0; i < exp; ++i) {
>> +            x = scale1 / pow_10(5 - i);
>> +            res += (pow_10(exp - 1 - i) * x);
>> +            scale1 = scale1 % pow_10(5 - i);
>> +        }
>> +        *val0 += res;
>> +            *val1 = scale1 * pow_10(exp);
> val1 = 665000 which is correct with the trailing zeros in val2.
> So your code is good but examples need those zeros!
Impressive, Absolutely great review. I will correct comments in the next 
version.

Thanks,
Srinivas
>
>> +    } else if (exp < 0) {
>> +        exp = abs(exp);
>> +        if (exp > 6) {
>> +            *val0 = *val1 = 0;
>> +            return;
>> +        }
>> +        *val0 = scale0 / pow_10(exp);
>> +        rem = scale0 % pow_10(exp);
>> +        res = 0;
>> +        for (i = 0; i < (6 - exp); ++i) {
>> +            x = scale1 / pow_10(5 - i);
>> +            res += (pow_10(5 - exp - i) * x);
>> +            scale1 = scale1 % pow_10(5 - i);
>> +        }
>> +        *val1 = rem * pow_10(6 - exp) + res;
>> +    } else {
>> +        *val0 = scale0;
>> +        *val1 = scale1;
>> +    }
>> +}
>> +
>> +int hid_sensor_format_scale(u32 usage_id,
>> +            struct hid_sensor_hub_attribute_info *attr_info,
>> +            int *val0, int *val1)
>> +{
>> +    int i;
>> +    int exp;
>> +
>> +    *val0 = 1;
>> +    *val1 = 0;
>> +
>> +    for (i = 0; ARRAY_SIZE(unit_conversion); ++i) {
>> +        if (unit_conversion[i].usage_id == usage_id &&
>> +            unit_conversion[i].unit == attr_info->units) {
>> +            exp  = hid_sensor_convert_exponent(
>> +                        attr_info->unit_expo);
>> +            adjust_exponent_micro(val0, val1,
>> +                    unit_conversion[i].scale_val0,
>> +                    unit_conversion[i].scale_val1, exp);
>> +            break;
>> +        }
>> +    }
>> +
>> +    return IIO_VAL_INT_PLUS_MICRO;
>> +}
>> +EXPORT_SYMBOL(hid_sensor_format_scale);
>> +
>>   int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device 
>> *hsdev,
>>                       u32 usage_id,
>>                       struct hid_sensor_common *st)
>> diff --git a/include/linux/hid-sensor-hub.h 
>> b/include/linux/hid-sensor-hub.h
>> index b70cfd7..89626b2 100644
>> --- a/include/linux/hid-sensor-hub.h
>> +++ b/include/linux/hid-sensor-hub.h
>> @@ -223,4 +223,8 @@ int hid_sensor_read_samp_freq_value(struct 
>> hid_sensor_common *st,
>>   int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
>>                   u32 report_id, int field_index, u32 usage_id);
>>
>> +int hid_sensor_format_scale(u32 usage_id,
>> +                struct hid_sensor_hub_attribute_info *attr_info,
>> +                int *val0, int *val1);
>> +
>>   #endif
>>
>
> -- 
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 01/16] iio: hid-sensors: Convert units and exponent
  2014-04-26 19:34   ` Srinivas Pandruvada
@ 2014-05-03 19:24     ` Jonathan Cameron
  2014-05-03 19:32       ` Jonathan Cameron
  2014-05-04 14:49       ` Srinivas Pandruvada
  0 siblings, 2 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:24 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 26/04/14 20:34, Srinivas Pandruvada wrote:
>
> On 04/25/2014 11:30 AM, Jonathan Cameron wrote:
>> On 19/04/14 00:22, Srinivas Pandruvada wrote:
>>> HID sensor hub specify a default unit and alternative units. This
>>> along with unit exponent can be used adjust scale. This change
>>> change HID sensor data units to IIO defined units for each
>>> sensor type. So in this way user space can use a simply use:
>>> "(data + offset) * scale" to get final result.
>>>
>>> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
>> see inline.
Applied to the togreg branch of iio.git with a tweaks to comments as mentioned
(please check I didn't mess them up!)

>>> ---
>>>   .../iio/common/hid-sensors/hid-sensor-attributes.c | 114 +++++++++++++++++++++
>>>   include/linux/hid-sensor-hub.h                     |   4 +
>>>   2 files changed, 118 insertions(+)
>>>
>>> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>>> index 75b5473..451a95b 100644
>>> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>>> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>>> @@ -26,6 +26,40 @@
>>>   #include <linux/iio/iio.h>
>>>   #include <linux/iio/sysfs.h>
>>>
>>> +struct {
>>> +    u32 usage_id;
>>> +    int unit; /* 0 for default others from HID sensor spec */
>>> +    int scale_val0; /* scale, whole number */
>>> +    int scale_val1; /* scale, fraction in micros */
>>> +} unit_conversion[] = {
>>> +    {HID_USAGE_SENSOR_ACCEL_3D, 0, 9, 806650},
>>> +    {HID_USAGE_SENSOR_ACCEL_3D,
>>> +        HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD, 1, 0},
>>> +    {HID_USAGE_SENSOR_ACCEL_3D,
>>> +        HID_USAGE_SENSOR_UNITS_G, 9, 806650},
>>> +
>>> +    {HID_USAGE_SENSOR_GYRO_3D, 0, 0, 17453},
>>> +    {HID_USAGE_SENSOR_GYRO_3D,
>>> +        HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND, 1, 0},
>>> +    {HID_USAGE_SENSOR_GYRO_3D,
>>> +        HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND, 0, 17453},
>>> +
>>> +    {HID_USAGE_SENSOR_COMPASS_3D, 0, 1000, 0},
>>> +    {HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},
>>> +
>>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 17453, 0},
>>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D,
>>> +        HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453},
>>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D,
>>> +        HID_USAGE_SENSOR_UNITS_RADIANS, 1, 0},
>>> +
>>> +    {HID_USAGE_SENSOR_ALS, 0, 1, 0},
>>> +    {HID_USAGE_SENSOR_ALS, HID_USAGE_SENSOR_UNITS_LUX, 1, 0},
>>> +
>>> +    {HID_USAGE_SENSOR_PRESSURE, 0, 100000, 0},
>>> +    {HID_USAGE_SENSOR_PRESSURE, HID_USAGE_SENSOR_UNITS_PASCAL, 1, 0},
>>> +};
>>> +
>>>   static int pow_10(unsigned power)
>>>   {
>>>       int i;
>>> @@ -209,6 +243,86 @@ int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
>>>   }
>>>   EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
>>>
>>> +/*
>>> + * This fuction applies the unit exponent to the scale.
>>> + * For example:
>> Function
>>> + * 9.806650 ->exp:2-> val0[980]val1[6650]
>>> + * 9.000806 ->exp:2-> val0[900]val1[806]
>>> + * 0.174535 ->exp:2-> val0[17]val1[4535]
>>> + * 1.001745 ->exp:0-> val0[1]val1[1745]
>>> + * 1.001745 ->exp:2-> val0[100]val1[1745]
>>> + * 1.001745 ->exp:4-> val0[10017]val1[45]
>>> + * 9.806650 ->exp:-2-> val0[0]val1[98066]
>> It took me a while to get what you meant here, perhaps for the examples it
>> is worth showing the actual value directly as well. Maybe.
>> 9.806650 exp:2->980.6650 -> val0[980]val1[665000] (note the above is I think
>> incorrect due to lack of trailing zeros on val1.
>>> + */
>>> +static void adjust_exponent_micro(int *val0, int *val1, int scale0,
>>> +                  int scale1, int exp)
>>> +{
>>> +    int i;
>>> +    int x;
>>> +    int res;
>>> +    int rem;
>>> +
>>> +    if (exp > 0) {
>>> +        *val0 = scale0 * pow_10(exp);
>>> +        res = 0;
>>> +        if (exp > 6) {
>>> +            *val1 = 0;
>>> +            return;
>>> +        }
>> so if example 1 above..
>> val0 = 900 as desired.
>> i  = 0;
>> sca1e1 = 806650
>> x = 806650/100000 = 8;
>> res = 80;
>> scale1 = 06650
>> i = 1
>> x = 06650/10000 = 0;
>> res = 80;
>>  so 980. Good.
>>> +        for (i = 0; i < exp; ++i) {
>>> +            x = scale1 / pow_10(5 - i);
>>> +            res += (pow_10(exp - 1 - i) * x);
>>> +            scale1 = scale1 % pow_10(5 - i);
>>> +        }
>>> +        *val0 += res;
>>> +            *val1 = scale1 * pow_10(exp);
>> val1 = 665000 which is correct with the trailing zeros in val2.
>> So your code is good but examples need those zeros!
> Impressive, Absolutely great review. I will correct comments in the next version.
Given this was the only issue in the patch set I'll just fix it up as I merge
it.

It's been a couple of weeks an noone else has chipped in on this series, so
I'm taking it now.


>
> Thanks,
> Srinivas
>>
>>> +    } else if (exp < 0) {
>>> +        exp = abs(exp);
>>> +        if (exp > 6) {
>>> +            *val0 = *val1 = 0;
>>> +            return;
>>> +        }
>>> +        *val0 = scale0 / pow_10(exp);
>>> +        rem = scale0 % pow_10(exp);
>>> +        res = 0;
>>> +        for (i = 0; i < (6 - exp); ++i) {
>>> +            x = scale1 / pow_10(5 - i);
>>> +            res += (pow_10(5 - exp - i) * x);
>>> +            scale1 = scale1 % pow_10(5 - i);
>>> +        }
>>> +        *val1 = rem * pow_10(6 - exp) + res;
>>> +    } else {
>>> +        *val0 = scale0;
>>> +        *val1 = scale1;
>>> +    }
>>> +}
>>> +
>>> +int hid_sensor_format_scale(u32 usage_id,
>>> +            struct hid_sensor_hub_attribute_info *attr_info,
>>> +            int *val0, int *val1)
>>> +{
>>> +    int i;
>>> +    int exp;
>>> +
>>> +    *val0 = 1;
>>> +    *val1 = 0;
>>> +
>>> +    for (i = 0; ARRAY_SIZE(unit_conversion); ++i) {
>>> +        if (unit_conversion[i].usage_id == usage_id &&
>>> +            unit_conversion[i].unit == attr_info->units) {
>>> +            exp  = hid_sensor_convert_exponent(
>>> +                        attr_info->unit_expo);
>>> +            adjust_exponent_micro(val0, val1,
>>> +                    unit_conversion[i].scale_val0,
>>> +                    unit_conversion[i].scale_val1, exp);
>>> +            break;
>>> +        }
>>> +    }
>>> +
>>> +    return IIO_VAL_INT_PLUS_MICRO;
>>> +}
>>> +EXPORT_SYMBOL(hid_sensor_format_scale);
>>> +
>>>   int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
>>>                       u32 usage_id,
>>>                       struct hid_sensor_common *st)
>>> diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
>>> index b70cfd7..89626b2 100644
>>> --- a/include/linux/hid-sensor-hub.h
>>> +++ b/include/linux/hid-sensor-hub.h
>>> @@ -223,4 +223,8 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
>>>   int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
>>>                   u32 report_id, int field_index, u32 usage_id);
>>>
>>> +int hid_sensor_format_scale(u32 usage_id,
>>> +                struct hid_sensor_hub_attribute_info *attr_info,
>>> +                int *val0, int *val1);
>>> +
>>>   #endif
>>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 01/16] iio: hid-sensors: Convert units and exponent
  2014-05-03 19:24     ` Jonathan Cameron
@ 2014-05-03 19:32       ` Jonathan Cameron
  2014-05-04 14:49       ` Srinivas Pandruvada
  1 sibling, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:32 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 03/05/14 20:24, Jonathan Cameron wrote:
> On 26/04/14 20:34, Srinivas Pandruvada wrote:
>>
>> On 04/25/2014 11:30 AM, Jonathan Cameron wrote:
>>> On 19/04/14 00:22, Srinivas Pandruvada wrote:
>>>> HID sensor hub specify a default unit and alternative units. This
>>>> along with unit exponent can be used adjust scale. This change
>>>> change HID sensor data units to IIO defined units for each
>>>> sensor type. So in this way user space can use a simply use:
>>>> "(data + offset) * scale" to get final result.
>>>>
>>>> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
>>> see inline.
> Applied to the togreg branch of iio.git with a tweaks to comments as mentioned
> (please check I didn't mess them up!)
I should let my build tests finish before sending these sorts of emails out.
There was a missing static on the unit_conversion structure.
Added to the version applied...

>
>>>> ---
>>>>   .../iio/common/hid-sensors/hid-sensor-attributes.c | 114 +++++++++++++++++++++
>>>>   include/linux/hid-sensor-hub.h                     |   4 +
>>>>   2 files changed, 118 insertions(+)
>>>>
>>>> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>>>> index 75b5473..451a95b 100644
>>>> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>>>> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>>>> @@ -26,6 +26,40 @@
>>>>   #include <linux/iio/iio.h>
>>>>   #include <linux/iio/sysfs.h>
>>>>
>>>> +struct {
>>>> +    u32 usage_id;
>>>> +    int unit; /* 0 for default others from HID sensor spec */
>>>> +    int scale_val0; /* scale, whole number */
>>>> +    int scale_val1; /* scale, fraction in micros */
>>>> +} unit_conversion[] = {
>>>> +    {HID_USAGE_SENSOR_ACCEL_3D, 0, 9, 806650},
>>>> +    {HID_USAGE_SENSOR_ACCEL_3D,
>>>> +        HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD, 1, 0},
>>>> +    {HID_USAGE_SENSOR_ACCEL_3D,
>>>> +        HID_USAGE_SENSOR_UNITS_G, 9, 806650},
>>>> +
>>>> +    {HID_USAGE_SENSOR_GYRO_3D, 0, 0, 17453},
>>>> +    {HID_USAGE_SENSOR_GYRO_3D,
>>>> +        HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND, 1, 0},
>>>> +    {HID_USAGE_SENSOR_GYRO_3D,
>>>> +        HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND, 0, 17453},
>>>> +
>>>> +    {HID_USAGE_SENSOR_COMPASS_3D, 0, 1000, 0},
>>>> +    {HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},
>>>> +
>>>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 17453, 0},
>>>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D,
>>>> +        HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453},
>>>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D,
>>>> +        HID_USAGE_SENSOR_UNITS_RADIANS, 1, 0},
>>>> +
>>>> +    {HID_USAGE_SENSOR_ALS, 0, 1, 0},
>>>> +    {HID_USAGE_SENSOR_ALS, HID_USAGE_SENSOR_UNITS_LUX, 1, 0},
>>>> +
>>>> +    {HID_USAGE_SENSOR_PRESSURE, 0, 100000, 0},
>>>> +    {HID_USAGE_SENSOR_PRESSURE, HID_USAGE_SENSOR_UNITS_PASCAL, 1, 0},
>>>> +};
>>>> +
>>>>   static int pow_10(unsigned power)
>>>>   {
>>>>       int i;
>>>> @@ -209,6 +243,86 @@ int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
>>>>   }
>>>>   EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
>>>>
>>>> +/*
>>>> + * This fuction applies the unit exponent to the scale.
>>>> + * For example:
>>> Function
>>>> + * 9.806650 ->exp:2-> val0[980]val1[6650]
>>>> + * 9.000806 ->exp:2-> val0[900]val1[806]
>>>> + * 0.174535 ->exp:2-> val0[17]val1[4535]
>>>> + * 1.001745 ->exp:0-> val0[1]val1[1745]
>>>> + * 1.001745 ->exp:2-> val0[100]val1[1745]
>>>> + * 1.001745 ->exp:4-> val0[10017]val1[45]
>>>> + * 9.806650 ->exp:-2-> val0[0]val1[98066]
>>> It took me a while to get what you meant here, perhaps for the examples it
>>> is worth showing the actual value directly as well. Maybe.
>>> 9.806650 exp:2->980.6650 -> val0[980]val1[665000] (note the above is I think
>>> incorrect due to lack of trailing zeros on val1.
>>>> + */
>>>> +static void adjust_exponent_micro(int *val0, int *val1, int scale0,
>>>> +                  int scale1, int exp)
>>>> +{
>>>> +    int i;
>>>> +    int x;
>>>> +    int res;
>>>> +    int rem;
>>>> +
>>>> +    if (exp > 0) {
>>>> +        *val0 = scale0 * pow_10(exp);
>>>> +        res = 0;
>>>> +        if (exp > 6) {
>>>> +            *val1 = 0;
>>>> +            return;
>>>> +        }
>>> so if example 1 above..
>>> val0 = 900 as desired.
>>> i  = 0;
>>> sca1e1 = 806650
>>> x = 806650/100000 = 8;
>>> res = 80;
>>> scale1 = 06650
>>> i = 1
>>> x = 06650/10000 = 0;
>>> res = 80;
>>>  so 980. Good.
>>>> +        for (i = 0; i < exp; ++i) {
>>>> +            x = scale1 / pow_10(5 - i);
>>>> +            res += (pow_10(exp - 1 - i) * x);
>>>> +            scale1 = scale1 % pow_10(5 - i);
>>>> +        }
>>>> +        *val0 += res;
>>>> +            *val1 = scale1 * pow_10(exp);
>>> val1 = 665000 which is correct with the trailing zeros in val2.
>>> So your code is good but examples need those zeros!
>> Impressive, Absolutely great review. I will correct comments in the next version.
> Given this was the only issue in the patch set I'll just fix it up as I merge
> it.
>
> It's been a couple of weeks an noone else has chipped in on this series, so
> I'm taking it now.
>
>
>>
>> Thanks,
>> Srinivas
>>>
>>>> +    } else if (exp < 0) {
>>>> +        exp = abs(exp);
>>>> +        if (exp > 6) {
>>>> +            *val0 = *val1 = 0;
>>>> +            return;
>>>> +        }
>>>> +        *val0 = scale0 / pow_10(exp);
>>>> +        rem = scale0 % pow_10(exp);
>>>> +        res = 0;
>>>> +        for (i = 0; i < (6 - exp); ++i) {
>>>> +            x = scale1 / pow_10(5 - i);
>>>> +            res += (pow_10(5 - exp - i) * x);
>>>> +            scale1 = scale1 % pow_10(5 - i);
>>>> +        }
>>>> +        *val1 = rem * pow_10(6 - exp) + res;
>>>> +    } else {
>>>> +        *val0 = scale0;
>>>> +        *val1 = scale1;
>>>> +    }
>>>> +}
>>>> +
>>>> +int hid_sensor_format_scale(u32 usage_id,
>>>> +            struct hid_sensor_hub_attribute_info *attr_info,
>>>> +            int *val0, int *val1)
>>>> +{
>>>> +    int i;
>>>> +    int exp;
>>>> +
>>>> +    *val0 = 1;
>>>> +    *val1 = 0;
>>>> +
>>>> +    for (i = 0; ARRAY_SIZE(unit_conversion); ++i) {
>>>> +        if (unit_conversion[i].usage_id == usage_id &&
>>>> +            unit_conversion[i].unit == attr_info->units) {
>>>> +            exp  = hid_sensor_convert_exponent(
>>>> +                        attr_info->unit_expo);
>>>> +            adjust_exponent_micro(val0, val1,
>>>> +                    unit_conversion[i].scale_val0,
>>>> +                    unit_conversion[i].scale_val1, exp);
>>>> +            break;
>>>> +        }
>>>> +    }
>>>> +
>>>> +    return IIO_VAL_INT_PLUS_MICRO;
>>>> +}
>>>> +EXPORT_SYMBOL(hid_sensor_format_scale);
>>>> +
>>>>   int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
>>>>                       u32 usage_id,
>>>>                       struct hid_sensor_common *st)
>>>> diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
>>>> index b70cfd7..89626b2 100644
>>>> --- a/include/linux/hid-sensor-hub.h
>>>> +++ b/include/linux/hid-sensor-hub.h
>>>> @@ -223,4 +223,8 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
>>>>   int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
>>>>                   u32 report_id, int field_index, u32 usage_id);
>>>>
>>>> +int hid_sensor_format_scale(u32 usage_id,
>>>> +                struct hid_sensor_hub_attribute_info *attr_info,
>>>> +                int *val0, int *val1);
>>>> +
>>>>   #endif
>>>>
>>>
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>>
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 02/16] iio: hid-sensors: Add api to get poll value
  2014-04-18 23:22 ` [PATCH 02/16] iio: hid-sensors: Add api to get poll value Srinivas Pandruvada
@ 2014-05-03 19:34   ` Jonathan Cameron
  0 siblings, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:34 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> Added interface to get poll value in milli-seconds. This value is
> changed by changing sampling frequency. This API allows clients
> to wait for atleast some poll milli seconds before reading a new sample.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
applied to the togreg branch of iio.git

> ---
>   .../iio/common/hid-sensors/hid-sensor-attributes.c   | 20 ++++++++++++++++++++
>   include/linux/hid-sensor-hub.h                       |  2 ++
>   2 files changed, 22 insertions(+)
>
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> index 451a95b..4a533b8 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> @@ -147,6 +147,26 @@ static u32 convert_to_vtf_format(int size, int exp, int val1, int val2)
>   	return value;
>   }
>
> +s32 hid_sensor_read_poll_value(struct hid_sensor_common *st)
> +{
> +	s32 value = 0;
> +	int ret;
> +
> +	ret = sensor_hub_get_feature(st->hsdev,
> +		st->poll.report_id,
> +		st->poll.index, &value);
> +
> +	if (ret < 0 || value < 0) {
> +		return -EINVAL;
> +	} else {
> +		if (st->poll.units == HID_USAGE_SENSOR_UNITS_SECOND)
> +			value = value * 1000;
> +	}
> +
> +	return value;
> +}
> +EXPORT_SYMBOL(hid_sensor_read_poll_value);
> +
>   int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
>   				int *val1, int *val2)
>   {
> diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
> index 89626b2..88d8d63 100644
> --- a/include/linux/hid-sensor-hub.h
> +++ b/include/linux/hid-sensor-hub.h
> @@ -227,4 +227,6 @@ int hid_sensor_format_scale(u32 usage_id,
>   			    struct hid_sensor_hub_attribute_info *attr_info,
>   			    int *val0, int *val1);
>
> +s32 hid_sensor_read_poll_value(struct hid_sensor_common *st);
> +
>   #endif
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 03/16] iio: hid-sensors: Accelerometer 3D: adjust scale and offset
  2014-04-18 23:22 ` [PATCH 03/16] iio: hid-sensors: Accelerometer 3D: adjust scale and offset Srinivas Pandruvada
@ 2014-05-03 19:35   ` Jonathan Cameron
  0 siblings, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:35 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> Using units and unit exponent to calculate scale which is compliant
> to IIO ABI.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Applied to the togreg branch of iio.git
Note I'll push this out as testing as normal, to allow the autobuilders to
play.
> ---
>   drivers/iio/accel/hid-sensor-accel-3d.c | 17 +++++++++++++----
>   1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
> index 3dcdbad..ca50a91 100644
> --- a/drivers/iio/accel/hid-sensor-accel-3d.c
> +++ b/drivers/iio/accel/hid-sensor-accel-3d.c
> @@ -42,6 +42,10 @@ struct accel_3d_state {
>   	struct hid_sensor_common common_attributes;
>   	struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX];
>   	u32 accel_val[ACCEL_3D_CHANNEL_MAX];
> +	int scale_pre_decml;
> +	int scale_post_decml;
> +	int scale_precision;
> +	int value_offset;
>   };
>
>   static const u32 accel_3d_addresses[ACCEL_3D_CHANNEL_MAX] = {
> @@ -123,12 +127,12 @@ static int accel_3d_read_raw(struct iio_dev *indio_dev,
>   		ret_type = IIO_VAL_INT;
>   		break;
>   	case IIO_CHAN_INFO_SCALE:
> -		*val = accel_state->accel[CHANNEL_SCAN_INDEX_X].units;
> -		ret_type = IIO_VAL_INT;
> +		*val = accel_state->scale_pre_decml;
> +		*val2 = accel_state->scale_post_decml;
> +		ret_type = accel_state->scale_precision;
>   		break;
>   	case IIO_CHAN_INFO_OFFSET:
> -		*val = hid_sensor_convert_exponent(
> -			accel_state->accel[CHANNEL_SCAN_INDEX_X].unit_expo);
> +		*val = accel_state->value_offset;
>   		ret_type = IIO_VAL_INT;
>   		break;
>   	case IIO_CHAN_INFO_SAMP_FREQ:
> @@ -262,6 +266,11 @@ static int accel_3d_parse_report(struct platform_device *pdev,
>   			st->accel[1].index, st->accel[1].report_id,
>   			st->accel[2].index, st->accel[2].report_id);
>
> +	st->scale_precision = hid_sensor_format_scale(
> +				HID_USAGE_SENSOR_ACCEL_3D,
> +				&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,
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 04/16] iio: hid-sensors: Gyro 3D : adjust scale and offset
  2014-04-18 23:22 ` [PATCH 04/16] iio: hid-sensors: Gyro 3D : " Srinivas Pandruvada
@ 2014-05-03 19:35   ` Jonathan Cameron
  0 siblings, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:35 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> Using units and unit exponent to calculate scale which is compliant
> to IIO ABI.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Applied to the togreg branch of iio.git

Thanks,
> ---
>   drivers/iio/gyro/hid-sensor-gyro-3d.c | 17 +++++++++++++----
>   1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
> index 59d6bc3..53ac060 100644
> --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
> +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
> @@ -42,6 +42,10 @@ struct gyro_3d_state {
>   	struct hid_sensor_common common_attributes;
>   	struct hid_sensor_hub_attribute_info gyro[GYRO_3D_CHANNEL_MAX];
>   	u32 gyro_val[GYRO_3D_CHANNEL_MAX];
> +	int scale_pre_decml;
> +	int scale_post_decml;
> +	int scale_precision;
> +	int value_offset;
>   };
>
>   static const u32 gyro_3d_addresses[GYRO_3D_CHANNEL_MAX] = {
> @@ -123,12 +127,12 @@ static int gyro_3d_read_raw(struct iio_dev *indio_dev,
>   		ret_type = IIO_VAL_INT;
>   		break;
>   	case IIO_CHAN_INFO_SCALE:
> -		*val = gyro_state->gyro[CHANNEL_SCAN_INDEX_X].units;
> -		ret_type = IIO_VAL_INT;
> +		*val = gyro_state->scale_pre_decml;
> +		*val2 = gyro_state->scale_post_decml;
> +		ret_type = gyro_state->scale_precision;
>   		break;
>   	case IIO_CHAN_INFO_OFFSET:
> -		*val = hid_sensor_convert_exponent(
> -			gyro_state->gyro[CHANNEL_SCAN_INDEX_X].unit_expo);
> +		*val = gyro_state->value_offset;
>   		ret_type = IIO_VAL_INT;
>   		break;
>   	case IIO_CHAN_INFO_SAMP_FREQ:
> @@ -262,6 +266,11 @@ static int gyro_3d_parse_report(struct platform_device *pdev,
>   			st->gyro[1].index, st->gyro[1].report_id,
>   			st->gyro[2].index, st->gyro[2].report_id);
>
> +	st->scale_precision = hid_sensor_format_scale(
> +				HID_USAGE_SENSOR_GYRO_3D,
> +				&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,
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 05/16] iio: hid-sensors: ALS: adjust scale and offset
  2014-04-18 23:22 ` [PATCH 05/16] iio: hid-sensors: ALS: " Srinivas Pandruvada
@ 2014-05-03 19:36   ` Jonathan Cameron
  0 siblings, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:36 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> Using units and unit exponent to calculate scale which is compliant
> to IIO ABI.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Applied to the togreg branch of iio.git

Thanks,
> ---
>   drivers/iio/light/hid-sensor-als.c | 17 +++++++++++++----
>   1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
> index 621541f..39b50be 100644
> --- a/drivers/iio/light/hid-sensor-als.c
> +++ b/drivers/iio/light/hid-sensor-als.c
> @@ -37,6 +37,10 @@ struct als_state {
>   	struct hid_sensor_common common_attributes;
>   	struct hid_sensor_hub_attribute_info als_illum;
>   	u32 illum;
> +	int scale_pre_decml;
> +	int scale_post_decml;
> +	int scale_precision;
> +	int value_offset;
>   };
>
>   /* Channel definitions */
> @@ -102,12 +106,12 @@ static int als_read_raw(struct iio_dev *indio_dev,
>   		ret_type = IIO_VAL_INT;
>   		break;
>   	case IIO_CHAN_INFO_SCALE:
> -		*val = als_state->als_illum.units;
> -		ret_type = IIO_VAL_INT;
> +		*val = als_state->scale_pre_decml;
> +		*val2 = als_state->scale_post_decml;
> +		ret_type = als_state->scale_precision;
>   		break;
>   	case IIO_CHAN_INFO_OFFSET:
> -		*val = hid_sensor_convert_exponent(
> -				als_state->als_illum.unit_expo);
> +		*val = als_state->value_offset;
>   		ret_type = IIO_VAL_INT;
>   		break;
>   	case IIO_CHAN_INFO_SAMP_FREQ:
> @@ -229,6 +233,11 @@ static int als_parse_report(struct platform_device *pdev,
>   	dev_dbg(&pdev->dev, "als %x:%x\n", st->als_illum.index,
>   			st->als_illum.report_id);
>
> +	st->scale_precision = hid_sensor_format_scale(
> +				HID_USAGE_SENSOR_ALS,
> +				&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,
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 06/16] iio: hid-sensors: Compass 3D: adjust scale and offset
  2014-04-18 23:22 ` [PATCH 06/16] iio: hid-sensors: Compass 3D: " Srinivas Pandruvada
@ 2014-05-03 19:36   ` Jonathan Cameron
  0 siblings, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:36 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> Using units and unit exponent to calculate scale which is compliant
> to IIO ABI.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Applied to the togreg branch of iio.git

Thanks,
> ---
>   drivers/iio/magnetometer/hid-sensor-magn-3d.c | 17 +++++++++++++----
>   1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
> index 6d162b7..131ced0 100644
> --- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
> +++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
> @@ -42,6 +42,10 @@ struct magn_3d_state {
>   	struct hid_sensor_common common_attributes;
>   	struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX];
>   	u32 magn_val[MAGN_3D_CHANNEL_MAX];
> +	int scale_pre_decml;
> +	int scale_post_decml;
> +	int scale_precision;
> +	int value_offset;
>   };
>
>   static const u32 magn_3d_addresses[MAGN_3D_CHANNEL_MAX] = {
> @@ -124,12 +128,12 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev,
>   		ret_type = IIO_VAL_INT;
>   		break;
>   	case IIO_CHAN_INFO_SCALE:
> -		*val = magn_state->magn[CHANNEL_SCAN_INDEX_X].units;
> -		ret_type = IIO_VAL_INT;
> +		*val = magn_state->scale_pre_decml;
> +		*val2 = magn_state->scale_post_decml;
> +		ret_type = magn_state->scale_precision;
>   		break;
>   	case IIO_CHAN_INFO_OFFSET:
> -		*val = hid_sensor_convert_exponent(
> -			magn_state->magn[CHANNEL_SCAN_INDEX_X].unit_expo);
> +		*val = magn_state->value_offset;
>   		ret_type = IIO_VAL_INT;
>   		break;
>   	case IIO_CHAN_INFO_SAMP_FREQ:
> @@ -263,6 +267,11 @@ static int magn_3d_parse_report(struct platform_device *pdev,
>   			st->magn[1].index, st->magn[1].report_id,
>   			st->magn[2].index, st->magn[2].report_id);
>
> +	st->scale_precision = hid_sensor_format_scale(
> +				HID_USAGE_SENSOR_COMPASS_3D,
> +				&st->magn[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,
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 07/16] iio: hid-sensors: Inclinometer 3D: adjust scale and offset
  2014-04-18 23:22 ` [PATCH 07/16] iio: hid-sensors: Inclinometer " Srinivas Pandruvada
@ 2014-05-03 19:37   ` Jonathan Cameron
  0 siblings, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:37 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> Using units and unit exponent to calculate scale which is compliant
> to IIO ABI.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Applied to the togreg branch of iio.git

Thanks,
> ---
>   drivers/iio/orientation/hid-sensor-incl-3d.c | 17 +++++++++++++----
>   1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/orientation/hid-sensor-incl-3d.c b/drivers/iio/orientation/hid-sensor-incl-3d.c
> index 070feab..f0c465c 100644
> --- a/drivers/iio/orientation/hid-sensor-incl-3d.c
> +++ b/drivers/iio/orientation/hid-sensor-incl-3d.c
> @@ -42,6 +42,10 @@ struct incl_3d_state {
>   	struct hid_sensor_common common_attributes;
>   	struct hid_sensor_hub_attribute_info incl[INCLI_3D_CHANNEL_MAX];
>   	u32 incl_val[INCLI_3D_CHANNEL_MAX];
> +	int scale_pre_decml;
> +	int scale_post_decml;
> +	int scale_precision;
> +	int value_offset;
>   };
>
>   static const u32 incl_3d_addresses[INCLI_3D_CHANNEL_MAX] = {
> @@ -125,12 +129,12 @@ static int incl_3d_read_raw(struct iio_dev *indio_dev,
>   		ret_type = IIO_VAL_INT;
>   		break;
>   	case IIO_CHAN_INFO_SCALE:
> -		*val = incl_state->incl[CHANNEL_SCAN_INDEX_X].units;
> -		ret_type = IIO_VAL_INT;
> +		*val = incl_state->scale_pre_decml;
> +		*val2 = incl_state->scale_post_decml;
> +		ret_type = incl_state->scale_precision;
>   		break;
>   	case IIO_CHAN_INFO_OFFSET:
> -		*val = hid_sensor_convert_exponent(
> -			incl_state->incl[CHANNEL_SCAN_INDEX_X].unit_expo);
> +		*val = incl_state->value_offset;
>   		ret_type = IIO_VAL_INT;
>   		break;
>   	case IIO_CHAN_INFO_SAMP_FREQ:
> @@ -279,6 +283,11 @@ static int incl_3d_parse_report(struct platform_device *pdev,
>   			st->incl[1].index, st->incl[1].report_id,
>   			st->incl[2].index, st->incl[2].report_id);
>
> +	st->scale_precision = hid_sensor_format_scale(
> +				HID_USAGE_SENSOR_INCLINOMETER_3D,
> +				&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,
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 08/16] iio: hid-sensors: Pressure:  adjust scale and offset
  2014-04-18 23:22 ` [PATCH 08/16] iio: hid-sensors: Pressure: " Srinivas Pandruvada
@ 2014-05-03 19:37   ` Jonathan Cameron
  0 siblings, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:37 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> Using units and unit exponent to calculate scale which is compliant
> to IIO ABI.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Applied
> ---
>   drivers/iio/pressure/hid-sensor-press.c | 17 +++++++++++++----
>   1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/pressure/hid-sensor-press.c b/drivers/iio/pressure/hid-sensor-press.c
> index e0e6409..ff69da4 100644
> --- a/drivers/iio/pressure/hid-sensor-press.c
> +++ b/drivers/iio/pressure/hid-sensor-press.c
> @@ -36,6 +36,10 @@ struct press_state {
>   	struct hid_sensor_common common_attributes;
>   	struct hid_sensor_hub_attribute_info press_attr;
>   	u32 press_data;
> +	int scale_pre_decml;
> +	int scale_post_decml;
> +	int scale_precision;
> +	int value_offset;
>   };
>
>   /* Channel definitions */
> @@ -102,12 +106,12 @@ static int press_read_raw(struct iio_dev *indio_dev,
>   		ret_type = IIO_VAL_INT;
>   		break;
>   	case IIO_CHAN_INFO_SCALE:
> -		*val = press_state->press_attr.units;
> -		ret_type = IIO_VAL_INT;
> +		*val = press_state->scale_pre_decml;
> +		*val2 = press_state->scale_post_decml;
> +		ret_type = press_state->scale_precision;
>   		break;
>   	case IIO_CHAN_INFO_OFFSET:
> -		*val = hid_sensor_convert_exponent(
> -				press_state->press_attr.unit_expo);
> +		*val = press_state->value_offset;
>   		ret_type = IIO_VAL_INT;
>   		break;
>   	case IIO_CHAN_INFO_SAMP_FREQ:
> @@ -229,6 +233,11 @@ static int press_parse_report(struct platform_device *pdev,
>   	dev_dbg(&pdev->dev, "press %x:%x\n", st->press_attr.index,
>   			st->press_attr.report_id);
>
> +	st->scale_precision = hid_sensor_format_scale(
> +				HID_USAGE_SENSOR_PRESSURE,
> +				&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,
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 09/16] iio: hid-sensors: Add API to power on/off
  2014-04-18 23:22 ` [PATCH 09/16] iio: hid-sensors: Add API to power on/off Srinivas Pandruvada
@ 2014-05-03 19:38   ` Jonathan Cameron
  0 siblings, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:38 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> Added an API to allow client drivers to turn ON and OFF sensors for
> quick read. Added data_read as counting varaible instead of boolean,
> so that sensor is powered off only when last user released it.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Applied to the togreg branch of iio.git

Thanks,
> ---
>   drivers/iio/accel/hid-sensor-accel-3d.c             |  7 +++----
>   drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 17 +++++++++++++----
>   drivers/iio/common/hid-sensors/hid-sensor-trigger.h |  1 +
>   drivers/iio/gyro/hid-sensor-gyro-3d.c               |  7 +++----
>   drivers/iio/light/hid-sensor-als.c                  |  7 +++----
>   drivers/iio/light/hid-sensor-prox.c                 |  7 +++----
>   drivers/iio/magnetometer/hid-sensor-magn-3d.c       |  7 +++----
>   drivers/iio/orientation/hid-sensor-incl-3d.c        |  7 +++----
>   drivers/iio/orientation/hid-sensor-rotation.c       |  8 +++-----
>   drivers/iio/pressure/hid-sensor-press.c             |  7 +++----
>   include/linux/hid-sensor-hub.h                      |  2 +-
>   11 files changed, 39 insertions(+), 38 deletions(-)
>
> diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
> index ca50a91..cf61c87 100644
> --- a/drivers/iio/accel/hid-sensor-accel-3d.c
> +++ b/drivers/iio/accel/hid-sensor-accel-3d.c
> @@ -201,9 +201,8 @@ static int accel_3d_proc_event(struct hid_sensor_hub_device *hsdev,
>   	struct iio_dev *indio_dev = platform_get_drvdata(priv);
>   	struct accel_3d_state *accel_state = iio_priv(indio_dev);
>
> -	dev_dbg(&indio_dev->dev, "accel_3d_proc_event [%d]\n",
> -				accel_state->common_attributes.data_ready);
> -	if (accel_state->common_attributes.data_ready)
> +	dev_dbg(&indio_dev->dev, "accel_3d_proc_event\n");
> +	if (atomic_read(&accel_state->common_attributes.data_ready))
>   		hid_sensor_push_data(indio_dev,
>   				accel_state->accel_val,
>   				sizeof(accel_state->accel_val));
> @@ -342,7 +341,7 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
>   		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
>   		goto error_free_dev_mem;
>   	}
> -	accel_state->common_attributes.data_ready = false;
> +	atomic_set(&accel_state->common_attributes.data_ready, 0);
>   	ret = hid_sensor_setup_trigger(indio_dev, name,
>   					&accel_state->common_attributes);
>   	if (ret < 0) {
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> index dbefbda..73282ce 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> @@ -28,16 +28,17 @@
>   #include <linux/iio/sysfs.h>
>   #include "hid-sensor-trigger.h"
>
> -static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
> -						bool state)
> +int hid_sensor_power_state(struct hid_sensor_common *st, bool state)
>   {
> -	struct hid_sensor_common *st = iio_trigger_get_drvdata(trig);
>   	int state_val;
>   	int report_val;
>
>   	if (state) {
>   		if (sensor_hub_device_open(st->hsdev))
>   			return -EIO;
> +
> +		atomic_inc(&st->data_ready);
> +
>   		state_val = hid_sensor_get_usage_index(st->hsdev,
>   			st->power_state.report_id,
>   			st->power_state.index,
> @@ -47,6 +48,8 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
>   			st->report_state.index,
>   			HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM);
>   	} else {
> +		if (!atomic_dec_and_test(&st->data_ready))
> +			return 0;
>   		sensor_hub_device_close(st->hsdev);
>   		state_val = hid_sensor_get_usage_index(st->hsdev,
>   			st->power_state.report_id,
> @@ -57,7 +60,6 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
>   			st->report_state.index,
>   			HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM);
>   	}
> -	st->data_ready = state;
>
>   	if (state_val >= 0) {
>   		state_val += st->power_state.logical_minimum;
> @@ -75,6 +77,13 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
>
>   	return 0;
>   }
> +EXPORT_SYMBOL(hid_sensor_power_state);
> +
> +static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
> +						bool state)
> +{
> +	return hid_sensor_power_state(iio_trigger_get_drvdata(trig), state);
> +}
>
>   void hid_sensor_remove_trigger(struct hid_sensor_common *attrb)
>   {
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
> index ca02f78..0f8e78c 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
> @@ -22,5 +22,6 @@
>   int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
>   				struct hid_sensor_common *attrb);
>   void hid_sensor_remove_trigger(struct hid_sensor_common *attrb);
> +int hid_sensor_power_state(struct hid_sensor_common *st, bool state);
>
>   #endif
> diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
> index 53ac060..392c30b 100644
> --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
> +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
> @@ -201,9 +201,8 @@ static int gyro_3d_proc_event(struct hid_sensor_hub_device *hsdev,
>   	struct iio_dev *indio_dev = platform_get_drvdata(priv);
>   	struct gyro_3d_state *gyro_state = iio_priv(indio_dev);
>
> -	dev_dbg(&indio_dev->dev, "gyro_3d_proc_event [%d]\n",
> -				gyro_state->common_attributes.data_ready);
> -	if (gyro_state->common_attributes.data_ready)
> +	dev_dbg(&indio_dev->dev, "gyro_3d_proc_event\n");
> +	if (atomic_read(&gyro_state->common_attributes.data_ready))
>   		hid_sensor_push_data(indio_dev,
>   				gyro_state->gyro_val,
>   				sizeof(gyro_state->gyro_val));
> @@ -339,7 +338,7 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)
>   		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
>   		goto error_free_dev_mem;
>   	}
> -	gyro_state->common_attributes.data_ready = false;
> +	atomic_set(&gyro_state->common_attributes.data_ready, 0);
>   	ret = hid_sensor_setup_trigger(indio_dev, name,
>   					&gyro_state->common_attributes);
>   	if (ret < 0) {
> diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
> index 39b50be..e124b39 100644
> --- a/drivers/iio/light/hid-sensor-als.c
> +++ b/drivers/iio/light/hid-sensor-als.c
> @@ -180,9 +180,8 @@ static int als_proc_event(struct hid_sensor_hub_device *hsdev,
>   	struct iio_dev *indio_dev = platform_get_drvdata(priv);
>   	struct als_state *als_state = iio_priv(indio_dev);
>
> -	dev_dbg(&indio_dev->dev, "als_proc_event [%d]\n",
> -				als_state->common_attributes.data_ready);
> -	if (als_state->common_attributes.data_ready)
> +	dev_dbg(&indio_dev->dev, "als_proc_event\n");
> +	if (atomic_read(&als_state->common_attributes.data_ready))
>   		hid_sensor_push_data(indio_dev,
>   				&als_state->illum,
>   				sizeof(als_state->illum));
> @@ -305,7 +304,7 @@ static int hid_als_probe(struct platform_device *pdev)
>   		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
>   		goto error_free_dev_mem;
>   	}
> -	als_state->common_attributes.data_ready = false;
> +	atomic_set(&als_state->common_attributes.data_ready, 0);
>   	ret = hid_sensor_setup_trigger(indio_dev, name,
>   				&als_state->common_attributes);
>   	if (ret < 0) {
> diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c
> index 1894ab1..07e98ec8 100644
> --- a/drivers/iio/light/hid-sensor-prox.c
> +++ b/drivers/iio/light/hid-sensor-prox.c
> @@ -176,9 +176,8 @@ static int prox_proc_event(struct hid_sensor_hub_device *hsdev,
>   	struct iio_dev *indio_dev = platform_get_drvdata(priv);
>   	struct prox_state *prox_state = iio_priv(indio_dev);
>
> -	dev_dbg(&indio_dev->dev, "prox_proc_event [%d]\n",
> -				prox_state->common_attributes.data_ready);
> -	if (prox_state->common_attributes.data_ready)
> +	dev_dbg(&indio_dev->dev, "prox_proc_event\n");
> +	if (atomic_read(&prox_state->common_attributes.data_ready))
>   		hid_sensor_push_data(indio_dev,
>   				&prox_state->human_presence,
>   				sizeof(prox_state->human_presence));
> @@ -297,7 +296,7 @@ static int hid_prox_probe(struct platform_device *pdev)
>   		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
>   		goto error_free_dev_mem;
>   	}
> -	prox_state->common_attributes.data_ready = false;
> +	atomic_set(&prox_state->common_attributes.data_ready, 0);
>   	ret = hid_sensor_setup_trigger(indio_dev, name,
>   				&prox_state->common_attributes);
>   	if (ret) {
> diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
> index 131ced0..54eea6a 100644
> --- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
> +++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
> @@ -202,9 +202,8 @@ static int magn_3d_proc_event(struct hid_sensor_hub_device *hsdev,
>   	struct iio_dev *indio_dev = platform_get_drvdata(priv);
>   	struct magn_3d_state *magn_state = iio_priv(indio_dev);
>
> -	dev_dbg(&indio_dev->dev, "magn_3d_proc_event [%d]\n",
> -				magn_state->common_attributes.data_ready);
> -	if (magn_state->common_attributes.data_ready)
> +	dev_dbg(&indio_dev->dev, "magn_3d_proc_event\n");
> +	if (atomic_read(&magn_state->common_attributes.data_ready))
>   		hid_sensor_push_data(indio_dev,
>   				magn_state->magn_val,
>   				sizeof(magn_state->magn_val));
> @@ -343,7 +342,7 @@ static int hid_magn_3d_probe(struct platform_device *pdev)
>   		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
>   		goto error_free_dev_mem;
>   	}
> -	magn_state->common_attributes.data_ready = false;
> +	atomic_set(&magn_state->common_attributes.data_ready, 0);
>   	ret = hid_sensor_setup_trigger(indio_dev, name,
>   					&magn_state->common_attributes);
>   	if (ret < 0) {
> diff --git a/drivers/iio/orientation/hid-sensor-incl-3d.c b/drivers/iio/orientation/hid-sensor-incl-3d.c
> index f0c465c..bf11678 100644
> --- a/drivers/iio/orientation/hid-sensor-incl-3d.c
> +++ b/drivers/iio/orientation/hid-sensor-incl-3d.c
> @@ -200,9 +200,8 @@ static int incl_3d_proc_event(struct hid_sensor_hub_device *hsdev,
>   	struct iio_dev *indio_dev = platform_get_drvdata(priv);
>   	struct incl_3d_state *incl_state = iio_priv(indio_dev);
>
> -	dev_dbg(&indio_dev->dev, "incl_3d_proc_event [%d]\n",
> -				incl_state->common_attributes.data_ready);
> -	if (incl_state->common_attributes.data_ready)
> +	dev_dbg(&indio_dev->dev, "incl_3d_proc_event\n");
> +	if (atomic_read(&incl_state->common_attributes.data_ready))
>   		hid_sensor_push_data(indio_dev,
>   				(u8 *)incl_state->incl_val,
>   				sizeof(incl_state->incl_val));
> @@ -358,7 +357,7 @@ static int hid_incl_3d_probe(struct platform_device *pdev)
>   		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
>   		goto error_free_dev_mem;
>   	}
> -	incl_state->common_attributes.data_ready = false;
> +	atomic_set(&incl_state->common_attributes.data_ready, 0);
>   	ret = hid_sensor_setup_trigger(indio_dev, name,
>   					&incl_state->common_attributes);
>   	if (ret) {
> diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c
> index 51387bb..dccf848 100644
> --- a/drivers/iio/orientation/hid-sensor-rotation.c
> +++ b/drivers/iio/orientation/hid-sensor-rotation.c
> @@ -145,10 +145,8 @@ static int dev_rot_proc_event(struct hid_sensor_hub_device *hsdev,
>   	struct iio_dev *indio_dev = platform_get_drvdata(priv);
>   	struct dev_rot_state *rot_state = iio_priv(indio_dev);
>
> -	dev_dbg(&indio_dev->dev, "dev_rot_proc_event [%d]\n",
> -				rot_state->common_attributes.data_ready);
> -
> -	if (rot_state->common_attributes.data_ready)
> +	dev_dbg(&indio_dev->dev, "dev_rot_proc_event\n");
> +	if (atomic_read(&rot_state->common_attributes.data_ready))
>   		hid_sensor_push_data(indio_dev,
>   				(u8 *)rot_state->sampled_vals,
>   				sizeof(rot_state->sampled_vals));
> @@ -272,7 +270,7 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
>   		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
>   		return ret;
>   	}
> -	rot_state->common_attributes.data_ready = false;
> +	atomic_set(&rot_state->common_attributes.data_ready, 0);
>   	ret = hid_sensor_setup_trigger(indio_dev, name,
>   					&rot_state->common_attributes);
>   	if (ret) {
> diff --git a/drivers/iio/pressure/hid-sensor-press.c b/drivers/iio/pressure/hid-sensor-press.c
> index ff69da4..39df50c 100644
> --- a/drivers/iio/pressure/hid-sensor-press.c
> +++ b/drivers/iio/pressure/hid-sensor-press.c
> @@ -180,9 +180,8 @@ static int press_proc_event(struct hid_sensor_hub_device *hsdev,
>   	struct iio_dev *indio_dev = platform_get_drvdata(priv);
>   	struct press_state *press_state = iio_priv(indio_dev);
>
> -	dev_dbg(&indio_dev->dev, "press_proc_event [%d]\n",
> -				press_state->common_attributes.data_ready);
> -	if (press_state->common_attributes.data_ready)
> +	dev_dbg(&indio_dev->dev, "press_proc_event\n");
> +	if (atomic_read(&press_state->common_attributes.data_ready))
>   		hid_sensor_push_data(indio_dev,
>   				&press_state->press_data,
>   				sizeof(press_state->press_data));
> @@ -307,7 +306,7 @@ static int hid_press_probe(struct platform_device *pdev)
>   		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
>   		goto error_free_dev_mem;
>   	}
> -	press_state->common_attributes.data_ready = false;
> +	atomic_set(&press_state->common_attributes.data_ready, 0);
>   	ret = hid_sensor_setup_trigger(indio_dev, name,
>   				&press_state->common_attributes);
>   	if (ret) {
> diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
> index 88d8d63..51f7cca 100644
> --- a/include/linux/hid-sensor-hub.h
> +++ b/include/linux/hid-sensor-hub.h
> @@ -189,7 +189,7 @@ struct hid_sensor_common {
>   	struct hid_sensor_hub_device *hsdev;
>   	struct platform_device *pdev;
>   	unsigned usage_id;
> -	bool data_ready;
> +	atomic_t data_ready;
>   	struct iio_trigger *trigger;
>   	struct hid_sensor_hub_attribute_info poll;
>   	struct hid_sensor_hub_attribute_info report_state;
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 10/16] iio: hid-sensors: Accelerometer 3D: Raw read support
  2014-04-18 23:22 ` [PATCH 10/16] iio: hid-sensors: Accelerometer 3D: Raw read support Srinivas Pandruvada
@ 2014-05-03 19:38   ` Jonathan Cameron
  0 siblings, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:38 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> Added support for raw reading of channel. If the sensor is powered
> off, it will turn on for reading value.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Applied to the togreg branch of iio.git

Thanks,
> ---
>   drivers/iio/accel/hid-sensor-accel-3d.c | 21 ++++++++++++++++++---
>   1 file changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
> index cf61c87..69abf91 100644
> --- a/drivers/iio/accel/hid-sensor-accel-3d.c
> +++ b/drivers/iio/accel/hid-sensor-accel-3d.c
> @@ -22,6 +22,7 @@
>   #include <linux/interrupt.h>
>   #include <linux/irq.h>
>   #include <linux/slab.h>
> +#include <linux/delay.h>
>   #include <linux/hid-sensor-hub.h>
>   #include <linux/iio/iio.h>
>   #include <linux/iio/sysfs.h>
> @@ -60,6 +61,7 @@ static const struct iio_chan_spec accel_3d_channels[] = {
>   		.type = IIO_ACCEL,
>   		.modified = 1,
>   		.channel2 = IIO_MOD_X,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>   		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
>   		BIT(IIO_CHAN_INFO_SCALE) |
>   		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
> @@ -69,6 +71,7 @@ static const struct iio_chan_spec accel_3d_channels[] = {
>   		.type = IIO_ACCEL,
>   		.modified = 1,
>   		.channel2 = IIO_MOD_Y,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>   		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
>   		BIT(IIO_CHAN_INFO_SCALE) |
>   		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
> @@ -78,6 +81,7 @@ static const struct iio_chan_spec accel_3d_channels[] = {
>   		.type = IIO_ACCEL,
>   		.modified = 1,
>   		.channel2 = IIO_MOD_Z,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>   		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
>   		BIT(IIO_CHAN_INFO_SCALE) |
>   		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
> @@ -108,22 +112,33 @@ static int accel_3d_read_raw(struct iio_dev *indio_dev,
>   	u32 address;
>   	int ret;
>   	int ret_type;
> +	s32 poll_value;
>
>   	*val = 0;
>   	*val2 = 0;
>   	switch (mask) {
>   	case 0:
> +		poll_value = hid_sensor_read_poll_value(
> +					&accel_state->common_attributes);
> +		if (poll_value < 0)
> +			return -EINVAL;
> +
> +		hid_sensor_power_state(&accel_state->common_attributes, true);
> +		msleep_interruptible(poll_value * 2);
>   		report_id = accel_state->accel[chan->scan_index].report_id;
>   		address = accel_3d_addresses[chan->scan_index];
>   		if (report_id >= 0)
>   			*val = sensor_hub_input_attr_get_raw_value(
> -				accel_state->common_attributes.hsdev,
> -				HID_USAGE_SENSOR_ACCEL_3D, address,
> -				report_id);
> +					accel_state->common_attributes.hsdev,
> +					HID_USAGE_SENSOR_ACCEL_3D, address,
> +					report_id);
>   		else {
>   			*val = 0;
> +			hid_sensor_power_state(&accel_state->common_attributes,
> +						 false);
>   			return -EINVAL;
>   		}
> +		hid_sensor_power_state(&accel_state->common_attributes, false);
>   		ret_type = IIO_VAL_INT;
>   		break;
>   	case IIO_CHAN_INFO_SCALE:
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 11/16] iio: hid-sensors: Gyro 3D: Raw read support
  2014-04-18 23:22 ` [PATCH 11/16] iio: hid-sensors: Gyro " Srinivas Pandruvada
@ 2014-05-03 19:39   ` Jonathan Cameron
  0 siblings, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:39 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> Added support for raw reading of channel. If the sensor is powered
> off, it will turn on for reading value.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Applied to the togreg branch of iio.git

Thanks,
> ---
>   drivers/iio/gyro/hid-sensor-gyro-3d.c | 21 ++++++++++++++++++---
>   1 file changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
> index 392c30b..40f4e49 100644
> --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
> +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
> @@ -22,6 +22,7 @@
>   #include <linux/interrupt.h>
>   #include <linux/irq.h>
>   #include <linux/slab.h>
> +#include <linux/delay.h>
>   #include <linux/hid-sensor-hub.h>
>   #include <linux/iio/iio.h>
>   #include <linux/iio/sysfs.h>
> @@ -60,6 +61,7 @@ static const struct iio_chan_spec gyro_3d_channels[] = {
>   		.type = IIO_ANGL_VEL,
>   		.modified = 1,
>   		.channel2 = IIO_MOD_X,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>   		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
>   		BIT(IIO_CHAN_INFO_SCALE) |
>   		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
> @@ -69,6 +71,7 @@ static const struct iio_chan_spec gyro_3d_channels[] = {
>   		.type = IIO_ANGL_VEL,
>   		.modified = 1,
>   		.channel2 = IIO_MOD_Y,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>   		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
>   		BIT(IIO_CHAN_INFO_SCALE) |
>   		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
> @@ -78,6 +81,7 @@ static const struct iio_chan_spec gyro_3d_channels[] = {
>   		.type = IIO_ANGL_VEL,
>   		.modified = 1,
>   		.channel2 = IIO_MOD_Z,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>   		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
>   		BIT(IIO_CHAN_INFO_SCALE) |
>   		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
> @@ -108,22 +112,33 @@ static int gyro_3d_read_raw(struct iio_dev *indio_dev,
>   	u32 address;
>   	int ret;
>   	int ret_type;
> +	s32 poll_value;
>
>   	*val = 0;
>   	*val2 = 0;
>   	switch (mask) {
>   	case 0:
> +		poll_value = hid_sensor_read_poll_value(
> +					&gyro_state->common_attributes);
> +		if (poll_value < 0)
> +			return -EINVAL;
> +
> +		hid_sensor_power_state(&gyro_state->common_attributes, true);
> +		msleep_interruptible(poll_value * 2);
>   		report_id = gyro_state->gyro[chan->scan_index].report_id;
>   		address = gyro_3d_addresses[chan->scan_index];
>   		if (report_id >= 0)
>   			*val = sensor_hub_input_attr_get_raw_value(
> -				gyro_state->common_attributes.hsdev,
> -				HID_USAGE_SENSOR_GYRO_3D, address,
> -				report_id);
> +					gyro_state->common_attributes.hsdev,
> +					HID_USAGE_SENSOR_GYRO_3D, address,
> +					report_id);
>   		else {
>   			*val = 0;
> +			hid_sensor_power_state(&gyro_state->common_attributes,
> +						false);
>   			return -EINVAL;
>   		}
> +		hid_sensor_power_state(&gyro_state->common_attributes, false);
>   		ret_type = IIO_VAL_INT;
>   		break;
>   	case IIO_CHAN_INFO_SCALE:
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 12/16] iio: hid-sensors: ALS: Raw read support
  2014-04-18 23:22 ` [PATCH 12/16] iio: hid-sensors: ALS: " Srinivas Pandruvada
@ 2014-05-03 19:39   ` Jonathan Cameron
  0 siblings, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:39 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> Added support for raw reading of channel. If the sensor is powered
> off, it will turn on for reading value.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Applied to the togreg branch of iio.git

Thanks,
> ---
>   drivers/iio/light/hid-sensor-als.c | 24 +++++++++++++++++++-----
>   1 file changed, 19 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
> index e124b39..f34c943 100644
> --- a/drivers/iio/light/hid-sensor-als.c
> +++ b/drivers/iio/light/hid-sensor-als.c
> @@ -22,6 +22,7 @@
>   #include <linux/interrupt.h>
>   #include <linux/irq.h>
>   #include <linux/slab.h>
> +#include <linux/delay.h>
>   #include <linux/hid-sensor-hub.h>
>   #include <linux/iio/iio.h>
>   #include <linux/iio/sysfs.h>
> @@ -49,6 +50,7 @@ static const struct iio_chan_spec als_channels[] = {
>   		.type = IIO_INTENSITY,
>   		.modified = 1,
>   		.channel2 = IIO_MOD_LIGHT_BOTH,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>   		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
>   		BIT(IIO_CHAN_INFO_SCALE) |
>   		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
> @@ -79,6 +81,7 @@ static int als_read_raw(struct iio_dev *indio_dev,
>   	u32 address;
>   	int ret;
>   	int ret_type;
> +	s32 poll_value;
>
>   	*val = 0;
>   	*val2 = 0;
> @@ -94,12 +97,23 @@ static int als_read_raw(struct iio_dev *indio_dev,
>   			report_id = -1;
>   			break;
>   		}
> -		if (report_id >= 0)
> +		if (report_id >= 0) {
> +			poll_value = hid_sensor_read_poll_value(
> +						&als_state->common_attributes);
> +			if (poll_value < 0)
> +				return -EINVAL;
> +
> +			hid_sensor_power_state(&als_state->common_attributes,
> +						true);
> +			msleep_interruptible(poll_value * 2);
> +
>   			*val = sensor_hub_input_attr_get_raw_value(
> -				als_state->common_attributes.hsdev,
> -				HID_USAGE_SENSOR_ALS, address,
> -				report_id);
> -		else {
> +					als_state->common_attributes.hsdev,
> +					HID_USAGE_SENSOR_ALS, address,
> +					report_id);
> +			hid_sensor_power_state(&als_state->common_attributes,
> +						false);
> +		} else {
>   			*val = 0;
>   			return -EINVAL;
>   		}
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 13/16] iio: hid-sensors: Proximity: Raw read support
  2014-04-18 23:22 ` [PATCH 13/16] iio: hid-sensors: Proximity: " Srinivas Pandruvada
@ 2014-05-03 19:40   ` Jonathan Cameron
  0 siblings, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:40 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> Added support for raw reading of channel. If the sensor is powered
> off, it will turn on for reading value.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Applied.
> ---
>   drivers/iio/light/hid-sensor-prox.c | 18 ++++++++++++++++--
>   1 file changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c
> index 07e98ec8..d203ef4 100644
> --- a/drivers/iio/light/hid-sensor-prox.c
> +++ b/drivers/iio/light/hid-sensor-prox.c
> @@ -21,6 +21,7 @@
>   #include <linux/interrupt.h>
>   #include <linux/irq.h>
>   #include <linux/slab.h>
> +#include <linux/delay.h>
>   #include <linux/hid-sensor-hub.h>
>   #include <linux/iio/iio.h>
>   #include <linux/iio/sysfs.h>
> @@ -75,6 +76,7 @@ static int prox_read_raw(struct iio_dev *indio_dev,
>   	u32 address;
>   	int ret;
>   	int ret_type;
> +	s32 poll_value;
>
>   	*val = 0;
>   	*val2 = 0;
> @@ -90,12 +92,24 @@ static int prox_read_raw(struct iio_dev *indio_dev,
>   			report_id = -1;
>   			break;
>   		}
> -		if (report_id >= 0)
> +		if (report_id >= 0) {
> +			poll_value = hid_sensor_read_poll_value(
> +					&prox_state->common_attributes);
> +			if (poll_value < 0)
> +				return -EINVAL;
> +
> +			hid_sensor_power_state(&prox_state->common_attributes,
> +						true);
> +
> +			msleep_interruptible(poll_value * 2);
> +
>   			*val = sensor_hub_input_attr_get_raw_value(
>   				prox_state->common_attributes.hsdev,
>   				HID_USAGE_SENSOR_PROX, address,
>   				report_id);
> -		else {
> +			hid_sensor_power_state(&prox_state->common_attributes,
> +						false);
> +		} else {
>   			*val = 0;
>   			return -EINVAL;
>   		}
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 14/16] iio: hid-sensors: Compass 3D: Raw read support
  2014-04-18 23:22 ` [PATCH 14/16] iio: hid-sensors: Compass 3D: " Srinivas Pandruvada
@ 2014-05-03 19:41   ` Jonathan Cameron
  0 siblings, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:41 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> Added support for raw reading of channel. If the sensor is powered
> off, it will turn on for reading value
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Applied to the togreg branch of iio.git

Thanks,
> ---
>   drivers/iio/magnetometer/hid-sensor-magn-3d.c | 16 ++++++++++++++++
>   1 file changed, 16 insertions(+)
>
> diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
> index 54eea6a..41cf29e 100644
> --- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
> +++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
> @@ -22,6 +22,7 @@
>   #include <linux/interrupt.h>
>   #include <linux/irq.h>
>   #include <linux/slab.h>
> +#include <linux/delay.h>
>   #include <linux/hid-sensor-hub.h>
>   #include <linux/iio/iio.h>
>   #include <linux/iio/sysfs.h>
> @@ -60,6 +61,7 @@ static const struct iio_chan_spec magn_3d_channels[] = {
>   		.type = IIO_MAGN,
>   		.modified = 1,
>   		.channel2 = IIO_MOD_X,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>   		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
>   		BIT(IIO_CHAN_INFO_SCALE) |
>   		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
> @@ -69,6 +71,7 @@ static const struct iio_chan_spec magn_3d_channels[] = {
>   		.type = IIO_MAGN,
>   		.modified = 1,
>   		.channel2 = IIO_MOD_Y,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>   		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
>   		BIT(IIO_CHAN_INFO_SCALE) |
>   		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
> @@ -78,6 +81,7 @@ static const struct iio_chan_spec magn_3d_channels[] = {
>   		.type = IIO_MAGN,
>   		.modified = 1,
>   		.channel2 = IIO_MOD_Z,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>   		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
>   		BIT(IIO_CHAN_INFO_SCALE) |
>   		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
> @@ -108,11 +112,20 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev,
>   	u32 address;
>   	int ret;
>   	int ret_type;
> +	s32 poll_value;
>
>   	*val = 0;
>   	*val2 = 0;
>   	switch (mask) {
>   	case 0:
> +		poll_value = hid_sensor_read_poll_value(
> +					&magn_state->common_attributes);
> +		if (poll_value < 0)
> +				return -EINVAL;
> +
> +		hid_sensor_power_state(&magn_state->common_attributes, true);
> +		msleep_interruptible(poll_value * 2);
> +
>   		report_id =
>   			magn_state->magn[chan->scan_index].report_id;
>   		address = magn_3d_addresses[chan->scan_index];
> @@ -123,8 +136,11 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev,
>   				report_id);
>   		else {
>   			*val = 0;
> +			hid_sensor_power_state(&magn_state->common_attributes,
> +						false);
>   			return -EINVAL;
>   		}
> +		hid_sensor_power_state(&magn_state->common_attributes, false);
>   		ret_type = IIO_VAL_INT;
>   		break;
>   	case IIO_CHAN_INFO_SCALE:
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 15/16] iio: hid-sensors: Inclinometer 3D: Raw read support
  2014-04-18 23:22 ` [PATCH 15/16] iio: hid-sensors: Inclinometer " Srinivas Pandruvada
@ 2014-05-03 19:41   ` Jonathan Cameron
  0 siblings, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:41 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 19/04/14 00:22, Srinivas Pandruvada wrote:
> Added support for raw reading of channel. If the sensor is powered
> off, it will turn on for reading value.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Applied to the togreg branch of iio.git

Thanks
> ---
>   drivers/iio/orientation/hid-sensor-incl-3d.c | 13 +++++++++++++
>   1 file changed, 13 insertions(+)
>
> diff --git a/drivers/iio/orientation/hid-sensor-incl-3d.c b/drivers/iio/orientation/hid-sensor-incl-3d.c
> index bf11678..2478f6c 100644
> --- a/drivers/iio/orientation/hid-sensor-incl-3d.c
> +++ b/drivers/iio/orientation/hid-sensor-incl-3d.c
> @@ -22,6 +22,7 @@
>   #include <linux/interrupt.h>
>   #include <linux/irq.h>
>   #include <linux/slab.h>
> +#include <linux/delay.h>
>   #include <linux/hid-sensor-hub.h>
>   #include <linux/iio/iio.h>
>   #include <linux/iio/sysfs.h>
> @@ -110,11 +111,20 @@ static int incl_3d_read_raw(struct iio_dev *indio_dev,
>   	int report_id = -1;
>   	u32 address;
>   	int ret_type;
> +	s32 poll_value;
>
>   	*val = 0;
>   	*val2 = 0;
>   	switch (mask) {
>   	case IIO_CHAN_INFO_RAW:
> +		poll_value = hid_sensor_read_poll_value(
> +					&incl_state->common_attributes);
> +		if (poll_value < 0)
> +			return -EINVAL;
> +
> +		hid_sensor_power_state(&incl_state->common_attributes, true);
> +		msleep_interruptible(poll_value * 2);
> +
>   		report_id =
>   			incl_state->incl[chan->scan_index].report_id;
>   		address = incl_3d_addresses[chan->scan_index];
> @@ -124,8 +134,11 @@ static int incl_3d_read_raw(struct iio_dev *indio_dev,
>   				HID_USAGE_SENSOR_INCLINOMETER_3D, address,
>   				report_id);
>   		else {
> +			hid_sensor_power_state(&incl_state->common_attributes,
> +						false);
>   			return -EINVAL;
>   		}
> +		hid_sensor_power_state(&incl_state->common_attributes, false);
>   		ret_type = IIO_VAL_INT;
>   		break;
>   	case IIO_CHAN_INFO_SCALE:
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 16/16] iio: hid-sensors: Pressure: Raw read support
  2014-04-23 21:03   ` Jonathan Cameron
@ 2014-05-03 19:45     ` Jonathan Cameron
  0 siblings, 0 replies; 41+ messages in thread
From: Jonathan Cameron @ 2014-05-03 19:45 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: linux-iio

On 23/04/14 22:03, Jonathan Cameron wrote:
> On 19/04/14 00:22, Srinivas Pandruvada wrote:
>> Added support for raw reading of channel. If the sensor is powered
>> off, it will turn on for reading value.
>>
>> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> Hi Srinivas.
>
> Looks like a good patch set.  Probably should have been 'formally'
> broken in two to separate the ABI related fixes and the new stuff.
>
> I'll let this sit for a while to garner opinions on the ABI change.
Seems no one cares so lets put it in.

All applied to the togreg branch of iio.git pushed out initially as testing.

Jonathan
>> ---
>>   drivers/iio/pressure/hid-sensor-press.c | 17 +++++++++++++++--
>>   1 file changed, 15 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/iio/pressure/hid-sensor-press.c b/drivers/iio/pressure/hid-sensor-press.c
>> index 39df50c..1cd190c 100644
>> --- a/drivers/iio/pressure/hid-sensor-press.c
>> +++ b/drivers/iio/pressure/hid-sensor-press.c
>> @@ -21,6 +21,7 @@
>>   #include <linux/interrupt.h>
>>   #include <linux/irq.h>
>>   #include <linux/slab.h>
>> +#include <linux/delay.h>
>>   #include <linux/hid-sensor-hub.h>
>>   #include <linux/iio/iio.h>
>>   #include <linux/iio/sysfs.h>
>> @@ -79,6 +80,7 @@ static int press_read_raw(struct iio_dev *indio_dev,
>>       u32 address;
>>       int ret;
>>       int ret_type;
>> +    s32 poll_value;
>>
>>       *val = 0;
>>       *val2 = 0;
>> @@ -94,12 +96,23 @@ static int press_read_raw(struct iio_dev *indio_dev,
>>               report_id = -1;
>>               break;
>>           }
>> -        if (report_id >= 0)
>> +        if (report_id >= 0) {
>> +            poll_value = hid_sensor_read_poll_value(
>> +                    &press_state->common_attributes);
>> +            if (poll_value < 0)
>> +                return -EINVAL;
>> +            hid_sensor_power_state(&press_state->common_attributes,
>> +                        true);
>> +
>> +            msleep_interruptible(poll_value * 2);
>> +
>>               *val = sensor_hub_input_attr_get_raw_value(
>>                   press_state->common_attributes.hsdev,
>>                   HID_USAGE_SENSOR_PRESSURE, address,
>>                   report_id);
>> -        else {
>> +            hid_sensor_power_state(&press_state->common_attributes,
>> +                        false);
>> +        } else {
>>               *val = 0;
>>               return -EINVAL;
>>           }
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 01/16] iio: hid-sensors: Convert units and exponent
  2014-05-03 19:24     ` Jonathan Cameron
  2014-05-03 19:32       ` Jonathan Cameron
@ 2014-05-04 14:49       ` Srinivas Pandruvada
       [not found]         ` <4102328d-88e0-441f-87c9-0b57cbc33ca5@email.android.com>
  1 sibling, 1 reply; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-05-04 14:49 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio

Hi Jonathan,

Somebody pointed me some error in magnetometer calculation, I have a 
correction,
I will submit as another patch. I was about to push second version of 
these patches.

Thanks,
Srinivas

On 05/03/2014 12:24 PM, Jonathan Cameron wrote:
> On 26/04/14 20:34, Srinivas Pandruvada wrote:
>>
>> On 04/25/2014 11:30 AM, Jonathan Cameron wrote:
>>> On 19/04/14 00:22, Srinivas Pandruvada wrote:
>>>> HID sensor hub specify a default unit and alternative units. This
>>>> along with unit exponent can be used adjust scale. This change
>>>> change HID sensor data units to IIO defined units for each
>>>> sensor type. So in this way user space can use a simply use:
>>>> "(data + offset) * scale" to get final result.
>>>>
>>>> Signed-off-by: Srinivas Pandruvada 
>>>> <srinivas.pandruvada@linux.intel.com>
>>> see inline.
> Applied to the togreg branch of iio.git with a tweaks to comments as 
> mentioned
> (please check I didn't mess them up!)
>
>>>> ---
>>>>   .../iio/common/hid-sensors/hid-sensor-attributes.c | 114 
>>>> +++++++++++++++++++++
>>>>   include/linux/hid-sensor-hub.h                     |   4 +
>>>>   2 files changed, 118 insertions(+)
>>>>
>>>> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c 
>>>> b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>>>> index 75b5473..451a95b 100644
>>>> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>>>> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>>>> @@ -26,6 +26,40 @@
>>>>   #include <linux/iio/iio.h>
>>>>   #include <linux/iio/sysfs.h>
>>>>
>>>> +struct {
>>>> +    u32 usage_id;
>>>> +    int unit; /* 0 for default others from HID sensor spec */
>>>> +    int scale_val0; /* scale, whole number */
>>>> +    int scale_val1; /* scale, fraction in micros */
>>>> +} unit_conversion[] = {
>>>> +    {HID_USAGE_SENSOR_ACCEL_3D, 0, 9, 806650},
>>>> +    {HID_USAGE_SENSOR_ACCEL_3D,
>>>> +        HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD, 1, 0},
>>>> +    {HID_USAGE_SENSOR_ACCEL_3D,
>>>> +        HID_USAGE_SENSOR_UNITS_G, 9, 806650},
>>>> +
>>>> +    {HID_USAGE_SENSOR_GYRO_3D, 0, 0, 17453},
>>>> +    {HID_USAGE_SENSOR_GYRO_3D,
>>>> +        HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND, 1, 0},
>>>> +    {HID_USAGE_SENSOR_GYRO_3D,
>>>> +        HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND, 0, 17453},
>>>> +
>>>> +    {HID_USAGE_SENSOR_COMPASS_3D, 0, 1000, 0},
>>>> +    {HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 
>>>> 0},
>>>> +
>>>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 17453, 0},
>>>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D,
>>>> +        HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453},
>>>> +    {HID_USAGE_SENSOR_INCLINOMETER_3D,
>>>> +        HID_USAGE_SENSOR_UNITS_RADIANS, 1, 0},
>>>> +
>>>> +    {HID_USAGE_SENSOR_ALS, 0, 1, 0},
>>>> +    {HID_USAGE_SENSOR_ALS, HID_USAGE_SENSOR_UNITS_LUX, 1, 0},
>>>> +
>>>> +    {HID_USAGE_SENSOR_PRESSURE, 0, 100000, 0},
>>>> +    {HID_USAGE_SENSOR_PRESSURE, HID_USAGE_SENSOR_UNITS_PASCAL, 1, 0},
>>>> +};
>>>> +
>>>>   static int pow_10(unsigned power)
>>>>   {
>>>>       int i;
>>>> @@ -209,6 +243,86 @@ int hid_sensor_write_raw_hyst_value(struct 
>>>> hid_sensor_common *st,
>>>>   }
>>>>   EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
>>>>
>>>> +/*
>>>> + * This fuction applies the unit exponent to the scale.
>>>> + * For example:
>>> Function
>>>> + * 9.806650 ->exp:2-> val0[980]val1[6650]
>>>> + * 9.000806 ->exp:2-> val0[900]val1[806]
>>>> + * 0.174535 ->exp:2-> val0[17]val1[4535]
>>>> + * 1.001745 ->exp:0-> val0[1]val1[1745]
>>>> + * 1.001745 ->exp:2-> val0[100]val1[1745]
>>>> + * 1.001745 ->exp:4-> val0[10017]val1[45]
>>>> + * 9.806650 ->exp:-2-> val0[0]val1[98066]
>>> It took me a while to get what you meant here, perhaps for the 
>>> examples it
>>> is worth showing the actual value directly as well. Maybe.
>>> 9.806650 exp:2->980.6650 -> val0[980]val1[665000] (note the above is 
>>> I think
>>> incorrect due to lack of trailing zeros on val1.
>>>> + */
>>>> +static void adjust_exponent_micro(int *val0, int *val1, int scale0,
>>>> +                  int scale1, int exp)
>>>> +{
>>>> +    int i;
>>>> +    int x;
>>>> +    int res;
>>>> +    int rem;
>>>> +
>>>> +    if (exp > 0) {
>>>> +        *val0 = scale0 * pow_10(exp);
>>>> +        res = 0;
>>>> +        if (exp > 6) {
>>>> +            *val1 = 0;
>>>> +            return;
>>>> +        }
>>> so if example 1 above..
>>> val0 = 900 as desired.
>>> i  = 0;
>>> sca1e1 = 806650
>>> x = 806650/100000 = 8;
>>> res = 80;
>>> scale1 = 06650
>>> i = 1
>>> x = 06650/10000 = 0;
>>> res = 80;
>>>  so 980. Good.
>>>> +        for (i = 0; i < exp; ++i) {
>>>> +            x = scale1 / pow_10(5 - i);
>>>> +            res += (pow_10(exp - 1 - i) * x);
>>>> +            scale1 = scale1 % pow_10(5 - i);
>>>> +        }
>>>> +        *val0 += res;
>>>> +            *val1 = scale1 * pow_10(exp);
>>> val1 = 665000 which is correct with the trailing zeros in val2.
>>> So your code is good but examples need those zeros!
>> Impressive, Absolutely great review. I will correct comments in the 
>> next version.
> Given this was the only issue in the patch set I'll just fix it up as 
> I merge
> it.
>
> It's been a couple of weeks an noone else has chipped in on this 
> series, so
> I'm taking it now.
>
>
>>
>> Thanks,
>> Srinivas
>>>
>>>> +    } else if (exp < 0) {
>>>> +        exp = abs(exp);
>>>> +        if (exp > 6) {
>>>> +            *val0 = *val1 = 0;
>>>> +            return;
>>>> +        }
>>>> +        *val0 = scale0 / pow_10(exp);
>>>> +        rem = scale0 % pow_10(exp);
>>>> +        res = 0;
>>>> +        for (i = 0; i < (6 - exp); ++i) {
>>>> +            x = scale1 / pow_10(5 - i);
>>>> +            res += (pow_10(5 - exp - i) * x);
>>>> +            scale1 = scale1 % pow_10(5 - i);
>>>> +        }
>>>> +        *val1 = rem * pow_10(6 - exp) + res;
>>>> +    } else {
>>>> +        *val0 = scale0;
>>>> +        *val1 = scale1;
>>>> +    }
>>>> +}
>>>> +
>>>> +int hid_sensor_format_scale(u32 usage_id,
>>>> +            struct hid_sensor_hub_attribute_info *attr_info,
>>>> +            int *val0, int *val1)
>>>> +{
>>>> +    int i;
>>>> +    int exp;
>>>> +
>>>> +    *val0 = 1;
>>>> +    *val1 = 0;
>>>> +
>>>> +    for (i = 0; ARRAY_SIZE(unit_conversion); ++i) {
>>>> +        if (unit_conversion[i].usage_id == usage_id &&
>>>> +            unit_conversion[i].unit == attr_info->units) {
>>>> +            exp  = hid_sensor_convert_exponent(
>>>> +                        attr_info->unit_expo);
>>>> +            adjust_exponent_micro(val0, val1,
>>>> +                    unit_conversion[i].scale_val0,
>>>> +                    unit_conversion[i].scale_val1, exp);
>>>> +            break;
>>>> +        }
>>>> +    }
>>>> +
>>>> +    return IIO_VAL_INT_PLUS_MICRO;
>>>> +}
>>>> +EXPORT_SYMBOL(hid_sensor_format_scale);
>>>> +
>>>>   int hid_sensor_parse_common_attributes(struct 
>>>> hid_sensor_hub_device *hsdev,
>>>>                       u32 usage_id,
>>>>                       struct hid_sensor_common *st)
>>>> diff --git a/include/linux/hid-sensor-hub.h 
>>>> b/include/linux/hid-sensor-hub.h
>>>> index b70cfd7..89626b2 100644
>>>> --- a/include/linux/hid-sensor-hub.h
>>>> +++ b/include/linux/hid-sensor-hub.h
>>>> @@ -223,4 +223,8 @@ int hid_sensor_read_samp_freq_value(struct 
>>>> hid_sensor_common *st,
>>>>   int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
>>>>                   u32 report_id, int field_index, u32 usage_id);
>>>>
>>>> +int hid_sensor_format_scale(u32 usage_id,
>>>> +                struct hid_sensor_hub_attribute_info *attr_info,
>>>> +                int *val0, int *val1);
>>>> +
>>>>   #endif
>>>>
>>>
>>> -- 
>>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>
>>
>
>


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 01/16] iio: hid-sensors: Convert units and exponent
       [not found]         ` <4102328d-88e0-441f-87c9-0b57cbc33ca5@email.android.com>
@ 2014-05-05  1:00           ` Srinivas Pandruvada
  0 siblings, 0 replies; 41+ messages in thread
From: Srinivas Pandruvada @ 2014-05-05  1:00 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio

[-- Attachment #1: Type: text/plain, Size: 9844 bytes --]

Hi Jonathan,

I have just sent you one patch, which can be applied to iio git tree on 
top of the currently applied patches.

Thanks,
Srinivas

On 05/04/2014 07:56 AM, Jonathan Cameron wrote:
> Cool. I will hold them for now then. Had a bored moment and not much 
> else pending so jumped the gun!
>
> On May 4, 2014 3:49:38 PM GMT+01:00, Srinivas Pandruvada 
> <srinivas.pandruvada@linux.intel.com> wrote:
>
>     Hi Jonathan,
>
>     Somebody pointed me some error in magnetometer calculation, I have a
>     correction,
>     I will submit as another patch. I was about to push second version of
>     these patches.
>
>     Thanks,
>     Srinivas
>
>     On 05/03/2014 12:24 PM, Jonathan Cameron wrote:
>
>         On 26/04/14 20:34, Srinivas Pandruvada wrote:
>
>             On 04/25/2014 11:30 AM, Jonathan Cameron wrote:
>
>                 On 19/04/14 00:22, Srinivas Pandruvada wrote:
>
>                     HID sensor hub specify a default unit and
>                     alternative units. This along with unit exponent
>                     can be used adjust scale. This change change HID
>                     sensor data units to IIO defined units for each
>                     sensor type. So in this way user space can use a
>                     simply use: "(data + offset) * scale" to get final
>                     result. Signed-off-by: Srinivas Pandruvada
>                     <srinivas.pandruvada@linux.intel.com> 
>
>                 see inline. 
>
>         Applied to the togreg branch of iio.git with a tweaks to
>         comments as mentioned (please check I didn't mess them up!)
>
>                     ---
>                     .../iio/common/hid-sensors/hid-sensor-attributes.c
>                     | 114 +++++++++++++++++++++
>                     include/linux/hid-sensor-hub.h | 4 + 2 files
>                     changed, 118 insertions(+) diff --git
>                     a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>                     b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>                     index 75b5473..451a95b 100644 ---
>                     a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>                     +++
>                     b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
>                     @@ -26,6 +26,40 @@ #include <linux/iio/iio.h>
>                     #include <linux/iio/sysfs.h> +struct { + u32
>                     usage_id; + int unit; /* 0 for default others from
>                     HID sensor spec */ + int scale_val0; /* scale,
>                     whole number */ + int scale_val1; /* scale,
>                     fraction in micros */ +} unit_conversion[] = { +
>                     {HID_USAGE_SENSOR_ACCEL_3D, 0, 9, 806650}, +
>                     {HID_USAGE_SENSOR_ACCEL_3D, +
>                     HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD, 1, 0},
>                     + {HID_USAGE_SENSOR_ACCEL_3D, +
>                     HID_USAGE_SENSOR_UNITS_G, 9, 806650}, + +
>                     {HID_USAGE_SENSOR_GYRO_3D, 0, 0, 17453}, +
>                     {HID_USAGE_SENSOR_GYRO_3D, +
>                     HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND, 1, 0},
>                     + {HID_USAGE_SENSOR_GYRO_3D, +
>                     HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND, 0,
>                     17453}, + + {HID_USAGE_SENSOR_COMPASS_3D, 0, 1000,
>                     0}, + {HID_USAGE_SENSOR_COMPASS_3D,
>                     HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0}, + +
>                     {HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 17453, 0}, +
>                     {HID_USAGE_SENSOR_INCLINOMETER_3D, +
>                     HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453}, +
>                     {HID_USAGE_SENSOR_INCLINOMETER_3D, +
>                     HID_USAGE_SENSOR_UNITS_RADIANS, 1, 0}, + +
>                     {HID_USAGE_SENSOR_ALS, 0, 1, 0}, +
>                     {HID_USAGE_SENSOR_ALS, HID_USAGE_SENSOR_UNITS_LUX,
>                     1, 0}, + + {HID_USAGE_SENSOR_PRESSURE, 0, 100000,
>                     0}, + {HID_USAGE_SENSOR_PRESSURE,
>                     HID_USAGE_SENSOR_UNITS_PASCAL, 1, 0}, +}; + static
>                     int pow_10(unsigned power) { int i; @@ -209,6
>                     +243,86 @@ int
>                     hid_sensor_write_raw_hyst_value(struct
>                     hid_sensor_common *st, }
>                     EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
>                     +/* + * This fuction applies the unit exponent to
>                     the scale. + * For example: 
>
>                 Function
>
>                     + * 9.806650 ->exp:2-> val0[980]val1[6650] + *
>                     9.000806 ->exp:2-> val0[900]val1[806] + * 0.174535
>                     ->exp:2-> val0[17]val1[4535] + * 1.001745
>                     ->exp:0-> val0[1]val1[1745] + * 1.001745 ->exp:2->
>                     val0[100]val1[1745] + * 1.001745 ->exp:4->
>                     val0[10017]val1[45] + * 9.806650 ->exp:-2->
>                     val0[0]val1[98066] 
>
>                 It took me a while to get what you meant here, perhaps
>                 for the examples it is worth showing the actual value
>                 directly as well. Maybe. 9.806650 exp:2->980.6650 ->
>                 val0[980]val1[665000] (note the above is I think
>                 incorrect due to lack of trailing zeros on val1.
>
>                     + */ +static void adjust_exponent_micro(int *val0,
>                     int *val1, int scale0, + int scale1, int exp) +{ +
>                     int i; + int x; + int res; + int rem; + + if (exp
>                     > 0) { + *val0 = scale0 * pow_10(exp); + res = 0;
>                     + if (exp > 6) { + *val1 = 0; + return; + } 
>
>                 so if example 1 above.. val0 = 900 as desired. i = 0;
>                 sca1e1 = 806650 x = 806650/100000 = 8; res = 80;
>                 scale1 = 06650 i = 1 x = 06650/10000 = 0; res = 80; so
>                 980. Good.
>
>                     + for (i = 0; i < exp; ++i) { + x = scale1 /
>                     pow_10(5 - i); + res += (pow_10(exp - 1 - i) * x);
>                     + scale1 = scale1 % pow_10(5 - i); + } + *val0 +=
>                     res; + *val1 = scale1 * pow_10(exp); 
>
>                 val1 = 665000 which is correct with the trailing zeros
>                 in val2. So your code is good but examples need those
>                 zeros! 
>
>             Impressive, Absolutely great review. I will correct
>             comments in the next version. 
>
>         Given this was the only issue in the patch set I'll just fix
>         it up as I merge it. It's been a couple of weeks an noone else
>         has chipped in on this series, so I'm taking it now.
>
>             Thanks, Srinivas
>
>                     + } else if (exp < 0) { + exp = abs(exp); + if
>                     (exp > 6) { + *val0 = *val1 = 0; + return; + } +
>                     *val0 = scale0 / pow_10(exp); + rem = scale0 %
>                     pow_10(exp); + res = 0; + for (i = 0; i < (6 -
>                     exp); ++i) { + x = scale1 / pow_10(5 - i); + res
>                     += (pow_10(5 - exp - i) * x); + scale1 = scale1 %
>                     pow_10(5 - i); + } + *val1 = rem * pow_10(6 - exp)
>                     + res; + } else { + *val0 = scale0; + *val1 =
>                     scale1; + } +} + +int hid_sensor_format_scale(u32
>                     usage_id, + struct hid_sensor_hub_attribute_info
>                     *attr_info, + int *val0, int *val1) +{ + int i; +
>                     int exp; + + *val0 = 1; + *val1 = 0; + + for (i =
>                     0; ARRAY_SIZE(unit_conversion); ++i) { + if
>                     (unit_conversion[i].usage_id == usage_id && +
>                     unit_conversion[i].unit == attr_info->units) { +
>                     exp = hid_sensor_convert_exponent( +
>                     attr_info->unit_expo); +
>                     adjust_exponent_micro(val0, val1, +
>                     unit_conversion[i].scale_val0, +
>                     unit_conversion[i].scale_val1, exp); + break; + }
>                     + } + + return IIO_VAL_INT_PLUS_MICRO; +}
>                     +EXPORT_SYMBOL(hid_sensor_format_scale); + int
>                     hid_sensor_parse_common_attributes(struct
>                     hid_sensor_hub_device *hsdev, u32 usage_id, struct
>                     hid_sensor_common *st) diff --git
>                     a/include/linux/hid-sensor-hub.h
>                     b/include/linux/hid-sensor-hub.h index
>                     b70cfd7..89626b2 100644 ---
>                     a/include/linux/hid-sensor-hub.h +++
>                     b/include/linux/hid-sensor-hub.h @@ -223,4 +223,8
>                     @@ int hid_sensor_read_samp_freq_value(struct
>                     hid_sensor_common *st, int
>                     hid_sensor_get_usage_index(struct
>                     hid_sensor_hub_device *hsdev, u32 report_id, int
>                     field_index, u32 usage_id); +int
>                     hid_sensor_format_scale(u32 usage_id, + struct
>                     hid_sensor_hub_attribute_info *attr_info, + int
>                     *val0, int *val1); + #endif
>
>                 -- To unsubscribe from this list: send the line
>                 "unsubscribe linux-iio" in the body of a message to
>                 majordomo@vger.kernel.org More majordomo info at
>                 http://vger.kernel.org/majordomo-info.html
>
>
>
>     --
>     To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>     the body of a message to majordomo@vger.kernel.org
>     More majordomo info athttp://vger.kernel.org/majordomo-info.html
>
>
> -- 
> Sent from my Android phone with K-9 Mail. Please excuse my brevity. 


[-- Attachment #2: Type: text/html, Size: 10805 bytes --]

^ permalink raw reply	[flat|nested] 41+ messages in thread

end of thread, other threads:[~2014-05-05  1:00 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-18 23:22 [PATCH 01/16] iio: hid-sensors: Convert units and exponent Srinivas Pandruvada
2014-04-18 23:22 ` [PATCH 02/16] iio: hid-sensors: Add api to get poll value Srinivas Pandruvada
2014-05-03 19:34   ` Jonathan Cameron
2014-04-18 23:22 ` [PATCH 03/16] iio: hid-sensors: Accelerometer 3D: adjust scale and offset Srinivas Pandruvada
2014-05-03 19:35   ` Jonathan Cameron
2014-04-18 23:22 ` [PATCH 04/16] iio: hid-sensors: Gyro 3D : " Srinivas Pandruvada
2014-05-03 19:35   ` Jonathan Cameron
2014-04-18 23:22 ` [PATCH 05/16] iio: hid-sensors: ALS: " Srinivas Pandruvada
2014-05-03 19:36   ` Jonathan Cameron
2014-04-18 23:22 ` [PATCH 06/16] iio: hid-sensors: Compass 3D: " Srinivas Pandruvada
2014-05-03 19:36   ` Jonathan Cameron
2014-04-18 23:22 ` [PATCH 07/16] iio: hid-sensors: Inclinometer " Srinivas Pandruvada
2014-05-03 19:37   ` Jonathan Cameron
2014-04-18 23:22 ` [PATCH 08/16] iio: hid-sensors: Pressure: " Srinivas Pandruvada
2014-05-03 19:37   ` Jonathan Cameron
2014-04-18 23:22 ` [PATCH 09/16] iio: hid-sensors: Add API to power on/off Srinivas Pandruvada
2014-05-03 19:38   ` Jonathan Cameron
2014-04-18 23:22 ` [PATCH 10/16] iio: hid-sensors: Accelerometer 3D: Raw read support Srinivas Pandruvada
2014-05-03 19:38   ` Jonathan Cameron
2014-04-18 23:22 ` [PATCH 11/16] iio: hid-sensors: Gyro " Srinivas Pandruvada
2014-05-03 19:39   ` Jonathan Cameron
2014-04-18 23:22 ` [PATCH 12/16] iio: hid-sensors: ALS: " Srinivas Pandruvada
2014-05-03 19:39   ` Jonathan Cameron
2014-04-18 23:22 ` [PATCH 13/16] iio: hid-sensors: Proximity: " Srinivas Pandruvada
2014-05-03 19:40   ` Jonathan Cameron
2014-04-18 23:22 ` [PATCH 14/16] iio: hid-sensors: Compass 3D: " Srinivas Pandruvada
2014-05-03 19:41   ` Jonathan Cameron
2014-04-18 23:22 ` [PATCH 15/16] iio: hid-sensors: Inclinometer " Srinivas Pandruvada
2014-05-03 19:41   ` Jonathan Cameron
2014-04-18 23:22 ` [PATCH 16/16] iio: hid-sensors: Pressure: " Srinivas Pandruvada
2014-04-23 21:03   ` Jonathan Cameron
2014-05-03 19:45     ` Jonathan Cameron
2014-04-23 20:57 ` [PATCH 01/16] iio: hid-sensors: Convert units and exponent Jonathan Cameron
2014-04-23 21:17   ` Srinivas Pandruvada
2014-04-25 18:34     ` Jonathan Cameron
2014-04-25 18:30 ` Jonathan Cameron
2014-04-26 19:34   ` Srinivas Pandruvada
2014-05-03 19:24     ` Jonathan Cameron
2014-05-03 19:32       ` Jonathan Cameron
2014-05-04 14:49       ` Srinivas Pandruvada
     [not found]         ` <4102328d-88e0-441f-87c9-0b57cbc33ca5@email.android.com>
2014-05-05  1:00           ` Srinivas Pandruvada

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.