From nobody Wed Apr 15 16:24:16 2026 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.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 C3FF33890EA for ; Wed, 4 Mar 2026 08:06:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772611615; cv=none; b=XrzBv8JtwSfsiS+/npTMTu0hsk8imkOiwBV2qYPGWNeatc8HJSiPyeG61xm/AQIy3Tt22q/bnfChr/8kz8bTluvDLvPF07p8JXZTeEDp9QkZDeOYlc5Lm9krZBBS8dAFqgyIXGFK21lq0UIm0VS7D0aVEDW5drK0uYNr1JVSsVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772611615; c=relaxed/simple; bh=+VTQz46EOKW2Um5JmqDbjWtJ4+tNkrLXbwXC9v6BvGc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z+H1sfQKi+rt3Zx8Dhsl6DcJECL7oGebOEi4qf6AzAGdtE2pLOQoEUh7X2jXmS6JqCqPUarb1b+v8f+2HFjff2X5NsySUGn1yujnlNz0GKvshM/agalWU+wUCSJybk56ounVYau9RUMvzUZ9EytfSGTaI6EeGkB3oL87JZpRpdE= 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=RDi/GzrL; arc=none smtp.client-ip=209.85.128.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="RDi/GzrL" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-480706554beso70887835e9.1 for ; Wed, 04 Mar 2026 00:06:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1772611612; x=1773216412; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=+TMotMzaSW4Oh+VOEFs9Z8B+kUyDiiMOR5H6kPqUxcM=; b=RDi/GzrLJlAAOsPznAFCKpS0arKPn4uLArwLYj/oFLqbShu0Qp4wyf+fwVw9lbCc3I 3a7zeJJb1RKnWZc7WtzIkzpCfde8MI46PA9DetI7bsOjzydJW0KsjxZz08tMAw9IrZxv sxoElF0TTT+JKZA5FB5RdunrkdLbKTw+O9jOPlO7YO14J942cv3UBDEqssfgbPKBL8lq R3HZLWSoarjda77m2zby/yIDIhR7kVhZIOVsg7AbbKAlFiqhGxAPZmN6DgJQXkvmtWdJ vNby1QCxqd8m4/AI5vJsGpxufHMb8eYdtbUoITtDbcfnZ1mLtHxBB0w1eiJuCMRiOPcq qOrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772611612; x=1773216412; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=+TMotMzaSW4Oh+VOEFs9Z8B+kUyDiiMOR5H6kPqUxcM=; b=nd2ugg3IrljV7DZKW9z3yo5bRBVUg9i62AgbociTSCguLmtuqZ+s+iLLeSlQHSvSyQ E2dNO92mKH+tyTL5tf7jc70CtE64PvEeJ23jtIN4Lf86tjCrZ/LPfdkeCeR3RivtRKpL TJ8cBXR3EEF/dU8s4lLoeK1BXtNO/GnT0edwtB80L/Aor9nkpbwnH4HDRw8lvTlw+ave xWXnFnXhcvjSuMhvto/FsUJ7LACpE9TXKwA9jfB2ghtfg2Pos4BgZY5SpjDQovB1+qL2 zdcbBsAXMAqRPVho3jCLWX5g0kNc3E5qxbftvq6Uj+RrAT/JoFPEJZk9hExMFKHmg1j/ /ARg== X-Forwarded-Encrypted: i=1; AJvYcCUOO7bTa+jv4+iKX9l9tMIeMMC01wxjQtELXJmsF65m3kswpCgdxy9FlNWRx8QwSn1Ax9up0GAOAx5ZWyE=@vger.kernel.org X-Gm-Message-State: AOJu0YwFwCEeLFYnUQ8ELICajQho+MFDDzKNfuJJg/vb6+jBfjPbJLj+ r7mqRjQZcimX7WZ8iwYjZYT7JhQz++fea+sCGCJtfhcOJkNqfVdF2peoTwnql60hmrE= X-Gm-Gg: ATEYQzxAWiGkN24E6mkX1S43IJU1iaICKAlebbRJ3jLkTMbS6cRGKk95PQ0mlC3r3Zd 5vQfLO1/E0+2PgjCpHLlQ7Wn5xcgSpOJfIDT2HDM2mmBpxeaNYtziN6rq90zCWOI7S76XaS1vk1 K1i3WuZ7x6PdbMJsf3qr/EWla8Q9xqfQLKbpkW4Ca5kDwnROloSjCkOZI34Wxc5/bwb25RN6iBe 8G0uf7WRa/gJKWhrgn3LEi/cja0c0k83J38/36iqOPRm6223o4nF3N7x/O5NoRfpN+K13y4NQS7 4My36SKbDoFcs52u5oVXhe4W8kYMA11OefAVlka1lDu0rmNIqG/N2h7d8N7xZMlFtZblQTVWAom ys6c9+YRxbjTKE4G7WF7ilTXHFZDvEbjvrL/ufEmdvxXRTFbelLYj1xs71VtFEcwUHIxk X-Received: by 2002:a05:600c:6305:b0:483:6de6:37ad with SMTP id 5b1f17b1804b1-485198c0f13mr15807855e9.34.1772611612150; Wed, 04 Mar 2026 00:06:52 -0800 (PST) Received: from localhost ([151.19.177.89]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4851889322bsm30526075e9.13.2026.03.04.00.06.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2026 00:06:51 -0800 (PST) From: Francesco Lavra To: Jonathan Cameron , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 3/6] iio: tools: Add support for floating-point numbers in buffer scan elements Date: Wed, 4 Mar 2026 09:06:50 +0100 Message-Id: <20260304080650.2844401-1-flavra@baylibre.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260304080519.2844101-1-flavra@baylibre.com> References: <20260304080519.2844101-1-flavra@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5677; i=flavra@baylibre.com; h=from:subject; bh=+VTQz46EOKW2Um5JmqDbjWtJ4+tNkrLXbwXC9v6BvGc=; b=owEB7QES/pANAwAKAe3xO3POlDZfAcsmYgBpp+gapVKFxU+E52FqXhhcoV8BK2/kFJ0s/Abse cqUilczh26JAbMEAAEKAB0WIQSGV4VPlTvcox7DFObt8TtzzpQ2XwUCaafoGgAKCRDt8TtzzpQ2 X/gJC/45XxRJat2G5uf63pyQ+kI8sVYHxXkMELVPYYGl5QzuuRVSpMGT5+N7/Vv8rYpvbtUVhzY fJEf3EJjgfmAnBJp5VTHyY6Yc2/7Q6dzz9elIpjT7x5ycihSgh4XM+FNP7CxiYVVNw+35UY4y1w zxS7WvxQfZd9xjZEGH6dc3mL8Wjz+oY2DFI0i2TnCPEpBSxuuDxkUXzc4LPtRGAljSzEHGiyFFK qLb2N2o66kzEHGaUOuYUdYd+bj/WRXZl+AQWxa7qmYQszuqVsiNVYcYVAdSJ2bvDU96UtAzGEUU TRCeOgmFbJBomwh/rLdVA9E8b93n9dVDP2vgdoQUwdaN0nfPNLdfY41JfrHUNKn3vGEzhR644cd fvahuTD3YwJyAGE83heWI1w506fBlialdRvu+dH8i7x/Oa8CQB75p9rN4GHjWhkThpvZuKn2Lwb XwqPPaWwcwUyF4d2wVXNpU+VHq1kB/3WT9Tr2dfrNB/+fqkY/K+2SCoWw9qZZYSvIDlok= X-Developer-Key: i=flavra@baylibre.com; a=openpgp; fpr=8657854F953BDCA31EC314E6EDF13B73CE94365F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A subsequent commit will add floating-point support to the ABI; enhance the iio_generic_buffer tool to be able to parse this new data format. Signed-off-by: Francesco Lavra --- tools/iio/iio_generic_buffer.c | 56 +++++++++++++++++++++++++++++----- tools/iio/iio_utils.c | 8 ++--- tools/iio/iio_utils.h | 4 +-- 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/tools/iio/iio_generic_buffer.c b/tools/iio/iio_generic_buffer.c index bc82bb6a7a2a..39c13b9ad20b 100644 --- a/tools/iio/iio_generic_buffer.c +++ b/tools/iio/iio_generic_buffer.c @@ -89,7 +89,7 @@ static void print1byte(uint8_t input, struct iio_channel_= info *info) */ input >>=3D info->shift; input &=3D info->mask; - if (info->is_signed) { + if (info->format =3D=3D 's') { int8_t val =3D (int8_t)(input << (8 - info->bits_used)) >> (8 - info->bits_used); printf("%05f ", ((float)val + info->offset) * info->scale); @@ -112,12 +112,26 @@ static void print2byte(uint16_t input, struct iio_cha= nnel_info *info) */ input >>=3D info->shift; input &=3D info->mask; - if (info->is_signed) { + switch (info->format) { + case 's': { int16_t val =3D (int16_t)(input << (16 - info->bits_used)) >> (16 - info->bits_used); printf("%05f ", ((float)val + info->offset) * info->scale); - } else { + break; + } + case 'u': printf("%05f ", ((float)input + info->offset) * info->scale); + break; + case 'f': { + union { + uint16_t u; + __fp16 f; + } converter; + + converter.u =3D input; + printf("%05f ", ((float)converter.f + info->offset) * info->scale); + break; + } } } =20 @@ -135,12 +149,26 @@ static void print4byte(uint32_t input, struct iio_cha= nnel_info *info) */ input >>=3D info->shift; input &=3D info->mask; - if (info->is_signed) { + switch (info->format) { + case 's': { int32_t val =3D (int32_t)(input << (32 - info->bits_used)) >> (32 - info->bits_used); printf("%05f ", ((float)val + info->offset) * info->scale); - } else { + break; + } + case 'u': printf("%05f ", ((float)input + info->offset) * info->scale); + break; + case 'f': { + union { + uint32_t u; + float f; + } converter; + + converter.u =3D input; + printf("%05f ", (converter.f + info->offset) * info->scale); + break; + } } } =20 @@ -158,7 +186,8 @@ static void print8byte(uint64_t input, struct iio_chann= el_info *info) */ input >>=3D info->shift; input &=3D info->mask; - if (info->is_signed) { + switch (info->format) { + case 's': { int64_t val =3D (int64_t)(input << (64 - info->bits_used)) >> (64 - info->bits_used); /* special case for timestamp */ @@ -167,8 +196,21 @@ static void print8byte(uint64_t input, struct iio_chan= nel_info *info) else printf("%05f ", ((float)val + info->offset) * info->scale); - } else { + break; + } + case 'u': printf("%05f ", ((float)input + info->offset) * info->scale); + break; + case 'f': { + union { + uint64_t u; + double f; + } converter; + + converter.u =3D input; + printf("%05f ", (converter.f + info->offset) * info->scale); + break; + } } } =20 diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c index c5c5082cb24e..0643a943b2ad 100644 --- a/tools/iio/iio_utils.c +++ b/tools/iio/iio_utils.c @@ -70,7 +70,7 @@ int iioutils_break_up_name(const char *full_name, char **= generic_name) =20 /** * iioutils_get_type() - find and process _type attribute data - * @is_signed: output whether channel is signed + * @format: output channel format * @bytes: output how many bytes the channel storage occupies * @bits_used: output number of valid bits of data * @shift: output amount of bits to shift right data before applying bit m= ask @@ -83,7 +83,7 @@ int iioutils_break_up_name(const char *full_name, char **= generic_name) * * Returns a value >=3D 0 on success, otherwise a negative error code. **/ -static int iioutils_get_type(unsigned int *is_signed, unsigned int *bytes, +static int iioutils_get_type(unsigned int *format, unsigned int *bytes, unsigned int *bits_used, unsigned int *shift, uint64_t *mask, unsigned int *be, const char *device_dir, int buffer_idx, @@ -162,7 +162,7 @@ static int iioutils_get_type(unsigned int *is_signed, u= nsigned int *bytes, else *mask =3D (1ULL << *bits_used) - 1ULL; =20 - *is_signed =3D (signchar =3D=3D 's'); + *format =3D signchar; if (fclose(sysfsfp)) { ret =3D -errno; fprintf(stderr, "Failed to close %s\n", @@ -487,7 +487,7 @@ int build_channel_array(const char *device_dir, int buf= fer_idx, if ((ret < 0) && (ret !=3D -ENOENT)) goto error_cleanup_array; =20 - ret =3D iioutils_get_type(¤t->is_signed, + ret =3D iioutils_get_type(¤t->format, ¤t->bytes, ¤t->bits_used, ¤t->shift, diff --git a/tools/iio/iio_utils.h b/tools/iio/iio_utils.h index 663c94a6c705..e09116af194b 100644 --- a/tools/iio/iio_utils.h +++ b/tools/iio/iio_utils.h @@ -32,7 +32,7 @@ extern const char *iio_dir; * @shift: amount of bits to shift right data before applying bit mask * @mask: a bit mask for the raw output * @be: flag if data is big endian - * @is_signed: is the raw value stored signed + * @format: format of the raw value * @location: data offset for this channel inside the buffer (in bytes) **/ struct iio_channel_info { @@ -46,7 +46,7 @@ struct iio_channel_info { unsigned shift; uint64_t mask; unsigned be; - unsigned is_signed; + unsigned format; unsigned location; }; =20 --=20 2.39.5