Skip to contentSkip to conversation

iio: magnetometer: add Infineon TLE493D-W2B6 support

PATCH In review Viral Patel 3 participants 11 messages Nov 5 – Nov 8

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

cover iio: magnetometer: add Infineon TLE493D-W2B6 support

This series adds support for the Infineon TLE493D-W2B6, a 3D Hall-effect sensor with an I2C interface, 12-bit X/Y/Z data and an integrated temperature sensor. It was tested with the TLE493D-W2B6 Shield2Go board (variant A0, I2C address 0x35) on a Raspberry Pi 5.

Why a new driver
================
The TLE493D-W2B6 is a second-generation sibling of the TLV493D-A1B6 (drivers/iio/magnetometer/tlv493d.c). Only the X/Y/Z bit packing is shared; everything else differs, so this adds a new driver rather than extending tlv493d.c, as agreed with Andy in the RFC [1]:

- Writes: the byte after the I2C address is a register address that also carries ADC trigger bits; tlv493d writes a raw stream starting at write register 0.
- Reads after reset: the sensor starts in a 2-byte read protocol that Linux cannot drive, so the first access must be a write that sets the PR bit to switch to plain reads starting at 0x00.
- Register map: a single unified map, 0x00-0x16.
- Mandatory odd parity bits (FP, CP). A wrong FP makes the sensor release the bus until it is reset, so FP is recomputed on every mode register write.
- Data validity: a Diag register (PD0/PD3, frame counter, bus parity) instead of the channel bits tlv493d polls in register 3.
- Temperature: 10-bit, with a different encoding and scale/offset.
- Different power modes and update rates, and a selectable short range (X2); the A1B6 has a single range.
- A dedicated I2C reset sequence.

The other Hall-effect drivers in drivers/iio/magnetometer (tmag5273, als31300, si7210) were also checked; none share the register map, the write format or the parity scheme.

Scope
=====
v1 supports master-controlled single-shot measurements of X/Y/Z and temperature at full range, via sysfs and a triggered buffer with a soft timestamp.

The temperature has 10 bits of resolution. It is reported as the 12-bit aligned register value, so in_temp_raw moves in steps of 4 and the scale and offset follow the datasheet's 12-bit LSB.

Not supported yet (possible follow-ups): wake-up thresholds, the built-in self-tests, low-power and fast modes, sampling-frequency control, and the short range.

Testing
=======
The series is based on iio.git togreg and build-tested there. Hardware testing was done on a Raspberry Pi 5 running the downstream rpi-6.18.y kernel (6.18.59), with both patches applied unchanged apart from a Makefile context fix-up.

- Probe: the module autoloads from the DT compatible and the Version and ID registers match the A0 variant. With the sensor disconnected, probe fails cleanly with -EREMOTEIO.
- Raw reads via sysfs: with no magnet nearby, X/Y/Z read within +/-3 LSB of zero; temperature reads 31.7-32.7 degC at room temperature, matching a userspace bring-up tool.
- Triggered buffer with an hrtimer trigger at 10, 100 and 500 Hz: no missed samples (200/200 at 100 and 500 Hz), mean period 10.000 ms and 2.000 ms with at most 3 us jitter. sysfs reads while streaming work.
- 10 rmmod/modprobe cycles and unbind/bind: no errors.
- W=1, sparse, checkpatch --strict and dt_binding_check are clean apart from the Datasheet: tag line-length/link warnings.

Known limitation
================
After a sensor power-on reset while the driver is bound, reads return -ETIMEDOUT until the driver is rebound. The reset clears PR, so the sensor is back in its 2-byte read protocol, plain reads return 0xff, the frame counter never changes and the driver times out waiting for a new frame. Recovery is planned as a follow-up.

Use of AI tools
===============
Claude (Anthropic), used through Claude Code, assisted with this series. I gave it a specification of the hardware (register map, parity rules, I2C protocol, conversion constants and test vectors) based on the User Manual, together with the v1 scope and IIO style requirements. From that it produced the initial drafts of the driver, the binding and a userspace bring-up tool, and it reviewed my later changes. I did the hardware bring-up and all of the testing above on the Pi 5, including the device tree overlay and boot setup, analysed the power-loss behaviour, and fixed up and reviewed every patch. I take responsibility for all of it.

[1] https://lore.kernel.org/linux-iio/[email protected]/

