[PATCH v9 4/5] iio: magnetometer: ak8975: add scan mask index enum
From: Joshua Crofts
Date: Sun Sep 20 2026 - 14:06:47 EST
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>
Reviewed-by: Nuno Sá <nuno.sa@xxxxxxxxxx>
Signed-off-by: Joshua Crofts <joshua.crofts1@xxxxxxxxx>
---
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 42f6892f4efd..ac556644b02d 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -237,6 +237,13 @@ enum ak_ctrl_mode {
MODE_END,
};
+enum ak_chan_index {
+ AK8975_CHAN_X,
+ AK8975_CHAN_Y,
+ AK8975_CHAN_Z,
+ AK8975_CHAN_TS,
+};
+
struct ak_def {
enum asahi_compass_chipset type;
long (*raw_to_gauss)(u16 data);
@@ -851,8 +858,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_CHAN_X),
+ AK8975_CHANNEL(Y, AK8975_CHAN_Y),
+ AK8975_CHANNEL(Z, AK8975_CHAN_Z),
+ IIO_CHAN_SOFT_TIMESTAMP(AK8975_CHAN_TS),
};
static const unsigned long ak8975_scan_masks[] = { 0x7, 0 };
--
2.55.0