Skip to contentSkip to conversation

iio: magnetometer: add Infineon TLE493D-W2B6 support

PATCH In review Viral Patel 3 participants 5 messages Dec 5

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

v3 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
=====
The driver 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. W=1, sparse, checkpatch --strict and dt_binding_check are clean apart from the Datasheet: tag line-length/link warnings.

The v3 changes were build-tested only, as the hardware was not available for this revision. They are review clean-ups; the parity helpers rewritten with parity8() were checked against the v2 versions on 2 million random inputs in userspace.

The hardware results below are from v1 and v2, on a Raspberry Pi 5 running the downstream rpi-6.18.y kernel (6.18.59). For v1 both patches were applied there unchanged apart from a Makefile context fix-up; for v2 the driver from this series was built as a module against that kernel and re-tested.

- 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 (v1).
- Reset: the Pi's DesignWare adapter advertises I2C_FUNC_SMBUS_QUICK. An i2c/smbus trace of probe shows two Quick reads from 0x7f and two Quick writes to 0x00, each NACKed as expected, followed by the MOD1 write to 0x35.
- Raw reads via sysfs: with no magnet nearby, X/Y/Z read within +/-3 LSB of zero; temperature reads about 30-33 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 (20/20, 200/200 and 1000/1000 over 2 s). In v1 the mean period at 100 and 500 Hz was 10.000 ms and 2.000 ms with at most 3 us jitter.
- sysfs reads from four processes in parallel, and sysfs reads while streaming, work.
- 10 rmmod/modprobe cycles and unbind/bind: no errors.

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
===============
My part: I wrote the hardware specification the driver is based on (register map, parity rules, I2C protocol, conversion constants and test vectors, from the User Manual). I did the bring-up and the v1 hardware testing on the Pi 5, including the device tree overlay and boot setup, analysed the power-loss behaviour, and checked the TLV493D datasheet to confirm the binding can be shared. I decided how to address each round of review, re-tested v2 myself and wrote the v3 driver commit message. I reviewed every patch and take responsibility for all of it.

Claude (Anthropic), used through Claude Code, wrote the initial drafts of the driver, the binding and a userspace bring-up tool from my specification and the IIO style requirements I gave it. It also made the v2 and v3 code changes, analysed the v3 review comments, ran the v2 re-test on my setup and drafted parts of this cover letter.

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

---
Changes in v3:
- dt-bindings: use a folded description and drop the A0-A3 address paragraph (Jonathan)
- Move the MAINTAINERS entry to the driver patch, without the binding
F: line (Jonathan)
- Pick up Rob's Reviewed-by on the binding
- Shorten the driver commit message (Jonathan)
- Link the user manual with a second Datasheet: tag (Jonathan). Andy suggested Link:, I followed Jonathan's request for Datasheet:
- tle493d_write(): fill buf[0] first, write buf[1] in the switch (Jonathan)
- Comment on why only the four IICadr addresses work (Jonathan)
- Use parity8() for FP, CP and the data parity check (Andy)
- Declare loop counters in the for statements (Andy)
- Add a helper for the Diag frame counter (Andy)
- Sleep for the 175 us conversion time before polling, then poll every 50 us; timeout as (1 * USEC_PER_MSEC) (Andy)
- Add tle493d_measure_locked() using guard(), used by read_raw() and the trigger handler instead of mutex_lock()/mutex_unlock() (Andy)
- Write the scan mask with BIT()s (Andy)
- Drop linux/bits.h (Andy)
- Andy asked whether the temperature can be negative: over the
-40 to 125 degC operating range the raw value is about 909 to 1597 (1180 at 25 degC, 0.24 K/LSB), so the top bit is never set
- Andy asked whether tle493d_init() needs a rollback: it only configures sensor registers and vdd is released through devm, so there is nothing to undo on remove
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Rebased onto current togreg
- dt-bindings: add the compatible to infineon,tlv493d-a1b6.yaml instead of a new file. interrupts is allowed as for the TLV493D, since both parts have /INT on SCL and Infineon recommends wiring it up (Jonathan)
- Use FIELD_GET() for the single-bit Diag flags (Jonathan)
- Comment on why Diag is cached before the error checks (Jonathan)
- Use guard() in read_raw() and mutex_lock()/mutex_unlock() in the trigger handler (Jonathan)
- Send the reset as SMBus Quick commands and skip it if the adapter lacks I2C_FUNC_SMBUS_QUICK (Jonathan)
- Declare the reset loop counter in the for statement (Jonathan)
- Comment on IICadr and on the 7-bit vs 8-bit addresses (Jonathan, Victor)
- Link the user manual in the driver commit message (Victor)
- Link to v1: https://lore.kernel.org/r/[email protected]

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

 .../iio/magnetometer/infineon,tlv493d-a1b6.yaml    |  11 +-
 MAINTAINERS                                        |   6 +
 drivers/iio/magnetometer/Kconfig                   |  13 +
 drivers/iio/magnetometer/Makefile                  |   1 +
 drivers/iio/magnetometer/tle493d.c                 | 580 +++++++++++++++++++++
 5 files changed, 609 insertions(+), 2 deletions(-)

---
base-commit: fba506008a5b548ad2708bc2765a039cb00a47ab
change-id: 20261028-tle493d-14c38f2bd273

Best regards,

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

PATCH v3 1/2 dt-bindings: iio: magnetometer: infineon,tlv493d-a1b6: add TLE493D-W2B6

Add the Infineon TLE493D-W2B6, a 3D Hall effect magnetic sensor with 12-bit resolution per axis and an integrated temperature sensor, accessed over I2C. It is a second-generation sibling of the TLV493D-A1B6 with a different register interface, so it gets its own compatible, but it has the same supply range and the same /INT output sharing the SCL pin, so it fits the existing binding.

The A0 to A3 variants of the part only differ in their default I2C address, so a single compatible covers all of them.

---
 .../bindings/iio/magnetometer/infineon,tlv493d-a1b6.yaml      | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/iio/magnetometer/infineon,tlv493d-a1b6.yaml +9 -2
index dd23a9370a71..fc1163a94910 100644
@@ -4,17 +4,24 @@
 $id: http://devicetree.org/schemas/iio/magnetometer/infineon,tlv493d-a1b6.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: Infineon Technologies TLV493D Low-Power 3D Magnetic Sensor
+title: Infineon Technologies TLV493D and TLE493D 3D Magnetic Sensors
 
 maintainers:
   - Dixit Parmar <[email protected]>
+  - Viral Patel <[email protected]>
+
+description: >
+  3D Hall effect magnetic sensors with an I2C interface. The /INT output
+  shares a pin with SCL.
 
 properties:
   $nodename:
     pattern: '^magnetometer@[0-9a-f]+$'
 
   compatible:
-    const: infineon,tlv493d-a1b6
+    enum:
+      - infineon,tle493d-w2b6
+      - infineon,tlv493d-a1b6
 
   reg:
     maxItems: 1
Signature · 1 line
2.43.0
#2 lore raw

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

In reply to Viral Patel

Add a driver for a 3-axis Hall effect magnetometer with 12-bit resolution and a built-in temperature sensor. Communication is via I2C.

The driver runs the sensor in master-controlled mode. As /INT is combined with the SCL pin, the interrupt and clock stretching are turned off.

Communication uses raw I2C transfers rather than regmap. Once the PR bit has been set, a plain read always begins at register 0x00, and the register address byte of a write also carries trigger bits.

Channel data can be read through sysfs and through a triggered buffer.

Datasheet: https://www.infineon.com/assets/row/public/documents/30/49/infineon-tle493d-w2b6-datasheet-en.pdf
Datasheet: https://www.infineon.com/gated/infineon-tle493d-w2b6-usermanual-en_dc6d4e62-cde1-4d4b-87bb-c3368e25e35c

---
 MAINTAINERS                        |   6 +
 drivers/iio/magnetometer/Kconfig   |  13 +
 drivers/iio/magnetometer/Makefile  |   1 +
 drivers/iio/magnetometer/tle493d.c | 580 +++++++++++++++++++++++++++++++++++++
 4 files changed, 600 insertions(+)
MAINTAINERS +6 -0
index b37bf911c2b7..1c9ed28cdabf 100644
@@ -13133,6 +13133,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:	drivers/iio/magnetometer/tle493d.c
+
 INFINEON TLV493D Driver
 M:	Dixit Parmar <[email protected]>
 L:	[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 +580 -0

580 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

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

Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] iio: magnetometer: tle493d_probe() broadcast reset breaks sibling sensors - [Medium] iio…

Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] iio: magnetometer: tle493d_probe() broadcast reset breaks sibling sensors
- [Medium] iio: magnetometer: tle493d_reset() lacks I2C bus lock across reset frames
- [Medium] iio: magnetometer: tle493d_measure() can read torn data with CA disabled
- [Medium] iio: tle493d: missing power-on delay after vdd enable in tle493d_probe()
--

commit eb9704b11b9a3ed71756d6e4d39fe59ef234e32f
Author: Viral Patel <[email protected]>

iio: magnetometer: add Infineon TLE493D-W2B6 driver

This commit adds an IIO driver for the Infineon TLE493D-W2B6 3-axis Hall effect magnetometer and temperature sensor over I2C, supporting sysfs reads and triggered buffer capture in master-controlled mode.

