Skip to contentSkip to conversation

iio: add Open Sensor Fusion IIO driver

PATCH Superseded Jinseob Kim 3 participants 11 messages Aug 20 – Sep 13

Subsystems (3)

v8 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v8 cover iio: add Open Sensor Fusion IIO driver

Open Sensor Fusion (OSF) is a physical sensor board that reports measurements over UART. Add a serdev driver using the generic "opensensorfusion,osf" compatible.

The compatible is intentionally independent of a board model or firmware revision. A fixed wire header carries the protocol version, while a capability report discovers the available sensors and channels at runtime. Supported capabilities are exposed as four IIO devices: accelerometer, gyroscope, magnetometer, and temperature.

Changes since v7:

- Separate wire decoding from support policy. Validate the protocol major and reserved header bytes after frame authentication, and ignore unsupported capability entries without discarding supported entries.
- Harden resynchronization: unauthenticated candidates discard one head byte, while authenticated frames consume the complete frame for every handled, ignored, or rejected outcome.
- Retain split one-, two-, and three-byte magic prefixes across UART callbacks, and use an opaque callback so the stream parser does not depend on the driver added by patch 5.
- Zero-initialize explicitly aligned IIO scans, use iio_push_to_buffers_with_ts(), and simplify the buffered fast path and one-axis versus three-axis handling.
- Commit a sensor sample to the direct-read cache only after the registered IIO channel and buffer path accepts it. A rejected CRC-valid sample therefore cannot change direct RAW state or the last accepted sequence.
- Add focused KUnit coverage for accepted, ignored, rejected, and malformed sample paths and protection against invalid-sample cache-slot exhaustion. Run the same suite against pre-fix ordering as a negative control.
- Consolidate MAINTAINERS coverage under
F: drivers/iio/opensensorfusion/.

Static and build validation completed for the corrected source includes git diff --check, scripts/checkpatch.pl --strict with no errors or warnings on all five patches, four passing focused KUnit cases, the expected two failures when the same tests are run against the pre-fix core, the targeted DT binding check with dtschema 2026.6, the IIO documentation build with no OSF-specific warnings, clean W=1 GCC and Clang module builds, per-patch build checks, and clean-base application with an identical final tree.

Pre-audit v8 hardware validation used a Raspberry Pi 4 over UART with a physical OSF board. It covered serdev probe and bind, capability discovery, direct raw reads, a 66.5-second simultaneous buffered capture of all four IIO devices, and unload and reload. The capture delivered 919 accelerometer samples and 918 samples from each of the gyroscope, magnetometer, and temperature devices, without a kernel warning, OOPS, or IIO overrun.

A focused post-audit Raspberry Pi regression then exercised the corrected ARM64 module in a one-shot tryboot without installing it or changing boot artifacts. Both the first load and reload registered four IIO devices and passed direct raw reads. A 12.0005-second simultaneous buffered capture delivered 165 accelerometer, 165 gyroscope, 166 magnetometer, and 166 temperature records, with no read errors, timestamp regressions, or critical dmesg findings. Unload, reload, and final cleanup passed, and one normal reboot restored the stock kernel with the OSF module and devices absent.

A validation-only debug build from the pre-audit v8 development source was used solely to observe internal parser and DEVICE_STATUS counters.
All parser error counters stayed at zero, and all 94 DEVICE_STATUS reports had a zero dropped-frame count. The submitted source exposes no debug counter ABI.

This series is based on the IIO testing branch at
a9fa85254feee2b52b2bb4fbb4920ece47dfd6f8.

Previous revisions:

v1: https://lore.kernel.org/r/[email protected]
v2: https://lore.kernel.org/r/[email protected]
v3: https://lore.kernel.org/r/[email protected]
v4: https://lore.kernel.org/r/[email protected]
v5: https://lore.kernel.org/r/[email protected]
v6: https://lore.kernel.org/r/[email protected]
v7: https://lore.kernel.org/r/[email protected]

