Skip to contentSkip to conversation

Adding support for Microchip MCP3564 ADC family

PATCH Superseded [email protected] 4 participants 9 messages Aug 29, 2023 – Sep 3, 2023

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

v5 cover Adding support for Microchip MCP3564 ADC family

From: Marius Cristea <[email protected]>

Adding support for Microchip family of 153.6 ksps, Low-Noise 16/24-Bit Delta-Sigma ADCs with an SPI interface. This driver covers the following part numbers:
- MCP3561, MCP3562, MCP3564, MCP3561R, MCP3562R, MCP3564R,
- MCP3461, MCP3462, MCP3464, MCP3461R, MCP3462R and MCP3464R.

Differences related to previous patch:
v5:
- fix review comments from v4:
- fix coding stile
- remove some of the _SET defines
- flip logic to cut down on indent in some cases
- update "mcp3564_update_8bits" function to be more clear

v4:
- fix review comments from v3:
- adding label names for channels into the example from the

    "microchip,mcp3564.yaml" file  

- update defines names (with _REG and _MASK)
- code clean-up
- flip logic to cut down on indent in some cases
- use "spi_get_device_match_data" instead of "device_get_match_data"
- remove some unnecessary _SET functions
- change "boost_current" attribute to "boost_current_gain". The attribute is a gain not an absolute value.
- change "boost_current_available" attribute to "boost_current_gain_available"
- update comment from v3 (to better describe the change) "fallback compatible in device tree to deal with some newer part number" to "stop failing to probe when the chip id is not recognized. In this case a fallback compatible has been used to support a new part number"

v3:
- fix review comments:
- fix and update the device tree bindings
- enable "auto_zeroing_ref_enable" attribute only
when internal reference is used
- remove unused headers
- fix comments (kernel-docs)
- remove scan_type
- replace "extend_name" with read_label
- print label for each channel (label could be added into the dt)
- add comment to explain the maximum channels numbers
- add protection around critical region
- stop failing to probe when the chip id is not recognized. In this case a fallback compatible has been used to support a new part number

- Open questions:
- whether or not to add a spi-mux type of thing to deal with the part number address in case there are multiple devices connected to the same chip select.
- discussion related to the "custom property". Last time around a consensus wasn't reached.

v2:
- fix review comments:
- change the device tree bindings
- change the ADC channel creation (starting from DT)
- use defines, masks and FIELD_PREP() instead of hardcoded values
- mode the PGA from Hardware Gain to scale
- add a current output channel from burnout current
- fix coding style issues
- use self-explanatory naming to drop the comment
- renumbered the versioning (start with v1 instead of v0)

v1:
- first version committed to review

Marius Cristea (2):
dt-bindings: iio: adc: adding MCP3564 ADC
iio: adc: adding support for MCP3564 ADC

 .../ABI/testing/sysfs-bus-iio-adc-mcp3564     |   53 +
 .../bindings/iio/adc/microchip,mcp3564.yaml   |  205 +++
 MAINTAINERS                                   |    7 +
 drivers/iio/adc/Kconfig                       |   13 +
 drivers/iio/adc/Makefile                      |    1 +
 drivers/iio/adc/mcp3564.c                     | 1516 +++++++++++++++++
 6 files changed, 1795 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-adc-mcp3564
 create mode 100644 Documentation/devicetree/bindings/iio/adc/microchip,mcp3564.yaml
 create mode 100644 drivers/iio/adc/mcp3564.c

base-commit: 9e66fb52449538406cea43e9f3889c391350e76e

Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v5 1/2 dt-bindings: iio: adc: adding MCP3564 ADC

From: Marius Cristea <[email protected]>

This is the device tree schema for iio driver for Microchip family of 153.6 ksps, Low-Noise 16/24-Bit Delta-Sigma ADCs with an SPI interface (Microchip's MCP3461, MCP3462, MCP3464, MCP3461R, MCP3462R, MCP3464R, MCP3561, MCP3562, MCP3564, MCP3561R, MCP3562R and MCP3564R analog to digital converters).

---
 .../bindings/iio/adc/microchip,mcp3564.yaml   | 205 ++++++++++++++++++
 1 file changed, 205 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/microchip,mcp3564.yaml
Documentation/devicetree/bindings/iio/adc/microchip,mcp3564.yaml new file +205 -0
new file mode 100644
index 000000000000..675319276197
@@ -0,0 +1,205 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/microchip,mcp3564.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Microchip MCP346X and MCP356X ADC Family
+
+maintainers:
+  - Marius Cristea <[email protected]>
+
+description: |
+  Bindings for the Microchip family of 153.6 ksps, Low-Noise 16/24-Bit
+  Delta-Sigma ADCs with an SPI interface. Datasheet can be found here:
+  Datasheet for MCP3561, MCP3562, MCP3564 can be found here:
+    https://ww1.microchip.com/downloads/aemDocuments/documents/MSLD/ProductDocuments/DataSheets/MCP3561-2-4-Family-Data-Sheet-DS20006181C.pdf
+  Datasheet for MCP3561R, MCP3562R, MCP3564R can be found here:
+    https://ww1.microchip.com/downloads/aemDocuments/documents/APID/ProductDocuments/DataSheets/MCP3561_2_4R-Data-Sheet-DS200006391C.pdf
+  Datasheet for MCP3461, MCP3462, MCP3464 can be found here:
+    https://ww1.microchip.com/downloads/aemDocuments/documents/APID/ProductDocuments/DataSheets/MCP3461-2-4-Two-Four-Eight-Channel-153.6-ksps-Low-Noise-16-Bit-Delta-Sigma-ADC-Data-Sheet-20006180D.pdf
+  Datasheet for MCP3461R, MCP3462R, MCP3464R can be found here:
+    https://ww1.microchip.com/downloads/aemDocuments/documents/APID/ProductDocuments/DataSheets/MCP3461-2-4R-Family-Data-Sheet-DS20006404C.pdf
+
+properties:
+  compatible:
+    enum:
+      - microchip,mcp3461
+      - microchip,mcp3462
+      - microchip,mcp3464
+      - microchip,mcp3461r
+      - microchip,mcp3462r
+      - microchip,mcp3464r
+      - microchip,mcp3561
+      - microchip,mcp3562
+      - microchip,mcp3564
+      - microchip,mcp3561r
+      - microchip,mcp3562r
+      - microchip,mcp3564r
+
+  reg:
+    maxItems: 1
+
+  spi-max-frequency:
+    maximum: 20000000
+
+  spi-cpha: true
+
+  spi-cpol: true
+
+  vdd-supply: true
+
+  avdd-supply: true
+
+  clocks:
+    description:
+      Phandle and clock identifier for external sampling clock.
+      If not specified, the internal crystal oscillator will be used.
+    maxItems: 1
+
+  interrupts:
+    description: IRQ line of the ADC
+    maxItems: 1
+
+  drive-open-drain:
+    description:
+      Whether to drive the IRQ signal as push-pull (default) or open-drain. Note
+      that the device requires this pin to become "high", otherwise it will stop
+      converting.
+    type: boolean
+
+  vref-supply:
+    description:
+      Some devices have a specific reference voltage supplied on a different
+      pin to the other supplies. Needed to be able to establish channel scaling
+      unless there is also an internal reference available (e.g. mcp3564r). In
+      case of "r" devices (e. g. mcp3564r), if it does not exists the internal
+      reference will be used.
+
+  microchip,hw-device-address:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 0
+    maximum: 3
+    description:
+      The address is set on a per-device basis by fuses in the factory,
+      configured on request. If not requested, the fuses are set for 0x1.
+      The device address is part of the device markings to avoid
+      potential confusion. This address is coded on two bits, so four possible
+      addresses are available when multiple devices are present on the same
+      SPI bus with only one Chip Select line for all devices.
+      Each device communication starts by a CS falling edge, followed by the
+      clocking of the device address (BITS[7:6] - top two bits of COMMAND BYTE
+      which is first one on the wire).
+
+  "#io-channel-cells":
+    const: 1
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+patternProperties:
+  "^channel@([0-9]|([1-7][0-9]))$":
+    $ref: adc.yaml
+    type: object
+    unevaluatedProperties: false
+    description: Represents the external channels which are connected to the ADC.
+
+    properties:
+      reg:
+        description: The channel number in single-ended and differential mode.
+        minimum: 0
+        maximum: 79
+
+    required:
+      - reg
+
+dependencies:
+  spi-cpol: [ spi-cpha ]
+  spi-cpha: [ spi-cpol ]
+
+required:
+  - compatible
+  - reg
+  - microchip,hw-device-address
+  - spi-max-frequency
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+  - # External vref, no internal reference
+    if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - microchip,mcp3461
+              - microchip,mcp3462
+              - microchip,mcp3464
+              - microchip,mcp3561
+              - microchip,mcp3562
+              - microchip,mcp3564
+    then:
+      required:
+        - vref-supply
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@0 {
+            compatible = "microchip,mcp3564r";
+            reg = <0>;
+            vref-supply = <&vref_reg>;
+            spi-cpha;
+            spi-cpol;
+            spi-max-frequency = <10000000>;
+            microchip,hw-device-address = <1>;
+
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            channel@0 {
+                /* CH0 to AGND */
+                reg = <0>;
+                label = "CH0";
+            };
+
+            channel@1 {
+                /* CH1 to AGND */
+                reg = <1>;
+                label = "CH1";
+            };
+
+            /* diff-channels */
+            channel@11 {
+                reg = <11>;
+
+                /* CN0, CN1 */
+                diff-channels = <0 1>;
+                label = "CH0_CH1";
+            };
+
+            channel@22 {
+                reg = <0x22>;
+
+                /* CN1, CN2 */
+                diff-channels = <1 2>;
+                label = "CH1_CH3";
+            };
+
+            channel@23 {
+                reg = <0x23>;
+
+                /* CN1, CN3 */
+                diff-channels = <1 3>;
+                label = "CH1_CH3";
+            };
+        };
+    };
+...
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v5 1/2] dt-bindings: iio: adc: adding MCP3564 ADC

