Devicetree
 help / color / mirror / Atom feed
* [PATCH v3 0/2] iio: magnetometer: add Infineon TLE493D-W2B6 support
@ 2026-12-05  7:21 Viral Patel
  2026-12-05  7:21 ` [PATCH v3 1/2] dt-bindings: iio: magnetometer: infineon,tlv493d-a1b6: add TLE493D-W2B6 Viral Patel
  2026-12-05  7:21 ` [PATCH v3 2/2] iio: magnetometer: add Infineon TLE493D-W2B6 driver Viral Patel
  0 siblings, 2 replies; 4+ messages in thread
From: Viral Patel @ 2026-12-05  7:21 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Dixit Parmar
  Cc: Victor Chernyakin, linux-iio, devicetree, linux-kernel,
	Viral Patel

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/atyPf0msZ85z2m19@ashevche-desk.local/

Signed-off-by: Viral Patel <viral8854@gmail.com>
---
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/20261121-tle493d-v2-0-92d7e57cec89@gmail.com

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/20261105-tle493d-v1-0-3246e91e6394@gmail.com

---
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,
-- 
Viral Patel <viral8854@gmail.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-05  7:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05  7:21 [PATCH v3 0/2] iio: magnetometer: add Infineon TLE493D-W2B6 support Viral Patel
2026-12-05  7:21 ` [PATCH v3 1/2] dt-bindings: iio: magnetometer: infineon,tlv493d-a1b6: add TLE493D-W2B6 Viral Patel
2026-12-05  7:21 ` [PATCH v3 2/2] iio: magnetometer: add Infineon TLE493D-W2B6 driver Viral Patel
2026-12-05  7:37   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox