linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 01/11] iio: Add some helper macros for unit conversion
@ 2012-10-15  9:35 Lars-Peter Clausen
  2012-10-15  9:35 ` [PATCH 02/11] staging:iio: Fix adis16201 channel offsets and scales Lars-Peter Clausen
                   ` (10 more replies)
  0 siblings, 11 replies; 17+ messages in thread
From: Lars-Peter Clausen @ 2012-10-15  9:35 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, drivers, Lars-Peter Clausen

Some datasheets use a different unit to specify the channel scale than what IIO
expects it to be. This patch adds two helper macros which allow to convert units
commonly used in datasheets to IIO units:

 * acceleration: g -> meter / second**2
 * angular velocity: degree (/ second) -> rad (/ second)

This makes it much more convenient to specify and also easier to verify a
channel's scale attribute.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 include/linux/iio/iio.h |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index c0ae76a..7806c24 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -618,4 +618,20 @@ static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
 };
 #endif
 
+/**
+ * IIO_DEGREE_TO_RAD() - Convert degree to rad
+ * @deg: A value in degree
+ *
+ * Returns the given value converted from degree to rad
+ */
+#define IIO_DEGREE_TO_RAD(deg) (((deg) * 314159ULL + 9000000ULL) / 18000000ULL)
+
+/**
+ * IIO_G_TO_M_S_2() - Convert g to meter / second**2
+ * @g: A value in g
+ *
+ * Returns the given value converted from g to meter / second**2
+ */
+#define IIO_G_TO_M_S_2(g) ((g) * 980665ULL / 100000ULL)
+
 #endif /* _INDUSTRIAL_IO_H_ */
-- 
1.7.10.4


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

* [PATCH 02/11] staging:iio: Fix adis16201 channel offsets and scales
  2012-10-15  9:35 [PATCH 01/11] iio: Add some helper macros for unit conversion Lars-Peter Clausen
@ 2012-10-15  9:35 ` Lars-Peter Clausen
  2012-10-18  9:06   ` Jonathan Cameron
  2012-10-15  9:35 ` [PATCH 03/11] staging:iio: Fix adis16203 " Lars-Peter Clausen
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 17+ messages in thread
From: Lars-Peter Clausen @ 2012-10-15  9:35 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, drivers, Lars-Peter Clausen

Most of the channel offsets and scales in the adis16201 are incorrect:
	* Temperature scale is off by a factor of 1000
	* Voltage scale is off by a factor of 1000
	* Acceleration scale is in g instead of m/(s**2)
	* Temperature offset is completely wrong

This patch fixes these issues.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/accel/adis16201_core.c |   24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201_core.c b/drivers/staging/iio/accel/adis16201_core.c
index 8e37d6e..b12ca68 100644
--- a/drivers/staging/iio/accel/adis16201_core.c
+++ b/drivers/staging/iio/accel/adis16201_core.c
@@ -310,30 +310,32 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_SCALE:
 		switch (chan->type) {
 		case IIO_VOLTAGE:
-			*val = 0;
-			if (chan->channel == 0)
-				*val2 = 1220;
-			else
-				*val2 = 610;
+			if (chan->channel == 0) {
+				*val = 1;
+				*val2 = 220000; /* 1.22 mV */
+			} else {
+				*val = 0;
+				*val2 = 610000; /* 0.610 mV */
+			}
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_TEMP:
-			*val = 0;
-			*val2 = -470000;
+			*val = -470; /* 0.47 C */
+			*val2 = 0;
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_ACCEL:
 			*val = 0;
-			*val2 = 462500;
-			return IIO_VAL_INT_PLUS_MICRO;
+			*val2 = IIO_G_TO_M_S_2(462400); /* 0.4624 mg */
+			return IIO_VAL_INT_PLUS_NANO;
 		case IIO_INCLI:
 			*val = 0;
-			*val2 = 100000;
+			*val2 = 100000; /* 0.1 degree */
 			return IIO_VAL_INT_PLUS_MICRO;
 		default:
 			return -EINVAL;
 		}
 		break;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = 25;
+		*val = 25000 / -470 - 1278; /* 25 C = 1278 */
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_CALIBBIAS:
 		switch (chan->type) {
-- 
1.7.10.4


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

* [PATCH 03/11] staging:iio: Fix adis16203 channel offsets and scales
  2012-10-15  9:35 [PATCH 01/11] iio: Add some helper macros for unit conversion Lars-Peter Clausen
  2012-10-15  9:35 ` [PATCH 02/11] staging:iio: Fix adis16201 channel offsets and scales Lars-Peter Clausen
@ 2012-10-15  9:35 ` Lars-Peter Clausen
  2012-10-18  9:07   ` Jonathan Cameron
  2012-10-15  9:35 ` [PATCH 04/11] " Lars-Peter Clausen
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 17+ messages in thread
From: Lars-Peter Clausen @ 2012-10-15  9:35 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, drivers, Lars-Peter Clausen

Most of the channel offsets and scales in the adis16203 are incorrect:
	* Temperature scale is off by a factor of 1000
	* Voltage scale is off by a factor of 1000
	* Temperature offset is completely wrong

This patch fixes these issues.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/accel/adis16203_core.c |   20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16203_core.c b/drivers/staging/iio/accel/adis16203_core.c
index 002fa9d..e7b3441 100644
--- a/drivers/staging/iio/accel/adis16203_core.c
+++ b/drivers/staging/iio/accel/adis16203_core.c
@@ -316,25 +316,27 @@ static int adis16203_read_raw(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_SCALE:
 		switch (chan->type) {
 		case IIO_VOLTAGE:
-			*val = 0;
-			if (chan->channel == 0)
-				*val2 = 1220;
-			else
-				*val2 = 610;
+			if (chan->channel == 0) {
+				*val = 1;
+				*val2 = 220000; /* 1.22 mV */
+			} else {
+				*val = 0;
+				*val2 = 610000; /* 0.61 mV */
+			}
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_TEMP:
-			*val = 0;
-			*val2 = -470000;
+			*val = -470; /* -0.47 C */
+			*val2 = 0;
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_INCLI:
 			*val = 0;
-			*val2 = 25000;
+			*val2 = 25000; /* 0.025 degree */
 			return IIO_VAL_INT_PLUS_MICRO;
 		default:
 			return -EINVAL;
 		}
 	case IIO_CHAN_INFO_OFFSET:
-		*val = 25;
+		*val = 25000 / -470 - 1278; /* 25 C = 1278 */
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_CALIBBIAS:
 		bits = 14;
-- 
1.7.10.4


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

* [PATCH 04/11] staging:iio: Fix adis16203 channel offsets and scales
  2012-10-15  9:35 [PATCH 01/11] iio: Add some helper macros for unit conversion Lars-Peter Clausen
  2012-10-15  9:35 ` [PATCH 02/11] staging:iio: Fix adis16201 channel offsets and scales Lars-Peter Clausen
  2012-10-15  9:35 ` [PATCH 03/11] staging:iio: Fix adis16203 " Lars-Peter Clausen
@ 2012-10-15  9:35 ` Lars-Peter Clausen
  2012-10-15  9:42   ` Lars-Peter Clausen
  2012-10-15  9:35 ` [PATCH 05/11] staging:iio: Fix adis16209 " Lars-Peter Clausen
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 17+ messages in thread
From: Lars-Peter Clausen @ 2012-10-15  9:35 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, drivers, Lars-Peter Clausen

Most of the channel offsets and scales in the adis16203 are incorrect:
	* Temperature scale is off by a factor of 1000
	* Voltage scale is off by a factor of 1000
	* Acceleration is scale is in g instead of m/(s**2)
	* Temperature offset is completely wrong

This patch fixes these issues.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/accel/adis16204_core.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16204_core.c b/drivers/staging/iio/accel/adis16204_core.c
index 05bdb7c..c6234c2 100644
--- a/drivers/staging/iio/accel/adis16204_core.c
+++ b/drivers/staging/iio/accel/adis16204_core.c
@@ -317,26 +317,28 @@ static int adis16204_read_raw(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_SCALE:
 		switch (chan->type) {
 		case IIO_VOLTAGE:
-			*val = 0;
-			if (chan->channel == 0)
-				*val2 = 1220;
-			else
-				*val2 = 610;
+			if (chan->channel == 0) {
+				*val = 1;
+				*val2 = 220000; /* 1.22 mV */
+			} else {
+				*val = 0;
+				*val2 = 610000; /* 0.61 mV */
+			}
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_TEMP:
-			*val = 0;
-			*val2 = -470000;
+			*val = -470; /* 0.47 C */
+			*val2 = 0;
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_ACCEL:
 			*val = 0;
 			switch (chan->channel2) {
 			case IIO_MOD_X:
 			case IIO_MOD_ROOT_SUM_SQUARED_X_Y:
-				*val2 = 17125;
+				*val2 = IIO_G_TO_M_S_2(17125); /* 17.125 mg */
 				break;
 			case IIO_MOD_Y:
 			case IIO_MOD_Z:
-				*val2 = 8407;
+				*val2 = IIO_G_TO_M_S_2(8407); /* 8.407 mg */
 				break;
 			}
 			return IIO_VAL_INT_PLUS_MICRO;
@@ -345,7 +347,7 @@ static int adis16204_read_raw(struct iio_dev *indio_dev,
 		}
 		break;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = 25;
+		*val = 25000 / -470 - 1278; /* 25 C = 1278 */
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_CALIBBIAS:
 	case IIO_CHAN_INFO_PEAK:
-- 
1.7.10.4


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

* [PATCH 05/11] staging:iio: Fix adis16209 channel offsets and scales
  2012-10-15  9:35 [PATCH 01/11] iio: Add some helper macros for unit conversion Lars-Peter Clausen
                   ` (2 preceding siblings ...)
  2012-10-15  9:35 ` [PATCH 04/11] " Lars-Peter Clausen
@ 2012-10-15  9:35 ` Lars-Peter Clausen
  2012-10-18  9:09   ` Jonathan Cameron
  2012-10-15  9:35 ` [PATCH 06/11] staging:iio: Fix adis16220 " Lars-Peter Clausen
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 17+ messages in thread
From: Lars-Peter Clausen @ 2012-10-15  9:35 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, drivers, Lars-Peter Clausen

Most of the channel offsets and scales in the adis16209 are incorrect:
	* Temperature scale is of by a factor of 1000
	* Voltage scale is of by a factor of 1000
	* Temperature offset is completely wrong
	* Rotational position scale is missing

This patch fixes these issues. Also use the IIO_G_TO_M_S_2 macro for the
acceleration scale since this makes it much easier to compare it with the value
given in the datasheet.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/accel/adis16209_core.c |   18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16209_core.c b/drivers/staging/iio/accel/adis16209_core.c
index b7333bf..7ee974b 100644
--- a/drivers/staging/iio/accel/adis16209_core.c
+++ b/drivers/staging/iio/accel/adis16209_core.c
@@ -343,28 +343,29 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
 		case IIO_VOLTAGE:
 			*val = 0;
 			if (chan->channel == 0)
-				*val2 = 305180;
+				*val2 = 305180; /* 0.30518 mV */
 			else
-				*val2 = 610500;
+				*val2 = 610500; /* 0.6105 mV */
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_TEMP:
-			*val = 0;
-			*val2 = -470000;
+			*val = -470; /* -0.47 C */
+			*val2 = 0;
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_ACCEL:
 			*val = 0;
-			*val2 = 2394;
-			return IIO_VAL_INT_PLUS_MICRO;
+			*val2 = IIO_G_TO_M_S_2(244140); /* 0.244140 mg */
+			return IIO_VAL_INT_PLUS_NANO;
 		case IIO_INCLI:
+		case IIO_ROT:
 			*val = 0;
-			*val2 = 436;
+			*val2 = 25000; /* 0.025 degree */
 			return IIO_VAL_INT_PLUS_MICRO;
 		default:
 			return -EINVAL;
 		}
 		break;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = 25;
+		*val = 25000 / -470 - 0x4FE; /* 25 C = 0x4FE */
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_CALIBBIAS:
 		switch (chan->type) {
@@ -491,6 +492,7 @@ static const struct iio_chan_spec adis16209_channels[] = {
 		.modified = 1,
 		.channel2 = IIO_MOD_X,
 		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+		IIO_CHAN_INFO_SCALE_SHARED_BIT,
 		.address = rot,
 		.scan_index = ADIS16209_SCAN_ROT,
 		.scan_type = {
-- 
1.7.10.4


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

* [PATCH 06/11] staging:iio: Fix adis16220 channel offsets and scales
  2012-10-15  9:35 [PATCH 01/11] iio: Add some helper macros for unit conversion Lars-Peter Clausen
                   ` (3 preceding siblings ...)
  2012-10-15  9:35 ` [PATCH 05/11] staging:iio: Fix adis16209 " Lars-Peter Clausen
@ 2012-10-15  9:35 ` Lars-Peter Clausen
  2012-10-15  9:35 ` [PATCH 07/11] staging:iio: Fix adis16240 " Lars-Peter Clausen
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Lars-Peter Clausen @ 2012-10-15  9:35 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, drivers, Lars-Peter Clausen

Most of the channel offsets and scales in the adis16220 are incorrect:
	* Temperature scale is off by a factor of 1000
	* Voltage scale is off by a factor of 1000
	* Acceleration seems to have a typo "187042" since it should be instead of
	  "1887042"
	* Temperature offset is completely wrong

This patch fixes these issues.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/accel/adis16220_core.c |   19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16220_core.c b/drivers/staging/iio/accel/adis16220_core.c
index c755089..eaadd9d 100644
--- a/drivers/staging/iio/accel/adis16220_core.c
+++ b/drivers/staging/iio/accel/adis16220_core.c
@@ -486,7 +486,7 @@ static int adis16220_read_raw(struct iio_dev *indio_dev,
 		break;
 	case IIO_CHAN_INFO_OFFSET:
 		if (chan->type == IIO_TEMP) {
-			*val = 25;
+			*val = 25000 / -470 - 1278; /* 25 C = 1278 */
 			return IIO_VAL_INT;
 		}
 		addrind = 1;
@@ -495,19 +495,22 @@ static int adis16220_read_raw(struct iio_dev *indio_dev,
 		addrind = 2;
 		break;
 	case IIO_CHAN_INFO_SCALE:
-		*val = 0;
 		switch (chan->type) {
 		case IIO_TEMP:
-			*val2 = -470000;
+			*val = -470; /* -0.47 C */
+			*val2 = 0;
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_ACCEL:
-			*val2 = 1887042;
+			*val2 = IIO_G_TO_M_S_2(19073); /* 19.073 g */
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_VOLTAGE:
-			if (chan->channel == 0)
-				*val2 = 0012221;
-			else /* Should really be dependent on VDD */
-				*val2 = 305;
+			if (chan->channel == 0) {
+				*val = 1;
+				*val2 = 220700; /* 1.2207 mV */
+			} else {
+				/* Should really be dependent on VDD */
+				*val2 = 305180; /* 305.18 uV */
+			}
 			return IIO_VAL_INT_PLUS_MICRO;
 		default:
 			return -EINVAL;
-- 
1.7.10.4


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

* [PATCH 07/11] staging:iio: Fix adis16240 channel offsets and scales
  2012-10-15  9:35 [PATCH 01/11] iio: Add some helper macros for unit conversion Lars-Peter Clausen
                   ` (4 preceding siblings ...)
  2012-10-15  9:35 ` [PATCH 06/11] staging:iio: Fix adis16220 " Lars-Peter Clausen
@ 2012-10-15  9:35 ` Lars-Peter Clausen
  2012-10-15  9:35 ` [PATCH 08/11] staging:iio: Fix adis16260 " Lars-Peter Clausen
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Lars-Peter Clausen @ 2012-10-15  9:35 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, drivers, Lars-Peter Clausen

Most of the channel offsets and scales in the adis16240 are incorrect:
    * Temperature scale is of by a factor of 1000
    * Voltage scale is of by a factor of 1000
    * Temperature offset is completely wrong
	* Peak scale is completely wrong

This patch fixes these issues. Also use the IIO_G_TO_M_S_2 macro for the
acceleration scale since this makes it much easier to compare it to the value
given in the datasheet.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/accel/adis16240_core.c |   23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16240_core.c b/drivers/staging/iio/accel/adis16240_core.c
index 0fc26a4..35e0939 100644
--- a/drivers/staging/iio/accel/adis16240_core.c
+++ b/drivers/staging/iio/accel/adis16240_core.c
@@ -373,30 +373,31 @@ static int adis16240_read_raw(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_SCALE:
 		switch (chan->type) {
 		case IIO_VOLTAGE:
-			*val = 0;
-			if (chan->channel == 0)
-				*val2 = 4880;
-			else
+			if (chan->channel == 0) {
+				*val = 4;
+				*val2 = 880000; /* 4.88 mV */
+				return IIO_VAL_INT_PLUS_MICRO;
+			} else {
 				return -EINVAL;
-			return IIO_VAL_INT_PLUS_MICRO;
+			}
 		case IIO_TEMP:
-			*val = 0;
-			*val2 = 244000;
+			*val = 244; /* 0.244 C */
+			*val2 = 0;
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_ACCEL:
 			*val = 0;
-			*val2 = 504062;
+			*val2 = IIO_G_TO_M_S_2(51400); /* 51.4 mg */
 			return IIO_VAL_INT_PLUS_MICRO;
 		default:
 			return -EINVAL;
 		}
 		break;
 	case IIO_CHAN_INFO_PEAK_SCALE:
-		*val = 6;
-		*val2 = 629295;
+		*val = 0;
+		*val2 = IIO_G_TO_M_S_2(51400); /* 51.4 mg */
 		return IIO_VAL_INT_PLUS_MICRO;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = 25;
+		*val = 25000 / 244 - 0x133; /* 25 C = 0x133 */
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_CALIBBIAS:
 		bits = 10;
-- 
1.7.10.4


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

* [PATCH 08/11] staging:iio: Fix adis16260 channel offsets and scales
  2012-10-15  9:35 [PATCH 01/11] iio: Add some helper macros for unit conversion Lars-Peter Clausen
                   ` (5 preceding siblings ...)
  2012-10-15  9:35 ` [PATCH 07/11] staging:iio: Fix adis16240 " Lars-Peter Clausen
@ 2012-10-15  9:35 ` Lars-Peter Clausen
  2012-10-15  9:35 ` [PATCH 09/11] staging:iio: Fix adis16400 " Lars-Peter Clausen
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Lars-Peter Clausen @ 2012-10-15  9:35 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, drivers, Lars-Peter Clausen

Most of the channel offsets and scales in the adis16260 are incorrect:
	* Temperature scale is off by a factor of 1000
	* Voltage scale is off by a factor of 1000
	* Temperature offset is completely wrong

This patch fixes these issues. Also use the IIO_DEGREE_TO_RAD for the angle
velocity since this makes it much easier to compare it to the value given in the
datasheet.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/gyro/adis16260_core.c |   29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/iio/gyro/adis16260_core.c b/drivers/staging/iio/gyro/adis16260_core.c
index 9571c03..aa964a2 100644
--- a/drivers/staging/iio/gyro/adis16260_core.c
+++ b/drivers/staging/iio/gyro/adis16260_core.c
@@ -498,28 +498,33 @@ static int adis16260_read_raw(struct iio_dev *indio_dev,
 		switch (chan->type) {
 		case IIO_ANGL_VEL:
 			*val = 0;
-			if (spi_get_device_id(st->us)->driver_data)
-				*val2 = 320;
-			else
-				*val2 = 1278;
+			if (spi_get_device_id(st->us)->driver_data) {
+				/* 0.01832 degree / sec */
+				*val2 = IIO_DEGREE_TO_RAD(18320);
+			} else {
+				/* 0.07326 degree / sec */
+				*val2 = IIO_DEGREE_TO_RAD(73260);
+			}
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_VOLTAGE:
-			*val = 0;
-			if (chan->channel == 0)
-				*val2 = 18315;
-			else
-				*val2 = 610500;
+			if (chan->channel == 0) {
+				*val = 1;
+				*val2 = 831500; /* 1.8315 mV */
+			} else {
+				*val = 0;
+				*val2 = 610500; /* 610.5 uV */
+			}
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_TEMP:
-			*val = 0;
-			*val2 = 145300;
+			*val = 145;
+			*val2 = 300000; /* 0.1453 C */
 			return IIO_VAL_INT_PLUS_MICRO;
 		default:
 			return -EINVAL;
 		}
 		break;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = 25;
+		*val = 250000 / 1453; /* 25 C = 0x00 */
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_CALIBBIAS:
 		switch (chan->type) {
-- 
1.7.10.4


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

* [PATCH 09/11] staging:iio: Fix adis16400 channel offsets and scales
  2012-10-15  9:35 [PATCH 01/11] iio: Add some helper macros for unit conversion Lars-Peter Clausen
                   ` (6 preceding siblings ...)
  2012-10-15  9:35 ` [PATCH 08/11] staging:iio: Fix adis16260 " Lars-Peter Clausen
@ 2012-10-15  9:35 ` Lars-Peter Clausen
  2012-10-15  9:35 ` [PATCH 10/11] staging:iio:adis16400: Report correct temperature scale and offset Lars-Peter Clausen
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Lars-Peter Clausen @ 2012-10-15  9:35 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, drivers, Lars-Peter Clausen

Most of the channel offsets and scales in the adis16400 are incorrect:
    * Voltage scale is off by a factor of 1000
    * Temperature scale is off by a factor of 1000
	* Temperature offset is completely wrong
	* Some of the acceleration scales are either completely wrong or have the
	  wrong unit
	* Some of the angular velocity scale are either completely wrong or have
	  the wrong unit

This patch fixes these issues. For consistency it also converts scales which are
correct to use the IIO_G_TO_M_S_2 and IIO_DEGREE_TO_RAD macro. This makes it
much easier to compare it to the value given in the datasheet.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/imu/adis16400_core.c |   53 +++++++++++++++---------------
 1 file changed, 27 insertions(+), 26 deletions(-)

diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c
index b302c9b..dccea95 100644
--- a/drivers/staging/iio/imu/adis16400_core.c
+++ b/drivers/staging/iio/imu/adis16400_core.c
@@ -553,10 +553,13 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_VOLTAGE:
 			*val = 0;
-			if (chan->channel == 0)
-				*val2 = 2418;
-			else
-				*val2 = 806;
+			if (chan->channel == 0) {
+				*val = 2;
+				*val2 = 418000; /* 2.418 mV */
+			} else {
+				*val = 0;
+				*val2 = 805800; /* 805.8 uV */
+			}
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_ACCEL:
 			*val = 0;
@@ -564,11 +567,11 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_MAGN:
 			*val = 0;
-			*val2 = 500;
+			*val2 = 500; /* 0.5 mgauss */
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_TEMP:
-			*val = 0;
-			*val2 = 140000;
+			*val = 140; /* 0.14 C */
+			*val2 = 0;
 			return IIO_VAL_INT_PLUS_MICRO;
 		default:
 			return -EINVAL;
@@ -585,10 +588,8 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
 		*val = val16;
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_OFFSET:
-		/* currently only temperature */
-		*val = 198;
-		*val2 = 160000;
-		return IIO_VAL_INT_PLUS_MICRO;
+		*val = 2500 / 14; /* 25 C = 0x00 */
+		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
 		mutex_lock(&indio_dev->mlock);
 		/* Need both the number of taps and the sampling frequency */
@@ -1058,7 +1059,7 @@ static struct adis16400_chip_info adis16400_chips[] = {
 	[ADIS16300] = {
 		.channels = adis16300_channels,
 		.num_channels = ARRAY_SIZE(adis16300_channels),
-		.gyro_scale_micro = 873,
+		.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
 		.accel_scale_micro = 5884,
 		.default_scan_mask = (1 << ADIS16400_SCAN_SUPPLY) |
 		(1 << ADIS16400_SCAN_GYRO_X) | (1 << ADIS16400_SCAN_ACC_X) |
@@ -1070,8 +1071,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
 	[ADIS16334] = {
 		.channels = adis16334_channels,
 		.num_channels = ARRAY_SIZE(adis16334_channels),
-		.gyro_scale_micro = 873,
-		.accel_scale_micro = 981,
+		.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
+		.accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */
 		.default_scan_mask = (1 << ADIS16400_SCAN_GYRO_X) |
 		(1 << ADIS16400_SCAN_GYRO_Y) | (1 << ADIS16400_SCAN_GYRO_Z) |
 		(1 << ADIS16400_SCAN_ACC_X) | (1 << ADIS16400_SCAN_ACC_Y) |
@@ -1080,8 +1081,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
 	[ADIS16350] = {
 		.channels = adis16350_channels,
 		.num_channels = ARRAY_SIZE(adis16350_channels),
-		.gyro_scale_micro = 872664,
-		.accel_scale_micro = 24732,
+		.gyro_scale_micro = IIO_DEGREE_TO_RAD(73260), /* 0.07326 deg/s */
+		.accel_scale_micro = IIO_G_TO_M_S_2(2522), /* 0.002522 g */
 		.default_scan_mask = 0x7FF,
 		.flags = ADIS16400_NO_BURST,
 	},
@@ -1090,8 +1091,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
 		.num_channels = ARRAY_SIZE(adis16350_channels),
 		.flags = ADIS16400_HAS_PROD_ID,
 		.product_id = 0x3FE8,
-		.gyro_scale_micro = 1279,
-		.accel_scale_micro = 24732,
+		.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
+		.accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */
 		.default_scan_mask = 0x7FF,
 	},
 	[ADIS16362] = {
@@ -1099,8 +1100,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
 		.num_channels = ARRAY_SIZE(adis16350_channels),
 		.flags = ADIS16400_HAS_PROD_ID,
 		.product_id = 0x3FEA,
-		.gyro_scale_micro = 1279,
-		.accel_scale_micro = 24732,
+		.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
+		.accel_scale_micro = IIO_G_TO_M_S_2(333), /* 0.333 mg */
 		.default_scan_mask = 0x7FF,
 	},
 	[ADIS16364] = {
@@ -1108,8 +1109,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
 		.num_channels = ARRAY_SIZE(adis16350_channels),
 		.flags = ADIS16400_HAS_PROD_ID,
 		.product_id = 0x3FEC,
-		.gyro_scale_micro = 1279,
-		.accel_scale_micro = 24732,
+		.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
+		.accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */
 		.default_scan_mask = 0x7FF,
 	},
 	[ADIS16365] = {
@@ -1117,8 +1118,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
 		.num_channels = ARRAY_SIZE(adis16350_channels),
 		.flags = ADIS16400_HAS_PROD_ID,
 		.product_id = 0x3FED,
-		.gyro_scale_micro = 1279,
-		.accel_scale_micro = 24732,
+		.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
+		.accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */
 		.default_scan_mask = 0x7FF,
 	},
 	[ADIS16400] = {
@@ -1126,8 +1127,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
 		.num_channels = ARRAY_SIZE(adis16400_channels),
 		.flags = ADIS16400_HAS_PROD_ID,
 		.product_id = 0x4015,
-		.gyro_scale_micro = 873,
-		.accel_scale_micro = 32656,
+		.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
+		.accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */
 		.default_scan_mask = 0xFFF,
 	}
 };
-- 
1.7.10.4


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

* [PATCH 10/11] staging:iio:adis16400: Report correct temperature scale and offset
  2012-10-15  9:35 [PATCH 01/11] iio: Add some helper macros for unit conversion Lars-Peter Clausen
                   ` (7 preceding siblings ...)
  2012-10-15  9:35 ` [PATCH 09/11] staging:iio: Fix adis16400 " Lars-Peter Clausen
@ 2012-10-15  9:35 ` Lars-Peter Clausen
  2012-10-15  9:35 ` [PATCH 11/11] staging:iio:adis16400: Fixup adis16336 temp channel attributes Lars-Peter Clausen
  2012-10-18  8:57 ` [PATCH 01/11] iio: Add some helper macros for unit conversion Jonathan Cameron
  10 siblings, 0 replies; 17+ messages in thread
From: Lars-Peter Clausen @ 2012-10-15  9:35 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, drivers, Lars-Peter Clausen

Temperature scale and offset differ between the different devices supported by
this driver. Right now the driver always reports the temperature scale and
offset of the adis16400 regardless of which chip variant is used. This patch
adds two new attributes to the chip_info struct, one for the temperature scale
and one for the temperature offset.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/imu/adis16400.h      |    2 ++
 drivers/staging/iio/imu/adis16400_core.c |   23 ++++++++++++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/iio/imu/adis16400.h b/drivers/staging/iio/imu/adis16400.h
index d59d7ac..77c601d 100644
--- a/drivers/staging/iio/imu/adis16400.h
+++ b/drivers/staging/iio/imu/adis16400.h
@@ -139,6 +139,8 @@ struct adis16400_chip_info {
 	const long flags;
 	unsigned int gyro_scale_micro;
 	unsigned int accel_scale_micro;
+	int temp_scale_nano;
+	int temp_offset;
 	unsigned long default_scan_mask;
 };
 
diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c
index dccea95..eaed87f 100644
--- a/drivers/staging/iio/imu/adis16400_core.c
+++ b/drivers/staging/iio/imu/adis16400_core.c
@@ -570,8 +570,8 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
 			*val2 = 500; /* 0.5 mgauss */
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_TEMP:
-			*val = 140; /* 0.14 C */
-			*val2 = 0;
+			*val = st->variant->temp_scale_nano / 1000000;
+			*val2 = (st->variant->temp_scale_nano % 1000000);
 			return IIO_VAL_INT_PLUS_MICRO;
 		default:
 			return -EINVAL;
@@ -588,7 +588,8 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
 		*val = val16;
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = 2500 / 14; /* 25 C = 0x00 */
+		/* currently only temperature */
+		*val = st->variant->temp_offset;
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
 		mutex_lock(&indio_dev->mlock);
@@ -1061,6 +1062,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
 		.num_channels = ARRAY_SIZE(adis16300_channels),
 		.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
 		.accel_scale_micro = 5884,
+		.temp_scale_nano = 140000000, /* 0.14 C */
+		.temp_offset = 25000000 / 140000, /* 25 C = 0x00 */
 		.default_scan_mask = (1 << ADIS16400_SCAN_SUPPLY) |
 		(1 << ADIS16400_SCAN_GYRO_X) | (1 << ADIS16400_SCAN_ACC_X) |
 		(1 << ADIS16400_SCAN_ACC_Y) | (1 << ADIS16400_SCAN_ACC_Z) |
@@ -1073,6 +1076,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
 		.num_channels = ARRAY_SIZE(adis16334_channels),
 		.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
 		.accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */
+		.temp_scale_nano = 67850000, /* 0.06785 C */
+		.temp_offset = 25000000 / 67850, /* 25 C = 0x00 */
 		.default_scan_mask = (1 << ADIS16400_SCAN_GYRO_X) |
 		(1 << ADIS16400_SCAN_GYRO_Y) | (1 << ADIS16400_SCAN_GYRO_Z) |
 		(1 << ADIS16400_SCAN_ACC_X) | (1 << ADIS16400_SCAN_ACC_Y) |
@@ -1083,6 +1088,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
 		.num_channels = ARRAY_SIZE(adis16350_channels),
 		.gyro_scale_micro = IIO_DEGREE_TO_RAD(73260), /* 0.07326 deg/s */
 		.accel_scale_micro = IIO_G_TO_M_S_2(2522), /* 0.002522 g */
+		.temp_scale_nano = 145300000, /* 0.1453 C */
+		.temp_offset = 25000000 / 145300, /* 25 C = 0x00 */
 		.default_scan_mask = 0x7FF,
 		.flags = ADIS16400_NO_BURST,
 	},
@@ -1093,6 +1100,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
 		.product_id = 0x3FE8,
 		.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
 		.accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */
+		.temp_scale_nano = 136000000, /* 0.136 C */
+		.temp_offset = 25000000 / 136000, /* 25 C = 0x00 */
 		.default_scan_mask = 0x7FF,
 	},
 	[ADIS16362] = {
@@ -1102,6 +1111,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
 		.product_id = 0x3FEA,
 		.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
 		.accel_scale_micro = IIO_G_TO_M_S_2(333), /* 0.333 mg */
+		.temp_scale_nano = 136000000, /* 0.136 C */
+		.temp_offset = 25000000 / 136000, /* 25 C = 0x00 */
 		.default_scan_mask = 0x7FF,
 	},
 	[ADIS16364] = {
@@ -1111,6 +1122,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
 		.product_id = 0x3FEC,
 		.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
 		.accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */
+		.temp_scale_nano = 136000000, /* 0.136 C */
+		.temp_offset = 25000000 / 136000, /* 25 C = 0x00 */
 		.default_scan_mask = 0x7FF,
 	},
 	[ADIS16365] = {
@@ -1120,6 +1133,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
 		.product_id = 0x3FED,
 		.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
 		.accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */
+		.temp_scale_nano = 136000000, /* 0.136 C */
+		.temp_offset = 25000000 / 136000, /* 25 C = 0x00 */
 		.default_scan_mask = 0x7FF,
 	},
 	[ADIS16400] = {
@@ -1130,6 +1145,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
 		.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
 		.accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */
 		.default_scan_mask = 0xFFF,
+		.temp_scale_nano = 140000000, /* 0.14 C */
+		.temp_offset = 25000000 / 140000, /* 25 C = 0x00 */
 	}
 };
 
-- 
1.7.10.4


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

* [PATCH 11/11] staging:iio:adis16400: Fixup adis16336 temp channel attributes
  2012-10-15  9:35 [PATCH 01/11] iio: Add some helper macros for unit conversion Lars-Peter Clausen
                   ` (8 preceding siblings ...)
  2012-10-15  9:35 ` [PATCH 10/11] staging:iio:adis16400: Report correct temperature scale and offset Lars-Peter Clausen
@ 2012-10-15  9:35 ` Lars-Peter Clausen
  2012-10-18  8:57 ` [PATCH 01/11] iio: Add some helper macros for unit conversion Jonathan Cameron
  10 siblings, 0 replies; 17+ messages in thread
From: Lars-Peter Clausen @ 2012-10-15  9:35 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, drivers, Lars-Peter Clausen

The temperature channel has a calibbias attribute which it should not have, but
the offset attribute is missing.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/imu/adis16400_core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c
index eaed87f..3144a7b 100644
--- a/drivers/staging/iio/imu/adis16400_core.c
+++ b/drivers/staging/iio/imu/adis16400_core.c
@@ -1037,7 +1037,7 @@ static const struct iio_chan_spec adis16334_channels[] = {
 		.indexed = 1,
 		.channel = 0,
 		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-		IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
+		IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
 		IIO_CHAN_INFO_SCALE_SHARED_BIT,
 		.address = temp0,
 		.scan_index = ADIS16400_SCAN_TEMP,
-- 
1.7.10.4


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

* Re: [PATCH 04/11] staging:iio: Fix adis16203 channel offsets and scales
  2012-10-15  9:35 ` [PATCH 04/11] " Lars-Peter Clausen
@ 2012-10-15  9:42   ` Lars-Peter Clausen
  2012-10-18  9:07     ` Jonathan Cameron
  0 siblings, 1 reply; 17+ messages in thread
From: Lars-Peter Clausen @ 2012-10-15  9:42 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio, drivers

s/adis16203/adis16204/

On 10/15/2012 11:35 AM, Lars-Peter Clausen wrote:
> Most of the channel offsets and scales in the adis16203 are incorrect:
> 	* Temperature scale is off by a factor of 1000
> 	* Voltage scale is off by a factor of 1000
> 	* Acceleration is scale is in g instead of m/(s**2)
> 	* Temperature offset is completely wrong
> 
> This patch fixes these issues.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
>  drivers/staging/iio/accel/adis16204_core.c |   22 ++++++++++++----------
>  1 file changed, 12 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/staging/iio/accel/adis16204_core.c b/drivers/staging/iio/accel/adis16204_core.c
> index 05bdb7c..c6234c2 100644
> --- a/drivers/staging/iio/accel/adis16204_core.c
> +++ b/drivers/staging/iio/accel/adis16204_core.c
> @@ -317,26 +317,28 @@ static int adis16204_read_raw(struct iio_dev *indio_dev,
>  	case IIO_CHAN_INFO_SCALE:
>  		switch (chan->type) {
>  		case IIO_VOLTAGE:
> -			*val = 0;
> -			if (chan->channel == 0)
> -				*val2 = 1220;
> -			else
> -				*val2 = 610;
> +			if (chan->channel == 0) {
> +				*val = 1;
> +				*val2 = 220000; /* 1.22 mV */
> +			} else {
> +				*val = 0;
> +				*val2 = 610000; /* 0.61 mV */
> +			}
>  			return IIO_VAL_INT_PLUS_MICRO;
>  		case IIO_TEMP:
> -			*val = 0;
> -			*val2 = -470000;
> +			*val = -470; /* 0.47 C */
> +			*val2 = 0;
>  			return IIO_VAL_INT_PLUS_MICRO;
>  		case IIO_ACCEL:
>  			*val = 0;
>  			switch (chan->channel2) {
>  			case IIO_MOD_X:
>  			case IIO_MOD_ROOT_SUM_SQUARED_X_Y:
> -				*val2 = 17125;
> +				*val2 = IIO_G_TO_M_S_2(17125); /* 17.125 mg */
>  				break;
>  			case IIO_MOD_Y:
>  			case IIO_MOD_Z:
> -				*val2 = 8407;
> +				*val2 = IIO_G_TO_M_S_2(8407); /* 8.407 mg */
>  				break;
>  			}
>  			return IIO_VAL_INT_PLUS_MICRO;
> @@ -345,7 +347,7 @@ static int adis16204_read_raw(struct iio_dev *indio_dev,
>  		}
>  		break;
>  	case IIO_CHAN_INFO_OFFSET:
> -		*val = 25;
> +		*val = 25000 / -470 - 1278; /* 25 C = 1278 */
>  		return IIO_VAL_INT;
>  	case IIO_CHAN_INFO_CALIBBIAS:
>  	case IIO_CHAN_INFO_PEAK:


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

* Re: [PATCH 01/11] iio: Add some helper macros for unit conversion
  2012-10-15  9:35 [PATCH 01/11] iio: Add some helper macros for unit conversion Lars-Peter Clausen
                   ` (9 preceding siblings ...)
  2012-10-15  9:35 ` [PATCH 11/11] staging:iio:adis16400: Fixup adis16336 temp channel attributes Lars-Peter Clausen
@ 2012-10-18  8:57 ` Jonathan Cameron
  10 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-10-18  8:57 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio, drivers

On 10/15/2012 10:35 AM, Lars-Peter Clausen wrote:
> Some datasheets use a different unit to specify the channel scale than what IIO
> expects it to be. This patch adds two helper macros which allow to convert units
> commonly used in datasheets to IIO units:
>
>  * acceleration: g -> meter / second**2
>  * angular velocity: degree (/ second) -> rad (/ second)
>
> This makes it much more convenient to specify and also easier to verify a
> channel's scale attribute.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Good idea applied to togreg branch of iio.git (or at least will
be when I get home from travelling).

> ---
>  include/linux/iio/iio.h |   16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index c0ae76a..7806c24 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -618,4 +618,20 @@ static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
>  };
>  #endif
>
> +/**
> + * IIO_DEGREE_TO_RAD() - Convert degree to rad
> + * @deg: A value in degree
> + *
> + * Returns the given value converted from degree to rad
> + */
> +#define IIO_DEGREE_TO_RAD(deg) (((deg) * 314159ULL + 9000000ULL) / 18000000ULL)
> +
> +/**
> + * IIO_G_TO_M_S_2() - Convert g to meter / second**2
> + * @g: A value in g
> + *
> + * Returns the given value converted from g to meter / second**2
> + */
> +#define IIO_G_TO_M_S_2(g) ((g) * 980665ULL / 100000ULL)
> +
>  #endif /* _INDUSTRIAL_IO_H_ */
>

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

* Re: [PATCH 02/11] staging:iio: Fix adis16201 channel offsets and scales
  2012-10-15  9:35 ` [PATCH 02/11] staging:iio: Fix adis16201 channel offsets and scales Lars-Peter Clausen
@ 2012-10-18  9:06   ` Jonathan Cameron
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-10-18  9:06 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio, drivers

On 10/15/2012 10:35 AM, Lars-Peter Clausen wrote:
> Most of the channel offsets and scales in the adis16201 are incorrect:
> 	* Temperature scale is off by a factor of 1000
> 	* Voltage scale is off by a factor of 1000
> 	* Acceleration scale is in g instead of m/(s**2)
> 	* Temperature offset is completely wrong
> 
> This patch fixes these issues.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to fixes-togreg branch (changed plan on the previous patch as these
fixes are dependent on it and that will now go in the fixes branch as well).

