From patchwork Mon Dec 26 04:27:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bough Chen X-Patchwork-Id: 636893 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 0334BC4708D for ; Mon, 26 Dec 2022 04:27:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229727AbiLZE04 (ORCPT ); Sun, 25 Dec 2022 23:26:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229975AbiLZE0y (ORCPT ); Sun, 25 Dec 2022 23:26:54 -0500 Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2080.outbound.protection.outlook.com [40.107.103.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24D121115; Sun, 25 Dec 2022 20:26:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G9dsuTyojT/NRxuGmooSigzQLrMwyeWYw5Lv+NQietLxTqXPtF4ngGoOXPAXcdPGNXMC0GgkSC4H1G2wnL6SNuVxFfu8RweJiRRVH6pFx5JCcD/05CPao1Mz2HiMCY8H8IfD5w3W47KVlsOWb3BgcIKdI1G75tA7De5JQlFxMh88q/oUsCtC+sad8XBJpuKN5H0nENWvNVv+2QYuELhPlX8FFHSmUCODGOPuEbRNX8qTFVASa4FTmTaZSV6tnVGq2WEtpCVm0S0vITloNcIqpjpqMqrUxUa4Ro9TT/jpxHQTUkxqKAn2VU4LuHmKi5zsebSReNP/mS/QvBeIexbHyA== 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=s8WeXELn6TnZVeuuEkba6D7BiyPx6EU4LMOE7On2Mmc=; b=R/MMjBYgVFwUa0y12Jjvb0qn5PzThTxv07KQ1WkdpaGZ7UHnRDEVH3jkxmsM7LBbhxlZaDOP/WK6jLEY4SDMXfhu0dlhXQdeWlVfl4ANQ9qSSh13pmpg9yHC2t0GHMtD/2APp8mKqFaaLMi+4zuN7YoMcPlS6lqrX5kosbGXkII+0JVERnJcvzGpGkzvxFRYyru77Soeb2IU3OfcQJZmp8A4XRcwFmPVxj08ON7r4x+oUXyFqskFKsIvwXuBRsyIhjtTwiQfE/dMvpFE3cEHZh0vOCLnSeCrTZLpQ4BVZLcfxuqRu7Q0vx/cPXJZeeN1xlp0Md9JQbH8JJsWwZXHXQ== 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=s8WeXELn6TnZVeuuEkba6D7BiyPx6EU4LMOE7On2Mmc=; b=pI0aqvwn8xRyrOYvokJtv872fchSvb2c9D4RBIY29tYA1oYipfzoLBbaW/7s4rJF19DQFAQn9Cg6tsH2i//N+hKtKSuqpj0kHy3NBUBtSM03m7kgB6l/ItaH4BtmrKMTOYw0OPhOnKeiChB+QISauKyXi+52rO+/yJVvOYmbKaU= 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 PA4PR04MB7792.eurprd04.prod.outlook.com (2603:10a6:102:c0::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.16; Mon, 26 Dec 2022 04:26:48 +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.5944.016; Mon, 26 Dec 2022 04:26:48 +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 Cc: kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, haibo.chen@nxp.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v4 1/3] iio: adc: add imx93 adc support Date: Mon, 26 Dec 2022 12:27:17 +0800 Message-Id: <20221226042719.694659-2-haibo.chen@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221226042719.694659-1-haibo.chen@nxp.com> References: <20221226042719.694659-1-haibo.chen@nxp.com> X-ClientProxiedBy: SI2PR04CA0012.apcprd04.prod.outlook.com (2603:1096:4:197::14) To DB7PR04MB4010.eurprd04.prod.outlook.com (2603:10a6:5:21::30) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4010:EE_|PA4PR04MB7792:EE_ X-MS-Office365-Filtering-Correlation-Id: 2098626c-50e5-4db8-da4c-08dae6f9676b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o9+wDVrFnXuGqCcC7IbJF+UJjyAAvwfyOidUdSLNvY8pZzht3E+3R70krve+7kMz4GAhVyJjO+4s1Smv4nMg6Z7VfCz84WjgeCGaSdQdYYTi8wPEnlkvRcax9taUEdCHyhdklLe8+DL5QzCkvqch5k1LYsWls0CbIgUY+JNrJZ/l2qqKGS8VZf1U45tlIHHXW3UO7QxovRGWdUX0AU7bZXkNWecbScRYB0759pD8dDVUcpJ41BoYLrV3hitmq9x6nWMG375pZYqA882/n++hcHwfNv1agzew2rGXxrAZH65kyDrxEqgosUbxabLxVbK+C1dxFqFQGynooE+ulSx1fnk99R5lo97gZ4AlwQHiS0HNeE3KqtS62AlhVBMh5Kd1sbaCJlNqwZVTMVDqlwkp+5mS78fuB4AlkQKqDcLclxJlXEX13220gp1OiG8b7nNegF3TN4NuxJSAnv6mQMTstrazuUaFs6JSyX9ezORuu1qWjQsMywa/KHWG+Xq6hD4tYP84szm8n8E15fFLWQ/HopKV2695UW8Jvpke+wcFGDAMmZVZ/v05fA2Y9WnGIWahuJoeDLPz0j2VGt5+sCjFuuOsghZoRsrb28oQ/IHuKhZKJXJN+IRFgIqINBRTLvj1jizISdng0dH5i83h5CY2wzb08EyZUENVgq8yRup/KbB0Qf2ORVKhtyahNNLTBMXooS/iRhJYOt58hTOi5lU20w== 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)(366004)(136003)(396003)(346002)(39860400002)(376002)(451199015)(478600001)(6486002)(6666004)(2906002)(316002)(52116002)(36756003)(38100700002)(83380400001)(38350700002)(1076003)(2616005)(26005)(9686003)(6506007)(186003)(6512007)(86362001)(5660300002)(30864003)(7416002)(41300700001)(8676002)(4326008)(66476007)(66556008)(8936002)(66946007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cdAdSScq8aoJ3fYiydxO0bTf4SjA60LPF7M4gFeUs+SYToBcQlE9DTR9RTYu1ME51rmg5D/maWakNhBY1tPax6+c9PJiJOr5wYBU5O+6Tt3jGBGG+Wfj/VJ4LwgWsXI3F0SJncvmCWz2wrem5X5U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ZE+i20FiLIUPyOUuo3/1Hfv86YwN3pZbJH86oOZVE95nI3wk/1gSYdO9s4EOqF8cyBp699icVoFr98wk9q5BIlIWV2lk+nOeLZrCLFzfYy+txE51NQaceWO/kv2hDPPiEWQ0Kqsc/WrSCEaLyxrtJvmicBjlgSf/46drZvlilIyeGI7veDkVGfA+zyAIKxwHtrq+NV3vpYqC8FvcOMI8J2Eu6TJuegjXu5AEu7kAjvLokl/osAceD62UglB/OmPk/CAzPc0FmHzW9NJBpwNSZOPL39SUPev8icwyLKYmNsWVcOK4qNa9HJ5jf4k+EtPZgjRlDcPR04y93pDvCS7vad9wp7J7L1 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2098626c-50e5-4db8-da4c-08dae6f9676b X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4010.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2022 04:26:48.6150 (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: BHrqpiAs0uquUXYkWPi8dF+VhfZFqfQT5wOuRQtzvAtQrSmXTwk2diLHYVv1MnwZOSDETbwzSj1yGE+Kh1IiDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7792 Precedence: bulk List-ID: X-Mailing-List: devicetree@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 | 477 ++++++++++++++++++++++++++++++++++++ 4 files changed, 491 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..677f13a040f8 --- /dev/null +++ b/drivers/iio/adc/imx93_adc.c @@ -0,0 +1,477 @@ +// 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_MSR_ADCSTATUS_IDLE 0 +#define IMX93_ADC_MSR_ADCSTATUS_POWER_DOWN 1 +#define IMX93_ADC_MSR_ADCSTATUS_WAIT_STATE 2 +#define IMX93_ADC_MSR_ADCSTATUS_BUSY_IN_CALIBRATION 3 +#define IMX93_ADC_MSR_ADCSTATUS_SAMPLE 4 +#define IMX93_ADC_MSR_ADCSTATUS_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_MSR_ADCSTATUS_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 ret; + + return IIO_VAL_INT; + + 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"; + 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); + + iio_device_unregister(indio_dev); + imx93_adc_power_down(adc); + free_irq(adc->irq, adc); + clk_disable_unprepare(adc->ipg_clk); + regulator_disable(adc->vref); + + pm_runtime_disable(dev); + pm_runtime_put_noidle(dev); + + 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 26 04:27:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bough Chen X-Patchwork-Id: 637468 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 AB165C53210 for ; Mon, 26 Dec 2022 04:27:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229741AbiLZE1I (ORCPT ); Sun, 25 Dec 2022 23:27:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229595AbiLZE0z (ORCPT ); Sun, 25 Dec 2022 23:26:55 -0500 Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2080.outbound.protection.outlook.com [40.107.103.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26564EA1; Sun, 25 Dec 2022 20:26:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nox4/iVKy5AFKQjjnfRcKpjr7M4cVorWuaeKKtUWlSLItxJ56SaOOB3CDY8b5mVE7b9YmxANVnYiY8K3K2AmaJuT4pnWRfE5Kspcb9M01xY7v2RRh7xXu42ToUP/D64w7YqnIuql5Q8JDR0gIsR9kezq65NzaO6dPAb/nJ1QaO+DsmH5Qwge333rxZVi3Mwgvm1H+BTRxMbJqSjPl5ni9yyckVMAFFmwK56g9dy16RqU0riS7anAlKwSZuYQe4zPzV6sVx2lALQq+X4XisKy+HedqlGjwlsTQEA+ggX+tTaDJKFC9SSqITojkHGjBE0ykoBQ3I+htutP1sJBBJy8SA== 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=0Dckup4bNqyej2ibkcfsxjXeol4324ikjI78C+Rf6Q4=; b=ZxxwtRv6fDIz1fd92Okc8RplW2UE8AngYYmNqogkX2YQji6ZIh/ot2kosOIbeEVruKK7W/pR02mhpkCyiYfVHafuCjpGVPi50SsqkbyxcwBvGaDAVmp7VJd4Oquoum34zSZnFwXhw2Y40blBpROLiwtDtKXVU0tEm/ymcHQABpQxY5OE6r6DHXZ7tA5JXWelb9Sb2Duap9goRI7m051NKfizwRSkb1OPV41BKrQ9qwIZm8yUTuHCgsy6hezSZGoK5ogTkzKKhi9igSN/vcdqBBvKVjUkYWACIjOVtrA7VWZqdKYwZSdDQyuRZHYxkUhCBfOcAdBmQHsUfytBuJD79w== 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=0Dckup4bNqyej2ibkcfsxjXeol4324ikjI78C+Rf6Q4=; b=KDfBGHeDfyBWkDFbDV+h4UTcdspLV8H7y5k4xBrxf3FaiXvdOHSTR0wBTNO0u5hZfA3LAUeEi+x5p1dYAAYKW2EoDrH5gHQMLPXQ5b12c6wRNAEqrMwCkXGsFTeVywAZh8fNcU7eziBDRGfiG4/gMTNw1RdNS1xee9lhnwY0faY= 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 PA4PR04MB7792.eurprd04.prod.outlook.com (2603:10a6:102:c0::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.16; Mon, 26 Dec 2022 04:26:53 +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.5944.016; Mon, 26 Dec 2022 04:26:53 +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 Cc: kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, haibo.chen@nxp.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v4 2/3] dt-bindings: iio: adc: Add NXP IMX93 ADC Date: Mon, 26 Dec 2022 12:27:18 +0800 Message-Id: <20221226042719.694659-3-haibo.chen@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221226042719.694659-1-haibo.chen@nxp.com> References: <20221226042719.694659-1-haibo.chen@nxp.com> X-ClientProxiedBy: SI2PR04CA0012.apcprd04.prod.outlook.com (2603:1096:4:197::14) To DB7PR04MB4010.eurprd04.prod.outlook.com (2603:10a6:5:21::30) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4010:EE_|PA4PR04MB7792:EE_ X-MS-Office365-Filtering-Correlation-Id: 80025b16-83bc-495a-4913-08dae6f96a32 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LNjUpzJTLYyL++4phZo7QaWSOhWn24OngEj2pwP1jzayljejJyDez90ZT5WZTGci0rgxp1cuU35R/XmNRR5WzLRGESm5wDTtrun+W+w/4wwXu+EcZslCZsI5aPsCXhAVQItbKWE2lhTW2er7AxZaTYe/u0ZLzi+LFCwHmRI0xcqiUvjwCHbWkSON8h2ewAlsco7VJWEEgr8H4CYvwvjjUFxPCtdneJREREisoPd+7qxMH76csLJp2KTEPYKg/0nFdoDrIe622dO5kG10tkfeJNuMv74mnbxyXyR6PkxIxEpBqHkmWdv100VwG0CKrRgo5jUxKEqOuy0qB1VQiIxIsQqLPx/7MkqZbPs5ynJt/SyveA4Vuh4QXnOo3x4HXegqttovRmBHiEtp/pssYulLslutZ66ouPpf3jult8nlblJKuDCWquQbxqgDIqRraUlu3tw/4X9yUpAeeW03kWsvWnDV1H8+9v4fku5K3ACTHuoRB1C5IUI136KlZ24d6YXqlqAokhtyv1LSA36EFOYgcxDrumz1sFm8LhjM7Zqog5X2CUTBBPedUPI3HKTxI6jJi1wW84ad8G+0yqoFhhyEijJdyE8Qev39fkAjiGDh/IN6bS1k9ZKJdeO7snPVNa6/+wQwTDDCoub+tS6Xv5kYh18ZdSirAljId4TF1VeQrfnNyzkMi4WJFTVKDu/et2CzRG5LIsbUqVA93w+XldPCweqcyKAQaZKofNkKZAPqjik8j1BmjGPJP4mAwLb0kv/GGRNYJAkDFFHg35U4VdBniQ== 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)(366004)(136003)(396003)(346002)(39860400002)(376002)(451199015)(478600001)(6486002)(6666004)(966005)(2906002)(316002)(52116002)(36756003)(38100700002)(83380400001)(38350700002)(1076003)(2616005)(26005)(9686003)(6506007)(186003)(6512007)(86362001)(5660300002)(7416002)(41300700001)(8676002)(4326008)(66476007)(66556008)(8936002)(66946007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CQ+TsRsgINT511nkCCmPQ5pW6tZc/bxax/VefgQxMBRmukoCUdoqkWz/nau2yoTarCev+lJBm6CWMBe0g214/aNnG/yjG1HN+CwFBrJdfIUNm7d17DDh0Pf8dBGlyscJ7fgQpDqeRTyGqssbkp09cI7PHKVg0OSsVysBkttyfrUB69VOPjGZo4rM2sOCN9M56KF1TmJeXni3EerkGglByKqU+ufnO9e1VwpBQ7Lw3aUY9migDbFlBrdqmKqvfX1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ejo/mFaDFzPSF+s5yhP5aHp0Sody6n5dwwPtUs6f94UEM2VMRIV+/naeQuZN4mMDubOSeQn/MHhnn7ujQfkj5wWdovo1NGq92seyosOzcYLeOn3nJhpHPcOEFHkBNGvS4r+mKvZiwBJI0nR27eBBJAUX+kd7ns1Pv6ZstjO5KQV57x/0czq/maznFIk04d40Lgheqj7DxqudlLsudFXLFQKDxMwKjmcOWmPEBuRM6FA+bl8Fu9ijs4/ekmBknW X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 80025b16-83bc-495a-4913-08dae6f96a32 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4010.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2022 04:26:53.0209 (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: rPkS6+y7a/YgkTRAn8W37vwFOHoZ6rpeaJpy6wmP0UxVVOe8U7A2uHO3ZYA4RAAtqXmovSRVhi33f645ET2mbg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7792 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Haibo Chen The IMX93 SoC has a new ADC IP, so add binding documentation for NXP IMX93 ADC. Reviewed-by: Rob Herring Signed-off-by: Haibo Chen --- .../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 26 04:27:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bough Chen X-Patchwork-Id: 637467 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 5EF29C4708E for ; Mon, 26 Dec 2022 04:27:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229595AbiLZE1I (ORCPT ); Sun, 25 Dec 2022 23:27:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231560AbiLZE1F (ORCPT ); Sun, 25 Dec 2022 23:27:05 -0500 Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2079.outbound.protection.outlook.com [40.107.103.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BA84F26; Sun, 25 Dec 2022 20:27:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jekBTXU7Pcve44wTxc29PVrMTTcW25rdmBKd16QgZce5jc3/bHkPe72dEt/urkdGMGlR38Mzb7YNtqQ8cxy7d91djRQtfJoubRlXc6r4xNxGEPhvaC+hOsfIzaLCZ09YqyFAV8HZKi5zCosDK8x8visCTOIZVNDCE8xRbHhQvrBE6S1e3FT/kpGs5okuitiyklK7fgiwRwld9zrk6HsJ2EAzd9lyFLMei/MHSK8mQlSJEBWdI0SmdvHQSFo/L8LDSvANiPBpA/F13uHiYQ6iwLqwci8ZWIvFvIFhdcXay0ghSlrkR19mOtfvYrgC/S1ODNnp6U9CoKU8Oob1WEmW3g== 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=bHI01kFAW6pygQce9+iBurupRc4Wo9HWoCJacgawRVg71lkRr8WmdR6wL8IpEEw699F8cg3Q9KGLMHN+0bj8CuV00Y3ocJm41CYFdqdOYn2arJaFvM83fLNPvAgh9BQ1QsQoZ3e00ffFSwHFa4DlFIPI9hnrIDJBcvk/HmWn+rfkIaV/I9rA0ZeTndXvBOmuytBmLm96KaB0/yaa1rAK/5AVv8uODCIJ9uWu5NWTZ8FNcCX32ud0+kD6JgMR8sCViLXTeyQjy542M1o4v94rfY4nocCiyFHtZgaKl6Ko7x2rMs9Eo6hsLicCIUJoFtE0tKdDnDvEo27EzOsExsj6cg== 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=UAE3MK8M6rDl+lW8ocXdXfW8WhrXWg0AEUo//JkqhoTCDgUSnRZIZN79WW9LwisLOORw4jfXlwJmbJjt6sZqSrozNWk7lCPeMTpsGSvT3x7Cd50XaNJhnm9M6hdCm18tPjOVqAXhHWTybwpSnwbqnGVWmqMOwbH77mR0SPsJhN0= 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 PA4PR04MB7792.eurprd04.prod.outlook.com (2603:10a6:102:c0::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.16; Mon, 26 Dec 2022 04:26:57 +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.5944.016; Mon, 26 Dec 2022 04:26:57 +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 Cc: kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, haibo.chen@nxp.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v4 3/3] arm64: dts: imx93: add ADC support Date: Mon, 26 Dec 2022 12:27:19 +0800 Message-Id: <20221226042719.694659-4-haibo.chen@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221226042719.694659-1-haibo.chen@nxp.com> References: <20221226042719.694659-1-haibo.chen@nxp.com> X-ClientProxiedBy: SI2PR04CA0012.apcprd04.prod.outlook.com (2603:1096:4:197::14) To DB7PR04MB4010.eurprd04.prod.outlook.com (2603:10a6:5:21::30) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4010:EE_|PA4PR04MB7792:EE_ X-MS-Office365-Filtering-Correlation-Id: afa1864a-7624-44f7-30aa-08dae6f96cd0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XYQovKxL/nxJhpaUsQLAhSCgmJwqBAWYubktBe4ko4kEYCoh5yff6h5OikYd6AKTVvnfaIN7PkBmq4nN6EqYgReMOV6xLdOUCb2krduMlTzWA1oP4IE8jijpWZP7tMj74DilzlNp7oOMuKjQnf8PWRjldT7FqGToqNQTKgu/ovbkQhWhMpEnBXqcmt7obDvocEAY5VVkMxyC3P+FJCSapcH+d+byhir/30184zNhkx6eqOO2w/wUVluvpz35hVJLFOPpY3riwB/4SsPgnMjzgmPmzqj2s6c4ZI/hPm+44Puuk0B/S2R9FYXG1yt+WlFGsrhp5irPr3gMQSsP7WhZLKrVgSKBcGuQzUekZ1RLzSIASc17XBXg6RO8FFjwXKHhXiC6M/Vm2cQ6F1q3ipD+dG3jCVjyCaWfxQ0tngYnpKioeGeYOttyVhoH/K3UQ2bFkyIzXEfor0baeM8xZ37rXGUyZc8Eg6Y2yV6BH70y+U769yTUtlh8pylaLzovXaWOwERk0Xfbf1IlR4p84RuQQFiWjQ8qfk5F6muoXVR9U+3Y5bWGtoOpxTs2DVtxCoHvrO6Ssrjhjejd9ZZIXd9pwsoktA4U9LJ3PVoekm3KaOmkUxWPFUZ8+IwPgm/w1slu3dGwMGnC97PxDK3t37iu+89M+UgngbJsepLX01+KwMNpntMZGBUT8QjD08bIfpo0gQBRvI0daJYV8ALJCZBVdA== 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)(366004)(136003)(396003)(346002)(39860400002)(376002)(451199015)(478600001)(6486002)(6666004)(2906002)(316002)(52116002)(36756003)(38100700002)(83380400001)(38350700002)(1076003)(2616005)(26005)(9686003)(6506007)(186003)(6512007)(86362001)(5660300002)(7416002)(41300700001)(8676002)(4326008)(66476007)(66556008)(8936002)(66946007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LoUDTGdMe62iviqK/LxnQ44k8WDA+Z4Gm6LaAQSOqDUifV9sM6EYmLKZ3+31v2SRkM86eO0odzJsPWyQ0Rh32BFb87vykqjp4QsKryOw8BhGQeVu2UBESUOqIjGh/wfrKD3AgSauTLlI7csEK2WJICDQJEtp41gGXhd2x9O+cTWXNxxOCjHbhbEjoGcmeqTWj61BvOSBkjJMYHXVNs5z+nTRqDOHPvV3FskNaJ4Qdz33FYkunKg9OoLpGHRyDPCW5fi5wF6X+tXpmt4O6FLvShZiPSJ/z+WLMqy0MuYyVqBkPCggAxZJWo75otI/2Txk6DTHet3OWJ1aCjCGZMLSZ0S5lcmfe2YbzVwfrUp2LVHvnh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8H50qkcuuuvGda206Na3pOv7iLt42/aK0jQPlokbPh7PMA2A1KtD2YxsKQ3BcfatYzR6sYm0lb72tmf7rbmX9iTi9aqpgIJVyMc1Tit7S6wGOobHfRNFKSOsnFtu6oY83iFkgUdcCDJJcyaV+wRLFf+lrvPj2 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: afa1864a-7624-44f7-30aa-08dae6f96cd0 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4010.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2022 04:26:57.5674 (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: XtQgfXczLpi58ZVLHbTNKryECwY8U8Hso4GrRXoB0maIvcAK+8mPUbpuQ3LeEXh9H6EGCmo9CQ3EolQQ/TZi/g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7792 Precedence: bulk List-ID: X-Mailing-List: devicetree@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 {