Skip to contentSkip to conversation

dt-bindings: adc: add AD7173

PATCH Superseded Dumitru Ceclan 6 participants 18 messages Feb 20, 2024 – Feb 24, 2024

Subsystems (4)

v13 of 16 Superseded Latest is v16 →

lore
Share & tools
lore
#0 lore raw

PATCH v13 1/3 dt-bindings: adc: add AD7173

The AD7173 family offer a complete integrated Sigma-Delta ADC solution which can be used in high precision, low noise single channel applications or higher speed multiplexed applications. The Sigma-Delta ADC is intended primarily for measurement of signals close to DC but also delivers outstanding performance with input bandwidths out to ~10kHz.

---
V12->V13
- Remove adi,clock-select
- Update avdd and avdd2 supply descriptions
- Update adi,reference-select description to suggest that it is referenced to avss
- Make clocks/clock-names and clock-controller mutually exclusive
V11->V12
- Drop "binding", describe hardware in binding description
- Rename refin and refin2 to vref and vref2
- Add better description to external references to better show that the voltage value that needs to be specified is the difference between the positive and negative reference pins
- Add optional clocks properties
- Add optional adi,clock-select property
- Add option for second interrupt, error
- Add description to interrupts
V10->V11
- Fix example warning: '#gpio-cells' is a dependency of 'gpio-controller'
- Add description to #gpio-cells property
V9->V10
- Fix dt_binding_check type warning from adi,reference-select
V8->v9
- Add gpio-controller and "#gpio-cells" properties
- Add missing avdd2 and iovdd supplies
- Add string type to reference-select
V7->V8
- include missing fix from V6
V6->V7 <no changes>
V5->V6
- Moved global required property to proper placement
V4 -> V5
- Use string enum instead of integers for "adi,reference-select"
- Fix conditional checking in regards to compatible
V3 -> V4
- include supply attributes
- add channel attribute for selecting conversion reference
V2 -> V3
- remove redundant descriptions
- use referenced 'bipolar' property
- remove newlines from example
V1 -> V2 <no changes>

 .../bindings/iio/adc/adi,ad7173.yaml          | 242 ++++++++++++++++++
 1 file changed, 242 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +242 -0
new file mode 100644
index 000000000000..347a0cc0e278
@@ -0,0 +1,242 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright 2023 Analog Devices Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ad7173.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD7173 ADC
+
+maintainers:
+  - Ceclan Dumitru <[email protected]>
+
+description: |
+  Analog Devices AD717x ADC's:
+  The AD717x family offer a complete integrated Sigma-Delta ADC solution which
+  can be used in high precision, low noise single channel applications
+  (Life Science measurements) or higher speed multiplexed applications
+  (Factory Automation PLC Input modules). The Sigma-Delta ADC is intended
+  primarily for measurement of signals close to DC but also delivers
+  outstanding performance with input bandwidths out to ~10kHz.
+
+  Datasheets for supported chips:
+    https://www.analog.com/media/en/technical-documentation/data-sheets/AD7172-2.pdf
+    https://www.analog.com/media/en/technical-documentation/data-sheets/AD7173-8.pdf
+    https://www.analog.com/media/en/technical-documentation/data-sheets/AD7175-2.pdf
+    https://www.analog.com/media/en/technical-documentation/data-sheets/AD7176-2.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,ad7172-2
+      - adi,ad7173-8
+      - adi,ad7175-2
+      - adi,ad7176-2
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    minItems: 1
+    description: |
+      Ready interrupt: multiplexed with SPI data out. While SPI CS is low,
+      can be used to indicate the completion of a conversion.
+
+      Error: The three error bits in the status register (ADC_ERROR, CRC_ERROR,
+      and REG_ERROR) are OR'ed, inverted, and mapped to the ERROR pin. Therefore,
+      the ERROR pin indicates that an error has occurred.
+
+  interrupt-names:
+    minItems: 1
+    items:
+      - const: rdy
+      - const: err
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  spi-max-frequency:
+    maximum: 20000000
+
+  gpio-controller:
+    description: Marks the device node as a GPIO controller.
+
+  '#gpio-cells':
+    const: 2
+    description:
+      The first cell is the GPIO number and the second cell specifies
+      GPIO flags, as defined in <dt-bindings/gpio/gpio.h>.
+
+  vref-supply:
+    description: |
+      Differential external reference supply used for conversion. The reference
+      voltage (Vref) specified here must be the voltage difference between the
+      REF+ and REF- pins: Vref = (REF+) - (REF-).
+
+  vref2-supply:
+    description: |
+      Differential external reference supply used for conversion. The reference
+      voltage (Vref2) specified here must be the voltage difference between the
+      REF2+ and REF2- pins: Vref2 = (REF2+) - (REF2-).
+
+  avdd-supply:
+    description: Avdd supply, can be used as reference for conversion.
+                 This supply is referenced to AVSS, voltage specified here
+                 represens (AVDD - AVSS).
+
+  avdd2-supply:
+    description: Avdd2 supply, used as the input to the internal voltage regulator.
+                 This supply is referenced to AVSS, voltage specified here
+                 represens (AVDD2 - AVSS).
+
+  iovdd-supply:
+    description: iovdd supply, used for the chip digital interface.
+
+  clocks:
+    maxItems: 1
+    description: |
+      Optional external clock source. Can include one clock source: external
+      clock or external crystal.
+
+  clock-names:
+    enum:
+      - ext-clk
+      - xtal
+
+  '#clock-cells':
+    const: 0
+
+patternProperties:
+  "^channel@[0-9a-f]$":
+    type: object
+    $ref: adc.yaml
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        minimum: 0
+        maximum: 15
+
+      diff-channels:
+        items:
+          minimum: 0
+          maximum: 31
+
+      adi,reference-select:
+        description: |
+          Select the reference source to use when converting on
+          the specific channel. Valid values are:
+          vref       : REF+  /REF−
+          vref2      : REF2+ /REF2−
+          refout-avss: REFOUT/AVSS (Internal reference)
+          avdd       : AVDD  /AVSS
+
+          External reference ref2 only available on ad7173-8.
+          If not specified, internal reference used.
+        $ref: /schemas/types.yaml#/definitions/string
+        enum:
+          - vref
+          - vref2
+          - refout-avss
+          - avdd
+        default: refout-avss
+
+    required:
+      - reg
+      - diff-channels
+
+required:
+  - compatible
+  - reg
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+
+  - if:
+      properties:
+        compatible:
+          not:
+            contains:
+              const: adi,ad7173-8
+    then:
+      properties:
+        vref2-supply: false
+      patternProperties:
+        "^channel@[0-9a-f]$":
+          properties:
+            adi,reference-select:
+              enum:
+                - vref
+                - refout-avss
+                - avdd
+
+  - if:
+      anyOf:
+        - required: [clock-names]
+        - required: [clocks]
+    then:
+      properties:
+        '#clock-cells': false
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      adc@0 {
+        compatible = "adi,ad7173-8";
+        reg = <0>;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
+        interrupt-names = "rdy";
+        interrupt-parent = <&gpio>;
+        spi-max-frequency = <5000000>;
+        gpio-controller;
+        #gpio-cells = <2>;
+        #clock-cells = <0>;
+
+        vref-supply = <&dummy_regulator>;
+
+        channel@0 {
+          reg = <0>;
+          bipolar;
+          diff-channels = <0 1>;
+          adi,reference-select = "vref";
+        };
+
+        channel@1 {
+          reg = <1>;
+          diff-channels = <2 3>;
+        };
+
+        channel@2 {
+          reg = <2>;
+          bipolar;
+          diff-channels = <4 5>;
+        };
+
+        channel@3 {
+          reg = <3>;
+          bipolar;
+          diff-channels = <6 7>;
+        };
+
+        channel@4 {
+          reg = <4>;
+          diff-channels = <8 9>;
+          adi,reference-select = "avdd";
+        };
+      };
+    };
Signature · 1 line
2.42.0
#1 lore raw

PATCH v13 2/3 iio: adc: ad_sigma_delta: Add optional irq selection

Add optional irq_num attribute to ad_sigma_delta_info structure for selecting the used interrupt line for adc's conversion completion.

---
 drivers/iio/adc/ad_sigma_delta.c       | 23 ++++++++++++++---------
 include/linux/iio/adc/ad_sigma_delta.h |  3 +++
 2 files changed, 17 insertions(+), 9 deletions(-)
drivers/iio/adc/ad_sigma_delta.c +14 -9
index 7e2192870743..a0ae3a21e919 100644
@@ -222,11 +222,11 @@ int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
 		goto out;
 
 	sigma_delta->irq_dis = false;
-	enable_irq(sigma_delta->spi->irq);
+	enable_irq(sigma_delta->irq_num);
 	timeout = wait_for_completion_timeout(&sigma_delta->completion, 2 * HZ);
 	if (timeout == 0) {
 		sigma_delta->irq_dis = true;
-		disable_irq_nosync(sigma_delta->spi->irq);
+		disable_irq_nosync(sigma_delta->irq_num);
 		ret = -EIO;
 	} else {
 		ret = 0;
@@ -295,7 +295,7 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
 	ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_SINGLE);
 
 	sigma_delta->irq_dis = false;
-	enable_irq(sigma_delta->spi->irq);
+	enable_irq(sigma_delta->irq_num);
 	ret = wait_for_completion_interruptible_timeout(
 			&sigma_delta->completion, HZ);
 
@@ -315,7 +315,7 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
 
 out:
 	if (!sigma_delta->irq_dis) {
-		disable_irq_nosync(sigma_delta->spi->irq);
+		disable_irq_nosync(sigma_delta->irq_num);
 		sigma_delta->irq_dis = true;
 	}
 
@@ -396,7 +396,7 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
 		goto err_unlock;
 
 	sigma_delta->irq_dis = false;
-	enable_irq(sigma_delta->spi->irq);
+	enable_irq(sigma_delta->irq_num);
 
 	return 0;
 
@@ -414,7 +414,7 @@ static int ad_sd_buffer_postdisable(struct iio_dev *indio_dev)
 	wait_for_completion_timeout(&sigma_delta->completion, HZ);
 
 	if (!sigma_delta->irq_dis) {
-		disable_irq_nosync(sigma_delta->spi->irq);
+		disable_irq_nosync(sigma_delta->irq_num);
 		sigma_delta->irq_dis = true;
 	}
 