Jinseob Kim (5):
dt-bindings: iio: add Open Sensor Fusion device
Documentation: iio: add Open Sensor Fusion driver overview
iio: osf: add protocol decoding
iio: osf: add authenticated stream parser
iio: osf: add UART IIO driver

 .../bindings/iio/opensensorfusion,osf.yaml    |  52 ++
 .../devicetree/bindings/vendor-prefixes.yaml  |   2 +
 Documentation/iio/index.rst                   |   1 +
 Documentation/iio/open-sensor-fusion.rst      |  72 +++
 MAINTAINERS                                   |   8 +
 drivers/iio/Kconfig                           |   1 +
 drivers/iio/Makefile                          |   1 +
 drivers/iio/opensensorfusion/Kconfig          |  27 +
 drivers/iio/opensensorfusion/Makefile         |   7 +
 drivers/iio/opensensorfusion/osf_core.c       | 393 ++++++++++++++
 drivers/iio/opensensorfusion/osf_core.h       |  70 +++
 drivers/iio/opensensorfusion/osf_core_test.c  | 493 ++++++++++++++++++
 drivers/iio/opensensorfusion/osf_iio.c        | 304 +++++++++++
 drivers/iio/opensensorfusion/osf_iio.h        |  22 +
 drivers/iio/opensensorfusion/osf_protocol.c   | 224 ++++++++
 drivers/iio/opensensorfusion/osf_protocol.h   | 101 ++++
 drivers/iio/opensensorfusion/osf_serdev.c     | 124 +++++
 drivers/iio/opensensorfusion/osf_stream.c     | 231 ++++++++
 drivers/iio/opensensorfusion/osf_stream.h     |  53 ++
 19 files changed, 2186 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml
 create mode 100644 Documentation/iio/open-sensor-fusion.rst
 create mode 100644 drivers/iio/opensensorfusion/Kconfig
 create mode 100644 drivers/iio/opensensorfusion/Makefile
 create mode 100644 drivers/iio/opensensorfusion/osf_core.c
 create mode 100644 drivers/iio/opensensorfusion/osf_core.h
 create mode 100644 drivers/iio/opensensorfusion/osf_core_test.c
 create mode 100644 drivers/iio/opensensorfusion/osf_iio.c
 create mode 100644 drivers/iio/opensensorfusion/osf_iio.h
 create mode 100644 drivers/iio/opensensorfusion/osf_protocol.c
 create mode 100644 drivers/iio/opensensorfusion/osf_protocol.h
 create mode 100644 drivers/iio/opensensorfusion/osf_serdev.c
 create mode 100644 drivers/iio/opensensorfusion/osf_stream.c
 create mode 100644 drivers/iio/opensensorfusion/osf_stream.h
Signature · 1 line
2.43.0
#1 lore raw

PATCH v8 1/5 dt-bindings: iio: add Open Sensor Fusion device

Add a binding for the generic Open Sensor Fusion host interface.

Open Sensor Fusion devices report capabilities and samples over an OSF protocol stream. Sensor channels are discovered at runtime from capability reports instead of being described individually in Device Tree.

The protocol version is discovered at runtime from the OSF frame header. OSF GREEN is a product identity, and OSF0 is a wire-format magic value, so neither is used as the Linux compatible string.

---
 .../bindings/iio/opensensorfusion,osf.yaml    | 52 +++++++++++++++++++
 .../devicetree/bindings/vendor-prefixes.yaml  |  2 +
 MAINTAINERS                                   |  6 +++
 3 files changed, 60 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml
Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml new file +52 -0
new file mode 100644
index 000000000000..3998390828cc
@@ -0,0 +1,52 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/opensensorfusion,osf.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Open Sensor Fusion Sensor Aggregation Hub
+
+maintainers:
+  - Jinseob Kim <[email protected]>
+
+description: |
+  This binding documents the generic Open Sensor Fusion host interface. Open
+  Sensor Fusion is a sensor aggregation hub. The hub exposes an OSF protocol
+  data stream over its host interface and reports capabilities and samples for
+  multiple sensor classes. The actual sensor channels are discovered at runtime
+  from OSF capability reports instead of describing them in Device Tree. The
+  protocol version is discovered at runtime.
+
+  Public project documentation is available at:
+
+    https://github.com/opensensorfusion
+
+  OSF0, protocol_major, and protocol_minor are wire-protocol details
+  exchanged in OSF frames.
+
+allOf:
+  - $ref: /schemas/serial/serial-peripheral-props.yaml#
+
+properties:
+  compatible:
+    const: opensensorfusion,osf
+
+  vcc-supply:
+    description:
+      Regulator supplying power to the Open Sensor Fusion device.
+
+required:
+  - compatible
+  - vcc-supply
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    serial {
+        sensor {
+            compatible = "opensensorfusion,osf";
+            vcc-supply = <&vcc_sensor>;
+        };
+    };
+...
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
index f88e595f7077..d746aadb994f 100644
@@ -1245,6 +1245,8 @@ patternProperties:
     description: OpenPandora GmbH
   "^openrisc,.*":
     description: OpenRISC.io
+  "^opensensorfusion,.*":
+    description: Open Sensor Fusion
   "^openwrt,.*":
     description: OpenWrt
   "^option,.*":
MAINTAINERS +6 -0
index 3c5084fec202..17652ba6039d 100644
@@ -20293,6 +20293,12 @@ F:	Documentation/devicetree/
 F:	arch/*/boot/dts/
 F:	include/dt-bindings/
 
+OPEN SENSOR FUSION
+M:	Jinseob Kim <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml
+K:	opensensorfusion
+
 OPENCOMPUTE PTP CLOCK DRIVER
 M:	Vadim Fedorenko <[email protected]>
 L:	[email protected]
Signature · 1 line
2.43.0
#2 lore raw

PATCH v8 2/5 Documentation: iio: add Open Sensor Fusion driver overview

In reply to Jinseob Kim

Document the Linux IIO mapping for Open Sensor Fusion devices.

The overview explains that sensor channels are discovered at runtime from mandatory capability reports. It also documents that OSF0 is a wire-format detail and that protocol_major and protocol_minor carry protocol compatibility information.

---
 Documentation/iio/index.rst              |  1 +
 Documentation/iio/open-sensor-fusion.rst | 72 ++++++++++++++++++++++++
 MAINTAINERS                              |  1 +
 3 files changed, 74 insertions(+)
 create mode 100644 Documentation/iio/open-sensor-fusion.rst
Documentation/iio/index.rst +1 -0
index b02b879b053a..c2b7963348fd 100644
@@ -40,4 +40,5 @@ Industrial I/O Kernel Drivers
    adxl345
    bno055
    ep93xx_adc
+   open-sensor-fusion
    opt4060
Documentation/iio/open-sensor-fusion.rst new file +72 -0

72 lines not on this page · raw message

MAINTAINERS +1 -0
index 17652ba6039d..9550cf1900bd 100644
@@ -20297,6 +20297,7 @@ OPEN SENSOR FUSION
 M:	Jinseob Kim <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml
+F:	Documentation/iio/open-sensor-fusion.rst
 K:	opensensorfusion
 
 OPENCOMPUTE PTP CLOCK DRIVER
Signature · 1 line
2.43.0
#3 lore raw

PATCH v8 3/5 iio: osf: add protocol decoding

In reply to Jinseob Kim

Add helpers for decoding Open Sensor Fusion frame headers and supported message payloads.

The decoder validates framing, payload bounds and CRC before exposing decoded frame contents to the rest of the driver. Framing validation includes the OSF0 wire magic and fixed header length. Protocol version and reserved header fields are exposed to the core so authenticated-frame policy is handled after CRC validation.

Capability entries are decoded structurally, including their flags and reserved fields. The core can then apply support policy without rejecting an entire report solely because it contains future entry values.

Use explicit little-endian wire storage sizes and designated initializers for decoded output structures.

---
 MAINTAINERS                                 |   1 +
 drivers/iio/opensensorfusion/osf_protocol.c | 224 ++++++++++++++++++++
 drivers/iio/opensensorfusion/osf_protocol.h | 101 +++++++++
 3 files changed, 326 insertions(+)
 create mode 100644 drivers/iio/opensensorfusion/osf_protocol.c
 create mode 100644 drivers/iio/opensensorfusion/osf_protocol.h
MAINTAINERS +1 -0
index 9550cf1900bd..76fa860a7b91 100644
@@ -20298,6 +20298,7 @@ M:	Jinseob Kim <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml
 F:	Documentation/iio/open-sensor-fusion.rst
+F:	drivers/iio/opensensorfusion/osf_protocol.*
 K:	opensensorfusion
 
 OPENCOMPUTE PTP CLOCK DRIVER
drivers/iio/opensensorfusion/osf_protocol.c new file +224 -0

224 lines not on this page · raw message

drivers/iio/opensensorfusion/osf_protocol.h new file +101 -0

101 lines not on this page · raw message

Signature · 1 line
2.43.0
#4 lore raw

PATCH v8 4/5 iio: osf: add authenticated stream parser

In reply to Jinseob Kim

Add a UART byte-stream parser for Open Sensor Fusion frames.

The parser searches for the OSF0 wire magic, keeps partial frames buffered, checks header length and payload bounds, and passes complete candidate frames to a registered frame callback.

Candidates rejected before authentication drop only the current head byte before resynchronizing, so a corrupted unauthenticated payload length cannot make the parser skip later valid frames. CRC-valid authenticated frames are consumed in full and classified as handled, ignored, or rejected.

Use a direct callback member with an opaque context and keep explicit statistics for authenticated outcomes and framing failures.

---
 MAINTAINERS                               |   1 +
 drivers/iio/opensensorfusion/osf_stream.c | 231 ++++++++++++++++++++++
 drivers/iio/opensensorfusion/osf_stream.h |  53 +++++
 3 files changed, 285 insertions(+)
 create mode 100644 drivers/iio/opensensorfusion/osf_stream.c
 create mode 100644 drivers/iio/opensensorfusion/osf_stream.h
MAINTAINERS +1 -0
index 76fa860a7b91..093b569de12e 100644
@@ -20299,6 +20299,7 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml
 F:	Documentation/iio/open-sensor-fusion.rst
 F:	drivers/iio/opensensorfusion/osf_protocol.*
+F:	drivers/iio/opensensorfusion/osf_stream.*
 K:	opensensorfusion
 
 OPENCOMPUTE PTP CLOCK DRIVER
drivers/iio/opensensorfusion/osf_stream.c new file +231 -0

231 lines not on this page · raw message

drivers/iio/opensensorfusion/osf_stream.h new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
2.43.0
#6 lore raw

PATCH v8 5/5 iio: osf: add UART IIO driver

In reply to Jinseob Kim

Add the Open Sensor Fusion serdev transport, driver core, and IIO registration path as one complete driver patch.

The driver enables the required vcc regulator, receives OSF frames over UART, registers IIO devices from capability reports, supports direct raw reads from the latest sample cache, and pushes buffered samples into software kfifo buffers.

Wire the stream parser frame callback to the OSF core, use final Kconfig and Makefile contents from the start, check iio_buffer_enabled() before pushing samples, and use zero-initialized scan storage with explicit timestamp alignment.

Classify authenticated application outcomes as handled, ignored, or rejected so the parser consumes every CRC-valid frame in full. Decode capability entries structurally, skip unsupported entries individually, and register the supported entries from the same report. Allocate latest sample cache slots only for sensors with registered IIO devices.

Deliver sensor samples to IIO before committing the latest-sample cache, so a frame rejected by the registered channel layout or buffer path cannot change direct-read state or the last accepted sequence. Add focused KUnit coverage for rejected, valid, ignored, and malformed sample paths and cache-slot exhaustion.

---
 MAINTAINERS                                  |   3 +-
 drivers/iio/Kconfig                          |   1 +
 drivers/iio/Makefile                         |   1 +
 drivers/iio/opensensorfusion/Kconfig         |  27 +
 drivers/iio/opensensorfusion/Makefile        |   7 +
 drivers/iio/opensensorfusion/osf_core.c      | 393 +++++++++++++++
 drivers/iio/opensensorfusion/osf_core.h      |  70 +++
 drivers/iio/opensensorfusion/osf_core_test.c | 493 +++++++++++++++++++
 drivers/iio/opensensorfusion/osf_iio.c       | 304 ++++++++++++
 drivers/iio/opensensorfusion/osf_iio.h       |  22 +
 drivers/iio/opensensorfusion/osf_serdev.c    | 124 +++++
 11 files changed, 1443 insertions(+), 2 deletions(-)
 create mode 100644 drivers/iio/opensensorfusion/Kconfig
 create mode 100644 drivers/iio/opensensorfusion/Makefile
 create mode 100644 drivers/iio/opensensorfusion/osf_core.c
 create mode 100644 drivers/iio/opensensorfusion/osf_core.h
 create mode 100644 drivers/iio/opensensorfusion/osf_core_test.c
 create mode 100644 drivers/iio/opensensorfusion/osf_iio.c
 create mode 100644 drivers/iio/opensensorfusion/osf_iio.h
 create mode 100644 drivers/iio/opensensorfusion/osf_serdev.c
MAINTAINERS +1 -2
index 093b569de12e..ec1e86718015 100644
@@ -20298,8 +20298,7 @@ M:	Jinseob Kim <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/iio/opensensorfusion,osf.yaml
 F:	Documentation/iio/open-sensor-fusion.rst
-F:	drivers/iio/opensensorfusion/osf_protocol.*
-F:	drivers/iio/opensensorfusion/osf_stream.*
+F:	drivers/iio/opensensorfusion/
 K:	opensensorfusion
 
 OPENCOMPUTE PTP CLOCK DRIVER
drivers/iio/Kconfig +1 -0
index 652557a5b851..89bb5b65c761 100644
@@ -102,6 +102,7 @@ source "drivers/iio/light/Kconfig"
 source "drivers/iio/magnetometer/Kconfig"
 source "drivers/iio/multiplexer/Kconfig"
 source "drivers/iio/orientation/Kconfig"
+source "drivers/iio/opensensorfusion/Kconfig"
 source "drivers/iio/test/Kconfig"
 if IIO_TRIGGER
    source "drivers/iio/trigger/Kconfig"
drivers/iio/Makefile +1 -0
index f03a4100c800..a51c4446ee09 100644
@@ -38,6 +38,7 @@ obj-y += light/
 obj-y += magnetometer/
 obj-y += multiplexer/
 obj-y += orientation/
+obj-y += opensensorfusion/
 obj-y += position/
 obj-y += potentiometer/
 obj-y += potentiostat/
drivers/iio/opensensorfusion/Kconfig new file +27 -0
new file mode 100644
index 000000000000..b4a2cde9645e
@@ -0,0 +1,27 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config OPEN_SENSOR_FUSION
+	tristate "Open Sensor Fusion UART IIO driver"
+	depends on SERIAL_DEV_BUS
+	select CRC32
+	select IIO_BUFFER
+	select IIO_KFIFO_BUF
+	help
+	  Build the Open Sensor Fusion UART IIO driver.
+
+	  The driver receives OSF protocol frames over a serdev UART and
+	  registers IIO devices for supported capability entries. It exposes
+	  accelerometer, gyroscope, magnetometer, and temperature samples
+	  through IIO direct reads and software buffers.
+
+config OPEN_SENSOR_FUSION_KUNIT_TEST
+	bool "KUnit tests for Open Sensor Fusion" if !KUNIT_ALL_TESTS
+	depends on OPEN_SENSOR_FUSION=y && KUNIT=y
+	default KUNIT_ALL_TESTS
+	help
+	  Build focused unit tests for the Open Sensor Fusion core sample
+	  acceptance, direct-read cache, and IIO buffer paths. The tests
+	  exercise accepted, ignored, and rejected sample handling without
+	  exposing additional production interfaces.
+
+	  If unsure, say N.
drivers/iio/opensensorfusion/Makefile new file +7 -0
new file mode 100644
index 000000000000..c2f5ba065a62
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-$(CONFIG_OPEN_SENSOR_FUSION) += open-sensor-fusion.o
+
+open-sensor-fusion-y := osf_core.o osf_iio.o osf_protocol.o osf_serdev.o \
+			 osf_stream.o
+open-sensor-fusion-$(CONFIG_OPEN_SENSOR_FUSION_KUNIT_TEST) += osf_core_test.o
drivers/iio/opensensorfusion/osf_core.c new file +393 -0

393 lines not on this page · raw message

drivers/iio/opensensorfusion/osf_core.h new file +70 -0

70 lines not on this page · raw message

drivers/iio/opensensorfusion/osf_core_test.c new file +493 -0

493 lines not on this page · raw message

drivers/iio/opensensorfusion/osf_iio.c new file +304 -0

304 lines not on this page · raw message

drivers/iio/opensensorfusion/osf_iio.h new file +22 -0
new file mode 100644
index 000000000000..d0745167f8e0
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _OSF_IIO_H
+#define _OSF_IIO_H
+
+#include <linux/types.h>
+
+#include "osf_protocol.h"
+
+struct device;
+struct iio_dev;
+struct osf_device;
+
+int osf_iio_register_sensor(struct device *dev,
+			    const struct osf_capability_entry *entry,
+			    struct osf_device *osf, struct iio_dev **indio_dev);
+void osf_iio_unregister_sensor(struct iio_dev *indio_dev);
+int osf_iio_push_sample(struct iio_dev *indio_dev, const s32 *values,
+			u16 channel_count);
+bool osf_iio_sensor_supported(u16 sensor_type, u16 channel_count);
+const char *osf_iio_sensor_name(u16 sensor_type);
+
+#endif
drivers/iio/opensensorfusion/osf_serdev.c new file +124 -0

124 lines not on this page · raw message

Signature · 1 line
2.43.0
#7 lore raw

Re: [PATCH v8 5/5] iio: osf: add UART IIO driver

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Hardware Initialization Order: Regulator enabled before UART is configured, risking loss of…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Hardware Initialization Order: Regulator enabled before UART is configured, risking loss of initial capability report. --

--- Patch [5]: [PATCH v8 5/5] iio: osf: add UART IIO driver --- commit 9c6fb720e1ae8c10cafcfaeb63c04248f654050d
Author: Jinseob Kim <[email protected]>

iio: osf: add UART IIO driver

This commit adds the Open Sensor Fusion (OSF) UART IIO driver. It handles receiving OSF frames over a serdev UART, registers IIO devices based on capability reports, and exposes sensor samples via direct reads and buffers.

Quoted 3 lines
drivers/iio/opensensorfusion/osf_serdev.c new file +0 -0

[ ... ]

Quoted 2 lines
drivers/iio/opensensorfusion/osf_serdev.c new file +2 -0
+static int osf_serdev_probe(struct serdev_device *serdev)
+{

[ ... ]

drivers/iio/opensensorfusion/osf_serdev.c line 87

Quoted 13 lines
drivers/iio/opensensorfusion/osf_serdev.c new file +13 -0
+	serdev_device_set_drvdata(serdev, osf_uart);
+	serdev_device_set_client_ops(serdev, &osf_serdev_ops);
+
+	ret = devm_regulator_get_enable(dev, "vcc");
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to enable vcc regulator\n");
+
+	ret = serdev_device_open(serdev);
+	if (ret)
+		return ret;
+
+	baudrate = serdev_device_set_baudrate(serdev, OSF_SERDEV_BAUD);

[Severity: High]
Could this hardware initialization order lead to a race condition where the sensor's initial capability report is lost?

Since the vcc regulator is enabled before the serdev UART port is opened and its baud rate configured, if the sensor boots quickly and transmits its capability report immediately upon power-up, the host UART might not be ready to receive it.

Because the driver relies on autonomously transmitted capability reports to register IIO devices, missing this initial report could leave the driver completely non-functional.

Would it be safer to open and configure the serdev UART before enabling the regulator?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
maintainer
#9 lore raw
In reply to Jinseob Kim
Quoted 10 lines · On Thu, 20 Aug 2026 14:06:03 +0900 Jinseob Kim <[email protected]> wrote:

Open Sensor Fusion (OSF) is a physical sensor board that reports measurements over UART. Add a serdev driver using the generic "opensensorfusion,osf" compatible.

The compatible is intentionally independent of a board model or firmware revision. A fixed wire header carries the protocol version, while a capability report discovers the available sensors and channels at runtime. Supported capabilities are exposed as four IIO devices: accelerometer, gyroscope, magnetometer, and temperature.

Sashiko has one reasonable sounding comment
https://sashiko.dev/#/patchset/20260820050608.5440-1-kimjinseob88%40gmail.com

What this cover letter is missing is any info on maturity of the specification. Is this at a stage where merging it to Linux makes sense, or are there still elements on the spec side that need to be resolved?

I'll take a fresh look anyway given it has been a while since the last version, but others may make their decisions based on that statement of how mature things are.

Jonathan

maintainer
#5 lore raw

Re: [PATCH v8 4/5] iio: osf: add authenticated stream parser

In reply to Jinseob Kim
Quoted 12 lines · On Thu, 20 Aug 2026 14:06:07 +0900 Jinseob Kim <[email protected]> wrote:

Add a UART byte-stream parser for Open Sensor Fusion frames.

The parser searches for the OSF0 wire magic, keeps partial frames buffered, checks header length and payload bounds, and passes complete candidate frames to a registered frame callback.

Candidates rejected before authentication drop only the current head byte before resynchronizing, so a corrupted unauthenticated payload length cannot make the parser skip later valid frames. CRC-valid authenticated frames are consumed in full and classified as handled, ignored, or rejected.

Quoted 4 lines

Use a direct callback member with an opaque context and keep explicit statistics for authenticated outcomes and framing failures.

One really trivial thing inline. Please check to see if other areas of code alignment would benefit from a bit of a reorg.

Quoted 5 lines
drivers/iio/opensensorfusion/osf_stream.c new file +0 -0
new file mode 100644
index 000000000000..7ce45e631648

...

Quoted 37 lines
drivers/iio/opensensorfusion/osf_stream.c new file +37 -0
+
+static int osf_stream_process(struct osf_stream *stream)
+{
+	size_t discarded;
+	size_t frame_len;
+	u32 payload_len;
+	int frame_result;
+	int first_err = 0;
+
+	while (stream->len) {
+		discarded = osf_stream_discard_to_magic(stream);
+		if (discarded) {
+			stream->stats.bad_magic_resyncs++;
+			stream->stats.dropped_bytes += discarded;
+			if (!first_err)
+				first_err = -EPROTO;
+		}
+
+		if (!stream->len)
+			break;
+
+		if (stream->len < OSF_FRAME_HEADER_LEN)
+			break;
+
+		if (get_unaligned_le16(stream->buf + 6) != OSF_FRAME_HEADER_LEN) {
+			stream->stats.dropped_bytes++;
+			osf_stream_drop_invalid_head(stream);
+			if (!first_err)
+				first_err = -EPROTO;
+			continue;
+		}
+
+		payload_len = get_unaligned_le32(stream->buf + 10);
+		if (payload_len > OSF_STREAM_MAX_PAYLOAD_LEN) {
+			stream->stats.dropped_bytes++;
+			osf_stream_drop_invalid_head(stream);
+			if (!first_err)

drivers/iio/opensensorfusion/osf_stream.c line 120

Quoted 10 lines
drivers/iio/opensensorfusion/osf_stream.c new file +10 -0
+				first_err = -EMSGSIZE;
+			continue;
+		}
+
+		frame_len = OSF_FRAME_HEADER_LEN + payload_len + OSF_FRAME_CRC_LEN;
+		if (stream->len < frame_len)
+			break;
+
+		frame_result = stream->receive_frame(stream->frame_context,
+					     stream->buf, frame_len);

Align after (

Quoted 43 lines
drivers/iio/opensensorfusion/osf_stream.c new file +43 -0
+		if (frame_result < 0) {
+			if (frame_result == -EBADMSG)
+				stream->stats.bad_crc_frames++;
+
+			/*
+			 * Decoding failed before the frame was authenticated;
+			 * payload_len is still untrusted. Drop only the current
+			 * head and resynchronize.
+			 */
+			stream->stats.dropped_bytes++;
+			osf_stream_drop_invalid_head(stream);
+			if (!first_err)
+				first_err = frame_result;
+			continue;
+		}
+
+		/* Count exactly one outcome for every authenticated frame. */
+		stream->stats.authenticated_frames++;
+		switch (frame_result) {
+		case OSF_STREAM_FRAME_HANDLED:
+			stream->stats.handled_frames++;
+			break;
+		case OSF_STREAM_FRAME_IGNORED:
+			stream->stats.ignored_frames++;
+			break;
+		case OSF_STREAM_FRAME_REJECTED:
+			stream->stats.rejected_frames++;
+			break;
+		default:
+			/*
+			 * Preserve the authenticated boundary without scanning the
+			 * payload for another magic value.
+			 */
+			stream->stats.rejected_frames++;
+			if (!first_err)
+				first_err = -EPROTO;
+			break;
+		}
+		osf_stream_discard(stream, frame_len);
+	}
+
+	return first_err;
+}
maintainer
#8 lore raw

Re: [PATCH v8 5/5] iio: osf: add UART IIO driver

In reply to Jinseob Kim
Quoted 7 lines · On Thu, 20 Aug 2026 14:06:08 +0900 Jinseob Kim <[email protected]> wrote:

Add the Open Sensor Fusion serdev transport, driver core, and IIO registration path as one complete driver patch.

The driver enables the required vcc regulator, receives OSF frames over UART, registers IIO devices from capability reports, supports direct raw reads from the latest sample cache, and pushes buffered samples into software kfifo buffers.

Too much info. We definitely don't need mention it turns on the power or that the data goes standard paths.

Quoted 12 lines

Wire the stream parser frame callback to the OSF core, use final Kconfig and Makefile contents from the start, check iio_buffer_enabled() before pushing samples, and use zero-initialized scan storage with explicit timestamp alignment.

Classify authenticated application outcomes as handled, ignored, or rejected so the parser consumes every CRC-valid frame in full. Decode capability entries structurally, skip unsupported entries individually, and register the supported entries from the same report. Allocate latest sample cache slots only for sensors with registered IIO devices.

Quoted 7 lines

Deliver sensor samples to IIO before committing the latest-sample cache, so a frame rejected by the registered channel layout or buffer path cannot change direct-read state or the last accepted sequence. Add focused KUnit coverage for rejected, valid, ignored, and malformed sample paths and cache-slot exhaustion.

