Make i.MX 93 ADC calibration params configurable
Subsystems (4)
cover Make i.MX 93 ADC calibration params configurable
The i.MX 93 ADC calibration parameters are configurable in the MCR (Main Configuration Register). One can tweak bits:
- MCR[AVGEN]: Enable calibration averaging function,
- MCR[NRSMPL]: Select number of calibration samples,
- MCR[TSAMP]: Select sample time of calibration conversions,
Make it possible to configure those parameters via the corresponding device-tree properties.
This patch series is based on the one we submitted in March 2024:
https://lore.kernel.org/linux-arm-kernel/[email protected]/
Changes since the original submission:
- rebase on linux-next
- reorder patches (bindings before users)
- fix checkpatch errors
- reword commit subject & body
- implement feedback from reviewers
Andrej Picej (2):
dt-bindings: iio: adc: imx93: Add calibration properties
iio: adc: imx93: Make calibration parameters configurable
.../bindings/iio/adc/nxp,imx93-adc.yaml | 21 ++++++ drivers/iio/adc/imx93_adc.c | 75 +++++++++++++++++-- 2 files changed, 91 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 dt-bindings: iio: adc: imx93: Add calibration properties
From: Andrej Picej <[email protected]>
Document i.MX93 ADC calibration properties and how to set them.
--- .../bindings/iio/adc/nxp,imx93-adc.yaml | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+)
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +21 -0
@@ -52,6 +52,27 @@ properties: "#io-channel-cells": const: 1 + nxp,calib-avg-en: + default: 1 + description: + Enable or disable calibration averaging function (AVGEN). + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 0, 1 ] + + nxp,calib-nr-samples: + default: 512 + description: + Selects number of samples (NRSMPL) to be used during calibration. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 16, 32, 128, 512 ] + + nxp,calib-t-sample: + default: 22 + description: + Selects sample time (TSAMP) of calibration conversions in ADC clock cycles + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 8, 16, 22, 32 ] + required: - compatible - reg
Signature · 1 line
2.34.1
Frank Li
maintainerRe: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration properties
Quoted 15 lines · Primoz Fiser
From: Andrej Picej <[email protected]>
Document i.MX93 ADC calibration properties and how to set them.
Signed-off-by Andrej Picej <[email protected]>Signed-off-by Primoz Fiser <[email protected]>--- .../bindings/iio/adc/nxp,imx93-adc.yaml | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+)Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +0
-0
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml properties: · line 60
Quoted 9 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +6
-0@@ -52,6 +52,27 @@ properties: "#io-channel-cells": const: 1 + nxp,calib-avg-en: + default: 1 + description: + Enable or disable calibration averaging function (AVGEN). + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 0, 1 ]
bool type should be enough
Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +4
-0+ + nxp,calib-nr-samples: + default: 512 + description:
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml properties: · line 74
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +10
-0+ Selects number of samples (NRSMPL) to be used during calibration. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 16, 32, 128, 512 ] + + nxp,calib-t-sample: + default: 22 + description: + Selects sample time (TSAMP) of calibration conversions in ADC clock cycles + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 8, 16, 22, 32 ]
Need some judgement in commit message, such as difference board need difference nxp,calib-nr-samples value.
Frank
Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +1
-1+ required: - compatible - reg --2.34.1
David Lechner
reviewerRe: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration properties
In reply to Primoz FiserQuoted 32 lines · Primoz Fiser
From: Andrej Picej <[email protected]>
Document i.MX93 ADC calibration properties and how to set them.
Signed-off-by Andrej Picej <[email protected]>Signed-off-by Primoz Fiser <[email protected]>--- .../bindings/iio/adc/nxp,imx93-adc.yaml | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+)Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +14
-0@@ -52,6 +52,27 @@ properties: "#io-channel-cells": const: 1 + nxp,calib-avg-en: + default: 1 + description: + Enable or disable calibration averaging function (AVGEN). + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 0, 1 ] + + nxp,calib-nr-samples: + default: 512 + description: + Selects number of samples (NRSMPL) to be used during calibration. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 16, 32, 128, 512 ] +
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml properties: · line 78
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +7
-0+ nxp,calib-t-sample: + default: 22 + description: + Selects sample time (TSAMP) of calibration conversions in ADC clock cycles + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 8, 16, 22, 32 ] + required: - compatible - reg
This seem like things that should be set at runtime rather than in the devicetree. Unless there is some justification on why these values depend on how the chip is wired up?
Jonathan Cameron
maintainerRe: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration properties
Quoted 19 lines · On Thu, 10 Jul 2025 10:46:44 -0500 David Lechner <[email protected]> wrote:
Quoted 18 lines · Primoz Fiser
From: Andrej Picej <[email protected]>
Document i.MX93 ADC calibration properties and how to set them.
Signed-off-by Andrej Picej <[email protected]>Signed-off-by Primoz Fiser <[email protected]>--- .../bindings/iio/adc/nxp,imx93-adc.yaml | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+)Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +0
-0@@ -52,6 +52,27 @@ properties: "#io-channel-cells": const: 1
Quoted 13 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml properties: · line 67
Quoted 13 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +13
-0+ nxp,calib-avg-en: + default: 1 + description: + Enable or disable calibration averaging function (AVGEN). + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 0, 1 ] + + nxp,calib-nr-samples: + default: 512 + description: + Selects number of samples (NRSMPL) to be used during calibration. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 16, 32, 128, 512 ]
Allow 1 as a value and drop the enabled above. Averaging over 1 sample
is same as no averaging and gives simpler binding.
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +7
-0+ + nxp,calib-t-sample: + default: 22 + description: + Selects sample time (TSAMP) of calibration conversions in ADC clock cycles + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 8, 16, 22, 32 ]
Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml properties: · line 78
Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +1
-0+ required: - compatible - regThis seem like things that should be set at runtime rather than in the devicetree. Unless there is some justification on why these values depend on how the chip is wired up?
Further to that, I'd like to see some explanation of why we care to change it at all. Is it ever a bad idea to enable averaging and pick a large number of samples for calibration?
Quoted 2 lines
Re: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration properties
Hi all,
Quoted 22 lines · Jonathan Cameron
Quoted 19 lines · On Thu, 10 Jul 2025 10:46:44 -0500 David Lechner <[email protected]> wrote:
Quoted 18 lines · Primoz Fiser
From: Andrej Picej <[email protected]>
Document i.MX93 ADC calibration properties and how to set them.
Signed-off-by Andrej Picej <[email protected]>Signed-off-by Primoz Fiser <[email protected]>--- .../bindings/iio/adc/nxp,imx93-adc.yaml | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+)Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +0
-0@@ -52,6 +52,27 @@ properties: "#io-channel-cells": const: 1
Quoted 32 lines
Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +5
-0+ nxp,calib-avg-en: + default: 1 + description: + Enable or disable calibration averaging function (AVGEN). + $ref: /schemas/types.yaml#/definitions/uint32Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml properties: · line 67
Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +8
-0+ enum: [ 0, 1 ] + + nxp,calib-nr-samples: + default: 512 + description: + Selects number of samples (NRSMPL) to be used during calibration. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 16, 32, 128, 512 ]Allow 1 as a value and drop the enabled above. Averaging over 1 sample
is same as no averaging and gives simpler binding.Quoted 15 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml properties: · line 78
Quoted 11 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +8
-0+ + nxp,calib-t-sample: + default: 22 + description: + Selects sample time (TSAMP) of calibration conversions in ADC clock cycles + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 8, 16, 22, 32 ] + required: - compatible - regThis seem like things that should be set at runtime rather than in the devicetree. Unless there is some justification on why these values depend on how the chip is wired up?
It depends how ADC 1.8V Vref is wired up, especially how noisy it is.
Quoted 4 lines
Further to that, I'd like to see some explanation of why we care to change it at all. Is it ever a bad idea to enable averaging and pick a large number of samples for calibration?
This is a snippet from the i.MX93 TRM, chapter Analog-to-Digital Converter (SAR_ADC) describing calibration steps:
1. Wait for deassertion of functional reset.
2. Configure SAR controller operating clock (MCR[ADCLKSE] = 0).
3. Bring ADC out of Power-down state (MCR[PWDN] = 0).
4. Configure desired calibration settings (default values kept for highest accuracy maximum time).
• MCR[TSAMP]: Sample time for calibration conversion
• MCR[NRSMPL]: Number of samples in averaging
• MCR[AVGEN]: Averaging function enable in calibration
5. Run calibration by writing a one to MCR[CALSTART].
6. Check calibration run status in MSR[CALBUSY]—wait until MSR[CALBUSY] = 0; alternatively, MSR[ADCSTAT] can be
used to check status.
7. Check calibration pass/fail status in MSR[CALFAIL] field. If MSR[CALFAIL] = 1 then calibration failed. Detailed status can be checked in CALSTAT.
See point 4).
Not sure why would there be an option to configure i.MX93 ADC calibration parameters if one use-case (max accuracy max time) to rule them all?
On the other hand, public TRM doesn't give much more information and input from NXP would be highly desired.
@Haibo Chen your thoughts?
BR,
Primoz
Quoted 4 lines
Quoted 3 lines
Signature · 9 lines
Primoz Fiser phone: +386-41-390-545 email: [email protected] -- Norik systems d.o.o. Your embedded software partner Slovenia, EU phone: +386-41-540-545 email: [email protected]
Re: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration properties
Quoted 87 lines · Primoz Fiser
Hi all,
Quoted 31 lines · Jonathan Cameron
Quoted 28 lines · On Thu, 10 Jul 2025 10:46:44 -0500 David Lechner <[email protected]> wrote:
Quoted 27 lines · Primoz Fiser
From: Andrej Picej <[email protected]>
Document i.MX93 ADC calibration properties and how to set them.
Signed-off-by Andrej Picej <[email protected]>Signed-off-by Primoz Fiser <[email protected]>---
.../bindings/iio/adc/nxp,imx93-adc.yaml | 21 +++++++++++++++++++1 file changed, 21 insertions(+)(quoted diff) +0
-0
adc.yamlb/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yamlindexc2e5ff418920..d1c04cf85fe6100644Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +0
-0@@ -52,6 +52,27 @@ properties:"#io-channel-cells":
const: 1
+ nxp,calib-avg-en:
+ default: 1
+ description:
+ Enable or disable calibration averaging function (AVGEN). + $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [ 0, 1 ]
+
+ nxp,calib-nr-samples:Quoted 25 lines
Quoted 5 lines
Quoted 5 lines
+ default: 512
+ description:
+ Selects number of samples (NRSMPL) to be used during calibration. + $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [ 16, 32, 128, 512 ]Allow 1 as a value and drop the enabled above. Averaging over 1 sample is same as no averaging and gives simpler binding.
Quoted 16 lines
Quoted 4 lines
+
+ nxp,calib-t-sample:
+ default: 22
+ description:Quoted 8 lines
+ Selects sample time (TSAMP) of calibration conversions in ADC clock cycles
+ $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [ 8, 16, 22, 32 ]
+
required:
- compatible
- regThis seem like things that should be set at runtime rather than in the devicetree. Unless there is some justification on why these values depend on how the chip is wired up?
It depends how ADC 1.8V Vref is wired up, especially how noisy it is.
Quoted 4 lines
Further to that, I'd like to see some explanation of why we care to change it at all. Is it ever a bad idea to enable averaging and pick a large number of samples for calibration?
This is a snippet from the i.MX93 TRM, chapter Analog-to-Digital Converter (
SAR_ADC) describing calibration steps:1. Wait for deassertion of functional reset.
2. Configure SAR controller operating clock (MCR[ADCLKSE] = 0).
3. Bring ADC out of Power-down state (MCR[PWDN] = 0).
4. Configure desired calibration settings (default values kept for highest accuracy maximum time).
• MCR[TSAMP]: Sample time for calibration conversion
• MCR[NRSMPL]: Number of samples in averaging
• MCR[AVGEN]: Averaging function enable in calibration
5. Run calibration by writing a one to MCR[CALSTART].
6. Check calibration run status in MSR[CALBUSY]—wait until MSR[CALBUSY] = 0; alternatively, MSR[ADCSTAT] can be
used to check status.
7. Check calibration pass/fail status in MSR[CALFAIL] field. If MSR[CALFAIL] = 1 then calibration failed. Detailed status can be checked in CALSTAT.
Quoted 6 lines
See point 4).
Not sure why would there be an option to configure i.MX93 ADC calibration parameters if one use-case (max accuracy max time) to rule them all?
Sometimes HW guys just want to give you some options. Does not mean we have to use them all :).
I guess what Jonathan is interested in, is to understand in what conditions the defaults are no good for the calibration? If we can have a set of values that should pretty much always work, no need to further complicate the bindings or the driver.
- Nuno Sá
Quoted 2 lines
On the other hand, public TRM doesn't give much more information and
Quoted 1 line
Re: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration properties
Hi Nuno,
Quoted 95 lines · Nuno Sá
Quoted 87 lines · Primoz Fiser
Hi all,
Quoted 31 lines · Jonathan Cameron
Quoted 28 lines · On Thu, 10 Jul 2025 10:46:44 -0500 David Lechner <[email protected]> wrote:
Quoted 27 lines · Primoz Fiser
From: Andrej Picej <[email protected]>
Document i.MX93 ADC calibration properties and how to set them.
Signed-off-by Andrej Picej <[email protected]>Signed-off-by Primoz Fiser <[email protected]>---
.../bindings/iio/adc/nxp,imx93-adc.yaml | 21 +++++++++++++++++++1 file changed, 21 insertions(+)(quoted diff) +0
-0
adc.yamlb/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yamlindexc2e5ff418920..d1c04cf85fe6100644Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +0
-0@@ -52,6 +52,27 @@ properties:"#io-channel-cells":
const: 1
+ nxp,calib-avg-en:
+ default: 1
+ description:
+ Enable or disable calibration averaging function (AVGEN). + $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [ 0, 1 ]
+
+ nxp,calib-nr-samples:Quoted 25 lines
Quoted 5 lines
Quoted 5 lines
+ default: 512
+ description:
+ Selects number of samples (NRSMPL) to be used during calibration. + $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [ 16, 32, 128, 512 ]Allow 1 as a value and drop the enabled above. Averaging over 1 sample is same as no averaging and gives simpler binding.
Quoted 16 lines
Quoted 4 lines
+
+ nxp,calib-t-sample:
+ default: 22
+ description:Quoted 8 lines
+ Selects sample time (TSAMP) of calibration conversions in ADC clock cycles
+ $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [ 8, 16, 22, 32 ]
+
required:
- compatible
- regThis seem like things that should be set at runtime rather than in the devicetree. Unless there is some justification on why these values depend on how the chip is wired up?
It depends how ADC 1.8V Vref is wired up, especially how noisy it is.
Quoted 4 lines
Further to that, I'd like to see some explanation of why we care to change it at all. Is it ever a bad idea to enable averaging and pick a large number of samples for calibration?
This is a snippet from the i.MX93 TRM, chapter Analog-to-Digital Converter (
SAR_ADC) describing calibration steps:1. Wait for deassertion of functional reset.
2. Configure SAR controller operating clock (MCR[ADCLKSE] = 0).
3. Bring ADC out of Power-down state (MCR[PWDN] = 0).
4. Configure desired calibration settings (default values kept for highest accuracy maximum time).
• MCR[TSAMP]: Sample time for calibration conversion
• MCR[NRSMPL]: Number of samples in averaging
• MCR[AVGEN]: Averaging function enable in calibration
5. Run calibration by writing a one to MCR[CALSTART].
6. Check calibration run status in MSR[CALBUSY]—wait until MSR[CALBUSY] = 0; alternatively, MSR[ADCSTAT] can be
used to check status.
7. Check calibration pass/fail status in MSR[CALFAIL] field. If MSR[CALFAIL] = 1 then calibration failed. Detailed status can be checked in CALSTAT.Quoted 6 lines
See point 4).
Not sure why would there be an option to configure i.MX93 ADC calibration parameters if one use-case (max accuracy max time) to rule them all?
Quoted 7 lines
Sometimes HW guys just want to give you some options. Does not mean we have to use them all :).
I guess what Jonathan is interested in, is to understand in what conditions the defaults are no good for the calibration? If we can have a set of values that should pretty much always work, no need to further complicate the bindings or the driver.
In case you have a noisy Vref you can adjust the parameters to pass the calibration and have a working ADC.
The trade-off is a less precise ADC but at least a working one.
In ideal case you would have Vref supplied by the dedicated LDO and tons of decoupling caps, but in real-world you have it connected to a noisy SMPS and you need to adjust the parameters accordingly.
That's it :)
BR,
Primoz
Signature · 9 lines
Primoz Fiser phone: +386-41-390-545 email: [email protected] -- Norik systems d.o.o. Your embedded software partner Slovenia, EU phone: +386-41-540-545 email: [email protected]
Jonathan Cameron
maintainerRe: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration properties
Quoted 101 lines · On Tue, 15 Jul 2025 07:46:44 +0200 Primoz Fiser <[email protected]> wrote:
Hi Nuno,
Quoted 98 lines · Nuno Sá
Quoted 87 lines · Primoz Fiser
Hi all,
Quoted 31 lines · Jonathan Cameron
Quoted 28 lines · On Thu, 10 Jul 2025 10:46:44 -0500 David Lechner <[email protected]> wrote:
Quoted 27 lines · Primoz Fiser
From: Andrej Picej <[email protected]>
Document i.MX93 ADC calibration properties and how to set them.
Signed-off-by Andrej Picej <[email protected]>Signed-off-by Primoz Fiser <[email protected]>---
.../bindings/iio/adc/nxp,imx93-adc.yaml | 21 +++++++++++++++++++1 file changed, 21 insertions(+)(quoted diff) +0
-0
adc.yamlb/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yamlindexc2e5ff418920..d1c04cf85fe6100644Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +0
-0@@ -52,6 +52,27 @@ properties:"#io-channel-cells":
const: 1
+ nxp,calib-avg-en:
+ default: 1
+ description:
+ Enable or disable calibration averaging function (AVGEN). + $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [ 0, 1 ]
+
+ nxp,calib-nr-samples:Quoted 25 lines
Quoted 5 lines
Quoted 5 lines
+ default: 512
+ description:
+ Selects number of samples (NRSMPL) to be used during calibration. + $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [ 16, 32, 128, 512 ]Allow 1 as a value and drop the enabled above. Averaging over 1 sample is same as no averaging and gives simpler binding.
Quoted 16 lines
Quoted 4 lines
+
+ nxp,calib-t-sample:
+ default: 22
+ description:Quoted 8 lines
+ Selects sample time (TSAMP) of calibration conversions in ADC clock cycles
+ $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [ 8, 16, 22, 32 ]
+
required:
- compatible
- regThis seem like things that should be set at runtime rather than in the devicetree. Unless there is some justification on why these values depend on how the chip is wired up?
It depends how ADC 1.8V Vref is wired up, especially how noisy it is.
Quoted 4 lines
Further to that, I'd like to see some explanation of why we care to change it at all. Is it ever a bad idea to enable averaging and pick a large number of samples for calibration?
This is a snippet from the i.MX93 TRM, chapter Analog-to-Digital Converter (
SAR_ADC) describing calibration steps:1. Wait for deassertion of functional reset.
2. Configure SAR controller operating clock (MCR[ADCLKSE] = 0).
3. Bring ADC out of Power-down state (MCR[PWDN] = 0).
4. Configure desired calibration settings (default values kept for highest accuracy maximum time).
• MCR[TSAMP]: Sample time for calibration conversion
• MCR[NRSMPL]: Number of samples in averaging
• MCR[AVGEN]: Averaging function enable in calibration
5. Run calibration by writing a one to MCR[CALSTART].
6. Check calibration run status in MSR[CALBUSY]—wait until MSR[CALBUSY] = 0; alternatively, MSR[ADCSTAT] can be
used to check status.
7. Check calibration pass/fail status in MSR[CALFAIL] field. If MSR[CALFAIL] = 1 then calibration failed. Detailed status can be checked in CALSTAT.Quoted 6 lines
See point 4).
Not sure why would there be an option to configure i.MX93 ADC calibration parameters if one use-case (max accuracy max time) to rule them all?
Sometimes HW guys just want to give you some options. Does not mean we have to use them all :).
Quoted 7 lines
Quoted 4 lines
I guess what Jonathan is interested in, is to understand in what conditions the defaults are no good for the calibration? If we can have a set of values that should pretty much always work, no need to further complicate the bindings or the driver.
In case you have a noisy Vref you can adjust the parameters to pass the calibration and have a working ADC.
That's a fairly odd sounding situation. Is this a case of it will always pass because there is some drift going on or something low frequency like that?
Or is it a case of retry until it passes?
Jonathan
Quoted 12 lines
The trade-off is a less precise ADC but at least a working one.
In ideal case you would have Vref supplied by the dedicated LDO and tons of decoupling caps, but in real-world you have it connected to a noisy SMPS and you need to adjust the parameters accordingly.
That's it :)
BR,
Primoz
Re: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration properties
In reply to Nuno SáQuoted 95 lines · Nuno S?
Quoted 87 lines · Primoz Fiser
Hi all,
Quoted 31 lines · Jonathan Cameron
Quoted 28 lines · On Thu, 10 Jul 2025 10:46:44 -0500 David Lechner <[email protected]> wrote:
Quoted 27 lines · Primoz Fiser
From: Andrej Picej <[email protected]>
Document i.MX93 ADC calibration properties and how to set them.
Signed-off-by Andrej Picej <[email protected]>Signed-off-by Primoz Fiser <[email protected]>---
??.../bindings/iio/adc/nxp,imx93-adc.yaml???????????? | 21 +++++++++++++++++++ ??1 file changed, 21 insertions(+)(quoted diff) +0
-0
adc.yamlb/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yamlindexc2e5ff418920..d1c04cf85fe6100644Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml +0
-0@@ -52,6 +52,27 @@ properties:???? "#io-channel-cells":
???????? const: 1
??
+?? nxp,calib-avg-en:
+?????? default: 1
+?????? description:
+?????????? Enable or disable calibration averaging function (AVGEN). +?????? $ref: /schemas/types.yaml#/definitions/uint32 +?????? enum: [ 0, 1 ]
+
+?? nxp,calib-nr-samples:Quoted 25 lines
Quoted 5 lines
Quoted 5 lines
+?????? default: 512
+?????? description:
+?????????? Selects number of samples (NRSMPL) to be used during calibration. +?????? $ref: /schemas/types.yaml#/definitions/uint32
+?????? enum: [ 16, 32, 128, 512 ]Allow 1 as a value and drop the enabled above.???? Averaging over 1 sample is same as no averaging and gives simpler binding.
Quoted 16 lines
Quoted 4 lines
+
+?? nxp,calib-t-sample:
+?????? default: 22
+?????? description:Quoted 8 lines
+?????????? Selects sample time (TSAMP) of calibration conversions in ADC clock cycles
+?????? $ref: /schemas/types.yaml#/definitions/uint32
+?????? enum: [ 8, 16, 22, 32 ]
+
??required:
???? - compatible
???? - reg??This seem like things that should be set at runtime rather than in the devicetree. Unless there is some justification on why these values depend on how the chip is wired up?
It depends how ADC 1.8V Vref is wired up, especially how noisy it is.
Quoted 4 lines
Further to that, I'd like to see some explanation of why we care to change it at all. Is it ever a bad idea to enable averaging and pick a large number of samples for calibration?
This is a snippet from the i.MX93 TRM, chapter Analog-to-Digital Converter (
SAR_ADC) describing calibration steps:1. Wait for deassertion of functional reset.
2. Configure SAR controller operating clock (MCR[ADCLKSE] = 0).
3. Bring ADC out of Power-down state (MCR[PWDN] = 0).
4. Configure desired calibration settings (default values kept for highest accuracy maximum time).
??? MCR[TSAMP]: Sample time for calibration conversion
??? MCR[NRSMPL]: Number of samples in averaging
??? MCR[AVGEN]: Averaging function enable in calibration
5. Run calibration by writing a one to MCR[CALSTART].
6. Check calibration run status in MSR[CALBUSY]???wait until MSR[CALBUSY] = 0; alternatively, MSR[ADCSTAT] can be
used to check status.
7. Check calibration pass/fail status in MSR[CALFAIL] field. If MSR[CALFAIL] = 1 then calibration failed. Detailed status
can be checked in CALSTAT.Quoted 6 lines
See point 4).
Not sure why would there be an option to configure i.MX93 ADC calibration parameters if one use-case (max accuracy max time) to rule them all?
Quoted 7 lines
Sometimes HW guys just want to give you some options. Does not mean we have to use them all :).
I guess what Jonathan is interested in, is to understand in what conditions the defaults are no good for the calibration? If we can have a set of values that should pretty much always work, no need to further complicate the bindings or the driver.
Just my understanding, it is hard to use one fixed settings to fit all kinds of conditions.
Noise induced from PCB tracks Electro- magnetic noise
| |
V V
---------
|SOC(ADC)| <---------------------------------<- (~) external Signal
---------
^ ^
| |
I/O coupled noise Internal noise
So OEM A's board may needs different settings compared with OEM B's board.
Regards,
Peng
Quoted 4 lines
- Nuno S??
Quoted 2 lines
On the other hand, public TRM doesn't give much more information and
Quoted 1 line
Bough Chen
maintainerRE: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration properties
Quoted 142 lines
-----Original Message-----
From: Peng Fan (OSS) <[email protected]>
Sent: 2025年7月21日 17:39
To: Nuno S? <[email protected]>
Cc: Primoz Fiser <[email protected]>; Jonathan Cameron <[email protected]>; David Lechner <[email protected]>; Bough Chen <[email protected]>; Nuno Sa <[email protected]>; Andy Shevchenko <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Shawn Guo <[email protected]>; Sascha Hauer <[email protected]>; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration propertiesQuoted 35 lines · Nuno S?
Quoted 34 lines · Primoz Fiser
Hi all,
Quoted 31 lines · Jonathan Cameron
Quoted 28 lines · On Thu, 10 Jul 2025 10:46:44 -0500 David Lechner <[email protected]> wrote:
Quoted 27 lines · Primoz Fiser
From: Andrej Picej <[email protected]>
Document i.MX93 ADC calibration properties and how to set them.
Signed-off-by Andrej Picej <[email protected]>Signed-off-by Primoz Fiser <[email protected]>---
??.../bindings/iio/adc/nxp,imx93-adc.yaml???????????? | 21
+++++++++++++++++++
??1 file changed, 21 insertions(+)diff --git a/Documentation/devicetree/bindings/iio/adc/nxp,imx93-
adc.yamlb/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yamlindexc2e5ff418920..d1c04cf85fe6100644
---a/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml+++ b/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.y +++ aml(quoted diff) +0
-0@@ -52,6 +52,27 @@ properties:???? "#io-channel-cells":
???????? const: 1
??
+?? nxp,calib-avg-en:
+?????? default: 1
+?????? description:Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+?????????? Enable or disable calibration averaging function (AVGEN). +?????? $ref: /schemas/types.yaml#/definitions/uint32 +?????? enum: [ 0, 1 ]
+
+?? nxp,calib-nr-samples:
+?????? default: 512
+?????? description:
+?????????? Selects number of samples (NRSMPL) to be used duringcalibration.
Quoted 58 lines
Quoted 51 lines
Quoted 23 lines
Quoted 2 lines
Quoted 2 lines
+?????? $ref: /schemas/types.yaml#/definitions/uint32 +?????? enum: [ 16, 32, 128, 512 ]
Allow 1 as a value and drop the enabled above.???? Averaging over 1 sample is same as no averaging and gives simpler binding.
Quoted 17 lines
Quoted 6 lines
(quoted diff) +6
-0+ +?? nxp,calib-t-sample: +?????? default: 22 +?????? description: +?????????? Selects sample time (TSAMP) of calibration +conversions in ADCQuoted 7 lines
clock cycles
+?????? $ref: /schemas/types.yaml#/definitions/uint32 +?????? enum: [ 8, 16, 22, 32 ]
+
??required:
???? - compatible
???? - reg??This seem like things that should be set at runtime rather than in the devicetree. Unless there is some justification on why these values depend on how the chip is wired up?
It depends how ADC 1.8V Vref is wired up, especially how noisy it is.
Quoted 4 lines
Further to that, I'd like to see some explanation of why we care to change it at all. Is it ever a bad idea to enable averaging and pick a large number of samples for calibration?
This is a snippet from the i.MX93 TRM, chapter Analog-to-Digital Converter (
SAR_ADC) describing calibration steps:1. Wait for deassertion of functional reset.
2. Configure SAR controller operating clock (MCR[ADCLKSE] = 0).
3. Bring ADC out of Power-down state (MCR[PWDN] = 0).
4. Configure desired calibration settings (default values kept for highest accuracy maximum time).
??? MCR[TSAMP]: Sample time for calibration conversion ??? MCR[NRSMPL]: Number of samples in averaging ??? MCR[AVGEN]: Averaging function enable in calibration 5. Run calibration by writing a one to MCR[CALSTART].
6. Check calibration run status in MSR[CALBUSY]???wait until MSR[CALBUSY] = 0; alternatively, MSR[ADCSTAT] can be used to check status.
7. Check calibration pass/fail status in MSR[CALFAIL] field. If MSR[CALFAIL] = 1 then calibration failed. Detailed status can be checked in CALSTAT.Quoted 6 lines
See point 4).
Not sure why would there be an option to configure i.MX93 ADC calibration parameters if one use-case (max accuracy max time) to rule them all?
Quoted 7 lines
Sometimes HW guys just want to give you some options. Does not mean we have to use them all :).
I guess what Jonathan is interested in, is to understand in what conditions the defaults are no good for the calibration? If we can have a set of values that should pretty much always work, no need to further complicate the bindings or the driver.
Just my understanding, it is hard to use one fixed settings to fit all kinds of conditions.
Noise induced from PCB tracks Electro- magnetic noise
| |
V V
---------
|SOC(ADC)| <---------------------------------<- (~) external Signal
---------
^ ^
| |
I/O coupled noise Internal noise
Quoted 1 line
So OEM A's board may needs different settings compared with OEM B's board.
The noise on Vref did impact the calibration, we did get report from customer, and IC guys suggested to do like the following patch, what's your comments?
https://patchwork.kernel.org/project/linux-iio/patch/[email protected]/
Regards
Haibo Chen
Quoted 8 lines
Regards,
PengQuoted 4 lines
- Nuno S??
Quoted 2 lines
On the other hand, public TRM doesn't give much more information and
Quoted 1 line
Jonathan Cameron
maintainerRe: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration properties
Quoted 142 lines · On Mon, 21 Jul 2025 09:09:06 +0000 Bough Chen <[email protected]> wrote:
Quoted 142 lines
-----Original Message-----
From: Peng Fan (OSS) <[email protected]>
Sent: 2025年7月21日 17:39
To: Nuno S? <[email protected]>
Cc: Primoz Fiser <[email protected]>; Jonathan Cameron <[email protected]>; David Lechner <[email protected]>; Bough Chen <[email protected]>; Nuno Sa <[email protected]>; Andy Shevchenko <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Shawn Guo <[email protected]>; Sascha Hauer <[email protected]>; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration propertiesQuoted 35 lines · Nuno S?
Quoted 34 lines · Primoz Fiser
Hi all,
Quoted 31 lines · Jonathan Cameron
Quoted 28 lines · On Thu, 10 Jul 2025 10:46:44 -0500 David Lechner <[email protected]> wrote:
Quoted 27 lines · Primoz Fiser
From: Andrej Picej <[email protected]>
Document i.MX93 ADC calibration properties and how to set them.
Signed-off-by Andrej Picej <[email protected]>Signed-off-by Primoz Fiser <[email protected]>---
??.../bindings/iio/adc/nxp,imx93-adc.yaml???????????? | 21
+++++++++++++++++++
??1 file changed, 21 insertions(+)diff --git a/Documentation/devicetree/bindings/iio/adc/nxp,imx93-
adc.yamlb/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yamlindexc2e5ff418920..d1c04cf85fe6100644
---a/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml+++ b/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.y +++ aml(quoted diff) +0
-0@@ -52,6 +52,27 @@ properties:???? "#io-channel-cells":
???????? const: 1
??
+?? nxp,calib-avg-en:
+?????? default: 1
+?????? description:Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+?????????? Enable or disable calibration averaging function (AVGEN). +?????? $ref: /schemas/types.yaml#/definitions/uint32 +?????? enum: [ 0, 1 ]
+
+?? nxp,calib-nr-samples:
+?????? default: 512
+?????? description:
+?????????? Selects number of samples (NRSMPL) to be used duringcalibration.
Quoted 58 lines
Quoted 51 lines
Quoted 23 lines
Quoted 2 lines
Quoted 2 lines
+?????? $ref: /schemas/types.yaml#/definitions/uint32 +?????? enum: [ 16, 32, 128, 512 ]
Allow 1 as a value and drop the enabled above.???? Averaging over 1 sample is same as no averaging and gives simpler binding.
Quoted 17 lines
Quoted 6 lines
(quoted diff) +6
-0+ +?? nxp,calib-t-sample: +?????? default: 22 +?????? description: +?????????? Selects sample time (TSAMP) of calibration +conversions in ADCQuoted 7 lines
clock cycles
+?????? $ref: /schemas/types.yaml#/definitions/uint32 +?????? enum: [ 8, 16, 22, 32 ]
+
??required:
???? - compatible
???? - reg??This seem like things that should be set at runtime rather than in the devicetree. Unless there is some justification on why these values depend on how the chip is wired up?
It depends how ADC 1.8V Vref is wired up, especially how noisy it is.
Quoted 4 lines
Further to that, I'd like to see some explanation of why we care to change it at all. Is it ever a bad idea to enable averaging and pick a large number of samples for calibration?
This is a snippet from the i.MX93 TRM, chapter Analog-to-Digital Converter (
SAR_ADC) describing calibration steps:1. Wait for deassertion of functional reset.
2. Configure SAR controller operating clock (MCR[ADCLKSE] = 0).
3. Bring ADC out of Power-down state (MCR[PWDN] = 0).
4. Configure desired calibration settings (default values kept for highest accuracy maximum time).
??? MCR[TSAMP]: Sample time for calibration conversion ??? MCR[NRSMPL]: Number of samples in averaging ??? MCR[AVGEN]: Averaging function enable in calibration 5. Run calibration by writing a one to MCR[CALSTART].
6. Check calibration run status in MSR[CALBUSY]???wait until MSR[CALBUSY] = 0; alternatively, MSR[ADCSTAT] can be used to check status.
7. Check calibration pass/fail status in MSR[CALFAIL] field. If MSR[CALFAIL] = 1 then calibration failed. Detailed status can be checked in CALSTAT.Quoted 6 lines
See point 4).
Not sure why would there be an option to configure i.MX93 ADC calibration parameters if one use-case (max accuracy max time) to rule them all?
Quoted 7 lines
Sometimes HW guys just want to give you some options. Does not mean we have to use them all :).
I guess what Jonathan is interested in, is to understand in what conditions the defaults are no good for the calibration? If we can have a set of values that should pretty much always work, no need to further complicate the bindings or the driver.
Just my understanding, it is hard to use one fixed settings to fit all kinds of conditions.
Noise induced from PCB tracks Electro- magnetic noise
| |
V V
---------
|SOC(ADC)| <---------------------------------<- (~) external Signal
---------
^ ^
| |
I/O coupled noise Internal noise
Quoted 5 lines
Quoted 1 line
So OEM A's board may needs different settings compared with OEM B's board.
The noise on Vref did impact the calibration, we did get report from customer, and IC guys suggested to do like the following patch, what's your comments?
https://patchwork.kernel.org/project/linux-iio/patch/[email protected]/
To me warning and accepting a failed calibration is better than tweaking settings.
The reason is I'm still failing to understand why we should (for example) reduce the time over which the signal is averaged. Why would that make it more likely to pass in some noise conditions than another set? It might increase the chance of passing I guess, but it's still likely to fail sometimes.
Jonathan
Quoted 11 lines
Regards
Haibo ChenQuoted 8 lines
Regards,
PengQuoted 4 lines
- Nuno S??
Quoted 2 lines
On the other hand, public TRM doesn't give much more information and
Quoted 1 line
Re: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration properties
In reply to Bough ChenHi,
Quoted 142 lines · Bough Chen
Quoted 142 lines
-----Original Message-----
From: Peng Fan (OSS) <[email protected]>
Sent: 2025年7月21日 17:39
To: Nuno S? <[email protected]>
Cc: Primoz Fiser <[email protected]>; Jonathan Cameron <[email protected]>; David Lechner <[email protected]>; Bough Chen <[email protected]>; Nuno Sa <[email protected]>; Andy Shevchenko <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Shawn Guo <[email protected]>; Sascha Hauer <[email protected]>; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration propertiesQuoted 35 lines · Nuno S?
Quoted 34 lines · Primoz Fiser
Hi all,
Quoted 31 lines · Jonathan Cameron
Quoted 28 lines · On Thu, 10 Jul 2025 10:46:44 -0500 David Lechner <[email protected]> wrote:
Quoted 27 lines · Primoz Fiser
From: Andrej Picej <[email protected]>
Document i.MX93 ADC calibration properties and how to set them.
Signed-off-by Andrej Picej <[email protected]>Signed-off-by Primoz Fiser <[email protected]>---
??.../bindings/iio/adc/nxp,imx93-adc.yaml???????????? | 21
+++++++++++++++++++
??1 file changed, 21 insertions(+)diff --git a/Documentation/devicetree/bindings/iio/adc/nxp,imx93-
adc.yamlb/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yamlindexc2e5ff418920..d1c04cf85fe6100644
---a/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml+++ b/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.y +++ aml(quoted diff) +0
-0@@ -52,6 +52,27 @@ properties:???? "#io-channel-cells":
???????? const: 1
??
+?? nxp,calib-avg-en:
+?????? default: 1
+?????? description:Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+?????????? Enable or disable calibration averaging function (AVGEN). +?????? $ref: /schemas/types.yaml#/definitions/uint32 +?????? enum: [ 0, 1 ]
+
+?? nxp,calib-nr-samples:
+?????? default: 512
+?????? description:
+?????????? Selects number of samples (NRSMPL) to be used duringcalibration.
Quoted 58 lines
Quoted 51 lines
Quoted 23 lines
Quoted 2 lines
Quoted 2 lines
+?????? $ref: /schemas/types.yaml#/definitions/uint32 +?????? enum: [ 16, 32, 128, 512 ]
Allow 1 as a value and drop the enabled above.???? Averaging over 1 sample is same as no averaging and gives simpler binding.
Quoted 17 lines
Quoted 6 lines
(quoted diff) +6
-0+ +?? nxp,calib-t-sample: +?????? default: 22 +?????? description: +?????????? Selects sample time (TSAMP) of calibration +conversions in ADCQuoted 7 lines
clock cycles
+?????? $ref: /schemas/types.yaml#/definitions/uint32 +?????? enum: [ 8, 16, 22, 32 ]
+
??required:
???? - compatible
???? - reg??This seem like things that should be set at runtime rather than in the devicetree. Unless there is some justification on why these values depend on how the chip is wired up?
It depends how ADC 1.8V Vref is wired up, especially how noisy it is.
Quoted 4 lines
Further to that, I'd like to see some explanation of why we care to change it at all. Is it ever a bad idea to enable averaging and pick a large number of samples for calibration?
This is a snippet from the i.MX93 TRM, chapter Analog-to-Digital Converter (
SAR_ADC) describing calibration steps:1. Wait for deassertion of functional reset.
2. Configure SAR controller operating clock (MCR[ADCLKSE] = 0).
3. Bring ADC out of Power-down state (MCR[PWDN] = 0).
4. Configure desired calibration settings (default values kept for highest accuracy maximum time).
??? MCR[TSAMP]: Sample time for calibration conversion ??? MCR[NRSMPL]: Number of samples in averaging ??? MCR[AVGEN]: Averaging function enable in calibration 5. Run calibration by writing a one to MCR[CALSTART].
6. Check calibration run status in MSR[CALBUSY]???wait until MSR[CALBUSY] = 0; alternatively, MSR[ADCSTAT] can be used to check status.
7. Check calibration pass/fail status in MSR[CALFAIL] field. If MSR[CALFAIL] = 1 then calibration failed. Detailed status can be checked in CALSTAT.Quoted 6 lines
See point 4).
Not sure why would there be an option to configure i.MX93 ADC calibration parameters if one use-case (max accuracy max time) to rule them all?
Quoted 7 lines
Sometimes HW guys just want to give you some options. Does not mean we have to use them all :).
I guess what Jonathan is interested in, is to understand in what conditions the defaults are no good for the calibration? If we can have a set of values that should pretty much always work, no need to further complicate the bindings or the driver.
Just my understanding, it is hard to use one fixed settings to fit all kinds of conditions.
Noise induced from PCB tracks Electro- magnetic noise
| |
V V
---------
|SOC(ADC)| <---------------------------------<- (~) external Signal
---------
^ ^
| |
I/O coupled noise Internal noise
Quoted 5 lines
Quoted 1 line
So OEM A's board may needs different settings compared with OEM B's board.
The noise on Vref did impact the calibration, we did get report from customer, and IC guys suggested to do like the following patch, what's your comments?
https://patchwork.kernel.org/project/linux-iio/patch/[email protected]/
With this patch we still get calibration warning however ADC is eventually working.
Where can we get mapping for this register:
#define IMX93_ADC_CALCFG0 0X3A0
It seems that public i.MX 93 TRM goes up to offset 0x39C only?
BR,
Primoz
Quoted 11 lines
Regards
Haibo ChenQuoted 8 lines
Regards,
PengQuoted 4 lines
- Nuno S??
Quoted 2 lines
On the other hand, public TRM doesn't give much more information and
Quoted 1 line
Signature · 9 lines
Primoz Fiser phone: +386-41-390-545 email: [email protected] -- Norik systems d.o.o. Your embedded software partner Slovenia, EU phone: +386-41-540-545 email: [email protected]
Bough Chen
maintainerRE: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration properties
Quoted 190 lines
-----Original Message-----
From: Primoz Fiser <[email protected]>
Sent: 2025年8月7日 12:37
To: Bough Chen <[email protected]>; Peng Fan (OSS) <[email protected]>; Nuno S? <[email protected]>
Cc: Jonathan Cameron <[email protected]>; David Lechner <[email protected]>; Nuno Sa <[email protected]>; Andy Shevchenko <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Shawn Guo <[email protected]>; Sascha Hauer <[email protected]>; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration propertiesHi,
Quoted 7 lines · Bough Chen
Quoted 7 lines
-----Original Message-----
From: Peng Fan (OSS) <[email protected]>
Sent: 2025年7月21日 17:39
To: Nuno S? <[email protected]>
Cc: Primoz Fiser <[email protected]>; Jonathan Cameron <[email protected]>; David Lechner <[email protected]>; Bough Chen <[email protected]>; Nuno Sa <[email protected]>; AndyShevchenko
Quoted 122 lines
Quoted 122 lines
<[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Shawn Guo <[email protected]>; Sascha Hauer <[email protected]>; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/2] dt-bindings: iio: adc: imx93: Add calibration propertiesQuoted 35 lines · Nuno S?
Quoted 34 lines · Primoz Fiser
Hi all,
Quoted 31 lines · Jonathan Cameron
Quoted 28 lines · On Thu, 10 Jul 2025 10:46:44 -0500 David Lechner <[email protected]> wrote:
Quoted 27 lines · Primoz Fiser
From: Andrej Picej <[email protected]>
Document i.MX93 ADC calibration properties and how to set them.
Signed-off-by Andrej Picej <[email protected]>Signed-off-by Primoz Fiser <[email protected]>---
??.../bindings/iio/adc/nxp,imx93-adc.yaml???????????? | 21
+++++++++++++++++++
??1 file changed, 21 insertions(+)diff --git a/Documentation/devicetree/bindings/iio/adc/nxp,imx93-
adc.yamlb/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yamlindexc2e5ff418920..d1c04cf85fe6100644
---a/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml+++ b/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.y +++ aml(quoted diff) +0
-0@@ -52,6 +52,27 @@ properties:???? "#io-channel-cells":
???????? const: 1
??
+?? nxp,calib-avg-en:
+?????? default: 1
+?????? description:Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+?????????? Enable or disable calibration averaging function (AVGEN). +?????? $ref: /schemas/types.yaml#/definitions/uint32 +?????? enum: [ 0, 1 ]
+
+?? nxp,calib-nr-samples:
+?????? default: 512
+?????? description:
+?????????? Selects number of samples (NRSMPL) to be used duringcalibration.
Quoted 65 lines
Quoted 51 lines
Quoted 23 lines
Quoted 2 lines
Quoted 2 lines
+?????? $ref: /schemas/types.yaml#/definitions/uint32 +?????? enum: [ 16, 32, 128, 512 ]
Allow 1 as a value and drop the enabled above.???? Averaging over 1 sample is same as no averaging and gives simpler binding.
Quoted 17 lines
Quoted 6 lines
(quoted diff) +6
-0+ +?? nxp,calib-t-sample: +?????? default: 22 +?????? description: +?????????? Selects sample time (TSAMP) of calibration +conversions in ADCQuoted 7 lines
clock cycles
+?????? $ref: /schemas/types.yaml#/definitions/uint32 +?????? enum: [ 8, 16, 22, 32 ]
+
??required:
???? - compatible
???? - reg??This seem like things that should be set at runtime rather than in the devicetree. Unless there is some justification on why these values depend on how the chip is wired up?
It depends how ADC 1.8V Vref is wired up, especially how noisy it is.
Quoted 4 lines
Further to that, I'd like to see some explanation of why we care to change it at all. Is it ever a bad idea to enable averaging and pick a large number of samples for calibration?
This is a snippet from the i.MX93 TRM, chapter Analog-to-Digital Converter (
SAR_ADC) describing calibration steps:1. Wait for deassertion of functional reset.
2. Configure SAR controller operating clock (MCR[ADCLKSE] = 0).
3. Bring ADC out of Power-down state (MCR[PWDN] = 0).
4. Configure desired calibration settings (default values kept for highest accuracy maximum time).
??? MCR[TSAMP]: Sample time for calibration conversion ??? MCR[NRSMPL]: Number of samples in averaging ??? MCR[AVGEN]:
Averaging function enable in calibration 5. Run calibration by writing a one to MCR[CALSTART].
6. Check calibration run status in MSR[CALBUSY]???wait until MSR[CALBUSY] = 0; alternatively, MSR[ADCSTAT] can be used to check status.
7. Check calibration pass/fail status in MSR[CALFAIL] field. If MSR[CALFAIL] = 1 then calibration failed. Detailed status can be checked in CALSTAT.Quoted 6 lines
See point 4).
Not sure why would there be an option to configure i.MX93 ADC calibration parameters if one use-case (max accuracy max time) to rule them all?
Sometimes HW guys just want to give you some options. Does not mean we have to use them all :).
I guess what Jonathan is interested in, is to understand in what conditions the defaults are no good for the calibration? If we can have a set of values that should pretty much always work, no need to further complicate the bindings or the driver.
Quoted 4 lines
Quoted 4 lines
Just my understanding, it is hard to use one fixed settings to fit all kinds of conditions.
Noise induced from PCB tracks Electro- magnetic
noise
Quoted 11 lines
Quoted 11 lines
| | V V---------
|SOC(ADC)| <---------------------------------<- (~) external Signal
---------
^ ^
| |
I/O coupled noise Internal noiseSo OEM A's board may needs different settings compared with OEM B's
board.
Quoted 2 lines
The noise on Vref did impact the calibration, we did get report from customer,
and IC guys suggested to do like the following patch, what's your comments?
Quoted 4 lines
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatc
hwork.kernel.org%2Fproject%2Flinux-iio%2Fpatch%2F20250423-adcpatch-v1-1-b0e84c27ae98%40nxp.com%2F&data=05%7C02%7Chaibo.chen%40nxp.com %7C2101
Quoted 1 line
ebdd274b4dc119fa08ddd56c1e7f%7C686ea1d3bc2b4c6fa92cd99c5c301635%7 C0%7C
Quoted 1 line
0%7C638901382543508027%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcG kiOnRydWU
Quoted 1 line
sIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D %
Quoted 1 line
7C0%7C%7C%7C&sdata=gW%2F7FPCrcyVSduyj0dK%2BVm4rQJ4hviEsTlTJ06uvH 0M%3D&
Quoted 1 line
reserved=0
Quoted 8 lines
With this patch we still get calibration warning however ADC is eventually working.
Where can we get mapping for this register:
#define
IMX93_ADC_CALCFG00X3A0It seems that public i.MX 93 TRM goes up to offset
0x39Conly?
You can get the RM our nxp.com, the latest RM already add register 3A0 definition, here is the link,:
https://www.nxp.com/products/processors-and-microcontrollers/arm-processors/i-mx-applications-processors/i-mx-9-processors/i-mx-93-applications-processor-family-arm-cortex-a55-ml-acceleration-power-efficient-mpu:i.MX93
I will send out v2 of this patch.
Regards
Haibo Chen
Quoted 27 lines
BR,
PrimozQuoted 12 lines
Regards
Haibo ChenQuoted 9 lines
Regards,
PengQuoted 5 lines
- Nuno S??
Quoted 3 lines
On the other hand, public TRM doesn't give much more information and
Quoted 1 line
--
Primoz Fiser
phone: +386-41-390-545
email: [email protected]
--
Norik systems d.o.o.
Your embedded software partner
Slovenia, EU
phone: +386-41-540-545
email: [email protected]
PATCH 2/2 iio: adc: imx93: Make calibration parameters configurable
In reply to Primoz FiserFrom: Andrej Picej <[email protected]>
Make i.MX93 ADC calibration parameters:
- AVGEN: Enable calibration averaging function,
- NRSMPL: Select number of calibration samples,
- TSAMP: Select sample time of calibration conversions,
in the MCR register configurable with the corresponding device-tree properties:
- nxp,calib-avg-en,
- nxp,calib-nr-samples and
- nxp,calib-t-sample.
--- drivers/iio/adc/imx93_adc.c | 75 ++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 5 deletions(-)
drivers/iio/adc/imx93_adc.c +70 -5
@@ -18,6 +18,7 @@#include <linux/platform_device.h> #include <linux/pm_runtime.h> #include <linux/regulator/consumer.h> +#include <linux/property.h> #define IMX93_ADC_DRIVER_NAME "imx93-adc"
@@ -43,6 +44,9 @@#define IMX93_ADC_MCR_MODE_MASK BIT(29)#define IMX93_ADC_MCR_NSTART_MASK BIT(24)#define IMX93_ADC_MCR_CALSTART_MASK BIT(14) +#define IMX93_ADC_MCR_AVGEN_MASK BIT(13) +#define IMX93_ADC_MCR_NRSMPL_MASK GENMASK(12, 11) +#define IMX93_ADC_MCR_TSAMP_MASK GENMASK(10, 9)#define IMX93_ADC_MCR_ADCLKSE_MASK BIT(8)#define IMX93_ADC_MCR_PWDN_MASK BIT(0)#define IMX93_ADC_MSR_CALFAIL_MASK BIT(30)
@@ -145,7 +149,7 @@ static void imx93_adc_config_ad_clk(struct imx93_adc *adc)static int imx93_adc_calibration (struct imx93_adc *adc) { -u32 mcr, msr; +u32 mcr, msr, val, reg;int ret;/* make sure ADC in power down mode */
@@ -156,12 +160,73 @@ static int imx93_adc_calibration(struct imx93_adc *adc) mcr &= ~FIELD_PREP (IMX93_ADC_MCR_ADCLKSE_MASK ,1 );writel (mcr, adc->regs +IMX93_ADC_MCR ); -imx93_adc_power_up (adc); -/* -* TODO: we use the default TSAMP/NRSMPL/AVGEN in MCR, -* can add the setting of these bit if need in future. +* Optionally configure desired ADC calibration settings in MCR +* - MCR[AVGEN]: Enable/disable calibration averaging function (default: on) +* - MCR[NRSMPL]: Select the number of calibration samples (default: 512) +* - MCR[TSAMP]: Select sample time of calibration conversions (default: 22) */ + ret =device_property_read_u32 (adc->dev,"nxp,calib-avg-en" , &val); +if (!ret) { +if (val !=0 && val !=1 ) { +dev_err (adc->dev,"invalid nxp,calib-avg-en: %d\n" , val); +return -EINVAL ; + } + reg = val; + mcr &= ~IMX93_ADC_MCR_AVGEN_MASK ; + mcr |=FIELD_PREP (IMX93_ADC_MCR_AVGEN_MASK , reg); + } + + ret =device_property_read_u32 (adc->dev,"nxp,calib-nr-samples" , &val); +if (!ret) { +switch (val) { +case 16 : + reg =0x0 ; +break ; +case 32 : + reg =0x1 ; +break ; +case 128 : + reg =0x2 ; +break ; +case 512 : + reg =0x3 ; +break ; +default : +dev_err (adc->dev,"invalid nxp,calib-nr-samples: %d\n" , val); +return -EINVAL ; + } + mcr &= ~IMX93_ADC_MCR_NRSMPL_MASK ; + mcr |=FIELD_PREP (IMX93_ADC_MCR_NRSMPL_MASK , reg); + } + + ret =device_property_read_u32 (adc->dev,"nxp,calib-t-sample" , &val); +if (!ret) { +switch (val) { +case 8 : + reg =0x1 ; +break ; +case 16 : + reg =0x2 ; +break ; +case 22 : + reg =0x0 ; +break ; +case 32 : + reg =0x3 ; +break ; +default : +dev_err (adc->dev,"invalid nxp,calib-t-sample: %d\n" , val); +return -EINVAL ; + } + mcr &= ~IMX93_ADC_MCR_TSAMP_MASK ; + mcr |=FIELD_PREP (IMX93_ADC_MCR_TSAMP_MASK , reg); + } + +/* write calibration settings to MCR */ +writel (mcr, adc->regs +IMX93_ADC_MCR ); + +imx93_adc_power_up (adc);/* run calibration */ mcr =readl (adc->regs +IMX93_ADC_MCR );
Signature · 1 line
2.34.1
Re: [PATCH 2/2] iio: adc: imx93: Make calibration parameters configurable
Quoted 11 lines · Primoz Fiser
Make i.MX93 ADC calibration parameters:
- AVGEN: Enable calibration averaging function,
- NRSMPL: Select number of calibration samples,
- TSAMP: Select sample time of calibration conversions,in the MCR register configurable with the corresponding device-tree properties:
- nxp,calib-avg-en,
- nxp,calib-nr-samples and
- nxp,calib-t-sample.
...
Quoted 4 lines
#include <
linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/regulator/consumer.h>
+#include <linux/property.h>
Keep it in order.
...
drivers/iio/adc/imx93_adc.c static int imx93_adc_calibration(struct imx93_adc *adc) · line 178
Quoted 10 lines
drivers/iio/adc/imx93_adc.c +10
-0+ ret =device_property_read_u32 (adc->dev,"nxp,calib-avg-en" , &val); +if (!ret) { +if (val !=0 && val !=1 ) { +dev_err (adc->dev,"invalid nxp,calib-avg-en: %d\n" , val); +return -EINVAL ; + } + reg = val; + mcr &= ~IMX93_ADC_MCR_AVGEN_MASK ; + mcr |=FIELD_PREP (IMX93_ADC_MCR_AVGEN_MASK , reg); + }
Please, since it's optional, do other way around.
val = $DEFAUTL; device_property_read_u32(adc->dev, "nxp,calib-avg-en", &val); FIELD_MODIFY(...)
Similar approach may be used for the other properties.
...
drivers/iio/adc/imx93_adc.c static int imx93_adc_calibration(struct imx93_adc *adc) · line 227
Quoted 2 lines
drivers/iio/adc/imx93_adc.c +2
-0+/* write calibration settings to MCR */ +writel (mcr, adc->regs +IMX93_ADC_MCR );
Please, factor out this to the function, so we won't see the direct IO in the ->probe().
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/2] iio: adc: imx93: Make calibration parameters configurable
Hi Andy,
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Primoz Fiser
Make i.MX93 ADC calibration parameters:
- AVGEN: Enable calibration averaging function,
- NRSMPL: Select number of calibration samples,
- TSAMP: Select sample time of calibration conversions,in the MCR register configurable with the corresponding device-tree properties:
- nxp,calib-avg-en,
- nxp,calib-nr-samples and
- nxp,calib-t-sample.
Quoted 8 lines
...
Quoted 4 lines
#include <
linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/regulator/consumer.h>
+#include <linux/property.h>Keep it in order.
OK. Will fix for v2.
Quoted 16 lines
...
drivers/iio/adc/imx93_adc.c static int imx93_adc_calibration(struct imx93_adc *adc) · line 178
Quoted 10 lines
drivers/iio/adc/imx93_adc.c +10
-0+ ret =device_property_read_u32 (adc->dev,"nxp,calib-avg-en" , &val); +if (!ret) { +if (val !=0 && val !=1 ) { +dev_err (adc->dev,"invalid nxp,calib-avg-en: %d\n" , val); +return -EINVAL ; + } + reg = val; + mcr &= ~IMX93_ADC_MCR_AVGEN_MASK ; + mcr |=FIELD_PREP (IMX93_ADC_MCR_AVGEN_MASK , reg); + }Please, since it's optional, do other way around.
Quoted 5 lines
val = $DEFAUTL; device_property_read_u32(adc->dev, "nxp,calib-avg-en", &val); FIELD_MODIFY(...)Similar approach may be used for the other properties.
OK, I guess I could implement it like you suggested to explicitly set the default parameter values.
But in current implementation MCR values are read at the beginning of imx93_adc_calibration(), meaning calibration parameters are register POR defaults. With you suggestion, we put defaults in software rather than reading them from the hw directly.
Quoted 8 lines
...
drivers/iio/adc/imx93_adc.c static int imx93_adc_calibration(struct imx93_adc *adc) · line 227
Quoted 2 lines
drivers/iio/adc/imx93_adc.c +2
-0+/* write calibration settings to MCR */ +writel (mcr, adc->regs +IMX93_ADC_MCR );Please, factor out this to the function, so we won't see the direct IO in the ->probe().
Sorry I don't understand this part.
What do you mean by factoring out this writel()?
Do you perhaps suggest to implement function imx93_adc_configure_calibration() and put all our changes into it?
But we are already in imx93_adc_calibration() which is separate from probe().
Please explain.
BR,
Primoz
Re: [PATCH 2/2] iio: adc: imx93: Make calibration parameters configurable
Quoted 2 lines · Primoz Fiser
Quoted 1 line · Andy Shevchenko
On Thu, Jul 10, 2025 at 09:39:04AM +0200, Primoz Fiser wrote:
...
Quoted 19 lines
Quoted 13 lines
drivers/iio/adc/imx93_adc.c static int imx93_adc_calibration(struct imx93_adc *adc) · line 178
Quoted 10 lines
drivers/iio/adc/imx93_adc.c +10
-0+ ret =device_property_read_u32 (adc->dev,"nxp,calib-avg-en" , &val); +if (!ret) { +if (val !=0 && val !=1 ) { +dev_err (adc->dev,"invalid nxp,calib-avg-en: %d\n" , val); +return -EINVAL ; + } + reg = val; + mcr &= ~IMX93_ADC_MCR_AVGEN_MASK ; + mcr |=FIELD_PREP (IMX93_ADC_MCR_AVGEN_MASK , reg); + }Please, since it's optional, do other way around.
Quoted 5 lines
val = $DEFAUTL; device_property_read_u32(adc->dev, "nxp,calib-avg-en", &val); FIELD_MODIFY(...)Similar approach may be used for the other properties.
Quoted 7 lines
OK, I guess I could implement it like you suggested to explicitly set the default parameter values.
But in current implementation MCR values are read at the beginning of
imx93_adc_calibration(), meaning calibration parameters are register POR defaults. With you suggestion, we put defaults in software rather than reading them from the hw directly.
I see, then you need to read, do FIELD_GET()/device_property_read()/FIELD_MODIFY(). You got the idea.
...
Quoted 5 lines
Quoted 2 lines
Please, factor out this to the function, so we won't see the direct IO in the ->probe().
Sorry I don't understand this part.
Quoted 7 lines
What do you mean by factoring out this
writel()?Do you perhaps suggest to implement function
imx93_adc_configure_calibration()and put all our changes into it?But we are already in
imx93_adc_calibration()which is separate fromprobe().
Ah, sorry for the mistakenly read the function name. Ignore this comment.
Signature · 2 lines
With Best Regards, Andy Shevchenko