Skip to contentSkip to conversation

dt-bindings: iio: adc: ti-ads1298: Add bindings

PATCH Superseded Mike Looijmans 3 participants 5 messages Feb 2, 2024 – Feb 5, 2024 1 message not in the archive

Subsystems (2)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.50455eb1-2ccc-4e6a-b8ed-0c142743ae03@emailsignatures365.codetwo.com

#1 lore raw

PATCH v2 1/2 dt-bindings: iio: adc: ti-ads1298: Add bindings

Bindings for the TI ADS1298 medical ADC. This device is typically used for ECG and similar measurements. Supports data acquisition at configurable scale and sampling frequency.

The device has so many options for connecting stuff, at this point the bindings aren't nearly complete but partial bindings are better than no bindings at all.

---

Changes in v2:
Remove "clk" name
Add datasheet and "incomplete" note

 .../bindings/iio/adc/ti,ads1298.yaml          | 80 +++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/ti,ads1298.yaml
Documentation/devicetree/bindings/iio/adc/ti,ads1298.yaml new file +80 -0
new file mode 100644
index 000000000000..bf5a43a81d59
@@ -0,0 +1,80 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/ti,ads1298.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments' ads1298 medical ADC chips
+
+description: |
+  Datasheet at: https://www.ti.com/product/ADS1298
+  Bindings for this chip aren't complete.
+
+maintainers:
+  - Mike Looijmans <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - ti,ads1298
+
+  reg:
+    maxItems: 1
+
+  spi-cpha: true
+
+  reset-gpios:
+    maxItems: 1
+
+  avdd-supply:
+    description:
+      Analog power supply, voltage between AVDD and AVSS. When providing a
+      symmetric +/- 2.5V, the regulator should report 5V.
+
+  vref-supply:
+    description:
+      Optional reference voltage. If omitted, internal reference is used,
+      which is 2.4V when analog supply is below 4.4V, 4V otherwise.
+
+  clocks:
+    description: Optional 2.048 MHz external source clock on CLK pin
+    maxItems: 1
+
+  interrupts:
+    description: Interrupt on DRDY pin, triggers on falling edge
+    maxItems: 1
+
+  label: true
+
+required:
+  - compatible
+  - reg
+  - avdd-supply
+  - interrupts
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@1 {
+          reg = <1>;
+          compatible = "ti,ads1298";
+          label = "ads1298-1-ecg";
+          avdd-supply = <&reg_iso_5v_a>;
+          clocks = <&clk_ads1298>;
+          interrupt-parent = <&gpio0>;
+          interrupts = <78 IRQ_TYPE_EDGE_FALLING>;
+          spi-max-frequency = <20000000>;
+          spi-cpha;
+        };
+    };
+...
Signature · 18 lines
2.34.1


Met vriendelijke groet / kind regards,

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

Please consider the environment before printing this e-mail
#2 lore raw

PATCH v2 2/2 iio: adc: ti-ads1298: Add driver

Skeleton driver for the TI ADS1298 medical ADC. This device is typically used for ECG and similar measurements. Supports data acquisition at configurable scale and sampling frequency.

---

Changes in v2:
Remove accidental "default y" in Kconfig
Indentation and similar cosmetic fixes
Magic numbers into constants
Short return paths in read_raw and write_raw
DMA buffer alignment
Bounce buffer is u32 instead of u8
Avoid races using claim_direct_mode
Check errors on all register accesses
Immediate SPI restart to reduce underruns
"name" is chip name, not unique

 drivers/iio/adc/Kconfig      |  11 +
 drivers/iio/adc/Makefile     |   1 +
 drivers/iio/adc/ti-ads1298.c | 769 +++++++++++++++++++++++++++++++++++
 3 files changed, 781 insertions(+)
 create mode 100644 drivers/iio/adc/ti-ads1298.c
drivers/iio/adc/Kconfig +11 -0
index 35f9867da12c..1d2d2eff15da 100644
@@ -1318,6 +1318,17 @@ config TI_ADS8688
 	  This driver can also be built as a module. If so, the module will be
 	  called ti-ads8688.
 
+config TI_ADS1298
+	tristate "Texas Instruments ADS1298"
+	depends on SPI
+	select IIO_BUFFER
+	help
+	  If you say yes here you get support for Texas Instruments ADS1298
+	  medical ADC chips
+
+	  This driver can also be built as a module. If so, the module will be
+	  called ti-ads1298.
+
 config TI_ADS124S08
 	tristate "Texas Instruments ADS124S08"
 	depends on SPI
