The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/3] iio: lsm303dlh-magn: endianness + boot-time fullscale selection
@ 2026-06-05 10:08 Herman van Hazendonk
  2026-06-05 10:08 ` [PATCH 1/3] iio: common: st_sensors: honour channel endianness in read_axis_data Herman van Hazendonk
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Herman van Hazendonk @ 2026-06-05 10:08 UTC (permalink / raw)
  To: jic23, linusw, denis.ciocca, robh, krzk+dt, conor+dt
  Cc: dlechner, nuno.sa, andy, sanjayembeddedse, maudspierings,
	linux-iio, devicetree, linux-kernel, Herman van Hazendonk

This series fixes two independent issues that together prevent the
LSM303DLH magnetometer from delivering usable readings out of the
box on at least the HP TouchPad (apq8060), and adds a small generic
extension to the ST sensors device-tree binding to allow boards to
declare a non-default initial full-scale.

PATCH 1/3 fixes st_sensors_core's read_axis_data() helper to honour
the channel's declared scan_type.endianness. The helper has
unconditionally decoded multi-byte results as little-endian since
it was introduced. Every other in-tree ST sensor declares IIO_LE
and was unaffected, but the LSM303DLH magnetometer publishes its
X / Y / Z words as big-endian pairs (high byte at the lower
register address, 0x03 / 0x05 / 0x07) and its channel specs in
st_magn_core.c correctly declare IIO_BE. The mismatch swapped the
high and low bytes of every magnetometer sample. The fix is generic
and only affects the IIO_BE branch; existing IIO_LE consumers are
untouched.

PATCH 2/3 adds an optional `st,fullscale-mg` device-tree property
to the ST sensors binding. The driver core hardcodes fs_avl[0] (the
highest-sensitivity range) as the starting full-scale, which is the
right default for a desk-noise floor but leaves no margin for
boards that pick up DC bias from nearby PCB structures. The
property lets a board declare the initial range in milligauss, with
the driver falling back to its built-in default on absence or on an
unsupported value. The property is purely additive and no in-tree
DTS is affected.

PATCH 3/3 parses st,fullscale-mg in the magnetometer common probe
and selects the matching fs_avl entry. The LSM303DLH on the HP
TouchPad picks up enough DC bias from the surrounding power planes
that the chip-default +/-1.3 G range saturates the X axis to the
chip's 0xF000 overflow sentinel on every sample, while Y and Z fall
within range. Empirically any fs_avl >= 1 (+/-1.9 G and up) works;
on tenderloin the appropriate value is 2500 mg (+/-2.5 G).

Before this series, on the HP TouchPad with the magnetometer flat
on a stable surface (sysfs in_magn_x_raw / in_magn_y_raw /
in_magn_z_raw, 15 reads at 200 ms intervals):

  X = 240             (high byte stuck at 0x00, low byte = 0xF0)
  Y = 12032..23296    (apparent random walk over ~11 K range)
  Z = -16128..-9728   (apparent random walk over ~6 K range)

After PATCH 1/3 alone (endianness fix), the chip reports its real
overflow sentinel for X:

  X = -4096           (= 0xF000, chip's saturation marker)
  Y =  91..103        (tight, sensible field reading)
  Z = 173..184        (tight, sensible field reading)

After the full series with st,fullscale-mg=2500 on tenderloin:

  X = -384..-403      (tight, sensible field reading)
  Y =   47..58
  Z =   96..108

Spans of 14..20 raw counts at scale 0.000670 G/LSB across all axes,
matching expected chip noise around the ambient DC bias.

PATCH 1/3 is a standalone bug fix and could be applied on its own
even if the binding extension is rejected. PATCHES 2/3 and 3/3 form
a unit.


Herman van Hazendonk (3):
  iio: common: st_sensors: honour channel endianness in read_axis_data
  dt-bindings: iio: st,st-sensors: add st,fullscale-mg
  iio: magnetometer: st_magn: honour st,fullscale-mg DT property

 .../bindings/iio/st,st-sensors.yaml           | 18 ++++++++++
 .../iio/common/st_sensors/st_sensors_core.c   | 19 +++++++---
 drivers/iio/magnetometer/st_magn_core.c       | 35 +++++++++++++++++++
 3 files changed, 67 insertions(+), 5 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-06-05 17:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-05 10:08 [PATCH 0/3] iio: lsm303dlh-magn: endianness + boot-time fullscale selection Herman van Hazendonk
2026-06-05 10:08 ` [PATCH 1/3] iio: common: st_sensors: honour channel endianness in read_axis_data Herman van Hazendonk
2026-06-05 17:47   ` Andy Shevchenko
2026-06-05 10:08 ` [PATCH 2/3] dt-bindings: iio: st,st-sensors: add st,fullscale-mg Herman van Hazendonk
2026-06-05 16:07   ` Conor Dooley
2026-06-05 10:08 ` [PATCH 3/3] iio: magnetometer: st_magn: honour st,fullscale-mg DT property Herman van Hazendonk
2026-06-05 17:52   ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox