From: Jonathan Cameron <jic23@kernel.org>
To: Joshua Crofts via B4 Relay <devnull+joshua.crofts1.gmail.com@kernel.org>
Cc: joshua.crofts1@gmail.com, "David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v8 4/5] iio: magnetometer: ak8975: add scan mask index enum
Date: Wed, 20 May 2026 16:37:15 +0100 [thread overview]
Message-ID: <20260520163715.7d6358b6@jic23-huawei> (raw)
In-Reply-To: <20260518-magnetometer-fixes-post-pickup-v8-4-088d610108a0@gmail.com>
On Mon, 18 May 2026 09:50:28 +0200
Joshua Crofts via B4 Relay <devnull+joshua.crofts1.gmail.com@kernel.org> wrote:
> From: Joshua Crofts <joshua.crofts1@gmail.com>
>
> Add an enum to explicitly define scan mask indexes for the X, Y, Z and
> timestamp channels. Also, update the struct iio_chan_spec to use said
> enum for the .scan_index parameter.
>
> This prevents magic numbers from obscuring the hardware channel mapping
> and improves code style.
>
> No functional change.
>
> Suggested-by: Jonathan Cameron <jic23@kernel.org>
> Reviewed-by: Nuno Sá <nuno.sa@analog.com>
> Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
There is one other place we can use this to improve the code:
Replace:
static const unsigned long ak8975_scan_masks[] = { 0x7, 0 };
with
static const unsigned long ak8975_scan_masks[] = {
BIT(AK8975_SCAN_X) | BIT(AK8975_SCAN_Y) | BIT(AK8975_SCAN_Z),
0
};
That makes it obvious we are dealing with all the channels.
I only noticed this because I couldn't work out why there weren't
more per things indexing the channel / addresses stored in channels
or that sort of thing. Answer was because the driver only does things
one way.
Also, maybe rename....
Jonathan
> ---
> drivers/iio/magnetometer/ak8975.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
> index 7ab4c4d69d8b73c6f367f6e62fee3017d8691b67..a140d352bad663a138295dc0c44084a9a18a4c24 100644
> --- a/drivers/iio/magnetometer/ak8975.c
> +++ b/drivers/iio/magnetometer/ak8975.c
> @@ -238,6 +238,13 @@ enum ak_ctrl_mode {
> MODE_END,
> };
>
> +enum ak_scan_index {
> + AK8975_SCAN_X,
> + AK8975_SCAN_Y,
> + AK8975_SCAN_Z,
> + AK8975_SCAN_TS,
Can we call these
AK8975_CHAN_X,
etc because they are used both for scan indexes and as chan->address
and putting something called scan index in there feels wrong.
Hence use a vaguer naming.
> +};
> +
> struct ak_def {
> enum asahi_compass_chipset type;
> long (*raw_to_gauss)(u16 data);
> @@ -845,8 +852,10 @@ static const struct iio_chan_spec_ext_info ak8975_ext_info[] = {
> }
>
> static const struct iio_chan_spec ak8975_channels[] = {
> - AK8975_CHANNEL(X, 0), AK8975_CHANNEL(Y, 1), AK8975_CHANNEL(Z, 2),
> - IIO_CHAN_SOFT_TIMESTAMP(3),
> + AK8975_CHANNEL(X, AK8975_SCAN_X),
> + AK8975_CHANNEL(Y, AK8975_SCAN_Y),
> + AK8975_CHANNEL(Z, AK8975_SCAN_Z),
> + IIO_CHAN_SOFT_TIMESTAMP(AK8975_SCAN_TS),
> };
>
> static const unsigned long ak8975_scan_masks[] = { 0x7, 0 };
>
next prev parent reply other threads:[~2026-05-20 15:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-18 7:50 [PATCH v8 0/5] iio: magnetometer: ak8975: driver cleanup Joshua Crofts via B4 Relay
2026-05-18 7:50 ` [PATCH v8 1/5] iio: magnetometer: ak8975: switch to using managed resources Joshua Crofts via B4 Relay
2026-05-20 15:31 ` Jonathan Cameron
2026-05-21 7:06 ` Joshua Crofts
2026-05-18 7:50 ` [PATCH v8 2/5] iio: magnetometer: ak8975: unify messages with help of dev_err_probe() Joshua Crofts via B4 Relay
2026-05-18 7:50 ` [PATCH v8 3/5] iio: magnetometer: ak8975: use temporary variable for struct device Joshua Crofts via B4 Relay
2026-05-18 7:50 ` [PATCH v8 4/5] iio: magnetometer: ak8975: add scan mask index enum Joshua Crofts via B4 Relay
2026-05-20 15:37 ` Jonathan Cameron [this message]
2026-05-18 7:50 ` [PATCH v8 5/5] iio: magnetometer: ak8975: make use of the macros from bits.h Joshua Crofts via B4 Relay
2026-05-20 15:38 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260520163715.7d6358b6@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=devnull+joshua.crofts1.gmail.com@kernel.org \
--cc=dlechner@baylibre.com \
--cc=joshua.crofts1@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®