Skip to contentSkip to conversation

iio: iadc: Qualcomm SPMI PMIC current ADC driver

PATCH Superseded Ivan T. Ivanov 3 participants 10 messages Sep 24, 2014 – Sep 29, 2014

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 iio: iadc: Qualcomm SPMI PMIC current ADC driver

The current ADC is peripheral of Qualcomm SPMI PMIC chips. It has 16 bits resolution and register space inside PMIC accessible across SPMI bus.

The driver registers itself through IIO interface.

---
Changes:
- Fix Kconfig dependencies
- Reword Kconfig help text
- Replace IIO_CHAN_INFO_PROCESSED with IIO_CHAN_INFO_RAW and IIO_CHAN_INFO_SCALE, This enable client drivers to use microampers precission, instead miliamps.
- Use const array for iio_schan_spec-fiers.
- Fix spelling errors and adress review comments.

Previous version:
https://www.mail-archive.com/[email protected]/msg728360.html

 .../devicetree/bindings/iio/adc/qcom,spmi-iadc.txt |  61 ++
 drivers/iio/adc/Kconfig                            |  11 +
 drivers/iio/adc/Makefile                           |   1 +
 drivers/iio/adc/qcom-spmi-iadc.c                   | 691 +++++++++++++++++++++
 4 files changed, 764 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt
 create mode 100644 drivers/iio/adc/qcom-spmi-iadc.c
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +61 -0
new file mode 100644
index 0000000..06e58b6
@@ -0,0 +1,61 @@
+Qualcomm's SPMI PMIC current ADC
+
+QPNP PMIC current ADC (IADC) provides interface to clients to read current.
+A 16 bit ADC is used for current measurements.
+
+IADC node:
+
+- compatible:
+    Usage: required
+    Value type: <string>
+    Definition: Should contain "qcom,spmi-iadc".
+
+- reg:
+    Usage: required
+    Value type: <prop-encoded-array>
+    Definition: IADC base address and length in the SPMI PMIC register map.
+                TRIM_CNST_RDS register address and length(1)
+
+- interrupts:
+    Usage: optional
+    Value type: <prop-encoded-array>
+    Definition: End of conversion interrupt number. If property is
+            missing driver will use polling to detect end of conversion
+            completion.
+
+- qcom,rsense:
+    Usage: optional
+    Value type: <u32>
+    Definition: External sense register value in Ohm. Defining this
+            propery will instruct ADC to use external ADC sense channel.
+            If property is not defined ADC will use internal sense channel.
+
+- qcom,rds-trim:
+    Usage: optional
+    Value type: <u32>
+    Definition: Calculate internal sense resistor value based TRIM_CNST_RDS,
+            IADC RDS and manufacturer.
+            0: Read the IADC and SMBB trim register and apply the default
+               RSENSE if conditions are met.
+            1: Read the IADC, SMBB trim register and manufacturer type and
+               apply the default RSENSE if conditions are met.
+            2: Read the IADC, SMBB trim register and apply the default RSENSE
+               if conditions are met.
+            If property is not defined driver will use qcom,rsense value if
+            defined or internal sense resistor value trimmed into register.
+
+Example:
+	/* IADC node */
+	pmic_iadc: iadc@3600 {
+		compatible = "qcom,spmi-iadc";
+		reg = <0x3600 0x100>,
+			  <0x12f1 0x1>;
+		interrupts = <0x0 0x36 0x0 IRQ_TYPE_EDGE_RISING>;
+		qcom,rds-trim = <0>;
+	};
+
+	/* IIO client node */
+	bat {
+		io-channels = <&pmic_iadc 0>;
+		io-channel-names = "iadc";
+	};
drivers/iio/adc/Kconfig +11 -0
index 11b048a..ee1ad5b 100644
@@ -206,6 +206,17 @@ config NAU7802
 	  To compile this driver as a module, choose M here: the
 	  module will be called nau7802.
 
+config QCOM_SPMI_IADC
+	tristate "Qualcomm SPMI PMIC current ADC"
+	depends on SPMI
+	select REGMAP_SPMI
+	help
+	  This is the IIO Current ADC driver for Qualcomm QPNP IADC Chip.
+
+	  The driver supports single mode operation to read from one of two
+	  channels (external or internal). Hardware have additional
+	  channels internally used for gain and offset calibration.
+
 config TI_ADC081C
 	tristate "Texas Instruments ADC081C021/027"
 	depends on I2C
drivers/iio/adc/Makefile +1 -0
index ad81b51..c790543 100644
@@ -30,3 +30,4 @@ obj-$(CONFIG_VF610_ADC) += vf610_adc.o
 obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o
 xilinx-xadc-y := xilinx-xadc-core.o xilinx-xadc-events.o
 obj-$(CONFIG_XILINX_XADC) += xilinx-xadc.o
+obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o
drivers/iio/adc/qcom-spmi-iadc.c new file +691 -0

691 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw
Quoted 40 lines · Ivan T. Ivanov

The current ADC is peripheral of Qualcomm SPMI PMIC chips. It has 16 bits resolution and register space inside PMIC accessible across SPMI bus.

The driver registers itself through IIO interface.

---
Changes:
- Fix Kconfig dependencies
- Reword Kconfig help text
- Replace IIO_CHAN_INFO_PROCESSED with IIO_CHAN_INFO_RAW and IIO_CHAN_INFO_SCALE, This enable client drivers to use microampers precission, instead miliamps.
- Use const array for iio_schan_spec-fiers.
- Fix spelling errors and adress review comments.

Previous version:
https://www.mail-archive.com/[email protected]/msg728360.html

 .../devicetree/bindings/iio/adc/qcom,spmi-iadc.txt |  61 ++
 drivers/iio/adc/Kconfig                            |  11 +
 drivers/iio/adc/Makefile                           |   1 +
 drivers/iio/adc/qcom-spmi-iadc.c                   | 691 +++++++++++++++++++++
 4 files changed, 764 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt
 create mode 100644 drivers/iio/adc/qcom-spmi-iadc.c
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +7 -0
new file mode 100644
index 0000000..06e58b6
@@ -0,0 +1,61 @@
+Qualcomm's SPMI PMIC current ADC
+
+QPNP PMIC current ADC (IADC) provides interface to clients to read current.
+A 16 bit ADC is used for current measurements.
+
+IADC node:
+

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 17

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +10 -0
+- compatible:
+    Usage: required
+    Value type: <string>
+    Definition: Should contain "qcom,spmi-iadc".
+
+- reg:
+    Usage: required
+    Value type: <prop-encoded-array>
+    Definition: IADC base address and length in the SPMI PMIC register map.
+                TRIM_CNST_RDS register address and length(1)

Are these two register regions? Please make the order explicit somehow (either say first/second/third/etc, or use reg-names).

Are they both part of the IADC, or is one part of an external/shared component?

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 24

Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +7 -0
+
+- interrupts:
+    Usage: optional
+    Value type: <prop-encoded-array>
+    Definition: End of conversion interrupt number. If property is
+            missing driver will use polling to detect end of conversion
+            completion.

Driver details shouldn't be in the binding. If the driver can poll, that's good, but it should be dropped form this description.

Is this the only interrupt?

What do you mean be "End of conversion interrupt number"? Just describe what the interrupt logically is from the PoV of the device -- interrupts is a standard property so we don't need to be too explicit about the type.

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 31

Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +7 -0
+
+- qcom,rsense:
+    Usage: optional
+    Value type: <u32>
+    Definition: External sense register value in Ohm. Defining this
+            propery will instruct ADC to use external ADC sense channel.
+            If property is not defined ADC will use internal sense channel.

