iio: accel: dmard09: Implement IIO_CHAN_INFO_SCALE
PATCH v2 1/1 iio: accel: dmard09: Implement IIO_CHAN_INFO_SCALE
Reading the in_accel_scale attribute on the DMARD09 has always returned -EINVAL: the channels advertise scale via info_mask_shared_by_type so the IIO core exposes the attribute, but dmard09_read_raw() only handles IIO_CHAN_INFO_RAW, so a SCALE read falls through to 'default: return -EINVAL':
$ cat .../iio:deviceX/in_accel_scale
cat: in_accel_scale: Invalid argumentleaving 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 reduces each 16-bit sample to a signed 9-bit value, and the preparation in dmard09_read_raw() yields the same value. It is
self-consistent: 256 counts / 32 = 8 g full scale, matching the +/-8g range.
Implement the scale derived from that sensitivity using standard gravity:
scale = 9.80665 / 32 = 0.3064578125 m/s^2 per LSB
---
Changes in v2:
- Reword the opening around reading the attribute and merge the duplicated explanation into it.
- Describe the sample as a signed 9-bit value in plain language instead of the register bit operations (the vendor code is in the link).
- Turn the vendor-source URL into a Link: tag.
- Express the scale via the IIO_G_TO_M_S_2() helper instead of a precomputed constant.
- Add a blank line before the return in the SCALE case.
drivers/iio/accel/dmard09.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/iio/accel/dmard09.c +7 -0
@@ -8,6 +8,7 @@#include <linux/unaligned.h> #include <linux/module.h> #include <linux/i2c.h> +#include <linux/units.h> #include <linux/iio/iio.h> #define DMARD09_DRV_NAME "dmard09"
@@ -79,6 +80,12 @@ static int dmard09_read_raw(struct iio_dev *indio_dev, *val = accel;return IIO_VAL_INT ; +case IIO_CHAN_INFO_SCALE : + *val =0 ; +/* 1 g / 32 LSB, in m/s^2 */ + *val2 =IIO_G_TO_M_S_2 (NANO /32 ); + +return IIO_VAL_INT_PLUS_NANO ;default :return -EINVAL ; }
Signature · 1 line
2.55.0
Quoted 26 lines · On Fri, 10 Jul 2026 10:36:23 +0200 Mert Seftali <[email protected]> wrote:
Reading the
in_accel_scaleattribute on the DMARD09 has always returned-EINVAL: the channels advertise scale viainfo_mask_shared_by_typeso the IIO core exposes the attribute, butdmard09_read_raw()only handlesIIO_CHAN_INFO_RAW, so a SCALE read falls through to 'default: return-EINVAL':$ cat .../iio:deviceX/in_accel_scale cat: in_accel_scale: Invalid argumentleaving 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 reduces each 16-bit sample to a signed 9-bit value, and the preparation indmard09_read_raw()yields the same value. It is
self-consistent: 256 counts / 32 = 8 g full scale, matching the +/-8g range.
Quoted 8 lines
Implement the scale derived from that sensitivity using standard gravity:
scale = 9.80665 / 32 = 0.3064578125 m/s^2 per LSBFixes a4fa6509dda4 ("iio: accel: add support for the Domintech DMARD09 3-axis accelerometer")Signed-off-by Mert Seftali <[email protected]>---
Good thing that Jelle sent the vendor driver, LGTM.
Signature · 3 lines
Kind regards CJD
Quoted 31 lines · On Fri, 10 Jul 2026 10:51:09 +0200 Joshua Crofts <[email protected]>…
Quoted 28 lines · On Fri, 10 Jul 2026 10:36:23 +0200 Mert Seftali <[email protected]> wrote:
Reading the
in_accel_scaleattribute on the DMARD09 has always returned-EINVAL: the channels advertise scale viainfo_mask_shared_by_typeso the IIO core exposes the attribute, butdmard09_read_raw()only handlesIIO_CHAN_INFO_RAW, so a SCALE read falls through to 'default: return-EINVAL':$ cat .../iio:deviceX/in_accel_scale cat: in_accel_scale: Invalid argumentleaving 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 reduces each 16-bit sample to a signed 9-bit value, and the preparation indmard09_read_raw()yields the same value. It is
self-consistent: 256 counts / 32 = 8 g full scale, matching the +/-8g range.Implement the scale derived from that sensitivity using standard gravity:
Quoted 8 lines
Quoted 6 lines
scale = 9.80665 / 32 = 0.3064578125 m/s^2 per LSBFixes a4fa6509dda4 ("iio: accel: add support for the Domintech DMARD09 3-axis accelerometer")Signed-off-by Mert Seftali <[email protected]>---
Good thing that Jelle sent the vendor driver, LGTM.
Indeed
Quoted 3 lines
Reviewed-by Joshua Crofts <[email protected]>
Applied to the testing branch of iio.git. It's been broken from the start, so whilst it is a fix, I'm not rushing to get it upstream!
Thanks,
Jonathan