iio: imx8qxp-adc: Add driver support for NXP IMX8QXP ADC
v3 cover iio: imx8qxp-adc: Add driver support for NXP IMX8QXP ADC
The NXP i.MX 8QuadXPlus SOC has a new ADC IP. These patches add driver support for this ADC
dt-bindings: iio: adc:v1->v2: *Fix some indentation issues.
*Mark status as okay.
*Change clock2 source.
iio: imx8qxp-adc:v1->v2: *Squash patches 1, 2, 3, and 5 into a single patch.
*Add device specific prefix.
*Remove the brackets around individual numbers. *Make use of FIELD_PREP() and FIELD_GET(). *Remove a lot of cache values.
*Replace mlock with adc->lock.
*Move adc->value read from isr to the completion. *Set pm_runtime_disable/_put_noidle() before adc_disable. *Add error handler-err_disable_reg/err_unprepare_clk.v2->v3: *Add "return 0" to adc_runtime_resume()
v1 link:
https://patchwork.kernel.org/project/linux-arm-kernel/patch/[email protected]/
Cai Huoqing (3):
iio: imx8qxp-adc: Add driver support for NXP IMX8QXP ADC
dt-bindings: iio: adc: Add the binding documentation for NXP IMX8QXP
ADC
MAINTAINERS: Add the driver info of the NXP IMX8QXP ADC
.../bindings/iio/adc/nxp,imx8qxp-adc.yaml | 85 ++++ MAINTAINERS | 7 + drivers/iio/adc/Kconfig | 10 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/imx8qxp-adc.c | 470 ++++++++++++++++++ 5 files changed, 573 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml create mode 100644 drivers/iio/adc/imx8qxp-adc.c
Signature · 1 line
2.25.1
PATCH v3 1/3 iio: imx8qxp-adc: Add driver support for NXP IMX8QXP ADC
The NXP i.MX 8QuadXPlus SOC has a new ADC IP. These patches add driver support for this ADC.
---v1->v2: *Squash patches 1, 2, 3, and 5 into a single patch.
*Add device specific prefix.
*Remove the brackets around individual numbers. *Make use of FIELD_PREP() and FIELD_GET(). *Remove a lot of cache values.
*Replace mlock with adc->lock.
*Move adc->value read from isr to the completion. *Set pm_runtime_disable/_put_noidle() before adc_disable. *Add error handler-err_disable_reg/err_unprepare_clk.v2->v3: *Add "return 0" to adc_runtime_resume().
v1 link:
https://patchwork.kernel.org/project/linux-arm-kernel/patch/[email protected]/
drivers/iio/adc/Kconfig | 10 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/imx8qxp-adc.c | 470 ++++++++++++++++++++++++++++++++++ 3 files changed, 481 insertions(+) create mode 100644 drivers/iio/adc/imx8qxp-adc.c
drivers/iio/adc/Kconfig +10 -0
@@ -530,6 +530,16 @@ config IMX7D_ADC This driver can also be built as a module. If so, the module will be called imx7d_adc. +config IMX8QXP_ADC + tristate "NXP IMX8QXP ADC driver" + depends on ARCH_MXC_ARM64 || COMPILE_TEST + depends on HAS_IOMEM + help + Say yes here to build support for IMX8QXP ADC. + + This driver can also be built as a module. If so, the module will be + called imx8qxp-adc. + config LP8788_ADC tristate "LP8788 ADC driver" depends on MFD_LP8788
drivers/iio/adc/Makefile +1 -0
@@ -46,6 +46,7 @@ obj-$(CONFIG_FSL_MX25_ADC) += fsl-imx25-gcq.o obj-$(CONFIG_HI8435) += hi8435.o obj-$(CONFIG_HX711) += hx711.o obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o +obj-$(CONFIG_IMX8QXP_ADC) += imx8qxp-adc.o obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o obj-$(CONFIG_INGENIC_ADC) += ingenic-adc.o obj-$(CONFIG_INTEL_MRFLD_ADC) += intel_mrfld_adc.o
drivers/iio/adc/imx8qxp-adc.c new file +470 -0
470 lines not on this page · raw message
Signature · 1 line
2.25.1
Jonathan Cameron
maintainerQuoted 4 lines · On Tue, 7 Sep 2021 09:57:21 +0800 Cai Huoqing <[email protected]> wrote:
The NXP i.MX 8QuadXPlus SOC has a new ADC IP. These patches add driver support for this ADC.
Signed-off-by Cai Huoqing <[email protected]>
Hi,
A few minor things inline. This is looking pretty good to me!
Jonathan
Quoted 25 lines
---
v1->v2: *Squash patches 1, 2, 3, and 5 into a single patch.
*Add device specific prefix.
*Remove the brackets around individual numbers. *Make use ofFIELD_PREP()andFIELD_GET(). *Remove a lot of cache values.
*Replace mlock withadc->lock.
*Moveadc->valueread from isr to the completion. *Set pm_runtime_disable/_put_noidle() beforeadc_disable. *Add error handler-err_disable_reg/err_unprepare_clk.v2->v3: *Add "return 0" toadc_runtime_resume().
v1 link:
https://patchwork.kernel.org/project/linux-arm-kernel/patch/[email protected]/drivers/iio/adc/Kconfig | 10 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/imx8qxp-adc.c | 470 ++++++++++++++++++++++++++++++++++ 3 files changed, 481 insertions(+) create mode 100644 drivers/iio/adc/imx8qxp-adc.cdrivers/iio/adc/Kconfig +0
-0@@ -530,6 +530,16 @@ config IMX7D_ADC
....
Quoted 17 lines
drivers/iio/adc/imx8qxp-adc.c new file +11
-0@@ -0,0 +1,470 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* NXP i.MX8QXP ADC driver +* +* Based on the work of Haibo Chen <[email protected]> +* The initial developer of the original code is Haibo Chen. +* Portions created by Haibo Chen are Copyright (C) 2018 NXP. +* All Rights Reserved. +* +* Copyright (C) 2018 NXP +* Copyright (C) 2021 Cai Huoqing
drivers/iio/adc/imx8qxp-adc.c line 21
Quoted 10 lines
drivers/iio/adc/imx8qxp-adc.c new file +10
-0+*/ +#include <linux/bitfield.h> +#include <linux/bits.h> +#include <linux/clk.h> +#include <linux/completion.h> +#include <linux/err.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/delay.h>
Not in alphabetical order.
Quoted 2 lines
drivers/iio/adc/imx8qxp-adc.c new file +2
-0+#include <linux/module.h> +#include <linux/pm_runtime.h>
...
drivers/iio/adc/imx8qxp-adc.c line 262
Quoted 3 lines
drivers/iio/adc/imx8qxp-adc.c new file +3
-0+static irqreturn_t imx8qxp_adc_isr (int irq,void *dev_id) +{ +struct imx8qxp_adc *adc = (struct imx8qxp_adc *)dev_id;
Never any need to explicitly cast from void * in c.
struct imx8qpx_adc *adc = dev_id;
Quoted 12 lines
drivers/iio/adc/imx8qxp-adc.c new file +12
-0+ +u32 fifo_count; + + fifo_count =FIELD_GET (IMX8QXP_ADC_FCTRL_FCOUNT_MASK , +readl (adc->regs +IMX8QXP_ADR_ADC_FCTRL )); + +if (fifo_count) +complete (&adc->completion); + +return IRQ_HANDLED ; +} +
...
Quoted 35 lines
drivers/iio/adc/imx8qxp-adc.c new file +35
-0+ +static int imx8qxp_adc_probe (struct platform_device *pdev) +{ +struct imx8qxp_adc *adc; +struct iio_dev *indio_dev; +struct device *dev = &pdev->dev; +int irq; +int ret; + + indio_dev =devm_iio_device_alloc (dev,sizeof (*adc)); +if (!indio_dev) { +dev_err (dev,"Failed allocating iio device\n" ); +return -ENOMEM ; + } + + adc =iio_priv (indio_dev); + adc->dev = dev; + +mutex_init (&adc->lock); + adc->regs =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (adc->regs)) +return PTR_ERR (adc->regs); + + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) +return irq; + + adc->clk =devm_clk_get (dev,"per" ); +if (IS_ERR (adc->clk)) { + ret =PTR_ERR (adc->clk); +dev_err (dev,"Failed getting clock, err = %d\n" , ret); +return ret; + } + + adc->ipg_clk =devm_clk_get (dev,"ipg" );
drivers/iio/adc/imx8qxp-adc.c line 342
Quoted 10 lines
drivers/iio/adc/imx8qxp-adc.c new file +10
-0+if (IS_ERR (adc->ipg_clk)) { + ret =PTR_ERR (adc->ipg_clk); +dev_err (dev,"Failed getting clock, err = %d\n" , ret); +return ret; + } + + adc->vref =devm_regulator_get (dev,"vref" ); +if (IS_ERR (adc->vref)) { + ret =PTR_ERR (adc->vref); + dev_err(dev,
return dev_err_probe(dev, PTR_ERR(adc->vref), "Failed getting reference voltage\n");
as might be a deferred case and then we don't want errors filling up the log. This function also deals with reporting error codes etc for you. Same for anything else that might be deferred because of driver load ordering (clks for example)
Quoted 37 lines
drivers/iio/adc/imx8qxp-adc.c new file +37
-0+ "Failed getting reference voltage, err = %d\n", ret); +return ret; + } + +platform_set_drvdata (pdev, indio_dev); + +init_completion (&adc->completion); + + indio_dev->name =dev_name (dev); + indio_dev->info = &imx8qxp_adc_iio_info; + indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->channels = imx8qxp_adc_iio_channels; + indio_dev->num_channels =ARRAY_SIZE (imx8qxp_adc_iio_channels); + + ret =devm_request_irq (dev, irq, imx8qxp_adc_isr,0 ,dev_name (dev), adc); +if (ret <0 ) { +dev_err (dev,"Failed requesting irq, irq = %d\n" , irq); +return ret; + } + +imx8qxp_adc_reset (adc); + + ret =iio_device_register (indio_dev); +if (ret) { +imx8qxp_adc_disable (adc); +dev_err (dev,"Couldn't register the device.\n" ); +return ret; + } + +pm_runtime_set_active (dev); +pm_runtime_set_autosuspend_delay (dev,50 ); +pm_runtime_use_autosuspend (dev); +pm_runtime_enable (dev); + +return 0 ; +} +
...
Quoted 13 lines
drivers/iio/adc/imx8qxp-adc.c new file +13
-0+static int imx8qxp_adc_runtime_resume (struct device *dev) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct imx8qxp_adc *adc =iio_priv (indio_dev); +int ret; + + ret =regulator_enable (adc->vref); +if (ret) { +dev_err (dev,"Can't enable adc reference top voltage, err = %d\n" , ret); +return ret; + } + + ret =clk_prepare_enable (adc->clk);
drivers/iio/adc/imx8qxp-adc.c line 434
Quoted 10 lines
drivers/iio/adc/imx8qxp-adc.c new file +10
-0+if (ret) { +dev_err (dev,"Could not prepare or enable clock.\n" ); + goto err_disable_reg; + } + + ret =clk_prepare_enable (adc->ipg_clk); +if (ret) { +dev_err (dev,"Could not prepare or enable clock.\n" ); + goto err_unprepare_clk; + }
Blank lines here (to separate statement + error handler from next statement)
drivers/iio/adc/imx8qxp-adc.c
Quoted 1 line
drivers/iio/adc/imx8qxp-adc.c new file +1
-0+imx8qxp_adc_reset (adc);
here
drivers/iio/adc/imx8qxp-adc.c
Quoted 1 line
drivers/iio/adc/imx8qxp-adc.c new file +1
-0+return 0 ;
and here would help readability (slightly!)
Quoted 9 lines
drivers/iio/adc/imx8qxp-adc.c new file +9
-0+err_unprepare_clk: +clk_disable_unprepare (adc->clk); + +err_disable_reg: +regulator_disable (adc->vref); + +return ret; +} +
...
PATCH v3 2/3 dt-bindings: iio: adc: Add the binding documentation for NXP IMX8QXP ADC
In reply to Cai HuoqingThe NXP i.MX 8QuadXPlus SOC has a new ADC IP, so add the binding documentation for NXP IMX8QXP ADC.
---v1->v2: *Fix some indentation issues.
*Mark status as okay.
*Change clock2 source.
v1 link:
https://patchwork.kernel.org/project/linux-arm-kernel/patch/[email protected]/
.../bindings/iio/adc/nxp,imx8qxp-adc.yaml | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml
Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml new file +85 -0
@@ -0,0 +1,85 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/nxp,imx8qxp-adc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP IMX8QXP ADC bindings + +maintainers: + - Cai Huoqing <[email protected]> + +description: + Supports the ADC found on the IMX8QXP SoC. + +properties: + compatible: + const: nxp,imx8qxp-adc + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 2 + + clock-names: + items: + - const: per + - const: ipg + + assigned-clocks: + maxItems: 1 + + assigned-clocks-rate: + maxItems: 1 + + power-domains: + maxItems: 1 + + status: + const: disable + + "#io-channel-cells": + const: 1 + +required: + - compatible + - reg + - interrupts + - interrupts-parent + - clocks + - clock-names + - assigned-clocks + - assigned-clock-rates + - power-domains + - state + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/firmware/imx/rsrc.h> + soc { + #address-cells = <1>; + #size-cells = <1>; + adc@5a880000 { + compatible = "nxp,imx8qxp-adc"; + reg = <0x0 0x5a880000 0x0 0x10000>; + interrupts = <GIC_SPI 240 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clk IMX_SC_R_ADC_0>, + <&clk IMX_SC_R_ADC_0>; + clock-names = "per", "ipg"; + assigned-clocks = <&clk IMX_SC_R_ADC_0>; + assigned-clock-rates = <24000000>; + power-domains = <&pd IMX_SC_R_ADC_0>; + status = "okay"; + #io-channel-cells = <1>; + }; + }; +...
Signature · 1 line
2.25.1
Rob Herring
maintainerRe: [PATCH v3 2/3] dt-bindings: iio: adc: Add the binding documentation for NXP IMX8QXP ADC
Quoted 11 lines · Cai Huoqing
The NXP i.MX 8QuadXPlus SOC has a new ADC IP, so add the binding documentation for NXP IMX8QXP ADC.
Signed-off-by Cai Huoqing <[email protected]>---
v1->v2: *Fix some indentation issues.
*Mark status as okay.
*Change clock2 source.
v1 link:
https://patchwork.kernel.org/project/linux-arm-kernel/patch/[email protected]/
Quoted 4 lines
.../bindings/iio/adc/nxp,imx8qxp-adc.yaml | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml
My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.example.dt.yaml: soc: adc@5a880000:reg:0: [0, 1518862336, 0, 65536] is too long
From schema: /usr/local/lib/python3.8/dist-packages/dtschema/schemas/reg.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.example.dt.yaml: adc@5a880000: 'interrupts-parent' is a required property
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.example.dt.yaml: adc@5a880000: 'state' is a required property
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.example.dt.yaml: adc@5a880000: '#address-cells' is a required property
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.example.dt.yaml: adc@5a880000: '#size-cells' is a required property
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.example.dt.yaml: adc@5a880000: 'assigned-clock-rates' does not match any of the regexes: 'pinctrl-[0-9]+'
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/patch/1525098
This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit.
Rob Herring
maintainerRe: [PATCH v3 2/3] dt-bindings: iio: adc: Add the binding documentation for NXP IMX8QXP ADC
In reply to Cai HuoqingQuoted 54 lines · Cai Huoqing
The NXP i.MX 8QuadXPlus SOC has a new ADC IP, so add the binding documentation for NXP IMX8QXP ADC.
Signed-off-by Cai Huoqing <[email protected]>---
v1->v2: *Fix some indentation issues.
*Mark status as okay.
*Change clock2 source.
v1 link:
https://patchwork.kernel.org/project/linux-arm-kernel/patch/[email protected]/.../bindings/iio/adc/nxp,imx8qxp-adc.yaml | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yamlDocumentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml new file +33
-0@@ -0,0 +1,85 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/nxp,imx8qxp-adc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP IMX8QXP ADC bindings + +maintainers: + - Cai Huoqing <[email protected]> + +description: + Supports the ADC found on the IMX8QXP SoC. + +properties: + compatible: + const: nxp,imx8qxp-adc + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 2 + + clock-names: + items: + - const: per + - const: ipg + + assigned-clocks:
Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml line 43
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml new file +10
-0+ maxItems: 1 + + assigned-clocks-rate: + maxItems: 1 + + power-domains: + maxItems: 1 + + status: + const: disable
???
You don't need 'status' in bindings. Plus this would cause 'status = "okay"' to cause an error in your dts files.
Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml line 52
Quoted 9 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml new file +9
-0+ + "#io-channel-cells": + const: 1 + +required: + - compatible + - reg + - interrupts + - interrupts-parent
It is valid for interrupt-parent to be in a parent node, so it is never required.
Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml line 58
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml new file +6
-0+ - clocks + - clock-names + - assigned-clocks + - assigned-clock-rates + - power-domains + - state
Not documented.
Quoted 13 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml new file +13
-0+ - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/firmware/imx/rsrc.h> + soc { + #address-cells = <1>; + #size-cells = <1>; + adc@5a880000 {
Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml line 81
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml new file +10
-0+ compatible = "nxp,imx8qxp-adc"; + reg = <0x0 0x5a880000 0x0 0x10000>; + interrupts = <GIC_SPI 240 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clk IMX_SC_R_ADC_0>, + <&clk IMX_SC_R_ADC_0>; + clock-names = "per", "ipg"; + assigned-clocks = <&clk IMX_SC_R_ADC_0>; + assigned-clock-rates = <24000000>; + power-domains = <&pd IMX_SC_R_ADC_0>; + status = "okay";
Remove status from examples.
Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml new file +4
-0+ #io-channel-cells = <1>; + }; + }; +...Signature · 1 line
2.25.1
PATCH v3 3/3 MAINTAINERS: Add the driver info of the NXP IMX8QXP ADC
In reply to Cai HuoqingThe NXP i.MX 8QuadXPlus SOC has a new ADC IP. After adding the driver support for it, I add the driver info of the NXP IMX8QXP ADC to MAINTAINERS file.
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -13475,6 +13475,13 @@ S: Maintained F: Documentation/devicetree/bindings/display/imx/nxp,imx8mq-dcss.yaml F: drivers/gpu/drm/imx/dcss/ +NXP i.MX 8QXP ADC DRIVER +M: Cai Huoqing <[email protected]> +L: [email protected] +S: Supported +F: Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml +F: drivers/iio/adc/imx8qxp-adc.c + NXP PF8100/PF8121A/PF8200 PMIC REGULATOR DEVICE DRIVER M: Jagan Teki <[email protected]> S: Maintained
Signature · 1 line
2.25.1