Skip to contentSkip to conversation

dt-bindings: adc: add AD7173

PATCH Superseded Dumitru Ceclan 8 participants 14 messages Sep 28, 2023 – Oct 4, 2023

Subsystems (4)

v2 of 16 Superseded Latest is v16 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 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.

---
 .../bindings/iio/adc/adi,ad7173.yaml          | 139 ++++++++++++++++++
 1 file changed, 139 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +139 -0
new file mode 100644
index 000000000000..a0f437297a23
@@ -0,0 +1,139 @@
+# 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 device driver
+
+maintainers:
+  - Ceclan Dumitru <[email protected]>
+
+description: |
+  Bindings for the Analog Devices AD717X ADC's. 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:
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  spi-max-frequency:
+    maximum: 20000000
+
+  spi-cpol:
+    type: boolean
+
+  spi-cpha:
+    type: boolean
+
+  required:
+    - compatible
+    - reg
+    - interrupts
+
+patternProperties:
+  "^channel@[0-9a-f]$":
+    type: object
+    $ref: adc.yaml
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        description: Channel number
+        minimum: 0
+        maximum: 15
+
+      diff-channels:
+        description:
+          Analog input pins
+        items:
+          minimum: 0
+          maximum: 31
+
+      adi,bipolar:
+        description: Specify if the channel should measure in bipolar mode.
+        type: boolean
+
+    required:
+      - reg
+      - diff-channels
+
+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@0 {
+        compatible = "adi,ad7173-8";
+        reg = <0>;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
+        interrupt-parent = <&gpio>;
+        spi-max-frequency = <5000000>;
+
+        channel@0 {
+          reg = <0>;
+          adi,bipolar;
+
+          diff-channels = <0 1>;
+        };
+
+        channel@1 {
+          reg = <1>;
+
+          diff-channels = <2 3>;
+        };
+
+        channel@2 {
+          reg = <2>;
+          adi,bipolar;
+
+          diff-channels = <4 5>;
+        };
+
+        channel@3 {
+          reg = <3>;
+          adi,bipolar;
+
+          diff-channels = <6 7>;
+        };
+
+        channel@4 {
+          reg = <4>;
+
+          diff-channels = <8 9>;
+        };
+      };
+    };
Signature · 1 line
2.39.2
#1 lore raw

PATCH v2 2/2 iio: adc: ad7173: add AD7173 driver

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.

---
 drivers/iio/adc/Kconfig  |  13 +
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad7173.c | 850 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 864 insertions(+)
 create mode 100644 drivers/iio/adc/ad7173.c
drivers/iio/adc/Kconfig +13 -0
index 517b3db114b8..fe14a8b24e41 100644
@@ -54,6 +54,19 @@ 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
+	select REGMAP_SPI
+	help
+	  Say yes here to build support for Analog Devices AD7173 and similar ADC
+	  (currently supported: 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 2facf979327d..8c70333ae967 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
 obj-$(CONFIG_AD4130) += ad4130.o
 obj-$(CONFIG_AD7091R5) += ad7091r5.o ad7091r-base.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 +850 -0

850 lines not on this page · raw message

Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH v2 2/2] iio: adc: ad7173: add AD7173 driver

Quoted 7 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.

Forgot changelog
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)

#3 lore raw

Re: [PATCH v2 2/2] iio: adc: ad7173: add AD7173 driver

In reply to Dumitru Ceclan
kernel test robot noticed the following build warnings:

Hi Dumitru,

kernel test robot noticed the following build warnings:

