From: Herman van Hazendonk <github.com@herrie.org>
To: jic23@kernel.org, linusw@kernel.org, denis.ciocca@st.com,
robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org
Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
sanjayembeddedse@gmail.com, maudspierings@gocontroll.com,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
Herman van Hazendonk <github.com@herrie.org>
Subject: [PATCH 0/3] iio: lsm303dlh-magn: endianness + boot-time fullscale selection
Date: Fri, 5 Jun 2026 12:08:40 +0200 [thread overview]
Message-ID: <cover.1780652883.git.github.com@herrie.org> (raw)
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
next reply other threads:[~2026-06-05 10:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 10:08 Herman van Hazendonk [this message]
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
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=cover.1780652883.git.github.com@herrie.org \
--to=github.com@herrie.org \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=denis.ciocca@st.com \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maudspierings@gocontroll.com \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=sanjayembeddedse@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox