Skip to contentSkip to conversation

iio: potentiometer: Add support for DS3502

PATCH Superseded Jagath Jog J 4 participants 13 messages Feb 14, 2022 – Feb 18, 2022

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover iio: potentiometer: Add support for DS3502

Add dt-bindings and support for Maxim DS3502 into existing ds1803 driver. DS3502 is a 7 bit Nonvolatile Digital Potentiometer.

Changes since v1:
1. Fixes the alignment to match the open parenthesis in separate patch
2. Adding available functionality for ds1803 driver in separate patch
3. Moving maxim_potentiometer members into ds1803_cfg structure
4. Droping of the INFO_ENABLE channel type
5. Firmware entry with data is used instead of id->driver_data to to retrieve the chip specific data.

Jagath Jog J (4):
iio: potentiometer: Alignment to match the open parenthesis
iio: potentiometer: Add available functionality
iio: potentiometer: Add support for Maxim DS3502
dt-bindings: iio: potentiometer: Add Maxim DS3502 in trivial-devices

 .../devicetree/bindings/trivial-devices.yaml  |   2 +
 drivers/iio/potentiometer/Kconfig             |   6 +-
 drivers/iio/potentiometer/ds1803.c            | 141 +++++++++++++-----
 3 files changed, 106 insertions(+), 43 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/4 iio: potentiometer: Alignment to match the open parenthesis

Fix following checkpatch.pl check by removing black space
CHECK: Alignment should match open parenthesis

---
 drivers/iio/potentiometer/ds1803.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/iio/potentiometer/ds1803.c +6 -6
index 20b45407eaac..3481dd460525 100644
@@ -55,8 +55,8 @@ static const struct iio_chan_spec ds1803_channels[] = {
 };
 
 static int ds1803_read_raw(struct iio_dev *indio_dev,
-			    struct iio_chan_spec const *chan,
-			    int *val, int *val2, long mask)
+			   struct iio_chan_spec const *chan,
+			   int *val, int *val2, long mask)
 {
 	struct ds1803_data *data = iio_priv(indio_dev);
 	int pot = chan->channel;
@@ -66,7 +66,7 @@ static int ds1803_read_raw(struct iio_dev *indio_dev,
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
 		ret = i2c_master_recv(data->client, result,
-				indio_dev->num_channels);
+				      indio_dev->num_channels);
 		if (ret < 0)
 			return ret;
 
@@ -83,8 +83,8 @@ static int ds1803_read_raw(struct iio_dev *indio_dev,
 }
 
 static int ds1803_write_raw(struct iio_dev *indio_dev,
-			     struct iio_chan_spec const *chan,
-			     int val, int val2, long mask)
+			    struct iio_chan_spec const *chan,
+			    int val, int val2, long mask)
 {
 	struct ds1803_data *data = iio_priv(indio_dev);
 	int pot = chan->channel;
@@ -110,7 +110,7 @@ static const struct iio_info ds1803_info = {
 };
 
 static int ds1803_probe(struct i2c_client *client,
-			 const struct i2c_device_id *id)
+			const struct i2c_device_id *id)
 {
 	struct device *dev = &client->dev;
 	struct ds1803_data *data;
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v2 1/4] iio: potentiometer: Alignment to match the open parenthesis

Quoted 3 lines · Jagath Jog J

Fix following checkpatch.pl check by removing black space
CHECK: Alignment should match open parenthesis

I believe in some cases you may make them more compact, like join lines (it will be slightly longer, but still readable). OTOH, it depends on the style of the entire driver.

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

PATCH v2 2/4 iio: potentiometer: Add available functionality

In reply to Jagath Jog J

Adding available functionality for ds1803 driver which will show the minimum, step and maximum values it can accepts through sysfs entry.

---
 drivers/iio/potentiometer/ds1803.c | 38 ++++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 10 deletions(-)
drivers/iio/potentiometer/ds1803.c +28 -10
index 3481dd460525..bccb9ccac931 100644
@@ -27,12 +27,13 @@ enum ds1803_type {
 
 struct ds1803_cfg {
 	int kohms;
+	int avail[3];
 };
 
 static const struct ds1803_cfg ds1803_cfg[] = {
-	[DS1803_010] = { .kohms =  10, },
-	[DS1803_050] = { .kohms =  50, },
-	[DS1803_100] = { .kohms = 100, },
+	[DS1803_010] = { .avail = { 0, 1, 255 }, .kohms =  10, },
+	[DS1803_050] = { .avail = { 0, 1, 255 }, .kohms =  50, },
+	[DS1803_100] = { .avail = { 0, 1, 255 }, .kohms = 100, },
 };
 
 struct ds1803_data {
@@ -40,13 +41,14 @@ struct ds1803_data {
 	const struct ds1803_cfg *cfg;
 };
 
-#define DS1803_CHANNEL(ch) {					\
-	.type = IIO_RESISTANCE,					\
-	.indexed = 1,						\
-	.output = 1,						\
-	.channel = (ch),					\
-	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),		\
-	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),	\
+#define DS1803_CHANNEL(ch) {						\
+	.type = IIO_RESISTANCE,						\
+	.indexed = 1,							\
+	.output = 1,							\
+	.channel = (ch),						\
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),			\
+	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),		\
+	.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_RAW),   \
 }
 
 static const struct iio_chan_spec ds1803_channels[] = {
@@ -104,9 +106,25 @@ static int ds1803_write_raw(struct iio_dev *indio_dev,
 	return i2c_smbus_write_byte_data(data->client, DS1803_WRITE(pot), val);
 }
 
+static int ds1803_read_avail(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
+			     const int **vals, int *type, int *length, long mask)
+{
+	struct ds1803_data *data = iio_priv(indio_dev);
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		*vals = data->cfg->avail;
+		*length = ARRAY_SIZE(data->cfg->avail);
+		*type = IIO_VAL_INT;
+		return IIO_AVAIL_RANGE;
+	}
+	return -EINVAL;
+}
+
 static const struct iio_info ds1803_info = {
 	.read_raw = ds1803_read_raw,
 	.write_raw = ds1803_write_raw,
+	.read_avail = ds1803_read_avail,
 };
 
 static int ds1803_probe(struct i2c_client *client,
Signature · 1 line
2.17.1
#4 lore raw

Re: [PATCH v2 2/4] iio: potentiometer: Add available functionality

Quoted 4 lines · Jagath Jog J

Adding available functionality for ds1803 driver which will show the minimum, step and maximum values it can accepts through sysfs entry.

accept

...

drivers/iio/potentiometer/ds1803.c enum ds1803_type { · line 37

Quoted 13 lines
 struct ds1803_cfg {
        int kohms;
drivers/iio/potentiometer/ds1803.c +4 -3
+       int avail[3];
 };
 
 static const struct ds1803_cfg ds1803_cfg[] = {
-       [DS1803_010] = { .kohms =  10, },
-       [DS1803_050] = { .kohms =  50, },
-       [DS1803_100] = { .kohms = 100, },
+       [DS1803_010] = { .avail = { 0, 1, 255 }, .kohms =  10, },
+       [DS1803_050] = { .avail = { 0, 1, 255 }, .kohms =  50, },
+       [DS1803_100] = { .avail = { 0, 1, 255 }, .kohms = 100, },
 };

Please, do it rather with additional data:

static const int ds1803_range[] = { ... };

.avail = ..._range,

Also, looking into the next patch, can you move the structure to the place where it's more appropriate?

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

PATCH v2 3/4 iio: potentiometer: Add support for Maxim DS3502

In reply to Jagath Jog J

The DS3502 is a 7-bit, nonvolatile digital potentiometer featuring an output voltage range of up to 15.5V.
DS3502 support is implemented into existing ds1803 driver

Datasheet: https://datasheets.maximintegrated.com/en/ds/DS3502.pdf

---
 drivers/iio/potentiometer/Kconfig  |   6 +-
 drivers/iio/potentiometer/ds1803.c | 101 ++++++++++++++++++++---------
 2 files changed, 75 insertions(+), 32 deletions(-)
drivers/iio/potentiometer/Kconfig +3 -3
index 832df8da2bc6..cd9aaceb15fe 100644
@@ -27,11 +27,11 @@ config AD5272
 	  module will be called ad5272.
 
 config DS1803
-	tristate "Maxim Integrated DS1803 Digital Potentiometer driver"
+	tristate "Maxim Integrated DS1803 and similar Digital Potentiometer driver"
 	depends on I2C
 	help
-	  Say yes here to build support for the Maxim Integrated DS1803
-	  digital potentiometer chip.
+	  Say yes here to build support for the Maxim Integrated DS1803 and
+	  similar digital potentiometer chip.
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called ds1803.
drivers/iio/potentiometer/ds1803.c +72 -29

197 lines not on this page · raw message

Signature · 1 line
2.17.1
#6 lore raw

Re: [PATCH v2 3/4] iio: potentiometer: Add support for Maxim DS3502

Quoted 4 lines · Jagath Jog J

The DS3502 is a 7-bit, nonvolatile digital potentiometer featuring an output voltage range of up to 15.5V.
DS3502 support is implemented into existing ds1803 driver

Be consistent here and in other commit messages with how you refer to the IC parts, i.e.
DS1803. Don't forget English grammar and punctuation, i.e. missed period above.

Quoted 3 lines

Datasheet: https://datasheets.maximintegrated.com/en/ds/DS3502.pdf

A tag block may not have blank lines. Drop it.

Quoted 1 line

...

drivers/iio/potentiometer/Kconfig config AD5272 · line 30

Quoted 2 lines
drivers/iio/potentiometer/Kconfig +1 -1
-       tristate "Maxim Integrated DS1803 Digital Potentiometer driver"
+       tristate "Maxim Integrated DS1803 and similar Digital Potentiometer driver"

Please, list them like other drivers do:

tristate "Maxim Integrated DS1803/DS... Digital Potentiometer driver"

...

drivers/iio/potentiometer/Kconfig config AD5272 · line 34

Quoted 4 lines
drivers/iio/potentiometer/Kconfig +2 -2
-         Say yes here to build support for the Maxim Integrated DS1803
-         digital potentiometer chip.
+         Say yes here to build support for the Maxim Integrated DS1803 and
+         similar digital potentiometer chip.

Same here.

...

Quoted 2 lines

- * Maxim Integrated DS1803 digital potentiometer driver
+ * Maxim Integrated DS1803 and similar digital potentiometer driver

Same here.

...

drivers/iio/potentiometer/ds1803.c line 20

Quoted 2 lines
drivers/iio/potentiometer/ds1803.c +0 -2
-#define DS1803_MAX_POS         255
-#define DS1803_WRITE(chan)     (0xa8 | ((chan) + 1))

Not sure why these were removed (or moved?)

...

Quoted 4 lines
drivers/iio/potentiometer/ds1803.c +4 -0
+static const struct ds1803_cfg ds1803_cfg[] = {
+       [DS1803_010] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms =  10,
+                        .channels = ds1803_channels,
+                        .num_channels = ARRAY_SIZE(ds1803_channels) },

drivers/iio/potentiometer/ds1803.c line 80

Quoted 10 lines
drivers/iio/potentiometer/ds1803.c +9 -0
+       [DS1803_050] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms =  50,
+                        .channels = ds1803_channels,
+                        .num_channels = ARRAY_SIZE(ds1803_channels) },
+       [DS1803_100] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms = 100,
+                        .channels = ds1803_channels,
+                        .num_channels = ARRAY_SIZE(ds1803_channels) },
+       [DS3502] =     { .wipers = 1, .avail = { 0, 1, 127 }, .kohms =  10,
+                        .channels = ds3502_channels,
+                        .num_channels = ARRAY_SIZE(ds3502_channels) },
 };

