Skip to contentSkip to conversation

iio: proximity: Add Benewake TF-Luna LiDAR driver

PATCH In review Vidhu Sarwal 5 participants 13 messages Oct 30 – Nov 8

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover iio: proximity: Add Benewake TF-Luna LiDAR driver

This series adds support for the Benewake TF-Luna, a single point ToF
LiDAR distance sensor with a range of 0.2 m to 8 m. The
sensor uses either UART or I2C, selected by a strap pin at power-up. This series covers the I2C interface only.

Patch 1 adds the vendor prefix, patch 2 adds the binding and patch 3 adds the driver, which reports distance using an IIO_DISTANCE channel.

The driver keeps the sensor in trigger mode and starts a measurement per read. The manual warns that reads in continuous mode can race with the sensor updating its result registers unless they are synchronised to the data ready output, which the driver does not use yet.

Two issues I faced with the hardware that the manual does not mention:
- The sensor silently drops a register write that arrives right after another one, so probe reads the mode back after setting it.
- The boot time is not documented. I was able to measure 350ms after a reboot before the registers read back correctly, so probe waits 500 ms after enabling the supply, keeping some buffer.

Later on I plan to add buffered caputure using data ready interrupt and runtime PM in a follow up series.

This was tested on hardware using Raspberry Pi 4 and with firmware v3.6.0 built out of tree on the 6.18 RPi kernel both via new_device as well as a DT Overlay.

---
Changes in v2:
- dt-bindings: describe the UART interface as well per Krzysztof (dropped Reviewed-by as binding has changed)
- Use a local regmap variable in probe and tf_luna_measure() per Joshua and Andy
- Use msleep() instead of fsleep per Joshua and Andy
- Use FourCC for signature and print it with %p4ch per Andy
- Comment explaining why there is no regmap cache per Andy
- Use a Datasheet: tag, drop unused includes per Andy and Joshua
- Keep the channel array per Jonathan, as buffered support is planned
- Link to v1: https://patch.msgid.link/[email protected]

---
Vidhu Sarwal (3):
dt-bindings: vendor-prefixes: Add Benewake
dt-bindings: iio: proximity: Add Benewake TF-Luna
iio: proximity: Add Benewake TF-Luna LiDAR driver

 .../bindings/iio/proximity/benewake,tf-luna.yaml   |  66 ++++++
 .../devicetree/bindings/vendor-prefixes.yaml       |   2 +
 MAINTAINERS                                        |   7 +
 drivers/iio/proximity/Kconfig                      |  11 +
 drivers/iio/proximity/Makefile                     |   1 +
 drivers/iio/proximity/tf-luna.c                    | 260 +++++++++++++++++++++
 6 files changed, 347 insertions(+)

---
base-commit: 43ffda3c7f8456bbe641ae8249a077a361b97880
change-id: 20261019-tf-luna-e2685e0570d5

Best regards,

Signature · 1 line
Vidhu Sarwal <[email protected]>
#1 lore raw

PATCH v2 1/3 dt-bindings: vendor-prefixes: Add Benewake

Add vendor prefix for Benewake (Beijing) Co., Ltd., a manufacturer of LiDAR distance sensors.
https://en.benewake.com/

---
 Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
index 0ec4e481c64b..7bc9c071913b 100644
@@ -245,6 +245,8 @@ patternProperties:
     description: BeagleBoard.org Foundation
   "^belling,.*":
     description: Shanghai Belling Co., Ltd.
+  "^benewake,.*":
+    description: Benewake (Beijing) Co., Ltd.
   "^bestar,.*":
     description: Shenzhen Bestar Electronic Technology Co., Ltd.
   "^bhf,.*":
Signature · 1 line
2.53.0
#2 lore raw

PATCH v2 2/3 dt-bindings: iio: proximity: Add Benewake TF-Luna

In reply to Vidhu Sarwal

Add binding for the Benewake TF-Luna, a single point ToF LiDAR distance sensor with a range of 0.2 m to 8 m.

The sensor talks either UART or I2C, selected by the level of pin 5 at power-up. This binding covers both interfaces. Pin 6 is a data ready output and is described as an interrupt.

---
 .../bindings/iio/proximity/benewake,tf-luna.yaml   | 66 ++++++++++++++++++++++
 MAINTAINERS                                        |  6 ++
 2 files changed, 72 insertions(+)
