From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Mert Seftali <mertsftl@gmail.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Jelle van der Waa" <jelle@vdwaa.nl>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: accel: dmard09: Implement IIO_CHAN_INFO_SCALE
Date: Fri, 3 Jul 2026 16:30:08 +0300 [thread overview]
Message-ID: <ake5YH7GsGFnkSPm@ashevche-desk.local> (raw)
In-Reply-To: <20260703130750.66549-1-mertseftali@web.de>
On Fri, Jul 03, 2026 at 03:07:50PM +0200, Mert Seftali wrote:
> in_accel_scale has returned -EINVAL ever since the driver was added.
You mean "Reading the in_accel_scale attribute ends up in returning..." ?
> The channels advertise scale via info_mask_shared_by_type, so the IIO
> core exposes in_accel_scale, but dmard09_read_raw() only handles
> IIO_CHAN_INFO_RAW;
> a SCALE read falls through to 'default: return
> -EINVAL':
This part is repetition of the first paragraph. Drop one of them.
> $ cat .../iio:deviceX/in_accel_scale
> cat: in_accel_scale: Invalid argument
>
> leaving userspace with raw counts it cannot convert to m/s^2.
>
> The driver was written from a vendor source [1] without a datasheet, and
> the scale was declared but never implemented. The vendor source carries
> the sensitivity: its conversion is
>
> acc = raw * GRAVITY_EARTH_1000 / sensitivity (then / 1000 -> m/s^2)
>
> with sensitivity = 32 and GRAVITY_EARTH_1000 = 9807 ("about
> (9.80665)*1000"), i.e. 32 counts correspond to 1 g.
>
> That sensitivity applies to the value this driver already reports as raw.
> The vendor processes each 16-bit sample as 'data >>= 3; data &= 0x1ff'
Try to write it more human and less programmish. Something like
"...16-bit sample as a signed 9-bit..." In other words, drop those technical
details, people can check the code by the link.
> plus a sign-extend of bit 8 - a signed 9-bit quantity from register bits
> [11:3] - and dmard09_read_raw()'s 'accel <<= 4; accel >>= 7' yields the
"...and in dmard09_read_raw() preparation yields the..."
> same value. It is self-consistent: 256 counts / 32 = 8 g full scale,
> matching the part's +/-8g range.
>
> Implement the scale derived from that sensitivity using standard gravity:
>
> scale = 9.80665 / 32 = 0.3064578125 m/s^2 per LSB
> [1] https://github.com/minstrelsy/mediatek/blob/1f49d8c87b839651bc89afc870277e8e0f2e2d55/custom/common/kernel/accelerometer/dmard09/dmard09.c
>
Make this a Link tag
Link: $URL [1]
> Fixes: a4fa6509dda4 ("iio: accel: add support for the Domintech DMARD09 3-axis accelerometer")
> Signed-off-by: Mert Seftali <mertsftl@gmail.com>
...
> +/* Sensitivity is 32 LSB/g; scale = 9.80665 / 32 m/s^2 per LSB. */
> +#define DMARD09_SCALE_NANO 306457813
I'm not sure how it's derived. Can we use more of calculations here instead of
precalculated value?
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-07-03 13:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-03 13:07 [PATCH] iio: accel: dmard09: Implement IIO_CHAN_INFO_SCALE Mert Seftali
2026-07-03 13:30 ` Andy Shevchenko [this message]
2026-07-03 13:32 ` Joshua Crofts
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=ake5YH7GsGFnkSPm@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jelle@vdwaa.nl \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mertsftl@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.