Skip to contentSkip to conversation

iio: magnetometer: add support for Si7210

PATCH Applied Antoni Pokusinski 2 participants 4 messages Jan 20, 2025 – Jan 25, 2025

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

v5 cover iio: magnetometer: add support for Si7210

This patch series adds support for the Si7210 Hall effect I2C sensor. The driver currently supports the basic functionalities (i.e. making temperature and magnetic field measurements and changing the measurements scale) but I plan to add support for some other features in the future as well (e.g. the digital output interrupt).

---
Hi all,
In this version I add only some minor tweaks and comments (for the temperature calculation) according to the latest review. Everything else was left intact.

Kind regards,
Antoni

Changes since v4:
* Makefile: replace spaces/tabs mixture with tabs only
* si7210: includes: move asm/byteorder.h to the end
* si7210: read_raw: add comments for temperature calculation

Changes since v3:
* si7210: fetch_measurement/read_raw: fix issue with endianess
* si7210: replace if (ret < 0) with if (ret) wherever possible
* si7210: read_raw: use SI metric prefixes (MICRO, MILLI)
* si7210: si7210_data: swap i2c_client with regmap
* si7210: read_otpreg_val: remove unnecessary cast
* si7210: minor formatting updates
(add missing trailing commas, spaces etc)
* si7210: probe: use devm_mutex_init
* si7210: add missing includes

Changes since v2:
* Makefile: fix alignment
* si7210: fetch_measurement: use temporary variable to read the measurement instead of reading directly to buf
* si7210: read_raw: change tmp to temp
* si7210: read_raw: adjust temperature computation to match the spec better
* si7210: device_wake: do not init ret to 0
* si7210: MODULE_LICENSE: change license type to GPL
* si7210: minor improvements in comments

Changes since v1:
* dt-binding: add vdd-supply
* si7210: reorder includes in alphabetic order
* si7210: add comment for fetch_lock
* si7210: remove otp_lock
* si7210: fetch_measurement: change result type to __be16
* si7210: use guard(mutex) instead of scoped_guard
* si7210: read_raw: use FIELD_GET to get raw temperature value
* si7210: read_raw: return temperature in milli-celsius
* si7210: use regulator for getting the voltage
* si7210: si7210_device_wake: remove unnecessary cast
* si7210: si7210_device_init: use fsleep instead of usleep_range
* si7210: si7210_probe: remove i2c_set_clientdata()
* si7210: minor alignment and formatting fixes

Antoni Pokusinski (2):
dt-bindings: iio: magnetometer: add binding for Si7210
iio: magnetometer: si7210: add driver for Si7210

 .../iio/magnetometer/silabs,si7210.yaml       |  48 ++
 drivers/iio/magnetometer/Kconfig              |  11 +
 drivers/iio/magnetometer/Makefile             |   2 +
 drivers/iio/magnetometer/si7210.c             | 446 ++++++++++++++++++
 4 files changed, 507 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/magnetometer/silabs,si7210.yaml
 create mode 100644 drivers/iio/magnetometer/si7210.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH v5 1/2 dt-bindings: iio: magnetometer: add binding for Si7210

Silicon Labs Si7210 is an I2C Hall effect magnetic position and temperature sensor.

---
 .../iio/magnetometer/silabs,si7210.yaml       | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/magnetometer/silabs,si7210.yaml
Documentation/devicetree/bindings/iio/magnetometer/silabs,si7210.yaml new file +48 -0
new file mode 100644
index 000000000000..d4a3f7981c36
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/magnetometer/silabs,si7210.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Si7210 magnetic position and temperature sensor
+
+maintainers:
+  - Antoni Pokusinski <[email protected]>
+
+description: |
+  Silabs Si7210 I2C Hall effect magnetic position and temperature sensor.
+  https://www.silabs.com/documents/public/data-sheets/si7210-datasheet.pdf
+
+properties:
+  compatible:
+    const: silabs,si7210
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  vdd-supply:
+    description: Regulator that provides power to the sensor
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        magnetometer@30 {
+            compatible = "silabs,si7210";
+            reg = <0x30>;
+            interrupt-parent = <&gpio1>;
+            interrupts = <4 IRQ_TYPE_EDGE_FALLING>;
+            vdd-supply = <&vdd_3v3_reg>;
+        };
+    };
Signature · 1 line
2.25.1
#2 lore raw

PATCH v5 2/2 iio: magnetometer: si7210: add driver for Si7210

In reply to Antoni Pokusinski

Silicon Labs Si7210 is an I2C Hall effect magnetic position and temperature sensor. The driver supports the following functionalities:
* reading the temperature measurements
* reading the magnetic field measurements in a single-shot mode
* choosing the magnetic field measurement scale (20 or 200 mT)

---
 drivers/iio/magnetometer/Kconfig  |  11 +
 drivers/iio/magnetometer/Makefile |   2 +
 drivers/iio/magnetometer/si7210.c | 446 ++++++++++++++++++++++++++++++
 3 files changed, 459 insertions(+)
 create mode 100644 drivers/iio/magnetometer/si7210.c
drivers/iio/magnetometer/Kconfig +11 -0
index 7177cd1d67cb..3debf1320ad1 100644
@@ -235,6 +235,17 @@ config SENSORS_RM3100_SPI
 	  To compile this driver as a module, choose M here: the module
 	  will be called rm3100-spi.
 
+config SI7210
+	tristate "SI7210 Hall effect sensor"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  Say Y here to add support for the SI7210 Hall effect 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 si7210.
+
 config TI_TMAG5273
 	tristate "TI TMAG5273 Low-Power Linear 3D Hall-Effect Sensor"
 	depends on I2C
drivers/iio/magnetometer/Makefile +2 -0
index 3e4c2ecd9adf..9297723a97d8 100644
@@ -31,6 +31,8 @@ obj-$(CONFIG_SENSORS_RM3100)		+= rm3100-core.o
 obj-$(CONFIG_SENSORS_RM3100_I2C)	+= rm3100-i2c.o
 obj-$(CONFIG_SENSORS_RM3100_SPI)	+= rm3100-spi.o
 
+obj-$(CONFIG_SI7210)			+= si7210.o
+
 obj-$(CONFIG_TI_TMAG5273)		+= tmag5273.o
 
 obj-$(CONFIG_YAMAHA_YAS530)		+= yamaha-yas530.o
drivers/iio/magnetometer/si7210.c new file +446 -0

446 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer Applied
#3 lore raw
In reply to Antoni Pokusinski
Quoted 11 lines · On Mon, 20 Jan 2025 22:56:18 +0100 Antoni Pokusinski <[email protected]>…

This patch series adds support for the Si7210 Hall effect I2C sensor. The driver currently supports the basic functionalities (i.e. making temperature and magnetic field measurements and changing the measurements scale) but I plan to add support for some other features in the future as well (e.g. the digital output interrupt).

---
Hi all,
In this version I add only some minor tweaks and comments (for the temperature calculation) according to the latest review. Everything else was left intact.

Applied to the togreg branch of iio.git but initially only pushed out as testing because I'll rebase on rc1 once available in about a week.

Thanks,

Jonathan