Re: [PATCH 7/8] iio: magnetometer: ak8975: add scan mask index enum
From: Nuno Sá
Date: Sat May 09 2026 - 05:06:13 EST
On Thu, 2026-05-07 at 16:35 +0200, Joshua Crofts via B4 Relay wrote:
> From: Joshua Crofts <joshua.crofts1@xxxxxxxxx>
>
> 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@xxxxxxxxxx>
> Signed-off-by: Joshua Crofts <joshua.crofts1@xxxxxxxxx>
> ---
Reviewed-by: Nuno Sá <nuno.sa@xxxxxxxxxx>
> 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
> fde37cdcdd053bde1630c2f73ab717f9d008e2fa..d11f025e146d098508f35ef31c1ccad544612535
> 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,
> +};
> +
> struct ak_def {
> enum asahi_compass_chipset type;
> long (*raw_to_gauss)(u16 data);
> @@ -835,8 +842,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 };