Split this on a per type basis. I believe it won't be too much work, also, consider adding channels as a separate preparatory patch as you did with avail.

...

drivers/iio/potentiometer/ds1803.c static int ds1803_probe(struct i2c_client *client, · line 184

Quoted 4 lines
drivers/iio/potentiometer/ds1803.c +3 -1
-       data->cfg = &ds1803_cfg[id->driver_data];
+       data->chip_type = (uintptr_t)device_get_match_data(dev);
+       if (data->chip_type < DS1803_010 || data->chip_type > DS3502)
+               data->chip_type = id->driver_data;

Split it into a separate patch and use pointer validation instead:

data->cfg = ...
if (!data->cfg)
data->cfg = ...id->driver_data;

...

drivers/iio/potentiometer/ds1803.c static int ds1803_probe(struct i2c_client *client, · line 198

Quoted 6 lines
drivers/iio/potentiometer/ds1803.c +3 -3
-       { .compatible = "maxim,ds1803-010", .data = &ds1803_cfg[DS1803_010] },
-       { .compatible = "maxim,ds1803-050", .data = &ds1803_cfg[DS1803_050] },
-       { .compatible = "maxim,ds1803-100", .data = &ds1803_cfg[DS1803_100] },
+       { .compatible = "maxim,ds1803-010", .data = (void *)DS1803_010 },
+       { .compatible = "maxim,ds1803-050", .data = (void *)DS1803_050 },
+       { .compatible = "maxim,ds1803-100", .data = (void *)DS1803_100 },

This is not good, please use pointers as it was before.

Quoted 1 line

+ { .compatible = "maxim,ds3502", .data = (void *)DS3502 },

Ditto. Create a new, separate structure for this type.

...

Quoted 4 lines
        { "ds1803-010", DS1803_010 },
        { "ds1803-050", DS1803_050 },
        { "ds1803-100", DS1803_100 },

+ { "ds3502", DS3502 },

Too many spaces.
Besides this, please create a new prerequisite patch to convert this to use pointers as above.

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

Re: [PATCH v2 3/4] iio: potentiometer: Add support for Maxim DS3502

Hello Andy,

Quoted 10 lines · Andy Shevchenko
Quoted 4 lines · Jagath Jog J

The DS3502 is a 7-bit, nonvolatile digital potentiometer featuring an output voltage range of up to 15.5V.
DS3502 support is implemented into existing ds1803 driver

Be consistent here and in other commit messages with how you refer to the IC parts, i.e.
DS1803. Don't forget English grammar and punctuation, i.e. missed period above.

I will fix this in v3

Quoted 24 lines
Quoted 3 lines

Datasheet: https://datasheets.maximintegrated.com/en/ds/DS3502.pdf

A tag block may not have blank lines. Drop it.

Quoted 1 line

...

drivers/iio/potentiometer/Kconfig config AD5272 · line 30

Quoted 2 lines
drivers/iio/potentiometer/Kconfig +1 -1
-       tristate "Maxim Integrated DS1803 Digital Potentiometer driver"
+       tristate "Maxim Integrated DS1803 and similar Digital Potentiometer driver"

Please, list them like other drivers do:

tristate "Maxim Integrated DS1803/DS... Digital Potentiometer driver"

...

drivers/iio/potentiometer/Kconfig config AD5272 · line 34

Quoted 4 lines
drivers/iio/potentiometer/Kconfig +2 -2
-         Say yes here to build support for the Maxim Integrated DS1803
-         digital potentiometer chip.
+         Say yes here to build support for the Maxim Integrated DS1803 and
+         similar digital potentiometer chip.
Quoted 8 lines

Same here.

...

Quoted 2 lines

- * Maxim Integrated DS1803 digital potentiometer driver
+ * Maxim Integrated DS1803 and similar digital potentiometer driver

Same here.

Based on Jonathan suggestion for the previous patch version I used "and similar" wording here.

Quoted 7 lines

...

drivers/iio/potentiometer/ds1803.c line 20

Quoted 2 lines
drivers/iio/potentiometer/ds1803.c +0 -2
-#define DS1803_MAX_POS         255
-#define DS1803_WRITE(chan)     (0xa8 | ((chan) + 1))

Not sure why these were removed (or moved?)

Since max wiper position is present in avail array of ds1803_cfg structure and that is being used for read scale so DS1803_MAX_POS is removed.

Since each wiper address of both parts is assigned to the address member of iio_chan_spec struct so DS1803_WRITE(chan) is removed.

Quoted 18 lines

...

Quoted 4 lines
drivers/iio/potentiometer/ds1803.c +4 -0
+static const struct ds1803_cfg ds1803_cfg[] = {
+       [DS1803_010] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms =  10,
+                        .channels = ds1803_channels,
+                        .num_channels = ARRAY_SIZE(ds1803_channels) },

drivers/iio/potentiometer/ds1803.c line 80

Quoted 10 lines
drivers/iio/potentiometer/ds1803.c +9 -0
+       [DS1803_050] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms =  50,
+                        .channels = ds1803_channels,
+                        .num_channels = ARRAY_SIZE(ds1803_channels) },
+       [DS1803_100] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms = 100,
+                        .channels = ds1803_channels,
+                        .num_channels = ARRAY_SIZE(ds1803_channels) },
+       [DS3502] =     { .wipers = 1, .avail = { 0, 1, 127 }, .kohms =  10,
+                        .channels = ds3502_channels,
+                        .num_channels = ARRAY_SIZE(ds3502_channels) },
 };
Quoted 3 lines

Split this on a per type basis. I believe it won't be too much work, also, consider adding channels as a separate preparatory patch as you did with avail.

Based on Jonathan suggestion for the previous patch version to avoid having different chip type related structures so channels and num_channels are added into ds1803_cfg structure.

Sure for channels I will split into separate patch for old part in v3.

Quoted 8 lines

...

drivers/iio/potentiometer/ds1803.c static int ds1803_probe(struct i2c_client *client, · line 184

Quoted 4 lines
drivers/iio/potentiometer/ds1803.c +3 -1
-       data->cfg = &ds1803_cfg[id->driver_data];
+       data->chip_type = (uintptr_t)device_get_match_data(dev);
+       if (data->chip_type < DS1803_010 || data->chip_type > DS3502)
+               data->chip_type = id->driver_data;
Quoted 11 lines

Split it into a separate patch and use pointer validation instead:

data->cfg = ...
if (!data->cfg)
data->cfg = ...id->driver_data;

...

Quoted 3 lines
drivers/iio/potentiometer/ds1803.c +0 -3
-       { .compatible = "maxim,ds1803-010", .data = &ds1803_cfg[DS1803_010] },
-       { .compatible = "maxim,ds1803-050", .data = &ds1803_cfg[DS1803_050] },
-       { .compatible = "maxim,ds1803-100", .data = &ds1803_cfg[DS1803_100] },

To get the chip specific structure I can use previous structure method for data and validation as you shown above.
But it is necessary to get the chip_type also because of dependency in ds1803_raw_read().

To get the chip_type can I use
data->chip_type = id->driver_data

Quoted 12 lines

drivers/iio/potentiometer/ds1803.c static int ds1803_probe(struct i2c_client *client, · line 198

Quoted 3 lines
drivers/iio/potentiometer/ds1803.c +3 -0
+       { .compatible = "maxim,ds1803-010", .data = (void *)DS1803_010 },
+       { .compatible = "maxim,ds1803-050", .data = (void *)DS1803_050 },
+       { .compatible = "maxim,ds1803-100", .data = (void *)DS1803_100 },

This is not good, please use pointers as it was before.

Quoted 1 line

+ { .compatible = "maxim,ds3502", .data = (void *)DS3502 },

Ditto. Create a new, separate structure for this type.

...

Quoted 8 lines
Quoted 4 lines
        { "ds1803-010", DS1803_010 },
        { "ds1803-050", DS1803_050 },
        { "ds1803-100", DS1803_100 },

+ { "ds3502", DS3502 },

Too many spaces.
Besides this, please create a new prerequisite patch to convert this to use pointers as above.

Sure I will split this patch in v3.
Thanks for feedback.

Quoted 4 lines
Signature · 3 lines
-- 
With Best Regards,
Andy Shevchenko

Best Regards,
Jagath

maintainer
#8 lore raw

Re: [PATCH v2 3/4] iio: potentiometer: Add support for Maxim DS3502

Quoted 9 lines · On Tue, 15 Feb 2022 01:22:54 +0530 Jagath Jog J <[email protected]> wrote:

Hello Andy,

Quoted 6 lines · Andy Shevchenko
Quoted 4 lines · Jagath Jog J

The DS3502 is a 7-bit, nonvolatile digital potentiometer featuring an output voltage range of up to 15.5V.
DS3502 support is implemented into existing ds1803 driver

Quoted 32 lines
Quoted 4 lines

Be consistent here and in other commit messages with how you refer to the IC parts, i.e.
DS1803. Don't forget English grammar and punctuation, i.e. missed period above.

I will fix this in v3

Quoted 25 lines
Quoted 3 lines

Datasheet: https://datasheets.maximintegrated.com/en/ds/DS3502.pdf

A tag block may not have blank lines. Drop it.

Quoted 1 line

...

drivers/iio/potentiometer/Kconfig config AD5272 · line 30

Quoted 2 lines
drivers/iio/potentiometer/Kconfig +1 -1
-       tristate "Maxim Integrated DS1803 Digital Potentiometer driver"
+       tristate "Maxim Integrated DS1803 and similar Digital Potentiometer driver"  

Please, list them like other drivers do:

tristate "Maxim Integrated DS1803/DS... Digital Potentiometer driver"

...

drivers/iio/potentiometer/Kconfig config AD5272 · line 34

Quoted 4 lines
drivers/iio/potentiometer/Kconfig +2 -2
-         Say yes here to build support for the Maxim Integrated DS1803
-         digital potentiometer chip.
+         Say yes here to build support for the Maxim Integrated DS1803 and
+         similar digital potentiometer chip.  

Same here.

Usual thing is to use the and similar phrasing for the title if it is getting to long and have the one place that lists them all being the belp text. We need it somewhere so people can grep for it.

Quoted 10 lines
Quoted 7 lines

...

Quoted 2 lines

- * Maxim Integrated DS1803 digital potentiometer driver
+ * Maxim Integrated DS1803 and similar digital potentiometer driver

Same here.

Based on Jonathan suggestion for the previous patch version I used "and similar" wording here.

I wasn't that clear on exactly where to do that! Sorry about that.

Quoted 37 lines
Quoted 8 lines

...

drivers/iio/potentiometer/ds1803.c line 20

Quoted 2 lines
drivers/iio/potentiometer/ds1803.c +0 -2
-#define DS1803_MAX_POS         255
-#define DS1803_WRITE(chan)     (0xa8 | ((chan) + 1))  

Not sure why these were removed (or moved?)

Since max wiper position is present in avail array of ds1803_cfg structure and that is being used for read scale so DS1803_MAX_POS is removed.

Since each wiper address of both parts is assigned to the address member of iio_chan_spec struct so DS1803_WRITE(chan) is removed.

Quoted 18 lines

...

Quoted 4 lines
drivers/iio/potentiometer/ds1803.c +4 -0
+static const struct ds1803_cfg ds1803_cfg[] = {
+       [DS1803_010] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms =  10,
+                        .channels = ds1803_channels,
+                        .num_channels = ARRAY_SIZE(ds1803_channels) },

drivers/iio/potentiometer/ds1803.c line 80

Quoted 10 lines
drivers/iio/potentiometer/ds1803.c +9 -0
+       [DS1803_050] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms =  50,
+                        .channels = ds1803_channels,
+                        .num_channels = ARRAY_SIZE(ds1803_channels) },
+       [DS1803_100] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms = 100,
+                        .channels = ds1803_channels,
+                        .num_channels = ARRAY_SIZE(ds1803_channels) },
+       [DS3502] =     { .wipers = 1, .avail = { 0, 1, 127 }, .kohms =  10,
+                        .channels = ds3502_channels,
+                        .num_channels = ARRAY_SIZE(ds3502_channels) },
 };  
