Skip to contentSkip to conversation

dt-bindings: iio: adc: Add TI ADS1100 and ADS1000

PATCH Superseded Mike Looijmans 2 participants 5 messages Mar 6, 2023 1 message not in the archive

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

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.fd3967b4-1646-4b17-a426-66ee84660804@emailsignatures365.codetwo.com

#1 lore raw

PATCH v4 1/2 dt-bindings: iio: adc: Add TI ADS1100 and ADS1000

The ADS1100 is a 16-bit ADC (at 8 samples per second). The ADS1000 is similar, but has a fixed data rate.

---

(no changes since v2)

Changes in v2:
"reg" property is mandatory.
Add vdd-supply and #io-channel-cells

 .../bindings/iio/adc/ti,ads1100.yaml          | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/ti,ads1100.yaml
Documentation/devicetree/bindings/iio/adc/ti,ads1100.yaml new file +46 -0
new file mode 100644
index 000000000000..970ccab15e1e
@@ -0,0 +1,46 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/ti,ads1100.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TI ADS1100/ADS1000 single channel I2C analog to digital converter
+
+maintainers:
+  - Mike Looijmans <[email protected]>
+
+description: |
+  Datasheet at: https://www.ti.com/lit/gpn/ads1100
+
+properties:
+  compatible:
+    enum:
+      - ti,ads1100
+      - ti,ads1000
+
+  reg:
+    maxItems: 1
+
+  vdd-supply: true
+
+  "#io-channel-cells":
+    const: 0
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@49 {
+            compatible = "ti,ads1100";
+            reg = <0x49>;
+        };
+    };
+...
Signature · 18 lines
2.17.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 v4 2/2 iio: adc: Add TI ADS1100 and ADS1000

The ADS1100 is a 16-bit ADC (at 8 samples per second). The ADS1000 is similar, but has a fixed data rate.

---

Changes in v4:
Use post-increment
Formatting fixes (commas, indents, empty line) Use 'ffs' and explain gain formula
Use dev_set_drvdata/dev_get_drvdata for pm_ methods Use units.h for micro-to-milli conversion

Changes in v3:
Add #include linux/bitfield.h and linux/bits.h

Changes in v2:
Remove "driver for" from title
Use proper PM_RUNTIME macros
Fix indents
Use dev_err_probe()
Unsigned index and post-increment
Use GENMASK and FIELD_GET
remove ads1100_set_conv_mode
remove Kconfig BUFFER dependencies
remove unused #include
Set SCALE instead of HARDWAREGAIN
Use devm_add_action_or_reset

 drivers/iio/adc/Kconfig      |  10 +
 drivers/iio/adc/Makefile     |   1 +
 drivers/iio/adc/ti-ads1100.c | 442 +++++++++++++++++++++++++++++++++++
 3 files changed, 453 insertions(+)
 create mode 100644 drivers/iio/adc/ti-ads1100.c
drivers/iio/adc/Kconfig +10 -0
index 63f80d747cbd..257efb25a92e 100644
@@ -1207,6 +1207,16 @@ config TI_ADS1015
 	  This driver can also be built as a module. If so, the module will be
 	  called ti-ads1015.
 
+config TI_ADS1100
+	tristate "Texas Instruments ADS1100 and ADS1000 ADC"
+	depends on I2C
+	help
+	  If you say yes here you get support for Texas Instruments ADS1100 and
+	  ADS1000 ADC chips.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called ti-ads1100.
+
 config TI_ADS7950
 	tristate "Texas Instruments ADS7950 ADC driver"
 	depends on SPI && GPIOLIB
drivers/iio/adc/Makefile +1 -0
index 4ef41a7dfac6..61ef600fab99 100644
@@ -107,6 +107,7 @@ obj-$(CONFIG_TI_ADC108S102) += ti-adc108s102.o
 obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o
 obj-$(CONFIG_TI_ADC161S626) += ti-adc161s626.o
 obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o
+obj-$(CONFIG_TI_ADS1100) += ti-ads1100.o
 obj-$(CONFIG_TI_ADS7950) += ti-ads7950.o
 obj-$(CONFIG_TI_ADS8344) += ti-ads8344.o
 obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o
drivers/iio/adc/ti-ads1100.c new file +442 -0

442 lines not on this page · raw message

Signature · 18 lines
2.17.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
#3 lore raw

Re: [PATCH v4 2/2] iio: adc: Add TI ADS1100 and ADS1000

Quoted 2 lines · Mike Looijmans

The ADS1100 is a 16-bit ADC (at 8 samples per second). The ADS1000 is similar, but has a fixed data rate.

...

drivers/iio/adc/ti-ads1100.c line 117

Quoted 2 lines
drivers/iio/adc/ti-ads1100.c new file +2 -0
+	/* Value is always 16-bit 2's complement */
+	value = be16_to_cpu(buffer);

+ Blank line?

drivers/iio/adc/ti-ads1100.c line 119

Quoted 2 lines
drivers/iio/adc/ti-ads1100.c new file +2 -0
+	/* Shift result to compensate for bit resolution vs. sample rate */
+	value <<= 16 - ads1100_data_bits(data);

+ Blank line?

Quoted 1 line
drivers/iio/adc/ti-ads1100.c new file +1 -0
+	*val = sign_extend32(value, 15);

...

drivers/iio/adc/ti-ads1100.c line 146

Quoted 9 lines
drivers/iio/adc/ti-ads1100.c new file +9 -0
+	microvolts = regulator_get_voltage(data->reg_vdd);
+	/*
+	 * val2 is in 'micro' units, n = val2 / 1000000
+	 * result must be millivolts, d = microvolts / 1000
+	 * the full-scale value is d/n, corresponds to 2^15,
+	 * hence the gain = (d / n) >> 15, factoring out the 1000 and moving the
+	 * bitshift so everything fits in 32-bits yields this formula.
+	 */
+	gain = ((microvolts + BIT(14)) >> 15) * 1000 / val2;

Perhaps adding MICROVOLT_PER_MILLIVOLT (to units.h) and use it here?

Besides that it's seems like

	microvolts = regulator_get_voltage(data->reg_vdd);
	gain = DIV_ROUNDUP_CLOSEST(microvolts, BIT(15)) *
	       MICROVOLT_PER_MILLIVOLT / val2;

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (gain <= 0 || gain > 8)
+		return -EINVAL;

As I commented out in the previous discussion (please, give a chance to the reviewers to answer before issuing a new version of the series) this better to be

	if (gain < BIT(0) || gain > BIT(3))

which will show the nature of power of two implicitly.

drivers/iio/adc/ti-ads1100.c line 151

Quoted 2 lines
drivers/iio/adc/ti-ads1100.c new file +2 -0
+	regval = ffs(gain) - 1;
+	ads1100_set_config_bits(data, ADS1100_PGA_MASK, regval);

Can be unified in one line.

Quoted 2 lines
(quoted diff) +2 -0
+	return 0;
+}

...

drivers/iio/adc/ti-ads1100.c line 165

Quoted 3 lines
drivers/iio/adc/ti-ads1100.c new file +3 -0
+			return ads1100_set_config_bits(
+					data, ADS1100_DR_MASK,
+					FIELD_PREP(ADS1100_DR_MASK, i));

Wrong indentation.
Please, check all your code for this kind of issues.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH v4 2/2] iio: adc: Add TI ADS1100 and ADS1000

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 5 lines · Andy Shevchenko
Quoted 2 lines · Mike Looijmans

The ADS1100 is a 16-bit ADC (at 8 samples per second). The ADS1000 is similar, but has a fixed data rate.

...

Quoted 10 lines

drivers/iio/adc/ti-ads1100.c line 146

Quoted 9 lines
drivers/iio/adc/ti-ads1100.c new file +9 -0
+	microvolts = regulator_get_voltage(data->reg_vdd);
+	/*
+	 * val2 is in 'micro' units, n = val2 / 1000000
+	 * result must be millivolts, d = microvolts / 1000
+	 * the full-scale value is d/n, corresponds to 2^15,
+	 * hence the gain = (d / n) >> 15, factoring out the 1000 and moving the
+	 * bitshift so everything fits in 32-bits yields this formula.
+	 */
+	gain = ((microvolts + BIT(14)) >> 15) * 1000 / val2;