---
Viral Patel (2):
dt-bindings: iio: magnetometer: add Infineon TLE493D-W2B6
iio: magnetometer: add Infineon TLE493D-W2B6 driver

 .../iio/magnetometer/infineon,tle493d-w2b6.yaml    |  48 ++
 MAINTAINERS                                        |   7 +
 drivers/iio/magnetometer/Kconfig                   |  13 +
 drivers/iio/magnetometer/Makefile                  |   1 +
 drivers/iio/magnetometer/tle493d.c                 | 552 +++++++++++++++++++++
 5 files changed, 621 insertions(+)

---
base-commit: 1390ca4953a7400ca932cb49635f02c727f885a6
change-id: 20261028-tle493d-14c38f2bd273

Best regards,

Signature · 1 line
Viral Patel <[email protected]>
#1 lore raw

PATCH 1/2 dt-bindings: iio: magnetometer: add Infineon TLE493D-W2B6

Add a binding for the Infineon TLE493D-W2B6, a 3D Hall effect magnetic sensor with 12-bit resolution per axis and an integrated temperature sensor, accessed over I2C. The A0 to A3 variants of the part only differ in their default I2C address, so a single compatible covers all of them.

The sensor's /INT output shares a pin with SCL and cannot be wired to an interrupt controller as a separate line, so there is no interrupts property.

---
 .../iio/magnetometer/infineon,tle493d-w2b6.yaml    | 48 ++++++++++++++++++++++
 MAINTAINERS                                        |  6 +++
 2 files changed, 54 insertions(+)
Documentation/devicetree/bindings/iio/magnetometer/infineon,tle493d-w2b6.yaml new file +48 -0
new file mode 100644
index 000000000000..46f9c0e77e24
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/magnetometer/infineon,tle493d-w2b6.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Infineon TLE493D-W2B6 3D Magnetic Sensor
+
+maintainers:
+  - Viral Patel <[email protected]>
+
+description: |
+  Infineon TLE493D-W2B6 3D Hall effect magnetic sensor with an I2C interface
+  and an integrated temperature sensor. The A0, A1, A2 and A3 variants only
+  differ in their default I2C address (0x35, 0x22, 0x78 and 0x44).
+
+  The sensor's /INT output shares a pin with SCL, so it cannot be routed to
+  an interrupt controller as a separate line. The binding therefore has no
+  interrupts property.
+
+properties:
+  compatible:
+    const: infineon,tle493d-w2b6
+
+  reg:
+    maxItems: 1
+
+  vdd-supply: true
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        magnetometer@35 {
+            compatible = "infineon,tle493d-w2b6";
+            reg = <0x35>;
+            vdd-supply = <&vdd_3v3>;
+        };
+    };
MAINTAINERS +6 -0
index 0017755f593b..c8916e1286d3 100644
@@ -13110,6 +13110,12 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/sound/infineon,peb2466.yaml
 F:	sound/soc/codecs/peb2466.c
 
+INFINEON TLE493D-W2B6 DRIVER
+M:	Viral Patel <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/magnetometer/infineon,tle493d-w2b6.yaml
+
 INFINEON TLV493D Driver
 M:	Dixit Parmar <[email protected]>
 L:	[email protected]
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH 1/2] dt-bindings: iio: magnetometer: add Infineon TLE493D-W2B6

Quoted 8 lines · On Thu, 05 Nov 2026 21:23:47 +0530 Viral Patel <[email protected]> wrote:

Add a binding for the Infineon TLE493D-W2B6, a 3D Hall effect magnetic sensor with 12-bit resolution per axis and an integrated temperature sensor, accessed over I2C. The A0 to A3 variants of the part only differ in their default I2C address, so a single compatible covers all of them.

The sensor's /INT output shares a pin with SCL and cannot be wired to an interrupt controller as a separate line, so there is no interrupts property.

I haven't looked at the driver yet, but your explanation in the cover letter of why it is a separate driver seems fine.

That doesn't exclude using a shared device tree binding (as it is a many to many relationship between bindings and drivers) and it seems like nothing stops you combining this with the tle493d-a1b6 binding.

Thanks,

Jonathan

Quoted 79 lines
---
 .../iio/magnetometer/infineon,tle493d-w2b6.yaml    | 48 ++++++++++++++++++++++
 MAINTAINERS                                        |  6 +++
 2 files changed, 54 insertions(+)
