From nobody Sun Feb 8 07:44:48 2026 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 8C55A146592 for ; Sat, 7 Sep 2024 06:50:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691855; cv=none; b=q/aQ76adZPMalMI7px+dGIEDlOirJzj6VByKhud/+OE35imtcitr18RS7oKjOG6ZVCQkjfb/PzaUZpnYFY3jTskOs++JPeks7vxEsB/w+19V8tIDsgEqJfOnrPYKMsX4hDYnUey5g/tVINKKfGj2YWzamYr9gd0CaBms1/B0ksg= 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.53 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-f53.google.com with SMTP id a640c23a62f3a-a8d13b83511so85386966b.2 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=OjpMVpTyihP+pmxUyyYXuGB6YH4r481hS/ingRL+quNZU37rJOiXi+P8bCR9DmAkQq Q2zRvCyggT9g56UGF1AtVLTu1GzHqs6ysyVIQjHcifMgy74MGVDbICOcwLxaLrSlo8u6 GHFMSFF27skuuXP0dRyK7kG7CDZNilto4C/wlOIgmrCSo+vtfNvx03h/UngXxyXFbqnG 5jcCzOzgTFcHugXoEkVdRv+h1SnT85267a7cE3xrybCR1SCe7i9RcK4rNSR/s72tYJi7 EN5B1rh+rVbKcu743eU37sORE9lfNcflx4OzBd8/CK7XNkuKVc4dg6GZLitRA9QWiP0v SNGQ== X-Forwarded-Encrypted: i=1; AJvYcCXJojddwQfwlgPf7Tbs0HQ57uEXzdgMwwM61Lys5DKvF71vUCeBq1dDdf2rB1nHfKHp9QV0Ww5HKkKgadU=@vger.kernel.org X-Gm-Message-State: AOJu0YwUYC88KWqT9u2uEQQAXMiw4AHoIfxrSilzkymCXbEfMRTLiCns s484p84D5VpCzHtgkVWoiSn0CN+Mym5NGK/Z487tcQsu8cToswgfD1dG4Py5gTc= 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/AD7= 606-4") Signed-off-by: Guillaume Stols Reviewed-by: Nuno Sa Link: https://patch.msgid.link/20240702-cleanup-ad7606-v3-1-18d5ea18770e@ba= ylibre.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] = =3D { 1, 2, 4, 8, 16, 32, 64, 128, }; =20 -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) =20 return -ENODEV; } +EXPORT_SYMBOL_NS_GPL(ad7606_reset, IIO_AD7606); =20 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 =3D st->chip_info->num_channels - 1; u16 *data =3D 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 =3D 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--; - } =20 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 __io= mem *base_address, const char *name, unsigned int id, const struct ad7606_bus_ops *bops); =20 +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 @@ =20 #include #include +#include #include #include #include @@ -21,8 +22,29 @@ static int ad7606_par16_read_block(struct device *dev, struct iio_dev *indio_dev =3D dev_get_drvdata(dev); struct ad7606_state *st =3D iio_priv(indio_dev); =20 - insw((unsigned long)st->base_address, buf, count); =20 + /* + * 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 =3D count; + u16 *_buf =3D 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; } =20 @@ -35,8 +57,28 @@ static int ad7606_par8_read_block(struct device *dev, { struct iio_dev *indio_dev =3D dev_get_drvdata(dev); struct ad7606_state *st =3D 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 =3D count; + u16 *_buf =3D 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); =20 return 0; } --=20 2.46.0 From nobody Sun Feb 8 07:44:48 2026 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 D9B32149011 for ; Sat, 7 Sep 2024 06:50:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691856; cv=none; b=Ih1iV8wtgfzUuF6DFGmtbWeCs78Oqom/jIWJAALv8aKj8h67zbRb2x4nqi6/D1v0h3OkQRTmsLKgc/TH9hml/u+Id3ry53x9U9bTujfqIZ6RMx6bN2LbPztNP8oBccer+G9VNUWtWfsOK4Nr/p095EYuI4btbQBFWpy99waBOOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691856; c=relaxed/simple; bh=NnhAJQBJzpZTWf9ZHFLmLmSoGg+UPZzZPZwyu2zRvAI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dENOJfbMjZK1mely5wfUJo6R03SnFqzZGxo5R82AImWRgHmGiJcjizyqrHd8Ntz6bhsxL1wx2H1QLWsEHfKovvqdcIiVnQMsZ4yBAcdPu3kPpUIz1ZuttXNDZJdvS4IA25g0fIuo1sgYD1b0JzggLpSJ3gboA+NXLv+1aYBuBk0= 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.49 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-f49.google.com with SMTP id 2adb3069b0e04-5365aec6fc1so1408830e87.3 for ; Fri, 06 Sep 2024 23:50:54 -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=R9HpROCkXTjs4fJ7SFLNYRNPhhLqqRRGCltVI1waJuap/ZN/LygvvPSlnIcej75XtZ fFuVZEXGjs70LkTQ9ZngsRw0+cFKrC9d8gVBhInTbbLpGjij8IfqZJOAy/Sby0jPaAVA qFGDdhDl5RfnA6+en0/2i/qx4OzBqZHNRuq3Zo3vHhjsSNzO3dhBpmx71JqpNfbdai/H 2rNsKdh/njA1rWgTOfEQYIJR4iPb0y6s20Udx9YknAZKaS4YNdVOce9m52qwwJ3FbGWx RhptkkoTID97dQ5SpRuzNki0ZisFV6KG2N4MH3NfoU8+4qk/eHwa1s8mWAunCXnWO+8m 6CNQ== X-Forwarded-Encrypted: i=1; AJvYcCV/p1bR9U0ExDcS1OK5umklM66vlLX97sLy/XSck/NfEqbF9HyTCTwFKIAhkxZO1PpV+JfvKNBs+MFJSoE=@vger.kernel.org X-Gm-Message-State: AOJu0Ywb2ZE0kQr7plituRXxNTWxdnSKXRr657pSEOzcFJ/rK8p6+K8w XJ+TfhkYl4rytzEysrFVqfmkq/3ngVjTD6qxe39TPxcTl/44zT6VDoqm6IKoeVs= 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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[] = =3D { AD7605_CHANNEL(3), }; =20 -static const struct iio_chan_spec ad7606_channels[] =3D { +static const struct iio_chan_spec ad7606_channels_16bit[] =3D { 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), }; =20 /* @@ -333,22 +333,22 @@ static const struct iio_chan_spec ad7606_channels[] = =3D { */ static const struct iio_chan_spec ad7616_channels[] =3D { 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), }; =20 static const struct ad7606_chip_info ad7606_chip_info_tbl[] =3D { @@ -358,25 +358,25 @@ static const struct ad7606_chip_info ad7606_chip_info= _tbl[] =3D { .num_channels =3D 5, }, [ID_AD7606_8] =3D { - .channels =3D ad7606_channels, + .channels =3D ad7606_channels_16bit, .num_channels =3D 9, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), }, [ID_AD7606_6] =3D { - .channels =3D ad7606_channels, + .channels =3D ad7606_channels_16bit, .num_channels =3D 7, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), }, [ID_AD7606_4] =3D { - .channels =3D ad7606_channels, + .channels =3D ad7606_channels_16bit, .num_channels =3D 5, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), }, [ID_AD7606B] =3D { - .channels =3D ad7606_channels, + .channels =3D ad7606_channels_16bit, .num_channels =3D 9, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D 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_ =20 -#define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all) { \ +#define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all, bits) { \ .type =3D IIO_VOLTAGE, \ .indexed =3D 1, \ .channel =3D num, \ @@ -19,24 +19,26 @@ .scan_index =3D num, \ .scan_type =3D { \ .sign =3D 's', \ - .realbits =3D 16, \ - .storagebits =3D 16, \ + .realbits =3D (bits), \ + .storagebits =3D (bits) > 16 ? 32 : 16, \ .endianness =3D IIO_CPU, \ }, \ } =20 #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) =20 -#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) =20 -#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) =20 /** * 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[] = =3D { =20 static const struct iio_chan_spec ad7606b_sw_channels[] =3D { 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), }; =20 static const unsigned int ad7606B_oversampling_avail[9] =3D { --=20 2.46.0 From nobody Sun Feb 8 07:44:48 2026 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 569691494A7 for ; Sat, 7 Sep 2024 06:50:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691857; cv=none; b=UfN75TRvCd6KHh/UhN8eEYkGDoyX8LngV2JEOoArf1+yPLoYpQuO9wmZ6MMVZJlDRKtV+zlrALOL4M+VObdhCEKa6QRP7vNkKm74JtfgRNBlAL3zY/aPgAM/JmpowzHF0S2u6Kgx4deZhZDN9nDS4/GGROJNbqeBC6dMKl0ZvXc= 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.52 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-f52.google.com with SMTP id a640c23a62f3a-a868b739cd9so372615266b.2 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=MR5Fbnw71mN71RlwNqScRSiV5xTv8Z/1jNpncWeAW7EkZjaZaJJinaylEp1p/tQTzj iLIBT9FSRSFsY3qwKqmTDFj2R5c5uq5RaO8bhh5rjiO4R+1ZsjLJjO5vNh9zJJDKweIf xcIwMWUXJrSLkAkkfa1pNzRuHHsp7sOSV893/xhL08HQqowyTwtNHIBfnxWOMAOjNgOv DngNRaYH4WolbRH0f7U/Mw5yTqUovF4WZRVvHTT6oLvAtCzZri2P2FGxx9xNAXjFPpan 8aIAzo+ImoTC/K4VNrJU590yNuIA7GEX/n375WDzB8z0GJBJLZsFVbp6/bGkV3oM0Iro HMKA== X-Forwarded-Encrypted: i=1; AJvYcCVoYfHVcMJ1nT9mRTkNDYbSHSmBiwuBHpQiGSZ3XUoZZUROBobEQQyv1gIWJ/OmEGbH5/eEIViX3lN9ZNw=@vger.kernel.org X-Gm-Message-State: AOJu0YyosGWVmJmCvQYoKq9wjwG57Ge8mOrvbdEvgRF8Dzua35A5fIoN ztzHzi+khD62iPlWhsvcfS0uGUFLx03WfLQ1yXL2lfHkDeW+0kNWRyTTc5XFhHM= 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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; } =20 -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 =3D iio_priv(indio_dev); int ret; @@ -129,7 +130,7 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev= , unsigned int ch) =20 ret =3D ad7606_read_samples(st); if (ret =3D=3D 0) - ret =3D st->data[ch]; + *val =3D sign_extend32(st->data[ch], 15); =20 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 =3D ad7606_scan_direct(indio_dev, chan->address); + ret =3D ad7606_scan_direct(indio_dev, chan->address, val); if (ret < 0) return ret; - *val =3D (short) ret; return IIO_VAL_INT; } unreachable(); --=20 2.46.0 From nobody Sun Feb 8 07:44:48 2026 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.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 1A8C514A614 for ; Sat, 7 Sep 2024 06:50:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691859; cv=none; b=S5XcaYUE65ym84Cx36GXekAVP6VicS6NSNZhdJIOpnwWEGGNw1dNF1WvsO2qLhQCAUFVlOQMbNdvsFDZFgJGG7WofAqp53GyRURfjKn13xhPQ2BjZF8zcYb+8cvckCXpuk+BwPbWkFmYy7NHziFGlEH2NbCNRbB7CmQKcr/J+nA= 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.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="EeRVgSeC" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a86883231b4so62758866b.3 for ; Fri, 06 Sep 2024 23:50:56 -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=sF4JFDTj3lBz0Iz6UmoKMbbWdxj03Qbv1O0ql31aBipNck0iFpCKqyVge9Ax/+qXDP S3odjqCFAaDNAfNzbmex0hghjd9niEvBfiTsJBln6huVqGEo4p4kuBKg8vhFrhh2SH9H VpJEc7ayJvvlXUBGHQceZQK1AMDeIbzFOsSdxKSkOInQfba2KraSoByv6fuM698B5JOJ khzVWYbC+MaCwrh2kmYjuX3OT0TKO0JlPlnMZivDxUfwonNd6bet5LuAna7kO6LHa8bw /KkVW+vsMsovYNqIkvr+H+80ywuhXGMMCiZ4xmoKdVFP7ZtpSkx5J7nm+a0YSvTQvP4e e0wA== X-Forwarded-Encrypted: i=1; AJvYcCUDt7ej2vyft77uV2KPLGH9vlMPpdYj54Z+UFRzpHvBzq5AGqHaqY7FW4I08OtEcqQ5Y1J5u7Pd01BI9WA=@vger.kernel.org X-Gm-Message-State: AOJu0Yzi4Jt9zRqcvfVxuYA3eJmbU8ooSu5vyQBKibsjy+R0cMrHu8dE i2rd38qXLa/Hlml///Hnoum+AOXOevr1b4ATHWG5327aTTSMrKXf1uapbCVZL0g= 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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= =3D { .validate_device =3D iio_trigger_validate_own_device, }; =20 +static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + + if (!st->bops->sw_mode_config) + return 0; + + st->sw_mode_en =3D device_property_present(st->dev, "adi,sw-mode"); + if (!st->sw_mode_en) + return 0; + + indio_dev->info =3D &ad7606_info_os_range_and_debug; + + /* Scale of 0.076293 is only available in sw mode */ + st->scale_avail =3D ad7616_sw_scale_avail; + st->num_scales =3D ARRAY_SIZE(ad7616_sw_scale_avail); + + /* After reset, in software mode, =C2=B110 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 __i= omem *base_address, st->write_scale =3D ad7606_write_scale_hw; st->write_os =3D ad7606_write_os_hw; =20 - if (st->bops->sw_mode_config) - st->sw_mode_en =3D 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 =3D ad7616_sw_scale_avail; - st->num_scales =3D ARRAY_SIZE(ad7616_sw_scale_avail); - - /* After reset, in software mode, =C2=B110 V is set by default */ - memset32(st->range, 2, ARRAY_SIZE(st->range)); - indio_dev->info =3D &ad7606_info_os_range_and_debug; - - ret =3D st->bops->sw_mode_config(indio_dev); - if (ret < 0) - return ret; - } + ret =3D ad7606_sw_mode_setup(indio_dev); + if (ret) + return ret; =20 st->trig =3D devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, --=20 2.46.0 From nobody Sun Feb 8 07:44:48 2026 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 26EB8146592 for ; Sat, 7 Sep 2024 06:50:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691862; cv=none; b=pI4AQP/kMwvSBRXMFudOV3MeKT7J1JEBXuhkg2djosnrTrzH/MMEWDJ/O+6LnnsmdiHcT6tFJiqXlIWd3VgKU8srV8APfkpEIhCJsQNbfSH4koYmXOrS3TNsuiPh94mRtYESO3ysG6ps0UUF3m6QLcuFKiHKoAY1yvcRzh6qUQ0= 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.44 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-f44.google.com with SMTP id 2adb3069b0e04-5333b2fbedaso4800855e87.0 for ; Fri, 06 Sep 2024 23:50:59 -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=HgEPFVlXFuJuvSOJmMnZYRMrWc+9jUgQBy2dkL3ie/95S4jZedfML/V9jOTwRfCNfj iP3KFIKqo4O/1lfE9MAddINueOAZNaFnKCJo0OZx+RTgGVaR3gpooHP6IAhnYOK9Y1NH Eg3KY8MbuTiB1WlvDiCc6FcXbnF8PLBlCaRrL41KQ7n0jtQyLEw+uFdv3fngKFHmyoLs DXZVJuP/KHUsdxdIPgDrx17BYY2LeYpTAm4uaNG7PtdcdSJBiJaHfo//J1KkXRLDo1yS AXZM7ZH8a05pglziyuEFUitSR/vYGQtAp5Fggc90FvRoXXZEYdlod64WvpDIUxz8DKWL QN3Q== X-Forwarded-Encrypted: i=1; AJvYcCVxFlFtH9hX6mWBDi1fGNk+HH/vtFRdSgfiFPDSPc8zSHvYRMzeddFPFBxCHnhUQmALuluA4QvkVVkORY8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8ast9t2yfviwqE/E2P0zKtmHp8iYSZwi/pXnlh2aFhzDF0sTg D33/x31RQHN3ApqjAN6RbfoRkYw7rUizAn+iBDqqnkfuSpQgwXuE6be32rSW2Zs= 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 =3D 0; struct ad7606_state *st =3D iio_priv(indio_dev); + struct ad7606_chan_scale *cs; =20 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 =3D chan->address; + cs =3D &st->chan_scales[ch]; *val =3D 0; - *val2 =3D st->scale_avail[st->range[ch]]; + *val2 =3D cs->scale_avail[cs->range]; return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: *val =3D st->oversampling; @@ -190,8 +192,9 @@ static ssize_t in_voltage_scale_available_show(struct d= evice *dev, { struct iio_dev *indio_dev =3D dev_to_iio_dev(dev); struct ad7606_state *st =3D iio_priv(indio_dev); + struct ad7606_chan_scale *cs =3D &st->chan_scales[0]; =20 - return ad7606_show_avail(buf, st->scale_avail, st->num_scales, true); + return ad7606_show_avail(buf, cs->scale_avail, cs->num_scales, true); } =20 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 =3D iio_priv(indio_dev); + struct ad7606_chan_scale *cs; int i, ret, ch =3D 0; =20 guard(mutex)(&st->lock); =20 switch (mask) { case IIO_CHAN_INFO_SCALE: - i =3D find_closest(val2, st->scale_avail, st->num_scales); if (st->sw_mode_en) ch =3D chan->address; + cs =3D &st->chan_scales[ch]; + i =3D find_closest(val2, cs->scale_avail, cs->num_scales); ret =3D st->write_scale(indio_dev, ch, i); if (ret < 0) return ret; - st->range[ch] =3D i; + cs->range =3D i; =20 return 0; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: @@ -523,7 +528,9 @@ static const struct iio_trigger_ops ad7606_trigger_ops = =3D { =20 static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) { + unsigned int num_channels =3D indio_dev->num_channels - 1; struct ad7606_state *st =3D iio_priv(indio_dev); + int ch; =20 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 =3D &ad7606_info_os_range_and_debug; =20 /* Scale of 0.076293 is only available in sw mode */ - st->scale_avail =3D ad7616_sw_scale_avail; - st->num_scales =3D ARRAY_SIZE(ad7616_sw_scale_avail); - /* After reset, in software mode, =C2=B110 V is set by default */ - memset32(st->range, 2, ARRAY_SIZE(st->range)); + for (ch =3D 0; ch < num_channels; ch++) { + struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; + + cs->scale_avail =3D ad7616_sw_scale_avail; + cs->num_scales =3D ARRAY_SIZE(ad7616_sw_scale_avail); + cs->range =3D 2; + } =20 return st->bops->sw_mode_config(indio_dev); } @@ -548,6 +558,7 @@ int ad7606_probe(struct device *dev, int irq, void __io= mem *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 =3D bops; st->base_address =3D base_address; /* tied to logic low, analog input range is +/- 5V */ - st->range[0] =3D 0; st->oversampling =3D 1; - st->scale_avail =3D ad7606_scale_avail; - st->num_scales =3D ARRAY_SIZE(ad7606_scale_avail); + + cs =3D &st->chan_scales[0]; + cs->range =3D 0; + cs->scale_avail =3D ad7606_scale_avail; + cs->num_scales =3D ARRAY_SIZE(ad7606_scale_avail); =20 ret =3D devm_regulator_get_enable(dev, "avcc"); if (ret) @@ -674,7 +687,7 @@ static int ad7606_resume(struct device *dev) struct ad7606_state *st =3D iio_priv(indio_dev); =20 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_ =20 +#define AD760X_MAX_CHANNELS 16 + #define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all, bits) { \ .type =3D IIO_VOLTAGE, \ .indexed =3D 1, \ @@ -60,17 +62,27 @@ struct ad7606_chip_info { unsigned long init_delay_ms; }; =20 +/** + * 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); --=20 2.46.0 From nobody Sun Feb 8 07:44:48 2026 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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 D94B8157E87 for ; Sat, 7 Sep 2024 06:51:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691862; cv=none; b=hXwXvosDhaJaYZ6GlrPpdhUJuifBcEUQbPkqpk7mMmUygrgZ9ignEcWgwZ2Y0c0+Hi38SmlN/ODvXAiCqu6pjUXdC88o3ZEfJ4N1oHvHyxnCdXWIUdhk5/L2ierkbx/YEyyTKs96xFHdKDjwDhhGl46oJ+k259GSAuS+F0zB4Jw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691862; c=relaxed/simple; bh=UrQVZr2Ut7tXRzDLHI6k+MfrW96ZgN+yhIcNORux8Lc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RewQQUBBeIk//6gekPxt3XD8sPVzOoH+dJW6cGRSvr2T8TyV1/EDyOuMrdIGUaGNEIHbGeCjIy0WmdaqImxMt4cq62SHJruZxY4yJdSrkLFElRW0hQqck0Nu6kGTw2+g315ZOb7zP3NvopuTpxgwkEtpeUDXnrgWDkpJMiBWDLk= 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.208.178 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-lj1-f178.google.com with SMTP id 38308e7fff4ca-2f74e613a10so343911fa.1 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=IvQv0dBUycOZW8aX1xhas9kBoU34hKz+Vf2PnwgLArEV2nS7RCAHMkV6yj0J9Nla5R ADEjMgKoOQNjsb8Bn4WyFZTGb+ZDnHveJpldpN2t4fgXOKCsimaWvihHh2YOr7Q6SBtK /+820/wl2Up17e/CqimqCfQCPVwNS1SkKrmt5f2S3pdkbfHSI4HpojKU0gffYKUQuxCA nimFAoeRJkC7oL3R0DDBOrho6Z1xEAc7GmtbiHgyh+XC1HxMNledQ4k9I/xrkwDB5ozl mM4B8T0OldEzD+GJrHAl7aYmh6S//3q090mAKx03tUVCSZRQZYdpvyqAC4zK0YfqrEgf fTjw== X-Forwarded-Encrypted: i=1; AJvYcCV3cqrFKIudWAELHsPgW+ve+9makMPQiiORHX83iwAVo+jya/i22S+mCfIoMYTOK7aSYLbxF/27fbnLWTs=@vger.kernel.org X-Gm-Message-State: AOJu0YzSAHqeHrThNkVZFnX01HqyvSoI02TRlXAld3fLSfQ3QAqI7J0b votlqzQqlyfpZSmujVa1vPDMaiCMORgpLPKjuK7+o2eZoFBbxW2wMssAxd7PZb8= 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 *in= dio_dev) return 0; } =20 +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 =3D iio_priv(indio_dev); + struct ad7606_chan_scale *cs; + unsigned int ch =3D 0; + + switch (info) { + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + *vals =3D st->oversampling_avail; + *length =3D st->num_os_ratios; + *type =3D IIO_VAL_INT; + + return IIO_AVAIL_LIST; + + case IIO_CHAN_INFO_SCALE: + if (st->sw_mode_en) + ch =3D chan->address; + + cs =3D &st->chan_scales[ch]; + *vals =3D cs->scale_avail_show; + *length =3D cs->num_scales * 2; + *type =3D IIO_VAL_INT_PLUS_MICRO; + + return IIO_AVAIL_LIST; + } + return -EINVAL; +} + static const struct iio_buffer_setup_ops ad7606_buffer_ops =3D { .postenable =3D &ad7606_buffer_postenable, .predisable =3D &ad7606_buffer_predisable, @@ -500,11 +531,11 @@ static const struct iio_info ad7606_info_os_and_range= =3D { .validate_trigger =3D &ad7606_validate_trigger, }; =20 -static const struct iio_info ad7606_info_os_range_and_debug =3D { +static const struct iio_info ad7606_info_sw_mode =3D { .read_raw =3D &ad7606_read_raw, .write_raw =3D &ad7606_write_raw, + .read_avail =3D &ad7606_read_avail, .debugfs_reg_access =3D &ad7606_reg_access, - .attrs =3D &ad7606_attribute_group_os_and_range, .validate_trigger =3D &ad7606_validate_trigger, }; =20 @@ -530,7 +561,7 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio_d= ev) { unsigned int num_channels =3D indio_dev->num_channels - 1; struct ad7606_state *st =3D iio_priv(indio_dev); - int ch; + int ret, ch; =20 if (!st->bops->sw_mode_config) return 0; @@ -539,7 +570,7 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio_d= ev) if (!st->sw_mode_en) return 0; =20 - indio_dev->info =3D &ad7606_info_os_range_and_debug; + indio_dev->info =3D &ad7606_info_sw_mode; =20 /* Scale of 0.076293 is only available in sw mode */ /* After reset, in software mode, =C2=B110 V is set by default */ @@ -551,7 +582,29 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio_= dev) cs->range =3D 2; } =20 - return st->bops->sw_mode_config(indio_dev); + ret =3D st->bops->sw_mode_config(indio_dev); + if (ret) + return ret; + + for (ch =3D 0; ch < num_channels; ch++) { + struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; + int i; + + cs =3D &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 =3D 0; i < cs->num_scales; i++) { + cs->scale_avail_show[i * 2] =3D 0; + cs->scale_avail_show[i * 2 + 1] =3D cs->scale_avail[i]; + } + } + + return 0; } =20 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 @@ }, \ } =20 +#define AD7606_SW_CHANNEL(num, bits) { \ + .type =3D IIO_VOLTAGE, \ + .indexed =3D 1, \ + .channel =3D num, \ + .address =3D num, \ + .info_mask_separate =3D \ + BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_separate_available =3D \ + BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_all =3D \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .info_mask_shared_by_all_available =3D \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .scan_index =3D num, \ + .scan_type =3D { \ + .sign =3D 's', \ + .realbits =3D (bits), \ + .storagebits =3D (bits) > 16 ? 32 : 16, \ + .endianness =3D 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) =20 -#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) =20 /** @@ -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 formatt= ed + * 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; }; --=20 2.46.0 From nobody Sun Feb 8 07:44:48 2026 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.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 A2F951586DB for ; Sat, 7 Sep 2024 06:51:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691864; cv=none; b=d4zqsOVEvh8iqhXhmfWIzg3zFWmi81Ym6DypVMPLX8nNXnxznL3qIcbiuFDyGSEFosOp7FND6iyg9M3IZLT11JKXF+j/wge7DmWVjAvcPDdnMqtzp1bbGQheTqRpx9wD4Q3Ua3VT55WkzCZ77rhW8ViZS5P0wx+vpKLYbZpPTkk= 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.218.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="I6b01P3v" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a89c8db505bso368937766b.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=RB4xmY5RjQ/FOPfMjIP+r5fNMXN36eThkd1HOC+txe2F+8FhxOmSRR/Q4h3OnqKBdi DEEyRZxL+Uipo+SMIcpG5eN0pQJn7pSAddeRvNaJiRuTQOkg3vppPhDSYXBRkw1ZV1ZX Sxu7cQmIxrTxXwNdl9D59sghm9RYmxKPwfdnPfhUbuDifg7SFYldxPxWMELk/BwGDML2 VzjoJHH7osxoDqK93h78jnL6j27yaEL5I79WyHE6xIp/O3B4DTGYMJbkCfw6Szg1yYNl dSMthk10asmkB2nHGHO92zOw46LG8C0EN6tpx0Ggud2rCIpRYeGTRk+3wLh+yQZ5XAhe AH0g== X-Forwarded-Encrypted: i=1; AJvYcCXmXwbP9Pzo9L9+UR+PqfXuMWit5Qp9Oh6OUZ7wSwR+GI+JE+ZzMnpsMK3YIk2qwoUUMdjoSpENmkUmwVo=@vger.kernel.org X-Gm-Message-State: AOJu0YyzQ/i8SJMOIr6ZhXmUElRU6VWpy7KsHjlySuntuwik1esOZYym Fur9C8pdI6MN2QvDV2YGuYoLf+ZWHLhivDmxKjCpn034jw7d+nkyIl6NIao5VF4= 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/Documenta= tion/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 dedicat= ed + positive and negative inputs which can be used to measure differenti= al + voltage levels. For those setups, this property can be configured wi= th + the 'reg' property for both inputs (i.e. diff-channels =3D = ). =20 single-channel: $ref: /schemas/types.yaml#/definitions/uint32 --=20 2.46.0 From nobody Sun Feb 8 07:44:48 2026 Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (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 CC398159583 for ; Sat, 7 Sep 2024 06:51:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691868; cv=none; b=OFTOVyMqaDO+35saQeB4nqir/BMr4yBhE7ME0aux8IuRq+KEbqBqyRO1v74jQ68AfNJqxHu7sXI7IoEwWINMZWYPsVVtzMoie5dzrO6r4uTt0Wz6M7LlKSFrmsXCO9QsEewF4WJ0mJLMIupS1mmwDaNhJcg890avb2J8rKBZWz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725691868; c=relaxed/simple; bh=WtTqoqsoPDCsAqupR0u+y5bxkErf4GAtT/qIF8GJb84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HgXSe2jMVsP7bAmlZnZn4Ot9/S4ubkOeOj9Fzlc0mdRxytOm84G6smb9AJ/AWRMJu9bHIX+DNni857YHIX6QPSXcWORIVtST4llU/Px862+NEpI2x5oPrR4Qmr9++5Ipgp8ZK3BD5uNZn7mjfwnRdyhVNypFj9gNrxrgmSc/c+s= 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.173 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-f173.google.com with SMTP id 38308e7fff4ca-2f74e613a10so344591fa.1 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=pVXV/licJ0K9UcZ1EvHPt/QtSJCoL+PHwd3OrnL4b53YgD19RkiiaAImeahv2AbvJI HkQ17QgLE5xJl7gwYsCptT6ZyjyLjHKdn0LHgJneUGR/caIYyqOn7Uv4tnioSZmR2pY3 KeGEOPwPT4WczVV+XpALv0CsB7T/zNXmGMIkxbFkAiuX7FBPBzyv6zo0CzSWHnvsRuxq yfoC6SqEvuzAe5RHEsM02fytf2cShsno5pW1UfMogeV2LxAEvc84jvu3EW6BhFHXgKjx f0jodS/5u8gOxlvDx4wnPBy1fXgAq57C7EbLl1E8fY3t64UjY87FuyFiSgjO25pS8WLI Fnig== X-Forwarded-Encrypted: i=1; AJvYcCXI/D1WTRA9xbH/oS3tEW4/5gIlHZNbvhDErGHYKPMA2E9wM2FiEUsKAWV2u88QhvxgthvljtcD32hWYGk=@vger.kernel.org X-Gm-Message-State: AOJu0YxDFgoF8GX6RJewiYwKKFQE3XnBRKqun7mH41oETq14UyT/mm8U XIzU6AizCv/XBylaYPYgLDUskzvtd4ILyKbN4h+fug5Hd/QMQPv081zAS8v39d8= 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/Do= cumentation/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/AD76= 05-4.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/ad76= 06_7606-6_7606-4.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD76= 06B.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/ad76= 06c-16.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/ad76= 06c-18.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD76= 16.pdf =20 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 =20 reg: maxItems: 1 =20 + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + spi-cpha: true =20 spi-cpol: true @@ -114,6 +124,46 @@ properties: assumed that the pins are hardwired to VDD. type: boolean =20 +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 =3D ). + items: + minimum: 1 + maximum: 8 + + bipolar: + description: + Each channel can be configured as a unipolar or bipolar single-e= nded. + When this property is not specified, it's unipolar, so the ADC w= ill + have only the positive input wired. + For this ADC the 'diff-channels' & 'bipolar' properties are mutu= ally + exclusive. + + required: + - reg + + oneOf: + - required: + - diff-channels + - required: + - bipolar + required: - compatible - reg @@ -170,6 +220,25 @@ allOf: adi,conversion-start-gpios: maxItems: 1 =20 + - 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 =20 examples: @@ -202,4 +271,52 @@ examples: standby-gpios =3D <&gpio 24 GPIO_ACTIVE_LOW>; }; }; + - | + #include + #include + spi { + #address-cells =3D <1>; + #size-cells =3D <0>; + + adc@0 { + compatible =3D "adi,ad7606c-18"; + reg =3D <0>; + + #address-cells =3D <1>; + #size-cells =3D <0>; + + spi-max-frequency =3D <1000000>; + spi-cpol; + spi-cpha; + + avcc-supply =3D <&adc_vref>; + vdrive-supply =3D <&vdd_supply>; + + interrupts =3D <25 IRQ_TYPE_EDGE_FALLING>; + interrupt-parent =3D <&gpio>; + + adi,conversion-start-gpios =3D <&gpio 17 GPIO_ACTIVE_HIGH>; + reset-gpios =3D <&gpio 27 GPIO_ACTIVE_HIGH>; + adi,first-data-gpios =3D <&gpio 22 GPIO_ACTIVE_HIGH>; + standby-gpios =3D <&gpio 24 GPIO_ACTIVE_LOW>; + + adi,sw-mode; + + channel@1 { + reg =3D <1>; + diff-channels =3D <1 1>; + }; + + channel@3 { + reg =3D <3>; + bipolar; + }; + + channel@8 { + reg =3D <8>; + diff-channels =3D <8 8>; + }; + + }; + }; ... --=20 2.46.0 From nobody Sun Feb 8 07:44:48 2026 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 91EEC15B10E for ; Sat, 7 Sep 2024 06:51:06 +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=1725691869; cv=none; b=gnuDnuxIbBd0ZnruLAYrcL10nabeonkPNO0Xa2+qGhveD+FGRuBDidYzK4FCziQdxPiRKvOKIZmUvwOsp8Oi3rvAn3j/nBeFFEk42jZmPeVMO8ZfMVhuNyQiS4mY8hmnQ/RTky4z/2RQqlY0+Hf4s0gpQY6BMEm9x2T/nMjTLmM= 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.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="els9QOCy" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-5365aa568ceso1544176e87.0 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=gQkqWhv32Yf2gq5hlLa5pFbkTnWyxEYX08YjE15V7JVYsDu+Q7kc7risjp4MmC6r8C 3RixdaYPt2h9WarxH1YPGXkezUvFZhVEJ7N6KrE6ZaKvFHv05IOQ+GJV//ZR6yk9Ct9Z 7+Z0DREcSjK/O1o8WenHsnkhcG36ooUvXoTRGTzonBKSVoZq2L8QGh58Hfu8eg6CJqE6 /Qpe0VPFcv8F7ISSoM1mmG1gmc5I9e7gvD8x9ccwOs9vmHAcs96t3eyK/KCJwuY9WIXm cWg2c9xq/dwq2V2IPI+piL1BerGM5bdw8Eva4Ep+NGy+ibceeRpTrWDW/CKTz8d7YzBS Z6LQ== X-Forwarded-Encrypted: i=1; AJvYcCVMUsmWB1iy34emlsaA0mza2rIYe7bVSt8TMxzj8p+uOH1Fijyn89rHe3+ZBpXLcZB0U29+A9secj9O8aE=@vger.kernel.org X-Gm-Message-State: AOJu0YwnRdZE3ayr9eFGWXfVH7Xkg+JGizYv4tI8WOum5MSEr0495Af0 McLhiM0gZ/dKY1yXjTdiotcMp1mJG1TwMmenv24biV3n+ExkXUJDGW7LqIBvmAs= 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 =C2=B110V should be set at probe. On reset, the default range (in the registers) is set to value 0x3 which corresponds to '=C2=B110 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/ad760= 6c-16.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/ad760= 6c-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 @@ =20 #include "ad7606.h" =20 +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] =3D { +static const unsigned int ad7606_16bit_hw_scale_avail[2] =3D { 152588, 305176 }; =20 +static const unsigned int ad7606_18bit_hw_scale_avail[2] =3D { + 38147, 76294 +}; + +static const unsigned int ad7606c_16_scale_single_ended_unipolar_avail[3] = =3D { + 76294, 152588, 190735, +}; + +static const unsigned int ad7606c_16_scale_single_ended_bipolar_avail[5] = =3D { + 76294, 152588, 190735, 305176, 381470 +}; + +static const unsigned int ad7606c_16_scale_differential_bipolar_avail[4] = =3D { + 152588, 305176, 381470, 610352 +}; + +static const unsigned int ad7606c_18_scale_single_ended_unipolar_avail[3] = =3D { + 19073, 38147, 47684 +}; + +static const unsigned int ad7606c_18_scale_single_ended_bipolar_avail[5] = =3D { + 19073, 38147, 47684, 76294, 95367 +}; + +static const unsigned int ad7606c_18_scale_differential_bipolar_avail[4] = =3D { + 38147, 76294, 95367, 152588 +}; =20 static const unsigned int ad7616_sw_scale_avail[3] =3D { 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 =3D st->chip_info->num_channels - 1; - u16 *data =3D st->data; + void *data =3D st->data.d16; =20 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; =20 - 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 =3D iio_priv(indio_dev); + unsigned int storagebits =3D st->chip_info->channels[1].scan_type.storage= bits; int ret; =20 gpiod_set_value(st->gpio_convst, 1); @@ -129,8 +160,12 @@ static int ad7606_scan_direct(struct iio_dev *indio_de= v, unsigned int ch, } =20 ret =3D ad7606_read_samples(st); - if (ret =3D=3D 0) - *val =3D sign_extend32(st->data[ch], 15); + if (ret =3D=3D 0) { + if (storagebits > 16) + *val =3D sign_extend32(st->data.d32[ch], 17); + else + *val =3D sign_extend32(st->data.d16[ch], 15); + } =20 error_ret: gpiod_set_value(st->gpio_convst, 0); @@ -243,7 +278,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, ch =3D chan->address; cs =3D &st->chan_scales[ch]; i =3D find_closest(val2, cs->scale_avail, cs->num_scales); - ret =3D st->write_scale(indio_dev, ch, i); + ret =3D st->write_scale(indio_dev, ch, i + cs->reg_offset); if (ret < 0) return ret; cs->range =3D i; @@ -326,6 +361,18 @@ static const struct iio_chan_spec ad7606_channels_16bi= t[] =3D { AD7606_CHANNEL(7, 16), }; =20 +static const struct iio_chan_spec ad7606_channels_18bit[] =3D { + 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 activat= ed. @@ -386,6 +433,18 @@ static const struct ad7606_chip_info ad7606_chip_info_= tbl[] =3D { .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), }, + [ID_AD7606C_16] =3D { + .channels =3D ad7606_channels_16bit, + .num_channels =3D 9, + .oversampling_avail =3D ad7606_oversampling_avail, + .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), + }, + [ID_AD7606C_18] =3D { + .channels =3D ad7606_channels_18bit, + .num_channels =3D 9, + .oversampling_avail =3D ad7606_oversampling_avail, + .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), + }, [ID_AD7616] =3D { .channels =3D ad7616_channels, .num_channels =3D 17, @@ -557,7 +616,127 @@ static const struct iio_trigger_ops ad7606_trigger_op= s =3D { .validate_device =3D iio_trigger_validate_own_device, }; =20 -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 =3D &st->chan_scales[ch]; + + if (differential) { + cs->scale_avail =3D + ad7606c_18_scale_differential_bipolar_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_18_scale_differential_bipolar_avail); + /* Bipolar differential ranges start at 8 (b1000) */ + cs->reg_offset =3D 8; + cs->range =3D 1; + } else if (bipolar) { + cs->scale_avail =3D + ad7606c_18_scale_single_ended_bipolar_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_18_scale_single_ended_bipolar_avail); + cs->reg_offset =3D 0; + cs->range =3D 3; + } else { + cs->scale_avail =3D + ad7606c_18_scale_single_ended_unipolar_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_18_scale_single_ended_unipolar_avail); + /* Unipolar single-ended ranges start at 5 (b0101) */ + cs->reg_offset =3D 5; + cs->range =3D 1; + } +} + +static void ad7606c_16_chan_setup(struct ad7606_state *st, int ch, + bool bipolar, bool differential) +{ + struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; + + if (differential) { + cs->scale_avail =3D + ad7606c_16_scale_differential_bipolar_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_16_scale_differential_bipolar_avail); + /* Bipolar differential ranges start at 8 (b1000) */ + cs->reg_offset =3D 8; + cs->range =3D 1; + } else if (bipolar) { + cs->scale_avail =3D + ad7606c_16_scale_single_ended_bipolar_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_16_scale_single_ended_bipolar_avail); + cs->reg_offset =3D 0; + cs->range =3D 3; + } else { + cs->scale_avail =3D + ad7606c_16_scale_single_ended_unipolar_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_16_scale_single_ended_unipolar_avail); + /* Unipolar single-ended ranges start at 5 (b0101) */ + cs->reg_offset =3D 5; + cs->range =3D 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 =3D indio_dev->num_channels - 1; + struct ad7606_state *st =3D iio_priv(indio_dev); + bool chan_configured[AD760X_MAX_CHANNELS] =3D {}; + struct device *dev =3D st->dev; + int ret; + u32 ch; + + /* We call this first, so that the proper SW scales get assigned */ + ret =3D 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 =3D fwnode_property_read_u32(child, "reg", &ch); + if (ret) + continue; + + /* channel number (here) is from 1 to num_channels */ + if (ch =3D=3D 0 || ch > num_channels) { + dev_warn(st->dev, + "Invalid channel number (ignoring): %d\n", ch); + continue; + } + + bipolar =3D fwnode_property_read_bool(child, "bipolar"); + + ret =3D fwnode_property_read_u32_array(child, "diff-channels", + pins, ARRAY_SIZE(pins)); + /* Channel is differential, if pins are the same as 'reg' */ + if (ret =3D=3D 0 && (pins[0] !=3D ch || pins[1] !=3D ch)) { + dev_err(st->dev, + "Differential pins must be the same as 'reg'"); + return -EINVAL; + } + + differential =3D (ret =3D=3D 0); + + ch--; + + chan_setup_cb(st, ch, bipolar, differential); + chan_configured[ch] =3D true; + } + + /* Apply default configuration to unconfigured (via DT) channels */ + for (ch =3D 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 =3D indio_dev->num_channels - 1; struct ad7606_state *st =3D iio_priv(indio_dev); @@ -572,17 +751,30 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio= _dev) =20 indio_dev->info =3D &ad7606_info_sw_mode; =20 - /* Scale of 0.076293 is only available in sw mode */ - /* After reset, in software mode, =C2=B110 V is set by default */ - for (ch =3D 0; ch < num_channels; ch++) { - struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; + switch (id) { + case ID_AD7606C_18: + ret =3D ad7606c_sw_mode_setup_channels(indio_dev, + ad7606c_18_chan_setup); + break; + case ID_AD7606C_16: + ret =3D 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, =C2=B110 V is set by default */ + for (ch =3D 0; ch < num_channels; ch++) { + struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; + + cs->scale_avail =3D ad7616_sw_scale_avail; + cs->num_scales =3D ARRAY_SIZE(ad7616_sw_scale_avail); + cs->range =3D 2; + } =20 - cs->scale_avail =3D ad7616_sw_scale_avail; - cs->num_scales =3D ARRAY_SIZE(ad7616_sw_scale_avail); - cs->range =3D 2; + ret =3D st->bops->sw_mode_config(indio_dev); + break; } =20 - ret =3D st->bops->sw_mode_config(indio_dev); if (ret) return ret; =20 @@ -631,9 +823,16 @@ int ad7606_probe(struct device *dev, int irq, void __i= omem *base_address, st->oversampling =3D 1; =20 cs =3D &st->chan_scales[0]; - cs->range =3D 0; - cs->scale_avail =3D ad7606_scale_avail; - cs->num_scales =3D ARRAY_SIZE(ad7606_scale_avail); + switch (id) { + case ID_AD7606C_18: + cs->scale_avail =3D ad7606_18bit_hw_scale_avail; + cs->num_scales =3D ARRAY_SIZE(ad7606_18bit_hw_scale_avail); + break; + default: + cs->scale_avail =3D ad7606_16bit_hw_scale_avail; + cs->num_scales =3D ARRAY_SIZE(ad7606_16bit_hw_scale_avail); + break; + } =20 ret =3D devm_regulator_get_enable(dev, "avcc"); if (ret) @@ -682,7 +881,7 @@ int ad7606_probe(struct device *dev, int irq, void __io= mem *base_address, st->write_scale =3D ad7606_write_scale_hw; st->write_os =3D ad7606_write_os_hw; =20 - ret =3D ad7606_sw_mode_setup(indio_dev); + ret =3D ad7606_sw_mode_setup(indio_dev, id); if (ret) return ret; =20 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; }; =20 /** @@ -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]; }; =20 @@ -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, }; =20 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[] = =3D { AD7606_SW_CHANNEL(7, 16), }; =20 +static const struct iio_chan_spec ad7606c_18_sw_channels[] =3D { + 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] =3D { 1, 2, 4, 8, 16, 32, 64, 128, 256 }; @@ -120,6 +132,19 @@ static int ad7606_spi_read_block(struct device *dev, return 0; } =20 +static int ad7606_spi_read_block18to32(struct device *dev, + int count, void *buf) +{ + struct spi_device *spi =3D to_spi_device(dev); + struct spi_transfer xfer =3D { + .bits_per_word =3D 18, + .len =3D count * sizeof(uint32_t), + .rx_buf =3D 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 =3D to_spi_device(st->dev); @@ -283,6 +308,19 @@ static int ad7606B_sw_mode_config(struct iio_dev *indi= o_dev) return 0; } =20 +static int ad7606c_18_sw_mode_config(struct iio_dev *indio_dev) +{ + int ret; + + ret =3D ad7606B_sw_mode_config(indio_dev); + if (ret) + return ret; + + indio_dev->channels =3D ad7606c_18_sw_channels; + + return 0; +} + static const struct ad7606_bus_ops ad7606_spi_bops =3D { .read_block =3D ad7606_spi_read_block, }; @@ -305,6 +343,15 @@ static const struct ad7606_bus_ops ad7606B_spi_bops = =3D { .sw_mode_config =3D ad7606B_sw_mode_config, }; =20 +static const struct ad7606_bus_ops ad7606c_18_spi_bops =3D { + .read_block =3D ad7606_spi_read_block18to32, + .reg_read =3D ad7606_spi_reg_read, + .reg_write =3D ad7606_spi_reg_write, + .write_mask =3D ad7606_spi_write_mask, + .rd_wr_cmd =3D ad7606B_spi_rd_wr_cmd, + .sw_mode_config =3D ad7606c_18_sw_mode_config, +}; + static int ad7606_spi_probe(struct spi_device *spi) { const struct spi_device_id *id =3D spi_get_device_id(spi); @@ -315,8 +362,12 @@ static int ad7606_spi_probe(struct spi_device *spi) bops =3D &ad7616_spi_bops; break; case ID_AD7606B: + case ID_AD7606C_16: bops =3D &ad7606B_spi_bops; break; + case ID_AD7606C_18: + bops =3D &ad7606c_18_spi_bops; + break; default: bops =3D &ad7606_spi_bops; break; @@ -333,6 +384,8 @@ static const struct spi_device_id ad7606_id_table[] =3D= { { "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[] =3D { { .compatible =3D "adi,ad7606-6" }, { .compatible =3D "adi,ad7606-8" }, { .compatible =3D "adi,ad7606b" }, + { .compatible =3D "adi,ad7606c-16" }, + { .compatible =3D "adi,ad7606c-18" }, { .compatible =3D "adi,ad7616" }, { } }; --=20 2.46.0