The latter two sentences sound like a driver description.

What exactly is the difference between the internal and external channels, and what exactly is the value in the sense register used for?

The binding should describe the logical properties of the device rather than the specific programming model details.

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +4 -0
+
+- qcom,rds-trim:
+    Usage: optional
+    Value type: <u32>

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 45

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +10 -0
+    Definition: Calculate internal sense resistor value based TRIM_CNST_RDS,
+            IADC RDS and manufacturer.
+            0: Read the IADC and SMBB trim register and apply the default
+               RSENSE if conditions are met.
+            1: Read the IADC, SMBB trim register and manufacturer type and
+               apply the default RSENSE if conditions are met.
+            2: Read the IADC, SMBB trim register and apply the default RSENSE
+               if conditions are met.
+            If property is not defined driver will use qcom,rsense value if
+            defined or internal sense resistor value trimmed into register.

Having read this a few times, I still don't understand which I would use and when.

Which conditions need to be met in each of these cases?

When does the manufacturer need to be taken into account and what does it even mean for that to be the case? That sounds very much like a driver detail rather than a HW property.

Cases 0 and 2 seem to be the same, just with s/, / and /. I cannot figure out the intended difference between the two.

The last sentence is very much a driver description.

Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +6 -0
+
+Example:
+       /* IADC node */
+       pmic_iadc: iadc@3600 {
+               compatible = "qcom,spmi-iadc";
+               reg = <0x3600 0x100>,

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 61

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +10 -0
+                         <0x12f1 0x1>;
+               interrupts = <0x0 0x36 0x0 IRQ_TYPE_EDGE_RISING>;
+               qcom,rds-trim = <0>;
+       };
+
+       /* IIO client node */
+       bat {
+               io-channels = <&pmic_iadc 0>;
+               io-channel-names = "iadc";
+       };

Surely you need #iio-cells on the IADC node?

Given the client seems to pass a specifier value, does this have multiple channels, or only a single channel?

Mark.

#2 lore raw
Quoted 46 lines · Mark Rutland
Quoted 45 lines · Ivan T. Ivanov

The current ADC is peripheral of Qualcomm SPMI PMIC chips. It has 16 bits resolution and register space inside PMIC accessible across SPMI bus.

The driver registers itself through IIO interface.

---
Changes:
- Fix Kconfig dependencies
- Reword Kconfig help text
- Replace IIO_CHAN_INFO_PROCESSED with IIO_CHAN_INFO_RAW and IIO_CHAN_INFO_SCALE, This enable client drivers to use microampers precission, instead miliamps.
- Use const array for iio_schan_spec-fiers.
- Fix spelling errors and adress review comments.

Previous version:
https://www.mail-archive.com/[email protected]/msg728360.html

 .../devicetree/bindings/iio/adc/qcom,spmi-iadc.txt |  61 ++
 drivers/iio/adc/Kconfig                            |  11 +
 drivers/iio/adc/Makefile                           |   1 +
 drivers/iio/adc/qcom-spmi-iadc.c                   | 691 +++++++++++++++++++++
 4 files changed, 764 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt
 create mode 100644 drivers/iio/adc/qcom-spmi-iadc.c
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +12 -0
new file mode 100644
index 0000000..06e58b6
@@ -0,0 +1,61 @@
+Qualcomm's SPMI PMIC current ADC
+
+QPNP PMIC current ADC (IADC) provides interface to clients to read current.
+A 16 bit ADC is used for current measurements.
+
+IADC node:
+
+- compatible:
+    Usage: required
+    Value type: <string>
+    Definition: Should contain "qcom,spmi-iadc".
+
Quoted 8 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 17

Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +5 -0
+- reg:
+    Usage: required
+    Value type: <prop-encoded-array>
+    Definition: IADC base address and length in the SPMI PMIC register map.
+                TRIM_CNST_RDS register address and length(1)

Are these two register regions? Please make the order explicit somehow (either say first/second/third/etc, or use reg-names).

Will make order explicit.

Quoted 3 lines

Are they both part of the IADC, or is one part of an external/shared component?

I think that this is shared component.

Quoted 9 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 24

Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +7 -0
+
+- interrupts:
+    Usage: optional
+    Value type: <prop-encoded-array>
+    Definition: End of conversion interrupt number. If property is
+            missing driver will use polling to detect end of conversion
+            completion.
Quoted 3 lines

Driver details shouldn't be in the binding. If the driver can poll, that's good, but it should be dropped form this description.

Will remove driver details.

Quoted 2 lines

Is this the only interrupt?

Yes.

Quoted 4 lines

What do you mean be "End of conversion interrupt number"? Just describe what the interrupt logically is from the PoV of the device -- interrupts is a standard property so we don't need to be too explicit about the type.

Badly worded. Just, "End of conversion interrupt"?

Quoted 9 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 31

Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +7 -0
+
+- qcom,rsense:
+    Usage: optional
+    Value type: <u32>
+    Definition: External sense register value in Ohm. Defining this
+            propery will instruct ADC to use external ADC sense channel.
+            If property is not defined ADC will use internal sense channel.
Quoted 4 lines

The latter two sentences sound like a driver description.

What exactly is the difference between the internal and external channels, and what exactly is the value in the sense register used for?

Internal - when using chip build-in resistor
External - when using off-chip resistor

Quoted 24 lines

The binding should describe the logical properties of the device rather than the specific programming model details.

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +4 -0
+
+- qcom,rds-trim:
+    Usage: optional
+    Value type: <u32>

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 45

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +10 -0
+    Definition: Calculate internal sense resistor value based TRIM_CNST_RDS,
+            IADC RDS and manufacturer.
+            0: Read the IADC and SMBB trim register and apply the default
+               RSENSE if conditions are met.
+            1: Read the IADC, SMBB trim register and manufacturer type and
+               apply the default RSENSE if conditions are met.
+            2: Read the IADC, SMBB trim register and apply the default RSENSE
+               if conditions are met.
+            If property is not defined driver will use qcom,rsense value if
+            defined or internal sense resistor value trimmed into register.

Having read this a few times, I still don't understand which I would use and when.

Which conditions need to be met in each of these cases?

Quoted 8 lines

When does the manufacturer need to be taken into account and what does it even mean for that to be the case? That sounds very much like a driver detail rather than a HW property.

Cases 0 and 2 seem to be the same, just with s/, / and /. I cannot figure out the intended difference between the two.

The last sentence is very much a driver description.

Sorry. I have tried to make it better. Now looking again DT files in codeaurora tree I see that 0 is used in pm8941, 1 is used in pm8110 and 2 is used for pm8226. So I will remove this property and handle this inside driver based on chip version.

Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +10 -0
+
+Example:
+       /* IADC node */
+       pmic_iadc: iadc@3600 {
+               compatible = "qcom,spmi-iadc";
+               reg = <0x3600 0x100>,
+                         <0x12f1 0x1>;
+               interrupts = <0x0 0x36 0x0 IRQ_TYPE_EDGE_RISING>;
+               qcom,rds-trim = <0>;
+       };
Quoted 8 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 61

Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +6 -0
+
+       /* IIO client node */
+       bat {
+               io-channels = <&pmic_iadc 0>;
+               io-channel-names = "iadc";
+       };

Surely you need #iio-cells on the IADC node?

Yes, I need to add it.

Quoted 3 lines

