Skip to contentSkip to conversation

staging: iio: adc: ad799x drop in_precision in favor of new in_type

PATCH In review [email protected] 2 participants 4 messages Oct 7, 2010

Subsystems (4)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 staging: iio: adc: ad799x drop in_precision in favor of new in_type

From: Michael Hennerich <[email protected]>

drop in_precision in favor of new in_type
add sign and storagebits to struct ad799x_chip_info properly mask the results based on ad799x_chip_info:bits

---
 drivers/staging/iio/adc/ad799x.h      |    4 ++-
 drivers/staging/iio/adc/ad799x_core.c |   42 +++++++++++++++++++++++---------
 drivers/staging/iio/adc/ad799x_ring.c |    2 +-
 3 files changed, 34 insertions(+), 14 deletions(-)
drivers/staging/iio/adc/ad799x.h +3 -1
index 2325929..f023212 100644
@@ -97,7 +97,9 @@ struct ad799x_state;
 struct ad799x_chip_info {
 	u8				num_inputs;
 	u8				bits;
-	u16				int_vref_mv;
+	u8				storagebits;
+	char				sign;
+	unsigned int			int_vref_mv;
 	bool				monitor_mode;
 	u16				default_config;
 	struct attribute_group		*dev_attrs;
drivers/staging/iio/adc/ad799x_core.c +30 -12

133 lines not on this page · raw message

drivers/staging/iio/adc/ad799x_ring.c +1 -1
index d0217f8..c6871fa 100644
@@ -53,7 +53,7 @@ int ad799x_single_channel_from_ring(struct ad799x_state *st, long mask)
 		mask >>= 1;
 	}
 
-	ret = be16_to_cpu(ring_data[count]) & 0xFFF;
+	ret = be16_to_cpu(ring_data[count]);
 
 error_free_ring_data:
 	kfree(ring_data);
Signature · 1 line
1.6.0.2
#1 lore raw
Quoted 5 lines · On 10/07/10 13:58, [email protected] wrote:

From: Michael Hennerich <[email protected]>

drop in_precision in favor of new in_type
add sign and storagebits to struct ad799x_chip_info properly mask the results based on ad799x_chip_info:bits

This also fixes the bug from the scan elements move (as a side effect). Normally I'd say that needed flagging up but seeing how short a time the driver has been in place, the chances of it having bitten anyone are pretty low! Still if you re roll the patch it is probably worth adding a mention.

Couple of minor queries below.

Quoted 13 lines
---
 drivers/staging/iio/adc/ad799x.h      |    4 ++-
 drivers/staging/iio/adc/ad799x_core.c |   42 +++++++++++++++++++++++---------
 drivers/staging/iio/adc/ad799x_ring.c |    2 +-
 3 files changed, 34 insertions(+), 14 deletions(-)
drivers/staging/iio/adc/ad799x.h +0 -0
index 2325929..f023212 100644

drivers/staging/iio/adc/ad799x.h struct ad799x_state; · line 102