> ---
>  drivers/staging/iio/accel/adis16201_core.c |   24 +++++++++++++-----------
>  1 file changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/staging/iio/accel/adis16201_core.c b/drivers/staging/iio/accel/adis16201_core.c
> index 8e37d6e..b12ca68 100644
> --- a/drivers/staging/iio/accel/adis16201_core.c
> +++ b/drivers/staging/iio/accel/adis16201_core.c
> @@ -310,30 +310,32 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
>  	case IIO_CHAN_INFO_SCALE:
>  		switch (chan->type) {
>  		case IIO_VOLTAGE:
> -			*val = 0;
> -			if (chan->channel == 0)
> -				*val2 = 1220;
> -			else
> -				*val2 = 610;
> +			if (chan->channel == 0) {
> +				*val = 1;
> +				*val2 = 220000; /* 1.22 mV */
> +			} else {
> +				*val = 0;
> +				*val2 = 610000; /* 0.610 mV */
> +			}
>  			return IIO_VAL_INT_PLUS_MICRO;
>  		case IIO_TEMP:
> -			*val = 0;
> -			*val2 = -470000;
> +			*val = -470; /* 0.47 C */
> +			*val2 = 0;
>  			return IIO_VAL_INT_PLUS_MICRO;
>  		case IIO_ACCEL:
>  			*val = 0;
> -			*val2 = 462500;
> -			return IIO_VAL_INT_PLUS_MICRO;
> +			*val2 = IIO_G_TO_M_S_2(462400); /* 0.4624 mg */
> +			return IIO_VAL_INT_PLUS_NANO;
>  		case IIO_INCLI:
>  			*val = 0;
> -			*val2 = 100000;
> +			*val2 = 100000; /* 0.1 degree */
>  			return IIO_VAL_INT_PLUS_MICRO;
>  		default:
>  			return -EINVAL;
>  		}
>  		break;
>  	case IIO_CHAN_INFO_OFFSET:
> -		*val = 25;
> +		*val = 25000 / -470 - 1278; /* 25 C = 1278 */
>  		return IIO_VAL_INT;
>  	case IIO_CHAN_INFO_CALIBBIAS:
>  		switch (chan->type) {
> 

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

* Re: [PATCH 03/11] staging:iio: Fix adis16203 channel offsets and scales
  2012-10-15  9:35 ` [PATCH 03/11] staging:iio: Fix adis16203 " Lars-Peter Clausen
@ 2012-10-18  9:07   ` Jonathan Cameron
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-10-18  9:07 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio, drivers

On 10/15/2012 10:35 AM, Lars-Peter Clausen wrote:
> Most of the channel offsets and scales in the adis16203 are incorrect:
> 	* Temperature scale is off by a factor of 1000
> 	* Voltage scale is off by a factor of 1000
> 	* Temperature offset is completely wrong
> 
> This patch fixes these issues.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to fixes branch of iio.git

> ---
>  drivers/staging/iio/accel/adis16203_core.c |   20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/staging/iio/accel/adis16203_core.c b/drivers/staging/iio/accel/adis16203_core.c
> index 002fa9d..e7b3441 100644
> --- a/drivers/staging/iio/accel/adis16203_core.c
> +++ b/drivers/staging/iio/accel/adis16203_core.c
> @@ -316,25 +316,27 @@ static int adis16203_read_raw(struct iio_dev *indio_dev,
>  	case IIO_CHAN_INFO_SCALE:
>  		switch (chan->type) {
>  		case IIO_VOLTAGE:
> -			*val = 0;
> -			if (chan->channel == 0)
> -				*val2 = 1220;
> -			else
> -				*val2 = 610;
> +			if (chan->channel == 0) {
> +				*val = 1;
> +				*val2 = 220000; /* 1.22 mV */
> +			} else {
> +				*val = 0;
> +				*val2 = 610000; /* 0.61 mV */
> +			}
>  			return IIO_VAL_INT_PLUS_MICRO;
>  		case IIO_TEMP:
> -			*val = 0;
> -			*val2 = -470000;
> +			*val = -470; /* -0.47 C */
> +			*val2 = 0;
>  			return IIO_VAL_INT_PLUS_MICRO;
>  		case IIO_INCLI:
>  			*val = 0;
> -			*val2 = 25000;
> +			*val2 = 25000; /* 0.025 degree */
>  			return IIO_VAL_INT_PLUS_MICRO;
>  		default:
>  			return -EINVAL;
>  		}
>  	case IIO_CHAN_INFO_OFFSET:
> -		*val = 25;
> +		*val = 25000 / -470 - 1278; /* 25 C = 1278 */
>  		return IIO_VAL_INT;
>  	case IIO_CHAN_INFO_CALIBBIAS:
>  		bits = 14;
> 

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

* Re: [PATCH 04/11] staging:iio: Fix adis16203 channel offsets and scales
  2012-10-15  9:42   ` Lars-Peter Clausen
@ 2012-10-18  9:07     ` Jonathan Cameron
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-10-18  9:07 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio, drivers

On 10/15/2012 10:42 AM, Lars-Peter Clausen wrote:
> s/adis16203/adis16204/
:)
> 
> On 10/15/2012 11:35 AM, Lars-Peter Clausen wrote:
>> Most of the channel offsets and scales in the adis16203 are incorrect:
>> 	* Temperature scale is off by a factor of 1000
>> 	* Voltage scale is off by a factor of 1000
>> 	* Acceleration is scale is in g instead of m/(s**2)
>> 	* Temperature offset is completely wrong
>>
>> This patch fixes these issues.
>>
>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to fixes branch of iio.git with appropriate sed.

>> ---
>>  drivers/staging/iio/accel/adis16204_core.c |   22 ++++++++++++----------
>>  1 file changed, 12 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/staging/iio/accel/adis16204_core.c b/drivers/staging/iio/accel/adis16204_core.c
>> index 05bdb7c..c6234c2 100644
>> --- a/drivers/staging/iio/accel/adis16204_core.c
>> +++ b/drivers/staging/iio/accel/adis16204_core.c
>> @@ -317,26 +317,28 @@ static int adis16204_read_raw(struct iio_dev *indio_dev,
>>  	case IIO_CHAN_INFO_SCALE:
>>  		switch (chan->type) {
>>  		case IIO_VOLTAGE:
>> -			*val = 0;
>> -			if (chan->channel == 0)
>> -				*val2 = 1220;
>> -			else
>> -				*val2 = 610;
>> +			if (chan->channel == 0) {
>> +				*val = 1;
>> +				*val2 = 220000; /* 1.22 mV */
>> +			} else {
>> +				*val = 0;
>> +				*val2 = 610000; /* 0.61 mV */
>> +			}
>>  			return IIO_VAL_INT_PLUS_MICRO;
>>  		case IIO_TEMP:
>> -			*val = 0;
>> -			*val2 = -470000;
>> +			*val = -470; /* 0.47 C */
>> +			*val2 = 0;
>>  			return IIO_VAL_INT_PLUS_MICRO;
>>  		case IIO_ACCEL:
>>  			*val = 0;
>>  			switch (chan->channel2) {
>>  			case IIO_MOD_X:
>>  			case IIO_MOD_ROOT_SUM_SQUARED_X_Y:
>> -				*val2 = 17125;
>> +				*val2 = IIO_G_TO_M_S_2(17125); /* 17.125 mg */
>>  				break;
>>  			case IIO_MOD_Y:
>>  			case IIO_MOD_Z:
>> -				*val2 = 8407;
>> +				*val2 = IIO_G_TO_M_S_2(8407); /* 8.407 mg */
>>  				break;
>>  			}
>>  			return IIO_VAL_INT_PLUS_MICRO;
>> @@ -345,7 +347,7 @@ static int adis16204_read_raw(struct iio_dev *indio_dev,
>>  		}
>>  		break;
>>  	case IIO_CHAN_INFO_OFFSET:
>> -		*val = 25;
>> +		*val = 25000 / -470 - 1278; /* 25 C = 1278 */
>>  		return IIO_VAL_INT;
>>  	case IIO_CHAN_INFO_CALIBBIAS:
>>  	case IIO_CHAN_INFO_PEAK:
> 
> --
> 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] 17+ messages in thread

* Re: [PATCH 05/11] staging:iio: Fix adis16209 channel offsets and scales
  2012-10-15  9:35 ` [PATCH 05/11] staging:iio: Fix adis16209 " Lars-Peter Clausen
@ 2012-10-18  9:09   ` Jonathan Cameron
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-10-18  9:09 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio, drivers

On 10/15/2012 10:35 AM, Lars-Peter Clausen wrote:
> Most of the channel offsets and scales in the adis16209 are incorrect:
> 	* Temperature scale is of by a factor of 1000
> 	* Voltage scale is of by a factor of 1000
> 	* Temperature offset is completely wrong
> 	* Rotational position scale is missing
> 
> This patch fixes these issues. Also use the IIO_G_TO_M_S_2 macro for the
> acceleration scale since this makes it much easier to compare it with the value
> given in the datasheet.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to fixes-togreg branch of iio.git
> ---
>  drivers/staging/iio/accel/adis16209_core.c |   18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/staging/iio/accel/adis16209_core.c b/drivers/staging/iio/accel/adis16209_core.c
> index b7333bf..7ee974b 100644
> --- a/drivers/staging/iio/accel/adis16209_core.c
> +++ b/drivers/staging/iio/accel/adis16209_core.c
> @@ -343,28 +343,29 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
>  		case IIO_VOLTAGE:
>  			*val = 0;
>  			if (chan->channel == 0)
> -				*val2 = 305180;
> +				*val2 = 305180; /* 0.30518 mV */
>  			else
> -				*val2 = 610500;
> +				*val2 = 610500; /* 0.6105 mV */
>  			return IIO_VAL_INT_PLUS_MICRO;
>  		case IIO_TEMP:
> -			*val = 0;
> -			*val2 = -470000;
> +			*val = -470; /* -0.47 C */
> +			*val2 = 0;
>  			return IIO_VAL_INT_PLUS_MICRO;
>  		case IIO_ACCEL:
>  			*val = 0;
> -			*val2 = 2394;
> -			return IIO_VAL_INT_PLUS_MICRO;
> +			*val2 = IIO_G_TO_M_S_2(244140); /* 0.244140 mg */
> +			return IIO_VAL_INT_PLUS_NANO;
>  		case IIO_INCLI:
> +		case IIO_ROT:
>  			*val = 0;
> -			*val2 = 436;
> +			*val2 = 25000; /* 0.025 degree */
>  			return IIO_VAL_INT_PLUS_MICRO;
>  		default:
>  			return -EINVAL;
>  		}
>  		break;
>  	case IIO_CHAN_INFO_OFFSET:
> -		*val = 25;
> +		*val = 25000 / -470 - 0x4FE; /* 25 C = 0x4FE */
>  		return IIO_VAL_INT;
>  	case IIO_CHAN_INFO_CALIBBIAS:
>  		switch (chan->type) {
> @@ -491,6 +492,7 @@ static const struct iio_chan_spec adis16209_channels[] = {
>  		.modified = 1,
>  		.channel2 = IIO_MOD_X,
>  		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
> +		IIO_CHAN_INFO_SCALE_SHARED_BIT,
>  		.address = rot,
>  		.scan_index = ADIS16209_SCAN_ROT,
>  		.scan_type = {
> 

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

end of thread, other threads:[~2012-10-19  5:30 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-15  9:35 [PATCH 01/11] iio: Add some helper macros for unit conversion Lars-Peter Clausen
2012-10-15  9:35 ` [PATCH 02/11] staging:iio: Fix adis16201 channel offsets and scales Lars-Peter Clausen
2012-10-18  9:06   ` Jonathan Cameron
2012-10-15  9:35 ` [PATCH 03/11] staging:iio: Fix adis16203 " Lars-Peter Clausen
2012-10-18  9:07   ` Jonathan Cameron
2012-10-15  9:35 ` [PATCH 04/11] " Lars-Peter Clausen
2012-10-15  9:42   ` Lars-Peter Clausen
2012-10-18  9:07     ` Jonathan Cameron
2012-10-15  9:35 ` [PATCH 05/11] staging:iio: Fix adis16209 " Lars-Peter Clausen
2012-10-18  9:09   ` Jonathan Cameron
2012-10-15  9:35 ` [PATCH 06/11] staging:iio: Fix adis16220 " Lars-Peter Clausen
2012-10-15  9:35 ` [PATCH 07/11] staging:iio: Fix adis16240 " Lars-Peter Clausen
2012-10-15  9:35 ` [PATCH 08/11] staging:iio: Fix adis16260 " Lars-Peter Clausen
2012-10-15  9:35 ` [PATCH 09/11] staging:iio: Fix adis16400 " Lars-Peter Clausen
2012-10-15  9:35 ` [PATCH 10/11] staging:iio:adis16400: Report correct temperature scale and offset Lars-Peter Clausen
2012-10-15  9:35 ` [PATCH 11/11] staging:iio:adis16400: Fixup adis16336 temp channel attributes Lars-Peter Clausen
2012-10-18  8:57 ` [PATCH 01/11] iio: Add some helper macros for unit conversion Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).