From patchwork Tue Jan 3 11:43:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bough Chen X-Patchwork-Id: 13087405 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 67434C54EBD for ; Tue, 3 Jan 2023 11:44:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237460AbjACLoH (ORCPT ); Tue, 3 Jan 2023 06:44:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237359AbjACLna (ORCPT ); Tue, 3 Jan 2023 06:43:30 -0500 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2085.outbound.protection.outlook.com [40.107.14.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E20D42A5; Tue, 3 Jan 2023 03:43:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JaZEfq4zTKfsVt6co+NpMj5OHPcTGeL4pi30tsToMTTXj3AHSsbRa4MqUg9lLsmnSMvYAq9I+OZNbBZv+l9sW6H6dpYGH7uNdPE+pZ/g8u1M7k6Biard4NOJMdAzfVojtpjILTrYTSl2OmFX2vRDYLB51ZaY+NewgSUdtUySuHKDDNeIszEB2wsMAK0cbTjgkHeQIrUd0QSJWrGhdYLgG0R4/5kVuNMdBaePe9hyAIhZYabyUUePeRhVnOaoNt39sDPm4gDKD/wfBlEIWgnTYH2hEJ4RwULWcqHLvH5a8MWeXRMwoiGf0bMjPpvkyxPRSFnTlQ7F81aOzNtMw7m5jg== 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=op8zeHcBdxDraHZvpXmZDA1F79/E6YPSzeLYvYFVLes=; b=i5t03SrrUo/gz/hRiC17Y5zj8rlDbykZxGCCduQK4a8KT+W9bn7x6emQF3/vJXw9H4Qn0dURX9YqTak9QyKEt3/q4XqpoZfsesqB7eaW+B96CjhJ9/DV24UeV2tFwvtkox8LhTG0Ng3B2SZBJAhsJ4uDRCWZ9eJ+OcwDJma/qVS8b+zBxpYOoRzAoqMURwf8FA9Fv5BDfGEf47oWU49Ugh3ctwMju8eIPgO8hoOCZDJ3sqTEWYDKIkGxYPWak0ToHKXZZpo7W4yVmUDym4b88wommtIJgBUYcCPZ5+vLfLYBbLMgTinuhpjfw6ztSreYuRs8tKxBOTzC84NmE4Nq9A== 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=op8zeHcBdxDraHZvpXmZDA1F79/E6YPSzeLYvYFVLes=; b=p0ThTZieVEKeTzl4Dbpsod6algUIYjXlh+r6duyUos1zRlRFNky087qzRQDWmzz2Gg08R3mWUWr4Wk/lfYiOgRcqHStd+aQUSRFH80e+RkV+6brl4uxIXtSq5xeUrIVIaNBdwWF+QqOgvcPK2ykm2L6sGM9nccIjHkjKjcT6bUc= 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 AM7PR04MB7013.eurprd04.prod.outlook.com (2603:10a6:20b:116::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.19; Tue, 3 Jan 2023 11:43:20 +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.019; Tue, 3 Jan 2023 11:43:20 +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 v5 1/3] iio: adc: add imx93 adc support Date: Tue, 3 Jan 2023 19:43:56 +0800 Message-Id: <20230103114359.2663262-2-haibo.chen@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230103114359.2663262-1-haibo.chen@nxp.com> References: <20230103114359.2663262-1-haibo.chen@nxp.com> X-ClientProxiedBy: SG2PR06CA0240.apcprd06.prod.outlook.com (2603:1096:4:ac::24) To DB7PR04MB4010.eurprd04.prod.outlook.com (2603:10a6:5:21::30) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4010:EE_|AM7PR04MB7013:EE_ X-MS-Office365-Filtering-Correlation-Id: f5325ab3-759d-45e6-ba41-08daed7fb612 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iswMUIS+XWC2qpHB5apu+g3sYnuBCGli8xadfNizQHnVHVqpgfwKTBgZ9fD/wQJ0yxI3n5LzCi88S9CKVNRR3R29V5lyk7RfjkN8Rxy6mri69CVe+2nduP1QnQUAH6v7jyBuMtIxD8GpfePDa9AoQt88gk2Mq7T9BbnU+PRISnHQbpes7ENAkigSZtQFeJag0CU2MsRGjjEyKdf5l+FCGMAclzSVDfOMhsgBe5opBVi2zrp7fZi3vUyxyAHArR21Uvyl2x7CqkRVRoWQ30gdB2vZLeVkeI5MwgS1zy0+IsntsqxF/1/PkvcD/r9O8z+Q4rVqocEOzV26ZHoobmKKdz0KCkmZo1k8qlWe8TtBtkixTGYWBeWBzOHt9UCC571M2ZNT7vloupt/viDJ2rT8suSjr75EpNWfymSSIVxQxwg+BsHA+K2FSOHb8gn3rxJPYxPM38LracnkfeymdE4oFVr3awXfMEqlYaAEXMSIciTS6QSwwdEAJYIXyq9KZarxyGonxcSqEYL7tWWnykkTXCKpKNfZw3JXZNaXdAU2h7tCThkHsp5PrB+jmPHsLafRhwULlZ4hQfQvexZV/VDIK2k+GIoDdpMwcsKNaBLpRPeHtzYfNojnf7kr2TWF5/t02GcaIXKY4KKeAEzpsfffpnqPslgRHV7aAXwPju35bfYMbe917fjMYrn+CmNvjjBpY/FnGZxsCrP33Gyr6D/T142xyRnfynFKqUMqoBXrwPk= 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)(39860400002)(376002)(396003)(136003)(346002)(451199015)(6512007)(9686003)(26005)(52116002)(6666004)(186003)(2906002)(6506007)(478600001)(6486002)(66556008)(66946007)(1076003)(66476007)(2616005)(4326008)(8676002)(41300700001)(316002)(83380400001)(5660300002)(7416002)(30864003)(36756003)(38350700002)(38100700002)(8936002)(86362001)(22166006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DoD5ZxKjQeEepRRZ2kG3v0895Op+uaHt+IbqG8281GUlnh0RbngtAdM0FsF2/huTS1I8KhmQr+xVFnI041NuoIZtNVjUQw3Yfpw1ioKAOeK2IdKkdNF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VdzyMI/2whEftCPGDi2H3iKfVS3s7365qmBR8O7GA+BNNKZyFxKcIgW9NWOlEHDAzeebwrCaiPF1KYnqQx4UIIB5AR8QcXraX5SXQWkhqEIz9UdUVikULanQ6g8U9KjIy4Xd+NrlOzQIx2KpVYwT7bp4Pt37QhyvjNxZosZDL5oKjw/AGIKmTB/oVXDnBPzaW4Jd+aZjzz9wgDJKp8Y7xHXIPvnJdcIvwCpS4ppVYSphd4qz8aI1aQ5VjVODsmLvoSTDEzPNSUvuOZLnHrdmsuBclFBrdg3T8VPhOv11LiwdZ3/uTdO3w4Zkh4XBGOzSfp4hfXqOsrl2dEXQRjXj0yc4svc4Gu8JcTHraXenjCUiSA0+UpHOi/Xov39Bjh45sag/J8TXbhURsNfGwKc9I7T X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f5325ab3-759d-45e6-ba41-08daed7fb612 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4010.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2023 11:43:20.0156 (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: MOo7rq6OuBYWUxzibDP+NHp8KRr22RFSWMVdXzXBAVp+Ci8weErPOF2rT82IQJPbbpmipj2FSD+IKCY+OdTIOw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB7013 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 | 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..0c98de438919 --- /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) + return dev_err_probe(dev, -ENOMEM, + "Failed allocating iio device\n"); + + 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 dev_err_probe(dev, PTR_ERR(adc->regs), + "Failed geting ioremap resource\n"); + + /* 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) + return dev_err_probe(dev, ret, + "Failed to enable reference voltage.\n"); + + 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_probe(dev, ret, + "Failed to enable ipg 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_probe(dev, ret, + "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_probe(dev, ret, + "Failed to register this iio 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: + imx93_adc_power_down(adc); + 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; + + pm_runtime_disable(dev); + pm_runtime_dont_use_autosuspend(dev); + pm_runtime_put_noidle(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); + + 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 Tue Jan 3 11:43:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bough Chen X-Patchwork-Id: 13087407 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 8CDE8C54EF0 for ; Tue, 3 Jan 2023 11:44:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237476AbjACLoL (ORCPT ); Tue, 3 Jan 2023 06:44:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237065AbjACLna (ORCPT ); Tue, 3 Jan 2023 06:43:30 -0500 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2087.outbound.protection.outlook.com [40.107.14.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4215AE6F; Tue, 3 Jan 2023 03:43:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KiKVKm24eoGIah/bkC5hmbScB6VY4RS6YjLIPeXSyr4G2IaHkxyrkSUHCGeA0eoFnxAZFm1uuxvebAGuqDERUQ6/Jm4lCqUqXeNXKFMO+tSbppqEwulHPhhB71aGCKLuwolMkG3uG+mdffIjkCzvybXRiZ1cnAWYYezYZaG7op0079WPuQLZ+JC2JhXGuMQddGCOnOk8OqYA1ptY4gbmHzTlOUY9L93PYm0JuvcVCn8l9cdku2rh0zuWsd8PpHSKSUPqxIrtiGEM1mmWM6NcQyKs+MunbIcZR5YV+LcLM5oEMZLNfBnoMmxNDK0TrE/0KG8ZHaprQ6c9LfXFvCtz6A== 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=gaZFNFMf8nz1Iyr7I4KWph70WUlqFkrhEjnn2dlLNw28rm/CA0umVopQ6ENgOzU4BxmEtVI9ueE2LIK8rb96OK22EhzkRrB/2FlMg3mNBZjnNAk451WhGrCtEMnet1D6h/tdkcOMuAp1eHUS2c3J+4QuxlDBTMLKy9lKZyuaN562aNoN7z8ZlHycQIQAtTXjKKpsxrtr6snBupycjTbPiRizPWFUOeNLXgshCA5TpiKLiBdJ8eQJX/kZnikU8z89HbwffyItw0ackxcycEk44/mWglEiSWQTENHzJviuWqoba8leV+GtnDkJsw93IOctkiKrzfzfMQnJa07vmJAPow== 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=WSrl3PEG8Qkyqd22YJ1UqJl4ZJcVLPzXGgVqJBKw86WHWjQb7LYI2vuWXibANVWfW3AsS7tSCd1l7zlsky8IRQgu3qKbnBasV9uNjhMZEt1lSrl4ZxeenL2r1CEi4o+hnSf1t58GPYGpvL0ZxygFPj9s+LDkLogVeqizWfyvsVw= 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 AM7PR04MB7013.eurprd04.prod.outlook.com (2603:10a6:20b:116::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.19; Tue, 3 Jan 2023 11:43:23 +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.019; Tue, 3 Jan 2023 11:43:23 +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 v5 2/3] dt-bindings: iio: adc: Add NXP IMX93 ADC Date: Tue, 3 Jan 2023 19:43:57 +0800 Message-Id: <20230103114359.2663262-3-haibo.chen@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230103114359.2663262-1-haibo.chen@nxp.com> References: <20230103114359.2663262-1-haibo.chen@nxp.com> X-ClientProxiedBy: SG2PR06CA0240.apcprd06.prod.outlook.com (2603:1096:4:ac::24) To DB7PR04MB4010.eurprd04.prod.outlook.com (2603:10a6:5:21::30) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4010:EE_|AM7PR04MB7013:EE_ X-MS-Office365-Filtering-Correlation-Id: c56c9113-62a2-4da7-9342-08daed7fb85f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vDs1BwCK8XyUhN2vxk4GbUPo3IlsOlhvbI9E9X/eChSRLgVS4EEqL46Vi1fPa7NGXFhddy5EfdeqaXsNdiV9oG/Mgmte1DEU1ndwkmbGNEdXz0FYkU7q/4hZBm5Z/50jwiXA9bUcYcE0AvGT8WRau38UWv1ffOauPocQz+voLOUP9/sQKPDooJFXjU2cqgU0sNZFr+yl4yj0KPGih3XG11etbIhtw2ZJ/o8UzgYXje7aeq5eY3qpfL2VmyP4M7raLpK4vywLPxx4Hlv+kS7gjFzHNihci/CfErkT5WrKqd6hljxbLOyl5VekCmjTOs0tM/ZbdUWyHmX6NmWGF1o0oMo2LUI7whOBqTY/+m0gDYQqJKllQMlKlsm9SuJiOogeinPnbglSVyQ1FNow4+qD9t3yzcVGYU5ob8pBw0NEWTkp5bbLpANrKR16VcHy1+PNbU6006oskOOvAub/kDd6ViE5Ohko+Ugy9L+svfW8NyzdzZ5Kpq6YEccEXMPLwNtY4dOujZYn9AjBvFP7W/jK6JIQOdbGlosgsZ6uncBe2nsDB71ihxnvijdaICClhnQoW8ntpzVM/nElRmNl4irhq4ctGk3lfD6kotW9oWAKo2EWFV6t31XH5mMvH/Cd8Z5cEMFvtjTx0rK/iT6+DCIts5N/gRjlZYxUNxr5yPlwIPMeAGOc1cDcyZ1rjMVmkroPvOELvTcchPmtZQiNq15sSluCMDWZUAjOOOKLfz4/GRFOyVQQdjTrStNsC2EgtNblSX3/MTFS91nBGAyvW/aekOWKztyviXaNLMUrFPNR4Jo= 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)(39860400002)(376002)(396003)(136003)(346002)(451199015)(6512007)(9686003)(26005)(52116002)(6666004)(186003)(2906002)(6506007)(478600001)(6486002)(966005)(66556008)(66946007)(1076003)(66476007)(2616005)(4326008)(8676002)(41300700001)(316002)(83380400001)(5660300002)(7416002)(36756003)(38350700002)(38100700002)(8936002)(86362001)(22166006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EunOb6UxkoBe4qWFbz1xinoGe4ViKnqzDVvz+Fdz4uN8YR7EuNT0jO3TJp1cUVOxtguMSl4PsxQIbE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clc+vzB/O/fDlNyEfDBNuK1JF+f8LtXhT043B/VhQZsd0vt+x5cq5oBgRenzjapqsJLQPJ/Y4FUCRywqUDjaVeLfPPgBGJlmVgsHXZUo+e0Nvmn9OzI5rRvn/ZZ29412r8dZLJO1p5xqLBqMZouRVzdG1AthUjau9hKnVXtxLd+UXzWgos6rfSgbm8oyz+dfWXRuCPWypInzIf9L9YlgRwePx5HR8rNm6YXnf5Br6WEUqkEpz93yzcSwYflaFNIpcu8b00KMUC/ymFAhZ6+TmwCKZPH9T1Cf6nA6VOEg49JV6cOJG4eJKq5zdPDMGNemYrtCdLFWiZQ5M4OCzmSJxqq7ZjTu7R7pSf7Qx3wUTvSY6gByGfJroVydzLKs1SoDCvOLBrHSxqTC0AZNmPecZvhQi9dsdxq2GujDF5WmNY X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c56c9113-62a2-4da7-9342-08daed7fb85f X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4010.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2023 11:43:23.8747 (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: hKzGOpZJ2nQTIrok9rhLU3pGPZS3iNDIWeS97j1ThR4vLVJ648QnSNJ/B6V0iWBnGol8CntX0O4TdQpe9UO4Xw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB7013 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. 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 Tue Jan 3 11:43:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bough Chen X-Patchwork-Id: 13087406 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 B342CC54EBE for ; Tue, 3 Jan 2023 11:44:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237479AbjACLoM (ORCPT ); Tue, 3 Jan 2023 06:44:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237175AbjACLnb (ORCPT ); Tue, 3 Jan 2023 06:43:31 -0500 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2087.outbound.protection.outlook.com [40.107.14.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3D4A6153; Tue, 3 Jan 2023 03:43:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JZaz5hqZRSE2/Gxy7HsRyQnozoLJgH+PLO/Piks3aFAjEmo8Mr90egWna5tCsJX4/4H74DmQD9Sud5qaH+WQkAKiJnei5H6PwpRUJUndpIl3bs1XaWPj2cDYN2QPgqov2NeuxdLSpoOeeRmjPxQXVxc36/+whXLwAQDqyHAgLCmITP3zXAL+RZGqEFEsy//8eT5sbz+tVe3L+SklJhkeHii1MKOrRWnhdcNjZrqO6BemG6GB1xoc7AY18CnySnibu7LoMj6SXfuNCXYIb0r8KGXIDP3D1kKpmG0i4YCDVO1XgR55KA/XJtQPq9RYIuB7bJnB7Tm0I3nQPHC6fhn+MA== 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=oU3bSkV5rRfye7YQq4ngtiC2WXbegLKEnoV51gsmGuzgt0ERpGiL0rwcynEq+RdghAW2A9IQHheZbAsO0Ht17WxHlly3h2M+PIMFJswbIQEKReSZhT/jKvhy8dh0DAx3aIPryhcOeopXoyTDcCFdzG7m8PhC/JjSdn3BvD2srfkolaErhe0tbaTrpn15kHVUaGn72nLONnPZwb35JMJtUB7HtzqHrjssOQzbCOD0xlmOyswdiVcr5/UzebP2Qggzxj5U07Je7+EmRVL+f935XDx94vMbOd0e+x2xTj/T3uVmh64ZVfEViA0NWT4qdah1/PFZ+0J6Wp4MW7YJ/yjthQ== 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=L9xrSqqYOS0We0ptUJ1MhGgkQ/rtm+Lv/GQnwzCqLlvGwKx9QI9FJS9dY20QNLDn3a9v1hr1ZM4/l1m/4K08GK5cPcn68yjvypIouvDy1gZEF3vaBKLoaNFK1YiMH9leaQ7uBwKEfxjc7wxMoXMO0I2IeMjP5TZNOOmPcvoIAyc= 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 AM7PR04MB7013.eurprd04.prod.outlook.com (2603:10a6:20b:116::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.19; Tue, 3 Jan 2023 11:43:27 +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.019; Tue, 3 Jan 2023 11:43:27 +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 v5 3/3] arm64: dts: imx93: add ADC support Date: Tue, 3 Jan 2023 19:43:58 +0800 Message-Id: <20230103114359.2663262-4-haibo.chen@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230103114359.2663262-1-haibo.chen@nxp.com> References: <20230103114359.2663262-1-haibo.chen@nxp.com> X-ClientProxiedBy: SG2PR06CA0240.apcprd06.prod.outlook.com (2603:1096:4:ac::24) To DB7PR04MB4010.eurprd04.prod.outlook.com (2603:10a6:5:21::30) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4010:EE_|AM7PR04MB7013:EE_ X-MS-Office365-Filtering-Correlation-Id: b61b0753-4720-41c4-a7a9-08daed7fbaa7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6Qo9qwlYEzvnGzU5dQwCHSRxzJXT2zwONLYmGz+DCH+cjDHVLEPkkvgeniYYDjjYxLmI21nZwSOKr6s35ExRksrbSUdNFXvzBWt0Rb8XFc7c8CrI9YriwRxF9W3S2bdjIRX27lEDyqF79TTvlHW1OLlYELB1sx7nMyl/Gz2gMJT2Khg5DRd2X06GHWa4EBOwj3eQdo+WB3Yum+7H/5awQET8Opzu+Uj4C7A/4gAZfrDCgqi6xl6s3tDUGQ8druA0DujtGJ58UHgpQ5XuYDPYCKnITpMam19WWPfJRaVXbCTxf/34QQ+fUk+UGBeroCQTu33xUxK+F1UOGyznLqjXvlbySHrCeOmNXt3IoEcniVj0MQg/JSc0MyT0y6fhIUr4VX4KYmNeeBcLnSIqXYfso9S8kx/UH+icwVdRXsY3WdGZvvOk+7gPHIn5pqUUQcFMUA0OSS5CqfbLas+cKrjgEGHArTmPUkyh6ECHvqr/Eze2va32mPqRNYXo77YKTxI6WY5czK8IFrGSSjKcDtDU2GCMGQPPqMt5Si2zqktoS2BdvZoGnWBvF37mVF4faAxw4dGwfPZW2ThS+kMEpvPEPPLXJ4rLF2EyaK6L9HTsx3njy4PirSdPhTHw+ruxpdWn6nquzXARY2sZp9BUNU4+t9+xH7LSPFMk0WZ/8P4s3/N319AQGAjWg/uI9EEusOTh6af6JjsRo5fGjMvEDbqIEDHVeXV57rMwgAmPlBE/s+w= 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)(39860400002)(376002)(396003)(136003)(346002)(451199015)(6512007)(9686003)(26005)(52116002)(6666004)(186003)(2906002)(6506007)(478600001)(6486002)(66556008)(66946007)(1076003)(66476007)(2616005)(4326008)(8676002)(41300700001)(316002)(83380400001)(5660300002)(7416002)(36756003)(38350700002)(38100700002)(8936002)(86362001)(22166006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cfEBRtZiCJrSAp+TVtv0FJVq5VJefxKCwA+6k+inZoU8gEjR8aoKE4HbSzpFADhDMVi0cdk/gyZ5aDm14Dz5Na5sn9r0coRrYGUYPUuV3ieP1TWgyfRYBxdghY4W0xcLrpH9LW1XkBc6Yxok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cdXxBx0pQCC+ECqREyUoLz3jX89Ob26r2GJsGQdhifAm9hdWchRYzuZvtCvvEVf/iEK2UM/bkeZQp61nGzGx4a1d5tNayMpL1ztAv5iYPT9bid9rT6OVSP6X243XZ9ngqqKDILl3OJevphh+8uoXo/vNqxLCmaSbQXDnRXnkDoB5+ayYv7Mh9O19uJgKqRCPKkT48il4XJDTonBNIxenkfbzxY/7Dg/QYJP9wK5fkpJi/R+C/oq34vz687F+qxr35E8n9UybFm3H5MASwHyRdL7jpsfCh+d/a3hPWQTzM/YpT3sS9AgGNJbqmVuUPc5zoOuIsiV8/6cO4sR9Mj4Y0ic7YOEXl8yK4IAt6byN6imRFKomJgJozQJ0MFIqs5uByZL57WO X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b61b0753-4720-41c4-a7a9-08daed7fbaa7 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4010.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2023 11:43:27.6869 (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: dfG4HxnYK13I7icO0u3ERW9Tv0RKHVl5fmlr4vw7ksU1h75xwiw4oXy60Xih8Rxyx4y91EGpGQRn8rxTi8kcaw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB7013 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 {