From patchwork Mon Dec 19 10:13:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bough Chen X-Patchwork-Id: 13076416 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD099C4332F for ; Mon, 19 Dec 2022 10:13:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231438AbiLSKNw (ORCPT ); Mon, 19 Dec 2022 05:13:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231683AbiLSKNs (ORCPT ); Mon, 19 Dec 2022 05:13:48 -0500 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2066.outbound.protection.outlook.com [40.107.22.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C1532DFD; Mon, 19 Dec 2022 02:13:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eu7NtUUArEJ22tWFqEGu2fePDgVRWUBEmKCbBjgQjAPAPzmd7PKQ6mUW/N+jLQMiRrABJhybHcrBiV5CDGNf6t25OMOS088VzfAiWffkZAPFqPHUPTDMEtBhGoafPAZsdws4IpYhiqA12Lr4fxkQI89mO023DkVMMO1Ncxhs8vCzFtNhWgb0ysyvA7BVPUVYcDOrN991F+dggWGz4F8rIJNuhJC6DKadS+U1P2+0PTXINTG0MuKm7FzbxQ1T5GWGgZOWZ1oC/2adq5JwU43U+DlxhitcZj5pywCoNEdV/+fxxxjK7Nc++wuZ4of9KaUg62DGGpP3O6h5nQDgoKHpNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iZe5CIVGsBFmM/6sBy37JYecPphAnK0ahY4LuG2v2hs=; b=m2igtNJlCtlWuhO5TsGy2R+xeODP0I7vLb2qetfvkf4bfcnctK2hKiQX62URnM71zpu0A93vot0OY7/vrY9G7nLUMFI81yNf72b2NiunXBDA695+DlNBNeIgL+oOoKdbZcx7ze51R1Yy1oiPYYLiFIEx6QYJ/6codAfna652WYGL83ZppeIo5ih/NaAIgp1h/nuEJv8/iwcXomBPk3TxU+B/GIbpcpx47fMaLKXleiclNFmbUAsH1C24xR+lW1VHnIzUCdFvaWJhwJp7DyVrjA7xnoDpQevfbIjdKcnqtLIcXgR6yj6/eeYvgZi+np1c1qnYyY3VpsqbhzIv10z2dQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iZe5CIVGsBFmM/6sBy37JYecPphAnK0ahY4LuG2v2hs=; b=OdwbdYl+yxZJ/qchCPN8yPYu00HvxHwpT41IGr4sGZzAwbj45ZCpzBgpI4lN4xFCF1DFUE4nv2IcPGdSk26ZMGTZiuAidy23GdvdUmWmg09nQyOqp5utyf4Z/OyMtidjK5LB8nCDYBEfouvYkKA6Gq8P4oBCoThS/YECS6z7oH0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB7PR04MB4010.eurprd04.prod.outlook.com (2603:10a6:5:21::30) by AM9PR04MB8178.eurprd04.prod.outlook.com (2603:10a6:20b:3e3::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.10; Mon, 19 Dec 2022 10:13:41 +0000 Received: from DB7PR04MB4010.eurprd04.prod.outlook.com ([fe80::7479:76ef:8e5:da0b]) by DB7PR04MB4010.eurprd04.prod.outlook.com ([fe80::7479:76ef:8e5:da0b%6]) with mapi id 15.20.5924.016; Mon, 19 Dec 2022 10:13:39 +0000 From: haibo.chen@nxp.com To: jic23@kernel.org, lars@metafoo.de, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de Cc: festevam@gmail.com, linux-imx@nxp.com, haibo.chen@nxp.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v3 1/3] iio: adc: add imx93 adc support Date: Mon, 19 Dec 2022 18:13:34 +0800 Message-Id: <20221219101336.3929570-2-haibo.chen@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221219101336.3929570-1-haibo.chen@nxp.com> References: <20221219101336.3929570-1-haibo.chen@nxp.com> X-ClientProxiedBy: SI2PR01CA0017.apcprd01.prod.exchangelabs.com (2603:1096:4:191::19) To DB7PR04MB4010.eurprd04.prod.outlook.com (2603:10a6:5:21::30) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4010:EE_|AM9PR04MB8178:EE_ X-MS-Office365-Filtering-Correlation-Id: c01e0f86-303c-4e44-8dd1-08dae1a9b299 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9NNarH1/B/G50+8ZiPSdBR76gaQuJsw1FHgJaRjEJjF7eIcDnqvcD1LBW7Zd325fy/8lGnQb0AX2CO2dMzh6x6Dqr+oY2ct1iOcPvYKZcU1fguoEbJ86ffmMH9g+3oi5z8ak25TXm5WuZguK5f77/jXxI9M3nw5OpfRTG+8e6bim6kX/caau0q2d5V+2FcQzNycA+T3U0C8lw1UgydinM3jMX6nWKlygsxxeFBySa2dtsNRoClPdbf0cYuHJH0eiXrkTTeHJVU26J+NQ2gIUXyZoGNxbgLNrtI1S0bnfDWm1iUHehBFuX1hTnkzKuqmZduBDHiVs4Mhk+0SXc8XBjCJLsOlawBWopgynHBH65HTBxXV0+gZEDTfs7VQMvCtEu21z0EIEiQqwJ/Amun4cOq+WHje4buXaiBcp/SRcA+ngVkfbvQRDnEBmBj3FCyFZSvu8YFR2jos7jcR4mCrCsjYDj0K9nIMqLgDZnd0e7fY+JrGpkheh7cCKXBp+59yPFLYhbUjOKJM++5WoHpWZ7jTw8MAS3TzkMn03svJqCndPv4SdkkvXAbO8uub/M0FAd2Cg9PmEoPlVDGlaqFW2WH0tJjRBjp2lwwxrP7114g4K8BVYZ8fbd/s2WDG+6YtUx7lwVOsywH4sybjdI2JwS7qMbv1l2dYn+3bLdq+Na6KsRpQlsuDTuXBD/pT3olS1gByjlQbdEcl+S0l5RfT+ng== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB7PR04MB4010.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(366004)(396003)(376002)(39860400002)(136003)(451199015)(66556008)(38350700002)(41300700001)(7416002)(66476007)(66946007)(30864003)(8676002)(86362001)(8936002)(6512007)(36756003)(52116002)(26005)(2906002)(478600001)(6666004)(4326008)(186003)(2616005)(83380400001)(1076003)(6506007)(316002)(38100700002)(5660300002)(9686003)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1qoV59v8usOfbPywGlKQ0z0wejafysxB+dXpEmlKGusb2ErpDmq2yLV0mzXwuSoUOVvgaTByx40/JredxIsmdyLihCzn7XV0q5fh6L/s2/aWeAzUb/46CE9GrNev2gZ3tX1oly6XmLK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x5bVsV6q8ZLUh4NFoCadMs9sg6SwMj1RxpZ+DIQSP24OP4Pp5aCKri3hvOpGyG2XunC1kEOiRqmXHcTseAA8jUjSYiaFQAfgq+3gxnq1xaPdfzGvAOf4WiCBCSlvQquVM1B+7tWyaW1F03PwWI1BX85ISjaYy4La+Q71hJXh6Ow2MeucDbf2qQtTiDKO1GuIAsR7fNCj7lI54OjLweZfiOgnyV/wOW2V6B3oI7PcgDeMIrTMUjvNDVpHz26IqjQDj4nYEnaONIwAgVJZUYHj8gmuQCNMjiLZNIYr2RGlYyvJA1IroRkAxJL9IcZvGdr9RPVAsxCojlfcwlOWsEzgP0fvGbrF76blVexaJKPbQKZFeVY7LYPtC5ioJqO X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c01e0f86-303c-4e44-8dd1-08dae1a9b299 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4010.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Dec 2022 10:13:39.1132 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 14oei8KHeo6aENk0V5nMCTD0ydcx21Oekf8jBDH7dFgz/2H6XVhJvz4lQVi8UDii2NLJ2FGclwUE0eroWbMOFw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8178 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Haibo Chen The ADC in i.mx93 is a total new ADC IP, add a driver to support this ADC. Currently, only support one shot normal conversion triggered by software. For other mode, will add in future. Signed-off-by: Haibo Chen --- MAINTAINERS | 4 +- drivers/iio/adc/Kconfig | 10 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/imx93_adc.c | 474 ++++++++++++++++++++++++++++++++++++ 4 files changed, 488 insertions(+), 1 deletion(-) create mode 100644 drivers/iio/adc/imx93_adc.c diff --git a/MAINTAINERS b/MAINTAINERS index 30e032abd196..37431a02cd60 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15020,14 +15020,16 @@ S: Maintained F: Documentation/devicetree/bindings/iio/adc/nxp,imx8qxp-adc.yaml F: drivers/iio/adc/imx8qxp-adc.c -NXP i.MX 7D/6SX/6UL AND VF610 ADC DRIVER +NXP i.MX 7D/6SX/6UL/93 AND VF610 ADC DRIVER M: Haibo Chen L: linux-iio@vger.kernel.org L: linux-imx@nxp.com S: Maintained F: Documentation/devicetree/bindings/iio/adc/fsl,imx7d-adc.yaml F: Documentation/devicetree/bindings/iio/adc/fsl,vf610-adc.yaml +F: Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml F: drivers/iio/adc/imx7d_adc.c +F: drivers/iio/adc/imx93_adc.c F: drivers/iio/adc/vf610_adc.c NXP PF8100/PF8121A/PF8200 PMIC REGULATOR DEVICE DRIVER diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 46c4fc2fc534..4fc826f52b8c 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -565,6 +565,16 @@ config IMX8QXP_ADC This driver can also be built as a module. If so, the module will be called imx8qxp-adc. +config IMX93_ADC + tristate "IMX93 ADC driver" + depends on ARCH_MXC || COMPILE_TEST + depends on HAS_IOMEM + help + Say yes here to build support for IMX93 ADC. + + This driver can also be built as a module. If so, the module will be + called imx93_adc. + config LP8788_ADC tristate "LP8788 ADC driver" depends on MFD_LP8788 diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index 6e08415c3f3a..df8c0f26307d 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -49,6 +49,7 @@ 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_IMX93_ADC) += imx93_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 diff --git a/drivers/iio/adc/imx93_adc.c b/drivers/iio/adc/imx93_adc.c new file mode 100644 index 000000000000..3ea16a70e746 --- /dev/null +++ b/drivers/iio/adc/imx93_adc.c @@ -0,0 +1,474 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * NXP i.MX93 ADC driver + * + * Copyright 2022 NXP + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define IMX93_ADC_DRIVER_NAME "imx93-adc" + +/* Register map definition */ +#define IMX93_ADC_MCR 0x00 +#define IMX93_ADC_MSR 0x04 +#define IMX93_ADC_ISR 0x10 +#define IMX93_ADC_IMR 0x20 +#define IMX93_ADC_CIMR0 0x24 +#define IMX93_ADC_CTR0 0x94 +#define IMX93_ADC_NCMR0 0xA4 +#define IMX93_ADC_PCDR0 0x100 +#define IMX93_ADC_PCDR1 0x104 +#define IMX93_ADC_PCDR2 0x108 +#define IMX93_ADC_PCDR3 0x10c +#define IMX93_ADC_PCDR4 0x110 +#define IMX93_ADC_PCDR5 0x114 +#define IMX93_ADC_PCDR6 0x118 +#define IMX93_ADC_PCDR7 0x11c +#define IMX93_ADC_CALSTAT 0x39C + +/* ADC bit shift */ +#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_ADCLKSE_MASK BIT(8) +#define IMX93_ADC_MCR_PWDN_MASK BIT(0) +#define IMX93_ADC_MSR_CALFAIL_MASK BIT(30) +#define IMX93_ADC_MSR_CALBUSY_MASK BIT(29) +#define IMX93_ADC_MSR_ADCSTATUS_MASK GENMASK(2, 0) +#define IMX93_ADC_ISR_ECH_MASK BIT(0) +#define IMX93_ADC_ISR_EOC_MASK BIT(1) +#define IMX93_ADC_ISR_EOC_ECH_MASK (IMX93_ADC_ISR_EOC_MASK | \ + IMX93_ADC_ISR_ECH_MASK) +#define IMX93_ADC_IMR_JEOC_MASK BIT(3) +#define IMX93_ADC_IMR_JECH_MASK BIT(2) +#define IMX93_ADC_IMR_EOC_MASK BIT(1) +#define IMX93_ADC_IMR_ECH_MASK BIT(0) +#define IMX93_ADC_PCDR_CDATA_MASK GENMASK(11, 0) + +/* ADC status */ +#define IMX93_ADC_IDLE 0 +#define IMX93_ADC_POWER_DOWN 1 +#define IMX93_ADC_WAIT_STATE 2 +#define IMX93_ADC_BUSY_IN_CALIBRATION 3 +#define IMX93_ADC_SAMPLE 4 +#define IMX93_ADC_CONVERSION 6 + +#define IMX93_ADC_TIMEOUT msecs_to_jiffies(100) + +struct imx93_adc { + struct device *dev; + void __iomem *regs; + struct clk *ipg_clk; + int irq; + struct regulator *vref; + /* lock to protect against multiple access to the device */ + struct mutex lock; + struct completion completion; +}; + +#define IMX93_ADC_CHAN(_idx) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = (_idx), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ +} + +static const struct iio_chan_spec imx93_adc_iio_channels[] = { + IMX93_ADC_CHAN(0), + IMX93_ADC_CHAN(1), + IMX93_ADC_CHAN(2), + IMX93_ADC_CHAN(3), +}; + +static void imx93_adc_power_down(struct imx93_adc *adc) +{ + u32 mcr, msr; + int ret; + + mcr = readl(adc->regs + IMX93_ADC_MCR); + mcr |= FIELD_PREP(IMX93_ADC_MCR_PWDN_MASK, 1); + writel(mcr, adc->regs + IMX93_ADC_MCR); + + ret = readl_poll_timeout(adc->regs + IMX93_ADC_MSR, msr, + ((msr & IMX93_ADC_MSR_ADCSTATUS_MASK) == IMX93_ADC_POWER_DOWN), 1, 50); + if (ret == -ETIMEDOUT) + dev_warn(adc->dev, + "ADC do not in power down mode, current MSR is %x\n", + msr); +} + +static void imx93_adc_power_up(struct imx93_adc *adc) +{ + u32 mcr; + + /* bring ADC out of power down state, in idle state */ + mcr = readl(adc->regs + IMX93_ADC_MCR); + mcr &= ~FIELD_PREP(IMX93_ADC_MCR_PWDN_MASK, 1); + writel(mcr, adc->regs + IMX93_ADC_MCR); +} + +static void imx93_adc_config_ad_clk(struct imx93_adc *adc) +{ + u32 mcr; + + /* put adc in power down mode */ + imx93_adc_power_down(adc); + + /* config the AD_CLK equal to bus clock */ + mcr = readl(adc->regs + IMX93_ADC_MCR); + mcr |= FIELD_PREP(IMX93_ADC_MCR_ADCLKSE_MASK, 1); + writel(mcr, adc->regs + IMX93_ADC_MCR); + + imx93_adc_power_up(adc); +} + +static int imx93_adc_calibration(struct imx93_adc *adc) +{ + u32 mcr, msr; + int ret; + + /* make sure ADC in power down mode */ + imx93_adc_power_down(adc); + + /* config SAR controller operating clock */ + mcr = readl(adc->regs + IMX93_ADC_MCR); + 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. + */ + + /* run calibration */ + mcr = readl(adc->regs + IMX93_ADC_MCR); + mcr |= FIELD_PREP(IMX93_ADC_MCR_CALSTART_MASK, 1); + writel(mcr, adc->regs + IMX93_ADC_MCR); + + /* wait calibration to be finished */ + ret = readl_poll_timeout(adc->regs + IMX93_ADC_MSR, msr, + !(msr & IMX93_ADC_MSR_CALBUSY_MASK), 1000, 2000000); + if (ret == -ETIMEDOUT) { + dev_warn(adc->dev, "ADC do not finish calibration in 1 min!\n"); + return ret; + } + + /* check whether calbration is success or not */ + msr = readl(adc->regs + IMX93_ADC_MSR); + if (msr & IMX93_ADC_MSR_CALFAIL_MASK) { + dev_warn(adc->dev, "ADC calibration failed!\n"); + return -EAGAIN; + } + + return 0; +} + +static int imx93_adc_read_channel_conversion(struct imx93_adc *adc, + int channel_number, + int *result) +{ + u32 channel; + u32 imr, mcr, pcda; + long ret; + + reinit_completion(&adc->completion); + + /* config channel mask register */ + channel = 1 << channel_number; + writel(channel, adc->regs + IMX93_ADC_NCMR0); + + /* TODO: can config desired sample time in CTRn if need */ + + /* config interrupt mask */ + imr = FIELD_PREP(IMX93_ADC_IMR_EOC_MASK, 1); + writel(imr, adc->regs + IMX93_ADC_IMR); + writel(channel, adc->regs + IMX93_ADC_CIMR0); + + /* config one-shot mode */ + mcr = readl(adc->regs + IMX93_ADC_MCR); + mcr &= ~FIELD_PREP(IMX93_ADC_MCR_MODE_MASK, 1); + writel(mcr, adc->regs + IMX93_ADC_MCR); + + /* start normal conversion */ + mcr = readl(adc->regs + IMX93_ADC_MCR); + mcr |= FIELD_PREP(IMX93_ADC_MCR_NSTART_MASK, 1); + writel(mcr, adc->regs + IMX93_ADC_MCR); + + ret = wait_for_completion_interruptible_timeout(&adc->completion, + IMX93_ADC_TIMEOUT); + if (ret == 0) + return -ETIMEDOUT; + + if (ret < 0) + return ret; + + pcda = readl(adc->regs + IMX93_ADC_PCDR0 + channel_number * 4); + + *result = FIELD_GET(IMX93_ADC_PCDR_CDATA_MASK, pcda); + + return ret; +} + +static int imx93_adc_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct imx93_adc *adc = iio_priv(indio_dev); + struct device *dev = adc->dev; + long ret; + u32 vref_uv; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + pm_runtime_get_sync(dev); + mutex_lock(&adc->lock); + ret = imx93_adc_read_channel_conversion(adc, chan->channel, val); + mutex_unlock(&adc->lock); + pm_runtime_mark_last_busy(dev); + pm_runtime_put_sync_autosuspend(dev); + if (ret > 0) + return IIO_VAL_INT; + else + return ret; + + case IIO_CHAN_INFO_SCALE: + ret = vref_uv = regulator_get_voltage(adc->vref); + if (ret < 0) + return ret; + *val = vref_uv / 1000; + *val2 = 12; + return IIO_VAL_FRACTIONAL_LOG2; + + case IIO_CHAN_INFO_SAMP_FREQ: + *val = clk_get_rate(adc->ipg_clk); + return IIO_VAL_INT; + + default: + return -EINVAL; + } +} + +static irqreturn_t imx93_adc_isr(int irq, void *dev_id) +{ + struct imx93_adc *adc = dev_id; + u32 isr, eoc, unexpected; + + isr = readl(adc->regs + IMX93_ADC_ISR); + + if (FIELD_GET(IMX93_ADC_ISR_EOC_ECH_MASK, isr)) { + eoc = isr & IMX93_ADC_ISR_EOC_ECH_MASK; + writel(eoc, adc->regs + IMX93_ADC_ISR); + complete(&adc->completion); + } + + unexpected = isr & ~IMX93_ADC_ISR_EOC_ECH_MASK; + if (unexpected) { + writel(unexpected, adc->regs + IMX93_ADC_ISR); + dev_err(adc->dev, "Unexpected interrupt 0x%08x.\n", unexpected); + return IRQ_NONE; + } + + return IRQ_HANDLED; +} + +static const struct iio_info imx93_adc_iio_info = { + .read_raw = &imx93_adc_read_raw, +}; + +static int imx93_adc_probe(struct platform_device *pdev) +{ + struct imx93_adc *adc; + struct iio_dev *indio_dev; + struct device *dev = &pdev->dev; + 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); + + /* The third irq is for ADC conversion usage */ + adc->irq = platform_get_irq(pdev, 2); + if (adc->irq < 0) + return adc->irq; + + adc->ipg_clk = devm_clk_get(dev, "ipg"); + if (IS_ERR(adc->ipg_clk)) + return dev_err_probe(dev, PTR_ERR(adc->ipg_clk), + "Failed getting clock.\n"); + + adc->vref = devm_regulator_get(dev, "vref"); + if (IS_ERR(adc->vref)) + return dev_err_probe(dev, PTR_ERR(adc->vref), + "Failed getting reference voltage.\n"); + + ret = regulator_enable(adc->vref); + if (ret) { + dev_err(dev, "Can't enable adc reference top voltage.\n"); + return ret; + } + + platform_set_drvdata(pdev, indio_dev); + + init_completion(&adc->completion); + + indio_dev->name = IMX93_ADC_DRIVER_NAME; + indio_dev->info = &imx93_adc_iio_info; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = imx93_adc_iio_channels; + indio_dev->num_channels = ARRAY_SIZE(imx93_adc_iio_channels); + + ret = clk_prepare_enable(adc->ipg_clk); + if (ret) { + dev_err(&pdev->dev, "Could not prepare or enable the clock.\n"); + goto error_regulator_disable; + } + + ret = request_irq(adc->irq, imx93_adc_isr, 0, IMX93_ADC_DRIVER_NAME, adc); + if (ret < 0) { + dev_err(dev, "Failed requesting irq, irq = %d\n", adc->irq); + goto error_ipg_clk_disable; + } + + ret = imx93_adc_calibration(adc); + if (ret < 0) + goto error_free_adc_irq; + + imx93_adc_config_ad_clk(adc); + + ret = iio_device_register(indio_dev); + if (ret) { + dev_err(dev, "Couldn't register the device.\n"); + goto error_free_adc_irq; + } + + pm_runtime_set_active(dev); + pm_runtime_set_autosuspend_delay(dev, 50); + pm_runtime_use_autosuspend(dev); + pm_runtime_enable(dev); + + return 0; + +error_free_adc_irq: + free_irq(adc->irq, adc); +error_ipg_clk_disable: + clk_disable_unprepare(adc->ipg_clk); +error_regulator_disable: + regulator_disable(adc->vref); + + return ret; +} + +static int imx93_adc_remove(struct platform_device *pdev) +{ + struct iio_dev *indio_dev = platform_get_drvdata(pdev); + struct imx93_adc *adc = iio_priv(indio_dev); + struct device *dev = adc->dev; + + /* adc power down need clock on */ + pm_runtime_get_sync(dev); + imx93_adc_power_down(adc); + + pm_runtime_disable(dev); + pm_runtime_put_noidle(dev); + iio_device_unregister(indio_dev); + free_irq(adc->irq, adc); + clk_disable_unprepare(adc->ipg_clk); + regulator_disable(adc->vref); + + return 0; +} + +static int imx93_adc_runtime_suspend(struct device *dev) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct imx93_adc *adc = iio_priv(indio_dev); + + imx93_adc_power_down(adc); + clk_disable_unprepare(adc->ipg_clk); + regulator_disable(adc->vref); + + return 0; +} + +static int imx93_adc_runtime_resume(struct device *dev) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct imx93_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->ipg_clk); + if (ret) { + dev_err(dev, "Could not prepare or enable clock.\n"); + goto err_disable_reg; + } + + imx93_adc_power_up(adc); + + return 0; + +err_disable_reg: + regulator_disable(adc->vref); + + return ret; +} + +static DEFINE_RUNTIME_DEV_PM_OPS(imx93_adc_pm_ops, + imx93_adc_runtime_suspend, + imx93_adc_runtime_resume, NULL); + +static const struct of_device_id imx93_adc_match[] = { + { .compatible = "nxp,imx93-adc", }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, imx93_adc_match); + +static struct platform_driver imx93_adc_driver = { + .probe = imx93_adc_probe, + .remove = imx93_adc_remove, + .driver = { + .name = IMX93_ADC_DRIVER_NAME, + .of_match_table = imx93_adc_match, + .pm = pm_ptr(&imx93_adc_pm_ops), + }, +}; + +module_platform_driver(imx93_adc_driver); + +MODULE_DESCRIPTION("NXP i.MX93 ADC driver"); +MODULE_AUTHOR("Haibo Chen "); +MODULE_LICENSE("GPL"); From patchwork Mon Dec 19 10:13:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bough Chen X-Patchwork-Id: 13076417 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CECEC3DA79 for ; Mon, 19 Dec 2022 10:13:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231618AbiLSKNy (ORCPT ); Mon, 19 Dec 2022 05:13:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229519AbiLSKNt (ORCPT ); Mon, 19 Dec 2022 05:13:49 -0500 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2066.outbound.protection.outlook.com [40.107.22.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A08D65FE; Mon, 19 Dec 2022 02:13:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DexNeplrBRv8E2I23unhlqqpwdGtE+D5p898fIbUfeFJOcbGAUuFEtvtmiboe4/DPlxuRPk/hLhC8BmRZ8rk1WWRw0IaQonjsZpO/Rxd9yQIIBfxgr7ToXEGXrOqOAKI80y7zj78kXQVsPLDwnSW4FxiG6MOmdjjSSLLk7CQLgMyDYwrWhi4+hZRX46yXIM984xnf6UnK8C2znpDNJWkVToKrd8eTAvQSevA8A7DaANU3+0sqyX/Nl6V3fDqNVTV9qykEyLbB0rTdsQTeaCBS565abIz7+mBawKTjdFAjaCmxPbywW8wTZvQ5NyIRR/Ymz6UZHEmiwQIgMAXJTSb/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mYurfjzNhiWkHbQ+7z+h/M2VnO0svQn1uAjsmbnOFB4=; b=JaU/bNkePlA1NzCRB9q4X/zjx19ZwiYHAs7cjr2D+H8YY3GwZG8gyHjqyR/D0X3rqu9BWJSCw813WVkbXteZLHu8yFrcq01Z9y9IAZgwYO8Rj5xqhRgDlA7ZGgQLRKS8JSqh/x0AnBCkt9HvhiCynRO8z9x5W+lZSyhStfJrtZtQzBtM3laQkSSe1VzfGs8KgS4Ocb/7WOHdvsWTULdrtKOnMz03puLW4rLMWSCmnP3grDgxIP0hbcfmehS/Wb4veGqmZv9Z7Ow1jCDj0B8xiqHJBekwOAjUJHcbzsD4eCCsS3gSw9BKp+cCysDcphbO0mJ2sOxkD4fGEr2sUtgF/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mYurfjzNhiWkHbQ+7z+h/M2VnO0svQn1uAjsmbnOFB4=; b=XkhGwLRXwBEzP8tRUyLpLy7WtnFBYjeYn8ayowXogweAbAVXPg7nhFQkNGY4O/MCRVdYo+yov4Vqtkml7Iwg49sorrkhX1CsgLA+FpnSYMGz1j9WMhDap1JfTxajRIdTT2IvyNdjJmdDatDHnI3UThs5ygXsY12Y0LDJ9XLJQfA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB7PR04MB4010.eurprd04.prod.outlook.com (2603:10a6:5:21::30) by AM9PR04MB8178.eurprd04.prod.outlook.com (2603:10a6:20b:3e3::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.10; Mon, 19 Dec 2022 10:13:43 +0000 Received: from DB7PR04MB4010.eurprd04.prod.outlook.com ([fe80::7479:76ef:8e5:da0b]) by DB7PR04MB4010.eurprd04.prod.outlook.com ([fe80::7479:76ef:8e5:da0b%6]) with mapi id 15.20.5924.016; Mon, 19 Dec 2022 10:13:43 +0000 From: haibo.chen@nxp.com To: jic23@kernel.org, lars@metafoo.de, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de Cc: festevam@gmail.com, linux-imx@nxp.com, haibo.chen@nxp.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v3 2/3] dt-bindings: iio: adc: Add binding documentation for NXP IMX93 ADC Date: Mon, 19 Dec 2022 18:13:35 +0800 Message-Id: <20221219101336.3929570-3-haibo.chen@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221219101336.3929570-1-haibo.chen@nxp.com> References: <20221219101336.3929570-1-haibo.chen@nxp.com> X-ClientProxiedBy: SI2PR01CA0017.apcprd01.prod.exchangelabs.com (2603:1096:4:191::19) To DB7PR04MB4010.eurprd04.prod.outlook.com (2603:10a6:5:21::30) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4010:EE_|AM9PR04MB8178:EE_ X-MS-Office365-Filtering-Correlation-Id: ddc8aeec-a0d6-4c0a-2ba9-08dae1a9b4eb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4nCOLMz3t+geX9prXaZ6VDGU6DrQ8mcmRJZhTy1DtNZJw5xFwJi8iRdFf8KkieQIRj28zRO8NGyORvXWgIiv7mR2ggYxN3SsNz+lRK2+OY5/RvsMX8+4vu/j15+iJ2jcfGIPHUxkeSITI180Pcc6Gnpt021Q7q8vXnts/Csn+9lyaoRRIep+ivctEzVFW19D9NTvJR+jccf3OFcxXGPQyFsaI5HT4BciHQV0x4sVbKFXVR4sPjoVHAf4CTY06WncnPxv/r+2POz4vKAYng8P/W25Jvnw3P3Y9ZlUkF8hOFly2NBckKUPs0h6ESgZF1Z825QzpKeB2j9sj++rrbUAW7l3O55oWjwJhCbDRRC3gjNN8+SygxCBzHPb7ty+Ak/0lZ2tjwLSvlQVbcFhAh8pgpQOLAuqmW3jhkJZyeGB6BTSths+uBGkGDzvKNVAuWzw5JFBY7y5H6hIF/730eOLJDL2aME1khYdKMqSrPlxXEKZHVl4AnIJqtuzJ6659LZ4WKg1wpfigyosGqBhcK1pB9+hjt3dWMgYKCkf36+6X4bLfAYCkkmVKduJqVGwji/X7+13Owj4bHJVEzb5zErjkNAawAEfr5UQfQA05w97xmi3LiDxExHVtk0K5IaGVvZ3//9R0aUx6WjdBdaSjzCSfDLd8Tf/OXQvXEB0NnI1SG2Z837joCJXpnrWHK9XRp8d2USk/jrOXwQn3eGTiUb/FJIYcK+hyzDyh4skgJTNxMyMtRMDqc2ZbOIQ5IiBYrL2y3HrMbPVhAR60Ko++pWLbg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB7PR04MB4010.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(366004)(396003)(376002)(39860400002)(136003)(451199015)(66556008)(38350700002)(41300700001)(7416002)(66476007)(66946007)(8676002)(86362001)(8936002)(6512007)(36756003)(52116002)(26005)(2906002)(478600001)(6666004)(4326008)(186003)(2616005)(83380400001)(1076003)(6506007)(316002)(966005)(38100700002)(5660300002)(9686003)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TbN8lwDzHsn7vlow75264+z0q1hrWVmjDskigJnBdRc5eDZYbovqJgTW9PXzxqkKzKiD60haJg8z63r6v5x5WGht6urJNU8Qgx+kF08PVgTlpE8nfvcoFSpezSIPL/gChW4B/H6t4Bkhd6adZAddUgSP6ly9L9eRlCvk96qZ5BEvIiFbUQ6NEF2VHEqE/5Oqw3AvNaGnM9BPZWUKPf4HSaZc0l9dp8i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WS46A9X6nvsrA7gBoxVaqMHAlZOaAYY7B2pVIuJC7jfPUH7mrLCaKRcv7r0kUFGsGLSk53k54JCwNjDi2QGKilCB9GlXaGAUxzN27Ylv+8dBfbGFr6mCtl0UHwpDXstnU/gGBsZG6BvHL3ls2/KIxudeih74QLNi4YYGyWCCHbmEDcE/lFFMpxtUHdYeLBIOQ6uwt2RTibu0V3pUduN7x0bwVSbc3pNq8+KZ/Katlvjl0Aw0Iik/VuR9h5+wUDYRPAWKsZxzzSIucziEoYlYW37M7Fxzue2uI2RCF+pya X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ddc8aeec-a0d6-4c0a-2ba9-08dae1a9b4eb X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4010.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Dec 2022 10:13:42.9254 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wMxbAPiJ9IU+rrBnTtfnsTYygQ4TksaXvofdy/XvV1AOOlgHx9GTw9hP77urDzoH1Jx2Q6jfqBcUMd/OOzylhQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8178 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Haibo Chen The IMX93 SoC has a new ADC IP, so add binding documentation for NXP IMX93 ADC. Signed-off-by: Haibo Chen Reviewed-by: Rob Herring --- .../bindings/iio/adc/nxp,imx93-adc.yaml | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml diff --git a/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml b/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml new file mode 100644 index 000000000000..dacc526dc695 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/adc/nxp,imx93-adc.yaml @@ -0,0 +1,81 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/nxp,imx93-adc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP iMX93 ADC + +maintainers: + - Haibo Chen + +description: + The ADC on iMX93 is a 8-channel 12-bit 1MS/s ADC with 4 channels + connected to pins. it support normal and inject mode, include + One-Shot and Scan (continuous) conversions. Programmable DMA + enables for each channel Also this ADC contain alternate analog + watchdog thresholds, select threshold through input ports. And + also has Self-test logic and Software-initiated calibration. + +properties: + compatible: + const: nxp,imx93-adc + + reg: + maxItems: 1 + + interrupts: + items: + - description: WDGnL, watchdog threshold interrupt requests. + - description: WDGnH, watchdog threshold interrupt requests. + - description: normal conversion, include EOC (End of Conversion), + ECH (End of Chain), JEOC (End of Injected Conversion) and + JECH (End of injected Chain). + - description: Self-testing Interrupts. + + clocks: + maxItems: 1 + + clock-names: + const: ipg + + vref-supply: + description: + The reference voltage which used to establish channel scaling. + + "#io-channel-cells": + const: 1 + +required: + - compatible + - reg + - interrupts + - clocks + - clock-names + - vref-supply + - "#io-channel-cells" + +additionalProperties: false + +examples: + - | + #include + #include + #include + soc { + #address-cells = <1>; + #size-cells = <1>; + adc@44530000 { + compatible = "nxp,imx93-adc"; + reg = <0x44530000 0x10000>; + interrupts = , + , + , + ; + clocks = <&clk IMX93_CLK_ADC1_GATE>; + clock-names = "ipg"; + vref-supply = <®_vref_1v8>; + #io-channel-cells = <1>; + }; + }; +... From patchwork Mon Dec 19 10:13:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bough Chen X-Patchwork-Id: 13076418 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 199ABC4332F for ; Mon, 19 Dec 2022 10:14:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229528AbiLSKN6 (ORCPT ); Mon, 19 Dec 2022 05:13:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231663AbiLSKNu (ORCPT ); Mon, 19 Dec 2022 05:13:50 -0500 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2066.outbound.protection.outlook.com [40.107.22.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90503A444; Mon, 19 Dec 2022 02:13:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cIgitW3Dgm6z4ToVL3HUdOPktTZ2ZJ0+gDl4cZbnuomd/2SzkmSzrYaSPT3GnWTJm8H0spbyJuCTetM35N5IPLiR9/p0go8nFEbQtPbCJ/wecryWIFg/4RxIU/7WuW8Yixt2IZjPbycDZv2VVhFfl802FSL8M8T3I3JwMLMTn/PyFO7CXMouo0mZOA2u8L+tGK/gt9OZHOE7xfbqCtkJL8FCzezMlqpwae37gSsvVtfZGsaK8DBMbLqroFOywbusKSdMmremuyP7CcYHpTglxOAvMJhq0SXZiXvfwowpSyZHa4GrUTyUn9oh+HmqLL/uu7vRWAdCW/c1dugezBvopA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mnF4qNwlp9kJu26GVY9c+6QFxVEYVdoAp364itOFTKg=; b=AdWR1mnTLPf4xE7t+ODPMFiYQIXjCt0DGO0tzA76Yqb5dc49rSRSTNF2HkW7yIFVG0SnSgJYFzPZewrc/jcP8UtAEpt6P6rrs/YyyxVEKwbrLmLFwkyLb2uCwMRWDySM4sO28Jl5w8qjzOWRhgocaewSzQx0/6a8iKfxqwLnWphajgn0G4Ozq5TBn/pA1gAuWJIC38hL/fSXVHpI8kydtUfXuNdptWTTGK/EF+LehIEE0U9vokMZr2ER62PLhLUVU9BSZp3DsDJnsV2w5UB31hdDM9qhp+UABVLNauCehZkZfokOLjHCeOO6t4Bd3H0GSqVyVzKqKgKEpD2jLqn8VA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mnF4qNwlp9kJu26GVY9c+6QFxVEYVdoAp364itOFTKg=; b=JmLS7tvVlmbQJfUgiasuPv/YQeGFV555KfEvVr5ypNHFIBEWFo1fmZKzVolTnrmd+j1CZxcbuL0zTn3Wd1qQ89TntzmrlSXQ71d+aO4k/AdHhvPT9UtwxC10cxf8HH/lyXz46u99p1gbg45cz6KLzHqObmPszN7/NHv7hvuyLSA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB7PR04MB4010.eurprd04.prod.outlook.com (2603:10a6:5:21::30) by AM9PR04MB8178.eurprd04.prod.outlook.com (2603:10a6:20b:3e3::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.10; Mon, 19 Dec 2022 10:13:46 +0000 Received: from DB7PR04MB4010.eurprd04.prod.outlook.com ([fe80::7479:76ef:8e5:da0b]) by DB7PR04MB4010.eurprd04.prod.outlook.com ([fe80::7479:76ef:8e5:da0b%6]) with mapi id 15.20.5924.016; Mon, 19 Dec 2022 10:13:46 +0000 From: haibo.chen@nxp.com To: jic23@kernel.org, lars@metafoo.de, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de Cc: festevam@gmail.com, linux-imx@nxp.com, haibo.chen@nxp.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v3 3/3] arm64: dts: imx93: add ADC support Date: Mon, 19 Dec 2022 18:13:36 +0800 Message-Id: <20221219101336.3929570-4-haibo.chen@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221219101336.3929570-1-haibo.chen@nxp.com> References: <20221219101336.3929570-1-haibo.chen@nxp.com> X-ClientProxiedBy: SI2PR01CA0017.apcprd01.prod.exchangelabs.com (2603:1096:4:191::19) To DB7PR04MB4010.eurprd04.prod.outlook.com (2603:10a6:5:21::30) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4010:EE_|AM9PR04MB8178:EE_ X-MS-Office365-Filtering-Correlation-Id: beff18b8-27ee-41b5-de03-08dae1a9b730 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SzofJELxbtuO5RncnoqgvLvHgyV6OdCHKdjV87Q1CCx6FaJkgKRsbnjudsy+0ECNUB0iweO1esrmKj/7SzaxSh2Vo8miLZLHhbKtHeECESvYGZEspTPKOE1pdMOx1LgND1YAn41W4Z7vj39MxzNxbd4EHaqD4xRiuT65JLhwbPZPC0KwPMtRLpaxMVbJtz2SmeyCqy42bCCJaqNk4h0V7XwAP4cylToXDV77Ic2vgAt8XLnXUpOpW8IPNxrlFPCVUcvh77+YH0av7bPW7+SoTpDWcdlK36NFLYUW5njexPZNX1EvfXCNbUu4rmm440J5WMQ9Oi+R5cq1yoG/Y5/FD0Bk14bdSv74yxlTBF6lAWWIzYcRz6a2vSeSEloOTrVsDhi5c/qI/TV3wAfqFAbw5CexPwlW9tc86enluOFmGynUyvdkokO0/rGSz6KXGFkHX1jEs22waDUHVrcHAInSdYw81qC0ZsN93EKEucs2NfG292v1n24YsmkJ09JAmQdvbNSyRMy38MQMWmWargBwdBCWOEjDknFnhPOnppeO5ykR3MueyRfI1avHGRrtviiwYiPoUn91RSKqBhW6GztB27b4h9EsjgFLSOlPsmDN0V7zMdDSbGTnW3AgAyEtOwS/crbwAnJllw/iTbmVsBbTU3xQYZA2PGJkY/kGOuqxEoYKY4myYM8vjcHjm0nwjXRl X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB7PR04MB4010.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(366004)(396003)(376002)(39860400002)(136003)(451199015)(66556008)(38350700002)(41300700001)(7416002)(66476007)(66946007)(8676002)(86362001)(8936002)(6512007)(36756003)(52116002)(26005)(2906002)(478600001)(6666004)(4326008)(186003)(2616005)(83380400001)(1076003)(6506007)(316002)(38100700002)(5660300002)(9686003)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uKbJ+9/yfM8ZfwgNv4+aMClGwkfs602iPNELXCeN3WsmMsVJu2AvodY8aNCpk8tFyfVhPhp3O8cl7SQX/EdSYI8o5mQmzWvWzswhR9bCIoAgT40Eoua/UMF1vRYP2ZvHK2VplqflrxxLG2x/R4cQfsgwGwr+2hW2zH40pISwQO0xYJKgzP/8KDFw/vLV0PL4M8lpEJkqosLcSHb6ghzt6nSspQLlaXfNPVEzCggv9SR6i0Rnv2LthOGsmimIthqlxi0GCxhT7ZBNiNeuG5Nw8nQedc7j5edvLYFcfR0r7010/tkyI6x6GPRT7RUdEeICptUsPGbfiLowxg51G7QJ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VsAPjl2lDYYVh1+90vHvIowb8oNSClETAdBAsnPcRdiUlwNoWHVOe4rUe9AOvzTQegqAL4Y4ISFIOcQH/jPAcNr22/wg7iSDqDcEtnT/OyegnI902ot5XjsEohW1iqa5MY0HyaMGdrbNVL6X9ag+tOAWuEXWOLX5mGXP9OEHkMTe X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: beff18b8-27ee-41b5-de03-08dae1a9b730 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4010.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Dec 2022 10:13:46.7220 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nRaHyePqyYpBDeLIqqX06hpDfpYUDhjBxkWDN5Nbg6uMPdD8HUwqzF1NDc27PYo2Jr22KnzTnKvADNsv5TWgmQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8178 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Haibo Chen Add ADC support for imx93-11x11-evk board. Signed-off-by: Haibo Chen --- arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts | 12 ++++++++++++ arch/arm64/boot/dts/freescale/imx93.dtsi | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts b/arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts index 69786c326db0..cab5f4d66bf9 100644 --- a/arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts +++ b/arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts @@ -15,6 +15,13 @@ chosen { stdout-path = &lpuart1; }; + reg_vref_1v8: regulator-adc-vref { + compatible = "regulator-fixed"; + regulator-name = "vref_1v8"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + }; + reg_usdhc2_vmmc: regulator-usdhc2 { compatible = "regulator-fixed"; pinctrl-names = "default"; @@ -27,6 +34,11 @@ reg_usdhc2_vmmc: regulator-usdhc2 { }; }; +&adc1 { + vref-supply = <®_vref_1v8>; + status = "okay"; +}; + &mu1 { status = "okay"; }; diff --git a/arch/arm64/boot/dts/freescale/imx93.dtsi b/arch/arm64/boot/dts/freescale/imx93.dtsi index 5d79663b3b84..a0d39dd34591 100644 --- a/arch/arm64/boot/dts/freescale/imx93.dtsi +++ b/arch/arm64/boot/dts/freescale/imx93.dtsi @@ -266,6 +266,19 @@ anatop: anatop@44480000 { compatible = "fsl,imx93-anatop", "syscon"; reg = <0x44480000 0x10000>; }; + + adc1: adc@44530000 { + compatible = "nxp,imx93-adc"; + reg = <0x44530000 0x10000>; + interrupts = , + , + , + ; + clocks = <&clk IMX93_CLK_ADC1_GATE>; + clock-names = "ipg"; + #io-channel-cells = <1>; + status = "disabled"; + }; }; aips2: bus@42000000 {