Given the client seems to pass a specifier value, does this have multiple channels, or only a single channel?

Driver register only one IIO channel, so #io-channel-cells should be <0>.

Thank you for the comments.

Regards,
Ivan

#3 lore raw
Quoted 56 lines · Ivan T. Ivanov
Quoted 46 lines · Mark Rutland
Quoted 45 lines · Ivan T. Ivanov

The current ADC is peripheral of Qualcomm SPMI PMIC chips. It has 16 bits resolution and register space inside PMIC accessible across SPMI bus.

The driver registers itself through IIO interface.

---
Changes:
- Fix Kconfig dependencies
- Reword Kconfig help text
- Replace IIO_CHAN_INFO_PROCESSED with IIO_CHAN_INFO_RAW and IIO_CHAN_INFO_SCALE, This enable client drivers to use microampers precission, instead miliamps.
- Use const array for iio_schan_spec-fiers.
- Fix spelling errors and adress review comments.

Previous version:
https://www.mail-archive.com/[email protected]/msg728360.html

 .../devicetree/bindings/iio/adc/qcom,spmi-iadc.txt |  61 ++
 drivers/iio/adc/Kconfig                            |  11 +
 drivers/iio/adc/Makefile                           |   1 +
 drivers/iio/adc/qcom-spmi-iadc.c                   | 691 +++++++++++++++++++++
 4 files changed, 764 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt
 create mode 100644 drivers/iio/adc/qcom-spmi-iadc.c
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +12 -0
new file mode 100644
index 0000000..06e58b6
@@ -0,0 +1,61 @@
+Qualcomm's SPMI PMIC current ADC
+
+QPNP PMIC current ADC (IADC) provides interface to clients to read current.
+A 16 bit ADC is used for current measurements.
+
+IADC node:
+
+- compatible:
+    Usage: required
+    Value type: <string>
+    Definition: Should contain "qcom,spmi-iadc".
+
Quoted 8 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 17

Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +5 -0
+- reg:
+    Usage: required
+    Value type: <prop-encoded-array>
+    Definition: IADC base address and length in the SPMI PMIC register map.
+                TRIM_CNST_RDS register address and length(1)

Are these two register regions? Please make the order explicit somehow (either say first/second/third/etc, or use reg-names).

Quoted 7 lines

Will make order explicit.

Quoted 3 lines

Are they both part of the IADC, or is one part of an external/shared component?

I think that this is shared component.

If it's not a portion of the ADC itself, then that should probably be described as a separate unit, and referred to by phandle. What else is that unit, and what else is said unit used by?

Quoted 19 lines
Quoted 10 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 24

Quoted 9 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +7 -0
+
+- interrupts:
+    Usage: optional
+    Value type: <prop-encoded-array>
+    Definition: End of conversion interrupt number. If property is
+            missing driver will use polling to detect end of conversion
+            completion.
Quoted 3 lines

Driver details shouldn't be in the binding. If the driver can poll, that's good, but it should be dropped form this description.

Will remove driver details.

Quoted 2 lines

Is this the only interrupt?

Quoted 8 lines

Yes.

Quoted 4 lines

What do you mean be "End of conversion interrupt number"? Just describe what the interrupt logically is from the PoV of the device -- interrupts is a standard property so we don't need to be too explicit about the type.

Badly worded. Just, "End of conversion interrupt"?

The part I didn't understand was what was meant by "End of conversion", but dropping "number" is certainly better.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +7 -0
+
+- qcom,rsense:
+    Usage: optional
+    Value type: <u32>
+    Definition: External sense register value in Ohm. Defining this
+            propery will instruct ADC to use external ADC sense channel.
+            If property is not defined ADC will use internal sense channel.
Quoted 7 lines
Quoted 4 lines

The latter two sentences sound like a driver description.

What exactly is the difference between the internal and external channels, and what exactly is the value in the sense register used for?

Internal - when using chip build-in resistor
External - when using off-chip resistor

Would it be possible to use the internal channel when you have an external resistor?

If so, does the device have a channel per resistor, or can either resistor be selected and applied to the single channel the device has?

This might be better worded as "external-registor-ohms".

Quoted 32 lines
Quoted 32 lines

The binding should describe the logical properties of the device rather than the specific programming model details.

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +4 -0
+
+- qcom,rds-trim:
+    Usage: optional
+    Value type: <u32>

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 45

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +10 -0
+    Definition: Calculate internal sense resistor value based TRIM_CNST_RDS,
+            IADC RDS and manufacturer.
+            0: Read the IADC and SMBB trim register and apply the default
+               RSENSE if conditions are met.
+            1: Read the IADC, SMBB trim register and manufacturer type and
+               apply the default RSENSE if conditions are met.
+            2: Read the IADC, SMBB trim register and apply the default RSENSE
+               if conditions are met.
+            If property is not defined driver will use qcom,rsense value if
+            defined or internal sense resistor value trimmed into register.

Having read this a few times, I still don't understand which I would use and when.

Which conditions need to be met in each of these cases?

When does the manufacturer need to be taken into account and what does it even mean for that to be the case? That sounds very much like a driver detail rather than a HW property.

Cases 0 and 2 seem to be the same, just with s/, / and /. I cannot figure out the intended difference between the two.

Quoted 6 lines
Quoted 1 line

The last sentence is very much a driver description.

Sorry. I have tried to make it better. Now looking again DT files in codeaurora tree I see that 0 is used in pm8941, 1 is used in pm8110 and 2 is used for pm8226. So I will remove this property and handle this inside driver based on chip version.

Is this only to determine the value of the internal resistor?

If that isn't probable in a standard way across all variations, would an "internal-resistor-ohms" property be sufficient?

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +10 -0
+
+Example:
+       /* IADC node */
+       pmic_iadc: iadc@3600 {
+               compatible = "qcom,spmi-iadc";
+               reg = <0x3600 0x100>,
+                         <0x12f1 0x1>;
+               interrupts = <0x0 0x36 0x0 IRQ_TYPE_EDGE_RISING>;
+               qcom,rds-trim = <0>;
+       };
Quoted 8 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 61

Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +6 -0
+
+       /* IIO client node */
+       bat {
+               io-channels = <&pmic_iadc 0>;
+               io-channel-names = "iadc";
+       };

Surely you need #iio-cells on the IADC node?

Quoted 8 lines

Yes, I need to add it.

Quoted 3 lines

Given the client seems to pass a specifier value, does this have multiple channels, or only a single channel?

Driver register only one IIO channel, so #io-channel-cells should be <0>.

Ok. Regardless of what the driver does, does the hardware have multi-channel capability?

Thanks,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +7 -0
+
+- qcom,rsense:
+    Usage: optional
+    Value type: <u32>
+    Definition: External sense register value in Ohm. Defining this
+            propery will instruct ADC to use external ADC sense channel.
+            If property is not defined ADC will use internal sense channel.
Quoted 7 lines
Quoted 4 lines

The latter two sentences sound like a driver description.

What exactly is the difference between the internal and external channels, and what exactly is the value in the sense register used for?

Internal - when using chip build-in resistor
External - when using off-chip resistor

Quoted 7 lines

Would it be possible to use the internal channel when you have an external resistor?

If so, does the device have a channel per resistor, or can either resistor be selected and applied to the single channel the device has?

This might be better worded as "external-registor-ohms".

I meant to say "external-resistor-ohms".

Muscle memory and lack of coffee got the better of me.

Mark.

#5 lore raw
In reply to Mark Rutland