drivers/iio/adc/Makefile +1 -0
index bee11d442af4..ff0e3633eded 100644
@@ -117,6 +117,7 @@ obj-$(CONFIG_TI_ADS7924) += ti-ads7924.o
 obj-$(CONFIG_TI_ADS7950) += ti-ads7950.o
 obj-$(CONFIG_TI_ADS8344) += ti-ads8344.o
 obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o
+obj-$(CONFIG_TI_ADS1298) += ti-ads1298.o
 obj-$(CONFIG_TI_ADS124S08) += ti-ads124s08.o
 obj-$(CONFIG_TI_ADS131E08) += ti-ads131e08.o
 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
drivers/iio/adc/ti-ads1298.c new file +769 -0

769 lines not on this page · raw message

Signature · 18 lines
2.34.1


Met vriendelijke groet / kind regards,

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

Please consider the environment before printing this e-mail
maintainer
#3 lore raw

Re: [PATCH v2 2/2] iio: adc: ti-ads1298: Add driver

Quoted 6 lines · On Fri, 2 Feb 2024 11:59:01 +0100 Mike Looijmans <[email protected]>…

Skeleton driver for the TI ADS1298 medical ADC. This device is typically used for ECG and similar measurements. Supports data acquisition at configurable scale and sampling frequency.

Hi Mike,

A few minor things I'd missed before.

I'm still interested in why more standard interrupt handling isn't good enough here (see reply to v1 thread) but if we can't get to the bottom of that (or do figure it out and we can't fix it) then this doesn't look too bad so I'll accept the complex handling.

J

drivers/iio/adc/ti-ads1298.c line 23

Quoted 12 lines
drivers/iio/adc/ti-ads1298.c new file +5 -0
new file mode 100644
index 000000000000..539598b9f3fa
@@ -0,0 +1,769 @@
 
+
+#include <linux/iio/iio.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/kfifo_buf.h>
+#include <linux/iio/sysfs.h>

I don't see any custom ABI, so shouldn't need this.

Quoted 13 lines
drivers/iio/adc/ti-ads1298.c new file +10 -0
+
+#include <asm/unaligned.h>
+
 
 
 
+static int ads1298_reg_read(void *context, unsigned int reg, unsigned int *val)
+{
+	struct ads1298_private *priv = context;
+	struct spi_transfer reg_read_xfer = {
+		.tx_buf = priv->cmd_buffer,
+		.rx_buf = priv->cmd_buffer,
+		.len = 3,

drivers/iio/adc/ti-ads1298.c line 395

Quoted 10 lines
drivers/iio/adc/ti-ads1298.c new file +10 -0
+		.speed_hz = ADS1298_SPI_BUS_SPEED_SLOW,
+		.delay = {
+			.value = 2,
+			.unit = SPI_DELAY_UNIT_USECS,
+		},
+	};
+	int ret;
+
+	priv->cmd_buffer[0] = ADS1298_CMD_RREG | reg;
+	priv->cmd_buffer[1] = 0x0;

Why mix of hex and decimal? Doesn't matter but looks odd

Quoted 11 lines
drivers/iio/adc/ti-ads1298.c new file +10 -0
+	priv->cmd_buffer[2] = 0;
+
+	ret = spi_sync_transfer(priv->spi, &reg_read_xfer, 1);
+	if (ret)
+		return ret;
+
+	*val = priv->cmd_buffer[2];
+
+	return 0;
+}
 

drivers/iio/adc/ti-ads1298.c line 493

Quoted 10 lines
drivers/iio/adc/ti-ads1298.c new file +10 -0
+
+/* Called from SPI completion interrupt handler */
+static void ads1298_rdata_complete(void *context)
+{
+	struct iio_dev *indio_dev = context;
+	struct ads1298_private *priv = iio_priv(indio_dev);
+	int scan_index;
+	u32 *bounce = priv->bounce_buffer;
+
+	if (!iio_buffer_enabled(indio_dev)) {

Good to add a comment here on why this can't race as we are holding the device in direct mode until after the completion.

iio_buffer_enabled() checks tend to expose races so I prefer people to explicitly say why there isn't one.

Quoted 42 lines
drivers/iio/adc/ti-ads1298.c new file +41 -0
+		/* Happens when running in single transfer mode */
+		ads1298_rdata_unmark_busy(priv);
+		complete(&priv->completion);
+		return;
+	}
+
+	/* Demux the channel data into our bounce buffer */
+	for_each_set_bit(scan_index, indio_dev->active_scan_mask,
+			 indio_dev->masklength) {
+		const struct iio_chan_spec *scan_chan =
+					&indio_dev->channels[scan_index];
+		const u8 *data = priv->rx_buffer + scan_chan->address;
+
+		*bounce++ = get_unaligned_be24(data);
+	}
+
+	/* rx_buffer can be overwritten from this point on */
+	ads1298_rdata_release_busy_or_restart(priv);
+
+	iio_push_to_buffers(indio_dev, priv->bounce_buffer);
+}
 
