From nobody Fri Apr 3 17:32:59 2026 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C9123D88E2 for ; Tue, 24 Mar 2026 08:47:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774342072; cv=none; b=IQyaDxWGRx1QsK1mnMw44YepYuKJVX1GrIHmDej3Y9z5D9QxFt0MBLHlUdQcNvGm9uyvn8by7nvjqObtd5MBSZlTGFW739vql0vejZ+elhTV/YvBqt8eKJawUlWaX585H6CKwT+n1pLAYLs7TwTO3cKrl9OJnctoZRN7q9Cnmdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774342072; c=relaxed/simple; bh=Pmx09FjUuabFWsJvX9ZIiyJWEPRXSi3I/1OkkdhbSUY=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dkgI/0AsUJ8kxHoJ2dTcTtfuqnKogYcr1twEa6OQ9aJeYzyu6zeuH/SrDS+beKCvo3j3l5rt6eQbixmaYLoqaWZ0x+71ASShxSK2RGswb7hOjXka5eGmDnO55k69Q/nQ4mxnOthkp9Ry+43ZpIRxJewin/iCrCBZgBXSirwV3rM= 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=LghlXToY; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="LghlXToY" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-486fb112c09so32744825e9.1 for ; Tue, 24 Mar 2026 01:47:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1774342068; x=1774946868; 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=r00Ss0X9VzFEuDRGE5q7OfOKcRugbWSqniqvg/LPyQ0=; b=LghlXToYcVJwwPS4uuhLR3fSgimoJ9WWjWJwWUHhL17gztjxEK0HOLPlUYT1N/aMTv cGg+jk3icATChIJtBznLZSukyIm4th66uMt3GloxJ5zOadCT4WGTU2WzlpfH4e7/I+sX joRjxM67/egRggWjemwcCGIWwQ2mQn1LhEXoK5bPeyvtv7QV8eGLprKZoO0rfa9SXswK aP1/L5iL3HqJyc7eQHxgiBdvYJJQLp1yf3HjFjXTHVPUg0HmdPSMi9yf1Awyu/aJmp7x R2nB8N7xDgrQDDobqnp+8qk+CTgv3wK5lWxoaGOUuoIy3oDRapa+VEjsqe5TMxN+d8t4 NdFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774342068; x=1774946868; 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=r00Ss0X9VzFEuDRGE5q7OfOKcRugbWSqniqvg/LPyQ0=; b=s4DEXTVFlKFp4DuxVfA35vgBPlagHdbXSIgxUfKcVIwKNx8HtuIxJrb6BmMcoU7t4k ppTqFGYLHO+ck/Lk62tvUnnTCzd/gXJWuEahHqtJVfb/G5Y6C8G7GgynMukxq3I0MNUe UxKDq3xSxz+/zII8kD1ftLEHyGPgMoFFskCxwIX89LVBLmZEQZmSX/3R6qr7lifHEx87 PSZ49/tXwm0kHLOQIWO63nHYABCjHl8ZZ31oNS4JyIRLE5WV6tFI+/JYkJcnRHehwhYr ODUcGNAaCKs5IQP3qB5IorWhj6QARW3ZSZkOCTLiuPpDflOoXaFer7X3W98WMtZpKn0i QKdg== X-Forwarded-Encrypted: i=1; AJvYcCXMb/DIOfLe3Z08aE7Xp5Gnhq/pchoMkoyvybYjaa6F0d/S36PwmsEqSzRXbAVrxMLPGj6iYyl1wNWSyAQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxFWmRiQ2vhhLCCcj0zArH0hXbNqBDHARj2UDur+ck8xwLeFfDE 9jOX+0vtH9Vbv20GIwA9VaLqidqkf1LxBz1BYkDFdpouopydielJP7i/oY2GwvRUntw= X-Gm-Gg: ATEYQzwjbHjyb5wpXJ+Ggh16Z+/g4uA/osYVFqWioVwHYLP9tvbekcqOs1QQk6sEjcF FYYD5xuKn23W3Q4JyYr/7Hzj5SpvOPZtX/9pCoPKVZNq890O1c3mqG2zLEMXe+Aki8nN+0oOoWW TQndObjhH5xvIPNBmcX9VsnL0LZ+C4eAKzjUNCZ6YAvktOqQ01eC1J8BsL8T+M3WruiTJq1jE8t LUoaN4f4ZHx+io3y0zghcCoJCDe7Q6ms9cLqHlCDgPKSfge/cJcugqMITLeNBnQ4MNkuCQo2x+i wU8fISgHJx/IR/OpPn1T3nKqxUqBVcbcnXxG7qk4z7VBKPbYd2QVMRGLQaCfUDm09/HlmNZZdPk wbM53zYKBK9M8vI0CqICKST0kkEzUozdJyZUn4yQZz4M9EjYsbJNlHEfYa2rKxVnMSYECVBTiJS L5zw== X-Received: by 2002:a05:600c:5294:b0:486:fe46:b647 with SMTP id 5b1f17b1804b1-4870334cb27mr162699155e9.10.1774342067728; Tue, 24 Mar 2026 01:47:47 -0700 (PDT) Received: from localhost ([151.43.230.2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4871174f2desm42738755e9.9.2026.03.24.01.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2026 01:47:47 -0700 (PDT) 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 v9 3/6] iio: tools: Add support for floating-point types in buffer scan elements Date: Tue, 24 Mar 2026 09:47:46 +0100 Message-Id: <20260324084746.653984-1-flavra@baylibre.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260324084655.653781-1-flavra@baylibre.com> References: <20260324084655.653781-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=6732; i=flavra@baylibre.com; h=from:subject; bh=Pmx09FjUuabFWsJvX9ZIiyJWEPRXSi3I/1OkkdhbSUY=; b=owEB7QES/pANAwAKAe3xO3POlDZfAcsmYgBpwk+yvAIzq2SkukP7iiVaZG3ChhyjyTILdbl1o IntpAUDUOuJAbMEAAEKAB0WIQSGV4VPlTvcox7DFObt8TtzzpQ2XwUCacJPsgAKCRDt8TtzzpQ2 X+x3C/9jcXLhig2HmXyjJ4uTsWGddZHaV4l20UtvgR6RzulQHZ3Qo+DeA/LGvD5xibYz9YACxng f7czaBF+mdD5SOxB12FYKujod7WD8gCmp6U1O0NUvY21YkhrB36b1okQHvqsNTEzSn6hckmWbo4 vAzRG64eWtxIjJk2oITn+Mw9zg2tYjoRNA7UCpb+1/XbgXA4IxyLbz8O/4J6bx12IC57qwI//DX sBtvu4KReW4kegDK2fAPrflfWYEHzTRdHj5+yBmfgqc9bS5nPCNNWk1JMCpW2QhWvYH2S3xwBhR UPL7K57UNURVw+Dj0bOg/5g4Qb/8KyGfjd7gtzJYB/g84Wc4C/ZlyQt84Raa4/7YfnxhmHHwrlq sMbAOvmfcslYEBBrnWu4ZYHgFJ7ZRQ2e4KnYlp+y6JfxvCdg2xrb51+rIjdUHYn72z9xPU3Yyg9 cIUedYihR52VycF4dlN8OeXLmzfxM8SJD6GRhroOtGgBlX6WGBmOEOO9AFvlaTN95HC/U= 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 | 70 ++++++++++++++++++++++++++++++---- tools/iio/iio_utils.c | 12 +++--- tools/iio/iio_utils.h | 4 +- 3 files changed, 70 insertions(+), 16 deletions(-) diff --git a/tools/iio/iio_generic_buffer.c b/tools/iio/iio_generic_buffer.c index bc82bb6a7a2a..000193612aad 100644 --- a/tools/iio/iio_generic_buffer.c +++ b/tools/iio/iio_generic_buffer.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -89,12 +90,19 @@ static void print1byte(uint8_t input, struct iio_channe= l_info *info) */ input >>=3D info->shift; input &=3D info->mask; - if (info->is_signed) { + switch (info->format) { + case 's': { int8_t val =3D (int8_t)(input << (8 - info->bits_used)) >> (8 - 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': + printf(" "); + break; } } =20 @@ -112,12 +120,30 @@ 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': { +#if defined(__FLT16_MAX__) + union { + uint16_t u; + _Float16 f; + } converter; + + converter.u =3D input; + printf("%05f ", ((float)converter.f + info->offset) * info->scale); +#else + printf(" "); +#endif + break; + } } } =20 @@ -135,12 +161,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 +198,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 +208,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..e274a0d8376b 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(char *format, unsigned int *bytes, unsigned int *bits_used, unsigned int *shift, uint64_t *mask, unsigned int *be, const char *device_dir, int buffer_idx, @@ -93,7 +93,7 @@ static int iioutils_get_type(unsigned int *is_signed, uns= igned int *bytes, int ret; DIR *dp; char *scan_el_dir, *builtname, *builtname_generic, *filename =3D 0; - char signchar, endianchar; + char formatchar, endianchar; unsigned padint; const struct dirent *ent; =20 @@ -140,7 +140,7 @@ static int iioutils_get_type(unsigned int *is_signed, u= nsigned int *bytes, ret =3D fscanf(sysfsfp, "%ce:%c%u/%u>>%u", &endianchar, - &signchar, + &formatchar, bits_used, &padint, shift); if (ret < 0) { @@ -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 formatchar; 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..8c72f002d050 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; + char format; unsigned location; }; =20 --=20 2.39.5