Quoted 7 lines
drivers/staging/iio/adc/ad799x.h +3 -1
@@ -97,7 +97,9 @@ struct ad799x_state;
 struct ad799x_chip_info {
 	u8				num_inputs;
 	u8				bits;
-	u16				int_vref_mv;
+	u8				storagebits;
+	char				sign;
+	unsigned int			int_vref_mv;

Why the type change? If it is needed, please submit as as separate patch as it definitely isn't conceptually linked to the rest we have here.

Quoted 34 lines
drivers/staging/iio/adc/ad799x.h +0 -0
 	bool				monitor_mode;
 	u16				default_config;
 	struct attribute_group		*dev_attrs;
drivers/staging/iio/adc/ad799x_core.c +8 -7
index 2589856..a804515 100644
@@ -123,17 +123,18 @@ static AD799X_SCAN_EL(5);
 static AD799X_SCAN_EL(6);
 static AD799X_SCAN_EL(7);
 
-static ssize_t ad799x_show_precision(struct device *dev,
+static ssize_t ad799x_show_type(struct device *dev,
 				struct device_attribute *attr,
 				char *buf)
 {
-	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	struct ad799x_state *st = iio_dev_get_devdata(dev_info);
-	return sprintf(buf, "%d\n", st->chip_info->bits);
-}
+	struct iio_ring_buffer *ring = dev_get_drvdata(dev);
+	struct iio_dev *indio_dev = ring->indio_dev;
+	struct ad799x_state *st = indio_dev->dev_data;
 
-static IIO_DEVICE_ATTR(in_precision, S_IRUGO, ad799x_show_precision,
-		       NULL, 0);
+	return sprintf(buf, "%c%d/%d\n", st->chip_info->sign,
+		       st->chip_info->bits, st->chip_info->storagebits);
+}
+static IIO_DEVICE_ATTR(in_type, S_IRUGO, ad799x_show_type, NULL, 0);
 
 static int ad7991_5_9_set_scan_mode(struct ad799x_state *st, unsigned mask)
 {

drivers/staging/iio/adc/ad799x_core.c static ssize_t ad799x_read_single_channel(struct device *dev, · line 189

Quoted 4 lines
drivers/staging/iio/adc/ad799x_core.c +1 -0
@@ -185,6 +186,7 @@ static ssize_t ad799x_read_single_channel(struct device *dev,
 		data = ret = ad799x_single_channel_from_ring(st, mask);
 		if (ret < 0)
 			goto error_ret;
+

Why the new line?

Quoted 45 lines
drivers/staging/iio/adc/ad799x_core.c +5 -5
 		ret = 0;
 	} else {
 		switch (st->id) {
@@ -211,11 +213,11 @@ static ssize_t ad799x_read_single_channel(struct device *dev,
 		if (ret < 0)
 			goto error_ret;
 
-		data = rxbuf[0] & 0xFFF;
+		data = rxbuf[0];
 	}
 
 	/* Pretty print the result */
-	len = sprintf(buf, "%u\n", data);
+	len = sprintf(buf, "%u\n", data & ((1 << (st->chip_info->bits)) - 1));
 
 error_ret:
 	mutex_unlock(&dev_info->mlock);
@@ -473,7 +475,7 @@ static struct attribute *ad7991_5_9_3_4_scan_el_attrs[] = {
 	&iio_const_attr_in2_index.dev_attr.attr,
 	&iio_scan_el_in3.dev_attr.attr,
 	&iio_const_attr_in3_index.dev_attr.attr,
-	&iio_dev_attr_in_precision.dev_attr.attr,
+	&iio_dev_attr_in_type.dev_attr.attr,
 	NULL,
 };
 
@@ -499,7 +501,7 @@ static struct attribute *ad7992_scan_el_attrs[] = {
 	&iio_const_attr_in0_index.dev_attr.attr,
 	&iio_scan_el_in1.dev_attr.attr,
 	&iio_const_attr_in1_index.dev_attr.attr,
-	&iio_dev_attr_in_precision.dev_attr.attr,
+	&iio_dev_attr_in_type.dev_attr.attr,
 	NULL,
 };
 
@@ -543,7 +545,7 @@ static struct attribute *ad7997_8_scan_el_attrs[] = {
 	&iio_const_attr_in6_index.dev_attr.attr,
 	&iio_scan_el_in7.dev_attr.attr,
 	&iio_const_attr_in7_index.dev_attr.attr,
-	&iio_dev_attr_in_precision.dev_attr.attr,
+	&iio_dev_attr_in_type.dev_attr.attr,
 	NULL,
 };
 

drivers/staging/iio/adc/ad799x_core.c static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { · line 676

Quoted 4 lines
drivers/staging/iio/adc/ad799x_core.c +1 -0
@@ -671,6 +673,8 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	[ad7991] = {
 		.num_inputs = 4,
 		.bits = 12,
+		.storagebits = 16,

Why have storage bits if it is always 16? It's also a characteristic of the buffer elements of the driver rather than the chip so it doesn't really make sense. I'd prefer to see it generated as a round up integer multiple of 8 from the bits value. That way the driver will nicely extend to 8 bit or 17bit+ devices should any exist.

Quoted 80 lines
drivers/staging/iio/adc/ad799x_core.c +15 -0
+		.sign = IIO_SCAN_EL_TYPE_UNSIGNED,
 		.int_vref_mv = 4096,
 		.dev_attrs = &ad7991_5_9_3_4_dev_attr_group,
 		.scan_attrs = &ad7991_5_9_3_4_scan_el_group,
@@ -679,6 +683,8 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	[ad7995] = {
 		.num_inputs = 4,
 		.bits = 10,
+		.storagebits = 16,
+		.sign = IIO_SCAN_EL_TYPE_UNSIGNED,
 		.int_vref_mv = 1024,
 		.dev_attrs = &ad7991_5_9_3_4_dev_attr_group,
 		.scan_attrs = &ad7991_5_9_3_4_scan_el_group,
@@ -687,6 +693,8 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	[ad7999] = {
 		.num_inputs = 4,
 		.bits = 10,
+		.storagebits = 16,
+		.sign = IIO_SCAN_EL_TYPE_UNSIGNED,
 		.int_vref_mv = 1024,
 		.dev_attrs = &ad7991_5_9_3_4_dev_attr_group,
 		.scan_attrs = &ad7991_5_9_3_4_scan_el_group,
@@ -695,6 +703,8 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	[ad7992] = {
 		.num_inputs = 2,
 		.bits = 12,
+		.storagebits = 16,
+		.sign = IIO_SCAN_EL_TYPE_UNSIGNED,
 		.int_vref_mv = 4096,
 		.monitor_mode = true,
 		.default_config = AD7998_ALERT_EN,
@@ -706,6 +716,8 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	[ad7993] = {
 		.num_inputs = 4,
 		.bits = 10,
+		.storagebits = 16,
+		.sign = IIO_SCAN_EL_TYPE_UNSIGNED,
 		.int_vref_mv = 1024,
 		.monitor_mode = true,
 		.default_config = AD7998_ALERT_EN,
@@ -717,6 +729,8 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	[ad7994] = {
 		.num_inputs = 4,
 		.bits = 12,
+		.storagebits = 16,
+		.sign = IIO_SCAN_EL_TYPE_UNSIGNED,
 		.int_vref_mv = 4096,
 		.monitor_mode = true,
 		.default_config = AD7998_ALERT_EN,
@@ -728,6 +742,8 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	[ad7997] = {
 		.num_inputs = 8,
 		.bits = 10,
+		.storagebits = 16,
+		.sign = IIO_SCAN_EL_TYPE_UNSIGNED,
 		.int_vref_mv = 1024,
 		.monitor_mode = true,
 		.default_config = AD7998_ALERT_EN,
@@ -739,6 +755,8 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	[ad7998] = {
 		.num_inputs = 8,
 		.bits = 12,
+		.storagebits = 16,
+		.sign = IIO_SCAN_EL_TYPE_UNSIGNED,
 		.int_vref_mv = 4096,
 		.monitor_mode = true,
 		.default_config = AD7998_ALERT_EN,
drivers/staging/iio/adc/ad799x_ring.c +1 -1
index d0217f8..c6871fa 100644
@@ -53,7 +53,7 @@ int ad799x_single_channel_from_ring(struct ad799x_state *st, long mask)
 		mask >>= 1;
 	}
 
-	ret = be16_to_cpu(ring_data[count]) & 0xFFF;
+	ret = be16_to_cpu(ring_data[count]);
 
 error_free_ring_data:
 	kfree(ring_data);
author maintainer
#2 lore raw

Jonathan Cameron wrote on 2010-10-07:

Quoted 27 lines · On 10/07/10 13:58, [email protected] wrote:
Quoted 5 lines

From: Michael Hennerich <[email protected]>

drop in_precision in favor of new in_type add sign and storagebits to struct ad799x_chip_info properly mask the results based on ad799x_chip_info:bits

This also fixes the bug from the scan elements move (as a side effect). Normally I'd say that needed flagging up but seeing how short a time the driver has been in place, the chances of it having bitten anyone are pretty low! Still if you re roll the patch it is probably worth adding a mention.

Couple of minor queries below.

Quoted 14 lines
---
 drivers/staging/iio/adc/ad799x.h      |    4 ++-
 drivers/staging/iio/adc/ad799x_core.c |   42

+++++++++++++++++++++++--------- drivers/staging/iio/adc/ad799x_ring.c
| 2 +- 3 files changed, 34 insertions(+), 14 deletions(-)

drivers/staging/iio/adc/ad799x.h +0 -0
index 2325929..f023212 100644
@@ -97,7 +97,9 @@ struct ad799x_state;  struct ad799x_chip_info {
     u8                              num_inputs;
Quoted 8 lines

drivers/staging/iio/adc/ad799x.h struct ad799x_state; · line 102

Quoted 5 lines
drivers/staging/iio/adc/ad799x.h +3 -1
     u8                              bits;
-    u16                             int_vref_mv;
+    u8                              storagebits;
+    char                            sign;
+    unsigned int                    int_vref_mv;

Why the type change? If it is needed, please submit as as separate patch as it definitely isn't conceptually linked to the rest we have here.

Not actually needed - I revert.

Quoted 32 lines
Quoted 21 lines
drivers/staging/iio/adc/ad799x.h +0 -0
     bool                            monitor_mode;
     u16                             default_config;
     struct attribute_group          *dev_attrs;
drivers/staging/iio/adc/ad799x_core.c +2 -5
index 2589856..a804515 100644
@@ -123,17 +123,18 @@ static AD799X_SCAN_EL(5);  static
 AD799X_SCAN_EL(6);  static AD799X_SCAN_EL(7);
 
-static ssize_t ad799x_show_precision(struct device *dev,
+static ssize_t ad799x_show_type(struct device *dev,
                             struct device_attribute *attr,
                             char *buf)
 {
-    struct iio_dev *dev_info = dev_get_drvdata(dev);
-    struct ad799x_state *st = iio_dev_get_devdata(dev_info);
-    return sprintf(buf, "%d\n", st->chip_info->bits);
-}
+    struct iio_ring_buffer *ring = dev_get_drvdata(dev);

drivers/staging/iio/adc/ad799x_core.c static AD799X_SCAN_EL(5); static

Quoted 10 lines
drivers/staging/iio/adc/ad799x_core.c +2 -2
+    struct iio_dev *indio_dev = ring->indio_dev;
+    struct ad799x_state *st = indio_dev->dev_data;
 
-static IIO_DEVICE_ATTR(in_precision, S_IRUGO, ad799x_show_precision,
-                   NULL, 0); +      return sprintf(buf, "%c%d/%d\n",
 st->chip_info->sign, +                      st->chip_info->bits,
 st->chip_info->storagebits); } static +IIO_DEVICE_ATTR(in_type,
 S_IRUGO, ad799x_show_type, NULL, 0);
 
 static int ad7991_5_9_set_scan_mode(struct ad799x_state *st,

unsigned

Quoted 7 lines
Quoted 6 lines

mask) { @@ -185,6 +186,7 @@ static ssize_t
ad799x_read_single_channel(struct device *dev,

             data = ret = ad799x_single_channel_from_ring(st, mask);
             if (ret < 0)
                     goto error_ret;

+

Why the new line?

Got there by accident

Quoted 49 lines

drivers/staging/iio/adc/ad799x_core.c static ssize_t

Quoted 4 lines
             ret = 0;
     } else {
             switch (st->id) {
drivers/staging/iio/adc/ad799x_core.c +0 -0
@@ -211,11 +213,11 @@ static ssize_t

ad799x_read_single_channel(struct device *dev,

drivers/staging/iio/adc/ad799x_core.c static struct attribute

Quoted 14 lines
drivers/staging/iio/adc/ad799x_core.c +3 -2
             if (ret < 0)
                     goto error_ret;
-            data = rxbuf[0] & 0xFFF;
+            data = rxbuf[0];
     }
 
     /* Pretty print the result */
-    len = sprintf(buf, "%u\n", data);
+    len = sprintf(buf, "%u\n", data & ((1 << (st->chip_info->bits)) -
+1));
 
 error_ret:
     mutex_unlock(&dev_info->mlock);
@@ -473,7 +475,7 @@ static struct attribute

*ad7991_5_9_3_4_scan_el_attrs[] = {

Quoted 9 lines
drivers/staging/iio/adc/ad799x_core.c +1 -1
     &iio_const_attr_in2_index.dev_attr.attr,
     &iio_scan_el_in3.dev_attr.attr,
     &iio_const_attr_in3_index.dev_attr.attr,
-    &iio_dev_attr_in_precision.dev_attr.attr,
+    &iio_dev_attr_in_type.dev_attr.attr,
     NULL,
 };
@@ -499,7 +501,7 @@ static struct attribute *ad7992_scan_el_attrs[]

=

{

drivers/staging/iio/adc/ad799x_core.c static struct attribute · line 545

Quoted 9 lines
     &iio_const_attr_in0_index.dev_attr.attr,
     &iio_scan_el_in1.dev_attr.attr,
     &iio_const_attr_in1_index.dev_attr.attr,
drivers/staging/iio/adc/ad799x_core.c +1 -1
-    &iio_dev_attr_in_precision.dev_attr.attr,
+    &iio_dev_attr_in_type.dev_attr.attr,
     NULL,
 };
@@ -543,7 +545,7 @@ static struct attribute
 *ad7997_8_scan_el_attrs[]

= {

drivers/staging/iio/adc/ad799x_core.c static const struct ad799x_chip_info

Quoted 8 lines
drivers/staging/iio/adc/ad799x_core.c +1 -1
     &iio_const_attr_in6_index.dev_attr.attr,
     &iio_scan_el_in7.dev_attr.attr,
     &iio_const_attr_in7_index.dev_attr.attr,
-    &iio_dev_attr_in_precision.dev_attr.attr,
+    &iio_dev_attr_in_type.dev_attr.attr,
     NULL,
 };
@@ -671,6 +673,8 @@ static const struct ad799x_chip_info

ad799x_chip_info_tbl[] = {

Quoted 7 lines

drivers/staging/iio/adc/ad799x_core.c static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { · line 676

Quoted 4 lines
drivers/staging/iio/adc/ad799x_core.c +1 -0
     [ad7991] = {
             .num_inputs = 4,
             .bits = 12,
+            .storagebits = 16,

Why have storage bits if it is always 16? It's also a characteristic of the buffer elements of the driver rather than the chip so it doesn't really make sense.

We use storagebits in in_type. In a different driver that I'm currently preparing for RFC. I also use storagebits to characterize the buffer elements.
But here you're right it doesn't make too much sense.

Quoted 2 lines

I'd prefer to see it generated as a round up integer multiple of 8 from the bits value.

Well that doesn't always work. There are devices that are 8-bit but require an 16-bit buffer. I think you remember the need for the in_type shift extension.
They are type u8/16>>4

Quoted 68 lines

That way the driver will nicely
extend to 8 bit or 17bit+ devices should any exist.

drivers/staging/iio/adc/ad799x_core.c static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {

Quoted 4 lines
drivers/staging/iio/adc/ad799x_core.c +1 -0
+            .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
             .int_vref_mv = 4096,
             .dev_attrs = &ad7991_5_9_3_4_dev_attr_group,
             .scan_attrs = &ad7991_5_9_3_4_scan_el_group, @@ -679,6

+683,8 @@

drivers/staging/iio/adc/ad799x_core.c static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {

Quoted 9 lines
static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
     [ad7995] = {
             .num_inputs = 4,
             .bits = 10,
drivers/staging/iio/adc/ad799x_core.c +2 -0
+            .storagebits = 16,
+            .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
             .int_vref_mv = 1024,
             .dev_attrs = &ad7991_5_9_3_4_dev_attr_group,
             .scan_attrs = &ad7991_5_9_3_4_scan_el_group, @@ -687,6

+693,8 @@

drivers/staging/iio/adc/ad799x_core.c static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {

Quoted 9 lines
static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
     [ad7999] = {
             .num_inputs = 4,
             .bits = 10,
drivers/staging/iio/adc/ad799x_core.c +2 -0
+            .storagebits = 16,
+            .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
             .int_vref_mv = 1024,
             .dev_attrs = &ad7991_5_9_3_4_dev_attr_group,
             .scan_attrs = &ad7991_5_9_3_4_scan_el_group, @@ -695,6

+703,8 @@

Quoted 10 lines
static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
     [ad7992] = {
             .num_inputs = 2,
             .bits = 12,
drivers/staging/iio/adc/ad799x_core.c +2 -0
+            .storagebits = 16,
+            .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
             .int_vref_mv = 4096,
             .monitor_mode = true,
             .default_config = AD7998_ALERT_EN, @@ -706,6 +716,8 @@ static

const struct ad799x_chip_info

ad799x_chip_info_tbl[] = {

Quoted 9 lines
     [ad7993] = {
             .num_inputs = 4,
             .bits = 10,
drivers/staging/iio/adc/ad799x_core.c +2 -0
+            .storagebits = 16,
+            .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
             .int_vref_mv = 1024,
             .monitor_mode = true,
             .default_config = AD7998_ALERT_EN, @@ -717,6 +729,8 @@ static

const struct ad799x_chip_info

ad799x_chip_info_tbl[] = {

Quoted 9 lines
     [ad7994] = {
             .num_inputs = 4,
             .bits = 12,
drivers/staging/iio/adc/ad799x_core.c +2 -0
+            .storagebits = 16,
+            .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
             .int_vref_mv = 4096,
             .monitor_mode = true,
             .default_config = AD7998_ALERT_EN, @@ -728,6 +742,8 @@ static

const struct ad799x_chip_info

ad799x_chip_info_tbl[] = {

Quoted 9 lines
     [ad7997] = {
             .num_inputs = 8,
             .bits = 10,
drivers/staging/iio/adc/ad799x_core.c +2 -0
+            .storagebits = 16,
+            .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
             .int_vref_mv = 1024,
             .monitor_mode = true,
             .default_config = AD7998_ALERT_EN, @@ -739,6 +755,8 @@ static

const struct ad799x_chip_info

ad799x_chip_info_tbl[] = {

Quoted 22 lines

drivers/staging/iio/adc/ad799x_ring.c int ad799x_single_channel_from_ring(struct

Quoted 14 lines
     [ad7998] = {
             .num_inputs = 8,
             .bits = 12,
drivers/staging/iio/adc/ad799x_core.c +2 -0
+            .storagebits = 16,
+            .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
             .int_vref_mv = 4096,
             .monitor_mode = true,
             .default_config = AD7998_ALERT_EN, diff --git

a/drivers/staging/iio/adc/ad799x_ring.c
b/drivers/staging/iio/adc/ad799x_ring.c
index d0217f8..c6871fa 100644

drivers/staging/iio/adc/ad799x_ring.c +0 -0
@@ -53,7 +53,7 @@ int ad799x_single_channel_from_ring(struct

ad799x_state *st, long mask)

Quoted 7 lines
drivers/staging/iio/adc/ad799x_ring.c +1 -1
             mask >>= 1;
     }
-    ret = be16_to_cpu(ring_data[count]) & 0xFFF;
+    ret = be16_to_cpu(ring_data[count]);
 
 error_free_ring_data:
     kfree(ring_data);

Greetings,
Michael

Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen
Sitz der Gesellschaft Muenchen, Registergericht Muenchen HRB 4036 Geschaeftsfuehrer Thomas Wessel, William A. Martin, Margaret Seif

#3 lore raw
Quoted 142 lines · Michael

Jonathan Cameron wrote on 2010-10-07:

Quoted 27 lines · On 10/07/10 13:58, [email protected] wrote:
Quoted 5 lines

From: Michael Hennerich <[email protected]>

drop in_precision in favor of new in_type add sign and storagebits to struct ad799x_chip_info properly mask the results based on ad799x_chip_info:bits

This also fixes the bug from the scan elements move (as a side effect). Normally I'd say that needed flagging up but seeing how short a time the driver has been in place, the chances of it having bitten anyone are pretty low! Still if you re roll the patch it is probably worth adding a mention.

Couple of minor queries below.

Quoted 14 lines
---
 drivers/staging/iio/adc/ad799x.h      |    4 ++-
 drivers/staging/iio/adc/ad799x_core.c |   42

+++++++++++++++++++++++--------- drivers/staging/iio/adc/ad799x_ring.c
| 2 +- 3 files changed, 34 insertions(+), 14 deletions(-)

drivers/staging/iio/adc/ad799x.h +0 -0
index 2325929..f023212 100644
@@ -97,7 +97,9 @@ struct ad799x_state;  struct ad799x_chip_info {
     u8                              num_inputs;
Quoted 8 lines

drivers/staging/iio/adc/ad799x.h struct ad799x_state; · line 102

Quoted 5 lines
drivers/staging/iio/adc/ad799x.h +3 -1
     u8                              bits;
-    u16                             int_vref_mv;
+    u8                              storagebits;
+    char                            sign;
+    unsigned int                    int_vref_mv;

Why the type change? If it is needed, please submit as as separate patch as it definitely isn't conceptually linked to the rest we have here.

Not actually needed - I revert.

Quoted 32 lines
Quoted 21 lines
drivers/staging/iio/adc/ad799x.h +0 -0
     bool                            monitor_mode;
     u16                             default_config;
     struct attribute_group          *dev_attrs;
drivers/staging/iio/adc/ad799x_core.c +2 -5
index 2589856..a804515 100644
@@ -123,17 +123,18 @@ static AD799X_SCAN_EL(5);  static
 AD799X_SCAN_EL(6);  static AD799X_SCAN_EL(7);
 
-static ssize_t ad799x_show_precision(struct device *dev,
+static ssize_t ad799x_show_type(struct device *dev,
                             struct device_attribute *attr,
                             char *buf)
 {
-    struct iio_dev *dev_info = dev_get_drvdata(dev);
-    struct ad799x_state *st = iio_dev_get_devdata(dev_info);
-    return sprintf(buf, "%d\n", st->chip_info->bits);
-}
+    struct iio_ring_buffer *ring = dev_get_drvdata(dev);

drivers/staging/iio/adc/ad799x_core.c static AD799X_SCAN_EL(5); static

Quoted 10 lines
drivers/staging/iio/adc/ad799x_core.c +2 -2
+    struct iio_dev *indio_dev = ring->indio_dev;
+    struct ad799x_state *st = indio_dev->dev_data;
 
-static IIO_DEVICE_ATTR(in_precision, S_IRUGO, ad799x_show_precision,
-                   NULL, 0); +      return sprintf(buf, "%c%d/%d\n",
 st->chip_info->sign, +                      st->chip_info->bits,
 st->chip_info->storagebits); } static +IIO_DEVICE_ATTR(in_type,
 S_IRUGO, ad799x_show_type, NULL, 0);
 
 static int ad7991_5_9_set_scan_mode(struct ad799x_state *st,

unsigned

Quoted 7 lines
Quoted 6 lines

mask) { @@ -185,6 +186,7 @@ static ssize_t
ad799x_read_single_channel(struct device *dev,

             data = ret = ad799x_single_channel_from_ring(st, mask);
             if (ret < 0)
                     goto error_ret;

+

Why the new line?

Got there by accident

Quoted 49 lines

drivers/staging/iio/adc/ad799x_core.c static ssize_t

Quoted 4 lines
             ret = 0;
     } else {
             switch (st->id) {
drivers/staging/iio/adc/ad799x_core.c +0 -0
@@ -211,11 +213,11 @@ static ssize_t

ad799x_read_single_channel(struct device *dev,

drivers/staging/iio/adc/ad799x_core.c static struct attribute

Quoted 14 lines
drivers/staging/iio/adc/ad799x_core.c +3 -2
             if (ret < 0)
                     goto error_ret;
-            data = rxbuf[0] & 0xFFF;
+            data = rxbuf[0];
     }
 
     /* Pretty print the result */
-    len = sprintf(buf, "%u\n", data);
+    len = sprintf(buf, "%u\n", data & ((1 << (st->chip_info->bits)) -
+1));
 
 error_ret:
     mutex_unlock(&dev_info->mlock);
@@ -473,7 +475,7 @@ static struct attribute

*ad7991_5_9_3_4_scan_el_attrs[] = {

Quoted 9 lines
drivers/staging/iio/adc/ad799x_core.c +1 -1
     &iio_const_attr_in2_index.dev_attr.attr,
     &iio_scan_el_in3.dev_attr.attr,
     &iio_const_attr_in3_index.dev_attr.attr,
-    &iio_dev_attr_in_precision.dev_attr.attr,
+    &iio_dev_attr_in_type.dev_attr.attr,
     NULL,
 };
@@ -499,7 +501,7 @@ static struct attribute *ad7992_scan_el_attrs[]

=

{

drivers/staging/iio/adc/ad799x_core.c static struct attribute · line 545

Quoted 9 lines
     &iio_const_attr_in0_index.dev_attr.attr,
     &iio_scan_el_in1.dev_attr.attr,
     &iio_const_attr_in1_index.dev_attr.attr,
drivers/staging/iio/adc/ad799x_core.c +1 -1
-    &iio_dev_attr_in_precision.dev_attr.attr,
+    &iio_dev_attr_in_type.dev_attr.attr,
     NULL,
 };
@@ -543,7 +545,7 @@ static struct attribute
 *ad7997_8_scan_el_attrs[]

= {

drivers/staging/iio/adc/ad799x_core.c static const struct ad799x_chip_info

Quoted 8 lines
drivers/staging/iio/adc/ad799x_core.c +1 -1
     &iio_const_attr_in6_index.dev_attr.attr,
     &iio_scan_el_in7.dev_attr.attr,
     &iio_const_attr_in7_index.dev_attr.attr,
-    &iio_dev_attr_in_precision.dev_attr.attr,
+    &iio_dev_attr_in_type.dev_attr.attr,
     NULL,
 };
@@ -671,6 +673,8 @@ static const struct ad799x_chip_info

ad799x_chip_info_tbl[] = {

Quoted 7 lines

drivers/staging/iio/adc/ad799x_core.c static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { · line 676

Quoted 4 lines
drivers/staging/iio/adc/ad799x_core.c +1 -0
     [ad7991] = {
             .num_inputs = 4,
             .bits = 12,
+            .storagebits = 16,

Why have storage bits if it is always 16? It's also a characteristic of the buffer elements of the driver rather than the chip so it doesn't really make sense.

We use storagebits in in_type. In a different driver that I'm currently preparing for RFC. I also use storagebits to characterize the buffer elements.
But here you're right it doesn't make too much sense.

Quoted 6 lines
Quoted 2 lines

I'd prefer to see it generated as a round up integer multiple of 8 from the bits value.

Well that doesn't always work. There are devices that are 8-bit but require an 16-bit buffer. I think you remember the need for the in_type shift extension.
They are type u8/16>>4

Good point. Still, lets only have the variable where it is needed.

Quoted 104 lines
Quoted 69 lines

That way the driver will nicely
extend to 8 bit or 17bit+ devices should any exist.

drivers/staging/iio/adc/ad799x_core.c static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {

Quoted 4 lines
drivers/staging/iio/adc/ad799x_core.c +1 -0
+            .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
             .int_vref_mv = 4096,
             .dev_attrs = &ad7991_5_9_3_4_dev_attr_group,
             .scan_attrs = &ad7991_5_9_3_4_scan_el_group, @@ -679,6

+683,8 @@

drivers/staging/iio/adc/ad799x_core.c static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {

Quoted 9 lines
static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
     [ad7995] = {
             .num_inputs = 4,
             .bits = 10,
drivers/staging/iio/adc/ad799x_core.c +2 -0
+            .storagebits = 16,
+            .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
             .int_vref_mv = 1024,
             .dev_attrs = &ad7991_5_9_3_4_dev_attr_group,
             .scan_attrs = &ad7991_5_9_3_4_scan_el_group, @@ -687,6

+693,8 @@

drivers/staging/iio/adc/ad799x_core.c static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {

Quoted 9 lines
static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
     [ad7999] = {
             .num_inputs = 4,
             .bits = 10,
drivers/staging/iio/adc/ad799x_core.c +2 -0
+            .storagebits = 16,
+            .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
             .int_vref_mv = 1024,
             .dev_attrs = &ad7991_5_9_3_4_dev_attr_group,
             .scan_attrs = &ad7991_5_9_3_4_scan_el_group, @@ -695,6

+703,8 @@

Quoted 10 lines
static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
     [ad7992] = {
             .num_inputs = 2,
             .bits = 12,
drivers/staging/iio/adc/ad799x_core.c +2 -0
+            .storagebits = 16,
+            .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
             .int_vref_mv = 4096,
             .monitor_mode = true,
             .default_config = AD7998_ALERT_EN, @@ -706,6 +716,8 @@ static

const struct ad799x_chip_info

ad799x_chip_info_tbl[] = {

Quoted 9 lines
     [ad7993] = {
             .num_inputs = 4,
             .bits = 10,
drivers/staging/iio/adc/ad799x_core.c +2 -0
+            .storagebits = 16,
+            .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
             .int_vref_mv = 1024,
             .monitor_mode = true,
             .default_config = AD7998_ALERT_EN, @@ -717,6 +729,8 @@ static

const struct ad799x_chip_info

ad799x_chip_info_tbl[] = {

Quoted 9 lines
     [ad7994] = {
             .num_inputs = 4,
             .bits = 12,
drivers/staging/iio/adc/ad799x_core.c +2 -0
+            .storagebits = 16,
+            .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
             .int_vref_mv = 4096,
             .monitor_mode = true,
             .default_config = AD7998_ALERT_EN, @@ -728,6 +742,8 @@ static

const struct ad799x_chip_info

ad799x_chip_info_tbl[] = {

Quoted 9 lines
     [ad7997] = {
             .num_inputs = 8,
             .bits = 10,
drivers/staging/iio/adc/ad799x_core.c +2 -0
+            .storagebits = 16,
+            .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
             .int_vref_mv = 1024,
             .monitor_mode = true,
             .default_config = AD7998_ALERT_EN, @@ -739,6 +755,8 @@ static

const struct ad799x_chip_info

ad799x_chip_info_tbl[] = {

Quoted 22 lines

drivers/staging/iio/adc/ad799x_ring.c int ad799x_single_channel_from_ring(struct

Quoted 14 lines
     [ad7998] = {
             .num_inputs = 8,
             .bits = 12,
drivers/staging/iio/adc/ad799x_core.c +2 -0
+            .storagebits = 16,
+            .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
             .int_vref_mv = 4096,
             .monitor_mode = true,
             .default_config = AD7998_ALERT_EN, diff --git

a/drivers/staging/iio/adc/ad799x_ring.c
b/drivers/staging/iio/adc/ad799x_ring.c
index d0217f8..c6871fa 100644

drivers/staging/iio/adc/ad799x_ring.c +0 -0
@@ -53,7 +53,7 @@ int ad799x_single_channel_from_ring(struct

ad799x_state *st, long mask)

Quoted 7 lines
drivers/staging/iio/adc/ad799x_ring.c +1 -1
             mask >>= 1;
     }
-    ret = be16_to_cpu(ring_data[count]) & 0xFFF;
+    ret = be16_to_cpu(ring_data[count]);
 
 error_free_ring_data:
     kfree(ring_data);

Greetings,
Michael

Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen
Sitz der Gesellschaft Muenchen, Registergericht Muenchen HRB 4036 Geschaeftsfuehrer Thomas Wessel, William A. Martin, Margaret Seif

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html