Skip to contentSkip to conversation

Add support for the ad7908/ad7918/ad7928

PATCH Superseded Daniel Junho 3 participants 12 messages Dec 10, 2019 – Dec 16, 2019

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add support for the ad7908/ad7918/ad7928

This patch adds support to AD7928 family on the implementation of the AD7923.

The ad7928 is software compatible with the ad7923.
The ad7908 and ad7918 are the 8 and 10-bit versions of the ad7928.

Change log v1 -> v2
- Split the v1 into 4 commits.
- Removes a buggy line committed unintentionally

Daniel Junho (4):
iio: adc: ad7923: Remove the unused defines
iio: adc: ad7923: Fix checkpatch warning
iio: adc: ad7923: Add of_device_id table
iio: adc: ad7923: Add support for the ad7908/ad7918/ad7928

 drivers/iio/adc/ad7923.c | 78 +++++++++++++++++++++++++++++++---------
 1 file changed, 62 insertions(+), 16 deletions(-)
Signature · 1 line
2.24.0
#1 lore raw

PATCH v2 1/4 iio: adc: ad7923: Remove the unused defines

Removes the unused define AD7923_CHANNEL_x from the code.

---
 drivers/iio/adc/ad7923.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/iio/adc/ad7923.c +0 -4
index 3212eb4c0f25..969c06b7d2b7 100644
@@ -29,10 +29,6 @@
 #define AD7923_PM_MODE_AS	(1)		/* auto shutdown */
 #define AD7923_PM_MODE_FS	(2)		/* full shutdown */
 #define AD7923_PM_MODE_OPS	(3)		/* normal operation */
-#define AD7923_CHANNEL_0	(0)		/* analog input 0 */
-#define AD7923_CHANNEL_1	(1)		/* analog input 1 */
-#define AD7923_CHANNEL_2	(2)		/* analog input 2 */
-#define AD7923_CHANNEL_3	(3)		/* analog input 3 */
 #define AD7923_SEQUENCE_OFF	(0)		/* no sequence fonction */
 #define AD7923_SEQUENCE_PROTECT	(2)		/* no interrupt write cycle */
 #define AD7923_SEQUENCE_ON	(3)		/* continuous sequence */
Signature · 1 line
2.24.0
#2 lore raw

Re: [PATCH v2 1/4] iio: adc: ad7923: Remove the unused defines

Quoted 14 lines · Daniel Junho

[External]

Removes the unused define AD7923_CHANNEL_x from the code.

---
 drivers/iio/adc/ad7923.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/iio/adc/ad7923.c +0 -0
index 3212eb4c0f25..969c06b7d2b7 100644

drivers/iio/adc/ad7923.c line 35

Quoted 7 lines
drivers/iio/adc/ad7923.c +0 -4
@@ -29,10 +29,6 @@
 #define AD7923_PM_MODE_AS	(1)		/* auto shutdown */
 #define AD7923_PM_MODE_FS	(2)		/* full shutdown */
 #define AD7923_PM_MODE_OPS	(3)		/* normal operation */
-#define AD7923_CHANNEL_0	(0)		/* analog input 0 */
-#define AD7923_CHANNEL_1	(1)		/* analog input 1 */
-#define AD7923_CHANNEL_2	(2)		/* analog input 2 */
-#define AD7923_CHANNEL_3	(3)		/* analog input 3 */

The fact that is not used, is not a problem really. This can serve as a "shortcut" for the datasheet.

We can leave this as-is [1], or remove it as you do [2], or an alternative would be [3]:
#define AD7923_CHANNEL(x) (x) /* analog channel input */

I don't mind either of these 3 versions ([1], [2] or [3]).

I'll leave it to Jonathan's preference.

Quoted 5 lines
drivers/iio/adc/ad7923.c +0 -0
 #define AD7923_SEQUENCE_OFF	(0)		/* no sequence fonction
 */
 #define AD7923_SEQUENCE_PROTECT	(2)		/* no interrupt

write cycle */
#define AD7923_SEQUENCE_ON (3) /* continuous sequence */

maintainer
#3 lore raw

Re: [PATCH v2 1/4] iio: adc: ad7923: Remove the unused defines

Quoted 10 lines · Alexandru
Quoted 9 lines · Daniel Junho

[External]

Removes the unused define AD7923_CHANNEL_x from the code.

---
 drivers/iio/adc/ad7923.c | 4 ----
 1 file changed, 4 deletions(-)
Quoted 15 lines

drivers/iio/adc/ad7923.c line 35

Quoted 12 lines
drivers/iio/adc/ad7923.c +0 -4
index 3212eb4c0f25..969c06b7d2b7 100644
@@ -29,10 +29,6 @@
 #define AD7923_PM_MODE_AS	(1)		/* auto shutdown */
 #define AD7923_PM_MODE_FS	(2)		/* full shutdown */
 #define AD7923_PM_MODE_OPS	(3)		/* normal operation */
-#define AD7923_CHANNEL_0	(0)		/* analog input 0 */
-#define AD7923_CHANNEL_1	(1)		/* analog input 1 */
-#define AD7923_CHANNEL_2	(2)		/* analog input 2 */
-#define AD7923_CHANNEL_3	(3)		/* analog input 3 */  

The fact that is not used, is not a problem really. This can serve as a "shortcut" for the datasheet.

In some cases I would agree, but here adding a definition to go from a channel number in text to an actual number doesn't add anything.

If there mapping was more complex then it would be reasonable to have defines, but here I can't see the point.

So let's keep the patch to drop them. I'll pick it up whilst the comments on patch 4 have been addressed.

Thanks,

Jonathan

Quoted 14 lines

We can leave this as-is [1], or remove it as you do [2], or an alternative would be [3]:
#define AD7923_CHANNEL(x) (x) /* analog channel input */

I don't mind either of these 3 versions ([1], [2] or [3]).

I'll leave it to Jonathan's preference.

Quoted 5 lines
drivers/iio/adc/ad7923.c +0 -0
 #define AD7923_SEQUENCE_OFF	(0)		/* no sequence fonction
 */
 #define AD7923_SEQUENCE_PROTECT	(2)		/* no interrupt

write cycle */
#define AD7923_SEQUENCE_ON (3) /* continuous sequence */

#4 lore raw

PATCH v2 2/4 iio: adc: ad7923: Fix checkpatch warning

In reply to Daniel Junho

Fix checkpatch warning:
WARNING: Prefer 'unsigned int' to bare use of 'unsigned' +static int ad7923_scan_direct(struct ad7923_state *st, unsigned ch)

---
 drivers/iio/adc/ad7923.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad7923.c +1 -1
index 969c06b7d2b7..e535cec9fc02 100644
@@ -184,7 +184,7 @@ static irqreturn_t ad7923_trigger_handler(int irq, void *p)
 	return IRQ_HANDLED;
 }
 
-static int ad7923_scan_direct(struct ad7923_state *st, unsigned ch)
+static int ad7923_scan_direct(struct ad7923_state *st, unsigned int ch)
 {
 	int ret, cmd;
 
Signature · 1 line
2.24.0
Reviewed-by on v2 2/4
#5 lore raw

Re: [PATCH v2 2/4] iio: adc: ad7923: Fix checkpatch warning

Quoted 6 lines · Daniel Junho

[External]

Fix checkpatch warning:
WARNING: Prefer 'unsigned int' to bare use of 'unsigned' +static int ad7923_scan_direct(struct ad7923_state *st, unsigned ch)

Quoted 19 lines
---
 drivers/iio/adc/ad7923.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad7923.c +1 -1
index 969c06b7d2b7..e535cec9fc02 100644
@@ -184,7 +184,7 @@ static irqreturn_t ad7923_trigger_handler(int irq,
 void *p)
 	return IRQ_HANDLED;
 }
 