+
+static const char *ads1298_family_name(unsigned int id)
+{
+	switch (id & ADS1298_MASK_ID_FAMILY) {
+	case ADS1298_ID_FAMILY_ADS129X:
+		return "ADS129x";
+	case ADS1298_ID_FAMILY_ADS129XR:
+		return "ADS129xR";
+	default:
+		return "(unknown)";
+	}
+}
+
+static int ads1298_init(struct ads1298_private *priv)
+{
+	struct device *dev = &priv->spi->dev;
+	int ret;
+	unsigned int val;
+
+	/* Device initializes into RDATAC mode, which we don't want. */

drivers/iio/adc/ti-ads1298.c line 613

Quoted 10 lines
drivers/iio/adc/ti-ads1298.c new file +10 -0
+	ret = ads1298_write_cmd(priv, ADS1298_CMD_SDATAC);
+	if (ret)
+		return ret;
+
+	ret = regmap_read(priv->regmap, ADS1298_REG_ID, &val);
+	if (ret)
+		return ret;
+
+	dev_info(dev, "Found %s, %u channels\n", ads1298_family_name(val),
+		 4 + 2 * (val & ADS1298_MASK_ID_CHANNELS));

Noise for the log that is easy to figure out anyway (assuming successful probe) Make that dev_dbg()

drivers/iio/adc/ti-ads1298.c line 620

Quoted 7 lines
drivers/iio/adc/ti-ads1298.c new file +7 -0
+
+	/* Enable internal test signal, double amplitude, double frequency */
+	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);

Unless lines are very long, parameters should align just after (

Quoted 16 lines
drivers/iio/adc/ti-ads1298.c new file +16 -0
+	if (ret)
+		return ret;
+
+	val = ADS1298_MASK_CONFIG3_RESERVED; /* Must write 1 always */
+	if (!priv->reg_vref) {
+		/* Enable internal reference */
+		val |= ADS1298_MASK_CONFIG3_PWR_REFBUF;
+		/* Use 4V VREF when power supply is at least 4.4V */
+		if (regulator_get_voltage(priv->reg_avdd) >= 4400000)
+			val |= ADS1298_MASK_CONFIG3_VREF_4V;
+	}
+	return regmap_write(priv->regmap, ADS1298_REG_CONFIG3, val);
+}
+
+static int ads1298_probe(struct spi_device *spi)
+{

...

drivers/iio/adc/ti-ads1298.c line 733

Quoted 2 lines
drivers/iio/adc/ti-ads1298.c new file +2 -0
+	ret = devm_request_irq(dev, spi->irq, &ads1298_interrupt,
+			       IRQF_TRIGGER_FALLING, indio_dev->name,

I missed this before (and we've gotten it wrong a bunch of times in the past so plenty of bad examples to copy that we can't fix without possible regressions) but we generally now leave irq direction to the firmware description. People have an annoying habit of putting not gates and similar in the path to interrupt pins. Fine to have the binding state the expected form though (as you do). So basically not flags here.

I'm still curious to understand more of where the delays that lead to needing to do this complex handling came from, but I guess it's not too bad if we can't get to the bottom of that so I'll take the driver anyway (after a little more time on list for others to review!)

Quoted 1 line
drivers/iio/adc/ti-ads1298.c new file +1 -0
+			       indio_dev);
#4 lore raw

Re: [PATCH v2 2/2] iio: adc: ti-ads1298: Add driver

Met vriendelijke groet / kind regards,

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

Please consider the environment before printing this e-mail

Quoted 9 lines · Jonathan Cameron
Quoted 6 lines · On Fri, 2 Feb 2024 11:59:01 +0100 Mike Looijmans<[email protected]>…

Skeleton driver for the TI ADS1298 medical ADC. This device is typically used for ECG and similar measurements. Supports data acquisition at configurable scale and sampling frequency.

Quoted 8 lines

Hi Mike,

A few minor things I'd missed before.

I'm still interested in why more standard interrupt handling isn't good enough here (see reply to v1 thread) but if we can't get to the bottom of that (or do figure it out and we can't fix it) then this doesn't look too bad so I'll accept the complex handling.

I think one of the key elements was the IRQF_ONESHOT usage. The DRDY signal on this chip isn't a "level" signal as most chips have, it will de-assert at any rising edge of the SPI clock, without regarding chip-select. There's no other indication of "data ready", so the only way is to keep the interrupt active on edge detect.

Keeping things in hard IRQ handlers reduces the number of context switches, and the amount of work done is minimal. A worker thread would wake at every DRDY signal, and after the corresponding SPI transaction. This doesn't account for much overhead, but the interrupt rate is double the sampling frequency. Most importantly, the device doesn't have to compete with other threads in the system.

If I have time and hardware available, I try to get some timing info with an oscilloscope...

Assume "yes" to all other suggestions...

Quoted 8 lines

drivers/iio/adc/ti-ads1298.c line 733

Quoted 2 lines
drivers/iio/adc/ti-ads1298.c new file +2 -0
+	ret = devm_request_irq(dev, spi->irq, &ads1298_interrupt,
+			       IRQF_TRIGGER_FALLING, indio_dev->name,

I missed this before (and we've gotten it wrong a bunch of times in the past so plenty of bad examples to copy that we can't fix without possible regressions) but we generally now leave irq direction to the firmware description. People have an annoying habit of putting not gates and similar in the path to interrupt pins. Fine to have the binding state the expected form though (as you do). So basically not flags here.

I'd be happy to leave the IRQ direction to firmware (indeed, inverters happen...), but afaik that wasn't possible with interrupts. I'll dig into the docs to see if that has changed recently.

Quoted 6 lines

I'm still curious to understand more of where the delays that lead to needing to do this complex handling came from, but I guess it's not too bad if we can't get to the bottom of that so I'll take the driver anyway (after a little more time on list for others to review!)

drivers/iio/adc/ti-ads1298.c line 734

Quoted 1 line
drivers/iio/adc/ti-ads1298.c new file +1 -0
+			       indio_dev);

(PS - sorry for sending HTML, consider me appropriately punisched for that)

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
Reviewed-by on v2 1/2
#5 lore raw
In reply to Mike Looijmans
Quoted 7 lines · Mike Looijmans

Bindings for the TI ADS1298 medical ADC. This device is typically used for ECG and similar measurements. Supports data acquisition at configurable scale and sampling frequency.

The device has so many options for connecting stuff, at this point the bindings aren't nearly complete but partial bindings are better than no bindings at all.

I'm inclined to agree, particularly given your comments on v1.

Cheers,
Conor.

Quoted 118 lines

---

Changes in v2:
Remove "clk" name
Add datasheet and "incomplete" note

 .../bindings/iio/adc/ti,ads1298.yaml          | 80 +++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/ti,ads1298.yaml
Documentation/devicetree/bindings/iio/adc/ti,ads1298.yaml new file +80 -0
new file mode 100644
index 000000000000..bf5a43a81d59
@@ -0,0 +1,80 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/ti,ads1298.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments' ads1298 medical ADC chips
+
+description: |
+  Datasheet at: https://www.ti.com/product/ADS1298
+  Bindings for this chip aren't complete.
+
+maintainers:
+  - Mike Looijmans <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - ti,ads1298
+
+  reg:
+    maxItems: 1
+
+  spi-cpha: true
+
+  reset-gpios:
+    maxItems: 1
+
+  avdd-supply:
+    description:
+      Analog power supply, voltage between AVDD and AVSS. When providing a
+      symmetric +/- 2.5V, the regulator should report 5V.
+
+  vref-supply:
+    description:
+      Optional reference voltage. If omitted, internal reference is used,
+      which is 2.4V when analog supply is below 4.4V, 4V otherwise.
+
+  clocks:
+    description: Optional 2.048 MHz external source clock on CLK pin
+    maxItems: 1
+
+  interrupts:
+    description: Interrupt on DRDY pin, triggers on falling edge
+    maxItems: 1
+
+  label: true
+
+required:
+  - compatible
+  - reg
+  - avdd-supply
+  - interrupts
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@1 {
+          reg = <1>;
+          compatible = "ti,ads1298";
+          label = "ads1298-1-ecg";
+          avdd-supply = <&reg_iso_5v_a>;
+          clocks = <&clk_ads1298>;
+          interrupt-parent = <&gpio0>;
+          interrupts = <78 IRQ_TYPE_EDGE_FALLING>;
+          spi-max-frequency = <20000000>;
+          spi-cpha;
+        };
+    };
+...
Signature · 18 lines
2.34.1


Met vriendelijke groet / kind regards,

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

Please consider the environment before printing this e-mail