From patchwork Sat Jun 10 20:19:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maksim Kiselev X-Patchwork-Id: 13275064 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B96A7C7EE2E for ; Sat, 10 Jun 2023 20:20:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gzfywUPNs01gBbzCVD/cWDl0YcrUMWUN+BHayBqcW48=; b=KKdRjr3t2ERDYf dN+L7RnRW9dtnhLbUAfgEiYS/Qb/Vgc69r82v7MTDDjw3EkcoS43Qy2WmGcHN8kzK5198cxOOMdGr oA+YAqVwuuR6gCDdes84OQmOfGmeAOYYblJYW/sH+7qxxwPIytbtYR/fCS4KA54zVgiG9SfIMAjP8 SLM4fW4/6YHw3tvYp/V+VcFZivP3Bm0X3MlvM2JlO7WRe/TPtmPQ6CaOnVh5pSp/jtX+DFI4Hn3cm TKZdQhGsoPn47UVQKCQEngQdpvcXBaXVqQJw69vj8oAminthAz7/v05PhBv6A8eXAAmAzx5B/eWaK w/mb/2ZCdUjonzHnFQhg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q854u-00Gz6T-2Z; Sat, 10 Jun 2023 20:20:52 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q854r-00Gz5G-05; Sat, 10 Jun 2023 20:20:51 +0000 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-30af0aa4812so1887935f8f.1; Sat, 10 Jun 2023 13:20:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686428444; x=1689020444; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6BjEpm9NwhVHBIExE7pS4ZYKc4O01AwTvFArc3SxE2w=; b=EUfzr2erPtiFG3z6wfkW65/IV2F993LOMXjszsJnMeFKsjXbQC7k/LxM/fSGU3Be+9 iv0qwlQn4Y2janaVzJc9ZLcIdtgpT5zRaxYjvGF0QP2qGPcvxAJY+5PWzoPyUEOlfUyX 7K1anUnmxIj7fPptvs9eCtoMqnGj08aSKsSvX8dtxlHYIPidgXpycQOjeHSNfz/OWHP2 cvqpliO8zCFOC7vObg/OIWWS3l1X4tj6QmtZHSxJ2HgJ3ormLlhR0hfn1qyPVybZIHS+ P69hsXE5VpXKgkVLFsuGfLf1wZsRIsfdFVXabdwf5i/XyLMKgeBPiCk58N5DKJeltSu3 Uq3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686428444; x=1689020444; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6BjEpm9NwhVHBIExE7pS4ZYKc4O01AwTvFArc3SxE2w=; b=ZwulDRfADnzCtHCPXeUkREroLUtJDbwhLz6MIO/B0PtHQs4tcCMGFFyA8vqA00wrGM MU2nqCVbaOxCH++zbBLQ+yCTKfZl9w5iRuUZD1//9Y+6rHHW5JLgBRX+XpKZM5ZFcqEE +Dc23inrdXQjyc/30DReXcuPpdr8uJmz2dZd/MUbpmQ0R2j1QEgWnGGasf6wyP5nVbFy XVQrqRLrzKABHhfARVN48Uu6FFEQlfZt6F58Pihh4emkUmCNzhMGbz84Ou7cRkXEIEOe HbwjMHjbR4gfAs2UHeA96dQfzmh7SzhHqhCU5nCPXURodDk+VIgnQLsfvaOHmy9aJjc5 DC5Q== X-Gm-Message-State: AC+VfDwXJyk+CnOo/Pyvdy+MupTEBmeLhbx8b1Ws4VdMkJpsWoE4USQm KUK5qggad4FK1s9pQOVpSU8= X-Google-Smtp-Source: ACHHUZ7Y3ndeJJGheB57rIUQ26/K6AUrREjC4e9ro9J0WIBmzxjFbv5qukIM/SCTKMcF6mIm1a/eGA== X-Received: by 2002:adf:ebd0:0:b0:309:3c0c:b2c1 with SMTP id v16-20020adfebd0000000b003093c0cb2c1mr1112255wrn.23.1686428443599; Sat, 10 Jun 2023 13:20:43 -0700 (PDT) Received: from user-PC.. ([92.51.95.194]) by smtp.gmail.com with ESMTPSA id m11-20020a5d6a0b000000b0030b5d203e7esm7878116wru.97.2023.06.10.13.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jun 2023 13:20:43 -0700 (PDT) From: Maksim Kiselev To: linux-iio@vger.kernel.org Cc: Maxim Kiselev , Andy Shevchenko , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Paul Walmsley , Palmer Dabbelt , Albert Ou , Philipp Zabel , Cristian Ciocaltea , Greg Kroah-Hartman , Andy Shevchenko , Cosmin Tanislav , William Breathitt Gray , Ulf Hansson , Haibo Chen , Marcus Folkesson , ChiYuan Huang , Ramona Bolboaca , Ibrahim Tilki , ChiaEn Wu , Arnd Bergmann , AngeloGioacchino Del Regno , Caleb Connolly , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v5 1/3] iio: adc: Add Allwinner D1/T113s/R329/T507 SoCs GPADC Date: Sat, 10 Jun 2023 23:19:48 +0300 Message-Id: <20230610202005.1118049-2-bigunclemax@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230610202005.1118049-1-bigunclemax@gmail.com> References: <20230610202005.1118049-1-bigunclemax@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230610_132049_070301_1F888E59 X-CRM114-Status: GOOD ( 31.65 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Maxim Kiselev The General Purpose ADC (GPADC) can convert the external signal into a certain proportion of digital value, to realize the measurement of analog signal, which can be applied to power detection and key detection. Theoretically, this ADC can support up to 16 channels. All SoCs below contain this GPADC IP. The only difference between them is the number of available channels: T113 - 1 channel D1 - 2 channels R329 - 4 channels T507 - 4 channels Signed-off-by: Maxim Kiselev Reviewed-by: Andy Shevchenko --- drivers/iio/adc/Kconfig | 10 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/sun20i-gpadc-iio.c | 281 +++++++++++++++++++++++++++++ 3 files changed, 292 insertions(+) create mode 100644 drivers/iio/adc/sun20i-gpadc-iio.c diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index eb2b09ef5d5b..deff7ae704ce 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -1123,6 +1123,16 @@ config SUN4I_GPADC To compile this driver as a module, choose M here: the module will be called sun4i-gpadc-iio. +config SUN20I_GPADC + tristate "Support for the Allwinner SoCs GPADC" + depends on ARCH_SUNXI || COMPILE_TEST + help + Say yes here to build support for Allwinner (D1, T113, T507 and R329) + SoCs GPADC. This ADC provides up to 16 channels. + + To compile this driver as a module, choose M here: the module will be + called sun20i-gpadc-iio. + config TI_ADC081C tristate "Texas Instruments ADC081C/ADC101C/ADC121C family" depends on I2C diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index e07e4a3e6237..fc4ef71d5f8f 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -95,6 +95,7 @@ obj-$(CONFIG_RZG2L_ADC) += rzg2l_adc.o obj-$(CONFIG_SC27XX_ADC) += sc27xx_adc.o obj-$(CONFIG_SPEAR_ADC) += spear_adc.o obj-$(CONFIG_SUN4I_GPADC) += sun4i-gpadc-iio.o +obj-$(CONFIG_SUN20I_GPADC) += sun20i-gpadc-iio.o obj-$(CONFIG_STM32_ADC_CORE) += stm32-adc-core.o obj-$(CONFIG_STM32_ADC) += stm32-adc.o obj-$(CONFIG_STM32_DFSDM_CORE) += stm32-dfsdm-core.o diff --git a/drivers/iio/adc/sun20i-gpadc-iio.c b/drivers/iio/adc/sun20i-gpadc-iio.c new file mode 100644 index 000000000000..bd14a6449030 --- /dev/null +++ b/drivers/iio/adc/sun20i-gpadc-iio.c @@ -0,0 +1,281 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * GPADC driver for sunxi platforms (D1, T113-S3 and R329) + * Copyright (c) 2023 Maksim Kiselev + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define SUN20I_GPADC_DRIVER_NAME "sun20i-gpadc" + +/* Register map definition */ +#define SUN20I_GPADC_SR 0x00 +#define SUN20I_GPADC_CTRL 0x04 +#define SUN20I_GPADC_CS_EN 0x08 +#define SUN20I_GPADC_FIFO_INTC 0x0c +#define SUN20I_GPADC_FIFO_INTS 0x10 +#define SUN20I_GPADC_FIFO_DATA 0X14 +#define SUN20I_GPADC_CB_DATA 0X18 +#define SUN20I_GPADC_DATAL_INTC 0x20 +#define SUN20I_GPADC_DATAH_INTC 0x24 +#define SUN20I_GPADC_DATA_INTC 0x28 +#define SUN20I_GPADC_DATAL_INTS 0x30 +#define SUN20I_GPADC_DATAH_INTS 0x34 +#define SUN20I_GPADC_DATA_INTS 0x38 +#define SUN20I_GPADC_CH_CMP_DATA(x) (0x40 + (x) * 4) +#define SUN20I_GPADC_CH_DATA(x) (0x80 + (x) * 4) + +#define SUN20I_GPADC_CTRL_ADC_AUTOCALI_EN_MASK BIT(23) +#define SUN20I_GPADC_CTRL_WORK_MODE_MASK GENMASK(19, 18) +#define SUN20I_GPADC_CTRL_ADC_EN_MASK BIT(16) +#define SUN20I_GPADC_CS_EN_ADC_CH(x) BIT(x) +#define SUN20I_GPADC_DATA_INTC_CH_DATA_IRQ_EN(x) BIT(x) + +#define SUN20I_GPADC_WORK_MODE_SINGLE 0 + +#define SUN20I_GPADC_MAX_CHANNELS 16 + +struct sun20i_gpadc_iio { + void __iomem *regs; + struct completion completion; + int last_channel; + /* + * Lock to protect the device state during a potential concurrent + * read access from userspace. Reading a raw value requires a sequence + * of register writes, then a wait for a completion callback, + * and finally a register read, during which userspace could issue + * another read request. This lock protects a read access from + * ocurring before another one has finished. + */ + struct mutex lock; +}; + +static int sun20i_gpadc_adc_read(struct sun20i_gpadc_iio *info, + struct iio_chan_spec const *chan, int *val) +{ + u32 ctrl; + int ret = IIO_VAL_INT; + + mutex_lock(&info->lock); + + reinit_completion(&info->completion); + + if (info->last_channel != chan->channel) { + info->last_channel = chan->channel; + + /* enable the analog input channel */ + writel(SUN20I_GPADC_CS_EN_ADC_CH(chan->channel), + info->regs + SUN20I_GPADC_CS_EN); + + /* enable the data irq for input channel */ + writel(SUN20I_GPADC_DATA_INTC_CH_DATA_IRQ_EN(chan->channel), + info->regs + SUN20I_GPADC_DATA_INTC); + } + + /* enable the ADC function */ + ctrl = readl(info->regs + SUN20I_GPADC_CTRL); + ctrl |= FIELD_PREP(SUN20I_GPADC_CTRL_ADC_EN_MASK, 1); + writel(ctrl, info->regs + SUN20I_GPADC_CTRL); + + /* + * According to the datasheet maximum acquire time(TACQ) can be + * (65535+1)/24Mhz and conversion time(CONV_TIME) is always constant + * and equal to 14/24Mhz, so (TACQ+CONV_TIME) <= 2.73125ms. + * A 10ms delay should be enough to make sure an interrupt occurs in + * normal conditions. If it doesn't occur, then there is a timeout. + */ + if (!wait_for_completion_timeout(&info->completion, msecs_to_jiffies(10))) { + ret = -ETIMEDOUT; + goto err_unlock; + } + + /* read the ADC data */ + *val = readl(info->regs + SUN20I_GPADC_CH_DATA(chan->channel)); + +err_unlock: + mutex_unlock(&info->lock); + + return ret; +} + +static int sun20i_gpadc_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, + int *val2, long mask) +{ + struct sun20i_gpadc_iio *info = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + return sun20i_gpadc_adc_read(info, chan, val); + case IIO_CHAN_INFO_SCALE: + /* value in mv = 1800mV / 4096 raw */ + *val = 1800; + *val2 = 12; + return IIO_VAL_FRACTIONAL_LOG2; + default: + return -EINVAL; + } +} + +static irqreturn_t sun20i_gpadc_irq_handler(int irq, void *data) +{ + struct sun20i_gpadc_iio *info = data; + + /* clear data interrupt status register */ + writel(GENMASK(31, 0), info->regs + SUN20I_GPADC_DATA_INTS); + + complete(&info->completion); + + return IRQ_HANDLED; +} + +static const struct iio_info sun20i_gpadc_iio_info = { + .read_raw = sun20i_gpadc_read_raw, +}; + +static void sun20i_gpadc_reset_assert(void *data) +{ + struct reset_control *rst = data; + + reset_control_assert(rst); +} + +static int sun20i_gpadc_alloc_channels(struct iio_dev *indio_dev, + struct device *dev) +{ + unsigned int channel; + int num_channels, i, ret; + struct iio_chan_spec *channels; + struct fwnode_handle *node; + + num_channels = device_get_child_node_count(dev); + if (num_channels == 0) + return dev_err_probe(dev, -ENODEV, "no channel children\n"); + + if (num_channels > SUN20I_GPADC_MAX_CHANNELS) + return dev_err_probe(dev, -EINVAL, "num of channel children out of range\n"); + + channels = devm_kcalloc(dev, num_channels, sizeof(*channels), + GFP_KERNEL); + if (!channels) + return -ENOMEM; + + i = 0; + device_for_each_child_node(dev, node) { + ret = fwnode_property_read_u32(node, "reg", &channel); + if (ret) { + fwnode_handle_put(node); + return dev_err_probe(dev, ret, "invalid channel number\n"); + } + + channels[i].type = IIO_VOLTAGE; + channels[i].indexed = 1; + channels[i].channel = channel; + channels[i].info_mask_separate = BIT(IIO_CHAN_INFO_RAW); + channels[i].info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE); + + i++; + } + + indio_dev->channels = channels; + indio_dev->num_channels = num_channels; + + return 0; +} + +static int sun20i_gpadc_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct iio_dev *indio_dev; + struct sun20i_gpadc_iio *info; + struct reset_control *rst; + struct clk *clk; + int irq; + int ret; + + indio_dev = devm_iio_device_alloc(dev, sizeof(*info)); + if (!indio_dev) + return -ENOMEM; + + info = iio_priv(indio_dev); + info->last_channel = -1; + + mutex_init(&info->lock); + init_completion(&info->completion); + + ret = sun20i_gpadc_alloc_channels(indio_dev, dev); + if (ret) + return ret; + + indio_dev->info = &sun20i_gpadc_iio_info; + indio_dev->name = SUN20I_GPADC_DRIVER_NAME; + + info->regs = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(info->regs)) + return PTR_ERR(info->regs); + + clk = devm_clk_get_enabled(dev, NULL); + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), "failed to enable bus clock\n"); + + rst = devm_reset_control_get_exclusive(dev, NULL); + if (IS_ERR(rst)) + return dev_err_probe(dev, PTR_ERR(rst), "failed to get reset control\n"); + + ret = reset_control_deassert(rst); + if (ret) + return dev_err_probe(dev, ret, "failed to deassert reset\n"); + + ret = devm_add_action_or_reset(dev, sun20i_gpadc_reset_assert, rst); + if (ret) + return ret; + + irq = platform_get_irq(pdev, 0); + if (irq < 0) + return irq; + + ret = devm_request_irq(dev, irq, sun20i_gpadc_irq_handler, 0, + dev_name(dev), info); + if (ret) + return dev_err_probe(dev, ret, "failed requesting irq %d\n", irq); + + writel(FIELD_PREP(SUN20I_GPADC_CTRL_ADC_AUTOCALI_EN_MASK, 1) | + FIELD_PREP(SUN20I_GPADC_CTRL_WORK_MODE_MASK, SUN20I_GPADC_WORK_MODE_SINGLE), + info->regs + SUN20I_GPADC_CTRL); + + ret = devm_iio_device_register(dev, indio_dev); + if (ret) + return dev_err_probe(dev, ret, "could not register the device\n"); + + return 0; +} + +static const struct of_device_id sun20i_gpadc_of_id[] = { + { .compatible = "allwinner,sun20i-d1-gpadc" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, sun20i_gpadc_of_id); + +static struct platform_driver sun20i_gpadc_driver = { + .driver = { + .name = SUN20I_GPADC_DRIVER_NAME, + .of_match_table = sun20i_gpadc_of_id, + }, + .probe = sun20i_gpadc_probe, +}; +module_platform_driver(sun20i_gpadc_driver); + +MODULE_DESCRIPTION("ADC driver for sunxi platforms"); +MODULE_AUTHOR("Maksim Kiselev "); +MODULE_LICENSE("GPL"); From patchwork Sat Jun 10 20:19:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maksim Kiselev X-Patchwork-Id: 13275065 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9CE56C7EE2E for ; Sat, 10 Jun 2023 20:21:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=l1yDQLzkKLDerNZH03KuLiPboamBNgFAEelM6IPkOUQ=; b=ObnsXBCuM21zaS lQbZmMGzPJc70HFkdXUN3b7v7h68agjUu9glx/Col24JRL8+4fguzihll8PfPkZsYuRRGwc1B12Ko 8izt0wWbgqOzuSaWZX9homHRMukfcH/sxlTY8jEhVs2psq4WpPpoJwDPjsfvR0GE/RJc62GItEYJD 67ItD0ngyR+klli1Xo9fsH3ybO8A6oUop836S2Hn1sidYW2NG1kUX1tzVUqX71dIwkTjm+2ecVKG2 PhFR3fIRAuiO9uuo5Qu+JDtOGYK31NQ8eNRBWhTMcWkZYznEAz+oC/8LAfSNauXqc7gc0mLBjGupi L/O8FGJZ6hjTMsh9999Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q855D-00GzE9-1h; Sat, 10 Jun 2023 20:21:11 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q8559-00GzBd-14; Sat, 10 Jun 2023 20:21:09 +0000 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3094910b150so2910931f8f.0; Sat, 10 Jun 2023 13:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686428465; x=1689020465; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HwlNr/WLM3KKZTrIdFCLg61Yoj39feXOCHJbchF+mgM=; b=fTmAmr+5to5leCNYnFTwILHcBPZQ0ECfy4oFDnIx8zo01PmKgZS8EA9eQE2dC20MJZ +PHKS78ldecBv8GsOho8+FIhN+xHHn1p3oCs8maUhXxkCeNI+Bq685OMQpxZPyxnJzch suCfpswQDaJQuRGPpAb5RiTy7k+9omxLHsLkhV52AxXK7gFzpawSlUvi7oLy3mo9ph6T uYcGZIOn3/yIxSNkXkVamU1i0VGoFXXNClE17vSdO9fpKoDVtx7EnsWQLNEEaaUk5lSE ouRnvtXahKdqDsp52J3KrKmKzmpE6WIyZTVxIidD+ovRNBBmA4tDaX2joovcA3WmDRLE 25AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686428465; x=1689020465; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HwlNr/WLM3KKZTrIdFCLg61Yoj39feXOCHJbchF+mgM=; b=IkwTNMzUNDeKEe+wm+v18IDZQuUV7FLU+KZqNc+lTsZhruFpgSVWnwooRTipNZZX6z 0zXf21pg9ETaHVz9FOFWgJHUPG8cUnJTqdsm49O2qdvMf+zyNg0kgCjroCWBcsxkzegm MP1QFE3YMWE6ohZB4QHIKh82NFnCWiI1QxhCpInM2cKzM4oTPgcc4hc8NFN5Pr2vnWMn ICpsXh56B8Z+l1g9beArFeULD51ZKPaWMdVatRSW1crOhGxN5eK9n0EoynIxg3otIi5a r7AMrTIeHNxXFZL25bsZ5LglWXHjN3C4rbnUfiT3/f+rlCmMCvieRmb4A9JKD9RbwER2 VzNQ== X-Gm-Message-State: AC+VfDzEIoG792bZm4saIfwH6Xn70fITcrHiW8Y3b0sIZmXjkb8LqAhC FSMKFI87JUUOvEP70n7jz7o= X-Google-Smtp-Source: ACHHUZ6Cx2GIHN6yMr+Avkyx6iMnRVy/dyI/hNY1MJdhy7I0Tjtr+dNcDWnh5t7W1qpmMyNgj0VyCw== X-Received: by 2002:a5d:4e84:0:b0:306:27db:16c3 with SMTP id e4-20020a5d4e84000000b0030627db16c3mr1980878wru.50.1686428465475; Sat, 10 Jun 2023 13:21:05 -0700 (PDT) Received: from user-PC.. ([92.51.95.194]) by smtp.gmail.com with ESMTPSA id m11-20020a5d6a0b000000b0030b5d203e7esm7878116wru.97.2023.06.10.13.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jun 2023 13:21:05 -0700 (PDT) From: Maksim Kiselev To: linux-iio@vger.kernel.org Cc: Maxim Kiselev , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Paul Walmsley , Palmer Dabbelt , Albert Ou , Philipp Zabel , Cristian Ciocaltea , Heiko Stuebner , Andy Shevchenko , Cosmin Tanislav , Hugo Villeneuve , Ulf Hansson , Arnd Bergmann , ChiaEn Wu , Ibrahim Tilki , ChiYuan Huang , Ramona Bolboaca , William Breathitt Gray , =?utf-8?q?Leonard_G=C3=B6?= =?utf-8?q?hrs?= , Caleb Connolly , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v5 2/3] dt-bindings: iio: adc: Add Allwinner D1/T113s/R329/T507 SoCs GPADC Date: Sat, 10 Jun 2023 23:19:49 +0300 Message-Id: <20230610202005.1118049-3-bigunclemax@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230610202005.1118049-1-bigunclemax@gmail.com> References: <20230610202005.1118049-1-bigunclemax@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230610_132107_369493_B6E9564B X-CRM114-Status: GOOD ( 13.70 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Maxim Kiselev Allwinner's D1/T113s/R329/T507 SoCs have a new general purpose ADC. This ADC is the same for all of this SoCs. The only difference is the number of available channels. Signed-off-by: Maxim Kiselev Reviewed-by: Conor Dooley --- .../iio/adc/allwinner,sun20i-d1-gpadc.yaml | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml diff --git a/Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml b/Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml new file mode 100644 index 000000000000..43256ad2b7ed --- /dev/null +++ b/Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml @@ -0,0 +1,91 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/allwinner,sun20i-d1-gpadc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Allwinner D1 General Purpose ADC + +maintainers: + - Maksim Kiselev + +properties: + compatible: + enum: + - allwinner,sun20i-d1-gpadc + + "#io-channel-cells": + const: 1 + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + + clocks: + maxItems: 1 + + interrupts: + maxItems: 1 + + reg: + maxItems: 1 + + resets: + maxItems: 1 + +patternProperties: + "^channel@([0-15])$": + $ref: adc.yaml + type: object + description: + Represents the internal channels of the ADC. + + properties: + reg: + items: + minimum: 0 + maximum: 15 + + required: + - reg + + unevaluatedProperties: false + +required: + - "#io-channel-cells" + - clocks + - compatible + - interrupts + - reg + - resets + +additionalProperties: false + +examples: + - | + #include + #include + #include + + gpadc: adc@2009000 { + compatible = "allwinner,sun20i-d1-gpadc"; + reg = <0x2009000 0x1000>; + clocks = <&ccu CLK_BUS_GPADC>; + resets = <&ccu RST_BUS_GPADC>; + interrupts = <73 IRQ_TYPE_LEVEL_HIGH>; + #io-channel-cells = <1>; + + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0>; + }; + + channel@1 { + reg = <1>; + }; + }; +... From patchwork Sat Jun 10 20:19:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maksim Kiselev X-Patchwork-Id: 13275066 X-Patchwork-Delegate: mail@conchuod.ie 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63279C7EE29 for ; Sat, 10 Jun 2023 20:21:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ykkXplSPzTWz12JdxRq5t//LP3nCPq8Jin5M9FRThJc=; b=zo+w+mWQeBCoSK sPKQkpVmjaieelZceEIKv70U8KKPgE4+0BmqsUF3EVWEKpCoYPjKBgE7cPGq0z8tz3Z7SeflajH0p fIB+5JOVRag99FMy3iKO59dT9KYvtdqcHiGHIH/O2AXUiw2vs3MfIru2f2B0rGyqWPzpFdjyqfsYI 11jr3/oam5s7CLKyaxUWyW884JjoD6ywLHJyhLzrWI/3FznuixjtiAVl+dfeEBkGjTisM1ePwGf5N JqHh8x4AHWwvwGVevRc0iDz9njMhRP9qcV/4D/BhWV0y3aKT8j9lFZkBb5Qev3VsQJ393z3AOTjJi oZ/dy+cyDsYCRuBJHkEA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q855W-00GzLD-0U; Sat, 10 Jun 2023 20:21:30 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q855S-00GzIx-2n; Sat, 10 Jun 2023 20:21:28 +0000 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-30e53cacc10so1813079f8f.0; Sat, 10 Jun 2023 13:21:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686428484; x=1689020484; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9/TmEA+PoC7xu6/KU/ll32pvJQ2ck1CrGNuRyF6FIV0=; b=q/HkAmIWDbgYoNWDDvT9YG/eWL52I35C0UJbDbI1HdQKZp+vNeYsWGUudS+FVnuO7q hw7oXcII3vxaWQLMSONG8XrmkQct32TLHET/Ql5xDmhf5uiDqZnN4HQBe0w6LiWQo4zd KTb5ddXVdsLXL2s6ElAylt2FpfdAEz/YboO5Hd9p0zgz1ZqnKlP4moTQmkNENgKys9yq mpoOc0nPZTKaYEZAPyPIOx48Ac/nQIeNMRCdldsJb3ivr3NtfDBs1TpRJIyLuZXgA0Am 1FqqmH4xUJnhQrzIBYrZggfwm3JglxUDmeeEh4F7S0htHerNjv2xR07w23BaRpcpwXLv 4Gsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686428484; x=1689020484; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9/TmEA+PoC7xu6/KU/ll32pvJQ2ck1CrGNuRyF6FIV0=; b=dWTNK+jAOd6bjVcaHG8rshUI07B3+n+hn8yNG+YtwcfVOXH3/yQ8mOP6RTx2kYK8bD KmtbLfbjcDAqbP4Tz+QMSMDahOrWf42+3YzEqT2T/M9tv7I9Z4aVnEhEtSS9r+Da18TE 4nSW4gl7+9+7uR9fPYielT3AMbZp/JU3lNtr08y5PvQ2YzqE8zUyGopwaE2UaC1bYzqf ROAWSNxUYR8vOyLj9azLY/vZJfo8eHBBlDrLRw37UzNFpFpxgpfUDRZWHUB7lDFDeSv+ RLgVxMk5C1j2gaMQ7onBNKXvc4i5nXOgL7+ZF59TTVKmvo7tgNOPiomHffrTO9Eph9/j CTEw== X-Gm-Message-State: AC+VfDymXj9IcI3X2MFRxCAM1JF9CbRWzKsnLOldINmkJLHpjFnamj8m zSooDC0PYa6nuTopgl3NhHo= X-Google-Smtp-Source: ACHHUZ5DbztnfIc7NFufk8XwP3nLXNU5KRP/S//g+7bbSRmQvPvKaCzCwkR1IA7NmuIeIlqhNtOGqg== X-Received: by 2002:a5d:4111:0:b0:30f:babb:4e02 with SMTP id l17-20020a5d4111000000b0030fbabb4e02mr339596wrp.10.1686428484369; Sat, 10 Jun 2023 13:21:24 -0700 (PDT) Received: from user-PC.. ([92.51.95.194]) by smtp.gmail.com with ESMTPSA id m11-20020a5d6a0b000000b0030b5d203e7esm7878116wru.97.2023.06.10.13.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jun 2023 13:21:24 -0700 (PDT) From: Maksim Kiselev To: linux-iio@vger.kernel.org Cc: Maxim Kiselev , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Paul Walmsley , Palmer Dabbelt , Albert Ou , Philipp Zabel , Cristian Ciocaltea , Heiko Stuebner , Andy Shevchenko , Cosmin Tanislav , Hugo Villeneuve , Alexander Sverdlin , Marcus Folkesson , ChiYuan Huang , Ramona Bolboaca , Ibrahim Tilki , ChiaEn Wu , William Breathitt Gray , Arnd Bergmann , =?utf-8?q?Leonard_G=C3=B6hrs?= , Caleb Connolly , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v5 3/3] riscv: dts: allwinner: d1: Add GPADC node Date: Sat, 10 Jun 2023 23:19:50 +0300 Message-Id: <20230610202005.1118049-4-bigunclemax@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230610202005.1118049-1-bigunclemax@gmail.com> References: <20230610202005.1118049-1-bigunclemax@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230610_132126_903515_02A2F41E X-CRM114-Status: GOOD ( 10.03 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Maxim Kiselev This patch adds declaration of the general purpose ADC for D1 and T113s SoCs. Signed-off-by: Maxim Kiselev --- arch/riscv/boot/dts/allwinner/sunxi-d1s-t113.dtsi | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/riscv/boot/dts/allwinner/sunxi-d1s-t113.dtsi b/arch/riscv/boot/dts/allwinner/sunxi-d1s-t113.dtsi index 922e8e0e2c09..90c79041cfba 100644 --- a/arch/riscv/boot/dts/allwinner/sunxi-d1s-t113.dtsi +++ b/arch/riscv/boot/dts/allwinner/sunxi-d1s-t113.dtsi @@ -138,6 +138,16 @@ ccu: clock-controller@2001000 { #reset-cells = <1>; }; + gpadc: adc@2009000 { + compatible = "allwinner,sun20i-d1-gpadc"; + reg = <0x2009000 0x1000>; + clocks = <&ccu CLK_BUS_GPADC>; + resets = <&ccu RST_BUS_GPADC>; + interrupts = ; + status = "disabled"; + #io-channel-cells = <1>; + }; + dmic: dmic@2031000 { compatible = "allwinner,sun20i-d1-dmic", "allwinner,sun50i-h6-dmic";