Skip to contentSkip to conversation

dt-bindings: iio: adc: mcp3911: add support for the whole MCP39xx family

PATCH Superseded Marcus Folkesson 2 participants 4 messages Aug 4, 2023 – Aug 5, 2023

Subsystems (3)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Marcus Folkesson

author maintainer
#0 lore raw

PATCH v2 1/2 dt-bindings: iio: adc: mcp3911: add support for the whole MCP39xx family

Microchip does have many similar chips, add those to the compatible string as the driver support is extended.

The new supported chips are:
- microchip,mcp3910
- microchip,mcp3912
- microchip,mcp3913
- microchip,mcp3914
- microchip,mcp3918
- microchip,mcp3919

---

Notes:
v2:
- No changes

 .../devicetree/bindings/iio/adc/microchip,mcp3911.yaml      | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/iio/adc/microchip,mcp3911.yaml +6 -0
index f7b3fde4115a..06951ec5f5da 100644
@@ -18,7 +18,13 @@ description: |
 properties:
   compatible:
     enum:
+      - microchip,mcp3910
       - microchip,mcp3911
+      - microchip,mcp3912
+      - microchip,mcp3913
+      - microchip,mcp3914
+      - microchip,mcp3918
+      - microchip,mcp3919
 
   reg:
     maxItems: 1
Signature · 1 line
2.40.1
author maintainer
#1 lore raw

PATCH v2 2/2 iio: adc: mcp3911: add support for the whole MCP39xx family

Microchip does have many similar chips, add support for those.

The new supported chips are:
- microchip,mcp3910
- microchip,mcp3912
- microchip,mcp3913
- microchip,mcp3914
- microchip,mcp3918
- microchip,mcp3919

---

Notes:
v2:
- Use callbacks rather than matching against enum for determine chip variants

 drivers/iio/adc/Kconfig   |   5 +-
 drivers/iio/adc/mcp3911.c | 446 +++++++++++++++++++++++++++++++++-----
 2 files changed, 392 insertions(+), 59 deletions(-)
drivers/iio/adc/Kconfig +3 -2
index eb2b09ef5d5b..36ea09cbbaaa 100644
@@ -774,8 +774,9 @@ config MCP3911
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
 	help
-	  Say yes here to build support for Microchip Technology's MCP3911
-	  analog to digital converter.
+	  Say yes here to build support for Microchip Technology's MCP3910,
+          MCP3911, MCP3912, MCP3913, MCP3914, MCP3918 and MCP3919
+	  analog to digital converters.
 
 	  This driver can also be built as a module. If so, the module will be
 	  called mcp3911.
drivers/iio/adc/mcp3911.c +389 -57

577 lines not on this page · raw message

Signature · 1 line
2.40.1
#2 lore raw

Re: [PATCH v2 2/2] iio: adc: mcp3911: add support for the whole MCP39xx family

Quoted 9 lines · Marcus Folkesson

Microchip does have many similar chips, add support for those.

The new supported chips are:
- microchip,mcp3910
- microchip,mcp3912
- microchip,mcp3913
- microchip,mcp3914
- microchip,mcp3918
- microchip,mcp3919

...

drivers/iio/adc/Kconfig config MCP3911

Quoted 6 lines
drivers/iio/adc/Kconfig +2 -2
 	help
-	  Say yes here to build support for Microchip Technology's MCP3911
-	  analog to digital converter.
+	  Say yes here to build support for Microchip Technology's MCP3910,
 
+          MCP3911, MCP3912, MCP3913, MCP3914, MCP3918 and MCP3919

This line is misindented. Should be <TAB><space><space>.

Quoted 1 line
drivers/iio/adc/Kconfig +1 -0
+	  analog to digital converters.

...

drivers/iio/adc/mcp3911.c line 84

Quoted 4 lines
drivers/iio/adc/mcp3911.c +4 -0
+#define MCP3910_REG_OFFCAL_CH0		0x0f
+#define MCP3910_OFFCAL(x)		(MCP3910_REG_OFFCAL_CH0 + x * 6)
+
+

Single blank line is enough.

...

drivers/iio/adc/mcp3911.c static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, · line 176

Quoted 3 lines
drivers/iio/adc/mcp3911.c +3 -0
+static int mcp3910_get_offset(struct mcp3911 *adc, int channel, int *val)
+{
+	return mcp3911_read(adc, MCP3910_OFFCAL(channel), val, 3);

Just to be sure, the proper endianess conversion is done in mcp3911_read() and mcp3911_write() calls?

This question applies to all calls to that APIs.

Quoted 1 line

+}

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+	int ret = mcp3911_write(adc, MCP3910_OFFCAL(channel), val,
+			3);

This looks weird not being on a single line. Moreover it fits even 80 characters. Same applies to other similar cases.

Also, please use better approach, i.e.

	int ret;

	ret = ...(...);
	if (ret)
		...

Also applies to several places.

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

...

Review

Quoted 1 line
(quoted diff) +1 -0
+	/* Enable offset*/

Missing space.

...

drivers/iio/adc/mcp3911.c static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, · line 214