Documentation/devicetree/bindings/iio/magnetometer/infineon,tle493d-w2b6.yaml new file +48 -0
new file mode 100644
index 000000000000..46f9c0e77e24
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/magnetometer/infineon,tle493d-w2b6.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Infineon TLE493D-W2B6 3D Magnetic Sensor
+
+maintainers:
+  - Viral Patel <[email protected]>
+
+description: |
+  Infineon TLE493D-W2B6 3D Hall effect magnetic sensor with an I2C interface
+  and an integrated temperature sensor. The A0, A1, A2 and A3 variants only
+  differ in their default I2C address (0x35, 0x22, 0x78 and 0x44).
+
+  The sensor's /INT output shares a pin with SCL, so it cannot be routed to
+  an interrupt controller as a separate line. The binding therefore has no
+  interrupts property.
+
+properties:
+  compatible:
+    const: infineon,tle493d-w2b6
+
+  reg:
+    maxItems: 1
+
+  vdd-supply: true
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        magnetometer@35 {
+            compatible = "infineon,tle493d-w2b6";
+            reg = <0x35>;
+            vdd-supply = <&vdd_3v3>;
+        };
+    };
MAINTAINERS +6 -0
index 0017755f593b..c8916e1286d3 100644
@@ -13110,6 +13110,12 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/sound/infineon,peb2466.yaml
 F:	sound/soc/codecs/peb2466.c
 
+INFINEON TLE493D-W2B6 DRIVER
+M:	Viral Patel <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/magnetometer/infineon,tle493d-w2b6.yaml
+
 INFINEON TLV493D Driver
 M:	Dixit Parmar <[email protected]>
 L:	[email protected]
#3 lore raw

Re: [PATCH 1/2] dt-bindings: iio: magnetometer: add Infineon TLE493D-W2B6

Quoted 3 lines · Jonathan Cameron

That doesn't exclude using a shared device tree binding (as it is a many to many relationship between bindings and drivers) and it seems like nothing stops you combining this with the tle493d-a1b6 binding.

Makes sense, I'll add the compatible to infineon,tlv493d-a1b6.yaml in v2 and Cc Dixit.

Thanks,
Viral

#4 lore raw

PATCH 2/2 iio: magnetometer: add Infineon TLE493D-W2B6 driver

In reply to Viral Patel

Add a driver for the Infineon TLE493D-W2B6, a 3D Hall effect magnetic sensor with 12-bit resolution per axis and an integrated temperature sensor, accessed over I2C.

The sensor is run in master-controlled mode. Each measurement rewrites the Config register with the "trigger after write" bits set in the register address byte, which starts a single conversion, and then polls registers 0x00 to 0x06 until Diag reports a completed conversion with a new frame counter. Results with a fuse parity error, test mode flag or bad bus parity are rejected. FP and CP are recomputed on every write of MOD1 and Config, as a wrong FP makes the sensor release the bus until it is reset.

The /INT output shares a pin with SCL, so the interrupt is disabled and so is clock stretching. The sensor's reset sequence relies on zero-length messages which many I2C adapters reject, so it is sent on a best-effort basis during probe.

Raw I2C transfers are used rather than regmap: once PR is set a plain read always starts at register 0x00, and the register address byte of a write carries trigger bits.

The X, Y and Z channels and the temperature channel are available through sysfs and through a triggered buffer with a software timestamp. Wake-up, self-test, low-power and fast modes, sampling frequency control and the short range are not supported yet.

This is not added to the tlv493d driver: apart from the X/Y/Z bit packing, the two parts differ in write format, read protocol after reset, register map and parity scheme.

Based on the TLE493D-W2B6 User Manual v1.11 and Datasheet v1.2.

Datasheet: https://www.infineon.com/assets/row/public/documents/30/49/infineon-tle493d-w2b6-datasheet-en.pdf

---
 MAINTAINERS                        |   1 +
 drivers/iio/magnetometer/Kconfig   |  13 +
 drivers/iio/magnetometer/Makefile  |   1 +
 drivers/iio/magnetometer/tle493d.c | 552 +++++++++++++++++++++++++++++++++++++
 4 files changed, 567 insertions(+)
MAINTAINERS +1 -0
index c8916e1286d3..5282c0039abb 100644
@@ -13115,6 +13115,7 @@ M:	Viral Patel <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/iio/magnetometer/infineon,tle493d-w2b6.yaml
+F:	drivers/iio/magnetometer/tle493d.c
 
 INFINEON TLV493D Driver
 M:	Dixit Parmar <[email protected]>
drivers/iio/magnetometer/Kconfig +13 -0
index d359003b248e..bc26fc4d78e2 100644
@@ -196,6 +196,19 @@ config IIO_ST_MAGN_SPI_3AXIS
 	  To compile this driver as a module, choose M here. The module
 	  will be called st_magn_spi.
 
+config INFINEON_TLE493D
+	tristate "Infineon TLE493D-W2B6 3D Magnetic Sensor"
+	depends on I2C
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	help
+	  Say Y here to add support for the Infineon TLE493D-W2B6 3D
+	  magnetic sensor.
+
+	  This driver can also be compiled as a module.
+	  To compile this driver as a module, choose M here: the module
+	  will be called tle493d.
+
 config INFINEON_TLV493D
 	tristate "Infineon TLV493D Low-Power 3D Magnetic Sensor"
 	depends on I2C
drivers/iio/magnetometer/Makefile +1 -0
index 8f2205975c1b..31df6a49459c 100644
@@ -25,6 +25,7 @@ st_magn-$(CONFIG_IIO_BUFFER) += st_magn_buffer.o
 obj-$(CONFIG_IIO_ST_MAGN_I2C_3AXIS) += st_magn_i2c.o
 obj-$(CONFIG_IIO_ST_MAGN_SPI_3AXIS) += st_magn_spi.o
 
+obj-$(CONFIG_INFINEON_TLE493D)		+= tle493d.o
 obj-$(CONFIG_INFINEON_TLV493D)		+= tlv493d.o
 
 obj-$(CONFIG_QMC5883L)			+= qmc5883l.o
drivers/iio/magnetometer/tle493d.c new file +552 -0

552 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer
#5 lore raw

Re: [PATCH 2/2] iio: magnetometer: add Infineon TLE493D-W2B6 driver

Quoted 27 lines · On Thu, 05 Nov 2026 21:23:48 +0530 Viral Patel <[email protected]> wrote:

Add a driver for the Infineon TLE493D-W2B6, a 3D Hall effect magnetic sensor with 12-bit resolution per axis and an integrated temperature sensor, accessed over I2C.

The sensor is run in master-controlled mode. Each measurement rewrites the Config register with the "trigger after write" bits set in the register address byte, which starts a single conversion, and then polls registers 0x00 to 0x06 until Diag reports a completed conversion with a new frame counter. Results with a fuse parity error, test mode flag or bad bus parity are rejected. FP and CP are recomputed on every write of MOD1 and Config, as a wrong FP makes the sensor release the bus until it is reset.

The /INT output shares a pin with SCL, so the interrupt is disabled and so is clock stretching. The sensor's reset sequence relies on zero-length messages which many I2C adapters reject, so it is sent on a best-effort basis during probe.

Raw I2C transfers are used rather than regmap: once PR is set a plain read always starts at register 0x00, and the register address byte of a write carries trigger bits.

The X, Y and Z channels and the temperature channel are available through sysfs and through a triggered buffer with a software timestamp. Wake-up, self-test, low-power and fast modes, sampling frequency control and the short range are not supported yet.

Quoted 8 lines

This is not added to the tlv493d driver: apart from the X/Y/Z bit packing, the two parts differ in write format, read protocol after reset, register map and parity scheme.

Based on the TLE493D-W2B6 User Manual v1.11 and Datasheet v1.2.

Datasheet: https://www.infineon.com/assets/row/public/documents/30/49/infineon-tle493d-w2b6-datasheet-en.pdf

Seems sashiko isn't done with this one yet (at time of writing) so please take a look to see if it finds anything useful
https://sashiko.dev/#/patchset/20261105-tle493d-v1-0-3246e91e6394%40gmail.com

This hardware has a creative interface so I may have asked some questions that reflect my general state of confusion induced by that.

A few things inline,

Quoted 5 lines
drivers/iio/magnetometer/tle493d.c new file +0 -0
new file mode 100644
index 000000000000..232f7680a02b

drivers/iio/magnetometer/tle493d.c line 213

Quoted 9 lines
drivers/iio/magnetometer/tle493d.c new file +6 -0
 
 
 
+
+static bool tle493d_conversion_done(const u8 *buf, u8 last_frm)
+{
+	u8 diag = buf[TLE493D_REG_DIAG];
+
+	return (diag & TLE493D_DIAG_PD0) && (diag & TLE493D_DIAG_PD3) &&

Use FIELD_GET() to extract the 1 bit values as well. Ends up easier to read than the mix of & and &&

Quoted 20 lines
drivers/iio/magnetometer/tle493d.c new file +20 -0
+	       FIELD_GET(TLE493D_DIAG_FRM, diag) != last_frm;
+}
+
+static int tle493d_measure(struct tle493d_data *data, u8 *buf)
+{
+	u8 last_frm = FIELD_GET(TLE493D_DIAG_FRM, data->regs[TLE493D_REG_DIAG]);
+	u8 diag;
+	int ret, err;
+
+	/* Rewriting Config with the write trigger starts a single conversion */
+	ret = tle493d_write(data, TLE493D_REG_CONFIG,
+			    data->regs[TLE493D_REG_CONFIG], TLE493D_ADDR_TRIG_WRITE);
+	if (ret)
+		return ret;
+
+	ret = read_poll_timeout(tle493d_read, err,
+				err || tle493d_conversion_done(buf, last_frm),
+				TLE493D_POLL_US, TLE493D_TIMEOUT_US, true,
+				data, buf, TLE493D_DATA_LEN);
+	if (ret)

drivers/iio/magnetometer/tle493d.c line 243

Quoted 10 lines
drivers/iio/magnetometer/tle493d.c new file +10 -0
+		return ret;
+	if (err)
+		return err;
+
+	diag = buf[TLE493D_REG_DIAG];
+	data->regs[TLE493D_REG_DIAG] = diag;
+
+	if (!(diag & TLE493D_DIAG_FF) || (diag & TLE493D_DIAG_T) ||
+	    !tle493d_data_parity_ok(buf))
+		return -EIO;

Why do this after setting data->regs[TLE493_REG_DIAG]? If this function is returning an error I'd assume we wouldn't use that value anyway

Quoted 6 lines
drivers/iio/magnetometer/tle493d.c new file +5 -0
+
+	return 0;
+}
 
+
+static int tle493d_read_raw(struct iio_dev *indio_dev,

drivers/iio/magnetometer/tle493d.c line 284

Quoted 10 lines
drivers/iio/magnetometer/tle493d.c new file +10 -0
+			    const struct iio_chan_spec *chan, int *val,
+			    int *val2, long mask)
+{
+	struct tle493d_data *data = iio_priv(indio_dev);
+	u8 buf[TLE493D_DATA_LEN];
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		scoped_guard(mutex, &data->lock) {

I'd be tempted to just hold the lock a bit long and do the simpler

	case IIO_CHAN_INFO_RAW: {
		guard()...

	...
		return IIO_VAL_INT;
	}
Quoted 6 lines
drivers/iio/magnetometer/tle493d.c new file +6 -0
+			ret = tle493d_measure(data, buf);
+			if (ret)
+				return ret;
+		}
+		*val = tle493d_get_channel_data(buf, chan->address);
+		return IIO_VAL_INT;

...

Quoted 5 lines
drivers/iio/magnetometer/tle493d.c new file +5 -0
+
+static irqreturn_t tle493d_trigger_handler(int irq, void *p)
+{
+	struct iio_poll_func *pf = p;
+	struct iio_dev *indio_dev = pf->indio_dev;

drivers/iio/magnetometer/tle493d.c line 336

Quoted 10 lines
drivers/iio/magnetometer/tle493d.c new file +10 -0
+	struct tle493d_data *data = iio_priv(indio_dev);
+	u8 buf[TLE493D_DATA_LEN];
+	struct {
+		s16 magn[3];
+		u16 temp;
+		aligned_s64 timestamp;
+	} scan = { };
+	int ret;
+
+	scoped_guard(mutex, &data->lock)

Generally avoid any use of cleanup.h magic in a function with a goto. This one isn't a bug as such but it is considered bad practice. Just use mutex_lock/unlock()

Quoted 18 lines
drivers/iio/magnetometer/tle493d.c new file +17 -0
+		ret = tle493d_measure(data, buf);
+	if (ret)
+		goto out;
+
+	scan.magn[0] = tle493d_get_channel_data(buf, TLE493D_AXIS_X);
+	scan.magn[1] = tle493d_get_channel_data(buf, TLE493D_AXIS_Y);
+	scan.magn[2] = tle493d_get_channel_data(buf, TLE493D_AXIS_Z);
+	scan.temp = tle493d_get_channel_data(buf, TLE493D_TEMPERATURE);
+
+	iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), pf->timestamp);
+
+out:
+	iio_trigger_notify_done(indio_dev->trig);
+
+	return IRQ_HANDLED;
+}
 
