* iio: accel: dmard09: in_accel_scale always returns -EINVAL
@ 2026-06-17 15:53 Mert Seftali
2026-06-18 15:47 ` Maxwell Doose
2026-06-29 19:06 ` Jelle van der Waa
0 siblings, 2 replies; 8+ messages in thread
From: Mert Seftali @ 2026-06-17 15:53 UTC (permalink / raw)
To: jic23, jelle; +Cc: linux-iio, linux-kernel
Hi,
I've been digging into IIO to learn my way around it, and the dmard09
accelerometer driver caught my eye as I think its scale attribute has
been broken since day one, so I wanted to flag it.
The channels advertise scale:
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
which makes the core create in_accel_scale. The trouble is
dmard09_read_raw() never handles IIO_CHAN_INFO_SCALE, it only does
RAW, and SCALE drops straight into 'default: return -EINVAL'. So
reading the scale just errors out:
$ cat .../iio:deviceX/in_accel_scale
cat: in_accel_scale: Invalid argument
and userspace is left with raw counts it can't turn into m/s^2.
To be clear about how I found this: I don't have the hardware, I traced
it through the core (iio_read_channel_info() -> read_raw() with the
SCALE mask) rather than seeing it fail on a device. But the path looks
unambiguous.
I went looking to fix it properly; add a SCALE case returning the
sensitivity, the way dmard06 and dmard10 do, but I couldn't find a
DMARD09 datasheet anywhere. Digging through the list archives, it looks
like the scale was declared in the original 2016 submission but never
implemented, and the driver was written from a vendor source without a
datasheet to begin with. So I don't have a real number to use, and I'd
rather not make one up.
Hence the email instead of a patch: would you prefer to just drop the
scale declaration so the driver stops advertising something it can't
deliver, or does anyone happen to have the DMARD09 sensitivity so it
can be done right? I'm happy to send a patch either way.
Thanks,
Mert
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: iio: accel: dmard09: in_accel_scale always returns -EINVAL
2026-06-17 15:53 iio: accel: dmard09: in_accel_scale always returns -EINVAL Mert Seftali
@ 2026-06-18 15:47 ` Maxwell Doose
2026-06-18 16:08 ` Mert Seftali
2026-06-29 19:06 ` Jelle van der Waa
1 sibling, 1 reply; 8+ messages in thread
From: Maxwell Doose @ 2026-06-18 15:47 UTC (permalink / raw)
To: Mert Seftali; +Cc: jic23, jelle, linux-iio, linux-kernel
Hi Mert,
On Wed, Jun 17, 2026 at 11:10 AM Mert Seftali <mertsftl@gmail.com> wrote:
>
> Hi,
>
> I've been digging into IIO to learn my way around it, and the dmard09
> accelerometer driver caught my eye as I think its scale attribute has
> been broken since day one, so I wanted to flag it.
>
> The channels advertise scale:
>
> .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
>
> which makes the core create in_accel_scale. The trouble is
> dmard09_read_raw() never handles IIO_CHAN_INFO_SCALE, it only does
> RAW, and SCALE drops straight into 'default: return -EINVAL'. So
> reading the scale just errors out:
>
> $ cat .../iio:deviceX/in_accel_scale
> cat: in_accel_scale: Invalid argument
>
> and userspace is left with raw counts it can't turn into m/s^2.
>
Interesting, so userspace was broken from the start.
>
> To be clear about how I found this: I don't have the hardware, I traced
> it through the core (iio_read_channel_info() -> read_raw() with the
> SCALE mask) rather than seeing it fail on a device. But the path looks
> unambiguous.
>
> I went looking to fix it properly; add a SCALE case returning the
> sensitivity, the way dmard06 and dmard10 do, but I couldn't find a
> DMARD09 datasheet anywhere. Digging through the list archives, it looks
> like the scale was declared in the original 2016 submission but never
> implemented, and the driver was written from a vendor source without a
> datasheet to begin with. So I don't have a real number to use, and I'd
> rather not make one up.
>
If you can, try contacting the vendor, they may have a datasheet to
reference. Otherwise check Documentation/iio/ because sometimes
dev-written datasheets will end up in there.
>
> Hence the email instead of a patch: would you prefer to just drop the
> scale declaration so the driver stops advertising something it can't
> deliver, or does anyone happen to have the DMARD09 sensitivity so it
> can be done right? I'm happy to send a patch either way.
>
Perhaps the scale declaration should be dropped; I'd argue if it's
unimplemented it's dead, and dead code removal is always a good thing
:) Let's let the maintainer for this driver chime in first though
because I wonder if they might just want you to implement it.
--
best regards,
max
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: iio: accel: dmard09: in_accel_scale always returns -EINVAL
2026-06-18 15:47 ` Maxwell Doose
@ 2026-06-18 16:08 ` Mert Seftali
2026-06-19 7:20 ` Joshua Crofts
0 siblings, 1 reply; 8+ messages in thread
From: Mert Seftali @ 2026-06-18 16:08 UTC (permalink / raw)
To: Maxwell Doose; +Cc: jic23, jelle, linux-iio, linux-kernel
Hey Max,
Thanks for the reply and hints. I checked Documentation/ and the
bindings and dmard09 is only in
trivial-devices.yaml, no datasheet notes or scale anywhere in tree.
Will wait for the maintainers call and If they agree on
implementation, I'll try to reach Domintech for the datasheet first so
the scale is a real number.
Mert
Am Do., 18. Juni 2026 um 17:47 Uhr schrieb Maxwell Doose <m32285159@gmail.com>:
>
> Hi Mert,
>
> On Wed, Jun 17, 2026 at 11:10 AM Mert Seftali <mertsftl@gmail.com> wrote:
> >
> > Hi,
> >
> > I've been digging into IIO to learn my way around it, and the dmard09
> > accelerometer driver caught my eye as I think its scale attribute has
> > been broken since day one, so I wanted to flag it.
> >
> > The channels advertise scale:
> >
> > .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
> >
> > which makes the core create in_accel_scale. The trouble is
> > dmard09_read_raw() never handles IIO_CHAN_INFO_SCALE, it only does
> > RAW, and SCALE drops straight into 'default: return -EINVAL'. So
> > reading the scale just errors out:
> >
> > $ cat .../iio:deviceX/in_accel_scale
> > cat: in_accel_scale: Invalid argument
> >
> > and userspace is left with raw counts it can't turn into m/s^2.
> >
>
> Interesting, so userspace was broken from the start.
>
> >
> > To be clear about how I found this: I don't have the hardware, I traced
> > it through the core (iio_read_channel_info() -> read_raw() with the
> > SCALE mask) rather than seeing it fail on a device. But the path looks
> > unambiguous.
> >
> > I went looking to fix it properly; add a SCALE case returning the
> > sensitivity, the way dmard06 and dmard10 do, but I couldn't find a
> > DMARD09 datasheet anywhere. Digging through the list archives, it looks
> > like the scale was declared in the original 2016 submission but never
> > implemented, and the driver was written from a vendor source without a
> > datasheet to begin with. So I don't have a real number to use, and I'd
> > rather not make one up.
> >
>
> If you can, try contacting the vendor, they may have a datasheet to
> reference. Otherwise check Documentation/iio/ because sometimes
> dev-written datasheets will end up in there.
>
> >
> > Hence the email instead of a patch: would you prefer to just drop the
> > scale declaration so the driver stops advertising something it can't
> > deliver, or does anyone happen to have the DMARD09 sensitivity so it
> > can be done right? I'm happy to send a patch either way.
> >
>
> Perhaps the scale declaration should be dropped; I'd argue if it's
> unimplemented it's dead, and dead code removal is always a good thing
> :) Let's let the maintainer for this driver chime in first though
> because I wonder if they might just want you to implement it.
>
> --
> best regards,
> max
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: iio: accel: dmard09: in_accel_scale always returns -EINVAL
2026-06-18 16:08 ` Mert Seftali
@ 2026-06-19 7:20 ` Joshua Crofts
2026-06-19 12:10 ` Mert Seftali
0 siblings, 1 reply; 8+ messages in thread
From: Joshua Crofts @ 2026-06-19 7:20 UTC (permalink / raw)
To: Mert Seftali; +Cc: Maxwell Doose, jic23, jelle, linux-iio, linux-kernel
On Thu, 18 Jun 2026 18:08:58 +0200
Mert Seftali <mertsftl@gmail.com> wrote:
> Will wait for the maintainers call and If they agree on
> implementation, I'll try to reach Domintech for the datasheet first so
> the scale is a real number.
Did some research with Gemini and found out that Domintech went bust...
The cover letter for the original submission mentions that the driver
was essentially ported from the Android driver for the DMARD09 (the
Github link for it is dead).
FWIW I found a datasheet for the DMARD06, so maybe it could help
https://www.scribd.com/document/358640331/Accelerometer-DMARD06-Datasheet-V1-0-pdf
--
Kind regards
CJD
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: iio: accel: dmard09: in_accel_scale always returns -EINVAL
2026-06-19 7:20 ` Joshua Crofts
@ 2026-06-19 12:10 ` Mert Seftali
0 siblings, 0 replies; 8+ messages in thread
From: Mert Seftali @ 2026-06-19 12:10 UTC (permalink / raw)
To: Joshua Crofts; +Cc: Maxwell Doose, jic23, jelle, linux-iio, linux-kernel
Hi Joshua,
Thanks for digging into this, their bust explains the missing datasheet.
On the dmard06 sheet, i don't think it carries over though. dmard06 is
a different part as far as i understood: that driver works on an 8-bit
sample with its own scale,
while dmard09 does its own undocumented bit-twiddling on a 16-bit read
(the "<<4 >>7, remove lower
3 bits" dance). Different sample format, and dmard09's resolution isn't
even spelled out in the code, so even with dmard06's range i'd be
guessing dmard09's scale, which is the bit i wanted to avoid.
So unless the real dmard09 numbers turn up, dropping the dead scale
declaration still looks like the honest fix imo. Happy either way once
Jonathan weighs in.
Mert
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: iio: accel: dmard09: in_accel_scale always returns -EINVAL
2026-06-17 15:53 iio: accel: dmard09: in_accel_scale always returns -EINVAL Mert Seftali
2026-06-18 15:47 ` Maxwell Doose
@ 2026-06-29 19:06 ` Jelle van der Waa
2026-06-30 13:59 ` Mert Seftali
1 sibling, 1 reply; 8+ messages in thread
From: Jelle van der Waa @ 2026-06-29 19:06 UTC (permalink / raw)
To: Mert Seftali, jic23; +Cc: linux-iio, linux-kernel
Hi,
On 17/06/2026 17:53, Mert Seftali wrote:
> Hi,
>
> I've been digging into IIO to learn my way around it, and the dmard09
> accelerometer driver caught my eye as I think its scale attribute has
> been broken since day one, so I wanted to flag it.
>
> The channels advertise scale:
>
> .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
>
> which makes the core create in_accel_scale. The trouble is
> dmard09_read_raw() never handles IIO_CHAN_INFO_SCALE, it only does
> RAW, and SCALE drops straight into 'default: return -EINVAL'. So
> reading the scale just errors out:
>
> $ cat .../iio:deviceX/in_accel_scale
> cat: in_accel_scale: Invalid argument
>
> and userspace is left with raw counts it can't turn into m/s^2.
>
> To be clear about how I found this: I don't have the hardware, I traced
> it through the core (iio_read_channel_info() -> read_raw() with the
> SCALE mask) rather than seeing it fail on a device. But the path looks
> unambiguous.
>
> I went looking to fix it properly; add a SCALE case returning the
> sensitivity, the way dmard06 and dmard10 do, but I couldn't find a
> DMARD09 datasheet anywhere. Digging through the list archives, it looks
> like the scale was declared in the original 2016 submission but never
> implemented, and the driver was written from a vendor source without a
> datasheet to begin with. So I don't have a real number to use, and I'd
> rather not make one up.
Thanks for digging into this, I no longer have the device in question.
But the vendor driver can be found on GitHub:
https://github.com/minstrelsy/mediatek/blob/1f49d8c87b839651bc89afc870277e8e0f2e2d55/custom/common/kernel/accelerometer/dmard09/dmard09.c
Greetings,
Jelle van der Waa
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: iio: accel: dmard09: in_accel_scale always returns -EINVAL
2026-06-29 19:06 ` Jelle van der Waa
@ 2026-06-30 13:59 ` Mert Seftali
2026-07-03 0:55 ` Jonathan Cameron
0 siblings, 1 reply; 8+ messages in thread
From: Mert Seftali @ 2026-06-30 13:59 UTC (permalink / raw)
To: Jelle van der Waa; +Cc: jic23, linux-iio, linux-kernel
On Mon, 29 Jun 2026 21:06:..., Jelle van der Waa wrote:
> Thanks for digging into this, I no longer have the device in question.
> But the vendor driver can be found on GitHub:
>
> https://github.com/minstrelsy/mediatek/blob/.../dmard09/dmard09.c
Thanks Jelle, got this from the repository;
It has the sensitivity, and it's used in the driver's own conversion:
acc = raw * GRAVITY_EARTH_1000 / sensitivity (then / 1000 -> m/s^2)
with sensitivity = 32 and GRAVITY_EARTH_1000 = 9807 ("about
(9.80665)*1000" in the MTK header), so 32 counts == 1 g.
It also clears up that bit-twiddling i was worried about. The vendor does
'data >>= 3; data &= 0x1ff' plus a sign-extend of bit 8 on the 16-bit
read, i.e. a signed 9-bit value (register bits [11:3]), and our '<<4 >>7'
dance lands on the exact same number. So the 32 applies to what the driver
already returns as raw. Self consistent too: 256 / 32 = 8g, which matches
the +/-8g.
So this time i think we can implement it instead of dropping it:
scale = 9.80665 / 32 = 0.3064578125 m/s^2 per LSB
happy to send that Jonathan, it's the vendor's 32, so same
no-datasheet situation as before. or just drop the scale declaration if
you'd rather not. Whichever way you point.
Thanks,
Mert
Am Mo., 29. Juni 2026 um 21:06 Uhr schrieb Jelle van der Waa <jelle@vdwaa.nl>:
>
> Hi,
>
> On 17/06/2026 17:53, Mert Seftali wrote:
> > Hi,
> >
> > I've been digging into IIO to learn my way around it, and the dmard09
> > accelerometer driver caught my eye as I think its scale attribute has
> > been broken since day one, so I wanted to flag it.
> >
> > The channels advertise scale:
> >
> > .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
> >
> > which makes the core create in_accel_scale. The trouble is
> > dmard09_read_raw() never handles IIO_CHAN_INFO_SCALE, it only does
> > RAW, and SCALE drops straight into 'default: return -EINVAL'. So
> > reading the scale just errors out:
> >
> > $ cat .../iio:deviceX/in_accel_scale
> > cat: in_accel_scale: Invalid argument
> >
> > and userspace is left with raw counts it can't turn into m/s^2.
> >
> > To be clear about how I found this: I don't have the hardware, I traced
> > it through the core (iio_read_channel_info() -> read_raw() with the
> > SCALE mask) rather than seeing it fail on a device. But the path looks
> > unambiguous.
> >
> > I went looking to fix it properly; add a SCALE case returning the
> > sensitivity, the way dmard06 and dmard10 do, but I couldn't find a
> > DMARD09 datasheet anywhere. Digging through the list archives, it looks
> > like the scale was declared in the original 2016 submission but never
> > implemented, and the driver was written from a vendor source without a
> > datasheet to begin with. So I don't have a real number to use, and I'd
> > rather not make one up.
> Thanks for digging into this, I no longer have the device in question.
> But the vendor driver can be found on GitHub:
>
> https://github.com/minstrelsy/mediatek/blob/1f49d8c87b839651bc89afc870277e8e0f2e2d55/custom/common/kernel/accelerometer/dmard09/dmard09.c
>
> Greetings,
>
> Jelle van der Waa
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: iio: accel: dmard09: in_accel_scale always returns -EINVAL
2026-06-30 13:59 ` Mert Seftali
@ 2026-07-03 0:55 ` Jonathan Cameron
0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2026-07-03 0:55 UTC (permalink / raw)
To: Mert Seftali; +Cc: Jelle van der Waa, linux-iio, linux-kernel
On Tue, 30 Jun 2026 15:59:59 +0200
Mert Seftali <mertsftl@gmail.com> wrote:
> On Mon, 29 Jun 2026 21:06:..., Jelle van der Waa wrote:
> > Thanks for digging into this, I no longer have the device in question.
> > But the vendor driver can be found on GitHub:
> >
> > https://github.com/minstrelsy/mediatek/blob/.../dmard09/dmard09.c
>
> Thanks Jelle, got this from the repository;
>
> It has the sensitivity, and it's used in the driver's own conversion:
>
> acc = raw * GRAVITY_EARTH_1000 / sensitivity (then / 1000 -> m/s^2)
>
> with sensitivity = 32 and GRAVITY_EARTH_1000 = 9807 ("about
> (9.80665)*1000" in the MTK header), so 32 counts == 1 g.
>
> It also clears up that bit-twiddling i was worried about. The vendor does
> 'data >>= 3; data &= 0x1ff' plus a sign-extend of bit 8 on the 16-bit
> read, i.e. a signed 9-bit value (register bits [11:3]), and our '<<4 >>7'
> dance lands on the exact same number. So the 32 applies to what the driver
> already returns as raw. Self consistent too: 256 / 32 = 8g, which matches
> the +/-8g.
>
> So this time i think we can implement it instead of dropping it:
>
> scale = 9.80665 / 32 = 0.3064578125 m/s^2 per LSB
>
> happy to send that Jonathan, it's the vendor's 32, so same
> no-datasheet situation as before. or just drop the scale declaration if
> you'd rather not. Whichever way you point.
Thanks for digging into this. Ideally good to fix it if we can rather
than just dropping the support. If it looks doubtful dropping is fine
given it never worked anyway so it's not a regression :)
Which is basically me saying I'll take either - up to you!
Jonathan
>
>
> Thanks,
> Mert
>
>
> Am Mo., 29. Juni 2026 um 21:06 Uhr schrieb Jelle van der Waa <jelle@vdwaa.nl>:
> >
> > Hi,
> >
> > On 17/06/2026 17:53, Mert Seftali wrote:
> > > Hi,
> > >
> > > I've been digging into IIO to learn my way around it, and the dmard09
> > > accelerometer driver caught my eye as I think its scale attribute has
> > > been broken since day one, so I wanted to flag it.
> > >
> > > The channels advertise scale:
> > >
> > > .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
> > >
> > > which makes the core create in_accel_scale. The trouble is
> > > dmard09_read_raw() never handles IIO_CHAN_INFO_SCALE, it only does
> > > RAW, and SCALE drops straight into 'default: return -EINVAL'. So
> > > reading the scale just errors out:
> > >
> > > $ cat .../iio:deviceX/in_accel_scale
> > > cat: in_accel_scale: Invalid argument
> > >
> > > and userspace is left with raw counts it can't turn into m/s^2.
> > >
> > > To be clear about how I found this: I don't have the hardware, I traced
> > > it through the core (iio_read_channel_info() -> read_raw() with the
> > > SCALE mask) rather than seeing it fail on a device. But the path looks
> > > unambiguous.
> > >
> > > I went looking to fix it properly; add a SCALE case returning the
> > > sensitivity, the way dmard06 and dmard10 do, but I couldn't find a
> > > DMARD09 datasheet anywhere. Digging through the list archives, it looks
> > > like the scale was declared in the original 2016 submission but never
> > > implemented, and the driver was written from a vendor source without a
> > > datasheet to begin with. So I don't have a real number to use, and I'd
> > > rather not make one up.
> > Thanks for digging into this, I no longer have the device in question.
> > But the vendor driver can be found on GitHub:
> >
> > https://github.com/minstrelsy/mediatek/blob/1f49d8c87b839651bc89afc870277e8e0f2e2d55/custom/common/kernel/accelerometer/dmard09/dmard09.c
> >
> > Greetings,
> >
> > Jelle van der Waa
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-07-03 0:55 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-17 15:53 iio: accel: dmard09: in_accel_scale always returns -EINVAL Mert Seftali
2026-06-18 15:47 ` Maxwell Doose
2026-06-18 16:08 ` Mert Seftali
2026-06-19 7:20 ` Joshua Crofts
2026-06-19 12:10 ` Mert Seftali
2026-06-29 19:06 ` Jelle van der Waa
2026-06-30 13:59 ` Mert Seftali
2026-07-03 0:55 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox