All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v1 1/2] dt-bindings: iio: imu: Add QST QMI8658C
       [not found] <20261204085504.184447-1-nanami@yosoro.hk>
@ 2026-12-04  8:55 ` NanamiKite
  2026-12-05 15:32   ` Krzysztof Kozlowski
  2026-12-04  8:55 ` [RFC PATCH v1 2/2] iio: imu: Add driver for " NanamiKite
  1 sibling, 1 reply; 8+ messages in thread
From: NanamiKite @ 2026-12-04  8:55 UTC (permalink / raw)
  To: Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
	devicetree, linux-kernel, NanamiKite

Add DT binding documentation for the QST QMI8658C 6-axis IMU over I2C.

Signed-off-by: NanamiKite <nanami@yosoro.hk>
---
 .../bindings/iio/imu/qstcorp,qmi8658c.yaml    | 71 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 2 files changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/qstcorp,qmi8658c.yaml

diff --git a/Documentation/devicetree/bindings/iio/imu/qstcorp,qmi8658c.yaml b/Documentation/devicetree/bindings/iio/imu/qstcorp,qmi8658c.yaml
new file mode 100644
index 000000000..e69fa82f7
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/imu/qstcorp,qmi8658c.yaml
@@ -0,0 +1,71 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/imu/qstcorp,qmi8658c.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: QST QMI8658C 6-Axis Inertial Measurement Unit
+
+maintainers:
+  - NanamiKite <nanami@yosoro.hk>
+
+description: |
+  QST QMI8658C is a 6-axis inertial measurement unit integrating a 3-axis
+  accelerometer, a 3-axis gyroscope, and an internal temperature sensor,
+  connected via an I2C bus.
+  https://qstcorp.com/upload/pdf/202202/QMI8658C%20datasheet%20rev%200.9.pdf
+
+properties:
+  compatible:
+    const: qstcorp,qmi8658c
+
+  reg:
+    maxItems: 1
+
+  vdd-supply: true
+  vddio-supply: true
+
+  interrupts:
+    minItems: 1
+    maxItems: 2
+
+  interrupt-names:
+    minItems: 1
+    maxItems: 2
+    items:
+      enum:
+        - INT1
+        - INT2
+
+  mount-matrix: true
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+  - vddio-supply
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        imu@6a {
+            compatible = "qstcorp,qmi8658c";
+            reg = <0x6a>;
+            vdd-supply = <&vdd_3v3>;
+            vddio-supply = <&vddio_1v8>;
+            interrupt-parent = <&gpio0>;
+            interrupts = <4 IRQ_TYPE_EDGE_RISING>;
+            interrupt-names = "INT1";
+            mount-matrix = "1", "0", "0",
+                           "0", "1", "0",
+                           "0", "0", "1";
+        };
+    };
+...
diff --git a/MAINTAINERS b/MAINTAINERS
index ee1adff49..2166f80a0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -23143,6 +23143,12 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/iio/magnetometer/qstcorp,qmc6308.yaml
 F:	drivers/iio/magnetometer/qmc6308.c
 
+QST QMI8658C 6-AXIS IMU DRIVER
+M:	NanamiKite <nanami@yosoro.hk>
+L:	linux-iio@vger.kernel.org
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/imu/qstcorp,qmi8658c.yaml
+
 QT1010 MEDIA DRIVER
 L:	linux-media@vger.kernel.org
 S:	Orphan
-- 
2.56.1


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

* [RFC PATCH v1 2/2] iio: imu: Add driver for QST QMI8658C
       [not found] <20261204085504.184447-1-nanami@yosoro.hk>
  2026-12-04  8:55 ` [RFC PATCH v1 1/2] dt-bindings: iio: imu: Add QST QMI8658C NanamiKite
