mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arka Mondal <arka@arkamondal.net>
To: Jonathan Cameron <jic23@kernel.org>, Linus Walleij <linusw@kernel.org>
Cc: "David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Peter Meerwald" <pmeerw@pmeerw.net>,
	"Matt Ranostay" <mranostay@gmail.com>,
	"Robert Eshleman" <bobbyeshleman@gmail.com>,
	"Leonard Crestez" <cdleonard@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Arka Mondal" <arka@arkamondal.net>
Subject: [PATCH 6/6] iio: gyro: mpu3050: Fix the scale list and report it via read_avail()
Date: Mon,  2 Nov 2026 16:47:00 +0900	[thread overview]
Message-ID: <20261102074700.63075-7-arka@arkamondal.net> (raw)
In-Reply-To: <20261102074700.63075-1-arka@arkamondal.net>

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@arkamondal.net>
---

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


      parent reply	other threads:[~2026-11-02  7:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  7:46 [PATCH 0/6] iio: Give the *_available attributes the names the core generates Arka Mondal
2026-11-02  7:46 ` [PATCH 1/6] iio: light: isl29125: Report the scale list via read_avail() Arka Mondal
2026-11-02 22:26   ` Jonathan Cameron
2026-11-02  7:46 ` [PATCH 2/6] iio: light: apds9960: Report the available lists " Arka Mondal
2026-11-02  7:46 ` [PATCH 3/6] iio: light: max44009: Report the integration time " Arka Mondal
2026-11-02  7:46 ` [PATCH 4/6] iio: light: max44000: Report the available lists " Arka Mondal
2026-11-02  7:46 ` [PATCH 5/6] iio: humidity: hdc100x: " Arka Mondal
2026-11-02  7:47 ` Arka Mondal [this message]

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=20261102074700.63075-7-arka@arkamondal.net \
    --to=arka@arkamondal.net \
    --cc=andy@kernel.org \
    --cc=bobbyeshleman@gmail.com \
    --cc=cdleonard@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mranostay@gmail.com \
    --cc=nuno.sa@analog.com \
    --cc=pmeerw@pmeerw.net \
    /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®