-static int ad7923_scan_direct(struct ad7923_state *st, unsigned ch)
+static int ad7923_scan_direct(struct ad7923_state *st, unsigned int ch)
 {
 	int ret, cmd;
#6 lore raw

PATCH v2 3/4 iio: adc: ad7923: Add of_device_id table

In reply to Daniel Junho

Accomplish device tree compatibility to driver AD7923 by adding of_device_id table and making a subsequent call to MODULE_DEVICE_TABLE.

---
 drivers/iio/adc/ad7923.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/iio/adc/ad7923.c +10 -0
index e535cec9fc02..6d56fa0b9e30 100644
@@ -348,9 +348,19 @@ static const struct spi_device_id ad7923_id[] = {
 };
 MODULE_DEVICE_TABLE(spi, ad7923_id);
 
+static const struct of_device_id ad7923_of_match[] = {
+	{ .compatible = "adi,ad7904", },
+	{ .compatible = "adi,ad7914", },
+	{ .compatible = "adi,ad7923", },
+	{ .compatible = "adi,ad7924", },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, ad7923_of_match);
+
 static struct spi_driver ad7923_driver = {
 	.driver = {
 		.name	= "ad7923",
+		.of_match_table = ad7923_of_match,
 	},
 	.probe		= ad7923_probe,
 	.remove		= ad7923_remove,
Signature · 1 line
2.24.0
Reviewed-by on v2 3/4
#7 lore raw

Re: [PATCH v2 3/4] iio: adc: ad7923: Add of_device_id table

Quoted 6 lines · Daniel Junho

[External]

Accomplish device tree compatibility to driver AD7923 by adding of_device_id table and making a subsequent call to MODULE_DEVICE_TABLE.

Quoted 29 lines
---
 drivers/iio/adc/ad7923.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/iio/adc/ad7923.c +10 -0
index e535cec9fc02..6d56fa0b9e30 100644
@@ -348,9 +348,19 @@ static const struct spi_device_id ad7923_id[] = {
 };
 MODULE_DEVICE_TABLE(spi, ad7923_id);
 
+static const struct of_device_id ad7923_of_match[] = {
+	{ .compatible = "adi,ad7904", },
+	{ .compatible = "adi,ad7914", },
+	{ .compatible = "adi,ad7923", },
+	{ .compatible = "adi,ad7924", },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, ad7923_of_match);
+
 static struct spi_driver ad7923_driver = {
 	.driver = {
 		.name	= "ad7923",
+		.of_match_table = ad7923_of_match,
 	},
 	.probe		= ad7923_probe,
 	.remove		= ad7923_remove,
#8 lore raw

PATCH v2 4/4 iio: adc: ad7923: Add support for the ad7908/ad7918/ad7928

In reply to Daniel Junho

The ad7928 is software compatible with the ad7923.
The ad7908 and ad7918 are the 8 and 10-bit versions of the ad7928.

---
 drivers/iio/adc/ad7923.c | 62 +++++++++++++++++++++++++++++++++-------
 1 file changed, 51 insertions(+), 11 deletions(-)
drivers/iio/adc/ad7923.c +51 -11
index 6d56fa0b9e30..ae807fcaad76 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * AD7904/AD7914/AD7923/AD7924 SPI ADC driver
+ * AD7904/AD7914/AD7923/AD7924/AD7908/AD7918/AD7928 SPI ADC driver
  *
  * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
  * Copyright 2012 CS Systemes d'Information
@@ -29,11 +29,14 @@
 #define AD7923_PM_MODE_AS	(1)		/* auto shutdown */
 #define AD7923_PM_MODE_FS	(2)		/* full shutdown */
 #define AD7923_PM_MODE_OPS	(3)		/* normal operation */
-#define AD7923_SEQUENCE_OFF	(0)		/* no sequence fonction */
-#define AD7923_SEQUENCE_PROTECT	(2)		/* no interrupt write cycle */
-#define AD7923_SEQUENCE_ON	(3)		/* continuous sequence */
 
-#define AD7923_MAX_CHAN		4
+#define AD7923_SEQUENCE_OFF	(0x00)		/* no sequence function */
+#define AD7923_SEQUENCE_SHADOW	(0x01)		/* use the shadow register
+						 * for programming
+						 * (only AD7908/7918/7928)
+						 */
+#define AD7923_SEQUENCE_PROTECT	(0x10)		/* no interrupt write cycle */
+#define AD7923_SEQUENCE_ON	(0x11)		/* continuous sequence */
 
 #define AD7923_PM_MODE_WRITE(mode)	((mode) << 4)	 /* write mode */
 #define AD7923_CHANNEL_WRITE(channel)	((channel) << 6) /* write channel */
@@ -74,6 +77,9 @@ enum ad7923_id {
 	AD7904,
 	AD7914,
 	AD7924,
+	AD7908,
+	AD7918,
+	AD7928
 };
 
 #define AD7923_V_CHAN(index, bits)					\
@@ -93,7 +99,7 @@ enum ad7923_id {
 		},							\
 	}
 
-#define DECLARE_AD7923_CHANNELS(name, bits) \
+#define DECLARE_AD7923_4CHANNELS(name, bits) \
 const struct iio_chan_spec name ## _channels[] = { \
 	AD7923_V_CHAN(0, bits), \
 	AD7923_V_CHAN(1, bits), \
@@ -102,9 +108,25 @@ const struct iio_chan_spec name ## _channels[] = { \
 	IIO_CHAN_SOFT_TIMESTAMP(4), \
 }
 
-static DECLARE_AD7923_CHANNELS(ad7904, 8);
-static DECLARE_AD7923_CHANNELS(ad7914, 10);
-static DECLARE_AD7923_CHANNELS(ad7924, 12);
+#define DECLARE_AD7923_8CHANNELS(name, bits) \
+const struct iio_chan_spec name ## _channels[] = { \
+	AD7923_V_CHAN(0, bits), \
+	AD7923_V_CHAN(1, bits), \
+	AD7923_V_CHAN(2, bits), \
+	AD7923_V_CHAN(3, bits), \
+	AD7923_V_CHAN(4, bits), \
+	AD7923_V_CHAN(5, bits), \
+	AD7923_V_CHAN(6, bits), \
+	AD7923_V_CHAN(7, bits), \
+	IIO_CHAN_SOFT_TIMESTAMP(8), \
+}
+
+static DECLARE_AD7923_4CHANNELS(ad7904, 8);
+static DECLARE_AD7923_4CHANNELS(ad7914, 10);
+static DECLARE_AD7923_4CHANNELS(ad7924, 12);
+static DECLARE_AD7923_8CHANNELS(ad7908, 8);
+static DECLARE_AD7923_8CHANNELS(ad7918, 10);
+static DECLARE_AD7923_8CHANNELS(ad7928, 12);
 
 static const struct ad7923_chip_info ad7923_chip_info[] = {
 	[AD7904] = {
@@ -119,6 +141,18 @@ static const struct ad7923_chip_info ad7923_chip_info[] = {
 		.channels = ad7924_channels,
 		.num_channels = ARRAY_SIZE(ad7924_channels),
 	},
+	[AD7908] = {
+		.channels = ad7908_channels,
+		.num_channels = ARRAY_SIZE(ad7908_channels),
+	},
+	[AD7918] = {
+		.channels = ad7918_channels,
+		.num_channels = ARRAY_SIZE(ad7918_channels),
+	},
+	[AD7928] = {
+		.channels = ad7928_channels,
+		.num_channels = ARRAY_SIZE(ad7928_channels),
+	},
 };
 
 /**
@@ -131,7 +165,7 @@ static int ad7923_update_scan_mode(struct iio_dev *indio_dev,
 	int i, cmd, len;
 
 	len = 0;
-	for_each_set_bit(i, active_scan_mask, AD7923_MAX_CHAN) {
+	for_each_set_bit(i, active_scan_mask, indio_dev->num_channels - 1) {
 		cmd = AD7923_WRITE_CR | AD7923_CHANNEL_WRITE(i) |
 			AD7923_SEQUENCE_WRITE(AD7923_SEQUENCE_OFF) |
 			st->settings;
@@ -344,6 +378,9 @@ static const struct spi_device_id ad7923_id[] = {
 	{"ad7914", AD7914},
 	{"ad7923", AD7924},
 	{"ad7924", AD7924},
+	{"ad7908", AD7908},
+	{"ad7918", AD7918},
+	{"ad7928", AD7928},
 	{}
 };
 MODULE_DEVICE_TABLE(spi, ad7923_id);
@@ -353,6 +390,9 @@ static const struct of_device_id ad7923_of_match[] = {
 	{ .compatible = "adi,ad7914", },
 	{ .compatible = "adi,ad7923", },
 	{ .compatible = "adi,ad7924", },
+	{ .compatible = "adi,ad7908", },
+	{ .compatible = "adi,ad7918", },
+	{ .compatible = "adi,ad7928", },
 	{ },
 };
 MODULE_DEVICE_TABLE(of, ad7923_of_match);
@@ -370,5 +410,5 @@ module_spi_driver(ad7923_driver);
 
 MODULE_AUTHOR("Michael Hennerich <[email protected]>");
 MODULE_AUTHOR("Patrick Vasseur <[email protected]>");
-MODULE_DESCRIPTION("Analog Devices AD7904/AD7914/AD7923/AD7924 ADC");
+MODULE_DESCRIPTION("Analog Devices AD7904/AD7914/AD7923/AD7924/AD7908/AD7918/AD7928 ADC");
 MODULE_LICENSE("GPL v2");
Signature · 1 line
2.24.0
#9 lore raw

Re: [PATCH v2 4/4] iio: adc: ad7923: Add support for the ad7908/ad7918/ad7928

Quoted 5 lines · Daniel Junho

[External]

The ad7928 is software compatible with the ad7923.
The ad7908 and ad7918 are the 8 and 10-bit versions of the ad7928.

The patch looks good.
Comments mostly about namimg.
One about channel numbers.

Quoted 32 lines
---
 drivers/iio/adc/ad7923.c | 62 +++++++++++++++++++++++++++++++++-------
 1 file changed, 51 insertions(+), 11 deletions(-)
drivers/iio/adc/ad7923.c +1 -3
index 6d56fa0b9e30..ae807fcaad76 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * AD7904/AD7914/AD7923/AD7924 SPI ADC driver
+ * AD7904/AD7914/AD7923/AD7924/AD7908/AD7918/AD7928 SPI ADC driver
  *
  * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
  * Copyright 2012 CS Systemes d'Information
@@ -29,11 +29,14 @@
 #define AD7923_PM_MODE_AS	(1)		/* auto shutdown */
 #define AD7923_PM_MODE_FS	(2)		/* full shutdown */
 #define AD7923_PM_MODE_OPS	(3)		/* normal operation */
-#define AD7923_SEQUENCE_OFF	(0)		/* no sequence fonction
 */
-#define AD7923_SEQUENCE_PROTECT	(2)		/* no interrupt

write cycle */

drivers/iio/adc/ad7923.c +1 -2
-#define AD7923_SEQUENCE_ON	(3)		/* continuous sequence */
 
-#define AD7923_MAX_CHAN		4
+#define AD7923_SEQUENCE_OFF	(0x00)		/* no sequence function

*/
+#define AD7923_SEQUENCE_SHADOW (0x01) /* use the shadow
register

drivers/iio/adc/ad7923.c line 36

Quoted 2 lines
drivers/iio/adc/ad7923.c +2 -0
+						 * for programming
+						 * (only AD7908/7918/7928)

[1] Since this reg is only available on these 3 chips, you could rename this to AD7908_SEQUENCE_SHADOW and use it for these 3 chips only. That way, you don't need to mention via comment "(only AD7908/7918/7928)"

Quoted 28 lines
drivers/iio/adc/ad7923.c +2 -0
+						 */
+#define AD7923_SEQUENCE_PROTECT	(0x10)		/* no interrupt

write cycle */
+#define AD7923_SEQUENCE_ON (0x11) /* continuous sequence */

#define AD7923_PM_MODE_WRITE(mode) ((mode) << 4) /* write mode */
#define AD7923_CHANNEL_WRITE(channel) ((channel) << 6) /* write
channel */

drivers/iio/adc/ad7923.c +4 -1
@@ -74,6 +77,9 @@ enum ad7923_id {
 	AD7904,
 	AD7914,
 	AD7924,
+	AD7908,
+	AD7918,
+	AD7928
 };
 
 #define AD7923_V_CHAN(index, bits)					\
@@ -93,7 +99,7 @@ enum ad7923_id {
 		},							\
 	}
 
-#define DECLARE_AD7923_CHANNELS(name, bits) \
+#define DECLARE_AD7923_4CHANNELS(name, bits) \
 const struct iio_chan_spec name ## _channels[] = { \
 	AD7923_V_CHAN(0, bits), \
 	AD7923_V_CHAN(1, bits), \

drivers/iio/adc/ad7923.c const struct iio_chan_spec name ## _channels[] = { \ · line 111

Quoted 7 lines
drivers/iio/adc/ad7923.c +1 -3
@@ -102,9 +108,25 @@ const struct iio_chan_spec name ## _channels[] = { \
 	IIO_CHAN_SOFT_TIMESTAMP(4), \
 }
 
-static DECLARE_AD7923_CHANNELS(ad7904, 8);
-static DECLARE_AD7923_CHANNELS(ad7914, 10);
-static DECLARE_AD7923_CHANNELS(ad7924, 12);
+#define DECLARE_AD7923_8CHANNELS(name, bits) \

Same comments as [1], you could leave DECLARE_AD7923_CHANNELS and declare DECLARE_AD7908_CHANNELS which has 8 channels and use for the 3 new chips.

Quoted 42 lines
drivers/iio/adc/ad7923.c +30 -0
+const struct iio_chan_spec name ## _channels[] = { \
+	AD7923_V_CHAN(0, bits), \
+	AD7923_V_CHAN(1, bits), \
+	AD7923_V_CHAN(2, bits), \
+	AD7923_V_CHAN(3, bits), \
+	AD7923_V_CHAN(4, bits), \
+	AD7923_V_CHAN(5, bits), \
+	AD7923_V_CHAN(6, bits), \
+	AD7923_V_CHAN(7, bits), \
+	IIO_CHAN_SOFT_TIMESTAMP(8), \
+}
+
+static DECLARE_AD7923_4CHANNELS(ad7904, 8);
+static DECLARE_AD7923_4CHANNELS(ad7914, 10);
+static DECLARE_AD7923_4CHANNELS(ad7924, 12);
+static DECLARE_AD7923_8CHANNELS(ad7908, 8);
+static DECLARE_AD7923_8CHANNELS(ad7918, 10);
+static DECLARE_AD7923_8CHANNELS(ad7928, 12);
 
 static const struct ad7923_chip_info ad7923_chip_info[] = {
 	[AD7904] = {
@@ -119,6 +141,18 @@ static const struct ad7923_chip_info
 ad7923_chip_info[] = {
 		.channels = ad7924_channels,
 		.num_channels = ARRAY_SIZE(ad7924_channels),
 	},
+	[AD7908] = {
+		.channels = ad7908_channels,
+		.num_channels = ARRAY_SIZE(ad7908_channels),
+	},
+	[AD7918] = {
+		.channels = ad7918_channels,
+		.num_channels = ARRAY_SIZE(ad7918_channels),
+	},
+	[AD7928] = {
+		.channels = ad7928_channels,
+		.num_channels = ARRAY_SIZE(ad7928_channels),
+	},
 };
 

/**

drivers/iio/adc/ad7923.c static int ad7923_update_scan_mode(struct iio_dev · line 169

Quoted 6 lines
drivers/iio/adc/ad7923.c +1 -1
@@ -131,7 +165,7 @@ static int ad7923_update_scan_mode(struct iio_dev
 *indio_dev,
 	int i, cmd, len;
 
 	len = 0;
-	for_each_set_bit(i, active_scan_mask, AD7923_MAX_CHAN) {
+	for_each_set_bit(i, active_scan_mask, indio_dev->num_channels - 1) 

I got the idea about 'indio_dev->num_channel - 1'.
This makes the assumption that the number of IIO channels is always HW- channels + 1 timestamp channel [which for now is true].
I'm not sure if this is ok.

I think Jonathan would be a bit better here to comment.

Quoted 26 lines
drivers/iio/adc/ad7923.c +0 -0
 {
 		cmd = AD7923_WRITE_CR | AD7923_CHANNEL_WRITE(i) |
drivers/iio/adc/ad7923.c +6 -0
 			AD7923_SEQUENCE_WRITE(AD7923_SEQUENCE_OFF) |
 			st->settings;
@@ -344,6 +378,9 @@ static const struct spi_device_id ad7923_id[] = {
 	{"ad7914", AD7914},
 	{"ad7923", AD7924},
 	{"ad7924", AD7924},
+	{"ad7908", AD7908},
+	{"ad7918", AD7918},
+	{"ad7928", AD7928},
 	{}
 };
 MODULE_DEVICE_TABLE(spi, ad7923_id);
@@ -353,6 +390,9 @@ static const struct of_device_id ad7923_of_match[] =
 {
 	{ .compatible = "adi,ad7914", },
 	{ .compatible = "adi,ad7923", },
 	{ .compatible = "adi,ad7924", },
+	{ .compatible = "adi,ad7908", },
+	{ .compatible = "adi,ad7918", },
+	{ .compatible = "adi,ad7928", },
 	{ },
 };

MODULE_DEVICE_TABLE(of, ad7923_of_match);

drivers/iio/adc/ad7923.c module_spi_driver(ad7923_driver); · line 414

Quoted 6 lines
drivers/iio/adc/ad7923.c +1 -1
@@ -370,5 +410,5 @@ module_spi_driver(ad7923_driver);
 
 MODULE_AUTHOR("Michael Hennerich <[email protected]>");
 MODULE_AUTHOR("Patrick Vasseur <[email protected]>");
-MODULE_DESCRIPTION("Analog Devices AD7904/AD7914/AD7923/AD7924 ADC");
+MODULE_DESCRIPTION("Analog Devices
 AD7904/AD7914/AD7923/AD7924/AD7908/AD7918/AD7928 ADC");

This description is becoming long.
Maybe simplify to
MODULE_DESCRIPTION("Analog Devices AD7923 and similar ADC");

Quoted 1 line

MODULE_LICENSE("GPL v2");

maintainer
#10 lore raw

Re: [PATCH v2 4/4] iio: adc: ad7923: Add support for the ad7908/ad7918/ad7928

Quoted 146 lines · Alexandru
Quoted 5 lines · Daniel Junho

[External]

The ad7928 is software compatible with the ad7923.
The ad7908 and ad7918 are the 8 and 10-bit versions of the ad7928.

The patch looks good.
Comments mostly about namimg.
One about channel numbers.

Quoted 32 lines
---
 drivers/iio/adc/ad7923.c | 62 +++++++++++++++++++++++++++++++++-------
 1 file changed, 51 insertions(+), 11 deletions(-)
drivers/iio/adc/ad7923.c +1 -3
index 6d56fa0b9e30..ae807fcaad76 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * AD7904/AD7914/AD7923/AD7924 SPI ADC driver
+ * AD7904/AD7914/AD7923/AD7924/AD7908/AD7918/AD7928 SPI ADC driver
  *
  * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
  * Copyright 2012 CS Systemes d'Information
@@ -29,11 +29,14 @@
 #define AD7923_PM_MODE_AS	(1)		/* auto shutdown */
 #define AD7923_PM_MODE_FS	(2)		/* full shutdown */
 #define AD7923_PM_MODE_OPS	(3)		/* normal operation */
-#define AD7923_SEQUENCE_OFF	(0)		/* no sequence fonction
 */
-#define AD7923_SEQUENCE_PROTECT	(2)		/* no interrupt

write cycle */

drivers/iio/adc/ad7923.c +1 -2
-#define AD7923_SEQUENCE_ON	(3)		/* continuous sequence */
 
-#define AD7923_MAX_CHAN		4
+#define AD7923_SEQUENCE_OFF	(0x00)		/* no sequence function

*/
+#define AD7923_SEQUENCE_SHADOW (0x01) /* use the shadow
register

drivers/iio/adc/ad7923.c line 36

Quoted 2 lines
drivers/iio/adc/ad7923.c +2 -0
+						 * for programming
+						 * (only AD7908/7918/7928)  

[1] Since this reg is only available on these 3 chips, you could rename this to AD7908_SEQUENCE_SHADOW and use it for these 3 chips only. That way, you don't need to mention via comment "(only AD7908/7918/7928)"

Quoted 28 lines
drivers/iio/adc/ad7923.c +2 -0
+						 */
+#define AD7923_SEQUENCE_PROTECT	(0x10)		/* no interrupt

write cycle */
+#define AD7923_SEQUENCE_ON (0x11) /* continuous sequence */

#define AD7923_PM_MODE_WRITE(mode) ((mode) << 4) /* write mode */
#define AD7923_CHANNEL_WRITE(channel) ((channel) << 6) /* write
channel */

drivers/iio/adc/ad7923.c +4 -1
@@ -74,6 +77,9 @@ enum ad7923_id {
 	AD7904,
 	AD7914,
 	AD7924,
+	AD7908,
+	AD7918,
+	AD7928
 };
 
 #define AD7923_V_CHAN(index, bits)					\
@@ -93,7 +99,7 @@ enum ad7923_id {
 		},							\
 	}
 