Quoted 6 lines
drivers/iio/magnetometer/tle493d.c new file +0 -0
new file mode 100644
index 0000000000000..9982362b57cd2
@@ -0,0 +1,580 @@

[ ... ]

Quoted 9 lines
drivers/iio/magnetometer/tle493d.c new file +9 -0
+static int tle493d_measure(struct tle493d_data *data, u8 *buf)
+{
+	u8 last_frm = 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);

drivers/iio/magnetometer/tle493d.c line 239

Quoted 10 lines
drivers/iio/magnetometer/tle493d.c new file +10 -0
+	if (ret)
+		return ret;
+
+	/* The result cannot be ready before the conversion time has passed */
+	fsleep(TLE493D_CONV_US);
+
+	ret = read_poll_timeout(tle493d_read, err,
+				err || tle493d_conversion_done(buf, last_frm),
+				TLE493D_POLL_US, TLE493D_TIMEOUT_US, false,
+				data, buf, TLE493D_DATA_LEN);

[Severity: Medium]
Can tle493d_measure() return a torn measurement when a conversion finishes mid-read?

tle493d_init() sets TLE493D_MOD1_CA, disabling clock stretching, and tle493d_measure() sleeps only the typical conversion time (175 us) before reading registers 0x00 through 0x06 in one transfer.

If the conversion completes after byte 0x00 starts clocking out and before Diag (0x06) is read, buf[0..5] can mix old and new bytes while buf[6] already reports completion.

Because tle493d_data_parity_ok() only checks a single XOR parity bit, half of torn frames fail with -EIO and the other half silently pass with corrupted readings. A clean read once Diag confirms completion (or sleeping past the worst-case conversion time) would avoid this.

[ ... ]

Quoted 15 lines
drivers/iio/magnetometer/tle493d.c new file +15 -0
+static void tle493d_reset(struct tle493d_data *data)
+{
+	struct i2c_adapter *adap = data->client->adapter;
+	static const struct {
+		u16 addr;
+		char read_write;
+	} frames[] = {
+		{ 0x7f, I2C_SMBUS_READ },
+		{ 0x7f, I2C_SMBUS_READ },
+		{ 0x00, I2C_SMBUS_WRITE },
+		{ 0x00, I2C_SMBUS_WRITE },
+	};
+
+	if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) {
+		dev_dbg(&data->client->dev, "adapter cannot send the reset sequence\n");

drivers/iio/magnetometer/tle493d.c line 449

Quoted 10 lines
drivers/iio/magnetometer/tle493d.c new file +10 -0
+		return;
+	}
+
+	/* The reset frames are not acknowledged, so ignore the return values */
+	for (unsigned int i = 0; i < ARRAY_SIZE(frames); i++)
+		i2c_smbus_xfer(adap, frames[i].addr, 0, frames[i].read_write, 0,
+			       I2C_SMBUS_QUICK, NULL);
+
+	fsleep(TLE493D_RESET_DELAY_US);
+}

[Severity: Medium]
Should tle493d_reset() hold the I2C segment lock across all four reset frames?

i2c_smbus_xfer() acquires and releases I2C_LOCK_SEGMENT on each call, so another driver on the adapter can interleave a transfer between frames and silently break the reset sequence.

If the sensor fails to reset and retains a non-zero MOD2.PRD, tle493d_init() computes FP assuming MOD2.PRD is 0 and can write a bad parity bit that drops the sensor off the bus.

Locking with i2c_lock_bus(adap, I2C_LOCK_SEGMENT) around four __i2c_smbus_xfer() calls and unlocking with i2c_unlock_bus() would keep the sequence contiguous on the bus.

[ ... ]