[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master v6.6-rc3 next-20230928] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Dumitru-Ceclan/iio-adc-ad7173-add-AD7173-driver/20230928-205802
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20230928125443.615006-2-mitrutzceclan%40gmail.com
patch subject: [PATCH v2 2/2] iio: adc: ad7173: add AD7173 driver
config: sparc-allyesconfig (https://download.01.org/0day-ci/archive/20230929/[email protected]/config)
compiler: sparc64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230929/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/iio/adc/ad7173.c:829:23: warning: initialization of 'long unsigned int' from 'const struct ad7173_device_info *' makes integer from pointer without a cast [-Wint-conversion]
     829 |         { "ad7172-2", &ad7173_device_info[ID_AD7172_2], },
         |                       ^
   drivers/iio/adc/ad7173.c:829:23: note: (near initialization for 'ad7173_id_table[0].driver_data')
   drivers/iio/adc/ad7173.c:830:23: warning: initialization of 'long unsigned int' from 'const struct ad7173_device_info *' makes integer from pointer without a cast [-Wint-conversion]
     830 |         { "ad7173-8", &ad7173_device_info[ID_AD7173_8], },
         |                       ^
   drivers/iio/adc/ad7173.c:830:23: note: (near initialization for 'ad7173_id_table[1].driver_data')
   drivers/iio/adc/ad7173.c:831:23: warning: initialization of 'long unsigned int' from 'const struct ad7173_device_info *' makes integer from pointer without a cast [-Wint-conversion]
     831 |         { "ad7175-2", &ad7173_device_info[ID_AD7175_2], },
         |                       ^
   drivers/iio/adc/ad7173.c:831:23: note: (near initialization for 'ad7173_id_table[2].driver_data')
   drivers/iio/adc/ad7173.c:832:23: warning: initialization of 'long unsigned int' from 'const struct ad7173_device_info *' makes integer from pointer without a cast [-Wint-conversion]
     832 |         { "ad7176-2", &ad7173_device_info[ID_AD7176_2], },
         |                       ^

drivers/iio/adc/ad7173.c:832:23: note: (near initialization for 'ad7173_id_table[3].driver_data')

vim +829 drivers/iio/adc/ad7173.c

827
828 static const struct spi_device_id ad7173_id_table[] = {

 > 829		{ "ad7172-2", &ad7173_device_info[ID_AD7172_2], },

830 { "ad7173-8", &ad7173_device_info[ID_AD7173_8], },
831 { "ad7175-2", &ad7173_device_info[ID_AD7175_2], },
832 { "ad7176-2", &ad7173_device_info[ID_AD7176_2], },
833 { },
834 };
835 MODULE_DEVICE_TABLE(spi, ad7173_id_table);
836

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#4 lore raw

Re: [PATCH v2 2/2] iio: adc: ad7173: add AD7173 driver

Quoted 43 lines · On Fri, 29 Sep 2023 07:29:01 +0800 kernel test robot <[email protected]> wrote:

Hi Dumitru,

kernel test robot noticed the following build warnings:

[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master v6.6-rc3 next-20230928] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Dumitru-Ceclan/iio-adc-ad7173-add-AD7173-driver/20230928-205802
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20230928125443.615006-2-mitrutzceclan%40gmail.com
patch subject: [PATCH v2 2/2] iio: adc: ad7173: add AD7173 driver
config: sparc-allyesconfig (https://download.01.org/0day-ci/archive/20230929/[email protected]/config)
compiler: sparc64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230929/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

drivers/iio/adc/ad7173.c:829:23: warning: initialization of 'long unsigned int' from 'const struct ad7173_device_info *' makes integer from pointer without a cast [-Wint-conversion]

     829 |         { "ad7172-2", &ad7173_device_info[ID_AD7172_2], },
         |                       ^
   drivers/iio/adc/ad7173.c:829:23: note: (near initialization for 'ad7173_id_table[0].driver_data')
   drivers/iio/adc/ad7173.c:830:23: warning: initialization of 'long unsigned int' from 'const struct ad7173_device_info *' makes integer from pointer without a cast [-Wint-conversion]
     830 |         { "ad7173-8", &ad7173_device_info[ID_AD7173_8], },
         |                       ^
   drivers/iio/adc/ad7173.c:830:23: note: (near initialization for 'ad7173_id_table[1].driver_data')
   drivers/iio/adc/ad7173.c:831:23: warning: initialization of 'long unsigned int' from 'const struct ad7173_device_info *' makes integer from pointer without a cast [-Wint-conversion]
     831 |         { "ad7175-2", &ad7173_device_info[ID_AD7175_2], },
         |                       ^
   drivers/iio/adc/ad7173.c:831:23: note: (near initialization for 'ad7173_id_table[2].driver_data')
   drivers/iio/adc/ad7173.c:832:23: warning: initialization of 'long unsigned int' from 'const struct ad7173_device_info *' makes integer from pointer without a cast [-Wint-conversion]
     832 |         { "ad7176-2", &ad7173_device_info[ID_AD7176_2], },
         |                       ^

drivers/iio/adc/ad7173.c:832:23: note: (near initialization for 'ad7173_id_table[3].driver_data')

Quoted 8 lines

vim +829 drivers/iio/adc/ad7173.c

   827	
   828	static const struct spi_device_id ad7173_id_table[] = {
Quoted 1 line

829 { "ad7172-2", &ad7173_device_info[ID_AD7172_2], },

830 { "ad7173-8", &ad7173_device_info[ID_AD7173_8], },
831 { "ad7175-2", &ad7173_device_info[ID_AD7175_2], },
832 { "ad7176-2", &ad7173_device_info[ID_AD7176_2], },

Cast these to kernel_ulong_t as done in similar drivers like the ad7192

Jonathan

Quoted 5 lines
   833		{ },
   834	};
   835	MODULE_DEVICE_TABLE(spi, ad7173_id_table);
   836	
maintainer
#5 lore raw

Re: [PATCH v2 2/2] iio: adc: ad7173: add AD7173 driver

In reply to Dumitru Ceclan
Quoted 7 lines · On Thu, 28 Sep 2023 15:54:43 +0300 Dumitru Ceclan <[email protected]>…

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,

A few more things came up on a fresh look. All small stuff so fingers crossed for v3.

Jonathan

Quoted 12 lines
---
 drivers/iio/adc/Kconfig  |  13 +
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad7173.c | 850 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 864 insertions(+)
 create mode 100644 drivers/iio/adc/ad7173.c
drivers/iio/adc/Kconfig +0 -0
index 517b3db114b8..fe14a8b24e41 100644

drivers/iio/adc/Kconfig config AD7124 · line 61

Quoted 8 lines
drivers/iio/adc/Kconfig +5 -0
@@ -54,6 +54,19 @@ 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 you are selecting it, why does it have if guards in the driver. I prefer the select here, so drop this if guards.

Quoted 11 lines
drivers/iio/adc/Kconfig +8 -0
+	select REGMAP_SPI
+	help
+	  Say yes here to build support for Analog Devices AD7173 and similar ADC
+	  (currently supported: 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/ad7173.c line 4

Quoted 10 lines
drivers/iio/adc/ad7173.c new file +4 -0
new file mode 100644
index 000000000000..648bcec836a5
@@ -0,0 +1,850 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AD7172-2/AD7173-8/AD7175-2/AD7176-2 SPI ADC driver
+ * Copyright (C) 2023 Analog Devices, Inc.

As you list Lars as an author and he's not be at ADI for 'a while' I'm guessing this should probably include a date range going back a few years. Always good to reflect that history even if it's been out of tree.

Quoted 14 lines
drivers/iio/adc/ad7173.c new file +14 -0
+ */
+
+#include <linux/bitfield.h>
+#include <linux/bits.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/gpio/driver.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/property.h>
+#include <linux/regmap.h>

drivers/iio/adc/ad7173.c line 28

Quoted 10 lines
drivers/iio/adc/ad7173.c new file +10 -0
+#include <linux/gpio/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/slab.h>
+#include <linux/spi/spi.h>
+#include <linux/sysfs.h>
+#include <linux/units.h>
+
+#include <linux/iio/buffer.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>

sysfs.h is only needed if you are defining IIO attrs without doing it via the IIO core channel descriptions. I don't see you doing that so shouldn't be needed.

drivers/iio/adc/ad7173.c line 29

Quoted 1 line
drivers/iio/adc/ad7173.c new file +1 -0
+#include <linux/iio/trigger.h>

Whilst the driver provides a trigger, it's via the ad_sigma_delta library so I don't think this driver needs to include trigger.h

Quoted 72 lines
drivers/iio/adc/ad7173.c new file +72 -0
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+
+#include <linux/iio/adc/ad_sigma_delta.h>
+
+#define AD7173_REG_COMMS		0x00
+#define AD7173_REG_ADC_MODE		0x01
+#define AD7173_REG_INTERFACE_MODE	0x02
+#define AD7173_REG_CRC			0x03
+#define AD7173_REG_DATA			0x04
+#define AD7173_REG_GPIO			0x06
+#define AD7173_REG_ID			0x07
+#define AD7173_REG_CH(x)		(0x10 + (x))
+#define AD7173_REG_SETUP(x)		(0x20 + (x))
+#define AD7173_REG_FILTER(x)		(0x28 + (x))
+#define AD7173_REG_OFFSET(x)		(0x30 + (x))
+#define AD7173_REG_GAIN(x)		(0x38 + (x))
+
+#define AD7173_RESET_LENGTH		BITS_TO_BYTES(64)
+
+#define AD7173_CH_ENABLE		BIT(15)
+#define AD7173_CH_SETUP_SEL_MASK	GENMASK(14, 12)
+#define AD7173_CH_SETUP_SEL(x)		FIELD_PREP(AD7173_CH_SETUP_SEL_MASK, x)
+#define AD7173_CH_SETUP_AINPOS_MASK	GENMASK(9, 5)
+#define AD7173_CH_SETUP_AINPOS(x)	FIELD_PREP(AD7173_CH_SETUP_AINPOS_MASK, x)
+#define AD7173_CH_SETUP_AINNEG(x)	(x)
+
+#define AD7173_CH_ADDRESS(pos, neg) \
+	(AD7173_CH_SETUP_AINPOS(pos) | AD7173_CH_SETUP_AINNEG(neg))
+#define AD7173_AIN_TEMP_POS	17
+#define AD7173_AIN_TEMP_NEG	18
+
+#define AD7172_ID			0x00d0
+#define AD7173_ID			0x30d0
+#define AD7175_ID			0x0cd0
+#define AD7176_ID			0x0c90
+#define AD7173_ID_MASK			GENMASK(15, 4)
+
+#define AD7173_ADC_MODE_REF_EN		BIT(15)
+#define AD7173_ADC_MODE_SING_CYC	BIT(13)
+#define AD7173_ADC_MODE_MODE_MASK	GENMASK(6, 4)
+#define AD7173_ADC_MODE_MODE(x)		FIELD_PREP(AD7173_ADC_MODE_MODE_MASK, x)
+#define AD7173_ADC_MODE_CLOCKSEL_MASK	GENMASK(3, 2)
+#define AD7173_ADC_MODE_CLOCKSEL(x)	FIELD_PREP(AD7173_ADC_MODE_CLOCKSEL_MASK, x)
+
+#define AD7173_GPIO_PDSW	BIT(14)
+#define AD7173_GPIO_OP_EN2_3	BIT(13)
+#define AD7173_GPIO_MUX_IO	BIT(12)
+#define AD7173_GPIO_SYNC_EN	BIT(11)
+#define AD7173_GPIO_ERR_EN	BIT(10)
+#define AD7173_GPIO_ERR_DAT	BIT(9)
+#define AD7173_GPIO_GP_DATA3	BIT(7)
+#define AD7173_GPIO_GP_DATA2	BIT(6)
+#define AD7173_GPIO_IP_EN1	BIT(5)
+#define AD7173_GPIO_IP_EN0	BIT(4)
+#define AD7173_GPIO_OP_EN1	BIT(3)
+#define AD7173_GPIO_OP_EN0	BIT(2)
+#define AD7173_GPIO_GP_DATA1	BIT(1)
+#define AD7173_GPIO_GP_DATA0	BIT(0)
+
+#define AD7173_GPO12_DATA(x)	BIT(x)
+#define AD7173_GPO23_DATA(x)	BIT(x + 4)
+#define AD7173_GPO_DATA(x)	(x < 2 ? AD7173_GPO12_DATA(x) : AD7173_GPO23_DATA(x))
+
+#define AD7173_INTERFACE_DATA_STAT	BIT(6)
+#define AD7173_INTERFACE_DATA_STAT_EN(x)\
+	FIELD_PREP(AD7173_INTERFACE_DATA_STAT, x)
+
+#define AD7173_SETUP_BIPOLAR		BIT(12)
+#define AD7173_SETUP_AREF_BUF_MASK	GENMASK(11, 10)
+#define AD7173_SETUP_AIN_BUF_MASK	GENMASK(9, 8)
+

drivers/iio/adc/ad7173.c line 111

Quoted 10 lines
drivers/iio/adc/ad7173.c new file +10 -0
+#define AD7173_SETUP_REF_SEL_MASK	GENMASK(5, 4)
+#define AD7173_SETUP_REF_SEL(x)		FIELD_PREP(AD7173_SETUP_REF_SEL_MASK, x)
+#define AD7173_SETUP_REF_SEL_AVDD1_AVSS	0x3
+#define AD7173_SETUP_REF_SEL_INT_REF	0x2
+#define AD7173_SETUP_REF_SEL_EXT_REF2	0x1
+#define AD7173_SETUP_REF_SEL_EXT_REF	0x0
+
+#define AD7173_FILTER_ODR0_MASK		GENMASK(5, 0)
+#define AD7173_FILTER_ODR0(x)		FIELD_PREP(AD7173_FILTER_ODR0_MASK, x)
+#define AD7173_FILTER_ODR0(x)		FIELD_PREP(AD7173_FILTER_ODR0_MASK, x)

Firstly why is it duplicated?

Secondly why not just use the FIELD_PREP() inline as it's obvious what it's doing and the extra macro, if anything makes it less clear. Same is true for all the similar macros.

Quoted 35 lines
drivers/iio/adc/ad7173.c new file +35 -0
+
+enum ad7173_ids {
+	ID_AD7172_2,
+	ID_AD7173_8,
+	ID_AD7175_2,
+	ID_AD7176_2,
+};
+
+struct ad7173_device_info {
+	unsigned int id;
+	unsigned int num_inputs;
+	unsigned int num_configs;
+	unsigned int num_channels;
+	unsigned char num_gpios;
+	bool has_temp;
+	unsigned int clock;
+
+	const unsigned int *sinc5_data_rates;
+	unsigned int num_sinc5_data_rates;
+};
+
+struct ad7173_channel_config {
+	bool live;
+	unsigned char cfg_slot;
+	/* Following fields are used to compare equality. Bipolar must be first */
+	bool bipolar;
+	bool input_buf;
+	unsigned char odr;
+};
+
+struct ad7173_channel {
+	unsigned int chan_reg;
+	struct ad7173_channel_config cfg;
+	unsigned int ain;
+};

drivers/iio/adc/ad7173.c line 156

Quoted 10 lines
drivers/iio/adc/ad7173.c new file +10 -0
+
+struct ad7173_state {
+	const struct ad7173_device_info *info;
+	struct ad_sigma_delta sd;
+	struct ad7173_channel *channels;
+	struct regulator *reg;
+	unsigned int adc_mode;
+	unsigned int interface_mode;
+	unsigned int num_channels;
+	unsigned long cfg_slots_status; /* slots usage status bitmap*/

Whilst you might not need to as it fits in one, DECLARE_BITMAP() is a good way of making it clear something is a bitmap.

I wondered if you used this a bitmap, and you do. Though another question there is why assign_bit() when value is known. Just use set_bit() or clear_bit() directly

drivers/iio/adc/ad7173.c line 224

Quoted 9 lines
drivers/iio/adc/ad7173.c new file +8 -0
+	unsigned long long config_usage_counter;
+	unsigned long long *config_cnts;
+#if IS_ENABLED(CONFIG_GPIOLIB)
+	struct regmap *regmap;
+	struct gpio_regmap *gpio_regmap;
+#endif
+};
 
+#if IS_ENABLED(CONFIG_GPIOLIB)

Seems odd to have these guards. I don't think we mind obliging people to build with GPIOLIB support as very unlikely they won't have it anyway for other reasons. Looking at the Kconfig I see you select this anyway, so just drop the if guards.

Quoted 25 lines
drivers/iio/adc/ad7173.c new file +25 -0
+
+static const struct regmap_range ad7173_range_gpio[] = {
+	regmap_reg_range(AD7173_REG_GPIO, AD7173_REG_GPIO),
+};
+
+static const struct regmap_access_table ad7173_access_table = {
+	.yes_ranges = ad7173_range_gpio,
+	.n_yes_ranges = ARRAY_SIZE(ad7173_range_gpio),
+};
+
+static const struct regmap_config ad7173_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 16,
+	.rd_table = &ad7173_access_table,
+	.wr_table = &ad7173_access_table,
+	.read_flag_mask = BIT(6),
+};
+
+static int ad7173_mask_xlate(struct gpio_regmap *gpio, unsigned int base,
+			     unsigned int offset, unsigned int *reg,
+			     unsigned int *mask)
+{
+	*mask = AD7173_GPO_DATA(offset);
+	*reg = AD7173_REG_GPIO;
+	return 0;

drivers/iio/adc/ad7173.c line 259

Quoted 10 lines
drivers/iio/adc/ad7173.c new file +10 -0
+}
+
+static int ad7173_gpio_init(struct iio_dev *indio_dev)
+{
+	struct ad7173_state *st = iio_priv(indio_dev);
+	struct gpio_regmap_config gpio_regmap = {};
+	struct device *dev = &st->sd.spi->dev;
+	unsigned int mask;
+
+	st->regmap = devm_regmap_init_spi(st->sd.spi, &ad7173_regmap_config);

If the regmap config is only used for the gpio parts, good to name it to make that clear.

Quoted 18 lines
drivers/iio/adc/ad7173.c new file +18 -0
+	if (IS_ERR(st->regmap)) {
+		return dev_err_probe(dev, PTR_ERR(st->regmap),
+				     "Unable to init regmap\n");
+	}
+
+	mask = AD7173_GPIO_OP_EN0 | AD7173_GPIO_OP_EN1 | AD7173_GPIO_OP_EN2_3;
+	regmap_update_bits(st->regmap, AD7173_REG_GPIO, mask, mask);
+
+	gpio_regmap.parent = dev;
+	gpio_regmap.regmap = st->regmap;
+	gpio_regmap.ngpio = st->info->num_gpios;
+	gpio_regmap.reg_set_base = GPIO_REGMAP_ADDR_ZERO;
+	gpio_regmap.reg_mask_xlate = ad7173_mask_xlate;
+
+	st->gpio_regmap = devm_gpio_regmap_register(dev, &gpio_regmap);
+	if (IS_ERR(st->gpio_regmap)) {
+		return dev_err_probe(dev, PTR_ERR(st->gpio_regmap),
+				     "Unable to init gpio-regmap\n");

drivers/iio/adc/ad7173.c line 287

Quoted 10 lines
drivers/iio/adc/ad7173.c new file +10 -0
+	}
+
+	return 0;
+}
+
+#endif /* CONFIG_GPIOLIB */
+
+static struct ad7173_state *ad_sigma_delta_to_ad7173(struct ad_sigma_delta *sd)
+{
+	return container_of(sd, struct ad7173_state, sd);

At least one more place you can use this... ( I deleted it whilst reviewing but remembered the pattern). It's in ad7173_append_status()

Quoted 27 lines
drivers/iio/adc/ad7173.c new file +27 -0
+}
+
+static void ad7173_reset_usage_cnts(struct ad7173_state *st)
+{
+	memset64(st->config_cnts, 0, st->info->num_configs);
+	st->config_usage_counter = 0;
+}
+
+static struct ad7173_channel_config *ad7173_find_live_config
+	(struct ad7173_state *st, struct ad7173_channel_config *cfg)
+{
+	struct ad7173_channel_config *cfg_aux;
+	ptrdiff_t cmp_size, offset;
+	int i;
+
+	offset = offsetof(struct ad7173_channel_config, cfg_slot) +
+		 sizeof(cfg->cfg_slot);
+	cmp_size = sizeof(*cfg) - offset;
+
+	for (i = 0; i < st->num_channels; i++) {
+		cfg_aux = &st->channels[i].cfg;
+
+		if (cfg_aux->live && !memcmp(&cfg->bipolar, &cfg_aux->bipolar,
+					     cmp_size))
+			return cfg_aux;
+	}
+	return NULL;

drivers/iio/adc/ad7173.c

Quoted 10 lines
drivers/iio/adc/ad7173.c new file +9 -0
+}
 
+
+static int ad7173_set_mode(struct ad_sigma_delta *sd,
+			   enum ad_sigma_delta_mode mode)
+{
+	struct ad7173_state *st = ad_sigma_delta_to_ad7173(sd);
+
+	st->adc_mode &= ~AD7173_ADC_MODE_MODE_MASK;
+	st->adc_mode |= AD7173_ADC_MODE_MODE(mode);

Another one I'd find easier to read if it were just FIELD_PREP(AD71...)
as then it would be obvious we masked the field out then replaced it. It's fairly obvious anyway, but the macro doesn't make it more than just calling FIELD_PREP directly.

Quoted 36 lines
drivers/iio/adc/ad7173.c new file +34 -0
+
+	return ad_sd_write_reg(&st->sd, AD7173_REG_ADC_MODE, 2, st->adc_mode);
+}
 
 
+static int ad7173_read_raw(struct iio_dev *indio_dev,
+			   struct iio_chan_spec const *chan,
+			   int *val, int *val2, long info)
+{
+	struct ad7173_state *st = iio_priv(indio_dev);
+	unsigned int reg;
+	int ret;
+
+	switch (info) {
+	case IIO_CHAN_INFO_RAW:
+		ret = ad_sigma_delta_single_conversion(indio_dev, chan, val);
+		if (ret < 0)
+			return ret;
+
+		/* disable channel after single conversion */
+		ret = ad_sd_write_reg(&st->sd, AD7173_REG_CH(chan->address), 2, 0);
+		if (ret < 0)
+			return ret;
+
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_SCALE:
+		if (chan->type == IIO_TEMP) {
+			*val = 250000000;
+			*val2 = 800273203; /* (2^24 * 477) / 10 */
+			return IIO_VAL_FRACTIONAL;
+		} else {
+			*val = 2500;
+			if (chan->differential)
+				*val2 = 23;
+			else
+				*val2 = 24;

drivers/iio/adc/ad7173.c line 542

Quoted 10 lines
drivers/iio/adc/ad7173.c new file +10 -0
+			return IIO_VAL_FRACTIONAL_LOG2;
+		}
+	case IIO_CHAN_INFO_OFFSET:
+		if (chan->type == IIO_TEMP) {
+			*val = -874379;
+		} else {
+			if (chan->differential)
+				*val = (chan->scan_type.realbits < 32) ?
+					-(1 << (chan->scan_type.realbits - 1)) :
+					INT_MIN;

when is realbits >= 32? I'm not seeing such a case, so perhaps a comment here if there is one.

drivers/iio/adc/ad7173.c line 551

Quoted 9 lines
drivers/iio/adc/ad7173.c new file +9 -0
+			else
+				*val = 0;
+		}
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		reg = st->channels[chan->address].cfg.odr;
+
+		*val = st->info->sinc5_data_rates[reg] / MILLI;
+		*val2 = (st->info->sinc5_data_rates[reg] % MILLI) * MILLI;

* MICRO/MILLI

probably better expresses what is going on here as first bit ends up in milli and you want it in micro. Maths the same though - just a slight boost in readability I think.

Quoted 7 lines
drivers/iio/adc/ad7173.c new file +7 -0
+
+		return IIO_VAL_INT_PLUS_MICRO;
+	}
+	return -EINVAL;
+}
+
+static int ad7173_write_raw(struct iio_dev *indio_dev,

drivers/iio/adc/ad7173.c line 568

Quoted 10 lines
drivers/iio/adc/ad7173.c new file +10 -0
+			    struct iio_chan_spec const *chan,
+			    int val, int val2, long info)
+{
+	struct ad7173_state *st = iio_priv(indio_dev);
+	struct ad7173_channel_config *cfg;
+	unsigned int freq, i, reg;
+	int ret = 0;
+
+	iio_device_claim_direct_mode(indio_dev);
+	if (iio_buffer_enabled(indio_dev)) {

Take a closer look at what iio_device_claim_direct_mode does and
check it's return value. For reference if the buffer is enabled
this is a double unlock of the mutex and a nice big error splat.

Quoted 12 lines
drivers/iio/adc/ad7173.c new file +12 -0
+		iio_device_release_direct_mode(indio_dev);
+		return -EBUSY;
+	}
+
+	switch (info) {
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		freq = val * MILLI + val2 / MILLI;
+
+		for (i = 0; i < st->info->num_sinc5_data_rates - 1; i++) {
+			if (freq >= st->info->sinc5_data_rates[i])
+				break;
+		}

drivers/iio/adc/ad7173.c line 590

Quoted 10 lines
drivers/iio/adc/ad7173.c new file +10 -0
+
+		cfg = &st->channels[chan->address].cfg;
+		cfg->odr = i;
+
+		if (cfg->live) {
+			ret = ad_sd_read_reg(&st->sd, AD7173_REG_FILTER(cfg->cfg_slot), 2, &reg);
+			if (ret)
+				break;
+			reg &= ~AD7173_FILTER_ODR0_MASK;
+			reg |= AD7173_FILTER_ODR0(i);

As mentioned above, I think this is less clear than

			reg &= ~AD7173_FILTER_ODR0_MASK;
			reg |= FIELD_PREP(AD7173_FILTER_ODR0_MASK, i);

as you can then see it's all about the same file specified as a mask.

drivers/iio/adc/ad7173.c line 591

Quoted 1 line
drivers/iio/adc/ad7173.c new file +1 -0
+			ret = ad_sd_write_reg(&st->sd, AD7173_REG_FILTER(cfg->cfg_slot), 2, reg);

Line is very long. If you can keep closer to 80 chars and below that's alway preferred. Maybe flip the logic to exit early if nothing to do..

		if(!cfg->live) /* Nothing to do yet */
			break; 

		ret = ...
Quoted 49 lines
drivers/iio/adc/ad7173.c new file +47 -0
+		}
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	iio_device_release_direct_mode(indio_dev);
+	return ret;
+}
 
 
+static int ad7173_probe(struct spi_device *spi)
+{
+	struct ad7173_state *st;
+	struct iio_dev *indio_dev;
+	struct device *dev = &spi->dev;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	st = iio_priv(indio_dev);
+	st->info = device_get_match_data(dev);
+	if (!st->info)
+		return -ENODEV;
+
+	indio_dev->name = spi_get_device_id(spi)->name;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->info = &ad7173_info;
+
+	spi->mode = SPI_MODE_3;
+
+	ad7173_sigma_delta_info.num_slots = st->info->num_configs;
+	ret = ad_sd_init(&st->sd, indio_dev, spi, &ad7173_sigma_delta_info);
+	if (ret)
+		return ret;
+
+	spi_set_drvdata(spi, indio_dev);
+
+	ret = ad7173_fw_parse_channel_config(indio_dev);
+	if (ret)
+		return ret;
+
+	ret = devm_ad_sd_setup_buffer_and_trigger(dev, indio_dev);
+	if (ret)
+		return ret;
+

drivers/iio/adc/ad7173.c line 810

Quoted 10 lines
drivers/iio/adc/ad7173.c new file +10 -0
+	ret = ad7173_setup(indio_dev);
+	if (ret)
+		return ret;
+
+	ret = devm_iio_device_register(dev, indio_dev);
+	if (ret)
+		return ret;
+
+	if (IS_ENABLED(CONFIG_GPIOLIB))
+		return ad7173_gpio_init(indio_dev);

As nothing to do with IIO part of driver, I'd just pass in st instead so there is no implication that this is IIO related.

drivers/iio/adc/ad7173.c

Quoted 1 line
drivers/iio/adc/ad7173.c new file +1 -0
+	else

Either drop the else (one of the bots will moan about this otherwise) or I'd go for as style more consistent with earlier code.

	if (IS_ENABLED(COHNFIG_GPIOLIB)) {
		ret = ad7173_gpio_init(st); 
		if (ret)
			return ret;
	}
	
	return 0;

	}
Quoted 11 lines
drivers/iio/adc/ad7173.c new file +11 -0
+		return 0;
+}
+
+static const struct of_device_id ad7173_of_match[] = {
+	{ .compatible = "adi,ad7172-2",
+	  .data = &ad7173_device_info[ID_AD7172_2], },
+	{ .compatible = "adi,ad7173-8",
+	  .data = &ad7173_device_info[ID_AD7173_8], },
+	{ .compatible = "adi,ad7175-2",
+	  .data = &ad7173_device_info[ID_AD7175_2], },
+	{ .compatible = "adi,ad7176-2",

drivers/iio/adc/ad7173.c line 832

Quoted 10 lines
drivers/iio/adc/ad7173.c new file +10 -0
+	  .data = &ad7173_device_info[ID_AD7176_2], },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, ad7173_of_match);
+
+static const struct spi_device_id ad7173_id_table[] = {
+	{ "ad7172-2", &ad7173_device_info[ID_AD7172_2], },
+	{ "ad7173-8", &ad7173_device_info[ID_AD7173_8], },
+	{ "ad7175-2", &ad7173_device_info[ID_AD7175_2], },
+	{ "ad7176-2", &ad7173_device_info[ID_AD7176_2], },

Cast to kernel_ulong_t as per the build bot warning you got.

drivers/iio/adc/ad7173.c

Quoted 1 line
drivers/iio/adc/ad7173.c new file +1 -0
+	{ },

trivial, but little point in a comma after an element acting as a list terminator.

Quoted 1 line

+};

#6 lore raw

Re: [PATCH v2 2/2] iio: adc: ad7173: add AD7173 driver

Quoted 8 lines · Jonathan Cameron

On Thu, 28 Sep 2023 15:54:43 +0300
Dumitru Ceclan <[email protected]> wrote>> +config AD7173

drivers/iio/adc/Kconfig config AD7124 · line 61

Quoted 4 lines
drivers/iio/adc/Kconfig +4 -0
+	tristate "Analog Devices AD7173 driver"
+	depends on SPI_MASTER
+	select AD_SIGMA_DELTA
+	select GPIO_REGMAP

If you are selecting it, why does it have if guards in the driver. I prefer the select here, so drop this if guards.

From what i checked, selecting GPIO_REGMAP does not select GPIOLIB but only REGMAP.

Also, in the thread from V1 Arnd Bergmann suggested:
" I think the best way to handle these is to remove both
the 'select' and the #ifdef in the driver and instead use 'if (IS_ENABLED(CONFIG_GPIOLIB))' to handle optional gpio providers in the code. "

#7 lore raw

Re: [PATCH v2 2/2] iio: adc: ad7173: add AD7173 driver

Quoted 10 lines · Ceclan Dumitru-Ioan
Quoted 8 lines · Jonathan Cameron

On Thu, 28 Sep 2023 15:54:43 +0300
Dumitru Ceclan <[email protected]> wrote>> +config AD7173

drivers/iio/adc/Kconfig config AD7124 · line 61

Quoted 4 lines
drivers/iio/adc/Kconfig +4 -0
+	tristate "Analog Devices AD7173 driver"
+	depends on SPI_MASTER
+	select AD_SIGMA_DELTA
+	select GPIO_REGMAP

If you are selecting it, why does it have if guards in the driver. I prefer the select here, so drop this if guards.

Quoted 7 lines

From what i checked, selecting GPIO_REGMAP does not select GPIOLIB but only REGMAP.

Also, in the thread from V1 Arnd Bergmann suggested:
" I think the best way to handle these is to remove both
the 'select' and the #ifdef in the driver and instead use 'if (IS_ENABLED(CONFIG_GPIOLIB))' to handle optional gpio providers in the code. "

Why not simply to be dependent on GPIOLIB like other drivers do in this folder?

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

Re: [PATCH v2 2/2] iio: adc: ad7173: add AD7173 driver

Quoted 23 lines · Andy Shevchenko

Subject:
Re: [PATCH v2 2/2] iio: adc: ad7173: add AD7173 driver From:
Andy Shevchenko <[email protected]>
Date:
10/3/23, 13:45

To:
Ceclan Dumitru-Ioan <[email protected]>
CC:
Jonathan Cameron <[email protected]>, [email protected], [email protected], [email protected], Lars-Peter Clausen <[email protected]>, Rob Herring <[email protected]>, Krzysztof Kozlowski <[email protected]>, Conor Dooley <[email protected]>, Michael Walle <[email protected]>, Arnd Bergmann <[email protected]>, ChiaEn Wu <[email protected]>, Niklas Schnelle <[email protected]>, Leonard Göhrs <[email protected]>, Mike Looijmans <[email protected]>, Haibo Chen <[email protected]>, Hugo Villeneuve <[email protected]>, Ceclan Dumitru <[email protected]>, [email protected], [email protected], [email protected]

Quoted 9 lines · Ceclan Dumitru-Ioan
Quoted 8 lines · Jonathan Cameron

On Thu, 28 Sep 2023 15:54:43 +0300
Dumitru Ceclan <[email protected]> wrote>> +config AD7173

drivers/iio/adc/Kconfig config AD7124 · line 61

Quoted 4 lines
drivers/iio/adc/Kconfig +4 -0
+	tristate "Analog Devices AD7173 driver"
+	depends on SPI_MASTER
+	select AD_SIGMA_DELTA
+	select GPIO_REGMAP

If you are selecting it, why does it have if guards in the driver. I prefer the select here, so drop this if guards.

Quoted 8 lines
Quoted 7 lines

From what i checked, selecting GPIO_REGMAP does not select GPIOLIB but only REGMAP.

Also, in the thread from V1 Arnd Bergmann suggested:
" I think the best way to handle these is to remove both
the 'select' and the #ifdef in the driver and instead use 'if (IS_ENABLED(CONFIG_GPIOLIB))' to handle optional gpio providers in the code. "

Why not simply to be dependent on GPIOLIB like other drivers do in this folder?

I followed the suggestion given by Arnd. The full argument:

"From a Kconfig perspective, any user-visible symbol ideally only uses 'depends on', while hidden symbols usually use 'select'.

For the GPIOLIB symbol specifically, we have a mix of both, but the overall usage is that gpio consumers only use 'depends on', while some of the providers use 'select'. This risks causing build breakage from a dependency loop when combined with other symbols that have the same problem (e.g. I2C), but it tends to work out as long as a strong hierarchy is kept. In particular, using 'select' from an arch/*/Kconfig platform option is generally harmless as long as those don't depend on anything else.

The new driver is a gpio provider and at least ad4130 and ad5592r uses 'select' here, but then again ad74115 and ad74113 use 'depends on' and ads7950 uses neither.

I think the best way to handle these is to remove both the 'select' and the #ifdef in the driver and instead use 'if (IS_ENABLED(CONFIG_GPIOLIB))' to handle optional gpio providers in the code."

I do not have a lot of experience with this subject.
As such, if you consider the argument invalid, mention it and i will change to 'depends on'.

#9 lore raw

Re: [PATCH v2 2/2] iio: adc: ad7173: add AD7173 driver

Quoted 5 lines · Ceclan Dumitru-Ioan
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Ceclan Dumitru-Ioan
Quoted 2 lines · Jonathan Cameron

On Thu, 28 Sep 2023 15:54:43 +0300
Dumitru Ceclan <[email protected]> wrote>> +config AD7173

...

Quoted 30 lines
Quoted 11 lines
Quoted 10 lines
Quoted 3 lines
Quoted 1 line

+ select GPIO_REGMAP

If you are selecting it, why does it have if guards in the driver. I prefer the select here, so drop this if guards.

From what i checked, selecting GPIO_REGMAP does not select GPIOLIB but only REGMAP.

Also, in the thread from V1 Arnd Bergmann suggested:
" I think the best way to handle these is to remove both
the 'select' and the #ifdef in the driver and instead use 'if (IS_ENABLED(CONFIG_GPIOLIB))' to handle optional gpio providers in the code. "

Why not simply to be dependent on GPIOLIB like other drivers do in this folder?

I followed the suggestion given by Arnd. The full argument:

"From a Kconfig perspective, any user-visible symbol ideally only uses 'depends on', while hidden symbols usually use 'select'.

For the GPIOLIB symbol specifically, we have a mix of both, but the overall usage is that gpio consumers only use 'depends on', while some of the providers use 'select'. This risks causing build breakage from a dependency loop when combined with other symbols that have the same problem (e.g. I2C), but it tends to work out as long as a strong hierarchy is kept. In particular, using 'select' from an arch/*/Kconfig platform option is generally harmless as long as those don't depend on anything else.

The new driver is a gpio provider and at least ad4130 and ad5592r uses 'select' here, but then again ad74115 and ad74113 use 'depends on' and ads7950 uses neither.

Quoted 8 lines

I think the best way to handle these is to remove both the 'select' and the #ifdef in the driver and instead use 'if (IS_ENABLED(CONFIG_GPIOLIB))' to handle optional gpio providers in the code."

I do not have a lot of experience with this subject.
As such, if you consider the argument invalid, mention it and i will change to 'depends on'.

I see, I would ask GPIOLIB maintainers about this.
I don't know if there is any plan to fix this through the entire kernel and which way has been chosen for that.

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

Re: [PATCH v2 2/2] iio: adc: ad7173: add AD7173 driver

Quoted 10 lines · Andy Shevchenko
Quoted 8 lines · Ceclan Dumitru-Ioan
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Ceclan Dumitru-Ioan
Quoted 4 lines · Jonathan Cameron
Quoted 2 lines

+ select GPIO_REGMAP

If you are selecting it, why does it have if guards in the driver. I prefer the select here, so drop this if guards.

From what i checked, selecting GPIO_REGMAP does not select GPIOLIB but only REGMAP.

I think the correct solution for this is to use

select GPIO_REGMAP if GPIOLIB

which matches what the driver does.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Also, in the thread from V1 Arnd Bergmann suggested:
" I think the best way to handle these is to remove both
the 'select' and the #ifdef in the driver and instead use 'if (IS_ENABLED(CONFIG_GPIOLIB))' to handle optional gpio providers in the code. "

Why not simply to be dependent on GPIOLIB like other drivers do in this folder?

Some (possibly all) of the other drivers are gpiolib users that do not function without gpiolib. This one is only a provider and not a consumer, and the gpiolib functionality in it is optional, so I think there is technically no dependency, even if in practice gpiolib is always there.

Quoted 23 lines
Quoted 23 lines

I followed the suggestion given by Arnd. The full argument:

"From a Kconfig perspective, any user-visible symbol ideally only uses 'depends on', while hidden symbols usually use 'select'.

For the GPIOLIB symbol specifically, we have a mix of both, but the overall usage is that gpio consumers only use 'depends on', while some of the providers use 'select'. This risks causing build breakage from a dependency loop when combined with other symbols that have the same problem (e.g. I2C), but it tends to work out as long as a strong hierarchy is kept. In particular, using 'select' from an arch/*/Kconfig platform option is generally harmless as long as those don't depend on anything else.

The new driver is a gpio provider and at least ad4130 and ad5592r uses 'select' here, but then again ad74115 and ad74113 use 'depends on' and ads7950 uses neither.

I think the best way to handle these is to remove both the 'select' and the #ifdef in the driver and instead use 'if (IS_ENABLED(CONFIG_GPIOLIB))' to handle optional gpio providers in the code."

Quoted 7 lines
Quoted 3 lines

I do not have a lot of experience with this subject.
As such, if you consider the argument invalid, mention it and i will change to 'depends on'.

I see, I would ask GPIOLIB maintainers about this.
I don't know if there is any plan to fix this through the entire kernel and which way has been chosen for that.

I think the way we have handled it in the past is to not touch existing drivers unless there is a problem with circular dependencies, and then we change a bunch of 'select' to 'depends on' to make it work again.

Changing all the wrong ones at once would be nice, but likely cause introduce other dependency problems, but circular dependencies and incorrect defaults in defconfig builds.

In the long run, we might decide to make gpiolib unconditional all architectures, but for the moment that causes bloat on small memory configurations like most m68k or armv7-m.

Arnd

#11 lore raw

Re: [PATCH v2 2/2] iio: adc: ad7173: add AD7173 driver

In reply to Dumitru Ceclan

Hi,

I've just had a look at the gpio-regmap part.

drivers/iio/adc/ad7173.c line 248

Quoted 7 lines

+static int ad7173_mask_xlate(struct gpio_regmap *gpio, unsigned int base,

drivers/iio/adc/ad7173.c new file +5 -0
+			     unsigned int offset, unsigned int *reg,
+			     unsigned int *mask)
+{
+	*mask = AD7173_GPO_DATA(offset);
+	*reg = AD7173_REG_GPIO;

*reg = base;

See also below.

Quoted 18 lines
drivers/iio/adc/ad7173.c new file +17 -0
+	return 0;
+}
+
+static int ad7173_gpio_init(struct iio_dev *indio_dev)
+{
+	struct ad7173_state *st = iio_priv(indio_dev);
+	struct gpio_regmap_config gpio_regmap = {};
+	struct device *dev = &st->sd.spi->dev;
+	unsigned int mask;
+
+	st->regmap = devm_regmap_init_spi(st->sd.spi, &ad7173_regmap_config);
+	if (IS_ERR(st->regmap)) {
+		return dev_err_probe(dev, PTR_ERR(st->regmap),
+				     "Unable to init regmap\n");
+	}
+
+	mask = AD7173_GPIO_OP_EN0 | AD7173_GPIO_OP_EN1 | 

AD7173_GPIO_OP_EN2_3;

drivers/iio/adc/ad7173.c line 271

Quoted 6 lines
drivers/iio/adc/ad7173.c new file +6 -0
+	regmap_update_bits(st->regmap, AD7173_REG_GPIO, mask, mask);
+
+	gpio_regmap.parent = dev;
+	gpio_regmap.regmap = st->regmap;
+	gpio_regmap.ngpio = st->info->num_gpios;
+	gpio_regmap.reg_set_base = GPIO_REGMAP_ADDR_ZERO;

Why don't you set it to AD7173_REG_GPIO? Register 0 seems wrong, it looks like you're using that to say this is a output-only I/O.

drivers/iio/adc/ad7173.c line 283

Quoted 12 lines
drivers/iio/adc/ad7173.c new file +12 -0
+	gpio_regmap.reg_mask_xlate = ad7173_mask_xlate;
+
+	st->gpio_regmap = devm_gpio_regmap_register(dev, &gpio_regmap);
+	if (IS_ERR(st->gpio_regmap)) {
+		return dev_err_probe(dev, PTR_ERR(st->gpio_regmap),
+				     "Unable to init gpio-regmap\n");
+	}
+
+	return 0;
+}
+
+#endif /* CONFIG_GPIOLIB */

Otherwise looks good. But I've noticed that the chip can actually also do input on gpio0 and gpio1. If you ever want to support that, it seems like you need two gpio-regmaps.

-michael

#12 lore raw

Re: [PATCH v2 2/2] iio: adc: ad7173: add AD7173 driver

In reply to Dumitru Ceclan
kernel test robot noticed the following build warnings:

Hi Dumitru,

kernel test robot noticed the following build warnings:

[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master v6.6-rc4 next-20231004] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Dumitru-Ceclan/iio-adc-ad7173-add-AD7173-driver/20230928-205802
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20230928125443.615006-2-mitrutzceclan%40gmail.com
patch subject: [PATCH v2 2/2] iio: adc: ad7173: add AD7173 driver
config: i386-randconfig-063-20231005 (https://download.01.org/0day-ci/archive/20231005/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231005/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

>> drivers/iio/adc/ad7173.c:829:42: sparse: sparse: incorrect type in initializer (different base types) @@     expected unsigned long [usertype] driver_data @@     got struct ad7173_device_info const * @@

drivers/iio/adc/ad7173.c:829:42: sparse: expected unsigned long [usertype] driver_data
drivers/iio/adc/ad7173.c:829:42: sparse: got struct ad7173_device_info const *
drivers/iio/adc/ad7173.c:830:42: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned long [usertype] driver_data @@ got struct ad7173_device_info const * @@
drivers/iio/adc/ad7173.c:830:42: sparse: expected unsigned long [usertype] driver_data
drivers/iio/adc/ad7173.c:830:42: sparse: got struct ad7173_device_info const *
drivers/iio/adc/ad7173.c:831:42: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned long [usertype] driver_data @@ got struct ad7173_device_info const * @@
drivers/iio/adc/ad7173.c:831:42: sparse: expected unsigned long [usertype] driver_data
drivers/iio/adc/ad7173.c:831:42: sparse: got struct ad7173_device_info const *
drivers/iio/adc/ad7173.c:832:42: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned long [usertype] driver_data @@ got struct ad7173_device_info const * @@
drivers/iio/adc/ad7173.c:832:42: sparse: expected unsigned long [usertype] driver_data
drivers/iio/adc/ad7173.c:832:42: sparse: got struct ad7173_device_info const *

vim +829 drivers/iio/adc/ad7173.c

827
828 static const struct spi_device_id ad7173_id_table[] = {

 > 829		{ "ad7172-2", &ad7173_device_info[ID_AD7172_2], },

830 { "ad7173-8", &ad7173_device_info[ID_AD7173_8], },
831 { "ad7175-2", &ad7173_device_info[ID_AD7175_2], },
832 { "ad7176-2", &ad7173_device_info[ID_AD7176_2], },
833 { },
834 };
835 MODULE_DEVICE_TABLE(spi, ad7173_id_table);
836

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#13 lore raw
In reply to Dumitru Ceclan

Hey,

Quoted 76 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.

---
 .../bindings/iio/adc/adi,ad7173.yaml          | 139 ++++++++++++++++++
 1 file changed, 139 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +58 -0
new file mode 100644
index 000000000000..a0f437297a23
@@ -0,0 +1,139 @@
+# 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 device driver
+
+maintainers:
+  - Ceclan Dumitru <[email protected]>
+
+description: |
+  Bindings for the Analog Devices AD717X ADC's. 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:
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  spi-max-frequency:
+    maximum: 20000000
+
+  spi-cpol:
+    type: boolean
+
+  spi-cpha:
+    type: boolean
+
+  required:
+    - compatible
+    - reg
+    - interrupts
+
+patternProperties:
+  "^channel@[0-9a-f]$":
+    type: object
+    $ref: adc.yaml
+    unevaluatedProperties: false

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

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +10 -0
+
+    properties:
+      reg:
+        description: Channel number
+        minimum: 0
+        maximum: 15
+
+      diff-channels:
+        description:
+          Analog input pins

These descriptions are redundant AFAICT, since youre just constraining properties defined in adc.yaml.

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

Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +7 -0
+        items:
+          minimum: 0
+          maximum: 31
+
+      adi,bipolar:
+        description: Specify if the channel should measure in bipolar mode.
+        type: boolean

You have a ref here to adc.yaml, but do not appear to be making use of "bipolar" property:
bipolar:
$ref: /schemas/types.yaml#/definitions/flag
description: If provided, the channel is to be used in bipolar mode.

Quoted 24 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +24 -0
+
+    required:
+      - reg
+      - diff-channels
+
+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@0 {
+        compatible = "adi,ad7173-8";
+        reg = <0>;
+
+        #address-cells = <1>;

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

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +10 -0
+        #size-cells = <0>;
+
+        interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
+        interrupt-parent = <&gpio>;
+        spi-max-frequency = <5000000>;
+
+        channel@0 {
+          reg = <0>;
+          adi,bipolar;
+

Why the odd newlines?

Mostly looks good to me, cheers,
Conor.

Quoted 33 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml new file +30 -0
+          diff-channels = <0 1>;
+        };
+
+        channel@1 {
+          reg = <1>;
+
+          diff-channels = <2 3>;
+        };
+
+        channel@2 {
+          reg = <2>;
+          adi,bipolar;
+
+          diff-channels = <4 5>;
+        };
+
+        channel@3 {
+          reg = <3>;
+          adi,bipolar;
+
+          diff-channels = <6 7>;
+        };
+
+        channel@4 {
+          reg = <4>;
+
+          diff-channels = <8 9>;
+        };
+      };
+    };
Signature · 1 line
2.39.2