From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA0D5CD6E59 for ; Sat, 30 May 2026 03:20:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KEGADsbi+dvQw2sdQKcS1EBu1y542A3ue1qbNwGRaBk=; b=v+I4aYgc8AEWKR a5av49WfPqLBSxY5C4LssK1uWlqw+dIRMidDL7rEu/BhaHWQgfuPFri5rk/kr5LkCzHdL+QZg4/uA KXUn4lppEVqkljhVGP9kbbps3sHJBtdUlsVVuiAn+ow31tCKVuoj7gtS48wBhpmNOX73aB0FkRda1 39ULVuGG4ndT9ehr6dJ1g7eqOfPQmmh7i3JpipD9Q4g7c59FLv4Sca9g4mncMpnE2r78t/Nosjfe8 ZorJpyjS1HkBo+b+vLQYKkhXQ8qeFC+aP+bj4SKRXa/Ygsktmlk1YIuiDmQJ0if3HDnp5dxIy5yha WoWdzA/dNtMnh9VsgWBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wTAFP-00000008PKi-36yg; Sat, 30 May 2026 03:20:27 +0000 Received: from mail-oo1-xc35.google.com ([2607:f8b0:4864:20::c35]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wTAFK-00000008PH6-07Pc for linux-rockchip@lists.infradead.org; Sat, 30 May 2026 03:20:23 +0000 Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-69d7aa0ac14so5286331eaf.3 for ; Fri, 29 May 2026 20:20:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780111221; x=1780716021; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JYZ9Hm8Lf/HQhtQVgZ7/T9QD8Q+iGUVzRElNt4yyXx4=; b=eVFORiF2RINZNhFO+pmAByOgB8pkAwIXTOMGQgpI52dTj27xaGMkm0yRf2q4dVpn2o E8tzxJJ+RGNUdRDllwAN5t5AmmLra7hSIEeJDvqQJxkxJsi1QwvsBIF0LYMUBcfa/lnr jF4JqN075eWcNftrD6Y8CUvBuIX4uHLBi9pP93IWcWwRmhmNIAaUJ1+m5GbNyS7hYbX2 o96hxX19izTRbFH13Ut8UDO1TXx9jeWVwtFRLv+NmCtek95qEcmpar17J/tlzn2S4OS6 JS6C8yMY7mTOqC5LQjTjVThW7wp+M20qvf/7KOr3shJPNkRz8sqKZv+jNB5/UTO0wPzJ zC9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780111221; x=1780716021; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=JYZ9Hm8Lf/HQhtQVgZ7/T9QD8Q+iGUVzRElNt4yyXx4=; b=GyRikwyas3KiBvT3sU1Xv276cfe135ETcIKO23Bg1YLgDRLQImDls7bFkuA+SdUbOP 69BmCY7U5OpOkCOgx4GTObiOtxF7pTWEhNpTU8sefpLLlJhDnywHo38exMShGkgoAkeo KuZPjnsojRcSPQpXgDr1x1g6YvQ5MA6mE34WAl+zDbQs8TMGg255AW+kjbVgof+4DkkZ 1IhKeq6BGCoNfg8wfUnllGwUrHJNixd/Q7OLO0WMSGjb2aTNS7SYeky7JgYdP/UjU6i8 TgBvY4uLuClu6BqYdpRfS5sL9cpFhXyYyh+dwMSf4zHfiBWIYoPbJY9IrcVP7N1RhwUd 1G1A== X-Forwarded-Encrypted: i=1; AFNElJ/j2Nzc26GS426d3aVO9HDFcCiSfa9gGuR3pWY5pBgAbtMebNNT+r9SbqpUo20rbfr2y0AlHz16KgMJ2NDDuQ==@lists.infradead.org X-Gm-Message-State: AOJu0YwjUHmYAisJL92TES2L2j/LyfbFnB5Nc58R7wjUDbVXuNmMfyXo CtR0JoEk3Q8TyNs+9UOw7kPKhpQjLKXX9dKGz5wU01cd2CmPoVIFz7oc X-Gm-Gg: Acq92OEGCdJtdsXPbiBpqAJoi515L8JQIJtznBZLFrgJ21D9IsKp0BBlsB2y38vjhJB qbaJ4rldDyyGlRZHeg6Oqd3nnXq8x3ESzcxEPcdcc6ghiBndQHK7MptH44o8Qpp1PeW6pGzthiS d+hKcv/4bbL0d15sgpMCPAIFqBffiBe+PRRsie05lgY8wfOnLU2U8m7VJBdb96o2sg2yAYl5E59 NFDm9FSaR8lEWTtL8hxoHxRTOFGwMb3GdDaDiq4wqRHiqKNafJ07xV7KS68rgPzghzJUJ1rRggc 7xdQeI1BwT1OkqMziTY7iJktBxJ0zgHNDEeyq9Jlxgi6oZIhRa2eT+aObdZXnaT4gKMeYAP/e0L vjdd6HYui/ECIlgr0No3BO9tZLMMCgOiqhpLTyOO6jyDp5OEm4LtB2pIlbDSBPYf1zurXmVmwlX 9LXUeLhFJoaU5QS4vbJU/teh5+0+uK5IThYUwn0IV16A== X-Received: by 2002:a05:6820:1849:b0:69e:2fd:408e with SMTP id 006d021491bc7-69e103852d4mr1013272eaf.37.1780111220952; Fri, 29 May 2026 20:20:20 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bc0::54]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-69e067e911csm2130737eaf.5.2026.05.29.20.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 20:20:20 -0700 (PDT) From: Chris Morgan To: linux-iio@vger.kernel.org Cc: andy@kernel.org, nuno.sa@analog.com, dlechner@baylibre.com, jic23@kernel.org, jean-baptiste.maneyrol@tdk.com, linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org, heiko@sntech.de, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, andriy.shevchenko@intel.com, Chris Morgan Subject: [PATCH V9 05/11] iio: imu: inv_icm42607: Add PM support for icm42607 Date: Fri, 29 May 2026 22:17:32 -0500 Message-ID: <20260530031739.109063-6-macroalpha82@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260530031739.109063-1-macroalpha82@gmail.com> References: <20260530031739.109063-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260529_202022_079437_910443CC X-CRM114-Status: GOOD ( 21.87 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org From: Chris Morgan Add power management support for the ICM42607 device driver. Signed-off-by: Chris Morgan --- drivers/iio/imu/inv_icm42607/inv_icm42607.h | 10 ++ .../iio/imu/inv_icm42607/inv_icm42607_core.c | 144 ++++++++++++++++++ .../iio/imu/inv_icm42607/inv_icm42607_i2c.c | 1 + .../iio/imu/inv_icm42607/inv_icm42607_spi.c | 1 + 4 files changed, 156 insertions(+) diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607.h b/drivers/iio/imu/inv_icm42607/inv_icm42607.h index 7a73c917fe8a..00c8dfe20717 100644 --- a/drivers/iio/imu/inv_icm42607/inv_icm42607.h +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -109,6 +110,7 @@ struct inv_icm42607_hw { * @hw: Hardware specific data. * @map: regmap pointer. * @vddio_supply: I/O voltage regulator for the chip. + * @vddio_en: I/O voltage status for runtime PM. * @irq: chip irq, required to enable/disable and set wakeup * @orientation: sensor chip orientation relative to main hardware. * @conf: chip sensors configurations. @@ -118,6 +120,7 @@ struct inv_icm42607_state { const struct inv_icm42607_hw *hw; struct regmap *map; struct regulator *vddio_supply; + bool vddio_en; int irq; struct iio_mount_matrix orientation; struct inv_icm42607_conf conf; @@ -339,11 +342,18 @@ struct inv_icm42607_state { #define INV_ICM42607_GYRO_STARTUP_TIME_MS 30 #define INV_ICM42607_TEMP_STARTUP_TIME_MS 77 +/* + * Suspend delay assumed from other icm42600 series device, not + * documented in datasheet. + */ +#define INV_ICM42607_SUSPEND_DELAY_MS 2000 + typedef int (*inv_icm42607_bus_setup)(struct inv_icm42607_state *); extern const struct regmap_config inv_icm42607_regmap_config; extern const struct inv_icm42607_hw inv_icm42607_hw_data; extern const struct inv_icm42607_hw inv_icm42607p_hw_data; +extern const struct dev_pm_ops inv_icm42607_pm_ops; int inv_icm42607_core_probe(struct regmap *regmap, const struct inv_icm42607_hw *hw, diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c index 3dd4cc8c6b1d..cfdce70ce25d 100644 --- a/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -73,6 +74,51 @@ const struct inv_icm42607_hw inv_icm42607p_hw_data = { }; EXPORT_SYMBOL_NS_GPL(inv_icm42607p_hw_data, "IIO_ICM42607"); +static int inv_icm42607_set_pwr_mgmt0(struct inv_icm42607_state *st, + enum inv_icm42607_sensor_mode gyro, + enum inv_icm42607_sensor_mode accel, + bool temp, unsigned int *sleep_ms) +{ + enum inv_icm42607_sensor_mode oldgyro = st->conf.gyro.mode; + enum inv_icm42607_sensor_mode oldaccel = st->conf.accel.mode; + bool oldtemp = st->conf.temp_en; + unsigned int sleepval; + unsigned int val; + int ret; + + if (gyro == oldgyro && accel == oldaccel && temp == oldtemp) + return 0; + + val = FIELD_PREP(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, gyro); + val |= FIELD_PREP(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, accel); + if (!temp) + val |= INV_ICM42607_PWR_MGMT0_ACCEL_LP_CLK_SEL; + ret = regmap_write(st->map, INV_ICM42607_REG_PWR_MGMT0, val); + if (ret) + return ret; + + st->conf.gyro.mode = gyro; + st->conf.accel.mode = accel; + st->conf.temp_en = temp; + + sleepval = 0; + if (temp && !oldtemp) + sleepval = max(sleepval, INV_ICM42607_TEMP_STARTUP_TIME_MS); + + if (accel != oldaccel) + sleepval = max(sleepval, INV_ICM42607_ACCEL_STARTUP_TIME_MS); + + if (gyro != oldgyro) + sleepval = max(sleepval, INV_ICM42607_GYRO_STARTUP_TIME_MS); + + if (sleep_ms) + *sleep_ms = sleepval; + else if (sleepval) + fsleep(sleepval * 1000); + + return 0; +} + static int inv_icm42607_set_conf(struct inv_icm42607_state *st, const struct inv_icm42607_conf *conf) { @@ -182,12 +228,17 @@ static int inv_icm42607_enable_vddio_reg(struct inv_icm42607_state *st) { int ret; + if (st->vddio_en) + return 0; + ret = regulator_enable(st->vddio_supply); if (ret) return ret; fsleep(INV_ICM42607_POWER_UP_TIME_US); + st->vddio_en = true; + return 0; } @@ -195,7 +246,12 @@ static void inv_icm42607_disable_vddio_reg(void *_data) { struct inv_icm42607_state *st = _data; + if (!st->vddio_en) + return; + regulator_disable(st->vddio_supply); + + st->vddio_en = false; } int inv_icm42607_core_probe(struct regmap *regmap, @@ -253,10 +309,98 @@ int inv_icm42607_core_probe(struct regmap *regmap, if (ret) return ret; + ret = devm_pm_runtime_set_active_enabled(dev); + if (ret) + return ret; + + pm_runtime_set_autosuspend_delay(dev, INV_ICM42607_SUSPEND_DELAY_MS); + pm_runtime_use_autosuspend(dev); + return 0; } EXPORT_SYMBOL_NS_GPL(inv_icm42607_core_probe, "IIO_ICM42607"); +static int inv_icm42607_suspend(struct device *dev) +{ + struct inv_icm42607_state *st = dev_get_drvdata(dev); + int ret; + + guard(mutex)(&st->lock); + + if (pm_runtime_suspended(dev)) + return 0; + + ret = pm_runtime_force_suspend(dev); + if (ret) + return ret; + + ret = inv_icm42607_set_pwr_mgmt0(st, INV_ICM42607_SENSOR_MODE_OFF, + INV_ICM42607_SENSOR_MODE_OFF, + false, NULL); + if (ret) + return ret; + + inv_icm42607_disable_vddio_reg(st); + + return 0; +} + +static int inv_icm42607_resume(struct device *dev) +{ + struct inv_icm42607_state *st = dev_get_drvdata(dev); + int ret; + + guard(mutex)(&st->lock); + + if (pm_runtime_suspended(dev)) + return 0; + + ret = pm_runtime_force_resume(dev); + if (ret) + return ret; + + ret = inv_icm42607_enable_vddio_reg(st); + if (ret) + return ret; + + /* Nothing else to restore at this time. */ + + return 0; +} + +static int inv_icm42607_runtime_suspend(struct device *dev) +{ + struct inv_icm42607_state *st = dev_get_drvdata(dev); + int ret; + + guard(mutex)(&st->lock); + + ret = inv_icm42607_set_pwr_mgmt0(st, INV_ICM42607_SENSOR_MODE_OFF, + INV_ICM42607_SENSOR_MODE_OFF, false, + NULL); + if (ret) + return ret; + + inv_icm42607_disable_vddio_reg(st); + + return 0; +} + +static int inv_icm42607_runtime_resume(struct device *dev) +{ + struct inv_icm42607_state *st = dev_get_drvdata(dev); + + guard(mutex)(&st->lock); + + return inv_icm42607_enable_vddio_reg(st); +} + +EXPORT_NS_GPL_DEV_PM_OPS(inv_icm42607_pm_ops, IIO_ICM42607) = { + SYSTEM_SLEEP_PM_OPS(inv_icm42607_suspend, inv_icm42607_resume) + RUNTIME_PM_OPS(inv_icm42607_runtime_suspend, + inv_icm42607_runtime_resume, NULL) +}; + MODULE_AUTHOR("InvenSense, Inc."); MODULE_DESCRIPTION("InvenSense ICM-42607x device driver"); MODULE_LICENSE("GPL"); diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c index 22ac51108cd3..cd08bb9514f2 100644 --- a/drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c @@ -82,6 +82,7 @@ static struct i2c_driver inv_icm42607_driver = { .driver = { .name = "inv-icm42607-i2c", .of_match_table = inv_icm42607_of_matches, + .pm = pm_ptr(&inv_icm42607_pm_ops), }, .id_table = inv_icm42607_id, .probe = inv_icm42607_probe, diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c index 421d3ec1cded..8a82e1610531 100644 --- a/drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c @@ -94,6 +94,7 @@ static struct spi_driver inv_icm42607_driver = { .driver = { .name = "inv-icm42607-spi", .of_match_table = inv_icm42607_of_matches, + .pm = pm_ptr(&inv_icm42607_pm_ops), }, .id_table = inv_icm42607_spi_id_table, .probe = inv_icm42607_probe, -- 2.43.0 _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip