Skip to contentSkip to conversation

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

PATCH Superseded Marcus Folkesson 3 participants 7 messages Aug 7, 2023 – Aug 8, 2023

Subsystems (3)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Marcus Folkesson

author maintainer
#0 lore raw

PATCH v3 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
v3:
- 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 v3 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
v3:
- Fix cosmetics

 drivers/iio/adc/Kconfig   |   5 +-
 drivers/iio/adc/mcp3911.c | 457 +++++++++++++++++++++++++++++++++-----
 2 files changed, 401 insertions(+), 61 deletions(-)
drivers/iio/adc/Kconfig +3 -2
index eb2b09ef5d5b..9a9838430530 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 +398 -59

590 lines not on this page · raw message

Signature · 1 line
2.40.1
#2 lore raw

Re: [PATCH v3 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

...

Quoted 1 line

+#define MCP3910_STATUSCOM_DRHIZ BIT(20)

Is it deliberately using spaces? If so, why?

...

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

Quoted 9 lines
drivers/iio/adc/mcp3911.c +8 -0
+static int mcp3910_get_osr(struct mcp3911 *adc, int *val)
+{
+	int ret, osr;
+
+	ret = mcp3911_read(adc, MCP3910_REG_CONFIG0, val, 3);
 
+	osr = FIELD_GET(MCP3910_CONFIG0_OSR, *val);
+	*val = 32 << osr;
+	return ret;

I believe this is wrong order. Or bad code. The rule of thumb is not pollute the output variable if we know the error happened.

Same applies to another function.

Quoted 1 line

+}

...

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

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

Why not spi->dev? Ditto for other uses like this.

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

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

In reply to Marcus Folkesson
Quoted 8 lines · Marcus Folkesson
Quoted 7 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 -1
-	ret = mcp3911_config(adc);
+	ret = device_property_read_u32(&adc->spi->dev, "microchip,device-addr", &adc->dev_addr);

Why not spi->dev? Ditto for other uses like this.

Quoted 5 lines

After all, I think it is better to stick sith adc->spi-dev to be consistent with the rest of the probe function. Change to spi->dev should probably be a seperate patch.
Do you agree?

You can first simplify the usages and then add new family support already using spi->dev.

Best regards,
Krzysztof

#6 lore raw

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

In reply to Marcus Folkesson
Quoted 2 lines · Marcus Folkesson
Quoted 1 line · Andy Shevchenko

On Mon, Aug 07, 2023 at 09:18:31AM +0200, Marcus Folkesson wrote:

...

Quoted 9 lines
Quoted 4 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 -1
-	ret = mcp3911_config(adc);
+	ret = device_property_read_u32(&adc->spi->dev, "microchip,device-addr", &adc->dev_addr);

Why not spi->dev? Ditto for other uses like this.

After all, I think it is better to stick sith adc->spi-dev to be consistent with the rest of the probe function. Change to spi->dev should probably be a seperate patch.
Do you agree?

Make sure you first switch to use shorter form and then add this one. In that case I agree.

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

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

In reply to Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
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

Quoted 5 lines

...

Quoted 1 line

+#define MCP3910_STATUSCOM_DRHIZ BIT(20)

Is it deliberately using spaces? If so, why?

No, probably due to my with my new vim setup..

Quoted 18 lines

...

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

Quoted 9 lines
drivers/iio/adc/mcp3911.c +8 -0
+static int mcp3910_get_osr(struct mcp3911 *adc, int *val)
+{
+	int ret, osr;
+
+	ret = mcp3911_read(adc, MCP3910_REG_CONFIG0, val, 3);
 
+	osr = FIELD_GET(MCP3910_CONFIG0_OSR, *val);
+	*val = 32 << osr;
+	return ret;

I believe this is wrong order. Or bad code. The rule of thumb is not pollute the output variable if we know the error happened.

Same applies to another function.

Quoted 8 lines
Quoted 1 line

+}

...

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

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

Why not spi->dev? Ditto for other uses like this.

After all, I think it is better to stick sith adc->spi-dev to be consistent with the rest of the probe function. Change to spi->dev should probably be a seperate patch.
Do you agree?

Quoted 6 lines
Signature · 3 lines
-- 
With Best Regards,
Andy Shevchenko
#5 lore raw

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

In reply to Krzysztof Kozlowski
Quoted 1 line · Krzysztof Kozlowski

On 08/08/2023 09:22, Marcus Folkesson wrote:

...

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

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
+	ret = device_property_read_u32(&adc->spi->dev, "microchip,device-addr", &adc->dev_addr);

Why not spi->dev? Ditto for other uses like this.

Quoted 8 lines
Quoted 5 lines

After all, I think it is better to stick sith adc->spi-dev to be consistent with the rest of the probe function. Change to spi->dev should probably be a seperate patch.
Do you agree?

You can first simplify the usages and then add new family support already using spi->dev.

He-he, answered the same :-)

Signature · 2 lines
With Best Regards,
Andy Shevchenko