Documentation/devicetree/bindings/iio/proximity/benewake,tf-luna.yaml new file +66 -0
new file mode 100644
index 000000000000..607a71a6ab39
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/proximity/benewake,tf-luna.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Benewake TF-Luna LiDAR distance sensor
+
+maintainers:
+  - Vidhu Sarwal <[email protected]>
+
+description: |
+  Single-point time-of-flight LiDAR ranging sensor with a range of 0.2 m to
+  8 m. The sensor talks either UART or I2C, selected at power-up by the level
+  of pin 5: tied to ground for I2C, unconnected or tied to 3.3 V for UART.
+
+  Datasheet: https://en.benewake.com/uploadfiles/2025/04/20250430174501874.pdf
+
+properties:
+  compatible:
+    const: benewake,tf-luna
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    description:
+      Output on pin 6. In I2C mode it is a data ready signal that goes high
+      when a new measurement is available and goes low again once any
+      register has been read. In UART mode it can be configured as an on/off
+      output.
+    maxItems: 1
+
+  vcc-supply:
+    description: Power supply, 3.7 V to 5.2 V.
+
+required:
+  - compatible
+  - vcc-supply
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        proximity@10 {
+            compatible = "benewake,tf-luna";
+            reg = <0x10>;
+            vcc-supply = <&reg_5v>;
+            interrupt-parent = <&gpio>;
+            interrupts = <17 IRQ_TYPE_EDGE_RISING>;
+        };
+    };
+  - |
+    serial {
+        proximity {
+            compatible = "benewake,tf-luna";
+            vcc-supply = <&reg_5v>;
+        };
+    };
+...
MAINTAINERS +6 -0
index 52024397dc78..24fa7cdf6a57 100644
@@ -4662,6 +4662,12 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/luisbg/linux-befs.git
 F:	Documentation/filesystems/befs.rst
 F:	fs/befs/
 
+BENEWAKE TF-LUNA LIDAR IIO DRIVER
+M:	Vidhu Sarwal <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/proximity/benewake,tf-luna.yaml
+
 BFQ I/O SCHEDULER
 M:	Yu Kuai <[email protected]>
 L:	[email protected]
Signature · 1 line
2.53.0
#3 lore raw

Re: [PATCH v2 2/3] dt-bindings: iio: proximity: Add Benewake TF-Luna

Quoted 9 lines · Vidhu Sarwal

Add binding for the Benewake TF-Luna, a single point ToF LiDAR distance sensor with a range of 0.2 m to 8 m.

The sensor talks either UART or I2C, selected by the level of pin 5 at power-up. This binding covers both interfaces. Pin 6 is a data ready output and is described as an interrupt.

---

What is the base of it? I tried two linux-next and 7 different mainline tags (v6.18 and newer - up to current mainline).

All fail.

b4 diff '[email protected]' Using cached copy of the lookup
---
Analyzing 19 messages in the thread
Preparing fake-am for v1: dt-bindings: vendor-prefixes: Add Benewake
ERROR: Could not fake-am version v1
---
Could not create fake-am range for lower series v1

Best regards,
Krzysztof

Reviewed-by on v2 2/3
#4 lore raw

Re: [PATCH v2 2/3] dt-bindings: iio: proximity: Add Benewake TF-Luna

In reply to Vidhu Sarwal
Quoted 9 lines · On 30/10/2026 19:53, Vidhu Sarwal via B4 Relay wrote:

From: Vidhu Sarwal <[email protected]>

Add binding for the Benewake TF-Luna, a single point ToF LiDAR distance sensor with a range of 0.2 m to 8 m.

The sensor talks either UART or I2C, selected by the level of pin 5 at power-up. This binding covers both interfaces. Pin 6 is a data ready output and is described as an interrupt.

Quoted 5 lines
---
 .../bindings/iio/proximity/benewake,tf-luna.yaml   | 66 ++++++++++++++++++++++
 MAINTAINERS                                        |  6 ++
 2 files changed, 72 insertions(+)

Best regards,
Krzysztof

#5 lore raw

PATCH v2 3/3 iio: proximity: Add Benewake TF-Luna LiDAR driver

In reply to Vidhu Sarwal