Hi Mark,

Quoted 60 lines · Mark Rutland
Quoted 59 lines · Ivan T. Ivanov
Quoted 46 lines · Mark Rutland
Quoted 45 lines · Ivan T. Ivanov

The current ADC is peripheral of Qualcomm SPMI PMIC chips. It has 16 bits resolution and register space inside PMIC accessible across SPMI bus.

The driver registers itself through IIO interface.

---
Changes:
- Fix Kconfig dependencies
- Reword Kconfig help text
- Replace IIO_CHAN_INFO_PROCESSED with IIO_CHAN_INFO_RAW and IIO_CHAN_INFO_SCALE, This enable client drivers to use microampers precission, instead miliamps.
- Use const array for iio_schan_spec-fiers.
- Fix spelling errors and adress review comments.

Previous version:
https://www.mail-archive.com/[email protected]/msg728360.html

 .../devicetree/bindings/iio/adc/qcom,spmi-iadc.txt |  61 ++
 drivers/iio/adc/Kconfig                            |  11 +
 drivers/iio/adc/Makefile                           |   1 +
 drivers/iio/adc/qcom-spmi-iadc.c                   | 691 +++++++++++++++++++++
 4 files changed, 764 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt
 create mode 100644 drivers/iio/adc/qcom-spmi-iadc.c
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +12 -0
new file mode 100644
index 0000000..06e58b6
@@ -0,0 +1,61 @@
+Qualcomm's SPMI PMIC current ADC
+
+QPNP PMIC current ADC (IADC) provides interface to clients to read current.
+A 16 bit ADC is used for current measurements.
+
+IADC node:
+
+- compatible:
+    Usage: required
+    Value type: <string>
+    Definition: Should contain "qcom,spmi-iadc".
+
Quoted 8 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 17

Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +5 -0
+- reg:
+    Usage: required
+    Value type: <prop-encoded-array>
+    Definition: IADC base address and length in the SPMI PMIC register map.
+                TRIM_CNST_RDS register address and length(1)

Are these two register regions? Please make the order explicit somehow (either say first/second/third/etc, or use reg-names).

Will make order explicit.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Are they both part of the IADC, or is one part of an external/shared component?

I think that this is shared component.

If it's not a portion of the ADC itself, then that should probably be described as a separate unit, and referred to by phandle. What else is that unit, and what else is said unit used by?

Please read below.

Quoted 27 lines
Quoted 27 lines
Quoted 11 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 24

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +7 -0
+
+- interrupts:
+    Usage: optional
+    Value type: <prop-encoded-array>
+    Definition: End of conversion interrupt number. If property is
+            missing driver will use polling to detect end of conversion
+            completion.
Quoted 3 lines

Driver details shouldn't be in the binding. If the driver can poll, that's good, but it should be dropped form this description.

Will remove driver details.

Quoted 2 lines

Is this the only interrupt?

Yes.

Quoted 4 lines

What do you mean be "End of conversion interrupt number"? Just describe what the interrupt logically is from the PoV of the device -- interrupts is a standard property so we don't need to be too explicit about the type.

Quoted 4 lines
Quoted 1 line

Badly worded. Just, "End of conversion interrupt"?

The part I didn't understand was what was meant by "End of conversion", but dropping "number" is certainly better.

It is clear now, right? End of ADC conversion.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 31

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +7 -0
+
+- qcom,rsense:
+    Usage: optional
+    Value type: <u32>
+    Definition: External sense register value in Ohm. Defining this
+            propery will instruct ADC to use external ADC sense channel.
+            If property is not defined ADC will use internal sense channel.

The latter two sentences sound like a driver description.

What exactly is the difference between the internal and external channels, and what exactly is the value in the sense register used for?

Quoted 9 lines
Quoted 2 lines

Internal - when using chip build-in resistor
External - when using off-chip resistor

Would it be possible to use the internal channel when you have an external resistor?

If so, does the device have a channel per resistor, or can either resistor be selected and applied to the single channel the device has?

They are two dedicated channels. Channel zero can only measure current over internal resistor (MOSFET). Channel two can only measure current over external resistor. This ADC is part of Battery Monitor System (BMS), i.e. it is not general purpose ADC. Based on DT files in codeaurora repository, only one of the channels is used, probably chosen at schematics design time. In practice, on the systems that use battery, there is always two resistors, and they are connected in sequence, just one of them should be zero. External resistor could be with higher quality, I suppose.

Quoted 1 line

This might be better worded as "external-registor-ohms".

Ok.

Quoted 33 lines
Quoted 33 lines
Quoted 33 lines

The binding should describe the logical properties of the device rather than the specific programming model details.

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +4 -0
+
+- qcom,rds-trim:
+    Usage: optional
+    Value type: <u32>

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 45

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +10 -0
+    Definition: Calculate internal sense resistor value based TRIM_CNST_RDS,
+            IADC RDS and manufacturer.
+            0: Read the IADC and SMBB trim register and apply the default
+               RSENSE if conditions are met.
+            1: Read the IADC, SMBB trim register and manufacturer type and
+               apply the default RSENSE if conditions are met.
+            2: Read the IADC, SMBB trim register and apply the default RSENSE
+               if conditions are met.
+            If property is not defined driver will use qcom,rsense value if
+            defined or internal sense resistor value trimmed into register.

Having read this a few times, I still don't understand which I would use and when.

Which conditions need to be met in each of these cases?

When does the manufacturer need to be taken into account and what does it even mean for that to be the case? That sounds very much like a driver detail rather than a HW property.

Cases 0 and 2 seem to be the same, just with s/, / and /. I cannot figure out the intended difference between the two.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

The last sentence is very much a driver description.

Sorry. I have tried to make it better. Now looking again DT files in codeaurora tree I see that 0 is used in pm8941, 1 is used in pm8110 and 2 is used for pm8226. So I will remove this property and handle this inside driver based on chip version.

Is this only to determine the value of the internal resistor?

No. Ideal value for internal resistor is supposed to be 10Mohms. One register(8 bits) hold production time trimmed value, which represent difference against ideal value. It looks like some times real resistor values is too far from ideal and register can't hold the difference, so some additional hints are needed. In this case value trimmed to register into BMS peripheral.

Quoted 28 lines

If that isn't probable in a standard way across all variations, would an "internal-resistor-ohms" property be sufficient?

Quoted 24 lines
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +10 -0
+
+Example:
+       /* IADC node */
+       pmic_iadc: iadc@3600 {
+               compatible = "qcom,spmi-iadc";
+               reg = <0x3600 0x100>,
+                         <0x12f1 0x1>;
+               interrupts = <0x0 0x36 0x0 IRQ_TYPE_EDGE_RISING>;
+               qcom,rds-trim = <0>;
+       };
Quoted 8 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 61

Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +6 -0
+
+       /* IIO client node */
+       bat {
+               io-channels = <&pmic_iadc 0>;
+               io-channel-names = "iadc";
+       };

Surely you need #iio-cells on the IADC node?

Yes, I need to add it.

Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Given the client seems to pass a specifier value, does this have multiple channels, or only a single channel?

Driver register only one IIO channel, so #io-channel-cells should be <0>.

Ok. Regardless of what the driver does, does the hardware have multi-channel capability?

Strictly speaking, yes. But I don't see how both of them could used at the same time in practice.

Regards,
Ivan

#6 lore raw
Quoted 68 lines · Ivan T. Ivanov

Hi Mark,