Quoted 3 lines

Split this on a per type basis. I believe it won't be too much work, also, consider adding channels as a separate preparatory patch as you did with avail.

Quoted 5 lines

Based on Jonathan suggestion for the previous patch version to avoid having different chip type related structures so channels and num_channels are added into ds1803_cfg structure.

Sure for channels I will split into separate patch for old part in v3.

I'm not totally sure what Andy is suggesting with his feedback here.

Quoted 17 lines
Quoted 17 lines

...

drivers/iio/potentiometer/ds1803.c static int ds1803_probe(struct i2c_client *client, · line 184

Quoted 4 lines
drivers/iio/potentiometer/ds1803.c +3 -1
-       data->cfg = &ds1803_cfg[id->driver_data];
+       data->chip_type = (uintptr_t)device_get_match_data(dev);
+       if (data->chip_type < DS1803_010 || data->chip_type > DS3502)
+               data->chip_type = id->driver_data;  

Split it into a separate patch and use pointer validation instead:

data->cfg = ...
if (!data->cfg)
data->cfg = ...id->driver_data;

...

Quoted 8 lines
Quoted 3 lines

drivers/iio/potentiometer/ds1803.c static int ds1803_probe(struct i2c_client *client, · line 158

Quoted 3 lines
drivers/iio/potentiometer/ds1803.c +0 -3
-       { .compatible = "maxim,ds1803-010", .data = &ds1803_cfg[DS1803_010] },
-       { .compatible = "maxim,ds1803-050", .data = &ds1803_cfg[DS1803_050] },
-       { .compatible = "maxim,ds1803-100", .data = &ds1803_cfg[DS1803_100] },  

To get the chip specific structure I can use previous structure method for data and validation as you shown above.
But it is necessary to get the chip_type also because of dependency in ds1803_raw_read().

You could use a function pointer in the cfg structure and provide appropriate read functions for the different types so that read_raw() can call the appropriate function for the type of device. That would be tidy and avoid this need to change to an enum.

Sorry for slow response btw as I didn't get in before v3!

Thanks,

Jonathan

Quoted 35 lines

To get the chip_type can I use
data->chip_type = id->driver_data

Quoted 12 lines

drivers/iio/potentiometer/ds1803.c static int ds1803_probe(struct i2c_client *client, · line 198

Quoted 3 lines
drivers/iio/potentiometer/ds1803.c +3 -0
+       { .compatible = "maxim,ds1803-010", .data = (void *)DS1803_010 },
+       { .compatible = "maxim,ds1803-050", .data = (void *)DS1803_050 },
+       { .compatible = "maxim,ds1803-100", .data = (void *)DS1803_100 },  

This is not good, please use pointers as it was before.

Quoted 1 line

+ { .compatible = "maxim,ds3502", .data = (void *)DS3502 },

Ditto. Create a new, separate structure for this type.

...

Quoted 8 lines
Quoted 4 lines
        { "ds1803-010", DS1803_010 },
        { "ds1803-050", DS1803_050 },
        { "ds1803-100", DS1803_100 },

+ { "ds3502", DS3502 },

Too many spaces.
Besides this, please create a new prerequisite patch to convert this to use pointers as above.

Sure I will split this patch in v3.
Thanks for feedback.

Quoted 4 lines
Signature · 3 lines
-- 
With Best Regards,
Andy Shevchenko  

Best Regards,
Jagath

#9 lore raw

PATCH v2 4/4 dt-bindings: iio: potentiometer: Add Maxim DS3502 in trivial-devices

In reply to Jagath Jog J

Maxim DS3502 is a 7 bit nonvolatile digital potentiometer. Add DS3502 binding into trivial-devices.yaml

---
 Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/trivial-devices.yaml +2 -0
index 091792ba993e..b6187603317a 100644
@@ -157,6 +157,8 @@ properties:
           - maxim,ds1803-050
             # 100 kOhm digital potentiometer with I2C interface
           - maxim,ds1803-100
+            # 10 kOhm digital potentiometer with I2C interface
+          - maxim,ds3502
             # Low-Power, 4-/12-Channel, 2-Wire Serial, 12-Bit ADCs
           - maxim,max1237
             # Temperature Sensor, I2C interface
Signature · 1 line
2.17.1
#10 lore raw

Re: [PATCH v2 4/4] dt-bindings: iio: potentiometer: Add Maxim DS3502 in trivial-devices

Quoted 3 lines · Jagath Jog J

Maxim DS3502 is a 7 bit nonvolatile digital potentiometer. Add DS3502 binding into trivial-devices.yaml

Missed grammar period here.

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

Re: [PATCH v2 4/4] dt-bindings: iio: potentiometer: Add Maxim DS3502 in trivial-devices

In reply to Jagath Jog J
Quoted 8 lines · Jagath Jog J

Maxim DS3502 is a 7 bit nonvolatile digital potentiometer. Add DS3502 binding into trivial-devices.yaml

---
 Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++
 1 file changed, 2 insertions(+)

Please add Acked-by/Reviewed-by tags when posting new versions. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for acks received on the version they apply.

If a tag was not added on purpose, please state why and what changed.

#12 lore raw
In reply to Jagath Jog J
Quoted 3 lines · Jagath Jog J

Add dt-bindings and support for Maxim DS3502 into existing ds1803 driver. DS3502 is a 7 bit Nonvolatile Digital Potentiometer.

A very good start! A few minor comments to be addressed and one patch has to be split to at least three.

Signature · 2 lines
With Best Regards,
Andy Shevchenko