iio: proximity: Add Benewake TF-Luna LiDAR driver
Subsystems (2)
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.
---
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 | 58 +++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + MAINTAINERS | 7 + drivers/iio/proximity/Kconfig | 11 + drivers/iio/proximity/Makefile | 1 + drivers/iio/proximity/tf-luna.c | 254 +++++++++++++++++++++ 6 files changed, 333 insertions(+)
---
base-commit: 43ffda3c7f8456bbe641ae8249a077a361b97880
change-id: 20261019-tf-luna-e2685e0570d5
Best regards,
Signature · 1 line
Vidhu Sarwal <[email protected]>
PATCH 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
@@ -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
PATCH 2/3 dt-bindings: iio: proximity: Add Benewake TF-Luna
In reply to Vidhu SarwalAdd 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 the I2C interface. Pin 6 is a data ready output and is described as an interrupt.
--- .../bindings/iio/proximity/benewake,tf-luna.yaml | 58 ++++++++++++++++++++++ MAINTAINERS | 6 +++ 2 files changed, 64 insertions(+)
Documentation/devicetree/bindings/iio/proximity/benewake,tf-luna.yaml new file +58 -0
@@ -0,0 +1,58 @@ +# 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. Pin 5 must be tied to ground for the I2C interface described here. + + Datasheet: https://en.benewake.com/uploadfiles/2025/04/20250430174501874.pdf + +properties: + compatible: + const: benewake,tf-luna + + reg: + maxItems: 1 + + interrupts: + description: + Data ready output on pin 6. Goes high when a new measurement is + available and goes low again once any register has been read. + maxItems: 1 + + vcc-supply: + description: Power supply, 3.7 V to 5.2 V. + +required: + - compatible + - reg + - 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 = <®_5v>; + interrupt-parent = <&gpio>; + interrupts = <17 IRQ_TYPE_EDGE_RISING>; + }; + }; +...
MAINTAINERS +6 -0
@@ -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
PATCH 3/3 iio: proximity: Add Benewake TF-Luna LiDAR driver
In reply to Vidhu SarwalAdd 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.
The datasheet is available at:
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 | 254 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 267 insertions(+)
MAINTAINERS +1 -0
@@ -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
@@ -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
@@ -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 +254 -0
254 lines not on this page · raw message
Signature · 1 line
2.53.0
Quoted 15 lines · On Tue, 20 Oct 2026 00:03:43 +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.
When the signal strength is too low the sensor reports a dummy distance of 0, so such readings, as well as overexposed ones, return
-ENODATAinstead of a distance.
Quoted 5 lines
The datasheet is available at:
https://en.benewake.com/uploadfiles/2025/04/20250430174501874.pdfSigned-off-by Vidhu Sarwal <[email protected]>---
Hi Vidhu,
very good for a v1, even Sashiko reported no issues. Minor style issues from me.
Josh
drivers/iio/proximity/tf-luna.c line 21
Quoted 9 lines
drivers/iio/proximity/tf-luna.c new file +9
-0+#include <linux/array_size.h> +#include <linux/bits.h> +#include <linux/cleanup.h> +#include <linux/delay.h> +#include <linux/dev_printk.h> +#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/iopoll.h> +#include <linux/mod_devicetable.h>
Remove this, this is included by i2c.h
Quoted 19 lines
drivers/iio/proximity/tf-luna.c new file +19
-0+#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/regmap.h> +#include <linux/regulator/consumer.h> +#include <linux/string.h> +#include <linux/time.h> +#include <linux/types.h> + +#include <asm/byteorder.h> + +#include <linux/iio/iio.h> + +#define TF_LUNA_REG_DIST 0x00 +#define TF_LUNA_REG_TICK 0x06 +#define TF_LUNA_REG_VERSION 0x0A +#define TF_LUNA_REG_MODE 0x23 +#define TF_LUNA_REG_TRIG_ONE_SHOT 0x24 +#define TF_LUNA_REG_SIGNATURE 0x3C +
drivers/iio/proximity/tf-luna.c line 50
Quoted 10 lines
drivers/iio/proximity/tf-luna.c new file +10
-0+#define TF_LUNA_MODE_TRIGGER 0x01 +#define TF_LUNA_TRIG_ONE_SHOT 0x01 + +/* Below this the sensor reports a dummy distance of 0 */ +#define TF_LUNA_AMP_MIN 100 +#define TF_LUNA_AMP_OVEREXPOSED 0xFFFF + +/* A measurement takes 10-20 ms in trigger mode */ +#define TF_LUNA_POLL_US (2 * USEC_PER_MSEC) +#define TF_LUNA_TIMEOUT_US (100 * USEC_PER_MSEC)
uS is better instead of US.
Quoted 30 lines
drivers/iio/proximity/tf-luna.c new file +30
-0+ +struct tf_luna_data { +struct regmap *regmap; +/* Serialises the trigger, poll and read of a single measurement */ +struct mutex lock; +}; + +static const struct regmap_config tf_luna_regmap_config = { + .reg_bits =8 , + .val_bits =8 , + .max_register =TF_LUNA_REG_SIGNATURE +3 , +}; + +static int tf_luna_read_tick (struct tf_luna_data *data,u16 *tick) +{ +__le16 val; +int ret; + + ret =regmap_bulk_read (data->regmap,TF_LUNA_REG_TICK , &val,sizeof (val)); +if (ret) +return ret; + + *tick =le16_to_cpu (val); +return 0 ; +} + +static int tf_luna_measure (struct tf_luna_data *data,int *dist) +{ +__le16 buf[2 ];/* distance in cm, signal strength */ +u16 old_tick, tick, amp;
drivers/iio/proximity/tf-luna.c line 90
Quoted 10 lines
drivers/iio/proximity/tf-luna.c new file +10
-0+int ret, err; + +guard (mutex)(&data->lock); + + ret =tf_luna_read_tick (data, &old_tick); +if (ret) +return ret; + + ret =regmap_write (data->regmap,TF_LUNA_REG_TRIG_ONE_SHOT , +TF_LUNA_TRIG_ONE_SHOT );
Why not have a local variable for regmap? It would allow the previous call to fit on one line.
...
Quoted 21 lines
drivers/iio/proximity/tf-luna.c new file +21
-0+static int tf_luna_probe (struct i2c_client *client) +{ +struct device *dev = &client->dev; +struct tf_luna_data *data; +struct iio_dev *indio_dev; +unsigned int mode; +u8 signature[4 ]; +u8 version[3 ]; +int ret; + + indio_dev =devm_iio_device_alloc (dev,sizeof (*data)); +if (!indio_dev) +return -ENOMEM ; + + data =iio_priv (indio_dev); + + ret =devm_mutex_init (dev, &data->lock); +if (ret) +return ret; + + data->regmap =devm_regmap_init_i2c (client, &tf_luna_regmap_config);
drivers/iio/proximity/tf-luna.c line 180
Quoted 10 lines
drivers/iio/proximity/tf-luna.c new file +10
-0+if (IS_ERR (data->regmap)) +return dev_err_probe (dev,PTR_ERR (data->regmap), +"Failed to initialize regmap\n" ); + + ret =devm_regulator_get_enable (dev,"vcc" ); +if (ret) +return dev_err_probe (dev, ret,"Failed to enable vcc regulator\n" ); + +/* Boot time is not documented, about 350 ms was measured */ +fsleep (500 *USEC_PER_MSEC );
msleep() is fine here, saves you the x * USEC_PER_MSEC format.
Signature · 2 lines
Kind regards, Joshua Crofts
Quoted 2 lines · Joshua Crofts
On Tue, 20 Oct 2026 00:03:43 +0530
Vidhu Sarwal via B4 Relay <[email protected]> wrote:
...
Quoted 6 lines
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
-ENODATAinstead of a distance.The datasheet is available at:
https://en.benewake.com/uploadfiles/2025/04/20250430174501874.pdf
Make it Datasheet tag.
Quoted 1 line
Quoted 1 line
Signed-off-by Vidhu Sarwal <[email protected]>
...
Quoted 5 lines
drivers/iio/proximity/tf-luna.c line 50
Quoted 3 lines
drivers/iio/proximity/tf-luna.c new file +3
-0+/* A measurement takes 10-20 ms in trigger mode */ +#define TF_LUNA_POLL_US (2 * USEC_PER_MSEC) +#define TF_LUNA_TIMEOUT_US (100 * USEC_PER_MSEC)uS is better instead of US.
Currently _US is established suffix, unfortunately. But I have no strong opinion here, I'm full to support _uS, but OTOH the _US will be consistent.
...
Quoted 4 lines
drivers/iio/proximity/tf-luna.c line 61
Quoted 4 lines
drivers/iio/proximity/tf-luna.c new file +4
-0+static const struct regmap_config tf_luna_regmap_config = { + .reg_bits =8 , + .val_bits =8 , + .max_register =TF_LUNA_REG_SIGNATURE +3 ,
No cache?
Quoted 1 line
Quoted 1 line
+};
...
Quoted 9 lines
Quoted 9 lines
drivers/iio/proximity/tf-luna.c new file +9
-0+static int tf_luna_measure (struct tf_luna_data *data,int *dist) +{ +__le16 buf[2 ];/* distance in cm, signal strength */ +u16 old_tick, tick, amp; +int ret, err; + +guard (mutex)(&data->lock); + + ret =tf_luna_read_tick (data, &old_tick);
Quoted 8 lines
drivers/iio/proximity/tf-luna.c line 90
Quoted 5 lines
drivers/iio/proximity/tf-luna.c new file +5
-0+if (ret) +return ret; + + ret =regmap_write (data->regmap,TF_LUNA_REG_TRIG_ONE_SHOT , +TF_LUNA_TRIG_ONE_SHOT );Why not have a local variable for regmap? It would allow the previous call to fit on one line.
Almost, but I agree.
ret = regmap_write(map, TF_LUNA_REG_TRIG_ONE_SHOT, TF_LUNA_TRIG_ONE_SHOT);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 10 lines · On Tue, Oct 20, 2026 at 12:03:43AM +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
-ENODATAinstead of a distance.
On top of my previous reply.
...
drivers/iio/proximity/tf-luna.c line 158
Quoted 9 lines
drivers/iio/proximity/tf-luna.c new file +9
-0+static int tf_luna_probe (struct i2c_client *client) +{ +struct device *dev = &client->dev; +struct tf_luna_data *data; +struct iio_dev *indio_dev; +unsigned int mode; +u8 signature[4 ]; +u8 version[3 ]; +int ret;
It also makes sense to have local variable here
struct regmap *map;
Quoted 4 lines
drivers/iio/proximity/tf-luna.c new file +4
-0+ indio_dev =devm_iio_device_alloc (dev,sizeof (*data)); +if (!indio_dev) +return -ENOMEM ; +
drivers/iio/proximity/tf-luna.c line 173
Quoted 10 lines
drivers/iio/proximity/tf-luna.c new file +9
-0+ data =iio_priv (indio_dev); + + ret =devm_mutex_init (dev, &data->lock); +if (ret) +return ret; + data->regmap =devm_regmap_init_i2c (client, &tf_luna_regmap_config); +if (IS_ERR (data->regmap)) +return dev_err_probe (dev,PTR_ERR (data->regmap), +"Failed to initialize regmap\n" );
map = devm_regmap_init_i2c(client, &tf_luna_regmap_config); if (IS_ERR(map)) return dev_err_probe(dev, PTR_ERR(map), "Failed to initialize regmap\n"); data->regmap = map;
drivers/iio/proximity/tf-luna.c line 183
Quoted 9 lines
drivers/iio/proximity/tf-luna.c new file +9
-0+ ret =devm_regulator_get_enable (dev,"vcc" ); +if (ret) +return dev_err_probe (dev, ret,"Failed to enable vcc regulator\n" ); + +/* Boot time is not documented, about 350 ms was measured */ +fsleep (500 *USEC_PER_MSEC ); + + ret =regmap_bulk_read (data->regmap,TF_LUNA_REG_SIGNATURE , signature, +sizeof (signature));
Make it split logically and taking into account the above either
ret = regmap_bulk_read(map, TF_LUNA_REG_SIGNATURE, signature, sizeof(signature));
OR
ret = regmap_bulk_read(map, TF_LUNA_REG_SIGNATURE, signature, sizeof(signature));
(perhaps you can shorten the 'signature' to 'sign' to fit).
drivers/iio/proximity/tf-luna.c line 187
Quoted 4 lines
drivers/iio/proximity/tf-luna.c new file +4
-0+if (ret) +return dev_err_probe (dev, ret,"Failed to read signature\n" ); + +if (memcmp (signature,"LUNA" ,sizeof (signature)))
Hmm... No. Please, make signature to be __?e32 and use a definition for this FourCC [1] in the hexadecimal with the comment, and compare as regular integers...
drivers/iio/proximity/tf-luna.c line 189
Quoted 2 lines
drivers/iio/proximity/tf-luna.c new file +2
-0+dev_info (dev,"Unknown signature %*ph, continuing\n" , + (int )sizeof (signature), signature);
...and here use %*p4c?.
#define TF_LUNA_SIGN 0x... /* "LUNA" in ASCII */
__?e32 signature; u32 fourcc; ... ret = regmap_bulk_read(map, TF_LUNA_REG_SIGNATURE, signature, sizeof(signature)); ... fourcc = ?e32_to_cpu(signature); if (fourcc != TF_LUNA_SIGN) dev_info(dev, "Unknown signature %p4c?, continuing\n", &fourcc);
where '?' represents either 'b' or 'l' depending on what you have and what you want to see printed.
drivers/iio/proximity/tf-luna.c line 192
Quoted 2 lines
drivers/iio/proximity/tf-luna.c new file +2
-0+ ret =regmap_bulk_read (data->regmap,TF_LUNA_REG_VERSION , version, +sizeof (version));
ret = regmap_bulk_read(map, TF_LUNA_REG_VERSION, version, sizeof(version));
(or 'version' --> 'ver', for example).
drivers/iio/proximity/tf-luna.c line 197
Quoted 5 lines
drivers/iio/proximity/tf-luna.c new file +4
-0+if (ret) +return ret; +dev_dbg (dev,"Firmware version %u.%u.%u\n" , + version[2 ], version[1 ], version[0 ]);
Yeah, I need to post my series to also make this to be a pointer extension.
Quoted 4 lines
drivers/iio/proximity/tf-luna.c new file +4
-0+/* +* In continuous mode a read can catch the sensor updating its result +* registers unless it is synchronised to the data ready output. Use +* trigger mode and start each measurement on demand instead.
drivers/iio/proximity/tf-luna.c line 212
Quoted 10 lines
drivers/iio/proximity/tf-luna.c new file +10
-0+*/ + ret =regmap_write (data->regmap,TF_LUNA_REG_MODE ,TF_LUNA_MODE_TRIGGER ); +if (ret) +return ret; + +/* +* The sensor silently drops writes it is not ready for, so check that +* the mode was set. A write takes up to 100 ms to read back. +*/ +fsleep (100 *USEC_PER_MSEC );
msleep() as it's known to be big enough.
Quoted 5 lines
drivers/iio/proximity/tf-luna.c new file +5
-0+ ret =regmap_read (data->regmap,TF_LUNA_REG_MODE , &mode); +if (ret) +return ret; + +if (mode !=TF_LUNA_MODE_TRIGGER )
drivers/iio/proximity/tf-luna.c line 228
Quoted 10 lines
drivers/iio/proximity/tf-luna.c new file +10
-0+return dev_err_probe (dev, -EIO ,"Failed to set trigger mode\n" ); + + indio_dev->name ="tf-luna" ; + indio_dev->info = &tf_luna_info; + indio_dev->channels = tf_luna_channels; + indio_dev->num_channels =ARRAY_SIZE (tf_luna_channels); + indio_dev->modes =INDIO_DIRECT_MODE ; + +return devm_iio_device_register (dev, indio_dev); +}
[1]: https://en.wikipedia.org/wiki/FourCC
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 1/3] dt-bindings: vendor-prefixes: Add Benewake
In reply to Vidhu SarwalQuoted 8 lines · Vidhu Sarwal
Add vendor prefix for Benewake (Beijing) Co., Ltd., a manufacturer of LiDAR distance sensors.
https://en.benewake.com/Signed-off-by Vidhu Sarwal <[email protected]>--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Best regards,
Krzysztof
Re: [PATCH 2/3] dt-bindings: iio: proximity: Add Benewake TF-Luna
In reply to Vidhu SarwalQuoted 5 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 the I2C interface. Pin 6 is a data ready
Binding should in general cover both interfaces. You will not get different compatible for UART. Incompatible changes won't be accepted, either.
Quoted 7 lines
output and is described as an interrupt.
Signed-off-by Vidhu Sarwal <[email protected]>--- .../bindings/iio/proximity/benewake,tf-luna.yaml | 58 ++++++++++++++++++++++ MAINTAINERS | 6 +++ 2 files changed, 64 insertions(+)
Best regards,
Krzysztof
Jonathan Cameron
maintainerQuoted 11 lines · On Tue, 20 Oct 2026 00:03:43 +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 8 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
-ENODATAinstead of a distance.The datasheet is available at:
https://en.benewake.com/uploadfiles/2025/04/20250430174501874.pdfSigned-off-by Vidhu Sarwal <[email protected]>
One trivial addition to comments from other reviewers.
Quoted 10 lines
drivers/iio/proximity/tf-luna.c new file +2
-0+ +static const struct iio_info tf_luna_info = {
drivers/iio/proximity/tf-luna.c line 148
Quoted 10 lines
drivers/iio/proximity/tf-luna.c new file +10
-0+ .read_raw = tf_luna_read_raw, +}; + +static const struct iio_chan_spec tf_luna_channels[] = { + { + .type =IIO_DISTANCE , + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ) | +BIT (IIO_CHAN_INFO_SCALE ), + }, +};
Where there is only ever going to be one channel it is fine to just not use an array and hard code num_channels = 1.
If you plan to add buffered support (no idea if that makes sense for this device), then I don't mind you leaving this as an array to make that step easier later.
Quoted 6 lines · Andy Shevchenko
Quoted 4 lines
drivers/iio/proximity/tf-luna.c line 61
Quoted 4 lines
drivers/iio/proximity/tf-luna.c new file +4
-0+static const struct regmap_config tf_luna_regmap_config = { + .reg_bits =8 , + .val_bits =8 , + .max_register =TF_LUNA_REG_SIGNATURE +3 ,No cache?
Hi Andy,
The only configuration register the driver writes to is MODE, once during probe. The other write is only a one shot trigger, and the registers read afterwards contain measurement data that keeps changing. also need to read MODE back from hardware since the sensor can silently ignore writes that come too quickly. I was planning to add caching later along with runtime PM to restore MODE , but I can add it in v2 if you think its better added now.
I'll also address the other comments from you, Joshua and Jonathan in v2.
Thanks,
Vidhu
Re: [PATCH 2/3] dt-bindings: iio: proximity: Add Benewake TF-Luna
In reply to Krzysztof KozlowskiQuoted 3 lines · Krzysztof Kozlowski
Binding should in general cover both interfaces. You will not get different compatible for UART. Incompatible changes won't be accepted, either.
Hi Krzysztof,
Thanks, In v2 I'll extend the binding to describe the UART interface as well. The driver stays I2C-only for now.
Thanks,
Vidhu
Quoted 1 line · Vidhu Sarwal
On Tue, Oct 20, 2026 at 10:42:51AM +0300, Andy Shevchenko wrote:
...
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
drivers/iio/proximity/tf-luna.c line 61
Quoted 4 lines
drivers/iio/proximity/tf-luna.c new file +4
-0+static const struct regmap_config tf_luna_regmap_config = { + .reg_bits =8 , + .val_bits =8 , + .max_register =TF_LUNA_REG_SIGNATURE +3 ,No cache?
Quoted 7 lines
The only configuration register the driver writes to is MODE, once during probe. The other write is only a one shot trigger, and the registers read afterwards contain measurement data that keeps changing. also need to read MODE back from hardware since the sensor can silently ignore writes that come too quickly. I was planning to add caching later along with runtime PM to restore MODE , but I can add it in v2 if you think its better added now.
Just add a comment summarizing what you just said.
Signature · 2 lines
With Best Regards, Andy Shevchenko