-
Notifications
You must be signed in to change notification settings - Fork 912
Description
This is not adis16XXX driver bug, actualy is IIO subsystem bug.
I use adis16505-2 on armv7l soc with spi, kernel version 6.1. In iio sysfs, anglvel and accel scale is:
# anglvel scale
cat /sys/bus/iio/devices/iio\:device1/in_anglvel_scale
0.000000006
# accel scale
cat /sys/bus/iio/devices/iio\:device1/in_accel_scale
0.000000037But ref the datasheet and driver code , anglvel(gyro) scale and accel scale should be
gyro: 1/IIO_RAD_TO_DEGREE(40 << 16) => 6.657902725198096e-09
accel(driver): 78.0 /(32000 << 16) => 3.719329833984375e-08
accel(datasheet): 2.45 * 1E-3 / (2**16) => 3.7384033203125005e-08
Compare to these, the sysfs scale lost much precision, especially gyro lost 10% precision.
The sysfs output ref function __iio_format_value of type IIO_VAL_FRACTIONAL :
linux/drivers/iio/industrialio-core.c
Lines 671 to 678 in 10d2a5d
| case IIO_VAL_FRACTIONAL: | |
| tmp2 = div_s64((s64)vals[0] * 1000000000LL, vals[1]); | |
| tmp0 = (int)div_s64_rem(tmp2, 1000000000, &tmp1); | |
| if ((tmp2 < 0) && (tmp0 == 0)) | |
| return sysfs_emit_at(buf, offset, "-0.%09u", abs(tmp1)); | |
| else | |
| return sysfs_emit_at(buf, offset, "%d.%09u", tmp0, | |
| abs(tmp1)); |
Only preserve 9 number after zero point, not enough for adis16505-2 scale.
I don't know how to fix it properly, kernel has not float point, I suppose using scientific notation for fractional values will has no probem.
I know it is not analog driver bug, but it affect usability of adis16xxx imu with iio drivers.