Quoted 65 lines · Mark Rutland
Quoted 63 lines · Ivan T. Ivanov
Quoted 46 lines · Mark Rutland
Quoted 45 lines · Ivan T. Ivanov

The current ADC is peripheral of Qualcomm SPMI PMIC chips. It has 16 bits resolution and register space inside PMIC accessible across SPMI bus.

The driver registers itself through IIO interface.

---
Changes:
- Fix Kconfig dependencies
- Reword Kconfig help text
- Replace IIO_CHAN_INFO_PROCESSED with IIO_CHAN_INFO_RAW and IIO_CHAN_INFO_SCALE, This enable client drivers to use microampers precission, instead miliamps.
- Use const array for iio_schan_spec-fiers.
- Fix spelling errors and adress review comments.

Previous version:
https://www.mail-archive.com/[email protected]/msg728360.html

 .../devicetree/bindings/iio/adc/qcom,spmi-iadc.txt |  61 ++
 drivers/iio/adc/Kconfig                            |  11 +
 drivers/iio/adc/Makefile                           |   1 +
 drivers/iio/adc/qcom-spmi-iadc.c                   | 691 +++++++++++++++++++++
 4 files changed, 764 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt
 create mode 100644 drivers/iio/adc/qcom-spmi-iadc.c
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +12 -0
new file mode 100644
index 0000000..06e58b6
@@ -0,0 +1,61 @@
+Qualcomm's SPMI PMIC current ADC
+
+QPNP PMIC current ADC (IADC) provides interface to clients to read current.
+A 16 bit ADC is used for current measurements.
+
+IADC node:
+
+- compatible:
+    Usage: required
+    Value type: <string>
+    Definition: Should contain "qcom,spmi-iadc".
+
Quoted 8 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 17

Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +5 -0
+- reg:
+    Usage: required
+    Value type: <prop-encoded-array>
+    Definition: IADC base address and length in the SPMI PMIC register map.
+                TRIM_CNST_RDS register address and length(1)

Are these two register regions? Please make the order explicit somehow (either say first/second/third/etc, or use reg-names).

Will make order explicit.

Quoted 3 lines

Are they both part of the IADC, or is one part of an external/shared component?

I think that this is shared component.

Quoted 7 lines
Quoted 3 lines

If it's not a portion of the ADC itself, then that should probably be described as a separate unit, and referred to by phandle. What else is that unit, and what else is said unit used by?

Please read below.

From my reading of the below, it's not clear we even need the TRIM

register values. If we do, and that's in a separate peripheral, that register region should not be described directly in the IADC node. We should have a reference to the other peripheral.

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 10 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 24

Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +6 -0
+- interrupts:
+    Usage: optional
+    Value type: <prop-encoded-array>
+    Definition: End of conversion interrupt number. If property is
+            missing driver will use polling to detect end of conversion
+            completion.

Driver details shouldn't be in the binding. If the driver can poll, that's good, but it should be dropped form this description.

Will remove driver details.

Quoted 2 lines

Is this the only interrupt?

Yes.

Quoted 4 lines

What do you mean be "End of conversion interrupt number"? Just describe what the interrupt logically is from the PoV of the device -- interrupts is a standard property so we don't need to be too explicit about the type.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Badly worded. Just, "End of conversion interrupt"?

The part I didn't understand was what was meant by "End of conversion", but dropping "number" is certainly better.

It is clear now, right? End of ADC conversion.

Sorry if I'm being thick here, but it's still somewhat confusing to me. That's a consequence of me not being familiar with the HW more than anything, I'm just missing simple details regarding the model of operation, suchs as exactly what the "end of ADC conversion" entails. There are a few things that could potentially mean depending on how the HW was designed and intended to be used.

Does the device periodically sample, convert some number of values (possibly just 1), and trigger an interrupt to state that a buffer is full / values are available? Or is the interrupt triggered for some other reason?

Quoted 22 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 31

Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +6 -0
+- qcom,rsense:
+    Usage: optional
+    Value type: <u32>
+    Definition: External sense register value in Ohm. Defining this
+            propery will instruct ADC to use external ADC sense channel.
+            If property is not defined ADC will use internal sense channel.

The latter two sentences sound like a driver description.

What exactly is the difference between the internal and external channels, and what exactly is the value in the sense register used for?

Quoted 9 lines
Quoted 2 lines

Internal - when using chip build-in resistor
External - when using off-chip resistor

Would it be possible to use the internal channel when you have an external resistor?

If so, does the device have a channel per resistor, or can either resistor be selected and applied to the single channel the device has?

Quoted 9 lines

They are two dedicated channels. Channel zero can only measure current over internal resistor (MOSFET). Channel two can only measure current over external resistor. This ADC is part of Battery Monitor System (BMS), i.e. it is not general purpose ADC. Based on DT files in codeaurora repository, only one of the channels is used, probably chosen at schematics design time. In practice, on the systems that use battery, there is always two resistors, and they are connected in sequence, just one of them should be zero. External resistor could be with higher quality, I suppose.

I see. So there are two channels, but in all instances so far only one is wired up to anything?

Quoted 44 lines
Quoted 1 line

This might be better worded as "external-registor-ohms".

Ok.

Quoted 40 lines
Quoted 39 lines
Quoted 26 lines

The binding should describe the logical properties of the device rather than the specific programming model details.

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +4 -0
+
+- qcom,rds-trim:
+    Usage: optional
+    Value type: <u32>

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 45

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +10 -0
+    Definition: Calculate internal sense resistor value based TRIM_CNST_RDS,
+            IADC RDS and manufacturer.
+            0: Read the IADC and SMBB trim register and apply the default
+               RSENSE if conditions are met.
+            1: Read the IADC, SMBB trim register and manufacturer type and
+               apply the default RSENSE if conditions are met.
+            2: Read the IADC, SMBB trim register and apply the default RSENSE
+               if conditions are met.
+            If property is not defined driver will use qcom,rsense value if
+            defined or internal sense resistor value trimmed into register.

Having read this a few times, I still don't understand which I would use and when.

Which conditions need to be met in each of these cases?

Quoted 8 lines

When does the manufacturer need to be taken into account and what does it even mean for that to be the case? That sounds very much like a driver detail rather than a HW property.

Cases 0 and 2 seem to be the same, just with s/, / and /. I cannot figure out the intended difference between the two.

The last sentence is very much a driver description.

Sorry. I have tried to make it better. Now looking again DT files in codeaurora tree I see that 0 is used in pm8941, 1 is used in pm8110 and 2 is used for pm8226. So I will remove this property and handle this inside driver based on chip version.

Quoted 8 lines
Quoted 1 line

Is this only to determine the value of the internal resistor?

No. Ideal value for internal resistor is supposed to be 10Mohms. One register(8 bits) hold production time trimmed value, which represent difference against ideal value. It looks like some times real resistor values is too far from ideal and register can't hold the difference, so some additional hints are needed. In this case value trimmed to register into BMS peripheral.

Ok. So from my PoV, the answer to my question is 'yes'. All that information is used to determine the actual (rather than ideal) value of the internal resistor.

How variable is this value? Does it vary per board, only per SoC version? Would the suggested "internal-resistor-ohms" property be sufficient, or is the value too variable for that to work?

Quoted 30 lines
Quoted 30 lines

If that isn't probable in a standard way across all variations, would an "internal-resistor-ohms" property be sufficient?

Quoted 27 lines
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +10 -0
+
+Example:
+       /* IADC node */
+       pmic_iadc: iadc@3600 {
+               compatible = "qcom,spmi-iadc";
+               reg = <0x3600 0x100>,
+                         <0x12f1 0x1>;
+               interrupts = <0x0 0x36 0x0 IRQ_TYPE_EDGE_RISING>;
+               qcom,rds-trim = <0>;
+       };
Quoted 8 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 61

Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +6 -0
+
+       /* IIO client node */
+       bat {
+               io-channels = <&pmic_iadc 0>;
+               io-channel-names = "iadc";
+       };

Surely you need #iio-cells on the IADC node?

Yes, I need to add it.

Quoted 3 lines

Given the client seems to pass a specifier value, does this have multiple channels, or only a single channel?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Driver register only one IIO channel, so #io-channel-cells should be <0>.

Ok. Regardless of what the driver does, does the hardware have multi-channel capability?

Strictly speaking, yes. But I don't see how both of them could used at the same time in practice.

Even if that is the case, sure we can support #iio-cells = <1> and refer to the channels as you numbered them above (zero for internal, one for external)?

Mark.

#7 lore raw
Quoted 73 lines · Mark Rutland
Quoted 72 lines · Ivan T. Ivanov

Hi Mark,

Quoted 68 lines · Mark Rutland
Quoted 56 lines · Ivan T. Ivanov
Quoted 46 lines · Mark Rutland
Quoted 45 lines · Ivan T. Ivanov

The current ADC is peripheral of Qualcomm SPMI PMIC chips. It has 16 bits resolution and register space inside PMIC accessible across SPMI bus.

The driver registers itself through IIO interface.

---
Changes:
- Fix Kconfig dependencies
- Reword Kconfig help text
- Replace IIO_CHAN_INFO_PROCESSED with IIO_CHAN_INFO_RAW and IIO_CHAN_INFO_SCALE, This enable client drivers to use microampers precission, instead miliamps.
- Use const array for iio_schan_spec-fiers.
- Fix spelling errors and adress review comments.

Previous version:
https://www.mail-archive.com/[email protected]/msg728360.html

 .../devicetree/bindings/iio/adc/qcom,spmi-iadc.txt |  61 ++
 drivers/iio/adc/Kconfig                            |  11 +
 drivers/iio/adc/Makefile                           |   1 +
 drivers/iio/adc/qcom-spmi-iadc.c                   | 691 +++++++++++++++++++++
 4 files changed, 764 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt
 create mode 100644 drivers/iio/adc/qcom-spmi-iadc.c
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +12 -0
new file mode 100644
index 0000000..06e58b6
@@ -0,0 +1,61 @@
+Qualcomm's SPMI PMIC current ADC
+
+QPNP PMIC current ADC (IADC) provides interface to clients to read current.
+A 16 bit ADC is used for current measurements.
+
+IADC node:
+
+- compatible:
+    Usage: required
+    Value type: <string>
+    Definition: Should contain "qcom,spmi-iadc".
+
Quoted 8 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 17

Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +5 -0
+- reg:
+    Usage: required
+    Value type: <prop-encoded-array>
+    Definition: IADC base address and length in the SPMI PMIC register map.
+                TRIM_CNST_RDS register address and length(1)

Are these two register regions? Please make the order explicit somehow (either say first/second/third/etc, or use reg-names).

Quoted 7 lines

Will make order explicit.

Quoted 3 lines

Are they both part of the IADC, or is one part of an external/shared component?

I think that this is shared component.

If it's not a portion of the ADC itself, then that should probably be described as a separate unit, and referred to by phandle. What else is that unit, and what else is said unit used by?

Quoted 6 lines
Quoted 1 line

Please read below.

From my reading of the below, it's not clear we even need the TRIM register values. If we do, and that's in a separate peripheral, that register region should not be described directly in the IADC node. We should have a reference to the other peripheral.

Yes, we need them. Just to clarify, they are two TRIM registers. One is part of the IADC and the other is part of the BMS. If the one in IADC can not accumulate internal resistor deviation we have to read also one in BMS.

Do we have any standard way for such kind inter-device register readings? Just note these devices are sub-functions of the PMIC, which are accessed from SoC over SPMI bus. Address ranges are not ioremmed or claimed by device drivers.

Quoted 38 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 11 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 24

Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +6 -0
+- interrupts:
+    Usage: optional
+    Value type: <prop-encoded-array>
+    Definition: End of conversion interrupt number. If property is
+            missing driver will use polling to detect end of conversion
+            completion.

Driver details shouldn't be in the binding. If the driver can poll, that's good, but it should be dropped form this description.

Will remove driver details.

Quoted 2 lines

Is this the only interrupt?

Yes.

Quoted 4 lines

What do you mean be "End of conversion interrupt number"? Just describe what the interrupt logically is from the PoV of the device -- interrupts is a standard property so we don't need to be too explicit about the type.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Badly worded. Just, "End of conversion interrupt"?

The part I didn't understand was what was meant by "End of conversion", but dropping "number" is certainly better.

It is clear now, right? End of ADC conversion.

Sorry if I'm being thick here, but it's still somewhat confusing to me. That's a consequence of me not being familiar with the HW more than anything, I'm just missing simple details regarding the model of operation, suchs as exactly what the "end of ADC conversion" entails. There are a few things that could potentially mean depending on how the HW was designed and intended to be used.

Quoted 4 lines

Does the device periodically sample, convert some number of values (possibly just 1), and trigger an interrupt to state that a buffer is full / values are available? Or is the interrupt triggered for some other reason?

Interrupt is triggered after ADC convert analog signal to digital. Other details are irrelevant, I believe.

Quoted 33 lines
Quoted 23 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 31

Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +6 -0
+- qcom,rsense:
+    Usage: optional
+    Value type: <u32>
+    Definition: External sense register value in Ohm. Defining this
+            propery will instruct ADC to use external ADC sense channel.
+            If property is not defined ADC will use internal sense channel.

The latter two sentences sound like a driver description.

What exactly is the difference between the internal and external channels, and what exactly is the value in the sense register used for?

Quoted 9 lines
Quoted 2 lines

Internal - when using chip build-in resistor
External - when using off-chip resistor

Would it be possible to use the internal channel when you have an external resistor?

If so, does the device have a channel per resistor, or can either resistor be selected and applied to the single channel the device has?

Quoted 9 lines

They are two dedicated channels. Channel zero can only measure current over internal resistor (MOSFET). Channel two can only measure current over external resistor. This ADC is part of Battery Monitor System (BMS), i.e. it is not general purpose ADC. Based on DT files in codeaurora repository, only one of the channels is used, probably chosen at schematics design time. In practice, on the systems that use battery, there is always two resistors, and they are connected in sequence, just one of them should be zero. External resistor could be with higher quality, I suppose.

Quoted 2 lines

I see. So there are two channels, but in all instances so far only one is wired up to anything?

I will say, Yes :-).

Quoted 54 lines
Quoted 45 lines
Quoted 2 lines

This might be better worded as "external-registor-ohms".

Ok.

Quoted 40 lines
Quoted 39 lines
Quoted 26 lines

The binding should describe the logical properties of the device rather than the specific programming model details.

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +4 -0
+
+- qcom,rds-trim:
+    Usage: optional
+    Value type: <u32>

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 45

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +10 -0
+    Definition: Calculate internal sense resistor value based TRIM_CNST_RDS,
+            IADC RDS and manufacturer.
+            0: Read the IADC and SMBB trim register and apply the default
+               RSENSE if conditions are met.
+            1: Read the IADC, SMBB trim register and manufacturer type and
+               apply the default RSENSE if conditions are met.
+            2: Read the IADC, SMBB trim register and apply the default RSENSE
+               if conditions are met.
+            If property is not defined driver will use qcom,rsense value if
+            defined or internal sense resistor value trimmed into register.

