From nobody Mon Jun 8 06:35:56 2026 Received: from outbound1.mail.transip.nl (outbound1.mail.transip.nl [149.210.149.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEB9E378D9C; Fri, 5 Jun 2026 10:08:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=149.210.149.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780654134; cv=none; b=uWUZ/k8AA7Ee7ZMIf6Ki39Xq0IkQIiEq4wsBPSH6MGL9vOR4OI4hlIz2n7Hmksi6K+HKvZPbQI6Wu7iPPyT6Hb19KovpqKQ8FS9mOSfC8BwsxmJNdYNCHOJrftGfSHNJGiEvZQEsSOzM2PORzOsWFF88i1xKA+mnJqVsB/lMrAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780654134; c=relaxed/simple; bh=vIJDzY22/pR5PVFHnxAxJReqIhW7CHx+PE8fszsXqVM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hriyuNiJnn71v686QbyuBRLH141MejwNbF5oork4/2avCYsEDVZaOOAQzZ3Y0R3RcoLe6BlsAyECuTcDdohs2TF8qkeHE13kmxVf/KWDNZmItz4r3hZJYzLUy0AxI/qtgYo/uw7LowfvHf6F//6sppOX9rRCY5F4sky2dJ3zoLo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=herrie.org; spf=pass smtp.mailfrom=herrie.org; dkim=pass (2048-bit key) header.d=herrie.org header.i=@herrie.org header.b=C5oTZjrc; arc=none smtp.client-ip=149.210.149.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=herrie.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=herrie.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=herrie.org header.i=@herrie.org header.b="C5oTZjrc" Received: from submission4.mail.transip.nl (unknown [10.103.8.155]) by outbound1.mail.transip.nl (Postfix) with ESMTP id 4gWxwY4SbvzRj3L; Fri, 5 Jun 2026 12:08:45 +0200 (CEST) Received: from herrie-desktop.. (180-93-184-31.ftth.glasoperator.nl [31.184.93.180]) by submission4.mail.transip.nl (Postfix) with ESMTPA id 4gWxwX6rLzz3R3p02; Fri, 5 Jun 2026 12:08:44 +0200 (CEST) From: Herman van Hazendonk 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 Subject: [PATCH 1/3] iio: common: st_sensors: honour channel endianness in read_axis_data Date: Fri, 5 Jun 2026 12:08:41 +0200 Message-ID: <0dac8e8e2872dc180b138923b5cd4fd18eee047b.1780652883.git.github.com@herrie.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: ClueGetter at submission4.mail.transip.nl DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=transip-a; d=herrie.org; t=1780654125; h=from:subject:to:cc: references:in-reply-to:date:mime-version:content-type; bh=u8xxJRCo95FdjbzXYIN6cwNdNtoDj6gaprfSMe/H9M0=; b=C5oTZjrcmM3BRd4UrxRVd3qRPJgM5+HscVMm6OIAiqcNP5YPpOsn1sG547GpnVGSxrah3Y nL9abxNVm9bjGn00YNccAgpcd7qyP7rfJhxUyZMUF3V6yqxp4mWg5ugxBNRZZsvhVk2U28 mhyOhfnLqGJ9UAFr4WSCX0J2PEPdbzwZamZje3Kd5bozUFEZnpTemc6Ab1JG/ux/YufeF9 xXjfLQ/rpITAZAePfvOGEk/cmrBHJfjinAJPVQglnYQfH0DtU4TSu/Q+6N16wMxMCAW3CN yzCQ6JZIqAuF4sxAIpflI2jqulBxqd8x3FC9apGuB7IvmaCc5/7cs3ASPEKjAA== X-Report-Abuse-To: abuse@transip.nl st_sensors_read_axis_data() unconditionally decoded multi-byte results with get_unaligned_le16() / get_unaligned_le24() regardless of the channel's declared scan_type.endianness. For every ST sensor that has used this helper since it was introduced this happened to be fine because the ST IMU/accel/gyro/pressure families publish their data registers as little-endian and the channel specs in those drivers declare IIO_LE accordingly. The LSM303DLH magnetometer however publishes its X/Y/Z output as a pair of big-endian bytes (the H register sits at the lower address, 0x03/0x05/0x07, and the L register immediately after), and its channel specs in st_magn_core.c correctly declare IIO_BE -- but read_axis_data() ignored that and decoded as little-endian, swapping the high and low bytes of every magnetometer sample. The bug is most visible on a stationary chip: in earth's field the true X reading is small and the high byte sits at 0x00, so swapping the bytes pins sysfs X at exactly the low byte's pattern (e.g. 0x00F0 =3D 240). Y and Z still appear "to vary" because their magnitudes are larger and the noise in the low byte produces big swings in the swapped high byte: before (chip flat, sysfs in_magn_*_raw): X=3D240 (stuck), Y=3D 12032..23296, Z=3D-16128..-9728 after (direct i2c-dev big-endian decode, same chip same orientation): X=E2=89=88-4096, Y=E2=89=88210, Z=E2=89=8880 (sensible values ref= lecting earth's ambient field at low gauss range) Fix read_axis_data() to dispatch on ch->scan_type.endianness and call get_unaligned_be16() / get_unaligned_be24() when the channel declares IIO_BE. Existing IIO_LE consumers (st_accel, st_gyro, st_pressure, st_lsm6dsx and others) are unaffected because their channel specs already declare IIO_LE and the LE path is unchanged. Signed-off-by: Herman van Hazendonk --- .../iio/common/st_sensors/st_sensors_core.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/= common/st_sensors/st_sensors_core.c index dbc5e16fbde4..84bce1539908 100644 --- a/drivers/iio/common/st_sensors/st_sensors_core.c +++ b/drivers/iio/common/st_sensors/st_sensors_core.c @@ -508,12 +508,21 @@ static int st_sensors_read_axis_data(struct iio_dev *= indio_dev, if (err < 0) return err; =20 - if (byte_for_channel =3D=3D 1) + if (byte_for_channel =3D=3D 1) { *data =3D (s8)*outdata; - else if (byte_for_channel =3D=3D 2) - *data =3D (s16)get_unaligned_le16(outdata); - else if (byte_for_channel =3D=3D 3) - *data =3D (s32)sign_extend32(get_unaligned_le24(outdata), 23); + } else if (byte_for_channel =3D=3D 2) { + if (ch->scan_type.endianness =3D=3D IIO_BE) + *data =3D (s16)get_unaligned_be16(outdata); + else + *data =3D (s16)get_unaligned_le16(outdata); + } else if (byte_for_channel =3D=3D 3) { + if (ch->scan_type.endianness =3D=3D IIO_BE) + *data =3D (s32)sign_extend32(get_unaligned_be24(outdata), + 23); + else + *data =3D (s32)sign_extend32(get_unaligned_le24(outdata), + 23); + } =20 return 0; } --=20 2.43.0 From nobody Mon Jun 8 06:35:56 2026 Received: from outbound0.mail.transip.nl (outbound0.mail.transip.nl [149.210.149.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFC703CE0A1; Fri, 5 Jun 2026 10:08:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=149.210.149.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780654137; cv=none; b=oMFyJafBgXChQnkH4WIJ/PbWTDEYVbLXUTPteqJNFayj3fdWVze2hgzUmASnYP/DFnWwHl/X9mhUuPrLLh/x/botdA7n4bV0ylmjUEFTbatYRrKGcobT8D/CecrWyP6ijyEOAjuPVgdGdJBfvkbpoNtkYusVo2GhJC9pk92JX34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780654137; c=relaxed/simple; bh=tC0kyB9BK6SOo8GI5KsOX8ZAJbre+gCaY1tRs4yAu9c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SYyCXSeAJ0mG+NhrnNu0jH2ccfO5XdCfya1ga6sVpT32gG6BdggsOVoPpOu7P41VIlcsH/2Va6Uw5hAabX3BouKu99B39ztiYM91/6DJd8sRRA2PSkKwczf3EX4HdZQA2uyJWFFHeucDk3j8A+Yv0o7mqp3m2Y+GgtwDGrTOfMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=herrie.org; spf=pass smtp.mailfrom=herrie.org; dkim=pass (2048-bit key) header.d=herrie.org header.i=@herrie.org header.b=I9ipa7eX; arc=none smtp.client-ip=149.210.149.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=herrie.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=herrie.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=herrie.org header.i=@herrie.org header.b="I9ipa7eX" Received: from submission4.mail.transip.nl (unknown [10.103.8.155]) by outbound0.mail.transip.nl (Postfix) with ESMTP id 4gWxwZ1y2QzxPMS; Fri, 5 Jun 2026 12:08:46 +0200 (CEST) Received: from herrie-desktop.. (180-93-184-31.ftth.glasoperator.nl [31.184.93.180]) by submission4.mail.transip.nl (Postfix) with ESMTPA id 4gWxwY4fB1z3R3p03; Fri, 5 Jun 2026 12:08:45 +0200 (CEST) From: Herman van Hazendonk 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 Subject: [PATCH 2/3] dt-bindings: iio: st,st-sensors: add st,fullscale-mg Date: Fri, 5 Jun 2026 12:08:42 +0200 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: ClueGetter at submission4.mail.transip.nl DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=transip-a; d=herrie.org; t=1780654125; h=from:subject:to:cc: references:in-reply-to:date:mime-version; bh=XKJowAeDiAVcG9eyEc4OrgXmXamMxeJkeFMuCHuDvPw=; b=I9ipa7eXR04FsMnaejEeS+uFMjFLferYWZJp11sDc8yzkxUXENdr8FAKHgn1R1UeKkaWce VV36qtAvDiCuKMvI9J+773yLDinRxAoIaNva2isYzbFzH1K+GzJGzTFnCbkPNEjBzOLEiC pDzFcgFdNzNGUUIib6dHWdCBIu3C/GeDHd8ZpKAkza0D1qZvFuFoJYvT79ns1Gpn35YnEt duM3KhKrW11mUb8LbnuQxkBKPXLHouJt9mX/5pKJdS5vcLfuvPO/rp1lgqo7kHNdEPQ3ko YLMw1hBnPhf42XctkXiZ8TheYVbYy9mzKKaN8i7Ur1fOUo+TVdF8oCDd/sU/nw== X-Report-Abuse-To: abuse@transip.nl Content-Type: text/plain; charset="utf-8" Add an optional st,fullscale-mg property that selects the initial full-scale range of an ST MEMS sensor at probe time, expressed in milligauss for magnetometers (and analogous engineering units for other ST sensor families that may grow this property in the future). The property is purely additive: if absent, drivers fall back to their existing chip default, and if present but unsupported by the specific sensor the driver warns and falls back. No existing in-tree DTS is affected. The motivating case is the LSM303DLH magnetometer on the HP TouchPad (apq8060 / tenderloin) where the kernel's chip-default +/-1.3 G range saturates the X axis to the chip's 0xF000 overflow sentinel out of probe, because the chip is mounted close to surrounding power planes and picks up enough DC bias to exceed the smallest range. The driver core hardcodes fs_avl[0] as the starting range, so userspace cannot recover without racing the driver to write the in_magn_x_scale sysfs attribute after probe. st,fullscale-mg lets the device tree declare a wider initial range up-front and avoids the race entirely. Signed-off-by: Herman van Hazendonk Acked-by: Conor Dooley Reviewed-by: Linus Walleij --- .../devicetree/bindings/iio/st,st-sensors.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/st,st-sensors.yaml b/Doc= umentation/devicetree/bindings/iio/st,st-sensors.yaml index a1a958215cdb..335f38e9f78f 100644 --- a/Documentation/devicetree/bindings/iio/st,st-sensors.yaml +++ b/Documentation/devicetree/bindings/iio/st,st-sensors.yaml @@ -126,6 +126,24 @@ properties: mount-matrix: description: an optional 3x3 mounting rotation matrix. =20 + st,fullscale-mg: + description: | + Selects the initial sensor full-scale at probe time, expressed in + milligauss for magnetometers (or analogous engineering units for + other sensor families that may grow this property in the future). + The value must match one of the sensor-specific full-scale ranges + supported by the chip; if the chip does not support the requested + range the driver falls back to its built-in default. + + This is intended for boards where the magnetometer chip picks up + enough DC bias from nearby PCB structures (power planes, ferrous + shields, etc.) that the kernel's chip-default highest-sensitivity + range saturates one or more axes to the chip's overflow sentinel, + and userspace observes that axis as permanently stuck. Declaring + a wider initial range avoids the saturation at the cost of a + slightly coarser quantisation. + $ref: /schemas/types.yaml#/definitions/uint32 + allOf: - if: properties: --=20 2.43.0 From nobody Mon Jun 8 06:35:56 2026 Received: from outbound11.mail.transip.nl (outbound11.mail.transip.nl [136.144.136.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E36693F0ABF; Fri, 5 Jun 2026 10:08:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=136.144.136.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780654144; cv=none; b=H3eeQ5XuSCFvJFkp5/hejJRe3mwVRbBXAQv7gymry1TRTTANziYvjqkjszLZjrnwAsoiLfO/Wst8SxoOtg/HUYTg2xHkbNhMa+QiaPL+A6Dnl1pj4sFF2ID5434TmiH+iSwLCoABLlNc3CKOYESQnLX0+3OnBroBcrnZUCRMfRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780654144; c=relaxed/simple; bh=sJxLEqKR9v8Hg0iJX3EyuPAsYh2VmANHcCjjQi9bWDc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JfP74E2BolEFIpiU+mtXZapnjhfXW6r20CerjN5/CRpoK+ohzO45uE08WNXkPRL9DkM6J8LCnBrLe13yBnXgC0VLuOTEwqcSXtR5DQZzmWjCaRqK10AI500ZbdXf7sFm+49T76sSQDwl/tDE3nBpjGPNP5UJEW+HS9p0OkjWHmU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=herrie.org; spf=pass smtp.mailfrom=herrie.org; dkim=pass (2048-bit key) header.d=herrie.org header.i=@herrie.org header.b=byFlq7bu; arc=none smtp.client-ip=136.144.136.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=herrie.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=herrie.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=herrie.org header.i=@herrie.org header.b="byFlq7bu" Received: from submission4.mail.transip.nl (unknown [10.103.8.155]) by outbound11.mail.transip.nl (Postfix) with ESMTP id 4gWxwZ6l8PzkQRYC; Fri, 5 Jun 2026 12:08:46 +0200 (CEST) Received: from herrie-desktop.. (180-93-184-31.ftth.glasoperator.nl [31.184.93.180]) by submission4.mail.transip.nl (Postfix) with ESMTPA id 4gWxwZ2780z3R3nyy; Fri, 5 Jun 2026 12:08:46 +0200 (CEST) From: Herman van Hazendonk 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 Subject: [PATCH 3/3] iio: magnetometer: st_magn: honour st,fullscale-mg DT property Date: Fri, 5 Jun 2026 12:08:43 +0200 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: ClueGetter at submission4.mail.transip.nl DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=transip-a; d=herrie.org; t=1780654126; h=from:subject:to:cc: references:in-reply-to:date:mime-version; bh=xb/U3BDUqdxbY5zFe5F+I4YVsGUKm6tPSWQsBYhq7+g=; b=byFlq7buZZiGbj8oT1vpSjGMHfELTx2Vf5wd7t6PFvHF3uE+tmY65zIwcI/AABcpwFERgG W/QjEeXIef42HUPYcj+4864hYlh8vLptqA61re1wRsM0CYOojp6ffTgCw2R/7ghm91UP47 QF9UhznJDHYdKjo+ohdQ/hmI5WCCnzcrrQtVe17mdJeHaOQ/mATX2rDuBHiJFUGGEqGIo2 LaOBA+TZgvNhUa986AYLuEzyKDIGmivFsyce3zhtvIrHMOhj9evS2LUX2Yw5cDeqGKLslp RBqGj5RM8lcyFmtDcnkbxJANnNy8a+2zOHbMNj3HJ6SwCvVQFUOlo2PL5GdGtA== X-Report-Abuse-To: abuse@transip.nl Content-Type: text/plain; charset="utf-8" The ST magnetometer core's common probe hardcodes fs_avl[0] -- the highest-sensitivity full-scale supported by the chip -- as the starting range. For the LSM303DLH that is +/-1.3 G; for the LSM303DLHC and LSM303DLM it is +/-2 G; for the LIS3MDL it is +/-4 G. That is the right default for "minimal noise floor at a desk", but it leaves no margin for boards that pick up appreciable DC bias from nearby PCB structures. On the HP TouchPad (apq8060 / tenderloin) the LSM303DLH magnetometer is mounted close enough to the surrounding power planes that X reads back as the chip's 0xF000 overflow sentinel (=3D=3D -4096 raw, the value the chip publishes when the ADC saturates) on every sample at the chip-default range, while Y and Z fall well within the +/-1.3 G window. Parse the st,fullscale-mg device-tree property (documented separately in dt-bindings/iio/st,st-sensors.yaml) in the magnetometer common probe to select the initial fs_avl entry by its mg value. The driver tolerates an unknown / unsupported value by falling back to the chip default and warning, so the property is purely additive -- existing in-tree DTSes are unaffected. Per-sensor mg ranges are listed in st_magn_sensors_settings[]. For LSM303DLH the valid values are 1300, 1900, 2500, 4000, 4700, 5600 and 8100; for LSM303DLHC they are 1300, 1900, 2500, 4000, 4700, 5600, 8100 (same code path); for LIS3MDL they are 4000, 8000, 12000, 16000; and so on. Sensors with a fixed full-scale (fs.addr =3D=3D 0) simply ignore the property. Empirical scale sweep on the HP TouchPad confirmed that on this board any fs_avl >=3D 1 produces non-saturated X readings: scale (0.001 G/LSB) | X raw Y raw Z raw --------------------+------------------------------- 1.100 | -4096 44 46 (X saturated) 0.855 | -547 37 37 (clean) 0.670 | -433 94 103 (clean) 0.450 | -266 44 71 (clean) 0.400 | -235 34 65 (clean) 0.330 | -196 27 56 (clean) 0.230 | -145 15 40 (clean) 2500 mg is the natural choice for tenderloin: comfortably outside the saturation regime while keeping useful precision for compass applications. Signed-off-by: Herman van Hazendonk --- drivers/iio/magnetometer/st_magn_core.c | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetom= eter/st_magn_core.c index ef348d316c00..936253440856 100644 --- a/drivers/iio/magnetometer/st_magn_core.c +++ b/drivers/iio/magnetometer/st_magn_core.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -628,6 +629,40 @@ int st_magn_common_probe(struct iio_dev *indio_dev) mdata->current_fullscale =3D &mdata->sensor_settings->fs.fs_avl[0]; mdata->odr =3D mdata->sensor_settings->odr.odr_avl[0].hz; =20 + /* + * Allow the device tree to override the default full-scale. Hardware + * such as the LSM303DLH magnetometer on the HP TouchPad picks up + * enough DC bias from nearby PCB structures that the chip-default + * highest-sensitivity range saturates the X axis to a sentinel + * 0xF000 immediately at probe; selecting a less sensitive range via + * st,fullscale-mg fixes that without requiring userspace to write + * in_magn_*_scale at startup. + */ + { + u32 fs_mg; + + if (!device_property_read_u32(parent, "st,fullscale-mg", + &fs_mg)) { + struct st_sensor_fullscale *fs =3D + &mdata->sensor_settings->fs; + int i; + + for (i =3D 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) { + if (!fs->fs_avl[i].num) + break; + if (fs->fs_avl[i].num =3D=3D fs_mg) { + mdata->current_fullscale =3D + &fs->fs_avl[i]; + break; + } + } + if (mdata->current_fullscale->num !=3D fs_mg) + dev_warn(parent, + "st,fullscale-mg=3D%u not supported, using %u\n", + fs_mg, mdata->current_fullscale->num); + } + } + if (!pdata) pdata =3D (struct st_sensors_platform_data *)&default_magn_pdata; =20 --=20 2.43.0