[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250330161721.7d718fd0@jic23-huawei>
Date: Sun, 30 Mar 2025 16:17:21 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: Sam Winchenbach <sam.winchenbach@...mepointer.org>
Cc: linux-kernel@...r.kernel.org, lars@...afoo.de,
Michael.Hennerich@...log.com, antoniu.miclaus@...log.com, robh@...nel.org,
krzk+dt@...nel.org, conor+dt@...nel.org, linux-iio@...r.kernel.org,
devicetree@...r.kernel.org, bpellegrino@...a.org, Sam Winchenbach
<swinchenbach@...a.org>
Subject: Re: [PATCH v8 5/6] iio: core: Add support for writing 64 bit attrs
On Fri, 28 Mar 2025 13:48:30 -0400
Sam Winchenbach <sam.winchenbach@...mepointer.org> wrote:
> From: Sam Winchenbach <swinchenbach@...a.org>
>
> Prior to this patch it was only possible to read 64 bit integers.
>
> Signed-off-by: Sam Winchenbach <swinchenbach@...a.org>
> ---
> drivers/iio/industrialio-core.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index a2117ad1337d5..b2436b8f3eeae 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -965,8 +965,10 @@ static ssize_t iio_write_channel_info(struct device *dev,
> struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
> int ret, fract_mult = 100000;
> int integer, fract = 0;
> + long long integer64;
> bool is_char = false;
> bool scale_db = false;
> + bool is_64bit = false;
>
> /* Assumes decimal - precision based on number of digits */
> if (!indio_dev->info->write_raw)
> @@ -990,6 +992,9 @@ static ssize_t iio_write_channel_info(struct device *dev,
> case IIO_VAL_CHAR:
> is_char = true;
> break;
> + case IIO_VAL_INT_64:
> + is_64bit = true;
> + break;
> default:
> return -EINVAL;
> }
> @@ -1000,6 +1005,13 @@ static ssize_t iio_write_channel_info(struct device *dev,
> if (sscanf(buf, "%c", &ch) != 1)
> return -EINVAL;
> integer = ch;
> + } else if (is_64bit) {
> + ret = kstrtoll(buf, 0, &integer64);
> + if (ret)
> + return ret;
> +
> + fract = (int)(integer64 >> 32);
> + integer = (int)(integer64 & 0xFFFFFFFF);
I forgot on previous reviews but for this case we have wordpart.h
fract = lower_32_bits(integer64);
integer = upper_32_bits(integer64);
I'll tweak that whilst applying.
> } else {
> ret = __iio_str_to_fixpoint(buf, fract_mult, &integer, &fract,
> scale_db);
Powered by blists - more mailing lists