Skip to contentSkip to conversation

iio: add Open Sensor Fusion OSF0 UART driver

RFC PATCH Superseded Jinseob Kim 5 participants 20 messages May 29 – Jun 2

Subsystems (3)

v3 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v3 cover iio: add Open Sensor Fusion OSF0 UART driver

This RFC series adds an Industrial I/O driver for Open Sensor Fusion OSF0 UART devices.

Open Sensor Fusion is an open hardware project for sensor aggregation devices and Linux IIO host support. OSF0 is not a general standard; it is the current wire format used by this project and by the RFC driver in this series. The first concrete hardware target is OSF GREEN, an STM32F405-based sensor aggregation board that streams sensor samples to a Linux host.

Project links:
https://www.opensensorfusion.org/
https://github.com/opensensorfusion
https://github.com/opensensorfusion/opensensorfusion-linux

The driver receives OSF0 frames over a serdev UART, validates the stream, decodes capability and sample frames, and registers IIO devices for the supported sensor types. The current RFC driver covers the device-to-host path used for accelerometer, gyroscope, magnetometer, and temperature samples.

Changes since v2:

* Reworked the binding around the concrete OSF GREEN hardware target.
* Changed the compatible from opensensorfusion,osf-uart to opensensorfusion,osf-green.
* Renamed the binding file to opensensorfusion,osf-green.yaml.
* Updated the example node name to generic sensor.
* Added serial-peripheral-props.yaml and unevaluatedProperties: false.
* Added public project links and clarified that OSF0 is not a general standard.
* Separated the OSF0 wire format from the subset currently supported by this RFC driver.
* Clarified SENSOR_SAMPLE as a 16-byte payload header followed by 4 * channel_count bytes of s32 channel data.
* Clarified device-side timestamp limitations.
* Spelled out Attitude and Heading Reference System (AHRS).
* Added sensor_type, sample_format, channel_count, reserved-field, and payload length overflow validation.
* Changed reserved fields to validate-only handling.
* Fixed IIO_BUFFER / IIO_KFIFO_BUF dependency handling.
* Added channel_count checks before pushing samples to IIO buffers.
* Added locking for cached latest samples.
* Removed explicit linux-iio and devicetree list entries from MAINTAINERS.
* Folded MAINTAINERS updates into the patches that add the corresponding files.
* Addressed Sashiko feedback from v2.

The runtime smoke test used for the previous revision was performed with an OSF GREEN prototype connected to a Raspberry Pi 4 over UART/serdev. This v3 series was also checked with dt_binding_check, checkpatch, and a W=1 target build in the local full-tree environment.

Jinseob Kim (6):
dt-bindings: iio: add OSF GREEN sensor aggregation device
Documentation: iio: add Open Sensor Fusion protocol v0 reference
iio: osf: add protocol v0 decoding
iio: osf: add stream parser
iio: osf: add UART serdev transport
iio: osf: register IIO devices from capabilities

 .../iio/imu/opensensorfusion,osf-green.yaml   |  43 +++
 .../devicetree/bindings/vendor-prefixes.yaml  |   2 +
 .../iio/open-sensor-fusion-protocol-v0.rst    | 308 ++++++++++++++++++
 MAINTAINERS                                   |  13 +
 drivers/iio/Kconfig                           |   1 +
 drivers/iio/Makefile                          |   1 +
 drivers/iio/opensensorfusion/Kconfig          |  14 +
 drivers/iio/opensensorfusion/Makefile         |   6 +
 drivers/iio/opensensorfusion/osf_core.c       | 305 +++++++++++++++++
 drivers/iio/opensensorfusion/osf_core.h       |  70 ++++
 drivers/iio/opensensorfusion/osf_iio.c        | 285 ++++++++++++++++
 drivers/iio/opensensorfusion/osf_iio.h        |  22 ++
 drivers/iio/opensensorfusion/osf_protocol.c   | 247 ++++++++++++++
 drivers/iio/opensensorfusion/osf_protocol.h   |  95 ++++++
 drivers/iio/opensensorfusion/osf_serdev.c     | 111 +++++++
 drivers/iio/opensensorfusion/osf_stream.c     | 207 ++++++++++++
 drivers/iio/opensensorfusion/osf_stream.h     |  31 ++
 17 files changed, 1761 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml
 create mode 100644 Documentation/iio/open-sensor-fusion-protocol-v0.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_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

RFC PATCH v3 1/6 dt-bindings: iio: add OSF GREEN sensor aggregation device

Describe OSF GREEN as the first board target.

Add vendor prefix and MAINTAINERS binding entry.

---
 .../iio/imu/opensensorfusion,osf-green.yaml   | 43 +++++++++++++++++++
 .../devicetree/bindings/vendor-prefixes.yaml  |  2 +
 MAINTAINERS                                   |  5 +++
 3 files changed, 50 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml
Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml new file +43 -0
new file mode 100644
index 000000000..626b41fb0
@@ -0,0 +1,43 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/imu/opensensorfusion,osf-green.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: OSF GREEN sensor aggregation board
+
+maintainers:
+  - Jinseob Kim <[email protected]>
+
+description: |
+  OSF GREEN is an STM32F405-based sensor aggregation board from the Open
+  Sensor Fusion open hardware project. It sends OSF0 capability, status, and
+  sample frames to a host over a UART link.
+
+  Open Sensor Fusion is not a generic industry standard. Public project and
+  hardware documentation is available at:
+
+    https://github.com/opensensorfusion
+    https://github.com/opensensorfusion/opensensorfusion-hardware
+
+allOf:
+  - $ref: /schemas/serial/serial-peripheral-props.yaml#
+
+properties:
+  compatible:
+    const: opensensorfusion,osf-green
+
+required:
+  - compatible
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    serial {
+        sensor {
+            compatible = "opensensorfusion,osf-green";
+        };
+    };
+
+...
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
index 28784d66a..f1b1f2ad3 100644
@@ -1237,6 +1237,8 @@ patternProperties:
     description: OpenPandora GmbH
   "^openrisc,.*":
     description: OpenRISC.io
+  "^opensensorfusion,.*":
+    description: Open Sensor Fusion project
   "^openwrt,.*":
     description: OpenWrt
   "^option,.*":
MAINTAINERS +5 -0
index c2c6d7927..26bbdf8d3 100644
@@ -19977,6 +19977,11 @@ F:	Documentation/networking/oa-tc6-framework.rst
 F:	drivers/net/ethernet/oa_tc6.c
 F:	include/linux/oa_tc6.h
 
+OPEN SENSOR FUSION IIO DRIVER
+M:	Jinseob Kim <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml
+
 OPEN FIRMWARE AND FLATTENED DEVICE TREE
 M:	Rob Herring <[email protected]>
 M:	Saravana Kannan <[email protected]>
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH RFC v3 1/6] dt-bindings: iio: add OSF GREEN sensor aggregation device

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The new entry in the MAINTAINERS file is not sorted alphabetically. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The new entry in the MAINTAINERS file is not sorted alphabetically. --

commit 869d40e7e24db8cc9824d50010506b2a425a4d29
Author: Jinseob Kim <[email protected]>

dt-bindings: iio: add OSF GREEN sensor aggregation device

This commit adds the device tree binding for the OSF GREEN sensor aggregation board. It also introduces the vendor prefix and adds the corresponding entry to the MAINTAINERS file.

[ ... ]

Quoted 5 lines
MAINTAINERS +0 -0
index 6aa3fe2ee1bbf..5931d46fcabc2 100644

MAINTAINERS F: Documentation/networking/oa-tc6-framework.rst · line 19985

Quoted 9 lines
MAINTAINERS +5 -0
@@ -19977,6 +19977,11 @@ F:	Documentation/networking/oa-tc6-framework.rst
 F:	drivers/net/ethernet/oa_tc6.c
 F:	include/linux/oa_tc6.h
 
+OPEN SENSOR FUSION IIO DRIVER
+M:	Jinseob Kim <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml
+
 OPEN FIRMWARE AND FLATTENED DEVICE TREE

[Severity: Low]
This isn't a bug, but should this new entry be placed after the Open Firmware section? MAINTAINERS entries are typically sorted alphabetically by their section titles to prevent merge conflicts. Because S comes after F alphabetically, Open Sensor Fusion should probably appear after Open Firmware and Flattened Device Tree.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH RFC v3 1/6] dt-bindings: iio: add OSF GREEN sensor aggregation device

In reply to Jinseob Kim

Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml

Quoted 17 lines · Jinseob Kim

Describe OSF GREEN as the first board target.

Add vendor prefix and MAINTAINERS binding entry.

---
 .../iio/imu/opensensorfusion,osf-green.yaml   | 43 +++++++++++++++++++
 .../devicetree/bindings/vendor-prefixes.yaml  |  2 +
 MAINTAINERS                                   |  5 +++
 3 files changed, 50 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml
Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml new file +0 -0
new file mode 100644
index 000000000..626b41fb0

This is still not an IMU.
pw-bot: changes-requested

Quoted 19 lines
Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml new file +18 -0
@@ -0,0 +1,43 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/imu/opensensorfusion,osf-green.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: OSF GREEN sensor aggregation board
+
+maintainers:
+  - Jinseob Kim <[email protected]>
+
+description: |
+  OSF GREEN is an STM32F405-based sensor aggregation board from the Open
+  Sensor Fusion open hardware project. It sends OSF0 capability, status, and
+  sample frames to a host over a UART link.
+
+  Open Sensor Fusion is not a generic industry standard. Public project and
+  hardware documentation is available at:

Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml line 28

Quoted 10 lines
Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml new file +10 -0
+
+    https://github.com/opensensorfusion
+    https://github.com/opensensorfusion/opensensorfusion-hardware
+
+allOf:
+  - $ref: /schemas/serial/serial-peripheral-props.yaml#
+
+properties:
+  compatible:
+    const: opensensorfusion,osf-green

I'm still not convinced by the compatible here, or at least I am not convinced by it without clear answers to my questions on v1 about discoverability and compatibility between protocol versions. If the software on the "osf-green" is updatable (it is, right?) the compatible doesn't actually represent the hardware, it represents the programming model of what's exposed on the serial port to the host. That means the compatible you use has to identify the exact protocol version implemented, or provide enough information that the version can be figured out by software.

Given you talk about OSF0 communicating capability etc, it seems to me like OSF0 is a discoverable bus? In that case, compatibles for boards doesn't really matter, all software should need to know is that there is an OSF0 "bus" and query it for what sensors are there.

The questions I asked on v1 were:
- What does "v0" mean here? Is the data format not complete yet?
- Are versions of the protocol likely to be backwards compatible?
- Will the device identify what version of the protocol it implements?

Remember, there's no rush here, and you're better off slowing down and taking your time responding to reviews before sending new versions, so that the same conversations don't take place multiple times.

Cheers,
Conor.

Quoted 47 lines
Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml new file +15 -0
+
+required:
+  - compatible
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    serial {
+        sensor {
+            compatible = "opensensorfusion,osf-green";
+        };
+    };
+
+...
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
index 28784d66a..f1b1f2ad3 100644
@@ -1237,6 +1237,8 @@ patternProperties:
     description: OpenPandora GmbH
   "^openrisc,.*":
     description: OpenRISC.io