@ 2026-12-04  8:55 ` NanamiKite
  2026-12-04  9:10   ` sashiko-bot
                     ` (2 more replies)
  1 sibling, 3 replies; 8+ messages in thread
From: NanamiKite @ 2026-12-04  8:55 UTC (permalink / raw)
  To: Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
	devicetree, linux-kernel, NanamiKite

Add an I2C IIO driver for the QST QMI8658C 6-axis IMU, supporting
3-axis accelerometer, 3-axis gyroscope, and die temperature reads, along
with scale, 6DOF ODR configuration, and mount-matrix.

Signed-off-by: NanamiKite <nanami@yosoro.hk>
---
 MAINTAINERS               |   1 +
 drivers/iio/imu/Kconfig   |  12 +
 drivers/iio/imu/Makefile  |   2 +
 drivers/iio/imu/qmi8658.c | 622 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 637 insertions(+)
 create mode 100644 drivers/iio/imu/qmi8658.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 2166f80a0..72007981e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -23148,6 +23148,7 @@ M:	NanamiKite <nanami@yosoro.hk>
 L:	linux-iio@vger.kernel.org
 S:	Maintained
 F:	Documentation/devicetree/bindings/iio/imu/qstcorp,qmi8658c.yaml
+F:	drivers/iio/imu/qmi8658.c
 
 QT1010 MEDIA DRIVER
 L:	linux-media@vger.kernel.org
diff --git a/drivers/iio/imu/Kconfig b/drivers/iio/imu/Kconfig
index 8bab4616b..7bfb891c3 100644
--- a/drivers/iio/imu/Kconfig
+++ b/drivers/iio/imu/Kconfig
@@ -113,6 +113,18 @@ source "drivers/iio/imu/inv_icm42607/Kconfig"
 source "drivers/iio/imu/inv_icm45600/Kconfig"
 source "drivers/iio/imu/inv_mpu6050/Kconfig"
 
+config QMI8658
+	tristate "QST QMI8658C 6-Axis IMU"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  Say yes here to build support for the QST QMI8658C 6-axis inertial
+	  measurement unit (3-axis accelerometer, 3-axis gyroscope, and
+	  on-chip temperature sensor) connected via I2C.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called qmi8658.
+
 config SMI240
 	tristate "Bosch Sensor SMI240 Inertial Measurement Unit"
 	depends on SPI
diff --git a/drivers/iio/imu/Makefile b/drivers/iio/imu/Makefile
index 3268dc237..898fdb1ed 100644
--- a/drivers/iio/imu/Makefile
+++ b/drivers/iio/imu/Makefile
@@ -31,6 +31,8 @@ obj-y += inv_mpu6050/
 
 obj-$(CONFIG_KMX61) += kmx61.o
 
+obj-$(CONFIG_QMI8658) += qmi8658.o
+
 obj-$(CONFIG_SMI240) += smi240.o
 
 obj-y += smi330/
diff --git a/drivers/iio/imu/qmi8658.c b/drivers/iio/imu/qmi8658.c
new file mode 100644
index 000000000..6ccb67dcf
--- /dev/null
+++ b/drivers/iio/imu/qmi8658.c
@@ -0,0 +1,622 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * QST QMI8658C 6-axis IMU (3-axis accelerometer, 3-axis gyroscope, temperature)
+ *
+ * Datasheet:
+ * https://qstcorp.com/upload/pdf/202202/QMI8658C%20datasheet%20rev%200.9.pdf
+ */
+
+#include <linux/array_size.h>
+#include <linux/bitfield.h>
+#include <linux/bits.h>
+#include <linux/byteorder/generic.h>
+#include <linux/cleanup.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/types.h>
+#include <linux/units.h>
+
+#include <linux/iio/iio.h>
+
+#define QMI8658_REG_WHO_AM_I		0x00
+#define QMI8658_REG_REVISION_ID		0x01
+#define QMI8658_REG_CTRL1		0x02
+#define QMI8658_REG_CTRL2		0x03
+#define QMI8658_REG_CTRL3		0x04
+#define QMI8658_REG_CTRL7		0x08
+#define QMI8658_REG_CTRL9		0x0a
+#define QMI8658_REG_STATUSINT		0x2d
+#define QMI8658_REG_TEMP_L		0x33
+#define QMI8658_REG_AX_L		0x35
+#define QMI8658_REG_AY_L		0x37
+#define QMI8658_REG_AZ_L		0x39
+#define QMI8658_REG_GX_L		0x3b
+#define QMI8658_REG_GY_L		0x3d
+#define QMI8658_REG_GZ_L		0x3f
+#define QMI8658_REG_GZ_H		0x40
+#define QMI8658_REG_RESET		0x60
+
+#define QMI8658_CTRL1_ADDR_AI		BIT(6)
+#define QMI8658_CTRL1_SENSOR_DISABLE	BIT(0)
+
+#define QMI8658_CTRL2_ACCEL_FS_MASK	GENMASK(6, 4)
+#define QMI8658_CTRL2_ACCEL_ODR_MASK	GENMASK(3, 0)
+
+#define QMI8658_CTRL3_GYRO_FS_MASK	GENMASK(6, 4)
+#define QMI8658_CTRL3_GYRO_ODR_MASK	GENMASK(3, 0)
+
+#define QMI8658_CTRL7_GYRO_EN		BIT(1)
+#define QMI8658_CTRL7_ACCEL_EN		BIT(0)
+
+#define QMI8658_WHO_AM_I_VAL		0x05
+#define QMI8658_RESET_CMD		0xb0
+
+#define QMI8658_RESET_DELAY_MS		150
+#define QMI8658_STARTUP_DELAY_MS	80
+
+#define QMI8658_TEMP_SENSITIVITY	256
+#define QMI8658_ODR_6DOF_MIN_REG	8
+
+#define QMI8658_DEFAULT_ACCEL_FS_IDX	0 /* +/-2 g */
+#define QMI8658_DEFAULT_GYRO_FS_IDX	4 /* +/-256 dps */
+#define QMI8658_DEFAULT_ODR_IDX		3 /* 235 Hz */
+
+struct qmi8658_data {
+	struct device *dev;
+	struct regmap *regmap;
+	struct mutex lock; /* Protect register RMW and cached config state */
+	struct iio_mount_matrix orientation;
+	unsigned int accel_fs_idx;
+	unsigned int gyro_fs_idx;
+	unsigned int accel_odr_idx;
+	unsigned int gyro_odr_idx;
+};
+
+static const char * const qmi8658_regulators[] = {
+	"vdd",
+	"vddio",
+};
+
+/*
+ * Accelerometer full-scale sensitivity: 16384, 8192, 4096, 2048 LSB/g.
+ * Values in m/s^2 per LSB (9.80665 / sensitivity) in ascending order.
+ */
+static const int qmi8658_accel_scales[][2] = {
+	{ 0, 598550 },	/* +/-2 g */
+	{ 0, 1197101 },	/* +/-4 g */
+	{ 0, 2394202 },	/* +/-8 g */
+	{ 0, 4788403 },	/* +/-16 g */
+};
+
+/*
+ * Gyroscope full-scale sensitivity: 2048 .. 16 LSB/dps.
+ * Values in rad/s per LSB ((pi / 180) / sensitivity) in ascending order.
+ */
+static const int qmi8658_gyro_scales[][2] = {
+	{ 0, 8522 },	/* +/-16 dps */
+	{ 0, 17044 },	/* +/-32 dps */
+	{ 0, 34088 },	/* +/-64 dps */
+	{ 0, 68177 },	/* +/-128 dps */
+	{ 0, 136354 },	/* +/-256 dps */
+	{ 0, 272708 },	/* +/-512 dps */
+	{ 0, 545415 },	/* +/-1024 dps */
+	{ 0, 1090831 },	/* +/-2048 dps */
+};
+
+/*
+ * 6DOF Output Data Rates (Hz) in ascending order.
+ * Index i maps to register field (QMI8658_ODR_6DOF_MIN_REG - i).
+ */
+static const int qmi8658_samp_freqs[][2] = {
+	{ 29, 375000 },
+	{ 58, 750000 },
+	{ 117, 500000 },
+	{ 235, 0 },
+	{ 470, 0 },
+	{ 940, 0 },
+	{ 1880, 0 },
+	{ 3760, 0 },
+	{ 7520, 0 },
+};
+
+static const struct regmap_range qmi8658_rd_ranges[] = {
+	regmap_reg_range(QMI8658_REG_WHO_AM_I, QMI8658_REG_CTRL9),
+	regmap_reg_range(QMI8658_REG_STATUSINT, QMI8658_REG_GZ_H),
+};
+
+static const struct regmap_access_table qmi8658_rd_table = {
+	.yes_ranges = qmi8658_rd_ranges,
+	.n_yes_ranges = ARRAY_SIZE(qmi8658_rd_ranges),
+};
+
+static const struct regmap_range qmi8658_wr_ranges[] = {
+	regmap_reg_range(QMI8658_REG_CTRL1, QMI8658_REG_CTRL9),
+	regmap_reg_range(QMI8658_REG_RESET, QMI8658_REG_RESET),
+};
+
+static const struct regmap_access_table qmi8658_wr_table = {
+	.yes_ranges = qmi8658_wr_ranges,
+	.n_yes_ranges = ARRAY_SIZE(qmi8658_wr_ranges),
+};
+
+static const struct regmap_config qmi8658_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = QMI8658_REG_RESET,
+	.rd_table = &qmi8658_rd_table,
+	.wr_table = &qmi8658_wr_table,
+};
+
+static const struct iio_mount_matrix *
+qmi8658_get_mount_matrix(const struct iio_dev *indio_dev,
+			 const struct iio_chan_spec *chan)
+{
+	struct qmi8658_data *data = iio_priv(indio_dev);
+
+	return &data->orientation;
+}
+
+static const struct iio_chan_spec_ext_info qmi8658_ext_info[] = {
+	IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, qmi8658_get_mount_matrix),
+	{ }
+};
+
+#define QMI8658_CHANNEL(_type, _axis, _reg) {				\
+	.type = _type,							\
+	.modified = 1,							\
+	.channel2 = IIO_MOD_##_axis,					\
+	.address = _reg,						\
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),			\
+	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |		\
+				    BIT(IIO_CHAN_INFO_SAMP_FREQ),	\
+	.info_mask_shared_by_type_available =				\
+		BIT(IIO_CHAN_INFO_SCALE) |				\
+		BIT(IIO_CHAN_INFO_SAMP_FREQ),				\
+	.ext_info = qmi8658_ext_info,					\
+}
+
+static const struct iio_chan_spec qmi8658_channels[] = {
+	QMI8658_CHANNEL(IIO_ACCEL, X, QMI8658_REG_AX_L),
+	QMI8658_CHANNEL(IIO_ACCEL, Y, QMI8658_REG_AY_L),
+	QMI8658_CHANNEL(IIO_ACCEL, Z, QMI8658_REG_AZ_L),
+	QMI8658_CHANNEL(IIO_ANGL_VEL, X, QMI8658_REG_GX_L),
+	QMI8658_CHANNEL(IIO_ANGL_VEL, Y, QMI8658_REG_GY_L),
+	QMI8658_CHANNEL(IIO_ANGL_VEL, Z, QMI8658_REG_GZ_L),
+	{
+		.type = IIO_TEMP,
+		.address = QMI8658_REG_TEMP_L,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+				      BIT(IIO_CHAN_INFO_SCALE),
+	},
+};
+
+static int qmi8658_find_table_idx(const int table[][2], size_t len,
+				  int val, int val2)
+{
+	size_t i;
+
+	for (i = 0; i < len; i++) {
+		if (table[i][0] == val && table[i][1] == val2)
+			return i;
+	}
+
+	return -EINVAL;
+}
+
+static int qmi8658_read_raw_val(struct qmi8658_data *data,
+				const struct iio_chan_spec *chan, int *val)
+{
+	__le16 raw;
+	int ret;
+
+	guard(mutex)(&data->lock);
+
+	ret = regmap_bulk_read(data->regmap, chan->address, &raw, sizeof(raw));
+	if (ret)
+		return ret;
+
+	*val = (s16)le16_to_cpu(raw);
+	return IIO_VAL_INT;
+}
+
+static int qmi8658_read_raw(struct iio_dev *indio_dev,
+			    const struct iio_chan_spec *chan,
+			    int *val, int *val2, long mask)
+{
+	struct qmi8658_data *data = iio_priv(indio_dev);
+	unsigned int idx;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		switch (chan->type) {
+		case IIO_ACCEL:
+		case IIO_ANGL_VEL:
+		case IIO_TEMP:
+			return qmi8658_read_raw_val(data, chan, val);
+		default:
+			return -EINVAL;
+		}
+	case IIO_CHAN_INFO_SCALE:
+		switch (chan->type) {
+		case IIO_ACCEL: {
+			guard(mutex)(&data->lock);
+			idx = data->accel_fs_idx;
+			*val = qmi8658_accel_scales[idx][0];
+			*val2 = qmi8658_accel_scales[idx][1];
+			return IIO_VAL_INT_PLUS_NANO;
+		}
+		case IIO_ANGL_VEL: {
+			guard(mutex)(&data->lock);
+			idx = data->gyro_fs_idx;
+			*val = qmi8658_gyro_scales[idx][0];
+			*val2 = qmi8658_gyro_scales[idx][1];
+			return IIO_VAL_INT_PLUS_NANO;
+		}
+		case IIO_TEMP:
+			*val = MILLI;
+			*val2 = QMI8658_TEMP_SENSITIVITY;
+			return IIO_VAL_FRACTIONAL;
+		default:
+			return -EINVAL;
+		}
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		switch (chan->type) {
+		case IIO_ACCEL: {
+			guard(mutex)(&data->lock);
+			idx = data->accel_odr_idx;
+			*val = qmi8658_samp_freqs[idx][0];
+			*val2 = qmi8658_samp_freqs[idx][1];
+			return IIO_VAL_INT_PLUS_MICRO;
+		}
+		case IIO_ANGL_VEL: {
+			guard(mutex)(&data->lock);
+			idx = data->gyro_odr_idx;
+			*val = qmi8658_samp_freqs[idx][0];
+			*val2 = qmi8658_samp_freqs[idx][1];
+			return IIO_VAL_INT_PLUS_MICRO;
+		}
+		default:
+			return -EINVAL;
+		}
+	default:
+		return -EINVAL;
+	}
+}
+
+static int qmi8658_update_locked(struct qmi8658_data *data, unsigned int reg,
+				 unsigned int mask, unsigned int reg_val,
+				 unsigned int *target, unsigned int idx)
+{
+	int ret;
+
+	guard(mutex)(&data->lock);
+
+	ret = regmap_update_bits(data->regmap, reg, mask, reg_val);
+	if (ret)
+		return ret;
+
+	*target = idx;
+	return 0;
+}
+
+static int qmi8658_set_scale(struct qmi8658_data *data, enum iio_chan_type type,
+			     int val, int val2)
+{
+	unsigned int *target;
+	unsigned int reg_val;
+	unsigned int mask;
+	unsigned int reg;
+	int idx;
+
+	switch (type) {
+	case IIO_ACCEL:
+		idx = qmi8658_find_table_idx(qmi8658_accel_scales,
+					     ARRAY_SIZE(qmi8658_accel_scales),
+					     val, val2);
+		if (idx < 0)
+			return idx;
+
+		reg = QMI8658_REG_CTRL2;
+		mask = QMI8658_CTRL2_ACCEL_FS_MASK;
+		reg_val = FIELD_PREP(QMI8658_CTRL2_ACCEL_FS_MASK, idx);
+		target = &data->accel_fs_idx;
+		break;
+	case IIO_ANGL_VEL:
+		idx = qmi8658_find_table_idx(qmi8658_gyro_scales,
+					     ARRAY_SIZE(qmi8658_gyro_scales),
+					     val, val2);
+		if (idx < 0)
+			return idx;
+
+		reg = QMI8658_REG_CTRL3;
+		mask = QMI8658_CTRL3_GYRO_FS_MASK;
+		reg_val = FIELD_PREP(QMI8658_CTRL3_GYRO_FS_MASK, idx);
+		target = &data->gyro_fs_idx;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return qmi8658_update_locked(data, reg, mask, reg_val, target, idx);
+}
+
+static int qmi8658_set_samp_freq(struct qmi8658_data *data,
+				 enum iio_chan_type type, int val, int val2)
+{
+	unsigned int odr_field;
+	unsigned int *target;
+	unsigned int reg_val;
+	unsigned int mask;
+	unsigned int reg;
+	int idx;
+
+	idx = qmi8658_find_table_idx(qmi8658_samp_freqs,
+				     ARRAY_SIZE(qmi8658_samp_freqs),
+				     val, val2);
+	if (idx < 0)
+		return idx;
+
+	odr_field = QMI8658_ODR_6DOF_MIN_REG - idx;
+
+	switch (type) {
+	case IIO_ACCEL:
+		reg = QMI8658_REG_CTRL2;
+		mask = QMI8658_CTRL2_ACCEL_ODR_MASK;
+		reg_val = FIELD_PREP(QMI8658_CTRL2_ACCEL_ODR_MASK, odr_field);
+		target = &data->accel_odr_idx;
+		break;
+	case IIO_ANGL_VEL:
+		reg = QMI8658_REG_CTRL3;
+		mask = QMI8658_CTRL3_GYRO_ODR_MASK;
+		reg_val = FIELD_PREP(QMI8658_CTRL3_GYRO_ODR_MASK, odr_field);
+		target = &data->gyro_odr_idx;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return qmi8658_update_locked(data, reg, mask, reg_val, target, idx);
+}
+
+static int qmi8658_write_raw(struct iio_dev *indio_dev,
+			     const struct iio_chan_spec *chan,
+			     int val, int val2, long mask)
+{
+	struct qmi8658_data *data = iio_priv(indio_dev);
+
+	switch (mask) {
+	case IIO_CHAN_INFO_SCALE:
+		return qmi8658_set_scale(data, chan->type, val, val2);
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		return qmi8658_set_samp_freq(data, chan->type, val, val2);
+	default:
+		return -EINVAL;
+	}
+}
+
+static int qmi8658_write_raw_get_fmt(struct iio_dev *indio_dev,
+				     const struct iio_chan_spec *chan,
+				     long mask)
+{
+	switch (mask) {
+	case IIO_CHAN_INFO_SCALE:
+		return IIO_VAL_INT_PLUS_NANO;
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		return IIO_VAL_INT_PLUS_MICRO;
+	default:
+		return -EINVAL;
+	}
+}
+
+static int qmi8658_read_avail(struct iio_dev *indio_dev,
+			      const struct iio_chan_spec *chan,
+			      const int **vals, int *type, int *length,
+			      long mask)
+{
+	switch (mask) {
+	case IIO_CHAN_INFO_SCALE:
+		switch (chan->type) {
+		case IIO_ACCEL:
+			*vals = (const int *)qmi8658_accel_scales;
+			*type = IIO_VAL_INT_PLUS_NANO;
+			*length = ARRAY_SIZE(qmi8658_accel_scales) * 2;
+			return IIO_AVAIL_LIST;
+		case IIO_ANGL_VEL:
+			*vals = (const int *)qmi8658_gyro_scales;
+			*type = IIO_VAL_INT_PLUS_NANO;
+			*length = ARRAY_SIZE(qmi8658_gyro_scales) * 2;
+			return IIO_AVAIL_LIST;
+		default:
+			return -EINVAL;
+		}
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		switch (chan->type) {
+		case IIO_ACCEL:
+		case IIO_ANGL_VEL:
+			*vals = (const int *)qmi8658_samp_freqs;
+			*type = IIO_VAL_INT_PLUS_MICRO;
+			*length = ARRAY_SIZE(qmi8658_samp_freqs) * 2;
+			return IIO_AVAIL_LIST;
+		default:
+			return -EINVAL;
+		}
+	default:
+		return -EINVAL;
+	}
+}
+
+static const struct iio_info qmi8658_info = {
+	.read_raw = qmi8658_read_raw,
+	.write_raw = qmi8658_write_raw,
+	.write_raw_get_fmt = qmi8658_write_raw_get_fmt,
+	.read_avail = qmi8658_read_avail,
+};
+
+static void qmi8658_power_down(void *ctx)
+{
+	struct qmi8658_data *data = ctx;
+
+	regmap_write(data->regmap, QMI8658_REG_CTRL7, 0);
+	regmap_write(data->regmap, QMI8658_REG_CTRL1,
+		     QMI8658_CTRL1_SENSOR_DISABLE);
+}
+
+static int qmi8658_chip_init(struct qmi8658_data *data)
+{
+	unsigned int odr_reg;
+	unsigned int val;
+	int ret;
+
+	odr_reg = QMI8658_ODR_6DOF_MIN_REG - QMI8658_DEFAULT_ODR_IDX;
+
+	ret = regmap_read(data->regmap, QMI8658_REG_WHO_AM_I, &val);
+	if (ret)
+		return dev_err_probe(data->dev, ret,
+				     "Failed to read WHO_AM_I register\n");
+
+	if (val != QMI8658_WHO_AM_I_VAL)
+		dev_warn(data->dev, "Unexpected WHO_AM_I value: 0x%02x\n", val);
+
+	ret = regmap_read(data->regmap, QMI8658_REG_REVISION_ID, &val);
+	if (ret)
+		return dev_err_probe(data->dev, ret,
+				     "Failed to read REVISION_ID register\n");
+
+	dev_dbg(data->dev, "QMI8658 revision ID: 0x%02x\n", val);
+
+	/*
+	 * Ensure the internal 2 MHz oscillator is enabled before soft reset;
+	 * otherwise a reset written while SensorDisable=1 stays pending until
+	 * CTRL1 clears SensorDisable and then wipes CTRL1 back to 0x20.
+	 */
+	ret = regmap_clear_bits(data->regmap, QMI8658_REG_CTRL1,
+				QMI8658_CTRL1_SENSOR_DISABLE);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(data->regmap, QMI8658_REG_RESET, QMI8658_RESET_CMD);
+	if (ret)
+		return dev_err_probe(data->dev, ret, "Soft reset failed\n");
+
+	msleep(QMI8658_RESET_DELAY_MS);
+
+	/* Enable auto-increment and clear default big-endian bit */
+	ret = regmap_write(data->regmap, QMI8658_REG_CTRL1,
+			   QMI8658_CTRL1_ADDR_AI);
+	if (ret)
+		return ret;
+
+	data->accel_fs_idx = QMI8658_DEFAULT_ACCEL_FS_IDX;
+	data->gyro_fs_idx = QMI8658_DEFAULT_GYRO_FS_IDX;
+	data->accel_odr_idx = QMI8658_DEFAULT_ODR_IDX;
+	data->gyro_odr_idx = QMI8658_DEFAULT_ODR_IDX;
+
+	ret = regmap_write(data->regmap, QMI8658_REG_CTRL2,
+			   FIELD_PREP(QMI8658_CTRL2_ACCEL_FS_MASK,
+				      data->accel_fs_idx) |
+			   FIELD_PREP(QMI8658_CTRL2_ACCEL_ODR_MASK, odr_reg));
+	if (ret)
+		return ret;
+
+	ret = regmap_write(data->regmap, QMI8658_REG_CTRL3,
+			   FIELD_PREP(QMI8658_CTRL3_GYRO_FS_MASK,
+				      data->gyro_fs_idx) |
+			   FIELD_PREP(QMI8658_CTRL3_GYRO_ODR_MASK, odr_reg));
+	if (ret)
+		return ret;
+
+	/* Enable both accelerometer and gyroscope for consistent 6DOF ODRs */
+	ret = regmap_write(data->regmap, QMI8658_REG_CTRL7,
+			   QMI8658_CTRL7_ACCEL_EN | QMI8658_CTRL7_GYRO_EN);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(data->dev, qmi8658_power_down, data);
+	if (ret)
+		return ret;
+
+	msleep(QMI8658_STARTUP_DELAY_MS);
+
+	return 0;
+}
+
+static int qmi8658_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct iio_dev *indio_dev;
+	struct qmi8658_data *data;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	data = iio_priv(indio_dev);
+	data->dev = dev;
+
+	data->regmap = devm_regmap_init_i2c(client, &qmi8658_regmap_config);
+	if (IS_ERR(data->regmap))
+		return dev_err_probe(dev, PTR_ERR(data->regmap),
+				     "Failed to initialize regmap\n");
+
+	ret = devm_mutex_init(dev, &data->lock);
+	if (ret)
+		return ret;
+
+	ret = iio_read_mount_matrix(dev, &data->orientation);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Failed to read mount matrix\n");
+
+	ret = devm_regulator_bulk_get_enable(dev,
+					     ARRAY_SIZE(qmi8658_regulators),
+					     qmi8658_regulators);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Failed to enable regulators\n");
+
+	ret = qmi8658_chip_init(data);
+	if (ret)
+		return ret;
+
+	indio_dev->name = "qmi8658c";
+	indio_dev->info = &qmi8658_info;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->channels = qmi8658_channels;
+	indio_dev->num_channels = ARRAY_SIZE(qmi8658_channels);
+
+	return devm_iio_device_register(dev, indio_dev);
+}
+
+static const struct of_device_id qmi8658_of_match[] = {
+	{ .compatible = "qstcorp,qmi8658c" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, qmi8658_of_match);
+
+static const struct i2c_device_id qmi8658_id[] = {
+	{ "qmi8658c" },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, qmi8658_id);
+
+static struct i2c_driver qmi8658_driver = {
+	.driver = {
+		.name = "qmi8658",
+		.of_match_table = qmi8658_of_match,
+	},
+	.probe = qmi8658_probe,
+	.id_table = qmi8658_id,
+};
+module_i2c_driver(qmi8658_driver);
+
+MODULE_AUTHOR("NanamiKite <nanami@yosoro.hk>");
+MODULE_DESCRIPTION("QST QMI8658C 6-axis IMU driver");
+MODULE_LICENSE("GPL");
-- 
2.56.1


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

* Re: [RFC PATCH v1 2/2] iio: imu: Add driver for QST QMI8658C
  2026-12-04  8:55 ` [RFC PATCH v1 2/2] iio: imu: Add driver for " NanamiKite
