Devicetree
 help / color / mirror / Atom feed
* [PATCH v2 0/3] iio: lsm303dlh-magn: endianness + boot-time fullscale selection
@ 2026-06-16 13:02 Herman van Hazendonk
  2026-06-16 13:02 ` [PATCH v2 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-16 13:02 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Denis Ciocca, Lars-Peter Clausen, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Denis Ciocca, Linus Walleij
  Cc: linux-iio, linux-kernel, llvm, devicetree, stable,
	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 / LSM303DLHC / LSM303DLM
magnetometers all bind st_magn_16bit_channels (IIO_BE) and publish
their X / Y / Z words as big-endian pairs (high byte at the lower
register address, 0x03 / 0x05 / 0x07). The mismatch swapped the
high and low bytes of every magnetometer sample on these three
parts. The fix only affects the IIO_BE branch; existing IIO_LE
consumers are untouched.

PATCH 2/3 adds an optional st,fullscale-milligauss 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 is scoped to magnetometer compatibles
via per-family enum clauses so DTSes with a misspelled value, or
that put the property on accel/gyro/pressure or fixed-FS magn
nodes, fail dt_binding_check rather than being silently no-op'd at
runtime.

PATCH 3/3 parses st,fullscale-milligauss 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).

PATCH 1/3 is a standalone bug fix and is now Cc'd to stable;
PATCHES 2/3 and 3/3 form a unit.

Changes since v1
~~~~~~~~~~~~~~~~

PATCH 1/3 (endianness):
  - Restructure around a single u32 tmp + one trailing
    sign_extend32(tmp, BYTES_TO_BITS(byte_for_channel) - 1), drop
    the (s16) / (s32) casts (Andy Shevchenko).
  - Make byte_for_channel == 0 || >= 4 an explicit -EINVAL return
    (no in-tree caller hits this, but the prior code silently left
    *data uninitialised).
  - Add Fixes: 23491b513bcd ("iio:common: Add STMicroelectronics
    common library") and Cc: stable@vger.kernel.org (Jonathan
    Cameron). The bug has been present since the helper was
    introduced in 2013.
  - Spell out that the fix changes in_magn_*_raw decoding for
    LSM303DLHC and LSM303DLM too (same IIO_BE channel set), not
    only LSM303DLH.

PATCH 2/3 (binding):
  - Rename st,fullscale-mg to st,fullscale-milligauss. "-mg" is
    the DT unit-suffix convention but already names milli-g in
    the accelerometer parts of this same binding file; spelling
    milligauss out keeps the unit unambiguous if a similar
    tunable is ever added for accel/gyro/pressure.
  - Scope the property to magnetometer compatibles via per-family
    allOf:if-then enum clauses:
      LSM303DLH/DLHC/DLM: enum [1300, 1900, 2500, 4000, 4700,
                                5600, 8100]
      LIS3MDL/LSM9DS1/LSM303C: enum [4000, 8000, 12000, 16000]
      LSM303AGR/LIS2MDL/IIS2MDC (fixed FS): rejected outright
      everything else (accel/gyro/pressure/IMU): rejected outright
  - Drop the "(or analogous engineering units for other sensor
    families that may grow this property in the future)" hand-wave
    from the description (Jonathan Cameron); the property is now
    positively bound to magnetometers only.
  - Drop the overstated "userspace cannot recover without racing
    the driver" wording; document the actual probe-time window
    (the in-tree IIO consumers cache the saturation sentinel
    before any UDEV rule fires).
  - Add an in-file maintenance comment before the catch-all NOT
    clause so future contributors who add a new magnetometer
    compatible know all four clauses must be updated together.

PATCH 3/3 (driver):
  - Honour the rename to st,fullscale-milligauss.
  - Restructure per Andy: const char *propname at the top,
    device_property_present() pre-check, device_property_read_u32()
    error path with explicit return.
  - Gate the parse block on mdata->sensor_settings->fs.addr != 0
    as defence in depth; the binding already rejects the property
    on fixed-FS magnetometers, the gate keeps the code path
    self-contained against stale DTBs.

To: Jonathan Cameron <jic23@kernel.org>
To: David Lechner <dlechner@baylibre.com>
To: Nuno Sá <nuno.sa@analog.com>
To: Andy Shevchenko <andy@kernel.org>
To: Nathan Chancellor <nathan@kernel.org>
To: Nick Desaulniers <nick.desaulniers+lkml@gmail.com>
To: Bill Wendling <morbo@google.com>
To: Justin Stitt <justinstitt@google.com>
To: Denis Ciocca <denis.ciocca@gmail.com>
To: Lars-Peter Clausen <lars@metafoo.de>
To: Rob Herring <robh@kernel.org>
To: Krzysztof Kozlowski <krzk+dt@kernel.org>
To: Conor Dooley <conor+dt@kernel.org>
To: Denis Ciocca <denis.ciocca@st.com>
To: Linus Walleij <linusw@kernel.org>
Cc: linux-iio@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: llvm@lists.linux.dev
Cc: devicetree@vger.kernel.org
v1: https://lore.kernel.org/linux-iio/cover.1780652883.git.github.com@herrie.org/

base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
change-id: 20260616-submit-iio-lsm303dlh-magn-fixes-48153433b301
---
Herman van Hazendonk (3):
      iio: common: st_sensors: honour channel endianness in read_axis_data
      dt-bindings: iio: st,st-sensors: add st,fullscale-milligauss
      iio: magnetometer: st_magn: honour st,fullscale-milligauss DT property

 .../devicetree/bindings/iio/st,st-sensors.yaml     | 71 ++++++++++++++++++++++
 drivers/iio/common/st_sensors/st_sensors_core.c    | 23 +++++--
 drivers/iio/magnetometer/st_magn_core.c            | 32 ++++++++++
 3 files changed, 120 insertions(+), 6 deletions(-)
---
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
change-id: 20260616-submit-iio-lsm303dlh-magn-fixes-48153433b301

Best regards,
-- 
Herman van Hazendonk <github.com@herrie.org>


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

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

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

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