Perhaps adding MICROVOLT_PER_MILLIVOLT (to units.h) and use it here?

Would that require a separate patch?

I fear that would get feedback like "why not MICROCOULOB_PER_MILLICOULOMB".

If I fill in the equation then that "1000" is actually MICROVOLT_PER_MICROVOLT_PER_MILLIVOLT, which would evaluate to simply "MILLIVOLT".

Quoted 6 lines

Besides that it's seems like

	microvolts = regulator_get_voltage(data->reg_vdd);
	gain = DIV_ROUNDUP_CLOSEST(microvolts, BIT(15)) *
	       MICROVOLT_PER_MILLIVOLT / val2;

Yeah, the DIV_ROUNDUP_CLOSEST is more readable.

Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (gain <= 0 || gain > 8)
+		return -EINVAL;

As I commented out in the previous discussion (please, give a chance to the reviewers to answer before issuing a new version of the series) this better to be

Quoted 7 lines
	if (gain < BIT(0) || gain > BIT(3))

which will show the nature of power of two implicitly.

drivers/iio/adc/ti-ads1100.c line 151

Quoted 2 lines
drivers/iio/adc/ti-ads1100.c new file +2 -0
+	regval = ffs(gain) - 1;
+	ads1100_set_config_bits(data, ADS1100_PGA_MASK, regval);

Can be unified in one line.

Combining it all, I'd arrive at this code:

    gain = DIV_ROUNDUP_CLOSEST(microvolts, BIT(15)) * MILLI / val2; if (gain < BIT(0) || gain > BIT(3))
        return -EINVAL;

    ads1100_set_config_bits(data, ADS1100_PGA_MASK, ffs(gain) - 1);

Quoted 10 lines
Quoted 2 lines
(quoted diff) +2 -0
+	return 0;
+}

...

drivers/iio/adc/ti-ads1100.c line 165

Quoted 3 lines
drivers/iio/adc/ti-ads1100.c new file +3 -0
+			return ads1100_set_config_bits(
+					data, ADS1100_DR_MASK,
+					FIELD_PREP(ADS1100_DR_MASK, i));

Wrong indentation.
Please, check all your code for this kind of issues.

I always run it through checkpatch.pl but that didn't report on this indentation.

A bit of digging in the scripts directory yields "Lindent". Feeding my file to that indeed changes those lines (and some others too). I'll run my next patch through that.

Signature · 1 line
Mike Looijmans
#5 lore raw

Re: [PATCH v4 2/2] iio: adc: Add TI ADS1100 and ADS1000

Quoted 1 line · Mike Looijmans

On 06-03-2023 14:29, Andy Shevchenko wrote:

...

Quoted 7 lines

Combining it all, I'd arrive at this code:

    gain = DIV_ROUNDUP_CLOSEST(microvolts, BIT(15)) * MILLI / val2; if (gain < BIT(0) || gain > BIT(3))
        return -EINVAL;

    ads1100_set_config_bits(data, ADS1100_PGA_MASK, ffs(gain) - 1);

Fine by me.

...

Quoted 8 lines
Quoted 6 lines

drivers/iio/adc/ti-ads1100.c line 165

Quoted 3 lines
drivers/iio/adc/ti-ads1100.c new file +3 -0
+			return ads1100_set_config_bits(
+					data, ADS1100_DR_MASK,
+					FIELD_PREP(ADS1100_DR_MASK, i));

Wrong indentation.
Please, check all your code for this kind of issues.

I always run it through checkpatch.pl but that didn't report on this indentation.

Checkpatch is:

1) not comprehensive;
2) not must-to-follow;

tool.

Use your common sense. You have a lot of room on the previous line at least for 'data'. Trailing opening ( is not good indentation. But sometimes might be unavoidable.

Quoted 3 lines

A bit of digging in the scripts directory yields "Lindent". Feeding my file to that indeed changes those lines (and some others too). I'll run my next patch through that.

If it will look nice, why not?

Signature · 2 lines
With Best Regards,
Andy Shevchenko