Having read this a few times, I still don't understand which I would use and when.

Which conditions need to be met in each of these cases?

Quoted 8 lines

When does the manufacturer need to be taken into account and what does it even mean for that to be the case? That sounds very much like a driver detail rather than a HW property.

Cases 0 and 2 seem to be the same, just with s/, / and /. I cannot figure out the intended difference between the two.

The last sentence is very much a driver description.

Sorry. I have tried to make it better. Now looking again DT files in codeaurora tree I see that 0 is used in pm8941, 1 is used in pm8110 and 2 is used for pm8226. So I will remove this property and handle this inside driver based on chip version.

Quoted 8 lines
Quoted 1 line

Is this only to determine the value of the internal resistor?

No. Ideal value for internal resistor is supposed to be 10Mohms. One register(8 bits) hold production time trimmed value, which represent difference against ideal value. It looks like some times real resistor values is too far from ideal and register can't hold the difference, so some additional hints are needed. In this case value trimmed to register into BMS peripheral.

Quoted 7 lines

Ok. So from my PoV, the answer to my question is 'yes'. All that information is used to determine the actual (rather than ideal) value of the internal resistor.

How variable is this value? Does it vary per board, only per SoC version? Would the suggested "internal-resistor-ohms" property be sufficient, or is the value too variable for that to work?

It vary, per chip. Note this is PMIC chip accessed from SoC over SPMI bus.

Quoted 37 lines
Quoted 37 lines
Quoted 36 lines

If that isn't probable in a standard way across all variations, would an "internal-resistor-ohms" property be sufficient?

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +10 -0
+
+Example:
+       /* IADC node */
+       pmic_iadc: iadc@3600 {
+               compatible = "qcom,spmi-iadc";
+               reg = <0x3600 0x100>,
+                         <0x12f1 0x1>;
+               interrupts = <0x0 0x36 0x0 IRQ_TYPE_EDGE_RISING>;
+               qcom,rds-trim = <0>;
+       };
Quoted 8 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 61

Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +6 -0
+
+       /* IIO client node */
+       bat {
+               io-channels = <&pmic_iadc 0>;
+               io-channel-names = "iadc";
+       };

Surely you need #iio-cells on the IADC node?

Quoted 8 lines

Yes, I need to add it.

Quoted 3 lines

Given the client seems to pass a specifier value, does this have multiple channels, or only a single channel?

Driver register only one IIO channel, so #io-channel-cells should be <0>.

Ok. Regardless of what the driver does, does the hardware have multi-channel capability?

Quoted 6 lines
Quoted 2 lines

Strictly speaking, yes. But I don't see how both of them could used at the same time in practice.

Even if that is the case, sure we can support #iio-cells = <1> and refer to the channels as you numbered them above (zero for internal, one for external)?

Ok, will rework it.

Thank you,
Ivan

Quoted 2 lines

Mark.

maintainer
#8 lore raw
Quoted 129 lines · Ivan T. Ivanov
Quoted 73 lines · Mark Rutland
Quoted 72 lines · Ivan T. Ivanov

Hi Mark,

Quoted 68 lines · Mark Rutland
Quoted 56 lines · Ivan T. Ivanov
Quoted 46 lines · Mark Rutland
Quoted 45 lines · Ivan T. Ivanov

The current ADC is peripheral of Qualcomm SPMI PMIC chips. It has 16 bits resolution and register space inside PMIC accessible across SPMI bus.

The driver registers itself through IIO interface.

---
Changes:
- Fix Kconfig dependencies
- Reword Kconfig help text
- Replace IIO_CHAN_INFO_PROCESSED with IIO_CHAN_INFO_RAW and IIO_CHAN_INFO_SCALE, This enable client drivers to use microampers precission, instead miliamps.
- Use const array for iio_schan_spec-fiers.
- Fix spelling errors and adress review comments.

Previous version:
https://www.mail-archive.com/[email protected]/msg728360.html

 .../devicetree/bindings/iio/adc/qcom,spmi-iadc.txt |  61 ++
 drivers/iio/adc/Kconfig                            |  11 +
 drivers/iio/adc/Makefile                           |   1 +
 drivers/iio/adc/qcom-spmi-iadc.c                   | 691 +++++++++++++++++++++
 4 files changed, 764 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt
 create mode 100644 drivers/iio/adc/qcom-spmi-iadc.c
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +12 -0
new file mode 100644
index 0000000..06e58b6
@@ -0,0 +1,61 @@
+Qualcomm's SPMI PMIC current ADC
+
+QPNP PMIC current ADC (IADC) provides interface to clients to read current.
+A 16 bit ADC is used for current measurements.
+
+IADC node:
+
+- compatible:
+    Usage: required
+    Value type: <string>
+    Definition: Should contain "qcom,spmi-iadc".
+
Quoted 8 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 17

Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +5 -0
+- reg:
+    Usage: required
+    Value type: <prop-encoded-array>
+    Definition: IADC base address and length in the SPMI PMIC register map.
+                TRIM_CNST_RDS register address and length(1)

Are these two register regions? Please make the order explicit somehow (either say first/second/third/etc, or use reg-names).

Quoted 7 lines

Will make order explicit.

Quoted 3 lines

Are they both part of the IADC, or is one part of an external/shared component?

I think that this is shared component.

If it's not a portion of the ADC itself, then that should probably be described as a separate unit, and referred to by phandle. What else is that unit, and what else is said unit used by?

Quoted 6 lines
Quoted 1 line

Please read below.

From my reading of the below, it's not clear we even need the TRIM register values. If we do, and that's in a separate peripheral, that register region should not be described directly in the IADC node. We should have a reference to the other peripheral.

Yes, we need them. Just to clarify, they are two TRIM registers. One is part of the IADC and the other is part of the BMS. If the one in IADC can not accumulate internal resistor deviation we have to read also one in BMS.

Do we have any standard way for such kind inter-device register readings? Just note these devices are sub-functions of the PMIC, which are accessed from SoC over SPMI bus. Address ranges are not ioremmed or claimed by device drivers.

Quoted 38 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 11 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 23

Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +6 -0
+- interrupts:
+    Usage: optional
+    Value type: <prop-encoded-array>
+    Definition: End of conversion interrupt number. If property is
+            missing driver will use polling to detect end of conversion
+            completion.

Driver details shouldn't be in the binding. If the driver can poll, that's good, but it should be dropped form this description.

Will remove driver details.

Quoted 2 lines

Is this the only interrupt?

Yes.

Quoted 4 lines

What do you mean be "End of conversion interrupt number"? Just describe what the interrupt logically is from the PoV of the device -- interrupts is a standard property so we don't need to be too explicit about the type.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Badly worded. Just, "End of conversion interrupt"?

The part I didn't understand was what was meant by "End of conversion", but dropping "number" is certainly better.

It is clear now, right? End of ADC conversion.

Sorry if I'm being thick here, but it's still somewhat confusing to me. That's a consequence of me not being familiar with the HW more than anything, I'm just missing simple details regarding the model of operation, suchs as exactly what the "end of ADC conversion" entails. There are a few things that could potentially mean depending on how the HW was designed and intended to be used.

