From patchwork Sat Sep 7 06:50:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 13795094 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7538146D65 for ; Sat, 7 Sep 2024 06:50:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691855; cv=none; b=VnmgngR/L1/dIRw6/sBH2jV0CozVCo8/UlZIwfkqNgRCI58AMqFI0g3psb7v+dHkRMLOrKLmvssRZHlj4KFwAmvt3M5fnKCXNApF33HPXJOo5iUBFIKI63GYEeHD+5D4GZRLKVNEjvTJfN1FLYPntGC0O2w2TwzYDWuaPplJVO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691855; c=relaxed/simple; bh=RurNE9Ha90Rn5+C8di0PSCRyHdhsAmm8wmhIHv8jvRc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GyfwCLWXKTT/WmncoP0sThX4NGY3KExsOZXmDn1ejMQ/NGYr/soQln886DCUPSoK7veXpUy0fHUF6heuTqSqXdSjEJcw5bu8Lor8/uKoxDSm0IjOLdUzk+vLAV3gee7sDOjxe/18aJsDe4oAIbx4kL2MHm8+Rue5llB/+UYfmEk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=zcCG0mIu; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="zcCG0mIu" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a8a7929fd64so307601666b.0 for ; Fri, 06 Sep 2024 23:50:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725691851; x=1726296651; darn=vger.kernel.org; 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=h3JtexnWjnXvUsidh7QMdp79QHg5ea8WTGp7w/eiApA=; b=zcCG0mIuUklDloXWj53/YjPgBgY3fDQrETP7o2IR6Qhg1HwQJ8zKpiESLyvy9swsr4 J7B/oEYMcIqtyN5kx97uvS2BtvUHJ7lynUZvo5yp7tKMToH50umn7rqTwhdzsDdNLvkq ajCYhhyEDNpbPVzG8pH9I/17ie/gRXdG58HiXVY2Y7q9k8eMSh3Bl5wORKNwbNZN3AO8 io1UsPGgDj4UjBmhvkLe+/QpLK8ahg596PwL1TrUPDMfegHMGGe3Qt2LDP4ka5GzgoP9 fVXLeM25vKaGGMHLAy5fR98r7K+yZYD/iifofiTcsyoflANAw0PNCFhpLU1hRardhMiw 4iEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725691851; x=1726296651; 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=h3JtexnWjnXvUsidh7QMdp79QHg5ea8WTGp7w/eiApA=; b=Ukq0kYLKvLVBo241UWHL+F+BhTTbsVMrLw1hgf5Y2el4w0BMNAeyu1RKNvApxQRycO mQ3VvW+F8onOkOt07qJZsQD/Bcvkyfxaq0459SyXkE6bmrIfW7UOAZLTzeNNBO6ueUh9 p6D6X0XMVrA4CqtLfHBLUWNYkVPE4vr2yybGoi8EEosfJD2+TDwEMxF1Y+SVjahjIqCE NkiteS1o/bKvZukchr5i6wpQeGQ5sFCHe9HMQkCWW+fEeBrFto3NJv1ZGiNfoNszUtk9 3n4+HB0UxQoOc5zQOemZVTCxUtGWQXO5otZ58zfEM6uQ6K7dQ5qv5ZdFHvIyFH0x0Aks sIKA== X-Gm-Message-State: AOJu0YzVBV0/tc0v9pn26Pmqa+YXZp9cFIROvYUIKXr//xdSq+TcIx+V mtUzRfTr3ljLSP9OpecsCI44ZBXAknn7msmk4dsvMLetatMh2ida/WhZsO53LcdMgIcQPDmMPe8 xs1o= X-Google-Smtp-Source: AGHT+IGvkxQf/n2NX2cE2z+X+S7ZUQH6/Izb8AcLwNQDLeE+Z0alDWqW1olFQP1RmToFlXgRSvK83g== X-Received: by 2002:a17:907:3d9f:b0:a86:b789:164b with SMTP id a640c23a62f3a-a8a88870eb7mr344487166b.58.1725691849956; Fri, 06 Sep 2024 23:50:49 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25835a76sm36539266b.39.2024.09.06.23.50.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 23:50:49 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, Nuno Sa , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH v5 1/9] iio: adc: ad7606: remove frstdata check for serial mode Date: Sat, 7 Sep 2024 09:50:34 +0300 Message-ID: <20240907065043.771364-2-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240907065043.771364-1-aardelean@baylibre.com> References: <20240907065043.771364-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Guillaume Stols The current implementation attempts to recover from an eventual glitch in the clock by checking frstdata state after reading the first channel's sample: If frstdata is low, it will reset the chip and return -EIO. This will only work in parallel mode, where frstdata pin is set low after the 2nd sample read starts. For the serial mode, according to the datasheet, "The FRSTDATA output returns to a logic low following the 16th SCLK falling edge.", thus after the Xth pulse, X being the number of bits in a sample, the check will always be true, and the driver will not work at all in serial mode if frstdata(optional) is defined in the devicetree as it will reset the chip, and return -EIO every time read_sample is called. Hence, this check must be removed for serial mode. Fixes: b9618c0cacd7 ("staging: IIO: ADC: New driver for AD7606/AD7606-6/AD7606-4") Signed-off-by: Guillaume Stols Reviewed-by: Nuno Sa Link: https://patch.msgid.link/20240702-cleanup-ad7606-v3-1-18d5ea18770e@baylibre.com Cc: Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ad7606.c | 28 ++------------------- drivers/iio/adc/ad7606.h | 2 ++ drivers/iio/adc/ad7606_par.c | 48 +++++++++++++++++++++++++++++++++--- 3 files changed, 49 insertions(+), 29 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 539e4a8621fe..9b457472d49c 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -49,7 +49,7 @@ static const unsigned int ad7616_oversampling_avail[8] = { 1, 2, 4, 8, 16, 32, 64, 128, }; -static int ad7606_reset(struct ad7606_state *st) +int ad7606_reset(struct ad7606_state *st) { if (st->gpio_reset) { gpiod_set_value(st->gpio_reset, 1); @@ -60,6 +60,7 @@ static int ad7606_reset(struct ad7606_state *st) return -ENODEV; } +EXPORT_SYMBOL_NS_GPL(ad7606_reset, IIO_AD7606); static int ad7606_reg_access(struct iio_dev *indio_dev, unsigned int reg, @@ -86,31 +87,6 @@ static int ad7606_read_samples(struct ad7606_state *st) { unsigned int num = st->chip_info->num_channels - 1; u16 *data = st->data; - int ret; - - /* - * The frstdata signal is set to high while and after reading the sample - * of the first channel and low for all other channels. This can be used - * to check that the incoming data is correctly aligned. During normal - * operation the data should never become unaligned, but some glitch or - * electrostatic discharge might cause an extra read or clock cycle. - * Monitoring the frstdata signal allows to recover from such failure - * situations. - */ - - if (st->gpio_frstdata) { - ret = st->bops->read_block(st->dev, 1, data); - if (ret) - return ret; - - if (!gpiod_get_value(st->gpio_frstdata)) { - ad7606_reset(st); - return -EIO; - } - - data++; - num--; - } return st->bops->read_block(st->dev, num, data); } diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 0c6a88cc4695..6649e84d25de 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -151,6 +151,8 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, const char *name, unsigned int id, const struct ad7606_bus_ops *bops); +int ad7606_reset(struct ad7606_state *st); + enum ad7606_supported_device_ids { ID_AD7605_4, ID_AD7606_8, diff --git a/drivers/iio/adc/ad7606_par.c b/drivers/iio/adc/ad7606_par.c index b5975bbfcbe0..02d8c309304e 100644 --- a/drivers/iio/adc/ad7606_par.c +++ b/drivers/iio/adc/ad7606_par.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -21,8 +22,29 @@ static int ad7606_par16_read_block(struct device *dev, struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad7606_state *st = iio_priv(indio_dev); - insw((unsigned long)st->base_address, buf, count); + /* + * On the parallel interface, the frstdata signal is set to high while + * and after reading the sample of the first channel and low for all + * other channels. This can be used to check that the incoming data is + * correctly aligned. During normal operation the data should never + * become unaligned, but some glitch or electrostatic discharge might + * cause an extra read or clock cycle. Monitoring the frstdata signal + * allows to recover from such failure situations. + */ + int num = count; + u16 *_buf = buf; + + if (st->gpio_frstdata) { + insw((unsigned long)st->base_address, _buf, 1); + if (!gpiod_get_value(st->gpio_frstdata)) { + ad7606_reset(st); + return -EIO; + } + _buf++; + num--; + } + insw((unsigned long)st->base_address, _buf, num); return 0; } @@ -35,8 +57,28 @@ static int ad7606_par8_read_block(struct device *dev, { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad7606_state *st = iio_priv(indio_dev); - - insb((unsigned long)st->base_address, buf, count * 2); + /* + * On the parallel interface, the frstdata signal is set to high while + * and after reading the sample of the first channel and low for all + * other channels. This can be used to check that the incoming data is + * correctly aligned. During normal operation the data should never + * become unaligned, but some glitch or electrostatic discharge might + * cause an extra read or clock cycle. Monitoring the frstdata signal + * allows to recover from such failure situations. + */ + int num = count; + u16 *_buf = buf; + + if (st->gpio_frstdata) { + insb((unsigned long)st->base_address, _buf, 2); + if (!gpiod_get_value(st->gpio_frstdata)) { + ad7606_reset(st); + return -EIO; + } + _buf++; + num--; + } + insb((unsigned long)st->base_address, _buf, num * 2); return 0; } From patchwork Sat Sep 7 06:50:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 13795095 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60A021494BD for ; Sat, 7 Sep 2024 06:50:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691857; cv=none; b=JnQcWrTocpg6PY9pVc1uTnOnkevTPpiZJ05Jofzc1hND9pWIQHY0wYw+0SsydFrQD0piS7cC6ytZtZPS+HMNZHJXFJB8eoCLdNsKalxzTUbfjYAdlQsFIDuHGZNAUxlUTG2HN/j2dg2vWXzezNbQsw3aZU1GdA03Jb7tvvkpx2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691857; c=relaxed/simple; bh=NnhAJQBJzpZTWf9ZHFLmLmSoGg+UPZzZPZwyu2zRvAI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L9kwojpi2L2cPwGlMxqNGOMTWqSnwWruhZ3ZPeKHMpWm1gKG9PqwKtsYhKNYf+wpARZj8KnKD/+Tz3r7YVCClcnhcAr6oZ4WNFk+58eiFNSQX3V6IyCgNdQTKaiPAQib4rSQ8mNPdzuj5Rm/DjQKXCr3jSR0OH0zZK/moPxYYtA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=PwXlGtk4; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="PwXlGtk4" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-5365aec6fc1so1408833e87.3 for ; Fri, 06 Sep 2024 23:50:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725691853; x=1726296653; darn=vger.kernel.org; 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=9QIaOK2ELUCzmVw69s9QKwCGqHYmV8BBwk11dJWdR7M=; b=PwXlGtk4Cezkr1wOOrd5Bx2LvuCkzzNIzoX5exBXGcPILZjR1lzvzyGiR/tWtSLAPc ic8IOOObCfVyuzILLAceQx2iVatKme+nuwoc8f8ZG2s3sIUoGCb+ChtV/t0ftZOWWqy+ qgGDfT6TslTyqKA69DbSmKtNa5aVQmU/OLtxg8WFd+792C3grM6HWQGW/aYGlpvimcnR AkEE7gdE7C1hdgkd136w6X9YxrhkEG4otFavebEH8QLFyz9/XQI5YAatIIpS66b2h9X0 bRqtQk2i/zeC8qpUvLyljv7cEHXmUFWs+fxH3QwzTyRgatYO5b0C0Pkj4r5wsP8v3oWD yXIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725691853; x=1726296653; 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=9QIaOK2ELUCzmVw69s9QKwCGqHYmV8BBwk11dJWdR7M=; b=jWlUlP40yTbwDUCGymYkWEOdQ6fEkcA35tl7kYqInbJj1rcZhT/kI6KD9Oq5aTEVtp M2CsSNVOtMmx5HA6Jztac/XV0qUPkmt4NSpM+/Ux/3nvmuluJg6gM1vBbp9CzX8m7f09 Tc9SdF4tQdjetZA48yzRljf8b+LtCEaH/z7/DNwiWkk/2nfaNSG1+Xg8RazZc+Z8JJ5F lIWtRPxk+0FfRdUnhzj7+HAhLyxI4C/sKzJUZYGdHg+aHXCk5MC/j/JUQt2rliXDMnv/ M3oX81h7M6B5HhBTfpdzdlvaSLzHiQHDh2VN9dVHFGEYdYduWJCtGFTTXnDFkSoGbwX+ DQiw== X-Gm-Message-State: AOJu0YwGo2eLeGiEQJ/Vt9QHkoyFdRP0yxoKZtS2/JL23IPCki+lBJBK o+XBag7xCWxHk7Ne9uvTf5myzmo4M1JS0hq4gO8XQSvrvlxqoZvdy9/WIVYxcPaKlHWQpN2XjiE fYaA= X-Google-Smtp-Source: AGHT+IGDJhYReTqFur0m0xhFFPRRr0K5nQluJLBA90FTLp0fQEp0LWuyDqIRFcNMjZ/hC0jzc+s3pw== X-Received: by 2002:a05:6512:2348:b0:52f:eb:aaca with SMTP id 2adb3069b0e04-536587b4586mr3113934e87.32.1725691851871; Fri, 06 Sep 2024 23:50:51 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25835a76sm36539266b.39.2024.09.06.23.50.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 23:50:51 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, Alexandru Ardelean Subject: [PATCH v5 2/9] iio: adc: ad7606: add 'bits' parameter to channels macros Date: Sat, 7 Sep 2024 09:50:35 +0300 Message-ID: <20240907065043.771364-3-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240907065043.771364-1-aardelean@baylibre.com> References: <20240907065043.771364-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There are some newer additions to the AD7606 family, which support 18 bit precision. Up until now, all chips were 16 bit. This change adds a 'bits' parameter to the AD760X_CHANNEL macro and renames 'ad7606_channels' -> 'ad7606_channels_16bit' for the current devices. The AD7606_SW_CHANNEL() macro is also introduced, as a short-hand for IIO channels in SW mode. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 58 ++++++++++++++++++------------------ drivers/iio/adc/ad7606.h | 18 ++++++----- drivers/iio/adc/ad7606_spi.c | 16 +++++----- 3 files changed, 47 insertions(+), 45 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 9b457472d49c..8ebfe8abc3f4 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -309,16 +309,16 @@ static const struct iio_chan_spec ad7605_channels[] = { AD7605_CHANNEL(3), }; -static const struct iio_chan_spec ad7606_channels[] = { +static const struct iio_chan_spec ad7606_channels_16bit[] = { IIO_CHAN_SOFT_TIMESTAMP(8), - AD7606_CHANNEL(0), - AD7606_CHANNEL(1), - AD7606_CHANNEL(2), - AD7606_CHANNEL(3), - AD7606_CHANNEL(4), - AD7606_CHANNEL(5), - AD7606_CHANNEL(6), - AD7606_CHANNEL(7), + AD7606_CHANNEL(0, 16), + AD7606_CHANNEL(1, 16), + AD7606_CHANNEL(2, 16), + AD7606_CHANNEL(3, 16), + AD7606_CHANNEL(4, 16), + AD7606_CHANNEL(5, 16), + AD7606_CHANNEL(6, 16), + AD7606_CHANNEL(7, 16), }; /* @@ -333,22 +333,22 @@ static const struct iio_chan_spec ad7606_channels[] = { */ static const struct iio_chan_spec ad7616_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(16), - AD7606_CHANNEL(0), - AD7606_CHANNEL(1), - AD7606_CHANNEL(2), - AD7606_CHANNEL(3), - AD7606_CHANNEL(4), - AD7606_CHANNEL(5), - AD7606_CHANNEL(6), - AD7606_CHANNEL(7), - AD7606_CHANNEL(8), - AD7606_CHANNEL(9), - AD7606_CHANNEL(10), - AD7606_CHANNEL(11), - AD7606_CHANNEL(12), - AD7606_CHANNEL(13), - AD7606_CHANNEL(14), - AD7606_CHANNEL(15), + AD7606_CHANNEL(0, 16), + AD7606_CHANNEL(1, 16), + AD7606_CHANNEL(2, 16), + AD7606_CHANNEL(3, 16), + AD7606_CHANNEL(4, 16), + AD7606_CHANNEL(5, 16), + AD7606_CHANNEL(6, 16), + AD7606_CHANNEL(7, 16), + AD7606_CHANNEL(8, 16), + AD7606_CHANNEL(9, 16), + AD7606_CHANNEL(10, 16), + AD7606_CHANNEL(11, 16), + AD7606_CHANNEL(12, 16), + AD7606_CHANNEL(13, 16), + AD7606_CHANNEL(14, 16), + AD7606_CHANNEL(15, 16), }; static const struct ad7606_chip_info ad7606_chip_info_tbl[] = { @@ -358,25 +358,25 @@ static const struct ad7606_chip_info ad7606_chip_info_tbl[] = { .num_channels = 5, }, [ID_AD7606_8] = { - .channels = ad7606_channels, + .channels = ad7606_channels_16bit, .num_channels = 9, .oversampling_avail = ad7606_oversampling_avail, .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), }, [ID_AD7606_6] = { - .channels = ad7606_channels, + .channels = ad7606_channels_16bit, .num_channels = 7, .oversampling_avail = ad7606_oversampling_avail, .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), }, [ID_AD7606_4] = { - .channels = ad7606_channels, + .channels = ad7606_channels_16bit, .num_channels = 5, .oversampling_avail = ad7606_oversampling_avail, .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), }, [ID_AD7606B] = { - .channels = ad7606_channels, + .channels = ad7606_channels_16bit, .num_channels = 9, .oversampling_avail = ad7606_oversampling_avail, .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 6649e84d25de..204a343067e5 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -8,7 +8,7 @@ #ifndef IIO_ADC_AD7606_H_ #define IIO_ADC_AD7606_H_ -#define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all) { \ +#define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all, bits) { \ .type = IIO_VOLTAGE, \ .indexed = 1, \ .channel = num, \ @@ -19,24 +19,26 @@ .scan_index = num, \ .scan_type = { \ .sign = 's', \ - .realbits = 16, \ - .storagebits = 16, \ + .realbits = (bits), \ + .storagebits = (bits) > 16 ? 32 : 16, \ .endianness = IIO_CPU, \ }, \ } #define AD7605_CHANNEL(num) \ AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \ - BIT(IIO_CHAN_INFO_SCALE), 0) + BIT(IIO_CHAN_INFO_SCALE), 0, 16) -#define AD7606_CHANNEL(num) \ +#define AD7606_CHANNEL(num, bits) \ AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \ BIT(IIO_CHAN_INFO_SCALE), \ - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO)) + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), bits) -#define AD7616_CHANNEL(num) \ +#define AD7606_SW_CHANNEL(num, bits) \ AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),\ - 0, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO)) + 0, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), bits) + +#define AD7616_CHANNEL(num) AD7606_SW_CHANNEL(num, 16) /** * struct ad7606_chip_info - chip specific information diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c index 62ec12195307..e00f58a6a0e9 100644 --- a/drivers/iio/adc/ad7606_spi.c +++ b/drivers/iio/adc/ad7606_spi.c @@ -67,14 +67,14 @@ static const struct iio_chan_spec ad7616_sw_channels[] = { static const struct iio_chan_spec ad7606b_sw_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(8), - AD7616_CHANNEL(0), - AD7616_CHANNEL(1), - AD7616_CHANNEL(2), - AD7616_CHANNEL(3), - AD7616_CHANNEL(4), - AD7616_CHANNEL(5), - AD7616_CHANNEL(6), - AD7616_CHANNEL(7), + AD7606_SW_CHANNEL(0, 16), + AD7606_SW_CHANNEL(1, 16), + AD7606_SW_CHANNEL(2, 16), + AD7606_SW_CHANNEL(3, 16), + AD7606_SW_CHANNEL(4, 16), + AD7606_SW_CHANNEL(5, 16), + AD7606_SW_CHANNEL(6, 16), + AD7606_SW_CHANNEL(7, 16), }; static const unsigned int ad7606B_oversampling_avail[9] = { From patchwork Sat Sep 7 06:50:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 13795096 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8F8F1494A8 for ; Sat, 7 Sep 2024 06:50:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691857; cv=none; b=XSF1zfJ/isTDPsEZSws54i+5wv5lfWwLOxYSXP906rxQARMRLPYuwwC2X+f5LCmi7ig3IAAhY4YwpOe1VDgQ79S5ilvYUyl5uNtokSqGaSD4BrgShK2rQiyDUpP6+9qjSiY/3e/tmAv9hEkdVLYjEDH5nd8imXAiCZWdELr0Gb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691857; c=relaxed/simple; bh=ReX1tcN+8IqMEgTbR3kytKFtMyNG7SXasp/uFdZgMvM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z7w0eETFr6y2YxQmLRKyPmW2ilXNygEIPwGH5PT3lLRjPaBYnfiyYiRR/06EkOQ1yDbBQoG2cXsN9iUHAmNmZ5s92YxxNdIUt2auLoajENSKAk+eIxzHg3iDAO50UCFijJzXjw4/Nh1EepAi7GVTfZ1sc7cG638f799aV1/LrIo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=3aMGbeMX; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="3aMGbeMX" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a8696e9bd24so355837766b.0 for ; Fri, 06 Sep 2024 23:50:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725691854; x=1726296654; darn=vger.kernel.org; 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=IhYVin5vQT0MSKwrGG9FGK6a0HpbK2VnCXypCXGshr0=; b=3aMGbeMXzkQDBQlQO6DsjXHymz2qROUIG8V3jkjnzUx1THGI9nA5+ZcPYy+ZNAjlBT 6U03LTRliHFQyXNtk9W49WM6Eq4B33q3rVZxPpO8T+6XCA5pZthZsAiT+SO33deiYaZ6 O2ANYUNMplR8sgcc6t4HwZ9yAWxomVlql529T1NBSuecYIlhG4/bC/Qf7vzMX7lsFqCF 2btdP3zadYIZa7Z3LVSKSNsEGJj5bwzt67nDpBMJc21l0BpWIZ10KA//dTADuTcYK2V1 ncKtAcKBmE/GV7m3zZ/s6/GH50Xoahbsa6TXHTsQjXKoaAKiiOFRhdZBtG8RbJGYn/Yo IJnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725691854; x=1726296654; 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=IhYVin5vQT0MSKwrGG9FGK6a0HpbK2VnCXypCXGshr0=; b=msyCrDC14lAlWsnYYhpi+MQK1Pe8HwuLECasrE4/8DV33CBaeETOWfbkhOTlQ9+sz1 9nzmyzkfJ4l0pywr3iQ0YryxRRrc1uDh/DfTONW8t2EgHQewx169YEHApbK5hUB3PEoO y4e0MHHVxLAhMVPraJKDU5QMHiD2ooiulKVfiiyCkED8uyY6tb/tKPOHW8L50U425+wj VGV1aElF+l7uDmKouJ+VrOvRv6+LxcAv0kSf1nolAdfYwe9IcDG8FxaUzWC096Bm+3Ub 3bTFtTctQRNEwQH6cxcZmh6fPXcFlr524w0n4oisgYypjqiP58x/JrUuKTLZmfBaHQrc 3TEw== X-Gm-Message-State: AOJu0YwSAG/bf7X33dImDzRljmPKqUjvgOI0XSa1NV5x5V55tRbHEh0W bzAlyG5+1iXxo3ds8Azcj2t/hU04ygaqA+/W+jlTijFfZaUvNO0zZuvk7hQr3P/4NxYsBAiUi1i j/sU= X-Google-Smtp-Source: AGHT+IHoPfEDsWIq0u4z+PJUMCGdKNmjGDdO9gTrnoCfWIHbvrCb+iCAjNF8nE/gdzLtc4wDz3CPAw== X-Received: by 2002:a17:907:3e1f:b0:a86:79a2:ab12 with SMTP id a640c23a62f3a-a8d1c4d7748mr148169166b.38.1725691853607; Fri, 06 Sep 2024 23:50:53 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25835a76sm36539266b.39.2024.09.06.23.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 23:50:53 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, Alexandru Ardelean , David Lechner Subject: [PATCH v5 3/9] iio: adc: ad7606: move 'val' pointer to ad7606_scan_direct() Date: Sat, 7 Sep 2024 09:50:36 +0300 Message-ID: <20240907065043.771364-4-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240907065043.771364-1-aardelean@baylibre.com> References: <20240907065043.771364-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The ad7606_scan_direct() function returns 'int', which is fine for 16-bit samples. But when going to 18-bit samples, these need to be implemented as 32-bit (or int) type. In that case when getting samples (which can be negative), we'd get random error codes. So, the easiest thing is to just move the 'val' pointer to 'ad7606_scan_direct()'. This doesn't qualify as a fix, it's just a preparation for 18-bit ADCs (of the AD7606 family). Reviewed-by: David Lechner Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 8ebfe8abc3f4..fec728f5b3e9 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -114,7 +114,8 @@ static irqreturn_t ad7606_trigger_handler(int irq, void *p) return IRQ_HANDLED; } -static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch) +static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch, + int *val) { struct ad7606_state *st = iio_priv(indio_dev); int ret; @@ -129,7 +130,7 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch) ret = ad7606_read_samples(st); if (ret == 0) - ret = st->data[ch]; + *val = sign_extend32(st->data[ch], 15); error_ret: gpiod_set_value(st->gpio_convst, 0); @@ -149,10 +150,9 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, switch (m) { case IIO_CHAN_INFO_RAW: iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret = ad7606_scan_direct(indio_dev, chan->address); + ret = ad7606_scan_direct(indio_dev, chan->address, val); if (ret < 0) return ret; - *val = (short) ret; return IIO_VAL_INT; } unreachable(); From patchwork Sat Sep 7 06:50:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 13795097 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F48814B94F for ; Sat, 7 Sep 2024 06:50:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691859; cv=none; b=Q75xxK1J6UHTrIedVGbWEaRa5Tz+jCj6gH14rE/y6finpdzUjKeD0671qv7nkrmmkVOLzMPTWZkJjc/H1ilVTN36UOeuWcdwwNXw1YHI1cUstqLaJg4fnfVGyVH7Duj46TtAq4IwtpGdogDTsgvUWtq9oK8B6CDO3P7XiJbrpZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691859; c=relaxed/simple; bh=upn2kbj2uSiQQ0mLh63/viN7iiey7yEDDGSNyPdk+iA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lbI/s5iWutrGZJBd8Y4ocGWP2MERcfWcyvoUyic3HtRulBWS9yk1U6GRYSGccwYQMkZpKtUwRQWD3n2mBrTPQT/kH5dmo8H5NyvX3lohhLi3VBGomZ/G+ioN/a5z9AclH/yA2qU4HGSAX+prw7buUEYK2lm7GaqAmVgIOfzW+TU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=EeRVgSeC; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="EeRVgSeC" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a86883231b4so62759666b.3 for ; Fri, 06 Sep 2024 23:50:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725691855; x=1726296655; darn=vger.kernel.org; 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=zk+bvTvfw/Rnr5cxB/BtoOVKrkN1O+3CMaqpAJ2Bql0=; b=EeRVgSeC6rjCGfVbzc6kmT3i9+TfFJuBszDX+3NyjsAbvwiKctLiWNHs+4TyS7VdTQ KtZf28jczsKG0FQc0PtTS0+vbleY4x1Zi0cOs1ckjivimk4/aLFwgsLCje6VaUnwLQTX zk5D4nNVuCB1Pxehg6Q0oB+zcM89nCS9yml4AJpbc5g9va5dvRxkOOadhBAlBL/7LMPb fAwniAbMiEjlwhURB2hjnWItbH+JKgo3zN63NxgDvICq2dARiCWEr88dlZ9BMyIRvxln xkVmbt9PYAY1gWWoTzYsrCf2aYlqCUjZ+fAgvuvTYNhxycZ4BObwo3eGJZnuS3rwg8dd MChQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725691855; x=1726296655; 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=zk+bvTvfw/Rnr5cxB/BtoOVKrkN1O+3CMaqpAJ2Bql0=; b=ep49AazdcjS6V5h6MWn6Ei+zOqI1iGJKkkOHl3/iXIOb/1NYrIAZXjv8q8dYfqA25E DwdoDHoVvSggmjSgt89ZbYXPOuZjcw9wCOC2CT+MfQynVAOW8/NP0tEVVAmdEiz+kiUG AerXdmHr8EjAOi7r5b3lEjtpV2kAt6diTtaGoUvpkdAy3yosAQIBVkVlt+CxvzmkVkUw Ok7z4rAF7MNdr99xNbIkmCeWYQhc6WnZ+GucCeIvUxXbB+4oWchm+CmUKnKJDdb3Sv2X zpSLWV0fQm++tkOZbLVzzslgWMiO8G91AEIMBVzNFy+SbBPkXu3wVRna8HEHdtiEsDq7 ECxw== X-Gm-Message-State: AOJu0Yzsni3cBzogdxbrDDRl0HjvWnWXfxDHTP4x3fcdwHmUvsxUmkuo fqMDinHvVTw3eHLMTL0xIvJWnSE9RnUsytuyrUliT/EycUtv6ulal4eYGLuhwph5COL0DwGLDwh sDB0= X-Google-Smtp-Source: AGHT+IHFHrh/1Zp+2+jx9LNCihhk323IDLbTIeCG9ZU0+CmNaKrot4eRu64BfYQoQiyCyAXrmfauRw== X-Received: by 2002:a17:906:da85:b0:a7a:9f0f:ab2c with SMTP id a640c23a62f3a-a8a8866090amr444973666b.29.1725691855268; Fri, 06 Sep 2024 23:50:55 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25835a76sm36539266b.39.2024.09.06.23.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 23:50:54 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, Alexandru Ardelean Subject: [PATCH v5 4/9] iio: adc: ad7606: split a 'ad7606_sw_mode_setup()' from probe Date: Sat, 7 Sep 2024 09:50:37 +0300 Message-ID: <20240907065043.771364-5-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240907065043.771364-1-aardelean@baylibre.com> References: <20240907065043.771364-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This change moves the logic for setting up SW mode (during probe) into it's own function. With the addition of some newer parts, the SW-mode part can get a little more complicated. So it's a bit better to have a separate function for this. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 43 ++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index fec728f5b3e9..5d92463abf8c 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -521,6 +521,29 @@ static const struct iio_trigger_ops ad7606_trigger_ops = { .validate_device = iio_trigger_validate_own_device, }; +static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) +{ + struct ad7606_state *st = iio_priv(indio_dev); + + if (!st->bops->sw_mode_config) + return 0; + + st->sw_mode_en = device_property_present(st->dev, "adi,sw-mode"); + if (!st->sw_mode_en) + return 0; + + indio_dev->info = &ad7606_info_os_range_and_debug; + + /* Scale of 0.076293 is only available in sw mode */ + st->scale_avail = ad7616_sw_scale_avail; + st->num_scales = ARRAY_SIZE(ad7616_sw_scale_avail); + + /* After reset, in software mode, ±10 V is set by default */ + memset32(st->range, 2, ARRAY_SIZE(st->range)); + + return st->bops->sw_mode_config(indio_dev); +} + int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, const char *name, unsigned int id, const struct ad7606_bus_ops *bops) @@ -593,23 +616,9 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, st->write_scale = ad7606_write_scale_hw; st->write_os = ad7606_write_os_hw; - if (st->bops->sw_mode_config) - st->sw_mode_en = device_property_present(st->dev, - "adi,sw-mode"); - - if (st->sw_mode_en) { - /* Scale of 0.076293 is only available in sw mode */ - st->scale_avail = ad7616_sw_scale_avail; - st->num_scales = ARRAY_SIZE(ad7616_sw_scale_avail); - - /* After reset, in software mode, ±10 V is set by default */ - memset32(st->range, 2, ARRAY_SIZE(st->range)); - indio_dev->info = &ad7606_info_os_range_and_debug; - - ret = st->bops->sw_mode_config(indio_dev); - if (ret < 0) - return ret; - } + ret = ad7606_sw_mode_setup(indio_dev); + if (ret) + return ret; st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, From patchwork Sat Sep 7 06:50:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 13795098 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78278157493 for ; Sat, 7 Sep 2024 06:51:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691862; cv=none; b=HYenLA9gyQuxBb5rlKJ49yBsz1mRCFU8tYGzWKp1Ww5T21hzRYvIqXZa2GxdPVNVa+X3n/McHlADZE79JwFwqlVvaQyngQwMhKbSIHi2FRPiCXVPe4yaAzcRyBu06uQHlb+O2f1L+9j0QiZtrtXESNlO0eq2x7BxouPGTl8Df1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691862; c=relaxed/simple; bh=30ItHTLovVM1Ek7VqZlwyvYFIdtpxGD4hrvXB2LDUIA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZSgIB0dgrOfO/Uqf4m/kZ8Bhm0eBPCu2v/2xErRV8Y88uOd/N2Kvny5Xuwjc/IioPbs6kMDEp7E6nNNAxETb6aXo6+qt8KKXK965K20qZff6CDS8CCOcwROG1PDd7nctCwuGUeLiySsm8vkKjWjFomJGKIwIFBS6poMmg7cifPk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=21YvUZCY; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="21YvUZCY" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-5333b2fbedaso4800862e87.0 for ; Fri, 06 Sep 2024 23:51:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725691858; x=1726296658; darn=vger.kernel.org; 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=q+L8RwiILhPiWz6XMzynW5ib21/NG2r40upss5Y2x7I=; b=21YvUZCYEgnkjSg/gfoA+YXJp3cLC7pekGwYCqW7jUtqLs1FsRpoaKeSihOKGRIwfv 7YY/nqwR/xN383XP5CiU6LCTsV9cn13r994Meg9bTUQtgpcavVs8tjI/KQI8ndT9SIFt lP9yqI0/bdSwmdvOdXYOO1efcIMHTTIsYyfcUdxY9KNjSINfoSLrwoVQdDqBlQkNng0z m0KgO5I5/6KjQXMheNVANnUQLILFz6uEFioEhF0DsV/9amw0pCfwDsHmHNBjBKzrnyYc ksenJln9Tnu89py+gcGiKEIkvtUytnZKfZKpe2PdAGe2Xcj3qg9ps1+8rXFzgzxzo0Q3 Z/hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725691858; x=1726296658; 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=q+L8RwiILhPiWz6XMzynW5ib21/NG2r40upss5Y2x7I=; b=IiMA65xICoPlxMI5Hr4wkihlxB5BcF1aNx7Gg2BNzr1DSzEoe8T7y4wMxgiyr6fVD9 EgMs6ooEvWrxBFKWth7jyl0hs+MYwT1MulEusabFZMDQkBvZ4znwtoBI+NunLGyPCYIs X7SvAVmdpdenZjOsoVVuoNfv+CcUZXA47xN51rpy7j51g8oWdtDc0dLiMuSTFCO1It9R Tv/gXvWHNsPTK0FByiqmZW4f0hMBrDaLHSxFBX40nD771q5rtbOqgnQAAAswwqcArFDk MnjtWFD1iOH3mNqjTc9a23d8qXj0ET5/hadP9BuGTEy1Lp87PIOu6pFsVluCKu05PibR 7wtQ== X-Gm-Message-State: AOJu0Yw6sxeNp0XDEiXgqvFPzfEIS3azlOtMWFFsBPx/NrVTB72jFRdQ JXlrXx/31qYwkGVmSZPmmxkIy3vXk4s8J9rr6Ivc3r7QUykYw364Bnf+lIEpqDZn01l4XBSI/r1 Bw6w= X-Google-Smtp-Source: AGHT+IGb8Ow+LDuZDRfrlDyrYU9D8XeQFB7ZRUiyYK+1f6RQHb70HpOV/0B8HkAhPL3xXic8uNbqlw== X-Received: by 2002:a05:6512:3088:b0:535:6892:3be6 with SMTP id 2adb3069b0e04-5365880bf79mr2638100e87.54.1725691857112; Fri, 06 Sep 2024 23:50:57 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25835a76sm36539266b.39.2024.09.06.23.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 23:50:56 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, Alexandru Ardelean Subject: [PATCH v5 5/9] iio: adc: ad7606: wrap channel ranges & scales into struct Date: Sat, 7 Sep 2024 09:50:38 +0300 Message-ID: <20240907065043.771364-6-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240907065043.771364-1-aardelean@baylibre.com> References: <20240907065043.771364-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With the addition of AD7606C-16,18 which have differential & bipolar channels (and ranges), which can vary from channel to channel, we'll need to keep more information about each channel range. To do that, we'll add a 'struct ad7606_chan_scale' type to hold just configuration for each channel. This includes the scales per channel (which can be different with AD7606C-16,18), as well as the range for each channel. This driver was already keeping the range value for each channel before, and since this is couple with the scales, it also makes sense to put them in the same struct. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 37 +++++++++++++++++++++++++------------ drivers/iio/adc/ad7606.h | 22 ++++++++++++++++------ 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 5d92463abf8c..39ef72a8acd2 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -146,6 +146,7 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, { int ret, ch = 0; struct ad7606_state *st = iio_priv(indio_dev); + struct ad7606_chan_scale *cs; switch (m) { case IIO_CHAN_INFO_RAW: @@ -159,8 +160,9 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_SCALE: if (st->sw_mode_en) ch = chan->address; + cs = &st->chan_scales[ch]; *val = 0; - *val2 = st->scale_avail[st->range[ch]]; + *val2 = cs->scale_avail[cs->range]; return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: *val = st->oversampling; @@ -190,8 +192,9 @@ static ssize_t in_voltage_scale_available_show(struct device *dev, { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ad7606_state *st = iio_priv(indio_dev); + struct ad7606_chan_scale *cs = &st->chan_scales[0]; - return ad7606_show_avail(buf, st->scale_avail, st->num_scales, true); + return ad7606_show_avail(buf, cs->scale_avail, cs->num_scales, true); } static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0); @@ -229,19 +232,21 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, long mask) { struct ad7606_state *st = iio_priv(indio_dev); + struct ad7606_chan_scale *cs; int i, ret, ch = 0; guard(mutex)(&st->lock); switch (mask) { case IIO_CHAN_INFO_SCALE: - i = find_closest(val2, st->scale_avail, st->num_scales); if (st->sw_mode_en) ch = chan->address; + cs = &st->chan_scales[ch]; + i = find_closest(val2, cs->scale_avail, cs->num_scales); ret = st->write_scale(indio_dev, ch, i); if (ret < 0) return ret; - st->range[ch] = i; + cs->range = i; return 0; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: @@ -523,7 +528,9 @@ static const struct iio_trigger_ops ad7606_trigger_ops = { static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) { + unsigned int num_channels = indio_dev->num_channels - 1; struct ad7606_state *st = iio_priv(indio_dev); + int ch; if (!st->bops->sw_mode_config) return 0; @@ -535,11 +542,14 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) indio_dev->info = &ad7606_info_os_range_and_debug; /* Scale of 0.076293 is only available in sw mode */ - st->scale_avail = ad7616_sw_scale_avail; - st->num_scales = ARRAY_SIZE(ad7616_sw_scale_avail); - /* After reset, in software mode, ±10 V is set by default */ - memset32(st->range, 2, ARRAY_SIZE(st->range)); + for (ch = 0; ch < num_channels; ch++) { + struct ad7606_chan_scale *cs = &st->chan_scales[ch]; + + cs->scale_avail = ad7616_sw_scale_avail; + cs->num_scales = ARRAY_SIZE(ad7616_sw_scale_avail); + cs->range = 2; + } return st->bops->sw_mode_config(indio_dev); } @@ -548,6 +558,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, const char *name, unsigned int id, const struct ad7606_bus_ops *bops) { + struct ad7606_chan_scale *cs; struct ad7606_state *st; int ret; struct iio_dev *indio_dev; @@ -564,10 +575,12 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, st->bops = bops; st->base_address = base_address; /* tied to logic low, analog input range is +/- 5V */ - st->range[0] = 0; st->oversampling = 1; - st->scale_avail = ad7606_scale_avail; - st->num_scales = ARRAY_SIZE(ad7606_scale_avail); + + cs = &st->chan_scales[0]; + cs->range = 0; + cs->scale_avail = ad7606_scale_avail; + cs->num_scales = ARRAY_SIZE(ad7606_scale_avail); ret = devm_regulator_get_enable(dev, "avcc"); if (ret) @@ -674,7 +687,7 @@ static int ad7606_resume(struct device *dev) struct ad7606_state *st = iio_priv(indio_dev); if (st->gpio_standby) { - gpiod_set_value(st->gpio_range, st->range[0]); + gpiod_set_value(st->gpio_range, st->chan_scales[0].range); gpiod_set_value(st->gpio_standby, 1); ad7606_reset(st); } diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 204a343067e5..635407c2acc0 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -8,6 +8,8 @@ #ifndef IIO_ADC_AD7606_H_ #define IIO_ADC_AD7606_H_ +#define AD760X_MAX_CHANNELS 16 + #define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all, bits) { \ .type = IIO_VOLTAGE, \ .indexed = 1, \ @@ -60,17 +62,27 @@ struct ad7606_chip_info { unsigned long init_delay_ms; }; +/** + * struct ad7606_chan_scale - channel scale configuration + * @scale_avail pointer to the array which stores the available scales + * @num_scales number of elements stored in the scale_avail array + * @range voltage range selection, selects which scale to apply + */ +struct ad7606_chan_scale { + const unsigned int *scale_avail; + unsigned int num_scales; + unsigned int range; +}; + /** * struct ad7606_state - driver instance specific data * @dev pointer to kernel device * @chip_info entry in the table of chips that describes this device * @bops bus operations (SPI or parallel) - * @range voltage range selection, selects which scale to apply + * @chan_scales scale configuration for channels * @oversampling oversampling selection * @base_address address from where to read data in parallel operation * @sw_mode_en software mode enabled - * @scale_avail pointer to the array which stores the available scales - * @num_scales number of elements stored in the scale_avail array * @oversampling_avail pointer to the array which stores the available * oversampling ratios. * @num_os_ratios number of elements stored in oversampling_avail array @@ -94,12 +106,10 @@ struct ad7606_state { struct device *dev; const struct ad7606_chip_info *chip_info; const struct ad7606_bus_ops *bops; - unsigned int range[16]; + struct ad7606_chan_scale chan_scales[AD760X_MAX_CHANNELS]; unsigned int oversampling; void __iomem *base_address; bool sw_mode_en; - const unsigned int *scale_avail; - unsigned int num_scales; const unsigned int *oversampling_avail; unsigned int num_os_ratios; int (*write_scale)(struct iio_dev *indio_dev, int ch, int val); From patchwork Sat Sep 7 06:50:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 13795099 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C30614884C for ; Sat, 7 Sep 2024 06:51:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691863; cv=none; b=ra63czfs0eW+nh8xVBVCtbXkEl+qBYLgBupmzO3Wy6Vlo0eIbjOTLqU+i9sxiSHAp5FM1vCok2BdWYJMp+DhAHGG6mK6Wrh7u9ptr5SQdayzWIlZXvsBIGJ0hVZgMdAuZtA0l98ixXZZ8W1t4lQJcs85wkPVasWHkYR4igBWh1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691863; c=relaxed/simple; bh=UrQVZr2Ut7tXRzDLHI6k+MfrW96ZgN+yhIcNORux8Lc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XKvcDEZVlkGaTNlUfsYvGZTeMaKEjAkd+UoHNmmhh2vMsOUeI3KF4OY/l5Gc1cW/TNSRq0Mqk62pvuZenaONCBHz+E+T/PbHq8671CT7DLj8IY9CoA5zVQG9BLUlOlY7hgFW32NmJE3agT/1okTxVu/pzFrjR+DJGfSRmyWatug= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=tl+AxXpz; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="tl+AxXpz" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-5356aa9a0afso4634881e87.2 for ; Fri, 06 Sep 2024 23:51:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725691859; x=1726296659; darn=vger.kernel.org; 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=iMcKOFwkI5rA4jvBzx/C0roj6f73aPe0+suqT1cOIBQ=; b=tl+AxXpzQ2NKZcFeWUvLxYl9tgyQXqjMlMichhsSjBQg6YzgDW3oxMJfEqJHJEK5jV VZhURuRMwWXdh3XzSRAI0dtv8liS9k6hjqUkMB9YDKOVOPrWH+p8lE9WzrELtwhZ0POV f+c6PPONyHhZPnT9wU6SEhm1S+SoQCF6Z6SK+IXVF/4+teJGU+XAFAF+Bo4nTpRL63B0 Im5Vkkm5BQ8SRqoUc4GGvOrA4l3e6d/55m/gAMYwNP0rdS8CGkUm8+mNjGvWmyeLdv+F h93zmTsDiTVCnHAt5j+yIL+0d23dwYdGdnGqJIm+wEnOW1StXXMspFkzGuAgBlnXJWjN LNgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725691859; x=1726296659; 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=iMcKOFwkI5rA4jvBzx/C0roj6f73aPe0+suqT1cOIBQ=; b=uVQAZJFJCz5Sy+TeUuL9RY7d8NjwgXNIWI0ArbG746RAdxLsm3aTMt0OC3Y6PwL58D i6ddyojU4WbSYCdp3CEC+jGD79PeHAtJCS3yMs5wuVgdRl3HwgxURgUimQC0t6wqnK+q DNNNqLExdXTdCAd7W1YyrnVYtozZ+/Sd7jF2mpL1gBYWNNYxrHdDa4vhUepblAXChkVz tWrUSKB+boluDDrxnorcJSzlO3ugDPDO6tB9VOm1rJ8kiwv1gwRY2gCb0+Yp+XNQcCVq bEvO21nCRVhtRxd1efhkjI6krgMexb/NM6DWiPYb/d4J8F70E4sxYQ3Z3+jZYdiFqfdV YNOQ== X-Gm-Message-State: AOJu0YxEW3sTjUzzkVD8qD4deYvDhMETPrFRXDBqxOYSbjBDlXbWmTwK GSRqTaCdUoJQYri96LUXdR7boDwNrgJXU0O2Qg7XXcslAIhLppB0YNLq5M3JcZHOo3rVdT6PF+e xGkc= X-Google-Smtp-Source: AGHT+IEY5tdhxR8rZimtBcmWuZd+S2OGAxIzohVmU4P1L3XcjB9nocDnAsvxsLEZEqokzoNR2fysmA== X-Received: by 2002:a05:6512:308f:b0:52c:dcdc:f186 with SMTP id 2adb3069b0e04-536587b96b1mr3505379e87.27.1725691858839; Fri, 06 Sep 2024 23:50:58 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25835a76sm36539266b.39.2024.09.06.23.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 23:50:58 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, Alexandru Ardelean Subject: [PATCH v5 6/9] iio: adc: ad7606: rework available attributes for SW channels Date: Sat, 7 Sep 2024 09:50:39 +0300 Message-ID: <20240907065043.771364-7-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240907065043.771364-1-aardelean@baylibre.com> References: <20240907065043.771364-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For SW mode, the oversampling and scales attributes are always present. So, they can be implemented via a 'read_avail' hook in iio_info. For HW mode, it's a bit tricky, as these attributes get assigned based on GPIO definitions. So, for SW mode, we define a separate AD7606_SW_CHANNEL() macro, and use that for the SW channels. And 'ad7606_info_os_range_and_debug' can be renamed to 'ad7606_info_sw_mode' as it is only used for SW mode. For the 'read_avail' hook, we'll need to allocate the SW scales, so that they are just returned userspace without any extra processing. The allocation will happen when then ad7606_state struct is allocated. The oversampling available parameters don't need any extra processing; they can just be passed back to userspace (as they are). Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 63 ++++++++++++++++++++++++++++++++++++---- drivers/iio/adc/ad7606.h | 31 +++++++++++++++++--- 2 files changed, 85 insertions(+), 9 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 39ef72a8acd2..364f16fb96bf 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -483,6 +483,37 @@ static int ad7606_buffer_predisable(struct iio_dev *indio_dev) return 0; } +static int ad7606_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long info) +{ + struct ad7606_state *st = iio_priv(indio_dev); + struct ad7606_chan_scale *cs; + unsigned int ch = 0; + + switch (info) { + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + *vals = st->oversampling_avail; + *length = st->num_os_ratios; + *type = IIO_VAL_INT; + + return IIO_AVAIL_LIST; + + case IIO_CHAN_INFO_SCALE: + if (st->sw_mode_en) + ch = chan->address; + + cs = &st->chan_scales[ch]; + *vals = cs->scale_avail_show; + *length = cs->num_scales * 2; + *type = IIO_VAL_INT_PLUS_MICRO; + + return IIO_AVAIL_LIST; + } + return -EINVAL; +} + static const struct iio_buffer_setup_ops ad7606_buffer_ops = { .postenable = &ad7606_buffer_postenable, .predisable = &ad7606_buffer_predisable, @@ -500,11 +531,11 @@ static const struct iio_info ad7606_info_os_and_range = { .validate_trigger = &ad7606_validate_trigger, }; -static const struct iio_info ad7606_info_os_range_and_debug = { +static const struct iio_info ad7606_info_sw_mode = { .read_raw = &ad7606_read_raw, .write_raw = &ad7606_write_raw, + .read_avail = &ad7606_read_avail, .debugfs_reg_access = &ad7606_reg_access, - .attrs = &ad7606_attribute_group_os_and_range, .validate_trigger = &ad7606_validate_trigger, }; @@ -530,7 +561,7 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) { unsigned int num_channels = indio_dev->num_channels - 1; struct ad7606_state *st = iio_priv(indio_dev); - int ch; + int ret, ch; if (!st->bops->sw_mode_config) return 0; @@ -539,7 +570,7 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) if (!st->sw_mode_en) return 0; - indio_dev->info = &ad7606_info_os_range_and_debug; + indio_dev->info = &ad7606_info_sw_mode; /* Scale of 0.076293 is only available in sw mode */ /* After reset, in software mode, ±10 V is set by default */ @@ -551,7 +582,29 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) cs->range = 2; } - return st->bops->sw_mode_config(indio_dev); + ret = st->bops->sw_mode_config(indio_dev); + if (ret) + return ret; + + for (ch = 0; ch < num_channels; ch++) { + struct ad7606_chan_scale *cs = &st->chan_scales[ch]; + int i; + + cs = &st->chan_scales[ch]; + + if (cs->num_scales * 2 > AD760X_MAX_SCALE_SHOW) { + dev_err(st->dev, "Driver error: scale range too big"); + return -ERANGE; + } + + /* Generate a scale_avail list for showing to userspace */ + for (i = 0; i < cs->num_scales; i++) { + cs->scale_avail_show[i * 2] = 0; + cs->scale_avail_show[i * 2 + 1] = cs->scale_avail[i]; + } + } + + return 0; } int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 635407c2acc0..fa175cff256c 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -27,6 +27,29 @@ }, \ } +#define AD7606_SW_CHANNEL(num, bits) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = num, \ + .address = num, \ + .info_mask_separate = \ + BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_separate_available = \ + BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_all = \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .info_mask_shared_by_all_available = \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .scan_index = num, \ + .scan_type = { \ + .sign = 's', \ + .realbits = (bits), \ + .storagebits = (bits) > 16 ? 32 : 16, \ + .endianness = IIO_CPU, \ + }, \ +} + #define AD7605_CHANNEL(num) \ AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \ BIT(IIO_CHAN_INFO_SCALE), 0, 16) @@ -36,10 +59,6 @@ BIT(IIO_CHAN_INFO_SCALE), \ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), bits) -#define AD7606_SW_CHANNEL(num, bits) \ - AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),\ - 0, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), bits) - #define AD7616_CHANNEL(num) AD7606_SW_CHANNEL(num, 16) /** @@ -65,11 +84,15 @@ struct ad7606_chip_info { /** * struct ad7606_chan_scale - channel scale configuration * @scale_avail pointer to the array which stores the available scales + * @scale_avail_show a duplicate of 'scale_avail' which is readily formatted + * such that it can be read via the 'read_avail' hook * @num_scales number of elements stored in the scale_avail array * @range voltage range selection, selects which scale to apply */ struct ad7606_chan_scale { +#define AD760X_MAX_SCALE_SHOW (AD760X_MAX_CHANNELS * 2) const unsigned int *scale_avail; + int scale_avail_show[AD760X_MAX_SCALE_SHOW]; unsigned int num_scales; unsigned int range; }; From patchwork Sat Sep 7 06:50:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 13795100 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBCB415886D for ; Sat, 7 Sep 2024 06:51:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691864; cv=none; b=omt9jOdoAIyl5mGwuGfL6FQwe9BbzBhYEKYM5XBm051Y6pKotQLXyibRzjXIyzZJwlGSertcBCF64WxhBvyDqNPFoS2wtSjcVcYwMbltU0z4hoN81OL1p/ORegm/aBIh42S+UmGyarOszG2NrG6MNbFX1299knJgCkY6e5REwzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691864; c=relaxed/simple; bh=/ovmFlVD/7j+ipJY0VPXyzdNP1zhe/wqKiyGk4ajqgM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VZL7PX/ybGnY4F3XuRh0W+pKnkpWor1bSRXSoqglUd5XskQKcOT0oNWbPE7esZ8VJpmSQ2ZpzUnpdJ7fXhIsPnvF52I/YGfvDcTZE8Q+6MvzW3CD31tAjwuTeZ/3c2Ef9tSwUtYa5wA5El61LMU4i4xSBmQ8LMjTHWsNxCam+FM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=I6b01P3v; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="I6b01P3v" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5c245c62362so3539407a12.0 for ; Fri, 06 Sep 2024 23:51:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725691861; x=1726296661; darn=vger.kernel.org; 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=g46xgvcRuzluvD9uFfVgOC6tB6SvIHIhrOwQLDjP3Ko=; b=I6b01P3vzUUiezNXDvPSKQHqpy6Vt8MZI65nq7QSzu1c95LiQQ1074KyboKxOfe3d4 ZRSc6YubFTd62WL0eS4ADryiILiWz+MxZlgDwzbDcNOWmkaDmr0xE7xqH5ZnrEgZV1OZ LT9LcG+ugggdjMR9cUWcl4U3dAbD3Thd/TU6bI3oRPR84MY/VMGRZP9MP5Ft3WcX3bHV oMgMSAOh10kynlbsF6uCVwcL3DC8X86OrPjezva++ib0Yo2501klhxVAljzwx2+oUel/ 0XKdjG7xgzBNlLvhaPFdNyzzyMJe70eIUM+PVvRAAGTXfcgXWqSKUs3S5hEPgsGzyy65 I4Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725691861; x=1726296661; 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=g46xgvcRuzluvD9uFfVgOC6tB6SvIHIhrOwQLDjP3Ko=; b=bEitRr4FqSIDsc3Jzz3CRvubwQNnXPmyBdrM0XAEySwYVaXEFwxWuoIAT+qlEJUKFD 9u+qUXNkYDazu5OT0TDZKwt0keOFHIDwNEGuiydE0TErbW2z7oYWRIbkh9dT1HgFYgKG AQFivLxrprbuYQj51hw7oQHI8iZeF/o1oN5zQYJinXpSlYz8efIbAyfbSvo20wMXSQ3W tBq4D1iuxtyp6chdiHMPNV3vIIIER99aYKAgXIFmE/CnxzhaJA2K9T4HxqcFxwFOT0tu hM/s+M+ihOkV10KFuR8E1YTgdHNz1IRIa3uujHI2dgfOcmJGQ1n/g3tV5j16G9mmgMTF EuXQ== X-Gm-Message-State: AOJu0Ywjc4uE4Ds28eH7I74F78jMsD88J06mM6j+7nh4TIaUNDEnx0jr PdoFJtqIPXF0QkHD8ZsspbZ/Fdsgs8u6jhpn4WenT19AOhkIGedfZmuHeR0CmeQlvP3F9hjoF8b naus= X-Google-Smtp-Source: AGHT+IF/D/Hkio2fyON8uWC4iTvVwDxSzhUtXtMuIcBtWjFH5BJ3N39nUeLSDxpP7WsrXEs9UeSfWA== X-Received: by 2002:a17:907:3d8b:b0:a7a:ba59:3164 with SMTP id a640c23a62f3a-a8a888e9c21mr347077966b.53.1725691860868; Fri, 06 Sep 2024 23:51:00 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25835a76sm36539266b.39.2024.09.06.23.50.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 23:51:00 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, Alexandru Ardelean , Krzysztof Kozlowski Subject: [PATCH v5 7/9] dt-bindings: iio: adc: document diff-channels corner case for some ADCs Date: Sat, 7 Sep 2024 09:50:40 +0300 Message-ID: <20240907065043.771364-8-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240907065043.771364-1-aardelean@baylibre.com> References: <20240907065043.771364-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some ADCs have channels with negative and positive inputs, which can be used to measure differential voltage levels. These inputs/pins are dedicated (to the given channel) and cannot be muxed as with other ADCs. For those types of setups, the 'diff-channels' property can be specified to be used with the channel number (or reg property) for both negative and positive inputs/pins. Reviewed-by: Krzysztof Kozlowski Signed-off-by: Alexandru Ardelean --- Documentation/devicetree/bindings/iio/adc/adc.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/adc.yaml b/Documentation/devicetree/bindings/iio/adc/adc.yaml index 8e7835cf36fd..b9bc02b5b07a 100644 --- a/Documentation/devicetree/bindings/iio/adc/adc.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adc.yaml @@ -37,6 +37,10 @@ properties: to both the positive and negative inputs of a differential ADC. The first value specifies the positive input pin, the second specifies the negative input pin. + There are also some ADCs, where the differential channel has dedicated + positive and negative inputs which can be used to measure differential + voltage levels. For those setups, this property can be configured with + the 'reg' property for both inputs (i.e. diff-channels = ). single-channel: $ref: /schemas/types.yaml#/definitions/uint32 From patchwork Sat Sep 7 06:50:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 13795101 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DD1A15A864 for ; Sat, 7 Sep 2024 06:51:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691867; cv=none; b=J+r1pFJchrSNMAbOrcmy2MOftubgn8zKja8JS10aejMp8/wwMQ91SDmB2KJEvbtjIzXztz/DA7Jt1rujh+tC/Iswp4jERPNJNb/IneteFo8ZeJcfCXpqcyiJfLZeJtHZzgO9LKZosMB3UdNfRb6hq052njsAq7mAnDzj0bng+fs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691867; c=relaxed/simple; bh=WtTqoqsoPDCsAqupR0u+y5bxkErf4GAtT/qIF8GJb84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Be1VrQ1SfsHjy2Utjl71yuiyNZNf+BHL0erUBYPkwmhIv7Gjmf/ug5adFyJfIsoPnt+nXe2hHEI2WJc0WG7IhHPK8nH+9ZE6rS7uTqDc9+T6OfajS6HtbPJRsUgwvEHm+0Ws3WPRyv487jxk00FdWCLTr0vWdTgD3i86rCvYWto= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=RzLECZQD; arc=none smtp.client-ip=209.85.208.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="RzLECZQD" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2f75428b9f8so393261fa.3 for ; Fri, 06 Sep 2024 23:51:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725691863; x=1726296663; darn=vger.kernel.org; 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=HT8k5fM4ZWLcTvzIYnUe0nI5L7nA0F+Tipopd6qH/00=; b=RzLECZQDGskcEj97s1fp7YGzSXQcUVdfZvHkt3lLTSrnVkgDNNsEvwl0OhMoc5NTGt iqhEetdWWIRK7h2EmWY5bGgfZcNdgSPCuIdWq2f7VaI7N2qjwl8l6KZkvnKQ0Tg/m2Np Onf3Z9+zMXXJx7wLl6AjUFa80+uoV13CuCCz1LcWoqS84GYUJzEf6mntBskHOfnbp0i+ EH35fegdFFoXrMtkr7MTF/TTHwa/JxX3pY1Lce93j7EXFCD4tjZK/A0UiGivgx/JnQKs p6Oee7/HJFZBY8UhEAeNPBX6lQwVrRlOYEsrRxZAgNZI2AwrhhufRmj4wkBa8N4kTQdK m7UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725691863; x=1726296663; 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=HT8k5fM4ZWLcTvzIYnUe0nI5L7nA0F+Tipopd6qH/00=; b=mHGVj/2b2nj+7UmRonuNpr0846bbKgn8NS6MrttHj63LZ9iJw05GM90aif90pS+B0a mN08TghVVUK+eVW62f1OkPLpkmMB3oEt2YFe4p9bycbO6wd3d9J+eSN38UOZkHvLOA6m XbHmAlp+2rzyNlN1QQfoijrIC1VhijluHwtglFDU3GdVu5JO58a/aITaxOxeXLxzSIRS lXdGP9CF+ib49SU3cIFLroWv7vEE1rW8F9g/yA7xkxdNG+E4BmVAREB5bW+96oweks39 3VrOsTBMteB51a1acd6MTspkycsQ3hZgt1AS1RgaruaqNXCVxIT2nZu3qp5K2rHUQK2l epXQ== X-Gm-Message-State: AOJu0YxvATFlg4Wudi0hfbRQXFLbaTXiLr/8kknmevTXYZAlhi+45NkV /pBKGvhifx0stbr+aYAz6WqzxKqaaaL4rqdIEBbhIt+79mDhwDDPcSP/UDc55hdt0KFjACvLQRD dFAA= X-Google-Smtp-Source: AGHT+IEci4IEtTe0vISInRqxpOJtLwF9ALHuxFoVHVuWCccPUOKu/XXZes/b6LFy3N1NkxKZv9osKg== X-Received: by 2002:a05:651c:1548:b0:2f7:5049:160 with SMTP id 38308e7fff4ca-2f75a98689bmr9815101fa.13.1725691862729; Fri, 06 Sep 2024 23:51:02 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25835a76sm36539266b.39.2024.09.06.23.51.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 23:51:02 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, Alexandru Ardelean , Krzysztof Kozlowski Subject: [PATCH v5 8/9] dt-bindings: iio: adc: add docs for AD7606C-{16,18} parts Date: Sat, 7 Sep 2024 09:50:41 +0300 Message-ID: <20240907065043.771364-9-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240907065043.771364-1-aardelean@baylibre.com> References: <20240907065043.771364-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The driver will support the AD7606C-16 and AD7606C-18. This change adds the compatible strings for these devices. The AD7606C-16,18 channels also support these (individually configurable) types of channels: - bipolar single-ended - unipolar single-ended - bipolar differential Reviewed-by: Krzysztof Kozlowski Signed-off-by: Alexandru Ardelean --- .../bindings/iio/adc/adi,ad7606.yaml | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml index 69408cae3db9..2329afc1d6f9 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml @@ -14,6 +14,8 @@ description: | https://www.analog.com/media/en/technical-documentation/data-sheets/AD7605-4.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606_7606-6_7606-4.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD7606B.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606c-16.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606c-18.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD7616.pdf properties: @@ -24,11 +26,19 @@ properties: - adi,ad7606-6 - adi,ad7606-8 # Referred to as AD7606 (without -8) in the datasheet - adi,ad7606b + - adi,ad7606c-16 + - adi,ad7606c-18 - adi,ad7616 reg: maxItems: 1 + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + spi-cpha: true spi-cpol: true @@ -114,6 +124,46 @@ properties: assumed that the pins are hardwired to VDD. type: boolean +patternProperties: + "^channel@[1-8]$": + type: object + $ref: adc.yaml + unevaluatedProperties: false + + properties: + reg: + description: + The channel number, as specified in the datasheet (from 1 to 8). + minimum: 1 + maximum: 8 + + diff-channels: + description: + Each channel can be configured as a differential bipolar channel. + The ADC uses the same positive and negative inputs for this. + This property must be specified as 'reg' (or the channel number) for + both positive and negative inputs (i.e. diff-channels = ). + items: + minimum: 1 + maximum: 8 + + bipolar: + description: + Each channel can be configured as a unipolar or bipolar single-ended. + When this property is not specified, it's unipolar, so the ADC will + have only the positive input wired. + For this ADC the 'diff-channels' & 'bipolar' properties are mutually + exclusive. + + required: + - reg + + oneOf: + - required: + - diff-channels + - required: + - bipolar + required: - compatible - reg @@ -170,6 +220,25 @@ allOf: adi,conversion-start-gpios: maxItems: 1 + - if: + not: + required: + - adi,sw-mode + then: + patternProperties: + "^channel@[1-8]$": false + + - if: + not: + properties: + compatible: + enum: + - adi,ad7606c-16 + - adi,ad7606c-18 + then: + patternProperties: + "^channel@[1-8]$": false + unevaluatedProperties: false examples: @@ -202,4 +271,52 @@ examples: standby-gpios = <&gpio 24 GPIO_ACTIVE_LOW>; }; }; + - | + #include + #include + spi { + #address-cells = <1>; + #size-cells = <0>; + + adc@0 { + compatible = "adi,ad7606c-18"; + reg = <0>; + + #address-cells = <1>; + #size-cells = <0>; + + spi-max-frequency = <1000000>; + spi-cpol; + spi-cpha; + + avcc-supply = <&adc_vref>; + vdrive-supply = <&vdd_supply>; + + interrupts = <25 IRQ_TYPE_EDGE_FALLING>; + interrupt-parent = <&gpio>; + + adi,conversion-start-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>; + reset-gpios = <&gpio 27 GPIO_ACTIVE_HIGH>; + adi,first-data-gpios = <&gpio 22 GPIO_ACTIVE_HIGH>; + standby-gpios = <&gpio 24 GPIO_ACTIVE_LOW>; + + adi,sw-mode; + + channel@1 { + reg = <1>; + diff-channels = <1 1>; + }; + + channel@3 { + reg = <3>; + bipolar; + }; + + channel@8 { + reg = <8>; + diff-channels = <8 8>; + }; + + }; + }; ... From patchwork Sat Sep 7 06:50:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 13795102 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0236B146592 for ; Sat, 7 Sep 2024 06:51:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691869; cv=none; b=KonW3Pu6tCusweHbjz4KCoMNFaOXiCM9mu/t4lzYYDfQPzUTIzfR7lrIrWomPaGe536Gm0PpVAeqUiXUzV1Ey+TAMIS/F/sLRrtYVNWEfhDGMuMqyFtUVZIxD04xEChwmW7x5azGjBi/zG5DxpQ1ewySnLEOhCpfJ3IocNHwVhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691869; c=relaxed/simple; bh=78CWyaDWtr0LL9iirJli/NGq8Ejww7g/x9SdIF3aCfg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XjvTq1rIbYD5w88MHIBlc0LfQascs9Fxn5JrvqwoavLwbXKZHZ9/V0jfnUQLr4n8YK92nLsBnfNHRVJvabuXbijGaQPMDWxMKhwisD1fAA8RCqgQFP7vPGb1276RnAjLJURbQDVw/LsNtZRlWD6VIEyxviPA5RSf31a2Z1qq26s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=els9QOCy; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="els9QOCy" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-5365a9574b6so1818633e87.1 for ; Fri, 06 Sep 2024 23:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725691865; x=1726296665; darn=vger.kernel.org; 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=x5oRUAic73WkO8NUPsYEANCF6hNp2zLwEU1uii99EH0=; b=els9QOCyCBdFRL3XBGVpLgIzdQLurhZyiJN4Jfjj0Jfd50myH6pZUDxJrgRrl0Y/Vi UhOJ89YWtzt58asgj0rRssnJmxcdM2T3O9GRCLFrEAbMLTpPMbwSBv2XQ3gOqci6ynvP JDWsIyav9bmys4o6EaguFvZpE4OGMS8z1QMQ1Kl7tqofw3ro5rNb+3PcuNvNSJ+6KjQI fqqExxKtpIT77Wnmvna+cPpMEjdcO1GoRwPTPUQ4yTWzj42wqmrTAwUd6xWgYbcbfpvs 6/qWvR0Y6SHZ/jz0OoyyWg4OJiK83Rh/+0aMtetesqDc3YpIgM2rYgJN1sQ+5O5J2F35 ZJDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725691865; x=1726296665; 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=x5oRUAic73WkO8NUPsYEANCF6hNp2zLwEU1uii99EH0=; b=uRcPjodmiTdaTtFTwBJmO6Y40Uoy0QeewzjENCU2mqZnTYQSCVFcuQ8syn9E9mfFRa k4xHI5dK2eHj4wRMjoGbUZdWe7FBIUfv/wDlaVHUfTreoIXQSuNvXgQHtN+/xV28M5rJ dh8di4H8TMmqCJbKpYyp75ltgjkYqfJKnIxRWXE5TXyB/a4pTT3JqpncchUi00EpqgiO 44Flhjoat60FV1n6G6/nTilSEHN6i9ghs4pSo69PMkHU7Q7xqYoaEnjoKlGhKy4QWQPJ Jdmeq2jf0OFyQ3ElGWfGhbmDPW3m+wzagb7b1wglvirs6Ejeu0MPB9g4VHcKayme6evH +YKg== X-Gm-Message-State: AOJu0YyyiSd0SdtT2ggNQhRSzhkW6NVpzM+VGjo5HlPG5bximCoCQXbH XMkFsHLV/72hsti44MydbuSzcZEdIB/S9erplGhWAW6kz/hI4wAj7rdHtuQDCzi2FFj40dX5pvP Qc5Q= X-Google-Smtp-Source: AGHT+IHZRjypMDJL3tyReij3VlDoFBX1WbHJnLfpW8s950aEpoMCJyHdyAF6xRUnVM5KoZnTmfKr2Q== X-Received: by 2002:a05:6512:2215:b0:530:ad8d:dcdb with SMTP id 2adb3069b0e04-536587ae7aemr4708314e87.19.1725691864517; Fri, 06 Sep 2024 23:51:04 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25835a76sm36539266b.39.2024.09.06.23.51.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 23:51:04 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, Alexandru Ardelean Subject: [PATCH v5 9/9] iio: adc: ad7606: add support for AD7606C-{16,18} parts Date: Sat, 7 Sep 2024 09:50:42 +0300 Message-ID: <20240907065043.771364-10-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240907065043.771364-1-aardelean@baylibre.com> References: <20240907065043.771364-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The AD7606C-16 and AD7606C-18 are pretty similar with the AD7606B. The main difference between AD7606C-16 & AD7606C-18 is the precision in bits (16 vs 18). Because of that, some scales need to be defined for the 18-bit variants, as they need to be computed against 2**18 (vs 2**16 for the 16 bit-variants). Because the AD7606C-16,18 also supports bipolar & differential channels, for SW-mode, the default range of 10 V or ±10V should be set at probe. On reset, the default range (in the registers) is set to value 0x3 which corresponds to '±10 V single-ended range', regardless of bipolar or differential configuration. Aside from the scale/ranges, the AD7606C-16 is similar to the AD7606B. The AD7606C-18 variant offers 18-bit precision. Because of this, the requirement to use this chip is that the SPI controller supports padding of 18-bit sequences to 32-bit arrays. Datasheet links: https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606c-16.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606c-18.pdf Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 237 ++++++++++++++++++++++++++++++++--- drivers/iio/adc/ad7606.h | 13 +- drivers/iio/adc/ad7606_spi.c | 55 ++++++++ 3 files changed, 284 insertions(+), 21 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 364f16fb96bf..67bac6c97fff 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -28,14 +28,44 @@ #include "ad7606.h" +typedef void (*ad7606c_chan_setup_cb_t)(struct ad7606_state *st, int ch, + bool bipolar, bool differential); + /* * Scales are computed as 5000/32768 and 10000/32768 respectively, * so that when applied to the raw values they provide mV values */ -static const unsigned int ad7606_scale_avail[2] = { +static const unsigned int ad7606_16bit_hw_scale_avail[2] = { 152588, 305176 }; +static const unsigned int ad7606_18bit_hw_scale_avail[2] = { + 38147, 76294 +}; + +static const unsigned int ad7606c_16_scale_single_ended_unipolar_avail[3] = { + 76294, 152588, 190735, +}; + +static const unsigned int ad7606c_16_scale_single_ended_bipolar_avail[5] = { + 76294, 152588, 190735, 305176, 381470 +}; + +static const unsigned int ad7606c_16_scale_differential_bipolar_avail[4] = { + 152588, 305176, 381470, 610352 +}; + +static const unsigned int ad7606c_18_scale_single_ended_unipolar_avail[3] = { + 19073, 38147, 47684 +}; + +static const unsigned int ad7606c_18_scale_single_ended_bipolar_avail[5] = { + 19073, 38147, 47684, 76294, 95367 +}; + +static const unsigned int ad7606c_18_scale_differential_bipolar_avail[4] = { + 38147, 76294, 95367, 152588 +}; static const unsigned int ad7616_sw_scale_avail[3] = { 76293, 152588, 305176 @@ -86,7 +116,7 @@ static int ad7606_reg_access(struct iio_dev *indio_dev, static int ad7606_read_samples(struct ad7606_state *st) { unsigned int num = st->chip_info->num_channels - 1; - u16 *data = st->data; + void *data = st->data.d16; return st->bops->read_block(st->dev, num, data); } @@ -104,7 +134,7 @@ static irqreturn_t ad7606_trigger_handler(int irq, void *p) if (ret) goto error_ret; - iio_push_to_buffers_with_timestamp(indio_dev, st->data, + iio_push_to_buffers_with_timestamp(indio_dev, st->data.d16, iio_get_time_ns(indio_dev)); error_ret: iio_trigger_notify_done(indio_dev->trig); @@ -118,6 +148,7 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch, int *val) { struct ad7606_state *st = iio_priv(indio_dev); + unsigned int storagebits = st->chip_info->channels[1].scan_type.storagebits; int ret; gpiod_set_value(st->gpio_convst, 1); @@ -129,8 +160,12 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch, } ret = ad7606_read_samples(st); - if (ret == 0) - *val = sign_extend32(st->data[ch], 15); + if (ret == 0) { + if (storagebits > 16) + *val = sign_extend32(st->data.d32[ch], 17); + else + *val = sign_extend32(st->data.d16[ch], 15); + } error_ret: gpiod_set_value(st->gpio_convst, 0); @@ -243,7 +278,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, ch = chan->address; cs = &st->chan_scales[ch]; i = find_closest(val2, cs->scale_avail, cs->num_scales); - ret = st->write_scale(indio_dev, ch, i); + ret = st->write_scale(indio_dev, ch, i + cs->reg_offset); if (ret < 0) return ret; cs->range = i; @@ -326,6 +361,18 @@ static const struct iio_chan_spec ad7606_channels_16bit[] = { AD7606_CHANNEL(7, 16), }; +static const struct iio_chan_spec ad7606_channels_18bit[] = { + IIO_CHAN_SOFT_TIMESTAMP(8), + AD7606_CHANNEL(0, 18), + AD7606_CHANNEL(1, 18), + AD7606_CHANNEL(2, 18), + AD7606_CHANNEL(3, 18), + AD7606_CHANNEL(4, 18), + AD7606_CHANNEL(5, 18), + AD7606_CHANNEL(6, 18), + AD7606_CHANNEL(7, 18), +}; + /* * The current assumption that this driver makes for AD7616, is that it's * working in Hardware Mode with Serial, Burst and Sequencer modes activated. @@ -386,6 +433,18 @@ static const struct ad7606_chip_info ad7606_chip_info_tbl[] = { .oversampling_avail = ad7606_oversampling_avail, .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), }, + [ID_AD7606C_16] = { + .channels = ad7606_channels_16bit, + .num_channels = 9, + .oversampling_avail = ad7606_oversampling_avail, + .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), + }, + [ID_AD7606C_18] = { + .channels = ad7606_channels_18bit, + .num_channels = 9, + .oversampling_avail = ad7606_oversampling_avail, + .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), + }, [ID_AD7616] = { .channels = ad7616_channels, .num_channels = 17, @@ -557,7 +616,127 @@ static const struct iio_trigger_ops ad7606_trigger_ops = { .validate_device = iio_trigger_validate_own_device, }; -static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) +static void ad7606c_18_chan_setup(struct ad7606_state *st, int ch, + bool bipolar, bool differential) +{ + struct ad7606_chan_scale *cs = &st->chan_scales[ch]; + + if (differential) { + cs->scale_avail = + ad7606c_18_scale_differential_bipolar_avail; + cs->num_scales = + ARRAY_SIZE(ad7606c_18_scale_differential_bipolar_avail); + /* Bipolar differential ranges start at 8 (b1000) */ + cs->reg_offset = 8; + cs->range = 1; + } else if (bipolar) { + cs->scale_avail = + ad7606c_18_scale_single_ended_bipolar_avail; + cs->num_scales = + ARRAY_SIZE(ad7606c_18_scale_single_ended_bipolar_avail); + cs->reg_offset = 0; + cs->range = 3; + } else { + cs->scale_avail = + ad7606c_18_scale_single_ended_unipolar_avail; + cs->num_scales = + ARRAY_SIZE(ad7606c_18_scale_single_ended_unipolar_avail); + /* Unipolar single-ended ranges start at 5 (b0101) */ + cs->reg_offset = 5; + cs->range = 1; + } +} + +static void ad7606c_16_chan_setup(struct ad7606_state *st, int ch, + bool bipolar, bool differential) +{ + struct ad7606_chan_scale *cs = &st->chan_scales[ch]; + + if (differential) { + cs->scale_avail = + ad7606c_16_scale_differential_bipolar_avail; + cs->num_scales = + ARRAY_SIZE(ad7606c_16_scale_differential_bipolar_avail); + /* Bipolar differential ranges start at 8 (b1000) */ + cs->reg_offset = 8; + cs->range = 1; + } else if (bipolar) { + cs->scale_avail = + ad7606c_16_scale_single_ended_bipolar_avail; + cs->num_scales = + ARRAY_SIZE(ad7606c_16_scale_single_ended_bipolar_avail); + cs->reg_offset = 0; + cs->range = 3; + } else { + cs->scale_avail = + ad7606c_16_scale_single_ended_unipolar_avail; + cs->num_scales = + ARRAY_SIZE(ad7606c_16_scale_single_ended_unipolar_avail); + /* Unipolar single-ended ranges start at 5 (b0101) */ + cs->reg_offset = 5; + cs->range = 1; + } +} + +static int ad7606c_sw_mode_setup_channels(struct iio_dev *indio_dev, + ad7606c_chan_setup_cb_t chan_setup_cb) +{ + unsigned int num_channels = indio_dev->num_channels - 1; + struct ad7606_state *st = iio_priv(indio_dev); + bool chan_configured[AD760X_MAX_CHANNELS] = {}; + struct device *dev = st->dev; + int ret; + u32 ch; + + /* We call this first, so that the proper SW scales get assigned */ + ret = st->bops->sw_mode_config(indio_dev); + if (ret) + return ret; + + device_for_each_child_node_scoped(dev, child) { + bool bipolar, differential; + u32 pins[2]; + + ret = fwnode_property_read_u32(child, "reg", &ch); + if (ret) + continue; + + /* channel number (here) is from 1 to num_channels */ + if (ch == 0 || ch > num_channels) { + dev_warn(st->dev, + "Invalid channel number (ignoring): %d\n", ch); + continue; + } + + bipolar = fwnode_property_read_bool(child, "bipolar"); + + ret = fwnode_property_read_u32_array(child, "diff-channels", + pins, ARRAY_SIZE(pins)); + /* Channel is differential, if pins are the same as 'reg' */ + if (ret == 0 && (pins[0] != ch || pins[1] != ch)) { + dev_err(st->dev, + "Differential pins must be the same as 'reg'"); + return -EINVAL; + } + + differential = (ret == 0); + + ch--; + + chan_setup_cb(st, ch, bipolar, differential); + chan_configured[ch] = true; + } + + /* Apply default configuration to unconfigured (via DT) channels */ + for (ch = 0; ch < num_channels; ch++) { + if (!chan_configured[ch]) + chan_setup_cb(st, ch, false, false); + } + + return 0; +} + +static int ad7606_sw_mode_setup(struct iio_dev *indio_dev, unsigned int id) { unsigned int num_channels = indio_dev->num_channels - 1; struct ad7606_state *st = iio_priv(indio_dev); @@ -572,17 +751,30 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) indio_dev->info = &ad7606_info_sw_mode; - /* Scale of 0.076293 is only available in sw mode */ - /* After reset, in software mode, ±10 V is set by default */ - for (ch = 0; ch < num_channels; ch++) { - struct ad7606_chan_scale *cs = &st->chan_scales[ch]; + switch (id) { + case ID_AD7606C_18: + ret = ad7606c_sw_mode_setup_channels(indio_dev, + ad7606c_18_chan_setup); + break; + case ID_AD7606C_16: + ret = ad7606c_sw_mode_setup_channels(indio_dev, + ad7606c_16_chan_setup); + break; + default: + /* Scale of 0.076293 is only available in sw mode */ + /* After reset, in software mode, ±10 V is set by default */ + for (ch = 0; ch < num_channels; ch++) { + struct ad7606_chan_scale *cs = &st->chan_scales[ch]; + + cs->scale_avail = ad7616_sw_scale_avail; + cs->num_scales = ARRAY_SIZE(ad7616_sw_scale_avail); + cs->range = 2; + } - cs->scale_avail = ad7616_sw_scale_avail; - cs->num_scales = ARRAY_SIZE(ad7616_sw_scale_avail); - cs->range = 2; + ret = st->bops->sw_mode_config(indio_dev); + break; } - ret = st->bops->sw_mode_config(indio_dev); if (ret) return ret; @@ -631,9 +823,16 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, st->oversampling = 1; cs = &st->chan_scales[0]; - cs->range = 0; - cs->scale_avail = ad7606_scale_avail; - cs->num_scales = ARRAY_SIZE(ad7606_scale_avail); + switch (id) { + case ID_AD7606C_18: + cs->scale_avail = ad7606_18bit_hw_scale_avail; + cs->num_scales = ARRAY_SIZE(ad7606_18bit_hw_scale_avail); + break; + default: + cs->scale_avail = ad7606_16bit_hw_scale_avail; + cs->num_scales = ARRAY_SIZE(ad7606_16bit_hw_scale_avail); + break; + } ret = devm_regulator_get_enable(dev, "avcc"); if (ret) @@ -682,7 +881,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, st->write_scale = ad7606_write_scale_hw; st->write_os = ad7606_write_os_hw; - ret = ad7606_sw_mode_setup(indio_dev); + ret = ad7606_sw_mode_setup(indio_dev, id); if (ret) return ret; diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index fa175cff256c..c2cb536ecef1 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -88,6 +88,8 @@ struct ad7606_chip_info { * such that it can be read via the 'read_avail' hook * @num_scales number of elements stored in the scale_avail array * @range voltage range selection, selects which scale to apply + * @reg_offset offset for the register value, to be applied when + * writing the value of 'range' to the register value */ struct ad7606_chan_scale { #define AD760X_MAX_SCALE_SHOW (AD760X_MAX_CHANNELS * 2) @@ -95,6 +97,7 @@ struct ad7606_chan_scale { int scale_avail_show[AD760X_MAX_SCALE_SHOW]; unsigned int num_scales; unsigned int range; + unsigned int reg_offset; }; /** @@ -151,9 +154,13 @@ struct ad7606_state { /* * DMA (thus cache coherency maintenance) may require the * transfer buffers to live in their own cache lines. - * 16 * 16-bit samples + 64-bit timestamp + * 16 * 16-bit samples + 64-bit timestamp - for AD7616 + * 8 * 32-bit samples + 64-bit timestamp - for AD7616C-18 (and similar) */ - unsigned short data[20] __aligned(IIO_DMA_MINALIGN); + union { + unsigned short d16[20]; + unsigned int d32[10]; + } data __aligned(IIO_DMA_MINALIGN); __be16 d16[2]; }; @@ -194,6 +201,8 @@ enum ad7606_supported_device_ids { ID_AD7606_6, ID_AD7606_4, ID_AD7606B, + ID_AD7606C_16, + ID_AD7606C_18, ID_AD7616, }; diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c index e00f58a6a0e9..2d7467314283 100644 --- a/drivers/iio/adc/ad7606_spi.c +++ b/drivers/iio/adc/ad7606_spi.c @@ -77,6 +77,18 @@ static const struct iio_chan_spec ad7606b_sw_channels[] = { AD7606_SW_CHANNEL(7, 16), }; +static const struct iio_chan_spec ad7606c_18_sw_channels[] = { + IIO_CHAN_SOFT_TIMESTAMP(8), + AD7606_SW_CHANNEL(0, 18), + AD7606_SW_CHANNEL(1, 18), + AD7606_SW_CHANNEL(2, 18), + AD7606_SW_CHANNEL(3, 18), + AD7606_SW_CHANNEL(4, 18), + AD7606_SW_CHANNEL(5, 18), + AD7606_SW_CHANNEL(6, 18), + AD7606_SW_CHANNEL(7, 18), +}; + static const unsigned int ad7606B_oversampling_avail[9] = { 1, 2, 4, 8, 16, 32, 64, 128, 256 }; @@ -120,6 +132,19 @@ static int ad7606_spi_read_block(struct device *dev, return 0; } +static int ad7606_spi_read_block18to32(struct device *dev, + int count, void *buf) +{ + struct spi_device *spi = to_spi_device(dev); + struct spi_transfer xfer = { + .bits_per_word = 18, + .len = count * sizeof(uint32_t), + .rx_buf = buf, + }; + + return spi_sync_transfer(spi, &xfer, 1); +} + static int ad7606_spi_reg_read(struct ad7606_state *st, unsigned int addr) { struct spi_device *spi = to_spi_device(st->dev); @@ -283,6 +308,19 @@ static int ad7606B_sw_mode_config(struct iio_dev *indio_dev) return 0; } +static int ad7606c_18_sw_mode_config(struct iio_dev *indio_dev) +{ + int ret; + + ret = ad7606B_sw_mode_config(indio_dev); + if (ret) + return ret; + + indio_dev->channels = ad7606c_18_sw_channels; + + return 0; +} + static const struct ad7606_bus_ops ad7606_spi_bops = { .read_block = ad7606_spi_read_block, }; @@ -305,6 +343,15 @@ static const struct ad7606_bus_ops ad7606B_spi_bops = { .sw_mode_config = ad7606B_sw_mode_config, }; +static const struct ad7606_bus_ops ad7606c_18_spi_bops = { + .read_block = ad7606_spi_read_block18to32, + .reg_read = ad7606_spi_reg_read, + .reg_write = ad7606_spi_reg_write, + .write_mask = ad7606_spi_write_mask, + .rd_wr_cmd = ad7606B_spi_rd_wr_cmd, + .sw_mode_config = ad7606c_18_sw_mode_config, +}; + static int ad7606_spi_probe(struct spi_device *spi) { const struct spi_device_id *id = spi_get_device_id(spi); @@ -315,8 +362,12 @@ static int ad7606_spi_probe(struct spi_device *spi) bops = &ad7616_spi_bops; break; case ID_AD7606B: + case ID_AD7606C_16: bops = &ad7606B_spi_bops; break; + case ID_AD7606C_18: + bops = &ad7606c_18_spi_bops; + break; default: bops = &ad7606_spi_bops; break; @@ -333,6 +384,8 @@ static const struct spi_device_id ad7606_id_table[] = { { "ad7606-6", ID_AD7606_6 }, { "ad7606-8", ID_AD7606_8 }, { "ad7606b", ID_AD7606B }, + { "ad7606c-16", ID_AD7606C_16 }, + { "ad7606c-18", ID_AD7606C_18 }, { "ad7616", ID_AD7616 }, { } }; @@ -344,6 +397,8 @@ static const struct of_device_id ad7606_of_match[] = { { .compatible = "adi,ad7606-6" }, { .compatible = "adi,ad7606-8" }, { .compatible = "adi,ad7606b" }, + { .compatible = "adi,ad7606c-16" }, + { .compatible = "adi,ad7606c-18" }, { .compatible = "adi,ad7616" }, { } };