+static const unsigned long tle493d_scan_masks[] = { GENMASK(3, 0), 0 };

drivers/iio/magnetometer/tle493d.c line 402

Quoted 10 lines
drivers/iio/magnetometer/tle493d.c new file +10 -0
+
+static const struct iio_info tle493d_info = {
+	.read_raw = tle493d_read_raw,
+};
+
+/*
+ * The reset sequence is four separate frames whose first bytes are 0xff,
+ * 0xff, 0x00 and 0x00, i.e. zero-length reads from address 0x7f followed by
+ * zero-length writes to address 0x00. Not every adapter can send zero-length
+ * messages, so the reset is best effort.

Can we detect if the controller supports it? Feels like it should have an I2C_FUNC_xxx to enable discovery of this.

Is it same as SMBUS Quick command? If so use that.

Quoted 4 lines

+ */

drivers/iio/magnetometer/tle493d.c new file +3 -0
+static void tle493d_reset(struct tle493d_data *data)
+{
+	struct device *dev = &data->client->dev;

drivers/iio/magnetometer/tle493d.c line 416

Quoted 10 lines
drivers/iio/magnetometer/tle493d.c new file +10 -0
+	struct i2c_msg msgs[] = {
+		{ .addr = 0x7f, .flags = I2C_M_RD },
+		{ .addr = 0x7f, .flags = I2C_M_RD },
+		{ .addr = 0x00 },
+		{ .addr = 0x00 },
+	};
+	unsigned int i;
+	int ret;
+
+	for (i = 0; i < ARRAY_SIZE(msgs); i++) {

for (unsigned int i = 0; ...

Quoted 58 lines
drivers/iio/magnetometer/tle493d.c new file +58 -0
+		/* The reset frames are not acknowledged, so ignore NACKs */
+		ret = i2c_transfer(data->client->adapter, &msgs[i], 1);
+		if (ret == -EOPNOTSUPP) {
+			dev_dbg(dev, "adapter cannot send the reset sequence\n");
+			return;
+		}
+	}
+
+	fsleep(TLE493D_RESET_DELAY_US);
+}
+
+static int tle493d_init(struct tle493d_data *data, unsigned int iicadr)
+{
+	struct device *dev = &data->client->dev;
+	unsigned int hwv, id;
+	u8 mod1;
+	int ret;
+
+	/*
+	 * After reset the sensor uses a 2-byte read protocol which plain I2C
+	 * reads cannot handle, so MOD1 has to be written before any read. MOD2
+	 * is not known yet and FP is computed with its reset value, PRD = 0.
+	 * Clock stretching and the interrupt are disabled because /INT shares
+	 * the SCL pin.
+	 */
+	mod1 = FIELD_PREP(TLE493D_MOD1_IICADR, iicadr) | TLE493D_MOD1_PR |
+	       TLE493D_MOD1_CA | TLE493D_MOD1_INT |
+	       FIELD_PREP(TLE493D_MOD1_MODE, TLE493D_MOD1_MODE_MASTER);
+	ret = tle493d_write(data, TLE493D_REG_MOD1, mod1, 0);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to write MOD1\n");
+
+	ret = tle493d_read(data, data->regs, TLE493D_NUM_REGS);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to read registers\n");
+
+	hwv = FIELD_GET(TLE493D_VER_HWV, data->regs[TLE493D_REG_VER]);
+	if (hwv != TLE493D_VER_HWV_B21)
+		dev_info(dev, "unknown hardware version %u\n", hwv);
+
+	id = FIELD_GET(TLE493D_TEMP2_ID, data->regs[TLE493D_REG_TEMP2]);
+	if (id != iicadr)
+		dev_info(dev, "unexpected ID %u, expected %u\n", id, iicadr);
+
+	/*
+	 * Full range, temperature and Bz enabled, no trigger via Config. This
+	 * also sets a valid CP, which is not the case after reset.
+	 */
+	ret = tle493d_write(data, TLE493D_REG_CONFIG, 0, 0);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to write Config\n");
+
+	return 0;
+}
+
+static int tle493d_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;

drivers/iio/magnetometer/tle493d.c line 484

Quoted 10 lines
drivers/iio/magnetometer/tle493d.c new file +10 -0
+	struct tle493d_data *data;
+	struct iio_dev *indio_dev;
+	unsigned int iicadr;
+	int ret;
+
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
+		return dev_err_probe(dev, -EOPNOTSUPP, "plain I2C transfers not supported\n");
+
+	for (iicadr = 0; iicadr < ARRAY_SIZE(tle493d_i2c_addrs); iicadr++) {
+		if (client->addr == tle493d_i2c_addrs[iicadr])

This match is unusual. I don't think we should be failing probe on seeing a device on a different i2c address given we are happy to accept a mismatch from internal device ID as long as it is one of this list. However it seems the index is
written to the device. Can you add a few comments on what
this iicadr is for.

Quoted 44 lines
drivers/iio/magnetometer/tle493d.c new file +42 -0
+			break;
+	}
+	if (iicadr == ARRAY_SIZE(tle493d_i2c_addrs))
+		return dev_err_probe(dev, -EINVAL, "unsupported I2C address 0x%02x\n",
+				     client->addr);
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	data = iio_priv(indio_dev);
+	data->client = client;
+
+	ret = devm_mutex_init(dev, &data->lock);
+	if (ret)
+		return ret;
+
+	ret = devm_regulator_get_enable(dev, "vdd");
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to enable vdd regulator\n");
+
+	tle493d_reset(data);
+
+	ret = tle493d_init(data, iicadr);
+	if (ret)
+		return ret;
+
+	indio_dev->name = "tle493d";
+	indio_dev->info = &tle493d_info;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->channels = tle493d_channels;
+	indio_dev->num_channels = ARRAY_SIZE(tle493d_channels);
+	indio_dev->available_scan_masks = tle493d_scan_masks;
+
+	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+					      iio_pollfunc_store_time,
+					      tle493d_trigger_handler, NULL);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to set up triggered buffer\n");
+
+	return devm_iio_device_register(dev, indio_dev);
+}
#6 lore raw