Add a driver for the Benewake TF-Luna, a single-point time-of-flight LiDAR distance sensor with a range of 0.2 m to 8 m, connected over I2C.

The sensor is run in trigger mode. Each read starts one measurement and waits for the timestamp register to change before reading the result. In continuous mode a read can catch the sensor in the middle of updating its result registers unless it is synchronised to the data ready output, which this driver does not use yet.

When the signal strength is too low the sensor reports a dummy distance of 0, so such readings, as well as overexposed ones, return -ENODATA instead of a distance.

Datasheet: https://en.benewake.com/uploadfiles/2025/04/20250430174501874.pdf

---
 MAINTAINERS                     |   1 +
 drivers/iio/proximity/Kconfig   |  11 ++
 drivers/iio/proximity/Makefile  |   1 +
 drivers/iio/proximity/tf-luna.c | 260 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 273 insertions(+)
MAINTAINERS +1 -0
index 24fa7cdf6a57..20e43a003bed 100644
@@ -4667,6 +4667,7 @@ M:	Vidhu Sarwal <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/iio/proximity/benewake,tf-luna.yaml
+F:	drivers/iio/proximity/tf-luna.c
 
 BFQ I/O SCHEDULER
 M:	Yu Kuai <[email protected]>
drivers/iio/proximity/Kconfig +11 -0
index f3cec799df67..d16458ea4b0f 100644
@@ -222,6 +222,17 @@ config SRF08
 	  To compile this driver as a module, choose M here: the
 	  module will be called srf08.
 
+config TF_LUNA
+	tristate "Benewake TF-Luna LiDAR distance sensor"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  Say Y here to build a driver for the Benewake TF-Luna LiDAR
+	  distance sensor connected over I2C.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called tf-luna.
+
 config VCNL3020
 	tristate "VCNL3020 proximity sensor"
 	select REGMAP_I2C
drivers/iio/proximity/Makefile +1 -0
index 8a65e42fbea0..43741115a921 100644
@@ -21,6 +21,7 @@ obj-$(CONFIG_SX9324)		+= sx9324.o
 obj-$(CONFIG_SX9360)		+= sx9360.o
 obj-$(CONFIG_SX_COMMON) 	+= sx_common.o
 obj-$(CONFIG_SX9500)		+= sx9500.o
+obj-$(CONFIG_TF_LUNA)		+= tf-luna.o
 obj-$(CONFIG_VCNL3020)		+= vcnl3020.o
 obj-$(CONFIG_VCNL36829)		+= vcnl36829.o
 obj-$(CONFIG_VL53L0X_I2C)	+= vl53l0x-i2c.o
drivers/iio/proximity/tf-luna.c new file +260 -0

260 lines not on this page · raw message

Signature · 1 line
2.53.0
Reviewed-by on v2 3/3
#6 lore raw
Quoted 10 lines · On Sat, Oct 31, 2026 at 12:23:30AM +0530, Vidhu Sarwal via B4 Relay wrote:

Add a driver for the Benewake TF-Luna, a single-point time-of-flight LiDAR distance sensor with a range of 0.2 m to 8 m, connected over I2C.

The sensor is run in trigger mode. Each read starts one measurement and waits for the timestamp register to change before reading the result. In continuous mode a read can catch the sensor in the middle of updating its result registers unless it is synchronised to the data ready output, which this driver does not use yet.

Quoted 3 lines

When the signal strength is too low the sensor reports a dummy distance of 0, so such readings, as well as overexposed ones, return -ENODATA instead of a distance.

LGTM now,

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#7 lore raw
In reply to Vidhu Sarwal
Quoted 11 lines · On Sat, 31 Oct 2026 00:23:30 +0530 Vidhu Sarwal via B4 Relay…

From: Vidhu Sarwal <[email protected]>

Add a driver for the Benewake TF-Luna, a single-point time-of-flight LiDAR distance sensor with a range of 0.2 m to 8 m, connected over I2C.

The sensor is run in trigger mode. Each read starts one measurement and waits for the timestamp register to change before reading the result. In continuous mode a read can catch the sensor in the middle of updating its result registers unless it is synchronised to the data ready output, which this driver does not use yet.

Quoted 6 lines

When the signal strength is too low the sensor reports a dummy distance of 0, so such readings, as well as overexposed ones, return -ENODATA instead of a distance.