Quoted 3 lines
drivers/iio/adc/mcp3911.c +3 -0
+static int mcp3910_get_osr(struct mcp3911 *adc, int *val)
+{
+	int ret = mcp3911_read(adc, MCP3910_REG_CONFIG0, val, 3);

Have you run checkpatch? Here should be a blank line. Same in other several places.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	*val = FIELD_GET(MCP3910_CONFIG0_OSR, *val);
+	*val = 32 << *val;

Please, use a temporary variable and assign the result only once. It will be a better code.

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

...

drivers/iio/adc/mcp3911.c static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, · line 229

Quoted 3 lines
drivers/iio/adc/mcp3911.c +3 -0
+static int mcp3911_set_osr(struct mcp3911 *adc, int val)
+{
+	val = FIELD_PREP(MCP3911_CONFIG_OSR, val);

As per above.

drivers/iio/adc/mcp3911.c static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, · line 232

Quoted 4 lines
drivers/iio/adc/mcp3911.c +3 -0
+	return mcp3911_update(adc, MCP3911_REG_CONFIG,
+			MCP3911_CONFIG_OSR, val, 2);
 
+

Redundant blank line.

Quoted 1 line

+}

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+static int mcp3911_get_osr(struct mcp3911 *adc, int *val)
+{

As per above.

Quoted 1 line

+}

...

Quoted 1 line

+ /* Set gain to 1 for all channels */

Again, wrong indentation. Can you check all your lines for the proper indentation. (Here should be just <TAB>.)

...

drivers/iio/adc/mcp3911.c static int mcp3911_config(struct mcp3911 *adc) · line 607

Quoted 4 lines
drivers/iio/adc/mcp3911.c +4 -0
+	for (int i = 0; i < adc->chip->num_channels - 1; i++) {
+		adc->gain[i] = 1;
+		regval &= ~MCP3911_GAIN_MASK(i);
+	}

Missing blank line.

drivers/iio/adc/mcp3911.c static int mcp3911_config(struct mcp3911 *adc) · line 610

Quoted 3 lines
drivers/iio/adc/mcp3911.c +3 -0
+	return mcp3911_write(adc, MCP3911_REG_GAIN, regval, 1);
+
+

Too many redundant blank lines.

Quoted 1 line

+}

...

Quoted 1 line

+ /* Set gain to 1 for all channels */

Mind indentation.

...

Review

Quoted 1 line
(quoted diff) +1 -0
+	/* Disable offset to ignore any old values in offset register*/

Missing space.

...

drivers/iio/adc/mcp3911.c static int mcp3911_probe(struct spi_device *spi) · line 718

Quoted 1 line
drivers/iio/adc/mcp3911.c +1 -0
+	adc->chip = (struct mcp3911_chip_info *)spi_get_device_id(spi)->driver_data;

Can't you use spi_get_device_match_data()?

...

drivers/iio/adc/mcp3911.c static int mcp3911_probe(struct spi_device *spi) · line 758

Quoted 3 lines
drivers/iio/adc/mcp3911.c +3 -0
+	/*
+	 * Fallback to "device-addr" due to historical mismatch between
+	 * dt-bindings and implementation

Missing grammatical period at the end.

Quoted 1 line
drivers/iio/adc/mcp3911.c +1 -0
+	 */

...

drivers/iio/adc/mcp3911.c static int mcp3911_probe(struct spi_device *spi) · line 761

Quoted 1 line
drivers/iio/adc/mcp3911.c +1 -0
+		device_property_read_u32(&adc->spi->dev, "device-addr", &adc->dev_addr);

With

	struct device *dev = &adc->spi->dev;

lines like this will be neater.

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

Re: [PATCH v2 2/2] iio: adc: mcp3911: add support for the whole MCP39xx family

Hi Andy,

Thanks for your revew!

[...]

Quoted 9 lines

drivers/iio/adc/mcp3911.c static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, · line 176

Quoted 4 lines
drivers/iio/adc/mcp3911.c +3 -0
+static int mcp3910_get_offset(struct mcp3911 *adc, int channel, int *val)
+{
+	return mcp3911_read(adc, MCP3910_OFFCAL(channel), val, 3);

Just to be sure, the proper endianess conversion is done in mcp3911_read() and mcp3911_write() calls?

This question applies to all calls to that APIs.

Yes it does.

[...]

Quoted 7 lines

drivers/iio/adc/mcp3911.c static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, · line 214

Quoted 4 lines
drivers/iio/adc/mcp3911.c +3 -0
+static int mcp3910_get_osr(struct mcp3911 *adc, int *val)
+{
+	int ret = mcp3911_read(adc, MCP3910_REG_CONFIG0, val, 3);

Have you run checkpatch? Here should be a blank line. Same in other several places.

Yes, checkpatch does not report any warning for this.

[...]

Quoted 5 lines

drivers/iio/adc/mcp3911.c static int mcp3911_probe(struct spi_device *spi) · line 718

Quoted 1 line
drivers/iio/adc/mcp3911.c +1 -0
+	adc->chip = (struct mcp3911_chip_info *)spi_get_device_id(spi)->driver_data;

Can't you use spi_get_device_match_data()?

...

Will go for spi_get_device_match_data().

[...]

Quoted 8 lines

drivers/iio/adc/mcp3911.c static int mcp3911_probe(struct spi_device *spi) · line 761

Quoted 2 lines
drivers/iio/adc/mcp3911.c +1 -0
+		device_property_read_u32(&adc->spi->dev, "device-addr", &adc->dev_addr);

With

	struct device *dev = &adc->spi->dev;

lines like this will be neater.

Indeed, but I think I will short it down to just spi->dev.

Quoted 3 lines

Best regards,
Marcus Folkesson