[PATCH 6/6] iio: gyro: mpu3050: Fix the scale list and report it via read_avail()
From: Arka Mondal
Date: Mon Nov 02 2026 - 02:53:12 EST
The angular velocity channels keep IIO_CHAN_INFO_SCALE in
info_mask_shared_by_type, so userspace reads the scale from
in_anglvel_scale. One custom attribute lists the values it can take,
and that list is wrong in both its numbers and its name.
The four numbers were computed against 2^16 while mpu3050_read_raw()
divides by U16_MAX, so not one of them is a value the channel ever
reports. The list gives 0.000122070, 0.000274658, 0.000518798 and
0.001068115, where the channel reports 0.000122072, 0.000274662,
0.000518806 and 0.001068131.
The name, anglevel_scale_available, has neither the in_ prefix nor
the anglvel spelling the core uses for IIO_ANGL_VEL, so it sits at the
device level and userspace that opens in_anglvel_scale_available finds
no such file.
Report the list through read_avail(), built from the same
IIO_DEGREE_TO_RAD() terms and U16_MAX that mpu3050_read_raw() uses so
the two cannot drift apart again, and delete the attribute along with
the comment describing the hardcoded factors.
Fixes: 3904b28efb2c ("iio: gyro: Add driver for the MPU-3050 gyroscope")
Signed-off-by: Arka Mondal <arka@xxxxxxxxxxxxxx>
---
Notes:
Compile tested only; no relevant hardware available.
drivers/iio/gyro/mpu3050-core.c | 40 +++++++++++++++++++--------------
1 file changed, 23 insertions(+), 17 deletions(-)
diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
index 07c0f9011c63..0dfb5e6039fb 100644
--- a/drivers/iio/gyro/mpu3050-core.c
+++ b/drivers/iio/gyro/mpu3050-core.c
@@ -701,6 +701,8 @@ static const struct iio_chan_spec_ext_info mpu3050_ext_info[] = {
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
BIT(IIO_CHAN_INFO_CALIBBIAS), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
+ .info_mask_shared_by_type_available = \
+ BIT(IIO_CHAN_INFO_SCALE), \
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
.ext_info = mpu3050_ext_info, \
.scan_index = index, \
@@ -736,29 +738,33 @@ static const struct iio_chan_spec mpu3050_channels[] = {
/* Four channels apart from timestamp, scan mask = 0x0f */
static const unsigned long mpu3050_scan_masks[] = { 0xf, 0 };
-/*
- * These are just the hardcoded factors resulting from the more elaborate
- * calculations done with fractions in the scale raw get/set functions.
- */
-static IIO_CONST_ATTR(anglevel_scale_available,
- "0.000122070 "
- "0.000274658 "
- "0.000518798 "
- "0.001068115");
-
-static struct attribute *mpu3050_attributes[] = {
- &iio_const_attr_anglevel_scale_available.dev_attr.attr,
- NULL,
+static const int mpu3050_scale_avail[] = {
+ IIO_DEGREE_TO_RAD(250) * 2, U16_MAX,
+ IIO_DEGREE_TO_RAD(500) * 2, U16_MAX,
+ IIO_DEGREE_TO_RAD(1000) * 2, U16_MAX,
+ IIO_DEGREE_TO_RAD(2000) * 2, U16_MAX,
};
-static const struct attribute_group mpu3050_attribute_group = {
- .attrs = mpu3050_attributes,
-};
+static int mpu3050_read_avail(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ const int **vals, int *type, int *length,
+ long mask)
+{
+ switch (mask) {
+ case IIO_CHAN_INFO_SCALE:
+ *vals = mpu3050_scale_avail;
+ *type = IIO_VAL_FRACTIONAL;
+ *length = ARRAY_SIZE(mpu3050_scale_avail);
+ return IIO_AVAIL_LIST;
+ default:
+ return -EINVAL;
+ }
+}
static const struct iio_info mpu3050_info = {
.read_raw = mpu3050_read_raw,
.write_raw = mpu3050_write_raw,
- .attrs = &mpu3050_attribute_group,
+ .read_avail = mpu3050_read_avail,
};
/**
--
2.56.0