+  "^opensensorfusion,.*":
+    description: Open Sensor Fusion project
   "^openwrt,.*":
     description: OpenWrt
   "^option,.*":
MAINTAINERS +5 -0
index c2c6d7927..26bbdf8d3 100644
@@ -19977,6 +19977,11 @@ F:	Documentation/networking/oa-tc6-framework.rst
 F:	drivers/net/ethernet/oa_tc6.c
 F:	include/linux/oa_tc6.h
 
+OPEN SENSOR FUSION IIO DRIVER
+M:	Jinseob Kim <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml
+
 OPEN FIRMWARE AND FLATTENED DEVICE TREE
 M:	Rob Herring <[email protected]>
 M:	Saravana Kannan <[email protected]>
Signature · 1 line
2.43.0
maintainer
#4 lore raw

Re: [PATCH RFC v3 1/6] dt-bindings: iio: add OSF GREEN sensor aggregation device

Quoted 13 lines · On Fri, 29 May 2026 17:31:42 +0100 Conor Dooley <[email protected]> wrote:
Quoted 12 lines · Jinseob Kim

Describe OSF GREEN as the first board target.

Add vendor prefix and MAINTAINERS binding entry.

---
 .../iio/imu/opensensorfusion,osf-green.yaml   | 43 +++++++++++++++++++
 .../devicetree/bindings/vendor-prefixes.yaml  |  2 +
 MAINTAINERS                                   |  5 +++
 3 files changed, 50 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml
Quoted 7 lines

Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml

Quoted 5 lines
Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml new file +0 -0
new file mode 100644
index 000000000..626b41fb0

This is still not an IMU.

Might include one but agreed, it is more. So probably move it up a a directory to bindings/iio as it's more of a sensorhub.

Quoted 42 lines

pw-bot: changes-requested

Quoted 19 lines
Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml new file +18 -0
@@ -0,0 +1,43 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/imu/opensensorfusion,osf-green.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: OSF GREEN sensor aggregation board
+
+maintainers:
+  - Jinseob Kim <[email protected]>
+
+description: |
+  OSF GREEN is an STM32F405-based sensor aggregation board from the Open
+  Sensor Fusion open hardware project. It sends OSF0 capability, status, and
+  sample frames to a host over a UART link.
+
+  Open Sensor Fusion is not a generic industry standard. Public project and
+  hardware documentation is available at:

Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml line 28

Quoted 10 lines
Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml new file +10 -0
+
+    https://github.com/opensensorfusion
+    https://github.com/opensensorfusion/opensensorfusion-hardware
+
+allOf:
+  - $ref: /schemas/serial/serial-peripheral-props.yaml#
+
+properties:
+  compatible:
+    const: opensensorfusion,osf-green  

I'm still not convinced by the compatible here, or at least I am not convinced by it without clear answers to my questions on v1 about discoverability and compatibility between protocol versions. If the software on the "osf-green" is updatable (it is, right?) the compatible doesn't actually represent the hardware, it represents the programming model of what's exposed on the serial port to the host. That means the compatible you use has to identify the exact protocol version implemented, or provide enough information that the version can be figured out by software.

Quoted 4 lines

Given you talk about OSF0 communicating capability etc, it seems to me like OSF0 is a discoverable bus? In that case, compatibles for boards doesn't really matter, all software should need to know is that there is an OSF0 "bus" and query it for what sensors are there.

Agreed - should be very generic and rely on protocol discovery. Only need to break that if some some silly reason the way protocol version is discovered changes.

Quoted 13 lines

The questions I asked on v1 were:
- What does "v0" mean here? Is the data format not complete yet?
- Are versions of the protocol likely to be backwards compatible?
- Will the device identify what version of the protocol it implements?

Remember, there's no rush here, and you're better off slowing down and taking your time responding to reviews before sending new versions, so that the same conversations don't take place multiple times.

Cheers,
Conor.

#5 lore raw

RFC PATCH v3 2/6 Documentation: iio: add Open Sensor Fusion protocol v0 reference

In reply to Jinseob Kim

Document OSF0 UART frames and the supported RFC driver subset.

Extend MAINTAINERS to cover the protocol reference.

---
 .../iio/open-sensor-fusion-protocol-v0.rst    | 308 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 309 insertions(+)
 create mode 100644 Documentation/iio/open-sensor-fusion-protocol-v0.rst
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +308 -0
new file mode 100644
index 000000000..80852f4cf
@@ -0,0 +1,308 @@
+.. SPDX-License-Identifier: GPL-2.0-only
+
+Open Sensor Fusion protocol v0
+==============================
+
+This document describes the OSF0 UART wire format used by the Open Sensor
+Fusion Linux IIO driver. It is a wire format reference for the host driver. It
+is not a firmware programming interface.
+
+Background
+----------
+
+Open Sensor Fusion is an open hardware project for sensor aggregation devices
+and Linux IIO host support. It is not a generic sensor protocol standard. The
+first concrete hardware target is OSF GREEN, an STM32F405-based board that
+streams OSF0 frames to a Linux host.
+
+Public project documentation is available at:
+
+- https://www.opensensorfusion.org/
+- https://github.com/opensensorfusion
+- https://github.com/opensensorfusion/opensensorfusion-hardware
+- https://github.com/opensensorfusion/opensensorfusion-linux
+
+Wire format and driver subset
+-----------------------------
+
+OSF0 defines a small device-to-host UART frame format. The current RFC driver
+supports only the subset needed to expose OSF GREEN raw sensor data through
+IIO:
+
+- ``SENSOR_SAMPLE`` frames for accelerometer, gyroscope, magnetometer, and
+  temperature samples.
+- ``CAPABILITY_REPORT`` frames used to create the supported IIO devices.
+- ``DEVICE_STATUS`` frames cached for diagnostics.
+
+The driver ignores vendor private message types and does not implement command
+transport, calibration controls, USB transport, fusion output, or runtime
+capability removal.
+
+Device model
+------------
+
+An OSF0 device is a sensor aggregation device. It sends binary frames from the
+device to the host. The host driver decodes the frames and maps supported
+sensors to IIO devices.
+
+The hardware used for smoke testing is an OSF GREEN prototype with an
+STM32F405RGT6 MCU, an ICM42688P-class IMU, and an MMC5983MA magnetometer. That
+hardware is the first supported target for the RFC driver.
+
+Transport
+---------
+
+The transport is UART at 115200 baud, 8 data bits, no parity, and 1 stop bit.
+The Linux transport is serdev. The v0 upstream driver covers device-to-host
+frames. Flow control is not used by the tested stream.
+
+Byte order
+----------
+
+All multi-byte integer fields are little-endian. Samples use signed 32-bit
+little-endian integers when ``sample_format`` is ``s32``.
+
+Frame format
+------------
+
+Each frame has a fixed 38-byte header, a payload, and a 4-byte CRC.
+
+.. list-table::
+   :header-rows: 1
+
+   * - Offset
+     - Size
+     - Field
+     - Description
+   * - 0
+     - 4
+     - magic
+     - ASCII ``OSF0``
+   * - 4
+     - 1
+     - protocol_major
+     - Must be ``0``
+   * - 5
+     - 1
+     - protocol_minor
+     - Minor version
+   * - 6
+     - 2
+     - header_len
+     - Must be ``38``
+   * - 8
+     - 2
+     - message_type
+     - Message type
+   * - 10
+     - 4
+     - payload_len
+     - Payload length in bytes
+   * - 14
+     - 8
+     - sequence
+     - Monotonic device sequence
+   * - 22
+     - 8
+     - timestamp_us
+     - Device timestamp in microseconds
+   * - 30
+     - 4
+     - flags
+     - Message flags
+   * - 34
+     - 4
+     - reserved
+     - Must be zero for v0
+   * - 38
+     - payload_len
+     - payload
+     - Message payload
+   * - 38 + payload_len
+     - 4
+     - crc32
+     - CRC32 over header and payload
+
+The frame CRC is IEEE CRC32 as implemented by ``crc32_le()`` with initial
+value ``0xffffffff`` and final XOR value ``0xffffffff``. The CRC field is not
+included in the CRC input.
+
+Message types
+-------------
+
+.. list-table::
+   :header-rows: 1
+
+   * - Value
+     - Name
+     - Direction
+   * - ``0x0001``
+     - ``SENSOR_SAMPLE``
+     - device to host
+   * - ``0x0002``
+     - ``DEVICE_STATUS``
+     - device to host
+   * - ``0x0003``
+     - ``CAPABILITY_REPORT``
+     - device to host
+
+Message types ``0x7f00`` through ``0x7fff`` are reserved. Values at or above
+``0x8000`` are vendor private and are ignored by the current RFC driver.
+
+``SENSOR_SAMPLE`` payload
+-------------------------
+
+The payload is a 16-byte payload header followed by ``4 * channel_count`` bytes
+of sample data.
+
+.. list-table::
+   :header-rows: 1
+
+   * - Offset
+     - Size
+     - Field
+     - Description
+   * - 0
+     - 2
+     - sensor_type
+     - Sensor type ID
+   * - 2
+     - 2
+     - sensor_index
+     - Instance index
+   * - 4
+     - 2
+     - channel_count
+     - Number of ``s32`` channels
+   * - 6
+     - 2
+     - sample_format
+     - Must be ``1`` (``s32``)
+   * - 8
+     - 4
+     - scale_nano
+     - Scale factor in nano-units
+   * - 12
+     - 4
+     - reserved
+     - Must be zero for v0
+   * - 16
+     - 4 * channel_count
+     - samples
+     - Signed 32-bit channel samples
+
+The current RFC driver accepts only ``sample_format = s32`` and only the fixed
+channel counts used by its supported IIO devices.
+
+``DEVICE_STATUS`` payload
+-------------------------
+
+The payload size is 20 bytes. Fields are ``uptime_s``, ``status_flags``,
+``error_flags``, ``dropped_frames``, and a reserved field. Each field is
+32 bits. The reserved field must be zero for v0.
+
+``CAPABILITY_REPORT`` payload
+-----------------------------
+
+The base payload size is 4 bytes. It contains ``capability_count`` and a
+reserved field. The reserved field must be zero for v0. Each capability entry
+is 20 bytes:
+
+.. list-table::
+   :header-rows: 1
+
+   * - Offset
+     - Size
+     - Field
+     - Description
+   * - 0
+     - 2
+     - sensor_type
+     - Sensor type ID
+   * - 2
+     - 2
+     - sensor_index
+     - Instance index
+   * - 4
+     - 2
+     - channel_count
+     - Number of channels
+   * - 6
+     - 2
+     - sample_format
+     - Must be ``1`` (``s32``)
+   * - 8
+     - 4
+     - scale_nano
+     - Scale factor in nano-units
+   * - 12
+     - 4
+     - flags
+     - Capability flags
+   * - 16
+     - 4
+     - reserved
+     - Must be zero for v0
+
+Capability flag bit 0 means enabled by default. Bit 1 means calibrated data can
+be provided by the device. Other bits are invalid for v0.
+
+Sensor type IDs
+---------------
+
+.. list-table::
+   :header-rows: 1
+
+   * - Value
+     - Sensor
+     - Current RFC driver mapping
+   * - ``0x0001``
+     - accelerometer
+     - ``IIO_ACCEL``, X/Y/Z
+   * - ``0x0002``
+     - gyroscope
+     - ``IIO_ANGL_VEL``, X/Y/Z
+   * - ``0x0003``
+     - magnetometer
+     - ``IIO_MAGN``, X/Y/Z
+   * - ``0x0004``
+     - barometer
+     - not mapped
+   * - ``0x0005``
+     - temperature
+     - ``IIO_TEMP``
+   * - ``0x0006``
+     - humidity
+     - not mapped
+   * - ``0x0007``
+     - ambient light
+     - not mapped
+   * - ``0x0008``
+     - proximity
+     - not mapped
+
+Scaling
+-------
+
+``scale_nano`` is the per-channel scale value in nano-units. The Linux driver
+maps it to ``IIO_CHAN_INFO_SCALE`` as integer plus nano. The exact physical
+unit depends on the IIO channel type.
+
+Timestamps
+----------
+
+The frame header carries ``timestamp_us``, a device-side timestamp in
+microseconds. UART buffering and host scheduling can add delay before a frame
+is processed by the host.
+
+The current RFC driver does not claim production-grade host/device timestamp
+correlation. Buffered IIO timestamps are taken from IIO timestamp clock handling
+when samples are pushed to IIO buffers.
+
+Non-goals for v0 upstream
+-------------------------
+
+The v0 upstream driver does not include USB transport, fusion output, Attitude
+and Heading Reference System (AHRS) output, Kalman output, calibration command
+ABI, custom sysfs control surface, production timestamp correlation, or runtime
+capability removal.
MAINTAINERS +1 -0
index 26bbdf8d3..6ccaaa738 100644
@@ -19981,6 +19981,7 @@ OPEN SENSOR FUSION IIO DRIVER
 M:	Jinseob Kim <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml
+F:	Documentation/iio/open-sensor-fusion-protocol-v0.rst
 
 OPEN FIRMWARE AND FLATTENED DEVICE TREE
 M:	Rob Herring <[email protected]>
Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH RFC v3 2/6] Documentation: iio: add Open Sensor Fusion protocol v0 reference

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The newly added documentation file `open-sensor-fusion-protocol-v0.rst` is not included in any…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The newly added documentation file open-sensor-fusion-protocol-v0.rst is not included in any toctree. --

commit 6378b8f2ea4ed104155c2c56a270addafda38309
Author: Jinseob Kim <[email protected]>

Documentation: iio: add Open Sensor Fusion protocol v0 reference

This commit documents the OSF0 UART frames and the supported RFC driver subset. It also extends the MAINTAINERS file to cover the new protocol reference documentation.

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 4

Quoted 10 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +4 -0
new file mode 100644
index 0000000000000..80852f4cf4f1f
@@ -0,0 +1,308 @@
+.. SPDX-License-Identifier: GPL-2.0-only
+
+Open Sensor Fusion protocol v0
+==============================

[Severity: Low]
This new documentation file does not appear to be included in any toctree, such as the one in Documentation/iio/index.rst. Should it be added to an index to ensure it is discoverable and to prevent a Sphinx build warning about the document not being included in any toctree?

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
maintainer
#7 lore raw

Re: [PATCH RFC v3 2/6] Documentation: iio: add Open Sensor Fusion protocol v0 reference

In reply to Jinseob Kim
Quoted 3 lines · On Fri, 29 May 2026 21:10:01 +0900 Jinseob Kim <[email protected]> wrote:

Document OSF0 UART frames and the supported RFC driver subset.

Extend MAINTAINERS to cover the protocol reference.

Some of this perhaps should just be cross references to project docs. Other things that repeat:
- Avoid lists of what isn't supported. They become wrong fast, just list what is supported.
- Don't reference driver versions (definitely not RFC ones!) in docs.

Mostly a case of ensuing you have one canonical source for the protocol docs and that what you have here doesn't become 'wrong' if new features are added either to the sensor platform, or to the driver - it just becomes potentially out of date.

Jonathan

Quoted 14 lines
---
 .../iio/open-sensor-fusion-protocol-v0.rst    | 308 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 309 insertions(+)
 create mode 100644 Documentation/iio/open-sensor-fusion-protocol-v0.rst
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +0 -0
new file mode 100644
index 000000000..80852f4cf

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 7

Quoted 7 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +7 -0
@@ -0,0 +1,308 @@
+.. SPDX-License-Identifier: GPL-2.0-only
+
+Open Sensor Fusion protocol v0
+==============================
+
+This document describes the OSF0 UART wire format used by the Open Sensor
+Fusion Linux IIO driver. It is a wire format reference for the host driver. It

I'd argue this is spinning it wrong. It is the wire format used by the device implementing your protocol. Linux is just one "customer".

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 14

Quoted 7 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +7 -0
+is not a firmware programming interface.
+
+Background
+----------
+
+Open Sensor Fusion is an open hardware project for sensor aggregation devices
+and Linux IIO host support. It is not a generic sensor protocol standard. The

Again, why Linux specific? Nothing wrong with starting there, but if this is successful seems unlikely this will be the only host OS.

I'd talk about the Linux/IIO driver as a reference stack or something like that.

Quoted 5 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +5 -0
+first concrete hardware target is OSF GREEN, an STM32F405-based board that
+streams OSF0 frames to a Linux host.
+
+Public project documentation is available at:
+

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 28

Quoted 10 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +9 -0
+- https://www.opensensorfusion.org/
+- https://github.com/opensensorfusion
+- https://github.com/opensensorfusion/opensensorfusion-hardware
+- https://github.com/opensensorfusion/opensensorfusion-linux
 
+
+Wire format and driver subset
+-----------------------------
+
+OSF0 defines a small device-to-host UART frame format. The current RFC driver

Don't talk about "RFC" in here because that's just text that will become wrong and might get missed when you move on from RFCs.

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 39

Quoted 11 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +11 -0
+supports only the subset needed to expose OSF GREEN raw sensor data through
+IIO:
+
+- ``SENSOR_SAMPLE`` frames for accelerometer, gyroscope, magnetometer, and
+  temperature samples.
+- ``CAPABILITY_REPORT`` frames used to create the supported IIO devices.
+- ``DEVICE_STATUS`` frames cached for diagnostics.
+
+The driver ignores vendor private message types and does not implement command
+transport, calibration controls, USB transport, fusion output, or runtime
+capability removal.

Generally I'd avoid adding notes in documentation for what is 'not' supported. That stuff tends to become wrong fast :) Just focus on what is supported and by all means say that it is a subset of functionality, just don't list what that 'other' is.

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 44

Quoted 5 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +5 -0
+
+Device model
+------------
+
+An OSF0 device is a sensor aggregation device. It sends binary frames from the

What does the 0 in OSF0 mean?

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 50

Quoted 6 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +6 -0
+device to the host. The host driver decodes the frames and maps supported
+sensors to IIO devices.
+
+The hardware used for smoke testing is an OSF GREEN prototype with an
+STM32F405RGT6 MCU, an ICM42688P-class IMU, and an MMC5983MA magnetometer. That
+hardware is the first supported target for the RFC driver.

Keep that for the cover letter. Don't say what you tested in on this doc as it'll likely become wrong very fast.

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 56

Quoted 6 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +6 -0
+
+Transport
+---------
+
+The transport is UART at 115200 baud, 8 data bits, no parity, and 1 stop bit.
+The Linux transport is serdev. The v0 upstream driver covers device-to-host

I'd skip serdev reference, that is an implementation detail we don't need in this doc.

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 63

Quoted 7 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +7 -0
+frames. Flow control is not used by the tested stream.
+
+Byte order
+----------
+
+All multi-byte integer fields are little-endian. Samples use signed 32-bit
+little-endian integers when ``sample_format`` is ``s32``.

If this is always the case, it's a detail that belongs in your project docs. If you are calling out the subset that Linux is supporting then make that clear.

"The driver supports the signed 32-bit little endian sample format."

That s32 things is a little confusing as it's __le32 in Linux if it is little endian. Maybe don't use that and just spell out what it is.

Quoted 55 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +55 -0
+
+Frame format
+------------
+
+Each frame has a fixed 38-byte header, a payload, and a 4-byte CRC.
+
+.. list-table::
+   :header-rows: 1
+
+   * - Offset
+     - Size
+     - Field
+     - Description
+   * - 0
+     - 4
+     - magic
+     - ASCII ``OSF0``
+   * - 4
+     - 1
+     - protocol_major
+     - Must be ``0``
+   * - 5
+     - 1
+     - protocol_minor
+     - Minor version
+   * - 6
+     - 2
+     - header_len
+     - Must be ``38``
+   * - 8
+     - 2
+     - message_type
+     - Message type
+   * - 10
+     - 4
+     - payload_len
+     - Payload length in bytes
+   * - 14
+     - 8
+     - sequence
+     - Monotonic device sequence
+   * - 22
+     - 8
+     - timestamp_us
+     - Device timestamp in microseconds
+   * - 30
+     - 4
+     - flags
+     - Message flags
+   * - 34
+     - 4
+     - reserved
+     - Must be zero for v0
+   * - 38
+     - payload_len

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 128

Quoted 10 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +10 -0
+     - payload
+     - Message payload
+   * - 38 + payload_len
+     - 4
+     - crc32
+     - CRC32 over header and payload
+
+The frame CRC is IEEE CRC32 as implemented by ``crc32_le()`` with initial
+value ``0xffffffff`` and final XOR value ``0xffffffff``. The CRC field is not
+included in the CRC input.

Feels like details that belong in project docs, not here.

Quoted 13 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +13 -0
+
+Message types
+-------------
+
+.. list-table::
+   :header-rows: 1
+
+   * - Value
+     - Name
+     - Direction
+   * - ``0x0001``
+     - ``SENSOR_SAMPLE``
+     - device to host

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 151

Quoted 10 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +10 -0
+   * - ``0x0002``
+     - ``DEVICE_STATUS``
+     - device to host
+   * - ``0x0003``
+     - ``CAPABILITY_REPORT``
+     - device to host
+
+Message types ``0x7f00`` through ``0x7fff`` are reserved. Values at or above
+``0x8000`` are vendor private and are ignored by the current RFC driver.
+

Likewise, project docs.

Quoted 34 lines

+``SENSOR_SAMPLE`` payload
+-------------------------

Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +32 -0
+
+The payload is a 16-byte payload header followed by ``4 * channel_count`` bytes
+of sample data.
+
+.. list-table::
+   :header-rows: 1
+
+   * - Offset
+     - Size
+     - Field
+     - Description
+   * - 0
+     - 2
+     - sensor_type
+     - Sensor type ID
+   * - 2
+     - 2
+     - sensor_index
+     - Instance index
+   * - 4
+     - 2
+     - channel_count
+     - Number of ``s32`` channels
+   * - 6
+     - 2
+     - sample_format
+     - Must be ``1`` (``s32``)
+   * - 8
+     - 4
+     - scale_nano
+     - Scale factor in nano-units
+   * - 12

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 195

Quoted 10 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +10 -0
+     - 4
+     - reserved
+     - Must be zero for v0
+   * - 16
+     - 4 * channel_count
+     - samples
+     - Signed 32-bit channel samples
+
+The current RFC driver accepts only ``sample_format = s32`` and only the fixed
+channel counts used by its supported IIO devices.

Also project docs.

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 203

Quoted 8 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +8 -0
+
+``DEVICE_STATUS`` payload
+-------------------------
+
+The payload size is 20 bytes. Fields are ``uptime_s``, ``status_flags``,
+``error_flags``, ``dropped_frames``, and a reserved field. Each field is
+32 bits. The reserved field must be zero for v0.
+

As a side note, if you've built your protocol well then it should be backwards compatible. So you shouldn't care what the payload size is for messages like this other than it is >= 20 and for now the driver only understands 20 bytes.

However, I'd just not say it here - keep it for project docs.

Quoted 36 lines

+``CAPABILITY_REPORT`` payload
+-----------------------------

Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +34 -0
+
+The base payload size is 4 bytes. It contains ``capability_count`` and a
+reserved field. The reserved field must be zero for v0. Each capability entry
+is 20 bytes:
+
+.. list-table::
+   :header-rows: 1
+
+   * - Offset
+     - Size
+     - Field
+     - Description
+   * - 0
+     - 2
+     - sensor_type
+     - Sensor type ID
+   * - 2
+     - 2
+     - sensor_index
+     - Instance index
+   * - 4
+     - 2
+     - channel_count
+     - Number of channels
+   * - 6
+     - 2
+     - sample_format
+     - Must be ``1`` (``s32``)
+   * - 8
+     - 4
+     - scale_nano
+     - Scale factor in nano-units
+   * - 12
+     - 4

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 249

Quoted 10 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +10 -0
+     - flags
+     - Capability flags
+   * - 16
+     - 4
+     - reserved
+     - Must be zero for v0
+
+Capability flag bit 0 means enabled by default. Bit 1 means calibrated data can
+be provided by the device. Other bits are invalid for v0.
+

Likewise, project docs.

Quoted 23 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +23 -0
+Sensor type IDs
+---------------
+
+.. list-table::
+   :header-rows: 1
+
+   * - Value
+     - Sensor
+     - Current RFC driver mapping
+   * - ``0x0001``
+     - accelerometer
+     - ``IIO_ACCEL``, X/Y/Z
+   * - ``0x0002``
+     - gyroscope
+     - ``IIO_ANGL_VEL``, X/Y/Z
+   * - ``0x0003``
+     - magnetometer
+     - ``IIO_MAGN``, X/Y/Z
+   * - ``0x0004``
+     - barometer
+     - not mapped
+   * - ``0x0005``
+     - temperature

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 282

Quoted 10 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +10 -0
+     - ``IIO_TEMP``
+   * - ``0x0006``
+     - humidity
+     - not mapped
+   * - ``0x0007``
+     - ambient light
+     - not mapped
+   * - ``0x0008``
+     - proximity
+     - not mapped

This is potentially interesting, but I don't think we care about the IDs, just what device types are supported and the fact they are either 1D or 3D depending on device type.

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 289

Quoted 7 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +7 -0
+
+Scaling
+-------
+
+``scale_nano`` is the per-channel scale value in nano-units. The Linux driver
+maps it to ``IIO_CHAN_INFO_SCALE`` as integer plus nano. The exact physical
+unit depends on the IIO channel type.

This basically says Linux presents it right. Not needed.

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 300

Quoted 11 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +11 -0
+
+Timestamps
+----------
+
+The frame header carries ``timestamp_us``, a device-side timestamp in
+microseconds. UART buffering and host scheduling can add delay before a frame
+is processed by the host.
+
+The current RFC driver does not claim production-grade host/device timestamp
+correlation. Buffered IIO timestamps are taken from IIO timestamp clock handling
+when samples are pushed to IIO buffers.

This bit is worth capturing in the Docs, but avoid RFC reference.

Documentation/iio/open-sensor-fusion-protocol-v0.rst line 302

Quoted 2 lines
Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +2 -0
+
+Non-goals for v0 upstream

Not in here. Just list what is supported.

Quoted 18 lines

+-------------------------

Documentation/iio/open-sensor-fusion-protocol-v0.rst new file +5 -0
+
+The v0 upstream driver does not include USB transport, fusion output, Attitude
+and Heading Reference System (AHRS) output, Kalman output, calibration command
+ABI, custom sysfs control surface, production timestamp correlation, or runtime
+capability removal.
MAINTAINERS +1 -0
index 26bbdf8d3..6ccaaa738 100644
@@ -19981,6 +19981,7 @@ OPEN SENSOR FUSION IIO DRIVER
 M:	Jinseob Kim <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml
+F:	Documentation/iio/open-sensor-fusion-protocol-v0.rst
 
 OPEN FIRMWARE AND FLATTENED DEVICE TREE
 M:	Rob Herring <[email protected]>
#8 lore raw

RFC PATCH v3 3/6 iio: osf: add protocol v0 decoding

In reply to Jinseob Kim

Add OSF0 frame validation and payload decoders.

Extend MAINTAINERS to cover the protocol decoder.

---
 MAINTAINERS                                 |   1 +
 drivers/iio/opensensorfusion/osf_protocol.c | 247 ++++++++++++++++++++
 drivers/iio/opensensorfusion/osf_protocol.h |  95 ++++++++
 3 files changed, 343 insertions(+)
 create mode 100644 drivers/iio/opensensorfusion/osf_protocol.c
 create mode 100644 drivers/iio/opensensorfusion/osf_protocol.h
MAINTAINERS +1 -0
index 6ccaaa738..9fab72689 100644
@@ -19982,6 +19982,7 @@ M:	Jinseob Kim <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml
 F:	Documentation/iio/open-sensor-fusion-protocol-v0.rst
+F:	drivers/iio/opensensorfusion/osf_protocol.*
 
 OPEN FIRMWARE AND FLATTENED DEVICE TREE
 M:	Rob Herring <[email protected]>
drivers/iio/opensensorfusion/osf_protocol.c new file +247 -0

247 lines not on this page · raw message

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

95 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer
#9 lore raw

Re: [PATCH RFC v3 3/6] iio: osf: add protocol v0 decoding

Quoted 5 lines · On Fri, 29 May 2026 21:10:02 +0900 Jinseob Kim <[email protected]> wrote:

Add OSF0 frame validation and payload decoders.

Extend MAINTAINERS to cover the protocol decoder.

I've commented on a few things inline. Some of them apply in multiple places. Biggest thing is asking for rules on how this 'specification' handled backwards compatibility.

Jonathan

Quoted 17 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +11 -0
new file mode 100644
index 000000000..ed91d3dd5
 
+
+int osf_protocol_decode_capability_report(const struct osf_frame *frame,
+					  struct osf_capability_report *report)
+{
+	u16 capability_count;
+	size_t expected_len;
+	const u8 *payload;
+
+	if (!frame || !report || !frame->payload)
+		return -EINVAL;
+

drivers/iio/opensensorfusion/osf_protocol.c line 189

Quoted 10 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +10 -0
+	if (frame->message_type != OSF_MSG_CAPABILITY_REPORT)
+		return -EPROTO;
+
+	if (frame->payload_len < OSF_CAP_REPORT_BASE_LEN)
+		return -EMSGSIZE;
+
+	payload = frame->payload;
+	capability_count = get_unaligned_le16(payload);
+
+	if (get_unaligned_le16(payload + 2))

As below - these zero checks to me look like a protocol design bug. If you can I'd encourage adding something on rules for backward compatibility to your initial spec docs.

drivers/iio/opensensorfusion/osf_protocol.c line 193

Quoted 4 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +4 -0
+		return -EPROTO;
+
+	if (capability_count > (SIZE_MAX - OSF_CAP_REPORT_BASE_LEN) /
+	    OSF_CAP_SENSOR_ENTRY_LEN)

Alignment can be easier to read.

if (capability_count >
(SIZE_MAX - OSF_CAP_REPORT_BASE_LEN) / OSF_CAP_SENSOR_ENTRY_LEN)

Quoted 11 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +11 -0
+		return -EOVERFLOW;
+
+	expected_len = OSF_CAP_REPORT_BASE_LEN +
+		       capability_count * OSF_CAP_SENSOR_ENTRY_LEN;
+	if (frame->payload_len != expected_len)
+		return -EMSGSIZE;
+
+	report->capability_count = capability_count;
+	report->entries = payload + OSF_CAP_REPORT_BASE_LEN;
+
+	return 0;

drivers/iio/opensensorfusion/osf_protocol.c line 214

Quoted 10 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +10 -0
+}
+
+int osf_protocol_decode_capability_entry(const struct osf_capability_report *report,
+					 unsigned int index,
+					 struct osf_capability_entry *entry)
+{
+	u16 sample_format;
+	u16 sensor_type;
+	u32 flags;
+	const u8 *payload;

If no other reason for order, use reverse xmas tree. Also fine to combine entries of same type as long as non assign values. Up to you if you'd prefer not to.

	u16 sample_format, sensor_type;
	const u8 *payload;
	u32 flags;
Quoted 12 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +12 -0
+
+	if (!report || !report->entries || !entry)
+		return -EINVAL;
+
+	if (index >= report->capability_count)
+		return -ERANGE;
+
+	payload = report->entries + index * OSF_CAP_SENSOR_ENTRY_LEN;
+	sensor_type = get_unaligned_le16(payload);
+	sample_format = get_unaligned_le16(payload + 6);
+	flags = get_unaligned_le32(payload + 12);
+

drivers/iio/opensensorfusion/osf_protocol.c line 236

Quoted 10 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +10 -0
+	if (!osf_sensor_type_valid(sensor_type))
+		return -EPROTO;
+
+	if (sample_format != OSF_SAMPLE_FORMAT_S32)
+		return -EPROTO;
+
+	if (flags & ~OSF_CAPABILITY_FLAGS_MASK)
+		return -EPROTO;
+
+	if (get_unaligned_le32(payload + 16))

That needs more info. I guess it's check reserved is 0? In an extensible protocol design there should be no need to check that. If a future version adds stuff in there then there are rules on how it is done.

1) Not by default, needs to be enabled be aware software.
2) If by default, can be ignored, but must be discoverable - i.e. we must know if 0 means the value 0 or reserved0
3) If we can't ignore it then 0 must be natural default. I.e. future capability bits, 0 means not supported.

Upshot, unless the protocol design for future versions is broken there should never be a reason to check reserved values are 0 other than debug.

If you really need to keep this because the protocol design is not backwards compatible, then add a comment on what that check is.

Quoted 26 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +11 -0
+		return -EPROTO;
+
+	entry->sensor_type = sensor_type;
+	entry->sensor_index = get_unaligned_le16(payload + 2);
+	entry->channel_count = get_unaligned_le16(payload + 4);
+	entry->sample_format = sample_format;
+	entry->scale_nano = get_unaligned_le32(payload + 8);
+	entry->flags = flags;
+
+	return 0;
+}
drivers/iio/opensensorfusion/osf_protocol.h new file +9 -0
new file mode 100644
index 000000000..4b6fb131a
@@ -0,0 +1,95 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _OSF_PROTOCOL_H
+#define _OSF_PROTOCOL_H
+
+#include <linux/types.h>
+
+#define OSF_PROTOCOL_MAJOR		0
+#define OSF_PROTOCOL_MINOR		0
+#define OSF_FRAME_HEADER_LEN		38

drivers/iio/opensensorfusion/osf_protocol.h line 19

Quoted 10 lines
drivers/iio/opensensorfusion/osf_protocol.h new file +10 -0
+#define OSF_FRAME_CRC_LEN		4
+#define OSF_FRAME_MIN_LEN		(OSF_FRAME_HEADER_LEN + OSF_FRAME_CRC_LEN)
+
+#define OSF_SENSOR_SAMPLE_BASE_LEN	16
+#define OSF_DEVICE_STATUS_LEN		20
+#define OSF_CAP_REPORT_BASE_LEN		4
+#define OSF_CAP_SENSOR_ENTRY_LEN		20
+#define OSF_CAPABILITY_FLAGS_MASK	0x00000003U
+
+enum osf_message_type {

Ideally each of these blocks would have a reference to a spec document section. From website I guess that doc is a work in progress?

Quoted 19 lines
drivers/iio/opensensorfusion/osf_protocol.h new file +19 -0
+	OSF_MSG_SENSOR_SAMPLE		= 0x0001,
+	OSF_MSG_DEVICE_STATUS		= 0x0002,
+	OSF_MSG_CAPABILITY_REPORT	= 0x0003,
+};
+
+enum osf_sensor_type {
+	OSF_SENSOR_ACCELEROMETER		= 0x0001,
+	OSF_SENSOR_GYROSCOPE		= 0x0002,
+	OSF_SENSOR_MAGNETOMETER		= 0x0003,
+	OSF_SENSOR_BAROMETER		= 0x0004,
+	OSF_SENSOR_TEMPERATURE		= 0x0005,
+	OSF_SENSOR_HUMIDITY		= 0x0006,
+	OSF_SENSOR_AMBIENT_LIGHT		= 0x0007,
+	OSF_SENSOR_PROXIMITY		= 0x0008,
+};
+
+enum osf_sample_format {
+	OSF_SAMPLE_FORMAT_S32		= 0x0001,
+};

drivers/iio/opensensorfusion/osf_protocol.h line 47

Quoted 10 lines
drivers/iio/opensensorfusion/osf_protocol.h new file +9 -0
+
 
+struct osf_frame {
+	u8 protocol_minor;
+	u16 message_type;
+	u32 payload_len;
+	u64 sequence;
+	u64 timestamp_us;
+	u32 flags;
+	const u8 *payload;

#
__counted_by_ptr(payload_len); ?

drivers/iio/opensensorfusion/osf_protocol.h line 57

Quoted 10 lines
drivers/iio/opensensorfusion/osf_protocol.h new file +10 -0
+	u32 crc;
+};
+
+struct osf_sensor_sample {
+	u16 sensor_type;
+	u16 sensor_index;
+	u16 channel_count;
+	u16 sample_format;
+	u32 scale_nano;
+	const u8 *samples;

I guess we don't know the alignement so can't
type this and that also stops use doing __counted_by_ptr() which is annoying.

Quoted 22 lines
drivers/iio/opensensorfusion/osf_protocol.h new file +22 -0
+};
+
+struct osf_device_status {
+	u32 uptime_s;
+	u32 status_flags;
+	u32 error_flags;
+	u32 dropped_frames;
+};
+
+struct osf_capability_report {
+	u16 capability_count;
+	const u8 *entries;
+};
+
+struct osf_capability_entry {
+	u16 sensor_type;
+	u16 sensor_index;
+	u16 channel_count;
+	u16 sample_format;
+	u32 scale_nano;
+	u32 flags;
+};
#10 lore raw

Re: [PATCH RFC v3 3/6] iio: osf: add protocol v0 decoding

In reply to Jinseob Kim
Quoted 3 lines · Jinseob Kim

Add OSF0 frame validation and payload decoders.

Extend MAINTAINERS to cover the protocol decoder.

Unneeded detail in the commit message. It's implied that MAINTAINERS is updated accordingly.

...

Quoted 7 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +7 -0
+int osf_protocol_decode_frame(const u8 *buf, size_t len,
+			      struct osf_frame *frame, size_t *frame_len)
+{
+	u32 expected_crc;
+	u32 actual_crc;
+	u32 payload_len;
+	size_t total_len;

drivers/iio/opensensorfusion/osf_protocol.c line 42

Quoted 10 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +9 -0
+	u8 major;
+
+	if (!buf || !frame || !frame_len)
+		return -EINVAL;
+
+	if (len < OSF_FRAME_MIN_LEN)
+		return -EMSGSIZE;
 
+	if (buf[0] != 'O' || buf[1] != 'S' || buf[2] != 'F' || buf[3] != '0')
+		return -EPROTO;

It's FourCC, define it as integer and compare as integer

#define ..._MAGIC 0xhhhhhhhh /* OSF0 */

	if (get_unaligned_le32() != _MAGIC)
Quoted 33 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +33 -0
+	major = buf[4];
+	if (major != OSF_PROTOCOL_MAJOR)
+		return -EPROTO;
+
+	if (get_unaligned_le16(buf + 6) != OSF_FRAME_HEADER_LEN)
+		return -EPROTO;
+
+	payload_len = get_unaligned_le32(buf + 10);
+	if (payload_len > len - OSF_FRAME_MIN_LEN)
+		return -EMSGSIZE;
+
+	if (get_unaligned_le32(buf + 34))
+		return -EPROTO;
+
+	total_len = OSF_FRAME_HEADER_LEN + payload_len + OSF_FRAME_CRC_LEN;
+	expected_crc = osf_crc32_ieee(buf, OSF_FRAME_HEADER_LEN + payload_len);
+	actual_crc = get_unaligned_le32(buf + OSF_FRAME_HEADER_LEN + payload_len);
+
+	if (actual_crc != expected_crc)
+		return -EBADMSG;
+
+	frame->protocol_minor = buf[5];
+	frame->message_type = get_unaligned_le16(buf + 8);
+	frame->payload_len = payload_len;
+	frame->sequence = get_unaligned_le64(buf + 14);
+	frame->timestamp_us = get_unaligned_le64(buf + 22);
+	frame->flags = get_unaligned_le32(buf + 30);
+	frame->payload = buf + OSF_FRAME_HEADER_LEN;
+	frame->crc = actual_crc;
+	*frame_len = total_len;
+
+	return 0;
+}

...

drivers/iio/opensensorfusion/osf_protocol.c line 139

Quoted 10 lines
drivers/iio/opensensorfusion/osf_protocol.c new file +10 -0
+int osf_protocol_sensor_sample_value(const struct osf_sensor_sample *sample,
+				     unsigned int index, s32 *value)
+{
+	if (!sample || !sample->samples || !value)
+		return -EINVAL;
+
+	if (index >= sample->channel_count)
+		return -ERANGE;
+
+	*value = (s32)get_unaligned_le32(sample->samples + index * sizeof(s32));

Why casting?

Quoted 2 lines
(quoted diff) +2 -0
+	return 0;
+}

...

Quoted 1 line

+#define OSF_CAPABILITY_FLAGS_MASK 0x00000003U

GENMASK() ?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#11 lore raw

RFC PATCH v3 4/6 iio: osf: add stream parser

In reply to Jinseob Kim

Add the byte stream assembler and resync handling for OSF0 UART frames.

---
 MAINTAINERS                               |   1 +
 drivers/iio/opensensorfusion/osf_stream.c | 207 ++++++++++++++++++++++
 drivers/iio/opensensorfusion/osf_stream.h |  31 ++++
 3 files changed, 239 insertions(+)
 create mode 100644 drivers/iio/opensensorfusion/osf_stream.c
 create mode 100644 drivers/iio/opensensorfusion/osf_stream.h
MAINTAINERS +1 -0
index 9fab72689..91c342d88 100644
@@ -19983,6 +19983,7 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml
 F:	Documentation/iio/open-sensor-fusion-protocol-v0.rst
 F:	drivers/iio/opensensorfusion/osf_protocol.*
+F:	drivers/iio/opensensorfusion/osf_stream.*
 
 OPEN FIRMWARE AND FLATTENED DEVICE TREE
 M:	Rob Herring <[email protected]>
drivers/iio/opensensorfusion/osf_stream.c new file +207 -0

207 lines not on this page · raw message

drivers/iio/opensensorfusion/osf_stream.h new file +31 -0
new file mode 100644
index 000000000..f7f9477fe
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _OSF_STREAM_H
+#define _OSF_STREAM_H
+
+#include <linux/types.h>
+
+#define OSF_STREAM_MAX_FRAME_LEN	4096
+
+struct osf_device;
+
+struct osf_stream_stats {
+	u64 valid_frames;
+	u64 bad_magic_resyncs;
+	u64 bad_crc_frames;
+	u64 partial_frames;
+	u64 dropped_bytes;
+};
+
+struct osf_stream {
+	struct osf_device *osf;
+	u8 buf[OSF_STREAM_MAX_FRAME_LEN];
+	size_t len;
+	struct osf_stream_stats stats;
+};
+
+void osf_stream_init(struct osf_stream *stream, struct osf_device *osf);
+void osf_stream_reset(struct osf_stream *stream);
+int osf_stream_receive_bytes(struct osf_stream *stream, const u8 *buf,
+			     size_t len);
+
+#endif
Signature · 1 line
2.43.0
#12 lore raw

Re: [PATCH RFC v3 4/6] iio: osf: add stream parser

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The `partial_frames` statistic incorrectly increments multiple times for a single valid frame…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The partial_frames statistic incorrectly increments multiple times for a single valid frame during normal stream reception.
- [Medium] Frame is fully decoded into a local structure that is subsequently discarded without being used, causing duplicate CRC and parsing overhead. --

commit 8eb00bef4725c351a5a3267078dfac541b5f3a1b
Author: Jinseob Kim <[email protected]>

iio: osf: add stream parser

Add the byte stream assembler and resync handling for OSF0 UART frames.

Quoted 5 lines
drivers/iio/opensensorfusion/osf_stream.c new file +0 -0
new file mode 100644
index 0000000000000..a2739c987da3f

[ ... ]