Re: [PATCH 2/2] iio: magnetometer: add Infineon TLE493D-W2B6 driver

Quoted 1 line · Jonathan Cameron

Seems sashiko isn't done with this one yet ...

It has finished now and reported no issues on either patch.

Quoted 1 line

Use FIELD_GET() to extract the 1 bit values as well.

Will do.

Quoted 1 line

Why do this after setting data->regs[TLE493_REG_DIAG]?

It's deliberate: the cached Diag holds the frame counter of the last frame read, and the next measurement waits for FRM to change. Updating it even for a rejected frame means that frame is not treated as new next time. I'll add a comment.

Quoted 7 lines

I'd be tempted to just hold the lock a bit long and do the simpler case IIO_CHAN_INFO_RAW: {
guard()...

...
return IIO_VAL_INT;
}

Ok, will simplify.

Quoted 2 lines

Generally avoid any use of cleanup.h magic in a function with a goto.

Will switch to mutex_lock()/mutex_unlock().

Quoted 1 line

for (unsigned int i = 0; ...

Will change.

Quoted 1 line

Is it same as SMBUS Quick? If so use that.

Yes, the reset frames are Quick commands (read at 0x7f, write at 0x00). v2 will use I2C_SMBUS_QUICK and skip the reset when the adapter lacks I2C_FUNC_SMBUS_QUICK. Note 0x00 is the general call address, so other devices that respond to general call will see an empty write; this follows the manual's reset sequence. The Pi 5 controller doesn't support Quick, so the reset was not exercised in my testing.

Quoted 1 line

Can you add a few comments on what this iicadr is for.

IICadr in MOD1 selects which of the four addresses the sensor responds on (User Manual v1.11, MOD1 and Table 4), and every MOD1 write includes it. The manual's write example notes that IICadr must be kept at the current value so the address doesn't change, so the driver has to write the value matching the address the device is on. That's why an address outside the list fails probe: there is no correct value to write. The ID check is only informational. I'll add a comment.

Thanks,
Viral

#7 lore raw

Re: [PATCH 2/2] iio: magnetometer: add Infineon TLE493D-W2B6 driver

Quoted 2 lines · On Fri, 6 Nov 2026 22:14:42 +0530, Viral Patel [email protected] wrote:

The Pi 5 controller doesn't support Quick, so
the reset was not exercised in my testing.

Correction: that's true of the mainline DesignWare driver, but the Raspberry Pi kernel I tested on advertises I2C_FUNC_SMBUS_QUICK and sends zero-length messages as Quick commands, so the reset sequence was sent and worked in my testing.

Thanks,
Viral

#8 lore raw

Re: [PATCH 2/2] iio: magnetometer: add Infineon TLE493D-W2B6 driver

In reply to Viral Patel
Quoted 4 lines

Based on the TLE493D-W2B6 User Manual v1.11 and Datasheet v1.2.

Datasheet: https://www.infineon.com/assets/row/public/documents/30/49/infineon-tle493d-w2b6-datasheet-en.pdf

You should link to the user manual too, since that's where most of the information relevant to programming the driver is.
I see that it's not available from the Infineon website without a login, but it's easy to find elsewhere:

https://assets.sourcengine.com/datasheets/c9ebe749-34ab-4924-ab2b-aa7d4dd15e25.pdf

drivers/iio/magnetometer/tle493d.c line 107

Quoted 3 lines
drivers/iio/magnetometer/tle493d.c new file +3 -0
+/* I2C addresses selected by IICadr, i.e. the default of variants A0 to A3 */
+static const u8 tle493d_i2c_addrs[] = { 0x35, 0x22, 0x78, 0x44 };
+

The manual seems to list these addresses as 0x6A, 0x44, 0xF0, 0x88 (Table 4, p. 14). Can you explain how you go from those values to the ones in the code?

#9 lore raw

Re: [PATCH 2/2] iio: magnetometer: add Infineon TLE493D-W2B6 driver

Quoted 10 lines · Victor Chernyakin
Quoted 3 lines

Based on the TLE493D-W2B6 User Manual v1.11 and Datasheet v1.2.

Datasheet: https://www.infineon.com/assets/row/public/documents/30/49/infineon-tle493d-w2b6-datasheet-en.pdf

You should link to the user manual too, since that's where most of the information relevant to programming the driver is.
I see that it's not available from the Infineon website without a login, but it's easy to find elsewhere:

https://assets.sourcengine.com/datasheets/c9ebe749-34ab-4924-ab2b-aa7d4dd15e25.pdf

Agreed, thanks. In v2 I'll link Infineon's own copy:

Register details are from the TLE493D-W2B6 User Manual v1.11, which Infineon provides after a free registration:
https://www.infineon.com/gated/infineon-tle493d-w2b6-usermanual-en_dc6d4e62-cde1-4d4b-87bb-c3368e25e35c

I'd rather use the vendor URL than a third-party mirror, which might not stay up.

Quoted 6 lines

drivers/iio/magnetometer/tle493d.c line 106

Quoted 2 lines
drivers/iio/magnetometer/tle493d.c new file +2 -0
+/* I2C addresses selected by IICadr, i.e. the default of variants A0 to A3 */
+static const u8 tle493d_i2c_addrs[] = { 0x35, 0x22, 0x78, 0x44 };

The manual seems to list these addresses as 0x6A, 0x44, 0xF0, 0x88 (Table 4, p. 14). Can you explain how you go from those values to the ones in the code?

Table 4 gives the addresses in 8-bit form, that is, the 7-bit address shifted left by one with the R/W bit in bit 0. Linux uses 7-bit addresses, so 0x6A >> 1 = 0x35, 0x44 >> 1 = 0x22, 0xF0 >> 1 = 0x78 and 0x88 >> 1 = 0x44. The hardware agrees: the driver probes my A0 part at 0x35 on a Pi 5.

I'll add that to the comment in v2.

Thanks,
Viral

#10 lore raw

Re: [PATCH 2/2] iio: magnetometer: add Infineon TLE493D-W2B6 driver

Quoted 7 lines
Quoted 6 lines

drivers/iio/magnetometer/tle493d.c line 106

Quoted 2 lines
drivers/iio/magnetometer/tle493d.c new file +2 -0
+/* I2C addresses selected by IICadr, i.e. the default of variants A0 to A3 */
+static const u8 tle493d_i2c_addrs[] = { 0x35, 0x22, 0x78, 0x44 };

The manual seems to list these addresses as 0x6A, 0x44, 0xF0, 0x88 (Table 4, p. 14). Can you explain how you go from those values to the ones in the code?

Quoted 7 lines

Table 4 gives the addresses in 8-bit form, that is, the 7-bit address shifted left by one with the R/W bit in bit 0. Linux uses 7-bit addresses, so 0x6A >> 1 = 0x35, 0x44 >> 1 = 0x22, 0xF0 >> 1 = 0x78 and 0x88 >> 1 = 0x44. The hardware agrees: the driver probes my A0 part at 0x35 on a Pi 5.

I'll add that to the comment in v2.

Okay, now that you've explained it I feel silly for not getting it earlier :p
Feel free to add the comment, but it may be unnecessary, I think the problem is that I'm just not very familiar with I2C.