Quoted 10 lines · On Tue, Aug 29, 2023 at 06:41:32PM +0300, [email protected] wrote:

From: Marius Cristea <[email protected]>

This is the device tree schema for iio driver for Microchip family of 153.6 ksps, Low-Noise 16/24-Bit Delta-Sigma ADCs with an SPI interface (Microchip's MCP3461, MCP3462, MCP3464, MCP3461R, MCP3462R, MCP3464R, MCP3561, MCP3562, MCP3564, MCP3561R, MCP3562R and MCP3564R analog to digital converters).

Did you intentionally drop my reviewed-by that I gave you on v4?

Thanks,
Conor.

author maintainer
#3 lore raw

Re: [PATCH v5 1/2] dt-bindings: iio: adc: adding MCP3564 ADC

Hi Conor

Quoted 11 lines · Conor Dooley
Quoted 9 lines · On Tue, Aug 29, 2023 at 06:41:32PM +0300, [email protected] wrote:

From: Marius Cristea <[email protected]>

This is the device tree schema for iio driver for Microchip family of 153.6 ksps, Low-Noise 16/24-Bit Delta-Sigma ADCs with an SPI interface (Microchip's MCP3461, MCP3462, MCP3464, MCP3461R, MCP3462R, MCP3464R, MCP3561, MCP3562, MCP3564, MCP3561R, MCP3562R and MCP3564R analog to digital converters).

Quoted 4 lines
Quoted 1 line

Did you intentionally drop my reviewed-by that I gave you on v4?

Sorry that was my mistake. I was not aware that I need to keep the reviewd-by that you have given me on v4, also on v5.

Thanks,
Marius

Reviewed-by
#4 lore raw

Re: [PATCH v5 1/2] dt-bindings: iio: adc: adding MCP3564 ADC

Quoted 14 lines · On Tue, Aug 29, 2023 at 04:01:00PM +0000, [email protected] wrote:

Hi Conor

Quoted 11 lines · Conor Dooley
Quoted 9 lines · On Tue, Aug 29, 2023 at 06:41:32PM +0300, [email protected] wrote:

From: Marius Cristea <[email protected]>

This is the device tree schema for iio driver for Microchip family of 153.6 ksps, Low-Noise 16/24-Bit Delta-Sigma ADCs with an SPI interface (Microchip's MCP3461, MCP3462, MCP3464, MCP3461R, MCP3462R, MCP3464R, MCP3561, MCP3562, MCP3564, MCP3561R, MCP3562R and MCP3564R analog to digital converters).

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Did you intentionally drop my reviewed-by that I gave you on v4?

Sorry that was my mistake. I was not aware that I need to keep the reviewd-by that you have given me on v4, also on v5.

If you don't change anything meaningful, there's no need to drop the tags. AFAICT, you changed nothing at all here.

Thanks,
Conor.

#5 lore raw

Re: [PATCH v5 1/2] dt-bindings: iio: adc: adding MCP3564 ADC

In reply to [email protected]
Quoted 9 lines · On 29/08/2023 17:41, [email protected] wrote:

From: Marius Cristea <[email protected]>

This is the device tree schema for iio driver for Microchip family of 153.6 ksps, Low-Noise 16/24-Bit Delta-Sigma ADCs with an SPI interface (Microchip's MCP3461, MCP3462, MCP3464, MCP3461R, MCP3462R, MCP3464R, MCP3561, MCP3562, MCP3564, MCP3561R, MCP3562R and MCP3564R analog to digital converters).

Quoted 3 lines
---
 .../bindings/iio/adc/microchip,mcp3564.yaml   | 205 ++++++++++++++++++

What changed? Cover letter says nothing about binding, so this patch must say. Especially that you decided to ignore review.

Best regards,
Krzysztof

author maintainer
#6 lore raw

Re: [PATCH v5 1/2] dt-bindings: iio: adc: adding MCP3564 ADC

Hi Krzysztof,

Quoted 13 lines · Krzysztof Kozlowski

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 9 lines · On 29/08/2023 17:41, [email protected] wrote:

From: Marius Cristea <[email protected]>

This is the device tree schema for iio driver for Microchip family of 153.6 ksps, Low-Noise 16/24-Bit Delta-Sigma ADCs with an SPI interface (Microchip's MCP3461, MCP3462, MCP3464, MCP3461R, MCP3462R, MCP3464R, MCP3561, MCP3562, MCP3564, MCP3561R, MCP3562R and MCP3564R analog to digital converters).

Quoted 8 lines
Quoted 4 lines

---
 .../bindings/iio/adc/microchip,mcp3564.yaml   | 205
++++++++++++++++++

What changed? Cover letter says nothing about binding, so this patch must say. Especially that you decided to ignore review.

My bad. I was bad handling the resubmition of the patch. I was not
"aware" that I need to keep the "reviewed-by" for the following patches.

This patch didn't change anything to the "microchip,mcp3564.yaml" file.

Quoted 3 lines

Best regards,
Krzysztof

author maintainer
#7 lore raw

PATCH v5 2/2 iio: adc: adding support for MCP3564 ADC

In reply to [email protected]

From: Marius Cristea <[email protected]>

This is the iio driver for Microchip family of 153.6 ksps, Low-Noise 16/24-Bit Delta-Sigma ADCs with an SPI interface (Microchip's MCP3461, MCP3462, MCP3464, MCP3461R, MCP3462R, MCP3464R, MCP3561, MCP3562, MCP3564, MCP3561R, MCP3562R and MCP3564R analog to digital converters).

---
 .../ABI/testing/sysfs-bus-iio-adc-mcp3564     |   53 +
 MAINTAINERS                                   |    7 +
 drivers/iio/adc/Kconfig                       |   13 +
 drivers/iio/adc/Makefile                      |    1 +
 drivers/iio/adc/mcp3564.c                     | 1516 +++++++++++++++++
 5 files changed, 1590 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-adc-mcp3564
 create mode 100644 drivers/iio/adc/mcp3564.c
Documentation/ABI/testing/sysfs-bus-iio-adc-mcp3564 new file +53 -0
new file mode 100644
index 000000000000..4d6b1f40e277
@@ -0,0 +1,53 @@
+What:		/sys/bus/iio/devices/iio:deviceX/boost_current_gain
+KernelVersion:	6.4
+Contact:	[email protected]
+Description:
+		This attribute is used to set the gain of the biasing current
+		circuit of the Delta-Sigma modulator. The different BOOST
+		settings are applied to the entire modulator circuit, including
+		the voltage reference buffers.
+
+What:		/sys/bus/iio/devices/iio:deviceX/boost_current_gain_available
+KernelVersion:	6.4
+Contact:	[email protected]
+Description:
+		Reading returns a list with the possible gain values for
+		the current biasing circuit of the Delta-Sigma modulator.
+
+What:		/sys/bus/iio/devices/iio:deviceX/auto_zeroing_mux_enable
+KernelVersion:	6.4
+Contact:	[email protected]
+Description:
+		This attribute is used to enable the analog input multiplexer
+		auto-zeroing algorithm (the input multiplexer and the ADC
+		include an offset cancellation algorithm that cancels the offset
+		contribution of the ADC). When the offset cancellation algorithm
+		is enabled, ADC takes two conversions, one with the differential
+		input as VIN+/VIN-, one with VIN+/VIN- inverted. In this case the
+		conversion time is multiplied by two compared to the default
+		case where the algorithm is disabled. This technique allows the
+		cancellation of the ADC offset error and the achievement of
+		ultra-low offset without any digital calibration. The resulting
+		offset is the residue of the difference between the two
+		conversions, which is on the order of magnitude of the noise
+		floor. This offset is effectively canceled at every conversion,
+		so the residual offset error temperature drift is extremely low.
+		Write '1' to enable it, write '0' to disable it.
+
+What:		/sys/bus/iio/devices/iio:deviceX/auto_zeroing_ref_enable
+KernelVersion:	6.4
+Contact:	[email protected]
+Description:
+		This attribute is used to enable the chopping algorithm for the 
+		internal voltage reference buffer. This setting has no effect
+		when external voltage reference is selected.
+		Internal voltage reference buffer injects a certain quantity of
+		1/f noise into the system that can be modulated with the
+		incoming input signals and can limit the SNR performance at
+		higher Oversampling Ratio values (over 256). To overcome this
+		limitation, the buffer includes an auto-zeroing algorithm that
+		greatly reduces (cancels out) the 1/f noise and cancels the
+		offset value of the reference buffer. As a result, the SNR of
+		the system is not affected by this 1/f noise component of the
+		reference buffer, even at maximum oversampling ratio values.
+		Write '1' to enable it, write '0' to disable it.
MAINTAINERS +7 -0
index 6969a2962ffe..50c879f85e1e 100644
@@ -13798,6 +13798,13 @@ S:	Supported
 F:	Documentation/devicetree/bindings/regulator/mcp16502-regulator.txt
 F:	drivers/regulator/mcp16502.c
 
+MICROCHIP MCP3564 ADC DRIVER
+M:      Marius Cristea <[email protected]>
+L:      [email protected]
+S:      Supported
+F:      Documentation/devicetree/bindings/iio/adc/microchip,mcp3564.yaml
+F:      drivers/iio/adc/mcp3564.c
+
 MICROCHIP MCP3911 ADC DRIVER
 M:	Marcus Folkesson <[email protected]>
 M:	Kent Gustavsson <[email protected]>
drivers/iio/adc/Kconfig +13 -0
index 53098aca06ea..782bf5eec8ed 100644
@@ -768,6 +768,19 @@ config MCP3422
 	  This driver can also be built as a module. If so, the module will be
 	  called mcp3422.
 
+config MCP3564
+        tristate "Microchip Technology MCP3461/2/4/R, MCP3561/2/4/R driver"
+        depends on SPI
+        depends on IIO
+        help
+          Say yes here to build support for Microchip Technology's MCP3461,
+          MCP3462, MCP3464, MCP3461R, MCP3462R, MCP3464R, MCP3561, MCP3562,
+          MCP3564, MCP3561R, MCP3562R and MCP3564R analog to digital
+          converters.
+
+          This driver can also be built as a module. If so, the module will be
+          called mcp3564.
+
 config MCP3911
 	tristate "Microchip Technology MCP3911 driver"
 	depends on SPI
drivers/iio/adc/Makefile +1 -0
index e07e4a3e6237..91f713af574f 100644
@@ -70,6 +70,7 @@ obj-$(CONFIG_MAX1363) += max1363.o
 obj-$(CONFIG_MAX9611) += max9611.o
 obj-$(CONFIG_MCP320X) += mcp320x.o
 obj-$(CONFIG_MCP3422) += mcp3422.o
+obj-$(CONFIG_MCP3564) += mcp3564.o
 obj-$(CONFIG_MCP3911) += mcp3911.o
 obj-$(CONFIG_MEDIATEK_MT6360_ADC) += mt6360-adc.o
 obj-$(CONFIG_MEDIATEK_MT6370_ADC) += mt6370-adc.o
drivers/iio/adc/mcp3564.c new file +1516 -0

1,516 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#8 lore raw

Re: [PATCH v5 2/2] iio: adc: adding support for MCP3564 ADC

Quoted 9 lines · On Tue, 29 Aug 2023 18:41:33 +0300 <[email protected]> wrote:

From: Marius Cristea <[email protected]>

This is the iio driver for Microchip family of 153.6 ksps, Low-Noise 16/24-Bit Delta-Sigma ADCs with an SPI interface (Microchip's MCP3461, MCP3462, MCP3464, MCP3461R, MCP3462R, MCP3464R, MCP3561, MCP3562, MCP3564, MCP3561R, MCP3562R and MCP3564R analog to digital converters).

LGTM

Series applied to the togreg branch of iio.git.
Note I'll be rebasing that branch of rc1 once available and in the meantime it will only be visible as testing.

Note there was a trailing space in the docs file. Fixed that up. Thanks,

Jonathan