Quoted 2 lines
drivers/iio/magnetometer/tle493d.c new file +2 -0
+static int tle493d_probe(struct i2c_client *client)
+{

[ ... ]

drivers/iio/magnetometer/tle493d.c line 532

Quoted 3 lines
drivers/iio/magnetometer/tle493d.c new file +3 -0
+	ret = devm_regulator_get_enable(dev, "vdd");
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to enable vdd regulator\n");

[Severity: Medium]
Does tle493d_probe() need a power-on startup delay after enabling the vdd regulator?

devm_regulator_get_enable() only waits for the regulator's own ramp time, not the sensor's internal power-on reset and fuse-loading startup (~250 us).

When vdd is cold-enabled, especially on adapters without I2C_FUNC_SMBUS_QUICK where tle493d_reset() returns with no delay, the single non-retried MOD1 write in tle493d_init() can get a NACK and fail probe.

drivers/iio/magnetometer/tle493d.c line 536

Quoted 4 lines
drivers/iio/magnetometer/tle493d.c new file +4 -0
+
+	tle493d_reset(data);
+
+	ret = tle493d_init(data, iicadr);

[Severity: High]
Will calling tle493d_reset() on every probe break already-probed TLE493D sensors sharing the same I2C bus?

The driver supports all four factory address variants in tle493d_i2c_addrs[], but tle493d_reset() sends unaddressed broadcast frames (0x7f and general-call 0x00) that hardware-reset every TLE493D on the bus.

When a second sensor probes, it resets any already-initialized sibling back to power-on defaults (PR=0, CA=0, INT=0, non-master mode), disrupting any in-flight measurement and re-enabling /INT pulses on the shared SCL pin.

Because tle493d_measure() only rewrites Config and never restores MOD1, previously probed sibling sensors stay permanently broken while only the last-probed instance remains configured.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Reviewed-by on v3 2/2
#4 lore raw

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

In reply to Viral Patel
Quoted 12 lines · Viral Patel

Add a driver for a 3-axis Hall effect magnetometer with 12-bit resolution and a built-in temperature sensor. Communication is via I2C.

The driver runs the sensor in master-controlled mode. As /INT is combined with the SCL pin, the interrupt and clock stretching are turned off.

Communication uses raw I2C transfers rather than regmap. Once the PR bit has been set, a plain read always begins at register 0x00, and the register address byte of a write also carries trigger bits.

Channel data can be read through sysfs and through a triggered buffer.

...

drivers/iio/magnetometer/tle493d.c line 295

Quoted 3 lines
drivers/iio/magnetometer/tle493d.c new file +3 -0
+static int tle493d_read_raw(struct iio_dev *indio_dev,
+			    const struct iio_chan_spec *chan, int *val,
+			    int *val2, long mask)

Wrap logically

static int tle493d_read_raw(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan, int *val, int *val2, long mask)

...

drivers/iio/magnetometer/tle493d.c line 436

Quoted 12 lines
drivers/iio/magnetometer/tle493d.c new file +12 -0
+static void tle493d_reset(struct tle493d_data *data)
+{
+	struct i2c_adapter *adap = data->client->adapter;
+	static const struct {
+		u16 addr;
+		char read_write;
+	} frames[] = {
+		{ 0x7f, I2C_SMBUS_READ },
+		{ 0x7f, I2C_SMBUS_READ },
+		{ 0x00, I2C_SMBUS_WRITE },
+		{ 0x00, I2C_SMBUS_WRITE },
+	};

No need, see below how.

drivers/iio/magnetometer/tle493d.c line 446

Quoted 9 lines
drivers/iio/magnetometer/tle493d.c new file +9 -0
+	if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) {
+		dev_dbg(&data->client->dev, "adapter cannot send the reset sequence\n");
+		return;
+	}
+
+	/* The reset frames are not acknowledged, so ignore the return values */
+	for (unsigned int i = 0; i < ARRAY_SIZE(frames); i++)
+		i2c_smbus_xfer(adap, frames[i].addr, 0, frames[i].read_write, 0,
+			       I2C_SMBUS_QUICK, NULL);

You don't need the above table, just do two loops:

	for (unsigned int i = 0; i < 2; i++)
		i2c_smbus_xfer(adap, 0x7f, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_QUICK, NULL);
	for (unsigned int i = 0; i < 2; i++)
		i2c_smbus_xfer(adap, 0x00, 0, I2C_SMBUS_WRITE, 0, I2C_SMBUS_QUICK, NULL);

The comment has to explain double reads and writes

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

...

Quoted 11 lines
drivers/iio/magnetometer/tle493d.c new file +11 -0
+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.

drivers/iio/magnetometer/tle493d.c line 471

Quoted 10 lines
drivers/iio/magnetometer/tle493d.c new file +10 -0
+	 * Clock stretching and the interrupt are disabled because /INT shares
+	 * the SCL pin.
+	 *
+	 * Every MOD1 write also sets IICadr, which selects the address the
+	 * sensor responds on, so it must match the address the device is
+	 * already on or the sensor moves to another address.
+	 */
+	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);

Rewrap to improve readability:

	mod1 = FIELD_PREP(TLE493D_MOD1_MODE, TLE493D_MOD1_MODE_MASTER) |
	       FIELD_PREP(TLE493D_MOD1_IICADR, iicadr) |
	       TLE493D_MOD1_PR | TLE493D_MOD1_CA | TLE493D_MOD1_INT;
Quoted 16 lines
drivers/iio/magnetometer/tle493d.c new file +16 -0
+	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);
+

drivers/iio/magnetometer/tle493d.c line 497

Quoted 10 lines
drivers/iio/magnetometer/tle493d.c new file +10 -0
+	/*
+	 * 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;
+}

...

With the above being addressed, feel free to add

Signature · 2 lines
With Best Regards,
Andy Shevchenko