Quoted 7 lines
Quoted 4 lines

Does the device periodically sample, convert some number of values (possibly just 1), and trigger an interrupt to state that a buffer is full / values are available? Or is the interrupt triggered for some other reason?

Interrupt is triggered after ADC convert analog signal to digital. Other details are irrelevant, I believe.

Often called a data ready interrupt. However, here it is per channel so perhaps that description is confusing as well...

Quoted 162 lines
Quoted 34 lines
Quoted 24 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 29

Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +6 -0
+- qcom,rsense:
+    Usage: optional
+    Value type: <u32>
+    Definition: External sense register value in Ohm. Defining this
+            propery will instruct ADC to use external ADC sense channel.
+            If property is not defined ADC will use internal sense channel.

The latter two sentences sound like a driver description.

What exactly is the difference between the internal and external channels, and what exactly is the value in the sense register used for?

Quoted 9 lines
Quoted 2 lines

Internal - when using chip build-in resistor
External - when using off-chip resistor

Would it be possible to use the internal channel when you have an external resistor?

If so, does the device have a channel per resistor, or can either resistor be selected and applied to the single channel the device has?

Quoted 9 lines

They are two dedicated channels. Channel zero can only measure current over internal resistor (MOSFET). Channel two can only measure current over external resistor. This ADC is part of Battery Monitor System (BMS), i.e. it is not general purpose ADC. Based on DT files in codeaurora repository, only one of the channels is used, probably chosen at schematics design time. In practice, on the systems that use battery, there is always two resistors, and they are connected in sequence, just one of them should be zero. External resistor could be with higher quality, I suppose.

Quoted 2 lines

I see. So there are two channels, but in all instances so far only one is wired up to anything?

I will say, Yes :-).

Quoted 54 lines
Quoted 45 lines
Quoted 2 lines

This might be better worded as "external-registor-ohms".

Ok.

Quoted 40 lines
Quoted 39 lines
Quoted 26 lines

The binding should describe the logical properties of the device rather than the specific programming model details.

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +4 -0
+
+- qcom,rds-trim:
+    Usage: optional
+    Value type: <u32>

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 43

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +10 -0
+    Definition: Calculate internal sense resistor value based TRIM_CNST_RDS,
+            IADC RDS and manufacturer.
+            0: Read the IADC and SMBB trim register and apply the default
+               RSENSE if conditions are met.
+            1: Read the IADC, SMBB trim register and manufacturer type and
+               apply the default RSENSE if conditions are met.
+            2: Read the IADC, SMBB trim register and apply the default RSENSE
+               if conditions are met.
+            If property is not defined driver will use qcom,rsense value if
+            defined or internal sense resistor value trimmed into register.

Having read this a few times, I still don't understand which I would use and when.

Which conditions need to be met in each of these cases?

Quoted 8 lines

When does the manufacturer need to be taken into account and what does it even mean for that to be the case? That sounds very much like a driver detail rather than a HW property.

Cases 0 and 2 seem to be the same, just with s/, / and /. I cannot figure out the intended difference between the two.

The last sentence is very much a driver description.

Sorry. I have tried to make it better. Now looking again DT files in codeaurora tree I see that 0 is used in pm8941, 1 is used in pm8110 and 2 is used for pm8226. So I will remove this property and handle this inside driver based on chip version.

Quoted 8 lines
Quoted 1 line

Is this only to determine the value of the internal resistor?

No. Ideal value for internal resistor is supposed to be 10Mohms. One register(8 bits) hold production time trimmed value, which represent difference against ideal value. It looks like some times real resistor values is too far from ideal and register can't hold the difference, so some additional hints are needed. In this case value trimmed to register into BMS peripheral.

Quoted 7 lines

Ok. So from my PoV, the answer to my question is 'yes'. All that information is used to determine the actual (rather than ideal) value of the internal resistor.

How variable is this value? Does it vary per board, only per SoC version? Would the suggested "internal-resistor-ohms" property be sufficient, or is the value too variable for that to work?

It vary, per chip. Note this is PMIC chip accessed from SoC over SPMI bus.

Quoted 37 lines
Quoted 37 lines
Quoted 36 lines

If that isn't probable in a standard way across all variations, would an "internal-resistor-ohms" property be sufficient?

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +10 -0
+
+Example:
+       /* IADC node */
+       pmic_iadc: iadc@3600 {
+               compatible = "qcom,spmi-iadc";
+               reg = <0x3600 0x100>,
+                         <0x12f1 0x1>;
+               interrupts = <0x0 0x36 0x0 IRQ_TYPE_EDGE_RISING>;
+               qcom,rds-trim = <0>;
+       };
Quoted 8 lines

Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt line 59

Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt new file +6 -0
+
+       /* IIO client node */
+       bat {
+               io-channels = <&pmic_iadc 0>;
+               io-channel-names = "iadc";
+       };

Surely you need #iio-cells on the IADC node?

Quoted 8 lines

Yes, I need to add it.

Quoted 3 lines

Given the client seems to pass a specifier value, does this have multiple channels, or only a single channel?

Driver register only one IIO channel, so #io-channel-cells should be <0>.

Ok. Regardless of what the driver does, does the hardware have multi-channel capability?

Quoted 6 lines
Quoted 2 lines

Strictly speaking, yes. But I don't see how both of them could used at the same time in practice.

Even if that is the case, sure we can support #iio-cells = <1> and refer to the channels as you numbered them above (zero for internal, one for external)?

Ok, will rework it.

Thank you,
Ivan

Quoted 2 lines

Mark.

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw
Quoted 3 lines · Jonathan Cameron
Quoted 2 lines · Ivan T. Ivanov
Quoted 1 line · Mark Rutland

On Thu, Sep 25, 2014 at 10:47:15AM +0100, Ivan T. Ivanov wrote:

<snip>

Quoted 43 lines
Quoted 43 lines
Quoted 42 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 11 lines

Review

Quoted 7 lines

+- interrupts:

(quoted diff) +5 -0
+    Usage: optional
+    Value type: <prop-encoded-array>
+    Definition: End of conversion interrupt number. If property is
+            missing driver will use polling to detect end of conversion
+            completion.

Driver details shouldn't be in the binding. If the driver can poll, that's good, but it should be dropped form this description.

Will remove driver details.

Quoted 2 lines

Is this the only interrupt?

Yes.

Quoted 4 lines

What do you mean be "End of conversion interrupt number"? Just describe what the interrupt logically is from the PoV of the device -- interrupts is a standard property so we don't need to be too explicit about the type.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Badly worded. Just, "End of conversion interrupt"?

The part I didn't understand was what was meant by "End of conversion", but dropping "number" is certainly better.

It is clear now, right? End of ADC conversion.

Sorry if I'm being thick here, but it's still somewhat confusing to me. That's a consequence of me not being familiar with the HW more than anything, I'm just missing simple details regarding the model of operation, suchs as exactly what the "end of ADC conversion" entails. There are a few things that could potentially mean depending on how the HW was designed and intended to be used.

Does the device periodically sample, convert some number of values (possibly just 1), and trigger an interrupt to state that a buffer is full / values are available? Or is the interrupt triggered for some other reason?

Quoted 4 lines
Quoted 2 lines

Interrupt is triggered after ADC convert analog signal to digital. Other details are irrelevant, I believe.

Often called a data ready interrupt. However, here it is per channel so perhaps that description is confusing as well...

Not exactly. There is only one interrupt. Simultaneous conversions are not possible.

Regards,
Ivan