Skip to contentSkip to conversation

iio: adc: ti-ads1298: Three driver cleanups

PATCH Superseded Md Shofiqul Islam 2 participants 7 messages May 6 – May 7 IIO

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover iio: adc: ti-ads1298: Three driver cleanups

Three small cleanups to the TI ADS1298 medical ECG ADC driver:

1. Add missing parentheses around macro parameter in ADS1298_REG_CHnSET() to follow kernel macro coding style.

2. Fix a comment that incorrectly states 40ms for a 250Hz conversion period — the correct value is 4ms.

3. Remove the internal test signal configuration from init. The driver was enabling INT_TEST, TEST_AMP, and TEST_FREQ_FAST during device initialization, which is inappropriate for a medical ADC in normal operation. Only the RESERVED bit (required by the datasheet) is kept.

Md Shofiqul Islam (3):
iio: adc: ti-ads1298: Add parentheses around macro parameter
iio: adc: ti-ads1298: Fix incorrect timeout comment
iio: adc: ti-ads1298: Don't enable internal test signal during init

 drivers/iio/adc/ti-ads1298.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
Signature · 1 line
2.54.0.windows.1
#1 lore raw

PATCH 1/3 iio: adc: ti-ads1298: Add parentheses around macro parameter

ADS1298_REG_CHnSET() is missing parentheses around the parameter 'n'. Add them to follow kernel macro coding style and prevent potential operator precedence issues if the argument is an expression.

---
 drivers/iio/adc/ti-ads1298.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ti-ads1298.c +1 -1
index ae30b47e45..cf5f954206 100644
@@ -66,7 +66,7 @@
 #define ADS1298_MASK_CONFIG3_VREF_4V		BIT(5)
 
 #define ADS1298_REG_LOFF	0x04
-#define ADS1298_REG_CHnSET(n)	(0x05 + n)
+#define ADS1298_REG_CHnSET(n)	(0x05 + (n))
 #define ADS1298_MASK_CH_PD		BIT(7)
 #define ADS1298_MASK_CH_PGA		GENMASK(6, 4)
 #define ADS1298_MASK_CH_MUX		GENMASK(2, 0)
Signature · 1 line
2.54.0.windows.1
#3 lore raw

PATCH 2/3 iio: adc: ti-ads1298: Fix incorrect timeout comment

In reply to Md Shofiqul Islam

At the lowest supported data rate of 250Hz, one conversion period is 4ms, not 40ms. Fix the comment to correctly reflect the timing. The 50ms timeout value itself is correct as a conservative margin.

---
 drivers/iio/adc/ti-ads1298.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ti-ads1298.c +1 -1
index cf5f954206..186bda3087 100644
@@ -210,7 +210,7 @@ static int ads1298_read_one(struct ads1298_private *priv, int chan_index)
 		return ret;
 	}
 
-	/* Cannot take longer than 40ms (250Hz) */
+	/* Cannot take longer than 4ms at the lowest rate (250Hz) */
 	ret = wait_for_completion_timeout(&priv->completion, msecs_to_jiffies(50));
 	if (!ret)
 		return -ETIMEDOUT;
Signature · 1 line
2.54.0.windows.1
#5 lore raw

PATCH 3/3 iio: adc: ti-ads1298: Don't enable internal test signal during init

In reply to Md Shofiqul Islam

The driver was enabling the internal test signal (INT_TEST), double amplitude (TEST_AMP), and fast frequency (TEST_FREQ_FAST) bits in CONFIG2 during initialization. These bits activate an internal square wave generator intended for device testing and calibration, not normal ECG operation.

While the test signal does not affect channel measurements unless the channel MUX is explicitly set to route it (MUX = 101), enabling the test signal generator unnecessarily increases power consumption and is inappropriate for a medical ADC driver in normal operation.

Keep only the RESERVED bit which the datasheet requires to always be written as 1.

---
 drivers/iio/adc/ti-ads1298.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/iio/adc/ti-ads1298.c +2 -5
index 186bda3087..360dfd2fc8 100644
@@ -615,12 +615,9 @@ static int ads1298_init(struct iio_dev *indio_dev)
 	if (!indio_dev->name)
 		return -ENOMEM;
 
-	/* Enable internal test signal, double amplitude, double frequency */
+	/* CONFIG2: reserved bit must always be written as 1 per datasheet */
 	ret = regmap_write(priv->regmap, ADS1298_REG_CONFIG2,
-			   ADS1298_MASK_CONFIG2_RESERVED |
-			   ADS1298_MASK_CONFIG2_INT_TEST |
-			   ADS1298_MASK_CONFIG2_TEST_AMP |
-			   ADS1298_MASK_CONFIG2_TEST_FREQ_FAST);
+			   ADS1298_MASK_CONFIG2_RESERVED);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.54.0.windows.1
#4 lore raw

Re: [PATCH 2/3] iio: adc: ti-ads1298: Fix incorrect timeout comment

In reply to Md Shofiqul Islam
Quoted 3 lines · Md Shofiqul Islam

At the lowest supported data rate of 250Hz, one conversion period is 4ms, not 40ms. Fix the comment to correctly reflect the timing. The 50ms timeout value itself is correct as a conservative margin.

The 50ms value is also wrong then, change it to 5. That's already more than enough margin.

Quoted 19 lines
---
  drivers/iio/adc/ti-ads1298.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ti-ads1298.c +1 -1
index cf5f954206..186bda3087 100644
@@ -210,7 +210,7 @@ static int ads1298_read_one(struct ads1298_private *priv, int chan_index)
  		return ret;
  	}
 
-	/* Cannot take longer than 40ms (250Hz) */
+	/* Cannot take longer than 4ms at the lowest rate (250Hz) */
  	ret = wait_for_completion_timeout(&priv->completion, msecs_to_jiffies(50));
  	if (!ret)
  		return -ETIMEDOUT;
Signature · 10 lines
Mike Looijmans
System Expert

TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: [email protected]
W: www.topic.nl
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] iio: adc: ti-ads1298: Add parentheses around macro parameter

In reply to Md Shofiqul Islam
Quoted 3 lines · Md Shofiqul Islam

ADS1298_REG_CHnSET() is missing parentheses around the parameter 'n'. Add them to follow kernel macro coding style and prevent potential operator precedence issues if the argument is an expression.

Quoted 19 lines
---
  drivers/iio/adc/ti-ads1298.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ti-ads1298.c +1 -1
index ae30b47e45..cf5f954206 100644
@@ -66,7 +66,7 @@
  #define ADS1298_MASK_CONFIG3_VREF_4V		BIT(5)
 
  #define ADS1298_REG_LOFF	0x04
-#define ADS1298_REG_CHnSET(n)	(0x05 + n)
+#define ADS1298_REG_CHnSET(n)	(0x05 + (n))
  #define ADS1298_MASK_CH_PD		BIT(7)
  #define ADS1298_MASK_CH_PGA		GENMASK(6, 4)
  #define ADS1298_MASK_CH_MUX		GENMASK(2, 0)
Signature · 10 lines
Mike Looijmans
System Expert

TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: [email protected]
W: www.topic.nl
#6 lore raw

Re: [PATCH 3/3] iio: adc: ti-ads1298: Don't enable internal test signal during init

In reply to Md Shofiqul Islam
Quoted 6 lines · Md Shofiqul Islam

The driver was enabling the internal test signal (INT_TEST), double amplitude (TEST_AMP), and fast frequency (TEST_FREQ_FAST) bits in CONFIG2 during initialization. These bits activate an internal square wave generator intended for device testing and calibration, not normal ECG operation.

Quoted 7 lines

While the test signal does not affect channel measurements unless the channel MUX is explicitly set to route it (MUX = 101), enabling the test signal generator unnecessarily increases power consumption and is inappropriate for a medical ADC driver in normal operation.

Keep only the RESERVED bit which the datasheet requires to always be written as 1.

This boils down to just leaving the register at its default value. In that case, I'd suggest removing this completely.

Quoted 25 lines
---
  drivers/iio/adc/ti-ads1298.c | 7 ++-----
  1 file changed, 2 insertions(+), 5 deletions(-)
drivers/iio/adc/ti-ads1298.c +2 -5
index 186bda3087..360dfd2fc8 100644
@@ -615,12 +615,9 @@ static int ads1298_init(struct iio_dev *indio_dev)
  	if (!indio_dev->name)
  		return -ENOMEM;
 
-	/* Enable internal test signal, double amplitude, double frequency */
+	/* CONFIG2: reserved bit must always be written as 1 per datasheet */
  	ret = regmap_write(priv->regmap, ADS1298_REG_CONFIG2,
-			   ADS1298_MASK_CONFIG2_RESERVED |
-			   ADS1298_MASK_CONFIG2_INT_TEST |
-			   ADS1298_MASK_CONFIG2_TEST_AMP |
-			   ADS1298_MASK_CONFIG2_TEST_FREQ_FAST);
+			   ADS1298_MASK_CONFIG2_RESERVED);
  	if (ret)
  		return ret;
 
Signature · 10 lines
Mike Looijmans
System Expert

TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: [email protected]
W: www.topic.nl