From nobody Tue Feb 10 07:37:43 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 1AA8B2BAF8; Tue, 15 Apr 2025 14:47:35 +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=1744728456; cv=none; b=MIOoyKF6INSIpjZY66cVFCNMSAQRwHz3D5LCohgxyIrUTaQNrM6rAArMfNahCNWpBElw/Zb2VXSPdd/mybwj24wusy/7rIq7AyfT080OSsp80D9pK7GRxP2ImD/ZEPmIy6q8R7IWmKf18Xvl8BZVioSwlnoxKJ/+YasQYXwICM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744728456; c=relaxed/simple; bh=LqB3B/3CmwyGt6HPrW41ZJQgvlYv2Gh1w1/YAFnXC6A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=vBblGD1NeuL186eH4piOnJONdvn+rMdzx7RyDn08hcQljF/wyFJ9S48Xra6EtpCgCvKbNzXrEvz+WTbP1PUED9NzUcxuyUYAz5jHpjBzl/j/ieDi0QJ6mG25WpWjLi6hmmjrO0zhsba0gfEnxWpx7CrAocqdAd0YC/Qa5OdOwf4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fbeF7mOo; 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="fbeF7mOo" Received: by smtp.kernel.org (Postfix) with ESMTPS id 9EE93C4CEEC; Tue, 15 Apr 2025 14:47:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744728455; bh=LqB3B/3CmwyGt6HPrW41ZJQgvlYv2Gh1w1/YAFnXC6A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=fbeF7mOoQZVmxO/GQebvCfZ7IUBpOaQGmh1Fnn0Asj8IPYsi9opPfgcUyw3Z877OS knD7mBBDZQV089J1ka/vo95rOTLHd4SXIt3Oavr4LiO2eq+hU77JZYzhzKonoA5bJl XXGs8E6VoM++QMFb9yIakfzkgPUrRHzCD6z0Ibl2KJ8InukDJeyASln5r6GvGx7/Vv Tel+RLEMKxNsNBNw0bSqSQMx1o8fKXFJDpaEUGTTHyRMm316O7pt4aGknj+vRNfR5s HArVVdlk3TzlAroAJYsf6SUru8J1Mo13oZ7eNjAHFQ684iccUEQfYB3Bf71ndq1weA zbIwMIY5DIBHw== 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 97B49C369BD; Tue, 15 Apr 2025 14:47:35 +0000 (UTC) From: Jean-Baptiste Maneyrol via B4 Relay Date: Tue, 15 Apr 2025 16:47:32 +0200 Subject: [PATCH v2 2/2] iio: imu: inv_icm42600: add wakeup functionality for Wake-on-Motion 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: <20250415-losd-3-inv-icm42600-add-wom-support-v2-2-de94dfb92b7e@tdk.com> References: <20250415-losd-3-inv-icm42600-add-wom-support-v2-0-de94dfb92b7e@tdk.com> In-Reply-To: <20250415-losd-3-inv-icm42600-add-wom-support-v2-0-de94dfb92b7e@tdk.com> To: Jonathan Cameron , Lars-Peter Clausen , 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 X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1744728454; l=5749; i=jean-baptiste.maneyrol@tdk.com; s=20240923; h=from:subject:message-id; bh=CuFRYaRZxPuw+fgDSMa7IYo+bKSh1dwxzccbZhiX9sA=; b=vbuV00uOU5VTIzGu9D4r3pMAh4mKVxn8sBkrGlWTDOc5qrgJHSGLTivgyBPW++UvzimZdDFVi BNoL2+3nGkKB9e0sKWYFKS+GCYCAYTnFFr/9S7F9qOsLuUGYZyIb8ec 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 Wake-on-Motion is on, enable system wakeup and keep chip on for waking up system with interrupt. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_icm42600/inv_icm42600.h | 2 + drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c | 3 ++ drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 65 +++++++++++++++++--= ---- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600.h b/drivers/iio/imu/= inv_icm42600/inv_icm42600.h index f5adebe4640fc36c5dc9810b515369d4909ba834..768d773a9129c5d64f0af195950= 4889ffbc9c131 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600.h +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600.h @@ -151,6 +151,7 @@ struct inv_icm42600_apex { * @map: regmap pointer. * @vdd_supply: VDD voltage regulator for the chip. * @vddio_supply: I/O voltage regulator for the chip. + * @irq: chip irq, required to enable/disable and set wakeup * @orientation: sensor chip orientation relative to main hardware. * @conf: chip sensors configurations. * @suspended: suspended sensors configuration. @@ -168,6 +169,7 @@ struct inv_icm42600_state { struct regmap *map; struct regulator *vdd_supply; struct regulator *vddio_supply; + int irq; struct iio_mount_matrix orientation; struct inv_icm42600_conf conf; struct inv_icm42600_suspended suspended; diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c b/drivers/ii= o/imu/inv_icm42600/inv_icm42600_accel.c index 94515166c1fcdf6cc7ba4843334f51cb14696eba..2249f551f10f3211dadde2f6aa1= dccd9b704f146 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c @@ -1162,6 +1162,9 @@ struct iio_dev *inv_icm42600_accel_init(struct inv_ic= m42600_state *st) if (ret) return ERR_PTR(ret); =20 + /* accel events are wakeup capable */ + device_set_wakeup_capable(&indio_dev->dev, true); + return indio_dev; } =20 diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio= /imu/inv_icm42600/inv_icm42600_core.c index 9a2150ab9e874f17d7fda731cb131c3f688a75a3..14b64d14a6241ec60c23b64486a= 615a84513ae3c 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c @@ -765,6 +765,7 @@ int inv_icm42600_core_probe(struct regmap *regmap, int = chip, mutex_init(&st->lock); st->chip =3D chip; st->map =3D regmap; + st->irq =3D irq; =20 ret =3D iio_read_mount_matrix(dev, &st->orientation); if (ret) { @@ -843,6 +844,9 @@ EXPORT_SYMBOL_NS_GPL(inv_icm42600_core_probe, "IIO_ICM4= 2600"); static int inv_icm42600_suspend(struct device *dev) { struct inv_icm42600_state *st =3D dev_get_drvdata(dev); + struct device *accel_dev; + bool wakeup; + int accel_conf; int ret; =20 mutex_lock(&st->lock); @@ -863,20 +867,33 @@ static int inv_icm42600_suspend(struct device *dev) goto out_unlock; } =20 - /* disable APEX features */ - if (st->apex.wom.enable) { - ret =3D inv_icm42600_disable_wom(st); - if (ret) - goto out_unlock; + /* keep chip on and wake-up capable if APEX and wakeup on */ + accel_dev =3D &st->indio_accel->dev; + wakeup =3D (st->apex.on && device_may_wakeup(accel_dev)) ? true : false; + + if (!wakeup) { + /* disable APEX features and accel if wakeup disabled */ + if (st->apex.wom.enable) { + ret =3D inv_icm42600_disable_wom(st); + if (ret) + goto out_unlock; + } + accel_conf =3D INV_ICM42600_SENSOR_MODE_OFF; + } else { + /* keep accel on and setup irq for wakeup */ + accel_conf =3D st->conf.accel.mode; + enable_irq_wake(st->irq); + disable_irq(st->irq); } =20 ret =3D inv_icm42600_set_pwr_mgmt0(st, INV_ICM42600_SENSOR_MODE_OFF, - INV_ICM42600_SENSOR_MODE_OFF, false, - NULL); + accel_conf, false, NULL); if (ret) goto out_unlock; =20 - regulator_disable(st->vddio_supply); + /* disable vddio regulator if chip is sleeping */ + if (!wakeup) + regulator_disable(st->vddio_supply); =20 out_unlock: mutex_unlock(&st->lock); @@ -892,13 +909,25 @@ static int inv_icm42600_resume(struct device *dev) struct inv_icm42600_state *st =3D dev_get_drvdata(dev); struct inv_icm42600_sensor_state *gyro_st =3D iio_priv(st->indio_gyro); struct inv_icm42600_sensor_state *accel_st =3D iio_priv(st->indio_accel); + struct device *accel_dev; + bool wakeup; int ret; =20 mutex_lock(&st->lock); =20 - ret =3D inv_icm42600_enable_regulator_vddio(st); - if (ret) - goto out_unlock; + /* check wakeup capability */ + accel_dev =3D &st->indio_accel->dev; + wakeup =3D (st->apex.on && device_may_wakeup(accel_dev)) ? true : false; + + /* restore vddio if cut off or irq state */ + if (!wakeup) { + ret =3D inv_icm42600_enable_regulator_vddio(st); + if (ret) + goto out_unlock; + } else { + enable_irq(st->irq); + disable_irq_wake(st->irq); + } =20 pm_runtime_disable(dev); pm_runtime_set_active(dev); @@ -911,11 +940,13 @@ static int inv_icm42600_resume(struct device *dev) if (ret) goto out_unlock; =20 - /* restore APEX features */ - if (st->apex.wom.enable) { - ret =3D inv_icm42600_enable_wom(st); - if (ret) - goto out_unlock; + /* restore APEX features if disabled */ + if (!wakeup) { + if (st->apex.wom.enable) { + ret =3D inv_icm42600_enable_wom(st); + if (ret) + goto out_unlock; + } } =20 /* restore FIFO data streaming */ @@ -924,6 +955,8 @@ static int inv_icm42600_resume(struct device *dev) inv_sensors_timestamp_reset(&accel_st->ts); ret =3D regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG, INV_ICM42600_FIFO_CONFIG_STREAM); + if (ret) + goto out_unlock; } =20 out_unlock: --=20 2.49.0