@@ -516,7 +516,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
 irq_handled:
 	iio_trigger_notify_done(indio_dev->trig);
 	sigma_delta->irq_dis = false;
-	enable_irq(sigma_delta->spi->irq);
+	enable_irq(sigma_delta->irq_num);
 
 	return IRQ_HANDLED;
 }
@@ -586,9 +586,9 @@ static int devm_ad_sd_probe_trigger(struct device *dev, struct iio_dev *indio_de
 	sigma_delta->irq_dis = true;
 
 	/* the IRQ core clears IRQ_DISABLE_UNLAZY flag when freeing an IRQ */
-	irq_set_status_flags(sigma_delta->spi->irq, IRQ_DISABLE_UNLAZY);
+	irq_set_status_flags(sigma_delta->irq_num, IRQ_DISABLE_UNLAZY);
 
-	ret = devm_request_irq(dev, sigma_delta->spi->irq,
+	ret = devm_request_irq(dev, sigma_delta->irq_num,
 			       ad_sd_data_rdy_trig_poll,
 			       sigma_delta->info->irq_flags | IRQF_NO_AUTOEN,
 			       indio_dev->name,
@@ -668,6 +668,11 @@ int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev,
 		}
 	}
 
+	if (!info->irq_num)
+		sigma_delta->irq_num = spi->irq;
+	else
+		sigma_delta->irq_num = info->irq_num;
+
 	iio_device_set_drvdata(indio_dev, sigma_delta);
 
 	return 0;
include/linux/iio/adc/ad_sigma_delta.h +3 -0
index 7852f6c9a714..77c3a33e5370 100644
@@ -45,6 +45,7 @@ struct iio_dev;
  * @data_reg: Address of the data register, if 0 the default address of 0x3 will
  *   be used.
  * @irq_flags: flags for the interrupt used by the triggered buffer
+ * @irq_num: IRQ for reading conversions. If 0, spi->irq will be used
  * @num_slots: Number of sequencer slots
  */
 struct ad_sigma_delta_info {
@@ -59,6 +60,7 @@ struct ad_sigma_delta_info {
 	unsigned int status_ch_mask;
 	unsigned int data_reg;
 	unsigned long irq_flags;
+	unsigned long irq_num;
 	unsigned int num_slots;
 };
 
@@ -87,6 +89,7 @@ struct ad_sigma_delta {
 	unsigned int		active_slots;
 	unsigned int		current_slot;
 	unsigned int		num_slots;
+	unsigned int		irq_num;
 	bool			status_appended;
 	/* map slots to channels in order to know what to expect from devices */
 	unsigned int		*slots;
Signature · 1 line
2.42.0
#2 lore raw

Re: [PATCH v13 2/3] iio: adc: ad_sigma_delta: Add optional irq selection

Quoted 2 lines · Dumitru Ceclan

Add optional irq_num attribute to ad_sigma_delta_info structure for selecting the used interrupt line for adc's conversion completion.

...

drivers/iio/adc/ad_sigma_delta.c int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev, · line 674

Quoted 4 lines
drivers/iio/adc/ad_sigma_delta.c +4 -0
+	if (!info->irq_num)
+		sigma_delta->irq_num = spi->irq;
+	else
+		sigma_delta->irq_num = info->irq_num;

Why not positive check?

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

Re: [PATCH v13 2/3] iio: adc: ad_sigma_delta: Add optional irq selection

Quoted 4 lines · Andy Shevchenko
Quoted 2 lines · Dumitru Ceclan

Add optional irq_num attribute to ad_sigma_delta_info structure for selecting the used interrupt line for adc's conversion completion.

Quoted 9 lines

...

drivers/iio/adc/ad_sigma_delta.c int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev, · line 674

Quoted 4 lines
drivers/iio/adc/ad_sigma_delta.c +4 -0
+	if (!info->irq_num)
+		sigma_delta->irq_num = spi->irq;
+	else
+		sigma_delta->irq_num = info->irq_num;

Why not positive check?

Considered that selecting spi->irq is usually the default case, so it should be the first branch

#4 lore raw

Re: [PATCH v13 2/3] iio: adc: ad_sigma_delta: Add optional irq selection

Quoted 2 lines · Ceclan Dumitru
Quoted 1 line · Andy Shevchenko

On Tue, Feb 20, 2024 at 11:43:39AM +0200, Dumitru Ceclan wrote:

...

Quoted 9 lines
Quoted 7 lines

drivers/iio/adc/ad_sigma_delta.c int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev, · line 674

Quoted 4 lines
drivers/iio/adc/ad_sigma_delta.c +4 -0
+	if (!info->irq_num)
+		sigma_delta->irq_num = spi->irq;
+	else
+		sigma_delta->irq_num = info->irq_num;

Why not positive check?

Considered that selecting spi->irq is usually the default case, so it should be the first branch

Let compiler do its job, the negative conditions are harder to read/parse by human beings.

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

Re: [PATCH v13 2/3] iio: adc: ad_sigma_delta: Add optional irq selection

Quoted 13 lines · On Tue, 20 Feb 2024 16:17:52 +0200 Andy Shevchenko <[email protected]> wrote:
Quoted 2 lines · Ceclan Dumitru
Quoted 1 line · Andy Shevchenko

On Tue, Feb 20, 2024 at 11:43:39AM +0200, Dumitru Ceclan wrote:

...

Quoted 7 lines
Quoted 7 lines

drivers/iio/adc/ad_sigma_delta.c int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev, · line 674

Quoted 4 lines
drivers/iio/adc/ad_sigma_delta.c +4 -0
+	if (!info->irq_num)
+		sigma_delta->irq_num = spi->irq;
+	else
+		sigma_delta->irq_num = info->irq_num;  

Why not positive check?

Quoted 6 lines
Quoted 2 lines

Considered that selecting spi->irq is usually the default case, so it should be the first branch

Let compiler do its job, the negative conditions are harder to read/parse by human beings.

FWIW compiler almost certainly won't figure this out as it has nothing to go on
- history based branch prediction in processors will though! We don't want to be hinting direction to the compiler for a case like this as that will make it very painful if we get it wrong. Anyhow Andy's comment is valid even if I disagree with the reason.

Jonathan

#6 lore raw

PATCH v13 3/3 iio: adc: ad7173: add AD7173 driver

In reply to Dumitru Ceclan

The AD7173 family offer a complete integrated Sigma-Delta ADC solution which can be used in high precision, low noise single channel applications or higher speed multiplexed applications. The Sigma-Delta ADC is intended primarily for measurement of signals close to DC but also delivers outstanding performance with input bandwidths out to ~10kHz.

---

V12-> V13
- Add precursor patch for new irq_num attribute in ad_sigma_delta_info and ad_sigma_delta structs
- Split *_fw_parse_channel_config() into *_channel_config and *_device_config
- Reorder probe calls to ad_sd_init to use correctly the optional irq_num attribute
- Require in probe interrupt named "rdy" to be present
- If external clock not present, register clk provider
- If external clock present, get clock and enable
- Add constants, strings for clock selections
V11-> V12
- rename refin, refin2 to vref, vref2
V10-> V11 <no changes>
V9 -> V10 <no changes>
V8 -> V9
- Add '(x)' to some macro's definition to reduce NO of checks
- Use reg 0 constant definition in debug_reg_access()
- Rename channels_st_priv_arr to chans_st_arr
- Remove unnecessary u32 cast from read_raw()
- Compute read_raw() offset instead of constant
- Add offset comments to data rate arrays
- Removed redundant newline in _parse_channel_config()
V7 -> V8
- remove Kconfig commas
- reorder include <...gpio/regmap.h>
- GPO12_DATA(x) from BIT(x) -> BIT(x+0)
- use the same pointer to dev in ad7173_setup()
- rewrite temp channel read_raw scale for better readability
- add comment to explain temp channel offset
- follow multi-line comment style
- change ref_sel type to signed int
- use fwnode_property_match_property_string()
V6 -> V7
- format Kconfig supported models using '-'
- include types.h instead of stddef.h
- change device_info->num_gpios type to u8
- reorder fields in ad7173_state, place ad_sigma_delta
- reorder fields in ad7173_device_info, group by type
- add default case in read_raw()
- rename ad7173_debug() to ad7173_debug_reg_access()
- remove explicit u8 cast
- remove return 0; for offset in read_raw()
- add '\n' to error messages
- reorder probe variables -> reversed xmas tree
- remove redundant inner commas in of_match and id_table
- simplify selected reference code by setting default value and ignoring fwnode_property_read_string() error
- use match_string() for finding selected reference
- err on no channels specified
- add missing fwnode_handle_put(child) on err return branches
- remove spi_set_drvdata() from probe
- remove offset variable from find_live_config(), not used
- add comment showing a generic LRU implementation might be used if one
will exist
- MISC: add blank line to chanel_config struct, trailing comma ref_sel_str[], remove blank line in update_scan_mode(), add spaces around '/'
V5->V6 <no changes>
V4 -> V5
- List Kconfig supported models one per line
- Include <array_size.h> and <container_of.h>
- Remove bits.h and kernel.h include
- Add spaces before '\' on multi-line definitions
- Change constant definition name from "..._MICROV" to "..._uV"
- Change ad7173_channel_config attributes order for grouping by type
- Remove redundant {} in ad7173_gpio_init()
- Add array with reference select strings
- Change parsing of device tree adi,reference-select from integer to string
- Change indentation for ad7173_find_live_config() header
- Use struct_group() in config struct
- Use offsetofend() and sizeof_field() in ad7173_find_live_config()
- Split line on logic operator in ad7173_find_live_config() at configs comparison
- Use IDA for config slots allocation
- Reverse xmas tree order for probe local variables
- Use BIT() for computing bipolar channels offset
- Change (MICRO/MILLI) to MILLI in read_raw for integer part of sampling frequency
- MISC: remove blank line, use 0 value dirrectly, one line statement devm_kcalloc()
V3 -> V4
- cleaned up includes
- add ad7173_gpio_disable(), include to devm actions
- remove iio_device_claim_direct_mode() from update_scan_mode()
- always set differential iio_chan attribute to true, retain bipolar info only in private struct
- store multiple regulators in state for voltage references
- compute read_raw offset depending on channel used reference
- configure channel setup using selected reference
- add ad7173_get_ref_voltage_milli()
- clean up ad7173_fw_sparse_channel_config() changing array access of channel structs to pointers
- retain chip name in st->info structure
- use spi_device_get_match_data() in probe
V2 -> V3
- change Kconfig GPIO_REGMAP and REGMAP_SPI to be conditioned by GPIOLIB
- cast chip info to (kernel_ulong_t) to suppress warnings
- adjust copyright year to reflect the out-of-tree history
- remove unused sysfs and trigger header files
- clean up defined macros by using FIELD_PREP( ) inline
- use DECLARE_BITMAP( ) for defiining cfg_slots_status
- use clear/set _bit instead of assign_bit
- rename state field regmap to reg_gpiocon_regmap to better represent usage
- replace container_of( ) usages to ad_sigma_delta_to_ad7173( )
- improve readability of sampling frequency conversion in write_raw( )
specifying conversion from Micro to Milli
- use iio_device_claim_direct_mode( ) correctly in write_raw( )
- flip logic in write_raw( ) to reduce line length
- pass only state struct to gpio_init function
- remove else branch at end of probe
- remove comma after list terminator for of_match and id_table arrays
- clarify write_raw( ) realbits 32 bit size check in a comment
- change parsed fw property 'adi,bipolar' to 'bipolar' to matched referenced adc.yaml
- use reg_set_base for gpio regmap xlate
V1 -> V2
- keep original out-of-tree AD7173 naming
- remove gpio_cleanup
- handle 32bit realbits offset case
- use iio_device_claim_direct_mode, drop own mutex
- use dev_err_probe
- cleanup headers include
- use GENMASK() and FIELD_PREP()
- use HZ_PER_MHZ
- change #ifdef GPIOLIB to if( IS_ENABLED(CONFIG_GPIOLIB))
- use gpio-regmap
- change boolean flag in info struct to number of gpios
- NIH memset64
- use struct pointers for config comparison
- use spi_write_then_read for ADC reset
- use stack allocated buffer for reset
- define constant for reset sequence size
- use kcalloc instead of kzalloc
- change of naming to fw of dt parse function
- change de-referencing chain to local variable dev in multiple locations
- drop write_raw_get_fmt
- add driver private data to spi_device_id table
- use fsleep() instead of usleep_range()
- put config value inline
- align read/write raw arguments
- remove zeroed values from channel templates structure
- define constants for temperature sensor positive and negative inputs
- always enable temperature channel
- configure spi clock phase and polarity from driver
misc changes (test bit, return disable all, indentation fix, change statements to single line)

 drivers/iio/adc/Kconfig  |   17 +
 drivers/iio/adc/Makefile |    1 +
 drivers/iio/adc/ad7173.c | 1105 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 1123 insertions(+)
 create mode 100644 drivers/iio/adc/ad7173.c
drivers/iio/adc/Kconfig +17 -0
index 3b73c509bd68..c32054afdfc4 100644
@@ -70,6 +70,23 @@ config AD7124
 	  To compile this driver as a module, choose M here: the module will be
 	  called ad7124.
 
+config AD7173
+	tristate "Analog Devices AD7173 driver"
+	depends on SPI_MASTER
+	select AD_SIGMA_DELTA
+	select GPIO_REGMAP if GPIOLIB
+	select REGMAP_SPI if GPIOLIB
+	help
+	  Say yes here to build support for Analog Devices AD7173 and similar ADC
+	  Currently supported models:
+	   - AD7172-2
+	   - AD7173-8
+	   - AD7175-2
+	   - AD7176-2
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called ad7173.
+
 config AD7192
 	tristate "Analog Devices AD7190 AD7192 AD7193 AD7195 ADC driver"
 	depends on SPI
drivers/iio/adc/Makefile +1 -0
index d2fda54a3259..dd4210a3634f 100644
@@ -11,6 +11,7 @@ obj-$(CONFIG_AD7091R) += ad7091r-base.o
 obj-$(CONFIG_AD7091R5) += ad7091r5.o
 obj-$(CONFIG_AD7091R8) += ad7091r8.o
 obj-$(CONFIG_AD7124) += ad7124.o
+obj-$(CONFIG_AD7173) += ad7173.o
 obj-$(CONFIG_AD7192) += ad7192.o
 obj-$(CONFIG_AD7266) += ad7266.o
 obj-$(CONFIG_AD7280) += ad7280a.o
drivers/iio/adc/ad7173.c new file +1105 -0

1,105 lines not on this page · raw message

Signature · 1 line
2.42.0
Reviewed-by Nuno Sa on v13 3/3
#7 lore raw

Re: [PATCH v13 3/3] iio: adc: ad7173: add AD7173 driver

Quoted 11 lines · Dumitru Ceclan

The AD7173 family offer a complete integrated Sigma-Delta ADC solution which can be used in high precision, low noise single channel applications or higher speed multiplexed applications. The Sigma-Delta ADC is intended primarily for measurement of signals close to DC but also delivers outstanding performance with input bandwidths out to ~10kHz.

---

Hi Dumitru,

Just a couple of things... With those addressed:

...

Quoted 17 lines
drivers/iio/adc/ad7173.c new file +16 -0
+static int ad7173_disable_all(struct ad_sigma_delta *sd)
+{
+	struct ad7173_state *st = ad_sigma_delta_to_ad7173(sd);
+	int ret;
+	int i;
+
+	for (i = 0; i < st->num_channels; i++) {
+		ret = ad_sd_write_reg(sd, AD7173_REG_CH(i), 2, 0);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
+static struct ad_sigma_delta_info ad7173_sigma_delta_info = {

drivers/iio/adc/ad7173.c line 507

Quoted 10 lines
drivers/iio/adc/ad7173.c new file +10 -0
+	.set_channel = ad7173_set_channel,
+	.append_status = ad7173_append_status,
+	.disable_all = ad7173_disable_all,
+	.set_mode = ad7173_set_mode,
+	.has_registers = true,
+	.addr_shift = 0,
+	.read_mask = BIT(6),
+	.status_ch_mask = GENMASK(3, 0),
+	.data_reg = AD7173_REG_DATA,
+	.irq_flags = IRQF_TRIGGER_FALLING,

You need to rebase on the current testing (or maybe Jonathan can fix it if this get's applied in this version). Basically, I would drop the above .irq_flags assigment. The lib will now check if you gave the trigger over Firmware (like device tree) and use it. And that#s how we should set the IRQ trigger type. I did not removed the variable just for backward compatibility [1].

...

drivers/iio/adc/ad7173.c line 1042

Quoted 8 lines
drivers/iio/adc/ad7173.c new file +7 -0
+};
 
+	indio_dev->name = st->info->name;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->info = &ad7173_info;
+
+	spi->mode = SPI_MODE_3;
+

I don't think we need the above. We should just enforce it to SPI_CPOL| SPI_CPHA in the bindings [2].

[1]: https://lore.kernel.org/linux-iio/20240117-dev_sigma_delta_no_irq_flags-v1-2-db39261592cf@analog.com/
[2]: https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml#L45

- Nuno Sá

Quoted 1 line
#8 lore raw

Re: [PATCH v13 3/3] iio: adc: ad7173: add AD7173 driver

Quoted 1 line · Nuno Sá

On Tue, 2024-02-20 at 11:43 +0200, Dumitru Ceclan wrote:

...

Quoted 13 lines

drivers/iio/adc/ad7173.c line 1042

Quoted 9 lines
drivers/iio/adc/ad7173.c new file +7 -0
+};
 
+	indio_dev->name = st->info->name;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->info = &ad7173_info;
+
+	spi->mode = SPI_MODE_3;
+

I don't think we need the above. We should just enforce it to SPI_CPOL| SPI_CPHA in the bindings [2].

Quoted 1 line

[2]: https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml#L45

Rob Herring V1:

"""

Review

Quoted 6 lines
(quoted diff) +6 -0
+  required:
+    - compatible
+    - reg
+    - interrupts
+    - spi-cpol
+    - spi-cpha

If the device(s) are not configurable, then you shouldn't need these 2 properties. The driver can hardcode the correct setting. """

ref:
https://lore.kernel.org/linux-iio/[email protected]/

#9 lore raw

Re: [PATCH v13 3/3] iio: adc: ad7173: add AD7173 driver

Quoted 34 lines · Ceclan Dumitru
Quoted 1 line · Nuno Sá

On Tue, 2024-02-20 at 11:43 +0200, Dumitru Ceclan wrote:

...

Quoted 14 lines

drivers/iio/adc/ad7173.c line 1042

Quoted 9 lines
drivers/iio/adc/ad7173.c new file +7 -0
+};
 
+	indio_dev->name = st->info->name;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->info = &ad7173_info;
+
+	spi->mode = SPI_MODE_3;
+

I don't think we need the above. We should just enforce it to SPI_CPOL| SPI_CPHA in
the bindings [2].

Quoted 2 lines

[2]:
https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml#L45

Rob Herring V1:

"""

Quoted 6 lines

+  required:
+    - compatible
+    - reg
+    - interrupts
+    - spi-cpol
+    - spi-cpha

Quoted 7 lines

If the device(s) are not configurable, then you shouldn't need these 2 properties. The driver can hardcode the correct setting. """

ref:
https://lore.kernel.org/linux-iio/[email protected]/

I see. I thought it was the other way around... Then, the other thing is that I think you should call spi_setup() after hardcoding the mode.

- Nuno Sá

#10 lore raw

Re: [PATCH v13 3/3] iio: adc: ad7173: add AD7173 driver

In reply to Dumitru Ceclan
Quoted 10 lines · Dumitru Ceclan

The AD7173 family offer a complete integrated Sigma-Delta ADC solution which can be used in high precision, low noise single channel applications or higher speed multiplexed applications. The Sigma-Delta ADC is intended primarily for measurement of signals close to DC but also delivers outstanding performance with input bandwidths out to ~10kHz.

---

Another thing that caught my attention

...

drivers/iio/adc/ad7173.c line 830

Quoted 11 lines
drivers/iio/adc/ad7173.c new file +10 -0
+static int ad7173_register_clk_provider(struct iio_dev *indio_dev)
+{
+	struct ad7173_state *st = iio_priv(indio_dev);
+	struct device *dev = indio_dev->dev.parent;
+	struct fwnode_handle *fw_node = dev_fwnode(dev);
+	struct clk_init_data init = {};
+	int ret;
+
+	if (!fw_node)
+		return 0;

I think that better than the above check (do we really have any case where fw_node is NULL?) is to have:

if (!IS_ENABLED(CONFIG_COMMON_CLK))

	return 0;

- Nuno Sá

#11 lore raw

Re: [PATCH v13 3/3] iio: adc: ad7173: add AD7173 driver

Quoted 1 line · Nuno Sá

On Tue, 2024-02-20 at 11:43 +0200, Dumitru Ceclan wrote:

...

Quoted 7 lines

Another thing that caught my attention

drivers/iio/adc/ad7173.c line 825

Quoted 5 lines
drivers/iio/adc/ad7173.c new file +5 -0
+static int ad7173_register_clk_provider(struct iio_dev *indio_dev)
+{
+	struct ad7173_state *st = iio_priv(indio_dev);
+	struct device *dev = indio_dev->dev.parent;
+	struct fwnode_handle *fw_node = dev_fwnode(dev);

Since you used this context, I would also like fw_node to be renamed to fwnode (in case it will still be used).

Quoted 11 lines

drivers/iio/adc/ad7173.c line 830

Quoted 5 lines
drivers/iio/adc/ad7173.c new file +5 -0
+	struct clk_init_data init = {};
+	int ret;
+
+	if (!fw_node)
+		return 0;

I think that better than the above check (do we really have any case where fw_node is NULL?) is to have:

if (!IS_ENABLED(CONFIG_COMMON_CLK))

	return 0;
Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on v13 1/3
#12 lore raw
In reply to Dumitru Ceclan

Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml line 53

Quoted 10 lines · Dumitru Ceclan
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +9 -0
+  interrupts:
+    minItems: 1
+    description: |
 
+
+  interrupt-names:
+    minItems: 1
+    items:
+      - const: rdy
+      - const: err

I noticed that for minItems == 1, the rdy interrupt is required and err is the optional one.

With that in mind, you can simplify the interrupts description so that it describes the interrupts separately:

interrupts:
minItems:
items:
- description:
Ready: multiplexed with SPI data out. While SPI CS is low, can be used to indicate the completion of a conversion.

- description:
Error: The three error bits in the status register (ADC_ERROR, CRC_ERROR, and REG_ERROR) are OR'ed, inverted, and mapped to the ERROR pin. Therefore, the ERROR pin indicates that an error has occurred.

Otherwise, I think everything has been sorted out?

Cheers,
Conor.

maintainer
#13 lore raw
Quoted 26 lines · On Tue, 20 Feb 2024 18:52:37 +0000 Conor Dooley <[email protected]> wrote:

Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml line 53

Quoted 10 lines · Dumitru Ceclan
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +9 -0
+  interrupts:
+    minItems: 1
+    description: |  
 
+
+  interrupt-names:
+    minItems: 1
+    items:
+      - const: rdy
+      - const: err  

I noticed that for minItems == 1, the rdy interrupt is required and err is the optional one.

With that in mind, you can simplify the interrupts description so that it describes the interrupts separately:

interrupts:
minItems:
items:
- description:
Ready: multiplexed with SPI data out. While SPI CS is low, can be used to indicate the completion of a conversion.

Quoted 8 lines

- description:
Error: The three error bits in the status register (ADC_ERROR, CRC_ERROR, and REG_ERROR) are OR'ed, inverted, and mapped to the ERROR pin. Therefore, the ERROR pin indicates that an error has occurred.

Otherwise, I think everything has been sorted out?

This ordering may bite us in the future. Someone will build a board with err as only one wired. But meh, it will be a binding relaxation needed so I'm not that bothered by that.

Quoted 3 lines

Cheers,
Conor.

reviewer
#14 lore raw
In reply to Dumitru Ceclan
Quoted 1 line · Dumitru Ceclan

...

Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml line 88

Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +5 -0
+
+  avdd-supply:
+    description: Avdd supply, can be used as reference for conversion.
+                 This supply is referenced to AVSS, voltage specified here
+                 represens (AVDD - AVSS).

The datasheets call this AVDD1, not AVDD. Would be nice to use the correct name to avoid ambiguity.

Also check spelling represents above and below.

Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml line 100

Quoted 12 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +12 -0
+
+  avdd2-supply:
+    description: Avdd2 supply, used as the input to the internal voltage regulator.
+                 This supply is referenced to AVSS, voltage specified here
+                 represens (AVDD2 - AVSS).
+
+  iovdd-supply:
+    description: iovdd supply, used for the chip digital interface.
+
+  clocks:
+    maxItems: 1
+    description: |

Don't need | here.

Quoted 11 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +11 -0
+      Optional external clock source. Can include one clock source: external
+      clock or external crystal.
+
+  clock-names:
+    enum:
+      - ext-clk
+      - xtal
+
+  '#clock-cells':
+    const: 0
+

Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml line 121

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +10 -0
+patternProperties:
+  "^channel@[0-9a-f]$":
+    type: object
+    $ref: adc.yaml
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        minimum: 0
+        maximum: 15

Parts ending in -2 only have four channels.

Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml line 127

Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +6 -0
+
+      diff-channels:
+        items:
+          minimum: 0
+          maximum: 31
+

Are we missing bipolar: true here? (since we have
unevaluatedProperties: false)

Quoted 16 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +16 -0
+      adi,reference-select:
+        description: |
+          Select the reference source to use when converting on
+          the specific channel. Valid values are:
+          vref       : REF+  /REF−
+          vref2      : REF2+ /REF2−
+          refout-avss: REFOUT/AVSS (Internal reference)
+          avdd       : AVDD  /AVSS
+
+          External reference ref2 only available on ad7173-8.
+          If not specified, internal reference used.
+        $ref: /schemas/types.yaml#/definitions/string
+        enum:
+          - vref
+          - vref2
+          - refout-avss

Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml line 153

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +10 -0
+          - avdd
+        default: refout-avss
+
+    required:
+      - reg
+      - diff-channels
+
+required:
+  - compatible
+  - reg

Aren't the various power supplies supposed to be required?

- avdd-supply
- avdd2-supply
- iovdd-supply

#15 lore raw
Quoted 1 line · David Lechner

On Tue, Feb 20, 2024 at 3:43 AM Dumitru Ceclan <[email protected]> wrote:

...

Quoted 6 lines

Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml line 100

Quoted 3 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +3 -0
+  clocks:
+    maxItems: 1
+    description: |

Don't need | here.

The description contains ": ". Without '|' yaml syntax considers the whole string before ':' as another attribute

Quoted 3 lines
Quoted 3 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +3 -0
+      Optional external clock source. Can include one clock source: external
+      clock or external crystal.
+

...

Quoted 10 lines

Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml line 127

Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +6 -0
+
+      diff-channels:
+        items:
+          minimum: 0
+          maximum: 31
+

Are we missing bipolar: true here? (since we have
unevaluatedProperties: false)

No, since we are referencing the adc schema "$ref: adc.yaml" Which contains:
"""
bipolar:

$ref: /schemas/types.yaml#/definitions/flag

description: If provided, the channel is to be used in bipolar mode.
"""

...

Quoted 10 lines

Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml line 153

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +4 -0
+
+required:
+  - compatible
+  - reg

Aren't the various power supplies supposed to be required?

- avdd-supply
- avdd2-supply
- iovdd-supply

From my point of view, if someone uses a single supply (avdd == avdd2 == iovdd), and uses only the internal reference then the supplies should not necessarily be required.

#16 lore raw
Quoted 17 lines
Quoted 11 lines

Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml line 127

Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +6 -0
+
+      diff-channels:
+        items:
+          minimum: 0
+          maximum: 31
+

Are we missing bipolar: true here? (since we have
unevaluatedProperties: false)

No, since we are referencing the adc schema "$ref: adc.yaml" Which contains:
"""
bipolar:

Quoted 4 lines

$ref: /schemas/types.yaml#/definitions/flag

description: If provided, the channel is to be used in bipolar mode.
"""

FWIW, the difference here is whether or not the binding for the device contains "additionalProperties: false" or "unevaluatedProperties: false". The former requires "bipolar: true", the latter does not.

Cheers,
Conor.

maintainer
#17 lore raw
In reply to Ceclan Dumitru
Quoted 51 lines · On Wed, 21 Feb 2024 10:29:30 +0200 Ceclan Dumitru <[email protected]>…
Quoted 1 line · David Lechner

On Tue, Feb 20, 2024 at 3:43 AM Dumitru Ceclan <[email protected]> wrote:

...

Quoted 6 lines

Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml line 100

Quoted 3 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +3 -0
+  clocks:
+    maxItems: 1
+    description: |  

Don't need | here.

The description contains ": ". Without '|' yaml syntax considers the whole string before ':' as another attribute

Quoted 3 lines
Quoted 3 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +3 -0
+      Optional external clock source. Can include one clock source: external
+      clock or external crystal.
+  

...

Quoted 10 lines

Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml line 127

Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +6 -0
+
+      diff-channels:
+        items:
+          minimum: 0
+          maximum: 31
+  

Are we missing bipolar: true here? (since we have
unevaluatedProperties: false)

No, since we are referencing the adc schema "$ref: adc.yaml" Which contains:
"""
bipolar:

$ref: /schemas/types.yaml#/definitions/flag

description: If provided, the channel is to be used in bipolar mode.
"""

...

Quoted 7 lines

Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml line 153

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +4 -0
+
+required:
+  - compatible
+  - reg  

Aren't the various power supplies supposed to be required?

Quoted 7 lines
Quoted 3 lines

- avdd-supply
- avdd2-supply
- iovdd-supply

From my point of view, if someone uses a single supply (avdd == avdd2 == iovdd), and uses only the internal reference then the supplies should not necessarily be required.

Convention is that anything that represent a voltage on a pin that is needed for operation should be required. Key here is the difference from optional supplies where the driver does something different. vref is a good example of this. The ones above are always needed I think.

Obviously they may all say the same thing if they are connected externally.