Quoted 14 lines
drivers/iio/opensensorfusion/osf_stream.c new file +14 -0
+static int osf_stream_process(struct osf_stream *stream)
+{
+	struct osf_frame frame;
+	size_t decoded_len;
+	size_t discarded;
+	size_t frame_len;
+	u32 payload_len;
+	int first_err = 0;
+	int ret;
+
+	while (stream->len) {
+		discarded = osf_stream_discard_to_magic(stream);
+		if (discarded) {
+			stream->stats.bad_magic_resyncs++;

drivers/iio/opensensorfusion/osf_stream.c line 86

Quoted 10 lines
drivers/iio/opensensorfusion/osf_stream.c new file +10 -0
+			stream->stats.dropped_bytes += discarded;
+			if (!first_err)
+				first_err = -EPROTO;
+		}
+
+		if (!stream->len)
+			break;
+
+		if (stream->len < OSF_FRAME_HEADER_LEN) {
+			stream->stats.partial_frames++;

[Severity: Medium]
Since UART receives data in small chunks, will osf_stream_receive_bytes() repeatedly hit this break condition while accumulating a single valid frame?

It looks like this might inflate partial_frames into a count of receive wait states rather than actual truncated frames.

Quoted 14 lines
drivers/iio/opensensorfusion/osf_stream.c new file +14 -0
+			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) {

drivers/iio/opensensorfusion/osf_stream.c line 110

Quoted 10 lines
drivers/iio/opensensorfusion/osf_stream.c new file +10 -0
+			stream->stats.dropped_bytes++;
+			osf_stream_drop_invalid_head(stream);
+			if (!first_err)
+				first_err = -EMSGSIZE;
+			continue;
+		}
+
+		frame_len = OSF_FRAME_HEADER_LEN + payload_len + OSF_FRAME_CRC_LEN;
+		if (stream->len < frame_len) {
+			stream->stats.partial_frames++;

[Severity: Medium]
Similar to the check above, does this increment partial_frames incorrectly when simply waiting for the rest of the payload and CRC to arrive over UART?

Quoted 14 lines
drivers/iio/opensensorfusion/osf_stream.c new file +14 -0
+			break;
+		}
+
+		ret = osf_protocol_decode_frame(stream->buf, frame_len, &frame,
+						&decoded_len);
+		if (ret) {
+			if (ret == -EBADMSG)
+				stream->stats.bad_crc_frames++;
+			stream->stats.dropped_bytes++;
+			osf_stream_drop_invalid_head(stream);
+			if (!first_err)
+				first_err = ret;
+			continue;
+		}

drivers/iio/opensensorfusion/osf_stream.c line 134

Quoted 10 lines
drivers/iio/opensensorfusion/osf_stream.c new file +10 -0
+
+		if (decoded_len != frame_len) {
+			stream->stats.dropped_bytes++;
+			osf_stream_drop_invalid_head(stream);
+			if (!first_err)
+				first_err = -EMSGSIZE;
+			continue;
+		}
+
+		ret = osf_core_receive_frame(stream->osf, stream->buf, frame_len);

[Severity: Medium]
The frame structure is fully decoded and its CRC calculated by osf_protocol_decode_frame() above, but then the local frame struct is discarded.

Does passing stream->buf directly to osf_core_receive_frame() cause the frame to be decoded and the CRC to be calculated a second time?

Quoted 6 lines
drivers/iio/opensensorfusion/osf_stream.c new file +6 -0
+		if (ret) {
+			osf_stream_discard(stream, frame_len);
+			if (!first_err)
+				first_err = ret;
+			continue;
+		}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#13 lore raw

RFC PATCH v3 5/6 iio: osf: add UART serdev transport

In reply to Jinseob Kim

Register the OSF serdev driver.

Pass received bytes into the OSF0 stream parser.

---
 MAINTAINERS                               |   4 +
 drivers/iio/Kconfig                       |   1 +
 drivers/iio/Makefile                      |   1 +
 drivers/iio/opensensorfusion/Kconfig      |  15 +++
 drivers/iio/opensensorfusion/Makefile     |   5 +
 drivers/iio/opensensorfusion/osf_core.c   | 107 +++++++++++++++++++++
 drivers/iio/opensensorfusion/osf_core.h   |  18 ++++
 drivers/iio/opensensorfusion/osf_serdev.c | 111 ++++++++++++++++++++++
 8 files changed, 262 insertions(+)
 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_serdev.c
MAINTAINERS +4 -0
index 91c342d88..ebbd82bf0 100644
@@ -19982,7 +19982,11 @@ M:	Jinseob Kim <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml
 F:	Documentation/iio/open-sensor-fusion-protocol-v0.rst
+F:	drivers/iio/opensensorfusion/Kconfig
+F:	drivers/iio/opensensorfusion/Makefile
+F:	drivers/iio/opensensorfusion/osf_core.*
 F:	drivers/iio/opensensorfusion/osf_protocol.*
+F:	drivers/iio/opensensorfusion/osf_serdev.c
 F:	drivers/iio/opensensorfusion/osf_stream.*
 
 OPEN FIRMWARE AND FLATTENED DEVICE TREE
drivers/iio/Kconfig +1 -0
index 661127aed..939f6c546 100644
@@ -101,6 +101,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 cb80ef837..d864fe17b 100644
@@ -37,6 +37,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 +15 -0
new file mode 100644
index 000000000..360f25b4f
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config OPEN_SENSOR_FUSION
+	tristate "Open Sensor Fusion UART IIO driver"
+	depends on IIO
+	depends on SERIAL_DEV_BUS
+	select CRC32
+	help
+	  Build the Open Sensor Fusion UART receive path.
+
+	  The driver receives OSF0 frames over a serdev UART.
+	  Frames are decoded and validated before being passed to the
+	  driver core.
+	  This patch only adds the transport path.
+	  IIO device registration is added separately.
drivers/iio/opensensorfusion/Makefile new file +5 -0
new file mode 100644
index 000000000..940c82edd
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-$(CONFIG_OPEN_SENSOR_FUSION) += open-sensor-fusion.o
+
+open-sensor-fusion-y := osf_core.o osf_protocol.o osf_serdev.o osf_stream.o
drivers/iio/opensensorfusion/osf_core.c new file +107 -0

107 lines not on this page · raw message

drivers/iio/opensensorfusion/osf_core.h new file +18 -0
new file mode 100644
index 000000000..3680c8c9b
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _OSF_CORE_H
+#define _OSF_CORE_H
+
+#include <linux/types.h>
+
+struct device;
+
+struct osf_device {
+	struct device *dev;
+	u64 last_sequence;
+};
+
+void osf_core_init(struct osf_device *osf, struct device *dev);
+void osf_core_unregister_iio(struct osf_device *osf);
+int osf_core_receive_frame(struct osf_device *osf, const u8 *buf, size_t len);
+
+#endif
drivers/iio/opensensorfusion/osf_serdev.c new file +111 -0

111 lines not on this page · raw message

Signature · 1 line
2.43.0
#14 lore raw

Re: [PATCH RFC v3 5/6] iio: osf: add UART serdev transport

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Build failure due to access of non-existent `reserved` field in `struct osf_device_status`. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Build failure due to access of non-existent reserved field in struct osf_device_status. --

commit 63140b0b3643f374150f5ac89882047f831e521f
Author: Jinseob Kim <[email protected]>

iio: osf: add UART serdev transport

Register the OSF serdev driver and pass received bytes into the OSF0 stream parser.

Quoted 5 lines
drivers/iio/opensensorfusion/osf_core.c new file +0 -0
new file mode 100644
index 0000000000000..c867b315865d2

[ ... ]

drivers/iio/opensensorfusion/osf_core.c line 40

Quoted 10 lines
drivers/iio/opensensorfusion/osf_core.c new file +10 -0
+static int osf_core_validate_device_status(const struct osf_frame *frame)
+{
+	struct osf_device_status status;
+	int ret;
+
+	ret = osf_protocol_decode_device_status(frame, &status);
+	if (ret)
+		return ret;
+
+	if (status.reserved)

[Severity: Low]
Does struct osf_device_status contain a reserved field?

Looking at osf_protocol_decode_device_status(), the struct appears to only contain uptime_s, status_flags, error_flags, and dropped_frames.

This causes a compilation error (error: 'struct osf_device_status' has no member named 'reserved') when building this patch.

While I noticed this function is replaced and the invalid check is removed later in the series by the patch "iio: osf: register IIO devices from capabilities", each patch in a series should ideally compile independently to preserve git bisect functionality.

Quoted 4 lines
drivers/iio/opensensorfusion/osf_core.c new file +4 -0
+		return -EPROTO;
+
+	return 0;
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
maintainer
#15 lore raw

Re: [PATCH RFC v3 5/6] iio: osf: add UART serdev transport

In reply to Jinseob Kim
Quoted 5 lines · On Fri, 29 May 2026 21:10:04 +0900 Jinseob Kim <[email protected]> wrote:

Register the OSF serdev driver.

Pass received bytes into the OSF0 stream parser.

A few minor things inline.

drivers/iio/opensensorfusion/osf_core.c line 16

Quoted 9 lines
drivers/iio/opensensorfusion/osf_core.c new file +3 -0
new file mode 100644
index 000000000..c867b3158
 
+void osf_core_init(struct osf_device *osf, struct device *dev)
+{
+	memset(osf, 0, sizeof(*osf));

Looks to me like it's is already guaranteed to be zero. If so don't clear it again here.

Quoted 6 lines
drivers/iio/opensensorfusion/osf_core.c new file +5 -0
+	osf->dev = dev;
+}
 
+
+static int osf_core_validate_capability_report(const struct osf_frame *frame)
+{

drivers/iio/opensensorfusion/osf_core.c line 57

Quoted 10 lines
drivers/iio/opensensorfusion/osf_core.c new file +10 -0
+	struct osf_capability_entry entry;
+	struct osf_capability_report report;
+	unsigned int i;
+	int ret;
+
+	ret = osf_protocol_decode_capability_report(frame, &report);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < report.capability_count; i++) {
	for (unsigned int i = 0;

Is now acceptable in the kernel so use it where appropriate

Quoted 32 lines
drivers/iio/opensensorfusion/osf_core.c new file +32 -0
+		ret = osf_protocol_decode_capability_entry(&report, i, &entry);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+int osf_core_receive_frame(struct osf_device *osf, const u8 *buf, size_t len)
+{
+	struct osf_frame frame;
+	size_t frame_len;
+	int ret;
+
+	if (!osf || !buf)
+		return -EINVAL;
+
+	ret = osf_protocol_decode_frame(buf, len, &frame, &frame_len);
+	if (ret)
+		return ret;
+
+	if (frame_len != len)
+		return -EMSGSIZE;
+
+	switch (frame.message_type) {
+	case OSF_MSG_SENSOR_SAMPLE:
+		ret = osf_core_validate_sensor_sample(&frame);
+		break;
+	case OSF_MSG_DEVICE_STATUS:
+		ret = osf_core_validate_device_status(&frame);
+		break;
+	case OSF_MSG_CAPABILITY_REPORT:

drivers/iio/opensensorfusion/osf_core.c line 99

Quoted 10 lines
drivers/iio/opensensorfusion/osf_core.c new file +10 -0
+		ret = osf_core_validate_capability_report(&frame);
+		break;
+	default:
+		if (frame.message_type >= OSF_RESERVED_MSG_FIRST &&
+		    frame.message_type <= OSF_RESERVED_MSG_LAST)
+			ret = 0;
+		else if (frame.message_type >= OSF_VENDOR_PRIVATE_FIRST)
+			ret = 0;
+		else
+			ret = -EOPNOTSUPP;

I'd return early on error cases so...

drivers/iio/opensensorfusion/osf_core.c line 103

Quoted 4 lines
drivers/iio/opensensorfusion/osf_core.c new file +4 -0
+		break;
+	}
+
+	if (!ret)

.. you can drop this check as you know if you reach here we are in good path.

It will mean adding a few
if (ret)

	return ret;

above, but will give a simpler code flow. Generally, I'd split the bad path from the good as soon as possible.

Quoted 5 lines
drivers/iio/opensensorfusion/osf_core.c new file +4 -0
+		osf->last_sequence = frame.sequence;
+
+	return ret;
+}
 

drivers/iio/opensensorfusion/osf_core.c

Quoted 10 lines
drivers/iio/opensensorfusion/osf_core.c new file +9 -0
 
+static struct serdev_device_driver osf_serdev_driver = {
+	.probe = osf_serdev_probe,
+	.remove = osf_serdev_remove,
+	.driver = {
+		.name = "open-sensor-fusion-uart",
+		.of_match_table = osf_serdev_of_match,
+	},
+};
+

Common convention to have no blank line here to keep that macro tightly coupled with the structure.

Quoted 4 lines
drivers/iio/opensensorfusion/osf_core.c new file +4 -0
+module_serdev_device_driver(osf_serdev_driver);
+
+MODULE_DESCRIPTION("Open Sensor Fusion IIO driver");
+MODULE_LICENSE("GPL");
#16 lore raw

RFC PATCH v3 6/6 iio: osf: register IIO devices from capabilities

In reply to Jinseob Kim

Use the first capability report to create supported IIO devices.

Cache latest samples and push enabled buffers directly.

---
 MAINTAINERS                             |   1 +
 drivers/iio/opensensorfusion/Kconfig    |  11 +-
 drivers/iio/opensensorfusion/Makefile   |   3 +-
 drivers/iio/opensensorfusion/osf_core.c | 244 ++++++++++++++++++--
 drivers/iio/opensensorfusion/osf_core.h |  52 +++++
 drivers/iio/opensensorfusion/osf_iio.c  | 285 ++++++++++++++++++++++++
 drivers/iio/opensensorfusion/osf_iio.h  |  22 ++
 7 files changed, 588 insertions(+), 30 deletions(-)
 create mode 100644 drivers/iio/opensensorfusion/osf_iio.c
 create mode 100644 drivers/iio/opensensorfusion/osf_iio.h
MAINTAINERS +1 -0
index ebbd82bf0..56181470d 100644
@@ -19985,6 +19985,7 @@ F:	Documentation/iio/open-sensor-fusion-protocol-v0.rst
 F:	drivers/iio/opensensorfusion/Kconfig
 F:	drivers/iio/opensensorfusion/Makefile
 F:	drivers/iio/opensensorfusion/osf_core.*
+F:	drivers/iio/opensensorfusion/osf_iio.*
 F:	drivers/iio/opensensorfusion/osf_protocol.*
 F:	drivers/iio/opensensorfusion/osf_serdev.c
 F:	drivers/iio/opensensorfusion/osf_stream.*
drivers/iio/opensensorfusion/Kconfig +5 -6
index 360f25b4f..957caed2b 100644
@@ -5,11 +5,10 @@ config OPEN_SENSOR_FUSION
 	depends on IIO
 	depends on SERIAL_DEV_BUS
 	select CRC32
+	select IIO_BUFFER
+	select IIO_KFIFO_BUF
 	help
-	  Build the Open Sensor Fusion UART receive path.
+	  Build the Open Sensor Fusion UART IIO driver.
 
-	  The driver receives OSF0 frames over a serdev UART.
-	  Frames are decoded and validated before being passed to the
-	  driver core.
-	  This patch only adds the transport path.
-	  IIO device registration is added separately.
+	  The driver receives OSF0 frames over a serdev UART and registers
+	  IIO devices for supported capability entries.
drivers/iio/opensensorfusion/Makefile +2 -1
index 940c82edd..b4e03b80c 100644
@@ -2,4 +2,5 @@
 
 obj-$(CONFIG_OPEN_SENSOR_FUSION) += open-sensor-fusion.o
 
-open-sensor-fusion-y := osf_core.o osf_protocol.o osf_serdev.o osf_stream.o
+open-sensor-fusion-y := osf_core.o osf_iio.o osf_protocol.o osf_serdev.o \
+			 osf_stream.o
drivers/iio/opensensorfusion/osf_core.c +221 -23

305 lines not on this page · raw message

drivers/iio/opensensorfusion/osf_core.h +52 -0

69 lines not on this page · raw message

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

285 lines not on this page · raw message

drivers/iio/opensensorfusion/osf_iio.h new file +22 -0
new file mode 100644
index 000000000..d90c58fc4
@@ -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,
+			unsigned int channel_count);
+bool osf_iio_sensor_supported(u16 sensor_type, u16 channel_count);
+const char *osf_iio_sensor_name(u16 sensor_type);
+
+#endif
Signature · 1 line
2.43.0
#17 lore raw

Re: [PATCH RFC v3 6/6] iio: osf: register IIO devices from capabilities

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Uninitialized kernel heap memory is leaked to userspace through IIO buffer padding. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Uninitialized kernel heap memory is leaked to userspace through IIO buffer padding. --

commit 9319c55b6b77ef9ce1f7e526e5ce9463c217bc27
Author: Jinseob Kim <[email protected]>

iio: osf: register IIO devices from capabilities

This commit updates the Open Sensor Fusion (OSF) driver to parse the first capability report and create corresponding IIO devices. It also adds logic to cache the latest samples and push enabled buffers directly to userspace.

Quoted 5 lines
drivers/iio/opensensorfusion/osf_iio.c new file +0 -0
new file mode 100644
index 0000000000000..5e509987876d7

[ ... ]

Quoted 11 lines
drivers/iio/opensensorfusion/osf_iio.c new file +11 -0
+int osf_iio_push_sample(struct iio_dev *indio_dev, const s32 *values,
+			unsigned int channel_count)
+{
+	struct osf_iio_state *state = iio_priv(indio_dev);
+	s32 scan[OSF_MAX_SAMPLE_CHANNELS] = { };
+	s64 timestamp;
+
+	if (channel_count != state->spec->channel_count)
+		return -EPROTO;
+
+	memcpy(scan, values, channel_count * sizeof(*values));

drivers/iio/opensensorfusion/osf_iio.c line 284

Quoted 10 lines
drivers/iio/opensensorfusion/osf_iio.c new file +10 -0
+
+	/* Buffer state can change here; IIO rechecks it during the push path. */
+	if (!iio_buffer_enabled(indio_dev))
+		return 0;
+
+	timestamp = iio_get_time_ns(indio_dev);
+
+	return iio_push_to_buffers_with_ts_unaligned(indio_dev, scan,
+						     channel_count * sizeof(*scan),
+						     timestamp);

[Severity: High]
Does this leak uninitialized kernel heap memory to userspace?

The driver passes channel_count * sizeof(*scan) as the data_sz, which is 12 bytes for a 3-axis sensor or 4 bytes for temperature.

However, the IIO core calculates the buffer's scan_bytes to include padding to 8-byte align the 64-bit timestamp. This results in a scan size of 24 bytes for a 3-axis sensor, or 16 bytes for temperature.

Looking at iio_push_to_buffers_with_ts_unaligned(), the bounce buffer is allocated without zeroing the memory:

drivers/iio/industrialio-buffer.c:iio_push_to_buffers_with_ts_unaligned() {
	...
	if (iio_dev_opaque->bounce_buffer_size !=  indio_dev->scan_bytes) {
		void *bb;

		bb = devm_krealloc(&indio_dev->dev,
				   iio_dev_opaque->bounce_buffer,
				   indio_dev->scan_bytes, GFP_KERNEL);
		...
	}
	memcpy(iio_dev_opaque->bounce_buffer, data, data_sz);
	return iio_push_to_buffers_with_timestamp(indio_dev, ...);
}

It only copies data_sz bytes into the bounce buffer and then appends the 8-byte timestamp, leaving the intermediate padding bytes uninitialized. When this buffer is pushed to the kfifo, the uninitialized kernel memory is exposed to userspace.

Could we pass a correctly padded and zero-initialized structure, or provide the exact size including padding up to the timestamp, to avoid leaking these bytes?

Quoted 1 line

+}

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
maintainer
#18 lore raw

Re: [PATCH RFC v3 6/6] iio: osf: register IIO devices from capabilities

In reply to Jinseob Kim
Quoted 5 lines · On Fri, 29 May 2026 21:10:05 +0900 Jinseob Kim <[email protected]> wrote:

Use the first capability report to create supported IIO devices.

Cache latest samples and push enabled buffers directly.

Sahiko spotted an uninitialized heap data leak in the one of the IIO core functions. I've just sent a patch to fix that.

https://sashiko.dev/#/patchset/20260529121005.1470-1-kimjinseob88%40gmail.com

Thankfully that bounce buffering variant is rarely used so the bug should affect too many systems.

A few other things inline, but mostly looks pretty good to me.

Jonathan

drivers/iio/opensensorfusion/osf_core.c line 8

Quoted 10 lines
drivers/iio/opensensorfusion/osf_core.c +1 -1
index c867b3158..e0a12de01 100644
@@ -5,7 +5,7 @@
 #include <linux/types.h>
 
 #include "osf_core.h"
-#include "osf_protocol.h"
+#include "osf_iio.h"

Did this stop using the osf_protocol.h? Seems unlikely that changed in this patch. So why drop it?

drivers/iio/opensensorfusion/osf_core.c line 16

Quoted 8 lines
drivers/iio/opensensorfusion/osf_core.c +0 -1
 #define OSF_RESERVED_MSG_FIRST		0x7f00
 #define OSF_RESERVED_MSG_LAST		0x7fff
@@ -13,23 +13,175 @@
 
 void osf_core_init(struct osf_device *osf, struct device *dev)
 {
-	memset(osf, 0, sizeof(*osf));

Wrong patch, push that earlier.

Quoted 20 lines
drivers/iio/opensensorfusion/osf_core.c +16 -0
+	mutex_init(&osf->latest_lock);
 	osf->dev = dev;
 }
 
+
+static int osf_core_handle_sensor_sample(struct osf_device *osf,
+					 const struct osf_frame *frame)
+{
+	struct osf_latest_sample *latest;
 	struct osf_sensor_sample sample;
+	struct iio_dev *indio_dev;
+	s32 values[OSF_MAX_SAMPLE_CHANNELS] = { };
+	unsigned int i;
+	int ret;
+
+	ret = osf_protocol_decode_sensor_sample(frame, &sample);
+	if (ret)
+		return ret;
+
+	if (sample.channel_count > OSF_MAX_SAMPLE_CHANNELS)

drivers/iio/opensensorfusion/osf_core.c line 153

Quoted 10 lines
drivers/iio/opensensorfusion/osf_core.c +8 -1
+		return -E2BIG;
 
-	return osf_protocol_decode_sensor_sample(frame, &sample);
+	for (i = 0; i < sample.channel_count; i++) {
+		ret = osf_protocol_sensor_sample_value(&sample, i, &values[i]);
+		if (ret)
+			return ret;
+	}
+
+	mutex_lock(&osf->latest_lock);

scoped_guard() should work well here.

Quoted 29 lines
drivers/iio/opensensorfusion/osf_core.c +27 -0
+	latest = osf_core_find_latest_sample(osf, sample.sensor_type,
+					     sample.sensor_index);
+	if (!latest) {
+		mutex_unlock(&osf->latest_lock);
+		return -E2BIG;
+	}
+
+	memcpy(latest->values, values, sizeof(values));
+	latest->sensor_type = sample.sensor_type;
+	latest->sensor_index = sample.sensor_index;
+	latest->channel_count = sample.channel_count;
+	latest->sample_format = sample.sample_format;
+	latest->scale_nano = sample.scale_nano;
+	latest->sequence = frame->sequence;
+	latest->timestamp_us = frame->timestamp_us;
+	latest->valid = true;
+	osf->last_sequence = frame->sequence;
+	mutex_unlock(&osf->latest_lock);
+
+	indio_dev = osf_core_find_iio_dev(osf, sample.sensor_type,
+					  sample.sensor_index);
+	if (!indio_dev)
+		return 0;
+
+	return osf_iio_push_sample(indio_dev, values, sample.channel_count);
 }
 
+int osf_core_read_latest_sample(struct osf_device *osf, u16 sensor_type,
+				u16 sensor_index, unsigned int channel,

drivers/iio/opensensorfusion/osf_core.c

Quoted 10 lines
drivers/iio/opensensorfusion/osf_core.c +10 -0
+				s32 *value)
+{
+	const struct osf_latest_sample *latest;
+	unsigned int i;
+	int ret = -ENODATA;
+
+	if (!osf || !value)
+		return -EINVAL;
+
+	mutex_lock(&osf->latest_lock);

I'd look at using guard(mutex) here

drivers/iio/opensensorfusion/osf_core.c int osf_core_receive_frame(struct osf_device *osf, const u8 *buf, size_t len) · line 295

Quoted 6 lines
drivers/iio/opensensorfusion/osf_core.c +6 -0
+	for (i = 0; i < osf->latest_sample_count; i++) {
+		latest = &osf->latest_samples[i];
+		if (latest->sensor_type != sensor_type ||
+		    latest->sensor_index != sensor_index)
+			continue;
+

You can easily push the following out of the loop by just doing the test

	if (i == osf->latest_sample_count)
		return -ENODATA;

after the loops.

Quoted 27 lines
drivers/iio/opensensorfusion/osf_core.c +4 -7
+		if (latest->valid && channel < latest->channel_count) {
+			*value = latest->values[channel];
 			ret = 0;
-		else if (frame.message_type >= OSF_VENDOR_PRIVATE_FIRST)
-			ret = 0;
-		else
-			ret = -EOPNOTSUPP;
+		}
 		break;
 	}
-
-	if (!ret)
-		osf->last_sequence = frame.sequence;
+	mutex_unlock(&osf->latest_lock);
 
 	return ret;
 }
drivers/iio/opensensorfusion/osf_core.h +0 -0
index 3680c8c9b..04dd2a367 100644
drivers/iio/opensensorfusion/osf_iio.c new file +0 -0
new file mode 100644
index 000000000..5e5099878

drivers/iio/opensensorfusion/osf_iio.c line 93

Quoted 4 lines
drivers/iio/opensensorfusion/osf_iio.c new file +3 -0
 
+
+static const unsigned long osf_temp_available_scan_masks[] = {
+	BIT(0),

This one is a bit comic. It's not doing anything as can only either or disable the single channel anyway before this!

Quoted 14 lines
drivers/iio/opensensorfusion/osf_iio.c new file +13 -0
+	0
+};
 
+
+void osf_iio_unregister_sensor(struct iio_dev *indio_dev)
+{
+	struct osf_iio_state *state = iio_priv(indio_dev);
+
+	iio_device_unregister(indio_dev);
+	iio_kfifo_free(state->buffer);
+	iio_device_free(indio_dev);
+}
+
+int osf_iio_push_sample(struct iio_dev *indio_dev, const s32 *values,

drivers/iio/opensensorfusion/osf_iio.c line 274

Quoted 10 lines
drivers/iio/opensensorfusion/osf_iio.c new file +10 -0
+			unsigned int channel_count)
+{
+	struct osf_iio_state *state = iio_priv(indio_dev);
+	s32 scan[OSF_MAX_SAMPLE_CHANNELS] = { };
+	s64 timestamp;
+
+	if (channel_count != state->spec->channel_count)
+		return -EPROTO;
+
+	memcpy(scan, values, channel_count * sizeof(*values));

This is odd. You are using the unaligned push but bouncing here as well. If you are going to bounce here then use a structure that includes the aligned_s64 timestamp, or don't bounce here and leave it to the push to buffer below to do that.

drivers/iio/opensensorfusion/osf_iio.c line 276

Quoted 2 lines
drivers/iio/opensensorfusion/osf_iio.c new file +2 -0
+
+	/* Buffer state can change here; IIO rechecks it during the push path. */

Add more detail on what the race is and where IIO is checking it on the push path. Note it's not a problem to race unless the buffer we are pushing to is not ready to receive data. An extra sample during tear down is fine. If there is another race that needs this then I doubt this fixes it as opposed to narrowing the window.

drivers/iio/opensensorfusion/osf_iio.c line 280

Quoted 4 lines
drivers/iio/opensensorfusion/osf_iio.c new file +4 -0
+	if (!iio_buffer_enabled(indio_dev))
+		return 0;
+
+	timestamp = iio_get_time_ns(indio_dev);

I wonder if it's worth grabbing the timestamp earlier. There is quite a bit of code between where we know we have a sample and here and we want it as near to the real data capture time as possible. So perhaps grab in the caller and pass down into here.

drivers/iio/opensensorfusion/osf_iio.c line 282

Quoted 2 lines
drivers/iio/opensensorfusion/osf_iio.c new file +2 -0
+
+	return iio_push_to_buffers_with_ts_unaligned(indio_dev, scan,

As above, if using this should pass in values, not scan.

drivers/iio/opensensorfusion/osf_iio.c line 284

Quoted 2 lines
drivers/iio/opensensorfusion/osf_iio.c new file +2 -0
+						     channel_count * sizeof(*scan),
+						     timestamp);

This is where Sashiko noticed that if we have the timestamp turned on and a non multiple of 8 channel_count * sizeof(*scan) the hole between channels and timestamp is never initialized. That's a core bug so don't do anything here. Please test the patch I just sent out though to make sure I didn't mess it up!

Jonathan

Quoted 1 line

+}

maintainer
#19 lore raw
In reply to Jinseob Kim
Quoted 2 lines · On Fri, 29 May 2026 21:09:59 +0900 Jinseob Kim <[email protected]> wrote:

This RFC series adds an Industrial I/O driver for Open Sensor Fusion OSF0 UART devices.

This misses a clear statement of why it is an RFC. Are their open questions? Is the protocol still evolving? Are you waiting for testing?

Quoted 92 lines

Open Sensor Fusion is an open hardware project for sensor aggregation devices and Linux IIO host support. OSF0 is not a general standard; it is the current wire format used by this project and by the RFC driver in this series. The first concrete hardware target is OSF GREEN, an STM32F405-based sensor aggregation board that streams sensor samples to a Linux host.

Project links:
https://www.opensensorfusion.org/
https://github.com/opensensorfusion
https://github.com/opensensorfusion/opensensorfusion-linux

The driver receives OSF0 frames over a serdev UART, validates the stream, decodes capability and sample frames, and registers IIO devices for the supported sensor types. The current RFC driver covers the device-to-host path used for accelerometer, gyroscope, magnetometer, and temperature samples.

Changes since v2:

* Reworked the binding around the concrete OSF GREEN hardware target.
* Changed the compatible from opensensorfusion,osf-uart to opensensorfusion,osf-green.
* Renamed the binding file to opensensorfusion,osf-green.yaml.
* Updated the example node name to generic sensor.
* Added serial-peripheral-props.yaml and unevaluatedProperties: false.
* Added public project links and clarified that OSF0 is not a general standard.
* Separated the OSF0 wire format from the subset currently supported by this RFC driver.
* Clarified SENSOR_SAMPLE as a 16-byte payload header followed by 4 * channel_count bytes of s32 channel data.
* Clarified device-side timestamp limitations.
* Spelled out Attitude and Heading Reference System (AHRS).
* Added sensor_type, sample_format, channel_count, reserved-field, and payload length overflow validation.
* Changed reserved fields to validate-only handling.
* Fixed IIO_BUFFER / IIO_KFIFO_BUF dependency handling.
* Added channel_count checks before pushing samples to IIO buffers.
* Added locking for cached latest samples.
* Removed explicit linux-iio and devicetree list entries from MAINTAINERS.
* Folded MAINTAINERS updates into the patches that add the corresponding files.
* Addressed Sashiko feedback from v2.

The runtime smoke test used for the previous revision was performed with an OSF GREEN prototype connected to a Raspberry Pi 4 over UART/serdev. This v3 series was also checked with dt_binding_check, checkpatch, and a W=1 target build in the local full-tree environment.

Jinseob Kim (6):
dt-bindings: iio: add OSF GREEN sensor aggregation device
Documentation: iio: add Open Sensor Fusion protocol v0 reference
iio: osf: add protocol v0 decoding
iio: osf: add stream parser
iio: osf: add UART serdev transport
iio: osf: register IIO devices from capabilities

 .../iio/imu/opensensorfusion,osf-green.yaml   |  43 +++
 .../devicetree/bindings/vendor-prefixes.yaml  |   2 +
 .../iio/open-sensor-fusion-protocol-v0.rst    | 308 ++++++++++++++++++
 MAINTAINERS                                   |  13 +
 drivers/iio/Kconfig                           |   1 +
 drivers/iio/Makefile                          |   1 +
 drivers/iio/opensensorfusion/Kconfig          |  14 +
 drivers/iio/opensensorfusion/Makefile         |   6 +
 drivers/iio/opensensorfusion/osf_core.c       | 305 +++++++++++++++++
 drivers/iio/opensensorfusion/osf_core.h       |  70 ++++
 drivers/iio/opensensorfusion/osf_iio.c        | 285 ++++++++++++++++
 drivers/iio/opensensorfusion/osf_iio.h        |  22 ++
 drivers/iio/opensensorfusion/osf_protocol.c   | 247 ++++++++++++++
 drivers/iio/opensensorfusion/osf_protocol.h   |  95 ++++++
 drivers/iio/opensensorfusion/osf_serdev.c     | 111 +++++++
 drivers/iio/opensensorfusion/osf_stream.c     | 207 ++++++++++++
 drivers/iio/opensensorfusion/osf_stream.h     |  31 ++
 17 files changed, 1761 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/opensensorfusion,osf-green.yaml
 create mode 100644 Documentation/iio/open-sensor-fusion-protocol-v0.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_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