Datasheet: https://en.benewake.com/uploadfiles/2025/04/20250430174501874.pdf

Nice driver. I'll pick it up once the DT folk have had a look at the additional serial binding if nothing else comes up.

Thanks,

Jonathan

#8 lore raw
In reply to Vidhu Sarwal
Quoted 23 lines · Vidhu Sarwal

This series adds support for the Benewake TF-Luna, a single point ToF
LiDAR distance sensor with a range of 0.2 m to 8 m. The
sensor uses either UART or I2C, selected by a strap pin at power-up. This series covers the I2C interface only.

Patch 1 adds the vendor prefix, patch 2 adds the binding and patch 3 adds the driver, which reports distance using an IIO_DISTANCE channel.

The driver keeps the sensor in trigger mode and starts a measurement per read. The manual warns that reads in continuous mode can race with the sensor updating its result registers unless they are synchronised to the data ready output, which the driver does not use yet.

Two issues I faced with the hardware that the manual does not mention:
- The sensor silently drops a register write that arrives right after another one, so probe reads the mode back after setting it.
- The boot time is not documented. I was able to measure 350ms after a reboot before the registers read back correctly, so probe waits 500 ms after enabling the supply, keeping some buffer.

Later on I plan to add buffered caputure using data ready interrupt and runtime PM in a follow up series.

Quoted 7 lines

This was tested on hardware using Raspberry Pi 4 and with firmware v3.6.0 built out of tree on the 6.18 RPi kernel both via new_device as well as a DT Overlay.

---
Changes in v2:
- dt-bindings: describe the UART interface as well per Krzysztof

What changed exactly? b4 diff fails, the patchset cannot be applied on any known upstream revision I tried.

Best regards,
Krzysztof

#9 lore raw
Quoted 2 lines · Krzysztof Kozlowski

What changed exactly? b4 diff fails, the patchset cannot be applied on any known upstream revision I tried.

I am really sorry for that, I didn't realise it was based on Jonathan's iio.git (testing branch) instead of linux-next. Patch 3 conflicts in the Makefile on next.

In the binding, reg is now optional, there's a serial example, and the pin 5/6 descriptions cover UART too.

Happy to rebase on next and resend if that's easier.

Thanks,
Vidhu

#10 lore raw
Quoted 6 lines · Vidhu Sarwal
Quoted 2 lines · Krzysztof Kozlowski

What changed exactly? b4 diff fails, the patchset cannot be applied on any known upstream revision I tried.

I am really sorry for that, I didn't realise it was based on Jonathan's iio.git (testing branch) instead of linux-next. Patch 3 conflicts in the

That is fine in general, I'll wait for next linux-next.

Best regards,
Krzysztof

maintainer
#11 lore raw
Quoted 9 lines · On Mon, 2 Nov 2026 13:23:56 +0100 Krzysztof Kozlowski…
Quoted 6 lines · Vidhu Sarwal
Quoted 2 lines · Krzysztof Kozlowski

What changed exactly? b4 diff fails, the patchset cannot be applied on any known upstream revision I tried.

I am really sorry for that, I didn't realise it was based on Jonathan's iio.git (testing branch) instead of linux-next. Patch 3 conflicts in the

That is fine in general, I'll wait for next linux-next.

Might be a little longer. I've pushed out now. Was just waiting for anything nasty from the bots on after rebasing on rc1 before pushing out.

J

Quoted 3 lines

Best regards,
Krzysztof

maintainer
#12 lore raw
Quoted 8 lines · On Mon, 2 Nov 2026 22:20:56 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 5 lines · On Mon, 2 Nov 2026 13:23:56 +0100 Krzysztof Kozlowski…
Quoted 4 lines · Vidhu Sarwal
Quoted 2 lines · Krzysztof Kozlowski

What changed exactly? b4 diff fails, the patchset cannot be applied on any known upstream revision I tried.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I am really sorry for that, I didn't realise it was based on Jonathan's iio.git (testing branch) instead of linux-next. Patch 3 conflicts in the

That is fine in general, I'll wait for next linux-next.

Might be a little longer. I've pushed out now. Was just waiting for anything nasty from the bots on after rebasing on rc1 before pushing out.

Applied to the testing branch of iio.git.

thanks

Jonathan

Quoted 7 lines

J

Quoted 3 lines

Best regards,
Krzysztof