A couple of minor things inline.

Thanks,

Jonathan

Quoted 6 lines
drivers/iio/opensensorfusion/osf_iio.c new file +0 -0
new file mode 100644
index 000000000000..56030b4d6a9f
@@ -0,0 +1,304 @@

...

Quoted 20 lines
drivers/iio/opensensorfusion/osf_iio.c new file +20 -0
+
+#define OSF_MOD_CHAN(_type, _mod, _idx)                         \
+	{                                                               \
+		.type = (_type),                                           \
+		.modified = 1,                                             \
+		.channel2 = (_mod),                                        \
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),              \
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),      \
+		.scan_index = (_idx),                                      \
+		.scan_type = {                                             \
+			.sign = 's',                                         \
+			.realbits = 32,                                      \
+			.storagebits = 32,                                   \
+			.endianness = IIO_CPU,                               \
+		},                                                        \
+	}
+
+#define OSF_CHAN(_type, _idx)                                     \
+	{                                                               \
+		.type = (_type),                                           \

drivers/iio/opensensorfusion/osf_iio.c line 70

Quoted 10 lines
drivers/iio/opensensorfusion/osf_iio.c new file +10 -0
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),              \
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),      \
+		.scan_index = (_idx),                                      \
+		.scan_type = {                                             \
+			.sign = 's',                                         \
+			.realbits = 32,                                      \
+			.storagebits = 32,                                   \
+			.endianness = IIO_CPU,                               \
+		},                                                        \
+	}

Tidy up the \ as there doesn't seem to be any standard arrangement going on here.

Quoted 7 lines
drivers/iio/opensensorfusion/osf_iio.c new file +7 -0
+int osf_iio_push_sample(struct iio_dev *indio_dev, const s32 *values,
+			u16 channel_count)
+{
+	struct osf_iio_state *state = iio_priv(indio_dev);
+	s64 timestamp;
+
+	if (channel_count != state->spec->channel_count)

drivers/iio/opensensorfusion/osf_iio.c line 286

Quoted 10 lines
drivers/iio/opensensorfusion/osf_iio.c new file +10 -0
+		return -EPROTO;
+
+	if (!iio_buffer_enabled(indio_dev))
+		return 0;
+
+	timestamp = iio_get_time_ns(indio_dev);
+
+	switch (channel_count) {
+	case 1: {
+		struct osf_iio_scan_1axis scan = { };

Similar to below - you might as well initialize the one value.

drivers/iio/opensensorfusion/osf_iio.c line 290

Quoted 4 lines
drivers/iio/opensensorfusion/osf_iio.c new file +4 -0
+
+		scan.value = values[0];
+		return iio_push_to_buffers_with_ts(indio_dev, &scan,
+						       sizeof(scan), timestamp);

Check for bits of alignment of code that have become wrong over time.

drivers/iio/opensensorfusion/osf_iio.c line 297

Quoted 7 lines
drivers/iio/opensensorfusion/osf_iio.c new file +7 -0
+	}
+	case 3: {
+		struct osf_iio_scan_3axis scan = { };
+
+		scan.values[0] = values[0];
+		scan.values[1] = values[1];
+		scan.values[2] = values[2];

Might as well do

		struct osf_iio_scan_3axis scan = {
			.values[0] = values[0],
			.values[1] = values[1],
			.values[2] = values[2],
		};

Similar for other cases.

Quoted 7 lines
drivers/iio/opensensorfusion/osf_iio.c new file +7 -0
+		return iio_push_to_buffers_with_ts(indio_dev, &scan,
+						       sizeof(scan), timestamp);
+	}
+	default:
+		return -EPROTO;
+	}
+}
#10 lore raw
In reply to Jonathan Cameron

Hi Jonathan

Quoted 4 lines

What this cover letter is missing is any info on maturity of the specification. Is this at a stage where merging it to Linux makes sense, or are there still elements on the spec side that need to be resolved?

my intention is to preserve compatibility across firmware updates by keeping existing message layouts, lengths and field meanings, including units, unchanged. Incompatible changes would require a new protocol major and corresponding driver support.

The remaining specification work is to reconcile the draft differences on reserved fields, extensions and magnetometer units. I will document the agreed rules and compatibility policy in a versioned specification referenced by v10.

Thanks,

Jinseob

2026년 8월 21일 (금) 오전 11:33, Jonathan Cameron <[email protected]>님이 작성:

Quoted 28 lines
Quoted 10 lines · On Thu, 20 Aug 2026 14:06:03 +0900 Jinseob Kim <[email protected]> wrote:

Open Sensor Fusion (OSF) is a physical sensor board that reports measurements over UART. Add a serdev driver using the generic "opensensorfusion,osf" compatible.

The compatible is intentionally independent of a board model or firmware revision. A fixed wire header carries the protocol version, while a capability report discovers the available sensors and channels at runtime. Supported capabilities are exposed as four IIO devices: accelerometer, gyroscope, magnetometer, and temperature.

Sashiko has one reasonable sounding comment
https://sashiko.dev/#/patchset/20260820050608.5440-1-kimjinseob88%40gmail.com

What this cover letter is missing is any info on maturity of the specification. Is this at a stage where merging it to Linux makes sense, or are there still elements on the spec side that need to be resolved?

I'll take a fresh look anyway given it has been a while since the last version, but others may make their decisions based on that statement of how mature things are.

Jonathan