From nobody Mon Feb 9 14:37:26 2026 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 54A751FECCC for ; Tue, 4 Mar 2025 09:39:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741081183; cv=none; b=PlVdGAS+RqbJq3P1pkD3N71GAUptLsUjCJCeI0vR6LjU4I8vfLg55djorRPT+mMxw+qtXDBfnIKIW6xe+Feol5pIFczmiCdW5l1oXmny1032kLBEdkZG+vjGXnmkSXIVFtNDuU/cxAjZkmHL7IMPu+uGKKnHVBaIRQZgBwu7ZPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741081183; c=relaxed/simple; bh=2slm5m9BpKKXU+a/X36HfWUI+7ujXf9i4hlS78CPhAI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NkdY3VR/dmqG6fPVIe21S5ISksf6Q5imvnsGNfVXEyMqYHtmPODVZLk8iEv68q3e2Fk6KvB8cZxTbSJgDX7diLs9tC48grSzM2kZL1EC2FCiCO/OPee7QHWbUnvQ2R8/twfKFfh+QRPgxlUJLdaxGEMQqFtWK4RdpoicAy9AfIo= 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=P10K3Ir4; arc=none smtp.client-ip=209.85.221.54 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="P10K3Ir4" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-390dd35c78dso3470515f8f.1 for ; Tue, 04 Mar 2025 01:39:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1741081177; x=1741685977; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Ppg79k4Nqs5dyhQk3VANLrHFFSUqyJzAJGv/n9su4ro=; b=P10K3Ir4CfsfPjwhSzXhYgX1wVY7RRvKxTLmOU2bgugDxUQv7pJG5bl1do5eGT8wxM UtoFVDZvLRkix/MmygJMQC469/vHOywLUoZ9Nu3c3NAiv0kqNd+nEcfco2tcG2XBYw5l o6GHCaD56RhkL+ZR24gcCtiCOwC1da6DHkoJxsDzGx7cxcU94B5wd3WlsbpsIyfa9phq O8XVEJa/ez8ISA+sG9lcjxkLeJ4doN+/XUYiEj7GcyOwna01E0jJs02iWLKEYZYFOnfD HFeBc+7cJy5I0/Npf4CS5XtoH78NdRnOSrfvoadgtXZVB/n12JQkRXwdNlB9Dsd04R8Q cCOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741081177; x=1741685977; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ppg79k4Nqs5dyhQk3VANLrHFFSUqyJzAJGv/n9su4ro=; b=tlCRjJyO3kH+jQeHjkHXVf+jpWSnUphU05n6kjh+NjkBO70RdGbsNuqQwldQLbb6Cy Z/+yZrnwndXI6hjlU+opFDB7gW04If7qaE+BXVN2W9ccYOAvU9jHTzcF4qp/FAzH6vbT ogPlK6LCSZ4c59daKBHMtB5FpuYenVo/n+WnVoBotjWOLAWa3H6UVVRTxOA4Z+IJnoEe EJzE095sQDjXjKg4pp8KlXusWDxz/S46Tt79glmQlENtzq29BSAtReLbzRHBwNz05Lul 86B0Z6D/T09vca7mpCtENm7p1qG0cBVSdHqpATArXlHf0W9nGT8foNP51q5sm+vFkPKu AZ5A== X-Forwarded-Encrypted: i=1; AJvYcCVIBlEburS19tPYXF0/CiLDq7+NXiMbXhAsA3wnX85j3JavBCZslv57AcYBfhzDHqIWua9ZF+AoCh+B4PA=@vger.kernel.org X-Gm-Message-State: AOJu0YwVPva+gQ1DLyOa6BqgBCc8l9wHbSzwiRnDj6zG0Shg0tMrbTiZ scehCbRn2gPZWSWwuIASDIenzGU+Mr1K0XjJQevy1eAmYyxABa1MVNLhuiegwsM= X-Gm-Gg: ASbGncuH3jNB4NQzEQWlrznxp79uzbDK5QpUIGO2Jh8axclhC9uXzdskiGCcN1YNMaP W6I4mluAmIrQ6P1dQJIeyBWxa1htZCI17pf9RV89RexN14dK/0v5d16BoFISOW/hH4t/8tyaHvT RtT3q/bglSBoHkQMBAf0E7PKap07LQe7OHgpbBJDVxoz2/VS5SST14nEiIvuq91nw9I9DMPPVTS 1EXnsG5PzKyYxbMrwY0EoR8F1TibSGtDgGIAZtX0Sdh5rA8legj4eQauWHHcKOJ/+u/1LPZ6uB3 Dpk6j2+s2A6sDDSvAMVCzz9KCGBAVPeX45WtJC2KlWf50te5L3ioziUFjfXDGHBQyrmRBDUBbWA NVKqNlEEV8da/bsGUP3i2/zRGiJatbWpAZg== X-Google-Smtp-Source: AGHT+IGzrC2x+eW3lKqtmNmvxi8Yw3N0w0fNWe4dQJ5JNIqHcOKJwl/5wcjsaA+G0cvhyV2oDNb6Vg== X-Received: by 2002:a5d:47af:0:b0:390:df83:1f22 with SMTP id ffacd0b85a97d-39115627f82mr2195463f8f.25.1741081177460; Tue, 04 Mar 2025 01:39:37 -0800 (PST) Received: from [10.2.5.157] (amontpellier-556-1-148-206.w109-210.abo.wanadoo.fr. [109.210.4.206]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e47b7ddesm17307844f8f.57.2025.03.04.01.39.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 01:39:36 -0800 (PST) From: Angelo Dureghello Date: Tue, 04 Mar 2025 10:37:50 +0100 Subject: [PATCH v2 1/2] iio: ad7380: add support for SPI offload 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 Message-Id: <20250304-wip-bl-spi-offload-ad7380-v2-1-0fef61f2650a@baylibre.com> References: <20250304-wip-bl-spi-offload-ad7380-v2-0-0fef61f2650a@baylibre.com> In-Reply-To: <20250304-wip-bl-spi-offload-ad7380-v2-0-0fef61f2650a@baylibre.com> To: Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , David Lechner , Jonathan Corbet Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Angelo Dureghello X-Mailer: b4 0.14.2 Add support for SPI offload to the ad7380 driver. SPI offload allows sampling data at the max sample rate (2MSPS with one SDO line). This is developed and tested against the ADI example FPGA design for this family of ADCs [1]. [1]: http://analogdevicesinc.github.io/hdl/projects/ad738x_fmc/index.html Signed-off-by: Angelo Dureghello --- drivers/iio/adc/Kconfig | 2 + drivers/iio/adc/ad7380.c | 509 +++++++++++++++++++++++++++++++++++++++++++= ---- 2 files changed, 475 insertions(+), 36 deletions(-) diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 27413516216cb3f83cf1d995b9ffc22bf01776a4..c528f4632c0ef6782269d8afa89= c17d2046d28a3 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -218,7 +218,9 @@ config AD7298 config AD7380 tristate "Analog Devices AD7380 ADC driver" depends on SPI_MASTER + select SPI_OFFLOAD select IIO_BUFFER + select IIO_BUFFER_DMAENGINE select IIO_TRIGGER select IIO_TRIGGERED_BUFFER help diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c index f232ad1a49634baeedc655916bc7a967604a1206..39a5e55fa7e8a6706e15750d07f= a4b0fda7175eb 100644 --- a/drivers/iio/adc/ad7380.c +++ b/drivers/iio/adc/ad7380.c @@ -15,6 +15,9 @@ * ad7386/7/8-4 : https://www.analog.com/media/en/technical-documentation/= data-sheets/ad7386-4-7387-4-7388-4.pdf * adaq4370-4 : https://www.analog.com/media/en/technical-documentation/da= ta-sheets/adaq4370-4.pdf * adaq4380-4 : https://www.analog.com/media/en/technical-documentation/da= ta-sheets/adaq4380-4.pdf + * + * HDL ad738x_fmc: https://analogdevicesinc.github.io/hdl/projects/ad738x_= fmc/index.html + * */ =20 #include @@ -29,11 +32,13 @@ #include #include #include +#include #include #include #include =20 #include +#include #include #include #include @@ -92,6 +97,12 @@ #define AD7380_NUM_SDO_LINES 1 #define AD7380_DEFAULT_GAIN_MILLI 1000 =20 +/* + * Using SPI offload, storagebits is always 32, so can't be used to comput= e struct + * spi_transfer.len. Using realbits instead. + */ +#define AD7380_SPI_BYTES(scan_type) ((scan_type)->realbits > 16 ? 4 : 2) + struct ad7380_timing_specs { const unsigned int t_csh_ns; /* CS minimum high time */ }; @@ -99,6 +110,7 @@ struct ad7380_timing_specs { struct ad7380_chip_info { const char *name; const struct iio_chan_spec *channels; + const struct iio_chan_spec *offload_channels; unsigned int num_channels; unsigned int num_simult_channels; bool has_hardware_gain; @@ -111,6 +123,7 @@ struct ad7380_chip_info { unsigned int num_vcm_supplies; const unsigned long *available_scan_masks; const struct ad7380_timing_specs *timing_specs; + u32 max_conversion_rate_hz; }; =20 static const struct iio_event_spec ad7380_events[] =3D { @@ -216,6 +229,91 @@ static const struct iio_scan_type ad7380_scan_type_16_= u[] =3D { }, }; =20 +/* + * Defining here scan types for offload mode, since with current available= HDL + * only a value of 32 for storagebits is supported. + */ + +/* Extended scan types for 12-bit unsigned chips, offload support. */ +static const struct iio_scan_type ad7380_scan_type_12_u_offload[] =3D { + [AD7380_SCAN_TYPE_NORMAL] =3D { + .sign =3D 'u', + .realbits =3D 12, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, + [AD7380_SCAN_TYPE_RESOLUTION_BOOST] =3D { + .sign =3D 'u', + .realbits =3D 14, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, +}; + +/* Extended scan types for 14-bit signed chips, offload support. */ +static const struct iio_scan_type ad7380_scan_type_14_s_offload[] =3D { + [AD7380_SCAN_TYPE_NORMAL] =3D { + .sign =3D 's', + .realbits =3D 14, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, + [AD7380_SCAN_TYPE_RESOLUTION_BOOST] =3D { + .sign =3D 's', + .realbits =3D 16, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, +}; + +/* Extended scan types for 14-bit unsigned chips, offload support. */ +static const struct iio_scan_type ad7380_scan_type_14_u_offload[] =3D { + [AD7380_SCAN_TYPE_NORMAL] =3D { + .sign =3D 'u', + .realbits =3D 14, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, + [AD7380_SCAN_TYPE_RESOLUTION_BOOST] =3D { + .sign =3D 'u', + .realbits =3D 16, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, +}; + +/* Extended scan types for 16-bit signed_chips, offload support. */ +static const struct iio_scan_type ad7380_scan_type_16_s_offload[] =3D { + [AD7380_SCAN_TYPE_NORMAL] =3D { + .sign =3D 's', + .realbits =3D 16, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, + [AD7380_SCAN_TYPE_RESOLUTION_BOOST] =3D { + .sign =3D 's', + .realbits =3D 18, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, +}; + +/* Extended scan types for 16-bit unsigned chips, offload support. */ +static const struct iio_scan_type ad7380_scan_type_16_u_offload[] =3D { + [AD7380_SCAN_TYPE_NORMAL] =3D { + .sign =3D 'u', + .realbits =3D 16, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, + [AD7380_SCAN_TYPE_RESOLUTION_BOOST] =3D { + .sign =3D 'u', + .realbits =3D 18, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, +}; + #define _AD7380_CHANNEL(index, bits, diff, sign, gain) { \ .type =3D IIO_VOLTAGE, \ .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | \ @@ -237,48 +335,123 @@ static const struct iio_scan_type ad7380_scan_type_1= 6_u[] =3D { .num_event_specs =3D ARRAY_SIZE(ad7380_events), \ } =20 +#define _AD7380_OFFLOAD_CHANNEL(index, bits, diff, sign, gain) { \ + .type =3D IIO_VOLTAGE, \ + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | = \ + ((gain) ? BIT(IIO_CHAN_INFO_SCALE) : 0) | \ + ((diff) ? 0 : BIT(IIO_CHAN_INFO_OFFSET)), \ + .info_mask_shared_by_type =3D ((gain) ? 0 : BIT(IIO_CHAN_INFO_SCALE)) | = \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .info_mask_shared_by_type_available =3D \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .indexed =3D 1, = \ + .differential =3D (diff), = \ + .channel =3D (diff) ? (2 * (index)) : (index), = \ + .channel2 =3D (diff) ? (2 * (index) + 1) : 0, = \ + .scan_index =3D (index), = \ + .has_ext_scan_type =3D 1, = \ + .ext_scan_type =3D ad7380_scan_type_##bits##_##sign##_offload, = \ + .num_ext_scan_type =3D = \ + ARRAY_SIZE(ad7380_scan_type_##bits##_##sign##_offload), \ + .event_spec =3D ad7380_events, = \ + .num_event_specs =3D ARRAY_SIZE(ad7380_events), = \ +} + +/* + * Notes on the offload channels: + * - There is no soft timestamp since everything is done in hardware. + * - There is a sampling frequency attribute added. This controls the SPI + * offload trigger. + * - The storagebits value depends on the SPI offload provider. Currently = there + * is only one supported provider, namely the ADI PULSAR ADC HDL project, + * which always uses 32-bit words for data values, even for <=3D 16-bit = ADCs. + * So the value is just hardcoded to 32 for now. + */ + #define AD7380_CHANNEL(index, bits, diff, sign) \ _AD7380_CHANNEL(index, bits, diff, sign, false) =20 #define ADAQ4380_CHANNEL(index, bits, diff, sign) \ _AD7380_CHANNEL(index, bits, diff, sign, true) =20 -#define DEFINE_AD7380_2_CHANNEL(name, bits, diff, sign) \ +#define DEFINE_AD7380_2_CHANNEL(name, bits, diff, sign) \ +static const struct iio_chan_spec name[] =3D { \ + AD7380_CHANNEL(0, bits, diff, sign), \ + AD7380_CHANNEL(1, bits, diff, sign), \ + IIO_CHAN_SOFT_TIMESTAMP(2), \ +} + +#define DEFINE_AD7380_4_CHANNEL(name, bits, diff, sign) \ +static const struct iio_chan_spec name[] =3D { \ + AD7380_CHANNEL(0, bits, diff, sign), \ + AD7380_CHANNEL(1, bits, diff, sign), \ + AD7380_CHANNEL(2, bits, diff, sign), \ + AD7380_CHANNEL(3, bits, diff, sign), \ + IIO_CHAN_SOFT_TIMESTAMP(4), \ +} + +#define DEFINE_ADAQ4380_4_CHANNEL(name, bits, diff, sign) \ +static const struct iio_chan_spec name[] =3D { \ + ADAQ4380_CHANNEL(0, bits, diff, sign), \ + ADAQ4380_CHANNEL(1, bits, diff, sign), \ + ADAQ4380_CHANNEL(2, bits, diff, sign), \ + ADAQ4380_CHANNEL(3, bits, diff, sign), \ + IIO_CHAN_SOFT_TIMESTAMP(4), \ +} + +#define DEFINE_AD7380_8_CHANNEL(name, bits, diff, sign) \ +static const struct iio_chan_spec name[] =3D { \ + AD7380_CHANNEL(0, bits, diff, sign), \ + AD7380_CHANNEL(1, bits, diff, sign), \ + AD7380_CHANNEL(2, bits, diff, sign), \ + AD7380_CHANNEL(3, bits, diff, sign), \ + AD7380_CHANNEL(4, bits, diff, sign), \ + AD7380_CHANNEL(5, bits, diff, sign), \ + AD7380_CHANNEL(6, bits, diff, sign), \ + AD7380_CHANNEL(7, bits, diff, sign), \ + IIO_CHAN_SOFT_TIMESTAMP(8), \ +} + +#define AD7380_OFFLOAD_CHANNEL(index, bits, diff, sign) \ +_AD7380_OFFLOAD_CHANNEL(index, bits, diff, sign, false) + +#define ADAQ4380_OFFLOAD_CHANNEL(index, bits, diff, sign) \ +_AD7380_OFFLOAD_CHANNEL(index, bits, diff, sign, true) + +#define DEFINE_AD7380_2_OFFLOAD_CHANNEL(name, bits, diff, sign) \ static const struct iio_chan_spec name[] =3D { \ - AD7380_CHANNEL(0, bits, diff, sign), \ - AD7380_CHANNEL(1, bits, diff, sign), \ - IIO_CHAN_SOFT_TIMESTAMP(2), \ + AD7380_OFFLOAD_CHANNEL(0, bits, diff, sign), \ + AD7380_OFFLOAD_CHANNEL(1, bits, diff, sign), \ } =20 -#define DEFINE_AD7380_4_CHANNEL(name, bits, diff, sign) \ +#define DEFINE_AD7380_4_OFFLOAD_CHANNEL(name, bits, diff, sign) \ static const struct iio_chan_spec name[] =3D { \ - AD7380_CHANNEL(0, bits, diff, sign), \ - AD7380_CHANNEL(1, bits, diff, sign), \ - AD7380_CHANNEL(2, bits, diff, sign), \ - AD7380_CHANNEL(3, bits, diff, sign), \ - IIO_CHAN_SOFT_TIMESTAMP(4), \ + AD7380_OFFLOAD_CHANNEL(0, bits, diff, sign), \ + AD7380_OFFLOAD_CHANNEL(1, bits, diff, sign), \ + AD7380_OFFLOAD_CHANNEL(2, bits, diff, sign), \ + AD7380_OFFLOAD_CHANNEL(3, bits, diff, sign), \ } =20 -#define DEFINE_ADAQ4380_4_CHANNEL(name, bits, diff, sign) \ -static const struct iio_chan_spec name[] =3D { \ - ADAQ4380_CHANNEL(0, bits, diff, sign), \ - ADAQ4380_CHANNEL(1, bits, diff, sign), \ - ADAQ4380_CHANNEL(2, bits, diff, sign), \ - ADAQ4380_CHANNEL(3, bits, diff, sign), \ - IIO_CHAN_SOFT_TIMESTAMP(4), \ +#define DEFINE_ADAQ4380_4_OFFLOAD_CHANNEL(name, bits, diff, sign) \ +static const struct iio_chan_spec name[] =3D { \ + AD7380_OFFLOAD_CHANNEL(0, bits, diff, sign), \ + AD7380_OFFLOAD_CHANNEL(1, bits, diff, sign), \ + AD7380_OFFLOAD_CHANNEL(2, bits, diff, sign), \ + AD7380_OFFLOAD_CHANNEL(3, bits, diff, sign), \ } =20 -#define DEFINE_AD7380_8_CHANNEL(name, bits, diff, sign) \ +#define DEFINE_AD7380_8_OFFLOAD_CHANNEL(name, bits, diff, sign) \ static const struct iio_chan_spec name[] =3D { \ - AD7380_CHANNEL(0, bits, diff, sign), \ - AD7380_CHANNEL(1, bits, diff, sign), \ - AD7380_CHANNEL(2, bits, diff, sign), \ - AD7380_CHANNEL(3, bits, diff, sign), \ - AD7380_CHANNEL(4, bits, diff, sign), \ - AD7380_CHANNEL(5, bits, diff, sign), \ - AD7380_CHANNEL(6, bits, diff, sign), \ - AD7380_CHANNEL(7, bits, diff, sign), \ - IIO_CHAN_SOFT_TIMESTAMP(8), \ + AD7380_OFFLOAD_CHANNEL(0, bits, diff, sign), \ + AD7380_OFFLOAD_CHANNEL(1, bits, diff, sign), \ + AD7380_OFFLOAD_CHANNEL(2, bits, diff, sign), \ + AD7380_OFFLOAD_CHANNEL(3, bits, diff, sign), \ + AD7380_OFFLOAD_CHANNEL(4, bits, diff, sign), \ + AD7380_OFFLOAD_CHANNEL(5, bits, diff, sign), \ + AD7380_OFFLOAD_CHANNEL(6, bits, diff, sign), \ + AD7380_OFFLOAD_CHANNEL(7, bits, diff, sign), \ } =20 /* fully differential */ @@ -301,6 +474,27 @@ DEFINE_AD7380_8_CHANNEL(ad7386_4_channels, 16, 0, u); DEFINE_AD7380_8_CHANNEL(ad7387_4_channels, 14, 0, u); DEFINE_AD7380_8_CHANNEL(ad7388_4_channels, 12, 0, u); =20 +/* offload channels */ +DEFINE_AD7380_2_OFFLOAD_CHANNEL(ad7380_offload_channels, 16, 1, s); +DEFINE_AD7380_2_OFFLOAD_CHANNEL(ad7381_offload_channels, 14, 1, s); +DEFINE_AD7380_4_OFFLOAD_CHANNEL(ad7380_4_offload_channels, 16, 1, s); +DEFINE_AD7380_4_OFFLOAD_CHANNEL(ad7381_4_offload_channels, 14, 1, s); +DEFINE_ADAQ4380_4_OFFLOAD_CHANNEL(adaq4380_4_offload_channels, 16, 1, s); + +/* pseudo differential */ +DEFINE_AD7380_2_OFFLOAD_CHANNEL(ad7383_offload_channels, 16, 0, s); +DEFINE_AD7380_2_OFFLOAD_CHANNEL(ad7384_offload_channels, 14, 0, s); +DEFINE_AD7380_4_OFFLOAD_CHANNEL(ad7383_4_offload_channels, 16, 0, s); +DEFINE_AD7380_4_OFFLOAD_CHANNEL(ad7384_4_offload_channels, 14, 0, s); + +/* Single ended */ +DEFINE_AD7380_4_OFFLOAD_CHANNEL(ad7386_offload_channels, 16, 0, u); +DEFINE_AD7380_4_OFFLOAD_CHANNEL(ad7387_offload_channels, 14, 0, u); +DEFINE_AD7380_4_OFFLOAD_CHANNEL(ad7388_offload_channels, 12, 0, u); +DEFINE_AD7380_8_OFFLOAD_CHANNEL(ad7386_4_offload_channels, 16, 0, u); +DEFINE_AD7380_8_OFFLOAD_CHANNEL(ad7387_4_offload_channels, 14, 0, u); +DEFINE_AD7380_8_OFFLOAD_CHANNEL(ad7388_4_offload_channels, 12, 0, u); + static const char * const ad7380_supplies[] =3D { "vcc", "vlogic", }; @@ -407,28 +601,33 @@ static const int ad7380_gains[] =3D { static const struct ad7380_chip_info ad7380_chip_info =3D { .name =3D "ad7380", .channels =3D ad7380_channels, + .offload_channels =3D ad7380_offload_channels, .num_channels =3D ARRAY_SIZE(ad7380_channels), .num_simult_channels =3D 2, .supplies =3D ad7380_supplies, .num_supplies =3D ARRAY_SIZE(ad7380_supplies), .available_scan_masks =3D ad7380_2_channel_scan_masks, .timing_specs =3D &ad7380_timing, + .max_conversion_rate_hz =3D 4 * MEGA, }; =20 static const struct ad7380_chip_info ad7381_chip_info =3D { .name =3D "ad7381", .channels =3D ad7381_channels, + .offload_channels =3D ad7381_offload_channels, .num_channels =3D ARRAY_SIZE(ad7381_channels), .num_simult_channels =3D 2, .supplies =3D ad7380_supplies, .num_supplies =3D ARRAY_SIZE(ad7380_supplies), .available_scan_masks =3D ad7380_2_channel_scan_masks, .timing_specs =3D &ad7380_timing, + .max_conversion_rate_hz =3D 4 * MEGA, }; =20 static const struct ad7380_chip_info ad7383_chip_info =3D { .name =3D "ad7383", .channels =3D ad7383_channels, + .offload_channels =3D ad7383_offload_channels, .num_channels =3D ARRAY_SIZE(ad7383_channels), .num_simult_channels =3D 2, .supplies =3D ad7380_supplies, @@ -437,11 +636,13 @@ static const struct ad7380_chip_info ad7383_chip_info= =3D { .num_vcm_supplies =3D ARRAY_SIZE(ad7380_2_channel_vcm_supplies), .available_scan_masks =3D ad7380_2_channel_scan_masks, .timing_specs =3D &ad7380_timing, + .max_conversion_rate_hz =3D 4 * MEGA, }; =20 static const struct ad7380_chip_info ad7384_chip_info =3D { .name =3D "ad7384", .channels =3D ad7384_channels, + .offload_channels =3D ad7384_offload_channels, .num_channels =3D ARRAY_SIZE(ad7384_channels), .num_simult_channels =3D 2, .supplies =3D ad7380_supplies, @@ -450,11 +651,13 @@ static const struct ad7380_chip_info ad7384_chip_info= =3D { .num_vcm_supplies =3D ARRAY_SIZE(ad7380_2_channel_vcm_supplies), .available_scan_masks =3D ad7380_2_channel_scan_masks, .timing_specs =3D &ad7380_timing, + .max_conversion_rate_hz =3D 4 * MEGA, }; =20 static const struct ad7380_chip_info ad7386_chip_info =3D { .name =3D "ad7386", .channels =3D ad7386_channels, + .offload_channels =3D ad7386_offload_channels, .num_channels =3D ARRAY_SIZE(ad7386_channels), .num_simult_channels =3D 2, .supplies =3D ad7380_supplies, @@ -462,11 +665,13 @@ static const struct ad7380_chip_info ad7386_chip_info= =3D { .has_mux =3D true, .available_scan_masks =3D ad7380_2x2_channel_scan_masks, .timing_specs =3D &ad7380_timing, + .max_conversion_rate_hz =3D 4 * MEGA, }; =20 static const struct ad7380_chip_info ad7387_chip_info =3D { .name =3D "ad7387", .channels =3D ad7387_channels, + .offload_channels =3D ad7387_offload_channels, .num_channels =3D ARRAY_SIZE(ad7387_channels), .num_simult_channels =3D 2, .supplies =3D ad7380_supplies, @@ -474,11 +679,13 @@ static const struct ad7380_chip_info ad7387_chip_info= =3D { .has_mux =3D true, .available_scan_masks =3D ad7380_2x2_channel_scan_masks, .timing_specs =3D &ad7380_timing, + .max_conversion_rate_hz =3D 4 * MEGA, }; =20 static const struct ad7380_chip_info ad7388_chip_info =3D { .name =3D "ad7388", .channels =3D ad7388_channels, + .offload_channels =3D ad7388_offload_channels, .num_channels =3D ARRAY_SIZE(ad7388_channels), .num_simult_channels =3D 2, .supplies =3D ad7380_supplies, @@ -486,11 +693,13 @@ static const struct ad7380_chip_info ad7388_chip_info= =3D { .has_mux =3D true, .available_scan_masks =3D ad7380_2x2_channel_scan_masks, .timing_specs =3D &ad7380_timing, + .max_conversion_rate_hz =3D 4 * MEGA, }; =20 static const struct ad7380_chip_info ad7380_4_chip_info =3D { .name =3D "ad7380-4", .channels =3D ad7380_4_channels, + .offload_channels =3D ad7380_4_offload_channels, .num_channels =3D ARRAY_SIZE(ad7380_4_channels), .num_simult_channels =3D 4, .supplies =3D ad7380_supplies, @@ -498,22 +707,26 @@ static const struct ad7380_chip_info ad7380_4_chip_in= fo =3D { .external_ref_only =3D true, .available_scan_masks =3D ad7380_4_channel_scan_masks, .timing_specs =3D &ad7380_4_timing, + .max_conversion_rate_hz =3D 4 * MEGA, }; =20 static const struct ad7380_chip_info ad7381_4_chip_info =3D { .name =3D "ad7381-4", .channels =3D ad7381_4_channels, + .offload_channels =3D ad7381_4_offload_channels, .num_channels =3D ARRAY_SIZE(ad7381_4_channels), .num_simult_channels =3D 4, .supplies =3D ad7380_supplies, .num_supplies =3D ARRAY_SIZE(ad7380_supplies), .available_scan_masks =3D ad7380_4_channel_scan_masks, .timing_specs =3D &ad7380_4_timing, + .max_conversion_rate_hz =3D 4 * MEGA, }; =20 static const struct ad7380_chip_info ad7383_4_chip_info =3D { .name =3D "ad7383-4", .channels =3D ad7383_4_channels, + .offload_channels =3D ad7383_4_offload_channels, .num_channels =3D ARRAY_SIZE(ad7383_4_channels), .num_simult_channels =3D 4, .supplies =3D ad7380_supplies, @@ -522,11 +735,13 @@ static const struct ad7380_chip_info ad7383_4_chip_in= fo =3D { .num_vcm_supplies =3D ARRAY_SIZE(ad7380_4_channel_vcm_supplies), .available_scan_masks =3D ad7380_4_channel_scan_masks, .timing_specs =3D &ad7380_4_timing, + .max_conversion_rate_hz =3D 4 * MEGA, }; =20 static const struct ad7380_chip_info ad7384_4_chip_info =3D { .name =3D "ad7384-4", .channels =3D ad7384_4_channels, + .offload_channels =3D ad7384_4_offload_channels, .num_channels =3D ARRAY_SIZE(ad7384_4_channels), .num_simult_channels =3D 4, .supplies =3D ad7380_supplies, @@ -535,11 +750,13 @@ static const struct ad7380_chip_info ad7384_4_chip_in= fo =3D { .num_vcm_supplies =3D ARRAY_SIZE(ad7380_4_channel_vcm_supplies), .available_scan_masks =3D ad7380_4_channel_scan_masks, .timing_specs =3D &ad7380_4_timing, + .max_conversion_rate_hz =3D 4 * MEGA, }; =20 static const struct ad7380_chip_info ad7386_4_chip_info =3D { .name =3D "ad7386-4", .channels =3D ad7386_4_channels, + .offload_channels =3D ad7386_4_offload_channels, .num_channels =3D ARRAY_SIZE(ad7386_4_channels), .num_simult_channels =3D 4, .supplies =3D ad7380_supplies, @@ -547,11 +764,13 @@ static const struct ad7380_chip_info ad7386_4_chip_in= fo =3D { .has_mux =3D true, .available_scan_masks =3D ad7380_2x4_channel_scan_masks, .timing_specs =3D &ad7380_4_timing, + .max_conversion_rate_hz =3D 4 * MEGA, }; =20 static const struct ad7380_chip_info ad7387_4_chip_info =3D { .name =3D "ad7387-4", .channels =3D ad7387_4_channels, + .offload_channels =3D ad7387_4_offload_channels, .num_channels =3D ARRAY_SIZE(ad7387_4_channels), .num_simult_channels =3D 4, .supplies =3D ad7380_supplies, @@ -559,11 +778,13 @@ static const struct ad7380_chip_info ad7387_4_chip_in= fo =3D { .has_mux =3D true, .available_scan_masks =3D ad7380_2x4_channel_scan_masks, .timing_specs =3D &ad7380_4_timing, + .max_conversion_rate_hz =3D 4 * MEGA, }; =20 static const struct ad7380_chip_info ad7388_4_chip_info =3D { .name =3D "ad7388-4", .channels =3D ad7388_4_channels, + .offload_channels =3D ad7388_4_offload_channels, .num_channels =3D ARRAY_SIZE(ad7388_4_channels), .num_simult_channels =3D 4, .supplies =3D ad7380_supplies, @@ -571,11 +792,13 @@ static const struct ad7380_chip_info ad7388_4_chip_in= fo =3D { .has_mux =3D true, .available_scan_masks =3D ad7380_2x4_channel_scan_masks, .timing_specs =3D &ad7380_4_timing, + .max_conversion_rate_hz =3D 4 * MEGA, }; =20 static const struct ad7380_chip_info adaq4370_4_chip_info =3D { .name =3D "adaq4370-4", .channels =3D adaq4380_4_channels, + .offload_channels =3D adaq4380_4_offload_channels, .num_channels =3D ARRAY_SIZE(adaq4380_4_channels), .num_simult_channels =3D 4, .supplies =3D adaq4380_supplies, @@ -584,11 +807,13 @@ static const struct ad7380_chip_info adaq4370_4_chip_= info =3D { .has_hardware_gain =3D true, .available_scan_masks =3D ad7380_4_channel_scan_masks, .timing_specs =3D &ad7380_4_timing, + .max_conversion_rate_hz =3D 2 * MEGA, }; =20 static const struct ad7380_chip_info adaq4380_4_chip_info =3D { .name =3D "adaq4380-4", .channels =3D adaq4380_4_channels, + .offload_channels =3D adaq4380_4_offload_channels, .num_channels =3D ARRAY_SIZE(adaq4380_4_channels), .num_simult_channels =3D 4, .supplies =3D adaq4380_supplies, @@ -597,6 +822,12 @@ static const struct ad7380_chip_info adaq4380_4_chip_i= nfo =3D { .has_hardware_gain =3D true, .available_scan_masks =3D ad7380_4_channel_scan_masks, .timing_specs =3D &ad7380_4_timing, + .max_conversion_rate_hz =3D 4 * MEGA, +}; + +static const struct spi_offload_config ad7380_offload_config =3D { + .capability_flags =3D SPI_OFFLOAD_CAP_TRIGGER | + SPI_OFFLOAD_CAP_RX_STREAM_DMA, }; =20 struct ad7380_state { @@ -614,6 +845,13 @@ struct ad7380_state { struct spi_message normal_msg; struct spi_transfer seq_xfer[4]; struct spi_message seq_msg; + struct spi_transfer offload_xfer; + struct spi_message offload_msg; + struct spi_offload *offload; + struct spi_offload_trigger *offload_trigger; + unsigned long offload_trigger_hz; + + int sample_freq_range[3]; /* * DMA (thus cache coherency maintenance) requires the transfer buffers * to live in their own cache lines. @@ -833,7 +1071,7 @@ static int ad7380_update_xfers(struct ad7380_state *st, xfer[2].bits_per_word =3D xfer[3].bits_per_word =3D scan_type->realbits; xfer[2].len =3D xfer[3].len =3D - BITS_TO_BYTES(scan_type->storagebits) * + AD7380_SPI_BYTES(scan_type) * st->chip_info->num_simult_channels; xfer[3].rx_buf =3D xfer[2].rx_buf + xfer[2].len; /* Additional delay required here when oversampling is enabled */ @@ -846,13 +1084,139 @@ static int ad7380_update_xfers(struct ad7380_state = *st, xfer[0].delay.value =3D t_convert; xfer[0].delay.unit =3D SPI_DELAY_UNIT_NSECS; xfer[1].bits_per_word =3D scan_type->realbits; - xfer[1].len =3D BITS_TO_BYTES(scan_type->storagebits) * + xfer[1].len =3D AD7380_SPI_BYTES(scan_type) * st->chip_info->num_simult_channels; } =20 return 0; } =20 +static int ad7380_set_sample_freq(struct ad7380_state *st, int val) +{ + struct spi_offload_trigger_config config =3D { + .type =3D SPI_OFFLOAD_TRIGGER_PERIODIC, + .periodic =3D { + .frequency_hz =3D val, + }, + }; + int ret; + + ret =3D spi_offload_trigger_validate(st->offload_trigger, &config); + if (ret) + return ret; + + st->offload_trigger_hz =3D config.periodic.frequency_hz; + + return 0; +} + +static int ad7380_init_offload_msg(struct ad7380_state *st, + struct iio_dev *indio_dev) +{ + struct spi_transfer *xfer =3D &st->offload_xfer; + struct device *dev =3D &st->spi->dev; + const struct iio_scan_type *scan_type; + int oversampling_ratio; + int ret; + + scan_type =3D iio_get_current_scan_type(indio_dev, + &indio_dev->channels[0]); + if (IS_ERR(scan_type)) + return PTR_ERR(scan_type); + + if (st->chip_info->has_mux) { + int index; + + ret =3D iio_active_scan_mask_index(indio_dev); + if (ret < 0) + return ret; + + index =3D ret; + if (index =3D=3D AD7380_SCAN_MASK_SEQ) { + ret =3D regmap_set_bits(st->regmap, AD7380_REG_ADDR_CONFIG1, + AD7380_CONFIG1_SEQ); + if (ret) + return ret; + + st->seq =3D true; + } else { + ret =3D ad7380_set_ch(st, index); + if (ret) + return ret; + } + } + + ret =3D ad7380_get_osr(st, &oversampling_ratio); + if (ret) + return ret; + + xfer->bits_per_word =3D scan_type->realbits; + xfer->offload_flags =3D SPI_OFFLOAD_XFER_RX_STREAM; + xfer->len =3D AD7380_SPI_BYTES(scan_type) * st->chip_info->num_simult_cha= nnels; + + spi_message_init_with_transfers(&st->offload_msg, xfer, 1); + st->offload_msg.offload =3D st->offload; + + ret =3D spi_optimize_message(st->spi, &st->offload_msg); + if (ret) { + dev_err(dev, "failed to prepare offload msg, err: %d\n", + ret); + return ret; + } + + return 0; +} + +static int ad7380_offload_buffer_postenable(struct iio_dev *indio_dev) +{ + struct ad7380_state *st =3D iio_priv(indio_dev); + struct spi_offload_trigger_config config =3D { + .type =3D SPI_OFFLOAD_TRIGGER_PERIODIC, + .periodic =3D { + .frequency_hz =3D st->offload_trigger_hz, + }, + }; + int ret; + + ret =3D ad7380_init_offload_msg(st, indio_dev); + if (ret) + return ret; + + ret =3D spi_offload_trigger_enable(st->offload, st->offload_trigger, &con= fig); + if (ret) + spi_unoptimize_message(&st->offload_msg); + + return ret; +} + +static int ad7380_offload_buffer_predisable(struct iio_dev *indio_dev) +{ + struct ad7380_state *st =3D iio_priv(indio_dev); + int ret; + + if (st->seq) { + ret =3D regmap_update_bits(st->regmap, + AD7380_REG_ADDR_CONFIG1, + AD7380_CONFIG1_SEQ, + FIELD_PREP(AD7380_CONFIG1_SEQ, 0)); + if (ret) + return ret; + + st->seq =3D false; + } + + spi_offload_trigger_disable(st->offload, st->offload_trigger); + + spi_unoptimize_message(&st->offload_msg); + + return 0; +} + +static const struct iio_buffer_setup_ops ad7380_offload_buffer_setup_ops = =3D { + .postenable =3D ad7380_offload_buffer_postenable, + .predisable =3D ad7380_offload_buffer_predisable, +}; + static int ad7380_triggered_buffer_preenable(struct iio_dev *indio_dev) { struct ad7380_state *st =3D iio_priv(indio_dev); @@ -983,7 +1347,7 @@ static int ad7380_read_direct(struct ad7380_state *st,= unsigned int scan_index, if (ret < 0) return ret; =20 - if (scan_type->storagebits > 16) { + if (scan_type->realbits > 16) { if (scan_type->sign =3D=3D 's') *val =3D sign_extend32(*(u32 *)(st->scan_data + 4 * index), scan_type->realbits - 1); @@ -1064,6 +1428,9 @@ static int ad7380_read_raw(struct iio_dev *indio_dev, if (ret) return ret; =20 + return IIO_VAL_INT; + case IIO_CHAN_INFO_SAMP_FREQ: + *val =3D st->offload_trigger_hz; return IIO_VAL_INT; default: return -EINVAL; @@ -1075,6 +1442,8 @@ static int ad7380_read_avail(struct iio_dev *indio_de= v, const int **vals, int *type, int *length, long mask) { + struct ad7380_state *st =3D iio_priv(indio_dev); + switch (mask) { case IIO_CHAN_INFO_OVERSAMPLING_RATIO: *vals =3D ad7380_oversampling_ratios; @@ -1082,6 +1451,10 @@ static int ad7380_read_avail(struct iio_dev *indio_d= ev, *type =3D IIO_VAL_INT; =20 return IIO_AVAIL_LIST; + case IIO_CHAN_INFO_SAMP_FREQ: + *vals =3D st->sample_freq_range; + *type =3D IIO_VAL_INT; + return IIO_AVAIL_RANGE; default: return -EINVAL; } @@ -1151,6 +1524,10 @@ static int ad7380_write_raw(struct iio_dev *indio_de= v, int ret; =20 switch (mask) { + case IIO_CHAN_INFO_SAMP_FREQ: + if (val < 1) + return -EINVAL; + return ad7380_set_sample_freq(st, val); case IIO_CHAN_INFO_OVERSAMPLING_RATIO: if (!iio_device_claim_direct(indio_dev)) return -EBUSY; @@ -1380,6 +1757,53 @@ static int ad7380_init(struct ad7380_state *st, bool= external_ref_en) AD7380_NUM_SDO_LINES)); } =20 +static int ad7380_probe_spi_offload(struct iio_dev *indio_dev, + struct ad7380_state *st) +{ + struct spi_device *spi =3D st->spi; + struct device *dev =3D &spi->dev; + struct dma_chan *rx_dma; + int sample_rate, ret; + + indio_dev->setup_ops =3D &ad7380_offload_buffer_setup_ops; + indio_dev->channels =3D st->chip_info->offload_channels; + /* Just removing the timestamp channel. */ + indio_dev->num_channels--; + + st->offload_trigger =3D devm_spi_offload_trigger_get(dev, st->offload, + SPI_OFFLOAD_TRIGGER_PERIODIC); + if (IS_ERR(st->offload_trigger)) + return dev_err_probe(dev, PTR_ERR(st->offload_trigger), + "failed to get offload trigger\n"); + + sample_rate =3D st->chip_info->max_conversion_rate_hz * + AD7380_NUM_SDO_LINES / st->chip_info->num_simult_channels; + + st->sample_freq_range[0] =3D 1; /* min */ + st->sample_freq_range[1] =3D 1; /* step */ + st->sample_freq_range[2] =3D sample_rate; /* max */ + + /* + * Starting with a quite low frequency, to allow oversampling x32, + * user is then reponsible to adjust the frequency for the specific case. + */ + ret =3D ad7380_set_sample_freq(st, sample_rate / 32); + if (ret) + return ret; + + rx_dma =3D devm_spi_offload_rx_stream_request_dma_chan(dev, st->offload); + if (IS_ERR(rx_dma)) + return dev_err_probe(dev, PTR_ERR(rx_dma), + "failed to get offload RX DMA\n"); + + ret =3D devm_iio_dmaengine_buffer_setup_with_handle(dev, indio_dev, + rx_dma, IIO_BUFFER_DIRECTION_IN); + if (ret) + return dev_err_probe(dev, ret, "cannot setup dma buffer\n"); + + return 0; +} + static int ad7380_probe(struct spi_device *spi) { struct device *dev =3D &spi->dev; @@ -1551,12 +1975,24 @@ static int ad7380_probe(struct spi_device *spi) indio_dev->modes =3D INDIO_DIRECT_MODE; indio_dev->available_scan_masks =3D st->chip_info->available_scan_masks; =20 - ret =3D devm_iio_triggered_buffer_setup(dev, indio_dev, - iio_pollfunc_store_time, - ad7380_trigger_handler, - &ad7380_buffer_setup_ops); - if (ret) - return ret; + st->offload =3D devm_spi_offload_get(dev, spi, &ad7380_offload_config); + ret =3D PTR_ERR_OR_ZERO(st->offload); + if (ret && ret !=3D -ENODEV) + return dev_err_probe(dev, ret, "failed to get offload\n"); + + /* If no SPI offload, fall back to low speed usage. */ + if (ret =3D=3D -ENODEV) { + ret =3D devm_iio_triggered_buffer_setup(dev, indio_dev, + iio_pollfunc_store_time, + ad7380_trigger_handler, + &ad7380_buffer_setup_ops); + if (ret) + return ret; + } else { + ret =3D ad7380_probe_spi_offload(indio_dev, st); + if (ret) + return ret; + } =20 ret =3D ad7380_init(st, external_ref_en); if (ret) @@ -1619,3 +2055,4 @@ module_spi_driver(ad7380_driver); MODULE_AUTHOR("Stefan Popa "); MODULE_DESCRIPTION("Analog Devices AD738x ADC driver"); MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS("IIO_DMAENGINE_BUFFER"); --=20 2.48.1 From nobody Mon Feb 9 14:37:26 2026 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89B0B1FF1A7 for ; Tue, 4 Mar 2025 09:39:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741081183; cv=none; b=XkPPh9jLriY2AMfNPGBdTW+z3SMw2fNOEK1wgamm/7QqPe7YBnQEXuqBWIWSNMV0XY1J9GWAIipNXp9c5W+oDjqoDh/Xn/Tv5WfK9DcvPTglcu/yaaCNR3AQ2EuCDnGn6ijzPCv6QZ1zg26HV0mqZH6UAJaNpwNzbKb9GUJBpGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741081183; c=relaxed/simple; bh=ZXzmpb4axwe5e+KmC+wKSRDPy9USmDbFe7MNC5wo4Dc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nIG/Pui2PGVhFYudaC1hAQl+kWKpDk0aKb9TUqJ0ibV0QKzeiiEprTt4/3itKx8N5OagO7Tl9tiaOEfLd3eaMUmYZd1c60txUZMEJRsYdSfc9mtQczSE3fO7iNpru4oABDcjIza0adcBVUF3hDaDWk+vxv+mrAIHFajqWSzHrt8= 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=LKLawjV7; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="LKLawjV7" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-390e3b3d3bcso6412806f8f.3 for ; Tue, 04 Mar 2025 01:39:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1741081179; x=1741685979; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=PzkM1CNNQnYlbfs6JoNQ+Yr5xlry9PSvlEEig9xhArk=; b=LKLawjV7AIYB1Dn4KIboRFFGQj7j/50uL+aCGqG4EVpkh0UsvexDVWmVyR2N49T7Hm mYcwgKPoKzq1n8pHLsObgeEtHGgiUPRqLbxQIqCBC9+BZX8J6Ku0csPBoU57EiLgoQvS JSSKV6LOU03PhRkVbt/lmeZKI4UyH+7F4RsRcycrWO3VgFFbZXXMlWQVqArctN/VqHuS vrFByc+VKhjFum4iX0OZROWeUTqmZxpTy8K9FKBN97ZALainTsnErYkDpMiVtwH+xGMc yxd6KeMHuwcBtsEk5/nBsTMDM/P+BEJ79OaejtsQZbCYYsvcKWjv/57+sZYyasRY8loM wA0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741081179; x=1741685979; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PzkM1CNNQnYlbfs6JoNQ+Yr5xlry9PSvlEEig9xhArk=; b=pAhCpeSf7tYkUGRNtbx1kyqDpeUmGngaaj8R6ffpp6671zC25JN6RGTh/wXDxdsdO7 A01/Y+GkjtBybP7A0tupfEdvuEbrWfmMr2dANhNquy+r6mloYY1pfvrtKJ4AUIcyFfsM 8gW11BkNVnth5LrF5/A66jGNFCv6P1TSK9j1KMy7pg9lwLu8KjdU0dKiBrqIV7OQAvUZ /8ulz/5uhIVrgB9jzXl9nIr6k0Wh3UyfUPrG4POgOpn3KtdLAbfbMsp72PzeDul85VMQ hgras5CXa6OQdhXhsyx+VbHlb9+0KhR/OlxHecDZO2gtkEseHeEdxstkcw9B2BHSgqHC 09Wg== X-Forwarded-Encrypted: i=1; AJvYcCXI28fugMv7YdEsNp3VpckkRGttavUNP2CDOqzq6sTDxm0/0fCNC96Wnljg0pudmv+j5rnoam2YsQzEBOw=@vger.kernel.org X-Gm-Message-State: AOJu0YwNf2GBeXDVej5eZDuFuM4JLA9NDlpnCTzKFfxK4w9cCBRuah2a G2cxCf6iJqrcdix1nHVbRpZ1PzNid/SfeIv37kmxfBrQpin73bHO0dyNr25CDxU= X-Gm-Gg: ASbGncuvJ6TyzK9eBW/B09Hbm8dms+ixza4mPgQYKV9qEr+8d9/PyHxqh3uvaZ42B2X 1VB7yr7RHTXQHQVtzTBfRGI2bNfG3T7LiTTzyvk6It2b+4R0O8F7vPw8mDlTJvVxHkHtH/U4tnO URoY7xRhQo8SPrDP5e6co1I2sImfmOzyB/VIF2zNpIpeGsxbmucbQQlZV9VGhfHBeJ9iu9gsd// Y/hVC1D4w+526dJlIkFfxHwW7NStcjG89I1Y+yEefz+24mCY7N990KHD29zM4PZLZk7NcKeFAUj /Y3f2iNBdhHbT9kRJoBS+NCY07fpGshbGzYGy9lV2BfuB6TykkFTbNpIjEiZdST427VddfEvWhJ odZDYgg+mY12fB7iscghweQ6PcXA4T2pQfw== X-Google-Smtp-Source: AGHT+IGP8/XNJEym12siW12OXb4Z12lWgJwu5ud44/xI6+DcmWzTDDMlA/u9XUQdHWGyyJpPjSs+9A== X-Received: by 2002:a05:6000:1847:b0:390:fc5a:91c8 with SMTP id ffacd0b85a97d-390fc5a9e2emr10725079f8f.53.1741081178818; Tue, 04 Mar 2025 01:39:38 -0800 (PST) Received: from [10.2.5.157] (amontpellier-556-1-148-206.w109-210.abo.wanadoo.fr. [109.210.4.206]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e47b7ddesm17307844f8f.57.2025.03.04.01.39.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 01:39:38 -0800 (PST) From: Angelo Dureghello Date: Tue, 04 Mar 2025 10:37:51 +0100 Subject: [PATCH v2 2/2] docs: iio: ad7380: add SPI offload support 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 Message-Id: <20250304-wip-bl-spi-offload-ad7380-v2-2-0fef61f2650a@baylibre.com> References: <20250304-wip-bl-spi-offload-ad7380-v2-0-0fef61f2650a@baylibre.com> In-Reply-To: <20250304-wip-bl-spi-offload-ad7380-v2-0-0fef61f2650a@baylibre.com> To: Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , David Lechner , Jonathan Corbet Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Angelo Dureghello X-Mailer: b4 0.14.2 Document SPI offload support for the ad7380 driver. Signed-off-by: Angelo Dureghello --- Documentation/iio/ad7380.rst | 54 +++++++++++++++++++++++++++++++++++-----= ---- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/Documentation/iio/ad7380.rst b/Documentation/iio/ad7380.rst index cff688bcc2d9601a9faf42d5e9c217486639ca66..e593ab6037b0da4cebfad148313= f21cca7f00fd4 100644 --- a/Documentation/iio/ad7380.rst +++ b/Documentation/iio/ad7380.rst @@ -142,21 +142,21 @@ Example for AD7386/7/8 (2 channels parts): .. code-block:: =20 IIO | AD7386/7/8 - | +---------------------------- - | | _____ ______ - | | | | | | + | +---------------------------- + | | _____ ______ + | | | | | | voltage0 | AinA0 --|--->| | | | - | | | mux |----->| ADCA |--- + | | | mux |----->| ADCA |--- voltage2 | AinA1 --|--->| | | | - | | |_____| |_____ | - | | _____ ______ - | | | | | | + | | |_____| |_____ | + | | _____ ______ + | | | | | | voltage1 | AinB0 --|--->| | | | - | | | mux |----->| ADCB |--- + | | | mux |----->| ADCB |--- voltage3 | AinB1 --|--->| | | | - | | |_____| |______| - | | - | +---------------------------- + | | |_____| |______| + | | + | +---------------------------- =20 =20 When enabling sequencer mode, the effective sampling rate is divided by tw= o. @@ -169,6 +169,38 @@ gain is selectable from device tree using the ``adi,ga= in-milli`` property. Refer to the typical connection diagrams section of the datasheet for pin wiring. =20 + +SPI offload support +------------------- + +To be able to achieve the maximum sample rate, the driver can be used with= the +`AXI SPI Engine`_ to provide SPI offload support. + +.. _AXI SPI Engine: http://analogdevicesinc.github.io/hdl/projects/ad738x_= fmc/index.html + +When SPI offload is being used, some attributes will be different. + +* ``in_voltage-voltage_sampling_frequency`` attribute is added for setting= the + sample rate. +* ``in_voltage-voltage_sampling_frequency_available`` attribute is added f= or + querying the max sample rate. +* ``timestamp`` channel is removed. +* Buffer data format may be different compared to when offload is not used, + e.g. the ``buffer0/in_voltage0-voltage1_type`` and the + ``buffer0/in_voltage2-voltage3_type`` attributes. + +.. seealso:: `SPI offload support`_ + +Effective sample rate for buffered reads +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Using SPI offload, the PWM generator drives the starting of the conversion= by +executing the pre-recorded SPI transfer at each PWM cycle, asserting CS and +reading the previous available sample values for all channels. +Default sample rate is set to a quite low frequency, to allow oversampling= x32, +user is then reponsible to adjust ``in_voltage-voltage_sampling_frequency`= ` for +the specific case. + Unimplemented features ---------------------- =20 --=20 2.48.1