[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241019161546.026f02e7@jic23-huawei>
Date: Sat, 19 Oct 2024 16:15:46 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: Angelo Dureghello <adureghello@...libre.com>
Cc: Nuno Sá <nuno.sa@...log.com>, Lars-Peter Clausen
<lars@...afoo.de>, Michael Hennerich <Michael.Hennerich@...log.com>, Rob
Herring <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>, Conor
Dooley <conor+dt@...nel.org>, Olivier Moysan <olivier.moysan@...s.st.com>,
linux-iio@...r.kernel.org, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org, dlechner@...libre.com, Mark Brown
<broonie@...nel.org>
Subject: Re: [PATCH v6 6/8] iio: dac: ad3552r: extract common code (no
changes in behavior intended)
On Mon, 14 Oct 2024 12:08:12 +0200
Angelo Dureghello <adureghello@...libre.com> wrote:
> From: Angelo Dureghello <adureghello@...libre.com>
>
> Extracting common code, to share common code to be used later
> by the AXI driver version (ad3552r-axi.c).
>
> Signed-off-by: Angelo Dureghello <adureghello@...libre.com>
One suggestion inline.
Jonathan
> ---
> drivers/iio/dac/Makefile | 2 +-
> drivers/iio/dac/ad3552r-common.c | 170 ++++++++++++++++++++++
> drivers/iio/dac/ad3552r.c | 303 ++++-----------------------------------
> drivers/iio/dac/ad3552r.h | 200 ++++++++++++++++++++++++++
> 4 files changed, 398 insertions(+), 277 deletions(-)
>
> diff --git a/drivers/iio/dac/Makefile b/drivers/iio/dac/Makefile
> index 621d553bd6e3..c92de0366238 100644
> --- a/drivers/iio/dac/Makefile
> +++ b/drivers/iio/dac/Makefile
> @@ -4,7 +4,7 @@
> #
>
> # When adding new entries keep the list in alphabetical order
> -obj-$(CONFIG_AD3552R) += ad3552r.o
> +obj-$(CONFIG_AD3552R) += ad3552r.o ad3552r-common.o
> obj-$(CONFIG_AD5360) += ad5360.o
> obj-$(CONFIG_AD5380) += ad5380.o
> obj-$(CONFIG_AD5421) += ad5421.o
> diff --git a/drivers/iio/dac/ad3552r-common.c b/drivers/iio/dac/ad3552r-common.c
> new file mode 100644
> index 000000000000..9a892abf99ac
> --- /dev/null
> +++ b/drivers/iio/dac/ad3552r-common.c
> @@ -0,0 +1,170 @@
> +
> +u16 ad3552r_calc_custom_gain(u8 p, u8 n, s16 goffs)
> +{
> + u16 reg;
> +
> + reg = FIELD_PREP(AD3552R_MASK_CH_RANGE_OVERRIDE, 1);
> + reg |= FIELD_PREP(AD3552R_MASK_CH_GAIN_SCALING_P, p);
> + reg |= FIELD_PREP(AD3552R_MASK_CH_GAIN_SCALING_N, n);
> + reg |= FIELD_PREP(AD3552R_MASK_CH_OFFSET_BIT_8, abs(goffs));
> + reg |= FIELD_PREP(AD3552R_MASK_CH_OFFSET_POLARITY, goffs < 0);
Trivial but whilst here, to me this is no more readable than.
return FIELD_PREP(AD3552R_MASK_CH_RANGE_OVERRIDE, 1) |
FIELD_PREP(AD3552R_MASK_CH_GAIN_SCALING_P, p) |
FIELD_PREP(AD3552R_MASK_CH_GAIN_SCALING_N, n) |
FIELD_PREP(AD3552R_MASK_CH_OFFSET_BIT_8, abs(goffs)) |
FIELD_PREP(AD3552R_MASK_CH_OFFSET_POLARITY, goffs < 0);
> +
> + return reg;
> +}
>
Powered by blists - more mailing lists