-#define DECLARE_AD7923_CHANNELS(name, bits) \
+#define DECLARE_AD7923_4CHANNELS(name, bits) \
 const struct iio_chan_spec name ## _channels[] = { \
 	AD7923_V_CHAN(0, bits), \
 	AD7923_V_CHAN(1, bits), \

drivers/iio/adc/ad7923.c const struct iio_chan_spec name ## _channels[] = { \ · line 111

Quoted 7 lines
drivers/iio/adc/ad7923.c +1 -3
@@ -102,9 +108,25 @@ const struct iio_chan_spec name ## _channels[] = { \
 	IIO_CHAN_SOFT_TIMESTAMP(4), \
 }
 
-static DECLARE_AD7923_CHANNELS(ad7904, 8);
-static DECLARE_AD7923_CHANNELS(ad7914, 10);
-static DECLARE_AD7923_CHANNELS(ad7924, 12);
+#define DECLARE_AD7923_8CHANNELS(name, bits) \  

Same comments as [1], you could leave DECLARE_AD7923_CHANNELS and declare DECLARE_AD7908_CHANNELS which has 8 channels and use for the 3 new chips.

Quoted 42 lines
drivers/iio/adc/ad7923.c +30 -0
+const struct iio_chan_spec name ## _channels[] = { \
+	AD7923_V_CHAN(0, bits), \
+	AD7923_V_CHAN(1, bits), \
+	AD7923_V_CHAN(2, bits), \
+	AD7923_V_CHAN(3, bits), \
+	AD7923_V_CHAN(4, bits), \
+	AD7923_V_CHAN(5, bits), \
+	AD7923_V_CHAN(6, bits), \
+	AD7923_V_CHAN(7, bits), \
+	IIO_CHAN_SOFT_TIMESTAMP(8), \
+}
+
+static DECLARE_AD7923_4CHANNELS(ad7904, 8);
+static DECLARE_AD7923_4CHANNELS(ad7914, 10);
+static DECLARE_AD7923_4CHANNELS(ad7924, 12);
+static DECLARE_AD7923_8CHANNELS(ad7908, 8);
+static DECLARE_AD7923_8CHANNELS(ad7918, 10);
+static DECLARE_AD7923_8CHANNELS(ad7928, 12);
 
 static const struct ad7923_chip_info ad7923_chip_info[] = {
 	[AD7904] = {
@@ -119,6 +141,18 @@ static const struct ad7923_chip_info
 ad7923_chip_info[] = {
 		.channels = ad7924_channels,
 		.num_channels = ARRAY_SIZE(ad7924_channels),
 	},
+	[AD7908] = {
+		.channels = ad7908_channels,
+		.num_channels = ARRAY_SIZE(ad7908_channels),
+	},
+	[AD7918] = {
+		.channels = ad7918_channels,
+		.num_channels = ARRAY_SIZE(ad7918_channels),
+	},
+	[AD7928] = {
+		.channels = ad7928_channels,
+		.num_channels = ARRAY_SIZE(ad7928_channels),
+	},
 };
 

/**

drivers/iio/adc/ad7923.c static int ad7923_update_scan_mode(struct iio_dev · line 169

Quoted 6 lines
drivers/iio/adc/ad7923.c +1 -1
@@ -131,7 +165,7 @@ static int ad7923_update_scan_mode(struct iio_dev
 *indio_dev,
 	int i, cmd, len;
 
 	len = 0;
-	for_each_set_bit(i, active_scan_mask, AD7923_MAX_CHAN) {
+	for_each_set_bit(i, active_scan_mask, indio_dev->num_channels - 1)   

I got the idea about 'indio_dev->num_channel - 1'.
This makes the assumption that the number of IIO channels is always HW- channels + 1 timestamp channel [which for now is true].
I'm not sure if this is ok.

Quoted 1 line

I think Jonathan would be a bit better here to comment.

It is a driver specific assumption so we don't need it to be true in general. Perhaps add a comment along the lines of
/*
* For this driver the last channel is always the software timestamp so
* skip that one.
*/

Quoted 39 lines
Quoted 27 lines
drivers/iio/adc/ad7923.c +0 -0
 {
 		cmd = AD7923_WRITE_CR | AD7923_CHANNEL_WRITE(i) |
drivers/iio/adc/ad7923.c +6 -0
 			AD7923_SEQUENCE_WRITE(AD7923_SEQUENCE_OFF) |
 			st->settings;
@@ -344,6 +378,9 @@ static const struct spi_device_id ad7923_id[] = {
 	{"ad7914", AD7914},
 	{"ad7923", AD7924},
 	{"ad7924", AD7924},
+	{"ad7908", AD7908},
+	{"ad7918", AD7918},
+	{"ad7928", AD7928},
 	{}
 };
 MODULE_DEVICE_TABLE(spi, ad7923_id);
@@ -353,6 +390,9 @@ static const struct of_device_id ad7923_of_match[] =
 {
 	{ .compatible = "adi,ad7914", },
 	{ .compatible = "adi,ad7923", },
 	{ .compatible = "adi,ad7924", },
+	{ .compatible = "adi,ad7908", },
+	{ .compatible = "adi,ad7918", },
+	{ .compatible = "adi,ad7928", },
 	{ },
 };

MODULE_DEVICE_TABLE(of, ad7923_of_match);

drivers/iio/adc/ad7923.c module_spi_driver(ad7923_driver); · line 414

Quoted 6 lines
drivers/iio/adc/ad7923.c +1 -1
@@ -370,5 +410,5 @@ module_spi_driver(ad7923_driver);
 
 MODULE_AUTHOR("Michael Hennerich <[email protected]>");
 MODULE_AUTHOR("Patrick Vasseur <[email protected]>");
-MODULE_DESCRIPTION("Analog Devices AD7904/AD7914/AD7923/AD7924 ADC");
+MODULE_DESCRIPTION("Analog Devices
 AD7904/AD7914/AD7923/AD7924/AD7908/AD7918/AD7928 ADC");  

This description is becoming long.
Maybe simplify to
MODULE_DESCRIPTION("Analog Devices AD7923 and similar ADC");

Quoted 1 line

MODULE_LICENSE("GPL v2");

#11 lore raw

Re: [PATCH v2 4/4] iio: adc: ad7923: Add support for the ad7908/ad7918/ad7928

Quoted 150 lines · Jonathan Cameron
Quoted 146 lines · Alexandru
Quoted 5 lines · Daniel Junho

[External]

The ad7928 is software compatible with the ad7923.
The ad7908 and ad7918 are the 8 and 10-bit versions of the ad7928.

The patch looks good.
Comments mostly about namimg.
One about channel numbers.

Quoted 32 lines
---
 drivers/iio/adc/ad7923.c | 62 +++++++++++++++++++++++++++++++++-------
 1 file changed, 51 insertions(+), 11 deletions(-)
drivers/iio/adc/ad7923.c +1 -3
index 6d56fa0b9e30..ae807fcaad76 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * AD7904/AD7914/AD7923/AD7924 SPI ADC driver
+ * AD7904/AD7914/AD7923/AD7924/AD7908/AD7918/AD7928 SPI ADC driver
  *
  * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
  * Copyright 2012 CS Systemes d'Information
@@ -29,11 +29,14 @@
 #define AD7923_PM_MODE_AS  (1)             /* auto shutdown */
 #define AD7923_PM_MODE_FS  (2)             /* full shutdown */
 #define AD7923_PM_MODE_OPS (3)             /* normal operation */
-#define AD7923_SEQUENCE_OFF        (0)             /* no sequence fonction
 */
-#define AD7923_SEQUENCE_PROTECT    (2)             /* no interrupt

write cycle */

drivers/iio/adc/ad7923.c +1 -2
-#define AD7923_SEQUENCE_ON (3)             /* continuous sequence */
 
-#define AD7923_MAX_CHAN            4
+#define AD7923_SEQUENCE_OFF        (0x00)          /* no sequence function

*/
+#define AD7923_SEQUENCE_SHADOW (0x01) /* use the shadow
register

drivers/iio/adc/ad7923.c line 36

Quoted 2 lines
drivers/iio/adc/ad7923.c +2 -0
+                                            * for programming
+                                            * (only AD7908/7918/7928)

[1] Since this reg is only available on these 3 chips, you could rename this to AD7908_SEQUENCE_SHADOW and use it for these 3 chips only. That way, you don't need to mention via comment "(only AD7908/7918/7928)"

Quoted 28 lines
drivers/iio/adc/ad7923.c +2 -0
+                                            */
+#define AD7923_SEQUENCE_PROTECT    (0x10)          /* no interrupt

write cycle */
+#define AD7923_SEQUENCE_ON (0x11) /* continuous sequence */

#define AD7923_PM_MODE_WRITE(mode) ((mode) << 4) /* write mode */
#define AD7923_CHANNEL_WRITE(channel) ((channel) << 6) /* write
channel */

drivers/iio/adc/ad7923.c +4 -1
@@ -74,6 +77,9 @@ enum ad7923_id {
    AD7904,
    AD7914,
    AD7924,
+   AD7908,
+   AD7918,
+   AD7928
 };
 
 #define AD7923_V_CHAN(index, bits)                                 \
@@ -93,7 +99,7 @@ enum ad7923_id {
            },                                                      \
    }
 
-#define DECLARE_AD7923_CHANNELS(name, bits) \
+#define DECLARE_AD7923_4CHANNELS(name, bits) \
 const struct iio_chan_spec name ## _channels[] = { \
    AD7923_V_CHAN(0, bits), \
    AD7923_V_CHAN(1, bits), \

drivers/iio/adc/ad7923.c const struct iio_chan_spec name ## _channels[] = { \ · line 111

Quoted 7 lines
drivers/iio/adc/ad7923.c +1 -3
@@ -102,9 +108,25 @@ const struct iio_chan_spec name ## _channels[] = { \
    IIO_CHAN_SOFT_TIMESTAMP(4), \
 }
 
-static DECLARE_AD7923_CHANNELS(ad7904, 8);
-static DECLARE_AD7923_CHANNELS(ad7914, 10);
-static DECLARE_AD7923_CHANNELS(ad7924, 12);
+#define DECLARE_AD7923_8CHANNELS(name, bits) \

Same comments as [1], you could leave DECLARE_AD7923_CHANNELS and declare DECLARE_AD7908_CHANNELS which has 8 channels and use for the 3 new chips.

Quoted 42 lines
drivers/iio/adc/ad7923.c +30 -0
+const struct iio_chan_spec name ## _channels[] = { \
+   AD7923_V_CHAN(0, bits), \
+   AD7923_V_CHAN(1, bits), \
+   AD7923_V_CHAN(2, bits), \
+   AD7923_V_CHAN(3, bits), \
+   AD7923_V_CHAN(4, bits), \
+   AD7923_V_CHAN(5, bits), \
+   AD7923_V_CHAN(6, bits), \
+   AD7923_V_CHAN(7, bits), \
+   IIO_CHAN_SOFT_TIMESTAMP(8), \
+}
+
+static DECLARE_AD7923_4CHANNELS(ad7904, 8);
+static DECLARE_AD7923_4CHANNELS(ad7914, 10);
+static DECLARE_AD7923_4CHANNELS(ad7924, 12);
+static DECLARE_AD7923_8CHANNELS(ad7908, 8);
+static DECLARE_AD7923_8CHANNELS(ad7918, 10);
+static DECLARE_AD7923_8CHANNELS(ad7928, 12);
 
 static const struct ad7923_chip_info ad7923_chip_info[] = {
    [AD7904] = {
@@ -119,6 +141,18 @@ static const struct ad7923_chip_info
 ad7923_chip_info[] = {
            .channels = ad7924_channels,
            .num_channels = ARRAY_SIZE(ad7924_channels),
    },
+   [AD7908] = {
+           .channels = ad7908_channels,
+           .num_channels = ARRAY_SIZE(ad7908_channels),
+   },
+   [AD7918] = {
+           .channels = ad7918_channels,
+           .num_channels = ARRAY_SIZE(ad7918_channels),
+   },
+   [AD7928] = {
+           .channels = ad7928_channels,
+           .num_channels = ARRAY_SIZE(ad7928_channels),
+   },
 };
 

/**

drivers/iio/adc/ad7923.c static int ad7923_update_scan_mode(struct iio_dev · line 169

Quoted 6 lines
drivers/iio/adc/ad7923.c +1 -1
@@ -131,7 +165,7 @@ static int ad7923_update_scan_mode(struct iio_dev
 *indio_dev,
    int i, cmd, len;
 
    len = 0;
-   for_each_set_bit(i, active_scan_mask, AD7923_MAX_CHAN) {
+   for_each_set_bit(i, active_scan_mask, indio_dev->num_channels - 1)

I got the idea about 'indio_dev->num_channel - 1'.
This makes the assumption that the number of IIO channels is always HW- channels + 1 timestamp channel [which for now is true].
I'm not sure if this is ok.

Quoted 9 lines
Quoted 1 line

I think Jonathan would be a bit better here to comment.

It is a driver specific assumption so we don't need it to be true in general. Perhaps add a comment along the lines of
/*
* For this driver the last channel is always the software timestamp so
* skip that one.
*/

Ok. I will add this comment to the code and send a v3.

Thank you all.

Quoted 41 lines
Quoted 40 lines
Quoted 28 lines
drivers/iio/adc/ad7923.c +0 -0
 {
            cmd = AD7923_WRITE_CR | AD7923_CHANNEL_WRITE(i) |
                    AD7923_SEQUENCE_WRITE(AD7923_SEQUENCE_OFF) |
                    st->settings;
drivers/iio/adc/ad7923.c +6 -0
@@ -344,6 +378,9 @@ static const struct spi_device_id ad7923_id[] = {
    {"ad7914", AD7914},
    {"ad7923", AD7924},
    {"ad7924", AD7924},
+   {"ad7908", AD7908},
+   {"ad7918", AD7918},
+   {"ad7928", AD7928},
    {}
 };
 MODULE_DEVICE_TABLE(spi, ad7923_id);
@@ -353,6 +390,9 @@ static const struct of_device_id ad7923_of_match[] =
 {
    { .compatible = "adi,ad7914", },
    { .compatible = "adi,ad7923", },
    { .compatible = "adi,ad7924", },
+   { .compatible = "adi,ad7908", },
+   { .compatible = "adi,ad7918", },
+   { .compatible = "adi,ad7928", },
    { },
 };

MODULE_DEVICE_TABLE(of, ad7923_of_match);

drivers/iio/adc/ad7923.c module_spi_driver(ad7923_driver); · line 414

Quoted 6 lines
drivers/iio/adc/ad7923.c +1 -1
@@ -370,5 +410,5 @@ module_spi_driver(ad7923_driver);
 
 MODULE_AUTHOR("Michael Hennerich <[email protected]>");
 MODULE_AUTHOR("Patrick Vasseur <[email protected]>");
-MODULE_DESCRIPTION("Analog Devices AD7904/AD7914/AD7923/AD7924 ADC");
+MODULE_DESCRIPTION("Analog Devices
 AD7904/AD7914/AD7923/AD7924/AD7908/AD7918/AD7928 ADC");

This description is becoming long.
Maybe simplify to
MODULE_DESCRIPTION("Analog Devices AD7923 and similar ADC");

Quoted 1 line

MODULE_LICENSE("GPL v2");