@ 2026-12-04  9:10   ` sashiko-bot
  2026-12-04  9:49   ` Andy Shevchenko
  2026-12-05  9:41   ` Uwe Kleine-König
  2 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-12-04  9:10 UTC (permalink / raw)
  To: NanamiKite; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] iio: qmi8658: missing POR delay after regulator enable in
  qmi8658_probe()
- [Low] iio: imu: use named initializer in qmi8658_id table
--

commit a4708c7236bed9810ccaa2f7196cc6b1724f4a55
Author: NanamiKite <nanami@yosoro.hk>

iio: imu: Add driver for QST QMI8658C

This commit adds an I2C IIO driver for the QST QMI8658C 6-axis IMU,
supporting 3-axis accelerometer, 3-axis gyroscope, and die temperature
reads along with scale, 6DOF ODR configuration, and mount-matrix support.

> diff --git a/drivers/iio/imu/qmi8658.c b/drivers/iio/imu/qmi8658.c
> new file mode 100644
> index 0000000000000..6ccb67dcf7859
> --- /dev/null
> +++ b/drivers/iio/imu/qmi8658.c

[ ... ]

> +	ret = devm_regulator_bulk_get_enable(dev,
> +					     ARRAY_SIZE(qmi8658_regulators),
> +					     qmi8658_regulators);
> +	if (ret)
> +		return dev_err_probe(dev, ret,
> +				     "Failed to enable regulators\n");
> +
> +	ret = qmi8658_chip_init(data);

[Severity: Medium]
Does qmi8658_probe() need a power-on reset settling delay after enabling
the regulators before calling qmi8658_chip_init()?

devm_regulator_bulk_get_enable() only waits for each regulator's own
voltage ramp time, not the sensor's internal power-on reset latency.
qmi8658_chip_init() immediately reads QMI8658_REG_WHO_AM_I with no delay
or retry, so on boards with switched vdd or vddio supplies the first I2C
transfer can NACK or return an invalid ID and fail probe.

[ ... ]

> +static const struct i2c_device_id qmi8658_id[] = {
> +	{ "qmi8658c" },
> +	{ }
> +};

[Severity: Low]
New struct i2c_device_id entries should use named initializers per I2C
subsystem conventions, i.e. { .name = "qmi8658c" }.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_022CC05CE10211C280F48ABCE864A0552A06@qq.com?part=2

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

* Re: [RFC PATCH v1 2/2] iio: imu: Add driver for QST QMI8658C
  2026-12-04  8:55 ` [RFC PATCH v1 2/2] iio: imu: Add driver for " NanamiKite
  2026-12-04  9:10   ` sashiko-bot
@ 2026-12-04  9:49   ` Andy Shevchenko
  2026-12-04 11:00     ` NanamiKite
  2026-12-05  9:41   ` Uwe Kleine-König
  2 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2026-12-04  9:49 UTC (permalink / raw)
  To: NanamiKite
  Cc: Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
	devicetree, linux-kernel

On Fri, Dec 04, 2026 at 04:55:04PM +0800, NanamiKite wrote:
> Add an I2C IIO driver for the QST QMI8658C 6-axis IMU, supporting
> 3-axis accelerometer, 3-axis gyroscope, and die temperature reads, along
> with scale, 6DOF ODR configuration, and mount-matrix.

There are some mistakes people do for the last half a year for IIO drivers.
Check the mailing list archives and act accordingly.

In general code looks okay as for the first version.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [RFC PATCH v1 2/2] iio: imu: Add driver for QST QMI8658C
  2026-12-04  9:49   ` Andy Shevchenko
@ 2026-12-04 11:00     ` NanamiKite
  0 siblings, 0 replies; 8+ messages in thread
From: NanamiKite @ 2026-12-04 11:00 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
	devicetree, linux-kernel

Hi Andy,

On Fri, 04 Dec 2026 11:49:17 +0200, Andy Shevchenko wrote:
> There are some mistakes people do for the last half a year for IIO drivers.
> Check the mailing list archives and act accordingly.
>
> In general code looks okay as for the first version.

Thanks for taking a look! I went through recent linux-iio reviews and
newly merged drivers (such as qmc5883l and qmc6308) and spotted several
things to clean up for v2:

- Headers / IWYU: switch <linux/byteorder/generic.h> to <asm/byteorder.h>,
  add explicit <linux/errno.h> and <linux/time.h>, and replace
  <linux/device.h> with <linux/dev_printk.h> and <linux/device/devres.h>.
