From nobody Mon Sep 28 14:00:10 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6586A2F616A; Thu, 20 Aug 2026 19:02:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787252564; cv=none; b=Je/X0Q/2QDAkj4pX3apAgavU74N9AMMnoGqK33mR/GvBUO+QVIo052Rd5TI/tlH0LG/dBnLDrB8DU8I3j3IS/Lsx1k89z6mgPICszX5DbR8uaOWXQ1GDkEkUibfLYrXQ0kwgR0Ut0IM36ysSCQQmiLzmvcgT/O/p+I2KJOFvC/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787252564; c=relaxed/simple; bh=0+lKZtAUGxYGhdYt52Oe+klkPEFhqiKENBd93lJ9oDc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=I6RM5pSbaUVDvoclJe2ucLV8TDFJaRlu/a3wNPhWPfh8affIXKg7IEyihKZ2dubXu9ZK+BewzO1DY5HpWFRoFVM3wTuJje2p/iU96TZ2bD/CdGzLW4PAhNGp1Dm7Ebojbo9wr06bNrlQph7ksJnz5lEKu292dfCARQ6Vy1KYLXA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nFMb9Y6f; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nFMb9Y6f" Received: by smtp.kernel.org (Postfix) with ESMTPS id 04638C2BCC7; Thu, 20 Aug 2026 19:02:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1787252564; bh=0+lKZtAUGxYGhdYt52Oe+klkPEFhqiKENBd93lJ9oDc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=nFMb9Y6f1e5Q8mfQgKd+SGnaICOAeHrOXI2E+0dzqwT8QAueIP8rbcDzyBMWzap8m 6S57Zg3gMr0JwB6iPOWZKOwiLKK3zTTZIEVaJVFP9z5PoXzALD0+ICTv88k0LyPzpf 5tEFPLtgs4dh3WRanR1rhlY735WtESMihqeOaWap2WJlt1pSivGOaU6ZS7oAgDUHGT 12XJ42Ph7BH2tRyAKzepKsY21ZbllGUtvsZu6v+cJnx8025SN9MpDO69JQqUjbill2 eiecSnxLMMXWy2iPXa645waMh3xLviXjtIgsu0lOOJwf/0L23RxURm6lnETq76RYVB xAvV8ZENf2XQQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D718AC5DF85; Thu, 20 Aug 2026 19:02:43 +0000 (UTC) From: Jean-Baptiste Maneyrol via B4 Relay Date: Thu, 20 Aug 2026 21:02:37 +0200 Subject: [PATCH 1/4] iio: imu: inv_icm42600: sleep before enabling FIFO data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260820-inv-icm42600-enhacements-v1-1-075a881db557@tdk.com> References: <20260820-inv-icm42600-enhacements-v1-0-075a881db557@tdk.com> In-Reply-To: <20260820-inv-icm42600-enhacements-v1-0-075a881db557@tdk.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jean-Baptiste Maneyrol , Jean-Baptiste Maneyrol , Jonathan Cameron X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1787252562; l=2310; i=jean-baptiste.maneyrol@tdk.com; s=20240923; h=from:subject:message-id; bh=+bwsfyS+uWdp/eU+N8iIh3HLaiG1bPAzG41AqLrkjT8=; b=zEpsW03HkfJ8KN0pMsxC03QcysYWGYv2K7XFHKKbROlvxXlsVLrNVgpoqzH1JqoIqtdXkXOVE lcm06IPv1jBCQm1ngmRqVFbxAjqSdiSMOkUXgLcw//587Tv8vNDc47C X-Developer-Key: i=jean-baptiste.maneyrol@tdk.com; a=ed25519; pk=bRqF1WYk0hR3qrnAithOLXSD0LvSu8DUd+quKLxCicI= X-Endpoint-Received: by B4 Relay for jean-baptiste.maneyrol@tdk.com/20240923 with auth_id=218 X-Original-From: Jean-Baptiste Maneyrol Reply-To: jean-baptiste.maneyrol@tdk.com From: Jean-Baptiste Maneyrol When turning accel or gyro on, a sleep is required for letting the mechanical part stabilize before reporting correct data. Do the sleep before enabling FIFO data to prevent push of incorrect data. This is required if the FIFO is already on because a sensor is already running. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c | 12 ++++++++---- drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c b/drivers/ii= o/imu/inv_icm42600/inv_icm42600_accel.c index 4b0e3cd8a506..d889c1dceec1 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c @@ -254,15 +254,19 @@ static int inv_icm42600_accel_update_scan_mode(struct= iio_dev *indio_dev, fifo_en |=3D INV_ICM42600_SENSOR_ACCEL; } =20 + /* sleep maximum required time */ + sleep =3D max(sleep_accel, sleep_temp); + if (sleep) { + mutex_unlock(&st->lock); + msleep(sleep); + mutex_lock(&st->lock); + } + /* update data FIFO write */ ret =3D inv_icm42600_buffer_set_fifo_en(st, fifo_en | st->fifo.en); =20 out_unlock: mutex_unlock(&st->lock); - /* sleep maximum required time */ - sleep =3D max(sleep_accel, sleep_temp); - if (sleep) - msleep(sleep); return ret; } =20 diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c b/drivers/iio= /imu/inv_icm42600/inv_icm42600_gyro.c index 253bf571439d..34037b9c1f82 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c @@ -126,15 +126,19 @@ static int inv_icm42600_gyro_update_scan_mode(struct = iio_dev *indio_dev, fifo_en |=3D INV_ICM42600_SENSOR_GYRO; } =20 + /* sleep maximum required time */ + sleep =3D max(sleep_gyro, sleep_temp); + if (sleep) { + mutex_unlock(&st->lock); + msleep(sleep); + mutex_lock(&st->lock); + } + /* update data FIFO write */ ret =3D inv_icm42600_buffer_set_fifo_en(st, fifo_en | st->fifo.en); =20 out_unlock: mutex_unlock(&st->lock); - /* sleep maximum required time */ - sleep =3D max(sleep_gyro, sleep_temp); - if (sleep) - msleep(sleep); return ret; } =20 --=20 2.55.0 From nobody Mon Sep 28 14:00:10 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 659F137755C; Thu, 20 Aug 2026 19:02:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787252564; cv=none; b=EInccX+BMaj1EvZ74tYXAavEqFWmiUOZsngySW0zd0/hF8Iz9YWzZWk4/WtHdsTZMe1xanqjHJubl27NZRb5JENZuytsyzCZGN60hK3kxNBp5ptLfyDITvaccEBPthEVXCcHOFHuvlzEisvwQtztqMil9MlfF4KfvAuXQKqE5Vo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787252564; c=relaxed/simple; bh=2vZsEikX46Hh1gkMPLahRa9HT0GsukkRkYSsHhSU7qY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j5T2MlRPrneKUekTeCFlwoBohFXpdfKENitspaPbu4q0npbBmbgTh0vuXD355NznNgxdAzpZ6kqExhxvq+V0pacry7XTh1B33H6QFPyK6fq0veL+Q+noABUSfQ/wq0ks3j4BVEABlOZZUmCCYXR9yVu5hnEV2IojlOtE5iLwzCU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mtdCGLWO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mtdCGLWO" Received: by smtp.kernel.org (Postfix) with ESMTPS id 13065C2BCFA; Thu, 20 Aug 2026 19:02:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1787252564; bh=2vZsEikX46Hh1gkMPLahRa9HT0GsukkRkYSsHhSU7qY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=mtdCGLWObYJfdou1XWz5uBDLWvXo3U/pbvlu1IuKN+YSVCp/hJw8tUTGovOXnH+wC /XkQuZwodm+zRF+hNkbKGqRexNxDm2sMu9H42SYXLvvkTUzlcMEutPdik0p3gK6oP8 GrdLC893wQEEZA59LwkWzGJCSPdremCsMBkxybIfhsBd+sOZcAntP+kBE6pHjXhGVR dy9QgTfUXzqWxER/dplIiYfAJa/vmrRt7UQUTjOO6+wxQ+XWp0A3VxaCfuBL56L7aQ nlV5b97Zmm2ZkJSEOupQWJY0OhDoEbc48OYq67+8pznAyYoVcHHBitggOBimWtuZjt thks5ZTzDrmMg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8328C5DF89; Thu, 20 Aug 2026 19:02:43 +0000 (UTC) From: Jean-Baptiste Maneyrol via B4 Relay Date: Thu, 20 Aug 2026 21:02:38 +0200 Subject: [PATCH 2/4] iio: imu: inv_icm42600: use 2 sensors fixed packet size of 16 bytes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260820-inv-icm42600-enhacements-v1-2-075a881db557@tdk.com> References: <20260820-inv-icm42600-enhacements-v1-0-075a881db557@tdk.com> In-Reply-To: <20260820-inv-icm42600-enhacements-v1-0-075a881db557@tdk.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jean-Baptiste Maneyrol , Jean-Baptiste Maneyrol , Jonathan Cameron X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1787252562; l=3920; i=jean-baptiste.maneyrol@tdk.com; s=20240923; h=from:subject:message-id; bh=EM8dhUPdXrhxOAegwezQFHC3UihVboFJF7OdXrMFA5w=; b=cb3+gFMTyJ9T/aVpre8TyXbP8V33mN8QMyJebry/eQ9/d8DRKSQVFBEeZafxKHiQVPEaLGwOg iuny1DBElSMDlw7ePd5pPuVkaZE5Iz7U0zWpjWMx6ZWk7hHfKApRXv7 X-Developer-Key: i=jean-baptiste.maneyrol@tdk.com; a=ed25519; pk=bRqF1WYk0hR3qrnAithOLXSD0LvSu8DUd+quKLxCicI= X-Endpoint-Received: by B4 Relay for jean-baptiste.maneyrol@tdk.com/20240923 with auth_id=218 X-Original-From: Jean-Baptiste Maneyrol Reply-To: jean-baptiste.maneyrol@tdk.com From: Jean-Baptiste Maneyrol Sometimes dynamic switch between 1 sensor frame to 2 sensors frame is not working when there are too much frames already in the FIFO. By moving accel/gyro on sleep before turning FIFO on, we are storing many FIFO frames before updating the frame format hitting the bug everytime. Fix that by always using the 2 sensors frame of 16 bytes. Also update the hwfifo max watermark reported. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_icm42600/inv_icm42600.h | 4 +-- drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c | 31 +++++++-----------= ---- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600.h b/drivers/iio/imu/= inv_icm42600/inv_icm42600.h index b55d993f0264..f6c7c84c7e45 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600.h +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600.h @@ -356,8 +356,8 @@ struct inv_icm42600_sensor_state { cpu_to_le16((_wm) & GENMASK(11, 0)) /* FIFO is 2048 bytes, let 12 samples for reading latency */ #define INV_ICM42600_FIFO_WATERMARK_MAX (2048 - 12 * 16) -/* INV_ICM42600_FIFO_WATERMARK_MAX / 8 =3D 232 */ -#define INV_ICM42600_FIFO_WATERMARK_MAX_SAMPLES 232 +/* INV_ICM42600_FIFO_WATERMARK_MAX / 16 =3D 116 */ +#define INV_ICM42600_FIFO_WATERMARK_MAX_SAMPLES 116 =20 #define INV_ICM42600_REG_INT_CONFIG1 0x0064 #define INV_ICM42600_INT_CONFIG1_TPULSE_DURATION BIT(6) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c b/drivers/i= io/imu/inv_icm42600/inv_icm42600_buffer.c index 998d312f7bde..043ae9deee65 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c @@ -131,13 +131,13 @@ int inv_icm42600_buffer_set_fifo_en(struct inv_icm426= 00_state *st, INV_ICM42600_FIFO_CONFIG1_GYRO_EN | INV_ICM42600_FIFO_CONFIG1_ACCEL_EN; =20 - val =3D 0; - if (fifo_en & INV_ICM42600_SENSOR_GYRO) - val |=3D INV_ICM42600_FIFO_CONFIG1_GYRO_EN; - if (fifo_en & INV_ICM42600_SENSOR_ACCEL) - val |=3D INV_ICM42600_FIFO_CONFIG1_ACCEL_EN; - if (fifo_en & INV_ICM42600_SENSOR_TEMP) - val |=3D INV_ICM42600_FIFO_CONFIG1_TEMP_EN; + /* always enable/disable all bits for allowing dynamic transitions */ + if (fifo_en) + val =3D INV_ICM42600_FIFO_CONFIG1_TEMP_EN | + INV_ICM42600_FIFO_CONFIG1_GYRO_EN | + INV_ICM42600_FIFO_CONFIG1_ACCEL_EN; + else + val =3D 0; =20 ret =3D regmap_update_bits(st->map, INV_ICM42600_REG_FIFO_CONFIG1, mask, = val); if (ret) @@ -149,19 +149,6 @@ int inv_icm42600_buffer_set_fifo_en(struct inv_icm4260= 0_state *st, return 0; } =20 -static size_t inv_icm42600_get_packet_size(unsigned int fifo_en) -{ - size_t packet_size; - - if ((fifo_en & INV_ICM42600_SENSOR_GYRO) && - (fifo_en & INV_ICM42600_SENSOR_ACCEL)) - packet_size =3D INV_ICM42600_FIFO_2SENSORS_PACKET_SIZE; - else - packet_size =3D INV_ICM42600_FIFO_1SENSOR_PACKET_SIZE; - - return packet_size; -} - static unsigned int inv_icm42600_wm_truncate(unsigned int watermark, size_t packet_size) { @@ -209,7 +196,7 @@ int inv_icm42600_buffer_update_watermark(struct inv_icm= 42600_state *st) __le16 raw_wm; int ret; =20 - packet_size =3D inv_icm42600_get_packet_size(st->fifo.en); + packet_size =3D INV_ICM42600_FIFO_2SENSORS_PACKET_SIZE; =20 /* compute sensors latency, depending on sensor watermark and odr */ wm_gyro =3D inv_icm42600_wm_truncate(st->fifo.watermark.gyro, packet_size= ); @@ -495,7 +482,7 @@ int inv_icm42600_buffer_fifo_read(struct inv_icm42600_s= tate *st, /* compute maximum FIFO read size (watermark for max =3D 0 interrupt case= ) */ if (max =3D=3D 0) max =3D st->fifo.watermark.value; - max_count =3D max * inv_icm42600_get_packet_size(st->fifo.en); + max_count =3D max * INV_ICM42600_FIFO_2SENSORS_PACKET_SIZE; =20 /* read FIFO count value */ raw_fifo_count =3D (__be16 *)st->buffer; --=20 2.55.0 From nobody Mon Sep 28 14:00:10 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65B1D3803DD; Thu, 20 Aug 2026 19:02:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787252564; cv=none; b=XDBERQthiUfw6GqGXaWsq9QxGb6xxxvFfWM8kxRx9R93+jmlr/05ehgHg4YgfIiG6HeqIjSsEURT6gDqIwUOH1v8fATFzo8SqdCvi6036eJ/gU2OxeLwnz3kXyo67zZV5QHo7+OF/7MgurKX6Ruc0XLF73+NAUtvZqYW2E0/p1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787252564; c=relaxed/simple; bh=rDMx9sIWGeeq9a56wl+tBY6uR9IDxUaz0FHi+kPxOxI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sr2L3lH8T8uNFV2TzcDAY+74CkjsTGmlW1wQoV2HF2t1wOho/6FtXkrdwVTha3/pGewT3DybHL7LX3hGBXYzGc2fE2FK5MkoTPJaTzAUyCw0ajNNcEfjxIw8JPtLZ3AUOgnbLEXsQ3qiVsNGRMZ66XOdOYivhMWdXewXboFYkSQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=C7nQ4VMl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="C7nQ4VMl" Received: by smtp.kernel.org (Postfix) with ESMTPS id 239A5C2BCFB; Thu, 20 Aug 2026 19:02:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1787252564; bh=rDMx9sIWGeeq9a56wl+tBY6uR9IDxUaz0FHi+kPxOxI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=C7nQ4VMlin0xstnLLrqY+9czwaNE3oQvpSY7uzH/bSxJzExeJVnZTyzml4hoTbjHK YT7+O1M78z166OIaKNvqUdMCVMWEjKZvMHW8bWhF3IIV7QCo8xlStTsSGxF3St0JB5 kEi80RrxWuUBxY/+KuIB7TCLMhkYeldP9MoXSh4y7Q8Nu2CRh1pSQrByF/DIX9l649 4Q0Z+X0lE1aYVCvKI292jit0cZ3ihZ2C+6IRKWtU9YJMyJ9hEhsiyn69vglPljq3AA MxRhq3uhjJCGPKsw1Jl9zMnbbLB2NkRH6RgorEsLZIlqfcPBitd3eMwKnn045CGvLq EDvPx2K9M0hJg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0967AC5DF81; Thu, 20 Aug 2026 19:02:44 +0000 (UTC) From: Jean-Baptiste Maneyrol via B4 Relay Date: Thu, 20 Aug 2026 21:02:39 +0200 Subject: [PATCH 3/4] iio: imu: inv_icm42600: simplify watermark computation by using gcd Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260820-inv-icm42600-enhacements-v1-3-075a881db557@tdk.com> References: <20260820-inv-icm42600-enhacements-v1-0-075a881db557@tdk.com> In-Reply-To: <20260820-inv-icm42600-enhacements-v1-0-075a881db557@tdk.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jean-Baptiste Maneyrol , Jean-Baptiste Maneyrol , Jonathan Cameron X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1787252562; l=4645; i=jean-baptiste.maneyrol@tdk.com; s=20240923; h=from:subject:message-id; bh=bwjlmqmiKOXuuvGZcZK9+89VfoFOSDBn/75xuRvm4m8=; b=HCkBJxq7pHZwLvEyJrwdC5vX29IfILXzM2Lw+kKIyONM+hwKEgDpkfX192Z+LZoEFC2Fi029d a785lHuNu7jAacpP18AeH70iUoEhtnnTUenqcdNCf29gCGc0vHI0nYG X-Developer-Key: i=jean-baptiste.maneyrol@tdk.com; a=ed25519; pk=bRqF1WYk0hR3qrnAithOLXSD0LvSu8DUd+quKLxCicI= X-Endpoint-Received: by B4 Relay for jean-baptiste.maneyrol@tdk.com/20240923 with auth_id=218 X-Original-From: Jean-Baptiste Maneyrol Reply-To: jean-baptiste.maneyrol@tdk.com From: Jean-Baptiste Maneyrol The watermark computation was in fact resulting in computing the gcd of the latencies when both sensors are on. Gcd is required because of the IIO buffer watermark. We need to use a divider of IIO buffer watermark, otherwise we will overflow the requested watermark. Move to use gcd and update documentation accordingly. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c | 47 ++++++++++--------= ---- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c b/drivers/i= io/imu/inv_icm42600/inv_icm42600_buffer.c index 043ae9deee65..1428f18408ce 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c @@ -5,6 +5,7 @@ =20 #include #include +#include #include #include #include @@ -172,15 +173,14 @@ static unsigned int inv_icm42600_wm_truncate(unsigned= int watermark, * * FIFO watermark threshold is computed based on the required watermark va= lues * set for gyro and accel sensors. Since watermark is all about acceptable= data - * latency, use the smallest setting between the 2. It means choosing the - * smallest latency but this is not as simple as choosing the smallest wat= ermark - * value. Latency depends on watermark and ODR. It requires several steps: - * 1) compute gyro and accel latencies and choose the smallest value. - * 2) adapt the chosen latency so that it is a multiple of both gyro and a= ccel - * ones. Otherwise it is possible that you don't meet a requirement. (f= or - * example with gyro @100Hz wm 4 and accel @100Hz with wm 6, choosing t= he - * value of 4 will not meet accel latency requirement because 6 is not a - * multiple of 4. You need to use the value 2.) + * latency, we should need to use the smallest latency value. But it is no= t as + * simple as choosing the smallest watermark value. Latency depends on wat= ermark + * and ODR and IIO buffer watermark adds another requirement. The required= steps: + * 1) compute gyro and accel periods and latencies + * 2) Use the smallest period and the gcd of the latencies. Gcd is required + * because of the IIO buffer watermark that will prevent send of data i= f not + * crossed. Thus accel and gyro watermarks must be a multiple of the wa= termark + * value. Computing the gcd gives us the biggest value that meets this = criteria. * 3) Since all periods are multiple of each others, watermark is computed= by * dividing this computed latency by the smallest period, which corresp= onds * to the FIFO frequency. Beware that this is only true because we are = not @@ -190,7 +190,7 @@ int inv_icm42600_buffer_update_watermark(struct inv_icm= 42600_state *st) { size_t packet_size, wm_size; unsigned int wm_gyro, wm_accel, watermark; - u32 period_gyro, period_accel; + u32 period_gyro, period_accel, period; u32 latency_gyro, latency_accel, latency; bool restore; __le16 raw_wm; @@ -218,22 +218,17 @@ int inv_icm42600_buffer_update_watermark(struct inv_i= cm42600_state *st) watermark =3D wm_gyro; st->fifo.watermark.eff_gyro =3D wm_gyro; } else { - /* compute the smallest latency that is a multiple of both */ - if (latency_gyro <=3D latency_accel) - latency =3D latency_gyro - (latency_accel % latency_gyro); - else - latency =3D latency_accel - (latency_gyro % latency_accel); - /* all this works because periods are multiple of each others */ - watermark =3D latency / min(period_gyro, period_accel); - if (watermark < 1) - watermark =3D 1; - /* update effective watermark */ - st->fifo.watermark.eff_gyro =3D latency / period_gyro; - if (st->fifo.watermark.eff_gyro < 1) - st->fifo.watermark.eff_gyro =3D 1; - st->fifo.watermark.eff_accel =3D latency / period_accel; - if (st->fifo.watermark.eff_accel < 1) - st->fifo.watermark.eff_accel =3D 1; + /* + * In case of both accel and gyro enabled, we need to use the + * shortest period and the gcd of the latencies. Gcd is required + * because of the IIO buffer watermark that will prevent data + * sending if we are not crossing the watermark level. + */ + period =3D min(period_gyro, period_accel); + latency =3D gcd(latency_gyro, latency_accel); + watermark =3D max(latency / period, 1); + st->fifo.watermark.eff_gyro =3D max(latency / period_gyro, 1); + st->fifo.watermark.eff_accel =3D max(latency / period_accel, 1); } =20 /* compute watermark value in bytes */ --=20 2.55.0 From nobody Mon Sep 28 14:00:10 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65A9337F8DA; Thu, 20 Aug 2026 19:02:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787252564; cv=none; b=H9/dQI4CumukZKUIIj3xRGj/x/VrpEkEvQJiey9+vlNsdYZneIOIHQAPsjWYrkA2ue9MOXpXPx3EwXnoOxkIWCT7oJcnWYtBcV9Az52M8rrOuMqxqfVY6C2ehYju4pjO0u9y9A/vZrnqHSiGJ1ql9Tgag7XgLVkHWHcpmabH+fw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787252564; c=relaxed/simple; bh=W9WzyYMOrIHWPalTMijgMMlFoiy6Z9oo9VFEI+WQ96M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=epF1eCL8Il0fTXOAI17jS0FeZPcA1bC8+YR6CxJEtS7CMYL/V9Tt+OtirJl+aHjOvXcInuj0TSnERy+fFhgmsuNpugVYH+de0Llk5pLXcfBMEj5zmtHu+PqGjnFxOYDUBI8Hk5d5gaHuXoqat8/B06iDuSpxhnuFvh0hZWfO5LE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GNudyh4a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GNudyh4a" Received: by smtp.kernel.org (Postfix) with ESMTPS id 2FD85C2BD01; Thu, 20 Aug 2026 19:02:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1787252564; bh=W9WzyYMOrIHWPalTMijgMMlFoiy6Z9oo9VFEI+WQ96M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=GNudyh4aU95XCUSkxUpUx9Ye6JHg76zGF3c2ImtXNQEzZInU4rrJhZdjq4P+akWSt NpjZRXwIvf1dmY/lDQLMuVJQWQmMfxth+jUox59YBgs4H6xhQTBPMNE7SwtVllzkV8 MWoJp6RsRF1FoN2aIEHJyfg3WjP74ydlL7wqMRXhRLkbBnEHEQ/bwC+b+4acA/rCSM hXDpWqOSao6+ugOKiGX7EgDXCYRSZ6kVXsvCxwBRGqyRfuJCpbq/fbkc43Hw+qr/xc taG2Urn7iCiYpukPpC4JlDbGxHLuJq9wiqaEXuR/mgE+NjNlsH2i4oeb67jhM7QWrc 0/M/5tGPczvSA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C398C5DF8E; Thu, 20 Aug 2026 19:02:44 +0000 (UTC) From: Jean-Baptiste Maneyrol via B4 Relay Date: Thu, 20 Aug 2026 21:02:40 +0200 Subject: [PATCH 4/4] iio: imu: inv_icm42600: do not read FIFO count for watermark it Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260820-inv-icm42600-enhacements-v1-4-075a881db557@tdk.com> References: <20260820-inv-icm42600-enhacements-v1-0-075a881db557@tdk.com> In-Reply-To: <20260820-inv-icm42600-enhacements-v1-0-075a881db557@tdk.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jean-Baptiste Maneyrol , Jean-Baptiste Maneyrol , Jonathan Cameron X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1787252562; l=2268; i=jean-baptiste.maneyrol@tdk.com; s=20240923; h=from:subject:message-id; bh=OQmQVi4yJ7lu/WvxADoFhgDSPCmfaq3lgsQjBlIiMZo=; b=0NCK0EjmfbIqD3uY37VDeTKqiWGqEGfKSkBe6nBp2xvo0aFvRx1fwMmbFe7DbuSnLaq31+GPU zHEwQo7Fp/nDmacOz6dhgNo95FOHblt5Ci8yi6FOWW4Y2PVjI8n3u5K X-Developer-Key: i=jean-baptiste.maneyrol@tdk.com; a=ed25519; pk=bRqF1WYk0hR3qrnAithOLXSD0LvSu8DUd+quKLxCicI= X-Endpoint-Received: by B4 Relay for jean-baptiste.maneyrol@tdk.com/20240923 with auth_id=218 X-Original-From: Jean-Baptiste Maneyrol Reply-To: jean-baptiste.maneyrol@tdk.com From: Jean-Baptiste Maneyrol Optimize data reading for high frequencies by not reading FIFO count in case of watermark interrupt. We already know there is watermark samples in the FIFO and we need to not read more than watermark samples for timestamping mechanism. Let's just read FIFO data directly without reading FIFO count in this case. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c | 33 ++++++++++--------= ---- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c b/drivers/i= io/imu/inv_icm42600/inv_icm42600_buffer.c index 1428f18408ce..1410096f6e6d 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c @@ -474,24 +474,21 @@ int inv_icm42600_buffer_fifo_read(struct inv_icm42600= _state *st, st->fifo.nb.accel =3D 0; st->fifo.nb.total =3D 0; =20 - /* compute maximum FIFO read size (watermark for max =3D 0 interrupt case= ) */ - if (max =3D=3D 0) - max =3D st->fifo.watermark.value; - max_count =3D max * INV_ICM42600_FIFO_2SENSORS_PACKET_SIZE; - - /* read FIFO count value */ - raw_fifo_count =3D (__be16 *)st->buffer; - ret =3D regmap_bulk_read(st->map, INV_ICM42600_REG_FIFO_COUNT, - raw_fifo_count, sizeof(*raw_fifo_count)); - if (ret) - return ret; - st->fifo.count =3D be16_to_cpup(raw_fifo_count); - - /* check and clamp FIFO count value */ - if (st->fifo.count =3D=3D 0) - return 0; - if (st->fifo.count > max_count) - st->fifo.count =3D max_count; + /* read watermark samples for interrupt case (max =3D 0) or read FIFO cou= nt */ + if (max =3D=3D 0) { + st->fifo.count =3D st->fifo.watermark.value * + INV_ICM42600_FIFO_2SENSORS_PACKET_SIZE; + } else { + raw_fifo_count =3D (__be16 *)st->buffer; + ret =3D regmap_bulk_read(st->map, INV_ICM42600_REG_FIFO_COUNT, + raw_fifo_count, sizeof(*raw_fifo_count)); + if (ret) + return ret; + max_count =3D max * INV_ICM42600_FIFO_2SENSORS_PACKET_SIZE; + st->fifo.count =3D min(be16_to_cpup(raw_fifo_count), max_count); + if (st->fifo.count =3D=3D 0) + return 0; + } =20 /* read all FIFO data in internal buffer */ ret =3D regmap_noinc_read(st->map, INV_ICM42600_REG_FIFO_DATA, --=20 2.55.0