- Drop the redundant struct device *dev from struct qmi8658_data and use
  regmap_get_device() instead.
- Keep dev_err_probe() and devm_add_action_or_reset() in qmi8658_probe()
  rather than mixing them into qmi8658_chip_init().
- Use fsleep() and add the datasheet t0 (150 ms) POR delay after
  devm_regulator_bulk_get_enable().
- Use named initializer { .name = "qmi8658c" } in qmi8658_id[] and clean up
  blank-line spacing around guard(mutex).

I'll wait a few days for any further feedback on RFC v1 before sending v2.

Thanks,
NanamiKite


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

* Re: [RFC PATCH v1 2/2] iio: imu: Add driver for QST QMI8658C
  2026-12-04  8:55 ` [RFC PATCH v1 2/2] iio: imu: Add driver for " NanamiKite
  2026-12-04  9:10   ` sashiko-bot
  2026-12-04  9:49   ` Andy Shevchenko
@ 2026-12-05  9:41   ` Uwe Kleine-König
  2 siblings, 0 replies; 8+ messages in thread
From: Uwe Kleine-König @ 2026-12-05  9:41 UTC (permalink / raw)
  To: NanamiKite
  Cc: Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
	devicetree, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 655 bytes --]

On Fri, Dec 04, 2026 at 04:55:04PM +0800, NanamiKite wrote:
> +#include <linux/i2c.h>
> +#include <linux/mod_devicetable.h>

<linux/i2c.h> already provides i2c_device_id and of_device_id, so there
is no need to include <linux/mod_devicetable.h> (which pulls in a lot
more *_device_id and thus introduces many unneeded build dependencies).

I'm working on removing <linux/mod_devicetable.h>, so it also helps me
if you don't add another user.

> +static const struct i2c_device_id qmi8658_id[] = {
> +	{ "qmi8658c" },

Please use a named initializer, i.e.

	{ .name = "qmi8658c" },

> +	{ }
> +};
> +MODULE_DEVICE_TABLE(i2c, qmi8658_id);

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [RFC PATCH v1 1/2] dt-bindings: iio: imu: Add QST QMI8658C
  2026-12-04  8:55 ` [RFC PATCH v1 1/2] dt-bindings: iio: imu: Add QST QMI8658C NanamiKite
@ 2026-12-05 15:32   ` Krzysztof Kozlowski
  2026-12-05 15:57     ` NanamiKite
  0 siblings, 1 reply; 8+ messages in thread
From: Krzysztof Kozlowski @ 2026-12-05 15:32 UTC (permalink / raw)
  To: NanamiKite, Jonathan Cameron, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
	devicetree, linux-kernel

On 04/12/2026 09:55, NanamiKite wrote:
> +  interrupts:
> +    minItems: 1
> +    maxItems: 2
> +
> +  interrupt-names:
> +    minItems: 1
> +    maxItems: 2
> +    items:
> +      enum:
> +        - INT1
> +        - INT2

lowercase int1 and int2

I assume these are really optional?


Best regards,
Krzysztof

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

* Re: [RFC PATCH v1 1/2] dt-bindings: iio: imu: Add QST QMI8658C
  2026-12-05 15:32   ` Krzysztof Kozlowski
@ 2026-12-05 15:57     ` NanamiKite
  0 siblings, 0 replies; 8+ messages in thread
From: NanamiKite @ 2026-12-05 15:57 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
	devicetree, linux-kernel

Hi Krzysztof,

On Sat, 05 Dec 2026 16:32:39 +0100, Krzysztof Kozlowski wrote:
> > +  interrupts:
> > +    minItems: 1
> > +    maxItems: 2
> > +
> > +  interrupt-names:
> > +    minItems: 1
> > +    maxItems: 2
> > +    items:
> > +      enum:
> > +        - INT1
> > +        - INT2
>
> lowercase int1 and int2

Will change to lowercase int1/int2 (and update the example) in v2.

> I assume these are really optional?

Yes, both INT1 and INT2 are optional: sensor data, status registers, and
even CTRL9 command handshaking (via STATUSINT.bit7 when CTRL8.bit7 is set)
can all be polled over I2C without wiring either interrupt line, and many
breakout boards leave them unconnected.

Thanks,
NanamiKite


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

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

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261204085504.184447-1-nanami@yosoro.hk>
2026-12-04  8:55 ` [RFC PATCH v1 1/2] dt-bindings: iio: imu: Add QST QMI8658C NanamiKite
2026-12-05 15:32   ` Krzysztof Kozlowski
2026-12-05 15:57     ` NanamiKite
2026-12-04  8:55 ` [RFC PATCH v1 2/2] iio: imu: Add driver for " NanamiKite
2026-12-04  9:10   ` sashiko-bot
2026-12-04  9:49   ` Andy Shevchenko
2026-12-04 11:00     ` NanamiKite
2026-12-05  9:41   ` Uwe Kleine-König

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.